em28xx-camera.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. em28xx-camera.c - driver for Empia EM25xx/27xx/28xx USB video capture devices
  3. Copyright (C) 2009 Mauro Carvalho Chehab <mchehab@infradead.org>
  4. Copyright (C) 2013 Frank Schäfer <fschaefer.oss@googlemail.com>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #include <linux/i2c.h>
  18. #include <media/mt9v011.h>
  19. #include <media/v4l2-common.h>
  20. #include "em28xx.h"
  21. /* FIXME: Should be replaced by a proper mt9m111 driver */
  22. static int em28xx_initialize_mt9m111(struct em28xx *dev)
  23. {
  24. int i;
  25. unsigned char regs[][3] = {
  26. { 0x0d, 0x00, 0x01, }, /* reset and use defaults */
  27. { 0x0d, 0x00, 0x00, },
  28. { 0x0a, 0x00, 0x21, },
  29. { 0x21, 0x04, 0x00, }, /* full readout speed, no row/col skipping */
  30. };
  31. for (i = 0; i < ARRAY_SIZE(regs); i++)
  32. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
  33. &regs[i][0], 3);
  34. return 0;
  35. }
  36. /* FIXME: Should be replaced by a proper mt9m001 driver */
  37. static int em28xx_initialize_mt9m001(struct em28xx *dev)
  38. {
  39. int i;
  40. unsigned char regs[][3] = {
  41. { 0x0d, 0x00, 0x01, },
  42. { 0x0d, 0x00, 0x00, },
  43. { 0x04, 0x05, 0x00, }, /* hres = 1280 */
  44. { 0x03, 0x04, 0x00, }, /* vres = 1024 */
  45. { 0x20, 0x11, 0x00, },
  46. { 0x06, 0x00, 0x10, },
  47. { 0x2b, 0x00, 0x24, },
  48. { 0x2e, 0x00, 0x24, },
  49. { 0x35, 0x00, 0x24, },
  50. { 0x2d, 0x00, 0x20, },
  51. { 0x2c, 0x00, 0x20, },
  52. { 0x09, 0x0a, 0xd4, },
  53. { 0x35, 0x00, 0x57, },
  54. };
  55. for (i = 0; i < ARRAY_SIZE(regs); i++)
  56. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
  57. &regs[i][0], 3);
  58. return 0;
  59. }
  60. /*
  61. * This method works for webcams with Micron sensors
  62. */
  63. int em28xx_detect_sensor(struct em28xx *dev)
  64. {
  65. int ret;
  66. char *name;
  67. u8 reg;
  68. __be16 id_be;
  69. u16 id;
  70. /* Micron sensor detection */
  71. dev->i2c_client[dev->def_i2c_bus].addr = 0xba >> 1;
  72. reg = 0;
  73. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], &reg, 1);
  74. ret = i2c_master_recv(&dev->i2c_client[dev->def_i2c_bus],
  75. (char *)&id_be, 2);
  76. if (ret != 2)
  77. return -EINVAL;
  78. id = be16_to_cpu(id_be);
  79. switch (id) {
  80. case 0x8232: /* mt9v011 640x480 1.3 Mpix sensor */
  81. case 0x8243: /* mt9v011 rev B 640x480 1.3 Mpix sensor */
  82. name = "mt9v011";
  83. dev->em28xx_sensor = EM28XX_MT9V011;
  84. break;
  85. case 0x143a: /* MT9M111 as found in the ECS G200 */
  86. name = "mt9m111";
  87. dev->em28xx_sensor = EM28XX_MT9M111;
  88. break;
  89. case 0x8431:
  90. name = "mt9m001";
  91. dev->em28xx_sensor = EM28XX_MT9M001;
  92. break;
  93. default:
  94. em28xx_info("unknown Micron sensor detected: 0x%04x\n", id);
  95. return -EINVAL;
  96. }
  97. em28xx_info("sensor %s detected\n", name);
  98. return 0;
  99. }
  100. int em28xx_init_camera(struct em28xx *dev)
  101. {
  102. switch (dev->em28xx_sensor) {
  103. case EM28XX_MT9V011:
  104. {
  105. struct mt9v011_platform_data pdata;
  106. struct i2c_board_info mt9v011_info = {
  107. .type = "mt9v011",
  108. .addr = dev->i2c_client[dev->def_i2c_bus].addr,
  109. .platform_data = &pdata,
  110. };
  111. dev->sensor_xres = 640;
  112. dev->sensor_yres = 480;
  113. /*
  114. * FIXME: mt9v011 uses I2S speed as xtal clk - at least with
  115. * the Silvercrest cam I have here for testing - for higher
  116. * resolutions, a high clock cause horizontal artifacts, so we
  117. * need to use a lower xclk frequency.
  118. * Yet, it would be possible to adjust xclk depending on the
  119. * desired resolution, since this affects directly the
  120. * frame rate.
  121. */
  122. dev->board.xclk = EM28XX_XCLK_FREQUENCY_4_3MHZ;
  123. em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
  124. dev->sensor_xtal = 4300000;
  125. pdata.xtal = dev->sensor_xtal;
  126. if (NULL ==
  127. v4l2_i2c_new_subdev_board(&dev->v4l2_dev,
  128. &dev->i2c_adap[dev->def_i2c_bus],
  129. &mt9v011_info, NULL))
  130. return -ENODEV;
  131. /* probably means GRGB 16 bit bayer */
  132. dev->vinmode = 0x0d;
  133. dev->vinctl = 0x00;
  134. break;
  135. }
  136. case EM28XX_MT9M001:
  137. dev->sensor_xres = 1280;
  138. dev->sensor_yres = 1024;
  139. em28xx_initialize_mt9m001(dev);
  140. /* probably means BGGR 16 bit bayer */
  141. dev->vinmode = 0x0c;
  142. dev->vinctl = 0x00;
  143. break;
  144. case EM28XX_MT9M111:
  145. dev->sensor_xres = 640;
  146. dev->sensor_yres = 512;
  147. dev->board.xclk = EM28XX_XCLK_FREQUENCY_48MHZ;
  148. em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
  149. em28xx_initialize_mt9m111(dev);
  150. dev->vinmode = 0x0a;
  151. dev->vinctl = 0x00;
  152. break;
  153. case EM28XX_NOSENSOR:
  154. default:
  155. return -EINVAL;
  156. }
  157. return 0;
  158. }