m5602_ov7660.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Driver for the ov7660 sensor
  3. *
  4. * Copyright (C) 2009 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_ov7660.h"
  19. const static struct ctrl ov7660_ctrls[] = {};
  20. static struct v4l2_pix_format ov7660_modes[] = {
  21. {
  22. 640,
  23. 480,
  24. V4L2_PIX_FMT_SBGGR8,
  25. V4L2_FIELD_NONE,
  26. .sizeimage =
  27. 640 * 480,
  28. .bytesperline = 640,
  29. .colorspace = V4L2_COLORSPACE_SRGB,
  30. .priv = 0
  31. }
  32. };
  33. static void ov7660_dump_registers(struct sd *sd);
  34. int ov7660_probe(struct sd *sd)
  35. {
  36. int err = 0, i;
  37. u8 prod_id = 0, ver_id = 0;
  38. s32 *sensor_settings;
  39. if (force_sensor) {
  40. if (force_sensor == OV7660_SENSOR) {
  41. info("Forcing an %s sensor", ov7660.name);
  42. goto sensor_found;
  43. }
  44. /* If we want to force another sensor,
  45. don't try to probe this one */
  46. return -ENODEV;
  47. }
  48. /* Do the preinit */
  49. for (i = 0; i < ARRAY_SIZE(preinit_ov7660) && !err; i++) {
  50. u8 data[2];
  51. if (preinit_ov7660[i][0] == BRIDGE) {
  52. err = m5602_write_bridge(sd,
  53. preinit_ov7660[i][1],
  54. preinit_ov7660[i][2]);
  55. } else {
  56. data[0] = preinit_ov7660[i][2];
  57. err = m5602_write_sensor(sd,
  58. preinit_ov7660[i][1], data, 1);
  59. }
  60. }
  61. if (err < 0)
  62. return err;
  63. if (m5602_read_sensor(sd, OV7660_PID, &prod_id, 1))
  64. return -ENODEV;
  65. if (m5602_read_sensor(sd, OV7660_VER, &ver_id, 1))
  66. return -ENODEV;
  67. info("Sensor reported 0x%x%x", prod_id, ver_id);
  68. if ((prod_id == 0x76) && (ver_id == 0x60)) {
  69. info("Detected a ov7660 sensor");
  70. goto sensor_found;
  71. }
  72. return -ENODEV;
  73. sensor_found:
  74. sd->gspca_dev.cam.cam_mode = ov7660_modes;
  75. sd->gspca_dev.cam.nmodes = ARRAY_SIZE(ov7660_modes);
  76. sd->desc->ctrls = ov7660_ctrls;
  77. sd->desc->nctrls = ARRAY_SIZE(ov7660_ctrls);
  78. for (i = 0; i < ARRAY_SIZE(ov7660_ctrls); i++)
  79. sensor_settings[i] = ov7660_ctrls[i].qctrl.default_value;
  80. sd->sensor_priv = sensor_settings;
  81. return 0;
  82. }
  83. int ov7660_init(struct sd *sd)
  84. {
  85. int i, err = 0;
  86. /* Init the sensor */
  87. for (i = 0; i < ARRAY_SIZE(init_ov7660); i++) {
  88. u8 data[2];
  89. if (init_ov7660[i][0] == BRIDGE) {
  90. err = m5602_write_bridge(sd,
  91. init_ov7660[i][1],
  92. init_ov7660[i][2]);
  93. } else {
  94. data[0] = init_ov7660[i][2];
  95. err = m5602_write_sensor(sd,
  96. init_ov7660[i][1], data, 1);
  97. }
  98. }
  99. if (dump_sensor)
  100. ov7660_dump_registers(sd);
  101. return err;
  102. }
  103. int ov7660_start(struct sd *sd)
  104. {
  105. return 0;
  106. }
  107. int ov7660_stop(struct sd *sd)
  108. {
  109. return 0;
  110. }
  111. void ov7660_disconnect(struct sd *sd) {}
  112. static void ov7660_dump_registers(struct sd *sd)
  113. {
  114. int address;
  115. info("Dumping the ov7660 register state");
  116. for (address = 0; address < 0xa9; address++) {
  117. u8 value;
  118. m5602_read_sensor(sd, address, &value, 1);
  119. info("register 0x%x contains 0x%x",
  120. address, value);
  121. }
  122. info("ov7660 register state dump complete");
  123. info("Probing for which registers that are read/write");
  124. for (address = 0; address < 0xff; address++) {
  125. u8 old_value, ctrl_value;
  126. u8 test_value[2] = {0xff, 0xff};
  127. m5602_read_sensor(sd, address, &old_value, 1);
  128. m5602_write_sensor(sd, address, test_value, 1);
  129. m5602_read_sensor(sd, address, &ctrl_value, 1);
  130. if (ctrl_value == test_value[0])
  131. info("register 0x%x is writeable", address);
  132. else
  133. info("register 0x%x is read only", address);
  134. /* Restore original value */
  135. m5602_write_sensor(sd, address, &old_value, 1);
  136. }
  137. }