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