aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/mt9m111.c
diff options
context:
space:
mode:
authorGuennadi Liakhovetski <g.liakhovetski@gmx.de>2009-04-24 11:57:01 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-06-16 17:20:43 -0400
commit9538e1c226f1fd665126869f542170a2e90f2039 (patch)
tree3a0b01a6d84980a55eac9e87c9822dec31514006 /drivers/media/video/mt9m111.c
parenteff505fa1511b753b7cfb397a754b8ff4367cd55 (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/media/video/mt9m111.c')
-rw-r--r--drivers/media/video/mt9m111.c73
1 files changed, 40 insertions, 33 deletions
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
187static int mt9m111_reg_read(struct soc_camera_device *icd, const u16 reg) 187static 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
201static int mt9m111_reg_write(struct soc_camera_device *icd, const u16 reg, 199static 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
216static int mt9m111_reg_set(struct soc_camera_device *icd, const u16 reg, 212static 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
227static int mt9m111_reg_clear(struct soc_camera_device *icd, const u16 reg, 223static 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
236static int mt9m111_set_context(struct soc_camera_device *icd, 232static 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,
252static int mt9m111_setup_rect(struct soc_camera_device *icd, 249static 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
297static int mt9m111_setup_pixfmt(struct soc_camera_device *icd, u16 outfmt) 295static 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
358static int mt9m111_enable(struct soc_camera_device *icd) 357static 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
379static int mt9m111_disable(struct soc_camera_device *icd) 379static 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
395static int mt9m111_reset(struct soc_camera_device *icd) 396static 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,
583static int mt9m111_set_register(struct soc_camera_device *icd, 583static 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
673static int mt9m111_set_flip(struct soc_camera_device *icd, int flip, int mask) 673static 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
693static int mt9m111_get_global_gain(struct soc_camera_device *icd) 694static 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
704static int mt9m111_set_global_gain(struct soc_camera_device *icd, int gain) 706static 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
722static int mt9m111_set_autoexposure(struct soc_camera_device *icd, int on) 725static 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
738static int mt9m111_set_autowhitebalance(struct soc_camera_device *icd, int on) 742static 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)
754static int mt9m111_get_control(struct soc_camera_device *icd, 759static 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 */
899static int mt9m111_video_probe(struct soc_camera_device *icd) 905static 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;