spca500.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  1. /*
  2. * SPCA500 chip based cameras initialization data
  3. *
  4. * V4L2 by Jean-Francois 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. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #define MODULE_NAME "spca500"
  19. #include "gspca.h"
  20. #include "jpeg.h"
  21. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  22. MODULE_DESCRIPTION("GSPCA/SPCA500 USB Camera Driver");
  23. MODULE_LICENSE("GPL");
  24. #define QUALITY 85
  25. /* specific webcam descriptor */
  26. struct sd {
  27. struct gspca_dev gspca_dev; /* !! must be the first item */
  28. char subtype;
  29. #define AgfaCl20 0
  30. #define AiptekPocketDV 1
  31. #define BenqDC1016 2
  32. #define CreativePCCam300 3
  33. #define DLinkDSC350 4
  34. #define Gsmartmini 5
  35. #define IntelPocketPCCamera 6
  36. #define KodakEZ200 7
  37. #define LogitechClickSmart310 8
  38. #define LogitechClickSmart510 9
  39. #define LogitechTraveler 10
  40. #define MustekGsmart300 11
  41. #define Optimedia 12
  42. #define PalmPixDC85 13
  43. #define ToptroIndus 14
  44. u8 jpeg_hdr[JPEG_HDR_SZ];
  45. };
  46. static const struct v4l2_pix_format vga_mode[] = {
  47. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  48. .bytesperline = 320,
  49. .sizeimage = 320 * 240 * 3 / 8 + 590,
  50. .colorspace = V4L2_COLORSPACE_JPEG,
  51. .priv = 1},
  52. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  53. .bytesperline = 640,
  54. .sizeimage = 640 * 480 * 3 / 8 + 590,
  55. .colorspace = V4L2_COLORSPACE_JPEG,
  56. .priv = 0},
  57. };
  58. static const struct v4l2_pix_format sif_mode[] = {
  59. {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  60. .bytesperline = 176,
  61. .sizeimage = 176 * 144 * 3 / 8 + 590,
  62. .colorspace = V4L2_COLORSPACE_JPEG,
  63. .priv = 1},
  64. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  65. .bytesperline = 352,
  66. .sizeimage = 352 * 288 * 3 / 8 + 590,
  67. .colorspace = V4L2_COLORSPACE_JPEG,
  68. .priv = 0},
  69. };
  70. /* Frame packet header offsets for the spca500 */
  71. #define SPCA500_OFFSET_PADDINGLB 2
  72. #define SPCA500_OFFSET_PADDINGHB 3
  73. #define SPCA500_OFFSET_MODE 4
  74. #define SPCA500_OFFSET_IMGWIDTH 5
  75. #define SPCA500_OFFSET_IMGHEIGHT 6
  76. #define SPCA500_OFFSET_IMGMODE 7
  77. #define SPCA500_OFFSET_QTBLINDEX 8
  78. #define SPCA500_OFFSET_FRAMSEQ 9
  79. #define SPCA500_OFFSET_CDSPINFO 10
  80. #define SPCA500_OFFSET_GPIO 11
  81. #define SPCA500_OFFSET_AUGPIO 12
  82. #define SPCA500_OFFSET_DATA 16
  83. static const __u16 spca500_visual_defaults[][3] = {
  84. {0x00, 0x0003, 0x816b}, /* SSI not active sync with vsync,
  85. * hue (H byte) = 0,
  86. * saturation/hue enable,
  87. * brightness/contrast enable.
  88. */
  89. {0x00, 0x0000, 0x8167}, /* brightness = 0 */
  90. {0x00, 0x0020, 0x8168}, /* contrast = 0 */
  91. {0x00, 0x0003, 0x816b}, /* SSI not active sync with vsync,
  92. * hue (H byte) = 0, saturation/hue enable,
  93. * brightness/contrast enable.
  94. * was 0x0003, now 0x0000.
  95. */
  96. {0x00, 0x0000, 0x816a}, /* hue (L byte) = 0 */
  97. {0x00, 0x0020, 0x8169}, /* saturation = 0x20 */
  98. {0x00, 0x0050, 0x8157}, /* edge gain high threshold */
  99. {0x00, 0x0030, 0x8158}, /* edge gain low threshold */
  100. {0x00, 0x0028, 0x8159}, /* edge bandwidth high threshold */
  101. {0x00, 0x000a, 0x815a}, /* edge bandwidth low threshold */
  102. {0x00, 0x0001, 0x8202}, /* clock rate compensation = 1/25 sec/frame */
  103. {0x0c, 0x0004, 0x0000},
  104. /* set interface */
  105. {}
  106. };
  107. static const __u16 Clicksmart510_defaults[][3] = {
  108. {0x00, 0x00, 0x8211},
  109. {0x00, 0x01, 0x82c0},
  110. {0x00, 0x10, 0x82cb},
  111. {0x00, 0x0f, 0x800d},
  112. {0x00, 0x82, 0x8225},
  113. {0x00, 0x21, 0x8228},
  114. {0x00, 0x00, 0x8203},
  115. {0x00, 0x00, 0x8204},
  116. {0x00, 0x08, 0x8205},
  117. {0x00, 0xf8, 0x8206},
  118. {0x00, 0x28, 0x8207},
  119. {0x00, 0xa0, 0x8208},
  120. {0x00, 0x08, 0x824a},
  121. {0x00, 0x08, 0x8214},
  122. {0x00, 0x80, 0x82c1},
  123. {0x00, 0x00, 0x82c2},
  124. {0x00, 0x00, 0x82ca},
  125. {0x00, 0x80, 0x82c1},
  126. {0x00, 0x04, 0x82c2},
  127. {0x00, 0x00, 0x82ca},
  128. {0x00, 0xfc, 0x8100},
  129. {0x00, 0xfc, 0x8105},
  130. {0x00, 0x30, 0x8101},
  131. {0x00, 0x00, 0x8102},
  132. {0x00, 0x00, 0x8103},
  133. {0x00, 0x66, 0x8107},
  134. {0x00, 0x00, 0x816b},
  135. {0x00, 0x00, 0x8155},
  136. {0x00, 0x01, 0x8156},
  137. {0x00, 0x60, 0x8157},
  138. {0x00, 0x40, 0x8158},
  139. {0x00, 0x0a, 0x8159},
  140. {0x00, 0x06, 0x815a},
  141. {0x00, 0x00, 0x813f},
  142. {0x00, 0x00, 0x8200},
  143. {0x00, 0x19, 0x8201},
  144. {0x00, 0x00, 0x82c1},
  145. {0x00, 0xa0, 0x82c2},
  146. {0x00, 0x00, 0x82ca},
  147. {0x00, 0x00, 0x8117},
  148. {0x00, 0x00, 0x8118},
  149. {0x00, 0x65, 0x8119},
  150. {0x00, 0x00, 0x811a},
  151. {0x00, 0x00, 0x811b},
  152. {0x00, 0x55, 0x811c},
  153. {0x00, 0x65, 0x811d},
  154. {0x00, 0x55, 0x811e},
  155. {0x00, 0x16, 0x811f},
  156. {0x00, 0x19, 0x8120},
  157. {0x00, 0x80, 0x8103},
  158. {0x00, 0x83, 0x816b},
  159. {0x00, 0x25, 0x8168},
  160. {0x00, 0x01, 0x820f},
  161. {0x00, 0xff, 0x8115},
  162. {0x00, 0x48, 0x8116},
  163. {0x00, 0x50, 0x8151},
  164. {0x00, 0x40, 0x8152},
  165. {0x00, 0x78, 0x8153},
  166. {0x00, 0x40, 0x8154},
  167. {0x00, 0x00, 0x8167},
  168. {0x00, 0x20, 0x8168},
  169. {0x00, 0x00, 0x816a},
  170. {0x00, 0x03, 0x816b},
  171. {0x00, 0x20, 0x8169},
  172. {0x00, 0x60, 0x8157},
  173. {0x00, 0x00, 0x8190},
  174. {0x00, 0x00, 0x81a1},
  175. {0x00, 0x00, 0x81b2},
  176. {0x00, 0x27, 0x8191},
  177. {0x00, 0x27, 0x81a2},
  178. {0x00, 0x27, 0x81b3},
  179. {0x00, 0x4b, 0x8192},
  180. {0x00, 0x4b, 0x81a3},
  181. {0x00, 0x4b, 0x81b4},
  182. {0x00, 0x66, 0x8193},
  183. {0x00, 0x66, 0x81a4},
  184. {0x00, 0x66, 0x81b5},
  185. {0x00, 0x79, 0x8194},
  186. {0x00, 0x79, 0x81a5},
  187. {0x00, 0x79, 0x81b6},
  188. {0x00, 0x8a, 0x8195},
  189. {0x00, 0x8a, 0x81a6},
  190. {0x00, 0x8a, 0x81b7},
  191. {0x00, 0x9b, 0x8196},
  192. {0x00, 0x9b, 0x81a7},
  193. {0x00, 0x9b, 0x81b8},
  194. {0x00, 0xa6, 0x8197},
  195. {0x00, 0xa6, 0x81a8},
  196. {0x00, 0xa6, 0x81b9},
  197. {0x00, 0xb2, 0x8198},
  198. {0x00, 0xb2, 0x81a9},
  199. {0x00, 0xb2, 0x81ba},
  200. {0x00, 0xbe, 0x8199},
  201. {0x00, 0xbe, 0x81aa},
  202. {0x00, 0xbe, 0x81bb},
  203. {0x00, 0xc8, 0x819a},
  204. {0x00, 0xc8, 0x81ab},
  205. {0x00, 0xc8, 0x81bc},
  206. {0x00, 0xd2, 0x819b},
  207. {0x00, 0xd2, 0x81ac},
  208. {0x00, 0xd2, 0x81bd},
  209. {0x00, 0xdb, 0x819c},
  210. {0x00, 0xdb, 0x81ad},
  211. {0x00, 0xdb, 0x81be},
  212. {0x00, 0xe4, 0x819d},
  213. {0x00, 0xe4, 0x81ae},
  214. {0x00, 0xe4, 0x81bf},
  215. {0x00, 0xed, 0x819e},
  216. {0x00, 0xed, 0x81af},
  217. {0x00, 0xed, 0x81c0},
  218. {0x00, 0xf7, 0x819f},
  219. {0x00, 0xf7, 0x81b0},
  220. {0x00, 0xf7, 0x81c1},
  221. {0x00, 0xff, 0x81a0},
  222. {0x00, 0xff, 0x81b1},
  223. {0x00, 0xff, 0x81c2},
  224. {0x00, 0x03, 0x8156},
  225. {0x00, 0x00, 0x8211},
  226. {0x00, 0x20, 0x8168},
  227. {0x00, 0x01, 0x8202},
  228. {0x00, 0x30, 0x8101},
  229. {0x00, 0x00, 0x8111},
  230. {0x00, 0x00, 0x8112},
  231. {0x00, 0x00, 0x8113},
  232. {0x00, 0x00, 0x8114},
  233. {}
  234. };
  235. static const __u8 qtable_creative_pccam[2][64] = {
  236. { /* Q-table Y-components */
  237. 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12,
  238. 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11,
  239. 0x04, 0x04, 0x05, 0x07, 0x0c, 0x11, 0x15, 0x11,
  240. 0x04, 0x05, 0x07, 0x09, 0x0f, 0x1a, 0x18, 0x13,
  241. 0x05, 0x07, 0x0b, 0x11, 0x14, 0x21, 0x1f, 0x17,
  242. 0x07, 0x0b, 0x11, 0x13, 0x18, 0x1f, 0x22, 0x1c,
  243. 0x0f, 0x13, 0x17, 0x1a, 0x1f, 0x24, 0x24, 0x1e,
  244. 0x16, 0x1c, 0x1d, 0x1d, 0x22, 0x1e, 0x1f, 0x1e},
  245. { /* Q-table C-components */
  246. 0x05, 0x05, 0x07, 0x0e, 0x1e, 0x1e, 0x1e, 0x1e,
  247. 0x05, 0x06, 0x08, 0x14, 0x1e, 0x1e, 0x1e, 0x1e,
  248. 0x07, 0x08, 0x11, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  249. 0x0e, 0x14, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  250. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  251. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  252. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
  253. 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e}
  254. };
  255. static const __u8 qtable_kodak_ez200[2][64] = {
  256. { /* Q-table Y-components */
  257. 0x02, 0x01, 0x01, 0x02, 0x02, 0x04, 0x05, 0x06,
  258. 0x01, 0x01, 0x01, 0x02, 0x03, 0x06, 0x06, 0x06,
  259. 0x01, 0x01, 0x02, 0x02, 0x04, 0x06, 0x07, 0x06,
  260. 0x01, 0x02, 0x02, 0x03, 0x05, 0x09, 0x08, 0x06,
  261. 0x02, 0x02, 0x04, 0x06, 0x07, 0x0b, 0x0a, 0x08,
  262. 0x02, 0x04, 0x06, 0x06, 0x08, 0x0a, 0x0b, 0x09,
  263. 0x05, 0x06, 0x08, 0x09, 0x0a, 0x0c, 0x0c, 0x0a,
  264. 0x07, 0x09, 0x0a, 0x0a, 0x0b, 0x0a, 0x0a, 0x0a},
  265. { /* Q-table C-components */
  266. 0x02, 0x02, 0x02, 0x05, 0x0a, 0x0a, 0x0a, 0x0a,
  267. 0x02, 0x02, 0x03, 0x07, 0x0a, 0x0a, 0x0a, 0x0a,
  268. 0x02, 0x03, 0x06, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  269. 0x05, 0x07, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  270. 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  271. 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  272. 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  273. 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}
  274. };
  275. static const __u8 qtable_pocketdv[2][64] = {
  276. { /* Q-table Y-components start registers 0x8800 */
  277. 0x06, 0x04, 0x04, 0x06, 0x0a, 0x10, 0x14, 0x18,
  278. 0x05, 0x05, 0x06, 0x08, 0x0a, 0x17, 0x18, 0x16,
  279. 0x06, 0x05, 0x06, 0x0a, 0x10, 0x17, 0x1c, 0x16,
  280. 0x06, 0x07, 0x09, 0x0c, 0x14, 0x23, 0x20, 0x19,
  281. 0x07, 0x09, 0x0f, 0x16, 0x1b, 0x2c, 0x29, 0x1f,
  282. 0x0a, 0x0e, 0x16, 0x1a, 0x20, 0x2a, 0x2d, 0x25,
  283. 0x14, 0x1a, 0x1f, 0x23, 0x29, 0x30, 0x30, 0x28,
  284. 0x1d, 0x25, 0x26, 0x27, 0x2d, 0x28, 0x29, 0x28,
  285. },
  286. { /* Q-table C-components start registers 0x8840 */
  287. 0x07, 0x07, 0x0a, 0x13, 0x28, 0x28, 0x28, 0x28,
  288. 0x07, 0x08, 0x0a, 0x1a, 0x28, 0x28, 0x28, 0x28,
  289. 0x0a, 0x0a, 0x16, 0x28, 0x28, 0x28, 0x28, 0x28,
  290. 0x13, 0x1a, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
  291. 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
  292. 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
  293. 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
  294. 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28}
  295. };
  296. /* read 'len' bytes to gspca_dev->usb_buf */
  297. static void reg_r(struct gspca_dev *gspca_dev,
  298. __u16 index,
  299. __u16 length)
  300. {
  301. usb_control_msg(gspca_dev->dev,
  302. usb_rcvctrlpipe(gspca_dev->dev, 0),
  303. 0,
  304. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  305. 0, /* value */
  306. index, gspca_dev->usb_buf, length, 500);
  307. }
  308. static int reg_w(struct gspca_dev *gspca_dev,
  309. __u16 req, __u16 index, __u16 value)
  310. {
  311. int ret;
  312. gspca_dbg(gspca_dev, D_USBO, "reg write: [0x%02x] = 0x%02x\n",
  313. index, value);
  314. ret = usb_control_msg(gspca_dev->dev,
  315. usb_sndctrlpipe(gspca_dev->dev, 0),
  316. req,
  317. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  318. value, index, NULL, 0, 500);
  319. if (ret < 0)
  320. pr_err("reg write: error %d\n", ret);
  321. return ret;
  322. }
  323. /* returns: negative is error, pos or zero is data */
  324. static int reg_r_12(struct gspca_dev *gspca_dev,
  325. __u16 req, /* bRequest */
  326. __u16 index, /* wIndex */
  327. __u16 length) /* wLength (1 or 2 only) */
  328. {
  329. int ret;
  330. gspca_dev->usb_buf[1] = 0;
  331. ret = usb_control_msg(gspca_dev->dev,
  332. usb_rcvctrlpipe(gspca_dev->dev, 0),
  333. req,
  334. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  335. 0, /* value */
  336. index,
  337. gspca_dev->usb_buf, length,
  338. 500); /* timeout */
  339. if (ret < 0) {
  340. pr_err("reg_r_12 err %d\n", ret);
  341. return ret;
  342. }
  343. return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
  344. }
  345. /*
  346. * Simple function to wait for a given 8-bit value to be returned from
  347. * a reg_read call.
  348. * Returns: negative is error or timeout, zero is success.
  349. */
  350. static int reg_r_wait(struct gspca_dev *gspca_dev,
  351. __u16 reg, __u16 index, __u16 value)
  352. {
  353. int ret, cnt = 20;
  354. while (--cnt > 0) {
  355. ret = reg_r_12(gspca_dev, reg, index, 1);
  356. if (ret == value)
  357. return 0;
  358. msleep(50);
  359. }
  360. return -EIO;
  361. }
  362. static int write_vector(struct gspca_dev *gspca_dev,
  363. const __u16 data[][3])
  364. {
  365. int ret, i = 0;
  366. while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) {
  367. ret = reg_w(gspca_dev, data[i][0], data[i][2], data[i][1]);
  368. if (ret < 0)
  369. return ret;
  370. i++;
  371. }
  372. return 0;
  373. }
  374. static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
  375. unsigned int request,
  376. unsigned int ybase,
  377. unsigned int cbase,
  378. const __u8 qtable[2][64])
  379. {
  380. int i, err;
  381. /* loop over y components */
  382. for (i = 0; i < 64; i++) {
  383. err = reg_w(gspca_dev, request, ybase + i, qtable[0][i]);
  384. if (err < 0)
  385. return err;
  386. }
  387. /* loop over c components */
  388. for (i = 0; i < 64; i++) {
  389. err = reg_w(gspca_dev, request, cbase + i, qtable[1][i]);
  390. if (err < 0)
  391. return err;
  392. }
  393. return 0;
  394. }
  395. static void spca500_ping310(struct gspca_dev *gspca_dev)
  396. {
  397. reg_r(gspca_dev, 0x0d04, 2);
  398. gspca_dbg(gspca_dev, D_STREAM, "ClickSmart310 ping 0x0d04 0x%02x 0x%02x\n",
  399. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]);
  400. }
  401. static void spca500_clksmart310_init(struct gspca_dev *gspca_dev)
  402. {
  403. reg_r(gspca_dev, 0x0d05, 2);
  404. gspca_dbg(gspca_dev, D_STREAM, "ClickSmart310 init 0x0d05 0x%02x 0x%02x\n",
  405. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]);
  406. reg_w(gspca_dev, 0x00, 0x8167, 0x5a);
  407. spca500_ping310(gspca_dev);
  408. reg_w(gspca_dev, 0x00, 0x8168, 0x22);
  409. reg_w(gspca_dev, 0x00, 0x816a, 0xc0);
  410. reg_w(gspca_dev, 0x00, 0x816b, 0x0b);
  411. reg_w(gspca_dev, 0x00, 0x8169, 0x25);
  412. reg_w(gspca_dev, 0x00, 0x8157, 0x5b);
  413. reg_w(gspca_dev, 0x00, 0x8158, 0x5b);
  414. reg_w(gspca_dev, 0x00, 0x813f, 0x03);
  415. reg_w(gspca_dev, 0x00, 0x8151, 0x4a);
  416. reg_w(gspca_dev, 0x00, 0x8153, 0x78);
  417. reg_w(gspca_dev, 0x00, 0x0d01, 0x04);
  418. /* 00 for adjust shutter */
  419. reg_w(gspca_dev, 0x00, 0x0d02, 0x01);
  420. reg_w(gspca_dev, 0x00, 0x8169, 0x25);
  421. reg_w(gspca_dev, 0x00, 0x0d01, 0x02);
  422. }
  423. static void spca500_setmode(struct gspca_dev *gspca_dev,
  424. __u8 xmult, __u8 ymult)
  425. {
  426. int mode;
  427. /* set x multiplier */
  428. reg_w(gspca_dev, 0, 0x8001, xmult);
  429. /* set y multiplier */
  430. reg_w(gspca_dev, 0, 0x8002, ymult);
  431. /* use compressed mode, VGA, with mode specific subsample */
  432. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  433. reg_w(gspca_dev, 0, 0x8003, mode << 4);
  434. }
  435. static int spca500_full_reset(struct gspca_dev *gspca_dev)
  436. {
  437. int err;
  438. /* send the reset command */
  439. err = reg_w(gspca_dev, 0xe0, 0x0001, 0x0000);
  440. if (err < 0)
  441. return err;
  442. /* wait for the reset to complete */
  443. err = reg_r_wait(gspca_dev, 0x06, 0x0000, 0x0000);
  444. if (err < 0)
  445. return err;
  446. err = reg_w(gspca_dev, 0xe0, 0x0000, 0x0000);
  447. if (err < 0)
  448. return err;
  449. err = reg_r_wait(gspca_dev, 0x06, 0, 0);
  450. if (err < 0) {
  451. gspca_err(gspca_dev, "reg_r_wait() failed\n");
  452. return err;
  453. }
  454. /* all ok */
  455. return 0;
  456. }
  457. /* Synchro the Bridge with sensor */
  458. /* Maybe that will work on all spca500 chip */
  459. /* because i only own a clicksmart310 try for that chip */
  460. /* using spca50x_set_packet_size() cause an Ooops here */
  461. /* usb_set_interface from kernel 2.6.x clear all the urb stuff */
  462. /* up-port the same feature as in 2.4.x kernel */
  463. static int spca500_synch310(struct gspca_dev *gspca_dev)
  464. {
  465. if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0) < 0) {
  466. gspca_err(gspca_dev, "Set packet size: set interface error\n");
  467. goto error;
  468. }
  469. spca500_ping310(gspca_dev);
  470. reg_r(gspca_dev, 0x0d00, 1);
  471. /* need alt setting here */
  472. gspca_dbg(gspca_dev, D_PACK, "ClickSmart310 sync alt: %d\n",
  473. gspca_dev->alt);
  474. /* Windoze use pipe with altsetting 6 why 7 here */
  475. if (usb_set_interface(gspca_dev->dev,
  476. gspca_dev->iface,
  477. gspca_dev->alt) < 0) {
  478. gspca_err(gspca_dev, "Set packet size: set interface error\n");
  479. goto error;
  480. }
  481. return 0;
  482. error:
  483. return -EBUSY;
  484. }
  485. static void spca500_reinit(struct gspca_dev *gspca_dev)
  486. {
  487. int err;
  488. __u8 Data;
  489. /* some unknown command from Aiptek pocket dv and family300 */
  490. reg_w(gspca_dev, 0x00, 0x0d01, 0x01);
  491. reg_w(gspca_dev, 0x00, 0x0d03, 0x00);
  492. reg_w(gspca_dev, 0x00, 0x0d02, 0x01);
  493. /* enable drop packet */
  494. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  495. err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840,
  496. qtable_pocketdv);
  497. if (err < 0)
  498. gspca_err(gspca_dev, "spca50x_setup_qtable failed on init\n");
  499. /* set qtable index */
  500. reg_w(gspca_dev, 0x00, 0x8880, 2);
  501. /* family cam Quicksmart stuff */
  502. reg_w(gspca_dev, 0x00, 0x800a, 0x00);
  503. /* Set agc transfer: synced between frames */
  504. reg_w(gspca_dev, 0x00, 0x820f, 0x01);
  505. /* Init SDRAM - needed for SDRAM access */
  506. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  507. /*Start init sequence or stream */
  508. reg_w(gspca_dev, 0, 0x8003, 0x00);
  509. /* switch to video camera mode */
  510. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  511. msleep(2000);
  512. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) {
  513. reg_r(gspca_dev, 0x816b, 1);
  514. Data = gspca_dev->usb_buf[0];
  515. reg_w(gspca_dev, 0x00, 0x816b, Data);
  516. }
  517. }
  518. /* this function is called at probe time */
  519. static int sd_config(struct gspca_dev *gspca_dev,
  520. const struct usb_device_id *id)
  521. {
  522. struct sd *sd = (struct sd *) gspca_dev;
  523. struct cam *cam;
  524. cam = &gspca_dev->cam;
  525. sd->subtype = id->driver_info;
  526. if (sd->subtype != LogitechClickSmart310) {
  527. cam->cam_mode = vga_mode;
  528. cam->nmodes = ARRAY_SIZE(vga_mode);
  529. } else {
  530. cam->cam_mode = sif_mode;
  531. cam->nmodes = ARRAY_SIZE(sif_mode);
  532. }
  533. return 0;
  534. }
  535. /* this function is called at probe and resume time */
  536. static int sd_init(struct gspca_dev *gspca_dev)
  537. {
  538. struct sd *sd = (struct sd *) gspca_dev;
  539. /* initialisation of spca500 based cameras is deferred */
  540. gspca_dbg(gspca_dev, D_STREAM, "SPCA500 init\n");
  541. if (sd->subtype == LogitechClickSmart310)
  542. spca500_clksmart310_init(gspca_dev);
  543. /* else
  544. spca500_initialise(gspca_dev); */
  545. gspca_dbg(gspca_dev, D_STREAM, "SPCA500 init done\n");
  546. return 0;
  547. }
  548. static int sd_start(struct gspca_dev *gspca_dev)
  549. {
  550. struct sd *sd = (struct sd *) gspca_dev;
  551. int err;
  552. __u8 Data;
  553. __u8 xmult, ymult;
  554. /* create the JPEG header */
  555. jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
  556. gspca_dev->pixfmt.width,
  557. 0x22); /* JPEG 411 */
  558. jpeg_set_qual(sd->jpeg_hdr, QUALITY);
  559. if (sd->subtype == LogitechClickSmart310) {
  560. xmult = 0x16;
  561. ymult = 0x12;
  562. } else {
  563. xmult = 0x28;
  564. ymult = 0x1e;
  565. }
  566. /* is there a sensor here ? */
  567. reg_r(gspca_dev, 0x8a04, 1);
  568. gspca_dbg(gspca_dev, D_STREAM, "Spca500 Sensor Address 0x%02x\n",
  569. gspca_dev->usb_buf[0]);
  570. gspca_dbg(gspca_dev, D_STREAM, "Spca500 curr_mode: %d Xmult: 0x%02x, Ymult: 0x%02x",
  571. gspca_dev->curr_mode, xmult, ymult);
  572. /* setup qtable */
  573. switch (sd->subtype) {
  574. case LogitechClickSmart310:
  575. spca500_setmode(gspca_dev, xmult, ymult);
  576. /* enable drop packet */
  577. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  578. reg_w(gspca_dev, 0x00, 0x8880, 3);
  579. err = spca50x_setup_qtable(gspca_dev,
  580. 0x00, 0x8800, 0x8840,
  581. qtable_creative_pccam);
  582. if (err < 0)
  583. gspca_err(gspca_dev, "spca50x_setup_qtable failed\n");
  584. /* Init SDRAM - needed for SDRAM access */
  585. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  586. /* switch to video camera mode */
  587. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  588. msleep(500);
  589. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
  590. gspca_err(gspca_dev, "reg_r_wait() failed\n");
  591. reg_r(gspca_dev, 0x816b, 1);
  592. Data = gspca_dev->usb_buf[0];
  593. reg_w(gspca_dev, 0x00, 0x816b, Data);
  594. spca500_synch310(gspca_dev);
  595. write_vector(gspca_dev, spca500_visual_defaults);
  596. spca500_setmode(gspca_dev, xmult, ymult);
  597. /* enable drop packet */
  598. err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  599. if (err < 0)
  600. gspca_err(gspca_dev, "failed to enable drop packet\n");
  601. reg_w(gspca_dev, 0x00, 0x8880, 3);
  602. err = spca50x_setup_qtable(gspca_dev,
  603. 0x00, 0x8800, 0x8840,
  604. qtable_creative_pccam);
  605. if (err < 0)
  606. gspca_err(gspca_dev, "spca50x_setup_qtable failed\n");
  607. /* Init SDRAM - needed for SDRAM access */
  608. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  609. /* switch to video camera mode */
  610. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  611. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
  612. gspca_err(gspca_dev, "reg_r_wait() failed\n");
  613. reg_r(gspca_dev, 0x816b, 1);
  614. Data = gspca_dev->usb_buf[0];
  615. reg_w(gspca_dev, 0x00, 0x816b, Data);
  616. break;
  617. case CreativePCCam300: /* Creative PC-CAM 300 640x480 CCD */
  618. case IntelPocketPCCamera: /* FIXME: Temporary fix for
  619. * Intel Pocket PC Camera
  620. * - NWG (Sat 29th March 2003) */
  621. /* do a full reset */
  622. err = spca500_full_reset(gspca_dev);
  623. if (err < 0)
  624. gspca_err(gspca_dev, "spca500_full_reset failed\n");
  625. /* enable drop packet */
  626. err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  627. if (err < 0)
  628. gspca_err(gspca_dev, "failed to enable drop packet\n");
  629. reg_w(gspca_dev, 0x00, 0x8880, 3);
  630. err = spca50x_setup_qtable(gspca_dev,
  631. 0x00, 0x8800, 0x8840,
  632. qtable_creative_pccam);
  633. if (err < 0)
  634. gspca_err(gspca_dev, "spca50x_setup_qtable failed\n");
  635. spca500_setmode(gspca_dev, xmult, ymult);
  636. reg_w(gspca_dev, 0x20, 0x0001, 0x0004);
  637. /* switch to video camera mode */
  638. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  639. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
  640. gspca_err(gspca_dev, "reg_r_wait() failed\n");
  641. reg_r(gspca_dev, 0x816b, 1);
  642. Data = gspca_dev->usb_buf[0];
  643. reg_w(gspca_dev, 0x00, 0x816b, Data);
  644. /* write_vector(gspca_dev, spca500_visual_defaults); */
  645. break;
  646. case KodakEZ200: /* Kodak EZ200 */
  647. /* do a full reset */
  648. err = spca500_full_reset(gspca_dev);
  649. if (err < 0)
  650. gspca_err(gspca_dev, "spca500_full_reset failed\n");
  651. /* enable drop packet */
  652. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  653. reg_w(gspca_dev, 0x00, 0x8880, 0);
  654. err = spca50x_setup_qtable(gspca_dev,
  655. 0x00, 0x8800, 0x8840,
  656. qtable_kodak_ez200);
  657. if (err < 0)
  658. gspca_err(gspca_dev, "spca50x_setup_qtable failed\n");
  659. spca500_setmode(gspca_dev, xmult, ymult);
  660. reg_w(gspca_dev, 0x20, 0x0001, 0x0004);
  661. /* switch to video camera mode */
  662. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  663. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
  664. gspca_err(gspca_dev, "reg_r_wait() failed\n");
  665. reg_r(gspca_dev, 0x816b, 1);
  666. Data = gspca_dev->usb_buf[0];
  667. reg_w(gspca_dev, 0x00, 0x816b, Data);
  668. /* write_vector(gspca_dev, spca500_visual_defaults); */
  669. break;
  670. case BenqDC1016:
  671. case DLinkDSC350: /* FamilyCam 300 */
  672. case AiptekPocketDV: /* Aiptek PocketDV */
  673. case Gsmartmini: /*Mustek Gsmart Mini */
  674. case MustekGsmart300: /* Mustek Gsmart 300 */
  675. case PalmPixDC85:
  676. case Optimedia:
  677. case ToptroIndus:
  678. case AgfaCl20:
  679. spca500_reinit(gspca_dev);
  680. reg_w(gspca_dev, 0x00, 0x0d01, 0x01);
  681. /* enable drop packet */
  682. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  683. err = spca50x_setup_qtable(gspca_dev,
  684. 0x00, 0x8800, 0x8840, qtable_pocketdv);
  685. if (err < 0)
  686. gspca_err(gspca_dev, "spca50x_setup_qtable failed\n");
  687. reg_w(gspca_dev, 0x00, 0x8880, 2);
  688. /* familycam Quicksmart pocketDV stuff */
  689. reg_w(gspca_dev, 0x00, 0x800a, 0x00);
  690. /* Set agc transfer: synced between frames */
  691. reg_w(gspca_dev, 0x00, 0x820f, 0x01);
  692. /* Init SDRAM - needed for SDRAM access */
  693. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  694. spca500_setmode(gspca_dev, xmult, ymult);
  695. /* switch to video camera mode */
  696. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  697. reg_r_wait(gspca_dev, 0, 0x8000, 0x44);
  698. reg_r(gspca_dev, 0x816b, 1);
  699. Data = gspca_dev->usb_buf[0];
  700. reg_w(gspca_dev, 0x00, 0x816b, Data);
  701. break;
  702. case LogitechTraveler:
  703. case LogitechClickSmart510:
  704. reg_w(gspca_dev, 0x02, 0x00, 0x00);
  705. /* enable drop packet */
  706. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  707. err = spca50x_setup_qtable(gspca_dev,
  708. 0x00, 0x8800,
  709. 0x8840, qtable_creative_pccam);
  710. if (err < 0)
  711. gspca_err(gspca_dev, "spca50x_setup_qtable failed\n");
  712. reg_w(gspca_dev, 0x00, 0x8880, 3);
  713. reg_w(gspca_dev, 0x00, 0x800a, 0x00);
  714. /* Init SDRAM - needed for SDRAM access */
  715. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  716. spca500_setmode(gspca_dev, xmult, ymult);
  717. /* switch to video camera mode */
  718. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  719. reg_r_wait(gspca_dev, 0, 0x8000, 0x44);
  720. reg_r(gspca_dev, 0x816b, 1);
  721. Data = gspca_dev->usb_buf[0];
  722. reg_w(gspca_dev, 0x00, 0x816b, Data);
  723. write_vector(gspca_dev, Clicksmart510_defaults);
  724. break;
  725. }
  726. return 0;
  727. }
  728. static void sd_stopN(struct gspca_dev *gspca_dev)
  729. {
  730. reg_w(gspca_dev, 0, 0x8003, 0x00);
  731. /* switch to video camera mode */
  732. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  733. reg_r(gspca_dev, 0x8000, 1);
  734. gspca_dbg(gspca_dev, D_STREAM, "stop SPCA500 done reg8000: 0x%2x\n",
  735. gspca_dev->usb_buf[0]);
  736. }
  737. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  738. u8 *data, /* isoc packet */
  739. int len) /* iso packet length */
  740. {
  741. struct sd *sd = (struct sd *) gspca_dev;
  742. int i;
  743. static __u8 ffd9[] = {0xff, 0xd9};
  744. /* frames are jpeg 4.1.1 without 0xff escape */
  745. if (data[0] == 0xff) {
  746. if (data[1] != 0x01) { /* drop packet */
  747. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  748. return;
  749. }
  750. gspca_frame_add(gspca_dev, LAST_PACKET,
  751. ffd9, 2);
  752. /* put the JPEG header in the new frame */
  753. gspca_frame_add(gspca_dev, FIRST_PACKET,
  754. sd->jpeg_hdr, JPEG_HDR_SZ);
  755. data += SPCA500_OFFSET_DATA;
  756. len -= SPCA500_OFFSET_DATA;
  757. } else {
  758. data += 1;
  759. len -= 1;
  760. }
  761. /* add 0x00 after 0xff */
  762. i = 0;
  763. do {
  764. if (data[i] == 0xff) {
  765. gspca_frame_add(gspca_dev, INTER_PACKET,
  766. data, i + 1);
  767. len -= i;
  768. data += i;
  769. *data = 0x00;
  770. i = 0;
  771. }
  772. i++;
  773. } while (i < len);
  774. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  775. }
  776. static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
  777. {
  778. reg_w(gspca_dev, 0x00, 0x8167,
  779. (__u8) (val - 128));
  780. }
  781. static void setcontrast(struct gspca_dev *gspca_dev, s32 val)
  782. {
  783. reg_w(gspca_dev, 0x00, 0x8168, val);
  784. }
  785. static void setcolors(struct gspca_dev *gspca_dev, s32 val)
  786. {
  787. reg_w(gspca_dev, 0x00, 0x8169, val);
  788. }
  789. static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
  790. {
  791. struct gspca_dev *gspca_dev =
  792. container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
  793. gspca_dev->usb_err = 0;
  794. if (!gspca_dev->streaming)
  795. return 0;
  796. switch (ctrl->id) {
  797. case V4L2_CID_BRIGHTNESS:
  798. setbrightness(gspca_dev, ctrl->val);
  799. break;
  800. case V4L2_CID_CONTRAST:
  801. setcontrast(gspca_dev, ctrl->val);
  802. break;
  803. case V4L2_CID_SATURATION:
  804. setcolors(gspca_dev, ctrl->val);
  805. break;
  806. }
  807. return gspca_dev->usb_err;
  808. }
  809. static const struct v4l2_ctrl_ops sd_ctrl_ops = {
  810. .s_ctrl = sd_s_ctrl,
  811. };
  812. static int sd_init_controls(struct gspca_dev *gspca_dev)
  813. {
  814. struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
  815. gspca_dev->vdev.ctrl_handler = hdl;
  816. v4l2_ctrl_handler_init(hdl, 3);
  817. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  818. V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
  819. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  820. V4L2_CID_CONTRAST, 0, 63, 1, 31);
  821. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  822. V4L2_CID_SATURATION, 0, 63, 1, 31);
  823. if (hdl->error) {
  824. pr_err("Could not initialize controls\n");
  825. return hdl->error;
  826. }
  827. return 0;
  828. }
  829. /* sub-driver description */
  830. static const struct sd_desc sd_desc = {
  831. .name = MODULE_NAME,
  832. .config = sd_config,
  833. .init = sd_init,
  834. .init_controls = sd_init_controls,
  835. .start = sd_start,
  836. .stopN = sd_stopN,
  837. .pkt_scan = sd_pkt_scan,
  838. };
  839. /* -- module initialisation -- */
  840. static const struct usb_device_id device_table[] = {
  841. {USB_DEVICE(0x040a, 0x0300), .driver_info = KodakEZ200},
  842. {USB_DEVICE(0x041e, 0x400a), .driver_info = CreativePCCam300},
  843. {USB_DEVICE(0x046d, 0x0890), .driver_info = LogitechTraveler},
  844. {USB_DEVICE(0x046d, 0x0900), .driver_info = LogitechClickSmart310},
  845. {USB_DEVICE(0x046d, 0x0901), .driver_info = LogitechClickSmart510},
  846. {USB_DEVICE(0x04a5, 0x300c), .driver_info = BenqDC1016},
  847. {USB_DEVICE(0x04fc, 0x7333), .driver_info = PalmPixDC85},
  848. {USB_DEVICE(0x055f, 0xc200), .driver_info = MustekGsmart300},
  849. {USB_DEVICE(0x055f, 0xc220), .driver_info = Gsmartmini},
  850. {USB_DEVICE(0x06bd, 0x0404), .driver_info = AgfaCl20},
  851. {USB_DEVICE(0x06be, 0x0800), .driver_info = Optimedia},
  852. {USB_DEVICE(0x084d, 0x0003), .driver_info = DLinkDSC350},
  853. {USB_DEVICE(0x08ca, 0x0103), .driver_info = AiptekPocketDV},
  854. {USB_DEVICE(0x2899, 0x012c), .driver_info = ToptroIndus},
  855. {USB_DEVICE(0x8086, 0x0630), .driver_info = IntelPocketPCCamera},
  856. {}
  857. };
  858. MODULE_DEVICE_TABLE(usb, device_table);
  859. /* -- device connect -- */
  860. static int sd_probe(struct usb_interface *intf,
  861. const struct usb_device_id *id)
  862. {
  863. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  864. THIS_MODULE);
  865. }
  866. static struct usb_driver sd_driver = {
  867. .name = MODULE_NAME,
  868. .id_table = device_table,
  869. .probe = sd_probe,
  870. .disconnect = gspca_disconnect,
  871. #ifdef CONFIG_PM
  872. .suspend = gspca_suspend,
  873. .resume = gspca_resume,
  874. .reset_resume = gspca_resume,
  875. #endif
  876. };
  877. module_usb_driver(sd_driver);