sonixj.c 45 KB

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