diff options
author | Antti Palosaari <crope@iki.fi> | 2013-10-15 18:22:45 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2014-03-14 04:21:27 -0400 |
commit | 28fd31f82dccfcfcb4c80fd916d4caf875c04d90 (patch) | |
tree | cbc74bc76d16c9de8ccb46119f4034bba37471ee /drivers/media/tuners/e4000.c | |
parent | 8ea5488a919bbd49941584f773fd66623192ffc0 (diff) |
[media] e4000: convert DVB tuner to I2C driver model
Driver conversion from proprietary DVB tuner model to more
general I2C driver model.
Cc: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media/tuners/e4000.c')
-rw-r--r-- | drivers/media/tuners/e4000.c | 115 |
1 files changed, 71 insertions, 44 deletions
diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c index 40c1da707d15..015316985245 100644 --- a/drivers/media/tuners/e4000.c +++ b/drivers/media/tuners/e4000.c | |||
@@ -31,7 +31,7 @@ static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len) | |||
31 | u8 buf[MAX_XFER_SIZE]; | 31 | u8 buf[MAX_XFER_SIZE]; |
32 | struct i2c_msg msg[1] = { | 32 | struct i2c_msg msg[1] = { |
33 | { | 33 | { |
34 | .addr = priv->cfg->i2c_addr, | 34 | .addr = priv->client->addr, |
35 | .flags = 0, | 35 | .flags = 0, |
36 | .len = 1 + len, | 36 | .len = 1 + len, |
37 | .buf = buf, | 37 | .buf = buf, |
@@ -39,7 +39,7 @@ static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len) | |||
39 | }; | 39 | }; |
40 | 40 | ||
41 | if (1 + len > sizeof(buf)) { | 41 | if (1 + len > sizeof(buf)) { |
42 | dev_warn(&priv->i2c->dev, | 42 | dev_warn(&priv->client->dev, |
43 | "%s: i2c wr reg=%04x: len=%d is too big!\n", | 43 | "%s: i2c wr reg=%04x: len=%d is too big!\n", |
44 | KBUILD_MODNAME, reg, len); | 44 | KBUILD_MODNAME, reg, len); |
45 | return -EINVAL; | 45 | return -EINVAL; |
@@ -48,11 +48,11 @@ static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len) | |||
48 | buf[0] = reg; | 48 | buf[0] = reg; |
49 | memcpy(&buf[1], val, len); | 49 | memcpy(&buf[1], val, len); |
50 | 50 | ||
51 | ret = i2c_transfer(priv->i2c, msg, 1); | 51 | ret = i2c_transfer(priv->client->adapter, msg, 1); |
52 | if (ret == 1) { | 52 | if (ret == 1) { |
53 | ret = 0; | 53 | ret = 0; |
54 | } else { | 54 | } else { |
55 | dev_warn(&priv->i2c->dev, | 55 | dev_warn(&priv->client->dev, |
56 | "%s: i2c wr failed=%d reg=%02x len=%d\n", | 56 | "%s: i2c wr failed=%d reg=%02x len=%d\n", |
57 | KBUILD_MODNAME, ret, reg, len); | 57 | KBUILD_MODNAME, ret, reg, len); |
58 | ret = -EREMOTEIO; | 58 | ret = -EREMOTEIO; |
@@ -67,12 +67,12 @@ static int e4000_rd_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len) | |||
67 | u8 buf[MAX_XFER_SIZE]; | 67 | u8 buf[MAX_XFER_SIZE]; |
68 | struct i2c_msg msg[2] = { | 68 | struct i2c_msg msg[2] = { |
69 | { | 69 | { |
70 | .addr = priv->cfg->i2c_addr, | 70 | .addr = priv->client->addr, |
71 | .flags = 0, | 71 | .flags = 0, |
72 | .len = 1, | 72 | .len = 1, |
73 | .buf = ®, | 73 | .buf = ®, |
74 | }, { | 74 | }, { |
75 | .addr = priv->cfg->i2c_addr, | 75 | .addr = priv->client->addr, |
76 | .flags = I2C_M_RD, | 76 | .flags = I2C_M_RD, |
77 | .len = len, | 77 | .len = len, |
78 | .buf = buf, | 78 | .buf = buf, |
@@ -80,18 +80,18 @@ static int e4000_rd_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len) | |||
80 | }; | 80 | }; |
81 | 81 | ||
82 | if (len > sizeof(buf)) { | 82 | if (len > sizeof(buf)) { |
83 | dev_warn(&priv->i2c->dev, | 83 | dev_warn(&priv->client->dev, |
84 | "%s: i2c rd reg=%04x: len=%d is too big!\n", | 84 | "%s: i2c rd reg=%04x: len=%d is too big!\n", |
85 | KBUILD_MODNAME, reg, len); | 85 | KBUILD_MODNAME, reg, len); |
86 | return -EINVAL; | 86 | return -EINVAL; |
87 | } | 87 | } |
88 | 88 | ||
89 | ret = i2c_transfer(priv->i2c, msg, 2); | 89 | ret = i2c_transfer(priv->client->adapter, msg, 2); |
90 | if (ret == 2) { | 90 | if (ret == 2) { |
91 | memcpy(val, buf, len); | 91 | memcpy(val, buf, len); |
92 | ret = 0; | 92 | ret = 0; |
93 | } else { | 93 | } else { |
94 | dev_warn(&priv->i2c->dev, | 94 | dev_warn(&priv->client->dev, |
95 | "%s: i2c rd failed=%d reg=%02x len=%d\n", | 95 | "%s: i2c rd failed=%d reg=%02x len=%d\n", |
96 | KBUILD_MODNAME, ret, reg, len); | 96 | KBUILD_MODNAME, ret, reg, len); |
97 | ret = -EREMOTEIO; | 97 | ret = -EREMOTEIO; |
@@ -117,7 +117,7 @@ static int e4000_init(struct dvb_frontend *fe) | |||
117 | struct e4000_priv *priv = fe->tuner_priv; | 117 | struct e4000_priv *priv = fe->tuner_priv; |
118 | int ret; | 118 | int ret; |
119 | 119 | ||
120 | dev_dbg(&priv->i2c->dev, "%s:\n", __func__); | 120 | dev_dbg(&priv->client->dev, "%s:\n", __func__); |
121 | 121 | ||
122 | if (fe->ops.i2c_gate_ctrl) | 122 | if (fe->ops.i2c_gate_ctrl) |
123 | fe->ops.i2c_gate_ctrl(fe, 1); | 123 | fe->ops.i2c_gate_ctrl(fe, 1); |
@@ -186,7 +186,7 @@ err: | |||
186 | if (fe->ops.i2c_gate_ctrl) | 186 | if (fe->ops.i2c_gate_ctrl) |
187 | fe->ops.i2c_gate_ctrl(fe, 0); | 187 | fe->ops.i2c_gate_ctrl(fe, 0); |
188 | 188 | ||
189 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); | 189 | dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret); |
190 | return ret; | 190 | return ret; |
191 | } | 191 | } |
192 | 192 | ||
@@ -195,7 +195,7 @@ static int e4000_sleep(struct dvb_frontend *fe) | |||
195 | struct e4000_priv *priv = fe->tuner_priv; | 195 | struct e4000_priv *priv = fe->tuner_priv; |
196 | int ret; | 196 | int ret; |
197 | 197 | ||
198 | dev_dbg(&priv->i2c->dev, "%s:\n", __func__); | 198 | dev_dbg(&priv->client->dev, "%s:\n", __func__); |
199 | 199 | ||
200 | if (fe->ops.i2c_gate_ctrl) | 200 | if (fe->ops.i2c_gate_ctrl) |
201 | fe->ops.i2c_gate_ctrl(fe, 1); | 201 | fe->ops.i2c_gate_ctrl(fe, 1); |
@@ -212,7 +212,7 @@ err: | |||
212 | if (fe->ops.i2c_gate_ctrl) | 212 | if (fe->ops.i2c_gate_ctrl) |
213 | fe->ops.i2c_gate_ctrl(fe, 0); | 213 | fe->ops.i2c_gate_ctrl(fe, 0); |
214 | 214 | ||
215 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); | 215 | dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret); |
216 | return ret; | 216 | return ret; |
217 | } | 217 | } |
218 | 218 | ||
@@ -224,7 +224,7 @@ static int e4000_set_params(struct dvb_frontend *fe) | |||
224 | unsigned int f_vco; | 224 | unsigned int f_vco; |
225 | u8 buf[5], i_data[4], q_data[4]; | 225 | u8 buf[5], i_data[4], q_data[4]; |
226 | 226 | ||
227 | dev_dbg(&priv->i2c->dev, | 227 | dev_dbg(&priv->client->dev, |
228 | "%s: delivery_system=%d frequency=%d bandwidth_hz=%d\n", | 228 | "%s: delivery_system=%d frequency=%d bandwidth_hz=%d\n", |
229 | __func__, c->delivery_system, c->frequency, | 229 | __func__, c->delivery_system, c->frequency, |
230 | c->bandwidth_hz); | 230 | c->bandwidth_hz); |
@@ -253,14 +253,15 @@ static int e4000_set_params(struct dvb_frontend *fe) | |||
253 | * or more. | 253 | * or more. |
254 | */ | 254 | */ |
255 | f_vco = c->frequency * e4000_pll_lut[i].mul; | 255 | f_vco = c->frequency * e4000_pll_lut[i].mul; |
256 | sigma_delta = div_u64(0x10000ULL * (f_vco % priv->cfg->clock), priv->cfg->clock); | 256 | sigma_delta = div_u64(0x10000ULL * (f_vco % priv->clock), priv->clock); |
257 | buf[0] = f_vco / priv->cfg->clock; | 257 | buf[0] = f_vco / priv->clock; |
258 | buf[1] = (sigma_delta >> 0) & 0xff; | 258 | buf[1] = (sigma_delta >> 0) & 0xff; |
259 | buf[2] = (sigma_delta >> 8) & 0xff; | 259 | buf[2] = (sigma_delta >> 8) & 0xff; |
260 | buf[3] = 0x00; | 260 | buf[3] = 0x00; |
261 | buf[4] = e4000_pll_lut[i].div; | 261 | buf[4] = e4000_pll_lut[i].div; |
262 | 262 | ||
263 | dev_dbg(&priv->i2c->dev, "%s: f_vco=%u pll div=%d sigma_delta=%04x\n", | 263 | dev_dbg(&priv->client->dev, |
264 | "%s: f_vco=%u pll div=%d sigma_delta=%04x\n", | ||
264 | __func__, f_vco, buf[0], sigma_delta); | 265 | __func__, f_vco, buf[0], sigma_delta); |
265 | 266 | ||
266 | ret = e4000_wr_regs(priv, 0x09, buf, 5); | 267 | ret = e4000_wr_regs(priv, 0x09, buf, 5); |
@@ -369,7 +370,7 @@ err: | |||
369 | if (fe->ops.i2c_gate_ctrl) | 370 | if (fe->ops.i2c_gate_ctrl) |
370 | fe->ops.i2c_gate_ctrl(fe, 0); | 371 | fe->ops.i2c_gate_ctrl(fe, 0); |
371 | 372 | ||
372 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); | 373 | dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret); |
373 | return ret; | 374 | return ret; |
374 | } | 375 | } |
375 | 376 | ||
@@ -377,24 +378,13 @@ static int e4000_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) | |||
377 | { | 378 | { |
378 | struct e4000_priv *priv = fe->tuner_priv; | 379 | struct e4000_priv *priv = fe->tuner_priv; |
379 | 380 | ||
380 | dev_dbg(&priv->i2c->dev, "%s:\n", __func__); | 381 | dev_dbg(&priv->client->dev, "%s:\n", __func__); |
381 | 382 | ||
382 | *frequency = 0; /* Zero-IF */ | 383 | *frequency = 0; /* Zero-IF */ |
383 | 384 | ||
384 | return 0; | 385 | return 0; |
385 | } | 386 | } |
386 | 387 | ||
387 | static int e4000_release(struct dvb_frontend *fe) | ||
388 | { | ||
389 | struct e4000_priv *priv = fe->tuner_priv; | ||
390 | |||
391 | dev_dbg(&priv->i2c->dev, "%s:\n", __func__); | ||
392 | |||
393 | kfree(fe->tuner_priv); | ||
394 | |||
395 | return 0; | ||
396 | } | ||
397 | |||
398 | static const struct dvb_tuner_ops e4000_tuner_ops = { | 388 | static const struct dvb_tuner_ops e4000_tuner_ops = { |
399 | .info = { | 389 | .info = { |
400 | .name = "Elonics E4000", | 390 | .name = "Elonics E4000", |
@@ -402,8 +392,6 @@ static const struct dvb_tuner_ops e4000_tuner_ops = { | |||
402 | .frequency_max = 862000000, | 392 | .frequency_max = 862000000, |
403 | }, | 393 | }, |
404 | 394 | ||
405 | .release = e4000_release, | ||
406 | |||
407 | .init = e4000_init, | 395 | .init = e4000_init, |
408 | .sleep = e4000_sleep, | 396 | .sleep = e4000_sleep, |
409 | .set_params = e4000_set_params, | 397 | .set_params = e4000_set_params, |
@@ -411,9 +399,11 @@ static const struct dvb_tuner_ops e4000_tuner_ops = { | |||
411 | .get_if_frequency = e4000_get_if_frequency, | 399 | .get_if_frequency = e4000_get_if_frequency, |
412 | }; | 400 | }; |
413 | 401 | ||
414 | struct dvb_frontend *e4000_attach(struct dvb_frontend *fe, | 402 | static int e4000_probe(struct i2c_client *client, |
415 | struct i2c_adapter *i2c, const struct e4000_config *cfg) | 403 | const struct i2c_device_id *id) |
416 | { | 404 | { |
405 | struct e4000_config *cfg = client->dev.platform_data; | ||
406 | struct dvb_frontend *fe = cfg->fe; | ||
417 | struct e4000_priv *priv; | 407 | struct e4000_priv *priv; |
418 | int ret; | 408 | int ret; |
419 | u8 chip_id; | 409 | u8 chip_id; |
@@ -424,29 +414,33 @@ struct dvb_frontend *e4000_attach(struct dvb_frontend *fe, | |||
424 | priv = kzalloc(sizeof(struct e4000_priv), GFP_KERNEL); | 414 | priv = kzalloc(sizeof(struct e4000_priv), GFP_KERNEL); |
425 | if (!priv) { | 415 | if (!priv) { |
426 | ret = -ENOMEM; | 416 | ret = -ENOMEM; |
427 | dev_err(&i2c->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME); | 417 | dev_err(&client->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME); |
428 | goto err; | 418 | goto err; |
429 | } | 419 | } |
430 | 420 | ||
431 | priv->cfg = cfg; | 421 | priv->clock = cfg->clock; |
432 | priv->i2c = i2c; | 422 | priv->client = client; |
423 | priv->fe = cfg->fe; | ||
433 | 424 | ||
434 | /* check if the tuner is there */ | 425 | /* check if the tuner is there */ |
435 | ret = e4000_rd_reg(priv, 0x02, &chip_id); | 426 | ret = e4000_rd_reg(priv, 0x02, &chip_id); |
436 | if (ret < 0) | 427 | if (ret < 0) |
437 | goto err; | 428 | goto err; |
438 | 429 | ||
439 | dev_dbg(&priv->i2c->dev, "%s: chip_id=%02x\n", __func__, chip_id); | 430 | dev_dbg(&priv->client->dev, |
431 | "%s: chip_id=%02x\n", __func__, chip_id); | ||
440 | 432 | ||
441 | if (chip_id != 0x40) | 433 | if (chip_id != 0x40) { |
434 | ret = -ENODEV; | ||
442 | goto err; | 435 | goto err; |
436 | } | ||
443 | 437 | ||
444 | /* put sleep as chip seems to be in normal mode by default */ | 438 | /* put sleep as chip seems to be in normal mode by default */ |
445 | ret = e4000_wr_reg(priv, 0x00, 0x00); | 439 | ret = e4000_wr_reg(priv, 0x00, 0x00); |
446 | if (ret < 0) | 440 | if (ret < 0) |
447 | goto err; | 441 | goto err; |
448 | 442 | ||
449 | dev_info(&priv->i2c->dev, | 443 | dev_info(&priv->client->dev, |
450 | "%s: Elonics E4000 successfully identified\n", | 444 | "%s: Elonics E4000 successfully identified\n", |
451 | KBUILD_MODNAME); | 445 | KBUILD_MODNAME); |
452 | 446 | ||
@@ -457,16 +451,49 @@ struct dvb_frontend *e4000_attach(struct dvb_frontend *fe, | |||
457 | if (fe->ops.i2c_gate_ctrl) | 451 | if (fe->ops.i2c_gate_ctrl) |
458 | fe->ops.i2c_gate_ctrl(fe, 0); | 452 | fe->ops.i2c_gate_ctrl(fe, 0); |
459 | 453 | ||
460 | return fe; | 454 | i2c_set_clientdata(client, priv); |
455 | |||
456 | return 0; | ||
461 | err: | 457 | err: |
462 | if (fe->ops.i2c_gate_ctrl) | 458 | if (fe->ops.i2c_gate_ctrl) |
463 | fe->ops.i2c_gate_ctrl(fe, 0); | 459 | fe->ops.i2c_gate_ctrl(fe, 0); |
464 | 460 | ||
465 | dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret); | 461 | dev_dbg(&client->dev, "%s: failed=%d\n", __func__, ret); |
466 | kfree(priv); | 462 | kfree(priv); |
467 | return NULL; | 463 | return ret; |
468 | } | 464 | } |
469 | EXPORT_SYMBOL(e4000_attach); | 465 | |
466 | static int e4000_remove(struct i2c_client *client) | ||
467 | { | ||
468 | struct e4000_priv *priv = i2c_get_clientdata(client); | ||
469 | struct dvb_frontend *fe = priv->fe; | ||
470 | |||
471 | dev_dbg(&client->dev, "%s:\n", __func__); | ||
472 | |||
473 | memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); | ||
474 | fe->tuner_priv = NULL; | ||
475 | kfree(priv); | ||
476 | |||
477 | return 0; | ||
478 | } | ||
479 | |||
480 | static const struct i2c_device_id e4000_id[] = { | ||
481 | {"e4000", 0}, | ||
482 | {} | ||
483 | }; | ||
484 | MODULE_DEVICE_TABLE(i2c, e4000_id); | ||
485 | |||
486 | static struct i2c_driver e4000_driver = { | ||
487 | .driver = { | ||
488 | .owner = THIS_MODULE, | ||
489 | .name = "e4000", | ||
490 | }, | ||
491 | .probe = e4000_probe, | ||
492 | .remove = e4000_remove, | ||
493 | .id_table = e4000_id, | ||
494 | }; | ||
495 | |||
496 | module_i2c_driver(e4000_driver); | ||
470 | 497 | ||
471 | MODULE_DESCRIPTION("Elonics E4000 silicon tuner driver"); | 498 | MODULE_DESCRIPTION("Elonics E4000 silicon tuner driver"); |
472 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); | 499 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |