spca500.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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. PDEBUG(D_USBO, "reg write: [0x%02x] = 0x%02x", index, value);
  313. ret = usb_control_msg(gspca_dev->dev,
  314. usb_sndctrlpipe(gspca_dev->dev, 0),
  315. req,
  316. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  317. value, index, NULL, 0, 500);
  318. if (ret < 0)
  319. pr_err("reg write: error %d\n", ret);
  320. return ret;
  321. }
  322. /* returns: negative is error, pos or zero is data */
  323. static int reg_r_12(struct gspca_dev *gspca_dev,
  324. __u16 req, /* bRequest */
  325. __u16 index, /* wIndex */
  326. __u16 length) /* wLength (1 or 2 only) */
  327. {
  328. int ret;
  329. gspca_dev->usb_buf[1] = 0;
  330. ret = usb_control_msg(gspca_dev->dev,
  331. usb_rcvctrlpipe(gspca_dev->dev, 0),
  332. req,
  333. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  334. 0, /* value */
  335. index,
  336. gspca_dev->usb_buf, length,
  337. 500); /* timeout */
  338. if (ret < 0) {
  339. pr_err("reg_r_12 err %d\n", ret);
  340. return ret;
  341. }
  342. return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
  343. }
  344. /*
  345. * Simple function to wait for a given 8-bit value to be returned from
  346. * a reg_read call.
  347. * Returns: negative is error or timeout, zero is success.
  348. */
  349. static int reg_r_wait(struct gspca_dev *gspca_dev,
  350. __u16 reg, __u16 index, __u16 value)
  351. {
  352. int ret, cnt = 20;
  353. while (--cnt > 0) {
  354. ret = reg_r_12(gspca_dev, reg, index, 1);
  355. if (ret == value)
  356. return 0;
  357. msleep(50);
  358. }
  359. return -EIO;
  360. }
  361. static int write_vector(struct gspca_dev *gspca_dev,
  362. const __u16 data[][3])
  363. {
  364. int ret, i = 0;
  365. while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) {
  366. ret = reg_w(gspca_dev, data[i][0], data[i][2], data[i][1]);
  367. if (ret < 0)
  368. return ret;
  369. i++;
  370. }
  371. return 0;
  372. }
  373. static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
  374. unsigned int request,
  375. unsigned int ybase,
  376. unsigned int cbase,
  377. const __u8 qtable[2][64])
  378. {
  379. int i, err;
  380. /* loop over y components */
  381. for (i = 0; i < 64; i++) {
  382. err = reg_w(gspca_dev, request, ybase + i, qtable[0][i]);
  383. if (err < 0)
  384. return err;
  385. }
  386. /* loop over c components */
  387. for (i = 0; i < 64; i++) {
  388. err = reg_w(gspca_dev, request, cbase + i, qtable[1][i]);
  389. if (err < 0)
  390. return err;
  391. }
  392. return 0;
  393. }
  394. static void spca500_ping310(struct gspca_dev *gspca_dev)
  395. {
  396. reg_r(gspca_dev, 0x0d04, 2);
  397. PDEBUG(D_STREAM, "ClickSmart310 ping 0x0d04 0x%02x 0x%02x",
  398. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]);
  399. }
  400. static void spca500_clksmart310_init(struct gspca_dev *gspca_dev)
  401. {
  402. reg_r(gspca_dev, 0x0d05, 2);
  403. PDEBUG(D_STREAM, "ClickSmart310 init 0x0d05 0x%02x 0x%02x",
  404. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]);
  405. reg_w(gspca_dev, 0x00, 0x8167, 0x5a);
  406. spca500_ping310(gspca_dev);
  407. reg_w(gspca_dev, 0x00, 0x8168, 0x22);
  408. reg_w(gspca_dev, 0x00, 0x816a, 0xc0);
  409. reg_w(gspca_dev, 0x00, 0x816b, 0x0b);
  410. reg_w(gspca_dev, 0x00, 0x8169, 0x25);
  411. reg_w(gspca_dev, 0x00, 0x8157, 0x5b);
  412. reg_w(gspca_dev, 0x00, 0x8158, 0x5b);
  413. reg_w(gspca_dev, 0x00, 0x813f, 0x03);
  414. reg_w(gspca_dev, 0x00, 0x8151, 0x4a);
  415. reg_w(gspca_dev, 0x00, 0x8153, 0x78);
  416. reg_w(gspca_dev, 0x00, 0x0d01, 0x04);
  417. /* 00 for adjust shutter */
  418. reg_w(gspca_dev, 0x00, 0x0d02, 0x01);
  419. reg_w(gspca_dev, 0x00, 0x8169, 0x25);
  420. reg_w(gspca_dev, 0x00, 0x0d01, 0x02);
  421. }
  422. static void spca500_setmode(struct gspca_dev *gspca_dev,
  423. __u8 xmult, __u8 ymult)
  424. {
  425. int mode;
  426. /* set x multiplier */
  427. reg_w(gspca_dev, 0, 0x8001, xmult);
  428. /* set y multiplier */
  429. reg_w(gspca_dev, 0, 0x8002, ymult);
  430. /* use compressed mode, VGA, with mode specific subsample */
  431. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  432. reg_w(gspca_dev, 0, 0x8003, mode << 4);
  433. }
  434. static int spca500_full_reset(struct gspca_dev *gspca_dev)
  435. {
  436. int err;
  437. /* send the reset command */
  438. err = reg_w(gspca_dev, 0xe0, 0x0001, 0x0000);
  439. if (err < 0)
  440. return err;
  441. /* wait for the reset to complete */
  442. err = reg_r_wait(gspca_dev, 0x06, 0x0000, 0x0000);
  443. if (err < 0)
  444. return err;
  445. err = reg_w(gspca_dev, 0xe0, 0x0000, 0x0000);
  446. if (err < 0)
  447. return err;
  448. err = reg_r_wait(gspca_dev, 0x06, 0, 0);
  449. if (err < 0) {
  450. PERR("reg_r_wait() failed");
  451. return err;
  452. }
  453. /* all ok */
  454. return 0;
  455. }
  456. /* Synchro the Bridge with sensor */
  457. /* Maybe that will work on all spca500 chip */
  458. /* because i only own a clicksmart310 try for that chip */
  459. /* using spca50x_set_packet_size() cause an Ooops here */
  460. /* usb_set_interface from kernel 2.6.x clear all the urb stuff */
  461. /* up-port the same feature as in 2.4.x kernel */
  462. static int spca500_synch310(struct gspca_dev *gspca_dev)
  463. {
  464. if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0) < 0) {
  465. PERR("Set packet size: set interface error");
  466. goto error;
  467. }
  468. spca500_ping310(gspca_dev);
  469. reg_r(gspca_dev, 0x0d00, 1);
  470. /* need alt setting here */
  471. PDEBUG(D_PACK, "ClickSmart310 sync alt: %d", gspca_dev->alt);
  472. /* Windoze use pipe with altsetting 6 why 7 here */
  473. if (usb_set_interface(gspca_dev->dev,
  474. gspca_dev->iface,
  475. gspca_dev->alt) < 0) {
  476. PERR("Set packet size: set interface error");
  477. goto error;
  478. }
  479. return 0;
  480. error:
  481. return -EBUSY;
  482. }
  483. static void spca500_reinit(struct gspca_dev *gspca_dev)
  484. {
  485. int err;
  486. __u8 Data;
  487. /* some unknown command from Aiptek pocket dv and family300 */
  488. reg_w(gspca_dev, 0x00, 0x0d01, 0x01);
  489. reg_w(gspca_dev, 0x00, 0x0d03, 0x00);
  490. reg_w(gspca_dev, 0x00, 0x0d02, 0x01);
  491. /* enable drop packet */
  492. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  493. err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840,
  494. qtable_pocketdv);
  495. if (err < 0)
  496. PERR("spca50x_setup_qtable failed on init");
  497. /* set qtable index */
  498. reg_w(gspca_dev, 0x00, 0x8880, 2);
  499. /* family cam Quicksmart stuff */
  500. reg_w(gspca_dev, 0x00, 0x800a, 0x00);
  501. /* Set agc transfer: synced between frames */
  502. reg_w(gspca_dev, 0x00, 0x820f, 0x01);
  503. /* Init SDRAM - needed for SDRAM access */
  504. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  505. /*Start init sequence or stream */
  506. reg_w(gspca_dev, 0, 0x8003, 0x00);
  507. /* switch to video camera mode */
  508. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  509. msleep(2000);
  510. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) {
  511. reg_r(gspca_dev, 0x816b, 1);
  512. Data = gspca_dev->usb_buf[0];
  513. reg_w(gspca_dev, 0x00, 0x816b, Data);
  514. }
  515. }
  516. /* this function is called at probe time */
  517. static int sd_config(struct gspca_dev *gspca_dev,
  518. const struct usb_device_id *id)
  519. {
  520. struct sd *sd = (struct sd *) gspca_dev;
  521. struct cam *cam;
  522. cam = &gspca_dev->cam;
  523. sd->subtype = id->driver_info;
  524. if (sd->subtype != LogitechClickSmart310) {
  525. cam->cam_mode = vga_mode;
  526. cam->nmodes = ARRAY_SIZE(vga_mode);
  527. } else {
  528. cam->cam_mode = sif_mode;
  529. cam->nmodes = ARRAY_SIZE(sif_mode);
  530. }
  531. return 0;
  532. }
  533. /* this function is called at probe and resume time */
  534. static int sd_init(struct gspca_dev *gspca_dev)
  535. {
  536. struct sd *sd = (struct sd *) gspca_dev;
  537. /* initialisation of spca500 based cameras is deferred */
  538. PDEBUG(D_STREAM, "SPCA500 init");
  539. if (sd->subtype == LogitechClickSmart310)
  540. spca500_clksmart310_init(gspca_dev);
  541. /* else
  542. spca500_initialise(gspca_dev); */
  543. PDEBUG(D_STREAM, "SPCA500 init done");
  544. return 0;
  545. }
  546. static int sd_start(struct gspca_dev *gspca_dev)
  547. {
  548. struct sd *sd = (struct sd *) gspca_dev;
  549. int err;
  550. __u8 Data;
  551. __u8 xmult, ymult;
  552. /* create the JPEG header */
  553. jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
  554. gspca_dev->pixfmt.width,
  555. 0x22); /* JPEG 411 */
  556. jpeg_set_qual(sd->jpeg_hdr, QUALITY);
  557. if (sd->subtype == LogitechClickSmart310) {
  558. xmult = 0x16;
  559. ymult = 0x12;
  560. } else {
  561. xmult = 0x28;
  562. ymult = 0x1e;
  563. }
  564. /* is there a sensor here ? */
  565. reg_r(gspca_dev, 0x8a04, 1);
  566. PDEBUG(D_STREAM, "Spca500 Sensor Address 0x%02x",
  567. gspca_dev->usb_buf[0]);
  568. PDEBUG(D_STREAM, "Spca500 curr_mode: %d Xmult: 0x%02x, Ymult: 0x%02x",
  569. gspca_dev->curr_mode, xmult, ymult);
  570. /* setup qtable */
  571. switch (sd->subtype) {
  572. case LogitechClickSmart310:
  573. spca500_setmode(gspca_dev, xmult, ymult);
  574. /* enable drop packet */
  575. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  576. reg_w(gspca_dev, 0x00, 0x8880, 3);
  577. err = spca50x_setup_qtable(gspca_dev,
  578. 0x00, 0x8800, 0x8840,
  579. qtable_creative_pccam);
  580. if (err < 0)
  581. PERR("spca50x_setup_qtable failed");
  582. /* Init SDRAM - needed for SDRAM access */
  583. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  584. /* switch to video camera mode */
  585. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  586. msleep(500);
  587. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
  588. PERR("reg_r_wait() failed");
  589. reg_r(gspca_dev, 0x816b, 1);
  590. Data = gspca_dev->usb_buf[0];
  591. reg_w(gspca_dev, 0x00, 0x816b, Data);
  592. spca500_synch310(gspca_dev);
  593. write_vector(gspca_dev, spca500_visual_defaults);
  594. spca500_setmode(gspca_dev, xmult, ymult);
  595. /* enable drop packet */
  596. err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  597. if (err < 0)
  598. PERR("failed to enable drop packet");
  599. reg_w(gspca_dev, 0x00, 0x8880, 3);
  600. err = spca50x_setup_qtable(gspca_dev,
  601. 0x00, 0x8800, 0x8840,
  602. qtable_creative_pccam);
  603. if (err < 0)
  604. PERR("spca50x_setup_qtable failed");
  605. /* Init SDRAM - needed for SDRAM access */
  606. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  607. /* switch to video camera mode */
  608. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  609. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
  610. PERR("reg_r_wait() failed");
  611. reg_r(gspca_dev, 0x816b, 1);
  612. Data = gspca_dev->usb_buf[0];
  613. reg_w(gspca_dev, 0x00, 0x816b, Data);
  614. break;
  615. case CreativePCCam300: /* Creative PC-CAM 300 640x480 CCD */
  616. case IntelPocketPCCamera: /* FIXME: Temporary fix for
  617. * Intel Pocket PC Camera
  618. * - NWG (Sat 29th March 2003) */
  619. /* do a full reset */
  620. err = spca500_full_reset(gspca_dev);
  621. if (err < 0)
  622. PERR("spca500_full_reset failed");
  623. /* enable drop packet */
  624. err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  625. if (err < 0)
  626. PERR("failed to enable drop packet");
  627. reg_w(gspca_dev, 0x00, 0x8880, 3);
  628. err = spca50x_setup_qtable(gspca_dev,
  629. 0x00, 0x8800, 0x8840,
  630. qtable_creative_pccam);
  631. if (err < 0)
  632. PERR("spca50x_setup_qtable failed");
  633. spca500_setmode(gspca_dev, xmult, ymult);
  634. reg_w(gspca_dev, 0x20, 0x0001, 0x0004);
  635. /* switch to video camera mode */
  636. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  637. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
  638. PERR("reg_r_wait() failed");
  639. reg_r(gspca_dev, 0x816b, 1);
  640. Data = gspca_dev->usb_buf[0];
  641. reg_w(gspca_dev, 0x00, 0x816b, Data);
  642. /* write_vector(gspca_dev, spca500_visual_defaults); */
  643. break;
  644. case KodakEZ200: /* Kodak EZ200 */
  645. /* do a full reset */
  646. err = spca500_full_reset(gspca_dev);
  647. if (err < 0)
  648. PERR("spca500_full_reset failed");
  649. /* enable drop packet */
  650. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  651. reg_w(gspca_dev, 0x00, 0x8880, 0);
  652. err = spca50x_setup_qtable(gspca_dev,
  653. 0x00, 0x8800, 0x8840,
  654. qtable_kodak_ez200);
  655. if (err < 0)
  656. PERR("spca50x_setup_qtable failed");
  657. spca500_setmode(gspca_dev, xmult, ymult);
  658. reg_w(gspca_dev, 0x20, 0x0001, 0x0004);
  659. /* switch to video camera mode */
  660. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  661. if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
  662. PERR("reg_r_wait() failed");
  663. reg_r(gspca_dev, 0x816b, 1);
  664. Data = gspca_dev->usb_buf[0];
  665. reg_w(gspca_dev, 0x00, 0x816b, Data);
  666. /* write_vector(gspca_dev, spca500_visual_defaults); */
  667. break;
  668. case BenqDC1016:
  669. case DLinkDSC350: /* FamilyCam 300 */
  670. case AiptekPocketDV: /* Aiptek PocketDV */
  671. case Gsmartmini: /*Mustek Gsmart Mini */
  672. case MustekGsmart300: /* Mustek Gsmart 300 */
  673. case PalmPixDC85:
  674. case Optimedia:
  675. case ToptroIndus:
  676. case AgfaCl20:
  677. spca500_reinit(gspca_dev);
  678. reg_w(gspca_dev, 0x00, 0x0d01, 0x01);
  679. /* enable drop packet */
  680. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  681. err = spca50x_setup_qtable(gspca_dev,
  682. 0x00, 0x8800, 0x8840, qtable_pocketdv);
  683. if (err < 0)
  684. PERR("spca50x_setup_qtable failed");
  685. reg_w(gspca_dev, 0x00, 0x8880, 2);
  686. /* familycam Quicksmart pocketDV stuff */
  687. reg_w(gspca_dev, 0x00, 0x800a, 0x00);
  688. /* Set agc transfer: synced between frames */
  689. reg_w(gspca_dev, 0x00, 0x820f, 0x01);
  690. /* Init SDRAM - needed for SDRAM access */
  691. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  692. spca500_setmode(gspca_dev, xmult, ymult);
  693. /* switch to video camera mode */
  694. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  695. reg_r_wait(gspca_dev, 0, 0x8000, 0x44);
  696. reg_r(gspca_dev, 0x816b, 1);
  697. Data = gspca_dev->usb_buf[0];
  698. reg_w(gspca_dev, 0x00, 0x816b, Data);
  699. break;
  700. case LogitechTraveler:
  701. case LogitechClickSmart510:
  702. reg_w(gspca_dev, 0x02, 0x00, 0x00);
  703. /* enable drop packet */
  704. reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
  705. err = spca50x_setup_qtable(gspca_dev,
  706. 0x00, 0x8800,
  707. 0x8840, qtable_creative_pccam);
  708. if (err < 0)
  709. PERR("spca50x_setup_qtable failed");
  710. reg_w(gspca_dev, 0x00, 0x8880, 3);
  711. reg_w(gspca_dev, 0x00, 0x800a, 0x00);
  712. /* Init SDRAM - needed for SDRAM access */
  713. reg_w(gspca_dev, 0x00, 0x870a, 0x04);
  714. spca500_setmode(gspca_dev, xmult, ymult);
  715. /* switch to video camera mode */
  716. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  717. reg_r_wait(gspca_dev, 0, 0x8000, 0x44);
  718. reg_r(gspca_dev, 0x816b, 1);
  719. Data = gspca_dev->usb_buf[0];
  720. reg_w(gspca_dev, 0x00, 0x816b, Data);
  721. write_vector(gspca_dev, Clicksmart510_defaults);
  722. break;
  723. }
  724. return 0;
  725. }
  726. static void sd_stopN(struct gspca_dev *gspca_dev)
  727. {
  728. reg_w(gspca_dev, 0, 0x8003, 0x00);
  729. /* switch to video camera mode */
  730. reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
  731. reg_r(gspca_dev, 0x8000, 1);
  732. PDEBUG(D_STREAM, "stop SPCA500 done reg8000: 0x%2x",
  733. gspca_dev->usb_buf[0]);
  734. }
  735. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  736. u8 *data, /* isoc packet */
  737. int len) /* iso packet length */
  738. {
  739. struct sd *sd = (struct sd *) gspca_dev;
  740. int i;
  741. static __u8 ffd9[] = {0xff, 0xd9};
  742. /* frames are jpeg 4.1.1 without 0xff escape */
  743. if (data[0] == 0xff) {
  744. if (data[1] != 0x01) { /* drop packet */
  745. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  746. return;
  747. }
  748. gspca_frame_add(gspca_dev, LAST_PACKET,
  749. ffd9, 2);
  750. /* put the JPEG header in the new frame */
  751. gspca_frame_add(gspca_dev, FIRST_PACKET,
  752. sd->jpeg_hdr, JPEG_HDR_SZ);
  753. data += SPCA500_OFFSET_DATA;
  754. len -= SPCA500_OFFSET_DATA;
  755. } else {
  756. data += 1;
  757. len -= 1;
  758. }
  759. /* add 0x00 after 0xff */
  760. i = 0;
  761. do {
  762. if (data[i] == 0xff) {
  763. gspca_frame_add(gspca_dev, INTER_PACKET,
  764. data, i + 1);
  765. len -= i;
  766. data += i;
  767. *data = 0x00;
  768. i = 0;
  769. }
  770. i++;
  771. } while (i < len);
  772. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  773. }
  774. static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
  775. {
  776. reg_w(gspca_dev, 0x00, 0x8167,
  777. (__u8) (val - 128));
  778. }
  779. static void setcontrast(struct gspca_dev *gspca_dev, s32 val)
  780. {
  781. reg_w(gspca_dev, 0x00, 0x8168, val);
  782. }
  783. static void setcolors(struct gspca_dev *gspca_dev, s32 val)
  784. {
  785. reg_w(gspca_dev, 0x00, 0x8169, val);
  786. }
  787. static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
  788. {
  789. struct gspca_dev *gspca_dev =
  790. container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
  791. gspca_dev->usb_err = 0;
  792. if (!gspca_dev->streaming)
  793. return 0;
  794. switch (ctrl->id) {
  795. case V4L2_CID_BRIGHTNESS:
  796. setbrightness(gspca_dev, ctrl->val);
  797. break;
  798. case V4L2_CID_CONTRAST:
  799. setcontrast(gspca_dev, ctrl->val);
  800. break;
  801. case V4L2_CID_SATURATION:
  802. setcolors(gspca_dev, ctrl->val);
  803. break;
  804. }
  805. return gspca_dev->usb_err;
  806. }
  807. static const struct v4l2_ctrl_ops sd_ctrl_ops = {
  808. .s_ctrl = sd_s_ctrl,
  809. };
  810. static int sd_init_controls(struct gspca_dev *gspca_dev)
  811. {
  812. struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
  813. gspca_dev->vdev.ctrl_handler = hdl;
  814. v4l2_ctrl_handler_init(hdl, 3);
  815. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  816. V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
  817. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  818. V4L2_CID_CONTRAST, 0, 63, 1, 31);
  819. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  820. V4L2_CID_SATURATION, 0, 63, 1, 31);
  821. if (hdl->error) {
  822. pr_err("Could not initialize controls\n");
  823. return hdl->error;
  824. }
  825. return 0;
  826. }
  827. /* sub-driver description */
  828. static const struct sd_desc sd_desc = {
  829. .name = MODULE_NAME,
  830. .config = sd_config,
  831. .init = sd_init,
  832. .init_controls = sd_init_controls,
  833. .start = sd_start,
  834. .stopN = sd_stopN,
  835. .pkt_scan = sd_pkt_scan,
  836. };
  837. /* -- module initialisation -- */
  838. static const struct usb_device_id device_table[] = {
  839. {USB_DEVICE(0x040a, 0x0300), .driver_info = KodakEZ200},
  840. {USB_DEVICE(0x041e, 0x400a), .driver_info = CreativePCCam300},
  841. {USB_DEVICE(0x046d, 0x0890), .driver_info = LogitechTraveler},
  842. {USB_DEVICE(0x046d, 0x0900), .driver_info = LogitechClickSmart310},
  843. {USB_DEVICE(0x046d, 0x0901), .driver_info = LogitechClickSmart510},
  844. {USB_DEVICE(0x04a5, 0x300c), .driver_info = BenqDC1016},
  845. {USB_DEVICE(0x04fc, 0x7333), .driver_info = PalmPixDC85},
  846. {USB_DEVICE(0x055f, 0xc200), .driver_info = MustekGsmart300},
  847. {USB_DEVICE(0x055f, 0xc220), .driver_info = Gsmartmini},
  848. {USB_DEVICE(0x06bd, 0x0404), .driver_info = AgfaCl20},
  849. {USB_DEVICE(0x06be, 0x0800), .driver_info = Optimedia},
  850. {USB_DEVICE(0x084d, 0x0003), .driver_info = DLinkDSC350},
  851. {USB_DEVICE(0x08ca, 0x0103), .driver_info = AiptekPocketDV},
  852. {USB_DEVICE(0x2899, 0x012c), .driver_info = ToptroIndus},
  853. {USB_DEVICE(0x8086, 0x0630), .driver_info = IntelPocketPCCamera},
  854. {}
  855. };
  856. MODULE_DEVICE_TABLE(usb, device_table);
  857. /* -- device connect -- */
  858. static int sd_probe(struct usb_interface *intf,
  859. const struct usb_device_id *id)
  860. {
  861. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  862. THIS_MODULE);
  863. }
  864. static struct usb_driver sd_driver = {
  865. .name = MODULE_NAME,
  866. .id_table = device_table,
  867. .probe = sd_probe,
  868. .disconnect = gspca_disconnect,
  869. #ifdef CONFIG_PM
  870. .suspend = gspca_suspend,
  871. .resume = gspca_resume,
  872. .reset_resume = gspca_resume,
  873. #endif
  874. };
  875. module_usb_driver(sd_driver);