sonixj.c 49 KB

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