sn9c102_tas5110c1b.c 4.5 KB

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