spca500.c 29 KB

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