sonixb.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  1. /*
  2. * sonix sn9c102 (bayer) library
  3. * Copyright (C) 2003 2004 Michel Xhaard mxhaard@magic.fr
  4. * Add Pas106 Stefano Mozzi (C) 2004
  5. *
  6. * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #define MODULE_NAME "sonixb"
  23. #include "gspca.h"
  24. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  25. MODULE_DESCRIPTION("GSPCA/SN9C102 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. struct sd_desc sd_desc; /* our nctrls differ dependend upon the
  31. sensor, so we use a per cam copy */
  32. atomic_t avg_lum;
  33. unsigned char gain;
  34. unsigned char exposure;
  35. unsigned char brightness;
  36. unsigned char autogain;
  37. unsigned char autogain_ignore_frames;
  38. unsigned char freq; /* light freq filter setting */
  39. unsigned char saturation;
  40. unsigned char hue;
  41. unsigned char contrast;
  42. unsigned char fr_h_sz; /* size of frame header */
  43. char sensor; /* Type of image sensor chip */
  44. #define SENSOR_HV7131R 0
  45. #define SENSOR_OV6650 1
  46. #define SENSOR_OV7630 2
  47. #define SENSOR_OV7630_3 3
  48. #define SENSOR_PAS106 4
  49. #define SENSOR_PAS202 5
  50. #define SENSOR_TAS5110 6
  51. #define SENSOR_TAS5130CXX 7
  52. char sensor_has_gain;
  53. __u8 sensor_addr;
  54. };
  55. #define COMP2 0x8f
  56. #define COMP 0xc7 /* 0x87 //0x07 */
  57. #define COMP1 0xc9 /* 0x89 //0x09 */
  58. #define MCK_INIT 0x63
  59. #define MCK_INIT1 0x20 /*fixme: Bayer - 0x50 for JPEG ??*/
  60. #define SYS_CLK 0x04
  61. /* We calculate the autogain at the end of the transfer of a frame, at this
  62. moment a frame with the old settings is being transmitted, and a frame is
  63. being captured with the old settings. So if we adjust the autogain we must
  64. ignore atleast the 2 next frames for the new settings to come into effect
  65. before doing any other adjustments */
  66. #define AUTOGAIN_IGNORE_FRAMES 3
  67. #define AUTOGAIN_DEADZONE 1000
  68. #define DESIRED_AVG_LUM 7000
  69. /* V4L2 controls supported by the driver */
  70. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  71. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  72. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
  73. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
  74. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
  75. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
  76. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
  77. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
  78. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
  79. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
  80. static int sd_setsaturation(struct gspca_dev *gspca_dev, __s32 val);
  81. static int sd_getsaturation(struct gspca_dev *gspca_dev, __s32 *val);
  82. static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
  83. static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
  84. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  85. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  86. static struct ctrl sd_ctrls[] = {
  87. {
  88. {
  89. .id = V4L2_CID_BRIGHTNESS,
  90. .type = V4L2_CTRL_TYPE_INTEGER,
  91. .name = "Brightness",
  92. .minimum = 0,
  93. .maximum = 255,
  94. .step = 1,
  95. #define BRIGHTNESS_DEF 127
  96. .default_value = BRIGHTNESS_DEF,
  97. },
  98. .set = sd_setbrightness,
  99. .get = sd_getbrightness,
  100. },
  101. {
  102. {
  103. .id = V4L2_CID_GAIN,
  104. .type = V4L2_CTRL_TYPE_INTEGER,
  105. .name = "Gain",
  106. .minimum = 0,
  107. .maximum = 255,
  108. .step = 1,
  109. #define GAIN_DEF 127
  110. #define GAIN_KNEE 200
  111. .default_value = GAIN_DEF,
  112. },
  113. .set = sd_setgain,
  114. .get = sd_getgain,
  115. },
  116. {
  117. {
  118. .id = V4L2_CID_EXPOSURE,
  119. .type = V4L2_CTRL_TYPE_INTEGER,
  120. .name = "Exposure",
  121. #define EXPOSURE_DEF 16 /* 32 ms / 30 fps */
  122. #define EXPOSURE_KNEE 50 /* 100 ms / 10 fps */
  123. .minimum = 0,
  124. .maximum = 255,
  125. .step = 1,
  126. .default_value = EXPOSURE_DEF,
  127. .flags = 0,
  128. },
  129. .set = sd_setexposure,
  130. .get = sd_getexposure,
  131. },
  132. {
  133. {
  134. .id = V4L2_CID_AUTOGAIN,
  135. .type = V4L2_CTRL_TYPE_BOOLEAN,
  136. .name = "Automatic Gain (and Exposure)",
  137. .minimum = 0,
  138. .maximum = 1,
  139. .step = 1,
  140. #define AUTOGAIN_DEF 1
  141. .default_value = AUTOGAIN_DEF,
  142. .flags = 0,
  143. },
  144. .set = sd_setautogain,
  145. .get = sd_getautogain,
  146. },
  147. {
  148. {
  149. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  150. .type = V4L2_CTRL_TYPE_MENU,
  151. .name = "Light frequency filter",
  152. .minimum = 0,
  153. .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
  154. .step = 1,
  155. #define FREQ_DEF 1
  156. .default_value = FREQ_DEF,
  157. },
  158. .set = sd_setfreq,
  159. .get = sd_getfreq,
  160. },
  161. {
  162. {
  163. .id = V4L2_CID_SATURATION,
  164. .type = V4L2_CTRL_TYPE_INTEGER,
  165. .name = "Saturation",
  166. .minimum = 0,
  167. .maximum = 255,
  168. .step = 1,
  169. #define SATURATION_DEF 127
  170. .default_value = SATURATION_DEF,
  171. },
  172. .set = sd_setsaturation,
  173. .get = sd_getsaturation,
  174. },
  175. {
  176. {
  177. .id = V4L2_CID_HUE,
  178. .type = V4L2_CTRL_TYPE_INTEGER,
  179. .name = "Hue",
  180. .minimum = 0,
  181. .maximum = 255,
  182. .step = 1,
  183. #define HUE_DEF 127
  184. .default_value = HUE_DEF,
  185. },
  186. .set = sd_sethue,
  187. .get = sd_gethue,
  188. },
  189. {
  190. {
  191. .id = V4L2_CID_CONTRAST,
  192. .type = V4L2_CTRL_TYPE_INTEGER,
  193. .name = "Contrast",
  194. .minimum = 0,
  195. .maximum = 255,
  196. .step = 1,
  197. #define CONTRAST_DEF 127
  198. .default_value = CONTRAST_DEF,
  199. },
  200. .set = sd_setcontrast,
  201. .get = sd_getcontrast,
  202. },
  203. };
  204. static struct v4l2_pix_format vga_mode[] = {
  205. {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  206. .bytesperline = 160,
  207. .sizeimage = 160 * 120,
  208. .colorspace = V4L2_COLORSPACE_SRGB,
  209. .priv = 2},
  210. {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  211. .bytesperline = 320,
  212. .sizeimage = 320 * 240,
  213. .colorspace = V4L2_COLORSPACE_SRGB,
  214. .priv = 1},
  215. {640, 480, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  216. .bytesperline = 640,
  217. .sizeimage = 640 * 480,
  218. .colorspace = V4L2_COLORSPACE_SRGB,
  219. .priv = 0},
  220. };
  221. static struct v4l2_pix_format sif_mode[] = {
  222. {176, 144, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  223. .bytesperline = 176,
  224. .sizeimage = 176 * 144,
  225. .colorspace = V4L2_COLORSPACE_SRGB,
  226. .priv = 1},
  227. {352, 288, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  228. .bytesperline = 352,
  229. .sizeimage = 352 * 288,
  230. .colorspace = V4L2_COLORSPACE_SRGB,
  231. .priv = 0},
  232. };
  233. static const __u8 probe_ov7630[] = {0x08, 0x44};
  234. static const __u8 initHv7131[] = {
  235. 0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,
  236. 0x00, 0x00,
  237. 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* shift from 0x02 0x01 0x00 */
  238. 0x28, 0x1e, 0x60, 0x8a, 0x20,
  239. 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c
  240. };
  241. static const __u8 hv7131_sensor_init[][8] = {
  242. {0xc0, 0x11, 0x31, 0x38, 0x2a, 0x2e, 0x00, 0x10},
  243. {0xa0, 0x11, 0x01, 0x08, 0x2a, 0x2e, 0x00, 0x10},
  244. {0xb0, 0x11, 0x20, 0x00, 0xd0, 0x2e, 0x00, 0x10},
  245. {0xc0, 0x11, 0x25, 0x03, 0x0e, 0x28, 0x00, 0x16},
  246. {0xa0, 0x11, 0x30, 0x10, 0x0e, 0x28, 0x00, 0x15},
  247. };
  248. static const __u8 initOv6650[] = {
  249. 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  250. 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  251. 0x00, 0x02, 0x01, 0x0a, 0x16, 0x12, 0x68, 0x0b,
  252. 0x10, 0x1d, 0x10, 0x00, 0x06, 0x1f, 0x00
  253. };
  254. static const __u8 ov6650_sensor_init[][8] =
  255. {
  256. /* Bright, contrast, etc are set througth SCBB interface.
  257. * AVCAP on win2 do not send any data on this controls. */
  258. /* Anyway, some registers appears to alter bright and constrat */
  259. /* Reset sensor */
  260. {0xa0, 0x60, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
  261. /* Set clock register 0x11 low nibble is clock divider */
  262. {0xd0, 0x60, 0x11, 0xc0, 0x1b, 0x18, 0xc1, 0x10},
  263. /* Next some unknown stuff */
  264. {0xb0, 0x60, 0x15, 0x00, 0x02, 0x18, 0xc1, 0x10},
  265. /* {0xa0, 0x60, 0x1b, 0x01, 0x02, 0x18, 0xc1, 0x10},
  266. * THIS SET GREEN SCREEN
  267. * (pixels could be innverted in decode kind of "brg",
  268. * but blue wont be there. Avoid this data ... */
  269. {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, /* format out? */
  270. {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10},
  271. {0xa0, 0x60, 0x30, 0x3d, 0x0A, 0xd8, 0xa4, 0x10},
  272. /* Enable rgb brightness control */
  273. {0xa0, 0x60, 0x61, 0x08, 0x00, 0x00, 0x00, 0x10},
  274. /* HDG: Note windows uses the line below, which sets both register 0x60
  275. and 0x61 I believe these registers of the ov6650 are identical as
  276. those of the ov7630, because if this is true the windows settings
  277. add a bit additional red gain and a lot additional blue gain, which
  278. matches my findings that the windows settings make blue much too
  279. blue and red a little too red.
  280. {0xb0, 0x60, 0x60, 0x66, 0x68, 0xd8, 0xa4, 0x10}, */
  281. /* Some more unknown stuff */
  282. {0xa0, 0x60, 0x68, 0x04, 0x68, 0xd8, 0xa4, 0x10},
  283. {0xd0, 0x60, 0x17, 0x24, 0xd6, 0x04, 0x94, 0x10}, /* Clipreg */
  284. };
  285. static const __u8 initOv7630[] = {
  286. 0x04, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* r01 .. r08 */
  287. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* r09 .. r10 */
  288. 0x00, 0x02, 0x01, 0x0a, /* r11 .. r14 */
  289. 0x28, 0x1e, /* H & V sizes r15 .. r16 */
  290. 0x68, COMP1, MCK_INIT1, /* r17 .. r19 */
  291. 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c /* r1a .. r1f */
  292. };
  293. static const __u8 initOv7630_3[] = {
  294. 0x44, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20, 0x80, /* r01 .. r08 */
  295. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, /* r09 .. r10 */
  296. 0x00, 0x01, 0x01, 0x0a, /* r11 .. r14 */
  297. 0x28, 0x1e, /* H & V sizes r15 .. r16 */
  298. 0x68, 0x8f, MCK_INIT1, /* r17 .. r19 */
  299. 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c, 0x00, /* r1a .. r20 */
  300. 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, /* r21 .. r28 */
  301. 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0xff /* r29 .. r30 */
  302. };
  303. static const __u8 ov7630_sensor_init_com[][8] = {
  304. {0xa0, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
  305. {0xb0, 0x21, 0x01, 0x77, 0x3a, 0x00, 0x00, 0x10},
  306. /* {0xd0, 0x21, 0x12, 0x7c, 0x01, 0x80, 0x34, 0x10}, jfm */
  307. {0xd0, 0x21, 0x12, 0x1c, 0x00, 0x80, 0x34, 0x10}, /* jfm */
  308. {0xa0, 0x21, 0x1b, 0x04, 0x00, 0x80, 0x34, 0x10},
  309. {0xa0, 0x21, 0x20, 0x44, 0x00, 0x80, 0x34, 0x10},
  310. {0xa0, 0x21, 0x23, 0xee, 0x00, 0x80, 0x34, 0x10},
  311. {0xd0, 0x21, 0x26, 0xa0, 0x9a, 0xa0, 0x30, 0x10},
  312. {0xb0, 0x21, 0x2a, 0x80, 0x00, 0xa0, 0x30, 0x10},
  313. {0xb0, 0x21, 0x2f, 0x3d, 0x24, 0xa0, 0x30, 0x10},
  314. {0xa0, 0x21, 0x32, 0x86, 0x24, 0xa0, 0x30, 0x10},
  315. {0xb0, 0x21, 0x60, 0xa9, 0x4a, 0xa0, 0x30, 0x10},
  316. /* {0xb0, 0x21, 0x60, 0xa9, 0x42, 0xa0, 0x30, 0x10}, * jfm */
  317. {0xa0, 0x21, 0x65, 0x00, 0x42, 0xa0, 0x30, 0x10},
  318. {0xa0, 0x21, 0x69, 0x38, 0x42, 0xa0, 0x30, 0x10},
  319. {0xc0, 0x21, 0x6f, 0x88, 0x0b, 0x00, 0x30, 0x10},
  320. {0xc0, 0x21, 0x74, 0x21, 0x8e, 0x00, 0x30, 0x10},
  321. {0xa0, 0x21, 0x7d, 0xf7, 0x8e, 0x00, 0x30, 0x10},
  322. {0xd0, 0x21, 0x17, 0x1c, 0xbd, 0x06, 0xf6, 0x10},
  323. };
  324. static const __u8 ov7630_sensor_init[][8] = {
  325. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 200ms */
  326. {0xa0, 0x21, 0x11, 0x01, 0xbd, 0x06, 0xf6, 0x10}, /* jfm */
  327. {0xa0, 0x21, 0x10, 0x57, 0xbd, 0x06, 0xf6, 0x16},
  328. {0xa0, 0x21, 0x76, 0x02, 0xbd, 0x06, 0xf6, 0x16},
  329. {0xa0, 0x21, 0x00, 0x10, 0xbd, 0x06, 0xf6, 0x15}, /* gain */
  330. };
  331. static const __u8 ov7630_sensor_init_3[][8] = {
  332. {0xa0, 0x21, 0x2a, 0xa0, 0x00, 0x00, 0x00, 0x10},
  333. {0xa0, 0x21, 0x2a, 0x80, 0x00, 0x00, 0x00, 0x10},
  334. };
  335. static const __u8 initPas106[] = {
  336. 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x00, 0x00,
  337. 0x00, 0x00,
  338. 0x00, 0x00, 0x00, 0x05, 0x01, 0x00,
  339. 0x16, 0x12, 0x28, COMP1, MCK_INIT1,
  340. 0x18, 0x10, 0x04, 0x03, 0x11, 0x0c
  341. };
  342. /* compression 0x86 mckinit1 0x2b */
  343. static const __u8 pas106_data[][2] = {
  344. {0x02, 0x04}, /* Pixel Clock Divider 6 */
  345. {0x03, 0x13}, /* Frame Time MSB */
  346. /* {0x03, 0x12}, * Frame Time MSB */
  347. {0x04, 0x06}, /* Frame Time LSB */
  348. /* {0x04, 0x05}, * Frame Time LSB */
  349. {0x05, 0x65}, /* Shutter Time Line Offset */
  350. /* {0x05, 0x6d}, * Shutter Time Line Offset */
  351. /* {0x06, 0xb1}, * Shutter Time Pixel Offset */
  352. {0x06, 0xcd}, /* Shutter Time Pixel Offset */
  353. {0x07, 0xc1}, /* Black Level Subtract Sign */
  354. /* {0x07, 0x00}, * Black Level Subtract Sign */
  355. {0x08, 0x06}, /* Black Level Subtract Level */
  356. {0x08, 0x06}, /* Black Level Subtract Level */
  357. /* {0x08, 0x01}, * Black Level Subtract Level */
  358. {0x09, 0x05}, /* Color Gain B Pixel 5 a */
  359. {0x0a, 0x04}, /* Color Gain G1 Pixel 1 5 */
  360. {0x0b, 0x04}, /* Color Gain G2 Pixel 1 0 5 */
  361. {0x0c, 0x05}, /* Color Gain R Pixel 3 1 */
  362. {0x0d, 0x00}, /* Color GainH Pixel */
  363. {0x0e, 0x0e}, /* Global Gain */
  364. {0x0f, 0x00}, /* Contrast */
  365. {0x10, 0x06}, /* H&V synchro polarity */
  366. {0x11, 0x06}, /* ?default */
  367. {0x12, 0x06}, /* DAC scale */
  368. {0x14, 0x02}, /* ?default */
  369. {0x13, 0x01}, /* Validate Settings */
  370. };
  371. static const __u8 initPas202[] = {
  372. 0x44, 0x44, 0x21, 0x30, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00,
  373. 0x00, 0x00,
  374. 0x00, 0x00, 0x00, 0x07, 0x03, 0x0a, /* 6 */
  375. 0x28, 0x1e, 0x28, 0x89, 0x30,
  376. 0x00, 0x00, 0x02, 0x03, 0x0f, 0x0c
  377. };
  378. static const __u8 pas202_sensor_init[][8] = {
  379. {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10},
  380. {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10},
  381. {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10},
  382. {0xd0, 0x40, 0x0C, 0x00, 0x0C, 0x00, 0x32, 0x10},
  383. {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10},
  384. {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10},
  385. {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10},
  386. {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
  387. {0xa0, 0x40, 0x03, 0x56, 0x01, 0x00, 0x63, 0x10},
  388. {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
  389. {0xb0, 0x40, 0x04, 0x07, 0x2a, 0x00, 0x63, 0x10},
  390. {0xb0, 0x40, 0x0e, 0x00, 0x3d, 0x00, 0x63, 0x10},
  391. {0xa0, 0x40, 0x11, 0x01, 0x3d, 0x00, 0x63, 0x16},
  392. {0xa0, 0x40, 0x10, 0x08, 0x3d, 0x00, 0x63, 0x15},
  393. {0xa0, 0x40, 0x02, 0x04, 0x3d, 0x00, 0x63, 0x16},
  394. {0xa0, 0x40, 0x11, 0x01, 0x3d, 0x00, 0x63, 0x16},
  395. {0xb0, 0x40, 0x0e, 0x00, 0x31, 0x00, 0x63, 0x16},
  396. {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16},
  397. {0xa0, 0x40, 0x10, 0x0e, 0x31, 0x00, 0x63, 0x15},
  398. {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16},
  399. };
  400. static const __u8 initTas5110[] = {
  401. 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
  402. 0x00, 0x00,
  403. 0x00, 0x01, 0x00, 0x46, 0x09, 0x0a, /* shift from 0x45 0x09 0x0a */
  404. 0x16, 0x12, 0x60, 0x86, 0x2b,
  405. 0x14, 0x0a, 0x02, 0x02, 0x09, 0x07
  406. };
  407. static const __u8 tas5110_sensor_init[][8] = {
  408. {0x30, 0x11, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10},
  409. {0x30, 0x11, 0x02, 0x20, 0xa9, 0x00, 0x00, 0x10},
  410. {0xa0, 0x61, 0x9a, 0xca, 0x00, 0x00, 0x00, 0x17},
  411. };
  412. static const __u8 initTas5130[] = {
  413. 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
  414. 0x00, 0x00,
  415. 0x00, 0x01, 0x00, 0x69, 0x0c, 0x0a,
  416. 0x28, 0x1e, 0x60, COMP, MCK_INIT,
  417. 0x18, 0x10, 0x04, 0x03, 0x11, 0x0c
  418. };
  419. static const __u8 tas5130_sensor_init[][8] = {
  420. /* {0x30, 0x11, 0x00, 0x40, 0x47, 0x00, 0x00, 0x10},
  421. * shutter 0x47 short exposure? */
  422. {0x30, 0x11, 0x00, 0x40, 0x01, 0x00, 0x00, 0x10},
  423. /* shutter 0x01 long exposure */
  424. {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10},
  425. };
  426. /* get one byte in gspca_dev->usb_buf */
  427. static void reg_r(struct gspca_dev *gspca_dev,
  428. __u16 value)
  429. {
  430. usb_control_msg(gspca_dev->dev,
  431. usb_rcvctrlpipe(gspca_dev->dev, 0),
  432. 0, /* request */
  433. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  434. value,
  435. 0, /* index */
  436. gspca_dev->usb_buf, 1,
  437. 500);
  438. }
  439. static void reg_w(struct gspca_dev *gspca_dev,
  440. __u16 value,
  441. const __u8 *buffer,
  442. int len)
  443. {
  444. #ifdef CONFIG_VIDEO_ADV_DEBUG
  445. if (len > sizeof gspca_dev->usb_buf) {
  446. PDEBUG(D_ERR|D_PACK, "reg_w: buffer overflow");
  447. return;
  448. }
  449. #endif
  450. memcpy(gspca_dev->usb_buf, buffer, len);
  451. usb_control_msg(gspca_dev->dev,
  452. usb_sndctrlpipe(gspca_dev->dev, 0),
  453. 0x08, /* request */
  454. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  455. value,
  456. 0, /* index */
  457. gspca_dev->usb_buf, len,
  458. 500);
  459. }
  460. static void reg_w_big(struct gspca_dev *gspca_dev,
  461. __u16 value,
  462. const __u8 *buffer,
  463. int len)
  464. {
  465. __u8 *tmpbuf;
  466. tmpbuf = kmalloc(len, GFP_KERNEL);
  467. memcpy(tmpbuf, buffer, len);
  468. usb_control_msg(gspca_dev->dev,
  469. usb_sndctrlpipe(gspca_dev->dev, 0),
  470. 0x08, /* request */
  471. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  472. value,
  473. 0, /* index */
  474. tmpbuf, len,
  475. 500);
  476. kfree(tmpbuf);
  477. }
  478. static int i2c_w(struct gspca_dev *gspca_dev, const __u8 *buffer)
  479. {
  480. int retry = 60;
  481. /* is i2c ready */
  482. reg_w(gspca_dev, 0x08, buffer, 8);
  483. while (retry--) {
  484. msleep(10);
  485. reg_r(gspca_dev, 0x08);
  486. if (gspca_dev->usb_buf[0] & 0x04) {
  487. if (gspca_dev->usb_buf[0] & 0x08)
  488. return -1;
  489. return 0;
  490. }
  491. }
  492. return -1;
  493. }
  494. static void i2c_w_vector(struct gspca_dev *gspca_dev,
  495. const __u8 buffer[][8], int len)
  496. {
  497. for (;;) {
  498. reg_w(gspca_dev, 0x08, *buffer, 8);
  499. len -= 8;
  500. if (len <= 0)
  501. break;
  502. buffer++;
  503. }
  504. }
  505. static void setbrightness(struct gspca_dev *gspca_dev)
  506. {
  507. struct sd *sd = (struct sd *) gspca_dev;
  508. __u8 value;
  509. switch (sd->sensor) {
  510. case SENSOR_OV6650:
  511. case SENSOR_OV7630_3:
  512. case SENSOR_OV7630: {
  513. __u8 i2cOV[] =
  514. {0xa0, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10};
  515. /* change reg 0x06 */
  516. i2cOV[1] = sd->sensor_addr;
  517. i2cOV[3] = sd->brightness;
  518. if (i2c_w(gspca_dev, i2cOV) < 0)
  519. goto err;
  520. break;
  521. }
  522. case SENSOR_PAS106: {
  523. __u8 i2c1[] =
  524. {0xa1, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14};
  525. i2c1[3] = sd->brightness >> 3;
  526. i2c1[2] = 0x0e;
  527. if (i2c_w(gspca_dev, i2c1) < 0)
  528. goto err;
  529. i2c1[3] = 0x01;
  530. i2c1[2] = 0x13;
  531. if (i2c_w(gspca_dev, i2c1) < 0)
  532. goto err;
  533. break;
  534. }
  535. case SENSOR_PAS202: {
  536. /* __u8 i2cpexpo1[] =
  537. {0xb0, 0x40, 0x04, 0x07, 0x2a, 0x00, 0x63, 0x16}; */
  538. __u8 i2cpexpo[] =
  539. {0xb0, 0x40, 0x0e, 0x01, 0xab, 0x00, 0x63, 0x16};
  540. __u8 i2cp202[] =
  541. {0xa0, 0x40, 0x10, 0x0e, 0x31, 0x00, 0x63, 0x15};
  542. static __u8 i2cpdoit[] =
  543. {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16};
  544. /* change reg 0x10 */
  545. i2cpexpo[4] = 0xff - sd->brightness;
  546. /* if(i2c_w(gspca_dev,i2cpexpo1) < 0)
  547. goto err; */
  548. /* if(i2c_w(gspca_dev,i2cpdoit) < 0)
  549. goto err; */
  550. if (i2c_w(gspca_dev, i2cpexpo) < 0)
  551. goto err;
  552. if (i2c_w(gspca_dev, i2cpdoit) < 0)
  553. goto err;
  554. i2cp202[3] = sd->brightness >> 3;
  555. if (i2c_w(gspca_dev, i2cp202) < 0)
  556. goto err;
  557. if (i2c_w(gspca_dev, i2cpdoit) < 0)
  558. goto err;
  559. break;
  560. }
  561. case SENSOR_TAS5130CXX: {
  562. __u8 i2c[] =
  563. {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
  564. value = 0xff - sd->brightness;
  565. i2c[4] = value;
  566. PDEBUG(D_CONF, "brightness %d : %d", value, i2c[4]);
  567. if (i2c_w(gspca_dev, i2c) < 0)
  568. goto err;
  569. break;
  570. }
  571. case SENSOR_TAS5110:
  572. /* FIXME figure out howto control brightness on TAS5110 */
  573. break;
  574. }
  575. return;
  576. err:
  577. PDEBUG(D_ERR, "i2c error brightness");
  578. }
  579. static void setsensorgain(struct gspca_dev *gspca_dev)
  580. {
  581. struct sd *sd = (struct sd *) gspca_dev;
  582. unsigned char gain = sd->gain;
  583. switch (sd->sensor) {
  584. case SENSOR_TAS5110: {
  585. __u8 i2c[] =
  586. {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
  587. i2c[4] = 255 - gain;
  588. if (i2c_w(gspca_dev, i2c) < 0)
  589. goto err;
  590. break;
  591. }
  592. case SENSOR_OV6650:
  593. gain >>= 1;
  594. /* fall thru */
  595. case SENSOR_OV7630_3: {
  596. __u8 i2c[] = {0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10};
  597. i2c[1] = sd->sensor_addr;
  598. i2c[3] = gain >> 2;
  599. if (i2c_w(gspca_dev, i2c) < 0)
  600. goto err;
  601. break;
  602. }
  603. }
  604. return;
  605. err:
  606. PDEBUG(D_ERR, "i2c error gain");
  607. }
  608. static void setgain(struct gspca_dev *gspca_dev)
  609. {
  610. struct sd *sd = (struct sd *) gspca_dev;
  611. __u8 gain;
  612. __u8 rgb_value;
  613. gain = sd->gain >> 4;
  614. /* red and blue gain */
  615. rgb_value = gain << 4 | gain;
  616. reg_w(gspca_dev, 0x10, &rgb_value, 1);
  617. /* green gain */
  618. rgb_value = gain;
  619. reg_w(gspca_dev, 0x11, &rgb_value, 1);
  620. if (sd->sensor_has_gain)
  621. setsensorgain(gspca_dev);
  622. }
  623. static void setexposure(struct gspca_dev *gspca_dev)
  624. {
  625. struct sd *sd = (struct sd *) gspca_dev;
  626. switch (sd->sensor) {
  627. case SENSOR_TAS5110: {
  628. __u8 reg;
  629. /* register 19's high nibble contains the sn9c10x clock divider
  630. The high nibble configures the no fps according to the
  631. formula: 60 / high_nibble. With a maximum of 30 fps */
  632. reg = 120 * sd->exposure / 1000;
  633. if (reg < 2)
  634. reg = 2;
  635. else if (reg > 15)
  636. reg = 15;
  637. reg = (reg << 4) | 0x0b;
  638. reg_w(gspca_dev, 0x19, &reg, 1);
  639. break;
  640. }
  641. case SENSOR_OV6650:
  642. case SENSOR_OV7630_3: {
  643. /* The ov6650 / ov7630 have 2 registers which both influence
  644. exposure, register 11, whose low nibble sets the nr off fps
  645. according to: fps = 30 / (low_nibble + 1)
  646. The fps configures the maximum exposure setting, but it is
  647. possible to use less exposure then what the fps maximum
  648. allows by setting register 10. register 10 configures the
  649. actual exposure as quotient of the full exposure, with 0
  650. being no exposure at all (not very usefull) and reg10_max
  651. being max exposure possible at that framerate.
  652. The code maps our 0 - 510 ms exposure ctrl to these 2
  653. registers, trying to keep fps as high as possible.
  654. */
  655. __u8 i2c[] = {0xb0, 0x00, 0x10, 0x00, 0xc0, 0x00, 0x00, 0x10};
  656. int reg10, reg11;
  657. /* ov6645 datasheet says reg10_max is 9a, but that uses
  658. tline * 2 * reg10 as formula for calculating texpo, the
  659. ov6650 probably uses the same formula as the 7730 which uses
  660. tline * 4 * reg10, which explains why the reg10max we've
  661. found experimentally for the ov6650 is exactly half that of
  662. the ov6645. The ov7630 datasheet says the max is 0x41. */
  663. const int reg10_max = (sd->sensor == SENSOR_OV6650)
  664. ? 0x4d : 0x41;
  665. reg11 = (60 * sd->exposure + 999) / 1000;
  666. if (reg11 < 1)
  667. reg11 = 1;
  668. else if (reg11 > 16)
  669. reg11 = 16;
  670. /* frame exposure time in ms = 1000 * reg11 / 30 ->
  671. reg10 = sd->exposure * 2 * reg10_max / (1000 * reg11 / 30) */
  672. reg10 = (sd->exposure * 60 * reg10_max) / (1000 * reg11);
  673. /* Don't allow this to get below 10 when using autogain, the
  674. steps become very large (relatively) when below 10 causing
  675. the image to oscilate from much too dark, to much too bright
  676. and back again. */
  677. if (sd->autogain && reg10 < 10)
  678. reg10 = 10;
  679. else if (reg10 > reg10_max)
  680. reg10 = reg10_max;
  681. /* Write reg 10 and reg11 low nibble */
  682. i2c[1] = sd->sensor_addr;
  683. i2c[3] = reg10;
  684. i2c[4] |= reg11 - 1;
  685. if (sd->sensor == SENSOR_OV7630_3) {
  686. __u8 reg76 = reg10 & 0x03;
  687. __u8 i2c_reg76[] = {0xa0, 0x21, 0x76, 0x00,
  688. 0x00, 0x00, 0x00, 0x10};
  689. reg10 >>= 2;
  690. i2c_reg76[3] = reg76;
  691. if (i2c_w(gspca_dev, i2c_reg76) < 0)
  692. PDEBUG(D_ERR, "i2c error exposure");
  693. }
  694. if (i2c_w(gspca_dev, i2c) < 0)
  695. PDEBUG(D_ERR, "i2c error exposure");
  696. break;
  697. }
  698. }
  699. }
  700. static void setfreq(struct gspca_dev *gspca_dev)
  701. {
  702. struct sd *sd = (struct sd *) gspca_dev;
  703. switch (sd->sensor) {
  704. case SENSOR_OV6650:
  705. case SENSOR_OV7630_3: {
  706. /* Framerate adjust register for artificial light 50 hz flicker
  707. compensation, identical to ov6630 0x2b register, see ov6630
  708. datasheet.
  709. 0x4f -> (30 fps -> 25 fps), 0x00 -> no adjustment */
  710. __u8 i2c[] = {0xa0, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10};
  711. switch (sd->freq) {
  712. default:
  713. /* case 0: * no filter*/
  714. /* case 2: * 60 hz */
  715. i2c[3] = 0;
  716. break;
  717. case 1: /* 50 hz */
  718. i2c[3] = (sd->sensor == SENSOR_OV6650)
  719. ? 0x4f : 0x8a;
  720. break;
  721. }
  722. i2c[1] = sd->sensor_addr;
  723. if (i2c_w(gspca_dev, i2c) < 0)
  724. PDEBUG(D_ERR, "i2c error setfreq");
  725. break;
  726. }
  727. }
  728. }
  729. static void setsaturation(struct gspca_dev *gspca_dev)
  730. {
  731. struct sd *sd = (struct sd *) gspca_dev;
  732. switch (sd->sensor) {
  733. /* case SENSOR_OV6650: */
  734. case SENSOR_OV7630_3:
  735. case SENSOR_OV7630: {
  736. __u8 i2c[] = {0xa0, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10};
  737. i2c[1] = sd->sensor_addr;
  738. i2c[3] = sd->saturation & 0xf0;
  739. if (i2c_w(gspca_dev, i2c) < 0)
  740. PDEBUG(D_ERR, "i2c error setsaturation");
  741. else
  742. PDEBUG(D_CONF, "saturation set to: %d",
  743. (int)sd->saturation);
  744. break;
  745. }
  746. }
  747. }
  748. static void sethue(struct gspca_dev *gspca_dev)
  749. {
  750. struct sd *sd = (struct sd *) gspca_dev;
  751. switch (sd->sensor) {
  752. /* case SENSOR_OV6650: */
  753. case SENSOR_OV7630_3:
  754. case SENSOR_OV7630: {
  755. __u8 i2c[] = {0xa0, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10};
  756. i2c[1] = sd->sensor_addr;
  757. i2c[3] = 0x20 | (sd->hue >> 3);
  758. if (i2c_w(gspca_dev, i2c) < 0)
  759. PDEBUG(D_ERR, "i2c error setsaturation");
  760. else
  761. PDEBUG(D_CONF, "hue set to: %d", (int)sd->hue);
  762. break;
  763. }
  764. }
  765. }
  766. static void setcontrast(struct gspca_dev *gspca_dev)
  767. {
  768. struct sd *sd = (struct sd *) gspca_dev;
  769. switch (sd->sensor) {
  770. /* case SENSOR_OV6650: */
  771. case SENSOR_OV7630_3:
  772. case SENSOR_OV7630: {
  773. __u8 i2c[] = {0xa0, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10};
  774. i2c[1] = sd->sensor_addr;
  775. i2c[3] = 0x20 | (sd->contrast >> 3);
  776. if (i2c_w(gspca_dev, i2c) < 0)
  777. PDEBUG(D_ERR, "i2c error setcontrast");
  778. else
  779. PDEBUG(D_CONF, "contrast set to: %d",
  780. (int)sd->contrast);
  781. break;
  782. }
  783. }
  784. }
  785. static void do_autogain(struct gspca_dev *gspca_dev)
  786. {
  787. struct sd *sd = (struct sd *) gspca_dev;
  788. int avg_lum = atomic_read(&sd->avg_lum);
  789. if (avg_lum == -1)
  790. return;
  791. if (sd->autogain_ignore_frames > 0)
  792. sd->autogain_ignore_frames--;
  793. else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum,
  794. sd->brightness * DESIRED_AVG_LUM / 127,
  795. AUTOGAIN_DEADZONE, GAIN_KNEE, EXPOSURE_KNEE)) {
  796. PDEBUG(D_FRAM, "autogain: gain changed: gain: %d expo: %d\n",
  797. (int)sd->gain, (int)sd->exposure);
  798. sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
  799. }
  800. }
  801. /* this function is called at probe time */
  802. static int sd_config(struct gspca_dev *gspca_dev,
  803. const struct usb_device_id *id)
  804. {
  805. struct sd *sd = (struct sd *) gspca_dev;
  806. struct cam *cam;
  807. __u16 product;
  808. int sif = 0;
  809. /* nctrls depends upon the sensor, so we use a per cam copy */
  810. memcpy(&sd->sd_desc, gspca_dev->sd_desc, sizeof(struct sd_desc));
  811. gspca_dev->sd_desc = &sd->sd_desc;
  812. sd->fr_h_sz = 12; /* default size of the frame header */
  813. sd->sd_desc.nctrls = 2; /* default nb of ctrls */
  814. sd->autogain = AUTOGAIN_DEF; /* default is autogain active */
  815. product = id->idProduct;
  816. /* switch (id->idVendor) { */
  817. /* case 0x0c45: * Sonix */
  818. switch (product) {
  819. case 0x6001: /* SN9C102 */
  820. case 0x6005: /* SN9C101 */
  821. case 0x6007: /* SN9C101 */
  822. sd->sensor = SENSOR_TAS5110;
  823. sd->sensor_has_gain = 1;
  824. sd->sd_desc.nctrls = 4;
  825. sd->sd_desc.dq_callback = do_autogain;
  826. sif = 1;
  827. break;
  828. case 0x6009: /* SN9C101 */
  829. case 0x600d: /* SN9C101 */
  830. case 0x6029: /* SN9C101 */
  831. sd->sensor = SENSOR_PAS106;
  832. sif = 1;
  833. break;
  834. case 0x6011: /* SN9C101 - SN9C101G */
  835. sd->sensor = SENSOR_OV6650;
  836. sd->sensor_has_gain = 1;
  837. sd->sensor_addr = 0x60;
  838. sd->sd_desc.nctrls = 5;
  839. sd->sd_desc.dq_callback = do_autogain;
  840. sif = 1;
  841. break;
  842. case 0x6019: /* SN9C101 */
  843. case 0x602c: /* SN9C102 */
  844. case 0x602e: /* SN9C102 */
  845. sd->sensor = SENSOR_OV7630;
  846. sd->sensor_addr = 0x21;
  847. break;
  848. case 0x60b0: /* SN9C103 */
  849. sd->sensor = SENSOR_OV7630_3;
  850. sd->sensor_addr = 0x21;
  851. sd->fr_h_sz = 18; /* size of frame header */
  852. sd->sensor_has_gain = 1;
  853. sd->sd_desc.nctrls = 8;
  854. sd->sd_desc.dq_callback = do_autogain;
  855. sd->autogain = 0;
  856. break;
  857. case 0x6024: /* SN9C102 */
  858. case 0x6025: /* SN9C102 */
  859. sd->sensor = SENSOR_TAS5130CXX;
  860. break;
  861. case 0x6028: /* SN9C102 */
  862. sd->sensor = SENSOR_PAS202;
  863. break;
  864. case 0x602d: /* SN9C102 */
  865. sd->sensor = SENSOR_HV7131R;
  866. break;
  867. case 0x60af: /* SN9C103 */
  868. sd->sensor = SENSOR_PAS202;
  869. sd->fr_h_sz = 18; /* size of frame header (?) */
  870. break;
  871. }
  872. /* break; */
  873. /* } */
  874. cam = &gspca_dev->cam;
  875. cam->dev_name = (char *) id->driver_info;
  876. cam->epaddr = 0x01;
  877. if (!sif) {
  878. cam->cam_mode = vga_mode;
  879. cam->nmodes = ARRAY_SIZE(vga_mode);
  880. if (sd->sensor == SENSOR_OV7630_3) {
  881. /* We only have 320x240 & 640x480 */
  882. cam->cam_mode++;
  883. cam->nmodes--;
  884. }
  885. } else {
  886. cam->cam_mode = sif_mode;
  887. cam->nmodes = ARRAY_SIZE(sif_mode);
  888. }
  889. sd->brightness = BRIGHTNESS_DEF;
  890. sd->gain = GAIN_DEF;
  891. sd->exposure = EXPOSURE_DEF;
  892. sd->freq = FREQ_DEF;
  893. sd->contrast = CONTRAST_DEF;
  894. sd->saturation = SATURATION_DEF;
  895. sd->hue = HUE_DEF;
  896. if (sd->sensor == SENSOR_OV7630_3) /* jfm: from win trace */
  897. reg_w(gspca_dev, 0x01, probe_ov7630, sizeof probe_ov7630);
  898. return 0;
  899. }
  900. /* this function is called at open time */
  901. static int sd_open(struct gspca_dev *gspca_dev)
  902. {
  903. reg_r(gspca_dev, 0x00);
  904. if (gspca_dev->usb_buf[0] != 0x10)
  905. return -ENODEV;
  906. return 0;
  907. }
  908. static void pas106_i2cinit(struct gspca_dev *gspca_dev)
  909. {
  910. int i;
  911. const __u8 *data;
  912. __u8 i2c1[] = { 0xa1, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14 };
  913. i = ARRAY_SIZE(pas106_data);
  914. data = pas106_data[0];
  915. while (--i >= 0) {
  916. memcpy(&i2c1[2], data, 2);
  917. /* copy 2 bytes from the template */
  918. if (i2c_w(gspca_dev, i2c1) < 0)
  919. PDEBUG(D_ERR, "i2c error pas106");
  920. data += 2;
  921. }
  922. }
  923. /* -- start the camera -- */
  924. static void sd_start(struct gspca_dev *gspca_dev)
  925. {
  926. struct sd *sd = (struct sd *) gspca_dev;
  927. int mode, l;
  928. const __u8 *sn9c10x;
  929. __u8 reg01, reg17;
  930. __u8 reg17_19[3];
  931. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  932. switch (sd->sensor) {
  933. case SENSOR_HV7131R:
  934. sn9c10x = initHv7131;
  935. reg17_19[0] = 0x60;
  936. reg17_19[1] = (mode << 4) | 0x8a;
  937. reg17_19[2] = 0x20;
  938. break;
  939. case SENSOR_OV6650:
  940. sn9c10x = initOv6650;
  941. reg17_19[0] = 0x68;
  942. reg17_19[1] = (mode << 4) | 0x8b;
  943. reg17_19[2] = 0x20;
  944. break;
  945. case SENSOR_OV7630:
  946. sn9c10x = initOv7630;
  947. reg17_19[0] = 0x68;
  948. reg17_19[1] = (mode << 4) | COMP2;
  949. reg17_19[2] = MCK_INIT1;
  950. break;
  951. case SENSOR_OV7630_3:
  952. sn9c10x = initOv7630_3;
  953. reg17_19[0] = 0x68;
  954. reg17_19[1] = (mode << 4) | COMP2;
  955. reg17_19[2] = MCK_INIT1;
  956. break;
  957. case SENSOR_PAS106:
  958. sn9c10x = initPas106;
  959. reg17_19[0] = 0x24; /* 0x28 */
  960. reg17_19[1] = (mode << 4) | COMP1;
  961. reg17_19[2] = MCK_INIT1;
  962. break;
  963. case SENSOR_PAS202:
  964. sn9c10x = initPas202;
  965. reg17_19[0] = mode ? 0x24 : 0x20;
  966. reg17_19[1] = (mode << 4) | 0x89;
  967. reg17_19[2] = 0x20;
  968. break;
  969. case SENSOR_TAS5110:
  970. sn9c10x = initTas5110;
  971. reg17_19[0] = 0x60;
  972. reg17_19[1] = (mode << 4) | 0x86;
  973. reg17_19[2] = 0x2b; /* 0xf3; */
  974. break;
  975. default:
  976. /* case SENSOR_TAS5130CXX: */
  977. sn9c10x = initTas5130;
  978. reg17_19[0] = 0x60;
  979. reg17_19[1] = (mode << 4) | COMP;
  980. reg17_19[2] = mode ? 0x23 : 0x43;
  981. break;
  982. }
  983. switch (sd->sensor) {
  984. case SENSOR_OV7630:
  985. reg01 = 0x06;
  986. reg17 = 0x29;
  987. l = sizeof initOv7630;
  988. break;
  989. case SENSOR_OV7630_3:
  990. reg01 = 0x44;
  991. reg17 = 0x68;
  992. l = sizeof initOv7630_3;
  993. break;
  994. default:
  995. reg01 = sn9c10x[0];
  996. reg17 = sn9c10x[0x17 - 1];
  997. l = 0x1f;
  998. break;
  999. }
  1000. /* reg 0x01 bit 2 video transfert on */
  1001. reg_w(gspca_dev, 0x01, &reg01, 1);
  1002. /* reg 0x17 SensorClk enable inv Clk 0x60 */
  1003. reg_w(gspca_dev, 0x17, &reg17, 1);
  1004. /*fixme: for ov7630 102
  1005. reg_w(gspca_dev, 0x01, {0x06, sn9c10x[1]}, 2); */
  1006. /* Set the registers from the template */
  1007. reg_w_big(gspca_dev, 0x01, sn9c10x, l);
  1008. switch (sd->sensor) {
  1009. case SENSOR_HV7131R:
  1010. i2c_w_vector(gspca_dev, hv7131_sensor_init,
  1011. sizeof hv7131_sensor_init);
  1012. break;
  1013. case SENSOR_OV6650:
  1014. i2c_w_vector(gspca_dev, ov6650_sensor_init,
  1015. sizeof ov6650_sensor_init);
  1016. break;
  1017. case SENSOR_OV7630:
  1018. i2c_w_vector(gspca_dev, ov7630_sensor_init_com,
  1019. sizeof ov7630_sensor_init_com);
  1020. msleep(200);
  1021. i2c_w_vector(gspca_dev, ov7630_sensor_init,
  1022. sizeof ov7630_sensor_init);
  1023. break;
  1024. case SENSOR_OV7630_3:
  1025. i2c_w_vector(gspca_dev, ov7630_sensor_init_com,
  1026. sizeof ov7630_sensor_init_com);
  1027. msleep(200);
  1028. i2c_w(gspca_dev, ov7630_sensor_init_3[mode]);
  1029. break;
  1030. case SENSOR_PAS106:
  1031. pas106_i2cinit(gspca_dev);
  1032. break;
  1033. case SENSOR_PAS202:
  1034. i2c_w_vector(gspca_dev, pas202_sensor_init,
  1035. sizeof pas202_sensor_init);
  1036. break;
  1037. case SENSOR_TAS5110:
  1038. i2c_w_vector(gspca_dev, tas5110_sensor_init,
  1039. sizeof tas5110_sensor_init);
  1040. break;
  1041. default:
  1042. /* case SENSOR_TAS5130CXX: */
  1043. i2c_w_vector(gspca_dev, tas5130_sensor_init,
  1044. sizeof tas5130_sensor_init);
  1045. break;
  1046. }
  1047. /* H_size V_size 0x28, 0x1e -> 640x480. 0x16, 0x12 -> 352x288 */
  1048. reg_w(gspca_dev, 0x15, &sn9c10x[0x15 - 1], 2);
  1049. /* compression register */
  1050. reg_w(gspca_dev, 0x18, &reg17_19[1], 1);
  1051. /* H_start */
  1052. reg_w(gspca_dev, 0x12, &sn9c10x[0x12 - 1], 1);
  1053. /* V_START */
  1054. reg_w(gspca_dev, 0x13, &sn9c10x[0x13 - 1], 1);
  1055. /* reset 0x17 SensorClk enable inv Clk 0x60 */
  1056. /*fixme: ov7630 [17]=68 8f (+20 if 102)*/
  1057. reg_w(gspca_dev, 0x17, &reg17_19[0], 1);
  1058. /*MCKSIZE ->3 */ /*fixme: not ov7630*/
  1059. reg_w(gspca_dev, 0x19, &reg17_19[2], 1);
  1060. /* AE_STRX AE_STRY AE_ENDX AE_ENDY */
  1061. reg_w(gspca_dev, 0x1c, &sn9c10x[0x1c - 1], 4);
  1062. /* Enable video transfert */
  1063. reg_w(gspca_dev, 0x01, &sn9c10x[0], 1);
  1064. /* Compression */
  1065. reg_w(gspca_dev, 0x18, &reg17_19[1], 2);
  1066. msleep(20);
  1067. setgain(gspca_dev);
  1068. setbrightness(gspca_dev);
  1069. setexposure(gspca_dev);
  1070. setfreq(gspca_dev);
  1071. setsaturation(gspca_dev);
  1072. sethue(gspca_dev);
  1073. setcontrast(gspca_dev);
  1074. sd->autogain_ignore_frames = 0;
  1075. atomic_set(&sd->avg_lum, -1);
  1076. }
  1077. static void sd_stopN(struct gspca_dev *gspca_dev)
  1078. {
  1079. __u8 ByteSend;
  1080. ByteSend = 0x09; /* 0X00 */
  1081. reg_w(gspca_dev, 0x01, &ByteSend, 1);
  1082. }
  1083. static void sd_stop0(struct gspca_dev *gspca_dev)
  1084. {
  1085. }
  1086. static void sd_close(struct gspca_dev *gspca_dev)
  1087. {
  1088. }
  1089. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1090. struct gspca_frame *frame, /* target */
  1091. unsigned char *data, /* isoc packet */
  1092. int len) /* iso packet length */
  1093. {
  1094. int i;
  1095. struct sd *sd = (struct sd *) gspca_dev;
  1096. /* frames start with:
  1097. * ff ff 00 c4 c4 96 synchro
  1098. * 00 (unknown)
  1099. * xx (frame sequence / size / compression)
  1100. * (xx) (idem - extra byte for sn9c103)
  1101. * ll mm brightness sum inside auto exposure
  1102. * ll mm brightness sum outside auto exposure
  1103. * (xx xx xx xx xx) audio values for snc103
  1104. */
  1105. if (len > 6 && len < 24) {
  1106. for (i = 0; i < len - 6; i++) {
  1107. if (data[0 + i] == 0xff
  1108. && data[1 + i] == 0xff
  1109. && data[2 + i] == 0x00
  1110. && data[3 + i] == 0xc4
  1111. && data[4 + i] == 0xc4
  1112. && data[5 + i] == 0x96) { /* start of frame */
  1113. frame = gspca_frame_add(gspca_dev, LAST_PACKET,
  1114. frame, data, 0);
  1115. if (len - i < sd->fr_h_sz) {
  1116. atomic_set(&sd->avg_lum, -1);
  1117. PDEBUG(D_STREAM, "packet too short to"
  1118. " get avg brightness");
  1119. } else if (sd->fr_h_sz == 12) {
  1120. atomic_set(&sd->avg_lum,
  1121. data[i + 8] +
  1122. (data[i + 9] << 8));
  1123. } else {
  1124. atomic_set(&sd->avg_lum,
  1125. data[i + 9] +
  1126. (data[i + 10] << 8));
  1127. }
  1128. data += i + sd->fr_h_sz;
  1129. len -= i + sd->fr_h_sz;
  1130. gspca_frame_add(gspca_dev, FIRST_PACKET,
  1131. frame, data, len);
  1132. return;
  1133. }
  1134. }
  1135. }
  1136. gspca_frame_add(gspca_dev, INTER_PACKET,
  1137. frame, data, len);
  1138. }
  1139. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1140. {
  1141. struct sd *sd = (struct sd *) gspca_dev;
  1142. sd->brightness = val;
  1143. if (gspca_dev->streaming)
  1144. setbrightness(gspca_dev);
  1145. return 0;
  1146. }
  1147. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1148. {
  1149. struct sd *sd = (struct sd *) gspca_dev;
  1150. *val = sd->brightness;
  1151. return 0;
  1152. }
  1153. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  1154. {
  1155. struct sd *sd = (struct sd *) gspca_dev;
  1156. sd->gain = val;
  1157. if (gspca_dev->streaming)
  1158. setgain(gspca_dev);
  1159. return 0;
  1160. }
  1161. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  1162. {
  1163. struct sd *sd = (struct sd *) gspca_dev;
  1164. *val = sd->gain;
  1165. return 0;
  1166. }
  1167. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  1168. {
  1169. struct sd *sd = (struct sd *) gspca_dev;
  1170. sd->exposure = val;
  1171. if (gspca_dev->streaming)
  1172. setexposure(gspca_dev);
  1173. return 0;
  1174. }
  1175. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  1176. {
  1177. struct sd *sd = (struct sd *) gspca_dev;
  1178. *val = sd->exposure;
  1179. return 0;
  1180. }
  1181. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1182. {
  1183. struct sd *sd = (struct sd *) gspca_dev;
  1184. sd->autogain = val;
  1185. /* when switching to autogain set defaults to make sure
  1186. we are on a valid point of the autogain gain /
  1187. exposure knee graph, and give this change time to
  1188. take effect before doing autogain. */
  1189. if (sd->autogain) {
  1190. sd->exposure = EXPOSURE_DEF;
  1191. sd->gain = GAIN_DEF;
  1192. if (gspca_dev->streaming) {
  1193. sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
  1194. setexposure(gspca_dev);
  1195. setgain(gspca_dev);
  1196. }
  1197. }
  1198. return 0;
  1199. }
  1200. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1201. {
  1202. struct sd *sd = (struct sd *) gspca_dev;
  1203. *val = sd->autogain;
  1204. return 0;
  1205. }
  1206. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
  1207. {
  1208. struct sd *sd = (struct sd *) gspca_dev;
  1209. sd->freq = val;
  1210. if (gspca_dev->streaming)
  1211. setfreq(gspca_dev);
  1212. return 0;
  1213. }
  1214. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
  1215. {
  1216. struct sd *sd = (struct sd *) gspca_dev;
  1217. *val = sd->freq;
  1218. return 0;
  1219. }
  1220. static int sd_setsaturation(struct gspca_dev *gspca_dev, __s32 val)
  1221. {
  1222. struct sd *sd = (struct sd *) gspca_dev;
  1223. sd->saturation = val;
  1224. if (gspca_dev->streaming)
  1225. setsaturation(gspca_dev);
  1226. return 0;
  1227. }
  1228. static int sd_getsaturation(struct gspca_dev *gspca_dev, __s32 *val)
  1229. {
  1230. struct sd *sd = (struct sd *) gspca_dev;
  1231. *val = sd->saturation;
  1232. return 0;
  1233. }
  1234. static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
  1235. {
  1236. struct sd *sd = (struct sd *) gspca_dev;
  1237. sd->hue = val;
  1238. if (gspca_dev->streaming)
  1239. sethue(gspca_dev);
  1240. return 0;
  1241. }
  1242. static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
  1243. {
  1244. struct sd *sd = (struct sd *) gspca_dev;
  1245. *val = sd->hue;
  1246. return 0;
  1247. }
  1248. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1249. {
  1250. struct sd *sd = (struct sd *) gspca_dev;
  1251. sd->contrast = val;
  1252. if (gspca_dev->streaming)
  1253. setcontrast(gspca_dev);
  1254. return 0;
  1255. }
  1256. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1257. {
  1258. struct sd *sd = (struct sd *) gspca_dev;
  1259. *val = sd->contrast;
  1260. return 0;
  1261. }
  1262. static int sd_querymenu(struct gspca_dev *gspca_dev,
  1263. struct v4l2_querymenu *menu)
  1264. {
  1265. switch (menu->id) {
  1266. case V4L2_CID_POWER_LINE_FREQUENCY:
  1267. switch (menu->index) {
  1268. case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
  1269. strcpy((char *) menu->name, "NoFliker");
  1270. return 0;
  1271. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  1272. strcpy((char *) menu->name, "50 Hz");
  1273. return 0;
  1274. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  1275. strcpy((char *) menu->name, "60 Hz");
  1276. return 0;
  1277. }
  1278. break;
  1279. }
  1280. return -EINVAL;
  1281. }
  1282. /* sub-driver description */
  1283. static const struct sd_desc sd_desc = {
  1284. .name = MODULE_NAME,
  1285. .ctrls = sd_ctrls,
  1286. .nctrls = ARRAY_SIZE(sd_ctrls),
  1287. .config = sd_config,
  1288. .open = sd_open,
  1289. .start = sd_start,
  1290. .stopN = sd_stopN,
  1291. .stop0 = sd_stop0,
  1292. .close = sd_close,
  1293. .pkt_scan = sd_pkt_scan,
  1294. .querymenu = sd_querymenu,
  1295. };
  1296. /* -- module initialisation -- */
  1297. #define DVNM(name) .driver_info = (kernel_ulong_t) name
  1298. static __devinitdata struct usb_device_id device_table[] = {
  1299. #ifndef CONFIG_USB_SN9C102
  1300. {USB_DEVICE(0x0c45, 0x6001), DVNM("Genius VideoCAM NB")},
  1301. {USB_DEVICE(0x0c45, 0x6005), DVNM("Sweex Tas5110")},
  1302. {USB_DEVICE(0x0c45, 0x6007), DVNM("Sonix sn9c101 + Tas5110D")},
  1303. {USB_DEVICE(0x0c45, 0x6009), DVNM("spcaCam@120")},
  1304. {USB_DEVICE(0x0c45, 0x600d), DVNM("spcaCam@120")},
  1305. #endif
  1306. {USB_DEVICE(0x0c45, 0x6011), DVNM("MAX Webcam Microdia")},
  1307. #ifndef CONFIG_USB_SN9C102
  1308. {USB_DEVICE(0x0c45, 0x6019), DVNM("Generic Sonix OV7630")},
  1309. {USB_DEVICE(0x0c45, 0x6024), DVNM("Generic Sonix Tas5130c")},
  1310. {USB_DEVICE(0x0c45, 0x6025), DVNM("Xcam Shanga")},
  1311. {USB_DEVICE(0x0c45, 0x6028), DVNM("Sonix Btc Pc380")},
  1312. {USB_DEVICE(0x0c45, 0x6029), DVNM("spcaCam@150")},
  1313. {USB_DEVICE(0x0c45, 0x602c), DVNM("Generic Sonix OV7630")},
  1314. {USB_DEVICE(0x0c45, 0x602d), DVNM("LIC-200 LG")},
  1315. {USB_DEVICE(0x0c45, 0x602e), DVNM("Genius VideoCam Messenger")},
  1316. {USB_DEVICE(0x0c45, 0x60af), DVNM("Trust WB3100P")},
  1317. {USB_DEVICE(0x0c45, 0x60b0), DVNM("Genius VideoCam Look")},
  1318. #endif
  1319. {}
  1320. };
  1321. MODULE_DEVICE_TABLE(usb, device_table);
  1322. /* -- device connect -- */
  1323. static int sd_probe(struct usb_interface *intf,
  1324. const struct usb_device_id *id)
  1325. {
  1326. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1327. THIS_MODULE);
  1328. }
  1329. static struct usb_driver sd_driver = {
  1330. .name = MODULE_NAME,
  1331. .id_table = device_table,
  1332. .probe = sd_probe,
  1333. .disconnect = gspca_disconnect,
  1334. };
  1335. /* -- module insert / remove -- */
  1336. static int __init sd_mod_init(void)
  1337. {
  1338. if (usb_register(&sd_driver) < 0)
  1339. return -1;
  1340. PDEBUG(D_PROBE, "registered");
  1341. return 0;
  1342. }
  1343. static void __exit sd_mod_exit(void)
  1344. {
  1345. usb_deregister(&sd_driver);
  1346. PDEBUG(D_PROBE, "deregistered");
  1347. }
  1348. module_init(sd_mod_init);
  1349. module_exit(sd_mod_exit);