Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 1 | /* |
| 2 | * NXP TDA18212HN silicon tuner driver |
| 3 | * |
| 4 | * Copyright (C) 2011 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 along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
Joe Perches | 2b50763 | 2011-07-31 04:30:10 -0300 | [diff] [blame] | 21 | #include "tda18212.h" |
| 22 | |
Mauro Carvalho Chehab | f1baab8 | 2013-11-02 06:07:42 -0300 | [diff] [blame] | 23 | /* Max transfer size done by I2C transfer functions */ |
| 24 | #define MAX_XFER_SIZE 64 |
| 25 | |
Joe Perches | 2b50763 | 2011-07-31 04:30:10 -0300 | [diff] [blame] | 26 | struct tda18212_priv { |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 27 | struct tda18212_config cfg; |
| 28 | struct i2c_client *client; |
Antti Palosaari | 835bf82 | 2011-11-13 11:20:08 -0300 | [diff] [blame] | 29 | |
| 30 | u32 if_frequency; |
Joe Perches | 2b50763 | 2011-07-31 04:30:10 -0300 | [diff] [blame] | 31 | }; |
| 32 | |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 33 | /* write multiple registers */ |
| 34 | static int tda18212_wr_regs(struct tda18212_priv *priv, u8 reg, u8 *val, |
| 35 | int len) |
| 36 | { |
| 37 | int ret; |
Mauro Carvalho Chehab | f1baab8 | 2013-11-02 06:07:42 -0300 | [diff] [blame] | 38 | u8 buf[MAX_XFER_SIZE]; |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 39 | struct i2c_msg msg[1] = { |
| 40 | { |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 41 | .addr = priv->client->addr, |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 42 | .flags = 0, |
Mauro Carvalho Chehab | f1baab8 | 2013-11-02 06:07:42 -0300 | [diff] [blame] | 43 | .len = 1 + len, |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 44 | .buf = buf, |
| 45 | } |
| 46 | }; |
| 47 | |
Mauro Carvalho Chehab | f1baab8 | 2013-11-02 06:07:42 -0300 | [diff] [blame] | 48 | if (1 + len > sizeof(buf)) { |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 49 | dev_warn(&priv->client->dev, |
Mauro Carvalho Chehab | f1baab8 | 2013-11-02 06:07:42 -0300 | [diff] [blame] | 50 | "%s: i2c wr reg=%04x: len=%d is too big!\n", |
| 51 | KBUILD_MODNAME, reg, len); |
| 52 | return -EINVAL; |
| 53 | } |
| 54 | |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 55 | buf[0] = reg; |
| 56 | memcpy(&buf[1], val, len); |
| 57 | |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 58 | ret = i2c_transfer(priv->client->adapter, msg, 1); |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 59 | if (ret == 1) { |
| 60 | ret = 0; |
| 61 | } else { |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 62 | dev_warn(&priv->client->dev, "%s: i2c wr failed=%d reg=%02x len=%d\n", |
| 63 | KBUILD_MODNAME, ret, reg, len); |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 64 | ret = -EREMOTEIO; |
| 65 | } |
| 66 | return ret; |
| 67 | } |
| 68 | |
| 69 | /* read multiple registers */ |
| 70 | static int tda18212_rd_regs(struct tda18212_priv *priv, u8 reg, u8 *val, |
| 71 | int len) |
| 72 | { |
| 73 | int ret; |
Mauro Carvalho Chehab | f1baab8 | 2013-11-02 06:07:42 -0300 | [diff] [blame] | 74 | u8 buf[MAX_XFER_SIZE]; |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 75 | struct i2c_msg msg[2] = { |
| 76 | { |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 77 | .addr = priv->client->addr, |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 78 | .flags = 0, |
| 79 | .len = 1, |
| 80 | .buf = ®, |
| 81 | }, { |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 82 | .addr = priv->client->addr, |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 83 | .flags = I2C_M_RD, |
Mauro Carvalho Chehab | f1baab8 | 2013-11-02 06:07:42 -0300 | [diff] [blame] | 84 | .len = len, |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 85 | .buf = buf, |
| 86 | } |
| 87 | }; |
| 88 | |
Mauro Carvalho Chehab | f1baab8 | 2013-11-02 06:07:42 -0300 | [diff] [blame] | 89 | if (len > sizeof(buf)) { |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 90 | dev_warn(&priv->client->dev, |
Mauro Carvalho Chehab | f1baab8 | 2013-11-02 06:07:42 -0300 | [diff] [blame] | 91 | "%s: i2c rd reg=%04x: len=%d is too big!\n", |
| 92 | KBUILD_MODNAME, reg, len); |
| 93 | return -EINVAL; |
| 94 | } |
| 95 | |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 96 | ret = i2c_transfer(priv->client->adapter, msg, 2); |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 97 | if (ret == 2) { |
| 98 | memcpy(val, buf, len); |
| 99 | ret = 0; |
| 100 | } else { |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 101 | dev_warn(&priv->client->dev, "%s: i2c rd failed=%d reg=%02x len=%d\n", |
| 102 | KBUILD_MODNAME, ret, reg, len); |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 103 | ret = -EREMOTEIO; |
| 104 | } |
| 105 | |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | /* write single register */ |
| 110 | static int tda18212_wr_reg(struct tda18212_priv *priv, u8 reg, u8 val) |
| 111 | { |
| 112 | return tda18212_wr_regs(priv, reg, &val, 1); |
| 113 | } |
| 114 | |
| 115 | /* read single register */ |
| 116 | static int tda18212_rd_reg(struct tda18212_priv *priv, u8 reg, u8 *val) |
| 117 | { |
| 118 | return tda18212_rd_regs(priv, reg, val, 1); |
| 119 | } |
| 120 | |
| 121 | #if 0 /* keep, useful when developing driver */ |
| 122 | static void tda18212_dump_regs(struct tda18212_priv *priv) |
| 123 | { |
| 124 | int i; |
| 125 | u8 buf[256]; |
| 126 | |
| 127 | #define TDA18212_RD_LEN 32 |
| 128 | for (i = 0; i < sizeof(buf); i += TDA18212_RD_LEN) |
| 129 | tda18212_rd_regs(priv, i, &buf[i], TDA18212_RD_LEN); |
| 130 | |
| 131 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 32, 1, buf, |
| 132 | sizeof(buf), true); |
| 133 | |
| 134 | return; |
| 135 | } |
| 136 | #endif |
| 137 | |
Mauro Carvalho Chehab | 14d24d1 | 2011-12-24 12:24:33 -0300 | [diff] [blame] | 138 | static int tda18212_set_params(struct dvb_frontend *fe) |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 139 | { |
| 140 | struct tda18212_priv *priv = fe->tuner_priv; |
| 141 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 142 | int ret, i; |
| 143 | u32 if_khz; |
| 144 | u8 buf[9]; |
Antti Palosaari | b682ad1 | 2011-08-12 18:29:10 -0300 | [diff] [blame] | 145 | #define DVBT_6 0 |
| 146 | #define DVBT_7 1 |
| 147 | #define DVBT_8 2 |
| 148 | #define DVBT2_6 3 |
| 149 | #define DVBT2_7 4 |
| 150 | #define DVBT2_8 5 |
| 151 | #define DVBC_6 6 |
| 152 | #define DVBC_8 7 |
Mauro Carvalho Chehab | 6cff36b | 2014-03-03 16:27:38 -0300 | [diff] [blame] | 153 | #define ATSC_VSB 8 |
| 154 | #define ATSC_QAM 9 |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 155 | static const u8 bw_params[][3] = { |
Antti Palosaari | b682ad1 | 2011-08-12 18:29:10 -0300 | [diff] [blame] | 156 | /* reg: 0f 13 23 */ |
| 157 | [DVBT_6] = { 0xb3, 0x20, 0x03 }, |
| 158 | [DVBT_7] = { 0xb3, 0x31, 0x01 }, |
| 159 | [DVBT_8] = { 0xb3, 0x22, 0x01 }, |
| 160 | [DVBT2_6] = { 0xbc, 0x20, 0x03 }, |
| 161 | [DVBT2_7] = { 0xbc, 0x72, 0x03 }, |
| 162 | [DVBT2_8] = { 0xbc, 0x22, 0x01 }, |
| 163 | [DVBC_6] = { 0x92, 0x50, 0x03 }, |
| 164 | [DVBC_8] = { 0x92, 0x53, 0x03 }, |
Mauro Carvalho Chehab | 6cff36b | 2014-03-03 16:27:38 -0300 | [diff] [blame] | 165 | [ATSC_VSB] = { 0x7d, 0x20, 0x63 }, |
| 166 | [ATSC_QAM] = { 0x7d, 0x20, 0x63 }, |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 167 | }; |
| 168 | |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 169 | dev_dbg(&priv->client->dev, |
Antti Palosaari | d46ddbe | 2012-08-09 20:50:36 -0300 | [diff] [blame] | 170 | "%s: delivery_system=%d frequency=%d bandwidth_hz=%d\n", |
| 171 | __func__, c->delivery_system, c->frequency, |
| 172 | c->bandwidth_hz); |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 173 | |
| 174 | if (fe->ops.i2c_gate_ctrl) |
| 175 | fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */ |
| 176 | |
| 177 | switch (c->delivery_system) { |
Mauro Carvalho Chehab | 6cff36b | 2014-03-03 16:27:38 -0300 | [diff] [blame] | 178 | case SYS_ATSC: |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 179 | if_khz = priv->cfg.if_atsc_vsb; |
Mauro Carvalho Chehab | 6cff36b | 2014-03-03 16:27:38 -0300 | [diff] [blame] | 180 | i = ATSC_VSB; |
| 181 | break; |
| 182 | case SYS_DVBC_ANNEX_B: |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 183 | if_khz = priv->cfg.if_atsc_qam; |
Mauro Carvalho Chehab | 6cff36b | 2014-03-03 16:27:38 -0300 | [diff] [blame] | 184 | i = ATSC_QAM; |
| 185 | break; |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 186 | case SYS_DVBT: |
| 187 | switch (c->bandwidth_hz) { |
| 188 | case 6000000: |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 189 | if_khz = priv->cfg.if_dvbt_6; |
Antti Palosaari | b682ad1 | 2011-08-12 18:29:10 -0300 | [diff] [blame] | 190 | i = DVBT_6; |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 191 | break; |
| 192 | case 7000000: |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 193 | if_khz = priv->cfg.if_dvbt_7; |
Antti Palosaari | b682ad1 | 2011-08-12 18:29:10 -0300 | [diff] [blame] | 194 | i = DVBT_7; |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 195 | break; |
| 196 | case 8000000: |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 197 | if_khz = priv->cfg.if_dvbt_8; |
Antti Palosaari | b682ad1 | 2011-08-12 18:29:10 -0300 | [diff] [blame] | 198 | i = DVBT_8; |
| 199 | break; |
| 200 | default: |
| 201 | ret = -EINVAL; |
| 202 | goto error; |
| 203 | } |
| 204 | break; |
| 205 | case SYS_DVBT2: |
| 206 | switch (c->bandwidth_hz) { |
| 207 | case 6000000: |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 208 | if_khz = priv->cfg.if_dvbt2_6; |
Antti Palosaari | b682ad1 | 2011-08-12 18:29:10 -0300 | [diff] [blame] | 209 | i = DVBT2_6; |
| 210 | break; |
| 211 | case 7000000: |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 212 | if_khz = priv->cfg.if_dvbt2_7; |
Antti Palosaari | b682ad1 | 2011-08-12 18:29:10 -0300 | [diff] [blame] | 213 | i = DVBT2_7; |
| 214 | break; |
| 215 | case 8000000: |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 216 | if_khz = priv->cfg.if_dvbt2_8; |
Antti Palosaari | b682ad1 | 2011-08-12 18:29:10 -0300 | [diff] [blame] | 217 | i = DVBT2_8; |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 218 | break; |
| 219 | default: |
| 220 | ret = -EINVAL; |
| 221 | goto error; |
| 222 | } |
| 223 | break; |
Mauro Carvalho Chehab | 0349471 | 2011-12-22 18:11:39 -0300 | [diff] [blame] | 224 | case SYS_DVBC_ANNEX_A: |
| 225 | case SYS_DVBC_ANNEX_C: |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 226 | if_khz = priv->cfg.if_dvbc; |
Antti Palosaari | b682ad1 | 2011-08-12 18:29:10 -0300 | [diff] [blame] | 227 | i = DVBC_8; |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 228 | break; |
| 229 | default: |
| 230 | ret = -EINVAL; |
| 231 | goto error; |
| 232 | } |
| 233 | |
| 234 | ret = tda18212_wr_reg(priv, 0x23, bw_params[i][2]); |
| 235 | if (ret) |
| 236 | goto error; |
| 237 | |
| 238 | ret = tda18212_wr_reg(priv, 0x06, 0x00); |
| 239 | if (ret) |
| 240 | goto error; |
| 241 | |
| 242 | ret = tda18212_wr_reg(priv, 0x0f, bw_params[i][0]); |
| 243 | if (ret) |
| 244 | goto error; |
| 245 | |
| 246 | buf[0] = 0x02; |
| 247 | buf[1] = bw_params[i][1]; |
| 248 | buf[2] = 0x03; /* default value */ |
Antti Palosaari | 8cffcc7 | 2011-11-13 11:22:58 -0300 | [diff] [blame] | 249 | buf[3] = DIV_ROUND_CLOSEST(if_khz, 50); |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 250 | buf[4] = ((c->frequency / 1000) >> 16) & 0xff; |
| 251 | buf[5] = ((c->frequency / 1000) >> 8) & 0xff; |
| 252 | buf[6] = ((c->frequency / 1000) >> 0) & 0xff; |
| 253 | buf[7] = 0xc1; |
| 254 | buf[8] = 0x01; |
| 255 | ret = tda18212_wr_regs(priv, 0x12, buf, sizeof(buf)); |
| 256 | if (ret) |
| 257 | goto error; |
| 258 | |
Antti Palosaari | 835bf82 | 2011-11-13 11:20:08 -0300 | [diff] [blame] | 259 | /* actual IF rounded as it is on register */ |
| 260 | priv->if_frequency = buf[3] * 50 * 1000; |
| 261 | |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 262 | exit: |
| 263 | if (fe->ops.i2c_gate_ctrl) |
| 264 | fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ |
| 265 | |
| 266 | return ret; |
| 267 | |
| 268 | error: |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 269 | dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 270 | goto exit; |
| 271 | } |
| 272 | |
Antti Palosaari | 835bf82 | 2011-11-13 11:20:08 -0300 | [diff] [blame] | 273 | static int tda18212_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) |
| 274 | { |
| 275 | struct tda18212_priv *priv = fe->tuner_priv; |
| 276 | |
| 277 | *frequency = priv->if_frequency; |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 282 | static const struct dvb_tuner_ops tda18212_tuner_ops = { |
| 283 | .info = { |
| 284 | .name = "NXP TDA18212", |
| 285 | |
| 286 | .frequency_min = 48000000, |
| 287 | .frequency_max = 864000000, |
| 288 | .frequency_step = 1000, |
| 289 | }, |
| 290 | |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 291 | .set_params = tda18212_set_params, |
Antti Palosaari | 835bf82 | 2011-11-13 11:20:08 -0300 | [diff] [blame] | 292 | .get_if_frequency = tda18212_get_if_frequency, |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 293 | }; |
| 294 | |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 295 | static int tda18212_probe(struct i2c_client *client, |
| 296 | const struct i2c_device_id *id) |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 297 | { |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 298 | struct tda18212_config *cfg = client->dev.platform_data; |
| 299 | struct dvb_frontend *fe = cfg->fe; |
| 300 | struct tda18212_priv *priv; |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 301 | int ret; |
Antti Palosaari | 976bcb2 | 2014-07-31 16:35:56 -0300 | [diff] [blame] | 302 | u8 chip_id = chip_id; |
| 303 | char *version; |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 304 | |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 305 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 306 | if (!priv) { |
| 307 | ret = -ENOMEM; |
| 308 | dev_err(&client->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME); |
| 309 | goto err; |
| 310 | } |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 311 | |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 312 | memcpy(&priv->cfg, cfg, sizeof(struct tda18212_config)); |
| 313 | priv->client = client; |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 314 | |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 315 | /* check if the tuner is there */ |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 316 | if (fe->ops.i2c_gate_ctrl) |
| 317 | fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */ |
| 318 | |
Antti Palosaari | 976bcb2 | 2014-07-31 16:35:56 -0300 | [diff] [blame] | 319 | ret = tda18212_rd_reg(priv, 0x00, &chip_id); |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 320 | dev_dbg(&priv->client->dev, "%s: chip_id=%02x\n", __func__, chip_id); |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 321 | |
| 322 | if (fe->ops.i2c_gate_ctrl) |
| 323 | fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ |
| 324 | |
Antti Palosaari | 976bcb2 | 2014-07-31 16:35:56 -0300 | [diff] [blame] | 325 | if (ret) |
| 326 | goto err; |
| 327 | |
| 328 | switch (chip_id) { |
| 329 | case 0xc7: |
| 330 | version = "M"; /* master */ |
| 331 | break; |
| 332 | case 0x47: |
| 333 | version = "S"; /* slave */ |
| 334 | break; |
| 335 | default: |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 336 | ret = -ENODEV; |
Antti Palosaari | 976bcb2 | 2014-07-31 16:35:56 -0300 | [diff] [blame] | 337 | goto err; |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 338 | } |
| 339 | |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 340 | dev_info(&priv->client->dev, |
Antti Palosaari | 976bcb2 | 2014-07-31 16:35:56 -0300 | [diff] [blame] | 341 | "%s: NXP TDA18212HN/%s successfully identified\n", |
| 342 | KBUILD_MODNAME, version); |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 343 | |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 344 | fe->tuner_priv = priv; |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 345 | memcpy(&fe->ops.tuner_ops, &tda18212_tuner_ops, |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 346 | sizeof(struct dvb_tuner_ops)); |
| 347 | i2c_set_clientdata(client, priv); |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 348 | |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 349 | return 0; |
Antti Palosaari | 976bcb2 | 2014-07-31 16:35:56 -0300 | [diff] [blame] | 350 | err: |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 351 | dev_dbg(&client->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 976bcb2 | 2014-07-31 16:35:56 -0300 | [diff] [blame] | 352 | kfree(priv); |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 353 | return ret; |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 354 | } |
Antti Palosaari | 0e584cc | 2014-08-03 23:05:31 -0300 | [diff] [blame^] | 355 | |
| 356 | static int tda18212_remove(struct i2c_client *client) |
| 357 | { |
| 358 | struct tda18212_priv *priv = i2c_get_clientdata(client); |
| 359 | struct dvb_frontend *fe = priv->cfg.fe; |
| 360 | |
| 361 | dev_dbg(&client->dev, "%s:\n", __func__); |
| 362 | |
| 363 | memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); |
| 364 | fe->tuner_priv = NULL; |
| 365 | kfree(priv); |
| 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | static const struct i2c_device_id tda18212_id[] = { |
| 371 | {"tda18212", 0}, |
| 372 | {} |
| 373 | }; |
| 374 | MODULE_DEVICE_TABLE(i2c, tda18212_id); |
| 375 | |
| 376 | static struct i2c_driver tda18212_driver = { |
| 377 | .driver = { |
| 378 | .owner = THIS_MODULE, |
| 379 | .name = "tda18212", |
| 380 | }, |
| 381 | .probe = tda18212_probe, |
| 382 | .remove = tda18212_remove, |
| 383 | .id_table = tda18212_id, |
| 384 | }; |
| 385 | |
| 386 | module_i2c_driver(tda18212_driver); |
Antti Palosaari | 26eb704 | 2011-04-09 20:07:30 -0300 | [diff] [blame] | 387 | |
| 388 | MODULE_DESCRIPTION("NXP TDA18212HN silicon tuner driver"); |
| 389 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 390 | MODULE_LICENSE("GPL"); |