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