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