spca505.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * SPCA505 chip based cameras initialization data
  4. *
  5. * V4L2 by Jean-Francis Moine <http://moinejf.free.fr>
  6. */
  7. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  8. #define MODULE_NAME "spca505"
  9. #include "gspca.h"
  10. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  11. MODULE_DESCRIPTION("GSPCA/SPCA505 USB Camera Driver");
  12. MODULE_LICENSE("GPL");
  13. /* specific webcam descriptor */
  14. struct sd {
  15. struct gspca_dev gspca_dev; /* !! must be the first item */
  16. u8 subtype;
  17. #define IntelPCCameraPro 0
  18. #define Nxultra 1
  19. };
  20. static const struct v4l2_pix_format vga_mode[] = {
  21. {160, 120, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
  22. .bytesperline = 160,
  23. .sizeimage = 160 * 120 * 3 / 2,
  24. .colorspace = V4L2_COLORSPACE_SRGB,
  25. .priv = 4},
  26. {176, 144, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
  27. .bytesperline = 176,
  28. .sizeimage = 176 * 144 * 3 / 2,
  29. .colorspace = V4L2_COLORSPACE_SRGB,
  30. .priv = 3},
  31. {320, 240, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
  32. .bytesperline = 320,
  33. .sizeimage = 320 * 240 * 3 / 2,
  34. .colorspace = V4L2_COLORSPACE_SRGB,
  35. .priv = 2},
  36. {352, 288, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
  37. .bytesperline = 352,
  38. .sizeimage = 352 * 288 * 3 / 2,
  39. .colorspace = V4L2_COLORSPACE_SRGB,
  40. .priv = 1},
  41. {640, 480, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
  42. .bytesperline = 640,
  43. .sizeimage = 640 * 480 * 3 / 2,
  44. .colorspace = V4L2_COLORSPACE_SRGB,
  45. .priv = 0},
  46. };
  47. #define SPCA50X_OFFSET_DATA 10
  48. #define SPCA50X_REG_USB 0x02 /* spca505 501 */
  49. #define SPCA50X_USB_CTRL 0x00 /* spca505 */
  50. #define SPCA50X_CUSB_ENABLE 0x01 /* spca505 */
  51. #define SPCA50X_REG_GLOBAL 0x03 /* spca505 */
  52. #define SPCA50X_GMISC0_IDSEL 0x01 /* Global control device ID select spca505 */
  53. #define SPCA50X_GLOBAL_MISC0 0x00 /* Global control miscellaneous 0 spca505 */
  54. #define SPCA50X_GLOBAL_MISC1 0x01 /* 505 */
  55. #define SPCA50X_GLOBAL_MISC3 0x03 /* 505 */
  56. #define SPCA50X_GMISC3_SAA7113RST 0x20 /* Not sure about this one spca505 */
  57. /* Image format and compression control */
  58. #define SPCA50X_REG_COMPRESS 0x04
  59. /*
  60. * Data to initialize a SPCA505. Common to the CCD and external modes
  61. */
  62. static const u8 spca505_init_data[][3] = {
  63. /* bmRequest,value,index */
  64. {SPCA50X_REG_GLOBAL, SPCA50X_GMISC3_SAA7113RST, SPCA50X_GLOBAL_MISC3},
  65. /* Sensor reset */
  66. {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC3},
  67. {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC1},
  68. /* Block USB reset */
  69. {SPCA50X_REG_GLOBAL, SPCA50X_GMISC0_IDSEL, SPCA50X_GLOBAL_MISC0},
  70. {0x05, 0x01, 0x10},
  71. /* Maybe power down some stuff */
  72. {0x05, 0x0f, 0x11},
  73. /* Setup internal CCD ? */
  74. {0x06, 0x10, 0x08},
  75. {0x06, 0x00, 0x09},
  76. {0x06, 0x00, 0x0a},
  77. {0x06, 0x00, 0x0b},
  78. {0x06, 0x10, 0x0c},
  79. {0x06, 0x00, 0x0d},
  80. {0x06, 0x00, 0x0e},
  81. {0x06, 0x00, 0x0f},
  82. {0x06, 0x10, 0x10},
  83. {0x06, 0x02, 0x11},
  84. {0x06, 0x00, 0x12},
  85. {0x06, 0x04, 0x13},
  86. {0x06, 0x02, 0x14},
  87. {0x06, 0x8a, 0x51},
  88. {0x06, 0x40, 0x52},
  89. {0x06, 0xb6, 0x53},
  90. {0x06, 0x3d, 0x54},
  91. {}
  92. };
  93. /*
  94. * Data to initialize the camera using the internal CCD
  95. */
  96. static const u8 spca505_open_data_ccd[][3] = {
  97. /* bmRequest,value,index */
  98. /* Internal CCD data set */
  99. {0x03, 0x04, 0x01},
  100. /* This could be a reset */
  101. {0x03, 0x00, 0x01},
  102. /* Setup compression and image registers. 0x6 and 0x7 seem to be
  103. related to H&V hold, and are resolution mode specific */
  104. {0x04, 0x10, 0x01},
  105. /* DIFF(0x50), was (0x10) */
  106. {0x04, 0x00, 0x04},
  107. {0x04, 0x00, 0x05},
  108. {0x04, 0x20, 0x06},
  109. {0x04, 0x20, 0x07},
  110. {0x08, 0x0a, 0x00},
  111. /* DIFF (0x4a), was (0xa) */
  112. {0x05, 0x00, 0x10},
  113. {0x05, 0x00, 0x11},
  114. {0x05, 0x00, 0x00},
  115. /* DIFF not written */
  116. {0x05, 0x00, 0x01},
  117. /* DIFF not written */
  118. {0x05, 0x00, 0x02},
  119. /* DIFF not written */
  120. {0x05, 0x00, 0x03},
  121. /* DIFF not written */
  122. {0x05, 0x00, 0x04},
  123. /* DIFF not written */
  124. {0x05, 0x80, 0x05},
  125. /* DIFF not written */
  126. {0x05, 0xe0, 0x06},
  127. /* DIFF not written */
  128. {0x05, 0x20, 0x07},
  129. /* DIFF not written */
  130. {0x05, 0xa0, 0x08},
  131. /* DIFF not written */
  132. {0x05, 0x0, 0x12},
  133. /* DIFF not written */
  134. {0x05, 0x02, 0x0f},
  135. /* DIFF not written */
  136. {0x05, 0x10, 0x46},
  137. /* DIFF not written */
  138. {0x05, 0x8, 0x4a},
  139. /* DIFF not written */
  140. {0x03, 0x08, 0x03},
  141. /* DIFF (0x3,0x28,0x3) */
  142. {0x03, 0x08, 0x01},
  143. {0x03, 0x0c, 0x03},
  144. /* DIFF not written */
  145. {0x03, 0x21, 0x00},
  146. /* DIFF (0x39) */
  147. /* Extra block copied from init to hopefully ensure CCD is in a sane state */
  148. {0x06, 0x10, 0x08},
  149. {0x06, 0x00, 0x09},
  150. {0x06, 0x00, 0x0a},
  151. {0x06, 0x00, 0x0b},
  152. {0x06, 0x10, 0x0c},
  153. {0x06, 0x00, 0x0d},
  154. {0x06, 0x00, 0x0e},
  155. {0x06, 0x00, 0x0f},
  156. {0x06, 0x10, 0x10},
  157. {0x06, 0x02, 0x11},
  158. {0x06, 0x00, 0x12},
  159. {0x06, 0x04, 0x13},
  160. {0x06, 0x02, 0x14},
  161. {0x06, 0x8a, 0x51},
  162. {0x06, 0x40, 0x52},
  163. {0x06, 0xb6, 0x53},
  164. {0x06, 0x3d, 0x54},
  165. /* End of extra block */
  166. {0x06, 0x3f, 0x1},
  167. /* Block skipped */
  168. {0x06, 0x10, 0x02},
  169. {0x06, 0x64, 0x07},
  170. {0x06, 0x10, 0x08},
  171. {0x06, 0x00, 0x09},
  172. {0x06, 0x00, 0x0a},
  173. {0x06, 0x00, 0x0b},
  174. {0x06, 0x10, 0x0c},
  175. {0x06, 0x00, 0x0d},
  176. {0x06, 0x00, 0x0e},
  177. {0x06, 0x00, 0x0f},
  178. {0x06, 0x10, 0x10},
  179. {0x06, 0x02, 0x11},
  180. {0x06, 0x00, 0x12},
  181. {0x06, 0x04, 0x13},
  182. {0x06, 0x02, 0x14},
  183. {0x06, 0x8a, 0x51},
  184. {0x06, 0x40, 0x52},
  185. {0x06, 0xb6, 0x53},
  186. {0x06, 0x3d, 0x54},
  187. {0x06, 0x60, 0x57},
  188. {0x06, 0x20, 0x58},
  189. {0x06, 0x15, 0x59},
  190. {0x06, 0x05, 0x5a},
  191. {0x05, 0x01, 0xc0},
  192. {0x05, 0x10, 0xcb},
  193. {0x05, 0x80, 0xc1},
  194. /* */
  195. {0x05, 0x0, 0xc2},
  196. /* 4 was 0 */
  197. {0x05, 0x00, 0xca},
  198. {0x05, 0x80, 0xc1},
  199. /* */
  200. {0x05, 0x04, 0xc2},
  201. {0x05, 0x00, 0xca},
  202. {0x05, 0x0, 0xc1},
  203. /* */
  204. {0x05, 0x00, 0xc2},
  205. {0x05, 0x00, 0xca},
  206. {0x05, 0x40, 0xc1},
  207. /* */
  208. {0x05, 0x17, 0xc2},
  209. {0x05, 0x00, 0xca},
  210. {0x05, 0x80, 0xc1},
  211. /* */
  212. {0x05, 0x06, 0xc2},
  213. {0x05, 0x00, 0xca},
  214. {0x05, 0x80, 0xc1},
  215. /* */
  216. {0x05, 0x04, 0xc2},
  217. {0x05, 0x00, 0xca},
  218. {0x03, 0x4c, 0x3},
  219. {0x03, 0x18, 0x1},
  220. {0x06, 0x70, 0x51},
  221. {0x06, 0xbe, 0x53},
  222. {0x06, 0x71, 0x57},
  223. {0x06, 0x20, 0x58},
  224. {0x06, 0x05, 0x59},
  225. {0x06, 0x15, 0x5a},
  226. {0x04, 0x00, 0x08},
  227. /* Compress = OFF (0x1 to turn on) */
  228. {0x04, 0x12, 0x09},
  229. {0x04, 0x21, 0x0a},
  230. {0x04, 0x10, 0x0b},
  231. {0x04, 0x21, 0x0c},
  232. {0x04, 0x05, 0x00},
  233. /* was 5 (Image Type ? ) */
  234. {0x04, 0x00, 0x01},
  235. {0x06, 0x3f, 0x01},
  236. {0x04, 0x00, 0x04},
  237. {0x04, 0x00, 0x05},
  238. {0x04, 0x40, 0x06},
  239. {0x04, 0x40, 0x07},
  240. {0x06, 0x1c, 0x17},
  241. {0x06, 0xe2, 0x19},
  242. {0x06, 0x1c, 0x1b},
  243. {0x06, 0xe2, 0x1d},
  244. {0x06, 0xaa, 0x1f},
  245. {0x06, 0x70, 0x20},
  246. {0x05, 0x01, 0x10},
  247. {0x05, 0x00, 0x11},
  248. {0x05, 0x01, 0x00},
  249. {0x05, 0x05, 0x01},
  250. {0x05, 0x00, 0xc1},
  251. /* */
  252. {0x05, 0x00, 0xc2},
  253. {0x05, 0x00, 0xca},
  254. {0x06, 0x70, 0x51},
  255. {0x06, 0xbe, 0x53},
  256. {}
  257. };
  258. /*
  259. * Made by Tomasz Zablocki (skalamandra@poczta.onet.pl)
  260. * SPCA505b chip based cameras initialization data
  261. */
  262. /* jfm */
  263. #define initial_brightness 0x7f /* 0x0(white)-0xff(black) */
  264. /* #define initial_brightness 0x0 //0x0(white)-0xff(black) */
  265. /*
  266. * Data to initialize a SPCA505. Common to the CCD and external modes
  267. */
  268. static const u8 spca505b_init_data[][3] = {
  269. /* start */
  270. {0x02, 0x00, 0x00}, /* init */
  271. {0x02, 0x00, 0x01},
  272. {0x02, 0x00, 0x02},
  273. {0x02, 0x00, 0x03},
  274. {0x02, 0x00, 0x04},
  275. {0x02, 0x00, 0x05},
  276. {0x02, 0x00, 0x06},
  277. {0x02, 0x00, 0x07},
  278. {0x02, 0x00, 0x08},
  279. {0x02, 0x00, 0x09},
  280. {0x03, 0x00, 0x00},
  281. {0x03, 0x00, 0x01},
  282. {0x03, 0x00, 0x02},
  283. {0x03, 0x00, 0x03},
  284. {0x03, 0x00, 0x04},
  285. {0x03, 0x00, 0x05},
  286. {0x03, 0x00, 0x06},
  287. {0x04, 0x00, 0x00},
  288. {0x04, 0x00, 0x02},
  289. {0x04, 0x00, 0x04},
  290. {0x04, 0x00, 0x05},
  291. {0x04, 0x00, 0x06},
  292. {0x04, 0x00, 0x07},
  293. {0x04, 0x00, 0x08},
  294. {0x04, 0x00, 0x09},
  295. {0x04, 0x00, 0x0a},
  296. {0x04, 0x00, 0x0b},
  297. {0x04, 0x00, 0x0c},
  298. {0x07, 0x00, 0x00},
  299. {0x07, 0x00, 0x03},
  300. {0x08, 0x00, 0x00},
  301. {0x08, 0x00, 0x01},
  302. {0x08, 0x00, 0x02},
  303. {0x06, 0x18, 0x08},
  304. {0x06, 0xfc, 0x09},
  305. {0x06, 0xfc, 0x0a},
  306. {0x06, 0xfc, 0x0b},
  307. {0x06, 0x18, 0x0c},
  308. {0x06, 0xfc, 0x0d},
  309. {0x06, 0xfc, 0x0e},
  310. {0x06, 0xfc, 0x0f},
  311. {0x06, 0x18, 0x10},
  312. {0x06, 0xfe, 0x12},
  313. {0x06, 0x00, 0x11},
  314. {0x06, 0x00, 0x14},
  315. {0x06, 0x00, 0x13},
  316. {0x06, 0x28, 0x51},
  317. {0x06, 0xff, 0x53},
  318. {0x02, 0x00, 0x08},
  319. {0x03, 0x00, 0x03},
  320. {0x03, 0x10, 0x03},
  321. {}
  322. };
  323. /*
  324. * Data to initialize the camera using the internal CCD
  325. */
  326. static const u8 spca505b_open_data_ccd[][3] = {
  327. /* {0x02,0x00,0x00}, */
  328. {0x03, 0x04, 0x01}, /* rst */
  329. {0x03, 0x00, 0x01},
  330. {0x03, 0x00, 0x00},
  331. {0x03, 0x21, 0x00},
  332. {0x03, 0x00, 0x04},
  333. {0x03, 0x00, 0x03},
  334. {0x03, 0x18, 0x03},
  335. {0x03, 0x08, 0x01},
  336. {0x03, 0x1c, 0x03},
  337. {0x03, 0x5c, 0x03},
  338. {0x03, 0x5c, 0x03},
  339. {0x03, 0x18, 0x01},
  340. /* same as 505 */
  341. {0x04, 0x10, 0x01},
  342. {0x04, 0x00, 0x04},
  343. {0x04, 0x00, 0x05},
  344. {0x04, 0x20, 0x06},
  345. {0x04, 0x20, 0x07},
  346. {0x08, 0x0a, 0x00},
  347. {0x05, 0x00, 0x10},
  348. {0x05, 0x00, 0x11},
  349. {0x05, 0x00, 0x12},
  350. {0x05, 0x6f, 0x00},
  351. {0x05, initial_brightness >> 6, 0x00},
  352. {0x05, (initial_brightness << 2) & 0xff, 0x01},
  353. {0x05, 0x00, 0x02},
  354. {0x05, 0x01, 0x03},
  355. {0x05, 0x00, 0x04},
  356. {0x05, 0x03, 0x05},
  357. {0x05, 0xe0, 0x06},
  358. {0x05, 0x20, 0x07},
  359. {0x05, 0xa0, 0x08},
  360. {0x05, 0x00, 0x12},
  361. {0x05, 0x02, 0x0f},
  362. {0x05, 0x80, 0x14}, /* max exposure off (0=on) */
  363. {0x05, 0x01, 0xb0},
  364. {0x05, 0x01, 0xbf},
  365. {0x03, 0x02, 0x06},
  366. {0x05, 0x10, 0x46},
  367. {0x05, 0x08, 0x4a},
  368. {0x06, 0x00, 0x01},
  369. {0x06, 0x10, 0x02},
  370. {0x06, 0x64, 0x07},
  371. {0x06, 0x18, 0x08},
  372. {0x06, 0xfc, 0x09},
  373. {0x06, 0xfc, 0x0a},
  374. {0x06, 0xfc, 0x0b},
  375. {0x04, 0x00, 0x01},
  376. {0x06, 0x18, 0x0c},
  377. {0x06, 0xfc, 0x0d},
  378. {0x06, 0xfc, 0x0e},
  379. {0x06, 0xfc, 0x0f},
  380. {0x06, 0x11, 0x10}, /* contrast */
  381. {0x06, 0x00, 0x11},
  382. {0x06, 0xfe, 0x12},
  383. {0x06, 0x00, 0x13},
  384. {0x06, 0x00, 0x14},
  385. {0x06, 0x9d, 0x51},
  386. {0x06, 0x40, 0x52},
  387. {0x06, 0x7c, 0x53},
  388. {0x06, 0x40, 0x54},
  389. {0x06, 0x02, 0x57},
  390. {0x06, 0x03, 0x58},
  391. {0x06, 0x15, 0x59},
  392. {0x06, 0x05, 0x5a},
  393. {0x06, 0x03, 0x56},
  394. {0x06, 0x02, 0x3f},
  395. {0x06, 0x00, 0x40},
  396. {0x06, 0x39, 0x41},
  397. {0x06, 0x69, 0x42},
  398. {0x06, 0x87, 0x43},
  399. {0x06, 0x9e, 0x44},
  400. {0x06, 0xb1, 0x45},
  401. {0x06, 0xbf, 0x46},
  402. {0x06, 0xcc, 0x47},
  403. {0x06, 0xd5, 0x48},
  404. {0x06, 0xdd, 0x49},
  405. {0x06, 0xe3, 0x4a},
  406. {0x06, 0xe8, 0x4b},
  407. {0x06, 0xed, 0x4c},
  408. {0x06, 0xf2, 0x4d},
  409. {0x06, 0xf7, 0x4e},
  410. {0x06, 0xfc, 0x4f},
  411. {0x06, 0xff, 0x50},
  412. {0x05, 0x01, 0xc0},
  413. {0x05, 0x10, 0xcb},
  414. {0x05, 0x40, 0xc1},
  415. {0x05, 0x04, 0xc2},
  416. {0x05, 0x00, 0xca},
  417. {0x05, 0x40, 0xc1},
  418. {0x05, 0x09, 0xc2},
  419. {0x05, 0x00, 0xca},
  420. {0x05, 0xc0, 0xc1},
  421. {0x05, 0x09, 0xc2},
  422. {0x05, 0x00, 0xca},
  423. {0x05, 0x40, 0xc1},
  424. {0x05, 0x59, 0xc2},
  425. {0x05, 0x00, 0xca},
  426. {0x04, 0x00, 0x01},
  427. {0x05, 0x80, 0xc1},
  428. {0x05, 0xec, 0xc2},
  429. {0x05, 0x0, 0xca},
  430. {0x06, 0x02, 0x57},
  431. {0x06, 0x01, 0x58},
  432. {0x06, 0x15, 0x59},
  433. {0x06, 0x0a, 0x5a},
  434. {0x06, 0x01, 0x57},
  435. {0x06, 0x8a, 0x03},
  436. {0x06, 0x0a, 0x6c},
  437. {0x06, 0x30, 0x01},
  438. {0x06, 0x20, 0x02},
  439. {0x06, 0x00, 0x03},
  440. {0x05, 0x8c, 0x25},
  441. {0x06, 0x4d, 0x51}, /* maybe saturation (4d) */
  442. {0x06, 0x84, 0x53}, /* making green (84) */
  443. {0x06, 0x00, 0x57}, /* sharpness (1) */
  444. {0x06, 0x18, 0x08},
  445. {0x06, 0xfc, 0x09},
  446. {0x06, 0xfc, 0x0a},
  447. {0x06, 0xfc, 0x0b},
  448. {0x06, 0x18, 0x0c}, /* maybe hue (18) */
  449. {0x06, 0xfc, 0x0d},
  450. {0x06, 0xfc, 0x0e},
  451. {0x06, 0xfc, 0x0f},
  452. {0x06, 0x18, 0x10}, /* maybe contrast (18) */
  453. {0x05, 0x01, 0x02},
  454. {0x04, 0x00, 0x08}, /* compression */
  455. {0x04, 0x12, 0x09},
  456. {0x04, 0x21, 0x0a},
  457. {0x04, 0x10, 0x0b},
  458. {0x04, 0x21, 0x0c},
  459. {0x04, 0x1d, 0x00}, /* imagetype (1d) */
  460. {0x04, 0x41, 0x01}, /* hardware snapcontrol */
  461. {0x04, 0x00, 0x04},
  462. {0x04, 0x00, 0x05},
  463. {0x04, 0x10, 0x06},
  464. {0x04, 0x10, 0x07},
  465. {0x04, 0x40, 0x06},
  466. {0x04, 0x40, 0x07},
  467. {0x04, 0x00, 0x04},
  468. {0x04, 0x00, 0x05},
  469. {0x06, 0x1c, 0x17},
  470. {0x06, 0xe2, 0x19},
  471. {0x06, 0x1c, 0x1b},
  472. {0x06, 0xe2, 0x1d},
  473. {0x06, 0x5f, 0x1f},
  474. {0x06, 0x32, 0x20},
  475. {0x05, initial_brightness >> 6, 0x00},
  476. {0x05, (initial_brightness << 2) & 0xff, 0x01},
  477. {0x05, 0x06, 0xc1},
  478. {0x05, 0x58, 0xc2},
  479. {0x05, 0x00, 0xca},
  480. {0x05, 0x00, 0x11},
  481. {}
  482. };
  483. static int reg_write(struct gspca_dev *gspca_dev,
  484. u16 req, u16 index, u16 value)
  485. {
  486. int ret;
  487. struct usb_device *dev = gspca_dev->dev;
  488. ret = usb_control_msg(dev,
  489. usb_sndctrlpipe(dev, 0),
  490. req,
  491. USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  492. value, index, NULL, 0, 500);
  493. gspca_dbg(gspca_dev, D_USBO, "reg write: 0x%02x,0x%02x:0x%02x, %d\n",
  494. req, index, value, ret);
  495. if (ret < 0)
  496. pr_err("reg write: error %d\n", ret);
  497. return ret;
  498. }
  499. /* returns: negative is error, pos or zero is data */
  500. static int reg_read(struct gspca_dev *gspca_dev,
  501. u16 req, /* bRequest */
  502. u16 index) /* wIndex */
  503. {
  504. int ret;
  505. ret = usb_control_msg(gspca_dev->dev,
  506. usb_rcvctrlpipe(gspca_dev->dev, 0),
  507. req,
  508. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  509. 0, /* value */
  510. index,
  511. gspca_dev->usb_buf, 2,
  512. 500); /* timeout */
  513. if (ret < 0)
  514. return ret;
  515. return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
  516. }
  517. static int write_vector(struct gspca_dev *gspca_dev,
  518. const u8 data[][3])
  519. {
  520. int ret, i = 0;
  521. while (data[i][0] != 0) {
  522. ret = reg_write(gspca_dev, data[i][0], data[i][2],
  523. data[i][1]);
  524. if (ret < 0)
  525. return ret;
  526. i++;
  527. }
  528. return 0;
  529. }
  530. /* this function is called at probe time */
  531. static int sd_config(struct gspca_dev *gspca_dev,
  532. const struct usb_device_id *id)
  533. {
  534. struct sd *sd = (struct sd *) gspca_dev;
  535. struct cam *cam;
  536. cam = &gspca_dev->cam;
  537. cam->cam_mode = vga_mode;
  538. sd->subtype = id->driver_info;
  539. if (sd->subtype != IntelPCCameraPro)
  540. cam->nmodes = ARRAY_SIZE(vga_mode);
  541. else /* no 640x480 for IntelPCCameraPro */
  542. cam->nmodes = ARRAY_SIZE(vga_mode) - 1;
  543. return 0;
  544. }
  545. /* this function is called at probe and resume time */
  546. static int sd_init(struct gspca_dev *gspca_dev)
  547. {
  548. struct sd *sd = (struct sd *) gspca_dev;
  549. if (write_vector(gspca_dev,
  550. sd->subtype == Nxultra
  551. ? spca505b_init_data
  552. : spca505_init_data))
  553. return -EIO;
  554. return 0;
  555. }
  556. static void setbrightness(struct gspca_dev *gspca_dev, s32 brightness)
  557. {
  558. reg_write(gspca_dev, 0x05, 0x00, (255 - brightness) >> 6);
  559. reg_write(gspca_dev, 0x05, 0x01, (255 - brightness) << 2);
  560. }
  561. static int sd_start(struct gspca_dev *gspca_dev)
  562. {
  563. struct sd *sd = (struct sd *) gspca_dev;
  564. int ret, mode;
  565. static u8 mode_tb[][3] = {
  566. /* r00 r06 r07 */
  567. {0x00, 0x10, 0x10}, /* 640x480 */
  568. {0x01, 0x1a, 0x1a}, /* 352x288 */
  569. {0x02, 0x1c, 0x1d}, /* 320x240 */
  570. {0x04, 0x34, 0x34}, /* 176x144 */
  571. {0x05, 0x40, 0x40} /* 160x120 */
  572. };
  573. if (sd->subtype == Nxultra)
  574. write_vector(gspca_dev, spca505b_open_data_ccd);
  575. else
  576. write_vector(gspca_dev, spca505_open_data_ccd);
  577. ret = reg_read(gspca_dev, 0x06, 0x16);
  578. if (ret < 0) {
  579. gspca_err(gspca_dev, "register read failed err: %d\n", ret);
  580. return ret;
  581. }
  582. if (ret != 0x0101) {
  583. pr_err("After vector read returns 0x%04x should be 0x0101\n",
  584. ret);
  585. }
  586. ret = reg_write(gspca_dev, 0x06, 0x16, 0x0a);
  587. if (ret < 0)
  588. return ret;
  589. reg_write(gspca_dev, 0x05, 0xc2, 0x12);
  590. /* necessary because without it we can see stream
  591. * only once after loading module */
  592. /* stopping usb registers Tomasz change */
  593. reg_write(gspca_dev, 0x02, 0x00, 0x00);
  594. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  595. reg_write(gspca_dev, SPCA50X_REG_COMPRESS, 0x00, mode_tb[mode][0]);
  596. reg_write(gspca_dev, SPCA50X_REG_COMPRESS, 0x06, mode_tb[mode][1]);
  597. reg_write(gspca_dev, SPCA50X_REG_COMPRESS, 0x07, mode_tb[mode][2]);
  598. return reg_write(gspca_dev, SPCA50X_REG_USB,
  599. SPCA50X_USB_CTRL,
  600. SPCA50X_CUSB_ENABLE);
  601. }
  602. static void sd_stopN(struct gspca_dev *gspca_dev)
  603. {
  604. /* Disable ISO packet machine */
  605. reg_write(gspca_dev, 0x02, 0x00, 0x00);
  606. }
  607. /* called on streamoff with alt 0 and on disconnect */
  608. static void sd_stop0(struct gspca_dev *gspca_dev)
  609. {
  610. if (!gspca_dev->present)
  611. return;
  612. /* This maybe reset or power control */
  613. reg_write(gspca_dev, 0x03, 0x03, 0x20);
  614. reg_write(gspca_dev, 0x03, 0x01, 0x00);
  615. reg_write(gspca_dev, 0x03, 0x00, 0x01);
  616. reg_write(gspca_dev, 0x05, 0x10, 0x01);
  617. reg_write(gspca_dev, 0x05, 0x11, 0x0f);
  618. }
  619. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  620. u8 *data, /* isoc packet */
  621. int len) /* iso packet length */
  622. {
  623. switch (data[0]) {
  624. case 0: /* start of frame */
  625. gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
  626. data += SPCA50X_OFFSET_DATA;
  627. len -= SPCA50X_OFFSET_DATA;
  628. gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
  629. break;
  630. case 0xff: /* drop */
  631. break;
  632. default:
  633. data += 1;
  634. len -= 1;
  635. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  636. break;
  637. }
  638. }
  639. static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
  640. {
  641. struct gspca_dev *gspca_dev =
  642. container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
  643. gspca_dev->usb_err = 0;
  644. if (!gspca_dev->streaming)
  645. return 0;
  646. switch (ctrl->id) {
  647. case V4L2_CID_BRIGHTNESS:
  648. setbrightness(gspca_dev, ctrl->val);
  649. break;
  650. }
  651. return gspca_dev->usb_err;
  652. }
  653. static const struct v4l2_ctrl_ops sd_ctrl_ops = {
  654. .s_ctrl = sd_s_ctrl,
  655. };
  656. static int sd_init_controls(struct gspca_dev *gspca_dev)
  657. {
  658. struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
  659. gspca_dev->vdev.ctrl_handler = hdl;
  660. v4l2_ctrl_handler_init(hdl, 5);
  661. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  662. V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
  663. if (hdl->error) {
  664. pr_err("Could not initialize controls\n");
  665. return hdl->error;
  666. }
  667. return 0;
  668. }
  669. /* sub-driver description */
  670. static const struct sd_desc sd_desc = {
  671. .name = MODULE_NAME,
  672. .config = sd_config,
  673. .init_controls = sd_init_controls,
  674. .init = sd_init,
  675. .start = sd_start,
  676. .stopN = sd_stopN,
  677. .stop0 = sd_stop0,
  678. .pkt_scan = sd_pkt_scan,
  679. };
  680. /* -- module initialisation -- */
  681. static const struct usb_device_id device_table[] = {
  682. {USB_DEVICE(0x041e, 0x401d), .driver_info = Nxultra},
  683. {USB_DEVICE(0x0733, 0x0430), .driver_info = IntelPCCameraPro},
  684. /*fixme: may be UsbGrabberPV321 BRIDGE_SPCA506 SENSOR_SAA7113 */
  685. {}
  686. };
  687. MODULE_DEVICE_TABLE(usb, device_table);
  688. /* -- device connect -- */
  689. static int sd_probe(struct usb_interface *intf,
  690. const struct usb_device_id *id)
  691. {
  692. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  693. THIS_MODULE);
  694. }
  695. static struct usb_driver sd_driver = {
  696. .name = MODULE_NAME,
  697. .id_table = device_table,
  698. .probe = sd_probe,
  699. .disconnect = gspca_disconnect,
  700. #ifdef CONFIG_PM
  701. .suspend = gspca_suspend,
  702. .resume = gspca_resume,
  703. .reset_resume = gspca_resume,
  704. #endif
  705. };
  706. module_usb_driver(sd_driver);