m5602_mt9m111.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. * Driver for the mt9m111 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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. #include "m5602_mt9m111.h"
  20. static int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
  21. static int mt9m111_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
  22. static int mt9m111_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
  23. static int mt9m111_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
  24. static int mt9m111_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
  25. static int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val);
  26. static int mt9m111_set_auto_white_balance(struct gspca_dev *gspca_dev,
  27. __s32 val);
  28. static int mt9m111_get_auto_white_balance(struct gspca_dev *gspca_dev,
  29. __s32 *val);
  30. static int mt9m111_get_green_balance(struct gspca_dev *gspca_dev, __s32 *val);
  31. static int mt9m111_set_green_balance(struct gspca_dev *gspca_dev, __s32 val);
  32. static int mt9m111_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val);
  33. static int mt9m111_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val);
  34. static int mt9m111_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val);
  35. static int mt9m111_set_red_balance(struct gspca_dev *gspca_dev, __s32 val);
  36. static struct v4l2_pix_format mt9m111_modes[] = {
  37. {
  38. 640,
  39. 480,
  40. V4L2_PIX_FMT_SBGGR8,
  41. V4L2_FIELD_NONE,
  42. .sizeimage = 640 * 480,
  43. .bytesperline = 640,
  44. .colorspace = V4L2_COLORSPACE_SRGB,
  45. .priv = 0
  46. }
  47. };
  48. static const struct ctrl mt9m111_ctrls[] = {
  49. #define VFLIP_IDX 0
  50. {
  51. {
  52. .id = V4L2_CID_VFLIP,
  53. .type = V4L2_CTRL_TYPE_BOOLEAN,
  54. .name = "vertical flip",
  55. .minimum = 0,
  56. .maximum = 1,
  57. .step = 1,
  58. .default_value = 0
  59. },
  60. .set = mt9m111_set_vflip,
  61. .get = mt9m111_get_vflip
  62. },
  63. #define HFLIP_IDX 1
  64. {
  65. {
  66. .id = V4L2_CID_HFLIP,
  67. .type = V4L2_CTRL_TYPE_BOOLEAN,
  68. .name = "horizontal flip",
  69. .minimum = 0,
  70. .maximum = 1,
  71. .step = 1,
  72. .default_value = 0
  73. },
  74. .set = mt9m111_set_hflip,
  75. .get = mt9m111_get_hflip
  76. },
  77. #define GAIN_IDX 2
  78. {
  79. {
  80. .id = V4L2_CID_GAIN,
  81. .type = V4L2_CTRL_TYPE_INTEGER,
  82. .name = "gain",
  83. .minimum = 0,
  84. .maximum = (INITIAL_MAX_GAIN - 1) * 2 * 2 * 2,
  85. .step = 1,
  86. .default_value = MT9M111_DEFAULT_GAIN,
  87. .flags = V4L2_CTRL_FLAG_SLIDER
  88. },
  89. .set = mt9m111_set_gain,
  90. .get = mt9m111_get_gain
  91. },
  92. #define AUTO_WHITE_BALANCE_IDX 3
  93. {
  94. {
  95. .id = V4L2_CID_AUTO_WHITE_BALANCE,
  96. .type = V4L2_CTRL_TYPE_BOOLEAN,
  97. .name = "auto white balance",
  98. .minimum = 0,
  99. .maximum = 1,
  100. .step = 1,
  101. .default_value = 0,
  102. },
  103. .set = mt9m111_set_auto_white_balance,
  104. .get = mt9m111_get_auto_white_balance
  105. },
  106. #define GREEN_BALANCE_IDX 4
  107. {
  108. {
  109. .id = M5602_V4L2_CID_GREEN_BALANCE,
  110. .type = V4L2_CTRL_TYPE_INTEGER,
  111. .name = "green balance",
  112. .minimum = 0x00,
  113. .maximum = 0x7ff,
  114. .step = 0x1,
  115. .default_value = MT9M111_GREEN_GAIN_DEFAULT,
  116. .flags = V4L2_CTRL_FLAG_SLIDER
  117. },
  118. .set = mt9m111_set_green_balance,
  119. .get = mt9m111_get_green_balance
  120. },
  121. #define BLUE_BALANCE_IDX 5
  122. {
  123. {
  124. .id = V4L2_CID_BLUE_BALANCE,
  125. .type = V4L2_CTRL_TYPE_INTEGER,
  126. .name = "blue balance",
  127. .minimum = 0x00,
  128. .maximum = 0x7ff,
  129. .step = 0x1,
  130. .default_value = MT9M111_BLUE_GAIN_DEFAULT,
  131. .flags = V4L2_CTRL_FLAG_SLIDER
  132. },
  133. .set = mt9m111_set_blue_balance,
  134. .get = mt9m111_get_blue_balance
  135. },
  136. #define RED_BALANCE_IDX 5
  137. {
  138. {
  139. .id = V4L2_CID_RED_BALANCE,
  140. .type = V4L2_CTRL_TYPE_INTEGER,
  141. .name = "red balance",
  142. .minimum = 0x00,
  143. .maximum = 0x7ff,
  144. .step = 0x1,
  145. .default_value = MT9M111_RED_GAIN_DEFAULT,
  146. .flags = V4L2_CTRL_FLAG_SLIDER
  147. },
  148. .set = mt9m111_set_red_balance,
  149. .get = mt9m111_get_red_balance
  150. },
  151. };
  152. static void mt9m111_dump_registers(struct sd *sd);
  153. int mt9m111_probe(struct sd *sd)
  154. {
  155. u8 data[2] = {0x00, 0x00};
  156. int i;
  157. s32 *sensor_settings;
  158. if (force_sensor) {
  159. if (force_sensor == MT9M111_SENSOR) {
  160. pr_info("Forcing a %s sensor\n", mt9m111.name);
  161. goto sensor_found;
  162. }
  163. /* If we want to force another sensor, don't try to probe this
  164. * one */
  165. return -ENODEV;
  166. }
  167. PDEBUG(D_PROBE, "Probing for a mt9m111 sensor");
  168. /* Do the preinit */
  169. for (i = 0; i < ARRAY_SIZE(preinit_mt9m111); i++) {
  170. if (preinit_mt9m111[i][0] == BRIDGE) {
  171. m5602_write_bridge(sd,
  172. preinit_mt9m111[i][1],
  173. preinit_mt9m111[i][2]);
  174. } else {
  175. data[0] = preinit_mt9m111[i][2];
  176. data[1] = preinit_mt9m111[i][3];
  177. m5602_write_sensor(sd,
  178. preinit_mt9m111[i][1], data, 2);
  179. }
  180. }
  181. if (m5602_read_sensor(sd, MT9M111_SC_CHIPVER, data, 2))
  182. return -ENODEV;
  183. if ((data[0] == 0x14) && (data[1] == 0x3a)) {
  184. pr_info("Detected a mt9m111 sensor\n");
  185. goto sensor_found;
  186. }
  187. return -ENODEV;
  188. sensor_found:
  189. sensor_settings = kmalloc(ARRAY_SIZE(mt9m111_ctrls) * sizeof(s32),
  190. GFP_KERNEL);
  191. if (!sensor_settings)
  192. return -ENOMEM;
  193. sd->gspca_dev.cam.cam_mode = mt9m111_modes;
  194. sd->gspca_dev.cam.nmodes = ARRAY_SIZE(mt9m111_modes);
  195. sd->desc->ctrls = mt9m111_ctrls;
  196. sd->desc->nctrls = ARRAY_SIZE(mt9m111_ctrls);
  197. for (i = 0; i < ARRAY_SIZE(mt9m111_ctrls); i++)
  198. sensor_settings[i] = mt9m111_ctrls[i].qctrl.default_value;
  199. sd->sensor_priv = sensor_settings;
  200. return 0;
  201. }
  202. int mt9m111_init(struct sd *sd)
  203. {
  204. int i, err = 0;
  205. s32 *sensor_settings = sd->sensor_priv;
  206. /* Init the sensor */
  207. for (i = 0; i < ARRAY_SIZE(init_mt9m111) && !err; i++) {
  208. u8 data[2];
  209. if (init_mt9m111[i][0] == BRIDGE) {
  210. err = m5602_write_bridge(sd,
  211. init_mt9m111[i][1],
  212. init_mt9m111[i][2]);
  213. } else {
  214. data[0] = init_mt9m111[i][2];
  215. data[1] = init_mt9m111[i][3];
  216. err = m5602_write_sensor(sd,
  217. init_mt9m111[i][1], data, 2);
  218. }
  219. }
  220. if (dump_sensor)
  221. mt9m111_dump_registers(sd);
  222. err = mt9m111_set_vflip(&sd->gspca_dev, sensor_settings[VFLIP_IDX]);
  223. if (err < 0)
  224. return err;
  225. err = mt9m111_set_hflip(&sd->gspca_dev, sensor_settings[HFLIP_IDX]);
  226. if (err < 0)
  227. return err;
  228. err = mt9m111_set_green_balance(&sd->gspca_dev,
  229. sensor_settings[GREEN_BALANCE_IDX]);
  230. if (err < 0)
  231. return err;
  232. err = mt9m111_set_blue_balance(&sd->gspca_dev,
  233. sensor_settings[BLUE_BALANCE_IDX]);
  234. if (err < 0)
  235. return err;
  236. err = mt9m111_set_red_balance(&sd->gspca_dev,
  237. sensor_settings[RED_BALANCE_IDX]);
  238. if (err < 0)
  239. return err;
  240. return mt9m111_set_gain(&sd->gspca_dev, sensor_settings[GAIN_IDX]);
  241. }
  242. int mt9m111_start(struct sd *sd)
  243. {
  244. int i, err = 0;
  245. u8 data[2];
  246. struct cam *cam = &sd->gspca_dev.cam;
  247. s32 *sensor_settings = sd->sensor_priv;
  248. int width = cam->cam_mode[sd->gspca_dev.curr_mode].width - 1;
  249. int height = cam->cam_mode[sd->gspca_dev.curr_mode].height;
  250. for (i = 0; i < ARRAY_SIZE(start_mt9m111) && !err; i++) {
  251. if (start_mt9m111[i][0] == BRIDGE) {
  252. err = m5602_write_bridge(sd,
  253. start_mt9m111[i][1],
  254. start_mt9m111[i][2]);
  255. } else {
  256. data[0] = start_mt9m111[i][2];
  257. data[1] = start_mt9m111[i][3];
  258. err = m5602_write_sensor(sd,
  259. start_mt9m111[i][1], data, 2);
  260. }
  261. }
  262. if (err < 0)
  263. return err;
  264. err = m5602_write_bridge(sd, M5602_XB_VSYNC_PARA, (height >> 8) & 0xff);
  265. if (err < 0)
  266. return err;
  267. err = m5602_write_bridge(sd, M5602_XB_VSYNC_PARA, (height & 0xff));
  268. if (err < 0)
  269. return err;
  270. for (i = 0; i < 2 && !err; i++)
  271. err = m5602_write_bridge(sd, M5602_XB_VSYNC_PARA, 0);
  272. if (err < 0)
  273. return err;
  274. err = m5602_write_bridge(sd, M5602_XB_SIG_INI, 0);
  275. if (err < 0)
  276. return err;
  277. err = m5602_write_bridge(sd, M5602_XB_SIG_INI, 2);
  278. if (err < 0)
  279. return err;
  280. for (i = 0; i < 2 && !err; i++)
  281. err = m5602_write_bridge(sd, M5602_XB_HSYNC_PARA, 0);
  282. if (err < 0)
  283. return err;
  284. err = m5602_write_bridge(sd, M5602_XB_HSYNC_PARA,
  285. (width >> 8) & 0xff);
  286. if (err < 0)
  287. return err;
  288. err = m5602_write_bridge(sd, M5602_XB_HSYNC_PARA, width & 0xff);
  289. if (err < 0)
  290. return err;
  291. err = m5602_write_bridge(sd, M5602_XB_SIG_INI, 0);
  292. if (err < 0)
  293. return err;
  294. switch (width) {
  295. case 640:
  296. PDEBUG(D_V4L2, "Configuring camera for VGA mode");
  297. data[0] = MT9M111_RMB_OVER_SIZED;
  298. data[1] = MT9M111_RMB_ROW_SKIP_2X |
  299. MT9M111_RMB_COLUMN_SKIP_2X |
  300. (sensor_settings[VFLIP_IDX] << 0) |
  301. (sensor_settings[HFLIP_IDX] << 1);
  302. err = m5602_write_sensor(sd,
  303. MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
  304. break;
  305. case 320:
  306. PDEBUG(D_V4L2, "Configuring camera for QVGA mode");
  307. data[0] = MT9M111_RMB_OVER_SIZED;
  308. data[1] = MT9M111_RMB_ROW_SKIP_4X |
  309. MT9M111_RMB_COLUMN_SKIP_4X |
  310. (sensor_settings[VFLIP_IDX] << 0) |
  311. (sensor_settings[HFLIP_IDX] << 1);
  312. err = m5602_write_sensor(sd,
  313. MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
  314. break;
  315. }
  316. return err;
  317. }
  318. void mt9m111_disconnect(struct sd *sd)
  319. {
  320. sd->sensor = NULL;
  321. kfree(sd->sensor_priv);
  322. }
  323. static int mt9m111_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
  324. {
  325. struct sd *sd = (struct sd *) gspca_dev;
  326. s32 *sensor_settings = sd->sensor_priv;
  327. *val = sensor_settings[VFLIP_IDX];
  328. PDEBUG(D_V4L2, "Read vertical flip %d", *val);
  329. return 0;
  330. }
  331. static int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
  332. {
  333. int err;
  334. u8 data[2] = {0x00, 0x00};
  335. struct sd *sd = (struct sd *) gspca_dev;
  336. s32 *sensor_settings = sd->sensor_priv;
  337. PDEBUG(D_V4L2, "Set vertical flip to %d", val);
  338. sensor_settings[VFLIP_IDX] = val;
  339. /* The mt9m111 is flipped by default */
  340. val = !val;
  341. /* Set the correct page map */
  342. err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
  343. if (err < 0)
  344. return err;
  345. err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
  346. if (err < 0)
  347. return err;
  348. data[1] = (data[1] & 0xfe) | val;
  349. err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
  350. data, 2);
  351. return err;
  352. }
  353. static int mt9m111_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
  354. {
  355. struct sd *sd = (struct sd *) gspca_dev;
  356. s32 *sensor_settings = sd->sensor_priv;
  357. *val = sensor_settings[HFLIP_IDX];
  358. PDEBUG(D_V4L2, "Read horizontal flip %d", *val);
  359. return 0;
  360. }
  361. static int mt9m111_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
  362. {
  363. int err;
  364. u8 data[2] = {0x00, 0x00};
  365. struct sd *sd = (struct sd *) gspca_dev;
  366. s32 *sensor_settings = sd->sensor_priv;
  367. PDEBUG(D_V4L2, "Set horizontal flip to %d", val);
  368. sensor_settings[HFLIP_IDX] = val;
  369. /* The mt9m111 is flipped by default */
  370. val = !val;
  371. /* Set the correct page map */
  372. err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
  373. if (err < 0)
  374. return err;
  375. err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
  376. if (err < 0)
  377. return err;
  378. data[1] = (data[1] & 0xfd) | ((val << 1) & 0x02);
  379. err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
  380. data, 2);
  381. return err;
  382. }
  383. static int mt9m111_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
  384. {
  385. struct sd *sd = (struct sd *) gspca_dev;
  386. s32 *sensor_settings = sd->sensor_priv;
  387. *val = sensor_settings[GAIN_IDX];
  388. PDEBUG(D_V4L2, "Read gain %d", *val);
  389. return 0;
  390. }
  391. static int mt9m111_set_auto_white_balance(struct gspca_dev *gspca_dev,
  392. __s32 val)
  393. {
  394. struct sd *sd = (struct sd *) gspca_dev;
  395. s32 *sensor_settings = sd->sensor_priv;
  396. int err;
  397. u8 data[2];
  398. err = m5602_read_sensor(sd, MT9M111_CP_OPERATING_MODE_CTL, data, 2);
  399. if (err < 0)
  400. return err;
  401. sensor_settings[AUTO_WHITE_BALANCE_IDX] = val & 0x01;
  402. data[1] = ((data[1] & 0xfd) | ((val & 0x01) << 1));
  403. err = m5602_write_sensor(sd, MT9M111_CP_OPERATING_MODE_CTL, data, 2);
  404. PDEBUG(D_V4L2, "Set auto white balance %d", val);
  405. return err;
  406. }
  407. static int mt9m111_get_auto_white_balance(struct gspca_dev *gspca_dev,
  408. __s32 *val) {
  409. struct sd *sd = (struct sd *) gspca_dev;
  410. s32 *sensor_settings = sd->sensor_priv;
  411. *val = sensor_settings[AUTO_WHITE_BALANCE_IDX];
  412. PDEBUG(D_V4L2, "Read auto white balance %d", *val);
  413. return 0;
  414. }
  415. static int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val)
  416. {
  417. int err, tmp;
  418. u8 data[2] = {0x00, 0x00};
  419. struct sd *sd = (struct sd *) gspca_dev;
  420. s32 *sensor_settings = sd->sensor_priv;
  421. sensor_settings[GAIN_IDX] = val;
  422. /* Set the correct page map */
  423. err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
  424. if (err < 0)
  425. return err;
  426. if (val >= INITIAL_MAX_GAIN * 2 * 2 * 2)
  427. return -EINVAL;
  428. if ((val >= INITIAL_MAX_GAIN * 2 * 2) &&
  429. (val < (INITIAL_MAX_GAIN - 1) * 2 * 2 * 2))
  430. tmp = (1 << 10) | (val << 9) |
  431. (val << 8) | (val / 8);
  432. else if ((val >= INITIAL_MAX_GAIN * 2) &&
  433. (val < INITIAL_MAX_GAIN * 2 * 2))
  434. tmp = (1 << 9) | (1 << 8) | (val / 4);
  435. else if ((val >= INITIAL_MAX_GAIN) &&
  436. (val < INITIAL_MAX_GAIN * 2))
  437. tmp = (1 << 8) | (val / 2);
  438. else
  439. tmp = val;
  440. data[1] = (tmp & 0xff);
  441. data[0] = (tmp & 0xff00) >> 8;
  442. PDEBUG(D_V4L2, "tmp=%d, data[1]=%d, data[0]=%d", tmp,
  443. data[1], data[0]);
  444. err = m5602_write_sensor(sd, MT9M111_SC_GLOBAL_GAIN,
  445. data, 2);
  446. return err;
  447. }
  448. static int mt9m111_set_green_balance(struct gspca_dev *gspca_dev, __s32 val)
  449. {
  450. int err;
  451. u8 data[2];
  452. struct sd *sd = (struct sd *) gspca_dev;
  453. s32 *sensor_settings = sd->sensor_priv;
  454. sensor_settings[GREEN_BALANCE_IDX] = val;
  455. data[1] = (val & 0xff);
  456. data[0] = (val & 0xff00) >> 8;
  457. PDEBUG(D_V4L2, "Set green balance %d", val);
  458. err = m5602_write_sensor(sd, MT9M111_SC_GREEN_1_GAIN,
  459. data, 2);
  460. if (err < 0)
  461. return err;
  462. return m5602_write_sensor(sd, MT9M111_SC_GREEN_2_GAIN,
  463. data, 2);
  464. }
  465. static int mt9m111_get_green_balance(struct gspca_dev *gspca_dev, __s32 *val)
  466. {
  467. struct sd *sd = (struct sd *) gspca_dev;
  468. s32 *sensor_settings = sd->sensor_priv;
  469. *val = sensor_settings[GREEN_BALANCE_IDX];
  470. PDEBUG(D_V4L2, "Read green balance %d", *val);
  471. return 0;
  472. }
  473. static int mt9m111_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
  474. {
  475. u8 data[2];
  476. struct sd *sd = (struct sd *) gspca_dev;
  477. s32 *sensor_settings = sd->sensor_priv;
  478. sensor_settings[BLUE_BALANCE_IDX] = val;
  479. data[1] = (val & 0xff);
  480. data[0] = (val & 0xff00) >> 8;
  481. PDEBUG(D_V4L2, "Set blue balance %d", val);
  482. return m5602_write_sensor(sd, MT9M111_SC_BLUE_GAIN,
  483. data, 2);
  484. }
  485. static int mt9m111_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val)
  486. {
  487. struct sd *sd = (struct sd *) gspca_dev;
  488. s32 *sensor_settings = sd->sensor_priv;
  489. *val = sensor_settings[BLUE_BALANCE_IDX];
  490. PDEBUG(D_V4L2, "Read blue balance %d", *val);
  491. return 0;
  492. }
  493. static int mt9m111_set_red_balance(struct gspca_dev *gspca_dev, __s32 val)
  494. {
  495. u8 data[2];
  496. struct sd *sd = (struct sd *) gspca_dev;
  497. s32 *sensor_settings = sd->sensor_priv;
  498. sensor_settings[RED_BALANCE_IDX] = val;
  499. data[1] = (val & 0xff);
  500. data[0] = (val & 0xff00) >> 8;
  501. PDEBUG(D_V4L2, "Set red balance %d", val);
  502. return m5602_write_sensor(sd, MT9M111_SC_RED_GAIN,
  503. data, 2);
  504. }
  505. static int mt9m111_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val)
  506. {
  507. struct sd *sd = (struct sd *) gspca_dev;
  508. s32 *sensor_settings = sd->sensor_priv;
  509. *val = sensor_settings[RED_BALANCE_IDX];
  510. PDEBUG(D_V4L2, "Read red balance %d", *val);
  511. return 0;
  512. }
  513. static void mt9m111_dump_registers(struct sd *sd)
  514. {
  515. u8 address, value[2] = {0x00, 0x00};
  516. pr_info("Dumping the mt9m111 register state\n");
  517. pr_info("Dumping the mt9m111 sensor core registers\n");
  518. value[1] = MT9M111_SENSOR_CORE;
  519. m5602_write_sensor(sd, MT9M111_PAGE_MAP, value, 2);
  520. for (address = 0; address < 0xff; address++) {
  521. m5602_read_sensor(sd, address, value, 2);
  522. pr_info("register 0x%x contains 0x%x%x\n",
  523. address, value[0], value[1]);
  524. }
  525. pr_info("Dumping the mt9m111 color pipeline registers\n");
  526. value[1] = MT9M111_COLORPIPE;
  527. m5602_write_sensor(sd, MT9M111_PAGE_MAP, value, 2);
  528. for (address = 0; address < 0xff; address++) {
  529. m5602_read_sensor(sd, address, value, 2);
  530. pr_info("register 0x%x contains 0x%x%x\n",
  531. address, value[0], value[1]);
  532. }
  533. pr_info("Dumping the mt9m111 camera control registers\n");
  534. value[1] = MT9M111_CAMERA_CONTROL;
  535. m5602_write_sensor(sd, MT9M111_PAGE_MAP, value, 2);
  536. for (address = 0; address < 0xff; address++) {
  537. m5602_read_sensor(sd, address, value, 2);
  538. pr_info("register 0x%x contains 0x%x%x\n",
  539. address, value[0], value[1]);
  540. }
  541. pr_info("mt9m111 register state dump complete\n");
  542. }