sonixj.c 45 KB

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