spca505.c 23 KB

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