diff options
author | Jean-Francois Moine <moinejf@free.fr> | 2009-11-02 07:10:25 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-12-05 15:41:16 -0500 |
commit | 23a98274cc348880ecb6803307c254448084953a (patch) | |
tree | d3cd1aa29efb4591de0229ef4c9ebd6a6c3f20ec | |
parent | 1408b8472910e894b290205b4baed5b14b8f45af (diff) |
V4L/DVB (13301): gspca - sonixj: Simplify the sensor init exchanges.
Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/gspca/sonixj.c | 174 |
1 files changed, 34 insertions, 140 deletions
diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c index 22209945698e..63371bbe3da9 100644 --- a/drivers/media/video/gspca/sonixj.c +++ b/drivers/media/video/gspca/sonixj.c | |||
@@ -464,6 +464,8 @@ static const u8 hv7131r_sensor_init[][8] = { | |||
464 | {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10}, | 464 | {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10}, |
465 | {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10}, | 465 | {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10}, |
466 | {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10}, | 466 | {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10}, |
467 | {0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10}, | ||
468 | /* set sensor clock */ | ||
467 | {} | 469 | {} |
468 | }; | 470 | }; |
469 | static const u8 mi0360_sensor_init[][8] = { | 471 | static const u8 mi0360_sensor_init[][8] = { |
@@ -545,7 +547,7 @@ static const u8 mo4000_sensor_init[][8] = { | |||
545 | }; | 547 | }; |
546 | static const u8 mt9v111_sensor_init[][8] = { | 548 | static const u8 mt9v111_sensor_init[][8] = { |
547 | {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */ | 549 | {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */ |
548 | /* delay 20 ms */ | 550 | {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */ |
549 | {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10}, | 551 | {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10}, |
550 | {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */ | 552 | {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */ |
551 | {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */ | 553 | {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */ |
@@ -622,10 +624,10 @@ static const u8 om6802_sensor_init[][8] = { | |||
622 | static const u8 ov7630_sensor_init[][8] = { | 624 | static const u8 ov7630_sensor_init[][8] = { |
623 | {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10}, | 625 | {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10}, |
624 | {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10}, | 626 | {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10}, |
625 | /* win: delay 20ms */ | 627 | {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */ |
626 | {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10}, | 628 | {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10}, |
627 | {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10}, | 629 | {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10}, |
628 | /* win: delay 20ms */ | 630 | {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */ |
629 | {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10}, | 631 | {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10}, |
630 | /* win: i2c_r from 00 to 80 */ | 632 | /* win: i2c_r from 00 to 80 */ |
631 | {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10}, | 633 | {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10}, |
@@ -677,6 +679,7 @@ static const u8 ov7630_sensor_init[][8] = { | |||
677 | static const u8 ov7648_sensor_init[][8] = { | 679 | static const u8 ov7648_sensor_init[][8] = { |
678 | {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10}, | 680 | {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10}, |
679 | {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */ | 681 | {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */ |
682 | {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */ | ||
680 | {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10}, | 683 | {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10}, |
681 | {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10}, | 684 | {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10}, |
682 | {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10}, | 685 | {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10}, |
@@ -723,7 +726,7 @@ static const u8 ov7648_sensor_init[][8] = { | |||
723 | 726 | ||
724 | static const u8 ov7660_sensor_init[][8] = { | 727 | static const u8 ov7660_sensor_init[][8] = { |
725 | {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */ | 728 | {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */ |
726 | /* (delay 20ms) */ | 729 | {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */ |
727 | {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10}, | 730 | {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10}, |
728 | /* Outformat = rawRGB */ | 731 | /* Outformat = rawRGB */ |
729 | {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */ | 732 | {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */ |
@@ -894,6 +897,18 @@ static const u8 sp80708_sensor_init[][8] = { | |||
894 | {} | 897 | {} |
895 | }; | 898 | }; |
896 | 899 | ||
900 | static const u8 (*sensor_init[9])[8] = { | ||
901 | hv7131r_sensor_init, /* HV7131R 0 */ | ||
902 | mi0360_sensor_init, /* MI0360 1 */ | ||
903 | mo4000_sensor_init, /* MO4000 2 */ | ||
904 | mt9v111_sensor_init, /* MT9V111 3 */ | ||
905 | om6802_sensor_init, /* OM6802 4 */ | ||
906 | ov7630_sensor_init, /* OV7630 5 */ | ||
907 | ov7648_sensor_init, /* OV7648 6 */ | ||
908 | ov7660_sensor_init, /* OV7660 7 */ | ||
909 | sp80708_sensor_init, /* SP80708 8 */ | ||
910 | }; | ||
911 | |||
897 | /* read <len> bytes to gspca_dev->usb_buf */ | 912 | /* read <len> bytes to gspca_dev->usb_buf */ |
898 | static void reg_r(struct gspca_dev *gspca_dev, | 913 | static void reg_r(struct gspca_dev *gspca_dev, |
899 | u16 value, int len) | 914 | u16 value, int len) |
@@ -1014,6 +1029,18 @@ static void i2c_r5(struct gspca_dev *gspca_dev, u8 reg) | |||
1014 | reg_r(gspca_dev, 0x0a, 5); | 1029 | reg_r(gspca_dev, 0x0a, 5); |
1015 | } | 1030 | } |
1016 | 1031 | ||
1032 | static void i2c_w_seq(struct gspca_dev *gspca_dev, | ||
1033 | const u8 (*data)[8]) | ||
1034 | { | ||
1035 | while ((*data)[0] != 0) { | ||
1036 | if ((*data)[0] != 0xdd) | ||
1037 | i2c_w8(gspca_dev, *data); | ||
1038 | else | ||
1039 | msleep((*data)[1]); | ||
1040 | data++; | ||
1041 | } | ||
1042 | } | ||
1043 | |||
1017 | static void hv7131r_probe(struct gspca_dev *gspca_dev) | 1044 | static void hv7131r_probe(struct gspca_dev *gspca_dev) |
1018 | { | 1045 | { |
1019 | i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */ | 1046 | i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */ |
@@ -1164,129 +1191,6 @@ static void configure_gpio(struct gspca_dev *gspca_dev, | |||
1164 | } | 1191 | } |
1165 | } | 1192 | } |
1166 | 1193 | ||
1167 | static void hv7131R_InitSensor(struct gspca_dev *gspca_dev) | ||
1168 | { | ||
1169 | int i = 0; | ||
1170 | static const u8 SetSensorClk[] = /* 0x08 Mclk */ | ||
1171 | { 0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10 }; | ||
1172 | |||
1173 | while (hv7131r_sensor_init[i][0]) { | ||
1174 | i2c_w8(gspca_dev, hv7131r_sensor_init[i]); | ||
1175 | i++; | ||
1176 | } | ||
1177 | i2c_w8(gspca_dev, SetSensorClk); | ||
1178 | } | ||
1179 | |||
1180 | static void mi0360_InitSensor(struct gspca_dev *gspca_dev) | ||
1181 | { | ||
1182 | int i = 0; | ||
1183 | |||
1184 | while (mi0360_sensor_init[i][0]) { | ||
1185 | i2c_w8(gspca_dev, mi0360_sensor_init[i]); | ||
1186 | i++; | ||
1187 | } | ||
1188 | } | ||
1189 | |||
1190 | static void mo4000_InitSensor(struct gspca_dev *gspca_dev) | ||
1191 | { | ||
1192 | int i = 0; | ||
1193 | |||
1194 | while (mo4000_sensor_init[i][0]) { | ||
1195 | i2c_w8(gspca_dev, mo4000_sensor_init[i]); | ||
1196 | i++; | ||
1197 | } | ||
1198 | } | ||
1199 | |||
1200 | static void mt9v111_InitSensor(struct gspca_dev *gspca_dev) | ||
1201 | { | ||
1202 | int i = 0; | ||
1203 | |||
1204 | i2c_w8(gspca_dev, mt9v111_sensor_init[i]); | ||
1205 | i++; | ||
1206 | msleep(20); | ||
1207 | while (mt9v111_sensor_init[i][0]) { | ||
1208 | i2c_w8(gspca_dev, mt9v111_sensor_init[i]); | ||
1209 | i++; | ||
1210 | } | ||
1211 | } | ||
1212 | |||
1213 | static void om6802_InitSensor(struct gspca_dev *gspca_dev) | ||
1214 | { | ||
1215 | int i = 0; | ||
1216 | |||
1217 | while (om6802_sensor_init[i][0]) { | ||
1218 | i2c_w8(gspca_dev, om6802_sensor_init[i]); | ||
1219 | i++; | ||
1220 | } | ||
1221 | } | ||
1222 | |||
1223 | static void ov7630_InitSensor(struct gspca_dev *gspca_dev) | ||
1224 | { | ||
1225 | int i = 0; | ||
1226 | |||
1227 | i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 76 01 */ | ||
1228 | i++; | ||
1229 | i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 c8 (RGB+SRST) */ | ||
1230 | i++; | ||
1231 | msleep(20); | ||
1232 | i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 48 */ | ||
1233 | i++; | ||
1234 | i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 c8 */ | ||
1235 | i++; | ||
1236 | msleep(20); | ||
1237 | i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 48 */ | ||
1238 | i++; | ||
1239 | /*jfm:win i2c_r from 00 to 80*/ | ||
1240 | |||
1241 | while (ov7630_sensor_init[i][0]) { | ||
1242 | i2c_w8(gspca_dev, ov7630_sensor_init[i]); | ||
1243 | i++; | ||
1244 | } | ||
1245 | } | ||
1246 | |||
1247 | static void ov7648_InitSensor(struct gspca_dev *gspca_dev) | ||
1248 | { | ||
1249 | int i = 0; | ||
1250 | |||
1251 | i2c_w8(gspca_dev, ov7648_sensor_init[i]); | ||
1252 | i++; | ||
1253 | /* win: dble reset */ | ||
1254 | i2c_w8(gspca_dev, ov7648_sensor_init[i]); /* reset */ | ||
1255 | i++; | ||
1256 | msleep(20); | ||
1257 | /* win: i2c reg read 00..7f */ | ||
1258 | while (ov7648_sensor_init[i][0]) { | ||
1259 | i2c_w8(gspca_dev, ov7648_sensor_init[i]); | ||
1260 | i++; | ||
1261 | } | ||
1262 | } | ||
1263 | |||
1264 | static void ov7660_InitSensor(struct gspca_dev *gspca_dev) | ||
1265 | { | ||
1266 | int i = 0; | ||
1267 | |||
1268 | i2c_w8(gspca_dev, ov7660_sensor_init[i]); /* reset SCCB */ | ||
1269 | i++; | ||
1270 | msleep(20); | ||
1271 | while (ov7660_sensor_init[i][0]) { | ||
1272 | i2c_w8(gspca_dev, ov7660_sensor_init[i]); | ||
1273 | i++; | ||
1274 | } | ||
1275 | } | ||
1276 | |||
1277 | static void sp80708_InitSensor(struct gspca_dev *gspca_dev) | ||
1278 | { | ||
1279 | int i = 0; | ||
1280 | |||
1281 | i2c_w8(gspca_dev, sp80708_sensor_init[i]); /* reset SCCB */ | ||
1282 | i++; | ||
1283 | msleep(20); | ||
1284 | while (sp80708_sensor_init[i][0]) { | ||
1285 | i2c_w8(gspca_dev, sp80708_sensor_init[i]); | ||
1286 | i++; | ||
1287 | } | ||
1288 | } | ||
1289 | |||
1290 | /* this function is called at probe time */ | 1194 | /* this function is called at probe time */ |
1291 | static int sd_config(struct gspca_dev *gspca_dev, | 1195 | static int sd_config(struct gspca_dev *gspca_dev, |
1292 | const struct usb_device_id *id) | 1196 | const struct usb_device_id *id) |
@@ -1801,6 +1705,9 @@ static int sd_start(struct gspca_dev *gspca_dev) | |||
1801 | break; | 1705 | break; |
1802 | } | 1706 | } |
1803 | 1707 | ||
1708 | /* initialize the sensor */ | ||
1709 | i2c_w_seq(gspca_dev, sensor_init[sd->sensor]); | ||
1710 | |||
1804 | mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; | 1711 | mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; |
1805 | if (mode) | 1712 | if (mode) |
1806 | reg1 = 0x46; /* 320x240: clk 48Mhz, video trf enable */ | 1713 | reg1 = 0x46; /* 320x240: clk 48Mhz, video trf enable */ |
@@ -1808,14 +1715,7 @@ static int sd_start(struct gspca_dev *gspca_dev) | |||
1808 | reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */ | 1715 | reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */ |
1809 | reg17 = 0x61; /* 0x:20: enable sensor clock */ | 1716 | reg17 = 0x61; /* 0x:20: enable sensor clock */ |
1810 | switch (sd->sensor) { | 1717 | switch (sd->sensor) { |
1811 | case SENSOR_HV7131R: | ||
1812 | hv7131R_InitSensor(gspca_dev); | ||
1813 | break; | ||
1814 | case SENSOR_MI0360: | ||
1815 | mi0360_InitSensor(gspca_dev); | ||
1816 | break; | ||
1817 | case SENSOR_MO4000: | 1718 | case SENSOR_MO4000: |
1818 | mo4000_InitSensor(gspca_dev); | ||
1819 | if (mode) { | 1719 | if (mode) { |
1820 | /* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */ | 1720 | /* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */ |
1821 | reg1 = 0x06; /* clk 24Mz */ | 1721 | reg1 = 0x06; /* clk 24Mz */ |
@@ -1825,7 +1725,6 @@ static int sd_start(struct gspca_dev *gspca_dev) | |||
1825 | } | 1725 | } |
1826 | break; | 1726 | break; |
1827 | case SENSOR_MT9V111: | 1727 | case SENSOR_MT9V111: |
1828 | mt9v111_InitSensor(gspca_dev); | ||
1829 | if (mode) { | 1728 | if (mode) { |
1830 | reg1 = 0x04; /* 320 clk 48Mhz */ | 1729 | reg1 = 0x04; /* 320 clk 48Mhz */ |
1831 | } else { | 1730 | } else { |
@@ -1834,22 +1733,18 @@ static int sd_start(struct gspca_dev *gspca_dev) | |||
1834 | } | 1733 | } |
1835 | break; | 1734 | break; |
1836 | case SENSOR_OM6802: | 1735 | case SENSOR_OM6802: |
1837 | om6802_InitSensor(gspca_dev); | ||
1838 | reg17 = 0x64; /* 640 MCKSIZE */ | 1736 | reg17 = 0x64; /* 640 MCKSIZE */ |
1839 | break; | 1737 | break; |
1840 | case SENSOR_OV7630: | 1738 | case SENSOR_OV7630: |
1841 | ov7630_InitSensor(gspca_dev); | ||
1842 | setvflip(sd); | 1739 | setvflip(sd); |
1843 | reg17 = 0xe2; | 1740 | reg17 = 0xe2; |
1844 | reg1 = 0x44; | 1741 | reg1 = 0x44; |
1845 | break; | 1742 | break; |
1846 | case SENSOR_OV7648: | 1743 | case SENSOR_OV7648: |
1847 | ov7648_InitSensor(gspca_dev); | ||
1848 | reg17 = 0x21; | 1744 | reg17 = 0x21; |
1849 | /* reg1 = 0x42; * 42 - 46? */ | 1745 | /* reg1 = 0x42; * 42 - 46? */ |
1850 | break; | 1746 | break; |
1851 | case SENSOR_OV7660: | 1747 | case SENSOR_OV7660: |
1852 | ov7660_InitSensor(gspca_dev); | ||
1853 | if (sd->bridge == BRIDGE_SN9C120) { | 1748 | if (sd->bridge == BRIDGE_SN9C120) { |
1854 | if (mode) { /* 320x240 - 160x120 */ | 1749 | if (mode) { /* 320x240 - 160x120 */ |
1855 | reg17 = 0xa2; | 1750 | reg17 = 0xa2; |
@@ -1863,7 +1758,6 @@ static int sd_start(struct gspca_dev *gspca_dev) | |||
1863 | break; | 1758 | break; |
1864 | default: | 1759 | default: |
1865 | /* case SENSOR_SP80708: */ | 1760 | /* case SENSOR_SP80708: */ |
1866 | sp80708_InitSensor(gspca_dev); | ||
1867 | if (mode) { | 1761 | if (mode) { |
1868 | /*?? reg1 = 0x04; * 320 clk 48Mhz */ | 1762 | /*?? reg1 = 0x04; * 320 clk 48Mhz */ |
1869 | } else { | 1763 | } else { |