]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/media/tuners/e4000.c
29f73f61f5d352e54ecbe1e3b3d5812cb05dd163
[karo-tx-linux.git] / drivers / media / tuners / e4000.c
1 /*
2  * Elonics E4000 silicon tuner driver
3  *
4  * Copyright (C) 2012 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
21 #include "e4000_priv.h"
22 #include <linux/math64.h>
23
24 /* Max transfer size done by I2C transfer functions */
25 #define MAX_XFER_SIZE  64
26
27 /* write multiple registers */
28 static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
29 {
30         int ret;
31         u8 buf[MAX_XFER_SIZE];
32         struct i2c_msg msg[1] = {
33                 {
34                         .addr = priv->client->addr,
35                         .flags = 0,
36                         .len = 1 + len,
37                         .buf = buf,
38                 }
39         };
40
41         if (1 + len > sizeof(buf)) {
42                 dev_warn(&priv->client->dev,
43                          "%s: i2c wr reg=%04x: len=%d is too big!\n",
44                          KBUILD_MODNAME, reg, len);
45                 return -EINVAL;
46         }
47
48         buf[0] = reg;
49         memcpy(&buf[1], val, len);
50
51         ret = i2c_transfer(priv->client->adapter, msg, 1);
52         if (ret == 1) {
53                 ret = 0;
54         } else {
55                 dev_warn(&priv->client->dev,
56                                 "%s: i2c wr failed=%d reg=%02x len=%d\n",
57                                 KBUILD_MODNAME, ret, reg, len);
58                 ret = -EREMOTEIO;
59         }
60         return ret;
61 }
62
63 /* read multiple registers */
64 static int e4000_rd_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
65 {
66         int ret;
67         u8 buf[MAX_XFER_SIZE];
68         struct i2c_msg msg[2] = {
69                 {
70                         .addr = priv->client->addr,
71                         .flags = 0,
72                         .len = 1,
73                         .buf = &reg,
74                 }, {
75                         .addr = priv->client->addr,
76                         .flags = I2C_M_RD,
77                         .len = len,
78                         .buf = buf,
79                 }
80         };
81
82         if (len > sizeof(buf)) {
83                 dev_warn(&priv->client->dev,
84                          "%s: i2c rd reg=%04x: len=%d is too big!\n",
85                          KBUILD_MODNAME, reg, len);
86                 return -EINVAL;
87         }
88
89         ret = i2c_transfer(priv->client->adapter, msg, 2);
90         if (ret == 2) {
91                 memcpy(val, buf, len);
92                 ret = 0;
93         } else {
94                 dev_warn(&priv->client->dev,
95                                 "%s: i2c rd failed=%d reg=%02x len=%d\n",
96                                 KBUILD_MODNAME, ret, reg, len);
97                 ret = -EREMOTEIO;
98         }
99
100         return ret;
101 }
102
103 /* write single register */
104 static int e4000_wr_reg(struct e4000_priv *priv, u8 reg, u8 val)
105 {
106         return e4000_wr_regs(priv, reg, &val, 1);
107 }
108
109 /* read single register */
110 static int e4000_rd_reg(struct e4000_priv *priv, u8 reg, u8 *val)
111 {
112         return e4000_rd_regs(priv, reg, val, 1);
113 }
114
115 static int e4000_init(struct dvb_frontend *fe)
116 {
117         struct e4000_priv *priv = fe->tuner_priv;
118         int ret;
119
120         dev_dbg(&priv->client->dev, "%s:\n", __func__);
121
122         /* dummy I2C to ensure I2C wakes up */
123         ret = e4000_wr_reg(priv, 0x02, 0x40);
124
125         /* reset */
126         ret = e4000_wr_reg(priv, 0x00, 0x01);
127         if (ret < 0)
128                 goto err;
129
130         /* disable output clock */
131         ret = e4000_wr_reg(priv, 0x06, 0x00);
132         if (ret < 0)
133                 goto err;
134
135         ret = e4000_wr_reg(priv, 0x7a, 0x96);
136         if (ret < 0)
137                 goto err;
138
139         /* configure gains */
140         ret = e4000_wr_regs(priv, 0x7e, "\x01\xfe", 2);
141         if (ret < 0)
142                 goto err;
143
144         ret = e4000_wr_reg(priv, 0x82, 0x00);
145         if (ret < 0)
146                 goto err;
147
148         ret = e4000_wr_reg(priv, 0x24, 0x05);
149         if (ret < 0)
150                 goto err;
151
152         ret = e4000_wr_regs(priv, 0x87, "\x20\x01", 2);
153         if (ret < 0)
154                 goto err;
155
156         ret = e4000_wr_regs(priv, 0x9f, "\x7f\x07", 2);
157         if (ret < 0)
158                 goto err;
159
160         /* DC offset control */
161         ret = e4000_wr_reg(priv, 0x2d, 0x1f);
162         if (ret < 0)
163                 goto err;
164
165         ret = e4000_wr_regs(priv, 0x70, "\x01\x01", 2);
166         if (ret < 0)
167                 goto err;
168
169         /* gain control */
170         ret = e4000_wr_reg(priv, 0x1a, 0x17);
171         if (ret < 0)
172                 goto err;
173
174         ret = e4000_wr_reg(priv, 0x1f, 0x1a);
175         if (ret < 0)
176                 goto err;
177
178         priv->active = true;
179 err:
180         if (ret)
181                 dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret);
182
183         return ret;
184 }
185
186 static int e4000_sleep(struct dvb_frontend *fe)
187 {
188         struct e4000_priv *priv = fe->tuner_priv;
189         int ret;
190
191         dev_dbg(&priv->client->dev, "%s:\n", __func__);
192
193         priv->active = false;
194
195         ret = e4000_wr_reg(priv, 0x00, 0x00);
196         if (ret < 0)
197                 goto err;
198 err:
199         if (ret)
200                 dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret);
201
202         return ret;
203 }
204
205 static int e4000_set_params(struct dvb_frontend *fe)
206 {
207         struct e4000_priv *priv = fe->tuner_priv;
208         struct dtv_frontend_properties *c = &fe->dtv_property_cache;
209         int ret, i, sigma_delta;
210         u64 f_vco;
211         u8 buf[5], i_data[4], q_data[4];
212
213         dev_dbg(&priv->client->dev,
214                         "%s: delivery_system=%d frequency=%u bandwidth_hz=%u\n",
215                         __func__, c->delivery_system, c->frequency,
216                         c->bandwidth_hz);
217
218         /* gain control manual */
219         ret = e4000_wr_reg(priv, 0x1a, 0x00);
220         if (ret < 0)
221                 goto err;
222
223         /* PLL */
224         for (i = 0; i < ARRAY_SIZE(e4000_pll_lut); i++) {
225                 if (c->frequency <= e4000_pll_lut[i].freq)
226                         break;
227         }
228
229         if (i == ARRAY_SIZE(e4000_pll_lut)) {
230                 ret = -EINVAL;
231                 goto err;
232         }
233
234         f_vco = 1ull * c->frequency * e4000_pll_lut[i].mul;
235         sigma_delta = div_u64(0x10000ULL * (f_vco % priv->clock), priv->clock);
236         buf[0] = div_u64(f_vco, priv->clock);
237         buf[1] = (sigma_delta >> 0) & 0xff;
238         buf[2] = (sigma_delta >> 8) & 0xff;
239         buf[3] = 0x00;
240         buf[4] = e4000_pll_lut[i].div;
241
242         dev_dbg(&priv->client->dev,
243                         "%s: f_vco=%llu pll div=%d sigma_delta=%04x\n",
244                         __func__, f_vco, buf[0], sigma_delta);
245
246         ret = e4000_wr_regs(priv, 0x09, buf, 5);
247         if (ret < 0)
248                 goto err;
249
250         /* LNA filter (RF filter) */
251         for (i = 0; i < ARRAY_SIZE(e400_lna_filter_lut); i++) {
252                 if (c->frequency <= e400_lna_filter_lut[i].freq)
253                         break;
254         }
255
256         if (i == ARRAY_SIZE(e400_lna_filter_lut)) {
257                 ret = -EINVAL;
258                 goto err;
259         }
260
261         ret = e4000_wr_reg(priv, 0x10, e400_lna_filter_lut[i].val);
262         if (ret < 0)
263                 goto err;
264
265         /* IF filters */
266         for (i = 0; i < ARRAY_SIZE(e4000_if_filter_lut); i++) {
267                 if (c->bandwidth_hz <= e4000_if_filter_lut[i].freq)
268                         break;
269         }
270
271         if (i == ARRAY_SIZE(e4000_if_filter_lut)) {
272                 ret = -EINVAL;
273                 goto err;
274         }
275
276         buf[0] = e4000_if_filter_lut[i].reg11_val;
277         buf[1] = e4000_if_filter_lut[i].reg12_val;
278
279         ret = e4000_wr_regs(priv, 0x11, buf, 2);
280         if (ret < 0)
281                 goto err;
282
283         /* frequency band */
284         for (i = 0; i < ARRAY_SIZE(e4000_band_lut); i++) {
285                 if (c->frequency <= e4000_band_lut[i].freq)
286                         break;
287         }
288
289         if (i == ARRAY_SIZE(e4000_band_lut)) {
290                 ret = -EINVAL;
291                 goto err;
292         }
293
294         ret = e4000_wr_reg(priv, 0x07, e4000_band_lut[i].reg07_val);
295         if (ret < 0)
296                 goto err;
297
298         ret = e4000_wr_reg(priv, 0x78, e4000_band_lut[i].reg78_val);
299         if (ret < 0)
300                 goto err;
301
302         /* DC offset */
303         for (i = 0; i < 4; i++) {
304                 if (i == 0)
305                         ret = e4000_wr_regs(priv, 0x15, "\x00\x7e\x24", 3);
306                 else if (i == 1)
307                         ret = e4000_wr_regs(priv, 0x15, "\x00\x7f", 2);
308                 else if (i == 2)
309                         ret = e4000_wr_regs(priv, 0x15, "\x01", 1);
310                 else
311                         ret = e4000_wr_regs(priv, 0x16, "\x7e", 1);
312
313                 if (ret < 0)
314                         goto err;
315
316                 ret = e4000_wr_reg(priv, 0x29, 0x01);
317                 if (ret < 0)
318                         goto err;
319
320                 ret = e4000_rd_regs(priv, 0x2a, buf, 3);
321                 if (ret < 0)
322                         goto err;
323
324                 i_data[i] = (((buf[2] >> 0) & 0x3) << 6) | (buf[0] & 0x3f);
325                 q_data[i] = (((buf[2] >> 4) & 0x3) << 6) | (buf[1] & 0x3f);
326         }
327
328         swap(q_data[2], q_data[3]);
329         swap(i_data[2], i_data[3]);
330
331         ret = e4000_wr_regs(priv, 0x50, q_data, 4);
332         if (ret < 0)
333                 goto err;
334
335         ret = e4000_wr_regs(priv, 0x60, i_data, 4);
336         if (ret < 0)
337                 goto err;
338
339         /* gain control auto */
340         ret = e4000_wr_reg(priv, 0x1a, 0x17);
341         if (ret < 0)
342                 goto err;
343 err:
344         if (ret)
345                 dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret);
346
347         return ret;
348 }
349
350 static int e4000_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
351 {
352         struct e4000_priv *priv = fe->tuner_priv;
353
354         dev_dbg(&priv->client->dev, "%s:\n", __func__);
355
356         *frequency = 0; /* Zero-IF */
357
358         return 0;
359 }
360
361 static int e4000_set_lna_gain(struct dvb_frontend *fe)
362 {
363         struct e4000_priv *priv = fe->tuner_priv;
364         int ret;
365         u8 u8tmp;
366
367         dev_dbg(&priv->client->dev, "%s: lna auto=%d->%d val=%d->%d\n",
368                         __func__, priv->lna_gain_auto->cur.val,
369                         priv->lna_gain_auto->val, priv->lna_gain->cur.val,
370                         priv->lna_gain->val);
371
372         if (priv->lna_gain_auto->val && priv->if_gain_auto->cur.val)
373                 u8tmp = 0x17;
374         else if (priv->lna_gain_auto->val)
375                 u8tmp = 0x19;
376         else if (priv->if_gain_auto->cur.val)
377                 u8tmp = 0x16;
378         else
379                 u8tmp = 0x10;
380
381         ret = e4000_wr_reg(priv, 0x1a, u8tmp);
382         if (ret)
383                 goto err;
384
385         if (priv->lna_gain_auto->val == false) {
386                 ret = e4000_wr_reg(priv, 0x14, priv->lna_gain->val);
387                 if (ret)
388                         goto err;
389         }
390 err:
391         if (ret)
392                 dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret);
393
394         return ret;
395 }
396
397 static int e4000_set_mixer_gain(struct dvb_frontend *fe)
398 {
399         struct e4000_priv *priv = fe->tuner_priv;
400         int ret;
401         u8 u8tmp;
402
403         dev_dbg(&priv->client->dev, "%s: mixer auto=%d->%d val=%d->%d\n",
404                         __func__, priv->mixer_gain_auto->cur.val,
405                         priv->mixer_gain_auto->val, priv->mixer_gain->cur.val,
406                         priv->mixer_gain->val);
407
408         if (priv->mixer_gain_auto->val)
409                 u8tmp = 0x15;
410         else
411                 u8tmp = 0x14;
412
413         ret = e4000_wr_reg(priv, 0x20, u8tmp);
414         if (ret)
415                 goto err;
416
417         if (priv->mixer_gain_auto->val == false) {
418                 ret = e4000_wr_reg(priv, 0x15, priv->mixer_gain->val);
419                 if (ret)
420                         goto err;
421         }
422 err:
423         if (ret)
424                 dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret);
425
426         return ret;
427 }
428
429 static int e4000_set_if_gain(struct dvb_frontend *fe)
430 {
431         struct e4000_priv *priv = fe->tuner_priv;
432         int ret;
433         u8 buf[2];
434         u8 u8tmp;
435
436         dev_dbg(&priv->client->dev, "%s: if auto=%d->%d val=%d->%d\n",
437                         __func__, priv->if_gain_auto->cur.val,
438                         priv->if_gain_auto->val, priv->if_gain->cur.val,
439                         priv->if_gain->val);
440
441         if (priv->if_gain_auto->val && priv->lna_gain_auto->cur.val)
442                 u8tmp = 0x17;
443         else if (priv->lna_gain_auto->cur.val)
444                 u8tmp = 0x19;
445         else if (priv->if_gain_auto->val)
446                 u8tmp = 0x16;
447         else
448                 u8tmp = 0x10;
449
450         ret = e4000_wr_reg(priv, 0x1a, u8tmp);
451         if (ret)
452                 goto err;
453
454         if (priv->if_gain_auto->val == false) {
455                 buf[0] = e4000_if_gain_lut[priv->if_gain->val].reg16_val;
456                 buf[1] = e4000_if_gain_lut[priv->if_gain->val].reg17_val;
457                 ret = e4000_wr_regs(priv, 0x16, buf, 2);
458                 if (ret)
459                         goto err;
460         }
461 err:
462         if (ret)
463                 dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret);
464
465         return ret;
466 }
467
468 static int e4000_pll_lock(struct dvb_frontend *fe)
469 {
470         struct e4000_priv *priv = fe->tuner_priv;
471         int ret;
472         u8 u8tmp;
473
474         if (priv->active == false)
475                 return 0;
476
477         ret = e4000_rd_reg(priv, 0x07, &u8tmp);
478         if (ret)
479                 goto err;
480
481         priv->pll_lock->val = (u8tmp & 0x01);
482 err:
483         if (ret)
484                 dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret);
485
486         return ret;
487 }
488
489 static int e4000_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
490 {
491         struct e4000_priv *priv =
492                         container_of(ctrl->handler, struct e4000_priv, hdl);
493         int ret;
494
495         switch (ctrl->id) {
496         case  V4L2_CID_RF_TUNER_PLL_LOCK:
497                 ret = e4000_pll_lock(priv->fe);
498                 break;
499         default:
500                 ret = -EINVAL;
501         }
502
503         return ret;
504 }
505
506 static int e4000_s_ctrl(struct v4l2_ctrl *ctrl)
507 {
508         struct e4000_priv *priv =
509                         container_of(ctrl->handler, struct e4000_priv, hdl);
510         struct dvb_frontend *fe = priv->fe;
511         struct dtv_frontend_properties *c = &fe->dtv_property_cache;
512         int ret;
513
514         dev_dbg(&priv->client->dev,
515                         "%s: id=%d name=%s val=%d min=%d max=%d step=%d\n",
516                         __func__, ctrl->id, ctrl->name, ctrl->val,
517                         ctrl->minimum, ctrl->maximum, ctrl->step);
518
519         switch (ctrl->id) {
520         case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO:
521         case V4L2_CID_RF_TUNER_BANDWIDTH:
522                 c->bandwidth_hz = priv->bandwidth->val;
523                 ret = e4000_set_params(priv->fe);
524                 break;
525         case  V4L2_CID_RF_TUNER_LNA_GAIN_AUTO:
526         case  V4L2_CID_RF_TUNER_LNA_GAIN:
527                 ret = e4000_set_lna_gain(priv->fe);
528                 break;
529         case  V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO:
530         case  V4L2_CID_RF_TUNER_MIXER_GAIN:
531                 ret = e4000_set_mixer_gain(priv->fe);
532                 break;
533         case  V4L2_CID_RF_TUNER_IF_GAIN_AUTO:
534         case  V4L2_CID_RF_TUNER_IF_GAIN:
535                 ret = e4000_set_if_gain(priv->fe);
536                 break;
537         default:
538                 ret = -EINVAL;
539         }
540
541         return ret;
542 }
543
544 static const struct v4l2_ctrl_ops e4000_ctrl_ops = {
545         .g_volatile_ctrl = e4000_g_volatile_ctrl,
546         .s_ctrl = e4000_s_ctrl,
547 };
548
549 static const struct dvb_tuner_ops e4000_tuner_ops = {
550         .info = {
551                 .name           = "Elonics E4000",
552                 .frequency_min  = 174000000,
553                 .frequency_max  = 862000000,
554         },
555
556         .init = e4000_init,
557         .sleep = e4000_sleep,
558         .set_params = e4000_set_params,
559
560         .get_if_frequency = e4000_get_if_frequency,
561 };
562
563 /*
564  * Use V4L2 subdev to carry V4L2 control handler, even we don't implement
565  * subdev itself, just to avoid reinventing the wheel.
566  */
567 static int e4000_probe(struct i2c_client *client,
568                 const struct i2c_device_id *id)
569 {
570         struct e4000_config *cfg = client->dev.platform_data;
571         struct dvb_frontend *fe = cfg->fe;
572         struct e4000_priv *priv;
573         int ret;
574         u8 chip_id;
575
576         priv = kzalloc(sizeof(struct e4000_priv), GFP_KERNEL);
577         if (!priv) {
578                 ret = -ENOMEM;
579                 dev_err(&client->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME);
580                 goto err;
581         }
582
583         priv->clock = cfg->clock;
584         priv->client = client;
585         priv->fe = cfg->fe;
586
587         /* check if the tuner is there */
588         ret = e4000_rd_reg(priv, 0x02, &chip_id);
589         if (ret < 0)
590                 goto err;
591
592         dev_dbg(&priv->client->dev,
593                         "%s: chip_id=%02x\n", __func__, chip_id);
594
595         if (chip_id != 0x40) {
596                 ret = -ENODEV;
597                 goto err;
598         }
599
600         /* put sleep as chip seems to be in normal mode by default */
601         ret = e4000_wr_reg(priv, 0x00, 0x00);
602         if (ret < 0)
603                 goto err;
604
605         /* Register controls */
606         v4l2_ctrl_handler_init(&priv->hdl, 9);
607         priv->bandwidth_auto = v4l2_ctrl_new_std(&priv->hdl, &e4000_ctrl_ops,
608                         V4L2_CID_RF_TUNER_BANDWIDTH_AUTO, 0, 1, 1, 1);
609         priv->bandwidth = v4l2_ctrl_new_std(&priv->hdl, &e4000_ctrl_ops,
610                         V4L2_CID_RF_TUNER_BANDWIDTH, 4300000, 11000000, 100000, 4300000);
611         v4l2_ctrl_auto_cluster(2, &priv->bandwidth_auto, 0, false);
612         priv->lna_gain_auto = v4l2_ctrl_new_std(&priv->hdl, &e4000_ctrl_ops,
613                         V4L2_CID_RF_TUNER_LNA_GAIN_AUTO, 0, 1, 1, 1);
614         priv->lna_gain = v4l2_ctrl_new_std(&priv->hdl, &e4000_ctrl_ops,
615                         V4L2_CID_RF_TUNER_LNA_GAIN, 0, 15, 1, 10);
616         v4l2_ctrl_auto_cluster(2, &priv->lna_gain_auto, 0, false);
617         priv->mixer_gain_auto = v4l2_ctrl_new_std(&priv->hdl, &e4000_ctrl_ops,
618                         V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO, 0, 1, 1, 1);
619         priv->mixer_gain = v4l2_ctrl_new_std(&priv->hdl, &e4000_ctrl_ops,
620                         V4L2_CID_RF_TUNER_MIXER_GAIN, 0, 1, 1, 1);
621         v4l2_ctrl_auto_cluster(2, &priv->mixer_gain_auto, 0, false);
622         priv->if_gain_auto = v4l2_ctrl_new_std(&priv->hdl, &e4000_ctrl_ops,
623                         V4L2_CID_RF_TUNER_IF_GAIN_AUTO, 0, 1, 1, 1);
624         priv->if_gain = v4l2_ctrl_new_std(&priv->hdl, &e4000_ctrl_ops,
625                         V4L2_CID_RF_TUNER_IF_GAIN, 0, 54, 1, 0);
626         v4l2_ctrl_auto_cluster(2, &priv->if_gain_auto, 0, false);
627         priv->pll_lock = v4l2_ctrl_new_std(&priv->hdl, &e4000_ctrl_ops,
628                         V4L2_CID_RF_TUNER_PLL_LOCK,  0, 1, 1, 0);
629         if (priv->hdl.error) {
630                 ret = priv->hdl.error;
631                 dev_err(&priv->client->dev, "Could not initialize controls\n");
632                 v4l2_ctrl_handler_free(&priv->hdl);
633                 goto err;
634         }
635
636         priv->sd.ctrl_handler = &priv->hdl;
637
638         dev_info(&priv->client->dev,
639                         "%s: Elonics E4000 successfully identified\n",
640                         KBUILD_MODNAME);
641
642         fe->tuner_priv = priv;
643         memcpy(&fe->ops.tuner_ops, &e4000_tuner_ops,
644                         sizeof(struct dvb_tuner_ops));
645
646         v4l2_set_subdevdata(&priv->sd, client);
647         i2c_set_clientdata(client, &priv->sd);
648
649         return 0;
650 err:
651         if (ret) {
652                 dev_dbg(&client->dev, "%s: failed=%d\n", __func__, ret);
653                 kfree(priv);
654         }
655
656         return ret;
657 }
658
659 static int e4000_remove(struct i2c_client *client)
660 {
661         struct v4l2_subdev *sd = i2c_get_clientdata(client);
662         struct e4000_priv *priv = container_of(sd, struct e4000_priv, sd);
663         struct dvb_frontend *fe = priv->fe;
664
665         dev_dbg(&client->dev, "%s:\n", __func__);
666
667         v4l2_ctrl_handler_free(&priv->hdl);
668         memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops));
669         fe->tuner_priv = NULL;
670         kfree(priv);
671
672         return 0;
673 }
674
675 static const struct i2c_device_id e4000_id[] = {
676         {"e4000", 0},
677         {}
678 };
679 MODULE_DEVICE_TABLE(i2c, e4000_id);
680
681 static struct i2c_driver e4000_driver = {
682         .driver = {
683                 .owner  = THIS_MODULE,
684                 .name   = "e4000",
685         },
686         .probe          = e4000_probe,
687         .remove         = e4000_remove,
688         .id_table       = e4000_id,
689 };
690
691 module_i2c_driver(e4000_driver);
692
693 MODULE_DESCRIPTION("Elonics E4000 silicon tuner driver");
694 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
695 MODULE_LICENSE("GPL");