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