aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/i2c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2013-04-30 08:01:04 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-04-30 08:01:04 -0400
commitdf90e2258950fd631cdbf322c1ee1f22068391aa (patch)
tree0b6dd2717c04bb7f93db6abdeda208aeea4cd74e /drivers/media/i2c
parentaad797c89903d570c17f6affc770eb98afd74e62 (diff)
parent02615ed5e1b2283db2495af3cf8f4ee172c77d80 (diff)
Merge branch 'devel-for-v3.10' into v4l_for_linus
* patchwork: (831 commits) [media] cx88: make core less verbose [media] em28xx: fix oops at em28xx_dvb_bus_ctrl() [media] s5c73m3: fix indentation of the help section in Kconfig [media] cx25821-alsa: get rid of a __must_check warning [media] cx25821-video: declare cx25821_vidioc_s_std as static [media] cx25821-video: remove maxw from cx25821_vidioc_try_fmt_vid_cap [media] r820t: Remove a warning for an unused value [media] dib0090: Fix a warning at dib0090_set_EFUSE [media] dib8000: fix a warning [media] dib8000: Fix sub-channel range [media] dib8000: store dtv_property_cache in a temp var [media] dib8000: warning fix: declare internal functions as static [media] r820t: quiet gcc warning on n_ring [media] r820t: memory leak in release() [media] r820t: precendence bug in r820t_xtal_check() [media] videodev2.h: Remove the unused old V4L1 buffer types [media] anysee: Grammar s/report the/report to/ [media] anysee: Initialize ret = 0 in anysee_frontend_attach() [media] media: videobuf2: fix the length check for mmap [media] em28xx: save isoc endpoint number for DVB only if endpoint has alt settings with xMaxPacketSize != 0 ... Conflicts: drivers/media/pci/cx25821/cx25821-video.c drivers/media/platform/Kconfig
Diffstat (limited to 'drivers/media/i2c')
-rw-r--r--drivers/media/i2c/Kconfig70
-rw-r--r--drivers/media/i2c/Makefile8
-rw-r--r--drivers/media/i2c/ad9389b.c2
-rw-r--r--drivers/media/i2c/adp1653.c4
-rw-r--r--drivers/media/i2c/adv7180.c4
-rw-r--r--drivers/media/i2c/adv7183.c2
-rw-r--r--drivers/media/i2c/adv7604.c2
-rw-r--r--drivers/media/i2c/ak881x.c2
-rw-r--r--drivers/media/i2c/cs5345.c2
-rw-r--r--drivers/media/i2c/cx25840/cx25840-core.c6
-rw-r--r--drivers/media/i2c/ir-kbd-i2c.c14
-rw-r--r--drivers/media/i2c/m52790.c2
-rw-r--r--drivers/media/i2c/msp3400-driver.c4
-rw-r--r--drivers/media/i2c/mt9m032.c48
-rw-r--r--drivers/media/i2c/mt9p031.c58
-rw-r--r--drivers/media/i2c/mt9v011.c2
-rw-r--r--drivers/media/i2c/ov7640.c106
-rw-r--r--drivers/media/i2c/ov7670.c2
-rw-r--r--drivers/media/i2c/s5c73m3/s5c73m3-core.c23
-rw-r--r--drivers/media/i2c/saa6588.c2
-rw-r--r--drivers/media/i2c/saa7115.c80
-rw-r--r--drivers/media/i2c/saa7127.c2
-rw-r--r--drivers/media/i2c/saa717x.c4
-rw-r--r--drivers/media/i2c/smiapp/smiapp-core.c4
-rw-r--r--drivers/media/i2c/soc_camera/Kconfig2
-rw-r--r--drivers/media/i2c/soc_camera/mt9m001.c2
-rw-r--r--drivers/media/i2c/soc_camera/mt9m111.c11
-rw-r--r--drivers/media/i2c/soc_camera/mt9t031.c2
-rw-r--r--drivers/media/i2c/soc_camera/mt9t112.c2
-rw-r--r--drivers/media/i2c/soc_camera/mt9v022.c21
-rw-r--r--drivers/media/i2c/soc_camera/ov2640.c2
-rw-r--r--drivers/media/i2c/soc_camera/ov5642.c2
-rw-r--r--drivers/media/i2c/soc_camera/ov6650.c2
-rw-r--r--drivers/media/i2c/soc_camera/ov772x.c2
-rw-r--r--drivers/media/i2c/soc_camera/ov9640.c2
-rw-r--r--drivers/media/i2c/soc_camera/ov9740.c2
-rw-r--r--drivers/media/i2c/soc_camera/rj54n1cb0c.c2
-rw-r--r--drivers/media/i2c/soc_camera/tw9910.c2
-rw-r--r--drivers/media/i2c/sony-btf-mpx.c399
-rw-r--r--drivers/media/i2c/tda7432.c276
-rw-r--r--drivers/media/i2c/tda9840.c2
-rw-r--r--drivers/media/i2c/ths7303.c351
-rw-r--r--drivers/media/i2c/tvaudio.c6
-rw-r--r--drivers/media/i2c/tvp514x.c163
-rw-r--r--drivers/media/i2c/tvp5150.c2
-rw-r--r--drivers/media/i2c/tvp7002.c184
-rw-r--r--drivers/media/i2c/tw2804.c453
-rw-r--r--drivers/media/i2c/tw9903.c279
-rw-r--r--drivers/media/i2c/tw9906.c247
-rw-r--r--drivers/media/i2c/uda1342.c113
-rw-r--r--drivers/media/i2c/upd64031a.c4
-rw-r--r--drivers/media/i2c/upd64083.c2
-rw-r--r--drivers/media/i2c/vp27smpx.c2
-rw-r--r--drivers/media/i2c/vs6624.c2
-rw-r--r--drivers/media/i2c/wm8775.c2
55 files changed, 2491 insertions, 505 deletions
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 7b771baa2212..f981d50a2a8c 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -112,6 +112,15 @@ config VIDEO_TLV320AIC23B
112 To compile this driver as a module, choose M here: the 112 To compile this driver as a module, choose M here: the
113 module will be called tlv320aic23b. 113 module will be called tlv320aic23b.
114 114
115config VIDEO_UDA1342
116 tristate "Philips UDA1342 audio codec"
117 depends on VIDEO_V4L2 && I2C
118 ---help---
119 Support for the Philips UDA1342 audio codec.
120
121 To compile this driver as a module, choose M here: the
122 module will be called uda1342.
123
115config VIDEO_WM8775 124config VIDEO_WM8775
116 tristate "Wolfson Microelectronics WM8775 audio ADC with input mixer" 125 tristate "Wolfson Microelectronics WM8775 audio ADC with input mixer"
117 depends on VIDEO_V4L2 && I2C 126 depends on VIDEO_V4L2 && I2C
@@ -133,7 +142,7 @@ config VIDEO_WM8739
133 module will be called wm8739. 142 module will be called wm8739.
134 143
135config VIDEO_VP27SMPX 144config VIDEO_VP27SMPX
136 tristate "Panasonic VP27s internal MPX" 145 tristate "Panasonic VP27's internal MPX"
137 depends on VIDEO_V4L2 && I2C 146 depends on VIDEO_V4L2 && I2C
138 ---help--- 147 ---help---
139 Support for the internal MPX of the Panasonic VP27s tuner. 148 Support for the internal MPX of the Panasonic VP27s tuner.
@@ -141,6 +150,15 @@ config VIDEO_VP27SMPX
141 To compile this driver as a module, choose M here: the 150 To compile this driver as a module, choose M here: the
142 module will be called vp27smpx. 151 module will be called vp27smpx.
143 152
153config VIDEO_SONY_BTF_MPX
154 tristate "Sony BTF's internal MPX"
155 depends on VIDEO_V4L2 && I2C
156 help
157 Support for the internal MPX of the Sony BTF-PG472Z tuner.
158
159 To compile this driver as a module, choose M here: the
160 module will be called sony-btf-mpx.
161
144comment "RDS decoders" 162comment "RDS decoders"
145 163
146config VIDEO_SAA6588 164config VIDEO_SAA6588
@@ -283,6 +301,35 @@ config VIDEO_TVP7002
283 To compile this driver as a module, choose M here: the 301 To compile this driver as a module, choose M here: the
284 module will be called tvp7002. 302 module will be called tvp7002.
285 303
304config VIDEO_TW2804
305 tristate "Techwell TW2804 multiple video decoder"
306 depends on VIDEO_V4L2 && I2C
307 ---help---
308 Support for the Techwell tw2804 multiple video decoder.
309
310 To compile this driver as a module, choose M here: the
311 module will be called tw2804.
312
313config VIDEO_TW9903
314 tristate "Techwell TW9903 video decoder"
315 depends on VIDEO_V4L2 && I2C
316 ---help---
317 Support for the Techwell tw9903 multi-standard video decoder
318 with high quality down scaler.
319
320 To compile this driver as a module, choose M here: the
321 module will be called tw9903.
322
323config VIDEO_TW9906
324 tristate "Techwell TW9906 video decoder"
325 depends on VIDEO_V4L2 && I2C
326 ---help---
327 Support for the Techwell tw9906 enhanced multi-standard comb filter
328 video decoder with YCbCr input support.
329
330 To compile this driver as a module, choose M here: the
331 module will be called tw9906.
332
286config VIDEO_VPX3220 333config VIDEO_VPX3220
287 tristate "vpx3220a, vpx3216b & vpx3214c video decoders" 334 tristate "vpx3220a, vpx3216b & vpx3214c video decoders"
288 depends on VIDEO_V4L2 && I2C 335 depends on VIDEO_V4L2 && I2C
@@ -386,6 +433,17 @@ config VIDEO_APTINA_PLL
386config VIDEO_SMIAPP_PLL 433config VIDEO_SMIAPP_PLL
387 tristate 434 tristate
388 435
436config VIDEO_OV7640
437 tristate "OmniVision OV7640 sensor support"
438 depends on I2C && VIDEO_V4L2
439 depends on MEDIA_CAMERA_SUPPORT
440 ---help---
441 This is a Video4Linux2 sensor-level driver for the OmniVision
442 OV7640 camera.
443
444 To compile this driver as a module, choose M here: the
445 module will be called ov7640.
446
389config VIDEO_OV7670 447config VIDEO_OV7670
390 tristate "OmniVision OV7670 sensor support" 448 tristate "OmniVision OV7670 sensor support"
391 depends on I2C && VIDEO_V4L2 449 depends on I2C && VIDEO_V4L2
@@ -501,8 +559,8 @@ config VIDEO_S5C73M3
501 tristate "Samsung S5C73M3 sensor support" 559 tristate "Samsung S5C73M3 sensor support"
502 depends on I2C && SPI && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API 560 depends on I2C && SPI && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
503 ---help--- 561 ---help---
504 This is a V4L2 sensor-level driver for Samsung S5C73M3 562 This is a V4L2 sensor-level driver for Samsung S5C73M3
505 8 Mpixel camera. 563 8 Mpixel camera.
506 564
507comment "Flash devices" 565comment "Flash devices"
508 566
@@ -550,10 +608,10 @@ config VIDEO_UPD64083
550comment "Miscelaneous helper chips" 608comment "Miscelaneous helper chips"
551 609
552config VIDEO_THS7303 610config VIDEO_THS7303
553 tristate "THS7303 Video Amplifier" 611 tristate "THS7303/53 Video Amplifier"
554 depends on I2C 612 depends on VIDEO_V4L2 && I2C
555 help 613 help
556 Support for TI THS7303 video amplifier 614 Support for TI THS7303/53 video amplifier
557 615
558 To compile this driver as a module, choose M here: the 616 To compile this driver as a module, choose M here: the
559 module will be called ths7303. 617 module will be called ths7303.
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index cfefd30cc1bc..720f42d9d9f4 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -37,16 +37,22 @@ obj-$(CONFIG_VIDEO_THS7303) += ths7303.o
37obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o 37obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o
38obj-$(CONFIG_VIDEO_TVP514X) += tvp514x.o 38obj-$(CONFIG_VIDEO_TVP514X) += tvp514x.o
39obj-$(CONFIG_VIDEO_TVP7002) += tvp7002.o 39obj-$(CONFIG_VIDEO_TVP7002) += tvp7002.o
40obj-$(CONFIG_VIDEO_TW2804) += tw2804.o
41obj-$(CONFIG_VIDEO_TW9903) += tw9903.o
42obj-$(CONFIG_VIDEO_TW9906) += tw9906.o
40obj-$(CONFIG_VIDEO_CS5345) += cs5345.o 43obj-$(CONFIG_VIDEO_CS5345) += cs5345.o
41obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o 44obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o
42obj-$(CONFIG_VIDEO_M52790) += m52790.o 45obj-$(CONFIG_VIDEO_M52790) += m52790.o
43obj-$(CONFIG_VIDEO_TLV320AIC23B) += tlv320aic23b.o 46obj-$(CONFIG_VIDEO_TLV320AIC23B) += tlv320aic23b.o
47obj-$(CONFIG_VIDEO_UDA1342) += uda1342.o
44obj-$(CONFIG_VIDEO_WM8775) += wm8775.o 48obj-$(CONFIG_VIDEO_WM8775) += wm8775.o
45obj-$(CONFIG_VIDEO_WM8739) += wm8739.o 49obj-$(CONFIG_VIDEO_WM8739) += wm8739.o
46obj-$(CONFIG_VIDEO_VP27SMPX) += vp27smpx.o 50obj-$(CONFIG_VIDEO_VP27SMPX) += vp27smpx.o
51obj-$(CONFIG_VIDEO_SONY_BTF_MPX) += sony-btf-mpx.o
47obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o 52obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o
48obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o 53obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o
49obj-$(CONFIG_VIDEO_OV7670) += ov7670.o 54obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
55obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
50obj-$(CONFIG_VIDEO_OV9650) += ov9650.o 56obj-$(CONFIG_VIDEO_OV9650) += ov9650.o
51obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o 57obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o
52obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o 58obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o
diff --git a/drivers/media/i2c/ad9389b.c b/drivers/media/i2c/ad9389b.c
index c2886b6a727d..58344b6c3a55 100644
--- a/drivers/media/i2c/ad9389b.c
+++ b/drivers/media/i2c/ad9389b.c
@@ -354,7 +354,7 @@ static int ad9389b_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
354 return 0; 354 return 0;
355} 355}
356 356
357static int ad9389b_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 357static int ad9389b_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
358{ 358{
359 struct i2c_client *client = v4l2_get_subdevdata(sd); 359 struct i2c_client *client = v4l2_get_subdevdata(sd);
360 360
diff --git a/drivers/media/i2c/adp1653.c b/drivers/media/i2c/adp1653.c
index df163800c8e1..ef75abe5984c 100644
--- a/drivers/media/i2c/adp1653.c
+++ b/drivers/media/i2c/adp1653.c
@@ -447,7 +447,7 @@ free_and_quit:
447 return ret; 447 return ret;
448} 448}
449 449
450static int __exit adp1653_remove(struct i2c_client *client) 450static int adp1653_remove(struct i2c_client *client)
451{ 451{
452 struct v4l2_subdev *subdev = i2c_get_clientdata(client); 452 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
453 struct adp1653_flash *flash = to_adp1653_flash(subdev); 453 struct adp1653_flash *flash = to_adp1653_flash(subdev);
@@ -476,7 +476,7 @@ static struct i2c_driver adp1653_i2c_driver = {
476 .pm = &adp1653_pm_ops, 476 .pm = &adp1653_pm_ops,
477 }, 477 },
478 .probe = adp1653_probe, 478 .probe = adp1653_probe,
479 .remove = __exit_p(adp1653_remove), 479 .remove = adp1653_remove,
480 .id_table = adp1653_id_table, 480 .id_table = adp1653_id_table,
481}; 481};
482 482
diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 34f39d3b3e3e..afd561ab190d 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -135,6 +135,10 @@ struct adv7180_state {
135 135
136static v4l2_std_id adv7180_std_to_v4l2(u8 status1) 136static v4l2_std_id adv7180_std_to_v4l2(u8 status1)
137{ 137{
138 /* in case V4L2_IN_ST_NO_SIGNAL */
139 if (!(status1 & ADV7180_STATUS1_IN_LOCK))
140 return V4L2_STD_UNKNOWN;
141
138 switch (status1 & ADV7180_STATUS1_AUTOD_MASK) { 142 switch (status1 & ADV7180_STATUS1_AUTOD_MASK) {
139 case ADV7180_STATUS1_AUTOD_NTSM_M_J: 143 case ADV7180_STATUS1_AUTOD_NTSM_M_J:
140 return V4L2_STD_NTSC; 144 return V4L2_STD_NTSC;
diff --git a/drivers/media/i2c/adv7183.c b/drivers/media/i2c/adv7183.c
index 6fed5b74e743..56a1fa4af0fe 100644
--- a/drivers/media/i2c/adv7183.c
+++ b/drivers/media/i2c/adv7183.c
@@ -507,7 +507,7 @@ static int adv7183_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
507 return 0; 507 return 0;
508} 508}
509 509
510static int adv7183_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 510static int adv7183_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
511{ 511{
512 struct i2c_client *client = v4l2_get_subdevdata(sd); 512 struct i2c_client *client = v4l2_get_subdevdata(sd);
513 513
diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index f47555b1000a..31a63c9324fe 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -699,7 +699,7 @@ static int adv7604_g_register(struct v4l2_subdev *sd,
699} 699}
700 700
701static int adv7604_s_register(struct v4l2_subdev *sd, 701static int adv7604_s_register(struct v4l2_subdev *sd,
702 struct v4l2_dbg_register *reg) 702 const struct v4l2_dbg_register *reg)
703{ 703{
704 struct i2c_client *client = v4l2_get_subdevdata(sd); 704 struct i2c_client *client = v4l2_get_subdevdata(sd);
705 705
diff --git a/drivers/media/i2c/ak881x.c b/drivers/media/i2c/ak881x.c
index ba674656b10d..fd47465e4f6a 100644
--- a/drivers/media/i2c/ak881x.c
+++ b/drivers/media/i2c/ak881x.c
@@ -101,7 +101,7 @@ static int ak881x_g_register(struct v4l2_subdev *sd,
101} 101}
102 102
103static int ak881x_s_register(struct v4l2_subdev *sd, 103static int ak881x_s_register(struct v4l2_subdev *sd,
104 struct v4l2_dbg_register *reg) 104 const struct v4l2_dbg_register *reg)
105{ 105{
106 struct i2c_client *client = v4l2_get_subdevdata(sd); 106 struct i2c_client *client = v4l2_get_subdevdata(sd);
107 107
diff --git a/drivers/media/i2c/cs5345.c b/drivers/media/i2c/cs5345.c
index c8581e26fa9c..1d2f7c8512b5 100644
--- a/drivers/media/i2c/cs5345.c
+++ b/drivers/media/i2c/cs5345.c
@@ -110,7 +110,7 @@ static int cs5345_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *r
110 return 0; 110 return 0;
111} 111}
112 112
113static int cs5345_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 113static int cs5345_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
114{ 114{
115 struct i2c_client *client = v4l2_get_subdevdata(sd); 115 struct i2c_client *client = v4l2_get_subdevdata(sd);
116 116
diff --git a/drivers/media/i2c/cx25840/cx25840-core.c b/drivers/media/i2c/cx25840/cx25840-core.c
index f4149eb4d7b4..12fb9b2eb887 100644
--- a/drivers/media/i2c/cx25840/cx25840-core.c
+++ b/drivers/media/i2c/cx25840/cx25840-core.c
@@ -1671,7 +1671,7 @@ static int cx25840_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
1671 return 0; 1671 return 0;
1672} 1672}
1673 1673
1674static int cx25840_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 1674static int cx25840_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
1675{ 1675{
1676 struct i2c_client *client = v4l2_get_subdevdata(sd); 1676 struct i2c_client *client = v4l2_get_subdevdata(sd);
1677 1677
@@ -1835,7 +1835,7 @@ static int cx25840_s_audio_routing(struct v4l2_subdev *sd,
1835 return set_input(client, state->vid_input, input); 1835 return set_input(client, state->vid_input, input);
1836} 1836}
1837 1837
1838static int cx25840_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) 1838static int cx25840_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *freq)
1839{ 1839{
1840 struct i2c_client *client = v4l2_get_subdevdata(sd); 1840 struct i2c_client *client = v4l2_get_subdevdata(sd);
1841 1841
@@ -1881,7 +1881,7 @@ static int cx25840_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1881 return 0; 1881 return 0;
1882} 1882}
1883 1883
1884static int cx25840_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 1884static int cx25840_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
1885{ 1885{
1886 struct cx25840_state *state = to_state(sd); 1886 struct cx25840_state *state = to_state(sd);
1887 struct i2c_client *client = v4l2_get_subdevdata(sd); 1887 struct i2c_client *client = v4l2_get_subdevdata(sd);
diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c
index 08ae067b2b6f..8e2f79cb045e 100644
--- a/drivers/media/i2c/ir-kbd-i2c.c
+++ b/drivers/media/i2c/ir-kbd-i2c.c
@@ -230,7 +230,7 @@ static int get_key_avermedia_cardbus(struct IR_i2c *ir,
230 return 0; 230 return 0;
231 231
232 dprintk(1, "read key 0x%02x/0x%02x\n", key, keygroup); 232 dprintk(1, "read key 0x%02x/0x%02x\n", key, keygroup);
233 if (keygroup < 2 || keygroup > 3) { 233 if (keygroup < 2 || keygroup > 4) {
234 /* Only a warning */ 234 /* Only a warning */
235 dprintk(1, "warning: invalid key group 0x%02x for key 0x%02x\n", 235 dprintk(1, "warning: invalid key group 0x%02x for key 0x%02x\n",
236 keygroup, key); 236 keygroup, key);
@@ -239,6 +239,10 @@ static int get_key_avermedia_cardbus(struct IR_i2c *ir,
239 239
240 *ir_key = key; 240 *ir_key = key;
241 *ir_raw = key; 241 *ir_raw = key;
242 if (!strcmp(ir->ir_codes, RC_MAP_AVERMEDIA_M733A_RM_K6)) {
243 *ir_key |= keygroup << 8;
244 *ir_raw |= keygroup << 8;
245 }
242 return 1; 246 return 1;
243} 247}
244 248
@@ -332,6 +336,13 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
332 rc_type = RC_BIT_OTHER; 336 rc_type = RC_BIT_OTHER;
333 ir_codes = RC_MAP_AVERMEDIA_CARDBUS; 337 ir_codes = RC_MAP_AVERMEDIA_CARDBUS;
334 break; 338 break;
339 case 0x41:
340 name = "AVerMedia EM78P153";
341 ir->get_key = get_key_avermedia_cardbus;
342 rc_type = RC_BIT_OTHER;
343 /* RM-KV remote, seems to be same as RM-K6 */
344 ir_codes = RC_MAP_AVERMEDIA_M733A_RM_K6;
345 break;
335 case 0x71: 346 case 0x71:
336 name = "Hauppauge/Zilog Z8"; 347 name = "Hauppauge/Zilog Z8";
337 ir->get_key = get_key_haup_xvr; 348 ir->get_key = get_key_haup_xvr;
@@ -423,6 +434,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
423 */ 434 */
424 rc->map_name = ir->ir_codes; 435 rc->map_name = ir->ir_codes;
425 rc->allowed_protos = rc_type; 436 rc->allowed_protos = rc_type;
437 rc->enabled_protocols = rc_type;
426 if (!rc->driver_name) 438 if (!rc->driver_name)
427 rc->driver_name = MODULE_NAME; 439 rc->driver_name = MODULE_NAME;
428 440
diff --git a/drivers/media/i2c/m52790.c b/drivers/media/i2c/m52790.c
index 0991576f4c82..39f50fd2b8d2 100644
--- a/drivers/media/i2c/m52790.c
+++ b/drivers/media/i2c/m52790.c
@@ -96,7 +96,7 @@ static int m52790_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *r
96 return 0; 96 return 0;
97} 97}
98 98
99static int m52790_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 99static int m52790_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
100{ 100{
101 struct m52790_state *state = to_state(sd); 101 struct m52790_state *state = to_state(sd);
102 struct i2c_client *client = v4l2_get_subdevdata(sd); 102 struct i2c_client *client = v4l2_get_subdevdata(sd);
diff --git a/drivers/media/i2c/msp3400-driver.c b/drivers/media/i2c/msp3400-driver.c
index 766305f69a28..54a9dd394f45 100644
--- a/drivers/media/i2c/msp3400-driver.c
+++ b/drivers/media/i2c/msp3400-driver.c
@@ -445,7 +445,7 @@ static int msp_s_radio(struct v4l2_subdev *sd)
445 return 0; 445 return 0;
446} 446}
447 447
448static int msp_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) 448static int msp_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *freq)
449{ 449{
450 struct i2c_client *client = v4l2_get_subdevdata(sd); 450 struct i2c_client *client = v4l2_get_subdevdata(sd);
451 451
@@ -535,7 +535,7 @@ static int msp_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
535 return 0; 535 return 0;
536} 536}
537 537
538static int msp_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 538static int msp_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
539{ 539{
540 struct msp_state *state = to_state(sd); 540 struct msp_state *state = to_state(sd);
541 struct i2c_client *client = v4l2_get_subdevdata(sd); 541 struct i2c_client *client = v4l2_get_subdevdata(sd);
diff --git a/drivers/media/i2c/mt9m032.c b/drivers/media/i2c/mt9m032.c
index f80c1d7ec884..8edb3d8f7b90 100644
--- a/drivers/media/i2c/mt9m032.c
+++ b/drivers/media/i2c/mt9m032.c
@@ -87,9 +87,27 @@
87#define MT9M032_RESTART 0x0b 87#define MT9M032_RESTART 0x0b
88#define MT9M032_RESET 0x0d 88#define MT9M032_RESET 0x0d
89#define MT9M032_PLL_CONFIG1 0x11 89#define MT9M032_PLL_CONFIG1 0x11
90#define MT9M032_PLL_CONFIG1_OUTDIV_MASK 0x3f 90#define MT9M032_PLL_CONFIG1_PREDIV_MASK 0x3f
91#define MT9M032_PLL_CONFIG1_MUL_SHIFT 8 91#define MT9M032_PLL_CONFIG1_MUL_SHIFT 8
92#define MT9M032_READ_MODE1 0x1e 92#define MT9M032_READ_MODE1 0x1e
93#define MT9M032_READ_MODE1_OUTPUT_BAD_FRAMES (1 << 13)
94#define MT9M032_READ_MODE1_MAINTAIN_FRAME_RATE (1 << 12)
95#define MT9M032_READ_MODE1_XOR_LINE_VALID (1 << 11)
96#define MT9M032_READ_MODE1_CONT_LINE_VALID (1 << 10)
97#define MT9M032_READ_MODE1_INVERT_TRIGGER (1 << 9)
98#define MT9M032_READ_MODE1_SNAPSHOT (1 << 8)
99#define MT9M032_READ_MODE1_GLOBAL_RESET (1 << 7)
100#define MT9M032_READ_MODE1_BULB_EXPOSURE (1 << 6)
101#define MT9M032_READ_MODE1_INVERT_STROBE (1 << 5)
102#define MT9M032_READ_MODE1_STROBE_ENABLE (1 << 4)
103#define MT9M032_READ_MODE1_STROBE_START_TRIG1 (0 << 2)
104#define MT9M032_READ_MODE1_STROBE_START_EXP (1 << 2)
105#define MT9M032_READ_MODE1_STROBE_START_SHUTTER (2 << 2)
106#define MT9M032_READ_MODE1_STROBE_START_TRIG2 (3 << 2)
107#define MT9M032_READ_MODE1_STROBE_END_TRIG1 (0 << 0)
108#define MT9M032_READ_MODE1_STROBE_END_EXP (1 << 0)
109#define MT9M032_READ_MODE1_STROBE_END_SHUTTER (2 << 0)
110#define MT9M032_READ_MODE1_STROBE_END_TRIG2 (3 << 0)
93#define MT9M032_READ_MODE2 0x20 111#define MT9M032_READ_MODE2 0x20
94#define MT9M032_READ_MODE2_VFLIP_SHIFT 15 112#define MT9M032_READ_MODE2_VFLIP_SHIFT 15
95#define MT9M032_READ_MODE2_HFLIP_SHIFT 14 113#define MT9M032_READ_MODE2_HFLIP_SHIFT 14
@@ -106,6 +124,8 @@
106#define MT9M032_GAIN_AMUL_SHIFT 6 124#define MT9M032_GAIN_AMUL_SHIFT 6
107#define MT9M032_GAIN_ANALOG_MASK 0x3f 125#define MT9M032_GAIN_ANALOG_MASK 0x3f
108#define MT9M032_FORMATTER1 0x9e 126#define MT9M032_FORMATTER1 0x9e
127#define MT9M032_FORMATTER1_PLL_P1_6 (1 << 8)
128#define MT9M032_FORMATTER1_PARALLEL (1 << 12)
109#define MT9M032_FORMATTER2 0x9f 129#define MT9M032_FORMATTER2 0x9f
110#define MT9M032_FORMATTER2_DOUT_EN 0x1000 130#define MT9M032_FORMATTER2_DOUT_EN 0x1000
111#define MT9M032_FORMATTER2_PIXCLK_EN 0x2000 131#define MT9M032_FORMATTER2_PIXCLK_EN 0x2000
@@ -121,8 +141,6 @@
121#define MT9P031_PLL_CONTROL_PWROFF 0x0050 141#define MT9P031_PLL_CONTROL_PWROFF 0x0050
122#define MT9P031_PLL_CONTROL_PWRON 0x0051 142#define MT9P031_PLL_CONTROL_PWRON 0x0051
123#define MT9P031_PLL_CONTROL_USEPLL 0x0052 143#define MT9P031_PLL_CONTROL_USEPLL 0x0052
124#define MT9P031_PLL_CONFIG2 0x11
125#define MT9P031_PLL_CONFIG2_P1_DIV_MASK 0x1f
126 144
127struct mt9m032 { 145struct mt9m032 {
128 struct v4l2_subdev subdev; 146 struct v4l2_subdev subdev;
@@ -255,13 +273,14 @@ static int mt9m032_setup_pll(struct mt9m032 *sensor)
255 .n_max = 64, 273 .n_max = 64,
256 .m_min = 16, 274 .m_min = 16,
257 .m_max = 255, 275 .m_max = 255,
258 .p1_min = 1, 276 .p1_min = 6,
259 .p1_max = 128, 277 .p1_max = 7,
260 }; 278 };
261 279
262 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); 280 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev);
263 struct mt9m032_platform_data *pdata = sensor->pdata; 281 struct mt9m032_platform_data *pdata = sensor->pdata;
264 struct aptina_pll pll; 282 struct aptina_pll pll;
283 u16 reg_val;
265 int ret; 284 int ret;
266 285
267 pll.ext_clock = pdata->ext_clock; 286 pll.ext_clock = pdata->ext_clock;
@@ -274,18 +293,21 @@ static int mt9m032_setup_pll(struct mt9m032 *sensor)
274 sensor->pix_clock = pdata->pix_clock; 293 sensor->pix_clock = pdata->pix_clock;
275 294
276 ret = mt9m032_write(client, MT9M032_PLL_CONFIG1, 295 ret = mt9m032_write(client, MT9M032_PLL_CONFIG1,
277 (pll.m << MT9M032_PLL_CONFIG1_MUL_SHIFT) 296 (pll.m << MT9M032_PLL_CONFIG1_MUL_SHIFT) |
278 | (pll.p1 - 1)); 297 ((pll.n - 1) & MT9M032_PLL_CONFIG1_PREDIV_MASK));
279 if (!ret)
280 ret = mt9m032_write(client, MT9P031_PLL_CONFIG2, pll.n - 1);
281 if (!ret) 298 if (!ret)
282 ret = mt9m032_write(client, MT9P031_PLL_CONTROL, 299 ret = mt9m032_write(client, MT9P031_PLL_CONTROL,
283 MT9P031_PLL_CONTROL_PWRON | 300 MT9P031_PLL_CONTROL_PWRON |
284 MT9P031_PLL_CONTROL_USEPLL); 301 MT9P031_PLL_CONTROL_USEPLL);
285 if (!ret) /* more reserved, Continuous, Master Mode */ 302 if (!ret) /* more reserved, Continuous, Master Mode */
286 ret = mt9m032_write(client, MT9M032_READ_MODE1, 0x8006); 303 ret = mt9m032_write(client, MT9M032_READ_MODE1, 0x8000 |
287 if (!ret) /* Set 14-bit mode, select 7 divider */ 304 MT9M032_READ_MODE1_STROBE_START_EXP |
288 ret = mt9m032_write(client, MT9M032_FORMATTER1, 0x111e); 305 MT9M032_READ_MODE1_STROBE_END_SHUTTER);
306 if (!ret) {
307 reg_val = (pll.p1 == 6 ? MT9M032_FORMATTER1_PLL_P1_6 : 0)
308 | MT9M032_FORMATTER1_PARALLEL | 0x001e; /* 14-bit */
309 ret = mt9m032_write(client, MT9M032_FORMATTER1, reg_val);
310 }
289 311
290 return ret; 312 return ret;
291} 313}
@@ -548,7 +570,7 @@ static int mt9m032_g_register(struct v4l2_subdev *sd,
548} 570}
549 571
550static int mt9m032_s_register(struct v4l2_subdev *sd, 572static int mt9m032_s_register(struct v4l2_subdev *sd,
551 struct v4l2_dbg_register *reg) 573 const struct v4l2_dbg_register *reg)
552{ 574{
553 struct mt9m032 *sensor = to_mt9m032(sd); 575 struct mt9m032 *sensor = to_mt9m032(sd);
554 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); 576 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev);
diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c
index e32833262d32..28cf95b37285 100644
--- a/drivers/media/i2c/mt9p031.c
+++ b/drivers/media/i2c/mt9p031.c
@@ -12,6 +12,7 @@
12 * published by the Free Software Foundation. 12 * published by the Free Software Foundation.
13 */ 13 */
14 14
15#include <linux/clk.h>
15#include <linux/delay.h> 16#include <linux/delay.h>
16#include <linux/device.h> 17#include <linux/device.h>
17#include <linux/gpio.h> 18#include <linux/gpio.h>
@@ -19,6 +20,7 @@
19#include <linux/i2c.h> 20#include <linux/i2c.h>
20#include <linux/log2.h> 21#include <linux/log2.h>
21#include <linux/pm.h> 22#include <linux/pm.h>
23#include <linux/regulator/consumer.h>
22#include <linux/slab.h> 24#include <linux/slab.h>
23#include <linux/videodev2.h> 25#include <linux/videodev2.h>
24 26
@@ -121,6 +123,11 @@ struct mt9p031 {
121 struct mutex power_lock; /* lock to protect power_count */ 123 struct mutex power_lock; /* lock to protect power_count */
122 int power_count; 124 int power_count;
123 125
126 struct clk *clk;
127 struct regulator *vaa;
128 struct regulator *vdd;
129 struct regulator *vdd_io;
130
124 enum mt9p031_model model; 131 enum mt9p031_model model;
125 struct aptina_pll pll; 132 struct aptina_pll pll;
126 int reset; 133 int reset;
@@ -195,7 +202,7 @@ static int mt9p031_reset(struct mt9p031 *mt9p031)
195 0); 202 0);
196} 203}
197 204
198static int mt9p031_pll_setup(struct mt9p031 *mt9p031) 205static int mt9p031_clk_setup(struct mt9p031 *mt9p031)
199{ 206{
200 static const struct aptina_pll_limits limits = { 207 static const struct aptina_pll_limits limits = {
201 .ext_clock_min = 6000000, 208 .ext_clock_min = 6000000,
@@ -216,6 +223,12 @@ static int mt9p031_pll_setup(struct mt9p031 *mt9p031)
216 struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); 223 struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
217 struct mt9p031_platform_data *pdata = mt9p031->pdata; 224 struct mt9p031_platform_data *pdata = mt9p031->pdata;
218 225
226 mt9p031->clk = devm_clk_get(&client->dev, NULL);
227 if (IS_ERR(mt9p031->clk))
228 return PTR_ERR(mt9p031->clk);
229
230 clk_set_rate(mt9p031->clk, pdata->ext_freq);
231
219 mt9p031->pll.ext_clock = pdata->ext_freq; 232 mt9p031->pll.ext_clock = pdata->ext_freq;
220 mt9p031->pll.pix_clock = pdata->target_freq; 233 mt9p031->pll.pix_clock = pdata->target_freq;
221 234
@@ -264,10 +277,14 @@ static int mt9p031_power_on(struct mt9p031 *mt9p031)
264 usleep_range(1000, 2000); 277 usleep_range(1000, 2000);
265 } 278 }
266 279
280 /* Bring up the supplies */
281 regulator_enable(mt9p031->vdd);
282 regulator_enable(mt9p031->vdd_io);
283 regulator_enable(mt9p031->vaa);
284
267 /* Emable clock */ 285 /* Emable clock */
268 if (mt9p031->pdata->set_xclk) 286 if (mt9p031->clk)
269 mt9p031->pdata->set_xclk(&mt9p031->subdev, 287 clk_prepare_enable(mt9p031->clk);
270 mt9p031->pdata->ext_freq);
271 288
272 /* Now RESET_BAR must be high */ 289 /* Now RESET_BAR must be high */
273 if (mt9p031->reset != -1) { 290 if (mt9p031->reset != -1) {
@@ -285,8 +302,12 @@ static void mt9p031_power_off(struct mt9p031 *mt9p031)
285 usleep_range(1000, 2000); 302 usleep_range(1000, 2000);
286 } 303 }
287 304
288 if (mt9p031->pdata->set_xclk) 305 regulator_disable(mt9p031->vaa);
289 mt9p031->pdata->set_xclk(&mt9p031->subdev, 0); 306 regulator_disable(mt9p031->vdd_io);
307 regulator_disable(mt9p031->vdd);
308
309 if (mt9p031->clk)
310 clk_disable_unprepare(mt9p031->clk);
290} 311}
291 312
292static int __mt9p031_set_power(struct mt9p031 *mt9p031, bool on) 313static int __mt9p031_set_power(struct mt9p031 *mt9p031, bool on)
@@ -927,7 +948,7 @@ static int mt9p031_probe(struct i2c_client *client,
927 return -EIO; 948 return -EIO;
928 } 949 }
929 950
930 mt9p031 = kzalloc(sizeof(*mt9p031), GFP_KERNEL); 951 mt9p031 = devm_kzalloc(&client->dev, sizeof(*mt9p031), GFP_KERNEL);
931 if (mt9p031 == NULL) 952 if (mt9p031 == NULL)
932 return -ENOMEM; 953 return -ENOMEM;
933 954
@@ -937,6 +958,16 @@ static int mt9p031_probe(struct i2c_client *client,
937 mt9p031->model = did->driver_data; 958 mt9p031->model = did->driver_data;
938 mt9p031->reset = -1; 959 mt9p031->reset = -1;
939 960
961 mt9p031->vaa = devm_regulator_get(&client->dev, "vaa");
962 mt9p031->vdd = devm_regulator_get(&client->dev, "vdd");
963 mt9p031->vdd_io = devm_regulator_get(&client->dev, "vdd_io");
964
965 if (IS_ERR(mt9p031->vaa) || IS_ERR(mt9p031->vdd) ||
966 IS_ERR(mt9p031->vdd_io)) {
967 dev_err(&client->dev, "Unable to get regulators\n");
968 return -ENODEV;
969 }
970
940 v4l2_ctrl_handler_init(&mt9p031->ctrls, ARRAY_SIZE(mt9p031_ctrls) + 6); 971 v4l2_ctrl_handler_init(&mt9p031->ctrls, ARRAY_SIZE(mt9p031_ctrls) + 6);
941 972
942 v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops, 973 v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops,
@@ -1001,24 +1032,20 @@ static int mt9p031_probe(struct i2c_client *client,
1001 mt9p031->format.colorspace = V4L2_COLORSPACE_SRGB; 1032 mt9p031->format.colorspace = V4L2_COLORSPACE_SRGB;
1002 1033
1003 if (pdata->reset != -1) { 1034 if (pdata->reset != -1) {
1004 ret = gpio_request_one(pdata->reset, GPIOF_OUT_INIT_LOW, 1035 ret = devm_gpio_request_one(&client->dev, pdata->reset,
1005 "mt9p031_rst"); 1036 GPIOF_OUT_INIT_LOW, "mt9p031_rst");
1006 if (ret < 0) 1037 if (ret < 0)
1007 goto done; 1038 goto done;
1008 1039
1009 mt9p031->reset = pdata->reset; 1040 mt9p031->reset = pdata->reset;
1010 } 1041 }
1011 1042
1012 ret = mt9p031_pll_setup(mt9p031); 1043 ret = mt9p031_clk_setup(mt9p031);
1013 1044
1014done: 1045done:
1015 if (ret < 0) { 1046 if (ret < 0) {
1016 if (mt9p031->reset != -1)
1017 gpio_free(mt9p031->reset);
1018
1019 v4l2_ctrl_handler_free(&mt9p031->ctrls); 1047 v4l2_ctrl_handler_free(&mt9p031->ctrls);
1020 media_entity_cleanup(&mt9p031->subdev.entity); 1048 media_entity_cleanup(&mt9p031->subdev.entity);
1021 kfree(mt9p031);
1022 } 1049 }
1023 1050
1024 return ret; 1051 return ret;
@@ -1032,9 +1059,6 @@ static int mt9p031_remove(struct i2c_client *client)
1032 v4l2_ctrl_handler_free(&mt9p031->ctrls); 1059 v4l2_ctrl_handler_free(&mt9p031->ctrls);
1033 v4l2_device_unregister_subdev(subdev); 1060 v4l2_device_unregister_subdev(subdev);
1034 media_entity_cleanup(&subdev->entity); 1061 media_entity_cleanup(&subdev->entity);
1035 if (mt9p031->reset != -1)
1036 gpio_free(mt9p031->reset);
1037 kfree(mt9p031);
1038 1062
1039 return 0; 1063 return 0;
1040} 1064}
diff --git a/drivers/media/i2c/mt9v011.c b/drivers/media/i2c/mt9v011.c
index 73b7688cbebd..3f415fd12de3 100644
--- a/drivers/media/i2c/mt9v011.c
+++ b/drivers/media/i2c/mt9v011.c
@@ -421,7 +421,7 @@ static int mt9v011_g_register(struct v4l2_subdev *sd,
421} 421}
422 422
423static int mt9v011_s_register(struct v4l2_subdev *sd, 423static int mt9v011_s_register(struct v4l2_subdev *sd,
424 struct v4l2_dbg_register *reg) 424 const struct v4l2_dbg_register *reg)
425{ 425{
426 struct i2c_client *client = v4l2_get_subdevdata(sd); 426 struct i2c_client *client = v4l2_get_subdevdata(sd);
427 427
diff --git a/drivers/media/i2c/ov7640.c b/drivers/media/i2c/ov7640.c
new file mode 100644
index 000000000000..b0cc927e8b19
--- /dev/null
+++ b/drivers/media/i2c/ov7640.c
@@ -0,0 +1,106 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/init.h>
19#include <linux/module.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <media/v4l2-device.h>
23#include <media/v4l2-chip-ident.h>
24#include <linux/slab.h>
25
26MODULE_DESCRIPTION("OmniVision ov7640 sensor driver");
27MODULE_LICENSE("GPL v2");
28
29static const u8 initial_registers[] = {
30 0x12, 0x80,
31 0x12, 0x54,
32 0x14, 0x24,
33 0x15, 0x01,
34 0x28, 0x20,
35 0x75, 0x82,
36 0xFF, 0xFF, /* Terminator (reg 0xFF is unused) */
37};
38
39static int write_regs(struct i2c_client *client, const u8 *regs)
40{
41 int i;
42
43 for (i = 0; regs[i] != 0xFF; i += 2)
44 if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0)
45 return -1;
46 return 0;
47}
48
49/* ----------------------------------------------------------------------- */
50
51static const struct v4l2_subdev_ops ov7640_ops;
52
53static int ov7640_probe(struct i2c_client *client,
54 const struct i2c_device_id *id)
55{
56 struct i2c_adapter *adapter = client->adapter;
57 struct v4l2_subdev *sd;
58
59 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
60 return -ENODEV;
61
62 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
63 if (sd == NULL)
64 return -ENOMEM;
65 v4l2_i2c_subdev_init(sd, client, &ov7640_ops);
66
67 client->flags = I2C_CLIENT_SCCB;
68
69 v4l_info(client, "chip found @ 0x%02x (%s)\n",
70 client->addr << 1, client->adapter->name);
71
72 if (write_regs(client, initial_registers) < 0) {
73 v4l_err(client, "error initializing OV7640\n");
74 kfree(sd);
75 return -ENODEV;
76 }
77
78 return 0;
79}
80
81
82static int ov7640_remove(struct i2c_client *client)
83{
84 struct v4l2_subdev *sd = i2c_get_clientdata(client);
85
86 v4l2_device_unregister_subdev(sd);
87 kfree(sd);
88 return 0;
89}
90
91static const struct i2c_device_id ov7640_id[] = {
92 { "ov7640", 0 },
93 { }
94};
95MODULE_DEVICE_TABLE(i2c, ov7640_id);
96
97static struct i2c_driver ov7640_driver = {
98 .driver = {
99 .owner = THIS_MODULE,
100 .name = "ov7640",
101 },
102 .probe = ov7640_probe,
103 .remove = ov7640_remove,
104 .id_table = ov7640_id,
105};
106module_i2c_driver(ov7640_driver);
diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
index 05ed5b8e7f88..617ad3fff4aa 100644
--- a/drivers/media/i2c/ov7670.c
+++ b/drivers/media/i2c/ov7670.c
@@ -1487,7 +1487,7 @@ static int ov7670_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *r
1487 return ret; 1487 return ret;
1488} 1488}
1489 1489
1490static int ov7670_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 1490static int ov7670_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
1491{ 1491{
1492 struct i2c_client *client = v4l2_get_subdevdata(sd); 1492 struct i2c_client *client = v4l2_get_subdevdata(sd);
1493 1493
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 5dbb65e1f6b7..cb52438e53ac 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -357,7 +357,7 @@ static int s5c73m3_load_fw(struct v4l2_subdev *sd)
357 return -EINVAL; 357 return -EINVAL;
358 } 358 }
359 359
360 v4l2_info(sd, "Loading firmware (%s, %d B)\n", fw_name, fw->size); 360 v4l2_info(sd, "Loading firmware (%s, %zu B)\n", fw_name, fw->size);
361 361
362 ret = s5c73m3_spi_write(state, fw->data, fw->size, 64); 362 ret = s5c73m3_spi_write(state, fw->data, fw->size, 64);
363 363
@@ -1457,6 +1457,12 @@ static int s5c73m3_oif_registered(struct v4l2_subdev *sd)
1457 return ret; 1457 return ret;
1458} 1458}
1459 1459
1460static void s5c73m3_oif_unregistered(struct v4l2_subdev *sd)
1461{
1462 struct s5c73m3 *state = oif_sd_to_s5c73m3(sd);
1463 v4l2_device_unregister_subdev(&state->sensor_sd);
1464}
1465
1460static const struct v4l2_subdev_internal_ops s5c73m3_internal_ops = { 1466static const struct v4l2_subdev_internal_ops s5c73m3_internal_ops = {
1461 .open = s5c73m3_open, 1467 .open = s5c73m3_open,
1462}; 1468};
@@ -1474,6 +1480,7 @@ static const struct v4l2_subdev_ops s5c73m3_subdev_ops = {
1474 1480
1475static const struct v4l2_subdev_internal_ops oif_internal_ops = { 1481static const struct v4l2_subdev_internal_ops oif_internal_ops = {
1476 .registered = s5c73m3_oif_registered, 1482 .registered = s5c73m3_oif_registered,
1483 .unregistered = s5c73m3_oif_unregistered,
1477 .open = s5c73m3_oif_open, 1484 .open = s5c73m3_oif_open,
1478}; 1485};
1479 1486
@@ -1668,13 +1675,17 @@ out_err1:
1668 1675
1669static int s5c73m3_remove(struct i2c_client *client) 1676static int s5c73m3_remove(struct i2c_client *client)
1670{ 1677{
1671 struct v4l2_subdev *sd = i2c_get_clientdata(client); 1678 struct v4l2_subdev *oif_sd = i2c_get_clientdata(client);
1672 struct s5c73m3 *state = sensor_sd_to_s5c73m3(sd); 1679 struct s5c73m3 *state = oif_sd_to_s5c73m3(oif_sd);
1680 struct v4l2_subdev *sensor_sd = &state->sensor_sd;
1673 1681
1674 v4l2_device_unregister_subdev(sd); 1682 v4l2_device_unregister_subdev(oif_sd);
1675 1683
1676 v4l2_ctrl_handler_free(sd->ctrl_handler); 1684 v4l2_ctrl_handler_free(oif_sd->ctrl_handler);
1677 media_entity_cleanup(&sd->entity); 1685 media_entity_cleanup(&oif_sd->entity);
1686
1687 v4l2_device_unregister_subdev(sensor_sd);
1688 media_entity_cleanup(&sensor_sd->entity);
1678 1689
1679 s5c73m3_unregister_spi_driver(state); 1690 s5c73m3_unregister_spi_driver(state);
1680 s5c73m3_free_gpios(state); 1691 s5c73m3_free_gpios(state);
diff --git a/drivers/media/i2c/saa6588.c b/drivers/media/i2c/saa6588.c
index 0caac50d7cf4..b4e1ccbd87ec 100644
--- a/drivers/media/i2c/saa6588.c
+++ b/drivers/media/i2c/saa6588.c
@@ -435,7 +435,7 @@ static int saa6588_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
435 return 0; 435 return 0;
436} 436}
437 437
438static int saa6588_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 438static int saa6588_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
439{ 439{
440 struct saa6588 *s = to_saa6588(sd); 440 struct saa6588 *s = to_saa6588(sd);
441 441
diff --git a/drivers/media/i2c/saa7115.c b/drivers/media/i2c/saa7115.c
index 6b6788cd08f6..52c717d977c9 100644
--- a/drivers/media/i2c/saa7115.c
+++ b/drivers/media/i2c/saa7115.c
@@ -83,9 +83,10 @@ struct saa711x_state {
83 u32 ident; 83 u32 ident;
84 u32 audclk_freq; 84 u32 audclk_freq;
85 u32 crystal_freq; 85 u32 crystal_freq;
86 u8 ucgc; 86 bool ucgc;
87 u8 cgcdiv; 87 u8 cgcdiv;
88 u8 apll; 88 bool apll;
89 bool double_asclk;
89}; 90};
90 91
91static inline struct saa711x_state *to_state(struct v4l2_subdev *sd) 92static inline struct saa711x_state *to_state(struct v4l2_subdev *sd)
@@ -732,8 +733,12 @@ static int saa711x_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
732 if (state->apll) 733 if (state->apll)
733 acc |= 0x08; 734 acc |= 0x08;
734 735
736 if (state->double_asclk) {
737 acpf <<= 1;
738 acni <<= 1;
739 }
735 saa711x_write(sd, R_38_CLK_RATIO_AMXCLK_TO_ASCLK, 0x03); 740 saa711x_write(sd, R_38_CLK_RATIO_AMXCLK_TO_ASCLK, 0x03);
736 saa711x_write(sd, R_39_CLK_RATIO_ASCLK_TO_ALRCLK, 0x10); 741 saa711x_write(sd, R_39_CLK_RATIO_ASCLK_TO_ALRCLK, 0x10 << state->double_asclk);
737 saa711x_write(sd, R_3A_AUD_CLK_GEN_BASIC_SETUP, acc); 742 saa711x_write(sd, R_3A_AUD_CLK_GEN_BASIC_SETUP, acc);
738 743
739 saa711x_write(sd, R_30_AUD_MAST_CLK_CYCLES_PER_FIELD, acpf & 0xff); 744 saa711x_write(sd, R_30_AUD_MAST_CLK_CYCLES_PER_FIELD, acpf & 0xff);
@@ -1259,6 +1264,12 @@ static int saa711x_s_routing(struct v4l2_subdev *sd,
1259 (saa711x_read(sd, R_83_X_PORT_I_O_ENA_AND_OUT_CLK) & 0xfe) | 1264 (saa711x_read(sd, R_83_X_PORT_I_O_ENA_AND_OUT_CLK) & 0xfe) |
1260 (state->output & 0x01)); 1265 (state->output & 0x01));
1261 } 1266 }
1267 if (state->ident > V4L2_IDENT_SAA7111A) {
1268 if (config & SAA7115_IDQ_IS_DEFAULT)
1269 saa711x_write(sd, R_85_I_PORT_SIGNAL_POLAR, 0x20);
1270 else
1271 saa711x_write(sd, R_85_I_PORT_SIGNAL_POLAR, 0x21);
1272 }
1262 return 0; 1273 return 0;
1263} 1274}
1264 1275
@@ -1296,9 +1307,10 @@ static int saa711x_s_crystal_freq(struct v4l2_subdev *sd, u32 freq, u32 flags)
1296 if (freq != SAA7115_FREQ_32_11_MHZ && freq != SAA7115_FREQ_24_576_MHZ) 1307 if (freq != SAA7115_FREQ_32_11_MHZ && freq != SAA7115_FREQ_24_576_MHZ)
1297 return -EINVAL; 1308 return -EINVAL;
1298 state->crystal_freq = freq; 1309 state->crystal_freq = freq;
1310 state->double_asclk = flags & SAA7115_FREQ_FL_DOUBLE_ASCLK;
1299 state->cgcdiv = (flags & SAA7115_FREQ_FL_CGCDIV) ? 3 : 4; 1311 state->cgcdiv = (flags & SAA7115_FREQ_FL_CGCDIV) ? 3 : 4;
1300 state->ucgc = (flags & SAA7115_FREQ_FL_UCGC) ? 1 : 0; 1312 state->ucgc = flags & SAA7115_FREQ_FL_UCGC;
1301 state->apll = (flags & SAA7115_FREQ_FL_APLL) ? 1 : 0; 1313 state->apll = flags & SAA7115_FREQ_FL_APLL;
1302 saa711x_s_clock_freq(sd, state->audclk_freq); 1314 saa711x_s_clock_freq(sd, state->audclk_freq);
1303 return 0; 1315 return 0;
1304} 1316}
@@ -1354,6 +1366,34 @@ static int saa711x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
1354 */ 1366 */
1355 1367
1356 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC); 1368 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC);
1369
1370 if (state->ident == V4L2_IDENT_SAA7115) {
1371 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC);
1372
1373 v4l2_dbg(1, debug, sd, "Status byte 1 (0x1e)=0x%02x\n", reg1e);
1374
1375 switch (reg1e & 0x03) {
1376 case 1:
1377 *std &= V4L2_STD_NTSC;
1378 break;
1379 case 2:
1380 /*
1381 * V4L2_STD_PAL just cover the european PAL standards.
1382 * This is wrong, as the device could also be using an
1383 * other PAL standard.
1384 */
1385 *std &= V4L2_STD_PAL | V4L2_STD_PAL_N | V4L2_STD_PAL_Nc |
1386 V4L2_STD_PAL_M | V4L2_STD_PAL_60;
1387 break;
1388 case 3:
1389 *std &= V4L2_STD_SECAM;
1390 break;
1391 default:
1392 /* Can't detect anything */
1393 break;
1394 }
1395 }
1396
1357 v4l2_dbg(1, debug, sd, "Status byte 2 (0x1f)=0x%02x\n", reg1f); 1397 v4l2_dbg(1, debug, sd, "Status byte 2 (0x1f)=0x%02x\n", reg1f);
1358 1398
1359 /* horizontal/vertical not locked */ 1399 /* horizontal/vertical not locked */
@@ -1365,34 +1405,6 @@ static int saa711x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
1365 else 1405 else
1366 *std &= V4L2_STD_625_50; 1406 *std &= V4L2_STD_625_50;
1367 1407
1368 if (state->ident != V4L2_IDENT_SAA7115)
1369 goto ret;
1370
1371 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC);
1372
1373 switch (reg1e & 0x03) {
1374 case 1:
1375 *std &= V4L2_STD_NTSC;
1376 break;
1377 case 2:
1378 /*
1379 * V4L2_STD_PAL just cover the european PAL standards.
1380 * This is wrong, as the device could also be using an
1381 * other PAL standard.
1382 */
1383 *std &= V4L2_STD_PAL | V4L2_STD_PAL_N | V4L2_STD_PAL_Nc |
1384 V4L2_STD_PAL_M | V4L2_STD_PAL_60;
1385 break;
1386 case 3:
1387 *std &= V4L2_STD_SECAM;
1388 break;
1389 default:
1390 /* Can't detect anything */
1391 break;
1392 }
1393
1394 v4l2_dbg(1, debug, sd, "Status byte 1 (0x1e)=0x%02x\n", reg1e);
1395
1396ret: 1408ret:
1397 v4l2_dbg(1, debug, sd, "detected std mask = %08Lx\n", *std); 1409 v4l2_dbg(1, debug, sd, "detected std mask = %08Lx\n", *std);
1398 1410
@@ -1428,7 +1440,7 @@ static int saa711x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
1428 return 0; 1440 return 0;
1429} 1441}
1430 1442
1431static int saa711x_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 1443static int saa711x_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
1432{ 1444{
1433 struct i2c_client *client = v4l2_get_subdevdata(sd); 1445 struct i2c_client *client = v4l2_get_subdevdata(sd);
1434 1446
diff --git a/drivers/media/i2c/saa7127.c b/drivers/media/i2c/saa7127.c
index b745f68fbc92..8a47ac10927f 100644
--- a/drivers/media/i2c/saa7127.c
+++ b/drivers/media/i2c/saa7127.c
@@ -672,7 +672,7 @@ static int saa7127_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
672 return 0; 672 return 0;
673} 673}
674 674
675static int saa7127_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 675static int saa7127_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
676{ 676{
677 struct i2c_client *client = v4l2_get_subdevdata(sd); 677 struct i2c_client *client = v4l2_get_subdevdata(sd);
678 678
diff --git a/drivers/media/i2c/saa717x.c b/drivers/media/i2c/saa717x.c
index 1e84466515aa..cf3a0aa7e45e 100644
--- a/drivers/media/i2c/saa717x.c
+++ b/drivers/media/i2c/saa717x.c
@@ -988,7 +988,7 @@ static int saa717x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
988 return 0; 988 return 0;
989} 989}
990 990
991static int saa717x_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 991static int saa717x_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
992{ 992{
993 struct i2c_client *client = v4l2_get_subdevdata(sd); 993 struct i2c_client *client = v4l2_get_subdevdata(sd);
994 u16 addr = reg->reg & 0xffff; 994 u16 addr = reg->reg & 0xffff;
@@ -1113,7 +1113,7 @@ static int saa717x_s_stream(struct v4l2_subdev *sd, int enable)
1113} 1113}
1114 1114
1115/* change audio mode */ 1115/* change audio mode */
1116static int saa717x_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 1116static int saa717x_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
1117{ 1117{
1118 struct saa717x_state *decoder = to_state(sd); 1118 struct saa717x_state *decoder = to_state(sd);
1119 int audio_mode; 1119 int audio_mode;
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 83c7ed7ffcc2..cae4f4683851 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2833,7 +2833,7 @@ static int smiapp_probe(struct i2c_client *client,
2833 sensor->src->pads, 0); 2833 sensor->src->pads, 0);
2834} 2834}
2835 2835
2836static int __exit smiapp_remove(struct i2c_client *client) 2836static int smiapp_remove(struct i2c_client *client)
2837{ 2837{
2838 struct v4l2_subdev *subdev = i2c_get_clientdata(client); 2838 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
2839 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev); 2839 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
@@ -2881,7 +2881,7 @@ static struct i2c_driver smiapp_i2c_driver = {
2881 .pm = &smiapp_pm_ops, 2881 .pm = &smiapp_pm_ops,
2882 }, 2882 },
2883 .probe = smiapp_probe, 2883 .probe = smiapp_probe,
2884 .remove = __exit_p(smiapp_remove), 2884 .remove = smiapp_remove,
2885 .id_table = smiapp_id_table, 2885 .id_table = smiapp_id_table,
2886}; 2886};
2887 2887
diff --git a/drivers/media/i2c/soc_camera/Kconfig b/drivers/media/i2c/soc_camera/Kconfig
index 6dff2b7ad520..23d352f0adf0 100644
--- a/drivers/media/i2c/soc_camera/Kconfig
+++ b/drivers/media/i2c/soc_camera/Kconfig
@@ -9,7 +9,6 @@ config SOC_CAMERA_IMX074
9config SOC_CAMERA_MT9M001 9config SOC_CAMERA_MT9M001
10 tristate "mt9m001 support" 10 tristate "mt9m001 support"
11 depends on SOC_CAMERA && I2C 11 depends on SOC_CAMERA && I2C
12 select GPIO_PCA953X if MT9M001_PCA9536_SWITCH
13 help 12 help
14 This driver supports MT9M001 cameras from Micron, monochrome 13 This driver supports MT9M001 cameras from Micron, monochrome
15 and colour models. 14 and colour models.
@@ -36,7 +35,6 @@ config SOC_CAMERA_MT9T112
36config SOC_CAMERA_MT9V022 35config SOC_CAMERA_MT9V022
37 tristate "mt9v022 and mt9v024 support" 36 tristate "mt9v022 and mt9v024 support"
38 depends on SOC_CAMERA && I2C 37 depends on SOC_CAMERA && I2C
39 select GPIO_PCA953X if MT9V022_PCA9536_SWITCH
40 help 38 help
41 This driver supports MT9V022 cameras from Micron 39 This driver supports MT9V022 cameras from Micron
42 40
diff --git a/drivers/media/i2c/soc_camera/mt9m001.c b/drivers/media/i2c/soc_camera/mt9m001.c
index bcdc86175549..dd9089805757 100644
--- a/drivers/media/i2c/soc_camera/mt9m001.c
+++ b/drivers/media/i2c/soc_camera/mt9m001.c
@@ -360,7 +360,7 @@ static int mt9m001_g_register(struct v4l2_subdev *sd,
360} 360}
361 361
362static int mt9m001_s_register(struct v4l2_subdev *sd, 362static int mt9m001_s_register(struct v4l2_subdev *sd,
363 struct v4l2_dbg_register *reg) 363 const struct v4l2_dbg_register *reg)
364{ 364{
365 struct i2c_client *client = v4l2_get_subdevdata(sd); 365 struct i2c_client *client = v4l2_get_subdevdata(sd);
366 366
diff --git a/drivers/media/i2c/soc_camera/mt9m111.c b/drivers/media/i2c/soc_camera/mt9m111.c
index bbc4ff99603c..8bd4e0d2ea03 100644
--- a/drivers/media/i2c/soc_camera/mt9m111.c
+++ b/drivers/media/i2c/soc_camera/mt9m111.c
@@ -641,7 +641,7 @@ static int mt9m111_g_register(struct v4l2_subdev *sd,
641} 641}
642 642
643static int mt9m111_s_register(struct v4l2_subdev *sd, 643static int mt9m111_s_register(struct v4l2_subdev *sd,
644 struct v4l2_dbg_register *reg) 644 const struct v4l2_dbg_register *reg)
645{ 645{
646 struct i2c_client *client = v4l2_get_subdevdata(sd); 646 struct i2c_client *client = v4l2_get_subdevdata(sd);
647 647
@@ -701,11 +701,11 @@ static int mt9m111_set_global_gain(struct mt9m111 *mt9m111, int gain)
701 return reg_write(GLOBAL_GAIN, val); 701 return reg_write(GLOBAL_GAIN, val);
702} 702}
703 703
704static int mt9m111_set_autoexposure(struct mt9m111 *mt9m111, int on) 704static int mt9m111_set_autoexposure(struct mt9m111 *mt9m111, int val)
705{ 705{
706 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); 706 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
707 707
708 if (on) 708 if (val == V4L2_EXPOSURE_AUTO)
709 return reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN); 709 return reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
710 return reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN); 710 return reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
711} 711}
@@ -785,8 +785,6 @@ static int mt9m111_init(struct mt9m111 *mt9m111)
785 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); 785 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
786 int ret; 786 int ret;
787 787
788 /* Default HIGHPOWER context */
789 mt9m111->ctx = &context_b;
790 ret = mt9m111_enable(mt9m111); 788 ret = mt9m111_enable(mt9m111);
791 if (!ret) 789 if (!ret)
792 ret = mt9m111_reset(mt9m111); 790 ret = mt9m111_reset(mt9m111);
@@ -975,6 +973,9 @@ static int mt9m111_probe(struct i2c_client *client,
975 if (!mt9m111) 973 if (!mt9m111)
976 return -ENOMEM; 974 return -ENOMEM;
977 975
976 /* Default HIGHPOWER context */
977 mt9m111->ctx = &context_b;
978
978 v4l2_i2c_subdev_init(&mt9m111->subdev, client, &mt9m111_subdev_ops); 979 v4l2_i2c_subdev_init(&mt9m111->subdev, client, &mt9m111_subdev_ops);
979 v4l2_ctrl_handler_init(&mt9m111->hdl, 5); 980 v4l2_ctrl_handler_init(&mt9m111->hdl, 5);
980 v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops, 981 v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
diff --git a/drivers/media/i2c/soc_camera/mt9t031.c b/drivers/media/i2c/soc_camera/mt9t031.c
index d80d044ebf15..26a15b87a9a2 100644
--- a/drivers/media/i2c/soc_camera/mt9t031.c
+++ b/drivers/media/i2c/soc_camera/mt9t031.c
@@ -430,7 +430,7 @@ static int mt9t031_g_register(struct v4l2_subdev *sd,
430} 430}
431 431
432static int mt9t031_s_register(struct v4l2_subdev *sd, 432static int mt9t031_s_register(struct v4l2_subdev *sd,
433 struct v4l2_dbg_register *reg) 433 const struct v4l2_dbg_register *reg)
434{ 434{
435 struct i2c_client *client = v4l2_get_subdevdata(sd); 435 struct i2c_client *client = v4l2_get_subdevdata(sd);
436 436
diff --git a/drivers/media/i2c/soc_camera/mt9t112.c b/drivers/media/i2c/soc_camera/mt9t112.c
index 188e29b03273..a7256b732804 100644
--- a/drivers/media/i2c/soc_camera/mt9t112.c
+++ b/drivers/media/i2c/soc_camera/mt9t112.c
@@ -766,7 +766,7 @@ static int mt9t112_g_register(struct v4l2_subdev *sd,
766} 766}
767 767
768static int mt9t112_s_register(struct v4l2_subdev *sd, 768static int mt9t112_s_register(struct v4l2_subdev *sd,
769 struct v4l2_dbg_register *reg) 769 const struct v4l2_dbg_register *reg)
770{ 770{
771 struct i2c_client *client = v4l2_get_subdevdata(sd); 771 struct i2c_client *client = v4l2_get_subdevdata(sd);
772 int ret; 772 int ret;
diff --git a/drivers/media/i2c/soc_camera/mt9v022.c b/drivers/media/i2c/soc_camera/mt9v022.c
index a5e65d6a0781..a295e598486f 100644
--- a/drivers/media/i2c/soc_camera/mt9v022.c
+++ b/drivers/media/i2c/soc_camera/mt9v022.c
@@ -275,6 +275,7 @@ static int mt9v022_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a)
275 struct i2c_client *client = v4l2_get_subdevdata(sd); 275 struct i2c_client *client = v4l2_get_subdevdata(sd);
276 struct mt9v022 *mt9v022 = to_mt9v022(client); 276 struct mt9v022 *mt9v022 = to_mt9v022(client);
277 struct v4l2_rect rect = a->c; 277 struct v4l2_rect rect = a->c;
278 int min_row, min_blank;
278 int ret; 279 int ret;
279 280
280 /* Bayer format - even size lengths */ 281 /* Bayer format - even size lengths */
@@ -310,13 +311,21 @@ static int mt9v022_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a)
310 ret = reg_write(client, MT9V022_COLUMN_START, rect.left); 311 ret = reg_write(client, MT9V022_COLUMN_START, rect.left);
311 if (!ret) 312 if (!ret)
312 ret = reg_write(client, MT9V022_ROW_START, rect.top); 313 ret = reg_write(client, MT9V022_ROW_START, rect.top);
314 /*
315 * mt9v022: min total row time is 660 columns, min blanking is 43
316 * mt9v024: min total row time is 690 columns, min blanking is 61
317 */
318 if (is_mt9v024(mt9v022->chip_version)) {
319 min_row = 690;
320 min_blank = 61;
321 } else {
322 min_row = 660;
323 min_blank = 43;
324 }
313 if (!ret) 325 if (!ret)
314 /*
315 * Default 94, Phytec driver says:
316 * "width + horizontal blank >= 660"
317 */
318 ret = v4l2_ctrl_s_ctrl(mt9v022->hblank, 326 ret = v4l2_ctrl_s_ctrl(mt9v022->hblank,
319 rect.width > 660 - 43 ? 43 : 660 - rect.width); 327 rect.width > min_row - min_blank ?
328 min_blank : min_row - rect.width);
320 if (!ret) 329 if (!ret)
321 ret = v4l2_ctrl_s_ctrl(mt9v022->vblank, 45); 330 ret = v4l2_ctrl_s_ctrl(mt9v022->vblank, 45);
322 if (!ret) 331 if (!ret)
@@ -488,7 +497,7 @@ static int mt9v022_g_register(struct v4l2_subdev *sd,
488} 497}
489 498
490static int mt9v022_s_register(struct v4l2_subdev *sd, 499static int mt9v022_s_register(struct v4l2_subdev *sd,
491 struct v4l2_dbg_register *reg) 500 const struct v4l2_dbg_register *reg)
492{ 501{
493 struct i2c_client *client = v4l2_get_subdevdata(sd); 502 struct i2c_client *client = v4l2_get_subdevdata(sd);
494 503
diff --git a/drivers/media/i2c/soc_camera/ov2640.c b/drivers/media/i2c/soc_camera/ov2640.c
index 0f520f693b6e..e3168424f9ba 100644
--- a/drivers/media/i2c/soc_camera/ov2640.c
+++ b/drivers/media/i2c/soc_camera/ov2640.c
@@ -756,7 +756,7 @@ static int ov2640_g_register(struct v4l2_subdev *sd,
756} 756}
757 757
758static int ov2640_s_register(struct v4l2_subdev *sd, 758static int ov2640_s_register(struct v4l2_subdev *sd,
759 struct v4l2_dbg_register *reg) 759 const struct v4l2_dbg_register *reg)
760{ 760{
761 struct i2c_client *client = v4l2_get_subdevdata(sd); 761 struct i2c_client *client = v4l2_get_subdevdata(sd);
762 762
diff --git a/drivers/media/i2c/soc_camera/ov5642.c b/drivers/media/i2c/soc_camera/ov5642.c
index 9d53309619d2..9aa56de69eed 100644
--- a/drivers/media/i2c/soc_camera/ov5642.c
+++ b/drivers/media/i2c/soc_camera/ov5642.c
@@ -708,7 +708,7 @@ static int ov5642_get_register(struct v4l2_subdev *sd, struct v4l2_dbg_register
708 return ret; 708 return ret;
709} 709}
710 710
711static int ov5642_set_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 711static int ov5642_set_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
712{ 712{
713 struct i2c_client *client = v4l2_get_subdevdata(sd); 713 struct i2c_client *client = v4l2_get_subdevdata(sd);
714 714
diff --git a/drivers/media/i2c/soc_camera/ov6650.c b/drivers/media/i2c/soc_camera/ov6650.c
index dbe4f564e6b2..991202d4bbae 100644
--- a/drivers/media/i2c/soc_camera/ov6650.c
+++ b/drivers/media/i2c/soc_camera/ov6650.c
@@ -421,7 +421,7 @@ static int ov6650_get_register(struct v4l2_subdev *sd,
421} 421}
422 422
423static int ov6650_set_register(struct v4l2_subdev *sd, 423static int ov6650_set_register(struct v4l2_subdev *sd,
424 struct v4l2_dbg_register *reg) 424 const struct v4l2_dbg_register *reg)
425{ 425{
426 struct i2c_client *client = v4l2_get_subdevdata(sd); 426 struct i2c_client *client = v4l2_get_subdevdata(sd);
427 427
diff --git a/drivers/media/i2c/soc_camera/ov772x.c b/drivers/media/i2c/soc_camera/ov772x.c
index fbeb5b2f3ae5..713d62e349f6 100644
--- a/drivers/media/i2c/soc_camera/ov772x.c
+++ b/drivers/media/i2c/soc_camera/ov772x.c
@@ -652,7 +652,7 @@ static int ov772x_g_register(struct v4l2_subdev *sd,
652} 652}
653 653
654static int ov772x_s_register(struct v4l2_subdev *sd, 654static int ov772x_s_register(struct v4l2_subdev *sd,
655 struct v4l2_dbg_register *reg) 655 const struct v4l2_dbg_register *reg)
656{ 656{
657 struct i2c_client *client = v4l2_get_subdevdata(sd); 657 struct i2c_client *client = v4l2_get_subdevdata(sd);
658 658
diff --git a/drivers/media/i2c/soc_camera/ov9640.c b/drivers/media/i2c/soc_camera/ov9640.c
index 05993041be31..20ca62d371c1 100644
--- a/drivers/media/i2c/soc_camera/ov9640.c
+++ b/drivers/media/i2c/soc_camera/ov9640.c
@@ -322,7 +322,7 @@ static int ov9640_get_register(struct v4l2_subdev *sd,
322} 322}
323 323
324static int ov9640_set_register(struct v4l2_subdev *sd, 324static int ov9640_set_register(struct v4l2_subdev *sd,
325 struct v4l2_dbg_register *reg) 325 const struct v4l2_dbg_register *reg)
326{ 326{
327 struct i2c_client *client = v4l2_get_subdevdata(sd); 327 struct i2c_client *client = v4l2_get_subdevdata(sd);
328 328
diff --git a/drivers/media/i2c/soc_camera/ov9740.c b/drivers/media/i2c/soc_camera/ov9740.c
index 2f236da80165..012bd6271124 100644
--- a/drivers/media/i2c/soc_camera/ov9740.c
+++ b/drivers/media/i2c/soc_camera/ov9740.c
@@ -835,7 +835,7 @@ static int ov9740_get_register(struct v4l2_subdev *sd,
835} 835}
836 836
837static int ov9740_set_register(struct v4l2_subdev *sd, 837static int ov9740_set_register(struct v4l2_subdev *sd,
838 struct v4l2_dbg_register *reg) 838 const struct v4l2_dbg_register *reg)
839{ 839{
840 struct i2c_client *client = v4l2_get_subdevdata(sd); 840 struct i2c_client *client = v4l2_get_subdevdata(sd);
841 841
diff --git a/drivers/media/i2c/soc_camera/rj54n1cb0c.c b/drivers/media/i2c/soc_camera/rj54n1cb0c.c
index 5c92679bfefb..1f9ec3b06b4e 100644
--- a/drivers/media/i2c/soc_camera/rj54n1cb0c.c
+++ b/drivers/media/i2c/soc_camera/rj54n1cb0c.c
@@ -1161,7 +1161,7 @@ static int rj54n1_g_register(struct v4l2_subdev *sd,
1161} 1161}
1162 1162
1163static int rj54n1_s_register(struct v4l2_subdev *sd, 1163static int rj54n1_s_register(struct v4l2_subdev *sd,
1164 struct v4l2_dbg_register *reg) 1164 const struct v4l2_dbg_register *reg)
1165{ 1165{
1166 struct i2c_client *client = v4l2_get_subdevdata(sd); 1166 struct i2c_client *client = v4l2_get_subdevdata(sd);
1167 1167
diff --git a/drivers/media/i2c/soc_camera/tw9910.c b/drivers/media/i2c/soc_camera/tw9910.c
index 7d2074601881..bad90b16a6dd 100644
--- a/drivers/media/i2c/soc_camera/tw9910.c
+++ b/drivers/media/i2c/soc_camera/tw9910.c
@@ -554,7 +554,7 @@ static int tw9910_g_register(struct v4l2_subdev *sd,
554} 554}
555 555
556static int tw9910_s_register(struct v4l2_subdev *sd, 556static int tw9910_s_register(struct v4l2_subdev *sd,
557 struct v4l2_dbg_register *reg) 557 const struct v4l2_dbg_register *reg)
558{ 558{
559 struct i2c_client *client = v4l2_get_subdevdata(sd); 559 struct i2c_client *client = v4l2_get_subdevdata(sd);
560 560
diff --git a/drivers/media/i2c/sony-btf-mpx.c b/drivers/media/i2c/sony-btf-mpx.c
new file mode 100644
index 000000000000..38cbea98764c
--- /dev/null
+++ b/drivers/media/i2c/sony-btf-mpx.c
@@ -0,0 +1,399 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <media/tuner.h>
23#include <media/v4l2-common.h>
24#include <media/v4l2-ioctl.h>
25#include <media/v4l2-device.h>
26#include <linux/slab.h>
27
28MODULE_DESCRIPTION("sony-btf-mpx driver");
29MODULE_LICENSE("GPL v2");
30
31static int debug;
32module_param(debug, int, 0644);
33MODULE_PARM_DESC(debug, "debug level 0=off(default) 1=on\n");
34
35/* #define MPX_DEBUG */
36
37/*
38 * Note:
39 *
40 * AS(IF/MPX) pin: LOW HIGH/OPEN
41 * IF/MPX address: 0x42/0x40 0x43/0x44
42 */
43
44
45static int force_mpx_mode = -1;
46module_param(force_mpx_mode, int, 0644);
47
48struct sony_btf_mpx {
49 struct v4l2_subdev sd;
50 int mpxmode;
51 u32 audmode;
52};
53
54static inline struct sony_btf_mpx *to_state(struct v4l2_subdev *sd)
55{
56 return container_of(sd, struct sony_btf_mpx, sd);
57}
58
59static int mpx_write(struct i2c_client *client, int dev, int addr, int val)
60{
61 u8 buffer[5];
62 struct i2c_msg msg;
63
64 buffer[0] = dev;
65 buffer[1] = addr >> 8;
66 buffer[2] = addr & 0xff;
67 buffer[3] = val >> 8;
68 buffer[4] = val & 0xff;
69 msg.addr = client->addr;
70 msg.flags = 0;
71 msg.len = 5;
72 msg.buf = buffer;
73 i2c_transfer(client->adapter, &msg, 1);
74 return 0;
75}
76
77/*
78 * MPX register values for the BTF-PG472Z:
79 *
80 * FM_ NICAM_ SCART_
81 * MODUS SOURCE ACB PRESCAL PRESCAL PRESCAL SYSTEM VOLUME
82 * 10/0030 12/0008 12/0013 12/000E 12/0010 12/0000 10/0020 12/0000
83 * ---------------------------------------------------------------
84 * Auto 1003 0020 0100 2603 5000 XXXX 0001 7500
85 *
86 * B/G
87 * Mono 1003 0020 0100 2603 5000 XXXX 0003 7500
88 * A2 1003 0020 0100 2601 5000 XXXX 0003 7500
89 * NICAM 1003 0120 0100 2603 5000 XXXX 0008 7500
90 *
91 * I
92 * Mono 1003 0020 0100 2603 7900 XXXX 000A 7500
93 * NICAM 1003 0120 0100 2603 7900 XXXX 000A 7500
94 *
95 * D/K
96 * Mono 1003 0020 0100 2603 5000 XXXX 0004 7500
97 * A2-1 1003 0020 0100 2601 5000 XXXX 0004 7500
98 * A2-2 1003 0020 0100 2601 5000 XXXX 0005 7500
99 * A2-3 1003 0020 0100 2601 5000 XXXX 0007 7500
100 * NICAM 1003 0120 0100 2603 5000 XXXX 000B 7500
101 *
102 * L/L'
103 * Mono 0003 0200 0100 7C03 5000 2200 0009 7500
104 * NICAM 0003 0120 0100 7C03 5000 XXXX 0009 7500
105 *
106 * M
107 * Mono 1003 0200 0100 2B03 5000 2B00 0002 7500
108 *
109 * For Asia, replace the 0x26XX in FM_PRESCALE with 0x14XX.
110 *
111 * Bilingual selection in A2/NICAM:
112 *
113 * High byte of SOURCE Left chan Right chan
114 * 0x01 MAIN SUB
115 * 0x03 MAIN MAIN
116 * 0x04 SUB SUB
117 *
118 * Force mono in NICAM by setting the high byte of SOURCE to 0x02 (L/L') or
119 * 0x00 (all other bands). Force mono in A2 with FMONO_A2:
120 *
121 * FMONO_A2
122 * 10/0022
123 * --------
124 * Forced mono ON 07F0
125 * Forced mono OFF 0190
126 */
127
128static const struct {
129 enum { AUD_MONO, AUD_A2, AUD_NICAM, AUD_NICAM_L } audio_mode;
130 u16 modus;
131 u16 source;
132 u16 acb;
133 u16 fm_prescale;
134 u16 nicam_prescale;
135 u16 scart_prescale;
136 u16 system;
137 u16 volume;
138} mpx_audio_modes[] = {
139 /* Auto */ { AUD_MONO, 0x1003, 0x0020, 0x0100, 0x2603,
140 0x5000, 0x0000, 0x0001, 0x7500 },
141 /* B/G Mono */ { AUD_MONO, 0x1003, 0x0020, 0x0100, 0x2603,
142 0x5000, 0x0000, 0x0003, 0x7500 },
143 /* B/G A2 */ { AUD_A2, 0x1003, 0x0020, 0x0100, 0x2601,
144 0x5000, 0x0000, 0x0003, 0x7500 },
145 /* B/G NICAM */ { AUD_NICAM, 0x1003, 0x0120, 0x0100, 0x2603,
146 0x5000, 0x0000, 0x0008, 0x7500 },
147 /* I Mono */ { AUD_MONO, 0x1003, 0x0020, 0x0100, 0x2603,
148 0x7900, 0x0000, 0x000A, 0x7500 },
149 /* I NICAM */ { AUD_NICAM, 0x1003, 0x0120, 0x0100, 0x2603,
150 0x7900, 0x0000, 0x000A, 0x7500 },
151 /* D/K Mono */ { AUD_MONO, 0x1003, 0x0020, 0x0100, 0x2603,
152 0x5000, 0x0000, 0x0004, 0x7500 },
153 /* D/K A2-1 */ { AUD_A2, 0x1003, 0x0020, 0x0100, 0x2601,
154 0x5000, 0x0000, 0x0004, 0x7500 },
155 /* D/K A2-2 */ { AUD_A2, 0x1003, 0x0020, 0x0100, 0x2601,
156 0x5000, 0x0000, 0x0005, 0x7500 },
157 /* D/K A2-3 */ { AUD_A2, 0x1003, 0x0020, 0x0100, 0x2601,
158 0x5000, 0x0000, 0x0007, 0x7500 },
159 /* D/K NICAM */ { AUD_NICAM, 0x1003, 0x0120, 0x0100, 0x2603,
160 0x5000, 0x0000, 0x000B, 0x7500 },
161 /* L/L' Mono */ { AUD_MONO, 0x0003, 0x0200, 0x0100, 0x7C03,
162 0x5000, 0x2200, 0x0009, 0x7500 },
163 /* L/L' NICAM */{ AUD_NICAM_L, 0x0003, 0x0120, 0x0100, 0x7C03,
164 0x5000, 0x0000, 0x0009, 0x7500 },
165};
166
167#define MPX_NUM_MODES ARRAY_SIZE(mpx_audio_modes)
168
169static int mpx_setup(struct sony_btf_mpx *t)
170{
171 struct i2c_client *client = v4l2_get_subdevdata(&t->sd);
172 u16 source = 0;
173 u8 buffer[3];
174 struct i2c_msg msg;
175 int mode = t->mpxmode;
176
177 /* reset MPX */
178 buffer[0] = 0x00;
179 buffer[1] = 0x80;
180 buffer[2] = 0x00;
181 msg.addr = client->addr;
182 msg.flags = 0;
183 msg.len = 3;
184 msg.buf = buffer;
185 i2c_transfer(client->adapter, &msg, 1);
186 buffer[1] = 0x00;
187 i2c_transfer(client->adapter, &msg, 1);
188
189 if (t->audmode != V4L2_TUNER_MODE_MONO)
190 mode++;
191
192 if (mpx_audio_modes[mode].audio_mode != AUD_MONO) {
193 switch (t->audmode) {
194 case V4L2_TUNER_MODE_MONO:
195 switch (mpx_audio_modes[mode].audio_mode) {
196 case AUD_A2:
197 source = mpx_audio_modes[mode].source;
198 break;
199 case AUD_NICAM:
200 source = 0x0000;
201 break;
202 case AUD_NICAM_L:
203 source = 0x0200;
204 break;
205 default:
206 break;
207 }
208 break;
209 case V4L2_TUNER_MODE_STEREO:
210 source = mpx_audio_modes[mode].source;
211 break;
212 case V4L2_TUNER_MODE_LANG1:
213 source = 0x0300;
214 break;
215 case V4L2_TUNER_MODE_LANG2:
216 source = 0x0400;
217 break;
218 }
219 source |= mpx_audio_modes[mode].source & 0x00ff;
220 } else
221 source = mpx_audio_modes[mode].source;
222
223 mpx_write(client, 0x10, 0x0030, mpx_audio_modes[mode].modus);
224 mpx_write(client, 0x12, 0x0008, source);
225 mpx_write(client, 0x12, 0x0013, mpx_audio_modes[mode].acb);
226 mpx_write(client, 0x12, 0x000e,
227 mpx_audio_modes[mode].fm_prescale);
228 mpx_write(client, 0x12, 0x0010,
229 mpx_audio_modes[mode].nicam_prescale);
230 mpx_write(client, 0x12, 0x000d,
231 mpx_audio_modes[mode].scart_prescale);
232 mpx_write(client, 0x10, 0x0020, mpx_audio_modes[mode].system);
233 mpx_write(client, 0x12, 0x0000, mpx_audio_modes[mode].volume);
234 if (mpx_audio_modes[mode].audio_mode == AUD_A2)
235 mpx_write(client, 0x10, 0x0022,
236 t->audmode == V4L2_TUNER_MODE_MONO ? 0x07f0 : 0x0190);
237
238#ifdef MPX_DEBUG
239 {
240 u8 buf1[3], buf2[2];
241 struct i2c_msg msgs[2];
242
243 v4l2_info(client,
244 "MPX registers: %04x %04x %04x %04x %04x %04x %04x %04x\n",
245 mpx_audio_modes[mode].modus,
246 source,
247 mpx_audio_modes[mode].acb,
248 mpx_audio_modes[mode].fm_prescale,
249 mpx_audio_modes[mode].nicam_prescale,
250 mpx_audio_modes[mode].scart_prescale,
251 mpx_audio_modes[mode].system,
252 mpx_audio_modes[mode].volume);
253 buf1[0] = 0x11;
254 buf1[1] = 0x00;
255 buf1[2] = 0x7e;
256 msgs[0].addr = client->addr;
257 msgs[0].flags = 0;
258 msgs[0].len = 3;
259 msgs[0].buf = buf1;
260 msgs[1].addr = client->addr;
261 msgs[1].flags = I2C_M_RD;
262 msgs[1].len = 2;
263 msgs[1].buf = buf2;
264 i2c_transfer(client->adapter, msgs, 2);
265 v4l2_info(client, "MPX system: %02x%02x\n",
266 buf2[0], buf2[1]);
267 buf1[0] = 0x11;
268 buf1[1] = 0x02;
269 buf1[2] = 0x00;
270 i2c_transfer(client->adapter, msgs, 2);
271 v4l2_info(client, "MPX status: %02x%02x\n",
272 buf2[0], buf2[1]);
273 }
274#endif
275 return 0;
276}
277
278
279static int sony_btf_mpx_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
280{
281 struct sony_btf_mpx *t = to_state(sd);
282 int default_mpx_mode = 0;
283
284 if (std & V4L2_STD_PAL_BG)
285 default_mpx_mode = 1;
286 else if (std & V4L2_STD_PAL_I)
287 default_mpx_mode = 4;
288 else if (std & V4L2_STD_PAL_DK)
289 default_mpx_mode = 6;
290 else if (std & V4L2_STD_SECAM_L)
291 default_mpx_mode = 11;
292
293 if (default_mpx_mode != t->mpxmode) {
294 t->mpxmode = default_mpx_mode;
295 mpx_setup(t);
296 }
297 return 0;
298}
299
300static int sony_btf_mpx_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
301{
302 struct sony_btf_mpx *t = to_state(sd);
303
304 vt->capability = V4L2_TUNER_CAP_NORM |
305 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
306 V4L2_TUNER_CAP_LANG2;
307 vt->rxsubchans = V4L2_TUNER_SUB_MONO |
308 V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_LANG1 |
309 V4L2_TUNER_SUB_LANG2;
310 vt->audmode = t->audmode;
311 return 0;
312}
313
314static int sony_btf_mpx_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
315{
316 struct sony_btf_mpx *t = to_state(sd);
317
318 if (vt->type != V4L2_TUNER_ANALOG_TV)
319 return -EINVAL;
320
321 if (vt->audmode != t->audmode) {
322 t->audmode = vt->audmode;
323 mpx_setup(t);
324 }
325 return 0;
326}
327
328/* --------------------------------------------------------------------------*/
329
330static const struct v4l2_subdev_core_ops sony_btf_mpx_core_ops = {
331 .s_std = sony_btf_mpx_s_std,
332};
333
334static const struct v4l2_subdev_tuner_ops sony_btf_mpx_tuner_ops = {
335 .s_tuner = sony_btf_mpx_s_tuner,
336 .g_tuner = sony_btf_mpx_g_tuner,
337};
338
339static const struct v4l2_subdev_ops sony_btf_mpx_ops = {
340 .core = &sony_btf_mpx_core_ops,
341 .tuner = &sony_btf_mpx_tuner_ops,
342};
343
344/* --------------------------------------------------------------------------*/
345
346static int sony_btf_mpx_probe(struct i2c_client *client,
347 const struct i2c_device_id *id)
348{
349 struct sony_btf_mpx *t;
350 struct v4l2_subdev *sd;
351
352 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
353 return -ENODEV;
354
355 v4l_info(client, "chip found @ 0x%x (%s)\n",
356 client->addr << 1, client->adapter->name);
357
358 t = kzalloc(sizeof(struct sony_btf_mpx), GFP_KERNEL);
359 if (t == NULL)
360 return -ENOMEM;
361
362 sd = &t->sd;
363 v4l2_i2c_subdev_init(sd, client, &sony_btf_mpx_ops);
364
365 /* Initialize sony_btf_mpx */
366 t->mpxmode = 0;
367 t->audmode = V4L2_TUNER_MODE_STEREO;
368
369 return 0;
370}
371
372static int sony_btf_mpx_remove(struct i2c_client *client)
373{
374 struct v4l2_subdev *sd = i2c_get_clientdata(client);
375
376 v4l2_device_unregister_subdev(sd);
377 kfree(to_state(sd));
378
379 return 0;
380}
381
382/* ----------------------------------------------------------------------- */
383
384static const struct i2c_device_id sony_btf_mpx_id[] = {
385 { "sony-btf-mpx", 0 },
386 { }
387};
388MODULE_DEVICE_TABLE(i2c, sony_btf_mpx_id);
389
390static struct i2c_driver sony_btf_mpx_driver = {
391 .driver = {
392 .owner = THIS_MODULE,
393 .name = "sony-btf-mpx",
394 },
395 .probe = sony_btf_mpx_probe,
396 .remove = sony_btf_mpx_remove,
397 .id_table = sony_btf_mpx_id,
398};
399module_i2c_driver(sony_btf_mpx_driver);
diff --git a/drivers/media/i2c/tda7432.c b/drivers/media/i2c/tda7432.c
index f7707e65761e..28b5121881f5 100644
--- a/drivers/media/i2c/tda7432.c
+++ b/drivers/media/i2c/tda7432.c
@@ -35,6 +35,7 @@
35 35
36#include <media/v4l2-device.h> 36#include <media/v4l2-device.h>
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-ctrls.h>
38#include <media/i2c-addr.h> 39#include <media/i2c-addr.h>
39 40
40#ifndef VIDEO_AUDIO_BALANCE 41#ifndef VIDEO_AUDIO_BALANCE
@@ -60,13 +61,17 @@ MODULE_PARM_DESC(maxvol, "Set maximium volume to +20dB(0) else +0dB(1). Default
60 61
61struct tda7432 { 62struct tda7432 {
62 struct v4l2_subdev sd; 63 struct v4l2_subdev sd;
63 int addr; 64 struct v4l2_ctrl_handler hdl;
64 int input; 65 struct {
65 int volume; 66 /* bass/treble cluster */
66 int muted; 67 struct v4l2_ctrl *bass;
67 int bass, treble; 68 struct v4l2_ctrl *treble;
68 int lf, lr, rf, rr; 69 };
69 int loud; 70 struct {
71 /* mute/balance cluster */
72 struct v4l2_ctrl *mute;
73 struct v4l2_ctrl *balance;
74 };
70}; 75};
71 76
72static inline struct tda7432 *to_state(struct v4l2_subdev *sd) 77static inline struct tda7432 *to_state(struct v4l2_subdev *sd)
@@ -74,6 +79,11 @@ static inline struct tda7432 *to_state(struct v4l2_subdev *sd)
74 return container_of(sd, struct tda7432, sd); 79 return container_of(sd, struct tda7432, sd);
75} 80}
76 81
82static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
83{
84 return &container_of(ctrl->handler, struct tda7432, hdl)->sd;
85}
86
77/* The TDA7432 is made by STS-Thompson 87/* The TDA7432 is made by STS-Thompson
78 * http://www.st.com 88 * http://www.st.com
79 * http://us.st.com/stonline/books/pdf/docs/4056.pdf 89 * http://us.st.com/stonline/books/pdf/docs/4056.pdf
@@ -227,24 +237,22 @@ static int tda7432_write(struct v4l2_subdev *sd, int subaddr, int val)
227static int tda7432_set(struct v4l2_subdev *sd) 237static int tda7432_set(struct v4l2_subdev *sd)
228{ 238{
229 struct i2c_client *client = v4l2_get_subdevdata(sd); 239 struct i2c_client *client = v4l2_get_subdevdata(sd);
230 struct tda7432 *t = to_state(sd);
231 unsigned char buf[16]; 240 unsigned char buf[16];
232 241
233 v4l2_dbg(1, debug, sd,
234 "tda7432: 7432_set(0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x)\n",
235 t->input, t->volume, t->bass, t->treble, t->lf, t->lr,
236 t->rf, t->rr, t->loud);
237 buf[0] = TDA7432_IN; 242 buf[0] = TDA7432_IN;
238 buf[1] = t->input; 243 buf[1] = TDA7432_STEREO_IN | /* Main (stereo) input */
239 buf[2] = t->volume; 244 TDA7432_BASS_SYM | /* Symmetric bass cut */
240 buf[3] = t->bass; 245 TDA7432_BASS_NORM; /* Normal bass range */
241 buf[4] = t->treble; 246 buf[2] = 0x3b;
242 buf[5] = t->lf; 247 if (loudness) /* Turn loudness on? */
243 buf[6] = t->lr; 248 buf[2] |= TDA7432_LD_ON;
244 buf[7] = t->rf; 249 buf[3] = TDA7432_TREBLE_0DB | (TDA7432_BASS_0DB << 4);
245 buf[8] = t->rr; 250 buf[4] = TDA7432_ATTEN_0DB;
246 buf[9] = t->loud; 251 buf[5] = TDA7432_ATTEN_0DB;
247 if (10 != i2c_master_send(client, buf, 10)) { 252 buf[6] = TDA7432_ATTEN_0DB;
253 buf[7] = TDA7432_ATTEN_0DB;
254 buf[8] = loudness;
255 if (9 != i2c_master_send(client, buf, 9)) {
248 v4l2_err(sd, "I/O error, trying tda7432_set\n"); 256 v4l2_err(sd, "I/O error, trying tda7432_set\n");
249 return -1; 257 return -1;
250 } 258 }
@@ -252,174 +260,86 @@ static int tda7432_set(struct v4l2_subdev *sd)
252 return 0; 260 return 0;
253} 261}
254 262
255static void do_tda7432_init(struct v4l2_subdev *sd) 263static int tda7432_log_status(struct v4l2_subdev *sd)
256{
257 struct tda7432 *t = to_state(sd);
258
259 v4l2_dbg(2, debug, sd, "In tda7432_init\n");
260
261 t->input = TDA7432_STEREO_IN | /* Main (stereo) input */
262 TDA7432_BASS_SYM | /* Symmetric bass cut */
263 TDA7432_BASS_NORM; /* Normal bass range */
264 t->volume = 0x3b ; /* -27dB Volume */
265 if (loudness) /* Turn loudness on? */
266 t->volume |= TDA7432_LD_ON;
267 t->muted = 1;
268 t->treble = TDA7432_TREBLE_0DB; /* 0dB Treble */
269 t->bass = TDA7432_BASS_0DB; /* 0dB Bass */
270 t->lf = TDA7432_ATTEN_0DB; /* 0dB attenuation */
271 t->lr = TDA7432_ATTEN_0DB; /* 0dB attenuation */
272 t->rf = TDA7432_ATTEN_0DB; /* 0dB attenuation */
273 t->rr = TDA7432_ATTEN_0DB; /* 0dB attenuation */
274 t->loud = loudness; /* insmod parameter */
275
276 tda7432_set(sd);
277}
278
279static int tda7432_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
280{ 264{
281 struct tda7432 *t = to_state(sd); 265 struct tda7432 *state = to_state(sd);
282 266
283 switch (ctrl->id) { 267 v4l2_ctrl_handler_log_status(&state->hdl, sd->name);
284 case V4L2_CID_AUDIO_MUTE: 268 return 0;
285 ctrl->value=t->muted;
286 return 0;
287 case V4L2_CID_AUDIO_VOLUME:
288 if (!maxvol){ /* max +20db */
289 ctrl->value = ( 0x6f - (t->volume & 0x7F) ) * 630;
290 } else { /* max 0db */
291 ctrl->value = ( 0x6f - (t->volume & 0x7F) ) * 829;
292 }
293 return 0;
294 case V4L2_CID_AUDIO_BALANCE:
295 {
296 if ( (t->lf) < (t->rf) )
297 /* right is attenuated, balance shifted left */
298 ctrl->value = (32768 - 1057*(t->rf));
299 else
300 /* left is attenuated, balance shifted right */
301 ctrl->value = (32768 + 1057*(t->lf));
302 return 0;
303 }
304 case V4L2_CID_AUDIO_BASS:
305 {
306 /* Bass/treble 4 bits each */
307 int bass=t->bass;
308 if(bass >= 0x8)
309 bass = ~(bass - 0x8) & 0xf;
310 ctrl->value = (bass << 12)+(bass << 8)+(bass << 4)+(bass);
311 return 0;
312 }
313 case V4L2_CID_AUDIO_TREBLE:
314 {
315 int treble=t->treble;
316 if(treble >= 0x8)
317 treble = ~(treble - 0x8) & 0xf;
318 ctrl->value = (treble << 12)+(treble << 8)+(treble << 4)+(treble);
319 return 0;
320 }
321 }
322 return -EINVAL;
323} 269}
324 270
325static int tda7432_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 271static int tda7432_s_ctrl(struct v4l2_ctrl *ctrl)
326{ 272{
273 struct v4l2_subdev *sd = to_sd(ctrl);
327 struct tda7432 *t = to_state(sd); 274 struct tda7432 *t = to_state(sd);
275 u8 bass, treble, volume;
276 u8 lf, lr, rf, rr;
328 277
329 switch (ctrl->id) { 278 switch (ctrl->id) {
330 case V4L2_CID_AUDIO_MUTE: 279 case V4L2_CID_AUDIO_MUTE:
331 t->muted=ctrl->value; 280 if (t->balance->val < 0) {
332 break;
333 case V4L2_CID_AUDIO_VOLUME:
334 if(!maxvol){ /* max +20db */
335 t->volume = 0x6f - ((ctrl->value)/630);
336 } else { /* max 0db */
337 t->volume = 0x6f - ((ctrl->value)/829);
338 }
339 if (loudness) /* Turn on the loudness bit */
340 t->volume |= TDA7432_LD_ON;
341
342 tda7432_write(sd, TDA7432_VL, t->volume);
343 return 0;
344 case V4L2_CID_AUDIO_BALANCE:
345 if (ctrl->value < 32768) {
346 /* shifted to left, attenuate right */ 281 /* shifted to left, attenuate right */
347 t->rr = (32768 - ctrl->value)/1057; 282 rr = rf = -t->balance->val;
348 t->rf = t->rr; 283 lr = lf = TDA7432_ATTEN_0DB;
349 t->lr = TDA7432_ATTEN_0DB; 284 } else if (t->balance->val > 0) {
350 t->lf = TDA7432_ATTEN_0DB;
351 } else if(ctrl->value > 32769) {
352 /* shifted to right, attenuate left */ 285 /* shifted to right, attenuate left */
353 t->lf = (ctrl->value - 32768)/1057; 286 rr = rf = TDA7432_ATTEN_0DB;
354 t->lr = t->lf; 287 lr = lf = t->balance->val;
355 t->rr = TDA7432_ATTEN_0DB;
356 t->rf = TDA7432_ATTEN_0DB;
357 } else { 288 } else {
358 /* centered */ 289 /* centered */
359 t->rr = TDA7432_ATTEN_0DB; 290 rr = rf = TDA7432_ATTEN_0DB;
360 t->rf = TDA7432_ATTEN_0DB; 291 lr = lf = TDA7432_ATTEN_0DB;
361 t->lf = TDA7432_ATTEN_0DB;
362 t->lr = TDA7432_ATTEN_0DB;
363 } 292 }
364 break; 293 if (t->mute->val) {
365 case V4L2_CID_AUDIO_BASS: 294 lf |= TDA7432_MUTE;
366 t->bass = ctrl->value >> 12; 295 lr |= TDA7432_MUTE;
367 if(t->bass>= 0x8) 296 lf |= TDA7432_MUTE;
368 t->bass = (~t->bass & 0xf) + 0x8 ; 297 rr |= TDA7432_MUTE;
369 298 }
370 tda7432_write(sd, TDA7432_TN, 0x10 | (t->bass << 4) | t->treble); 299 /* Mute & update balance*/
300 tda7432_write(sd, TDA7432_LF, lf);
301 tda7432_write(sd, TDA7432_LR, lr);
302 tda7432_write(sd, TDA7432_RF, rf);
303 tda7432_write(sd, TDA7432_RR, rr);
371 return 0; 304 return 0;
372 case V4L2_CID_AUDIO_TREBLE: 305 case V4L2_CID_AUDIO_VOLUME:
373 t->treble= ctrl->value >> 12; 306 volume = 0x6f - ctrl->val;
374 if(t->treble>= 0x8) 307 if (loudness) /* Turn on the loudness bit */
375 t->treble = (~t->treble & 0xf) + 0x8 ; 308 volume |= TDA7432_LD_ON;
376 309
377 tda7432_write(sd, TDA7432_TN, 0x10 | (t->bass << 4) | t->treble); 310 tda7432_write(sd, TDA7432_VL, volume);
378 return 0; 311 return 0;
379 default:
380 return -EINVAL;
381 }
382
383 /* Used for both mute and balance changes */
384 if (t->muted)
385 {
386 /* Mute & update balance*/
387 tda7432_write(sd, TDA7432_LF, t->lf | TDA7432_MUTE);
388 tda7432_write(sd, TDA7432_LR, t->lr | TDA7432_MUTE);
389 tda7432_write(sd, TDA7432_RF, t->rf | TDA7432_MUTE);
390 tda7432_write(sd, TDA7432_RR, t->rr | TDA7432_MUTE);
391 } else {
392 tda7432_write(sd, TDA7432_LF, t->lf);
393 tda7432_write(sd, TDA7432_LR, t->lr);
394 tda7432_write(sd, TDA7432_RF, t->rf);
395 tda7432_write(sd, TDA7432_RR, t->rr);
396 }
397 return 0;
398}
399
400static int tda7432_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
401{
402 switch (qc->id) {
403 case V4L2_CID_AUDIO_VOLUME:
404 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 58880);
405 case V4L2_CID_AUDIO_MUTE:
406 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
407 case V4L2_CID_AUDIO_BALANCE:
408 case V4L2_CID_AUDIO_BASS: 312 case V4L2_CID_AUDIO_BASS:
409 case V4L2_CID_AUDIO_TREBLE: 313 bass = t->bass->val;
410 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768); 314 treble = t->treble->val;
315 if (bass >= 0x8)
316 bass = 14 - (bass - 8);
317 if (treble >= 0x8)
318 treble = 14 - (treble - 8);
319
320 tda7432_write(sd, TDA7432_TN, 0x10 | (bass << 4) | treble);
321 return 0;
411 } 322 }
412 return -EINVAL; 323 return -EINVAL;
413} 324}
414 325
415/* ----------------------------------------------------------------------- */ 326/* ----------------------------------------------------------------------- */
416 327
417static const struct v4l2_subdev_core_ops tda7432_core_ops = { 328static const struct v4l2_ctrl_ops tda7432_ctrl_ops = {
418 .queryctrl = tda7432_queryctrl,
419 .g_ctrl = tda7432_g_ctrl,
420 .s_ctrl = tda7432_s_ctrl, 329 .s_ctrl = tda7432_s_ctrl,
421}; 330};
422 331
332static const struct v4l2_subdev_core_ops tda7432_core_ops = {
333 .log_status = tda7432_log_status,
334 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
335 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
336 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
337 .g_ctrl = v4l2_subdev_g_ctrl,
338 .s_ctrl = v4l2_subdev_s_ctrl,
339 .queryctrl = v4l2_subdev_queryctrl,
340 .querymenu = v4l2_subdev_querymenu,
341};
342
423static const struct v4l2_subdev_ops tda7432_ops = { 343static const struct v4l2_subdev_ops tda7432_ops = {
424 .core = &tda7432_core_ops, 344 .core = &tda7432_core_ops,
425}; 345};
@@ -444,6 +364,28 @@ static int tda7432_probe(struct i2c_client *client,
444 return -ENOMEM; 364 return -ENOMEM;
445 sd = &t->sd; 365 sd = &t->sd;
446 v4l2_i2c_subdev_init(sd, client, &tda7432_ops); 366 v4l2_i2c_subdev_init(sd, client, &tda7432_ops);
367 v4l2_ctrl_handler_init(&t->hdl, 5);
368 v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
369 V4L2_CID_AUDIO_VOLUME, 0, maxvol ? 0x68 : 0x4f, 1, maxvol ? 0x5d : 0x47);
370 t->mute = v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
371 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
372 t->balance = v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
373 V4L2_CID_AUDIO_BALANCE, -31, 31, 1, 0);
374 t->bass = v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
375 V4L2_CID_AUDIO_BASS, 0, 14, 1, 7);
376 t->treble = v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
377 V4L2_CID_AUDIO_TREBLE, 0, 14, 1, 7);
378 sd->ctrl_handler = &t->hdl;
379 if (t->hdl.error) {
380 int err = t->hdl.error;
381
382 v4l2_ctrl_handler_free(&t->hdl);
383 kfree(t);
384 return err;
385 }
386 v4l2_ctrl_cluster(2, &t->bass);
387 v4l2_ctrl_cluster(2, &t->mute);
388 v4l2_ctrl_handler_setup(&t->hdl);
447 if (loudness < 0 || loudness > 15) { 389 if (loudness < 0 || loudness > 15) {
448 v4l2_warn(sd, "loudness parameter must be between 0 and 15\n"); 390 v4l2_warn(sd, "loudness parameter must be between 0 and 15\n");
449 if (loudness < 0) 391 if (loudness < 0)
@@ -452,17 +394,19 @@ static int tda7432_probe(struct i2c_client *client,
452 loudness = 15; 394 loudness = 15;
453 } 395 }
454 396
455 do_tda7432_init(sd); 397 tda7432_set(sd);
456 return 0; 398 return 0;
457} 399}
458 400
459static int tda7432_remove(struct i2c_client *client) 401static int tda7432_remove(struct i2c_client *client)
460{ 402{
461 struct v4l2_subdev *sd = i2c_get_clientdata(client); 403 struct v4l2_subdev *sd = i2c_get_clientdata(client);
404 struct tda7432 *t = to_state(sd);
462 405
463 do_tda7432_init(sd); 406 tda7432_set(sd);
464 v4l2_device_unregister_subdev(sd); 407 v4l2_device_unregister_subdev(sd);
465 kfree(to_state(sd)); 408 v4l2_ctrl_handler_free(&t->hdl);
409 kfree(t);
466 return 0; 410 return 0;
467} 411}
468 412
diff --git a/drivers/media/i2c/tda9840.c b/drivers/media/i2c/tda9840.c
index 3d7ddd93282d..01441e35d88b 100644
--- a/drivers/media/i2c/tda9840.c
+++ b/drivers/media/i2c/tda9840.c
@@ -87,7 +87,7 @@ static int tda9840_status(struct v4l2_subdev *sd)
87 return byte & 0x60; 87 return byte & 0x60;
88} 88}
89 89
90static int tda9840_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *t) 90static int tda9840_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *t)
91{ 91{
92 int stat = tda9840_status(sd); 92 int stat = tda9840_status(sd);
93 int byte; 93 int byte;
diff --git a/drivers/media/i2c/ths7303.c b/drivers/media/i2c/ths7303.c
index e747524ba6ed..c4339556a2ea 100644
--- a/drivers/media/i2c/ths7303.c
+++ b/drivers/media/i2c/ths7303.c
@@ -1,7 +1,15 @@
1/* 1/*
2 * ths7303- THS7303 Video Amplifier driver 2 * ths7303/53- THS7303/53 Video Amplifier driver
3 * 3 *
4 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
5 * Copyright 2013 Cisco Systems, Inc. and/or its affiliates.
6 *
7 * Author: Chaithrika U S <chaithrika@ti.com>
8 *
9 * Contributors:
10 * Hans Verkuil <hans.verkuil@cisco.com>
11 * Lad, Prabhakar <prabhakar.lad@ti.com>
12 * Martin Bugge <marbugge@cisco.com>
5 * 13 *
6 * This program is free software; you can redistribute it and/or 14 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as 15 * modify it under the terms of the GNU General Public License as
@@ -13,25 +21,27 @@
13 * GNU General Public License for more details. 21 * GNU General Public License for more details.
14 */ 22 */
15 23
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/ctype.h>
19#include <linux/slab.h>
20#include <linux/i2c.h> 24#include <linux/i2c.h>
21#include <linux/device.h>
22#include <linux/delay.h>
23#include <linux/module.h> 25#include <linux/module.h>
24#include <linux/uaccess.h> 26#include <linux/slab.h>
25#include <linux/videodev2.h>
26 27
27#include <media/v4l2-device.h> 28#include <media/ths7303.h>
28#include <media/v4l2-subdev.h>
29#include <media/v4l2-chip-ident.h> 29#include <media/v4l2-chip-ident.h>
30#include <media/v4l2-device.h>
30 31
31#define THS7303_CHANNEL_1 1 32#define THS7303_CHANNEL_1 1
32#define THS7303_CHANNEL_2 2 33#define THS7303_CHANNEL_2 2
33#define THS7303_CHANNEL_3 3 34#define THS7303_CHANNEL_3 3
34 35
36struct ths7303_state {
37 struct v4l2_subdev sd;
38 struct ths7303_platform_data pdata;
39 struct v4l2_bt_timings bt;
40 int std_id;
41 int stream_on;
42 int driver_data;
43};
44
35enum ths7303_filter_mode { 45enum ths7303_filter_mode {
36 THS7303_FILTER_MODE_480I_576I, 46 THS7303_FILTER_MODE_480I_576I,
37 THS7303_FILTER_MODE_480P_576P, 47 THS7303_FILTER_MODE_480P_576P,
@@ -48,64 +58,84 @@ static int debug;
48module_param(debug, int, 0644); 58module_param(debug, int, 0644);
49MODULE_PARM_DESC(debug, "Debug level 0-1"); 59MODULE_PARM_DESC(debug, "Debug level 0-1");
50 60
61static inline struct ths7303_state *to_state(struct v4l2_subdev *sd)
62{
63 return container_of(sd, struct ths7303_state, sd);
64}
65
66static int ths7303_read(struct v4l2_subdev *sd, u8 reg)
67{
68 struct i2c_client *client = v4l2_get_subdevdata(sd);
69
70 return i2c_smbus_read_byte_data(client, reg);
71}
72
73static int ths7303_write(struct v4l2_subdev *sd, u8 reg, u8 val)
74{
75 struct i2c_client *client = v4l2_get_subdevdata(sd);
76 int ret;
77 int i;
78
79 for (i = 0; i < 3; i++) {
80 ret = i2c_smbus_write_byte_data(client, reg, val);
81 if (ret == 0)
82 return 0;
83 }
84 return ret;
85}
86
51/* following function is used to set ths7303 */ 87/* following function is used to set ths7303 */
52int ths7303_setval(struct v4l2_subdev *sd, enum ths7303_filter_mode mode) 88int ths7303_setval(struct v4l2_subdev *sd, enum ths7303_filter_mode mode)
53{ 89{
54 u8 input_bias_chroma = 3;
55 u8 input_bias_luma = 3;
56 int disable = 0;
57 int err = 0;
58 u8 val = 0;
59 u8 temp;
60
61 struct i2c_client *client = v4l2_get_subdevdata(sd); 90 struct i2c_client *client = v4l2_get_subdevdata(sd);
91 struct ths7303_state *state = to_state(sd);
92 struct ths7303_platform_data *pdata = &state->pdata;
93 u8 val, sel = 0;
94 int err, disable = 0;
62 95
63 if (!client) 96 if (!client)
64 return -EINVAL; 97 return -EINVAL;
65 98
66 switch (mode) { 99 switch (mode) {
67 case THS7303_FILTER_MODE_1080P: 100 case THS7303_FILTER_MODE_1080P:
68 val = (3 << 6); 101 sel = 0x3; /*1080p and SXGA/UXGA */
69 val |= (3 << 3);
70 break; 102 break;
71 case THS7303_FILTER_MODE_720P_1080I: 103 case THS7303_FILTER_MODE_720P_1080I:
72 val = (2 << 6); 104 sel = 0x2; /*720p, 1080i and SVGA/XGA */
73 val |= (2 << 3);
74 break; 105 break;
75 case THS7303_FILTER_MODE_480P_576P: 106 case THS7303_FILTER_MODE_480P_576P:
76 val = (1 << 6); 107 sel = 0x1; /* EDTV 480p/576p and VGA */
77 val |= (1 << 3);
78 break; 108 break;
79 case THS7303_FILTER_MODE_480I_576I: 109 case THS7303_FILTER_MODE_480I_576I:
110 sel = 0x0; /* SDTV, S-Video, 480i/576i */
80 break; 111 break;
81 case THS7303_FILTER_MODE_DISABLE:
82 pr_info("mode disabled\n");
83 /* disable all channels */
84 disable = 1;
85 default: 112 default:
86 /* disable all channels */ 113 /* disable all channels */
87 disable = 1; 114 disable = 1;
88 } 115 }
89 /* Setup channel 2 - Luma - Green */ 116
90 temp = val; 117 val = (sel << 6) | (sel << 3);
91 if (!disable) 118 if (!disable)
92 val |= input_bias_luma; 119 val |= (pdata->ch_1 & 0x27);
93 err = i2c_smbus_write_byte_data(client, THS7303_CHANNEL_2, val); 120 err = ths7303_write(sd, THS7303_CHANNEL_1, val);
94 if (err) 121 if (err)
95 goto out; 122 goto out;
96 123
97 /* setup two chroma channels */ 124 val = (sel << 6) | (sel << 3);
98 if (!disable) 125 if (!disable)
99 temp |= input_bias_chroma; 126 val |= (pdata->ch_2 & 0x27);
100 127 err = ths7303_write(sd, THS7303_CHANNEL_2, val);
101 err = i2c_smbus_write_byte_data(client, THS7303_CHANNEL_1, temp);
102 if (err) 128 if (err)
103 goto out; 129 goto out;
104 130
105 err = i2c_smbus_write_byte_data(client, THS7303_CHANNEL_3, temp); 131 val = (sel << 6) | (sel << 3);
132 if (!disable)
133 val |= (pdata->ch_3 & 0x27);
134 err = ths7303_write(sd, THS7303_CHANNEL_3, val);
106 if (err) 135 if (err)
107 goto out; 136 goto out;
108 return err; 137
138 return 0;
109out: 139out:
110 pr_info("write byte data failed\n"); 140 pr_info("write byte data failed\n");
111 return err; 141 return err;
@@ -113,49 +143,209 @@ out:
113 143
114static int ths7303_s_std_output(struct v4l2_subdev *sd, v4l2_std_id norm) 144static int ths7303_s_std_output(struct v4l2_subdev *sd, v4l2_std_id norm)
115{ 145{
116 if (norm & (V4L2_STD_ALL & ~V4L2_STD_SECAM)) 146 struct ths7303_state *state = to_state(sd);
147
148 if (norm & (V4L2_STD_ALL & ~V4L2_STD_SECAM)) {
149 state->std_id = 1;
150 state->bt.pixelclock = 0;
117 return ths7303_setval(sd, THS7303_FILTER_MODE_480I_576I); 151 return ths7303_setval(sd, THS7303_FILTER_MODE_480I_576I);
118 else 152 }
119 return ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE); 153
154 return ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE);
120} 155}
121 156
122/* for setting filter for HD output */ 157static int ths7303_config(struct v4l2_subdev *sd)
123static int ths7303_s_dv_timings(struct v4l2_subdev *sd,
124 struct v4l2_dv_timings *dv_timings)
125{ 158{
126 u32 height = dv_timings->bt.height; 159 struct ths7303_state *state = to_state(sd);
127 int interlaced = dv_timings->bt.interlaced; 160 int res;
128 int res = 0; 161
162 if (!state->stream_on) {
163 ths7303_write(sd, THS7303_CHANNEL_1,
164 (ths7303_read(sd, THS7303_CHANNEL_1) & 0xf8) |
165 0x00);
166 ths7303_write(sd, THS7303_CHANNEL_2,
167 (ths7303_read(sd, THS7303_CHANNEL_2) & 0xf8) |
168 0x00);
169 ths7303_write(sd, THS7303_CHANNEL_3,
170 (ths7303_read(sd, THS7303_CHANNEL_3) & 0xf8) |
171 0x00);
172 return 0;
173 }
129 174
130 if (height == 1080 && !interlaced) 175 if (state->bt.pixelclock > 120000000)
131 res = ths7303_setval(sd, THS7303_FILTER_MODE_1080P); 176 res = ths7303_setval(sd, THS7303_FILTER_MODE_1080P);
132 else if ((height == 720 && !interlaced) || 177 else if (state->bt.pixelclock > 70000000)
133 (height == 1080 && interlaced))
134 res = ths7303_setval(sd, THS7303_FILTER_MODE_720P_1080I); 178 res = ths7303_setval(sd, THS7303_FILTER_MODE_720P_1080I);
135 else if ((height == 480 || height == 576) && !interlaced) 179 else if (state->bt.pixelclock > 20000000)
136 res = ths7303_setval(sd, THS7303_FILTER_MODE_480P_576P); 180 res = ths7303_setval(sd, THS7303_FILTER_MODE_480P_576P);
181 else if (state->std_id)
182 res = ths7303_setval(sd, THS7303_FILTER_MODE_480I_576I);
137 else 183 else
138 /* disable all channels */ 184 /* disable all channels */
139 res = ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE); 185 res = ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE);
140 186
141 return res; 187 return res;
188
189}
190
191static int ths7303_s_stream(struct v4l2_subdev *sd, int enable)
192{
193 struct ths7303_state *state = to_state(sd);
194
195 state->stream_on = enable;
196
197 return ths7303_config(sd);
198}
199
200/* for setting filter for HD output */
201static int ths7303_s_dv_timings(struct v4l2_subdev *sd,
202 struct v4l2_dv_timings *dv_timings)
203{
204 struct ths7303_state *state = to_state(sd);
205
206 if (!dv_timings || dv_timings->type != V4L2_DV_BT_656_1120)
207 return -EINVAL;
208
209 state->bt = dv_timings->bt;
210 state->std_id = 0;
211
212 return ths7303_config(sd);
142} 213}
143 214
144static int ths7303_g_chip_ident(struct v4l2_subdev *sd, 215static int ths7303_g_chip_ident(struct v4l2_subdev *sd,
145 struct v4l2_dbg_chip_ident *chip) 216 struct v4l2_dbg_chip_ident *chip)
146{ 217{
147 struct i2c_client *client = v4l2_get_subdevdata(sd); 218 struct i2c_client *client = v4l2_get_subdevdata(sd);
219 struct ths7303_state *state = to_state(sd);
148 220
149 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_THS7303, 0); 221 return v4l2_chip_ident_i2c_client(client, chip, state->driver_data, 0);
150} 222}
151 223
152static const struct v4l2_subdev_video_ops ths7303_video_ops = { 224static const struct v4l2_subdev_video_ops ths7303_video_ops = {
225 .s_stream = ths7303_s_stream,
153 .s_std_output = ths7303_s_std_output, 226 .s_std_output = ths7303_s_std_output,
154 .s_dv_timings = ths7303_s_dv_timings, 227 .s_dv_timings = ths7303_s_dv_timings,
155}; 228};
156 229
230#ifdef CONFIG_VIDEO_ADV_DEBUG
231
232static int ths7303_g_register(struct v4l2_subdev *sd,
233 struct v4l2_dbg_register *reg)
234{
235 struct i2c_client *client = v4l2_get_subdevdata(sd);
236
237 if (!v4l2_chip_match_i2c_client(client, &reg->match))
238 return -EINVAL;
239 if (!capable(CAP_SYS_ADMIN))
240 return -EPERM;
241
242 reg->size = 1;
243 reg->val = ths7303_read(sd, reg->reg);
244 return 0;
245}
246
247static int ths7303_s_register(struct v4l2_subdev *sd,
248 const struct v4l2_dbg_register *reg)
249{
250 struct i2c_client *client = v4l2_get_subdevdata(sd);
251
252 if (!v4l2_chip_match_i2c_client(client, &reg->match))
253 return -EINVAL;
254 if (!capable(CAP_SYS_ADMIN))
255 return -EPERM;
256
257 ths7303_write(sd, reg->reg, reg->val);
258 return 0;
259}
260#endif
261
262static const char * const stc_lpf_sel_txt[4] = {
263 "500-kHz Filter",
264 "2.5-MHz Filter",
265 "5-MHz Filter",
266 "5-MHz Filter",
267};
268
269static const char * const in_mux_sel_txt[2] = {
270 "Input A Select",
271 "Input B Select",
272};
273
274static const char * const lpf_freq_sel_txt[4] = {
275 "9-MHz LPF",
276 "16-MHz LPF",
277 "35-MHz LPF",
278 "Bypass LPF",
279};
280
281static const char * const in_bias_sel_dis_cont_txt[8] = {
282 "Disable Channel",
283 "Mute Function - No Output",
284 "DC Bias Select",
285 "DC Bias + 250 mV Offset Select",
286 "AC Bias Select",
287 "Sync Tip Clamp with low bias",
288 "Sync Tip Clamp with mid bias",
289 "Sync Tip Clamp with high bias",
290};
291
292static void ths7303_log_channel_status(struct v4l2_subdev *sd, u8 reg)
293{
294 u8 val = ths7303_read(sd, reg);
295
296 if ((val & 0x7) == 0) {
297 v4l2_info(sd, "Channel %d Off\n", reg);
298 return;
299 }
300
301 v4l2_info(sd, "Channel %d On\n", reg);
302 v4l2_info(sd, " value 0x%x\n", val);
303 v4l2_info(sd, " %s\n", stc_lpf_sel_txt[(val >> 6) & 0x3]);
304 v4l2_info(sd, " %s\n", in_mux_sel_txt[(val >> 5) & 0x1]);
305 v4l2_info(sd, " %s\n", lpf_freq_sel_txt[(val >> 3) & 0x3]);
306 v4l2_info(sd, " %s\n", in_bias_sel_dis_cont_txt[(val >> 0) & 0x7]);
307}
308
309static int ths7303_log_status(struct v4l2_subdev *sd)
310{
311 struct ths7303_state *state = to_state(sd);
312
313 v4l2_info(sd, "stream %s\n", state->stream_on ? "On" : "Off");
314
315 if (state->bt.pixelclock) {
316 struct v4l2_bt_timings *bt = bt = &state->bt;
317 u32 frame_width, frame_height;
318
319 frame_width = bt->width + bt->hfrontporch +
320 bt->hsync + bt->hbackporch;
321 frame_height = bt->height + bt->vfrontporch +
322 bt->vsync + bt->vbackporch;
323 v4l2_info(sd,
324 "timings: %dx%d%s%d (%dx%d). Pix freq. = %d Hz. Polarities = 0x%x\n",
325 bt->width, bt->height, bt->interlaced ? "i" : "p",
326 (frame_height * frame_width) > 0 ?
327 (int)bt->pixelclock /
328 (frame_height * frame_width) : 0,
329 frame_width, frame_height,
330 (int)bt->pixelclock, bt->polarities);
331 } else {
332 v4l2_info(sd, "no timings set\n");
333 }
334
335 ths7303_log_channel_status(sd, THS7303_CHANNEL_1);
336 ths7303_log_channel_status(sd, THS7303_CHANNEL_2);
337 ths7303_log_channel_status(sd, THS7303_CHANNEL_3);
338
339 return 0;
340}
341
157static const struct v4l2_subdev_core_ops ths7303_core_ops = { 342static const struct v4l2_subdev_core_ops ths7303_core_ops = {
158 .g_chip_ident = ths7303_g_chip_ident, 343 .g_chip_ident = ths7303_g_chip_ident,
344 .log_status = ths7303_log_status,
345#ifdef CONFIG_VIDEO_ADV_DEBUG
346 .g_register = ths7303_g_register,
347 .s_register = ths7303_s_register,
348#endif
159}; 349};
160 350
161static const struct v4l2_subdev_ops ths7303_ops = { 351static const struct v4l2_subdev_ops ths7303_ops = {
@@ -163,11 +353,38 @@ static const struct v4l2_subdev_ops ths7303_ops = {
163 .video = &ths7303_video_ops, 353 .video = &ths7303_video_ops,
164}; 354};
165 355
356static int ths7303_setup(struct v4l2_subdev *sd)
357{
358 struct ths7303_state *state = to_state(sd);
359 struct ths7303_platform_data *pdata = &state->pdata;
360 int ret;
361 u8 mask;
362
363 state->stream_on = pdata->init_enable;
364
365 mask = state->stream_on ? 0xff : 0xf8;
366
367 ret = ths7303_write(sd, THS7303_CHANNEL_1, pdata->ch_1 & mask);
368 if (ret)
369 return ret;
370
371 ret = ths7303_write(sd, THS7303_CHANNEL_2, pdata->ch_2 & mask);
372 if (ret)
373 return ret;
374
375 ret = ths7303_write(sd, THS7303_CHANNEL_3, pdata->ch_3 & mask);
376 if (ret)
377 return ret;
378
379 return 0;
380}
381
166static int ths7303_probe(struct i2c_client *client, 382static int ths7303_probe(struct i2c_client *client,
167 const struct i2c_device_id *id) 383 const struct i2c_device_id *id)
168{ 384{
385 struct ths7303_platform_data *pdata = client->dev.platform_data;
386 struct ths7303_state *state;
169 struct v4l2_subdev *sd; 387 struct v4l2_subdev *sd;
170 v4l2_std_id std_id = V4L2_STD_NTSC;
171 388
172 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 389 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
173 return -ENODEV; 390 return -ENODEV;
@@ -175,13 +392,28 @@ static int ths7303_probe(struct i2c_client *client,
175 v4l_info(client, "chip found @ 0x%x (%s)\n", 392 v4l_info(client, "chip found @ 0x%x (%s)\n",
176 client->addr << 1, client->adapter->name); 393 client->addr << 1, client->adapter->name);
177 394
178 sd = devm_kzalloc(&client->dev, sizeof(struct v4l2_subdev), GFP_KERNEL); 395 state = devm_kzalloc(&client->dev, sizeof(struct ths7303_state),
179 if (sd == NULL) 396 GFP_KERNEL);
397 if (!state)
180 return -ENOMEM; 398 return -ENOMEM;
181 399
400 if (!pdata)
401 v4l_warn(client, "No platform data, using default data!\n");
402 else
403 state->pdata = *pdata;
404
405 sd = &state->sd;
182 v4l2_i2c_subdev_init(sd, client, &ths7303_ops); 406 v4l2_i2c_subdev_init(sd, client, &ths7303_ops);
183 407
184 return ths7303_s_std_output(sd, std_id); 408 /* store the driver data to differntiate the chip */
409 state->driver_data = (int)id->driver_data;
410
411 if (ths7303_setup(sd) < 0) {
412 v4l_err(client, "init failed\n");
413 return -EIO;
414 }
415
416 return 0;
185} 417}
186 418
187static int ths7303_remove(struct i2c_client *client) 419static int ths7303_remove(struct i2c_client *client)
@@ -194,7 +426,8 @@ static int ths7303_remove(struct i2c_client *client)
194} 426}
195 427
196static const struct i2c_device_id ths7303_id[] = { 428static const struct i2c_device_id ths7303_id[] = {
197 {"ths7303", 0}, 429 {"ths7303", V4L2_IDENT_THS7303},
430 {"ths7353", V4L2_IDENT_THS7353},
198 {}, 431 {},
199}; 432};
200 433
@@ -203,7 +436,7 @@ MODULE_DEVICE_TABLE(i2c, ths7303_id);
203static struct i2c_driver ths7303_driver = { 436static struct i2c_driver ths7303_driver = {
204 .driver = { 437 .driver = {
205 .owner = THIS_MODULE, 438 .owner = THIS_MODULE,
206 .name = "ths7303", 439 .name = "ths73x3",
207 }, 440 },
208 .probe = ths7303_probe, 441 .probe = ths7303_probe,
209 .remove = ths7303_remove, 442 .remove = ths7303_remove,
diff --git a/drivers/media/i2c/tvaudio.c b/drivers/media/i2c/tvaudio.c
index e3b33b78dd21..b72a59d3216a 100644
--- a/drivers/media/i2c/tvaudio.c
+++ b/drivers/media/i2c/tvaudio.c
@@ -1761,7 +1761,7 @@ static int tvaudio_s_routing(struct v4l2_subdev *sd,
1761 return 0; 1761 return 0;
1762} 1762}
1763 1763
1764static int tvaudio_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 1764static int tvaudio_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
1765{ 1765{
1766 struct CHIPSTATE *chip = to_state(sd); 1766 struct CHIPSTATE *chip = to_state(sd);
1767 struct CHIPDESC *desc = chip->desc; 1767 struct CHIPDESC *desc = chip->desc;
@@ -1803,7 +1803,7 @@ static int tvaudio_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1803 1803
1804 vt->audmode = chip->audmode; 1804 vt->audmode = chip->audmode;
1805 vt->rxsubchans = desc->getrxsubchans(chip); 1805 vt->rxsubchans = desc->getrxsubchans(chip);
1806 vt->capability = V4L2_TUNER_CAP_STEREO | 1806 vt->capability |= V4L2_TUNER_CAP_STEREO |
1807 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2; 1807 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
1808 1808
1809 return 0; 1809 return 0;
@@ -1817,7 +1817,7 @@ static int tvaudio_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
1817 return 0; 1817 return 0;
1818} 1818}
1819 1819
1820static int tvaudio_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) 1820static int tvaudio_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *freq)
1821{ 1821{
1822 struct CHIPSTATE *chip = to_state(sd); 1822 struct CHIPSTATE *chip = to_state(sd);
1823 struct CHIPDESC *desc = chip->desc; 1823 struct CHIPDESC *desc = chip->desc;
diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index aa94ebc2d755..ab8f3fee7e94 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -12,6 +12,7 @@
12 * Hardik Shah <hardik.shah@ti.com> 12 * Hardik Shah <hardik.shah@ti.com>
13 * Manjunath Hadli <mrh@ti.com> 13 * Manjunath Hadli <mrh@ti.com>
14 * Karicheri Muralidharan <m-karicheri2@ti.com> 14 * Karicheri Muralidharan <m-karicheri2@ti.com>
15 * Prabhakar Lad <prabhakar.lad@ti.com>
15 * 16 *
16 * This package is free software; you can redistribute it and/or modify 17 * This package is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as 18 * it under the terms of the GNU General Public License version 2 as
@@ -33,6 +34,7 @@
33#include <linux/delay.h> 34#include <linux/delay.h>
34#include <linux/videodev2.h> 35#include <linux/videodev2.h>
35#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/v4l2-mediabus.h>
36 38
37#include <media/v4l2-device.h> 39#include <media/v4l2-device.h>
38#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
@@ -40,12 +42,10 @@
40#include <media/v4l2-chip-ident.h> 42#include <media/v4l2-chip-ident.h>
41#include <media/v4l2-ctrls.h> 43#include <media/v4l2-ctrls.h>
42#include <media/tvp514x.h> 44#include <media/tvp514x.h>
45#include <media/media-entity.h>
43 46
44#include "tvp514x_regs.h" 47#include "tvp514x_regs.h"
45 48
46/* Module Name */
47#define TVP514X_MODULE_NAME "tvp514x"
48
49/* Private macros for TVP */ 49/* Private macros for TVP */
50#define I2C_RETRY_COUNT (5) 50#define I2C_RETRY_COUNT (5)
51#define LOCK_RETRY_COUNT (5) 51#define LOCK_RETRY_COUNT (5)
@@ -91,6 +91,9 @@ static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable);
91 * @pdata: Board specific 91 * @pdata: Board specific
92 * @ver: Chip version 92 * @ver: Chip version
93 * @streaming: TVP5146/47 decoder streaming - enabled or disabled. 93 * @streaming: TVP5146/47 decoder streaming - enabled or disabled.
94 * @pix: Current pixel format
95 * @num_fmts: Number of formats
96 * @fmt_list: Format list
94 * @current_std: Current standard 97 * @current_std: Current standard
95 * @num_stds: Number of standards 98 * @num_stds: Number of standards
96 * @std_list: Standards list 99 * @std_list: Standards list
@@ -106,12 +109,20 @@ struct tvp514x_decoder {
106 int ver; 109 int ver;
107 int streaming; 110 int streaming;
108 111
112 struct v4l2_pix_format pix;
113 int num_fmts;
114 const struct v4l2_fmtdesc *fmt_list;
115
109 enum tvp514x_std current_std; 116 enum tvp514x_std current_std;
110 int num_stds; 117 int num_stds;
111 const struct tvp514x_std_info *std_list; 118 const struct tvp514x_std_info *std_list;
112 /* Input and Output Routing parameters */ 119 /* Input and Output Routing parameters */
113 u32 input; 120 u32 input;
114 u32 output; 121 u32 output;
122
123 /* mc related members */
124 struct media_pad pad;
125 struct v4l2_mbus_framefmt format;
115}; 126};
116 127
117/* TVP514x default register values */ 128/* TVP514x default register values */
@@ -200,6 +211,21 @@ static struct tvp514x_reg tvp514x_reg_list_default[] = {
200}; 211};
201 212
202/** 213/**
214 * List of image formats supported by TVP5146/47 decoder
215 * Currently we are using 8 bit mode only, but can be
216 * extended to 10/20 bit mode.
217 */
218static const struct v4l2_fmtdesc tvp514x_fmt_list[] = {
219 {
220 .index = 0,
221 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
222 .flags = 0,
223 .description = "8-bit UYVY 4:2:2 Format",
224 .pixelformat = V4L2_PIX_FMT_UYVY,
225 },
226};
227
228/**
203 * Supported standards - 229 * Supported standards -
204 * 230 *
205 * Currently supports two standards only, need to add support for rest of the 231 * Currently supports two standards only, need to add support for rest of the
@@ -733,7 +759,7 @@ tvp514x_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index,
733} 759}
734 760
735/** 761/**
736 * tvp514x_mbus_fmt_cap() - V4L2 decoder interface handler for try/s/g_mbus_fmt 762 * tvp514x_mbus_fmt() - V4L2 decoder interface handler for try/s/g_mbus_fmt
737 * @sd: pointer to standard V4L2 sub-device structure 763 * @sd: pointer to standard V4L2 sub-device structure
738 * @f: pointer to the mediabus format structure 764 * @f: pointer to the mediabus format structure
739 * 765 *
@@ -751,12 +777,11 @@ tvp514x_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
751 /* Calculate height and width based on current standard */ 777 /* Calculate height and width based on current standard */
752 current_std = decoder->current_std; 778 current_std = decoder->current_std;
753 779
754 f->code = V4L2_MBUS_FMT_YUYV10_2X10; 780 f->code = V4L2_MBUS_FMT_YUYV8_2X8;
755 f->width = decoder->std_list[current_std].width; 781 f->width = decoder->std_list[current_std].width;
756 f->height = decoder->std_list[current_std].height; 782 f->height = decoder->std_list[current_std].height;
757 f->field = V4L2_FIELD_INTERLACED; 783 f->field = V4L2_FIELD_INTERLACED;
758 f->colorspace = V4L2_COLORSPACE_SMPTE170M; 784 f->colorspace = V4L2_COLORSPACE_SMPTE170M;
759
760 v4l2_dbg(1, debug, sd, "MBUS_FMT: Width - %d, Height - %d\n", 785 v4l2_dbg(1, debug, sd, "MBUS_FMT: Width - %d, Height - %d\n",
761 f->width, f->height); 786 f->width, f->height);
762 return 0; 787 return 0;
@@ -892,6 +917,88 @@ static const struct v4l2_ctrl_ops tvp514x_ctrl_ops = {
892 .s_ctrl = tvp514x_s_ctrl, 917 .s_ctrl = tvp514x_s_ctrl,
893}; 918};
894 919
920/**
921 * tvp514x_enum_mbus_code() - V4L2 decoder interface handler for enum_mbus_code
922 * @sd: pointer to standard V4L2 sub-device structure
923 * @fh: file handle
924 * @code: pointer to v4l2_subdev_mbus_code_enum structure
925 *
926 * Enumertaes mbus codes supported
927 */
928static int tvp514x_enum_mbus_code(struct v4l2_subdev *sd,
929 struct v4l2_subdev_fh *fh,
930 struct v4l2_subdev_mbus_code_enum *code)
931{
932 u32 pad = code->pad;
933 u32 index = code->index;
934
935 memset(code, 0, sizeof(*code));
936 code->index = index;
937 code->pad = pad;
938
939 if (index != 0)
940 return -EINVAL;
941
942 code->code = V4L2_MBUS_FMT_YUYV8_2X8;
943
944 return 0;
945}
946
947/**
948 * tvp514x_get_pad_format() - V4L2 decoder interface handler for get pad format
949 * @sd: pointer to standard V4L2 sub-device structure
950 * @fh: file handle
951 * @format: pointer to v4l2_subdev_format structure
952 *
953 * Retrieves pad format which is active or tried based on requirement
954 */
955static int tvp514x_get_pad_format(struct v4l2_subdev *sd,
956 struct v4l2_subdev_fh *fh,
957 struct v4l2_subdev_format *format)
958{
959 struct tvp514x_decoder *decoder = to_decoder(sd);
960 __u32 which = format->which;
961
962 if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
963 format->format = decoder->format;
964 return 0;
965 }
966
967 format->format.code = V4L2_MBUS_FMT_YUYV8_2X8;
968 format->format.width = tvp514x_std_list[decoder->current_std].width;
969 format->format.height = tvp514x_std_list[decoder->current_std].height;
970 format->format.colorspace = V4L2_COLORSPACE_SMPTE170M;
971 format->format.field = V4L2_FIELD_INTERLACED;
972
973 return 0;
974}
975
976/**
977 * tvp514x_set_pad_format() - V4L2 decoder interface handler for set pad format
978 * @sd: pointer to standard V4L2 sub-device structure
979 * @fh: file handle
980 * @format: pointer to v4l2_subdev_format structure
981 *
982 * Set pad format for the output pad
983 */
984static int tvp514x_set_pad_format(struct v4l2_subdev *sd,
985 struct v4l2_subdev_fh *fh,
986 struct v4l2_subdev_format *fmt)
987{
988 struct tvp514x_decoder *decoder = to_decoder(sd);
989
990 if (fmt->format.field != V4L2_FIELD_INTERLACED ||
991 fmt->format.code != V4L2_MBUS_FMT_YUYV8_2X8 ||
992 fmt->format.colorspace != V4L2_COLORSPACE_SMPTE170M ||
993 fmt->format.width != tvp514x_std_list[decoder->current_std].width ||
994 fmt->format.height != tvp514x_std_list[decoder->current_std].height)
995 return -EINVAL;
996
997 decoder->format = fmt->format;
998
999 return 0;
1000}
1001
895static const struct v4l2_subdev_core_ops tvp514x_core_ops = { 1002static const struct v4l2_subdev_core_ops tvp514x_core_ops = {
896 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 1003 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
897 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 1004 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
@@ -915,13 +1022,33 @@ static const struct v4l2_subdev_video_ops tvp514x_video_ops = {
915 .s_stream = tvp514x_s_stream, 1022 .s_stream = tvp514x_s_stream,
916}; 1023};
917 1024
1025static const struct v4l2_subdev_pad_ops tvp514x_pad_ops = {
1026 .enum_mbus_code = tvp514x_enum_mbus_code,
1027 .get_fmt = tvp514x_get_pad_format,
1028 .set_fmt = tvp514x_set_pad_format,
1029};
1030
918static const struct v4l2_subdev_ops tvp514x_ops = { 1031static const struct v4l2_subdev_ops tvp514x_ops = {
919 .core = &tvp514x_core_ops, 1032 .core = &tvp514x_core_ops,
920 .video = &tvp514x_video_ops, 1033 .video = &tvp514x_video_ops,
1034 .pad = &tvp514x_pad_ops,
921}; 1035};
922 1036
923static struct tvp514x_decoder tvp514x_dev = { 1037static struct tvp514x_decoder tvp514x_dev = {
924 .streaming = 0, 1038 .streaming = 0,
1039 .fmt_list = tvp514x_fmt_list,
1040 .num_fmts = ARRAY_SIZE(tvp514x_fmt_list),
1041 .pix = {
1042 /* Default to NTSC 8-bit YUV 422 */
1043 .width = NTSC_NUM_ACTIVE_PIXELS,
1044 .height = NTSC_NUM_ACTIVE_LINES,
1045 .pixelformat = V4L2_PIX_FMT_UYVY,
1046 .field = V4L2_FIELD_INTERLACED,
1047 .bytesperline = NTSC_NUM_ACTIVE_PIXELS * 2,
1048 .sizeimage = NTSC_NUM_ACTIVE_PIXELS * 2 *
1049 NTSC_NUM_ACTIVE_LINES,
1050 .colorspace = V4L2_COLORSPACE_SMPTE170M,
1051 },
925 .current_std = STD_NTSC_MJ, 1052 .current_std = STD_NTSC_MJ,
926 .std_list = tvp514x_std_list, 1053 .std_list = tvp514x_std_list,
927 .num_stds = ARRAY_SIZE(tvp514x_std_list), 1054 .num_stds = ARRAY_SIZE(tvp514x_std_list),
@@ -941,6 +1068,7 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
941{ 1068{
942 struct tvp514x_decoder *decoder; 1069 struct tvp514x_decoder *decoder;
943 struct v4l2_subdev *sd; 1070 struct v4l2_subdev *sd;
1071 int ret;
944 1072
945 /* Check if the adapter supports the needed features */ 1073 /* Check if the adapter supports the needed features */
946 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1074 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
@@ -981,7 +1109,21 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
981 /* Register with V4L2 layer as slave device */ 1109 /* Register with V4L2 layer as slave device */
982 sd = &decoder->sd; 1110 sd = &decoder->sd;
983 v4l2_i2c_subdev_init(sd, client, &tvp514x_ops); 1111 v4l2_i2c_subdev_init(sd, client, &tvp514x_ops);
984 1112 strlcpy(sd->name, TVP514X_MODULE_NAME, sizeof(sd->name));
1113
1114#if defined(CONFIG_MEDIA_CONTROLLER)
1115 decoder->pad.flags = MEDIA_PAD_FL_SOURCE;
1116 decoder->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1117 decoder->sd.entity.flags |= MEDIA_ENT_T_V4L2_SUBDEV_DECODER;
1118
1119 ret = media_entity_init(&decoder->sd.entity, 1, &decoder->pad, 0);
1120 if (ret < 0) {
1121 v4l2_err(sd, "%s decoder driver failed to register !!\n",
1122 sd->name);
1123 kfree(decoder);
1124 return ret;
1125 }
1126#endif
985 v4l2_ctrl_handler_init(&decoder->hdl, 5); 1127 v4l2_ctrl_handler_init(&decoder->hdl, 5);
986 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, 1128 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
987 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); 1129 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
@@ -995,10 +1137,10 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
995 V4L2_CID_AUTOGAIN, 0, 1, 1, 1); 1137 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
996 sd->ctrl_handler = &decoder->hdl; 1138 sd->ctrl_handler = &decoder->hdl;
997 if (decoder->hdl.error) { 1139 if (decoder->hdl.error) {
998 int err = decoder->hdl.error; 1140 ret = decoder->hdl.error;
999 1141
1000 v4l2_ctrl_handler_free(&decoder->hdl); 1142 v4l2_ctrl_handler_free(&decoder->hdl);
1001 return err; 1143 return ret;
1002 } 1144 }
1003 v4l2_ctrl_handler_setup(&decoder->hdl); 1145 v4l2_ctrl_handler_setup(&decoder->hdl);
1004 1146
@@ -1021,6 +1163,9 @@ static int tvp514x_remove(struct i2c_client *client)
1021 struct tvp514x_decoder *decoder = to_decoder(sd); 1163 struct tvp514x_decoder *decoder = to_decoder(sd);
1022 1164
1023 v4l2_device_unregister_subdev(sd); 1165 v4l2_device_unregister_subdev(sd);
1166#if defined(CONFIG_MEDIA_CONTROLLER)
1167 media_entity_cleanup(&decoder->sd.entity);
1168#endif
1024 v4l2_ctrl_handler_free(&decoder->hdl); 1169 v4l2_ctrl_handler_free(&decoder->hdl);
1025 return 0; 1170 return 0;
1026} 1171}
diff --git a/drivers/media/i2c/tvp5150.c b/drivers/media/i2c/tvp5150.c
index 5967e1a0c809..485159a3c0b7 100644
--- a/drivers/media/i2c/tvp5150.c
+++ b/drivers/media/i2c/tvp5150.c
@@ -1067,7 +1067,7 @@ static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
1067 return 0; 1067 return 0;
1068} 1068}
1069 1069
1070static int tvp5150_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 1070static int tvp5150_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
1071{ 1071{
1072 struct i2c_client *client = v4l2_get_subdevdata(sd); 1072 struct i2c_client *client = v4l2_get_subdevdata(sd);
1073 1073
diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c
index 537f6b4d4918..027809cca5f5 100644
--- a/drivers/media/i2c/tvp7002.c
+++ b/drivers/media/i2c/tvp7002.c
@@ -326,9 +326,8 @@ static const struct i2c_reg_value tvp7002_parms_720P50[] = {
326 { TVP7002_EOR, 0xff, TVP7002_RESERVED } 326 { TVP7002_EOR, 0xff, TVP7002_RESERVED }
327}; 327};
328 328
329/* Preset definition for handling device operation */ 329/* Timings definition for handling device operation */
330struct tvp7002_preset_definition { 330struct tvp7002_timings_definition {
331 u32 preset;
332 struct v4l2_dv_timings timings; 331 struct v4l2_dv_timings timings;
333 const struct i2c_reg_value *p_settings; 332 const struct i2c_reg_value *p_settings;
334 enum v4l2_colorspace color_space; 333 enum v4l2_colorspace color_space;
@@ -339,10 +338,9 @@ struct tvp7002_preset_definition {
339 u16 cpl_max; 338 u16 cpl_max;
340}; 339};
341 340
342/* Struct list for digital video presets */ 341/* Struct list for digital video timings */
343static const struct tvp7002_preset_definition tvp7002_presets[] = { 342static const struct tvp7002_timings_definition tvp7002_timings[] = {
344 { 343 {
345 V4L2_DV_720P60,
346 V4L2_DV_BT_CEA_1280X720P60, 344 V4L2_DV_BT_CEA_1280X720P60,
347 tvp7002_parms_720P60, 345 tvp7002_parms_720P60,
348 V4L2_COLORSPACE_REC709, 346 V4L2_COLORSPACE_REC709,
@@ -353,7 +351,6 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
353 153 351 153
354 }, 352 },
355 { 353 {
356 V4L2_DV_1080I60,
357 V4L2_DV_BT_CEA_1920X1080I60, 354 V4L2_DV_BT_CEA_1920X1080I60,
358 tvp7002_parms_1080I60, 355 tvp7002_parms_1080I60,
359 V4L2_COLORSPACE_REC709, 356 V4L2_COLORSPACE_REC709,
@@ -364,7 +361,6 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
364 205 361 205
365 }, 362 },
366 { 363 {
367 V4L2_DV_1080I50,
368 V4L2_DV_BT_CEA_1920X1080I50, 364 V4L2_DV_BT_CEA_1920X1080I50,
369 tvp7002_parms_1080I50, 365 tvp7002_parms_1080I50,
370 V4L2_COLORSPACE_REC709, 366 V4L2_COLORSPACE_REC709,
@@ -375,7 +371,6 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
375 245 371 245
376 }, 372 },
377 { 373 {
378 V4L2_DV_720P50,
379 V4L2_DV_BT_CEA_1280X720P50, 374 V4L2_DV_BT_CEA_1280X720P50,
380 tvp7002_parms_720P50, 375 tvp7002_parms_720P50,
381 V4L2_COLORSPACE_REC709, 376 V4L2_COLORSPACE_REC709,
@@ -386,7 +381,6 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
386 183 381 183
387 }, 382 },
388 { 383 {
389 V4L2_DV_1080P60,
390 V4L2_DV_BT_CEA_1920X1080P60, 384 V4L2_DV_BT_CEA_1920X1080P60,
391 tvp7002_parms_1080P60, 385 tvp7002_parms_1080P60,
392 V4L2_COLORSPACE_REC709, 386 V4L2_COLORSPACE_REC709,
@@ -397,7 +391,6 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
397 102 391 102
398 }, 392 },
399 { 393 {
400 V4L2_DV_480P59_94,
401 V4L2_DV_BT_CEA_720X480P59_94, 394 V4L2_DV_BT_CEA_720X480P59_94,
402 tvp7002_parms_480P, 395 tvp7002_parms_480P,
403 V4L2_COLORSPACE_SMPTE170M, 396 V4L2_COLORSPACE_SMPTE170M,
@@ -408,7 +401,6 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
408 0xffff 401 0xffff
409 }, 402 },
410 { 403 {
411 V4L2_DV_576P50,
412 V4L2_DV_BT_CEA_720X576P50, 404 V4L2_DV_BT_CEA_720X576P50,
413 tvp7002_parms_576P, 405 tvp7002_parms_576P,
414 V4L2_COLORSPACE_SMPTE170M, 406 V4L2_COLORSPACE_SMPTE170M,
@@ -420,7 +412,7 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
420 } 412 }
421}; 413};
422 414
423#define NUM_PRESETS ARRAY_SIZE(tvp7002_presets) 415#define NUM_TIMINGS ARRAY_SIZE(tvp7002_timings)
424 416
425/* Device definition */ 417/* Device definition */
426struct tvp7002 { 418struct tvp7002 {
@@ -431,7 +423,7 @@ struct tvp7002 {
431 int ver; 423 int ver;
432 int streaming; 424 int streaming;
433 425
434 const struct tvp7002_preset_definition *current_preset; 426 const struct tvp7002_timings_definition *current_timings;
435}; 427};
436 428
437/* 429/*
@@ -588,32 +580,6 @@ static int tvp7002_write_inittab(struct v4l2_subdev *sd,
588 return error; 580 return error;
589} 581}
590 582
591/*
592 * tvp7002_s_dv_preset() - Set digital video preset
593 * @sd: ptr to v4l2_subdev struct
594 * @dv_preset: ptr to v4l2_dv_preset struct
595 *
596 * Set the digital video preset for a TVP7002 decoder device.
597 * Returns zero when successful or -EINVAL if register access fails.
598 */
599static int tvp7002_s_dv_preset(struct v4l2_subdev *sd,
600 struct v4l2_dv_preset *dv_preset)
601{
602 struct tvp7002 *device = to_tvp7002(sd);
603 u32 preset;
604 int i;
605
606 for (i = 0; i < NUM_PRESETS; i++) {
607 preset = tvp7002_presets[i].preset;
608 if (preset == dv_preset->preset) {
609 device->current_preset = &tvp7002_presets[i];
610 return tvp7002_write_inittab(sd, tvp7002_presets[i].p_settings);
611 }
612 }
613
614 return -EINVAL;
615}
616
617static int tvp7002_s_dv_timings(struct v4l2_subdev *sd, 583static int tvp7002_s_dv_timings(struct v4l2_subdev *sd,
618 struct v4l2_dv_timings *dv_timings) 584 struct v4l2_dv_timings *dv_timings)
619{ 585{
@@ -623,12 +589,12 @@ static int tvp7002_s_dv_timings(struct v4l2_subdev *sd,
623 589
624 if (dv_timings->type != V4L2_DV_BT_656_1120) 590 if (dv_timings->type != V4L2_DV_BT_656_1120)
625 return -EINVAL; 591 return -EINVAL;
626 for (i = 0; i < NUM_PRESETS; i++) { 592 for (i = 0; i < NUM_TIMINGS; i++) {
627 const struct v4l2_bt_timings *t = &tvp7002_presets[i].timings.bt; 593 const struct v4l2_bt_timings *t = &tvp7002_timings[i].timings.bt;
628 594
629 if (!memcmp(bt, t, &bt->standards - &bt->width)) { 595 if (!memcmp(bt, t, &bt->standards - &bt->width)) {
630 device->current_preset = &tvp7002_presets[i]; 596 device->current_timings = &tvp7002_timings[i];
631 return tvp7002_write_inittab(sd, tvp7002_presets[i].p_settings); 597 return tvp7002_write_inittab(sd, tvp7002_timings[i].p_settings);
632 } 598 }
633 } 599 }
634 return -EINVAL; 600 return -EINVAL;
@@ -639,7 +605,7 @@ static int tvp7002_g_dv_timings(struct v4l2_subdev *sd,
639{ 605{
640 struct tvp7002 *device = to_tvp7002(sd); 606 struct tvp7002 *device = to_tvp7002(sd);
641 607
642 *dv_timings = device->current_preset->timings; 608 *dv_timings = device->current_timings->timings;
643 return 0; 609 return 0;
644} 610}
645 611
@@ -677,19 +643,13 @@ static int tvp7002_s_ctrl(struct v4l2_ctrl *ctrl)
677static int tvp7002_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f) 643static int tvp7002_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
678{ 644{
679 struct tvp7002 *device = to_tvp7002(sd); 645 struct tvp7002 *device = to_tvp7002(sd);
680 struct v4l2_dv_enum_preset e_preset; 646 const struct v4l2_bt_timings *bt = &device->current_timings->timings.bt;
681 int error;
682 647
683 /* Calculate height and width based on current standard */ 648 f->width = bt->width;
684 error = v4l_fill_dv_preset_info(device->current_preset->preset, &e_preset); 649 f->height = bt->height;
685 if (error)
686 return error;
687
688 f->width = e_preset.width;
689 f->height = e_preset.height;
690 f->code = V4L2_MBUS_FMT_YUYV10_1X20; 650 f->code = V4L2_MBUS_FMT_YUYV10_1X20;
691 f->field = device->current_preset->scanmode; 651 f->field = device->current_timings->scanmode;
692 f->colorspace = device->current_preset->color_space; 652 f->colorspace = device->current_timings->color_space;
693 653
694 v4l2_dbg(1, debug, sd, "MBUS_FMT: Width - %d, Height - %d", 654 v4l2_dbg(1, debug, sd, "MBUS_FMT: Width - %d, Height - %d",
695 f->width, f->height); 655 f->width, f->height);
@@ -697,16 +657,16 @@ static int tvp7002_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f
697} 657}
698 658
699/* 659/*
700 * tvp7002_query_dv_preset() - query DV preset 660 * tvp7002_query_dv() - query DV timings
701 * @sd: pointer to standard V4L2 sub-device structure 661 * @sd: pointer to standard V4L2 sub-device structure
702 * @qpreset: standard V4L2 v4l2_dv_preset structure 662 * @index: index into the tvp7002_timings array
703 * 663 *
704 * Returns the current DV preset by TVP7002. If no active input is 664 * Returns the current DV timings detected by TVP7002. If no active input is
705 * detected, returns -EINVAL 665 * detected, returns -EINVAL
706 */ 666 */
707static int tvp7002_query_dv(struct v4l2_subdev *sd, int *index) 667static int tvp7002_query_dv(struct v4l2_subdev *sd, int *index)
708{ 668{
709 const struct tvp7002_preset_definition *presets = tvp7002_presets; 669 const struct tvp7002_timings_definition *timings = tvp7002_timings;
710 u8 progressive; 670 u8 progressive;
711 u32 lpfr; 671 u32 lpfr;
712 u32 cpln; 672 u32 cpln;
@@ -717,7 +677,7 @@ static int tvp7002_query_dv(struct v4l2_subdev *sd, int *index)
717 u8 cpl_msb; 677 u8 cpl_msb;
718 678
719 /* Return invalid index if no active input is detected */ 679 /* Return invalid index if no active input is detected */
720 *index = NUM_PRESETS; 680 *index = NUM_TIMINGS;
721 681
722 /* Read standards from device registers */ 682 /* Read standards from device registers */
723 tvp7002_read_err(sd, TVP7002_L_FRAME_STAT_LSBS, &lpf_lsb, &error); 683 tvp7002_read_err(sd, TVP7002_L_FRAME_STAT_LSBS, &lpf_lsb, &error);
@@ -738,39 +698,23 @@ static int tvp7002_query_dv(struct v4l2_subdev *sd, int *index)
738 progressive = (lpf_msb & TVP7002_INPR_MASK) >> TVP7002_IP_SHIFT; 698 progressive = (lpf_msb & TVP7002_INPR_MASK) >> TVP7002_IP_SHIFT;
739 699
740 /* Do checking of video modes */ 700 /* Do checking of video modes */
741 for (*index = 0; *index < NUM_PRESETS; (*index)++, presets++) 701 for (*index = 0; *index < NUM_TIMINGS; (*index)++, timings++)
742 if (lpfr == presets->lines_per_frame && 702 if (lpfr == timings->lines_per_frame &&
743 progressive == presets->progressive) { 703 progressive == timings->progressive) {
744 if (presets->cpl_min == 0xffff) 704 if (timings->cpl_min == 0xffff)
745 break; 705 break;
746 if (cpln >= presets->cpl_min && cpln <= presets->cpl_max) 706 if (cpln >= timings->cpl_min && cpln <= timings->cpl_max)
747 break; 707 break;
748 } 708 }
749 709
750 if (*index == NUM_PRESETS) { 710 if (*index == NUM_TIMINGS) {
751 v4l2_dbg(1, debug, sd, "detection failed: lpf = %x, cpl = %x\n", 711 v4l2_dbg(1, debug, sd, "detection failed: lpf = %x, cpl = %x\n",
752 lpfr, cpln); 712 lpfr, cpln);
753 return -ENOLINK; 713 return -ENOLINK;
754 } 714 }
755 715
756 /* Update lines per frame and clocks per line info */ 716 /* Update lines per frame and clocks per line info */
757 v4l2_dbg(1, debug, sd, "detected preset: %d\n", *index); 717 v4l2_dbg(1, debug, sd, "detected timings: %d\n", *index);
758 return 0;
759}
760
761static int tvp7002_query_dv_preset(struct v4l2_subdev *sd,
762 struct v4l2_dv_preset *qpreset)
763{
764 int index;
765 int err = tvp7002_query_dv(sd, &index);
766
767 if (err || index == NUM_PRESETS) {
768 qpreset->preset = V4L2_DV_INVALID;
769 if (err == -ENOLINK)
770 err = 0;
771 return err;
772 }
773 qpreset->preset = tvp7002_presets[index].preset;
774 return 0; 718 return 0;
775} 719}
776 720
@@ -782,7 +726,7 @@ static int tvp7002_query_dv_timings(struct v4l2_subdev *sd,
782 726
783 if (err) 727 if (err)
784 return err; 728 return err;
785 *timings = tvp7002_presets[index].timings; 729 *timings = tvp7002_timings[index].timings;
786 return 0; 730 return 0;
787} 731}
788 732
@@ -824,7 +768,7 @@ static int tvp7002_g_register(struct v4l2_subdev *sd,
824 * -EPERM if call not allowed. 768 * -EPERM if call not allowed.
825 */ 769 */
826static int tvp7002_s_register(struct v4l2_subdev *sd, 770static int tvp7002_s_register(struct v4l2_subdev *sd,
827 struct v4l2_dbg_register *reg) 771 const struct v4l2_dbg_register *reg)
828{ 772{
829 struct i2c_client *client = v4l2_get_subdevdata(sd); 773 struct i2c_client *client = v4l2_get_subdevdata(sd);
830 774
@@ -896,35 +840,21 @@ static int tvp7002_s_stream(struct v4l2_subdev *sd, int enable)
896 */ 840 */
897static int tvp7002_log_status(struct v4l2_subdev *sd) 841static int tvp7002_log_status(struct v4l2_subdev *sd)
898{ 842{
899 const struct tvp7002_preset_definition *presets = tvp7002_presets;
900 struct tvp7002 *device = to_tvp7002(sd); 843 struct tvp7002 *device = to_tvp7002(sd);
901 struct v4l2_dv_enum_preset e_preset; 844 const struct v4l2_bt_timings *bt;
902 struct v4l2_dv_preset detected; 845 int detected;
903 int i;
904
905 detected.preset = V4L2_DV_INVALID;
906 /* Find my current standard*/
907 tvp7002_query_dv_preset(sd, &detected);
908 846
909 /* Print standard related code values */ 847 /* Find my current timings */
910 for (i = 0; i < NUM_PRESETS; i++, presets++) 848 tvp7002_query_dv(sd, &detected);
911 if (presets->preset == detected.preset)
912 break;
913 849
914 if (v4l_fill_dv_preset_info(device->current_preset->preset, &e_preset)) 850 bt = &device->current_timings->timings.bt;
915 return -EINVAL; 851 v4l2_info(sd, "Selected DV Timings: %ux%u\n", bt->width, bt->height);
916 852 if (detected == NUM_TIMINGS) {
917 v4l2_info(sd, "Selected DV Preset: %s\n", e_preset.name); 853 v4l2_info(sd, "Detected DV Timings: None\n");
918 v4l2_info(sd, " Pixels per line: %u\n", e_preset.width);
919 v4l2_info(sd, " Lines per frame: %u\n\n", e_preset.height);
920 if (i == NUM_PRESETS) {
921 v4l2_info(sd, "Detected DV Preset: None\n");
922 } else { 854 } else {
923 if (v4l_fill_dv_preset_info(presets->preset, &e_preset)) 855 bt = &tvp7002_timings[detected].timings.bt;
924 return -EINVAL; 856 v4l2_info(sd, "Detected DV Timings: %ux%u\n",
925 v4l2_info(sd, "Detected DV Preset: %s\n", e_preset.name); 857 bt->width, bt->height);
926 v4l2_info(sd, " Pixels per line: %u\n", e_preset.width);
927 v4l2_info(sd, " Lines per frame: %u\n\n", e_preset.height);
928 } 858 }
929 v4l2_info(sd, "Streaming enabled: %s\n", 859 v4l2_info(sd, "Streaming enabled: %s\n",
930 device->streaming ? "yes" : "no"); 860 device->streaming ? "yes" : "no");
@@ -935,31 +865,14 @@ static int tvp7002_log_status(struct v4l2_subdev *sd)
935 return 0; 865 return 0;
936} 866}
937 867
938/*
939 * tvp7002_enum_dv_presets() - Enum supported digital video formats
940 * @sd: pointer to standard V4L2 sub-device structure
941 * @preset: pointer to format struct
942 *
943 * Enumerate supported digital video formats.
944 */
945static int tvp7002_enum_dv_presets(struct v4l2_subdev *sd,
946 struct v4l2_dv_enum_preset *preset)
947{
948 /* Check requested format index is within range */
949 if (preset->index >= NUM_PRESETS)
950 return -EINVAL;
951
952 return v4l_fill_dv_preset_info(tvp7002_presets[preset->index].preset, preset);
953}
954
955static int tvp7002_enum_dv_timings(struct v4l2_subdev *sd, 868static int tvp7002_enum_dv_timings(struct v4l2_subdev *sd,
956 struct v4l2_enum_dv_timings *timings) 869 struct v4l2_enum_dv_timings *timings)
957{ 870{
958 /* Check requested format index is within range */ 871 /* Check requested format index is within range */
959 if (timings->index >= NUM_PRESETS) 872 if (timings->index >= NUM_TIMINGS)
960 return -EINVAL; 873 return -EINVAL;
961 874
962 timings->timings = tvp7002_presets[timings->index].timings; 875 timings->timings = tvp7002_timings[timings->index].timings;
963 return 0; 876 return 0;
964} 877}
965 878
@@ -986,9 +899,6 @@ static const struct v4l2_subdev_core_ops tvp7002_core_ops = {
986 899
987/* Specific video subsystem operation handlers */ 900/* Specific video subsystem operation handlers */
988static const struct v4l2_subdev_video_ops tvp7002_video_ops = { 901static const struct v4l2_subdev_video_ops tvp7002_video_ops = {
989 .enum_dv_presets = tvp7002_enum_dv_presets,
990 .s_dv_preset = tvp7002_s_dv_preset,
991 .query_dv_preset = tvp7002_query_dv_preset,
992 .g_dv_timings = tvp7002_g_dv_timings, 902 .g_dv_timings = tvp7002_g_dv_timings,
993 .s_dv_timings = tvp7002_s_dv_timings, 903 .s_dv_timings = tvp7002_s_dv_timings,
994 .enum_dv_timings = tvp7002_enum_dv_timings, 904 .enum_dv_timings = tvp7002_enum_dv_timings,
@@ -1019,7 +929,7 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
1019{ 929{
1020 struct v4l2_subdev *sd; 930 struct v4l2_subdev *sd;
1021 struct tvp7002 *device; 931 struct tvp7002 *device;
1022 struct v4l2_dv_preset preset; 932 struct v4l2_dv_timings timings;
1023 int polarity_a; 933 int polarity_a;
1024 int polarity_b; 934 int polarity_b;
1025 u8 revision; 935 u8 revision;
@@ -1043,7 +953,7 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
1043 953
1044 sd = &device->sd; 954 sd = &device->sd;
1045 device->pdata = c->dev.platform_data; 955 device->pdata = c->dev.platform_data;
1046 device->current_preset = tvp7002_presets; 956 device->current_timings = tvp7002_timings;
1047 957
1048 /* Tell v4l2 the device is ready */ 958 /* Tell v4l2 the device is ready */
1049 v4l2_i2c_subdev_init(sd, c, &tvp7002_ops); 959 v4l2_i2c_subdev_init(sd, c, &tvp7002_ops);
@@ -1080,8 +990,8 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
1080 return error; 990 return error;
1081 991
1082 /* Set registers according to default video mode */ 992 /* Set registers according to default video mode */
1083 preset.preset = device->current_preset->preset; 993 timings = device->current_timings->timings;
1084 error = tvp7002_s_dv_preset(sd, &preset); 994 error = tvp7002_s_dv_timings(sd, &timings);
1085 995
1086 v4l2_ctrl_handler_init(&device->hdl, 1); 996 v4l2_ctrl_handler_init(&device->hdl, 1);
1087 v4l2_ctrl_new_std(&device->hdl, &tvp7002_ctrl_ops, 997 v4l2_ctrl_new_std(&device->hdl, &tvp7002_ctrl_ops,
diff --git a/drivers/media/i2c/tw2804.c b/drivers/media/i2c/tw2804.c
new file mode 100644
index 000000000000..c5dc2c3bf2d7
--- /dev/null
+++ b/drivers/media/i2c/tw2804.c
@@ -0,0 +1,453 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <linux/ioctl.h>
23#include <linux/slab.h>
24#include <media/v4l2-subdev.h>
25#include <media/v4l2-device.h>
26#include <media/v4l2-chip-ident.h>
27#include <media/v4l2-ctrls.h>
28
29#define TW2804_REG_AUTOGAIN 0x02
30#define TW2804_REG_HUE 0x0f
31#define TW2804_REG_SATURATION 0x10
32#define TW2804_REG_CONTRAST 0x11
33#define TW2804_REG_BRIGHTNESS 0x12
34#define TW2804_REG_COLOR_KILLER 0x14
35#define TW2804_REG_GAIN 0x3c
36#define TW2804_REG_CHROMA_GAIN 0x3d
37#define TW2804_REG_BLUE_BALANCE 0x3e
38#define TW2804_REG_RED_BALANCE 0x3f
39
40struct tw2804 {
41 struct v4l2_subdev sd;
42 struct v4l2_ctrl_handler hdl;
43 u8 channel:2;
44 u8 input:1;
45 int norm;
46};
47
48static const u8 global_registers[] = {
49 0x39, 0x00,
50 0x3a, 0xff,
51 0x3b, 0x84,
52 0x3c, 0x80,
53 0x3d, 0x80,
54 0x3e, 0x82,
55 0x3f, 0x82,
56 0x78, 0x00,
57 0xff, 0xff, /* Terminator (reg 0xff does not exist) */
58};
59
60static const u8 channel_registers[] = {
61 0x01, 0xc4,
62 0x02, 0xa5,
63 0x03, 0x20,
64 0x04, 0xd0,
65 0x05, 0x20,
66 0x06, 0xd0,
67 0x07, 0x88,
68 0x08, 0x20,
69 0x09, 0x07,
70 0x0a, 0xf0,
71 0x0b, 0x07,
72 0x0c, 0xf0,
73 0x0d, 0x40,
74 0x0e, 0xd2,
75 0x0f, 0x80,
76 0x10, 0x80,
77 0x11, 0x80,
78 0x12, 0x80,
79 0x13, 0x1f,
80 0x14, 0x00,
81 0x15, 0x00,
82 0x16, 0x00,
83 0x17, 0x00,
84 0x18, 0xff,
85 0x19, 0xff,
86 0x1a, 0xff,
87 0x1b, 0xff,
88 0x1c, 0xff,
89 0x1d, 0xff,
90 0x1e, 0xff,
91 0x1f, 0xff,
92 0x20, 0x07,
93 0x21, 0x07,
94 0x22, 0x00,
95 0x23, 0x91,
96 0x24, 0x51,
97 0x25, 0x03,
98 0x26, 0x00,
99 0x27, 0x00,
100 0x28, 0x00,
101 0x29, 0x00,
102 0x2a, 0x00,
103 0x2b, 0x00,
104 0x2c, 0x00,
105 0x2d, 0x00,
106 0x2e, 0x00,
107 0x2f, 0x00,
108 0x30, 0x00,
109 0x31, 0x00,
110 0x32, 0x00,
111 0x33, 0x00,
112 0x34, 0x00,
113 0x35, 0x00,
114 0x36, 0x00,
115 0x37, 0x00,
116 0xff, 0xff, /* Terminator (reg 0xff does not exist) */
117};
118
119static int write_reg(struct i2c_client *client, u8 reg, u8 value, u8 channel)
120{
121 return i2c_smbus_write_byte_data(client, reg | (channel << 6), value);
122}
123
124static int write_regs(struct i2c_client *client, const u8 *regs, u8 channel)
125{
126 int ret;
127 int i;
128
129 for (i = 0; regs[i] != 0xff; i += 2) {
130 ret = i2c_smbus_write_byte_data(client,
131 regs[i] | (channel << 6), regs[i + 1]);
132 if (ret < 0)
133 return ret;
134 }
135 return 0;
136}
137
138static int read_reg(struct i2c_client *client, u8 reg, u8 channel)
139{
140 return i2c_smbus_read_byte_data(client, (reg) | (channel << 6));
141}
142
143static inline struct tw2804 *to_state(struct v4l2_subdev *sd)
144{
145 return container_of(sd, struct tw2804, sd);
146}
147
148static inline struct tw2804 *to_state_from_ctrl(struct v4l2_ctrl *ctrl)
149{
150 return container_of(ctrl->handler, struct tw2804, hdl);
151}
152
153static int tw2804_log_status(struct v4l2_subdev *sd)
154{
155 struct tw2804 *state = to_state(sd);
156
157 v4l2_info(sd, "Standard: %s\n",
158 state->norm & V4L2_STD_525_60 ? "60 Hz" : "50 Hz");
159 v4l2_info(sd, "Channel: %d\n", state->channel);
160 v4l2_info(sd, "Input: %d\n", state->input);
161 return v4l2_ctrl_subdev_log_status(sd);
162}
163
164/*
165 * These volatile controls are needed because all four channels share
166 * these controls. So a change made to them through one channel would
167 * require another channel to be updated.
168 *
169 * Normally this would have been done in a different way, but since the one
170 * board that uses this driver sees this single chip as if it was on four
171 * different i2c adapters (each adapter belonging to a separate instance of
172 * the same USB driver) there is no reliable method that I have found to let
173 * the instances know about each other.
174 *
175 * So implementing these global registers as volatile is the best we can do.
176 */
177static int tw2804_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
178{
179 struct tw2804 *state = to_state_from_ctrl(ctrl);
180 struct i2c_client *client = v4l2_get_subdevdata(&state->sd);
181
182 switch (ctrl->id) {
183 case V4L2_CID_GAIN:
184 ctrl->val = read_reg(client, TW2804_REG_GAIN, 0);
185 return 0;
186
187 case V4L2_CID_CHROMA_GAIN:
188 ctrl->val = read_reg(client, TW2804_REG_CHROMA_GAIN, 0);
189 return 0;
190
191 case V4L2_CID_BLUE_BALANCE:
192 ctrl->val = read_reg(client, TW2804_REG_BLUE_BALANCE, 0);
193 return 0;
194
195 case V4L2_CID_RED_BALANCE:
196 ctrl->val = read_reg(client, TW2804_REG_RED_BALANCE, 0);
197 return 0;
198 }
199 return 0;
200}
201
202static int tw2804_s_ctrl(struct v4l2_ctrl *ctrl)
203{
204 struct tw2804 *state = to_state_from_ctrl(ctrl);
205 struct i2c_client *client = v4l2_get_subdevdata(&state->sd);
206 int addr;
207 int reg;
208
209 switch (ctrl->id) {
210 case V4L2_CID_AUTOGAIN:
211 addr = TW2804_REG_AUTOGAIN;
212 reg = read_reg(client, addr, state->channel);
213 if (reg < 0)
214 return reg;
215 if (ctrl->val == 0)
216 reg &= ~(1 << 7);
217 else
218 reg |= 1 << 7;
219 return write_reg(client, addr, reg, state->channel);
220
221 case V4L2_CID_COLOR_KILLER:
222 addr = TW2804_REG_COLOR_KILLER;
223 reg = read_reg(client, addr, state->channel);
224 if (reg < 0)
225 return reg;
226 reg = (reg & ~(0x03)) | (ctrl->val == 0 ? 0x02 : 0x03);
227 return write_reg(client, addr, reg, state->channel);
228
229 case V4L2_CID_GAIN:
230 return write_reg(client, TW2804_REG_GAIN, ctrl->val, 0);
231
232 case V4L2_CID_CHROMA_GAIN:
233 return write_reg(client, TW2804_REG_CHROMA_GAIN, ctrl->val, 0);
234
235 case V4L2_CID_BLUE_BALANCE:
236 return write_reg(client, TW2804_REG_BLUE_BALANCE, ctrl->val, 0);
237
238 case V4L2_CID_RED_BALANCE:
239 return write_reg(client, TW2804_REG_RED_BALANCE, ctrl->val, 0);
240
241 case V4L2_CID_BRIGHTNESS:
242 return write_reg(client, TW2804_REG_BRIGHTNESS,
243 ctrl->val, state->channel);
244
245 case V4L2_CID_CONTRAST:
246 return write_reg(client, TW2804_REG_CONTRAST,
247 ctrl->val, state->channel);
248
249 case V4L2_CID_SATURATION:
250 return write_reg(client, TW2804_REG_SATURATION,
251 ctrl->val, state->channel);
252
253 case V4L2_CID_HUE:
254 return write_reg(client, TW2804_REG_HUE,
255 ctrl->val, state->channel);
256
257 default:
258 break;
259 }
260 return -EINVAL;
261}
262
263static int tw2804_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
264{
265 struct tw2804 *dec = to_state(sd);
266 struct i2c_client *client = v4l2_get_subdevdata(sd);
267 bool is_60hz = norm & V4L2_STD_525_60;
268 u8 regs[] = {
269 0x01, is_60hz ? 0xc4 : 0x84,
270 0x09, is_60hz ? 0x07 : 0x04,
271 0x0a, is_60hz ? 0xf0 : 0x20,
272 0x0b, is_60hz ? 0x07 : 0x04,
273 0x0c, is_60hz ? 0xf0 : 0x20,
274 0x0d, is_60hz ? 0x40 : 0x4a,
275 0x16, is_60hz ? 0x00 : 0x40,
276 0x17, is_60hz ? 0x00 : 0x40,
277 0x20, is_60hz ? 0x07 : 0x0f,
278 0x21, is_60hz ? 0x07 : 0x0f,
279 0xff, 0xff,
280 };
281
282 write_regs(client, regs, dec->channel);
283 dec->norm = norm;
284 return 0;
285}
286
287static int tw2804_s_video_routing(struct v4l2_subdev *sd, u32 input, u32 output,
288 u32 config)
289{
290 struct tw2804 *dec = to_state(sd);
291 struct i2c_client *client = v4l2_get_subdevdata(sd);
292 int reg;
293
294 if (config && config - 1 != dec->channel) {
295 if (config > 4) {
296 dev_err(&client->dev,
297 "channel %d is not between 1 and 4!\n", config);
298 return -EINVAL;
299 }
300 dec->channel = config - 1;
301 dev_dbg(&client->dev, "initializing TW2804 channel %d\n",
302 dec->channel);
303 if (dec->channel == 0 &&
304 write_regs(client, global_registers, 0) < 0) {
305 dev_err(&client->dev,
306 "error initializing TW2804 global registers\n");
307 return -EIO;
308 }
309 if (write_regs(client, channel_registers, dec->channel) < 0) {
310 dev_err(&client->dev,
311 "error initializing TW2804 channel %d\n",
312 dec->channel);
313 return -EIO;
314 }
315 }
316
317 if (input > 1)
318 return -EINVAL;
319
320 if (input == dec->input)
321 return 0;
322
323 reg = read_reg(client, 0x22, dec->channel);
324
325 if (reg >= 0) {
326 if (input == 0)
327 reg &= ~(1 << 2);
328 else
329 reg |= 1 << 2;
330 reg = write_reg(client, 0x22, reg, dec->channel);
331 }
332
333 if (reg >= 0)
334 dec->input = input;
335 else
336 return reg;
337 return 0;
338}
339
340static const struct v4l2_ctrl_ops tw2804_ctrl_ops = {
341 .g_volatile_ctrl = tw2804_g_volatile_ctrl,
342 .s_ctrl = tw2804_s_ctrl,
343};
344
345static const struct v4l2_subdev_video_ops tw2804_video_ops = {
346 .s_routing = tw2804_s_video_routing,
347};
348
349static const struct v4l2_subdev_core_ops tw2804_core_ops = {
350 .log_status = tw2804_log_status,
351 .s_std = tw2804_s_std,
352};
353
354static const struct v4l2_subdev_ops tw2804_ops = {
355 .core = &tw2804_core_ops,
356 .video = &tw2804_video_ops,
357};
358
359static int tw2804_probe(struct i2c_client *client,
360 const struct i2c_device_id *id)
361{
362 struct i2c_adapter *adapter = client->adapter;
363 struct tw2804 *state;
364 struct v4l2_subdev *sd;
365 struct v4l2_ctrl *ctrl;
366 int err;
367
368 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
369 return -ENODEV;
370
371 state = kzalloc(sizeof(struct tw2804), GFP_KERNEL);
372
373 if (state == NULL)
374 return -ENOMEM;
375 sd = &state->sd;
376 v4l2_i2c_subdev_init(sd, client, &tw2804_ops);
377 state->channel = -1;
378 state->norm = V4L2_STD_NTSC;
379
380 v4l2_ctrl_handler_init(&state->hdl, 10);
381 v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
382 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
383 v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
384 V4L2_CID_CONTRAST, 0, 255, 1, 128);
385 v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
386 V4L2_CID_SATURATION, 0, 255, 1, 128);
387 v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
388 V4L2_CID_HUE, 0, 255, 1, 128);
389 v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
390 V4L2_CID_COLOR_KILLER, 0, 1, 1, 0);
391 v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
392 V4L2_CID_AUTOGAIN, 0, 1, 1, 0);
393 ctrl = v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
394 V4L2_CID_GAIN, 0, 255, 1, 128);
395 if (ctrl)
396 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
397 ctrl = v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
398 V4L2_CID_CHROMA_GAIN, 0, 255, 1, 128);
399 if (ctrl)
400 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
401 ctrl = v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
402 V4L2_CID_BLUE_BALANCE, 0, 255, 1, 122);
403 if (ctrl)
404 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
405 ctrl = v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
406 V4L2_CID_RED_BALANCE, 0, 255, 1, 122);
407 if (ctrl)
408 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
409 sd->ctrl_handler = &state->hdl;
410 err = state->hdl.error;
411 if (err) {
412 v4l2_ctrl_handler_free(&state->hdl);
413 kfree(state);
414 return err;
415 }
416
417 v4l_info(client, "chip found @ 0x%02x (%s)\n",
418 client->addr << 1, client->adapter->name);
419
420 return 0;
421}
422
423static int tw2804_remove(struct i2c_client *client)
424{
425 struct v4l2_subdev *sd = i2c_get_clientdata(client);
426 struct tw2804 *state = to_state(sd);
427
428 v4l2_device_unregister_subdev(sd);
429 v4l2_ctrl_handler_free(&state->hdl);
430 kfree(state);
431 return 0;
432}
433
434static const struct i2c_device_id tw2804_id[] = {
435 { "tw2804", 0 },
436 { }
437};
438MODULE_DEVICE_TABLE(i2c, tw2804_id);
439
440static struct i2c_driver tw2804_driver = {
441 .driver = {
442 .name = "tw2804",
443 },
444 .probe = tw2804_probe,
445 .remove = tw2804_remove,
446 .id_table = tw2804_id,
447};
448
449module_i2c_driver(tw2804_driver);
450
451MODULE_LICENSE("GPL v2");
452MODULE_DESCRIPTION("TW2804/TW2802 V4L2 i2c driver");
453MODULE_AUTHOR("Micronas USA Inc");
diff --git a/drivers/media/i2c/tw9903.c b/drivers/media/i2c/tw9903.c
new file mode 100644
index 000000000000..87880b19d8c3
--- /dev/null
+++ b/drivers/media/i2c/tw9903.c
@@ -0,0 +1,279 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <linux/ioctl.h>
23#include <media/v4l2-device.h>
24#include <media/v4l2-ctrls.h>
25#include <linux/slab.h>
26
27MODULE_DESCRIPTION("TW9903 I2C subdev driver");
28MODULE_LICENSE("GPL v2");
29
30/*
31 * This driver is based on the wis-tw9903.c source that was in
32 * drivers/staging/media/go7007. That source had commented out code for
33 * saturation and scaling (neither seemed to work). If anyone ever gets
34 * hardware to test this driver, then that code might be useful to look at.
35 * You need to get the kernel sources of, say, kernel 3.8 where that
36 * wis-tw9903 driver is still present.
37 */
38
39struct tw9903 {
40 struct v4l2_subdev sd;
41 struct v4l2_ctrl_handler hdl;
42 v4l2_std_id norm;
43};
44
45static inline struct tw9903 *to_state(struct v4l2_subdev *sd)
46{
47 return container_of(sd, struct tw9903, sd);
48}
49
50static const u8 initial_registers[] = {
51 0x02, 0x44, /* input 1, composite */
52 0x03, 0x92, /* correct digital format */
53 0x04, 0x00,
54 0x05, 0x80, /* or 0x00 for PAL */
55 0x06, 0x40, /* second internal current reference */
56 0x07, 0x02, /* window */
57 0x08, 0x14, /* window */
58 0x09, 0xf0, /* window */
59 0x0a, 0x81, /* window */
60 0x0b, 0xd0, /* window */
61 0x0c, 0x8c,
62 0x0d, 0x00, /* scaling */
63 0x0e, 0x11, /* scaling */
64 0x0f, 0x00, /* scaling */
65 0x10, 0x00, /* brightness */
66 0x11, 0x60, /* contrast */
67 0x12, 0x01, /* sharpness */
68 0x13, 0x7f, /* U gain */
69 0x14, 0x5a, /* V gain */
70 0x15, 0x00, /* hue */
71 0x16, 0xc3, /* sharpness */
72 0x18, 0x00,
73 0x19, 0x58, /* vbi */
74 0x1a, 0x80,
75 0x1c, 0x0f, /* video norm */
76 0x1d, 0x7f, /* video norm */
77 0x20, 0xa0, /* clamping gain (working 0x50) */
78 0x21, 0x22,
79 0x22, 0xf0,
80 0x23, 0xfe,
81 0x24, 0x3c,
82 0x25, 0x38,
83 0x26, 0x44,
84 0x27, 0x20,
85 0x28, 0x00,
86 0x29, 0x15,
87 0x2a, 0xa0,
88 0x2b, 0x44,
89 0x2c, 0x37,
90 0x2d, 0x00,
91 0x2e, 0xa5, /* burst PLL control (working: a9) */
92 0x2f, 0xe0, /* 0xea is blue test frame -- 0xe0 for normal */
93 0x31, 0x00,
94 0x33, 0x22,
95 0x34, 0x11,
96 0x35, 0x35,
97 0x3b, 0x05,
98 0x06, 0xc0, /* reset device */
99 0x00, 0x00, /* Terminator (reg 0x00 is read-only) */
100};
101
102static int write_reg(struct v4l2_subdev *sd, u8 reg, u8 value)
103{
104 struct i2c_client *client = v4l2_get_subdevdata(sd);
105
106 return i2c_smbus_write_byte_data(client, reg, value);
107}
108
109static int write_regs(struct v4l2_subdev *sd, const u8 *regs)
110{
111 int i;
112
113 for (i = 0; regs[i] != 0x00; i += 2)
114 if (write_reg(sd, regs[i], regs[i + 1]) < 0)
115 return -1;
116 return 0;
117}
118
119static int tw9903_s_video_routing(struct v4l2_subdev *sd, u32 input,
120 u32 output, u32 config)
121{
122 write_reg(sd, 0x02, 0x40 | (input << 1));
123 return 0;
124}
125
126static int tw9903_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
127{
128 struct tw9903 *dec = to_state(sd);
129 bool is_60hz = norm & V4L2_STD_525_60;
130 static const u8 config_60hz[] = {
131 0x05, 0x80,
132 0x07, 0x02,
133 0x08, 0x14,
134 0x09, 0xf0,
135 0, 0,
136 };
137 static const u8 config_50hz[] = {
138 0x05, 0x00,
139 0x07, 0x12,
140 0x08, 0x18,
141 0x09, 0x20,
142 0, 0,
143 };
144
145 write_regs(sd, is_60hz ? config_60hz : config_50hz);
146 dec->norm = norm;
147 return 0;
148}
149
150
151static int tw9903_s_ctrl(struct v4l2_ctrl *ctrl)
152{
153 struct tw9903 *dec = container_of(ctrl->handler, struct tw9903, hdl);
154 struct v4l2_subdev *sd = &dec->sd;
155
156 switch (ctrl->id) {
157 case V4L2_CID_BRIGHTNESS:
158 write_reg(sd, 0x10, ctrl->val);
159 break;
160 case V4L2_CID_CONTRAST:
161 write_reg(sd, 0x11, ctrl->val);
162 break;
163 case V4L2_CID_HUE:
164 write_reg(sd, 0x15, ctrl->val);
165 break;
166 default:
167 return -EINVAL;
168 }
169 return 0;
170}
171
172static int tw9903_log_status(struct v4l2_subdev *sd)
173{
174 struct tw9903 *dec = to_state(sd);
175 bool is_60hz = dec->norm & V4L2_STD_525_60;
176
177 v4l2_info(sd, "Standard: %d Hz\n", is_60hz ? 60 : 50);
178 v4l2_ctrl_subdev_log_status(sd);
179 return 0;
180}
181
182/* --------------------------------------------------------------------------*/
183
184static const struct v4l2_ctrl_ops tw9903_ctrl_ops = {
185 .s_ctrl = tw9903_s_ctrl,
186};
187
188static const struct v4l2_subdev_core_ops tw9903_core_ops = {
189 .log_status = tw9903_log_status,
190 .s_std = tw9903_s_std,
191};
192
193static const struct v4l2_subdev_video_ops tw9903_video_ops = {
194 .s_routing = tw9903_s_video_routing,
195};
196
197static const struct v4l2_subdev_ops tw9903_ops = {
198 .core = &tw9903_core_ops,
199 .video = &tw9903_video_ops,
200};
201
202/* --------------------------------------------------------------------------*/
203
204static int tw9903_probe(struct i2c_client *client,
205 const struct i2c_device_id *id)
206{
207 struct tw9903 *dec;
208 struct v4l2_subdev *sd;
209 struct v4l2_ctrl_handler *hdl;
210
211 /* Check if the adapter supports the needed features */
212 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
213 return -EIO;
214
215 v4l_info(client, "chip found @ 0x%02x (%s)\n",
216 client->addr << 1, client->adapter->name);
217
218 dec = kzalloc(sizeof(struct tw9903), GFP_KERNEL);
219 if (dec == NULL)
220 return -ENOMEM;
221 sd = &dec->sd;
222 v4l2_i2c_subdev_init(sd, client, &tw9903_ops);
223 hdl = &dec->hdl;
224 v4l2_ctrl_handler_init(hdl, 4);
225 v4l2_ctrl_new_std(hdl, &tw9903_ctrl_ops,
226 V4L2_CID_BRIGHTNESS, -128, 127, 1, 0);
227 v4l2_ctrl_new_std(hdl, &tw9903_ctrl_ops,
228 V4L2_CID_CONTRAST, 0, 255, 1, 0x60);
229 v4l2_ctrl_new_std(hdl, &tw9903_ctrl_ops,
230 V4L2_CID_HUE, -128, 127, 1, 0);
231 sd->ctrl_handler = hdl;
232 if (hdl->error) {
233 int err = hdl->error;
234
235 v4l2_ctrl_handler_free(hdl);
236 kfree(dec);
237 return err;
238 }
239
240 /* Initialize tw9903 */
241 dec->norm = V4L2_STD_NTSC;
242
243 if (write_regs(sd, initial_registers) < 0) {
244 v4l2_err(client, "error initializing TW9903\n");
245 kfree(dec);
246 return -EINVAL;
247 }
248
249 return 0;
250}
251
252static int tw9903_remove(struct i2c_client *client)
253{
254 struct v4l2_subdev *sd = i2c_get_clientdata(client);
255
256 v4l2_device_unregister_subdev(sd);
257 v4l2_ctrl_handler_free(&to_state(sd)->hdl);
258 kfree(to_state(sd));
259 return 0;
260}
261
262/* ----------------------------------------------------------------------- */
263
264static const struct i2c_device_id tw9903_id[] = {
265 { "tw9903", 0 },
266 { }
267};
268MODULE_DEVICE_TABLE(i2c, tw9903_id);
269
270static struct i2c_driver tw9903_driver = {
271 .driver = {
272 .owner = THIS_MODULE,
273 .name = "tw9903",
274 },
275 .probe = tw9903_probe,
276 .remove = tw9903_remove,
277 .id_table = tw9903_id,
278};
279module_i2c_driver(tw9903_driver);
diff --git a/drivers/media/i2c/tw9906.c b/drivers/media/i2c/tw9906.c
new file mode 100644
index 000000000000..accd79e5a7fd
--- /dev/null
+++ b/drivers/media/i2c/tw9906.c
@@ -0,0 +1,247 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <linux/ioctl.h>
23#include <linux/slab.h>
24#include <media/v4l2-device.h>
25#include <media/v4l2-ctrls.h>
26
27MODULE_DESCRIPTION("TW9906 I2C subdev driver");
28MODULE_LICENSE("GPL v2");
29
30struct tw9906 {
31 struct v4l2_subdev sd;
32 struct v4l2_ctrl_handler hdl;
33 v4l2_std_id norm;
34};
35
36static inline struct tw9906 *to_state(struct v4l2_subdev *sd)
37{
38 return container_of(sd, struct tw9906, sd);
39}
40
41static const u8 initial_registers[] = {
42 0x02, 0x40, /* input 0, composite */
43 0x03, 0xa2, /* correct digital format */
44 0x05, 0x81, /* or 0x01 for PAL */
45 0x07, 0x02, /* window */
46 0x08, 0x14, /* window */
47 0x09, 0xf0, /* window */
48 0x0a, 0x10, /* window */
49 0x0b, 0xd0, /* window */
50 0x0d, 0x00, /* scaling */
51 0x0e, 0x11, /* scaling */
52 0x0f, 0x00, /* scaling */
53 0x10, 0x00, /* brightness */
54 0x11, 0x60, /* contrast */
55 0x12, 0x11, /* sharpness */
56 0x13, 0x7e, /* U gain */
57 0x14, 0x7e, /* V gain */
58 0x15, 0x00, /* hue */
59 0x19, 0x57, /* vbi */
60 0x1a, 0x0f,
61 0x1b, 0x40,
62 0x29, 0x03,
63 0x55, 0x00,
64 0x6b, 0x26,
65 0x6c, 0x36,
66 0x6d, 0xf0,
67 0x6e, 0x41,
68 0x6f, 0x13,
69 0xad, 0x70,
70 0x00, 0x00, /* Terminator (reg 0x00 is read-only) */
71};
72
73static int write_reg(struct v4l2_subdev *sd, u8 reg, u8 value)
74{
75 struct i2c_client *client = v4l2_get_subdevdata(sd);
76
77 return i2c_smbus_write_byte_data(client, reg, value);
78}
79
80static int write_regs(struct v4l2_subdev *sd, const u8 *regs)
81{
82 int i;
83
84 for (i = 0; regs[i] != 0x00; i += 2)
85 if (write_reg(sd, regs[i], regs[i + 1]) < 0)
86 return -1;
87 return 0;
88}
89
90static int tw9906_s_video_routing(struct v4l2_subdev *sd, u32 input,
91 u32 output, u32 config)
92{
93 write_reg(sd, 0x02, 0x40 | (input << 1));
94 return 0;
95}
96
97static int tw9906_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
98{
99 struct tw9906 *dec = to_state(sd);
100 bool is_60hz = norm & V4L2_STD_525_60;
101 static const u8 config_60hz[] = {
102 0x05, 0x81,
103 0x07, 0x02,
104 0x08, 0x14,
105 0x09, 0xf0,
106 0, 0,
107 };
108 static const u8 config_50hz[] = {
109 0x05, 0x01,
110 0x07, 0x12,
111 0x08, 0x18,
112 0x09, 0x20,
113 0, 0,
114 };
115
116 write_regs(sd, is_60hz ? config_60hz : config_50hz);
117 dec->norm = norm;
118 return 0;
119}
120
121static int tw9906_s_ctrl(struct v4l2_ctrl *ctrl)
122{
123 struct tw9906 *dec = container_of(ctrl->handler, struct tw9906, hdl);
124 struct v4l2_subdev *sd = &dec->sd;
125
126 switch (ctrl->id) {
127 case V4L2_CID_BRIGHTNESS:
128 write_reg(sd, 0x10, ctrl->val);
129 break;
130 case V4L2_CID_CONTRAST:
131 write_reg(sd, 0x11, ctrl->val);
132 break;
133 case V4L2_CID_HUE:
134 write_reg(sd, 0x15, ctrl->val);
135 break;
136 default:
137 return -EINVAL;
138 }
139 return 0;
140}
141
142static int tw9906_log_status(struct v4l2_subdev *sd)
143{
144 struct tw9906 *dec = to_state(sd);
145 bool is_60hz = dec->norm & V4L2_STD_525_60;
146
147 v4l2_info(sd, "Standard: %d Hz\n", is_60hz ? 60 : 50);
148 v4l2_ctrl_subdev_log_status(sd);
149 return 0;
150}
151
152/* --------------------------------------------------------------------------*/
153
154static const struct v4l2_ctrl_ops tw9906_ctrl_ops = {
155 .s_ctrl = tw9906_s_ctrl,
156};
157
158static const struct v4l2_subdev_core_ops tw9906_core_ops = {
159 .log_status = tw9906_log_status,
160 .s_std = tw9906_s_std,
161};
162
163static const struct v4l2_subdev_video_ops tw9906_video_ops = {
164 .s_routing = tw9906_s_video_routing,
165};
166
167static const struct v4l2_subdev_ops tw9906_ops = {
168 .core = &tw9906_core_ops,
169 .video = &tw9906_video_ops,
170};
171
172static int tw9906_probe(struct i2c_client *client,
173 const struct i2c_device_id *id)
174{
175 struct tw9906 *dec;
176 struct v4l2_subdev *sd;
177 struct v4l2_ctrl_handler *hdl;
178
179 /* Check if the adapter supports the needed features */
180 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
181 return -EIO;
182
183 v4l_info(client, "chip found @ 0x%02x (%s)\n",
184 client->addr << 1, client->adapter->name);
185
186 dec = kzalloc(sizeof(struct tw9906), GFP_KERNEL);
187 if (dec == NULL)
188 return -ENOMEM;
189 sd = &dec->sd;
190 v4l2_i2c_subdev_init(sd, client, &tw9906_ops);
191 hdl = &dec->hdl;
192 v4l2_ctrl_handler_init(hdl, 4);
193 v4l2_ctrl_new_std(hdl, &tw9906_ctrl_ops,
194 V4L2_CID_BRIGHTNESS, -128, 127, 1, 0);
195 v4l2_ctrl_new_std(hdl, &tw9906_ctrl_ops,
196 V4L2_CID_CONTRAST, 0, 255, 1, 0x60);
197 v4l2_ctrl_new_std(hdl, &tw9906_ctrl_ops,
198 V4L2_CID_HUE, -128, 127, 1, 0);
199 sd->ctrl_handler = hdl;
200 if (hdl->error) {
201 int err = hdl->error;
202
203 v4l2_ctrl_handler_free(hdl);
204 kfree(dec);
205 return err;
206 }
207
208 /* Initialize tw9906 */
209 dec->norm = V4L2_STD_NTSC;
210
211 if (write_regs(sd, initial_registers) < 0) {
212 v4l2_err(client, "error initializing TW9906\n");
213 kfree(dec);
214 return -EINVAL;
215 }
216
217 return 0;
218}
219
220static int tw9906_remove(struct i2c_client *client)
221{
222 struct v4l2_subdev *sd = i2c_get_clientdata(client);
223
224 v4l2_device_unregister_subdev(sd);
225 v4l2_ctrl_handler_free(&to_state(sd)->hdl);
226 kfree(to_state(sd));
227 return 0;
228}
229
230/* ----------------------------------------------------------------------- */
231
232static const struct i2c_device_id tw9906_id[] = {
233 { "tw9906", 0 },
234 { }
235};
236MODULE_DEVICE_TABLE(i2c, tw9906_id);
237
238static struct i2c_driver tw9906_driver = {
239 .driver = {
240 .owner = THIS_MODULE,
241 .name = "tw9906",
242 },
243 .probe = tw9906_probe,
244 .remove = tw9906_remove,
245 .id_table = tw9906_id,
246};
247module_i2c_driver(tw9906_driver);
diff --git a/drivers/media/i2c/uda1342.c b/drivers/media/i2c/uda1342.c
new file mode 100644
index 000000000000..3af408556d27
--- /dev/null
+++ b/drivers/media/i2c/uda1342.c
@@ -0,0 +1,113 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <media/v4l2-device.h>
23#include <media/uda1342.h>
24#include <linux/slab.h>
25
26static int write_reg(struct i2c_client *client, int reg, int value)
27{
28 /* UDA1342 wants MSB first, but SMBus sends LSB first */
29 i2c_smbus_write_word_data(client, reg, swab16(value));
30 return 0;
31}
32
33static int uda1342_s_routing(struct v4l2_subdev *sd,
34 u32 input, u32 output, u32 config)
35{
36 struct i2c_client *client = v4l2_get_subdevdata(sd);
37
38 switch (input) {
39 case UDA1342_IN1:
40 write_reg(client, 0x00, 0x1241); /* select input 1 */
41 break;
42 case UDA1342_IN2:
43 write_reg(client, 0x00, 0x1441); /* select input 2 */
44 break;
45 default:
46 v4l2_err(sd, "input %d not supported\n", input);
47 break;
48 }
49 return 0;
50}
51
52static const struct v4l2_subdev_audio_ops uda1342_audio_ops = {
53 .s_routing = uda1342_s_routing,
54};
55
56static const struct v4l2_subdev_ops uda1342_ops = {
57 .audio = &uda1342_audio_ops,
58};
59
60static int uda1342_probe(struct i2c_client *client,
61 const struct i2c_device_id *id)
62{
63 struct i2c_adapter *adapter = client->adapter;
64 struct v4l2_subdev *sd;
65
66 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
67 return -ENODEV;
68
69 dev_dbg(&client->dev, "initializing UDA1342 at address %d on %s\n",
70 client->addr, adapter->name);
71
72 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
73 if (sd == NULL)
74 return -ENOMEM;
75
76 v4l2_i2c_subdev_init(sd, client, &uda1342_ops);
77
78 write_reg(client, 0x00, 0x8000); /* reset registers */
79 write_reg(client, 0x00, 0x1241); /* select input 1 */
80
81 v4l_info(client, "chip found @ 0x%02x (%s)\n",
82 client->addr << 1, client->adapter->name);
83
84 return 0;
85}
86
87static int uda1342_remove(struct i2c_client *client)
88{
89 struct v4l2_subdev *sd = i2c_get_clientdata(client);
90
91 v4l2_device_unregister_subdev(sd);
92 kfree(sd);
93 return 0;
94}
95
96static const struct i2c_device_id uda1342_id[] = {
97 { "uda1342", 0 },
98 { }
99};
100MODULE_DEVICE_TABLE(i2c, uda1342_id);
101
102static struct i2c_driver uda1342_driver = {
103 .driver = {
104 .name = "uda1342",
105 },
106 .probe = uda1342_probe,
107 .remove = uda1342_remove,
108 .id_table = uda1342_id,
109};
110
111module_i2c_driver(uda1342_driver);
112
113MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/i2c/upd64031a.c b/drivers/media/i2c/upd64031a.c
index 1e7446542091..f0a09214c519 100644
--- a/drivers/media/i2c/upd64031a.c
+++ b/drivers/media/i2c/upd64031a.c
@@ -111,7 +111,7 @@ static void upd64031a_write(struct v4l2_subdev *sd, u8 reg, u8 val)
111/* ------------------------------------------------------------------------ */ 111/* ------------------------------------------------------------------------ */
112 112
113/* The input changed due to new input or channel changed */ 113/* The input changed due to new input or channel changed */
114static int upd64031a_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) 114static int upd64031a_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *freq)
115{ 115{
116 struct upd64031a_state *state = to_state(sd); 116 struct upd64031a_state *state = to_state(sd);
117 u8 reg = state->regs[R00]; 117 u8 reg = state->regs[R00];
@@ -175,7 +175,7 @@ static int upd64031a_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register
175 return 0; 175 return 0;
176} 176}
177 177
178static int upd64031a_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 178static int upd64031a_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
179{ 179{
180 struct i2c_client *client = v4l2_get_subdevdata(sd); 180 struct i2c_client *client = v4l2_get_subdevdata(sd);
181 181
diff --git a/drivers/media/i2c/upd64083.c b/drivers/media/i2c/upd64083.c
index 75d6acc62018..343e0215f74c 100644
--- a/drivers/media/i2c/upd64083.c
+++ b/drivers/media/i2c/upd64083.c
@@ -133,7 +133,7 @@ static int upd64083_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register
133 return 0; 133 return 0;
134} 134}
135 135
136static int upd64083_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 136static int upd64083_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
137{ 137{
138 struct i2c_client *client = v4l2_get_subdevdata(sd); 138 struct i2c_client *client = v4l2_get_subdevdata(sd);
139 139
diff --git a/drivers/media/i2c/vp27smpx.c b/drivers/media/i2c/vp27smpx.c
index 7cfbc9d94a48..e71f139695af 100644
--- a/drivers/media/i2c/vp27smpx.c
+++ b/drivers/media/i2c/vp27smpx.c
@@ -90,7 +90,7 @@ static int vp27smpx_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
90 return 0; 90 return 0;
91} 91}
92 92
93static int vp27smpx_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 93static int vp27smpx_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
94{ 94{
95 struct vp27smpx_state *state = to_state(sd); 95 struct vp27smpx_state *state = to_state(sd);
96 96
diff --git a/drivers/media/i2c/vs6624.c b/drivers/media/i2c/vs6624.c
index 9ac1b8c3a837..f366fad6269e 100644
--- a/drivers/media/i2c/vs6624.c
+++ b/drivers/media/i2c/vs6624.c
@@ -748,7 +748,7 @@ static int vs6624_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *r
748 return 0; 748 return 0;
749} 749}
750 750
751static int vs6624_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 751static int vs6624_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
752{ 752{
753 struct i2c_client *client = v4l2_get_subdevdata(sd); 753 struct i2c_client *client = v4l2_get_subdevdata(sd);
754 754
diff --git a/drivers/media/i2c/wm8775.c b/drivers/media/i2c/wm8775.c
index bee77ea9f49e..27c27b4ae238 100644
--- a/drivers/media/i2c/wm8775.c
+++ b/drivers/media/i2c/wm8775.c
@@ -174,7 +174,7 @@ static int wm8775_log_status(struct v4l2_subdev *sd)
174 return 0; 174 return 0;
175} 175}
176 176
177static int wm8775_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) 177static int wm8775_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *freq)
178{ 178{
179 wm8775_set_audio(sd, 0); 179 wm8775_set_audio(sd, 0);
180 return 0; 180 return 0;