m5602_ov9650.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /*
  2. * Driver for the ov9650 sensor
  3. *
  4. * Copyright (C) 2008 Erik Andrén
  5. * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
  6. * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
  7. *
  8. * Portions of code to USB interface and ALi driver software,
  9. * Copyright (c) 2006 Willem Duinker
  10. * v4l2 interface modeled after the V4L2 driver
  11. * for SN9C10x PC Camera Controllers
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation, version 2.
  16. *
  17. */
  18. #include "m5602_ov9650.h"
  19. /* Vertically and horizontally flips the image if matched, needed for machines
  20. where the sensor is mounted upside down */
  21. static
  22. const
  23. struct dmi_system_id ov9650_flip_dmi_table[] = {
  24. {
  25. .ident = "ASUS A6VC",
  26. .matches = {
  27. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  28. DMI_MATCH(DMI_PRODUCT_NAME, "A6VC")
  29. }
  30. },
  31. {
  32. .ident = "ASUS A6VM",
  33. .matches = {
  34. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  35. DMI_MATCH(DMI_PRODUCT_NAME, "A6VM")
  36. }
  37. },
  38. {
  39. .ident = "ASUS A6JC",
  40. .matches = {
  41. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  42. DMI_MATCH(DMI_PRODUCT_NAME, "A6JC")
  43. }
  44. },
  45. {
  46. .ident = "ASUS A6Ja",
  47. .matches = {
  48. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  49. DMI_MATCH(DMI_PRODUCT_NAME, "A6J")
  50. }
  51. },
  52. {
  53. .ident = "ASUS A6Kt",
  54. .matches = {
  55. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  56. DMI_MATCH(DMI_PRODUCT_NAME, "A6Kt")
  57. }
  58. },
  59. {
  60. .ident = "Alienware Aurora m9700",
  61. .matches = {
  62. DMI_MATCH(DMI_SYS_VENDOR, "alienware"),
  63. DMI_MATCH(DMI_PRODUCT_NAME, "Aurora m9700")
  64. }
  65. },
  66. { }
  67. };
  68. static struct v4l2_pix_format ov9650_modes[] = {
  69. {
  70. 176,
  71. 144,
  72. V4L2_PIX_FMT_SBGGR8,
  73. V4L2_FIELD_NONE,
  74. .sizeimage =
  75. 176 * 144,
  76. .bytesperline = 176,
  77. .colorspace = V4L2_COLORSPACE_SRGB,
  78. .priv = 0
  79. }, {
  80. 320,
  81. 240,
  82. V4L2_PIX_FMT_SBGGR8,
  83. V4L2_FIELD_NONE,
  84. .sizeimage =
  85. 320 * 240,
  86. .bytesperline = 320,
  87. .colorspace = V4L2_COLORSPACE_SRGB,
  88. .priv = 0
  89. }, {
  90. 352,
  91. 288,
  92. V4L2_PIX_FMT_SBGGR8,
  93. V4L2_FIELD_NONE,
  94. .sizeimage =
  95. 352 * 288,
  96. .bytesperline = 352,
  97. .colorspace = V4L2_COLORSPACE_SRGB,
  98. .priv = 0
  99. }, {
  100. 640,
  101. 480,
  102. V4L2_PIX_FMT_SBGGR8,
  103. V4L2_FIELD_NONE,
  104. .sizeimage =
  105. 640 * 480,
  106. .bytesperline = 640,
  107. .colorspace = V4L2_COLORSPACE_SRGB,
  108. .priv = 0
  109. }
  110. };
  111. static void ov9650_dump_registers(struct sd *sd);
  112. int ov9650_probe(struct sd *sd)
  113. {
  114. u8 prod_id = 0, ver_id = 0, i;
  115. if (force_sensor) {
  116. if (force_sensor == OV9650_SENSOR) {
  117. info("Forcing an %s sensor", ov9650.name);
  118. goto sensor_found;
  119. }
  120. /* If we want to force another sensor,
  121. don't try to probe this one */
  122. return -ENODEV;
  123. }
  124. info("Probing for an ov9650 sensor");
  125. /* Run the pre-init to actually probe the unit */
  126. for (i = 0; i < ARRAY_SIZE(preinit_ov9650); i++) {
  127. u8 data = preinit_ov9650[i][2];
  128. if (preinit_ov9650[i][0] == SENSOR)
  129. m5602_write_sensor(sd,
  130. preinit_ov9650[i][1], &data, 1);
  131. else
  132. m5602_write_bridge(sd, preinit_ov9650[i][1], data);
  133. }
  134. if (m5602_read_sensor(sd, OV9650_PID, &prod_id, 1))
  135. return -ENODEV;
  136. if (m5602_read_sensor(sd, OV9650_VER, &ver_id, 1))
  137. return -ENODEV;
  138. if ((prod_id == 0x96) && (ver_id == 0x52)) {
  139. info("Detected an ov9650 sensor");
  140. goto sensor_found;
  141. }
  142. return -ENODEV;
  143. sensor_found:
  144. // sd->gspca_dev.cam.cam_mode = ov9650.modes;
  145. // sd->gspca_dev.cam.nmodes = ov9650.nmodes;
  146. sd->gspca_dev.cam.cam_mode = ov9650_modes;
  147. sd->gspca_dev.cam.nmodes = ARRAY_SIZE(ov9650_modes);
  148. sd->desc->ctrls = ov9650.ctrls;
  149. sd->desc->nctrls = ARRAY_SIZE(ov9650_ctrls);
  150. return 0;
  151. }
  152. int ov9650_init(struct sd *sd)
  153. {
  154. int i, err = 0;
  155. u8 data;
  156. if (dump_sensor)
  157. ov9650_dump_registers(sd);
  158. for (i = 0; i < ARRAY_SIZE(init_ov9650) && !err; i++) {
  159. data = init_ov9650[i][2];
  160. if (init_ov9650[i][0] == SENSOR)
  161. err = m5602_write_sensor(sd, init_ov9650[i][1],
  162. &data, 1);
  163. else
  164. err = m5602_write_bridge(sd, init_ov9650[i][1], data);
  165. }
  166. if (dmi_check_system(ov9650_flip_dmi_table) && !err) {
  167. info("vflip quirk active");
  168. data = 0x30;
  169. err = m5602_write_sensor(sd, OV9650_MVFP, &data, 1);
  170. }
  171. return err;
  172. }
  173. int ov9650_start(struct sd *sd)
  174. {
  175. int i, err = 0;
  176. struct cam *cam = &sd->gspca_dev.cam;
  177. err = ov9650_init(sd);
  178. if (err < 0)
  179. return err;
  180. for (i = 0; i < ARRAY_SIZE(res_init_ov9650) && !err; i++) {
  181. if (res_init_ov9650[i][0] == BRIDGE)
  182. err = m5602_write_bridge(sd, res_init_ov9650[i][1],
  183. res_init_ov9650[i][2]);
  184. else if (res_init_ov9650[i][0] == SENSOR) {
  185. u8 data = res_init_ov9650[i][2];
  186. err = m5602_write_sensor(sd,
  187. res_init_ov9650[i][1], &data, 1);
  188. }
  189. }
  190. if (err < 0)
  191. return err;
  192. switch (cam->cam_mode[sd->gspca_dev.curr_mode].width) {
  193. case 640:
  194. PDEBUG(D_V4L2, "Configuring camera for VGA mode");
  195. for (i = 0; i < ARRAY_SIZE(VGA_ov9650) && !err; i++) {
  196. if (VGA_ov9650[i][0] == SENSOR) {
  197. u8 data = VGA_ov9650[i][2];
  198. err = m5602_write_sensor(sd,
  199. VGA_ov9650[i][1], &data, 1);
  200. } else {
  201. err = m5602_write_bridge(sd, VGA_ov9650[i][1],
  202. VGA_ov9650[i][2]);
  203. }
  204. }
  205. break;
  206. case 352:
  207. PDEBUG(D_V4L2, "Configuring camera for CIF mode");
  208. for (i = 0; i < ARRAY_SIZE(CIF_ov9650) && !err; i++) {
  209. if (CIF_ov9650[i][0] == SENSOR) {
  210. u8 data = CIF_ov9650[i][2];
  211. err = m5602_write_sensor(sd,
  212. CIF_ov9650[i][1], &data, 1);
  213. } else {
  214. err = m5602_write_bridge(sd, CIF_ov9650[i][1],
  215. CIF_ov9650[i][2]);
  216. }
  217. }
  218. break;
  219. case 320:
  220. PDEBUG(D_V4L2, "Configuring camera for QVGA mode");
  221. for (i = 0; i < ARRAY_SIZE(QVGA_ov9650) && !err; i++) {
  222. if (QVGA_ov9650[i][0] == SENSOR) {
  223. u8 data = QVGA_ov9650[i][2];
  224. err = m5602_write_sensor(sd,
  225. QVGA_ov9650[i][1], &data, 1);
  226. } else {
  227. err = m5602_write_bridge(sd, QVGA_ov9650[i][1],
  228. QVGA_ov9650[i][2]);
  229. }
  230. }
  231. break;
  232. case 176:
  233. PDEBUG(D_V4L2, "Configuring camera for QCIF mode");
  234. for (i = 0; i < ARRAY_SIZE(QCIF_ov9650) && !err; i++) {
  235. if (QCIF_ov9650[i][0] == SENSOR) {
  236. u8 data = QCIF_ov9650[i][2];
  237. err = m5602_write_sensor(sd,
  238. QCIF_ov9650[i][1], &data, 1);
  239. } else {
  240. err = m5602_write_bridge(sd, QCIF_ov9650[i][1],
  241. QCIF_ov9650[i][2]);
  242. }
  243. }
  244. break;
  245. }
  246. return err;
  247. }
  248. int ov9650_stop(struct sd *sd)
  249. {
  250. u8 data = OV9650_SOFT_SLEEP | OV9650_OUTPUT_DRIVE_2X;
  251. return m5602_write_sensor(sd, OV9650_COM2, &data, 1);
  252. }
  253. int ov9650_power_down(struct sd *sd)
  254. {
  255. int i, err = 0;
  256. for (i = 0; i < ARRAY_SIZE(power_down_ov9650) && !err; i++) {
  257. u8 data = power_down_ov9650[i][2];
  258. if (power_down_ov9650[i][0] == SENSOR)
  259. err = m5602_write_sensor(sd,
  260. power_down_ov9650[i][1], &data, 1);
  261. else
  262. err = m5602_write_bridge(sd, power_down_ov9650[i][1],
  263. data);
  264. }
  265. return err;
  266. }
  267. int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
  268. {
  269. struct sd *sd = (struct sd *) gspca_dev;
  270. u8 i2c_data;
  271. int err;
  272. err = m5602_read_sensor(sd, OV9650_COM1, &i2c_data, 1);
  273. if (err < 0)
  274. return err;
  275. *val = i2c_data & 0x03;
  276. err = m5602_read_sensor(sd, OV9650_AECH, &i2c_data, 1);
  277. if (err < 0)
  278. return err;
  279. *val |= (i2c_data << 2);
  280. err = m5602_read_sensor(sd, OV9650_AECHM, &i2c_data, 1);
  281. if (err < 0)
  282. return err;
  283. *val |= (i2c_data & 0x3f) << 10;
  284. PDEBUG(D_V4L2, "Read exposure %d", *val);
  285. return err;
  286. }
  287. int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
  288. {
  289. struct sd *sd = (struct sd *) gspca_dev;
  290. u8 i2c_data;
  291. int err;
  292. PDEBUG(D_V4L2, "Set exposure to %d",
  293. val & 0xffff);
  294. /* The 6 MSBs */
  295. i2c_data = (val >> 10) & 0x3f;
  296. err = m5602_write_sensor(sd, OV9650_AECHM,
  297. &i2c_data, 1);
  298. if (err < 0)
  299. return err;
  300. /* The 8 middle bits */
  301. i2c_data = (val >> 2) & 0xff;
  302. err = m5602_write_sensor(sd, OV9650_AECH,
  303. &i2c_data, 1);
  304. if (err < 0)
  305. return err;
  306. /* The 2 LSBs */
  307. i2c_data = val & 0x03;
  308. err = m5602_write_sensor(sd, OV9650_COM1, &i2c_data, 1);
  309. return err;
  310. }
  311. int ov9650_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
  312. {
  313. int err;
  314. u8 i2c_data;
  315. struct sd *sd = (struct sd *) gspca_dev;
  316. m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
  317. *val = (i2c_data & 0x03) << 8;
  318. err = m5602_read_sensor(sd, OV9650_GAIN, &i2c_data, 1);
  319. *val |= i2c_data;
  320. PDEBUG(D_V4L2, "Read gain %d", *val);
  321. return err;
  322. }
  323. int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val)
  324. {
  325. int err;
  326. u8 i2c_data;
  327. struct sd *sd = (struct sd *) gspca_dev;
  328. /* The 2 MSB */
  329. /* Read the OV9650_VREF register first to avoid
  330. corrupting the VREF high and low bits */
  331. m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
  332. /* Mask away all uninteresting bits */
  333. i2c_data = ((val & 0x0300) >> 2) |
  334. (i2c_data & 0x3F);
  335. err = m5602_write_sensor(sd, OV9650_VREF, &i2c_data, 1);
  336. /* The 8 LSBs */
  337. i2c_data = val & 0xff;
  338. err = m5602_write_sensor(sd, OV9650_GAIN, &i2c_data, 1);
  339. return err;
  340. }
  341. int ov9650_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val)
  342. {
  343. int err;
  344. u8 i2c_data;
  345. struct sd *sd = (struct sd *) gspca_dev;
  346. err = m5602_read_sensor(sd, OV9650_RED, &i2c_data, 1);
  347. *val = i2c_data;
  348. PDEBUG(D_V4L2, "Read red gain %d", *val);
  349. return err;
  350. }
  351. int ov9650_set_red_balance(struct gspca_dev *gspca_dev, __s32 val)
  352. {
  353. int err;
  354. u8 i2c_data;
  355. struct sd *sd = (struct sd *) gspca_dev;
  356. PDEBUG(D_V4L2, "Set red gain to %d",
  357. val & 0xff);
  358. i2c_data = val & 0xff;
  359. err = m5602_write_sensor(sd, OV9650_RED, &i2c_data, 1);
  360. return err;
  361. }
  362. int ov9650_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val)
  363. {
  364. int err;
  365. u8 i2c_data;
  366. struct sd *sd = (struct sd *) gspca_dev;
  367. err = m5602_read_sensor(sd, OV9650_BLUE, &i2c_data, 1);
  368. *val = i2c_data;
  369. PDEBUG(D_V4L2, "Read blue gain %d", *val);
  370. return err;
  371. }
  372. int ov9650_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
  373. {
  374. int err;
  375. u8 i2c_data;
  376. struct sd *sd = (struct sd *) gspca_dev;
  377. PDEBUG(D_V4L2, "Set blue gain to %d",
  378. val & 0xff);
  379. i2c_data = val & 0xff;
  380. err = m5602_write_sensor(sd, OV9650_BLUE, &i2c_data, 1);
  381. return err;
  382. }
  383. int ov9650_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
  384. {
  385. int err;
  386. u8 i2c_data;
  387. struct sd *sd = (struct sd *) gspca_dev;
  388. err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
  389. if (dmi_check_system(ov9650_flip_dmi_table))
  390. *val = ((i2c_data & OV9650_HFLIP) >> 5) ? 0 : 1;
  391. else
  392. *val = (i2c_data & OV9650_HFLIP) >> 5;
  393. PDEBUG(D_V4L2, "Read horizontal flip %d", *val);
  394. return err;
  395. }
  396. int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
  397. {
  398. int err;
  399. u8 i2c_data;
  400. struct sd *sd = (struct sd *) gspca_dev;
  401. PDEBUG(D_V4L2, "Set horizontal flip to %d", val);
  402. err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
  403. if (err < 0)
  404. return err;
  405. if (dmi_check_system(ov9650_flip_dmi_table))
  406. i2c_data = ((i2c_data & 0xdf) |
  407. (((val ? 0 : 1) & 0x01) << 5));
  408. else
  409. i2c_data = ((i2c_data & 0xdf) |
  410. ((val & 0x01) << 5));
  411. err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
  412. return err;
  413. }
  414. int ov9650_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
  415. {
  416. int err;
  417. u8 i2c_data;
  418. struct sd *sd = (struct sd *) gspca_dev;
  419. err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
  420. if (dmi_check_system(ov9650_flip_dmi_table))
  421. *val = ((i2c_data & 0x10) >> 4) ? 0 : 1;
  422. else
  423. *val = (i2c_data & 0x10) >> 4;
  424. PDEBUG(D_V4L2, "Read vertical flip %d", *val);
  425. return err;
  426. }
  427. int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
  428. {
  429. int err;
  430. u8 i2c_data;
  431. struct sd *sd = (struct sd *) gspca_dev;
  432. PDEBUG(D_V4L2, "Set vertical flip to %d", val);
  433. err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
  434. if (err < 0)
  435. return err;
  436. if (dmi_check_system(ov9650_flip_dmi_table))
  437. i2c_data = ((i2c_data & 0xef) |
  438. (((val ? 0 : 1) & 0x01) << 4));
  439. else
  440. i2c_data = ((i2c_data & 0xef) |
  441. ((val & 0x01) << 4));
  442. err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
  443. return err;
  444. }
  445. int ov9650_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
  446. {
  447. int err;
  448. u8 i2c_data;
  449. struct sd *sd = (struct sd *) gspca_dev;
  450. err = m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
  451. if (err < 0)
  452. return err;
  453. *val = (i2c_data & 0x03) << 8;
  454. err = m5602_read_sensor(sd, OV9650_GAIN, &i2c_data, 1);
  455. *val |= i2c_data;
  456. PDEBUG(D_V4L2, "Read gain %d", *val);
  457. return err;
  458. }
  459. int ov9650_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
  460. {
  461. int err;
  462. u8 i2c_data;
  463. struct sd *sd = (struct sd *) gspca_dev;
  464. PDEBUG(D_V4L2, "Set gain to %d", val & 0x3ff);
  465. /* Read the OV9650_VREF register first to avoid
  466. corrupting the VREF high and low bits */
  467. err = m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
  468. if (err < 0)
  469. return err;
  470. /* Mask away all uninteresting bits */
  471. i2c_data = ((val & 0x0300) >> 2) | (i2c_data & 0x3F);
  472. err = m5602_write_sensor(sd, OV9650_VREF, &i2c_data, 1);
  473. if (err < 0)
  474. return err;
  475. /* The 8 LSBs */
  476. i2c_data = val & 0xff;
  477. err = m5602_write_sensor(sd, OV9650_GAIN, &i2c_data, 1);
  478. return err;
  479. }
  480. int ov9650_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val)
  481. {
  482. int err;
  483. u8 i2c_data;
  484. struct sd *sd = (struct sd *) gspca_dev;
  485. err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
  486. *val = (i2c_data & OV9650_AWB_EN) >> 1;
  487. PDEBUG(D_V4L2, "Read auto white balance %d", *val);
  488. return err;
  489. }
  490. int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val)
  491. {
  492. int err;
  493. u8 i2c_data;
  494. struct sd *sd = (struct sd *) gspca_dev;
  495. PDEBUG(D_V4L2, "Set auto white balance to %d", val);
  496. err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
  497. if (err < 0)
  498. return err;
  499. i2c_data = ((i2c_data & 0xfd) | ((val & 0x01) << 1));
  500. err = m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
  501. return err;
  502. }
  503. int ov9650_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val)
  504. {
  505. int err;
  506. u8 i2c_data;
  507. struct sd *sd = (struct sd *) gspca_dev;
  508. err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
  509. *val = (i2c_data & OV9650_AGC_EN) >> 2;
  510. PDEBUG(D_V4L2, "Read auto gain control %d", *val);
  511. return err;
  512. }
  513. int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val)
  514. {
  515. int err;
  516. u8 i2c_data;
  517. struct sd *sd = (struct sd *) gspca_dev;
  518. PDEBUG(D_V4L2, "Set auto gain control to %d", val);
  519. err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
  520. if (err < 0)
  521. return err;
  522. i2c_data = ((i2c_data & 0xfb) | ((val & 0x01) << 2));
  523. err = m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
  524. return err;
  525. }
  526. static void ov9650_dump_registers(struct sd *sd)
  527. {
  528. int address;
  529. info("Dumping the ov9650 register state");
  530. for (address = 0; address < 0xa9; address++) {
  531. u8 value;
  532. m5602_read_sensor(sd, address, &value, 1);
  533. info("register 0x%x contains 0x%x",
  534. address, value);
  535. }
  536. info("ov9650 register state dump complete");
  537. info("Probing for which registers that are read/write");
  538. for (address = 0; address < 0xff; address++) {
  539. u8 old_value, ctrl_value;
  540. u8 test_value[2] = {0xff, 0xff};
  541. m5602_read_sensor(sd, address, &old_value, 1);
  542. m5602_write_sensor(sd, address, test_value, 1);
  543. m5602_read_sensor(sd, address, &ctrl_value, 1);
  544. if (ctrl_value == test_value[0])
  545. info("register 0x%x is writeable", address);
  546. else
  547. info("register 0x%x is read only", address);
  548. /* Restore original value */
  549. m5602_write_sensor(sd, address, &old_value, 1);
  550. }
  551. }