blob: 27e5bc1c3cb5d8b84f5f7cdab041c3cb2b1f5fff [file] [log] [blame]
Antti Palosaari88b38be2013-01-07 09:37:30 -03001/*
Antti Palosaari17027b92014-08-30 23:52:48 -03002 * ITE IT913X silicon tuner driver
Antti Palosaari88b38be2013-01-07 09:37:30 -03003 *
4 * Copyright (C) 2011 Malcolm Priestley (tvboxspy@gmail.com)
5 * IT9137 Copyright (C) ITE Tech Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 *
16 * GNU General Public License for more details.
Antti Palosaari88b38be2013-01-07 09:37:30 -030017 */
18
Antti Palosaari3d2f18d2014-08-28 02:07:08 -030019#include "it913x.h"
Antti Palosaari675ee802016-11-06 22:00:45 -020020#include <linux/platform_device.h>
Antti Palosaari3d2f18d2014-08-28 02:07:08 -030021#include <linux/regmap.h>
Antti Palosaari88b38be2013-01-07 09:37:30 -030022
Antti Palosaaria71b65e2014-08-26 20:11:08 -030023struct it913x_dev {
Antti Palosaari675ee802016-11-06 22:00:45 -020024 struct platform_device *pdev;
Antti Palosaarid2dbc002014-08-26 21:45:33 -030025 struct regmap *regmap;
Antti Palosaari3b2a5e82014-08-26 17:14:16 -030026 struct dvb_frontend *fe;
Antti Palosaari676c3502014-08-27 03:59:27 -030027 u8 chip_ver:2;
28 u8 role:2;
Antti Palosaari17027b92014-08-30 23:52:48 -030029 u16 xtal;
30 u8 fdiv;
31 u8 clk_mode;
32 u32 fn_min;
33 bool active;
Antti Palosaari88b38be2013-01-07 09:37:30 -030034};
35
Antti Palosaari42432b32013-02-26 20:57:01 -030036static int it913x_init(struct dvb_frontend *fe)
Antti Palosaari88b38be2013-01-07 09:37:30 -030037{
Antti Palosaaria71b65e2014-08-26 20:11:08 -030038 struct it913x_dev *dev = fe->tuner_priv;
Antti Palosaari675ee802016-11-06 22:00:45 -020039 struct platform_device *pdev = dev->pdev;
Antti Palosaari5190ff32014-08-31 00:29:33 -030040 int ret;
Antti Palosaari17027b92014-08-30 23:52:48 -030041 unsigned int utmp;
42 u8 iqik_m_cal, nv_val, buf[2];
43 static const u8 nv[] = {48, 32, 24, 16, 12, 8, 6, 4, 2};
Antti Palosaari5190ff32014-08-31 00:29:33 -030044 unsigned long timeout;
Antti Palosaari88b38be2013-01-07 09:37:30 -030045
Antti Palosaari675ee802016-11-06 22:00:45 -020046 dev_dbg(&pdev->dev, "role %u\n", dev->role);
Antti Palosaari17027b92014-08-30 23:52:48 -030047
48 ret = regmap_write(dev->regmap, 0x80ec4c, 0x68);
49 if (ret)
50 goto err;
51
52 usleep_range(10000, 100000);
53
54 ret = regmap_read(dev->regmap, 0x80ec86, &utmp);
55 if (ret)
56 goto err;
57
58 switch (utmp) {
Antti Palosaari88b38be2013-01-07 09:37:30 -030059 case 0:
Antti Palosaari17027b92014-08-30 23:52:48 -030060 /* 12.000 MHz */
61 dev->clk_mode = utmp;
62 dev->xtal = 2000;
63 dev->fdiv = 3;
64 iqik_m_cal = 16;
Antti Palosaari88b38be2013-01-07 09:37:30 -030065 break;
Antti Palosaari88b38be2013-01-07 09:37:30 -030066 case 1:
Antti Palosaari17027b92014-08-30 23:52:48 -030067 /* 20.480 MHz */
68 dev->clk_mode = utmp;
69 dev->xtal = 640;
70 dev->fdiv = 1;
71 iqik_m_cal = 6;
Antti Palosaari88b38be2013-01-07 09:37:30 -030072 break;
Antti Palosaari17027b92014-08-30 23:52:48 -030073 default:
Antti Palosaari675ee802016-11-06 22:00:45 -020074 dev_err(&pdev->dev, "unknown clock identifier %d\n", utmp);
Antti Palosaari17027b92014-08-30 23:52:48 -030075 goto err;
Antti Palosaari88b38be2013-01-07 09:37:30 -030076 }
77
Antti Palosaari17027b92014-08-30 23:52:48 -030078 ret = regmap_read(dev->regmap, 0x80ed03, &utmp);
79 if (ret)
80 goto err;
Antti Palosaari88b38be2013-01-07 09:37:30 -030081
Antti Palosaari17027b92014-08-30 23:52:48 -030082 else if (utmp < ARRAY_SIZE(nv))
83 nv_val = nv[utmp];
Antti Palosaari88b38be2013-01-07 09:37:30 -030084 else
85 nv_val = 2;
86
Antti Palosaari5190ff32014-08-31 00:29:33 -030087 #define TIMEOUT 50
88 timeout = jiffies + msecs_to_jiffies(TIMEOUT);
89 while (!time_after(jiffies, timeout)) {
Antti Palosaari17027b92014-08-30 23:52:48 -030090 ret = regmap_bulk_read(dev->regmap, 0x80ed23, buf, 2);
Antti Palosaarid2dbc002014-08-26 21:45:33 -030091 if (ret)
Antti Palosaari17027b92014-08-30 23:52:48 -030092 goto err;
93
94 utmp = (buf[1] << 8) | (buf[0] << 0);
95 if (utmp)
96 break;
Antti Palosaari88b38be2013-01-07 09:37:30 -030097 }
Antti Palosaari88b38be2013-01-07 09:37:30 -030098
Antti Palosaari675ee802016-11-06 22:00:45 -020099 dev_dbg(&pdev->dev, "r_fbc_m_bdry took %u ms, val %u\n",
Antti Palosaari5190ff32014-08-31 00:29:33 -0300100 jiffies_to_msecs(jiffies) -
101 (jiffies_to_msecs(timeout) - TIMEOUT), utmp);
Antti Palosaari17027b92014-08-30 23:52:48 -0300102
103 dev->fn_min = dev->xtal * utmp;
104 dev->fn_min /= (dev->fdiv * nv_val);
105 dev->fn_min *= 1000;
Antti Palosaari675ee802016-11-06 22:00:45 -0200106 dev_dbg(&pdev->dev, "fn_min %u\n", dev->fn_min);
Antti Palosaari17027b92014-08-30 23:52:48 -0300107
Antti Palosaari5190ff32014-08-31 00:29:33 -0300108 /*
109 * Chip version BX never sets that flag so we just wait 50ms in that
110 * case. It is possible poll BX similarly than AX and then timeout in
111 * order to get 50ms delay, but that causes about 120 extra I2C
112 * messages. As for now, we just wait and reduce IO.
113 */
Antti Palosaari17027b92014-08-30 23:52:48 -0300114 if (dev->chip_ver == 1) {
Antti Palosaari5190ff32014-08-31 00:29:33 -0300115 #define TIMEOUT 50
116 timeout = jiffies + msecs_to_jiffies(TIMEOUT);
117 while (!time_after(jiffies, timeout)) {
Antti Palosaari17027b92014-08-30 23:52:48 -0300118 ret = regmap_read(dev->regmap, 0x80ec82, &utmp);
119 if (ret)
120 goto err;
121
122 if (utmp)
Antti Palosaari88b38be2013-01-07 09:37:30 -0300123 break;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300124 }
Antti Palosaari17027b92014-08-30 23:52:48 -0300125
Antti Palosaari675ee802016-11-06 22:00:45 -0200126 dev_dbg(&pdev->dev, "p_tsm_init_mode took %u ms, val %u\n",
Antti Palosaari5190ff32014-08-31 00:29:33 -0300127 jiffies_to_msecs(jiffies) -
128 (jiffies_to_msecs(timeout) - TIMEOUT), utmp);
Antti Palosaari17027b92014-08-30 23:52:48 -0300129 } else {
130 msleep(50);
Antti Palosaari88b38be2013-01-07 09:37:30 -0300131 }
132
Antti Palosaari17027b92014-08-30 23:52:48 -0300133 ret = regmap_write(dev->regmap, 0x80ed81, iqik_m_cal);
134 if (ret)
135 goto err;
Antti Palosaarid19812e2013-02-27 23:29:02 -0300136
Antti Palosaari17027b92014-08-30 23:52:48 -0300137 ret = regmap_write(dev->regmap, 0x80ec57, 0x00);
138 if (ret)
139 goto err;
140
141 ret = regmap_write(dev->regmap, 0x80ec58, 0x00);
142 if (ret)
143 goto err;
144
145 ret = regmap_write(dev->regmap, 0x80ec40, 0x01);
146 if (ret)
147 goto err;
148
149 dev->active = true;
150
151 return 0;
152err:
Antti Palosaari675ee802016-11-06 22:00:45 -0200153 dev_dbg(&pdev->dev, "failed %d\n", ret);
Antti Palosaari17027b92014-08-30 23:52:48 -0300154 return ret;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300155}
156
Antti Palosaari676c3502014-08-27 03:59:27 -0300157static int it913x_sleep(struct dvb_frontend *fe)
158{
159 struct it913x_dev *dev = fe->tuner_priv;
Antti Palosaari675ee802016-11-06 22:00:45 -0200160 struct platform_device *pdev = dev->pdev;
Antti Palosaari676c3502014-08-27 03:59:27 -0300161 int ret, len;
162
Antti Palosaari675ee802016-11-06 22:00:45 -0200163 dev_dbg(&pdev->dev, "role %u\n", dev->role);
Antti Palosaari17027b92014-08-30 23:52:48 -0300164
165 dev->active = false;
Antti Palosaari676c3502014-08-27 03:59:27 -0300166
167 ret = regmap_bulk_write(dev->regmap, 0x80ec40, "\x00", 1);
168 if (ret)
169 goto err;
170
171 /*
172 * Writing '0x00' to master tuner register '0x80ec08' causes slave tuner
173 * communication lost. Due to that, we cannot put master full sleep.
174 */
175 if (dev->role == IT913X_ROLE_DUAL_MASTER)
176 len = 4;
177 else
178 len = 15;
179
Antti Palosaari675ee802016-11-06 22:00:45 -0200180 dev_dbg(&pdev->dev, "role %u, len %d\n", dev->role, len);
Antti Palosaari676c3502014-08-27 03:59:27 -0300181
182 ret = regmap_bulk_write(dev->regmap, 0x80ec02,
183 "\x3f\x1f\x3f\x3e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
184 len);
185 if (ret)
186 goto err;
187
188 ret = regmap_bulk_write(dev->regmap, 0x80ec12, "\x00\x00\x00\x00", 4);
189 if (ret)
190 goto err;
191
192 ret = regmap_bulk_write(dev->regmap, 0x80ec17,
193 "\x00\x00\x00\x00\x00\x00\x00\x00\x00", 9);
194 if (ret)
195 goto err;
196
197 ret = regmap_bulk_write(dev->regmap, 0x80ec22,
198 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 10);
199 if (ret)
200 goto err;
201
202 ret = regmap_bulk_write(dev->regmap, 0x80ec20, "\x00", 1);
203 if (ret)
204 goto err;
205
206 ret = regmap_bulk_write(dev->regmap, 0x80ec3f, "\x01", 1);
207 if (ret)
208 goto err;
209
210 return 0;
211err:
Antti Palosaari675ee802016-11-06 22:00:45 -0200212 dev_dbg(&pdev->dev, "failed %d\n", ret);
Antti Palosaari676c3502014-08-27 03:59:27 -0300213 return ret;
214}
215
Antti Palosaari17027b92014-08-30 23:52:48 -0300216static int it913x_set_params(struct dvb_frontend *fe)
Antti Palosaari88b38be2013-01-07 09:37:30 -0300217{
Antti Palosaaria71b65e2014-08-26 20:11:08 -0300218 struct it913x_dev *dev = fe->tuner_priv;
Antti Palosaari675ee802016-11-06 22:00:45 -0200219 struct platform_device *pdev = dev->pdev;
Antti Palosaari17027b92014-08-30 23:52:48 -0300220 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
Antti Palosaari8da55c92014-08-26 18:56:46 -0300221 int ret;
Antti Palosaari17027b92014-08-30 23:52:48 -0300222 unsigned int utmp;
223 u32 pre_lo_freq, t_cal_freq;
224 u16 iqik_m_cal, n_div;
225 u8 u8tmp, n, l_band, lna_band;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300226
Antti Palosaari675ee802016-11-06 22:00:45 -0200227 dev_dbg(&pdev->dev, "role=%u, frequency %u, bandwidth_hz %u\n",
Antti Palosaari17027b92014-08-30 23:52:48 -0300228 dev->role, c->frequency, c->bandwidth_hz);
Antti Palosaari88b38be2013-01-07 09:37:30 -0300229
Antti Palosaari17027b92014-08-30 23:52:48 -0300230 if (!dev->active) {
231 ret = -EINVAL;
Antti Palosaari3d2f18d2014-08-28 02:07:08 -0300232 goto err;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300233 }
234
Antti Palosaari17027b92014-08-30 23:52:48 -0300235 if (c->frequency <= 74000000) {
Antti Palosaari88b38be2013-01-07 09:37:30 -0300236 n_div = 48;
237 n = 0;
Antti Palosaari17027b92014-08-30 23:52:48 -0300238 } else if (c->frequency <= 111000000) {
Antti Palosaari88b38be2013-01-07 09:37:30 -0300239 n_div = 32;
240 n = 1;
Antti Palosaari17027b92014-08-30 23:52:48 -0300241 } else if (c->frequency <= 148000000) {
Antti Palosaari88b38be2013-01-07 09:37:30 -0300242 n_div = 24;
243 n = 2;
Antti Palosaari17027b92014-08-30 23:52:48 -0300244 } else if (c->frequency <= 222000000) {
Antti Palosaari88b38be2013-01-07 09:37:30 -0300245 n_div = 16;
246 n = 3;
Antti Palosaari17027b92014-08-30 23:52:48 -0300247 } else if (c->frequency <= 296000000) {
Antti Palosaari88b38be2013-01-07 09:37:30 -0300248 n_div = 12;
249 n = 4;
Antti Palosaari17027b92014-08-30 23:52:48 -0300250 } else if (c->frequency <= 445000000) {
Antti Palosaari88b38be2013-01-07 09:37:30 -0300251 n_div = 8;
252 n = 5;
Antti Palosaari17027b92014-08-30 23:52:48 -0300253 } else if (c->frequency <= dev->fn_min) {
Antti Palosaari88b38be2013-01-07 09:37:30 -0300254 n_div = 6;
255 n = 6;
Antti Palosaari17027b92014-08-30 23:52:48 -0300256 } else if (c->frequency <= 950000000) {
Antti Palosaari88b38be2013-01-07 09:37:30 -0300257 n_div = 4;
258 n = 7;
Antti Palosaari17027b92014-08-30 23:52:48 -0300259 } else {
Antti Palosaari88b38be2013-01-07 09:37:30 -0300260 n_div = 2;
261 n = 0;
Antti Palosaari17027b92014-08-30 23:52:48 -0300262 }
Antti Palosaari88b38be2013-01-07 09:37:30 -0300263
Antti Palosaari17027b92014-08-30 23:52:48 -0300264 ret = regmap_read(dev->regmap, 0x80ed81, &utmp);
265 if (ret)
266 goto err;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300267
Antti Palosaari17027b92014-08-30 23:52:48 -0300268 iqik_m_cal = utmp * n_div;
269
270 if (utmp < 0x20) {
271 if (dev->clk_mode == 0)
Antti Palosaari88b38be2013-01-07 09:37:30 -0300272 iqik_m_cal = (iqik_m_cal * 9) >> 5;
273 else
274 iqik_m_cal >>= 1;
275 } else {
276 iqik_m_cal = 0x40 - iqik_m_cal;
Antti Palosaari17027b92014-08-30 23:52:48 -0300277 if (dev->clk_mode == 0)
Antti Palosaari88b38be2013-01-07 09:37:30 -0300278 iqik_m_cal = ~((iqik_m_cal * 9) >> 5);
279 else
280 iqik_m_cal = ~(iqik_m_cal >> 1);
281 }
282
Antti Palosaari17027b92014-08-30 23:52:48 -0300283 t_cal_freq = (c->frequency / 1000) * n_div * dev->fdiv;
284 pre_lo_freq = t_cal_freq / dev->xtal;
285 utmp = pre_lo_freq * dev->xtal;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300286
Antti Palosaari17027b92014-08-30 23:52:48 -0300287 if ((t_cal_freq - utmp) >= (dev->xtal >> 1))
288 pre_lo_freq++;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300289
Antti Palosaari17027b92014-08-30 23:52:48 -0300290 pre_lo_freq += (u32) n << 13;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300291 /* Frequency OMEGA_IQIK_M_CAL_MID*/
Antti Palosaari17027b92014-08-30 23:52:48 -0300292 t_cal_freq = pre_lo_freq + (u32)iqik_m_cal;
Antti Palosaari675ee802016-11-06 22:00:45 -0200293 dev_dbg(&pdev->dev, "t_cal_freq %u, pre_lo_freq %u\n",
Antti Palosaari17027b92014-08-30 23:52:48 -0300294 t_cal_freq, pre_lo_freq);
Antti Palosaari88b38be2013-01-07 09:37:30 -0300295
Antti Palosaari17027b92014-08-30 23:52:48 -0300296 if (c->frequency <= 440000000) {
297 l_band = 0;
298 lna_band = 0;
299 } else if (c->frequency <= 484000000) {
300 l_band = 1;
301 lna_band = 1;
302 } else if (c->frequency <= 533000000) {
303 l_band = 1;
304 lna_band = 2;
305 } else if (c->frequency <= 587000000) {
306 l_band = 1;
307 lna_band = 3;
308 } else if (c->frequency <= 645000000) {
309 l_band = 1;
310 lna_band = 4;
311 } else if (c->frequency <= 710000000) {
312 l_band = 1;
313 lna_band = 5;
314 } else if (c->frequency <= 782000000) {
315 l_band = 1;
316 lna_band = 6;
317 } else if (c->frequency <= 860000000) {
318 l_band = 1;
319 lna_band = 7;
320 } else if (c->frequency <= 1492000000) {
321 l_band = 1;
322 lna_band = 0;
323 } else if (c->frequency <= 1685000000) {
324 l_band = 1;
325 lna_band = 1;
326 } else {
327 ret = -EINVAL;
328 goto err;
329 }
330
331 /* XXX: latest windows driver does not set that at all */
332 ret = regmap_write(dev->regmap, 0x80ee06, lna_band);
Antti Palosaari3d2f18d2014-08-28 02:07:08 -0300333 if (ret)
334 goto err;
335
Antti Palosaari17027b92014-08-30 23:52:48 -0300336 if (c->bandwidth_hz <= 5000000)
337 u8tmp = 0;
338 else if (c->bandwidth_hz <= 6000000)
339 u8tmp = 2;
340 else if (c->bandwidth_hz <= 7000000)
341 u8tmp = 4;
342 else
343 u8tmp = 6; /* 8000000 */
344
345 ret = regmap_write(dev->regmap, 0x80ec56, u8tmp);
Antti Palosaari3d2f18d2014-08-28 02:07:08 -0300346 if (ret)
347 goto err;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300348
Antti Palosaari17027b92014-08-30 23:52:48 -0300349 /* XXX: latest windows driver sets different value (a8 != 68) */
350 ret = regmap_write(dev->regmap, 0x80ec4c, 0xa0 | (l_band << 3));
Antti Palosaari3d2f18d2014-08-28 02:07:08 -0300351 if (ret)
352 goto err;
353
Antti Palosaari17027b92014-08-30 23:52:48 -0300354 ret = regmap_write(dev->regmap, 0x80ec4d, (t_cal_freq >> 0) & 0xff);
Antti Palosaari3d2f18d2014-08-28 02:07:08 -0300355 if (ret)
356 goto err;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300357
Antti Palosaari17027b92014-08-30 23:52:48 -0300358 ret = regmap_write(dev->regmap, 0x80ec4e, (t_cal_freq >> 8) & 0xff);
359 if (ret)
360 goto err;
361
362 ret = regmap_write(dev->regmap, 0x80011e, (pre_lo_freq >> 0) & 0xff);
363 if (ret)
364 goto err;
365
366 ret = regmap_write(dev->regmap, 0x80011f, (pre_lo_freq >> 8) & 0xff);
367 if (ret)
368 goto err;
369
Antti Palosaari3d2f18d2014-08-28 02:07:08 -0300370 return 0;
371err:
Antti Palosaari675ee802016-11-06 22:00:45 -0200372 dev_dbg(&pdev->dev, "failed %d\n", ret);
Antti Palosaari3d2f18d2014-08-28 02:07:08 -0300373 return ret;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300374}
375
Antti Palosaari88b38be2013-01-07 09:37:30 -0300376static const struct dvb_tuner_ops it913x_tuner_ops = {
377 .info = {
Antti Palosaari17027b92014-08-30 23:52:48 -0300378 .name = "ITE IT913X",
Antti Palosaari88b38be2013-01-07 09:37:30 -0300379 .frequency_min = 174000000,
380 .frequency_max = 862000000,
381 },
382
Antti Palosaari42432b32013-02-26 20:57:01 -0300383 .init = it913x_init,
384 .sleep = it913x_sleep,
Antti Palosaari17027b92014-08-30 23:52:48 -0300385 .set_params = it913x_set_params,
Antti Palosaari88b38be2013-01-07 09:37:30 -0300386};
387
Antti Palosaari675ee802016-11-06 22:00:45 -0200388static int it913x_probe(struct platform_device *pdev)
Antti Palosaari88b38be2013-01-07 09:37:30 -0300389{
Antti Palosaari675ee802016-11-06 22:00:45 -0200390 struct it913x_platform_data *pdata = pdev->dev.platform_data;
391 struct dvb_frontend *fe = pdata->fe;
Antti Palosaaria71b65e2014-08-26 20:11:08 -0300392 struct it913x_dev *dev;
Antti Palosaari8efb34b2016-11-10 01:24:50 -0200393 const struct platform_device_id *id = platform_get_device_id(pdev);
Bimow Chen01b461b2014-08-05 00:14:47 -0300394 int ret;
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300395 char *chip_ver_str;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300396
Antti Palosaaria71b65e2014-08-26 20:11:08 -0300397 dev = kzalloc(sizeof(struct it913x_dev), GFP_KERNEL);
398 if (dev == NULL) {
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300399 ret = -ENOMEM;
Antti Palosaari675ee802016-11-06 22:00:45 -0200400 dev_err(&pdev->dev, "kzalloc() failed\n");
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300401 goto err;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300402 }
403
Antti Palosaari675ee802016-11-06 22:00:45 -0200404 dev->pdev = pdev;
405 dev->regmap = pdata->regmap;
406 dev->fe = pdata->fe;
Antti Palosaari8efb34b2016-11-10 01:24:50 -0200407 dev->chip_ver = id->driver_data;
Antti Palosaari675ee802016-11-06 22:00:45 -0200408 dev->role = pdata->role;
Antti Palosaari44af7472013-02-28 00:14:06 -0300409
Antti Palosaaria71b65e2014-08-26 20:11:08 -0300410 fe->tuner_priv = dev;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300411 memcpy(&fe->ops.tuner_ops, &it913x_tuner_ops,
412 sizeof(struct dvb_tuner_ops));
Antti Palosaari675ee802016-11-06 22:00:45 -0200413 platform_set_drvdata(pdev, dev);
Antti Palosaari88b38be2013-01-07 09:37:30 -0300414
Antti Palosaaria71b65e2014-08-26 20:11:08 -0300415 if (dev->chip_ver == 1)
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300416 chip_ver_str = "AX";
Antti Palosaaria71b65e2014-08-26 20:11:08 -0300417 else if (dev->chip_ver == 2)
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300418 chip_ver_str = "BX";
419 else
420 chip_ver_str = "??";
Antti Palosaari88b38be2013-01-07 09:37:30 -0300421
Antti Palosaari675ee802016-11-06 22:00:45 -0200422 dev_info(&pdev->dev, "ITE IT913X %s successfully attached\n",
423 chip_ver_str);
424 dev_dbg(&pdev->dev, "chip_ver %u, role %u\n", dev->chip_ver, dev->role);
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300425 return 0;
426err:
Antti Palosaari675ee802016-11-06 22:00:45 -0200427 dev_dbg(&pdev->dev, "failed %d\n", ret);
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300428 return ret;
Antti Palosaari88b38be2013-01-07 09:37:30 -0300429}
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300430
Antti Palosaari675ee802016-11-06 22:00:45 -0200431static int it913x_remove(struct platform_device *pdev)
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300432{
Antti Palosaari675ee802016-11-06 22:00:45 -0200433 struct it913x_dev *dev = platform_get_drvdata(pdev);
Antti Palosaaria71b65e2014-08-26 20:11:08 -0300434 struct dvb_frontend *fe = dev->fe;
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300435
Antti Palosaari675ee802016-11-06 22:00:45 -0200436 dev_dbg(&pdev->dev, "\n");
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300437
438 memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops));
439 fe->tuner_priv = NULL;
Antti Palosaaria71b65e2014-08-26 20:11:08 -0300440 kfree(dev);
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300441
442 return 0;
443}
444
Antti Palosaari8efb34b2016-11-10 01:24:50 -0200445static const struct platform_device_id it913x_id_table[] = {
446 {"it9133ax-tuner", 1},
447 {"it9133bx-tuner", 2},
448 {},
449};
450MODULE_DEVICE_TABLE(platform, it913x_id_table);
451
Antti Palosaari675ee802016-11-06 22:00:45 -0200452static struct platform_driver it913x_driver = {
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300453 .driver = {
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300454 .name = "it913x",
Antti Palosaarid8d86362016-06-29 20:40:23 -0300455 .suppress_bind_attrs = true,
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300456 },
457 .probe = it913x_probe,
458 .remove = it913x_remove,
Antti Palosaari8efb34b2016-11-10 01:24:50 -0200459 .id_table = it913x_id_table,
Antti Palosaari3b2a5e82014-08-26 17:14:16 -0300460};
461
Antti Palosaari675ee802016-11-06 22:00:45 -0200462module_platform_driver(it913x_driver);
Antti Palosaari88b38be2013-01-07 09:37:30 -0300463
Antti Palosaari17027b92014-08-30 23:52:48 -0300464MODULE_DESCRIPTION("ITE IT913X silicon tuner driver");
Antti Palosaari88b38be2013-01-07 09:37:30 -0300465MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
466MODULE_LICENSE("GPL");