sonixj.c 46 KB

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