This source file includes following definitions.
- h3a_af_setup_regs
- h3a_af_enable
- h3a_af_busy
- h3a_af_get_buf_size
- h3a_af_validate_params
- h3a_af_set_params
- h3a_af_ioctl
- omap3isp_h3a_af_init
- omap3isp_h3a_af_cleanup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #include <linux/device.h>
17 #include <linux/slab.h>
18
19 #include "isp.h"
20 #include "isph3a.h"
21 #include "ispstat.h"
22
23 #define IS_OUT_OF_BOUNDS(value, min, max) \
24 (((value) < (min)) || ((value) > (max)))
25
26 static void h3a_af_setup_regs(struct ispstat *af, void *priv)
27 {
28 struct omap3isp_h3a_af_config *conf = priv;
29 u32 pcr;
30 u32 pax1;
31 u32 pax2;
32 u32 paxstart;
33 u32 coef;
34 u32 base_coef_set0;
35 u32 base_coef_set1;
36 int index;
37
38 if (af->state == ISPSTAT_DISABLED)
39 return;
40
41 isp_reg_writel(af->isp, af->active_buf->dma_addr, OMAP3_ISP_IOMEM_H3A,
42 ISPH3A_AFBUFST);
43
44 if (!af->update)
45 return;
46
47
48 pax1 = ((conf->paxel.width >> 1) - 1) << AF_PAXW_SHIFT;
49
50 pax1 |= (conf->paxel.height >> 1) - 1;
51 isp_reg_writel(af->isp, pax1, OMAP3_ISP_IOMEM_H3A, ISPH3A_AFPAX1);
52
53
54
55 pax2 = ((conf->paxel.line_inc >> 1) - 1) << AF_LINE_INCR_SHIFT;
56
57 pax2 |= (conf->paxel.v_cnt - 1) << AF_VT_COUNT_SHIFT;
58
59 pax2 |= (conf->paxel.h_cnt - 1);
60 isp_reg_writel(af->isp, pax2, OMAP3_ISP_IOMEM_H3A, ISPH3A_AFPAX2);
61
62
63
64 paxstart = conf->paxel.h_start << AF_HZ_START_SHIFT;
65
66 paxstart |= conf->paxel.v_start;
67 isp_reg_writel(af->isp, paxstart, OMAP3_ISP_IOMEM_H3A,
68 ISPH3A_AFPAXSTART);
69
70
71 isp_reg_writel(af->isp, conf->iir.h_start,
72 OMAP3_ISP_IOMEM_H3A, ISPH3A_AFIIRSH);
73
74 base_coef_set0 = ISPH3A_AFCOEF010;
75 base_coef_set1 = ISPH3A_AFCOEF110;
76 for (index = 0; index <= 8; index += 2) {
77
78 coef = 0;
79 coef |= conf->iir.coeff_set0[index];
80 coef |= conf->iir.coeff_set0[index + 1] <<
81 AF_COEF_SHIFT;
82 isp_reg_writel(af->isp, coef, OMAP3_ISP_IOMEM_H3A,
83 base_coef_set0);
84 base_coef_set0 += AFCOEF_OFFSET;
85
86
87 coef = 0;
88 coef |= conf->iir.coeff_set1[index];
89 coef |= conf->iir.coeff_set1[index + 1] <<
90 AF_COEF_SHIFT;
91 isp_reg_writel(af->isp, coef, OMAP3_ISP_IOMEM_H3A,
92 base_coef_set1);
93 base_coef_set1 += AFCOEF_OFFSET;
94 }
95
96 isp_reg_writel(af->isp, conf->iir.coeff_set0[10],
97 OMAP3_ISP_IOMEM_H3A, ISPH3A_AFCOEF0010);
98
99 isp_reg_writel(af->isp, conf->iir.coeff_set1[10],
100 OMAP3_ISP_IOMEM_H3A, ISPH3A_AFCOEF1010);
101
102
103
104 pcr = conf->rgb_pos << AF_RGBPOS_SHIFT;
105
106 if (conf->fvmode == OMAP3ISP_AF_MODE_PEAK)
107 pcr |= AF_FVMODE;
108
109 if (conf->alaw_enable)
110 pcr |= AF_ALAW_EN;
111
112 if (conf->hmf.enable) {
113
114 pcr |= AF_MED_EN;
115
116 pcr |= conf->hmf.threshold << AF_MED_TH_SHIFT;
117 }
118
119 isp_reg_clr_set(af->isp, OMAP3_ISP_IOMEM_H3A, ISPH3A_PCR,
120 AF_PCR_MASK, pcr);
121
122 af->update = 0;
123 af->config_counter += af->inc_config;
124 af->inc_config = 0;
125 af->buf_size = conf->buf_size;
126 }
127
128 static void h3a_af_enable(struct ispstat *af, int enable)
129 {
130 if (enable) {
131 isp_reg_set(af->isp, OMAP3_ISP_IOMEM_H3A, ISPH3A_PCR,
132 ISPH3A_PCR_AF_EN);
133 omap3isp_subclk_enable(af->isp, OMAP3_ISP_SUBCLK_AF);
134 } else {
135 isp_reg_clr(af->isp, OMAP3_ISP_IOMEM_H3A, ISPH3A_PCR,
136 ISPH3A_PCR_AF_EN);
137 omap3isp_subclk_disable(af->isp, OMAP3_ISP_SUBCLK_AF);
138 }
139 }
140
141 static int h3a_af_busy(struct ispstat *af)
142 {
143 return isp_reg_readl(af->isp, OMAP3_ISP_IOMEM_H3A, ISPH3A_PCR)
144 & ISPH3A_PCR_BUSYAF;
145 }
146
147 static u32 h3a_af_get_buf_size(struct omap3isp_h3a_af_config *conf)
148 {
149 return conf->paxel.h_cnt * conf->paxel.v_cnt * OMAP3ISP_AF_PAXEL_SIZE;
150 }
151
152
153 static int h3a_af_validate_params(struct ispstat *af, void *new_conf)
154 {
155 struct omap3isp_h3a_af_config *user_cfg = new_conf;
156 struct omap3isp_h3a_af_paxel *paxel_cfg = &user_cfg->paxel;
157 struct omap3isp_h3a_af_iir *iir_cfg = &user_cfg->iir;
158 int index;
159 u32 buf_size;
160
161
162 if (IS_OUT_OF_BOUNDS(paxel_cfg->h_cnt,
163 OMAP3ISP_AF_PAXEL_HORIZONTAL_COUNT_MIN,
164 OMAP3ISP_AF_PAXEL_HORIZONTAL_COUNT_MAX))
165 return -EINVAL;
166
167
168 if (IS_OUT_OF_BOUNDS(paxel_cfg->v_cnt,
169 OMAP3ISP_AF_PAXEL_VERTICAL_COUNT_MIN,
170 OMAP3ISP_AF_PAXEL_VERTICAL_COUNT_MAX))
171 return -EINVAL;
172
173 if (IS_OUT_OF_BOUNDS(paxel_cfg->height, OMAP3ISP_AF_PAXEL_HEIGHT_MIN,
174 OMAP3ISP_AF_PAXEL_HEIGHT_MAX) ||
175 paxel_cfg->height % 2)
176 return -EINVAL;
177
178
179 if (IS_OUT_OF_BOUNDS(paxel_cfg->width, OMAP3ISP_AF_PAXEL_WIDTH_MIN,
180 OMAP3ISP_AF_PAXEL_WIDTH_MAX) ||
181 paxel_cfg->width % 2)
182 return -EINVAL;
183
184
185 if (IS_OUT_OF_BOUNDS(paxel_cfg->line_inc,
186 OMAP3ISP_AF_PAXEL_INCREMENT_MIN,
187 OMAP3ISP_AF_PAXEL_INCREMENT_MAX) ||
188 paxel_cfg->line_inc % 2)
189 return -EINVAL;
190
191
192 if ((paxel_cfg->h_start < iir_cfg->h_start) ||
193 IS_OUT_OF_BOUNDS(paxel_cfg->h_start,
194 OMAP3ISP_AF_PAXEL_HZSTART_MIN,
195 OMAP3ISP_AF_PAXEL_HZSTART_MAX))
196 return -EINVAL;
197
198
199 for (index = 0; index < OMAP3ISP_AF_NUM_COEF; index++) {
200 if ((iir_cfg->coeff_set0[index]) > OMAP3ISP_AF_COEF_MAX)
201 return -EINVAL;
202
203 if ((iir_cfg->coeff_set1[index]) > OMAP3ISP_AF_COEF_MAX)
204 return -EINVAL;
205 }
206
207 if (IS_OUT_OF_BOUNDS(iir_cfg->h_start, OMAP3ISP_AF_IIRSH_MIN,
208 OMAP3ISP_AF_IIRSH_MAX))
209 return -EINVAL;
210
211
212 if ((paxel_cfg->h_cnt * paxel_cfg->v_cnt > 9) &&
213 (paxel_cfg->width * paxel_cfg->height == 12))
214 return -EINVAL;
215
216 buf_size = h3a_af_get_buf_size(user_cfg);
217 if (buf_size > user_cfg->buf_size)
218
219 user_cfg->buf_size = buf_size;
220 else if (user_cfg->buf_size > OMAP3ISP_AF_MAX_BUF_SIZE)
221 user_cfg->buf_size = OMAP3ISP_AF_MAX_BUF_SIZE;
222
223 return 0;
224 }
225
226
227 static void h3a_af_set_params(struct ispstat *af, void *new_conf)
228 {
229 struct omap3isp_h3a_af_config *user_cfg = new_conf;
230 struct omap3isp_h3a_af_config *cur_cfg = af->priv;
231 int update = 0;
232 int index;
233
234
235 if (cur_cfg->alaw_enable != user_cfg->alaw_enable) {
236 update = 1;
237 goto out;
238 }
239
240
241 if (cur_cfg->hmf.enable != user_cfg->hmf.enable) {
242 update = 1;
243 goto out;
244 }
245 if (cur_cfg->hmf.threshold != user_cfg->hmf.threshold) {
246 update = 1;
247 goto out;
248 }
249
250
251 if (cur_cfg->rgb_pos != user_cfg->rgb_pos) {
252 update = 1;
253 goto out;
254 }
255
256
257 if (cur_cfg->iir.h_start != user_cfg->iir.h_start) {
258 update = 1;
259 goto out;
260 }
261 for (index = 0; index < OMAP3ISP_AF_NUM_COEF; index++) {
262 if (cur_cfg->iir.coeff_set0[index] !=
263 user_cfg->iir.coeff_set0[index]) {
264 update = 1;
265 goto out;
266 }
267 if (cur_cfg->iir.coeff_set1[index] !=
268 user_cfg->iir.coeff_set1[index]) {
269 update = 1;
270 goto out;
271 }
272 }
273
274
275 if ((cur_cfg->paxel.width != user_cfg->paxel.width) ||
276 (cur_cfg->paxel.height != user_cfg->paxel.height) ||
277 (cur_cfg->paxel.h_start != user_cfg->paxel.h_start) ||
278 (cur_cfg->paxel.v_start != user_cfg->paxel.v_start) ||
279 (cur_cfg->paxel.h_cnt != user_cfg->paxel.h_cnt) ||
280 (cur_cfg->paxel.v_cnt != user_cfg->paxel.v_cnt) ||
281 (cur_cfg->paxel.line_inc != user_cfg->paxel.line_inc)) {
282 update = 1;
283 goto out;
284 }
285
286
287 if (cur_cfg->fvmode != user_cfg->fvmode)
288 update = 1;
289
290 out:
291 if (update || !af->configured) {
292 memcpy(cur_cfg, user_cfg, sizeof(*cur_cfg));
293 af->inc_config++;
294 af->update = 1;
295
296
297
298
299
300
301 cur_cfg->buf_size = h3a_af_get_buf_size(cur_cfg);
302 }
303 }
304
305 static long h3a_af_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
306 {
307 struct ispstat *stat = v4l2_get_subdevdata(sd);
308
309 switch (cmd) {
310 case VIDIOC_OMAP3ISP_AF_CFG:
311 return omap3isp_stat_config(stat, arg);
312 case VIDIOC_OMAP3ISP_STAT_REQ:
313 return omap3isp_stat_request_statistics(stat, arg);
314 case VIDIOC_OMAP3ISP_STAT_REQ_TIME32:
315 return omap3isp_stat_request_statistics_time32(stat, arg);
316 case VIDIOC_OMAP3ISP_STAT_EN: {
317 int *en = arg;
318 return omap3isp_stat_enable(stat, !!*en);
319 }
320 }
321
322 return -ENOIOCTLCMD;
323
324 }
325
326 static const struct ispstat_ops h3a_af_ops = {
327 .validate_params = h3a_af_validate_params,
328 .set_params = h3a_af_set_params,
329 .setup_regs = h3a_af_setup_regs,
330 .enable = h3a_af_enable,
331 .busy = h3a_af_busy,
332 };
333
334 static const struct v4l2_subdev_core_ops h3a_af_subdev_core_ops = {
335 .ioctl = h3a_af_ioctl,
336 .subscribe_event = omap3isp_stat_subscribe_event,
337 .unsubscribe_event = omap3isp_stat_unsubscribe_event,
338 };
339
340 static const struct v4l2_subdev_video_ops h3a_af_subdev_video_ops = {
341 .s_stream = omap3isp_stat_s_stream,
342 };
343
344 static const struct v4l2_subdev_ops h3a_af_subdev_ops = {
345 .core = &h3a_af_subdev_core_ops,
346 .video = &h3a_af_subdev_video_ops,
347 };
348
349
350 int omap3isp_h3a_af_init(struct isp_device *isp)
351 {
352 struct ispstat *af = &isp->isp_af;
353 struct omap3isp_h3a_af_config *af_cfg;
354 struct omap3isp_h3a_af_config *af_recover_cfg = NULL;
355 int ret;
356
357 af_cfg = kzalloc(sizeof(*af_cfg), GFP_KERNEL);
358 if (af_cfg == NULL)
359 return -ENOMEM;
360
361 af->ops = &h3a_af_ops;
362 af->priv = af_cfg;
363 af->event_type = V4L2_EVENT_OMAP3ISP_AF;
364 af->isp = isp;
365
366
367 af_recover_cfg = kzalloc(sizeof(*af_recover_cfg), GFP_KERNEL);
368 if (!af_recover_cfg) {
369 dev_err(af->isp->dev,
370 "AF: cannot allocate memory for recover configuration.\n");
371 ret = -ENOMEM;
372 goto err;
373 }
374
375 af_recover_cfg->paxel.h_start = OMAP3ISP_AF_PAXEL_HZSTART_MIN;
376 af_recover_cfg->paxel.width = OMAP3ISP_AF_PAXEL_WIDTH_MIN;
377 af_recover_cfg->paxel.height = OMAP3ISP_AF_PAXEL_HEIGHT_MIN;
378 af_recover_cfg->paxel.h_cnt = OMAP3ISP_AF_PAXEL_HORIZONTAL_COUNT_MIN;
379 af_recover_cfg->paxel.v_cnt = OMAP3ISP_AF_PAXEL_VERTICAL_COUNT_MIN;
380 af_recover_cfg->paxel.line_inc = OMAP3ISP_AF_PAXEL_INCREMENT_MIN;
381 if (h3a_af_validate_params(af, af_recover_cfg)) {
382 dev_err(af->isp->dev,
383 "AF: recover configuration is invalid.\n");
384 ret = -EINVAL;
385 goto err;
386 }
387
388 af_recover_cfg->buf_size = h3a_af_get_buf_size(af_recover_cfg);
389 af->recover_priv = af_recover_cfg;
390
391 ret = omap3isp_stat_init(af, "AF", &h3a_af_subdev_ops);
392
393 err:
394 if (ret) {
395 kfree(af_cfg);
396 kfree(af_recover_cfg);
397 }
398
399 return ret;
400 }
401
402 void omap3isp_h3a_af_cleanup(struct isp_device *isp)
403 {
404 omap3isp_stat_cleanup(&isp->isp_af);
405 }