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