Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 1 | /* DVB USB compliant linux driver for IT9137 |
| 2 | * |
| 3 | * Copyright (C) 2011 Malcolm Priestley (tvboxspy@gmail.com) |
| 4 | * IT9137 (C) ITE Tech Inc. |
| 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 Version 2, as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | * |
| 19 | * |
| 20 | * see Documentation/dvb/README.dvb-usb for more information |
| 21 | * see Documentation/dvb/it9137.txt for firmware information |
| 22 | * |
| 23 | */ |
| 24 | #define DVB_USB_LOG_PREFIX "it913x" |
| 25 | |
| 26 | #include <linux/usb.h> |
| 27 | #include <linux/usb/input.h> |
| 28 | #include <media/rc-core.h> |
| 29 | |
| 30 | #include "dvb-usb.h" |
| 31 | #include "it913x-fe.h" |
| 32 | |
| 33 | /* debug */ |
| 34 | static int dvb_usb_it913x_debug; |
| 35 | #define l_dprintk(var, level, args...) do { \ |
| 36 | if ((var >= level)) \ |
| 37 | printk(KERN_DEBUG DVB_USB_LOG_PREFIX ": " args); \ |
| 38 | } while (0) |
| 39 | |
| 40 | #define deb_info(level, args...) l_dprintk(dvb_usb_it913x_debug, level, args) |
| 41 | #define debug_data_snipet(level, name, p) \ |
| 42 | deb_info(level, name" (%02x%02x%02x%02x%02x%02x%02x%02x)", \ |
| 43 | *p, *(p+1), *(p+2), *(p+3), *(p+4), \ |
| 44 | *(p+5), *(p+6), *(p+7)); |
| 45 | |
| 46 | |
| 47 | module_param_named(debug, dvb_usb_it913x_debug, int, 0644); |
| 48 | MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." |
| 49 | DVB_USB_DEBUG_STATUS); |
| 50 | |
| 51 | static int pid_filter; |
| 52 | module_param_named(pid, pid_filter, int, 0644); |
| 53 | MODULE_PARM_DESC(pid, "set default 0=on 1=off"); |
| 54 | |
Malcolm Priestley | 5e642c0 | 2011-11-30 17:16:09 -0300 | [diff] [blame] | 55 | static int dvb_usb_it913x_firmware; |
| 56 | module_param_named(firmware, dvb_usb_it913x_firmware, int, 0644); |
| 57 | MODULE_PARM_DESC(firmware, "set firmware 0=auto 1=IT9137 2=IT9135V1"); |
| 58 | |
| 59 | |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 60 | int cmd_counter; |
| 61 | |
| 62 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 63 | |
| 64 | struct it913x_state { |
| 65 | u8 id; |
Malcolm Priestley | 5081570 | 2011-12-04 08:20:37 -0300 | [diff] [blame] | 66 | struct ite_config it913x_config; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 67 | }; |
| 68 | |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 69 | struct ite_config it913x_config; |
| 70 | |
Malcolm Priestley | 15157c5 | 2011-12-01 17:35:48 -0300 | [diff] [blame] | 71 | #define IT913X_RETRY 10 |
| 72 | #define IT913X_SND_TIMEOUT 100 |
| 73 | #define IT913X_RCV_TIMEOUT 200 |
| 74 | |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 75 | static int it913x_bulk_write(struct usb_device *dev, |
| 76 | u8 *snd, int len, u8 pipe) |
| 77 | { |
Malcolm Priestley | 15157c5 | 2011-12-01 17:35:48 -0300 | [diff] [blame] | 78 | int ret, actual_l, i; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 79 | |
Malcolm Priestley | 15157c5 | 2011-12-01 17:35:48 -0300 | [diff] [blame] | 80 | for (i = 0; i < IT913X_RETRY; i++) { |
| 81 | ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe), |
| 82 | snd, len , &actual_l, IT913X_SND_TIMEOUT); |
| 83 | if (ret == 0 || ret != -EBUSY || ret != -ETIMEDOUT) |
| 84 | break; |
| 85 | } |
| 86 | |
| 87 | if (len != actual_l && ret == 0) |
| 88 | ret = -EAGAIN; |
| 89 | |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 90 | return ret; |
| 91 | } |
| 92 | |
| 93 | static int it913x_bulk_read(struct usb_device *dev, |
| 94 | u8 *rev, int len, u8 pipe) |
| 95 | { |
Malcolm Priestley | 15157c5 | 2011-12-01 17:35:48 -0300 | [diff] [blame] | 96 | int ret, actual_l, i; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 97 | |
Malcolm Priestley | 15157c5 | 2011-12-01 17:35:48 -0300 | [diff] [blame] | 98 | for (i = 0; i < IT913X_RETRY; i++) { |
| 99 | ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe), |
| 100 | rev, len , &actual_l, IT913X_RCV_TIMEOUT); |
| 101 | if (ret == 0 || ret != -EBUSY || ret != -ETIMEDOUT) |
| 102 | break; |
| 103 | } |
| 104 | |
| 105 | if (len != actual_l && ret == 0) |
| 106 | ret = -EAGAIN; |
| 107 | |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 108 | return ret; |
| 109 | } |
| 110 | |
| 111 | static u16 check_sum(u8 *p, u8 len) |
| 112 | { |
| 113 | u16 sum = 0; |
| 114 | u8 i = 1; |
| 115 | while (i < len) |
| 116 | sum += (i++ & 1) ? (*p++) << 8 : *p++; |
| 117 | return ~sum; |
| 118 | } |
| 119 | |
Malcolm Priestley | 15157c5 | 2011-12-01 17:35:48 -0300 | [diff] [blame] | 120 | static int it913x_usb_talk(struct usb_device *udev, u8 mode, u8 pro, |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 121 | u8 cmd, u32 reg, u8 addr, u8 *data, u8 len) |
| 122 | { |
| 123 | int ret = 0, i, buf_size = 1; |
| 124 | u8 *buff; |
| 125 | u8 rlen; |
| 126 | u16 chk_sum; |
| 127 | |
| 128 | buff = kzalloc(256, GFP_KERNEL); |
| 129 | if (!buff) { |
| 130 | info("USB Buffer Failed"); |
| 131 | return -ENOMEM; |
| 132 | } |
| 133 | |
| 134 | buff[buf_size++] = pro; |
| 135 | buff[buf_size++] = cmd; |
| 136 | buff[buf_size++] = cmd_counter; |
| 137 | |
| 138 | switch (mode) { |
| 139 | case READ_LONG: |
| 140 | case WRITE_LONG: |
| 141 | buff[buf_size++] = len; |
| 142 | buff[buf_size++] = 2; |
| 143 | buff[buf_size++] = (reg >> 24); |
| 144 | buff[buf_size++] = (reg >> 16) & 0xff; |
| 145 | buff[buf_size++] = (reg >> 8) & 0xff; |
| 146 | buff[buf_size++] = reg & 0xff; |
| 147 | break; |
| 148 | case READ_SHORT: |
| 149 | buff[buf_size++] = addr; |
| 150 | break; |
| 151 | case WRITE_SHORT: |
| 152 | buff[buf_size++] = len; |
| 153 | buff[buf_size++] = addr; |
| 154 | buff[buf_size++] = (reg >> 8) & 0xff; |
| 155 | buff[buf_size++] = reg & 0xff; |
| 156 | break; |
| 157 | case READ_DATA: |
| 158 | case WRITE_DATA: |
| 159 | break; |
| 160 | case WRITE_CMD: |
| 161 | mode = 7; |
| 162 | break; |
| 163 | default: |
| 164 | kfree(buff); |
| 165 | return -EINVAL; |
| 166 | } |
| 167 | |
| 168 | if (mode & 1) { |
| 169 | for (i = 0; i < len ; i++) |
| 170 | buff[buf_size++] = data[i]; |
| 171 | } |
| 172 | chk_sum = check_sum(&buff[1], buf_size); |
| 173 | |
| 174 | buff[buf_size++] = chk_sum >> 8; |
| 175 | buff[0] = buf_size; |
| 176 | buff[buf_size++] = (chk_sum & 0xff); |
| 177 | |
| 178 | ret = it913x_bulk_write(udev, buff, buf_size , 0x02); |
Malcolm Priestley | 15157c5 | 2011-12-01 17:35:48 -0300 | [diff] [blame] | 179 | if (ret < 0) |
| 180 | goto error; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 181 | |
Malcolm Priestley | 15157c5 | 2011-12-01 17:35:48 -0300 | [diff] [blame] | 182 | ret = it913x_bulk_read(udev, buff, (mode & 1) ? |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 183 | 5 : len + 5 , 0x01); |
Malcolm Priestley | 15157c5 | 2011-12-01 17:35:48 -0300 | [diff] [blame] | 184 | if (ret < 0) |
| 185 | goto error; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 186 | |
| 187 | rlen = (mode & 0x1) ? 0x1 : len; |
| 188 | |
| 189 | if (mode & 1) |
Malcolm Priestley | 15157c5 | 2011-12-01 17:35:48 -0300 | [diff] [blame] | 190 | ret = buff[2]; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 191 | else |
| 192 | memcpy(data, &buff[3], rlen); |
| 193 | |
| 194 | cmd_counter++; |
| 195 | |
Malcolm Priestley | 15157c5 | 2011-12-01 17:35:48 -0300 | [diff] [blame] | 196 | error: kfree(buff); |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 197 | |
Malcolm Priestley | 15157c5 | 2011-12-01 17:35:48 -0300 | [diff] [blame] | 198 | return ret; |
| 199 | } |
| 200 | |
| 201 | static int it913x_io(struct usb_device *udev, u8 mode, u8 pro, |
| 202 | u8 cmd, u32 reg, u8 addr, u8 *data, u8 len) |
| 203 | { |
| 204 | int ret, i; |
| 205 | |
| 206 | for (i = 0; i < IT913X_RETRY; i++) { |
| 207 | ret = it913x_usb_talk(udev, mode, pro, |
| 208 | cmd, reg, addr, data, len); |
| 209 | if (ret != -EAGAIN) |
| 210 | break; |
| 211 | } |
| 212 | |
| 213 | return ret; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static int it913x_wr_reg(struct usb_device *udev, u8 pro, u32 reg , u8 data) |
| 217 | { |
| 218 | int ret; |
| 219 | u8 b[1]; |
| 220 | b[0] = data; |
| 221 | ret = it913x_io(udev, WRITE_LONG, pro, |
| 222 | CMD_DEMOD_WRITE, reg, 0, b, sizeof(b)); |
| 223 | |
| 224 | return ret; |
| 225 | } |
| 226 | |
| 227 | static int it913x_read_reg(struct usb_device *udev, u32 reg) |
| 228 | { |
| 229 | int ret; |
| 230 | u8 data[1]; |
| 231 | |
| 232 | ret = it913x_io(udev, READ_LONG, DEV_0, |
| 233 | CMD_DEMOD_READ, reg, 0, &data[0], 1); |
| 234 | |
| 235 | return (ret < 0) ? ret : data[0]; |
| 236 | } |
| 237 | |
| 238 | static u32 it913x_query(struct usb_device *udev, u8 pro) |
| 239 | { |
| 240 | int ret; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 241 | u8 data[4]; |
| 242 | ret = it913x_io(udev, READ_LONG, pro, CMD_DEMOD_READ, |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 243 | 0x1222, 0, &data[0], 3); |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 244 | |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 245 | it913x_config.chip_ver = data[0]; |
| 246 | it913x_config.chip_type = (u16)(data[2] << 8) + data[1]; |
| 247 | |
| 248 | info("Chip Version=%02x Chip Type=%04x", it913x_config.chip_ver, |
| 249 | it913x_config.chip_type); |
| 250 | |
| 251 | ret |= it913x_io(udev, READ_SHORT, pro, |
| 252 | CMD_QUERYINFO, 0, 0x1, &data[0], 4); |
| 253 | |
| 254 | it913x_config.firmware = (data[0] << 24) + (data[1] << 16) + |
| 255 | (data[2] << 8) + data[3]; |
| 256 | |
| 257 | return (ret < 0) ? 0 : it913x_config.firmware; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static int it913x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff) |
| 261 | { |
| 262 | int ret = 0; |
| 263 | u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD; |
| 264 | |
| 265 | if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0) |
| 266 | return -EAGAIN; |
| 267 | deb_info(1, "PID_C (%02x)", onoff); |
| 268 | |
| 269 | if (!onoff) |
| 270 | ret = it913x_wr_reg(adap->dev->udev, pro, PID_RST, 0x1); |
| 271 | |
| 272 | mutex_unlock(&adap->dev->i2c_mutex); |
| 273 | return ret; |
| 274 | } |
| 275 | |
| 276 | static int it913x_pid_filter(struct dvb_usb_adapter *adap, |
| 277 | int index, u16 pid, int onoff) |
| 278 | { |
| 279 | struct usb_device *udev = adap->dev->udev; |
| 280 | int ret = 0; |
| 281 | u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD; |
| 282 | |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 283 | if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0) |
| 284 | return -EAGAIN; |
| 285 | deb_info(1, "PID_F (%02x)", onoff); |
| 286 | if (onoff) { |
| 287 | ret = it913x_wr_reg(udev, pro, PID_EN, 0x1); |
| 288 | |
| 289 | ret |= it913x_wr_reg(udev, pro, PID_LSB, (u8)(pid & 0xff)); |
| 290 | |
| 291 | ret |= it913x_wr_reg(udev, pro, PID_MSB, (u8)(pid >> 8)); |
| 292 | |
| 293 | ret |= it913x_wr_reg(udev, pro, PID_INX_EN, (u8)onoff); |
| 294 | |
| 295 | ret |= it913x_wr_reg(udev, pro, PID_INX, (u8)(index & 0x1f)); |
| 296 | |
| 297 | } |
| 298 | |
| 299 | mutex_unlock(&adap->dev->i2c_mutex); |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | |
| 304 | static int it913x_return_status(struct usb_device *udev) |
| 305 | { |
| 306 | u32 firm = 0; |
| 307 | |
| 308 | firm = it913x_query(udev, DEV_0); |
| 309 | if (firm > 0) |
| 310 | info("Firmware Version %d", firm); |
| 311 | |
| 312 | return (firm > 0) ? firm : 0; |
| 313 | } |
| 314 | |
| 315 | static int it913x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
| 316 | int num) |
| 317 | { |
| 318 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 319 | static u8 data[256]; |
| 320 | int ret; |
| 321 | u32 reg; |
| 322 | u8 pro; |
| 323 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 324 | return -EAGAIN; |
| 325 | |
| 326 | debug_data_snipet(1, "Message out", msg[0].buf); |
| 327 | deb_info(2, "num of messages %d address %02x", num, msg[0].addr); |
| 328 | |
| 329 | pro = (msg[0].addr & 0x2) ? DEV_0_DMOD : 0x0; |
| 330 | pro |= (msg[0].addr & 0x20) ? DEV_1 : DEV_0; |
| 331 | memcpy(data, msg[0].buf, msg[0].len); |
| 332 | reg = (data[0] << 24) + (data[1] << 16) + |
| 333 | (data[2] << 8) + data[3]; |
| 334 | if (num == 2) { |
| 335 | ret = it913x_io(d->udev, READ_LONG, pro, |
| 336 | CMD_DEMOD_READ, reg, 0, data, msg[1].len); |
| 337 | memcpy(msg[1].buf, data, msg[1].len); |
| 338 | } else |
| 339 | ret = it913x_io(d->udev, WRITE_LONG, pro, CMD_DEMOD_WRITE, |
| 340 | reg, 0, &data[4], msg[0].len - 4); |
| 341 | |
| 342 | mutex_unlock(&d->i2c_mutex); |
| 343 | |
| 344 | return ret; |
| 345 | } |
| 346 | |
| 347 | static u32 it913x_i2c_func(struct i2c_adapter *adapter) |
| 348 | { |
| 349 | return I2C_FUNC_I2C; |
| 350 | } |
| 351 | |
| 352 | static struct i2c_algorithm it913x_i2c_algo = { |
| 353 | .master_xfer = it913x_i2c_xfer, |
| 354 | .functionality = it913x_i2c_func, |
| 355 | }; |
| 356 | |
| 357 | /* Callbacks for DVB USB */ |
tvboxspy | 2ba0f94 | 2011-09-21 18:57:41 -0300 | [diff] [blame] | 358 | #define IT913X_POLL 250 |
| 359 | static int it913x_rc_query(struct dvb_usb_device *d) |
| 360 | { |
| 361 | u8 ibuf[4]; |
| 362 | int ret; |
| 363 | u32 key; |
| 364 | /* Avoid conflict with frontends*/ |
| 365 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 366 | return -EAGAIN; |
| 367 | |
| 368 | ret = it913x_io(d->udev, READ_LONG, PRO_LINK, CMD_IR_GET, |
| 369 | 0, 0, &ibuf[0], sizeof(ibuf)); |
| 370 | |
| 371 | if ((ibuf[2] + ibuf[3]) == 0xff) { |
| 372 | key = ibuf[2]; |
Malcolm Priestley | c725ff6 | 2011-11-28 18:22:41 -0300 | [diff] [blame] | 373 | key += ibuf[0] << 16; |
| 374 | key += ibuf[1] << 8; |
| 375 | deb_info(1, "NEC Extended Key =%08x", key); |
tvboxspy | 2ba0f94 | 2011-09-21 18:57:41 -0300 | [diff] [blame] | 376 | if (d->rc_dev != NULL) |
| 377 | rc_keydown(d->rc_dev, key, 0); |
| 378 | } |
Malcolm Priestley | c725ff6 | 2011-11-28 18:22:41 -0300 | [diff] [blame] | 379 | |
tvboxspy | 2ba0f94 | 2011-09-21 18:57:41 -0300 | [diff] [blame] | 380 | mutex_unlock(&d->i2c_mutex); |
| 381 | |
| 382 | return ret; |
| 383 | } |
Malcolm Priestley | 9c1133c | 2011-11-27 17:35:06 -0300 | [diff] [blame] | 384 | |
Malcolm Priestley | 5e642c0 | 2011-11-30 17:16:09 -0300 | [diff] [blame] | 385 | /* Firmware sets raw */ |
| 386 | const char fw_it9135_v1[] = "dvb-usb-it9135-01.fw"; |
Malcolm Priestley | 53844c4 | 2011-12-12 15:53:00 -0300 | [diff] [blame] | 387 | const char fw_it9135_v2[] = "dvb-usb-it9135-02.fw"; |
Malcolm Priestley | 5e642c0 | 2011-11-30 17:16:09 -0300 | [diff] [blame] | 388 | const char fw_it9137[] = "dvb-usb-it9137-01.fw"; |
| 389 | |
Malcolm Priestley | 990f49a | 2011-11-28 18:04:21 -0300 | [diff] [blame] | 390 | static int ite_firmware_select(struct usb_device *udev, |
| 391 | struct dvb_usb_device_properties *props) |
| 392 | { |
| 393 | int sw; |
| 394 | /* auto switch */ |
| 395 | if (le16_to_cpu(udev->descriptor.idProduct) == |
| 396 | USB_PID_ITETECH_IT9135) |
| 397 | sw = IT9135_V1_FW; |
Malcolm Priestley | 5e642c0 | 2011-11-30 17:16:09 -0300 | [diff] [blame] | 398 | else if (le16_to_cpu(udev->descriptor.idProduct) == |
| 399 | USB_PID_ITETECH_IT9135_9005) |
| 400 | sw = IT9135_V1_FW; |
Malcolm Priestley | 53844c4 | 2011-12-12 15:53:00 -0300 | [diff] [blame] | 401 | else if (le16_to_cpu(udev->descriptor.idProduct) == |
| 402 | USB_PID_ITETECH_IT9135_9006) |
| 403 | sw = IT9135_V2_FW; |
Malcolm Priestley | 990f49a | 2011-11-28 18:04:21 -0300 | [diff] [blame] | 404 | else |
| 405 | sw = IT9137_FW; |
| 406 | |
Malcolm Priestley | 5e642c0 | 2011-11-30 17:16:09 -0300 | [diff] [blame] | 407 | /* force switch */ |
| 408 | if (dvb_usb_it913x_firmware != IT9135_AUTO) |
| 409 | sw = dvb_usb_it913x_firmware; |
| 410 | |
Malcolm Priestley | 990f49a | 2011-11-28 18:04:21 -0300 | [diff] [blame] | 411 | switch (sw) { |
| 412 | case IT9135_V1_FW: |
Malcolm Priestley | 5e642c0 | 2011-11-30 17:16:09 -0300 | [diff] [blame] | 413 | it913x_config.firmware_ver = 1; |
Malcolm Priestley | 990f49a | 2011-11-28 18:04:21 -0300 | [diff] [blame] | 414 | it913x_config.adc_x2 = 1; |
Malcolm Priestley | 5e642c0 | 2011-11-30 17:16:09 -0300 | [diff] [blame] | 415 | props->firmware = fw_it9135_v1; |
Malcolm Priestley | 990f49a | 2011-11-28 18:04:21 -0300 | [diff] [blame] | 416 | break; |
Malcolm Priestley | 53844c4 | 2011-12-12 15:53:00 -0300 | [diff] [blame] | 417 | case IT9135_V2_FW: |
| 418 | it913x_config.firmware_ver = 1; |
| 419 | it913x_config.adc_x2 = 1; |
| 420 | props->firmware = fw_it9135_v2; |
| 421 | break; |
Malcolm Priestley | 990f49a | 2011-11-28 18:04:21 -0300 | [diff] [blame] | 422 | case IT9137_FW: |
| 423 | default: |
| 424 | it913x_config.firmware_ver = 0; |
| 425 | it913x_config.adc_x2 = 0; |
Malcolm Priestley | 5e642c0 | 2011-11-30 17:16:09 -0300 | [diff] [blame] | 426 | props->firmware = fw_it9137; |
Malcolm Priestley | 990f49a | 2011-11-28 18:04:21 -0300 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
Malcolm Priestley | 9c1133c | 2011-11-27 17:35:06 -0300 | [diff] [blame] | 432 | #define TS_MPEG_PKT_SIZE 188 |
| 433 | #define EP_LOW 21 |
| 434 | #define TS_BUFFER_SIZE_PID (EP_LOW*TS_MPEG_PKT_SIZE) |
| 435 | #define EP_HIGH 348 |
| 436 | #define TS_BUFFER_SIZE_MAX (EP_HIGH*TS_MPEG_PKT_SIZE) |
| 437 | |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 438 | static int it913x_identify_state(struct usb_device *udev, |
| 439 | struct dvb_usb_device_properties *props, |
| 440 | struct dvb_usb_device_description **desc, |
| 441 | int *cold) |
| 442 | { |
| 443 | int ret = 0, firm_no; |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 444 | u8 reg, remote; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 445 | |
| 446 | firm_no = it913x_return_status(udev); |
| 447 | |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 448 | /* checnk for dual mode */ |
| 449 | it913x_config.dual_mode = it913x_read_reg(udev, 0x49c5); |
| 450 | |
Malcolm Priestley | 3822c7c | 2011-11-06 10:24:30 -0300 | [diff] [blame] | 451 | if (udev->speed != USB_SPEED_HIGH) { |
| 452 | props->adapter[0].fe[0].pid_filter_count = 5; |
| 453 | info("USB 1 low speed mode - connect to USB 2 port"); |
| 454 | if (pid_filter > 0) |
| 455 | pid_filter = 0; |
| 456 | if (it913x_config.dual_mode) { |
| 457 | it913x_config.dual_mode = 0; |
| 458 | info("Dual mode not supported in USB 1"); |
| 459 | } |
| 460 | } else /* For replugging */ |
| 461 | if(props->adapter[0].fe[0].pid_filter_count == 5) |
| 462 | props->adapter[0].fe[0].pid_filter_count = 31; |
| 463 | |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 464 | /* TODO different remotes */ |
| 465 | remote = it913x_read_reg(udev, 0x49ac); /* Remote */ |
| 466 | if (remote == 0) |
| 467 | props->rc.core.rc_codes = NULL; |
| 468 | |
| 469 | /* TODO at the moment tuner_id is always assigned to 0x38 */ |
| 470 | it913x_config.tuner_id_0 = it913x_read_reg(udev, 0x49d0); |
| 471 | |
| 472 | info("Dual mode=%x Remote=%x Tuner Type=%x", it913x_config.dual_mode |
| 473 | , remote, it913x_config.tuner_id_0); |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 474 | |
Malcolm Priestley | ed3189c | 2011-12-30 18:48:00 -0300 | [diff] [blame^] | 475 | /* Select Stream Buffer Size and pid filter option*/ |
| 476 | if (pid_filter) { |
Malcolm Priestley | 9c1133c | 2011-11-27 17:35:06 -0300 | [diff] [blame] | 477 | props->adapter[0].fe[0].stream.u.bulk.buffersize = |
| 478 | TS_BUFFER_SIZE_MAX; |
Malcolm Priestley | ed3189c | 2011-12-30 18:48:00 -0300 | [diff] [blame^] | 479 | props->adapter[0].fe[0].caps &= |
| 480 | ~DVB_USB_ADAP_NEED_PID_FILTERING; |
| 481 | } else |
Malcolm Priestley | 9c1133c | 2011-11-27 17:35:06 -0300 | [diff] [blame] | 482 | props->adapter[0].fe[0].stream.u.bulk.buffersize = |
| 483 | TS_BUFFER_SIZE_PID; |
Malcolm Priestley | ed3189c | 2011-12-30 18:48:00 -0300 | [diff] [blame^] | 484 | |
Malcolm Priestley | f36472d | 2011-12-11 17:09:46 -0300 | [diff] [blame] | 485 | if (it913x_config.dual_mode) { |
Malcolm Priestley | 9c1133c | 2011-11-27 17:35:06 -0300 | [diff] [blame] | 486 | props->adapter[1].fe[0].stream.u.bulk.buffersize = |
| 487 | props->adapter[0].fe[0].stream.u.bulk.buffersize; |
Malcolm Priestley | f36472d | 2011-12-11 17:09:46 -0300 | [diff] [blame] | 488 | props->num_adapters = 2; |
Malcolm Priestley | ed3189c | 2011-12-30 18:48:00 -0300 | [diff] [blame^] | 489 | if (pid_filter) |
| 490 | props->adapter[1].fe[0].caps = |
| 491 | props->adapter[0].fe[0].caps; |
Malcolm Priestley | f36472d | 2011-12-11 17:09:46 -0300 | [diff] [blame] | 492 | } else |
| 493 | props->num_adapters = 1; |
Malcolm Priestley | 9c1133c | 2011-11-27 17:35:06 -0300 | [diff] [blame] | 494 | |
Malcolm Priestley | 990f49a | 2011-11-28 18:04:21 -0300 | [diff] [blame] | 495 | ret = ite_firmware_select(udev, props); |
| 496 | |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 497 | if (firm_no > 0) { |
| 498 | *cold = 0; |
| 499 | return 0; |
| 500 | } |
| 501 | |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 502 | if (it913x_config.dual_mode) { |
| 503 | it913x_config.tuner_id_1 = it913x_read_reg(udev, 0x49e0); |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 504 | ret = it913x_wr_reg(udev, DEV_0, GPIOH1_EN, 0x1); |
| 505 | ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_ON, 0x1); |
| 506 | ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x1); |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 507 | msleep(50); |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 508 | ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x0); |
| 509 | msleep(50); |
| 510 | reg = it913x_read_reg(udev, GPIOH1_O); |
| 511 | if (reg == 0) { |
| 512 | ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x1); |
| 513 | ret |= it913x_return_status(udev); |
| 514 | if (ret != 0) |
| 515 | ret = it913x_wr_reg(udev, DEV_0, |
| 516 | GPIOH1_O, 0x0); |
| 517 | } |
Malcolm Priestley | f36472d | 2011-12-11 17:09:46 -0300 | [diff] [blame] | 518 | } |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 519 | |
| 520 | reg = it913x_read_reg(udev, IO_MUX_POWER_CLK); |
| 521 | |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 522 | if (it913x_config.dual_mode) { |
| 523 | ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, CHIP2_I2C_ADDR); |
Malcolm Priestley | 990f49a | 2011-11-28 18:04:21 -0300 | [diff] [blame] | 524 | if (it913x_config.firmware_ver == 1) |
| 525 | ret |= it913x_wr_reg(udev, DEV_0, 0xcfff, 0x1); |
| 526 | else |
| 527 | ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x1); |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 528 | } else { |
| 529 | ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, 0x0); |
Malcolm Priestley | 990f49a | 2011-11-28 18:04:21 -0300 | [diff] [blame] | 530 | if (it913x_config.firmware_ver == 1) |
| 531 | ret |= it913x_wr_reg(udev, DEV_0, 0xcfff, 0x0); |
| 532 | else |
| 533 | ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x0); |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 534 | } |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 535 | |
| 536 | *cold = 1; |
| 537 | |
| 538 | return (ret < 0) ? -ENODEV : 0; |
| 539 | } |
| 540 | |
| 541 | static int it913x_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) |
| 542 | { |
| 543 | int ret = 0; |
| 544 | u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD; |
| 545 | |
| 546 | if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0) |
| 547 | return -EAGAIN; |
| 548 | deb_info(1, "STM (%02x)", onoff); |
| 549 | |
| 550 | if (!onoff) |
| 551 | ret = it913x_wr_reg(adap->dev->udev, pro, PID_RST, 0x1); |
| 552 | |
| 553 | |
| 554 | mutex_unlock(&adap->dev->i2c_mutex); |
| 555 | |
| 556 | return ret; |
| 557 | } |
| 558 | |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 559 | static int it913x_download_firmware(struct usb_device *udev, |
| 560 | const struct firmware *fw) |
| 561 | { |
Malcolm Priestley | b699029 | 2011-11-30 17:14:47 -0300 | [diff] [blame] | 562 | int ret = 0, i = 0, pos = 0; |
| 563 | u8 packet_size; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 564 | u8 *fw_data; |
| 565 | |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 566 | ret = it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_100); |
| 567 | |
| 568 | info("FRM Starting Firmware Download"); |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 569 | |
Malcolm Priestley | b699029 | 2011-11-30 17:14:47 -0300 | [diff] [blame] | 570 | /* Multi firmware loader */ |
| 571 | /* This uses scatter write firmware headers */ |
| 572 | /* The firmware must start with 03 XX 00 */ |
| 573 | /* and be the extact firmware length */ |
| 574 | |
| 575 | while (i <= fw->size) { |
| 576 | if (((fw->data[i] == 0x3) && (fw->data[i + 2] == 0x0)) |
| 577 | || (i == fw->size)) { |
| 578 | packet_size = i - pos; |
| 579 | if ((packet_size > 0x19) || (i == fw->size)) { |
| 580 | fw_data = (u8 *)(fw->data + pos); |
| 581 | pos += packet_size; |
| 582 | if (packet_size > 0) |
| 583 | ret |= it913x_io(udev, WRITE_DATA, |
| 584 | DEV_0, CMD_SCATTER_WRITE, 0, |
| 585 | 0, fw_data, packet_size); |
| 586 | udelay(1000); |
| 587 | } |
| 588 | } |
| 589 | i++; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 590 | } |
| 591 | |
Malcolm Priestley | b699029 | 2011-11-30 17:14:47 -0300 | [diff] [blame] | 592 | ret |= it913x_io(udev, WRITE_CMD, DEV_0, CMD_BOOT, 0, 0, NULL, 0); |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 593 | |
| 594 | msleep(100); |
| 595 | |
| 596 | if (ret < 0) |
| 597 | info("FRM Firmware Download Failed (%04x)" , ret); |
| 598 | else |
| 599 | info("FRM Firmware Download Completed - Resetting Device"); |
| 600 | |
| 601 | ret |= it913x_return_status(udev); |
| 602 | |
| 603 | msleep(30); |
| 604 | |
| 605 | ret |= it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_400); |
| 606 | |
| 607 | /* Tuner function */ |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 608 | if (it913x_config.dual_mode) |
| 609 | ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0xa0); |
Malcolm Priestley | b7d425d39 | 2011-10-31 12:02:08 -0300 | [diff] [blame] | 610 | else |
| 611 | ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0x68); |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 612 | |
Malcolm Priestley | b7d425d39 | 2011-10-31 12:02:08 -0300 | [diff] [blame] | 613 | if ((it913x_config.chip_ver == 1) && |
| 614 | (it913x_config.chip_type == 0x9135)) { |
| 615 | ret |= it913x_wr_reg(udev, DEV_0, PADODPU, 0x0); |
| 616 | ret |= it913x_wr_reg(udev, DEV_0, AGC_O_D, 0x0); |
| 617 | if (it913x_config.dual_mode) { |
| 618 | ret |= it913x_wr_reg(udev, DEV_1, PADODPU, 0x0); |
| 619 | ret |= it913x_wr_reg(udev, DEV_1, AGC_O_D, 0x0); |
| 620 | } |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | return (ret < 0) ? -ENODEV : 0; |
| 624 | } |
| 625 | |
| 626 | static int it913x_name(struct dvb_usb_adapter *adap) |
| 627 | { |
| 628 | const char *desc = adap->dev->desc->name; |
| 629 | char *fe_name[] = {"_1", "_2", "_3", "_4"}; |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 630 | char *name = adap->fe_adap[0].fe->ops.info.name; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 631 | |
| 632 | strlcpy(name, desc, 128); |
| 633 | strlcat(name, fe_name[adap->id], 128); |
| 634 | |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | static int it913x_frontend_attach(struct dvb_usb_adapter *adap) |
| 639 | { |
| 640 | struct usb_device *udev = adap->dev->udev; |
Malcolm Priestley | 5081570 | 2011-12-04 08:20:37 -0300 | [diff] [blame] | 641 | struct it913x_state *st = adap->dev->priv; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 642 | int ret = 0; |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 643 | u8 adap_addr = I2C_BASE_ADDR + (adap->id << 5); |
Malcolm Priestley | 9c1133c | 2011-11-27 17:35:06 -0300 | [diff] [blame] | 644 | u16 ep_size = adap->props.fe[0].stream.u.bulk.buffersize / 4; |
Malcolm Priestley | 3822c7c | 2011-11-06 10:24:30 -0300 | [diff] [blame] | 645 | u8 pkt_size = 0x80; |
| 646 | |
| 647 | if (adap->dev->udev->speed != USB_SPEED_HIGH) |
| 648 | pkt_size = 0x10; |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 649 | |
Malcolm Priestley | b7d425d39 | 2011-10-31 12:02:08 -0300 | [diff] [blame] | 650 | it913x_config.adf = it913x_read_reg(udev, IO_MUX_POWER_CLK); |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 651 | |
Malcolm Priestley | 5081570 | 2011-12-04 08:20:37 -0300 | [diff] [blame] | 652 | if (adap->id == 0) |
| 653 | memcpy(&st->it913x_config, &it913x_config, |
| 654 | sizeof(struct ite_config)); |
| 655 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 656 | adap->fe_adap[0].fe = dvb_attach(it913x_fe_attach, |
Malcolm Priestley | 5081570 | 2011-12-04 08:20:37 -0300 | [diff] [blame] | 657 | &adap->dev->i2c_adap, adap_addr, &st->it913x_config); |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 658 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 659 | if (adap->id == 0 && adap->fe_adap[0].fe) { |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 660 | ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x1); |
| 661 | ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_SW_RST, 0x1); |
| 662 | ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x0f); |
| 663 | ret = it913x_wr_reg(udev, DEV_0, EP0_TX_NAK, 0x1b); |
| 664 | ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x2f); |
| 665 | ret = it913x_wr_reg(udev, DEV_0, EP4_TX_LEN_LSB, |
| 666 | ep_size & 0xff); |
| 667 | ret = it913x_wr_reg(udev, DEV_0, EP4_TX_LEN_MSB, ep_size >> 8); |
Malcolm Priestley | 3822c7c | 2011-11-06 10:24:30 -0300 | [diff] [blame] | 668 | ret = it913x_wr_reg(udev, DEV_0, EP4_MAX_PKT, pkt_size); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 669 | } else if (adap->id == 1 && adap->fe_adap[0].fe) { |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 670 | ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x6f); |
| 671 | ret = it913x_wr_reg(udev, DEV_0, EP5_TX_LEN_LSB, |
| 672 | ep_size & 0xff); |
| 673 | ret = it913x_wr_reg(udev, DEV_0, EP5_TX_LEN_MSB, ep_size >> 8); |
Malcolm Priestley | 3822c7c | 2011-11-06 10:24:30 -0300 | [diff] [blame] | 674 | ret = it913x_wr_reg(udev, DEV_0, EP5_MAX_PKT, pkt_size); |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 675 | ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_EN, 0x1); |
| 676 | ret = it913x_wr_reg(udev, DEV_1_DMOD, MP2IF_SERIAL, 0x1); |
| 677 | ret = it913x_wr_reg(udev, DEV_1, TOP_HOSTB_SER_MODE, 0x1); |
| 678 | ret = it913x_wr_reg(udev, DEV_0_DMOD, TSIS_ENABLE, 0x1); |
| 679 | ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x0); |
| 680 | ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_SW_RST, 0x0); |
| 681 | ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_HALF_PSB, 0x0); |
| 682 | ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF_STOP_EN, 0x1); |
| 683 | ret = it913x_wr_reg(udev, DEV_1_DMOD, MPEG_FULL_SPEED, 0x0); |
| 684 | ret = it913x_wr_reg(udev, DEV_1_DMOD, MP2IF_STOP_EN, 0x0); |
| 685 | } else |
| 686 | return -ENODEV; |
| 687 | |
| 688 | ret = it913x_name(adap); |
| 689 | |
| 690 | return ret; |
| 691 | } |
| 692 | |
| 693 | /* DVB USB Driver */ |
| 694 | static struct dvb_usb_device_properties it913x_properties; |
| 695 | |
| 696 | static int it913x_probe(struct usb_interface *intf, |
| 697 | const struct usb_device_id *id) |
| 698 | { |
| 699 | cmd_counter = 0; |
| 700 | if (0 == dvb_usb_device_init(intf, &it913x_properties, |
| 701 | THIS_MODULE, NULL, adapter_nr)) { |
| 702 | info("DEV registering device driver"); |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | info("DEV it913x Error"); |
| 707 | return -ENODEV; |
| 708 | |
| 709 | } |
| 710 | |
| 711 | static struct usb_device_id it913x_table[] = { |
| 712 | { USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB499_2T_T09) }, |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 713 | { USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135) }, |
Malcolm Priestley | fdb5a91 | 2011-11-06 18:30:26 -0300 | [diff] [blame] | 714 | { USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV22_IT9137) }, |
Malcolm Priestley | 5e642c0 | 2011-11-30 17:16:09 -0300 | [diff] [blame] | 715 | { USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9005) }, |
Malcolm Priestley | 53844c4 | 2011-12-12 15:53:00 -0300 | [diff] [blame] | 716 | { USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9006) }, |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 717 | {} /* Terminating entry */ |
| 718 | }; |
| 719 | |
| 720 | MODULE_DEVICE_TABLE(usb, it913x_table); |
| 721 | |
| 722 | static struct dvb_usb_device_properties it913x_properties = { |
| 723 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
| 724 | .usb_ctrl = DEVICE_SPECIFIC, |
| 725 | .download_firmware = it913x_download_firmware, |
| 726 | .firmware = "dvb-usb-it9137-01.fw", |
| 727 | .no_reconnect = 1, |
| 728 | .size_of_priv = sizeof(struct it913x_state), |
| 729 | .num_adapters = 2, |
| 730 | .adapter = { |
| 731 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 732 | .num_frontends = 1, |
| 733 | .fe = {{ |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 734 | .caps = DVB_USB_ADAP_HAS_PID_FILTER| |
| 735 | DVB_USB_ADAP_NEED_PID_FILTERING| |
| 736 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, |
| 737 | .streaming_ctrl = it913x_streaming_ctrl, |
| 738 | .pid_filter_count = 31, |
| 739 | .pid_filter = it913x_pid_filter, |
| 740 | .pid_filter_ctrl = it913x_pid_filter_ctrl, |
| 741 | .frontend_attach = it913x_frontend_attach, |
| 742 | /* parameter for the MPEG2-data transfer */ |
| 743 | .stream = { |
| 744 | .type = USB_BULK, |
| 745 | .count = 10, |
| 746 | .endpoint = 0x04, |
| 747 | .u = {/* Keep Low if PID filter on */ |
| 748 | .bulk = { |
Malcolm Priestley | 9c1133c | 2011-11-27 17:35:06 -0300 | [diff] [blame] | 749 | .buffersize = |
| 750 | TS_BUFFER_SIZE_PID, |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | } |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 754 | }}, |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 755 | }, |
| 756 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 757 | .num_frontends = 1, |
| 758 | .fe = {{ |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 759 | .caps = DVB_USB_ADAP_HAS_PID_FILTER| |
| 760 | DVB_USB_ADAP_NEED_PID_FILTERING| |
| 761 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, |
| 762 | .streaming_ctrl = it913x_streaming_ctrl, |
| 763 | .pid_filter_count = 31, |
| 764 | .pid_filter = it913x_pid_filter, |
| 765 | .pid_filter_ctrl = it913x_pid_filter_ctrl, |
| 766 | .frontend_attach = it913x_frontend_attach, |
| 767 | /* parameter for the MPEG2-data transfer */ |
| 768 | .stream = { |
| 769 | .type = USB_BULK, |
| 770 | .count = 5, |
| 771 | .endpoint = 0x05, |
| 772 | .u = { |
| 773 | .bulk = { |
Malcolm Priestley | 9c1133c | 2011-11-27 17:35:06 -0300 | [diff] [blame] | 774 | .buffersize = |
| 775 | TS_BUFFER_SIZE_PID, |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | } |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 779 | }}, |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 780 | } |
| 781 | }, |
| 782 | .identify_state = it913x_identify_state, |
tvboxspy | 2ba0f94 | 2011-09-21 18:57:41 -0300 | [diff] [blame] | 783 | .rc.core = { |
| 784 | .protocol = RC_TYPE_NEC, |
| 785 | .module_name = "it913x", |
| 786 | .rc_query = it913x_rc_query, |
| 787 | .rc_interval = IT913X_POLL, |
| 788 | .allowed_protos = RC_TYPE_NEC, |
Malcolm Priestley | c725ff6 | 2011-11-28 18:22:41 -0300 | [diff] [blame] | 789 | .rc_codes = RC_MAP_MSI_DIGIVOX_III, |
tvboxspy | 2ba0f94 | 2011-09-21 18:57:41 -0300 | [diff] [blame] | 790 | }, |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 791 | .i2c_algo = &it913x_i2c_algo, |
Malcolm Priestley | 53844c4 | 2011-12-12 15:53:00 -0300 | [diff] [blame] | 792 | .num_device_descs = 5, |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 793 | .devices = { |
| 794 | { "Kworld UB499-2T T09(IT9137)", |
| 795 | { &it913x_table[0], NULL }, |
| 796 | }, |
Malcolm Priestley | bc54919 | 2011-10-14 19:54:11 -0300 | [diff] [blame] | 797 | { "ITE 9135 Generic", |
| 798 | { &it913x_table[1], NULL }, |
| 799 | }, |
Malcolm Priestley | fdb5a91 | 2011-11-06 18:30:26 -0300 | [diff] [blame] | 800 | { "Sveon STV22 Dual DVB-T HDTV(IT9137)", |
| 801 | { &it913x_table[2], NULL }, |
| 802 | }, |
Malcolm Priestley | 5e642c0 | 2011-11-30 17:16:09 -0300 | [diff] [blame] | 803 | { "ITE 9135(9005) Generic", |
| 804 | { &it913x_table[3], NULL }, |
| 805 | }, |
Malcolm Priestley | 53844c4 | 2011-12-12 15:53:00 -0300 | [diff] [blame] | 806 | { "ITE 9135(9006) Generic", |
| 807 | { &it913x_table[4], NULL }, |
| 808 | }, |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 809 | } |
| 810 | }; |
| 811 | |
| 812 | static struct usb_driver it913x_driver = { |
| 813 | .name = "it913x", |
| 814 | .probe = it913x_probe, |
| 815 | .disconnect = dvb_usb_device_exit, |
| 816 | .id_table = it913x_table, |
| 817 | }; |
| 818 | |
| 819 | /* module stuff */ |
| 820 | static int __init it913x_module_init(void) |
| 821 | { |
| 822 | int result = usb_register(&it913x_driver); |
| 823 | if (result) { |
| 824 | err("usb_register failed. Error number %d", result); |
| 825 | return result; |
| 826 | } |
| 827 | |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | static void __exit it913x_module_exit(void) |
| 832 | { |
| 833 | /* deregister this driver from the USB subsystem */ |
| 834 | usb_deregister(&it913x_driver); |
| 835 | } |
| 836 | |
| 837 | module_init(it913x_module_init); |
| 838 | module_exit(it913x_module_exit); |
| 839 | |
| 840 | MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>"); |
| 841 | MODULE_DESCRIPTION("it913x USB 2 Driver"); |
Malcolm Priestley | ed3189c | 2011-12-30 18:48:00 -0300 | [diff] [blame^] | 842 | MODULE_VERSION("1.18"); |
Malcolm Priestley | f6d8735 | 2011-07-25 15:35:03 -0300 | [diff] [blame] | 843 | MODULE_LICENSE("GPL"); |