spca500.c 27 KB

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