sn9c102_pas202bca.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /***************************************************************************
  2. * Plug-in for PAS202BCA image sensor connected to the SN9C10x PC Camera *
  3. * Controllers *
  4. * *
  5. * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> *
  6. * *
  7. * This program is free software; you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation; either version 2 of the License, or *
  10. * (at your option) any later version. *
  11. * *
  12. * This program is distributed in the hope that it will be useful, *
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15. * GNU General Public License for more details. *
  16. * *
  17. * You should have received a copy of the GNU General Public License *
  18. * along with this program; if not, write to the Free Software *
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
  20. ***************************************************************************/
  21. #include <linux/delay.h>
  22. #include "sn9c102_sensor.h"
  23. static struct sn9c102_sensor pas202bca;
  24. static int pas202bca_init(struct sn9c102_device* cam)
  25. {
  26. int err = 0;
  27. err += sn9c102_write_reg(cam, 0x00, 0x10);
  28. err += sn9c102_write_reg(cam, 0x00, 0x11);
  29. err += sn9c102_write_reg(cam, 0x00, 0x14);
  30. err += sn9c102_write_reg(cam, 0x20, 0x17);
  31. err += sn9c102_write_reg(cam, 0x30, 0x19);
  32. err += sn9c102_write_reg(cam, 0x09, 0x18);
  33. err += sn9c102_i2c_write(cam, 0x02, 0x14);
  34. err += sn9c102_i2c_write(cam, 0x03, 0x40);
  35. err += sn9c102_i2c_write(cam, 0x0d, 0x2c);
  36. err += sn9c102_i2c_write(cam, 0x0e, 0x01);
  37. err += sn9c102_i2c_write(cam, 0x0f, 0xa9);
  38. err += sn9c102_i2c_write(cam, 0x10, 0x08);
  39. err += sn9c102_i2c_write(cam, 0x13, 0x63);
  40. err += sn9c102_i2c_write(cam, 0x15, 0x70);
  41. err += sn9c102_i2c_write(cam, 0x11, 0x01);
  42. msleep(400);
  43. return err;
  44. }
  45. static int pas202bca_set_pix_format(struct sn9c102_device* cam,
  46. const struct v4l2_pix_format* pix)
  47. {
  48. int err = 0;
  49. if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X)
  50. err += sn9c102_write_reg(cam, 0x24, 0x17);
  51. else
  52. err += sn9c102_write_reg(cam, 0x20, 0x17);
  53. return err;
  54. }
  55. static int pas202bca_set_ctrl(struct sn9c102_device* cam,
  56. const struct v4l2_control* ctrl)
  57. {
  58. int err = 0;
  59. switch (ctrl->id) {
  60. case V4L2_CID_EXPOSURE:
  61. err += sn9c102_i2c_write(cam, 0x04, ctrl->value >> 6);
  62. err += sn9c102_i2c_write(cam, 0x05, ctrl->value & 0x3f);
  63. break;
  64. case V4L2_CID_RED_BALANCE:
  65. err += sn9c102_i2c_write(cam, 0x09, ctrl->value);
  66. break;
  67. case V4L2_CID_BLUE_BALANCE:
  68. err += sn9c102_i2c_write(cam, 0x07, ctrl->value);
  69. break;
  70. case V4L2_CID_GAIN:
  71. err += sn9c102_i2c_write(cam, 0x10, ctrl->value);
  72. break;
  73. case SN9C102_V4L2_CID_GREEN_BALANCE:
  74. err += sn9c102_i2c_write(cam, 0x08, ctrl->value);
  75. break;
  76. case SN9C102_V4L2_CID_DAC_MAGNITUDE:
  77. err += sn9c102_i2c_write(cam, 0x0c, ctrl->value);
  78. break;
  79. default:
  80. return -EINVAL;
  81. }
  82. err += sn9c102_i2c_write(cam, 0x11, 0x01);
  83. return err ? -EIO : 0;
  84. }
  85. static int pas202bca_set_crop(struct sn9c102_device* cam,
  86. const struct v4l2_rect* rect)
  87. {
  88. struct sn9c102_sensor* s = &pas202bca;
  89. int err = 0;
  90. u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 3,
  91. v_start = (u8)(rect->top - s->cropcap.bounds.top) + 3;
  92. err += sn9c102_write_reg(cam, h_start, 0x12);
  93. err += sn9c102_write_reg(cam, v_start, 0x13);
  94. return err;
  95. }
  96. static struct sn9c102_sensor pas202bca = {
  97. .name = "PAS202BCA",
  98. .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
  99. .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE,
  100. .frequency = SN9C102_I2C_400KHZ | SN9C102_I2C_100KHZ,
  101. .interface = SN9C102_I2C_2WIRES,
  102. .i2c_slave_id = 0x40,
  103. .init = &pas202bca_init,
  104. .qctrl = {
  105. {
  106. .id = V4L2_CID_EXPOSURE,
  107. .type = V4L2_CTRL_TYPE_INTEGER,
  108. .name = "exposure",
  109. .minimum = 0x01e5,
  110. .maximum = 0x3fff,
  111. .step = 0x0001,
  112. .default_value = 0x01e5,
  113. .flags = 0,
  114. },
  115. {
  116. .id = V4L2_CID_GAIN,
  117. .type = V4L2_CTRL_TYPE_INTEGER,
  118. .name = "global gain",
  119. .minimum = 0x00,
  120. .maximum = 0x1f,
  121. .step = 0x01,
  122. .default_value = 0x0c,
  123. .flags = 0,
  124. },
  125. {
  126. .id = V4L2_CID_RED_BALANCE,
  127. .type = V4L2_CTRL_TYPE_INTEGER,
  128. .name = "red balance",
  129. .minimum = 0x00,
  130. .maximum = 0x0f,
  131. .step = 0x01,
  132. .default_value = 0x01,
  133. .flags = 0,
  134. },
  135. {
  136. .id = V4L2_CID_BLUE_BALANCE,
  137. .type = V4L2_CTRL_TYPE_INTEGER,
  138. .name = "blue balance",
  139. .minimum = 0x00,
  140. .maximum = 0x0f,
  141. .step = 0x01,
  142. .default_value = 0x05,
  143. .flags = 0,
  144. },
  145. {
  146. .id = SN9C102_V4L2_CID_GREEN_BALANCE,
  147. .type = V4L2_CTRL_TYPE_INTEGER,
  148. .name = "green balance",
  149. .minimum = 0x00,
  150. .maximum = 0x0f,
  151. .step = 0x01,
  152. .default_value = 0x00,
  153. .flags = 0,
  154. },
  155. {
  156. .id = SN9C102_V4L2_CID_DAC_MAGNITUDE,
  157. .type = V4L2_CTRL_TYPE_INTEGER,
  158. .name = "DAC magnitude",
  159. .minimum = 0x00,
  160. .maximum = 0xff,
  161. .step = 0x01,
  162. .default_value = 0x04,
  163. .flags = 0,
  164. },
  165. },
  166. .set_ctrl = &pas202bca_set_ctrl,
  167. .cropcap = {
  168. .bounds = {
  169. .left = 0,
  170. .top = 0,
  171. .width = 640,
  172. .height = 480,
  173. },
  174. .defrect = {
  175. .left = 0,
  176. .top = 0,
  177. .width = 640,
  178. .height = 480,
  179. },
  180. },
  181. .set_crop = &pas202bca_set_crop,
  182. .pix_format = {
  183. .width = 640,
  184. .height = 480,
  185. .pixelformat = V4L2_PIX_FMT_SBGGR8,
  186. .priv = 8,
  187. },
  188. .set_pix_format = &pas202bca_set_pix_format
  189. };
  190. int sn9c102_probe_pas202bca(struct sn9c102_device* cam)
  191. {
  192. const struct usb_device_id pas202bca_id_table[] = {
  193. { USB_DEVICE(0x0c45, 0x60af), },
  194. { }
  195. };
  196. int err = 0;
  197. if (!sn9c102_match_id(cam,pas202bca_id_table))
  198. return -ENODEV;
  199. err += sn9c102_write_reg(cam, 0x01, 0x01);
  200. err += sn9c102_write_reg(cam, 0x40, 0x01);
  201. err += sn9c102_write_reg(cam, 0x28, 0x17);
  202. if (err)
  203. return -EIO;
  204. if (sn9c102_i2c_try_write(cam, &pas202bca, 0x10, 0)) /* try to write */
  205. return -ENODEV;
  206. sn9c102_attach_sensor(cam, &pas202bca);
  207. return 0;
  208. }