Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1 | /* |
| 2 | * dm1105.c - driver for DVB cards based on SDMC DM1105 PCI chip |
| 3 | * |
| 4 | * Copyright (C) 2008 Igor M. Liplianin <liplianin@me.by> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 16 | */ |
| 17 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 18 | #include <linux/i2c.h> |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 19 | #include <linux/i2c-algo-bit.h> |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 20 | #include <linux/init.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 21 | #include <linux/interrupt.h> |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/proc_fs.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/dma-mapping.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Mauro Carvalho Chehab | 6bda964 | 2010-11-17 13:28:38 -0300 | [diff] [blame] | 28 | #include <media/rc-core.h> |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 29 | |
| 30 | #include "demux.h" |
| 31 | #include "dmxdev.h" |
| 32 | #include "dvb_demux.h" |
| 33 | #include "dvb_frontend.h" |
| 34 | #include "dvb_net.h" |
| 35 | #include "dvbdev.h" |
| 36 | #include "dvb-pll.h" |
| 37 | |
| 38 | #include "stv0299.h" |
Igor M. Liplianin | e4aab64 | 2008-09-23 15:43:57 -0300 | [diff] [blame] | 39 | #include "stv0288.h" |
| 40 | #include "stb6000.h" |
Igor M. Liplianin | 04ad28c | 2008-09-16 18:21:11 -0300 | [diff] [blame] | 41 | #include "si21xx.h" |
Igor M. Liplianin | 35d9c42 | 2008-09-13 20:56:59 -0300 | [diff] [blame] | 42 | #include "cx24116.h" |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 43 | #include "z0194a.h" |
Konstantin Dimitrov | 73f0af4 | 2012-12-23 19:25:38 -0300 | [diff] [blame] | 44 | #include "ts2020.h" |
Igor M. Liplianin | b4a0e81 | 2010-01-17 10:32:26 -0300 | [diff] [blame] | 45 | #include "ds3000.h" |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 46 | |
Mauro Carvalho Chehab | 727e625 | 2010-03-12 21:18:14 -0300 | [diff] [blame] | 47 | #define MODULE_NAME "dm1105" |
| 48 | |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 49 | #define UNSET (-1U) |
| 50 | |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 51 | #define DM1105_BOARD_NOAUTO UNSET |
| 52 | #define DM1105_BOARD_UNKNOWN 0 |
| 53 | #define DM1105_BOARD_DVBWORLD_2002 1 |
| 54 | #define DM1105_BOARD_DVBWORLD_2004 2 |
| 55 | #define DM1105_BOARD_AXESS_DM05 3 |
| 56 | #define DM1105_BOARD_UNBRANDED_I2C_ON_GPIO 4 |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 57 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 58 | /* ----------------------------------------------- */ |
| 59 | /* |
| 60 | * PCI ID's |
| 61 | */ |
| 62 | #ifndef PCI_VENDOR_ID_TRIGEM |
| 63 | #define PCI_VENDOR_ID_TRIGEM 0x109f |
| 64 | #endif |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 65 | #ifndef PCI_VENDOR_ID_AXESS |
| 66 | #define PCI_VENDOR_ID_AXESS 0x195d |
| 67 | #endif |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 68 | #ifndef PCI_DEVICE_ID_DM1105 |
| 69 | #define PCI_DEVICE_ID_DM1105 0x036f |
| 70 | #endif |
| 71 | #ifndef PCI_DEVICE_ID_DW2002 |
| 72 | #define PCI_DEVICE_ID_DW2002 0x2002 |
| 73 | #endif |
| 74 | #ifndef PCI_DEVICE_ID_DW2004 |
| 75 | #define PCI_DEVICE_ID_DW2004 0x2004 |
| 76 | #endif |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 77 | #ifndef PCI_DEVICE_ID_DM05 |
| 78 | #define PCI_DEVICE_ID_DM05 0x1105 |
| 79 | #endif |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 80 | /* ----------------------------------------------- */ |
| 81 | /* sdmc dm1105 registers */ |
| 82 | |
| 83 | /* TS Control */ |
| 84 | #define DM1105_TSCTR 0x00 |
| 85 | #define DM1105_DTALENTH 0x04 |
| 86 | |
| 87 | /* GPIO Interface */ |
| 88 | #define DM1105_GPIOVAL 0x08 |
| 89 | #define DM1105_GPIOCTR 0x0c |
| 90 | |
| 91 | /* PID serial number */ |
| 92 | #define DM1105_PIDN 0x10 |
| 93 | |
| 94 | /* Odd-even secret key select */ |
| 95 | #define DM1105_CWSEL 0x14 |
| 96 | |
| 97 | /* Host Command Interface */ |
| 98 | #define DM1105_HOST_CTR 0x18 |
| 99 | #define DM1105_HOST_AD 0x1c |
| 100 | |
| 101 | /* PCI Interface */ |
| 102 | #define DM1105_CR 0x30 |
| 103 | #define DM1105_RST 0x34 |
| 104 | #define DM1105_STADR 0x38 |
| 105 | #define DM1105_RLEN 0x3c |
| 106 | #define DM1105_WRP 0x40 |
| 107 | #define DM1105_INTCNT 0x44 |
| 108 | #define DM1105_INTMAK 0x48 |
| 109 | #define DM1105_INTSTS 0x4c |
| 110 | |
| 111 | /* CW Value */ |
| 112 | #define DM1105_ODD 0x50 |
| 113 | #define DM1105_EVEN 0x58 |
| 114 | |
| 115 | /* PID Value */ |
| 116 | #define DM1105_PID 0x60 |
| 117 | |
| 118 | /* IR Control */ |
| 119 | #define DM1105_IRCTR 0x64 |
| 120 | #define DM1105_IRMODE 0x68 |
| 121 | #define DM1105_SYSTEMCODE 0x6c |
| 122 | #define DM1105_IRCODE 0x70 |
| 123 | |
| 124 | /* Unknown Values */ |
| 125 | #define DM1105_ENCRYPT 0x74 |
| 126 | #define DM1105_VER 0x7c |
| 127 | |
| 128 | /* I2C Interface */ |
| 129 | #define DM1105_I2CCTR 0x80 |
| 130 | #define DM1105_I2CSTS 0x81 |
| 131 | #define DM1105_I2CDAT 0x82 |
| 132 | #define DM1105_I2C_RA 0x83 |
| 133 | /* ----------------------------------------------- */ |
| 134 | /* Interrupt Mask Bits */ |
| 135 | |
| 136 | #define INTMAK_TSIRQM 0x01 |
| 137 | #define INTMAK_HIRQM 0x04 |
| 138 | #define INTMAK_IRM 0x08 |
| 139 | #define INTMAK_ALLMASK (INTMAK_TSIRQM | \ |
| 140 | INTMAK_HIRQM | \ |
| 141 | INTMAK_IRM) |
| 142 | #define INTMAK_NONEMASK 0x00 |
| 143 | |
| 144 | /* Interrupt Status Bits */ |
| 145 | #define INTSTS_TSIRQ 0x01 |
| 146 | #define INTSTS_HIRQ 0x04 |
| 147 | #define INTSTS_IR 0x08 |
| 148 | |
| 149 | /* IR Control Bits */ |
| 150 | #define DM1105_IR_EN 0x01 |
| 151 | #define DM1105_SYS_CHK 0x02 |
| 152 | #define DM1105_REP_FLG 0x08 |
| 153 | |
| 154 | /* EEPROM addr */ |
| 155 | #define IIC_24C01_addr 0xa0 |
| 156 | /* Max board count */ |
| 157 | #define DM1105_MAX 0x04 |
| 158 | |
| 159 | #define DRIVER_NAME "dm1105" |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 160 | #define DM1105_I2C_GPIO_NAME "dm1105-gpio" |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 161 | |
| 162 | #define DM1105_DMA_PACKETS 47 |
| 163 | #define DM1105_DMA_PACKET_LENGTH (128*4) |
| 164 | #define DM1105_DMA_BYTES (128 * 4 * DM1105_DMA_PACKETS) |
| 165 | |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 166 | /* */ |
| 167 | #define GPIO08 (1 << 8) |
| 168 | #define GPIO13 (1 << 13) |
| 169 | #define GPIO14 (1 << 14) |
| 170 | #define GPIO15 (1 << 15) |
| 171 | #define GPIO16 (1 << 16) |
| 172 | #define GPIO17 (1 << 17) |
| 173 | #define GPIO_ALL 0x03ffff |
| 174 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 175 | /* GPIO's for LNB power control */ |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 176 | #define DM1105_LNB_MASK (GPIO_ALL & ~(GPIO14 | GPIO13)) |
| 177 | #define DM1105_LNB_OFF GPIO17 |
| 178 | #define DM1105_LNB_13V (GPIO16 | GPIO08) |
| 179 | #define DM1105_LNB_18V GPIO08 |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 180 | |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 181 | /* GPIO's for LNB power control for Axess DM05 */ |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 182 | #define DM05_LNB_MASK (GPIO_ALL & ~(GPIO14 | GPIO13)) |
| 183 | #define DM05_LNB_OFF GPIO17/* actually 13v */ |
| 184 | #define DM05_LNB_13V GPIO17 |
| 185 | #define DM05_LNB_18V (GPIO17 | GPIO16) |
| 186 | |
| 187 | /* GPIO's for LNB power control for unbranded with I2C on GPIO */ |
| 188 | #define UNBR_LNB_MASK (GPIO17 | GPIO16) |
| 189 | #define UNBR_LNB_OFF 0 |
| 190 | #define UNBR_LNB_13V GPIO17 |
| 191 | #define UNBR_LNB_18V (GPIO17 | GPIO16) |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 192 | |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 193 | static unsigned int card[] = {[0 ... 3] = UNSET }; |
| 194 | module_param_array(card, int, NULL, 0444); |
| 195 | MODULE_PARM_DESC(card, "card type"); |
| 196 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 197 | static int ir_debug; |
| 198 | module_param(ir_debug, int, 0644); |
| 199 | MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding"); |
| 200 | |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 201 | static unsigned int dm1105_devcount; |
| 202 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 203 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 204 | |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 205 | struct dm1105_board { |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 206 | char *name; |
| 207 | struct { |
| 208 | u32 mask, off, v13, v18; |
| 209 | } lnb; |
| 210 | u32 gpio_scl, gpio_sda; |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | struct dm1105_subid { |
| 214 | u16 subvendor; |
| 215 | u16 subdevice; |
| 216 | u32 card; |
| 217 | }; |
| 218 | |
| 219 | static const struct dm1105_board dm1105_boards[] = { |
| 220 | [DM1105_BOARD_UNKNOWN] = { |
| 221 | .name = "UNKNOWN/GENERIC", |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 222 | .lnb = { |
| 223 | .mask = DM1105_LNB_MASK, |
| 224 | .off = DM1105_LNB_OFF, |
| 225 | .v13 = DM1105_LNB_13V, |
| 226 | .v18 = DM1105_LNB_18V, |
| 227 | }, |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 228 | }, |
| 229 | [DM1105_BOARD_DVBWORLD_2002] = { |
| 230 | .name = "DVBWorld PCI 2002", |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 231 | .lnb = { |
| 232 | .mask = DM1105_LNB_MASK, |
| 233 | .off = DM1105_LNB_OFF, |
| 234 | .v13 = DM1105_LNB_13V, |
| 235 | .v18 = DM1105_LNB_18V, |
| 236 | }, |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 237 | }, |
| 238 | [DM1105_BOARD_DVBWORLD_2004] = { |
| 239 | .name = "DVBWorld PCI 2004", |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 240 | .lnb = { |
| 241 | .mask = DM1105_LNB_MASK, |
| 242 | .off = DM1105_LNB_OFF, |
| 243 | .v13 = DM1105_LNB_13V, |
| 244 | .v18 = DM1105_LNB_18V, |
| 245 | }, |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 246 | }, |
| 247 | [DM1105_BOARD_AXESS_DM05] = { |
| 248 | .name = "Axess/EasyTv DM05", |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 249 | .lnb = { |
| 250 | .mask = DM05_LNB_MASK, |
| 251 | .off = DM05_LNB_OFF, |
| 252 | .v13 = DM05_LNB_13V, |
| 253 | .v18 = DM05_LNB_18V, |
| 254 | }, |
| 255 | }, |
| 256 | [DM1105_BOARD_UNBRANDED_I2C_ON_GPIO] = { |
| 257 | .name = "Unbranded DM1105 with i2c on GPIOs", |
| 258 | .lnb = { |
| 259 | .mask = UNBR_LNB_MASK, |
| 260 | .off = UNBR_LNB_OFF, |
| 261 | .v13 = UNBR_LNB_13V, |
| 262 | .v18 = UNBR_LNB_18V, |
| 263 | }, |
| 264 | .gpio_scl = GPIO14, |
| 265 | .gpio_sda = GPIO13, |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 266 | }, |
| 267 | }; |
| 268 | |
| 269 | static const struct dm1105_subid dm1105_subids[] = { |
| 270 | { |
| 271 | .subvendor = 0x0000, |
| 272 | .subdevice = 0x2002, |
| 273 | .card = DM1105_BOARD_DVBWORLD_2002, |
| 274 | }, { |
| 275 | .subvendor = 0x0001, |
| 276 | .subdevice = 0x2002, |
| 277 | .card = DM1105_BOARD_DVBWORLD_2002, |
| 278 | }, { |
| 279 | .subvendor = 0x0000, |
| 280 | .subdevice = 0x2004, |
| 281 | .card = DM1105_BOARD_DVBWORLD_2004, |
| 282 | }, { |
| 283 | .subvendor = 0x0001, |
| 284 | .subdevice = 0x2004, |
| 285 | .card = DM1105_BOARD_DVBWORLD_2004, |
| 286 | }, { |
| 287 | .subvendor = 0x195d, |
| 288 | .subdevice = 0x1105, |
| 289 | .card = DM1105_BOARD_AXESS_DM05, |
| 290 | }, |
| 291 | }; |
| 292 | |
| 293 | static void dm1105_card_list(struct pci_dev *pci) |
| 294 | { |
| 295 | int i; |
| 296 | |
| 297 | if (0 == pci->subsystem_vendor && |
| 298 | 0 == pci->subsystem_device) { |
| 299 | printk(KERN_ERR |
| 300 | "dm1105: Your board has no valid PCI Subsystem ID\n" |
| 301 | "dm1105: and thus can't be autodetected\n" |
| 302 | "dm1105: Please pass card=<n> insmod option to\n" |
| 303 | "dm1105: workaround that. Redirect complaints to\n" |
| 304 | "dm1105: the vendor of the TV card. Best regards,\n" |
| 305 | "dm1105: -- tux\n"); |
| 306 | } else { |
| 307 | printk(KERN_ERR |
| 308 | "dm1105: Your board isn't known (yet) to the driver.\n" |
| 309 | "dm1105: You can try to pick one of the existing\n" |
| 310 | "dm1105: card configs via card=<n> insmod option.\n" |
| 311 | "dm1105: Updating to the latest version might help\n" |
| 312 | "dm1105: as well.\n"); |
| 313 | } |
Mauro Carvalho Chehab | 0e8aebb | 2016-10-18 17:44:04 -0200 | [diff] [blame] | 314 | printk(KERN_ERR "Here is a list of valid choices for the card=<n> insmod option:\n"); |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 315 | for (i = 0; i < ARRAY_SIZE(dm1105_boards); i++) |
| 316 | printk(KERN_ERR "dm1105: card=%d -> %s\n", |
| 317 | i, dm1105_boards[i].name); |
| 318 | } |
| 319 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 320 | /* infrared remote control */ |
| 321 | struct infrared { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 322 | struct rc_dev *dev; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 323 | char input_phys[32]; |
Igor M. Liplianin | b72857d | 2009-02-26 03:49:44 -0300 | [diff] [blame] | 324 | struct work_struct work; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 325 | u32 ir_command; |
| 326 | }; |
| 327 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 328 | struct dm1105_dev { |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 329 | /* pci */ |
| 330 | struct pci_dev *pdev; |
| 331 | u8 __iomem *io_mem; |
| 332 | |
| 333 | /* ir */ |
| 334 | struct infrared ir; |
| 335 | |
| 336 | /* dvb */ |
| 337 | struct dmx_frontend hw_frontend; |
| 338 | struct dmx_frontend mem_frontend; |
| 339 | struct dmxdev dmxdev; |
| 340 | struct dvb_adapter dvb_adapter; |
| 341 | struct dvb_demux demux; |
| 342 | struct dvb_frontend *fe; |
| 343 | struct dvb_net dvbnet; |
| 344 | unsigned int full_ts_users; |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 345 | unsigned int boardnr; |
| 346 | int nr; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 347 | |
| 348 | /* i2c */ |
| 349 | struct i2c_adapter i2c_adap; |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 350 | struct i2c_adapter i2c_bb_adap; |
| 351 | struct i2c_algo_bit_data i2c_bit; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 352 | |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 353 | /* irq */ |
| 354 | struct work_struct work; |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 355 | struct workqueue_struct *wq; |
| 356 | char wqn[16]; |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 357 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 358 | /* dma */ |
| 359 | dma_addr_t dma_addr; |
| 360 | unsigned char *ts_buf; |
| 361 | u32 wrp; |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 362 | u32 nextwrp; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 363 | u32 buffer_size; |
| 364 | unsigned int PacketErrorCount; |
| 365 | unsigned int dmarst; |
| 366 | spinlock_t lock; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 367 | }; |
| 368 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 369 | #define dm_io_mem(reg) ((unsigned long)(&dev->io_mem[reg])) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 370 | |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 371 | #define dm_readb(reg) inb(dm_io_mem(reg)) |
| 372 | #define dm_writeb(reg, value) outb((value), (dm_io_mem(reg))) |
| 373 | |
| 374 | #define dm_readw(reg) inw(dm_io_mem(reg)) |
| 375 | #define dm_writew(reg, value) outw((value), (dm_io_mem(reg))) |
| 376 | |
| 377 | #define dm_readl(reg) inl(dm_io_mem(reg)) |
| 378 | #define dm_writel(reg, value) outl((value), (dm_io_mem(reg))) |
| 379 | |
| 380 | #define dm_andorl(reg, mask, value) \ |
| 381 | outl((inl(dm_io_mem(reg)) & ~(mask)) |\ |
| 382 | ((value) & (mask)), (dm_io_mem(reg))) |
| 383 | |
| 384 | #define dm_setl(reg, bit) dm_andorl((reg), (bit), (bit)) |
| 385 | #define dm_clearl(reg, bit) dm_andorl((reg), (bit), 0) |
| 386 | |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 387 | /* The chip has 18 GPIOs. In HOST mode GPIO's used as 15 bit address lines, |
| 388 | so we can use only 3 GPIO's from GPIO15 to GPIO17. |
| 389 | Here I don't check whether HOST is enebled as it is not implemented yet. |
| 390 | */ |
| 391 | static void dm1105_gpio_set(struct dm1105_dev *dev, u32 mask) |
| 392 | { |
| 393 | if (mask & 0xfffc0000) |
| 394 | printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__); |
| 395 | |
| 396 | if (mask & 0x0003ffff) |
| 397 | dm_setl(DM1105_GPIOVAL, mask & 0x0003ffff); |
| 398 | |
| 399 | } |
| 400 | |
| 401 | static void dm1105_gpio_clear(struct dm1105_dev *dev, u32 mask) |
| 402 | { |
| 403 | if (mask & 0xfffc0000) |
| 404 | printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__); |
| 405 | |
| 406 | if (mask & 0x0003ffff) |
| 407 | dm_clearl(DM1105_GPIOVAL, mask & 0x0003ffff); |
| 408 | |
| 409 | } |
| 410 | |
| 411 | static void dm1105_gpio_andor(struct dm1105_dev *dev, u32 mask, u32 val) |
| 412 | { |
| 413 | if (mask & 0xfffc0000) |
| 414 | printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__); |
| 415 | |
| 416 | if (mask & 0x0003ffff) |
| 417 | dm_andorl(DM1105_GPIOVAL, mask & 0x0003ffff, val); |
| 418 | |
| 419 | } |
| 420 | |
| 421 | static u32 dm1105_gpio_get(struct dm1105_dev *dev, u32 mask) |
| 422 | { |
| 423 | if (mask & 0xfffc0000) |
| 424 | printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__); |
| 425 | |
| 426 | if (mask & 0x0003ffff) |
| 427 | return dm_readl(DM1105_GPIOVAL) & mask & 0x0003ffff; |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | static void dm1105_gpio_enable(struct dm1105_dev *dev, u32 mask, int asoutput) |
| 433 | { |
| 434 | if (mask & 0xfffc0000) |
| 435 | printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__); |
| 436 | |
| 437 | if ((mask & 0x0003ffff) && asoutput) |
| 438 | dm_clearl(DM1105_GPIOCTR, mask & 0x0003ffff); |
| 439 | else if ((mask & 0x0003ffff) && !asoutput) |
| 440 | dm_setl(DM1105_GPIOCTR, mask & 0x0003ffff); |
| 441 | |
| 442 | } |
| 443 | |
| 444 | static void dm1105_setline(struct dm1105_dev *dev, u32 line, int state) |
| 445 | { |
| 446 | if (state) |
| 447 | dm1105_gpio_enable(dev, line, 0); |
| 448 | else { |
| 449 | dm1105_gpio_enable(dev, line, 1); |
| 450 | dm1105_gpio_clear(dev, line); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | static void dm1105_setsda(void *data, int state) |
| 455 | { |
| 456 | struct dm1105_dev *dev = data; |
| 457 | |
| 458 | dm1105_setline(dev, dm1105_boards[dev->boardnr].gpio_sda, state); |
| 459 | } |
| 460 | |
| 461 | static void dm1105_setscl(void *data, int state) |
| 462 | { |
| 463 | struct dm1105_dev *dev = data; |
| 464 | |
| 465 | dm1105_setline(dev, dm1105_boards[dev->boardnr].gpio_scl, state); |
| 466 | } |
| 467 | |
| 468 | static int dm1105_getsda(void *data) |
| 469 | { |
| 470 | struct dm1105_dev *dev = data; |
| 471 | |
| 472 | return dm1105_gpio_get(dev, dm1105_boards[dev->boardnr].gpio_sda) |
| 473 | ? 1 : 0; |
| 474 | } |
| 475 | |
| 476 | static int dm1105_getscl(void *data) |
| 477 | { |
| 478 | struct dm1105_dev *dev = data; |
| 479 | |
| 480 | return dm1105_gpio_get(dev, dm1105_boards[dev->boardnr].gpio_scl) |
| 481 | ? 1 : 0; |
| 482 | } |
| 483 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 484 | static int dm1105_i2c_xfer(struct i2c_adapter *i2c_adap, |
| 485 | struct i2c_msg *msgs, int num) |
| 486 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 487 | struct dm1105_dev *dev ; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 488 | |
| 489 | int addr, rc, i, j, k, len, byte, data; |
| 490 | u8 status; |
| 491 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 492 | dev = i2c_adap->algo_data; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 493 | for (i = 0; i < num; i++) { |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 494 | dm_writeb(DM1105_I2CCTR, 0x00); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 495 | if (msgs[i].flags & I2C_M_RD) { |
| 496 | /* read bytes */ |
| 497 | addr = msgs[i].addr << 1; |
| 498 | addr |= 1; |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 499 | dm_writeb(DM1105_I2CDAT, addr); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 500 | for (byte = 0; byte < msgs[i].len; byte++) |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 501 | dm_writeb(DM1105_I2CDAT + byte + 1, 0); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 502 | |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 503 | dm_writeb(DM1105_I2CCTR, 0x81 + msgs[i].len); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 504 | for (j = 0; j < 55; j++) { |
| 505 | mdelay(10); |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 506 | status = dm_readb(DM1105_I2CSTS); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 507 | if ((status & 0xc0) == 0x40) |
| 508 | break; |
| 509 | } |
| 510 | if (j >= 55) |
| 511 | return -1; |
| 512 | |
| 513 | for (byte = 0; byte < msgs[i].len; byte++) { |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 514 | rc = dm_readb(DM1105_I2CDAT + byte + 1); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 515 | if (rc < 0) |
| 516 | goto err; |
| 517 | msgs[i].buf[byte] = rc; |
| 518 | } |
Igor M. Liplianin | ed7c847 | 2010-01-17 11:15:06 -0300 | [diff] [blame] | 519 | } else if ((msgs[i].buf[0] == 0xf7) && (msgs[i].addr == 0x55)) { |
| 520 | /* prepaired for cx24116 firmware */ |
| 521 | /* Write in small blocks */ |
| 522 | len = msgs[i].len - 1; |
| 523 | k = 1; |
| 524 | do { |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 525 | dm_writeb(DM1105_I2CDAT, msgs[i].addr << 1); |
| 526 | dm_writeb(DM1105_I2CDAT + 1, 0xf7); |
Igor M. Liplianin | ed7c847 | 2010-01-17 11:15:06 -0300 | [diff] [blame] | 527 | for (byte = 0; byte < (len > 48 ? 48 : len); byte++) { |
| 528 | data = msgs[i].buf[k + byte]; |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 529 | dm_writeb(DM1105_I2CDAT + byte + 2, data); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 530 | } |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 531 | dm_writeb(DM1105_I2CCTR, 0x82 + (len > 48 ? 48 : len)); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 532 | for (j = 0; j < 25; j++) { |
| 533 | mdelay(10); |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 534 | status = dm_readb(DM1105_I2CSTS); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 535 | if ((status & 0xc0) == 0x40) |
| 536 | break; |
| 537 | } |
| 538 | |
| 539 | if (j >= 25) |
| 540 | return -1; |
Igor M. Liplianin | ed7c847 | 2010-01-17 11:15:06 -0300 | [diff] [blame] | 541 | |
| 542 | k += 48; |
| 543 | len -= 48; |
| 544 | } while (len > 0); |
| 545 | } else { |
| 546 | /* write bytes */ |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 547 | dm_writeb(DM1105_I2CDAT, msgs[i].addr << 1); |
Igor M. Liplianin | ed7c847 | 2010-01-17 11:15:06 -0300 | [diff] [blame] | 548 | for (byte = 0; byte < msgs[i].len; byte++) { |
| 549 | data = msgs[i].buf[byte]; |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 550 | dm_writeb(DM1105_I2CDAT + byte + 1, data); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 551 | } |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 552 | dm_writeb(DM1105_I2CCTR, 0x81 + msgs[i].len); |
Igor M. Liplianin | ed7c847 | 2010-01-17 11:15:06 -0300 | [diff] [blame] | 553 | for (j = 0; j < 25; j++) { |
| 554 | mdelay(10); |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 555 | status = dm_readb(DM1105_I2CSTS); |
Igor M. Liplianin | ed7c847 | 2010-01-17 11:15:06 -0300 | [diff] [blame] | 556 | if ((status & 0xc0) == 0x40) |
| 557 | break; |
| 558 | } |
| 559 | |
| 560 | if (j >= 25) |
| 561 | return -1; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | return num; |
| 565 | err: |
| 566 | return rc; |
| 567 | } |
| 568 | |
| 569 | static u32 functionality(struct i2c_adapter *adap) |
| 570 | { |
| 571 | return I2C_FUNC_I2C; |
| 572 | } |
| 573 | |
Gustavo A. R. Silva | 3c13978 | 2017-07-09 21:19:36 -0400 | [diff] [blame] | 574 | static const struct i2c_algorithm dm1105_algo = { |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 575 | .master_xfer = dm1105_i2c_xfer, |
| 576 | .functionality = functionality, |
| 577 | }; |
| 578 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 579 | static inline struct dm1105_dev *feed_to_dm1105_dev(struct dvb_demux_feed *feed) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 580 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 581 | return container_of(feed->demux, struct dm1105_dev, demux); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 582 | } |
| 583 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 584 | static inline struct dm1105_dev *frontend_to_dm1105_dev(struct dvb_frontend *fe) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 585 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 586 | return container_of(fe->dvb, struct dm1105_dev, dvb_adapter); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 587 | } |
| 588 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 589 | static int dm1105_set_voltage(struct dvb_frontend *fe, |
| 590 | enum fe_sec_voltage voltage) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 591 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 592 | struct dm1105_dev *dev = frontend_to_dm1105_dev(fe); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 593 | |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 594 | dm1105_gpio_enable(dev, dm1105_boards[dev->boardnr].lnb.mask, 1); |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 595 | if (voltage == SEC_VOLTAGE_18) |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 596 | dm1105_gpio_andor(dev, |
| 597 | dm1105_boards[dev->boardnr].lnb.mask, |
| 598 | dm1105_boards[dev->boardnr].lnb.v18); |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 599 | else if (voltage == SEC_VOLTAGE_13) |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 600 | dm1105_gpio_andor(dev, |
| 601 | dm1105_boards[dev->boardnr].lnb.mask, |
| 602 | dm1105_boards[dev->boardnr].lnb.v13); |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 603 | else |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 604 | dm1105_gpio_andor(dev, |
| 605 | dm1105_boards[dev->boardnr].lnb.mask, |
| 606 | dm1105_boards[dev->boardnr].lnb.off); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 607 | |
| 608 | return 0; |
| 609 | } |
| 610 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 611 | static void dm1105_set_dma_addr(struct dm1105_dev *dev) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 612 | { |
Hans Verkuil | 888bd5d | 2014-08-21 11:50:34 -0300 | [diff] [blame] | 613 | dm_writel(DM1105_STADR, (__force u32)cpu_to_le32(dev->dma_addr)); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 614 | } |
| 615 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 616 | static int dm1105_dma_map(struct dm1105_dev *dev) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 617 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 618 | dev->ts_buf = pci_alloc_consistent(dev->pdev, |
| 619 | 6 * DM1105_DMA_BYTES, |
| 620 | &dev->dma_addr); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 621 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 622 | return !dev->ts_buf; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 623 | } |
| 624 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 625 | static void dm1105_dma_unmap(struct dm1105_dev *dev) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 626 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 627 | pci_free_consistent(dev->pdev, |
| 628 | 6 * DM1105_DMA_BYTES, |
| 629 | dev->ts_buf, |
| 630 | dev->dma_addr); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 631 | } |
| 632 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 633 | static void dm1105_enable_irqs(struct dm1105_dev *dev) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 634 | { |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 635 | dm_writeb(DM1105_INTMAK, INTMAK_ALLMASK); |
| 636 | dm_writeb(DM1105_CR, 1); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 637 | } |
| 638 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 639 | static void dm1105_disable_irqs(struct dm1105_dev *dev) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 640 | { |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 641 | dm_writeb(DM1105_INTMAK, INTMAK_IRM); |
| 642 | dm_writeb(DM1105_CR, 0); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 643 | } |
| 644 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 645 | static int dm1105_start_feed(struct dvb_demux_feed *f) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 646 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 647 | struct dm1105_dev *dev = feed_to_dm1105_dev(f); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 648 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 649 | if (dev->full_ts_users++ == 0) |
| 650 | dm1105_enable_irqs(dev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 651 | |
| 652 | return 0; |
| 653 | } |
| 654 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 655 | static int dm1105_stop_feed(struct dvb_demux_feed *f) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 656 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 657 | struct dm1105_dev *dev = feed_to_dm1105_dev(f); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 658 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 659 | if (--dev->full_ts_users == 0) |
| 660 | dm1105_disable_irqs(dev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 661 | |
| 662 | return 0; |
| 663 | } |
| 664 | |
Igor M. Liplianin | b72857d | 2009-02-26 03:49:44 -0300 | [diff] [blame] | 665 | /* ir work handler */ |
| 666 | static void dm1105_emit_key(struct work_struct *work) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 667 | { |
Igor M. Liplianin | b72857d | 2009-02-26 03:49:44 -0300 | [diff] [blame] | 668 | struct infrared *ir = container_of(work, struct infrared, work); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 669 | u32 ircom = ir->ir_command; |
| 670 | u8 data; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 671 | |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 672 | if (ir_debug) |
| 673 | printk(KERN_INFO "%s: received byte 0x%04x\n", __func__, ircom); |
| 674 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 675 | data = (ircom >> 8) & 0x7f; |
| 676 | |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 677 | /* FIXME: UNKNOWN because we don't generate a full NEC scancode (yet?) */ |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 678 | rc_keydown(ir->dev, RC_PROTO_UNKNOWN, data, 0); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 679 | } |
| 680 | |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 681 | /* work handler */ |
| 682 | static void dm1105_dmx_buffer(struct work_struct *work) |
| 683 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 684 | struct dm1105_dev *dev = container_of(work, struct dm1105_dev, work); |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 685 | unsigned int nbpackets; |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 686 | u32 oldwrp = dev->wrp; |
| 687 | u32 nextwrp = dev->nextwrp; |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 688 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 689 | if (!((dev->ts_buf[oldwrp] == 0x47) && |
| 690 | (dev->ts_buf[oldwrp + 188] == 0x47) && |
| 691 | (dev->ts_buf[oldwrp + 188 * 2] == 0x47))) { |
| 692 | dev->PacketErrorCount++; |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 693 | /* bad packet found */ |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 694 | if ((dev->PacketErrorCount >= 2) && |
| 695 | (dev->dmarst == 0)) { |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 696 | dm_writeb(DM1105_RST, 1); |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 697 | dev->wrp = 0; |
| 698 | dev->PacketErrorCount = 0; |
| 699 | dev->dmarst = 0; |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 700 | return; |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | if (nextwrp < oldwrp) { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 705 | memcpy(dev->ts_buf + dev->buffer_size, dev->ts_buf, nextwrp); |
| 706 | nbpackets = ((dev->buffer_size - oldwrp) + nextwrp) / 188; |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 707 | } else |
| 708 | nbpackets = (nextwrp - oldwrp) / 188; |
| 709 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 710 | dev->wrp = nextwrp; |
| 711 | dvb_dmx_swfilter_packets(&dev->demux, &dev->ts_buf[oldwrp], nbpackets); |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 712 | } |
| 713 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 714 | static irqreturn_t dm1105_irq(int irq, void *dev_id) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 715 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 716 | struct dm1105_dev *dev = dev_id; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 717 | |
| 718 | /* Read-Write INSTS Ack's Interrupt for DM1105 chip 16.03.2008 */ |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 719 | unsigned int intsts = dm_readb(DM1105_INTSTS); |
| 720 | dm_writeb(DM1105_INTSTS, intsts); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 721 | |
| 722 | switch (intsts) { |
| 723 | case INTSTS_TSIRQ: |
| 724 | case (INTSTS_TSIRQ | INTSTS_IR): |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 725 | dev->nextwrp = dm_readl(DM1105_WRP) - dm_readl(DM1105_STADR); |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 726 | queue_work(dev->wq, &dev->work); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 727 | break; |
| 728 | case INTSTS_IR: |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 729 | dev->ir.ir_command = dm_readl(DM1105_IRCODE); |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 730 | schedule_work(&dev->ir.work); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 731 | break; |
| 732 | } |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 733 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 734 | return IRQ_HANDLED; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 735 | } |
| 736 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 737 | static int dm1105_ir_init(struct dm1105_dev *dm1105) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 738 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 739 | struct rc_dev *dev; |
Igor M. Liplianin | b72857d | 2009-02-26 03:49:44 -0300 | [diff] [blame] | 740 | int err = -ENOMEM; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 741 | |
Andi Shyti | 0f7499f | 2016-12-16 06:50:58 -0200 | [diff] [blame] | 742 | dev = rc_allocate_device(RC_DRIVER_SCANCODE); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 743 | if (!dev) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 744 | return -ENOMEM; |
| 745 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 746 | snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys), |
| 747 | "pci-%s/ir0", pci_name(dm1105->pdev)); |
| 748 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 749 | dev->driver_name = MODULE_NAME; |
| 750 | dev->map_name = RC_MAP_DM1105_NEC; |
Sean Young | 518f4b2 | 2017-07-01 12:13:19 -0400 | [diff] [blame] | 751 | dev->device_name = "DVB on-card IR receiver"; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 752 | dev->input_phys = dm1105->ir.input_phys; |
| 753 | dev->input_id.bustype = BUS_PCI; |
| 754 | dev->input_id.version = 1; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 755 | if (dm1105->pdev->subsystem_vendor) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 756 | dev->input_id.vendor = dm1105->pdev->subsystem_vendor; |
| 757 | dev->input_id.product = dm1105->pdev->subsystem_device; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 758 | } else { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 759 | dev->input_id.vendor = dm1105->pdev->vendor; |
| 760 | dev->input_id.product = dm1105->pdev->device; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 761 | } |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 762 | dev->dev.parent = &dm1105->pdev->dev; |
Igor M. Liplianin | b72857d | 2009-02-26 03:49:44 -0300 | [diff] [blame] | 763 | |
| 764 | INIT_WORK(&dm1105->ir.work, dm1105_emit_key); |
| 765 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 766 | err = rc_register_device(dev); |
David Härdeman | 15100d8 | 2010-04-15 18:46:15 -0300 | [diff] [blame] | 767 | if (err < 0) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 768 | rc_free_device(dev); |
David Härdeman | 15100d8 | 2010-04-15 18:46:15 -0300 | [diff] [blame] | 769 | return err; |
| 770 | } |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 771 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 772 | dm1105->ir.dev = dev; |
David Härdeman | 15100d8 | 2010-04-15 18:46:15 -0300 | [diff] [blame] | 773 | return 0; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 774 | } |
| 775 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 776 | static void dm1105_ir_exit(struct dm1105_dev *dm1105) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 777 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 778 | rc_unregister_device(dm1105->ir.dev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 779 | } |
| 780 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 781 | static int dm1105_hw_init(struct dm1105_dev *dev) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 782 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 783 | dm1105_disable_irqs(dev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 784 | |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 785 | dm_writeb(DM1105_HOST_CTR, 0); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 786 | |
| 787 | /*DATALEN 188,*/ |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 788 | dm_writeb(DM1105_DTALENTH, 188); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 789 | /*TS_STRT TS_VALP MSBFIRST TS_MODE ALPAS TSPES*/ |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 790 | dm_writew(DM1105_TSCTR, 0xc10a); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 791 | |
| 792 | /* map DMA and set address */ |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 793 | dm1105_dma_map(dev); |
| 794 | dm1105_set_dma_addr(dev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 795 | /* big buffer */ |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 796 | dm_writel(DM1105_RLEN, 5 * DM1105_DMA_BYTES); |
| 797 | dm_writeb(DM1105_INTCNT, 47); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 798 | |
| 799 | /* IR NEC mode enable */ |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 800 | dm_writeb(DM1105_IRCTR, (DM1105_IR_EN | DM1105_SYS_CHK)); |
| 801 | dm_writeb(DM1105_IRMODE, 0); |
| 802 | dm_writew(DM1105_SYSTEMCODE, 0); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 803 | |
| 804 | return 0; |
| 805 | } |
| 806 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 807 | static void dm1105_hw_exit(struct dm1105_dev *dev) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 808 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 809 | dm1105_disable_irqs(dev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 810 | |
| 811 | /* IR disable */ |
Igor M. Liplianin | 5eb3291 | 2010-01-17 12:23:04 -0300 | [diff] [blame] | 812 | dm_writeb(DM1105_IRCTR, 0); |
| 813 | dm_writeb(DM1105_INTMAK, INTMAK_NONEMASK); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 814 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 815 | dm1105_dma_unmap(dev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 816 | } |
Igor M. Liplianin | e4aab64 | 2008-09-23 15:43:57 -0300 | [diff] [blame] | 817 | |
Bhumika Goyal | 650497f | 2017-02-19 15:04:41 -0300 | [diff] [blame] | 818 | static const struct stv0299_config sharp_z0194a_config = { |
Igor M. Liplianin | d4305c6 | 2008-10-17 13:45:55 -0300 | [diff] [blame] | 819 | .demod_address = 0x68, |
| 820 | .inittab = sharp_z0194a_inittab, |
| 821 | .mclk = 88000000UL, |
| 822 | .invert = 1, |
| 823 | .skip_reinit = 0, |
| 824 | .lock_output = STV0299_LOCKOUTPUT_1, |
| 825 | .volt13_op0_op1 = STV0299_VOLT13_OP1, |
| 826 | .min_delay_ms = 100, |
| 827 | .set_symbol_rate = sharp_z0194a_set_symbol_rate, |
| 828 | }; |
| 829 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 830 | static struct stv0288_config earda_config = { |
| 831 | .demod_address = 0x68, |
| 832 | .min_delay_ms = 100, |
| 833 | }; |
| 834 | |
| 835 | static struct si21xx_config serit_config = { |
| 836 | .demod_address = 0x68, |
| 837 | .min_delay_ms = 100, |
| 838 | |
| 839 | }; |
| 840 | |
| 841 | static struct cx24116_config serit_sp2633_config = { |
| 842 | .demod_address = 0x55, |
| 843 | }; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 844 | |
Igor M. Liplianin | b4a0e81 | 2010-01-17 10:32:26 -0300 | [diff] [blame] | 845 | static struct ds3000_config dvbworld_ds3000_config = { |
| 846 | .demod_address = 0x68, |
| 847 | }; |
| 848 | |
Konstantin Dimitrov | 73f0af4 | 2012-12-23 19:25:38 -0300 | [diff] [blame] | 849 | static struct ts2020_config dvbworld_ts2020_config = { |
| 850 | .tuner_address = 0x60, |
Igor M. Liplianin | b858c33 | 2012-12-28 19:40:33 -0300 | [diff] [blame] | 851 | .clk_out_div = 1, |
Konstantin Dimitrov | 73f0af4 | 2012-12-23 19:25:38 -0300 | [diff] [blame] | 852 | }; |
| 853 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 854 | static int frontend_init(struct dm1105_dev *dev) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 855 | { |
| 856 | int ret; |
| 857 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 858 | switch (dev->boardnr) { |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 859 | case DM1105_BOARD_UNBRANDED_I2C_ON_GPIO: |
| 860 | dm1105_gpio_enable(dev, GPIO15, 1); |
| 861 | dm1105_gpio_clear(dev, GPIO15); |
| 862 | msleep(100); |
| 863 | dm1105_gpio_set(dev, GPIO15); |
| 864 | msleep(200); |
| 865 | dev->fe = dvb_attach( |
| 866 | stv0299_attach, &sharp_z0194a_config, |
| 867 | &dev->i2c_bb_adap); |
| 868 | if (dev->fe) { |
| 869 | dev->fe->ops.set_voltage = dm1105_set_voltage; |
| 870 | dvb_attach(dvb_pll_attach, dev->fe, 0x60, |
| 871 | &dev->i2c_bb_adap, DVB_PLL_OPERA1); |
| 872 | break; |
| 873 | } |
| 874 | |
| 875 | dev->fe = dvb_attach( |
| 876 | stv0288_attach, &earda_config, |
| 877 | &dev->i2c_bb_adap); |
| 878 | if (dev->fe) { |
| 879 | dev->fe->ops.set_voltage = dm1105_set_voltage; |
| 880 | dvb_attach(stb6000_attach, dev->fe, 0x61, |
| 881 | &dev->i2c_bb_adap); |
| 882 | break; |
| 883 | } |
| 884 | |
| 885 | dev->fe = dvb_attach( |
| 886 | si21xx_attach, &serit_config, |
| 887 | &dev->i2c_bb_adap); |
| 888 | if (dev->fe) |
| 889 | dev->fe->ops.set_voltage = dm1105_set_voltage; |
| 890 | break; |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 891 | case DM1105_BOARD_DVBWORLD_2004: |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 892 | dev->fe = dvb_attach( |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 893 | cx24116_attach, &serit_sp2633_config, |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 894 | &dev->i2c_adap); |
| 895 | if (dev->fe) { |
| 896 | dev->fe->ops.set_voltage = dm1105_set_voltage; |
Igor M. Liplianin | b4a0e81 | 2010-01-17 10:32:26 -0300 | [diff] [blame] | 897 | break; |
| 898 | } |
| 899 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 900 | dev->fe = dvb_attach( |
Igor M. Liplianin | b4a0e81 | 2010-01-17 10:32:26 -0300 | [diff] [blame] | 901 | ds3000_attach, &dvbworld_ds3000_config, |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 902 | &dev->i2c_adap); |
Konstantin Dimitrov | 73f0af4 | 2012-12-23 19:25:38 -0300 | [diff] [blame] | 903 | if (dev->fe) { |
| 904 | dvb_attach(ts2020_attach, dev->fe, |
| 905 | &dvbworld_ts2020_config, &dev->i2c_adap); |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 906 | dev->fe->ops.set_voltage = dm1105_set_voltage; |
Konstantin Dimitrov | 73f0af4 | 2012-12-23 19:25:38 -0300 | [diff] [blame] | 907 | } |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 908 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 909 | break; |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 910 | case DM1105_BOARD_DVBWORLD_2002: |
| 911 | case DM1105_BOARD_AXESS_DM05: |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 912 | default: |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 913 | dev->fe = dvb_attach( |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 914 | stv0299_attach, &sharp_z0194a_config, |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 915 | &dev->i2c_adap); |
| 916 | if (dev->fe) { |
| 917 | dev->fe->ops.set_voltage = dm1105_set_voltage; |
| 918 | dvb_attach(dvb_pll_attach, dev->fe, 0x60, |
| 919 | &dev->i2c_adap, DVB_PLL_OPERA1); |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 920 | break; |
| 921 | } |
| 922 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 923 | dev->fe = dvb_attach( |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 924 | stv0288_attach, &earda_config, |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 925 | &dev->i2c_adap); |
| 926 | if (dev->fe) { |
| 927 | dev->fe->ops.set_voltage = dm1105_set_voltage; |
| 928 | dvb_attach(stb6000_attach, dev->fe, 0x61, |
| 929 | &dev->i2c_adap); |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 930 | break; |
| 931 | } |
| 932 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 933 | dev->fe = dvb_attach( |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 934 | si21xx_attach, &serit_config, |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 935 | &dev->i2c_adap); |
| 936 | if (dev->fe) |
| 937 | dev->fe->ops.set_voltage = dm1105_set_voltage; |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 938 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 939 | } |
| 940 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 941 | if (!dev->fe) { |
| 942 | dev_err(&dev->pdev->dev, "could not attach frontend\n"); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 943 | return -ENODEV; |
| 944 | } |
| 945 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 946 | ret = dvb_register_frontend(&dev->dvb_adapter, dev->fe); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 947 | if (ret < 0) { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 948 | if (dev->fe->ops.release) |
| 949 | dev->fe->ops.release(dev->fe); |
| 950 | dev->fe = NULL; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 951 | return ret; |
| 952 | } |
| 953 | |
| 954 | return 0; |
| 955 | } |
| 956 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 957 | static void dm1105_read_mac(struct dm1105_dev *dev, u8 *mac) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 958 | { |
| 959 | static u8 command[1] = { 0x28 }; |
| 960 | |
| 961 | struct i2c_msg msg[] = { |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 962 | { |
| 963 | .addr = IIC_24C01_addr >> 1, |
| 964 | .flags = 0, |
| 965 | .buf = command, |
| 966 | .len = 1 |
| 967 | }, { |
| 968 | .addr = IIC_24C01_addr >> 1, |
| 969 | .flags = I2C_M_RD, |
| 970 | .buf = mac, |
| 971 | .len = 6 |
| 972 | }, |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 973 | }; |
| 974 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 975 | dm1105_i2c_xfer(&dev->i2c_adap, msg , 2); |
| 976 | dev_info(&dev->pdev->dev, "MAC %pM\n", mac); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 977 | } |
| 978 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 979 | static int dm1105_probe(struct pci_dev *pdev, |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 980 | const struct pci_device_id *ent) |
| 981 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 982 | struct dm1105_dev *dev; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 983 | struct dvb_adapter *dvb_adapter; |
| 984 | struct dvb_demux *dvbdemux; |
| 985 | struct dmx_demux *dmx; |
| 986 | int ret = -ENOMEM; |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 987 | int i; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 988 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 989 | dev = kzalloc(sizeof(struct dm1105_dev), GFP_KERNEL); |
| 990 | if (!dev) |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 991 | return -ENOMEM; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 992 | |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 993 | /* board config */ |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 994 | dev->nr = dm1105_devcount; |
| 995 | dev->boardnr = UNSET; |
| 996 | if (card[dev->nr] < ARRAY_SIZE(dm1105_boards)) |
| 997 | dev->boardnr = card[dev->nr]; |
| 998 | for (i = 0; UNSET == dev->boardnr && |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 999 | i < ARRAY_SIZE(dm1105_subids); i++) |
| 1000 | if (pdev->subsystem_vendor == |
| 1001 | dm1105_subids[i].subvendor && |
| 1002 | pdev->subsystem_device == |
| 1003 | dm1105_subids[i].subdevice) |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1004 | dev->boardnr = dm1105_subids[i].card; |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 1005 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1006 | if (UNSET == dev->boardnr) { |
| 1007 | dev->boardnr = DM1105_BOARD_UNKNOWN; |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 1008 | dm1105_card_list(pdev); |
| 1009 | } |
| 1010 | |
| 1011 | dm1105_devcount++; |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1012 | dev->pdev = pdev; |
| 1013 | dev->buffer_size = 5 * DM1105_DMA_BYTES; |
| 1014 | dev->PacketErrorCount = 0; |
| 1015 | dev->dmarst = 0; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1016 | |
| 1017 | ret = pci_enable_device(pdev); |
| 1018 | if (ret < 0) |
| 1019 | goto err_kfree; |
| 1020 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1021 | ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1022 | if (ret < 0) |
| 1023 | goto err_pci_disable_device; |
| 1024 | |
| 1025 | pci_set_master(pdev); |
| 1026 | |
| 1027 | ret = pci_request_regions(pdev, DRIVER_NAME); |
| 1028 | if (ret < 0) |
| 1029 | goto err_pci_disable_device; |
| 1030 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1031 | dev->io_mem = pci_iomap(pdev, 0, pci_resource_len(pdev, 0)); |
| 1032 | if (!dev->io_mem) { |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1033 | ret = -EIO; |
| 1034 | goto err_pci_release_regions; |
| 1035 | } |
| 1036 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1037 | spin_lock_init(&dev->lock); |
| 1038 | pci_set_drvdata(pdev, dev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1039 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1040 | ret = dm1105_hw_init(dev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1041 | if (ret < 0) |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 1042 | goto err_pci_iounmap; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1043 | |
| 1044 | /* i2c */ |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1045 | i2c_set_adapdata(&dev->i2c_adap, dev); |
| 1046 | strcpy(dev->i2c_adap.name, DRIVER_NAME); |
| 1047 | dev->i2c_adap.owner = THIS_MODULE; |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1048 | dev->i2c_adap.dev.parent = &pdev->dev; |
| 1049 | dev->i2c_adap.algo = &dm1105_algo; |
| 1050 | dev->i2c_adap.algo_data = dev; |
| 1051 | ret = i2c_add_adapter(&dev->i2c_adap); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1052 | |
| 1053 | if (ret < 0) |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1054 | goto err_dm1105_hw_exit; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1055 | |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 1056 | i2c_set_adapdata(&dev->i2c_bb_adap, dev); |
| 1057 | strcpy(dev->i2c_bb_adap.name, DM1105_I2C_GPIO_NAME); |
| 1058 | dev->i2c_bb_adap.owner = THIS_MODULE; |
| 1059 | dev->i2c_bb_adap.dev.parent = &pdev->dev; |
| 1060 | dev->i2c_bb_adap.algo_data = &dev->i2c_bit; |
| 1061 | dev->i2c_bit.data = dev; |
| 1062 | dev->i2c_bit.setsda = dm1105_setsda; |
| 1063 | dev->i2c_bit.setscl = dm1105_setscl; |
| 1064 | dev->i2c_bit.getsda = dm1105_getsda; |
| 1065 | dev->i2c_bit.getscl = dm1105_getscl; |
| 1066 | dev->i2c_bit.udelay = 10; |
| 1067 | dev->i2c_bit.timeout = 10; |
| 1068 | |
| 1069 | /* Raise SCL and SDA */ |
| 1070 | dm1105_setsda(dev, 1); |
| 1071 | dm1105_setscl(dev, 1); |
| 1072 | |
| 1073 | ret = i2c_bit_add_bus(&dev->i2c_bb_adap); |
| 1074 | if (ret < 0) |
| 1075 | goto err_i2c_del_adapter; |
| 1076 | |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1077 | /* dvb */ |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1078 | ret = dvb_register_adapter(&dev->dvb_adapter, DRIVER_NAME, |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1079 | THIS_MODULE, &pdev->dev, adapter_nr); |
| 1080 | if (ret < 0) |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 1081 | goto err_i2c_del_adapters; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1082 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1083 | dvb_adapter = &dev->dvb_adapter; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1084 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1085 | dm1105_read_mac(dev, dvb_adapter->proposed_mac); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1086 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1087 | dvbdemux = &dev->demux; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1088 | dvbdemux->filternum = 256; |
| 1089 | dvbdemux->feednum = 256; |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1090 | dvbdemux->start_feed = dm1105_start_feed; |
| 1091 | dvbdemux->stop_feed = dm1105_stop_feed; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1092 | dvbdemux->dmx.capabilities = (DMX_TS_FILTERING | |
| 1093 | DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING); |
| 1094 | ret = dvb_dmx_init(dvbdemux); |
| 1095 | if (ret < 0) |
| 1096 | goto err_dvb_unregister_adapter; |
| 1097 | |
| 1098 | dmx = &dvbdemux->dmx; |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1099 | dev->dmxdev.filternum = 256; |
| 1100 | dev->dmxdev.demux = dmx; |
| 1101 | dev->dmxdev.capabilities = 0; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1102 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1103 | ret = dvb_dmxdev_init(&dev->dmxdev, dvb_adapter); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1104 | if (ret < 0) |
| 1105 | goto err_dvb_dmx_release; |
| 1106 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1107 | dev->hw_frontend.source = DMX_FRONTEND_0; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1108 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1109 | ret = dmx->add_frontend(dmx, &dev->hw_frontend); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1110 | if (ret < 0) |
| 1111 | goto err_dvb_dmxdev_release; |
| 1112 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1113 | dev->mem_frontend.source = DMX_MEMORY_FE; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1114 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1115 | ret = dmx->add_frontend(dmx, &dev->mem_frontend); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1116 | if (ret < 0) |
| 1117 | goto err_remove_hw_frontend; |
| 1118 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1119 | ret = dmx->connect_frontend(dmx, &dev->hw_frontend); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1120 | if (ret < 0) |
| 1121 | goto err_remove_mem_frontend; |
| 1122 | |
Jonathan Nieder | 5584c64 | 2011-12-31 08:08:45 -0300 | [diff] [blame] | 1123 | ret = dvb_net_init(dvb_adapter, &dev->dvbnet, dmx); |
| 1124 | if (ret < 0) |
| 1125 | goto err_disconnect_frontend; |
| 1126 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1127 | ret = frontend_init(dev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1128 | if (ret < 0) |
Jonathan Nieder | e996634 | 2012-01-06 14:40:26 -0300 | [diff] [blame] | 1129 | goto err_dvb_net; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1130 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1131 | dm1105_ir_init(dev); |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 1132 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1133 | INIT_WORK(&dev->work, dm1105_dmx_buffer); |
| 1134 | sprintf(dev->wqn, "%s/%d", dvb_adapter->name, dvb_adapter->num); |
| 1135 | dev->wq = create_singlethread_workqueue(dev->wqn); |
Peter Senna Tschudin | 95d0812 | 2012-09-06 11:23:55 -0300 | [diff] [blame] | 1136 | if (!dev->wq) { |
| 1137 | ret = -ENOMEM; |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 1138 | goto err_dvb_net; |
Peter Senna Tschudin | 95d0812 | 2012-09-06 11:23:55 -0300 | [diff] [blame] | 1139 | } |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 1140 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1141 | ret = request_irq(pdev->irq, dm1105_irq, IRQF_SHARED, |
| 1142 | DRIVER_NAME, dev); |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 1143 | if (ret < 0) |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 1144 | goto err_workqueue; |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 1145 | |
| 1146 | return 0; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1147 | |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 1148 | err_workqueue: |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1149 | destroy_workqueue(dev->wq); |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 1150 | err_dvb_net: |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1151 | dvb_net_release(&dev->dvbnet); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1152 | err_disconnect_frontend: |
| 1153 | dmx->disconnect_frontend(dmx); |
| 1154 | err_remove_mem_frontend: |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1155 | dmx->remove_frontend(dmx, &dev->mem_frontend); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1156 | err_remove_hw_frontend: |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1157 | dmx->remove_frontend(dmx, &dev->hw_frontend); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1158 | err_dvb_dmxdev_release: |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1159 | dvb_dmxdev_release(&dev->dmxdev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1160 | err_dvb_dmx_release: |
| 1161 | dvb_dmx_release(dvbdemux); |
| 1162 | err_dvb_unregister_adapter: |
| 1163 | dvb_unregister_adapter(dvb_adapter); |
Igor M. Liplianin | 0017505 | 2011-05-05 16:35:01 -0300 | [diff] [blame] | 1164 | err_i2c_del_adapters: |
| 1165 | i2c_del_adapter(&dev->i2c_bb_adap); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1166 | err_i2c_del_adapter: |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1167 | i2c_del_adapter(&dev->i2c_adap); |
| 1168 | err_dm1105_hw_exit: |
| 1169 | dm1105_hw_exit(dev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1170 | err_pci_iounmap: |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1171 | pci_iounmap(pdev, dev->io_mem); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1172 | err_pci_release_regions: |
| 1173 | pci_release_regions(pdev); |
| 1174 | err_pci_disable_device: |
| 1175 | pci_disable_device(pdev); |
| 1176 | err_kfree: |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1177 | kfree(dev); |
Igor M. Liplianin | d1498ff | 2009-02-26 03:40:41 -0300 | [diff] [blame] | 1178 | return ret; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1179 | } |
| 1180 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1181 | static void dm1105_remove(struct pci_dev *pdev) |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1182 | { |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1183 | struct dm1105_dev *dev = pci_get_drvdata(pdev); |
| 1184 | struct dvb_adapter *dvb_adapter = &dev->dvb_adapter; |
| 1185 | struct dvb_demux *dvbdemux = &dev->demux; |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1186 | struct dmx_demux *dmx = &dvbdemux->dmx; |
| 1187 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1188 | dm1105_ir_exit(dev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1189 | dmx->close(dmx); |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1190 | dvb_net_release(&dev->dvbnet); |
| 1191 | if (dev->fe) |
| 1192 | dvb_unregister_frontend(dev->fe); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1193 | |
| 1194 | dmx->disconnect_frontend(dmx); |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1195 | dmx->remove_frontend(dmx, &dev->mem_frontend); |
| 1196 | dmx->remove_frontend(dmx, &dev->hw_frontend); |
| 1197 | dvb_dmxdev_release(&dev->dmxdev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1198 | dvb_dmx_release(dvbdemux); |
| 1199 | dvb_unregister_adapter(dvb_adapter); |
Alexandru Juncu | 0e48a3e | 2013-09-04 11:41:34 -0300 | [diff] [blame] | 1200 | i2c_del_adapter(&dev->i2c_adap); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1201 | |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1202 | dm1105_hw_exit(dev); |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1203 | free_irq(pdev->irq, dev); |
| 1204 | pci_iounmap(pdev, dev->io_mem); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1205 | pci_release_regions(pdev); |
| 1206 | pci_disable_device(pdev); |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 1207 | dm1105_devcount--; |
Igor M. Liplianin | 34d2f9b | 2010-01-17 12:11:00 -0300 | [diff] [blame] | 1208 | kfree(dev); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1209 | } |
| 1210 | |
Arvind Yadav | 82c055c | 2017-08-01 13:56:22 -0400 | [diff] [blame] | 1211 | static const struct pci_device_id dm1105_id_table[] = { |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1212 | { |
| 1213 | .vendor = PCI_VENDOR_ID_TRIGEM, |
| 1214 | .device = PCI_DEVICE_ID_DM1105, |
| 1215 | .subvendor = PCI_ANY_ID, |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 1216 | .subdevice = PCI_ANY_ID, |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1217 | }, { |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 1218 | .vendor = PCI_VENDOR_ID_AXESS, |
| 1219 | .device = PCI_DEVICE_ID_DM05, |
Igor M. Liplianin | d8300df | 2009-07-22 17:30:25 -0300 | [diff] [blame] | 1220 | .subvendor = PCI_ANY_ID, |
| 1221 | .subdevice = PCI_ANY_ID, |
Igor M. Liplianin | 519a4bd | 2009-06-14 21:34:12 -0300 | [diff] [blame] | 1222 | }, { |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1223 | /* empty */ |
| 1224 | }, |
| 1225 | }; |
| 1226 | |
| 1227 | MODULE_DEVICE_TABLE(pci, dm1105_id_table); |
| 1228 | |
| 1229 | static struct pci_driver dm1105_driver = { |
| 1230 | .name = DRIVER_NAME, |
| 1231 | .id_table = dm1105_id_table, |
| 1232 | .probe = dm1105_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1233 | .remove = dm1105_remove, |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1234 | }; |
| 1235 | |
Libo Chen | 548006c | 2013-05-26 22:31:49 -0300 | [diff] [blame] | 1236 | module_pci_driver(dm1105_driver); |
Igor M. Liplianin | a611d0c | 2008-09-13 10:10:53 -0300 | [diff] [blame] | 1237 | |
| 1238 | MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>"); |
| 1239 | MODULE_DESCRIPTION("SDMC DM1105 DVB driver"); |
| 1240 | MODULE_LICENSE("GPL"); |