[media] smiapp: Round minimum pre_pll up rather than down in ip_clk_freq check
[deliverable/linux.git] / drivers / media / video / smiapp / smiapp-core.c
CommitLineData
ccfc97bd
SA
1/*
2 * drivers/media/video/smiapp/smiapp-core.c
3 *
4 * Generic driver for SMIA/SMIA++ compliant camera modules
5 *
6 * Copyright (C) 2010--2012 Nokia Corporation
7 * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
8 *
9 * Based on smiapp driver by Vimarsh Zutshi
10 * Based on jt8ev1.c by Vimarsh Zutshi
11 * Based on smia-sensor.c by Tuukka Toivonen <tuukkat76@gmail.com>
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * version 2 as published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 * 02110-1301 USA
26 *
27 */
28
2547428d 29#include <linux/clk.h>
ccfc97bd
SA
30#include <linux/delay.h>
31#include <linux/device.h>
32#include <linux/gpio.h>
33#include <linux/module.h>
34#include <linux/regulator/consumer.h>
35#include <linux/v4l2-mediabus.h>
36#include <media/v4l2-device.h>
37
38#include "smiapp.h"
39
40#define SMIAPP_ALIGN_DIM(dim, flags) \
41 ((flags) & V4L2_SUBDEV_SEL_FLAG_SIZE_GE \
42 ? ALIGN((dim), 2) \
43 : (dim) & ~1)
44
45/*
46 * smiapp_module_idents - supported camera modules
47 */
48static const struct smiapp_module_ident smiapp_module_idents[] = {
49 SMIAPP_IDENT_L(0x01, 0x022b, -1, "vs6555"),
50 SMIAPP_IDENT_L(0x01, 0x022e, -1, "vw6558"),
51 SMIAPP_IDENT_L(0x07, 0x7698, -1, "ovm7698"),
52 SMIAPP_IDENT_L(0x0b, 0x4242, -1, "smiapp-003"),
53 SMIAPP_IDENT_L(0x0c, 0x208a, -1, "tcm8330md"),
54 SMIAPP_IDENT_LQ(0x0c, 0x2134, -1, "tcm8500md", &smiapp_tcm8500md_quirk),
55 SMIAPP_IDENT_L(0x0c, 0x213e, -1, "et8en2"),
56 SMIAPP_IDENT_L(0x0c, 0x2184, -1, "tcm8580md"),
57 SMIAPP_IDENT_LQ(0x0c, 0x560f, -1, "jt8ew9", &smiapp_jt8ew9_quirk),
58 SMIAPP_IDENT_LQ(0x10, 0x4141, -1, "jt8ev1", &smiapp_jt8ev1_quirk),
59 SMIAPP_IDENT_LQ(0x10, 0x4241, -1, "imx125es", &smiapp_imx125es_quirk),
60};
61
62/*
63 *
64 * Dynamic Capability Identification
65 *
66 */
67
68static int smiapp_read_frame_fmt(struct smiapp_sensor *sensor)
69{
70 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
71 u32 fmt_model_type, fmt_model_subtype, ncol_desc, nrow_desc;
72 unsigned int i;
73 int rval;
74 int line_count = 0;
75 int embedded_start = -1, embedded_end = -1;
76 int image_start = 0;
77
1e73eea7 78 rval = smiapp_read(sensor, SMIAPP_REG_U8_FRAME_FORMAT_MODEL_TYPE,
ccfc97bd
SA
79 &fmt_model_type);
80 if (rval)
81 return rval;
82
1e73eea7 83 rval = smiapp_read(sensor, SMIAPP_REG_U8_FRAME_FORMAT_MODEL_SUBTYPE,
ccfc97bd
SA
84 &fmt_model_subtype);
85 if (rval)
86 return rval;
87
88 ncol_desc = (fmt_model_subtype
89 & SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_MASK)
90 >> SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_SHIFT;
91 nrow_desc = fmt_model_subtype
92 & SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NROWS_MASK;
93
94 dev_dbg(&client->dev, "format_model_type %s\n",
95 fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE
96 ? "2 byte" :
97 fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE
98 ? "4 byte" : "is simply bad");
99
100 for (i = 0; i < ncol_desc + nrow_desc; i++) {
101 u32 desc;
102 u32 pixelcode;
103 u32 pixels;
104 char *which;
105 char *what;
106
107 if (fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE) {
108 rval = smiapp_read(
1e73eea7 109 sensor,
ccfc97bd
SA
110 SMIAPP_REG_U16_FRAME_FORMAT_DESCRIPTOR_2(i),
111 &desc);
112 if (rval)
113 return rval;
114
115 pixelcode =
116 (desc
117 & SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_MASK)
118 >> SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_SHIFT;
119 pixels = desc & SMIAPP_FRAME_FORMAT_DESC_2_PIXELS_MASK;
120 } else if (fmt_model_type
121 == SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE) {
122 rval = smiapp_read(
1e73eea7 123 sensor,
ccfc97bd
SA
124 SMIAPP_REG_U32_FRAME_FORMAT_DESCRIPTOR_4(i),
125 &desc);
126 if (rval)
127 return rval;
128
129 pixelcode =
130 (desc
131 & SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_MASK)
132 >> SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_SHIFT;
133 pixels = desc & SMIAPP_FRAME_FORMAT_DESC_4_PIXELS_MASK;
134 } else {
135 dev_dbg(&client->dev,
136 "invalid frame format model type %d\n",
137 fmt_model_type);
138 return -EINVAL;
139 }
140
141 if (i < ncol_desc)
142 which = "columns";
143 else
144 which = "rows";
145
146 switch (pixelcode) {
147 case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED:
148 what = "embedded";
149 break;
150 case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DUMMY:
151 what = "dummy";
152 break;
153 case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_BLACK:
154 what = "black";
155 break;
156 case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DARK:
157 what = "dark";
158 break;
159 case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE:
160 what = "visible";
161 break;
162 default:
163 what = "invalid";
164 dev_dbg(&client->dev, "pixelcode %d\n", pixelcode);
165 break;
166 }
167
168 dev_dbg(&client->dev, "%s pixels: %d %s\n",
169 what, pixels, which);
170
171 if (i < ncol_desc)
172 continue;
173
174 /* Handle row descriptors */
175 if (pixelcode
176 == SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED) {
177 embedded_start = line_count;
178 } else {
179 if (pixelcode == SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE
180 || pixels >= sensor->limits[SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES] / 2)
181 image_start = line_count;
182 if (embedded_start != -1 && embedded_end == -1)
183 embedded_end = line_count;
184 }
185 line_count += pixels;
186 }
187
188 if (embedded_start == -1 || embedded_end == -1) {
189 embedded_start = 0;
190 embedded_end = 0;
191 }
192
193 dev_dbg(&client->dev, "embedded data from lines %d to %d\n",
194 embedded_start, embedded_end);
195 dev_dbg(&client->dev, "image data starts at line %d\n", image_start);
196
197 return 0;
198}
199
200static int smiapp_pll_configure(struct smiapp_sensor *sensor)
201{
ccfc97bd
SA
202 struct smiapp_pll *pll = &sensor->pll;
203 int rval;
204
205 rval = smiapp_write(
1e73eea7 206 sensor, SMIAPP_REG_U16_VT_PIX_CLK_DIV, pll->vt_pix_clk_div);
ccfc97bd
SA
207 if (rval < 0)
208 return rval;
209
210 rval = smiapp_write(
1e73eea7 211 sensor, SMIAPP_REG_U16_VT_SYS_CLK_DIV, pll->vt_sys_clk_div);
ccfc97bd
SA
212 if (rval < 0)
213 return rval;
214
215 rval = smiapp_write(
1e73eea7 216 sensor, SMIAPP_REG_U16_PRE_PLL_CLK_DIV, pll->pre_pll_clk_div);
ccfc97bd
SA
217 if (rval < 0)
218 return rval;
219
220 rval = smiapp_write(
1e73eea7 221 sensor, SMIAPP_REG_U16_PLL_MULTIPLIER, pll->pll_multiplier);
ccfc97bd
SA
222 if (rval < 0)
223 return rval;
224
225 /* Lane op clock ratio does not apply here. */
226 rval = smiapp_write(
1e73eea7 227 sensor, SMIAPP_REG_U32_REQUESTED_LINK_BIT_RATE_MBPS,
ccfc97bd
SA
228 DIV_ROUND_UP(pll->op_sys_clk_freq_hz, 1000000 / 256 / 256));
229 if (rval < 0 || sensor->minfo.smiapp_profile == SMIAPP_PROFILE_0)
230 return rval;
231
232 rval = smiapp_write(
1e73eea7 233 sensor, SMIAPP_REG_U16_OP_PIX_CLK_DIV, pll->op_pix_clk_div);
ccfc97bd
SA
234 if (rval < 0)
235 return rval;
236
237 return smiapp_write(
1e73eea7 238 sensor, SMIAPP_REG_U16_OP_SYS_CLK_DIV, pll->op_sys_clk_div);
ccfc97bd
SA
239}
240
241static int smiapp_pll_update(struct smiapp_sensor *sensor)
242{
243 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
244 struct smiapp_pll_limits lim = {
245 .min_pre_pll_clk_div = sensor->limits[SMIAPP_LIMIT_MIN_PRE_PLL_CLK_DIV],
246 .max_pre_pll_clk_div = sensor->limits[SMIAPP_LIMIT_MAX_PRE_PLL_CLK_DIV],
247 .min_pll_ip_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_PLL_IP_FREQ_HZ],
248 .max_pll_ip_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_PLL_IP_FREQ_HZ],
249 .min_pll_multiplier = sensor->limits[SMIAPP_LIMIT_MIN_PLL_MULTIPLIER],
250 .max_pll_multiplier = sensor->limits[SMIAPP_LIMIT_MAX_PLL_MULTIPLIER],
251 .min_pll_op_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_PLL_OP_FREQ_HZ],
252 .max_pll_op_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_PLL_OP_FREQ_HZ],
253
254 .min_op_sys_clk_div = sensor->limits[SMIAPP_LIMIT_MIN_OP_SYS_CLK_DIV],
255 .max_op_sys_clk_div = sensor->limits[SMIAPP_LIMIT_MAX_OP_SYS_CLK_DIV],
256 .min_op_pix_clk_div = sensor->limits[SMIAPP_LIMIT_MIN_OP_PIX_CLK_DIV],
257 .max_op_pix_clk_div = sensor->limits[SMIAPP_LIMIT_MAX_OP_PIX_CLK_DIV],
258 .min_op_sys_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_OP_SYS_CLK_FREQ_HZ],
259 .max_op_sys_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_OP_SYS_CLK_FREQ_HZ],
260 .min_op_pix_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_OP_PIX_CLK_FREQ_HZ],
261 .max_op_pix_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_OP_PIX_CLK_FREQ_HZ],
262
263 .min_vt_sys_clk_div = sensor->limits[SMIAPP_LIMIT_MIN_VT_SYS_CLK_DIV],
264 .max_vt_sys_clk_div = sensor->limits[SMIAPP_LIMIT_MAX_VT_SYS_CLK_DIV],
265 .min_vt_pix_clk_div = sensor->limits[SMIAPP_LIMIT_MIN_VT_PIX_CLK_DIV],
266 .max_vt_pix_clk_div = sensor->limits[SMIAPP_LIMIT_MAX_VT_PIX_CLK_DIV],
267 .min_vt_sys_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_VT_SYS_CLK_FREQ_HZ],
268 .max_vt_sys_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_VT_SYS_CLK_FREQ_HZ],
269 .min_vt_pix_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_VT_PIX_CLK_FREQ_HZ],
270 .max_vt_pix_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_VT_PIX_CLK_FREQ_HZ],
271
272 .min_line_length_pck_bin = sensor->limits[SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN],
273 .min_line_length_pck = sensor->limits[SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK],
274 };
275 struct smiapp_pll *pll = &sensor->pll;
276 int rval;
277
278 memset(&sensor->pll, 0, sizeof(sensor->pll));
279
280 pll->lanes = sensor->platform_data->lanes;
281 pll->ext_clk_freq_hz = sensor->platform_data->ext_clk;
282
283 if (sensor->minfo.smiapp_profile == SMIAPP_PROFILE_0) {
284 /*
285 * Fill in operational clock divisors limits from the
286 * video timing ones. On profile 0 sensors the
287 * requirements regarding them are essentially the
288 * same as on VT ones.
289 */
290 lim.min_op_sys_clk_div = lim.min_vt_sys_clk_div;
291 lim.max_op_sys_clk_div = lim.max_vt_sys_clk_div;
292 lim.min_op_pix_clk_div = lim.min_vt_pix_clk_div;
293 lim.max_op_pix_clk_div = lim.max_vt_pix_clk_div;
294 lim.min_op_sys_clk_freq_hz = lim.min_vt_sys_clk_freq_hz;
295 lim.max_op_sys_clk_freq_hz = lim.max_vt_sys_clk_freq_hz;
296 lim.min_op_pix_clk_freq_hz = lim.min_vt_pix_clk_freq_hz;
297 lim.max_op_pix_clk_freq_hz = lim.max_vt_pix_clk_freq_hz;
298 /* Profile 0 sensors have no separate OP clock branch. */
299 pll->flags |= SMIAPP_PLL_FLAG_NO_OP_CLOCKS;
300 }
301
302 if (smiapp_needs_quirk(sensor,
303 SMIAPP_QUIRK_FLAG_OP_PIX_CLOCK_PER_LANE))
304 pll->flags |= SMIAPP_PLL_FLAG_OP_PIX_CLOCK_PER_LANE;
305
306 pll->binning_horizontal = sensor->binning_horizontal;
307 pll->binning_vertical = sensor->binning_vertical;
308 pll->link_freq =
309 sensor->link_freq->qmenu_int[sensor->link_freq->val];
310 pll->scale_m = sensor->scale_m;
311 pll->scale_n = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
312 pll->bits_per_pixel = sensor->csi_format->compressed;
313
314 rval = smiapp_pll_calculate(&client->dev, &lim, pll);
315 if (rval < 0)
316 return rval;
317
318 sensor->pixel_rate_parray->cur.val64 = pll->vt_pix_clk_freq_hz;
319 sensor->pixel_rate_csi->cur.val64 = pll->pixel_rate_csi;
320
321 return 0;
322}
323
324
325/*
326 *
327 * V4L2 Controls handling
328 *
329 */
330
331static void __smiapp_update_exposure_limits(struct smiapp_sensor *sensor)
332{
333 struct v4l2_ctrl *ctrl = sensor->exposure;
334 int max;
335
336 max = sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height
337 + sensor->vblank->val
338 - sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MAX_MARGIN];
339
340 ctrl->maximum = max;
341 if (ctrl->default_value > max)
342 ctrl->default_value = max;
343 if (ctrl->val > max)
344 ctrl->val = max;
345 if (ctrl->cur.val > max)
346 ctrl->cur.val = max;
347}
348
349/*
350 * Order matters.
351 *
352 * 1. Bits-per-pixel, descending.
353 * 2. Bits-per-pixel compressed, descending.
354 * 3. Pixel order, same as in pixel_order_str. Formats for all four pixel
355 * orders must be defined.
356 */
357static const struct smiapp_csi_data_format smiapp_csi_data_formats[] = {
358 { V4L2_MBUS_FMT_SGRBG12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_GRBG, },
359 { V4L2_MBUS_FMT_SRGGB12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_RGGB, },
360 { V4L2_MBUS_FMT_SBGGR12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_BGGR, },
361 { V4L2_MBUS_FMT_SGBRG12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_GBRG, },
362 { V4L2_MBUS_FMT_SGRBG10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_GRBG, },
363 { V4L2_MBUS_FMT_SRGGB10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_RGGB, },
364 { V4L2_MBUS_FMT_SBGGR10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_BGGR, },
365 { V4L2_MBUS_FMT_SGBRG10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_GBRG, },
366 { V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_GRBG, },
367 { V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_RGGB, },
368 { V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_BGGR, },
369 { V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_GBRG, },
370};
371
372const char *pixel_order_str[] = { "GRBG", "RGGB", "BGGR", "GBRG" };
373
374#define to_csi_format_idx(fmt) (((unsigned long)(fmt) \
375 - (unsigned long)smiapp_csi_data_formats) \
376 / sizeof(*smiapp_csi_data_formats))
377
378static u32 smiapp_pixel_order(struct smiapp_sensor *sensor)
379{
380 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
381 int flip = 0;
382
383 if (sensor->hflip) {
384 if (sensor->hflip->val)
385 flip |= SMIAPP_IMAGE_ORIENTATION_HFLIP;
386
387 if (sensor->vflip->val)
388 flip |= SMIAPP_IMAGE_ORIENTATION_VFLIP;
389 }
390
391 flip ^= sensor->hvflip_inv_mask;
392
393 dev_dbg(&client->dev, "flip %d\n", flip);
394 return sensor->default_pixel_order ^ flip;
395}
396
397static void smiapp_update_mbus_formats(struct smiapp_sensor *sensor)
398{
399 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
400 unsigned int csi_format_idx =
401 to_csi_format_idx(sensor->csi_format) & ~3;
402 unsigned int internal_csi_format_idx =
403 to_csi_format_idx(sensor->internal_csi_format) & ~3;
404 unsigned int pixel_order = smiapp_pixel_order(sensor);
405
406 sensor->mbus_frame_fmts =
407 sensor->default_mbus_frame_fmts << pixel_order;
408 sensor->csi_format =
409 &smiapp_csi_data_formats[csi_format_idx + pixel_order];
410 sensor->internal_csi_format =
411 &smiapp_csi_data_formats[internal_csi_format_idx
412 + pixel_order];
413
414 BUG_ON(max(internal_csi_format_idx, csi_format_idx) + pixel_order
415 >= ARRAY_SIZE(smiapp_csi_data_formats));
416 BUG_ON(min(internal_csi_format_idx, csi_format_idx) < 0);
417
418 dev_dbg(&client->dev, "new pixel order %s\n",
419 pixel_order_str[pixel_order]);
420}
421
422static int smiapp_set_ctrl(struct v4l2_ctrl *ctrl)
423{
424 struct smiapp_sensor *sensor =
425 container_of(ctrl->handler, struct smiapp_subdev, ctrl_handler)
426 ->sensor;
ccfc97bd
SA
427 u32 orient = 0;
428 int exposure;
429 int rval;
430
431 switch (ctrl->id) {
432 case V4L2_CID_ANALOGUE_GAIN:
433 return smiapp_write(
1e73eea7 434 sensor,
ccfc97bd
SA
435 SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_GLOBAL, ctrl->val);
436
437 case V4L2_CID_EXPOSURE:
438 return smiapp_write(
1e73eea7 439 sensor,
ccfc97bd
SA
440 SMIAPP_REG_U16_COARSE_INTEGRATION_TIME, ctrl->val);
441
442 case V4L2_CID_HFLIP:
443 case V4L2_CID_VFLIP:
444 if (sensor->streaming)
445 return -EBUSY;
446
447 if (sensor->hflip->val)
448 orient |= SMIAPP_IMAGE_ORIENTATION_HFLIP;
449
450 if (sensor->vflip->val)
451 orient |= SMIAPP_IMAGE_ORIENTATION_VFLIP;
452
453 orient ^= sensor->hvflip_inv_mask;
1e73eea7 454 rval = smiapp_write(sensor,
ccfc97bd
SA
455 SMIAPP_REG_U8_IMAGE_ORIENTATION,
456 orient);
457 if (rval < 0)
458 return rval;
459
460 smiapp_update_mbus_formats(sensor);
461
462 return 0;
463
464 case V4L2_CID_VBLANK:
465 exposure = sensor->exposure->val;
466
467 __smiapp_update_exposure_limits(sensor);
468
469 if (exposure > sensor->exposure->maximum) {
470 sensor->exposure->val =
471 sensor->exposure->maximum;
472 rval = smiapp_set_ctrl(
473 sensor->exposure);
474 if (rval < 0)
475 return rval;
476 }
477
478 return smiapp_write(
1e73eea7 479 sensor, SMIAPP_REG_U16_FRAME_LENGTH_LINES,
ccfc97bd
SA
480 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height
481 + ctrl->val);
482
483 case V4L2_CID_HBLANK:
484 return smiapp_write(
1e73eea7 485 sensor, SMIAPP_REG_U16_LINE_LENGTH_PCK,
ccfc97bd
SA
486 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].width
487 + ctrl->val);
488
489 case V4L2_CID_LINK_FREQ:
490 if (sensor->streaming)
491 return -EBUSY;
492
493 return smiapp_pll_update(sensor);
494
495 default:
496 return -EINVAL;
497 }
498}
499
500static const struct v4l2_ctrl_ops smiapp_ctrl_ops = {
501 .s_ctrl = smiapp_set_ctrl,
502};
503
504static int smiapp_init_controls(struct smiapp_sensor *sensor)
505{
506 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
507 struct v4l2_ctrl_config cfg;
508 int rval;
509
510 rval = v4l2_ctrl_handler_init(&sensor->pixel_array->ctrl_handler, 7);
511 if (rval)
512 return rval;
513 sensor->pixel_array->ctrl_handler.lock = &sensor->mutex;
514
515 sensor->analog_gain = v4l2_ctrl_new_std(
516 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
517 V4L2_CID_ANALOGUE_GAIN,
518 sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN],
519 sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MAX],
520 max(sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_STEP], 1U),
521 sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN]);
522
523 /* Exposure limits will be updated soon, use just something here. */
524 sensor->exposure = v4l2_ctrl_new_std(
525 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
526 V4L2_CID_EXPOSURE, 0, 0, 1, 0);
527
528 sensor->hflip = v4l2_ctrl_new_std(
529 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
530 V4L2_CID_HFLIP, 0, 1, 1, 0);
531 sensor->vflip = v4l2_ctrl_new_std(
532 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
533 V4L2_CID_VFLIP, 0, 1, 1, 0);
534
535 sensor->vblank = v4l2_ctrl_new_std(
536 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
537 V4L2_CID_VBLANK, 0, 1, 1, 0);
538
539 if (sensor->vblank)
540 sensor->vblank->flags |= V4L2_CTRL_FLAG_UPDATE;
541
542 sensor->hblank = v4l2_ctrl_new_std(
543 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
544 V4L2_CID_HBLANK, 0, 1, 1, 0);
545
546 if (sensor->hblank)
547 sensor->hblank->flags |= V4L2_CTRL_FLAG_UPDATE;
548
549 sensor->pixel_rate_parray = v4l2_ctrl_new_std(
550 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
551 V4L2_CID_PIXEL_RATE, 0, 0, 1, 0);
552
553 if (sensor->pixel_array->ctrl_handler.error) {
554 dev_err(&client->dev,
555 "pixel array controls initialization failed (%d)\n",
556 sensor->pixel_array->ctrl_handler.error);
557 rval = sensor->pixel_array->ctrl_handler.error;
558 goto error;
559 }
560
561 sensor->pixel_array->sd.ctrl_handler =
562 &sensor->pixel_array->ctrl_handler;
563
564 v4l2_ctrl_cluster(2, &sensor->hflip);
565
566 rval = v4l2_ctrl_handler_init(&sensor->src->ctrl_handler, 0);
567 if (rval)
568 goto error;
569 sensor->src->ctrl_handler.lock = &sensor->mutex;
570
571 memset(&cfg, 0, sizeof(cfg));
572
573 cfg.ops = &smiapp_ctrl_ops;
574 cfg.id = V4L2_CID_LINK_FREQ;
575 cfg.type = V4L2_CTRL_TYPE_INTEGER_MENU;
576 while (sensor->platform_data->op_sys_clock[cfg.max + 1])
577 cfg.max++;
578 cfg.qmenu_int = sensor->platform_data->op_sys_clock;
579
580 sensor->link_freq = v4l2_ctrl_new_custom(
581 &sensor->src->ctrl_handler, &cfg, NULL);
582
583 sensor->pixel_rate_csi = v4l2_ctrl_new_std(
584 &sensor->src->ctrl_handler, &smiapp_ctrl_ops,
585 V4L2_CID_PIXEL_RATE, 0, 0, 1, 0);
586
587 if (sensor->src->ctrl_handler.error) {
588 dev_err(&client->dev,
589 "src controls initialization failed (%d)\n",
590 sensor->src->ctrl_handler.error);
591 rval = sensor->src->ctrl_handler.error;
592 goto error;
593 }
594
595 sensor->src->sd.ctrl_handler =
596 &sensor->src->ctrl_handler;
597
598 return 0;
599
600error:
601 v4l2_ctrl_handler_free(&sensor->pixel_array->ctrl_handler);
602 v4l2_ctrl_handler_free(&sensor->src->ctrl_handler);
603
604 return rval;
605}
606
607static void smiapp_free_controls(struct smiapp_sensor *sensor)
608{
609 unsigned int i;
610
611 for (i = 0; i < sensor->ssds_used; i++)
612 v4l2_ctrl_handler_free(&sensor->ssds[i].ctrl_handler);
613}
614
615static int smiapp_get_limits(struct smiapp_sensor *sensor, int const *limit,
616 unsigned int n)
617{
618 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
619 unsigned int i;
620 u32 val;
621 int rval;
622
623 for (i = 0; i < n; i++) {
624 rval = smiapp_read(
1e73eea7 625 sensor, smiapp_reg_limits[limit[i]].addr, &val);
ccfc97bd
SA
626 if (rval)
627 return rval;
628 sensor->limits[limit[i]] = val;
629 dev_dbg(&client->dev, "0x%8.8x \"%s\" = %d, 0x%x\n",
630 smiapp_reg_limits[limit[i]].addr,
631 smiapp_reg_limits[limit[i]].what, val, val);
632 }
633
634 return 0;
635}
636
637static int smiapp_get_all_limits(struct smiapp_sensor *sensor)
638{
639 unsigned int i;
640 int rval;
641
642 for (i = 0; i < SMIAPP_LIMIT_LAST; i++) {
643 rval = smiapp_get_limits(sensor, &i, 1);
644 if (rval < 0)
645 return rval;
646 }
647
648 if (sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN] == 0)
649 smiapp_replace_limit(sensor, SMIAPP_LIMIT_SCALER_N_MIN, 16);
650
651 return 0;
652}
653
654static int smiapp_get_limits_binning(struct smiapp_sensor *sensor)
655{
656 static u32 const limits[] = {
657 SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN,
658 SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES_BIN,
659 SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN,
660 SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK_BIN,
661 SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN,
662 SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN_BIN,
663 SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN_BIN,
664 };
665 static u32 const limits_replace[] = {
666 SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES,
667 SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES,
668 SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK,
669 SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK,
670 SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK,
671 SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN,
672 SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN,
673 };
674
675 if (sensor->limits[SMIAPP_LIMIT_BINNING_CAPABILITY] ==
676 SMIAPP_BINNING_CAPABILITY_NO) {
677 unsigned int i;
678
679 for (i = 0; i < ARRAY_SIZE(limits); i++)
680 sensor->limits[limits[i]] =
681 sensor->limits[limits_replace[i]];
682
683 return 0;
684 }
685
686 return smiapp_get_limits(sensor, limits, ARRAY_SIZE(limits));
687}
688
689static int smiapp_get_mbus_formats(struct smiapp_sensor *sensor)
690{
691 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
692 unsigned int type, n;
693 unsigned int i, pixel_order;
694 int rval;
695
696 rval = smiapp_read(
1e73eea7 697 sensor, SMIAPP_REG_U8_DATA_FORMAT_MODEL_TYPE, &type);
ccfc97bd
SA
698 if (rval)
699 return rval;
700
701 dev_dbg(&client->dev, "data_format_model_type %d\n", type);
702
1e73eea7 703 rval = smiapp_read(sensor, SMIAPP_REG_U8_PIXEL_ORDER,
ccfc97bd
SA
704 &pixel_order);
705 if (rval)
706 return rval;
707
708 if (pixel_order >= ARRAY_SIZE(pixel_order_str)) {
709 dev_dbg(&client->dev, "bad pixel order %d\n", pixel_order);
710 return -EINVAL;
711 }
712
713 dev_dbg(&client->dev, "pixel order %d (%s)\n", pixel_order,
714 pixel_order_str[pixel_order]);
715
716 switch (type) {
717 case SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL:
718 n = SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL_N;
719 break;
720 case SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED:
721 n = SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED_N;
722 break;
723 default:
724 return -EINVAL;
725 }
726
727 sensor->default_pixel_order = pixel_order;
728 sensor->mbus_frame_fmts = 0;
729
730 for (i = 0; i < n; i++) {
731 unsigned int fmt, j;
732
733 rval = smiapp_read(
1e73eea7 734 sensor,
ccfc97bd
SA
735 SMIAPP_REG_U16_DATA_FORMAT_DESCRIPTOR(i), &fmt);
736 if (rval)
737 return rval;
738
739 dev_dbg(&client->dev, "bpp %d, compressed %d\n",
740 fmt >> 8, (u8)fmt);
741
742 for (j = 0; j < ARRAY_SIZE(smiapp_csi_data_formats); j++) {
743 const struct smiapp_csi_data_format *f =
744 &smiapp_csi_data_formats[j];
745
746 if (f->pixel_order != SMIAPP_PIXEL_ORDER_GRBG)
747 continue;
748
749 if (f->width != fmt >> 8 || f->compressed != (u8)fmt)
750 continue;
751
752 dev_dbg(&client->dev, "jolly good! %d\n", j);
753
754 sensor->default_mbus_frame_fmts |= 1 << j;
755 if (!sensor->csi_format) {
756 sensor->csi_format = f;
757 sensor->internal_csi_format = f;
758 }
759 }
760 }
761
762 if (!sensor->csi_format) {
763 dev_err(&client->dev, "no supported mbus code found\n");
764 return -EINVAL;
765 }
766
767 smiapp_update_mbus_formats(sensor);
768
769 return 0;
770}
771
772static void smiapp_update_blanking(struct smiapp_sensor *sensor)
773{
774 struct v4l2_ctrl *vblank = sensor->vblank;
775 struct v4l2_ctrl *hblank = sensor->hblank;
776
777 vblank->minimum =
778 max_t(int,
779 sensor->limits[SMIAPP_LIMIT_MIN_FRAME_BLANKING_LINES],
780 sensor->limits[SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN] -
781 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height);
782 vblank->maximum =
783 sensor->limits[SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES_BIN] -
784 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height;
785
786 vblank->val = clamp_t(int, vblank->val,
787 vblank->minimum, vblank->maximum);
788 vblank->default_value = vblank->minimum;
789 vblank->val = vblank->val;
790 vblank->cur.val = vblank->val;
791
792 hblank->minimum =
793 max_t(int,
794 sensor->limits[SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN] -
795 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].width,
796 sensor->limits[SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN]);
797 hblank->maximum =
798 sensor->limits[SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK_BIN] -
799 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].width;
800
801 hblank->val = clamp_t(int, hblank->val,
802 hblank->minimum, hblank->maximum);
803 hblank->default_value = hblank->minimum;
804 hblank->val = hblank->val;
805 hblank->cur.val = hblank->val;
806
807 __smiapp_update_exposure_limits(sensor);
808}
809
810static int smiapp_update_mode(struct smiapp_sensor *sensor)
811{
812 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
813 unsigned int binning_mode;
814 int rval;
815
816 dev_dbg(&client->dev, "frame size: %dx%d\n",
817 sensor->src->crop[SMIAPP_PAD_SRC].width,
818 sensor->src->crop[SMIAPP_PAD_SRC].height);
819 dev_dbg(&client->dev, "csi format width: %d\n",
820 sensor->csi_format->width);
821
822 /* Binning has to be set up here; it affects limits */
823 if (sensor->binning_horizontal == 1 &&
824 sensor->binning_vertical == 1) {
825 binning_mode = 0;
826 } else {
827 u8 binning_type =
828 (sensor->binning_horizontal << 4)
829 | sensor->binning_vertical;
830
831 rval = smiapp_write(
1e73eea7 832 sensor, SMIAPP_REG_U8_BINNING_TYPE, binning_type);
ccfc97bd
SA
833 if (rval < 0)
834 return rval;
835
836 binning_mode = 1;
837 }
1e73eea7 838 rval = smiapp_write(sensor, SMIAPP_REG_U8_BINNING_MODE, binning_mode);
ccfc97bd
SA
839 if (rval < 0)
840 return rval;
841
842 /* Get updated limits due to binning */
843 rval = smiapp_get_limits_binning(sensor);
844 if (rval < 0)
845 return rval;
846
847 rval = smiapp_pll_update(sensor);
848 if (rval < 0)
849 return rval;
850
851 /* Output from pixel array, including blanking */
852 smiapp_update_blanking(sensor);
853
854 dev_dbg(&client->dev, "vblank\t\t%d\n", sensor->vblank->val);
855 dev_dbg(&client->dev, "hblank\t\t%d\n", sensor->hblank->val);
856
857 dev_dbg(&client->dev, "real timeperframe\t100/%d\n",
858 sensor->pll.vt_pix_clk_freq_hz /
859 ((sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].width
860 + sensor->hblank->val) *
861 (sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height
862 + sensor->vblank->val) / 100));
863
864 return 0;
865}
866
867/*
868 *
869 * SMIA++ NVM handling
870 *
871 */
872static int smiapp_read_nvm(struct smiapp_sensor *sensor,
873 unsigned char *nvm)
874{
ccfc97bd
SA
875 u32 i, s, p, np, v;
876 int rval, rval2;
877
878 np = sensor->nvm_size / SMIAPP_NVM_PAGE_SIZE;
879 for (p = 0; p < np; p++) {
880 rval = smiapp_write(
1e73eea7 881 sensor,
ccfc97bd
SA
882 SMIAPP_REG_U8_DATA_TRANSFER_IF_1_PAGE_SELECT, p);
883 if (rval)
884 goto out;
885
1e73eea7 886 rval = smiapp_write(sensor,
ccfc97bd
SA
887 SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL,
888 SMIAPP_DATA_TRANSFER_IF_1_CTRL_EN |
889 SMIAPP_DATA_TRANSFER_IF_1_CTRL_RD_EN);
890 if (rval)
891 goto out;
892
893 for (i = 0; i < 1000; i++) {
894 rval = smiapp_read(
1e73eea7 895 sensor,
ccfc97bd
SA
896 SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS, &s);
897
898 if (rval)
899 goto out;
900
901 if (s & SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY)
902 break;
903
904 if (--i == 0) {
905 rval = -ETIMEDOUT;
906 goto out;
907 }
908
909 }
910
911 for (i = 0; i < SMIAPP_NVM_PAGE_SIZE; i++) {
912 rval = smiapp_read(
1e73eea7 913 sensor,
ccfc97bd
SA
914 SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_0 + i,
915 &v);
916 if (rval)
917 goto out;
918
919 *nvm++ = v;
920 }
921 }
922
923out:
1e73eea7 924 rval2 = smiapp_write(sensor, SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL, 0);
ccfc97bd
SA
925 if (rval < 0)
926 return rval;
927 else
928 return rval2;
929}
930
931/*
932 *
933 * SMIA++ CCI address control
934 *
935 */
936static int smiapp_change_cci_addr(struct smiapp_sensor *sensor)
937{
938 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
939 int rval;
940 u32 val;
941
942 client->addr = sensor->platform_data->i2c_addr_dfl;
943
1e73eea7 944 rval = smiapp_write(sensor,
ccfc97bd
SA
945 SMIAPP_REG_U8_CCI_ADDRESS_CONTROL,
946 sensor->platform_data->i2c_addr_alt << 1);
947 if (rval)
948 return rval;
949
950 client->addr = sensor->platform_data->i2c_addr_alt;
951
952 /* verify addr change went ok */
1e73eea7 953 rval = smiapp_read(sensor, SMIAPP_REG_U8_CCI_ADDRESS_CONTROL, &val);
ccfc97bd
SA
954 if (rval)
955 return rval;
956
957 if (val != sensor->platform_data->i2c_addr_alt << 1)
958 return -ENODEV;
959
960 return 0;
961}
962
963/*
964 *
965 * SMIA++ Mode Control
966 *
967 */
968static int smiapp_setup_flash_strobe(struct smiapp_sensor *sensor)
969{
ccfc97bd
SA
970 struct smiapp_flash_strobe_parms *strobe_setup;
971 unsigned int ext_freq = sensor->platform_data->ext_clk;
972 u32 tmp;
973 u32 strobe_adjustment;
974 u32 strobe_width_high_rs;
975 int rval;
976
977 strobe_setup = sensor->platform_data->strobe_setup;
978
979 /*
980 * How to calculate registers related to strobe length. Please
981 * do not change, or if you do at least know what you're
982 * doing. :-)
983 *
984 * Sakari Ailus <sakari.ailus@maxwell.research.nokia.com> 2010-10-25
985 *
986 * flash_strobe_length [us] / 10^6 = (tFlash_strobe_width_ctrl
987 * / EXTCLK freq [Hz]) * flash_strobe_adjustment
988 *
989 * tFlash_strobe_width_ctrl E N, [1 - 0xffff]
990 * flash_strobe_adjustment E N, [1 - 0xff]
991 *
992 * The formula above is written as below to keep it on one
993 * line:
994 *
995 * l / 10^6 = w / e * a
996 *
997 * Let's mark w * a by x:
998 *
999 * x = w * a
1000 *
1001 * Thus, we get:
1002 *
1003 * x = l * e / 10^6
1004 *
1005 * The strobe width must be at least as long as requested,
1006 * thus rounding upwards is needed.
1007 *
1008 * x = (l * e + 10^6 - 1) / 10^6
1009 * -----------------------------
1010 *
1011 * Maximum possible accuracy is wanted at all times. Thus keep
1012 * a as small as possible.
1013 *
1014 * Calculate a, assuming maximum w, with rounding upwards:
1015 *
1016 * a = (x + (2^16 - 1) - 1) / (2^16 - 1)
1017 * -------------------------------------
1018 *
1019 * Thus, we also get w, with that a, with rounding upwards:
1020 *
1021 * w = (x + a - 1) / a
1022 * -------------------
1023 *
1024 * To get limits:
1025 *
1026 * x E [1, (2^16 - 1) * (2^8 - 1)]
1027 *
1028 * Substituting maximum x to the original formula (with rounding),
1029 * the maximum l is thus
1030 *
1031 * (2^16 - 1) * (2^8 - 1) * 10^6 = l * e + 10^6 - 1
1032 *
1033 * l = (10^6 * (2^16 - 1) * (2^8 - 1) - 10^6 + 1) / e
1034 * --------------------------------------------------
1035 *
1036 * flash_strobe_length must be clamped between 1 and
1037 * (10^6 * (2^16 - 1) * (2^8 - 1) - 10^6 + 1) / EXTCLK freq.
1038 *
1039 * Then,
1040 *
1041 * flash_strobe_adjustment = ((flash_strobe_length *
1042 * EXTCLK freq + 10^6 - 1) / 10^6 + (2^16 - 1) - 1) / (2^16 - 1)
1043 *
1044 * tFlash_strobe_width_ctrl = ((flash_strobe_length *
1045 * EXTCLK freq + 10^6 - 1) / 10^6 +
1046 * flash_strobe_adjustment - 1) / flash_strobe_adjustment
1047 */
1048 tmp = div_u64(1000000ULL * ((1 << 16) - 1) * ((1 << 8) - 1) -
1049 1000000 + 1, ext_freq);
1050 strobe_setup->strobe_width_high_us =
1051 clamp_t(u32, strobe_setup->strobe_width_high_us, 1, tmp);
1052
1053 tmp = div_u64(((u64)strobe_setup->strobe_width_high_us * (u64)ext_freq +
1054 1000000 - 1), 1000000ULL);
1055 strobe_adjustment = (tmp + (1 << 16) - 1 - 1) / ((1 << 16) - 1);
1056 strobe_width_high_rs = (tmp + strobe_adjustment - 1) /
1057 strobe_adjustment;
1058
1e73eea7 1059 rval = smiapp_write(sensor, SMIAPP_REG_U8_FLASH_MODE_RS,
ccfc97bd
SA
1060 strobe_setup->mode);
1061 if (rval < 0)
1062 goto out;
1063
1e73eea7 1064 rval = smiapp_write(sensor, SMIAPP_REG_U8_FLASH_STROBE_ADJUSTMENT,
ccfc97bd
SA
1065 strobe_adjustment);
1066 if (rval < 0)
1067 goto out;
1068
1069 rval = smiapp_write(
1e73eea7 1070 sensor, SMIAPP_REG_U16_TFLASH_STROBE_WIDTH_HIGH_RS_CTRL,
ccfc97bd
SA
1071 strobe_width_high_rs);
1072 if (rval < 0)
1073 goto out;
1074
1e73eea7 1075 rval = smiapp_write(sensor, SMIAPP_REG_U16_TFLASH_STROBE_DELAY_RS_CTRL,
ccfc97bd
SA
1076 strobe_setup->strobe_delay);
1077 if (rval < 0)
1078 goto out;
1079
1e73eea7 1080 rval = smiapp_write(sensor, SMIAPP_REG_U16_FLASH_STROBE_START_POINT,
ccfc97bd
SA
1081 strobe_setup->stobe_start_point);
1082 if (rval < 0)
1083 goto out;
1084
1e73eea7 1085 rval = smiapp_write(sensor, SMIAPP_REG_U8_FLASH_TRIGGER_RS,
ccfc97bd
SA
1086 strobe_setup->trigger);
1087
1088out:
1089 sensor->platform_data->strobe_setup->trigger = 0;
1090
1091 return rval;
1092}
1093
1094/* -----------------------------------------------------------------------------
1095 * Power management
1096 */
1097
1098static int smiapp_power_on(struct smiapp_sensor *sensor)
1099{
1100 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
1101 unsigned int sleep;
1102 int rval;
1103
1104 rval = regulator_enable(sensor->vana);
1105 if (rval) {
1106 dev_err(&client->dev, "failed to enable vana regulator\n");
1107 return rval;
1108 }
1109 usleep_range(1000, 1000);
1110
2547428d
SA
1111 if (sensor->platform_data->set_xclk)
1112 rval = sensor->platform_data->set_xclk(
1113 &sensor->src->sd, sensor->platform_data->ext_clk);
1114 else
1115 rval = clk_enable(sensor->ext_clk);
ccfc97bd
SA
1116 if (rval < 0) {
1117 dev_dbg(&client->dev, "failed to set xclk\n");
1118 goto out_xclk_fail;
1119 }
1120 usleep_range(1000, 1000);
1121
1122 if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
1123 gpio_set_value(sensor->platform_data->xshutdown, 1);
1124
1125 sleep = SMIAPP_RESET_DELAY(sensor->platform_data->ext_clk);
1126 usleep_range(sleep, sleep);
1127
1128 /*
1129 * Failures to respond to the address change command have been noticed.
1130 * Those failures seem to be caused by the sensor requiring a longer
1131 * boot time than advertised. An additional 10ms delay seems to work
1132 * around the issue, but the SMIA++ I2C write retry hack makes the delay
1133 * unnecessary. The failures need to be investigated to find a proper
1134 * fix, and a delay will likely need to be added here if the I2C write
1135 * retry hack is reverted before the root cause of the boot time issue
1136 * is found.
1137 */
1138
1139 if (sensor->platform_data->i2c_addr_alt) {
1140 rval = smiapp_change_cci_addr(sensor);
1141 if (rval) {
1142 dev_err(&client->dev, "cci address change error\n");
1143 goto out_cci_addr_fail;
1144 }
1145 }
1146
1e73eea7 1147 rval = smiapp_write(sensor, SMIAPP_REG_U8_SOFTWARE_RESET,
ccfc97bd
SA
1148 SMIAPP_SOFTWARE_RESET);
1149 if (rval < 0) {
1150 dev_err(&client->dev, "software reset failed\n");
1151 goto out_cci_addr_fail;
1152 }
1153
1154 if (sensor->platform_data->i2c_addr_alt) {
1155 rval = smiapp_change_cci_addr(sensor);
1156 if (rval) {
1157 dev_err(&client->dev, "cci address change error\n");
1158 goto out_cci_addr_fail;
1159 }
1160 }
1161
1e73eea7 1162 rval = smiapp_write(sensor, SMIAPP_REG_U16_COMPRESSION_MODE,
ccfc97bd
SA
1163 SMIAPP_COMPRESSION_MODE_SIMPLE_PREDICTOR);
1164 if (rval) {
1165 dev_err(&client->dev, "compression mode set failed\n");
1166 goto out_cci_addr_fail;
1167 }
1168
1169 rval = smiapp_write(
1e73eea7 1170 sensor, SMIAPP_REG_U16_EXTCLK_FREQUENCY_MHZ,
ccfc97bd
SA
1171 sensor->platform_data->ext_clk / (1000000 / (1 << 8)));
1172 if (rval) {
1173 dev_err(&client->dev, "extclk frequency set failed\n");
1174 goto out_cci_addr_fail;
1175 }
1176
1e73eea7 1177 rval = smiapp_write(sensor, SMIAPP_REG_U8_CSI_LANE_MODE,
ccfc97bd
SA
1178 sensor->platform_data->lanes - 1);
1179 if (rval) {
1180 dev_err(&client->dev, "csi lane mode set failed\n");
1181 goto out_cci_addr_fail;
1182 }
1183
1e73eea7 1184 rval = smiapp_write(sensor, SMIAPP_REG_U8_FAST_STANDBY_CTRL,
ccfc97bd
SA
1185 SMIAPP_FAST_STANDBY_CTRL_IMMEDIATE);
1186 if (rval) {
1187 dev_err(&client->dev, "fast standby set failed\n");
1188 goto out_cci_addr_fail;
1189 }
1190
1e73eea7 1191 rval = smiapp_write(sensor, SMIAPP_REG_U8_CSI_SIGNALLING_MODE,
ccfc97bd
SA
1192 sensor->platform_data->csi_signalling_mode);
1193 if (rval) {
1194 dev_err(&client->dev, "csi signalling mode set failed\n");
1195 goto out_cci_addr_fail;
1196 }
1197
1198 /* DPHY control done by sensor based on requested link rate */
1e73eea7 1199 rval = smiapp_write(sensor, SMIAPP_REG_U8_DPHY_CTRL,
ccfc97bd
SA
1200 SMIAPP_DPHY_CTRL_UI);
1201 if (rval < 0)
1202 return rval;
1203
1204 rval = smiapp_call_quirk(sensor, post_poweron);
1205 if (rval) {
1206 dev_err(&client->dev, "post_poweron quirks failed\n");
1207 goto out_cci_addr_fail;
1208 }
1209
1210 /* Are we still initialising...? If yes, return here. */
1211 if (!sensor->pixel_array)
1212 return 0;
1213
1214 rval = v4l2_ctrl_handler_setup(
1215 &sensor->pixel_array->ctrl_handler);
1216 if (rval)
1217 goto out_cci_addr_fail;
1218
1219 rval = v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
1220 if (rval)
1221 goto out_cci_addr_fail;
1222
1223 mutex_lock(&sensor->mutex);
1224 rval = smiapp_update_mode(sensor);
1225 mutex_unlock(&sensor->mutex);
1226 if (rval < 0)
1227 goto out_cci_addr_fail;
1228
1229 return 0;
1230
1231out_cci_addr_fail:
1232 if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
1233 gpio_set_value(sensor->platform_data->xshutdown, 0);
2547428d
SA
1234 if (sensor->platform_data->set_xclk)
1235 sensor->platform_data->set_xclk(&sensor->src->sd, 0);
1236 else
1237 clk_disable(sensor->ext_clk);
ccfc97bd
SA
1238
1239out_xclk_fail:
1240 regulator_disable(sensor->vana);
1241 return rval;
1242}
1243
1244static void smiapp_power_off(struct smiapp_sensor *sensor)
1245{
ccfc97bd
SA
1246 /*
1247 * Currently power/clock to lens are enable/disabled separately
1248 * but they are essentially the same signals. So if the sensor is
1249 * powered off while the lens is powered on the sensor does not
1250 * really see a power off and next time the cci address change
1251 * will fail. So do a soft reset explicitly here.
1252 */
1253 if (sensor->platform_data->i2c_addr_alt)
1e73eea7 1254 smiapp_write(sensor,
ccfc97bd
SA
1255 SMIAPP_REG_U8_SOFTWARE_RESET,
1256 SMIAPP_SOFTWARE_RESET);
1257
1258 if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
1259 gpio_set_value(sensor->platform_data->xshutdown, 0);
2547428d
SA
1260 if (sensor->platform_data->set_xclk)
1261 sensor->platform_data->set_xclk(&sensor->src->sd, 0);
1262 else
1263 clk_disable(sensor->ext_clk);
ccfc97bd
SA
1264 usleep_range(5000, 5000);
1265 regulator_disable(sensor->vana);
1266 sensor->streaming = 0;
1267}
1268
1269static int smiapp_set_power(struct v4l2_subdev *subdev, int on)
1270{
1271 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1272 int ret = 0;
1273
1274 mutex_lock(&sensor->power_mutex);
1275
1276 /*
1277 * If the power count is modified from 0 to != 0 or from != 0
1278 * to 0, update the power state.
1279 */
1280 if (!sensor->power_count == !on)
1281 goto out;
1282
1283 if (on) {
1284 /* Power on and perform initialisation. */
1285 ret = smiapp_power_on(sensor);
1286 if (ret < 0)
1287 goto out;
1288 } else {
1289 smiapp_power_off(sensor);
1290 }
1291
1292 /* Update the power count. */
1293 sensor->power_count += on ? 1 : -1;
1294 WARN_ON(sensor->power_count < 0);
1295
1296out:
1297 mutex_unlock(&sensor->power_mutex);
1298 return ret;
1299}
1300
1301/* -----------------------------------------------------------------------------
1302 * Video stream management
1303 */
1304
1305static int smiapp_start_streaming(struct smiapp_sensor *sensor)
1306{
1307 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
1308 int rval;
1309
1310 mutex_lock(&sensor->mutex);
1311
1e73eea7 1312 rval = smiapp_write(sensor, SMIAPP_REG_U16_CSI_DATA_FORMAT,
ccfc97bd
SA
1313 (sensor->csi_format->width << 8) |
1314 sensor->csi_format->compressed);
1315 if (rval)
1316 goto out;
1317
1318 rval = smiapp_pll_configure(sensor);
1319 if (rval)
1320 goto out;
1321
1322 /* Analog crop start coordinates */
1e73eea7 1323 rval = smiapp_write(sensor, SMIAPP_REG_U16_X_ADDR_START,
ccfc97bd
SA
1324 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].left);
1325 if (rval < 0)
1326 goto out;
1327
1e73eea7 1328 rval = smiapp_write(sensor, SMIAPP_REG_U16_Y_ADDR_START,
ccfc97bd
SA
1329 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].top);
1330 if (rval < 0)
1331 goto out;
1332
1333 /* Analog crop end coordinates */
1334 rval = smiapp_write(
1e73eea7 1335 sensor, SMIAPP_REG_U16_X_ADDR_END,
ccfc97bd
SA
1336 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].left
1337 + sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].width - 1);
1338 if (rval < 0)
1339 goto out;
1340
1341 rval = smiapp_write(
1e73eea7 1342 sensor, SMIAPP_REG_U16_Y_ADDR_END,
ccfc97bd
SA
1343 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].top
1344 + sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height - 1);
1345 if (rval < 0)
1346 goto out;
1347
1348 /*
1349 * Output from pixel array, including blanking, is set using
1350 * controls below. No need to set here.
1351 */
1352
1353 /* Digital crop */
1354 if (sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
1355 == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP) {
1356 rval = smiapp_write(
1e73eea7 1357 sensor, SMIAPP_REG_U16_DIGITAL_CROP_X_OFFSET,
ccfc97bd
SA
1358 sensor->scaler->crop[SMIAPP_PAD_SINK].left);
1359 if (rval < 0)
1360 goto out;
1361
1362 rval = smiapp_write(
1e73eea7 1363 sensor, SMIAPP_REG_U16_DIGITAL_CROP_Y_OFFSET,
ccfc97bd
SA
1364 sensor->scaler->crop[SMIAPP_PAD_SINK].top);
1365 if (rval < 0)
1366 goto out;
1367
1368 rval = smiapp_write(
1e73eea7 1369 sensor, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_WIDTH,
ccfc97bd
SA
1370 sensor->scaler->crop[SMIAPP_PAD_SINK].width);
1371 if (rval < 0)
1372 goto out;
1373
1374 rval = smiapp_write(
1e73eea7 1375 sensor, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_HEIGHT,
ccfc97bd
SA
1376 sensor->scaler->crop[SMIAPP_PAD_SINK].height);
1377 if (rval < 0)
1378 goto out;
1379 }
1380
1381 /* Scaling */
1382 if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
1383 != SMIAPP_SCALING_CAPABILITY_NONE) {
1e73eea7 1384 rval = smiapp_write(sensor, SMIAPP_REG_U16_SCALING_MODE,
ccfc97bd
SA
1385 sensor->scaling_mode);
1386 if (rval < 0)
1387 goto out;
1388
1e73eea7 1389 rval = smiapp_write(sensor, SMIAPP_REG_U16_SCALE_M,
ccfc97bd
SA
1390 sensor->scale_m);
1391 if (rval < 0)
1392 goto out;
1393 }
1394
1395 /* Output size from sensor */
1e73eea7 1396 rval = smiapp_write(sensor, SMIAPP_REG_U16_X_OUTPUT_SIZE,
ccfc97bd
SA
1397 sensor->src->crop[SMIAPP_PAD_SRC].width);
1398 if (rval < 0)
1399 goto out;
1e73eea7 1400 rval = smiapp_write(sensor, SMIAPP_REG_U16_Y_OUTPUT_SIZE,
ccfc97bd
SA
1401 sensor->src->crop[SMIAPP_PAD_SRC].height);
1402 if (rval < 0)
1403 goto out;
1404
1405 if ((sensor->flash_capability &
1406 (SMIAPP_FLASH_MODE_CAPABILITY_SINGLE_STROBE |
1407 SMIAPP_FLASH_MODE_CAPABILITY_MULTIPLE_STROBE)) &&
1408 sensor->platform_data->strobe_setup != NULL &&
1409 sensor->platform_data->strobe_setup->trigger != 0) {
1410 rval = smiapp_setup_flash_strobe(sensor);
1411 if (rval)
1412 goto out;
1413 }
1414
1415 rval = smiapp_call_quirk(sensor, pre_streamon);
1416 if (rval) {
1417 dev_err(&client->dev, "pre_streamon quirks failed\n");
1418 goto out;
1419 }
1420
1e73eea7 1421 rval = smiapp_write(sensor, SMIAPP_REG_U8_MODE_SELECT,
ccfc97bd
SA
1422 SMIAPP_MODE_SELECT_STREAMING);
1423
1424out:
1425 mutex_unlock(&sensor->mutex);
1426
1427 return rval;
1428}
1429
1430static int smiapp_stop_streaming(struct smiapp_sensor *sensor)
1431{
1432 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
1433 int rval;
1434
1435 mutex_lock(&sensor->mutex);
1e73eea7 1436 rval = smiapp_write(sensor, SMIAPP_REG_U8_MODE_SELECT,
ccfc97bd
SA
1437 SMIAPP_MODE_SELECT_SOFTWARE_STANDBY);
1438 if (rval)
1439 goto out;
1440
1441 rval = smiapp_call_quirk(sensor, post_streamoff);
1442 if (rval)
1443 dev_err(&client->dev, "post_streamoff quirks failed\n");
1444
1445out:
1446 mutex_unlock(&sensor->mutex);
1447 return rval;
1448}
1449
1450/* -----------------------------------------------------------------------------
1451 * V4L2 subdev video operations
1452 */
1453
1454static int smiapp_set_stream(struct v4l2_subdev *subdev, int enable)
1455{
1456 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1457 int rval;
1458
1459 if (sensor->streaming == enable)
1460 return 0;
1461
1462 if (enable) {
1463 sensor->streaming = 1;
1464 rval = smiapp_start_streaming(sensor);
1465 if (rval < 0)
1466 sensor->streaming = 0;
1467 } else {
1468 rval = smiapp_stop_streaming(sensor);
1469 sensor->streaming = 0;
1470 }
1471
1472 return rval;
1473}
1474
1475static int smiapp_enum_mbus_code(struct v4l2_subdev *subdev,
1476 struct v4l2_subdev_fh *fh,
1477 struct v4l2_subdev_mbus_code_enum *code)
1478{
1479 struct i2c_client *client = v4l2_get_subdevdata(subdev);
1480 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1481 unsigned int i;
1482 int idx = -1;
1483 int rval = -EINVAL;
1484
1485 mutex_lock(&sensor->mutex);
1486
1487 dev_err(&client->dev, "subdev %s, pad %d, index %d\n",
1488 subdev->name, code->pad, code->index);
1489
1490 if (subdev != &sensor->src->sd || code->pad != SMIAPP_PAD_SRC) {
1491 if (code->index)
1492 goto out;
1493
1494 code->code = sensor->internal_csi_format->code;
1495 rval = 0;
1496 goto out;
1497 }
1498
1499 for (i = 0; i < ARRAY_SIZE(smiapp_csi_data_formats); i++) {
1500 if (sensor->mbus_frame_fmts & (1 << i))
1501 idx++;
1502
1503 if (idx == code->index) {
1504 code->code = smiapp_csi_data_formats[i].code;
1505 dev_err(&client->dev, "found index %d, i %d, code %x\n",
1506 code->index, i, code->code);
1507 rval = 0;
1508 break;
1509 }
1510 }
1511
1512out:
1513 mutex_unlock(&sensor->mutex);
1514
1515 return rval;
1516}
1517
1518static u32 __smiapp_get_mbus_code(struct v4l2_subdev *subdev,
1519 unsigned int pad)
1520{
1521 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1522
1523 if (subdev == &sensor->src->sd && pad == SMIAPP_PAD_SRC)
1524 return sensor->csi_format->code;
1525 else
1526 return sensor->internal_csi_format->code;
1527}
1528
1529static int __smiapp_get_format(struct v4l2_subdev *subdev,
1530 struct v4l2_subdev_fh *fh,
1531 struct v4l2_subdev_format *fmt)
1532{
1533 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1534
1535 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1536 fmt->format = *v4l2_subdev_get_try_format(fh, fmt->pad);
1537 } else {
1538 struct v4l2_rect *r;
1539
1540 if (fmt->pad == ssd->source_pad)
1541 r = &ssd->crop[ssd->source_pad];
1542 else
1543 r = &ssd->sink_fmt;
1544
1545 fmt->format.code = __smiapp_get_mbus_code(subdev, fmt->pad);
1546 fmt->format.width = r->width;
1547 fmt->format.height = r->height;
1548 }
1549
1550 return 0;
1551}
1552
1553static int smiapp_get_format(struct v4l2_subdev *subdev,
1554 struct v4l2_subdev_fh *fh,
1555 struct v4l2_subdev_format *fmt)
1556{
1557 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1558 int rval;
1559
1560 mutex_lock(&sensor->mutex);
1561 rval = __smiapp_get_format(subdev, fh, fmt);
1562 mutex_unlock(&sensor->mutex);
1563
1564 return rval;
1565}
1566
1567static void smiapp_get_crop_compose(struct v4l2_subdev *subdev,
1568 struct v4l2_subdev_fh *fh,
1569 struct v4l2_rect **crops,
1570 struct v4l2_rect **comps, int which)
1571{
1572 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1573 unsigned int i;
1574
1575 if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1576 if (crops)
1577 for (i = 0; i < subdev->entity.num_pads; i++)
1578 crops[i] = &ssd->crop[i];
1579 if (comps)
1580 *comps = &ssd->compose;
1581 } else {
1582 if (crops) {
1583 for (i = 0; i < subdev->entity.num_pads; i++) {
1584 crops[i] = v4l2_subdev_get_try_crop(fh, i);
1585 BUG_ON(!crops[i]);
1586 }
1587 }
1588 if (comps) {
1589 *comps = v4l2_subdev_get_try_compose(fh,
1590 SMIAPP_PAD_SINK);
1591 BUG_ON(!*comps);
1592 }
1593 }
1594}
1595
1596/* Changes require propagation only on sink pad. */
1597static void smiapp_propagate(struct v4l2_subdev *subdev,
1598 struct v4l2_subdev_fh *fh, int which,
1599 int target)
1600{
1601 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1602 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1603 struct v4l2_rect *comp, *crops[SMIAPP_PADS];
1604
1605 smiapp_get_crop_compose(subdev, fh, crops, &comp, which);
1606
1607 switch (target) {
1608 case V4L2_SUBDEV_SEL_TGT_CROP_ACTUAL:
1609 comp->width = crops[SMIAPP_PAD_SINK]->width;
1610 comp->height = crops[SMIAPP_PAD_SINK]->height;
1611 if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1612 if (ssd == sensor->scaler) {
1613 sensor->scale_m =
1614 sensor->limits[
1615 SMIAPP_LIMIT_SCALER_N_MIN];
1616 sensor->scaling_mode =
1617 SMIAPP_SCALING_MODE_NONE;
1618 } else if (ssd == sensor->binner) {
1619 sensor->binning_horizontal = 1;
1620 sensor->binning_vertical = 1;
1621 }
1622 }
1623 /* Fall through */
1624 case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTUAL:
1625 *crops[SMIAPP_PAD_SRC] = *comp;
1626 break;
1627 default:
1628 BUG();
1629 }
1630}
1631
1632static const struct smiapp_csi_data_format
1633*smiapp_validate_csi_data_format(struct smiapp_sensor *sensor, u32 code)
1634{
1635 const struct smiapp_csi_data_format *csi_format = sensor->csi_format;
1636 unsigned int i;
1637
1638 for (i = 0; i < ARRAY_SIZE(smiapp_csi_data_formats); i++) {
1639 if (sensor->mbus_frame_fmts & (1 << i)
1640 && smiapp_csi_data_formats[i].code == code)
1641 return &smiapp_csi_data_formats[i];
1642 }
1643
1644 return csi_format;
1645}
1646
1647static int smiapp_set_format(struct v4l2_subdev *subdev,
1648 struct v4l2_subdev_fh *fh,
1649 struct v4l2_subdev_format *fmt)
1650{
1651 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1652 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1653 struct v4l2_rect *crops[SMIAPP_PADS];
1654
1655 mutex_lock(&sensor->mutex);
1656
1657 /*
1658 * Media bus code is changeable on src subdev's source pad. On
1659 * other source pads we just get format here.
1660 */
1661 if (fmt->pad == ssd->source_pad) {
1662 u32 code = fmt->format.code;
1663 int rval = __smiapp_get_format(subdev, fh, fmt);
1664
1665 if (!rval && subdev == &sensor->src->sd) {
1666 const struct smiapp_csi_data_format *csi_format =
1667 smiapp_validate_csi_data_format(sensor, code);
1668 if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
1669 sensor->csi_format = csi_format;
1670 fmt->format.code = csi_format->code;
1671 }
1672
1673 mutex_unlock(&sensor->mutex);
1674 return rval;
1675 }
1676
1677 /* Sink pad. Width and height are changeable here. */
1678 fmt->format.code = __smiapp_get_mbus_code(subdev, fmt->pad);
1679 fmt->format.width &= ~1;
1680 fmt->format.height &= ~1;
1681
1682 fmt->format.width =
1683 clamp(fmt->format.width,
1684 sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE],
1685 sensor->limits[SMIAPP_LIMIT_MAX_X_OUTPUT_SIZE]);
1686 fmt->format.height =
1687 clamp(fmt->format.height,
1688 sensor->limits[SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE],
1689 sensor->limits[SMIAPP_LIMIT_MAX_Y_OUTPUT_SIZE]);
1690
1691 smiapp_get_crop_compose(subdev, fh, crops, NULL, fmt->which);
1692
1693 crops[ssd->sink_pad]->left = 0;
1694 crops[ssd->sink_pad]->top = 0;
1695 crops[ssd->sink_pad]->width = fmt->format.width;
1696 crops[ssd->sink_pad]->height = fmt->format.height;
1697 if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
1698 ssd->sink_fmt = *crops[ssd->sink_pad];
1699 smiapp_propagate(subdev, fh, fmt->which,
1700 V4L2_SUBDEV_SEL_TGT_CROP_ACTUAL);
1701
1702 mutex_unlock(&sensor->mutex);
1703
1704 return 0;
1705}
1706
1707/*
1708 * Calculate goodness of scaled image size compared to expected image
1709 * size and flags provided.
1710 */
1711#define SCALING_GOODNESS 100000
1712#define SCALING_GOODNESS_EXTREME 100000000
1713static int scaling_goodness(struct v4l2_subdev *subdev, int w, int ask_w,
1714 int h, int ask_h, u32 flags)
1715{
1716 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1717 struct i2c_client *client = v4l2_get_subdevdata(subdev);
1718 int val = 0;
1719
1720 w &= ~1;
1721 ask_w &= ~1;
1722 h &= ~1;
1723 ask_h &= ~1;
1724
1725 if (flags & V4L2_SUBDEV_SEL_FLAG_SIZE_GE) {
1726 if (w < ask_w)
1727 val -= SCALING_GOODNESS;
1728 if (h < ask_h)
1729 val -= SCALING_GOODNESS;
1730 }
1731
1732 if (flags & V4L2_SUBDEV_SEL_FLAG_SIZE_LE) {
1733 if (w > ask_w)
1734 val -= SCALING_GOODNESS;
1735 if (h > ask_h)
1736 val -= SCALING_GOODNESS;
1737 }
1738
1739 val -= abs(w - ask_w);
1740 val -= abs(h - ask_h);
1741
1742 if (w < sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE])
1743 val -= SCALING_GOODNESS_EXTREME;
1744
1745 dev_dbg(&client->dev, "w %d ask_w %d h %d ask_h %d goodness %d\n",
1746 w, ask_h, h, ask_h, val);
1747
1748 return val;
1749}
1750
1751static void smiapp_set_compose_binner(struct v4l2_subdev *subdev,
1752 struct v4l2_subdev_fh *fh,
1753 struct v4l2_subdev_selection *sel,
1754 struct v4l2_rect **crops,
1755 struct v4l2_rect *comp)
1756{
1757 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1758 unsigned int i;
1759 unsigned int binh = 1, binv = 1;
1760 unsigned int best = scaling_goodness(
1761 subdev,
1762 crops[SMIAPP_PAD_SINK]->width, sel->r.width,
1763 crops[SMIAPP_PAD_SINK]->height, sel->r.height, sel->flags);
1764
1765 for (i = 0; i < sensor->nbinning_subtypes; i++) {
1766 int this = scaling_goodness(
1767 subdev,
1768 crops[SMIAPP_PAD_SINK]->width
1769 / sensor->binning_subtypes[i].horizontal,
1770 sel->r.width,
1771 crops[SMIAPP_PAD_SINK]->height
1772 / sensor->binning_subtypes[i].vertical,
1773 sel->r.height, sel->flags);
1774
1775 if (this > best) {
1776 binh = sensor->binning_subtypes[i].horizontal;
1777 binv = sensor->binning_subtypes[i].vertical;
1778 best = this;
1779 }
1780 }
1781 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1782 sensor->binning_vertical = binv;
1783 sensor->binning_horizontal = binh;
1784 }
1785
1786 sel->r.width = (crops[SMIAPP_PAD_SINK]->width / binh) & ~1;
1787 sel->r.height = (crops[SMIAPP_PAD_SINK]->height / binv) & ~1;
1788}
1789
1790/*
1791 * Calculate best scaling ratio and mode for given output resolution.
1792 *
1793 * Try all of these: horizontal ratio, vertical ratio and smallest
1794 * size possible (horizontally).
1795 *
1796 * Also try whether horizontal scaler or full scaler gives a better
1797 * result.
1798 */
1799static void smiapp_set_compose_scaler(struct v4l2_subdev *subdev,
1800 struct v4l2_subdev_fh *fh,
1801 struct v4l2_subdev_selection *sel,
1802 struct v4l2_rect **crops,
1803 struct v4l2_rect *comp)
1804{
1805 struct i2c_client *client = v4l2_get_subdevdata(subdev);
1806 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1807 u32 min, max, a, b, max_m;
1808 u32 scale_m = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
1809 int mode = SMIAPP_SCALING_MODE_HORIZONTAL;
1810 u32 try[4];
1811 u32 ntry = 0;
1812 unsigned int i;
1813 int best = INT_MIN;
1814
1815 sel->r.width = min_t(unsigned int, sel->r.width,
1816 crops[SMIAPP_PAD_SINK]->width);
1817 sel->r.height = min_t(unsigned int, sel->r.height,
1818 crops[SMIAPP_PAD_SINK]->height);
1819
1820 a = crops[SMIAPP_PAD_SINK]->width
1821 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN] / sel->r.width;
1822 b = crops[SMIAPP_PAD_SINK]->height
1823 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN] / sel->r.height;
1824 max_m = crops[SMIAPP_PAD_SINK]->width
1825 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]
1826 / sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE];
1827
1828 a = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
1829 max(a, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
1830 b = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
1831 max(b, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
1832 max_m = min(sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX],
1833 max(max_m, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN]));
1834
1835 dev_dbg(&client->dev, "scaling: a %d b %d max_m %d\n", a, b, max_m);
1836
1837 min = min(max_m, min(a, b));
1838 max = min(max_m, max(a, b));
1839
1840 try[ntry] = min;
1841 ntry++;
1842 if (min != max) {
1843 try[ntry] = max;
1844 ntry++;
1845 }
1846 if (max != max_m) {
1847 try[ntry] = min + 1;
1848 ntry++;
1849 if (min != max) {
1850 try[ntry] = max + 1;
1851 ntry++;
1852 }
1853 }
1854
1855 for (i = 0; i < ntry; i++) {
1856 int this = scaling_goodness(
1857 subdev,
1858 crops[SMIAPP_PAD_SINK]->width
1859 / try[i]
1860 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
1861 sel->r.width,
1862 crops[SMIAPP_PAD_SINK]->height,
1863 sel->r.height,
1864 sel->flags);
1865
1866 dev_dbg(&client->dev, "trying factor %d (%d)\n", try[i], i);
1867
1868 if (this > best) {
1869 scale_m = try[i];
1870 mode = SMIAPP_SCALING_MODE_HORIZONTAL;
1871 best = this;
1872 }
1873
1874 if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
1875 == SMIAPP_SCALING_CAPABILITY_HORIZONTAL)
1876 continue;
1877
1878 this = scaling_goodness(
1879 subdev, crops[SMIAPP_PAD_SINK]->width
1880 / try[i]
1881 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
1882 sel->r.width,
1883 crops[SMIAPP_PAD_SINK]->height
1884 / try[i]
1885 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
1886 sel->r.height,
1887 sel->flags);
1888
1889 if (this > best) {
1890 scale_m = try[i];
1891 mode = SMIAPP_SCALING_MODE_BOTH;
1892 best = this;
1893 }
1894 }
1895
1896 sel->r.width =
1897 (crops[SMIAPP_PAD_SINK]->width
1898 / scale_m
1899 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]) & ~1;
1900 if (mode == SMIAPP_SCALING_MODE_BOTH)
1901 sel->r.height =
1902 (crops[SMIAPP_PAD_SINK]->height
1903 / scale_m
1904 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN])
1905 & ~1;
1906 else
1907 sel->r.height = crops[SMIAPP_PAD_SINK]->height;
1908
1909 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1910 sensor->scale_m = scale_m;
1911 sensor->scaling_mode = mode;
1912 }
1913}
1914/* We're only called on source pads. This function sets scaling. */
1915static int smiapp_set_compose(struct v4l2_subdev *subdev,
1916 struct v4l2_subdev_fh *fh,
1917 struct v4l2_subdev_selection *sel)
1918{
1919 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1920 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1921 struct v4l2_rect *comp, *crops[SMIAPP_PADS];
1922
1923 smiapp_get_crop_compose(subdev, fh, crops, &comp, sel->which);
1924
1925 sel->r.top = 0;
1926 sel->r.left = 0;
1927
1928 if (ssd == sensor->binner)
1929 smiapp_set_compose_binner(subdev, fh, sel, crops, comp);
1930 else
1931 smiapp_set_compose_scaler(subdev, fh, sel, crops, comp);
1932
1933 *comp = sel->r;
1934 smiapp_propagate(subdev, fh, sel->which,
1935 V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTUAL);
1936
1937 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE)
1938 return smiapp_update_mode(sensor);
1939
1940 return 0;
1941}
1942
1943static int __smiapp_sel_supported(struct v4l2_subdev *subdev,
1944 struct v4l2_subdev_selection *sel)
1945{
1946 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1947 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1948
1949 /* We only implement crop in three places. */
1950 switch (sel->target) {
1951 case V4L2_SUBDEV_SEL_TGT_CROP_ACTUAL:
1952 case V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS:
1953 if (ssd == sensor->pixel_array
1954 && sel->pad == SMIAPP_PA_PAD_SRC)
1955 return 0;
1956 if (ssd == sensor->src
1957 && sel->pad == SMIAPP_PAD_SRC)
1958 return 0;
1959 if (ssd == sensor->scaler
1960 && sel->pad == SMIAPP_PAD_SINK
1961 && sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
1962 == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP)
1963 return 0;
1964 return -EINVAL;
1965 case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTUAL:
1966 case V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS:
1967 if (sel->pad == ssd->source_pad)
1968 return -EINVAL;
1969 if (ssd == sensor->binner)
1970 return 0;
1971 if (ssd == sensor->scaler
1972 && sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
1973 != SMIAPP_SCALING_CAPABILITY_NONE)
1974 return 0;
1975 /* Fall through */
1976 default:
1977 return -EINVAL;
1978 }
1979}
1980
1981static int smiapp_set_crop(struct v4l2_subdev *subdev,
1982 struct v4l2_subdev_fh *fh,
1983 struct v4l2_subdev_selection *sel)
1984{
1985 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1986 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1987 struct v4l2_rect *src_size, *crops[SMIAPP_PADS];
1988 struct v4l2_rect _r;
1989
1990 smiapp_get_crop_compose(subdev, fh, crops, NULL, sel->which);
1991
1992 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1993 if (sel->pad == ssd->sink_pad)
1994 src_size = &ssd->sink_fmt;
1995 else
1996 src_size = &ssd->compose;
1997 } else {
1998 if (sel->pad == ssd->sink_pad) {
1999 _r.left = 0;
2000 _r.top = 0;
2001 _r.width = v4l2_subdev_get_try_format(fh, sel->pad)
2002 ->width;
2003 _r.height = v4l2_subdev_get_try_format(fh, sel->pad)
2004 ->height;
2005 src_size = &_r;
2006 } else {
2007 src_size =
2008 v4l2_subdev_get_try_compose(
2009 fh, ssd->sink_pad);
2010 }
2011 }
2012
2013 if (ssd == sensor->src && sel->pad == SMIAPP_PAD_SRC) {
2014 sel->r.left = 0;
2015 sel->r.top = 0;
2016 }
2017
2018 sel->r.width = min(sel->r.width, src_size->width);
2019 sel->r.height = min(sel->r.height, src_size->height);
2020
2021 sel->r.left = min(sel->r.left, src_size->width - sel->r.width);
2022 sel->r.top = min(sel->r.top, src_size->height - sel->r.height);
2023
2024 *crops[sel->pad] = sel->r;
2025
2026 if (ssd != sensor->pixel_array && sel->pad == SMIAPP_PAD_SINK)
2027 smiapp_propagate(subdev, fh, sel->which,
2028 V4L2_SUBDEV_SEL_TGT_CROP_ACTUAL);
2029
2030 return 0;
2031}
2032
2033static int __smiapp_get_selection(struct v4l2_subdev *subdev,
2034 struct v4l2_subdev_fh *fh,
2035 struct v4l2_subdev_selection *sel)
2036{
2037 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2038 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
2039 struct v4l2_rect *comp, *crops[SMIAPP_PADS];
2040 struct v4l2_rect sink_fmt;
2041 int ret;
2042
2043 ret = __smiapp_sel_supported(subdev, sel);
2044 if (ret)
2045 return ret;
2046
2047 smiapp_get_crop_compose(subdev, fh, crops, &comp, sel->which);
2048
2049 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
2050 sink_fmt = ssd->sink_fmt;
2051 } else {
2052 struct v4l2_mbus_framefmt *fmt =
2053 v4l2_subdev_get_try_format(fh, ssd->sink_pad);
2054
2055 sink_fmt.left = 0;
2056 sink_fmt.top = 0;
2057 sink_fmt.width = fmt->width;
2058 sink_fmt.height = fmt->height;
2059 }
2060
2061 switch (sel->target) {
2062 case V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS:
2063 if (ssd == sensor->pixel_array) {
2064 sel->r.width =
2065 sensor->limits[SMIAPP_LIMIT_X_ADDR_MAX] + 1;
2066 sel->r.height =
2067 sensor->limits[SMIAPP_LIMIT_Y_ADDR_MAX] + 1;
2068 } else if (sel->pad == ssd->sink_pad) {
2069 sel->r = sink_fmt;
2070 } else {
2071 sel->r = *comp;
2072 }
2073 break;
2074 case V4L2_SUBDEV_SEL_TGT_CROP_ACTUAL:
2075 case V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS:
2076 sel->r = *crops[sel->pad];
2077 break;
2078 case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTUAL:
2079 sel->r = *comp;
2080 break;
2081 }
2082
2083 return 0;
2084}
2085
2086static int smiapp_get_selection(struct v4l2_subdev *subdev,
2087 struct v4l2_subdev_fh *fh,
2088 struct v4l2_subdev_selection *sel)
2089{
2090 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2091 int rval;
2092
2093 mutex_lock(&sensor->mutex);
2094 rval = __smiapp_get_selection(subdev, fh, sel);
2095 mutex_unlock(&sensor->mutex);
2096
2097 return rval;
2098}
2099static int smiapp_set_selection(struct v4l2_subdev *subdev,
2100 struct v4l2_subdev_fh *fh,
2101 struct v4l2_subdev_selection *sel)
2102{
2103 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2104 int ret;
2105
2106 ret = __smiapp_sel_supported(subdev, sel);
2107 if (ret)
2108 return ret;
2109
2110 mutex_lock(&sensor->mutex);
2111
2112 sel->r.left = max(0, sel->r.left & ~1);
2113 sel->r.top = max(0, sel->r.top & ~1);
2114 sel->r.width = max(0, SMIAPP_ALIGN_DIM(sel->r.width, sel->flags));
2115 sel->r.height = max(0, SMIAPP_ALIGN_DIM(sel->r.height, sel->flags));
2116
2117 sel->r.width = max_t(unsigned int,
2118 sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE],
2119 sel->r.width);
2120 sel->r.height = max_t(unsigned int,
2121 sensor->limits[SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE],
2122 sel->r.height);
2123
2124 switch (sel->target) {
2125 case V4L2_SUBDEV_SEL_TGT_CROP_ACTUAL:
2126 ret = smiapp_set_crop(subdev, fh, sel);
2127 break;
2128 case V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTUAL:
2129 ret = smiapp_set_compose(subdev, fh, sel);
2130 break;
2131 default:
2132 BUG();
2133 }
2134
2135 mutex_unlock(&sensor->mutex);
2136 return ret;
2137}
2138
2139static int smiapp_get_skip_frames(struct v4l2_subdev *subdev, u32 *frames)
2140{
2141 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2142
2143 *frames = sensor->frame_skip;
2144 return 0;
2145}
2146
2147/* -----------------------------------------------------------------------------
2148 * sysfs attributes
2149 */
2150
2151static ssize_t
2152smiapp_sysfs_nvm_read(struct device *dev, struct device_attribute *attr,
2153 char *buf)
2154{
2155 struct v4l2_subdev *subdev = i2c_get_clientdata(to_i2c_client(dev));
2156 struct i2c_client *client = v4l2_get_subdevdata(subdev);
2157 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2158 unsigned int nbytes;
2159
2160 if (!sensor->dev_init_done)
2161 return -EBUSY;
2162
2163 if (!sensor->nvm_size) {
2164 /* NVM not read yet - read it now */
2165 sensor->nvm_size = sensor->platform_data->nvm_size;
2166 if (smiapp_set_power(subdev, 1) < 0)
2167 return -ENODEV;
2168 if (smiapp_read_nvm(sensor, sensor->nvm)) {
2169 dev_err(&client->dev, "nvm read failed\n");
2170 return -ENODEV;
2171 }
2172 smiapp_set_power(subdev, 0);
2173 }
2174 /*
2175 * NVM is still way below a PAGE_SIZE, so we can safely
2176 * assume this for now.
2177 */
2178 nbytes = min_t(unsigned int, sensor->nvm_size, PAGE_SIZE);
2179 memcpy(buf, sensor->nvm, nbytes);
2180
2181 return nbytes;
2182}
2183static DEVICE_ATTR(nvm, S_IRUGO, smiapp_sysfs_nvm_read, NULL);
2184
2185/* -----------------------------------------------------------------------------
2186 * V4L2 subdev core operations
2187 */
2188
2189static int smiapp_identify_module(struct v4l2_subdev *subdev)
2190{
2191 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2192 struct i2c_client *client = v4l2_get_subdevdata(subdev);
2193 struct smiapp_module_info *minfo = &sensor->minfo;
2194 unsigned int i;
2195 int rval = 0;
2196
2197 minfo->name = SMIAPP_NAME;
2198
2199 /* Module info */
98add8e8
SA
2200 rval = smiapp_read_8only(sensor, SMIAPP_REG_U8_MANUFACTURER_ID,
2201 &minfo->manufacturer_id);
ccfc97bd 2202 if (!rval)
98add8e8
SA
2203 rval = smiapp_read_8only(sensor, SMIAPP_REG_U16_MODEL_ID,
2204 &minfo->model_id);
ccfc97bd 2205 if (!rval)
98add8e8
SA
2206 rval = smiapp_read_8only(sensor,
2207 SMIAPP_REG_U8_REVISION_NUMBER_MAJOR,
2208 &minfo->revision_number_major);
ccfc97bd 2209 if (!rval)
98add8e8
SA
2210 rval = smiapp_read_8only(sensor,
2211 SMIAPP_REG_U8_REVISION_NUMBER_MINOR,
2212 &minfo->revision_number_minor);
ccfc97bd 2213 if (!rval)
98add8e8
SA
2214 rval = smiapp_read_8only(sensor,
2215 SMIAPP_REG_U8_MODULE_DATE_YEAR,
2216 &minfo->module_year);
ccfc97bd 2217 if (!rval)
98add8e8
SA
2218 rval = smiapp_read_8only(sensor,
2219 SMIAPP_REG_U8_MODULE_DATE_MONTH,
2220 &minfo->module_month);
ccfc97bd 2221 if (!rval)
98add8e8
SA
2222 rval = smiapp_read_8only(sensor, SMIAPP_REG_U8_MODULE_DATE_DAY,
2223 &minfo->module_day);
ccfc97bd
SA
2224
2225 /* Sensor info */
2226 if (!rval)
98add8e8
SA
2227 rval = smiapp_read_8only(sensor,
2228 SMIAPP_REG_U8_SENSOR_MANUFACTURER_ID,
2229 &minfo->sensor_manufacturer_id);
ccfc97bd 2230 if (!rval)
98add8e8
SA
2231 rval = smiapp_read_8only(sensor,
2232 SMIAPP_REG_U16_SENSOR_MODEL_ID,
2233 &minfo->sensor_model_id);
ccfc97bd 2234 if (!rval)
98add8e8
SA
2235 rval = smiapp_read_8only(sensor,
2236 SMIAPP_REG_U8_SENSOR_REVISION_NUMBER,
2237 &minfo->sensor_revision_number);
ccfc97bd 2238 if (!rval)
98add8e8
SA
2239 rval = smiapp_read_8only(sensor,
2240 SMIAPP_REG_U8_SENSOR_FIRMWARE_VERSION,
2241 &minfo->sensor_firmware_version);
ccfc97bd
SA
2242
2243 /* SMIA */
2244 if (!rval)
98add8e8
SA
2245 rval = smiapp_read_8only(sensor, SMIAPP_REG_U8_SMIA_VERSION,
2246 &minfo->smia_version);
ccfc97bd 2247 if (!rval)
98add8e8
SA
2248 rval = smiapp_read_8only(sensor, SMIAPP_REG_U8_SMIAPP_VERSION,
2249 &minfo->smiapp_version);
ccfc97bd
SA
2250
2251 if (rval) {
2252 dev_err(&client->dev, "sensor detection failed\n");
2253 return -ENODEV;
2254 }
2255
2256 dev_dbg(&client->dev, "module 0x%2.2x-0x%4.4x\n",
2257 minfo->manufacturer_id, minfo->model_id);
2258
2259 dev_dbg(&client->dev,
2260 "module revision 0x%2.2x-0x%2.2x date %2.2d-%2.2d-%2.2d\n",
2261 minfo->revision_number_major, minfo->revision_number_minor,
2262 minfo->module_year, minfo->module_month, minfo->module_day);
2263
2264 dev_dbg(&client->dev, "sensor 0x%2.2x-0x%4.4x\n",
2265 minfo->sensor_manufacturer_id, minfo->sensor_model_id);
2266
2267 dev_dbg(&client->dev,
2268 "sensor revision 0x%2.2x firmware version 0x%2.2x\n",
2269 minfo->sensor_revision_number, minfo->sensor_firmware_version);
2270
2271 dev_dbg(&client->dev, "smia version %2.2d smiapp version %2.2d\n",
2272 minfo->smia_version, minfo->smiapp_version);
2273
2274 /*
2275 * Some modules have bad data in the lvalues below. Hope the
2276 * rvalues have better stuff. The lvalues are module
2277 * parameters whereas the rvalues are sensor parameters.
2278 */
2279 if (!minfo->manufacturer_id && !minfo->model_id) {
2280 minfo->manufacturer_id = minfo->sensor_manufacturer_id;
2281 minfo->model_id = minfo->sensor_model_id;
2282 minfo->revision_number_major = minfo->sensor_revision_number;
2283 }
2284
2285 for (i = 0; i < ARRAY_SIZE(smiapp_module_idents); i++) {
2286 if (smiapp_module_idents[i].manufacturer_id
2287 != minfo->manufacturer_id)
2288 continue;
2289 if (smiapp_module_idents[i].model_id != minfo->model_id)
2290 continue;
2291 if (smiapp_module_idents[i].flags
2292 & SMIAPP_MODULE_IDENT_FLAG_REV_LE) {
2293 if (smiapp_module_idents[i].revision_number_major
2294 < minfo->revision_number_major)
2295 continue;
2296 } else {
2297 if (smiapp_module_idents[i].revision_number_major
2298 != minfo->revision_number_major)
2299 continue;
2300 }
2301
2302 minfo->name = smiapp_module_idents[i].name;
2303 minfo->quirk = smiapp_module_idents[i].quirk;
2304 break;
2305 }
2306
2307 if (i >= ARRAY_SIZE(smiapp_module_idents))
2308 dev_warn(&client->dev,
2309 "no quirks for this module; let's hope it's fully compliant\n");
2310
2311 dev_dbg(&client->dev, "the sensor is called %s, ident %2.2x%4.4x%2.2x\n",
2312 minfo->name, minfo->manufacturer_id, minfo->model_id,
2313 minfo->revision_number_major);
2314
2315 strlcpy(subdev->name, sensor->minfo.name, sizeof(subdev->name));
2316
2317 return 0;
2318}
2319
2320static const struct v4l2_subdev_ops smiapp_ops;
2321static const struct v4l2_subdev_internal_ops smiapp_internal_ops;
2322static const struct media_entity_operations smiapp_entity_ops;
2323
2324static int smiapp_registered(struct v4l2_subdev *subdev)
2325{
2326 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2327 struct i2c_client *client = v4l2_get_subdevdata(subdev);
2328 struct smiapp_subdev *last = NULL;
2329 u32 tmp;
2330 unsigned int i;
2331 int rval;
2332
2333 sensor->vana = regulator_get(&client->dev, "VANA");
2334 if (IS_ERR(sensor->vana)) {
2335 dev_err(&client->dev, "could not get regulator for vana\n");
2336 return -ENODEV;
2337 }
2338
2547428d
SA
2339 if (!sensor->platform_data->set_xclk) {
2340 sensor->ext_clk = clk_get(&client->dev,
2341 sensor->platform_data->ext_clk_name);
2342 if (IS_ERR(sensor->ext_clk)) {
2343 dev_err(&client->dev, "could not get clock %s\n",
2344 sensor->platform_data->ext_clk_name);
2345 rval = -ENODEV;
2346 goto out_clk_get;
2347 }
2348
2349 rval = clk_set_rate(sensor->ext_clk,
2350 sensor->platform_data->ext_clk);
2351 if (rval < 0) {
2352 dev_err(&client->dev,
2353 "unable to set clock %s freq to %u\n",
2354 sensor->platform_data->ext_clk_name,
2355 sensor->platform_data->ext_clk);
2356 rval = -ENODEV;
2357 goto out_clk_set_rate;
2358 }
2359 }
2360
ccfc97bd
SA
2361 if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) {
2362 if (gpio_request_one(sensor->platform_data->xshutdown, 0,
2363 "SMIA++ xshutdown") != 0) {
2364 dev_err(&client->dev,
2365 "unable to acquire reset gpio %d\n",
2366 sensor->platform_data->xshutdown);
2367 rval = -ENODEV;
2547428d 2368 goto out_clk_set_rate;
ccfc97bd
SA
2369 }
2370 }
2371
2372 rval = smiapp_power_on(sensor);
2373 if (rval) {
2374 rval = -ENODEV;
2375 goto out_smiapp_power_on;
2376 }
2377
2378 rval = smiapp_identify_module(subdev);
2379 if (rval) {
2380 rval = -ENODEV;
2381 goto out_power_off;
2382 }
2383
2384 rval = smiapp_get_all_limits(sensor);
2385 if (rval) {
2386 rval = -ENODEV;
2387 goto out_power_off;
2388 }
2389
2390 /*
2391 * Handle Sensor Module orientation on the board.
2392 *
2393 * The application of H-FLIP and V-FLIP on the sensor is modified by
2394 * the sensor orientation on the board.
2395 *
2396 * For SMIAPP_BOARD_SENSOR_ORIENT_180 the default behaviour is to set
2397 * both H-FLIP and V-FLIP for normal operation which also implies
2398 * that a set/unset operation for user space HFLIP and VFLIP v4l2
2399 * controls will need to be internally inverted.
2400 *
2401 * Rotation also changes the bayer pattern.
2402 */
2403 if (sensor->platform_data->module_board_orient ==
2404 SMIAPP_MODULE_BOARD_ORIENT_180)
2405 sensor->hvflip_inv_mask = SMIAPP_IMAGE_ORIENTATION_HFLIP |
2406 SMIAPP_IMAGE_ORIENTATION_VFLIP;
2407
2408 rval = smiapp_get_mbus_formats(sensor);
2409 if (rval) {
2410 rval = -ENODEV;
2411 goto out_power_off;
2412 }
2413
2414 if (sensor->limits[SMIAPP_LIMIT_BINNING_CAPABILITY]) {
2415 u32 val;
2416
1e73eea7 2417 rval = smiapp_read(sensor,
ccfc97bd
SA
2418 SMIAPP_REG_U8_BINNING_SUBTYPES, &val);
2419 if (rval < 0) {
2420 rval = -ENODEV;
2421 goto out_power_off;
2422 }
2423 sensor->nbinning_subtypes = min_t(u8, val,
2424 SMIAPP_BINNING_SUBTYPES);
2425
2426 for (i = 0; i < sensor->nbinning_subtypes; i++) {
2427 rval = smiapp_read(
1e73eea7 2428 sensor, SMIAPP_REG_U8_BINNING_TYPE_n(i), &val);
ccfc97bd
SA
2429 if (rval < 0) {
2430 rval = -ENODEV;
2431 goto out_power_off;
2432 }
2433 sensor->binning_subtypes[i] =
2434 *(struct smiapp_binning_subtype *)&val;
2435
2436 dev_dbg(&client->dev, "binning %xx%x\n",
2437 sensor->binning_subtypes[i].horizontal,
2438 sensor->binning_subtypes[i].vertical);
2439 }
2440 }
2441 sensor->binning_horizontal = 1;
2442 sensor->binning_vertical = 1;
2443
2444 /* SMIA++ NVM initialization - it will be read from the sensor
2445 * when it is first requested by userspace.
2446 */
2447 if (sensor->minfo.smiapp_version && sensor->platform_data->nvm_size) {
2448 sensor->nvm = kzalloc(sensor->platform_data->nvm_size,
2449 GFP_KERNEL);
2450 if (sensor->nvm == NULL) {
2451 dev_err(&client->dev, "nvm buf allocation failed\n");
2452 rval = -ENOMEM;
2453 goto out_power_off;
2454 }
2455
2456 if (device_create_file(&client->dev, &dev_attr_nvm) != 0) {
2457 dev_err(&client->dev, "sysfs nvm entry failed\n");
2458 rval = -EBUSY;
2459 goto out_power_off;
2460 }
2461 }
2462
2463 rval = smiapp_call_quirk(sensor, limits);
2464 if (rval) {
2465 dev_err(&client->dev, "limits quirks failed\n");
2466 goto out_nvm_release;
2467 }
2468
2469 /* We consider this as profile 0 sensor if any of these are zero. */
2470 if (!sensor->limits[SMIAPP_LIMIT_MIN_OP_SYS_CLK_DIV] ||
2471 !sensor->limits[SMIAPP_LIMIT_MAX_OP_SYS_CLK_DIV] ||
2472 !sensor->limits[SMIAPP_LIMIT_MIN_OP_PIX_CLK_DIV] ||
2473 !sensor->limits[SMIAPP_LIMIT_MAX_OP_PIX_CLK_DIV]) {
2474 sensor->minfo.smiapp_profile = SMIAPP_PROFILE_0;
2475 } else if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
2476 != SMIAPP_SCALING_CAPABILITY_NONE) {
2477 if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
2478 == SMIAPP_SCALING_CAPABILITY_HORIZONTAL)
2479 sensor->minfo.smiapp_profile = SMIAPP_PROFILE_1;
2480 else
2481 sensor->minfo.smiapp_profile = SMIAPP_PROFILE_2;
2482 sensor->scaler = &sensor->ssds[sensor->ssds_used];
2483 sensor->ssds_used++;
2484 } else if (sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
2485 == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP) {
2486 sensor->scaler = &sensor->ssds[sensor->ssds_used];
2487 sensor->ssds_used++;
2488 }
2489 sensor->binner = &sensor->ssds[sensor->ssds_used];
2490 sensor->ssds_used++;
2491 sensor->pixel_array = &sensor->ssds[sensor->ssds_used];
2492 sensor->ssds_used++;
2493
2494 sensor->scale_m = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
2495
2496 for (i = 0; i < SMIAPP_SUBDEVS; i++) {
2497 struct {
2498 struct smiapp_subdev *ssd;
2499 char *name;
2500 } const __this[] = {
2501 { sensor->scaler, "scaler", },
2502 { sensor->binner, "binner", },
2503 { sensor->pixel_array, "pixel array", },
2504 }, *_this = &__this[i];
2505 struct smiapp_subdev *this = _this->ssd;
2506
2507 if (!this)
2508 continue;
2509
2510 if (this != sensor->src)
2511 v4l2_subdev_init(&this->sd, &smiapp_ops);
2512
2513 this->sensor = sensor;
2514
2515 if (this == sensor->pixel_array) {
2516 this->npads = 1;
2517 } else {
2518 this->npads = 2;
2519 this->source_pad = 1;
2520 }
2521
2522 snprintf(this->sd.name,
2523 sizeof(this->sd.name), "%s %s",
2524 sensor->minfo.name, _this->name);
2525
2526 this->sink_fmt.width =
2527 sensor->limits[SMIAPP_LIMIT_X_ADDR_MAX] + 1;
2528 this->sink_fmt.height =
2529 sensor->limits[SMIAPP_LIMIT_Y_ADDR_MAX] + 1;
2530 this->compose.width = this->sink_fmt.width;
2531 this->compose.height = this->sink_fmt.height;
2532 this->crop[this->source_pad] = this->compose;
2533 this->pads[this->source_pad].flags = MEDIA_PAD_FL_SOURCE;
2534 if (this != sensor->pixel_array) {
2535 this->crop[this->sink_pad] = this->compose;
2536 this->pads[this->sink_pad].flags = MEDIA_PAD_FL_SINK;
2537 }
2538
2539 this->sd.entity.ops = &smiapp_entity_ops;
2540
2541 if (last == NULL) {
2542 last = this;
2543 continue;
2544 }
2545
2546 this->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
2547 this->sd.internal_ops = &smiapp_internal_ops;
2548 this->sd.owner = NULL;
2549 v4l2_set_subdevdata(&this->sd, client);
2550
2551 rval = media_entity_init(&this->sd.entity,
2552 this->npads, this->pads, 0);
2553 if (rval) {
2554 dev_err(&client->dev,
2555 "media_entity_init failed\n");
2556 goto out_nvm_release;
2557 }
2558
2559 rval = media_entity_create_link(&this->sd.entity,
2560 this->source_pad,
2561 &last->sd.entity,
2562 last->sink_pad,
2563 MEDIA_LNK_FL_ENABLED |
2564 MEDIA_LNK_FL_IMMUTABLE);
2565 if (rval) {
2566 dev_err(&client->dev,
2567 "media_entity_create_link failed\n");
2568 goto out_nvm_release;
2569 }
2570
2571 rval = v4l2_device_register_subdev(sensor->src->sd.v4l2_dev,
2572 &this->sd);
2573 if (rval) {
2574 dev_err(&client->dev,
2575 "v4l2_device_register_subdev failed\n");
2576 goto out_nvm_release;
2577 }
2578
2579 last = this;
2580 }
2581
2582 dev_dbg(&client->dev, "profile %d\n", sensor->minfo.smiapp_profile);
2583
2584 sensor->pixel_array->sd.entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
2585
2586 /* final steps */
2587 smiapp_read_frame_fmt(sensor);
2588 rval = smiapp_init_controls(sensor);
2589 if (rval < 0)
2590 goto out_nvm_release;
2591
2592 rval = smiapp_update_mode(sensor);
2593 if (rval) {
2594 dev_err(&client->dev, "update mode failed\n");
2595 goto out_nvm_release;
2596 }
2597
2598 sensor->streaming = false;
2599 sensor->dev_init_done = true;
2600
2601 /* check flash capability */
1e73eea7 2602 rval = smiapp_read(sensor, SMIAPP_REG_U8_FLASH_MODE_CAPABILITY, &tmp);
ccfc97bd
SA
2603 sensor->flash_capability = tmp;
2604 if (rval)
2605 goto out_nvm_release;
2606
2607 smiapp_power_off(sensor);
2608
2609 return 0;
2610
2611out_nvm_release:
2612 device_remove_file(&client->dev, &dev_attr_nvm);
2613
2614out_power_off:
2615 kfree(sensor->nvm);
2616 sensor->nvm = NULL;
2617 smiapp_power_off(sensor);
2618
2619out_smiapp_power_on:
2620 if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
2621 gpio_free(sensor->platform_data->xshutdown);
2622
2547428d
SA
2623out_clk_set_rate:
2624 clk_put(sensor->ext_clk);
2625 sensor->ext_clk = NULL;
2626
2627out_clk_get:
ccfc97bd
SA
2628 regulator_put(sensor->vana);
2629 sensor->vana = NULL;
2630 return rval;
2631}
2632
2633static int smiapp_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
2634{
2635 struct smiapp_subdev *ssd = to_smiapp_subdev(sd);
2636 struct smiapp_sensor *sensor = ssd->sensor;
2637 u32 mbus_code =
2638 smiapp_csi_data_formats[smiapp_pixel_order(sensor)].code;
2639 unsigned int i;
2640
2641 mutex_lock(&sensor->mutex);
2642
2643 for (i = 0; i < ssd->npads; i++) {
2644 struct v4l2_mbus_framefmt *try_fmt =
2645 v4l2_subdev_get_try_format(fh, i);
2646 struct v4l2_rect *try_crop = v4l2_subdev_get_try_crop(fh, i);
2647 struct v4l2_rect *try_comp;
2648
2649 try_fmt->width = sensor->limits[SMIAPP_LIMIT_X_ADDR_MAX] + 1;
2650 try_fmt->height = sensor->limits[SMIAPP_LIMIT_Y_ADDR_MAX] + 1;
2651 try_fmt->code = mbus_code;
2652
2653 try_crop->top = 0;
2654 try_crop->left = 0;
2655 try_crop->width = try_fmt->width;
2656 try_crop->height = try_fmt->height;
2657
2658 if (ssd != sensor->pixel_array)
2659 continue;
2660
2661 try_comp = v4l2_subdev_get_try_compose(fh, i);
2662 *try_comp = *try_crop;
2663 }
2664
2665 mutex_unlock(&sensor->mutex);
2666
2667 return smiapp_set_power(sd, 1);
2668}
2669
2670static int smiapp_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
2671{
2672 return smiapp_set_power(sd, 0);
2673}
2674
2675static const struct v4l2_subdev_video_ops smiapp_video_ops = {
2676 .s_stream = smiapp_set_stream,
2677};
2678
2679static const struct v4l2_subdev_core_ops smiapp_core_ops = {
2680 .s_power = smiapp_set_power,
2681};
2682
2683static const struct v4l2_subdev_pad_ops smiapp_pad_ops = {
2684 .enum_mbus_code = smiapp_enum_mbus_code,
2685 .get_fmt = smiapp_get_format,
2686 .set_fmt = smiapp_set_format,
2687 .get_selection = smiapp_get_selection,
2688 .set_selection = smiapp_set_selection,
2689};
2690
2691static const struct v4l2_subdev_sensor_ops smiapp_sensor_ops = {
2692 .g_skip_frames = smiapp_get_skip_frames,
2693};
2694
2695static const struct v4l2_subdev_ops smiapp_ops = {
2696 .core = &smiapp_core_ops,
2697 .video = &smiapp_video_ops,
2698 .pad = &smiapp_pad_ops,
2699 .sensor = &smiapp_sensor_ops,
2700};
2701
2702static const struct media_entity_operations smiapp_entity_ops = {
2703 .link_validate = v4l2_subdev_link_validate,
2704};
2705
2706static const struct v4l2_subdev_internal_ops smiapp_internal_src_ops = {
2707 .registered = smiapp_registered,
2708 .open = smiapp_open,
2709 .close = smiapp_close,
2710};
2711
2712static const struct v4l2_subdev_internal_ops smiapp_internal_ops = {
2713 .open = smiapp_open,
2714 .close = smiapp_close,
2715};
2716
2717/* -----------------------------------------------------------------------------
2718 * I2C Driver
2719 */
2720
2721#ifdef CONFIG_PM
2722
2723static int smiapp_suspend(struct device *dev)
2724{
2725 struct i2c_client *client = to_i2c_client(dev);
2726 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
2727 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2728 bool streaming;
2729
2730 BUG_ON(mutex_is_locked(&sensor->mutex));
2731
2732 if (sensor->power_count == 0)
2733 return 0;
2734
2735 if (sensor->streaming)
2736 smiapp_stop_streaming(sensor);
2737
2738 streaming = sensor->streaming;
2739
2740 smiapp_power_off(sensor);
2741
2742 /* save state for resume */
2743 sensor->streaming = streaming;
2744
2745 return 0;
2746}
2747
2748static int smiapp_resume(struct device *dev)
2749{
2750 struct i2c_client *client = to_i2c_client(dev);
2751 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
2752 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2753 int rval;
2754
2755 if (sensor->power_count == 0)
2756 return 0;
2757
2758 rval = smiapp_power_on(sensor);
2759 if (rval)
2760 return rval;
2761
2762 if (sensor->streaming)
2763 rval = smiapp_start_streaming(sensor);
2764
2765 return rval;
2766}
2767
2768#else
2769
2770#define smiapp_suspend NULL
2771#define smiapp_resume NULL
2772
2773#endif /* CONFIG_PM */
2774
2775static int smiapp_probe(struct i2c_client *client,
2776 const struct i2c_device_id *devid)
2777{
2778 struct smiapp_sensor *sensor;
2779 int rval;
2780
2781 if (client->dev.platform_data == NULL)
2782 return -ENODEV;
2783
2784 sensor = kzalloc(sizeof(*sensor), GFP_KERNEL);
2785 if (sensor == NULL)
2786 return -ENOMEM;
2787
2788 sensor->platform_data = client->dev.platform_data;
2789 mutex_init(&sensor->mutex);
2790 mutex_init(&sensor->power_mutex);
2791 sensor->src = &sensor->ssds[sensor->ssds_used];
2792
2793 v4l2_i2c_subdev_init(&sensor->src->sd, client, &smiapp_ops);
2794 sensor->src->sd.internal_ops = &smiapp_internal_src_ops;
2795 sensor->src->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
2796 sensor->src->sensor = sensor;
2797
2798 sensor->src->pads[0].flags = MEDIA_PAD_FL_SOURCE;
2799 rval = media_entity_init(&sensor->src->sd.entity, 2,
2800 sensor->src->pads, 0);
2801 if (rval < 0)
2802 kfree(sensor);
2803
2804 return rval;
2805}
2806
2807static int __exit smiapp_remove(struct i2c_client *client)
2808{
2809 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
2810 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2811 unsigned int i;
2812
2813 if (sensor->power_count) {
2814 if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
2815 gpio_set_value(sensor->platform_data->xshutdown, 0);
2547428d
SA
2816 if (sensor->platform_data->set_xclk)
2817 sensor->platform_data->set_xclk(&sensor->src->sd, 0);
2818 else
2819 clk_disable(sensor->ext_clk);
ccfc97bd
SA
2820 sensor->power_count = 0;
2821 }
2822
2823 if (sensor->nvm) {
2824 device_remove_file(&client->dev, &dev_attr_nvm);
2825 kfree(sensor->nvm);
2826 }
2827
2828 for (i = 0; i < sensor->ssds_used; i++) {
2829 media_entity_cleanup(&sensor->ssds[i].sd.entity);
2830 v4l2_device_unregister_subdev(&sensor->ssds[i].sd);
2831 }
2832 smiapp_free_controls(sensor);
2833 if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
2834 gpio_free(sensor->platform_data->xshutdown);
2547428d
SA
2835 if (sensor->ext_clk)
2836 clk_put(sensor->ext_clk);
ccfc97bd
SA
2837 if (sensor->vana)
2838 regulator_put(sensor->vana);
2839
2840 kfree(sensor);
2841
2842 return 0;
2843}
2844
2845static const struct i2c_device_id smiapp_id_table[] = {
2846 { SMIAPP_NAME, 0 },
2847 { },
2848};
2849MODULE_DEVICE_TABLE(i2c, smiapp_id_table);
2850
2851static const struct dev_pm_ops smiapp_pm_ops = {
2852 .suspend = smiapp_suspend,
2853 .resume = smiapp_resume,
2854};
2855
2856static struct i2c_driver smiapp_i2c_driver = {
2857 .driver = {
2858 .name = SMIAPP_NAME,
2859 .pm = &smiapp_pm_ops,
2860 },
2861 .probe = smiapp_probe,
2862 .remove = __exit_p(smiapp_remove),
2863 .id_table = smiapp_id_table,
2864};
2865
2866module_i2c_driver(smiapp_i2c_driver);
2867
2868MODULE_AUTHOR("Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>");
2869MODULE_DESCRIPTION("Generic SMIA/SMIA++ camera module driver");
2870MODULE_LICENSE("GPL");
This page took 0.180677 seconds and 5 git commands to generate.