sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / media / dvb-frontends / cxd2820r_core.c
blob95267c6edb3a1357c463eabe4352ba40a9cc8319
1 /*
2 * Sony CXD2820R demodulator driver
4 * Copyright (C) 2010 Antti Palosaari <crope@iki.fi>
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.
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.
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.
22 #include "cxd2820r_priv.h"
24 /* Write register table */
25 int cxd2820r_wr_reg_val_mask_tab(struct cxd2820r_priv *priv,
26 const struct reg_val_mask *tab, int tab_len)
28 struct i2c_client *client = priv->client[0];
29 int ret;
30 unsigned int i, reg, mask, val;
31 struct regmap *regmap;
33 dev_dbg(&client->dev, "tab_len=%d\n", tab_len);
35 for (i = 0; i < tab_len; i++) {
36 if ((tab[i].reg >> 16) & 0x1)
37 regmap = priv->regmap[1];
38 else
39 regmap = priv->regmap[0];
41 reg = (tab[i].reg >> 0) & 0xffff;
42 val = tab[i].val;
43 mask = tab[i].mask;
45 if (mask == 0xff)
46 ret = regmap_write(regmap, reg, val);
47 else
48 ret = regmap_write_bits(regmap, reg, mask, val);
49 if (ret)
50 goto error;
53 return 0;
54 error:
55 dev_dbg(&client->dev, "failed=%d\n", ret);
56 return ret;
59 int cxd2820r_gpio(struct dvb_frontend *fe, u8 *gpio)
61 struct cxd2820r_priv *priv = fe->demodulator_priv;
62 struct i2c_client *client = priv->client[0];
63 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
64 int ret, i;
65 u8 tmp0, tmp1;
67 dev_dbg(&client->dev, "delivery_system=%d\n", c->delivery_system);
69 /* update GPIOs only when needed */
70 if (!memcmp(gpio, priv->gpio, sizeof(priv->gpio)))
71 return 0;
73 tmp0 = 0x00;
74 tmp1 = 0x00;
75 for (i = 0; i < sizeof(priv->gpio); i++) {
76 /* enable / disable */
77 if (gpio[i] & CXD2820R_GPIO_E)
78 tmp0 |= (2 << 6) >> (2 * i);
79 else
80 tmp0 |= (1 << 6) >> (2 * i);
82 /* input / output */
83 if (gpio[i] & CXD2820R_GPIO_I)
84 tmp1 |= (1 << (3 + i));
85 else
86 tmp1 |= (0 << (3 + i));
88 /* high / low */
89 if (gpio[i] & CXD2820R_GPIO_H)
90 tmp1 |= (1 << (0 + i));
91 else
92 tmp1 |= (0 << (0 + i));
94 dev_dbg(&client->dev, "gpio i=%d %02x %02x\n", i, tmp0, tmp1);
97 dev_dbg(&client->dev, "wr gpio=%02x %02x\n", tmp0, tmp1);
99 /* write bits [7:2] */
100 ret = regmap_update_bits(priv->regmap[0], 0x0089, 0xfc, tmp0);
101 if (ret)
102 goto error;
104 /* write bits [5:0] */
105 ret = regmap_update_bits(priv->regmap[0], 0x008e, 0x3f, tmp1);
106 if (ret)
107 goto error;
109 memcpy(priv->gpio, gpio, sizeof(priv->gpio));
111 return ret;
112 error:
113 dev_dbg(&client->dev, "failed=%d\n", ret);
114 return ret;
117 static int cxd2820r_set_frontend(struct dvb_frontend *fe)
119 struct cxd2820r_priv *priv = fe->demodulator_priv;
120 struct i2c_client *client = priv->client[0];
121 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
122 int ret;
124 dev_dbg(&client->dev, "delivery_system=%d\n", c->delivery_system);
126 switch (c->delivery_system) {
127 case SYS_DVBT:
128 ret = cxd2820r_init_t(fe);
129 if (ret < 0)
130 goto err;
131 ret = cxd2820r_set_frontend_t(fe);
132 if (ret < 0)
133 goto err;
134 break;
135 case SYS_DVBT2:
136 ret = cxd2820r_init_t(fe);
137 if (ret < 0)
138 goto err;
139 ret = cxd2820r_set_frontend_t2(fe);
140 if (ret < 0)
141 goto err;
142 break;
143 case SYS_DVBC_ANNEX_A:
144 ret = cxd2820r_init_c(fe);
145 if (ret < 0)
146 goto err;
147 ret = cxd2820r_set_frontend_c(fe);
148 if (ret < 0)
149 goto err;
150 break;
151 default:
152 dev_dbg(&client->dev, "invalid delivery_system\n");
153 ret = -EINVAL;
154 break;
156 err:
157 return ret;
160 static int cxd2820r_read_status(struct dvb_frontend *fe, enum fe_status *status)
162 struct cxd2820r_priv *priv = fe->demodulator_priv;
163 struct i2c_client *client = priv->client[0];
164 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
165 int ret;
167 dev_dbg(&client->dev, "delivery_system=%d\n", c->delivery_system);
169 switch (c->delivery_system) {
170 case SYS_DVBT:
171 ret = cxd2820r_read_status_t(fe, status);
172 break;
173 case SYS_DVBT2:
174 ret = cxd2820r_read_status_t2(fe, status);
175 break;
176 case SYS_DVBC_ANNEX_A:
177 ret = cxd2820r_read_status_c(fe, status);
178 break;
179 default:
180 ret = -EINVAL;
181 break;
183 return ret;
186 static int cxd2820r_get_frontend(struct dvb_frontend *fe,
187 struct dtv_frontend_properties *p)
189 struct cxd2820r_priv *priv = fe->demodulator_priv;
190 struct i2c_client *client = priv->client[0];
191 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
192 int ret;
194 dev_dbg(&client->dev, "delivery_system=%d\n", c->delivery_system);
196 if (priv->delivery_system == SYS_UNDEFINED)
197 return 0;
199 switch (c->delivery_system) {
200 case SYS_DVBT:
201 ret = cxd2820r_get_frontend_t(fe, p);
202 break;
203 case SYS_DVBT2:
204 ret = cxd2820r_get_frontend_t2(fe, p);
205 break;
206 case SYS_DVBC_ANNEX_A:
207 ret = cxd2820r_get_frontend_c(fe, p);
208 break;
209 default:
210 ret = -EINVAL;
211 break;
213 return ret;
216 static int cxd2820r_read_ber(struct dvb_frontend *fe, u32 *ber)
218 struct cxd2820r_priv *priv = fe->demodulator_priv;
219 struct i2c_client *client = priv->client[0];
220 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
222 dev_dbg(&client->dev, "delivery_system=%d\n", c->delivery_system);
224 *ber = (priv->post_bit_error - priv->post_bit_error_prev_dvbv3);
225 priv->post_bit_error_prev_dvbv3 = priv->post_bit_error;
227 return 0;
230 static int cxd2820r_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
232 struct cxd2820r_priv *priv = fe->demodulator_priv;
233 struct i2c_client *client = priv->client[0];
234 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
236 dev_dbg(&client->dev, "delivery_system=%d\n", c->delivery_system);
238 if (c->strength.stat[0].scale == FE_SCALE_RELATIVE)
239 *strength = c->strength.stat[0].uvalue;
240 else
241 *strength = 0;
243 return 0;
246 static int cxd2820r_read_snr(struct dvb_frontend *fe, u16 *snr)
248 struct cxd2820r_priv *priv = fe->demodulator_priv;
249 struct i2c_client *client = priv->client[0];
250 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
252 dev_dbg(&client->dev, "delivery_system=%d\n", c->delivery_system);
254 if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL)
255 *snr = div_s64(c->cnr.stat[0].svalue, 100);
256 else
257 *snr = 0;
259 return 0;
262 static int cxd2820r_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
264 struct cxd2820r_priv *priv = fe->demodulator_priv;
265 struct i2c_client *client = priv->client[0];
266 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
268 dev_dbg(&client->dev, "delivery_system=%d\n", c->delivery_system);
270 *ucblocks = 0;
272 return 0;
275 static int cxd2820r_init(struct dvb_frontend *fe)
277 return 0;
280 static int cxd2820r_sleep(struct dvb_frontend *fe)
282 struct cxd2820r_priv *priv = fe->demodulator_priv;
283 struct i2c_client *client = priv->client[0];
284 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
285 int ret;
287 dev_dbg(&client->dev, "delivery_system=%d\n", c->delivery_system);
289 switch (c->delivery_system) {
290 case SYS_DVBT:
291 ret = cxd2820r_sleep_t(fe);
292 break;
293 case SYS_DVBT2:
294 ret = cxd2820r_sleep_t2(fe);
295 break;
296 case SYS_DVBC_ANNEX_A:
297 ret = cxd2820r_sleep_c(fe);
298 break;
299 default:
300 ret = -EINVAL;
301 break;
303 return ret;
306 static int cxd2820r_get_tune_settings(struct dvb_frontend *fe,
307 struct dvb_frontend_tune_settings *s)
309 struct cxd2820r_priv *priv = fe->demodulator_priv;
310 struct i2c_client *client = priv->client[0];
311 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
312 int ret;
314 dev_dbg(&client->dev, "delivery_system=%d\n", c->delivery_system);
316 switch (c->delivery_system) {
317 case SYS_DVBT:
318 ret = cxd2820r_get_tune_settings_t(fe, s);
319 break;
320 case SYS_DVBT2:
321 ret = cxd2820r_get_tune_settings_t2(fe, s);
322 break;
323 case SYS_DVBC_ANNEX_A:
324 ret = cxd2820r_get_tune_settings_c(fe, s);
325 break;
326 default:
327 ret = -EINVAL;
328 break;
330 return ret;
333 static enum dvbfe_search cxd2820r_search(struct dvb_frontend *fe)
335 struct cxd2820r_priv *priv = fe->demodulator_priv;
336 struct i2c_client *client = priv->client[0];
337 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
338 int ret, i;
339 enum fe_status status = 0;
341 dev_dbg(&client->dev, "delivery_system=%d\n", c->delivery_system);
343 /* switch between DVB-T and DVB-T2 when tune fails */
344 if (priv->last_tune_failed) {
345 if (priv->delivery_system == SYS_DVBT) {
346 ret = cxd2820r_sleep_t(fe);
347 if (ret)
348 goto error;
350 c->delivery_system = SYS_DVBT2;
351 } else if (priv->delivery_system == SYS_DVBT2) {
352 ret = cxd2820r_sleep_t2(fe);
353 if (ret)
354 goto error;
356 c->delivery_system = SYS_DVBT;
360 /* set frontend */
361 ret = cxd2820r_set_frontend(fe);
362 if (ret)
363 goto error;
365 /* frontend lock wait loop count */
366 switch (priv->delivery_system) {
367 case SYS_DVBT:
368 case SYS_DVBC_ANNEX_A:
369 i = 20;
370 break;
371 case SYS_DVBT2:
372 i = 40;
373 break;
374 case SYS_UNDEFINED:
375 default:
376 i = 0;
377 break;
380 /* wait frontend lock */
381 for (; i > 0; i--) {
382 dev_dbg(&client->dev, "loop=%d\n", i);
383 msleep(50);
384 ret = cxd2820r_read_status(fe, &status);
385 if (ret)
386 goto error;
388 if (status & FE_HAS_LOCK)
389 break;
392 /* check if we have a valid signal */
393 if (status & FE_HAS_LOCK) {
394 priv->last_tune_failed = false;
395 return DVBFE_ALGO_SEARCH_SUCCESS;
396 } else {
397 priv->last_tune_failed = true;
398 return DVBFE_ALGO_SEARCH_AGAIN;
401 error:
402 dev_dbg(&client->dev, "failed=%d\n", ret);
403 return DVBFE_ALGO_SEARCH_ERROR;
406 static int cxd2820r_get_frontend_algo(struct dvb_frontend *fe)
408 return DVBFE_ALGO_CUSTOM;
411 static void cxd2820r_release(struct dvb_frontend *fe)
413 struct cxd2820r_priv *priv = fe->demodulator_priv;
414 struct i2c_client *client = priv->client[0];
416 dev_dbg(&client->dev, "\n");
418 i2c_unregister_device(client);
420 return;
423 static int cxd2820r_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
425 struct cxd2820r_priv *priv = fe->demodulator_priv;
426 struct i2c_client *client = priv->client[0];
428 dev_dbg_ratelimited(&client->dev, "enable=%d\n", enable);
430 return regmap_update_bits(priv->regmap[0], 0x00db, 0x01, enable ? 1 : 0);
433 #ifdef CONFIG_GPIOLIB
434 static int cxd2820r_gpio_direction_output(struct gpio_chip *chip, unsigned nr,
435 int val)
437 struct cxd2820r_priv *priv = gpiochip_get_data(chip);
438 struct i2c_client *client = priv->client[0];
439 u8 gpio[GPIO_COUNT];
441 dev_dbg(&client->dev, "nr=%u val=%d\n", nr, val);
443 memcpy(gpio, priv->gpio, sizeof(gpio));
444 gpio[nr] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | (val << 2);
446 return cxd2820r_gpio(&priv->fe, gpio);
449 static void cxd2820r_gpio_set(struct gpio_chip *chip, unsigned nr, int val)
451 struct cxd2820r_priv *priv = gpiochip_get_data(chip);
452 struct i2c_client *client = priv->client[0];
453 u8 gpio[GPIO_COUNT];
455 dev_dbg(&client->dev, "nr=%u val=%d\n", nr, val);
457 memcpy(gpio, priv->gpio, sizeof(gpio));
458 gpio[nr] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | (val << 2);
460 (void) cxd2820r_gpio(&priv->fe, gpio);
462 return;
465 static int cxd2820r_gpio_get(struct gpio_chip *chip, unsigned nr)
467 struct cxd2820r_priv *priv = gpiochip_get_data(chip);
468 struct i2c_client *client = priv->client[0];
470 dev_dbg(&client->dev, "nr=%u\n", nr);
472 return (priv->gpio[nr] >> 2) & 0x01;
474 #endif
476 static const struct dvb_frontend_ops cxd2820r_ops = {
477 .delsys = { SYS_DVBT, SYS_DVBT2, SYS_DVBC_ANNEX_A },
478 /* default: DVB-T/T2 */
479 .info = {
480 .name = "Sony CXD2820R",
482 .caps = FE_CAN_FEC_1_2 |
483 FE_CAN_FEC_2_3 |
484 FE_CAN_FEC_3_4 |
485 FE_CAN_FEC_5_6 |
486 FE_CAN_FEC_7_8 |
487 FE_CAN_FEC_AUTO |
488 FE_CAN_QPSK |
489 FE_CAN_QAM_16 |
490 FE_CAN_QAM_32 |
491 FE_CAN_QAM_64 |
492 FE_CAN_QAM_128 |
493 FE_CAN_QAM_256 |
494 FE_CAN_QAM_AUTO |
495 FE_CAN_TRANSMISSION_MODE_AUTO |
496 FE_CAN_GUARD_INTERVAL_AUTO |
497 FE_CAN_HIERARCHY_AUTO |
498 FE_CAN_MUTE_TS |
499 FE_CAN_2G_MODULATION |
500 FE_CAN_MULTISTREAM
503 .release = cxd2820r_release,
504 .init = cxd2820r_init,
505 .sleep = cxd2820r_sleep,
507 .get_tune_settings = cxd2820r_get_tune_settings,
508 .i2c_gate_ctrl = cxd2820r_i2c_gate_ctrl,
510 .get_frontend = cxd2820r_get_frontend,
512 .get_frontend_algo = cxd2820r_get_frontend_algo,
513 .search = cxd2820r_search,
515 .read_status = cxd2820r_read_status,
516 .read_snr = cxd2820r_read_snr,
517 .read_ber = cxd2820r_read_ber,
518 .read_ucblocks = cxd2820r_read_ucblocks,
519 .read_signal_strength = cxd2820r_read_signal_strength,
523 * XXX: That is wrapper to cxd2820r_probe() via driver core in order to provide
524 * proper I2C client for legacy media attach binding.
525 * New users must use I2C client binding directly!
527 struct dvb_frontend *cxd2820r_attach(const struct cxd2820r_config *config,
528 struct i2c_adapter *adapter,
529 int *gpio_chip_base)
531 struct i2c_client *client;
532 struct i2c_board_info board_info;
533 struct cxd2820r_platform_data pdata;
535 pdata.ts_mode = config->ts_mode;
536 pdata.ts_clk_inv = config->ts_clock_inv;
537 pdata.if_agc_polarity = config->if_agc_polarity;
538 pdata.spec_inv = config->spec_inv;
539 pdata.gpio_chip_base = &gpio_chip_base;
540 pdata.attach_in_use = true;
542 memset(&board_info, 0, sizeof(board_info));
543 strlcpy(board_info.type, "cxd2820r", I2C_NAME_SIZE);
544 board_info.addr = config->i2c_address;
545 board_info.platform_data = &pdata;
546 client = i2c_new_device(adapter, &board_info);
547 if (!client || !client->dev.driver)
548 return NULL;
550 return pdata.get_dvb_frontend(client);
552 EXPORT_SYMBOL(cxd2820r_attach);
554 static struct dvb_frontend *cxd2820r_get_dvb_frontend(struct i2c_client *client)
556 struct cxd2820r_priv *priv = i2c_get_clientdata(client);
558 dev_dbg(&client->dev, "\n");
560 return &priv->fe;
563 static int cxd2820r_probe(struct i2c_client *client,
564 const struct i2c_device_id *id)
566 struct cxd2820r_platform_data *pdata = client->dev.platform_data;
567 struct cxd2820r_priv *priv;
568 int ret, *gpio_chip_base;
569 unsigned int utmp;
570 static const struct regmap_range_cfg regmap_range_cfg0[] = {
572 .range_min = 0x0000,
573 .range_max = 0x3fff,
574 .selector_reg = 0x00,
575 .selector_mask = 0xff,
576 .selector_shift = 0,
577 .window_start = 0x00,
578 .window_len = 0x100,
581 static const struct regmap_range_cfg regmap_range_cfg1[] = {
583 .range_min = 0x0000,
584 .range_max = 0x01ff,
585 .selector_reg = 0x00,
586 .selector_mask = 0xff,
587 .selector_shift = 0,
588 .window_start = 0x00,
589 .window_len = 0x100,
592 static const struct regmap_config regmap_config0 = {
593 .reg_bits = 8,
594 .val_bits = 8,
595 .max_register = 0x3fff,
596 .ranges = regmap_range_cfg0,
597 .num_ranges = ARRAY_SIZE(regmap_range_cfg0),
598 .cache_type = REGCACHE_NONE,
600 static const struct regmap_config regmap_config1 = {
601 .reg_bits = 8,
602 .val_bits = 8,
603 .max_register = 0x01ff,
604 .ranges = regmap_range_cfg1,
605 .num_ranges = ARRAY_SIZE(regmap_range_cfg1),
606 .cache_type = REGCACHE_NONE,
609 dev_dbg(&client->dev, "\n");
611 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
612 if (!priv) {
613 ret = -ENOMEM;
614 goto err;
617 priv->client[0] = client;
618 priv->i2c = client->adapter;
619 priv->ts_mode = pdata->ts_mode;
620 priv->ts_clk_inv = pdata->ts_clk_inv;
621 priv->if_agc_polarity = pdata->if_agc_polarity;
622 priv->spec_inv = pdata->spec_inv;
623 gpio_chip_base = *pdata->gpio_chip_base;
624 priv->regmap[0] = regmap_init_i2c(priv->client[0], &regmap_config0);
625 if (IS_ERR(priv->regmap[0])) {
626 ret = PTR_ERR(priv->regmap[0]);
627 goto err_kfree;
630 /* Check demod answers with correct chip id */
631 ret = regmap_read(priv->regmap[0], 0x00fd, &utmp);
632 if (ret)
633 goto err_regmap_0_regmap_exit;
635 dev_dbg(&client->dev, "chip_id=%02x\n", utmp);
637 if (utmp != 0xe1) {
638 ret = -ENODEV;
639 goto err_regmap_0_regmap_exit;
643 * Chip has two I2C addresses for different register banks. We register
644 * one dummy I2C client in in order to get own I2C client for each
645 * register bank.
647 priv->client[1] = i2c_new_dummy(client->adapter, client->addr | (1 << 1));
648 if (!priv->client[1]) {
649 ret = -ENODEV;
650 dev_err(&client->dev, "I2C registration failed\n");
651 if (ret)
652 goto err_regmap_0_regmap_exit;
655 priv->regmap[1] = regmap_init_i2c(priv->client[1], &regmap_config1);
656 if (IS_ERR(priv->regmap[1])) {
657 ret = PTR_ERR(priv->regmap[1]);
658 goto err_client_1_i2c_unregister_device;
661 if (gpio_chip_base) {
662 #ifdef CONFIG_GPIOLIB
663 /* Add GPIOs */
664 priv->gpio_chip.label = KBUILD_MODNAME;
665 priv->gpio_chip.parent = &client->dev;
666 priv->gpio_chip.owner = THIS_MODULE;
667 priv->gpio_chip.direction_output = cxd2820r_gpio_direction_output;
668 priv->gpio_chip.set = cxd2820r_gpio_set;
669 priv->gpio_chip.get = cxd2820r_gpio_get;
670 priv->gpio_chip.base = -1; /* Dynamic allocation */
671 priv->gpio_chip.ngpio = GPIO_COUNT;
672 priv->gpio_chip.can_sleep = 1;
673 ret = gpiochip_add_data(&priv->gpio_chip, priv);
674 if (ret)
675 goto err_regmap_1_regmap_exit;
677 dev_dbg(&client->dev, "gpio_chip.base=%d\n",
678 priv->gpio_chip.base);
680 *gpio_chip_base = priv->gpio_chip.base;
681 #else
683 * Use static GPIO configuration if GPIOLIB is undefined.
684 * This is fallback condition.
686 u8 gpio[GPIO_COUNT];
687 gpio[0] = (*gpio_chip_base >> 0) & 0x07;
688 gpio[1] = (*gpio_chip_base >> 3) & 0x07;
689 gpio[2] = 0;
690 ret = cxd2820r_gpio(&priv->fe, gpio);
691 if (ret)
692 goto err_regmap_1_regmap_exit;
693 #endif
696 /* Create dvb frontend */
697 memcpy(&priv->fe.ops, &cxd2820r_ops, sizeof(priv->fe.ops));
698 if (!pdata->attach_in_use)
699 priv->fe.ops.release = NULL;
700 priv->fe.demodulator_priv = priv;
701 i2c_set_clientdata(client, priv);
703 /* Setup callbacks */
704 pdata->get_dvb_frontend = cxd2820r_get_dvb_frontend;
706 dev_info(&client->dev, "Sony CXD2820R successfully identified\n");
708 return 0;
709 err_regmap_1_regmap_exit:
710 regmap_exit(priv->regmap[1]);
711 err_client_1_i2c_unregister_device:
712 i2c_unregister_device(priv->client[1]);
713 err_regmap_0_regmap_exit:
714 regmap_exit(priv->regmap[0]);
715 err_kfree:
716 kfree(priv);
717 err:
718 dev_dbg(&client->dev, "failed=%d\n", ret);
719 return ret;
722 static int cxd2820r_remove(struct i2c_client *client)
724 struct cxd2820r_priv *priv = i2c_get_clientdata(client);
726 dev_dbg(&client->dev, "\n");
728 #ifdef CONFIG_GPIOLIB
729 if (priv->gpio_chip.label)
730 gpiochip_remove(&priv->gpio_chip);
731 #endif
732 regmap_exit(priv->regmap[1]);
733 i2c_unregister_device(priv->client[1]);
735 regmap_exit(priv->regmap[0]);
737 kfree(priv);
739 return 0;
742 static const struct i2c_device_id cxd2820r_id_table[] = {
743 {"cxd2820r", 0},
746 MODULE_DEVICE_TABLE(i2c, cxd2820r_id_table);
748 static struct i2c_driver cxd2820r_driver = {
749 .driver = {
750 .name = "cxd2820r",
751 .suppress_bind_attrs = true,
753 .probe = cxd2820r_probe,
754 .remove = cxd2820r_remove,
755 .id_table = cxd2820r_id_table,
758 module_i2c_driver(cxd2820r_driver);
760 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
761 MODULE_DESCRIPTION("Sony CXD2820R demodulator driver");
762 MODULE_LICENSE("GPL");