1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/delay.h>
20
21#include "smiapp.h"
22
23static int smiapp_write_8(struct smiapp_sensor *sensor, u16 reg, u8 val)
24{
25 return smiapp_write(sensor, SMIAPP_REG_MK_U8(reg), val);
26}
27
28static int smiapp_write_8s(struct smiapp_sensor *sensor,
29 const struct smiapp_reg_8 *regs, int len)
30{
31 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
32 int rval;
33
34 for (; len > 0; len--, regs++) {
35 rval = smiapp_write_8(sensor, regs->reg, regs->val);
36 if (rval < 0) {
37 dev_err(&client->dev,
38 "error %d writing reg 0x%4.4x, val 0x%2.2x",
39 rval, regs->reg, regs->val);
40 return rval;
41 }
42 }
43
44 return 0;
45}
46
47void smiapp_replace_limit(struct smiapp_sensor *sensor,
48 u32 limit, u32 val)
49{
50 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
51
52 dev_dbg(&client->dev, "quirk: 0x%8.8x \"%s\" = %d, 0x%x\n",
53 smiapp_reg_limits[limit].addr,
54 smiapp_reg_limits[limit].what, val, val);
55 sensor->limits[limit] = val;
56}
57
58static int jt8ew9_limits(struct smiapp_sensor *sensor)
59{
60 if (sensor->minfo.revision_number_major < 0x03)
61 sensor->frame_skip = 1;
62
63
64
65 smiapp_replace_limit(sensor, SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN, 59);
66 smiapp_replace_limit(
67 sensor, SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MAX, 6000);
68
69 return 0;
70}
71
72static int jt8ew9_post_poweron(struct smiapp_sensor *sensor)
73{
74 static const struct smiapp_reg_8 regs[] = {
75 { 0x30a3, 0xd8 },
76 { 0x30ae, 0x00 },
77 { 0x30af, 0xd0 },
78 { 0x322d, 0x04 },
79 { 0x3255, 0x0f },
80 { 0x3256, 0x15 },
81 { 0x3258, 0x70 },
82 { 0x3259, 0x70 },
83 { 0x325f, 0x7c },
84 { 0x3302, 0x06 },
85 { 0x3304, 0x00 },
86 { 0x3307, 0x22 },
87 { 0x3308, 0x8d },
88 { 0x331e, 0x0f },
89 { 0x3320, 0x30 },
90 { 0x3321, 0x11 },
91 { 0x3322, 0x98 },
92 { 0x3323, 0x64 },
93 { 0x3325, 0x83 },
94 { 0x3330, 0x18 },
95 { 0x333c, 0x01 },
96 { 0x3345, 0x2f },
97 { 0x33de, 0x38 },
98
99 { 0x32e0, 0x05 },
100 { 0x32e1, 0x05 },
101 { 0x32e2, 0x04 },
102 { 0x32e5, 0x04 },
103 { 0x32e6, 0x04 },
104
105 };
106
107 return smiapp_write_8s(sensor, regs, ARRAY_SIZE(regs));
108}
109
110const struct smiapp_quirk smiapp_jt8ew9_quirk = {
111 .limits = jt8ew9_limits,
112 .post_poweron = jt8ew9_post_poweron,
113};
114
115static int imx125es_post_poweron(struct smiapp_sensor *sensor)
116{
117
118 static const struct smiapp_reg_8 regs[] = {
119
120
121
122
123 { 0x3302, 0x01 },
124 { 0x302d, 0x00 },
125 { 0x3b08, 0x8c },
126 };
127
128 return smiapp_write_8s(sensor, regs, ARRAY_SIZE(regs));
129}
130
131const struct smiapp_quirk smiapp_imx125es_quirk = {
132 .post_poweron = imx125es_post_poweron,
133};
134
135static int jt8ev1_limits(struct smiapp_sensor *sensor)
136{
137 smiapp_replace_limit(sensor, SMIAPP_LIMIT_X_ADDR_MAX, 4271);
138 smiapp_replace_limit(sensor,
139 SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN, 184);
140
141 return 0;
142}
143
144static int jt8ev1_post_poweron(struct smiapp_sensor *sensor)
145{
146 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
147 int rval;
148 static const struct smiapp_reg_8 regs[] = {
149 { 0x3031, 0xcd },
150 { 0x30a3, 0xd0 },
151 { 0x3237, 0x00 },
152 { 0x3238, 0x43 },
153 { 0x3301, 0x06 },
154 { 0x3302, 0x06 },
155 { 0x3304, 0x00 },
156 { 0x3305, 0x88 },
157 { 0x332a, 0x14 },
158 { 0x332c, 0x6b },
159 { 0x3336, 0x01 },
160 { 0x333f, 0x1f },
161 { 0x3355, 0x00 },
162 { 0x3356, 0x20 },
163 { 0x33bf, 0x20 },
164 { 0x33c9, 0x20 },
165 { 0x33ce, 0x30 },
166 { 0x33cf, 0xec },
167 { 0x3328, 0x80 },
168 };
169 static const struct smiapp_reg_8 regs_96[] = {
170 { 0x30ae, 0x00 },
171 { 0x30af, 0xd0 },
172 { 0x30b0, 0x01 },
173 };
174
175 rval = smiapp_write_8s(sensor, regs, ARRAY_SIZE(regs));
176 if (rval < 0)
177 return rval;
178
179 switch (sensor->hwcfg->ext_clk) {
180 case 9600000:
181 return smiapp_write_8s(sensor, regs_96,
182 ARRAY_SIZE(regs_96));
183 default:
184 dev_warn(&client->dev, "no MSRs for %d Hz ext_clk\n",
185 sensor->hwcfg->ext_clk);
186 return 0;
187 }
188}
189
190static int jt8ev1_pre_streamon(struct smiapp_sensor *sensor)
191{
192 return smiapp_write_8(sensor, 0x3328, 0x00);
193}
194
195static int jt8ev1_post_streamoff(struct smiapp_sensor *sensor)
196{
197 int rval;
198
199
200 rval = smiapp_write_8(sensor, 0x3205, 0x04);
201 if (rval < 0)
202 return rval;
203
204
205 usleep_range(2000, 2000);
206
207
208 rval = smiapp_write_8(sensor, 0x3205, 0x00);
209 if (rval < 0)
210 return rval;
211
212 return smiapp_write_8(sensor, 0x3328, 0x80);
213}
214
215static int jt8ev1_init(struct smiapp_sensor *sensor)
216{
217 sensor->pll.flags |= SMIAPP_PLL_FLAG_OP_PIX_CLOCK_PER_LANE;
218
219 return 0;
220}
221
222const struct smiapp_quirk smiapp_jt8ev1_quirk = {
223 .limits = jt8ev1_limits,
224 .post_poweron = jt8ev1_post_poweron,
225 .pre_streamon = jt8ev1_pre_streamon,
226 .post_streamoff = jt8ev1_post_streamoff,
227 .init = jt8ev1_init,
228};
229
230static int tcm8500md_limits(struct smiapp_sensor *sensor)
231{
232 smiapp_replace_limit(sensor, SMIAPP_LIMIT_MIN_PLL_IP_FREQ_HZ, 2700000);
233
234 return 0;
235}
236
237const struct smiapp_quirk smiapp_tcm8500md_quirk = {
238 .limits = tcm8500md_limits,
239};
240