sn9c102_tas5110c1b.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /***************************************************************************
  2. * Plug-in for TAS5110C1B image sensor connected to the SN9C10x PC Camera *
  3. * Controllers *
  4. * *
  5. * Copyright (C) 2004-2005 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 "sn9c102_sensor.h"
  22. static struct sn9c102_sensor tas5110c1b;
  23. static struct v4l2_control tas5110c1b_gain;
  24. static int tas5110c1b_init(struct sn9c102_device* cam)
  25. {
  26. int err = 0;
  27. err += sn9c102_write_reg(cam, 0x01, 0x01);
  28. err += sn9c102_write_reg(cam, 0x44, 0x01);
  29. err += sn9c102_write_reg(cam, 0x00, 0x10);
  30. err += sn9c102_write_reg(cam, 0x00, 0x11);
  31. err += sn9c102_write_reg(cam, 0x0a, 0x14);
  32. err += sn9c102_write_reg(cam, 0x60, 0x17);
  33. err += sn9c102_write_reg(cam, 0x06, 0x18);
  34. err += sn9c102_write_reg(cam, 0xfb, 0x19);
  35. err += sn9c102_i2c_write(cam, 0xc0, 0x80);
  36. return err;
  37. }
  38. static int tas5110c1b_get_ctrl(struct sn9c102_device* cam,
  39. struct v4l2_control* ctrl)
  40. {
  41. switch (ctrl->id) {
  42. case V4L2_CID_GAIN:
  43. ctrl->value = tas5110c1b_gain.value;
  44. break;
  45. default:
  46. return -EINVAL;
  47. }
  48. return 0;
  49. }
  50. static int tas5110c1b_set_ctrl(struct sn9c102_device* cam,
  51. const struct v4l2_control* ctrl)
  52. {
  53. int err = 0;
  54. switch (ctrl->id) {
  55. case V4L2_CID_GAIN:
  56. if (!(err += sn9c102_i2c_write(cam, 0x20, 0xf6 - ctrl->value)))
  57. tas5110c1b_gain.value = ctrl->value;
  58. break;
  59. default:
  60. return -EINVAL;
  61. }
  62. return err ? -EIO : 0;
  63. }
  64. static int tas5110c1b_set_crop(struct sn9c102_device* cam,
  65. const struct v4l2_rect* rect)
  66. {
  67. struct sn9c102_sensor* s = &tas5110c1b;
  68. int err = 0;
  69. u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 69,
  70. v_start = (u8)(rect->top - s->cropcap.bounds.top) + 9;
  71. err += sn9c102_write_reg(cam, h_start, 0x12);
  72. err += sn9c102_write_reg(cam, v_start, 0x13);
  73. /* Don't change ! */
  74. err += sn9c102_write_reg(cam, 0x14, 0x1a);
  75. err += sn9c102_write_reg(cam, 0x0a, 0x1b);
  76. err += sn9c102_write_reg(cam, sn9c102_pread_reg(cam, 0x19), 0x19);
  77. return err;
  78. }
  79. static int tas5110c1b_set_pix_format(struct sn9c102_device* cam,
  80. const struct v4l2_pix_format* pix)
  81. {
  82. int err = 0;
  83. if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X)
  84. err += sn9c102_write_reg(cam, 0x2b, 0x19);
  85. else
  86. err += sn9c102_write_reg(cam, 0xfb, 0x19);
  87. return err;
  88. }
  89. static struct sn9c102_sensor tas5110c1b = {
  90. .name = "TAS5110C1B",
  91. .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
  92. .sysfs_ops = SN9C102_I2C_WRITE,
  93. .frequency = SN9C102_I2C_100KHZ,
  94. .interface = SN9C102_I2C_3WIRES,
  95. .init = &tas5110c1b_init,
  96. .qctrl = {
  97. {
  98. .id = V4L2_CID_GAIN,
  99. .type = V4L2_CTRL_TYPE_INTEGER,
  100. .name = "global gain",
  101. .minimum = 0x00,
  102. .maximum = 0xf6,
  103. .step = 0x01,
  104. .default_value = 0x40,
  105. .flags = 0,
  106. },
  107. },
  108. .set_ctrl = &tas5110c1b_set_ctrl,
  109. .cropcap = {
  110. .bounds = {
  111. .left = 0,
  112. .top = 0,
  113. .width = 352,
  114. .height = 288,
  115. },
  116. .defrect = {
  117. .left = 0,
  118. .top = 0,
  119. .width = 352,
  120. .height = 288,
  121. },
  122. },
  123. .get_ctrl = &tas5110c1b_get_ctrl,
  124. .set_crop = &tas5110c1b_set_crop,
  125. .pix_format = {
  126. .width = 352,
  127. .height = 288,
  128. .pixelformat = V4L2_PIX_FMT_SBGGR8,
  129. .priv = 8,
  130. },
  131. .set_pix_format = &tas5110c1b_set_pix_format
  132. };
  133. int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam)
  134. {
  135. /* This sensor has no identifiers, so let's attach it anyway */
  136. sn9c102_attach_sensor(cam, &tas5110c1b);
  137. /* Sensor detection is based on USB pid/vid */
  138. if (le16_to_cpu(tas5110c1b.usbdev->descriptor.idProduct) != 0x6001 &&
  139. le16_to_cpu(tas5110c1b.usbdev->descriptor.idProduct) != 0x6005 &&
  140. le16_to_cpu(tas5110c1b.usbdev->descriptor.idProduct) != 0x60ab)
  141. return -ENODEV;
  142. return 0;
  143. }