spca505.c 18 KB

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