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