stv06xx_vv6410.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Copyright (c) 2001 Jean-Fredric Clere, Nikolas Zimmermann, Georg Acher
  3. * Mark Cave-Ayland, Carlo E Prelz, Dick Streefland
  4. * Copyright (c) 2002, 2003 Tuukka Toivonen
  5. * Copyright (c) 2008 Erik Andrén
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. * P/N 861037: Sensor HDCS1000 ASIC STV0600
  22. * P/N 861050-0010: Sensor HDCS1000 ASIC STV0600
  23. * P/N 861050-0020: Sensor Photobit PB100 ASIC STV0600-1 - QuickCam Express
  24. * P/N 861055: Sensor ST VV6410 ASIC STV0610 - LEGO cam
  25. * P/N 861075-0040: Sensor HDCS1000 ASIC
  26. * P/N 961179-0700: Sensor ST VV6410 ASIC STV0602 - Dexxa WebCam USB
  27. * P/N 861040-0000: Sensor ST VV6410 ASIC STV0610 - QuickCam Web
  28. */
  29. #include "stv06xx_vv6410.h"
  30. static int vv6410_probe(struct sd *sd)
  31. {
  32. u16 data;
  33. int err;
  34. err = stv06xx_read_sensor(sd, VV6410_DEVICEH, &data);
  35. if (err < 0)
  36. return -ENODEV;
  37. if (data == 0x19) {
  38. info("vv6410 sensor detected");
  39. sd->gspca_dev.cam.cam_mode = stv06xx_sensor_vv6410.modes;
  40. sd->gspca_dev.cam.nmodes = stv06xx_sensor_vv6410.nmodes;
  41. sd->desc.ctrls = stv06xx_sensor_vv6410.ctrls;
  42. sd->desc.nctrls = stv06xx_sensor_vv6410.nctrls;
  43. return 0;
  44. }
  45. return -ENODEV;
  46. }
  47. static int vv6410_init(struct sd *sd)
  48. {
  49. int err = 0, i;
  50. for (i = 0; i < ARRAY_SIZE(stv_bridge_init); i++) {
  51. /* if NULL then len contains single value */
  52. if (stv_bridge_init[i].data == NULL) {
  53. err = stv06xx_write_bridge(sd,
  54. stv_bridge_init[i].start,
  55. stv_bridge_init[i].len);
  56. } else {
  57. int j;
  58. for (j = 0; j < stv_bridge_init[i].len; j++)
  59. err = stv06xx_write_bridge(sd,
  60. stv_bridge_init[i].start + j,
  61. stv_bridge_init[i].data[j]);
  62. }
  63. }
  64. if (err < 0)
  65. return err;
  66. err = stv06xx_write_sensor_bytes(sd, (u8 *) vv6410_sensor_init,
  67. ARRAY_SIZE(vv6410_sensor_init));
  68. return (err < 0) ? err : 0;
  69. }
  70. static int vv6410_start(struct sd *sd)
  71. {
  72. int err;
  73. struct cam *cam = &sd->gspca_dev.cam;
  74. u32 priv = cam->cam_mode[sd->gspca_dev.curr_mode].priv;
  75. if (priv & VV6410_CROP_TO_QVGA) {
  76. PDEBUG(D_CONF, "Cropping to QVGA");
  77. stv06xx_write_sensor(sd, VV6410_XENDH, 320 - 1);
  78. stv06xx_write_sensor(sd, VV6410_YENDH, 240 - 1);
  79. } else {
  80. stv06xx_write_sensor(sd, VV6410_XENDH, 360 - 1);
  81. stv06xx_write_sensor(sd, VV6410_YENDH, 294 - 1);
  82. }
  83. if (priv & VV6410_SUBSAMPLE) {
  84. PDEBUG(D_CONF, "Enabling subsampling");
  85. stv06xx_write_bridge(sd, STV_Y_CTRL, 0x02);
  86. stv06xx_write_bridge(sd, STV_X_CTRL, 0x06);
  87. stv06xx_write_bridge(sd, STV_SCAN_RATE, 0x10);
  88. } else {
  89. stv06xx_write_bridge(sd, STV_Y_CTRL, 0x01);
  90. stv06xx_write_bridge(sd, STV_X_CTRL, 0x0a);
  91. stv06xx_write_bridge(sd, STV_SCAN_RATE, 0x20);
  92. }
  93. /* Turn on LED */
  94. err = stv06xx_write_bridge(sd, STV_LED_CTRL, LED_ON);
  95. if (err < 0)
  96. return err;
  97. err = stv06xx_write_sensor(sd, VV6410_SETUP0, 0);
  98. if (err < 0)
  99. return err;
  100. PDEBUG(D_STREAM, "Starting stream");
  101. return 0;
  102. }
  103. static int vv6410_stop(struct sd *sd)
  104. {
  105. int err;
  106. /* Turn off LED */
  107. err = stv06xx_write_bridge(sd, STV_LED_CTRL, LED_OFF);
  108. if (err < 0)
  109. return err;
  110. err = stv06xx_write_sensor(sd, VV6410_SETUP0, VV6410_LOW_POWER_MODE);
  111. if (err < 0)
  112. return err;
  113. PDEBUG(D_STREAM, "Halting stream");
  114. return (err < 0) ? err : 0;
  115. }
  116. static int vv6410_dump(struct sd *sd)
  117. {
  118. u8 i;
  119. int err = 0;
  120. info("Dumping all vv6410 sensor registers");
  121. for (i = 0; i < 0xff && !err; i++) {
  122. u16 data;
  123. err = stv06xx_read_sensor(sd, i, &data);
  124. info("Register 0x%x contained 0x%x", i, data);
  125. }
  126. return (err < 0) ? err : 0;
  127. }
  128. static int vv6410_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
  129. {
  130. int err;
  131. u16 i2c_data;
  132. struct sd *sd = (struct sd *) gspca_dev;
  133. err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data);
  134. *val = (i2c_data & VV6410_HFLIP) ? 1 : 0;
  135. PDEBUG(D_V4L2, "Read horizontal flip %d", *val);
  136. return (err < 0) ? err : 0;
  137. }
  138. static int vv6410_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
  139. {
  140. int err;
  141. u16 i2c_data;
  142. struct sd *sd = (struct sd *) gspca_dev;
  143. err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data);
  144. if (err < 0)
  145. return err;
  146. if (val)
  147. i2c_data |= VV6410_HFLIP;
  148. else
  149. i2c_data &= ~VV6410_HFLIP;
  150. PDEBUG(D_V4L2, "Set horizontal flip to %d", val);
  151. err = stv06xx_write_sensor(sd, VV6410_DATAFORMAT, i2c_data);
  152. return (err < 0) ? err : 0;
  153. }
  154. static int vv6410_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
  155. {
  156. int err;
  157. u16 i2c_data;
  158. struct sd *sd = (struct sd *) gspca_dev;
  159. err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data);
  160. *val = (i2c_data & VV6410_VFLIP) ? 1 : 0;
  161. PDEBUG(D_V4L2, "Read vertical flip %d", *val);
  162. return (err < 0) ? err : 0;
  163. }
  164. static int vv6410_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
  165. {
  166. int err;
  167. u16 i2c_data;
  168. struct sd *sd = (struct sd *) gspca_dev;
  169. err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data);
  170. if (err < 0)
  171. return err;
  172. if (val)
  173. i2c_data |= VV6410_VFLIP;
  174. else
  175. i2c_data &= ~VV6410_VFLIP;
  176. PDEBUG(D_V4L2, "Set vertical flip to %d", val);
  177. err = stv06xx_write_sensor(sd, VV6410_DATAFORMAT, i2c_data);
  178. return (err < 0) ? err : 0;
  179. }
  180. static int vv6410_get_analog_gain(struct gspca_dev *gspca_dev, __s32 *val)
  181. {
  182. int err;
  183. u16 i2c_data;
  184. struct sd *sd = (struct sd *) gspca_dev;
  185. err = stv06xx_read_sensor(sd, VV6410_ANALOGGAIN, &i2c_data);
  186. *val = i2c_data & 0xf;
  187. PDEBUG(D_V4L2, "Read analog gain %d", *val);
  188. return (err < 0) ? err : 0;
  189. }
  190. static int vv6410_set_analog_gain(struct gspca_dev *gspca_dev, __s32 val)
  191. {
  192. int err;
  193. struct sd *sd = (struct sd *) gspca_dev;
  194. PDEBUG(D_V4L2, "Set analog gain to %d", val);
  195. err = stv06xx_write_sensor(sd, VV6410_ANALOGGAIN, 0xf0 | (val & 0xf));
  196. return (err < 0) ? err : 0;
  197. }