spca505.c 19 KB

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