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; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 594 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 595 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 596 | return ret; |
| 597 | } |
| 598 | |
| 599 | |
| 600 | static int rtl2832u_fc0013_tuner_callback(struct dvb_usb_device *d, |
| 601 | int cmd, int arg) |
| 602 | { |
| 603 | /* TODO implement*/ |
| 604 | return 0; |
| 605 | } |
| 606 | |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 607 | static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d, |
| 608 | int cmd, int arg) |
| 609 | { |
| 610 | int ret; |
| 611 | u8 val; |
| 612 | |
| 613 | dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg); |
| 614 | |
| 615 | /* |
| 616 | * CEN always enabled by hardware wiring |
| 617 | * RESETN GPIO4 |
| 618 | * RXEN GPIO1 |
| 619 | */ |
| 620 | |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 621 | switch (cmd) { |
| 622 | case TUA9001_CMD_RESETN: |
| 623 | if (arg) |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 624 | val = (1 << 4); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 625 | else |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 626 | val = (0 << 4); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 627 | |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 628 | ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x10); |
| 629 | if (ret) |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 630 | goto err; |
| 631 | break; |
| 632 | case TUA9001_CMD_RXEN: |
| 633 | if (arg) |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 634 | val = (1 << 1); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 635 | else |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 636 | val = (0 << 1); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 637 | |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 638 | ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x02); |
| 639 | if (ret) |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 640 | goto err; |
| 641 | break; |
| 642 | } |
| 643 | |
| 644 | return 0; |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 645 | err: |
| 646 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 647 | return ret; |
| 648 | } |
| 649 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 650 | static int rtl2832u_tuner_callback(struct dvb_usb_device *d, int cmd, int arg) |
| 651 | { |
| 652 | struct rtl28xxu_priv *priv = d->priv; |
| 653 | |
| 654 | switch (priv->tuner) { |
| 655 | case TUNER_RTL2832_FC0012: |
| 656 | return rtl2832u_fc0012_tuner_callback(d, cmd, arg); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 657 | case TUNER_RTL2832_FC0013: |
| 658 | return rtl2832u_fc0013_tuner_callback(d, cmd, arg); |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 659 | case TUNER_RTL2832_TUA9001: |
| 660 | return rtl2832u_tua9001_tuner_callback(d, cmd, arg); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 661 | default: |
| 662 | break; |
| 663 | } |
| 664 | |
Antti Palosaari | 97efe78 | 2012-09-17 15:49:54 -0300 | [diff] [blame^] | 665 | return 0; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static int rtl2832u_frontend_callback(void *adapter_priv, int component, |
| 669 | int cmd, int arg) |
| 670 | { |
| 671 | struct i2c_adapter *adap = adapter_priv; |
| 672 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 673 | |
| 674 | switch (component) { |
| 675 | case DVB_FRONTEND_COMPONENT_TUNER: |
| 676 | return rtl2832u_tuner_callback(d, cmd, arg); |
| 677 | default: |
| 678 | break; |
| 679 | } |
| 680 | |
Antti Palosaari | 97efe78 | 2012-09-17 15:49:54 -0300 | [diff] [blame^] | 681 | return 0; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 682 | } |
| 683 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 684 | static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap) |
| 685 | { |
| 686 | int ret; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 687 | struct dvb_usb_device *d = adap_to_d(adap); |
| 688 | struct rtl28xxu_priv *priv = d_to_priv(d); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 689 | struct rtl2832_config *rtl2832_config; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 690 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 691 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 692 | |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 693 | switch (priv->tuner) { |
| 694 | case TUNER_RTL2832_FC0012: |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 695 | rtl2832_config = &rtl28xxu_rtl2832_fc0012_config; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 696 | break; |
| 697 | case TUNER_RTL2832_FC0013: |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 698 | rtl2832_config = &rtl28xxu_rtl2832_fc0013_config; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 699 | break; |
| 700 | case TUNER_RTL2832_FC2580: |
Antti Palosaari | 384df49 | 2012-09-08 22:07:25 -0300 | [diff] [blame] | 701 | /* FIXME: do not abuse fc0012 settings */ |
| 702 | rtl2832_config = &rtl28xxu_rtl2832_fc0012_config; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 703 | break; |
| 704 | case TUNER_RTL2832_TUA9001: |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 705 | rtl2832_config = &rtl28xxu_rtl2832_tua9001_config; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 706 | break; |
| 707 | case TUNER_RTL2832_E4000: |
Antti Palosaari | 542f6a5 | 2012-09-01 21:09:22 -0300 | [diff] [blame] | 708 | /* FIXME: do not abuse fc0012 settings */ |
| 709 | rtl2832_config = &rtl28xxu_rtl2832_fc0012_config; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 710 | break; |
| 711 | default: |
| 712 | dev_err(&d->udev->dev, "%s: unknown tuner=%s\n", |
| 713 | KBUILD_MODNAME, priv->tuner_name); |
| 714 | ret = -ENODEV; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 715 | goto err; |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 716 | } |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 717 | |
| 718 | /* attach demodulator */ |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 719 | adap->fe[0] = dvb_attach(rtl2832_attach, rtl2832_config, &d->i2c_adap); |
| 720 | if (!adap->fe[0]) { |
| 721 | ret = -ENODEV; |
| 722 | goto err; |
| 723 | } |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 724 | |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 725 | /* set fe callback */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 726 | adap->fe[0]->callback = rtl2832u_frontend_callback; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 727 | |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 728 | return 0; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 729 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 730 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 731 | return ret; |
| 732 | } |
| 733 | |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 734 | static struct qt1010_config rtl28xxu_qt1010_config = { |
| 735 | .i2c_address = 0x62, /* 0xc4 */ |
| 736 | }; |
| 737 | |
| 738 | static struct mt2060_config rtl28xxu_mt2060_config = { |
| 739 | .i2c_address = 0x60, /* 0xc0 */ |
| 740 | .clock_out = 0, |
| 741 | }; |
| 742 | |
| 743 | static struct mxl5005s_config rtl28xxu_mxl5005s_config = { |
| 744 | .i2c_address = 0x63, /* 0xc6 */ |
| 745 | .if_freq = IF_FREQ_4570000HZ, |
| 746 | .xtal_freq = CRYSTAL_FREQ_16000000HZ, |
| 747 | .agc_mode = MXL_SINGLE_AGC, |
| 748 | .tracking_filter = MXL_TF_C_H, |
| 749 | .rssi_enable = MXL_RSSI_ENABLE, |
| 750 | .cap_select = MXL_CAP_SEL_ENABLE, |
| 751 | .div_out = MXL_DIV_OUT_4, |
| 752 | .clock_out = MXL_CLOCK_OUT_DISABLE, |
| 753 | .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM, |
| 754 | .top = MXL5005S_TOP_25P2, |
| 755 | .mod_mode = MXL_DIGITAL_MODE, |
| 756 | .if_mode = MXL_ZERO_IF, |
| 757 | .AgcMasterByte = 0x00, |
| 758 | }; |
| 759 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 760 | static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 761 | { |
| 762 | int ret; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 763 | struct dvb_usb_device *d = adap_to_d(adap); |
| 764 | struct rtl28xxu_priv *priv = d_to_priv(d); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 765 | struct i2c_adapter *rtl2830_tuner_i2c; |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 766 | struct dvb_frontend *fe; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 767 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 768 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 769 | |
| 770 | /* use rtl2830 driver I2C adapter, for more info see rtl2830 driver */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 771 | rtl2830_tuner_i2c = rtl2830_get_tuner_i2c_adapter(adap->fe[0]); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 772 | |
| 773 | switch (priv->tuner) { |
| 774 | case TUNER_RTL2830_QT1010: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 775 | fe = dvb_attach(qt1010_attach, adap->fe[0], |
Antti Palosaari | fba16b1 | 2012-01-21 20:28:38 -0300 | [diff] [blame] | 776 | rtl2830_tuner_i2c, &rtl28xxu_qt1010_config); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 777 | break; |
| 778 | case TUNER_RTL2830_MT2060: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 779 | fe = dvb_attach(mt2060_attach, adap->fe[0], |
Antti Palosaari | fba16b1 | 2012-01-21 20:28:38 -0300 | [diff] [blame] | 780 | rtl2830_tuner_i2c, &rtl28xxu_mt2060_config, |
| 781 | 1220); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 782 | break; |
| 783 | case TUNER_RTL2830_MXL5005S: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 784 | fe = dvb_attach(mxl5005s_attach, adap->fe[0], |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 785 | rtl2830_tuner_i2c, &rtl28xxu_mxl5005s_config); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 786 | break; |
| 787 | default: |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 788 | fe = NULL; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 789 | dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME, |
| 790 | priv->tuner); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | if (fe == NULL) { |
| 794 | ret = -ENODEV; |
| 795 | goto err; |
| 796 | } |
| 797 | |
| 798 | return 0; |
| 799 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 800 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 801 | return ret; |
| 802 | } |
| 803 | |
Antti Palosaari | 542f6a5 | 2012-09-01 21:09:22 -0300 | [diff] [blame] | 804 | static const struct e4000_config rtl2832u_e4000_config = { |
| 805 | .i2c_addr = 0x64, |
| 806 | .clock = 28800000, |
| 807 | }; |
| 808 | |
Antti Palosaari | 384df49 | 2012-09-08 22:07:25 -0300 | [diff] [blame] | 809 | static const struct fc2580_config rtl2832u_fc2580_config = { |
| 810 | .i2c_addr = 0x56, |
| 811 | .clock = 16384000, |
| 812 | }; |
| 813 | |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 814 | static struct tua9001_config rtl2832u_tua9001_config = { |
| 815 | .i2c_addr = 0x60, |
| 816 | }; |
| 817 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 818 | static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap) |
| 819 | { |
| 820 | int ret; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 821 | struct dvb_usb_device *d = adap_to_d(adap); |
| 822 | struct rtl28xxu_priv *priv = d_to_priv(d); |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 823 | struct dvb_frontend *fe; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 824 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 825 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 826 | |
| 827 | switch (priv->tuner) { |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 828 | case TUNER_RTL2832_FC0012: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 829 | fe = dvb_attach(fc0012_attach, adap->fe[0], |
| 830 | &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 831 | |
| 832 | /* since fc0012 includs reading the signal strength delegate |
| 833 | * that to the tuner driver */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 834 | adap->fe[0]->ops.read_signal_strength = |
| 835 | adap->fe[0]->ops.tuner_ops.get_rf_strength; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 836 | return 0; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 837 | break; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 838 | case TUNER_RTL2832_FC0013: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 839 | fe = dvb_attach(fc0013_attach, adap->fe[0], |
| 840 | &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 841 | |
| 842 | /* fc0013 also supports signal strength reading */ |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 843 | adap->fe[0]->ops.read_signal_strength = |
| 844 | adap->fe[0]->ops.tuner_ops.get_rf_strength; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 845 | return 0; |
Antti Palosaari | 542f6a5 | 2012-09-01 21:09:22 -0300 | [diff] [blame] | 846 | case TUNER_RTL2832_E4000: |
| 847 | fe = dvb_attach(e4000_attach, adap->fe[0], &d->i2c_adap, |
| 848 | &rtl2832u_e4000_config); |
| 849 | break; |
Antti Palosaari | 384df49 | 2012-09-08 22:07:25 -0300 | [diff] [blame] | 850 | case TUNER_RTL2832_FC2580: |
| 851 | fe = dvb_attach(fc2580_attach, adap->fe[0], &d->i2c_adap, |
| 852 | &rtl2832u_fc2580_config); |
| 853 | break; |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 854 | case TUNER_RTL2832_TUA9001: |
| 855 | /* enable GPIO1 and GPIO4 as output */ |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 856 | ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12); |
| 857 | if (ret) |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 858 | goto err; |
| 859 | |
Antti Palosaari | 4005c1a | 2012-09-17 15:43:57 -0300 | [diff] [blame] | 860 | ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x12, 0x12); |
| 861 | if (ret) |
Antti Palosaari | 5be6572 | 2012-09-11 22:27:09 -0300 | [diff] [blame] | 862 | goto err; |
| 863 | |
| 864 | fe = dvb_attach(tua9001_attach, adap->fe[0], &d->i2c_adap, |
| 865 | &rtl2832u_tua9001_config); |
| 866 | break; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 867 | default: |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 868 | fe = NULL; |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 869 | dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME, |
| 870 | priv->tuner); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | if (fe == NULL) { |
| 874 | ret = -ENODEV; |
| 875 | goto err; |
| 876 | } |
| 877 | |
| 878 | return 0; |
| 879 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 880 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 881 | return ret; |
| 882 | } |
| 883 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 884 | static int rtl28xxu_init(struct dvb_usb_device *d) |
| 885 | { |
| 886 | int ret; |
| 887 | u8 val; |
| 888 | |
| 889 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
| 890 | |
| 891 | /* init USB endpoints */ |
| 892 | ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val); |
| 893 | if (ret) |
| 894 | goto err; |
| 895 | |
| 896 | /* enable DMA and Full Packet Mode*/ |
| 897 | val |= 0x09; |
| 898 | ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val); |
| 899 | if (ret) |
| 900 | goto err; |
| 901 | |
| 902 | /* set EPA maximum packet size to 0x0200 */ |
| 903 | ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4); |
| 904 | if (ret) |
| 905 | goto err; |
| 906 | |
| 907 | /* change EPA FIFO length */ |
| 908 | ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4); |
| 909 | if (ret) |
| 910 | goto err; |
| 911 | |
| 912 | return ret; |
| 913 | err: |
| 914 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 915 | return ret; |
| 916 | } |
| 917 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 918 | static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 919 | { |
| 920 | int ret; |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 921 | u8 gpio, sys0, epa_ctl[2]; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 922 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 923 | dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 924 | |
| 925 | /* demod adc */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 926 | ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 927 | if (ret) |
| 928 | goto err; |
| 929 | |
| 930 | /* tuner power, read GPIOs */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 931 | ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 932 | if (ret) |
| 933 | goto err; |
| 934 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 935 | dev_dbg(&d->udev->dev, "%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__, |
| 936 | sys0, gpio); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 937 | |
| 938 | if (onoff) { |
| 939 | gpio |= 0x01; /* GPIO0 = 1 */ |
| 940 | gpio &= (~0x10); /* GPIO4 = 0 */ |
Antti Palosaari | 991452a | 2012-08-12 22:27:08 -0300 | [diff] [blame] | 941 | gpio |= 0x04; /* GPIO2 = 1, LED on */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 942 | sys0 = sys0 & 0x0f; |
| 943 | sys0 |= 0xe0; |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 944 | epa_ctl[0] = 0x00; /* clear stall */ |
| 945 | epa_ctl[1] = 0x00; /* clear reset */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 946 | } else { |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 947 | gpio &= (~0x01); /* GPIO0 = 0 */ |
| 948 | gpio |= 0x10; /* GPIO4 = 1 */ |
Antti Palosaari | 991452a | 2012-08-12 22:27:08 -0300 | [diff] [blame] | 949 | gpio &= (~0x04); /* GPIO2 = 1, LED off */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 950 | sys0 = sys0 & (~0xc0); |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 951 | epa_ctl[0] = 0x10; /* set stall */ |
| 952 | epa_ctl[1] = 0x02; /* set reset */ |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 953 | } |
| 954 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 955 | dev_dbg(&d->udev->dev, "%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__, |
| 956 | sys0, gpio); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 957 | |
| 958 | /* demod adc */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 959 | ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 960 | if (ret) |
| 961 | goto err; |
| 962 | |
| 963 | /* tuner power, write GPIOs */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 964 | ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, gpio); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 965 | if (ret) |
| 966 | goto err; |
| 967 | |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 968 | /* streaming EP: stall & reset */ |
| 969 | ret = rtl28xx_wr_regs(d, USB_EPA_CTL, epa_ctl, 2); |
| 970 | if (ret) |
| 971 | goto err; |
| 972 | |
| 973 | if (onoff) |
| 974 | usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81)); |
| 975 | |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 976 | return ret; |
| 977 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 978 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 979 | return ret; |
| 980 | } |
| 981 | |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 982 | static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff) |
| 983 | { |
| 984 | int ret; |
| 985 | u8 val; |
| 986 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 987 | dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 988 | |
| 989 | if (onoff) { |
| 990 | /* set output values */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 991 | ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 992 | if (ret) |
| 993 | goto err; |
| 994 | |
| 995 | val |= 0x08; |
| 996 | val &= 0xef; |
| 997 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 998 | ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 999 | if (ret) |
| 1000 | goto err; |
| 1001 | |
| 1002 | /* demod_ctl_1 */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1003 | ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1004 | if (ret) |
| 1005 | goto err; |
| 1006 | |
| 1007 | val &= 0xef; |
| 1008 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1009 | ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1010 | if (ret) |
| 1011 | goto err; |
| 1012 | |
| 1013 | /* demod control */ |
| 1014 | /* PLL enable */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1015 | ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1016 | if (ret) |
| 1017 | goto err; |
| 1018 | |
| 1019 | /* bit 7 to 1 */ |
| 1020 | val |= 0x80; |
| 1021 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1022 | ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1023 | if (ret) |
| 1024 | goto err; |
| 1025 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1026 | ret = rtl28xx_rd_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 | |
| 1030 | val |= 0x20; |
| 1031 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1032 | ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1033 | if (ret) |
| 1034 | goto err; |
| 1035 | |
| 1036 | mdelay(5); |
| 1037 | |
| 1038 | /*enable ADC_Q and ADC_I */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1039 | ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1040 | if (ret) |
| 1041 | goto err; |
| 1042 | |
| 1043 | val |= 0x48; |
| 1044 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1045 | ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1046 | if (ret) |
| 1047 | goto err; |
| 1048 | |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 1049 | /* streaming EP: clear stall & reset */ |
| 1050 | ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2); |
| 1051 | if (ret) |
| 1052 | goto err; |
| 1053 | |
| 1054 | ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81)); |
| 1055 | if (ret) |
| 1056 | goto err; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1057 | } else { |
| 1058 | /* demod_ctl_1 */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1059 | ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1060 | if (ret) |
| 1061 | goto err; |
| 1062 | |
| 1063 | val |= 0x0c; |
| 1064 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1065 | ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1066 | if (ret) |
| 1067 | goto err; |
| 1068 | |
| 1069 | /* set output values */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1070 | ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1071 | if (ret) |
| 1072 | goto err; |
| 1073 | |
| 1074 | val |= 0x10; |
| 1075 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1076 | ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1077 | if (ret) |
| 1078 | goto err; |
| 1079 | |
| 1080 | /* demod control */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1081 | ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1082 | if (ret) |
| 1083 | goto err; |
| 1084 | |
| 1085 | val &= 0x37; |
| 1086 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1087 | ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1088 | if (ret) |
| 1089 | goto err; |
| 1090 | |
Antti Palosaari | 8b03663 | 2012-09-01 09:54:43 -0300 | [diff] [blame] | 1091 | /* streaming EP: set stall & reset */ |
| 1092 | ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2); |
| 1093 | if (ret) |
| 1094 | goto err; |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | return ret; |
| 1098 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1099 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1100 | return ret; |
| 1101 | } |
| 1102 | |
| 1103 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1104 | static int rtl2831u_rc_query(struct dvb_usb_device *d) |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1105 | { |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1106 | int ret, i; |
| 1107 | struct rtl28xxu_priv *priv = d->priv; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1108 | u8 buf[5]; |
| 1109 | u32 rc_code; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1110 | struct rtl28xxu_reg_val rc_nec_tab[] = { |
| 1111 | { 0x3033, 0x80 }, |
| 1112 | { 0x3020, 0x43 }, |
| 1113 | { 0x3021, 0x16 }, |
| 1114 | { 0x3022, 0x16 }, |
| 1115 | { 0x3023, 0x5a }, |
| 1116 | { 0x3024, 0x2d }, |
| 1117 | { 0x3025, 0x16 }, |
| 1118 | { 0x3026, 0x01 }, |
| 1119 | { 0x3028, 0xb0 }, |
| 1120 | { 0x3029, 0x04 }, |
| 1121 | { 0x302c, 0x88 }, |
| 1122 | { 0x302e, 0x13 }, |
| 1123 | { 0x3030, 0xdf }, |
| 1124 | { 0x3031, 0x05 }, |
| 1125 | }; |
| 1126 | |
| 1127 | /* init remote controller */ |
| 1128 | if (!priv->rc_active) { |
| 1129 | for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) { |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1130 | ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg, |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 1131 | rc_nec_tab[i].val); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1132 | if (ret) |
| 1133 | goto err; |
| 1134 | } |
| 1135 | priv->rc_active = true; |
| 1136 | } |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1137 | |
| 1138 | ret = rtl2831_rd_regs(d, SYS_IRRC_RP, buf, 5); |
| 1139 | if (ret) |
| 1140 | goto err; |
| 1141 | |
| 1142 | if (buf[4] & 0x01) { |
| 1143 | if (buf[2] == (u8) ~buf[3]) { |
| 1144 | if (buf[0] == (u8) ~buf[1]) { |
| 1145 | /* NEC standard (16 bit) */ |
| 1146 | rc_code = buf[0] << 8 | buf[2]; |
| 1147 | } else { |
| 1148 | /* NEC extended (24 bit) */ |
| 1149 | rc_code = buf[0] << 16 | |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 1150 | buf[1] << 8 | buf[2]; |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1151 | } |
| 1152 | } else { |
| 1153 | /* NEC full (32 bit) */ |
| 1154 | rc_code = buf[0] << 24 | buf[1] << 16 | |
| 1155 | buf[2] << 8 | buf[3]; |
| 1156 | } |
| 1157 | |
| 1158 | rc_keydown(d->rc_dev, rc_code, 0); |
| 1159 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1160 | ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1161 | if (ret) |
| 1162 | goto err; |
| 1163 | |
| 1164 | /* repeated intentionally to avoid extra keypress */ |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1165 | ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1166 | if (ret) |
| 1167 | goto err; |
| 1168 | } |
| 1169 | |
| 1170 | return ret; |
| 1171 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1172 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1173 | return ret; |
| 1174 | } |
| 1175 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1176 | static int rtl2831u_get_rc_config(struct dvb_usb_device *d, |
| 1177 | struct dvb_usb_rc *rc) |
| 1178 | { |
| 1179 | rc->map_name = RC_MAP_EMPTY; |
| 1180 | rc->allowed_protos = RC_TYPE_NEC; |
| 1181 | rc->query = rtl2831u_rc_query; |
| 1182 | rc->interval = 400; |
| 1183 | |
| 1184 | return 0; |
| 1185 | } |
| 1186 | |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1187 | static int rtl2832u_rc_query(struct dvb_usb_device *d) |
| 1188 | { |
| 1189 | int ret, i; |
| 1190 | struct rtl28xxu_priv *priv = d->priv; |
| 1191 | u8 buf[128]; |
| 1192 | int len; |
| 1193 | struct rtl28xxu_reg_val rc_nec_tab[] = { |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 1194 | { IR_RX_CTRL, 0x20 }, |
| 1195 | { IR_RX_BUF_CTRL, 0x80 }, |
| 1196 | { IR_RX_IF, 0xff }, |
| 1197 | { IR_RX_IE, 0xff }, |
| 1198 | { IR_MAX_DURATION0, 0xd0 }, |
| 1199 | { IR_MAX_DURATION1, 0x07 }, |
| 1200 | { IR_IDLE_LEN0, 0xc0 }, |
| 1201 | { IR_IDLE_LEN1, 0x00 }, |
| 1202 | { IR_GLITCH_LEN, 0x03 }, |
| 1203 | { IR_RX_CLK, 0x09 }, |
| 1204 | { IR_RX_CFG, 0x1c }, |
| 1205 | { IR_MAX_H_TOL_LEN, 0x1e }, |
| 1206 | { IR_MAX_L_TOL_LEN, 0x1e }, |
| 1207 | { IR_RX_CTRL, 0x80 }, |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1208 | }; |
| 1209 | |
| 1210 | /* init remote controller */ |
| 1211 | if (!priv->rc_active) { |
| 1212 | for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) { |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1213 | ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg, |
Antti Palosaari | 9935eea | 2012-01-21 22:26:52 -0300 | [diff] [blame] | 1214 | rc_nec_tab[i].val); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1215 | if (ret) |
| 1216 | goto err; |
| 1217 | } |
| 1218 | priv->rc_active = true; |
| 1219 | } |
| 1220 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1221 | ret = rtl28xx_rd_reg(d, IR_RX_IF, &buf[0]); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1222 | if (ret) |
| 1223 | goto err; |
| 1224 | |
| 1225 | if (buf[0] != 0x83) |
| 1226 | goto exit; |
| 1227 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1228 | ret = rtl28xx_rd_reg(d, IR_RX_BC, &buf[0]); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1229 | if (ret) |
| 1230 | goto err; |
| 1231 | |
| 1232 | len = buf[0]; |
| 1233 | ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len); |
| 1234 | |
| 1235 | /* TODO: pass raw IR to Kernel IR decoder */ |
| 1236 | |
Thomas Mair | 40a2d3c | 2012-05-18 14:47:42 -0300 | [diff] [blame] | 1237 | ret = rtl28xx_wr_reg(d, IR_RX_IF, 0x03); |
| 1238 | ret = rtl28xx_wr_reg(d, IR_RX_BUF_CTRL, 0x80); |
| 1239 | ret = rtl28xx_wr_reg(d, IR_RX_CTRL, 0x80); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1240 | |
| 1241 | exit: |
| 1242 | return ret; |
| 1243 | err: |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1244 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1245 | return ret; |
| 1246 | } |
| 1247 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1248 | static int rtl2832u_get_rc_config(struct dvb_usb_device *d, |
| 1249 | struct dvb_usb_rc *rc) |
| 1250 | { |
| 1251 | rc->map_name = RC_MAP_EMPTY; |
| 1252 | rc->allowed_protos = RC_TYPE_NEC; |
| 1253 | rc->query = rtl2832u_rc_query; |
| 1254 | rc->interval = 400; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1255 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1256 | return 0; |
| 1257 | } |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1258 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1259 | static const struct dvb_usb_device_properties rtl2831u_props = { |
| 1260 | .driver_name = KBUILD_MODNAME, |
| 1261 | .owner = THIS_MODULE, |
| 1262 | .adapter_nr = adapter_nr, |
| 1263 | .size_of_priv = sizeof(struct rtl28xxu_priv), |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1264 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1265 | .power_ctrl = rtl2831u_power_ctrl, |
| 1266 | .i2c_algo = &rtl28xxu_i2c_algo, |
| 1267 | .frontend_attach = rtl2831u_frontend_attach, |
| 1268 | .tuner_attach = rtl2831u_tuner_attach, |
| 1269 | .init = rtl28xxu_init, |
| 1270 | .get_rc_config = rtl2831u_get_rc_config, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1271 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1272 | .num_adapters = 1, |
| 1273 | .adapter = { |
| 1274 | { |
| 1275 | .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512), |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1276 | }, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1277 | }, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1278 | }; |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1279 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1280 | static const struct dvb_usb_device_properties rtl2832u_props = { |
| 1281 | .driver_name = KBUILD_MODNAME, |
| 1282 | .owner = THIS_MODULE, |
| 1283 | .adapter_nr = adapter_nr, |
| 1284 | .size_of_priv = sizeof(struct rtl28xxu_priv), |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1285 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1286 | .power_ctrl = rtl2832u_power_ctrl, |
| 1287 | .i2c_algo = &rtl28xxu_i2c_algo, |
Antti Palosaari | ef37be1 | 2012-09-17 14:01:35 -0300 | [diff] [blame] | 1288 | .read_config = rtl2832u_read_config, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1289 | .frontend_attach = rtl2832u_frontend_attach, |
| 1290 | .tuner_attach = rtl2832u_tuner_attach, |
| 1291 | .init = rtl28xxu_init, |
| 1292 | .get_rc_config = rtl2832u_get_rc_config, |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1293 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1294 | .num_adapters = 1, |
| 1295 | .adapter = { |
| 1296 | { |
| 1297 | .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512), |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1298 | }, |
Antti Palosaari | b5cbaa4 | 2011-08-04 13:26:10 -0300 | [diff] [blame] | 1299 | }, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1300 | }; |
| 1301 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1302 | static const struct usb_device_id rtl28xxu_id_table[] = { |
| 1303 | { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U, |
| 1304 | &rtl2831u_props, "Realtek RTL2831U reference design", NULL) }, |
| 1305 | { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT, |
| 1306 | &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) }, |
| 1307 | { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2, |
| 1308 | &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) }, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1309 | |
Antti Palosaari | 254ee2e | 2012-09-18 10:27:05 -0300 | [diff] [blame] | 1310 | { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2832, |
| 1311 | &rtl2832u_props, "Realtek RTL2832U reference design", NULL) }, |
| 1312 | { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838, |
| 1313 | &rtl2832u_props, "Realtek RTL2832U reference design", NULL) }, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1314 | { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1, |
| 1315 | &rtl2832u_props, "Terratec Cinergy T Stick Black", NULL) }, |
| 1316 | { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT, |
| 1317 | &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) }, |
| 1318 | { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK, |
| 1319 | &rtl2832u_props, "NOXON DAB/DAB+ USB dongle", NULL) }, |
Philipp Dreimann | 6d60805 | 2012-09-02 19:30:54 -0300 | [diff] [blame] | 1320 | { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0, |
| 1321 | &rtl2832u_props, "Trekstor DVB-T Stick Terres 2.0", NULL) }, |
Antti Palosaari | c2d246d1 | 2012-09-08 22:07:26 -0300 | [diff] [blame] | 1322 | { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101, |
| 1323 | &rtl2832u_props, "Dexatek DK DVB-T Dongle", NULL) }, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1324 | { } |
| 1325 | }; |
| 1326 | MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1327 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1328 | static struct usb_driver rtl28xxu_usb_driver = { |
| 1329 | .name = KBUILD_MODNAME, |
| 1330 | .id_table = rtl28xxu_id_table, |
| 1331 | .probe = dvb_usbv2_probe, |
| 1332 | .disconnect = dvb_usbv2_disconnect, |
| 1333 | .suspend = dvb_usbv2_suspend, |
| 1334 | .resume = dvb_usbv2_resume, |
Antti Palosaari | 78fa590 | 2012-08-14 22:21:09 -0300 | [diff] [blame] | 1335 | .reset_resume = dvb_usbv2_reset_resume, |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1336 | .no_dynamic_id = 1, |
| 1337 | .soft_unbind = 1, |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1338 | }; |
| 1339 | |
Antti Palosaari | c01a359 | 2012-08-12 22:27:07 -0300 | [diff] [blame] | 1340 | module_usb_driver(rtl28xxu_usb_driver); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1341 | |
| 1342 | MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver"); |
| 1343 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
Thomas Mair | 5cf6631 | 2012-05-18 14:47:41 -0300 | [diff] [blame] | 1344 | MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>"); |
Antti Palosaari | 831e0b7 | 2011-07-08 23:36:07 -0300 | [diff] [blame] | 1345 | MODULE_LICENSE("GPL"); |