smiapp-quirk.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * drivers/media/i2c/smiapp/smiapp-quirk.c
  3. *
  4. * Generic driver for SMIA/SMIA++ compliant camera modules
  5. *
  6. * Copyright (C) 2011--2012 Nokia Corporation
  7. * Contact: Sakari Ailus <sakari.ailus@iki.fi>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. #include <linux/delay.h>
  25. #include "smiapp.h"
  26. static int smiapp_write_8(struct smiapp_sensor *sensor, u16 reg, u8 val)
  27. {
  28. return smiapp_write(sensor, SMIAPP_REG_MK_U8(reg), val);
  29. }
  30. static int smiapp_write_8s(struct smiapp_sensor *sensor,
  31. struct smiapp_reg_8 *regs, int len)
  32. {
  33. struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
  34. int rval;
  35. for (; len > 0; len--, regs++) {
  36. rval = smiapp_write_8(sensor, regs->reg, regs->val);
  37. if (rval < 0) {
  38. dev_err(&client->dev,
  39. "error %d writing reg 0x%4.4x, val 0x%2.2x",
  40. rval, regs->reg, regs->val);
  41. return rval;
  42. }
  43. }
  44. return 0;
  45. }
  46. void smiapp_replace_limit(struct smiapp_sensor *sensor,
  47. u32 limit, u32 val)
  48. {
  49. struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
  50. dev_dbg(&client->dev, "quirk: 0x%8.8x \"%s\" = %d, 0x%x\n",
  51. smiapp_reg_limits[limit].addr,
  52. smiapp_reg_limits[limit].what, val, val);
  53. sensor->limits[limit] = val;
  54. }
  55. static int jt8ew9_limits(struct smiapp_sensor *sensor)
  56. {
  57. if (sensor->minfo.revision_number_major < 0x03)
  58. sensor->frame_skip = 1;
  59. /* Below 24 gain doesn't have effect at all, */
  60. /* but ~59 is needed for full dynamic range */
  61. smiapp_replace_limit(sensor, SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN, 59);
  62. smiapp_replace_limit(
  63. sensor, SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MAX, 6000);
  64. return 0;
  65. }
  66. static int jt8ew9_post_poweron(struct smiapp_sensor *sensor)
  67. {
  68. struct smiapp_reg_8 regs[] = {
  69. { 0x30a3, 0xd8 }, /* Output port control : LVDS ports only */
  70. { 0x30ae, 0x00 }, /* 0x0307 pll_multiplier maximum value on PLL input 9.6MHz ( 19.2MHz is divided on pre_pll_div) */
  71. { 0x30af, 0xd0 }, /* 0x0307 pll_multiplier maximum value on PLL input 9.6MHz ( 19.2MHz is divided on pre_pll_div) */
  72. { 0x322d, 0x04 }, /* Adjusting Processing Image Size to Scaler Toshiba Recommendation Setting */
  73. { 0x3255, 0x0f }, /* Horizontal Noise Reduction Control Toshiba Recommendation Setting */
  74. { 0x3256, 0x15 }, /* Horizontal Noise Reduction Control Toshiba Recommendation Setting */
  75. { 0x3258, 0x70 }, /* Analog Gain Control Toshiba Recommendation Setting */
  76. { 0x3259, 0x70 }, /* Analog Gain Control Toshiba Recommendation Setting */
  77. { 0x325f, 0x7c }, /* Analog Gain Control Toshiba Recommendation Setting */
  78. { 0x3302, 0x06 }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */
  79. { 0x3304, 0x00 }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */
  80. { 0x3307, 0x22 }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */
  81. { 0x3308, 0x8d }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */
  82. { 0x331e, 0x0f }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
  83. { 0x3320, 0x30 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
  84. { 0x3321, 0x11 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
  85. { 0x3322, 0x98 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
  86. { 0x3323, 0x64 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
  87. { 0x3325, 0x83 }, /* Read Out Timing Control Toshiba Recommendation Setting */
  88. { 0x3330, 0x18 }, /* Read Out Timing Control Toshiba Recommendation Setting */
  89. { 0x333c, 0x01 }, /* Read Out Timing Control Toshiba Recommendation Setting */
  90. { 0x3345, 0x2f }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
  91. { 0x33de, 0x38 }, /* Horizontal Noise Reduction Control Toshiba Recommendation Setting */
  92. /* Taken from v03. No idea what the rest are. */
  93. { 0x32e0, 0x05 },
  94. { 0x32e1, 0x05 },
  95. { 0x32e2, 0x04 },
  96. { 0x32e5, 0x04 },
  97. { 0x32e6, 0x04 },
  98. };
  99. return smiapp_write_8s(sensor, regs, ARRAY_SIZE(regs));
  100. }
  101. const struct smiapp_quirk smiapp_jt8ew9_quirk = {
  102. .limits = jt8ew9_limits,
  103. .post_poweron = jt8ew9_post_poweron,
  104. };
  105. static int imx125es_post_poweron(struct smiapp_sensor *sensor)
  106. {
  107. /* Taken from v02. No idea what the other two are. */
  108. struct smiapp_reg_8 regs[] = {
  109. /*
  110. * 0x3302: clk during frame blanking:
  111. * 0x00 - HS mode, 0x01 - LP11
  112. */
  113. { 0x3302, 0x01 },
  114. { 0x302d, 0x00 },
  115. { 0x3b08, 0x8c },
  116. };
  117. return smiapp_write_8s(sensor, regs, ARRAY_SIZE(regs));
  118. }
  119. const struct smiapp_quirk smiapp_imx125es_quirk = {
  120. .post_poweron = imx125es_post_poweron,
  121. };
  122. static int jt8ev1_limits(struct smiapp_sensor *sensor)
  123. {
  124. smiapp_replace_limit(sensor, SMIAPP_LIMIT_X_ADDR_MAX, 4271);
  125. smiapp_replace_limit(sensor,
  126. SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN, 184);
  127. return 0;
  128. }
  129. static int jt8ev1_post_poweron(struct smiapp_sensor *sensor)
  130. {
  131. struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
  132. int rval;
  133. struct smiapp_reg_8 regs[] = {
  134. { 0x3031, 0xcd }, /* For digital binning (EQ_MONI) */
  135. { 0x30a3, 0xd0 }, /* FLASH STROBE enable */
  136. { 0x3237, 0x00 }, /* For control of pulse timing for ADC */
  137. { 0x3238, 0x43 },
  138. { 0x3301, 0x06 }, /* For analog bias for sensor */
  139. { 0x3302, 0x06 },
  140. { 0x3304, 0x00 },
  141. { 0x3305, 0x88 },
  142. { 0x332a, 0x14 },
  143. { 0x332c, 0x6b },
  144. { 0x3336, 0x01 },
  145. { 0x333f, 0x1f },
  146. { 0x3355, 0x00 },
  147. { 0x3356, 0x20 },
  148. { 0x33bf, 0x20 }, /* Adjust the FBC speed */
  149. { 0x33c9, 0x20 },
  150. { 0x33ce, 0x30 }, /* Adjust the parameter for logic function */
  151. { 0x33cf, 0xec }, /* For Black sun */
  152. { 0x3328, 0x80 }, /* Ugh. No idea what's this. */
  153. };
  154. struct smiapp_reg_8 regs_96[] = {
  155. { 0x30ae, 0x00 }, /* For control of ADC clock */
  156. { 0x30af, 0xd0 },
  157. { 0x30b0, 0x01 },
  158. };
  159. rval = smiapp_write_8s(sensor, regs, ARRAY_SIZE(regs));
  160. if (rval < 0)
  161. return rval;
  162. switch (sensor->platform_data->ext_clk) {
  163. case 9600000:
  164. return smiapp_write_8s(sensor, regs_96,
  165. ARRAY_SIZE(regs_96));
  166. default:
  167. dev_warn(&client->dev, "no MSRs for %d Hz ext_clk\n",
  168. sensor->platform_data->ext_clk);
  169. return 0;
  170. }
  171. }
  172. static int jt8ev1_pre_streamon(struct smiapp_sensor *sensor)
  173. {
  174. return smiapp_write_8(sensor, 0x3328, 0x00);
  175. }
  176. static int jt8ev1_post_streamoff(struct smiapp_sensor *sensor)
  177. {
  178. int rval;
  179. /* Workaround: allows fast standby to work properly */
  180. rval = smiapp_write_8(sensor, 0x3205, 0x04);
  181. if (rval < 0)
  182. return rval;
  183. /* Wait for 1 ms + one line => 2 ms is likely enough */
  184. usleep_range(2000, 2000);
  185. /* Restore it */
  186. rval = smiapp_write_8(sensor, 0x3205, 0x00);
  187. if (rval < 0)
  188. return rval;
  189. return smiapp_write_8(sensor, 0x3328, 0x80);
  190. }
  191. static unsigned long jt8ev1_pll_flags(struct smiapp_sensor *sensor)
  192. {
  193. return SMIAPP_PLL_FLAG_OP_PIX_CLOCK_PER_LANE;
  194. }
  195. const struct smiapp_quirk smiapp_jt8ev1_quirk = {
  196. .limits = jt8ev1_limits,
  197. .post_poweron = jt8ev1_post_poweron,
  198. .pre_streamon = jt8ev1_pre_streamon,
  199. .post_streamoff = jt8ev1_post_streamoff,
  200. .pll_flags = jt8ev1_pll_flags,
  201. };
  202. static int tcm8500md_limits(struct smiapp_sensor *sensor)
  203. {
  204. smiapp_replace_limit(sensor, SMIAPP_LIMIT_MIN_PLL_IP_FREQ_HZ, 2700000);
  205. return 0;
  206. }
  207. const struct smiapp_quirk smiapp_tcm8500md_quirk = {
  208. .limits = tcm8500md_limits,
  209. };