spca505.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  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. unsigned char brightness;
  30. char 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. #define SD_BRIGHTNESS 0
  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. .default_value = 127,
  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 = 5},
  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 = 4},
  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. /*
  91. * Data to initialize a SPCA505. Common to the CCD and external modes
  92. */
  93. static const __u16 spca505_init_data[][3] = {
  94. /* line bmRequest,value,index */
  95. /* 1819 */
  96. {SPCA50X_REG_GLOBAL, SPCA50X_GMISC3_SAA7113RST, SPCA50X_GLOBAL_MISC3},
  97. /* Sensor reset */
  98. /* 1822 */ {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC3},
  99. /* 1825 */ {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC1},
  100. /* Block USB reset */
  101. /* 1828 */ {SPCA50X_REG_GLOBAL, SPCA50X_GMISC0_IDSEL,
  102. SPCA50X_GLOBAL_MISC0},
  103. /* 1831 */ {0x5, 0x01, 0x10},
  104. /* Maybe power down some stuff */
  105. /* 1834 */ {0x5, 0x0f, 0x11},
  106. /* Setup internal CCD ? */
  107. /* 1837 */ {0x6, 0x10, 0x08},
  108. /* 1840 */ {0x6, 0x00, 0x09},
  109. /* 1843 */ {0x6, 0x00, 0x0a},
  110. /* 1846 */ {0x6, 0x00, 0x0b},
  111. /* 1849 */ {0x6, 0x10, 0x0c},
  112. /* 1852 */ {0x6, 0x00, 0x0d},
  113. /* 1855 */ {0x6, 0x00, 0x0e},
  114. /* 1858 */ {0x6, 0x00, 0x0f},
  115. /* 1861 */ {0x6, 0x10, 0x10},
  116. /* 1864 */ {0x6, 0x02, 0x11},
  117. /* 1867 */ {0x6, 0x00, 0x12},
  118. /* 1870 */ {0x6, 0x04, 0x13},
  119. /* 1873 */ {0x6, 0x02, 0x14},
  120. /* 1876 */ {0x6, 0x8a, 0x51},
  121. /* 1879 */ {0x6, 0x40, 0x52},
  122. /* 1882 */ {0x6, 0xb6, 0x53},
  123. /* 1885 */ {0x6, 0x3d, 0x54},
  124. {}
  125. };
  126. /*
  127. * Data to initialize the camera using the internal CCD
  128. */
  129. static const __u16 spca505_open_data_ccd[][3] = {
  130. /* line bmRequest,value,index */
  131. /* Internal CCD data set */
  132. /* 1891 */ {0x3, 0x04, 0x01},
  133. /* This could be a reset */
  134. /* 1894 */ {0x3, 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. /* 1897 */ {0x4, 0x10, 0x01},
  138. /* DIFF(0x50), was (0x10) */
  139. /* 1900 */ {0x4, 0x00, 0x04},
  140. /* 1903 */ {0x4, 0x00, 0x05},
  141. /* 1906 */ {0x4, 0x20, 0x06},
  142. /* 1909 */ {0x4, 0x20, 0x07},
  143. /* 1912 */ {0x8, 0x0a, 0x00},
  144. /* DIFF (0x4a), was (0xa) */
  145. /* 1915 */ {0x5, 0x00, 0x10},
  146. /* 1918 */ {0x5, 0x00, 0x11},
  147. /* 1921 */ {0x5, 0x00, 0x00},
  148. /* DIFF not written */
  149. /* 1924 */ {0x5, 0x00, 0x01},
  150. /* DIFF not written */
  151. /* 1927 */ {0x5, 0x00, 0x02},
  152. /* DIFF not written */
  153. /* 1930 */ {0x5, 0x00, 0x03},
  154. /* DIFF not written */
  155. /* 1933 */ {0x5, 0x00, 0x04},
  156. /* DIFF not written */
  157. /* 1936 */ {0x5, 0x80, 0x05},
  158. /* DIFF not written */
  159. /* 1939 */ {0x5, 0xe0, 0x06},
  160. /* DIFF not written */
  161. /* 1942 */ {0x5, 0x20, 0x07},
  162. /* DIFF not written */
  163. /* 1945 */ {0x5, 0xa0, 0x08},
  164. /* DIFF not written */
  165. /* 1948 */ {0x5, 0x0, 0x12},
  166. /* DIFF not written */
  167. /* 1951 */ {0x5, 0x02, 0x0f},
  168. /* DIFF not written */
  169. /* 1954 */ {0x5, 0x10, 0x46},
  170. /* DIFF not written */
  171. /* 1957 */ {0x5, 0x8, 0x4a},
  172. /* DIFF not written */
  173. /* 1960 */ {0x3, 0x08, 0x03},
  174. /* DIFF (0x3,0x28,0x3) */
  175. /* 1963 */ {0x3, 0x08, 0x01},
  176. /* 1966 */ {0x3, 0x0c, 0x03},
  177. /* DIFF not written */
  178. /* 1969 */ {0x3, 0x21, 0x00},
  179. /* DIFF (0x39) */
  180. /* Extra block copied from init to hopefully ensure CCD is in a sane state */
  181. /* 1837 */ {0x6, 0x10, 0x08},
  182. /* 1840 */ {0x6, 0x00, 0x09},
  183. /* 1843 */ {0x6, 0x00, 0x0a},
  184. /* 1846 */ {0x6, 0x00, 0x0b},
  185. /* 1849 */ {0x6, 0x10, 0x0c},
  186. /* 1852 */ {0x6, 0x00, 0x0d},
  187. /* 1855 */ {0x6, 0x00, 0x0e},
  188. /* 1858 */ {0x6, 0x00, 0x0f},
  189. /* 1861 */ {0x6, 0x10, 0x10},
  190. /* 1864 */ {0x6, 0x02, 0x11},
  191. /* 1867 */ {0x6, 0x00, 0x12},
  192. /* 1870 */ {0x6, 0x04, 0x13},
  193. /* 1873 */ {0x6, 0x02, 0x14},
  194. /* 1876 */ {0x6, 0x8a, 0x51},
  195. /* 1879 */ {0x6, 0x40, 0x52},
  196. /* 1882 */ {0x6, 0xb6, 0x53},
  197. /* 1885 */ {0x6, 0x3d, 0x54},
  198. /* End of extra block */
  199. /* 1972 */ {0x6, 0x3f, 0x1},
  200. /* Block skipped */
  201. /* 1975 */ {0x6, 0x10, 0x02},
  202. /* 1978 */ {0x6, 0x64, 0x07},
  203. /* 1981 */ {0x6, 0x10, 0x08},
  204. /* 1984 */ {0x6, 0x00, 0x09},
  205. /* 1987 */ {0x6, 0x00, 0x0a},
  206. /* 1990 */ {0x6, 0x00, 0x0b},
  207. /* 1993 */ {0x6, 0x10, 0x0c},
  208. /* 1996 */ {0x6, 0x00, 0x0d},
  209. /* 1999 */ {0x6, 0x00, 0x0e},
  210. /* 2002 */ {0x6, 0x00, 0x0f},
  211. /* 2005 */ {0x6, 0x10, 0x10},
  212. /* 2008 */ {0x6, 0x02, 0x11},
  213. /* 2011 */ {0x6, 0x00, 0x12},
  214. /* 2014 */ {0x6, 0x04, 0x13},
  215. /* 2017 */ {0x6, 0x02, 0x14},
  216. /* 2020 */ {0x6, 0x8a, 0x51},
  217. /* 2023 */ {0x6, 0x40, 0x52},
  218. /* 2026 */ {0x6, 0xb6, 0x53},
  219. /* 2029 */ {0x6, 0x3d, 0x54},
  220. /* 2032 */ {0x6, 0x60, 0x57},
  221. /* 2035 */ {0x6, 0x20, 0x58},
  222. /* 2038 */ {0x6, 0x15, 0x59},
  223. /* 2041 */ {0x6, 0x05, 0x5a},
  224. /* 2044 */ {0x5, 0x01, 0xc0},
  225. /* 2047 */ {0x5, 0x10, 0xcb},
  226. /* 2050 */ {0x5, 0x80, 0xc1},
  227. /* */
  228. /* 2053 */ {0x5, 0x0, 0xc2},
  229. /* 4 was 0 */
  230. /* 2056 */ {0x5, 0x00, 0xca},
  231. /* 2059 */ {0x5, 0x80, 0xc1},
  232. /* */
  233. /* 2062 */ {0x5, 0x04, 0xc2},
  234. /* 2065 */ {0x5, 0x00, 0xca},
  235. /* 2068 */ {0x5, 0x0, 0xc1},
  236. /* */
  237. /* 2071 */ {0x5, 0x00, 0xc2},
  238. /* 2074 */ {0x5, 0x00, 0xca},
  239. /* 2077 */ {0x5, 0x40, 0xc1},
  240. /* */
  241. /* 2080 */ {0x5, 0x17, 0xc2},
  242. /* 2083 */ {0x5, 0x00, 0xca},
  243. /* 2086 */ {0x5, 0x80, 0xc1},
  244. /* */
  245. /* 2089 */ {0x5, 0x06, 0xc2},
  246. /* 2092 */ {0x5, 0x00, 0xca},
  247. /* 2095 */ {0x5, 0x80, 0xc1},
  248. /* */
  249. /* 2098 */ {0x5, 0x04, 0xc2},
  250. /* 2101 */ {0x5, 0x00, 0xca},
  251. /* 2104 */ {0x3, 0x4c, 0x3},
  252. /* 2107 */ {0x3, 0x18, 0x1},
  253. /* 2110 */ {0x6, 0x70, 0x51},
  254. /* 2113 */ {0x6, 0xbe, 0x53},
  255. /* 2116 */ {0x6, 0x71, 0x57},
  256. /* 2119 */ {0x6, 0x20, 0x58},
  257. /* 2122 */ {0x6, 0x05, 0x59},
  258. /* 2125 */ {0x6, 0x15, 0x5a},
  259. /* 2128 */ {0x4, 0x00, 0x08},
  260. /* Compress = OFF (0x1 to turn on) */
  261. /* 2131 */ {0x4, 0x12, 0x09},
  262. /* 2134 */ {0x4, 0x21, 0x0a},
  263. /* 2137 */ {0x4, 0x10, 0x0b},
  264. /* 2140 */ {0x4, 0x21, 0x0c},
  265. /* 2143 */ {0x4, 0x05, 0x00},
  266. /* was 5 (Image Type ? ) */
  267. /* 2146 */ {0x4, 0x00, 0x01},
  268. /* 2149 */ {0x6, 0x3f, 0x01},
  269. /* 2152 */ {0x4, 0x00, 0x04},
  270. /* 2155 */ {0x4, 0x00, 0x05},
  271. /* 2158 */ {0x4, 0x40, 0x06},
  272. /* 2161 */ {0x4, 0x40, 0x07},
  273. /* 2164 */ {0x6, 0x1c, 0x17},
  274. /* 2167 */ {0x6, 0xe2, 0x19},
  275. /* 2170 */ {0x6, 0x1c, 0x1b},
  276. /* 2173 */ {0x6, 0xe2, 0x1d},
  277. /* 2176 */ {0x6, 0xaa, 0x1f},
  278. /* 2179 */ {0x6, 0x70, 0x20},
  279. /* 2182 */ {0x5, 0x01, 0x10},
  280. /* 2185 */ {0x5, 0x00, 0x11},
  281. /* 2188 */ {0x5, 0x01, 0x00},
  282. /* 2191 */ {0x5, 0x05, 0x01},
  283. /* 2194 */ {0x5, 0x00, 0xc1},
  284. /* */
  285. /* 2197 */ {0x5, 0x00, 0xc2},
  286. /* 2200 */ {0x5, 0x00, 0xca},
  287. /* 2203 */ {0x6, 0x70, 0x51},
  288. /* 2206 */ {0x6, 0xbe, 0x53},
  289. {}
  290. };
  291. /*
  292. Made by Tomasz Zablocki (skalamandra@poczta.onet.pl)
  293. * SPCA505b chip based cameras initialization data
  294. *
  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 __u16 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. {0x00, 0x01, 0x00},
  338. {0x00, 0x01, 0x01},
  339. {0x00, 0x01, 0x34},
  340. {0x00, 0x01, 0x35},
  341. {0x06, 0x18, 0x08},
  342. {0x06, 0xfc, 0x09},
  343. {0x06, 0xfc, 0x0a},
  344. {0x06, 0xfc, 0x0b},
  345. {0x06, 0x18, 0x0c},
  346. {0x06, 0xfc, 0x0d},
  347. {0x06, 0xfc, 0x0e},
  348. {0x06, 0xfc, 0x0f},
  349. {0x06, 0x18, 0x10},
  350. {0x06, 0xfe, 0x12},
  351. {0x06, 0x00, 0x11},
  352. {0x06, 0x00, 0x14},
  353. {0x06, 0x00, 0x13},
  354. {0x06, 0x28, 0x51},
  355. {0x06, 0xff, 0x53},
  356. {0x02, 0x00, 0x08},
  357. {0x03, 0x00, 0x03},
  358. {0x03, 0x10, 0x03},
  359. {}
  360. };
  361. /*
  362. * Data to initialize the camera using the internal CCD
  363. */
  364. static const __u16 spca505b_open_data_ccd[][3] = {
  365. /* {0x02,0x00,0x00}, */
  366. {0x03, 0x04, 0x01}, /* rst */
  367. {0x03, 0x00, 0x01},
  368. {0x03, 0x00, 0x00},
  369. {0x03, 0x21, 0x00},
  370. {0x03, 0x00, 0x04},
  371. {0x03, 0x00, 0x03},
  372. {0x03, 0x18, 0x03},
  373. {0x03, 0x08, 0x01},
  374. {0x03, 0x1c, 0x03},
  375. {0x03, 0x5c, 0x03},
  376. {0x03, 0x5c, 0x03},
  377. {0x03, 0x18, 0x01},
  378. /* same as 505 */
  379. {0x04, 0x10, 0x01},
  380. {0x04, 0x00, 0x04},
  381. {0x04, 0x00, 0x05},
  382. {0x04, 0x20, 0x06},
  383. {0x04, 0x20, 0x07},
  384. {0x08, 0x0a, 0x00},
  385. {0x05, 0x00, 0x10},
  386. {0x05, 0x00, 0x11},
  387. {0x05, 0x00, 0x12},
  388. {0x05, 0x6f, 0x00},
  389. {0x05, initial_brightness >> 6, 0x00},
  390. {0x05, initial_brightness << 2, 0x01},
  391. {0x05, 0x00, 0x02},
  392. {0x05, 0x01, 0x03},
  393. {0x05, 0x00, 0x04},
  394. {0x05, 0x03, 0x05},
  395. {0x05, 0xe0, 0x06},
  396. {0x05, 0x20, 0x07},
  397. {0x05, 0xa0, 0x08},
  398. {0x05, 0x00, 0x12},
  399. {0x05, 0x02, 0x0f},
  400. {0x05, 128, 0x14}, /* max exposure off (0=on) */
  401. {0x05, 0x01, 0xb0},
  402. {0x05, 0x01, 0xbf},
  403. {0x03, 0x02, 0x06},
  404. {0x05, 0x10, 0x46},
  405. {0x05, 0x08, 0x4a},
  406. {0x06, 0x00, 0x01},
  407. {0x06, 0x10, 0x02},
  408. {0x06, 0x64, 0x07},
  409. {0x06, 0x18, 0x08},
  410. {0x06, 0xfc, 0x09},
  411. {0x06, 0xfc, 0x0a},
  412. {0x06, 0xfc, 0x0b},
  413. {0x04, 0x00, 0x01},
  414. {0x06, 0x18, 0x0c},
  415. {0x06, 0xfc, 0x0d},
  416. {0x06, 0xfc, 0x0e},
  417. {0x06, 0xfc, 0x0f},
  418. {0x06, 0x11, 0x10}, /* contrast */
  419. {0x06, 0x00, 0x11},
  420. {0x06, 0xfe, 0x12},
  421. {0x06, 0x00, 0x13},
  422. {0x06, 0x00, 0x14},
  423. {0x06, 0x9d, 0x51},
  424. {0x06, 0x40, 0x52},
  425. {0x06, 0x7c, 0x53},
  426. {0x06, 0x40, 0x54},
  427. {0x06, 0x02, 0x57},
  428. {0x06, 0x03, 0x58},
  429. {0x06, 0x15, 0x59},
  430. {0x06, 0x05, 0x5a},
  431. {0x06, 0x03, 0x56},
  432. {0x06, 0x02, 0x3f},
  433. {0x06, 0x00, 0x40},
  434. {0x06, 0x39, 0x41},
  435. {0x06, 0x69, 0x42},
  436. {0x06, 0x87, 0x43},
  437. {0x06, 0x9e, 0x44},
  438. {0x06, 0xb1, 0x45},
  439. {0x06, 0xbf, 0x46},
  440. {0x06, 0xcc, 0x47},
  441. {0x06, 0xd5, 0x48},
  442. {0x06, 0xdd, 0x49},
  443. {0x06, 0xe3, 0x4a},
  444. {0x06, 0xe8, 0x4b},
  445. {0x06, 0xed, 0x4c},
  446. {0x06, 0xf2, 0x4d},
  447. {0x06, 0xf7, 0x4e},
  448. {0x06, 0xfc, 0x4f},
  449. {0x06, 0xff, 0x50},
  450. {0x05, 0x01, 0xc0},
  451. {0x05, 0x10, 0xcb},
  452. {0x05, 0x40, 0xc1},
  453. {0x05, 0x04, 0xc2},
  454. {0x05, 0x00, 0xca},
  455. {0x05, 0x40, 0xc1},
  456. {0x05, 0x09, 0xc2},
  457. {0x05, 0x00, 0xca},
  458. {0x05, 0xc0, 0xc1},
  459. {0x05, 0x09, 0xc2},
  460. {0x05, 0x00, 0xca},
  461. {0x05, 0x40, 0xc1},
  462. {0x05, 0x59, 0xc2},
  463. {0x05, 0x00, 0xca},
  464. {0x04, 0x00, 0x01},
  465. {0x05, 0x80, 0xc1},
  466. {0x05, 0xec, 0xc2},
  467. {0x05, 0x0, 0xca},
  468. {0x06, 0x02, 0x57},
  469. {0x06, 0x01, 0x58},
  470. {0x06, 0x15, 0x59},
  471. {0x06, 0x0a, 0x5a},
  472. {0x06, 0x01, 0x57},
  473. {0x06, 0x8a, 0x03},
  474. {0x06, 0x0a, 0x6c},
  475. {0x06, 0x30, 0x01},
  476. {0x06, 0x20, 0x02},
  477. {0x06, 0x00, 0x03},
  478. {0x05, 0x8c, 0x25},
  479. {0x06, 0x4d, 0x51}, /* maybe saturation (4d) */
  480. {0x06, 0x84, 0x53}, /* making green (84) */
  481. {0x06, 0x00, 0x57}, /* sharpness (1) */
  482. {0x06, 0x18, 0x08},
  483. {0x06, 0xfc, 0x09},
  484. {0x06, 0xfc, 0x0a},
  485. {0x06, 0xfc, 0x0b},
  486. {0x06, 0x18, 0x0c}, /* maybe hue (18) */
  487. {0x06, 0xfc, 0x0d},
  488. {0x06, 0xfc, 0x0e},
  489. {0x06, 0xfc, 0x0f},
  490. {0x06, 0x18, 0x10}, /* maybe contrast (18) */
  491. {0x05, 0x01, 0x02},
  492. {0x04, 0x00, 0x08}, /* compression */
  493. {0x04, 0x12, 0x09},
  494. {0x04, 0x21, 0x0a},
  495. {0x04, 0x10, 0x0b},
  496. {0x04, 0x21, 0x0c},
  497. {0x04, 0x1d, 0x00}, /* imagetype (1d) */
  498. {0x04, 0x41, 0x01}, /* hardware snapcontrol */
  499. {0x04, 0x00, 0x04},
  500. {0x04, 0x00, 0x05},
  501. {0x04, 0x10, 0x06},
  502. {0x04, 0x10, 0x07},
  503. {0x04, 0x40, 0x06},
  504. {0x04, 0x40, 0x07},
  505. {0x04, 0x00, 0x04},
  506. {0x04, 0x00, 0x05},
  507. {0x06, 0x1c, 0x17},
  508. {0x06, 0xe2, 0x19},
  509. {0x06, 0x1c, 0x1b},
  510. {0x06, 0xe2, 0x1d},
  511. {0x06, 0x5f, 0x1f},
  512. {0x06, 0x32, 0x20},
  513. {0x05, initial_brightness >> 6, 0x00},
  514. {0x05, initial_brightness << 2, 0x01},
  515. {0x05, 0x06, 0xc1},
  516. {0x05, 0x58, 0xc2},
  517. {0x05, 0x0, 0xca},
  518. {0x05, 0x0, 0x11},
  519. {}
  520. };
  521. static int reg_write(struct usb_device *dev,
  522. __u16 reg, __u16 index, __u16 value)
  523. {
  524. int ret;
  525. ret = usb_control_msg(dev,
  526. usb_sndctrlpipe(dev, 0),
  527. reg,
  528. USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  529. value, index, NULL, 0, 500);
  530. PDEBUG(D_PACK, "reg write: 0x%02x,0x%02x:0x%02x, 0x%x",
  531. reg, index, value, ret);
  532. if (ret < 0)
  533. PDEBUG(D_ERR, "reg write: error %d", ret);
  534. return ret;
  535. }
  536. /* returns: negative is error, pos or zero is data */
  537. static int reg_read(struct gspca_dev *gspca_dev,
  538. __u16 reg, /* bRequest */
  539. __u16 index, /* wIndex */
  540. __u16 length) /* wLength (1 or 2 only) */
  541. {
  542. int ret;
  543. gspca_dev->usb_buf[1] = 0;
  544. ret = usb_control_msg(gspca_dev->dev,
  545. usb_rcvctrlpipe(gspca_dev->dev, 0),
  546. reg,
  547. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  548. (__u16) 0, /* value */
  549. (__u16) index,
  550. gspca_dev->usb_buf, length,
  551. 500); /* timeout */
  552. if (ret < 0) {
  553. PDEBUG(D_ERR, "reg_read err %d", ret);
  554. return -1;
  555. }
  556. return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
  557. }
  558. static int write_vector(struct gspca_dev *gspca_dev,
  559. const __u16 data[][3])
  560. {
  561. struct usb_device *dev = gspca_dev->dev;
  562. int ret, i = 0;
  563. while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) {
  564. ret = reg_write(dev, data[i][0], data[i][2], data[i][1]);
  565. if (ret < 0) {
  566. PDEBUG(D_ERR,
  567. "Register write failed for 0x%x,0x%x,0x%x",
  568. data[i][0], data[i][1], data[i][2]);
  569. return ret;
  570. }
  571. i++;
  572. }
  573. return 0;
  574. }
  575. /* this function is called at probe time */
  576. static int sd_config(struct gspca_dev *gspca_dev,
  577. const struct usb_device_id *id)
  578. {
  579. struct sd *sd = (struct sd *) gspca_dev;
  580. struct cam *cam;
  581. cam = &gspca_dev->cam;
  582. cam->epaddr = 0x01;
  583. cam->cam_mode = vga_mode;
  584. sd->subtype = id->driver_info;
  585. if (sd->subtype != IntelPCCameraPro)
  586. cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
  587. else /* no 640x480 for IntelPCCameraPro */
  588. cam->nmodes = sizeof vga_mode / sizeof vga_mode[0] - 1;
  589. sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
  590. if (sd->subtype == Nxultra) {
  591. if (write_vector(gspca_dev, spca505b_init_data))
  592. return -EIO;
  593. } else {
  594. if (write_vector(gspca_dev, spca505_init_data))
  595. return -EIO;
  596. }
  597. return 0;
  598. }
  599. /* this function is called at probe and resume time */
  600. static int sd_init(struct gspca_dev *gspca_dev)
  601. {
  602. struct sd *sd = (struct sd *) gspca_dev;
  603. int ret;
  604. PDEBUG(D_STREAM, "Initializing SPCA505");
  605. if (sd->subtype == Nxultra)
  606. write_vector(gspca_dev, spca505b_open_data_ccd);
  607. else
  608. write_vector(gspca_dev, spca505_open_data_ccd);
  609. ret = reg_read(gspca_dev, 6, 0x16, 2);
  610. if (ret < 0) {
  611. PDEBUG(D_ERR|D_STREAM,
  612. "register read failed for after vector read err = %d",
  613. ret);
  614. return -EIO;
  615. }
  616. PDEBUG(D_STREAM,
  617. "After vector read returns : 0x%x should be 0x0101",
  618. ret & 0xffff);
  619. ret = reg_write(gspca_dev->dev, 6, 0x16, 0x0a);
  620. if (ret < 0) {
  621. PDEBUG(D_ERR, "register write failed for (6,0xa,0x16) err=%d",
  622. ret);
  623. return -EIO;
  624. }
  625. reg_write(gspca_dev->dev, 5, 0xc2, 18);
  626. return 0;
  627. }
  628. static int sd_start(struct gspca_dev *gspca_dev)
  629. {
  630. struct usb_device *dev = gspca_dev->dev;
  631. int ret;
  632. /* necessary because without it we can see stream
  633. * only once after loading module */
  634. /* stopping usb registers Tomasz change */
  635. reg_write(dev, 0x02, 0x0, 0x0);
  636. switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
  637. case 0:
  638. reg_write(dev, 0x04, 0x00, 0x00);
  639. reg_write(dev, 0x04, 0x06, 0x10);
  640. reg_write(dev, 0x04, 0x07, 0x10);
  641. break;
  642. case 1:
  643. reg_write(dev, 0x04, 0x00, 0x01);
  644. reg_write(dev, 0x04, 0x06, 0x1a);
  645. reg_write(dev, 0x04, 0x07, 0x1a);
  646. break;
  647. case 2:
  648. reg_write(dev, 0x04, 0x00, 0x02);
  649. reg_write(dev, 0x04, 0x06, 0x1c);
  650. reg_write(dev, 0x04, 0x07, 0x1d);
  651. break;
  652. case 4:
  653. reg_write(dev, 0x04, 0x00, 0x04);
  654. reg_write(dev, 0x04, 0x06, 0x34);
  655. reg_write(dev, 0x04, 0x07, 0x34);
  656. break;
  657. default:
  658. /* case 5: */
  659. reg_write(dev, 0x04, 0x00, 0x05);
  660. reg_write(dev, 0x04, 0x06, 0x40);
  661. reg_write(dev, 0x04, 0x07, 0x40);
  662. break;
  663. }
  664. /* Enable ISO packet machine - should we do this here or in ISOC init ? */
  665. ret = reg_write(dev, SPCA50X_REG_USB,
  666. SPCA50X_USB_CTRL,
  667. SPCA50X_CUSB_ENABLE);
  668. /* reg_write(dev, 0x5, 0x0, 0x0); */
  669. /* reg_write(dev, 0x5, 0x0, 0x1); */
  670. /* reg_write(dev, 0x5, 0x11, 0x2); */
  671. return ret;
  672. }
  673. static void sd_stopN(struct gspca_dev *gspca_dev)
  674. {
  675. /* Disable ISO packet machine */
  676. reg_write(gspca_dev->dev, 0x02, 0x00, 0x00);
  677. }
  678. /* called on streamoff with alt 0 and on disconnect */
  679. static void sd_stop0(struct gspca_dev *gspca_dev)
  680. {
  681. if (!gspca_dev->present)
  682. return;
  683. /* This maybe reset or power control */
  684. reg_write(gspca_dev->dev, 0x03, 0x03, 0x20);
  685. reg_write(gspca_dev->dev, 0x03, 0x01, 0x0);
  686. reg_write(gspca_dev->dev, 0x03, 0x00, 0x1);
  687. reg_write(gspca_dev->dev, 0x05, 0x10, 0x1);
  688. reg_write(gspca_dev->dev, 0x05, 0x11, 0xf);
  689. }
  690. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  691. struct gspca_frame *frame, /* target */
  692. __u8 *data, /* isoc packet */
  693. int len) /* iso packet length */
  694. {
  695. switch (data[0]) {
  696. case 0: /* start of frame */
  697. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  698. data, 0);
  699. data += SPCA50X_OFFSET_DATA;
  700. len -= SPCA50X_OFFSET_DATA;
  701. gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
  702. data, len);
  703. break;
  704. case 0xff: /* drop */
  705. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  706. break;
  707. default:
  708. data += 1;
  709. len -= 1;
  710. gspca_frame_add(gspca_dev, INTER_PACKET, frame,
  711. data, len);
  712. break;
  713. }
  714. }
  715. static void setbrightness(struct gspca_dev *gspca_dev)
  716. {
  717. struct sd *sd = (struct sd *) gspca_dev;
  718. __u8 brightness = sd->brightness;
  719. reg_write(gspca_dev->dev, 5, 0x00, (255 - brightness) >> 6);
  720. reg_write(gspca_dev->dev, 5, 0x01, (255 - brightness) << 2);
  721. }
  722. static void getbrightness(struct gspca_dev *gspca_dev)
  723. {
  724. struct sd *sd = (struct sd *) gspca_dev;
  725. sd->brightness = 255
  726. - ((reg_read(gspca_dev, 5, 0x01, 1) >> 2)
  727. + (reg_read(gspca_dev, 5, 0x0, 1) << 6));
  728. }
  729. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  730. {
  731. struct sd *sd = (struct sd *) gspca_dev;
  732. sd->brightness = val;
  733. if (gspca_dev->streaming)
  734. setbrightness(gspca_dev);
  735. return 0;
  736. }
  737. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  738. {
  739. struct sd *sd = (struct sd *) gspca_dev;
  740. getbrightness(gspca_dev);
  741. *val = sd->brightness;
  742. return 0;
  743. }
  744. /* sub-driver description */
  745. static const struct sd_desc sd_desc = {
  746. .name = MODULE_NAME,
  747. .ctrls = sd_ctrls,
  748. .nctrls = ARRAY_SIZE(sd_ctrls),
  749. .config = sd_config,
  750. .init = sd_init,
  751. .start = sd_start,
  752. .stopN = sd_stopN,
  753. .stop0 = sd_stop0,
  754. .pkt_scan = sd_pkt_scan,
  755. };
  756. /* -- module initialisation -- */
  757. static const __devinitdata struct usb_device_id device_table[] = {
  758. {USB_DEVICE(0x041e, 0x401d), .driver_info = Nxultra},
  759. {USB_DEVICE(0x0733, 0x0430), .driver_info = IntelPCCameraPro},
  760. /*fixme: may be UsbGrabberPV321 BRIDGE_SPCA506 SENSOR_SAA7113 */
  761. {}
  762. };
  763. MODULE_DEVICE_TABLE(usb, device_table);
  764. /* -- device connect -- */
  765. static int sd_probe(struct usb_interface *intf,
  766. const struct usb_device_id *id)
  767. {
  768. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  769. THIS_MODULE);
  770. }
  771. static struct usb_driver sd_driver = {
  772. .name = MODULE_NAME,
  773. .id_table = device_table,
  774. .probe = sd_probe,
  775. .disconnect = gspca_disconnect,
  776. #ifdef CONFIG_PM
  777. .suspend = gspca_suspend,
  778. .resume = gspca_resume,
  779. #endif
  780. };
  781. /* -- module insert / remove -- */
  782. static int __init sd_mod_init(void)
  783. {
  784. if (usb_register(&sd_driver) < 0)
  785. return -1;
  786. PDEBUG(D_PROBE, "registered");
  787. return 0;
  788. }
  789. static void __exit sd_mod_exit(void)
  790. {
  791. usb_deregister(&sd_driver);
  792. PDEBUG(D_PROBE, "deregistered");
  793. }
  794. module_init(sd_mod_init);
  795. module_exit(sd_mod_exit);