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