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