Lines Matching +full:ent +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * dm1105.c - driver for DVB cards based on SDMC DM1105 PCI chip
9 #include <linux/i2c-algo-bit.h>
15 #include <linux/dma-mapping.h>
17 #include <media/rc-core.h>
25 #include "dvb-pll.h"
38 #define UNSET (-1U)
47 /* ----------------------------------------------- */
69 /* ----------------------------------------------- */
83 /* Odd-even secret key select */
122 /* ----------------------------------------------- */
149 #define DM1105_I2C_GPIO_NAME "dm1105-gpio"
246 .name = "Unbranded DM1105 with i2c on GPIOs",
286 if (0 == pci->subsystem_vendor && in dm1105_card_list()
287 0 == pci->subsystem_device) { in dm1105_card_list()
294 "dm1105: -- tux\n"); in dm1105_card_list()
305 printk(KERN_ERR "dm1105: card=%d -> %s\n", in dm1105_card_list()
358 #define dm_io_mem(reg) ((unsigned long)(&dev->io_mem[reg]))
376 /* The chip has 18 GPIOs. In HOST mode GPIO's used as 15 bit address lines,
447 dm1105_setline(dev, dm1105_boards[dev->boardnr].gpio_sda, state); in dm1105_setsda()
454 dm1105_setline(dev, dm1105_boards[dev->boardnr].gpio_scl, state); in dm1105_setscl()
461 return dm1105_gpio_get(dev, dm1105_boards[dev->boardnr].gpio_sda) in dm1105_getsda()
469 return dm1105_gpio_get(dev, dm1105_boards[dev->boardnr].gpio_scl) in dm1105_getscl()
481 dev = i2c_adap->algo_data; in dm1105_i2c_xfer()
500 return -1; in dm1105_i2c_xfer()
511 len = msgs[i].len - 1; in dm1105_i2c_xfer()
529 return -1; in dm1105_i2c_xfer()
532 len -= 48; in dm1105_i2c_xfer()
550 return -1; in dm1105_i2c_xfer()
570 return container_of(feed->demux, struct dm1105_dev, demux); in feed_to_dm1105_dev()
575 return container_of(fe->dvb, struct dm1105_dev, dvb_adapter); in frontend_to_dm1105_dev()
583 dm1105_gpio_enable(dev, dm1105_boards[dev->boardnr].lnb.mask, 1); in dm1105_set_voltage()
586 dm1105_boards[dev->boardnr].lnb.mask, in dm1105_set_voltage()
587 dm1105_boards[dev->boardnr].lnb.v18); in dm1105_set_voltage()
590 dm1105_boards[dev->boardnr].lnb.mask, in dm1105_set_voltage()
591 dm1105_boards[dev->boardnr].lnb.v13); in dm1105_set_voltage()
594 dm1105_boards[dev->boardnr].lnb.mask, in dm1105_set_voltage()
595 dm1105_boards[dev->boardnr].lnb.off); in dm1105_set_voltage()
602 dm_writel(DM1105_STADR, (__force u32)cpu_to_le32(dev->dma_addr)); in dm1105_set_dma_addr()
607 dev->ts_buf = dma_alloc_coherent(&dev->pdev->dev, in dm1105_dma_map()
608 6 * DM1105_DMA_BYTES, &dev->dma_addr, in dm1105_dma_map()
611 return !dev->ts_buf; in dm1105_dma_map()
616 dma_free_coherent(&dev->pdev->dev, 6 * DM1105_DMA_BYTES, dev->ts_buf, in dm1105_dma_unmap()
617 dev->dma_addr); in dm1105_dma_unmap()
636 if (dev->full_ts_users++ == 0) in dm1105_start_feed()
646 if (--dev->full_ts_users == 0) in dm1105_stop_feed()
656 u32 ircom = ir->ir_command; in dm1105_emit_key()
665 rc_keydown(ir->dev, RC_PROTO_UNKNOWN, data, 0); in dm1105_emit_key()
673 u32 oldwrp = dev->wrp; in dm1105_dmx_buffer()
674 u32 nextwrp = dev->nextwrp; in dm1105_dmx_buffer()
676 if (!((dev->ts_buf[oldwrp] == 0x47) && in dm1105_dmx_buffer()
677 (dev->ts_buf[oldwrp + 188] == 0x47) && in dm1105_dmx_buffer()
678 (dev->ts_buf[oldwrp + 188 * 2] == 0x47))) { in dm1105_dmx_buffer()
679 dev->PacketErrorCount++; in dm1105_dmx_buffer()
681 if ((dev->PacketErrorCount >= 2) && in dm1105_dmx_buffer()
682 (dev->dmarst == 0)) { in dm1105_dmx_buffer()
684 dev->wrp = 0; in dm1105_dmx_buffer()
685 dev->PacketErrorCount = 0; in dm1105_dmx_buffer()
686 dev->dmarst = 0; in dm1105_dmx_buffer()
692 memcpy(dev->ts_buf + dev->buffer_size, dev->ts_buf, nextwrp); in dm1105_dmx_buffer()
693 nbpackets = ((dev->buffer_size - oldwrp) + nextwrp) / 188; in dm1105_dmx_buffer()
695 nbpackets = (nextwrp - oldwrp) / 188; in dm1105_dmx_buffer()
697 dev->wrp = nextwrp; in dm1105_dmx_buffer()
698 dvb_dmx_swfilter_packets(&dev->demux, &dev->ts_buf[oldwrp], nbpackets); in dm1105_dmx_buffer()
705 /* Read-Write INSTS Ack's Interrupt for DM1105 chip 16.03.2008 */ in dm1105_irq()
712 dev->nextwrp = dm_readl(DM1105_WRP) - dm_readl(DM1105_STADR); in dm1105_irq()
713 queue_work(dev->wq, &dev->work); in dm1105_irq()
716 dev->ir.ir_command = dm_readl(DM1105_IRCODE); in dm1105_irq()
717 schedule_work(&dev->ir.work); in dm1105_irq()
727 int err = -ENOMEM; in dm1105_ir_init()
731 return -ENOMEM; in dm1105_ir_init()
733 snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys), in dm1105_ir_init()
734 "pci-%s/ir0", pci_name(dm1105->pdev)); in dm1105_ir_init()
736 dev->driver_name = MODULE_NAME; in dm1105_ir_init()
737 dev->map_name = RC_MAP_DM1105_NEC; in dm1105_ir_init()
738 dev->device_name = "DVB on-card IR receiver"; in dm1105_ir_init()
739 dev->input_phys = dm1105->ir.input_phys; in dm1105_ir_init()
740 dev->input_id.bustype = BUS_PCI; in dm1105_ir_init()
741 dev->input_id.version = 1; in dm1105_ir_init()
742 if (dm1105->pdev->subsystem_vendor) { in dm1105_ir_init()
743 dev->input_id.vendor = dm1105->pdev->subsystem_vendor; in dm1105_ir_init()
744 dev->input_id.product = dm1105->pdev->subsystem_device; in dm1105_ir_init()
746 dev->input_id.vendor = dm1105->pdev->vendor; in dm1105_ir_init()
747 dev->input_id.product = dm1105->pdev->device; in dm1105_ir_init()
749 dev->dev.parent = &dm1105->pdev->dev; in dm1105_ir_init()
751 INIT_WORK(&dm1105->ir.work, dm1105_emit_key); in dm1105_ir_init()
759 dm1105->ir.dev = dev; in dm1105_ir_init()
765 rc_unregister_device(dm1105->ir.dev); in dm1105_ir_exit()
845 switch (dev->boardnr) { in frontend_init()
852 dev->fe = dvb_attach( in frontend_init()
854 &dev->i2c_bb_adap); in frontend_init()
855 if (dev->fe) { in frontend_init()
856 dev->fe->ops.set_voltage = dm1105_set_voltage; in frontend_init()
857 dvb_attach(dvb_pll_attach, dev->fe, 0x60, in frontend_init()
858 &dev->i2c_bb_adap, DVB_PLL_OPERA1); in frontend_init()
862 dev->fe = dvb_attach( in frontend_init()
864 &dev->i2c_bb_adap); in frontend_init()
865 if (dev->fe) { in frontend_init()
866 dev->fe->ops.set_voltage = dm1105_set_voltage; in frontend_init()
867 dvb_attach(stb6000_attach, dev->fe, 0x61, in frontend_init()
868 &dev->i2c_bb_adap); in frontend_init()
872 dev->fe = dvb_attach( in frontend_init()
874 &dev->i2c_bb_adap); in frontend_init()
875 if (dev->fe) in frontend_init()
876 dev->fe->ops.set_voltage = dm1105_set_voltage; in frontend_init()
879 dev->fe = dvb_attach( in frontend_init()
881 &dev->i2c_adap); in frontend_init()
882 if (dev->fe) { in frontend_init()
883 dev->fe->ops.set_voltage = dm1105_set_voltage; in frontend_init()
887 dev->fe = dvb_attach( in frontend_init()
889 &dev->i2c_adap); in frontend_init()
890 if (dev->fe) { in frontend_init()
891 dvb_attach(ts2020_attach, dev->fe, in frontend_init()
892 &dvbworld_ts2020_config, &dev->i2c_adap); in frontend_init()
893 dev->fe->ops.set_voltage = dm1105_set_voltage; in frontend_init()
900 dev->fe = dvb_attach( in frontend_init()
902 &dev->i2c_adap); in frontend_init()
903 if (dev->fe) { in frontend_init()
904 dev->fe->ops.set_voltage = dm1105_set_voltage; in frontend_init()
905 dvb_attach(dvb_pll_attach, dev->fe, 0x60, in frontend_init()
906 &dev->i2c_adap, DVB_PLL_OPERA1); in frontend_init()
910 dev->fe = dvb_attach( in frontend_init()
912 &dev->i2c_adap); in frontend_init()
913 if (dev->fe) { in frontend_init()
914 dev->fe->ops.set_voltage = dm1105_set_voltage; in frontend_init()
915 dvb_attach(stb6000_attach, dev->fe, 0x61, in frontend_init()
916 &dev->i2c_adap); in frontend_init()
920 dev->fe = dvb_attach( in frontend_init()
922 &dev->i2c_adap); in frontend_init()
923 if (dev->fe) in frontend_init()
924 dev->fe->ops.set_voltage = dm1105_set_voltage; in frontend_init()
928 if (!dev->fe) { in frontend_init()
929 dev_err(&dev->pdev->dev, "could not attach frontend\n"); in frontend_init()
930 return -ENODEV; in frontend_init()
933 ret = dvb_register_frontend(&dev->dvb_adapter, dev->fe); in frontend_init()
935 if (dev->fe->ops.release) in frontend_init()
936 dev->fe->ops.release(dev->fe); in frontend_init()
937 dev->fe = NULL; in frontend_init()
962 dm1105_i2c_xfer(&dev->i2c_adap, msg , 2); in dm1105_read_mac()
963 dev_info(&dev->pdev->dev, "MAC %pM\n", mac); in dm1105_read_mac()
967 const struct pci_device_id *ent) in dm1105_probe() argument
973 int ret = -ENOMEM; in dm1105_probe()
977 return -ENODEV; in dm1105_probe()
981 return -ENOMEM; in dm1105_probe()
984 dev->nr = dm1105_devcount; in dm1105_probe()
985 dev->boardnr = UNSET; in dm1105_probe()
986 if (card[dev->nr] < ARRAY_SIZE(dm1105_boards)) in dm1105_probe()
987 dev->boardnr = card[dev->nr]; in dm1105_probe()
988 for (i = 0; UNSET == dev->boardnr && in dm1105_probe()
990 if (pdev->subsystem_vendor == in dm1105_probe()
992 pdev->subsystem_device == in dm1105_probe()
994 dev->boardnr = dm1105_subids[i].card; in dm1105_probe()
996 if (UNSET == dev->boardnr) { in dm1105_probe()
997 dev->boardnr = DM1105_BOARD_UNKNOWN; in dm1105_probe()
1002 dev->pdev = pdev; in dm1105_probe()
1003 dev->buffer_size = 5 * DM1105_DMA_BYTES; in dm1105_probe()
1004 dev->PacketErrorCount = 0; in dm1105_probe()
1005 dev->dmarst = 0; in dm1105_probe()
1011 ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); in dm1105_probe()
1021 dev->io_mem = pci_iomap(pdev, 0, pci_resource_len(pdev, 0)); in dm1105_probe()
1022 if (!dev->io_mem) { in dm1105_probe()
1023 ret = -EIO; in dm1105_probe()
1027 spin_lock_init(&dev->lock); in dm1105_probe()
1035 i2c_set_adapdata(&dev->i2c_adap, dev); in dm1105_probe()
1036 strscpy(dev->i2c_adap.name, DRIVER_NAME, sizeof(dev->i2c_adap.name)); in dm1105_probe()
1037 dev->i2c_adap.owner = THIS_MODULE; in dm1105_probe()
1038 dev->i2c_adap.dev.parent = &pdev->dev; in dm1105_probe()
1039 dev->i2c_adap.algo = &dm1105_algo; in dm1105_probe()
1040 dev->i2c_adap.algo_data = dev; in dm1105_probe()
1041 ret = i2c_add_adapter(&dev->i2c_adap); in dm1105_probe()
1046 i2c_set_adapdata(&dev->i2c_bb_adap, dev); in dm1105_probe()
1047 strscpy(dev->i2c_bb_adap.name, DM1105_I2C_GPIO_NAME, in dm1105_probe()
1048 sizeof(dev->i2c_bb_adap.name)); in dm1105_probe()
1049 dev->i2c_bb_adap.owner = THIS_MODULE; in dm1105_probe()
1050 dev->i2c_bb_adap.dev.parent = &pdev->dev; in dm1105_probe()
1051 dev->i2c_bb_adap.algo_data = &dev->i2c_bit; in dm1105_probe()
1052 dev->i2c_bit.data = dev; in dm1105_probe()
1053 dev->i2c_bit.setsda = dm1105_setsda; in dm1105_probe()
1054 dev->i2c_bit.setscl = dm1105_setscl; in dm1105_probe()
1055 dev->i2c_bit.getsda = dm1105_getsda; in dm1105_probe()
1056 dev->i2c_bit.getscl = dm1105_getscl; in dm1105_probe()
1057 dev->i2c_bit.udelay = 10; in dm1105_probe()
1058 dev->i2c_bit.timeout = 10; in dm1105_probe()
1064 ret = i2c_bit_add_bus(&dev->i2c_bb_adap); in dm1105_probe()
1069 ret = dvb_register_adapter(&dev->dvb_adapter, DRIVER_NAME, in dm1105_probe()
1070 THIS_MODULE, &pdev->dev, adapter_nr); in dm1105_probe()
1074 dvb_adapter = &dev->dvb_adapter; in dm1105_probe()
1076 dm1105_read_mac(dev, dvb_adapter->proposed_mac); in dm1105_probe()
1078 dvbdemux = &dev->demux; in dm1105_probe()
1079 dvbdemux->filternum = 256; in dm1105_probe()
1080 dvbdemux->feednum = 256; in dm1105_probe()
1081 dvbdemux->start_feed = dm1105_start_feed; in dm1105_probe()
1082 dvbdemux->stop_feed = dm1105_stop_feed; in dm1105_probe()
1083 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING | in dm1105_probe()
1089 dmx = &dvbdemux->dmx; in dm1105_probe()
1090 dev->dmxdev.filternum = 256; in dm1105_probe()
1091 dev->dmxdev.demux = dmx; in dm1105_probe()
1092 dev->dmxdev.capabilities = 0; in dm1105_probe()
1094 ret = dvb_dmxdev_init(&dev->dmxdev, dvb_adapter); in dm1105_probe()
1098 dev->hw_frontend.source = DMX_FRONTEND_0; in dm1105_probe()
1100 ret = dmx->add_frontend(dmx, &dev->hw_frontend); in dm1105_probe()
1104 dev->mem_frontend.source = DMX_MEMORY_FE; in dm1105_probe()
1106 ret = dmx->add_frontend(dmx, &dev->mem_frontend); in dm1105_probe()
1110 ret = dmx->connect_frontend(dmx, &dev->hw_frontend); in dm1105_probe()
1114 ret = dvb_net_init(dvb_adapter, &dev->dvbnet, dmx); in dm1105_probe()
1124 INIT_WORK(&dev->work, dm1105_dmx_buffer); in dm1105_probe()
1125 sprintf(dev->wqn, "%s/%d", dvb_adapter->name, dvb_adapter->num); in dm1105_probe()
1126 dev->wq = create_singlethread_workqueue(dev->wqn); in dm1105_probe()
1127 if (!dev->wq) { in dm1105_probe()
1128 ret = -ENOMEM; in dm1105_probe()
1132 ret = request_irq(pdev->irq, dm1105_irq, IRQF_SHARED, in dm1105_probe()
1140 destroy_workqueue(dev->wq); in dm1105_probe()
1142 dvb_net_release(&dev->dvbnet); in dm1105_probe()
1144 dmx->disconnect_frontend(dmx); in dm1105_probe()
1146 dmx->remove_frontend(dmx, &dev->mem_frontend); in dm1105_probe()
1148 dmx->remove_frontend(dmx, &dev->hw_frontend); in dm1105_probe()
1150 dvb_dmxdev_release(&dev->dmxdev); in dm1105_probe()
1156 i2c_del_adapter(&dev->i2c_bb_adap); in dm1105_probe()
1158 i2c_del_adapter(&dev->i2c_adap); in dm1105_probe()
1162 pci_iounmap(pdev, dev->io_mem); in dm1105_probe()
1175 struct dvb_adapter *dvb_adapter = &dev->dvb_adapter; in dm1105_remove()
1176 struct dvb_demux *dvbdemux = &dev->demux; in dm1105_remove()
1177 struct dmx_demux *dmx = &dvbdemux->dmx; in dm1105_remove()
1179 cancel_work_sync(&dev->ir.work); in dm1105_remove()
1181 dmx->close(dmx); in dm1105_remove()
1182 dvb_net_release(&dev->dvbnet); in dm1105_remove()
1183 if (dev->fe) in dm1105_remove()
1184 dvb_unregister_frontend(dev->fe); in dm1105_remove()
1186 dmx->disconnect_frontend(dmx); in dm1105_remove()
1187 dmx->remove_frontend(dmx, &dev->mem_frontend); in dm1105_remove()
1188 dmx->remove_frontend(dmx, &dev->hw_frontend); in dm1105_remove()
1189 dvb_dmxdev_release(&dev->dmxdev); in dm1105_remove()
1192 i2c_del_adapter(&dev->i2c_adap); in dm1105_remove()
1195 free_irq(pdev->irq, dev); in dm1105_remove()
1196 pci_iounmap(pdev, dev->io_mem); in dm1105_remove()
1199 dm1105_devcount--; in dm1105_remove()