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 | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 277 | static int rtl2832u_read_config(struct dvb_usb_device *d) |
| 278 | { |
| 279 | struct rtl28xxu_priv *priv = d_to_priv(d); |
| 280 | int ret; |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame^] | 281 | u8 buf[2]; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 282 | /* open RTL2832U/RTL2832 I2C gate */ |
| 283 | struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"}; |
| 284 | /* close RTL2832U/RTL2832 I2C gate */ |
| 285 | struct rtl28xxu_req req_gate_close = {0x0120, 0x0011, 0x0001, "\x10"}; |
| 286 | /* tuner probes */ |
| 287 | struct rtl28xxu_req req_fc0012 = {0x00c6, CMD_I2C_RD, 1, buf}; |
| 288 | struct rtl28xxu_req req_fc0013 = {0x00c6, CMD_I2C_RD, 1, buf}; |
| 289 | struct rtl28xxu_req req_mt2266 = {0x00c0, CMD_I2C_RD, 1, buf}; |
| 290 | struct rtl28xxu_req req_fc2580 = {0x01ac, CMD_I2C_RD, 1, buf}; |
| 291 | struct rtl28xxu_req req_mt2063 = {0x00c0, CMD_I2C_RD, 1, buf}; |
| 292 | struct rtl28xxu_req req_max3543 = {0x00c0, CMD_I2C_RD, 1, buf}; |
| 293 | struct rtl28xxu_req req_tua9001 = {0x7ec0, CMD_I2C_RD, 2, buf}; |
| 294 | struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf}; |
| 295 | struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf}; |
| 296 | struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf}; |
| 297 | |
| 298 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
| 299 | |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame^] | 300 | /* enable GPIO3 and GPIO6 as output */ |
| 301 | ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x40); |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 302 | if (ret) |
| 303 | goto err; |
| 304 | |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame^] | 305 | ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x48, 0x48); |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 306 | if (ret) |
| 307 | goto err; |
| 308 | |
| 309 | /* |
| 310 | * Probe used tuner. We need to know used tuner before demod attach |
| 311 | * since there is some demod params needed to set according to tuner. |
| 312 | */ |
| 313 | |
| 314 | /* open demod I2C gate */ |
| 315 | ret = rtl28xxu_ctrl_msg(d, &req_gate_open); |
| 316 | if (ret) |
| 317 | goto err; |
| 318 | |
| 319 | priv->tuner_name = "NONE"; |
| 320 | |
| 321 | /* check FC0012 ID register; reg=00 val=a1 */ |
| 322 | ret = rtl28xxu_ctrl_msg(d, &req_fc0012); |
| 323 | if (ret == 0 && buf[0] == 0xa1) { |
| 324 | priv->tuner = TUNER_RTL2832_FC0012; |
| 325 | priv->tuner_name = "FC0012"; |
| 326 | goto found; |
| 327 | } |
| 328 | |
| 329 | /* check FC0013 ID register; reg=00 val=a3 */ |
| 330 | ret = rtl28xxu_ctrl_msg(d, &req_fc0013); |
| 331 | if (ret == 0 && buf[0] == 0xa3) { |
| 332 | priv->tuner = TUNER_RTL2832_FC0013; |
| 333 | priv->tuner_name = "FC0013"; |
| 334 | goto found; |
| 335 | } |
| 336 | |
| 337 | /* check MT2266 ID register; reg=00 val=85 */ |
| 338 | ret = rtl28xxu_ctrl_msg(d, &req_mt2266); |
| 339 | if (ret == 0 && buf[0] == 0x85) { |
| 340 | priv->tuner = TUNER_RTL2832_MT2266; |
| 341 | priv->tuner_name = "MT2266"; |
| 342 | goto found; |
| 343 | } |
| 344 | |
| 345 | /* check FC2580 ID register; reg=01 val=56 */ |
| 346 | ret = rtl28xxu_ctrl_msg(d, &req_fc2580); |
| 347 | if (ret == 0 && buf[0] == 0x56) { |
| 348 | priv->tuner = TUNER_RTL2832_FC2580; |
| 349 | priv->tuner_name = "FC2580"; |
| 350 | goto found; |
| 351 | } |
| 352 | |
| 353 | /* check MT2063 ID register; reg=00 val=9e || 9c */ |
| 354 | ret = rtl28xxu_ctrl_msg(d, &req_mt2063); |
| 355 | if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) { |
| 356 | priv->tuner = TUNER_RTL2832_MT2063; |
| 357 | priv->tuner_name = "MT2063"; |
| 358 | goto found; |
| 359 | } |
| 360 | |
| 361 | /* check MAX3543 ID register; reg=00 val=38 */ |
| 362 | ret = rtl28xxu_ctrl_msg(d, &req_max3543); |
| 363 | if (ret == 0 && buf[0] == 0x38) { |
| 364 | priv->tuner = TUNER_RTL2832_MAX3543; |
| 365 | priv->tuner_name = "MAX3543"; |
| 366 | goto found; |
| 367 | } |
| 368 | |
| 369 | /* check TUA9001 ID register; reg=7e val=2328 */ |
| 370 | ret = rtl28xxu_ctrl_msg(d, &req_tua9001); |
| 371 | if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) { |
| 372 | priv->tuner = TUNER_RTL2832_TUA9001; |
| 373 | priv->tuner_name = "TUA9001"; |
| 374 | goto found; |
| 375 | } |
| 376 | |
| 377 | /* check MXL5007R ID register; reg=d9 val=14 */ |
| 378 | ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t); |
| 379 | if (ret == 0 && buf[0] == 0x14) { |
| 380 | priv->tuner = TUNER_RTL2832_MXL5007T; |
| 381 | priv->tuner_name = "MXL5007T"; |
| 382 | goto found; |
| 383 | } |
| 384 | |
| 385 | /* check E4000 ID register; reg=02 val=40 */ |
| 386 | ret = rtl28xxu_ctrl_msg(d, &req_e4000); |
| 387 | if (ret == 0 && buf[0] == 0x40) { |
| 388 | priv->tuner = TUNER_RTL2832_E4000; |
| 389 | priv->tuner_name = "E4000"; |
| 390 | goto found; |
| 391 | } |
| 392 | |
| 393 | /* check TDA18272 ID register; reg=00 val=c760 */ |
| 394 | ret = rtl28xxu_ctrl_msg(d, &req_tda18272); |
| 395 | if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) { |
| 396 | priv->tuner = TUNER_RTL2832_TDA18272; |
| 397 | priv->tuner_name = "TDA18272"; |
| 398 | goto found; |
| 399 | } |
| 400 | |
| 401 | found: |
| 402 | dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name); |
| 403 | |
| 404 | /* close demod I2C gate */ |
| 405 | ret = rtl28xxu_ctrl_msg(d, &req_gate_close); |
| 406 | if (ret < 0) |
| 407 | goto err; |
| 408 | |
| 409 | return 0; |
| 410 | err: |
| 411 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 412 | return ret; |
| 413 | } |
| 414 | |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 415 | static struct rtl2830_config rtl28xxu_rtl2830_mt2060_config = { |
| 416 | .i2c_addr = 0x10, /* 0x20 */ |
| 417 | .xtal = 28800000, |
| 418 | .ts_mode = 0, |
| 419 | .spec_inv = 1, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 420 | .vtop = 0x20, |
| 421 | .krf = 0x04, |
| 422 | .agc_targ_val = 0x2d, |
| 423 | |
| 424 | }; |
| 425 | |
| 426 | static struct rtl2830_config rtl28xxu_rtl2830_qt1010_config = { |
| 427 | .i2c_addr = 0x10, /* 0x20 */ |
| 428 | .xtal = 28800000, |
| 429 | .ts_mode = 0, |
| 430 | .spec_inv = 1, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 431 | .vtop = 0x20, |
| 432 | .krf = 0x04, |
| 433 | .agc_targ_val = 0x2d, |
| 434 | }; |
| 435 | |
| 436 | static struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = { |
| 437 | .i2c_addr = 0x10, /* 0x20 */ |
| 438 | .xtal = 28800000, |
| 439 | .ts_mode = 0, |
| 440 | .spec_inv = 0, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 441 | .vtop = 0x3f, |
| 442 | .krf = 0x04, |
| 443 | .agc_targ_val = 0x3e, |
| 444 | }; |
| 445 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 446 | static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 447 | { |
| 448 | int ret; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 449 | struct dvb_usb_device *d = adap_to_d(adap); |
| 450 | struct rtl28xxu_priv *priv = d_to_priv(d); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 451 | u8 buf[1]; |
| 452 | struct rtl2830_config *rtl2830_config; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 453 | /* open RTL2831U/RTL2830 I2C gate */ |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 454 | struct rtl28xxu_req req_gate = { 0x0120, 0x0011, 0x0001, "\x08" }; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 455 | /* for MT2060 tuner probe */ |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 456 | struct rtl28xxu_req req_mt2060 = { 0x00c0, CMD_I2C_RD, 1, buf }; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 457 | /* for QT1010 tuner probe */ |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 458 | struct rtl28xxu_req req_qt1010 = { 0x0fc4, CMD_I2C_RD, 1, buf }; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 459 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 460 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 461 | |
| 462 | /* |
| 463 | * RTL2831U GPIOs |
| 464 | * ========================================================= |
| 465 | * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?) |
| 466 | * GPIO2 | LED | 0 off | 1 on | |
| 467 | * GPIO4 | tuner#1 | 0 on | 1 off | MT2060 |
| 468 | */ |
| 469 | |
| 470 | /* GPIO direction */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 471 | ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, 0x0a); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 472 | if (ret) |
| 473 | goto err; |
| 474 | |
| 475 | /* enable as output GPIO0, GPIO2, GPIO4 */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 476 | ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, 0x15); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 477 | if (ret) |
| 478 | goto err; |
| 479 | |
| 480 | /* |
| 481 | * Probe used tuner. We need to know used tuner before demod attach |
| 482 | * since there is some demod params needed to set according to tuner. |
| 483 | */ |
| 484 | |
Antti Palosaari | ccb5cf9 | 2012-05-18 16:07:46 -0300 | [diff] [blame] | 485 | /* demod needs some time to wake up */ |
| 486 | msleep(20); |
| 487 | |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 488 | /* open demod I2C gate */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 489 | ret = rtl28xxu_ctrl_msg(d, &req_gate); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 490 | if (ret) |
| 491 | goto err; |
| 492 | |
| 493 | /* check QT1010 ID(?) register; reg=0f val=2c */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 494 | ret = rtl28xxu_ctrl_msg(d, &req_qt1010); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 495 | if (ret == 0 && buf[0] == 0x2c) { |
| 496 | priv->tuner = TUNER_RTL2830_QT1010; |
| 497 | rtl2830_config = &rtl28xxu_rtl2830_qt1010_config; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 498 | dev_dbg(&d->udev->dev, "%s: QT1010\n", __func__); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 499 | goto found; |
| 500 | } else { |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 501 | dev_dbg(&d->udev->dev, "%s: QT1010 probe failed=%d - %02x\n", |
| 502 | __func__, ret, buf[0]); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /* open demod I2C gate */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 506 | ret = rtl28xxu_ctrl_msg(d, &req_gate); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 507 | if (ret) |
| 508 | goto err; |
| 509 | |
| 510 | /* check MT2060 ID register; reg=00 val=63 */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 511 | ret = rtl28xxu_ctrl_msg(d, &req_mt2060); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 512 | if (ret == 0 && buf[0] == 0x63) { |
| 513 | priv->tuner = TUNER_RTL2830_MT2060; |
| 514 | rtl2830_config = &rtl28xxu_rtl2830_mt2060_config; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 515 | dev_dbg(&d->udev->dev, "%s: MT2060\n", __func__); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 516 | goto found; |
| 517 | } else { |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 518 | dev_dbg(&d->udev->dev, "%s: MT2060 probe failed=%d - %02x\n", |
| 519 | __func__, ret, buf[0]); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | /* assume MXL5005S */ |
Antti Palosaari | e9320ec | 2011-08-03 04:35:30 -0300 | [diff] [blame] | 523 | ret = 0; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 524 | priv->tuner = TUNER_RTL2830_MXL5005S; |
| 525 | rtl2830_config = &rtl28xxu_rtl2830_mxl5005s_config; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 526 | dev_dbg(&d->udev->dev, "%s: MXL5005S\n", __func__); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 527 | goto found; |
| 528 | |
| 529 | found: |
| 530 | /* attach demodulator */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 531 | adap->fe[0] = dvb_attach(rtl2830_attach, rtl2830_config, |
| 532 | &d->i2c_adap); |
| 533 | if (adap->fe[0] == NULL) { |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 534 | ret = -ENODEV; |
| 535 | goto err; |
| 536 | } |
| 537 | |
| 538 | return ret; |
| 539 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 540 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 541 | return ret; |
| 542 | } |
| 543 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 544 | static struct rtl2832_config rtl28xxu_rtl2832_fc0012_config = { |
| 545 | .i2c_addr = 0x10, /* 0x20 */ |
| 546 | .xtal = 28800000, |
| 547 | .if_dvbt = 0, |
| 548 | .tuner = TUNER_RTL2832_FC0012 |
| 549 | }; |
| 550 | |
| 551 | static struct rtl2832_config rtl28xxu_rtl2832_fc0013_config = { |
| 552 | .i2c_addr = 0x10, /* 0x20 */ |
| 553 | .xtal = 28800000, |
| 554 | .if_dvbt = 0, |
| 555 | .tuner = TUNER_RTL2832_FC0013 |
| 556 | }; |
| 557 | |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 558 | static struct rtl2832_config rtl28xxu_rtl2832_tua9001_config = { |
| 559 | .i2c_addr = 0x10, /* 0x20 */ |
| 560 | .xtal = 28800000, |
| 561 | .tuner = TUNER_RTL2832_TUA9001, |
| 562 | }; |
| 563 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 564 | static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d, |
| 565 | int cmd, int arg) |
| 566 | { |
| 567 | int ret; |
| 568 | u8 val; |
| 569 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 570 | dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg); |
| 571 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 572 | switch (cmd) { |
| 573 | case FC_FE_CALLBACK_VHF_ENABLE: |
| 574 | /* set output values */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 575 | ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 576 | if (ret) |
| 577 | goto err; |
| 578 | |
| 579 | if (arg) |
| 580 | val &= 0xbf; /* set GPIO6 low */ |
| 581 | else |
| 582 | val |= 0x40; /* set GPIO6 high */ |
| 583 | |
| 584 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 585 | ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 586 | if (ret) |
| 587 | goto err; |
| 588 | break; |
| 589 | default: |
| 590 | ret = -EINVAL; |
| 591 | goto err; |
| 592 | } |
| 593 | return 0; |
| 594 | |
| 595 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 596 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 597 | return ret; |
| 598 | } |
| 599 | |
| 600 | |
| 601 | static int rtl2832u_fc0013_tuner_callback(struct dvb_usb_device *d, |
| 602 | int cmd, int arg) |
| 603 | { |
| 604 | /* TODO implement*/ |
| 605 | return 0; |
| 606 | } |
| 607 | |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 608 | static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d, |
| 609 | int cmd, int arg) |
| 610 | { |
| 611 | int ret; |
| 612 | u8 val; |
| 613 | |
| 614 | dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg); |
| 615 | |
| 616 | /* |
| 617 | * CEN always enabled by hardware wiring |
| 618 | * RESETN GPIO4 |
| 619 | * RXEN GPIO1 |
| 620 | */ |
| 621 | |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 622 | switch (cmd) { |
| 623 | case TUA9001_CMD_RESETN: |
| 624 | if (arg) |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame^] | 625 | val = (1 << 4); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 626 | else |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame^] | 627 | val = (0 << 4); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 628 | |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame^] | 629 | ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x10); |
| 630 | if (ret) |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 631 | goto err; |
| 632 | break; |
| 633 | case TUA9001_CMD_RXEN: |
| 634 | if (arg) |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame^] | 635 | val = (1 << 1); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 636 | else |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame^] | 637 | val = (0 << 1); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 638 | |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame^] | 639 | ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x02); |
| 640 | if (ret) |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 641 | goto err; |
| 642 | break; |
| 643 | } |
| 644 | |
| 645 | return 0; |
| 646 | |
| 647 | err: |
| 648 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 649 | return ret; |
| 650 | } |
| 651 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 652 | static int rtl2832u_tuner_callback(struct dvb_usb_device *d, int cmd, int arg) |
| 653 | { |
| 654 | struct rtl28xxu_priv *priv = d->priv; |
| 655 | |
| 656 | switch (priv->tuner) { |
| 657 | case TUNER_RTL2832_FC0012: |
| 658 | return rtl2832u_fc0012_tuner_callback(d, cmd, arg); |
| 659 | |
| 660 | case TUNER_RTL2832_FC0013: |
| 661 | return rtl2832u_fc0013_tuner_callback(d, cmd, arg); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 662 | |
| 663 | case TUNER_RTL2832_TUA9001: |
| 664 | return rtl2832u_tua9001_tuner_callback(d, cmd, arg); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 665 | default: |
| 666 | break; |
| 667 | } |
| 668 | |
| 669 | return -ENODEV; |
| 670 | } |
| 671 | |
| 672 | static int rtl2832u_frontend_callback(void *adapter_priv, int component, |
| 673 | int cmd, int arg) |
| 674 | { |
| 675 | struct i2c_adapter *adap = adapter_priv; |
| 676 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 677 | |
| 678 | switch (component) { |
| 679 | case DVB_FRONTEND_COMPONENT_TUNER: |
| 680 | return rtl2832u_tuner_callback(d, cmd, arg); |
| 681 | default: |
| 682 | break; |
| 683 | } |
| 684 | |
| 685 | return -EINVAL; |
| 686 | } |
| 687 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 688 | static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap) |
| 689 | { |
| 690 | int ret; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 691 | struct dvb_usb_device *d = adap_to_d(adap); |
| 692 | struct rtl28xxu_priv *priv = d_to_priv(d); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 693 | struct rtl2832_config *rtl2832_config; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 694 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 695 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 696 | |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 697 | switch (priv->tuner) { |
| 698 | case TUNER_RTL2832_FC0012: |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 699 | rtl2832_config = &rtl28xxu_rtl2832_fc0012_config; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 700 | break; |
| 701 | case TUNER_RTL2832_FC0013: |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 702 | rtl2832_config = &rtl28xxu_rtl2832_fc0013_config; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 703 | break; |
| 704 | case TUNER_RTL2832_FC2580: |
Antti Palosaari | 384df49 | 2012-09-08 22:07:25 -0300 | [diff] [blame] | 705 | /* FIXME: do not abuse fc0012 settings */ |
| 706 | rtl2832_config = &rtl28xxu_rtl2832_fc0012_config; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 707 | break; |
| 708 | case TUNER_RTL2832_TUA9001: |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 709 | rtl2832_config = &rtl28xxu_rtl2832_tua9001_config; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 710 | break; |
| 711 | case TUNER_RTL2832_E4000: |
Antti Palosaari | 542f6a5 | 2012-09-01 21:09:22 -0300 | [diff] [blame] | 712 | /* FIXME: do not abuse fc0012 settings */ |
| 713 | rtl2832_config = &rtl28xxu_rtl2832_fc0012_config; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 714 | break; |
| 715 | default: |
| 716 | dev_err(&d->udev->dev, "%s: unknown tuner=%s\n", |
| 717 | KBUILD_MODNAME, priv->tuner_name); |
| 718 | ret = -ENODEV; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 719 | goto err; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 720 | } |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 721 | |
| 722 | /* attach demodulator */ |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 723 | adap->fe[0] = dvb_attach(rtl2832_attach, rtl2832_config, &d->i2c_adap); |
| 724 | if (!adap->fe[0]) { |
| 725 | ret = -ENODEV; |
| 726 | goto err; |
| 727 | } |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 728 | |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 729 | /* set fe callback */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 730 | adap->fe[0]->callback = rtl2832u_frontend_callback; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 731 | |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 732 | return 0; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 733 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 734 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 735 | return ret; |
| 736 | } |
| 737 | |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 738 | static struct qt1010_config rtl28xxu_qt1010_config = { |
| 739 | .i2c_address = 0x62, /* 0xc4 */ |
| 740 | }; |
| 741 | |
| 742 | static struct mt2060_config rtl28xxu_mt2060_config = { |
| 743 | .i2c_address = 0x60, /* 0xc0 */ |
| 744 | .clock_out = 0, |
| 745 | }; |
| 746 | |
| 747 | static struct mxl5005s_config rtl28xxu_mxl5005s_config = { |
| 748 | .i2c_address = 0x63, /* 0xc6 */ |
| 749 | .if_freq = IF_FREQ_4570000HZ, |
| 750 | .xtal_freq = CRYSTAL_FREQ_16000000HZ, |
| 751 | .agc_mode = MXL_SINGLE_AGC, |
| 752 | .tracking_filter = MXL_TF_C_H, |
| 753 | .rssi_enable = MXL_RSSI_ENABLE, |
| 754 | .cap_select = MXL_CAP_SEL_ENABLE, |
| 755 | .div_out = MXL_DIV_OUT_4, |
| 756 | .clock_out = MXL_CLOCK_OUT_DISABLE, |
| 757 | .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM, |
| 758 | .top = MXL5005S_TOP_25P2, |
| 759 | .mod_mode = MXL_DIGITAL_MODE, |
| 760 | .if_mode = MXL_ZERO_IF, |
| 761 | .AgcMasterByte = 0x00, |
| 762 | }; |
| 763 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 764 | static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 765 | { |
| 766 | int ret; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 767 | struct dvb_usb_device *d = adap_to_d(adap); |
| 768 | struct rtl28xxu_priv *priv = d_to_priv(d); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 769 | struct i2c_adapter *rtl2830_tuner_i2c; |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 770 | struct dvb_frontend *fe; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 771 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 772 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 773 | |
| 774 | /* use rtl2830 driver I2C adapter, for more info see rtl2830 driver */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 775 | rtl2830_tuner_i2c = rtl2830_get_tuner_i2c_adapter(adap->fe[0]); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 776 | |
| 777 | switch (priv->tuner) { |
| 778 | case TUNER_RTL2830_QT1010: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 779 | fe = dvb_attach(qt1010_attach, adap->fe[0], |
Antti Palosaari | fba16b1 | 2012-01-21 20:28:38 -0300 | [diff] [blame] | 780 | rtl2830_tuner_i2c, &rtl28xxu_qt1010_config); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 781 | break; |
| 782 | case TUNER_RTL2830_MT2060: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 783 | fe = dvb_attach(mt2060_attach, adap->fe[0], |
Antti Palosaari | fba16b1 | 2012-01-21 20:28:38 -0300 | [diff] [blame] | 784 | rtl2830_tuner_i2c, &rtl28xxu_mt2060_config, |
| 785 | 1220); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 786 | break; |
| 787 | case TUNER_RTL2830_MXL5005S: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 788 | fe = dvb_attach(mxl5005s_attach, adap->fe[0], |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 789 | rtl2830_tuner_i2c, &rtl28xxu_mxl5005s_config); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 790 | break; |
| 791 | default: |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 792 | fe = NULL; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 793 | dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME, |
| 794 | priv->tuner); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | if (fe == NULL) { |
| 798 | ret = -ENODEV; |
| 799 | goto err; |
| 800 | } |
| 801 | |
| 802 | return 0; |
| 803 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 804 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 805 | return ret; |
| 806 | } |
| 807 | |
Antti Palosaari | 542f6a5 | 2012-09-01 21:09:22 -0300 | [diff] [blame] | 808 | static const struct e4000_config rtl2832u_e4000_config = { |
| 809 | .i2c_addr = 0x64, |
| 810 | .clock = 28800000, |
| 811 | }; |
| 812 | |
Antti Palosaari | 384df49 | 2012-09-08 22:07:25 -0300 | [diff] [blame] | 813 | static const struct fc2580_config rtl2832u_fc2580_config = { |
| 814 | .i2c_addr = 0x56, |
| 815 | .clock = 16384000, |
| 816 | }; |
| 817 | |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 818 | static struct tua9001_config rtl2832u_tua9001_config = { |
| 819 | .i2c_addr = 0x60, |
| 820 | }; |
| 821 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 822 | static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap) |
| 823 | { |
| 824 | int ret; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 825 | struct dvb_usb_device *d = adap_to_d(adap); |
| 826 | struct rtl28xxu_priv *priv = d_to_priv(d); |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 827 | struct dvb_frontend *fe; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 828 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 829 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 830 | |
| 831 | switch (priv->tuner) { |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 832 | case TUNER_RTL2832_FC0012: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 833 | fe = dvb_attach(fc0012_attach, adap->fe[0], |
| 834 | &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 835 | |
| 836 | /* since fc0012 includs reading the signal strength delegate |
| 837 | * that to the tuner driver */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 838 | adap->fe[0]->ops.read_signal_strength = |
| 839 | adap->fe[0]->ops.tuner_ops.get_rf_strength; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 840 | return 0; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 841 | break; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 842 | case TUNER_RTL2832_FC0013: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 843 | fe = dvb_attach(fc0013_attach, adap->fe[0], |
| 844 | &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 845 | |
| 846 | /* fc0013 also supports signal strength reading */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 847 | adap->fe[0]->ops.read_signal_strength = |
| 848 | adap->fe[0]->ops.tuner_ops.get_rf_strength; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 849 | return 0; |
Antti Palosaari | 542f6a5 | 2012-09-01 21:09:22 -0300 | [diff] [blame] | 850 | case TUNER_RTL2832_E4000: |
| 851 | fe = dvb_attach(e4000_attach, adap->fe[0], &d->i2c_adap, |
| 852 | &rtl2832u_e4000_config); |
| 853 | break; |
Antti Palosaari | 384df49 | 2012-09-08 22:07:25 -0300 | [diff] [blame] | 854 | case TUNER_RTL2832_FC2580: |
| 855 | fe = dvb_attach(fc2580_attach, adap->fe[0], &d->i2c_adap, |
| 856 | &rtl2832u_fc2580_config); |
| 857 | break; |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 858 | case TUNER_RTL2832_TUA9001: |
| 859 | /* enable GPIO1 and GPIO4 as output */ |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame^] | 860 | ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12); |
| 861 | if (ret) |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 862 | goto err; |
| 863 | |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame^] | 864 | ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x12, 0x12); |
| 865 | if (ret) |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 866 | goto err; |
| 867 | |
| 868 | fe = dvb_attach(tua9001_attach, adap->fe[0], &d->i2c_adap, |
| 869 | &rtl2832u_tua9001_config); |
| 870 | break; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 871 | default: |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 872 | fe = NULL; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 873 | dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME, |
| 874 | priv->tuner); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | if (fe == NULL) { |
| 878 | ret = -ENODEV; |
| 879 | goto err; |
| 880 | } |
| 881 | |
| 882 | return 0; |
| 883 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 884 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 885 | return ret; |
| 886 | } |
| 887 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 888 | static int rtl28xxu_init(struct dvb_usb_device *d) |
| 889 | { |
| 890 | int ret; |
| 891 | u8 val; |
| 892 | |
| 893 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
| 894 | |
| 895 | /* init USB endpoints */ |
| 896 | ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val); |
| 897 | if (ret) |
| 898 | goto err; |
| 899 | |
| 900 | /* enable DMA and Full Packet Mode*/ |
| 901 | val |= 0x09; |
| 902 | ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val); |
| 903 | if (ret) |
| 904 | goto err; |
| 905 | |
| 906 | /* set EPA maximum packet size to 0x0200 */ |
| 907 | ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4); |
| 908 | if (ret) |
| 909 | goto err; |
| 910 | |
| 911 | /* change EPA FIFO length */ |
| 912 | ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4); |
| 913 | if (ret) |
| 914 | goto err; |
| 915 | |
| 916 | return ret; |
| 917 | err: |
| 918 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 919 | return ret; |
| 920 | } |
| 921 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 922 | static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 923 | { |
| 924 | int ret; |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 925 | u8 gpio, sys0, epa_ctl[2]; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 926 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 927 | dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 928 | |
| 929 | /* demod adc */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 930 | ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 931 | if (ret) |
| 932 | goto err; |
| 933 | |
| 934 | /* tuner power, read GPIOs */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 935 | ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 936 | if (ret) |
| 937 | goto err; |
| 938 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 939 | dev_dbg(&d->udev->dev, "%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__, |
| 940 | sys0, gpio); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 941 | |
| 942 | if (onoff) { |
| 943 | gpio |= 0x01; /* GPIO0 = 1 */ |
| 944 | gpio &= (~0x10); /* GPIO4 = 0 */ |
Antti Palosaari | 991452a | 2012-08-12 22:27:08 -0300 | [diff] [blame] | 945 | gpio |= 0x04; /* GPIO2 = 1, LED on */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 946 | sys0 = sys0 & 0x0f; |
| 947 | sys0 |= 0xe0; |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 948 | epa_ctl[0] = 0x00; /* clear stall */ |
| 949 | epa_ctl[1] = 0x00; /* clear reset */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 950 | } else { |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 951 | gpio &= (~0x01); /* GPIO0 = 0 */ |
| 952 | gpio |= 0x10; /* GPIO4 = 1 */ |
Antti Palosaari | 991452a | 2012-08-12 22:27:08 -0300 | [diff] [blame] | 953 | gpio &= (~0x04); /* GPIO2 = 1, LED off */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 954 | sys0 = sys0 & (~0xc0); |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 955 | epa_ctl[0] = 0x10; /* set stall */ |
| 956 | epa_ctl[1] = 0x02; /* set reset */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 957 | } |
| 958 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 959 | dev_dbg(&d->udev->dev, "%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__, |
| 960 | sys0, gpio); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 961 | |
| 962 | /* demod adc */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 963 | ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 964 | if (ret) |
| 965 | goto err; |
| 966 | |
| 967 | /* tuner power, write GPIOs */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 968 | ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, gpio); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 969 | if (ret) |
| 970 | goto err; |
| 971 | |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 972 | /* streaming EP: stall & reset */ |
| 973 | ret = rtl28xx_wr_regs(d, USB_EPA_CTL, epa_ctl, 2); |
| 974 | if (ret) |
| 975 | goto err; |
| 976 | |
| 977 | if (onoff) |
| 978 | usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81)); |
| 979 | |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 980 | return ret; |
| 981 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 982 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 983 | return ret; |
| 984 | } |
| 985 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 986 | static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff) |
| 987 | { |
| 988 | int ret; |
| 989 | u8 val; |
| 990 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 991 | dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 992 | |
| 993 | if (onoff) { |
| 994 | /* set output values */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 995 | ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 996 | if (ret) |
| 997 | goto err; |
| 998 | |
| 999 | val |= 0x08; |
| 1000 | val &= 0xef; |
| 1001 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1002 | ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1003 | if (ret) |
| 1004 | goto err; |
| 1005 | |
| 1006 | /* demod_ctl_1 */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1007 | ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1008 | if (ret) |
| 1009 | goto err; |
| 1010 | |
| 1011 | val &= 0xef; |
| 1012 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1013 | ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1014 | if (ret) |
| 1015 | goto err; |
| 1016 | |
| 1017 | /* demod control */ |
| 1018 | /* PLL enable */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1019 | ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1020 | if (ret) |
| 1021 | goto err; |
| 1022 | |
| 1023 | /* bit 7 to 1 */ |
| 1024 | val |= 0x80; |
| 1025 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1026 | ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1027 | if (ret) |
| 1028 | goto err; |
| 1029 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1030 | ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1031 | if (ret) |
| 1032 | goto err; |
| 1033 | |
| 1034 | val |= 0x20; |
| 1035 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1036 | ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1037 | if (ret) |
| 1038 | goto err; |
| 1039 | |
| 1040 | mdelay(5); |
| 1041 | |
| 1042 | /*enable ADC_Q and ADC_I */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1043 | ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1044 | if (ret) |
| 1045 | goto err; |
| 1046 | |
| 1047 | val |= 0x48; |
| 1048 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1049 | ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1050 | if (ret) |
| 1051 | goto err; |
| 1052 | |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 1053 | /* streaming EP: clear stall & reset */ |
| 1054 | ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2); |
| 1055 | if (ret) |
| 1056 | goto err; |
| 1057 | |
| 1058 | ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81)); |
| 1059 | if (ret) |
| 1060 | goto err; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1061 | } else { |
| 1062 | /* demod_ctl_1 */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1063 | ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1064 | if (ret) |
| 1065 | goto err; |
| 1066 | |
| 1067 | val |= 0x0c; |
| 1068 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1069 | ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1070 | if (ret) |
| 1071 | goto err; |
| 1072 | |
| 1073 | /* set output values */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1074 | ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1075 | if (ret) |
| 1076 | goto err; |
| 1077 | |
| 1078 | val |= 0x10; |
| 1079 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1080 | ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1081 | if (ret) |
| 1082 | goto err; |
| 1083 | |
| 1084 | /* demod control */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1085 | ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1086 | if (ret) |
| 1087 | goto err; |
| 1088 | |
| 1089 | val &= 0x37; |
| 1090 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1091 | ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1092 | if (ret) |
| 1093 | goto err; |
| 1094 | |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 1095 | /* streaming EP: set stall & reset */ |
| 1096 | ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2); |
| 1097 | if (ret) |
| 1098 | goto err; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | return ret; |
| 1102 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1103 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1104 | return ret; |
| 1105 | } |
| 1106 | |
| 1107 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1108 | static int rtl2831u_rc_query(struct dvb_usb_device *d) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1109 | { |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1110 | int ret, i; |
| 1111 | struct rtl28xxu_priv *priv = d->priv; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1112 | u8 buf[5]; |
| 1113 | u32 rc_code; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1114 | struct rtl28xxu_reg_val rc_nec_tab[] = { |
| 1115 | { 0x3033, 0x80 }, |
| 1116 | { 0x3020, 0x43 }, |
| 1117 | { 0x3021, 0x16 }, |
| 1118 | { 0x3022, 0x16 }, |
| 1119 | { 0x3023, 0x5a }, |
| 1120 | { 0x3024, 0x2d }, |
| 1121 | { 0x3025, 0x16 }, |
| 1122 | { 0x3026, 0x01 }, |
| 1123 | { 0x3028, 0xb0 }, |
| 1124 | { 0x3029, 0x04 }, |
| 1125 | { 0x302c, 0x88 }, |
| 1126 | { 0x302e, 0x13 }, |
| 1127 | { 0x3030, 0xdf }, |
| 1128 | { 0x3031, 0x05 }, |
| 1129 | }; |
| 1130 | |
| 1131 | /* init remote controller */ |
| 1132 | if (!priv->rc_active) { |
| 1133 | for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) { |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1134 | ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg, |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 1135 | rc_nec_tab[i].val); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1136 | if (ret) |
| 1137 | goto err; |
| 1138 | } |
| 1139 | priv->rc_active = true; |
| 1140 | } |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1141 | |
| 1142 | ret = rtl2831_rd_regs(d, SYS_IRRC_RP, buf, 5); |
| 1143 | if (ret) |
| 1144 | goto err; |
| 1145 | |
| 1146 | if (buf[4] & 0x01) { |
| 1147 | if (buf[2] == (u8) ~buf[3]) { |
| 1148 | if (buf[0] == (u8) ~buf[1]) { |
| 1149 | /* NEC standard (16 bit) */ |
| 1150 | rc_code = buf[0] << 8 | buf[2]; |
| 1151 | } else { |
| 1152 | /* NEC extended (24 bit) */ |
| 1153 | rc_code = buf[0] << 16 | |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 1154 | buf[1] << 8 | buf[2]; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1155 | } |
| 1156 | } else { |
| 1157 | /* NEC full (32 bit) */ |
| 1158 | rc_code = buf[0] << 24 | buf[1] << 16 | |
| 1159 | buf[2] << 8 | buf[3]; |
| 1160 | } |
| 1161 | |
| 1162 | rc_keydown(d->rc_dev, rc_code, 0); |
| 1163 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1164 | ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1165 | if (ret) |
| 1166 | goto err; |
| 1167 | |
| 1168 | /* repeated intentionally to avoid extra keypress */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1169 | ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1170 | if (ret) |
| 1171 | goto err; |
| 1172 | } |
| 1173 | |
| 1174 | return ret; |
| 1175 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1176 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1177 | return ret; |
| 1178 | } |
| 1179 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1180 | static int rtl2831u_get_rc_config(struct dvb_usb_device *d, |
| 1181 | struct dvb_usb_rc *rc) |
| 1182 | { |
| 1183 | rc->map_name = RC_MAP_EMPTY; |
| 1184 | rc->allowed_protos = RC_TYPE_NEC; |
| 1185 | rc->query = rtl2831u_rc_query; |
| 1186 | rc->interval = 400; |
| 1187 | |
| 1188 | return 0; |
| 1189 | } |
| 1190 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1191 | static int rtl2832u_rc_query(struct dvb_usb_device *d) |
| 1192 | { |
| 1193 | int ret, i; |
| 1194 | struct rtl28xxu_priv *priv = d->priv; |
| 1195 | u8 buf[128]; |
| 1196 | int len; |
| 1197 | struct rtl28xxu_reg_val rc_nec_tab[] = { |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 1198 | { IR_RX_CTRL, 0x20 }, |
| 1199 | { IR_RX_BUF_CTRL, 0x80 }, |
| 1200 | { IR_RX_IF, 0xff }, |
| 1201 | { IR_RX_IE, 0xff }, |
| 1202 | { IR_MAX_DURATION0, 0xd0 }, |
| 1203 | { IR_MAX_DURATION1, 0x07 }, |
| 1204 | { IR_IDLE_LEN0, 0xc0 }, |
| 1205 | { IR_IDLE_LEN1, 0x00 }, |
| 1206 | { IR_GLITCH_LEN, 0x03 }, |
| 1207 | { IR_RX_CLK, 0x09 }, |
| 1208 | { IR_RX_CFG, 0x1c }, |
| 1209 | { IR_MAX_H_TOL_LEN, 0x1e }, |
| 1210 | { IR_MAX_L_TOL_LEN, 0x1e }, |
| 1211 | { IR_RX_CTRL, 0x80 }, |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1212 | }; |
| 1213 | |
| 1214 | /* init remote controller */ |
| 1215 | if (!priv->rc_active) { |
| 1216 | for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) { |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1217 | ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg, |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 1218 | rc_nec_tab[i].val); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1219 | if (ret) |
| 1220 | goto err; |
| 1221 | } |
| 1222 | priv->rc_active = true; |
| 1223 | } |
| 1224 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1225 | ret = rtl28xx_rd_reg(d, IR_RX_IF, &buf[0]); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1226 | if (ret) |
| 1227 | goto err; |
| 1228 | |
| 1229 | if (buf[0] != 0x83) |
| 1230 | goto exit; |
| 1231 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1232 | ret = rtl28xx_rd_reg(d, IR_RX_BC, &buf[0]); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1233 | if (ret) |
| 1234 | goto err; |
| 1235 | |
| 1236 | len = buf[0]; |
| 1237 | ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len); |
| 1238 | |
| 1239 | /* TODO: pass raw IR to Kernel IR decoder */ |
| 1240 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1241 | ret = rtl28xx_wr_reg(d, IR_RX_IF, 0x03); |
| 1242 | ret = rtl28xx_wr_reg(d, IR_RX_BUF_CTRL, 0x80); |
| 1243 | ret = rtl28xx_wr_reg(d, IR_RX_CTRL, 0x80); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1244 | |
| 1245 | exit: |
| 1246 | return ret; |
| 1247 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1248 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1249 | return ret; |
| 1250 | } |
| 1251 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1252 | static int rtl2832u_get_rc_config(struct dvb_usb_device *d, |
| 1253 | struct dvb_usb_rc *rc) |
| 1254 | { |
| 1255 | rc->map_name = RC_MAP_EMPTY; |
| 1256 | rc->allowed_protos = RC_TYPE_NEC; |
| 1257 | rc->query = rtl2832u_rc_query; |
| 1258 | rc->interval = 400; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1259 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1260 | return 0; |
| 1261 | } |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1262 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1263 | static const struct dvb_usb_device_properties rtl2831u_props = { |
| 1264 | .driver_name = KBUILD_MODNAME, |
| 1265 | .owner = THIS_MODULE, |
| 1266 | .adapter_nr = adapter_nr, |
| 1267 | .size_of_priv = sizeof(struct rtl28xxu_priv), |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1268 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1269 | .power_ctrl = rtl2831u_power_ctrl, |
| 1270 | .i2c_algo = &rtl28xxu_i2c_algo, |
| 1271 | .frontend_attach = rtl2831u_frontend_attach, |
| 1272 | .tuner_attach = rtl2831u_tuner_attach, |
| 1273 | .init = rtl28xxu_init, |
| 1274 | .get_rc_config = rtl2831u_get_rc_config, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1275 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1276 | .num_adapters = 1, |
| 1277 | .adapter = { |
| 1278 | { |
| 1279 | .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512), |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1280 | }, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1281 | }, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1282 | }; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1283 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1284 | static const struct dvb_usb_device_properties rtl2832u_props = { |
| 1285 | .driver_name = KBUILD_MODNAME, |
| 1286 | .owner = THIS_MODULE, |
| 1287 | .adapter_nr = adapter_nr, |
| 1288 | .size_of_priv = sizeof(struct rtl28xxu_priv), |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1289 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1290 | .power_ctrl = rtl2832u_power_ctrl, |
| 1291 | .i2c_algo = &rtl28xxu_i2c_algo, |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 1292 | .read_config = rtl2832u_read_config, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1293 | .frontend_attach = rtl2832u_frontend_attach, |
| 1294 | .tuner_attach = rtl2832u_tuner_attach, |
| 1295 | .init = rtl28xxu_init, |
| 1296 | .get_rc_config = rtl2832u_get_rc_config, |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1297 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1298 | .num_adapters = 1, |
| 1299 | .adapter = { |
| 1300 | { |
| 1301 | .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512), |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1302 | }, |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1303 | }, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1304 | }; |
| 1305 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1306 | static const struct usb_device_id rtl28xxu_id_table[] = { |
| 1307 | { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U, |
| 1308 | &rtl2831u_props, "Realtek RTL2831U reference design", NULL) }, |
| 1309 | { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT, |
| 1310 | &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) }, |
| 1311 | { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2, |
| 1312 | &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) }, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1313 | |
Antti Palosaari | 254ee2e | 2012-09-18 10:27:05 -0300 | [diff] [blame] | 1314 | { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2832, |
| 1315 | &rtl2832u_props, "Realtek RTL2832U reference design", NULL) }, |
| 1316 | { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838, |
| 1317 | &rtl2832u_props, "Realtek RTL2832U reference design", NULL) }, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1318 | { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1, |
| 1319 | &rtl2832u_props, "Terratec Cinergy T Stick Black", NULL) }, |
| 1320 | { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT, |
| 1321 | &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) }, |
| 1322 | { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK, |
| 1323 | &rtl2832u_props, "NOXON DAB/DAB+ USB dongle", NULL) }, |
Philipp Dreimann | 6d60805 | 2012-09-02 19:30:54 -0300 | [diff] [blame] | 1324 | { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0, |
| 1325 | &rtl2832u_props, "Trekstor DVB-T Stick Terres 2.0", NULL) }, |
Antti Palosaari | c2d246d1 | 2012-09-08 22:07:26 -0300 | [diff] [blame] | 1326 | { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101, |
| 1327 | &rtl2832u_props, "Dexatek DK DVB-T Dongle", NULL) }, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1328 | { } |
| 1329 | }; |
| 1330 | MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1331 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1332 | static struct usb_driver rtl28xxu_usb_driver = { |
| 1333 | .name = KBUILD_MODNAME, |
| 1334 | .id_table = rtl28xxu_id_table, |
| 1335 | .probe = dvb_usbv2_probe, |
| 1336 | .disconnect = dvb_usbv2_disconnect, |
| 1337 | .suspend = dvb_usbv2_suspend, |
| 1338 | .resume = dvb_usbv2_resume, |
Antti Palosaari | 78fa590 | 2012-08-14 22:21:09 -0300 | [diff] [blame] | 1339 | .reset_resume = dvb_usbv2_reset_resume, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1340 | .no_dynamic_id = 1, |
| 1341 | .soft_unbind = 1, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1342 | }; |
| 1343 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1344 | module_usb_driver(rtl28xxu_usb_driver); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1345 | |
| 1346 | MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver"); |
| 1347 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1348 | MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>"); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1349 | MODULE_LICENSE("GPL"); |