Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 1 | /* Linux driver for devices based on the DiBcom DiB0700 USB bridge |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify it |
| 4 | * under the terms of the GNU General Public License as published by the Free |
| 5 | * Software Foundation, version 2. |
| 6 | * |
| 7 | * Copyright (C) 2005-6 DiBcom, SA |
| 8 | */ |
| 9 | #include "dib0700.h" |
| 10 | |
| 11 | /* debug */ |
| 12 | int dvb_usb_dib0700_debug; |
| 13 | module_param_named(debug,dvb_usb_dib0700_debug, int, 0644); |
| 14 | MODULE_PARM_DESC(debug, "set debugging level (1=info,2=fw,4=fwdata,8=data (or-able))." DVB_USB_DEBUG_STATUS); |
| 15 | |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 16 | static int nb_packet_buffer_size = 21; |
| 17 | module_param(nb_packet_buffer_size, int, 0644); |
| 18 | MODULE_PARM_DESC(nb_packet_buffer_size, |
| 19 | "Set the dib0700 driver data buffer size. This parameter " |
| 20 | "corresponds to the number of TS packets. The actual size of " |
| 21 | "the data buffer corresponds to this parameter " |
| 22 | "multiplied by 188 (default: 21)"); |
| 23 | |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 24 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 25 | |
Devin Heitmueller | 99afb98 | 2008-11-15 07:13:07 -0300 | [diff] [blame] | 26 | |
| 27 | int dib0700_get_version(struct dvb_usb_device *d, u32 *hwversion, |
| 28 | u32 *romversion, u32 *ramversion, u32 *fwtype) |
| 29 | { |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 30 | struct dib0700_state *st = d->priv; |
| 31 | int ret; |
| 32 | |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 33 | if (mutex_lock_interruptible(&d->usb_mutex) < 0) { |
Olivier Grenie | 680417b | 2011-08-04 13:10:03 -0300 | [diff] [blame] | 34 | err("could not acquire lock"); |
Santosh Nayak | 26a11eb | 2012-03-19 07:27:37 -0300 | [diff] [blame] | 35 | return -EINTR; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 36 | } |
| 37 | |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 38 | ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), |
Devin Heitmueller | 99afb98 | 2008-11-15 07:13:07 -0300 | [diff] [blame] | 39 | REQUEST_GET_VERSION, |
| 40 | USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 41 | st->buf, 16, USB_CTRL_GET_TIMEOUT); |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 42 | if (hwversion != NULL) |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 43 | *hwversion = (st->buf[0] << 24) | (st->buf[1] << 16) | |
| 44 | (st->buf[2] << 8) | st->buf[3]; |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 45 | if (romversion != NULL) |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 46 | *romversion = (st->buf[4] << 24) | (st->buf[5] << 16) | |
| 47 | (st->buf[6] << 8) | st->buf[7]; |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 48 | if (ramversion != NULL) |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 49 | *ramversion = (st->buf[8] << 24) | (st->buf[9] << 16) | |
| 50 | (st->buf[10] << 8) | st->buf[11]; |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 51 | if (fwtype != NULL) |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 52 | *fwtype = (st->buf[12] << 24) | (st->buf[13] << 16) | |
| 53 | (st->buf[14] << 8) | st->buf[15]; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 54 | mutex_unlock(&d->usb_mutex); |
Devin Heitmueller | 99afb98 | 2008-11-15 07:13:07 -0300 | [diff] [blame] | 55 | return ret; |
| 56 | } |
| 57 | |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 58 | /* expecting rx buffer: request data[0] data[1] ... data[2] */ |
| 59 | static int dib0700_ctrl_wr(struct dvb_usb_device *d, u8 *tx, u8 txlen) |
| 60 | { |
| 61 | int status; |
| 62 | |
| 63 | deb_data(">>> "); |
Daniel Mack | 230b27c | 2010-07-01 01:19:31 -0300 | [diff] [blame] | 64 | debug_dump(tx, txlen, deb_data); |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 65 | |
| 66 | status = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev,0), |
| 67 | tx[0], USB_TYPE_VENDOR | USB_DIR_OUT, 0, 0, tx, txlen, |
| 68 | USB_CTRL_GET_TIMEOUT); |
| 69 | |
| 70 | if (status != txlen) |
Patrick Boettcher | 6958eff | 2006-09-19 12:51:40 -0300 | [diff] [blame] | 71 | deb_data("ep 0 write error (status = %d, len: %d)\n",status,txlen); |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 72 | |
| 73 | return status < 0 ? status : 0; |
| 74 | } |
| 75 | |
| 76 | /* expecting tx buffer: request data[0] ... data[n] (n <= 4) */ |
Olivier DANET | 54d75eb | 2007-07-25 14:42:54 -0300 | [diff] [blame] | 77 | int dib0700_ctrl_rd(struct dvb_usb_device *d, u8 *tx, u8 txlen, u8 *rx, u8 rxlen) |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 78 | { |
| 79 | u16 index, value; |
| 80 | int status; |
| 81 | |
| 82 | if (txlen < 2) { |
| 83 | err("tx buffer length is smaller than 2. Makes no sense."); |
| 84 | return -EINVAL; |
| 85 | } |
| 86 | if (txlen > 4) { |
| 87 | err("tx buffer length is larger than 4. Not supported."); |
| 88 | return -EINVAL; |
| 89 | } |
| 90 | |
| 91 | deb_data(">>> "); |
| 92 | debug_dump(tx,txlen,deb_data); |
| 93 | |
| 94 | value = ((txlen - 2) << 8) | tx[1]; |
| 95 | index = 0; |
| 96 | if (txlen > 2) |
| 97 | index |= (tx[2] << 8); |
| 98 | if (txlen > 3) |
| 99 | index |= tx[3]; |
| 100 | |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 101 | status = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev,0), tx[0], |
| 102 | USB_TYPE_VENDOR | USB_DIR_IN, value, index, rx, rxlen, |
| 103 | USB_CTRL_GET_TIMEOUT); |
| 104 | |
| 105 | if (status < 0) |
Patrick Boettcher | 6958eff | 2006-09-19 12:51:40 -0300 | [diff] [blame] | 106 | deb_info("ep 0 read error (status = %d)\n",status); |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 107 | |
| 108 | deb_data("<<< "); |
Daniel Mack | 230b27c | 2010-07-01 01:19:31 -0300 | [diff] [blame] | 109 | debug_dump(rx, rxlen, deb_data); |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 110 | |
| 111 | return status; /* length in case of success */ |
| 112 | } |
| 113 | |
| 114 | int dib0700_set_gpio(struct dvb_usb_device *d, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val) |
| 115 | { |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 116 | struct dib0700_state *st = d->priv; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 117 | int ret; |
| 118 | |
| 119 | if (mutex_lock_interruptible(&d->usb_mutex) < 0) { |
Olivier Grenie | 680417b | 2011-08-04 13:10:03 -0300 | [diff] [blame] | 120 | err("could not acquire lock"); |
Santosh Nayak | 26a11eb | 2012-03-19 07:27:37 -0300 | [diff] [blame] | 121 | return -EINTR; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 122 | } |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 123 | |
| 124 | st->buf[0] = REQUEST_SET_GPIO; |
| 125 | st->buf[1] = gpio; |
| 126 | st->buf[2] = ((gpio_dir & 0x01) << 7) | ((gpio_val & 0x01) << 6); |
| 127 | |
| 128 | ret = dib0700_ctrl_wr(d, st->buf, 3); |
| 129 | |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 130 | mutex_unlock(&d->usb_mutex); |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 131 | return ret; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 132 | } |
| 133 | |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 134 | static int dib0700_set_usb_xfer_len(struct dvb_usb_device *d, u16 nb_ts_packets) |
| 135 | { |
Daniel Mack | 230b27c | 2010-07-01 01:19:31 -0300 | [diff] [blame] | 136 | struct dib0700_state *st = d->priv; |
Daniel Mack | 230b27c | 2010-07-01 01:19:31 -0300 | [diff] [blame] | 137 | int ret; |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 138 | |
Daniel Mack | 230b27c | 2010-07-01 01:19:31 -0300 | [diff] [blame] | 139 | if (st->fw_version >= 0x10201) { |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 140 | if (mutex_lock_interruptible(&d->usb_mutex) < 0) { |
Olivier Grenie | 680417b | 2011-08-04 13:10:03 -0300 | [diff] [blame] | 141 | err("could not acquire lock"); |
Santosh Nayak | 26a11eb | 2012-03-19 07:27:37 -0300 | [diff] [blame] | 142 | return -EINTR; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 143 | } |
| 144 | |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 145 | st->buf[0] = REQUEST_SET_USB_XFER_LEN; |
| 146 | st->buf[1] = (nb_ts_packets >> 8) & 0xff; |
| 147 | st->buf[2] = nb_ts_packets & 0xff; |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 148 | |
Daniel Mack | 230b27c | 2010-07-01 01:19:31 -0300 | [diff] [blame] | 149 | deb_info("set the USB xfer len to %i Ts packet\n", nb_ts_packets); |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 150 | |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 151 | ret = dib0700_ctrl_wr(d, st->buf, 3); |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 152 | mutex_unlock(&d->usb_mutex); |
Daniel Mack | 230b27c | 2010-07-01 01:19:31 -0300 | [diff] [blame] | 153 | } else { |
| 154 | deb_info("this firmware does not allow to change the USB xfer len\n"); |
| 155 | ret = -EIO; |
| 156 | } |
| 157 | |
| 158 | return ret; |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 159 | } |
| 160 | |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 161 | /* |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 162 | * I2C master xfer function (supported in 1.20 firmware) |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 163 | */ |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 164 | static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg, |
| 165 | int num) |
| 166 | { |
| 167 | /* The new i2c firmware messages are more reliable and in particular |
| 168 | properly support i2c read calls not preceded by a write */ |
| 169 | |
| 170 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 171 | struct dib0700_state *st = d->priv; |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 172 | uint8_t bus_mode = 1; /* 0=eeprom bus, 1=frontend bus */ |
| 173 | uint8_t gen_mode = 0; /* 0=master i2c, 1=gpio i2c */ |
| 174 | uint8_t en_start = 0; |
| 175 | uint8_t en_stop = 0; |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 176 | int result, i; |
| 177 | |
| 178 | /* Ensure nobody else hits the i2c bus while we're sending our |
| 179 | sequence of messages, (such as the remote control thread) */ |
| 180 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
Santosh Nayak | 26a11eb | 2012-03-19 07:27:37 -0300 | [diff] [blame] | 181 | return -EINTR; |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 182 | |
| 183 | for (i = 0; i < num; i++) { |
| 184 | if (i == 0) { |
| 185 | /* First message in the transaction */ |
| 186 | en_start = 1; |
| 187 | } else if (!(msg[i].flags & I2C_M_NOSTART)) { |
| 188 | /* Device supports repeated-start */ |
| 189 | en_start = 1; |
| 190 | } else { |
| 191 | /* Not the first packet and device doesn't support |
| 192 | repeated start */ |
| 193 | en_start = 0; |
| 194 | } |
| 195 | if (i == (num - 1)) { |
| 196 | /* Last message in the transaction */ |
| 197 | en_stop = 1; |
| 198 | } |
| 199 | |
| 200 | if (msg[i].flags & I2C_M_RD) { |
| 201 | /* Read request */ |
| 202 | u16 index, value; |
| 203 | uint8_t i2c_dest; |
| 204 | |
| 205 | i2c_dest = (msg[i].addr << 1); |
| 206 | value = ((en_start << 7) | (en_stop << 6) | |
| 207 | (msg[i].len & 0x3F)) << 8 | i2c_dest; |
| 208 | /* I2C ctrl + FE bus; */ |
Daniel Mack | 230b27c | 2010-07-01 01:19:31 -0300 | [diff] [blame] | 209 | index = ((gen_mode << 6) & 0xC0) | |
| 210 | ((bus_mode << 4) & 0x30); |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 211 | |
| 212 | result = usb_control_msg(d->udev, |
| 213 | usb_rcvctrlpipe(d->udev, 0), |
| 214 | REQUEST_NEW_I2C_READ, |
| 215 | USB_TYPE_VENDOR | USB_DIR_IN, |
Mauro Carvalho Chehab | fa1ecd8 | 2016-10-07 06:53:51 -0300 | [diff] [blame] | 216 | value, index, st->buf, |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 217 | msg[i].len, |
| 218 | USB_CTRL_GET_TIMEOUT); |
| 219 | if (result < 0) { |
Olivier Grenie | be9bae1 | 2011-01-04 05:42:19 -0300 | [diff] [blame] | 220 | deb_info("i2c read error (status = %d)\n", result); |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 221 | break; |
| 222 | } |
Michael Krufky | d251499 | 2009-01-30 00:24:01 -0300 | [diff] [blame] | 223 | |
Mauro Carvalho Chehab | fa1ecd8 | 2016-10-07 06:53:51 -0300 | [diff] [blame] | 224 | if (msg[i].len > sizeof(st->buf)) { |
| 225 | deb_info("buffer too small to fit %d bytes\n", |
| 226 | msg[i].len); |
| 227 | return -EIO; |
| 228 | } |
| 229 | |
| 230 | memcpy(msg[i].buf, st->buf, msg[i].len); |
| 231 | |
Michael Krufky | d251499 | 2009-01-30 00:24:01 -0300 | [diff] [blame] | 232 | deb_data("<<< "); |
| 233 | debug_dump(msg[i].buf, msg[i].len, deb_data); |
| 234 | |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 235 | } else { |
| 236 | /* Write request */ |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 237 | if (mutex_lock_interruptible(&d->usb_mutex) < 0) { |
Olivier Grenie | 680417b | 2011-08-04 13:10:03 -0300 | [diff] [blame] | 238 | err("could not acquire lock"); |
Santosh Nayak | 26a11eb | 2012-03-19 07:27:37 -0300 | [diff] [blame] | 239 | mutex_unlock(&d->i2c_mutex); |
| 240 | return -EINTR; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 241 | } |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 242 | st->buf[0] = REQUEST_NEW_I2C_WRITE; |
| 243 | st->buf[1] = msg[i].addr << 1; |
| 244 | st->buf[2] = (en_start << 7) | (en_stop << 6) | |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 245 | (msg[i].len & 0x3F); |
| 246 | /* I2C ctrl + FE bus; */ |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 247 | st->buf[3] = ((gen_mode << 6) & 0xC0) | |
Daniel Mack | 230b27c | 2010-07-01 01:19:31 -0300 | [diff] [blame] | 248 | ((bus_mode << 4) & 0x30); |
Mauro Carvalho Chehab | fa1ecd8 | 2016-10-07 06:53:51 -0300 | [diff] [blame] | 249 | |
| 250 | if (msg[i].len > sizeof(st->buf) - 4) { |
| 251 | deb_info("i2c message to big: %d\n", |
| 252 | msg[i].len); |
| 253 | return -EIO; |
| 254 | } |
| 255 | |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 256 | /* The Actual i2c payload */ |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 257 | memcpy(&st->buf[4], msg[i].buf, msg[i].len); |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 258 | |
Michael Krufky | d251499 | 2009-01-30 00:24:01 -0300 | [diff] [blame] | 259 | deb_data(">>> "); |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 260 | debug_dump(st->buf, msg[i].len + 4, deb_data); |
Michael Krufky | d251499 | 2009-01-30 00:24:01 -0300 | [diff] [blame] | 261 | |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 262 | result = usb_control_msg(d->udev, |
| 263 | usb_sndctrlpipe(d->udev, 0), |
| 264 | REQUEST_NEW_I2C_WRITE, |
| 265 | USB_TYPE_VENDOR | USB_DIR_OUT, |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 266 | 0, 0, st->buf, msg[i].len + 4, |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 267 | USB_CTRL_GET_TIMEOUT); |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 268 | mutex_unlock(&d->usb_mutex); |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 269 | if (result < 0) { |
Olivier Grenie | be9bae1 | 2011-01-04 05:42:19 -0300 | [diff] [blame] | 270 | deb_info("i2c write error (status = %d)\n", result); |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 271 | break; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | mutex_unlock(&d->i2c_mutex); |
| 276 | return i; |
| 277 | } |
| 278 | |
| 279 | /* |
| 280 | * I2C master xfer function (pre-1.20 firmware) |
| 281 | */ |
| 282 | static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap, |
| 283 | struct i2c_msg *msg, int num) |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 284 | { |
| 285 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 286 | struct dib0700_state *st = d->priv; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 287 | int i,len; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 288 | |
| 289 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
Santosh Nayak | 26a11eb | 2012-03-19 07:27:37 -0300 | [diff] [blame] | 290 | return -EINTR; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 291 | if (mutex_lock_interruptible(&d->usb_mutex) < 0) { |
Olivier Grenie | 680417b | 2011-08-04 13:10:03 -0300 | [diff] [blame] | 292 | err("could not acquire lock"); |
Santosh Nayak | 26a11eb | 2012-03-19 07:27:37 -0300 | [diff] [blame] | 293 | mutex_unlock(&d->i2c_mutex); |
| 294 | return -EINTR; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 295 | } |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 296 | |
| 297 | for (i = 0; i < num; i++) { |
| 298 | /* fill in the address */ |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 299 | st->buf[1] = msg[i].addr << 1; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 300 | /* fill the buffer */ |
Mauro Carvalho Chehab | fa1ecd8 | 2016-10-07 06:53:51 -0300 | [diff] [blame] | 301 | if (msg[i].len > sizeof(st->buf) - 2) { |
| 302 | deb_info("i2c xfer to big: %d\n", |
| 303 | msg[i].len); |
| 304 | return -EIO; |
| 305 | } |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 306 | memcpy(&st->buf[2], msg[i].buf, msg[i].len); |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 307 | |
| 308 | /* write/read request */ |
| 309 | if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 310 | st->buf[0] = REQUEST_I2C_READ; |
| 311 | st->buf[1] |= 1; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 312 | |
| 313 | /* special thing in the current firmware: when length is zero the read-failed */ |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 314 | len = dib0700_ctrl_rd(d, st->buf, msg[i].len + 2, |
Mauro Carvalho Chehab | bd1f976 | 2016-10-07 06:40:24 -0300 | [diff] [blame] | 315 | st->buf, msg[i + 1].len); |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 316 | if (len <= 0) { |
Devin Heitmueller | 8db12cd | 2009-01-21 01:40:04 -0300 | [diff] [blame] | 317 | deb_info("I2C read failed on address 0x%02x\n", |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 318 | msg[i].addr); |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 319 | break; |
Patrick Boettcher | 303cbea | 2006-09-19 12:51:56 -0300 | [diff] [blame] | 320 | } |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 321 | |
Mauro Carvalho Chehab | fa1ecd8 | 2016-10-07 06:53:51 -0300 | [diff] [blame] | 322 | if (msg[i + 1].len > sizeof(st->buf)) { |
| 323 | deb_info("i2c xfer buffer to small for %d\n", |
| 324 | msg[i].len); |
| 325 | return -EIO; |
| 326 | } |
Mauro Carvalho Chehab | bd1f976 | 2016-10-07 06:40:24 -0300 | [diff] [blame] | 327 | memcpy(msg[i + 1].buf, st->buf, msg[i + 1].len); |
| 328 | |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 329 | msg[i+1].len = len; |
| 330 | |
| 331 | i++; |
| 332 | } else { |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 333 | st->buf[0] = REQUEST_I2C_WRITE; |
| 334 | if (dib0700_ctrl_wr(d, st->buf, msg[i].len + 2) < 0) |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 335 | break; |
| 336 | } |
| 337 | } |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 338 | mutex_unlock(&d->usb_mutex); |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 339 | mutex_unlock(&d->i2c_mutex); |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 340 | |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 341 | return i; |
| 342 | } |
| 343 | |
Devin Heitmueller | bdc203e | 2008-09-06 13:45:27 -0300 | [diff] [blame] | 344 | static int dib0700_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, |
| 345 | int num) |
| 346 | { |
| 347 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 348 | struct dib0700_state *st = d->priv; |
| 349 | |
| 350 | if (st->fw_use_new_i2c_api == 1) { |
| 351 | /* User running at least fw 1.20 */ |
| 352 | return dib0700_i2c_xfer_new(adap, msg, num); |
| 353 | } else { |
| 354 | /* Use legacy calls */ |
| 355 | return dib0700_i2c_xfer_legacy(adap, msg, num); |
| 356 | } |
| 357 | } |
| 358 | |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 359 | static u32 dib0700_i2c_func(struct i2c_adapter *adapter) |
| 360 | { |
| 361 | return I2C_FUNC_I2C; |
| 362 | } |
| 363 | |
| 364 | struct i2c_algorithm dib0700_i2c_algo = { |
| 365 | .master_xfer = dib0700_i2c_xfer, |
| 366 | .functionality = dib0700_i2c_func, |
| 367 | }; |
| 368 | |
Patrick Boettcher | 6958eff | 2006-09-19 12:51:40 -0300 | [diff] [blame] | 369 | int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props, |
| 370 | struct dvb_usb_device_description **desc, int *cold) |
| 371 | { |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 372 | s16 ret; |
| 373 | u8 *b; |
| 374 | |
| 375 | b = kmalloc(16, GFP_KERNEL); |
| 376 | if (!b) |
| 377 | return -ENOMEM; |
| 378 | |
| 379 | |
| 380 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
Patrick Boettcher | a75763f | 2006-10-18 08:34:16 -0300 | [diff] [blame] | 381 | REQUEST_GET_VERSION, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, b, 16, USB_CTRL_GET_TIMEOUT); |
| 382 | |
| 383 | deb_info("FW GET_VERSION length: %d\n",ret); |
| 384 | |
| 385 | *cold = ret <= 0; |
Patrick Boettcher | 6958eff | 2006-09-19 12:51:40 -0300 | [diff] [blame] | 386 | deb_info("cold: %d\n", *cold); |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 387 | |
| 388 | kfree(b); |
Patrick Boettcher | 6958eff | 2006-09-19 12:51:40 -0300 | [diff] [blame] | 389 | return 0; |
| 390 | } |
| 391 | |
Patrick Boettcher | a75763f | 2006-10-18 08:34:16 -0300 | [diff] [blame] | 392 | static int dib0700_set_clock(struct dvb_usb_device *d, u8 en_pll, |
| 393 | u8 pll_src, u8 pll_range, u8 clock_gpio3, u16 pll_prediv, |
| 394 | u16 pll_loopdiv, u16 free_div, u16 dsuScaler) |
| 395 | { |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 396 | struct dib0700_state *st = d->priv; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 397 | int ret; |
| 398 | |
| 399 | if (mutex_lock_interruptible(&d->usb_mutex) < 0) { |
Olivier Grenie | 680417b | 2011-08-04 13:10:03 -0300 | [diff] [blame] | 400 | err("could not acquire lock"); |
Santosh Nayak | 26a11eb | 2012-03-19 07:27:37 -0300 | [diff] [blame] | 401 | return -EINTR; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 402 | } |
Patrick Boettcher | a75763f | 2006-10-18 08:34:16 -0300 | [diff] [blame] | 403 | |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 404 | st->buf[0] = REQUEST_SET_CLOCK; |
| 405 | st->buf[1] = (en_pll << 7) | (pll_src << 6) | |
| 406 | (pll_range << 5) | (clock_gpio3 << 4); |
| 407 | st->buf[2] = (pll_prediv >> 8) & 0xff; /* MSB */ |
| 408 | st->buf[3] = pll_prediv & 0xff; /* LSB */ |
| 409 | st->buf[4] = (pll_loopdiv >> 8) & 0xff; /* MSB */ |
| 410 | st->buf[5] = pll_loopdiv & 0xff; /* LSB */ |
| 411 | st->buf[6] = (free_div >> 8) & 0xff; /* MSB */ |
| 412 | st->buf[7] = free_div & 0xff; /* LSB */ |
| 413 | st->buf[8] = (dsuScaler >> 8) & 0xff; /* MSB */ |
| 414 | st->buf[9] = dsuScaler & 0xff; /* LSB */ |
| 415 | |
| 416 | ret = dib0700_ctrl_wr(d, st->buf, 10); |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 417 | mutex_unlock(&d->usb_mutex); |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 418 | |
| 419 | return ret; |
Patrick Boettcher | a75763f | 2006-10-18 08:34:16 -0300 | [diff] [blame] | 420 | } |
| 421 | |
Olivier Grenie | 7757ddd | 2011-01-03 15:30:14 -0300 | [diff] [blame] | 422 | int dib0700_set_i2c_speed(struct dvb_usb_device *d, u16 scl_kHz) |
| 423 | { |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 424 | struct dib0700_state *st = d->priv; |
Olivier Grenie | 7757ddd | 2011-01-03 15:30:14 -0300 | [diff] [blame] | 425 | u16 divider; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 426 | int ret; |
Olivier Grenie | 7757ddd | 2011-01-03 15:30:14 -0300 | [diff] [blame] | 427 | |
| 428 | if (scl_kHz == 0) |
| 429 | return -EINVAL; |
| 430 | |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 431 | if (mutex_lock_interruptible(&d->usb_mutex) < 0) { |
Olivier Grenie | 680417b | 2011-08-04 13:10:03 -0300 | [diff] [blame] | 432 | err("could not acquire lock"); |
Santosh Nayak | 26a11eb | 2012-03-19 07:27:37 -0300 | [diff] [blame] | 433 | return -EINTR; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 434 | } |
| 435 | |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 436 | st->buf[0] = REQUEST_SET_I2C_PARAM; |
Olivier Grenie | 7757ddd | 2011-01-03 15:30:14 -0300 | [diff] [blame] | 437 | divider = (u16) (30000 / scl_kHz); |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 438 | st->buf[1] = 0; |
| 439 | st->buf[2] = (u8) (divider >> 8); |
| 440 | st->buf[3] = (u8) (divider & 0xff); |
Olivier Grenie | 7757ddd | 2011-01-03 15:30:14 -0300 | [diff] [blame] | 441 | divider = (u16) (72000 / scl_kHz); |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 442 | st->buf[4] = (u8) (divider >> 8); |
| 443 | st->buf[5] = (u8) (divider & 0xff); |
Olivier Grenie | 7757ddd | 2011-01-03 15:30:14 -0300 | [diff] [blame] | 444 | divider = (u16) (72000 / scl_kHz); /* clock: 72MHz */ |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 445 | st->buf[6] = (u8) (divider >> 8); |
| 446 | st->buf[7] = (u8) (divider & 0xff); |
Olivier Grenie | 7757ddd | 2011-01-03 15:30:14 -0300 | [diff] [blame] | 447 | |
Olivier Grenie | b4d6046e | 2011-01-04 13:08:14 -0300 | [diff] [blame] | 448 | deb_info("setting I2C speed: %04x %04x %04x (%d kHz).", |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 449 | (st->buf[2] << 8) | (st->buf[3]), (st->buf[4] << 8) | |
| 450 | st->buf[5], (st->buf[6] << 8) | st->buf[7], scl_kHz); |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 451 | |
| 452 | ret = dib0700_ctrl_wr(d, st->buf, 8); |
| 453 | mutex_unlock(&d->usb_mutex); |
| 454 | |
| 455 | return ret; |
Olivier Grenie | 7757ddd | 2011-01-03 15:30:14 -0300 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | |
Patrick Boettcher | a75763f | 2006-10-18 08:34:16 -0300 | [diff] [blame] | 459 | int dib0700_ctrl_clock(struct dvb_usb_device *d, u32 clk_MHz, u8 clock_out_gp3) |
| 460 | { |
| 461 | switch (clk_MHz) { |
| 462 | case 72: dib0700_set_clock(d, 1, 0, 1, clock_out_gp3, 2, 24, 0, 0x4c); break; |
| 463 | default: return -EINVAL; |
| 464 | } |
| 465 | return 0; |
| 466 | } |
| 467 | |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 468 | static int dib0700_jumpram(struct usb_device *udev, u32 address) |
| 469 | { |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 470 | int ret = 0, actlen; |
| 471 | u8 *buf; |
| 472 | |
| 473 | buf = kmalloc(8, GFP_KERNEL); |
| 474 | if (!buf) |
| 475 | return -ENOMEM; |
| 476 | buf[0] = REQUEST_JUMPRAM; |
| 477 | buf[1] = 0; |
| 478 | buf[2] = 0; |
| 479 | buf[3] = 0; |
| 480 | buf[4] = (address >> 24) & 0xff; |
| 481 | buf[5] = (address >> 16) & 0xff; |
| 482 | buf[6] = (address >> 8) & 0xff; |
| 483 | buf[7] = address & 0xff; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 484 | |
| 485 | if ((ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x01),buf,8,&actlen,1000)) < 0) { |
| 486 | deb_fw("jumpram to 0x%x failed\n",address); |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 487 | goto out; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 488 | } |
| 489 | if (actlen != 8) { |
| 490 | deb_fw("jumpram to 0x%x failed\n",address); |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 491 | ret = -EIO; |
| 492 | goto out; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 493 | } |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 494 | out: |
| 495 | kfree(buf); |
| 496 | return ret; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw) |
| 500 | { |
| 501 | struct hexline hx; |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 502 | int pos = 0, ret, act_len, i, adap_num; |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 503 | u8 *buf; |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 504 | u32 fw_version; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 505 | |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 506 | buf = kmalloc(260, GFP_KERNEL); |
| 507 | if (!buf) |
| 508 | return -ENOMEM; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 509 | |
| 510 | while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) { |
Daniel Mack | 230b27c | 2010-07-01 01:19:31 -0300 | [diff] [blame] | 511 | deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n", |
| 512 | hx.addr, hx.len, hx.chk); |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 513 | |
| 514 | buf[0] = hx.len; |
Patrick Boettcher | 5bc6360 | 2006-09-19 12:51:46 -0300 | [diff] [blame] | 515 | buf[1] = (hx.addr >> 8) & 0xff; |
| 516 | buf[2] = hx.addr & 0xff; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 517 | buf[3] = hx.type; |
| 518 | memcpy(&buf[4],hx.data,hx.len); |
| 519 | buf[4+hx.len] = hx.chk; |
| 520 | |
| 521 | ret = usb_bulk_msg(udev, |
| 522 | usb_sndbulkpipe(udev, 0x01), |
| 523 | buf, |
| 524 | hx.len + 5, |
| 525 | &act_len, |
| 526 | 1000); |
| 527 | |
| 528 | if (ret < 0) { |
| 529 | err("firmware download failed at %d with %d",pos,ret); |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 530 | goto out; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
| 534 | if (ret == 0) { |
| 535 | /* start the firmware */ |
Patrick Boettcher | 6958eff | 2006-09-19 12:51:40 -0300 | [diff] [blame] | 536 | if ((ret = dib0700_jumpram(udev, 0x70000000)) == 0) { |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 537 | info("firmware started successfully."); |
Patrick Boettcher | a75763f | 2006-10-18 08:34:16 -0300 | [diff] [blame] | 538 | msleep(500); |
Patrick Boettcher | 6958eff | 2006-09-19 12:51:40 -0300 | [diff] [blame] | 539 | } |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 540 | } else |
| 541 | ret = -EIO; |
| 542 | |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 543 | /* the number of ts packet has to be at least 1 */ |
| 544 | if (nb_packet_buffer_size < 1) |
| 545 | nb_packet_buffer_size = 1; |
| 546 | |
Kees Cook | bad7de7 | 2016-05-19 17:09:14 -0700 | [diff] [blame] | 547 | /* get the firmware version */ |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 548 | usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
| 549 | REQUEST_GET_VERSION, |
| 550 | USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 551 | buf, 16, USB_CTRL_GET_TIMEOUT); |
| 552 | fw_version = (buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11]; |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 553 | |
| 554 | /* set the buffer size - DVB-USB is allocating URB buffers |
| 555 | * only after the firwmare download was successful */ |
| 556 | for (i = 0; i < dib0700_device_count; i++) { |
| 557 | for (adap_num = 0; adap_num < dib0700_devices[i].num_adapters; |
| 558 | adap_num++) { |
Daniel Mack | 230b27c | 2010-07-01 01:19:31 -0300 | [diff] [blame] | 559 | if (fw_version >= 0x10201) { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 560 | dib0700_devices[i].adapter[adap_num].fe[0].stream.u.bulk.buffersize = 188*nb_packet_buffer_size; |
Daniel Mack | 230b27c | 2010-07-01 01:19:31 -0300 | [diff] [blame] | 561 | } else { |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 562 | /* for fw version older than 1.20.1, |
| 563 | * the buffersize has to be n times 512 */ |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 564 | dib0700_devices[i].adapter[adap_num].fe[0].stream.u.bulk.buffersize = ((188*nb_packet_buffer_size+188/2)/512)*512; |
| 565 | if (dib0700_devices[i].adapter[adap_num].fe[0].stream.u.bulk.buffersize < 512) |
| 566 | dib0700_devices[i].adapter[adap_num].fe[0].stream.u.bulk.buffersize = 512; |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | } |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 570 | out: |
| 571 | kfree(buf); |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 572 | return ret; |
| 573 | } |
| 574 | |
| 575 | int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) |
| 576 | { |
| 577 | struct dib0700_state *st = adap->dev->priv; |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 578 | int ret; |
| 579 | |
| 580 | if ((onoff != 0) && (st->fw_version >= 0x10201)) { |
| 581 | /* for firmware later than 1.20.1, |
| 582 | * the USB xfer length can be set */ |
| 583 | ret = dib0700_set_usb_xfer_len(adap->dev, |
| 584 | st->nb_packet_buffer_size); |
| 585 | if (ret < 0) { |
| 586 | deb_info("can not set the USB xfer len\n"); |
| 587 | return ret; |
| 588 | } |
| 589 | } |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 590 | |
Jiri Slaby | a96fbe0 | 2013-01-03 12:53:53 -0300 | [diff] [blame] | 591 | mutex_lock(&adap->dev->usb_mutex); |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 592 | |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 593 | st->buf[0] = REQUEST_ENABLE_VIDEO; |
| 594 | /* this bit gives a kind of command, |
| 595 | * rather than enabling something or not */ |
| 596 | st->buf[1] = (onoff << 4) | 0x00; |
Devin Heitmueller | cb22cb5 | 2008-09-08 05:42:42 -0300 | [diff] [blame] | 597 | |
| 598 | if (st->disable_streaming_master_mode == 1) |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 599 | st->buf[2] = 0x00; |
Devin Heitmueller | cb22cb5 | 2008-09-08 05:42:42 -0300 | [diff] [blame] | 600 | else |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 601 | st->buf[2] = 0x01 << 4; /* Master mode */ |
Devin Heitmueller | cb22cb5 | 2008-09-08 05:42:42 -0300 | [diff] [blame] | 602 | |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 603 | st->buf[3] = 0x00; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 604 | |
| 605 | deb_info("modifying (%d) streaming state for %d\n", onoff, adap->id); |
| 606 | |
Olivier Grenie | 7757ddd | 2011-01-03 15:30:14 -0300 | [diff] [blame] | 607 | st->channel_state &= ~0x3; |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 608 | if ((adap->fe_adap[0].stream.props.endpoint != 2) |
| 609 | && (adap->fe_adap[0].stream.props.endpoint != 3)) { |
| 610 | deb_info("the endpoint number (%i) is not correct, use the adapter id instead", adap->fe_adap[0].stream.props.endpoint); |
Olivier Grenie | 7757ddd | 2011-01-03 15:30:14 -0300 | [diff] [blame] | 611 | if (onoff) |
| 612 | st->channel_state |= 1 << (adap->id); |
| 613 | else |
Mauro Carvalho Chehab | f85ed0c | 2013-02-06 08:29:39 -0200 | [diff] [blame] | 614 | st->channel_state |= 1 << ~(adap->id); |
Olivier Grenie | b4d6046e | 2011-01-04 13:08:14 -0300 | [diff] [blame] | 615 | } else { |
Olivier Grenie | 7757ddd | 2011-01-03 15:30:14 -0300 | [diff] [blame] | 616 | if (onoff) |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 617 | st->channel_state |= 1 << (adap->fe_adap[0].stream.props.endpoint-2); |
Olivier Grenie | 7757ddd | 2011-01-03 15:30:14 -0300 | [diff] [blame] | 618 | else |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 619 | st->channel_state |= 1 << (3-adap->fe_adap[0].stream.props.endpoint); |
Olivier Grenie | 7757ddd | 2011-01-03 15:30:14 -0300 | [diff] [blame] | 620 | } |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 621 | |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 622 | st->buf[2] |= st->channel_state; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 623 | |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 624 | deb_info("data for streaming: %x %x\n", st->buf[1], st->buf[2]); |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 625 | |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 626 | ret = dib0700_ctrl_wr(adap->dev, st->buf, 4); |
| 627 | mutex_unlock(&adap->dev->usb_mutex); |
| 628 | |
| 629 | return ret; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 630 | } |
| 631 | |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 632 | int dib0700_change_protocol(struct rc_dev *rc, u64 *rc_type) |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 633 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 634 | struct dvb_usb_device *d = rc->priv; |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 635 | struct dib0700_state *st = d->priv; |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 636 | int new_proto, ret; |
| 637 | |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 638 | if (mutex_lock_interruptible(&d->usb_mutex) < 0) { |
Olivier Grenie | 680417b | 2011-08-04 13:10:03 -0300 | [diff] [blame] | 639 | err("could not acquire lock"); |
Santosh Nayak | 26a11eb | 2012-03-19 07:27:37 -0300 | [diff] [blame] | 640 | return -EINTR; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 641 | } |
| 642 | |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 643 | st->buf[0] = REQUEST_SET_RC; |
| 644 | st->buf[1] = 0; |
| 645 | st->buf[2] = 0; |
| 646 | |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 647 | /* Set the IR mode */ |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 648 | if (*rc_type & RC_BIT_RC5) { |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 649 | new_proto = 1; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 650 | *rc_type = RC_BIT_RC5; |
| 651 | } else if (*rc_type & RC_BIT_NEC) { |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 652 | new_proto = 0; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 653 | *rc_type = RC_BIT_NEC; |
| 654 | } else if (*rc_type & RC_BIT_RC6_MCE) { |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 655 | if (st->fw_version < 0x10200) { |
| 656 | ret = -EINVAL; |
| 657 | goto out; |
| 658 | } |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 659 | new_proto = 2; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 660 | *rc_type = RC_BIT_RC6_MCE; |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 661 | } else { |
| 662 | ret = -EINVAL; |
| 663 | goto out; |
| 664 | } |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 665 | |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 666 | st->buf[1] = new_proto; |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 667 | |
Olivier Grenie | ffa5899 | 2011-03-24 09:32:26 -0300 | [diff] [blame] | 668 | ret = dib0700_ctrl_wr(d, st->buf, 3); |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 669 | if (ret < 0) { |
| 670 | err("ir protocol setup failed"); |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 671 | goto out; |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 672 | } |
| 673 | |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 674 | d->props.rc.core.protocol = *rc_type; |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 675 | |
Olivier Grenie | bff469f | 2011-08-01 12:45:58 -0300 | [diff] [blame] | 676 | out: |
| 677 | mutex_unlock(&d->usb_mutex); |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 678 | return ret; |
| 679 | } |
| 680 | |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 681 | /* This is the structure of the RC response packet starting in firmware 1.20 */ |
| 682 | struct dib0700_rc_response { |
| 683 | u8 report_id; |
| 684 | u8 data_state; |
David Härdeman | 4d298b8 | 2015-03-30 17:51:01 -0300 | [diff] [blame] | 685 | union { |
| 686 | struct { |
| 687 | u8 system; |
| 688 | u8 not_system; |
| 689 | u8 data; |
| 690 | u8 not_data; |
| 691 | } nec; |
| 692 | struct { |
| 693 | u8 not_used; |
| 694 | u8 system; |
| 695 | u8 data; |
| 696 | u8 not_data; |
| 697 | } rc5; |
| 698 | }; |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 699 | }; |
| 700 | #define RC_MSG_SIZE_V1_20 6 |
| 701 | |
| 702 | static void dib0700_rc_urb_completion(struct urb *purb) |
| 703 | { |
| 704 | struct dvb_usb_device *d = purb->context; |
Mauro Carvalho Chehab | d3c501d | 2010-08-01 10:35:49 -0300 | [diff] [blame] | 705 | struct dib0700_rc_response *poll_reply; |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 706 | enum rc_type protocol; |
Sean Young | ba13e98 | 2016-11-10 17:44:49 +0100 | [diff] [blame] | 707 | u32 keycode; |
Mauro Carvalho Chehab | 72b3931 | 2010-07-31 22:56:00 -0300 | [diff] [blame] | 708 | u8 toggle; |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 709 | |
| 710 | deb_info("%s()\n", __func__); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 711 | if (d->rc_dev == NULL) { |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 712 | /* This will occur if disable_rc_polling=1 */ |
Jean Delvare | d3db22e | 2012-03-13 13:52:50 -0300 | [diff] [blame] | 713 | kfree(purb->transfer_buffer); |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 714 | usb_free_urb(purb); |
| 715 | return; |
| 716 | } |
| 717 | |
Mauro Carvalho Chehab | d3c501d | 2010-08-01 10:35:49 -0300 | [diff] [blame] | 718 | poll_reply = purb->transfer_buffer; |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 719 | |
| 720 | if (purb->status < 0) { |
| 721 | deb_info("discontinuing polling\n"); |
Jean Delvare | d3db22e | 2012-03-13 13:52:50 -0300 | [diff] [blame] | 722 | kfree(purb->transfer_buffer); |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 723 | usb_free_urb(purb); |
| 724 | return; |
| 725 | } |
| 726 | |
| 727 | if (purb->actual_length != RC_MSG_SIZE_V1_20) { |
| 728 | deb_info("malformed rc msg size=%d\n", purb->actual_length); |
| 729 | goto resubmit; |
| 730 | } |
| 731 | |
Mauro Carvalho Chehab | d3c501d | 2010-08-01 10:35:49 -0300 | [diff] [blame] | 732 | deb_data("IR ID = %02X state = %02X System = %02X %02X Cmd = %02X %02X (len %d)\n", |
| 733 | poll_reply->report_id, poll_reply->data_state, |
David Härdeman | 4d298b8 | 2015-03-30 17:51:01 -0300 | [diff] [blame] | 734 | poll_reply->nec.system, poll_reply->nec.not_system, |
| 735 | poll_reply->nec.data, poll_reply->nec.not_data, |
Mauro Carvalho Chehab | d3c501d | 2010-08-01 10:35:49 -0300 | [diff] [blame] | 736 | purb->actual_length); |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 737 | |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 738 | switch (d->props.rc.core.protocol) { |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 739 | case RC_BIT_NEC: |
Mauro Carvalho Chehab | 72b3931 | 2010-07-31 22:56:00 -0300 | [diff] [blame] | 740 | toggle = 0; |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 741 | |
| 742 | /* NEC protocol sends repeat code as 0 0 0 FF */ |
David Härdeman | 4d298b8 | 2015-03-30 17:51:01 -0300 | [diff] [blame] | 743 | if (poll_reply->nec.system == 0x00 && |
| 744 | poll_reply->nec.not_system == 0x00 && |
| 745 | poll_reply->nec.data == 0x00 && |
| 746 | poll_reply->nec.not_data == 0xff) { |
Mauro Carvalho Chehab | d3c501d | 2010-08-01 10:35:49 -0300 | [diff] [blame] | 747 | poll_reply->data_state = 2; |
Sean Young | ba13e98 | 2016-11-10 17:44:49 +0100 | [diff] [blame] | 748 | rc_repeat(d->rc_dev); |
| 749 | goto resubmit; |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 750 | } |
Mauro Carvalho Chehab | 72b3931 | 2010-07-31 22:56:00 -0300 | [diff] [blame] | 751 | |
David Härdeman | 4d298b8 | 2015-03-30 17:51:01 -0300 | [diff] [blame] | 752 | if ((poll_reply->nec.data ^ poll_reply->nec.not_data) != 0xff) { |
David Härdeman | af3a4a9 | 2014-04-03 20:31:51 -0300 | [diff] [blame] | 753 | deb_data("NEC32 protocol\n"); |
David Härdeman | 4d298b8 | 2015-03-30 17:51:01 -0300 | [diff] [blame] | 754 | keycode = RC_SCANCODE_NEC32(poll_reply->nec.system << 24 | |
| 755 | poll_reply->nec.not_system << 16 | |
| 756 | poll_reply->nec.data << 8 | |
| 757 | poll_reply->nec.not_data); |
Sean Young | 2ceeca0 | 2016-09-21 06:54:19 -0300 | [diff] [blame] | 758 | protocol = RC_TYPE_NEC32; |
David Härdeman | 4d298b8 | 2015-03-30 17:51:01 -0300 | [diff] [blame] | 759 | } else if ((poll_reply->nec.system ^ poll_reply->nec.not_system) != 0xff) { |
Mauro Carvalho Chehab | d3c501d | 2010-08-01 10:35:49 -0300 | [diff] [blame] | 760 | deb_data("NEC extended protocol\n"); |
David Härdeman | 4d298b8 | 2015-03-30 17:51:01 -0300 | [diff] [blame] | 761 | keycode = RC_SCANCODE_NECX(poll_reply->nec.system << 8 | |
| 762 | poll_reply->nec.not_system, |
| 763 | poll_reply->nec.data); |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 764 | |
Sean Young | 2ceeca0 | 2016-09-21 06:54:19 -0300 | [diff] [blame] | 765 | protocol = RC_TYPE_NECX; |
Mauro Carvalho Chehab | d3c501d | 2010-08-01 10:35:49 -0300 | [diff] [blame] | 766 | } else { |
| 767 | deb_data("NEC normal protocol\n"); |
David Härdeman | 4d298b8 | 2015-03-30 17:51:01 -0300 | [diff] [blame] | 768 | keycode = RC_SCANCODE_NEC(poll_reply->nec.system, |
| 769 | poll_reply->nec.data); |
Sean Young | 2ceeca0 | 2016-09-21 06:54:19 -0300 | [diff] [blame] | 770 | protocol = RC_TYPE_NEC; |
Mauro Carvalho Chehab | d3c501d | 2010-08-01 10:35:49 -0300 | [diff] [blame] | 771 | } |
| 772 | |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 773 | break; |
| 774 | default: |
Mauro Carvalho Chehab | d3c501d | 2010-08-01 10:35:49 -0300 | [diff] [blame] | 775 | deb_data("RC5 protocol\n"); |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 776 | protocol = RC_TYPE_RC5; |
Mauro Carvalho Chehab | d3c501d | 2010-08-01 10:35:49 -0300 | [diff] [blame] | 777 | toggle = poll_reply->report_id; |
David Härdeman | 4d298b8 | 2015-03-30 17:51:01 -0300 | [diff] [blame] | 778 | keycode = RC_SCANCODE_RC5(poll_reply->rc5.system, poll_reply->rc5.data); |
| 779 | |
| 780 | if ((poll_reply->rc5.data ^ poll_reply->rc5.not_data) != 0xff) { |
| 781 | /* Key failed integrity check */ |
| 782 | err("key failed integrity check: %02x %02x %02x %02x", |
| 783 | poll_reply->rc5.not_used, poll_reply->rc5.system, |
| 784 | poll_reply->rc5.data, poll_reply->rc5.not_data); |
| 785 | goto resubmit; |
| 786 | } |
Mauro Carvalho Chehab | 72b3931 | 2010-07-31 22:56:00 -0300 | [diff] [blame] | 787 | |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 788 | break; |
| 789 | } |
| 790 | |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 791 | rc_keydown(d->rc_dev, protocol, keycode, toggle); |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 792 | |
| 793 | resubmit: |
| 794 | /* Clean the buffer before we requeue */ |
| 795 | memset(purb->transfer_buffer, 0, RC_MSG_SIZE_V1_20); |
| 796 | |
| 797 | /* Requeue URB */ |
| 798 | usb_submit_urb(purb, GFP_ATOMIC); |
| 799 | } |
| 800 | |
Mauro Carvalho Chehab | c4018fa | 2014-05-21 17:40:25 -0300 | [diff] [blame] | 801 | int dib0700_rc_setup(struct dvb_usb_device *d, struct usb_interface *intf) |
Janne Grunau | 89f4267 | 2007-07-31 19:45:13 -0300 | [diff] [blame] | 802 | { |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 803 | struct dib0700_state *st = d->priv; |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 804 | struct urb *purb; |
Mauro Carvalho Chehab | c4018fa | 2014-05-21 17:40:25 -0300 | [diff] [blame] | 805 | const struct usb_endpoint_descriptor *e; |
| 806 | int ret, rc_ep = 1; |
| 807 | unsigned int pipe = 0; |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 808 | |
Mauro Carvalho Chehab | 0ffd1ab | 2010-08-01 09:37:23 -0300 | [diff] [blame] | 809 | /* Poll-based. Don't initialize bulk mode */ |
Mauro Carvalho Chehab | c4018fa | 2014-05-21 17:40:25 -0300 | [diff] [blame] | 810 | if (st->fw_version < 0x10200 || !intf) |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 811 | return 0; |
| 812 | |
| 813 | /* Starting in firmware 1.20, the RC info is provided on a bulk pipe */ |
Mauro Carvalho Chehab | c4018fa | 2014-05-21 17:40:25 -0300 | [diff] [blame] | 814 | |
Johan Hovold | a1ba881 | 2020-01-03 17:35:12 +0100 | [diff] [blame] | 815 | if (intf->cur_altsetting->desc.bNumEndpoints < rc_ep + 1) |
Johan Hovold | 466b45a | 2017-03-13 09:53:54 -0300 | [diff] [blame] | 816 | return -ENODEV; |
| 817 | |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 818 | purb = usb_alloc_urb(0, GFP_KERNEL); |
Wolfram Sang | abbde78 | 2016-08-11 18:03:48 -0300 | [diff] [blame] | 819 | if (purb == NULL) |
Daniel Mack | 8871c85 | 2010-07-01 01:08:58 -0300 | [diff] [blame] | 820 | return -ENOMEM; |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 821 | |
| 822 | purb->transfer_buffer = kzalloc(RC_MSG_SIZE_V1_20, GFP_KERNEL); |
| 823 | if (purb->transfer_buffer == NULL) { |
Jiri Slaby | 24ed693 | 2012-07-30 14:03:16 -0300 | [diff] [blame] | 824 | err("rc kzalloc failed"); |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 825 | usb_free_urb(purb); |
Daniel Mack | 8871c85 | 2010-07-01 01:08:58 -0300 | [diff] [blame] | 826 | return -ENOMEM; |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | purb->status = -EINPROGRESS; |
Mauro Carvalho Chehab | c4018fa | 2014-05-21 17:40:25 -0300 | [diff] [blame] | 830 | |
| 831 | /* |
| 832 | * Some devices like the Hauppauge NovaTD model 52009 use an interrupt |
| 833 | * endpoint, while others use a bulk one. |
| 834 | */ |
Johan Hovold | a1ba881 | 2020-01-03 17:35:12 +0100 | [diff] [blame] | 835 | e = &intf->cur_altsetting->endpoint[rc_ep].desc; |
Mauro Carvalho Chehab | c4018fa | 2014-05-21 17:40:25 -0300 | [diff] [blame] | 836 | if (usb_endpoint_dir_in(e)) { |
| 837 | if (usb_endpoint_xfer_bulk(e)) { |
| 838 | pipe = usb_rcvbulkpipe(d->udev, rc_ep); |
| 839 | usb_fill_bulk_urb(purb, d->udev, pipe, |
| 840 | purb->transfer_buffer, |
| 841 | RC_MSG_SIZE_V1_20, |
| 842 | dib0700_rc_urb_completion, d); |
| 843 | |
| 844 | } else if (usb_endpoint_xfer_int(e)) { |
| 845 | pipe = usb_rcvintpipe(d->udev, rc_ep); |
| 846 | usb_fill_int_urb(purb, d->udev, pipe, |
| 847 | purb->transfer_buffer, |
| 848 | RC_MSG_SIZE_V1_20, |
| 849 | dib0700_rc_urb_completion, d, 1); |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | if (!pipe) { |
| 854 | err("There's no endpoint for remote controller"); |
| 855 | kfree(purb->transfer_buffer); |
| 856 | usb_free_urb(purb); |
| 857 | return 0; |
| 858 | } |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 859 | |
| 860 | ret = usb_submit_urb(purb, GFP_ATOMIC); |
Jean Delvare | d3db22e | 2012-03-13 13:52:50 -0300 | [diff] [blame] | 861 | if (ret) { |
Jiri Slaby | 24ed693 | 2012-07-30 14:03:16 -0300 | [diff] [blame] | 862 | err("rc submit urb failed"); |
Jean Delvare | d3db22e | 2012-03-13 13:52:50 -0300 | [diff] [blame] | 863 | kfree(purb->transfer_buffer); |
| 864 | usb_free_urb(purb); |
| 865 | } |
Devin Heitmueller | 6a20710 | 2010-01-04 02:43:19 -0300 | [diff] [blame] | 866 | |
Daniel Mack | 8871c85 | 2010-07-01 01:08:58 -0300 | [diff] [blame] | 867 | return ret; |
Janne Grunau | 89f4267 | 2007-07-31 19:45:13 -0300 | [diff] [blame] | 868 | } |
| 869 | |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 870 | static int dib0700_probe(struct usb_interface *intf, |
| 871 | const struct usb_device_id *id) |
| 872 | { |
| 873 | int i; |
Janne Grunau | 89f4267 | 2007-07-31 19:45:13 -0300 | [diff] [blame] | 874 | struct dvb_usb_device *dev; |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 875 | |
| 876 | for (i = 0; i < dib0700_device_count; i++) |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 877 | if (dvb_usb_device_init(intf, &dib0700_devices[i], THIS_MODULE, |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 878 | &dev, adapter_nr) == 0) { |
| 879 | struct dib0700_state *st = dev->priv; |
| 880 | u32 hwversion, romversion, fw_version, fwtype; |
| 881 | |
| 882 | dib0700_get_version(dev, &hwversion, &romversion, |
| 883 | &fw_version, &fwtype); |
| 884 | |
| 885 | deb_info("Firmware version: %x, %d, 0x%x, %d\n", |
| 886 | hwversion, romversion, fw_version, fwtype); |
| 887 | |
| 888 | st->fw_version = fw_version; |
| 889 | st->nb_packet_buffer_size = (u32)nb_packet_buffer_size; |
| 890 | |
Mauro Carvalho Chehab | 72b3931 | 2010-07-31 22:56:00 -0300 | [diff] [blame] | 891 | /* Disable polling mode on newer firmwares */ |
| 892 | if (st->fw_version >= 0x10200) |
| 893 | dev->props.rc.core.bulk_mode = true; |
| 894 | else |
| 895 | dev->props.rc.core.bulk_mode = false; |
| 896 | |
Mauro Carvalho Chehab | c4018fa | 2014-05-21 17:40:25 -0300 | [diff] [blame] | 897 | dib0700_rc_setup(dev, intf); |
Olivier Grenie | acc5c9e | 2009-12-07 08:22:53 -0300 | [diff] [blame] | 898 | |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 899 | return 0; |
Janne Grunau | 89f4267 | 2007-07-31 19:45:13 -0300 | [diff] [blame] | 900 | } |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 901 | |
| 902 | return -ENODEV; |
| 903 | } |
| 904 | |
| 905 | static struct usb_driver dib0700_driver = { |
| 906 | .name = "dvb_usb_dib0700", |
| 907 | .probe = dib0700_probe, |
| 908 | .disconnect = dvb_usb_device_exit, |
| 909 | .id_table = dib0700_usb_id_table, |
| 910 | }; |
| 911 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 912 | module_usb_driver(dib0700_driver); |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 913 | |
Patrick Boettcher | 68dc8bc | 2012-01-17 08:41:20 -0300 | [diff] [blame] | 914 | MODULE_FIRMWARE("dvb-usb-dib0700-1.20.fw"); |
Patrick Boettcher | 99e44da | 2016-01-24 12:56:58 -0200 | [diff] [blame] | 915 | MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>"); |
Patrick Boettcher | b7f5491 | 2006-09-19 12:51:37 -0300 | [diff] [blame] | 916 | MODULE_DESCRIPTION("Driver for devices based on DiBcom DiB0700 - USB bridge"); |
| 917 | MODULE_VERSION("1.0"); |
| 918 | MODULE_LICENSE("GPL"); |