Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Realtek RTL28xxU DVB USB driver |
| 3 | * |
| 4 | * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> |
| 5 | * Copyright (C) 2011 Antti Palosaari <crope@iki.fi> |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 6 | * Copyright (C) 2012 Thomas Mair <thomas.mair86@googlemail.com> |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | */ |
| 22 | |
| 23 | #include "rtl28xxu.h" |
| 24 | |
Antti Palosaari | 94b5fa6 | 2013-11-22 14:20:14 -0300 | [diff] [blame] | 25 | static int rtl28xxu_disable_rc; |
| 26 | module_param_named(disable_rc, rtl28xxu_disable_rc, int, 0644); |
| 27 | MODULE_PARM_DESC(disable_rc, "disable RTL2832U remote controller"); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 28 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 29 | |
| 30 | static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req) |
| 31 | { |
Antti Palosaari | c56222a | 2014-12-21 18:33:14 -0300 | [diff] [blame] | 32 | struct rtl28xxu_dev *dev = d->priv; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 33 | int ret; |
| 34 | unsigned int pipe; |
| 35 | u8 requesttype; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 36 | |
| 37 | if (req->index & CMD_WR_FLAG) { |
| 38 | /* write */ |
Antti Palosaari | c56222a | 2014-12-21 18:33:14 -0300 | [diff] [blame] | 39 | memcpy(dev->buf, req->data, req->size); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 40 | requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT); |
| 41 | pipe = usb_sndctrlpipe(d->udev, 0); |
| 42 | } else { |
| 43 | /* read */ |
| 44 | requesttype = (USB_TYPE_VENDOR | USB_DIR_IN); |
| 45 | pipe = usb_rcvctrlpipe(d->udev, 0); |
| 46 | } |
| 47 | |
| 48 | ret = usb_control_msg(d->udev, pipe, 0, requesttype, req->value, |
Antti Palosaari | c56222a | 2014-12-21 18:33:14 -0300 | [diff] [blame] | 49 | req->index, dev->buf, req->size, 1000); |
Antti Palosaari | d89b936 | 2012-08-22 19:42:00 -0300 | [diff] [blame] | 50 | dvb_usb_dbg_usb_control_msg(d->udev, 0, requesttype, req->value, |
Antti Palosaari | c56222a | 2014-12-21 18:33:14 -0300 | [diff] [blame] | 51 | req->index, dev->buf, req->size); |
| 52 | if (ret < 0) |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 53 | goto err; |
| 54 | |
Antti Palosaari | c56222a | 2014-12-21 18:33:14 -0300 | [diff] [blame] | 55 | /* read request, copy returned data to return buf */ |
| 56 | if (requesttype == (USB_TYPE_VENDOR | USB_DIR_IN)) |
| 57 | memcpy(req->data, dev->buf, req->size); |
| 58 | |
| 59 | return 0; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 60 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 61 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 62 | return ret; |
| 63 | } |
| 64 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 65 | static int rtl28xxu_wr_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 66 | { |
| 67 | struct rtl28xxu_req req; |
| 68 | |
| 69 | if (reg < 0x3000) |
| 70 | req.index = CMD_USB_WR; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 71 | else if (reg < 0x4000) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 72 | req.index = CMD_SYS_WR; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 73 | else |
| 74 | req.index = CMD_IR_WR; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 75 | |
| 76 | req.value = reg; |
| 77 | req.size = len; |
| 78 | req.data = val; |
| 79 | |
| 80 | return rtl28xxu_ctrl_msg(d, &req); |
| 81 | } |
| 82 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 83 | static int rtl28xxu_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 84 | { |
| 85 | struct rtl28xxu_req req; |
| 86 | |
| 87 | if (reg < 0x3000) |
| 88 | req.index = CMD_USB_RD; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 89 | else if (reg < 0x4000) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 90 | req.index = CMD_SYS_RD; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 91 | else |
| 92 | req.index = CMD_IR_RD; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 93 | |
| 94 | req.value = reg; |
| 95 | req.size = len; |
| 96 | req.data = val; |
| 97 | |
| 98 | return rtl28xxu_ctrl_msg(d, &req); |
| 99 | } |
| 100 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 101 | static int rtl28xxu_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 102 | { |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 103 | return rtl28xxu_wr_regs(d, reg, &val, 1); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 104 | } |
| 105 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 106 | static int rtl28xxu_rd_reg(struct dvb_usb_device *d, u16 reg, u8 *val) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 107 | { |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 108 | return rtl28xxu_rd_regs(d, reg, val, 1); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 109 | } |
| 110 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 111 | static int rtl28xxu_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val, |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 112 | u8 mask) |
| 113 | { |
| 114 | int ret; |
| 115 | u8 tmp; |
| 116 | |
| 117 | /* no need for read if whole reg is written */ |
| 118 | if (mask != 0xff) { |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 119 | ret = rtl28xxu_rd_reg(d, reg, &tmp); |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 120 | if (ret) |
| 121 | return ret; |
| 122 | |
| 123 | val &= mask; |
| 124 | tmp &= ~mask; |
| 125 | val |= tmp; |
| 126 | } |
| 127 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 128 | return rtl28xxu_wr_reg(d, reg, val); |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 129 | } |
| 130 | |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 131 | /* I2C */ |
| 132 | static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
| 133 | int num) |
| 134 | { |
| 135 | int ret; |
| 136 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 137 | struct rtl28xxu_dev *dev = d->priv; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 138 | struct rtl28xxu_req req; |
| 139 | |
| 140 | /* |
| 141 | * It is not known which are real I2C bus xfer limits, but testing |
| 142 | * with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes. |
Antti Palosaari | 34ec293 | 2011-08-04 20:21:16 -0300 | [diff] [blame] | 143 | * TODO: find out RTL2832U lens |
| 144 | */ |
| 145 | |
| 146 | /* |
| 147 | * I2C adapter logic looks rather complicated due to fact it handles |
| 148 | * three different access methods. Those methods are; |
| 149 | * 1) integrated demod access |
| 150 | * 2) old I2C access |
| 151 | * 3) new I2C access |
| 152 | * |
| 153 | * Used method is selected in order 1, 2, 3. Method 3 can handle all |
| 154 | * requests but there is two reasons why not use it always; |
| 155 | * 1) It is most expensive, usually two USB messages are needed |
| 156 | * 2) At least RTL2831U does not support it |
| 157 | * |
| 158 | * Method 3 is needed in case of I2C write+read (typical register read) |
| 159 | * where write is more than one byte. |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 160 | */ |
| 161 | |
| 162 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 163 | return -EAGAIN; |
| 164 | |
| 165 | if (num == 2 && !(msg[0].flags & I2C_M_RD) && |
| 166 | (msg[1].flags & I2C_M_RD)) { |
Antti Palosaari | 34ec293 | 2011-08-04 20:21:16 -0300 | [diff] [blame] | 167 | if (msg[0].len > 24 || msg[1].len > 24) { |
| 168 | /* TODO: check msg[0].len max */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 169 | ret = -EOPNOTSUPP; |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 170 | goto err_mutex_unlock; |
Antti Palosaari | 34ec293 | 2011-08-04 20:21:16 -0300 | [diff] [blame] | 171 | } else if (msg[0].addr == 0x10) { |
| 172 | /* method 1 - integrated demod */ |
| 173 | req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 174 | req.index = CMD_DEMOD_RD | dev->page; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 175 | req.size = msg[1].len; |
| 176 | req.data = &msg[1].buf[0]; |
| 177 | ret = rtl28xxu_ctrl_msg(d, &req); |
Antti Palosaari | 34ec293 | 2011-08-04 20:21:16 -0300 | [diff] [blame] | 178 | } else if (msg[0].len < 2) { |
| 179 | /* method 2 - old I2C */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 180 | req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1); |
| 181 | req.index = CMD_I2C_RD; |
| 182 | req.size = msg[1].len; |
| 183 | req.data = &msg[1].buf[0]; |
| 184 | ret = rtl28xxu_ctrl_msg(d, &req); |
Antti Palosaari | 34ec293 | 2011-08-04 20:21:16 -0300 | [diff] [blame] | 185 | } else { |
| 186 | /* method 3 - new I2C */ |
| 187 | req.value = (msg[0].addr << 1); |
| 188 | req.index = CMD_I2C_DA_WR; |
| 189 | req.size = msg[0].len; |
| 190 | req.data = msg[0].buf; |
| 191 | ret = rtl28xxu_ctrl_msg(d, &req); |
| 192 | if (ret) |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 193 | goto err_mutex_unlock; |
Antti Palosaari | 34ec293 | 2011-08-04 20:21:16 -0300 | [diff] [blame] | 194 | |
| 195 | req.value = (msg[0].addr << 1); |
| 196 | req.index = CMD_I2C_DA_RD; |
| 197 | req.size = msg[1].len; |
| 198 | req.data = msg[1].buf; |
| 199 | ret = rtl28xxu_ctrl_msg(d, &req); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 200 | } |
| 201 | } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) { |
| 202 | if (msg[0].len > 22) { |
Antti Palosaari | 34ec293 | 2011-08-04 20:21:16 -0300 | [diff] [blame] | 203 | /* TODO: check msg[0].len max */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 204 | ret = -EOPNOTSUPP; |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 205 | goto err_mutex_unlock; |
Antti Palosaari | 34ec293 | 2011-08-04 20:21:16 -0300 | [diff] [blame] | 206 | } else if (msg[0].addr == 0x10) { |
| 207 | /* method 1 - integrated demod */ |
| 208 | if (msg[0].buf[0] == 0x00) { |
| 209 | /* save demod page for later demod access */ |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 210 | dev->page = msg[0].buf[1]; |
Antti Palosaari | 34ec293 | 2011-08-04 20:21:16 -0300 | [diff] [blame] | 211 | ret = 0; |
| 212 | } else { |
| 213 | req.value = (msg[0].buf[0] << 8) | |
| 214 | (msg[0].addr << 1); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 215 | req.index = CMD_DEMOD_WR | dev->page; |
Antti Palosaari | 34ec293 | 2011-08-04 20:21:16 -0300 | [diff] [blame] | 216 | req.size = msg[0].len-1; |
| 217 | req.data = &msg[0].buf[1]; |
| 218 | ret = rtl28xxu_ctrl_msg(d, &req); |
| 219 | } |
Olli Salonen | 699dcff | 2015-05-05 13:54:19 -0300 | [diff] [blame] | 220 | } else if ((msg[0].len < 23) && (!dev->new_i2c_write)) { |
Antti Palosaari | 34ec293 | 2011-08-04 20:21:16 -0300 | [diff] [blame] | 221 | /* method 2 - old I2C */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 222 | req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1); |
| 223 | req.index = CMD_I2C_WR; |
| 224 | req.size = msg[0].len-1; |
| 225 | req.data = &msg[0].buf[1]; |
| 226 | ret = rtl28xxu_ctrl_msg(d, &req); |
Antti Palosaari | 34ec293 | 2011-08-04 20:21:16 -0300 | [diff] [blame] | 227 | } else { |
| 228 | /* method 3 - new I2C */ |
| 229 | req.value = (msg[0].addr << 1); |
| 230 | req.index = CMD_I2C_DA_WR; |
| 231 | req.size = msg[0].len; |
| 232 | req.data = msg[0].buf; |
| 233 | ret = rtl28xxu_ctrl_msg(d, &req); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 234 | } |
Olli Salonen | d744a0c | 2015-05-05 13:54:18 -0300 | [diff] [blame] | 235 | } else if (num == 1 && (msg[0].flags & I2C_M_RD)) { |
| 236 | req.value = (msg[0].addr << 1); |
| 237 | req.index = CMD_I2C_DA_RD; |
| 238 | req.size = msg[0].len; |
| 239 | req.data = msg[0].buf; |
| 240 | ret = rtl28xxu_ctrl_msg(d, &req); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 241 | } else { |
Olli Salonen | d744a0c | 2015-05-05 13:54:18 -0300 | [diff] [blame] | 242 | ret = -EOPNOTSUPP; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 243 | } |
| 244 | |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 245 | err_mutex_unlock: |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 246 | mutex_unlock(&d->i2c_mutex); |
| 247 | |
| 248 | return ret ? ret : num; |
| 249 | } |
| 250 | |
| 251 | static u32 rtl28xxu_i2c_func(struct i2c_adapter *adapter) |
| 252 | { |
| 253 | return I2C_FUNC_I2C; |
| 254 | } |
| 255 | |
| 256 | static struct i2c_algorithm rtl28xxu_i2c_algo = { |
| 257 | .master_xfer = rtl28xxu_i2c_xfer, |
| 258 | .functionality = rtl28xxu_i2c_func, |
| 259 | }; |
| 260 | |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 261 | static int rtl2831u_read_config(struct dvb_usb_device *d) |
| 262 | { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 263 | struct rtl28xxu_dev *dev = d_to_priv(d); |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 264 | int ret; |
| 265 | u8 buf[1]; |
| 266 | /* open RTL2831U/RTL2830 I2C gate */ |
| 267 | struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x08"}; |
| 268 | /* tuner probes */ |
| 269 | struct rtl28xxu_req req_mt2060 = {0x00c0, CMD_I2C_RD, 1, buf}; |
| 270 | struct rtl28xxu_req req_qt1010 = {0x0fc4, CMD_I2C_RD, 1, buf}; |
| 271 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 272 | dev_dbg(&d->intf->dev, "\n"); |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 273 | |
| 274 | /* |
| 275 | * RTL2831U GPIOs |
| 276 | * ========================================================= |
| 277 | * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?) |
| 278 | * GPIO2 | LED | 0 off | 1 on | |
| 279 | * GPIO4 | tuner#1 | 0 on | 1 off | MT2060 |
| 280 | */ |
| 281 | |
| 282 | /* GPIO direction */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 283 | ret = rtl28xxu_wr_reg(d, SYS_GPIO_DIR, 0x0a); |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 284 | if (ret) |
| 285 | goto err; |
| 286 | |
| 287 | /* enable as output GPIO0, GPIO2, GPIO4 */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 288 | ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_EN, 0x15); |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 289 | if (ret) |
| 290 | goto err; |
| 291 | |
| 292 | /* |
| 293 | * Probe used tuner. We need to know used tuner before demod attach |
| 294 | * since there is some demod params needed to set according to tuner. |
| 295 | */ |
| 296 | |
| 297 | /* demod needs some time to wake up */ |
| 298 | msleep(20); |
| 299 | |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 300 | dev->tuner_name = "NONE"; |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 301 | |
| 302 | /* open demod I2C gate */ |
| 303 | ret = rtl28xxu_ctrl_msg(d, &req_gate_open); |
| 304 | if (ret) |
| 305 | goto err; |
| 306 | |
| 307 | /* check QT1010 ID(?) register; reg=0f val=2c */ |
| 308 | ret = rtl28xxu_ctrl_msg(d, &req_qt1010); |
| 309 | if (ret == 0 && buf[0] == 0x2c) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 310 | dev->tuner = TUNER_RTL2830_QT1010; |
| 311 | dev->tuner_name = "QT1010"; |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 312 | goto found; |
| 313 | } |
| 314 | |
| 315 | /* open demod I2C gate */ |
| 316 | ret = rtl28xxu_ctrl_msg(d, &req_gate_open); |
| 317 | if (ret) |
| 318 | goto err; |
| 319 | |
| 320 | /* check MT2060 ID register; reg=00 val=63 */ |
| 321 | ret = rtl28xxu_ctrl_msg(d, &req_mt2060); |
| 322 | if (ret == 0 && buf[0] == 0x63) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 323 | dev->tuner = TUNER_RTL2830_MT2060; |
| 324 | dev->tuner_name = "MT2060"; |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 325 | goto found; |
| 326 | } |
| 327 | |
| 328 | /* assume MXL5005S */ |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 329 | dev->tuner = TUNER_RTL2830_MXL5005S; |
| 330 | dev->tuner_name = "MXL5005S"; |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 331 | goto found; |
| 332 | |
| 333 | found: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 334 | dev_dbg(&d->intf->dev, "tuner=%s\n", dev->tuner_name); |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 335 | |
| 336 | return 0; |
| 337 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 338 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 339 | return ret; |
| 340 | } |
| 341 | |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 342 | static int rtl2832u_read_config(struct dvb_usb_device *d) |
| 343 | { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 344 | struct rtl28xxu_dev *dev = d_to_priv(d); |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 345 | int ret; |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 346 | u8 buf[2]; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 347 | /* open RTL2832U/RTL2832 I2C gate */ |
| 348 | struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"}; |
| 349 | /* close RTL2832U/RTL2832 I2C gate */ |
| 350 | struct rtl28xxu_req req_gate_close = {0x0120, 0x0011, 0x0001, "\x10"}; |
| 351 | /* tuner probes */ |
| 352 | struct rtl28xxu_req req_fc0012 = {0x00c6, CMD_I2C_RD, 1, buf}; |
| 353 | struct rtl28xxu_req req_fc0013 = {0x00c6, CMD_I2C_RD, 1, buf}; |
| 354 | struct rtl28xxu_req req_mt2266 = {0x00c0, CMD_I2C_RD, 1, buf}; |
| 355 | struct rtl28xxu_req req_fc2580 = {0x01ac, CMD_I2C_RD, 1, buf}; |
| 356 | struct rtl28xxu_req req_mt2063 = {0x00c0, CMD_I2C_RD, 1, buf}; |
| 357 | struct rtl28xxu_req req_max3543 = {0x00c0, CMD_I2C_RD, 1, buf}; |
| 358 | struct rtl28xxu_req req_tua9001 = {0x7ec0, CMD_I2C_RD, 2, buf}; |
| 359 | struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf}; |
| 360 | struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf}; |
| 361 | struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf}; |
Gianluca Gennari | a908eb9 | 2013-06-02 17:24:24 -0300 | [diff] [blame] | 362 | struct rtl28xxu_req req_r820t = {0x0034, CMD_I2C_RD, 1, buf}; |
Antti Palosaari | 8b4cac1 | 2013-10-30 00:45:38 -0300 | [diff] [blame] | 363 | struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf}; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 364 | struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf}; |
Antti Palosaari | fc694e4 | 2014-09-30 01:03:04 -0300 | [diff] [blame] | 365 | struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf}; |
Olli Salonen | 699dcff | 2015-05-05 13:54:19 -0300 | [diff] [blame] | 366 | struct rtl28xxu_req req_si2157 = {0x00c0, CMD_I2C_RD, 1, buf}; |
| 367 | struct rtl28xxu_req req_si2168 = {0x00c8, CMD_I2C_RD, 1, buf}; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 368 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 369 | dev_dbg(&d->intf->dev, "\n"); |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 370 | |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 371 | /* enable GPIO3 and GPIO6 as output */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 372 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x40); |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 373 | if (ret) |
| 374 | goto err; |
| 375 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 376 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x48, 0x48); |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 377 | if (ret) |
| 378 | goto err; |
| 379 | |
| 380 | /* |
| 381 | * Probe used tuner. We need to know used tuner before demod attach |
| 382 | * since there is some demod params needed to set according to tuner. |
| 383 | */ |
| 384 | |
| 385 | /* open demod I2C gate */ |
| 386 | ret = rtl28xxu_ctrl_msg(d, &req_gate_open); |
| 387 | if (ret) |
| 388 | goto err; |
| 389 | |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 390 | dev->tuner_name = "NONE"; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 391 | |
| 392 | /* check FC0012 ID register; reg=00 val=a1 */ |
| 393 | ret = rtl28xxu_ctrl_msg(d, &req_fc0012); |
| 394 | if (ret == 0 && buf[0] == 0xa1) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 395 | dev->tuner = TUNER_RTL2832_FC0012; |
| 396 | dev->tuner_name = "FC0012"; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 397 | goto tuner_found; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | /* check FC0013 ID register; reg=00 val=a3 */ |
| 401 | ret = rtl28xxu_ctrl_msg(d, &req_fc0013); |
| 402 | if (ret == 0 && buf[0] == 0xa3) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 403 | dev->tuner = TUNER_RTL2832_FC0013; |
| 404 | dev->tuner_name = "FC0013"; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 405 | goto tuner_found; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | /* check MT2266 ID register; reg=00 val=85 */ |
| 409 | ret = rtl28xxu_ctrl_msg(d, &req_mt2266); |
| 410 | if (ret == 0 && buf[0] == 0x85) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 411 | dev->tuner = TUNER_RTL2832_MT2266; |
| 412 | dev->tuner_name = "MT2266"; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 413 | goto tuner_found; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /* check FC2580 ID register; reg=01 val=56 */ |
| 417 | ret = rtl28xxu_ctrl_msg(d, &req_fc2580); |
| 418 | if (ret == 0 && buf[0] == 0x56) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 419 | dev->tuner = TUNER_RTL2832_FC2580; |
| 420 | dev->tuner_name = "FC2580"; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 421 | goto tuner_found; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | /* check MT2063 ID register; reg=00 val=9e || 9c */ |
| 425 | ret = rtl28xxu_ctrl_msg(d, &req_mt2063); |
| 426 | if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 427 | dev->tuner = TUNER_RTL2832_MT2063; |
| 428 | dev->tuner_name = "MT2063"; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 429 | goto tuner_found; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /* check MAX3543 ID register; reg=00 val=38 */ |
| 433 | ret = rtl28xxu_ctrl_msg(d, &req_max3543); |
| 434 | if (ret == 0 && buf[0] == 0x38) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 435 | dev->tuner = TUNER_RTL2832_MAX3543; |
| 436 | dev->tuner_name = "MAX3543"; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 437 | goto tuner_found; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /* check TUA9001 ID register; reg=7e val=2328 */ |
| 441 | ret = rtl28xxu_ctrl_msg(d, &req_tua9001); |
| 442 | if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 443 | dev->tuner = TUNER_RTL2832_TUA9001; |
| 444 | dev->tuner_name = "TUA9001"; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 445 | goto tuner_found; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | /* check MXL5007R ID register; reg=d9 val=14 */ |
| 449 | ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t); |
| 450 | if (ret == 0 && buf[0] == 0x14) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 451 | dev->tuner = TUNER_RTL2832_MXL5007T; |
| 452 | dev->tuner_name = "MXL5007T"; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 453 | goto tuner_found; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /* check E4000 ID register; reg=02 val=40 */ |
| 457 | ret = rtl28xxu_ctrl_msg(d, &req_e4000); |
| 458 | if (ret == 0 && buf[0] == 0x40) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 459 | dev->tuner = TUNER_RTL2832_E4000; |
| 460 | dev->tuner_name = "E4000"; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 461 | goto tuner_found; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | /* check TDA18272 ID register; reg=00 val=c760 */ |
| 465 | ret = rtl28xxu_ctrl_msg(d, &req_tda18272); |
| 466 | if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 467 | dev->tuner = TUNER_RTL2832_TDA18272; |
| 468 | dev->tuner_name = "TDA18272"; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 469 | goto tuner_found; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 470 | } |
| 471 | |
Gianluca Gennari | a908eb9 | 2013-06-02 17:24:24 -0300 | [diff] [blame] | 472 | /* check R820T ID register; reg=00 val=69 */ |
Mauro Carvalho Chehab | 6889ab2 | 2013-04-06 09:40:11 -0300 | [diff] [blame] | 473 | ret = rtl28xxu_ctrl_msg(d, &req_r820t); |
Gianluca Gennari | a908eb9 | 2013-06-02 17:24:24 -0300 | [diff] [blame] | 474 | if (ret == 0 && buf[0] == 0x69) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 475 | dev->tuner = TUNER_RTL2832_R820T; |
| 476 | dev->tuner_name = "R820T"; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 477 | goto tuner_found; |
Mauro Carvalho Chehab | 6889ab2 | 2013-04-06 09:40:11 -0300 | [diff] [blame] | 478 | } |
| 479 | |
Antti Palosaari | 8b4cac1 | 2013-10-30 00:45:38 -0300 | [diff] [blame] | 480 | /* check R828D ID register; reg=00 val=69 */ |
| 481 | ret = rtl28xxu_ctrl_msg(d, &req_r828d); |
| 482 | if (ret == 0 && buf[0] == 0x69) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 483 | dev->tuner = TUNER_RTL2832_R828D; |
| 484 | dev->tuner_name = "R828D"; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 485 | goto tuner_found; |
Antti Palosaari | 8b4cac1 | 2013-10-30 00:45:38 -0300 | [diff] [blame] | 486 | } |
| 487 | |
Olli Salonen | 699dcff | 2015-05-05 13:54:19 -0300 | [diff] [blame] | 488 | /* GPIO0 and GPIO5 to reset Si2157/Si2168 tuner and demod */ |
| 489 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x00, 0x21); |
| 490 | if (ret) |
| 491 | goto err; |
| 492 | |
| 493 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x00, 0x21); |
| 494 | if (ret) |
| 495 | goto err; |
| 496 | |
| 497 | msleep(50); |
| 498 | |
| 499 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x21, 0x21); |
| 500 | if (ret) |
| 501 | goto err; |
| 502 | |
| 503 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x21, 0x21); |
| 504 | if (ret) |
| 505 | goto err; |
| 506 | |
| 507 | msleep(50); |
| 508 | |
| 509 | /* check Si2157 ID register; reg=c0 val=80 */ |
| 510 | ret = rtl28xxu_ctrl_msg(d, &req_si2157); |
| 511 | if (ret == 0 && ((buf[0] & 0x80) == 0x80)) { |
| 512 | dev->tuner = TUNER_RTL2832_SI2157; |
| 513 | dev->tuner_name = "SI2157"; |
| 514 | goto tuner_found; |
| 515 | } |
| 516 | |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 517 | tuner_found: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 518 | dev_dbg(&d->intf->dev, "tuner=%s\n", dev->tuner_name); |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 519 | |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 520 | /* probe slave demod */ |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 521 | if (dev->tuner == TUNER_RTL2832_R828D) { |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 522 | /* power on MN88472 demod on GPIO0 */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 523 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x01, 0x01); |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 524 | if (ret) |
| 525 | goto err; |
| 526 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 527 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x01); |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 528 | if (ret) |
| 529 | goto err; |
| 530 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 531 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x01, 0x01); |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 532 | if (ret) |
| 533 | goto err; |
| 534 | |
| 535 | /* check MN88472 answers */ |
| 536 | ret = rtl28xxu_ctrl_msg(d, &req_mn88472); |
| 537 | if (ret == 0 && buf[0] == 0x02) { |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 538 | dev_dbg(&d->intf->dev, "MN88472 found\n"); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 539 | dev->slave_demod = SLAVE_DEMOD_MN88472; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 540 | goto demod_found; |
| 541 | } |
Antti Palosaari | fc694e4 | 2014-09-30 01:03:04 -0300 | [diff] [blame] | 542 | |
| 543 | ret = rtl28xxu_ctrl_msg(d, &req_mn88473); |
| 544 | if (ret == 0 && buf[0] == 0x03) { |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 545 | dev_dbg(&d->intf->dev, "MN88473 found\n"); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 546 | dev->slave_demod = SLAVE_DEMOD_MN88473; |
Antti Palosaari | fc694e4 | 2014-09-30 01:03:04 -0300 | [diff] [blame] | 547 | goto demod_found; |
| 548 | } |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 549 | } |
Olli Salonen | 699dcff | 2015-05-05 13:54:19 -0300 | [diff] [blame] | 550 | if (dev->tuner == TUNER_RTL2832_SI2157) { |
| 551 | /* check Si2168 ID register; reg=c8 val=80 */ |
| 552 | ret = rtl28xxu_ctrl_msg(d, &req_si2168); |
| 553 | if (ret == 0 && ((buf[0] & 0x80) == 0x80)) { |
| 554 | dev_dbg(&d->intf->dev, "Si2168 found\n"); |
| 555 | dev->slave_demod = SLAVE_DEMOD_SI2168; |
| 556 | goto demod_found; |
| 557 | } |
| 558 | } |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 559 | |
| 560 | demod_found: |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 561 | /* close demod I2C gate */ |
| 562 | ret = rtl28xxu_ctrl_msg(d, &req_gate_close); |
| 563 | if (ret < 0) |
| 564 | goto err; |
| 565 | |
| 566 | return 0; |
| 567 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 568 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 569 | return ret; |
| 570 | } |
| 571 | |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 572 | static int rtl28xxu_read_config(struct dvb_usb_device *d) |
| 573 | { |
| 574 | struct rtl28xxu_dev *dev = d_to_priv(d); |
| 575 | |
| 576 | if (dev->chip_id == CHIP_ID_RTL2831U) |
| 577 | return rtl2831u_read_config(d); |
| 578 | else |
| 579 | return rtl2832u_read_config(d); |
| 580 | } |
| 581 | |
Antti Palosaari | d0f232e | 2014-12-23 13:14:36 -0300 | [diff] [blame] | 582 | static int rtl28xxu_identify_state(struct dvb_usb_device *d, const char **name) |
| 583 | { |
| 584 | struct rtl28xxu_dev *dev = d_to_priv(d); |
| 585 | int ret; |
| 586 | struct rtl28xxu_req req_demod_i2c = {0x0020, CMD_I2C_DA_RD, 0, NULL}; |
| 587 | |
| 588 | dev_dbg(&d->intf->dev, "\n"); |
| 589 | |
| 590 | /* |
| 591 | * Detect chip type using I2C command that is not supported |
| 592 | * by old RTL2831U. |
| 593 | */ |
| 594 | ret = rtl28xxu_ctrl_msg(d, &req_demod_i2c); |
| 595 | if (ret == -EPIPE) { |
| 596 | dev->chip_id = CHIP_ID_RTL2831U; |
| 597 | } else if (ret == 0) { |
| 598 | dev->chip_id = CHIP_ID_RTL2832U; |
| 599 | } else { |
| 600 | dev_err(&d->intf->dev, "chip type detection failed %d\n", ret); |
| 601 | goto err; |
| 602 | } |
| 603 | dev_dbg(&d->intf->dev, "chip_id=%u\n", dev->chip_id); |
| 604 | |
| 605 | return WARM; |
| 606 | err: |
| 607 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
| 608 | return ret; |
| 609 | } |
| 610 | |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 611 | static const struct rtl2830_platform_data rtl2830_mt2060_platform_data = { |
| 612 | .clk = 28800000, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 613 | .spec_inv = 1, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 614 | .vtop = 0x20, |
| 615 | .krf = 0x04, |
| 616 | .agc_targ_val = 0x2d, |
| 617 | |
| 618 | }; |
| 619 | |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 620 | static const struct rtl2830_platform_data rtl2830_qt1010_platform_data = { |
| 621 | .clk = 28800000, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 622 | .spec_inv = 1, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 623 | .vtop = 0x20, |
| 624 | .krf = 0x04, |
| 625 | .agc_targ_val = 0x2d, |
| 626 | }; |
| 627 | |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 628 | static const struct rtl2830_platform_data rtl2830_mxl5005s_platform_data = { |
| 629 | .clk = 28800000, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 630 | .spec_inv = 0, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 631 | .vtop = 0x3f, |
| 632 | .krf = 0x04, |
| 633 | .agc_targ_val = 0x3e, |
| 634 | }; |
| 635 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 636 | static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 637 | { |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 638 | struct dvb_usb_device *d = adap_to_d(adap); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 639 | struct rtl28xxu_dev *dev = d_to_priv(d); |
| 640 | struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data; |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 641 | struct i2c_board_info board_info; |
| 642 | struct i2c_client *client; |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 643 | int ret; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 644 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 645 | dev_dbg(&d->intf->dev, "\n"); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 646 | |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 647 | switch (dev->tuner) { |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 648 | case TUNER_RTL2830_QT1010: |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 649 | *pdata = rtl2830_qt1010_platform_data; |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 650 | break; |
| 651 | case TUNER_RTL2830_MT2060: |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 652 | *pdata = rtl2830_mt2060_platform_data; |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 653 | break; |
| 654 | case TUNER_RTL2830_MXL5005S: |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 655 | *pdata = rtl2830_mxl5005s_platform_data; |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 656 | break; |
| 657 | default: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 658 | dev_err(&d->intf->dev, "unknown tuner %s\n", dev->tuner_name); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 659 | ret = -ENODEV; |
| 660 | goto err; |
| 661 | } |
| 662 | |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 663 | /* attach demodulator */ |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 664 | memset(&board_info, 0, sizeof(board_info)); |
| 665 | strlcpy(board_info.type, "rtl2830", I2C_NAME_SIZE); |
| 666 | board_info.addr = 0x10; |
| 667 | board_info.platform_data = pdata; |
| 668 | request_module("%s", board_info.type); |
| 669 | client = i2c_new_device(&d->i2c_adap, &board_info); |
| 670 | if (client == NULL || client->dev.driver == NULL) { |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 671 | ret = -ENODEV; |
| 672 | goto err; |
| 673 | } |
| 674 | |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 675 | if (!try_module_get(client->dev.driver->owner)) { |
| 676 | i2c_unregister_device(client); |
| 677 | ret = -ENODEV; |
| 678 | goto err; |
| 679 | } |
| 680 | |
| 681 | adap->fe[0] = pdata->get_dvb_frontend(client); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 682 | dev->demod_i2c_adapter = pdata->get_i2c_adapter(client); |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 683 | |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 684 | dev->i2c_client_demod = client; |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 685 | |
Antti Palosaari | 81347f5 | 2012-09-17 16:50:36 -0300 | [diff] [blame] | 686 | return 0; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 687 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 688 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 689 | return ret; |
| 690 | } |
| 691 | |
Antti Palosaari | de0a5f1 | 2014-12-13 05:44:05 -0300 | [diff] [blame] | 692 | static const struct rtl2832_platform_data rtl2832_fc0012_platform_data = { |
| 693 | .clk = 28800000, |
| 694 | .tuner = TUNER_RTL2832_FC0012 |
| 695 | }; |
| 696 | |
| 697 | static const struct rtl2832_platform_data rtl2832_fc0013_platform_data = { |
| 698 | .clk = 28800000, |
| 699 | .tuner = TUNER_RTL2832_FC0013 |
| 700 | }; |
| 701 | |
| 702 | static const struct rtl2832_platform_data rtl2832_tua9001_platform_data = { |
| 703 | .clk = 28800000, |
| 704 | .tuner = TUNER_RTL2832_TUA9001, |
| 705 | }; |
| 706 | |
| 707 | static const struct rtl2832_platform_data rtl2832_e4000_platform_data = { |
| 708 | .clk = 28800000, |
| 709 | .tuner = TUNER_RTL2832_E4000, |
| 710 | }; |
| 711 | |
| 712 | static const struct rtl2832_platform_data rtl2832_r820t_platform_data = { |
| 713 | .clk = 28800000, |
| 714 | .tuner = TUNER_RTL2832_R820T, |
| 715 | }; |
| 716 | |
Olli Salonen | 699dcff | 2015-05-05 13:54:19 -0300 | [diff] [blame] | 717 | static const struct rtl2832_platform_data rtl2832_si2157_platform_data = { |
| 718 | .clk = 28800000, |
| 719 | .tuner = TUNER_RTL2832_SI2157, |
| 720 | }; |
| 721 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 722 | static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d, |
| 723 | int cmd, int arg) |
| 724 | { |
| 725 | int ret; |
| 726 | u8 val; |
| 727 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 728 | dev_dbg(&d->intf->dev, "cmd=%d arg=%d\n", cmd, arg); |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 729 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 730 | switch (cmd) { |
| 731 | case FC_FE_CALLBACK_VHF_ENABLE: |
| 732 | /* set output values */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 733 | ret = rtl28xxu_rd_reg(d, SYS_GPIO_OUT_VAL, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 734 | if (ret) |
| 735 | goto err; |
| 736 | |
| 737 | if (arg) |
| 738 | val &= 0xbf; /* set GPIO6 low */ |
| 739 | else |
| 740 | val |= 0x40; /* set GPIO6 high */ |
| 741 | |
| 742 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 743 | ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_VAL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 744 | if (ret) |
| 745 | goto err; |
| 746 | break; |
| 747 | default: |
| 748 | ret = -EINVAL; |
| 749 | goto err; |
| 750 | } |
| 751 | return 0; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 752 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 753 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 754 | return ret; |
| 755 | } |
| 756 | |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 757 | static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d, |
| 758 | int cmd, int arg) |
| 759 | { |
| 760 | int ret; |
| 761 | u8 val; |
| 762 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 763 | dev_dbg(&d->intf->dev, "cmd=%d arg=%d\n", cmd, arg); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 764 | |
| 765 | /* |
| 766 | * CEN always enabled by hardware wiring |
| 767 | * RESETN GPIO4 |
| 768 | * RXEN GPIO1 |
| 769 | */ |
| 770 | |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 771 | switch (cmd) { |
| 772 | case TUA9001_CMD_RESETN: |
| 773 | if (arg) |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 774 | val = (1 << 4); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 775 | else |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 776 | val = (0 << 4); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 777 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 778 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x10); |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 779 | if (ret) |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 780 | goto err; |
| 781 | break; |
| 782 | case TUA9001_CMD_RXEN: |
| 783 | if (arg) |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 784 | val = (1 << 1); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 785 | else |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 786 | val = (0 << 1); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 787 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 788 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x02); |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 789 | if (ret) |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 790 | goto err; |
| 791 | break; |
| 792 | } |
| 793 | |
| 794 | return 0; |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 795 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 796 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 797 | return ret; |
| 798 | } |
| 799 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 800 | static int rtl2832u_frontend_callback(void *adapter_priv, int component, |
Antti Palosaari | 8acc91c | 2012-09-17 16:55:39 -0300 | [diff] [blame] | 801 | int cmd, int arg) |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 802 | { |
Antti Palosaari | 1dbbdce | 2014-12-17 02:55:41 -0300 | [diff] [blame] | 803 | struct i2c_adapter *adapter = adapter_priv; |
| 804 | struct device *parent = adapter->dev.parent; |
| 805 | struct i2c_adapter *parent_adapter; |
| 806 | struct dvb_usb_device *d; |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 807 | struct rtl28xxu_dev *dev; |
Antti Palosaari | 1dbbdce | 2014-12-17 02:55:41 -0300 | [diff] [blame] | 808 | |
| 809 | /* |
| 810 | * All tuners are connected to demod muxed I2C adapter. We have to |
| 811 | * resolve its parent adapter in order to get handle for this driver |
| 812 | * private data. That is a bit hackish solution, GPIO or direct driver |
| 813 | * callback would be better... |
| 814 | */ |
| 815 | if (parent != NULL && parent->type == &i2c_adapter_type) |
| 816 | parent_adapter = to_i2c_adapter(parent); |
| 817 | else |
| 818 | return -EINVAL; |
| 819 | |
| 820 | d = i2c_get_adapdata(parent_adapter); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 821 | dev = d->priv; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 822 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 823 | dev_dbg(&d->intf->dev, "component=%d cmd=%d arg=%d\n", |
| 824 | component, cmd, arg); |
Antti Palosaari | 8acc91c | 2012-09-17 16:55:39 -0300 | [diff] [blame] | 825 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 826 | switch (component) { |
| 827 | case DVB_FRONTEND_COMPONENT_TUNER: |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 828 | switch (dev->tuner) { |
Antti Palosaari | a6f6243 | 2014-12-17 03:09:32 -0300 | [diff] [blame] | 829 | case TUNER_RTL2832_FC0012: |
| 830 | return rtl2832u_fc0012_tuner_callback(d, cmd, arg); |
| 831 | case TUNER_RTL2832_TUA9001: |
| 832 | return rtl2832u_tua9001_tuner_callback(d, cmd, arg); |
| 833 | } |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 834 | } |
| 835 | |
Antti Palosaari | 97efe78 | 2012-09-17 15:49:54 -0300 | [diff] [blame] | 836 | return 0; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 837 | } |
| 838 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 839 | static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap) |
| 840 | { |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 841 | struct dvb_usb_device *d = adap_to_d(adap); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 842 | struct rtl28xxu_dev *dev = d_to_priv(d); |
| 843 | struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data; |
Antti Palosaari | 77a2e76 | 2014-12-13 00:09:57 -0300 | [diff] [blame] | 844 | struct i2c_board_info board_info; |
Antti Palosaari | 83b2f84 | 2014-12-02 11:00:23 -0300 | [diff] [blame] | 845 | struct i2c_client *client; |
Antti Palosaari | 77a2e76 | 2014-12-13 00:09:57 -0300 | [diff] [blame] | 846 | int ret; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 847 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 848 | dev_dbg(&d->intf->dev, "\n"); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 849 | |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 850 | switch (dev->tuner) { |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 851 | case TUNER_RTL2832_FC0012: |
Antti Palosaari | de0a5f1 | 2014-12-13 05:44:05 -0300 | [diff] [blame] | 852 | *pdata = rtl2832_fc0012_platform_data; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 853 | break; |
| 854 | case TUNER_RTL2832_FC0013: |
Antti Palosaari | de0a5f1 | 2014-12-13 05:44:05 -0300 | [diff] [blame] | 855 | *pdata = rtl2832_fc0013_platform_data; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 856 | break; |
| 857 | case TUNER_RTL2832_FC2580: |
Antti Palosaari | 384df49 | 2012-09-08 22:07:25 -0300 | [diff] [blame] | 858 | /* FIXME: do not abuse fc0012 settings */ |
Antti Palosaari | de0a5f1 | 2014-12-13 05:44:05 -0300 | [diff] [blame] | 859 | *pdata = rtl2832_fc0012_platform_data; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 860 | break; |
| 861 | case TUNER_RTL2832_TUA9001: |
Antti Palosaari | de0a5f1 | 2014-12-13 05:44:05 -0300 | [diff] [blame] | 862 | *pdata = rtl2832_tua9001_platform_data; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 863 | break; |
| 864 | case TUNER_RTL2832_E4000: |
Antti Palosaari | de0a5f1 | 2014-12-13 05:44:05 -0300 | [diff] [blame] | 865 | *pdata = rtl2832_e4000_platform_data; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 866 | break; |
Mauro Carvalho Chehab | 6889ab2 | 2013-04-06 09:40:11 -0300 | [diff] [blame] | 867 | case TUNER_RTL2832_R820T: |
Antti Palosaari | 8b4cac1 | 2013-10-30 00:45:38 -0300 | [diff] [blame] | 868 | case TUNER_RTL2832_R828D: |
Antti Palosaari | de0a5f1 | 2014-12-13 05:44:05 -0300 | [diff] [blame] | 869 | *pdata = rtl2832_r820t_platform_data; |
Mauro Carvalho Chehab | 6889ab2 | 2013-04-06 09:40:11 -0300 | [diff] [blame] | 870 | break; |
Olli Salonen | 699dcff | 2015-05-05 13:54:19 -0300 | [diff] [blame] | 871 | case TUNER_RTL2832_SI2157: |
| 872 | *pdata = rtl2832_si2157_platform_data; |
| 873 | break; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 874 | default: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 875 | dev_err(&d->intf->dev, "unknown tuner %s\n", dev->tuner_name); |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 876 | ret = -ENODEV; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 877 | goto err; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 878 | } |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 879 | |
| 880 | /* attach demodulator */ |
Antti Palosaari | 77a2e76 | 2014-12-13 00:09:57 -0300 | [diff] [blame] | 881 | memset(&board_info, 0, sizeof(board_info)); |
Antti Palosaari | 83b2f84 | 2014-12-02 11:00:23 -0300 | [diff] [blame] | 882 | strlcpy(board_info.type, "rtl2832", I2C_NAME_SIZE); |
| 883 | board_info.addr = 0x10; |
Antti Palosaari | 77a2e76 | 2014-12-13 00:09:57 -0300 | [diff] [blame] | 884 | board_info.platform_data = pdata; |
Antti Palosaari | 83b2f84 | 2014-12-02 11:00:23 -0300 | [diff] [blame] | 885 | request_module("%s", board_info.type); |
| 886 | client = i2c_new_device(&d->i2c_adap, &board_info); |
| 887 | if (client == NULL || client->dev.driver == NULL) { |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 888 | ret = -ENODEV; |
| 889 | goto err; |
| 890 | } |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 891 | |
Antti Palosaari | 83b2f84 | 2014-12-02 11:00:23 -0300 | [diff] [blame] | 892 | if (!try_module_get(client->dev.driver->owner)) { |
| 893 | i2c_unregister_device(client); |
| 894 | ret = -ENODEV; |
| 895 | goto err; |
| 896 | } |
| 897 | |
Antti Palosaari | 77a2e76 | 2014-12-13 00:09:57 -0300 | [diff] [blame] | 898 | adap->fe[0] = pdata->get_dvb_frontend(client); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 899 | dev->demod_i2c_adapter = pdata->get_i2c_adapter(client); |
Antti Palosaari | 83b2f84 | 2014-12-02 11:00:23 -0300 | [diff] [blame] | 900 | |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 901 | dev->i2c_client_demod = client; |
Antti Palosaari | ae1f845 | 2014-02-08 04:03:57 -0300 | [diff] [blame] | 902 | |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 903 | /* set fe callback */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 904 | adap->fe[0]->callback = rtl2832u_frontend_callback; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 905 | |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 906 | if (dev->slave_demod) { |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 907 | struct i2c_board_info info = {}; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 908 | |
| 909 | /* |
| 910 | * We continue on reduced mode, without DVB-T2/C, using master |
| 911 | * demod, when slave demod fails. |
| 912 | */ |
| 913 | ret = 0; |
| 914 | |
| 915 | /* attach slave demodulator */ |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 916 | if (dev->slave_demod == SLAVE_DEMOD_MN88472) { |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 917 | struct mn88472_config mn88472_config = {}; |
| 918 | |
| 919 | mn88472_config.fe = &adap->fe[1]; |
| 920 | mn88472_config.i2c_wr_max = 22, |
| 921 | strlcpy(info.type, "mn88472", I2C_NAME_SIZE); |
Benjamin Larsson | d2fb785 | 2014-11-26 18:51:46 -0300 | [diff] [blame] | 922 | mn88472_config.xtal = 20500000; |
Benjamin Larsson | 021cd2d | 2014-12-05 21:25:33 -0300 | [diff] [blame] | 923 | mn88472_config.ts_mode = SERIAL_TS_MODE; |
| 924 | mn88472_config.ts_clock = VARIABLE_TS_CLOCK; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 925 | info.addr = 0x18; |
| 926 | info.platform_data = &mn88472_config; |
| 927 | request_module(info.type); |
Antti Palosaari | 488be13 | 2014-12-16 11:05:08 -0300 | [diff] [blame] | 928 | client = i2c_new_device(&d->i2c_adap, &info); |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 929 | if (client == NULL || client->dev.driver == NULL) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 930 | dev->slave_demod = SLAVE_DEMOD_NONE; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 931 | goto err_slave_demod_failed; |
| 932 | } |
| 933 | |
| 934 | if (!try_module_get(client->dev.driver->owner)) { |
| 935 | i2c_unregister_device(client); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 936 | dev->slave_demod = SLAVE_DEMOD_NONE; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 937 | goto err_slave_demod_failed; |
| 938 | } |
| 939 | |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 940 | dev->i2c_client_slave_demod = client; |
Olli Salonen | 699dcff | 2015-05-05 13:54:19 -0300 | [diff] [blame] | 941 | } else if (dev->slave_demod == SLAVE_DEMOD_MN88473) { |
Antti Palosaari | fc694e4 | 2014-09-30 01:03:04 -0300 | [diff] [blame] | 942 | struct mn88473_config mn88473_config = {}; |
| 943 | |
| 944 | mn88473_config.fe = &adap->fe[1]; |
| 945 | mn88473_config.i2c_wr_max = 22, |
| 946 | strlcpy(info.type, "mn88473", I2C_NAME_SIZE); |
| 947 | info.addr = 0x18; |
| 948 | info.platform_data = &mn88473_config; |
| 949 | request_module(info.type); |
Antti Palosaari | 488be13 | 2014-12-16 11:05:08 -0300 | [diff] [blame] | 950 | client = i2c_new_device(&d->i2c_adap, &info); |
Antti Palosaari | fc694e4 | 2014-09-30 01:03:04 -0300 | [diff] [blame] | 951 | if (client == NULL || client->dev.driver == NULL) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 952 | dev->slave_demod = SLAVE_DEMOD_NONE; |
Antti Palosaari | fc694e4 | 2014-09-30 01:03:04 -0300 | [diff] [blame] | 953 | goto err_slave_demod_failed; |
| 954 | } |
| 955 | |
| 956 | if (!try_module_get(client->dev.driver->owner)) { |
| 957 | i2c_unregister_device(client); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 958 | dev->slave_demod = SLAVE_DEMOD_NONE; |
Antti Palosaari | fc694e4 | 2014-09-30 01:03:04 -0300 | [diff] [blame] | 959 | goto err_slave_demod_failed; |
| 960 | } |
| 961 | |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 962 | dev->i2c_client_slave_demod = client; |
Olli Salonen | 699dcff | 2015-05-05 13:54:19 -0300 | [diff] [blame] | 963 | } else { |
| 964 | struct si2168_config si2168_config = {}; |
| 965 | struct i2c_adapter *adapter; |
| 966 | |
| 967 | si2168_config.i2c_adapter = &adapter; |
| 968 | si2168_config.fe = &adap->fe[1]; |
| 969 | si2168_config.ts_mode = SI2168_TS_SERIAL; |
| 970 | si2168_config.ts_clock_inv = false; |
| 971 | si2168_config.ts_clock_gapped = true; |
| 972 | strlcpy(info.type, "si2168", I2C_NAME_SIZE); |
| 973 | info.addr = 0x64; |
| 974 | info.platform_data = &si2168_config; |
| 975 | request_module(info.type); |
| 976 | client = i2c_new_device(&d->i2c_adap, &info); |
| 977 | if (client == NULL || client->dev.driver == NULL) { |
| 978 | dev->slave_demod = SLAVE_DEMOD_NONE; |
| 979 | goto err_slave_demod_failed; |
| 980 | } |
| 981 | |
| 982 | if (!try_module_get(client->dev.driver->owner)) { |
| 983 | i2c_unregister_device(client); |
| 984 | dev->slave_demod = SLAVE_DEMOD_NONE; |
| 985 | goto err_slave_demod_failed; |
| 986 | } |
| 987 | |
| 988 | dev->i2c_client_slave_demod = client; |
| 989 | |
| 990 | /* for Si2168 devices use only new I2C write method */ |
| 991 | dev->new_i2c_write = true; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 992 | } |
| 993 | } |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 994 | return 0; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 995 | err_slave_demod_failed: |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 996 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 997 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 998 | return ret; |
| 999 | } |
| 1000 | |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1001 | static int rtl28xxu_frontend_attach(struct dvb_usb_adapter *adap) |
| 1002 | { |
| 1003 | struct rtl28xxu_dev *dev = adap_to_priv(adap); |
| 1004 | |
| 1005 | if (dev->chip_id == CHIP_ID_RTL2831U) |
| 1006 | return rtl2831u_frontend_attach(adap); |
| 1007 | else |
| 1008 | return rtl2832u_frontend_attach(adap); |
| 1009 | } |
| 1010 | |
| 1011 | static int rtl28xxu_frontend_detach(struct dvb_usb_adapter *adap) |
Antti Palosaari | 8d44aee | 2014-12-02 11:23:49 -0300 | [diff] [blame] | 1012 | { |
| 1013 | struct dvb_usb_device *d = adap_to_d(adap); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1014 | struct rtl28xxu_dev *dev = d_to_priv(d); |
Antti Palosaari | 8d44aee | 2014-12-02 11:23:49 -0300 | [diff] [blame] | 1015 | struct i2c_client *client; |
| 1016 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1017 | dev_dbg(&d->intf->dev, "\n"); |
Antti Palosaari | 8d44aee | 2014-12-02 11:23:49 -0300 | [diff] [blame] | 1018 | |
| 1019 | /* remove I2C slave demod */ |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1020 | client = dev->i2c_client_slave_demod; |
Antti Palosaari | 8d44aee | 2014-12-02 11:23:49 -0300 | [diff] [blame] | 1021 | if (client) { |
| 1022 | module_put(client->dev.driver->owner); |
| 1023 | i2c_unregister_device(client); |
| 1024 | } |
| 1025 | |
| 1026 | /* remove I2C demod */ |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1027 | client = dev->i2c_client_demod; |
Antti Palosaari | 8d44aee | 2014-12-02 11:23:49 -0300 | [diff] [blame] | 1028 | if (client) { |
| 1029 | module_put(client->dev.driver->owner); |
| 1030 | i2c_unregister_device(client); |
| 1031 | } |
| 1032 | |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1036 | static struct qt1010_config rtl28xxu_qt1010_config = { |
| 1037 | .i2c_address = 0x62, /* 0xc4 */ |
| 1038 | }; |
| 1039 | |
| 1040 | static struct mt2060_config rtl28xxu_mt2060_config = { |
| 1041 | .i2c_address = 0x60, /* 0xc0 */ |
| 1042 | .clock_out = 0, |
| 1043 | }; |
| 1044 | |
| 1045 | static struct mxl5005s_config rtl28xxu_mxl5005s_config = { |
| 1046 | .i2c_address = 0x63, /* 0xc6 */ |
| 1047 | .if_freq = IF_FREQ_4570000HZ, |
| 1048 | .xtal_freq = CRYSTAL_FREQ_16000000HZ, |
| 1049 | .agc_mode = MXL_SINGLE_AGC, |
| 1050 | .tracking_filter = MXL_TF_C_H, |
| 1051 | .rssi_enable = MXL_RSSI_ENABLE, |
| 1052 | .cap_select = MXL_CAP_SEL_ENABLE, |
| 1053 | .div_out = MXL_DIV_OUT_4, |
| 1054 | .clock_out = MXL_CLOCK_OUT_DISABLE, |
| 1055 | .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM, |
| 1056 | .top = MXL5005S_TOP_25P2, |
| 1057 | .mod_mode = MXL_DIGITAL_MODE, |
| 1058 | .if_mode = MXL_ZERO_IF, |
| 1059 | .AgcMasterByte = 0x00, |
| 1060 | }; |
| 1061 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1062 | static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1063 | { |
| 1064 | int ret; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1065 | struct dvb_usb_device *d = adap_to_d(adap); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1066 | struct rtl28xxu_dev *dev = d_to_priv(d); |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 1067 | struct dvb_frontend *fe; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1068 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1069 | dev_dbg(&d->intf->dev, "\n"); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1070 | |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1071 | switch (dev->tuner) { |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1072 | case TUNER_RTL2830_QT1010: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1073 | fe = dvb_attach(qt1010_attach, adap->fe[0], |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1074 | dev->demod_i2c_adapter, |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 1075 | &rtl28xxu_qt1010_config); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1076 | break; |
| 1077 | case TUNER_RTL2830_MT2060: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1078 | fe = dvb_attach(mt2060_attach, adap->fe[0], |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1079 | dev->demod_i2c_adapter, |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 1080 | &rtl28xxu_mt2060_config, 1220); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1081 | break; |
| 1082 | case TUNER_RTL2830_MXL5005S: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1083 | fe = dvb_attach(mxl5005s_attach, adap->fe[0], |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1084 | dev->demod_i2c_adapter, |
Antti Palosaari | c0ceac9 | 2014-12-07 22:02:23 -0300 | [diff] [blame] | 1085 | &rtl28xxu_mxl5005s_config); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1086 | break; |
| 1087 | default: |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 1088 | fe = NULL; |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1089 | dev_err(&d->intf->dev, "unknown tuner %d\n", dev->tuner); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | if (fe == NULL) { |
| 1093 | ret = -ENODEV; |
| 1094 | goto err; |
| 1095 | } |
| 1096 | |
| 1097 | return 0; |
| 1098 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1099 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1100 | return ret; |
| 1101 | } |
| 1102 | |
Antti Palosaari | ad3a758 | 2012-12-08 23:27:49 -0300 | [diff] [blame] | 1103 | static const struct fc0012_config rtl2832u_fc0012_config = { |
| 1104 | .i2c_address = 0x63, /* 0xc6 >> 1 */ |
| 1105 | .xtal_freq = FC_XTAL_28_8_MHZ, |
| 1106 | }; |
| 1107 | |
Mauro Carvalho Chehab | 6889ab2 | 2013-04-06 09:40:11 -0300 | [diff] [blame] | 1108 | static const struct r820t_config rtl2832u_r820t_config = { |
| 1109 | .i2c_addr = 0x1a, |
| 1110 | .xtal = 28800000, |
| 1111 | .max_i2c_msg_len = 2, |
| 1112 | .rafael_chip = CHIP_R820T, |
| 1113 | }; |
| 1114 | |
Antti Palosaari | 8b4cac1 | 2013-10-30 00:45:38 -0300 | [diff] [blame] | 1115 | static const struct r820t_config rtl2832u_r828d_config = { |
| 1116 | .i2c_addr = 0x3a, |
| 1117 | .xtal = 16000000, |
| 1118 | .max_i2c_msg_len = 2, |
| 1119 | .rafael_chip = CHIP_R828D, |
| 1120 | }; |
| 1121 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1122 | static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap) |
| 1123 | { |
| 1124 | int ret; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1125 | struct dvb_usb_device *d = adap_to_d(adap); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1126 | struct rtl28xxu_dev *dev = d_to_priv(d); |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 1127 | struct dvb_frontend *fe = NULL; |
| 1128 | struct i2c_board_info info; |
| 1129 | struct i2c_client *client; |
Antti Palosaari | a2f7f22 | 2014-12-16 10:50:54 -0300 | [diff] [blame] | 1130 | struct v4l2_subdev *subdev = NULL; |
Mauro Carvalho Chehab | e181b1f | 2015-02-03 16:36:28 -0200 | [diff] [blame] | 1131 | struct platform_device *pdev; |
| 1132 | struct rtl2832_sdr_platform_data pdata; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1133 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1134 | dev_dbg(&d->intf->dev, "\n"); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1135 | |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 1136 | memset(&info, 0, sizeof(struct i2c_board_info)); |
Mauro Carvalho Chehab | e181b1f | 2015-02-03 16:36:28 -0200 | [diff] [blame] | 1137 | memset(&pdata, 0, sizeof(pdata)); |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 1138 | |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1139 | switch (dev->tuner) { |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1140 | case TUNER_RTL2832_FC0012: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1141 | fe = dvb_attach(fc0012_attach, adap->fe[0], |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1142 | dev->demod_i2c_adapter, &rtl2832u_fc0012_config); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1143 | |
| 1144 | /* since fc0012 includs reading the signal strength delegate |
| 1145 | * that to the tuner driver */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1146 | adap->fe[0]->ops.read_signal_strength = |
| 1147 | adap->fe[0]->ops.tuner_ops.get_rf_strength; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1148 | break; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1149 | case TUNER_RTL2832_FC0013: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1150 | fe = dvb_attach(fc0013_attach, adap->fe[0], |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1151 | dev->demod_i2c_adapter, 0xc6>>1, 0, FC_XTAL_28_8_MHZ); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1152 | |
| 1153 | /* fc0013 also supports signal strength reading */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1154 | adap->fe[0]->ops.read_signal_strength = |
| 1155 | adap->fe[0]->ops.tuner_ops.get_rf_strength; |
Antti Palosaari | 55cdb7d | 2014-02-03 23:07:21 -0300 | [diff] [blame] | 1156 | break; |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 1157 | case TUNER_RTL2832_E4000: { |
| 1158 | struct e4000_config e4000_config = { |
| 1159 | .fe = adap->fe[0], |
| 1160 | .clock = 28800000, |
| 1161 | }; |
| 1162 | |
| 1163 | strlcpy(info.type, "e4000", I2C_NAME_SIZE); |
| 1164 | info.addr = 0x64; |
| 1165 | info.platform_data = &e4000_config; |
| 1166 | |
| 1167 | request_module(info.type); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1168 | client = i2c_new_device(dev->demod_i2c_adapter, &info); |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 1169 | if (client == NULL || client->dev.driver == NULL) |
| 1170 | break; |
| 1171 | |
| 1172 | if (!try_module_get(client->dev.driver->owner)) { |
| 1173 | i2c_unregister_device(client); |
| 1174 | break; |
| 1175 | } |
| 1176 | |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1177 | dev->i2c_client_tuner = client; |
Antti Palosaari | a2f7f22 | 2014-12-16 10:50:54 -0300 | [diff] [blame] | 1178 | subdev = i2c_get_clientdata(client); |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 1179 | } |
Antti Palosaari | 542f6a5 | 2012-09-01 21:09:22 -0300 | [diff] [blame] | 1180 | break; |
Antti Palosaari | 35fc0e0 | 2015-04-14 19:55:51 -0300 | [diff] [blame] | 1181 | case TUNER_RTL2832_FC2580: { |
| 1182 | struct fc2580_platform_data fc2580_pdata = { |
| 1183 | .dvb_frontend = adap->fe[0], |
| 1184 | }; |
| 1185 | struct i2c_board_info board_info = {}; |
| 1186 | |
| 1187 | strlcpy(board_info.type, "fc2580", I2C_NAME_SIZE); |
| 1188 | board_info.addr = 0x56; |
| 1189 | board_info.platform_data = &fc2580_pdata; |
| 1190 | request_module("fc2580"); |
| 1191 | client = i2c_new_device(dev->demod_i2c_adapter, |
| 1192 | &board_info); |
| 1193 | if (client == NULL || client->dev.driver == NULL) |
| 1194 | break; |
| 1195 | if (!try_module_get(client->dev.driver->owner)) { |
| 1196 | i2c_unregister_device(client); |
| 1197 | break; |
| 1198 | } |
| 1199 | dev->i2c_client_tuner = client; |
| 1200 | } |
Antti Palosaari | 384df49 | 2012-09-08 22:07:25 -0300 | [diff] [blame] | 1201 | break; |
Antti Palosaari | 88ffe55 | 2015-04-15 19:25:32 -0300 | [diff] [blame^] | 1202 | case TUNER_RTL2832_TUA9001: { |
| 1203 | struct tua9001_platform_data tua9001_pdata = { |
| 1204 | .dvb_frontend = adap->fe[0], |
| 1205 | }; |
| 1206 | struct i2c_board_info board_info = {}; |
| 1207 | |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 1208 | /* enable GPIO1 and GPIO4 as output */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1209 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12); |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 1210 | if (ret) |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 1211 | goto err; |
| 1212 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1213 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x12, 0x12); |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 1214 | if (ret) |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 1215 | goto err; |
| 1216 | |
Antti Palosaari | 88ffe55 | 2015-04-15 19:25:32 -0300 | [diff] [blame^] | 1217 | strlcpy(board_info.type, "tua9001", I2C_NAME_SIZE); |
| 1218 | board_info.addr = 0x60; |
| 1219 | board_info.platform_data = &tua9001_pdata; |
| 1220 | request_module("tua9001"); |
| 1221 | client = i2c_new_device(dev->demod_i2c_adapter, &board_info); |
| 1222 | if (client == NULL || client->dev.driver == NULL) |
| 1223 | break; |
| 1224 | if (!try_module_get(client->dev.driver->owner)) { |
| 1225 | i2c_unregister_device(client); |
| 1226 | break; |
| 1227 | } |
| 1228 | dev->i2c_client_tuner = client; |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 1229 | break; |
Antti Palosaari | 88ffe55 | 2015-04-15 19:25:32 -0300 | [diff] [blame^] | 1230 | } |
Mauro Carvalho Chehab | 6889ab2 | 2013-04-06 09:40:11 -0300 | [diff] [blame] | 1231 | case TUNER_RTL2832_R820T: |
Antti Palosaari | 164f3d2 | 2014-12-14 11:45:55 -0300 | [diff] [blame] | 1232 | fe = dvb_attach(r820t_attach, adap->fe[0], |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1233 | dev->demod_i2c_adapter, |
Mauro Carvalho Chehab | 6889ab2 | 2013-04-06 09:40:11 -0300 | [diff] [blame] | 1234 | &rtl2832u_r820t_config); |
Mauro Carvalho Chehab | 9e30edd | 2013-04-07 18:57:15 -0300 | [diff] [blame] | 1235 | |
| 1236 | /* Use tuner to get the signal strength */ |
| 1237 | adap->fe[0]->ops.read_signal_strength = |
| 1238 | adap->fe[0]->ops.tuner_ops.get_rf_strength; |
Mauro Carvalho Chehab | 6889ab2 | 2013-04-06 09:40:11 -0300 | [diff] [blame] | 1239 | break; |
Antti Palosaari | 8b4cac1 | 2013-10-30 00:45:38 -0300 | [diff] [blame] | 1240 | case TUNER_RTL2832_R828D: |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 1241 | fe = dvb_attach(r820t_attach, adap->fe[0], |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1242 | dev->demod_i2c_adapter, |
Antti Palosaari | 8b4cac1 | 2013-10-30 00:45:38 -0300 | [diff] [blame] | 1243 | &rtl2832u_r828d_config); |
Antti Palosaari | 8b4cac1 | 2013-10-30 00:45:38 -0300 | [diff] [blame] | 1244 | adap->fe[0]->ops.read_signal_strength = |
| 1245 | adap->fe[0]->ops.tuner_ops.get_rf_strength; |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 1246 | |
| 1247 | if (adap->fe[1]) { |
| 1248 | fe = dvb_attach(r820t_attach, adap->fe[1], |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1249 | dev->demod_i2c_adapter, |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 1250 | &rtl2832u_r828d_config); |
| 1251 | adap->fe[1]->ops.read_signal_strength = |
| 1252 | adap->fe[1]->ops.tuner_ops.get_rf_strength; |
| 1253 | } |
Antti Palosaari | 8b4cac1 | 2013-10-30 00:45:38 -0300 | [diff] [blame] | 1254 | break; |
Olli Salonen | 699dcff | 2015-05-05 13:54:19 -0300 | [diff] [blame] | 1255 | case TUNER_RTL2832_SI2157: { |
| 1256 | struct si2157_config si2157_config = { |
| 1257 | .fe = adap->fe[0], |
| 1258 | .if_port = 0, |
| 1259 | .inversion = false, |
| 1260 | }; |
| 1261 | |
| 1262 | strlcpy(info.type, "si2157", I2C_NAME_SIZE); |
| 1263 | info.addr = 0x60; |
| 1264 | info.platform_data = &si2157_config; |
| 1265 | request_module(info.type); |
| 1266 | client = i2c_new_device(&d->i2c_adap, &info); |
| 1267 | if (client == NULL || client->dev.driver == NULL) |
| 1268 | break; |
| 1269 | |
| 1270 | if (!try_module_get(client->dev.driver->owner)) { |
| 1271 | i2c_unregister_device(client); |
| 1272 | break; |
| 1273 | } |
| 1274 | |
| 1275 | dev->i2c_client_tuner = client; |
| 1276 | subdev = i2c_get_clientdata(client); |
| 1277 | |
| 1278 | /* copy tuner ops for 2nd FE as tuner is shared */ |
| 1279 | if (adap->fe[1]) { |
| 1280 | adap->fe[1]->tuner_priv = |
| 1281 | adap->fe[0]->tuner_priv; |
| 1282 | memcpy(&adap->fe[1]->ops.tuner_ops, |
| 1283 | &adap->fe[0]->ops.tuner_ops, |
| 1284 | sizeof(struct dvb_tuner_ops)); |
| 1285 | } |
| 1286 | } |
| 1287 | break; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1288 | default: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1289 | dev_err(&d->intf->dev, "unknown tuner %d\n", dev->tuner); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1290 | } |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1291 | if (fe == NULL && dev->i2c_client_tuner == NULL) { |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1292 | ret = -ENODEV; |
| 1293 | goto err; |
| 1294 | } |
| 1295 | |
Antti Palosaari | a2f7f22 | 2014-12-16 10:50:54 -0300 | [diff] [blame] | 1296 | /* register SDR */ |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1297 | switch (dev->tuner) { |
Antti Palosaari | a2f7f22 | 2014-12-16 10:50:54 -0300 | [diff] [blame] | 1298 | case TUNER_RTL2832_FC0012: |
| 1299 | case TUNER_RTL2832_FC0013: |
| 1300 | case TUNER_RTL2832_E4000: |
| 1301 | case TUNER_RTL2832_R820T: |
| 1302 | case TUNER_RTL2832_R828D: |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1303 | pdata.clk = dev->rtl2832_platform_data.clk; |
| 1304 | pdata.tuner = dev->tuner; |
| 1305 | pdata.i2c_client = dev->i2c_client_demod; |
| 1306 | pdata.bulk_read = dev->rtl2832_platform_data.bulk_read; |
| 1307 | pdata.bulk_write = dev->rtl2832_platform_data.bulk_write; |
| 1308 | pdata.update_bits = dev->rtl2832_platform_data.update_bits; |
Antti Palosaari | a2f7f22 | 2014-12-16 10:50:54 -0300 | [diff] [blame] | 1309 | pdata.dvb_frontend = adap->fe[0]; |
| 1310 | pdata.dvb_usb_device = d; |
| 1311 | pdata.v4l2_subdev = subdev; |
| 1312 | |
| 1313 | request_module("%s", "rtl2832_sdr"); |
Antti Palosaari | 6a53fa2 | 2014-12-17 08:16:10 -0300 | [diff] [blame] | 1314 | pdev = platform_device_register_data(&d->intf->dev, |
Antti Palosaari | a2f7f22 | 2014-12-16 10:50:54 -0300 | [diff] [blame] | 1315 | "rtl2832_sdr", |
| 1316 | PLATFORM_DEVID_AUTO, |
| 1317 | &pdata, sizeof(pdata)); |
Wei Yongjun | 250d2ff | 2015-04-16 09:22:46 -0300 | [diff] [blame] | 1318 | if (IS_ERR(pdev) || pdev->dev.driver == NULL) |
Antti Palosaari | a2f7f22 | 2014-12-16 10:50:54 -0300 | [diff] [blame] | 1319 | break; |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1320 | dev->platform_device_sdr = pdev; |
Antti Palosaari | a2f7f22 | 2014-12-16 10:50:54 -0300 | [diff] [blame] | 1321 | break; |
| 1322 | default: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1323 | dev_dbg(&d->intf->dev, "no SDR for tuner=%d\n", dev->tuner); |
Antti Palosaari | a2f7f22 | 2014-12-16 10:50:54 -0300 | [diff] [blame] | 1324 | } |
| 1325 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1326 | return 0; |
| 1327 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1328 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1329 | return ret; |
| 1330 | } |
| 1331 | |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1332 | static int rtl28xxu_tuner_attach(struct dvb_usb_adapter *adap) |
| 1333 | { |
| 1334 | struct rtl28xxu_dev *dev = adap_to_priv(adap); |
| 1335 | |
| 1336 | if (dev->chip_id == CHIP_ID_RTL2831U) |
| 1337 | return rtl2831u_tuner_attach(adap); |
| 1338 | else |
| 1339 | return rtl2832u_tuner_attach(adap); |
| 1340 | } |
| 1341 | |
| 1342 | static int rtl28xxu_tuner_detach(struct dvb_usb_adapter *adap) |
Antti Palosaari | 8d44aee | 2014-12-02 11:23:49 -0300 | [diff] [blame] | 1343 | { |
| 1344 | struct dvb_usb_device *d = adap_to_d(adap); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1345 | struct rtl28xxu_dev *dev = d_to_priv(d); |
Antti Palosaari | 8d44aee | 2014-12-02 11:23:49 -0300 | [diff] [blame] | 1346 | struct i2c_client *client; |
Antti Palosaari | a2f7f22 | 2014-12-16 10:50:54 -0300 | [diff] [blame] | 1347 | struct platform_device *pdev; |
Antti Palosaari | 8d44aee | 2014-12-02 11:23:49 -0300 | [diff] [blame] | 1348 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1349 | dev_dbg(&d->intf->dev, "\n"); |
Antti Palosaari | 8d44aee | 2014-12-02 11:23:49 -0300 | [diff] [blame] | 1350 | |
Antti Palosaari | a2f7f22 | 2014-12-16 10:50:54 -0300 | [diff] [blame] | 1351 | /* remove platform SDR */ |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1352 | pdev = dev->platform_device_sdr; |
Antti Palosaari | 6a53fa2 | 2014-12-17 08:16:10 -0300 | [diff] [blame] | 1353 | if (pdev) |
Antti Palosaari | a2f7f22 | 2014-12-16 10:50:54 -0300 | [diff] [blame] | 1354 | platform_device_unregister(pdev); |
Antti Palosaari | a2f7f22 | 2014-12-16 10:50:54 -0300 | [diff] [blame] | 1355 | |
Antti Palosaari | 8d44aee | 2014-12-02 11:23:49 -0300 | [diff] [blame] | 1356 | /* remove I2C tuner */ |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1357 | client = dev->i2c_client_tuner; |
Antti Palosaari | 8d44aee | 2014-12-02 11:23:49 -0300 | [diff] [blame] | 1358 | if (client) { |
| 1359 | module_put(client->dev.driver->owner); |
| 1360 | i2c_unregister_device(client); |
| 1361 | } |
| 1362 | |
| 1363 | return 0; |
| 1364 | } |
| 1365 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1366 | static int rtl28xxu_init(struct dvb_usb_device *d) |
| 1367 | { |
| 1368 | int ret; |
| 1369 | u8 val; |
| 1370 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1371 | dev_dbg(&d->intf->dev, "\n"); |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1372 | |
| 1373 | /* init USB endpoints */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1374 | ret = rtl28xxu_rd_reg(d, USB_SYSCTL_0, &val); |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1375 | if (ret) |
| 1376 | goto err; |
| 1377 | |
| 1378 | /* enable DMA and Full Packet Mode*/ |
| 1379 | val |= 0x09; |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1380 | ret = rtl28xxu_wr_reg(d, USB_SYSCTL_0, val); |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1381 | if (ret) |
| 1382 | goto err; |
| 1383 | |
| 1384 | /* set EPA maximum packet size to 0x0200 */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1385 | ret = rtl28xxu_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4); |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1386 | if (ret) |
| 1387 | goto err; |
| 1388 | |
| 1389 | /* change EPA FIFO length */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1390 | ret = rtl28xxu_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4); |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1391 | if (ret) |
| 1392 | goto err; |
| 1393 | |
| 1394 | return ret; |
| 1395 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1396 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1397 | return ret; |
| 1398 | } |
| 1399 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1400 | static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1401 | { |
| 1402 | int ret; |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 1403 | u8 gpio, sys0, epa_ctl[2]; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1404 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1405 | dev_dbg(&d->intf->dev, "onoff=%d\n", onoff); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1406 | |
| 1407 | /* demod adc */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1408 | ret = rtl28xxu_rd_reg(d, SYS_SYS0, &sys0); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1409 | if (ret) |
| 1410 | goto err; |
| 1411 | |
| 1412 | /* tuner power, read GPIOs */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1413 | ret = rtl28xxu_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1414 | if (ret) |
| 1415 | goto err; |
| 1416 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1417 | dev_dbg(&d->intf->dev, "RD SYS0=%02x GPIO_OUT_VAL=%02x\n", sys0, gpio); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1418 | |
| 1419 | if (onoff) { |
| 1420 | gpio |= 0x01; /* GPIO0 = 1 */ |
| 1421 | gpio &= (~0x10); /* GPIO4 = 0 */ |
Antti Palosaari | 991452a | 2012-08-12 22:27:08 -0300 | [diff] [blame] | 1422 | gpio |= 0x04; /* GPIO2 = 1, LED on */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1423 | sys0 = sys0 & 0x0f; |
| 1424 | sys0 |= 0xe0; |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 1425 | epa_ctl[0] = 0x00; /* clear stall */ |
| 1426 | epa_ctl[1] = 0x00; /* clear reset */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1427 | } else { |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1428 | gpio &= (~0x01); /* GPIO0 = 0 */ |
| 1429 | gpio |= 0x10; /* GPIO4 = 1 */ |
Antti Palosaari | 991452a | 2012-08-12 22:27:08 -0300 | [diff] [blame] | 1430 | gpio &= (~0x04); /* GPIO2 = 1, LED off */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1431 | sys0 = sys0 & (~0xc0); |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 1432 | epa_ctl[0] = 0x10; /* set stall */ |
| 1433 | epa_ctl[1] = 0x02; /* set reset */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1434 | } |
| 1435 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1436 | dev_dbg(&d->intf->dev, "WR SYS0=%02x GPIO_OUT_VAL=%02x\n", sys0, gpio); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1437 | |
| 1438 | /* demod adc */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1439 | ret = rtl28xxu_wr_reg(d, SYS_SYS0, sys0); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1440 | if (ret) |
| 1441 | goto err; |
| 1442 | |
| 1443 | /* tuner power, write GPIOs */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1444 | ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_VAL, gpio); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1445 | if (ret) |
| 1446 | goto err; |
| 1447 | |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 1448 | /* streaming EP: stall & reset */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1449 | ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, epa_ctl, 2); |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 1450 | if (ret) |
| 1451 | goto err; |
| 1452 | |
| 1453 | if (onoff) |
| 1454 | usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81)); |
| 1455 | |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1456 | return ret; |
| 1457 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1458 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1459 | return ret; |
| 1460 | } |
| 1461 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1462 | static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff) |
| 1463 | { |
| 1464 | int ret; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1465 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1466 | dev_dbg(&d->intf->dev, "onoff=%d\n", onoff); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1467 | |
| 1468 | if (onoff) { |
Antti Palosaari | 526ca8d | 2013-06-04 18:26:54 -0300 | [diff] [blame] | 1469 | /* GPIO3=1, GPIO4=0 */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1470 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x08, 0x18); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1471 | if (ret) |
| 1472 | goto err; |
| 1473 | |
Antti Palosaari | 526ca8d | 2013-06-04 18:26:54 -0300 | [diff] [blame] | 1474 | /* suspend? */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1475 | ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL1, 0x00, 0x10); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1476 | if (ret) |
| 1477 | goto err; |
| 1478 | |
Antti Palosaari | 526ca8d | 2013-06-04 18:26:54 -0300 | [diff] [blame] | 1479 | /* enable PLL */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1480 | ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x80, 0x80); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1481 | if (ret) |
| 1482 | goto err; |
| 1483 | |
Antti Palosaari | 526ca8d | 2013-06-04 18:26:54 -0300 | [diff] [blame] | 1484 | /* disable reset */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1485 | ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x20, 0x20); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1486 | if (ret) |
| 1487 | goto err; |
| 1488 | |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 1489 | /* streaming EP: clear stall & reset */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1490 | ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2); |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 1491 | if (ret) |
| 1492 | goto err; |
| 1493 | |
| 1494 | ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81)); |
| 1495 | if (ret) |
| 1496 | goto err; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1497 | } else { |
Antti Palosaari | 526ca8d | 2013-06-04 18:26:54 -0300 | [diff] [blame] | 1498 | /* GPIO4=1 */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1499 | ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x10, 0x10); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1500 | if (ret) |
| 1501 | goto err; |
| 1502 | |
Antti Palosaari | 526ca8d | 2013-06-04 18:26:54 -0300 | [diff] [blame] | 1503 | /* disable PLL */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1504 | ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x00, 0x80); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1505 | if (ret) |
| 1506 | goto err; |
| 1507 | |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 1508 | /* streaming EP: set stall & reset */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1509 | ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2); |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 1510 | if (ret) |
| 1511 | goto err; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | return ret; |
| 1515 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1516 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1517 | return ret; |
| 1518 | } |
| 1519 | |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1520 | static int rtl28xxu_power_ctrl(struct dvb_usb_device *d, int onoff) |
| 1521 | { |
| 1522 | struct rtl28xxu_dev *dev = d_to_priv(d); |
| 1523 | |
| 1524 | if (dev->chip_id == CHIP_ID_RTL2831U) |
| 1525 | return rtl2831u_power_ctrl(d, onoff); |
| 1526 | else |
| 1527 | return rtl2832u_power_ctrl(d, onoff); |
| 1528 | } |
| 1529 | |
| 1530 | static int rtl28xxu_frontend_ctrl(struct dvb_frontend *fe, int onoff) |
Antti Palosaari | 698f626 | 2014-09-27 01:22:45 -0300 | [diff] [blame] | 1531 | { |
| 1532 | struct dvb_usb_device *d = fe_to_d(fe); |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1533 | struct rtl28xxu_dev *dev = fe_to_priv(fe); |
| 1534 | struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data; |
Antti Palosaari | 698f626 | 2014-09-27 01:22:45 -0300 | [diff] [blame] | 1535 | int ret; |
| 1536 | u8 val; |
| 1537 | |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1538 | dev_dbg(&d->intf->dev, "fe=%d onoff=%d\n", fe->id, onoff); |
Antti Palosaari | 698f626 | 2014-09-27 01:22:45 -0300 | [diff] [blame] | 1539 | |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1540 | if (dev->chip_id == CHIP_ID_RTL2831U) |
| 1541 | return 0; |
| 1542 | |
Antti Palosaari | 698f626 | 2014-09-27 01:22:45 -0300 | [diff] [blame] | 1543 | /* control internal demod ADC */ |
| 1544 | if (fe->id == 0 && onoff) |
| 1545 | val = 0x48; /* enable ADC */ |
| 1546 | else |
| 1547 | val = 0x00; /* disable ADC */ |
| 1548 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1549 | ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, val, 0x48); |
Antti Palosaari | 698f626 | 2014-09-27 01:22:45 -0300 | [diff] [blame] | 1550 | if (ret) |
| 1551 | goto err; |
| 1552 | |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 1553 | /* bypass slave demod TS through master demod */ |
| 1554 | if (fe->id == 1 && onoff) { |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1555 | ret = pdata->enable_slave_ts(dev->i2c_client_demod); |
Antti Palosaari | 80f189a | 2013-12-01 13:44:23 -0300 | [diff] [blame] | 1556 | if (ret) |
| 1557 | goto err; |
| 1558 | } |
| 1559 | |
Antti Palosaari | 698f626 | 2014-09-27 01:22:45 -0300 | [diff] [blame] | 1560 | return 0; |
| 1561 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1562 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Antti Palosaari | 698f626 | 2014-09-27 01:22:45 -0300 | [diff] [blame] | 1563 | return ret; |
| 1564 | } |
| 1565 | |
Antti Palosaari | 37b44a0 | 2013-01-04 15:21:26 -0300 | [diff] [blame] | 1566 | #if IS_ENABLED(CONFIG_RC_CORE) |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1567 | static int rtl2831u_rc_query(struct dvb_usb_device *d) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1568 | { |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1569 | int ret, i; |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1570 | struct rtl28xxu_dev *dev = d->priv; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1571 | u8 buf[5]; |
| 1572 | u32 rc_code; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1573 | struct rtl28xxu_reg_val rc_nec_tab[] = { |
| 1574 | { 0x3033, 0x80 }, |
| 1575 | { 0x3020, 0x43 }, |
| 1576 | { 0x3021, 0x16 }, |
| 1577 | { 0x3022, 0x16 }, |
| 1578 | { 0x3023, 0x5a }, |
| 1579 | { 0x3024, 0x2d }, |
| 1580 | { 0x3025, 0x16 }, |
| 1581 | { 0x3026, 0x01 }, |
| 1582 | { 0x3028, 0xb0 }, |
| 1583 | { 0x3029, 0x04 }, |
| 1584 | { 0x302c, 0x88 }, |
| 1585 | { 0x302e, 0x13 }, |
| 1586 | { 0x3030, 0xdf }, |
| 1587 | { 0x3031, 0x05 }, |
| 1588 | }; |
| 1589 | |
| 1590 | /* init remote controller */ |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1591 | if (!dev->rc_active) { |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1592 | for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) { |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1593 | ret = rtl28xxu_wr_reg(d, rc_nec_tab[i].reg, |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 1594 | rc_nec_tab[i].val); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1595 | if (ret) |
| 1596 | goto err; |
| 1597 | } |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1598 | dev->rc_active = true; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1599 | } |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1600 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1601 | ret = rtl28xxu_rd_regs(d, SYS_IRRC_RP, buf, 5); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1602 | if (ret) |
| 1603 | goto err; |
| 1604 | |
| 1605 | if (buf[4] & 0x01) { |
| 1606 | if (buf[2] == (u8) ~buf[3]) { |
| 1607 | if (buf[0] == (u8) ~buf[1]) { |
| 1608 | /* NEC standard (16 bit) */ |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 1609 | rc_code = RC_SCANCODE_NEC(buf[0], buf[2]); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1610 | } else { |
| 1611 | /* NEC extended (24 bit) */ |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 1612 | rc_code = RC_SCANCODE_NECX(buf[0] << 8 | buf[1], |
| 1613 | buf[2]); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1614 | } |
| 1615 | } else { |
| 1616 | /* NEC full (32 bit) */ |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 1617 | rc_code = RC_SCANCODE_NEC32(buf[0] << 24 | buf[1] << 16 | |
| 1618 | buf[2] << 8 | buf[3]); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1619 | } |
| 1620 | |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 1621 | rc_keydown(d->rc_dev, RC_TYPE_NEC, rc_code, 0); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1622 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1623 | ret = rtl28xxu_wr_reg(d, SYS_IRRC_SR, 1); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1624 | if (ret) |
| 1625 | goto err; |
| 1626 | |
| 1627 | /* repeated intentionally to avoid extra keypress */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1628 | ret = rtl28xxu_wr_reg(d, SYS_IRRC_SR, 1); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1629 | if (ret) |
| 1630 | goto err; |
| 1631 | } |
| 1632 | |
| 1633 | return ret; |
| 1634 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1635 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1636 | return ret; |
| 1637 | } |
| 1638 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1639 | static int rtl2831u_get_rc_config(struct dvb_usb_device *d, |
| 1640 | struct dvb_usb_rc *rc) |
| 1641 | { |
| 1642 | rc->map_name = RC_MAP_EMPTY; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 1643 | rc->allowed_protos = RC_BIT_NEC; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1644 | rc->query = rtl2831u_rc_query; |
| 1645 | rc->interval = 400; |
| 1646 | |
| 1647 | return 0; |
| 1648 | } |
| 1649 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1650 | static int rtl2832u_rc_query(struct dvb_usb_device *d) |
| 1651 | { |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1652 | int ret, i, len; |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1653 | struct rtl28xxu_dev *dev = d->priv; |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1654 | struct ir_raw_event ev; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1655 | u8 buf[128]; |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1656 | static const struct rtl28xxu_reg_val_mask refresh_tab[] = { |
| 1657 | {IR_RX_IF, 0x03, 0xff}, |
| 1658 | {IR_RX_BUF_CTRL, 0x80, 0xff}, |
| 1659 | {IR_RX_CTRL, 0x80, 0xff}, |
| 1660 | }; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1661 | |
| 1662 | /* init remote controller */ |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1663 | if (!dev->rc_active) { |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1664 | static const struct rtl28xxu_reg_val_mask init_tab[] = { |
| 1665 | {SYS_DEMOD_CTL1, 0x00, 0x04}, |
| 1666 | {SYS_DEMOD_CTL1, 0x00, 0x08}, |
| 1667 | {USB_CTRL, 0x20, 0x20}, |
| 1668 | {SYS_GPIO_DIR, 0x00, 0x08}, |
| 1669 | {SYS_GPIO_OUT_EN, 0x08, 0x08}, |
| 1670 | {SYS_GPIO_OUT_VAL, 0x08, 0x08}, |
| 1671 | {IR_MAX_DURATION0, 0xd0, 0xff}, |
| 1672 | {IR_MAX_DURATION1, 0x07, 0xff}, |
| 1673 | {IR_IDLE_LEN0, 0xc0, 0xff}, |
| 1674 | {IR_IDLE_LEN1, 0x00, 0xff}, |
| 1675 | {IR_GLITCH_LEN, 0x03, 0xff}, |
| 1676 | {IR_RX_CLK, 0x09, 0xff}, |
| 1677 | {IR_RX_CFG, 0x1c, 0xff}, |
| 1678 | {IR_MAX_H_TOL_LEN, 0x1e, 0xff}, |
| 1679 | {IR_MAX_L_TOL_LEN, 0x1e, 0xff}, |
| 1680 | {IR_RX_CTRL, 0x80, 0xff}, |
| 1681 | }; |
| 1682 | |
| 1683 | for (i = 0; i < ARRAY_SIZE(init_tab); i++) { |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1684 | ret = rtl28xxu_wr_reg_mask(d, init_tab[i].reg, |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1685 | init_tab[i].val, init_tab[i].mask); |
Rodrigo Tartajo | 1e41413 | 2013-04-20 20:02:12 -0300 | [diff] [blame] | 1686 | if (ret) |
| 1687 | goto err; |
| 1688 | } |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1689 | |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1690 | dev->rc_active = true; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1691 | } |
| 1692 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1693 | ret = rtl28xxu_rd_reg(d, IR_RX_IF, &buf[0]); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1694 | if (ret) |
| 1695 | goto err; |
| 1696 | |
| 1697 | if (buf[0] != 0x83) |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1698 | goto exit; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1699 | |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1700 | ret = rtl28xxu_rd_reg(d, IR_RX_BC, &buf[0]); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1701 | if (ret) |
| 1702 | goto err; |
| 1703 | |
| 1704 | len = buf[0]; |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1705 | |
| 1706 | /* read raw code from hw */ |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1707 | ret = rtl28xxu_rd_regs(d, IR_RX_BUF, buf, len); |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1708 | if (ret) |
| 1709 | goto err; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1710 | |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1711 | /* let hw receive new code */ |
| 1712 | for (i = 0; i < ARRAY_SIZE(refresh_tab); i++) { |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1713 | ret = rtl28xxu_wr_reg_mask(d, refresh_tab[i].reg, |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1714 | refresh_tab[i].val, refresh_tab[i].mask); |
Rodrigo Tartajo | 1e41413 | 2013-04-20 20:02:12 -0300 | [diff] [blame] | 1715 | if (ret) |
| 1716 | goto err; |
| 1717 | } |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1718 | |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1719 | /* pass data to Kernel IR decoder */ |
| 1720 | init_ir_raw_event(&ev); |
| 1721 | |
| 1722 | for (i = 0; i < len; i++) { |
| 1723 | ev.pulse = buf[i] >> 7; |
| 1724 | ev.duration = 50800 * (buf[i] & 0x7f); |
| 1725 | ir_raw_event_store_with_filter(d->rc_dev, &ev); |
| 1726 | } |
| 1727 | |
| 1728 | /* 'flush' ir_raw_event_store_with_filter() */ |
| 1729 | ir_raw_event_set_idle(d->rc_dev, true); |
| 1730 | ir_raw_event_handle(d->rc_dev); |
| 1731 | exit: |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1732 | return ret; |
| 1733 | err: |
Antti Palosaari | 5ba4ca1 | 2014-12-21 11:25:57 -0300 | [diff] [blame] | 1734 | dev_dbg(&d->intf->dev, "failed=%d\n", ret); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1735 | return ret; |
| 1736 | } |
| 1737 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1738 | static int rtl2832u_get_rc_config(struct dvb_usb_device *d, |
| 1739 | struct dvb_usb_rc *rc) |
| 1740 | { |
Antti Palosaari | 94b5fa6 | 2013-11-22 14:20:14 -0300 | [diff] [blame] | 1741 | /* disable IR interrupts in order to avoid SDR sample loss */ |
| 1742 | if (rtl28xxu_disable_rc) |
Antti Palosaari | 670ef05 | 2014-12-23 14:32:35 -0300 | [diff] [blame] | 1743 | return rtl28xxu_wr_reg(d, IR_RX_IE, 0x00); |
Antti Palosaari | 94b5fa6 | 2013-11-22 14:20:14 -0300 | [diff] [blame] | 1744 | |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1745 | /* load empty to enable rc */ |
| 1746 | if (!rc->map_name) |
| 1747 | rc->map_name = RC_MAP_EMPTY; |
Rodrigo Tartajo | 1e41413 | 2013-04-20 20:02:12 -0300 | [diff] [blame] | 1748 | rc->allowed_protos = RC_BIT_ALL; |
Antti Palosaari | f39fac3 | 2013-06-04 09:17:03 -0300 | [diff] [blame] | 1749 | rc->driver_type = RC_DRIVER_IR_RAW; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1750 | rc->query = rtl2832u_rc_query; |
Benjamin Larsson | 46cf707 | 2015-03-15 19:57:48 -0300 | [diff] [blame] | 1751 | rc->interval = 200; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1752 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1753 | return 0; |
| 1754 | } |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1755 | |
| 1756 | static int rtl28xxu_get_rc_config(struct dvb_usb_device *d, |
| 1757 | struct dvb_usb_rc *rc) |
| 1758 | { |
| 1759 | struct rtl28xxu_dev *dev = d_to_priv(d); |
| 1760 | |
| 1761 | if (dev->chip_id == CHIP_ID_RTL2831U) |
| 1762 | return rtl2831u_get_rc_config(d, rc); |
| 1763 | else |
| 1764 | return rtl2832u_get_rc_config(d, rc); |
| 1765 | } |
Antti Palosaari | cedda37 | 2012-12-09 20:06:00 -0300 | [diff] [blame] | 1766 | #else |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1767 | #define rtl28xxu_get_rc_config NULL |
Antti Palosaari | cedda37 | 2012-12-09 20:06:00 -0300 | [diff] [blame] | 1768 | #endif |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1769 | |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1770 | static int rtl28xxu_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff) |
Antti Palosaari | d9bd3fa | 2014-12-09 16:10:14 -0300 | [diff] [blame] | 1771 | { |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1772 | struct rtl28xxu_dev *dev = adap_to_priv(adap); |
Antti Palosaari | d9bd3fa | 2014-12-09 16:10:14 -0300 | [diff] [blame] | 1773 | |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1774 | if (dev->chip_id == CHIP_ID_RTL2831U) { |
| 1775 | struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data; |
| 1776 | |
| 1777 | return pdata->pid_filter_ctrl(adap->fe[0], onoff); |
| 1778 | } else { |
| 1779 | struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data; |
| 1780 | |
| 1781 | return pdata->pid_filter_ctrl(adap->fe[0], onoff); |
| 1782 | } |
Antti Palosaari | d9bd3fa | 2014-12-09 16:10:14 -0300 | [diff] [blame] | 1783 | } |
| 1784 | |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1785 | static int rtl28xxu_pid_filter(struct dvb_usb_adapter *adap, int index, |
| 1786 | u16 pid, int onoff) |
Antti Palosaari | e20b0cf | 2014-12-14 14:10:47 -0300 | [diff] [blame] | 1787 | { |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1788 | struct rtl28xxu_dev *dev = adap_to_priv(adap); |
Antti Palosaari | e20b0cf | 2014-12-14 14:10:47 -0300 | [diff] [blame] | 1789 | |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1790 | if (dev->chip_id == CHIP_ID_RTL2831U) { |
| 1791 | struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data; |
Antti Palosaari | e20b0cf | 2014-12-14 14:10:47 -0300 | [diff] [blame] | 1792 | |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1793 | return pdata->pid_filter(adap->fe[0], index, pid, onoff); |
| 1794 | } else { |
| 1795 | struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data; |
Antti Palosaari | d9bd3fa | 2014-12-09 16:10:14 -0300 | [diff] [blame] | 1796 | |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1797 | return pdata->pid_filter(adap->fe[0], index, pid, onoff); |
| 1798 | } |
Antti Palosaari | e20b0cf | 2014-12-14 14:10:47 -0300 | [diff] [blame] | 1799 | } |
| 1800 | |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1801 | static const struct dvb_usb_device_properties rtl28xxu_props = { |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1802 | .driver_name = KBUILD_MODNAME, |
| 1803 | .owner = THIS_MODULE, |
| 1804 | .adapter_nr = adapter_nr, |
Antti Palosaari | 9a02e8f | 2014-12-18 08:05:23 -0300 | [diff] [blame] | 1805 | .size_of_priv = sizeof(struct rtl28xxu_dev), |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1806 | |
Antti Palosaari | d0f232e | 2014-12-23 13:14:36 -0300 | [diff] [blame] | 1807 | .identify_state = rtl28xxu_identify_state, |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1808 | .power_ctrl = rtl28xxu_power_ctrl, |
| 1809 | .frontend_ctrl = rtl28xxu_frontend_ctrl, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1810 | .i2c_algo = &rtl28xxu_i2c_algo, |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1811 | .read_config = rtl28xxu_read_config, |
| 1812 | .frontend_attach = rtl28xxu_frontend_attach, |
| 1813 | .frontend_detach = rtl28xxu_frontend_detach, |
| 1814 | .tuner_attach = rtl28xxu_tuner_attach, |
| 1815 | .tuner_detach = rtl28xxu_tuner_detach, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1816 | .init = rtl28xxu_init, |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1817 | .get_rc_config = rtl28xxu_get_rc_config, |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1818 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1819 | .num_adapters = 1, |
| 1820 | .adapter = { |
| 1821 | { |
Antti Palosaari | e20b0cf | 2014-12-14 14:10:47 -0300 | [diff] [blame] | 1822 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | |
| 1823 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, |
| 1824 | |
| 1825 | .pid_filter_count = 32, |
Antti Palosaari | de701f0 | 2014-12-23 14:09:13 -0300 | [diff] [blame] | 1826 | .pid_filter_ctrl = rtl28xxu_pid_filter_ctrl, |
| 1827 | .pid_filter = rtl28xxu_pid_filter, |
Antti Palosaari | e20b0cf | 2014-12-14 14:10:47 -0300 | [diff] [blame] | 1828 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1829 | .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512), |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1830 | }, |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1831 | }, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1832 | }; |
| 1833 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1834 | static const struct usb_device_id rtl28xxu_id_table[] = { |
Jan Vcelak | 60aa4c6 | 2014-02-26 15:33:40 -0300 | [diff] [blame] | 1835 | /* RTL2831U devices: */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1836 | { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1837 | &rtl28xxu_props, "Realtek RTL2831U reference design", NULL) }, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1838 | { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1839 | &rtl28xxu_props, "Freecom USB2.0 DVB-T", NULL) }, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1840 | { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1841 | &rtl28xxu_props, "Freecom USB2.0 DVB-T", NULL) }, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1842 | |
Jan Vcelak | 60aa4c6 | 2014-02-26 15:33:40 -0300 | [diff] [blame] | 1843 | /* RTL2832U devices: */ |
Antti Palosaari | 254ee2e | 2012-09-18 10:27:05 -0300 | [diff] [blame] | 1844 | { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2832, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1845 | &rtl28xxu_props, "Realtek RTL2832U reference design", NULL) }, |
Antti Palosaari | 254ee2e | 2012-09-18 10:27:05 -0300 | [diff] [blame] | 1846 | { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1847 | &rtl28xxu_props, "Realtek RTL2832U reference design", NULL) }, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1848 | { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1849 | &rtl28xxu_props, "TerraTec Cinergy T Stick Black", RC_MAP_TERRATEC_SLIM) }, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1850 | { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1851 | &rtl28xxu_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) }, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1852 | { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1853 | &rtl28xxu_props, "TerraTec NOXON DAB Stick", NULL) }, |
Juergen Lock | e9de051 | 2012-11-13 14:09:28 -0300 | [diff] [blame] | 1854 | { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV2, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1855 | &rtl28xxu_props, "TerraTec NOXON DAB Stick (rev 2)", NULL) }, |
Till Dörges | a24bc32 | 2014-02-11 17:27:57 -0300 | [diff] [blame] | 1856 | { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV3, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1857 | &rtl28xxu_props, "TerraTec NOXON DAB Stick (rev 3)", NULL) }, |
Philipp Dreimann | 6d60805 | 2012-09-02 19:30:54 -0300 | [diff] [blame] | 1858 | { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1859 | &rtl28xxu_props, "Trekstor DVB-T Stick Terres 2.0", NULL) }, |
Antti Palosaari | c2d246d1 | 2012-09-08 22:07:26 -0300 | [diff] [blame] | 1860 | { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1861 | &rtl28xxu_props, "Dexatek DK DVB-T Dongle", NULL) }, |
Antti Palosaari | 3d8866d | 2012-09-20 18:34:50 -0300 | [diff] [blame] | 1862 | { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6680, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1863 | &rtl28xxu_props, "DigitalNow Quad DVB-T Receiver", NULL) }, |
Robert Backhaus | d22d32e | 2013-12-13 09:59:10 -0300 | [diff] [blame] | 1864 | { DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_MINID, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1865 | &rtl28xxu_props, "Leadtek Winfast DTV Dongle Mini D", NULL) }, |
Christian Dale | 09f5012 | 2015-03-09 02:19:01 -0300 | [diff] [blame] | 1866 | { DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV2000DS_PLUS, |
| 1867 | &rtl28xxu_props, "Leadtek WinFast DTV2000DS Plus", RC_MAP_LEADTEK_Y04G0051) }, |
Antti Palosaari | a4f6440 | 2012-09-29 15:28:56 -0300 | [diff] [blame] | 1868 | { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d3, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1869 | &rtl28xxu_props, "TerraTec Cinergy T Stick RC (Rev. 3)", NULL) }, |
Antti Palosaari | 08e5727 | 2012-11-06 16:03:35 -0300 | [diff] [blame] | 1870 | { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1102, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1871 | &rtl28xxu_props, "Dexatek DK mini DVB-T Dongle", NULL) }, |
Andrew Karpow | 86163ad | 2012-11-06 20:01:16 -0300 | [diff] [blame] | 1872 | { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d7, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1873 | &rtl28xxu_props, "TerraTec Cinergy T Stick+", NULL) }, |
Antti Palosaari | 3971e79 | 2012-12-16 11:47:07 -0300 | [diff] [blame] | 1874 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd3a8, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1875 | &rtl28xxu_props, "ASUS My Cinema-U3100Mini Plus V2", NULL) }, |
Alexander Inyukhin | 78a5e70 | 2013-01-04 18:19:02 -0300 | [diff] [blame] | 1876 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd393, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1877 | &rtl28xxu_props, "GIGABYTE U7300", NULL) }, |
Eddi De Pieri | 09f9408 | 2013-01-14 18:21:32 -0300 | [diff] [blame] | 1878 | { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1104, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1879 | &rtl28xxu_props, "MSI DIGIVOX Micro HD", NULL) }, |
Alistair Buxton | b9e2aff | 2013-02-12 21:58:47 -0300 | [diff] [blame] | 1880 | { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1881 | &rtl28xxu_props, "Compro VideoMate U620F", NULL) }, |
Fabrizio Gazzato | e6a60d7 | 2013-02-15 18:54:54 -0300 | [diff] [blame] | 1882 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1883 | &rtl28xxu_props, "MaxMedia HU394-T", NULL) }, |
Miroslav Šustek | 6c5a406 | 2013-05-14 19:42:11 -0300 | [diff] [blame] | 1884 | { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1885 | &rtl28xxu_props, "Leadtek WinFast DTV Dongle mini", NULL) }, |
Alessandro Miceli | c6be752 | 2013-06-04 16:10:34 -0300 | [diff] [blame] | 1886 | { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1887 | &rtl28xxu_props, "Crypto ReDi PC 50 A", NULL) }, |
Jan Vcelak | ac298cc | 2014-02-26 15:33:39 -0300 | [diff] [blame] | 1888 | { DVB_USB_DEVICE(USB_VID_KYE, 0x707f, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1889 | &rtl28xxu_props, "Genius TVGo DVB-T03", NULL) }, |
Brian Healy | 9ca24ae | 2014-05-04 18:43:39 -0300 | [diff] [blame] | 1890 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd395, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1891 | &rtl28xxu_props, "Peak DVB-T USB", NULL) }, |
Alessandro Miceli | f27f5b0 | 2014-05-04 07:37:15 -0300 | [diff] [blame] | 1892 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20_RTL2832U, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1893 | &rtl28xxu_props, "Sveon STV20", NULL) }, |
Sebastian | 89c5ff0 | 2014-06-12 03:22:45 -0300 | [diff] [blame] | 1894 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV21, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1895 | &rtl28xxu_props, "Sveon STV21", NULL) }, |
Alessandro Miceli | 74a8627 | 2014-05-04 07:50:31 -0300 | [diff] [blame] | 1896 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV27, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1897 | &rtl28xxu_props, "Sveon STV27", NULL) }, |
Dimitris Lampridis | 882302c | 2015-02-14 11:11:34 -0300 | [diff] [blame] | 1898 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TURBOX_DTT_2000, |
| 1899 | &rtl28xxu_props, "TURBO-X Pure TV Tuner DTT-2000", NULL) }, |
Antti Palosaari | 8fdd33b | 2013-10-30 02:33:42 -0300 | [diff] [blame] | 1900 | |
Jan Vcelak | 60aa4c6 | 2014-02-26 15:33:40 -0300 | [diff] [blame] | 1901 | /* RTL2832P devices: */ |
Antti Palosaari | 8fdd33b | 2013-10-30 02:33:42 -0300 | [diff] [blame] | 1902 | { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131, |
Antti Palosaari | 723abfd | 2014-12-23 14:21:10 -0300 | [diff] [blame] | 1903 | &rtl28xxu_props, "Astrometa DVB-T2", NULL) }, |
Olli Salonen | 699dcff | 2015-05-05 13:54:19 -0300 | [diff] [blame] | 1904 | { DVB_USB_DEVICE(0x5654, 0xca42, |
| 1905 | &rtl28xxu_props, "GoTView MasterHD 3", NULL) }, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1906 | { } |
| 1907 | }; |
| 1908 | MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1909 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1910 | static struct usb_driver rtl28xxu_usb_driver = { |
| 1911 | .name = KBUILD_MODNAME, |
| 1912 | .id_table = rtl28xxu_id_table, |
| 1913 | .probe = dvb_usbv2_probe, |
| 1914 | .disconnect = dvb_usbv2_disconnect, |
| 1915 | .suspend = dvb_usbv2_suspend, |
| 1916 | .resume = dvb_usbv2_resume, |
Antti Palosaari | 78fa590 | 2012-08-14 22:21:09 -0300 | [diff] [blame] | 1917 | .reset_resume = dvb_usbv2_reset_resume, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1918 | .no_dynamic_id = 1, |
| 1919 | .soft_unbind = 1, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1920 | }; |
| 1921 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1922 | module_usb_driver(rtl28xxu_usb_driver); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1923 | |
| 1924 | MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver"); |
| 1925 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1926 | MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>"); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1927 | MODULE_LICENSE("GPL"); |