spca505.c 23 KB

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