ov534.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  1. /*
  2. * ov534-ov772x gspca driver
  3. *
  4. * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
  5. * Copyright (C) 2008 Jim Paris <jim@jtan.com>
  6. * Copyright (C) 2009 Jean-Francois Moine http://moinejf.free.fr
  7. *
  8. * Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
  9. * USB protocol reverse engineered by Jim Paris <jim@jtan.com>
  10. * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
  11. *
  12. * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr
  13. * PS3 Eye camera, brightness, contrast, hue, AWB control added
  14. * by Max Thrun <bear24rw@gmail.com>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. */
  30. #define MODULE_NAME "ov534"
  31. #include "gspca.h"
  32. #define OV534_REG_ADDRESS 0xf1 /* sensor address */
  33. #define OV534_REG_SUBADDR 0xf2
  34. #define OV534_REG_WRITE 0xf3
  35. #define OV534_REG_READ 0xf4
  36. #define OV534_REG_OPERATION 0xf5
  37. #define OV534_REG_STATUS 0xf6
  38. #define OV534_OP_WRITE_3 0x37
  39. #define OV534_OP_WRITE_2 0x33
  40. #define OV534_OP_READ_2 0xf9
  41. #define CTRL_TIMEOUT 500
  42. MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
  43. MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver");
  44. MODULE_LICENSE("GPL");
  45. /* specific webcam descriptor */
  46. struct sd {
  47. struct gspca_dev gspca_dev; /* !! must be the first item */
  48. __u32 last_pts;
  49. u16 last_fid;
  50. u8 frame_rate;
  51. u8 brightness;
  52. u8 contrast;
  53. u8 gain;
  54. u8 exposure;
  55. u8 agc;
  56. u8 awb;
  57. u8 aec;
  58. s8 sharpness;
  59. u8 hflip;
  60. u8 vflip;
  61. };
  62. /* V4L2 controls supported by the driver */
  63. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
  64. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
  65. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
  66. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
  67. static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val);
  68. static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val);
  69. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
  70. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
  71. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
  72. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
  73. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
  74. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
  75. static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val);
  76. static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val);
  77. static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val);
  78. static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val);
  79. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  80. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  81. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  82. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  83. static const struct ctrl sd_ctrls[] = {
  84. { /* 0 */
  85. {
  86. .id = V4L2_CID_BRIGHTNESS,
  87. .type = V4L2_CTRL_TYPE_INTEGER,
  88. .name = "Brightness",
  89. .minimum = 0,
  90. .maximum = 255,
  91. .step = 1,
  92. #define BRIGHTNESS_DEF 0
  93. .default_value = BRIGHTNESS_DEF,
  94. },
  95. .set = sd_setbrightness,
  96. .get = sd_getbrightness,
  97. },
  98. { /* 1 */
  99. {
  100. .id = V4L2_CID_CONTRAST,
  101. .type = V4L2_CTRL_TYPE_INTEGER,
  102. .name = "Contrast",
  103. .minimum = 0,
  104. .maximum = 255,
  105. .step = 1,
  106. #define CONTRAST_DEF 32
  107. .default_value = CONTRAST_DEF,
  108. },
  109. .set = sd_setcontrast,
  110. .get = sd_getcontrast,
  111. },
  112. { /* 2 */
  113. {
  114. .id = V4L2_CID_GAIN,
  115. .type = V4L2_CTRL_TYPE_INTEGER,
  116. .name = "Main Gain",
  117. .minimum = 0,
  118. .maximum = 63,
  119. .step = 1,
  120. #define GAIN_DEF 20
  121. .default_value = GAIN_DEF,
  122. },
  123. .set = sd_setgain,
  124. .get = sd_getgain,
  125. },
  126. { /* 3 */
  127. {
  128. .id = V4L2_CID_EXPOSURE,
  129. .type = V4L2_CTRL_TYPE_INTEGER,
  130. .name = "Exposure",
  131. .minimum = 0,
  132. .maximum = 255,
  133. .step = 1,
  134. #define EXPO_DEF 120
  135. .default_value = EXPO_DEF,
  136. },
  137. .set = sd_setexposure,
  138. .get = sd_getexposure,
  139. },
  140. { /* 4 */
  141. {
  142. .id = V4L2_CID_AUTOGAIN,
  143. .type = V4L2_CTRL_TYPE_BOOLEAN,
  144. .name = "Auto Gain",
  145. .minimum = 0,
  146. .maximum = 1,
  147. .step = 1,
  148. #define AGC_DEF 1
  149. .default_value = AGC_DEF,
  150. },
  151. .set = sd_setagc,
  152. .get = sd_getagc,
  153. },
  154. #define AWB_IDX 5
  155. { /* 5 */
  156. {
  157. .id = V4L2_CID_AUTO_WHITE_BALANCE,
  158. .type = V4L2_CTRL_TYPE_BOOLEAN,
  159. .name = "Auto White Balance",
  160. .minimum = 0,
  161. .maximum = 1,
  162. .step = 1,
  163. #define AWB_DEF 0
  164. .default_value = AWB_DEF,
  165. },
  166. .set = sd_setawb,
  167. .get = sd_getawb,
  168. },
  169. { /* 6 */
  170. {
  171. .id = V4L2_CID_EXPOSURE_AUTO,
  172. .type = V4L2_CTRL_TYPE_BOOLEAN,
  173. .name = "Auto Exposure",
  174. .minimum = 0,
  175. .maximum = 1,
  176. .step = 1,
  177. #define AEC_DEF 1
  178. .default_value = AEC_DEF,
  179. },
  180. .set = sd_setaec,
  181. .get = sd_getaec,
  182. },
  183. { /* 7 */
  184. {
  185. .id = V4L2_CID_SHARPNESS,
  186. .type = V4L2_CTRL_TYPE_INTEGER,
  187. .name = "Sharpness",
  188. .minimum = 0,
  189. .maximum = 63,
  190. .step = 1,
  191. #define SHARPNESS_DEF 0
  192. .default_value = SHARPNESS_DEF,
  193. },
  194. .set = sd_setsharpness,
  195. .get = sd_getsharpness,
  196. },
  197. { /* 8 */
  198. {
  199. .id = V4L2_CID_HFLIP,
  200. .type = V4L2_CTRL_TYPE_BOOLEAN,
  201. .name = "HFlip",
  202. .minimum = 0,
  203. .maximum = 1,
  204. .step = 1,
  205. #define HFLIP_DEF 0
  206. .default_value = HFLIP_DEF,
  207. },
  208. .set = sd_sethflip,
  209. .get = sd_gethflip,
  210. },
  211. { /* 9 */
  212. {
  213. .id = V4L2_CID_VFLIP,
  214. .type = V4L2_CTRL_TYPE_BOOLEAN,
  215. .name = "VFlip",
  216. .minimum = 0,
  217. .maximum = 1,
  218. .step = 1,
  219. #define VFLIP_DEF 0
  220. .default_value = VFLIP_DEF,
  221. },
  222. .set = sd_setvflip,
  223. .get = sd_getvflip,
  224. },
  225. };
  226. static const struct v4l2_pix_format ov772x_mode[] = {
  227. {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
  228. .bytesperline = 320 * 2,
  229. .sizeimage = 320 * 240 * 2,
  230. .colorspace = V4L2_COLORSPACE_SRGB,
  231. .priv = 1},
  232. {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
  233. .bytesperline = 640 * 2,
  234. .sizeimage = 640 * 480 * 2,
  235. .colorspace = V4L2_COLORSPACE_SRGB,
  236. .priv = 0},
  237. };
  238. static const u8 qvga_rates[] = {125, 100, 75, 60, 50, 40, 30};
  239. static const u8 vga_rates[] = {60, 50, 40, 30, 15};
  240. static const struct framerates ov772x_framerates[] = {
  241. { /* 320x240 */
  242. .rates = qvga_rates,
  243. .nrates = ARRAY_SIZE(qvga_rates),
  244. },
  245. { /* 640x480 */
  246. .rates = vga_rates,
  247. .nrates = ARRAY_SIZE(vga_rates),
  248. },
  249. };
  250. static const u8 bridge_init[][2] = {
  251. { 0xc2, 0x0c },
  252. { 0x88, 0xf8 },
  253. { 0xc3, 0x69 },
  254. { 0x89, 0xff },
  255. { 0x76, 0x03 },
  256. { 0x92, 0x01 },
  257. { 0x93, 0x18 },
  258. { 0x94, 0x10 },
  259. { 0x95, 0x10 },
  260. { 0xe2, 0x00 },
  261. { 0xe7, 0x3e },
  262. { 0x96, 0x00 },
  263. { 0x97, 0x20 },
  264. { 0x97, 0x20 },
  265. { 0x97, 0x20 },
  266. { 0x97, 0x0a },
  267. { 0x97, 0x3f },
  268. { 0x97, 0x4a },
  269. { 0x97, 0x20 },
  270. { 0x97, 0x15 },
  271. { 0x97, 0x0b },
  272. { 0x8e, 0x40 },
  273. { 0x1f, 0x81 },
  274. { 0x34, 0x05 },
  275. { 0xe3, 0x04 },
  276. { 0x88, 0x00 },
  277. { 0x89, 0x00 },
  278. { 0x76, 0x00 },
  279. { 0xe7, 0x2e },
  280. { 0x31, 0xf9 },
  281. { 0x25, 0x42 },
  282. { 0x21, 0xf0 },
  283. { 0x1c, 0x00 },
  284. { 0x1d, 0x40 },
  285. { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
  286. { 0x1d, 0x00 }, /* payload size */
  287. { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
  288. { 0x1d, 0x58 }, /* frame size */
  289. { 0x1d, 0x00 }, /* frame size */
  290. { 0x1c, 0x0a },
  291. { 0x1d, 0x08 }, /* turn on UVC header */
  292. { 0x1d, 0x0e }, /* .. */
  293. { 0x8d, 0x1c },
  294. { 0x8e, 0x80 },
  295. { 0xe5, 0x04 },
  296. { 0xc0, 0x50 },
  297. { 0xc1, 0x3c },
  298. { 0xc2, 0x0c },
  299. };
  300. static const u8 sensor_init[][2] = {
  301. { 0x12, 0x80 },
  302. { 0x11, 0x01 },
  303. /*fixme: better have a delay?*/
  304. { 0x11, 0x01 },
  305. { 0x11, 0x01 },
  306. { 0x11, 0x01 },
  307. { 0x11, 0x01 },
  308. { 0x11, 0x01 },
  309. { 0x11, 0x01 },
  310. { 0x11, 0x01 },
  311. { 0x11, 0x01 },
  312. { 0x11, 0x01 },
  313. { 0x11, 0x01 },
  314. { 0x3d, 0x03 },
  315. { 0x17, 0x26 },
  316. { 0x18, 0xa0 },
  317. { 0x19, 0x07 },
  318. { 0x1a, 0xf0 },
  319. { 0x32, 0x00 },
  320. { 0x29, 0xa0 },
  321. { 0x2c, 0xf0 },
  322. { 0x65, 0x20 },
  323. { 0x11, 0x01 },
  324. { 0x42, 0x7f },
  325. { 0x63, 0xaa }, /* AWB - was e0 */
  326. { 0x64, 0xff },
  327. { 0x66, 0x00 },
  328. { 0x13, 0xf0 }, /* com8 */
  329. { 0x0d, 0x41 },
  330. { 0x0f, 0xc5 },
  331. { 0x14, 0x11 },
  332. { 0x22, 0x7f },
  333. { 0x23, 0x03 },
  334. { 0x24, 0x40 },
  335. { 0x25, 0x30 },
  336. { 0x26, 0xa1 },
  337. { 0x2a, 0x00 },
  338. { 0x2b, 0x00 },
  339. { 0x6b, 0xaa },
  340. { 0x13, 0xff }, /* AWB */
  341. { 0x90, 0x05 },
  342. { 0x91, 0x01 },
  343. { 0x92, 0x03 },
  344. { 0x93, 0x00 },
  345. { 0x94, 0x60 },
  346. { 0x95, 0x3c },
  347. { 0x96, 0x24 },
  348. { 0x97, 0x1e },
  349. { 0x98, 0x62 },
  350. { 0x99, 0x80 },
  351. { 0x9a, 0x1e },
  352. { 0x9b, 0x08 },
  353. { 0x9c, 0x20 },
  354. { 0x9e, 0x81 },
  355. { 0xa6, 0x04 },
  356. { 0x7e, 0x0c },
  357. { 0x7f, 0x16 },
  358. { 0x80, 0x2a },
  359. { 0x81, 0x4e },
  360. { 0x82, 0x61 },
  361. { 0x83, 0x6f },
  362. { 0x84, 0x7b },
  363. { 0x85, 0x86 },
  364. { 0x86, 0x8e },
  365. { 0x87, 0x97 },
  366. { 0x88, 0xa4 },
  367. { 0x89, 0xaf },
  368. { 0x8a, 0xc5 },
  369. { 0x8b, 0xd7 },
  370. { 0x8c, 0xe8 },
  371. { 0x8d, 0x20 },
  372. { 0x0c, 0x90 },
  373. { 0x2b, 0x00 },
  374. { 0x22, 0x7f },
  375. { 0x23, 0x03 },
  376. { 0x11, 0x01 },
  377. { 0x0c, 0xd0 },
  378. { 0x64, 0xff },
  379. { 0x0d, 0x41 },
  380. { 0x14, 0x41 },
  381. { 0x0e, 0xcd },
  382. { 0xac, 0xbf },
  383. { 0x8e, 0x00 }, /* De-noise threshold */
  384. { 0x0c, 0xd0 }
  385. };
  386. static const u8 bridge_start_vga[][2] = {
  387. {0x1c, 0x00},
  388. {0x1d, 0x40},
  389. {0x1d, 0x02},
  390. {0x1d, 0x00},
  391. {0x1d, 0x02},
  392. {0x1d, 0x58},
  393. {0x1d, 0x00},
  394. {0xc0, 0x50},
  395. {0xc1, 0x3c},
  396. };
  397. static const u8 sensor_start_vga[][2] = {
  398. {0x12, 0x00},
  399. {0x17, 0x26},
  400. {0x18, 0xa0},
  401. {0x19, 0x07},
  402. {0x1a, 0xf0},
  403. {0x29, 0xa0},
  404. {0x2c, 0xf0},
  405. {0x65, 0x20},
  406. };
  407. static const u8 bridge_start_qvga[][2] = {
  408. {0x1c, 0x00},
  409. {0x1d, 0x40},
  410. {0x1d, 0x02},
  411. {0x1d, 0x00},
  412. {0x1d, 0x01},
  413. {0x1d, 0x4b},
  414. {0x1d, 0x00},
  415. {0xc0, 0x28},
  416. {0xc1, 0x1e},
  417. };
  418. static const u8 sensor_start_qvga[][2] = {
  419. {0x12, 0x40},
  420. {0x17, 0x3f},
  421. {0x18, 0x50},
  422. {0x19, 0x03},
  423. {0x1a, 0x78},
  424. {0x29, 0x50},
  425. {0x2c, 0x78},
  426. {0x65, 0x2f},
  427. };
  428. static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
  429. {
  430. struct usb_device *udev = gspca_dev->dev;
  431. int ret;
  432. PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
  433. gspca_dev->usb_buf[0] = val;
  434. ret = usb_control_msg(udev,
  435. usb_sndctrlpipe(udev, 0),
  436. 0x01,
  437. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  438. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  439. if (ret < 0)
  440. PDEBUG(D_ERR, "write failed");
  441. }
  442. static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
  443. {
  444. struct usb_device *udev = gspca_dev->dev;
  445. int ret;
  446. ret = usb_control_msg(udev,
  447. usb_rcvctrlpipe(udev, 0),
  448. 0x01,
  449. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  450. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  451. PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
  452. if (ret < 0)
  453. PDEBUG(D_ERR, "read failed");
  454. return gspca_dev->usb_buf[0];
  455. }
  456. /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
  457. * (direction and output)? */
  458. static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
  459. {
  460. u8 data;
  461. PDEBUG(D_CONF, "led status: %d", status);
  462. data = ov534_reg_read(gspca_dev, 0x21);
  463. data |= 0x80;
  464. ov534_reg_write(gspca_dev, 0x21, data);
  465. data = ov534_reg_read(gspca_dev, 0x23);
  466. if (status)
  467. data |= 0x80;
  468. else
  469. data &= ~0x80;
  470. ov534_reg_write(gspca_dev, 0x23, data);
  471. if (!status) {
  472. data = ov534_reg_read(gspca_dev, 0x21);
  473. data &= ~0x80;
  474. ov534_reg_write(gspca_dev, 0x21, data);
  475. }
  476. }
  477. static int sccb_check_status(struct gspca_dev *gspca_dev)
  478. {
  479. u8 data;
  480. int i;
  481. for (i = 0; i < 5; i++) {
  482. data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
  483. switch (data) {
  484. case 0x00:
  485. return 1;
  486. case 0x04:
  487. return 0;
  488. case 0x03:
  489. break;
  490. default:
  491. PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
  492. data, i + 1);
  493. }
  494. }
  495. return 0;
  496. }
  497. static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  498. {
  499. PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val);
  500. ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
  501. ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
  502. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
  503. if (!sccb_check_status(gspca_dev))
  504. PDEBUG(D_ERR, "sccb_reg_write failed");
  505. }
  506. static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
  507. {
  508. ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
  509. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
  510. if (!sccb_check_status(gspca_dev))
  511. PDEBUG(D_ERR, "sccb_reg_read failed 1");
  512. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
  513. if (!sccb_check_status(gspca_dev))
  514. PDEBUG(D_ERR, "sccb_reg_read failed 2");
  515. return ov534_reg_read(gspca_dev, OV534_REG_READ);
  516. }
  517. /* output a bridge sequence (reg - val) */
  518. static void reg_w_array(struct gspca_dev *gspca_dev,
  519. const u8 (*data)[2], int len)
  520. {
  521. while (--len >= 0) {
  522. ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
  523. data++;
  524. }
  525. }
  526. /* output a sensor sequence (reg - val) */
  527. static void sccb_w_array(struct gspca_dev *gspca_dev,
  528. const u8 (*data)[2], int len)
  529. {
  530. while (--len >= 0) {
  531. if ((*data)[0] != 0xff) {
  532. sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
  533. } else {
  534. sccb_reg_read(gspca_dev, (*data)[1]);
  535. sccb_reg_write(gspca_dev, 0xff, 0x00);
  536. }
  537. data++;
  538. }
  539. }
  540. /* ov772x specific controls */
  541. static void set_frame_rate(struct gspca_dev *gspca_dev)
  542. {
  543. struct sd *sd = (struct sd *) gspca_dev;
  544. int i;
  545. struct rate_s {
  546. u8 fps;
  547. u8 r11;
  548. u8 r0d;
  549. u8 re5;
  550. };
  551. const struct rate_s *r;
  552. static const struct rate_s rate_0[] = { /* 640x480 */
  553. {60, 0x01, 0xc1, 0x04},
  554. {50, 0x01, 0x41, 0x02},
  555. {40, 0x02, 0xc1, 0x04},
  556. {30, 0x04, 0x81, 0x02},
  557. {15, 0x03, 0x41, 0x04},
  558. };
  559. static const struct rate_s rate_1[] = { /* 320x240 */
  560. {125, 0x02, 0x81, 0x02},
  561. {100, 0x02, 0xc1, 0x04},
  562. {75, 0x03, 0xc1, 0x04},
  563. {60, 0x04, 0xc1, 0x04},
  564. {50, 0x02, 0x41, 0x04},
  565. {40, 0x03, 0x41, 0x04},
  566. {30, 0x04, 0x41, 0x04},
  567. };
  568. if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) {
  569. r = rate_0;
  570. i = ARRAY_SIZE(rate_0);
  571. } else {
  572. r = rate_1;
  573. i = ARRAY_SIZE(rate_1);
  574. }
  575. while (--i > 0) {
  576. if (sd->frame_rate >= r->fps)
  577. break;
  578. r++;
  579. }
  580. sccb_reg_write(gspca_dev, 0x11, r->r11);
  581. sccb_reg_write(gspca_dev, 0x0d, r->r0d);
  582. ov534_reg_write(gspca_dev, 0xe5, r->re5);
  583. PDEBUG(D_PROBE, "frame_rate: %d", r->fps);
  584. }
  585. static void setbrightness(struct gspca_dev *gspca_dev)
  586. {
  587. struct sd *sd = (struct sd *) gspca_dev;
  588. sccb_reg_write(gspca_dev, 0x9B, sd->brightness);
  589. }
  590. static void setcontrast(struct gspca_dev *gspca_dev)
  591. {
  592. struct sd *sd = (struct sd *) gspca_dev;
  593. sccb_reg_write(gspca_dev, 0x9C, sd->contrast);
  594. }
  595. static void setgain(struct gspca_dev *gspca_dev)
  596. {
  597. struct sd *sd = (struct sd *) gspca_dev;
  598. u8 val;
  599. if (sd->agc)
  600. return;
  601. val = sd->gain;
  602. switch (val & 0x30) {
  603. case 0x00:
  604. val &= 0x0f;
  605. break;
  606. case 0x10:
  607. val &= 0x0f;
  608. val |= 0x30;
  609. break;
  610. case 0x20:
  611. val &= 0x0f;
  612. val |= 0x70;
  613. break;
  614. default:
  615. /* case 0x30: */
  616. val &= 0x0f;
  617. val |= 0xf0;
  618. break;
  619. }
  620. sccb_reg_write(gspca_dev, 0x00, val);
  621. }
  622. static void setexposure(struct gspca_dev *gspca_dev)
  623. {
  624. struct sd *sd = (struct sd *) gspca_dev;
  625. u8 val;
  626. val = sd->exposure;
  627. sccb_reg_write(gspca_dev, 0x08, val >> 7);
  628. sccb_reg_write(gspca_dev, 0x10, val << 1);
  629. }
  630. static void setagc(struct gspca_dev *gspca_dev)
  631. {
  632. struct sd *sd = (struct sd *) gspca_dev;
  633. if (sd->agc) {
  634. sccb_reg_write(gspca_dev, 0x13,
  635. sccb_reg_read(gspca_dev, 0x13) | 0x04);
  636. sccb_reg_write(gspca_dev, 0x64,
  637. sccb_reg_read(gspca_dev, 0x64) | 0x03);
  638. } else {
  639. sccb_reg_write(gspca_dev, 0x13,
  640. sccb_reg_read(gspca_dev, 0x13) & ~0x04);
  641. sccb_reg_write(gspca_dev, 0x64,
  642. sccb_reg_read(gspca_dev, 0x64) & ~0x03);
  643. setgain(gspca_dev);
  644. }
  645. }
  646. static void setawb(struct gspca_dev *gspca_dev)
  647. {
  648. struct sd *sd = (struct sd *) gspca_dev;
  649. if (sd->awb)
  650. sccb_reg_write(gspca_dev, 0x63, 0xe0); /* AWB on */
  651. else
  652. sccb_reg_write(gspca_dev, 0x63, 0xaa); /* AWB off */
  653. }
  654. static void setaec(struct gspca_dev *gspca_dev)
  655. {
  656. struct sd *sd = (struct sd *) gspca_dev;
  657. if (sd->aec)
  658. sccb_reg_write(gspca_dev, 0x13,
  659. sccb_reg_read(gspca_dev, 0x13) | 0x01);
  660. else {
  661. sccb_reg_write(gspca_dev, 0x13,
  662. sccb_reg_read(gspca_dev, 0x13) & ~0x01);
  663. setexposure(gspca_dev);
  664. }
  665. }
  666. static void setsharpness(struct gspca_dev *gspca_dev)
  667. {
  668. struct sd *sd = (struct sd *) gspca_dev;
  669. u8 val;
  670. val = sd->sharpness;
  671. sccb_reg_write(gspca_dev, 0x91, val); /* vga noise */
  672. sccb_reg_write(gspca_dev, 0x8e, val); /* qvga noise */
  673. }
  674. static void sethflip(struct gspca_dev *gspca_dev)
  675. {
  676. struct sd *sd = (struct sd *) gspca_dev;
  677. if (sd->hflip == 0)
  678. sccb_reg_write(gspca_dev, 0x0c,
  679. sccb_reg_read(gspca_dev, 0x0c) | 0x40);
  680. else
  681. sccb_reg_write(gspca_dev, 0x0c,
  682. sccb_reg_read(gspca_dev, 0x0c) & 0xbf);
  683. }
  684. static void setvflip(struct gspca_dev *gspca_dev)
  685. {
  686. struct sd *sd = (struct sd *) gspca_dev;
  687. if (sd->vflip == 0)
  688. sccb_reg_write(gspca_dev, 0x0c,
  689. sccb_reg_read(gspca_dev, 0x0c) | 0x80);
  690. else
  691. sccb_reg_write(gspca_dev, 0x0c,
  692. sccb_reg_read(gspca_dev, 0x0c) & 0x7f);
  693. }
  694. /* this function is called at probe time */
  695. static int sd_config(struct gspca_dev *gspca_dev,
  696. const struct usb_device_id *id)
  697. {
  698. struct sd *sd = (struct sd *) gspca_dev;
  699. struct cam *cam;
  700. cam = &gspca_dev->cam;
  701. cam->cam_mode = ov772x_mode;
  702. cam->nmodes = ARRAY_SIZE(ov772x_mode);
  703. cam->mode_framerates = ov772x_framerates;
  704. cam->bulk = 1;
  705. cam->bulk_size = 16384;
  706. cam->bulk_nurbs = 2;
  707. sd->frame_rate = 30;
  708. sd->brightness = BRIGHTNESS_DEF;
  709. sd->contrast = CONTRAST_DEF;
  710. sd->gain = GAIN_DEF;
  711. sd->exposure = EXPO_DEF;
  712. #if AGC_DEF != 0
  713. sd->agc = AGC_DEF;
  714. #else
  715. gspca_dev->ctrl_inac |= (1 << AWB_IDX);
  716. #endif
  717. #if AWB_DEF != 0
  718. sd->awb = AWB_DEF
  719. #endif
  720. sd->aec = AEC_DEF;
  721. #if SHARPNESS_DEF != 0
  722. sd->sharpness = SHARPNESS_DEF;
  723. #endif
  724. #if HFLIP_DEF != 0
  725. sd->hflip = HFLIP_DEF;
  726. #endif
  727. #if VFLIP_DEF != 0
  728. sd->vflip = VFLIP_DEF;
  729. #endif
  730. return 0;
  731. }
  732. /* this function is called at probe and resume time */
  733. static int sd_init(struct gspca_dev *gspca_dev)
  734. {
  735. u16 sensor_id;
  736. /* reset bridge */
  737. ov534_reg_write(gspca_dev, 0xe7, 0x3a);
  738. ov534_reg_write(gspca_dev, 0xe0, 0x08);
  739. msleep(100);
  740. /* initialize the sensor address */
  741. ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, 0x42);
  742. /* reset sensor */
  743. sccb_reg_write(gspca_dev, 0x12, 0x80);
  744. msleep(10);
  745. /* probe the sensor */
  746. sccb_reg_read(gspca_dev, 0x0a);
  747. sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
  748. sccb_reg_read(gspca_dev, 0x0b);
  749. sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
  750. PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
  751. /* initialize */
  752. reg_w_array(gspca_dev, bridge_init,
  753. ARRAY_SIZE(bridge_init));
  754. ov534_set_led(gspca_dev, 1);
  755. sccb_w_array(gspca_dev, sensor_init,
  756. ARRAY_SIZE(sensor_init));
  757. ov534_reg_write(gspca_dev, 0xe0, 0x09);
  758. ov534_set_led(gspca_dev, 0);
  759. set_frame_rate(gspca_dev);
  760. return 0;
  761. }
  762. static int sd_start(struct gspca_dev *gspca_dev)
  763. {
  764. int mode;
  765. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  766. if (mode != 0) { /* 320x240 */
  767. reg_w_array(gspca_dev, bridge_start_qvga,
  768. ARRAY_SIZE(bridge_start_qvga));
  769. sccb_w_array(gspca_dev, sensor_start_qvga,
  770. ARRAY_SIZE(sensor_start_qvga));
  771. } else { /* 640x480 */
  772. reg_w_array(gspca_dev, bridge_start_vga,
  773. ARRAY_SIZE(bridge_start_vga));
  774. sccb_w_array(gspca_dev, sensor_start_vga,
  775. ARRAY_SIZE(sensor_start_vga));
  776. }
  777. set_frame_rate(gspca_dev);
  778. setagc(gspca_dev);
  779. setawb(gspca_dev);
  780. setaec(gspca_dev);
  781. setgain(gspca_dev);
  782. setexposure(gspca_dev);
  783. setbrightness(gspca_dev);
  784. setcontrast(gspca_dev);
  785. setsharpness(gspca_dev);
  786. setvflip(gspca_dev);
  787. sethflip(gspca_dev);
  788. ov534_set_led(gspca_dev, 1);
  789. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  790. return 0;
  791. }
  792. static void sd_stopN(struct gspca_dev *gspca_dev)
  793. {
  794. ov534_reg_write(gspca_dev, 0xe0, 0x09);
  795. ov534_set_led(gspca_dev, 0);
  796. }
  797. /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
  798. #define UVC_STREAM_EOH (1 << 7)
  799. #define UVC_STREAM_ERR (1 << 6)
  800. #define UVC_STREAM_STI (1 << 5)
  801. #define UVC_STREAM_RES (1 << 4)
  802. #define UVC_STREAM_SCR (1 << 3)
  803. #define UVC_STREAM_PTS (1 << 2)
  804. #define UVC_STREAM_EOF (1 << 1)
  805. #define UVC_STREAM_FID (1 << 0)
  806. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  807. u8 *data, int len)
  808. {
  809. struct sd *sd = (struct sd *) gspca_dev;
  810. __u32 this_pts;
  811. u16 this_fid;
  812. int remaining_len = len;
  813. do {
  814. len = min(remaining_len, 2048);
  815. /* Payloads are prefixed with a UVC-style header. We
  816. consider a frame to start when the FID toggles, or the PTS
  817. changes. A frame ends when EOF is set, and we've received
  818. the correct number of bytes. */
  819. /* Verify UVC header. Header length is always 12 */
  820. if (data[0] != 12 || len < 12) {
  821. PDEBUG(D_PACK, "bad header");
  822. goto discard;
  823. }
  824. /* Check errors */
  825. if (data[1] & UVC_STREAM_ERR) {
  826. PDEBUG(D_PACK, "payload error");
  827. goto discard;
  828. }
  829. /* Extract PTS and FID */
  830. if (!(data[1] & UVC_STREAM_PTS)) {
  831. PDEBUG(D_PACK, "PTS not present");
  832. goto discard;
  833. }
  834. this_pts = (data[5] << 24) | (data[4] << 16)
  835. | (data[3] << 8) | data[2];
  836. this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
  837. /* If PTS or FID has changed, start a new frame. */
  838. if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
  839. if (gspca_dev->last_packet_type == INTER_PACKET)
  840. gspca_frame_add(gspca_dev, LAST_PACKET,
  841. NULL, 0);
  842. sd->last_pts = this_pts;
  843. sd->last_fid = this_fid;
  844. gspca_frame_add(gspca_dev, FIRST_PACKET,
  845. data + 12, len - 12);
  846. /* If this packet is marked as EOF, end the frame */
  847. } else if (data[1] & UVC_STREAM_EOF) {
  848. struct gspca_frame *frame;
  849. sd->last_pts = 0;
  850. frame = gspca_get_i_frame(gspca_dev);
  851. if (frame == NULL)
  852. goto discard;
  853. if (frame->data_end - frame->data + (len - 12) !=
  854. gspca_dev->width * gspca_dev->height * 2) {
  855. PDEBUG(D_PACK, "wrong sized frame");
  856. goto discard;
  857. }
  858. gspca_frame_add(gspca_dev, LAST_PACKET,
  859. data + 12, len - 12);
  860. } else {
  861. /* Add the data from this payload */
  862. gspca_frame_add(gspca_dev, INTER_PACKET,
  863. data + 12, len - 12);
  864. }
  865. /* Done this payload */
  866. goto scan_next;
  867. discard:
  868. /* Discard data until a new frame starts. */
  869. gspca_dev->last_packet_type = DISCARD_PACKET;
  870. scan_next:
  871. remaining_len -= len;
  872. data += len;
  873. } while (remaining_len > 0);
  874. }
  875. /* controls */
  876. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  877. {
  878. struct sd *sd = (struct sd *) gspca_dev;
  879. sd->gain = val;
  880. if (gspca_dev->streaming)
  881. setgain(gspca_dev);
  882. return 0;
  883. }
  884. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  885. {
  886. struct sd *sd = (struct sd *) gspca_dev;
  887. *val = sd->gain;
  888. return 0;
  889. }
  890. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  891. {
  892. struct sd *sd = (struct sd *) gspca_dev;
  893. sd->exposure = val;
  894. if (gspca_dev->streaming)
  895. setexposure(gspca_dev);
  896. return 0;
  897. }
  898. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  899. {
  900. struct sd *sd = (struct sd *) gspca_dev;
  901. *val = sd->exposure;
  902. return 0;
  903. }
  904. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  905. {
  906. struct sd *sd = (struct sd *) gspca_dev;
  907. sd->brightness = val;
  908. if (gspca_dev->streaming)
  909. setbrightness(gspca_dev);
  910. return 0;
  911. }
  912. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  913. {
  914. struct sd *sd = (struct sd *) gspca_dev;
  915. *val = sd->brightness;
  916. return 0;
  917. }
  918. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  919. {
  920. struct sd *sd = (struct sd *) gspca_dev;
  921. sd->contrast = val;
  922. if (gspca_dev->streaming)
  923. setcontrast(gspca_dev);
  924. return 0;
  925. }
  926. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  927. {
  928. struct sd *sd = (struct sd *) gspca_dev;
  929. *val = sd->contrast;
  930. return 0;
  931. }
  932. static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val)
  933. {
  934. struct sd *sd = (struct sd *) gspca_dev;
  935. sd->agc = val;
  936. if (gspca_dev->streaming) {
  937. /* the auto white balance control works only
  938. * when auto gain is set */
  939. if (val)
  940. gspca_dev->ctrl_inac &= ~(1 << AWB_IDX);
  941. else
  942. gspca_dev->ctrl_inac |= (1 << AWB_IDX);
  943. setagc(gspca_dev);
  944. }
  945. return 0;
  946. }
  947. static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val)
  948. {
  949. struct sd *sd = (struct sd *) gspca_dev;
  950. *val = sd->agc;
  951. return 0;
  952. }
  953. static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
  954. {
  955. struct sd *sd = (struct sd *) gspca_dev;
  956. sd->awb = val;
  957. if (gspca_dev->streaming)
  958. setawb(gspca_dev);
  959. return 0;
  960. }
  961. static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
  962. {
  963. struct sd *sd = (struct sd *) gspca_dev;
  964. *val = sd->awb;
  965. return 0;
  966. }
  967. static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val)
  968. {
  969. struct sd *sd = (struct sd *) gspca_dev;
  970. sd->aec = val;
  971. if (gspca_dev->streaming)
  972. setaec(gspca_dev);
  973. return 0;
  974. }
  975. static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val)
  976. {
  977. struct sd *sd = (struct sd *) gspca_dev;
  978. *val = sd->aec;
  979. return 0;
  980. }
  981. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  982. {
  983. struct sd *sd = (struct sd *) gspca_dev;
  984. sd->sharpness = val;
  985. if (gspca_dev->streaming)
  986. setsharpness(gspca_dev);
  987. return 0;
  988. }
  989. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  990. {
  991. struct sd *sd = (struct sd *) gspca_dev;
  992. *val = sd->sharpness;
  993. return 0;
  994. }
  995. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
  996. {
  997. struct sd *sd = (struct sd *) gspca_dev;
  998. sd->hflip = val;
  999. if (gspca_dev->streaming)
  1000. sethflip(gspca_dev);
  1001. return 0;
  1002. }
  1003. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
  1004. {
  1005. struct sd *sd = (struct sd *) gspca_dev;
  1006. *val = sd->hflip;
  1007. return 0;
  1008. }
  1009. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
  1010. {
  1011. struct sd *sd = (struct sd *) gspca_dev;
  1012. sd->vflip = val;
  1013. if (gspca_dev->streaming)
  1014. setvflip(gspca_dev);
  1015. return 0;
  1016. }
  1017. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
  1018. {
  1019. struct sd *sd = (struct sd *) gspca_dev;
  1020. *val = sd->vflip;
  1021. return 0;
  1022. }
  1023. /* get stream parameters (framerate) */
  1024. static int sd_get_streamparm(struct gspca_dev *gspca_dev,
  1025. struct v4l2_streamparm *parm)
  1026. {
  1027. struct v4l2_captureparm *cp = &parm->parm.capture;
  1028. struct v4l2_fract *tpf = &cp->timeperframe;
  1029. struct sd *sd = (struct sd *) gspca_dev;
  1030. if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1031. return -EINVAL;
  1032. cp->capability |= V4L2_CAP_TIMEPERFRAME;
  1033. tpf->numerator = 1;
  1034. tpf->denominator = sd->frame_rate;
  1035. return 0;
  1036. }
  1037. /* set stream parameters (framerate) */
  1038. static int sd_set_streamparm(struct gspca_dev *gspca_dev,
  1039. struct v4l2_streamparm *parm)
  1040. {
  1041. struct v4l2_captureparm *cp = &parm->parm.capture;
  1042. struct v4l2_fract *tpf = &cp->timeperframe;
  1043. struct sd *sd = (struct sd *) gspca_dev;
  1044. if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1045. return -EINVAL;
  1046. /* Set requested framerate */
  1047. sd->frame_rate = tpf->denominator / tpf->numerator;
  1048. if (gspca_dev->streaming)
  1049. set_frame_rate(gspca_dev);
  1050. /* Return the actual framerate */
  1051. tpf->numerator = 1;
  1052. tpf->denominator = sd->frame_rate;
  1053. return 0;
  1054. }
  1055. /* sub-driver description */
  1056. static const struct sd_desc sd_desc = {
  1057. .name = MODULE_NAME,
  1058. .ctrls = sd_ctrls,
  1059. .nctrls = ARRAY_SIZE(sd_ctrls),
  1060. .config = sd_config,
  1061. .init = sd_init,
  1062. .start = sd_start,
  1063. .stopN = sd_stopN,
  1064. .pkt_scan = sd_pkt_scan,
  1065. .get_streamparm = sd_get_streamparm,
  1066. .set_streamparm = sd_set_streamparm,
  1067. };
  1068. /* -- module initialisation -- */
  1069. static const __devinitdata struct usb_device_id device_table[] = {
  1070. {USB_DEVICE(0x1415, 0x2000)},
  1071. {}
  1072. };
  1073. MODULE_DEVICE_TABLE(usb, device_table);
  1074. /* -- device connect -- */
  1075. static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1076. {
  1077. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1078. THIS_MODULE);
  1079. }
  1080. static struct usb_driver sd_driver = {
  1081. .name = MODULE_NAME,
  1082. .id_table = device_table,
  1083. .probe = sd_probe,
  1084. .disconnect = gspca_disconnect,
  1085. #ifdef CONFIG_PM
  1086. .suspend = gspca_suspend,
  1087. .resume = gspca_resume,
  1088. #endif
  1089. };
  1090. /* -- module insert / remove -- */
  1091. static int __init sd_mod_init(void)
  1092. {
  1093. int ret;
  1094. ret = usb_register(&sd_driver);
  1095. if (ret < 0)
  1096. return ret;
  1097. PDEBUG(D_PROBE, "registered");
  1098. return 0;
  1099. }
  1100. static void __exit sd_mod_exit(void)
  1101. {
  1102. usb_deregister(&sd_driver);
  1103. PDEBUG(D_PROBE, "deregistered");
  1104. }
  1105. module_init(sd_mod_init);
  1106. module_exit(sd_mod_exit);