aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/media/video/gspca/sn9c20x.c323
1 files changed, 171 insertions, 152 deletions
diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c
index 45092eed8fc..15c371e4f8d 100644
--- a/drivers/media/video/gspca/sn9c20x.c
+++ b/drivers/media/video/gspca/sn9c20x.c
@@ -1061,10 +1061,13 @@ static struct i2c_reg_u8 hv7131r_init[] = {
1061 {0x23, 0x09}, {0x01, 0x08}, 1061 {0x23, 0x09}, {0x01, 0x08},
1062}; 1062};
1063 1063
1064static int reg_r(struct gspca_dev *gspca_dev, u16 reg, u16 length) 1064static void reg_r(struct gspca_dev *gspca_dev, u16 reg, u16 length)
1065{ 1065{
1066 struct usb_device *dev = gspca_dev->dev; 1066 struct usb_device *dev = gspca_dev->dev;
1067 int result; 1067 int result;
1068
1069 if (gspca_dev->usb_err < 0)
1070 return;
1068 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 1071 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
1069 0x00, 1072 0x00,
1070 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 1073 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
@@ -1074,17 +1077,19 @@ static int reg_r(struct gspca_dev *gspca_dev, u16 reg, u16 length)
1074 length, 1077 length,
1075 500); 1078 500);
1076 if (unlikely(result < 0 || result != length)) { 1079 if (unlikely(result < 0 || result != length)) {
1077 pr_err("Read register failed 0x%02X\n", reg); 1080 pr_err("Read register %02x failed %d\n", reg, result);
1078 return -EIO; 1081 gspca_dev->usb_err = result;
1079 } 1082 }
1080 return 0;
1081} 1083}
1082 1084
1083static int reg_w(struct gspca_dev *gspca_dev, u16 reg, 1085static void reg_w(struct gspca_dev *gspca_dev, u16 reg,
1084 const u8 *buffer, int length) 1086 const u8 *buffer, int length)
1085{ 1087{
1086 struct usb_device *dev = gspca_dev->dev; 1088 struct usb_device *dev = gspca_dev->dev;
1087 int result; 1089 int result;
1090
1091 if (gspca_dev->usb_err < 0)
1092 return;
1088 memcpy(gspca_dev->usb_buf, buffer, length); 1093 memcpy(gspca_dev->usb_buf, buffer, length);
1089 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 1094 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1090 0x08, 1095 0x08,
@@ -1095,35 +1100,39 @@ static int reg_w(struct gspca_dev *gspca_dev, u16 reg,
1095 length, 1100 length,
1096 500); 1101 500);
1097 if (unlikely(result < 0 || result != length)) { 1102 if (unlikely(result < 0 || result != length)) {
1098 pr_err("Write register failed index 0x%02X\n", reg); 1103 pr_err("Write register %02x failed %d\n", reg, result);
1099 return -EIO; 1104 gspca_dev->usb_err = result;
1100 } 1105 }
1101 return 0;
1102} 1106}
1103 1107
1104static int reg_w1(struct gspca_dev *gspca_dev, u16 reg, const u8 value) 1108static void reg_w1(struct gspca_dev *gspca_dev, u16 reg, const u8 value)
1105{ 1109{
1106 u8 data[1] = {value}; 1110 u8 data[1] = {value};
1107 return reg_w(gspca_dev, reg, data, 1); 1111 reg_w(gspca_dev, reg, data, 1);
1108} 1112}
1109 1113
1110static int i2c_w(struct gspca_dev *gspca_dev, const u8 *buffer) 1114static void i2c_w(struct gspca_dev *gspca_dev, const u8 *buffer)
1111{ 1115{
1112 int i; 1116 int i;
1113 reg_w(gspca_dev, 0x10c0, buffer, 8); 1117 reg_w(gspca_dev, 0x10c0, buffer, 8);
1114 for (i = 0; i < 5; i++) { 1118 for (i = 0; i < 5; i++) {
1115 reg_r(gspca_dev, 0x10c0, 1); 1119 reg_r(gspca_dev, 0x10c0, 1);
1120 if (gspca_dev->usb_err < 0)
1121 return;
1116 if (gspca_dev->usb_buf[0] & 0x04) { 1122 if (gspca_dev->usb_buf[0] & 0x04) {
1117 if (gspca_dev->usb_buf[0] & 0x08) 1123 if (gspca_dev->usb_buf[0] & 0x08) {
1118 return -EIO; 1124 pr_err("i2c_w error\n");
1119 return 0; 1125 gspca_dev->usb_err = -EIO;
1126 }
1127 return;
1120 } 1128 }
1121 msleep(1); 1129 msleep(1);
1122 } 1130 }
1123 return -EIO; 1131 pr_err("i2c_w reg %02x no response\n", buffer[2]);
1132/* gspca_dev->usb_err = -EIO; fixme: may occur */
1124} 1133}
1125 1134
1126static int i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val) 1135static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
1127{ 1136{
1128 struct sd *sd = (struct sd *) gspca_dev; 1137 struct sd *sd = (struct sd *) gspca_dev;
1129 1138
@@ -1142,10 +1151,10 @@ static int i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
1142 row[6] = 0x00; 1151 row[6] = 0x00;
1143 row[7] = 0x10; 1152 row[7] = 0x10;
1144 1153
1145 return i2c_w(gspca_dev, row); 1154 i2c_w(gspca_dev, row);
1146} 1155}
1147 1156
1148static int i2c_w2(struct gspca_dev *gspca_dev, u8 reg, u16 val) 1157static void i2c_w2(struct gspca_dev *gspca_dev, u8 reg, u16 val)
1149{ 1158{
1150 struct sd *sd = (struct sd *) gspca_dev; 1159 struct sd *sd = (struct sd *) gspca_dev;
1151 u8 row[8]; 1160 u8 row[8];
@@ -1163,10 +1172,10 @@ static int i2c_w2(struct gspca_dev *gspca_dev, u8 reg, u16 val)
1163 row[6] = 0x00; 1172 row[6] = 0x00;
1164 row[7] = 0x10; 1173 row[7] = 0x10;
1165 1174
1166 return i2c_w(gspca_dev, row); 1175 i2c_w(gspca_dev, row);
1167} 1176}
1168 1177
1169static int i2c_r1(struct gspca_dev *gspca_dev, u8 reg, u8 *val) 1178static void i2c_r1(struct gspca_dev *gspca_dev, u8 reg, u8 *val)
1170{ 1179{
1171 struct sd *sd = (struct sd *) gspca_dev; 1180 struct sd *sd = (struct sd *) gspca_dev;
1172 u8 row[8]; 1181 u8 row[8];
@@ -1179,19 +1188,15 @@ static int i2c_r1(struct gspca_dev *gspca_dev, u8 reg, u8 *val)
1179 row[5] = 0; 1188 row[5] = 0;
1180 row[6] = 0; 1189 row[6] = 0;
1181 row[7] = 0x10; 1190 row[7] = 0x10;
1182 if (i2c_w(gspca_dev, row) < 0) 1191 i2c_w(gspca_dev, row);
1183 return -EIO;
1184 row[0] = 0x81 | (1 << 4) | 0x02; 1192 row[0] = 0x81 | (1 << 4) | 0x02;
1185 row[2] = 0; 1193 row[2] = 0;
1186 if (i2c_w(gspca_dev, row) < 0) 1194 i2c_w(gspca_dev, row);
1187 return -EIO; 1195 reg_r(gspca_dev, 0x10c2, 5);
1188 if (reg_r(gspca_dev, 0x10c2, 5) < 0)
1189 return -EIO;
1190 *val = gspca_dev->usb_buf[4]; 1196 *val = gspca_dev->usb_buf[4];
1191 return 0;
1192} 1197}
1193 1198
1194static int i2c_r2(struct gspca_dev *gspca_dev, u8 reg, u16 *val) 1199static void i2c_r2(struct gspca_dev *gspca_dev, u8 reg, u16 *val)
1195{ 1200{
1196 struct sd *sd = (struct sd *) gspca_dev; 1201 struct sd *sd = (struct sd *) gspca_dev;
1197 u8 row[8]; 1202 u8 row[8];
@@ -1204,73 +1209,72 @@ static int i2c_r2(struct gspca_dev *gspca_dev, u8 reg, u16 *val)
1204 row[5] = 0; 1209 row[5] = 0;
1205 row[6] = 0; 1210 row[6] = 0;
1206 row[7] = 0x10; 1211 row[7] = 0x10;
1207 if (i2c_w(gspca_dev, row) < 0) 1212 i2c_w(gspca_dev, row);
1208 return -EIO;
1209 row[0] = 0x81 | (2 << 4) | 0x02; 1213 row[0] = 0x81 | (2 << 4) | 0x02;
1210 row[2] = 0; 1214 row[2] = 0;
1211 if (i2c_w(gspca_dev, row) < 0) 1215 i2c_w(gspca_dev, row);
1212 return -EIO; 1216 reg_r(gspca_dev, 0x10c2, 5);
1213 if (reg_r(gspca_dev, 0x10c2, 5) < 0)
1214 return -EIO;
1215 *val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4]; 1217 *val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1216 return 0;
1217} 1218}
1218 1219
1219static int ov9650_init_sensor(struct gspca_dev *gspca_dev) 1220static void ov9650_init_sensor(struct gspca_dev *gspca_dev)
1220{ 1221{
1221 int i; 1222 int i;
1222 u16 id; 1223 u16 id;
1223 struct sd *sd = (struct sd *) gspca_dev; 1224 struct sd *sd = (struct sd *) gspca_dev;
1224 1225
1225 if (i2c_r2(gspca_dev, 0x1c, &id) < 0) 1226 i2c_r2(gspca_dev, 0x1c, &id);
1226 return -EINVAL; 1227 if (gspca_dev->usb_err < 0)
1228 return;