aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tvp5150.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/tvp5150.c')
-rw-r--r--drivers/media/video/tvp5150.c95
1 files changed, 67 insertions, 28 deletions
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index b7867427e5c4..0d897cb1774a 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -61,13 +61,20 @@ static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr)
61 int rc; 61 int rc;
62 62
63 buffer[0] = addr; 63 buffer[0] = addr;
64 if (1 != (rc = i2c_master_send(c, buffer, 1))) 64
65 v4l2_dbg(0, debug, sd, "i2c i/o error: rc == %d (should be 1)\n", rc); 65 rc = i2c_master_send(c, buffer, 1);
66 if (rc < 0) {
67 v4l2_err(sd, "i2c i/o error: rc == %d (should be 1)\n", rc);
68 return rc;
69 }
66 70
67 msleep(10); 71 msleep(10);
68 72
69 if (1 != (rc = i2c_master_recv(c, buffer, 1))) 73 rc = i2c_master_recv(c, buffer, 1);
70 v4l2_dbg(0, debug, sd, "i2c i/o error: rc == %d (should be 1)\n", rc); 74 if (rc < 0) {
75 v4l2_err(sd, "i2c i/o error: rc == %d (should be 1)\n", rc);
76 return rc;
77 }
71 78
72 v4l2_dbg(2, debug, sd, "tvp5150: read 0x%02x = 0x%02x\n", addr, buffer[0]); 79 v4l2_dbg(2, debug, sd, "tvp5150: read 0x%02x = 0x%02x\n", addr, buffer[0]);
73 80
@@ -279,6 +286,11 @@ static inline void tvp5150_selmux(struct v4l2_subdev *sd)
279 * For Composite and TV, it should be the reverse 286 * For Composite and TV, it should be the reverse
280 */ 287 */
281 val = tvp5150_read(sd, TVP5150_MISC_CTL); 288 val = tvp5150_read(sd, TVP5150_MISC_CTL);
289 if (val < 0) {
290 v4l2_err(sd, "%s: failed with error = %d\n", __func__, val);
291 return;
292 }
293
282 if (decoder->input == TVP5150_SVIDEO) 294 if (decoder->input == TVP5150_SVIDEO)
283 val = (val & ~0x40) | 0x10; 295 val = (val & ~0x40) | 0x10;
284 else 296 else
@@ -676,6 +688,7 @@ static int tvp5150_get_vbi(struct v4l2_subdev *sd,
676 v4l2_std_id std = decoder->norm; 688 v4l2_std_id std = decoder->norm;
677 u8 reg; 689 u8 reg;
678 int pos, type = 0; 690 int pos, type = 0;
691 int i, ret = 0;
679 692
680 if (std == V4L2_STD_ALL) { 693 if (std == V4L2_STD_ALL) {
681 v4l2_err(sd, "VBI can't be configured without knowing number of lines\n"); 694 v4l2_err(sd, "VBI can't be configured without knowing number of lines\n");
@@ -690,13 +703,17 @@ static int tvp5150_get_vbi(struct v4l2_subdev *sd,
690 703
691 reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI; 704 reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI;
692 705
693 pos = tvp5150_read(sd, reg) & 0x0f; 706 for (i = 0; i <= 1; i++) {
694 if (pos < 0x0f) 707 ret = tvp5150_read(sd, reg + i);
695 type = regs[pos].type.vbi_type; 708 if (ret < 0) {
696 709 v4l2_err(sd, "%s: failed with error = %d\n",
697 pos = tvp5150_read(sd, reg + 1) & 0x0f; 710 __func__, ret);
698 if (pos < 0x0f) 711 return 0;
699 type |= regs[pos].type.vbi_type; 712 }
713 pos = ret & 0x0f;
714 if (pos < 0x0f)
715 type |= regs[pos].type.vbi_type;
716 }
700 717
701 return type; 718 return type;
702} 719}
@@ -1031,13 +1048,21 @@ static int tvp5150_g_chip_ident(struct v4l2_subdev *sd,
1031#ifdef CONFIG_VIDEO_ADV_DEBUG 1048#ifdef CONFIG_VIDEO_ADV_DEBUG
1032static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 1049static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
1033{ 1050{
1051 int res;
1052
1034 struct i2c_client *client = v4l2_get_subdevdata(sd); 1053 struct i2c_client *client = v4l2_get_subdevdata(sd);
1035 1054
1036 if (!v4l2_chip_match_i2c_client(client, &reg->match)) 1055 if (!v4l2_chip_match_i2c_client(client, &reg->match))
1037 return -EINVAL; 1056 return -EINVAL;
1038 if (!capable(CAP_SYS_ADMIN)) 1057 if (!capable(CAP_SYS_ADMIN))
1039 return -EPERM; 1058 return -EPERM;
1040 reg->val = tvp5150_read(sd, reg->reg & 0xff); 1059 res = tvp5150_read(sd, reg->reg & 0xff);
1060 if (res < 0) {
1061 v4l2_err(sd, "%s: failed with error = %d\n", __func__, res);
1062 return res;
1063 }
1064
1065 reg->val = res;
1041 reg->size = 1; 1066 reg->size = 1;
1042 return 0; 1067 return 0;
1043} 1068}
@@ -1126,7 +1151,8 @@ static int tvp5150_probe(struct i2c_client *c,
1126{ 1151{
1127 struct tvp5150 *core; 1152 struct tvp5150 *core;
1128 struct v4l2_subdev *sd; 1153 struct v4l2_subdev *sd;
1129 u8 msb_id, lsb_id, msb_rom, lsb_rom; 1154 int tvp5150_id[4];
1155 int i, res;
1130 1156
1131 /* Check if the adapter supports the needed features */ 1157 /* Check if the adapter supports the needed features */
1132 if (!i2c_check_functionality(c->adapter, 1158 if (!i2c_check_functionality(c->adapter,
@@ -1139,26 +1165,37 @@ static int tvp5150_probe(struct i2c_client *c,
1139 } 1165 }
1140 sd = &core->sd; 1166 sd = &core->sd;
1141 v4l2_i2c_subdev_init(sd, c, &tvp5150_ops); 1167 v4l2_i2c_subdev_init(sd, c, &tvp5150_ops);
1168
1169 /*
1170 * Read consequent registers - TVP5150_MSB_DEV_ID, TVP5150_LSB_DEV_ID,
1171 * TVP5150_ROM_MAJOR_VER, TVP5150_ROM_MINOR_VER
1172 */
1173 for (i = 0; i < 4; i++) {
1174 res = tvp5150_read(sd, TVP5150_MSB_DEV_ID + i);
1175 if (res < 0)
1176 goto free_core;
1177 tvp5150_id[i] = res;
1178 }
1179
1142 v4l_info(c, "chip found @ 0x%02x (%s)\n", 1180 v4l_info(c, "chip found @ 0x%02x (%s)\n",
1143 c->addr << 1, c->adapter->name); 1181 c->addr << 1, c->adapter->name);
1144 1182
1145 msb_id = tvp5150_read(sd, TVP5150_MSB_DEV_ID); 1183 if (tvp5150_id[2] == 4 && tvp5150_id[3] == 0) { /* Is TVP5150AM1 */
1146 lsb_id = tvp5150_read(sd, TVP5150_LSB_DEV_ID); 1184 v4l2_info(sd, "tvp%02x%02xam1 detected.\n",
1147 msb_rom = tvp5150_read(sd, TVP5150_ROM_MAJOR_VER); 1185 tvp5150_id[0], tvp5150_id[1]);
1148 lsb_rom = tvp5150_read(sd, TVP5150_ROM_MINOR_VER);
1149
1150 if (msb_rom == 4 && lsb_rom == 0) { /* Is TVP5150AM1 */
1151 v4l2_info(sd, "tvp%02x%02xam1 detected.\n", msb_id, lsb_id);
1152 1186
1153 /* ITU-T BT.656.4 timing */ 1187 /* ITU-T BT.656.4 timing */
1154 tvp5150_write(sd, TVP5150_REV_SELECT, 0); 1188 tvp5150_write(sd, TVP5150_REV_SELECT, 0);
1155 } else { 1189 } else {
1156 if (msb_rom == 3 || lsb_rom == 0x21) { /* Is TVP5150A */ 1190 /* Is TVP5150A */
1157 v4l2_info(sd, "tvp%02x%02xa detected.\n", msb_id, lsb_id); 1191 if (tvp5150_id[2] == 3 || tvp5150_id[3] == 0x21) {
1192 v4l2_info(sd, "tvp%02x%02xa detected.\n",
1193 tvp5150_id[2], tvp5150_id[3]);
1158 } else { 1194 } else {
1159 v4l2_info(sd, "*** unknown tvp%02x%02x chip detected.\n", 1195 v4l2_info(sd, "*** unknown tvp%02x%02x chip detected.\n",
1160 msb_id, lsb_id); 1196 tvp5150_id[2], tvp5150_id[3]);
1161 v4l2_info(sd, "*** Rom ver is %d.%d\n", msb_rom, lsb_rom); 1197 v4l2_info(sd, "*** Rom ver is %d.%d\n",
1198 tvp5150_id[2], tvp5150_id[3]);
1162 } 1199 }
1163 } 1200 }
1164 1201
@@ -1177,11 +1214,9 @@ static int tvp5150_probe(struct i2c_client *c,
1177 V4L2_CID_HUE, -128, 127, 1, 0); 1214 V4L2_CID_HUE, -128, 127, 1, 0);
1178 sd->ctrl_handler = &core->hdl; 1215 sd->ctrl_handler = &core->hdl;
1179 if (core->hdl.error) { 1216 if (core->hdl.error) {
1180 int err = core->hdl.error; 1217 res = core->hdl.error;
1181
1182 v4l2_ctrl_handler_free(&core->hdl); 1218 v4l2_ctrl_handler_free(&core->hdl);
1183 kfree(core); 1219 goto free_core;
1184 return err;
1185 } 1220 }
1186 v4l2_ctrl_handler_setup(&core->hdl); 1221 v4l2_ctrl_handler_setup(&core->hdl);
1187 1222
@@ -1197,6 +1232,10 @@ static int tvp5150_probe(struct i2c_client *c,
1197 if (debug > 1) 1232 if (debug > 1)
1198 tvp5150_log_status(sd); 1233 tvp5150_log_status(sd);
1199 return 0; 1234 return 0;
1235
1236free_core:
1237 kfree(core);
1238 return res;
1200} 1239}
1201 1240
1202static int tvp5150_remove(struct i2c_client *c) 1241static int tvp5150_remove(struct i2c_client *c)