spca505.c 18 KB

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