diff options
author | Guennadi Liakhovetski <g.liakhovetski@gmx.de> | 2009-04-24 11:57:01 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-06-16 17:20:43 -0400 |
commit | 9538e1c226f1fd665126869f542170a2e90f2039 (patch) | |
tree | 3a0b01a6d84980a55eac9e87c9822dec31514006 /drivers | |
parent | eff505fa1511b753b7cfb397a754b8ff4367cd55 (diff) |
V4L/DVB (11610): soc-camera: simplify register access routines in multiple sensor drivers
Register access routines only need the I2C client, not the soc-camera device
context.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/video/mt9m001.c | 105 | ||||
-rw-r--r-- | drivers/media/video/mt9m111.c | 73 | ||||
-rw-r--r-- | drivers/media/video/mt9t031.c | 135 | ||||
-rw-r--r-- | drivers/media/video/mt9v022.c | 135 |
4 files changed, 236 insertions, 212 deletions
diff --git a/drivers/media/video/mt9m001.c b/drivers/media/video/mt9m001.c index 3838ff77381b..459c04cbf69d 100644 --- a/drivers/media/video/mt9m001.c +++ b/drivers/media/video/mt9m001.c | |||
@@ -75,53 +75,50 @@ struct mt9m001 { | |||
75 | unsigned char autoexposure; | 75 | unsigned char autoexposure; |
76 | }; | 76 | }; |
77 | 77 | ||
78 | static int reg_read(struct soc_camera_device *icd, const u8 reg) | 78 | static int reg_read(struct i2c_client *client, const u8 reg) |
79 | { | 79 | { |
80 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); | ||
81 | struct i2c_client *client = mt9m001->client; | ||
82 | s32 data = i2c_smbus_read_word_data(client, reg); | 80 | s32 data = i2c_smbus_read_word_data(client, reg); |
83 | return data < 0 ? data : swab16(data); | 81 | return data < 0 ? data : swab16(data); |
84 | } | 82 | } |
85 | 83 | ||
86 | static int reg_write(struct soc_camera_device *icd, const u8 reg, | 84 | static int reg_write(struct i2c_client *client, const u8 reg, |
87 | const u16 data) | 85 | const u16 data) |
88 | { | 86 | { |
89 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); | 87 | return i2c_smbus_write_word_data(client, reg, swab16(data)); |
90 | return i2c_smbus_write_word_data(mt9m001->client, reg, swab16(data)); | ||
91 | } | 88 | } |
92 | 89 | ||
93 | static int reg_set(struct soc_camera_device *icd, const u8 reg, | 90 | static int reg_set(struct i2c_client *client, const u8 reg, |
94 | const u16 data) | 91 | const u16 data) |
95 | { | 92 | { |
96 | int ret; | 93 | int ret; |
97 | 94 | ||
98 | ret = reg_read(icd, reg); | 95 | ret = reg_read(client, reg); |
99 | if (ret < 0) | 96 | if (ret < 0) |
100 | return ret; | 97 | return ret; |
101 | return reg_write(icd, reg, ret | data); | 98 | return reg_write(client, reg, ret | data); |
102 | } | 99 | } |
103 | 100 | ||
104 | static int reg_clear(struct soc_camera_device *icd, const u8 reg, | 101 | static int reg_clear(struct i2c_client *client, const u8 reg, |
105 | const u16 data) | 102 | const u16 data) |
106 | { | 103 | { |
107 | int ret; | 104 | int ret; |
108 | 105 | ||
109 | ret = reg_read(icd, reg); | 106 | ret = reg_read(client, reg); |
110 | if (ret < 0) | 107 | if (ret < 0) |
111 | return ret; | 108 | return ret; |
112 | return reg_write(icd, reg, ret & ~data); | 109 | return reg_write(client, reg, ret & ~data); |
113 | } | 110 | } |
114 | 111 | ||
115 | static int mt9m001_init(struct soc_camera_device *icd) | 112 | static int mt9m001_init(struct soc_camera_device *icd) |
116 | { | 113 | { |
117 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); | 114 | struct i2c_client *client = to_i2c_client(icd->control); |
118 | struct soc_camera_link *icl = mt9m001->client->dev.platform_data; | 115 | struct soc_camera_link *icl = client->dev.platform_data; |
119 | int ret; | 116 | int ret; |
120 | 117 | ||
121 | dev_dbg(icd->vdev->parent, "%s\n", __func__); | 118 | dev_dbg(icd->vdev->parent, "%s\n", __func__); |
122 | 119 | ||
123 | if (icl->power) { | 120 | if (icl->power) { |
124 | ret = icl->power(&mt9m001->client->dev, 1); | 121 | ret = icl->power(&client->dev, 1); |
125 | if (ret < 0) { | 122 | if (ret < 0) { |
126 | dev_err(icd->vdev->parent, | 123 | dev_err(icd->vdev->parent, |
127 | "Platform failed to power-on the camera.\n"); | 124 | "Platform failed to power-on the camera.\n"); |
@@ -131,49 +128,53 @@ static int mt9m001_init(struct soc_camera_device *icd) | |||
131 | 128 | ||
132 | /* The camera could have been already on, we reset it additionally */ | 129 | /* The camera could have been already on, we reset it additionally */ |
133 | if (icl->reset) | 130 | if (icl->reset) |
134 | ret = icl->reset(&mt9m001->client->dev); | 131 | ret = icl->reset(&client->dev); |
135 | else | 132 | else |
136 | ret = -ENODEV; | 133 | ret = -ENODEV; |
137 | 134 | ||
138 | if (ret < 0) { | 135 | if (ret < 0) { |
139 | /* Either no platform reset, or platform reset failed */ | 136 | /* Either no platform reset, or platform reset failed */ |
140 | ret = reg_write(icd, MT9M001_RESET, 1); | 137 | ret = reg_write(client, MT9M001_RESET, 1); |
141 | if (!ret) | 138 | if (!ret) |
142 | ret = reg_write(icd, MT9M001_RESET, 0); | 139 | ret = reg_write(client, MT9M001_RESET, 0); |
143 | } | 140 | } |
144 | /* Disable chip, synchronous option update */ | 141 | /* Disable chip, synchronous option update */ |
145 | if (!ret) | 142 | if (!ret) |
146 | ret = reg_write(icd, MT9M001_OUTPUT_CONTROL, 0); | 143 | ret = reg_write(client, MT9M001_OUTPUT_CONTROL, 0); |
147 | 144 | ||
148 | return ret; | 145 | return ret; |
149 | } | 146 | } |
150 | 147 | ||
151 | static int mt9m001_release(struct soc_camera_device *icd) | 148 | static int mt9m001_release(struct soc_camera_device *icd) |
152 | { | 149 | { |
153 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); | 150 | struct i2c_client *client = to_i2c_client(icd->control); |
154 | struct soc_camera_link *icl = mt9m001->client->dev.platform_data; | 151 | struct soc_camera_link *icl = client->dev.platform_data; |
155 | 152 | ||
156 | /* Disable the chip */ | 153 | /* Disable the chip */ |
157 | reg_write(icd, MT9M001_OUTPUT_CONTROL, 0); | 154 | reg_write(client, MT9M001_OUTPUT_CONTROL, 0); |
158 | 155 | ||
159 | if (icl->power) | 156 | if (icl->power) |
160 | icl->power(&mt9m001->client->dev, 0); | 157 | icl->power(&client->dev, 0); |
161 | 158 | ||
162 | return 0; | 159 | return 0; |
163 | } | 160 | } |
164 | 161 | ||
165 | static int mt9m001_start_capture(struct soc_camera_device *icd) | 162 | static int mt9m001_start_capture(struct soc_camera_device *icd) |
166 | { | 163 | { |
164 | struct i2c_client *client = to_i2c_client(icd->control); | ||
165 | |||
167 | /* Switch to master "normal" mode */ | 166 | /* Switch to master "normal" mode */ |
168 | if (reg_write(icd, MT9M001_OUTPUT_CONTROL, 2) < 0) | 167 | if (reg_write(client, MT9M001_OUTPUT_CONTROL, 2) < 0) |
169 | return -EIO; | 168 | return -EIO; |
170 | return 0; | 169 | return 0; |
171 | } | 170 | } |
172 | 171 | ||
173 | static int mt9m001_stop_capture(struct soc_camera_device *icd) | 172 | static int mt9m001_stop_capture(struct soc_camera_device *icd) |
174 | { | 173 | { |
174 | struct i2c_client *client = to_i2c_client(icd->control); | ||
175 | |||
175 | /* Stop sensor readout */ | 176 | /* Stop sensor readout */ |
176 | if (reg_write(icd, MT9M001_OUTPUT_CONTROL, 0) < 0) | 177 | if (reg_write(client, MT9M001_OUTPUT_CONTROL, 0) < 0) |
177 | return -EIO; | 178 | return -EIO; |
178 | return 0; | 179 | return 0; |
179 | } | 180 | } |
@@ -222,28 +223,29 @@ static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd) | |||
222 | static int mt9m001_set_crop(struct soc_camera_device *icd, | 223 | static int mt9m001_set_crop(struct soc_camera_device *icd, |
223 | struct v4l2_rect *rect) | 224 | struct v4l2_rect *rect) |
224 | { | 225 | { |
226 | struct i2c_client *client = to_i2c_client(icd->control); | ||
225 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); | 227 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); |
226 | int ret; | 228 | int ret; |
227 | const u16 hblank = 9, vblank = 25; | 229 | const u16 hblank = 9, vblank = 25; |
228 | 230 | ||
229 | /* Blanking and start values - default... */ | 231 | /* Blanking and start values - default... */ |
230 | ret = reg_write(icd, MT9M001_HORIZONTAL_BLANKING, hblank); | 232 | ret = reg_write(client, MT9M001_HORIZONTAL_BLANKING, hblank); |
231 | if (!ret) | 233 | if (!ret) |
232 | ret = reg_write(icd, MT9M001_VERTICAL_BLANKING, vblank); | 234 | ret = reg_write(client, MT9M001_VERTICAL_BLANKING, vblank); |
233 | 235 | ||
234 | /* The caller provides a supported format, as verified per | 236 | /* The caller provides a supported format, as verified per |
235 | * call to icd->try_fmt() */ | 237 | * call to icd->try_fmt() */ |
236 | if (!ret) | 238 | if (!ret) |
237 | ret = reg_write(icd, MT9M001_COLUMN_START, rect->left); | 239 | ret = reg_write(client, MT9M001_COLUMN_START, rect->left); |
238 | if (!ret) | 240 | if (!ret) |
239 | ret = reg_write(icd, MT9M001_ROW_START, rect->top); | 241 | ret = reg_write(client, MT9M001_ROW_START, rect->top); |
240 | if (!ret) | 242 | if (!ret) |
241 | ret = reg_write(icd, MT9M001_WINDOW_WIDTH, rect->width - 1); | 243 | ret = reg_write(client, MT9M001_WINDOW_WIDTH, rect->width - 1); |
242 | if (!ret) | 244 | if (!ret) |
243 | ret = reg_write(icd, MT9M001_WINDOW_HEIGHT, | 245 | ret = reg_write(client, MT9M001_WINDOW_HEIGHT, |
244 | rect->height + icd->y_skip_top - 1); | 246 | rect->height + icd->y_skip_top - 1); |
245 | if (!ret && mt9m001->autoexposure) { | 247 | if (!ret && mt9m001->autoexposure) { |
246 | ret = reg_write(icd, MT9M001_SHUTTER_WIDTH, | 248 | ret = reg_write(client, MT9M001_SHUTTER_WIDTH, |
247 | rect->height + icd->y_skip_top + vblank); | 249 | rect->height + icd->y_skip_top + vblank); |
248 | if (!ret) { | 250 | if (!ret) { |
249 | const struct v4l2_queryctrl *qctrl = | 251 | const struct v4l2_queryctrl *qctrl = |
@@ -312,16 +314,16 @@ static int mt9m001_get_chip_id(struct soc_camera_device *icd, | |||
312 | static int mt9m001_get_register(struct soc_camera_device *icd, | 314 | static int mt9m001_get_register(struct soc_camera_device *icd, |
313 | struct v4l2_dbg_register *reg) | 315 | struct v4l2_dbg_register *reg) |
314 | { | 316 | { |
315 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); | 317 | struct i2c_client *client = to_i2c_client(icd->control); |
316 | 318 | ||
317 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) | 319 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) |
318 | return -EINVAL; | 320 | return -EINVAL; |
319 | 321 | ||
320 | if (reg->match.addr != mt9m001->client->addr) | 322 | if (reg->match.addr != client->addr) |
321 | return -ENODEV; | 323 | return -ENODEV; |
322 | 324 | ||
323 | reg->size = 2; | 325 | reg->size = 2; |
324 | reg->val = reg_read(icd, reg->reg); | 326 | reg->val = reg_read(client, reg->reg); |
325 | 327 | ||
326 | if (reg->val > 0xffff) | 328 | if (reg->val > 0xffff) |
327 | return -EIO; | 329 | return -EIO; |
@@ -332,15 +334,15 @@ static int mt9m001_get_register(struct soc_camera_device *icd, | |||
332 | static int mt9m001_set_register(struct soc_camera_device *icd, | 334 | static int mt9m001_set_register(struct soc_camera_device *icd, |
333 | struct v4l2_dbg_register *reg) | 335 | struct v4l2_dbg_register *reg) |
334 | { | 336 | { |
335 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); | 337 | struct i2c_client *client = to_i2c_client(icd->control); |
336 | 338 | ||
337 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) | 339 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) |
338 | return -EINVAL; | 340 | return -EINVAL; |
339 | 341 | ||
340 | if (reg->match.addr != mt9m001->client->addr) | 342 | if (reg->match.addr != client->addr) |
341 | return -ENODEV; | 343 | return -ENODEV; |
342 | 344 | ||
343 | if (reg_write(icd, reg->reg, reg->val) < 0) | 345 | if (reg_write(client, reg->reg, reg->val) < 0) |
344 | return -EIO; | 346 | return -EIO; |
345 | 347 | ||
346 | return 0; | 348 | return 0; |
@@ -416,12 +418,13 @@ static struct soc_camera_ops mt9m001_ops = { | |||
416 | 418 | ||
417 | static int mt9m001_get_control(struct soc_camera_device *icd, struct v4l2_control *ctrl) | 419 | static int mt9m001_get_control(struct soc_camera_device *icd, struct v4l2_control *ctrl) |
418 | { | 420 | { |
421 | struct i2c_client *client = to_i2c_client(icd->control); | ||
419 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); | 422 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); |
420 | int data; | 423 | int data; |
421 | 424 | ||
422 | switch (ctrl->id) { | 425 | switch (ctrl->id) { |
423 | case V4L2_CID_VFLIP: | 426 | case V4L2_CID_VFLIP: |
424 | data = reg_read(icd, MT9M001_READ_OPTIONS2); | 427 | data = reg_read(client, MT9M001_READ_OPTIONS2); |
425 | if (data < 0) | 428 | if (data < 0) |
426 | return -EIO; | 429 | return -EIO; |
427 | ctrl->value = !!(data & 0x8000); | 430 | ctrl->value = !!(data & 0x8000); |
@@ -435,6 +438,7 @@ static int mt9m001_get_control(struct soc_camera_device *icd, struct v4l2_contro | |||
435 | 438 | ||
436 | static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_control *ctrl) | 439 | static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_control *ctrl) |
437 | { | 440 | { |
441 | struct i2c_client *client = to_i2c_client(icd->control); | ||
438 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); | 442 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); |
439 | const struct v4l2_queryctrl *qctrl; | 443 | const struct v4l2_queryctrl *qctrl; |
440 | int data; | 444 | int data; |
@@ -447,9 +451,9 @@ static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_contro | |||
447 | switch (ctrl->id) { | 451 | switch (ctrl->id) { |
448 | case V4L2_CID_VFLIP: | 452 | case V4L2_CID_VFLIP: |
449 | if (ctrl->value) | 453 | if (ctrl->value) |
450 | data = reg_set(icd, MT9M001_READ_OPTIONS2, 0x8000); | 454 | data = reg_set(client, MT9M001_READ_OPTIONS2, 0x8000); |
451 | else | 455 | else |
452 | data = reg_clear(icd, MT9M001_READ_OPTIONS2, 0x8000); | 456 | data = reg_clear(client, MT9M001_READ_OPTIONS2, 0x8000); |
453 | if (data < 0) | 457 | if (data < 0) |
454 | return -EIO; | 458 | return -EIO; |
455 | break; | 459 | break; |
@@ -463,7 +467,7 @@ static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_contro | |||
463 | data = ((ctrl->value - qctrl->minimum) * 8 + range / 2) / range; | 467 | data = ((ctrl->value - qctrl->minimum) * 8 + range / 2) / range; |
464 | 468 | ||
465 | dev_dbg(&icd->dev, "Setting gain %d\n", data); | 469 | dev_dbg(&icd->dev, "Setting gain %d\n", data); |
466 | data = reg_write(icd, MT9M001_GLOBAL_GAIN, data); | 470 | data = reg_write(client, MT9M001_GLOBAL_GAIN, data); |
467 | if (data < 0) | 471 | if (data < 0) |
468 | return -EIO; | 472 | return -EIO; |
469 | } else { | 473 | } else { |
@@ -481,8 +485,8 @@ static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_contro | |||
481 | data = ((gain - 64) * 7 + 28) / 56 + 96; | 485 | data = ((gain - 64) * 7 + 28) / 56 + 96; |
482 | 486 | ||
483 | dev_dbg(&icd->dev, "Setting gain from %d to %d\n", | 487 | dev_dbg(&icd->dev, "Setting gain from %d to %d\n", |
484 | reg_read(icd, MT9M001_GLOBAL_GAIN), data); | 488 | reg_read(client, MT9M001_GLOBAL_GAIN), data); |
485 | data = reg_write(icd, MT9M001_GLOBAL_GAIN, data); | 489 | data = reg_write(client, MT9M001_GLOBAL_GAIN, data); |
486 | if (data < 0) | 490 | if (data < 0) |
487 | return -EIO; | 491 | return -EIO; |
488 | } | 492 | } |
@@ -500,8 +504,8 @@ static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_contro | |||
500 | range / 2) / range + 1; | 504 | range / 2) / range + 1; |
501 | 505 | ||
502 | dev_dbg(&icd->dev, "Setting shutter width from %d to %lu\n", | 506 | dev_dbg(&icd->dev, "Setting shutter width from %d to %lu\n", |
503 | reg_read(icd, MT9M001_SHUTTER_WIDTH), shutter); | 507 | reg_read(client, MT9M001_SHUTTER_WIDTH), shutter); |
504 | if (reg_write(icd, MT9M001_SHUTTER_WIDTH, shutter) < 0) | 508 | if (reg_write(client, MT9M001_SHUTTER_WIDTH, shutter) < 0) |
505 | return -EIO; | 509 | return -EIO; |
506 | icd->exposure = ctrl->value; | 510 | icd->exposure = ctrl->value; |
507 | mt9m001->autoexposure = 0; | 511 | mt9m001->autoexposure = 0; |
@@ -510,7 +514,7 @@ static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_contro | |||
510 | case V4L2_CID_EXPOSURE_AUTO: | 514 | case V4L2_CID_EXPOSURE_AUTO: |
511 | if (ctrl->value) { | 515 | if (ctrl->value) { |
512 | const u16 vblank = 25; | 516 | const u16 vblank = 25; |
513 | if (reg_write(icd, MT9M001_SHUTTER_WIDTH, icd->height + | 517 | if (reg_write(client, MT9M001_SHUTTER_WIDTH, icd->height + |
514 | icd->y_skip_top + vblank) < 0) | 518 | icd->y_skip_top + vblank) < 0) |
515 | return -EIO; | 519 | return -EIO; |
516 | qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE); | 520 | qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE); |
@@ -529,8 +533,9 @@ static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_contro | |||
529 | * this wasn't our capture interface, so, we wait for the right one */ | 533 | * this wasn't our capture interface, so, we wait for the right one */ |
530 | static int mt9m001_video_probe(struct soc_camera_device *icd) | 534 | static int mt9m001_video_probe(struct soc_camera_device *icd) |
531 | { | 535 | { |
536 | struct i2c_client *client = to_i2c_client(icd->control); | ||
532 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); | 537 | struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); |
533 | struct soc_camera_link *icl = mt9m001->client->dev.platform_data; | 538 | struct soc_camera_link *icl = client->dev.platform_data; |
534 | s32 data; | 539 | s32 data; |
535 | int ret; | 540 | int ret; |
536 | unsigned long flags; | 541 | unsigned long flags; |
@@ -542,11 +547,11 @@ static int mt9m001_video_probe(struct soc_camera_device *icd) | |||
542 | return -ENODEV; | 547 | return -ENODEV; |
543 | 548 | ||
544 | /* Enable the chip */ | 549 | /* Enable the chip */ |
545 | data = reg_write(icd, MT9M001_CHIP_ENABLE, 1); | 550 | data = reg_write(client, MT9M001_CHIP_ENABLE, 1); |
546 | dev_dbg(&icd->dev, "write: %d\n", data); | 551 | dev_dbg(&icd->dev, "write: %d\n", data); |
547 | 552 | ||
548 | /* Read out the chip version register */ | 553 | /* Read out the chip version register */ |
549 | data = reg_read(icd, MT9M001_CHIP_VERSION); | 554 | data = reg_read(client, MT9M001_CHIP_VERSION); |
550 | 555 | ||
551 | /* must be 0x8411 or 0x8421 for colour sensor and 8431 for bw */ | 556 | /* must be 0x8411 or 0x8421 for colour sensor and 8431 for bw */ |
552 | switch (data) { | 557 | switch (data) { |
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c index cdd1ddb51388..fc5e2de03766 100644 --- a/drivers/media/video/mt9m111.c +++ b/drivers/media/video/mt9m111.c | |||
@@ -113,10 +113,10 @@ | |||
113 | * mt9m111: Camera control register addresses (0x200..0x2ff not implemented) | 113 | * mt9m111: Camera control register addresses (0x200..0x2ff not implemented) |
114 | */ | 114 | */ |
115 | 115 | ||
116 | #define reg_read(reg) mt9m111_reg_read(icd, MT9M111_##reg) | 116 | #define reg_read(reg) mt9m111_reg_read(client, MT9M111_##reg) |
117 | #define reg_write(reg, val) mt9m111_reg_write(icd, MT9M111_##reg, (val)) | 117 | #define reg_write(reg, val) mt9m111_reg_write(client, MT9M111_##reg, (val)) |
118 | #define reg_set(reg, val) mt9m111_reg_set(icd, MT9M111_##reg, (val)) | 118 | #define reg_set(reg, val) mt9m111_reg_set(client, MT9M111_##reg, (val)) |
119 | #define reg_clear(reg, val) mt9m111_reg_clear(icd, MT9M111_##reg, (val)) | 119 | #define reg_clear(reg, val) mt9m111_reg_clear(client, MT9M111_##reg, (val)) |
120 | 120 | ||
121 | #define MT9M111_MIN_DARK_ROWS 8 | 121 | #define MT9M111_MIN_DARK_ROWS 8 |
122 | #define MT9M111_MIN_DARK_COLS 24 | 122 | #define MT9M111_MIN_DARK_COLS 24 |
@@ -184,58 +184,55 @@ static int reg_page_map_set(struct i2c_client *client, const u16 reg) | |||
184 | return ret; | 184 | return ret; |
185 | } | 185 | } |
186 | 186 | ||
187 | static int mt9m111_reg_read(struct soc_camera_device *icd, const u16 reg) | 187 | static int mt9m111_reg_read(struct i2c_client *client, const u16 reg) |
188 | { | 188 | { |
189 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); | ||
190 | struct i2c_client *client = mt9m111->client; | ||
191 | int ret; | 189 | int ret; |
192 | 190 | ||
193 | ret = reg_page_map_set(client, reg); | 191 | ret = reg_page_map_set(client, reg); |
194 | if (!ret) | 192 | if (!ret) |
195 | ret = swab16(i2c_smbus_read_word_data(client, (reg & 0xff))); | 193 | ret = swab16(i2c_smbus_read_word_data(client, (reg & 0xff))); |
196 | 194 | ||
197 | dev_dbg(&icd->dev, "read reg.%03x -> %04x\n", reg, ret); | 195 | dev_dbg(&client->dev, "read reg.%03x -> %04x\n", reg, ret); |
198 | return ret; | 196 | return ret; |
199 | } | 197 | } |
200 | 198 | ||
201 | static int mt9m111_reg_write(struct soc_camera_device *icd, const u16 reg, | 199 | static int mt9m111_reg_write(struct i2c_client *client, const u16 reg, |
202 | const u16 data) | 200 | const u16 data) |
203 | { | 201 | { |
204 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); | ||
205 | struct i2c_client *client = mt9m111->client; | ||
206 | int ret; | 202 | int ret; |
207 | 203 | ||
208 | ret = reg_page_map_set(client, reg); | 204 | ret = reg_page_map_set(client, reg); |
209 | if (!ret) | 205 | if (!ret) |
210 | ret = i2c_smbus_write_word_data(mt9m111->client, (reg & 0xff), | 206 | ret = i2c_smbus_write_word_data(client, (reg & 0xff), |
211 | swab16(data)); | 207 | swab16(data)); |
212 | dev_dbg(&icd->dev, "write reg.%03x = %04x -> %d\n", reg, data, ret); | 208 | dev_dbg(&client->dev, "write reg.%03x = %04x -> %d\n", reg, data, ret); |
213 | return ret; | 209 | return ret; |
214 | } | 210 | } |
215 | 211 | ||
216 | static int mt9m111_reg_set(struct soc_camera_device *icd, const u16 reg, | 212 | static int mt9m111_reg_set(struct i2c_client *client, const u16 reg, |
217 | const u16 data) | 213 | const u16 data) |
218 | { | 214 | { |
219 | int ret; | 215 | int ret; |
220 | 216 | ||
221 | ret = mt9m111_reg_read(icd, reg); | 217 | ret = mt9m111_reg_read(client, reg); |
222 | if (ret >= 0) | 218 | if (ret >= 0) |
223 | ret = mt9m111_reg_write(icd, reg, ret | data); | 219 | ret = mt9m111_reg_write(client, reg, ret | data); |
224 | return ret; | 220 | return ret; |
225 | } | 221 | } |
226 | 222 | ||
227 | static int mt9m111_reg_clear(struct soc_camera_device *icd, const u16 reg, | 223 | static int mt9m111_reg_clear(struct i2c_client *client, const u16 reg, |
228 | const u16 data) | 224 | const u16 data) |
229 | { | 225 | { |
230 | int ret; | 226 | int ret; |
231 | 227 | ||
232 | ret = mt9m111_reg_read(icd, reg); | 228 | ret = mt9m111_reg_read(client, reg); |
233 | return mt9m111_reg_write(icd, reg, ret & ~data); | 229 | return mt9m111_reg_write(client, reg, ret & ~data); |
234 | } | 230 | } |
235 | 231 | ||
236 | static int mt9m111_set_context(struct soc_camera_device *icd, | 232 | static int mt9m111_set_context(struct soc_camera_device *icd, |
237 | enum mt9m111_context ctxt) | 233 | enum mt9m111_context ctxt) |
238 | { | 234 | { |
235 | struct i2c_client *client = to_i2c_client(icd->control); | ||
239 | int valB = MT9M111_CTXT_CTRL_RESTART | MT9M111_CTXT_CTRL_DEFECTCOR_B | 236 | int valB = MT9M111_CTXT_CTRL_RESTART | MT9M111_CTXT_CTRL_DEFECTCOR_B |
240 | | MT9M111_CTXT_CTRL_RESIZE_B | MT9M111_CTXT_CTRL_CTRL2_B | 237 | | MT9M111_CTXT_CTRL_RESIZE_B | MT9M111_CTXT_CTRL_CTRL2_B |
241 | | MT9M111_CTXT_CTRL_GAMMA_B | MT9M111_CTXT_CTRL_READ_MODE_B | 238 | | MT9M111_CTXT_CTRL_GAMMA_B | MT9M111_CTXT_CTRL_READ_MODE_B |
@@ -252,6 +249,7 @@ static int mt9m111_set_context(struct soc_camera_device *icd, | |||
252 | static int mt9m111_setup_rect(struct soc_camera_device *icd, | 249 | static int mt9m111_setup_rect(struct soc_camera_device *icd, |
253 | struct v4l2_rect *rect) | 250 | struct v4l2_rect *rect) |
254 | { | 251 | { |
252 | struct i2c_client *client = to_i2c_client(icd->control); | ||
255 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); | 253 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); |
256 | int ret, is_raw_format; | 254 | int ret, is_raw_format; |
257 | int width = rect->width; | 255 | int width = rect->width; |
@@ -296,6 +294,7 @@ static int mt9m111_setup_rect(struct soc_camera_device *icd, | |||
296 | 294 | ||
297 | static int mt9m111_setup_pixfmt(struct soc_camera_device *icd, u16 outfmt) | 295 | static int mt9m111_setup_pixfmt(struct soc_camera_device *icd, u16 outfmt) |
298 | { | 296 | { |
297 | struct i2c_client *client = to_i2c_client(icd->control); | ||
299 | int ret; | 298 | int ret; |
300 | 299 | ||
301 | ret = reg_write(OUTPUT_FORMAT_CTRL2_A, outfmt); | 300 | ret = reg_write(OUTPUT_FORMAT_CTRL2_A, outfmt); |
@@ -357,12 +356,13 @@ static int mt9m111_setfmt_yuv(struct soc_camera_device *icd) | |||
357 | 356 | ||
358 | static int mt9m111_enable(struct soc_camera_device *icd) | 357 | static int mt9m111_enable(struct soc_camera_device *icd) |
359 | { | 358 | { |
359 | struct i2c_client *client = to_i2c_client(icd->control); | ||
360 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); | 360 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); |
361 | struct soc_camera_link *icl = mt9m111->client->dev.platform_data; | 361 | struct soc_camera_link *icl = client->dev.platform_data; |
362 | int ret; | 362 | int ret; |
363 | 363 | ||
364 | if (icl->power) { | 364 | if (icl->power) { |
365 | ret = icl->power(&mt9m111->client->dev, 1); | 365 | ret = icl->power(&client->dev, 1); |
366 | if (ret < 0) { | 366 | if (ret < 0) { |
367 | dev_err(icd->vdev->parent, | 367 | dev_err(icd->vdev->parent, |
368 | "Platform failed to power-on the camera.\n"); | 368 | "Platform failed to power-on the camera.\n"); |
@@ -378,8 +378,9 @@ static int mt9m111_enable(struct soc_camera_device *icd) | |||
378 | 378 | ||
379 | static int mt9m111_disable(struct soc_camera_device *icd) | 379 | static int mt9m111_disable(struct soc_camera_device *icd) |
380 | { | 380 | { |
381 | struct i2c_client *client = to_i2c_client(icd->control); | ||
381 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); | 382 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); |
382 | struct soc_camera_link *icl = mt9m111->client->dev.platform_data; | 383 | struct soc_camera_link *icl = client->dev.platform_data; |
383 | int ret; | 384 | int ret; |
384 | 385 | ||
385 | ret = reg_clear(RESET, MT9M111_RESET_CHIP_ENABLE); | 386 | ret = reg_clear(RESET, MT9M111_RESET_CHIP_ENABLE); |
@@ -387,15 +388,15 @@ static int mt9m111_disable(struct soc_camera_device *icd) | |||
387 | mt9m111->powered = 0; | 388 | mt9m111->powered = 0; |
388 | 389 | ||
389 | if (icl->power) | 390 | if (icl->power) |
390 | icl->power(&mt9m111->client->dev, 0); | 391 | icl->power(&client->dev, 0); |
391 | 392 | ||
392 | return ret; | 393 | return ret; |
393 | } | 394 | } |
394 | 395 | ||
395 | static int mt9m111_reset(struct soc_camera_device *icd) | 396 | static int mt9m111_reset(struct soc_camera_device *icd) |
396 | { | 397 | { |
397 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); | 398 | struct i2c_client *client = to_i2c_client(icd->control); |
398 | struct soc_camera_link *icl = mt9m111->client->dev.platform_data; | 399 | struct soc_camera_link *icl = client->dev.platform_data; |
399 | int ret; | 400 | int ret; |
400 | 401 | ||
401 | ret = reg_set(RESET, MT9M111_RESET_RESET_MODE); | 402 | ret = reg_set(RESET, MT9M111_RESET_RESET_MODE); |
@@ -406,7 +407,7 @@ static int mt9m111_reset(struct soc_camera_device *icd) | |||
406 | | MT9M111_RESET_RESET_SOC); | 407 | | MT9M111_RESET_RESET_SOC); |
407 | 408 | ||
408 | if (icl->reset) | 409 | if (icl->reset) |
409 | icl->reset(&mt9m111->client->dev); | 410 | icl->reset(&client->dev); |
410 | 411 | ||
411 | return ret; | 412 | return ret; |
412 | } | 413 | } |
@@ -562,15 +563,14 @@ static int mt9m111_get_register(struct soc_camera_device *icd, | |||
562 | struct v4l2_dbg_register *reg) | 563 | struct v4l2_dbg_register *reg) |
563 | { | 564 | { |
564 | int val; | 565 | int val; |
565 | 566 | struct i2c_client *client = to_i2c_client(icd->control); | |
566 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); | ||
567 | 567 | ||
568 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff) | 568 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff) |
569 | return -EINVAL; | 569 | return -EINVAL; |
570 | if (reg->match.addr != mt9m111->client->addr) | 570 | if (reg->match.addr != client->addr) |
571 | return -ENODEV; | 571 | return -ENODEV; |
572 | 572 | ||
573 | val = mt9m111_reg_read(icd, reg->reg); | 573 | val = mt9m111_reg_read(client, reg->reg); |
574 | reg->size = 2; | 574 | reg->size = 2; |
575 | reg->val = (u64)val; | 575 | reg->val = (u64)val; |
576 | 576 | ||
@@ -583,15 +583,15 @@ static int mt9m111_get_register(struct soc_camera_device *icd, | |||
583 | static int mt9m111_set_register(struct soc_camera_device *icd, | 583 | static int mt9m111_set_register(struct soc_camera_device *icd, |
584 | struct v4l2_dbg_register *reg) | 584 | struct v4l2_dbg_register *reg) |
585 | { | 585 | { |
586 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); | 586 | struct i2c_client *client = to_i2c_client(icd->control); |
587 | 587 | ||
588 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff) | 588 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff) |
589 | return -EINVAL; | 589 | return -EINVAL; |
590 | 590 | ||
591 | if (reg->match.addr != mt9m111->client->addr) | 591 | if (reg->match.addr != client->addr) |
592 | return -ENODEV; | 592 | return -ENODEV; |
593 | 593 | ||
594 | if (mt9m111_reg_write(icd, reg->reg, reg->val) < 0) | 594 | if (mt9m111_reg_write(client, reg->reg, reg->val) < 0) |
595 | return -EIO; | 595 | return -EIO; |
596 | 596 | ||
597 | return 0; | 597 | return 0; |
@@ -672,6 +672,7 @@ static struct soc_camera_ops mt9m111_ops = { | |||
672 | 672 | ||
673 | static int mt9m111_set_flip(struct soc_camera_device *icd, int flip, int mask) | 673 | static int mt9m111_set_flip(struct soc_camera_device *icd, int flip, int mask) |
674 | { | 674 | { |
675 | struct i2c_client *client = to_i2c_client(icd->control); | ||
675 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); | 676 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); |
676 | int ret; | 677 | int ret; |
677 | 678 | ||
@@ -692,6 +693,7 @@ static int mt9m111_set_flip(struct soc_camera_device *icd, int flip, int mask) | |||
692 | 693 | ||
693 | static int mt9m111_get_global_gain(struct soc_camera_device *icd) | 694 | static int mt9m111_get_global_gain(struct soc_camera_device *icd) |
694 | { | 695 | { |
696 | struct i2c_client *client = to_i2c_client(icd->control); | ||
695 | int data; | 697 | int data; |
696 | 698 | ||
697 | data = reg_read(GLOBAL_GAIN); | 699 | data = reg_read(GLOBAL_GAIN); |
@@ -703,6 +705,7 @@ static int mt9m111_get_global_gain(struct soc_camera_device *icd) | |||
703 | 705 | ||
704 | static int mt9m111_set_global_gain(struct soc_camera_device *icd, int gain) | 706 | static int mt9m111_set_global_gain(struct soc_camera_device *icd, int gain) |
705 | { | 707 | { |
708 | struct i2c_client *client = to_i2c_client(icd->control); | ||
706 | u16 val; | 709 | u16 val; |
707 | 710 | ||
708 | if (gain > 63 * 2 * 2) | 711 | if (gain > 63 * 2 * 2) |
@@ -721,6 +724,7 @@ static int mt9m111_set_global_gain(struct soc_camera_device *icd, int gain) | |||
721 | 724 | ||
722 | static int mt9m111_set_autoexposure(struct soc_camera_device *icd, int on) | 725 | static int mt9m111_set_autoexposure(struct soc_camera_device *icd, int on) |
723 | { | 726 | { |
727 | struct i2c_client *client = to_i2c_client(icd->control); | ||
724 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); | 728 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); |
725 | int ret; | 729 | int ret; |
726 | 730 | ||
@@ -737,6 +741,7 @@ static int mt9m111_set_autoexposure(struct soc_camera_device *icd, int on) | |||
737 | 741 | ||
738 | static int mt9m111_set_autowhitebalance(struct soc_camera_device *icd, int on) | 742 | static int mt9m111_set_autowhitebalance(struct soc_camera_device *icd, int on) |
739 | { | 743 | { |
744 | struct i2c_client *client = to_i2c_client(icd->control); | ||
740 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); | 745 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); |
741 | int ret; | 746 | int ret; |
742 | 747 | ||
@@ -754,6 +759,7 @@ static int mt9m111_set_autowhitebalance(struct soc_camera_device *icd, int on) | |||
754 | static int mt9m111_get_control(struct soc_camera_device *icd, | 759 | static int mt9m111_get_control(struct soc_camera_device *icd, |
755 | struct v4l2_control *ctrl) | 760 | struct v4l2_control *ctrl) |
756 | { | 761 | { |
762 | struct i2c_client *client = to_i2c_client(icd->control); | ||
757 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); | 763 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); |
758 | int data; | 764 | int data; |
759 | 765 | ||
@@ -898,6 +904,7 @@ static int mt9m111_release(struct soc_camera_device *icd) | |||
898 | */ | 904 | */ |
899 | static int mt9m111_video_probe(struct soc_camera_device *icd) | 905 | static int mt9m111_video_probe(struct soc_camera_device *icd) |
900 | { | 906 | { |
907 | struct i2c_client *client = to_i2c_client(icd->control); | ||
901 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); | 908 | struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); |
902 | s32 data; | 909 | s32 data; |
903 | int ret; | 910 | int ret; |
diff --git a/drivers/media/video/mt9t031.c b/drivers/media/video/mt9t031.c index 2b0927bfd217..f72aeb7c4deb 100644 --- a/drivers/media/video/mt9t031.c +++ b/drivers/media/video/mt9t031.c | |||
@@ -76,64 +76,61 @@ struct mt9t031 { | |||
76 | u16 yskip; | 76 | u16 yskip; |
77 | }; | 77 | }; |
78 | 78 | ||
79 | static int reg_read(struct soc_camera_device *icd, const u8 reg) | 79 | static int reg_read(struct i2c_client *client, const u8 reg) |
80 | { | 80 | { |
81 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); | ||
82 | struct i2c_client *client = mt9t031->client; | ||
83 | s32 data = i2c_smbus_read_word_data(client, reg); | 81 | s32 data = i2c_smbus_read_word_data(client, reg); |
84 | return data < 0 ? data : swab16(data); | 82 | return data < 0 ? data : swab16(data); |
85 | } | 83 | } |
86 | 84 | ||
87 | static int reg_write(struct soc_camera_device *icd, const u8 reg, | 85 | static int reg_write(struct i2c_client *client, const u8 reg, |
88 | const u16 data) | 86 | const u16 data) |
89 | { | 87 | { |
90 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); | 88 | return i2c_smbus_write_word_data(client, reg, swab16(data)); |
91 | return i2c_smbus_write_word_data(mt9t031->client, reg, swab16(data)); | ||
92 | } | 89 | } |
93 | 90 | ||
94 | static int reg_set(struct soc_camera_device *icd, const u8 reg, | 91 | static int reg_set(struct i2c_client *client, const u8 reg, |
95 | const u16 data) | 92 | const u16 data) |
96 | { | 93 | { |
97 | int ret; | 94 | int ret; |
98 | 95 | ||
99 | ret = reg_read(icd, reg); | 96 | ret = reg_read(client, reg); |
100 | if (ret < 0) | 97 | if (ret < 0) |
101 | return ret; | 98 | return ret; |
102 | return reg_write(icd, reg, ret | data); | 99 | return reg_write(client, reg, ret | data); |
103 | } | 100 | } |
104 | 101 | ||
105 | static int reg_clear(struct soc_camera_device *icd, const u8 reg, | 102 | static int reg_clear(struct i2c_client *client, const u8 reg, |
106 | const u16 data) | 103 | const u16 data) |
107 | { | 104 | { |
108 | int ret; | 105 | int ret; |
109 | 106 | ||
110 | ret = reg_read(icd, reg); | 107 | ret = reg_read(client, reg); |
111 | if (ret < 0) | 108 | if (ret < 0) |
112 | return ret; | 109 | return ret; |
113 | return reg_write(icd, reg, ret & ~data); | 110 | return reg_write(client, reg, ret & ~data); |
114 | } | 111 | } |
115 | 112 | ||
116 | static int set_shutter(struct soc_camera_device *icd, const u32 data) | 113 | static int set_shutter(struct i2c_client *client, const u32 data) |
117 | { | 114 | { |
118 | int ret; | 115 | int ret; |
119 | 116 | ||
120 | ret = reg_write(icd, MT9T031_SHUTTER_WIDTH_UPPER, data >> 16); | 117 | ret = reg_write(client, MT9T031_SHUTTER_WIDTH_UPPER, data >> 16); |
121 | 118 | ||
122 | if (ret >= 0) | 119 | if (ret >= 0) |
123 | ret = reg_write(icd, MT9T031_SHUTTER_WIDTH, data & 0xffff); | 120 | ret = reg_write(client, MT9T031_SHUTTER_WIDTH, data & 0xffff); |
124 | 121 | ||
125 | return ret; | 122 | return ret; |
126 | } | 123 | } |
127 | 124 | ||
128 | static int get_shutter(struct soc_camera_device *icd, u32 *data) | 125 | static int get_shutter(struct i2c_client *client, u32 *data) |
129 | { | 126 | { |
130 | int ret; | 127 | int ret; |
131 | 128 | ||
132 | ret = reg_read(icd, MT9T031_SHUTTER_WIDTH_UPPER); | 129 | ret = reg_read(client, MT9T031_SHUTTER_WIDTH_UPPER); |
133 | *data = ret << 16; | 130 | *data = ret << 16; |
134 | 131 | ||
135 | if (ret >= 0) | 132 | if (ret >= 0) |
136 | ret = reg_read(icd, MT9T031_SHUTTER_WIDTH); | 133 | ret = reg_read(client, MT9T031_SHUTTER_WIDTH); |
137 | *data |= ret & 0xffff; | 134 | *data |= ret & 0xffff; |
138 | 135 | ||
139 | return ret < 0 ? ret : 0; | 136 | return ret < 0 ? ret : 0; |
@@ -141,12 +138,12 @@ static int get_shutter(struct soc_camera_device *icd, u32 *data) | |||
141 | 138 | ||
142 | static int mt9t031_init(struct soc_camera_device *icd) | 139 | static int mt9t031_init(struct soc_camera_device *icd) |
143 | { | 140 | { |
144 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); | 141 | struct i2c_client *client = to_i2c_client(icd->control); |
145 | struct soc_camera_link *icl = mt9t031->client->dev.platform_data; | 142 | struct soc_camera_link *icl = client->dev.platform_data; |
146 | int ret; | 143 | int ret; |
147 | 144 | ||
148 | if (icl->power) { | 145 | if (icl->power) { |
149 | ret = icl->power(&mt9t031->client->dev, 1); | 146 | ret = icl->power(&client->dev, 1); |
150 | if (ret < 0) { | 147 | if (ret < 0) { |
151 | dev_err(icd->vdev->parent, | 148 | dev_err(icd->vdev->parent, |
152 | "Platform failed to power-on the camera.\n"); | 149 | "Platform failed to power-on the camera.\n"); |
@@ -155,44 +152,48 @@ static int mt9t031_init(struct soc_camera_device *icd) | |||
155 | } | 152 | } |
156 | 153 | ||
157 | /* Disable chip output, synchronous option update */ | 154 | /* Disable chip output, synchronous option update */ |
158 | ret = reg_write(icd, MT9T031_RESET, 1); | 155 | ret = reg_write(client, MT9T031_RESET, 1); |
159 | if (ret >= 0) | 156 | if (ret >= 0) |
160 | ret = reg_write(icd, MT9T031_RESET, 0); | 157 | ret = reg_write(client, MT9T031_RESET, 0); |
161 | if (ret >= 0) | 158 | if (ret >= 0) |
162 | ret = reg_clear(icd, MT9T031_OUTPUT_CONTROL, 2); | 159 | ret = reg_clear(client, MT9T031_OUTPUT_CONTROL, 2); |
163 | 160 | ||
164 | if (ret < 0 && icl->power) | 161 | if (ret < 0 && icl->power) |
165 | icl->power(&mt9t031->client->dev, 0); | 162 | icl->power(&client->dev, 0); |
166 | 163 | ||
167 | return ret >= 0 ? 0 : -EIO; | 164 | return ret >= 0 ? 0 : -EIO; |
168 | } | 165 | } |
169 | 166 | ||
170 | static int mt9t031_release(struct soc_camera_device *icd) | 167 | static int mt9t031_release(struct soc_camera_device *icd) |
171 | { | 168 | { |
172 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); | 169 | struct i2c_client *client = to_i2c_client(icd->control); |
173 | struct soc_camera_link *icl = mt9t031->client->dev.platform_data; | 170 | struct soc_camera_link *icl = client->dev.platform_data; |
174 | 171 | ||
175 | /* Disable the chip */ | 172 | /* Disable the chip */ |
176 | reg_clear(icd, MT9T031_OUTPUT_CONTROL, 2); | 173 | reg_clear(client, MT9T031_OUTPUT_CONTROL, 2); |
177 | 174 | ||
178 | if (icl->power) | 175 | if (icl->power) |
179 | icl->power(&mt9t031->client->dev, 0); | 176 | icl->power(&client->dev, 0); |
180 | 177 | ||
181 | return 0; | 178 | return 0; |
182 | } | 179 | } |
183 | 180 | ||
184 | static int mt9t031_start_capture(struct soc_camera_device *icd) | 181 | static int mt9t031_start_capture(struct soc_camera_device *icd) |
185 | { | 182 | { |
183 | struct i2c_client *client = to_i2c_client(icd->control); | ||
184 | |||
186 | /* Switch to master "normal" mode */ | 185 | /* Switch to master "normal" mode */ |
187 | if (reg_set(icd, MT9T031_OUTPUT_CONTROL, 2) < 0) | 186 | if (reg_set(client, MT9T031_OUTPUT_CONTROL, 2) < 0) |
188 | return -EIO; | 187 | return -EIO; |
189 | return 0; | 188 | return 0; |
190 | } | 189 | } |
191 | 190 | ||
192 | static int mt9t031_stop_capture(struct soc_camera_device *icd) | 191 | static int mt9t031_stop_capture(struct soc_camera_device *icd) |
193 | { | 192 | { |
193 | struct i2c_client *client = to_i2c_client(icd->control); | ||
194 | |||
194 | /* Stop sensor readout */ | 195 | /* Stop sensor readout */ |
195 | if (reg_clear(icd, MT9T031_OUTPUT_CONTROL, 2) < 0) | 196 | if (reg_clear(client, MT9T031_OUTPUT_CONTROL, 2) < 0) |
196 | return -EIO; | 197 | return -EIO; |
197 | return 0; | 198 | return 0; |
198 | } | 199 | } |
@@ -200,14 +201,16 @@ static int mt9t031_stop_capture(struct soc_camera_device *icd) | |||
200 | static int mt9t031_set_bus_param(struct soc_camera_device *icd, | 201 | static int mt9t031_set_bus_param(struct soc_camera_device *icd, |
201 | unsigned long flags) | 202 | unsigned long flags) |
202 | { | 203 | { |
204 | struct i2c_client *client = to_i2c_client(icd->control); | ||
205 | |||
203 | /* The caller should have queried our parameters, check anyway */ | 206 | /* The caller should have queried our parameters, check anyway */ |
204 | if (flags & ~MT9T031_BUS_PARAM) | 207 | if (flags & ~MT9T031_BUS_PARAM) |
205 | return -EINVAL; | 208 | return -EINVAL; |
206 | 209 | ||
207 | if (flags & SOCAM_PCLK_SAMPLE_FALLING) | 210 | if (flags & SOCAM_PCLK_SAMPLE_FALLING) |
208 | reg_clear(icd, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000); | 211 | reg_clear(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000); |
209 | else | 212 | else |
210 | reg_set(icd, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000); | 213 | reg_set(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000); |
211 | 214 | ||
212 | return 0; | 215 | return 0; |
213 | } | 216 | } |
@@ -235,6 +238,7 @@ static void recalculate_limits(struct soc_camera_device *icd, | |||
235 | static int mt9t031_set_params(struct soc_camera_device *icd, | 238 | static int mt9t031_set_params(struct soc_camera_device *icd, |
236 | struct v4l2_rect *rect, u16 xskip, u16 yskip) | 239 | struct v4l2_rect *rect, u16 xskip, u16 yskip) |
237 | { | 240 | { |
241 | struct i2c_client *client = to_i2c_client(icd->control); | ||
238 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); | 242 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); |
239 | int ret; | 243 | int ret; |
240 | u16 xbin, ybin, width, height, left, top; | 244 | u16 xbin, ybin, width, height, left, top; |
@@ -277,22 +281,22 @@ static int mt9t031_set_params(struct soc_camera_device *icd, | |||
277 | } | 281 | } |
278 | 282 | ||
279 | /* Disable register update, reconfigure atomically */ | 283 | /* Disable register update, reconfigure atomically */ |
280 | ret = reg_set(icd, MT9T031_OUTPUT_CONTROL, 1); | 284 | ret = reg_set(client, MT9T031_OUTPUT_CONTROL, 1); |
281 | if (ret < 0) | 285 | if (ret < 0) |
282 | return ret; | 286 | return ret; |
283 | 287 | ||
284 | /* Blanking and start values - default... */ | 288 | /* Blanking and start values - default... */ |
285 | ret = reg_write(icd, MT9T031_HORIZONTAL_BLANKING, hblank); | 289 | ret = reg_write(client, MT9T031_HORIZONTAL_BLANKING, hblank); |
286 | if (ret >= 0) | 290 | if (ret >= 0) |
287 | ret = reg_write(icd, MT9T031_VERTICAL_BLANKING, vblank); | 291 | ret = reg_write(client, MT9T031_VERTICAL_BLANKING, vblank); |
288 | 292 | ||
289 | if (yskip != mt9t031->yskip || xskip != mt9t031->xskip) { | 293 | if (yskip != mt9t031->yskip || xskip != mt9t031->xskip) { |
290 | /* Binning, skipping */ | 294 | /* Binning, skipping */ |
291 | if (ret >= 0) | 295 | if (ret >= 0) |
292 | ret = reg_write(icd, MT9T031_COLUMN_ADDRESS_MODE, | 296 | ret = reg_write(client, MT9T031_COLUMN_ADDRESS_MODE, |
293 | ((xbin - 1) << 4) | (xskip - 1)); | 297 | ((xbin - 1) << 4) | (xskip - 1)); |
294 | if (ret >= 0) | 298 | if (ret >= 0) |
295 | ret = reg_write(icd, MT9T031_ROW_ADDRESS_MODE, | 299 | ret = reg_write(client, MT9T031_ROW_ADDRESS_MODE, |
296 | ((ybin - 1) << 4) | (yskip - 1)); | 300 | ((ybin - 1) << 4) | (yskip - 1)); |
297 | } | 301 | } |
298 | dev_dbg(&icd->dev, "new physical left %u, top %u\n", left, top); | 302 | dev_dbg(&icd->dev, "new physical left %u, top %u\n", left, top); |
@@ -300,16 +304,16 @@ static int mt9t031_set_params(struct soc_camera_device *icd, | |||
300 | /* The caller provides a supported format, as guaranteed by | 304 | /* The caller provides a supported format, as guaranteed by |
301 | * icd->try_fmt_cap(), soc_camera_s_crop() and soc_camera_cropcap() */ | 305 | * icd->try_fmt_cap(), soc_camera_s_crop() and soc_camera_cropcap() */ |
302 | if (ret >= 0) | 306 | if (ret >= 0) |
303 | ret = reg_write(icd, MT9T031_COLUMN_START, left); | 307 | ret = reg_write(client, MT9T031_COLUMN_START, left); |
304 | if (ret >= 0) | 308 | if (ret >= 0) |
305 | ret = reg_write(icd, MT9T031_ROW_START, top); | 309 | ret = reg_write(client, MT9T031_ROW_START, top); |
306 | if (ret >= 0) | 310 | if (ret >= 0) |
307 | ret = reg_write(icd, MT9T031_WINDOW_WIDTH, width - 1); | 311 | ret = reg_write(client, MT9T031_WINDOW_WIDTH, width - 1); |
308 | if (ret >= 0) | 312 | if (ret >= 0) |
309 | ret = reg_write(icd, MT9T031_WINDOW_HEIGHT, | 313 | ret = reg_write(client, MT9T031_WINDOW_HEIGHT, |
310 | height + icd->y_skip_top - 1); | 314 | height + icd->y_skip_top - 1); |
311 | if (ret >= 0 && mt9t031->autoexposure) { | 315 | if (ret >= 0 && mt9t031->autoexposure) { |
312 | ret = set_shutter(icd, height + icd->y_skip_top + vblank); | 316 | ret = set_shutter(client, height + icd->y_skip_top + vblank); |
313 | if (ret >= 0) { | 317 | if (ret >= 0) { |
314 | const u32 shutter_max = MT9T031_MAX_HEIGHT + vblank; | 318 | const u32 shutter_max = MT9T031_MAX_HEIGHT + vblank; |
315 | const struct v4l2_queryctrl *qctrl = | 319 | const struct v4l2_queryctrl *qctrl = |
@@ -324,7 +328,7 @@ static int mt9t031_set_params(struct soc_camera_device *icd, | |||
324 | 328 | ||
325 | /* Re-enable register update, commit all changes */ | 329 | /* Re-enable register update, commit all changes */ |
326 | if (ret >= 0) | 330 | if (ret >= 0) |
327 | ret = reg_clear(icd, MT9T031_OUTPUT_CONTROL, 1); | 331 | ret = reg_clear(client, MT9T031_OUTPUT_CONTROL, 1); |
328 | 332 | ||
329 | return ret < 0 ? ret : 0; | 333 | return ret < 0 ? ret : 0; |
330 | } | 334 | } |
@@ -417,15 +421,15 @@ static int mt9t031_get_chip_id(struct soc_camera_device *icd, | |||
417 | static int mt9t031_get_register(struct soc_camera_device *icd, | 421 | static int mt9t031_get_register(struct soc_camera_device *icd, |
418 | struct v4l2_dbg_register *reg) | 422 | struct v4l2_dbg_register *reg) |
419 | { | 423 | { |
420 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); | 424 | struct i2c_client *client = to_i2c_client(icd->control); |
421 | 425 | ||
422 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) | 426 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) |
423 | return -EINVAL; | 427 | return -EINVAL; |
424 | 428 | ||
425 | if (reg->match.addr != mt9t031->client->addr) | 429 | if (reg->match.addr != client->addr) |
426 | return -ENODEV; | 430 | return -ENODEV; |
427 | 431 | ||
428 | reg->val = reg_read(icd, reg->reg); | 432 | reg->val = reg_read(client, reg->reg); |
429 | 433 | ||
430 | if (reg->val > 0xffff) | 434 | if (reg->val > 0xffff) |
431 | return -EIO; | 435 | return -EIO; |
@@ -436,15 +440,15 @@ static int mt9t031_get_register(struct soc_camera_device *icd, | |||
436 | static int mt9t031_set_register(struct soc_camera_device *icd, | 440 | static int mt9t031_set_register(struct soc_camera_device *icd, |
437 | struct v4l2_dbg_register *reg) | 441 | struct v4l2_dbg_register *reg) |
438 | { | 442 | { |
439 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); | 443 | struct i2c_client *client = to_i2c_client(icd->control); |
440 | 444 | ||
441 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) | 445 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) |
442 | return -EINVAL; | 446 | return -EINVAL; |
443 | 447 | ||
444 | if (reg->match.addr != mt9t031->client->addr) | 448 | if (reg->match.addr != client->addr) |
445 | return -ENODEV; | 449 | return -ENODEV; |
446 | 450 | ||
447 | if (reg_write(icd, reg->reg, reg->val) < 0) | 451 | if (reg_write(client, reg->reg, reg->val) < 0) |
448 | return -EIO; | 452 | return -EIO; |
449 | 453 | ||
450 | return 0; | 454 | return 0; |
@@ -528,18 +532,19 @@ static struct soc_camera_ops mt9t031_ops = { | |||
528 | 532 | ||
529 | static int mt9t031_get_control(struct soc_camera_device *icd, struct v4l2_control *ctrl) | 533 | static int mt9t031_get_control(struct soc_camera_device *icd, struct v4l2_control *ctrl) |
530 | { | 534 | { |
535 | struct i2c_client *client = to_i2c_client(icd->control); | ||
531 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); | 536 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); |
532 | int data; | 537 | int data; |
533 | 538 | ||
534 | switch (ctrl->id) { | 539 | switch (ctrl->id) { |
535 | case V4L2_CID_VFLIP: | 540 | case V4L2_CID_VFLIP: |
536 | data = reg_read(icd, MT9T031_READ_MODE_2); | 541 | data = reg_read(client, MT9T031_READ_MODE_2); |
537 | if (data < 0) | 542 | if (data < 0) |
538 | return -EIO; | 543 | return -EIO; |
539 | ctrl->value = !!(data & 0x8000); | 544 | ctrl->value = !!(data & 0x8000); |
540 | break; | 545 | break; |
541 | case V4L2_CID_HFLIP: | 546 | case V4L2_CID_HFLIP: |
542 | data = reg_read(icd, MT9T031_READ_MODE_2); | 547 | data = reg_read(client, MT9T031_READ_MODE_2); |
543 | if (data < 0) | 548 | if (data < 0) |
544 | return -EIO; | 549 | return -EIO; |
545 | ctrl->value = !!(data & 0x4000); | 550 | ctrl->value = !!(data & 0x4000); |
@@ -553,6 +558,7 @@ static int mt9t031_get_control(struct soc_camera_device *icd, struct v4l2_contro | |||
553 | 558 | ||
554 | static int mt9t031_set_control(struct soc_camera_device *icd, struct v4l2_control *ctrl) | 559 | static int mt9t031_set_control(struct soc_camera_device *icd, struct v4l2_control *ctrl) |
555 | { | 560 | { |
561 | struct i2c_client *client = to_i2c_client(icd->control); | ||
556 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); | 562 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); |
557 | const struct v4l2_queryctrl *qctrl; | 563 | const struct v4l2_queryctrl *qctrl; |
558 | int data; | 564 | int data; |
@@ -565,17 +571,17 @@ static int mt9t031_set_control(struct soc_camera_device *icd, struct v4l2_contro | |||
565 | switch (ctrl->id) { | 571 | switch (ctrl->id) { |
566 | case V4L2_CID_VFLIP: | 572 | case V4L2_CID_VFLIP: |
567 | if (ctrl->value) | 573 | if (ctrl->value) |
568 | data = reg_set(icd, MT9T031_READ_MODE_2, 0x8000); | 574 | data = reg_set(client, MT9T031_READ_MODE_2, 0x8000); |
569 | else | 575 | else |
570 | data = reg_clear(icd, MT9T031_READ_MODE_2, 0x8000); | 576 | data = reg_clear(client, MT9T031_READ_MODE_2, 0x8000); |
571 | if (data < 0) | 577 | if (data < 0) |
572 | return -EIO; | 578 | return -EIO; |
573 | break; | 579 | break; |
574 | case V4L2_CID_HFLIP: | 580 | case V4L2_CID_HFLIP: |
575 | if (ctrl->value) | 581 | if (ctrl->value) |
576 | data = reg_set(icd, MT9T031_READ_MODE_2, 0x4000); | 582 | data = reg_set(client, MT9T031_READ_MODE_2, 0x4000); |
577 | else | 583 | else |
578 | data = reg_clear(icd, MT9T031_READ_MODE_2, 0x4000); | 584 | data = reg_clear(client, MT9T031_READ_MODE_2, 0x4000); |
579 | if (data < 0) | 585 | if (data < 0) |
580 | return -EIO; | 586 | return -EIO; |
581 | break; | 587 | break; |
@@ -589,7 +595,7 @@ static int mt9t031_set_control(struct soc_camera_device *icd, struct v4l2_contro | |||
589 | data = ((ctrl->value - qctrl->minimum) * 8 + range / 2) / range; | 595 | data = ((ctrl->value - qctrl->minimum) * 8 + range / 2) / range; |
590 | 596 | ||
591 | dev_dbg(&icd->dev, "Setting gain %d\n", data); | 597 | dev_dbg(&icd->dev, "Setting gain %d\n", data); |
592 | data = reg_write(icd, MT9T031_GLOBAL_GAIN, data); | 598 | data = reg_write(client, MT9T031_GLOBAL_GAIN, data); |
593 | if (data < 0) | 599 | if (data < 0) |
594 | return -EIO; | 600 | return -EIO; |
595 | } else { | 601 | } else { |
@@ -609,8 +615,8 @@ static int mt9t031_set_control(struct soc_camera_device *icd, struct v4l2_contro | |||
609 | data = (((gain - 64 + 7) * 32) & 0xff00) | 0x60; | 615 | data = (((gain - 64 + 7) * 32) & 0xff00) | 0x60; |
610 | 616 | ||
611 | dev_dbg(&icd->dev, "Setting gain from 0x%x to 0x%x\n", | 617 | dev_dbg(&icd->dev, "Setting gain from 0x%x to 0x%x\n", |
612 | reg_read(icd, MT9T031_GLOBAL_GAIN), data); | 618 | reg_read(client, MT9T031_GLOBAL_GAIN), data); |
613 | data = reg_write(icd, MT9T031_GLOBAL_GAIN, data); | 619 | data = reg_write(client, MT9T031_GLOBAL_GAIN, data); |
614 | if (data < 0) | 620 | if (data < 0) |
615 | return -EIO; | 621 | return -EIO; |
616 | } | 622 | } |
@@ -628,10 +634,10 @@ static int mt9t031_set_control(struct soc_camera_device *icd, struct v4l2_contro | |||
628 | range / 2) / range + 1; | 634 | range / 2) / range + 1; |
629 | u32 old; | 635 | u32 old; |
630 | 636 | ||
631 | get_shutter(icd, &old); | 637 | get_shutter(client, &old); |
632 | dev_dbg(&icd->dev, "Setting shutter width from %u to %u\n", | 638 | dev_dbg(&icd->dev, "Setting shutter width from %u to %u\n", |
633 | old, shutter); | 639 | old, shutter); |
634 | if (set_shutter(icd, shutter) < 0) | 640 | if (set_shutter(client, shutter) < 0) |
635 | return -EIO; | 641 | return -EIO; |
636 | icd->exposure = ctrl->value; | 642 | icd->exposure = ctrl->value; |
637 | mt9t031->autoexposure = 0; | 643 | mt9t031->autoexposure = 0; |
@@ -641,7 +647,7 @@ static int mt9t031_set_control(struct soc_camera_device *icd, struct v4l2_contro | |||
641 | if (ctrl->value) { | 647 | if (ctrl->value) { |
642 | const u16 vblank = MT9T031_VERTICAL_BLANK; | 648 | const u16 vblank = MT9T031_VERTICAL_BLANK; |
643 | const u32 shutter_max = MT9T031_MAX_HEIGHT + vblank; | 649 | const u32 shutter_max = MT9T031_MAX_HEIGHT + vblank; |
644 | if (set_shutter(icd, icd->height + | 650 | if (set_shutter(client, icd->height + |
645 | icd->y_skip_top + vblank) < 0) | 651 | icd->y_skip_top + vblank) < 0) |
646 | return -EIO; | 652 | return -EIO; |
647 | qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE); | 653 | qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE); |
@@ -661,6 +667,7 @@ static int mt9t031_set_control(struct soc_camera_device *icd, struct v4l2_contro | |||
661 | * this wasn't our capture interface, so, we wait for the right one */ | 667 | * this wasn't our capture interface, so, we wait for the right one */ |
662 | static int mt9t031_video_probe(struct soc_camera_device *icd) | 668 | static int mt9t031_video_probe(struct soc_camera_device *icd) |
663 | { | 669 | { |
670 | struct i2c_client *client = to_i2c_client(icd->control); | ||
664 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); | 671 | struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); |
665 | s32 data; | 672 | s32 data; |
666 | int ret; | 673 | int ret; |
@@ -672,11 +679,11 @@ static int mt9t031_video_probe(struct soc_camera_device *icd) | |||
672 | return -ENODEV; | 679 | return -ENODEV; |
673 | 680 | ||
674 | /* Enable the chip */ | 681 | /* Enable the chip */ |
675 | data = reg_write(icd, MT9T031_CHIP_ENABLE, 1); | 682 | data = reg_write(client, MT9T031_CHIP_ENABLE, 1); |
676 | dev_dbg(&icd->dev, "write: %d\n", data); | 683 | dev_dbg(&icd->dev, "write: %d\n", data); |
677 | 684 | ||
678 | /* Read out the chip version register */ | 685 | /* Read out the chip version register */ |
679 | data = reg_read(icd, MT9T031_CHIP_VERSION); | 686 | data = reg_read(client, MT9T031_CHIP_VERSION); |
680 | 687 | ||
681 | switch (data) { | 688 | switch (data) { |
682 | case 0x1621: | 689 | case 0x1621: |
diff --git a/drivers/media/video/mt9v022.c b/drivers/media/video/mt9v022.c index 412b399baca4..be20d312b1dc 100644 --- a/drivers/media/video/mt9v022.c +++ b/drivers/media/video/mt9v022.c | |||
@@ -91,51 +91,49 @@ struct mt9v022 { | |||
91 | u16 chip_control; | 91 | u16 chip_control; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | static int reg_read(struct soc_camera_device *icd, const u8 reg) | 94 | static int reg_read(struct i2c_client *client, const u8 reg) |
95 | { | 95 | { |
96 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); | ||
97 | struct i2c_client *client = mt9v022->client; | ||
98 | s32 data = i2c_smbus_read_word_data(client, reg); | 96 | s32 data = i2c_smbus_read_word_data(client, reg); |
99 | return data < 0 ? data : swab16(data); | 97 | return data < 0 ? data : swab16(data); |
100 | } | 98 | } |
101 | 99 | ||
102 | static int reg_write(struct soc_camera_device *icd, const u8 reg, | 100 | static int reg_write(struct i2c_client *client, const u8 reg, |
103 | const u16 data) | 101 | const u16 data) |
104 | { | 102 | { |
105 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); | 103 | return i2c_smbus_write_word_data(client, reg, swab16(data)); |
106 | return i2c_smbus_write_word_data(mt9v022->client, reg, swab16(data)); | ||
107 | } | 104 | } |
108 | 105 | ||
109 | static int reg_set(struct soc_camera_device *icd, const u8 reg, | 106 | static int reg_set(struct i2c_client *client, const u8 reg, |
110 | const u16 data) | 107 | const u16 data) |
111 | { | 108 | { |
112 | int ret; | 109 | int ret; |
113 | 110 | ||
114 | ret = reg_read(icd, reg); | 111 | ret = reg_read(client, reg); |
115 | if (ret < 0) | 112 | if (ret < 0) |
116 | return ret; | 113 | return ret; |
117 | return reg_write(icd, reg, ret | data); | 114 | return reg_write(client, reg, ret | data); |
118 | } | 115 | } |
119 | 116 | ||
120 | static int reg_clear(struct soc_camera_device *icd, const u8 reg, | 117 | static int reg_clear(struct i2c_client *client, const u8 reg, |
121 | const u16 data) | 118 | const u16 data) |
122 | { | 119 | { |
123 | int ret; | 120 | int ret; |
124 | 121 | ||
125 | ret = reg_read(icd, reg); | 122 | ret = reg_read(client, reg); |
126 | if (ret < 0) | 123 | if (ret < 0) |
127 | return ret; | 124 | return ret; |
128 | return reg_write(icd, reg, ret & ~data); | 125 | return reg_write(client, reg, ret & ~data); |
129 | } | 126 | } |
130 | 127 | ||
131 | static int mt9v022_init(struct soc_camera_device *icd) | 128 | static int mt9v022_init(struct soc_camera_device *icd) |
132 | { | 129 | { |
130 | struct i2c_client *client = to_i2c_client(icd->control); | ||
133 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); | 131 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); |
134 | struct soc_camera_link *icl = mt9v022->client->dev.platform_data; | 132 | struct soc_camera_link *icl = client->dev.platform_data; |
135 | int ret; | 133 | int ret; |
136 | 134 | ||
137 | if (icl->power) { | 135 | if (icl->power) { |
138 | ret = icl->power(&mt9v022->client->dev, 1); | 136 | ret = icl->power(&client->dev, 1); |
139 | if (ret < 0) { | 137 | if (ret < 0) { |
140 | dev_err(icd->vdev->parent, | 138 | dev_err(icd->vdev->parent, |
141 | "Platform failed to power-on the camera.\n"); | 139 | "Platform failed to power-on the camera.\n"); |
@@ -148,27 +146,27 @@ static int mt9v022_init(struct soc_camera_device *icd) | |||
148 | * if available. Soft reset is done in video_probe(). | 146 | * if available. Soft reset is done in video_probe(). |
149 | */ | 147 | */ |
150 | if (icl->reset) | 148 | if (icl->reset) |
151 | icl->reset(&mt9v022->client->dev); | 149 | icl->reset(&client->dev); |
152 | 150 | ||
153 | /* Almost the default mode: master, parallel, simultaneous, and an | 151 | /* Almost the default mode: master, parallel, simultaneous, and an |
154 | * undocumented bit 0x200, which is present in table 7, but not in 8, | 152 | * undocumented bit 0x200, which is present in table 7, but not in 8, |
155 | * plus snapshot mode to disable scan for now */ | 153 | * plus snapshot mode to disable scan for now */ |
156 | mt9v022->chip_control |= 0x10; | 154 | mt9v022->chip_control |= 0x10; |
157 | ret = reg_write(icd, MT9V022_CHIP_CONTROL, mt9v022->chip_control); | 155 | ret = reg_write(client, MT9V022_CHIP_CONTROL, mt9v022->chip_control); |
158 | if (!ret) | 156 | if (!ret) |
159 | ret = reg_write(icd, MT9V022_READ_MODE, 0x300); | 157 | ret = reg_write(client, MT9V022_READ_MODE, 0x300); |
160 | 158 | ||
161 | /* All defaults */ | 159 | /* All defaults */ |
162 | if (!ret) | 160 | if (!ret) |
163 | /* AEC, AGC on */ | 161 | /* AEC, AGC on */ |
164 | ret = reg_set(icd, MT9V022_AEC_AGC_ENABLE, 0x3); | 162 | ret = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x3); |
165 | if (!ret) | 163 | if (!ret) |
166 | ret = reg_write(icd, MT9V022_MAX_TOTAL_SHUTTER_WIDTH, 480); | 164 | ret = reg_write(client, MT9V022_MAX_TOTAL_SHUTTER_WIDTH, 480); |
167 | if (!ret) | 165 | if (!ret) |
168 | /* default - auto */ | 166 | /* default - auto */ |
169 | ret = reg_clear(icd, MT9V022_BLACK_LEVEL_CALIB_CTRL, 1); | 167 | ret = reg_clear(client, MT9V022_BLACK_LEVEL_CALIB_CTRL, 1); |
170 | if (!ret) | 168 | if (!ret) |
171 | ret = reg_write(icd, MT9V022_DIGITAL_TEST_PATTERN, 0); | 169 | ret = reg_write(client, MT9V022_DIGITAL_TEST_PATTERN, 0); |
172 | 170 | ||
173 | return ret; | 171 | return ret; |
174 | } | 172 | } |
@@ -186,10 +184,11 @@ static int mt9v022_release(struct soc_camera_device *icd) | |||
186 | 184 | ||
187 | static int mt9v022_start_capture(struct soc_camera_device *icd) | 185 | static int mt9v022_start_capture(struct soc_camera_device *icd) |
188 | { | 186 | { |
187 | struct i2c_client *client = to_i2c_client(icd->control); | ||
189 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); | 188 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); |
190 | /* Switch to master "normal" mode */ | 189 | /* Switch to master "normal" mode */ |
191 | mt9v022->chip_control &= ~0x10; | 190 | mt9v022->chip_control &= ~0x10; |
192 | if (reg_write(icd, MT9V022_CHIP_CONTROL, | 191 | if (reg_write(client, MT9V022_CHIP_CONTROL, |
193 | mt9v022->chip_control) < 0) | 192 | mt9v022->chip_control) < 0) |
194 | return -EIO; | 193 | return -EIO; |
195 | return 0; | 194 | return 0; |
@@ -197,10 +196,11 @@ static int mt9v022_start_capture(struct soc_camera_device *icd) | |||
197 | 196 | ||
198 | static int mt9v022_stop_capture(struct soc_camera_device *icd) | 197 | static int mt9v022_stop_capture(struct soc_camera_device *icd) |
199 | { | 198 | { |
199 | struct i2c_client *client = to_i2c_client(icd->control); | ||
200 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); | 200 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); |
201 | /* Switch to snapshot mode */ | 201 | /* Switch to snapshot mode */ |
202 | mt9v022->chip_control |= 0x10; | 202 | mt9v022->chip_control |= 0x10; |
203 | if (reg_write(icd, MT9V022_CHIP_CONTROL, | 203 | if (reg_write(client, MT9V022_CHIP_CONTROL, |
204 | mt9v022->chip_control) < 0) | 204 | mt9v022->chip_control) < 0) |
205 | return -EIO; | 205 | return -EIO; |
206 | return 0; | 206 | return 0; |
@@ -209,8 +209,9 @@ static int mt9v022_stop_capture(struct soc_camera_device *icd) | |||
209 | static int mt9v022_set_bus_param(struct soc_camera_device *icd, | 209 | static int mt9v022_set_bus_param(struct soc_camera_device *icd, |
210 | unsigned long flags) | 210 | unsigned long flags) |
211 | { | 211 | { |
212 | struct i2c_client *client = to_i2c_client(icd->control); | ||
212 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); | 213 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); |
213 | struct soc_camera_link *icl = mt9v022->client->dev.platform_data; | 214 | struct soc_camera_link *icl = client->dev.platform_data; |
214 | unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK; | 215 | unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK; |
215 | int ret; | 216 | int ret; |
216 | u16 pixclk = 0; | 217 | u16 pixclk = 0; |
@@ -243,14 +244,14 @@ static int mt9v022_set_bus_param(struct soc_camera_device *icd, | |||
243 | if (!(flags & SOCAM_VSYNC_ACTIVE_HIGH)) | 244 | if (!(flags & SOCAM_VSYNC_ACTIVE_HIGH)) |
244 | pixclk |= 0x2; | 245 | pixclk |= 0x2; |
245 | 246 | ||
246 | ret = reg_write(icd, MT9V022_PIXCLK_FV_LV, pixclk); | 247 | ret = reg_write(client, MT9V022_PIXCLK_FV_LV, pixclk); |
247 | if (ret < 0) | 248 | if (ret < 0) |
248 | return ret; | 249 | return ret; |
249 | 250 | ||
250 | if (!(flags & SOCAM_MASTER)) | 251 | if (!(flags & SOCAM_MASTER)) |
251 | mt9v022->chip_control &= ~0x8; | 252 | mt9v022->chip_control &= ~0x8; |
252 | 253 | ||
253 | ret = reg_write(icd, MT9V022_CHIP_CONTROL, mt9v022->chip_control); | 254 | ret = reg_write(client, MT9V022_CHIP_CONTROL, mt9v022->chip_control); |
254 | if (ret < 0) | 255 | if (ret < 0) |
255 | return ret; | 256 | return ret; |
256 | 257 | ||
@@ -282,35 +283,36 @@ static unsigned long mt9v022_query_bus_param(struct soc_camera_device *icd) | |||
282 | static int mt9v022_set_crop(struct soc_camera_device *icd, | 283 | static int mt9v022_set_crop(struct soc_camera_device *icd, |
283 | struct v4l2_rect *rect) | 284 | struct v4l2_rect *rect) |
284 | { | 285 | { |
286 | struct i2c_client *client = to_i2c_client(icd->control); | ||
285 | int ret; | 287 | int ret; |
286 | 288 | ||
287 | /* Like in example app. Contradicts the datasheet though */ | 289 | /* Like in example app. Contradicts the datasheet though */ |
288 | ret = reg_read(icd, MT9V022_AEC_AGC_ENABLE); | 290 | ret = reg_read(client, MT9V022_AEC_AGC_ENABLE); |
289 | if (ret >= 0) { | 291 | if (ret >= 0) { |
290 | if (ret & 1) /* Autoexposure */ | 292 | if (ret & 1) /* Autoexposure */ |
291 | ret = reg_write(icd, MT9V022_MAX_TOTAL_SHUTTER_WIDTH, | 293 | ret = reg_write(client, MT9V022_MAX_TOTAL_SHUTTER_WIDTH, |
292 | rect->height + icd->y_skip_top + 43); | 294 | rect->height + icd->y_skip_top + 43); |
293 | else | 295 | else |
294 | ret = reg_write(icd, MT9V022_TOTAL_SHUTTER_WIDTH, | 296 | ret = reg_write(client, MT9V022_TOTAL_SHUTTER_WIDTH, |
295 | rect->height + icd->y_skip_top + 43); | 297 | rect->height + icd->y_skip_top + 43); |
296 | } | 298 | } |
297 | /* Setup frame format: defaults apart from width and height */ | 299 | /* Setup frame format: defaults apart from width and height */ |
298 | if (!ret) | 300 | if (!ret) |
299 | ret = reg_write(icd, MT9V022_COLUMN_START, rect->left); | 301 | ret = reg_write(client, MT9V022_COLUMN_START, rect->left); |
300 | if (!ret) | 302 | if (!ret) |
301 | ret = reg_write(icd, MT9V022_ROW_START, rect->top); | 303 | ret = reg_write(client, MT9V022_ROW_START, rect->top); |
302 | if (!ret) | 304 | if (!ret) |
303 | /* Default 94, Phytec driver says: | 305 | /* Default 94, Phytec driver says: |
304 | * "width + horizontal blank >= 660" */ | 306 | * "width + horizontal blank >= 660" */ |
305 | ret = reg_write(icd, MT9V022_HORIZONTAL_BLANKING, | 307 | ret = reg_write(client, MT9V022_HORIZONTAL_BLANKING, |
306 | rect->width > 660 - 43 ? 43 : | 308 | rect->width > 660 - 43 ? 43 : |
307 | 660 - rect->width); | 309 | 660 - rect->width); |
308 | if (!ret) | 310 | if (!ret) |
309 | ret = reg_write(icd, MT9V022_VERTICAL_BLANKING, 45); | 311 | ret = reg_write(client, MT9V022_VERTICAL_BLANKING, 45); |
310 | if (!ret) | 312 | if (!ret) |
311 | ret = reg_write(icd, MT9V022_WINDOW_WIDTH, rect->width); | 313 | ret = reg_write(client, MT9V022_WINDOW_WIDTH, rect->width); |
312 | if (!ret) | 314 | if (!ret) |
313 | ret = reg_write(icd, MT9V022_WINDOW_HEIGHT, | 315 | ret = reg_write(client, MT9V022_WINDOW_HEIGHT, |
314 | rect->height + icd->y_skip_top); | 316 | rect->height + icd->y_skip_top); |
315 | 317 | ||
316 | if (ret < 0) | 318 | if (ret < 0) |
@@ -396,16 +398,16 @@ static int mt9v022_get_chip_id(struct soc_camera_device *icd, | |||
396 | static int mt9v022_get_register(struct soc_camera_device *icd, | 398 | static int mt9v022_get_register(struct soc_camera_device *icd, |
397 | struct v4l2_dbg_register *reg) | 399 | struct v4l2_dbg_register *reg) |
398 | { | 400 | { |
399 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); | 401 | struct i2c_client *client = to_i2c_client(icd->control); |
400 | 402 | ||
401 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) | 403 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) |
402 | return -EINVAL; | 404 | return -EINVAL; |
403 | 405 | ||
404 | if (reg->match.addr != mt9v022->client->addr) | 406 | if (reg->match.addr != client->addr) |
405 | return -ENODEV; | 407 | return -ENODEV; |
406 | 408 | ||
407 | reg->size = 2; | 409 | reg->size = 2; |
408 | reg->val = reg_read(icd, reg->reg); | 410 | reg->val = reg_read(client, reg->reg); |
409 | 411 | ||
410 | if (reg->val > 0xffff) | 412 | if (reg->val > 0xffff) |
411 | return -EIO; | 413 | return -EIO; |
@@ -416,15 +418,15 @@ static int mt9v022_get_register(struct soc_camera_device *icd, | |||
416 | static int mt9v022_set_register(struct soc_camera_device *icd, | 418 | static int mt9v022_set_register(struct soc_camera_device *icd, |
417 | struct v4l2_dbg_register *reg) | 419 | struct v4l2_dbg_register *reg) |
418 | { | 420 | { |
419 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); | 421 | struct i2c_client *client = to_i2c_client(icd->control); |
420 | 422 | ||
421 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) | 423 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) |
422 | return -EINVAL; | 424 | return -EINVAL; |
423 | 425 | ||
424 | if (reg->match.addr != mt9v022->client->addr) | 426 | if (reg->match.addr != client->addr) |
425 | return -ENODEV; | 427 | return -ENODEV; |
426 | 428 | ||
427 | if (reg_write(icd, reg->reg, reg->val) < 0) | 429 | if (reg_write(client, reg->reg, reg->val) < 0) |
428 | return -EIO; | 430 | return -EIO; |
429 | 431 | ||
430 | return 0; | 432 | return 0; |
@@ -517,29 +519,30 @@ static struct soc_camera_ops mt9v022_ops = { | |||
517 | static int mt9v022_get_control(struct soc_camera_device *icd, | 519 | static int mt9v022_get_control(struct soc_camera_device *icd, |
518 | struct v4l2_control *ctrl) | 520 | struct v4l2_control *ctrl) |
519 | { | 521 | { |
522 | struct i2c_client *client = to_i2c_client(icd->control); | ||
520 | int data; | 523 | int data; |
521 | 524 | ||
522 | switch (ctrl->id) { | 525 | switch (ctrl->id) { |
523 | case V4L2_CID_VFLIP: | 526 | case V4L2_CID_VFLIP: |
524 | data = reg_read(icd, MT9V022_READ_MODE); | 527 | data = reg_read(client, MT9V022_READ_MODE); |
525 | if (data < 0) | 528 | if (data < 0) |
526 | return -EIO; | 529 | return -EIO; |
527 | ctrl->value = !!(data & 0x10); | 530 | ctrl->value = !!(data & 0x10); |
528 | break; | 531 | break; |
529 | case V4L2_CID_HFLIP: | 532 | case V4L2_CID_HFLIP: |
530 | data = reg_read(icd, MT9V022_READ_MODE); | 533 | data = reg_read(client, MT9V022_READ_MODE); |
531 | if (data < 0) | 534 | if (data < 0) |
532 | return -EIO; | 535 | return -EIO; |
533 | ctrl->value = !!(data & 0x20); | 536 | ctrl->value = !!(data & 0x20); |
534 | break; | 537 | break; |
535 | case V4L2_CID_EXPOSURE_AUTO: | 538 | case V4L2_CID_EXPOSURE_AUTO: |
536 | data = reg_read(icd, MT9V022_AEC_AGC_ENABLE); | 539 | data = reg_read(client, MT9V022_AEC_AGC_ENABLE); |
537 | if (data < 0) | 540 | if (data < 0) |
538 | return -EIO; | 541 | return -EIO; |
539 | ctrl->value = !!(data & 0x1); | 542 | ctrl->value = !!(data & 0x1); |
540 | break; | 543 | break; |
541 | case V4L2_CID_AUTOGAIN: | 544 | case V4L2_CID_AUTOGAIN: |
542 | data = reg_read(icd, MT9V022_AEC_AGC_ENABLE); | 545 | data = reg_read(client, MT9V022_AEC_AGC_ENABLE); |
543 | if (data < 0) | 546 | if (data < 0) |
544 | return -EIO; | 547 | return -EIO; |
545 | ctrl->value = !!(data & 0x2); | 548 | ctrl->value = !!(data & 0x2); |
@@ -552,6 +555,7 @@ static int mt9v022_set_control(struct soc_camera_device *icd, | |||
552 | struct v4l2_control *ctrl) | 555 | struct v4l2_control *ctrl) |
553 | { | 556 | { |
554 | int data; | 557 | int data; |
558 | struct i2c_client *client = to_i2c_client(icd->control); | ||
555 | const struct v4l2_queryctrl *qctrl; | 559 | const struct v4l2_queryctrl *qctrl; |
556 | 560 | ||
557 | qctrl = soc_camera_find_qctrl(&mt9v022_ops, ctrl->id); | 561 | qctrl = soc_camera_find_qctrl(&mt9v022_ops, ctrl->id); |
@@ -562,17 +566,17 @@ static int mt9v022_set_control(struct soc_camera_device *icd, | |||
562 | switch (ctrl->id) { | 566 | switch (ctrl->id) { |
563 | case V4L2_CID_VFLIP: | 567 | case V4L2_CID_VFLIP: |
564 | if (ctrl->value) | 568 | if (ctrl->value) |
565 | data = reg_set(icd, MT9V022_READ_MODE, 0x10); | 569 | data = reg_set(client, MT9V022_READ_MODE, 0x10); |
566 | else | 570 | else |
567 | data = reg_clear(icd, MT9V022_READ_MODE, 0x10); | 571 | data = reg_clear(client, MT9V022_READ_MODE, 0x10); |
568 | if (data < 0) | 572 | if (data < 0) |
569 | return -EIO; | 573 | return -EIO; |
570 | break; | 574 | break; |
571 | case V4L2_CID_HFLIP: | 575 | case V4L2_CID_HFLIP: |
572 | if (ctrl->value) | 576 | if (ctrl->value) |
573 | data = reg_set(icd, MT9V022_READ_MODE, 0x20); | 577 | data = reg_set(client, MT9V022_READ_MODE, 0x20); |
574 | else | 578 | else |
575 | data = reg_clear(icd, MT9V022_READ_MODE, 0x20); | 579 | data = reg_clear(client, MT9V022_READ_MODE, 0x20); |
576 | if (data < 0) | 580 | if (data < 0) |
577 | return -EIO; | 581 | return -EIO; |
578 | break; | 582 | break; |
@@ -593,12 +597,12 @@ static int mt9v022_set_control(struct soc_camera_device *icd, | |||
593 | /* The user wants to set gain manually, hope, she | 597 | /* The user wants to set gain manually, hope, she |
594 | * knows, what she's doing... Switch AGC off. */ | 598 | * knows, what she's doing... Switch AGC off. */ |
595 | 599 | ||
596 | if (reg_clear(icd, MT9V022_AEC_AGC_ENABLE, 0x2) < 0) | 600 | if (reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x2) < 0) |
597 | return -EIO; | 601 | return -EIO; |
598 | 602 | ||
599 | dev_info(&icd->dev, "Setting gain from %d to %lu\n", | 603 | dev_info(&icd->dev, "Setting gain from %d to %lu\n", |
600 | reg_read(icd, MT9V022_ANALOG_GAIN), gain); | 604 | reg_read(client, MT9V022_ANALOG_GAIN), gain); |
601 | if (reg_write(icd, MT9V022_ANALOG_GAIN, gain) < 0) | 605 | if (reg_write(client, MT9V022_ANALOG_GAIN, gain) < 0) |
602 | return -EIO; | 606 | return -EIO; |
603 | icd->gain = ctrl->value; | 607 | icd->gain = ctrl->value; |
604 | } | 608 | } |
@@ -614,13 +618,13 @@ static int mt9v022_set_control(struct soc_camera_device *icd, | |||
614 | /* The user wants to set shutter width manually, hope, | 618 | /* The user wants to set shutter width manually, hope, |
615 | * she knows, what she's doing... Switch AEC off. */ | 619 | * she knows, what she's doing... Switch AEC off. */ |
616 | 620 | ||
617 | if (reg_clear(icd, MT9V022_AEC_AGC_ENABLE, 0x1) < 0) | 621 | if (reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x1) < 0) |
618 | return -EIO; | 622 | return -EIO; |
619 | 623 | ||
620 | dev_dbg(&icd->dev, "Shutter width from %d to %lu\n", | 624 | dev_dbg(&icd->dev, "Shutter width from %d to %lu\n", |
621 | reg_read(icd, MT9V022_TOTAL_SHUTTER_WIDTH), | 625 | reg_read(client, MT9V022_TOTAL_SHUTTER_WIDTH), |
622 | shutter); | 626 | shutter); |
623 | if (reg_write(icd, MT9V022_TOTAL_SHUTTER_WIDTH, | 627 | if (reg_write(client, MT9V022_TOTAL_SHUTTER_WIDTH, |
624 | shutter) < 0) | 628 | shutter) < 0) |
625 | return -EIO; | 629 | return -EIO; |
626 | icd->exposure = ctrl->value; | 630 | icd->exposure = ctrl->value; |
@@ -628,17 +632,17 @@ static int mt9v022_set_control(struct soc_camera_device *icd, | |||
628 | break; | 632 | break; |
629 | case V4L2_CID_AUTOGAIN: | 633 | case V4L2_CID_AUTOGAIN: |
630 | if (ctrl->value) | 634 | if (ctrl->value) |
631 | data = reg_set(icd, MT9V022_AEC_AGC_ENABLE, 0x2); | 635 | data = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x2); |
632 | else | 636 | else |
633 | data = reg_clear(icd, MT9V022_AEC_AGC_ENABLE, 0x2); | 637 | data = reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x2); |
634 | if (data < 0) | 638 | if (data < 0) |
635 | return -EIO; | 639 | return -EIO; |
636 | break; | 640 | break; |
637 | case V4L2_CID_EXPOSURE_AUTO: | 641 | case V4L2_CID_EXPOSURE_AUTO: |
638 | if (ctrl->value) | 642 | if (ctrl->value) |
639 | data = reg_set(icd, MT9V022_AEC_AGC_ENABLE, 0x1); | 643 | data = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x1); |
640 | else | 644 | else |
641 | data = reg_clear(icd, MT9V022_AEC_AGC_ENABLE, 0x1); | 645 | data = reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x1); |
642 | if (data < 0) | 646 | if (data < 0) |
643 | return -EIO; | 647 | return -EIO; |
644 | break; | 648 | break; |
@@ -650,8 +654,9 @@ static int mt9v022_set_control(struct soc_camera_device *icd, | |||
650 | * this wasn't our capture interface, so, we wait for the right one */ | 654 | * this wasn't our capture interface, so, we wait for the right one */ |
651 | static int mt9v022_video_probe(struct soc_camera_device *icd) | 655 | static int mt9v022_video_probe(struct soc_camera_device *icd) |
652 | { | 656 | { |
657 | struct i2c_client *client = to_i2c_client(icd->control); | ||
653 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); | 658 | struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); |
654 | struct soc_camera_link *icl = mt9v022->client->dev.platform_data; | 659 | struct soc_camera_link *icl = client->dev.platform_data; |
655 | s32 data; | 660 | s32 data; |
656 | int ret; | 661 | int ret; |
657 | unsigned long flags; | 662 | unsigned long flags; |
@@ -661,7 +666,7 @@ static int mt9v022_video_probe(struct soc_camera_device *icd) | |||
661 | return -ENODEV; | 666 | return -ENODEV; |
662 | 667 | ||
663 | /* Read out the chip version register */ | 668 | /* Read out the chip version register */ |
664 | data = reg_read(icd, MT9V022_CHIP_VERSION); | 669 | data = reg_read(client, MT9V022_CHIP_VERSION); |
665 | 670 | ||
666 | /* must be 0x1311 or 0x1313 */ | 671 | /* must be 0x1311 or 0x1313 */ |
667 | if (data != 0x1311 && data != 0x1313) { | 672 | if (data != 0x1311 && data != 0x1313) { |
@@ -672,12 +677,12 @@ static int mt9v022_video_probe(struct soc_camera_device *icd) | |||
672 | } | 677 | } |
673 | 678 | ||
674 | /* Soft reset */ | 679 | /* Soft reset */ |
675 | ret = reg_write(icd, MT9V022_RESET, 1); | 680 | ret = reg_write(client, MT9V022_RESET, 1); |
676 | if (ret < 0) | 681 | if (ret < 0) |
677 | goto ei2c; | 682 | goto ei2c; |
678 | /* 15 clock cycles */ | 683 | /* 15 clock cycles */ |
679 | udelay(200); | 684 | udelay(200); |
680 | if (reg_read(icd, MT9V022_RESET)) { | 685 | if (reg_read(client, MT9V022_RESET)) { |
681 | dev_err(&icd->dev, "Resetting MT9V022 failed!\n"); | 686 | dev_err(&icd->dev, "Resetting MT9V022 failed!\n"); |
682 | goto ei2c; | 687 | goto ei2c; |
683 | } | 688 | } |
@@ -685,11 +690,11 @@ static int mt9v022_video_probe(struct soc_camera_device *icd) | |||
685 | /* Set monochrome or colour sensor type */ | 690 | /* Set monochrome or colour sensor type */ |
686 | if (sensor_type && (!strcmp("colour", sensor_type) || | 691 | if (sensor_type && (!strcmp("colour", sensor_type) || |
687 | !strcmp("color", sensor_type))) { | 692 | !strcmp("color", sensor_type))) { |
688 | ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 4 | 0x11); | 693 | ret = reg_write(client, MT9V022_PIXEL_OPERATION_MODE, 4 | 0x11); |
689 | mt9v022->model = V4L2_IDENT_MT9V022IX7ATC; | 694 | mt9v022->model = V4L2_IDENT_MT9V022IX7ATC; |
690 | icd->formats = mt9v022_colour_formats; | 695 | icd->formats = mt9v022_colour_formats; |
691 | } else { | 696 | } else { |
692 | ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 0x11); | 697 | ret = reg_write(client, MT9V022_PIXEL_OPERATION_MODE, 0x11); |
693 | mt9v022->model = V4L2_IDENT_MT9V022IX7ATM; | 698 | mt9v022->model = V4L2_IDENT_MT9V022IX7ATM; |
694 | icd->formats = mt9v022_monochrome_formats; | 699 | icd->formats = mt9v022_monochrome_formats; |
695 | } | 700 | } |