Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1 | /* DVB USB compliant linux driver for |
| 2 | * |
| 3 | * DM04/QQBOX DVB-S USB BOX LME2510C + SHARP:BS2F7HZ7395 |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 4 | * LME2510C + LG TDQY-P001F |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 5 | * LME2510C + BS2F7HZ0194 |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 6 | * LME2510 + LG TDQY-P001F |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 7 | * LME2510 + BS2F7HZ0194 |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 8 | * |
| 9 | * MVB7395 (LME2510C+SHARP:BS2F7HZ7395) |
| 10 | * SHARP:BS2F7HZ7395 = (STV0288+Sharp IX2505V) |
| 11 | * |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 12 | * MV001F (LME2510+LGTDQY-P001F) |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 13 | * LG TDQY - P001F =(TDA8263 + TDA10086H) |
| 14 | * |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 15 | * MVB0001F (LME2510C+LGTDQT-P001F) |
| 16 | * |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 17 | * MV0194 (LME2510+SHARP:BS2F7HZ0194) |
| 18 | * SHARP:BS2F7HZ0194 = (STV0299+IX2410) |
| 19 | * |
| 20 | * MVB0194 (LME2510C+SHARP0194) |
| 21 | * |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 22 | * For firmware see Documentation/dvb/lmedm04.txt |
| 23 | * |
| 24 | * I2C addresses: |
| 25 | * 0xd0 - STV0288 - Demodulator |
| 26 | * 0xc0 - Sharp IX2505V - Tuner |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 27 | * -- |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 28 | * 0x1c - TDA10086 - Demodulator |
| 29 | * 0xc0 - TDA8263 - Tuner |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 30 | * -- |
| 31 | * 0xd0 - STV0299 - Demodulator |
| 32 | * 0xc0 - IX2410 - Tuner |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 33 | * |
| 34 | * |
| 35 | * VID = 3344 PID LME2510=1122 LME2510C=1120 |
| 36 | * |
| 37 | * Copyright (C) 2010 Malcolm Priestley (tvboxspy@gmail.com) |
| 38 | * LME2510(C)(C) Leaguerme (Shenzhen) MicroElectronics Co., Ltd. |
| 39 | * |
| 40 | * This program is free software; you can redistribute it and/or modify |
| 41 | * it under the terms of the GNU General Public License Version 2, as |
| 42 | * published by the Free Software Foundation. |
| 43 | * |
| 44 | * This program is distributed in the hope that it will be useful, |
| 45 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 46 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 47 | * GNU General Public License for more details. |
| 48 | * |
| 49 | * You should have received a copy of the GNU General Public License |
| 50 | * along with this program; if not, write to the Free Software |
| 51 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 52 | * |
| 53 | * |
| 54 | * see Documentation/dvb/README.dvb-usb for more information |
| 55 | * |
| 56 | * Known Issues : |
| 57 | * LME2510: Non Intel USB chipsets fail to maintain High Speed on |
| 58 | * Boot or Hot Plug. |
| 59 | * |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 60 | * QQbox suffers from noise on LNB voltage. |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 61 | * |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 62 | * LME2510: SHARP:BS2F7HZ0194(MV0194) cannot cold reset and share system |
| 63 | * with other tuners. After a cold reset streaming will not start. |
| 64 | * |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 65 | * PID functions have been removed from this driver version due to |
| 66 | * problems with different firmware and application versions. |
| 67 | */ |
| 68 | #define DVB_USB_LOG_PREFIX "LME2510(C)" |
| 69 | #include <linux/usb.h> |
| 70 | #include <linux/usb/input.h> |
Mauro Carvalho Chehab | 6bda964 | 2010-11-17 13:28:38 -0300 | [diff] [blame] | 71 | #include <media/rc-core.h> |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 72 | |
| 73 | #include "dvb-usb.h" |
| 74 | #include "lmedm04.h" |
| 75 | #include "tda826x.h" |
| 76 | #include "tda10086.h" |
| 77 | #include "stv0288.h" |
| 78 | #include "ix2505v.h" |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 79 | #include "stv0299.h" |
| 80 | #include "dvb-pll.h" |
| 81 | #include "z0194a.h" |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 82 | |
| 83 | |
| 84 | |
| 85 | /* debug */ |
| 86 | static int dvb_usb_lme2510_debug; |
| 87 | #define l_dprintk(var, level, args...) do { \ |
| 88 | if ((var >= level)) \ |
| 89 | printk(KERN_DEBUG DVB_USB_LOG_PREFIX ": " args); \ |
| 90 | } while (0) |
| 91 | |
| 92 | #define deb_info(level, args...) l_dprintk(dvb_usb_lme2510_debug, level, args) |
| 93 | #define debug_data_snipet(level, name, p) \ |
| 94 | deb_info(level, name" (%02x%02x%02x%02x%02x%02x%02x%02x)", \ |
| 95 | *p, *(p+1), *(p+2), *(p+3), *(p+4), \ |
| 96 | *(p+5), *(p+6), *(p+7)); |
| 97 | |
| 98 | |
| 99 | module_param_named(debug, dvb_usb_lme2510_debug, int, 0644); |
| 100 | MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." |
| 101 | DVB_USB_DEBUG_STATUS); |
| 102 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 103 | static int dvb_usb_lme2510_firmware; |
| 104 | module_param_named(firmware, dvb_usb_lme2510_firmware, int, 0644); |
| 105 | MODULE_PARM_DESC(firmware, "set default firmware 0=Sharp7395 1=LG"); |
| 106 | |
| 107 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 108 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 109 | |
| 110 | #define TUNER_DEFAULT 0x0 |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 111 | #define TUNER_LG 0x1 |
| 112 | #define TUNER_S7395 0x2 |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 113 | #define TUNER_S0194 0x3 |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 114 | |
| 115 | struct lme2510_state { |
| 116 | u8 id; |
| 117 | u8 tuner_config; |
| 118 | u8 signal_lock; |
| 119 | u8 signal_level; |
| 120 | u8 signal_sn; |
| 121 | u8 time_key; |
| 122 | u8 i2c_talk_onoff; |
| 123 | u8 i2c_gate; |
| 124 | u8 i2c_tuner_gate_w; |
| 125 | u8 i2c_tuner_gate_r; |
| 126 | u8 i2c_tuner_addr; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 127 | u8 stream_on; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 128 | void *buffer; |
| 129 | struct urb *lme_urb; |
| 130 | void *usb_buffer; |
| 131 | |
| 132 | }; |
| 133 | |
| 134 | static int lme2510_bulk_write(struct usb_device *dev, |
| 135 | u8 *snd, int len, u8 pipe) |
| 136 | { |
| 137 | int ret, actual_l; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 138 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 139 | ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe), |
Malcolm Priestley | 25ad984 | 2010-11-04 17:17:51 -0300 | [diff] [blame] | 140 | snd, len , &actual_l, 100); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 141 | return ret; |
| 142 | } |
| 143 | |
| 144 | static int lme2510_bulk_read(struct usb_device *dev, |
| 145 | u8 *rev, int len, u8 pipe) |
| 146 | { |
| 147 | int ret, actual_l; |
| 148 | |
| 149 | ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe), |
Malcolm Priestley | 25ad984 | 2010-11-04 17:17:51 -0300 | [diff] [blame] | 150 | rev, len , &actual_l, 200); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 151 | return ret; |
| 152 | } |
| 153 | |
| 154 | static int lme2510_usb_talk(struct dvb_usb_device *d, |
| 155 | u8 *wbuf, int wlen, u8 *rbuf, int rlen) |
| 156 | { |
| 157 | struct lme2510_state *st = d->priv; |
| 158 | u8 *buff; |
| 159 | int ret = 0; |
| 160 | |
| 161 | if (st->usb_buffer == NULL) { |
| 162 | st->usb_buffer = kmalloc(512, GFP_KERNEL); |
| 163 | if (st->usb_buffer == NULL) { |
| 164 | info("MEM Error no memory"); |
| 165 | return -ENOMEM; |
| 166 | } |
| 167 | } |
| 168 | buff = st->usb_buffer; |
| 169 | |
| 170 | /* the read/write capped at 512 */ |
| 171 | memcpy(buff, wbuf, (wlen > 512) ? 512 : wlen); |
| 172 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 173 | ret = mutex_lock_interruptible(&d->usb_mutex); |
| 174 | |
| 175 | if (ret < 0) |
| 176 | return -EAGAIN; |
| 177 | |
| 178 | ret |= usb_clear_halt(d->udev, usb_sndbulkpipe(d->udev, 0x01)); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 179 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 180 | ret |= lme2510_bulk_write(d->udev, buff, wlen , 0x01); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 181 | |
Malcolm Priestley | 25ad984 | 2010-11-04 17:17:51 -0300 | [diff] [blame] | 182 | msleep(10); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 183 | |
| 184 | ret |= usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x01)); |
| 185 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 186 | ret |= lme2510_bulk_read(d->udev, buff, (rlen > 512) ? |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 187 | 512 : rlen , 0x01); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 188 | |
| 189 | if (rlen > 0) |
| 190 | memcpy(rbuf, buff, rlen); |
| 191 | |
| 192 | mutex_unlock(&d->usb_mutex); |
| 193 | |
| 194 | return (ret < 0) ? -ENODEV : 0; |
| 195 | } |
| 196 | |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 197 | static int lme2510_stream_restart(struct dvb_usb_device *d) |
| 198 | { |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 199 | static u8 stream_on[] = LME_ST_ON_W; |
| 200 | int ret; |
| 201 | u8 rbuff[10]; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 202 | /*Restart Stream Command*/ |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 203 | ret = lme2510_usb_talk(d, stream_on, sizeof(stream_on), |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 204 | rbuff, sizeof(rbuff)); |
| 205 | return ret; |
| 206 | } |
Malcolm Priestley | f8931f5 | 2011-01-23 18:22:45 -0300 | [diff] [blame] | 207 | static int lme2510_remote_keypress(struct dvb_usb_adapter *adap, u32 keypress) |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 208 | { |
| 209 | struct dvb_usb_device *d = adap->dev; |
| 210 | |
| 211 | deb_info(1, "INT Key Keypress =%04x", keypress); |
| 212 | |
| 213 | if (keypress > 0) |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 214 | rc_keydown(d->rc_dev, keypress, 0); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static void lme2510_int_response(struct urb *lme_urb) |
| 220 | { |
| 221 | struct dvb_usb_adapter *adap = lme_urb->context; |
| 222 | struct lme2510_state *st = adap->dev->priv; |
| 223 | static u8 *ibuf, *rbuf; |
| 224 | int i = 0, offset; |
| 225 | |
| 226 | switch (lme_urb->status) { |
| 227 | case 0: |
| 228 | case -ETIMEDOUT: |
| 229 | break; |
| 230 | case -ECONNRESET: |
| 231 | case -ENOENT: |
| 232 | case -ESHUTDOWN: |
| 233 | return; |
| 234 | default: |
| 235 | info("Error %x", lme_urb->status); |
| 236 | break; |
| 237 | } |
| 238 | |
| 239 | rbuf = (u8 *) lme_urb->transfer_buffer; |
| 240 | |
| 241 | offset = ((lme_urb->actual_length/8) > 4) |
| 242 | ? 4 : (lme_urb->actual_length/8) ; |
| 243 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 244 | for (i = 0; i < offset; ++i) { |
| 245 | ibuf = (u8 *)&rbuf[i*8]; |
| 246 | deb_info(5, "INT O/S C =%02x C/O=%02x Type =%02x%02x", |
| 247 | offset, i, ibuf[0], ibuf[1]); |
| 248 | |
| 249 | switch (ibuf[0]) { |
| 250 | case 0xaa: |
| 251 | debug_data_snipet(1, "INT Remote data snipet in", ibuf); |
| 252 | lme2510_remote_keypress(adap, |
Malcolm Priestley | f8931f5 | 2011-01-23 18:22:45 -0300 | [diff] [blame] | 253 | (u32)(ibuf[2] << 24) + (ibuf[3] << 16) + |
| 254 | (ibuf[4] << 8) + ibuf[5]); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 255 | break; |
| 256 | case 0xbb: |
| 257 | switch (st->tuner_config) { |
| 258 | case TUNER_LG: |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 259 | if (ibuf[2] > 0) |
| 260 | st->signal_lock = ibuf[2]; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 261 | st->signal_level = ibuf[4]; |
| 262 | st->signal_sn = ibuf[3]; |
| 263 | st->time_key = ibuf[7]; |
| 264 | break; |
| 265 | case TUNER_S7395: |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 266 | case TUNER_S0194: |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 267 | /* Tweak for earlier firmware*/ |
| 268 | if (ibuf[1] == 0x03) { |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 269 | if (ibuf[2] > 1) |
| 270 | st->signal_lock = ibuf[2]; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 271 | st->signal_level = ibuf[3]; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 272 | st->signal_sn = ibuf[4]; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 273 | } else { |
| 274 | st->signal_level = ibuf[4]; |
| 275 | st->signal_sn = ibuf[5]; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 276 | st->signal_lock = |
| 277 | (st->signal_lock & 0xf7) + |
| 278 | ((ibuf[2] & 0x01) << 0x03); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 279 | } |
| 280 | break; |
| 281 | default: |
| 282 | break; |
| 283 | } |
| 284 | debug_data_snipet(5, "INT Remote data snipet in", ibuf); |
| 285 | break; |
| 286 | case 0xcc: |
| 287 | debug_data_snipet(1, "INT Control data snipet", ibuf); |
| 288 | break; |
| 289 | default: |
| 290 | debug_data_snipet(1, "INT Unknown data snipet", ibuf); |
| 291 | break; |
| 292 | } |
| 293 | } |
| 294 | usb_submit_urb(lme_urb, GFP_ATOMIC); |
| 295 | } |
| 296 | |
| 297 | static int lme2510_int_read(struct dvb_usb_adapter *adap) |
| 298 | { |
| 299 | struct lme2510_state *lme_int = adap->dev->priv; |
| 300 | |
| 301 | lme_int->lme_urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 302 | |
| 303 | if (lme_int->lme_urb == NULL) |
| 304 | return -ENOMEM; |
| 305 | |
| 306 | lme_int->buffer = usb_alloc_coherent(adap->dev->udev, 5000, GFP_ATOMIC, |
| 307 | &lme_int->lme_urb->transfer_dma); |
| 308 | |
| 309 | if (lme_int->buffer == NULL) |
| 310 | return -ENOMEM; |
| 311 | |
| 312 | usb_fill_int_urb(lme_int->lme_urb, |
| 313 | adap->dev->udev, |
| 314 | usb_rcvintpipe(adap->dev->udev, 0xa), |
| 315 | lme_int->buffer, |
| 316 | 4096, |
| 317 | lme2510_int_response, |
| 318 | adap, |
| 319 | 11); |
| 320 | |
| 321 | lme_int->lme_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 322 | |
| 323 | usb_submit_urb(lme_int->lme_urb, GFP_ATOMIC); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 324 | info("INT Interrupt Service Started"); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | static int lme2510_return_status(struct usb_device *dev) |
| 330 | { |
| 331 | int ret = 0; |
Florian Mickler | 945b876 | 2011-03-20 18:50:52 -0300 | [diff] [blame^] | 332 | u8 *data; |
| 333 | |
| 334 | data = kzalloc(10, GFP_KERNEL); |
| 335 | if (!data) |
| 336 | return -ENOMEM; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 337 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 338 | ret |= usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 339 | 0x06, 0x80, 0x0302, 0x00, data, 0x0006, 200); |
| 340 | info("Firmware Status: %x (%x)", ret , data[2]); |
| 341 | |
Florian Mickler | 945b876 | 2011-03-20 18:50:52 -0300 | [diff] [blame^] | 342 | ret = (ret < 0) ? -ENODEV : data[2]; |
| 343 | kfree(data); |
| 344 | return ret; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static int lme2510_msg(struct dvb_usb_device *d, |
| 348 | u8 *wbuf, int wlen, u8 *rbuf, int rlen) |
| 349 | { |
| 350 | int ret = 0; |
| 351 | struct lme2510_state *st = d->priv; |
| 352 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 353 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 354 | return -EAGAIN; |
| 355 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 356 | if (st->i2c_talk_onoff == 1) { |
| 357 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 358 | ret = lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); |
| 359 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 360 | switch (st->tuner_config) { |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 361 | case TUNER_LG: |
| 362 | if (wbuf[2] == 0x1c) { |
| 363 | if (wbuf[3] == 0x0e) { |
| 364 | st->signal_lock = rbuf[1]; |
| 365 | if ((st->stream_on & 1) && |
| 366 | (st->signal_lock & 0x10)) { |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 367 | lme2510_stream_restart(d); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 368 | st->i2c_talk_onoff = 0; |
| 369 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 370 | msleep(80); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | break; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 374 | case TUNER_S7395: |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 375 | if (wbuf[2] == 0xd0) { |
| 376 | if (wbuf[3] == 0x24) { |
| 377 | st->signal_lock = rbuf[1]; |
| 378 | if ((st->stream_on & 1) && |
| 379 | (st->signal_lock & 0x8)) { |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 380 | lme2510_stream_restart(d); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 381 | st->i2c_talk_onoff = 0; |
| 382 | } |
| 383 | } |
| 384 | if ((wbuf[3] != 0x6) & (wbuf[3] != 0x5)) |
| 385 | msleep(5); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 386 | } |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 387 | break; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 388 | case TUNER_S0194: |
| 389 | if (wbuf[2] == 0xd0) { |
| 390 | if (wbuf[3] == 0x1b) { |
| 391 | st->signal_lock = rbuf[1]; |
| 392 | if ((st->stream_on & 1) && |
| 393 | (st->signal_lock & 0x8)) { |
| 394 | lme2510_stream_restart(d); |
| 395 | st->i2c_talk_onoff = 0; |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | break; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 400 | default: |
| 401 | break; |
| 402 | } |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 403 | } else { |
| 404 | switch (st->tuner_config) { |
| 405 | case TUNER_LG: |
| 406 | switch (wbuf[3]) { |
| 407 | case 0x0e: |
| 408 | rbuf[0] = 0x55; |
| 409 | rbuf[1] = st->signal_lock; |
| 410 | break; |
| 411 | case 0x43: |
| 412 | rbuf[0] = 0x55; |
| 413 | rbuf[1] = st->signal_level; |
| 414 | break; |
| 415 | case 0x1c: |
| 416 | rbuf[0] = 0x55; |
| 417 | rbuf[1] = st->signal_sn; |
| 418 | break; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 419 | case 0x15: |
| 420 | case 0x16: |
| 421 | case 0x17: |
| 422 | case 0x18: |
| 423 | rbuf[0] = 0x55; |
| 424 | rbuf[1] = 0x00; |
| 425 | break; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 426 | default: |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 427 | lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); |
| 428 | st->i2c_talk_onoff = 1; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 429 | break; |
| 430 | } |
| 431 | break; |
| 432 | case TUNER_S7395: |
| 433 | switch (wbuf[3]) { |
| 434 | case 0x10: |
| 435 | rbuf[0] = 0x55; |
| 436 | rbuf[1] = (st->signal_level & 0x80) |
| 437 | ? 0 : (st->signal_level * 2); |
| 438 | break; |
| 439 | case 0x2d: |
| 440 | rbuf[0] = 0x55; |
| 441 | rbuf[1] = st->signal_sn; |
| 442 | break; |
| 443 | case 0x24: |
| 444 | rbuf[0] = 0x55; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 445 | rbuf[1] = st->signal_lock; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 446 | break; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 447 | case 0x2e: |
| 448 | case 0x26: |
| 449 | case 0x27: |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 450 | rbuf[0] = 0x55; |
| 451 | rbuf[1] = 0x00; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 452 | break; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 453 | default: |
| 454 | lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); |
| 455 | st->i2c_talk_onoff = 1; |
| 456 | break; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 457 | } |
| 458 | break; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 459 | case TUNER_S0194: |
| 460 | switch (wbuf[3]) { |
| 461 | case 0x18: |
| 462 | rbuf[0] = 0x55; |
| 463 | rbuf[1] = (st->signal_level & 0x80) |
| 464 | ? 0 : (st->signal_level * 2); |
| 465 | break; |
| 466 | case 0x24: |
| 467 | rbuf[0] = 0x55; |
| 468 | rbuf[1] = st->signal_sn; |
| 469 | break; |
| 470 | case 0x1b: |
| 471 | rbuf[0] = 0x55; |
| 472 | rbuf[1] = st->signal_lock; |
| 473 | break; |
| 474 | case 0x19: |
| 475 | case 0x25: |
| 476 | case 0x1e: |
| 477 | case 0x1d: |
| 478 | rbuf[0] = 0x55; |
| 479 | rbuf[1] = 0x00; |
| 480 | break; |
| 481 | default: |
| 482 | lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); |
| 483 | st->i2c_talk_onoff = 1; |
| 484 | break; |
| 485 | } |
| 486 | break; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 487 | default: |
| 488 | break; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 489 | } |
| 490 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 491 | deb_info(4, "I2C From Interrupt Message out(%02x) in(%02x)", |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 492 | wbuf[3], rbuf[1]); |
| 493 | |
| 494 | } |
| 495 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 496 | mutex_unlock(&d->i2c_mutex); |
| 497 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 498 | return ret; |
| 499 | } |
| 500 | |
| 501 | |
| 502 | static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
| 503 | int num) |
| 504 | { |
| 505 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 506 | struct lme2510_state *st = d->priv; |
| 507 | static u8 obuf[64], ibuf[512]; |
| 508 | int i, read, read_o; |
| 509 | u16 len; |
| 510 | u8 gate = st->i2c_gate; |
| 511 | |
| 512 | if (gate == 0) |
| 513 | gate = 5; |
| 514 | |
| 515 | if (num > 2) |
| 516 | warn("more than 2 i2c messages" |
| 517 | "at a time is not handled yet. TODO."); |
| 518 | |
| 519 | for (i = 0; i < num; i++) { |
| 520 | read_o = 1 & (msg[i].flags & I2C_M_RD); |
| 521 | read = i+1 < num && (msg[i+1].flags & I2C_M_RD); |
| 522 | read |= read_o; |
| 523 | gate = (msg[i].addr == st->i2c_tuner_addr) |
| 524 | ? (read) ? st->i2c_tuner_gate_r |
| 525 | : st->i2c_tuner_gate_w |
| 526 | : st->i2c_gate; |
| 527 | obuf[0] = gate | (read << 7); |
| 528 | |
| 529 | if (gate == 5) |
| 530 | obuf[1] = (read) ? 2 : msg[i].len + 1; |
| 531 | else |
| 532 | obuf[1] = msg[i].len + read + 1; |
| 533 | |
| 534 | obuf[2] = msg[i].addr; |
| 535 | if (read) { |
| 536 | if (read_o) |
| 537 | len = 3; |
| 538 | else { |
| 539 | memcpy(&obuf[3], msg[i].buf, msg[i].len); |
| 540 | obuf[msg[i].len+3] = msg[i+1].len; |
| 541 | len = msg[i].len+4; |
| 542 | } |
| 543 | } else { |
| 544 | memcpy(&obuf[3], msg[i].buf, msg[i].len); |
| 545 | len = msg[i].len+3; |
| 546 | } |
| 547 | |
| 548 | if (lme2510_msg(d, obuf, len, ibuf, 512) < 0) { |
| 549 | deb_info(1, "i2c transfer failed."); |
| 550 | return -EAGAIN; |
| 551 | } |
| 552 | |
| 553 | if (read) { |
| 554 | if (read_o) |
| 555 | memcpy(msg[i].buf, &ibuf[1], msg[i].len); |
| 556 | else { |
| 557 | memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len); |
| 558 | i++; |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | return i; |
| 563 | } |
| 564 | |
| 565 | static u32 lme2510_i2c_func(struct i2c_adapter *adapter) |
| 566 | { |
| 567 | return I2C_FUNC_I2C; |
| 568 | } |
| 569 | |
| 570 | static struct i2c_algorithm lme2510_i2c_algo = { |
| 571 | .master_xfer = lme2510_i2c_xfer, |
| 572 | .functionality = lme2510_i2c_func, |
| 573 | }; |
| 574 | |
| 575 | /* Callbacks for DVB USB */ |
| 576 | static int lme2510_identify_state(struct usb_device *udev, |
| 577 | struct dvb_usb_device_properties *props, |
| 578 | struct dvb_usb_device_description **desc, |
| 579 | int *cold) |
| 580 | { |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 581 | *cold = 0; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | static int lme2510_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) |
| 586 | { |
| 587 | struct lme2510_state *st = adap->dev->priv; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 588 | static u8 clear_reg_3[] = LME_CLEAR_PID; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 589 | static u8 rbuf[1]; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 590 | int ret = 0, rlen = sizeof(rbuf); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 591 | |
| 592 | deb_info(1, "STM (%02x)", onoff); |
| 593 | |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 594 | /* Streaming is started by FE_HAS_LOCK */ |
| 595 | if (onoff == 1) |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 596 | st->stream_on = 1; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 597 | else { |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 598 | deb_info(1, "STM Steam Off"); |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 599 | /* mutex is here only to avoid collision with I2C */ |
| 600 | ret = mutex_lock_interruptible(&adap->dev->i2c_mutex); |
| 601 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 602 | ret |= lme2510_usb_talk(adap->dev, clear_reg_3, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 603 | sizeof(clear_reg_3), rbuf, rlen); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 604 | st->stream_on = 0; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 605 | st->i2c_talk_onoff = 1; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 606 | |
| 607 | mutex_unlock(&adap->dev->i2c_mutex); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | return (ret < 0) ? -ENODEV : 0; |
| 611 | } |
| 612 | |
| 613 | static int lme2510_int_service(struct dvb_usb_adapter *adap) |
| 614 | { |
| 615 | struct dvb_usb_device *d = adap->dev; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 616 | struct rc_dev *rc; |
| 617 | int ret; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 618 | |
| 619 | info("STA Configuring Remote"); |
| 620 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 621 | rc = rc_allocate_device(); |
| 622 | if (!rc) |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 623 | return -ENOMEM; |
| 624 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 625 | usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys)); |
| 626 | strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys)); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 627 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 628 | rc->input_name = "LME2510 Remote Control"; |
| 629 | rc->input_phys = d->rc_phys; |
| 630 | rc->map_name = RC_MAP_LME2510; |
| 631 | rc->driver_name = "LME 2510"; |
| 632 | usb_to_input_id(d->udev, &rc->input_id); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 633 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 634 | ret = rc_register_device(rc); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 635 | if (ret) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 636 | rc_free_device(rc); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 637 | return ret; |
| 638 | } |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 639 | d->rc_dev = rc; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 640 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 641 | /* Start the Interrupt */ |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 642 | ret = lme2510_int_read(adap); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 643 | if (ret < 0) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 644 | rc_unregister_device(rc); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 645 | info("INT Unable to start Interrupt Service"); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 646 | return -ENODEV; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 647 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 648 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 649 | return 0; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | static u8 check_sum(u8 *p, u8 len) |
| 653 | { |
| 654 | u8 sum = 0; |
| 655 | while (len--) |
| 656 | sum += *p++; |
| 657 | return sum; |
| 658 | } |
| 659 | |
| 660 | static int lme2510_download_firmware(struct usb_device *dev, |
| 661 | const struct firmware *fw) |
| 662 | { |
| 663 | int ret = 0; |
Florian Mickler | 945b876 | 2011-03-20 18:50:52 -0300 | [diff] [blame^] | 664 | u8 *data; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 665 | u16 j, wlen, len_in, start, end; |
| 666 | u8 packet_size, dlen, i; |
| 667 | u8 *fw_data; |
| 668 | |
| 669 | packet_size = 0x31; |
| 670 | len_in = 1; |
| 671 | |
Florian Mickler | 945b876 | 2011-03-20 18:50:52 -0300 | [diff] [blame^] | 672 | data = kzalloc(512, GFP_KERNEL); |
| 673 | if (!data) { |
| 674 | info("FRM Could not start Firmware Download (Buffer allocation failed)"); |
| 675 | return -ENOMEM; |
| 676 | } |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 677 | |
| 678 | info("FRM Starting Firmware Download"); |
| 679 | |
| 680 | for (i = 1; i < 3; i++) { |
| 681 | start = (i == 1) ? 0 : 512; |
| 682 | end = (i == 1) ? 512 : fw->size; |
| 683 | for (j = start; j < end; j += (packet_size+1)) { |
| 684 | fw_data = (u8 *)(fw->data + j); |
| 685 | if ((end - j) > packet_size) { |
| 686 | data[0] = i; |
| 687 | dlen = packet_size; |
| 688 | } else { |
| 689 | data[0] = i | 0x80; |
| 690 | dlen = (u8)(end - j)-1; |
| 691 | } |
Florian Mickler | b9f7b73 | 2011-03-20 18:50:51 -0300 | [diff] [blame] | 692 | data[1] = dlen; |
| 693 | memcpy(&data[2], fw_data, dlen+1); |
| 694 | wlen = (u8) dlen + 4; |
| 695 | data[wlen-1] = check_sum(fw_data, dlen+1); |
| 696 | deb_info(1, "Data S=%02x:E=%02x CS= %02x", data[3], |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 697 | data[dlen+2], data[dlen+3]); |
Florian Mickler | b9f7b73 | 2011-03-20 18:50:51 -0300 | [diff] [blame] | 698 | ret |= lme2510_bulk_write(dev, data, wlen, 1); |
| 699 | ret |= lme2510_bulk_read(dev, data, len_in , 1); |
| 700 | ret |= (data[0] == 0x88) ? 0 : -1; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 701 | } |
| 702 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 703 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 704 | usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 705 | 0x06, 0x80, 0x0200, 0x00, data, 0x0109, 1000); |
| 706 | |
| 707 | |
| 708 | data[0] = 0x8a; |
| 709 | len_in = 1; |
| 710 | msleep(2000); |
| 711 | ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Resetting*/ |
| 712 | ret |= lme2510_bulk_read(dev, data, len_in, 1); |
| 713 | msleep(400); |
| 714 | |
| 715 | if (ret < 0) |
| 716 | info("FRM Firmware Download Failed (%04x)" , ret); |
| 717 | else |
| 718 | info("FRM Firmware Download Completed - Resetting Device"); |
| 719 | |
Florian Mickler | 945b876 | 2011-03-20 18:50:52 -0300 | [diff] [blame^] | 720 | kfree(data); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 721 | return (ret < 0) ? -ENODEV : 0; |
| 722 | } |
| 723 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 724 | static void lme_coldreset(struct usb_device *dev) |
| 725 | { |
| 726 | int ret = 0, len_in; |
| 727 | u8 data[512] = {0}; |
| 728 | |
| 729 | data[0] = 0x0a; |
| 730 | len_in = 1; |
| 731 | info("FRM Firmware Cold Reset"); |
| 732 | ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Cold Resetting*/ |
| 733 | ret |= lme2510_bulk_read(dev, data, len_in, 1); |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 734 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 735 | return; |
| 736 | } |
| 737 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 738 | static int lme_firmware_switch(struct usb_device *udev, int cold) |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 739 | { |
| 740 | const struct firmware *fw = NULL; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 741 | const char fw_c_s7395[] = "dvb-usb-lme2510c-s7395.fw"; |
| 742 | const char fw_c_lg[] = "dvb-usb-lme2510c-lg.fw"; |
| 743 | const char fw_c_s0194[] = "dvb-usb-lme2510c-s0194.fw"; |
| 744 | const char fw_lg[] = "dvb-usb-lme2510-lg.fw"; |
| 745 | const char fw_s0194[] = "dvb-usb-lme2510-s0194.fw"; |
| 746 | const char *fw_lme; |
| 747 | int ret, cold_fw; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 748 | |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 749 | cold = (cold > 0) ? (cold & 1) : 0; |
| 750 | |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 751 | cold_fw = !cold; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 752 | |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 753 | if (udev->descriptor.idProduct == 0x1122) { |
| 754 | switch (dvb_usb_lme2510_firmware) { |
| 755 | default: |
| 756 | dvb_usb_lme2510_firmware = TUNER_S0194; |
| 757 | case TUNER_S0194: |
| 758 | fw_lme = fw_s0194; |
| 759 | ret = request_firmware(&fw, fw_lme, &udev->dev); |
| 760 | if (ret == 0) { |
Malcolm Priestley | 30bd3b5 | 2011-02-13 20:12:15 -0300 | [diff] [blame] | 761 | cold = 0; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 762 | break; |
| 763 | } |
| 764 | dvb_usb_lme2510_firmware = TUNER_LG; |
| 765 | case TUNER_LG: |
| 766 | fw_lme = fw_lg; |
| 767 | ret = request_firmware(&fw, fw_lme, &udev->dev); |
| 768 | if (ret == 0) |
| 769 | break; |
| 770 | info("FRM No Firmware Found - please install"); |
| 771 | dvb_usb_lme2510_firmware = TUNER_DEFAULT; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 772 | cold = 0; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 773 | cold_fw = 0; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 774 | break; |
| 775 | } |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 776 | } else { |
| 777 | switch (dvb_usb_lme2510_firmware) { |
| 778 | default: |
| 779 | dvb_usb_lme2510_firmware = TUNER_S7395; |
| 780 | case TUNER_S7395: |
| 781 | fw_lme = fw_c_s7395; |
| 782 | ret = request_firmware(&fw, fw_lme, &udev->dev); |
Malcolm Priestley | 30bd3b5 | 2011-02-13 20:12:15 -0300 | [diff] [blame] | 783 | if (ret == 0) { |
| 784 | cold = 0; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 785 | break; |
Malcolm Priestley | 30bd3b5 | 2011-02-13 20:12:15 -0300 | [diff] [blame] | 786 | } |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 787 | dvb_usb_lme2510_firmware = TUNER_LG; |
| 788 | case TUNER_LG: |
| 789 | fw_lme = fw_c_lg; |
| 790 | ret = request_firmware(&fw, fw_lme, &udev->dev); |
| 791 | if (ret == 0) |
| 792 | break; |
| 793 | dvb_usb_lme2510_firmware = TUNER_S0194; |
| 794 | case TUNER_S0194: |
| 795 | fw_lme = fw_c_s0194; |
| 796 | ret = request_firmware(&fw, fw_lme, &udev->dev); |
| 797 | if (ret == 0) |
| 798 | break; |
| 799 | info("FRM No Firmware Found - please install"); |
| 800 | dvb_usb_lme2510_firmware = TUNER_DEFAULT; |
| 801 | cold = 0; |
| 802 | cold_fw = 0; |
| 803 | break; |
| 804 | } |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 805 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 806 | |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 807 | if (cold_fw) { |
| 808 | info("FRM Loading %s file", fw_lme); |
| 809 | ret = lme2510_download_firmware(udev, fw); |
| 810 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 811 | |
Malcolm Priestley | 30bd3b5 | 2011-02-13 20:12:15 -0300 | [diff] [blame] | 812 | release_firmware(fw); |
| 813 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 814 | if (cold) { |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 815 | info("FRM Changing to %s firmware", fw_lme); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 816 | lme_coldreset(udev); |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 817 | return -ENODEV; |
| 818 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 819 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 820 | return ret; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 821 | } |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 822 | |
| 823 | static int lme2510_kill_urb(struct usb_data_stream *stream) |
| 824 | { |
| 825 | int i; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 826 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 827 | for (i = 0; i < stream->urbs_submitted; i++) { |
| 828 | deb_info(3, "killing URB no. %d.", i); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 829 | /* stop the URB */ |
| 830 | usb_kill_urb(stream->urb_list[i]); |
| 831 | } |
| 832 | stream->urbs_submitted = 0; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 833 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 834 | return 0; |
| 835 | } |
| 836 | |
| 837 | static struct tda10086_config tda10086_config = { |
| 838 | .demod_address = 0x1c, |
| 839 | .invert = 0, |
| 840 | .diseqc_tone = 1, |
| 841 | .xtal_freq = TDA10086_XTAL_16M, |
| 842 | }; |
| 843 | |
| 844 | static struct stv0288_config lme_config = { |
| 845 | .demod_address = 0xd0, |
| 846 | .min_delay_ms = 15, |
| 847 | .inittab = s7395_inittab, |
| 848 | }; |
| 849 | |
| 850 | static struct ix2505v_config lme_tuner = { |
| 851 | .tuner_address = 0xc0, |
| 852 | .min_delay_ms = 100, |
| 853 | .tuner_gain = 0x0, |
| 854 | .tuner_chargepump = 0x3, |
| 855 | }; |
| 856 | |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 857 | static struct stv0299_config sharp_z0194_config = { |
| 858 | .demod_address = 0xd0, |
| 859 | .inittab = sharp_z0194a_inittab, |
| 860 | .mclk = 88000000UL, |
| 861 | .invert = 0, |
| 862 | .skip_reinit = 0, |
| 863 | .lock_output = STV0299_LOCKOUTPUT_1, |
| 864 | .volt13_op0_op1 = STV0299_VOLT13_OP1, |
| 865 | .min_delay_ms = 100, |
| 866 | .set_symbol_rate = sharp_z0194a_set_symbol_rate, |
| 867 | }; |
| 868 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 869 | static int dm04_lme2510_set_voltage(struct dvb_frontend *fe, |
| 870 | fe_sec_voltage_t voltage) |
| 871 | { |
| 872 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 873 | static u8 voltage_low[] = LME_VOLTAGE_L; |
| 874 | static u8 voltage_high[] = LME_VOLTAGE_H; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 875 | static u8 rbuf[1]; |
| 876 | int ret = 0, len = 3, rlen = 1; |
| 877 | |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 878 | if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0) |
| 879 | return -EAGAIN; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 880 | |
| 881 | switch (voltage) { |
| 882 | case SEC_VOLTAGE_18: |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 883 | ret |= lme2510_usb_talk(adap->dev, |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 884 | voltage_high, len, rbuf, rlen); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 885 | break; |
| 886 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 887 | case SEC_VOLTAGE_OFF: |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 888 | case SEC_VOLTAGE_13: |
| 889 | default: |
| 890 | ret |= lme2510_usb_talk(adap->dev, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 891 | voltage_low, len, rbuf, rlen); |
| 892 | break; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 893 | } |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 894 | |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 895 | mutex_unlock(&adap->dev->i2c_mutex); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 896 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 897 | return (ret < 0) ? -ENODEV : 0; |
| 898 | } |
| 899 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 900 | static int lme_name(struct dvb_usb_adapter *adap) |
| 901 | { |
| 902 | struct lme2510_state *st = adap->dev->priv; |
| 903 | const char *desc = adap->dev->desc->name; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 904 | char *fe_name[] = {"", " LG TDQY-P001F", " SHARP:BS2F7HZ7395", |
| 905 | " SHARP:BS2F7HZ0194"}; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 906 | char *name = adap->fe->ops.info.name; |
| 907 | |
| 908 | strlcpy(name, desc, 128); |
| 909 | strlcat(name, fe_name[st->tuner_config], 128); |
| 910 | |
| 911 | return 0; |
| 912 | } |
| 913 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 914 | static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap) |
| 915 | { |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 916 | struct lme2510_state *st = adap->dev->priv; |
| 917 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 918 | int ret = 0; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 919 | |
| 920 | st->i2c_talk_onoff = 1; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 921 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 922 | st->i2c_gate = 4; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 923 | adap->fe = dvb_attach(tda10086_attach, &tda10086_config, |
| 924 | &adap->dev->i2c_adap); |
| 925 | |
| 926 | if (adap->fe) { |
| 927 | info("TUN Found Frontend TDA10086"); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 928 | st->i2c_tuner_gate_w = 4; |
| 929 | st->i2c_tuner_gate_r = 4; |
| 930 | st->i2c_tuner_addr = 0xc0; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 931 | st->tuner_config = TUNER_LG; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 932 | if (dvb_usb_lme2510_firmware != TUNER_LG) { |
| 933 | dvb_usb_lme2510_firmware = TUNER_LG; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 934 | ret = lme_firmware_switch(adap->dev->udev, 1); |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 935 | } |
| 936 | goto end; |
| 937 | } |
| 938 | |
| 939 | st->i2c_gate = 4; |
| 940 | adap->fe = dvb_attach(stv0299_attach, &sharp_z0194_config, |
| 941 | &adap->dev->i2c_adap); |
| 942 | if (adap->fe) { |
| 943 | info("FE Found Stv0299"); |
| 944 | st->i2c_tuner_gate_w = 4; |
| 945 | st->i2c_tuner_gate_r = 5; |
| 946 | st->i2c_tuner_addr = 0xc0; |
| 947 | st->tuner_config = TUNER_S0194; |
| 948 | if (dvb_usb_lme2510_firmware != TUNER_S0194) { |
| 949 | dvb_usb_lme2510_firmware = TUNER_S0194; |
| 950 | ret = lme_firmware_switch(adap->dev->udev, 1); |
| 951 | } |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 952 | goto end; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 953 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 954 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 955 | st->i2c_gate = 5; |
| 956 | adap->fe = dvb_attach(stv0288_attach, &lme_config, |
| 957 | &adap->dev->i2c_adap); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 958 | if (adap->fe) { |
| 959 | info("FE Found Stv0288"); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 960 | st->i2c_tuner_gate_w = 4; |
| 961 | st->i2c_tuner_gate_r = 5; |
| 962 | st->i2c_tuner_addr = 0xc0; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 963 | st->tuner_config = TUNER_S7395; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 964 | if (dvb_usb_lme2510_firmware != TUNER_S7395) { |
| 965 | dvb_usb_lme2510_firmware = TUNER_S7395; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 966 | ret = lme_firmware_switch(adap->dev->udev, 1); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 967 | } |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 968 | } else { |
| 969 | info("DM04 Not Supported"); |
| 970 | return -ENODEV; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 971 | } |
| 972 | |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 973 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 974 | end: if (ret) { |
| 975 | kfree(adap->fe); |
| 976 | adap->fe = NULL; |
| 977 | return -ENODEV; |
| 978 | } |
| 979 | |
| 980 | adap->fe->ops.set_voltage = dm04_lme2510_set_voltage; |
| 981 | ret = lme_name(adap); |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 982 | return ret; |
| 983 | } |
| 984 | |
| 985 | static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap) |
| 986 | { |
| 987 | struct lme2510_state *st = adap->dev->priv; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 988 | char *tun_msg[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA"}; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 989 | int ret = 0; |
| 990 | |
| 991 | switch (st->tuner_config) { |
| 992 | case TUNER_LG: |
| 993 | if (dvb_attach(tda826x_attach, adap->fe, 0xc0, |
| 994 | &adap->dev->i2c_adap, 1)) |
| 995 | ret = st->tuner_config; |
| 996 | break; |
| 997 | case TUNER_S7395: |
| 998 | if (dvb_attach(ix2505v_attach , adap->fe, &lme_tuner, |
| 999 | &adap->dev->i2c_adap)) |
| 1000 | ret = st->tuner_config; |
| 1001 | break; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 1002 | case TUNER_S0194: |
| 1003 | if (dvb_attach(dvb_pll_attach , adap->fe, 0xc0, |
| 1004 | &adap->dev->i2c_adap, DVB_PLL_OPERA1)) |
| 1005 | ret = st->tuner_config; |
| 1006 | break; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1007 | default: |
| 1008 | break; |
| 1009 | } |
| 1010 | |
| 1011 | if (ret) |
| 1012 | info("TUN Found %s tuner", tun_msg[ret]); |
| 1013 | else { |
| 1014 | info("TUN No tuner found --- reseting device"); |
| 1015 | lme_coldreset(adap->dev->udev); |
| 1016 | return -ENODEV; |
| 1017 | } |
| 1018 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1019 | /* Start the Interrupt & Remote*/ |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1020 | ret = lme2510_int_service(adap); |
| 1021 | |
| 1022 | return ret; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | static int lme2510_powerup(struct dvb_usb_device *d, int onoff) |
| 1026 | { |
| 1027 | struct lme2510_state *st = d->priv; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 1028 | static u8 lnb_on[] = LNB_ON; |
| 1029 | static u8 lnb_off[] = LNB_OFF; |
| 1030 | static u8 rbuf[1]; |
| 1031 | int ret, len = 3, rlen = 1; |
| 1032 | |
| 1033 | ret = mutex_lock_interruptible(&d->i2c_mutex); |
| 1034 | |
| 1035 | if (onoff) |
| 1036 | ret |= lme2510_usb_talk(d, lnb_on, len, rbuf, rlen); |
| 1037 | else |
| 1038 | ret |= lme2510_usb_talk(d, lnb_off, len, rbuf, rlen); |
| 1039 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1040 | st->i2c_talk_onoff = 1; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 1041 | |
| 1042 | mutex_unlock(&d->i2c_mutex); |
| 1043 | |
| 1044 | return ret; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | /* DVB USB Driver stuff */ |
| 1048 | static struct dvb_usb_device_properties lme2510_properties; |
| 1049 | static struct dvb_usb_device_properties lme2510c_properties; |
| 1050 | |
| 1051 | static int lme2510_probe(struct usb_interface *intf, |
| 1052 | const struct usb_device_id *id) |
| 1053 | { |
| 1054 | struct usb_device *udev = interface_to_usbdev(intf); |
| 1055 | int ret = 0; |
| 1056 | |
| 1057 | usb_reset_configuration(udev); |
| 1058 | |
| 1059 | usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 1); |
| 1060 | |
| 1061 | if (udev->speed != USB_SPEED_HIGH) { |
| 1062 | ret = usb_reset_device(udev); |
| 1063 | info("DEV Failed to connect in HIGH SPEED mode"); |
| 1064 | return -ENODEV; |
| 1065 | } |
| 1066 | |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 1067 | if (lme2510_return_status(udev) == 0x44) { |
| 1068 | lme_firmware_switch(udev, 0); |
| 1069 | return -ENODEV; |
| 1070 | } |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1071 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1072 | if (0 == dvb_usb_device_init(intf, &lme2510_properties, |
| 1073 | THIS_MODULE, NULL, adapter_nr)) { |
| 1074 | info("DEV registering device driver"); |
| 1075 | return 0; |
| 1076 | } |
| 1077 | if (0 == dvb_usb_device_init(intf, &lme2510c_properties, |
| 1078 | THIS_MODULE, NULL, adapter_nr)) { |
| 1079 | info("DEV registering device driver"); |
| 1080 | return 0; |
| 1081 | } |
| 1082 | |
| 1083 | info("DEV lme2510 Error"); |
| 1084 | return -ENODEV; |
| 1085 | |
| 1086 | } |
| 1087 | |
| 1088 | static struct usb_device_id lme2510_table[] = { |
| 1089 | { USB_DEVICE(0x3344, 0x1122) }, /* LME2510 */ |
| 1090 | { USB_DEVICE(0x3344, 0x1120) }, /* LME2510C */ |
| 1091 | {} /* Terminating entry */ |
| 1092 | }; |
| 1093 | |
| 1094 | MODULE_DEVICE_TABLE(usb, lme2510_table); |
| 1095 | |
| 1096 | static struct dvb_usb_device_properties lme2510_properties = { |
| 1097 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1098 | .size_of_priv = sizeof(struct lme2510_state), |
| 1099 | .num_adapters = 1, |
| 1100 | .adapter = { |
| 1101 | { |
| 1102 | .streaming_ctrl = lme2510_streaming_ctrl, |
| 1103 | .frontend_attach = dm04_lme2510_frontend_attach, |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1104 | .tuner_attach = dm04_lme2510_tuner, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1105 | /* parameter for the MPEG2-data transfer */ |
| 1106 | .stream = { |
| 1107 | .type = USB_BULK, |
| 1108 | .count = 10, |
| 1109 | .endpoint = 0x06, |
| 1110 | .u = { |
| 1111 | .bulk = { |
| 1112 | .buffersize = 4096, |
| 1113 | |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | }, |
| 1119 | .power_ctrl = lme2510_powerup, |
| 1120 | .identify_state = lme2510_identify_state, |
| 1121 | .i2c_algo = &lme2510_i2c_algo, |
| 1122 | .generic_bulk_ctrl_endpoint = 0, |
| 1123 | .num_device_descs = 1, |
| 1124 | .devices = { |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1125 | { "DM04_LME2510_DVB-S", |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1126 | { &lme2510_table[0], NULL }, |
| 1127 | }, |
| 1128 | |
| 1129 | } |
| 1130 | }; |
| 1131 | |
| 1132 | static struct dvb_usb_device_properties lme2510c_properties = { |
| 1133 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1134 | .size_of_priv = sizeof(struct lme2510_state), |
| 1135 | .num_adapters = 1, |
| 1136 | .adapter = { |
| 1137 | { |
| 1138 | .streaming_ctrl = lme2510_streaming_ctrl, |
| 1139 | .frontend_attach = dm04_lme2510_frontend_attach, |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1140 | .tuner_attach = dm04_lme2510_tuner, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1141 | /* parameter for the MPEG2-data transfer */ |
| 1142 | .stream = { |
| 1143 | .type = USB_BULK, |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1144 | .count = 10, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1145 | .endpoint = 0x8, |
| 1146 | .u = { |
| 1147 | .bulk = { |
| 1148 | .buffersize = 4096, |
| 1149 | |
| 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | } |
| 1154 | }, |
| 1155 | .power_ctrl = lme2510_powerup, |
| 1156 | .identify_state = lme2510_identify_state, |
| 1157 | .i2c_algo = &lme2510_i2c_algo, |
| 1158 | .generic_bulk_ctrl_endpoint = 0, |
| 1159 | .num_device_descs = 1, |
| 1160 | .devices = { |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1161 | { "DM04_LME2510C_DVB-S", |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1162 | { &lme2510_table[1], NULL }, |
| 1163 | }, |
| 1164 | } |
| 1165 | }; |
| 1166 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1167 | void *lme2510_exit_int(struct dvb_usb_device *d) |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1168 | { |
| 1169 | struct lme2510_state *st = d->priv; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1170 | struct dvb_usb_adapter *adap = &d->adapter[0]; |
| 1171 | void *buffer = NULL; |
| 1172 | |
| 1173 | if (adap != NULL) { |
| 1174 | lme2510_kill_urb(&adap->stream); |
| 1175 | adap->feedcount = 0; |
| 1176 | } |
| 1177 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1178 | if (st->lme_urb != NULL) { |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1179 | st->i2c_talk_onoff = 1; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1180 | st->signal_lock = 0; |
| 1181 | st->signal_level = 0; |
| 1182 | st->signal_sn = 0; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1183 | buffer = st->usb_buffer; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1184 | usb_kill_urb(st->lme_urb); |
| 1185 | usb_free_coherent(d->udev, 5000, st->buffer, |
| 1186 | st->lme_urb->transfer_dma); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1187 | info("Interrupt Service Stopped"); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1188 | rc_unregister_device(d->rc_dev); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1189 | info("Remote Stopped"); |
| 1190 | } |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1191 | return buffer; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | void lme2510_exit(struct usb_interface *intf) |
| 1195 | { |
| 1196 | struct dvb_usb_device *d = usb_get_intfdata(intf); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1197 | void *usb_buffer; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1198 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1199 | if (d != NULL) { |
| 1200 | usb_buffer = lme2510_exit_int(d); |
| 1201 | dvb_usb_device_exit(intf); |
| 1202 | kfree(usb_buffer); |
| 1203 | } |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | static struct usb_driver lme2510_driver = { |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1207 | .name = "LME2510C_DVB-S", |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1208 | .probe = lme2510_probe, |
| 1209 | .disconnect = lme2510_exit, |
| 1210 | .id_table = lme2510_table, |
| 1211 | }; |
| 1212 | |
| 1213 | /* module stuff */ |
| 1214 | static int __init lme2510_module_init(void) |
| 1215 | { |
| 1216 | int result = usb_register(&lme2510_driver); |
| 1217 | if (result) { |
| 1218 | err("usb_register failed. Error number %d", result); |
| 1219 | return result; |
| 1220 | } |
| 1221 | |
| 1222 | return 0; |
| 1223 | } |
| 1224 | |
| 1225 | static void __exit lme2510_module_exit(void) |
| 1226 | { |
| 1227 | /* deregister this driver from the USB subsystem */ |
| 1228 | usb_deregister(&lme2510_driver); |
| 1229 | } |
| 1230 | |
| 1231 | module_init(lme2510_module_init); |
| 1232 | module_exit(lme2510_module_exit); |
| 1233 | |
| 1234 | MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>"); |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1235 | MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0"); |
Malcolm Priestley | 30bd3b5 | 2011-02-13 20:12:15 -0300 | [diff] [blame] | 1236 | MODULE_VERSION("1.81"); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1237 | MODULE_LICENSE("GPL"); |