Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1 | /* |
| 2 | * DVB USB Linux driver for Anysee E30 DVB-C & DVB-T USB2.0 receiver |
| 3 | * |
| 4 | * Copyright (C) 2007 Antti Palosaari <crope@iki.fi> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * TODO: |
| 21 | * - add smart card reader support for Conditional Access (CA) |
| 22 | * |
| 23 | * Card reader in Anysee is nothing more than ISO 7816 card reader. |
| 24 | * There is no hardware CAM in any Anysee device sold. |
| 25 | * In my understanding it should be implemented by making own module |
Antti Palosaari | 9fdd9ca | 2008-06-11 11:43:19 -0300 | [diff] [blame] | 26 | * for ISO 7816 card reader, like dvb_ca_en50221 is implemented. This |
| 27 | * module registers serial interface that can be used to communicate |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 28 | * with any ISO 7816 smart card. |
| 29 | * |
| 30 | * Any help according to implement serial smart card reader support |
| 31 | * is highly welcome! |
| 32 | */ |
| 33 | |
| 34 | #include "anysee.h" |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 35 | #include "dvb-pll.h" |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 36 | #include "tda1002x.h" |
| 37 | #include "mt352.h" |
| 38 | #include "mt352_priv.h" |
| 39 | #include "zl10353.h" |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 40 | #include "tda18212.h" |
Antti Palosaari | f0a5310 | 2011-04-27 21:11:59 -0300 | [diff] [blame] | 41 | #include "cx24116.h" |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 42 | #include "stv0900.h" |
| 43 | #include "stv6110.h" |
Antti Palosaari | f0a5310 | 2011-04-27 21:11:59 -0300 | [diff] [blame] | 44 | #include "isl6423.h" |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 45 | #include "cxd2820r.h" |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 46 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 47 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 48 | |
Antti Palosaari | 4458a54c | 2013-02-26 14:18:13 -0300 | [diff] [blame] | 49 | static int anysee_ctrl_msg(struct dvb_usb_device *d, |
| 50 | u8 *sbuf, u8 slen, u8 *rbuf, u8 rlen) |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 51 | { |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 52 | struct anysee_state *state = d_to_priv(d); |
Antti Palosaari | cf42795 | 2012-01-21 11:19:29 -0300 | [diff] [blame] | 53 | int act_len, ret, i; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 54 | |
Antti Palosaari | 6c604e8 | 2013-02-26 14:13:41 -0300 | [diff] [blame] | 55 | mutex_lock(&d->usb_mutex); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 56 | |
Antti Palosaari | 6c604e8 | 2013-02-26 14:13:41 -0300 | [diff] [blame] | 57 | memcpy(&state->buf[0], sbuf, slen); |
| 58 | state->buf[60] = state->seq++; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 59 | |
Antti Palosaari | 6c604e8 | 2013-02-26 14:13:41 -0300 | [diff] [blame] | 60 | dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, slen, state->buf); |
Antti Palosaari | 4048da2 | 2011-09-29 20:28:53 -0300 | [diff] [blame] | 61 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 62 | /* We need receive one message more after dvb_usb_generic_rw due |
| 63 | to weird transaction flow, which is 1 x send + 2 x receive. */ |
Antti Palosaari | 6c604e8 | 2013-02-26 14:13:41 -0300 | [diff] [blame] | 64 | ret = dvb_usbv2_generic_rw_locked(d, state->buf, sizeof(state->buf), |
| 65 | state->buf, sizeof(state->buf)); |
Antti Palosaari | cf42795 | 2012-01-21 11:19:29 -0300 | [diff] [blame] | 66 | if (ret) |
| 67 | goto error_unlock; |
| 68 | |
| 69 | /* TODO FIXME: dvb_usb_generic_rw() fails rarely with error code -32 |
| 70 | * (EPIPE, Broken pipe). Function supports currently msleep() as a |
| 71 | * parameter but I would not like to use it, since according to |
| 72 | * Documentation/timers/timers-howto.txt it should not be used such |
| 73 | * short, under < 20ms, sleeps. Repeating failed message would be |
| 74 | * better choice as not to add unwanted delays... |
| 75 | * Fixing that correctly is one of those or both; |
| 76 | * 1) use repeat if possible |
| 77 | * 2) add suitable delay |
| 78 | */ |
| 79 | |
| 80 | /* get answer, retry few times if error returned */ |
| 81 | for (i = 0; i < 3; i++) { |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 82 | /* receive 2nd answer */ |
| 83 | ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev, |
Antti Palosaari | 6c604e8 | 2013-02-26 14:13:41 -0300 | [diff] [blame] | 84 | d->props->generic_bulk_ctrl_endpoint), |
| 85 | state->buf, sizeof(state->buf), &act_len, 2000); |
Antti Palosaari | cf42795 | 2012-01-21 11:19:29 -0300 | [diff] [blame] | 86 | if (ret) { |
Antti Palosaari | 4458a54c | 2013-02-26 14:18:13 -0300 | [diff] [blame] | 87 | dev_dbg(&d->udev->dev, |
| 88 | "%s: recv bulk message failed=%d\n", |
| 89 | __func__, ret); |
Antti Palosaari | cf42795 | 2012-01-21 11:19:29 -0300 | [diff] [blame] | 90 | } else { |
Antti Palosaari | 82026f9 | 2012-08-14 15:56:20 -0300 | [diff] [blame] | 91 | dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__, |
Antti Palosaari | 6c604e8 | 2013-02-26 14:13:41 -0300 | [diff] [blame] | 92 | rlen, state->buf); |
Antti Palosaari | 4048da2 | 2011-09-29 20:28:53 -0300 | [diff] [blame] | 93 | |
Antti Palosaari | 6c604e8 | 2013-02-26 14:13:41 -0300 | [diff] [blame] | 94 | if (state->buf[63] != 0x4f) |
Antti Palosaari | 4458a54c | 2013-02-26 14:18:13 -0300 | [diff] [blame] | 95 | dev_dbg(&d->udev->dev, |
| 96 | "%s: cmd failed\n", __func__); |
Antti Palosaari | cf42795 | 2012-01-21 11:19:29 -0300 | [diff] [blame] | 97 | break; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
Antti Palosaari | cf42795 | 2012-01-21 11:19:29 -0300 | [diff] [blame] | 101 | if (ret) { |
| 102 | /* all retries failed, it is fatal */ |
Antti Palosaari | 82026f9 | 2012-08-14 15:56:20 -0300 | [diff] [blame] | 103 | dev_err(&d->udev->dev, "%s: recv bulk message failed=%d\n", |
| 104 | KBUILD_MODNAME, ret); |
Antti Palosaari | cf42795 | 2012-01-21 11:19:29 -0300 | [diff] [blame] | 105 | goto error_unlock; |
| 106 | } |
| 107 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 108 | /* read request, copy returned data to return buf */ |
Antti Palosaari | cf42795 | 2012-01-21 11:19:29 -0300 | [diff] [blame] | 109 | if (rbuf && rlen) |
Antti Palosaari | 6c604e8 | 2013-02-26 14:13:41 -0300 | [diff] [blame] | 110 | memcpy(rbuf, state->buf, rlen); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 111 | |
Antti Palosaari | cf42795 | 2012-01-21 11:19:29 -0300 | [diff] [blame] | 112 | error_unlock: |
Antti Palosaari | 6c604e8 | 2013-02-26 14:13:41 -0300 | [diff] [blame] | 113 | mutex_unlock(&d->usb_mutex); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 114 | return ret; |
| 115 | } |
| 116 | |
| 117 | static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val) |
| 118 | { |
| 119 | u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01}; |
| 120 | int ret; |
| 121 | ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1); |
Antti Palosaari | 82026f9 | 2012-08-14 15:56:20 -0300 | [diff] [blame] | 122 | dev_dbg(&d->udev->dev, "%s: reg=%04x val=%02x\n", __func__, reg, *val); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val) |
| 127 | { |
| 128 | u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val}; |
Antti Palosaari | 82026f9 | 2012-08-14 15:56:20 -0300 | [diff] [blame] | 129 | dev_dbg(&d->udev->dev, "%s: reg=%04x val=%02x\n", __func__, reg, val); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 130 | return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); |
| 131 | } |
| 132 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 133 | /* write single register with mask */ |
| 134 | static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val, |
| 135 | u8 mask) |
| 136 | { |
| 137 | int ret; |
| 138 | u8 tmp; |
| 139 | |
| 140 | /* no need for read if whole reg is written */ |
| 141 | if (mask != 0xff) { |
| 142 | ret = anysee_read_reg(d, reg, &tmp); |
| 143 | if (ret) |
| 144 | return ret; |
| 145 | |
| 146 | val &= mask; |
| 147 | tmp &= ~mask; |
| 148 | val |= tmp; |
| 149 | } |
| 150 | |
| 151 | return anysee_write_reg(d, reg, val); |
| 152 | } |
| 153 | |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 154 | /* read single register with mask */ |
| 155 | static int anysee_rd_reg_mask(struct dvb_usb_device *d, u16 reg, u8 *val, |
| 156 | u8 mask) |
| 157 | { |
| 158 | int ret, i; |
| 159 | u8 tmp; |
| 160 | |
| 161 | ret = anysee_read_reg(d, reg, &tmp); |
| 162 | if (ret) |
| 163 | return ret; |
| 164 | |
| 165 | tmp &= mask; |
| 166 | |
| 167 | /* find position of the first bit */ |
| 168 | for (i = 0; i < 8; i++) { |
| 169 | if ((mask >> i) & 0x01) |
| 170 | break; |
| 171 | } |
| 172 | *val = tmp >> i; |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 177 | static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id) |
| 178 | { |
| 179 | u8 buf[] = {CMD_GET_HW_INFO}; |
| 180 | return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3); |
| 181 | } |
| 182 | |
Antti Palosaari | a13a6e1 | 2012-06-26 00:04:33 -0300 | [diff] [blame] | 183 | static int anysee_streaming_ctrl(struct dvb_frontend *fe, int onoff) |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 184 | { |
| 185 | u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00}; |
Antti Palosaari | 82026f9 | 2012-08-14 15:56:20 -0300 | [diff] [blame] | 186 | dev_dbg(&fe_to_d(fe)->udev->dev, "%s: onoff=%d\n", __func__, onoff); |
Antti Palosaari | a13a6e1 | 2012-06-26 00:04:33 -0300 | [diff] [blame] | 187 | return anysee_ctrl_msg(fe_to_d(fe), buf, sizeof(buf), NULL, 0); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval) |
| 191 | { |
| 192 | u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval}; |
Antti Palosaari | 82026f9 | 2012-08-14 15:56:20 -0300 | [diff] [blame] | 193 | dev_dbg(&d->udev->dev, "%s: state=%d interval=%d\n", __func__, |
| 194 | mode, interval); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 195 | return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); |
| 196 | } |
| 197 | |
| 198 | static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff) |
| 199 | { |
| 200 | u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff}; |
Antti Palosaari | 82026f9 | 2012-08-14 15:56:20 -0300 | [diff] [blame] | 201 | dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 202 | return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); |
| 203 | } |
| 204 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 205 | /* I2C */ |
| 206 | static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, |
| 207 | int num) |
| 208 | { |
| 209 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
Mauro Carvalho Chehab | 902571a | 2008-12-29 19:02:24 -0300 | [diff] [blame] | 210 | int ret = 0, inc, i = 0; |
Antti Palosaari | 21d2e93 | 2011-05-24 06:04:08 -0300 | [diff] [blame] | 211 | u8 buf[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */ |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 212 | |
| 213 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 214 | return -EAGAIN; |
| 215 | |
| 216 | while (i < num) { |
| 217 | if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) { |
Antti Palosaari | 21d2e93 | 2011-05-24 06:04:08 -0300 | [diff] [blame] | 218 | if (msg[i].len > 2 || msg[i+1].len > 60) { |
| 219 | ret = -EOPNOTSUPP; |
| 220 | break; |
| 221 | } |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 222 | buf[0] = CMD_I2C_READ; |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame] | 223 | buf[1] = (msg[i].addr << 1) | 0x01; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 224 | buf[2] = msg[i].buf[0]; |
Antti Palosaari | 882b82c | 2011-04-12 19:49:25 -0300 | [diff] [blame] | 225 | buf[3] = msg[i].buf[1]; |
| 226 | buf[4] = msg[i].len-1; |
Antti Palosaari | b3e6a5a | 2011-04-09 21:00:51 -0300 | [diff] [blame] | 227 | buf[5] = msg[i+1].len; |
Antti Palosaari | 21d2e93 | 2011-05-24 06:04:08 -0300 | [diff] [blame] | 228 | ret = anysee_ctrl_msg(d, buf, 6, msg[i+1].buf, |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 229 | msg[i+1].len); |
| 230 | inc = 2; |
| 231 | } else { |
Antti Palosaari | 21d2e93 | 2011-05-24 06:04:08 -0300 | [diff] [blame] | 232 | if (msg[i].len > 48) { |
| 233 | ret = -EOPNOTSUPP; |
| 234 | break; |
| 235 | } |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 236 | buf[0] = CMD_I2C_WRITE; |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame] | 237 | buf[1] = (msg[i].addr << 1); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 238 | buf[2] = msg[i].len; |
| 239 | buf[3] = 0x01; |
| 240 | memcpy(&buf[4], msg[i].buf, msg[i].len); |
Antti Palosaari | 21d2e93 | 2011-05-24 06:04:08 -0300 | [diff] [blame] | 241 | ret = anysee_ctrl_msg(d, buf, 4 + msg[i].len, NULL, 0); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 242 | inc = 1; |
| 243 | } |
| 244 | if (ret) |
Antti Palosaari | e613f8f | 2008-08-11 10:36:43 -0300 | [diff] [blame] | 245 | break; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 246 | |
| 247 | i += inc; |
| 248 | } |
| 249 | |
| 250 | mutex_unlock(&d->i2c_mutex); |
| 251 | |
Antti Palosaari | e613f8f | 2008-08-11 10:36:43 -0300 | [diff] [blame] | 252 | return ret ? ret : i; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | static u32 anysee_i2c_func(struct i2c_adapter *adapter) |
| 256 | { |
| 257 | return I2C_FUNC_I2C; |
| 258 | } |
| 259 | |
| 260 | static struct i2c_algorithm anysee_i2c_algo = { |
| 261 | .master_xfer = anysee_master_xfer, |
| 262 | .functionality = anysee_i2c_func, |
| 263 | }; |
| 264 | |
| 265 | static int anysee_mt352_demod_init(struct dvb_frontend *fe) |
| 266 | { |
Antti Palosaari | ae3745f | 2009-09-16 19:50:25 -0300 | [diff] [blame] | 267 | static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 }; |
| 268 | static u8 reset[] = { RESET, 0x80 }; |
| 269 | static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 }; |
| 270 | static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 }; |
| 271 | static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 }; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 272 | static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 }; |
| 273 | |
| 274 | mt352_write(fe, clock_config, sizeof(clock_config)); |
| 275 | udelay(200); |
| 276 | mt352_write(fe, reset, sizeof(reset)); |
| 277 | mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg)); |
| 278 | |
| 279 | mt352_write(fe, agc_cfg, sizeof(agc_cfg)); |
| 280 | mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg)); |
| 281 | mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg)); |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | /* Callbacks for DVB USB */ |
| 287 | static struct tda10023_config anysee_tda10023_config = { |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame] | 288 | .demod_address = (0x1a >> 1), |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 289 | .invert = 0, |
| 290 | .xtal = 16000000, |
| 291 | .pll_m = 11, |
| 292 | .pll_p = 3, |
| 293 | .pll_n = 1, |
Antti Palosaari | 5ae2fca | 2008-06-09 22:58:22 -0300 | [diff] [blame] | 294 | .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C, |
| 295 | .deltaf = 0xfeeb, |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | static struct mt352_config anysee_mt352_config = { |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame] | 299 | .demod_address = (0x1e >> 1), |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 300 | .demod_init = anysee_mt352_demod_init, |
| 301 | }; |
| 302 | |
| 303 | static struct zl10353_config anysee_zl10353_config = { |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame] | 304 | .demod_address = (0x1e >> 1), |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 305 | .parallel_ts = 1, |
| 306 | }; |
| 307 | |
Antti Palosaari | 1fd8070 | 2011-04-12 17:34:08 -0300 | [diff] [blame] | 308 | static struct zl10353_config anysee_zl10353_tda18212_config2 = { |
| 309 | .demod_address = (0x1e >> 1), |
| 310 | .parallel_ts = 1, |
| 311 | .disable_i2c_gate_ctrl = 1, |
| 312 | .no_tuner = 1, |
| 313 | .if2 = 41500, |
| 314 | }; |
| 315 | |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 316 | static struct zl10353_config anysee_zl10353_tda18212_config = { |
| 317 | .demod_address = (0x18 >> 1), |
| 318 | .parallel_ts = 1, |
| 319 | .disable_i2c_gate_ctrl = 1, |
| 320 | .no_tuner = 1, |
| 321 | .if2 = 41500, |
| 322 | }; |
| 323 | |
| 324 | static struct tda10023_config anysee_tda10023_tda18212_config = { |
| 325 | .demod_address = (0x1a >> 1), |
| 326 | .xtal = 16000000, |
| 327 | .pll_m = 12, |
| 328 | .pll_p = 3, |
| 329 | .pll_n = 1, |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 330 | .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_B, |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 331 | .deltaf = 0xba02, |
| 332 | }; |
| 333 | |
| 334 | static struct tda18212_config anysee_tda18212_config = { |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 335 | .if_dvbt_6 = 4150, |
| 336 | .if_dvbt_7 = 4150, |
| 337 | .if_dvbt_8 = 4150, |
| 338 | .if_dvbc = 5000, |
| 339 | }; |
| 340 | |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 341 | static struct tda18212_config anysee_tda18212_config2 = { |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 342 | .if_dvbt_6 = 3550, |
| 343 | .if_dvbt_7 = 3700, |
| 344 | .if_dvbt_8 = 4150, |
| 345 | .if_dvbt2_6 = 3250, |
| 346 | .if_dvbt2_7 = 4000, |
| 347 | .if_dvbt2_8 = 4000, |
| 348 | .if_dvbc = 5000, |
| 349 | }; |
| 350 | |
Antti Palosaari | f0a5310 | 2011-04-27 21:11:59 -0300 | [diff] [blame] | 351 | static struct cx24116_config anysee_cx24116_config = { |
| 352 | .demod_address = (0xaa >> 1), |
| 353 | .mpg_clk_pos_pol = 0x00, |
| 354 | .i2c_wr_max = 48, |
| 355 | }; |
| 356 | |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 357 | static struct stv0900_config anysee_stv0900_config = { |
| 358 | .demod_address = (0xd0 >> 1), |
| 359 | .demod_mode = 0, |
| 360 | .xtal = 8000000, |
| 361 | .clkmode = 3, |
| 362 | .diseqc_mode = 2, |
| 363 | .tun1_maddress = 0, |
| 364 | .tun1_adc = 1, /* 1 Vpp */ |
| 365 | .path1_mode = 3, |
| 366 | }; |
| 367 | |
| 368 | static struct stv6110_config anysee_stv6110_config = { |
| 369 | .i2c_address = (0xc0 >> 1), |
| 370 | .mclk = 16000000, |
| 371 | .clk_div = 1, |
| 372 | }; |
| 373 | |
Antti Palosaari | f0a5310 | 2011-04-27 21:11:59 -0300 | [diff] [blame] | 374 | static struct isl6423_config anysee_isl6423_config = { |
| 375 | .current_max = SEC_CURRENT_800m, |
| 376 | .curlim = SEC_CURRENT_LIM_OFF, |
| 377 | .mod_extern = 1, |
| 378 | .addr = (0x10 >> 1), |
| 379 | }; |
| 380 | |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 381 | static struct cxd2820r_config anysee_cxd2820r_config = { |
| 382 | .i2c_address = 0x6d, /* (0xda >> 1) */ |
| 383 | .ts_mode = 0x38, |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 384 | }; |
| 385 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 386 | /* |
| 387 | * New USB device strings: Mfr=1, Product=2, SerialNumber=0 |
| 388 | * Manufacturer: AMT.CO.KR |
| 389 | * |
| 390 | * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=???????? |
| 391 | * PCB: ? |
Antti Palosaari | 70fc26f | 2011-04-12 20:17:11 -0300 | [diff] [blame] | 392 | * parts: DNOS404ZH102A(MT352, DTT7579(?)) |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 393 | * |
Antti Palosaari | 05c46c0 | 2011-05-25 18:30:09 -0300 | [diff] [blame] | 394 | * E30 VID=04b4 PID=861f HW=2 FW=2.1 "anysee-T(LP)" |
| 395 | * PCB: PCB 507T (rev1.61) |
Antti Palosaari | 70fc26f | 2011-04-12 20:17:11 -0300 | [diff] [blame] | 396 | * parts: DNOS404ZH103A(ZL10353, DTT7579(?)) |
Antti Palosaari | 05c46c0 | 2011-05-25 18:30:09 -0300 | [diff] [blame] | 397 | * OEA=0a OEB=00 OEC=00 OED=ff OEE=00 |
| 398 | * IOA=45 IOB=ff IOC=00 IOD=ff IOE=00 |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 399 | * |
| 400 | * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee" |
| 401 | * PCB: 507CD (rev1.1) |
Antti Palosaari | 70fc26f | 2011-04-12 20:17:11 -0300 | [diff] [blame] | 402 | * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01 |
Antti Palosaari | 05c46c0 | 2011-05-25 18:30:09 -0300 | [diff] [blame] | 403 | * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe |
| 404 | * IOA=4f IOB=ff IOC=00 IOD=06 IOE=01 |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 405 | * IOD[0] ZL10353 1=enabled |
| 406 | * IOA[7] TS 0=enabled |
| 407 | * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not) |
| 408 | * |
| 409 | * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)" |
| 410 | * PCB: 507DC (rev0.2) |
Antti Palosaari | 70fc26f | 2011-04-12 20:17:11 -0300 | [diff] [blame] | 411 | * parts: TDA10023, DTOS403IH102B TM, CST56I01 |
Antti Palosaari | 05c46c0 | 2011-05-25 18:30:09 -0300 | [diff] [blame] | 412 | * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe |
| 413 | * IOA=4f IOB=ff IOC=00 IOD=26 IOE=01 |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 414 | * IOD[0] TDA10023 1=enabled |
| 415 | * |
Antti Palosaari | f0a5310 | 2011-04-27 21:11:59 -0300 | [diff] [blame] | 416 | * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)" |
| 417 | * PCB: 507SI (rev2.1) |
| 418 | * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024 |
Antti Palosaari | 05c46c0 | 2011-05-25 18:30:09 -0300 | [diff] [blame] | 419 | * OEA=80 OEB=00 OEC=ff OED=ff OEE=fe |
| 420 | * IOA=4d IOB=ff IOC=00 IOD=26 IOE=01 |
Antti Palosaari | f0a5310 | 2011-04-27 21:11:59 -0300 | [diff] [blame] | 421 | * IOD[0] CX24116 1=enabled |
| 422 | * |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 423 | * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)" |
| 424 | * PCB: 507FA (rev0.4) |
Antti Palosaari | 70fc26f | 2011-04-12 20:17:11 -0300 | [diff] [blame] | 425 | * parts: TDA10023, DTOS403IH102B TM, TDA8024 |
Antti Palosaari | 05c46c0 | 2011-05-25 18:30:09 -0300 | [diff] [blame] | 426 | * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff |
| 427 | * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0 |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 428 | * IOD[5] TDA10023 1=enabled |
| 429 | * IOE[0] tuner 1=enabled |
| 430 | * |
| 431 | * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)" |
| 432 | * PCB: 507FA (rev1.1) |
Antti Palosaari | 70fc26f | 2011-04-12 20:17:11 -0300 | [diff] [blame] | 433 | * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024 |
Antti Palosaari | 05c46c0 | 2011-05-25 18:30:09 -0300 | [diff] [blame] | 434 | * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff |
| 435 | * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0 |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 436 | * DVB-C: |
| 437 | * IOD[5] TDA10023 1=enabled |
| 438 | * IOE[0] tuner 1=enabled |
| 439 | * DVB-T: |
| 440 | * IOD[0] ZL10353 1=enabled |
| 441 | * IOE[0] tuner 0=enabled |
| 442 | * tuner is behind ZL10353 I2C-gate |
Antti Palosaari | c57f87e | 2013-12-16 21:08:04 -0300 | [diff] [blame] | 443 | * tuner is behind TDA10023 I2C-gate |
Antti Palosaari | 70fc26f | 2011-04-12 20:17:11 -0300 | [diff] [blame] | 444 | * |
| 445 | * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)" |
| 446 | * PCB: 508TC (rev0.6) |
| 447 | * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212) |
Antti Palosaari | 05c46c0 | 2011-05-25 18:30:09 -0300 | [diff] [blame] | 448 | * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff |
| 449 | * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4 |
Antti Palosaari | 70fc26f | 2011-04-12 20:17:11 -0300 | [diff] [blame] | 450 | * IOA[7] TS 1=enabled |
| 451 | * IOE[4] TDA18212 1=enabled |
| 452 | * DVB-C: |
| 453 | * IOD[6] ZL10353 0=disabled |
| 454 | * IOD[5] TDA10023 1=enabled |
| 455 | * IOE[0] IF 1=enabled |
| 456 | * DVB-T: |
| 457 | * IOD[5] TDA10023 0=disabled |
| 458 | * IOD[6] ZL10353 1=enabled |
| 459 | * IOE[0] IF 0=enabled |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 460 | * |
| 461 | * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)" |
| 462 | * PCB: 508S2 (rev0.7) |
| 463 | * parts: DNBU10512IST(STV0903, STV6110), ISL6423 |
Antti Palosaari | 05c46c0 | 2011-05-25 18:30:09 -0300 | [diff] [blame] | 464 | * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff |
| 465 | * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4 |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 466 | * IOA[7] TS 1=enabled |
| 467 | * IOE[5] STV0903 1=enabled |
| 468 | * |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 469 | * E7 T2C VID=1c73 PID=861f HW=20 FW=0.1 AMTCI=0.5 "anysee-E7T2C(LP)" |
| 470 | * PCB: 508T2C (rev0.3) |
| 471 | * parts: DNOQ44QCH106A(CXD2820R, TDA18212), TDA8024 |
| 472 | * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff |
| 473 | * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4 |
| 474 | * IOA[7] TS 1=enabled |
| 475 | * IOE[5] CXD2820R 1=enabled |
| 476 | * |
Antti Palosaari | 8439e0d | 2011-05-24 07:57:34 -0300 | [diff] [blame] | 477 | * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)" |
| 478 | * PCB: 508PTC (rev0.5) |
| 479 | * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212) |
| 480 | * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff |
| 481 | * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4 |
| 482 | * IOA[7] TS 1=enabled |
| 483 | * IOE[4] TDA18212 1=enabled |
| 484 | * DVB-C: |
| 485 | * IOD[6] ZL10353 0=disabled |
| 486 | * IOD[5] TDA10023 1=enabled |
| 487 | * IOE[0] IF 1=enabled |
| 488 | * DVB-T: |
| 489 | * IOD[5] TDA10023 0=disabled |
| 490 | * IOD[6] ZL10353 1=enabled |
| 491 | * IOE[0] IF 0=enabled |
Antti Palosaari | fea3c39 | 2011-05-25 18:21:43 -0300 | [diff] [blame] | 492 | * |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 493 | * E7 PS2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)" |
Antti Palosaari | fea3c39 | 2011-05-25 18:21:43 -0300 | [diff] [blame] | 494 | * PCB: 508PS2 (rev0.4) |
| 495 | * parts: DNBU10512IST(STV0903, STV6110), ISL6423 |
| 496 | * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff |
| 497 | * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4 |
| 498 | * IOA[7] TS 1=enabled |
| 499 | * IOE[5] STV0903 1=enabled |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 500 | */ |
| 501 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 502 | static int anysee_read_config(struct dvb_usb_device *d) |
| 503 | { |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 504 | struct anysee_state *state = d_to_priv(d); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 505 | int ret; |
| 506 | u8 hw_info[3]; |
| 507 | |
| 508 | /* |
| 509 | * Check which hardware we have. |
| 510 | * We must do this call two times to get reliable values (hw/fw bug). |
| 511 | */ |
| 512 | ret = anysee_get_hw_info(d, hw_info); |
| 513 | if (ret) |
| 514 | goto error; |
| 515 | |
| 516 | ret = anysee_get_hw_info(d, hw_info); |
| 517 | if (ret) |
| 518 | goto error; |
| 519 | |
Antti Palosaari | 82026f9 | 2012-08-14 15:56:20 -0300 | [diff] [blame] | 520 | /* |
| 521 | * Meaning of these info bytes are guessed. |
| 522 | */ |
| 523 | dev_info(&d->udev->dev, "%s: firmware version %d.%d hardware id %d\n", |
| 524 | KBUILD_MODNAME, hw_info[1], hw_info[2], hw_info[0]); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 525 | |
| 526 | state->hw = hw_info[0]; |
| 527 | error: |
| 528 | return ret; |
| 529 | } |
Antti Palosaari | be94351 | 2011-09-05 22:10:05 -0300 | [diff] [blame] | 530 | |
| 531 | /* external I2C gate used for DNOD44CDH086A(TDA18212) tuner module */ |
| 532 | static int anysee_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
| 533 | { |
Antti Palosaari | be94351 | 2011-09-05 22:10:05 -0300 | [diff] [blame] | 534 | /* enable / disable tuner access on IOE[4] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 535 | return anysee_wr_reg_mask(fe_to_d(fe), REG_IOE, (enable << 4), 0x10); |
Antti Palosaari | be94351 | 2011-09-05 22:10:05 -0300 | [diff] [blame] | 536 | } |
| 537 | |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 538 | static int anysee_frontend_ctrl(struct dvb_frontend *fe, int onoff) |
| 539 | { |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 540 | struct anysee_state *state = fe_to_priv(fe); |
| 541 | struct dvb_usb_device *d = fe_to_d(fe); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 542 | int ret; |
Antti Palosaari | 82026f9 | 2012-08-14 15:56:20 -0300 | [diff] [blame] | 543 | dev_dbg(&d->udev->dev, "%s: fe=%d onoff=%d\n", __func__, fe->id, onoff); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 544 | |
| 545 | /* no frontend sleep control */ |
| 546 | if (onoff == 0) |
| 547 | return 0; |
| 548 | |
| 549 | switch (state->hw) { |
| 550 | case ANYSEE_HW_507FA: /* 15 */ |
| 551 | /* E30 Combo Plus */ |
| 552 | /* E30 C Plus */ |
| 553 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 554 | if (fe->id == 0) { |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 555 | /* disable DVB-T demod on IOD[0] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 556 | ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 0), 0x01); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 557 | if (ret) |
| 558 | goto error; |
| 559 | |
| 560 | /* enable DVB-C demod on IOD[5] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 561 | ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 562 | if (ret) |
| 563 | goto error; |
| 564 | |
| 565 | /* enable DVB-C tuner on IOE[0] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 566 | ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 0), 0x01); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 567 | if (ret) |
| 568 | goto error; |
| 569 | } else { |
| 570 | /* disable DVB-C demod on IOD[5] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 571 | ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 572 | if (ret) |
| 573 | goto error; |
| 574 | |
| 575 | /* enable DVB-T demod on IOD[0] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 576 | ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 577 | if (ret) |
| 578 | goto error; |
| 579 | |
| 580 | /* enable DVB-T tuner on IOE[0] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 581 | ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 0), 0x01); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 582 | if (ret) |
| 583 | goto error; |
| 584 | } |
| 585 | |
| 586 | break; |
| 587 | case ANYSEE_HW_508TC: /* 18 */ |
| 588 | case ANYSEE_HW_508PTC: /* 21 */ |
| 589 | /* E7 TC */ |
| 590 | /* E7 PTC */ |
| 591 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 592 | if (fe->id == 0) { |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 593 | /* disable DVB-T demod on IOD[6] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 594 | ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 6), 0x40); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 595 | if (ret) |
| 596 | goto error; |
| 597 | |
| 598 | /* enable DVB-C demod on IOD[5] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 599 | ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 600 | if (ret) |
| 601 | goto error; |
| 602 | |
| 603 | /* enable IF route on IOE[0] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 604 | ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 0), 0x01); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 605 | if (ret) |
| 606 | goto error; |
| 607 | } else { |
| 608 | /* disable DVB-C demod on IOD[5] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 609 | ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 610 | if (ret) |
| 611 | goto error; |
| 612 | |
| 613 | /* enable DVB-T demod on IOD[6] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 614 | ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 6), 0x40); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 615 | if (ret) |
| 616 | goto error; |
| 617 | |
| 618 | /* enable IF route on IOE[0] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 619 | ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 0), 0x01); |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 620 | if (ret) |
| 621 | goto error; |
| 622 | } |
| 623 | |
| 624 | break; |
| 625 | default: |
| 626 | ret = 0; |
| 627 | } |
| 628 | |
| 629 | error: |
| 630 | return ret; |
| 631 | } |
| 632 | |
Kees Cook | 7383159 | 2014-10-20 18:49:04 -0300 | [diff] [blame] | 633 | static int anysee_add_i2c_dev(struct dvb_usb_device *d, const char *type, |
| 634 | u8 addr, void *platform_data) |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 635 | { |
| 636 | int ret, num; |
| 637 | struct anysee_state *state = d_to_priv(d); |
| 638 | struct i2c_client *client; |
| 639 | struct i2c_adapter *adapter = &d->i2c_adap; |
| 640 | struct i2c_board_info board_info = { |
| 641 | .addr = addr, |
| 642 | .platform_data = platform_data, |
| 643 | }; |
| 644 | |
| 645 | strlcpy(board_info.type, type, I2C_NAME_SIZE); |
| 646 | |
| 647 | /* find first free client */ |
| 648 | for (num = 0; num < ANYSEE_I2C_CLIENT_MAX; num++) { |
| 649 | if (state->i2c_client[num] == NULL) |
| 650 | break; |
| 651 | } |
| 652 | |
| 653 | dev_dbg(&d->udev->dev, "%s: num=%d\n", __func__, num); |
| 654 | |
| 655 | if (num == ANYSEE_I2C_CLIENT_MAX) { |
| 656 | dev_err(&d->udev->dev, "%s: I2C client out of index\n", |
| 657 | KBUILD_MODNAME); |
| 658 | ret = -ENODEV; |
| 659 | goto err; |
| 660 | } |
| 661 | |
Kees Cook | 7383159 | 2014-10-20 18:49:04 -0300 | [diff] [blame] | 662 | request_module("%s", board_info.type); |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 663 | |
| 664 | /* register I2C device */ |
| 665 | client = i2c_new_device(adapter, &board_info); |
| 666 | if (client == NULL || client->dev.driver == NULL) { |
| 667 | ret = -ENODEV; |
| 668 | goto err; |
| 669 | } |
| 670 | |
| 671 | /* increase I2C driver usage count */ |
| 672 | if (!try_module_get(client->dev.driver->owner)) { |
| 673 | i2c_unregister_device(client); |
| 674 | ret = -ENODEV; |
| 675 | goto err; |
| 676 | } |
| 677 | |
| 678 | state->i2c_client[num] = client; |
| 679 | return 0; |
| 680 | err: |
| 681 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 682 | return ret; |
| 683 | } |
| 684 | |
| 685 | static void anysee_del_i2c_dev(struct dvb_usb_device *d) |
| 686 | { |
| 687 | int num; |
| 688 | struct anysee_state *state = d_to_priv(d); |
| 689 | struct i2c_client *client; |
| 690 | |
| 691 | /* find last used client */ |
| 692 | num = ANYSEE_I2C_CLIENT_MAX; |
| 693 | while (num--) { |
| 694 | if (state->i2c_client[num] != NULL) |
| 695 | break; |
| 696 | } |
| 697 | |
| 698 | dev_dbg(&d->udev->dev, "%s: num=%d\n", __func__, num); |
| 699 | |
| 700 | if (num == -1) { |
| 701 | dev_err(&d->udev->dev, "%s: I2C client out of index\n", |
| 702 | KBUILD_MODNAME); |
| 703 | goto err; |
| 704 | } |
| 705 | |
| 706 | client = state->i2c_client[num]; |
| 707 | |
| 708 | /* decrease I2C driver usage count */ |
| 709 | module_put(client->dev.driver->owner); |
| 710 | |
| 711 | /* unregister I2C device */ |
| 712 | i2c_unregister_device(client); |
| 713 | |
| 714 | state->i2c_client[num] = NULL; |
| 715 | err: |
| 716 | dev_dbg(&d->udev->dev, "%s: failed\n", __func__); |
| 717 | } |
| 718 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 719 | static int anysee_frontend_attach(struct dvb_usb_adapter *adap) |
| 720 | { |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 721 | struct anysee_state *state = adap_to_priv(adap); |
| 722 | struct dvb_usb_device *d = adap_to_d(adap); |
Geert Uytterhoeven | ecb52ab | 2013-04-24 07:36:45 -0300 | [diff] [blame] | 723 | int ret = 0; |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 724 | u8 tmp; |
| 725 | struct i2c_msg msg[2] = { |
| 726 | { |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 727 | .addr = 0x60, |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 728 | .flags = 0, |
| 729 | .len = 1, |
| 730 | .buf = "\x00", |
| 731 | }, { |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 732 | .addr = 0x60, |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 733 | .flags = I2C_M_RD, |
| 734 | .len = 1, |
| 735 | .buf = &tmp, |
| 736 | } |
| 737 | }; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 738 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 739 | switch (state->hw) { |
Antti Palosaari | 05c46c0 | 2011-05-25 18:30:09 -0300 | [diff] [blame] | 740 | case ANYSEE_HW_507T: /* 2 */ |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 741 | /* E30 */ |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 742 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 743 | /* attach demod */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 744 | adap->fe[0] = dvb_attach(mt352_attach, &anysee_mt352_config, |
| 745 | &d->i2c_adap); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 746 | if (adap->fe[0]) |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 747 | break; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 748 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 749 | /* attach demod */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 750 | adap->fe[0] = dvb_attach(zl10353_attach, &anysee_zl10353_config, |
| 751 | &d->i2c_adap); |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 752 | |
| 753 | break; |
| 754 | case ANYSEE_HW_507CD: /* 6 */ |
| 755 | /* E30 Plus */ |
| 756 | |
| 757 | /* enable DVB-T demod on IOD[0] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 758 | ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01); |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 759 | if (ret) |
| 760 | goto error; |
| 761 | |
| 762 | /* enable transport stream on IOA[7] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 763 | ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80); |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 764 | if (ret) |
| 765 | goto error; |
| 766 | |
| 767 | /* attach demod */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 768 | adap->fe[0] = dvb_attach(zl10353_attach, &anysee_zl10353_config, |
| 769 | &d->i2c_adap); |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 770 | |
| 771 | break; |
| 772 | case ANYSEE_HW_507DC: /* 10 */ |
| 773 | /* E30 C Plus */ |
| 774 | |
| 775 | /* enable DVB-C demod on IOD[0] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 776 | ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01); |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 777 | if (ret) |
| 778 | goto error; |
| 779 | |
| 780 | /* attach demod */ |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 781 | adap->fe[0] = dvb_attach(tda10023_attach, |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 782 | &anysee_tda10023_config, &d->i2c_adap, 0x48); |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 783 | |
| 784 | break; |
Antti Palosaari | f0a5310 | 2011-04-27 21:11:59 -0300 | [diff] [blame] | 785 | case ANYSEE_HW_507SI: /* 11 */ |
| 786 | /* E30 S2 Plus */ |
| 787 | |
| 788 | /* enable DVB-S/S2 demod on IOD[0] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 789 | ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01); |
Antti Palosaari | f0a5310 | 2011-04-27 21:11:59 -0300 | [diff] [blame] | 790 | if (ret) |
| 791 | goto error; |
| 792 | |
| 793 | /* attach demod */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 794 | adap->fe[0] = dvb_attach(cx24116_attach, &anysee_cx24116_config, |
| 795 | &d->i2c_adap); |
Antti Palosaari | f0a5310 | 2011-04-27 21:11:59 -0300 | [diff] [blame] | 796 | |
| 797 | break; |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 798 | case ANYSEE_HW_507FA: /* 15 */ |
| 799 | /* E30 Combo Plus */ |
| 800 | /* E30 C Plus */ |
| 801 | |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 802 | /* enable tuner on IOE[4] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 803 | ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 4), 0x10); |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 804 | if (ret) |
| 805 | goto error; |
| 806 | |
| 807 | /* probe TDA18212 */ |
| 808 | tmp = 0; |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 809 | ret = i2c_transfer(&d->i2c_adap, msg, 2); |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 810 | if (ret == 2 && tmp == 0xc7) { |
Antti Palosaari | 82026f9 | 2012-08-14 15:56:20 -0300 | [diff] [blame] | 811 | dev_dbg(&d->udev->dev, "%s: TDA18212 found\n", |
| 812 | __func__); |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 813 | state->has_tda18212 = true; |
| 814 | } |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 815 | else |
| 816 | tmp = 0; |
| 817 | |
| 818 | /* disable tuner on IOE[4] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 819 | ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 4), 0x10); |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 820 | if (ret) |
| 821 | goto error; |
| 822 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 823 | /* disable DVB-T demod on IOD[0] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 824 | ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 0), 0x01); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 825 | if (ret) |
| 826 | goto error; |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 827 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 828 | /* enable DVB-C demod on IOD[5] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 829 | ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 830 | if (ret) |
| 831 | goto error; |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 832 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 833 | /* attach demod */ |
| 834 | if (tmp == 0xc7) { |
| 835 | /* TDA18212 config */ |
| 836 | adap->fe[0] = dvb_attach(tda10023_attach, |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 837 | &anysee_tda10023_tda18212_config, |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 838 | &d->i2c_adap, 0x48); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 839 | |
| 840 | /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */ |
| 841 | if (adap->fe[0]) |
| 842 | adap->fe[0]->ops.i2c_gate_ctrl = |
| 843 | anysee_i2c_gate_ctrl; |
| 844 | } else { |
| 845 | /* PLL config */ |
| 846 | adap->fe[0] = dvb_attach(tda10023_attach, |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 847 | &anysee_tda10023_config, |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 848 | &d->i2c_adap, 0x48); |
Antti Palosaari | 0f77c3a | 2008-08-11 10:54:16 -0300 | [diff] [blame] | 849 | } |
Antti Palosaari | e82eea7 | 2011-04-12 19:43:30 -0300 | [diff] [blame] | 850 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 851 | /* break out if first frontend attaching fails */ |
| 852 | if (!adap->fe[0]) |
| 853 | break; |
| 854 | |
| 855 | /* disable DVB-C demod on IOD[5] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 856 | ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 857 | if (ret) |
| 858 | goto error; |
| 859 | |
| 860 | /* enable DVB-T demod on IOD[0] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 861 | ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 862 | if (ret) |
| 863 | goto error; |
| 864 | |
| 865 | /* attach demod */ |
Antti Palosaari | be94351 | 2011-09-05 22:10:05 -0300 | [diff] [blame] | 866 | if (tmp == 0xc7) { |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 867 | /* TDA18212 config */ |
| 868 | adap->fe[1] = dvb_attach(zl10353_attach, |
| 869 | &anysee_zl10353_tda18212_config2, |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 870 | &d->i2c_adap); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 871 | |
| 872 | /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */ |
| 873 | if (adap->fe[1]) |
| 874 | adap->fe[1]->ops.i2c_gate_ctrl = |
| 875 | anysee_i2c_gate_ctrl; |
| 876 | } else { |
| 877 | /* PLL config */ |
| 878 | adap->fe[1] = dvb_attach(zl10353_attach, |
| 879 | &anysee_zl10353_config, |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 880 | &d->i2c_adap); |
Antti Palosaari | be94351 | 2011-09-05 22:10:05 -0300 | [diff] [blame] | 881 | } |
| 882 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 883 | break; |
Antti Palosaari | a43be98 | 2011-04-10 20:23:02 -0300 | [diff] [blame] | 884 | case ANYSEE_HW_508TC: /* 18 */ |
Antti Palosaari | 8439e0d | 2011-05-24 07:57:34 -0300 | [diff] [blame] | 885 | case ANYSEE_HW_508PTC: /* 21 */ |
Antti Palosaari | a43be98 | 2011-04-10 20:23:02 -0300 | [diff] [blame] | 886 | /* E7 TC */ |
Antti Palosaari | 8439e0d | 2011-05-24 07:57:34 -0300 | [diff] [blame] | 887 | /* E7 PTC */ |
Antti Palosaari | a43be98 | 2011-04-10 20:23:02 -0300 | [diff] [blame] | 888 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 889 | /* disable DVB-T demod on IOD[6] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 890 | ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 6), 0x40); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 891 | if (ret) |
| 892 | goto error; |
Antti Palosaari | a43be98 | 2011-04-10 20:23:02 -0300 | [diff] [blame] | 893 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 894 | /* enable DVB-C demod on IOD[5] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 895 | ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 896 | if (ret) |
| 897 | goto error; |
Antti Palosaari | a43be98 | 2011-04-10 20:23:02 -0300 | [diff] [blame] | 898 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 899 | /* attach demod */ |
| 900 | adap->fe[0] = dvb_attach(tda10023_attach, |
Antti Palosaari | 449d1a0 | 2011-07-25 20:25:21 -0300 | [diff] [blame] | 901 | &anysee_tda10023_tda18212_config, |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 902 | &d->i2c_adap, 0x48); |
Antti Palosaari | e82eea7 | 2011-04-12 19:43:30 -0300 | [diff] [blame] | 903 | |
Antti Palosaari | be94351 | 2011-09-05 22:10:05 -0300 | [diff] [blame] | 904 | /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */ |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 905 | if (adap->fe[0]) |
| 906 | adap->fe[0]->ops.i2c_gate_ctrl = anysee_i2c_gate_ctrl; |
| 907 | |
| 908 | /* break out if first frontend attaching fails */ |
| 909 | if (!adap->fe[0]) |
| 910 | break; |
| 911 | |
| 912 | /* disable DVB-C demod on IOD[5] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 913 | ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 914 | if (ret) |
| 915 | goto error; |
| 916 | |
| 917 | /* enable DVB-T demod on IOD[6] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 918 | ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 6), 0x40); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 919 | if (ret) |
| 920 | goto error; |
| 921 | |
| 922 | /* attach demod */ |
| 923 | adap->fe[1] = dvb_attach(zl10353_attach, |
| 924 | &anysee_zl10353_tda18212_config, |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 925 | &d->i2c_adap); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 926 | |
| 927 | /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */ |
| 928 | if (adap->fe[1]) |
| 929 | adap->fe[1]->ops.i2c_gate_ctrl = anysee_i2c_gate_ctrl; |
Antti Palosaari | be94351 | 2011-09-05 22:10:05 -0300 | [diff] [blame] | 930 | |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 931 | state->has_ci = true; |
| 932 | |
Antti Palosaari | a43be98 | 2011-04-10 20:23:02 -0300 | [diff] [blame] | 933 | break; |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 934 | case ANYSEE_HW_508S2: /* 19 */ |
Antti Palosaari | fea3c39 | 2011-05-25 18:21:43 -0300 | [diff] [blame] | 935 | case ANYSEE_HW_508PS2: /* 22 */ |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 936 | /* E7 S2 */ |
Antti Palosaari | fea3c39 | 2011-05-25 18:21:43 -0300 | [diff] [blame] | 937 | /* E7 PS2 */ |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 938 | |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 939 | /* enable DVB-S/S2 demod on IOE[5] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 940 | ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 5), 0x20); |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 941 | if (ret) |
| 942 | goto error; |
| 943 | |
| 944 | /* attach demod */ |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 945 | adap->fe[0] = dvb_attach(stv0900_attach, |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 946 | &anysee_stv0900_config, &d->i2c_adap, 0); |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 947 | |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 948 | state->has_ci = true; |
| 949 | |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 950 | break; |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 951 | case ANYSEE_HW_508T2C: /* 20 */ |
| 952 | /* E7 T2C */ |
| 953 | |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 954 | /* enable DVB-T/T2/C demod on IOE[5] */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 955 | ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 5), 0x20); |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 956 | if (ret) |
| 957 | goto error; |
| 958 | |
Antti Palosaari | faf2797 | 2012-01-15 14:20:50 -0300 | [diff] [blame] | 959 | /* attach demod */ |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 960 | adap->fe[0] = dvb_attach(cxd2820r_attach, |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 961 | &anysee_cxd2820r_config, &d->i2c_adap, NULL); |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 962 | |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 963 | state->has_ci = true; |
Antti Palosaari | 0f77c3a | 2008-08-11 10:54:16 -0300 | [diff] [blame] | 964 | |
| 965 | break; |
| 966 | } |
| 967 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 968 | if (!adap->fe[0]) { |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 969 | /* we have no frontend :-( */ |
| 970 | ret = -ENODEV; |
Antti Palosaari | 4458a54c | 2013-02-26 14:18:13 -0300 | [diff] [blame] | 971 | dev_err(&d->udev->dev, |
Geert Uytterhoeven | 542b329 | 2013-04-24 07:36:46 -0300 | [diff] [blame] | 972 | "%s: Unsupported Anysee version. Please report to <linux-media@vger.kernel.org>.\n", |
Antti Palosaari | 82026f9 | 2012-08-14 15:56:20 -0300 | [diff] [blame] | 973 | KBUILD_MODNAME); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 974 | } |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 975 | error: |
| 976 | return ret; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | static int anysee_tuner_attach(struct dvb_usb_adapter *adap) |
| 980 | { |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 981 | struct anysee_state *state = adap_to_priv(adap); |
| 982 | struct dvb_usb_device *d = adap_to_d(adap); |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 983 | struct dvb_frontend *fe; |
Antti Palosaari | e82eea7 | 2011-04-12 19:43:30 -0300 | [diff] [blame] | 984 | int ret; |
Antti Palosaari | 82026f9 | 2012-08-14 15:56:20 -0300 | [diff] [blame] | 985 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 986 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 987 | switch (state->hw) { |
Antti Palosaari | 05c46c0 | 2011-05-25 18:30:09 -0300 | [diff] [blame] | 988 | case ANYSEE_HW_507T: /* 2 */ |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 989 | /* E30 */ |
| 990 | |
| 991 | /* attach tuner */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 992 | fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc2 >> 1), NULL, |
| 993 | DVB_PLL_THOMSON_DTT7579); |
Antti Palosaari | e82eea7 | 2011-04-12 19:43:30 -0300 | [diff] [blame] | 994 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 995 | break; |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 996 | case ANYSEE_HW_507CD: /* 6 */ |
| 997 | /* E30 Plus */ |
| 998 | |
| 999 | /* attach tuner */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 1000 | fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc2 >> 1), |
| 1001 | &d->i2c_adap, DVB_PLL_THOMSON_DTT7579); |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 1002 | |
| 1003 | break; |
| 1004 | case ANYSEE_HW_507DC: /* 10 */ |
| 1005 | /* E30 C Plus */ |
| 1006 | |
| 1007 | /* attach tuner */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 1008 | fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc0 >> 1), |
| 1009 | &d->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A); |
Antti Palosaari | e82eea7 | 2011-04-12 19:43:30 -0300 | [diff] [blame] | 1010 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1011 | break; |
Antti Palosaari | f0a5310 | 2011-04-27 21:11:59 -0300 | [diff] [blame] | 1012 | case ANYSEE_HW_507SI: /* 11 */ |
| 1013 | /* E30 S2 Plus */ |
| 1014 | |
| 1015 | /* attach LNB controller */ |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 1016 | fe = dvb_attach(isl6423_attach, adap->fe[0], &d->i2c_adap, |
| 1017 | &anysee_isl6423_config); |
Antti Palosaari | f0a5310 | 2011-04-27 21:11:59 -0300 | [diff] [blame] | 1018 | |
| 1019 | break; |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 1020 | case ANYSEE_HW_507FA: /* 15 */ |
| 1021 | /* E30 Combo Plus */ |
| 1022 | /* E30 C Plus */ |
| 1023 | |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 1024 | /* Try first attach TDA18212 silicon tuner on IOE[4], if that |
| 1025 | * fails attach old simple PLL. */ |
| 1026 | |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 1027 | /* attach tuner */ |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1028 | if (state->has_tda18212) { |
| 1029 | struct tda18212_config tda18212_config = |
| 1030 | anysee_tda18212_config; |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1031 | |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1032 | tda18212_config.fe = adap->fe[0]; |
| 1033 | ret = anysee_add_i2c_dev(d, "tda18212", 0x60, |
| 1034 | &tda18212_config); |
| 1035 | if (ret) |
| 1036 | goto err; |
Antti Palosaari | 72ffd2b | 2011-04-10 20:14:50 -0300 | [diff] [blame] | 1037 | |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1038 | /* copy tuner ops for 2nd FE as tuner is shared */ |
| 1039 | if (adap->fe[1]) { |
| 1040 | adap->fe[1]->tuner_priv = |
| 1041 | adap->fe[0]->tuner_priv; |
| 1042 | memcpy(&adap->fe[1]->ops.tuner_ops, |
| 1043 | &adap->fe[0]->ops.tuner_ops, |
| 1044 | sizeof(struct dvb_tuner_ops)); |
| 1045 | } |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1046 | |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1047 | return 0; |
| 1048 | } else { |
| 1049 | /* attach tuner */ |
| 1050 | fe = dvb_attach(dvb_pll_attach, adap->fe[0], |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 1051 | (0xc0 >> 1), &d->i2c_adap, |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1052 | DVB_PLL_SAMSUNG_DTOS403IH102A); |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1053 | |
| 1054 | if (fe && adap->fe[1]) { |
| 1055 | /* attach tuner for 2nd FE */ |
| 1056 | fe = dvb_attach(dvb_pll_attach, adap->fe[1], |
| 1057 | (0xc0 >> 1), &d->i2c_adap, |
| 1058 | DVB_PLL_SAMSUNG_DTOS403IH102A); |
| 1059 | } |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1060 | } |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 1061 | |
| 1062 | break; |
Antti Palosaari | a43be98 | 2011-04-10 20:23:02 -0300 | [diff] [blame] | 1063 | case ANYSEE_HW_508TC: /* 18 */ |
Antti Palosaari | 8439e0d | 2011-05-24 07:57:34 -0300 | [diff] [blame] | 1064 | case ANYSEE_HW_508PTC: /* 21 */ |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1065 | { |
Antti Palosaari | a43be98 | 2011-04-10 20:23:02 -0300 | [diff] [blame] | 1066 | /* E7 TC */ |
Antti Palosaari | 8439e0d | 2011-05-24 07:57:34 -0300 | [diff] [blame] | 1067 | /* E7 PTC */ |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1068 | struct tda18212_config tda18212_config = anysee_tda18212_config; |
Antti Palosaari | a43be98 | 2011-04-10 20:23:02 -0300 | [diff] [blame] | 1069 | |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1070 | tda18212_config.fe = adap->fe[0]; |
| 1071 | ret = anysee_add_i2c_dev(d, "tda18212", 0x60, &tda18212_config); |
| 1072 | if (ret) |
| 1073 | goto err; |
Antti Palosaari | a43be98 | 2011-04-10 20:23:02 -0300 | [diff] [blame] | 1074 | |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1075 | /* copy tuner ops for 2nd FE as tuner is shared */ |
| 1076 | if (adap->fe[1]) { |
| 1077 | adap->fe[1]->tuner_priv = adap->fe[0]->tuner_priv; |
| 1078 | memcpy(&adap->fe[1]->ops.tuner_ops, |
| 1079 | &adap->fe[0]->ops.tuner_ops, |
| 1080 | sizeof(struct dvb_tuner_ops)); |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1081 | } |
| 1082 | |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1083 | return 0; |
| 1084 | } |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 1085 | case ANYSEE_HW_508S2: /* 19 */ |
Antti Palosaari | fea3c39 | 2011-05-25 18:21:43 -0300 | [diff] [blame] | 1086 | case ANYSEE_HW_508PS2: /* 22 */ |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 1087 | /* E7 S2 */ |
Antti Palosaari | fea3c39 | 2011-05-25 18:21:43 -0300 | [diff] [blame] | 1088 | /* E7 PS2 */ |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 1089 | |
| 1090 | /* attach tuner */ |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1091 | fe = dvb_attach(stv6110_attach, adap->fe[0], |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 1092 | &anysee_stv6110_config, &d->i2c_adap); |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 1093 | |
| 1094 | if (fe) { |
| 1095 | /* attach LNB controller */ |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1096 | fe = dvb_attach(isl6423_attach, adap->fe[0], |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 1097 | &d->i2c_adap, &anysee_isl6423_config); |
Antti Palosaari | bedbf3d | 2011-04-29 13:55:02 -0300 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | break; |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 1101 | |
| 1102 | case ANYSEE_HW_508T2C: /* 20 */ |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1103 | { |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 1104 | /* E7 T2C */ |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1105 | struct tda18212_config tda18212_config = |
| 1106 | anysee_tda18212_config2; |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 1107 | |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1108 | tda18212_config.fe = adap->fe[0]; |
| 1109 | ret = anysee_add_i2c_dev(d, "tda18212", 0x60, &tda18212_config); |
| 1110 | if (ret) |
| 1111 | goto err; |
Antti Palosaari | 608add8 | 2011-08-12 18:29:46 -0300 | [diff] [blame] | 1112 | |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1113 | return 0; |
| 1114 | } |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 1115 | default: |
Antti Palosaari | e82eea7 | 2011-04-12 19:43:30 -0300 | [diff] [blame] | 1116 | fe = NULL; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1117 | } |
| 1118 | |
Antti Palosaari | e82eea7 | 2011-04-12 19:43:30 -0300 | [diff] [blame] | 1119 | if (fe) |
| 1120 | ret = 0; |
| 1121 | else |
| 1122 | ret = -ENODEV; |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1123 | err: |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame] | 1124 | return ret; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1125 | } |
| 1126 | |
Antti Palosaari | 37b44a0 | 2013-01-04 15:21:26 -0300 | [diff] [blame] | 1127 | #if IS_ENABLED(CONFIG_RC_CORE) |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 1128 | static int anysee_rc_query(struct dvb_usb_device *d) |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1129 | { |
| 1130 | u8 buf[] = {CMD_GET_IR_CODE}; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1131 | u8 ircode[2]; |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 1132 | int ret; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1133 | |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 1134 | /* Remote controller is basic NEC using address byte 0x08. |
| 1135 | Anysee device RC query returns only two bytes, status and code, |
| 1136 | address byte is dropped. Also it does not return any value for |
| 1137 | NEC RCs having address byte other than 0x08. Due to that, we |
| 1138 | cannot use that device as standard NEC receiver. |
| 1139 | It could be possible make hack which reads whole code directly |
| 1140 | from device memory... */ |
| 1141 | |
| 1142 | ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode)); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1143 | if (ret) |
| 1144 | return ret; |
| 1145 | |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 1146 | if (ircode[0]) { |
Antti Palosaari | 82026f9 | 2012-08-14 15:56:20 -0300 | [diff] [blame] | 1147 | dev_dbg(&d->udev->dev, "%s: key pressed %02x\n", __func__, |
| 1148 | ircode[1]); |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 1149 | rc_keydown(d->rc_dev, RC_TYPE_NEC, |
| 1150 | RC_SCANCODE_NEC(0x08, ircode[1]), 0); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1151 | } |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 1152 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1153 | return 0; |
| 1154 | } |
| 1155 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1156 | static int anysee_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc) |
| 1157 | { |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 1158 | rc->allowed_protos = RC_BIT_NEC; |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1159 | rc->query = anysee_rc_query; |
| 1160 | rc->interval = 250; /* windows driver uses 500ms */ |
| 1161 | |
| 1162 | return 0; |
| 1163 | } |
Antti Palosaari | d5c6209 | 2012-12-09 20:12:07 -0300 | [diff] [blame] | 1164 | #else |
| 1165 | #define anysee_get_rc_config NULL |
| 1166 | #endif |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1167 | |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 1168 | static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221 *ci, int slot, |
| 1169 | int addr) |
| 1170 | { |
| 1171 | struct dvb_usb_device *d = ci->data; |
| 1172 | int ret; |
| 1173 | u8 buf[] = {CMD_CI, 0x02, 0x40 | addr >> 8, addr & 0xff, 0x00, 1}; |
| 1174 | u8 val; |
| 1175 | |
| 1176 | ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1); |
| 1177 | if (ret) |
| 1178 | return ret; |
| 1179 | |
| 1180 | return val; |
| 1181 | } |
| 1182 | |
| 1183 | static int anysee_ci_write_attribute_mem(struct dvb_ca_en50221 *ci, int slot, |
| 1184 | int addr, u8 val) |
| 1185 | { |
| 1186 | struct dvb_usb_device *d = ci->data; |
| 1187 | int ret; |
| 1188 | u8 buf[] = {CMD_CI, 0x03, 0x40 | addr >> 8, addr & 0xff, 0x00, 1, val}; |
| 1189 | |
| 1190 | ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); |
| 1191 | if (ret) |
| 1192 | return ret; |
| 1193 | |
| 1194 | return 0; |
| 1195 | } |
| 1196 | |
| 1197 | static int anysee_ci_read_cam_control(struct dvb_ca_en50221 *ci, int slot, |
| 1198 | u8 addr) |
| 1199 | { |
| 1200 | struct dvb_usb_device *d = ci->data; |
| 1201 | int ret; |
| 1202 | u8 buf[] = {CMD_CI, 0x04, 0x40, addr, 0x00, 1}; |
| 1203 | u8 val; |
| 1204 | |
| 1205 | ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1); |
| 1206 | if (ret) |
| 1207 | return ret; |
| 1208 | |
| 1209 | return val; |
| 1210 | } |
| 1211 | |
| 1212 | static int anysee_ci_write_cam_control(struct dvb_ca_en50221 *ci, int slot, |
| 1213 | u8 addr, u8 val) |
| 1214 | { |
| 1215 | struct dvb_usb_device *d = ci->data; |
| 1216 | int ret; |
| 1217 | u8 buf[] = {CMD_CI, 0x05, 0x40, addr, 0x00, 1, val}; |
| 1218 | |
| 1219 | ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); |
| 1220 | if (ret) |
| 1221 | return ret; |
| 1222 | |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
| 1226 | static int anysee_ci_slot_reset(struct dvb_ca_en50221 *ci, int slot) |
| 1227 | { |
| 1228 | struct dvb_usb_device *d = ci->data; |
| 1229 | int ret; |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 1230 | struct anysee_state *state = d_to_priv(d); |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 1231 | |
| 1232 | state->ci_cam_ready = jiffies + msecs_to_jiffies(1000); |
| 1233 | |
| 1234 | ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80); |
| 1235 | if (ret) |
| 1236 | return ret; |
| 1237 | |
| 1238 | msleep(300); |
| 1239 | |
| 1240 | ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80); |
| 1241 | if (ret) |
| 1242 | return ret; |
| 1243 | |
| 1244 | return 0; |
| 1245 | } |
| 1246 | |
| 1247 | static int anysee_ci_slot_shutdown(struct dvb_ca_en50221 *ci, int slot) |
| 1248 | { |
| 1249 | struct dvb_usb_device *d = ci->data; |
| 1250 | int ret; |
| 1251 | |
| 1252 | ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80); |
| 1253 | if (ret) |
| 1254 | return ret; |
| 1255 | |
| 1256 | msleep(30); |
| 1257 | |
| 1258 | ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80); |
| 1259 | if (ret) |
| 1260 | return ret; |
| 1261 | |
| 1262 | return 0; |
| 1263 | } |
| 1264 | |
| 1265 | static int anysee_ci_slot_ts_enable(struct dvb_ca_en50221 *ci, int slot) |
| 1266 | { |
| 1267 | struct dvb_usb_device *d = ci->data; |
| 1268 | int ret; |
| 1269 | |
| 1270 | ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 1), 0x02); |
| 1271 | if (ret) |
| 1272 | return ret; |
| 1273 | |
| 1274 | return 0; |
| 1275 | } |
| 1276 | |
| 1277 | static int anysee_ci_poll_slot_status(struct dvb_ca_en50221 *ci, int slot, |
| 1278 | int open) |
| 1279 | { |
| 1280 | struct dvb_usb_device *d = ci->data; |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 1281 | struct anysee_state *state = d_to_priv(d); |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 1282 | int ret; |
Mauro Carvalho Chehab | 03ad9fe | 2012-10-27 16:28:00 -0300 | [diff] [blame] | 1283 | u8 tmp = 0; |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 1284 | |
| 1285 | ret = anysee_rd_reg_mask(d, REG_IOC, &tmp, 0x40); |
| 1286 | if (ret) |
| 1287 | return ret; |
| 1288 | |
| 1289 | if (tmp == 0) { |
| 1290 | ret = DVB_CA_EN50221_POLL_CAM_PRESENT; |
| 1291 | if (time_after(jiffies, state->ci_cam_ready)) |
| 1292 | ret |= DVB_CA_EN50221_POLL_CAM_READY; |
| 1293 | } |
| 1294 | |
| 1295 | return ret; |
| 1296 | } |
| 1297 | |
| 1298 | static int anysee_ci_init(struct dvb_usb_device *d) |
| 1299 | { |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 1300 | struct anysee_state *state = d_to_priv(d); |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 1301 | int ret; |
| 1302 | |
| 1303 | state->ci.owner = THIS_MODULE; |
| 1304 | state->ci.read_attribute_mem = anysee_ci_read_attribute_mem; |
| 1305 | state->ci.write_attribute_mem = anysee_ci_write_attribute_mem; |
| 1306 | state->ci.read_cam_control = anysee_ci_read_cam_control; |
| 1307 | state->ci.write_cam_control = anysee_ci_write_cam_control; |
| 1308 | state->ci.slot_reset = anysee_ci_slot_reset; |
| 1309 | state->ci.slot_shutdown = anysee_ci_slot_shutdown; |
| 1310 | state->ci.slot_ts_enable = anysee_ci_slot_ts_enable; |
| 1311 | state->ci.poll_slot_status = anysee_ci_poll_slot_status; |
| 1312 | state->ci.data = d; |
| 1313 | |
| 1314 | ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80); |
| 1315 | if (ret) |
| 1316 | return ret; |
| 1317 | |
Antti Palosaari | 46de20a | 2012-01-20 17:39:17 -0300 | [diff] [blame] | 1318 | ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 2)|(0 << 1)|(0 << 0), 0x07); |
| 1319 | if (ret) |
| 1320 | return ret; |
| 1321 | |
| 1322 | ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 2)|(1 << 1)|(1 << 0), 0x07); |
| 1323 | if (ret) |
| 1324 | return ret; |
| 1325 | |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 1326 | ret = dvb_ca_en50221_init(&d->adapter[0].dvb_adap, &state->ci, 0, 1); |
| 1327 | if (ret) |
| 1328 | return ret; |
| 1329 | |
Antti Palosaari | f606876 | 2012-09-22 13:46:24 -0300 | [diff] [blame] | 1330 | state->ci_attached = true; |
| 1331 | |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 1332 | return 0; |
| 1333 | } |
| 1334 | |
| 1335 | static void anysee_ci_release(struct dvb_usb_device *d) |
| 1336 | { |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 1337 | struct anysee_state *state = d_to_priv(d); |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 1338 | |
| 1339 | /* detach CI */ |
Antti Palosaari | f606876 | 2012-09-22 13:46:24 -0300 | [diff] [blame] | 1340 | if (state->ci_attached) |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 1341 | dvb_ca_en50221_release(&state->ci); |
| 1342 | |
| 1343 | return; |
| 1344 | } |
| 1345 | |
| 1346 | static int anysee_init(struct dvb_usb_device *d) |
| 1347 | { |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 1348 | struct anysee_state *state = d_to_priv(d); |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 1349 | int ret; |
| 1350 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1351 | /* There is one interface with two alternate settings. |
| 1352 | Alternate setting 0 is for bulk transfer. |
| 1353 | Alternate setting 1 is for isochronous transfer. |
| 1354 | We use bulk transfer (alternate setting 0). */ |
| 1355 | ret = usb_set_interface(d->udev, 0, 0); |
| 1356 | if (ret) |
| 1357 | return ret; |
| 1358 | |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 1359 | /* LED light */ |
| 1360 | ret = anysee_led_ctrl(d, 0x01, 0x03); |
| 1361 | if (ret) |
| 1362 | return ret; |
| 1363 | |
| 1364 | /* enable IR */ |
| 1365 | ret = anysee_ir_ctrl(d, 1); |
| 1366 | if (ret) |
| 1367 | return ret; |
| 1368 | |
| 1369 | /* attach CI */ |
| 1370 | if (state->has_ci) { |
| 1371 | ret = anysee_ci_init(d); |
Antti Palosaari | f606876 | 2012-09-22 13:46:24 -0300 | [diff] [blame] | 1372 | if (ret) |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 1373 | return ret; |
Antti Palosaari | 05cd37d | 2011-09-05 23:33:04 -0300 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | return 0; |
| 1377 | } |
| 1378 | |
Antti Palosaari | 831511b | 2012-06-20 00:32:53 -0300 | [diff] [blame] | 1379 | static void anysee_exit(struct dvb_usb_device *d) |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1380 | { |
Antti Palosaari | f80f2ae | 2014-08-03 21:47:10 -0300 | [diff] [blame] | 1381 | struct anysee_state *state = d_to_priv(d); |
| 1382 | |
| 1383 | if (state->i2c_client[0]) |
| 1384 | anysee_del_i2c_dev(d); |
| 1385 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1386 | return anysee_ci_release(d); |
| 1387 | } |
| 1388 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1389 | /* DVB USB Driver stuff */ |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1390 | static struct dvb_usb_device_properties anysee_props = { |
| 1391 | .driver_name = KBUILD_MODNAME, |
| 1392 | .owner = THIS_MODULE, |
| 1393 | .adapter_nr = adapter_nr, |
| 1394 | .size_of_priv = sizeof(struct anysee_state), |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1395 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1396 | .generic_bulk_ctrl_endpoint = 0x01, |
| 1397 | .generic_bulk_ctrl_endpoint_response = 0x81, |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1398 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1399 | .i2c_algo = &anysee_i2c_algo, |
| 1400 | .read_config = anysee_read_config, |
| 1401 | .frontend_attach = anysee_frontend_attach, |
| 1402 | .tuner_attach = anysee_tuner_attach, |
| 1403 | .init = anysee_init, |
| 1404 | .get_rc_config = anysee_get_rc_config, |
| 1405 | .frontend_ctrl = anysee_frontend_ctrl, |
| 1406 | .streaming_ctrl = anysee_streaming_ctrl, |
Antti Palosaari | 831511b | 2012-06-20 00:32:53 -0300 | [diff] [blame] | 1407 | .exit = anysee_exit, |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1408 | |
| 1409 | .num_adapters = 1, |
| 1410 | .adapter = { |
| 1411 | { |
Antti Palosaari | 05cd62e | 2012-06-18 19:39:02 -0300 | [diff] [blame] | 1412 | .stream = DVB_USB_STREAM_BULK(0x82, 8, 16 * 512), |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1413 | } |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1414 | } |
| 1415 | }; |
| 1416 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1417 | static const struct usb_device_id anysee_id_table[] = { |
| 1418 | { DVB_USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE, |
| 1419 | &anysee_props, "Anysee", RC_MAP_ANYSEE) }, |
| 1420 | { DVB_USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE, |
| 1421 | &anysee_props, "Anysee", RC_MAP_ANYSEE) }, |
| 1422 | { } |
| 1423 | }; |
| 1424 | MODULE_DEVICE_TABLE(usb, anysee_id_table); |
| 1425 | |
| 1426 | static struct usb_driver anysee_usb_driver = { |
| 1427 | .name = KBUILD_MODNAME, |
| 1428 | .id_table = anysee_id_table, |
| 1429 | .probe = dvb_usbv2_probe, |
| 1430 | .disconnect = dvb_usbv2_disconnect, |
| 1431 | .suspend = dvb_usbv2_suspend, |
| 1432 | .resume = dvb_usbv2_resume, |
Antti Palosaari | 04966aa | 2012-08-14 22:21:08 -0300 | [diff] [blame] | 1433 | .reset_resume = dvb_usbv2_reset_resume, |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1434 | .no_dynamic_id = 1, |
| 1435 | .soft_unbind = 1, |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1436 | }; |
| 1437 | |
Antti Palosaari | a4e7c51 | 2012-06-14 04:56:09 -0300 | [diff] [blame] | 1438 | module_usb_driver(anysee_usb_driver); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1439 | |
| 1440 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 1441 | MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0"); |
| 1442 | MODULE_LICENSE("GPL"); |