diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-10-10 22:04:49 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-10-10 22:04:49 -0400 |
commit | 4d9708ea5e5a45973df7cf965805fdfb185dd5bf (patch) | |
tree | 833a918e85f1e3bff8cb182517707d12836d10a8 /drivers/media/tuners | |
parent | 754c780953397dd5ee5191b7b3ca67e09088ce7a (diff) | |
parent | a66d05d504a24894a8fdf11e4569752f313e5764 (diff) |
Merge tag 'media/v3.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media updates from Mauro Carvalho Chehab:
- new IR driver: hix5hd2-ir
- the virtual test driver (vivi) was replaced by vivid, with has an
almost complete set of features to emulate most v4l2 devices and
properly test all sorts of userspace apps
- the as102 driver had several bugs fixed and was properly split into a
frontend and a core driver. With that, it got promoted from staging
into mainstream
- one new CI driver got added for CIMaX SP2/SP2HF (sp2 driver)
- one new frontend driver for Toshiba ISDB-T/ISDB-S demod (tc90522)
- one new PCI driver for ISDB-T/ISDB-S (pt3 driver)
- saa7134 driver got support for go7007-based devices
- added a new PCI driver for Techwell 68xx chipsets (tw68)
- a new platform driver was added (coda)
- new tuner drivers: mxl301rf and qm1d1c0042
- a new DVB USB driver was added for DVBSky S860 & similar devices
- added a new SDR driver (hackrf)
- usbtv got audio support
- several platform drivers are now compiled with COMPILE_TEST
- a series of compiler fixup patches, making sparse/spatch happier with
the media stuff and removing several warnings, especially on those
platform drivers that didn't use to compile on x86
- Support for several new modern devices got added
- lots of other fixes, improvements and cleanups
* tag 'media/v3.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (544 commits)
[media] ir-hix5hd2: fix build on c6x arch
[media] pt3: fix DTV FE I2C driver load error paths
Revert "[media] media: em28xx - remove reset_resume interface"
[media] exynos4-is: fix some warnings when compiling on arm64
[media] usb drivers: use %zu instead of %zd
[media] pci drivers: use %zu instead of %zd
[media] dvb-frontends: use %zu instead of %zd
[media] s5p-mfc: Fix several printk warnings
[media] s5p_mfc_opr: Fix warnings
[media] ti-vpe: Fix typecast
[media] s3c-camif: fix dma_addr_t printks
[media] s5p_mfc_opr_v6: get rid of warnings when compiled with 64 bits
[media] s5p_mfc_opr_v5: Fix lots of warnings on x86_64
[media] em28xx: Fix identation
[media] drxd: remove a dead code
[media] saa7146: remove return after BUG()
[media] cx88: remove return after BUG()
[media] cx88: fix cards table CodingStyle
[media] radio-sf16fmr2: declare some structs as static
[media] radio-sf16fmi: declare pnp_attached as static
...
Diffstat (limited to 'drivers/media/tuners')
27 files changed, 1997 insertions, 1228 deletions
diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig index d79fd1ce5a18..f039dc2a21cf 100644 --- a/drivers/media/tuners/Kconfig +++ b/drivers/media/tuners/Kconfig | |||
@@ -204,6 +204,7 @@ config MEDIA_TUNER_FC0013 | |||
204 | config MEDIA_TUNER_TDA18212 | 204 | config MEDIA_TUNER_TDA18212 |
205 | tristate "NXP TDA18212 silicon tuner" | 205 | tristate "NXP TDA18212 silicon tuner" |
206 | depends on MEDIA_SUPPORT && I2C | 206 | depends on MEDIA_SUPPORT && I2C |
207 | select REGMAP_I2C | ||
207 | default m if !MEDIA_SUBDRV_AUTOSELECT | 208 | default m if !MEDIA_SUBDRV_AUTOSELECT |
208 | help | 209 | help |
209 | NXP TDA18212 silicon tuner driver. | 210 | NXP TDA18212 silicon tuner driver. |
@@ -226,6 +227,7 @@ config MEDIA_TUNER_FC2580 | |||
226 | config MEDIA_TUNER_M88TS2022 | 227 | config MEDIA_TUNER_M88TS2022 |
227 | tristate "Montage M88TS2022 silicon tuner" | 228 | tristate "Montage M88TS2022 silicon tuner" |
228 | depends on MEDIA_SUPPORT && I2C | 229 | depends on MEDIA_SUPPORT && I2C |
230 | select REGMAP_I2C | ||
229 | default m if !MEDIA_SUBDRV_AUTOSELECT | 231 | default m if !MEDIA_SUBDRV_AUTOSELECT |
230 | help | 232 | help |
231 | Montage M88TS2022 silicon tuner driver. | 233 | Montage M88TS2022 silicon tuner driver. |
@@ -247,6 +249,7 @@ config MEDIA_TUNER_SI2157 | |||
247 | config MEDIA_TUNER_IT913X | 249 | config MEDIA_TUNER_IT913X |
248 | tristate "ITE Tech IT913x silicon tuner" | 250 | tristate "ITE Tech IT913x silicon tuner" |
249 | depends on MEDIA_SUPPORT && I2C | 251 | depends on MEDIA_SUPPORT && I2C |
252 | select REGMAP_I2C | ||
250 | default m if !MEDIA_SUBDRV_AUTOSELECT | 253 | default m if !MEDIA_SUBDRV_AUTOSELECT |
251 | help | 254 | help |
252 | ITE Tech IT913x silicon tuner driver. | 255 | ITE Tech IT913x silicon tuner driver. |
@@ -257,4 +260,18 @@ config MEDIA_TUNER_R820T | |||
257 | default m if !MEDIA_SUBDRV_AUTOSELECT | 260 | default m if !MEDIA_SUBDRV_AUTOSELECT |
258 | help | 261 | help |
259 | Rafael Micro R820T silicon tuner driver. | 262 | Rafael Micro R820T silicon tuner driver. |
263 | |||
264 | config MEDIA_TUNER_MXL301RF | ||
265 | tristate "MaxLinear MxL301RF tuner" | ||
266 | depends on MEDIA_SUPPORT && I2C | ||
267 | default m if !MEDIA_SUBDRV_AUTOSELECT | ||
268 | help | ||
269 | MaxLinear MxL301RF OFDM tuner driver. | ||
270 | |||
271 | config MEDIA_TUNER_QM1D1C0042 | ||
272 | tristate "Sharp QM1D1C0042 tuner" | ||
273 | depends on MEDIA_SUPPORT && I2C | ||
274 | default m if !MEDIA_SUBDRV_AUTOSELECT | ||
275 | help | ||
276 | Sharp QM1D1C0042 trellis coded 8PSK tuner driver. | ||
260 | endmenu | 277 | endmenu |
diff --git a/drivers/media/tuners/Makefile b/drivers/media/tuners/Makefile index 5591699755ba..49fcf8033848 100644 --- a/drivers/media/tuners/Makefile +++ b/drivers/media/tuners/Makefile | |||
@@ -37,8 +37,10 @@ obj-$(CONFIG_MEDIA_TUNER_M88TS2022) += m88ts2022.o | |||
37 | obj-$(CONFIG_MEDIA_TUNER_FC0011) += fc0011.o | 37 | obj-$(CONFIG_MEDIA_TUNER_FC0011) += fc0011.o |
38 | obj-$(CONFIG_MEDIA_TUNER_FC0012) += fc0012.o | 38 | obj-$(CONFIG_MEDIA_TUNER_FC0012) += fc0012.o |
39 | obj-$(CONFIG_MEDIA_TUNER_FC0013) += fc0013.o | 39 | obj-$(CONFIG_MEDIA_TUNER_FC0013) += fc0013.o |
40 | obj-$(CONFIG_MEDIA_TUNER_IT913X) += tuner_it913x.o | 40 | obj-$(CONFIG_MEDIA_TUNER_IT913X) += it913x.o |
41 | obj-$(CONFIG_MEDIA_TUNER_R820T) += r820t.o | 41 | obj-$(CONFIG_MEDIA_TUNER_R820T) += r820t.o |
42 | obj-$(CONFIG_MEDIA_TUNER_MXL301RF) += mxl301rf.o | ||
43 | obj-$(CONFIG_MEDIA_TUNER_QM1D1C0042) += qm1d1c0042.o | ||
42 | 44 | ||
43 | ccflags-y += -I$(srctree)/drivers/media/dvb-core | 45 | ccflags-y += -I$(srctree)/drivers/media/dvb-core |
44 | ccflags-y += -I$(srctree)/drivers/media/dvb-frontends | 46 | ccflags-y += -I$(srctree)/drivers/media/dvb-frontends |
diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c index 90d93348f20c..510239f80c0d 100644 --- a/drivers/media/tuners/e4000.c +++ b/drivers/media/tuners/e4000.c | |||
@@ -26,7 +26,7 @@ static int e4000_init(struct dvb_frontend *fe) | |||
26 | struct e4000 *s = fe->tuner_priv; | 26 | struct e4000 *s = fe->tuner_priv; |
27 | int ret; | 27 | int ret; |
28 | 28 | ||
29 | dev_dbg(&s->client->dev, "%s:\n", __func__); | 29 | dev_dbg(&s->client->dev, "\n"); |
30 | 30 | ||
31 | /* dummy I2C to ensure I2C wakes up */ | 31 | /* dummy I2C to ensure I2C wakes up */ |
32 | ret = regmap_write(s->regmap, 0x02, 0x40); | 32 | ret = regmap_write(s->regmap, 0x02, 0x40); |
@@ -87,7 +87,7 @@ static int e4000_init(struct dvb_frontend *fe) | |||
87 | s->active = true; | 87 | s->active = true; |
88 | err: | 88 | err: |
89 | if (ret) | 89 | if (ret) |
90 | dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret); | 90 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
91 | 91 | ||
92 | return ret; | 92 | return ret; |
93 | } | 93 | } |
@@ -97,7 +97,7 @@ static int e4000_sleep(struct dvb_frontend *fe) | |||
97 | struct e4000 *s = fe->tuner_priv; | 97 | struct e4000 *s = fe->tuner_priv; |
98 | int ret; | 98 | int ret; |
99 | 99 | ||
100 | dev_dbg(&s->client->dev, "%s:\n", __func__); | 100 | dev_dbg(&s->client->dev, "\n"); |
101 | 101 | ||
102 | s->active = false; | 102 | s->active = false; |
103 | 103 | ||
@@ -106,7 +106,7 @@ static int e4000_sleep(struct dvb_frontend *fe) | |||
106 | goto err; | 106 | goto err; |
107 | err: | 107 | err: |
108 | if (ret) | 108 | if (ret) |
109 | dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret); | 109 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
110 | 110 | ||
111 | return ret; | 111 | return ret; |
112 | } | 112 | } |
@@ -121,9 +121,8 @@ static int e4000_set_params(struct dvb_frontend *fe) | |||
121 | u8 buf[5], i_data[4], q_data[4]; | 121 | u8 buf[5], i_data[4], q_data[4]; |
122 | 122 | ||
123 | dev_dbg(&s->client->dev, | 123 | dev_dbg(&s->client->dev, |
124 | "%s: delivery_system=%d frequency=%u bandwidth_hz=%u\n", | 124 | "delivery_system=%d frequency=%u bandwidth_hz=%u\n", |
125 | __func__, c->delivery_system, c->frequency, | 125 | c->delivery_system, c->frequency, c->bandwidth_hz); |
126 | c->bandwidth_hz); | ||
127 | 126 | ||
128 | /* gain control manual */ | 127 | /* gain control manual */ |
129 | ret = regmap_write(s->regmap, 0x1a, 0x00); | 128 | ret = regmap_write(s->regmap, 0x1a, 0x00); |
@@ -150,9 +149,8 @@ static int e4000_set_params(struct dvb_frontend *fe) | |||
150 | buf[3] = 0x00; | 149 | buf[3] = 0x00; |
151 | buf[4] = e4000_pll_lut[i].div; | 150 | buf[4] = e4000_pll_lut[i].div; |
152 | 151 | ||
153 | dev_dbg(&s->client->dev, | 152 | dev_dbg(&s->client->dev, "f_vco=%llu pll div=%d sigma_delta=%04x\n", |
154 | "%s: f_vco=%llu pll div=%d sigma_delta=%04x\n", | 153 | f_vco, buf[0], sigma_delta); |
155 | __func__, f_vco, buf[0], sigma_delta); | ||
156 | 154 | ||
157 | ret = regmap_bulk_write(s->regmap, 0x09, buf, 5); | 155 | ret = regmap_bulk_write(s->regmap, 0x09, buf, 5); |
158 | if (ret) | 156 | if (ret) |
@@ -253,7 +251,7 @@ static int e4000_set_params(struct dvb_frontend *fe) | |||
253 | goto err; | 251 | goto err; |
254 | err: | 252 | err: |
255 | if (ret) | 253 | if (ret) |
256 | dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret); | 254 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
257 | 255 | ||
258 | return ret; | 256 | return ret; |
259 | } | 257 | } |
@@ -262,7 +260,7 @@ static int e4000_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) | |||
262 | { | 260 | { |
263 | struct e4000 *s = fe->tuner_priv; | 261 | struct e4000 *s = fe->tuner_priv; |
264 | 262 | ||
265 | dev_dbg(&s->client->dev, "%s:\n", __func__); | 263 | dev_dbg(&s->client->dev, "\n"); |
266 | 264 | ||
267 | *frequency = 0; /* Zero-IF */ | 265 | *frequency = 0; /* Zero-IF */ |
268 | 266 | ||
@@ -276,10 +274,9 @@ static int e4000_set_lna_gain(struct dvb_frontend *fe) | |||
276 | int ret; | 274 | int ret; |
277 | u8 u8tmp; | 275 | u8 u8tmp; |
278 | 276 | ||
279 | dev_dbg(&s->client->dev, "%s: lna auto=%d->%d val=%d->%d\n", | 277 | dev_dbg(&s->client->dev, "lna auto=%d->%d val=%d->%d\n", |
280 | __func__, s->lna_gain_auto->cur.val, | 278 | s->lna_gain_auto->cur.val, s->lna_gain_auto->val, |
281 | s->lna_gain_auto->val, s->lna_gain->cur.val, | 279 | s->lna_gain->cur.val, s->lna_gain->val); |
282 | s->lna_gain->val); | ||
283 | 280 | ||
284 | if (s->lna_gain_auto->val && s->if_gain_auto->cur.val) | 281 | if (s->lna_gain_auto->val && s->if_gain_auto->cur.val) |
285 | u8tmp = 0x17; | 282 | u8tmp = 0x17; |
@@ -301,7 +298,7 @@ static int e4000_set_lna_gain(struct dvb_frontend *fe) | |||
301 | } | 298 | } |
302 | err: | 299 | err: |
303 | if (ret) | 300 | if (ret) |
304 | dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret); | 301 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
305 | 302 | ||
306 | return ret; | 303 | return ret; |
307 | } | 304 | } |
@@ -312,10 +309,9 @@ static int e4000_set_mixer_gain(struct dvb_frontend *fe) | |||
312 | int ret; | 309 | int ret; |
313 | u8 u8tmp; | 310 | u8 u8tmp; |
314 | 311 | ||
315 | dev_dbg(&s->client->dev, "%s: mixer auto=%d->%d val=%d->%d\n", | 312 | dev_dbg(&s->client->dev, "mixer auto=%d->%d val=%d->%d\n", |
316 | __func__, s->mixer_gain_auto->cur.val, | 313 | s->mixer_gain_auto->cur.val, s->mixer_gain_auto->val, |
317 | s->mixer_gain_auto->val, s->mixer_gain->cur.val, | 314 | s->mixer_gain->cur.val, s->mixer_gain->val); |
318 | s->mixer_gain->val); | ||
319 | 315 | ||
320 | if (s->mixer_gain_auto->val) | 316 | if (s->mixer_gain_auto->val) |
321 | u8tmp = 0x15; | 317 | u8tmp = 0x15; |
@@ -333,7 +329,7 @@ static int e4000_set_mixer_gain(struct dvb_frontend *fe) | |||
333 | } | 329 | } |
334 | err: | 330 | err: |
335 | if (ret) | 331 | if (ret) |
336 | dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret); | 332 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
337 | 333 | ||
338 | return ret; | 334 | return ret; |
339 | } | 335 | } |
@@ -345,10 +341,9 @@ static int e4000_set_if_gain(struct dvb_frontend *fe) | |||
345 | u8 buf[2]; | 341 | u8 buf[2]; |
346 | u8 u8tmp; | 342 | u8 u8tmp; |
347 | 343 | ||
348 | dev_dbg(&s->client->dev, "%s: if auto=%d->%d val=%d->%d\n", | 344 | dev_dbg(&s->client->dev, "if auto=%d->%d val=%d->%d\n", |
349 | __func__, s->if_gain_auto->cur.val, | 345 | s->if_gain_auto->cur.val, s->if_gain_auto->val, |
350 | s->if_gain_auto->val, s->if_gain->cur.val, | 346 | s->if_gain->cur.val, s->if_gain->val); |
351 | s->if_gain->val); | ||
352 | 347 | ||
353 | if (s->if_gain_auto->val && s->lna_gain_auto->cur.val) | 348 | if (s->if_gain_auto->val && s->lna_gain_auto->cur.val) |
354 | u8tmp = 0x17; | 349 | u8tmp = 0x17; |
@@ -372,7 +367,7 @@ static int e4000_set_if_gain(struct dvb_frontend *fe) | |||
372 | } | 367 | } |
373 | err: | 368 | err: |
374 | if (ret) | 369 | if (ret) |
375 | dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret); | 370 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
376 | 371 | ||
377 | return ret; | 372 | return ret; |
378 | } | 373 | } |
@@ -390,7 +385,7 @@ static int e4000_pll_lock(struct dvb_frontend *fe) | |||
390 | s->pll_lock->val = (utmp & 0x01); | 385 | s->pll_lock->val = (utmp & 0x01); |
391 | err: | 386 | err: |
392 | if (ret) | 387 | if (ret) |
393 | dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret); | 388 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
394 | 389 | ||
395 | return ret; | 390 | return ret; |
396 | } | 391 | } |
@@ -400,7 +395,7 @@ static int e4000_g_volatile_ctrl(struct v4l2_ctrl *ctrl) | |||
400 | struct e4000 *s = container_of(ctrl->handler, struct e4000, hdl); | 395 | struct e4000 *s = container_of(ctrl->handler, struct e4000, hdl); |
401 | int ret; | 396 | int ret; |
402 | 397 | ||
403 | if (s->active == false) | 398 | if (!s->active) |
404 | return 0; | 399 | return 0; |
405 | 400 | ||
406 | switch (ctrl->id) { | 401 | switch (ctrl->id) { |
@@ -408,8 +403,8 @@ static int e4000_g_volatile_ctrl(struct v4l2_ctrl *ctrl) | |||
408 | ret = e4000_pll_lock(s->fe); | 403 | ret = e4000_pll_lock(s->fe); |
409 | break; | 404 | break; |
410 | default: | 405 | default: |
411 | dev_dbg(&s->client->dev, "%s: unknown ctrl: id=%d name=%s\n", | 406 | dev_dbg(&s->client->dev, "unknown ctrl: id=%d name=%s\n", |
412 | __func__, ctrl->id, ctrl->name); | 407 | ctrl->id, ctrl->name); |
413 | ret = -EINVAL; | 408 | ret = -EINVAL; |
414 | } | 409 | } |
415 | 410 | ||
@@ -423,7 +418,7 @@ static int e4000_s_ctrl(struct v4l2_ctrl *ctrl) | |||
423 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; | 418 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
424 | int ret; | 419 | int ret; |
425 | 420 | ||
426 | if (s->active == false) | 421 | if (!s->active) |
427 | return 0; | 422 | return 0; |
428 | 423 | ||
429 | switch (ctrl->id) { | 424 | switch (ctrl->id) { |
@@ -445,8 +440,8 @@ static int e4000_s_ctrl(struct v4l2_ctrl *ctrl) | |||
445 | ret = e4000_set_if_gain(s->fe); | 440 | ret = e4000_set_if_gain(s->fe); |
446 | break; | 441 | break; |
447 | default: | 442 | default: |
448 | dev_dbg(&s->client->dev, "%s: unknown ctrl: id=%d name=%s\n", | 443 | dev_dbg(&s->client->dev, "unknown ctrl: id=%d name=%s\n", |
449 | __func__, ctrl->id, ctrl->name); | 444 | ctrl->id, ctrl->name); |
450 | ret = -EINVAL; | 445 | ret = -EINVAL; |
451 | } | 446 | } |
452 | 447 | ||
@@ -494,7 +489,7 @@ static int e4000_probe(struct i2c_client *client, | |||
494 | s = kzalloc(sizeof(struct e4000), GFP_KERNEL); | 489 | s = kzalloc(sizeof(struct e4000), GFP_KERNEL); |
495 | if (!s) { | 490 | if (!s) { |
496 | ret = -ENOMEM; | 491 | ret = -ENOMEM; |
497 | dev_err(&client->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME); | 492 | dev_err(&client->dev, "kzalloc() failed\n"); |
498 | goto err; | 493 | goto err; |
499 | } | 494 | } |
500 | 495 | ||
@@ -512,7 +507,7 @@ static int e4000_probe(struct i2c_client *client, | |||
512 | if (ret) | 507 | if (ret) |
513 | goto err; | 508 | goto err; |
514 | 509 | ||
515 | dev_dbg(&s->client->dev, "%s: chip id=%02x\n", __func__, utmp); | 510 | dev_dbg(&s->client->dev, "chip id=%02x\n", utmp); |
516 | 511 | ||
517 | if (utmp != 0x40) { | 512 | if (utmp != 0x40) { |
518 | ret = -ENODEV; | 513 | ret = -ENODEV; |
@@ -559,9 +554,7 @@ static int e4000_probe(struct i2c_client *client, | |||
559 | s->sd.ctrl_handler = &s->hdl; | 554 | s->sd.ctrl_handler = &s->hdl; |
560 | #endif | 555 | #endif |
561 | 556 | ||
562 | dev_info(&s->client->dev, | 557 | dev_info(&s->client->dev, "Elonics E4000 successfully identified\n"); |
563 | "%s: Elonics E4000 successfully identified\n", | ||
564 | KBUILD_MODNAME); | ||
565 | 558 | ||
566 | fe->tuner_priv = s; | 559 | fe->tuner_priv = s; |
567 | memcpy(&fe->ops.tuner_ops, &e4000_tuner_ops, | 560 | memcpy(&fe->ops.tuner_ops, &e4000_tuner_ops, |
@@ -573,7 +566,7 @@ static int e4000_probe(struct i2c_client *client, | |||
573 | return 0; | 566 | return 0; |
574 | err: | 567 | err: |
575 | if (ret) { | 568 | if (ret) { |
576 | dev_dbg(&client->dev, "%s: failed=%d\n", __func__, ret); | 569 | dev_dbg(&client->dev, "failed=%d\n", ret); |
577 | kfree(s); | 570 | kfree(s); |
578 | } | 571 | } |
579 | 572 | ||
@@ -586,7 +579,7 @@ static int e4000_remove(struct i2c_client *client) | |||
586 | struct e4000 *s = container_of(sd, struct e4000, sd); | 579 | struct e4000 *s = container_of(sd, struct e4000, sd); |
587 | struct dvb_frontend *fe = s->fe; | 580 | struct dvb_frontend *fe = s->fe; |
588 | 581 | ||
589 | dev_dbg(&client->dev, "%s:\n", __func__); | 582 | dev_dbg(&client->dev, "\n"); |
590 | 583 | ||
591 | #if IS_ENABLED(CONFIG_VIDEO_V4L2) | 584 | #if IS_ENABLED(CONFIG_VIDEO_V4L2) |
592 | v4l2_ctrl_handler_free(&s->hdl); | 585 | v4l2_ctrl_handler_free(&s->hdl); |
diff --git a/drivers/media/tuners/it913x.c b/drivers/media/tuners/it913x.c new file mode 100644 index 000000000000..a076c87eda7a --- /dev/null +++ b/drivers/media/tuners/it913x.c | |||
@@ -0,0 +1,478 @@ | |||
1 | /* | ||
2 | * ITE IT913X silicon tuner driver | ||
3 | * | ||
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. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.= | ||
21 | */ | ||
22 | |||
23 | #include "it913x.h" | ||
24 | #include <linux/regmap.h> | ||
25 | |||
26 | struct it913x_dev { | ||
27 | struct i2c_client *client; | ||
28 | struct regmap *regmap; | ||
29 | struct dvb_frontend *fe; | ||
30 | u8 chip_ver:2; | ||
31 | u8 role:2; | ||
32 | u16 xtal; | ||
33 | u8 fdiv; | ||
34 | u8 clk_mode; | ||
35 | u32 fn_min; | ||
36 | bool active; | ||
37 | }; | ||
38 | |||
39 | static int it913x_init(struct dvb_frontend *fe) | ||
40 | { | ||
41 | struct it913x_dev *dev = fe->tuner_priv; | ||
42 | int ret; | ||
43 | unsigned int utmp; | ||
44 | u8 iqik_m_cal, nv_val, buf[2]; | ||
45 | static const u8 nv[] = {48, 32, 24, 16, 12, 8, 6, 4, 2}; | ||
46 | unsigned long timeout; | ||
47 | |||
48 | dev_dbg(&dev->client->dev, "role %u\n", dev->role); | ||
49 | |||
50 | ret = regmap_write(dev->regmap, 0x80ec4c, 0x68); | ||
51 | if (ret) | ||
52 | goto err; | ||
53 | |||
54 | usleep_range(10000, 100000); | ||
55 | |||
56 | ret = regmap_read(dev->regmap, 0x80ec86, &utmp); | ||
57 | if (ret) | ||
58 | goto err; | ||
59 | |||
60 | switch (utmp) { | ||
61 | case 0: | ||
62 | /* 12.000 MHz */ | ||
63 | dev->clk_mode = utmp; | ||
64 | dev->xtal = 2000; | ||
65 | dev->fdiv = 3; | ||
66 | iqik_m_cal = 16; | ||
67 | break; | ||
68 | case 1: | ||
69 | /* 20.480 MHz */ | ||
70 | dev->clk_mode = utmp; | ||
71 | dev->xtal = 640; | ||
72 | dev->fdiv = 1; | ||
73 | iqik_m_cal = 6; | ||
74 | break; | ||
75 | default: | ||
76 | dev_err(&dev->client->dev, "unknown clock identifier %d\n", utmp); | ||
77 | goto err; | ||
78 | } | ||
79 | |||
80 | ret = regmap_read(dev->regmap, 0x80ed03, &utmp); | ||
81 | if (ret) | ||
82 | goto err; | ||
83 | |||
84 | else if (utmp < ARRAY_SIZE(nv)) | ||
85 | nv_val = nv[utmp]; | ||
86 | else | ||
87 | nv_val = 2; | ||
88 | |||
89 | #define TIMEOUT 50 | ||
90 | timeout = jiffies + msecs_to_jiffies(TIMEOUT); | ||
91 | while (!time_after(jiffies, timeout)) { | ||
92 | ret = regmap_bulk_read(dev->regmap, 0x80ed23, buf, 2); | ||
93 | if (ret) | ||
94 | goto err; | ||
95 | |||
96 | utmp = (buf[1] << 8) | (buf[0] << 0); | ||
97 | if (utmp) | ||
98 | break; | ||
99 | } | ||
100 | |||
101 | dev_dbg(&dev->client->dev, "r_fbc_m_bdry took %u ms, val %u\n", | ||
102 | jiffies_to_msecs(jiffies) - | ||
103 | (jiffies_to_msecs(timeout) - TIMEOUT), utmp); | ||
104 | |||
105 | dev->fn_min = dev->xtal * utmp; | ||
106 | dev->fn_min /= (dev->fdiv * nv_val); | ||
107 | dev->fn_min *= 1000; | ||
108 | dev_dbg(&dev->client->dev, "fn_min %u\n", dev->fn_min); | ||
109 | |||
110 | /* | ||
111 | * Chip version BX never sets that flag so we just wait 50ms in that | ||
112 | * case. It is possible poll BX similarly than AX and then timeout in | ||
113 | * order to get 50ms delay, but that causes about 120 extra I2C | ||
114 | * messages. As for now, we just wait and reduce IO. | ||
115 | */ | ||
116 | if (dev->chip_ver == 1) { | ||
117 | #define TIMEOUT 50 | ||
118 | timeout = jiffies + msecs_to_jiffies(TIMEOUT); | ||
119 | while (!time_after(jiffies, timeout)) { | ||
120 | ret = regmap_read(dev->regmap, 0x80ec82, &utmp); | ||
121 | if (ret) | ||
122 | goto err; | ||
123 | |||
124 | if (utmp) | ||
125 | break; | ||
126 | } | ||
127 | |||
128 | dev_dbg(&dev->client->dev, "p_tsm_init_mode took %u ms, val %u\n", | ||
129 | jiffies_to_msecs(jiffies) - | ||
130 | (jiffies_to_msecs(timeout) - TIMEOUT), utmp); | ||
131 | } else { | ||
132 | msleep(50); | ||
133 | } | ||
134 | |||
135 | ret = regmap_write(dev->regmap, 0x80ed81, iqik_m_cal); | ||
136 | if (ret) | ||
137 | goto err; | ||
138 | |||
139 | ret = regmap_write(dev->regmap, 0x80ec57, 0x00); | ||
140 | if (ret) | ||
141 | goto err; | ||
142 | |||
143 | ret = regmap_write(dev->regmap, 0x80ec58, 0x00); | ||
144 | if (ret) | ||
145 | goto err; | ||
146 | |||
147 | ret = regmap_write(dev->regmap, 0x80ec40, 0x01); | ||
148 | if (ret) | ||
149 | goto err; | ||
150 | |||
151 | dev->active = true; | ||
152 | |||
153 | return 0; | ||
154 | err: | ||
155 | dev_dbg(&dev->client->dev, "failed %d\n", ret); | ||
156 | return ret; | ||
157 | } | ||
158 | |||
159 | static int it913x_sleep(struct dvb_frontend *fe) | ||
160 | { | ||
161 | struct it913x_dev *dev = fe->tuner_priv; | ||
162 | int ret, len; | ||
163 | |||
164 | dev_dbg(&dev->client->dev, "role %u\n", dev->role); | ||
165 | |||
166 | dev->active = false; | ||
167 | |||
168 | ret = regmap_bulk_write(dev->regmap, 0x80ec40, "\x00", 1); | ||
169 | if (ret) | ||
170 | goto err; | ||
171 | |||
172 | /* | ||
173 | * Writing '0x00' to master tuner register '0x80ec08' causes slave tuner | ||
174 | * communication lost. Due to that, we cannot put master full sleep. | ||
175 | */ | ||
176 | if (dev->role == IT913X_ROLE_DUAL_MASTER) | ||
177 | len = 4; | ||
178 | else | ||
179 | len = 15; | ||
180 | |||
181 | dev_dbg(&dev->client->dev, "role %u, len %d\n", dev->role, len); | ||
182 | |||
183 | ret = regmap_bulk_write(dev->regmap, 0x80ec02, | ||
184 | "\x3f\x1f\x3f\x3e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", | ||
185 | len); | ||
186 | if (ret) | ||
187 | goto err; | ||
188 | |||
189 | ret = regmap_bulk_write(dev->regmap, 0x80ec12, "\x00\x00\x00\x00", 4); | ||
190 | if (ret) | ||
191 | goto err; | ||
192 | |||
193 | ret = regmap_bulk_write(dev->regmap, 0x80ec17, | ||
194 | "\x00\x00\x00\x00\x00\x00\x00\x00\x00", 9); | ||
195 | if (ret) | ||
196 | goto err; | ||
197 | |||
198 | ret = regmap_bulk_write(dev->regmap, 0x80ec22, | ||
199 | "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 10); | ||
200 | if (ret) | ||
201 | goto err; | ||
202 | |||
203 | ret = regmap_bulk_write(dev->regmap, 0x80ec20, "\x00", 1); | ||
204 | if (ret) | ||
205 | goto err; | ||
206 | |||
207 | ret = regmap_bulk_write(dev->regmap, 0x80ec3f, "\x01", 1); | ||
208 | if (ret) | ||
209 | goto err; | ||
210 | |||
211 | return 0; | ||
212 | err: | ||
213 | dev_dbg(&dev->client->dev, "failed %d\n", ret); | ||
214 | return ret; | ||
215 | } | ||
216 | |||
217 | static int it913x_set_params(struct dvb_frontend *fe) | ||
218 | { | ||
219 | struct it913x_dev *dev = fe->tuner_priv; | ||
220 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; | ||
221 | int ret; | ||
222 | 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; | ||
226 | |||
227 | dev_dbg(&dev->client->dev, "role=%u, frequency %u, bandwidth_hz %u\n", | ||
228 | dev->role, c->frequency, c->bandwidth_hz); | ||
229 | |||
230 | if (!dev->active) { | ||
231 | ret = -EINVAL; | ||
232 | goto err; | ||
233 | } | ||
234 | |||
235 | if (c->frequency <= 74000000) { | ||
236 | n_div = 48; | ||
237 | n = 0; | ||
238 | } else if (c->frequency <= 111000000) { | ||
239 | n_div = 32; | ||
240 | n = 1; | ||
241 | } else if (c->frequency <= 148000000) { | ||
242 | n_div = 24; | ||
243 | n = 2; | ||
244 | } else if (c->frequency <= 222000000) { | ||
245 | n_div = 16; | ||
246 | n = 3; | ||
247 | } else if (c->frequency <= 296000000) { | ||
248 | n_div = 12; | ||
249 | n = 4; | ||
250 | } else if (c->frequency <= 445000000) { | ||
251 | n_div = 8; | ||
252 | n = 5; | ||
253 | } else if (c->frequency <= dev->fn_min) { | ||
254 | n_div = 6; | ||
255 | n = 6; | ||
256 | } else if (c->frequency <= 950000000) { | ||
257 | n_div = 4; | ||
258 | n = 7; | ||
259 | } else { | ||
260 | n_div = 2; | ||
261 | n = 0; | ||
262 | } | ||
263 | |||
264 | ret = regmap_read(dev->regmap, 0x80ed81, &utmp); | ||
265 | if (ret) | ||
266 | goto err; | ||
267 | |||
268 | iqik_m_cal = utmp * n_div; | ||
269 | |||
270 | if (utmp < 0x20) { | ||
271 | if (dev->clk_mode == 0) | ||
272 | 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; | ||
277 | if (dev->clk_mode == 0) | ||
278 | iqik_m_cal = ~((iqik_m_cal * 9) >> 5); | ||
279 | else | ||
280 | iqik_m_cal = ~(iqik_m_cal >> 1); | ||
281 | } | ||
282 | |||
283 | 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; | ||
286 | |||
287 | if ((t_cal_freq - utmp) >= (dev->xtal >> 1)) | ||
288 | pre_lo_freq++; | ||
289 | |||
290 | pre_lo_freq += (u32) n << 13; | ||
291 | /* Frequency OMEGA_IQIK_M_CAL_MID*/ | ||
292 | t_cal_freq = pre_lo_freq + (u32)iqik_m_cal; | ||
293 | dev_dbg(&dev->client->dev, "t_cal_freq %u, pre_lo_freq %u\n", | ||
294 | t_cal_freq, pre_lo_freq); | ||
295 | |||
296 | 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); | ||
333 | if (ret) | ||
334 | goto err; | ||
335 | |||
336 | 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); | ||
346 | if (ret) | ||
347 | goto err; | ||
348 | |||
349 | /* XXX: latest windows driver sets different value (a8 != 68) */ | ||
350 | ret = regmap_write(dev->regmap, 0x80ec4c, 0xa0 | (l_band << 3)); | ||
351 | if (ret) | ||
352 | goto err; | ||
353 | |||
354 | ret = regmap_write(dev->regmap, 0x80ec4d, (t_cal_freq >> 0) & 0xff); | ||
355 | if (ret) | ||
356 | goto err; | ||
357 | |||
358 | 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 | |||
370 | return 0; | ||
371 | err: | ||
372 | dev_dbg(&dev->client->dev, "failed %d\n", ret); | ||
373 | return ret; | ||
374 | } | ||
375 | |||
376 | static const struct dvb_tuner_ops it913x_tuner_ops = { | ||
377 | .info = { | ||
378 | .name = "ITE IT913X", | ||
379 | .frequency_min = 174000000, | ||
380 | .frequency_max = 862000000, | ||
381 | }, | ||
382 | |||
383 | .init = it913x_init, | ||
384 | .sleep = it913x_sleep, | ||
385 | .set_params = it913x_set_params, | ||
386 | }; | ||
387 | |||
388 | static int it913x_probe(struct i2c_client *client, | ||
389 | const struct i2c_device_id *id) | ||
390 | { | ||
391 | struct it913x_config *cfg = client->dev.platform_data; | ||
392 | struct dvb_frontend *fe = cfg->fe; | ||
393 | struct it913x_dev *dev; | ||
394 | int ret; | ||
395 | char *chip_ver_str; | ||
396 | static const struct regmap_config regmap_config = { | ||
397 | .reg_bits = 24, | ||
398 | .val_bits = 8, | ||
399 | }; | ||
400 | |||
401 | dev = kzalloc(sizeof(struct it913x_dev), GFP_KERNEL); | ||
402 | if (dev == NULL) { | ||
403 | ret = -ENOMEM; | ||
404 | dev_err(&client->dev, "kzalloc() failed\n"); | ||
405 | goto err; | ||
406 | } | ||
407 | |||
408 | dev->client = client; | ||
409 | dev->fe = cfg->fe; | ||
410 | dev->chip_ver = cfg->chip_ver; | ||
411 | dev->role = cfg->role; | ||
412 | dev->regmap = regmap_init_i2c(client, ®map_config); | ||
413 | if (IS_ERR(dev->regmap)) { | ||
414 | ret = PTR_ERR(dev->regmap); | ||
415 | goto err_kfree; | ||
416 | } | ||
417 | |||
418 | fe->tuner_priv = dev; | ||
419 | memcpy(&fe->ops.tuner_ops, &it913x_tuner_ops, | ||
420 | sizeof(struct dvb_tuner_ops)); | ||
421 | i2c_set_clientdata(client, dev); | ||
422 | |||
423 | if (dev->chip_ver == 1) | ||
424 | chip_ver_str = "AX"; | ||
425 | else if (dev->chip_ver == 2) | ||
426 | chip_ver_str = "BX"; | ||
427 | else | ||
428 | chip_ver_str = "??"; | ||
429 | |||
430 | dev_info(&dev->client->dev, "ITE IT913X %s successfully attached\n", | ||
431 | chip_ver_str); | ||
432 | dev_dbg(&dev->client->dev, "chip_ver %u, role %u\n", | ||
433 | dev->chip_ver, dev->role); | ||
434 | return 0; | ||
435 | |||
436 | err_kfree: | ||
437 | kfree(dev); | ||
438 | err: | ||
439 | dev_dbg(&client->dev, "failed %d\n", ret); | ||
440 | return ret; | ||
441 | } | ||
442 | |||
443 | static int it913x_remove(struct i2c_client *client) | ||
444 | { | ||
445 | struct it913x_dev *dev = i2c_get_clientdata(client); | ||
446 | struct dvb_frontend *fe = dev->fe; | ||
447 | |||
448 | dev_dbg(&client->dev, "\n"); | ||
449 | |||
450 | memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); | ||
451 | fe->tuner_priv = NULL; | ||
452 | regmap_exit(dev->regmap); | ||
453 | kfree(dev); | ||
454 | |||
455 | return 0; | ||
456 | } | ||
457 | |||
458 | static const struct i2c_device_id it913x_id_table[] = { | ||
459 | {"it913x", 0}, | ||
460 | {} | ||
461 | }; | ||
462 | MODULE_DEVICE_TABLE(i2c, it913x_id_table); | ||
463 | |||
464 | static struct i2c_driver it913x_driver = { | ||
465 | .driver = { | ||
466 | .owner = THIS_MODULE, | ||
467 | .name = "it913x", | ||
468 | }, | ||
469 | .probe = it913x_probe, | ||
470 | .remove = it913x_remove, | ||
471 | .id_table = it913x_id_table, | ||
472 | }; | ||
473 | |||
474 | module_i2c_driver(it913x_driver); | ||
475 | |||
476 | MODULE_DESCRIPTION("ITE IT913X silicon tuner driver"); | ||
477 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); | ||
478 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/tuners/tuner_it913x.h b/drivers/media/tuners/it913x.h index 12dd36bd9e79..33de53d4a566 100644 --- a/drivers/media/tuners/tuner_it913x.h +++ b/drivers/media/tuners/it913x.h | |||
@@ -25,21 +25,30 @@ | |||
25 | 25 | ||
26 | #include "dvb_frontend.h" | 26 | #include "dvb_frontend.h" |
27 | 27 | ||
28 | #if defined(CONFIG_MEDIA_TUNER_IT913X) || \ | 28 | /* |
29 | (defined(CONFIG_MEDIA_TUNER_IT913X_MODULE) && defined(MODULE)) | 29 | * I2C address |
30 | extern struct dvb_frontend *it913x_attach(struct dvb_frontend *fe, | 30 | * 0x38, 0x3a, 0x3c, 0x3e |
31 | struct i2c_adapter *i2c_adap, | 31 | */ |
32 | u8 i2c_addr, | 32 | struct it913x_config { |
33 | u8 config); | 33 | /* |
34 | #else | 34 | * pointer to DVB frontend |
35 | static inline struct dvb_frontend *it913x_attach(struct dvb_frontend *fe, | 35 | */ |
36 | struct i2c_adapter *i2c_adap, | 36 | struct dvb_frontend *fe; |
37 | u8 i2c_addr, | 37 | |
38 | u8 config) | 38 | /* |
39 | { | 39 | * chip version |
40 | pr_warn("%s: driver disabled by Kconfig\n", __func__); | 40 | * 1 = IT9135 AX |
41 | return NULL; | 41 | * 2 = IT9135 BX |
42 | } | 42 | */ |
43 | #endif | 43 | unsigned int chip_ver:2; |
44 | |||
45 | /* | ||
46 | * tuner role | ||
47 | */ | ||
48 | #define IT913X_ROLE_SINGLE 0 | ||
49 | #define IT913X_ROLE_DUAL_MASTER 1 | ||
50 | #define IT913X_ROLE_DUAL_SLAVE 2 | ||
51 | unsigned int role:2; | ||
52 | }; | ||
44 | 53 | ||
45 | #endif | 54 | #endif |
diff --git a/drivers/media/tuners/m88ts2022.c b/drivers/media/tuners/m88ts2022.c index 40c42dec721b..caa542346891 100644 --- a/drivers/media/tuners/m88ts2022.c +++ b/drivers/media/tuners/m88ts2022.c | |||
@@ -18,120 +18,11 @@ | |||
18 | 18 | ||
19 | #include "m88ts2022_priv.h" | 19 | #include "m88ts2022_priv.h" |
20 | 20 | ||
21 | /* write multiple registers */ | 21 | static int m88ts2022_cmd(struct m88ts2022_dev *dev, int op, int sleep, u8 reg, |
22 | static int m88ts2022_wr_regs(struct m88ts2022_priv *priv, | 22 | u8 mask, u8 val, u8 *reg_val) |
23 | u8 reg, const u8 *val, int len) | ||
24 | { | 23 | { |
25 | #define MAX_WR_LEN 3 | ||
26 | #define MAX_WR_XFER_LEN (MAX_WR_LEN + 1) | ||
27 | int ret; | ||
28 | u8 buf[MAX_WR_XFER_LEN]; | ||
29 | struct i2c_msg msg[1] = { | ||
30 | { | ||
31 | .addr = priv->client->addr, | ||
32 | .flags = 0, | ||
33 | .len = 1 + len, | ||
34 | .buf = buf, | ||
35 | } | ||
36 | }; | ||
37 | |||
38 | if (WARN_ON(len > MAX_WR_LEN)) | ||
39 | return -EINVAL; | ||
40 | |||
41 | buf[0] = reg; | ||
42 | memcpy(&buf[1], val, len); | ||
43 | |||
44 | ret = i2c_transfer(priv->client->adapter, msg, 1); | ||
45 | if (ret == 1) { | ||
46 | ret = 0; | ||
47 | } else { | ||
48 | dev_warn(&priv->client->dev, | ||
49 | "%s: i2c wr failed=%d reg=%02x len=%d\n", | ||
50 | KBUILD_MODNAME, ret, reg, len); | ||
51 | ret = -EREMOTEIO; | ||
52 | } | ||
53 | |||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | /* read multiple registers */ | ||
58 | static int m88ts2022_rd_regs(struct m88ts2022_priv *priv, u8 reg, | ||
59 | u8 *val, int len) | ||
60 | { | ||
61 | #define MAX_RD_LEN 1 | ||
62 | #define MAX_RD_XFER_LEN (MAX_RD_LEN) | ||
63 | int ret; | ||
64 | u8 buf[MAX_RD_XFER_LEN]; | ||
65 | struct i2c_msg msg[2] = { | ||
66 | { | ||
67 | .addr = priv->client->addr, | ||
68 | .flags = 0, | ||
69 | .len = 1, | ||
70 | .buf = ®, | ||
71 | }, { | ||
72 | .addr = priv->client->addr, | ||
73 | .flags = I2C_M_RD, | ||
74 | .len = len, | ||
75 | .buf = buf, | ||
76 | } | ||
77 | }; | ||
78 | |||
79 | if (WARN_ON(len > MAX_RD_LEN)) | ||
80 | return -EINVAL; | ||
81 | |||
82 | ret = i2c_transfer(priv->client->adapter, msg, 2); | ||
83 | if (ret == 2) { | ||
84 | memcpy(val, buf, len); | ||
85 | ret = 0; | ||
86 | } else { | ||
87 | dev_warn(&priv->client->dev, | ||
88 | "%s: i2c rd failed=%d reg=%02x len=%d\n", | ||
89 | KBUILD_MODNAME, ret, reg, len); | ||
90 | ret = -EREMOTEIO; | ||
91 | } | ||
92 | |||
93 | return ret; | ||
94 | } | ||
95 | |||
96 | /* write single register */ | ||
97 | static int m88ts2022_wr_reg(struct m88ts2022_priv *priv, u8 reg, u8 val) | ||
98 | { | ||
99 | return m88ts2022_wr_regs(priv, reg, &val, 1); | ||
100 | } | ||
101 | |||
102 | /* read single register */ | ||
103 | static int m88ts2022_rd_reg(struct m88ts2022_priv *priv, u8 reg, u8 *val) | ||
104 | { | ||
105 | return m88ts2022_rd_regs(priv, reg, val, 1); | ||
106 | } | ||
107 | |||
108 | /* write single register with mask */ | ||
109 | static int m88ts2022_wr_reg_mask(struct m88ts2022_priv *priv, | ||
110 | u8 reg, u8 val, u8 mask) | ||
111 | { | ||
112 | int ret; | ||
113 | u8 u8tmp; | ||
114 | |||
115 | /* no need for read if whole reg is written */ | ||
116 | if (mask != 0xff) { | ||
117 | ret = m88ts2022_rd_regs(priv, reg, &u8tmp, 1); | ||
118 | if (ret) | ||
119 | return ret; | ||
120 | |||
121 | val &= mask; | ||
122 | u8tmp &= ~mask; | ||
123 | val |= u8tmp; | ||
124 | } | ||
125 | |||
126 | return m88ts2022_wr_regs(priv, reg, &val, 1); | ||
127 | } | ||
128 | |||
129 | static int m88ts2022_cmd(struct dvb_frontend *fe, | ||
130 | int op, int sleep, u8 reg, u8 mask, u8 val, u8 *reg_val) | ||
131 | { | ||
132 | struct m88ts2022_priv *priv = fe->tuner_priv; | ||
133 | int ret, i; | 24 | int ret, i; |
134 | u8 u8tmp; | 25 | unsigned int utmp; |
135 | struct m88ts2022_reg_val reg_vals[] = { | 26 | struct m88ts2022_reg_val reg_vals[] = { |
136 | {0x51, 0x1f - op}, | 27 | {0x51, 0x1f - op}, |
137 | {0x51, 0x1f}, | 28 | {0x51, 0x1f}, |
@@ -140,12 +31,12 @@ static int m88ts2022_cmd(struct dvb_frontend *fe, | |||
140 | }; | 31 | }; |
141 | 32 | ||
142 | for (i = 0; i < 2; i++) { | 33 | for (i = 0; i < 2; i++) { |
143 | dev_dbg(&priv->client->dev, | 34 | dev_dbg(&dev->client->dev, |
144 | "%s: i=%d op=%02x reg=%02x mask=%02x val=%02x\n", | 35 | "i=%d op=%02x reg=%02x mask=%02x val=%02x\n", |
145 | __func__, i, op, reg, mask, val); | 36 | i, op, reg, mask, val); |
146 | 37 | ||
147 | for (i = 0; i < ARRAY_SIZE(reg_vals); i++) { | 38 | for (i = 0; i < ARRAY_SIZE(reg_vals); i++) { |
148 | ret = m88ts2022_wr_reg(priv, reg_vals[i].reg, | 39 | ret = regmap_write(dev->regmap, reg_vals[i].reg, |
149 | reg_vals[i].val); | 40 | reg_vals[i].val); |
150 | if (ret) | 41 | if (ret) |
151 | goto err; | 42 | goto err; |
@@ -153,37 +44,38 @@ static int m88ts2022_cmd(struct dvb_frontend *fe, | |||
153 | 44 | ||
154 | usleep_range(sleep * 1000, sleep * 10000); | 45 | usleep_range(sleep * 1000, sleep * 10000); |
155 | 46 | ||
156 | ret = m88ts2022_rd_reg(priv, reg, &u8tmp); | 47 | ret = regmap_read(dev->regmap, reg, &utmp); |
157 | if (ret) | 48 | if (ret) |
158 | goto err; | 49 | goto err; |
159 | 50 | ||
160 | if ((u8tmp & mask) != val) | 51 | if ((utmp & mask) != val) |
161 | break; | 52 | break; |
162 | } | 53 | } |
163 | 54 | ||
164 | if (reg_val) | 55 | if (reg_val) |
165 | *reg_val = u8tmp; | 56 | *reg_val = utmp; |
166 | err: | 57 | err: |
167 | return ret; | 58 | return ret; |
168 | } | 59 | } |
169 | 60 | ||
170 | static int m88ts2022_set_params(struct dvb_frontend *fe) | 61 | static int m88ts2022_set_params(struct dvb_frontend *fe) |
171 | { | 62 | { |
172 | struct m88ts2022_priv *priv = fe->tuner_priv; | 63 | struct m88ts2022_dev *dev = fe->tuner_priv; |
173 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; | 64 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
174 | int ret; | 65 | int ret; |
175 | unsigned int frequency_khz, frequency_offset_khz, f_3db_hz; | 66 | unsigned int utmp, frequency_khz, frequency_offset_khz, f_3db_hz; |
176 | unsigned int f_ref_khz, f_vco_khz, div_ref, div_out, pll_n, gdiv28; | 67 | unsigned int f_ref_khz, f_vco_khz, div_ref, div_out, pll_n, gdiv28; |
177 | u8 buf[3], u8tmp, cap_code, lpf_gm, lpf_mxdiv, div_max, div_min; | 68 | u8 buf[3], u8tmp, cap_code, lpf_gm, lpf_mxdiv, div_max, div_min; |
178 | u16 u16tmp; | 69 | u16 u16tmp; |
179 | dev_dbg(&priv->client->dev, | 70 | |
180 | "%s: frequency=%d symbol_rate=%d rolloff=%d\n", | 71 | dev_dbg(&dev->client->dev, |
181 | __func__, c->frequency, c->symbol_rate, c->rolloff); | 72 | "frequency=%d symbol_rate=%d rolloff=%d\n", |
73 | c->frequency, c->symbol_rate, c->rolloff); | ||
182 | /* | 74 | /* |
183 | * Integer-N PLL synthesizer | 75 | * Integer-N PLL synthesizer |
184 | * kHz is used for all calculations to keep calculations within 32-bit | 76 | * kHz is used for all calculations to keep calculations within 32-bit |
185 | */ | 77 | */ |
186 | f_ref_khz = DIV_ROUND_CLOSEST(priv->cfg.clock, 1000); | 78 | f_ref_khz = DIV_ROUND_CLOSEST(dev->cfg.clock, 1000); |
187 | div_ref = DIV_ROUND_CLOSEST(f_ref_khz, 2000); | 79 | div_ref = DIV_ROUND_CLOSEST(f_ref_khz, 2000); |
188 | 80 | ||
189 | if (c->symbol_rate < 5000000) | 81 | if (c->symbol_rate < 5000000) |
@@ -203,14 +95,14 @@ static int m88ts2022_set_params(struct dvb_frontend *fe) | |||
203 | 95 | ||
204 | buf[0] = u8tmp; | 96 | buf[0] = u8tmp; |
205 | buf[1] = 0x40; | 97 | buf[1] = 0x40; |
206 | ret = m88ts2022_wr_regs(priv, 0x10, buf, 2); | 98 | ret = regmap_bulk_write(dev->regmap, 0x10, buf, 2); |
207 | if (ret) | 99 | if (ret) |
208 | goto err; | 100 | goto err; |
209 | 101 | ||
210 | f_vco_khz = frequency_khz * div_out; | 102 | f_vco_khz = frequency_khz * div_out; |
211 | pll_n = f_vco_khz * div_ref / f_ref_khz; | 103 | pll_n = f_vco_khz * div_ref / f_ref_khz; |
212 | pll_n += pll_n % 2; | 104 | pll_n += pll_n % 2; |
213 | priv->frequency_khz = pll_n * f_ref_khz / div_ref / div_out; | 105 | dev->frequency_khz = pll_n * f_ref_khz / div_ref / div_out; |
214 | 106 | ||
215 | if (pll_n < 4095) | 107 | if (pll_n < 4095) |
216 | u16tmp = pll_n - 1024; | 108 | u16tmp = pll_n - 1024; |
@@ -222,88 +114,87 @@ static int m88ts2022_set_params(struct dvb_frontend *fe) | |||
222 | buf[0] = (u16tmp >> 8) & 0x3f; | 114 | buf[0] = (u16tmp >> 8) & 0x3f; |
223 | buf[1] = (u16tmp >> 0) & 0xff; | 115 | buf[1] = (u16tmp >> 0) & 0xff; |
224 | buf[2] = div_ref - 8; | 116 | buf[2] = div_ref - 8; |
225 | ret = m88ts2022_wr_regs(priv, 0x01, buf, 3); | 117 | ret = regmap_bulk_write(dev->regmap, 0x01, buf, 3); |
226 | if (ret) | 118 | if (ret) |
227 | goto err; | 119 | goto err; |
228 | 120 | ||
229 | dev_dbg(&priv->client->dev, | 121 | dev_dbg(&dev->client->dev, |
230 | "%s: frequency=%u offset=%d f_vco_khz=%u pll_n=%u div_ref=%u div_out=%u\n", | 122 | "frequency=%u offset=%d f_vco_khz=%u pll_n=%u div_ref=%u div_out=%u\n", |
231 | __func__, priv->frequency_khz, | 123 | dev->frequency_khz, dev->frequency_khz - c->frequency, |
232 | priv->frequency_khz - c->frequency, f_vco_khz, pll_n, | 124 | f_vco_khz, pll_n, div_ref, div_out); |
233 | div_ref, div_out); | ||
234 | 125 | ||
235 | ret = m88ts2022_cmd(fe, 0x10, 5, 0x15, 0x40, 0x00, NULL); | 126 | ret = m88ts2022_cmd(dev, 0x10, 5, 0x15, 0x40, 0x00, NULL); |
236 | if (ret) | 127 | if (ret) |
237 | goto err; | 128 | goto err; |
238 | 129 | ||
239 | ret = m88ts2022_rd_reg(priv, 0x14, &u8tmp); | 130 | ret = regmap_read(dev->regmap, 0x14, &utmp); |
240 | if (ret) | 131 | if (ret) |
241 | goto err; | 132 | goto err; |
242 | 133 | ||
243 | u8tmp &= 0x7f; | 134 | utmp &= 0x7f; |
244 | if (u8tmp < 64) { | 135 | if (utmp < 64) { |
245 | ret = m88ts2022_wr_reg_mask(priv, 0x10, 0x80, 0x80); | 136 | ret = regmap_update_bits(dev->regmap, 0x10, 0x80, 0x80); |
246 | if (ret) | 137 | if (ret) |
247 | goto err; | 138 | goto err; |
248 | 139 | ||
249 | ret = m88ts2022_wr_reg(priv, 0x11, 0x6f); | 140 | ret = regmap_write(dev->regmap, 0x11, 0x6f); |
250 | if (ret) | 141 | if (ret) |
251 | goto err; | 142 | goto err; |
252 | 143 | ||
253 | ret = m88ts2022_cmd(fe, 0x10, 5, 0x15, 0x40, 0x00, NULL); | 144 | ret = m88ts2022_cmd(dev, 0x10, 5, 0x15, 0x40, 0x00, NULL); |
254 | if (ret) | 145 | if (ret) |
255 | goto err; | 146 | goto err; |
256 | } | 147 | } |
257 | 148 | ||
258 | ret = m88ts2022_rd_reg(priv, 0x14, &u8tmp); | 149 | ret = regmap_read(dev->regmap, 0x14, &utmp); |
259 | if (ret) | 150 | if (ret) |
260 | goto err; | 151 | goto err; |
261 | 152 | ||
262 | u8tmp &= 0x1f; | 153 | utmp &= 0x1f; |
263 | if (u8tmp > 19) { | 154 | if (utmp > 19) { |
264 | ret = m88ts2022_wr_reg_mask(priv, 0x10, 0x00, 0x02); | 155 | ret = regmap_update_bits(dev->regmap, 0x10, 0x02, 0x00); |
265 | if (ret) | 156 | if (ret) |
266 | goto err; | 157 | goto err; |
267 | } | 158 | } |
268 | 159 | ||
269 | ret = m88ts2022_cmd(fe, 0x08, 5, 0x3c, 0xff, 0x00, NULL); | 160 | ret = m88ts2022_cmd(dev, 0x08, 5, 0x3c, 0xff, 0x00, NULL); |
270 | if (ret) | 161 | if (ret) |
271 | goto err; | 162 | goto err; |
272 | 163 | ||
273 | ret = m88ts2022_wr_reg(priv, 0x25, 0x00); | 164 | ret = regmap_write(dev->regmap, 0x25, 0x00); |
274 | if (ret) | 165 | if (ret) |
275 | goto err; | 166 | goto err; |
276 | 167 | ||
277 | ret = m88ts2022_wr_reg(priv, 0x27, 0x70); | 168 | ret = regmap_write(dev->regmap, 0x27, 0x70); |
278 | if (ret) | 169 | if (ret) |
279 | goto err; | 170 | goto err; |
280 | 171 | ||
281 | ret = m88ts2022_wr_reg(priv, 0x41, 0x09); | 172 | ret = regmap_write(dev->regmap, 0x41, 0x09); |
282 | if (ret) | 173 | if (ret) |
283 | goto err; | 174 | goto err; |
284 | 175 | ||
285 | ret = m88ts2022_wr_reg(priv, 0x08, 0x0b); | 176 | ret = regmap_write(dev->regmap, 0x08, 0x0b); |
286 | if (ret) | 177 | if (ret) |
287 | goto err; | 178 | goto err; |
288 | 179 | ||
289 | /* filters */ | 180 | /* filters */ |
290 | gdiv28 = DIV_ROUND_CLOSEST(f_ref_khz * 1694U, 1000000U); | 181 | gdiv28 = DIV_ROUND_CLOSEST(f_ref_khz * 1694U, 1000000U); |
291 | 182 | ||
292 | ret = m88ts2022_wr_reg(priv, 0x04, gdiv28); | 183 | ret = regmap_write(dev->regmap, 0x04, gdiv28); |
293 | if (ret) | 184 | if (ret) |
294 | goto err; | 185 | goto err; |
295 | 186 | ||
296 | ret = m88ts2022_cmd(fe, 0x04, 2, 0x26, 0xff, 0x00, &u8tmp); | 187 | ret = m88ts2022_cmd(dev, 0x04, 2, 0x26, 0xff, 0x00, &u8tmp); |
297 | if (ret) | 188 | if (ret) |
298 | goto err; | 189 | goto err; |
299 | 190 | ||
300 | cap_code = u8tmp & 0x3f; | 191 | cap_code = u8tmp & 0x3f; |
301 | 192 | ||
302 | ret = m88ts2022_wr_reg(priv, 0x41, 0x0d); | 193 | ret = regmap_write(dev->regmap, 0x41, 0x0d); |
303 | if (ret) | 194 | if (ret) |
304 | goto err; | 195 | goto err; |
305 | 196 | ||
306 | ret = m88ts2022_cmd(fe, 0x04, 2, 0x26, 0xff, 0x00, &u8tmp); | 197 | ret = m88ts2022_cmd(dev, 0x04, 2, 0x26, 0xff, 0x00, &u8tmp); |
307 | if (ret) | 198 | if (ret) |
308 | goto err; | 199 | goto err; |
309 | 200 | ||
@@ -314,7 +205,7 @@ static int m88ts2022_set_params(struct dvb_frontend *fe) | |||
314 | div_min = gdiv28 * 78 / 100; | 205 | div_min = gdiv28 * 78 / 100; |
315 | div_max = clamp_val(div_max, 0U, 63U); | 206 | div_max = clamp_val(div_max, 0U, 63U); |
316 | 207 | ||
317 | f_3db_hz = c->symbol_rate * 135UL / 200UL; | 208 | f_3db_hz = mult_frac(c->symbol_rate, 135, 200); |
318 | f_3db_hz += 2000000U + (frequency_offset_khz * 1000U); | 209 | f_3db_hz += 2000000U + (frequency_offset_khz * 1000U); |
319 | f_3db_hz = clamp(f_3db_hz, 7000000U, 40000000U); | 210 | f_3db_hz = clamp(f_3db_hz, 7000000U, 40000000U); |
320 | 211 | ||
@@ -327,25 +218,25 @@ static int m88ts2022_set_params(struct dvb_frontend *fe) | |||
327 | lpf_mxdiv = DIV_ROUND_CLOSEST(++lpf_gm * LPF_COEFF * f_ref_khz, f_3db_hz); | 218 | lpf_mxdiv = DIV_ROUND_CLOSEST(++lpf_gm * LPF_COEFF * f_ref_khz, f_3db_hz); |
328 | lpf_mxdiv = clamp_val(lpf_mxdiv, 0U, div_max); | 219 | lpf_mxdiv = clamp_val(lpf_mxdiv, 0U, div_max); |
329 | 220 | ||
330 | ret = m88ts2022_wr_reg(priv, 0x04, lpf_mxdiv); | 221 | ret = regmap_write(dev->regmap, 0x04, lpf_mxdiv); |
331 | if (ret) | 222 | if (ret) |
332 | goto err; | 223 | goto err; |
333 | 224 | ||
334 | ret = m88ts2022_wr_reg(priv, 0x06, lpf_gm); | 225 | ret = regmap_write(dev->regmap, 0x06, lpf_gm); |
335 | if (ret) | 226 | if (ret) |
336 | goto err; | 227 | goto err; |
337 | 228 | ||
338 | ret = m88ts2022_cmd(fe, 0x04, 2, 0x26, 0xff, 0x00, &u8tmp); | 229 | ret = m88ts2022_cmd(dev, 0x04, 2, 0x26, 0xff, 0x00, &u8tmp); |
339 | if (ret) | 230 | if (ret) |
340 | goto err; | 231 | goto err; |
341 | 232 | ||
342 | cap_code = u8tmp & 0x3f; | 233 | cap_code = u8tmp & 0x3f; |
343 | 234 | ||
344 | ret = m88ts2022_wr_reg(priv, 0x41, 0x09); | 235 | ret = regmap_write(dev->regmap, 0x41, 0x09); |
345 | if (ret) | 236 | if (ret) |
346 | goto err; | 237 | goto err; |
347 | 238 | ||
348 | ret = m88ts2022_cmd(fe, 0x04, 2, 0x26, 0xff, 0x00, &u8tmp); | 239 | ret = m88ts2022_cmd(dev, 0x04, 2, 0x26, 0xff, 0x00, &u8tmp); |
349 | if (ret) | 240 | if (ret) |
350 | goto err; | 241 | goto err; |
351 | 242 | ||
@@ -353,31 +244,31 @@ static int m88ts2022_set_params(struct dvb_frontend *fe) | |||
353 | cap_code = (cap_code + u8tmp) / 2; | 244 | cap_code = (cap_code + u8tmp) / 2; |
354 | 245 | ||
355 | u8tmp = cap_code | 0x80; | 246 | u8tmp = cap_code | 0x80; |
356 | ret = m88ts2022_wr_reg(priv, 0x25, u8tmp); | 247 | ret = regmap_write(dev->regmap, 0x25, u8tmp); |
357 | if (ret) | 248 | if (ret) |
358 | goto err; | 249 | goto err; |
359 | 250 | ||
360 | ret = m88ts2022_wr_reg(priv, 0x27, 0x30); | 251 | ret = regmap_write(dev->regmap, 0x27, 0x30); |
361 | if (ret) | 252 | if (ret) |
362 | goto err; | 253 | goto err; |
363 | 254 | ||
364 | ret = m88ts2022_wr_reg(priv, 0x08, 0x09); | 255 | ret = regmap_write(dev->regmap, 0x08, 0x09); |
365 | if (ret) | 256 | if (ret) |
366 | goto err; | 257 | goto err; |
367 | 258 | ||
368 | ret = m88ts2022_cmd(fe, 0x01, 20, 0x21, 0xff, 0x00, NULL); | 259 | ret = m88ts2022_cmd(dev, 0x01, 20, 0x21, 0xff, 0x00, NULL); |
369 | if (ret) | 260 | if (ret) |
370 | goto err; | 261 | goto err; |
371 | err: | 262 | err: |
372 | if (ret) | 263 | if (ret) |
373 | dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret); | 264 | dev_dbg(&dev->client->dev, "failed=%d\n", ret); |
374 | 265 | ||
375 | return ret; | 266 | return ret; |
376 | } | 267 | } |
377 | 268 | ||
378 | static int m88ts2022_init(struct dvb_frontend *fe) | 269 | static int m88ts2022_init(struct dvb_frontend *fe) |
379 | { | 270 | { |
380 | struct m88ts2022_priv *priv = fe->tuner_priv; | 271 | struct m88ts2022_dev *dev = fe->tuner_priv; |
381 | int ret, i; | 272 | int ret, i; |
382 | u8 u8tmp; | 273 | u8 u8tmp; |
383 | static const struct m88ts2022_reg_val reg_vals[] = { | 274 | static const struct m88ts2022_reg_val reg_vals[] = { |
@@ -393,23 +284,24 @@ static int m88ts2022_init(struct dvb_frontend *fe) | |||
393 | {0x24, 0x02}, | 284 | {0x24, 0x02}, |
394 | {0x12, 0xa0}, | 285 | {0x12, 0xa0}, |
395 | }; | 286 | }; |
396 | dev_dbg(&priv->client->dev, "%s:\n", __func__); | ||
397 | 287 | ||
398 | ret = m88ts2022_wr_reg(priv, 0x00, 0x01); | 288 | dev_dbg(&dev->client->dev, "\n"); |
289 | |||
290 | ret = regmap_write(dev->regmap, 0x00, 0x01); | ||
399 | if (ret) | 291 | if (ret) |
400 | goto err; | 292 | goto err; |
401 | 293 | ||
402 | ret = m88ts2022_wr_reg(priv, 0x00, 0x03); | 294 | ret = regmap_write(dev->regmap, 0x00, 0x03); |
403 | if (ret) | 295 | if (ret) |
404 | goto err; | 296 | goto err; |
405 | 297 | ||
406 | switch (priv->cfg.clock_out) { | 298 | switch (dev->cfg.clock_out) { |
407 | case M88TS2022_CLOCK_OUT_DISABLED: | 299 | case M88TS2022_CLOCK_OUT_DISABLED: |
408 | u8tmp = 0x60; | 300 | u8tmp = 0x60; |
409 | break; | 301 | break; |
410 | case M88TS2022_CLOCK_OUT_ENABLED: | 302 | case M88TS2022_CLOCK_OUT_ENABLED: |
411 | u8tmp = 0x70; | 303 | u8tmp = 0x70; |
412 | ret = m88ts2022_wr_reg(priv, 0x05, priv->cfg.clock_out_div); | 304 | ret = regmap_write(dev->regmap, 0x05, dev->cfg.clock_out_div); |
413 | if (ret) | 305 | if (ret) |
414 | goto err; | 306 | goto err; |
415 | break; | 307 | break; |
@@ -420,58 +312,61 @@ static int m88ts2022_init(struct dvb_frontend *fe) | |||
420 | goto err; | 312 | goto err; |
421 | } | 313 | } |
422 | 314 | ||
423 | ret = m88ts2022_wr_reg(priv, 0x42, u8tmp); | 315 | ret = regmap_write(dev->regmap, 0x42, u8tmp); |
424 | if (ret) | 316 | if (ret) |
425 | goto err; | 317 | goto err; |
426 | 318 | ||
427 | if (priv->cfg.loop_through) | 319 | if (dev->cfg.loop_through) |
428 | u8tmp = 0xec; | 320 | u8tmp = 0xec; |
429 | else | 321 | else |
430 | u8tmp = 0x6c; | 322 | u8tmp = 0x6c; |
431 | 323 | ||
432 | ret = m88ts2022_wr_reg(priv, 0x62, u8tmp); | 324 | ret = regmap_write(dev->regmap, 0x62, u8tmp); |
433 | if (ret) | 325 | if (ret) |
434 | goto err; | 326 | goto err; |
435 | 327 | ||
436 | for (i = 0; i < ARRAY_SIZE(reg_vals); i++) { | 328 | for (i = 0; i < ARRAY_SIZE(reg_vals); i++) { |
437 | ret = m88ts2022_wr_reg(priv, reg_vals[i].reg, reg_vals[i].val); | 329 | ret = regmap_write(dev->regmap, reg_vals[i].reg, reg_vals[i].val); |
438 | if (ret) | 330 | if (ret) |
439 | goto err; | 331 | goto err; |
440 | } | 332 | } |
441 | err: | 333 | err: |
442 | if (ret) | 334 | if (ret) |
443 | dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret); | 335 | dev_dbg(&dev->client->dev, "failed=%d\n", ret); |
444 | return ret; | 336 | return ret; |
445 | } | 337 | } |
446 | 338 | ||
447 | static int m88ts2022_sleep(struct dvb_frontend *fe) | 339 | static int m88ts2022_sleep(struct dvb_frontend *fe) |
448 | { | 340 | { |
449 | struct m88ts2022_priv *priv = fe->tuner_priv; | 341 | struct m88ts2022_dev *dev = fe->tuner_priv; |
450 | int ret; | 342 | int ret; |
451 | dev_dbg(&priv->client->dev, "%s:\n", __func__); | ||
452 | 343 | ||
453 | ret = m88ts2022_wr_reg(priv, 0x00, 0x00); | 344 | dev_dbg(&dev->client->dev, "\n"); |
345 | |||
346 | ret = regmap_write(dev->regmap, 0x00, 0x00); | ||
454 | if (ret) | 347 | if (ret) |
455 | goto err; | 348 | goto err; |
456 | err: | 349 | err: |
457 | if (ret) | 350 | if (ret) |
458 | dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret); | 351 | dev_dbg(&dev->client->dev, "failed=%d\n", ret); |
459 | return ret; | 352 | return ret; |
460 | } | 353 | } |
461 | 354 | ||
462 | static int m88ts2022_get_frequency(struct dvb_frontend *fe, u32 *frequency) | 355 | static int m88ts2022_get_frequency(struct dvb_frontend *fe, u32 *frequency) |
463 | { | 356 | { |
464 | struct m88ts2022_priv *priv = fe->tuner_priv; | 357 | struct m88ts2022_dev *dev = fe->tuner_priv; |
465 | dev_dbg(&priv->client->dev, "%s:\n", __func__); | ||
466 | 358 | ||
467 | *frequency = priv->frequency_khz; | 359 | dev_dbg(&dev->client->dev, "\n"); |
360 | |||
361 | *frequency = dev->frequency_khz; | ||
468 | return 0; | 362 | return 0; |
469 | } | 363 | } |
470 | 364 | ||
471 | static int m88ts2022_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) | 365 | static int m88ts2022_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) |
472 | { | 366 | { |
473 | struct m88ts2022_priv *priv = fe->tuner_priv; | 367 | struct m88ts2022_dev *dev = fe->tuner_priv; |
474 | dev_dbg(&priv->client->dev, "%s:\n", __func__); | 368 | |
369 | dev_dbg(&dev->client->dev, "\n"); | ||
475 | 370 | ||
476 | *frequency = 0; /* Zero-IF */ | 371 | *frequency = 0; /* Zero-IF */ |
477 | return 0; | 372 | return 0; |
@@ -479,31 +374,30 @@ static int m88ts2022_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) | |||
479 | 374 | ||
480 | static int m88ts2022_get_rf_strength(struct dvb_frontend *fe, u16 *strength) | 375 | static int m88ts2022_get_rf_strength(struct dvb_frontend *fe, u16 *strength) |
481 | { | 376 | { |
482 | struct m88ts2022_priv *priv = fe->tuner_priv; | 377 | struct m88ts2022_dev *dev = fe->tuner_priv; |
483 | int ret; | 378 | int ret; |
484 | u8 u8tmp; | ||
485 | u16 gain, u16tmp; | 379 | u16 gain, u16tmp; |
486 | unsigned int gain1, gain2, gain3; | 380 | unsigned int utmp, gain1, gain2, gain3; |
487 | 381 | ||
488 | ret = m88ts2022_rd_reg(priv, 0x3d, &u8tmp); | 382 | ret = regmap_read(dev->regmap, 0x3d, &utmp); |
489 | if (ret) | 383 | if (ret) |
490 | goto err; | 384 | goto err; |
491 | 385 | ||
492 | gain1 = (u8tmp >> 0) & 0x1f; | 386 | gain1 = (utmp >> 0) & 0x1f; |
493 | gain1 = clamp(gain1, 0U, 15U); | 387 | gain1 = clamp(gain1, 0U, 15U); |
494 | 388 | ||
495 | ret = m88ts2022_rd_reg(priv, 0x21, &u8tmp); | 389 | ret = regmap_read(dev->regmap, 0x21, &utmp); |
496 | if (ret) | 390 | if (ret) |
497 | goto err; | 391 | goto err; |
498 | 392 | ||
499 | gain2 = (u8tmp >> 0) & 0x1f; | 393 | gain2 = (utmp >> 0) & 0x1f; |
500 | gain2 = clamp(gain2, 2U, 16U); | 394 | gain2 = clamp(gain2, 2U, 16U); |
501 | 395 | ||
502 | ret = m88ts2022_rd_reg(priv, 0x66, &u8tmp); | 396 | ret = regmap_read(dev->regmap, 0x66, &utmp); |
503 | if (ret) | 397 | if (ret) |
504 | goto err; | 398 | goto err; |
505 | 399 | ||
506 | gain3 = (u8tmp >> 3) & 0x07; | 400 | gain3 = (utmp >> 3) & 0x07; |
507 | gain3 = clamp(gain3, 0U, 6U); | 401 | gain3 = clamp(gain3, 0U, 6U); |
508 | 402 | ||
509 | gain = gain1 * 265 + gain2 * 338 + gain3 * 285; | 403 | gain = gain1 * 265 + gain2 * 338 + gain3 * 285; |
@@ -515,7 +409,7 @@ static int m88ts2022_get_rf_strength(struct dvb_frontend *fe, u16 *strength) | |||
515 | *strength = (u16tmp - 59000) * 0xffff / (61500 - 59000); | 409 | *strength = (u16tmp - 59000) * 0xffff / (61500 - 59000); |
516 | err: | 410 | err: |
517 | if (ret) | 411 | if (ret) |
518 | dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret); | 412 | dev_dbg(&dev->client->dev, "failed=%d\n", ret); |
519 | return ret; | 413 | return ret; |
520 | } | 414 | } |
521 | 415 | ||
@@ -540,46 +434,56 @@ static int m88ts2022_probe(struct i2c_client *client, | |||
540 | { | 434 | { |
541 | struct m88ts2022_config *cfg = client->dev.platform_data; | 435 | struct m88ts2022_config *cfg = client->dev.platform_data; |
542 | struct dvb_frontend *fe = cfg->fe; | 436 | struct dvb_frontend *fe = cfg->fe; |
543 | struct m88ts2022_priv *priv; | 437 | struct m88ts2022_dev *dev; |
544 | int ret; | 438 | int ret; |
545 | u8 chip_id, u8tmp; | 439 | u8 u8tmp; |
440 | unsigned int utmp; | ||
441 | static const struct regmap_config regmap_config = { | ||
442 | .reg_bits = 8, | ||
443 | .val_bits = 8, | ||
444 | }; | ||
546 | 445 | ||
547 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | 446 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
548 | if (!priv) { | 447 | if (!dev) { |
549 | ret = -ENOMEM; | 448 | ret = -ENOMEM; |
550 | dev_err(&client->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME); | 449 | dev_err(&client->dev, "kzalloc() failed\n"); |
551 | goto err; | 450 | goto err; |
552 | } | 451 | } |
553 | 452 | ||
554 | memcpy(&priv->cfg, cfg, sizeof(struct m88ts2022_config)); | 453 | memcpy(&dev->cfg, cfg, sizeof(struct m88ts2022_config)); |
555 | priv->client = client; | 454 | dev->client = client; |
455 | dev->regmap = devm_regmap_init_i2c(client, ®map_config); | ||
456 | if (IS_ERR(dev->regmap)) { | ||
457 | ret = PTR_ERR(dev->regmap); | ||
458 | goto err; | ||
459 | } | ||
556 | 460 | ||
557 | /* check if the tuner is there */ | 461 | /* check if the tuner is there */ |
558 | ret = m88ts2022_rd_reg(priv, 0x00, &u8tmp); | 462 | ret = regmap_read(dev->regmap, 0x00, &utmp); |
559 | if (ret) | 463 | if (ret) |
560 | goto err; | 464 | goto err; |
561 | 465 | ||
562 | if ((u8tmp & 0x03) == 0x00) { | 466 | if ((utmp & 0x03) == 0x00) { |
563 | ret = m88ts2022_wr_reg(priv, 0x00, 0x01); | 467 | ret = regmap_write(dev->regmap, 0x00, 0x01); |
564 | if (ret < 0) | 468 | if (ret) |
565 | goto err; | 469 | goto err; |
566 | 470 | ||
567 | usleep_range(2000, 50000); | 471 | usleep_range(2000, 50000); |
568 | } | 472 | } |
569 | 473 | ||
570 | ret = m88ts2022_wr_reg(priv, 0x00, 0x03); | 474 | ret = regmap_write(dev->regmap, 0x00, 0x03); |
571 | if (ret) | 475 | if (ret) |
572 | goto err; | 476 | goto err; |
573 | 477 | ||
574 | usleep_range(2000, 50000); | 478 | usleep_range(2000, 50000); |
575 | 479 | ||
576 | ret = m88ts2022_rd_reg(priv, 0x00, &chip_id); | 480 | ret = regmap_read(dev->regmap, 0x00, &utmp); |
577 | if (ret) | 481 | if (ret) |
578 | goto err; | 482 | goto err; |
579 | 483 | ||
580 | dev_dbg(&priv->client->dev, "%s: chip_id=%02x\n", __func__, chip_id); | 484 | dev_dbg(&dev->client->dev, "chip_id=%02x\n", utmp); |
581 | 485 | ||
582 | switch (chip_id) { | 486 | switch (utmp) { |
583 | case 0xc3: | 487 | case 0xc3: |
584 | case 0x83: | 488 | case 0x83: |
585 | break; | 489 | break; |
@@ -587,13 +491,13 @@ static int m88ts2022_probe(struct i2c_client *client, | |||
587 | goto err; | 491 | goto err; |
588 | } | 492 | } |
589 | 493 | ||
590 | switch (priv->cfg.clock_out) { | 494 | switch (dev->cfg.clock_out) { |
591 | case M88TS2022_CLOCK_OUT_DISABLED: | 495 | case M88TS2022_CLOCK_OUT_DISABLED: |
592 | u8tmp = 0x60; | 496 | u8tmp = 0x60; |
593 | break; | 497 | break; |
594 | case M88TS2022_CLOCK_OUT_ENABLED: | 498 | case M88TS2022_CLOCK_OUT_ENABLED: |
595 | u8tmp = 0x70; | 499 | u8tmp = 0x70; |
596 | ret = m88ts2022_wr_reg(priv, 0x05, priv->cfg.clock_out_div); | 500 | ret = regmap_write(dev->regmap, 0x05, dev->cfg.clock_out_div); |
597 | if (ret) | 501 | if (ret) |
598 | goto err; | 502 | goto err; |
599 | break; | 503 | break; |
@@ -604,49 +508,48 @@ static int m88ts2022_probe(struct i2c_client *client, | |||
604 | goto err; | 508 | goto err; |
605 | } | 509 | } |
606 | 510 | ||
607 | ret = m88ts2022_wr_reg(priv, 0x42, u8tmp); | 511 | ret = regmap_write(dev->regmap, 0x42, u8tmp); |
608 | if (ret) | 512 | if (ret) |
609 | goto err; | 513 | goto err; |
610 | 514 | ||
611 | if (priv->cfg.loop_through) | 515 | if (dev->cfg.loop_through) |
612 | u8tmp = 0xec; | 516 | u8tmp = 0xec; |
613 | else | 517 | else |
614 | u8tmp = 0x6c; | 518 | u8tmp = 0x6c; |
615 | 519 | ||
616 | ret = m88ts2022_wr_reg(priv, 0x62, u8tmp); | 520 | ret = regmap_write(dev->regmap, 0x62, u8tmp); |
617 | if (ret) | 521 | if (ret) |
618 | goto err; | 522 | goto err; |
619 | 523 | ||
620 | /* sleep */ | 524 | /* sleep */ |
621 | ret = m88ts2022_wr_reg(priv, 0x00, 0x00); | 525 | ret = regmap_write(dev->regmap, 0x00, 0x00); |
622 | if (ret) | 526 | if (ret) |
623 | goto err; | 527 | goto err; |
624 | 528 | ||
625 | dev_info(&priv->client->dev, | 529 | dev_info(&dev->client->dev, "Montage M88TS2022 successfully identified\n"); |
626 | "%s: Montage M88TS2022 successfully identified\n", | ||
627 | KBUILD_MODNAME); | ||
628 | 530 | ||
629 | fe->tuner_priv = priv; | 531 | fe->tuner_priv = dev; |
630 | memcpy(&fe->ops.tuner_ops, &m88ts2022_tuner_ops, | 532 | memcpy(&fe->ops.tuner_ops, &m88ts2022_tuner_ops, |
631 | sizeof(struct dvb_tuner_ops)); | 533 | sizeof(struct dvb_tuner_ops)); |
632 | 534 | ||
633 | i2c_set_clientdata(client, priv); | 535 | i2c_set_clientdata(client, dev); |
634 | return 0; | 536 | return 0; |
635 | err: | 537 | err: |
636 | dev_dbg(&client->dev, "%s: failed=%d\n", __func__, ret); | 538 | dev_dbg(&client->dev, "failed=%d\n", ret); |
637 | kfree(priv); | 539 | kfree(dev); |
638 | return ret; | 540 | return ret; |
639 | } | 541 | } |
640 | 542 | ||
641 | static int m88ts2022_remove(struct i2c_client *client) | 543 | static int m88ts2022_remove(struct i2c_client *client) |
642 | { | 544 | { |
643 | struct m88ts2022_priv *priv = i2c_get_clientdata(client); | 545 | struct m88ts2022_dev *dev = i2c_get_clientdata(client); |
644 | struct dvb_frontend *fe = priv->cfg.fe; | 546 | struct dvb_frontend *fe = dev->cfg.fe; |
645 | dev_dbg(&client->dev, "%s:\n", __func__); | 547 | |
548 | dev_dbg(&client->dev, "\n"); | ||
646 | 549 | ||
647 | memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); | 550 | memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); |
648 | fe->tuner_priv = NULL; | 551 | fe->tuner_priv = NULL; |
649 | kfree(priv); | 552 | kfree(dev); |
650 | 553 | ||
651 | return 0; | 554 | return 0; |
652 | } | 555 | } |
diff --git a/drivers/media/tuners/m88ts2022_priv.h b/drivers/media/tuners/m88ts2022_priv.h index 0363dd866a2d..feeb5ad6beef 100644 --- a/drivers/media/tuners/m88ts2022_priv.h +++ b/drivers/media/tuners/m88ts2022_priv.h | |||
@@ -18,11 +18,12 @@ | |||
18 | #define M88TS2022_PRIV_H | 18 | #define M88TS2022_PRIV_H |
19 | 19 | ||
20 | #include "m88ts2022.h" | 20 | #include "m88ts2022.h" |
21 | #include <linux/regmap.h> | ||
21 | 22 | ||
22 | struct m88ts2022_priv { | 23 | struct m88ts2022_dev { |
23 | struct m88ts2022_config cfg; | 24 | struct m88ts2022_config cfg; |
24 | struct i2c_client *client; | 25 | struct i2c_client *client; |
25 | struct dvb_frontend *fe; | 26 | struct regmap *regmap; |
26 | u32 frequency_khz; | 27 | u32 frequency_khz; |
27 | }; | 28 | }; |
28 | 29 | ||
diff --git a/drivers/media/tuners/msi001.c b/drivers/media/tuners/msi001.c index ee99e372c943..26019e731993 100644 --- a/drivers/media/tuners/msi001.c +++ b/drivers/media/tuners/msi001.c | |||
@@ -67,7 +67,8 @@ static int msi001_set_gain(struct msi001 *s, int lna_gain, int mixer_gain, | |||
67 | { | 67 | { |
68 | int ret; | 68 | int ret; |
69 | u32 reg; | 69 | u32 reg; |
70 | dev_dbg(&s->spi->dev, "%s: lna=%d mixer=%d if=%d\n", __func__, | 70 | |
71 | dev_dbg(&s->spi->dev, "lna=%d mixer=%d if=%d\n", | ||
71 | lna_gain, mixer_gain, if_gain); | 72 | lna_gain, mixer_gain, if_gain); |
72 | 73 | ||
73 | reg = 1 << 0; | 74 | reg = 1 << 0; |
@@ -83,7 +84,7 @@ static int msi001_set_gain(struct msi001 *s, int lna_gain, int mixer_gain, | |||
83 | 84 | ||
84 | return 0; | 85 | return 0; |
85 | err: | 86 | err: |
86 | dev_dbg(&s->spi->dev, "%s: failed %d\n", __func__, ret); | 87 | dev_dbg(&s->spi->dev, "failed %d\n", ret); |
87 | return ret; | 88 | return ret; |
88 | }; | 89 | }; |
89 | 90 | ||
@@ -94,6 +95,7 @@ static int msi001_set_tuner(struct msi001 *s) | |||
94 | u32 reg; | 95 | u32 reg; |
95 | u64 f_vco, tmp64; | 96 | u64 f_vco, tmp64; |
96 | u8 mode, filter_mode, lo_div; | 97 | u8 mode, filter_mode, lo_div; |
98 | |||
97 | static const struct { | 99 | static const struct { |
98 | u32 rf; | 100 | u32 rf; |
99 | u8 mode; | 101 | u8 mode; |
@@ -145,9 +147,7 @@ static int msi001_set_tuner(struct msi001 *s) | |||
145 | #define R_REF 4 | 147 | #define R_REF 4 |
146 | #define F_OUT_STEP 1 | 148 | #define F_OUT_STEP 1 |
147 | 149 | ||
148 | dev_dbg(&s->spi->dev, | 150 | dev_dbg(&s->spi->dev, "f_rf=%d f_if=%d\n", f_rf, f_if); |
149 | "%s: f_rf=%d f_if=%d\n", | ||
150 | __func__, f_rf, f_if); | ||
151 | 151 | ||
152 | for (i = 0; i < ARRAY_SIZE(band_lut); i++) { | 152 | for (i = 0; i < ARRAY_SIZE(band_lut); i++) { |
153 | if (f_rf <= band_lut[i].rf) { | 153 | if (f_rf <= band_lut[i].rf) { |
@@ -198,8 +198,7 @@ static int msi001_set_tuner(struct msi001 *s) | |||
198 | 198 | ||
199 | s->bandwidth->val = bandwidth_lut[i].freq; | 199 | s->bandwidth->val = bandwidth_lut[i].freq; |
200 | 200 | ||
201 | dev_dbg(&s->spi->dev, "%s: bandwidth selected=%d\n", | 201 | dev_dbg(&s->spi->dev, "bandwidth selected=%d\n", bandwidth_lut[i].freq); |
202 | __func__, bandwidth_lut[i].freq); | ||
203 | 202 | ||
204 | f_vco = (u64) (f_rf + f_if + f_if1) * lo_div; | 203 | f_vco = (u64) (f_rf + f_if + f_if1) * lo_div; |
205 | tmp64 = f_vco; | 204 | tmp64 = f_vco; |
@@ -225,9 +224,8 @@ static int msi001_set_tuner(struct msi001 *s) | |||
225 | tmp += 1ul * F_REF * R_REF * frac / thresh; | 224 | tmp += 1ul * F_REF * R_REF * frac / thresh; |
226 | tmp /= lo_div; | 225 | tmp /= lo_div; |
227 | 226 | ||
228 | dev_dbg(&s->spi->dev, | 227 | dev_dbg(&s->spi->dev, "rf=%u:%u n=%d thresh=%d frac=%d\n", |
229 | "%s: rf=%u:%u n=%d thresh=%d frac=%d\n", | 228 | f_rf, tmp, n, thresh, frac); |
230 | __func__, f_rf, tmp, n, thresh, frac); | ||
231 | 229 | ||
232 | ret = msi001_wreg(s, 0x00000e); | 230 | ret = msi001_wreg(s, 0x00000e); |
233 | if (ret) | 231 | if (ret) |
@@ -276,7 +274,7 @@ static int msi001_set_tuner(struct msi001 *s) | |||
276 | 274 | ||
277 | return 0; | 275 | return 0; |
278 | err: | 276 | err: |
279 | dev_dbg(&s->spi->dev, "%s: failed %d\n", __func__, ret); | 277 | dev_dbg(&s->spi->dev, "failed %d\n", ret); |
280 | return ret; | 278 | return ret; |
281 | }; | 279 | }; |
282 | 280 | ||
@@ -284,7 +282,8 @@ static int msi001_s_power(struct v4l2_subdev *sd, int on) | |||
284 | { | 282 | { |
285 | struct msi001 *s = sd_to_msi001(sd); | 283 | struct msi001 *s = sd_to_msi001(sd); |
286 | int ret; | 284 | int ret; |
287 | dev_dbg(&s->spi->dev, "%s: on=%d\n", __func__, on); | 285 | |
286 | dev_dbg(&s->spi->dev, "on=%d\n", on); | ||
288 | 287 | ||
289 | if (on) | 288 | if (on) |
290 | ret = 0; | 289 | ret = 0; |
@@ -301,7 +300,8 @@ static const struct v4l2_subdev_core_ops msi001_core_ops = { | |||
301 | static int msi001_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v) | 300 | static int msi001_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v) |
302 | { | 301 | { |
303 | struct msi001 *s = sd_to_msi001(sd); | 302 | struct msi001 *s = sd_to_msi001(sd); |
304 | dev_dbg(&s->spi->dev, "%s: index=%d\n", __func__, v->index); | 303 | |
304 | dev_dbg(&s->spi->dev, "index=%d\n", v->index); | ||
305 | 305 | ||
306 | strlcpy(v->name, "Mirics MSi001", sizeof(v->name)); | 306 | strlcpy(v->name, "Mirics MSi001", sizeof(v->name)); |
307 | v->type = V4L2_TUNER_RF; | 307 | v->type = V4L2_TUNER_RF; |
@@ -315,14 +315,16 @@ static int msi001_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v) | |||
315 | static int msi001_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *v) | 315 | static int msi001_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *v) |
316 | { | 316 | { |
317 | struct msi001 *s = sd_to_msi001(sd); | 317 | struct msi001 *s = sd_to_msi001(sd); |
318 | dev_dbg(&s->spi->dev, "%s: index=%d\n", __func__, v->index); | 318 | |
319 | dev_dbg(&s->spi->dev, "index=%d\n", v->index); | ||
319 | return 0; | 320 | return 0; |
320 | } | 321 | } |
321 | 322 | ||
322 | static int msi001_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f) | 323 | static int msi001_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f) |
323 | { | 324 | { |
324 | struct msi001 *s = sd_to_msi001(sd); | 325 | struct msi001 *s = sd_to_msi001(sd); |
325 | dev_dbg(&s->spi->dev, "%s: tuner=%d\n", __func__, f->tuner); | 326 | |
327 | dev_dbg(&s->spi->dev, "tuner=%d\n", f->tuner); | ||
326 | f->frequency = s->f_tuner; | 328 | f->frequency = s->f_tuner; |
327 | return 0; | 329 | return 0; |
328 | } | 330 | } |
@@ -332,8 +334,9 @@ static int msi001_s_frequency(struct v4l2_subdev *sd, | |||
332 | { | 334 | { |
333 | struct msi001 *s = sd_to_msi001(sd); | 335 | struct msi001 *s = sd_to_msi001(sd); |
334 | unsigned int band; | 336 | unsigned int band; |
335 | dev_dbg(&s->spi->dev, "%s: tuner=%d type=%d frequency=%u\n", | 337 | |
336 | __func__, f->tuner, f->type, f->frequency); | 338 | dev_dbg(&s->spi->dev, "tuner=%d type=%d frequency=%u\n", |
339 | f->tuner, f->type, f->frequency); | ||
337 | 340 | ||
338 | if (f->frequency < ((bands[0].rangehigh + bands[1].rangelow) / 2)) | 341 | if (f->frequency < ((bands[0].rangehigh + bands[1].rangelow) / 2)) |
339 | band = 0; | 342 | band = 0; |
@@ -349,8 +352,9 @@ static int msi001_enum_freq_bands(struct v4l2_subdev *sd, | |||
349 | struct v4l2_frequency_band *band) | 352 | struct v4l2_frequency_band *band) |
350 | { | 353 | { |
351 | struct msi001 *s = sd_to_msi001(sd); | 354 | struct msi001 *s = sd_to_msi001(sd); |
352 | dev_dbg(&s->spi->dev, "%s: tuner=%d type=%d index=%d\n", | 355 | |
353 | __func__, band->tuner, band->type, band->index); | 356 | dev_dbg(&s->spi->dev, "tuner=%d type=%d index=%d\n", |
357 | band->tuner, band->type, band->index); | ||
354 | 358 | ||
355 | if (band->index >= ARRAY_SIZE(bands)) | 359 | if (band->index >= ARRAY_SIZE(bands)) |
356 | return -EINVAL; | 360 | return -EINVAL; |
@@ -380,9 +384,10 @@ static int msi001_s_ctrl(struct v4l2_ctrl *ctrl) | |||
380 | struct msi001 *s = container_of(ctrl->handler, struct msi001, hdl); | 384 | struct msi001 *s = container_of(ctrl->handler, struct msi001, hdl); |
381 | 385 | ||
382 | int ret; | 386 | int ret; |
387 | |||
383 | dev_dbg(&s->spi->dev, | 388 | dev_dbg(&s->spi->dev, |
384 | "%s: id=%d name=%s val=%d min=%lld max=%lld step=%lld\n", | 389 | "id=%d name=%s val=%d min=%lld max=%lld step=%lld\n", |
385 | __func__, ctrl->id, ctrl->name, ctrl->val, | 390 | ctrl->id, ctrl->name, ctrl->val, |
386 | ctrl->minimum, ctrl->maximum, ctrl->step); | 391 | ctrl->minimum, ctrl->maximum, ctrl->step); |
387 | 392 | ||
388 | switch (ctrl->id) { | 393 | switch (ctrl->id) { |
@@ -403,8 +408,7 @@ static int msi001_s_ctrl(struct v4l2_ctrl *ctrl) | |||
403 | s->mixer_gain->cur.val, s->if_gain->val); | 408 | s->mixer_gain->cur.val, s->if_gain->val); |
404 | break; | 409 | break; |
405 | default: | 410 | default: |
406 | dev_dbg(&s->spi->dev, "%s: unkown control %d\n", | 411 | dev_dbg(&s->spi->dev, "unkown control %d\n", ctrl->id); |
407 | __func__, ctrl->id); | ||
408 | ret = -EINVAL; | 412 | ret = -EINVAL; |
409 | } | 413 | } |
410 | 414 | ||
@@ -419,7 +423,8 @@ static int msi001_probe(struct spi_device *spi) | |||
419 | { | 423 | { |
420 | struct msi001 *s; | 424 | struct msi001 *s; |
421 | int ret; | 425 | int ret; |
422 | dev_dbg(&spi->dev, "%s:\n", __func__); | 426 | |
427 | dev_dbg(&spi->dev, "\n"); | ||
423 | 428 | ||
424 | s = kzalloc(sizeof(struct msi001), GFP_KERNEL); | 429 | s = kzalloc(sizeof(struct msi001), GFP_KERNEL); |
425 | if (s == NULL) { | 430 | if (s == NULL) { |
@@ -466,7 +471,8 @@ static int msi001_remove(struct spi_device *spi) | |||
466 | { | 471 | { |
467 | struct v4l2_subdev *sd = spi_get_drvdata(spi); | 472 | struct v4l2_subdev *sd = spi_get_drvdata(spi); |
468 | struct msi001 *s = sd_to_msi001(sd); | 473 | struct msi001 *s = sd_to_msi001(sd); |
469 | dev_dbg(&spi->dev, "%s:\n", __func__); | 474 | |
475 | dev_dbg(&spi->dev, "\n"); | ||
470 | 476 | ||
471 | /* | 477 | /* |
472 | * Registered by v4l2_spi_new_subdev() from master driver, but we must | 478 | * Registered by v4l2_spi_new_subdev() from master driver, but we must |
diff --git a/drivers/media/tuners/mt2060.c b/drivers/media/tuners/mt2060.c index 13381de58a84..b87b2549d58d 100644 --- a/drivers/media/tuners/mt2060.c +++ b/drivers/media/tuners/mt2060.c | |||
@@ -157,7 +157,6 @@ static int mt2060_set_params(struct dvb_frontend *fe) | |||
157 | { | 157 | { |
158 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; | 158 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
159 | struct mt2060_priv *priv; | 159 | struct mt2060_priv *priv; |
160 | int ret=0; | ||
161 | int i=0; | 160 | int i=0; |
162 | u32 freq; | 161 | u32 freq; |
163 | u8 lnaband; | 162 | u8 lnaband; |
@@ -240,7 +239,7 @@ static int mt2060_set_params(struct dvb_frontend *fe) | |||
240 | if (fe->ops.i2c_gate_ctrl) | 239 | if (fe->ops.i2c_gate_ctrl) |
241 | fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */ | 240 | fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */ |
242 | 241 | ||
243 | return ret; | 242 | return 0; |
244 | } | 243 | } |
245 | 244 | ||
246 | static void mt2060_calibrate(struct mt2060_priv *priv) | 245 | static void mt2060_calibrate(struct mt2060_priv *priv) |
diff --git a/drivers/media/tuners/mt2063.c b/drivers/media/tuners/mt2063.c index f640dcf4a81d..9e9c5eb4cb66 100644 --- a/drivers/media/tuners/mt2063.c +++ b/drivers/media/tuners/mt2063.c | |||
@@ -1216,7 +1216,7 @@ static u32 MT2063_SetReceiverMode(struct mt2063_state *state, | |||
1216 | if (status >= 0) { | 1216 | if (status >= 0) { |
1217 | val = | 1217 | val = |
1218 | (state-> | 1218 | (state-> |
1219 | reg[MT2063_REG_PD1_TGT] & (u8) ~0x40) | (RFAGCEN[Mode] | 1219 | reg[MT2063_REG_PD1_TGT] & ~0x40) | (RFAGCEN[Mode] |
1220 | ? 0x40 : | 1220 | ? 0x40 : |
1221 | 0x00); | 1221 | 0x00); |
1222 | if (state->reg[MT2063_REG_PD1_TGT] != val) | 1222 | if (state->reg[MT2063_REG_PD1_TGT] != val) |
@@ -1225,7 +1225,7 @@ static u32 MT2063_SetReceiverMode(struct mt2063_state *state, | |||
1225 | 1225 | ||
1226 | /* LNARin */ | 1226 | /* LNARin */ |
1227 | if (status >= 0) { | 1227 | if (status >= 0) { |
1228 | u8 val = (state->reg[MT2063_REG_CTRL_2C] & (u8) ~0x03) | | 1228 | u8 val = (state->reg[MT2063_REG_CTRL_2C] & ~0x03) | |
1229 | (LNARIN[Mode] & 0x03); | 1229 | (LNARIN[Mode] & 0x03); |
1230 | if (state->reg[MT2063_REG_CTRL_2C] != val) | 1230 | if (state->reg[MT2063_REG_CTRL_2C] != val) |
1231 | status |= mt2063_setreg(state, MT2063_REG_CTRL_2C, val); | 1231 | status |= mt2063_setreg(state, MT2063_REG_CTRL_2C, val); |
@@ -1235,19 +1235,19 @@ static u32 MT2063_SetReceiverMode(struct mt2063_state *state, | |||
1235 | if (status >= 0) { | 1235 | if (status >= 0) { |
1236 | val = | 1236 | val = |
1237 | (state-> | 1237 | (state-> |
1238 | reg[MT2063_REG_FIFF_CTRL2] & (u8) ~0xF0) | | 1238 | reg[MT2063_REG_FIFF_CTRL2] & ~0xF0) | |
1239 | (FIFFQEN[Mode] << 7) | (FIFFQ[Mode] << 4); | 1239 | (FIFFQEN[Mode] << 7) | (FIFFQ[Mode] << 4); |
1240 | if (state->reg[MT2063_REG_FIFF_CTRL2] != val) { | 1240 | if (state->reg[MT2063_REG_FIFF_CTRL2] != val) { |
1241 | status |= | 1241 | status |= |
1242 | mt2063_setreg(state, MT2063_REG_FIFF_CTRL2, val); | 1242 | mt2063_setreg(state, MT2063_REG_FIFF_CTRL2, val); |
1243 | /* trigger FIFF calibration, needed after changing FIFFQ */ | 1243 | /* trigger FIFF calibration, needed after changing FIFFQ */ |
1244 | val = | 1244 | val = |
1245 | (state->reg[MT2063_REG_FIFF_CTRL] | (u8) 0x01); | 1245 | (state->reg[MT2063_REG_FIFF_CTRL] | 0x01); |
1246 | status |= | 1246 | status |= |
1247 | mt2063_setreg(state, MT2063_REG_FIFF_CTRL, val); | 1247 | mt2063_setreg(state, MT2063_REG_FIFF_CTRL, val); |
1248 | val = | 1248 | val = |
1249 | (state-> | 1249 | (state-> |
1250 | reg[MT2063_REG_FIFF_CTRL] & (u8) ~0x01); | 1250 | reg[MT2063_REG_FIFF_CTRL] & ~0x01); |
1251 | status |= | 1251 | status |= |
1252 | mt2063_setreg(state, MT2063_REG_FIFF_CTRL, val); | 1252 | mt2063_setreg(state, MT2063_REG_FIFF_CTRL, val); |
1253 | } | 1253 | } |
@@ -1259,7 +1259,7 @@ static u32 MT2063_SetReceiverMode(struct mt2063_state *state, | |||
1259 | 1259 | ||
1260 | /* acLNAmax */ | 1260 | /* acLNAmax */ |
1261 | if (status >= 0) { | 1261 | if (status >= 0) { |
1262 | u8 val = (state->reg[MT2063_REG_LNA_OV] & (u8) ~0x1F) | | 1262 | u8 val = (state->reg[MT2063_REG_LNA_OV] & ~0x1F) | |
1263 | (ACLNAMAX[Mode] & 0x1F); | 1263 | (ACLNAMAX[Mode] & 0x1F); |
1264 | if (state->reg[MT2063_REG_LNA_OV] != val) | 1264 | if (state->reg[MT2063_REG_LNA_OV] != val) |
1265 | status |= mt2063_setreg(state, MT2063_REG_LNA_OV, val); | 1265 | status |= mt2063_setreg(state, MT2063_REG_LNA_OV, val); |
@@ -1267,7 +1267,7 @@ static u32 MT2063_SetReceiverMode(struct mt2063_state *state, | |||
1267 | 1267 | ||
1268 | /* LNATGT */ | 1268 | /* LNATGT */ |
1269 | if (status >= 0) { | 1269 | if (status >= 0) { |
1270 | u8 val = (state->reg[MT2063_REG_LNA_TGT] & (u8) ~0x3F) | | 1270 | u8 val = (state->reg[MT2063_REG_LNA_TGT] & ~0x3F) | |
1271 | (LNATGT[Mode] & 0x3F); | 1271 | (LNATGT[Mode] & 0x3F); |
1272 | if (state->reg[MT2063_REG_LNA_TGT] != val) | 1272 | if (state->reg[MT2063_REG_LNA_TGT] != val) |
1273 | status |= mt2063_setreg(state, MT2063_REG_LNA_TGT, val); | 1273 | status |= mt2063_setreg(state, MT2063_REG_LNA_TGT, val); |
@@ -1275,7 +1275,7 @@ static u32 MT2063_SetReceiverMode(struct mt2063_state *state, | |||
1275 | 1275 | ||
1276 | /* ACRF */ | 1276 | /* ACRF */ |
1277 | if (status >= 0) { | 1277 | if (status >= 0) { |
1278 | u8 val = (state->reg[MT2063_REG_RF_OV] & (u8) ~0x1F) | | 1278 | u8 val = (state->reg[MT2063_REG_RF_OV] & ~0x1F) | |
1279 | (ACRFMAX[Mode] & 0x1F); | 1279 | (ACRFMAX[Mode] & 0x1F); |
1280 | if (state->reg[MT2063_REG_RF_OV] != val) | 1280 | if (state->reg[MT2063_REG_RF_OV] != val) |
1281 | status |= mt2063_setreg(state, MT2063_REG_RF_OV, val); | 1281 | status |= mt2063_setreg(state, MT2063_REG_RF_OV, val); |
@@ -1283,7 +1283,7 @@ static u32 MT2063_SetReceiverMode(struct mt2063_state *state, | |||
1283 | 1283 | ||
1284 | /* PD1TGT */ | 1284 | /* PD1TGT */ |
1285 | if (status >= 0) { | 1285 | if (status >= 0) { |
1286 | u8 val = (state->reg[MT2063_REG_PD1_TGT] & (u8) ~0x3F) | | 1286 | u8 val = (state->reg[MT2063_REG_PD1_TGT] & ~0x3F) | |
1287 | (PD1TGT[Mode] & 0x3F); | 1287 | (PD1TGT[Mode] & 0x3F); |
1288 | if (state->reg[MT2063_REG_PD1_TGT] != val) | 1288 | if (state->reg[MT2063_REG_PD1_TGT] != val) |
1289 | status |= mt2063_setreg(state, MT2063_REG_PD1_TGT, val); | 1289 | status |= mt2063_setreg(state, MT2063_REG_PD1_TGT, val); |
@@ -1294,7 +1294,7 @@ static u32 MT2063_SetReceiverMode(struct mt2063_state *state, | |||
1294 | u8 val = ACFIFMAX[Mode]; | 1294 | u8 val = ACFIFMAX[Mode]; |
1295 | if (state->reg[MT2063_REG_PART_REV] != MT2063_B3 && val > 5) | 1295 | if (state->reg[MT2063_REG_PART_REV] != MT2063_B3 && val > 5) |
1296 | val = 5; | 1296 | val = 5; |
1297 | val = (state->reg[MT2063_REG_FIF_OV] & (u8) ~0x1F) | | 1297 | val = (state->reg[MT2063_REG_FIF_OV] & ~0x1F) | |
1298 | (val & 0x1F); | 1298 | (val & 0x1F); |
1299 | if (state->reg[MT2063_REG_FIF_OV] != val) | 1299 | if (state->reg[MT2063_REG_FIF_OV] != val) |
1300 | status |= mt2063_setreg(state, MT2063_REG_FIF_OV, val); | 1300 | status |= mt2063_setreg(state, MT2063_REG_FIF_OV, val); |
@@ -1302,7 +1302,7 @@ static u32 MT2063_SetReceiverMode(struct mt2063_state *state, | |||
1302 | 1302 | ||
1303 | /* PD2TGT */ | 1303 | /* PD2TGT */ |
1304 | if (status >= 0) { | 1304 | if (status >= 0) { |
1305 | u8 val = (state->reg[MT2063_REG_PD2_TGT] & (u8) ~0x3F) | | 1305 | u8 val = (state->reg[MT2063_REG_PD2_TGT] & ~0x3F) | |
1306 | (PD2TGT[Mode] & 0x3F); | 1306 | (PD2TGT[Mode] & 0x3F); |
1307 | if (state->reg[MT2063_REG_PD2_TGT] != val) | 1307 | if (state->reg[MT2063_REG_PD2_TGT] != val) |
1308 | status |= mt2063_setreg(state, MT2063_REG_PD2_TGT, val); | 1308 | status |= mt2063_setreg(state, MT2063_REG_PD2_TGT, val); |
@@ -1310,7 +1310,7 @@ static u32 MT2063_SetReceiverMode(struct mt2063_state *state, | |||
1310 | 1310 | ||
1311 | /* Ignore ATN Overload */ | 1311 | /* Ignore ATN Overload */ |
1312 | if (status >= 0) { | 1312 | if (status >= 0) { |
1313 | val = (state->reg[MT2063_REG_LNA_TGT] & (u8) ~0x80) | | 1313 | val = (state->reg[MT2063_REG_LNA_TGT] & ~0x80) | |
1314 | (RFOVDIS[Mode] ? 0x80 : 0x00); | 1314 | (RFOVDIS[Mode] ? 0x80 : 0x00); |
1315 | if (state->reg[MT2063_REG_LNA_TGT] != val) | 1315 | if (state->reg[MT2063_REG_LNA_TGT] != val) |
1316 | status |= mt2063_setreg(state, MT2063_REG_LNA_TGT, val); | 1316 | status |= mt2063_setreg(state, MT2063_REG_LNA_TGT, val); |
@@ -1318,7 +1318,7 @@ static u32 MT2063_SetReceiverMode(struct mt2063_state *state, | |||
1318 | 1318 | ||
1319 | /* Ignore FIF Overload */ | 1319 | /* Ignore FIF Overload */ |
1320 | if (status >= 0) { | 1320 | if (status >= 0) { |
1321 | val = (state->reg[MT2063_REG_PD1_TGT] & (u8) ~0x80) | | 1321 | val = (state->reg[MT2063_REG_PD1_TGT] & ~0x80) | |
1322 | (FIFOVDIS[Mode] ? 0x80 : 0x00); | 1322 | (FIFOVDIS[Mode] ? 0x80 : 0x00); |
1323 | if (state->reg[MT2063_REG_PD1_TGT] != val) | 1323 | if (state->reg[MT2063_REG_PD1_TGT] != val) |
1324 | status |= mt2063_setreg(state, MT2063_REG_PD1_TGT, val); | 1324 | status |= mt2063_setreg(state, MT2063_REG_PD1_TGT, val); |
diff --git a/drivers/media/tuners/mxl301rf.c b/drivers/media/tuners/mxl301rf.c new file mode 100644 index 000000000000..1575a5db776a --- /dev/null +++ b/drivers/media/tuners/mxl301rf.c | |||
@@ -0,0 +1,349 @@ | |||
1 | /* | ||
2 | * MaxLinear MxL301RF OFDM tuner driver | ||
3 | * | ||
4 | * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License as | ||
8 | * published by the Free Software Foundation version 2. | ||
9 | * | ||
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 | |||
17 | /* | ||
18 | * NOTICE: | ||
19 | * This driver is incomplete and lacks init/config of the chips, | ||
20 | * as the necessary info is not disclosed. | ||
21 | * Other features like get_if_frequency() are missing as well. | ||
22 | * It assumes that users of this driver (such as a PCI bridge of | ||
23 | * DTV receiver cards) properly init and configure the chip | ||
24 | * via I2C *before* calling this driver's init() function. | ||
25 | * | ||
26 | * Currently, PT3 driver is the only one that uses this driver, | ||
27 | * and contains init/config code in its firmware. | ||
28 | * Thus some part of the code might be dependent on PT3 specific config. | ||
29 | */ | ||
30 | |||
31 | #include <linux/kernel.h> | ||
32 | #include "mxl301rf.h" | ||
33 | |||
34 | struct mxl301rf_state { | ||
35 | struct mxl301rf_config cfg; | ||
36 | struct i2c_client *i2c; | ||
37 | }; | ||
38 | |||
39 | static struct mxl301rf_state *cfg_to_state(struct mxl301rf_config *c) | ||
40 | { | ||
41 | return container_of(c, struct mxl301rf_state, cfg); | ||
42 | } | ||
43 | |||
44 | static int raw_write(struct mxl301rf_state *state, const u8 *buf, int len) | ||
45 | { | ||
46 | int ret; | ||
47 | |||
48 | ret = i2c_master_send(state->i2c, buf, len); | ||
49 | if (ret >= 0 && ret < len) | ||
50 | ret = -EIO; | ||
51 | return (ret == len) ? 0 : ret; | ||
52 | } | ||
53 | |||
54 | static int reg_write(struct mxl301rf_state *state, u8 reg, u8 val) | ||
55 | { | ||
56 | u8 buf[2] = { reg, val }; | ||
57 | |||
58 | return raw_write(state, buf, 2); | ||
59 | } | ||
60 | |||
61 | static int reg_read(struct mxl301rf_state *state, u8 reg, u8 *val) | ||
62 | { | ||
63 | u8 wbuf[2] = { 0xfb, reg }; | ||
64 | int ret; | ||
65 | |||
66 | ret = raw_write(state, wbuf, sizeof(wbuf)); | ||
67 | if (ret == 0) | ||
68 | ret = i2c_master_recv(state->i2c, val, 1); | ||
69 | if (ret >= 0 && ret < 1) | ||
70 | ret = -EIO; | ||
71 | return (ret == 1) ? 0 : ret; | ||
72 | } | ||
73 | |||
74 | /* tuner_ops */ | ||
75 | |||
76 | /* get RSSI and update propery cache, set to *out in % */ | ||
77 | static int mxl301rf_get_rf_strength(struct dvb_frontend *fe, u16 *out) | ||
78 | { | ||
79 | struct mxl301rf_state *state; | ||
80 | int ret; | ||
81 | u8 rf_in1, rf_in2, rf_off1, rf_off2; | ||
82 | u16 rf_in, rf_off; | ||
83 | s64 level; | ||
84 | struct dtv_fe_stats *rssi; | ||
85 | |||
86 | rssi = &fe->dtv_property_cache.strength; | ||
87 | rssi->len = 1; | ||
88 | rssi->stat[0].scale = FE_SCALE_NOT_AVAILABLE; | ||
89 | *out = 0; | ||
90 | |||
91 | state = fe->tuner_priv; | ||
92 | ret = reg_write(state, 0x14, 0x01); | ||
93 | if (ret < 0) | ||
94 | return ret; | ||
95 | usleep_range(1000, 2000); | ||
96 | |||
97 | ret = reg_read(state, 0x18, &rf_in1); | ||
98 | if (ret == 0) | ||
99 | ret = reg_read(state, 0x19, &rf_in2); | ||
100 | if (ret == 0) | ||
101 | ret = reg_read(state, 0xd6, &rf_off1); | ||
102 | if (ret == 0) | ||
103 | ret = reg_read(state, 0xd7, &rf_off2); | ||
104 | if (ret != 0) | ||
105 | return ret; | ||
106 | |||
107 | rf_in = (rf_in2 & 0x07) << 8 | rf_in1; | ||
108 | rf_off = (rf_off2 & 0x0f) << 5 | (rf_off1 >> 3); | ||
109 | level = rf_in - rf_off - (113 << 3); /* x8 dBm */ | ||
110 | level = level * 1000 / 8; | ||
111 | rssi->stat[0].svalue = level; | ||
112 | rssi->stat[0].scale = FE_SCALE_DECIBEL; | ||
113 | /* *out = (level - min) * 100 / (max - min) */ | ||
114 | *out = (rf_in - rf_off + (1 << 9) - 1) * 100 / ((5 << 9) - 2); | ||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | /* spur shift parameters */ | ||
119 | struct shf { | ||
120 | u32 freq; /* Channel center frequency */ | ||
121 | u32 ofst_th; /* Offset frequency threshold */ | ||
122 | u8 shf_val; /* Spur shift value */ | ||
123 | u8 shf_dir; /* Spur shift direction */ | ||
124 | }; | ||
125 | |||
126 | static const struct shf shf_tab[] = { | ||
127 | { 64500, 500, 0x92, 0x07 }, | ||
128 | { 191500, 300, 0xe2, 0x07 }, | ||
129 | { 205500, 500, 0x2c, 0x04 }, | ||
130 | { 212500, 500, 0x1e, 0x04 }, | ||
131 | { 226500, 500, 0xd4, 0x07 }, | ||
132 | { 99143, 500, 0x9c, 0x07 }, | ||
133 | { 173143, 500, 0xd4, 0x07 }, | ||
134 | { 191143, 300, 0xd4, 0x07 }, | ||
135 | { 207143, 500, 0xce, 0x07 }, | ||
136 | { 225143, 500, 0xce, 0x07 }, | ||
137 | { 243143, 500, 0xd4, 0x07 }, | ||
138 | { 261143, 500, 0xd4, 0x07 }, | ||
139 | { 291143, 500, 0xd4, 0x07 }, | ||
140 | { 339143, 500, 0x2c, 0x04 }, | ||
141 | { 117143, 500, 0x7a, 0x07 }, | ||
142 | { 135143, 300, 0x7a, 0x07 }, | ||
143 | { 153143, 500, 0x01, 0x07 } | ||
144 | }; | ||
145 | |||
146 | struct reg_val { | ||
147 | u8 reg; | ||
148 | u8 val; | ||
149 | } __attribute__ ((__packed__)); | ||
150 | |||
151 | static const struct reg_val set_idac[] = { | ||
152 | { 0x0d, 0x00 }, | ||
153 | { 0x0c, 0x67 }, | ||
154 | { 0x6f, 0x89 }, | ||
155 | { 0x70, 0x0c }, | ||
156 | { 0x6f, 0x8a }, | ||
157 | { 0x70, 0x0e }, | ||
158 | { 0x6f, 0x8b }, | ||
159 | { 0x70, 0x1c }, | ||
160 | }; | ||
161 | |||
162 | static int mxl301rf_set_params(struct dvb_frontend *fe) | ||
163 | { | ||
164 | struct reg_val tune0[] = { | ||
165 | { 0x13, 0x00 }, /* abort tuning */ | ||
166 | { 0x3b, 0xc0 }, | ||
167 | { 0x3b, 0x80 }, | ||
168 | { 0x10, 0x95 }, /* BW */ | ||
169 | { 0x1a, 0x05 }, | ||
170 | { 0x61, 0x00 }, /* spur shift value (placeholder) */ | ||
171 | { 0x62, 0xa0 } /* spur shift direction (placeholder) */ | ||
172 | }; | ||
173 | |||
174 | struct reg_val tune1[] = { | ||
175 | { 0x11, 0x40 }, /* RF frequency L (placeholder) */ | ||
176 | { 0x12, 0x0e }, /* RF frequency H (placeholder) */ | ||
177 | { 0x13, 0x01 } /* start tune */ | ||
178 | }; | ||
179 | |||
180 | struct mxl301rf_state *state; | ||
181 | u32 freq; | ||
182 | u16 f; | ||
183 | u32 tmp, div; | ||
184 | int i, ret; | ||
185 | |||
186 | state = fe->tuner_priv; | ||
187 | freq = fe->dtv_property_cache.frequency; | ||
188 | |||
189 | /* spur shift function (for analog) */ | ||
190 | for (i = 0; i < ARRAY_SIZE(shf_tab); i++) { | ||
191 | if (freq >= (shf_tab[i].freq - shf_tab[i].ofst_th) * 1000 && | ||
192 | freq <= (shf_tab[i].freq + shf_tab[i].ofst_th) * 1000) { | ||
193 | tune0[5].val = shf_tab[i].shf_val; | ||
194 | tune0[6].val = 0xa0 | shf_tab[i].shf_dir; | ||
195 | break; | ||
196 | } | ||
197 | } | ||
198 | ret = raw_write(state, (u8 *) tune0, sizeof(tune0)); | ||
199 | if (ret < 0) | ||
200 | goto failed; | ||
201 | usleep_range(3000, 4000); | ||
202 | |||
203 | /* convert freq to 10.6 fixed point float [MHz] */ | ||
204 | f = freq / 1000000; | ||
205 | tmp = freq % 1000000; | ||
206 | div = 1000000; | ||
207 | for (i = 0; i < 6; i++) { | ||
208 | f <<= 1; | ||
209 | div >>= 1; | ||
210 | if (tmp > div) { | ||
211 | tmp -= div; | ||
212 | f |= 1; | ||
213 | } | ||
214 | } | ||
215 | if (tmp > 7812) | ||
216 | f++; | ||
217 | tune1[0].val = f & 0xff; | ||
218 | tune1[1].val = f >> 8; | ||
219 | ret = raw_write(state, (u8 *) tune1, sizeof(tune1)); | ||
220 | if (ret < 0) | ||
221 | goto failed; | ||
222 | msleep(31); | ||
223 | |||
224 | ret = reg_write(state, 0x1a, 0x0d); | ||
225 | if (ret < 0) | ||
226 | goto failed; | ||
227 | ret = raw_write(state, (u8 *) set_idac, sizeof(set_idac)); | ||
228 | if (ret < 0) | ||
229 | goto failed; | ||
230 | return 0; | ||
231 | |||
232 | failed: | ||
233 | dev_warn(&state->i2c->dev, "(%s) failed. [adap%d-fe%d]\n", | ||
234 | __func__, fe->dvb->num, fe->id); | ||
235 | return ret; | ||
236 | } | ||
237 | |||
238 | static const struct reg_val standby_data[] = { | ||
239 | { 0x01, 0x00 }, | ||
240 | { 0x13, 0x00 } | ||
241 | }; | ||
242 | |||
243 | static int mxl301rf_sleep(struct dvb_frontend *fe) | ||
244 | { | ||
245 | struct mxl301rf_state *state; | ||
246 | int ret; | ||
247 | |||
248 | state = fe->tuner_priv; | ||
249 | ret = raw_write(state, (u8 *)standby_data, sizeof(standby_data)); | ||
250 | if (ret < 0) | ||
251 | dev_warn(&state->i2c->dev, "(%s) failed. [adap%d-fe%d]\n", | ||
252 | __func__, fe->dvb->num, fe->id); | ||
253 | return ret; | ||
254 | } | ||
255 | |||
256 | |||
257 | /* init sequence is not public. | ||
258 | * the parent must have init'ed the device. | ||
259 | * just wake up here. | ||
260 | */ | ||
261 | static int mxl301rf_init(struct dvb_frontend *fe) | ||
262 | { | ||
263 | struct mxl301rf_state *state; | ||
264 | int ret; | ||
265 | |||
266 | state = fe->tuner_priv; | ||
267 | |||
268 | ret = reg_write(state, 0x01, 0x01); | ||
269 | if (ret < 0) { | ||
270 | dev_warn(&state->i2c->dev, "(%s) failed. [adap%d-fe%d]\n", | ||
271 | __func__, fe->dvb->num, fe->id); | ||
272 | return ret; | ||
273 | } | ||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | /* I2C driver functions */ | ||
278 | |||
279 | static const struct dvb_tuner_ops mxl301rf_ops = { | ||
280 | .info = { | ||
281 | .name = "MaxLinear MxL301RF", | ||
282 | |||
283 | .frequency_min = 93000000, | ||
284 | .frequency_max = 803142857, | ||
285 | }, | ||
286 | |||
287 | .init = mxl301rf_init, | ||
288 | .sleep = mxl301rf_sleep, | ||
289 | |||
290 | .set_params = mxl301rf_set_params, | ||
291 | .get_rf_strength = mxl301rf_get_rf_strength, | ||
292 | }; | ||
293 | |||
294 | |||
295 | static int mxl301rf_probe(struct i2c_client *client, | ||
296 | const struct i2c_device_id *id) | ||
297 | { | ||
298 | struct mxl301rf_state *state; | ||
299 | struct mxl301rf_config *cfg; | ||
300 | struct dvb_frontend *fe; | ||
301 | |||
302 | state = kzalloc(sizeof(*state), GFP_KERNEL); | ||
303 | if (!state) | ||
304 | return -ENOMEM; | ||
305 | |||
306 | state->i2c = client; | ||
307 | cfg = client->dev.platform_data; | ||
308 | |||
309 | memcpy(&state->cfg, cfg, sizeof(state->cfg)); | ||
310 | fe = cfg->fe; | ||
311 | fe->tuner_priv = state; | ||
312 | memcpy(&fe->ops.tuner_ops, &mxl301rf_ops, sizeof(mxl301rf_ops)); | ||
313 | |||
314 | i2c_set_clientdata(client, &state->cfg); | ||
315 | dev_info(&client->dev, "MaxLinear MxL301RF attached.\n"); | ||
316 | return 0; | ||
317 | } | ||
318 | |||
319 | static int mxl301rf_remove(struct i2c_client *client) | ||
320 | { | ||
321 | struct mxl301rf_state *state; | ||
322 | |||
323 | state = cfg_to_state(i2c_get_clientdata(client)); | ||
324 | state->cfg.fe->tuner_priv = NULL; | ||
325 | kfree(state); | ||
326 | return 0; | ||
327 | } | ||
328 | |||
329 | |||
330 | static const struct i2c_device_id mxl301rf_id[] = { | ||
331 | {"mxl301rf", 0}, | ||
332 | {} | ||
333 | }; | ||
334 | MODULE_DEVICE_TABLE(i2c, mxl301rf_id); | ||
335 | |||
336 | static struct i2c_driver mxl301rf_driver = { | ||
337 | .driver = { | ||
338 | .name = "mxl301rf", | ||
339 | }, | ||
340 | .probe = mxl301rf_probe, | ||
341 | .remove = mxl301rf_remove, | ||
342 | .id_table = mxl301rf_id, | ||
343 | }; | ||
344 | |||
345 | module_i2c_driver(mxl301rf_driver); | ||
346 | |||
347 | MODULE_DESCRIPTION("MaxLinear MXL301RF tuner"); | ||
348 | MODULE_AUTHOR("Akihiro TSUKADA"); | ||
349 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/tuners/mxl301rf.h b/drivers/media/tuners/mxl301rf.h new file mode 100644 index 000000000000..19e68405f00d --- /dev/null +++ b/drivers/media/tuners/mxl301rf.h | |||
@@ -0,0 +1,26 @@ | |||
1 | /* | ||
2 | * MaxLinear MxL301RF OFDM tuner driver | ||
3 | * | ||
4 | * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License as | ||
8 | * published by the Free Software Foundation version 2. | ||
9 | * | ||
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 | |||
17 | #ifndef MXL301RF_H | ||
18 | #define MXL301RF_H | ||
19 | |||
20 | #include "dvb_frontend.h" | ||
21 | |||
22 | struct mxl301rf_config { | ||
23 | struct dvb_frontend *fe; | ||
24 | }; | ||
25 | |||
26 | #endif /* MXL301RF_H */ | ||
diff --git a/drivers/media/tuners/mxl5005s.c b/drivers/media/tuners/mxl5005s.c index b473b76cb278..92a3be4fde87 100644 --- a/drivers/media/tuners/mxl5005s.c +++ b/drivers/media/tuners/mxl5005s.c | |||
@@ -1692,7 +1692,6 @@ static u16 MXL5005_TunerConfig(struct dvb_frontend *fe, | |||
1692 | ) | 1692 | ) |
1693 | { | 1693 | { |
1694 | struct mxl5005s_state *state = fe->tuner_priv; | 1694 | struct mxl5005s_state *state = fe->tuner_priv; |
1695 | u16 status = 0; | ||
1696 | 1695 | ||
1697 | state->Mode = Mode; | 1696 | state->Mode = Mode; |
1698 | state->IF_Mode = IF_mode; | 1697 | state->IF_Mode = IF_mode; |
@@ -1715,7 +1714,7 @@ static u16 MXL5005_TunerConfig(struct dvb_frontend *fe, | |||
1715 | /* Synthesizer LO frequency calculation */ | 1714 | /* Synthesizer LO frequency calculation */ |
1716 | MXL_SynthIFLO_Calc(fe); | 1715 | MXL_SynthIFLO_Calc(fe); |
1717 | 1716 | ||
1718 | return status; | 1717 | return 0; |
1719 | } | 1718 | } |
1720 | 1719 | ||
1721 | static void MXL_SynthIFLO_Calc(struct dvb_frontend *fe) | 1720 | static void MXL_SynthIFLO_Calc(struct dvb_frontend *fe) |
diff --git a/drivers/media/tuners/qm1d1c0042.c b/drivers/media/tuners/qm1d1c0042.c new file mode 100644 index 000000000000..18bc745ed108 --- /dev/null +++ b/drivers/media/tuners/qm1d1c0042.c | |||
@@ -0,0 +1,448 @@ | |||
1 | /* | ||
2 | * Sharp QM1D1C0042 8PSK tuner driver | ||
3 | * | ||
4 | * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License as | ||
8 | * published by the Free Software Foundation version 2. | ||
9 | * | ||
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 | |||
17 | /* | ||
18 | * NOTICE: | ||
19 | * As the disclosed information on the chip is very limited, | ||
20 | * this driver lacks some features, including chip config like IF freq. | ||
21 | * It assumes that users of this driver (such as a PCI bridge of | ||
22 | * DTV receiver cards) know the relevant info and | ||
23 | * configure the chip via I2C if necessary. | ||
24 | * | ||
25 | * Currently, PT3 driver is the only one that uses this driver, | ||
26 | * and contains init/config code in its firmware. | ||
27 | * Thus some part of the code might be dependent on PT3 specific config. | ||
28 | */ | ||
29 | |||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/math64.h> | ||
32 | #include "qm1d1c0042.h" | ||
33 | |||
34 | #define QM1D1C0042_NUM_REGS 0x20 | ||
35 | |||
36 | static const u8 reg_initval[QM1D1C0042_NUM_REGS] = { | ||
37 | 0x48, 0x1c, 0xa0, 0x10, 0xbc, 0xc5, 0x20, 0x33, | ||
38 | 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, | ||
39 | 0x00, 0xff, 0xf3, 0x00, 0x2a, 0x64, 0xa6, 0x86, | ||
40 | 0x8c, 0xcf, 0xb8, 0xf1, 0xa8, 0xf2, 0x89, 0x00 | ||
41 | }; | ||
42 | |||
43 | static const struct qm1d1c0042_config default_cfg = { | ||
44 | .xtal_freq = 16000, | ||
45 | .lpf = 1, | ||
46 | .fast_srch = 0, | ||
47 | .lpf_wait = 20, | ||
48 | .fast_srch_wait = 4, | ||
49 | .normal_srch_wait = 15, | ||
50 | }; | ||
51 | |||
52 | struct qm1d1c0042_state { | ||
53 | struct qm1d1c0042_config cfg; | ||
54 | struct i2c_client *i2c; | ||
55 | u8 regs[QM1D1C0042_NUM_REGS]; | ||
56 | }; | ||
57 | |||
58 | static struct qm1d1c0042_state *cfg_to_state(struct qm1d1c0042_config *c) | ||
59 | { | ||
60 | return container_of(c, struct qm1d1c0042_state, cfg); | ||
61 | } | ||
62 | |||
63 | static int reg_write(struct qm1d1c0042_state *state, u8 reg, u8 val) | ||
64 | { | ||
65 | u8 wbuf[2] = { reg, val }; | ||
66 | int ret; | ||
67 | |||
68 | ret = i2c_master_send(state->i2c, wbuf, sizeof(wbuf)); | ||
69 | if (ret >= 0 && ret < sizeof(wbuf)) | ||
70 | ret = -EIO; | ||
71 | return (ret == sizeof(wbuf)) ? 0 : ret; | ||
72 | } | ||
73 | |||
74 | static int reg_read(struct qm1d1c0042_state *state, u8 reg, u8 *val) | ||
75 | { | ||
76 | struct i2c_msg msgs[2] = { | ||
77 | { | ||
78 | .addr = state->i2c->addr, | ||
79 | .flags = 0, | ||
80 | .buf = ®, | ||
81 | .len = 1, | ||
82 | }, | ||
83 | { | ||
84 | .addr = state->i2c->addr, | ||
85 | .flags = I2C_M_RD, | ||
86 | .buf = val, | ||
87 | .len = 1, | ||
88 | }, | ||
89 | }; | ||
90 | int ret; | ||
91 | |||
92 | ret = i2c_transfer(state->i2c->adapter, msgs, ARRAY_SIZE(msgs)); | ||
93 | if (ret >= 0 && ret < ARRAY_SIZE(msgs)) | ||
94 | ret = -EIO; | ||
95 | return (ret == ARRAY_SIZE(msgs)) ? 0 : ret; | ||
96 | } | ||
97 | |||
98 | |||
99 | static int qm1d1c0042_set_srch_mode(struct qm1d1c0042_state *state, bool fast) | ||
100 | { | ||
101 | if (fast) | ||
102 | state->regs[0x03] |= 0x01; /* set fast search mode */ | ||
103 | else | ||
104 | state->regs[0x03] &= ~0x01 & 0xff; | ||
105 | |||
106 | return reg_write(state, 0x03, state->regs[0x03]); | ||
107 | } | ||
108 | |||
109 | static int qm1d1c0042_wakeup(struct qm1d1c0042_state *state) | ||
110 | { | ||
111 | int ret; | ||
112 | |||
113 | state->regs[0x01] |= 1 << 3; /* BB_Reg_enable */ | ||
114 | state->regs[0x01] &= (~(1 << 0)) & 0xff; /* NORMAL (wake-up) */ | ||
115 | state->regs[0x05] &= (~(1 << 3)) & 0xff; /* pfd_rst NORMAL */ | ||
116 | ret = reg_write(state, 0x01, state->regs[0x01]); | ||
117 | if (ret == 0) | ||
118 | ret = reg_write(state, 0x05, state->regs[0x05]); | ||
119 | |||
120 | if (ret < 0) | ||
121 | dev_warn(&state->i2c->dev, "(%s) failed. [adap%d-fe%d]\n", | ||
122 | __func__, state->cfg.fe->dvb->num, state->cfg.fe->id); | ||
123 | return ret; | ||
124 | } | ||
125 | |||
126 | /* tuner_ops */ | ||
127 | |||
128 | static int qm1d1c0042_set_config(struct dvb_frontend *fe, void *priv_cfg) | ||
129 | { | ||
130 | struct qm1d1c0042_state *state; | ||
131 | struct qm1d1c0042_config *cfg; | ||
132 | |||
133 | state = fe->tuner_priv; | ||
134 | cfg = priv_cfg; | ||
135 | |||
136 | if (cfg->fe) | ||
137 | state->cfg.fe = cfg->fe; | ||
138 | |||
139 | if (cfg->xtal_freq != QM1D1C0042_CFG_XTAL_DFLT) | ||
140 | dev_warn(&state->i2c->dev, | ||
141 | "(%s) changing xtal_freq not supported. ", __func__); | ||
142 | state->cfg.xtal_freq = default_cfg.xtal_freq; | ||
143 | |||
144 | state->cfg.lpf = cfg->lpf; | ||
145 | state->cfg.fast_srch = cfg->fast_srch; | ||
146 | |||
147 | if (cfg->lpf_wait != QM1D1C0042_CFG_WAIT_DFLT) | ||
148 | state->cfg.lpf_wait = cfg->lpf_wait; | ||
149 | else | ||
150 | state->cfg.lpf_wait = default_cfg.lpf_wait; | ||
151 | |||
152 | if (cfg->fast_srch_wait != QM1D1C0042_CFG_WAIT_DFLT) | ||
153 | state->cfg.fast_srch_wait = cfg->fast_srch_wait; | ||
154 | else | ||
155 | state->cfg.fast_srch_wait = default_cfg.fast_srch_wait; | ||
156 | |||
157 | if (cfg->normal_srch_wait != QM1D1C0042_CFG_WAIT_DFLT) | ||
158 | state->cfg.normal_srch_wait = cfg->normal_srch_wait; | ||
159 | else | ||
160 | state->cfg.normal_srch_wait = default_cfg.normal_srch_wait; | ||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | /* divisor, vco_band parameters */ | ||
165 | /* {maxfreq, param1(band?), param2(div?) */ | ||
166 | static const u32 conv_table[9][3] = { | ||
167 | { 2151000, 1, 7 }, | ||
168 | { 1950000, 1, 6 }, | ||
169 | { 1800000, 1, 5 }, | ||
170 | { 1600000, 1, 4 }, | ||
171 | { 1450000, 1, 3 }, | ||
172 | { 1250000, 1, 2 }, | ||
173 | { 1200000, 0, 7 }, | ||
174 | { 975000, 0, 6 }, | ||
175 | { 950000, 0, 0 } | ||
176 | }; | ||
177 | |||
178 | static int qm1d1c0042_set_params(struct dvb_frontend *fe) | ||
179 | { | ||
180 | struct qm1d1c0042_state *state; | ||
181 | u32 freq; | ||
182 | int i, ret; | ||
183 | u8 val, mask; | ||
184 | u32 a, sd; | ||
185 | s32 b; | ||
186 | |||
187 | state = fe->tuner_priv; | ||
188 | freq = fe->dtv_property_cache.frequency; | ||
189 | |||
190 | state->regs[0x08] &= 0xf0; | ||
191 | state->regs[0x08] |= 0x09; | ||
192 | |||
193 | state->regs[0x13] &= 0x9f; | ||
194 | state->regs[0x13] |= 0x20; | ||
195 | |||
196 | /* div2/vco_band */ | ||
197 | val = state->regs[0x02] & 0x0f; | ||
198 | for (i = 0; i < 8; i++) | ||
199 | if (freq < conv_table[i][0] && freq >= conv_table[i + 1][0]) { | ||
200 | val |= conv_table[i][1] << 7; | ||
201 | val |= conv_table[i][2] << 4; | ||
202 | break; | ||
203 | } | ||
204 | ret = reg_write(state, 0x02, val); | ||
205 | if (ret < 0) | ||
206 | return ret; | ||
207 | |||
208 | a = (freq + state->cfg.xtal_freq / 2) / state->cfg.xtal_freq; | ||
209 | |||
210 | state->regs[0x06] &= 0x40; | ||
211 | state->regs[0x06] |= (a - 12) / 4; | ||
212 | ret = reg_write(state, 0x06, state->regs[0x06]); | ||
213 | if (ret < 0) | ||
214 | return ret; | ||
215 | |||
216 | state->regs[0x07] &= 0xf0; | ||
217 | state->regs[0x07] |= (a - 4 * ((a - 12) / 4 + 1) - 5) & 0x0f; | ||
218 | ret = reg_write(state, 0x07, state->regs[0x07]); | ||
219 | if (ret < 0) | ||
220 | return ret; | ||
221 | |||
222 | /* LPF */ | ||
223 | val = state->regs[0x08]; | ||
224 | if (state->cfg.lpf) { | ||
225 | /* LPF_CLK, LPF_FC */ | ||
226 | val &= 0xf0; | ||
227 | val |= 0x02; | ||
228 | } | ||
229 | ret = reg_write(state, 0x08, val); | ||
230 | if (ret < 0) | ||
231 | return ret; | ||
232 | |||
233 | /* | ||
234 | * b = (freq / state->cfg.xtal_freq - a) << 20; | ||
235 | * sd = b (b >= 0) | ||
236 | * 1<<22 + b (b < 0) | ||
237 | */ | ||
238 | b = (s32)div64_s64(((s64) freq) << 20, state->cfg.xtal_freq) | ||
239 | - (((s64) a) << 20); | ||
240 | |||
241 | if (b >= 0) | ||
242 | sd = b; | ||
243 | else | ||
244 | sd = (1 << 22) + b; | ||
245 | |||
246 | state->regs[0x09] &= 0xc0; | ||
247 | state->regs[0x09] |= (sd >> 16) & 0x3f; | ||
248 | state->regs[0x0a] = (sd >> 8) & 0xff; | ||
249 | state->regs[0x0b] = sd & 0xff; | ||
250 | ret = reg_write(state, 0x09, state->regs[0x09]); | ||
251 | if (ret == 0) | ||
252 | ret = reg_write(state, 0x0a, state->regs[0x0a]); | ||
253 | if (ret == 0) | ||
254 | ret = reg_write(state, 0x0b, state->regs[0x0b]); | ||
255 | if (ret != 0) | ||
256 | return ret; | ||
257 | |||
258 | if (!state->cfg.lpf) { | ||
259 | /* CSEL_Offset */ | ||
260 | ret = reg_write(state, 0x13, state->regs[0x13]); | ||
261 | if (ret < 0) | ||
262 | return ret; | ||
263 | } | ||
264 | |||
265 | /* VCO_TM, LPF_TM */ | ||
266 | mask = state->cfg.lpf ? 0x3f : 0x7f; | ||
267 | val = state->regs[0x0c] & mask; | ||
268 | ret = reg_write(state, 0x0c, val); | ||
269 | if (ret < 0) | ||
270 | return ret; | ||
271 | usleep_range(2000, 3000); | ||
272 | val = state->regs[0x0c] | ~mask; | ||
273 | ret = reg_write(state, 0x0c, val); | ||
274 | if (ret < 0) | ||
275 | return ret; | ||
276 | |||
277 | if (state->cfg.lpf) | ||
278 | msleep(state->cfg.lpf_wait); | ||
279 | else if (state->regs[0x03] & 0x01) | ||
280 | msleep(state->cfg.fast_srch_wait); | ||
281 | else | ||
282 | msleep(state->cfg.normal_srch_wait); | ||
283 | |||
284 | if (state->cfg.lpf) { | ||
285 | /* LPF_FC */ | ||
286 | ret = reg_write(state, 0x08, 0x09); | ||
287 | if (ret < 0) | ||
288 | return ret; | ||
289 | |||
290 | /* CSEL_Offset */ | ||
291 | ret = reg_write(state, 0x13, state->regs[0x13]); | ||
292 | if (ret < 0) | ||
293 | return ret; | ||
294 | } | ||
295 | return 0; | ||
296 | } | ||
297 | |||
298 | static int qm1d1c0042_sleep(struct dvb_frontend *fe) | ||
299 | { | ||
300 | struct qm1d1c0042_state *state; | ||
301 | int ret; | ||
302 | |||
303 | state = fe->tuner_priv; | ||
304 | state->regs[0x01] &= (~(1 << 3)) & 0xff; /* BB_Reg_disable */ | ||
305 | state->regs[0x01] |= 1 << 0; /* STDBY */ | ||
306 | state->regs[0x05] |= 1 << 3; /* pfd_rst STANDBY */ | ||
307 | ret = reg_write(state, 0x05, state->regs[0x05]); | ||
308 | if (ret == 0) | ||
309 | ret = reg_write(state, 0x01, state->regs[0x01]); | ||
310 | if (ret < 0) | ||
311 | dev_warn(&state->i2c->dev, "(%s) failed. [adap%d-fe%d]\n", | ||
312 | __func__, fe->dvb->num, fe->id); | ||
313 | return ret; | ||
314 | } | ||
315 | |||
316 | static int qm1d1c0042_init(struct dvb_frontend *fe) | ||
317 | { | ||
318 | struct qm1d1c0042_state *state; | ||
319 | u8 val; | ||
320 | int i, ret; | ||
321 | |||
322 | state = fe->tuner_priv; | ||
323 | memcpy(state->regs, reg_initval, sizeof(reg_initval)); | ||
324 | |||
325 | reg_write(state, 0x01, 0x0c); | ||
326 | reg_write(state, 0x01, 0x0c); | ||
327 | |||
328 | ret = reg_write(state, 0x01, 0x0c); /* soft reset on */ | ||
329 | if (ret < 0) | ||
330 | goto failed; | ||
331 | usleep_range(2000, 3000); | ||
332 | |||
333 | val = state->regs[0x01] | 0x10; | ||
334 | ret = reg_write(state, 0x01, val); /* soft reset off */ | ||
335 | if (ret < 0) | ||
336 | goto failed; | ||
337 | |||
338 | /* check ID */ | ||
339 | ret = reg_read(state, 0x00, &val); | ||
340 | if (ret < 0 || val != 0x48) | ||
341 | goto failed; | ||
342 | usleep_range(2000, 3000); | ||
343 | |||
344 | state->regs[0x0c] |= 0x40; | ||
345 | ret = reg_write(state, 0x0c, state->regs[0x0c]); | ||
346 | if (ret < 0) | ||
347 | goto failed; | ||
348 | msleep(state->cfg.lpf_wait); | ||
349 | |||
350 | /* set all writable registers */ | ||
351 | for (i = 1; i <= 0x0c ; i++) { | ||
352 | ret = reg_write(state, i, state->regs[i]); | ||
353 | if (ret < 0) | ||
354 | goto failed; | ||
355 | } | ||
356 | for (i = 0x11; i < QM1D1C0042_NUM_REGS; i++) { | ||
357 | ret = reg_write(state, i, state->regs[i]); | ||
358 | if (ret < 0) | ||
359 | goto failed; | ||
360 | } | ||
361 | |||
362 | ret = qm1d1c0042_wakeup(state); | ||
363 | if (ret < 0) | ||
364 | goto failed; | ||
365 | |||
366 | ret = qm1d1c0042_set_srch_mode(state, state->cfg.fast_srch); | ||
367 | if (ret < 0) | ||
368 | goto failed; | ||
369 | |||
370 | return ret; | ||
371 | |||
372 | failed: | ||
373 | dev_warn(&state->i2c->dev, "(%s) failed. [adap%d-fe%d]\n", | ||
374 | __func__, fe->dvb->num, fe->id); | ||
375 | return ret; | ||
376 | } | ||
377 | |||
378 | /* I2C driver functions */ | ||
379 | |||
380 | static const struct dvb_tuner_ops qm1d1c0042_ops = { | ||
381 | .info = { | ||
382 | .name = "Sharp QM1D1C0042", | ||
383 | |||
384 | .frequency_min = 950000, | ||
385 | .frequency_max = 2150000, | ||
386 | }, | ||
387 | |||
388 | .init = qm1d1c0042_init, | ||
389 | .sleep = qm1d1c0042_sleep, | ||
390 | .set_config = qm1d1c0042_set_config, | ||
391 | .set_params = qm1d1c0042_set_params, | ||
392 | }; | ||
393 | |||
394 | |||
395 | static int qm1d1c0042_probe(struct i2c_client *client, | ||
396 | const struct i2c_device_id *id) | ||
397 | { | ||
398 | struct qm1d1c0042_state *state; | ||
399 | struct qm1d1c0042_config *cfg; | ||
400 | struct dvb_frontend *fe; | ||
401 | |||
402 | state = kzalloc(sizeof(*state), GFP_KERNEL); | ||
403 | if (!state) | ||
404 | return -ENOMEM; | ||
405 | state->i2c = client; | ||
406 | |||
407 | cfg = client->dev.platform_data; | ||
408 | fe = cfg->fe; | ||
409 | fe->tuner_priv = state; | ||
410 | qm1d1c0042_set_config(fe, cfg); | ||
411 | memcpy(&fe->ops.tuner_ops, &qm1d1c0042_ops, sizeof(qm1d1c0042_ops)); | ||
412 | |||
413 | i2c_set_clientdata(client, &state->cfg); | ||
414 | dev_info(&client->dev, "Sharp QM1D1C0042 attached.\n"); | ||
415 | return 0; | ||
416 | } | ||
417 | |||
418 | static int qm1d1c0042_remove(struct i2c_client *client) | ||
419 | { | ||
420 | struct qm1d1c0042_state *state; | ||
421 | |||
422 | state = cfg_to_state(i2c_get_clientdata(client)); | ||
423 | state->cfg.fe->tuner_priv = NULL; | ||
424 | kfree(state); | ||
425 | return 0; | ||
426 | } | ||
427 | |||
428 | |||
429 | static const struct i2c_device_id qm1d1c0042_id[] = { | ||
430 | {"qm1d1c0042", 0}, | ||
431 | {} | ||
432 | }; | ||
433 | MODULE_DEVICE_TABLE(i2c, qm1d1c0042_id); | ||
434 | |||
435 | static struct i2c_driver qm1d1c0042_driver = { | ||
436 | .driver = { | ||
437 | .name = "qm1d1c0042", | ||
438 | }, | ||
439 | .probe = qm1d1c0042_probe, | ||
440 | .remove = qm1d1c0042_remove, | ||
441 | .id_table = qm1d1c0042_id, | ||
442 | }; | ||
443 | |||
444 | module_i2c_driver(qm1d1c0042_driver); | ||
445 | |||
446 | MODULE_DESCRIPTION("Sharp QM1D1C0042 tuner"); | ||
447 | MODULE_AUTHOR("Akihiro TSUKADA"); | ||
448 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/tuners/qm1d1c0042.h b/drivers/media/tuners/qm1d1c0042.h new file mode 100644 index 000000000000..4f5c18816c44 --- /dev/null +++ b/drivers/media/tuners/qm1d1c0042.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * Sharp QM1D1C0042 8PSK tuner driver | ||
3 | * | ||
4 | * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License as | ||
8 | * published by the Free Software Foundation version 2. | ||
9 | * | ||
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 | |||
17 | #ifndef QM1D1C0042_H | ||
18 | #define QM1D1C0042_H | ||
19 | |||
20 | #include "dvb_frontend.h" | ||
21 | |||
22 | |||
23 | struct qm1d1c0042_config { | ||
24 | struct dvb_frontend *fe; | ||
25 | |||
26 | u32 xtal_freq; /* [kHz] */ /* currently ignored */ | ||
27 | bool lpf; /* enable LPF */ | ||
28 | bool fast_srch; /* enable fast search mode, no LPF */ | ||
29 | u32 lpf_wait; /* wait in tuning with LPF enabled. [ms] */ | ||
30 | u32 fast_srch_wait; /* with fast-search mode, no LPF. [ms] */ | ||
31 | u32 normal_srch_wait; /* with no LPF/fast-search mode. [ms] */ | ||
32 | }; | ||
33 | /* special values indicating to use the default in qm1d1c0042_config */ | ||
34 | #define QM1D1C0042_CFG_XTAL_DFLT 0 | ||
35 | #define QM1D1C0042_CFG_WAIT_DFLT 0 | ||
36 | |||
37 | #endif /* QM1D1C0042_H */ | ||
diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c index 6c53edb73a63..cf97142e01e6 100644 --- a/drivers/media/tuners/si2157.c +++ b/drivers/media/tuners/si2157.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Silicon Labs Si2157/2158 silicon tuner driver | 2 | * Silicon Labs Si2147/2157/2158 silicon tuner driver |
3 | * | 3 | * |
4 | * Copyright (C) 2014 Antti Palosaari <crope@iki.fi> | 4 | * Copyright (C) 2014 Antti Palosaari <crope@iki.fi> |
5 | * | 5 | * |
@@ -55,8 +55,7 @@ static int si2157_cmd_execute(struct si2157 *s, struct si2157_cmd *cmd) | |||
55 | break; | 55 | break; |
56 | } | 56 | } |
57 | 57 | ||
58 | dev_dbg(&s->client->dev, "%s: cmd execution took %d ms\n", | 58 | dev_dbg(&s->client->dev, "cmd execution took %d ms\n", |
59 | __func__, | ||
60 | jiffies_to_msecs(jiffies) - | 59 | jiffies_to_msecs(jiffies) - |
61 | (jiffies_to_msecs(timeout) - TIMEOUT)); | 60 | (jiffies_to_msecs(timeout) - TIMEOUT)); |
62 | 61 | ||
@@ -75,7 +74,7 @@ err_mutex_unlock: | |||
75 | 74 | ||
76 | return 0; | 75 | return 0; |
77 | err: | 76 | err: |
78 | dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret); | 77 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
79 | return ret; | 78 | return ret; |
80 | } | 79 | } |
81 | 80 | ||
@@ -88,9 +87,12 @@ static int si2157_init(struct dvb_frontend *fe) | |||
88 | u8 *fw_file; | 87 | u8 *fw_file; |
89 | unsigned int chip_id; | 88 | unsigned int chip_id; |
90 | 89 | ||
91 | dev_dbg(&s->client->dev, "%s:\n", __func__); | 90 | dev_dbg(&s->client->dev, "\n"); |
92 | 91 | ||
93 | /* configure? */ | 92 | if (s->fw_loaded) |
93 | goto warm; | ||
94 | |||
95 | /* power up */ | ||
94 | memcpy(cmd.args, "\xc0\x00\x0c\x00\x00\x01\x01\x01\x01\x01\x01\x02\x00\x00\x01", 15); | 96 | memcpy(cmd.args, "\xc0\x00\x0c\x00\x00\x01\x01\x01\x01\x01\x01\x02\x00\x00\x01", 15); |
95 | cmd.wlen = 15; | 97 | cmd.wlen = 15; |
96 | cmd.rlen = 1; | 98 | cmd.rlen = 1; |
@@ -111,45 +113,47 @@ static int si2157_init(struct dvb_frontend *fe) | |||
111 | 113 | ||
112 | #define SI2158_A20 ('A' << 24 | 58 << 16 | '2' << 8 | '0' << 0) | 114 | #define SI2158_A20 ('A' << 24 | 58 << 16 | '2' << 8 | '0' << 0) |
113 | #define SI2157_A30 ('A' << 24 | 57 << 16 | '3' << 8 | '0' << 0) | 115 | #define SI2157_A30 ('A' << 24 | 57 << 16 | '3' << 8 | '0' << 0) |
116 | #define SI2147_A30 ('A' << 24 | 47 << 16 | '3' << 8 | '0' << 0) | ||
114 | 117 | ||
115 | switch (chip_id) { | 118 | switch (chip_id) { |
116 | case SI2158_A20: | 119 | case SI2158_A20: |
117 | fw_file = SI2158_A20_FIRMWARE; | 120 | fw_file = SI2158_A20_FIRMWARE; |
118 | break; | 121 | break; |
119 | case SI2157_A30: | 122 | case SI2157_A30: |
123 | case SI2147_A30: | ||
120 | goto skip_fw_download; | 124 | goto skip_fw_download; |
121 | break; | 125 | break; |
122 | default: | 126 | default: |
123 | dev_err(&s->client->dev, | 127 | dev_err(&s->client->dev, |
124 | "%s: unkown chip version Si21%d-%c%c%c\n", | 128 | "unknown chip version Si21%d-%c%c%c\n", |
125 | KBUILD_MODNAME, cmd.args[2], cmd.args[1], | 129 | cmd.args[2], cmd.args[1], |
126 | cmd.args[3], cmd.args[4]); | 130 | cmd.args[3], cmd.args[4]); |
127 | ret = -EINVAL; | 131 | ret = -EINVAL; |
128 | goto err; | 132 | goto err; |
129 | } | 133 | } |
130 | 134 | ||
131 | /* cold state - try to download firmware */ | 135 | /* cold state - try to download firmware */ |
132 | dev_info(&s->client->dev, "%s: found a '%s' in cold state\n", | 136 | dev_info(&s->client->dev, "found a '%s' in cold state\n", |
133 | KBUILD_MODNAME, si2157_ops.info.name); | 137 | si2157_ops.info.name); |
134 | 138 | ||
135 | /* request the firmware, this will block and timeout */ | 139 | /* request the firmware, this will block and timeout */ |
136 | ret = request_firmware(&fw, fw_file, &s->client->dev); | 140 | ret = request_firmware(&fw, fw_file, &s->client->dev); |
137 | if (ret) { | 141 | if (ret) { |
138 | dev_err(&s->client->dev, "%s: firmware file '%s' not found\n", | 142 | dev_err(&s->client->dev, "firmware file '%s' not found\n", |
139 | KBUILD_MODNAME, fw_file); | 143 | fw_file); |
140 | goto err; | 144 | goto err; |
141 | } | 145 | } |
142 | 146 | ||
143 | /* firmware should be n chunks of 17 bytes */ | 147 | /* firmware should be n chunks of 17 bytes */ |
144 | if (fw->size % 17 != 0) { | 148 | if (fw->size % 17 != 0) { |
145 | dev_err(&s->client->dev, "%s: firmware file '%s' is invalid\n", | 149 | dev_err(&s->client->dev, "firmware file '%s' is invalid\n", |
146 | KBUILD_MODNAME, fw_file); | 150 | fw_file); |
147 | ret = -EINVAL; | 151 | ret = -EINVAL; |
148 | goto err; | 152 | goto err; |
149 | } | 153 | } |
150 | 154 | ||
151 | dev_info(&s->client->dev, "%s: downloading firmware from file '%s'\n", | 155 | dev_info(&s->client->dev, "downloading firmware from file '%s'\n", |
152 | KBUILD_MODNAME, fw_file); | 156 | fw_file); |
153 | 157 | ||
154 | for (remaining = fw->size; remaining > 0; remaining -= 17) { | 158 | for (remaining = fw->size; remaining > 0; remaining -= 17) { |
155 | len = fw->data[fw->size - remaining]; | 159 | len = fw->data[fw->size - remaining]; |
@@ -159,8 +163,8 @@ static int si2157_init(struct dvb_frontend *fe) | |||
159 | ret = si2157_cmd_execute(s, &cmd); | 163 | ret = si2157_cmd_execute(s, &cmd); |
160 | if (ret) { | 164 | if (ret) { |
161 | dev_err(&s->client->dev, | 165 | dev_err(&s->client->dev, |
162 | "%s: firmware download failed=%d\n", | 166 | "firmware download failed=%d\n", |
163 | KBUILD_MODNAME, ret); | 167 | ret); |
164 | goto err; | 168 | goto err; |
165 | } | 169 | } |
166 | } | 170 | } |
@@ -177,14 +181,17 @@ skip_fw_download: | |||
177 | if (ret) | 181 | if (ret) |
178 | goto err; | 182 | goto err; |
179 | 183 | ||
180 | s->active = true; | 184 | s->fw_loaded = true; |
181 | 185 | ||
186 | warm: | ||
187 | s->active = true; | ||
182 | return 0; | 188 | return 0; |
189 | |||
183 | err: | 190 | err: |
184 | if (fw) | 191 | if (fw) |
185 | release_firmware(fw); | 192 | release_firmware(fw); |
186 | 193 | ||
187 | dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret); | 194 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
188 | return ret; | 195 | return ret; |
189 | } | 196 | } |
190 | 197 | ||
@@ -194,20 +201,21 @@ static int si2157_sleep(struct dvb_frontend *fe) | |||
194 | int ret; | 201 | int ret; |
195 | struct si2157_cmd cmd; | 202 | struct si2157_cmd cmd; |
196 | 203 | ||
197 | dev_dbg(&s->client->dev, "%s:\n", __func__); | 204 | dev_dbg(&s->client->dev, "\n"); |
198 | 205 | ||
199 | s->active = false; | 206 | s->active = false; |
200 | 207 | ||
201 | memcpy(cmd.args, "\x13", 1); | 208 | /* standby */ |
202 | cmd.wlen = 1; | 209 | memcpy(cmd.args, "\x16\x00", 2); |
203 | cmd.rlen = 0; | 210 | cmd.wlen = 2; |
211 | cmd.rlen = 1; | ||
204 | ret = si2157_cmd_execute(s, &cmd); | 212 | ret = si2157_cmd_execute(s, &cmd); |
205 | if (ret) | 213 | if (ret) |
206 | goto err; | 214 | goto err; |
207 | 215 | ||
208 | return 0; | 216 | return 0; |
209 | err: | 217 | err: |
210 | dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret); | 218 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
211 | return ret; | 219 | return ret; |
212 | } | 220 | } |
213 | 221 | ||
@@ -220,8 +228,8 @@ static int si2157_set_params(struct dvb_frontend *fe) | |||
220 | u8 bandwidth, delivery_system; | 228 | u8 bandwidth, delivery_system; |
221 | 229 | ||
222 | dev_dbg(&s->client->dev, | 230 | dev_dbg(&s->client->dev, |
223 | "%s: delivery_system=%d frequency=%u bandwidth_hz=%u\n", | 231 | "delivery_system=%d frequency=%u bandwidth_hz=%u\n", |
224 | __func__, c->delivery_system, c->frequency, | 232 | c->delivery_system, c->frequency, |
225 | c->bandwidth_hz); | 233 | c->bandwidth_hz); |
226 | 234 | ||
227 | if (!s->active) { | 235 | if (!s->active) { |
@@ -239,6 +247,9 @@ static int si2157_set_params(struct dvb_frontend *fe) | |||
239 | bandwidth = 0x0f; | 247 | bandwidth = 0x0f; |
240 | 248 | ||
241 | switch (c->delivery_system) { | 249 | switch (c->delivery_system) { |
250 | case SYS_ATSC: | ||
251 | delivery_system = 0x00; | ||
252 | break; | ||
242 | case SYS_DVBT: | 253 | case SYS_DVBT: |
243 | case SYS_DVBT2: /* it seems DVB-T and DVB-T2 both are 0x20 here */ | 254 | case SYS_DVBT2: /* it seems DVB-T and DVB-T2 both are 0x20 here */ |
244 | delivery_system = 0x20; | 255 | delivery_system = 0x20; |
@@ -256,7 +267,14 @@ static int si2157_set_params(struct dvb_frontend *fe) | |||
256 | if (s->inversion) | 267 | if (s->inversion) |
257 | cmd.args[5] = 0x01; | 268 | cmd.args[5] = 0x01; |
258 | cmd.wlen = 6; | 269 | cmd.wlen = 6; |
259 | cmd.rlen = 1; | 270 | cmd.rlen = 4; |
271 | ret = si2157_cmd_execute(s, &cmd); | ||
272 | if (ret) | ||
273 | goto err; | ||
274 | |||
275 | memcpy(cmd.args, "\x14\x00\x02\x07\x01\x00", 6); | ||
276 | cmd.wlen = 6; | ||
277 | cmd.rlen = 4; | ||
260 | ret = si2157_cmd_execute(s, &cmd); | 278 | ret = si2157_cmd_execute(s, &cmd); |
261 | if (ret) | 279 | if (ret) |
262 | goto err; | 280 | goto err; |
@@ -275,7 +293,7 @@ static int si2157_set_params(struct dvb_frontend *fe) | |||
275 | 293 | ||
276 | return 0; | 294 | return 0; |
277 | err: | 295 | err: |
278 | dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret); | 296 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
279 | return ret; | 297 | return ret; |
280 | } | 298 | } |
281 | 299 | ||
@@ -310,13 +328,14 @@ static int si2157_probe(struct i2c_client *client, | |||
310 | s = kzalloc(sizeof(struct si2157), GFP_KERNEL); | 328 | s = kzalloc(sizeof(struct si2157), GFP_KERNEL); |
311 | if (!s) { | 329 | if (!s) { |
312 | ret = -ENOMEM; | 330 | ret = -ENOMEM; |
313 | dev_err(&client->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME); | 331 | dev_err(&client->dev, "kzalloc() failed\n"); |
314 | goto err; | 332 | goto err; |
315 | } | 333 | } |
316 | 334 | ||
317 | s->client = client; | 335 | s->client = client; |
318 | s->fe = cfg->fe; | 336 | s->fe = cfg->fe; |
319 | s->inversion = cfg->inversion; | 337 | s->inversion = cfg->inversion; |
338 | s->fw_loaded = false; | ||
320 | mutex_init(&s->i2c_mutex); | 339 | mutex_init(&s->i2c_mutex); |
321 | 340 | ||
322 | /* check if the tuner is there */ | 341 | /* check if the tuner is there */ |
@@ -333,11 +352,10 @@ static int si2157_probe(struct i2c_client *client, | |||
333 | i2c_set_clientdata(client, s); | 352 | i2c_set_clientdata(client, s); |
334 | 353 | ||
335 | dev_info(&s->client->dev, | 354 | dev_info(&s->client->dev, |
336 | "%s: Silicon Labs Si2157/Si2158 successfully attached\n", | 355 | "Silicon Labs Si2157/Si2158 successfully attached\n"); |
337 | KBUILD_MODNAME); | ||
338 | return 0; | 356 | return 0; |
339 | err: | 357 | err: |
340 | dev_dbg(&client->dev, "%s: failed=%d\n", __func__, ret); | 358 | dev_dbg(&client->dev, "failed=%d\n", ret); |
341 | kfree(s); | 359 | kfree(s); |
342 | 360 | ||
343 | return ret; | 361 | return ret; |
@@ -348,7 +366,7 @@ static int si2157_remove(struct i2c_client *client) | |||
348 | struct si2157 *s = i2c_get_clientdata(client); | 366 | struct si2157 *s = i2c_get_clientdata(client); |
349 | struct dvb_frontend *fe = s->fe; | 367 | struct dvb_frontend *fe = s->fe; |
350 | 368 | ||
351 | dev_dbg(&client->dev, "%s:\n", __func__); | 369 | dev_dbg(&client->dev, "\n"); |
352 | 370 | ||
353 | memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); | 371 | memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); |
354 | fe->tuner_priv = NULL; | 372 | fe->tuner_priv = NULL; |
diff --git a/drivers/media/tuners/si2157.h b/drivers/media/tuners/si2157.h index 6da4d5d1c817..d3b19cadb4a1 100644 --- a/drivers/media/tuners/si2157.h +++ b/drivers/media/tuners/si2157.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Silicon Labs Si2157/2158 silicon tuner driver | 2 | * Silicon Labs Si2147/2157/2158 silicon tuner driver |
3 | * | 3 | * |
4 | * Copyright (C) 2014 Antti Palosaari <crope@iki.fi> | 4 | * Copyright (C) 2014 Antti Palosaari <crope@iki.fi> |
5 | * | 5 | * |
diff --git a/drivers/media/tuners/si2157_priv.h b/drivers/media/tuners/si2157_priv.h index 3ddab5e6b500..e71ffafed951 100644 --- a/drivers/media/tuners/si2157_priv.h +++ b/drivers/media/tuners/si2157_priv.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Silicon Labs Si2157/2158 silicon tuner driver | 2 | * Silicon Labs Si2147/2157/2158 silicon tuner driver |
3 | * | 3 | * |
4 | * Copyright (C) 2014 Antti Palosaari <crope@iki.fi> | 4 | * Copyright (C) 2014 Antti Palosaari <crope@iki.fi> |
5 | * | 5 | * |
@@ -26,6 +26,7 @@ struct si2157 { | |||
26 | struct i2c_client *client; | 26 | struct i2c_client *client; |
27 | struct dvb_frontend *fe; | 27 | struct dvb_frontend *fe; |
28 | bool active; | 28 | bool active; |
29 | bool fw_loaded; | ||
29 | bool inversion; | 30 | bool inversion; |
30 | }; | 31 | }; |
31 | 32 | ||
diff --git a/drivers/media/tuners/tda18212.c b/drivers/media/tuners/tda18212.c index 05a4ac9edb6b..d93e0667b46b 100644 --- a/drivers/media/tuners/tda18212.c +++ b/drivers/media/tuners/tda18212.c | |||
@@ -19,125 +19,19 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include "tda18212.h" | 21 | #include "tda18212.h" |
22 | #include <linux/regmap.h> | ||
22 | 23 | ||
23 | /* Max transfer size done by I2C transfer functions */ | 24 | struct tda18212_dev { |
24 | #define MAX_XFER_SIZE 64 | 25 | struct tda18212_config cfg; |
25 | 26 | struct i2c_client *client; | |
26 | struct tda18212_priv { | 27 | struct regmap *regmap; |
27 | struct tda18212_config *cfg; | ||
28 | struct i2c_adapter *i2c; | ||
29 | 28 | ||
30 | u32 if_frequency; | 29 | u32 if_frequency; |
31 | }; | 30 | }; |
32 | 31 | ||
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; | ||
38 | u8 buf[MAX_XFER_SIZE]; | ||
39 | struct i2c_msg msg[1] = { | ||
40 | { | ||
41 | .addr = priv->cfg->i2c_address, | ||
42 | .flags = 0, | ||
43 | .len = 1 + len, | ||
44 | .buf = buf, | ||
45 | } | ||
46 | }; | ||
47 | |||
48 | if (1 + len > sizeof(buf)) { | ||
49 | dev_warn(&priv->i2c->dev, | ||
50 | "%s: i2c wr reg=%04x: len=%d is too big!\n", | ||
51 | KBUILD_MODNAME, reg, len); | ||
52 | return -EINVAL; | ||
53 | } | ||
54 | |||
55 | buf[0] = reg; | ||
56 | memcpy(&buf[1], val, len); | ||
57 | |||
58 | ret = i2c_transfer(priv->i2c, msg, 1); | ||
59 | if (ret == 1) { | ||
60 | ret = 0; | ||
61 | } else { | ||
62 | dev_warn(&priv->i2c->dev, "%s: i2c wr failed=%d reg=%02x " \ | ||
63 | "len=%d\n", KBUILD_MODNAME, ret, reg, len); | ||
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; | ||
74 | u8 buf[MAX_XFER_SIZE]; | ||
75 | struct i2c_msg msg[2] = { | ||
76 | { | ||
77 | .addr = priv->cfg->i2c_address, | ||
78 | .flags = 0, | ||
79 | .len = 1, | ||
80 | .buf = ®, | ||
81 | }, { | ||
82 | .addr = priv->cfg->i2c_address, | ||
83 | .flags = I2C_M_RD, | ||
84 | .len = len, | ||
85 | .buf = buf, | ||
86 | } | ||
87 | }; | ||
88 | |||
89 | if (len > sizeof(buf)) { | ||
90 | dev_warn(&priv->i2c->dev, | ||
91 | "%s: i2c rd reg=%04x: len=%d is too big!\n", | ||
92 | KBUILD_MODNAME, reg, len); | ||
93 | return -EINVAL; | ||
94 | } | ||
95 | |||
96 | ret = i2c_transfer(priv->i2c, msg, 2); | ||
97 | if (ret == 2) { | ||
98 | memcpy(val, buf, len); | ||
99 | ret = 0; | ||
100 | } else { | ||
101 | dev_warn(&priv->i2c->dev, "%s: i2c rd failed=%d reg=%02x " \ | ||
102 | "len=%d\n", KBUILD_MODNAME, ret, reg, len); | ||
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 | |||
138 | static int tda18212_set_params(struct dvb_frontend *fe) | 32 | static int tda18212_set_params(struct dvb_frontend *fe) |
139 | { | 33 | { |
140 | struct tda18212_priv *priv = fe->tuner_priv; | 34 | struct tda18212_dev *dev = fe->tuner_priv; |
141 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; | 35 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
142 | int ret, i; | 36 | int ret, i; |
143 | u32 if_khz; | 37 | u32 if_khz; |
@@ -166,9 +60,9 @@ static int tda18212_set_params(struct dvb_frontend *fe) | |||
166 | [ATSC_QAM] = { 0x7d, 0x20, 0x63 }, | 60 | [ATSC_QAM] = { 0x7d, 0x20, 0x63 }, |
167 | }; | 61 | }; |
168 | 62 | ||
169 | dev_dbg(&priv->i2c->dev, | 63 | dev_dbg(&dev->client->dev, |
170 | "%s: delivery_system=%d frequency=%d bandwidth_hz=%d\n", | 64 | "delivery_system=%d frequency=%d bandwidth_hz=%d\n", |
171 | __func__, c->delivery_system, c->frequency, | 65 | c->delivery_system, c->frequency, |
172 | c->bandwidth_hz); | 66 | c->bandwidth_hz); |
173 | 67 | ||
174 | if (fe->ops.i2c_gate_ctrl) | 68 | if (fe->ops.i2c_gate_ctrl) |
@@ -176,25 +70,25 @@ static int tda18212_set_params(struct dvb_frontend *fe) | |||
176 | 70 | ||
177 | switch (c->delivery_system) { | 71 | switch (c->delivery_system) { |
178 | case SYS_ATSC: | 72 | case SYS_ATSC: |
179 | if_khz = priv->cfg->if_atsc_vsb; | 73 | if_khz = dev->cfg.if_atsc_vsb; |
180 | i = ATSC_VSB; | 74 | i = ATSC_VSB; |
181 | break; | 75 | break; |
182 | case SYS_DVBC_ANNEX_B: | 76 | case SYS_DVBC_ANNEX_B: |
183 | if_khz = priv->cfg->if_atsc_qam; | 77 | if_khz = dev->cfg.if_atsc_qam; |
184 | i = ATSC_QAM; | 78 | i = ATSC_QAM; |
185 | break; | 79 | break; |
186 | case SYS_DVBT: | 80 | case SYS_DVBT: |
187 | switch (c->bandwidth_hz) { | 81 | switch (c->bandwidth_hz) { |
188 | case 6000000: | 82 | case 6000000: |
189 | if_khz = priv->cfg->if_dvbt_6; | 83 | if_khz = dev->cfg.if_dvbt_6; |
190 | i = DVBT_6; | 84 | i = DVBT_6; |
191 | break; | 85 | break; |
192 | case 7000000: | 86 | case 7000000: |
193 | if_khz = priv->cfg->if_dvbt_7; | 87 | if_khz = dev->cfg.if_dvbt_7; |
194 | i = DVBT_7; | 88 | i = DVBT_7; |
195 | break; | 89 | break; |
196 | case 8000000: | 90 | case 8000000: |
197 | if_khz = priv->cfg->if_dvbt_8; | 91 | if_khz = dev->cfg.if_dvbt_8; |
198 | i = DVBT_8; | 92 | i = DVBT_8; |
199 | break; | 93 | break; |
200 | default: | 94 | default: |
@@ -205,15 +99,15 @@ static int tda18212_set_params(struct dvb_frontend *fe) | |||
205 | case SYS_DVBT2: | 99 | case SYS_DVBT2: |
206 | switch (c->bandwidth_hz) { | 100 | switch (c->bandwidth_hz) { |
207 | case 6000000: | 101 | case 6000000: |
208 | if_khz = priv->cfg->if_dvbt2_6; | 102 | if_khz = dev->cfg.if_dvbt2_6; |
209 | i = DVBT2_6; | 103 | i = DVBT2_6; |
210 | break; | 104 | break; |
211 | case 7000000: | 105 | case 7000000: |
212 | if_khz = priv->cfg->if_dvbt2_7; | 106 | if_khz = dev->cfg.if_dvbt2_7; |
213 | i = DVBT2_7; | 107 | i = DVBT2_7; |
214 | break; | 108 | break; |
215 | case 8000000: | 109 | case 8000000: |
216 | if_khz = priv->cfg->if_dvbt2_8; | 110 | if_khz = dev->cfg.if_dvbt2_8; |
217 | i = DVBT2_8; | 111 | i = DVBT2_8; |
218 | break; | 112 | break; |
219 | default: | 113 | default: |
@@ -223,7 +117,7 @@ static int tda18212_set_params(struct dvb_frontend *fe) | |||
223 | break; | 117 | break; |
224 | case SYS_DVBC_ANNEX_A: | 118 | case SYS_DVBC_ANNEX_A: |
225 | case SYS_DVBC_ANNEX_C: | 119 | case SYS_DVBC_ANNEX_C: |
226 | if_khz = priv->cfg->if_dvbc; | 120 | if_khz = dev->cfg.if_dvbc; |
227 | i = DVBC_8; | 121 | i = DVBC_8; |
228 | break; | 122 | break; |
229 | default: | 123 | default: |
@@ -231,15 +125,15 @@ static int tda18212_set_params(struct dvb_frontend *fe) | |||
231 | goto error; | 125 | goto error; |
232 | } | 126 | } |
233 | 127 | ||
234 | ret = tda18212_wr_reg(priv, 0x23, bw_params[i][2]); | 128 | ret = regmap_write(dev->regmap, 0x23, bw_params[i][2]); |
235 | if (ret) | 129 | if (ret) |
236 | goto error; | 130 | goto error; |
237 | 131 | ||
238 | ret = tda18212_wr_reg(priv, 0x06, 0x00); | 132 | ret = regmap_write(dev->regmap, 0x06, 0x00); |
239 | if (ret) | 133 | if (ret) |
240 | goto error; | 134 | goto error; |
241 | 135 | ||
242 | ret = tda18212_wr_reg(priv, 0x0f, bw_params[i][0]); | 136 | ret = regmap_write(dev->regmap, 0x0f, bw_params[i][0]); |
243 | if (ret) | 137 | if (ret) |
244 | goto error; | 138 | goto error; |
245 | 139 | ||
@@ -252,12 +146,12 @@ static int tda18212_set_params(struct dvb_frontend *fe) | |||
252 | buf[6] = ((c->frequency / 1000) >> 0) & 0xff; | 146 | buf[6] = ((c->frequency / 1000) >> 0) & 0xff; |
253 | buf[7] = 0xc1; | 147 | buf[7] = 0xc1; |
254 | buf[8] = 0x01; | 148 | buf[8] = 0x01; |
255 | ret = tda18212_wr_regs(priv, 0x12, buf, sizeof(buf)); | 149 | ret = regmap_bulk_write(dev->regmap, 0x12, buf, sizeof(buf)); |
256 | if (ret) | 150 | if (ret) |
257 | goto error; | 151 | goto error; |
258 | 152 | ||
259 | /* actual IF rounded as it is on register */ | 153 | /* actual IF rounded as it is on register */ |
260 | priv->if_frequency = buf[3] * 50 * 1000; | 154 | dev->if_frequency = buf[3] * 50 * 1000; |
261 | 155 | ||
262 | exit: | 156 | exit: |
263 | if (fe->ops.i2c_gate_ctrl) | 157 | if (fe->ops.i2c_gate_ctrl) |
@@ -266,26 +160,19 @@ exit: | |||
266 | return ret; | 160 | return ret; |
267 | 161 | ||
268 | error: | 162 | error: |
269 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); | 163 | dev_dbg(&dev->client->dev, "failed=%d\n", ret); |
270 | goto exit; | 164 | goto exit; |
271 | } | 165 | } |
272 | 166 | ||
273 | static int tda18212_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) | 167 | static int tda18212_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) |
274 | { | 168 | { |
275 | struct tda18212_priv *priv = fe->tuner_priv; | 169 | struct tda18212_dev *dev = fe->tuner_priv; |
276 | 170 | ||
277 | *frequency = priv->if_frequency; | 171 | *frequency = dev->if_frequency; |
278 | 172 | ||
279 | return 0; | 173 | return 0; |
280 | } | 174 | } |
281 | 175 | ||
282 | static int tda18212_release(struct dvb_frontend *fe) | ||
283 | { | ||
284 | kfree(fe->tuner_priv); | ||
285 | fe->tuner_priv = NULL; | ||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static const struct dvb_tuner_ops tda18212_tuner_ops = { | 176 | static const struct dvb_tuner_ops tda18212_tuner_ops = { |
290 | .info = { | 177 | .info = { |
291 | .name = "NXP TDA18212", | 178 | .name = "NXP TDA18212", |
@@ -295,53 +182,110 @@ static const struct dvb_tuner_ops tda18212_tuner_ops = { | |||
295 | .frequency_step = 1000, | 182 | .frequency_step = 1000, |
296 | }, | 183 | }, |
297 | 184 | ||
298 | .release = tda18212_release, | ||
299 | |||
300 | .set_params = tda18212_set_params, | 185 | .set_params = tda18212_set_params, |
301 | .get_if_frequency = tda18212_get_if_frequency, | 186 | .get_if_frequency = tda18212_get_if_frequency, |
302 | }; | 187 | }; |
303 | 188 | ||
304 | struct dvb_frontend *tda18212_attach(struct dvb_frontend *fe, | 189 | static int tda18212_probe(struct i2c_client *client, |
305 | struct i2c_adapter *i2c, struct tda18212_config *cfg) | 190 | const struct i2c_device_id *id) |
306 | { | 191 | { |
307 | struct tda18212_priv *priv = NULL; | 192 | struct tda18212_config *cfg = client->dev.platform_data; |
193 | struct dvb_frontend *fe = cfg->fe; | ||
194 | struct tda18212_dev *dev; | ||
308 | int ret; | 195 | int ret; |
309 | u8 val; | 196 | unsigned int chip_id; |
197 | char *version; | ||
198 | static const struct regmap_config regmap_config = { | ||
199 | .reg_bits = 8, | ||
200 | .val_bits = 8, | ||
201 | }; | ||
310 | 202 | ||
311 | priv = kzalloc(sizeof(struct tda18212_priv), GFP_KERNEL); | 203 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
312 | if (priv == NULL) | 204 | if (dev == NULL) { |
313 | return NULL; | 205 | ret = -ENOMEM; |
206 | dev_err(&client->dev, "kzalloc() failed\n"); | ||
207 | goto err; | ||
208 | } | ||
314 | 209 | ||
315 | priv->cfg = cfg; | 210 | memcpy(&dev->cfg, cfg, sizeof(struct tda18212_config)); |
316 | priv->i2c = i2c; | 211 | dev->client = client; |
317 | fe->tuner_priv = priv; | 212 | dev->regmap = devm_regmap_init_i2c(client, ®map_config); |
213 | if (IS_ERR(dev->regmap)) { | ||
214 | ret = PTR_ERR(dev->regmap); | ||
215 | goto err; | ||
216 | } | ||
318 | 217 | ||
218 | /* check if the tuner is there */ | ||
319 | if (fe->ops.i2c_gate_ctrl) | 219 | if (fe->ops.i2c_gate_ctrl) |
320 | fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */ | 220 | fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */ |
321 | 221 | ||
322 | /* check if the tuner is there */ | 222 | ret = regmap_read(dev->regmap, 0x00, &chip_id); |
323 | ret = tda18212_rd_reg(priv, 0x00, &val); | 223 | dev_dbg(&dev->client->dev, "chip_id=%02x\n", chip_id); |
324 | 224 | ||
325 | if (fe->ops.i2c_gate_ctrl) | 225 | if (fe->ops.i2c_gate_ctrl) |
326 | fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ | 226 | fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ |
327 | 227 | ||
328 | if (!ret) | 228 | if (ret) |
329 | dev_dbg(&priv->i2c->dev, "%s: chip id=%02x\n", __func__, val); | 229 | goto err; |
330 | if (ret || val != 0xc7) { | 230 | |
331 | kfree(priv); | 231 | switch (chip_id) { |
332 | return NULL; | 232 | case 0xc7: |
233 | version = "M"; /* master */ | ||
234 | break; | ||
235 | case 0x47: | ||
236 | version = "S"; /* slave */ | ||
237 | break; | ||
238 | default: | ||
239 | ret = -ENODEV; | ||
240 | goto err; | ||
333 | } | 241 | } |
334 | 242 | ||
335 | dev_info(&priv->i2c->dev, | 243 | dev_info(&dev->client->dev, |
336 | "%s: NXP TDA18212HN successfully identified\n", | 244 | "NXP TDA18212HN/%s successfully identified\n", version); |
337 | KBUILD_MODNAME); | ||
338 | 245 | ||
246 | fe->tuner_priv = dev; | ||
339 | memcpy(&fe->ops.tuner_ops, &tda18212_tuner_ops, | 247 | memcpy(&fe->ops.tuner_ops, &tda18212_tuner_ops, |
340 | sizeof(struct dvb_tuner_ops)); | 248 | sizeof(struct dvb_tuner_ops)); |
249 | i2c_set_clientdata(client, dev); | ||
341 | 250 | ||
342 | return fe; | 251 | return 0; |
252 | err: | ||
253 | dev_dbg(&client->dev, "failed=%d\n", ret); | ||
254 | kfree(dev); | ||
255 | return ret; | ||
343 | } | 256 | } |
344 | EXPORT_SYMBOL(tda18212_attach); | 257 | |
258 | static int tda18212_remove(struct i2c_client *client) | ||
259 | { | ||
260 | struct tda18212_dev *dev = i2c_get_clientdata(client); | ||
261 | struct dvb_frontend *fe = dev->cfg.fe; | ||
262 | |||
263 | dev_dbg(&client->dev, "\n"); | ||
264 | |||
265 | memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); | ||
266 | fe->tuner_priv = NULL; | ||
267 | kfree(dev); | ||
268 | |||
269 | return 0; | ||
270 | } | ||
271 | |||
272 | static const struct i2c_device_id tda18212_id[] = { | ||
273 | {"tda18212", 0}, | ||
274 | {} | ||
275 | }; | ||
276 | MODULE_DEVICE_TABLE(i2c, tda18212_id); | ||
277 | |||
278 | static struct i2c_driver tda18212_driver = { | ||
279 | .driver = { | ||
280 | .owner = THIS_MODULE, | ||
281 | .name = "tda18212", | ||
282 | }, | ||
283 | .probe = tda18212_probe, | ||
284 | .remove = tda18212_remove, | ||
285 | .id_table = tda18212_id, | ||
286 | }; | ||
287 | |||
288 | module_i2c_driver(tda18212_driver); | ||
345 | 289 | ||
346 | MODULE_DESCRIPTION("NXP TDA18212HN silicon tuner driver"); | 290 | MODULE_DESCRIPTION("NXP TDA18212HN silicon tuner driver"); |
347 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); | 291 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
diff --git a/drivers/media/tuners/tda18212.h b/drivers/media/tuners/tda18212.h index c36b49e4b274..e58c9096d79c 100644 --- a/drivers/media/tuners/tda18212.h +++ b/drivers/media/tuners/tda18212.h | |||
@@ -25,8 +25,6 @@ | |||
25 | #include "dvb_frontend.h" | 25 | #include "dvb_frontend.h" |
26 | 26 | ||
27 | struct tda18212_config { | 27 | struct tda18212_config { |
28 | u8 i2c_address; | ||
29 | |||
30 | u16 if_dvbt_6; | 28 | u16 if_dvbt_6; |
31 | u16 if_dvbt_7; | 29 | u16 if_dvbt_7; |
32 | u16 if_dvbt_8; | 30 | u16 if_dvbt_8; |
@@ -37,18 +35,11 @@ struct tda18212_config { | |||
37 | u16 if_dvbc; | 35 | u16 if_dvbc; |
38 | u16 if_atsc_vsb; | 36 | u16 if_atsc_vsb; |
39 | u16 if_atsc_qam; | 37 | u16 if_atsc_qam; |
40 | }; | ||
41 | 38 | ||
42 | #if IS_ENABLED(CONFIG_MEDIA_TUNER_TDA18212) | 39 | /* |
43 | extern struct dvb_frontend *tda18212_attach(struct dvb_frontend *fe, | 40 | * pointer to DVB frontend |
44 | struct i2c_adapter *i2c, struct tda18212_config *cfg); | 41 | */ |
45 | #else | 42 | struct dvb_frontend *fe; |
46 | static inline struct dvb_frontend *tda18212_attach(struct dvb_frontend *fe, | 43 | }; |
47 | struct i2c_adapter *i2c, struct tda18212_config *cfg) | ||
48 | { | ||
49 | printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); | ||
50 | return NULL; | ||
51 | } | ||
52 | #endif | ||
53 | 44 | ||
54 | #endif | 45 | #endif |
diff --git a/drivers/media/tuners/tda18271-common.c b/drivers/media/tuners/tda18271-common.c index 18c77afe2e4f..86e5e3110118 100644 --- a/drivers/media/tuners/tda18271-common.c +++ b/drivers/media/tuners/tda18271-common.c | |||
@@ -714,12 +714,11 @@ fail: | |||
714 | return ret; | 714 | return ret; |
715 | } | 715 | } |
716 | 716 | ||
717 | int _tda_printk(struct tda18271_priv *state, const char *level, | 717 | void _tda_printk(struct tda18271_priv *state, const char *level, |
718 | const char *func, const char *fmt, ...) | 718 | const char *func, const char *fmt, ...) |
719 | { | 719 | { |
720 | struct va_format vaf; | 720 | struct va_format vaf; |
721 | va_list args; | 721 | va_list args; |
722 | int rtn; | ||
723 | 722 | ||
724 | va_start(args, fmt); | 723 | va_start(args, fmt); |
725 | 724 | ||
@@ -727,15 +726,13 @@ int _tda_printk(struct tda18271_priv *state, const char *level, | |||
727 | vaf.va = &args; | 726 | vaf.va = &args; |
728 | 727 | ||
729 | if (state) | 728 | if (state) |
730 | rtn = printk("%s%s: [%d-%04x|%c] %pV", | 729 | printk("%s%s: [%d-%04x|%c] %pV", |
731 | level, func, i2c_adapter_id(state->i2c_props.adap), | 730 | level, func, i2c_adapter_id(state->i2c_props.adap), |
732 | state->i2c_props.addr, | 731 | state->i2c_props.addr, |
733 | (state->role == TDA18271_MASTER) ? 'M' : 'S', | 732 | (state->role == TDA18271_MASTER) ? 'M' : 'S', |
734 | &vaf); | 733 | &vaf); |
735 | else | 734 | else |
736 | rtn = printk("%s%s: %pV", level, func, &vaf); | 735 | printk("%s%s: %pV", level, func, &vaf); |
737 | 736 | ||
738 | va_end(args); | 737 | va_end(args); |
739 | |||
740 | return rtn; | ||
741 | } | 738 | } |
diff --git a/drivers/media/tuners/tda18271-priv.h b/drivers/media/tuners/tda18271-priv.h index 454c152ccaa0..b36a7b754772 100644 --- a/drivers/media/tuners/tda18271-priv.h +++ b/drivers/media/tuners/tda18271-priv.h | |||
@@ -139,8 +139,8 @@ extern int tda18271_debug; | |||
139 | #define DBG_CAL 16 | 139 | #define DBG_CAL 16 |
140 | 140 | ||
141 | __attribute__((format(printf, 4, 5))) | 141 | __attribute__((format(printf, 4, 5))) |
142 | int _tda_printk(struct tda18271_priv *state, const char *level, | 142 | void _tda_printk(struct tda18271_priv *state, const char *level, |
143 | const char *func, const char *fmt, ...); | 143 | const char *func, const char *fmt, ...); |
144 | 144 | ||
145 | #define tda_printk(st, lvl, fmt, arg...) \ | 145 | #define tda_printk(st, lvl, fmt, arg...) \ |
146 | _tda_printk(st, lvl, __func__, fmt, ##arg) | 146 | _tda_printk(st, lvl, __func__, fmt, ##arg) |
diff --git a/drivers/media/tuners/tuner-xc2028.c b/drivers/media/tuners/tuner-xc2028.c index 565eeebb3aeb..d12f5e4ad8bf 100644 --- a/drivers/media/tuners/tuner-xc2028.c +++ b/drivers/media/tuners/tuner-xc2028.c | |||
@@ -178,67 +178,67 @@ static int xc2028_get_reg(struct xc2028_data *priv, u16 reg, u16 *val) | |||
178 | #define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0) | 178 | #define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0) |
179 | static void dump_firm_type_and_int_freq(unsigned int type, u16 int_freq) | 179 | static void dump_firm_type_and_int_freq(unsigned int type, u16 int_freq) |
180 | { | 180 | { |
181 | if (type & BASE) | 181 | if (type & BASE) |
182 | printk("BASE "); | 182 | printk("BASE "); |
183 | if (type & INIT1) | 183 | if (type & INIT1) |
184 | printk("INIT1 "); | 184 | printk("INIT1 "); |
185 | if (type & F8MHZ) | 185 | if (type & F8MHZ) |
186 | printk("F8MHZ "); | 186 | printk("F8MHZ "); |
187 | if (type & MTS) | 187 | if (type & MTS) |
188 | printk("MTS "); | 188 | printk("MTS "); |
189 | if (type & D2620) | 189 | if (type & D2620) |
190 | printk("D2620 "); | 190 | printk("D2620 "); |
191 | if (type & D2633) | 191 | if (type & D2633) |
192 | printk("D2633 "); | 192 | printk("D2633 "); |
193 | if (type & DTV6) | 193 | if (type & DTV6) |
194 | printk("DTV6 "); | 194 | printk("DTV6 "); |
195 | if (type & QAM) | 195 | if (type & QAM) |
196 | printk("QAM "); | 196 | printk("QAM "); |
197 | if (type & DTV7) | 197 | if (type & DTV7) |
198 | printk("DTV7 "); | 198 | printk("DTV7 "); |
199 | if (type & DTV78) | 199 | if (type & DTV78) |
200 | printk("DTV78 "); | 200 | printk("DTV78 "); |
201 | if (type & DTV8) | 201 | if (type & DTV8) |
202 | printk("DTV8 "); | 202 | printk("DTV8 "); |
203 | if (type & FM) | 203 | if (type & FM) |
204 | printk("FM "); | 204 | printk("FM "); |
205 | if (type & INPUT1) | 205 | if (type & INPUT1) |
206 | printk("INPUT1 "); | 206 | printk("INPUT1 "); |
207 | if (type & LCD) | 207 | if (type & LCD) |
208 | printk("LCD "); | 208 | printk("LCD "); |
209 | if (type & NOGD) | 209 | if (type & NOGD) |
210 | printk("NOGD "); | 210 | printk("NOGD "); |
211 | if (type & MONO) | 211 | if (type & MONO) |
212 | printk("MONO "); | 212 | printk("MONO "); |
213 | if (type & ATSC) | 213 | if (type & ATSC) |
214 | printk("ATSC "); | 214 | printk("ATSC "); |
215 | if (type & IF) | 215 | if (type & IF) |
216 | printk("IF "); | 216 | printk("IF "); |
217 | if (type & LG60) | 217 | if (type & LG60) |
218 | printk("LG60 "); | 218 | printk("LG60 "); |
219 | if (type & ATI638) | 219 | if (type & ATI638) |
220 | printk("ATI638 "); | 220 | printk("ATI638 "); |
221 | if (type & OREN538) | 221 | if (type & OREN538) |
222 | printk("OREN538 "); | 222 | printk("OREN538 "); |
223 | if (type & OREN36) | 223 | if (type & OREN36) |
224 | printk("OREN36 "); | 224 | printk("OREN36 "); |
225 | if (type & TOYOTA388) | 225 | if (type & TOYOTA388) |
226 | printk("TOYOTA388 "); | 226 | printk("TOYOTA388 "); |
227 | if (type & TOYOTA794) | 227 | if (type & TOYOTA794) |
228 | printk("TOYOTA794 "); | 228 | printk("TOYOTA794 "); |
229 | if (type & DIBCOM52) | 229 | if (type & DIBCOM52) |
230 | printk("DIBCOM52 "); | 230 | printk("DIBCOM52 "); |
231 | if (type & ZARLINK456) | 231 | if (type & ZARLINK456) |
232 | printk("ZARLINK456 "); | 232 | printk("ZARLINK456 "); |
233 | if (type & CHINA) | 233 | if (type & CHINA) |
234 | printk("CHINA "); | 234 | printk("CHINA "); |
235 | if (type & F6MHZ) | 235 | if (type & F6MHZ) |
236 | printk("F6MHZ "); | 236 | printk("F6MHZ "); |
237 | if (type & INPUT2) | 237 | if (type & INPUT2) |
238 | printk("INPUT2 "); | 238 | printk("INPUT2 "); |
239 | if (type & SCODE) | 239 | if (type & SCODE) |
240 | printk("SCODE "); | 240 | printk("SCODE "); |
241 | if (type & HAS_IF) | 241 | if (type & HAS_IF) |
242 | printk("HAS_IF_%d ", int_freq); | 242 | printk("HAS_IF_%d ", int_freq); |
243 | } | 243 | } |
244 | 244 | ||
diff --git a/drivers/media/tuners/tuner_it913x.c b/drivers/media/tuners/tuner_it913x.c deleted file mode 100644 index 3d83c425bccf..000000000000 --- a/drivers/media/tuners/tuner_it913x.c +++ /dev/null | |||
@@ -1,453 +0,0 @@ | |||
1 | /* | ||
2 | * ITE Tech IT9137 silicon tuner driver | ||
3 | * | ||
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. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.= | ||
21 | */ | ||
22 | |||
23 | #include "tuner_it913x_priv.h" | ||
24 | |||
25 | struct it913x_state { | ||
26 | struct i2c_adapter *i2c_adap; | ||
27 | u8 i2c_addr; | ||
28 | u8 chip_ver; | ||
29 | u8 tuner_type; | ||
30 | u8 firmware_ver; | ||
31 | u16 tun_xtal; | ||
32 | u8 tun_fdiv; | ||
33 | u8 tun_clk_mode; | ||
34 | u32 tun_fn_min; | ||
35 | }; | ||
36 | |||
37 | /* read multiple registers */ | ||
38 | static int it913x_rd_regs(struct it913x_state *state, | ||
39 | u32 reg, u8 *data, u8 count) | ||
40 | { | ||
41 | int ret; | ||
42 | u8 b[3]; | ||
43 | struct i2c_msg msg[2] = { | ||
44 | { .addr = state->i2c_addr, .flags = 0, | ||
45 | .buf = b, .len = sizeof(b) }, | ||
46 | { .addr = state->i2c_addr, .flags = I2C_M_RD, | ||
47 | .buf = data, .len = count } | ||
48 | }; | ||
49 | b[0] = (u8)(reg >> 16) & 0xff; | ||
50 | b[1] = (u8)(reg >> 8) & 0xff; | ||
51 | b[2] = (u8) reg & 0xff; | ||
52 | b[0] |= 0x80; /* All reads from demodulator */ | ||
53 | |||
54 | ret = i2c_transfer(state->i2c_adap, msg, 2); | ||
55 | |||
56 | return ret; | ||
57 | } | ||
58 | |||
59 | /* read single register */ | ||
60 | static int it913x_rd_reg(struct it913x_state *state, u32 reg) | ||
61 | { | ||
62 | int ret; | ||
63 | u8 b[1]; | ||
64 | ret = it913x_rd_regs(state, reg, &b[0], sizeof(b)); | ||
65 | return (ret < 0) ? -ENODEV : b[0]; | ||
66 | } | ||
67 | |||
68 | /* write multiple registers */ | ||
69 | static int it913x_wr_regs(struct it913x_state *state, | ||
70 | u8 pro, u32 reg, u8 buf[], u8 count) | ||
71 | { | ||
72 | u8 b[256]; | ||
73 | struct i2c_msg msg[1] = { | ||
74 | { .addr = state->i2c_addr, .flags = 0, | ||
75 | .buf = b, .len = 3 + count } | ||
76 | }; | ||
77 | int ret; | ||
78 | b[0] = (u8)(reg >> 16) & 0xff; | ||
79 | b[1] = (u8)(reg >> 8) & 0xff; | ||
80 | b[2] = (u8) reg & 0xff; | ||
81 | memcpy(&b[3], buf, count); | ||
82 | |||
83 | if (pro == PRO_DMOD) | ||
84 | b[0] |= 0x80; | ||
85 | |||
86 | ret = i2c_transfer(state->i2c_adap, msg, 1); | ||
87 | |||
88 | if (ret < 0) | ||
89 | return -EIO; | ||
90 | |||
91 | return 0; | ||
92 | } | ||
93 | |||
94 | /* write single register */ | ||
95 | static int it913x_wr_reg(struct it913x_state *state, | ||
96 | u8 pro, u32 reg, u32 data) | ||
97 | { | ||
98 | int ret; | ||
99 | u8 b[4]; | ||
100 | u8 s; | ||
101 | |||
102 | b[0] = data >> 24; | ||
103 | b[1] = (data >> 16) & 0xff; | ||
104 | b[2] = (data >> 8) & 0xff; | ||
105 | b[3] = data & 0xff; | ||
106 | /* expand write as needed */ | ||
107 | if (data < 0x100) | ||
108 | s = 3; | ||
109 | else if (data < 0x1000) | ||
110 | s = 2; | ||
111 | else if (data < 0x100000) | ||
112 | s = 1; | ||
113 | else | ||
114 | s = 0; | ||
115 | |||
116 | ret = it913x_wr_regs(state, pro, reg, &b[s], sizeof(b) - s); | ||
117 | |||
118 | return ret; | ||
119 | } | ||
120 | |||
121 | static int it913x_script_loader(struct it913x_state *state, | ||
122 | struct it913xset *loadscript) | ||
123 | { | ||
124 | int ret, i; | ||
125 | if (loadscript == NULL) | ||
126 | return -EINVAL; | ||
127 | |||
128 | for (i = 0; i < 1000; ++i) { | ||
129 | if (loadscript[i].pro == 0xff) | ||
130 | break; | ||
131 | ret = it913x_wr_regs(state, loadscript[i].pro, | ||
132 | loadscript[i].address, | ||
133 | loadscript[i].reg, loadscript[i].count); | ||
134 | if (ret < 0) | ||
135 | return -ENODEV; | ||
136 | } | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | static int it913x_init(struct dvb_frontend *fe) | ||
141 | { | ||
142 | struct it913x_state *state = fe->tuner_priv; | ||
143 | int ret, i, reg; | ||
144 | u8 val, nv_val; | ||
145 | u8 nv[] = {48, 32, 24, 16, 12, 8, 6, 4, 2}; | ||
146 | u8 b[2]; | ||
147 | |||
148 | reg = it913x_rd_reg(state, 0xec86); | ||
149 | switch (reg) { | ||
150 | case 0: | ||
151 | state->tun_clk_mode = reg; | ||
152 | state->tun_xtal = 2000; | ||
153 | state->tun_fdiv = 3; | ||
154 | val = 16; | ||
155 | break; | ||
156 | case -ENODEV: | ||
157 | return -ENODEV; | ||
158 | case 1: | ||
159 | default: | ||
160 | state->tun_clk_mode = reg; | ||
161 | state->tun_xtal = 640; | ||
162 | state->tun_fdiv = 1; | ||
163 | val = 6; | ||
164 | break; | ||
165 | } | ||
166 | |||
167 | reg = it913x_rd_reg(state, 0xed03); | ||
168 | |||
169 | if (reg < 0) | ||
170 | return -ENODEV; | ||
171 | else if (reg < ARRAY_SIZE(nv)) | ||
172 | nv_val = nv[reg]; | ||
173 | else | ||
174 | nv_val = 2; | ||
175 | |||
176 | for (i = 0; i < 50; i++) { | ||
177 | ret = it913x_rd_regs(state, 0xed23, &b[0], sizeof(b)); | ||
178 | reg = (b[1] << 8) + b[0]; | ||
179 | if (reg > 0) | ||
180 | break; | ||
181 | if (ret < 0) | ||
182 | return -ENODEV; | ||
183 | udelay(2000); | ||
184 | } | ||
185 | state->tun_fn_min = state->tun_xtal * reg; | ||
186 | state->tun_fn_min /= (state->tun_fdiv * nv_val); | ||
187 | dev_dbg(&state->i2c_adap->dev, "%s: Tuner fn_min %d\n", __func__, | ||
188 | state->tun_fn_min); | ||
189 | |||
190 | if (state->chip_ver > 1) | ||
191 | msleep(50); | ||
192 | else { | ||
193 | for (i = 0; i < 50; i++) { | ||
194 | reg = it913x_rd_reg(state, 0xec82); | ||
195 | if (reg > 0) | ||
196 | break; | ||
197 | if (reg < 0) | ||
198 | return -ENODEV; | ||
199 | udelay(2000); | ||
200 | } | ||
201 | } | ||
202 | |||
203 | /* Power Up Tuner - common all versions */ | ||
204 | ret = it913x_wr_reg(state, PRO_DMOD, 0xec40, 0x1); | ||
205 | ret |= it913x_wr_reg(state, PRO_DMOD, 0xfba8, 0x0); | ||
206 | ret |= it913x_wr_reg(state, PRO_DMOD, 0xec57, 0x0); | ||
207 | ret |= it913x_wr_reg(state, PRO_DMOD, 0xec58, 0x0); | ||
208 | |||
209 | return it913x_wr_reg(state, PRO_DMOD, 0xed81, val); | ||
210 | } | ||
211 | |||
212 | static int it9137_set_params(struct dvb_frontend *fe) | ||
213 | { | ||
214 | struct it913x_state *state = fe->tuner_priv; | ||
215 | struct it913xset *set_tuner = set_it9137_template; | ||
216 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; | ||
217 | u32 bandwidth = p->bandwidth_hz; | ||
218 | u32 frequency_m = p->frequency; | ||
219 | int ret, reg; | ||
220 | u32 frequency = frequency_m / 1000; | ||
221 | u32 freq, temp_f, tmp; | ||
222 | u16 iqik_m_cal; | ||
223 | u16 n_div; | ||
224 | u8 n; | ||
225 | u8 l_band; | ||
226 | u8 lna_band; | ||
227 | u8 bw; | ||
228 | |||
229 | if (state->firmware_ver == 1) | ||
230 | set_tuner = set_it9135_template; | ||
231 | else | ||
232 | set_tuner = set_it9137_template; | ||
233 | |||
234 | dev_dbg(&state->i2c_adap->dev, "%s: Tuner Frequency %d Bandwidth %d\n", | ||
235 | __func__, frequency, bandwidth); | ||
236 | |||
237 | if (frequency >= 51000 && frequency <= 440000) { | ||
238 | l_band = 0; | ||
239 | lna_band = 0; | ||
240 | } else if (frequency > 440000 && frequency <= 484000) { | ||
241 | l_band = 1; | ||
242 | lna_band = 1; | ||
243 | } else if (frequency > 484000 && frequency <= 533000) { | ||
244 | l_band = 1; | ||
245 | lna_band = 2; | ||
246 | } else if (frequency > 533000 && frequency <= 587000) { | ||
247 | l_band = 1; | ||
248 | lna_band = 3; | ||
249 | } else if (frequency > 587000 && frequency <= 645000) { | ||
250 | l_band = 1; | ||
251 | lna_band = 4; | ||
252 | } else if (frequency > 645000 && frequency <= 710000) { | ||
253 | l_band = 1; | ||
254 | lna_band = 5; | ||
255 | } else if (frequency > 710000 && frequency <= 782000) { | ||
256 | l_band = 1; | ||
257 | lna_band = 6; | ||
258 | } else if (frequency > 782000 && frequency <= 860000) { | ||
259 | l_band = 1; | ||
260 | lna_band = 7; | ||
261 | } else if (frequency > 1450000 && frequency <= 1492000) { | ||
262 | l_band = 1; | ||
263 | lna_band = 0; | ||
264 | } else if (frequency > 1660000 && frequency <= 1685000) { | ||
265 | l_band = 1; | ||
266 | lna_band = 1; | ||
267 | } else | ||
268 | return -EINVAL; | ||
269 | set_tuner[0].reg[0] = lna_band; | ||
270 | |||
271 | switch (bandwidth) { | ||
272 | case 5000000: | ||
273 | bw = 0; | ||
274 | break; | ||
275 | case 6000000: | ||
276 | bw = 2; | ||
277 | break; | ||
278 | case 7000000: | ||
279 | bw = 4; | ||
280 | break; | ||
281 | default: | ||
282 | case 8000000: | ||
283 | bw = 6; | ||
284 | break; | ||
285 | } | ||
286 | |||
287 | set_tuner[1].reg[0] = bw; | ||
288 | set_tuner[2].reg[0] = 0xa0 | (l_band << 3); | ||
289 | |||
290 | if (frequency > 53000 && frequency <= 74000) { | ||
291 | n_div = 48; | ||
292 | n = 0; | ||
293 | } else if (frequency > 74000 && frequency <= 111000) { | ||
294 | n_div = 32; | ||
295 | n = 1; | ||
296 | } else if (frequency > 111000 && frequency <= 148000) { | ||
297 | n_div = 24; | ||
298 | n = 2; | ||
299 | } else if (frequency > 148000 && frequency <= 222000) { | ||
300 | n_div = 16; | ||
301 | n = 3; | ||
302 | } else if (frequency > 222000 && frequency <= 296000) { | ||
303 | n_div = 12; | ||
304 | n = 4; | ||
305 | } else if (frequency > 296000 && frequency <= 445000) { | ||
306 | n_div = 8; | ||
307 | n = 5; | ||
308 | } else if (frequency > 445000 && frequency <= state->tun_fn_min) { | ||
309 | n_div = 6; | ||
310 | n = 6; | ||
311 | } else if (frequency > state->tun_fn_min && frequency <= 950000) { | ||
312 | n_div = 4; | ||
313 | n = 7; | ||
314 | } else if (frequency > 1450000 && frequency <= 1680000) { | ||
315 | n_div = 2; | ||
316 | n = 0; | ||
317 | } else | ||
318 | return -EINVAL; | ||
319 | |||
320 | reg = it913x_rd_reg(state, 0xed81); | ||
321 | iqik_m_cal = (u16)reg * n_div; | ||
322 | |||
323 | if (reg < 0x20) { | ||
324 | if (state->tun_clk_mode == 0) | ||
325 | iqik_m_cal = (iqik_m_cal * 9) >> 5; | ||
326 | else | ||
327 | iqik_m_cal >>= 1; | ||
328 | } else { | ||
329 | iqik_m_cal = 0x40 - iqik_m_cal; | ||
330 | if (state->tun_clk_mode == 0) | ||
331 | iqik_m_cal = ~((iqik_m_cal * 9) >> 5); | ||
332 | else | ||
333 | iqik_m_cal = ~(iqik_m_cal >> 1); | ||
334 | } | ||
335 | |||
336 | temp_f = frequency * (u32)n_div * (u32)state->tun_fdiv; | ||
337 | freq = temp_f / state->tun_xtal; | ||
338 | tmp = freq * state->tun_xtal; | ||
339 | |||
340 | if ((temp_f - tmp) >= (state->tun_xtal >> 1)) | ||
341 | freq++; | ||
342 | |||
343 | freq += (u32) n << 13; | ||
344 | /* Frequency OMEGA_IQIK_M_CAL_MID*/ | ||
345 | temp_f = freq + (u32)iqik_m_cal; | ||
346 | |||
347 | set_tuner[3].reg[0] = temp_f & 0xff; | ||
348 | set_tuner[4].reg[0] = (temp_f >> 8) & 0xff; | ||
349 | |||
350 | dev_dbg(&state->i2c_adap->dev, "%s: High Frequency = %04x\n", | ||
351 | __func__, temp_f); | ||
352 | |||
353 | /* Lower frequency */ | ||
354 | set_tuner[5].reg[0] = freq & 0xff; | ||
355 | set_tuner[6].reg[0] = (freq >> 8) & 0xff; | ||
356 | |||
357 | dev_dbg(&state->i2c_adap->dev, "%s: low Frequency = %04x\n", | ||
358 | __func__, freq); | ||
359 | |||
360 | ret = it913x_script_loader(state, set_tuner); | ||
361 | |||
362 | return (ret < 0) ? -ENODEV : 0; | ||
363 | } | ||
364 | |||
365 | /* Power sequence */ | ||
366 | /* Power Up Tuner on -> Frontend suspend off -> Tuner clk on */ | ||
367 | /* Power Down Frontend suspend on -> Tuner clk off -> Tuner off */ | ||
368 | |||
369 | static int it913x_sleep(struct dvb_frontend *fe) | ||
370 | { | ||
371 | struct it913x_state *state = fe->tuner_priv; | ||
372 | return it913x_script_loader(state, it9137_tuner_off); | ||
373 | } | ||
374 | |||
375 | static int it913x_release(struct dvb_frontend *fe) | ||
376 | { | ||
377 | kfree(fe->tuner_priv); | ||
378 | return 0; | ||
379 | } | ||
380 | |||
381 | static const struct dvb_tuner_ops it913x_tuner_ops = { | ||
382 | .info = { | ||
383 | .name = "ITE Tech IT913X", | ||
384 | .frequency_min = 174000000, | ||
385 | .frequency_max = 862000000, | ||
386 | }, | ||
387 | |||
388 | .release = it913x_release, | ||
389 | |||
390 | .init = it913x_init, | ||
391 | .sleep = it913x_sleep, | ||
392 | .set_params = it9137_set_params, | ||
393 | }; | ||
394 | |||
395 | struct dvb_frontend *it913x_attach(struct dvb_frontend *fe, | ||
396 | struct i2c_adapter *i2c_adap, u8 i2c_addr, u8 config) | ||
397 | { | ||
398 | struct it913x_state *state = NULL; | ||
399 | int ret; | ||
400 | |||
401 | /* allocate memory for the internal state */ | ||
402 | state = kzalloc(sizeof(struct it913x_state), GFP_KERNEL); | ||
403 | if (state == NULL) | ||
404 | return NULL; | ||
405 | |||
406 | state->i2c_adap = i2c_adap; | ||
407 | state->i2c_addr = i2c_addr; | ||
408 | |||
409 | switch (config) { | ||
410 | case AF9033_TUNER_IT9135_38: | ||
411 | case AF9033_TUNER_IT9135_51: | ||
412 | case AF9033_TUNER_IT9135_52: | ||
413 | state->chip_ver = 0x01; | ||
414 | break; | ||
415 | case AF9033_TUNER_IT9135_60: | ||
416 | case AF9033_TUNER_IT9135_61: | ||
417 | case AF9033_TUNER_IT9135_62: | ||
418 | state->chip_ver = 0x02; | ||
419 | break; | ||
420 | default: | ||
421 | dev_dbg(&i2c_adap->dev, | ||
422 | "%s: invalid config=%02x\n", __func__, config); | ||
423 | goto error; | ||
424 | } | ||
425 | |||
426 | state->tuner_type = config; | ||
427 | state->firmware_ver = 1; | ||
428 | |||
429 | /* tuner RF initial */ | ||
430 | ret = it913x_wr_reg(state, PRO_DMOD, 0xec4c, 0x68); | ||
431 | if (ret < 0) | ||
432 | goto error; | ||
433 | |||
434 | fe->tuner_priv = state; | ||
435 | memcpy(&fe->ops.tuner_ops, &it913x_tuner_ops, | ||
436 | sizeof(struct dvb_tuner_ops)); | ||
437 | |||
438 | dev_info(&i2c_adap->dev, | ||
439 | "%s: ITE Tech IT913X successfully attached\n", | ||
440 | KBUILD_MODNAME); | ||
441 | dev_dbg(&i2c_adap->dev, "%s: config=%02x chip_ver=%02x\n", | ||
442 | __func__, config, state->chip_ver); | ||
443 | |||
444 | return fe; | ||
445 | error: | ||
446 | kfree(state); | ||
447 | return NULL; | ||
448 | } | ||
449 | EXPORT_SYMBOL(it913x_attach); | ||
450 | |||
451 | MODULE_DESCRIPTION("ITE Tech IT913X silicon tuner driver"); | ||
452 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); | ||
453 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/tuners/tuner_it913x_priv.h b/drivers/media/tuners/tuner_it913x_priv.h deleted file mode 100644 index ce652108aa5d..000000000000 --- a/drivers/media/tuners/tuner_it913x_priv.h +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | /* | ||
2 | * ITE Tech IT9137 silicon tuner driver | ||
3 | * | ||
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. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.= | ||
21 | */ | ||
22 | |||
23 | #ifndef IT913X_PRIV_H | ||
24 | #define IT913X_PRIV_H | ||
25 | |||
26 | #include "tuner_it913x.h" | ||
27 | #include "af9033.h" | ||
28 | |||
29 | #define PRO_LINK 0x0 | ||
30 | #define PRO_DMOD 0x1 | ||
31 | #define TRIGGER_OFSM 0x0000 | ||
32 | |||
33 | struct it913xset { u32 pro; | ||
34 | u32 address; | ||
35 | u8 reg[15]; | ||
36 | u8 count; | ||
37 | }; | ||
38 | |||
39 | /* Tuner setting scripts (still keeping it9137) */ | ||
40 | static struct it913xset it9137_tuner_off[] = { | ||
41 | {PRO_DMOD, 0xfba8, {0x01}, 0x01}, /* Tuner Clock Off */ | ||
42 | {PRO_DMOD, 0xec40, {0x00}, 0x01}, /* Power Down Tuner */ | ||
43 | {PRO_DMOD, 0xec02, {0x3f, 0x1f, 0x3f, 0x3f}, 0x04}, | ||
44 | {PRO_DMOD, 0xec06, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
45 | 0x00, 0x00, 0x00, 0x00}, 0x0c}, | ||
46 | {PRO_DMOD, 0xec12, {0x00, 0x00, 0x00, 0x00}, 0x04}, | ||
47 | {PRO_DMOD, 0xec17, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
48 | 0x00}, 0x09}, | ||
49 | {PRO_DMOD, 0xec22, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
50 | 0x00, 0x00}, 0x0a}, | ||
51 | {PRO_DMOD, 0xec20, {0x00}, 0x01}, | ||
52 | {PRO_DMOD, 0xec3f, {0x01}, 0x01}, | ||
53 | {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */ | ||
54 | }; | ||
55 | |||
56 | static struct it913xset set_it9135_template[] = { | ||
57 | {PRO_DMOD, 0xee06, {0x00}, 0x01}, | ||
58 | {PRO_DMOD, 0xec56, {0x00}, 0x01}, | ||
59 | {PRO_DMOD, 0xec4c, {0x00}, 0x01}, | ||
60 | {PRO_DMOD, 0xec4d, {0x00}, 0x01}, | ||
61 | {PRO_DMOD, 0xec4e, {0x00}, 0x01}, | ||
62 | {PRO_DMOD, 0x011e, {0x00}, 0x01}, /* Older Devices */ | ||
63 | {PRO_DMOD, 0x011f, {0x00}, 0x01}, | ||
64 | {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */ | ||
65 | }; | ||
66 | |||
67 | static struct it913xset set_it9137_template[] = { | ||
68 | {PRO_DMOD, 0xee06, {0x00}, 0x01}, | ||
69 | {PRO_DMOD, 0xec56, {0x00}, 0x01}, | ||
70 | {PRO_DMOD, 0xec4c, {0x00}, 0x01}, | ||
71 | {PRO_DMOD, 0xec4d, {0x00}, 0x01}, | ||
72 | {PRO_DMOD, 0xec4e, {0x00}, 0x01}, | ||
73 | {PRO_DMOD, 0xec4f, {0x00}, 0x01}, | ||
74 | {PRO_DMOD, 0xec50, {0x00}, 0x01}, | ||
75 | {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */ | ||
76 | }; | ||
77 | |||
78 | #endif | ||
diff --git a/drivers/media/tuners/xc4000.c b/drivers/media/tuners/xc4000.c index f9ab79e3432d..219ebafae70f 100644 --- a/drivers/media/tuners/xc4000.c +++ b/drivers/media/tuners/xc4000.c | |||
@@ -569,67 +569,67 @@ static int xc4000_readreg(struct xc4000_priv *priv, u16 reg, u16 *val) | |||
569 | #define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0) | 569 | #define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0) |
570 | static void dump_firm_type_and_int_freq(unsigned int type, u16 int_freq) | 570 | static void dump_firm_type_and_int_freq(unsigned int type, u16 int_freq) |
571 | { | 571 | { |
572 | if (type & BASE) | 572 | if (type & BASE) |
573 | printk(KERN_CONT "BASE "); | 573 | printk(KERN_CONT "BASE "); |
574 | if (type & INIT1) | 574 | if (type & INIT1) |
575 | printk(KERN_CONT "INIT1 "); | 575 | printk(KERN_CONT "INIT1 "); |
576 | if (type & F8MHZ) | 576 | if (type & F8MHZ) |
577 | printk(KERN_CONT "F8MHZ "); | 577 | printk(KERN_CONT "F8MHZ "); |
578 | if (type & MTS) | 578 | if (type & MTS) |
579 | printk(KERN_CONT "MTS "); | 579 | printk(KERN_CONT "MTS "); |
580 | if (type & D2620) | 580 | if (type & D2620) |
581 | printk(KERN_CONT "D2620 "); | 581 | printk(KERN_CONT "D2620 "); |
582 | if (type & D2633) | 582 | if (type & D2633) |
583 | printk(KERN_CONT "D2633 "); | 583 | printk(KERN_CONT "D2633 "); |
584 | if (type & DTV6) | 584 | if (type & DTV6) |
585 | printk(KERN_CONT "DTV6 "); | 585 | printk(KERN_CONT "DTV6 "); |
586 | if (type & QAM) | 586 | if (type & QAM) |
587 | printk(KERN_CONT "QAM "); | 587 | printk(KERN_CONT "QAM "); |
588 | if (type & DTV7) | 588 | if (type & DTV7) |
589 | printk(KERN_CONT "DTV7 "); | 589 | printk(KERN_CONT "DTV7 "); |
590 | if (type & DTV78) | 590 | if (type & DTV78) |
591 | printk(KERN_CONT "DTV78 "); | 591 | printk(KERN_CONT "DTV78 "); |
592 | if (type & DTV8) | 592 | if (type & DTV8) |
593 | printk(KERN_CONT "DTV8 "); | 593 | printk(KERN_CONT "DTV8 "); |
594 | if (type & FM) | 594 | if (type & FM) |
595 | printk(KERN_CONT "FM "); | 595 | printk(KERN_CONT "FM "); |
596 | if (type & INPUT1) | 596 | if (type & INPUT1) |
597 | printk(KERN_CONT "INPUT1 "); | 597 | printk(KERN_CONT "INPUT1 "); |
598 | if (type & LCD) | 598 | if (type & LCD) |
599 | printk(KERN_CONT "LCD "); | 599 | printk(KERN_CONT "LCD "); |
600 | if (type & NOGD) | 600 | if (type & NOGD) |
601 | printk(KERN_CONT "NOGD "); | 601 | printk(KERN_CONT "NOGD "); |
602 | if (type & MONO) | 602 | if (type & MONO) |
603 | printk(KERN_CONT "MONO "); | 603 | printk(KERN_CONT "MONO "); |
604 | if (type & ATSC) | 604 | if (type & ATSC) |
605 | printk(KERN_CONT "ATSC "); | 605 | printk(KERN_CONT "ATSC "); |
606 | if (type & IF) | 606 | if (type & IF) |
607 | printk(KERN_CONT "IF "); | 607 | printk(KERN_CONT "IF "); |
608 | if (type & LG60) | 608 | if (type & LG60) |
609 | printk(KERN_CONT "LG60 "); | 609 | printk(KERN_CONT "LG60 "); |
610 | if (type & ATI638) | 610 | if (type & ATI638) |
611 | printk(KERN_CONT "ATI638 "); | 611 | printk(KERN_CONT "ATI638 "); |
612 | if (type & OREN538) | 612 | if (type & OREN538) |
613 | printk(KERN_CONT "OREN538 "); | 613 | printk(KERN_CONT "OREN538 "); |
614 | if (type & OREN36) | 614 | if (type & OREN36) |
615 | printk(KERN_CONT "OREN36 "); | 615 | printk(KERN_CONT "OREN36 "); |
616 | if (type & TOYOTA388) | 616 | if (type & TOYOTA388) |
617 | printk(KERN_CONT "TOYOTA388 "); | 617 | printk(KERN_CONT "TOYOTA388 "); |
618 | if (type & TOYOTA794) | 618 | if (type & TOYOTA794) |
619 | printk(KERN_CONT "TOYOTA794 "); | 619 | printk(KERN_CONT "TOYOTA794 "); |
620 | if (type & DIBCOM52) | 620 | if (type & DIBCOM52) |
621 | printk(KERN_CONT "DIBCOM52 "); | 621 | printk(KERN_CONT "DIBCOM52 "); |
622 | if (type & ZARLINK456) | 622 | if (type & ZARLINK456) |
623 | printk(KERN_CONT "ZARLINK456 "); | 623 | printk(KERN_CONT "ZARLINK456 "); |
624 | if (type & CHINA) | 624 | if (type & CHINA) |
625 | printk(KERN_CONT "CHINA "); | 625 | printk(KERN_CONT "CHINA "); |
626 | if (type & F6MHZ) | 626 | if (type & F6MHZ) |
627 | printk(KERN_CONT "F6MHZ "); | 627 | printk(KERN_CONT "F6MHZ "); |
628 | if (type & INPUT2) | 628 | if (type & INPUT2) |
629 | printk(KERN_CONT "INPUT2 "); | 629 | printk(KERN_CONT "INPUT2 "); |
630 | if (type & SCODE) | 630 | if (type & SCODE) |
631 | printk(KERN_CONT "SCODE "); | 631 | printk(KERN_CONT "SCODE "); |
632 | if (type & HAS_IF) | 632 | if (type & HAS_IF) |
633 | printk(KERN_CONT "HAS_IF_%d ", int_freq); | 633 | printk(KERN_CONT "HAS_IF_%d ", int_freq); |
634 | } | 634 | } |
635 | 635 | ||
diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c index e135760f7d48..e44c8aba6074 100644 --- a/drivers/media/tuners/xc5000.c +++ b/drivers/media/tuners/xc5000.c | |||
@@ -59,6 +59,7 @@ struct xc5000_priv { | |||
59 | u32 freq_hz, freq_offset; | 59 | u32 freq_hz, freq_offset; |
60 | u32 bandwidth; | 60 | u32 bandwidth; |
61 | u8 video_standard; | 61 | u8 video_standard; |
62 | unsigned int mode; | ||
62 | u8 rf_mode; | 63 | u8 rf_mode; |
63 | u8 radio_input; | 64 | u8 radio_input; |
64 | 65 | ||
@@ -69,6 +70,8 @@ struct xc5000_priv { | |||
69 | 70 | ||
70 | struct dvb_frontend *fe; | 71 | struct dvb_frontend *fe; |
71 | struct delayed_work timer_sleep; | 72 | struct delayed_work timer_sleep; |
73 | |||
74 | const struct firmware *firmware; | ||
72 | }; | 75 | }; |
73 | 76 | ||
74 | /* Misc Defines */ | 77 | /* Misc Defines */ |
@@ -712,9 +715,50 @@ static void xc_debug_dump(struct xc5000_priv *priv) | |||
712 | } | 715 | } |
713 | } | 716 | } |
714 | 717 | ||
715 | static int xc5000_set_params(struct dvb_frontend *fe) | 718 | static int xc5000_tune_digital(struct dvb_frontend *fe) |
719 | { | ||
720 | struct xc5000_priv *priv = fe->tuner_priv; | ||
721 | int ret; | ||
722 | u32 bw = fe->dtv_property_cache.bandwidth_hz; | ||
723 | |||
724 | ret = xc_set_signal_source(priv, priv->rf_mode); | ||
725 | if (ret != 0) { | ||
726 | printk(KERN_ERR | ||
727 | "xc5000: xc_set_signal_source(%d) failed\n", | ||
728 | priv->rf_mode); | ||
729 | return -EREMOTEIO; | ||
730 | } | ||
731 | |||
732 | ret = xc_set_tv_standard(priv, | ||
733 | xc5000_standard[priv->video_standard].video_mode, | ||
734 | xc5000_standard[priv->video_standard].audio_mode, 0); | ||
735 | if (ret != 0) { | ||
736 | printk(KERN_ERR "xc5000: xc_set_tv_standard failed\n"); | ||
737 | return -EREMOTEIO; | ||
738 | } | ||
739 | |||
740 | ret = xc_set_IF_frequency(priv, priv->if_khz); | ||
741 | if (ret != 0) { | ||
742 | printk(KERN_ERR "xc5000: xc_Set_IF_frequency(%d) failed\n", | ||
743 | priv->if_khz); | ||
744 | return -EIO; | ||
745 | } | ||
746 | |||
747 | xc_write_reg(priv, XREG_OUTPUT_AMP, 0x8a); | ||
748 | |||
749 | xc_tune_channel(priv, priv->freq_hz, XC_TUNE_DIGITAL); | ||
750 | |||
751 | if (debug) | ||
752 | xc_debug_dump(priv); | ||
753 | |||
754 | priv->bandwidth = bw; | ||
755 | |||
756 | return 0; | ||
757 | } | ||
758 | |||
759 | static int xc5000_set_digital_params(struct dvb_frontend *fe) | ||
716 | { | 760 | { |
717 | int ret, b; | 761 | int b; |
718 | struct xc5000_priv *priv = fe->tuner_priv; | 762 | struct xc5000_priv *priv = fe->tuner_priv; |
719 | u32 bw = fe->dtv_property_cache.bandwidth_hz; | 763 | u32 bw = fe->dtv_property_cache.bandwidth_hz; |
720 | u32 freq = fe->dtv_property_cache.frequency; | 764 | u32 freq = fe->dtv_property_cache.frequency; |
@@ -794,43 +838,12 @@ static int xc5000_set_params(struct dvb_frontend *fe) | |||
794 | } | 838 | } |
795 | 839 | ||
796 | priv->freq_hz = freq - priv->freq_offset; | 840 | priv->freq_hz = freq - priv->freq_offset; |
841 | priv->mode = V4L2_TUNER_DIGITAL_TV; | ||
797 | 842 | ||
798 | dprintk(1, "%s() frequency=%d (compensated to %d)\n", | 843 | dprintk(1, "%s() frequency=%d (compensated to %d)\n", |
799 | __func__, freq, priv->freq_hz); | 844 | __func__, freq, priv->freq_hz); |
800 | 845 | ||
801 | ret = xc_set_signal_source(priv, priv->rf_mode); | 846 | return xc5000_tune_digital(fe); |
802 | if (ret != 0) { | ||
803 | printk(KERN_ERR | ||
804 | "xc5000: xc_set_signal_source(%d) failed\n", | ||
805 | priv->rf_mode); | ||
806 | return -EREMOTEIO; | ||
807 | } | ||
808 | |||
809 | ret = xc_set_tv_standard(priv, | ||
810 | xc5000_standard[priv->video_standard].video_mode, | ||
811 | xc5000_standard[priv->video_standard].audio_mode, 0); | ||
812 | if (ret != 0) { | ||
813 | printk(KERN_ERR "xc5000: xc_set_tv_standard failed\n"); | ||
814 | return -EREMOTEIO; | ||
815 | } | ||
816 | |||
817 | ret = xc_set_IF_frequency(priv, priv->if_khz); | ||
818 | if (ret != 0) { | ||
819 | printk(KERN_ERR "xc5000: xc_Set_IF_frequency(%d) failed\n", | ||
820 | priv->if_khz); | ||
821 | return -EIO; | ||
822 | } | ||
823 | |||
824 | xc_write_reg(priv, XREG_OUTPUT_AMP, 0x8a); | ||
825 | |||
826 | xc_tune_channel(priv, priv->freq_hz, XC_TUNE_DIGITAL); | ||
827 | |||
828 | if (debug) | ||
829 | xc_debug_dump(priv); | ||
830 | |||
831 | priv->bandwidth = bw; | ||
832 | |||
833 | return 0; | ||
834 | } | 847 | } |
835 | 848 | ||
836 | static int xc5000_is_firmware_loaded(struct dvb_frontend *fe) | 849 | static int xc5000_is_firmware_loaded(struct dvb_frontend *fe) |
@@ -852,12 +865,10 @@ static int xc5000_is_firmware_loaded(struct dvb_frontend *fe) | |||
852 | return ret; | 865 | return ret; |
853 | } | 866 | } |
854 | 867 | ||
855 | static int xc5000_set_tv_freq(struct dvb_frontend *fe, | 868 | static void xc5000_config_tv(struct dvb_frontend *fe, |
856 | struct analog_parameters *params) | 869 | struct analog_parameters *params) |
857 | { | 870 | { |
858 | struct xc5000_priv *priv = fe->tuner_priv; | 871 | struct xc5000_priv *priv = fe->tuner_priv; |
859 | u16 pll_lock_status; | ||
860 | int ret; | ||
861 | 872 | ||
862 | dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n", | 873 | dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n", |
863 | __func__, params->frequency); | 874 | __func__, params->frequency); |
@@ -876,42 +887,49 @@ static int xc5000_set_tv_freq(struct dvb_frontend *fe, | |||
876 | if (params->std & V4L2_STD_MN) { | 887 | if (params->std & V4L2_STD_MN) { |
877 | /* default to BTSC audio standard */ | 888 | /* default to BTSC audio standard */ |
878 | priv->video_standard = MN_NTSC_PAL_BTSC; | 889 | priv->video_standard = MN_NTSC_PAL_BTSC; |
879 | goto tune_channel; | 890 | return; |
880 | } | 891 | } |
881 | 892 | ||
882 | if (params->std & V4L2_STD_PAL_BG) { | 893 | if (params->std & V4L2_STD_PAL_BG) { |
883 | /* default to NICAM audio standard */ | 894 | /* default to NICAM audio standard */ |
884 | priv->video_standard = BG_PAL_NICAM; | 895 | priv->video_standard = BG_PAL_NICAM; |
885 | goto tune_channel; | 896 | return; |
886 | } | 897 | } |
887 | 898 | ||
888 | if (params->std & V4L2_STD_PAL_I) { | 899 | if (params->std & V4L2_STD_PAL_I) { |
889 | /* default to NICAM audio standard */ | 900 | /* default to NICAM audio standard */ |
890 | priv->video_standard = I_PAL_NICAM; | 901 | priv->video_standard = I_PAL_NICAM; |
891 | goto tune_channel; | 902 | return; |
892 | } | 903 | } |
893 | 904 | ||
894 | if (params->std & V4L2_STD_PAL_DK) { | 905 | if (params->std & V4L2_STD_PAL_DK) { |
895 | /* default to NICAM audio standard */ | 906 | /* default to NICAM audio standard */ |
896 | priv->video_standard = DK_PAL_NICAM; | 907 | priv->video_standard = DK_PAL_NICAM; |
897 | goto tune_channel; | 908 | return; |
898 | } | 909 | } |
899 | 910 | ||
900 | if (params->std & V4L2_STD_SECAM_DK) { | 911 | if (params->std & V4L2_STD_SECAM_DK) { |
901 | /* default to A2 DK1 audio standard */ | 912 | /* default to A2 DK1 audio standard */ |
902 | priv->video_standard = DK_SECAM_A2DK1; | 913 | priv->video_standard = DK_SECAM_A2DK1; |
903 | goto tune_channel; | 914 | return; |
904 | } | 915 | } |
905 | 916 | ||
906 | if (params->std & V4L2_STD_SECAM_L) { | 917 | if (params->std & V4L2_STD_SECAM_L) { |
907 | priv->video_standard = L_SECAM_NICAM; | 918 | priv->video_standard = L_SECAM_NICAM; |
908 | goto tune_channel; | 919 | return; |
909 | } | 920 | } |
910 | 921 | ||
911 | if (params->std & V4L2_STD_SECAM_LC) { | 922 | if (params->std & V4L2_STD_SECAM_LC) { |
912 | priv->video_standard = LC_SECAM_NICAM; | 923 | priv->video_standard = LC_SECAM_NICAM; |
913 | goto tune_channel; | 924 | return; |
914 | } | 925 | } |
926 | } | ||
927 | |||
928 | static int xc5000_set_tv_freq(struct dvb_frontend *fe) | ||
929 | { | ||
930 | struct xc5000_priv *priv = fe->tuner_priv; | ||
931 | u16 pll_lock_status; | ||
932 | int ret; | ||
915 | 933 | ||
916 | tune_channel: | 934 | tune_channel: |
917 | ret = xc_set_signal_source(priv, priv->rf_mode); | 935 | ret = xc_set_signal_source(priv, priv->rf_mode); |
@@ -955,12 +973,11 @@ tune_channel: | |||
955 | return 0; | 973 | return 0; |
956 | } | 974 | } |
957 | 975 | ||
958 | static int xc5000_set_radio_freq(struct dvb_frontend *fe, | 976 | static int xc5000_config_radio(struct dvb_frontend *fe, |
959 | struct analog_parameters *params) | 977 | struct analog_parameters *params) |
978 | |||
960 | { | 979 | { |
961 | struct xc5000_priv *priv = fe->tuner_priv; | 980 | struct xc5000_priv *priv = fe->tuner_priv; |
962 | int ret = -EINVAL; | ||
963 | u8 radio_input; | ||
964 | 981 | ||
965 | dprintk(1, "%s() frequency=%d (in units of khz)\n", | 982 | dprintk(1, "%s() frequency=%d (in units of khz)\n", |
966 | __func__, params->frequency); | 983 | __func__, params->frequency); |
@@ -970,6 +987,18 @@ static int xc5000_set_radio_freq(struct dvb_frontend *fe, | |||
970 | return -EINVAL; | 987 | return -EINVAL; |
971 | } | 988 | } |
972 | 989 | ||
990 | priv->freq_hz = params->frequency * 125 / 2; | ||
991 | priv->rf_mode = XC_RF_MODE_AIR; | ||
992 | |||
993 | return 0; | ||
994 | } | ||
995 | |||
996 | static int xc5000_set_radio_freq(struct dvb_frontend *fe) | ||
997 | { | ||
998 | struct xc5000_priv *priv = fe->tuner_priv; | ||
999 | int ret; | ||
1000 | u8 radio_input; | ||
1001 | |||
973 | if (priv->radio_input == XC5000_RADIO_FM1) | 1002 | if (priv->radio_input == XC5000_RADIO_FM1) |
974 | radio_input = FM_RADIO_INPUT1; | 1003 | radio_input = FM_RADIO_INPUT1; |
975 | else if (priv->radio_input == XC5000_RADIO_FM2) | 1004 | else if (priv->radio_input == XC5000_RADIO_FM2) |
@@ -982,10 +1011,6 @@ static int xc5000_set_radio_freq(struct dvb_frontend *fe, | |||
982 | return -EINVAL; | 1011 | return -EINVAL; |
983 | } | 1012 | } |
984 | 1013 | ||
985 | priv->freq_hz = params->frequency * 125 / 2; | ||
986 | |||
987 | priv->rf_mode = XC_RF_MODE_AIR; | ||
988 | |||
989 | ret = xc_set_tv_standard(priv, xc5000_standard[radio_input].video_mode, | 1014 | ret = xc_set_tv_standard(priv, xc5000_standard[radio_input].video_mode, |
990 | xc5000_standard[radio_input].audio_mode, radio_input); | 1015 | xc5000_standard[radio_input].audio_mode, radio_input); |
991 | 1016 | ||
@@ -1013,34 +1038,53 @@ static int xc5000_set_radio_freq(struct dvb_frontend *fe, | |||
1013 | return 0; | 1038 | return 0; |
1014 | } | 1039 | } |
1015 | 1040 | ||
1016 | static int xc5000_set_analog_params(struct dvb_frontend *fe, | 1041 | static int xc5000_set_params(struct dvb_frontend *fe) |
1017 | struct analog_parameters *params) | ||
1018 | { | 1042 | { |
1019 | struct xc5000_priv *priv = fe->tuner_priv; | 1043 | struct xc5000_priv *priv = fe->tuner_priv; |
1020 | int ret = -EINVAL; | ||
1021 | |||
1022 | if (priv->i2c_props.adap == NULL) | ||
1023 | return -EINVAL; | ||
1024 | 1044 | ||
1025 | if (xc_load_fw_and_init_tuner(fe, 0) != 0) { | 1045 | if (xc_load_fw_and_init_tuner(fe, 0) != 0) { |
1026 | dprintk(1, "Unable to load firmware and init tuner\n"); | 1046 | dprintk(1, "Unable to load firmware and init tuner\n"); |
1027 | return -EINVAL; | 1047 | return -EINVAL; |
1028 | } | 1048 | } |
1029 | 1049 | ||
1050 | switch (priv->mode) { | ||
1051 | case V4L2_TUNER_RADIO: | ||
1052 | return xc5000_set_radio_freq(fe); | ||
1053 | case V4L2_TUNER_ANALOG_TV: | ||
1054 | return xc5000_set_tv_freq(fe); | ||
1055 | case V4L2_TUNER_DIGITAL_TV: | ||
1056 | return xc5000_tune_digital(fe); | ||
1057 | } | ||
1058 | |||
1059 | return 0; | ||
1060 | } | ||
1061 | |||
1062 | static int xc5000_set_analog_params(struct dvb_frontend *fe, | ||
1063 | struct analog_parameters *params) | ||
1064 | { | ||
1065 | struct xc5000_priv *priv = fe->tuner_priv; | ||
1066 | int ret; | ||
1067 | |||
1068 | if (priv->i2c_props.adap == NULL) | ||
1069 | return -EINVAL; | ||
1070 | |||
1030 | switch (params->mode) { | 1071 | switch (params->mode) { |
1031 | case V4L2_TUNER_RADIO: | 1072 | case V4L2_TUNER_RADIO: |
1032 | ret = xc5000_set_radio_freq(fe, params); | 1073 | ret = xc5000_config_radio(fe, params); |
1074 | if (ret) | ||
1075 | return ret; | ||
1033 | break; | 1076 | break; |
1034 | case V4L2_TUNER_ANALOG_TV: | 1077 | case V4L2_TUNER_ANALOG_TV: |
1035 | case V4L2_TUNER_DIGITAL_TV: | 1078 | xc5000_config_tv(fe, params); |
1036 | ret = xc5000_set_tv_freq(fe, params); | 1079 | break; |
1080 | default: | ||
1037 | break; | 1081 | break; |
1038 | } | 1082 | } |
1083 | priv->mode = params->mode; | ||
1039 | 1084 | ||
1040 | return ret; | 1085 | return xc5000_set_params(fe); |
1041 | } | 1086 | } |
1042 | 1087 | ||
1043 | |||
1044 | static int xc5000_get_frequency(struct dvb_frontend *fe, u32 *freq) | 1088 | static int xc5000_get_frequency(struct dvb_frontend *fe, u32 *freq) |
1045 | { | 1089 | { |
1046 | struct xc5000_priv *priv = fe->tuner_priv; | 1090 | struct xc5000_priv *priv = fe->tuner_priv; |
@@ -1094,20 +1138,23 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force) | |||
1094 | if (!force && xc5000_is_firmware_loaded(fe) == 0) | 1138 | if (!force && xc5000_is_firmware_loaded(fe) == 0) |
1095 | return 0; | 1139 | return 0; |
1096 | 1140 | ||
1097 | ret = request_firmware(&fw, desired_fw->name, | 1141 | if (!priv->firmware) { |
1098 | priv->i2c_props.adap->dev.parent); | 1142 | ret = request_firmware(&fw, desired_fw->name, |
1099 | if (ret) { | 1143 | priv->i2c_props.adap->dev.parent); |
1100 | printk(KERN_ERR "xc5000: Upload failed. (file not found?)\n"); | 1144 | if (ret) { |
1101 | return ret; | 1145 | pr_err("xc5000: Upload failed. rc %d\n", ret); |
1102 | } | 1146 | return ret; |
1103 | 1147 | } | |
1104 | dprintk(1, "firmware read %Zu bytes.\n", fw->size); | 1148 | dprintk(1, "firmware read %Zu bytes.\n", fw->size); |
1105 | 1149 | ||
1106 | if (fw->size != desired_fw->size) { | 1150 | if (fw->size != desired_fw->size) { |
1107 | printk(KERN_ERR "xc5000: Firmware file with incorrect size\n"); | 1151 | pr_err("xc5000: Firmware file with incorrect size\n"); |
1108 | ret = -EINVAL; | 1152 | release_firmware(fw); |
1109 | goto err; | 1153 | return -EINVAL; |
1110 | } | 1154 | } |
1155 | priv->firmware = fw; | ||
1156 | } else | ||
1157 | fw = priv->firmware; | ||
1111 | 1158 | ||
1112 | /* Try up to 5 times to load firmware */ | 1159 | /* Try up to 5 times to load firmware */ |
1113 | for (i = 0; i < 5; i++) { | 1160 | for (i = 0; i < 5; i++) { |
@@ -1190,7 +1237,6 @@ err: | |||
1190 | else | 1237 | else |
1191 | printk(KERN_CONT " - too many retries. Giving up\n"); | 1238 | printk(KERN_CONT " - too many retries. Giving up\n"); |
1192 | 1239 | ||
1193 | release_firmware(fw); | ||
1194 | return ret; | 1240 | return ret; |
1195 | } | 1241 | } |
1196 | 1242 | ||
@@ -1229,6 +1275,38 @@ static int xc5000_sleep(struct dvb_frontend *fe) | |||
1229 | return 0; | 1275 | return 0; |
1230 | } | 1276 | } |
1231 | 1277 | ||
1278 | static int xc5000_suspend(struct dvb_frontend *fe) | ||
1279 | { | ||
1280 | struct xc5000_priv *priv = fe->tuner_priv; | ||
1281 | int ret; | ||
1282 | |||
1283 | dprintk(1, "%s()\n", __func__); | ||
1284 | |||
1285 | cancel_delayed_work(&priv->timer_sleep); | ||
1286 | |||
1287 | ret = xc5000_tuner_reset(fe); | ||
1288 | if (ret != 0) | ||
1289 | printk(KERN_ERR | ||
1290 | "xc5000: %s() unable to shutdown tuner\n", | ||
1291 | __func__); | ||
1292 | |||
1293 | return 0; | ||
1294 | } | ||
1295 | |||
1296 | static int xc5000_resume(struct dvb_frontend *fe) | ||
1297 | { | ||
1298 | struct xc5000_priv *priv = fe->tuner_priv; | ||
1299 | |||
1300 | dprintk(1, "%s()\n", __func__); | ||
1301 | |||
1302 | /* suspended before firmware is loaded. | ||
1303 | Avoid firmware load in resume path. */ | ||
1304 | if (!priv->firmware) | ||
1305 | return 0; | ||
1306 | |||
1307 | return xc5000_set_params(fe); | ||
1308 | } | ||
1309 | |||
1232 | static int xc5000_init(struct dvb_frontend *fe) | 1310 | static int xc5000_init(struct dvb_frontend *fe) |
1233 | { | 1311 | { |
1234 | struct xc5000_priv *priv = fe->tuner_priv; | 1312 | struct xc5000_priv *priv = fe->tuner_priv; |
@@ -1256,6 +1334,8 @@ static int xc5000_release(struct dvb_frontend *fe) | |||
1256 | if (priv) { | 1334 | if (priv) { |
1257 | cancel_delayed_work(&priv->timer_sleep); | 1335 | cancel_delayed_work(&priv->timer_sleep); |
1258 | hybrid_tuner_release_state(priv); | 1336 | hybrid_tuner_release_state(priv); |
1337 | if (priv->firmware) | ||
1338 | release_firmware(priv->firmware); | ||
1259 | } | 1339 | } |
1260 | 1340 | ||
1261 | mutex_unlock(&xc5000_list_mutex); | 1341 | mutex_unlock(&xc5000_list_mutex); |
@@ -1293,9 +1373,11 @@ static const struct dvb_tuner_ops xc5000_tuner_ops = { | |||
1293 | .release = xc5000_release, | 1373 | .release = xc5000_release, |
1294 | .init = xc5000_init, | 1374 | .init = xc5000_init, |
1295 | .sleep = xc5000_sleep, | 1375 | .sleep = xc5000_sleep, |
1376 | .suspend = xc5000_suspend, | ||
1377 | .resume = xc5000_resume, | ||
1296 | 1378 | ||
1297 | .set_config = xc5000_set_config, | 1379 | .set_config = xc5000_set_config, |
1298 | .set_params = xc5000_set_params, | 1380 | .set_params = xc5000_set_digital_params, |
1299 | .set_analog_params = xc5000_set_analog_params, | 1381 | .set_analog_params = xc5000_set_analog_params, |
1300 | .get_frequency = xc5000_get_frequency, | 1382 | .get_frequency = xc5000_get_frequency, |
1301 | .get_if_frequency = xc5000_get_if_frequency, | 1383 | .get_if_frequency = xc5000_get_if_frequency, |