spca500.c 31 KB

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