spca505.c 19 KB

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