spca500.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  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, 0)
  25. static const char version[] = "2.1.0";
  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. unsigned char 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. #define SD_BRIGHTNESS 0
  64. {
  65. {
  66. .id = V4L2_CID_BRIGHTNESS,
  67. .type = V4L2_CTRL_TYPE_INTEGER,
  68. .name = "Brightness",
  69. .minimum = 0,
  70. .maximum = 0xff,
  71. .step = 1,
  72. .default_value = 0x7f,
  73. },
  74. .set = sd_setbrightness,
  75. .get = sd_getbrightness,
  76. },
  77. #define SD_CONTRAST 1
  78. {
  79. {
  80. .id = V4L2_CID_CONTRAST,
  81. .type = V4L2_CTRL_TYPE_INTEGER,
  82. .name = "Contrast",
  83. .minimum = 0,
  84. .maximum = 255,
  85. .step = 1,
  86. .default_value = 127,
  87. },
  88. .set = sd_setcontrast,
  89. .get = sd_getcontrast,
  90. },
  91. #define SD_COLOR 2
  92. {
  93. {
  94. .id = V4L2_CID_SATURATION,
  95. .type = V4L2_CTRL_TYPE_INTEGER,
  96. .name = "Color",
  97. .minimum = 0,
  98. .maximum = 255,
  99. .step = 1,
  100. .default_value = 127,
  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 __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. {0, 0, 0}
  150. };
  151. static __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 unsigned char 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 unsigned char 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 unsigned char 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 spca5xxRegRead(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_write(struct usb_device *dev,
  352. __u16 req, __u16 index, __u16 value)
  353. {
  354. int ret;
  355. ret = usb_control_msg(dev,
  356. usb_sndctrlpipe(dev, 0),
  357. req,
  358. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  359. value, index, NULL, 0, 500);
  360. PDEBUG(D_USBO, "reg write: [0x%02x] = 0x%02x, 0x%x",
  361. index, value, ret);
  362. if (ret < 0)
  363. PDEBUG(D_ERR, "reg write: error %d", ret);
  364. return ret;
  365. }
  366. /* returns: negative is error, pos or zero is data */
  367. static int reg_read(struct usb_device *dev,
  368. __u16 req, /* bRequest */
  369. __u16 index, /* wIndex */
  370. __u16 length) /* wLength (1 or 2 only) */
  371. {
  372. int ret;
  373. __u8 buf[2];
  374. buf[1] = 0;
  375. ret = usb_control_msg(dev,
  376. usb_rcvctrlpipe(dev, 0),
  377. req,
  378. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  379. 0, /* value */
  380. index,
  381. buf, length,
  382. 500); /* timeout */
  383. if (ret < 0) {
  384. PDEBUG(D_ERR, "reg_read err %d", ret);
  385. return -1;
  386. }
  387. return (buf[1] << 8) + buf[0];
  388. }
  389. /*
  390. * Simple function to wait for a given 8-bit value to be returned from
  391. * a reg_read call.
  392. * Returns: negative is error or timeout, zero is success.
  393. */
  394. static int reg_readwait(struct usb_device *dev,
  395. __u16 reg, __u16 index, __u16 value)
  396. {
  397. int ret, cnt = 20;
  398. while (--cnt > 0) {
  399. ret = reg_read(dev, reg, index, 1);
  400. if (ret == value)
  401. return 0;
  402. msleep(50);
  403. }
  404. return -EIO;
  405. }
  406. static int write_vector(struct gspca_dev *gspca_dev,
  407. __u16 data[][3])
  408. {
  409. struct usb_device *dev = gspca_dev->dev;
  410. int ret, i = 0;
  411. while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) {
  412. ret = reg_write(dev, data[i][0], data[i][2], data[i][1]);
  413. if (ret < 0)
  414. return ret;
  415. i++;
  416. }
  417. return 0;
  418. }
  419. static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
  420. unsigned int request,
  421. unsigned int ybase,
  422. unsigned int cbase,
  423. unsigned char qtable[2][64])
  424. {
  425. struct usb_device *dev = gspca_dev->dev;
  426. int i, err;
  427. /* loop over y components */
  428. for (i = 0; i < 64; i++) {
  429. err = reg_write(dev, request, ybase + i, qtable[0][i]);
  430. if (err < 0)
  431. return err;
  432. }
  433. /* loop over c components */
  434. for (i = 0; i < 64; i++) {
  435. err = reg_write(dev, request, cbase + i, qtable[1][i]);
  436. if (err < 0)
  437. return err;
  438. }
  439. return 0;
  440. }
  441. static void spca500_ping310(struct gspca_dev *gspca_dev)
  442. {
  443. __u8 Data[2];
  444. spca5xxRegRead(gspca_dev->dev, 0x0d04, Data, 2);
  445. PDEBUG(D_PACK, "ClickSmart310 ping 0x0d04 0x%02x 0x%02x",
  446. Data[0], Data[1]);
  447. }
  448. static void spca500_clksmart310_init(struct gspca_dev *gspca_dev)
  449. {
  450. __u8 Data[2];
  451. spca5xxRegRead(gspca_dev->dev, 0x0d05, Data, 2);
  452. PDEBUG(D_PACK, "ClickSmart310 init 0x0d05 0x%02x 0x%02x", Data[0],
  453. Data[1]);
  454. reg_write(gspca_dev->dev, 0x00, 0x8167, 0x5a);
  455. spca500_ping310(gspca_dev);
  456. reg_write(gspca_dev->dev, 0x00, 0x8168, 0x22);
  457. reg_write(gspca_dev->dev, 0x00, 0x816a, 0xc0);
  458. reg_write(gspca_dev->dev, 0x00, 0x816b, 0x0b);
  459. reg_write(gspca_dev->dev, 0x00, 0x8169, 0x25);
  460. reg_write(gspca_dev->dev, 0x00, 0x8157, 0x5b);
  461. reg_write(gspca_dev->dev, 0x00, 0x8158, 0x5b);
  462. reg_write(gspca_dev->dev, 0x00, 0x813f, 0x03);
  463. reg_write(gspca_dev->dev, 0x00, 0x8151, 0x4a);
  464. reg_write(gspca_dev->dev, 0x00, 0x8153, 0x78);
  465. reg_write(gspca_dev->dev, 0x00, 0x0d01, 0x04);
  466. /* 00 for adjust shutter */
  467. reg_write(gspca_dev->dev, 0x00, 0x0d02, 0x01);
  468. reg_write(gspca_dev->dev, 0x00, 0x8169, 0x25);
  469. reg_write(gspca_dev->dev, 0x00, 0x0d01, 0x02);
  470. }
  471. static void spca500_setmode(struct gspca_dev *gspca_dev,
  472. __u8 xmult, __u8 ymult)
  473. {
  474. int mode;
  475. /* set x multiplier */
  476. reg_write(gspca_dev->dev, 0, 0x8001, xmult);
  477. /* set y multiplier */
  478. reg_write(gspca_dev->dev, 0, 0x8002, ymult);
  479. /* use compressed mode, VGA, with mode specific subsample */
  480. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode;
  481. reg_write(gspca_dev->dev, 0, 0x8003, mode << 4);
  482. }
  483. static int spca500_full_reset(struct gspca_dev *gspca_dev)
  484. {
  485. int err;
  486. /* send the reset command */
  487. err = reg_write(gspca_dev->dev, 0xe0, 0x0001, 0x0000);
  488. if (err < 0)
  489. return err;
  490. /* wait for the reset to complete */
  491. err = reg_readwait(gspca_dev->dev, 0x06, 0x0000, 0x0000);
  492. if (err < 0)
  493. return err;
  494. err = reg_write(gspca_dev->dev, 0xe0, 0x0000, 0x0000);
  495. if (err < 0)
  496. return err;
  497. err = reg_readwait(gspca_dev->dev, 0x06, 0, 0);
  498. if (err < 0) {
  499. PDEBUG(D_ERR, "reg_readwait() failed");
  500. return err;
  501. }
  502. /* all ok */
  503. return 0;
  504. }
  505. /* Synchro the Bridge with sensor */
  506. /* Maybe that will work on all spca500 chip */
  507. /* because i only own a clicksmart310 try for that chip */
  508. /* using spca50x_set_packet_size() cause an Ooops here */
  509. /* usb_set_interface from kernel 2.6.x clear all the urb stuff */
  510. /* up-port the same feature as in 2.4.x kernel */
  511. static int spca500_synch310(struct gspca_dev *gspca_dev)
  512. {
  513. __u8 Data;
  514. if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0) < 0) {
  515. PDEBUG(D_ERR, "Set packet size: set interface error");
  516. goto error;
  517. }
  518. spca500_ping310(gspca_dev);
  519. spca5xxRegRead(gspca_dev->dev, 0x0d00, &Data, 1);
  520. /* need alt setting here */
  521. PDEBUG(D_PACK, "ClickSmart310 sync alt: %d", gspca_dev->alt);
  522. /* Windoze use pipe with altsetting 6 why 7 here */
  523. if (usb_set_interface(gspca_dev->dev,
  524. gspca_dev->iface,
  525. gspca_dev->alt) < 0) {
  526. PDEBUG(D_ERR, "Set packet size: set interface error");
  527. goto error;
  528. }
  529. return 0;
  530. error:
  531. return -EBUSY;
  532. }
  533. static void spca500_reinit(struct gspca_dev *gspca_dev)
  534. {
  535. int err;
  536. __u8 Data;
  537. /* some unknow command from Aiptek pocket dv and family300 */
  538. reg_write(gspca_dev->dev, 0x00, 0x0d01, 0x01);
  539. reg_write(gspca_dev->dev, 0x00, 0x0d03, 0x00);
  540. reg_write(gspca_dev->dev, 0x00, 0x0d02, 0x01);
  541. /* enable drop packet */
  542. reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001);
  543. err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840,
  544. qtable_pocketdv);
  545. if (err < 0)
  546. PDEBUG(D_ERR|D_STREAM, "spca50x_setup_qtable failed on init");
  547. /* set qtable index */
  548. reg_write(gspca_dev->dev, 0x00, 0x8880, 2);
  549. /* family cam Quicksmart stuff */
  550. reg_write(gspca_dev->dev, 0x00, 0x800a, 0x00);
  551. /* Set agc transfer: synced inbetween frames */
  552. reg_write(gspca_dev->dev, 0x00, 0x820f, 0x01);
  553. /* Init SDRAM - needed for SDRAM access */
  554. reg_write(gspca_dev->dev, 0x00, 0x870a, 0x04);
  555. /*Start init sequence or stream */
  556. reg_write(gspca_dev->dev, 0, 0x8003, 0x00);
  557. /* switch to video camera mode */
  558. reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004);
  559. msleep(2000);
  560. if (reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44) != 0)
  561. spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1);
  562. reg_write(gspca_dev->dev, 0x00, 0x816b, Data);
  563. }
  564. /* this function is called at probe time */
  565. static int sd_config(struct gspca_dev *gspca_dev,
  566. const struct usb_device_id *id)
  567. {
  568. struct sd *sd = (struct sd *) gspca_dev;
  569. struct cam *cam;
  570. __u16 vendor;
  571. __u16 product;
  572. vendor = id->idVendor;
  573. product = id->idProduct;
  574. switch (vendor) {
  575. case 0x040a: /* Kodak cameras */
  576. /* switch (product) { */
  577. /* case 0x0300: */
  578. sd->subtype = KodakEZ200;
  579. /* break; */
  580. /* } */
  581. break;
  582. case 0x041e: /* Creative cameras */
  583. /* switch (product) { */
  584. /* case 0x400a: */
  585. sd->subtype = CreativePCCam300;
  586. /* break; */
  587. /* } */
  588. break;
  589. case 0x046d: /* Logitech Labtec */
  590. switch (product) {
  591. case 0x0890:
  592. sd->subtype = LogitechTraveler;
  593. break;
  594. case 0x0900:
  595. sd->subtype = LogitechClickSmart310;
  596. break;
  597. case 0x0901:
  598. sd->subtype = LogitechClickSmart510;
  599. break;
  600. }
  601. break;
  602. case 0x04a5: /* Benq */
  603. /* switch (product) { */
  604. /* case 0x300c: */
  605. sd->subtype = BenqDC1016;
  606. /* break; */
  607. /* } */
  608. break;
  609. case 0x04fc: /* SunPlus */
  610. /* switch (product) { */
  611. /* case 0x7333: */
  612. sd->subtype = PalmPixDC85;
  613. /* break; */
  614. /* } */
  615. break;
  616. case 0x055f: /* Mustek cameras */
  617. switch (product) {
  618. case 0xc200:
  619. sd->subtype = MustekGsmart300;
  620. break;
  621. case 0xc220:
  622. sd->subtype = Gsmartmini;
  623. break;
  624. }
  625. break;
  626. case 0x06bd: /* Agfa Cl20 */
  627. /* switch (product) { */
  628. /* case 0x0404: */
  629. sd->subtype = AgfaCl20;
  630. /* break; */
  631. /* } */
  632. break;
  633. case 0x06be: /* Optimedia */
  634. /* switch (product) { */
  635. /* case 0x0800: */
  636. sd->subtype = Optimedia;
  637. /* break; */
  638. /* } */
  639. break;
  640. case 0x084d: /* D-Link / Minton */
  641. /* switch (product) { */
  642. /* case 0x0003: * DSC-350 / S-Cam F5 */
  643. sd->subtype = DLinkDSC350;
  644. /* break; */
  645. /* } */
  646. break;
  647. case 0x08ca: /* Aiptek */
  648. /* switch (product) { */
  649. /* case 0x0103: */
  650. sd->subtype = AiptekPocketDV;
  651. /* break; */
  652. /* } */
  653. break;
  654. case 0x2899: /* ToptroIndustrial */
  655. /* switch (product) { */
  656. /* case 0x012c: */
  657. sd->subtype = ToptroIndus;
  658. /* break; */
  659. /* } */
  660. break;
  661. case 0x8086: /* Intel */
  662. /* switch (product) { */
  663. /* case 0x0630: * Pocket PC Camera */
  664. sd->subtype = IntelPocketPCCamera;
  665. /* break; */
  666. /* } */
  667. break;
  668. }
  669. cam = &gspca_dev->cam;
  670. cam->dev_name = (char *) id->driver_info;
  671. cam->epaddr = 0x01;
  672. if (sd->subtype != LogitechClickSmart310) {
  673. cam->cam_mode = vga_mode;
  674. cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
  675. } else {
  676. cam->cam_mode = sif_mode;
  677. cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
  678. }
  679. sd->qindex = 5;
  680. sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
  681. sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
  682. sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
  683. return 0;
  684. }
  685. /* this function is called at open time */
  686. static int sd_open(struct gspca_dev *gspca_dev)
  687. {
  688. struct sd *sd = (struct sd *) gspca_dev;
  689. /* initialisation of spca500 based cameras is deferred */
  690. PDEBUG(D_STREAM, "SPCA500 init");
  691. if (sd->subtype == LogitechClickSmart310)
  692. spca500_clksmart310_init(gspca_dev);
  693. /* else
  694. spca500_initialise(gspca_dev); */
  695. PDEBUG(D_STREAM, "SPCA500 init done");
  696. return 0;
  697. }
  698. static void sd_start(struct gspca_dev *gspca_dev)
  699. {
  700. struct sd *sd = (struct sd *) gspca_dev;
  701. int err;
  702. __u8 Data;
  703. __u8 xmult, ymult;
  704. if (sd->subtype == LogitechClickSmart310) {
  705. xmult = 0x16;
  706. ymult = 0x12;
  707. } else {
  708. xmult = 0x28;
  709. ymult = 0x1e;
  710. }
  711. /* is there a sensor here ? */
  712. spca5xxRegRead(gspca_dev->dev, 0x8a04, &Data, 1);
  713. PDEBUG(D_STREAM, "Spca500 Sensor Address 0x%02X", Data);
  714. PDEBUG(D_STREAM, "Spca500 curr_mode: %d Xmult: 0x%02X, Ymult: 0x%02X",
  715. gspca_dev->curr_mode, xmult, ymult);
  716. /* setup qtable */
  717. switch (sd->subtype) {
  718. case LogitechClickSmart310:
  719. spca500_setmode(gspca_dev, xmult, ymult);
  720. /* enable drop packet */
  721. reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001);
  722. reg_write(gspca_dev->dev, 0x00, 0x8880, 3);
  723. err = spca50x_setup_qtable(gspca_dev,
  724. 0x00, 0x8800, 0x8840,
  725. qtable_creative_pccam);
  726. if (err < 0)
  727. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  728. /* Init SDRAM - needed for SDRAM access */
  729. reg_write(gspca_dev->dev, 0x00, 0x870a, 0x04);
  730. /* switch to video camera mode */
  731. reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004);
  732. msleep(500);
  733. if (reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44) != 0)
  734. PDEBUG(D_ERR, "reg_readwait() failed");
  735. spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1);
  736. reg_write(gspca_dev->dev, 0x00, 0x816b, Data);
  737. spca500_synch310(gspca_dev);
  738. write_vector(gspca_dev, spca500_visual_defaults);
  739. spca500_setmode(gspca_dev, xmult, ymult);
  740. /* enable drop packet */
  741. reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001);
  742. PDEBUG(D_ERR, "failed to enable drop packet");
  743. reg_write(gspca_dev->dev, 0x00, 0x8880, 3);
  744. err = spca50x_setup_qtable(gspca_dev,
  745. 0x00, 0x8800, 0x8840,
  746. qtable_creative_pccam);
  747. if (err < 0)
  748. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  749. /* Init SDRAM - needed for SDRAM access */
  750. reg_write(gspca_dev->dev, 0x00, 0x870a, 0x04);
  751. /* switch to video camera mode */
  752. reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004);
  753. if (reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44) != 0)
  754. PDEBUG(D_ERR, "reg_readwait() failed");
  755. spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1);
  756. reg_write(gspca_dev->dev, 0x00, 0x816b, Data);
  757. break;
  758. case CreativePCCam300: /* Creative PC-CAM 300 640x480 CCD */
  759. case IntelPocketPCCamera: /* FIXME: Temporary fix for
  760. * Intel Pocket PC Camera
  761. * - NWG (Sat 29th March 2003) */
  762. /* do a full reset */
  763. err = spca500_full_reset(gspca_dev);
  764. if (err < 0)
  765. PDEBUG(D_ERR, "spca500_full_reset failed");
  766. /* enable drop packet */
  767. err = reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001);
  768. if (err < 0)
  769. PDEBUG(D_ERR, "failed to enable drop packet");
  770. reg_write(gspca_dev->dev, 0x00, 0x8880, 3);
  771. err = spca50x_setup_qtable(gspca_dev,
  772. 0x00, 0x8800, 0x8840,
  773. qtable_creative_pccam);
  774. if (err < 0)
  775. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  776. spca500_setmode(gspca_dev, xmult, ymult);
  777. reg_write(gspca_dev->dev, 0x20, 0x0001, 0x0004);
  778. /* switch to video camera mode */
  779. reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004);
  780. if (reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44) != 0)
  781. PDEBUG(D_ERR, "reg_readwait() failed");
  782. spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1);
  783. reg_write(gspca_dev->dev, 0x00, 0x816b, Data);
  784. /* write_vector(gspca_dev, spca500_visual_defaults); */
  785. break;
  786. case KodakEZ200: /* Kodak EZ200 */
  787. /* do a full reset */
  788. err = spca500_full_reset(gspca_dev);
  789. if (err < 0)
  790. PDEBUG(D_ERR, "spca500_full_reset failed");
  791. /* enable drop packet */
  792. reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001);
  793. reg_write(gspca_dev->dev, 0x00, 0x8880, 0);
  794. err = spca50x_setup_qtable(gspca_dev,
  795. 0x00, 0x8800, 0x8840,
  796. qtable_kodak_ez200);
  797. if (err < 0)
  798. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  799. spca500_setmode(gspca_dev, xmult, ymult);
  800. reg_write(gspca_dev->dev, 0x20, 0x0001, 0x0004);
  801. /* switch to video camera mode */
  802. reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004);
  803. if (reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44) != 0)
  804. PDEBUG(D_ERR, "reg_readwait() failed");
  805. spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1);
  806. reg_write(gspca_dev->dev, 0x00, 0x816b, Data);
  807. /* write_vector(gspca_dev, spca500_visual_defaults); */
  808. break;
  809. case BenqDC1016:
  810. case DLinkDSC350: /* FamilyCam 300 */
  811. case AiptekPocketDV: /* Aiptek PocketDV */
  812. case Gsmartmini: /*Mustek Gsmart Mini */
  813. case MustekGsmart300: /* Mustek Gsmart 300 */
  814. case PalmPixDC85:
  815. case Optimedia:
  816. case ToptroIndus:
  817. case AgfaCl20:
  818. spca500_reinit(gspca_dev);
  819. reg_write(gspca_dev->dev, 0x00, 0x0d01, 0x01);
  820. /* enable drop packet */
  821. reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001);
  822. err = spca50x_setup_qtable(gspca_dev,
  823. 0x00, 0x8800, 0x8840, qtable_pocketdv);
  824. if (err < 0)
  825. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  826. reg_write(gspca_dev->dev, 0x00, 0x8880, 2);
  827. /* familycam Quicksmart pocketDV stuff */
  828. reg_write(gspca_dev->dev, 0x00, 0x800a, 0x00);
  829. /* Set agc transfer: synced inbetween frames */
  830. reg_write(gspca_dev->dev, 0x00, 0x820f, 0x01);
  831. /* Init SDRAM - needed for SDRAM access */
  832. reg_write(gspca_dev->dev, 0x00, 0x870a, 0x04);
  833. spca500_setmode(gspca_dev, xmult, ymult);
  834. /* switch to video camera mode */
  835. reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004);
  836. reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44);
  837. spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1);
  838. reg_write(gspca_dev->dev, 0x00, 0x816b, Data);
  839. break;
  840. case LogitechTraveler:
  841. case LogitechClickSmart510:
  842. reg_write(gspca_dev->dev, 0x02, 0x00, 0x00);
  843. /* enable drop packet */
  844. reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001);
  845. err = spca50x_setup_qtable(gspca_dev,
  846. 0x00, 0x8800,
  847. 0x8840, qtable_creative_pccam);
  848. if (err < 0)
  849. PDEBUG(D_ERR, "spca50x_setup_qtable failed");
  850. reg_write(gspca_dev->dev, 0x00, 0x8880, 3);
  851. reg_write(gspca_dev->dev, 0x00, 0x800a, 0x00);
  852. /* Init SDRAM - needed for SDRAM access */
  853. reg_write(gspca_dev->dev, 0x00, 0x870a, 0x04);
  854. spca500_setmode(gspca_dev, xmult, ymult);
  855. /* switch to video camera mode */
  856. reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004);
  857. reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44);
  858. spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1);
  859. reg_write(gspca_dev->dev, 0x00, 0x816b, Data);
  860. write_vector(gspca_dev, Clicksmart510_defaults);
  861. break;
  862. }
  863. }
  864. static void sd_stopN(struct gspca_dev *gspca_dev)
  865. {
  866. __u8 data = 0;
  867. reg_write(gspca_dev->dev, 0, 0x8003, 0x00);
  868. /* switch to video camera mode */
  869. reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004);
  870. spca5xxRegRead(gspca_dev->dev, 0x8000, &data, 1);
  871. PDEBUG(D_STREAM, "stop SPCA500 done reg8000: 0x%2x", data);
  872. }
  873. static void sd_stop0(struct gspca_dev *gspca_dev)
  874. {
  875. }
  876. static void sd_close(struct gspca_dev *gspca_dev)
  877. {
  878. }
  879. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  880. struct gspca_frame *frame, /* target */
  881. unsigned char *data, /* isoc packet */
  882. int len) /* iso packet length */
  883. {
  884. struct sd *sd = (struct sd *) gspca_dev;
  885. int i;
  886. unsigned char *s, *d;
  887. static unsigned char ffd9[] = {0xff, 0xd9};
  888. /* frames are jpeg 4.1.1 without 0xff escape */
  889. if (data[0] == 0xff) {
  890. if (data[1] != 0x01) { /* drop packet */
  891. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  892. return;
  893. }
  894. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  895. ffd9, 2);
  896. /* put the JPEG header in the new frame */
  897. jpeg_put_header(gspca_dev, frame,
  898. ((struct sd *) gspca_dev)->qindex,
  899. 0x22);
  900. data += SPCA500_OFFSET_DATA;
  901. len -= SPCA500_OFFSET_DATA;
  902. } else {
  903. data += 1;
  904. len -= 1;
  905. }
  906. /* add 0x00 after 0xff */
  907. for (i = len; --i >= 0; )
  908. if (data[i] == 0xff)
  909. break;
  910. if (i < 0) { /* no 0xff */
  911. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  912. return;
  913. }
  914. s = data;
  915. d = sd->packet;
  916. for (i = 0; i < len; i++) {
  917. *d++ = *s++;
  918. if (s[-1] == 0xff)
  919. *d++ = 0x00;
  920. }
  921. gspca_frame_add(gspca_dev, INTER_PACKET, frame,
  922. sd->packet, d - sd->packet);
  923. }
  924. static void setbrightness(struct gspca_dev *gspca_dev)
  925. {
  926. struct sd *sd = (struct sd *) gspca_dev;
  927. reg_write(gspca_dev->dev, 0x00, 0x8167,
  928. (__u8) (sd->brightness - 128));
  929. }
  930. static void getbrightness(struct gspca_dev *gspca_dev)
  931. {
  932. struct sd *sd = (struct sd *) gspca_dev;
  933. sd->brightness = reg_read(gspca_dev->dev, 0x00, 0x8167, 1) + 128;
  934. }
  935. static void setcontrast(struct gspca_dev *gspca_dev)
  936. {
  937. struct sd *sd = (struct sd *) gspca_dev;
  938. reg_write(gspca_dev->dev, 0x00, 0x8168, sd->contrast >> 2);
  939. }
  940. static void getcontrast(struct gspca_dev *gspca_dev)
  941. {
  942. struct sd *sd = (struct sd *) gspca_dev;
  943. sd->contrast = reg_read(gspca_dev->dev, 0x0, 0x8168, 1) << 2;
  944. }
  945. static void setcolors(struct gspca_dev *gspca_dev)
  946. {
  947. struct sd *sd = (struct sd *) gspca_dev;
  948. reg_write(gspca_dev->dev, 0x00, 0x8169, sd->colors >> 2);
  949. }
  950. static void getcolors(struct gspca_dev *gspca_dev)
  951. {
  952. struct sd *sd = (struct sd *) gspca_dev;
  953. sd->colors = reg_read(gspca_dev->dev, 0x0, 0x8169, 1) << 2;
  954. }
  955. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  956. {
  957. struct sd *sd = (struct sd *) gspca_dev;
  958. sd->brightness = val;
  959. if (gspca_dev->streaming)
  960. setbrightness(gspca_dev);
  961. return 0;
  962. }
  963. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  964. {
  965. struct sd *sd = (struct sd *) gspca_dev;
  966. getbrightness(gspca_dev);
  967. *val = sd->brightness;
  968. return 0;
  969. }
  970. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  971. {
  972. struct sd *sd = (struct sd *) gspca_dev;
  973. sd->contrast = val;
  974. if (gspca_dev->streaming)
  975. setcontrast(gspca_dev);
  976. return 0;
  977. }
  978. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  979. {
  980. struct sd *sd = (struct sd *) gspca_dev;
  981. getcontrast(gspca_dev);
  982. *val = sd->contrast;
  983. return 0;
  984. }
  985. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  986. {
  987. struct sd *sd = (struct sd *) gspca_dev;
  988. sd->colors = val;
  989. if (gspca_dev->streaming)
  990. setcolors(gspca_dev);
  991. return 0;
  992. }
  993. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  994. {
  995. struct sd *sd = (struct sd *) gspca_dev;
  996. getcolors(gspca_dev);
  997. *val = sd->colors;
  998. return 0;
  999. }
  1000. /* sub-driver description */
  1001. static struct sd_desc sd_desc = {
  1002. .name = MODULE_NAME,
  1003. .ctrls = sd_ctrls,
  1004. .nctrls = sizeof sd_ctrls / sizeof sd_ctrls[0],
  1005. .config = sd_config,
  1006. .open = sd_open,
  1007. .start = sd_start,
  1008. .stopN = sd_stopN,
  1009. .stop0 = sd_stop0,
  1010. .close = sd_close,
  1011. .pkt_scan = sd_pkt_scan,
  1012. };
  1013. /* -- module initialisation -- */
  1014. #define DVNM(name) .driver_info = (kernel_ulong_t) name
  1015. static __devinitdata struct usb_device_id device_table[] = {
  1016. {USB_DEVICE(0x040a, 0x0300), DVNM("Kodak EZ200")},
  1017. {USB_DEVICE(0x041e, 0x400a), DVNM("Creative PC-CAM 300")},
  1018. {USB_DEVICE(0x046d, 0x0890), DVNM("Logitech QuickCam traveler")},
  1019. {USB_DEVICE(0x046d, 0x0900), DVNM("Logitech Inc. ClickSmart 310")},
  1020. {USB_DEVICE(0x046d, 0x0901), DVNM("Logitech Inc. ClickSmart 510")},
  1021. {USB_DEVICE(0x04a5, 0x300c), DVNM("Benq DC1016")},
  1022. {USB_DEVICE(0x04fc, 0x7333), DVNM("PalmPixDC85")},
  1023. {USB_DEVICE(0x055f, 0xc200), DVNM("Mustek Gsmart 300")},
  1024. {USB_DEVICE(0x055f, 0xc220), DVNM("Gsmart Mini")},
  1025. {USB_DEVICE(0x06bd, 0x0404), DVNM("Agfa CL20")},
  1026. {USB_DEVICE(0x06be, 0x0800), DVNM("Optimedia")},
  1027. {USB_DEVICE(0x084d, 0x0003), DVNM("D-Link DSC-350")},
  1028. {USB_DEVICE(0x08ca, 0x0103), DVNM("Aiptek PocketDV")},
  1029. {USB_DEVICE(0x2899, 0x012c), DVNM("Toptro Industrial")},
  1030. {USB_DEVICE(0x8086, 0x0630), DVNM("Intel Pocket PC Camera")},
  1031. {}
  1032. };
  1033. MODULE_DEVICE_TABLE(usb, device_table);
  1034. /* -- device connect -- */
  1035. static int sd_probe(struct usb_interface *intf,
  1036. const struct usb_device_id *id)
  1037. {
  1038. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1039. THIS_MODULE);
  1040. }
  1041. static struct usb_driver sd_driver = {
  1042. .name = MODULE_NAME,
  1043. .id_table = device_table,
  1044. .probe = sd_probe,
  1045. .disconnect = gspca_disconnect,
  1046. };
  1047. /* -- module insert / remove -- */
  1048. static int __init sd_mod_init(void)
  1049. {
  1050. if (usb_register(&sd_driver) < 0)
  1051. return -1;
  1052. PDEBUG(D_PROBE, "v%s registered", version);
  1053. return 0;
  1054. }
  1055. static void __exit sd_mod_exit(void)
  1056. {
  1057. usb_deregister(&sd_driver);
  1058. PDEBUG(D_PROBE, "deregistered");
  1059. }
  1060. module_init(sd_mod_init);
  1061. module_exit(sd_mod_exit);