spca505.c 23 KB

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