diff options
author | Jean-François Moine <moinejf@free.fr> | 2012-03-19 03:42:45 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-03-19 21:30:48 -0400 |
commit | d4689b740424e8163eefebcd21368a8c6273a7a2 (patch) | |
tree | 7de735c6d72c091ffbcd01363ef8e57dc330a495 /drivers/media | |
parent | 4c632e4e51e5d89af75ecf3e958988658c01294f (diff) |
[media] gspca - sn9c20x: Optimize the code of write sequences
The new functions i2c_w1_buf() and i2c_w2_buf() handle the write loops.
Signed-off-by: Jean-François Moine <moinejf@free.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/video/gspca/sn9c20x.c | 169 |
1 files changed, 66 insertions, 103 deletions
diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c index 0894a3d2c336..e45f5c4545ea 100644 --- a/drivers/media/video/gspca/sn9c20x.c +++ b/drivers/media/video/gspca/sn9c20x.c | |||
@@ -1172,6 +1172,15 @@ static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val) | |||
1172 | i2c_w(gspca_dev, row); | 1172 | i2c_w(gspca_dev, row); |
1173 | } | 1173 | } |
1174 | 1174 | ||
1175 | static void i2c_w1_buf(struct gspca_dev *gspca_dev, | ||
1176 | struct i2c_reg_u8 *buf, int sz) | ||
1177 | { | ||
1178 | while (--sz >= 0) { | ||
1179 | i2c_w1(gspca_dev, buf->reg, buf->val); | ||
1180 | buf++; | ||
1181 | } | ||
1182 | } | ||
1183 | |||
1175 | static void i2c_w2(struct gspca_dev *gspca_dev, u8 reg, u16 val) | 1184 | static void i2c_w2(struct gspca_dev *gspca_dev, u8 reg, u16 val) |
1176 | { | 1185 | { |
1177 | struct sd *sd = (struct sd *) gspca_dev; | 1186 | struct sd *sd = (struct sd *) gspca_dev; |
@@ -1193,6 +1202,15 @@ static void i2c_w2(struct gspca_dev *gspca_dev, u8 reg, u16 val) | |||
1193 | i2c_w(gspca_dev, row); | 1202 | i2c_w(gspca_dev, row); |
1194 | } | 1203 | } |
1195 | 1204 | ||
1205 | static void i2c_w2_buf(struct gspca_dev *gspca_dev, | ||
1206 | struct i2c_reg_u16 *buf, int sz) | ||
1207 | { | ||
1208 | while (--sz >= 0) { | ||
1209 | i2c_w2(gspca_dev, buf->reg, buf->val); | ||
1210 | buf++; | ||
1211 | } | ||
1212 | } | ||
1213 | |||
1196 | static void i2c_r1(struct gspca_dev *gspca_dev, u8 reg, u8 *val) | 1214 | static void i2c_r1(struct gspca_dev *gspca_dev, u8 reg, u8 *val) |
1197 | { | 1215 | { |
1198 | struct sd *sd = (struct sd *) gspca_dev; | 1216 | struct sd *sd = (struct sd *) gspca_dev; |
@@ -1237,7 +1255,6 @@ static void i2c_r2(struct gspca_dev *gspca_dev, u8 reg, u16 *val) | |||
1237 | 1255 | ||
1238 | static void ov9650_init_sensor(struct gspca_dev *gspca_dev) | 1256 | static void ov9650_init_sensor(struct gspca_dev *gspca_dev) |
1239 | { | 1257 | { |
1240 | int i; | ||
1241 | u16 id; | 1258 | u16 id; |
1242 | struct sd *sd = (struct sd *) gspca_dev; | 1259 | struct sd *sd = (struct sd *) gspca_dev; |
1243 | 1260 | ||
@@ -1253,33 +1270,23 @@ static void ov9650_init_sensor(struct gspca_dev *gspca_dev) | |||
1253 | 1270 | ||
1254 | i2c_w1(gspca_dev, 0x12, 0x80); /* sensor reset */ | 1271 | i2c_w1(gspca_dev, 0x12, 0x80); /* sensor reset */ |
1255 | msleep(200); | 1272 | msleep(200); |
1256 | for (i = 0; i < ARRAY_SIZE(ov9650_init); i++) { | 1273 | i2c_w1_buf(gspca_dev, ov9650_init, ARRAY_SIZE(ov9650_init)); |
1257 | i2c_w1(gspca_dev, ov9650_init[i].reg, | 1274 | if (gspca_dev->usb_err < 0) |
1258 | ov9650_init[i].val); | 1275 | pr_err("OV9650 sensor initialization failed\n"); |
1259 | if (gspca_dev->usb_err < 0) { | ||
1260 | pr_err("OV9650 sensor initialization failed\n"); | ||
1261 | return; | ||
1262 | } | ||
1263 | } | ||
1264 | sd->hstart = 1; | 1276 | sd->hstart = 1; |
1265 | sd->vstart = 7; | 1277 | sd->vstart = 7; |
1266 | } | 1278 | } |
1267 | 1279 | ||
1268 | static void ov9655_init_sensor(struct gspca_dev *gspca_dev) | 1280 | static void ov9655_init_sensor(struct gspca_dev *gspca_dev) |
1269 | { | 1281 | { |
1270 | int i; | ||
1271 | struct sd *sd = (struct sd *) gspca_dev; | 1282 | struct sd *sd = (struct sd *) gspca_dev; |
1272 | 1283 | ||
1273 | i2c_w1(gspca_dev, 0x12, 0x80); /* sensor reset */ | 1284 | i2c_w1(gspca_dev, 0x12, 0x80); /* sensor reset */ |
1274 | msleep(200); | 1285 | msleep(200); |
1275 | for (i = 0; i < ARRAY_SIZE(ov9655_init); i++) { | 1286 | i2c_w1_buf(gspca_dev, ov9655_init, ARRAY_SIZE(ov9655_init)); |
1276 | i2c_w1(gspca_dev, ov9655_init[i].reg, | 1287 | if (gspca_dev->usb_err < 0) |
1277 | ov9655_init[i].val); | 1288 | pr_err("OV9655 sensor initialization failed\n"); |
1278 | if (gspca_dev->usb_err < 0) { | 1289 | |
1279 | pr_err("OV9655 sensor initialization failed\n"); | ||
1280 | return; | ||
1281 | } | ||
1282 | } | ||
1283 | /* disable hflip and vflip */ | 1290 | /* disable hflip and vflip */ |
1284 | gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP); | 1291 | gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP); |
1285 | sd->hstart = 1; | 1292 | sd->hstart = 1; |
@@ -1288,19 +1295,14 @@ static void ov9655_init_sensor(struct gspca_dev *gspca_dev) | |||
1288 | 1295 | ||
1289 | static void soi968_init_sensor(struct gspca_dev *gspca_dev) | 1296 | static void soi968_init_sensor(struct gspca_dev *gspca_dev) |
1290 | { | 1297 | { |
1291 | int i; | ||
1292 | struct sd *sd = (struct sd *) gspca_dev; | 1298 | struct sd *sd = (struct sd *) gspca_dev; |
1293 | 1299 | ||
1294 | i2c_w1(gspca_dev, 0x12, 0x80); /* sensor reset */ | 1300 | i2c_w1(gspca_dev, 0x12, 0x80); /* sensor reset */ |
1295 | msleep(200); | 1301 | msleep(200); |
1296 | for (i = 0; i < ARRAY_SIZE(soi968_init); i++) { | 1302 | i2c_w1_buf(gspca_dev, soi968_init, ARRAY_SIZE(soi968_init)); |
1297 | i2c_w1(gspca_dev, soi968_init[i].reg, | 1303 | if (gspca_dev->usb_err < 0) |
1298 | soi968_init[i].val); | 1304 | pr_err("SOI968 sensor initialization failed\n"); |
1299 | if (gspca_dev->usb_err < 0) { | 1305 | |
1300 | pr_err("SOI968 sensor initialization failed\n"); | ||
1301 | return; | ||
1302 | } | ||
1303 | } | ||
1304 | /* disable hflip and vflip */ | 1306 | /* disable hflip and vflip */ |
1305 | gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP) | 1307 | gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP) |
1306 | | (1 << EXPOSURE); | 1308 | | (1 << EXPOSURE); |
@@ -1310,38 +1312,27 @@ static void soi968_init_sensor(struct gspca_dev *gspca_dev) | |||
1310 | 1312 | ||
1311 | static void ov7660_init_sensor(struct gspca_dev *gspca_dev) | 1313 | static void ov7660_init_sensor(struct gspca_dev *gspca_dev) |
1312 | { | 1314 | { |
1313 | int i; | ||
1314 | struct sd *sd = (struct sd *) gspca_dev; | 1315 | struct sd *sd = (struct sd *) gspca_dev; |
1315 | 1316 | ||
1316 | i2c_w1(gspca_dev, 0x12, 0x80); /* sensor reset */ | 1317 | i2c_w1(gspca_dev, 0x12, 0x80); /* sensor reset */ |
1317 | msleep(200); | 1318 | msleep(200); |
1318 | for (i = 0; i < ARRAY_SIZE(ov7660_init); i++) { | 1319 | i2c_w1_buf(gspca_dev, ov7660_init, ARRAY_SIZE(ov7660_init)); |
1319 | i2c_w1(gspca_dev, ov7660_init[i].reg, | 1320 | if (gspca_dev->usb_err < 0) |
1320 | ov7660_init[i].val); | 1321 | pr_err("OV7660 sensor initialization failed\n"); |
1321 | if (gspca_dev->usb_err < 0) { | ||
1322 | pr_err("OV7660 sensor initialization failed\n"); | ||
1323 | return; | ||
1324 | } | ||
1325 | } | ||
1326 | sd->hstart = 3; | 1322 | sd->hstart = 3; |
1327 | sd->vstart = 3; | 1323 | sd->vstart = 3; |
1328 | } | 1324 | } |
1329 | 1325 | ||
1330 | static void ov7670_init_sensor(struct gspca_dev *gspca_dev) | 1326 | static void ov7670_init_sensor(struct gspca_dev *gspca_dev) |
1331 | { | 1327 | { |
1332 | int i; | ||
1333 | struct sd *sd = (struct sd *) gspca_dev; | 1328 | struct sd *sd = (struct sd *) gspca_dev; |
1334 | 1329 | ||
1335 | i2c_w1(gspca_dev, 0x12, 0x80); /* sensor reset */ | 1330 | i2c_w1(gspca_dev, 0x12, 0x80); /* sensor reset */ |
1336 | msleep(200); | 1331 | msleep(200); |
1337 | for (i = 0; i < ARRAY_SIZE(ov7670_init); i++) { | 1332 | i2c_w1_buf(gspca_dev, ov7670_init, ARRAY_SIZE(ov7670_init)); |
1338 | i2c_w1(gspca_dev, ov7670_init[i].reg, | 1333 | if (gspca_dev->usb_err < 0) |
1339 | ov7670_init[i].val); | 1334 | pr_err("OV7670 sensor initialization failed\n"); |
1340 | if (gspca_dev->usb_err < 0) { | 1335 | |
1341 | pr_err("OV7670 sensor initialization failed\n"); | ||
1342 | return; | ||
1343 | } | ||
1344 | } | ||
1345 | /* disable hflip and vflip */ | 1336 | /* disable hflip and vflip */ |
1346 | gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP); | 1337 | gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP); |
1347 | sd->hstart = 0; | 1338 | sd->hstart = 0; |
@@ -1351,20 +1342,16 @@ static void ov7670_init_sensor(struct gspca_dev *gspca_dev) | |||
1351 | static void mt9v_init_sensor(struct gspca_dev *gspca_dev) | 1342 | static void mt9v_init_sensor(struct gspca_dev *gspca_dev) |
1352 | { | 1343 | { |
1353 | struct sd *sd = (struct sd *) gspca_dev; | 1344 | struct sd *sd = (struct sd *) gspca_dev; |
1354 | int i; | ||
1355 | u16 value; | 1345 | u16 value; |
1356 | 1346 | ||
1357 | sd->i2c_addr = 0x5d; | 1347 | sd->i2c_addr = 0x5d; |
1358 | i2c_r2(gspca_dev, 0xff, &value); | 1348 | i2c_r2(gspca_dev, 0xff, &value); |
1359 | if (gspca_dev->usb_err >= 0 | 1349 | if (gspca_dev->usb_err >= 0 |
1360 | && value == 0x8243) { | 1350 | && value == 0x8243) { |
1361 | for (i = 0; i < ARRAY_SIZE(mt9v011_init); i++) { | 1351 | i2c_w2_buf(gspca_dev, mt9v011_init, ARRAY_SIZE(mt9v011_init)); |
1362 | i2c_w2(gspca_dev, mt9v011_init[i].reg, | 1352 | if (gspca_dev->usb_err < 0) { |
1363 | mt9v011_init[i].val); | 1353 | pr_err("MT9V011 sensor initialization failed\n"); |
1364 | if (gspca_dev->usb_err < 0) { | 1354 | return; |
1365 | pr_err("MT9V011 sensor initialization failed\n"); | ||
1366 | return; | ||
1367 | } | ||
1368 | } | 1355 | } |
1369 | sd->hstart = 2; | 1356 | sd->hstart = 2; |
1370 | sd->vstart = 2; | 1357 | sd->vstart = 2; |
@@ -1379,13 +1366,10 @@ static void mt9v_init_sensor(struct gspca_dev *gspca_dev) | |||
1379 | i2c_r2(gspca_dev, 0xff, &value); | 1366 | i2c_r2(gspca_dev, 0xff, &value); |
1380 | if (gspca_dev->usb_err >= 0 | 1367 | if (gspca_dev->usb_err >= 0 |
1381 | && value == 0x823a) { | 1368 | && value == 0x823a) { |
1382 | for (i = 0; i < ARRAY_SIZE(mt9v111_init); i++) { | 1369 | i2c_w2_buf(gspca_dev, mt9v111_init, ARRAY_SIZE(mt9v111_init)); |
1383 | i2c_w2(gspca_dev, mt9v111_init[i].reg, | 1370 | if (gspca_dev->usb_err < 0) { |
1384 | mt9v111_init[i].val); | 1371 | pr_err("MT9V111 sensor initialization failed\n"); |
1385 | if (gspca_dev->usb_err < 0) { | 1372 | return; |
1386 | pr_err("MT9V111 sensor initialization failed\n"); | ||
1387 | return; | ||
1388 | } | ||
1389 | } | 1373 | } |
1390 | gspca_dev->ctrl_dis = (1 << EXPOSURE) | 1374 | gspca_dev->ctrl_dis = (1 << EXPOSURE) |
1391 | | (1 << AUTOGAIN) | 1375 | | (1 << AUTOGAIN) |
@@ -1408,13 +1392,10 @@ static void mt9v_init_sensor(struct gspca_dev *gspca_dev) | |||
1408 | i2c_r2(gspca_dev, 0x00, &value); | 1392 | i2c_r2(gspca_dev, 0x00, &value); |
1409 | if (gspca_dev->usb_err >= 0 | 1393 | if (gspca_dev->usb_err >= 0 |
1410 | && value == 0x1229) { | 1394 | && value == 0x1229) { |
1411 | for (i = 0; i < ARRAY_SIZE(mt9v112_init); i++) { | 1395 | i2c_w2_buf(gspca_dev, mt9v112_init, ARRAY_SIZE(mt9v112_init)); |
1412 | i2c_w2(gspca_dev, mt9v112_init[i].reg, | 1396 | if (gspca_dev->usb_err < 0) { |
1413 | mt9v112_init[i].val); | 1397 | pr_err("MT9V112 sensor initialization failed\n"); |
1414 | if (gspca_dev->usb_err < 0) { | 1398 | return; |
1415 | pr_err("MT9V112 sensor initialization failed\n"); | ||
1416 | return; | ||
1417 | } | ||
1418 | } | 1399 | } |
1419 | sd->hstart = 6; | 1400 | sd->hstart = 6; |
1420 | sd->vstart = 2; | 1401 | sd->vstart = 2; |
@@ -1429,15 +1410,11 @@ static void mt9v_init_sensor(struct gspca_dev *gspca_dev) | |||
1429 | static void mt9m112_init_sensor(struct gspca_dev *gspca_dev) | 1410 | static void mt9m112_init_sensor(struct gspca_dev *gspca_dev) |
1430 | { | 1411 | { |
1431 | struct sd *sd = (struct sd *) gspca_dev; | 1412 | struct sd *sd = (struct sd *) gspca_dev; |
1432 | int i; | 1413 | |
1433 | for (i = 0; i < ARRAY_SIZE(mt9m112_init); i++) { | 1414 | i2c_w2_buf(gspca_dev, mt9m112_init, ARRAY_SIZE(mt9m112_init)); |
1434 | i2c_w2(gspca_dev, mt9m112_init[i].reg, | 1415 | if (gspca_dev->usb_err < 0) |
1435 | mt9m112_init[i].val); | 1416 | pr_err("MT9M112 sensor initialization failed\n"); |
1436 | if (gspca_dev->usb_err < 0) { | 1417 | |
1437 | pr_err("MT9M112 sensor initialization failed\n"); | ||
1438 | return; | ||
1439 | } | ||
1440 | } | ||
1441 | gspca_dev->ctrl_dis = (1 << EXPOSURE) | (1 << AUTOGAIN) | 1418 | gspca_dev->ctrl_dis = (1 << EXPOSURE) | (1 << AUTOGAIN) |
1442 | | (1 << GAIN); | 1419 | | (1 << GAIN); |
1443 | sd->hstart = 0; | 1420 | sd->hstart = 0; |
@@ -1447,15 +1424,11 @@ static void mt9m112_init_sensor(struct gspca_dev *gspca_dev) | |||
1447 | static void mt9m111_init_sensor(struct gspca_dev *gspca_dev) | 1424 | static void mt9m111_init_sensor(struct gspca_dev *gspca_dev) |
1448 | { | 1425 | { |
1449 | struct sd *sd = (struct sd *) gspca_dev; | 1426 | struct sd *sd = (struct sd *) gspca_dev; |
1450 | int i; | 1427 | |
1451 | for (i = 0; i < ARRAY_SIZE(mt9m111_init); i++) { | 1428 | i2c_w2_buf(gspca_dev, mt9m111_init, ARRAY_SIZE(mt9m111_init)); |
1452 | i2c_w2(gspca_dev, mt9m111_init[i].reg, | 1429 | if (gspca_dev->usb_err < 0) |
1453 | mt9m111_init[i].val); | 1430 | pr_err("MT9M111 sensor initialization failed\n"); |
1454 | if (gspca_dev->usb_err < 0) { | 1431 | |
1455 | pr_err("MT9M111 sensor initialization failed\n"); | ||
1456 | return; | ||
1457 | } | ||
1458 | } | ||
1459 | gspca_dev->ctrl_dis = (1 << EXPOSURE) | (1 << AUTOGAIN) | 1432 | gspca_dev->ctrl_dis = (1 << EXPOSURE) | (1 << AUTOGAIN) |
1460 | | (1 << GAIN); | 1433 | | (1 << GAIN); |
1461 | sd->hstart = 0; | 1434 | sd->hstart = 0; |
@@ -1465,7 +1438,6 @@ static void mt9m111_init_sensor(struct gspca_dev *gspca_dev) | |||
1465 | static void mt9m001_init_sensor(struct gspca_dev *gspca_dev) | 1438 | static void mt9m001_init_sensor(struct gspca_dev *gspca_dev) |
1466 | { | 1439 | { |
1467 | struct sd *sd = (struct sd *) gspca_dev; | 1440 | struct sd *sd = (struct sd *) gspca_dev; |
1468 | int i; | ||
1469 | u16 id; | 1441 | u16 id; |
1470 | 1442 | ||
1471 | i2c_r2(gspca_dev, 0x00, &id); | 1443 | i2c_r2(gspca_dev, 0x00, &id); |
@@ -1487,14 +1459,10 @@ static void mt9m001_init_sensor(struct gspca_dev *gspca_dev) | |||
1487 | return; | 1459 | return; |
1488 | } | 1460 | } |
1489 | 1461 | ||
1490 | for (i = 0; i < ARRAY_SIZE(mt9m001_init); i++) { | 1462 | i2c_w2_buf(gspca_dev, mt9m001_init, ARRAY_SIZE(mt9m001_init)); |
1491 | i2c_w2(gspca_dev, mt9m001_init[i].reg, | 1463 | if (gspca_dev->usb_err < 0) |
1492 | mt9m001_init[i].val); | 1464 | pr_err("MT9M001 sensor initialization failed\n"); |
1493 | if (gspca_dev->usb_err < 0) { | 1465 | |
1494 | pr_err("MT9M001 sensor initialization failed\n"); | ||
1495 | return; | ||
1496 | } | ||
1497 | } | ||
1498 | /* disable hflip and vflip */ | 1466 | /* disable hflip and vflip */ |
1499 | gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP); | 1467 | gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP); |
1500 | sd->hstart = 1; | 1468 | sd->hstart = 1; |
@@ -1503,17 +1471,12 @@ static void mt9m001_init_sensor(struct gspca_dev *gspca_dev) | |||
1503 | 1471 | ||
1504 | static void hv7131r_init_sensor(struct gspca_dev *gspca_dev) | 1472 | static void hv7131r_init_sensor(struct gspca_dev *gspca_dev) |
1505 | { | 1473 | { |
1506 | int i; | ||
1507 | struct sd *sd = (struct sd *) gspca_dev; | 1474 | struct sd *sd = (struct sd *) gspca_dev; |
1508 | 1475 | ||
1509 | for (i = 0; i < ARRAY_SIZE(hv7131r_init); i++) { | 1476 | i2c_w1_buf(gspca_dev, hv7131r_init, ARRAY_SIZE(hv7131r_init)); |
1510 | i2c_w1(gspca_dev, hv7131r_init[i].reg, | 1477 | if (gspca_dev->usb_err < 0) |
1511 | hv7131r_init[i].val); | 1478 | pr_err("HV7131R Sensor initialization failed\n"); |
1512 | if (gspca_dev->usb_err < 0) { | 1479 | |
1513 | pr_err("HV7131R Sensor initialization failed\n"); | ||
1514 | return; | ||
1515 | } | ||
1516 | } | ||
1517 | sd->hstart = 0; | 1480 | sd->hstart = 0; |
1518 | sd->vstart = 1; | 1481 | sd->vstart = 1; |
1519 | } | 1482 | } |