aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2014-01-08 17:30:37 -0500
committerMauro Carvalho Chehab <m.chehab@samsung.com>2014-05-25 11:52:02 -0400
commit51182a945c3e267b9183643da3e6e4642fbe6cf2 (patch)
tree50482524cae7a3b1fe28ae117408115398b459f7 /drivers/media
parentf216ccb3d9d5603f750e50dbe66190de87dc52d8 (diff)
[media] adv7604: Add 16-bit read functions for CP and HDMI
16-bit registers are read through two 8-bit read operations. Factorize that common pattern into 16-bit read accessors to simplify the code. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/i2c/adv7604.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index dd0a9a96305d..da256ddf06d3 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -542,6 +542,11 @@ static inline int hdmi_read(struct v4l2_subdev *sd, u8 reg)
542 return adv_smbus_read_byte_data(state->i2c_hdmi, reg); 542 return adv_smbus_read_byte_data(state->i2c_hdmi, reg);
543} 543}
544 544
545static u16 hdmi_read16(struct v4l2_subdev *sd, u8 reg, u16 mask)
546{
547 return ((hdmi_read(sd, reg) << 8) | hdmi_read(sd, reg + 1)) & mask;
548}
549
545static inline int hdmi_write(struct v4l2_subdev *sd, u8 reg, u8 val) 550static inline int hdmi_write(struct v4l2_subdev *sd, u8 reg, u8 val)
546{ 551{
547 struct adv7604_state *state = to_state(sd); 552 struct adv7604_state *state = to_state(sd);
@@ -575,6 +580,11 @@ static inline int cp_read(struct v4l2_subdev *sd, u8 reg)
575 return adv_smbus_read_byte_data(state->i2c_cp, reg); 580 return adv_smbus_read_byte_data(state->i2c_cp, reg);
576} 581}
577 582
583static u16 cp_read16(struct v4l2_subdev *sd, u8 reg, u16 mask)
584{
585 return ((cp_read(sd, reg) << 8) | cp_read(sd, reg + 1)) & mask;
586}
587
578static inline int cp_write(struct v4l2_subdev *sd, u8 reg, u8 val) 588static inline int cp_write(struct v4l2_subdev *sd, u8 reg, u8 val)
579{ 589{
580 struct adv7604_state *state = to_state(sd); 590 struct adv7604_state *state = to_state(sd);
@@ -1203,8 +1213,8 @@ static int read_stdi(struct v4l2_subdev *sd, struct stdi_readback *stdi)
1203 } 1213 }
1204 1214
1205 /* read STDI */ 1215 /* read STDI */
1206 stdi->bl = ((cp_read(sd, 0xb1) & 0x3f) << 8) | cp_read(sd, 0xb2); 1216 stdi->bl = cp_read16(sd, 0xb1, 0x3fff);
1207 stdi->lcf = ((cp_read(sd, 0xb3) & 0x7) << 8) | cp_read(sd, 0xb4); 1217 stdi->lcf = cp_read16(sd, 0xb3, 0x7ff);
1208 stdi->lcvs = cp_read(sd, 0xb3) >> 3; 1218 stdi->lcvs = cp_read(sd, 0xb3) >> 3;
1209 stdi->interlaced = io_read(sd, 0x12) & 0x10; 1219 stdi->interlaced = io_read(sd, 0x12) & 0x10;
1210 1220
@@ -1315,8 +1325,8 @@ static int adv7604_query_dv_timings(struct v4l2_subdev *sd,
1315 1325
1316 timings->type = V4L2_DV_BT_656_1120; 1326 timings->type = V4L2_DV_BT_656_1120;
1317 1327
1318 bt->width = (hdmi_read(sd, 0x07) & 0x0f) * 256 + hdmi_read(sd, 0x08); 1328 bt->width = hdmi_read16(sd, 0x07, 0xfff);
1319 bt->height = (hdmi_read(sd, 0x09) & 0x0f) * 256 + hdmi_read(sd, 0x0a); 1329 bt->height = hdmi_read16(sd, 0x09, 0xfff);
1320 freq = (hdmi_read(sd, 0x06) * 1000000) + 1330 freq = (hdmi_read(sd, 0x06) * 1000000) +
1321 ((hdmi_read(sd, 0x3b) & 0x30) >> 4) * 250000; 1331 ((hdmi_read(sd, 0x3b) & 0x30) >> 4) * 250000;
1322 if (is_hdmi(sd)) { 1332 if (is_hdmi(sd)) {
@@ -1326,29 +1336,19 @@ static int adv7604_query_dv_timings(struct v4l2_subdev *sd,
1326 freq = freq * 8 / bits_per_channel; 1336 freq = freq * 8 / bits_per_channel;
1327 } 1337 }
1328 bt->pixelclock = freq; 1338 bt->pixelclock = freq;
1329 bt->hfrontporch = (hdmi_read(sd, 0x20) & 0x03) * 256 + 1339 bt->hfrontporch = hdmi_read16(sd, 0x20, 0x3ff);
1330 hdmi_read(sd, 0x21); 1340 bt->hsync = hdmi_read16(sd, 0x22, 0x3ff);
1331 bt->hsync = (hdmi_read(sd, 0x22) & 0x03) * 256 + 1341 bt->hbackporch = hdmi_read16(sd, 0x24, 0x3ff);
1332 hdmi_read(sd, 0x23); 1342 bt->vfrontporch = hdmi_read16(sd, 0x2a, 0x1fff) / 2;
1333 bt->hbackporch = (hdmi_read(sd, 0x24) & 0x03) * 256 + 1343 bt->vsync = hdmi_read16(sd, 0x2e, 0x1fff) / 2;
1334 hdmi_read(sd, 0x25); 1344 bt->vbackporch = hdmi_read16(sd, 0x32, 0x1fff) / 2;
1335 bt->vfrontporch = ((hdmi_read(sd, 0x2a) & 0x1f) * 256 +
1336 hdmi_read(sd, 0x2b)) / 2;
1337 bt->vsync = ((hdmi_read(sd, 0x2e) & 0x1f) * 256 +
1338 hdmi_read(sd, 0x2f)) / 2;
1339 bt->vbackporch = ((hdmi_read(sd, 0x32) & 0x1f) * 256 +
1340 hdmi_read(sd, 0x33)) / 2;
1341 bt->polarities = ((hdmi_read(sd, 0x05) & 0x10) ? V4L2_DV_VSYNC_POS_POL : 0) | 1345 bt->polarities = ((hdmi_read(sd, 0x05) & 0x10) ? V4L2_DV_VSYNC_POS_POL : 0) |
1342 ((hdmi_read(sd, 0x05) & 0x20) ? V4L2_DV_HSYNC_POS_POL : 0); 1346 ((hdmi_read(sd, 0x05) & 0x20) ? V4L2_DV_HSYNC_POS_POL : 0);
1343 if (bt->interlaced == V4L2_DV_INTERLACED) { 1347 if (bt->interlaced == V4L2_DV_INTERLACED) {
1344 bt->height += (hdmi_read(sd, 0x0b) & 0x0f) * 256 + 1348 bt->height += hdmi_read16(sd, 0x0b, 0xfff);
1345 hdmi_read(sd, 0x0c); 1349 bt->il_vfrontporch = hdmi_read16(sd, 0x2c, 0x1fff) / 2;
1346 bt->il_vfrontporch = ((hdmi_read(sd, 0x2c) & 0x1f) * 256 + 1350 bt->il_vsync = hdmi_read16(sd, 0x30, 0x1fff) / 2;
1347 hdmi_read(sd, 0x2d)) / 2; 1351 bt->vbackporch = hdmi_read16(sd, 0x34, 0x1fff) / 2;
1348 bt->il_vsync = ((hdmi_read(sd, 0x30) & 0x1f) * 256 +
1349 hdmi_read(sd, 0x31)) / 2;
1350 bt->vbackporch = ((hdmi_read(sd, 0x34) & 0x1f) * 256 +
1351 hdmi_read(sd, 0x35)) / 2;
1352 } 1352 }
1353 adv7604_fill_optional_dv_timings_fields(sd, timings); 1353 adv7604_fill_optional_dv_timings_fields(sd, timings);
1354 } else { 1354 } else {