aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/mt9m001.c157
-rw-r--r--drivers/media/video/mt9m111.c309
-rw-r--r--drivers/media/video/mt9t031.c173
-rw-r--r--drivers/media/video/mt9v022.c167
-rw-r--r--drivers/media/video/mx1_camera.c31
-rw-r--r--drivers/media/video/mx3_camera.c54
-rw-r--r--drivers/media/video/ov772x.c169
-rw-r--r--drivers/media/video/pxa_camera.c107
-rw-r--r--drivers/media/video/sh_mobile_ceu_camera.c45
-rw-r--r--drivers/media/video/soc_camera.c250
-rw-r--r--drivers/media/video/soc_camera_platform.c115
-rw-r--r--drivers/media/video/tw9910.c151
12 files changed, 783 insertions, 945 deletions
diff --git a/drivers/media/video/mt9m001.c b/drivers/media/video/mt9m001.c
index 1e4f269fc08b..2a73dac11d37 100644
--- a/drivers/media/video/mt9m001.c
+++ b/drivers/media/video/mt9m001.c
@@ -13,13 +13,13 @@
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/log2.h> 14#include <linux/log2.h>
15 15
16#include <media/v4l2-common.h> 16#include <media/v4l2-subdev.h>
17#include <media/v4l2-chip-ident.h> 17#include <media/v4l2-chip-ident.h>
18#include <media/soc_camera.h> 18#include <media/soc_camera.h>
19 19
20/* mt9m001 i2c address 0x5d 20/* mt9m001 i2c address 0x5d
21 * The platform has to define i2c_board_info 21 * The platform has to define ctruct i2c_board_info objects and link to them
22 * and call i2c_register_board_info() */ 22 * from struct soc_camera_link */
23 23
24/* mt9m001 selected register addresses */ 24/* mt9m001 selected register addresses */
25#define MT9M001_CHIP_VERSION 0x00 25#define MT9M001_CHIP_VERSION 0x00
@@ -69,10 +69,16 @@ static const struct soc_camera_data_format mt9m001_monochrome_formats[] = {
69}; 69};
70 70
71struct mt9m001 { 71struct mt9m001 {
72 struct v4l2_subdev subdev;
72 int model; /* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */ 73 int model; /* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */
73 unsigned char autoexposure; 74 unsigned char autoexposure;
74}; 75};
75 76
77static struct mt9m001 *to_mt9m001(const struct i2c_client *client)
78{
79 return container_of(i2c_get_clientdata(client), struct mt9m001, subdev);
80}
81
76static int reg_read(struct i2c_client *client, const u8 reg) 82static int reg_read(struct i2c_client *client, const u8 reg)
77{ 83{
78 s32 data = i2c_smbus_read_word_data(client, reg); 84 s32 data = i2c_smbus_read_word_data(client, reg);
@@ -110,32 +116,18 @@ static int reg_clear(struct i2c_client *client, const u8 reg,
110static int mt9m001_init(struct soc_camera_device *icd) 116static int mt9m001_init(struct soc_camera_device *icd)
111{ 117{
112 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 118 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
113 struct soc_camera_link *icl = to_soc_camera_link(icd);
114 int ret; 119 int ret;
115 120
116 dev_dbg(&icd->dev, "%s\n", __func__); 121 dev_dbg(&icd->dev, "%s\n", __func__);
117 122
118 if (icl->power) { 123 /*
119 ret = icl->power(&client->dev, 1); 124 * We don't know, whether platform provides reset,
120 if (ret < 0) { 125 * issue a soft reset too
121 dev_err(icd->vdev->parent, 126 */
122 "Platform failed to power-on the camera.\n"); 127 ret = reg_write(client, MT9M001_RESET, 1);
123 return ret; 128 if (!ret)
124 } 129 ret = reg_write(client, MT9M001_RESET, 0);
125 }
126
127 /* The camera could have been already on, we reset it additionally */
128 if (icl->reset)
129 ret = icl->reset(&client->dev);
130 else
131 ret = -ENODEV;
132 130
133 if (ret < 0) {
134 /* Either no platform reset, or platform reset failed */
135 ret = reg_write(client, MT9M001_RESET, 1);
136 if (!ret)
137 ret = reg_write(client, MT9M001_RESET, 0);
138 }
139 /* Disable chip, synchronous option update */ 131 /* Disable chip, synchronous option update */
140 if (!ret) 132 if (!ret)
141 ret = reg_write(client, MT9M001_OUTPUT_CONTROL, 0); 133 ret = reg_write(client, MT9M001_OUTPUT_CONTROL, 0);
@@ -146,33 +138,19 @@ static int mt9m001_init(struct soc_camera_device *icd)
146static int mt9m001_release(struct soc_camera_device *icd) 138static int mt9m001_release(struct soc_camera_device *icd)
147{ 139{
148 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 140 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
149 struct soc_camera_link *icl = to_soc_camera_link(icd);
150 141
151 /* Disable the chip */ 142 /* Disable the chip */
152 reg_write(client, MT9M001_OUTPUT_CONTROL, 0); 143 reg_write(client, MT9M001_OUTPUT_CONTROL, 0);
153 144
154 if (icl->power)
155 icl->power(&client->dev, 0);
156
157 return 0; 145 return 0;
158} 146}
159 147
160static int mt9m001_start_capture(struct soc_camera_device *icd) 148static int mt9m001_s_stream(struct v4l2_subdev *sd, int enable)
161{ 149{
162 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 150 struct i2c_client *client = sd->priv;
163 151
164 /* Switch to master "normal" mode */ 152 /* Switch to master "normal" mode or stop sensor readout */
165 if (reg_write(client, MT9M001_OUTPUT_CONTROL, 2) < 0) 153 if (reg_write(client, MT9M001_OUTPUT_CONTROL, enable ? 2 : 0) < 0)
166 return -EIO;
167 return 0;
168}
169
170static int mt9m001_stop_capture(struct soc_camera_device *icd)
171{
172 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
173
174 /* Stop sensor readout */
175 if (reg_write(client, MT9M001_OUTPUT_CONTROL, 0) < 0)
176 return -EIO; 154 return -EIO;
177 return 0; 155 return 0;
178} 156}
@@ -220,7 +198,7 @@ static int mt9m001_set_crop(struct soc_camera_device *icd,
220 struct v4l2_rect *rect) 198 struct v4l2_rect *rect)
221{ 199{
222 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 200 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
223 struct mt9m001 *mt9m001 = i2c_get_clientdata(client); 201 struct mt9m001 *mt9m001 = to_mt9m001(client);
224 int ret; 202 int ret;
225 const u16 hblank = 9, vblank = 25; 203 const u16 hblank = 9, vblank = 25;
226 204
@@ -257,9 +235,10 @@ static int mt9m001_set_crop(struct soc_camera_device *icd,
257 return ret; 235 return ret;
258} 236}
259 237
260static int mt9m001_set_fmt(struct soc_camera_device *icd, 238static int mt9m001_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
261 struct v4l2_format *f)
262{ 239{
240 struct i2c_client *client = sd->priv;
241 struct soc_camera_device *icd = client->dev.platform_data;
263 struct v4l2_rect rect = { 242 struct v4l2_rect rect = {
264 .left = icd->x_current, 243 .left = icd->x_current,
265 .top = icd->y_current, 244 .top = icd->y_current,
@@ -271,9 +250,10 @@ static int mt9m001_set_fmt(struct soc_camera_device *icd,
271 return mt9m001_set_crop(icd, &rect); 250 return mt9m001_set_crop(icd, &rect);
272} 251}
273 252
274static int mt9m001_try_fmt(struct soc_camera_device *icd, 253static int mt9m001_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
275 struct v4l2_format *f)
276{ 254{
255 struct i2c_client *client = sd->priv;
256 struct soc_camera_device *icd = client->dev.platform_data;
277 struct v4l2_pix_format *pix = &f->fmt.pix; 257 struct v4l2_pix_format *pix = &f->fmt.pix;
278 258
279 v4l_bound_align_image(&pix->width, 48, 1280, 1, 259 v4l_bound_align_image(&pix->width, 48, 1280, 1,
@@ -283,11 +263,11 @@ static int mt9m001_try_fmt(struct soc_camera_device *icd,
283 return 0; 263 return 0;
284} 264}
285 265
286static int mt9m001_get_chip_id(struct soc_camera_device *icd, 266static int mt9m001_g_chip_ident(struct v4l2_subdev *sd,
287 struct v4l2_dbg_chip_ident *id) 267 struct v4l2_dbg_chip_ident *id)
288{ 268{
289 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 269 struct i2c_client *client = sd->priv;
290 struct mt9m001 *mt9m001 = i2c_get_clientdata(client); 270 struct mt9m001 *mt9m001 = to_mt9m001(client);
291 271
292 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR) 272 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
293 return -EINVAL; 273 return -EINVAL;
@@ -302,10 +282,10 @@ static int mt9m001_get_chip_id(struct soc_camera_device *icd,
302} 282}
303 283
304#ifdef CONFIG_VIDEO_ADV_DEBUG 284#ifdef CONFIG_VIDEO_ADV_DEBUG
305static int mt9m001_get_register(struct soc_camera_device *icd, 285static int mt9m001_g_register(struct v4l2_subdev *sd,
306 struct v4l2_dbg_register *reg) 286 struct v4l2_dbg_register *reg)
307{ 287{
308 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 288 struct i2c_client *client = sd->priv;
309 289
310 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 290 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
311 return -EINVAL; 291 return -EINVAL;
@@ -322,10 +302,10 @@ static int mt9m001_get_register(struct soc_camera_device *icd,
322 return 0; 302 return 0;
323} 303}
324 304
325static int mt9m001_set_register(struct soc_camera_device *icd, 305static int mt9m001_s_register(struct v4l2_subdev *sd,
326 struct v4l2_dbg_register *reg) 306 struct v4l2_dbg_register *reg)
327{ 307{
328 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 308 struct i2c_client *client = sd->priv;
329 309
330 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 310 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
331 return -EINVAL; 311 return -EINVAL;
@@ -378,35 +358,20 @@ static const struct v4l2_queryctrl mt9m001_controls[] = {
378 } 358 }
379}; 359};
380 360
381static int mt9m001_get_control(struct soc_camera_device *, struct v4l2_control *);
382static int mt9m001_set_control(struct soc_camera_device *, struct v4l2_control *);
383
384static struct soc_camera_ops mt9m001_ops = { 361static struct soc_camera_ops mt9m001_ops = {
385 .owner = THIS_MODULE,
386 .init = mt9m001_init, 362 .init = mt9m001_init,
387 .release = mt9m001_release, 363 .release = mt9m001_release,
388 .start_capture = mt9m001_start_capture,
389 .stop_capture = mt9m001_stop_capture,
390 .set_crop = mt9m001_set_crop, 364 .set_crop = mt9m001_set_crop,
391 .set_fmt = mt9m001_set_fmt,
392 .try_fmt = mt9m001_try_fmt,
393 .set_bus_param = mt9m001_set_bus_param, 365 .set_bus_param = mt9m001_set_bus_param,
394 .query_bus_param = mt9m001_query_bus_param, 366 .query_bus_param = mt9m001_query_bus_param,
395 .controls = mt9m001_controls, 367 .controls = mt9m001_controls,
396 .num_controls = ARRAY_SIZE(mt9m001_controls), 368 .num_controls = ARRAY_SIZE(mt9m001_controls),
397 .get_control = mt9m001_get_control,
398 .set_control = mt9m001_set_control,
399 .get_chip_id = mt9m001_get_chip_id,
400#ifdef CONFIG_VIDEO_ADV_DEBUG
401 .get_register = mt9m001_get_register,
402 .set_register = mt9m001_set_register,
403#endif
404}; 369};
405 370
406static int mt9m001_get_control(struct soc_camera_device *icd, struct v4l2_control *ctrl) 371static int mt9m001_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
407{ 372{
408 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 373 struct i2c_client *client = sd->priv;
409 struct mt9m001 *mt9m001 = i2c_get_clientdata(client); 374 struct mt9m001 *mt9m001 = to_mt9m001(client);
410 int data; 375 int data;
411 376
412 switch (ctrl->id) { 377 switch (ctrl->id) {
@@ -423,10 +388,11 @@ static int mt9m001_get_control(struct soc_camera_device *icd, struct v4l2_contro
423 return 0; 388 return 0;
424} 389}
425 390
426static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_control *ctrl) 391static int mt9m001_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
427{ 392{
428 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 393 struct i2c_client *client = sd->priv;
429 struct mt9m001 *mt9m001 = i2c_get_clientdata(client); 394 struct mt9m001 *mt9m001 = to_mt9m001(client);
395 struct soc_camera_device *icd = client->dev.platform_data;
430 const struct v4l2_queryctrl *qctrl; 396 const struct v4l2_queryctrl *qctrl;
431 int data; 397 int data;
432 398
@@ -521,10 +487,9 @@ static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_contro
521static int mt9m001_video_probe(struct soc_camera_device *icd, 487static int mt9m001_video_probe(struct soc_camera_device *icd,
522 struct i2c_client *client) 488 struct i2c_client *client)
523{ 489{
524 struct mt9m001 *mt9m001 = i2c_get_clientdata(client); 490 struct mt9m001 *mt9m001 = to_mt9m001(client);
525 struct soc_camera_link *icl = to_soc_camera_link(icd); 491 struct soc_camera_link *icl = to_soc_camera_link(icd);
526 s32 data; 492 s32 data;
527 int ret;
528 unsigned long flags; 493 unsigned long flags;
529 494
530 /* We must have a parent by now. And it cannot be a wrong one. 495 /* We must have a parent by now. And it cannot be a wrong one.
@@ -533,11 +498,6 @@ static int mt9m001_video_probe(struct soc_camera_device *icd,
533 to_soc_camera_host(icd->dev.parent)->nr != icd->iface) 498 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
534 return -ENODEV; 499 return -ENODEV;
535 500
536 /* Switch master clock on */
537 ret = soc_camera_video_start(icd, &client->dev);
538 if (ret)
539 return ret;
540
541 /* Enable the chip */ 501 /* Enable the chip */
542 data = reg_write(client, MT9M001_CHIP_ENABLE, 1); 502 data = reg_write(client, MT9M001_CHIP_ENABLE, 1);
543 dev_dbg(&icd->dev, "write: %d\n", data); 503 dev_dbg(&icd->dev, "write: %d\n", data);
@@ -545,8 +505,6 @@ static int mt9m001_video_probe(struct soc_camera_device *icd,
545 /* Read out the chip version register */ 505 /* Read out the chip version register */
546 data = reg_read(client, MT9M001_CHIP_VERSION); 506 data = reg_read(client, MT9M001_CHIP_VERSION);
547 507
548 soc_camera_video_stop(icd);
549
550 /* must be 0x8411 or 0x8421 for colour sensor and 8431 for bw */ 508 /* must be 0x8411 or 0x8421 for colour sensor and 8431 for bw */
551 switch (data) { 509 switch (data) {
552 case 0x8411: 510 case 0x8411:
@@ -601,6 +559,27 @@ static void mt9m001_video_remove(struct soc_camera_device *icd)
601 icl->free_bus(icl); 559 icl->free_bus(icl);
602} 560}
603 561
562static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
563 .g_ctrl = mt9m001_g_ctrl,
564 .s_ctrl = mt9m001_s_ctrl,
565 .g_chip_ident = mt9m001_g_chip_ident,
566#ifdef CONFIG_VIDEO_ADV_DEBUG
567 .g_register = mt9m001_g_register,
568 .s_register = mt9m001_s_register,
569#endif
570};
571
572static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
573 .s_stream = mt9m001_s_stream,
574 .s_fmt = mt9m001_s_fmt,
575 .try_fmt = mt9m001_try_fmt,
576};
577
578static struct v4l2_subdev_ops mt9m001_subdev_ops = {
579 .core = &mt9m001_subdev_core_ops,
580 .video = &mt9m001_subdev_video_ops,
581};
582
604static int mt9m001_probe(struct i2c_client *client, 583static int mt9m001_probe(struct i2c_client *client,
605 const struct i2c_device_id *did) 584 const struct i2c_device_id *did)
606{ 585{
@@ -631,7 +610,7 @@ static int mt9m001_probe(struct i2c_client *client,
631 if (!mt9m001) 610 if (!mt9m001)
632 return -ENOMEM; 611 return -ENOMEM;
633 612
634 i2c_set_clientdata(client, mt9m001); 613 v4l2_i2c_subdev_init(&mt9m001->subdev, client, &mt9m001_subdev_ops);
635 614
636 /* Second stage probe - when a capture adapter is there */ 615 /* Second stage probe - when a capture adapter is there */
637 icd->ops = &mt9m001_ops; 616 icd->ops = &mt9m001_ops;
@@ -660,7 +639,7 @@ static int mt9m001_probe(struct i2c_client *client,
660 639
661static int mt9m001_remove(struct i2c_client *client) 640static int mt9m001_remove(struct i2c_client *client)
662{ 641{
663 struct mt9m001 *mt9m001 = i2c_get_clientdata(client); 642 struct mt9m001 *mt9m001 = to_mt9m001(client);
664 struct soc_camera_device *icd = client->dev.platform_data; 643 struct soc_camera_device *icd = client->dev.platform_data;
665 644
666 icd->ops = NULL; 645 icd->ops = NULL;
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
index 95c2f089605f..29f976afd465 100644
--- a/drivers/media/video/mt9m111.c
+++ b/drivers/media/video/mt9m111.c
@@ -148,6 +148,7 @@ enum mt9m111_context {
148}; 148};
149 149
150struct mt9m111 { 150struct mt9m111 {
151 struct v4l2_subdev subdev;
151 int model; /* V4L2_IDENT_MT9M11x* codes from v4l2-chip-ident.h */ 152 int model; /* V4L2_IDENT_MT9M11x* codes from v4l2-chip-ident.h */
152 enum mt9m111_context context; 153 enum mt9m111_context context;
153 struct v4l2_rect rect; 154 struct v4l2_rect rect;
@@ -164,6 +165,11 @@ struct mt9m111 {
164 unsigned int autowhitebalance:1; 165 unsigned int autowhitebalance:1;
165}; 166};
166 167
168static struct mt9m111 *to_mt9m111(const struct i2c_client *client)
169{
170 return container_of(i2c_get_clientdata(client), struct mt9m111, subdev);
171}
172
167static int reg_page_map_set(struct i2c_client *client, const u16 reg) 173static int reg_page_map_set(struct i2c_client *client, const u16 reg)
168{ 174{
169 int ret; 175 int ret;
@@ -227,10 +233,9 @@ static int mt9m111_reg_clear(struct i2c_client *client, const u16 reg,
227 return mt9m111_reg_write(client, reg, ret & ~data); 233 return mt9m111_reg_write(client, reg, ret & ~data);
228} 234}
229 235
230static int mt9m111_set_context(struct soc_camera_device *icd, 236static int mt9m111_set_context(struct i2c_client *client,
231 enum mt9m111_context ctxt) 237 enum mt9m111_context ctxt)
232{ 238{
233 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
234 int valB = MT9M111_CTXT_CTRL_RESTART | MT9M111_CTXT_CTRL_DEFECTCOR_B 239 int valB = MT9M111_CTXT_CTRL_RESTART | MT9M111_CTXT_CTRL_DEFECTCOR_B
235 | MT9M111_CTXT_CTRL_RESIZE_B | MT9M111_CTXT_CTRL_CTRL2_B 240 | MT9M111_CTXT_CTRL_RESIZE_B | MT9M111_CTXT_CTRL_CTRL2_B
236 | MT9M111_CTXT_CTRL_GAMMA_B | MT9M111_CTXT_CTRL_READ_MODE_B 241 | MT9M111_CTXT_CTRL_GAMMA_B | MT9M111_CTXT_CTRL_READ_MODE_B
@@ -244,11 +249,10 @@ static int mt9m111_set_context(struct soc_camera_device *icd,
244 return reg_write(CONTEXT_CONTROL, valA); 249 return reg_write(CONTEXT_CONTROL, valA);
245} 250}
246 251
247static int mt9m111_setup_rect(struct soc_camera_device *icd, 252static int mt9m111_setup_rect(struct i2c_client *client,
248 struct v4l2_rect *rect) 253 struct v4l2_rect *rect)
249{ 254{
250 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 255 struct mt9m111 *mt9m111 = to_mt9m111(client);
251 struct mt9m111 *mt9m111 = i2c_get_clientdata(client);
252 int ret, is_raw_format; 256 int ret, is_raw_format;
253 int width = rect->width; 257 int width = rect->width;
254 int height = rect->height; 258 int height = rect->height;
@@ -290,9 +294,8 @@ static int mt9m111_setup_rect(struct soc_camera_device *icd,
290 return ret; 294 return ret;
291} 295}
292 296
293static int mt9m111_setup_pixfmt(struct soc_camera_device *icd, u16 outfmt) 297static int mt9m111_setup_pixfmt(struct i2c_client *client, u16 outfmt)
294{ 298{
295 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
296 int ret; 299 int ret;
297 300
298 ret = reg_write(OUTPUT_FORMAT_CTRL2_A, outfmt); 301 ret = reg_write(OUTPUT_FORMAT_CTRL2_A, outfmt);
@@ -301,20 +304,19 @@ static int mt9m111_setup_pixfmt(struct soc_camera_device *icd, u16 outfmt)
301 return ret; 304 return ret;
302} 305}
303 306
304static int mt9m111_setfmt_bayer8(struct soc_camera_device *icd) 307static int mt9m111_setfmt_bayer8(struct i2c_client *client)
305{ 308{
306 return mt9m111_setup_pixfmt(icd, MT9M111_OUTFMT_PROCESSED_BAYER); 309 return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_PROCESSED_BAYER);
307} 310}
308 311
309static int mt9m111_setfmt_bayer10(struct soc_camera_device *icd) 312static int mt9m111_setfmt_bayer10(struct i2c_client *client)
310{ 313{
311 return mt9m111_setup_pixfmt(icd, MT9M111_OUTFMT_BYPASS_IFP); 314 return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_BYPASS_IFP);
312} 315}
313 316
314static int mt9m111_setfmt_rgb565(struct soc_camera_device *icd) 317static int mt9m111_setfmt_rgb565(struct i2c_client *client)
315{ 318{
316 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 319 struct mt9m111 *mt9m111 = to_mt9m111(client);
317 struct mt9m111 *mt9m111 = i2c_get_clientdata(client);
318 int val = 0; 320 int val = 0;
319 321
320 if (mt9m111->swap_rgb_red_blue) 322 if (mt9m111->swap_rgb_red_blue)
@@ -323,13 +325,12 @@ static int mt9m111_setfmt_rgb565(struct soc_camera_device *icd)
323 val |= MT9M111_OUTFMT_SWAP_RGB_EVEN; 325 val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
324 val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565; 326 val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
325 327
326 return mt9m111_setup_pixfmt(icd, val); 328 return mt9m111_setup_pixfmt(client, val);
327} 329}
328 330
329static int mt9m111_setfmt_rgb555(struct soc_camera_device *icd) 331static int mt9m111_setfmt_rgb555(struct i2c_client *client)
330{ 332{
331 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 333 struct mt9m111 *mt9m111 = to_mt9m111(client);
332 struct mt9m111 *mt9m111 = i2c_get_clientdata(client);
333 int val = 0; 334 int val = 0;
334 335
335 if (mt9m111->swap_rgb_red_blue) 336 if (mt9m111->swap_rgb_red_blue)
@@ -338,13 +339,12 @@ static int mt9m111_setfmt_rgb555(struct soc_camera_device *icd)
338 val |= MT9M111_OUTFMT_SWAP_RGB_EVEN; 339 val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
339 val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555; 340 val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555;
340 341
341 return mt9m111_setup_pixfmt(icd, val); 342 return mt9m111_setup_pixfmt(client, val);
342} 343}
343 344
344static int mt9m111_setfmt_yuv(struct soc_camera_device *icd) 345static int mt9m111_setfmt_yuv(struct i2c_client *client)
345{ 346{
346 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 347 struct mt9m111 *mt9m111 = to_mt9m111(client);
347 struct mt9m111 *mt9m111 = i2c_get_clientdata(client);
348 int val = 0; 348 int val = 0;
349 349
350 if (mt9m111->swap_yuv_cb_cr) 350 if (mt9m111->swap_yuv_cb_cr)
@@ -352,52 +352,22 @@ static int mt9m111_setfmt_yuv(struct soc_camera_device *icd)
352 if (mt9m111->swap_yuv_y_chromas) 352 if (mt9m111->swap_yuv_y_chromas)
353 val |= MT9M111_OUTFMT_SWAP_YCbCr_C_Y; 353 val |= MT9M111_OUTFMT_SWAP_YCbCr_C_Y;
354 354
355 return mt9m111_setup_pixfmt(icd, val); 355 return mt9m111_setup_pixfmt(client, val);
356} 356}
357 357
358static int mt9m111_enable(struct soc_camera_device *icd) 358static int mt9m111_enable(struct i2c_client *client)
359{ 359{
360 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 360 struct mt9m111 *mt9m111 = to_mt9m111(client);
361 struct soc_camera_link *icl = to_soc_camera_link(icd);
362 struct mt9m111 *mt9m111 = i2c_get_clientdata(client);
363 int ret; 361 int ret;
364 362
365 if (icl->power) {
366 ret = icl->power(&client->dev, 1);
367 if (ret < 0) {
368 dev_err(icd->vdev->parent,
369 "Platform failed to power-on the camera.\n");
370 return ret;
371 }
372 }
373
374 ret = reg_set(RESET, MT9M111_RESET_CHIP_ENABLE); 363 ret = reg_set(RESET, MT9M111_RESET_CHIP_ENABLE);
375 if (!ret) 364 if (!ret)
376 mt9m111->powered = 1; 365 mt9m111->powered = 1;
377 return ret; 366 return ret;
378} 367}
379 368
380static int mt9m111_disable(struct soc_camera_device *icd) 369static int mt9m111_reset(struct i2c_client *client)
381{
382 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
383 struct soc_camera_link *icl = to_soc_camera_link(icd);
384 struct mt9m111 *mt9m111 = i2c_get_clientdata(client);
385 int ret;
386
387 ret = reg_clear(RESET, MT9M111_RESET_CHIP_ENABLE);
388 if (!ret)
389 mt9m111->powered = 0;
390
391 if (icl->power)
392 icl->power(&client->dev, 0);
393
394 return ret;
395}
396
397static int mt9m111_reset(struct soc_camera_device *icd)
398{ 370{
399 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
400 struct soc_camera_link *icl = to_soc_camera_link(icd);
401 int ret; 371 int ret;
402 372
403 ret = reg_set(RESET, MT9M111_RESET_RESET_MODE); 373 ret = reg_set(RESET, MT9M111_RESET_RESET_MODE);
@@ -407,22 +377,9 @@ static int mt9m111_reset(struct soc_camera_device *icd)
407 ret = reg_clear(RESET, MT9M111_RESET_RESET_MODE 377 ret = reg_clear(RESET, MT9M111_RESET_RESET_MODE
408 | MT9M111_RESET_RESET_SOC); 378 | MT9M111_RESET_RESET_SOC);
409 379
410 if (icl->reset)
411 icl->reset(&client->dev);
412
413 return ret; 380 return ret;
414} 381}
415 382
416static int mt9m111_start_capture(struct soc_camera_device *icd)
417{
418 return 0;
419}
420
421static int mt9m111_stop_capture(struct soc_camera_device *icd)
422{
423 return 0;
424}
425
426static unsigned long mt9m111_query_bus_param(struct soc_camera_device *icd) 383static unsigned long mt9m111_query_bus_param(struct soc_camera_device *icd)
427{ 384{
428 struct soc_camera_link *icl = to_soc_camera_link(icd); 385 struct soc_camera_link *icl = to_soc_camera_link(icd);
@@ -442,60 +399,59 @@ static int mt9m111_set_crop(struct soc_camera_device *icd,
442 struct v4l2_rect *rect) 399 struct v4l2_rect *rect)
443{ 400{
444 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 401 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
445 struct mt9m111 *mt9m111 = i2c_get_clientdata(client); 402 struct mt9m111 *mt9m111 = to_mt9m111(client);
446 int ret; 403 int ret;
447 404
448 dev_dbg(&icd->dev, "%s left=%d, top=%d, width=%d, height=%d\n", 405 dev_dbg(&icd->dev, "%s left=%d, top=%d, width=%d, height=%d\n",
449 __func__, rect->left, rect->top, rect->width, 406 __func__, rect->left, rect->top, rect->width,
450 rect->height); 407 rect->height);
451 408
452 ret = mt9m111_setup_rect(icd, rect); 409 ret = mt9m111_setup_rect(client, rect);
453 if (!ret) 410 if (!ret)
454 mt9m111->rect = *rect; 411 mt9m111->rect = *rect;
455 return ret; 412 return ret;
456} 413}
457 414
458static int mt9m111_set_pixfmt(struct soc_camera_device *icd, u32 pixfmt) 415static int mt9m111_set_pixfmt(struct i2c_client *client, u32 pixfmt)
459{ 416{
460 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 417 struct mt9m111 *mt9m111 = to_mt9m111(client);
461 struct mt9m111 *mt9m111 = i2c_get_clientdata(client);
462 int ret; 418 int ret;
463 419
464 switch (pixfmt) { 420 switch (pixfmt) {
465 case V4L2_PIX_FMT_SBGGR8: 421 case V4L2_PIX_FMT_SBGGR8:
466 ret = mt9m111_setfmt_bayer8(icd); 422 ret = mt9m111_setfmt_bayer8(client);
467 break; 423 break;
468 case V4L2_PIX_FMT_SBGGR16: 424 case V4L2_PIX_FMT_SBGGR16:
469 ret = mt9m111_setfmt_bayer10(icd); 425 ret = mt9m111_setfmt_bayer10(client);
470 break; 426 break;
471 case V4L2_PIX_FMT_RGB555: 427 case V4L2_PIX_FMT_RGB555:
472 ret = mt9m111_setfmt_rgb555(icd); 428 ret = mt9m111_setfmt_rgb555(client);
473 break; 429 break;
474 case V4L2_PIX_FMT_RGB565: 430 case V4L2_PIX_FMT_RGB565:
475 ret = mt9m111_setfmt_rgb565(icd); 431 ret = mt9m111_setfmt_rgb565(client);
476 break; 432 break;
477 case V4L2_PIX_FMT_UYVY: 433 case V4L2_PIX_FMT_UYVY:
478 mt9m111->swap_yuv_y_chromas = 0; 434 mt9m111->swap_yuv_y_chromas = 0;
479 mt9m111->swap_yuv_cb_cr = 0; 435 mt9m111->swap_yuv_cb_cr = 0;
480 ret = mt9m111_setfmt_yuv(icd); 436 ret = mt9m111_setfmt_yuv(client);
481 break; 437 break;
482 case V4L2_PIX_FMT_VYUY: 438 case V4L2_PIX_FMT_VYUY:
483 mt9m111->swap_yuv_y_chromas = 0; 439 mt9m111->swap_yuv_y_chromas = 0;
484 mt9m111->swap_yuv_cb_cr = 1; 440 mt9m111->swap_yuv_cb_cr = 1;
485 ret = mt9m111_setfmt_yuv(icd); 441 ret = mt9m111_setfmt_yuv(client);
486 break; 442 break;
487 case V4L2_PIX_FMT_YUYV: 443 case V4L2_PIX_FMT_YUYV:
488 mt9m111->swap_yuv_y_chromas = 1; 444 mt9m111->swap_yuv_y_chromas = 1;
489 mt9m111->swap_yuv_cb_cr = 0; 445 mt9m111->swap_yuv_cb_cr = 0;
490 ret = mt9m111_setfmt_yuv(icd); 446 ret = mt9m111_setfmt_yuv(client);
491 break; 447 break;
492 case V4L2_PIX_FMT_YVYU: 448 case V4L2_PIX_FMT_YVYU:
493 mt9m111->swap_yuv_y_chromas = 1; 449 mt9m111->swap_yuv_y_chromas = 1;
494 mt9m111->swap_yuv_cb_cr = 1; 450 mt9m111->swap_yuv_cb_cr = 1;
495 ret = mt9m111_setfmt_yuv(icd); 451 ret = mt9m111_setfmt_yuv(client);
496 break; 452 break;
497 default: 453 default:
498 dev_err(&icd->dev, "Pixel format not handled : %x\n", pixfmt); 454 dev_err(&client->dev, "Pixel format not handled : %x\n", pixfmt);
499 ret = -EINVAL; 455 ret = -EINVAL;
500 } 456 }
501 457
@@ -505,11 +461,10 @@ static int mt9m111_set_pixfmt(struct soc_camera_device *icd, u32 pixfmt)
505 return ret; 461 return ret;
506} 462}
507 463
508static int mt9m111_set_fmt(struct soc_camera_device *icd, 464static int mt9m111_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
509 struct v4l2_format *f)
510{ 465{
511 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 466 struct i2c_client *client = sd->priv;
512 struct mt9m111 *mt9m111 = i2c_get_clientdata(client); 467 struct mt9m111 *mt9m111 = to_mt9m111(client);
513 struct v4l2_pix_format *pix = &f->fmt.pix; 468 struct v4l2_pix_format *pix = &f->fmt.pix;
514 struct v4l2_rect rect = { 469 struct v4l2_rect rect = {
515 .left = mt9m111->rect.left, 470 .left = mt9m111->rect.left,
@@ -519,20 +474,19 @@ static int mt9m111_set_fmt(struct soc_camera_device *icd,
519 }; 474 };
520 int ret; 475 int ret;
521 476
522 dev_dbg(&icd->dev, "%s fmt=%x left=%d, top=%d, width=%d, height=%d\n", 477 dev_dbg(&client->dev, "%s fmt=%x left=%d, top=%d, width=%d, height=%d\n",
523 __func__, pix->pixelformat, rect.left, rect.top, rect.width, 478 __func__, pix->pixelformat, rect.left, rect.top, rect.width,
524 rect.height); 479 rect.height);
525 480
526 ret = mt9m111_setup_rect(icd, &rect); 481 ret = mt9m111_setup_rect(client, &rect);
527 if (!ret) 482 if (!ret)
528 ret = mt9m111_set_pixfmt(icd, pix->pixelformat); 483 ret = mt9m111_set_pixfmt(client, pix->pixelformat);
529 if (!ret) 484 if (!ret)
530 mt9m111->rect = rect; 485 mt9m111->rect = rect;
531 return ret; 486 return ret;
532} 487}
533 488
534static int mt9m111_try_fmt(struct soc_camera_device *icd, 489static int mt9m111_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
535 struct v4l2_format *f)
536{ 490{
537 struct v4l2_pix_format *pix = &f->fmt.pix; 491 struct v4l2_pix_format *pix = &f->fmt.pix;
538 492
@@ -544,11 +498,11 @@ static int mt9m111_try_fmt(struct soc_camera_device *icd,
544 return 0; 498 return 0;
545} 499}
546 500
547static int mt9m111_get_chip_id(struct soc_camera_device *icd, 501static int mt9m111_g_chip_ident(struct v4l2_subdev *sd,
548 struct v4l2_dbg_chip_ident *id) 502 struct v4l2_dbg_chip_ident *id)
549{ 503{
550 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 504 struct i2c_client *client = sd->priv;
551 struct mt9m111 *mt9m111 = i2c_get_clientdata(client); 505 struct mt9m111 *mt9m111 = to_mt9m111(client);
552 506
553 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR) 507 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
554 return -EINVAL; 508 return -EINVAL;
@@ -563,10 +517,10 @@ static int mt9m111_get_chip_id(struct soc_camera_device *icd,
563} 517}
564 518
565#ifdef CONFIG_VIDEO_ADV_DEBUG 519#ifdef CONFIG_VIDEO_ADV_DEBUG
566static int mt9m111_get_register(struct soc_camera_device *icd, 520static int mt9m111_g_register(struct v4l2_subdev *sd,
567 struct v4l2_dbg_register *reg) 521 struct v4l2_dbg_register *reg)
568{ 522{
569 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 523 struct i2c_client *client = sd->priv;
570 int val; 524 int val;
571 525
572 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff) 526 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff)
@@ -584,10 +538,10 @@ static int mt9m111_get_register(struct soc_camera_device *icd,
584 return 0; 538 return 0;
585} 539}
586 540
587static int mt9m111_set_register(struct soc_camera_device *icd, 541static int mt9m111_s_register(struct v4l2_subdev *sd,
588 struct v4l2_dbg_register *reg) 542 struct v4l2_dbg_register *reg)
589{ 543{
590 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 544 struct i2c_client *client = sd->priv;
591 545
592 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff) 546 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff)
593 return -EINVAL; 547 return -EINVAL;
@@ -639,41 +593,24 @@ static const struct v4l2_queryctrl mt9m111_controls[] = {
639 } 593 }
640}; 594};
641 595
642static int mt9m111_get_control(struct soc_camera_device *,
643 struct v4l2_control *);
644static int mt9m111_set_control(struct soc_camera_device *,
645 struct v4l2_control *);
646static int mt9m111_resume(struct soc_camera_device *icd); 596static int mt9m111_resume(struct soc_camera_device *icd);
647static int mt9m111_init(struct soc_camera_device *icd); 597static int mt9m111_init(struct soc_camera_device *icd);
648static int mt9m111_release(struct soc_camera_device *icd); 598static int mt9m111_release(struct soc_camera_device *icd);
649 599
650static struct soc_camera_ops mt9m111_ops = { 600static struct soc_camera_ops mt9m111_ops = {
651 .owner = THIS_MODULE,
652 .init = mt9m111_init, 601 .init = mt9m111_init,
653 .resume = mt9m111_resume, 602 .resume = mt9m111_resume,
654 .release = mt9m111_release, 603 .release = mt9m111_release,
655 .start_capture = mt9m111_start_capture,
656 .stop_capture = mt9m111_stop_capture,
657 .set_crop = mt9m111_set_crop, 604 .set_crop = mt9m111_set_crop,
658 .set_fmt = mt9m111_set_fmt,
659 .try_fmt = mt9m111_try_fmt,
660 .query_bus_param = mt9m111_query_bus_param, 605 .query_bus_param = mt9m111_query_bus_param,
661 .set_bus_param = mt9m111_set_bus_param, 606 .set_bus_param = mt9m111_set_bus_param,
662 .controls = mt9m111_controls, 607 .controls = mt9m111_controls,
663 .num_controls = ARRAY_SIZE(mt9m111_controls), 608 .num_controls = ARRAY_SIZE(mt9m111_controls),
664 .get_control = mt9m111_get_control,
665 .set_control = mt9m111_set_control,
666 .get_chip_id = mt9m111_get_chip_id,
667#ifdef CONFIG_VIDEO_ADV_DEBUG
668 .get_register = mt9m111_get_register,
669 .set_register = mt9m111_set_register,
670#endif
671}; 609};
672 610
673static int mt9m111_set_flip(struct soc_camera_device *icd, int flip, int mask) 611static int mt9m111_set_flip(struct i2c_client *client, int flip, int mask)
674{ 612{
675 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 613 struct mt9m111 *mt9m111 = to_mt9m111(client);
676 struct mt9m111 *mt9m111 = i2c_get_clientdata(client);
677 int ret; 614 int ret;
678 615
679 if (mt9m111->context == HIGHPOWER) { 616 if (mt9m111->context == HIGHPOWER) {
@@ -691,9 +628,8 @@ static int mt9m111_set_flip(struct soc_camera_device *icd, int flip, int mask)
691 return ret; 628 return ret;
692} 629}
693 630
694static int mt9m111_get_global_gain(struct soc_camera_device *icd) 631static int mt9m111_get_global_gain(struct i2c_client *client)
695{ 632{
696 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
697 int data; 633 int data;
698 634
699 data = reg_read(GLOBAL_GAIN); 635 data = reg_read(GLOBAL_GAIN);
@@ -703,9 +639,9 @@ static int mt9m111_get_global_gain(struct soc_camera_device *icd)
703 return data; 639 return data;
704} 640}
705 641
706static int mt9m111_set_global_gain(struct soc_camera_device *icd, int gain) 642static int mt9m111_set_global_gain(struct i2c_client *client, int gain)
707{ 643{
708 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 644 struct soc_camera_device *icd = client->dev.platform_data;
709 u16 val; 645 u16 val;
710 646
711 if (gain > 63 * 2 * 2) 647 if (gain > 63 * 2 * 2)
@@ -722,10 +658,9 @@ static int mt9m111_set_global_gain(struct soc_camera_device *icd, int gain)
722 return reg_write(GLOBAL_GAIN, val); 658 return reg_write(GLOBAL_GAIN, val);
723} 659}
724 660
725static int mt9m111_set_autoexposure(struct soc_camera_device *icd, int on) 661static int mt9m111_set_autoexposure(struct i2c_client *client, int on)
726{ 662{
727 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 663 struct mt9m111 *mt9m111 = to_mt9m111(client);
728 struct mt9m111 *mt9m111 = i2c_get_clientdata(client);
729 int ret; 664 int ret;
730 665
731 if (on) 666 if (on)
@@ -739,10 +674,9 @@ static int mt9m111_set_autoexposure(struct soc_camera_device *icd, int on)
739 return ret; 674 return ret;
740} 675}
741 676
742static int mt9m111_set_autowhitebalance(struct soc_camera_device *icd, int on) 677static int mt9m111_set_autowhitebalance(struct i2c_client *client, int on)
743{ 678{
744 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 679 struct mt9m111 *mt9m111 = to_mt9m111(client);
745 struct mt9m111 *mt9m111 = i2c_get_clientdata(client);
746 int ret; 680 int ret;
747 681
748 if (on) 682 if (on)
@@ -756,11 +690,10 @@ static int mt9m111_set_autowhitebalance(struct soc_camera_device *icd, int on)
756 return ret; 690 return ret;
757} 691}
758 692
759static int mt9m111_get_control(struct soc_camera_device *icd, 693static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
760 struct v4l2_control *ctrl)
761{ 694{
762 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 695 struct i2c_client *client = sd->priv;
763 struct mt9m111 *mt9m111 = i2c_get_clientdata(client); 696 struct mt9m111 *mt9m111 = to_mt9m111(client);
764 int data; 697 int data;
765 698
766 switch (ctrl->id) { 699 switch (ctrl->id) {
@@ -785,7 +718,7 @@ static int mt9m111_get_control(struct soc_camera_device *icd,
785 ctrl->value = !!(data & MT9M111_RMB_MIRROR_COLS); 718 ctrl->value = !!(data & MT9M111_RMB_MIRROR_COLS);
786 break; 719 break;
787 case V4L2_CID_GAIN: 720 case V4L2_CID_GAIN:
788 data = mt9m111_get_global_gain(icd); 721 data = mt9m111_get_global_gain(client);
789 if (data < 0) 722 if (data < 0)
790 return data; 723 return data;
791 ctrl->value = data; 724 ctrl->value = data;
@@ -800,38 +733,36 @@ static int mt9m111_get_control(struct soc_camera_device *icd,
800 return 0; 733 return 0;
801} 734}
802 735
803static int mt9m111_set_control(struct soc_camera_device *icd, 736static int mt9m111_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
804 struct v4l2_control *ctrl)
805{ 737{
806 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 738 struct i2c_client *client = sd->priv;
807 struct mt9m111 *mt9m111 = i2c_get_clientdata(client); 739 struct mt9m111 *mt9m111 = to_mt9m111(client);
808 const struct v4l2_queryctrl *qctrl; 740 const struct v4l2_queryctrl *qctrl;
809 int ret; 741 int ret;
810 742
811 qctrl = soc_camera_find_qctrl(&mt9m111_ops, ctrl->id); 743 qctrl = soc_camera_find_qctrl(&mt9m111_ops, ctrl->id);
812
813 if (!qctrl) 744 if (!qctrl)
814 return -EINVAL; 745 return -EINVAL;
815 746
816 switch (ctrl->id) { 747 switch (ctrl->id) {
817 case V4L2_CID_VFLIP: 748 case V4L2_CID_VFLIP:
818 mt9m111->vflip = ctrl->value; 749 mt9m111->vflip = ctrl->value;
819 ret = mt9m111_set_flip(icd, ctrl->value, 750 ret = mt9m111_set_flip(client, ctrl->value,
820 MT9M111_RMB_MIRROR_ROWS); 751 MT9M111_RMB_MIRROR_ROWS);
821 break; 752 break;
822 case V4L2_CID_HFLIP: 753 case V4L2_CID_HFLIP:
823 mt9m111->hflip = ctrl->value; 754 mt9m111->hflip = ctrl->value;
824 ret = mt9m111_set_flip(icd, ctrl->value, 755 ret = mt9m111_set_flip(client, ctrl->value,
825 MT9M111_RMB_MIRROR_COLS); 756 MT9M111_RMB_MIRROR_COLS);
826 break; 757 break;
827 case V4L2_CID_GAIN: 758 case V4L2_CID_GAIN:
828 ret = mt9m111_set_global_gain(icd, ctrl->value); 759 ret = mt9m111_set_global_gain(client, ctrl->value);
829 break; 760 break;
830 case V4L2_CID_EXPOSURE_AUTO: 761 case V4L2_CID_EXPOSURE_AUTO:
831 ret = mt9m111_set_autoexposure(icd, ctrl->value); 762 ret = mt9m111_set_autoexposure(client, ctrl->value);
832 break; 763 break;
833 case V4L2_CID_AUTO_WHITE_BALANCE: 764 case V4L2_CID_AUTO_WHITE_BALANCE:
834 ret = mt9m111_set_autowhitebalance(icd, ctrl->value); 765 ret = mt9m111_set_autowhitebalance(client, ctrl->value);
835 break; 766 break;
836 default: 767 default:
837 ret = -EINVAL; 768 ret = -EINVAL;
@@ -840,34 +771,34 @@ static int mt9m111_set_control(struct soc_camera_device *icd,
840 return ret; 771 return ret;
841} 772}
842 773
843static int mt9m111_restore_state(struct soc_camera_device *icd) 774static int mt9m111_restore_state(struct i2c_client *client)
844{ 775{
845 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 776 struct mt9m111 *mt9m111 = to_mt9m111(client);
846 struct mt9m111 *mt9m111 = i2c_get_clientdata(client); 777 struct soc_camera_device *icd = client->dev.platform_data;
847 778
848 mt9m111_set_context(icd, mt9m111->context); 779 mt9m111_set_context(client, mt9m111->context);
849 mt9m111_set_pixfmt(icd, mt9m111->pixfmt); 780 mt9m111_set_pixfmt(client, mt9m111->pixfmt);
850 mt9m111_setup_rect(icd, &mt9m111->rect); 781 mt9m111_setup_rect(client, &mt9m111->rect);
851 mt9m111_set_flip(icd, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS); 782 mt9m111_set_flip(client, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS);
852 mt9m111_set_flip(icd, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS); 783 mt9m111_set_flip(client, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS);
853 mt9m111_set_global_gain(icd, icd->gain); 784 mt9m111_set_global_gain(client, icd->gain);
854 mt9m111_set_autoexposure(icd, mt9m111->autoexposure); 785 mt9m111_set_autoexposure(client, mt9m111->autoexposure);
855 mt9m111_set_autowhitebalance(icd, mt9m111->autowhitebalance); 786 mt9m111_set_autowhitebalance(client, mt9m111->autowhitebalance);
856 return 0; 787 return 0;
857} 788}
858 789
859static int mt9m111_resume(struct soc_camera_device *icd) 790static int mt9m111_resume(struct soc_camera_device *icd)
860{ 791{
861 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 792 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
862 struct mt9m111 *mt9m111 = i2c_get_clientdata(client); 793 struct mt9m111 *mt9m111 = to_mt9m111(client);
863 int ret = 0; 794 int ret = 0;
864 795
865 if (mt9m111->powered) { 796 if (mt9m111->powered) {
866 ret = mt9m111_enable(icd); 797 ret = mt9m111_enable(client);
867 if (!ret) 798 if (!ret)
868 ret = mt9m111_reset(icd); 799 ret = mt9m111_reset(client);
869 if (!ret) 800 if (!ret)
870 ret = mt9m111_restore_state(icd); 801 ret = mt9m111_restore_state(client);
871 } 802 }
872 return ret; 803 return ret;
873} 804}
@@ -875,17 +806,17 @@ static int mt9m111_resume(struct soc_camera_device *icd)
875static int mt9m111_init(struct soc_camera_device *icd) 806static int mt9m111_init(struct soc_camera_device *icd)
876{ 807{
877 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 808 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
878 struct mt9m111 *mt9m111 = i2c_get_clientdata(client); 809 struct mt9m111 *mt9m111 = to_mt9m111(client);
879 int ret; 810 int ret;
880 811
881 mt9m111->context = HIGHPOWER; 812 mt9m111->context = HIGHPOWER;
882 ret = mt9m111_enable(icd); 813 ret = mt9m111_enable(client);
883 if (!ret) 814 if (!ret)
884 ret = mt9m111_reset(icd); 815 ret = mt9m111_reset(client);
885 if (!ret) 816 if (!ret)
886 ret = mt9m111_set_context(icd, mt9m111->context); 817 ret = mt9m111_set_context(client, mt9m111->context);
887 if (!ret) 818 if (!ret)
888 ret = mt9m111_set_autoexposure(icd, mt9m111->autoexposure); 819 ret = mt9m111_set_autoexposure(client, mt9m111->autoexposure);
889 if (ret) 820 if (ret)
890 dev_err(&icd->dev, "mt9m11x init failed: %d\n", ret); 821 dev_err(&icd->dev, "mt9m11x init failed: %d\n", ret);
891 return ret; 822 return ret;
@@ -893,9 +824,14 @@ static int mt9m111_init(struct soc_camera_device *icd)
893 824
894static int mt9m111_release(struct soc_camera_device *icd) 825static int mt9m111_release(struct soc_camera_device *icd)
895{ 826{
827 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
828 struct mt9m111 *mt9m111 = to_mt9m111(client);
896 int ret; 829 int ret;
897 830
898 ret = mt9m111_disable(icd); 831 ret = reg_clear(RESET, MT9M111_RESET_CHIP_ENABLE);
832 if (!ret)
833 mt9m111->powered = 0;
834
899 if (ret < 0) 835 if (ret < 0)
900 dev_err(&icd->dev, "mt9m11x release failed: %d\n", ret); 836 dev_err(&icd->dev, "mt9m11x release failed: %d\n", ret);
901 837
@@ -909,7 +845,7 @@ static int mt9m111_release(struct soc_camera_device *icd)
909static int mt9m111_video_probe(struct soc_camera_device *icd, 845static int mt9m111_video_probe(struct soc_camera_device *icd,
910 struct i2c_client *client) 846 struct i2c_client *client)
911{ 847{
912 struct mt9m111 *mt9m111 = i2c_get_clientdata(client); 848 struct mt9m111 *mt9m111 = to_mt9m111(client);
913 s32 data; 849 s32 data;
914 int ret; 850 int ret;
915 851
@@ -921,15 +857,10 @@ static int mt9m111_video_probe(struct soc_camera_device *icd,
921 to_soc_camera_host(icd->dev.parent)->nr != icd->iface) 857 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
922 return -ENODEV; 858 return -ENODEV;
923 859
924 /* Switch master clock on */ 860 ret = mt9m111_enable(client);
925 ret = soc_camera_video_start(icd, &client->dev);
926 if (ret)
927 goto evstart;
928
929 ret = mt9m111_enable(icd);
930 if (ret) 861 if (ret)
931 goto ei2c; 862 goto ei2c;
932 ret = mt9m111_reset(icd); 863 ret = mt9m111_reset(client);
933 if (ret) 864 if (ret)
934 goto ei2c; 865 goto ei2c;
935 866
@@ -961,11 +892,29 @@ static int mt9m111_video_probe(struct soc_camera_device *icd,
961 mt9m111->swap_rgb_red_blue = 1; 892 mt9m111->swap_rgb_red_blue = 1;
962 893
963ei2c: 894ei2c:
964 soc_camera_video_stop(icd);
965evstart:
966 return ret; 895 return ret;
967} 896}
968 897
898static struct v4l2_subdev_core_ops mt9m111_subdev_core_ops = {
899 .g_ctrl = mt9m111_g_ctrl,
900 .s_ctrl = mt9m111_s_ctrl,
901 .g_chip_ident = mt9m111_g_chip_ident,
902#ifdef CONFIG_VIDEO_ADV_DEBUG
903 .g_register = mt9m111_g_register,
904 .s_register = mt9m111_s_register,
905#endif
906};
907
908static struct v4l2_subdev_video_ops mt9m111_subdev_video_ops = {
909 .s_fmt = mt9m111_s_fmt,
910 .try_fmt = mt9m111_try_fmt,
911};
912
913static struct v4l2_subdev_ops mt9m111_subdev_ops = {
914 .core = &mt9m111_subdev_core_ops,
915 .video = &mt9m111_subdev_video_ops,
916};
917
969static int mt9m111_probe(struct i2c_client *client, 918static int mt9m111_probe(struct i2c_client *client,
970 const struct i2c_device_id *did) 919 const struct i2c_device_id *did)
971{ 920{
@@ -996,7 +945,7 @@ static int mt9m111_probe(struct i2c_client *client,
996 if (!mt9m111) 945 if (!mt9m111)
997 return -ENOMEM; 946 return -ENOMEM;
998 947
999 i2c_set_clientdata(client, mt9m111); 948 v4l2_i2c_subdev_init(&mt9m111->subdev, client, &mt9m111_subdev_ops);
1000 949
1001 /* Second stage probe - when a capture adapter is there */ 950 /* Second stage probe - when a capture adapter is there */
1002 icd->ops = &mt9m111_ops; 951 icd->ops = &mt9m111_ops;
@@ -1022,7 +971,7 @@ static int mt9m111_probe(struct i2c_client *client,
1022 971
1023static int mt9m111_remove(struct i2c_client *client) 972static int mt9m111_remove(struct i2c_client *client)
1024{ 973{
1025 struct mt9m111 *mt9m111 = i2c_get_clientdata(client); 974 struct mt9m111 *mt9m111 = to_mt9m111(client);
1026 struct soc_camera_device *icd = client->dev.platform_data; 975 struct soc_camera_device *icd = client->dev.platform_data;
1027 976
1028 icd->ops = NULL; 977 icd->ops = NULL;
diff --git a/drivers/media/video/mt9t031.c b/drivers/media/video/mt9t031.c
index d9c7c2fd698a..27a5edda902c 100644
--- a/drivers/media/video/mt9t031.c
+++ b/drivers/media/video/mt9t031.c
@@ -13,13 +13,13 @@
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/log2.h> 14#include <linux/log2.h>
15 15
16#include <media/v4l2-common.h> 16#include <media/v4l2-subdev.h>
17#include <media/v4l2-chip-ident.h> 17#include <media/v4l2-chip-ident.h>
18#include <media/soc_camera.h> 18#include <media/soc_camera.h>
19 19
20/* mt9t031 i2c address 0x5d 20/* mt9t031 i2c address 0x5d
21 * The platform has to define i2c_board_info 21 * The platform has to define i2c_board_info and link to it from
22 * and call i2c_register_board_info() */ 22 * struct soc_camera_link */
23 23
24/* mt9t031 selected register addresses */ 24/* mt9t031 selected register addresses */
25#define MT9T031_CHIP_VERSION 0x00 25#define MT9T031_CHIP_VERSION 0x00
@@ -68,12 +68,18 @@ static const struct soc_camera_data_format mt9t031_colour_formats[] = {
68}; 68};
69 69
70struct mt9t031 { 70struct mt9t031 {
71 struct v4l2_subdev subdev;
71 int model; /* V4L2_IDENT_MT9T031* codes from v4l2-chip-ident.h */ 72 int model; /* V4L2_IDENT_MT9T031* codes from v4l2-chip-ident.h */
72 unsigned char autoexposure; 73 unsigned char autoexposure;
73 u16 xskip; 74 u16 xskip;
74 u16 yskip; 75 u16 yskip;
75}; 76};
76 77
78static struct mt9t031 *to_mt9t031(const struct i2c_client *client)
79{
80 return container_of(i2c_get_clientdata(client), struct mt9t031, subdev);
81}
82
77static int reg_read(struct i2c_client *client, const u8 reg) 83static int reg_read(struct i2c_client *client, const u8 reg)
78{ 84{
79 s32 data = i2c_smbus_read_word_data(client, reg); 85 s32 data = i2c_smbus_read_word_data(client, reg);
@@ -134,21 +140,10 @@ static int get_shutter(struct i2c_client *client, u32 *data)
134 return ret < 0 ? ret : 0; 140 return ret < 0 ? ret : 0;
135} 141}
136 142
137static int mt9t031_init(struct soc_camera_device *icd) 143static int mt9t031_idle(struct i2c_client *client)
138{ 144{
139 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
140 struct soc_camera_link *icl = to_soc_camera_link(icd);
141 int ret; 145 int ret;
142 146
143 if (icl->power) {
144 ret = icl->power(&client->dev, 1);
145 if (ret < 0) {
146 dev_err(icd->vdev->parent,
147 "Platform failed to power-on the camera.\n");
148 return ret;
149 }
150 }
151
152 /* Disable chip output, synchronous option update */ 147 /* Disable chip output, synchronous option update */
153 ret = reg_write(client, MT9T031_RESET, 1); 148 ret = reg_write(client, MT9T031_RESET, 1);
154 if (ret >= 0) 149 if (ret >= 0)
@@ -156,43 +151,46 @@ static int mt9t031_init(struct soc_camera_device *icd)
156 if (ret >= 0) 151 if (ret >= 0)
157 ret = reg_clear(client, MT9T031_OUTPUT_CONTROL, 2); 152 ret = reg_clear(client, MT9T031_OUTPUT_CONTROL, 2);
158 153
159 if (ret < 0 && icl->power)
160 icl->power(&client->dev, 0);
161
162 return ret >= 0 ? 0 : -EIO; 154 return ret >= 0 ? 0 : -EIO;
163} 155}
164 156
165static int mt9t031_release(struct soc_camera_device *icd) 157static int mt9t031_disable(struct i2c_client *client)
166{ 158{
167 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
168 struct soc_camera_link *icl = to_soc_camera_link(icd);
169
170 /* Disable the chip */ 159 /* Disable the chip */
171 reg_clear(client, MT9T031_OUTPUT_CONTROL, 2); 160 reg_clear(client, MT9T031_OUTPUT_CONTROL, 2);
172 161
173 if (icl->power)
174 icl->power(&client->dev, 0);
175
176 return 0; 162 return 0;
177} 163}
178 164
179static int mt9t031_start_capture(struct soc_camera_device *icd) 165static int mt9t031_init(struct soc_camera_device *icd)
180{ 166{
181 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 167 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
182 168
183 /* Switch to master "normal" mode */ 169 return mt9t031_idle(client);
184 if (reg_set(client, MT9T031_OUTPUT_CONTROL, 2) < 0)
185 return -EIO;
186 return 0;
187} 170}
188 171
189static int mt9t031_stop_capture(struct soc_camera_device *icd) 172static int mt9t031_release(struct soc_camera_device *icd)
190{ 173{
191 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 174 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
192 175
193 /* Stop sensor readout */ 176 return mt9t031_disable(client);
194 if (reg_clear(client, MT9T031_OUTPUT_CONTROL, 2) < 0) 177}
178
179static int mt9t031_s_stream(struct v4l2_subdev *sd, int enable)
180{
181 struct i2c_client *client = sd->priv;
182 int ret;
183
184 if (enable)
185 /* Switch to master "normal" mode */
186 ret = reg_set(client, MT9T031_OUTPUT_CONTROL, 2);
187 else
188 /* Stop sensor readout */
189 ret = reg_clear(client, MT9T031_OUTPUT_CONTROL, 2);
190
191 if (ret < 0)
195 return -EIO; 192 return -EIO;
193
196 return 0; 194 return 0;
197} 195}
198 196
@@ -236,7 +234,7 @@ static int mt9t031_set_params(struct soc_camera_device *icd,
236 struct v4l2_rect *rect, u16 xskip, u16 yskip) 234 struct v4l2_rect *rect, u16 xskip, u16 yskip)
237{ 235{
238 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 236 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
239 struct mt9t031 *mt9t031 = i2c_get_clientdata(client); 237 struct mt9t031 *mt9t031 = to_mt9t031(client);
240 int ret; 238 int ret;
241 u16 xbin, ybin, width, height, left, top; 239 u16 xbin, ybin, width, height, left, top;
242 const u16 hblank = MT9T031_HORIZONTAL_BLANK, 240 const u16 hblank = MT9T031_HORIZONTAL_BLANK,
@@ -334,17 +332,17 @@ static int mt9t031_set_crop(struct soc_camera_device *icd,
334 struct v4l2_rect *rect) 332 struct v4l2_rect *rect)
335{ 333{
336 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 334 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
337 struct mt9t031 *mt9t031 = i2c_get_clientdata(client); 335 struct mt9t031 *mt9t031 = to_mt9t031(client);
338 336
339 /* CROP - no change in scaling, or in limits */ 337 /* CROP - no change in scaling, or in limits */
340 return mt9t031_set_params(icd, rect, mt9t031->xskip, mt9t031->yskip); 338 return mt9t031_set_params(icd, rect, mt9t031->xskip, mt9t031->yskip);
341} 339}
342 340
343static int mt9t031_set_fmt(struct soc_camera_device *icd, 341static int mt9t031_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
344 struct v4l2_format *f)
345{ 342{
346 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 343 struct i2c_client *client = sd->priv;
347 struct mt9t031 *mt9t031 = i2c_get_clientdata(client); 344 struct mt9t031 *mt9t031 = to_mt9t031(client);
345 struct soc_camera_device *icd = client->dev.platform_data;
348 int ret; 346 int ret;
349 u16 xskip, yskip; 347 u16 xskip, yskip;
350 struct v4l2_rect rect = { 348 struct v4l2_rect rect = {
@@ -379,8 +377,7 @@ static int mt9t031_set_fmt(struct soc_camera_device *icd,
379 return ret; 377 return ret;
380} 378}
381 379
382static int mt9t031_try_fmt(struct soc_camera_device *icd, 380static int mt9t031_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
383 struct v4l2_format *f)
384{ 381{
385 struct v4l2_pix_format *pix = &f->fmt.pix; 382 struct v4l2_pix_format *pix = &f->fmt.pix;
386 383
@@ -391,11 +388,11 @@ static int mt9t031_try_fmt(struct soc_camera_device *icd,
391 return 0; 388 return 0;
392} 389}
393 390
394static int mt9t031_get_chip_id(struct soc_camera_device *icd, 391static int mt9t031_g_chip_ident(struct v4l2_subdev *sd,
395 struct v4l2_dbg_chip_ident *id) 392 struct v4l2_dbg_chip_ident *id)
396{ 393{
397 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 394 struct i2c_client *client = sd->priv;
398 struct mt9t031 *mt9t031 = i2c_get_clientdata(client); 395 struct mt9t031 *mt9t031 = to_mt9t031(client);
399 396
400 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR) 397 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
401 return -EINVAL; 398 return -EINVAL;
@@ -410,10 +407,10 @@ static int mt9t031_get_chip_id(struct soc_camera_device *icd,
410} 407}
411 408
412#ifdef CONFIG_VIDEO_ADV_DEBUG 409#ifdef CONFIG_VIDEO_ADV_DEBUG
413static int mt9t031_get_register(struct soc_camera_device *icd, 410static int mt9t031_g_register(struct v4l2_subdev *sd,
414 struct v4l2_dbg_register *reg) 411 struct v4l2_dbg_register *reg)
415{ 412{
416 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 413 struct i2c_client *client = sd->priv;
417 414
418 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 415 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
419 return -EINVAL; 416 return -EINVAL;
@@ -429,10 +426,10 @@ static int mt9t031_get_register(struct soc_camera_device *icd,
429 return 0; 426 return 0;
430} 427}
431 428
432static int mt9t031_set_register(struct soc_camera_device *icd, 429static int mt9t031_s_register(struct v4l2_subdev *sd,
433 struct v4l2_dbg_register *reg) 430 struct v4l2_dbg_register *reg)
434{ 431{
435 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 432 struct i2c_client *client = sd->priv;
436 433
437 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 434 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
438 return -EINVAL; 435 return -EINVAL;
@@ -493,35 +490,20 @@ static const struct v4l2_queryctrl mt9t031_controls[] = {
493 } 490 }
494}; 491};
495 492
496static int mt9t031_get_control(struct soc_camera_device *, struct v4l2_control *);
497static int mt9t031_set_control(struct soc_camera_device *, struct v4l2_control *);
498
499static struct soc_camera_ops mt9t031_ops = { 493static struct soc_camera_ops mt9t031_ops = {
500 .owner = THIS_MODULE,
501 .init = mt9t031_init, 494 .init = mt9t031_init,
502 .release = mt9t031_release, 495 .release = mt9t031_release,
503 .start_capture = mt9t031_start_capture,
504 .stop_capture = mt9t031_stop_capture,
505 .set_crop = mt9t031_set_crop, 496 .set_crop = mt9t031_set_crop,
506 .set_fmt = mt9t031_set_fmt,
507 .try_fmt = mt9t031_try_fmt,
508 .set_bus_param = mt9t031_set_bus_param, 497 .set_bus_param = mt9t031_set_bus_param,
509 .query_bus_param = mt9t031_query_bus_param, 498 .query_bus_param = mt9t031_query_bus_param,
510 .controls = mt9t031_controls, 499 .controls = mt9t031_controls,
511 .num_controls = ARRAY_SIZE(mt9t031_controls), 500 .num_controls = ARRAY_SIZE(mt9t031_controls),
512 .get_control = mt9t031_get_control,
513 .set_control = mt9t031_set_control,
514 .get_chip_id = mt9t031_get_chip_id,
515#ifdef CONFIG_VIDEO_ADV_DEBUG
516 .get_register = mt9t031_get_register,
517 .set_register = mt9t031_set_register,
518#endif
519}; 501};
520 502
521static int mt9t031_get_control(struct soc_camera_device *icd, struct v4l2_control *ctrl) 503static int mt9t031_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
522{ 504{
523 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 505 struct i2c_client *client = sd->priv;
524 struct mt9t031 *mt9t031 = i2c_get_clientdata(client); 506 struct mt9t031 *mt9t031 = to_mt9t031(client);
525 int data; 507 int data;
526 508
527 switch (ctrl->id) { 509 switch (ctrl->id) {
@@ -544,10 +526,11 @@ static int mt9t031_get_control(struct soc_camera_device *icd, struct v4l2_contro
544 return 0; 526 return 0;
545} 527}
546 528
547static int mt9t031_set_control(struct soc_camera_device *icd, struct v4l2_control *ctrl) 529static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
548{ 530{
549 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 531 struct i2c_client *client = sd->priv;
550 struct mt9t031 *mt9t031 = i2c_get_clientdata(client); 532 struct mt9t031 *mt9t031 = to_mt9t031(client);
533 struct soc_camera_device *icd = client->dev.platform_data;
551 const struct v4l2_queryctrl *qctrl; 534 const struct v4l2_queryctrl *qctrl;
552 int data; 535 int data;
553 536
@@ -653,12 +636,11 @@ static int mt9t031_set_control(struct soc_camera_device *icd, struct v4l2_contro
653 636
654/* Interface active, can use i2c. If it fails, it can indeed mean, that 637/* Interface active, can use i2c. If it fails, it can indeed mean, that
655 * this wasn't our capture interface, so, we wait for the right one */ 638 * this wasn't our capture interface, so, we wait for the right one */
656static int mt9t031_video_probe(struct soc_camera_device *icd, 639static int mt9t031_video_probe(struct i2c_client *client)
657 struct i2c_client *client)
658{ 640{
659 struct mt9t031 *mt9t031 = i2c_get_clientdata(client); 641 struct soc_camera_device *icd = client->dev.platform_data;
642 struct mt9t031 *mt9t031 = to_mt9t031(client);
660 s32 data; 643 s32 data;
661 int ret;
662 644
663 /* We must have a parent by now. And it cannot be a wrong one. 645 /* We must have a parent by now. And it cannot be a wrong one.
664 * So this entire test is completely redundant. */ 646 * So this entire test is completely redundant. */
@@ -666,11 +648,6 @@ static int mt9t031_video_probe(struct soc_camera_device *icd,
666 to_soc_camera_host(icd->dev.parent)->nr != icd->iface) 648 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
667 return -ENODEV; 649 return -ENODEV;
668 650
669 /* Switch master clock on */
670 ret = soc_camera_video_start(icd, &client->dev);
671 if (ret)
672 return ret;
673
674 /* Enable the chip */ 651 /* Enable the chip */
675 data = reg_write(client, MT9T031_CHIP_ENABLE, 1); 652 data = reg_write(client, MT9T031_CHIP_ENABLE, 1);
676 dev_dbg(&icd->dev, "write: %d\n", data); 653 dev_dbg(&icd->dev, "write: %d\n", data);
@@ -678,8 +655,6 @@ static int mt9t031_video_probe(struct soc_camera_device *icd,
678 /* Read out the chip version register */ 655 /* Read out the chip version register */
679 data = reg_read(client, MT9T031_CHIP_VERSION); 656 data = reg_read(client, MT9T031_CHIP_VERSION);
680 657
681 soc_camera_video_stop(icd);
682
683 switch (data) { 658 switch (data) {
684 case 0x1621: 659 case 0x1621:
685 mt9t031->model = V4L2_IDENT_MT9T031; 660 mt9t031->model = V4L2_IDENT_MT9T031;
@@ -697,6 +672,27 @@ static int mt9t031_video_probe(struct soc_camera_device *icd,
697 return 0; 672 return 0;
698} 673}
699 674
675static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
676 .g_ctrl = mt9t031_g_ctrl,
677 .s_ctrl = mt9t031_s_ctrl,
678 .g_chip_ident = mt9t031_g_chip_ident,
679#ifdef CONFIG_VIDEO_ADV_DEBUG
680 .g_register = mt9t031_g_register,
681 .s_register = mt9t031_s_register,
682#endif
683};
684
685static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
686 .s_stream = mt9t031_s_stream,
687 .s_fmt = mt9t031_s_fmt,
688 .try_fmt = mt9t031_try_fmt,
689};
690
691static struct v4l2_subdev_ops mt9t031_subdev_ops = {
692 .core = &mt9t031_subdev_core_ops,
693 .video = &mt9t031_subdev_video_ops,
694};
695
700static int mt9t031_probe(struct i2c_client *client, 696static int mt9t031_probe(struct i2c_client *client,
701 const struct i2c_device_id *did) 697 const struct i2c_device_id *did)
702{ 698{
@@ -727,7 +723,7 @@ static int mt9t031_probe(struct i2c_client *client,
727 if (!mt9t031) 723 if (!mt9t031)
728 return -ENOMEM; 724 return -ENOMEM;
729 725
730 i2c_set_clientdata(client, mt9t031); 726 v4l2_i2c_subdev_init(&mt9t031->subdev, client, &mt9t031_subdev_ops);
731 727
732 /* Second stage probe - when a capture adapter is there */ 728 /* Second stage probe - when a capture adapter is there */
733 icd->ops = &mt9t031_ops; 729 icd->ops = &mt9t031_ops;
@@ -747,7 +743,12 @@ static int mt9t031_probe(struct i2c_client *client,
747 mt9t031->xskip = 1; 743 mt9t031->xskip = 1;
748 mt9t031->yskip = 1; 744 mt9t031->yskip = 1;
749 745
750 ret = mt9t031_video_probe(icd, client); 746 mt9t031_idle(client);
747
748 ret = mt9t031_video_probe(client);
749
750 mt9t031_disable(client);
751
751 if (ret) { 752 if (ret) {
752 icd->ops = NULL; 753 icd->ops = NULL;
753 i2c_set_clientdata(client, NULL); 754 i2c_set_clientdata(client, NULL);
@@ -759,7 +760,7 @@ static int mt9t031_probe(struct i2c_client *client,
759 760
760static int mt9t031_remove(struct i2c_client *client) 761static int mt9t031_remove(struct i2c_client *client)
761{ 762{
762 struct mt9t031 *mt9t031 = i2c_get_clientdata(client); 763 struct mt9t031 *mt9t031 = to_mt9t031(client);
763 struct soc_camera_device *icd = client->dev.platform_data; 764 struct soc_camera_device *icd = client->dev.platform_data;
764 765
765 icd->ops = NULL; 766 icd->ops = NULL;
diff --git a/drivers/media/video/mt9v022.c b/drivers/media/video/mt9v022.c
index 959cc299f1ae..3cb9f0f1e256 100644
--- a/drivers/media/video/mt9v022.c
+++ b/drivers/media/video/mt9v022.c
@@ -14,13 +14,13 @@
14#include <linux/delay.h> 14#include <linux/delay.h>
15#include <linux/log2.h> 15#include <linux/log2.h>
16 16
17#include <media/v4l2-common.h> 17#include <media/v4l2-subdev.h>
18#include <media/v4l2-chip-ident.h> 18#include <media/v4l2-chip-ident.h>
19#include <media/soc_camera.h> 19#include <media/soc_camera.h>
20 20
21/* mt9v022 i2c address 0x48, 0x4c, 0x58, 0x5c 21/* mt9v022 i2c address 0x48, 0x4c, 0x58, 0x5c
22 * The platform has to define i2c_board_info 22 * The platform has to define ctruct i2c_board_info objects and link to them
23 * and call i2c_register_board_info() */ 23 * from struct soc_camera_link */
24 24
25static char *sensor_type; 25static char *sensor_type;
26module_param(sensor_type, charp, S_IRUGO); 26module_param(sensor_type, charp, S_IRUGO);
@@ -85,10 +85,16 @@ static const struct soc_camera_data_format mt9v022_monochrome_formats[] = {
85}; 85};
86 86
87struct mt9v022 { 87struct mt9v022 {
88 struct v4l2_subdev subdev;
88 int model; /* V4L2_IDENT_MT9V022* codes from v4l2-chip-ident.h */ 89 int model; /* V4L2_IDENT_MT9V022* codes from v4l2-chip-ident.h */
89 u16 chip_control; 90 u16 chip_control;
90}; 91};
91 92
93static struct mt9v022 *to_mt9v022(const struct i2c_client *client)
94{
95 return container_of(i2c_get_clientdata(client), struct mt9v022, subdev);
96}
97
92static int reg_read(struct i2c_client *client, const u8 reg) 98static int reg_read(struct i2c_client *client, const u8 reg)
93{ 99{
94 s32 data = i2c_smbus_read_word_data(client, reg); 100 s32 data = i2c_smbus_read_word_data(client, reg);
@@ -126,26 +132,9 @@ static int reg_clear(struct i2c_client *client, const u8 reg,
126static int mt9v022_init(struct soc_camera_device *icd) 132static int mt9v022_init(struct soc_camera_device *icd)
127{ 133{
128 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 134 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
129 struct soc_camera_link *icl = to_soc_camera_link(icd); 135 struct mt9v022 *mt9v022 = to_mt9v022(client);
130 struct mt9v022 *mt9v022 = i2c_get_clientdata(client);
131 int ret; 136 int ret;
132 137
133 if (icl->power) {
134 ret = icl->power(&client->dev, 1);
135 if (ret < 0) {
136 dev_err(icd->vdev->parent,
137 "Platform failed to power-on the camera.\n");
138 return ret;
139 }
140 }
141
142 /*
143 * The camera could have been already on, we hard-reset it additionally,
144 * if available. Soft reset is done in video_probe().
145 */
146 if (icl->reset)
147 icl->reset(&client->dev);
148
149 /* Almost the default mode: master, parallel, simultaneous, and an 138 /* Almost the default mode: master, parallel, simultaneous, and an
150 * undocumented bit 0x200, which is present in table 7, but not in 8, 139 * undocumented bit 0x200, which is present in table 7, but not in 8,
151 * plus snapshot mode to disable scan for now */ 140 * plus snapshot mode to disable scan for now */
@@ -169,37 +158,19 @@ static int mt9v022_init(struct soc_camera_device *icd)
169 return ret; 158 return ret;
170} 159}
171 160
172static int mt9v022_release(struct soc_camera_device *icd) 161static int mt9v022_s_stream(struct v4l2_subdev *sd, int enable)
173{ 162{
174 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 163 struct i2c_client *client = sd->priv;
175 struct soc_camera_link *icl = to_soc_camera_link(icd); 164 struct mt9v022 *mt9v022 = to_mt9v022(client);
176 165
177 if (icl->power) 166 if (enable)
178 icl->power(&client->dev, 0); 167 /* Switch to master "normal" mode */
179 168 mt9v022->chip_control &= ~0x10;
180 return 0; 169 else
181} 170 /* Switch to snapshot mode */
182 171 mt9v022->chip_control |= 0x10;
183static int mt9v022_start_capture(struct soc_camera_device *icd)
184{
185 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
186 struct mt9v022 *mt9v022 = i2c_get_clientdata(client);
187 /* Switch to master "normal" mode */
188 mt9v022->chip_control &= ~0x10;
189 if (reg_write(client, MT9V022_CHIP_CONTROL,
190 mt9v022->chip_control) < 0)
191 return -EIO;
192 return 0;
193}
194 172
195static int mt9v022_stop_capture(struct soc_camera_device *icd) 173 if (reg_write(client, MT9V022_CHIP_CONTROL, mt9v022->chip_control) < 0)
196{
197 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
198 struct mt9v022 *mt9v022 = i2c_get_clientdata(client);
199 /* Switch to snapshot mode */
200 mt9v022->chip_control |= 0x10;
201 if (reg_write(client, MT9V022_CHIP_CONTROL,
202 mt9v022->chip_control) < 0)
203 return -EIO; 174 return -EIO;
204 return 0; 175 return 0;
205} 176}
@@ -208,7 +179,7 @@ static int mt9v022_set_bus_param(struct soc_camera_device *icd,
208 unsigned long flags) 179 unsigned long flags)
209{ 180{
210 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 181 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
211 struct mt9v022 *mt9v022 = i2c_get_clientdata(client); 182 struct mt9v022 *mt9v022 = to_mt9v022(client);
212 struct soc_camera_link *icl = to_soc_camera_link(icd); 183 struct soc_camera_link *icl = to_soc_camera_link(icd);
213 unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK; 184 unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK;
214 int ret; 185 int ret;
@@ -320,11 +291,11 @@ static int mt9v022_set_crop(struct soc_camera_device *icd,
320 return 0; 291 return 0;
321} 292}
322 293
323static int mt9v022_set_fmt(struct soc_camera_device *icd, 294static int mt9v022_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
324 struct v4l2_format *f)
325{ 295{
326 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 296 struct i2c_client *client = sd->priv;
327 struct mt9v022 *mt9v022 = i2c_get_clientdata(client); 297 struct mt9v022 *mt9v022 = to_mt9v022(client);
298 struct soc_camera_device *icd = client->dev.platform_data;
328 struct v4l2_pix_format *pix = &f->fmt.pix; 299 struct v4l2_pix_format *pix = &f->fmt.pix;
329 struct v4l2_rect rect = { 300 struct v4l2_rect rect = {
330 .left = icd->x_current, 301 .left = icd->x_current,
@@ -357,9 +328,10 @@ static int mt9v022_set_fmt(struct soc_camera_device *icd,
357 return mt9v022_set_crop(icd, &rect); 328 return mt9v022_set_crop(icd, &rect);
358} 329}
359 330
360static int mt9v022_try_fmt(struct soc_camera_device *icd, 331static int mt9v022_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
361 struct v4l2_format *f)
362{ 332{
333 struct i2c_client *client = sd->priv;
334 struct soc_camera_device *icd = client->dev.platform_data;
363 struct v4l2_pix_format *pix = &f->fmt.pix; 335 struct v4l2_pix_format *pix = &f->fmt.pix;
364 336
365 v4l_bound_align_image(&pix->width, 48, 752, 2 /* ? */, 337 v4l_bound_align_image(&pix->width, 48, 752, 2 /* ? */,
@@ -369,11 +341,11 @@ static int mt9v022_try_fmt(struct soc_camera_device *icd,
369 return 0; 341 return 0;
370} 342}
371 343
372static int mt9v022_get_chip_id(struct soc_camera_device *icd, 344static int mt9v022_g_chip_ident(struct v4l2_subdev *sd,
373 struct v4l2_dbg_chip_ident *id) 345 struct v4l2_dbg_chip_ident *id)
374{ 346{
375 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 347 struct i2c_client *client = sd->priv;
376 struct mt9v022 *mt9v022 = i2c_get_clientdata(client); 348 struct mt9v022 *mt9v022 = to_mt9v022(client);
377 349
378 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR) 350 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
379 return -EINVAL; 351 return -EINVAL;
@@ -388,10 +360,10 @@ static int mt9v022_get_chip_id(struct soc_camera_device *icd,
388} 360}
389 361
390#ifdef CONFIG_VIDEO_ADV_DEBUG 362#ifdef CONFIG_VIDEO_ADV_DEBUG
391static int mt9v022_get_register(struct soc_camera_device *icd, 363static int mt9v022_g_register(struct v4l2_subdev *sd,
392 struct v4l2_dbg_register *reg) 364 struct v4l2_dbg_register *reg)
393{ 365{
394 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 366 struct i2c_client *client = sd->priv;
395 367
396 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 368 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
397 return -EINVAL; 369 return -EINVAL;
@@ -408,10 +380,10 @@ static int mt9v022_get_register(struct soc_camera_device *icd,
408 return 0; 380 return 0;
409} 381}
410 382
411static int mt9v022_set_register(struct soc_camera_device *icd, 383static int mt9v022_s_register(struct v4l2_subdev *sd,
412 struct v4l2_dbg_register *reg) 384 struct v4l2_dbg_register *reg)
413{ 385{
414 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 386 struct i2c_client *client = sd->priv;
415 387
416 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 388 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
417 return -EINVAL; 389 return -EINVAL;
@@ -480,35 +452,18 @@ static const struct v4l2_queryctrl mt9v022_controls[] = {
480 } 452 }
481}; 453};
482 454
483static int mt9v022_get_control(struct soc_camera_device *, struct v4l2_control *);
484static int mt9v022_set_control(struct soc_camera_device *, struct v4l2_control *);
485
486static struct soc_camera_ops mt9v022_ops = { 455static struct soc_camera_ops mt9v022_ops = {
487 .owner = THIS_MODULE,
488 .init = mt9v022_init, 456 .init = mt9v022_init,
489 .release = mt9v022_release,
490 .start_capture = mt9v022_start_capture,
491 .stop_capture = mt9v022_stop_capture,
492 .set_crop = mt9v022_set_crop, 457 .set_crop = mt9v022_set_crop,
493 .set_fmt = mt9v022_set_fmt,
494 .try_fmt = mt9v022_try_fmt,
495 .set_bus_param = mt9v022_set_bus_param, 458 .set_bus_param = mt9v022_set_bus_param,
496 .query_bus_param = mt9v022_query_bus_param, 459 .query_bus_param = mt9v022_query_bus_param,
497 .controls = mt9v022_controls, 460 .controls = mt9v022_controls,
498 .num_controls = ARRAY_SIZE(mt9v022_controls), 461 .num_controls = ARRAY_SIZE(mt9v022_controls),
499 .get_control = mt9v022_get_control,
500 .set_control = mt9v022_set_control,
501 .get_chip_id = mt9v022_get_chip_id,
502#ifdef CONFIG_VIDEO_ADV_DEBUG
503 .get_register = mt9v022_get_register,
504 .set_register = mt9v022_set_register,
505#endif
506}; 462};
507 463
508static int mt9v022_get_control(struct soc_camera_device *icd, 464static int mt9v022_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
509 struct v4l2_control *ctrl)
510{ 465{
511 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 466 struct i2c_client *client = sd->priv;
512 int data; 467 int data;
513 468
514 switch (ctrl->id) { 469 switch (ctrl->id) {
@@ -540,15 +495,14 @@ static int mt9v022_get_control(struct soc_camera_device *icd,
540 return 0; 495 return 0;
541} 496}
542 497
543static int mt9v022_set_control(struct soc_camera_device *icd, 498static int mt9v022_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
544 struct v4l2_control *ctrl)
545{ 499{
546 int data; 500 int data;
547 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 501 struct i2c_client *client = sd->priv;
502 struct soc_camera_device *icd = client->dev.platform_data;
548 const struct v4l2_queryctrl *qctrl; 503 const struct v4l2_queryctrl *qctrl;
549 504
550 qctrl = soc_camera_find_qctrl(&mt9v022_ops, ctrl->id); 505 qctrl = soc_camera_find_qctrl(&mt9v022_ops, ctrl->id);
551
552 if (!qctrl) 506 if (!qctrl)
553 return -EINVAL; 507 return -EINVAL;
554 508
@@ -644,7 +598,7 @@ static int mt9v022_set_control(struct soc_camera_device *icd,
644static int mt9v022_video_probe(struct soc_camera_device *icd, 598static int mt9v022_video_probe(struct soc_camera_device *icd,
645 struct i2c_client *client) 599 struct i2c_client *client)
646{ 600{
647 struct mt9v022 *mt9v022 = i2c_get_clientdata(client); 601 struct mt9v022 *mt9v022 = to_mt9v022(client);
648 struct soc_camera_link *icl = to_soc_camera_link(icd); 602 struct soc_camera_link *icl = to_soc_camera_link(icd);
649 s32 data; 603 s32 data;
650 int ret; 604 int ret;
@@ -654,11 +608,6 @@ static int mt9v022_video_probe(struct soc_camera_device *icd,
654 to_soc_camera_host(icd->dev.parent)->nr != icd->iface) 608 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
655 return -ENODEV; 609 return -ENODEV;
656 610
657 /* Switch master clock on */
658 ret = soc_camera_video_start(icd, &client->dev);
659 if (ret)
660 return ret;
661
662 /* Read out the chip version register */ 611 /* Read out the chip version register */
663 data = reg_read(client, MT9V022_CHIP_VERSION); 612 data = reg_read(client, MT9V022_CHIP_VERSION);
664 613
@@ -723,8 +672,6 @@ static int mt9v022_video_probe(struct soc_camera_device *icd,
723 "monochrome" : "colour"); 672 "monochrome" : "colour");
724 673
725ei2c: 674ei2c:
726 soc_camera_video_stop(icd);
727
728 return ret; 675 return ret;
729} 676}
730 677
@@ -739,6 +686,27 @@ static void mt9v022_video_remove(struct soc_camera_device *icd)
739 icl->free_bus(icl); 686 icl->free_bus(icl);
740} 687}
741 688
689static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
690 .g_ctrl = mt9v022_g_ctrl,
691 .s_ctrl = mt9v022_s_ctrl,
692 .g_chip_ident = mt9v022_g_chip_ident,
693#ifdef CONFIG_VIDEO_ADV_DEBUG
694 .g_register = mt9v022_g_register,
695 .s_register = mt9v022_s_register,
696#endif
697};
698
699static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
700 .s_stream = mt9v022_s_stream,
701 .s_fmt = mt9v022_s_fmt,
702 .try_fmt = mt9v022_try_fmt,
703};
704
705static struct v4l2_subdev_ops mt9v022_subdev_ops = {
706 .core = &mt9v022_subdev_core_ops,
707 .video = &mt9v022_subdev_video_ops,
708};
709
742static int mt9v022_probe(struct i2c_client *client, 710static int mt9v022_probe(struct i2c_client *client,
743 const struct i2c_device_id *did) 711 const struct i2c_device_id *did)
744{ 712{
@@ -769,8 +737,9 @@ static int mt9v022_probe(struct i2c_client *client,
769 if (!mt9v022) 737 if (!mt9v022)
770 return -ENOMEM; 738 return -ENOMEM;
771 739
740 v4l2_i2c_subdev_init(&mt9v022->subdev, client, &mt9v022_subdev_ops);
741
772 mt9v022->chip_control = MT9V022_CHIP_CONTROL_DEFAULT; 742 mt9v022->chip_control = MT9V022_CHIP_CONTROL_DEFAULT;
773 i2c_set_clientdata(client, mt9v022);
774 743
775 icd->ops = &mt9v022_ops; 744 icd->ops = &mt9v022_ops;
776 icd->x_min = 1; 745 icd->x_min = 1;
@@ -795,7 +764,7 @@ static int mt9v022_probe(struct i2c_client *client,
795 764
796static int mt9v022_remove(struct i2c_client *client) 765static int mt9v022_remove(struct i2c_client *client)
797{ 766{
798 struct mt9v022 *mt9v022 = i2c_get_clientdata(client); 767 struct mt9v022 *mt9v022 = to_mt9v022(client);
799 struct soc_camera_device *icd = client->dev.platform_data; 768 struct soc_camera_device *icd = client->dev.platform_data;
800 769
801 icd->ops = NULL; 770 icd->ops = NULL;
diff --git a/drivers/media/video/mx1_camera.c b/drivers/media/video/mx1_camera.c
index 736c31d23194..ea4ceaec85fe 100644
--- a/drivers/media/video/mx1_camera.c
+++ b/drivers/media/video/mx1_camera.c
@@ -219,7 +219,7 @@ static int mx1_camera_setup_dma(struct mx1_camera_dev *pcdev)
219 int ret; 219 int ret;
220 220
221 if (unlikely(!pcdev->active)) { 221 if (unlikely(!pcdev->active)) {
222 dev_err(pcdev->soc_host.dev, "DMA End IRQ with no active buffer\n"); 222 dev_err(pcdev->icd->dev.parent, "DMA End IRQ with no active buffer\n");
223 return -EFAULT; 223 return -EFAULT;
224 } 224 }
225 225
@@ -229,7 +229,7 @@ static int mx1_camera_setup_dma(struct mx1_camera_dev *pcdev)
229 vbuf->size, pcdev->res->start + 229 vbuf->size, pcdev->res->start +
230 CSIRXR, DMA_MODE_READ); 230 CSIRXR, DMA_MODE_READ);
231 if (unlikely(ret)) 231 if (unlikely(ret))
232 dev_err(pcdev->soc_host.dev, "Failed to setup DMA sg list\n"); 232 dev_err(pcdev->icd->dev.parent, "Failed to setup DMA sg list\n");
233 233
234 return ret; 234 return ret;
235} 235}
@@ -334,14 +334,14 @@ static void mx1_camera_dma_irq(int channel, void *data)
334 imx_dma_disable(channel); 334 imx_dma_disable(channel);
335 335
336 if (unlikely(!pcdev->active)) { 336 if (unlikely(!pcdev->active)) {
337 dev_err(pcdev->soc_host.dev, "DMA End IRQ with no active buffer\n"); 337 dev_err(pcdev->icd->dev.parent, "DMA End IRQ with no active buffer\n");
338 goto out; 338 goto out;
339 } 339 }
340 340
341 vb = &pcdev->active->vb; 341 vb = &pcdev->active->vb;
342 buf = container_of(vb, struct mx1_buffer, vb); 342 buf = container_of(vb, struct mx1_buffer, vb);
343 WARN_ON(buf->inwork || list_empty(&vb->queue)); 343 WARN_ON(buf->inwork || list_empty(&vb->queue));
344 dev_dbg(pcdev->soc_host.dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, 344 dev_dbg(pcdev->icd->dev.parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
345 vb, vb->baddr, vb->bsize); 345 vb, vb->baddr, vb->bsize);
346 346
347 mx1_camera_wakeup(pcdev, vb, buf); 347 mx1_camera_wakeup(pcdev, vb, buf);
@@ -362,7 +362,7 @@ static void mx1_camera_init_videobuf(struct videobuf_queue *q,
362 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 362 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
363 struct mx1_camera_dev *pcdev = ici->priv; 363 struct mx1_camera_dev *pcdev = ici->priv;
364 364
365 videobuf_queue_dma_contig_init(q, &mx1_videobuf_ops, ici->dev, 365 videobuf_queue_dma_contig_init(q, &mx1_videobuf_ops, icd->dev.parent,
366 &pcdev->lock, 366 &pcdev->lock,
367 V4L2_BUF_TYPE_VIDEO_CAPTURE, 367 V4L2_BUF_TYPE_VIDEO_CAPTURE,
368 V4L2_FIELD_NONE, 368 V4L2_FIELD_NONE,
@@ -381,7 +381,7 @@ static int mclk_get_divisor(struct mx1_camera_dev *pcdev)
381 * they get a nice Oops */ 381 * they get a nice Oops */
382 div = (lcdclk + 2 * mclk - 1) / (2 * mclk) - 1; 382 div = (lcdclk + 2 * mclk - 1) / (2 * mclk) - 1;
383 383
384 dev_dbg(pcdev->soc_host.dev, "System clock %lukHz, target freq %dkHz, " 384 dev_dbg(pcdev->icd->dev.parent, "System clock %lukHz, target freq %dkHz, "
385 "divisor %lu\n", lcdclk / 1000, mclk / 1000, div); 385 "divisor %lu\n", lcdclk / 1000, mclk / 1000, div);
386 386
387 return div; 387 return div;
@@ -391,7 +391,7 @@ static void mx1_camera_activate(struct mx1_camera_dev *pcdev)
391{ 391{
392 unsigned int csicr1 = CSICR1_EN; 392 unsigned int csicr1 = CSICR1_EN;
393 393
394 dev_dbg(pcdev->soc_host.dev, "Activate device\n"); 394 dev_dbg(pcdev->icd->dev.parent, "Activate device\n");
395 395
396 clk_enable(pcdev->clk); 396 clk_enable(pcdev->clk);
397 397
@@ -407,7 +407,7 @@ static void mx1_camera_activate(struct mx1_camera_dev *pcdev)
407 407
408static void mx1_camera_deactivate(struct mx1_camera_dev *pcdev) 408static void mx1_camera_deactivate(struct mx1_camera_dev *pcdev)
409{ 409{
410 dev_dbg(pcdev->soc_host.dev, "Deactivate device\n"); 410 dev_dbg(pcdev->icd->dev.parent, "Deactivate device\n");
411 411
412 /* Disable all CSI interface */ 412 /* Disable all CSI interface */
413 __raw_writel(0x00, pcdev->base + CSICR1); 413 __raw_writel(0x00, pcdev->base + CSICR1);
@@ -432,10 +432,8 @@ static int mx1_camera_add_device(struct soc_camera_device *icd)
432 icd->devnum); 432 icd->devnum);
433 433
434 mx1_camera_activate(pcdev); 434 mx1_camera_activate(pcdev);
435 ret = icd->ops->init(icd);
436 435
437 if (!ret) 436 pcdev->icd = icd;
438 pcdev->icd = icd;
439 437
440ebusy: 438ebusy:
441 return ret; 439 return ret;
@@ -459,8 +457,6 @@ static void mx1_camera_remove_device(struct soc_camera_device *icd)
459 dev_info(&icd->dev, "MX1 Camera driver detached from camera %d\n", 457 dev_info(&icd->dev, "MX1 Camera driver detached from camera %d\n",
460 icd->devnum); 458 icd->devnum);
461 459
462 icd->ops->release(icd);
463
464 mx1_camera_deactivate(pcdev); 460 mx1_camera_deactivate(pcdev);
465 461
466 pcdev->icd = NULL; 462 pcdev->icd = NULL;
@@ -546,11 +542,11 @@ static int mx1_camera_set_fmt(struct soc_camera_device *icd,
546 542
547 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); 543 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
548 if (!xlate) { 544 if (!xlate) {
549 dev_warn(ici->dev, "Format %x not found\n", pix->pixelformat); 545 dev_warn(icd->dev.parent, "Format %x not found\n", pix->pixelformat);
550 return -EINVAL; 546 return -EINVAL;
551 } 547 }
552 548
553 ret = icd->ops->set_fmt(icd, f); 549 ret = v4l2_device_call_until_err(&ici->v4l2_dev, 0, video, s_fmt, f);
554 if (!ret) { 550 if (!ret) {
555 icd->buswidth = xlate->buswidth; 551 icd->buswidth = xlate->buswidth;
556 icd->current_fmt = xlate->host_fmt; 552 icd->current_fmt = xlate->host_fmt;
@@ -562,10 +558,11 @@ static int mx1_camera_set_fmt(struct soc_camera_device *icd,
562static int mx1_camera_try_fmt(struct soc_camera_device *icd, 558static int mx1_camera_try_fmt(struct soc_camera_device *icd,
563 struct v4l2_format *f) 559 struct v4l2_format *f)
564{ 560{
561 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
565 /* TODO: limit to mx1 hardware capabilities */ 562 /* TODO: limit to mx1 hardware capabilities */
566 563
567 /* limit to sensor capabilities */ 564 /* limit to sensor capabilities */
568 return icd->ops->try_fmt(icd, f); 565 return v4l2_device_call_until_err(&ici->v4l2_dev, 0, video, try_fmt, f);
569} 566}
570 567
571static int mx1_camera_reqbufs(struct soc_camera_file *icf, 568static int mx1_camera_reqbufs(struct soc_camera_file *icf,
@@ -737,7 +734,7 @@ static int __init mx1_camera_probe(struct platform_device *pdev)
737 pcdev->soc_host.drv_name = DRIVER_NAME; 734 pcdev->soc_host.drv_name = DRIVER_NAME;
738 pcdev->soc_host.ops = &mx1_soc_camera_host_ops; 735 pcdev->soc_host.ops = &mx1_soc_camera_host_ops;
739 pcdev->soc_host.priv = pcdev; 736 pcdev->soc_host.priv = pcdev;
740 pcdev->soc_host.dev = &pdev->dev; 737 pcdev->soc_host.v4l2_dev.dev = &pdev->dev;
741 pcdev->soc_host.nr = pdev->id; 738 pcdev->soc_host.nr = pdev->id;
742 err = soc_camera_host_register(&pcdev->soc_host); 739 err = soc_camera_host_register(&pcdev->soc_host);
743 if (err) 740 if (err)
diff --git a/drivers/media/video/mx3_camera.c b/drivers/media/video/mx3_camera.c
index 2edf77a6256b..677d355be8fc 100644
--- a/drivers/media/video/mx3_camera.c
+++ b/drivers/media/video/mx3_camera.c
@@ -431,7 +431,7 @@ static void mx3_camera_init_videobuf(struct videobuf_queue *q,
431 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 431 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
432 struct mx3_camera_dev *mx3_cam = ici->priv; 432 struct mx3_camera_dev *mx3_cam = ici->priv;
433 433
434 videobuf_queue_dma_contig_init(q, &mx3_videobuf_ops, ici->dev, 434 videobuf_queue_dma_contig_init(q, &mx3_videobuf_ops, icd->dev.parent,
435 &mx3_cam->lock, 435 &mx3_cam->lock,
436 V4L2_BUF_TYPE_VIDEO_CAPTURE, 436 V4L2_BUF_TYPE_VIDEO_CAPTURE,
437 V4L2_FIELD_NONE, 437 V4L2_FIELD_NONE,
@@ -494,17 +494,11 @@ static int mx3_camera_add_device(struct soc_camera_device *icd)
494{ 494{
495 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 495 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
496 struct mx3_camera_dev *mx3_cam = ici->priv; 496 struct mx3_camera_dev *mx3_cam = ici->priv;
497 int ret;
498 497
499 if (mx3_cam->icd) { 498 if (mx3_cam->icd)
500 ret = -EBUSY; 499 return -EBUSY;
501 goto ebusy;
502 }
503 500
504 mx3_camera_activate(mx3_cam, icd); 501 mx3_camera_activate(mx3_cam, icd);
505 ret = icd->ops->init(icd);
506 if (ret < 0)
507 goto einit;
508 502
509 mx3_cam->icd = icd; 503 mx3_cam->icd = icd;
510 504
@@ -512,12 +506,6 @@ static int mx3_camera_add_device(struct soc_camera_device *icd)
512 icd->devnum); 506 icd->devnum);
513 507
514 return 0; 508 return 0;
515
516einit:
517 clk_disable(mx3_cam->clk);
518ebusy:
519
520 return ret;
521} 509}
522 510
523/* Called with .video_lock held */ 511/* Called with .video_lock held */
@@ -534,8 +522,6 @@ static void mx3_camera_remove_device(struct soc_camera_device *icd)
534 *ichan = NULL; 522 *ichan = NULL;
535 } 523 }
536 524
537 icd->ops->release(icd);
538
539 clk_disable(mx3_cam->clk); 525 clk_disable(mx3_cam->clk);
540 526
541 mx3_cam->icd = NULL; 527 mx3_cam->icd = NULL;
@@ -600,7 +586,7 @@ static int test_platform_param(struct mx3_camera_dev *mx3_cam,
600 *flags |= SOCAM_DATAWIDTH_4; 586 *flags |= SOCAM_DATAWIDTH_4;
601 break; 587 break;
602 default: 588 default:
603 dev_info(mx3_cam->soc_host.dev, "Unsupported bus width %d\n", 589 dev_info(mx3_cam->soc_host.v4l2_dev.dev, "Unsupported bus width %d\n",
604 buswidth); 590 buswidth);
605 return -EINVAL; 591 return -EINVAL;
606 } 592 }
@@ -616,7 +602,7 @@ static int mx3_camera_try_bus_param(struct soc_camera_device *icd,
616 unsigned long bus_flags, camera_flags; 602 unsigned long bus_flags, camera_flags;
617 int ret = test_platform_param(mx3_cam, depth, &bus_flags); 603 int ret = test_platform_param(mx3_cam, depth, &bus_flags);
618 604
619 dev_dbg(ici->dev, "requested bus width %d bit: %d\n", depth, ret); 605 dev_dbg(icd->dev.parent, "requested bus width %d bit: %d\n", depth, ret);
620 606
621 if (ret < 0) 607 if (ret < 0)
622 return ret; 608 return ret;
@@ -639,7 +625,7 @@ static bool chan_filter(struct dma_chan *chan, void *arg)
639 if (!rq) 625 if (!rq)
640 return false; 626 return false;
641 627
642 pdata = rq->mx3_cam->soc_host.dev->platform_data; 628 pdata = rq->mx3_cam->soc_host.v4l2_dev.dev->platform_data;
643 629
644 return rq->id == chan->chan_id && 630 return rq->id == chan->chan_id &&
645 pdata->dma_dev == chan->device->dev; 631 pdata->dma_dev == chan->device->dev;
@@ -699,7 +685,7 @@ static int mx3_camera_get_formats(struct soc_camera_device *icd, int idx,
699 xlate->cam_fmt = icd->formats + idx; 685 xlate->cam_fmt = icd->formats + idx;
700 xlate->buswidth = buswidth; 686 xlate->buswidth = buswidth;
701 xlate++; 687 xlate++;
702 dev_dbg(ici->dev, "Providing format %s using %s\n", 688 dev_dbg(icd->dev.parent, "Providing format %s using %s\n",
703 mx3_camera_formats[0].name, 689 mx3_camera_formats[0].name,
704 icd->formats[idx].name); 690 icd->formats[idx].name);
705 } 691 }
@@ -711,7 +697,7 @@ static int mx3_camera_get_formats(struct soc_camera_device *icd, int idx,
711 xlate->cam_fmt = icd->formats + idx; 697 xlate->cam_fmt = icd->formats + idx;
712 xlate->buswidth = buswidth; 698 xlate->buswidth = buswidth;
713 xlate++; 699 xlate++;
714 dev_dbg(ici->dev, "Providing format %s using %s\n", 700 dev_dbg(icd->dev.parent, "Providing format %s using %s\n",
715 mx3_camera_formats[0].name, 701 mx3_camera_formats[0].name,
716 icd->formats[idx].name); 702 icd->formats[idx].name);
717 } 703 }
@@ -724,7 +710,7 @@ passthrough:
724 xlate->cam_fmt = icd->formats + idx; 710 xlate->cam_fmt = icd->formats + idx;
725 xlate->buswidth = buswidth; 711 xlate->buswidth = buswidth;
726 xlate++; 712 xlate++;
727 dev_dbg(ici->dev, 713 dev_dbg(icd->dev.parent,
728 "Providing format %s in pass-through mode\n", 714 "Providing format %s in pass-through mode\n",
729 icd->formats[idx].name); 715 icd->formats[idx].name);
730 } 716 }
@@ -831,7 +817,7 @@ static int mx3_camera_set_fmt(struct soc_camera_device *icd,
831 817
832 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); 818 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
833 if (!xlate) { 819 if (!xlate) {
834 dev_warn(ici->dev, "Format %x not found\n", pix->pixelformat); 820 dev_warn(icd->dev.parent, "Format %x not found\n", pix->pixelformat);
835 return -EINVAL; 821 return -EINVAL;
836 } 822 }
837 823
@@ -847,7 +833,7 @@ static int mx3_camera_set_fmt(struct soc_camera_device *icd,
847 833
848 configure_geometry(mx3_cam, &rect); 834 configure_geometry(mx3_cam, &rect);
849 835
850 ret = icd->ops->set_fmt(icd, f); 836 ret = v4l2_device_call_until_err(&ici->v4l2_dev, 0, video, s_fmt, f);
851 if (!ret) { 837 if (!ret) {
852 icd->buswidth = xlate->buswidth; 838 icd->buswidth = xlate->buswidth;
853 icd->current_fmt = xlate->host_fmt; 839 icd->current_fmt = xlate->host_fmt;
@@ -868,7 +854,7 @@ static int mx3_camera_try_fmt(struct soc_camera_device *icd,
868 854
869 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); 855 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
870 if (pixfmt && !xlate) { 856 if (pixfmt && !xlate) {
871 dev_warn(ici->dev, "Format %x not found\n", pixfmt); 857 dev_warn(icd->dev.parent, "Format %x not found\n", pixfmt);
872 return -EINVAL; 858 return -EINVAL;
873 } 859 }
874 860
@@ -885,7 +871,7 @@ static int mx3_camera_try_fmt(struct soc_camera_device *icd,
885 /* camera has to see its format, but the user the original one */ 871 /* camera has to see its format, but the user the original one */
886 pix->pixelformat = xlate->cam_fmt->fourcc; 872 pix->pixelformat = xlate->cam_fmt->fourcc;
887 /* limit to sensor capabilities */ 873 /* limit to sensor capabilities */
888 ret = icd->ops->try_fmt(icd, f); 874 ret = v4l2_device_call_until_err(&ici->v4l2_dev, 0, video, try_fmt, f);
889 pix->pixelformat = xlate->host_fmt->fourcc; 875 pix->pixelformat = xlate->host_fmt->fourcc;
890 876
891 field = pix->field; 877 field = pix->field;
@@ -935,11 +921,11 @@ static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
935 921
936 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); 922 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
937 if (!xlate) { 923 if (!xlate) {
938 dev_warn(ici->dev, "Format %x not found\n", pixfmt); 924 dev_warn(icd->dev.parent, "Format %x not found\n", pixfmt);
939 return -EINVAL; 925 return -EINVAL;
940 } 926 }
941 927
942 dev_dbg(ici->dev, "requested bus width %d bit: %d\n", 928 dev_dbg(icd->dev.parent, "requested bus width %d bit: %d\n",
943 icd->buswidth, ret); 929 icd->buswidth, ret);
944 930
945 if (ret < 0) 931 if (ret < 0)
@@ -948,10 +934,10 @@ static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
948 camera_flags = icd->ops->query_bus_param(icd); 934 camera_flags = icd->ops->query_bus_param(icd);
949 935
950 common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags); 936 common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags);
951 dev_dbg(ici->dev, "Flags cam: 0x%lx host: 0x%lx common: 0x%lx\n", 937 dev_dbg(icd->dev.parent, "Flags cam: 0x%lx host: 0x%lx common: 0x%lx\n",
952 camera_flags, bus_flags, common_flags); 938 camera_flags, bus_flags, common_flags);
953 if (!common_flags) { 939 if (!common_flags) {
954 dev_dbg(ici->dev, "no common flags"); 940 dev_dbg(icd->dev.parent, "no common flags");
955 return -EINVAL; 941 return -EINVAL;
956 } 942 }
957 943
@@ -1005,7 +991,7 @@ static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
1005 991
1006 ret = icd->ops->set_bus_param(icd, common_flags); 992 ret = icd->ops->set_bus_param(icd, common_flags);
1007 if (ret < 0) { 993 if (ret < 0) {
1008 dev_dbg(ici->dev, "camera set_bus_param(%lx) returned %d\n", 994 dev_dbg(icd->dev.parent, "camera set_bus_param(%lx) returned %d\n",
1009 common_flags, ret); 995 common_flags, ret);
1010 return ret; 996 return ret;
1011 } 997 }
@@ -1060,7 +1046,7 @@ static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
1060 1046
1061 csi_reg_write(mx3_cam, sens_conf | dw, CSI_SENS_CONF); 1047 csi_reg_write(mx3_cam, sens_conf | dw, CSI_SENS_CONF);
1062 1048
1063 dev_dbg(ici->dev, "Set SENS_CONF to %x\n", sens_conf | dw); 1049 dev_dbg(icd->dev.parent, "Set SENS_CONF to %x\n", sens_conf | dw);
1064 1050
1065 return 0; 1051 return 0;
1066} 1052}
@@ -1145,7 +1131,7 @@ static int __devinit mx3_camera_probe(struct platform_device *pdev)
1145 soc_host->drv_name = MX3_CAM_DRV_NAME; 1131 soc_host->drv_name = MX3_CAM_DRV_NAME;
1146 soc_host->ops = &mx3_soc_camera_host_ops; 1132 soc_host->ops = &mx3_soc_camera_host_ops;
1147 soc_host->priv = mx3_cam; 1133 soc_host->priv = mx3_cam;
1148 soc_host->dev = &pdev->dev; 1134 soc_host->v4l2_dev.dev = &pdev->dev;
1149 soc_host->nr = pdev->id; 1135 soc_host->nr = pdev->id;
1150 1136
1151 err = soc_camera_host_register(soc_host); 1137 err = soc_camera_host_register(soc_host);
diff --git a/drivers/media/video/ov772x.c b/drivers/media/video/ov772x.c
index 3ea650d55b17..119159773a68 100644
--- a/drivers/media/video/ov772x.c
+++ b/drivers/media/video/ov772x.c
@@ -22,7 +22,7 @@
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/videodev2.h> 23#include <linux/videodev2.h>
24#include <media/v4l2-chip-ident.h> 24#include <media/v4l2-chip-ident.h>
25#include <media/v4l2-common.h> 25#include <media/v4l2-subdev.h>
26#include <media/soc_camera.h> 26#include <media/soc_camera.h>
27#include <media/ov772x.h> 27#include <media/ov772x.h>
28 28
@@ -398,6 +398,7 @@ struct ov772x_win_size {
398}; 398};
399 399
400struct ov772x_priv { 400struct ov772x_priv {
401 struct v4l2_subdev subdev;
401 struct ov772x_camera_info *info; 402 struct ov772x_camera_info *info;
402 const struct ov772x_color_format *fmt; 403 const struct ov772x_color_format *fmt;
403 const struct ov772x_win_size *win; 404 const struct ov772x_win_size *win;
@@ -575,6 +576,11 @@ static const struct v4l2_queryctrl ov772x_controls[] = {
575 * general function 576 * general function
576 */ 577 */
577 578
579static struct ov772x_priv *to_ov772x(const struct i2c_client *client)
580{
581 return container_of(i2c_get_clientdata(client), struct ov772x_priv, subdev);
582}
583
578static int ov772x_write_array(struct i2c_client *client, 584static int ov772x_write_array(struct i2c_client *client,
579 const struct regval_list *vals) 585 const struct regval_list *vals)
580{ 586{
@@ -615,61 +621,29 @@ static int ov772x_reset(struct i2c_client *client)
615 * soc_camera_ops function 621 * soc_camera_ops function
616 */ 622 */
617 623
618static int ov772x_init(struct soc_camera_device *icd) 624static int ov772x_s_stream(struct v4l2_subdev *sd, int enable)
619{ 625{
620 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 626 struct i2c_client *client = sd->priv;
621 struct soc_camera_link *icl = to_soc_camera_link(icd); 627 struct ov772x_priv *priv = to_ov772x(client);
622 int ret = 0;
623 628
624 if (icl->power) { 629 if (!enable) {
625 ret = icl->power(&client->dev, 1); 630 ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, SOFT_SLEEP_MODE);
626 if (ret < 0) 631 return 0;
627 return ret;
628 } 632 }
629 633
630 if (icl->reset)
631 ret = icl->reset(&client->dev);
632
633 return ret;
634}
635
636static int ov772x_release(struct soc_camera_device *icd)
637{
638 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
639 struct soc_camera_link *icl = to_soc_camera_link(icd);
640 int ret = 0;
641
642 if (icl->power)
643 ret = icl->power(&client->dev, 0);
644
645 return ret;
646}
647
648static int ov772x_start_capture(struct soc_camera_device *icd)
649{
650 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
651 struct ov772x_priv *priv = i2c_get_clientdata(client);
652
653 if (!priv->win || !priv->fmt) { 634 if (!priv->win || !priv->fmt) {
654 dev_err(&icd->dev, "norm or win select error\n"); 635 dev_err(&client->dev, "norm or win select error\n");
655 return -EPERM; 636 return -EPERM;
656 } 637 }
657 638
658 ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, 0); 639 ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, 0);
659 640
660 dev_dbg(&icd->dev, 641 dev_dbg(&client->dev,
661 "format %s, win %s\n", priv->fmt->name, priv->win->name); 642 "format %s, win %s\n", priv->fmt->name, priv->win->name);
662 643
663 return 0; 644 return 0;
664} 645}
665 646
666static int ov772x_stop_capture(struct soc_camera_device *icd)
667{
668 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
669 ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, SOFT_SLEEP_MODE);
670 return 0;
671}
672
673static int ov772x_set_bus_param(struct soc_camera_device *icd, 647static int ov772x_set_bus_param(struct soc_camera_device *icd,
674 unsigned long flags) 648 unsigned long flags)
675{ 649{
@@ -688,11 +662,10 @@ static unsigned long ov772x_query_bus_param(struct soc_camera_device *icd)
688 return soc_camera_apply_sensor_flags(icl, flags); 662 return soc_camera_apply_sensor_flags(icl, flags);
689} 663}
690 664
691static int ov772x_get_control(struct soc_camera_device *icd, 665static int ov772x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
692 struct v4l2_control *ctrl)
693{ 666{
694 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 667 struct i2c_client *client = sd->priv;
695 struct ov772x_priv *priv = i2c_get_clientdata(client); 668 struct ov772x_priv *priv = to_ov772x(client);
696 669
697 switch (ctrl->id) { 670 switch (ctrl->id) {
698 case V4L2_CID_VFLIP: 671 case V4L2_CID_VFLIP:
@@ -705,11 +678,10 @@ static int ov772x_get_control(struct soc_camera_device *icd,
705 return 0; 678 return 0;
706} 679}
707 680
708static int ov772x_set_control(struct soc_camera_device *icd, 681static int ov772x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
709 struct v4l2_control *ctrl)
710{ 682{
711 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 683 struct i2c_client *client = sd->priv;
712 struct ov772x_priv *priv = i2c_get_clientdata(client); 684 struct ov772x_priv *priv = to_ov772x(client);
713 int ret = 0; 685 int ret = 0;
714 u8 val; 686 u8 val;
715 687
@@ -733,11 +705,11 @@ static int ov772x_set_control(struct soc_camera_device *icd,
733 return ret; 705 return ret;
734} 706}
735 707
736static int ov772x_get_chip_id(struct soc_camera_device *icd, 708static int ov772x_g_chip_ident(struct v4l2_subdev *sd,
737 struct v4l2_dbg_chip_ident *id) 709 struct v4l2_dbg_chip_ident *id)
738{ 710{
739 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 711 struct i2c_client *client = sd->priv;
740 struct ov772x_priv *priv = i2c_get_clientdata(client); 712 struct ov772x_priv *priv = to_ov772x(client);
741 713
742 id->ident = priv->model; 714 id->ident = priv->model;
743 id->revision = 0; 715 id->revision = 0;
@@ -746,10 +718,10 @@ static int ov772x_get_chip_id(struct soc_camera_device *icd,
746} 718}
747 719
748#ifdef CONFIG_VIDEO_ADV_DEBUG 720#ifdef CONFIG_VIDEO_ADV_DEBUG
749static int ov772x_get_register(struct soc_camera_device *icd, 721static int ov772x_g_register(struct v4l2_subdev *sd,
750 struct v4l2_dbg_register *reg) 722 struct v4l2_dbg_register *reg)
751{ 723{
752 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 724 struct i2c_client *client = sd->priv;
753 int ret; 725 int ret;
754 726
755 reg->size = 1; 727 reg->size = 1;
@@ -765,10 +737,10 @@ static int ov772x_get_register(struct soc_camera_device *icd,
765 return 0; 737 return 0;
766} 738}
767 739
768static int ov772x_set_register(struct soc_camera_device *icd, 740static int ov772x_s_register(struct v4l2_subdev *sd,
769 struct v4l2_dbg_register *reg) 741 struct v4l2_dbg_register *reg)
770{ 742{
771 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 743 struct i2c_client *client = sd->priv;
772 744
773 if (reg->reg > 0xff || 745 if (reg->reg > 0xff ||
774 reg->val > 0xff) 746 reg->val > 0xff)
@@ -778,8 +750,7 @@ static int ov772x_set_register(struct soc_camera_device *icd,
778} 750}
779#endif 751#endif
780 752
781static const struct ov772x_win_size* 753static const struct ov772x_win_size *ov772x_select_win(u32 width, u32 height)
782ov772x_select_win(u32 width, u32 height)
783{ 754{
784 __u32 diff; 755 __u32 diff;
785 const struct ov772x_win_size *win; 756 const struct ov772x_win_size *win;
@@ -798,11 +769,10 @@ ov772x_select_win(u32 width, u32 height)
798 return win; 769 return win;
799} 770}
800 771
801static int ov772x_set_params(struct soc_camera_device *icd, 772static int ov772x_set_params(struct i2c_client *client,
802 u32 width, u32 height, u32 pixfmt) 773 u32 width, u32 height, u32 pixfmt)
803{ 774{
804 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 775 struct ov772x_priv *priv = to_ov772x(client);
805 struct ov772x_priv *priv = i2c_get_clientdata(client);
806 int ret = -EINVAL; 776 int ret = -EINVAL;
807 u8 val; 777 u8 val;
808 int i; 778 int i;
@@ -817,7 +787,6 @@ static int ov772x_set_params(struct soc_camera_device *icd,
817 break; 787 break;
818 } 788 }
819 } 789 }
820 dev_dbg(&icd->dev, "Using fmt %x #%d\n", pixfmt, i);
821 if (!priv->fmt) 790 if (!priv->fmt)
822 goto ov772x_set_fmt_error; 791 goto ov772x_set_fmt_error;
823 792
@@ -939,26 +908,26 @@ static int ov772x_set_crop(struct soc_camera_device *icd,
939 struct v4l2_rect *rect) 908 struct v4l2_rect *rect)
940{ 909{
941 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 910 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
942 struct ov772x_priv *priv = i2c_get_clientdata(client); 911 struct ov772x_priv *priv = to_ov772x(client);
943 912
944 if (!priv->fmt) 913 if (!priv->fmt)
945 return -EINVAL; 914 return -EINVAL;
946 915
947 return ov772x_set_params(icd, rect->width, rect->height, 916 return ov772x_set_params(client, rect->width, rect->height,
948 priv->fmt->fourcc); 917 priv->fmt->fourcc);
949} 918}
950 919
951static int ov772x_set_fmt(struct soc_camera_device *icd, 920static int ov772x_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
952 struct v4l2_format *f)
953{ 921{
922 struct i2c_client *client = sd->priv;
954 struct v4l2_pix_format *pix = &f->fmt.pix; 923 struct v4l2_pix_format *pix = &f->fmt.pix;
955 924
956 return ov772x_set_params(icd, pix->width, pix->height, 925 return ov772x_set_params(client, pix->width, pix->height,
957 pix->pixelformat); 926 pix->pixelformat);
958} 927}
959 928
960static int ov772x_try_fmt(struct soc_camera_device *icd, 929static int ov772x_try_fmt(struct v4l2_subdev *sd,
961 struct v4l2_format *f) 930 struct v4l2_format *f)
962{ 931{
963 struct v4l2_pix_format *pix = &f->fmt.pix; 932 struct v4l2_pix_format *pix = &f->fmt.pix;
964 const struct ov772x_win_size *win; 933 const struct ov772x_win_size *win;
@@ -978,10 +947,9 @@ static int ov772x_try_fmt(struct soc_camera_device *icd,
978static int ov772x_video_probe(struct soc_camera_device *icd, 947static int ov772x_video_probe(struct soc_camera_device *icd,
979 struct i2c_client *client) 948 struct i2c_client *client)
980{ 949{
981 struct ov772x_priv *priv = i2c_get_clientdata(client); 950 struct ov772x_priv *priv = to_ov772x(client);
982 u8 pid, ver; 951 u8 pid, ver;
983 const char *devname; 952 const char *devname;
984 int ret;
985 953
986 /* 954 /*
987 * We must have a parent by now. And it cannot be a wrong one. 955 * We must have a parent by now. And it cannot be a wrong one.
@@ -1003,11 +971,6 @@ static int ov772x_video_probe(struct soc_camera_device *icd,
1003 icd->formats = ov772x_fmt_lists; 971 icd->formats = ov772x_fmt_lists;
1004 icd->num_formats = ARRAY_SIZE(ov772x_fmt_lists); 972 icd->num_formats = ARRAY_SIZE(ov772x_fmt_lists);
1005 973
1006 /* Switch master clock on */
1007 ret = soc_camera_video_start(icd, &client->dev);
1008 if (ret)
1009 return ret;
1010
1011 /* 974 /*
1012 * check and show product ID and manufacturer ID 975 * check and show product ID and manufacturer ID
1013 */ 976 */
@@ -1026,8 +989,7 @@ static int ov772x_video_probe(struct soc_camera_device *icd,
1026 default: 989 default:
1027 dev_err(&icd->dev, 990 dev_err(&icd->dev,
1028 "Product ID error %x:%x\n", pid, ver); 991 "Product ID error %x:%x\n", pid, ver);
1029 ret = -ENODEV; 992 return -ENODEV;
1030 goto ever;
1031 } 993 }
1032 994
1033 dev_info(&icd->dev, 995 dev_info(&icd->dev,
@@ -1038,34 +1000,38 @@ static int ov772x_video_probe(struct soc_camera_device *icd,
1038 i2c_smbus_read_byte_data(client, MIDH), 1000 i2c_smbus_read_byte_data(client, MIDH),
1039 i2c_smbus_read_byte_data(client, MIDL)); 1001 i2c_smbus_read_byte_data(client, MIDL));
1040 1002
1041 soc_camera_video_stop(icd); 1003 return 0;
1042
1043ever:
1044 return ret;
1045} 1004}
1046 1005
1047static struct soc_camera_ops ov772x_ops = { 1006static struct soc_camera_ops ov772x_ops = {
1048 .owner = THIS_MODULE,
1049 .init = ov772x_init,
1050 .release = ov772x_release,
1051 .start_capture = ov772x_start_capture,
1052 .stop_capture = ov772x_stop_capture,
1053 .set_crop = ov772x_set_crop, 1007 .set_crop = ov772x_set_crop,
1054 .set_fmt = ov772x_set_fmt,
1055 .try_fmt = ov772x_try_fmt,
1056 .set_bus_param = ov772x_set_bus_param, 1008 .set_bus_param = ov772x_set_bus_param,
1057 .query_bus_param = ov772x_query_bus_param, 1009 .query_bus_param = ov772x_query_bus_param,
1058 .controls = ov772x_controls, 1010 .controls = ov772x_controls,
1059 .num_controls = ARRAY_SIZE(ov772x_controls), 1011 .num_controls = ARRAY_SIZE(ov772x_controls),
1060 .get_control = ov772x_get_control, 1012};
1061 .set_control = ov772x_set_control, 1013
1062 .get_chip_id = ov772x_get_chip_id, 1014static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
1015 .g_ctrl = ov772x_g_ctrl,
1016 .s_ctrl = ov772x_s_ctrl,
1017 .g_chip_ident = ov772x_g_chip_ident,
1063#ifdef CONFIG_VIDEO_ADV_DEBUG 1018#ifdef CONFIG_VIDEO_ADV_DEBUG
1064 .get_register = ov772x_get_register, 1019 .g_register = ov772x_g_register,
1065 .set_register = ov772x_set_register, 1020 .s_register = ov772x_s_register,
1066#endif 1021#endif
1067}; 1022};
1068 1023
1024static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
1025 .s_stream = ov772x_s_stream,
1026 .s_fmt = ov772x_s_fmt,
1027 .try_fmt = ov772x_try_fmt,
1028};
1029
1030static struct v4l2_subdev_ops ov772x_subdev_ops = {
1031 .core = &ov772x_subdev_core_ops,
1032 .video = &ov772x_subdev_video_ops,
1033};
1034
1069/* 1035/*
1070 * i2c_driver function 1036 * i2c_driver function
1071 */ 1037 */
@@ -1081,7 +1047,7 @@ static int ov772x_probe(struct i2c_client *client,
1081 int ret; 1047 int ret;
1082 1048
1083 if (!icd) { 1049 if (!icd) {
1084 dev_err(&client->dev, "MT9M001: missing soc-camera data!\n"); 1050 dev_err(&client->dev, "OV772X: missing soc-camera data!\n");
1085 return -EINVAL; 1051 return -EINVAL;
1086 } 1052 }
1087 1053
@@ -1102,8 +1068,9 @@ static int ov772x_probe(struct i2c_client *client,
1102 if (!priv) 1068 if (!priv)
1103 return -ENOMEM; 1069 return -ENOMEM;
1104 1070
1105 priv->info = info; 1071 priv->info = info;
1106 i2c_set_clientdata(client, priv); 1072
1073 v4l2_i2c_subdev_init(&priv->subdev, client, &ov772x_subdev_ops);
1107 1074
1108 icd->ops = &ov772x_ops; 1075 icd->ops = &ov772x_ops;
1109 icd->width_max = MAX_WIDTH; 1076 icd->width_max = MAX_WIDTH;
@@ -1121,7 +1088,7 @@ static int ov772x_probe(struct i2c_client *client,
1121 1088
1122static int ov772x_remove(struct i2c_client *client) 1089static int ov772x_remove(struct i2c_client *client)
1123{ 1090{
1124 struct ov772x_priv *priv = i2c_get_clientdata(client); 1091 struct ov772x_priv *priv = to_ov772x(client);
1125 struct soc_camera_device *icd = client->dev.platform_data; 1092 struct soc_camera_device *icd = client->dev.platform_data;
1126 1093
1127 icd->ops = NULL; 1094 icd->ops = NULL;
diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c
index 8b9b44d86837..bdc0d85c461b 100644
--- a/drivers/media/video/pxa_camera.c
+++ b/drivers/media/video/pxa_camera.c
@@ -270,7 +270,7 @@ static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf)
270 270
271 for (i = 0; i < ARRAY_SIZE(buf->dmas); i++) { 271 for (i = 0; i < ARRAY_SIZE(buf->dmas); i++) {
272 if (buf->dmas[i].sg_cpu) 272 if (buf->dmas[i].sg_cpu)
273 dma_free_coherent(ici->dev, buf->dmas[i].sg_size, 273 dma_free_coherent(ici->v4l2_dev.dev, buf->dmas[i].sg_size,
274 buf->dmas[i].sg_cpu, 274 buf->dmas[i].sg_cpu,
275 buf->dmas[i].sg_dma); 275 buf->dmas[i].sg_dma);
276 buf->dmas[i].sg_cpu = NULL; 276 buf->dmas[i].sg_cpu = NULL;
@@ -325,19 +325,20 @@ static int pxa_init_dma_channel(struct pxa_camera_dev *pcdev,
325 struct scatterlist **sg_first, int *sg_first_ofs) 325 struct scatterlist **sg_first, int *sg_first_ofs)
326{ 326{
327 struct pxa_cam_dma *pxa_dma = &buf->dmas[channel]; 327 struct pxa_cam_dma *pxa_dma = &buf->dmas[channel];
328 struct device *dev = pcdev->soc_host.v4l2_dev.dev;
328 struct scatterlist *sg; 329 struct scatterlist *sg;
329 int i, offset, sglen; 330 int i, offset, sglen;
330 int dma_len = 0, xfer_len = 0; 331 int dma_len = 0, xfer_len = 0;
331 332
332 if (pxa_dma->sg_cpu) 333 if (pxa_dma->sg_cpu)
333 dma_free_coherent(pcdev->soc_host.dev, pxa_dma->sg_size, 334 dma_free_coherent(dev, pxa_dma->sg_size,
334 pxa_dma->sg_cpu, pxa_dma->sg_dma); 335 pxa_dma->sg_cpu, pxa_dma->sg_dma);
335 336
336 sglen = calculate_dma_sglen(*sg_first, dma->sglen, 337 sglen = calculate_dma_sglen(*sg_first, dma->sglen,
337 *sg_first_ofs, size); 338 *sg_first_ofs, size);
338 339
339 pxa_dma->sg_size = (sglen + 1) * sizeof(struct pxa_dma_desc); 340 pxa_dma->sg_size = (sglen + 1) * sizeof(struct pxa_dma_desc);
340 pxa_dma->sg_cpu = dma_alloc_coherent(pcdev->soc_host.dev, pxa_dma->sg_size, 341 pxa_dma->sg_cpu = dma_alloc_coherent(dev, pxa_dma->sg_size,
341 &pxa_dma->sg_dma, GFP_KERNEL); 342 &pxa_dma->sg_dma, GFP_KERNEL);
342 if (!pxa_dma->sg_cpu) 343 if (!pxa_dma->sg_cpu)
343 return -ENOMEM; 344 return -ENOMEM;
@@ -345,7 +346,7 @@ static int pxa_init_dma_channel(struct pxa_camera_dev *pcdev,
345 pxa_dma->sglen = sglen; 346 pxa_dma->sglen = sglen;
346 offset = *sg_first_ofs; 347 offset = *sg_first_ofs;
347 348
348 dev_dbg(pcdev->soc_host.dev, "DMA: sg_first=%p, sglen=%d, ofs=%d, dma.desc=%x\n", 349 dev_dbg(dev, "DMA: sg_first=%p, sglen=%d, ofs=%d, dma.desc=%x\n",
349 *sg_first, sglen, *sg_first_ofs, pxa_dma->sg_dma); 350 *sg_first, sglen, *sg_first_ofs, pxa_dma->sg_dma);
350 351
351 352
@@ -368,7 +369,7 @@ static int pxa_init_dma_channel(struct pxa_camera_dev *pcdev,
368 pxa_dma->sg_cpu[i].ddadr = 369 pxa_dma->sg_cpu[i].ddadr =
369 pxa_dma->sg_dma + (i + 1) * sizeof(struct pxa_dma_desc); 370 pxa_dma->sg_dma + (i + 1) * sizeof(struct pxa_dma_desc);
370 371
371 dev_vdbg(pcdev->soc_host.dev, "DMA: desc.%08x->@phys=0x%08x, len=%d\n", 372 dev_vdbg(dev, "DMA: desc.%08x->@phys=0x%08x, len=%d\n",
372 pxa_dma->sg_dma + i * sizeof(struct pxa_dma_desc), 373 pxa_dma->sg_dma + i * sizeof(struct pxa_dma_desc),
373 sg_dma_address(sg) + offset, xfer_len); 374 sg_dma_address(sg) + offset, xfer_len);
374 offset = 0; 375 offset = 0;
@@ -418,11 +419,12 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq,
418 struct soc_camera_device *icd = vq->priv_data; 419 struct soc_camera_device *icd = vq->priv_data;
419 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 420 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
420 struct pxa_camera_dev *pcdev = ici->priv; 421 struct pxa_camera_dev *pcdev = ici->priv;
422 struct device *dev = pcdev->soc_host.v4l2_dev.dev;
421 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); 423 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
422 int ret; 424 int ret;
423 int size_y, size_u = 0, size_v = 0; 425 int size_y, size_u = 0, size_v = 0;
424 426
425 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, 427 dev_dbg(dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
426 vb, vb->baddr, vb->bsize); 428 vb, vb->baddr, vb->bsize);
427 429
428 /* Added list head initialization on alloc */ 430 /* Added list head initialization on alloc */
@@ -480,8 +482,7 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq,
480 ret = pxa_init_dma_channel(pcdev, buf, dma, 0, CIBR0, size_y, 482 ret = pxa_init_dma_channel(pcdev, buf, dma, 0, CIBR0, size_y,
481 &sg, &next_ofs); 483 &sg, &next_ofs);
482 if (ret) { 484 if (ret) {
483 dev_err(pcdev->soc_host.dev, 485 dev_err(dev, "DMA initialization for Y/RGB failed\n");
484 "DMA initialization for Y/RGB failed\n");
485 goto fail; 486 goto fail;
486 } 487 }
487 488
@@ -490,8 +491,7 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq,
490 ret = pxa_init_dma_channel(pcdev, buf, dma, 1, CIBR1, 491 ret = pxa_init_dma_channel(pcdev, buf, dma, 1, CIBR1,
491 size_u, &sg, &next_ofs); 492 size_u, &sg, &next_ofs);
492 if (ret) { 493 if (ret) {
493 dev_err(pcdev->soc_host.dev, 494 dev_err(dev, "DMA initialization for U failed\n");
494 "DMA initialization for U failed\n");
495 goto fail_u; 495 goto fail_u;
496 } 496 }
497 497
@@ -500,8 +500,7 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq,
500 ret = pxa_init_dma_channel(pcdev, buf, dma, 2, CIBR2, 500 ret = pxa_init_dma_channel(pcdev, buf, dma, 2, CIBR2,
501 size_v, &sg, &next_ofs); 501 size_v, &sg, &next_ofs);
502 if (ret) { 502 if (ret) {
503 dev_err(pcdev->soc_host.dev, 503 dev_err(dev, "DMA initialization for V failed\n");
504 "DMA initialization for V failed\n");
505 goto fail_v; 504 goto fail_v;
506 } 505 }
507 506
@@ -514,10 +513,10 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq,
514 return 0; 513 return 0;
515 514
516fail_v: 515fail_v:
517 dma_free_coherent(pcdev->soc_host.dev, buf->dmas[1].sg_size, 516 dma_free_coherent(dev, buf->dmas[1].sg_size,
518 buf->dmas[1].sg_cpu, buf->dmas[1].sg_dma); 517 buf->dmas[1].sg_cpu, buf->dmas[1].sg_dma);
519fail_u: 518fail_u:
520 dma_free_coherent(pcdev->soc_host.dev, buf->dmas[0].sg_size, 519 dma_free_coherent(dev, buf->dmas[0].sg_size,
521 buf->dmas[0].sg_cpu, buf->dmas[0].sg_dma); 520 buf->dmas[0].sg_cpu, buf->dmas[0].sg_dma);
522fail: 521fail:
523 free_buffer(vq, buf); 522 free_buffer(vq, buf);
@@ -541,7 +540,7 @@ static void pxa_dma_start_channels(struct pxa_camera_dev *pcdev)
541 active = pcdev->active; 540 active = pcdev->active;
542 541
543 for (i = 0; i < pcdev->channels; i++) { 542 for (i = 0; i < pcdev->channels; i++) {
544 dev_dbg(pcdev->soc_host.dev, "%s (channel=%d) ddadr=%08x\n", __func__, 543 dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s (channel=%d) ddadr=%08x\n", __func__,
545 i, active->dmas[i].sg_dma); 544 i, active->dmas[i].sg_dma);
546 DDADR(pcdev->dma_chans[i]) = active->dmas[i].sg_dma; 545 DDADR(pcdev->dma_chans[i]) = active->dmas[i].sg_dma;
547 DCSR(pcdev->dma_chans[i]) = DCSR_RUN; 546 DCSR(pcdev->dma_chans[i]) = DCSR_RUN;
@@ -553,7 +552,7 @@ static void pxa_dma_stop_channels(struct pxa_camera_dev *pcdev)
553 int i; 552 int i;
554 553
555 for (i = 0; i < pcdev->channels; i++) { 554 for (i = 0; i < pcdev->channels; i++) {
556 dev_dbg(pcdev->soc_host.dev, "%s (channel=%d)\n", __func__, i); 555 dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s (channel=%d)\n", __func__, i);
557 DCSR(pcdev->dma_chans[i]) = 0; 556 DCSR(pcdev->dma_chans[i]) = 0;
558 } 557 }
559} 558}
@@ -589,7 +588,7 @@ static void pxa_camera_start_capture(struct pxa_camera_dev *pcdev)
589{ 588{
590 unsigned long cicr0, cifr; 589 unsigned long cicr0, cifr;
591 590
592 dev_dbg(pcdev->soc_host.dev, "%s\n", __func__); 591 dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s\n", __func__);
593 /* Reset the FIFOs */ 592 /* Reset the FIFOs */
594 cifr = __raw_readl(pcdev->base + CIFR) | CIFR_RESET_F; 593 cifr = __raw_readl(pcdev->base + CIFR) | CIFR_RESET_F;
595 __raw_writel(cifr, pcdev->base + CIFR); 594 __raw_writel(cifr, pcdev->base + CIFR);
@@ -609,7 +608,7 @@ static void pxa_camera_stop_capture(struct pxa_camera_dev *pcdev)
609 __raw_writel(cicr0, pcdev->base + CICR0); 608 __raw_writel(cicr0, pcdev->base + CICR0);
610 609
611 pcdev->active = NULL; 610 pcdev->active = NULL;
612 dev_dbg(pcdev->soc_host.dev, "%s\n", __func__); 611 dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s\n", __func__);
613} 612}
614 613
615/* Called under spinlock_irqsave(&pcdev->lock, ...) */ 614/* Called under spinlock_irqsave(&pcdev->lock, ...) */
@@ -674,7 +673,8 @@ static void pxa_camera_wakeup(struct pxa_camera_dev *pcdev,
674 do_gettimeofday(&vb->ts); 673 do_gettimeofday(&vb->ts);
675 vb->field_count++; 674 vb->field_count++;
676 wake_up(&vb->done); 675 wake_up(&vb->done);
677 dev_dbg(pcdev->soc_host.dev, "%s dequeud buffer (vb=0x%p)\n", __func__, vb); 676 dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s dequeud buffer (vb=0x%p)\n",
677 __func__, vb);
678 678
679 if (list_empty(&pcdev->capture)) { 679 if (list_empty(&pcdev->capture)) {
680 pxa_camera_stop_capture(pcdev); 680 pxa_camera_stop_capture(pcdev);
@@ -710,7 +710,8 @@ static void pxa_camera_check_link_miss(struct pxa_camera_dev *pcdev)
710 for (i = 0; i < pcdev->channels; i++) 710 for (i = 0; i < pcdev->channels; i++)
711 if (DDADR(pcdev->dma_chans[i]) != DDADR_STOP) 711 if (DDADR(pcdev->dma_chans[i]) != DDADR_STOP)
712 is_dma_stopped = 0; 712 is_dma_stopped = 0;
713 dev_dbg(pcdev->soc_host.dev, "%s : top queued buffer=%p, dma_stopped=%d\n", 713 dev_dbg(pcdev->soc_host.v4l2_dev.dev,
714 "%s : top queued buffer=%p, dma_stopped=%d\n",
714 __func__, pcdev->active, is_dma_stopped); 715 __func__, pcdev->active, is_dma_stopped);
715 if (pcdev->active && is_dma_stopped) 716 if (pcdev->active && is_dma_stopped)
716 pxa_camera_start_capture(pcdev); 717 pxa_camera_start_capture(pcdev);
@@ -719,6 +720,7 @@ static void pxa_camera_check_link_miss(struct pxa_camera_dev *pcdev)
719static void pxa_camera_dma_irq(int channel, struct pxa_camera_dev *pcdev, 720static void pxa_camera_dma_irq(int channel, struct pxa_camera_dev *pcdev,
720 enum pxa_camera_active_dma act_dma) 721 enum pxa_camera_active_dma act_dma)
721{ 722{
723 struct device *dev = pcdev->soc_host.v4l2_dev.dev;
722 struct pxa_buffer *buf; 724 struct pxa_buffer *buf;
723 unsigned long flags; 725 unsigned long flags;
724 u32 status, camera_status, overrun; 726 u32 status, camera_status, overrun;
@@ -735,13 +737,13 @@ static void pxa_camera_dma_irq(int channel, struct pxa_camera_dev *pcdev,
735 overrun |= CISR_IFO_1 | CISR_IFO_2; 737 overrun |= CISR_IFO_1 | CISR_IFO_2;
736 738
737 if (status & DCSR_BUSERR) { 739 if (status & DCSR_BUSERR) {
738 dev_err(pcdev->soc_host.dev, "DMA Bus Error IRQ!\n"); 740 dev_err(dev, "DMA Bus Error IRQ!\n");
739 goto out; 741 goto out;
740 } 742 }
741 743
742 if (!(status & (DCSR_ENDINTR | DCSR_STARTINTR))) { 744 if (!(status & (DCSR_ENDINTR | DCSR_STARTINTR))) {
743 dev_err(pcdev->soc_host.dev, "Unknown DMA IRQ source, " 745 dev_err(dev, "Unknown DMA IRQ source, status: 0x%08x\n",
744 "status: 0x%08x\n", status); 746 status);
745 goto out; 747 goto out;
746 } 748 }
747 749
@@ -764,7 +766,7 @@ static void pxa_camera_dma_irq(int channel, struct pxa_camera_dev *pcdev,
764 buf = container_of(vb, struct pxa_buffer, vb); 766 buf = container_of(vb, struct pxa_buffer, vb);
765 WARN_ON(buf->inwork || list_empty(&vb->queue)); 767 WARN_ON(buf->inwork || list_empty(&vb->queue));
766 768
767 dev_dbg(pcdev->soc_host.dev, "%s channel=%d %s%s(vb=0x%p) dma.desc=%x\n", 769 dev_dbg(dev, "%s channel=%d %s%s(vb=0x%p) dma.desc=%x\n",
768 __func__, channel, status & DCSR_STARTINTR ? "SOF " : "", 770 __func__, channel, status & DCSR_STARTINTR ? "SOF " : "",
769 status & DCSR_ENDINTR ? "EOF " : "", vb, DDADR(channel)); 771 status & DCSR_ENDINTR ? "EOF " : "", vb, DDADR(channel));
770 772
@@ -775,7 +777,7 @@ static void pxa_camera_dma_irq(int channel, struct pxa_camera_dev *pcdev,
775 */ 777 */
776 if (camera_status & overrun && 778 if (camera_status & overrun &&
777 !list_is_last(pcdev->capture.next, &pcdev->capture)) { 779 !list_is_last(pcdev->capture.next, &pcdev->capture)) {
778 dev_dbg(pcdev->soc_host.dev, "FIFO overrun! CISR: %x\n", 780 dev_dbg(dev, "FIFO overrun! CISR: %x\n",
779 camera_status); 781 camera_status);
780 pxa_camera_stop_capture(pcdev); 782 pxa_camera_stop_capture(pcdev);
781 pxa_camera_start_capture(pcdev); 783 pxa_camera_start_capture(pcdev);
@@ -834,6 +836,7 @@ static u32 mclk_get_divisor(struct platform_device *pdev,
834 struct pxa_camera_dev *pcdev) 836 struct pxa_camera_dev *pcdev)
835{ 837{
836 unsigned long mclk = pcdev->mclk; 838 unsigned long mclk = pcdev->mclk;
839 struct device *dev = pcdev->soc_host.v4l2_dev.dev;
837 u32 div; 840 u32 div;
838 unsigned long lcdclk; 841 unsigned long lcdclk;
839 842
@@ -843,7 +846,7 @@ static u32 mclk_get_divisor(struct platform_device *pdev,
843 /* mclk <= ciclk / 4 (27.4.2) */ 846 /* mclk <= ciclk / 4 (27.4.2) */
844 if (mclk > lcdclk / 4) { 847 if (mclk > lcdclk / 4) {
845 mclk = lcdclk / 4; 848 mclk = lcdclk / 4;
846 dev_warn(&pdev->dev, "Limiting master clock to %lu\n", mclk); 849 dev_warn(dev, "Limiting master clock to %lu\n", mclk);
847 } 850 }
848 851
849 /* We verify mclk != 0, so if anyone breaks it, here comes their Oops */ 852 /* We verify mclk != 0, so if anyone breaks it, here comes their Oops */
@@ -853,7 +856,7 @@ static u32 mclk_get_divisor(struct platform_device *pdev,
853 if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN) 856 if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN)
854 pcdev->mclk = lcdclk / (2 * (div + 1)); 857 pcdev->mclk = lcdclk / (2 * (div + 1));
855 858
856 dev_dbg(&pdev->dev, "LCD clock %luHz, target freq %luHz, divisor %u\n", 859 dev_dbg(dev, "LCD clock %luHz, target freq %luHz, divisor %u\n",
857 lcdclk, mclk, div); 860 lcdclk, mclk, div);
858 861
859 return div; 862 return div;
@@ -871,14 +874,15 @@ static void recalculate_fifo_timeout(struct pxa_camera_dev *pcdev,
871static void pxa_camera_activate(struct pxa_camera_dev *pcdev) 874static void pxa_camera_activate(struct pxa_camera_dev *pcdev)
872{ 875{
873 struct pxacamera_platform_data *pdata = pcdev->pdata; 876 struct pxacamera_platform_data *pdata = pcdev->pdata;
877 struct device *dev = pcdev->soc_host.v4l2_dev.dev;
874 u32 cicr4 = 0; 878 u32 cicr4 = 0;
875 879
876 dev_dbg(pcdev->soc_host.dev, "Registered platform device at %p data %p\n", 880 dev_dbg(dev, "Registered platform device at %p data %p\n",
877 pcdev, pdata); 881 pcdev, pdata);
878 882
879 if (pdata && pdata->init) { 883 if (pdata && pdata->init) {
880 dev_dbg(pcdev->soc_host.dev, "%s: Init gpios\n", __func__); 884 dev_dbg(dev, "%s: Init gpios\n", __func__);
881 pdata->init(pcdev->soc_host.dev); 885 pdata->init(dev);
882 } 886 }
883 887
884 /* disable all interrupts */ 888 /* disable all interrupts */
@@ -920,7 +924,7 @@ static irqreturn_t pxa_camera_irq(int irq, void *data)
920 struct videobuf_buffer *vb; 924 struct videobuf_buffer *vb;
921 925
922 status = __raw_readl(pcdev->base + CISR); 926 status = __raw_readl(pcdev->base + CISR);
923 dev_dbg(pcdev->soc_host.dev, "Camera interrupt status 0x%lx\n", status); 927 dev_dbg(pcdev->soc_host.v4l2_dev.dev, "Camera interrupt status 0x%lx\n", status);
924 928
925 if (!status) 929 if (!status)
926 return IRQ_NONE; 930 return IRQ_NONE;
@@ -952,17 +956,11 @@ static int pxa_camera_add_device(struct soc_camera_device *icd)
952{ 956{
953 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 957 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
954 struct pxa_camera_dev *pcdev = ici->priv; 958 struct pxa_camera_dev *pcdev = ici->priv;
955 int ret;
956 959
957 if (pcdev->icd) { 960 if (pcdev->icd)
958 ret = -EBUSY; 961 return -EBUSY;
959 goto ebusy;
960 }
961 962
962 pxa_camera_activate(pcdev); 963 pxa_camera_activate(pcdev);
963 ret = icd->ops->init(icd);
964 if (ret < 0)
965 goto einit;
966 964
967 pcdev->icd = icd; 965 pcdev->icd = icd;
968 966
@@ -970,11 +968,6 @@ static int pxa_camera_add_device(struct soc_camera_device *icd)
970 icd->devnum); 968 icd->devnum);
971 969
972 return 0; 970 return 0;
973
974einit:
975 pxa_camera_deactivate(pcdev);
976ebusy:
977 return ret;
978} 971}
979 972
980/* Called with .video_lock held */ 973/* Called with .video_lock held */
@@ -996,8 +989,6 @@ static void pxa_camera_remove_device(struct soc_camera_device *icd)
996 DCSR(pcdev->dma_chans[1]) = 0; 989 DCSR(pcdev->dma_chans[1]) = 0;
997 DCSR(pcdev->dma_chans[2]) = 0; 990 DCSR(pcdev->dma_chans[2]) = 0;
998 991
999 icd->ops->release(icd);
1000
1001 pxa_camera_deactivate(pcdev); 992 pxa_camera_deactivate(pcdev);
1002 993
1003 pcdev->icd = NULL; 994 pcdev->icd = NULL;
@@ -1253,7 +1244,7 @@ static int pxa_camera_get_formats(struct soc_camera_device *icd, int idx,
1253 xlate->cam_fmt = icd->formats + idx; 1244 xlate->cam_fmt = icd->formats + idx;
1254 xlate->buswidth = buswidth; 1245 xlate->buswidth = buswidth;
1255 xlate++; 1246 xlate++;
1256 dev_dbg(ici->dev, "Providing format %s using %s\n", 1247 dev_dbg(ici->v4l2_dev.dev, "Providing format %s using %s\n",
1257 pxa_camera_formats[0].name, 1248 pxa_camera_formats[0].name,
1258 icd->formats[idx].name); 1249 icd->formats[idx].name);
1259 } 1250 }
@@ -1268,7 +1259,7 @@ static int pxa_camera_get_formats(struct soc_camera_device *icd, int idx,
1268 xlate->cam_fmt = icd->formats + idx; 1259 xlate->cam_fmt = icd->formats + idx;
1269 xlate->buswidth = buswidth; 1260 xlate->buswidth = buswidth;
1270 xlate++; 1261 xlate++;
1271 dev_dbg(ici->dev, "Providing format %s packed\n", 1262 dev_dbg(ici->v4l2_dev.dev, "Providing format %s packed\n",
1272 icd->formats[idx].name); 1263 icd->formats[idx].name);
1273 } 1264 }
1274 break; 1265 break;
@@ -1280,7 +1271,7 @@ static int pxa_camera_get_formats(struct soc_camera_device *icd, int idx,
1280 xlate->cam_fmt = icd->formats + idx; 1271 xlate->cam_fmt = icd->formats + idx;
1281 xlate->buswidth = icd->formats[idx].depth; 1272 xlate->buswidth = icd->formats[idx].depth;
1282 xlate++; 1273 xlate++;
1283 dev_dbg(ici->dev, 1274 dev_dbg(ici->v4l2_dev.dev,
1284 "Providing format %s in pass-through mode\n", 1275 "Providing format %s in pass-through mode\n",
1285 icd->formats[idx].name); 1276 icd->formats[idx].name);
1286 } 1277 }
@@ -1309,11 +1300,11 @@ static int pxa_camera_set_crop(struct soc_camera_device *icd,
1309 icd->sense = NULL; 1300 icd->sense = NULL;
1310 1301
1311 if (ret < 0) { 1302 if (ret < 0) {
1312 dev_warn(ici->dev, "Failed to crop to %ux%u@%u:%u\n", 1303 dev_warn(ici->v4l2_dev.dev, "Failed to crop to %ux%u@%u:%u\n",
1313 rect->width, rect->height, rect->left, rect->top); 1304 rect->width, rect->height, rect->left, rect->top);
1314 } else if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { 1305 } else if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) {
1315 if (sense.pixel_clock > sense.pixel_clock_max) { 1306 if (sense.pixel_clock > sense.pixel_clock_max) {
1316 dev_err(ici->dev, 1307 dev_err(ici->v4l2_dev.dev,
1317 "pixel clock %lu set by the camera too high!", 1308 "pixel clock %lu set by the camera too high!",
1318 sense.pixel_clock); 1309 sense.pixel_clock);
1319 return -EIO; 1310 return -EIO;
@@ -1341,7 +1332,7 @@ static int pxa_camera_set_fmt(struct soc_camera_device *icd,
1341 1332
1342 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); 1333 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
1343 if (!xlate) { 1334 if (!xlate) {
1344 dev_warn(ici->dev, "Format %x not found\n", pix->pixelformat); 1335 dev_warn(ici->v4l2_dev.dev, "Format %x not found\n", pix->pixelformat);
1345 return -EINVAL; 1336 return -EINVAL;
1346 } 1337 }
1347 1338
@@ -1352,16 +1343,16 @@ static int pxa_camera_set_fmt(struct soc_camera_device *icd,
1352 icd->sense = &sense; 1343 icd->sense = &sense;
1353 1344
1354 cam_f.fmt.pix.pixelformat = cam_fmt->fourcc; 1345 cam_f.fmt.pix.pixelformat = cam_fmt->fourcc;
1355 ret = icd->ops->set_fmt(icd, &cam_f); 1346 ret = v4l2_device_call_until_err(&ici->v4l2_dev, 0, video, s_fmt, f);
1356 1347
1357 icd->sense = NULL; 1348 icd->sense = NULL;
1358 1349
1359 if (ret < 0) { 1350 if (ret < 0) {
1360 dev_warn(ici->dev, "Failed to configure for format %x\n", 1351 dev_warn(ici->v4l2_dev.dev, "Failed to configure for format %x\n",
1361 pix->pixelformat); 1352 pix->pixelformat);
1362 } else if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { 1353 } else if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) {
1363 if (sense.pixel_clock > sense.pixel_clock_max) { 1354 if (sense.pixel_clock > sense.pixel_clock_max) {
1364 dev_err(ici->dev, 1355 dev_err(ici->v4l2_dev.dev,
1365 "pixel clock %lu set by the camera too high!", 1356 "pixel clock %lu set by the camera too high!",
1366 sense.pixel_clock); 1357 sense.pixel_clock);
1367 return -EIO; 1358 return -EIO;
@@ -1389,7 +1380,7 @@ static int pxa_camera_try_fmt(struct soc_camera_device *icd,
1389 1380
1390 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); 1381 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
1391 if (!xlate) { 1382 if (!xlate) {
1392 dev_warn(ici->dev, "Format %x not found\n", pixfmt); 1383 dev_warn(ici->v4l2_dev.dev, "Format %x not found\n", pixfmt);
1393 return -EINVAL; 1384 return -EINVAL;
1394 } 1385 }
1395 1386
@@ -1410,7 +1401,7 @@ static int pxa_camera_try_fmt(struct soc_camera_device *icd,
1410 /* camera has to see its format, but the user the original one */ 1401 /* camera has to see its format, but the user the original one */
1411 pix->pixelformat = xlate->cam_fmt->fourcc; 1402 pix->pixelformat = xlate->cam_fmt->fourcc;
1412 /* limit to sensor capabilities */ 1403 /* limit to sensor capabilities */
1413 ret = icd->ops->try_fmt(icd, f); 1404 ret = v4l2_device_call_until_err(&ici->v4l2_dev, 0, video, try_fmt, f);
1414 pix->pixelformat = xlate->host_fmt->fourcc; 1405 pix->pixelformat = xlate->host_fmt->fourcc;
1415 1406
1416 field = pix->field; 1407 field = pix->field;
@@ -1646,7 +1637,7 @@ static int __devinit pxa_camera_probe(struct platform_device *pdev)
1646 pcdev->soc_host.drv_name = PXA_CAM_DRV_NAME; 1637 pcdev->soc_host.drv_name = PXA_CAM_DRV_NAME;
1647 pcdev->soc_host.ops = &pxa_soc_camera_host_ops; 1638 pcdev->soc_host.ops = &pxa_soc_camera_host_ops;
1648 pcdev->soc_host.priv = pcdev; 1639 pcdev->soc_host.priv = pcdev;
1649 pcdev->soc_host.dev = &pdev->dev; 1640 pcdev->soc_host.v4l2_dev.dev = &pdev->dev;
1650 pcdev->soc_host.nr = pdev->id; 1641 pcdev->soc_host.nr = pdev->id;
1651 1642
1652 err = soc_camera_host_register(&pcdev->soc_host); 1643 err = soc_camera_host_register(&pcdev->soc_host);
diff --git a/drivers/media/video/sh_mobile_ceu_camera.c b/drivers/media/video/sh_mobile_ceu_camera.c
index e7ac84daf670..5101fa7cdb2f 100644
--- a/drivers/media/video/sh_mobile_ceu_camera.c
+++ b/drivers/media/video/sh_mobile_ceu_camera.c
@@ -347,10 +347,9 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
347{ 347{
348 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 348 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
349 struct sh_mobile_ceu_dev *pcdev = ici->priv; 349 struct sh_mobile_ceu_dev *pcdev = ici->priv;
350 int ret = -EBUSY;
351 350
352 if (pcdev->icd) 351 if (pcdev->icd)
353 goto err; 352 return -EBUSY;
354 353
355 dev_info(&icd->dev, 354 dev_info(&icd->dev,
356 "SuperH Mobile CEU driver attached to camera %d\n", 355 "SuperH Mobile CEU driver attached to camera %d\n",
@@ -358,19 +357,13 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
358 357
359 clk_enable(pcdev->clk); 358 clk_enable(pcdev->clk);
360 359
361 ret = icd->ops->init(icd);
362 if (ret) {
363 clk_disable(pcdev->clk);
364 goto err;
365 }
366
367 ceu_write(pcdev, CAPSR, 1 << 16); /* reset */ 360 ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
368 while (ceu_read(pcdev, CSTSR) & 1) 361 while (ceu_read(pcdev, CSTSR) & 1)
369 msleep(1); 362 msleep(1);
370 363
371 pcdev->icd = icd; 364 pcdev->icd = icd;
372err: 365
373 return ret; 366 return 0;
374} 367}
375 368
376/* Called with .video_lock held */ 369/* Called with .video_lock held */
@@ -396,8 +389,6 @@ static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
396 } 389 }
397 spin_unlock_irqrestore(&pcdev->lock, flags); 390 spin_unlock_irqrestore(&pcdev->lock, flags);
398 391
399 icd->ops->release(icd);
400
401 clk_disable(pcdev->clk); 392 clk_disable(pcdev->clk);
402 393
403 dev_info(&icd->dev, 394 dev_info(&icd->dev,
@@ -614,7 +605,7 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, int idx,
614 xlate->cam_fmt = icd->formats + idx; 605 xlate->cam_fmt = icd->formats + idx;
615 xlate->buswidth = icd->formats[idx].depth; 606 xlate->buswidth = icd->formats[idx].depth;
616 xlate++; 607 xlate++;
617 dev_dbg(ici->dev, "Providing format %s using %s\n", 608 dev_dbg(ici->v4l2_dev.dev, "Providing format %s using %s\n",
618 sh_mobile_ceu_formats[k].name, 609 sh_mobile_ceu_formats[k].name,
619 icd->formats[idx].name); 610 icd->formats[idx].name);
620 } 611 }
@@ -627,7 +618,7 @@ add_single_format:
627 xlate->cam_fmt = icd->formats + idx; 618 xlate->cam_fmt = icd->formats + idx;
628 xlate->buswidth = icd->formats[idx].depth; 619 xlate->buswidth = icd->formats[idx].depth;
629 xlate++; 620 xlate++;
630 dev_dbg(ici->dev, 621 dev_dbg(ici->v4l2_dev.dev,
631 "Providing format %s in pass-through mode\n", 622 "Providing format %s in pass-through mode\n",
632 icd->formats[idx].name); 623 icd->formats[idx].name);
633 } 624 }
@@ -649,18 +640,17 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
649 struct sh_mobile_ceu_dev *pcdev = ici->priv; 640 struct sh_mobile_ceu_dev *pcdev = ici->priv;
650 __u32 pixfmt = f->fmt.pix.pixelformat; 641 __u32 pixfmt = f->fmt.pix.pixelformat;
651 const struct soc_camera_format_xlate *xlate; 642 const struct soc_camera_format_xlate *xlate;
652 struct v4l2_format cam_f = *f;
653 int ret; 643 int ret;
654 644
655 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); 645 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
656 if (!xlate) { 646 if (!xlate) {
657 dev_warn(ici->dev, "Format %x not found\n", pixfmt); 647 dev_warn(ici->v4l2_dev.dev, "Format %x not found\n", pixfmt);
658 return -EINVAL; 648 return -EINVAL;
659 } 649 }
660 650
661 cam_f.fmt.pix.pixelformat = xlate->cam_fmt->fourcc; 651 f->fmt.pix.pixelformat = xlate->cam_fmt->fourcc;
662 ret = icd->ops->set_fmt(icd, &cam_f); 652 ret = v4l2_device_call_until_err(&ici->v4l2_dev, (__u32)icd, video, s_fmt, f);
663 653 f->fmt.pix.pixelformat = pixfmt;
664 if (!ret) { 654 if (!ret) {
665 icd->buswidth = xlate->buswidth; 655 icd->buswidth = xlate->buswidth;
666 icd->current_fmt = xlate->host_fmt; 656 icd->current_fmt = xlate->host_fmt;
@@ -681,7 +671,7 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
681 671
682 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); 672 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
683 if (!xlate) { 673 if (!xlate) {
684 dev_warn(ici->dev, "Format %x not found\n", pixfmt); 674 dev_warn(ici->v4l2_dev.dev, "Format %x not found\n", pixfmt);
685 return -EINVAL; 675 return -EINVAL;
686 } 676 }
687 677
@@ -694,8 +684,11 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
694 DIV_ROUND_UP(xlate->host_fmt->depth, 8); 684 DIV_ROUND_UP(xlate->host_fmt->depth, 8);
695 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; 685 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
696 686
687 f->fmt.pix.pixelformat = xlate->cam_fmt->fourcc;
688
697 /* limit to sensor capabilities */ 689 /* limit to sensor capabilities */
698 ret = icd->ops->try_fmt(icd, f); 690 ret = v4l2_device_call_until_err(&ici->v4l2_dev, (__u32)icd, video, try_fmt, f);
691 f->fmt.pix.pixelformat = pixfmt;
699 if (ret < 0) 692 if (ret < 0)
700 return ret; 693 return ret;
701 694
@@ -771,7 +764,7 @@ static void sh_mobile_ceu_init_videobuf(struct videobuf_queue *q,
771 764
772 videobuf_queue_dma_contig_init(q, 765 videobuf_queue_dma_contig_init(q,
773 &sh_mobile_ceu_videobuf_ops, 766 &sh_mobile_ceu_videobuf_ops,
774 ici->dev, &pcdev->lock, 767 ici->v4l2_dev.dev, &pcdev->lock,
775 V4L2_BUF_TYPE_VIDEO_CAPTURE, 768 V4L2_BUF_TYPE_VIDEO_CAPTURE,
776 pcdev->is_interlaced ? 769 pcdev->is_interlaced ?
777 V4L2_FIELD_INTERLACED : V4L2_FIELD_NONE, 770 V4L2_FIELD_INTERLACED : V4L2_FIELD_NONE,
@@ -794,7 +787,7 @@ static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
794 .init_videobuf = sh_mobile_ceu_init_videobuf, 787 .init_videobuf = sh_mobile_ceu_init_videobuf,
795}; 788};
796 789
797static int sh_mobile_ceu_probe(struct platform_device *pdev) 790static int __devinit sh_mobile_ceu_probe(struct platform_device *pdev)
798{ 791{
799 struct sh_mobile_ceu_dev *pcdev; 792 struct sh_mobile_ceu_dev *pcdev;
800 struct resource *res; 793 struct resource *res;
@@ -867,7 +860,7 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev)
867 pm_runtime_resume(&pdev->dev); 860 pm_runtime_resume(&pdev->dev);
868 861
869 pcdev->ici.priv = pcdev; 862 pcdev->ici.priv = pcdev;
870 pcdev->ici.dev = &pdev->dev; 863 pcdev->ici.v4l2_dev.dev = &pdev->dev;
871 pcdev->ici.nr = pdev->id; 864 pcdev->ici.nr = pdev->id;
872 pcdev->ici.drv_name = dev_name(&pdev->dev); 865 pcdev->ici.drv_name = dev_name(&pdev->dev);
873 pcdev->ici.ops = &sh_mobile_ceu_host_ops; 866 pcdev->ici.ops = &sh_mobile_ceu_host_ops;
@@ -891,7 +884,7 @@ exit:
891 return err; 884 return err;
892} 885}
893 886
894static int sh_mobile_ceu_remove(struct platform_device *pdev) 887static int __devexit sh_mobile_ceu_remove(struct platform_device *pdev)
895{ 888{
896 struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); 889 struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
897 struct sh_mobile_ceu_dev *pcdev = container_of(soc_host, 890 struct sh_mobile_ceu_dev *pcdev = container_of(soc_host,
@@ -929,7 +922,7 @@ static struct platform_driver sh_mobile_ceu_driver = {
929 .pm = &sh_mobile_ceu_dev_pm_ops, 922 .pm = &sh_mobile_ceu_dev_pm_ops,
930 }, 923 },
931 .probe = sh_mobile_ceu_probe, 924 .probe = sh_mobile_ceu_probe,
932 .remove = sh_mobile_ceu_remove, 925 .remove = __exit_p(sh_mobile_ceu_remove),
933}; 926};
934 927
935static int __init sh_mobile_ceu_init(void) 928static int __init sh_mobile_ceu_init(void)
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index 20ef5c773fae..0a1cb40bfbf6 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -170,8 +170,6 @@ static int soc_camera_reqbufs(struct file *file, void *priv,
170 170
171 WARN_ON(priv != file->private_data); 171 WARN_ON(priv != file->private_data);
172 172
173 dev_dbg(&icd->dev, "%s: %d\n", __func__, p->memory);
174
175 ret = videobuf_reqbufs(&icf->vb_vidq, p); 173 ret = videobuf_reqbufs(&icf->vb_vidq, p);
176 if (ret < 0) 174 if (ret < 0)
177 return ret; 175 return ret;
@@ -285,7 +283,7 @@ static int soc_camera_set_fmt(struct soc_camera_file *icf,
285 return ret; 283 return ret;
286 } else if (!icd->current_fmt || 284 } else if (!icd->current_fmt ||
287 icd->current_fmt->fourcc != pix->pixelformat) { 285 icd->current_fmt->fourcc != pix->pixelformat) {
288 dev_err(ici->dev, 286 dev_err(ici->v4l2_dev.dev,
289 "Host driver hasn't set up current format correctly!\n"); 287 "Host driver hasn't set up current format correctly!\n");
290 return -EINVAL; 288 return -EINVAL;
291 } 289 }
@@ -308,20 +306,13 @@ static int soc_camera_set_fmt(struct soc_camera_file *icf,
308 306
309static int soc_camera_open(struct file *file) 307static int soc_camera_open(struct file *file)
310{ 308{
311 struct video_device *vdev; 309 struct video_device *vdev = video_devdata(file);
312 struct soc_camera_device *icd; 310 struct soc_camera_device *icd = container_of(vdev->parent, struct soc_camera_device, dev);
311 struct soc_camera_link *icl = to_soc_camera_link(icd);
313 struct soc_camera_host *ici; 312 struct soc_camera_host *ici;
314 struct soc_camera_file *icf; 313 struct soc_camera_file *icf;
315 int ret; 314 int ret;
316 315
317 /*
318 * It is safe to dereference these pointers now as long as a user has
319 * the video device open - we are protected by the held cdev reference.
320 */
321
322 vdev = video_devdata(file);
323 icd = container_of(vdev->parent, struct soc_camera_device, dev);
324
325 if (!icd->ops) 316 if (!icd->ops)
326 /* No device driver attached */ 317 /* No device driver attached */
327 return -ENODEV; 318 return -ENODEV;
@@ -332,12 +323,6 @@ static int soc_camera_open(struct file *file)
332 if (!icf) 323 if (!icf)
333 return -ENOMEM; 324 return -ENOMEM;
334 325
335 if (!try_module_get(icd->ops->owner)) {
336 dev_err(&icd->dev, "Couldn't lock sensor driver.\n");
337 ret = -EINVAL;
338 goto emgd;
339 }
340
341 if (!try_module_get(ici->ops->owner)) { 326 if (!try_module_get(ici->ops->owner)) {
342 dev_err(&icd->dev, "Couldn't lock capture bus driver.\n"); 327 dev_err(&icd->dev, "Couldn't lock capture bus driver.\n");
343 ret = -EINVAL; 328 ret = -EINVAL;
@@ -366,47 +351,65 @@ static int soc_camera_open(struct file *file)
366 if (ret < 0) 351 if (ret < 0)
367 goto eiufmt; 352 goto eiufmt;
368 353
369 dev_dbg(&icd->dev, "Using fmt %x\n", icd->current_fmt->fourcc);
370
371 f.fmt.pix.pixelformat = icd->current_fmt->fourcc; 354 f.fmt.pix.pixelformat = icd->current_fmt->fourcc;
372 f.fmt.pix.colorspace = icd->current_fmt->colorspace; 355 f.fmt.pix.colorspace = icd->current_fmt->colorspace;
373 356
357 if (icl->power) {
358 ret = icl->power(icd->pdev, 1);
359 if (ret < 0)
360 goto epower;
361 }
362
363 /* The camera could have been already on, try to reset */
364 if (icl->reset)
365 icl->reset(icd->pdev);
366
374 ret = ici->ops->add(icd); 367 ret = ici->ops->add(icd);
375 if (ret < 0) { 368 if (ret < 0) {
376 dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret); 369 dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret);
377 goto eiciadd; 370 goto eiciadd;
378 } 371 }
379 372
373 if (icd->ops->init) {
374 ret = icd->ops->init(icd);
375 if (ret < 0)
376 goto einit;
377 }
378
380 /* Try to configure with default parameters */ 379 /* Try to configure with default parameters */
381 ret = soc_camera_set_fmt(icf, &f); 380 ret = soc_camera_set_fmt(icf, &f);
382 if (ret < 0) 381 if (ret < 0)
383 goto esfmt; 382 goto esfmt;
384 } 383 }
385 384
386 mutex_unlock(&icd->video_lock);
387
388 file->private_data = icf; 385 file->private_data = icf;
389 dev_dbg(&icd->dev, "camera device open\n"); 386 dev_dbg(&icd->dev, "camera device open\n");
390 387
391 ici->ops->init_videobuf(&icf->vb_vidq, icd); 388 ici->ops->init_videobuf(&icf->vb_vidq, icd);
392 389
390 mutex_unlock(&icd->video_lock);
391
393 return 0; 392 return 0;
394 393
395 /* 394 /*
396 * First three errors are entered with the .video_lock held 395 * First five errors are entered with the .video_lock held
397 * and use_count == 1 396 * and use_count == 1
398 */ 397 */
399esfmt: 398esfmt:
399 if (icd->ops->release)
400 icd->ops->release(icd);
401einit:
400 ici->ops->remove(icd); 402 ici->ops->remove(icd);
401eiciadd: 403eiciadd:
404 if (icl->power)
405 icl->power(icd->pdev, 0);
406epower:
402 soc_camera_free_user_formats(icd); 407 soc_camera_free_user_formats(icd);
403eiufmt: 408eiufmt:
404 icd->use_count--; 409 icd->use_count--;
405 mutex_unlock(&icd->video_lock); 410 mutex_unlock(&icd->video_lock);
406 module_put(ici->ops->owner); 411 module_put(ici->ops->owner);
407emgi: 412emgi:
408 module_put(icd->ops->owner);
409emgd:
410 vfree(icf); 413 vfree(icf);
411 return ret; 414 return ret;
412} 415}
@@ -421,13 +424,18 @@ static int soc_camera_close(struct file *file)
421 mutex_lock(&icd->video_lock); 424 mutex_lock(&icd->video_lock);
422 icd->use_count--; 425 icd->use_count--;
423 if (!icd->use_count) { 426 if (!icd->use_count) {
427 struct soc_camera_link *icl = to_soc_camera_link(icd);
428
429 if (icd->ops->release)
430 icd->ops->release(icd);
424 ici->ops->remove(icd); 431 ici->ops->remove(icd);
432 if (icl->power)
433 icl->power(icd->pdev, 0);
425 soc_camera_free_user_formats(icd); 434 soc_camera_free_user_formats(icd);
426 } 435 }
427 436
428 mutex_unlock(&icd->video_lock); 437 mutex_unlock(&icd->video_lock);
429 438
430 module_put(icd->ops->owner);
431 module_put(ici->ops->owner); 439 module_put(ici->ops->owner);
432 440
433 vfree(icf); 441 vfree(icf);
@@ -575,18 +583,17 @@ static int soc_camera_streamon(struct file *file, void *priv,
575{ 583{
576 struct soc_camera_file *icf = file->private_data; 584 struct soc_camera_file *icf = file->private_data;
577 struct soc_camera_device *icd = icf->icd; 585 struct soc_camera_device *icd = icf->icd;
586 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
578 int ret; 587 int ret;
579 588
580 WARN_ON(priv != file->private_data); 589 WARN_ON(priv != file->private_data);
581 590
582 dev_dbg(&icd->dev, "%s\n", __func__);
583
584 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) 591 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
585 return -EINVAL; 592 return -EINVAL;
586 593
587 mutex_lock(&icd->video_lock); 594 mutex_lock(&icd->video_lock);
588 595
589 icd->ops->start_capture(icd); 596 v4l2_device_call_until_err(&ici->v4l2_dev, (__u32)icd, video, s_stream, 1);
590 597
591 /* This calls buf_queue from host driver's videobuf_queue_ops */ 598 /* This calls buf_queue from host driver's videobuf_queue_ops */
592 ret = videobuf_streamon(&icf->vb_vidq); 599 ret = videobuf_streamon(&icf->vb_vidq);
@@ -601,11 +608,10 @@ static int soc_camera_streamoff(struct file *file, void *priv,
601{ 608{
602 struct soc_camera_file *icf = file->private_data; 609 struct soc_camera_file *icf = file->private_data;
603 struct soc_camera_device *icd = icf->icd; 610 struct soc_camera_device *icd = icf->icd;
611 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
604 612
605 WARN_ON(priv != file->private_data); 613 WARN_ON(priv != file->private_data);
606 614
607 dev_dbg(&icd->dev, "%s\n", __func__);
608
609 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) 615 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
610 return -EINVAL; 616 return -EINVAL;
611 617
@@ -615,7 +621,7 @@ static int soc_camera_streamoff(struct file *file, void *priv,
615 * remaining buffers. When the last buffer is freed, stop capture */ 621 * remaining buffers. When the last buffer is freed, stop capture */
616 videobuf_streamoff(&icf->vb_vidq); 622 videobuf_streamoff(&icf->vb_vidq);
617 623
618 icd->ops->stop_capture(icd); 624 v4l2_device_call_until_err(&ici->v4l2_dev, (__u32)icd, video, s_stream, 0);
619 625
620 mutex_unlock(&icd->video_lock); 626 mutex_unlock(&icd->video_lock);
621 627
@@ -649,6 +655,7 @@ static int soc_camera_g_ctrl(struct file *file, void *priv,
649{ 655{
650 struct soc_camera_file *icf = file->private_data; 656 struct soc_camera_file *icf = file->private_data;
651 struct soc_camera_device *icd = icf->icd; 657 struct soc_camera_device *icd = icf->icd;
658 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
652 659
653 WARN_ON(priv != file->private_data); 660 WARN_ON(priv != file->private_data);
654 661
@@ -665,9 +672,7 @@ static int soc_camera_g_ctrl(struct file *file, void *priv,
665 return 0; 672 return 0;
666 } 673 }
667 674
668 if (icd->ops->get_control) 675 return v4l2_device_call_until_err(&ici->v4l2_dev, (__u32)icd, core, g_ctrl, ctrl);
669 return icd->ops->get_control(icd, ctrl);
670 return -EINVAL;
671} 676}
672 677
673static int soc_camera_s_ctrl(struct file *file, void *priv, 678static int soc_camera_s_ctrl(struct file *file, void *priv,
@@ -675,12 +680,11 @@ static int soc_camera_s_ctrl(struct file *file, void *priv,
675{ 680{
676 struct soc_camera_file *icf = file->private_data; 681 struct soc_camera_file *icf = file->private_data;
677 struct soc_camera_device *icd = icf->icd; 682 struct soc_camera_device *icd = icf->icd;
683 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
678 684
679 WARN_ON(priv != file->private_data); 685 WARN_ON(priv != file->private_data);
680 686
681 if (icd->ops->set_control) 687 return v4l2_device_call_until_err(&ici->v4l2_dev, (__u32)icd, core, s_ctrl, ctrl);
682 return icd->ops->set_control(icd, ctrl);
683 return -EINVAL;
684} 688}
685 689
686static int soc_camera_cropcap(struct file *file, void *fh, 690static int soc_camera_cropcap(struct file *file, void *fh,
@@ -751,11 +755,9 @@ static int soc_camera_g_chip_ident(struct file *file, void *fh,
751{ 755{
752 struct soc_camera_file *icf = file->private_data; 756 struct soc_camera_file *icf = file->private_data;
753 struct soc_camera_device *icd = icf->icd; 757 struct soc_camera_device *icd = icf->icd;
758 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
754 759
755 if (!icd->ops->get_chip_id) 760 return v4l2_device_call_until_err(&ici->v4l2_dev, (__u32)icd, core, g_chip_ident, id);
756 return -EINVAL;
757
758 return icd->ops->get_chip_id(icd, id);
759} 761}
760 762
761#ifdef CONFIG_VIDEO_ADV_DEBUG 763#ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -764,11 +766,9 @@ static int soc_camera_g_register(struct file *file, void *fh,
764{ 766{
765 struct soc_camera_file *icf = file->private_data; 767 struct soc_camera_file *icf = file->private_data;
766 struct soc_camera_device *icd = icf->icd; 768 struct soc_camera_device *icd = icf->icd;
769 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
767 770
768 if (!icd->ops->get_register) 771 return v4l2_device_call_until_err(&ici->v4l2_dev, (__u32)icd, core, g_register, reg);
769 return -EINVAL;
770
771 return icd->ops->get_register(icd, reg);
772} 772}
773 773
774static int soc_camera_s_register(struct file *file, void *fh, 774static int soc_camera_s_register(struct file *file, void *fh,
@@ -776,11 +776,9 @@ static int soc_camera_s_register(struct file *file, void *fh,
776{ 776{
777 struct soc_camera_file *icf = file->private_data; 777 struct soc_camera_file *icf = file->private_data;
778 struct soc_camera_device *icd = icf->icd; 778 struct soc_camera_device *icd = icf->icd;
779 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
779 780
780 if (!icd->ops->set_register) 781 return v4l2_device_call_until_err(&ici->v4l2_dev, (__u32)icd, core, s_register, reg);
781 return -EINVAL;
782
783 return icd->ops->set_register(icd, reg);
784} 782}
785#endif 783#endif
786 784
@@ -794,7 +792,7 @@ static void scan_add_host(struct soc_camera_host *ici)
794 list_for_each_entry(icd, &devices, list) { 792 list_for_each_entry(icd, &devices, list) {
795 if (icd->iface == ici->nr) { 793 if (icd->iface == ici->nr) {
796 int ret; 794 int ret;
797 icd->dev.parent = ici->dev; 795 icd->dev.parent = ici->v4l2_dev.dev;
798 dev_set_name(&icd->dev, "%u-%u", icd->iface, 796 dev_set_name(&icd->dev, "%u-%u", icd->iface,
799 icd->devnum); 797 icd->devnum);
800 ret = device_register(&icd->dev); 798 ret = device_register(&icd->dev);
@@ -814,7 +812,9 @@ static int soc_camera_init_i2c(struct soc_camera_device *icd,
814 struct soc_camera_link *icl) 812 struct soc_camera_link *icl)
815{ 813{
816 struct i2c_client *client; 814 struct i2c_client *client;
815 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
817 struct i2c_adapter *adap = i2c_get_adapter(icl->i2c_adapter_id); 816 struct i2c_adapter *adap = i2c_get_adapter(icl->i2c_adapter_id);
817 struct v4l2_subdev *subdev;
818 int ret; 818 int ret;
819 819
820 if (!adap) { 820 if (!adap) {
@@ -826,17 +826,16 @@ static int soc_camera_init_i2c(struct soc_camera_device *icd,
826 826
827 icl->board_info->platform_data = icd; 827 icl->board_info->platform_data = icd;
828 828
829 client = i2c_new_device(adap, icl->board_info); 829 subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap,
830 if (!client) { 830 icl->module_name, icl->board_info, NULL);
831 if (!subdev) {
831 ret = -ENOMEM; 832 ret = -ENOMEM;
832 goto ei2cnd; 833 goto ei2cnd;
833 } 834 }
834 835
835 /* 836 subdev->grp_id = (__u32)icd;
836 * We set icd drvdata at two locations - here and in 837 client = subdev->priv;
837 * soc_camera_video_start(). Depending on the module loading / 838
838 * initialisation order one of these locations will be entered first
839 */
840 /* Use to_i2c_client(dev) to recover the i2c client */ 839 /* Use to_i2c_client(dev) to recover the i2c client */
841 dev_set_drvdata(&icd->dev, &client->dev); 840 dev_set_drvdata(&icd->dev, &client->dev);
842 841
@@ -852,6 +851,7 @@ static void soc_camera_free_i2c(struct soc_camera_device *icd)
852 struct i2c_client *client = 851 struct i2c_client *client =
853 to_i2c_client(to_soc_camera_control(icd)); 852 to_i2c_client(to_soc_camera_control(icd));
854 dev_set_drvdata(&icd->dev, NULL); 853 dev_set_drvdata(&icd->dev, NULL);
854 v4l2_device_unregister_subdev(i2c_get_clientdata(client));
855 i2c_unregister_device(client); 855 i2c_unregister_device(client);
856 i2c_put_adapter(client->adapter); 856 i2c_put_adapter(client->adapter);
857} 857}
@@ -860,16 +860,37 @@ static void soc_camera_free_i2c(struct soc_camera_device *icd)
860#define soc_camera_free_i2c(icd) do {} while (0) 860#define soc_camera_free_i2c(icd) do {} while (0)
861#endif 861#endif
862 862
863static int soc_camera_video_start(struct soc_camera_device *icd);
863static int video_dev_create(struct soc_camera_device *icd); 864static int video_dev_create(struct soc_camera_device *icd);
864/* Called during host-driver probe */ 865/* Called during host-driver probe */
865static int soc_camera_probe(struct device *dev) 866static int soc_camera_probe(struct device *dev)
866{ 867{
867 struct soc_camera_device *icd = to_soc_camera_dev(dev); 868 struct soc_camera_device *icd = to_soc_camera_dev(dev);
869 struct soc_camera_host *ici = to_soc_camera_host(dev->parent);
868 struct soc_camera_link *icl = to_soc_camera_link(icd); 870 struct soc_camera_link *icl = to_soc_camera_link(icd);
871 struct device *control = NULL;
869 int ret; 872 int ret;
870 873
871 dev_info(dev, "Probing %s\n", dev_name(dev)); 874 dev_info(dev, "Probing %s\n", dev_name(dev));
872 875
876 if (icl->power) {
877 ret = icl->power(icd->pdev, 1);
878 if (ret < 0) {
879 dev_err(dev,
880 "Platform failed to power-on the camera.\n");
881 goto epower;
882 }
883 }
884
885 /* The camera could have been already on, try to reset */
886 if (icl->reset)
887 icl->reset(icd->pdev);
888
889 ret = ici->ops->add(icd);
890 if (ret < 0)
891 goto eadd;
892
893 /* Must have icd->vdev before registering the device */
873 ret = video_dev_create(icd); 894 ret = video_dev_create(icd);
874 if (ret < 0) 895 if (ret < 0)
875 goto evdc; 896 goto evdc;
@@ -883,34 +904,61 @@ static int soc_camera_probe(struct device *dev)
883 ret = -EINVAL; 904 ret = -EINVAL;
884 goto eadddev; 905 goto eadddev;
885 } else { 906 } else {
907 if (icl->module_name)
908 ret = request_module(icl->module_name);
909
886 ret = icl->add_device(icl, &icd->dev); 910 ret = icl->add_device(icl, &icd->dev);
887 if (ret < 0) 911 if (ret < 0)
888 goto eadddev; 912 goto eadddev;
889 }
890 913
891 ret = video_register_device(icd->vdev, VFL_TYPE_GRABBER, icd->vdev->minor); 914 /* FIXME: this is racy, have to use driver-binding notification */
892 if (ret < 0) { 915 control = to_soc_camera_control(icd);
893 dev_err(&icd->dev, "video_register_device failed: %d\n", ret); 916 if (!control || !control->driver ||
894 goto evidregd; 917 !try_module_get(control->driver->owner)) {
918 icl->del_device(icl);
919 goto enodrv;
920 }
895 } 921 }
896 922
923 /* ..._video_start() will create a device node, so we have to protect */
924 mutex_lock(&icd->video_lock);
925
926 ret = soc_camera_video_start(icd);
927 if (ret < 0)
928 goto evidstart;
929
897 /* Do we have to sysfs_remove_link() before device_unregister()? */ 930 /* Do we have to sysfs_remove_link() before device_unregister()? */
898 if (to_soc_camera_control(icd) && 931 if (to_soc_camera_control(icd) &&
899 sysfs_create_link(&icd->dev.kobj, &to_soc_camera_control(icd)->kobj, 932 sysfs_create_link(&icd->dev.kobj, &to_soc_camera_control(icd)->kobj,
900 "control")) 933 "control"))
901 dev_warn(&icd->dev, "Failed creating the control symlink\n"); 934 dev_warn(&icd->dev, "Failed creating the control symlink\n");
902 935
936 ici->ops->remove(icd);
937
938 if (icl->power)
939 icl->power(icd->pdev, 0);
940
941 mutex_unlock(&icd->video_lock);
903 942
904 return 0; 943 return 0;
905 944
906evidregd: 945evidstart:
907 if (icl->board_info) 946 mutex_unlock(&icd->video_lock);
947 if (icl->board_info) {
908 soc_camera_free_i2c(icd); 948 soc_camera_free_i2c(icd);
909 else 949 } else {
910 icl->del_device(icl); 950 icl->del_device(icl);
951 module_put(control->driver->owner);
952 }
953enodrv:
911eadddev: 954eadddev:
912 video_device_release(icd->vdev); 955 video_device_release(icd->vdev);
913evdc: 956evdc:
957 ici->ops->remove(icd);
958eadd:
959 if (icl->power)
960 icl->power(icd->pdev, 0);
961epower:
914 return ret; 962 return ret;
915} 963}
916 964
@@ -931,10 +979,16 @@ static int soc_camera_remove(struct device *dev)
931 mutex_unlock(&icd->video_lock); 979 mutex_unlock(&icd->video_lock);
932 } 980 }
933 981
934 if (icl->board_info) 982 if (icl->board_info) {
935 soc_camera_free_i2c(icd); 983 soc_camera_free_i2c(icd);
936 else 984 } else {
937 icl->del_device(icl); 985 struct device_driver *drv = to_soc_camera_control(icd) ?
986 to_soc_camera_control(icd)->driver : NULL;
987 if (drv) {
988 icl->del_device(icl);
989 module_put(drv->owner);
990 }
991 }
938 992
939 return 0; 993 return 0;
940} 994}
@@ -984,6 +1038,7 @@ static void dummy_release(struct device *dev)
984int soc_camera_host_register(struct soc_camera_host *ici) 1038int soc_camera_host_register(struct soc_camera_host *ici)
985{ 1039{
986 struct soc_camera_host *ix; 1040 struct soc_camera_host *ix;
1041 int ret;
987 1042
988 if (!ici || !ici->ops || 1043 if (!ici || !ici->ops ||
989 !ici->ops->try_fmt || 1044 !ici->ops->try_fmt ||
@@ -996,18 +1051,20 @@ int soc_camera_host_register(struct soc_camera_host *ici)
996 !ici->ops->add || 1051 !ici->ops->add ||
997 !ici->ops->remove || 1052 !ici->ops->remove ||
998 !ici->ops->poll || 1053 !ici->ops->poll ||
999 !ici->dev) 1054 !ici->v4l2_dev.dev)
1000 return -EINVAL; 1055 return -EINVAL;
1001 1056
1002 mutex_lock(&list_lock); 1057 mutex_lock(&list_lock);
1003 list_for_each_entry(ix, &hosts, list) { 1058 list_for_each_entry(ix, &hosts, list) {
1004 if (ix->nr == ici->nr) { 1059 if (ix->nr == ici->nr) {
1005 mutex_unlock(&list_lock); 1060 ret = -EBUSY;
1006 return -EBUSY; 1061 goto edevreg;
1007 } 1062 }
1008 } 1063 }
1009 1064
1010 dev_set_drvdata(ici->dev, ici); 1065 ret = v4l2_device_register(ici->v4l2_dev.dev, &ici->v4l2_dev);
1066 if (ret < 0)
1067 goto edevreg;
1011 1068
1012 list_add_tail(&ici->list, &hosts); 1069 list_add_tail(&ici->list, &hosts);
1013 mutex_unlock(&list_lock); 1070 mutex_unlock(&list_lock);
@@ -1015,6 +1072,10 @@ int soc_camera_host_register(struct soc_camera_host *ici)
1015 scan_add_host(ici); 1072 scan_add_host(ici);
1016 1073
1017 return 0; 1074 return 0;
1075
1076edevreg:
1077 mutex_unlock(&list_lock);
1078 return ret;
1018} 1079}
1019EXPORT_SYMBOL(soc_camera_host_register); 1080EXPORT_SYMBOL(soc_camera_host_register);
1020 1081
@@ -1028,7 +1089,7 @@ void soc_camera_host_unregister(struct soc_camera_host *ici)
1028 list_del(&ici->list); 1089 list_del(&ici->list);
1029 1090
1030 list_for_each_entry(icd, &devices, list) { 1091 list_for_each_entry(icd, &devices, list) {
1031 if (icd->dev.parent == ici->dev) { 1092 if (icd->iface == ici->nr) {
1032 /* The bus->remove will be called */ 1093 /* The bus->remove will be called */
1033 device_unregister(&icd->dev); 1094 device_unregister(&icd->dev);
1034 /* Not before device_unregister(), .remove 1095 /* Not before device_unregister(), .remove
@@ -1043,7 +1104,7 @@ void soc_camera_host_unregister(struct soc_camera_host *ici)
1043 1104
1044 mutex_unlock(&list_lock); 1105 mutex_unlock(&list_lock);
1045 1106
1046 dev_set_drvdata(ici->dev, NULL); 1107 v4l2_device_unregister(&ici->v4l2_dev);
1047} 1108}
1048EXPORT_SYMBOL(soc_camera_host_unregister); 1109EXPORT_SYMBOL(soc_camera_host_unregister);
1049 1110
@@ -1123,7 +1184,6 @@ static int video_dev_create(struct soc_camera_device *icd)
1123 1184
1124 if (!vdev) 1185 if (!vdev)
1125 return -ENOMEM; 1186 return -ENOMEM;
1126 dev_dbg(ici->dev, "Allocated video_device %p\n", vdev);
1127 1187
1128 strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name)); 1188 strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name));
1129 1189
@@ -1141,50 +1201,35 @@ static int video_dev_create(struct soc_camera_device *icd)
1141} 1201}
1142 1202
1143/* 1203/*
1144 * Usually called from the struct soc_camera_ops .probe() method, i.e., from 1204 * Called from soc_camera_probe() above (with .video_lock held???)
1145 * soc_camera_probe() above with .video_lock held
1146 */ 1205 */
1147int soc_camera_video_start(struct soc_camera_device *icd, struct device *dev) 1206static int soc_camera_video_start(struct soc_camera_device *icd)
1148{ 1207{
1149 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
1150 const struct v4l2_queryctrl *qctrl; 1208 const struct v4l2_queryctrl *qctrl;
1209 int ret;
1151 1210
1152 if (!icd->dev.parent) 1211 if (!icd->dev.parent)
1153 return -ENODEV; 1212 return -ENODEV;
1154 1213
1155 if (!icd->ops || 1214 if (!icd->ops ||
1156 !icd->ops->init ||
1157 !icd->ops->release ||
1158 !icd->ops->start_capture ||
1159 !icd->ops->stop_capture ||
1160 !icd->ops->set_fmt ||
1161 !icd->ops->try_fmt ||
1162 !icd->ops->query_bus_param || 1215 !icd->ops->query_bus_param ||
1163 !icd->ops->set_bus_param) 1216 !icd->ops->set_bus_param)
1164 return -EINVAL; 1217 return -EINVAL;
1165 1218
1166 /* See comment in soc_camera_probe() */ 1219 ret = video_register_device(icd->vdev, VFL_TYPE_GRABBER,
1167 dev_set_drvdata(&icd->dev, dev); 1220 icd->vdev->minor);
1221 if (ret < 0) {
1222 dev_err(&icd->dev, "video_register_device failed: %d\n", ret);
1223 return ret;
1224 }
1168 1225
1169 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_GAIN); 1226 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_GAIN);
1170 icd->gain = qctrl ? qctrl->default_value : (unsigned short)~0; 1227 icd->gain = qctrl ? qctrl->default_value : (unsigned short)~0;
1171 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE); 1228 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE);
1172 icd->exposure = qctrl ? qctrl->default_value : (unsigned short)~0; 1229 icd->exposure = qctrl ? qctrl->default_value : (unsigned short)~0;
1173 1230
1174 return ici->ops->add(icd); 1231 return 0;
1175}
1176EXPORT_SYMBOL(soc_camera_video_start);
1177
1178/* Called from client .remove() methods with .video_lock held */
1179void soc_camera_video_stop(struct soc_camera_device *icd)
1180{
1181 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
1182
1183 dev_dbg(&icd->dev, "%s\n", __func__);
1184
1185 ici->ops->remove(icd);
1186} 1232}
1187EXPORT_SYMBOL(soc_camera_video_stop);
1188 1233
1189static int __devinit soc_camera_pdrv_probe(struct platform_device *pdev) 1234static int __devinit soc_camera_pdrv_probe(struct platform_device *pdev)
1190{ 1235{
@@ -1200,6 +1245,7 @@ static int __devinit soc_camera_pdrv_probe(struct platform_device *pdev)
1200 return -ENOMEM; 1245 return -ENOMEM;
1201 1246
1202 icd->iface = icl->bus_id; 1247 icd->iface = icl->bus_id;
1248 icd->pdev = &pdev->dev;
1203 platform_set_drvdata(pdev, icd); 1249 platform_set_drvdata(pdev, icd);
1204 icd->dev.platform_data = icl; 1250 icd->dev.platform_data = icl;
1205 1251
diff --git a/drivers/media/video/soc_camera_platform.c b/drivers/media/video/soc_camera_platform.c
index d84c134f8d59..8168cf470eb3 100644
--- a/drivers/media/video/soc_camera_platform.c
+++ b/drivers/media/video/soc_camera_platform.c
@@ -16,11 +16,12 @@
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/videodev2.h> 18#include <linux/videodev2.h>
19#include <media/v4l2-common.h> 19#include <media/v4l2-subdev.h>
20#include <media/soc_camera.h> 20#include <media/soc_camera.h>
21#include <media/soc_camera_platform.h> 21#include <media/soc_camera_platform.h>
22 22
23struct soc_camera_platform_priv { 23struct soc_camera_platform_priv {
24 struct v4l2_subdev subdev;
24 struct soc_camera_data_format format; 25 struct soc_camera_data_format format;
25}; 26};
26 27
@@ -31,36 +32,10 @@ soc_camera_platform_get_info(struct soc_camera_device *icd)
31 return pdev->dev.platform_data; 32 return pdev->dev.platform_data;
32} 33}
33 34
34static int soc_camera_platform_init(struct soc_camera_device *icd) 35static int soc_camera_platform_s_stream(struct v4l2_subdev *sd, int enable)
35{ 36{
36 struct soc_camera_link *icl = to_soc_camera_link(icd); 37 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
37 38 return p->set_capture(p, enable);
38 if (icl->power)
39 icl->power(dev_get_drvdata(&icd->dev), 1);
40
41 return 0;
42}
43
44static int soc_camera_platform_release(struct soc_camera_device *icd)
45{
46 struct soc_camera_link *icl = to_soc_camera_link(icd);
47
48 if (icl->power)
49 icl->power(dev_get_drvdata(&icd->dev), 0);
50
51 return 0;
52}
53
54static int soc_camera_platform_start_capture(struct soc_camera_device *icd)
55{
56 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
57 return p->set_capture(p, 1);
58}
59
60static int soc_camera_platform_stop_capture(struct soc_camera_device *icd)
61{
62 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
63 return p->set_capture(p, 0);
64} 39}
65 40
66static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd, 41static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd,
@@ -82,16 +57,10 @@ static int soc_camera_platform_set_crop(struct soc_camera_device *icd,
82 return 0; 57 return 0;
83} 58}
84 59
85static int soc_camera_platform_set_fmt(struct soc_camera_device *icd, 60static int soc_camera_platform_try_fmt(struct v4l2_subdev *sd,
86 struct v4l2_format *f) 61 struct v4l2_format *f)
87{ 62{
88 return 0; 63 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
89}
90
91static int soc_camera_platform_try_fmt(struct soc_camera_device *icd,
92 struct v4l2_format *f)
93{
94 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
95 struct v4l2_pix_format *pix = &f->fmt.pix; 64 struct v4l2_pix_format *pix = &f->fmt.pix;
96 65
97 pix->width = p->format.width; 66 pix->width = p->format.width;
@@ -99,12 +68,11 @@ static int soc_camera_platform_try_fmt(struct soc_camera_device *icd,
99 return 0; 68 return 0;
100} 69}
101 70
102static int soc_camera_platform_video_probe(struct soc_camera_device *icd, 71static void soc_camera_platform_video_probe(struct soc_camera_device *icd,
103 struct platform_device *pdev) 72 struct platform_device *pdev)
104{ 73{
105 struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev); 74 struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev);
106 struct soc_camera_platform_info *p = pdev->dev.platform_data; 75 struct soc_camera_platform_info *p = pdev->dev.platform_data;
107 int ret;
108 76
109 priv->format.name = p->format_name; 77 priv->format.name = p->format_name;
110 priv->format.depth = p->format_depth; 78 priv->format.depth = p->format_depth;
@@ -113,28 +81,29 @@ static int soc_camera_platform_video_probe(struct soc_camera_device *icd,
113 81
114 icd->formats = &priv->format; 82 icd->formats = &priv->format;
115 icd->num_formats = 1; 83 icd->num_formats = 1;
116
117 /* ..._video_start() does dev_set_drvdata(&icd->dev, &pdev->dev) */
118 ret = soc_camera_video_start(icd, &pdev->dev);
119 soc_camera_video_stop(icd);
120 return ret;
121} 84}
122 85
86static struct v4l2_subdev_core_ops platform_subdev_core_ops;
87
88static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
89 .s_stream = soc_camera_platform_s_stream,
90 .try_fmt = soc_camera_platform_try_fmt,
91};
92
93static struct v4l2_subdev_ops platform_subdev_ops = {
94 .core = &platform_subdev_core_ops,
95 .video = &platform_subdev_video_ops,
96};
97
123static struct soc_camera_ops soc_camera_platform_ops = { 98static struct soc_camera_ops soc_camera_platform_ops = {
124 .owner = THIS_MODULE,
125 .init = soc_camera_platform_init,
126 .release = soc_camera_platform_release,
127 .start_capture = soc_camera_platform_start_capture,
128 .stop_capture = soc_camera_platform_stop_capture,
129 .set_crop = soc_camera_platform_set_crop, 99 .set_crop = soc_camera_platform_set_crop,
130 .set_fmt = soc_camera_platform_set_fmt,
131 .try_fmt = soc_camera_platform_try_fmt,
132 .set_bus_param = soc_camera_platform_set_bus_param, 100 .set_bus_param = soc_camera_platform_set_bus_param,
133 .query_bus_param = soc_camera_platform_query_bus_param, 101 .query_bus_param = soc_camera_platform_query_bus_param,
134}; 102};
135 103
136static int soc_camera_platform_probe(struct platform_device *pdev) 104static int soc_camera_platform_probe(struct platform_device *pdev)
137{ 105{
106 struct soc_camera_host *ici;
138 struct soc_camera_platform_priv *priv; 107 struct soc_camera_platform_priv *priv;
139 struct soc_camera_platform_info *p = pdev->dev.platform_data; 108 struct soc_camera_platform_info *p = pdev->dev.platform_data;
140 struct soc_camera_device *icd; 109 struct soc_camera_device *icd;
@@ -143,35 +112,48 @@ static int soc_camera_platform_probe(struct platform_device *pdev)
143 if (!p) 112 if (!p)
144 return -EINVAL; 113 return -EINVAL;
145 114
115 if (!p->dev) {
116 dev_err(&pdev->dev,
117 "Platform has not set soc_camera_device pointer!\n");
118 return -EINVAL;
119 }
120
146 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 121 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
147 if (!priv) 122 if (!priv)
148 return -ENOMEM; 123 return -ENOMEM;
149 124
150 platform_set_drvdata(pdev, priv);
151
152 icd = to_soc_camera_dev(p->dev); 125 icd = to_soc_camera_dev(p->dev);
153 if (!icd)
154 goto enoicd;
155 126
156 icd->ops = &soc_camera_platform_ops; 127 platform_set_drvdata(pdev, priv);
157 dev_set_drvdata(&icd->dev, &pdev->dev); 128 dev_set_drvdata(&icd->dev, &pdev->dev);
129
158 icd->width_min = 0; 130 icd->width_min = 0;
159 icd->width_max = p->format.width; 131 icd->width_max = p->format.width;
160 icd->height_min = 0; 132 icd->height_min = 0;
161 icd->height_max = p->format.height; 133 icd->height_max = p->format.height;
162 icd->y_skip_top = 0; 134 icd->y_skip_top = 0;
135 icd->ops = &soc_camera_platform_ops;
163 136
164 ret = soc_camera_platform_video_probe(icd, pdev); 137 ici = to_soc_camera_host(icd->dev.parent);
165 if (ret) { 138
166 icd->ops = NULL; 139 soc_camera_platform_video_probe(icd, pdev);
167 kfree(priv); 140
168 } 141 v4l2_subdev_init(&priv->subdev, &platform_subdev_ops);
142 v4l2_set_subdevdata(&priv->subdev, p);
143 priv->subdev.grp_id = (__u32)icd;
144 strncpy(priv->subdev.name, dev_name(&pdev->dev), V4L2_SUBDEV_NAME_SIZE);
145
146 ret = v4l2_device_register_subdev(&ici->v4l2_dev, &priv->subdev);
147 if (ret)
148 goto evdrs;
169 149
170 return ret; 150 return ret;
171 151
172enoicd: 152evdrs:
153 icd->ops = NULL;
154 platform_set_drvdata(pdev, NULL);
173 kfree(priv); 155 kfree(priv);
174 return -EINVAL; 156 return ret;
175} 157}
176 158
177static int soc_camera_platform_remove(struct platform_device *pdev) 159static int soc_camera_platform_remove(struct platform_device *pdev)
@@ -180,7 +162,9 @@ static int soc_camera_platform_remove(struct platform_device *pdev)
180 struct soc_camera_platform_info *p = pdev->dev.platform_data; 162 struct soc_camera_platform_info *p = pdev->dev.platform_data;
181 struct soc_camera_device *icd = to_soc_camera_dev(p->dev); 163 struct soc_camera_device *icd = to_soc_camera_dev(p->dev);
182 164
165 v4l2_device_unregister_subdev(&priv->subdev);
183 icd->ops = NULL; 166 icd->ops = NULL;
167 platform_set_drvdata(pdev, NULL);
184 kfree(priv); 168 kfree(priv);
185 return 0; 169 return 0;
186} 170}
@@ -188,6 +172,7 @@ static int soc_camera_platform_remove(struct platform_device *pdev)
188static struct platform_driver soc_camera_platform_driver = { 172static struct platform_driver soc_camera_platform_driver = {
189 .driver = { 173 .driver = {
190 .name = "soc_camera_platform", 174 .name = "soc_camera_platform",
175 .owner = THIS_MODULE,
191 }, 176 },
192 .probe = soc_camera_platform_probe, 177 .probe = soc_camera_platform_probe,
193 .remove = soc_camera_platform_remove, 178 .remove = soc_camera_platform_remove,
diff --git a/drivers/media/video/tw9910.c b/drivers/media/video/tw9910.c
index d780a509faa9..a006df1d28ec 100644
--- a/drivers/media/video/tw9910.c
+++ b/drivers/media/video/tw9910.c
@@ -24,7 +24,7 @@
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/videodev2.h> 25#include <linux/videodev2.h>
26#include <media/v4l2-chip-ident.h> 26#include <media/v4l2-chip-ident.h>
27#include <media/v4l2-common.h> 27#include <media/v4l2-subdev.h>
28#include <media/soc_camera.h> 28#include <media/soc_camera.h>
29#include <media/tw9910.h> 29#include <media/tw9910.h>
30 30
@@ -223,6 +223,7 @@ struct tw9910_hsync_ctrl {
223}; 223};
224 224
225struct tw9910_priv { 225struct tw9910_priv {
226 struct v4l2_subdev subdev;
226 struct tw9910_video_info *info; 227 struct tw9910_video_info *info;
227 const struct tw9910_scale_ctrl *scale; 228 const struct tw9910_scale_ctrl *scale;
228}; 229};
@@ -354,6 +355,11 @@ static const struct tw9910_hsync_ctrl tw9910_hsync_ctrl = {
354/* 355/*
355 * general function 356 * general function
356 */ 357 */
358static struct tw9910_priv *to_tw9910(const struct i2c_client *client)
359{
360 return container_of(i2c_get_clientdata(client), struct tw9910_priv, subdev);
361}
362
357static int tw9910_set_scale(struct i2c_client *client, 363static int tw9910_set_scale(struct i2c_client *client,
358 const struct tw9910_scale_ctrl *scale) 364 const struct tw9910_scale_ctrl *scale)
359{ 365{
@@ -507,47 +513,20 @@ tw9910_select_norm(struct soc_camera_device *icd, u32 width, u32 height)
507/* 513/*
508 * soc_camera_ops function 514 * soc_camera_ops function
509 */ 515 */
510static int tw9910_init(struct soc_camera_device *icd) 516static int tw9910_s_stream(struct v4l2_subdev *sd, int enable)
511{ 517{
512 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 518 struct i2c_client *client = sd->priv;
513 struct soc_camera_link *icl = to_soc_camera_link(icd); 519 struct tw9910_priv *priv = to_tw9910(client);
514 int ret = 0;
515 520
516 if (icl->power) { 521 if (!enable)
517 ret = icl->power(&client->dev, 1); 522 return 0;
518 if (ret < 0)
519 return ret;
520 }
521
522 if (icl->reset)
523 ret = icl->reset(&client->dev);
524
525 return ret;
526}
527
528static int tw9910_release(struct soc_camera_device *icd)
529{
530 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
531 struct soc_camera_link *icl = to_soc_camera_link(icd);
532 int ret = 0;
533
534 if (icl->power)
535 ret = icl->power(&client->dev, 0);
536
537 return ret;
538}
539
540static int tw9910_start_capture(struct soc_camera_device *icd)
541{
542 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
543 struct tw9910_priv *priv = i2c_get_clientdata(client);
544 523
545 if (!priv->scale) { 524 if (!priv->scale) {
546 dev_err(&icd->dev, "norm select error\n"); 525 dev_err(&client->dev, "norm select error\n");
547 return -EPERM; 526 return -EPERM;
548 } 527 }
549 528
550 dev_dbg(&icd->dev, "%s %dx%d\n", 529 dev_dbg(&client->dev, "%s %dx%d\n",
551 priv->scale->name, 530 priv->scale->name,
552 priv->scale->width, 531 priv->scale->width,
553 priv->scale->height); 532 priv->scale->height);
@@ -555,11 +534,6 @@ static int tw9910_start_capture(struct soc_camera_device *icd)
555 return 0; 534 return 0;
556} 535}
557 536
558static int tw9910_stop_capture(struct soc_camera_device *icd)
559{
560 return 0;
561}
562
563static int tw9910_set_bus_param(struct soc_camera_device *icd, 537static int tw9910_set_bus_param(struct soc_camera_device *icd,
564 unsigned long flags) 538 unsigned long flags)
565{ 539{
@@ -569,7 +543,7 @@ static int tw9910_set_bus_param(struct soc_camera_device *icd,
569static unsigned long tw9910_query_bus_param(struct soc_camera_device *icd) 543static unsigned long tw9910_query_bus_param(struct soc_camera_device *icd)
570{ 544{
571 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 545 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
572 struct tw9910_priv *priv = i2c_get_clientdata(client); 546 struct tw9910_priv *priv = to_tw9910(client);
573 struct soc_camera_link *icl = to_soc_camera_link(icd); 547 struct soc_camera_link *icl = to_soc_camera_link(icd);
574 unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER | 548 unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
575 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH | 549 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
@@ -578,21 +552,11 @@ static unsigned long tw9910_query_bus_param(struct soc_camera_device *icd)
578 return soc_camera_apply_sensor_flags(icl, flags); 552 return soc_camera_apply_sensor_flags(icl, flags);
579} 553}
580 554
581static int tw9910_get_chip_id(struct soc_camera_device *icd, 555static int tw9910_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
582 struct v4l2_dbg_chip_ident *id)
583{
584 id->ident = V4L2_IDENT_TW9910;
585 id->revision = 0;
586
587 return 0;
588}
589
590static int tw9910_set_std(struct soc_camera_device *icd,
591 v4l2_std_id *a)
592{ 556{
593 int ret = -EINVAL; 557 int ret = -EINVAL;
594 558
595 if (*a & (V4L2_STD_NTSC | V4L2_STD_PAL)) 559 if (norm & (V4L2_STD_NTSC | V4L2_STD_PAL))
596 ret = 0; 560 ret = 0;
597 561
598 return ret; 562 return ret;
@@ -608,11 +572,20 @@ static int tw9910_enum_input(struct soc_camera_device *icd,
608 return 0; 572 return 0;
609} 573}
610 574
575static int tw9910_g_chip_ident(struct v4l2_subdev *sd,
576 struct v4l2_dbg_chip_ident *id)
577{
578 id->ident = V4L2_IDENT_TW9910;
579 id->revision = 0;
580
581 return 0;
582}
583
611#ifdef CONFIG_VIDEO_ADV_DEBUG 584#ifdef CONFIG_VIDEO_ADV_DEBUG
612static int tw9910_get_register(struct soc_camera_device *icd, 585static int tw9910_g_register(struct v4l2_subdev *sd,
613 struct v4l2_dbg_register *reg) 586 struct v4l2_dbg_register *reg)
614{ 587{
615 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 588 struct i2c_client *client = sd->priv;
616 int ret; 589 int ret;
617 590
618 if (reg->reg > 0xff) 591 if (reg->reg > 0xff)
@@ -630,10 +603,10 @@ static int tw9910_get_register(struct soc_camera_device *icd,
630 return 0; 603 return 0;
631} 604}
632 605
633static int tw9910_set_register(struct soc_camera_device *icd, 606static int tw9910_s_register(struct v4l2_subdev *sd,
634 struct v4l2_dbg_register *reg) 607 struct v4l2_dbg_register *reg)
635{ 608{
636 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 609 struct i2c_client *client = sd->priv;
637 610
638 if (reg->reg > 0xff || 611 if (reg->reg > 0xff ||
639 reg->val > 0xff) 612 reg->val > 0xff)
@@ -647,7 +620,7 @@ static int tw9910_set_crop(struct soc_camera_device *icd,
647 struct v4l2_rect *rect) 620 struct v4l2_rect *rect)
648{ 621{
649 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 622 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
650 struct tw9910_priv *priv = i2c_get_clientdata(client); 623 struct tw9910_priv *priv = to_tw9910(client);
651 int ret = -EINVAL; 624 int ret = -EINVAL;
652 u8 val; 625 u8 val;
653 626
@@ -736,9 +709,10 @@ tw9910_set_fmt_error:
736 return ret; 709 return ret;
737} 710}
738 711
739static int tw9910_set_fmt(struct soc_camera_device *icd, 712static int tw9910_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
740 struct v4l2_format *f)
741{ 713{
714 struct i2c_client *client = sd->priv;
715 struct soc_camera_device *icd = client->dev.platform_data;
742 struct v4l2_pix_format *pix = &f->fmt.pix; 716 struct v4l2_pix_format *pix = &f->fmt.pix;
743 struct v4l2_rect rect = { 717 struct v4l2_rect rect = {
744 .left = icd->x_current, 718 .left = icd->x_current,
@@ -761,16 +735,17 @@ static int tw9910_set_fmt(struct soc_camera_device *icd,
761 return tw9910_set_crop(icd, &rect); 735 return tw9910_set_crop(icd, &rect);
762} 736}
763 737
764static int tw9910_try_fmt(struct soc_camera_device *icd, 738static int tw9910_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
765 struct v4l2_format *f)
766{ 739{
740 struct i2c_client *client = sd->priv;
741 struct soc_camera_device *icd = client->dev.platform_data;
767 struct v4l2_pix_format *pix = &f->fmt.pix; 742 struct v4l2_pix_format *pix = &f->fmt.pix;
768 const struct tw9910_scale_ctrl *scale; 743 const struct tw9910_scale_ctrl *scale;
769 744
770 if (V4L2_FIELD_ANY == pix->field) { 745 if (V4L2_FIELD_ANY == pix->field) {
771 pix->field = V4L2_FIELD_INTERLACED; 746 pix->field = V4L2_FIELD_INTERLACED;
772 } else if (V4L2_FIELD_INTERLACED != pix->field) { 747 } else if (V4L2_FIELD_INTERLACED != pix->field) {
773 dev_err(&icd->dev, "Field type invalid.\n"); 748 dev_err(&client->dev, "Field type invalid.\n");
774 return -EINVAL; 749 return -EINVAL;
775 } 750 }
776 751
@@ -790,9 +765,8 @@ static int tw9910_try_fmt(struct soc_camera_device *icd,
790static int tw9910_video_probe(struct soc_camera_device *icd, 765static int tw9910_video_probe(struct soc_camera_device *icd,
791 struct i2c_client *client) 766 struct i2c_client *client)
792{ 767{
793 struct tw9910_priv *priv = i2c_get_clientdata(client); 768 struct tw9910_priv *priv = to_tw9910(client);
794 s32 val; 769 s32 val;
795 int ret;
796 770
797 /* 771 /*
798 * We must have a parent by now. And it cannot be a wrong one. 772 * We must have a parent by now. And it cannot be a wrong one.
@@ -814,18 +788,11 @@ static int tw9910_video_probe(struct soc_camera_device *icd,
814 icd->formats = tw9910_color_fmt; 788 icd->formats = tw9910_color_fmt;
815 icd->num_formats = ARRAY_SIZE(tw9910_color_fmt); 789 icd->num_formats = ARRAY_SIZE(tw9910_color_fmt);
816 790
817 /* Switch master clock on */
818 ret = soc_camera_video_start(icd, &client->dev);
819 if (ret)
820 return ret;
821
822 /* 791 /*
823 * check and show Product ID 792 * check and show Product ID
824 */ 793 */
825 val = i2c_smbus_read_byte_data(client, ID); 794 val = i2c_smbus_read_byte_data(client, ID);
826 795
827 soc_camera_video_stop(icd);
828
829 if (0x0B != GET_ID(val) || 796 if (0x0B != GET_ID(val) ||
830 0x00 != GET_ReV(val)) { 797 0x00 != GET_ReV(val)) {
831 dev_err(&icd->dev, 798 dev_err(&icd->dev,
@@ -839,29 +806,36 @@ static int tw9910_video_probe(struct soc_camera_device *icd,
839 icd->vdev->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL; 806 icd->vdev->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL;
840 icd->vdev->current_norm = V4L2_STD_NTSC; 807 icd->vdev->current_norm = V4L2_STD_NTSC;
841 808
842 return ret; 809 return 0;
843} 810}
844 811
845static struct soc_camera_ops tw9910_ops = { 812static struct soc_camera_ops tw9910_ops = {
846 .owner = THIS_MODULE,
847 .init = tw9910_init,
848 .release = tw9910_release,
849 .start_capture = tw9910_start_capture,
850 .stop_capture = tw9910_stop_capture,
851 .set_crop = tw9910_set_crop, 813 .set_crop = tw9910_set_crop,
852 .set_fmt = tw9910_set_fmt,
853 .try_fmt = tw9910_try_fmt,
854 .set_bus_param = tw9910_set_bus_param, 814 .set_bus_param = tw9910_set_bus_param,
855 .query_bus_param = tw9910_query_bus_param, 815 .query_bus_param = tw9910_query_bus_param,
856 .get_chip_id = tw9910_get_chip_id,
857 .set_std = tw9910_set_std,
858 .enum_input = tw9910_enum_input, 816 .enum_input = tw9910_enum_input,
817};
818
819static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
820 .g_chip_ident = tw9910_g_chip_ident,
821 .s_std = tw9910_s_std,
859#ifdef CONFIG_VIDEO_ADV_DEBUG 822#ifdef CONFIG_VIDEO_ADV_DEBUG
860 .get_register = tw9910_get_register, 823 .g_register = tw9910_g_register,
861 .set_register = tw9910_set_register, 824 .s_register = tw9910_s_register,
862#endif 825#endif
863}; 826};
864 827
828static struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
829 .s_stream = tw9910_s_stream,
830 .s_fmt = tw9910_s_fmt,
831 .try_fmt = tw9910_try_fmt,
832};
833
834static struct v4l2_subdev_ops tw9910_subdev_ops = {
835 .core = &tw9910_subdev_core_ops,
836 .video = &tw9910_subdev_video_ops,
837};
838
865/* 839/*
866 * i2c_driver function 840 * i2c_driver function
867 */ 841 */
@@ -902,7 +876,8 @@ static int tw9910_probe(struct i2c_client *client,
902 return -ENOMEM; 876 return -ENOMEM;
903 877
904 priv->info = info; 878 priv->info = info;
905 i2c_set_clientdata(client, priv); 879
880 v4l2_i2c_subdev_init(&priv->subdev, client, &tw9910_subdev_ops);
906 881
907 icd->ops = &tw9910_ops; 882 icd->ops = &tw9910_ops;
908 icd->iface = info->link.bus_id; 883 icd->iface = info->link.bus_id;
@@ -942,7 +917,7 @@ static int tw9910_probe(struct i2c_client *client,
942 917
943static int tw9910_remove(struct i2c_client *client) 918static int tw9910_remove(struct i2c_client *client)
944{ 919{
945 struct tw9910_priv *priv = i2c_get_clientdata(client); 920 struct tw9910_priv *priv = to_tw9910(client);
946 struct soc_camera_device *icd = client->dev.platform_data; 921 struct soc_camera_device *icd = client->dev.platform_data;
947 922
948 icd->ops = NULL; 923 icd->ops = NULL;