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