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); |
| 324 | info("INT Interupt Service Started"); |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | static int lme2510_return_status(struct usb_device *dev) |
| 330 | { |
| 331 | int ret = 0; |
| 332 | u8 data[10] = {0}; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 333 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 334 | ret |= usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 335 | 0x06, 0x80, 0x0302, 0x00, data, 0x0006, 200); |
| 336 | info("Firmware Status: %x (%x)", ret , data[2]); |
| 337 | |
| 338 | return (ret < 0) ? -ENODEV : data[2]; |
| 339 | } |
| 340 | |
| 341 | static int lme2510_msg(struct dvb_usb_device *d, |
| 342 | u8 *wbuf, int wlen, u8 *rbuf, int rlen) |
| 343 | { |
| 344 | int ret = 0; |
| 345 | struct lme2510_state *st = d->priv; |
| 346 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 347 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 348 | return -EAGAIN; |
| 349 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 350 | if (st->i2c_talk_onoff == 1) { |
| 351 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 352 | ret = lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); |
| 353 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 354 | switch (st->tuner_config) { |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 355 | case TUNER_LG: |
| 356 | if (wbuf[2] == 0x1c) { |
| 357 | if (wbuf[3] == 0x0e) { |
| 358 | st->signal_lock = rbuf[1]; |
| 359 | if ((st->stream_on & 1) && |
| 360 | (st->signal_lock & 0x10)) { |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 361 | lme2510_stream_restart(d); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 362 | st->i2c_talk_onoff = 0; |
| 363 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 364 | msleep(80); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | break; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 368 | case TUNER_S7395: |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 369 | if (wbuf[2] == 0xd0) { |
| 370 | if (wbuf[3] == 0x24) { |
| 371 | st->signal_lock = rbuf[1]; |
| 372 | if ((st->stream_on & 1) && |
| 373 | (st->signal_lock & 0x8)) { |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 374 | lme2510_stream_restart(d); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 375 | st->i2c_talk_onoff = 0; |
| 376 | } |
| 377 | } |
| 378 | if ((wbuf[3] != 0x6) & (wbuf[3] != 0x5)) |
| 379 | msleep(5); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 380 | } |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 381 | break; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 382 | case TUNER_S0194: |
| 383 | if (wbuf[2] == 0xd0) { |
| 384 | if (wbuf[3] == 0x1b) { |
| 385 | st->signal_lock = rbuf[1]; |
| 386 | if ((st->stream_on & 1) && |
| 387 | (st->signal_lock & 0x8)) { |
| 388 | lme2510_stream_restart(d); |
| 389 | st->i2c_talk_onoff = 0; |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | break; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 394 | default: |
| 395 | break; |
| 396 | } |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 397 | } else { |
| 398 | switch (st->tuner_config) { |
| 399 | case TUNER_LG: |
| 400 | switch (wbuf[3]) { |
| 401 | case 0x0e: |
| 402 | rbuf[0] = 0x55; |
| 403 | rbuf[1] = st->signal_lock; |
| 404 | break; |
| 405 | case 0x43: |
| 406 | rbuf[0] = 0x55; |
| 407 | rbuf[1] = st->signal_level; |
| 408 | break; |
| 409 | case 0x1c: |
| 410 | rbuf[0] = 0x55; |
| 411 | rbuf[1] = st->signal_sn; |
| 412 | break; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 413 | case 0x15: |
| 414 | case 0x16: |
| 415 | case 0x17: |
| 416 | case 0x18: |
| 417 | rbuf[0] = 0x55; |
| 418 | rbuf[1] = 0x00; |
| 419 | break; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 420 | default: |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 421 | lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); |
| 422 | st->i2c_talk_onoff = 1; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 423 | break; |
| 424 | } |
| 425 | break; |
| 426 | case TUNER_S7395: |
| 427 | switch (wbuf[3]) { |
| 428 | case 0x10: |
| 429 | rbuf[0] = 0x55; |
| 430 | rbuf[1] = (st->signal_level & 0x80) |
| 431 | ? 0 : (st->signal_level * 2); |
| 432 | break; |
| 433 | case 0x2d: |
| 434 | rbuf[0] = 0x55; |
| 435 | rbuf[1] = st->signal_sn; |
| 436 | break; |
| 437 | case 0x24: |
| 438 | rbuf[0] = 0x55; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 439 | rbuf[1] = st->signal_lock; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 440 | break; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 441 | case 0x2e: |
| 442 | case 0x26: |
| 443 | case 0x27: |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 444 | rbuf[0] = 0x55; |
| 445 | rbuf[1] = 0x00; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 446 | break; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 447 | default: |
| 448 | lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); |
| 449 | st->i2c_talk_onoff = 1; |
| 450 | break; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 451 | } |
| 452 | break; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 453 | case TUNER_S0194: |
| 454 | switch (wbuf[3]) { |
| 455 | case 0x18: |
| 456 | rbuf[0] = 0x55; |
| 457 | rbuf[1] = (st->signal_level & 0x80) |
| 458 | ? 0 : (st->signal_level * 2); |
| 459 | break; |
| 460 | case 0x24: |
| 461 | rbuf[0] = 0x55; |
| 462 | rbuf[1] = st->signal_sn; |
| 463 | break; |
| 464 | case 0x1b: |
| 465 | rbuf[0] = 0x55; |
| 466 | rbuf[1] = st->signal_lock; |
| 467 | break; |
| 468 | case 0x19: |
| 469 | case 0x25: |
| 470 | case 0x1e: |
| 471 | case 0x1d: |
| 472 | rbuf[0] = 0x55; |
| 473 | rbuf[1] = 0x00; |
| 474 | break; |
| 475 | default: |
| 476 | lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); |
| 477 | st->i2c_talk_onoff = 1; |
| 478 | break; |
| 479 | } |
| 480 | break; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 481 | default: |
| 482 | break; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | deb_info(4, "I2C From Interupt Message out(%02x) in(%02x)", |
| 486 | wbuf[3], rbuf[1]); |
| 487 | |
| 488 | } |
| 489 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 490 | mutex_unlock(&d->i2c_mutex); |
| 491 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 492 | return ret; |
| 493 | } |
| 494 | |
| 495 | |
| 496 | static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
| 497 | int num) |
| 498 | { |
| 499 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 500 | struct lme2510_state *st = d->priv; |
| 501 | static u8 obuf[64], ibuf[512]; |
| 502 | int i, read, read_o; |
| 503 | u16 len; |
| 504 | u8 gate = st->i2c_gate; |
| 505 | |
| 506 | if (gate == 0) |
| 507 | gate = 5; |
| 508 | |
| 509 | if (num > 2) |
| 510 | warn("more than 2 i2c messages" |
| 511 | "at a time is not handled yet. TODO."); |
| 512 | |
| 513 | for (i = 0; i < num; i++) { |
| 514 | read_o = 1 & (msg[i].flags & I2C_M_RD); |
| 515 | read = i+1 < num && (msg[i+1].flags & I2C_M_RD); |
| 516 | read |= read_o; |
| 517 | gate = (msg[i].addr == st->i2c_tuner_addr) |
| 518 | ? (read) ? st->i2c_tuner_gate_r |
| 519 | : st->i2c_tuner_gate_w |
| 520 | : st->i2c_gate; |
| 521 | obuf[0] = gate | (read << 7); |
| 522 | |
| 523 | if (gate == 5) |
| 524 | obuf[1] = (read) ? 2 : msg[i].len + 1; |
| 525 | else |
| 526 | obuf[1] = msg[i].len + read + 1; |
| 527 | |
| 528 | obuf[2] = msg[i].addr; |
| 529 | if (read) { |
| 530 | if (read_o) |
| 531 | len = 3; |
| 532 | else { |
| 533 | memcpy(&obuf[3], msg[i].buf, msg[i].len); |
| 534 | obuf[msg[i].len+3] = msg[i+1].len; |
| 535 | len = msg[i].len+4; |
| 536 | } |
| 537 | } else { |
| 538 | memcpy(&obuf[3], msg[i].buf, msg[i].len); |
| 539 | len = msg[i].len+3; |
| 540 | } |
| 541 | |
| 542 | if (lme2510_msg(d, obuf, len, ibuf, 512) < 0) { |
| 543 | deb_info(1, "i2c transfer failed."); |
| 544 | return -EAGAIN; |
| 545 | } |
| 546 | |
| 547 | if (read) { |
| 548 | if (read_o) |
| 549 | memcpy(msg[i].buf, &ibuf[1], msg[i].len); |
| 550 | else { |
| 551 | memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len); |
| 552 | i++; |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | return i; |
| 557 | } |
| 558 | |
| 559 | static u32 lme2510_i2c_func(struct i2c_adapter *adapter) |
| 560 | { |
| 561 | return I2C_FUNC_I2C; |
| 562 | } |
| 563 | |
| 564 | static struct i2c_algorithm lme2510_i2c_algo = { |
| 565 | .master_xfer = lme2510_i2c_xfer, |
| 566 | .functionality = lme2510_i2c_func, |
| 567 | }; |
| 568 | |
| 569 | /* Callbacks for DVB USB */ |
| 570 | static int lme2510_identify_state(struct usb_device *udev, |
| 571 | struct dvb_usb_device_properties *props, |
| 572 | struct dvb_usb_device_description **desc, |
| 573 | int *cold) |
| 574 | { |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 575 | *cold = 0; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 576 | return 0; |
| 577 | } |
| 578 | |
| 579 | static int lme2510_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) |
| 580 | { |
| 581 | struct lme2510_state *st = adap->dev->priv; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 582 | static u8 clear_reg_3[] = LME_CLEAR_PID; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 583 | static u8 rbuf[1]; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 584 | int ret = 0, rlen = sizeof(rbuf); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 585 | |
| 586 | deb_info(1, "STM (%02x)", onoff); |
| 587 | |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 588 | /* Streaming is started by FE_HAS_LOCK */ |
| 589 | if (onoff == 1) |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 590 | st->stream_on = 1; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 591 | else { |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 592 | deb_info(1, "STM Steam Off"); |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 593 | /* mutex is here only to avoid collision with I2C */ |
| 594 | ret = mutex_lock_interruptible(&adap->dev->i2c_mutex); |
| 595 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 596 | ret |= lme2510_usb_talk(adap->dev, clear_reg_3, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 597 | sizeof(clear_reg_3), rbuf, rlen); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 598 | st->stream_on = 0; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 599 | st->i2c_talk_onoff = 1; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 600 | |
| 601 | mutex_unlock(&adap->dev->i2c_mutex); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | return (ret < 0) ? -ENODEV : 0; |
| 605 | } |
| 606 | |
| 607 | static int lme2510_int_service(struct dvb_usb_adapter *adap) |
| 608 | { |
| 609 | struct dvb_usb_device *d = adap->dev; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 610 | struct rc_dev *rc; |
| 611 | int ret; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 612 | |
| 613 | info("STA Configuring Remote"); |
| 614 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 615 | rc = rc_allocate_device(); |
| 616 | if (!rc) |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 617 | return -ENOMEM; |
| 618 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 619 | usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys)); |
| 620 | strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys)); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 621 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 622 | rc->input_name = "LME2510 Remote Control"; |
| 623 | rc->input_phys = d->rc_phys; |
| 624 | rc->map_name = RC_MAP_LME2510; |
| 625 | rc->driver_name = "LME 2510"; |
| 626 | usb_to_input_id(d->udev, &rc->input_id); |
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 | ret = rc_register_device(rc); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 629 | if (ret) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 630 | rc_free_device(rc); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 631 | return ret; |
| 632 | } |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 633 | d->rc_dev = rc; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 634 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 635 | /* Start the Interupt */ |
| 636 | ret = lme2510_int_read(adap); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 637 | if (ret < 0) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 638 | rc_unregister_device(rc); |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 639 | info("INT Unable to start Interupt Service"); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 640 | return -ENODEV; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 641 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 642 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 643 | return 0; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | static u8 check_sum(u8 *p, u8 len) |
| 647 | { |
| 648 | u8 sum = 0; |
| 649 | while (len--) |
| 650 | sum += *p++; |
| 651 | return sum; |
| 652 | } |
| 653 | |
| 654 | static int lme2510_download_firmware(struct usb_device *dev, |
| 655 | const struct firmware *fw) |
| 656 | { |
| 657 | int ret = 0; |
| 658 | u8 data[512] = {0}; |
| 659 | u16 j, wlen, len_in, start, end; |
| 660 | u8 packet_size, dlen, i; |
| 661 | u8 *fw_data; |
| 662 | |
| 663 | packet_size = 0x31; |
| 664 | len_in = 1; |
| 665 | |
| 666 | |
| 667 | info("FRM Starting Firmware Download"); |
| 668 | |
| 669 | for (i = 1; i < 3; i++) { |
| 670 | start = (i == 1) ? 0 : 512; |
| 671 | end = (i == 1) ? 512 : fw->size; |
| 672 | for (j = start; j < end; j += (packet_size+1)) { |
| 673 | fw_data = (u8 *)(fw->data + j); |
| 674 | if ((end - j) > packet_size) { |
| 675 | data[0] = i; |
| 676 | dlen = packet_size; |
| 677 | } else { |
| 678 | data[0] = i | 0x80; |
| 679 | dlen = (u8)(end - j)-1; |
| 680 | } |
| 681 | data[1] = dlen; |
| 682 | memcpy(&data[2], fw_data, dlen+1); |
| 683 | wlen = (u8) dlen + 4; |
| 684 | data[wlen-1] = check_sum(fw_data, dlen+1); |
| 685 | deb_info(1, "Data S=%02x:E=%02x CS= %02x", data[3], |
| 686 | data[dlen+2], data[dlen+3]); |
| 687 | ret |= lme2510_bulk_write(dev, data, wlen, 1); |
| 688 | ret |= lme2510_bulk_read(dev, data, len_in , 1); |
| 689 | ret |= (data[0] == 0x88) ? 0 : -1; |
| 690 | } |
| 691 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 692 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 693 | usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 694 | 0x06, 0x80, 0x0200, 0x00, data, 0x0109, 1000); |
| 695 | |
| 696 | |
| 697 | data[0] = 0x8a; |
| 698 | len_in = 1; |
| 699 | msleep(2000); |
| 700 | ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Resetting*/ |
| 701 | ret |= lme2510_bulk_read(dev, data, len_in, 1); |
| 702 | msleep(400); |
| 703 | |
| 704 | if (ret < 0) |
| 705 | info("FRM Firmware Download Failed (%04x)" , ret); |
| 706 | else |
| 707 | info("FRM Firmware Download Completed - Resetting Device"); |
| 708 | |
| 709 | |
| 710 | return (ret < 0) ? -ENODEV : 0; |
| 711 | } |
| 712 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 713 | static void lme_coldreset(struct usb_device *dev) |
| 714 | { |
| 715 | int ret = 0, len_in; |
| 716 | u8 data[512] = {0}; |
| 717 | |
| 718 | data[0] = 0x0a; |
| 719 | len_in = 1; |
| 720 | info("FRM Firmware Cold Reset"); |
| 721 | ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Cold Resetting*/ |
| 722 | ret |= lme2510_bulk_read(dev, data, len_in, 1); |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 723 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 724 | return; |
| 725 | } |
| 726 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 727 | static int lme_firmware_switch(struct usb_device *udev, int cold) |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 728 | { |
| 729 | const struct firmware *fw = NULL; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 730 | const char fw_c_s7395[] = "dvb-usb-lme2510c-s7395.fw"; |
| 731 | const char fw_c_lg[] = "dvb-usb-lme2510c-lg.fw"; |
| 732 | const char fw_c_s0194[] = "dvb-usb-lme2510c-s0194.fw"; |
| 733 | const char fw_lg[] = "dvb-usb-lme2510-lg.fw"; |
| 734 | const char fw_s0194[] = "dvb-usb-lme2510-s0194.fw"; |
| 735 | const char *fw_lme; |
| 736 | int ret, cold_fw; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 737 | |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 738 | cold = (cold > 0) ? (cold & 1) : 0; |
| 739 | |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 740 | cold_fw = !cold; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 741 | |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 742 | if (udev->descriptor.idProduct == 0x1122) { |
| 743 | switch (dvb_usb_lme2510_firmware) { |
| 744 | default: |
| 745 | dvb_usb_lme2510_firmware = TUNER_S0194; |
| 746 | case TUNER_S0194: |
| 747 | fw_lme = fw_s0194; |
| 748 | ret = request_firmware(&fw, fw_lme, &udev->dev); |
| 749 | if (ret == 0) { |
| 750 | cold = 0;/*lme2510-s0194 cannot cold reset*/ |
| 751 | break; |
| 752 | } |
| 753 | dvb_usb_lme2510_firmware = TUNER_LG; |
| 754 | case TUNER_LG: |
| 755 | fw_lme = fw_lg; |
| 756 | ret = request_firmware(&fw, fw_lme, &udev->dev); |
| 757 | if (ret == 0) |
| 758 | break; |
| 759 | info("FRM No Firmware Found - please install"); |
| 760 | dvb_usb_lme2510_firmware = TUNER_DEFAULT; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 761 | cold = 0; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 762 | cold_fw = 0; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 763 | break; |
| 764 | } |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 765 | } else { |
| 766 | switch (dvb_usb_lme2510_firmware) { |
| 767 | default: |
| 768 | dvb_usb_lme2510_firmware = TUNER_S7395; |
| 769 | case TUNER_S7395: |
| 770 | fw_lme = fw_c_s7395; |
| 771 | ret = request_firmware(&fw, fw_lme, &udev->dev); |
| 772 | if (ret == 0) |
| 773 | break; |
| 774 | dvb_usb_lme2510_firmware = TUNER_LG; |
| 775 | case TUNER_LG: |
| 776 | fw_lme = fw_c_lg; |
| 777 | ret = request_firmware(&fw, fw_lme, &udev->dev); |
| 778 | if (ret == 0) |
| 779 | break; |
| 780 | dvb_usb_lme2510_firmware = TUNER_S0194; |
| 781 | case TUNER_S0194: |
| 782 | fw_lme = fw_c_s0194; |
| 783 | ret = request_firmware(&fw, fw_lme, &udev->dev); |
| 784 | if (ret == 0) |
| 785 | break; |
| 786 | info("FRM No Firmware Found - please install"); |
| 787 | dvb_usb_lme2510_firmware = TUNER_DEFAULT; |
| 788 | cold = 0; |
| 789 | cold_fw = 0; |
| 790 | break; |
| 791 | } |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 792 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 793 | |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 794 | if (cold_fw) { |
| 795 | info("FRM Loading %s file", fw_lme); |
| 796 | ret = lme2510_download_firmware(udev, fw); |
| 797 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 798 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 799 | if (cold) { |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 800 | info("FRM Changing to %s firmware", fw_lme); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 801 | lme_coldreset(udev); |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 802 | return -ENODEV; |
| 803 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 804 | |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 805 | release_firmware(fw); |
| 806 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 807 | return ret; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 808 | } |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 809 | |
| 810 | static int lme2510_kill_urb(struct usb_data_stream *stream) |
| 811 | { |
| 812 | int i; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 813 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 814 | for (i = 0; i < stream->urbs_submitted; i++) { |
| 815 | deb_info(3, "killing URB no. %d.", i); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 816 | /* stop the URB */ |
| 817 | usb_kill_urb(stream->urb_list[i]); |
| 818 | } |
| 819 | stream->urbs_submitted = 0; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 820 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | static struct tda10086_config tda10086_config = { |
| 825 | .demod_address = 0x1c, |
| 826 | .invert = 0, |
| 827 | .diseqc_tone = 1, |
| 828 | .xtal_freq = TDA10086_XTAL_16M, |
| 829 | }; |
| 830 | |
| 831 | static struct stv0288_config lme_config = { |
| 832 | .demod_address = 0xd0, |
| 833 | .min_delay_ms = 15, |
| 834 | .inittab = s7395_inittab, |
| 835 | }; |
| 836 | |
| 837 | static struct ix2505v_config lme_tuner = { |
| 838 | .tuner_address = 0xc0, |
| 839 | .min_delay_ms = 100, |
| 840 | .tuner_gain = 0x0, |
| 841 | .tuner_chargepump = 0x3, |
| 842 | }; |
| 843 | |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 844 | static struct stv0299_config sharp_z0194_config = { |
| 845 | .demod_address = 0xd0, |
| 846 | .inittab = sharp_z0194a_inittab, |
| 847 | .mclk = 88000000UL, |
| 848 | .invert = 0, |
| 849 | .skip_reinit = 0, |
| 850 | .lock_output = STV0299_LOCKOUTPUT_1, |
| 851 | .volt13_op0_op1 = STV0299_VOLT13_OP1, |
| 852 | .min_delay_ms = 100, |
| 853 | .set_symbol_rate = sharp_z0194a_set_symbol_rate, |
| 854 | }; |
| 855 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 856 | static int dm04_lme2510_set_voltage(struct dvb_frontend *fe, |
| 857 | fe_sec_voltage_t voltage) |
| 858 | { |
| 859 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 860 | static u8 voltage_low[] = LME_VOLTAGE_L; |
| 861 | static u8 voltage_high[] = LME_VOLTAGE_H; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 862 | static u8 rbuf[1]; |
| 863 | int ret = 0, len = 3, rlen = 1; |
| 864 | |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 865 | if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0) |
| 866 | return -EAGAIN; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 867 | |
| 868 | switch (voltage) { |
| 869 | case SEC_VOLTAGE_18: |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 870 | ret |= lme2510_usb_talk(adap->dev, |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 871 | voltage_high, len, rbuf, rlen); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 872 | break; |
| 873 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 874 | case SEC_VOLTAGE_OFF: |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 875 | case SEC_VOLTAGE_13: |
| 876 | default: |
| 877 | ret |= lme2510_usb_talk(adap->dev, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 878 | voltage_low, len, rbuf, rlen); |
| 879 | break; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 880 | } |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 881 | |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 882 | mutex_unlock(&adap->dev->i2c_mutex); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 883 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 884 | return (ret < 0) ? -ENODEV : 0; |
| 885 | } |
| 886 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 887 | static int lme_name(struct dvb_usb_adapter *adap) |
| 888 | { |
| 889 | struct lme2510_state *st = adap->dev->priv; |
| 890 | const char *desc = adap->dev->desc->name; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 891 | char *fe_name[] = {"", " LG TDQY-P001F", " SHARP:BS2F7HZ7395", |
| 892 | " SHARP:BS2F7HZ0194"}; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 893 | char *name = adap->fe->ops.info.name; |
| 894 | |
| 895 | strlcpy(name, desc, 128); |
| 896 | strlcat(name, fe_name[st->tuner_config], 128); |
| 897 | |
| 898 | return 0; |
| 899 | } |
| 900 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 901 | static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap) |
| 902 | { |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 903 | struct lme2510_state *st = adap->dev->priv; |
| 904 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 905 | int ret = 0; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 906 | |
| 907 | st->i2c_talk_onoff = 1; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 908 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 909 | st->i2c_gate = 4; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 910 | adap->fe = dvb_attach(tda10086_attach, &tda10086_config, |
| 911 | &adap->dev->i2c_adap); |
| 912 | |
| 913 | if (adap->fe) { |
| 914 | info("TUN Found Frontend TDA10086"); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 915 | st->i2c_tuner_gate_w = 4; |
| 916 | st->i2c_tuner_gate_r = 4; |
| 917 | st->i2c_tuner_addr = 0xc0; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 918 | st->tuner_config = TUNER_LG; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 919 | if (dvb_usb_lme2510_firmware != TUNER_LG) { |
| 920 | dvb_usb_lme2510_firmware = TUNER_LG; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 921 | ret = lme_firmware_switch(adap->dev->udev, 1); |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 922 | } |
| 923 | goto end; |
| 924 | } |
| 925 | |
| 926 | st->i2c_gate = 4; |
| 927 | adap->fe = dvb_attach(stv0299_attach, &sharp_z0194_config, |
| 928 | &adap->dev->i2c_adap); |
| 929 | if (adap->fe) { |
| 930 | info("FE Found Stv0299"); |
| 931 | st->i2c_tuner_gate_w = 4; |
| 932 | st->i2c_tuner_gate_r = 5; |
| 933 | st->i2c_tuner_addr = 0xc0; |
| 934 | st->tuner_config = TUNER_S0194; |
| 935 | if (dvb_usb_lme2510_firmware != TUNER_S0194) { |
| 936 | dvb_usb_lme2510_firmware = TUNER_S0194; |
| 937 | ret = lme_firmware_switch(adap->dev->udev, 1); |
| 938 | } |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 939 | goto end; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 940 | } |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 941 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 942 | st->i2c_gate = 5; |
| 943 | adap->fe = dvb_attach(stv0288_attach, &lme_config, |
| 944 | &adap->dev->i2c_adap); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 945 | if (adap->fe) { |
| 946 | info("FE Found Stv0288"); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 947 | st->i2c_tuner_gate_w = 4; |
| 948 | st->i2c_tuner_gate_r = 5; |
| 949 | st->i2c_tuner_addr = 0xc0; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 950 | st->tuner_config = TUNER_S7395; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 951 | if (dvb_usb_lme2510_firmware != TUNER_S7395) { |
| 952 | dvb_usb_lme2510_firmware = TUNER_S7395; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 953 | ret = lme_firmware_switch(adap->dev->udev, 1); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 954 | } |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 955 | } else { |
| 956 | info("DM04 Not Supported"); |
| 957 | return -ENODEV; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 958 | } |
| 959 | |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 960 | |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 961 | end: if (ret) { |
| 962 | kfree(adap->fe); |
| 963 | adap->fe = NULL; |
| 964 | return -ENODEV; |
| 965 | } |
| 966 | |
| 967 | adap->fe->ops.set_voltage = dm04_lme2510_set_voltage; |
| 968 | ret = lme_name(adap); |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 969 | return ret; |
| 970 | } |
| 971 | |
| 972 | static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap) |
| 973 | { |
| 974 | struct lme2510_state *st = adap->dev->priv; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 975 | char *tun_msg[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA"}; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 976 | int ret = 0; |
| 977 | |
| 978 | switch (st->tuner_config) { |
| 979 | case TUNER_LG: |
| 980 | if (dvb_attach(tda826x_attach, adap->fe, 0xc0, |
| 981 | &adap->dev->i2c_adap, 1)) |
| 982 | ret = st->tuner_config; |
| 983 | break; |
| 984 | case TUNER_S7395: |
| 985 | if (dvb_attach(ix2505v_attach , adap->fe, &lme_tuner, |
| 986 | &adap->dev->i2c_adap)) |
| 987 | ret = st->tuner_config; |
| 988 | break; |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 989 | case TUNER_S0194: |
| 990 | if (dvb_attach(dvb_pll_attach , adap->fe, 0xc0, |
| 991 | &adap->dev->i2c_adap, DVB_PLL_OPERA1)) |
| 992 | ret = st->tuner_config; |
| 993 | break; |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 994 | default: |
| 995 | break; |
| 996 | } |
| 997 | |
| 998 | if (ret) |
| 999 | info("TUN Found %s tuner", tun_msg[ret]); |
| 1000 | else { |
| 1001 | info("TUN No tuner found --- reseting device"); |
| 1002 | lme_coldreset(adap->dev->udev); |
| 1003 | return -ENODEV; |
| 1004 | } |
| 1005 | |
| 1006 | /* Start the Interupt & Remote*/ |
| 1007 | ret = lme2510_int_service(adap); |
| 1008 | |
| 1009 | return ret; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | static int lme2510_powerup(struct dvb_usb_device *d, int onoff) |
| 1013 | { |
| 1014 | struct lme2510_state *st = d->priv; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 1015 | static u8 lnb_on[] = LNB_ON; |
| 1016 | static u8 lnb_off[] = LNB_OFF; |
| 1017 | static u8 rbuf[1]; |
| 1018 | int ret, len = 3, rlen = 1; |
| 1019 | |
| 1020 | ret = mutex_lock_interruptible(&d->i2c_mutex); |
| 1021 | |
| 1022 | if (onoff) |
| 1023 | ret |= lme2510_usb_talk(d, lnb_on, len, rbuf, rlen); |
| 1024 | else |
| 1025 | ret |= lme2510_usb_talk(d, lnb_off, len, rbuf, rlen); |
| 1026 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1027 | st->i2c_talk_onoff = 1; |
Malcolm Priestley | f23e661 | 2010-10-27 19:50:36 -0300 | [diff] [blame] | 1028 | |
| 1029 | mutex_unlock(&d->i2c_mutex); |
| 1030 | |
| 1031 | return ret; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | /* DVB USB Driver stuff */ |
| 1035 | static struct dvb_usb_device_properties lme2510_properties; |
| 1036 | static struct dvb_usb_device_properties lme2510c_properties; |
| 1037 | |
| 1038 | static int lme2510_probe(struct usb_interface *intf, |
| 1039 | const struct usb_device_id *id) |
| 1040 | { |
| 1041 | struct usb_device *udev = interface_to_usbdev(intf); |
| 1042 | int ret = 0; |
| 1043 | |
| 1044 | usb_reset_configuration(udev); |
| 1045 | |
| 1046 | usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 1); |
| 1047 | |
| 1048 | if (udev->speed != USB_SPEED_HIGH) { |
| 1049 | ret = usb_reset_device(udev); |
| 1050 | info("DEV Failed to connect in HIGH SPEED mode"); |
| 1051 | return -ENODEV; |
| 1052 | } |
| 1053 | |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 1054 | if (lme2510_return_status(udev) == 0x44) { |
| 1055 | lme_firmware_switch(udev, 0); |
| 1056 | return -ENODEV; |
| 1057 | } |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1058 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1059 | if (0 == dvb_usb_device_init(intf, &lme2510_properties, |
| 1060 | THIS_MODULE, NULL, adapter_nr)) { |
| 1061 | info("DEV registering device driver"); |
| 1062 | return 0; |
| 1063 | } |
| 1064 | if (0 == dvb_usb_device_init(intf, &lme2510c_properties, |
| 1065 | THIS_MODULE, NULL, adapter_nr)) { |
| 1066 | info("DEV registering device driver"); |
| 1067 | return 0; |
| 1068 | } |
| 1069 | |
| 1070 | info("DEV lme2510 Error"); |
| 1071 | return -ENODEV; |
| 1072 | |
| 1073 | } |
| 1074 | |
| 1075 | static struct usb_device_id lme2510_table[] = { |
| 1076 | { USB_DEVICE(0x3344, 0x1122) }, /* LME2510 */ |
| 1077 | { USB_DEVICE(0x3344, 0x1120) }, /* LME2510C */ |
| 1078 | {} /* Terminating entry */ |
| 1079 | }; |
| 1080 | |
| 1081 | MODULE_DEVICE_TABLE(usb, lme2510_table); |
| 1082 | |
| 1083 | static struct dvb_usb_device_properties lme2510_properties = { |
| 1084 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1085 | .size_of_priv = sizeof(struct lme2510_state), |
| 1086 | .num_adapters = 1, |
| 1087 | .adapter = { |
| 1088 | { |
| 1089 | .streaming_ctrl = lme2510_streaming_ctrl, |
| 1090 | .frontend_attach = dm04_lme2510_frontend_attach, |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1091 | .tuner_attach = dm04_lme2510_tuner, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1092 | /* parameter for the MPEG2-data transfer */ |
| 1093 | .stream = { |
| 1094 | .type = USB_BULK, |
| 1095 | .count = 10, |
| 1096 | .endpoint = 0x06, |
| 1097 | .u = { |
| 1098 | .bulk = { |
| 1099 | .buffersize = 4096, |
| 1100 | |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | }, |
| 1106 | .power_ctrl = lme2510_powerup, |
| 1107 | .identify_state = lme2510_identify_state, |
| 1108 | .i2c_algo = &lme2510_i2c_algo, |
| 1109 | .generic_bulk_ctrl_endpoint = 0, |
| 1110 | .num_device_descs = 1, |
| 1111 | .devices = { |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1112 | { "DM04_LME2510_DVB-S", |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1113 | { &lme2510_table[0], NULL }, |
| 1114 | }, |
| 1115 | |
| 1116 | } |
| 1117 | }; |
| 1118 | |
| 1119 | static struct dvb_usb_device_properties lme2510c_properties = { |
| 1120 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1121 | .size_of_priv = sizeof(struct lme2510_state), |
| 1122 | .num_adapters = 1, |
| 1123 | .adapter = { |
| 1124 | { |
| 1125 | .streaming_ctrl = lme2510_streaming_ctrl, |
| 1126 | .frontend_attach = dm04_lme2510_frontend_attach, |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1127 | .tuner_attach = dm04_lme2510_tuner, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1128 | /* parameter for the MPEG2-data transfer */ |
| 1129 | .stream = { |
| 1130 | .type = USB_BULK, |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1131 | .count = 10, |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1132 | .endpoint = 0x8, |
| 1133 | .u = { |
| 1134 | .bulk = { |
| 1135 | .buffersize = 4096, |
| 1136 | |
| 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | } |
| 1141 | }, |
| 1142 | .power_ctrl = lme2510_powerup, |
| 1143 | .identify_state = lme2510_identify_state, |
| 1144 | .i2c_algo = &lme2510_i2c_algo, |
| 1145 | .generic_bulk_ctrl_endpoint = 0, |
| 1146 | .num_device_descs = 1, |
| 1147 | .devices = { |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1148 | { "DM04_LME2510C_DVB-S", |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1149 | { &lme2510_table[1], NULL }, |
| 1150 | }, |
| 1151 | } |
| 1152 | }; |
| 1153 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1154 | void *lme2510_exit_int(struct dvb_usb_device *d) |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1155 | { |
| 1156 | struct lme2510_state *st = d->priv; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1157 | struct dvb_usb_adapter *adap = &d->adapter[0]; |
| 1158 | void *buffer = NULL; |
| 1159 | |
| 1160 | if (adap != NULL) { |
| 1161 | lme2510_kill_urb(&adap->stream); |
| 1162 | adap->feedcount = 0; |
| 1163 | } |
| 1164 | |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1165 | if (st->lme_urb != NULL) { |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1166 | st->i2c_talk_onoff = 1; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1167 | st->signal_lock = 0; |
| 1168 | st->signal_level = 0; |
| 1169 | st->signal_sn = 0; |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1170 | buffer = st->usb_buffer; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1171 | usb_kill_urb(st->lme_urb); |
| 1172 | usb_free_coherent(d->udev, 5000, st->buffer, |
| 1173 | st->lme_urb->transfer_dma); |
| 1174 | info("Interupt Service Stopped"); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1175 | rc_unregister_device(d->rc_dev); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1176 | info("Remote Stopped"); |
| 1177 | } |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1178 | return buffer; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | void lme2510_exit(struct usb_interface *intf) |
| 1182 | { |
| 1183 | struct dvb_usb_device *d = usb_get_intfdata(intf); |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1184 | void *usb_buffer; |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1185 | |
Malcolm Priestley | ab599a6 | 2010-10-16 16:44:43 -0300 | [diff] [blame] | 1186 | if (d != NULL) { |
| 1187 | usb_buffer = lme2510_exit_int(d); |
| 1188 | dvb_usb_device_exit(intf); |
| 1189 | kfree(usb_buffer); |
| 1190 | } |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | static struct usb_driver lme2510_driver = { |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1194 | .name = "LME2510C_DVB-S", |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1195 | .probe = lme2510_probe, |
| 1196 | .disconnect = lme2510_exit, |
| 1197 | .id_table = lme2510_table, |
| 1198 | }; |
| 1199 | |
| 1200 | /* module stuff */ |
| 1201 | static int __init lme2510_module_init(void) |
| 1202 | { |
| 1203 | int result = usb_register(&lme2510_driver); |
| 1204 | if (result) { |
| 1205 | err("usb_register failed. Error number %d", result); |
| 1206 | return result; |
| 1207 | } |
| 1208 | |
| 1209 | return 0; |
| 1210 | } |
| 1211 | |
| 1212 | static void __exit lme2510_module_exit(void) |
| 1213 | { |
| 1214 | /* deregister this driver from the USB subsystem */ |
| 1215 | usb_deregister(&lme2510_driver); |
| 1216 | } |
| 1217 | |
| 1218 | module_init(lme2510_module_init); |
| 1219 | module_exit(lme2510_module_exit); |
| 1220 | |
| 1221 | MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>"); |
Malcolm Priestley | 75aecc3 | 2010-12-07 19:49:24 -0300 | [diff] [blame] | 1222 | MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0"); |
Malcolm Priestley | 9d4540c | 2011-02-12 22:35:08 -0300 | [diff] [blame] | 1223 | MODULE_VERSION("1.80"); |
Malcolm Priestley | d2f918b | 2010-09-02 17:29:30 -0300 | [diff] [blame] | 1224 | MODULE_LICENSE("GPL"); |