sonixj.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. /*
  2. * Sonix sn9c102p sn9c105 sn9c120 (jpeg) library
  3. * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
  4. *
  5. * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #define MODULE_NAME "sonixj"
  22. #include "gspca.h"
  23. #include "jpeg.h"
  24. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  25. MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
  26. MODULE_LICENSE("GPL");
  27. /* specific webcam descriptor */
  28. struct sd {
  29. struct gspca_dev gspca_dev; /* !! must be the first item */
  30. int avg_lum;
  31. unsigned int exposure;
  32. unsigned short brightness;
  33. unsigned char contrast;
  34. unsigned char colors;
  35. unsigned char autogain;
  36. signed char ag_cnt;
  37. #define AG_CNT_START 13
  38. char qindex;
  39. unsigned char bridge;
  40. #define BRIDGE_SN9C102P 0
  41. #define BRIDGE_SN9C105 1
  42. #define BRIDGE_SN9C110 2
  43. #define BRIDGE_SN9C120 3
  44. #define BRIDGE_SN9C325 4
  45. char sensor; /* Type of image sensor chip */
  46. #define SENSOR_HV7131R 0
  47. #define SENSOR_MI0360 1
  48. #define SENSOR_MO4000 2
  49. #define SENSOR_OV7648 3
  50. #define SENSOR_OV7660 4
  51. unsigned char i2c_base;
  52. };
  53. /* V4L2 controls supported by the driver */
  54. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  55. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  56. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  57. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  58. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  59. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  60. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
  61. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
  62. static struct ctrl sd_ctrls[] = {
  63. {
  64. {
  65. .id = V4L2_CID_BRIGHTNESS,
  66. .type = V4L2_CTRL_TYPE_INTEGER,
  67. .name = "Brightness",
  68. .minimum = 0,
  69. .maximum = 0xffff,
  70. .step = 1,
  71. #define BRIGHTNESS_DEF 0x7fff
  72. .default_value = BRIGHTNESS_DEF,
  73. },
  74. .set = sd_setbrightness,
  75. .get = sd_getbrightness,
  76. },
  77. {
  78. {
  79. .id = V4L2_CID_CONTRAST,
  80. .type = V4L2_CTRL_TYPE_INTEGER,
  81. .name = "Contrast",
  82. .minimum = 0,
  83. .maximum = 127,
  84. .step = 1,
  85. #define CONTRAST_DEF 63
  86. .default_value = CONTRAST_DEF,
  87. },
  88. .set = sd_setcontrast,
  89. .get = sd_getcontrast,
  90. },
  91. {
  92. {
  93. .id = V4L2_CID_SATURATION,
  94. .type = V4L2_CTRL_TYPE_INTEGER,
  95. .name = "Color",
  96. .minimum = 0,
  97. .maximum = 255,
  98. .step = 1,
  99. #define COLOR_DEF 127
  100. .default_value = COLOR_DEF,
  101. },
  102. .set = sd_setcolors,
  103. .get = sd_getcolors,
  104. },
  105. {
  106. {
  107. .id = V4L2_CID_AUTOGAIN,
  108. .type = V4L2_CTRL_TYPE_BOOLEAN,
  109. .name = "Auto Gain",
  110. .minimum = 0,
  111. .maximum = 1,
  112. .step = 1,
  113. #define AUTOGAIN_DEF 1
  114. .default_value = AUTOGAIN_DEF,
  115. },
  116. .set = sd_setautogain,
  117. .get = sd_getautogain,
  118. },
  119. };
  120. static struct v4l2_pix_format vga_mode[] = {
  121. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  122. .bytesperline = 160,
  123. .sizeimage = 160 * 120 * 3 / 8 + 590,
  124. .colorspace = V4L2_COLORSPACE_JPEG,
  125. .priv = 2},
  126. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  127. .bytesperline = 320,
  128. .sizeimage = 320 * 240 * 3 / 8 + 590,
  129. .colorspace = V4L2_COLORSPACE_JPEG,
  130. .priv = 1},
  131. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  132. .bytesperline = 640,
  133. .sizeimage = 640 * 480 * 3 / 8 + 590,
  134. .colorspace = V4L2_COLORSPACE_JPEG,
  135. .priv = 0},
  136. };
  137. /*Data from sn9c102p+hv71331r */
  138. static const __u8 sn_hv7131[] = {
  139. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  140. 0x00, 0x03, 0x64, 0x00, 0x1a, 0x20, 0x20, 0x20,
  141. /* reg8 reg9 rega regb regc regd rege regf */
  142. 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10,
  143. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  144. 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
  145. /* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */
  146. 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  147. };
  148. static const __u8 sn_mi0360[] = {
  149. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  150. 0x00, 0x61, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20,
  151. /* reg8 reg9 rega regb regc regd rege regf */
  152. 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10,
  153. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  154. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
  155. /* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */
  156. 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  157. };
  158. static const __u8 sn_mo4000[] = {
  159. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  160. 0x12, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
  161. /* reg8 reg9 rega regb regc regd rege regf */
  162. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  163. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  164. 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
  165. /* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */
  166. 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  167. };
  168. static const __u8 sn_ov7648[] = {
  169. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  170. 0x00, 0x21, 0x62, 0x00, 0x1a, 0x20, 0x20, 0x20,
  171. /* reg8 reg9 rega regb regc regd rege regf */
  172. 0xa1, 0x6e, 0x18, 0x65, 0x00, 0x00, 0x00, 0x10,
  173. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  174. 0x03, 0x00, 0x00, 0x06, 0x06, 0x28, 0x1e, 0x82,
  175. /* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */
  176. 0x07, 0x00, 0x00, 0x00, 0x00, 0x00
  177. };
  178. static const __u8 sn_ov7660[] = {
  179. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  180. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  181. /* reg8 reg9 rega regb regc regd rege regf */
  182. 0x81, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10,
  183. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  184. 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
  185. /* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */
  186. 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  187. };
  188. /* sequence specific to the sensors - !! index = SENSOR_xxx */
  189. static const __u8 *sn_tb[] = {
  190. sn_hv7131,
  191. sn_mi0360,
  192. sn_mo4000,
  193. sn_ov7648,
  194. sn_ov7660
  195. };
  196. static const __u8 regsn20[] = {
  197. 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
  198. 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
  199. };
  200. static const __u8 regsn20_sn9c325[] = {
  201. 0x0a, 0x3a, 0x56, 0x6c, 0x7e, 0x8d, 0x9a, 0xa4,
  202. 0xaf, 0xbb, 0xc5, 0xcd, 0xd5, 0xde, 0xe8, 0xed, 0xf5
  203. };
  204. static const __u8 reg84[] = {
  205. 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, 0xe5, 0x0f,
  206. 0xe4, 0x0f, 0x38, 0x00, 0x3e, 0x00, 0xc3, 0x0f,
  207. /* 0x00, 0x00, 0x00, 0x00, 0x00 */
  208. 0xf7, 0x0f, 0x0a, 0x00, 0x00
  209. };
  210. static const __u8 reg84_sn9c325[] = {
  211. 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, 0xe4, 0x0f,
  212. 0xd3, 0x0f, 0x4b, 0x00, 0x48, 0x00, 0xc0, 0x0f,
  213. 0xf8, 0x0f, 0x00, 0x00, 0x00
  214. };
  215. static const __u8 hv7131r_sensor_init[][8] = {
  216. {0xC1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
  217. {0xB1, 0x11, 0x34, 0x17, 0x7F, 0x00, 0x00, 0x10},
  218. {0xD1, 0x11, 0x40, 0xFF, 0x7F, 0x7F, 0x7F, 0x10},
  219. {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10},
  220. {0xD1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  221. {0xD1, 0x11, 0x14, 0x01, 0xE2, 0x02, 0x82, 0x10},
  222. {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  223. {0xA1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  224. {0xA1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  225. {0xC1, 0x11, 0x25, 0x00, 0x61, 0xA8, 0x00, 0x10},
  226. {0xA1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
  227. {0xC1, 0x11, 0x31, 0x20, 0x2E, 0x20, 0x00, 0x10},
  228. {0xC1, 0x11, 0x25, 0x00, 0xC3, 0x50, 0x00, 0x10},
  229. {0xA1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
  230. {0xC1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
  231. {0xA1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  232. {0xA1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  233. {0xA1, 0x11, 0x21, 0xD0, 0x00, 0x00, 0x00, 0x10},
  234. {0xA1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  235. {0xA1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
  236. {0xA1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  237. {0xA1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  238. {0xA1, 0x11, 0x21, 0xD0, 0x00, 0x00, 0x00, 0x10},
  239. {0xA1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  240. {0xA1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
  241. {}
  242. };
  243. static const __u8 mi0360_sensor_init[][8] = {
  244. {0xB1, 0x5D, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  245. {0xB1, 0x5D, 0x0D, 0x00, 0x01, 0x00, 0x00, 0x10},
  246. {0xB1, 0x5D, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x10},
  247. {0xD1, 0x5D, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  248. {0xD1, 0x5D, 0x03, 0x01, 0xE2, 0x02, 0x82, 0x10},
  249. {0xD1, 0x5D, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
  250. {0xB1, 0x5D, 0x0D, 0x00, 0x02, 0x00, 0x00, 0x10},
  251. {0xD1, 0x5D, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x10},
  252. {0xD1, 0x5D, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x10},
  253. {0xD1, 0x5D, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x10},
  254. {0xD1, 0x5D, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  255. {0xD1, 0x5D, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  256. {0xD1, 0x5D, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  257. {0xD1, 0x5D, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  258. {0xD1, 0x5D, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  259. {0xD1, 0x5D, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x10},
  260. {0xD1, 0x5D, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x10},
  261. {0xB1, 0x5D, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  262. {0xD1, 0x5D, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  263. {0xD1, 0x5D, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  264. {0xD1, 0x5D, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  265. {0xD1, 0x5D, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  266. {0xD1, 0x5D, 0x2F, 0xF7, 0xB0, 0x00, 0x04, 0x10},
  267. {0xD1, 0x5D, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  268. {0xD1, 0x5D, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  269. {0xB1, 0x5D, 0x3D, 0x06, 0x8F, 0x00, 0x00, 0x10},
  270. {0xD1, 0x5D, 0x40, 0x01, 0xE0, 0x00, 0xD1, 0x10},
  271. {0xB1, 0x5D, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  272. {0xD1, 0x5D, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  273. {0xD1, 0x5D, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x10},
  274. {0xD1, 0x5D, 0x5C, 0x00, 0x00, 0x00, 0x00, 0x10},
  275. {0xD1, 0x5D, 0x5E, 0x00, 0x00, 0xA3, 0x1D, 0x10},
  276. {0xB1, 0x5D, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  277. {0xB1, 0x5D, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  278. {0xB1, 0x5D, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  279. {0xB1, 0x5D, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  280. {0xD1, 0x5D, 0x2B, 0x00, 0xA0, 0x00, 0xB0, 0x10},
  281. {0xD1, 0x5D, 0x2D, 0x00, 0xA0, 0x00, 0xA0, 0x10},
  282. {0xB1, 0x5D, 0x0A, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
  283. {0xB1, 0x5D, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
  284. {0xB1, 0x5D, 0x05, 0x00, 0x0A, 0x00, 0x00, 0x10},
  285. {0xB1, 0x5D, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  286. {0xD1, 0x5D, 0x2B, 0x00, 0xB9, 0x00, 0xE3, 0x10},
  287. {0xD1, 0x5D, 0x2D, 0x00, 0x5f, 0x00, 0xB9, 0x10}, /* 42 */
  288. /* {0xB1, 0x5D, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
  289. /* {0xB1, 0x5D, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
  290. {0xB1, 0x5D, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  291. {0xB1, 0x5D, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  292. {}
  293. };
  294. static const __u8 mo4000_sensor_init[][8] = {
  295. {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
  296. {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
  297. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  298. {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  299. {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  300. {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
  301. {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
  302. {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
  303. {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  304. {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
  305. {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
  306. {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
  307. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  308. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  309. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  310. {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  311. {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
  312. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
  313. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  314. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  315. {}
  316. };
  317. static const __u8 ov7660_sensor_init[][8] = {
  318. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
  319. /* (delay 20ms) */
  320. {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
  321. /* Outformat = rawRGB */
  322. {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
  323. {0xd1, 0x21, 0x00, 0x01, 0x74, 0x74, 0x00, 0x10},
  324. /* GAIN BLUE RED VREF */
  325. {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
  326. /* COM 1 BAVE GEAVE AECHH */
  327. {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
  328. {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
  329. {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
  330. /* AECH CLKRC COM7 COM8 */
  331. {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
  332. {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
  333. /* HSTART HSTOP VSTRT VSTOP */
  334. {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
  335. {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
  336. {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
  337. /* BOS GBOS GROS ROS (BGGR offset) */
  338. /* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
  339. {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
  340. /* AEW AEB VPT BBIAS */
  341. {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
  342. /* GbBIAS RSVD EXHCH EXHCL */
  343. {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
  344. /* RBIAS ADVFL ASDVFH YAVE */
  345. {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
  346. /* HSYST HSYEN HREF */
  347. {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
  348. {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
  349. /* ADC ACOM OFON TSLB */
  350. {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
  351. /* COM11 COM12 COM13 COM14 */
  352. {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
  353. /* EDGE COM15 COM16 COM17 */
  354. {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
  355. {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
  356. {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  357. {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
  358. {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
  359. {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
  360. {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
  361. {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
  362. {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  363. {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
  364. /* LCC1 LCC2 LCC3 LCC4 */
  365. {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
  366. {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
  367. {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
  368. /* band gap reference [0:3] DBLV */
  369. {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
  370. {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
  371. {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
  372. {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
  373. {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
  374. {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
  375. {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
  376. {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
  377. {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
  378. {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
  379. /****** (some exchanges in the win trace) ******/
  380. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
  381. /* bits[3..0]reserved */
  382. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
  383. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  384. /* VREF vertical frame ctrl */
  385. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  386. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
  387. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
  388. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
  389. {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
  390. /* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
  391. /****** (some exchanges in the win trace) ******/
  392. {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
  393. {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
  394. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
  395. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
  396. /* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
  397. /****** (some exchanges in the win trace) ******/
  398. /******!! startsensor KO if changed !!****/
  399. {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
  400. {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
  401. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
  402. {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
  403. {}
  404. };
  405. /* reg 0x04 reg 0x07 reg 0x10 */
  406. /* expo = (COM1 & 0x02) | ((AECHH & 0x2f) << 10) | (AECh << 2) */
  407. static const __u8 ov7648_sensor_init[][8] = {
  408. {0xC1, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00},
  409. {0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00},
  410. {0xC1, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00},
  411. {0xA1, 0x6E, 0x3F, 0x20, 0x00, 0x00, 0x00, 0x10},
  412. {0xA1, 0x6E, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x10},
  413. {0xA1, 0x6E, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x10},
  414. {0xD1, 0x6E, 0x04, 0x02, 0xB1, 0x02, 0x39, 0x10},
  415. {0xD1, 0x6E, 0x08, 0x00, 0x01, 0x00, 0x00, 0x10},
  416. {0xD1, 0x6E, 0x0C, 0x02, 0x7F, 0x01, 0xE0, 0x10},
  417. {0xD1, 0x6E, 0x12, 0x03, 0x02, 0x00, 0x03, 0x10},
  418. {0xD1, 0x6E, 0x16, 0x85, 0x40, 0x4A, 0x40, 0x10},
  419. {0xC1, 0x6E, 0x1A, 0x00, 0x80, 0x00, 0x00, 0x10},
  420. {0xD1, 0x6E, 0x1D, 0x08, 0x03, 0x00, 0x00, 0x10},
  421. {0xD1, 0x6E, 0x23, 0x00, 0xB0, 0x00, 0x94, 0x10},
  422. {0xD1, 0x6E, 0x27, 0x58, 0x00, 0x00, 0x00, 0x10},
  423. {0xD1, 0x6E, 0x2D, 0x14, 0x35, 0x61, 0x84, 0x10},
  424. {0xD1, 0x6E, 0x31, 0xA2, 0xBD, 0xD8, 0xFF, 0x10},
  425. {0xD1, 0x6E, 0x35, 0x06, 0x1E, 0x12, 0x02, 0x10},
  426. {0xD1, 0x6E, 0x39, 0xAA, 0x53, 0x37, 0xD5, 0x10},
  427. {0xA1, 0x6E, 0x3D, 0xF2, 0x00, 0x00, 0x00, 0x10},
  428. {0xD1, 0x6E, 0x3E, 0x00, 0x00, 0x80, 0x03, 0x10},
  429. {0xD1, 0x6E, 0x42, 0x03, 0x00, 0x00, 0x00, 0x10},
  430. {0xC1, 0x6E, 0x46, 0x00, 0x80, 0x80, 0x00, 0x10},
  431. {0xD1, 0x6E, 0x4B, 0x02, 0xEF, 0x08, 0xCD, 0x10},
  432. {0xD1, 0x6E, 0x4F, 0x00, 0xD0, 0x00, 0xA0, 0x10},
  433. {0xD1, 0x6E, 0x53, 0x01, 0xAA, 0x01, 0x40, 0x10},
  434. {0xD1, 0x6E, 0x5A, 0x50, 0x04, 0x30, 0x03, 0x10},
  435. {0xA1, 0x6E, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x10},
  436. {0xD1, 0x6E, 0x5F, 0x10, 0x40, 0xFF, 0x00, 0x10},
  437. /* {0xD1, 0x6E, 0x63, 0x40, 0x40, 0x00, 0x00, 0x10},
  438. {0xD1, 0x6E, 0x67, 0x00, 0x00, 0x00, 0x00, 0x10},
  439. * This is currently setting a
  440. * blue tint, and some things more , i leave it here for future test if
  441. * somene is having problems with color on this sensor
  442. {0xD1, 0x6E, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x10},
  443. {0xD1, 0x6E, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x10},
  444. {0xC1, 0x6E, 0x73, 0x10, 0x80, 0xEB, 0x00, 0x10},
  445. {0xA1, 0x6E, 0x1E, 0x03, 0x00, 0x00, 0x00, 0x10},
  446. {0xA1, 0x6E, 0x15, 0x01, 0x00, 0x00, 0x00, 0x10},
  447. {0xC1, 0x6E, 0x16, 0x40, 0x40, 0x40, 0x00, 0x10},
  448. {0xA1, 0x6E, 0x1D, 0x08, 0x00, 0x00, 0x00, 0x10},
  449. {0xA1, 0x6E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  450. {0xA1, 0x6E, 0x07, 0xB5, 0x00, 0x00, 0x00, 0x10},
  451. {0xA1, 0x6E, 0x18, 0x6B, 0x00, 0x00, 0x00, 0x10},
  452. {0xA1, 0x6E, 0x1D, 0x08, 0x00, 0x00, 0x00, 0x10},
  453. {0xA1, 0x6E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  454. {0xA1, 0x6E, 0x07, 0xB8, 0x00, 0x00, 0x00, 0x10}, */
  455. {0xC1, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00},
  456. {0xA1, 0x6E, 0x06, 0x03, 0x00, 0x00, 0x00, 0x10}, /* Bright... */
  457. {0xA1, 0x6E, 0x07, 0x66, 0x00, 0x00, 0x00, 0x10}, /* B.. */
  458. {0xC1, 0x6E, 0x1A, 0x03, 0x65, 0x90, 0x00, 0x10}, /* Bright/Witen....*/
  459. /* {0xC1, 0x6E, 0x16, 0x45, 0x40, 0x60, 0x00, 0x10}, * Bright/Witene */
  460. {}
  461. };
  462. static const __u8 qtable4[] = {
  463. 0x06, 0x04, 0x04, 0x06, 0x04, 0x04, 0x06, 0x06, 0x06, 0x06, 0x08, 0x06,
  464. 0x06, 0x08, 0x0A, 0x11,
  465. 0x0A, 0x0A, 0x08, 0x08, 0x0A, 0x15, 0x0F, 0x0F, 0x0C, 0x11, 0x19, 0x15,
  466. 0x19, 0x19, 0x17, 0x15,
  467. 0x17, 0x17, 0x1B, 0x1D, 0x25, 0x21, 0x1B, 0x1D, 0x23, 0x1D, 0x17, 0x17,
  468. 0x21, 0x2E, 0x21, 0x23,
  469. 0x27, 0x29, 0x2C, 0x2C, 0x2C, 0x19, 0x1F, 0x30, 0x32, 0x2E, 0x29, 0x32,
  470. 0x25, 0x29, 0x2C, 0x29,
  471. 0x06, 0x08, 0x08, 0x0A, 0x08, 0x0A, 0x13, 0x0A, 0x0A, 0x13, 0x29, 0x1B,
  472. 0x17, 0x1B, 0x29, 0x29,
  473. 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29,
  474. 0x29, 0x29, 0x29, 0x29,
  475. 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29,
  476. 0x29, 0x29, 0x29, 0x29,
  477. 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29,
  478. 0x29, 0x29, 0x29, 0x29
  479. };
  480. /* read <len> bytes (len < sizeof gspca_dev->usb_buf) to gspca_dev->usb_buf */
  481. static void reg_r(struct gspca_dev *gspca_dev,
  482. __u16 value, int len)
  483. {
  484. usb_control_msg(gspca_dev->dev,
  485. usb_rcvctrlpipe(gspca_dev->dev, 0),
  486. 0,
  487. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  488. value, 0,
  489. gspca_dev->usb_buf, len,
  490. 500);
  491. PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
  492. }
  493. static void reg_w1(struct gspca_dev *gspca_dev,
  494. __u16 value,
  495. __u8 data)
  496. {
  497. PDEBUG(D_USBO, "reg_w1 [%02x] = %02x", value, data);
  498. gspca_dev->usb_buf[0] = data;
  499. usb_control_msg(gspca_dev->dev,
  500. usb_sndctrlpipe(gspca_dev->dev, 0),
  501. 0x08,
  502. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  503. value,
  504. 0,
  505. gspca_dev->usb_buf, 1,
  506. 500);
  507. }
  508. static void reg_w(struct gspca_dev *gspca_dev,
  509. __u16 value,
  510. const __u8 *buffer,
  511. int len)
  512. {
  513. PDEBUG(D_USBO, "reg_w [%02x] = %02x %02x ..",
  514. value, buffer[0], buffer[1]);
  515. if (len <= sizeof gspca_dev->usb_buf) {
  516. memcpy(gspca_dev->usb_buf, buffer, len);
  517. usb_control_msg(gspca_dev->dev,
  518. usb_sndctrlpipe(gspca_dev->dev, 0),
  519. 0x08,
  520. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  521. value, 0,
  522. gspca_dev->usb_buf, len,
  523. 500);
  524. } else {
  525. __u8 *tmpbuf;
  526. tmpbuf = kmalloc(len, GFP_KERNEL);
  527. memcpy(tmpbuf, buffer, len);
  528. usb_control_msg(gspca_dev->dev,
  529. usb_sndctrlpipe(gspca_dev->dev, 0),
  530. 0x08,
  531. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  532. value, 0,
  533. tmpbuf, len,
  534. 500);
  535. kfree(tmpbuf);
  536. }
  537. }
  538. /* I2C write 1 byte */
  539. static void i2c_w1(struct gspca_dev *gspca_dev, __u8 reg, __u8 val)
  540. {
  541. struct sd *sd = (struct sd *) gspca_dev;
  542. PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
  543. gspca_dev->usb_buf[0] = 0x81 | (2 << 4); /* = a1 */
  544. gspca_dev->usb_buf[1] = sd->i2c_base;
  545. gspca_dev->usb_buf[2] = reg;
  546. gspca_dev->usb_buf[3] = val;
  547. gspca_dev->usb_buf[4] = 0;
  548. gspca_dev->usb_buf[5] = 0;
  549. gspca_dev->usb_buf[6] = 0;
  550. gspca_dev->usb_buf[7] = 0x10;
  551. usb_control_msg(gspca_dev->dev,
  552. usb_sndctrlpipe(gspca_dev->dev, 0),
  553. 0x08,
  554. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  555. 0x08, /* value = i2c */
  556. 0,
  557. gspca_dev->usb_buf, 8,
  558. 500);
  559. }
  560. /* I2C write 8 bytes */
  561. static void i2c_w8(struct gspca_dev *gspca_dev,
  562. const __u8 *buffer)
  563. {
  564. memcpy(gspca_dev->usb_buf, buffer, 8);
  565. usb_control_msg(gspca_dev->dev,
  566. usb_sndctrlpipe(gspca_dev->dev, 0),
  567. 0x08,
  568. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  569. 0x08, 0, /* value, index */
  570. gspca_dev->usb_buf, 8,
  571. 500);
  572. }
  573. /* read 5 bytes in gspca_dev->usb_buf */
  574. static void i2c_r5(struct gspca_dev *gspca_dev, __u8 reg)
  575. {
  576. struct sd *sd = (struct sd *) gspca_dev;
  577. __u8 mode[8];
  578. mode[0] = 0x81 | 0x10;
  579. mode[1] = sd->i2c_base;
  580. mode[2] = reg;
  581. mode[3] = 0;
  582. mode[4] = 0;
  583. mode[5] = 0;
  584. mode[6] = 0;
  585. mode[7] = 0x10;
  586. i2c_w8(gspca_dev, mode);
  587. msleep(2);
  588. mode[0] = 0x81 | (5 << 4) | 0x02;
  589. mode[2] = 0;
  590. i2c_w8(gspca_dev, mode);
  591. msleep(2);
  592. reg_r(gspca_dev, 0x0a, 5);
  593. }
  594. static int probesensor(struct gspca_dev *gspca_dev)
  595. {
  596. struct sd *sd = (struct sd *) gspca_dev;
  597. i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
  598. msleep(10);
  599. reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
  600. msleep(10);
  601. i2c_r5(gspca_dev, 0); /* read sensor id */
  602. if (gspca_dev->usb_buf[0] == 0x02
  603. && gspca_dev->usb_buf[1] == 0x09
  604. && gspca_dev->usb_buf[2] == 0x01
  605. && gspca_dev->usb_buf[3] == 0x00
  606. && gspca_dev->usb_buf[4] == 0x00) {
  607. PDEBUG(D_PROBE, "Find Sensor sn9c102P HV7131R");
  608. sd->sensor = SENSOR_HV7131R;
  609. return SENSOR_HV7131R;
  610. }
  611. PDEBUG(D_PROBE, "Find Sensor 0x%02x 0x%02x 0x%02x",
  612. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
  613. gspca_dev->usb_buf[2]);
  614. PDEBUG(D_PROBE, "Sensor sn9c102P Not found");
  615. return -ENODEV;
  616. }
  617. static int configure_gpio(struct gspca_dev *gspca_dev,
  618. const __u8 *sn9c1xx)
  619. {
  620. struct sd *sd = (struct sd *) gspca_dev;
  621. const __u8 *reg9a;
  622. static const __u8 reg9a_def[] =
  623. {0x08, 0x40, 0x20, 0x10, 0x00, 0x04};
  624. static const __u8 reg9a_sn9c325[] =
  625. {0x0a, 0x40, 0x38, 0x30, 0x00, 0x20};
  626. static const __u8 regd4[] = {0x60, 0x00, 0x00};
  627. reg_w1(gspca_dev, 0xf1, 0x00);
  628. reg_w1(gspca_dev, 0x01, 0x00); /*jfm was sn9c1xx[1] in v1*/
  629. /* configure gpio */
  630. reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2);
  631. reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
  632. reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5); /* jfm len was 3 */
  633. switch (sd->bridge) {
  634. case BRIDGE_SN9C325:
  635. reg9a = reg9a_sn9c325;
  636. break;
  637. default:
  638. reg9a = reg9a_def;
  639. break;
  640. }
  641. reg_w(gspca_dev, 0x9a, reg9a, 6);
  642. reg_w(gspca_dev, 0xd4, regd4, sizeof regd4); /*fixme:jfm was 60 only*/
  643. reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
  644. switch (sd->bridge) {
  645. case BRIDGE_SN9C325:
  646. reg_w1(gspca_dev, 0x01, 0x43);
  647. reg_w1(gspca_dev, 0x17, 0xae);
  648. reg_w1(gspca_dev, 0x01, 0x42);
  649. break;
  650. default:
  651. reg_w1(gspca_dev, 0x01, 0x43);
  652. reg_w1(gspca_dev, 0x17, 0x61);
  653. reg_w1(gspca_dev, 0x01, 0x42);
  654. }
  655. if (sd->sensor == SENSOR_HV7131R) {
  656. if (probesensor(gspca_dev) < 0)
  657. return -ENODEV;
  658. }
  659. return 0;
  660. }
  661. static void hv7131R_InitSensor(struct gspca_dev *gspca_dev)
  662. {
  663. int i = 0;
  664. static const __u8 SetSensorClk[] = /* 0x08 Mclk */
  665. { 0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10 };
  666. while (hv7131r_sensor_init[i][0]) {
  667. i2c_w8(gspca_dev, hv7131r_sensor_init[i]);
  668. i++;
  669. }
  670. i2c_w8(gspca_dev, SetSensorClk);
  671. }
  672. static void mi0360_InitSensor(struct gspca_dev *gspca_dev)
  673. {
  674. int i = 0;
  675. while (mi0360_sensor_init[i][0]) {
  676. i2c_w8(gspca_dev, mi0360_sensor_init[i]);
  677. i++;
  678. }
  679. }
  680. static void mo4000_InitSensor(struct gspca_dev *gspca_dev)
  681. {
  682. int i = 0;
  683. while (mo4000_sensor_init[i][0]) {
  684. i2c_w8(gspca_dev, mo4000_sensor_init[i]);
  685. i++;
  686. }
  687. }
  688. static void ov7648_InitSensor(struct gspca_dev *gspca_dev)
  689. {
  690. int i = 0;
  691. while (ov7648_sensor_init[i][0]) {
  692. i2c_w8(gspca_dev, ov7648_sensor_init[i]);
  693. i++;
  694. }
  695. }
  696. static void ov7660_InitSensor(struct gspca_dev *gspca_dev)
  697. {
  698. int i = 0;
  699. i2c_w8(gspca_dev, ov7660_sensor_init[i]); /* reset SCCB */
  700. i++;
  701. msleep(20);
  702. while (ov7660_sensor_init[i][0]) {
  703. i2c_w8(gspca_dev, ov7660_sensor_init[i]);
  704. i++;
  705. }
  706. }
  707. /* this function is called at probe time */
  708. static int sd_config(struct gspca_dev *gspca_dev,
  709. const struct usb_device_id *id)
  710. {
  711. struct sd *sd = (struct sd *) gspca_dev;
  712. struct cam *cam;
  713. cam = &gspca_dev->cam;
  714. cam->epaddr = 0x01;
  715. cam->cam_mode = vga_mode;
  716. cam->nmodes = ARRAY_SIZE(vga_mode);
  717. sd->bridge = id->driver_info >> 16;
  718. sd->sensor = id->driver_info >> 8;
  719. sd->i2c_base = id->driver_info;
  720. sd->qindex = 4; /* set the quantization table */
  721. sd->brightness = BRIGHTNESS_DEF;
  722. sd->contrast = CONTRAST_DEF;
  723. sd->colors = COLOR_DEF;
  724. sd->autogain = AUTOGAIN_DEF;
  725. return 0;
  726. }
  727. /* this function is called at open time */
  728. static int sd_open(struct gspca_dev *gspca_dev)
  729. {
  730. struct sd *sd = (struct sd *) gspca_dev;
  731. /* const __u8 *sn9c1xx; */
  732. __u8 regGpio[] = { 0x29, 0x74 };
  733. __u8 regF1;
  734. /* setup a selector by bridge */
  735. reg_w1(gspca_dev, 0xf1, 0x01);
  736. reg_r(gspca_dev, 0x00, 1);
  737. reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]);
  738. reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
  739. regF1 = gspca_dev->usb_buf[0];
  740. PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
  741. switch (sd->bridge) {
  742. case BRIDGE_SN9C102P:
  743. if (regF1 != 0x11)
  744. return -ENODEV;
  745. reg_w1(gspca_dev, 0x02, regGpio[1]);
  746. break;
  747. case BRIDGE_SN9C105:
  748. if (regF1 != 0x11)
  749. return -ENODEV;
  750. reg_w(gspca_dev, 0x02, regGpio, 2);
  751. break;
  752. case BRIDGE_SN9C120:
  753. if (regF1 != 0x12)
  754. return -ENODEV;
  755. regGpio[1] = 0x70;
  756. reg_w(gspca_dev, 0x02, regGpio, 2);
  757. break;
  758. default:
  759. /* case BRIDGE_SN9C110: */
  760. /* case BRIDGE_SN9C325: */
  761. if (regF1 != 0x12)
  762. return -ENODEV;
  763. reg_w1(gspca_dev, 0x02, 0x62);
  764. break;
  765. }
  766. reg_w1(gspca_dev, 0xf1, 0x01);
  767. return 0;
  768. }
  769. static unsigned int setexposure(struct gspca_dev *gspca_dev,
  770. unsigned int expo)
  771. {
  772. struct sd *sd = (struct sd *) gspca_dev;
  773. static const __u8 doit[] = /* update sensor */
  774. { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
  775. static const __u8 sensorgo[] = /* sensor on */
  776. { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
  777. static const __u8 gainMo[] =
  778. { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
  779. switch (sd->sensor) {
  780. case SENSOR_HV7131R: {
  781. __u8 Expodoit[] =
  782. { 0xc1, 0x11, 0x25, 0x07, 0x27, 0xc0, 0x00, 0x16 };
  783. Expodoit[3] = expo >> 16;
  784. Expodoit[4] = expo >> 8;
  785. Expodoit[5] = expo;
  786. i2c_w8(gspca_dev, Expodoit);
  787. break;
  788. }
  789. case SENSOR_MI0360: {
  790. __u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
  791. { 0xb1, 0x5d, 0x09, 0x06, 0x35, 0x00, 0x00, 0x16 };
  792. if (expo > 0x0635)
  793. expo = 0x0635;
  794. else if (expo < 0x0001)
  795. expo = 0x0001;
  796. expoMi[3] = expo >> 8;
  797. expoMi[4] = expo;
  798. i2c_w8(gspca_dev, expoMi);
  799. i2c_w8(gspca_dev, doit);
  800. i2c_w8(gspca_dev, sensorgo);
  801. break;
  802. }
  803. case SENSOR_MO4000: {
  804. __u8 expoMof[] =
  805. { 0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10 };
  806. __u8 expoMo10[] =
  807. { 0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10 };
  808. if (expo > 0x1fff)
  809. expo = 0x1fff;
  810. else if (expo < 0x0001)
  811. expo = 0x0001;
  812. expoMof[3] = (expo & 0x03fc) >> 2;
  813. i2c_w8(gspca_dev, expoMof);
  814. expoMo10[3] = ((expo & 0x1c00) >> 10)
  815. | ((expo & 0x0003) << 4);
  816. i2c_w8(gspca_dev, expoMo10);
  817. i2c_w8(gspca_dev, gainMo);
  818. PDEBUG(D_CONF, "set exposure %d",
  819. ((expoMo10[3] & 0x07) << 10)
  820. | (expoMof[3] << 2)
  821. | ((expoMo10[3] & 0x30) >> 4));
  822. break;
  823. }
  824. }
  825. return expo;
  826. }
  827. static void setbrightness(struct gspca_dev *gspca_dev)
  828. {
  829. struct sd *sd = (struct sd *) gspca_dev;
  830. unsigned int expo;
  831. __u8 k2;
  832. switch (sd->sensor) {
  833. case SENSOR_HV7131R:
  834. expo = sd->brightness << 4;
  835. if (expo > 0x002dc6c0)
  836. expo = 0x002dc6c0;
  837. else if (expo < 0x02a0)
  838. expo = 0x02a0;
  839. sd->exposure = setexposure(gspca_dev, expo);
  840. break;
  841. case SENSOR_MI0360:
  842. case SENSOR_MO4000:
  843. expo = sd->brightness >> 4;
  844. sd->exposure = setexposure(gspca_dev, expo);
  845. break;
  846. }
  847. k2 = sd->brightness >> 10;
  848. reg_w1(gspca_dev, 0x96, k2);
  849. }
  850. static void setcontrast(struct gspca_dev *gspca_dev)
  851. {
  852. struct sd *sd = (struct sd *) gspca_dev;
  853. __u8 k2;
  854. __u8 contrast[] = { 0x00, 0x00, 0x28, 0x00, 0x07, 0x00 };
  855. k2 = sd->contrast;
  856. contrast[2] = k2;
  857. contrast[0] = (k2 + 1) >> 1;
  858. contrast[4] = (k2 + 1) / 5;
  859. reg_w(gspca_dev, 0x84, contrast, 6);
  860. }
  861. static void setcolors(struct gspca_dev *gspca_dev)
  862. {
  863. struct sd *sd = (struct sd *) gspca_dev;
  864. __u8 data;
  865. int colour;
  866. colour = sd->colors - 128;
  867. if (colour > 0)
  868. data = (colour + 32) & 0x7f; /* blue */
  869. else
  870. data = (-colour + 32) & 0x7f; /* red */
  871. reg_w1(gspca_dev, 0x05, data);
  872. }
  873. /* -- start the camera -- */
  874. static void sd_start(struct gspca_dev *gspca_dev)
  875. {
  876. struct sd *sd = (struct sd *) gspca_dev;
  877. int i;
  878. __u8 reg1, reg17, reg18;
  879. const __u8 *sn9c1xx;
  880. int mode;
  881. static const __u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
  882. static const __u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
  883. static const __u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
  884. static const __u8 CE_sn9c325[] =
  885. { 0x32, 0xdd, 0x32, 0xdd }; /* OV7648 - SN9C325 */
  886. sn9c1xx = sn_tb[(int) sd->sensor];
  887. configure_gpio(gspca_dev, sn9c1xx);
  888. /* reg_w1(gspca_dev, 0x01, 0x44); jfm from win trace*/
  889. reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
  890. reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
  891. reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
  892. reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
  893. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  894. reg_w1(gspca_dev, 0xd2, 0x6a); /* DC29 */
  895. reg_w1(gspca_dev, 0xd3, 0x50);
  896. reg_w1(gspca_dev, 0xc6, 0x00);
  897. reg_w1(gspca_dev, 0xc7, 0x00);
  898. reg_w1(gspca_dev, 0xc8, 0x50);
  899. reg_w1(gspca_dev, 0xc9, 0x3c);
  900. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  901. switch (sd->bridge) {
  902. case BRIDGE_SN9C325:
  903. reg17 = 0xae;
  904. break;
  905. default:
  906. reg17 = 0x60;
  907. break;
  908. }
  909. reg_w1(gspca_dev, 0x17, reg17);
  910. reg_w1(gspca_dev, 0x05, sn9c1xx[5]);
  911. reg_w1(gspca_dev, 0x07, sn9c1xx[7]);
  912. reg_w1(gspca_dev, 0x06, sn9c1xx[6]);
  913. reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
  914. switch (sd->bridge) {
  915. case BRIDGE_SN9C325:
  916. reg_w(gspca_dev, 0x20, regsn20_sn9c325,
  917. sizeof regsn20_sn9c325);
  918. for (i = 0; i < 8; i++)
  919. reg_w(gspca_dev, 0x84, reg84_sn9c325,
  920. sizeof reg84_sn9c325);
  921. reg_w1(gspca_dev, 0x9a, 0x0a);
  922. reg_w1(gspca_dev, 0x99, 0x60);
  923. break;
  924. default:
  925. reg_w(gspca_dev, 0x20, regsn20, sizeof regsn20);
  926. for (i = 0; i < 8; i++)
  927. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  928. reg_w1(gspca_dev, 0x9a, 0x08);
  929. reg_w1(gspca_dev, 0x99, 0x59);
  930. break;
  931. }
  932. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  933. if (mode)
  934. reg1 = 0x46; /* 320 clk 48Mhz */
  935. else
  936. reg1 = 0x06; /* 640 clk 24Mz */
  937. reg17 = 0x61;
  938. switch (sd->sensor) {
  939. case SENSOR_HV7131R:
  940. hv7131R_InitSensor(gspca_dev);
  941. break;
  942. case SENSOR_MI0360:
  943. mi0360_InitSensor(gspca_dev);
  944. break;
  945. case SENSOR_MO4000:
  946. mo4000_InitSensor(gspca_dev);
  947. if (mode) {
  948. /* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */
  949. reg1 = 0x06; /* clk 24Mz */
  950. } else {
  951. reg17 = 0x22; /* 640 MCKSIZE */
  952. /* reg1 = 0x06; * 640 clk 24Mz (done) */
  953. }
  954. break;
  955. case SENSOR_OV7648:
  956. ov7648_InitSensor(gspca_dev);
  957. reg17 = 0xa2;
  958. reg1 = 0x44;
  959. /* if (mode)
  960. ; * 320x2...
  961. else
  962. ; * 640x... */
  963. break;
  964. default:
  965. /* case SENSOR_OV7660: */
  966. ov7660_InitSensor(gspca_dev);
  967. if (mode) {
  968. /* reg17 = 0x21; * 320 */
  969. /* reg1 = 0x44; */
  970. /* reg1 = 0x46; (done) */
  971. } else {
  972. reg17 = 0x22; /* 640 MCKSIZE */
  973. reg1 = 0x06;
  974. }
  975. break;
  976. }
  977. reg_w(gspca_dev, 0xc0, C0, 6);
  978. reg_w(gspca_dev, 0xca, CA, 4);
  979. switch (sd->bridge) {
  980. case BRIDGE_SN9C325:
  981. reg_w(gspca_dev, 0xce, CE_sn9c325, 4);
  982. break;
  983. default:
  984. reg_w(gspca_dev, 0xce, CE, 4);
  985. /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
  986. break;
  987. }
  988. /* here change size mode 0 -> VGA; 1 -> CIF */
  989. reg18 = sn9c1xx[0x18] | (mode << 4);
  990. reg_w1(gspca_dev, 0x18, reg18 | 0x40);
  991. reg_w(gspca_dev, 0x100, qtable4, 0x40);
  992. reg_w(gspca_dev, 0x140, qtable4 + 0x40, 0x40);
  993. reg_w1(gspca_dev, 0x18, reg18);
  994. reg_w1(gspca_dev, 0x17, reg17);
  995. reg_w1(gspca_dev, 0x01, reg1);
  996. setbrightness(gspca_dev);
  997. setcontrast(gspca_dev);
  998. }
  999. static void sd_stopN(struct gspca_dev *gspca_dev)
  1000. {
  1001. struct sd *sd = (struct sd *) gspca_dev;
  1002. static const __u8 stophv7131[] =
  1003. { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
  1004. static const __u8 stopmi0360[] =
  1005. { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1006. __u8 data;
  1007. const __u8 *sn9c1xx;
  1008. data = 0x0b;
  1009. switch (sd->sensor) {
  1010. case SENSOR_HV7131R:
  1011. i2c_w8(gspca_dev, stophv7131);
  1012. data = 0x2b;
  1013. break;
  1014. case SENSOR_MI0360:
  1015. i2c_w8(gspca_dev, stopmi0360);
  1016. data = 0x29;
  1017. break;
  1018. case SENSOR_OV7648:
  1019. data = 0x29;
  1020. break;
  1021. default:
  1022. /* case SENSOR_MO4000: */
  1023. /* case SENSOR_OV7660: */
  1024. break;
  1025. }
  1026. sn9c1xx = sn_tb[(int) sd->sensor];
  1027. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  1028. reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
  1029. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  1030. reg_w1(gspca_dev, 0x01, data);
  1031. reg_w1(gspca_dev, 0xf1, 0x01);
  1032. }
  1033. static void sd_stop0(struct gspca_dev *gspca_dev)
  1034. {
  1035. }
  1036. static void sd_close(struct gspca_dev *gspca_dev)
  1037. {
  1038. }
  1039. static void setautogain(struct gspca_dev *gspca_dev)
  1040. {
  1041. struct sd *sd = (struct sd *) gspca_dev;
  1042. /* Thanks S., without your advice, autobright should not work :) */
  1043. int delta;
  1044. int expotimes = 0;
  1045. __u8 luma_mean = 130;
  1046. __u8 luma_delta = 20;
  1047. delta = sd->avg_lum;
  1048. if (delta < luma_mean - luma_delta ||
  1049. delta > luma_mean + luma_delta) {
  1050. switch (sd->sensor) {
  1051. case SENSOR_HV7131R:
  1052. expotimes = sd->exposure >> 8;
  1053. expotimes += (luma_mean - delta) >> 4;
  1054. if (expotimes < 0)
  1055. expotimes = 0;
  1056. sd->exposure = setexposure(gspca_dev,
  1057. (unsigned int) (expotimes << 8));
  1058. break;
  1059. case SENSOR_MO4000:
  1060. case SENSOR_MI0360:
  1061. expotimes = sd->exposure;
  1062. expotimes += (luma_mean - delta) >> 6;
  1063. if (expotimes < 0)
  1064. expotimes = 0;
  1065. sd->exposure = setexposure(gspca_dev,
  1066. (unsigned int) expotimes);
  1067. setcolors(gspca_dev);
  1068. break;
  1069. }
  1070. }
  1071. }
  1072. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1073. struct gspca_frame *frame, /* target */
  1074. __u8 *data, /* isoc packet */
  1075. int len) /* iso packet length */
  1076. {
  1077. struct sd *sd = (struct sd *) gspca_dev;
  1078. int sof, avg_lum;
  1079. sof = len - 64;
  1080. if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9) {
  1081. /* end of frame */
  1082. gspca_frame_add(gspca_dev, LAST_PACKET,
  1083. frame, data, sof + 2);
  1084. if (sd->ag_cnt < 0)
  1085. return;
  1086. if (--sd->ag_cnt >= 0)
  1087. return;
  1088. sd->ag_cnt = AG_CNT_START;
  1089. /* w1 w2 w3 */
  1090. /* w4 w5 w6 */
  1091. /* w7 w8 */
  1092. /* w4 */
  1093. avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;
  1094. /* w6 */
  1095. avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;
  1096. /* w2 */
  1097. avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;
  1098. /* w8 */
  1099. avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;
  1100. /* w5 */
  1101. avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4;
  1102. avg_lum >>= 4;
  1103. sd->avg_lum = avg_lum;
  1104. PDEBUG(D_PACK, "mean lum %d", avg_lum);
  1105. setautogain(gspca_dev);
  1106. return;
  1107. }
  1108. if (gspca_dev->last_packet_type == LAST_PACKET) {
  1109. /* put the JPEG 422 header */
  1110. jpeg_put_header(gspca_dev, frame, sd->qindex, 0x21);
  1111. }
  1112. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  1113. }
  1114. static unsigned int getexposure(struct gspca_dev *gspca_dev)
  1115. {
  1116. struct sd *sd = (struct sd *) gspca_dev;
  1117. __u8 hexpo, mexpo, lexpo;
  1118. switch (sd->sensor) {
  1119. case SENSOR_HV7131R:
  1120. /* read sensor exposure */
  1121. i2c_r5(gspca_dev, 0x25);
  1122. return (gspca_dev->usb_buf[0] << 16)
  1123. | (gspca_dev->usb_buf[1] << 8)
  1124. | gspca_dev->usb_buf[2];
  1125. case SENSOR_MI0360:
  1126. /* read sensor exposure */
  1127. i2c_r5(gspca_dev, 0x09);
  1128. return (gspca_dev->usb_buf[0] << 8)
  1129. | gspca_dev->usb_buf[1];
  1130. case SENSOR_MO4000:
  1131. i2c_r5(gspca_dev, 0x0e);
  1132. hexpo = 0; /* gspca_dev->usb_buf[1] & 0x07; */
  1133. mexpo = 0x40; /* gspca_dev->usb_buf[2] & 0xff; */
  1134. lexpo = (gspca_dev->usb_buf[1] & 0x30) >> 4;
  1135. PDEBUG(D_CONF, "exposure %d",
  1136. (hexpo << 10) | (mexpo << 2) | lexpo);
  1137. return (hexpo << 10) | (mexpo << 2) | lexpo;
  1138. default:
  1139. /* case SENSOR_OV7648: * jfm: is it ok for 7648? */
  1140. /* case SENSOR_OV7660: */
  1141. /* read sensor exposure */
  1142. i2c_r5(gspca_dev, 0x04);
  1143. hexpo = gspca_dev->usb_buf[3] & 0x2f;
  1144. lexpo = gspca_dev->usb_buf[0] & 0x02;
  1145. i2c_r5(gspca_dev, 0x08);
  1146. mexpo = gspca_dev->usb_buf[2];
  1147. return (hexpo << 10) | (mexpo << 2) | lexpo;
  1148. }
  1149. }
  1150. static void getbrightness(struct gspca_dev *gspca_dev)
  1151. {
  1152. struct sd *sd = (struct sd *) gspca_dev;
  1153. /* hardcoded registers seem not readable */
  1154. switch (sd->sensor) {
  1155. case SENSOR_HV7131R:
  1156. sd->brightness = getexposure(gspca_dev) >> 4;
  1157. break;
  1158. case SENSOR_MI0360:
  1159. sd->brightness = getexposure(gspca_dev) << 4;
  1160. break;
  1161. case SENSOR_MO4000:
  1162. sd->brightness = getexposure(gspca_dev) << 4;
  1163. break;
  1164. }
  1165. }
  1166. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1167. {
  1168. struct sd *sd = (struct sd *) gspca_dev;
  1169. sd->brightness = val;
  1170. if (gspca_dev->streaming)
  1171. setbrightness(gspca_dev);
  1172. return 0;
  1173. }
  1174. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1175. {
  1176. struct sd *sd = (struct sd *) gspca_dev;
  1177. getbrightness(gspca_dev);
  1178. *val = sd->brightness;
  1179. return 0;
  1180. }
  1181. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1182. {
  1183. struct sd *sd = (struct sd *) gspca_dev;
  1184. sd->contrast = val;
  1185. if (gspca_dev->streaming)
  1186. setcontrast(gspca_dev);
  1187. return 0;
  1188. }
  1189. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1190. {
  1191. struct sd *sd = (struct sd *) gspca_dev;
  1192. *val = sd->contrast;
  1193. return 0;
  1194. }
  1195. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  1196. {
  1197. struct sd *sd = (struct sd *) gspca_dev;
  1198. sd->colors = val;
  1199. if (gspca_dev->streaming)
  1200. setcolors(gspca_dev);
  1201. return 0;
  1202. }
  1203. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  1204. {
  1205. struct sd *sd = (struct sd *) gspca_dev;
  1206. *val = sd->colors;
  1207. return 0;
  1208. }
  1209. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1210. {
  1211. struct sd *sd = (struct sd *) gspca_dev;
  1212. sd->autogain = val;
  1213. if (val)
  1214. sd->ag_cnt = AG_CNT_START;
  1215. else
  1216. sd->ag_cnt = -1;
  1217. return 0;
  1218. }
  1219. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1220. {
  1221. struct sd *sd = (struct sd *) gspca_dev;
  1222. *val = sd->autogain;
  1223. return 0;
  1224. }
  1225. /* sub-driver description */
  1226. static const struct sd_desc sd_desc = {
  1227. .name = MODULE_NAME,
  1228. .ctrls = sd_ctrls,
  1229. .nctrls = ARRAY_SIZE(sd_ctrls),
  1230. .config = sd_config,
  1231. .open = sd_open,
  1232. .start = sd_start,
  1233. .stopN = sd_stopN,
  1234. .stop0 = sd_stop0,
  1235. .close = sd_close,
  1236. .pkt_scan = sd_pkt_scan,
  1237. };
  1238. /* -- module initialisation -- */
  1239. #define BSI(bridge, sensor, i2c_addr) \
  1240. .driver_info = (BRIDGE_ ## bridge << 16) \
  1241. | (SENSOR_ ## sensor << 8) \
  1242. | (i2c_addr)
  1243. static const __devinitdata struct usb_device_id device_table[] = {
  1244. #ifndef CONFIG_USB_SN9C102
  1245. {USB_DEVICE(0x0458, 0x7025), BSI(SN9C120, MI0360, 0x5d)},
  1246. {USB_DEVICE(0x045e, 0x00f5), BSI(SN9C105, OV7660, 0x21)},
  1247. {USB_DEVICE(0x045e, 0x00f7), BSI(SN9C105, OV7660, 0x21)},
  1248. {USB_DEVICE(0x0471, 0x0327), BSI(SN9C105, MI0360, 0x5d)},
  1249. {USB_DEVICE(0x0471, 0x0328), BSI(SN9C105, MI0360, 0x5d)},
  1250. #endif
  1251. {USB_DEVICE(0x0471, 0x0330), BSI(SN9C105, MI0360, 0x5d)},
  1252. {USB_DEVICE(0x0c45, 0x6040), BSI(SN9C102P, HV7131R, 0x11)},
  1253. /* bw600.inf:
  1254. {USB_DEVICE(0x0c45, 0x6040), BSI(SN9C102P, MI0360, 0x5d)}, */
  1255. /* {USB_DEVICE(0x0c45, 0x603a), BSI(SN9C102P, OV7648, 0x??)}, */
  1256. /* {USB_DEVICE(0x0c45, 0x607a), BSI(SN9C102P, OV7648, 0x??)}, */
  1257. {USB_DEVICE(0x0c45, 0x607c), BSI(SN9C102P, HV7131R, 0x11)},
  1258. /* {USB_DEVICE(0x0c45, 0x607e), BSI(SN9C102P, OV7630, 0x??)}, */
  1259. {USB_DEVICE(0x0c45, 0x60c0), BSI(SN9C105, MI0360, 0x5d)},
  1260. /* {USB_DEVICE(0x0c45, 0x60c8), BSI(SN9C105, OM6801, 0x??)}, */
  1261. /* {USB_DEVICE(0x0c45, 0x60cc), BSI(SN9C105, HV7131GP, 0x??)}, */
  1262. {USB_DEVICE(0x0c45, 0x60ec), BSI(SN9C105, MO4000, 0x21)},
  1263. /* {USB_DEVICE(0x0c45, 0x60ef), BSI(SN9C105, ICM105C, 0x??)}, */
  1264. /* {USB_DEVICE(0x0c45, 0x60fa), BSI(SN9C105, OV7648, 0x??)}, */
  1265. {USB_DEVICE(0x0c45, 0x60fb), BSI(SN9C105, OV7660, 0x21)},
  1266. {USB_DEVICE(0x0c45, 0x60fc), BSI(SN9C105, HV7131R, 0x11)},
  1267. /* {USB_DEVICE(0x0c45, 0x60fe), BSI(SN9C105, OV7630, 0x??)}, */
  1268. /* {USB_DEVICE(0x0c45, 0x6108), BSI(SN9C120, OM6801, 0x??)}, */
  1269. /* {USB_DEVICE(0x0c45, 0x6122), BSI(SN9C110, ICM105C, 0x??)}, */
  1270. /* {USB_DEVICE(0x0c45, 0x6123), BSI(SN9C110, SanyoCCD, 0x??)}, */
  1271. {USB_DEVICE(0x0c45, 0x612a), BSI(SN9C325, OV7648, 0x21)},
  1272. /* bw600.inf:
  1273. {USB_DEVICE(0x0c45, 0x612a), BSI(SN9C110, OV7648, 0x21)}, */
  1274. {USB_DEVICE(0x0c45, 0x612c), BSI(SN9C110, MO4000, 0x21)},
  1275. /* {USB_DEVICE(0x0c45, 0x612e), BSI(SN9C110, OV7630, 0x??)}, */
  1276. /* {USB_DEVICE(0x0c45, 0x612f), BSI(SN9C110, ICM105C, 0x??)}, */
  1277. #ifndef CONFIG_USB_SN9C102
  1278. {USB_DEVICE(0x0c45, 0x6130), BSI(SN9C120, MI0360, 0x5d)},
  1279. {USB_DEVICE(0x0c45, 0x6138), BSI(SN9C120, MO4000, 0x21)},
  1280. /* {USB_DEVICE(0x0c45, 0x613a), BSI(SN9C120, OV7648, 0x??)}, */
  1281. {USB_DEVICE(0x0c45, 0x613b), BSI(SN9C120, OV7660, 0x21)},
  1282. {USB_DEVICE(0x0c45, 0x613c), BSI(SN9C120, HV7131R, 0x11)},
  1283. /* {USB_DEVICE(0x0c45, 0x613e), BSI(SN9C120, OV7630, 0x??)}, */
  1284. #endif
  1285. {USB_DEVICE(0x0c45, 0x6143), BSI(SN9C120, MI0360, 0x5d)},
  1286. {}
  1287. };
  1288. MODULE_DEVICE_TABLE(usb, device_table);
  1289. /* -- device connect -- */
  1290. static int sd_probe(struct usb_interface *intf,
  1291. const struct usb_device_id *id)
  1292. {
  1293. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1294. THIS_MODULE);
  1295. }
  1296. static struct usb_driver sd_driver = {
  1297. .name = MODULE_NAME,
  1298. .id_table = device_table,
  1299. .probe = sd_probe,
  1300. .disconnect = gspca_disconnect,
  1301. };
  1302. /* -- module insert / remove -- */
  1303. static int __init sd_mod_init(void)
  1304. {
  1305. if (usb_register(&sd_driver) < 0)
  1306. return -1;
  1307. info("registered");
  1308. return 0;
  1309. }
  1310. static void __exit sd_mod_exit(void)
  1311. {
  1312. usb_deregister(&sd_driver);
  1313. info("deregistered");
  1314. }
  1315. module_init(sd_mod_init);
  1316. module_exit(sd_mod_exit);