sonixb.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477
  1. /*
  2. * sonix sn9c102 (bayer) library
  3. *
  4. * Copyright (C) 2009-2011 Jean-François Moine <http://moinejf.free.fr>
  5. * Copyright (C) 2003 2004 Michel Xhaard mxhaard@magic.fr
  6. * Add Pas106 Stefano Mozzi (C) 2004
  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. /* Some documentation on known sonixb registers:
  23. Reg Use
  24. sn9c101 / sn9c102:
  25. 0x10 high nibble red gain low nibble blue gain
  26. 0x11 low nibble green gain
  27. sn9c103:
  28. 0x05 red gain 0-127
  29. 0x06 blue gain 0-127
  30. 0x07 green gain 0-127
  31. all:
  32. 0x08-0x0f i2c / 3wire registers
  33. 0x12 hstart
  34. 0x13 vstart
  35. 0x15 hsize (hsize = register-value * 16)
  36. 0x16 vsize (vsize = register-value * 16)
  37. 0x17 bit 0 toggle compression quality (according to sn9c102 driver)
  38. 0x18 bit 7 enables compression, bit 4-5 set image down scaling:
  39. 00 scale 1, 01 scale 1/2, 10, scale 1/4
  40. 0x19 high-nibble is sensor clock divider, changes exposure on sensors which
  41. use a clock generated by the bridge. Some sensors have their own clock.
  42. 0x1c auto_exposure area (for avg_lum) startx (startx = register-value * 32)
  43. 0x1d auto_exposure area (for avg_lum) starty (starty = register-value * 32)
  44. 0x1e auto_exposure area (for avg_lum) stopx (hsize = (0x1e - 0x1c) * 32)
  45. 0x1f auto_exposure area (for avg_lum) stopy (vsize = (0x1f - 0x1d) * 32)
  46. */
  47. #define MODULE_NAME "sonixb"
  48. #include <linux/input.h>
  49. #include "gspca.h"
  50. MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
  51. MODULE_DESCRIPTION("GSPCA/SN9C102 USB Camera Driver");
  52. MODULE_LICENSE("GPL");
  53. /* specific webcam descriptor */
  54. struct sd {
  55. struct gspca_dev gspca_dev; /* !! must be the first item */
  56. struct v4l2_ctrl *brightness;
  57. struct v4l2_ctrl *plfreq;
  58. atomic_t avg_lum;
  59. int prev_avg_lum;
  60. int exposure_knee;
  61. int header_read;
  62. u8 header[12]; /* Header without sof marker */
  63. unsigned char autogain_ignore_frames;
  64. unsigned char frames_to_drop;
  65. __u8 bridge; /* Type of bridge */
  66. #define BRIDGE_101 0
  67. #define BRIDGE_102 0 /* We make no difference between 101 and 102 */
  68. #define BRIDGE_103 1
  69. __u8 sensor; /* Type of image sensor chip */
  70. #define SENSOR_HV7131D 0
  71. #define SENSOR_HV7131R 1
  72. #define SENSOR_OV6650 2
  73. #define SENSOR_OV7630 3
  74. #define SENSOR_PAS106 4
  75. #define SENSOR_PAS202 5
  76. #define SENSOR_TAS5110C 6
  77. #define SENSOR_TAS5110D 7
  78. #define SENSOR_TAS5130CXX 8
  79. __u8 reg11;
  80. };
  81. typedef const __u8 sensor_init_t[8];
  82. struct sensor_data {
  83. const __u8 *bridge_init;
  84. sensor_init_t *sensor_init;
  85. int sensor_init_size;
  86. int flags;
  87. __u8 sensor_addr;
  88. };
  89. /* sensor_data flags */
  90. #define F_SIF 0x01 /* sif or vga */
  91. /* priv field of struct v4l2_pix_format flags (do not use low nibble!) */
  92. #define MODE_RAW 0x10 /* raw bayer mode */
  93. #define MODE_REDUCED_SIF 0x20 /* vga mode (320x240 / 160x120) on sif cam */
  94. #define COMP 0xc7 /* 0x87 //0x07 */
  95. #define COMP1 0xc9 /* 0x89 //0x09 */
  96. #define MCK_INIT 0x63
  97. #define MCK_INIT1 0x20 /*fixme: Bayer - 0x50 for JPEG ??*/
  98. #define SYS_CLK 0x04
  99. #define SENS(bridge, sensor, _flags, _sensor_addr) \
  100. { \
  101. .bridge_init = bridge, \
  102. .sensor_init = sensor, \
  103. .sensor_init_size = sizeof(sensor), \
  104. .flags = _flags, .sensor_addr = _sensor_addr \
  105. }
  106. /* We calculate the autogain at the end of the transfer of a frame, at this
  107. moment a frame with the old settings is being captured and transmitted. So
  108. if we adjust the gain or exposure we must ignore atleast the next frame for
  109. the new settings to come into effect before doing any other adjustments. */
  110. #define AUTOGAIN_IGNORE_FRAMES 1
  111. static const struct v4l2_pix_format vga_mode[] = {
  112. {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  113. .bytesperline = 160,
  114. .sizeimage = 160 * 120,
  115. .colorspace = V4L2_COLORSPACE_SRGB,
  116. .priv = 2 | MODE_RAW},
  117. {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  118. .bytesperline = 160,
  119. .sizeimage = 160 * 120 * 5 / 4,
  120. .colorspace = V4L2_COLORSPACE_SRGB,
  121. .priv = 2},
  122. {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  123. .bytesperline = 320,
  124. .sizeimage = 320 * 240 * 5 / 4,
  125. .colorspace = V4L2_COLORSPACE_SRGB,
  126. .priv = 1},
  127. {640, 480, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  128. .bytesperline = 640,
  129. .sizeimage = 640 * 480 * 5 / 4,
  130. .colorspace = V4L2_COLORSPACE_SRGB,
  131. .priv = 0},
  132. };
  133. static const struct v4l2_pix_format sif_mode[] = {
  134. {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  135. .bytesperline = 160,
  136. .sizeimage = 160 * 120,
  137. .colorspace = V4L2_COLORSPACE_SRGB,
  138. .priv = 1 | MODE_RAW | MODE_REDUCED_SIF},
  139. {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  140. .bytesperline = 160,
  141. .sizeimage = 160 * 120 * 5 / 4,
  142. .colorspace = V4L2_COLORSPACE_SRGB,
  143. .priv = 1 | MODE_REDUCED_SIF},
  144. {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  145. .bytesperline = 176,
  146. .sizeimage = 176 * 144,
  147. .colorspace = V4L2_COLORSPACE_SRGB,
  148. .priv = 1 | MODE_RAW},
  149. {176, 144, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  150. .bytesperline = 176,
  151. .sizeimage = 176 * 144 * 5 / 4,
  152. .colorspace = V4L2_COLORSPACE_SRGB,
  153. .priv = 1},
  154. {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  155. .bytesperline = 320,
  156. .sizeimage = 320 * 240 * 5 / 4,
  157. .colorspace = V4L2_COLORSPACE_SRGB,
  158. .priv = 0 | MODE_REDUCED_SIF},
  159. {352, 288, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
  160. .bytesperline = 352,
  161. .sizeimage = 352 * 288 * 5 / 4,
  162. .colorspace = V4L2_COLORSPACE_SRGB,
  163. .priv = 0},
  164. };
  165. static const __u8 initHv7131d[] = {
  166. 0x04, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,
  167. 0x00, 0x00,
  168. 0x00, 0x00, 0x00, 0x02, 0x02, 0x00,
  169. 0x28, 0x1e, 0x60, 0x8e, 0x42,
  170. };
  171. static const __u8 hv7131d_sensor_init[][8] = {
  172. {0xa0, 0x11, 0x01, 0x04, 0x00, 0x00, 0x00, 0x17},
  173. {0xa0, 0x11, 0x02, 0x00, 0x00, 0x00, 0x00, 0x17},
  174. {0xa0, 0x11, 0x28, 0x00, 0x00, 0x00, 0x00, 0x17},
  175. {0xa0, 0x11, 0x30, 0x30, 0x00, 0x00, 0x00, 0x17}, /* reset level */
  176. {0xa0, 0x11, 0x34, 0x02, 0x00, 0x00, 0x00, 0x17}, /* pixel bias volt */
  177. };
  178. static const __u8 initHv7131r[] = {
  179. 0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,
  180. 0x00, 0x00,
  181. 0x00, 0x00, 0x00, 0x02, 0x01, 0x00,
  182. 0x28, 0x1e, 0x60, 0x8a, 0x20,
  183. };
  184. static const __u8 hv7131r_sensor_init[][8] = {
  185. {0xc0, 0x11, 0x31, 0x38, 0x2a, 0x2e, 0x00, 0x10},
  186. {0xa0, 0x11, 0x01, 0x08, 0x2a, 0x2e, 0x00, 0x10},
  187. {0xb0, 0x11, 0x20, 0x00, 0xd0, 0x2e, 0x00, 0x10},
  188. {0xc0, 0x11, 0x25, 0x03, 0x0e, 0x28, 0x00, 0x16},
  189. {0xa0, 0x11, 0x30, 0x10, 0x0e, 0x28, 0x00, 0x15},
  190. };
  191. static const __u8 initOv6650[] = {
  192. 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  193. 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  194. 0x00, 0x01, 0x01, 0x0a, 0x16, 0x12, 0x68, 0x8b,
  195. 0x10,
  196. };
  197. static const __u8 ov6650_sensor_init[][8] = {
  198. /* Bright, contrast, etc are set through SCBB interface.
  199. * AVCAP on win2 do not send any data on this controls. */
  200. /* Anyway, some registers appears to alter bright and constrat */
  201. /* Reset sensor */
  202. {0xa0, 0x60, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
  203. /* Set clock register 0x11 low nibble is clock divider */
  204. {0xd0, 0x60, 0x11, 0xc0, 0x1b, 0x18, 0xc1, 0x10},
  205. /* Next some unknown stuff */
  206. {0xb0, 0x60, 0x15, 0x00, 0x02, 0x18, 0xc1, 0x10},
  207. /* {0xa0, 0x60, 0x1b, 0x01, 0x02, 0x18, 0xc1, 0x10},
  208. * THIS SET GREEN SCREEN
  209. * (pixels could be innverted in decode kind of "brg",
  210. * but blue wont be there. Avoid this data ... */
  211. {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, /* format out? */
  212. {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10},
  213. {0xa0, 0x60, 0x30, 0x3d, 0x0a, 0xd8, 0xa4, 0x10},
  214. /* Enable rgb brightness control */
  215. {0xa0, 0x60, 0x61, 0x08, 0x00, 0x00, 0x00, 0x10},
  216. /* HDG: Note windows uses the line below, which sets both register 0x60
  217. and 0x61 I believe these registers of the ov6650 are identical as
  218. those of the ov7630, because if this is true the windows settings
  219. add a bit additional red gain and a lot additional blue gain, which
  220. matches my findings that the windows settings make blue much too
  221. blue and red a little too red.
  222. {0xb0, 0x60, 0x60, 0x66, 0x68, 0xd8, 0xa4, 0x10}, */
  223. /* Some more unknown stuff */
  224. {0xa0, 0x60, 0x68, 0x04, 0x68, 0xd8, 0xa4, 0x10},
  225. {0xd0, 0x60, 0x17, 0x24, 0xd6, 0x04, 0x94, 0x10}, /* Clipreg */
  226. };
  227. static const __u8 initOv7630[] = {
  228. 0x04, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* r01 .. r08 */
  229. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* r09 .. r10 */
  230. 0x00, 0x01, 0x01, 0x0a, /* r11 .. r14 */
  231. 0x28, 0x1e, /* H & V sizes r15 .. r16 */
  232. 0x68, 0x8f, MCK_INIT1, /* r17 .. r19 */
  233. };
  234. static const __u8 ov7630_sensor_init[][8] = {
  235. {0xa0, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
  236. {0xb0, 0x21, 0x01, 0x77, 0x3a, 0x00, 0x00, 0x10},
  237. /* {0xd0, 0x21, 0x12, 0x7c, 0x01, 0x80, 0x34, 0x10}, jfm */
  238. {0xd0, 0x21, 0x12, 0x5c, 0x00, 0x80, 0x34, 0x10}, /* jfm */
  239. {0xa0, 0x21, 0x1b, 0x04, 0x00, 0x80, 0x34, 0x10},
  240. {0xa0, 0x21, 0x20, 0x44, 0x00, 0x80, 0x34, 0x10},
  241. {0xa0, 0x21, 0x23, 0xee, 0x00, 0x80, 0x34, 0x10},
  242. {0xd0, 0x21, 0x26, 0xa0, 0x9a, 0xa0, 0x30, 0x10},
  243. {0xb0, 0x21, 0x2a, 0x80, 0x00, 0xa0, 0x30, 0x10},
  244. {0xb0, 0x21, 0x2f, 0x3d, 0x24, 0xa0, 0x30, 0x10},
  245. {0xa0, 0x21, 0x32, 0x86, 0x24, 0xa0, 0x30, 0x10},
  246. {0xb0, 0x21, 0x60, 0xa9, 0x4a, 0xa0, 0x30, 0x10},
  247. /* {0xb0, 0x21, 0x60, 0xa9, 0x42, 0xa0, 0x30, 0x10}, * jfm */
  248. {0xa0, 0x21, 0x65, 0x00, 0x42, 0xa0, 0x30, 0x10},
  249. {0xa0, 0x21, 0x69, 0x38, 0x42, 0xa0, 0x30, 0x10},
  250. {0xc0, 0x21, 0x6f, 0x88, 0x0b, 0x00, 0x30, 0x10},
  251. {0xc0, 0x21, 0x74, 0x21, 0x8e, 0x00, 0x30, 0x10},
  252. {0xa0, 0x21, 0x7d, 0xf7, 0x8e, 0x00, 0x30, 0x10},
  253. {0xd0, 0x21, 0x17, 0x1c, 0xbd, 0x06, 0xf6, 0x10},
  254. };
  255. static const __u8 initPas106[] = {
  256. 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x00, 0x00,
  257. 0x00, 0x00,
  258. 0x00, 0x00, 0x00, 0x04, 0x01, 0x00,
  259. 0x16, 0x12, 0x24, COMP1, MCK_INIT1,
  260. };
  261. /* compression 0x86 mckinit1 0x2b */
  262. /* "Known" PAS106B registers:
  263. 0x02 clock divider
  264. 0x03 Variable framerate bits 4-11
  265. 0x04 Var framerate bits 0-3, one must leave the 4 msb's at 0 !!
  266. The variable framerate control must never be set lower then 300,
  267. which sets the framerate at 90 / reg02, otherwise vsync is lost.
  268. 0x05 Shutter Time Line Offset, this can be used as an exposure control:
  269. 0 = use full frame time, 255 = no exposure at all
  270. Note this may never be larger then "var-framerate control" / 2 - 2.
  271. When var-framerate control is < 514, no exposure is reached at the max
  272. allowed value for the framerate control value, rather then at 255.
  273. 0x06 Shutter Time Pixel Offset, like reg05 this influences exposure, but
  274. only a very little bit, leave at 0xcd
  275. 0x07 offset sign bit (bit0 1 > negative offset)
  276. 0x08 offset
  277. 0x09 Blue Gain
  278. 0x0a Green1 Gain
  279. 0x0b Green2 Gain
  280. 0x0c Red Gain
  281. 0x0e Global gain
  282. 0x13 Write 1 to commit settings to sensor
  283. */
  284. static const __u8 pas106_sensor_init[][8] = {
  285. /* Pixel Clock Divider 6 */
  286. { 0xa1, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x14 },
  287. /* Frame Time MSB (also seen as 0x12) */
  288. { 0xa1, 0x40, 0x03, 0x13, 0x00, 0x00, 0x00, 0x14 },
  289. /* Frame Time LSB (also seen as 0x05) */
  290. { 0xa1, 0x40, 0x04, 0x06, 0x00, 0x00, 0x00, 0x14 },
  291. /* Shutter Time Line Offset (also seen as 0x6d) */
  292. { 0xa1, 0x40, 0x05, 0x65, 0x00, 0x00, 0x00, 0x14 },
  293. /* Shutter Time Pixel Offset (also seen as 0xb1) */
  294. { 0xa1, 0x40, 0x06, 0xcd, 0x00, 0x00, 0x00, 0x14 },
  295. /* Black Level Subtract Sign (also seen 0x00) */
  296. { 0xa1, 0x40, 0x07, 0xc1, 0x00, 0x00, 0x00, 0x14 },
  297. /* Black Level Subtract Level (also seen 0x01) */
  298. { 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 },
  299. { 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 },
  300. /* Color Gain B Pixel 5 a */
  301. { 0xa1, 0x40, 0x09, 0x05, 0x00, 0x00, 0x00, 0x14 },
  302. /* Color Gain G1 Pixel 1 5 */
  303. { 0xa1, 0x40, 0x0a, 0x04, 0x00, 0x00, 0x00, 0x14 },
  304. /* Color Gain G2 Pixel 1 0 5 */
  305. { 0xa1, 0x40, 0x0b, 0x04, 0x00, 0x00, 0x00, 0x14 },
  306. /* Color Gain R Pixel 3 1 */
  307. { 0xa1, 0x40, 0x0c, 0x05, 0x00, 0x00, 0x00, 0x14 },
  308. /* Color GainH Pixel */
  309. { 0xa1, 0x40, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x14 },
  310. /* Global Gain */
  311. { 0xa1, 0x40, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x14 },
  312. /* Contrast */
  313. { 0xa1, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x14 },
  314. /* H&V synchro polarity */
  315. { 0xa1, 0x40, 0x10, 0x06, 0x00, 0x00, 0x00, 0x14 },
  316. /* ?default */
  317. { 0xa1, 0x40, 0x11, 0x06, 0x00, 0x00, 0x00, 0x14 },
  318. /* DAC scale */
  319. { 0xa1, 0x40, 0x12, 0x06, 0x00, 0x00, 0x00, 0x14 },
  320. /* ?default */
  321. { 0xa1, 0x40, 0x14, 0x02, 0x00, 0x00, 0x00, 0x14 },
  322. /* Validate Settings */
  323. { 0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14 },
  324. };
  325. static const __u8 initPas202[] = {
  326. 0x44, 0x44, 0x21, 0x30, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00,
  327. 0x00, 0x00,
  328. 0x00, 0x00, 0x00, 0x06, 0x03, 0x0a,
  329. 0x28, 0x1e, 0x20, 0x89, 0x20,
  330. };
  331. /* "Known" PAS202BCB registers:
  332. 0x02 clock divider
  333. 0x04 Variable framerate bits 6-11 (*)
  334. 0x05 Var framerate bits 0-5, one must leave the 2 msb's at 0 !!
  335. 0x07 Blue Gain
  336. 0x08 Green Gain
  337. 0x09 Red Gain
  338. 0x0b offset sign bit (bit0 1 > negative offset)
  339. 0x0c offset
  340. 0x0e Unknown image is slightly brighter when bit 0 is 0, if reg0f is 0 too,
  341. leave at 1 otherwise we get a jump in our exposure control
  342. 0x0f Exposure 0-255, 0 = use full frame time, 255 = no exposure at all
  343. 0x10 Master gain 0 - 31
  344. 0x11 write 1 to apply changes
  345. (*) The variable framerate control must never be set lower then 500
  346. which sets the framerate at 30 / reg02, otherwise vsync is lost.
  347. */
  348. static const __u8 pas202_sensor_init[][8] = {
  349. /* Set the clock divider to 4 -> 30 / 4 = 7.5 fps, we would like
  350. to set it lower, but for some reason the bridge starts missing
  351. vsync's then */
  352. {0xa0, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x10},
  353. {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10},
  354. {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10},
  355. {0xd0, 0x40, 0x0c, 0x00, 0x0c, 0x01, 0x32, 0x10},
  356. {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10},
  357. {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10},
  358. {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10},
  359. {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
  360. {0xa0, 0x40, 0x03, 0x56, 0x01, 0x00, 0x63, 0x10},
  361. {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
  362. };
  363. static const __u8 initTas5110c[] = {
  364. 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
  365. 0x00, 0x00,
  366. 0x00, 0x00, 0x00, 0x45, 0x09, 0x0a,
  367. 0x16, 0x12, 0x60, 0x86, 0x2b,
  368. };
  369. /* Same as above, except a different hstart */
  370. static const __u8 initTas5110d[] = {
  371. 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
  372. 0x00, 0x00,
  373. 0x00, 0x00, 0x00, 0x41, 0x09, 0x0a,
  374. 0x16, 0x12, 0x60, 0x86, 0x2b,
  375. };
  376. /* tas5110c is 3 wire, tas5110d is 2 wire (regular i2c) */
  377. static const __u8 tas5110c_sensor_init[][8] = {
  378. {0x30, 0x11, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10},
  379. {0x30, 0x11, 0x02, 0x20, 0xa9, 0x00, 0x00, 0x10},
  380. };
  381. /* Known TAS5110D registers
  382. * reg02: gain, bit order reversed!! 0 == max gain, 255 == min gain
  383. * reg03: bit3: vflip, bit4: ~hflip, bit7: ~gainboost (~ == inverted)
  384. * Note: writing reg03 seems to only work when written together with 02
  385. */
  386. static const __u8 tas5110d_sensor_init[][8] = {
  387. {0xa0, 0x61, 0x9a, 0xca, 0x00, 0x00, 0x00, 0x17}, /* reset */
  388. };
  389. static const __u8 initTas5130[] = {
  390. 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
  391. 0x00, 0x00,
  392. 0x00, 0x00, 0x00, 0x68, 0x0c, 0x0a,
  393. 0x28, 0x1e, 0x60, COMP, MCK_INIT,
  394. };
  395. static const __u8 tas5130_sensor_init[][8] = {
  396. /* {0x30, 0x11, 0x00, 0x40, 0x47, 0x00, 0x00, 0x10},
  397. * shutter 0x47 short exposure? */
  398. {0x30, 0x11, 0x00, 0x40, 0x01, 0x00, 0x00, 0x10},
  399. /* shutter 0x01 long exposure */
  400. {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10},
  401. };
  402. static const struct sensor_data sensor_data[] = {
  403. SENS(initHv7131d, hv7131d_sensor_init, 0, 0),
  404. SENS(initHv7131r, hv7131r_sensor_init, 0, 0),
  405. SENS(initOv6650, ov6650_sensor_init, F_SIF, 0x60),
  406. SENS(initOv7630, ov7630_sensor_init, 0, 0x21),
  407. SENS(initPas106, pas106_sensor_init, F_SIF, 0),
  408. SENS(initPas202, pas202_sensor_init, 0, 0),
  409. SENS(initTas5110c, tas5110c_sensor_init, F_SIF, 0),
  410. SENS(initTas5110d, tas5110d_sensor_init, F_SIF, 0),
  411. SENS(initTas5130, tas5130_sensor_init, 0, 0),
  412. };
  413. /* get one byte in gspca_dev->usb_buf */
  414. static void reg_r(struct gspca_dev *gspca_dev,
  415. __u16 value)
  416. {
  417. int res;
  418. if (gspca_dev->usb_err < 0)
  419. return;
  420. res = usb_control_msg(gspca_dev->dev,
  421. usb_rcvctrlpipe(gspca_dev->dev, 0),
  422. 0, /* request */
  423. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  424. value,
  425. 0, /* index */
  426. gspca_dev->usb_buf, 1,
  427. 500);
  428. if (res < 0) {
  429. dev_err(gspca_dev->v4l2_dev.dev,
  430. "Error reading register %02x: %d\n", value, res);
  431. gspca_dev->usb_err = res;
  432. }
  433. }
  434. static void reg_w(struct gspca_dev *gspca_dev,
  435. __u16 value,
  436. const __u8 *buffer,
  437. int len)
  438. {
  439. int res;
  440. if (gspca_dev->usb_err < 0)
  441. return;
  442. memcpy(gspca_dev->usb_buf, buffer, len);
  443. res = usb_control_msg(gspca_dev->dev,
  444. usb_sndctrlpipe(gspca_dev->dev, 0),
  445. 0x08, /* request */
  446. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  447. value,
  448. 0, /* index */
  449. gspca_dev->usb_buf, len,
  450. 500);
  451. if (res < 0) {
  452. dev_err(gspca_dev->v4l2_dev.dev,
  453. "Error writing register %02x: %d\n", value, res);
  454. gspca_dev->usb_err = res;
  455. }
  456. }
  457. static void i2c_w(struct gspca_dev *gspca_dev, const u8 *buf)
  458. {
  459. int retry = 60;
  460. if (gspca_dev->usb_err < 0)
  461. return;
  462. /* is i2c ready */
  463. reg_w(gspca_dev, 0x08, buf, 8);
  464. while (retry--) {
  465. if (gspca_dev->usb_err < 0)
  466. return;
  467. msleep(1);
  468. reg_r(gspca_dev, 0x08);
  469. if (gspca_dev->usb_buf[0] & 0x04) {
  470. if (gspca_dev->usb_buf[0] & 0x08) {
  471. dev_err(gspca_dev->v4l2_dev.dev,
  472. "i2c error writing %8ph\n", buf);
  473. gspca_dev->usb_err = -EIO;
  474. }
  475. return;
  476. }
  477. }
  478. dev_err(gspca_dev->v4l2_dev.dev, "i2c write timeout\n");
  479. gspca_dev->usb_err = -EIO;
  480. }
  481. static void i2c_w_vector(struct gspca_dev *gspca_dev,
  482. const __u8 buffer[][8], int len)
  483. {
  484. for (;;) {
  485. if (gspca_dev->usb_err < 0)
  486. return;
  487. i2c_w(gspca_dev, *buffer);
  488. len -= 8;
  489. if (len <= 0)
  490. break;
  491. buffer++;
  492. }
  493. }
  494. static void setbrightness(struct gspca_dev *gspca_dev)
  495. {
  496. struct sd *sd = (struct sd *) gspca_dev;
  497. switch (sd->sensor) {
  498. case SENSOR_OV6650:
  499. case SENSOR_OV7630: {
  500. __u8 i2cOV[] =
  501. {0xa0, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10};
  502. /* change reg 0x06 */
  503. i2cOV[1] = sensor_data[sd->sensor].sensor_addr;
  504. i2cOV[3] = sd->brightness->val;
  505. i2c_w(gspca_dev, i2cOV);
  506. break;
  507. }
  508. case SENSOR_PAS106:
  509. case SENSOR_PAS202: {
  510. __u8 i2cpbright[] =
  511. {0xb0, 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x16};
  512. __u8 i2cpdoit[] =
  513. {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
  514. /* PAS106 uses reg 7 and 8 instead of b and c */
  515. if (sd->sensor == SENSOR_PAS106) {
  516. i2cpbright[2] = 7;
  517. i2cpdoit[2] = 0x13;
  518. }
  519. if (sd->brightness->val < 127) {
  520. /* change reg 0x0b, signreg */
  521. i2cpbright[3] = 0x01;
  522. /* set reg 0x0c, offset */
  523. i2cpbright[4] = 127 - sd->brightness->val;
  524. } else
  525. i2cpbright[4] = sd->brightness->val - 127;
  526. i2c_w(gspca_dev, i2cpbright);
  527. i2c_w(gspca_dev, i2cpdoit);
  528. break;
  529. }
  530. default:
  531. break;
  532. }
  533. }
  534. static void setgain(struct gspca_dev *gspca_dev)
  535. {
  536. struct sd *sd = (struct sd *) gspca_dev;
  537. u8 gain = gspca_dev->gain->val;
  538. switch (sd->sensor) {
  539. case SENSOR_HV7131D: {
  540. __u8 i2c[] =
  541. {0xc0, 0x11, 0x31, 0x00, 0x00, 0x00, 0x00, 0x17};
  542. i2c[3] = 0x3f - gain;
  543. i2c[4] = 0x3f - gain;
  544. i2c[5] = 0x3f - gain;
  545. i2c_w(gspca_dev, i2c);
  546. break;
  547. }
  548. case SENSOR_TAS5110C:
  549. case SENSOR_TAS5130CXX: {
  550. __u8 i2c[] =
  551. {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
  552. i2c[4] = 255 - gain;
  553. i2c_w(gspca_dev, i2c);
  554. break;
  555. }
  556. case SENSOR_TAS5110D: {
  557. __u8 i2c[] = {
  558. 0xb0, 0x61, 0x02, 0x00, 0x10, 0x00, 0x00, 0x17 };
  559. gain = 255 - gain;
  560. /* The bits in the register are the wrong way around!! */
  561. i2c[3] |= (gain & 0x80) >> 7;
  562. i2c[3] |= (gain & 0x40) >> 5;
  563. i2c[3] |= (gain & 0x20) >> 3;
  564. i2c[3] |= (gain & 0x10) >> 1;
  565. i2c[3] |= (gain & 0x08) << 1;
  566. i2c[3] |= (gain & 0x04) << 3;
  567. i2c[3] |= (gain & 0x02) << 5;
  568. i2c[3] |= (gain & 0x01) << 7;
  569. i2c_w(gspca_dev, i2c);
  570. break;
  571. }
  572. case SENSOR_OV6650:
  573. case SENSOR_OV7630: {
  574. __u8 i2c[] = {0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10};
  575. /*
  576. * The ov7630's gain is weird, at 32 the gain drops to the
  577. * same level as at 16, so skip 32-47 (of the 0-63 scale).
  578. */
  579. if (sd->sensor == SENSOR_OV7630 && gain >= 32)
  580. gain += 16;
  581. i2c[1] = sensor_data[sd->sensor].sensor_addr;
  582. i2c[3] = gain;
  583. i2c_w(gspca_dev, i2c);
  584. break;
  585. }
  586. case SENSOR_PAS106:
  587. case SENSOR_PAS202: {
  588. __u8 i2cpgain[] =
  589. {0xa0, 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x15};
  590. __u8 i2cpcolorgain[] =
  591. {0xc0, 0x40, 0x07, 0x00, 0x00, 0x00, 0x00, 0x15};
  592. __u8 i2cpdoit[] =
  593. {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
  594. /* PAS106 uses different regs (and has split green gains) */
  595. if (sd->sensor == SENSOR_PAS106) {
  596. i2cpgain[2] = 0x0e;
  597. i2cpcolorgain[0] = 0xd0;
  598. i2cpcolorgain[2] = 0x09;
  599. i2cpdoit[2] = 0x13;
  600. }
  601. i2cpgain[3] = gain;
  602. i2cpcolorgain[3] = gain >> 1;
  603. i2cpcolorgain[4] = gain >> 1;
  604. i2cpcolorgain[5] = gain >> 1;
  605. i2cpcolorgain[6] = gain >> 1;
  606. i2c_w(gspca_dev, i2cpgain);
  607. i2c_w(gspca_dev, i2cpcolorgain);
  608. i2c_w(gspca_dev, i2cpdoit);
  609. break;
  610. }
  611. default:
  612. if (sd->bridge == BRIDGE_103) {
  613. u8 buf[3] = { gain, gain, gain }; /* R, G, B */
  614. reg_w(gspca_dev, 0x05, buf, 3);
  615. } else {
  616. u8 buf[2];
  617. buf[0] = gain << 4 | gain; /* Red and blue */
  618. buf[1] = gain; /* Green */
  619. reg_w(gspca_dev, 0x10, buf, 2);
  620. }
  621. }
  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_HV7131D: {
  628. /* Note the datasheet wrongly says line mode exposure uses reg
  629. 0x26 and 0x27, testing has shown 0x25 + 0x26 */
  630. __u8 i2c[] = {0xc0, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x17};
  631. u16 reg = gspca_dev->exposure->val;
  632. i2c[3] = reg >> 8;
  633. i2c[4] = reg & 0xff;
  634. i2c_w(gspca_dev, i2c);
  635. break;
  636. }
  637. case SENSOR_TAS5110C:
  638. case SENSOR_TAS5110D: {
  639. /* register 19's high nibble contains the sn9c10x clock divider
  640. The high nibble configures the no fps according to the
  641. formula: 60 / high_nibble. With a maximum of 30 fps */
  642. u8 reg = gspca_dev->exposure->val;
  643. reg = (reg << 4) | 0x0b;
  644. reg_w(gspca_dev, 0x19, &reg, 1);
  645. break;
  646. }
  647. case SENSOR_OV6650:
  648. case SENSOR_OV7630: {
  649. /* The ov6650 / ov7630 have 2 registers which both influence
  650. exposure, register 11, whose low nibble sets the nr off fps
  651. according to: fps = 30 / (low_nibble + 1)
  652. The fps configures the maximum exposure setting, but it is
  653. possible to use less exposure then what the fps maximum
  654. allows by setting register 10. register 10 configures the
  655. actual exposure as quotient of the full exposure, with 0
  656. being no exposure at all (not very useful) and reg10_max
  657. being max exposure possible at that framerate.
  658. The code maps our 0 - 510 ms exposure ctrl to these 2
  659. registers, trying to keep fps as high as possible.
  660. */
  661. __u8 i2c[] = {0xb0, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10};
  662. int reg10, reg11, reg10_max;
  663. /* ov6645 datasheet says reg10_max is 9a, but that uses
  664. tline * 2 * reg10 as formula for calculating texpo, the
  665. ov6650 probably uses the same formula as the 7730 which uses
  666. tline * 4 * reg10, which explains why the reg10max we've
  667. found experimentally for the ov6650 is exactly half that of
  668. the ov6645. The ov7630 datasheet says the max is 0x41. */
  669. if (sd->sensor == SENSOR_OV6650) {
  670. reg10_max = 0x4d;
  671. i2c[4] = 0xc0; /* OV6650 needs non default vsync pol */
  672. } else
  673. reg10_max = 0x41;
  674. reg11 = (15 * gspca_dev->exposure->val + 999) / 1000;
  675. if (reg11 < 1)
  676. reg11 = 1;
  677. else if (reg11 > 16)
  678. reg11 = 16;
  679. /* In 640x480, if the reg11 has less than 4, the image is
  680. unstable (the bridge goes into a higher compression mode
  681. which we have not reverse engineered yet). */
  682. if (gspca_dev->pixfmt.width == 640 && reg11 < 4)
  683. reg11 = 4;
  684. /* frame exposure time in ms = 1000 * reg11 / 30 ->
  685. reg10 = (gspca_dev->exposure->val / 2) * reg10_max
  686. / (1000 * reg11 / 30) */
  687. reg10 = (gspca_dev->exposure->val * 15 * reg10_max)
  688. / (1000 * reg11);
  689. /* Don't allow this to get below 10 when using autogain, the
  690. steps become very large (relatively) when below 10 causing
  691. the image to oscilate from much too dark, to much too bright
  692. and back again. */
  693. if (gspca_dev->autogain->val && reg10 < 10)
  694. reg10 = 10;
  695. else if (reg10 > reg10_max)
  696. reg10 = reg10_max;
  697. /* Write reg 10 and reg11 low nibble */
  698. i2c[1] = sensor_data[sd->sensor].sensor_addr;
  699. i2c[3] = reg10;
  700. i2c[4] |= reg11 - 1;
  701. /* If register 11 didn't change, don't change it */
  702. if (sd->reg11 == reg11)
  703. i2c[0] = 0xa0;
  704. i2c_w(gspca_dev, i2c);
  705. if (gspca_dev->usb_err == 0)
  706. sd->reg11 = reg11;
  707. break;
  708. }
  709. case SENSOR_PAS202: {
  710. __u8 i2cpframerate[] =
  711. {0xb0, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x16};
  712. __u8 i2cpexpo[] =
  713. {0xa0, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x16};
  714. const __u8 i2cpdoit[] =
  715. {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
  716. int framerate_ctrl;
  717. /* The exposure knee for the autogain algorithm is 200
  718. (100 ms / 10 fps on other sensors), for values below this
  719. use the control for setting the partial frame expose time,
  720. above that use variable framerate. This way we run at max
  721. framerate (640x480@7.5 fps, 320x240@10fps) until the knee
  722. is reached. Using the variable framerate control above 200
  723. is better then playing around with both clockdiv + partial
  724. frame exposure times (like we are doing with the ov chips),
  725. as that sometimes leads to jumps in the exposure control,
  726. which are bad for auto exposure. */
  727. if (gspca_dev->exposure->val < 200) {
  728. i2cpexpo[3] = 255 - (gspca_dev->exposure->val * 255)
  729. / 200;
  730. framerate_ctrl = 500;
  731. } else {
  732. /* The PAS202's exposure control goes from 0 - 4095,
  733. but anything below 500 causes vsync issues, so scale
  734. our 200-1023 to 500-4095 */
  735. framerate_ctrl = (gspca_dev->exposure->val - 200)
  736. * 1000 / 229 + 500;
  737. }
  738. i2cpframerate[3] = framerate_ctrl >> 6;
  739. i2cpframerate[4] = framerate_ctrl & 0x3f;
  740. i2c_w(gspca_dev, i2cpframerate);
  741. i2c_w(gspca_dev, i2cpexpo);
  742. i2c_w(gspca_dev, i2cpdoit);
  743. break;
  744. }
  745. case SENSOR_PAS106: {
  746. __u8 i2cpframerate[] =
  747. {0xb1, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x14};
  748. __u8 i2cpexpo[] =
  749. {0xa1, 0x40, 0x05, 0x00, 0x00, 0x00, 0x00, 0x14};
  750. const __u8 i2cpdoit[] =
  751. {0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14};
  752. int framerate_ctrl;
  753. /* For values below 150 use partial frame exposure, above
  754. that use framerate ctrl */
  755. if (gspca_dev->exposure->val < 150) {
  756. i2cpexpo[3] = 150 - gspca_dev->exposure->val;
  757. framerate_ctrl = 300;
  758. } else {
  759. /* The PAS106's exposure control goes from 0 - 4095,
  760. but anything below 300 causes vsync issues, so scale
  761. our 150-1023 to 300-4095 */
  762. framerate_ctrl = (gspca_dev->exposure->val - 150)
  763. * 1000 / 230 + 300;
  764. }
  765. i2cpframerate[3] = framerate_ctrl >> 4;
  766. i2cpframerate[4] = framerate_ctrl & 0x0f;
  767. i2c_w(gspca_dev, i2cpframerate);
  768. i2c_w(gspca_dev, i2cpexpo);
  769. i2c_w(gspca_dev, i2cpdoit);
  770. break;
  771. }
  772. default:
  773. break;
  774. }
  775. }
  776. static void setfreq(struct gspca_dev *gspca_dev)
  777. {
  778. struct sd *sd = (struct sd *) gspca_dev;
  779. if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630) {
  780. /* Framerate adjust register for artificial light 50 hz flicker
  781. compensation, for the ov6650 this is identical to ov6630
  782. 0x2b register, see ov6630 datasheet.
  783. 0x4f / 0x8a -> (30 fps -> 25 fps), 0x00 -> no adjustment */
  784. __u8 i2c[] = {0xa0, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10};
  785. switch (sd->plfreq->val) {
  786. default:
  787. /* case 0: * no filter*/
  788. /* case 2: * 60 hz */
  789. i2c[3] = 0;
  790. break;
  791. case 1: /* 50 hz */
  792. i2c[3] = (sd->sensor == SENSOR_OV6650)
  793. ? 0x4f : 0x8a;
  794. break;
  795. }
  796. i2c[1] = sensor_data[sd->sensor].sensor_addr;
  797. i2c_w(gspca_dev, i2c);
  798. }
  799. }
  800. static void do_autogain(struct gspca_dev *gspca_dev)
  801. {
  802. struct sd *sd = (struct sd *) gspca_dev;
  803. int deadzone, desired_avg_lum, avg_lum;
  804. avg_lum = atomic_read(&sd->avg_lum);
  805. if (avg_lum == -1)
  806. return;
  807. if (sd->autogain_ignore_frames > 0) {
  808. sd->autogain_ignore_frames--;
  809. return;
  810. }
  811. /* SIF / VGA sensors have a different autoexposure area and thus
  812. different avg_lum values for the same picture brightness */
  813. if (sensor_data[sd->sensor].flags & F_SIF) {
  814. deadzone = 500;
  815. /* SIF sensors tend to overexpose, so keep this small */
  816. desired_avg_lum = 5000;
  817. } else {
  818. deadzone = 1500;
  819. desired_avg_lum = 13000;
  820. }
  821. if (sd->brightness)
  822. desired_avg_lum = sd->brightness->val * desired_avg_lum / 127;
  823. if (gspca_dev->exposure->maximum < 500) {
  824. if (gspca_coarse_grained_expo_autogain(gspca_dev, avg_lum,
  825. desired_avg_lum, deadzone))
  826. sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
  827. } else {
  828. int gain_knee = (s32)gspca_dev->gain->maximum * 9 / 10;
  829. if (gspca_expo_autogain(gspca_dev, avg_lum, desired_avg_lum,
  830. deadzone, gain_knee, sd->exposure_knee))
  831. sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
  832. }
  833. }
  834. /* this function is called at probe time */
  835. static int sd_config(struct gspca_dev *gspca_dev,
  836. const struct usb_device_id *id)
  837. {
  838. struct sd *sd = (struct sd *) gspca_dev;
  839. struct cam *cam;
  840. reg_r(gspca_dev, 0x00);
  841. if (gspca_dev->usb_buf[0] != 0x10)
  842. return -ENODEV;
  843. /* copy the webcam info from the device id */
  844. sd->sensor = id->driver_info >> 8;
  845. sd->bridge = id->driver_info & 0xff;
  846. cam = &gspca_dev->cam;
  847. if (!(sensor_data[sd->sensor].flags & F_SIF)) {
  848. cam->cam_mode = vga_mode;
  849. cam->nmodes = ARRAY_SIZE(vga_mode);
  850. } else {
  851. cam->cam_mode = sif_mode;
  852. cam->nmodes = ARRAY_SIZE(sif_mode);
  853. }
  854. cam->npkt = 36; /* 36 packets per ISOC message */
  855. return 0;
  856. }
  857. /* this function is called at probe and resume time */
  858. static int sd_init(struct gspca_dev *gspca_dev)
  859. {
  860. const __u8 stop = 0x09; /* Disable stream turn of LED */
  861. reg_w(gspca_dev, 0x01, &stop, 1);
  862. return gspca_dev->usb_err;
  863. }
  864. static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
  865. {
  866. struct gspca_dev *gspca_dev =
  867. container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
  868. struct sd *sd = (struct sd *)gspca_dev;
  869. gspca_dev->usb_err = 0;
  870. if (ctrl->id == V4L2_CID_AUTOGAIN && ctrl->is_new && ctrl->val) {
  871. /* when switching to autogain set defaults to make sure
  872. we are on a valid point of the autogain gain /
  873. exposure knee graph, and give this change time to
  874. take effect before doing autogain. */
  875. gspca_dev->gain->val = gspca_dev->gain->default_value;
  876. gspca_dev->exposure->val = gspca_dev->exposure->default_value;
  877. sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
  878. }
  879. if (!gspca_dev->streaming)
  880. return 0;
  881. switch (ctrl->id) {
  882. case V4L2_CID_BRIGHTNESS:
  883. setbrightness(gspca_dev);
  884. break;
  885. case V4L2_CID_AUTOGAIN:
  886. if (gspca_dev->exposure->is_new || (ctrl->is_new && ctrl->val))
  887. setexposure(gspca_dev);
  888. if (gspca_dev->gain->is_new || (ctrl->is_new && ctrl->val))
  889. setgain(gspca_dev);
  890. break;
  891. case V4L2_CID_POWER_LINE_FREQUENCY:
  892. setfreq(gspca_dev);
  893. break;
  894. default:
  895. return -EINVAL;
  896. }
  897. return gspca_dev->usb_err;
  898. }
  899. static const struct v4l2_ctrl_ops sd_ctrl_ops = {
  900. .s_ctrl = sd_s_ctrl,
  901. };
  902. /* this function is called at probe time */
  903. static int sd_init_controls(struct gspca_dev *gspca_dev)
  904. {
  905. struct sd *sd = (struct sd *) gspca_dev;
  906. struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
  907. gspca_dev->vdev.ctrl_handler = hdl;
  908. v4l2_ctrl_handler_init(hdl, 5);
  909. if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630 ||
  910. sd->sensor == SENSOR_PAS106 || sd->sensor == SENSOR_PAS202)
  911. sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  912. V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
  913. /* Gain range is sensor dependent */
  914. switch (sd->sensor) {
  915. case SENSOR_OV6650:
  916. case SENSOR_PAS106:
  917. case SENSOR_PAS202:
  918. gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  919. V4L2_CID_GAIN, 0, 31, 1, 15);
  920. break;
  921. case SENSOR_OV7630:
  922. gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  923. V4L2_CID_GAIN, 0, 47, 1, 31);
  924. break;
  925. case SENSOR_HV7131D:
  926. gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  927. V4L2_CID_GAIN, 0, 63, 1, 31);
  928. break;
  929. case SENSOR_TAS5110C:
  930. case SENSOR_TAS5110D:
  931. case SENSOR_TAS5130CXX:
  932. gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  933. V4L2_CID_GAIN, 0, 255, 1, 127);
  934. break;
  935. default:
  936. if (sd->bridge == BRIDGE_103) {
  937. gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  938. V4L2_CID_GAIN, 0, 127, 1, 63);
  939. } else {
  940. gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  941. V4L2_CID_GAIN, 0, 15, 1, 7);
  942. }
  943. }
  944. /* Exposure range is sensor dependent, and not all have exposure */
  945. switch (sd->sensor) {
  946. case SENSOR_HV7131D:
  947. gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  948. V4L2_CID_EXPOSURE, 0, 8191, 1, 482);
  949. sd->exposure_knee = 964;
  950. break;
  951. case SENSOR_OV6650:
  952. case SENSOR_OV7630:
  953. case SENSOR_PAS106:
  954. case SENSOR_PAS202:
  955. gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  956. V4L2_CID_EXPOSURE, 0, 1023, 1, 66);
  957. sd->exposure_knee = 200;
  958. break;
  959. case SENSOR_TAS5110C:
  960. case SENSOR_TAS5110D:
  961. gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  962. V4L2_CID_EXPOSURE, 2, 15, 1, 2);
  963. break;
  964. }
  965. if (gspca_dev->exposure) {
  966. gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  967. V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
  968. }
  969. if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630)
  970. sd->plfreq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
  971. V4L2_CID_POWER_LINE_FREQUENCY,
  972. V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0,
  973. V4L2_CID_POWER_LINE_FREQUENCY_DISABLED);
  974. if (hdl->error) {
  975. pr_err("Could not initialize controls\n");
  976. return hdl->error;
  977. }
  978. if (gspca_dev->autogain)
  979. v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false);
  980. return 0;
  981. }
  982. /* -- start the camera -- */
  983. static int sd_start(struct gspca_dev *gspca_dev)
  984. {
  985. struct sd *sd = (struct sd *) gspca_dev;
  986. struct cam *cam = &gspca_dev->cam;
  987. int i, mode;
  988. __u8 regs[0x31];
  989. mode = cam->cam_mode[gspca_dev->curr_mode].priv & 0x07;
  990. /* Copy registers 0x01 - 0x19 from the template */
  991. memcpy(&regs[0x01], sensor_data[sd->sensor].bridge_init, 0x19);
  992. /* Set the mode */
  993. regs[0x18] |= mode << 4;
  994. /* Set bridge gain to 1.0 */
  995. if (sd->bridge == BRIDGE_103) {
  996. regs[0x05] = 0x20; /* Red */
  997. regs[0x06] = 0x20; /* Green */
  998. regs[0x07] = 0x20; /* Blue */
  999. } else {
  1000. regs[0x10] = 0x00; /* Red and blue */
  1001. regs[0x11] = 0x00; /* Green */
  1002. }
  1003. /* Setup pixel numbers and auto exposure window */
  1004. if (sensor_data[sd->sensor].flags & F_SIF) {
  1005. regs[0x1a] = 0x14; /* HO_SIZE 640, makes no sense */
  1006. regs[0x1b] = 0x0a; /* VO_SIZE 320, makes no sense */
  1007. regs[0x1c] = 0x02; /* AE H-start 64 */
  1008. regs[0x1d] = 0x02; /* AE V-start 64 */
  1009. regs[0x1e] = 0x09; /* AE H-end 288 */
  1010. regs[0x1f] = 0x07; /* AE V-end 224 */
  1011. } else {
  1012. regs[0x1a] = 0x1d; /* HO_SIZE 960, makes no sense */
  1013. regs[0x1b] = 0x10; /* VO_SIZE 512, makes no sense */
  1014. regs[0x1c] = 0x05; /* AE H-start 160 */
  1015. regs[0x1d] = 0x03; /* AE V-start 96 */
  1016. regs[0x1e] = 0x0f; /* AE H-end 480 */
  1017. regs[0x1f] = 0x0c; /* AE V-end 384 */
  1018. }
  1019. /* Setup the gamma table (only used with the sn9c103 bridge) */
  1020. for (i = 0; i < 16; i++)
  1021. regs[0x20 + i] = i * 16;
  1022. regs[0x20 + i] = 255;
  1023. /* Special cases where some regs depend on mode or bridge */
  1024. switch (sd->sensor) {
  1025. case SENSOR_TAS5130CXX:
  1026. /* FIXME / TESTME
  1027. probably not mode specific at all most likely the upper
  1028. nibble of 0x19 is exposure (clock divider) just as with
  1029. the tas5110, we need someone to test this. */
  1030. regs[0x19] = mode ? 0x23 : 0x43;
  1031. break;
  1032. case SENSOR_OV7630:
  1033. /* FIXME / TESTME for some reason with the 101/102 bridge the
  1034. clock is set to 12 Mhz (reg1 == 0x04), rather then 24.
  1035. Also the hstart needs to go from 1 to 2 when using a 103,
  1036. which is likely related. This does not seem right. */
  1037. if (sd->bridge == BRIDGE_103) {
  1038. regs[0x01] = 0x44; /* Select 24 Mhz clock */
  1039. regs[0x12] = 0x02; /* Set hstart to 2 */
  1040. }
  1041. break;
  1042. case SENSOR_PAS202:
  1043. /* For some unknown reason we need to increase hstart by 1 on
  1044. the sn9c103, otherwise we get wrong colors (bayer shift). */
  1045. if (sd->bridge == BRIDGE_103)
  1046. regs[0x12] += 1;
  1047. break;
  1048. }
  1049. /* Disable compression when the raw bayer format has been selected */
  1050. if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW)
  1051. regs[0x18] &= ~0x80;
  1052. /* Vga mode emulation on SIF sensor? */
  1053. if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_REDUCED_SIF) {
  1054. regs[0x12] += 16; /* hstart adjust */
  1055. regs[0x13] += 24; /* vstart adjust */
  1056. regs[0x15] = 320 / 16; /* hsize */
  1057. regs[0x16] = 240 / 16; /* vsize */
  1058. }
  1059. /* reg 0x01 bit 2 video transfert on */
  1060. reg_w(gspca_dev, 0x01, &regs[0x01], 1);
  1061. /* reg 0x17 SensorClk enable inv Clk 0x60 */
  1062. reg_w(gspca_dev, 0x17, &regs[0x17], 1);
  1063. /* Set the registers from the template */
  1064. reg_w(gspca_dev, 0x01, &regs[0x01],
  1065. (sd->bridge == BRIDGE_103) ? 0x30 : 0x1f);
  1066. /* Init the sensor */
  1067. i2c_w_vector(gspca_dev, sensor_data[sd->sensor].sensor_init,
  1068. sensor_data[sd->sensor].sensor_init_size);
  1069. /* Mode / bridge specific sensor setup */
  1070. switch (sd->sensor) {
  1071. case SENSOR_PAS202: {
  1072. const __u8 i2cpclockdiv[] =
  1073. {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10};
  1074. /* clockdiv from 4 to 3 (7.5 -> 10 fps) when in low res mode */
  1075. if (mode)
  1076. i2c_w(gspca_dev, i2cpclockdiv);
  1077. break;
  1078. }
  1079. case SENSOR_OV7630:
  1080. /* FIXME / TESTME We should be able to handle this identical
  1081. for the 101/102 and the 103 case */
  1082. if (sd->bridge == BRIDGE_103) {
  1083. const __u8 i2c[] = { 0xa0, 0x21, 0x13,
  1084. 0x80, 0x00, 0x00, 0x00, 0x10 };
  1085. i2c_w(gspca_dev, i2c);
  1086. }
  1087. break;
  1088. }
  1089. /* H_size V_size 0x28, 0x1e -> 640x480. 0x16, 0x12 -> 352x288 */
  1090. reg_w(gspca_dev, 0x15, &regs[0x15], 2);
  1091. /* compression register */
  1092. reg_w(gspca_dev, 0x18, &regs[0x18], 1);
  1093. /* H_start */
  1094. reg_w(gspca_dev, 0x12, &regs[0x12], 1);
  1095. /* V_START */
  1096. reg_w(gspca_dev, 0x13, &regs[0x13], 1);
  1097. /* reset 0x17 SensorClk enable inv Clk 0x60 */
  1098. /*fixme: ov7630 [17]=68 8f (+20 if 102)*/
  1099. reg_w(gspca_dev, 0x17, &regs[0x17], 1);
  1100. /*MCKSIZE ->3 */ /*fixme: not ov7630*/
  1101. reg_w(gspca_dev, 0x19, &regs[0x19], 1);
  1102. /* AE_STRX AE_STRY AE_ENDX AE_ENDY */
  1103. reg_w(gspca_dev, 0x1c, &regs[0x1c], 4);
  1104. /* Enable video transfert */
  1105. reg_w(gspca_dev, 0x01, &regs[0x01], 1);
  1106. /* Compression */
  1107. reg_w(gspca_dev, 0x18, &regs[0x18], 2);
  1108. msleep(20);
  1109. sd->reg11 = -1;
  1110. setgain(gspca_dev);
  1111. setbrightness(gspca_dev);
  1112. setexposure(gspca_dev);
  1113. setfreq(gspca_dev);
  1114. sd->frames_to_drop = 0;
  1115. sd->autogain_ignore_frames = 0;
  1116. gspca_dev->exp_too_high_cnt = 0;
  1117. gspca_dev->exp_too_low_cnt = 0;
  1118. atomic_set(&sd->avg_lum, -1);
  1119. return gspca_dev->usb_err;
  1120. }
  1121. static void sd_stopN(struct gspca_dev *gspca_dev)
  1122. {
  1123. sd_init(gspca_dev);
  1124. }
  1125. static u8* find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
  1126. {
  1127. struct sd *sd = (struct sd *) gspca_dev;
  1128. int i, header_size = (sd->bridge == BRIDGE_103) ? 18 : 12;
  1129. /* frames start with:
  1130. * ff ff 00 c4 c4 96 synchro
  1131. * 00 (unknown)
  1132. * xx (frame sequence / size / compression)
  1133. * (xx) (idem - extra byte for sn9c103)
  1134. * ll mm brightness sum inside auto exposure
  1135. * ll mm brightness sum outside auto exposure
  1136. * (xx xx xx xx xx) audio values for snc103
  1137. */
  1138. for (i = 0; i < len; i++) {
  1139. switch (sd->header_read) {
  1140. case 0:
  1141. if (data[i] == 0xff)
  1142. sd->header_read++;
  1143. break;
  1144. case 1:
  1145. if (data[i] == 0xff)
  1146. sd->header_read++;
  1147. else
  1148. sd->header_read = 0;
  1149. break;
  1150. case 2:
  1151. if (data[i] == 0x00)
  1152. sd->header_read++;
  1153. else if (data[i] != 0xff)
  1154. sd->header_read = 0;
  1155. break;
  1156. case 3:
  1157. if (data[i] == 0xc4)
  1158. sd->header_read++;
  1159. else if (data[i] == 0xff)
  1160. sd->header_read = 1;
  1161. else
  1162. sd->header_read = 0;
  1163. break;
  1164. case 4:
  1165. if (data[i] == 0xc4)
  1166. sd->header_read++;
  1167. else if (data[i] == 0xff)
  1168. sd->header_read = 1;
  1169. else
  1170. sd->header_read = 0;
  1171. break;
  1172. case 5:
  1173. if (data[i] == 0x96)
  1174. sd->header_read++;
  1175. else if (data[i] == 0xff)
  1176. sd->header_read = 1;
  1177. else
  1178. sd->header_read = 0;
  1179. break;
  1180. default:
  1181. sd->header[sd->header_read - 6] = data[i];
  1182. sd->header_read++;
  1183. if (sd->header_read == header_size) {
  1184. sd->header_read = 0;
  1185. return data + i + 1;
  1186. }
  1187. }
  1188. }
  1189. return NULL;
  1190. }
  1191. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1192. u8 *data, /* isoc packet */
  1193. int len) /* iso packet length */
  1194. {
  1195. int fr_h_sz = 0, lum_offset = 0, len_after_sof = 0;
  1196. struct sd *sd = (struct sd *) gspca_dev;
  1197. struct cam *cam = &gspca_dev->cam;
  1198. u8 *sof;
  1199. sof = find_sof(gspca_dev, data, len);
  1200. if (sof) {
  1201. if (sd->bridge == BRIDGE_103) {
  1202. fr_h_sz = 18;
  1203. lum_offset = 3;
  1204. } else {
  1205. fr_h_sz = 12;
  1206. lum_offset = 2;
  1207. }
  1208. len_after_sof = len - (sof - data);
  1209. len = (sof - data) - fr_h_sz;
  1210. if (len < 0)
  1211. len = 0;
  1212. }
  1213. if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) {
  1214. /* In raw mode we sometimes get some garbage after the frame
  1215. ignore this */
  1216. int used;
  1217. int size = cam->cam_mode[gspca_dev->curr_mode].sizeimage;
  1218. used = gspca_dev->image_len;
  1219. if (used + len > size)
  1220. len = size - used;
  1221. }
  1222. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  1223. if (sof) {
  1224. int lum = sd->header[lum_offset] +
  1225. (sd->header[lum_offset + 1] << 8);
  1226. /* When exposure changes midway a frame we
  1227. get a lum of 0 in this case drop 2 frames
  1228. as the frames directly after an exposure
  1229. change have an unstable image. Sometimes lum
  1230. *really* is 0 (cam used in low light with
  1231. low exposure setting), so do not drop frames
  1232. if the previous lum was 0 too. */
  1233. if (lum == 0 && sd->prev_avg_lum != 0) {
  1234. lum = -1;
  1235. sd->frames_to_drop = 2;
  1236. sd->prev_avg_lum = 0;
  1237. } else
  1238. sd->prev_avg_lum = lum;
  1239. atomic_set(&sd->avg_lum, lum);
  1240. if (sd->frames_to_drop)
  1241. sd->frames_to_drop--;
  1242. else
  1243. gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
  1244. gspca_frame_add(gspca_dev, FIRST_PACKET, sof, len_after_sof);
  1245. }
  1246. }
  1247. #if IS_ENABLED(CONFIG_INPUT)
  1248. static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
  1249. u8 *data, /* interrupt packet data */
  1250. int len) /* interrupt packet length */
  1251. {
  1252. int ret = -EINVAL;
  1253. if (len == 1 && data[0] == 1) {
  1254. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
  1255. input_sync(gspca_dev->input_dev);
  1256. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
  1257. input_sync(gspca_dev->input_dev);
  1258. ret = 0;
  1259. }
  1260. return ret;
  1261. }
  1262. #endif
  1263. /* sub-driver description */
  1264. static const struct sd_desc sd_desc = {
  1265. .name = MODULE_NAME,
  1266. .config = sd_config,
  1267. .init = sd_init,
  1268. .init_controls = sd_init_controls,
  1269. .start = sd_start,
  1270. .stopN = sd_stopN,
  1271. .pkt_scan = sd_pkt_scan,
  1272. .dq_callback = do_autogain,
  1273. #if IS_ENABLED(CONFIG_INPUT)
  1274. .int_pkt_scan = sd_int_pkt_scan,
  1275. #endif
  1276. };
  1277. /* -- module initialisation -- */
  1278. #define SB(sensor, bridge) \
  1279. .driver_info = (SENSOR_ ## sensor << 8) | BRIDGE_ ## bridge
  1280. static const struct usb_device_id device_table[] = {
  1281. {USB_DEVICE(0x0c45, 0x6001), SB(TAS5110C, 102)}, /* TAS5110C1B */
  1282. {USB_DEVICE(0x0c45, 0x6005), SB(TAS5110C, 101)}, /* TAS5110C1B */
  1283. {USB_DEVICE(0x0c45, 0x6007), SB(TAS5110D, 101)}, /* TAS5110D */
  1284. {USB_DEVICE(0x0c45, 0x6009), SB(PAS106, 101)},
  1285. {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)},
  1286. {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)},
  1287. {USB_DEVICE(0x0c45, 0x6019), SB(OV7630, 101)},
  1288. {USB_DEVICE(0x0c45, 0x6024), SB(TAS5130CXX, 102)},
  1289. {USB_DEVICE(0x0c45, 0x6025), SB(TAS5130CXX, 102)},
  1290. {USB_DEVICE(0x0c45, 0x6027), SB(OV7630, 101)}, /* Genius Eye 310 */
  1291. {USB_DEVICE(0x0c45, 0x6028), SB(PAS202, 102)},
  1292. {USB_DEVICE(0x0c45, 0x6029), SB(PAS106, 102)},
  1293. {USB_DEVICE(0x0c45, 0x602a), SB(HV7131D, 102)},
  1294. /* {USB_DEVICE(0x0c45, 0x602b), SB(MI0343, 102)}, */
  1295. {USB_DEVICE(0x0c45, 0x602c), SB(OV7630, 102)},
  1296. {USB_DEVICE(0x0c45, 0x602d), SB(HV7131R, 102)},
  1297. {USB_DEVICE(0x0c45, 0x602e), SB(OV7630, 102)},
  1298. /* {USB_DEVICE(0x0c45, 0x6030), SB(MI03XX, 102)}, */ /* MI0343 MI0360 MI0330 */
  1299. /* {USB_DEVICE(0x0c45, 0x6082), SB(MI03XX, 103)}, */ /* MI0343 MI0360 */
  1300. {USB_DEVICE(0x0c45, 0x6083), SB(HV7131D, 103)},
  1301. {USB_DEVICE(0x0c45, 0x608c), SB(HV7131R, 103)},
  1302. /* {USB_DEVICE(0x0c45, 0x608e), SB(CISVF10, 103)}, */
  1303. {USB_DEVICE(0x0c45, 0x608f), SB(OV7630, 103)},
  1304. {USB_DEVICE(0x0c45, 0x60a8), SB(PAS106, 103)},
  1305. {USB_DEVICE(0x0c45, 0x60aa), SB(TAS5130CXX, 103)},
  1306. {USB_DEVICE(0x0c45, 0x60af), SB(PAS202, 103)},
  1307. {USB_DEVICE(0x0c45, 0x60b0), SB(OV7630, 103)},
  1308. {}
  1309. };
  1310. MODULE_DEVICE_TABLE(usb, device_table);
  1311. /* -- device connect -- */
  1312. static int sd_probe(struct usb_interface *intf,
  1313. const struct usb_device_id *id)
  1314. {
  1315. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1316. THIS_MODULE);
  1317. }
  1318. static struct usb_driver sd_driver = {
  1319. .name = MODULE_NAME,
  1320. .id_table = device_table,
  1321. .probe = sd_probe,
  1322. .disconnect = gspca_disconnect,
  1323. #ifdef CONFIG_PM
  1324. .suspend = gspca_suspend,
  1325. .resume = gspca_resume,
  1326. .reset_resume = gspca_resume,
  1327. #endif
  1328. };
  1329. module_usb_driver(sd_driver);