Commit | Line | Data |
---|---|---|
ccfc97bd SA |
1 | /* |
2 | * drivers/media/video/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@maxwell.research.nokia.com> | |
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 | ||
25 | #include "smiapp-debug.h" | |
26 | ||
27 | #include <linux/delay.h> | |
28 | ||
29 | #include "smiapp.h" | |
30 | ||
31 | static int smiapp_write_8(struct smiapp_sensor *sensor, u16 reg, u8 val) | |
32 | { | |
33 | struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd); | |
34 | ||
35 | return smiapp_write(client, (SMIA_REG_8BIT << 16) | reg, val); | |
36 | } | |
37 | ||
38 | static int smiapp_write_8s(struct smiapp_sensor *sensor, | |
39 | struct smiapp_reg_8 *regs, int len) | |
40 | { | |
41 | struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd); | |
42 | int rval; | |
43 | ||
44 | for (; len > 0; len--, regs++) { | |
45 | rval = smiapp_write_8(sensor, regs->reg, regs->val); | |
46 | if (rval < 0) { | |
47 | dev_err(&client->dev, | |
48 | "error %d writing reg 0x%4.4x, val 0x%2.2x", | |
49 | rval, regs->reg, regs->val); | |
50 | return rval; | |
51 | } | |
52 | } | |
53 | ||
54 | return 0; | |
55 | } | |
56 | ||
57 | void smiapp_replace_limit(struct smiapp_sensor *sensor, | |
58 | u32 limit, u32 val) | |
59 | { | |
60 | struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd); | |
61 | ||
62 | dev_dbg(&client->dev, "quirk: 0x%8.8x \"%s\" = %d, 0x%x\n", | |
63 | smiapp_reg_limits[limit].addr, | |
64 | smiapp_reg_limits[limit].what, val, val); | |
65 | sensor->limits[limit] = val; | |
66 | } | |
67 | ||
68 | int smiapp_replace_limit_at(struct smiapp_sensor *sensor, | |
69 | u32 reg, u32 val) | |
70 | { | |
71 | struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd); | |
72 | int i; | |
73 | ||
74 | for (i = 0; smiapp_reg_limits[i].addr; i++) { | |
75 | if ((smiapp_reg_limits[i].addr & 0xffff) != reg) | |
76 | continue; | |
77 | ||
78 | smiapp_replace_limit(sensor, i, val); | |
79 | ||
80 | return 0; | |
81 | } | |
82 | ||
83 | dev_dbg(&client->dev, "quirk: bad register 0x%4.4x\n", reg); | |
84 | ||
85 | return -EINVAL; | |
86 | } | |
87 | ||
88 | static int jt8ew9_limits(struct smiapp_sensor *sensor) | |
89 | { | |
90 | if (sensor->minfo.revision_number_major < 0x03) | |
91 | sensor->frame_skip = 1; | |
92 | ||
93 | /* Below 24 gain doesn't have effect at all, */ | |
94 | /* but ~59 is needed for full dynamic range */ | |
95 | smiapp_replace_limit(sensor, SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN, 59); | |
96 | smiapp_replace_limit( | |
97 | sensor, SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MAX, 6000); | |
98 | ||
99 | return 0; | |
100 | } | |
101 | ||
102 | static int jt8ew9_post_poweron(struct smiapp_sensor *sensor) | |
103 | { | |
104 | struct smiapp_reg_8 regs[] = { | |
105 | { 0x30a3, 0xd8 }, /* Output port control : LVDS ports only */ | |
106 | { 0x30ae, 0x00 }, /* 0x0307 pll_multiplier maximum value on PLL input 9.6MHz ( 19.2MHz is divided on pre_pll_div) */ | |
107 | { 0x30af, 0xd0 }, /* 0x0307 pll_multiplier maximum value on PLL input 9.6MHz ( 19.2MHz is divided on pre_pll_div) */ | |
108 | { 0x322d, 0x04 }, /* Adjusting Processing Image Size to Scaler Toshiba Recommendation Setting */ | |
109 | { 0x3255, 0x0f }, /* Horizontal Noise Reduction Control Toshiba Recommendation Setting */ | |
110 | { 0x3256, 0x15 }, /* Horizontal Noise Reduction Control Toshiba Recommendation Setting */ | |
111 | { 0x3258, 0x70 }, /* Analog Gain Control Toshiba Recommendation Setting */ | |
112 | { 0x3259, 0x70 }, /* Analog Gain Control Toshiba Recommendation Setting */ | |
113 | { 0x325f, 0x7c }, /* Analog Gain Control Toshiba Recommendation Setting */ | |
114 | { 0x3302, 0x06 }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */ | |
115 | { 0x3304, 0x00 }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */ | |
116 | { 0x3307, 0x22 }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */ | |
117 | { 0x3308, 0x8d }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */ | |
118 | { 0x331e, 0x0f }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */ | |
119 | { 0x3320, 0x30 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */ | |
120 | { 0x3321, 0x11 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */ | |
121 | { 0x3322, 0x98 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */ | |
122 | { 0x3323, 0x64 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */ | |
123 | { 0x3325, 0x83 }, /* Read Out Timing Control Toshiba Recommendation Setting */ | |
124 | { 0x3330, 0x18 }, /* Read Out Timing Control Toshiba Recommendation Setting */ | |
125 | { 0x333c, 0x01 }, /* Read Out Timing Control Toshiba Recommendation Setting */ | |
126 | { 0x3345, 0x2f }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */ | |
127 | { 0x33de, 0x38 }, /* Horizontal Noise Reduction Control Toshiba Recommendation Setting */ | |
128 | /* Taken from v03. No idea what the rest are. */ | |
129 | { 0x32e0, 0x05 }, | |
130 | { 0x32e1, 0x05 }, | |
131 | { 0x32e2, 0x04 }, | |
132 | { 0x32e5, 0x04 }, | |
133 | { 0x32e6, 0x04 }, | |
134 | ||
135 | }; | |
136 | ||
137 | return smiapp_write_8s(sensor, regs, ARRAY_SIZE(regs)); | |
138 | } | |
139 | ||
140 | const struct smiapp_quirk smiapp_jt8ew9_quirk = { | |
141 | .limits = jt8ew9_limits, | |
142 | .post_poweron = jt8ew9_post_poweron, | |
143 | }; | |
144 | ||
145 | static int imx125es_post_poweron(struct smiapp_sensor *sensor) | |
146 | { | |
147 | /* Taken from v02. No idea what the other two are. */ | |
148 | struct smiapp_reg_8 regs[] = { | |
149 | /* | |
150 | * 0x3302: clk during frame blanking: | |
151 | * 0x00 - HS mode, 0x01 - LP11 | |
152 | */ | |
153 | { 0x3302, 0x01 }, | |
154 | { 0x302d, 0x00 }, | |
155 | { 0x3b08, 0x8c }, | |
156 | }; | |
157 | ||
158 | return smiapp_write_8s(sensor, regs, ARRAY_SIZE(regs)); | |
159 | } | |
160 | ||
161 | const struct smiapp_quirk smiapp_imx125es_quirk = { | |
162 | .post_poweron = imx125es_post_poweron, | |
163 | }; | |
164 | ||
165 | static int jt8ev1_limits(struct smiapp_sensor *sensor) | |
166 | { | |
167 | smiapp_replace_limit(sensor, SMIAPP_LIMIT_X_ADDR_MAX, 4271); | |
168 | smiapp_replace_limit(sensor, | |
169 | SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN, 184); | |
170 | ||
171 | return 0; | |
172 | } | |
173 | ||
174 | static int jt8ev1_post_poweron(struct smiapp_sensor *sensor) | |
175 | { | |
176 | struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd); | |
177 | int rval; | |
178 | ||
179 | struct smiapp_reg_8 regs[] = { | |
180 | { 0x3031, 0xcd }, /* For digital binning (EQ_MONI) */ | |
181 | { 0x30a3, 0xd0 }, /* FLASH STROBE enable */ | |
182 | { 0x3237, 0x00 }, /* For control of pulse timing for ADC */ | |
183 | { 0x3238, 0x43 }, | |
184 | { 0x3301, 0x06 }, /* For analog bias for sensor */ | |
185 | { 0x3302, 0x06 }, | |
186 | { 0x3304, 0x00 }, | |
187 | { 0x3305, 0x88 }, | |
188 | { 0x332a, 0x14 }, | |
189 | { 0x332c, 0x6b }, | |
190 | { 0x3336, 0x01 }, | |
191 | { 0x333f, 0x1f }, | |
192 | { 0x3355, 0x00 }, | |
193 | { 0x3356, 0x20 }, | |
194 | { 0x33bf, 0x20 }, /* Adjust the FBC speed */ | |
195 | { 0x33c9, 0x20 }, | |
196 | { 0x33ce, 0x30 }, /* Adjust the parameter for logic function */ | |
197 | { 0x33cf, 0xec }, /* For Black sun */ | |
198 | { 0x3328, 0x80 }, /* Ugh. No idea what's this. */ | |
199 | }; | |
200 | ||
201 | struct smiapp_reg_8 regs_96[] = { | |
202 | { 0x30ae, 0x00 }, /* For control of ADC clock */ | |
203 | { 0x30af, 0xd0 }, | |
204 | { 0x30b0, 0x01 }, | |
205 | }; | |
206 | ||
207 | rval = smiapp_write_8s(sensor, regs, ARRAY_SIZE(regs)); | |
208 | if (rval < 0) | |
209 | return rval; | |
210 | ||
211 | switch (sensor->platform_data->ext_clk) { | |
212 | case 9600000: | |
213 | return smiapp_write_8s(sensor, regs_96, | |
214 | ARRAY_SIZE(regs_96)); | |
215 | default: | |
216 | dev_warn(&client->dev, "no MSRs for %d Hz ext_clk\n", | |
217 | sensor->platform_data->ext_clk); | |
218 | return 0; | |
219 | } | |
220 | } | |
221 | ||
222 | static int jt8ev1_pre_streamon(struct smiapp_sensor *sensor) | |
223 | { | |
224 | return smiapp_write_8(sensor, 0x3328, 0x00); | |
225 | } | |
226 | ||
227 | static int jt8ev1_post_streamoff(struct smiapp_sensor *sensor) | |
228 | { | |
229 | int rval; | |
230 | ||
231 | /* Workaround: allows fast standby to work properly */ | |
232 | rval = smiapp_write_8(sensor, 0x3205, 0x04); | |
233 | if (rval < 0) | |
234 | return rval; | |
235 | ||
236 | /* Wait for 1 ms + one line => 2 ms is likely enough */ | |
237 | usleep_range(2000, 2000); | |
238 | ||
239 | /* Restore it */ | |
240 | rval = smiapp_write_8(sensor, 0x3205, 0x00); | |
241 | if (rval < 0) | |
242 | return rval; | |
243 | ||
244 | return smiapp_write_8(sensor, 0x3328, 0x80); | |
245 | } | |
246 | ||
247 | const struct smiapp_quirk smiapp_jt8ev1_quirk = { | |
248 | .limits = jt8ev1_limits, | |
249 | .post_poweron = jt8ev1_post_poweron, | |
250 | .pre_streamon = jt8ev1_pre_streamon, | |
251 | .post_streamoff = jt8ev1_post_streamoff, | |
252 | .flags = SMIAPP_QUIRK_FLAG_OP_PIX_CLOCK_PER_LANE, | |
253 | }; | |
254 | ||
255 | static int tcm8500md_limits(struct smiapp_sensor *sensor) | |
256 | { | |
257 | smiapp_replace_limit(sensor, SMIAPP_LIMIT_MIN_PLL_IP_FREQ_HZ, 2700000); | |
258 | ||
259 | return 0; | |
260 | } | |
261 | ||
262 | const struct smiapp_quirk smiapp_tcm8500md_quirk = { | |
263 | .limits = tcm8500md_limits, | |
264 | }; |