2 * drivers/media/i2c/smiapp/smiapp-core.c
4 * Generic driver for SMIA/SMIA++ compliant camera modules
6 * Copyright (C) 2010--2012 Nokia Corporation
7 * Contact: Sakari Ailus <sakari.ailus@iki.fi>
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>
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.
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.
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
29 #include <linux/clk.h>
30 #include <linux/delay.h>
31 #include <linux/device.h>
32 #include <linux/gpio.h>
33 #include <linux/module.h>
34 #include <linux/slab.h>
35 #include <linux/regulator/consumer.h>
36 #include <linux/v4l2-mediabus.h>
37 #include <media/v4l2-device.h>
41 #define SMIAPP_ALIGN_DIM(dim, flags) \
42 ((flags) & V4L2_SEL_FLAG_GE \
47 * smiapp_module_idents - supported camera modules
49 static const struct smiapp_module_ident smiapp_module_idents[] = {
50 SMIAPP_IDENT_L(0x01, 0x022b, -1, "vs6555"),
51 SMIAPP_IDENT_L(0x01, 0x022e, -1, "vw6558"),
52 SMIAPP_IDENT_L(0x07, 0x7698, -1, "ovm7698"),
53 SMIAPP_IDENT_L(0x0b, 0x4242, -1, "smiapp-003"),
54 SMIAPP_IDENT_L(0x0c, 0x208a, -1, "tcm8330md"),
55 SMIAPP_IDENT_LQ(0x0c, 0x2134, -1, "tcm8500md", &smiapp_tcm8500md_quirk),
56 SMIAPP_IDENT_L(0x0c, 0x213e, -1, "et8en2"),
57 SMIAPP_IDENT_L(0x0c, 0x2184, -1, "tcm8580md"),
58 SMIAPP_IDENT_LQ(0x0c, 0x560f, -1, "jt8ew9", &smiapp_jt8ew9_quirk),
59 SMIAPP_IDENT_LQ(0x10, 0x4141, -1, "jt8ev1", &smiapp_jt8ev1_quirk),
60 SMIAPP_IDENT_LQ(0x10, 0x4241, -1, "imx125es", &smiapp_imx125es_quirk),
65 * Dynamic Capability Identification
69 static int smiapp_read_frame_fmt(struct smiapp_sensor *sensor)
71 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
72 u32 fmt_model_type, fmt_model_subtype, ncol_desc, nrow_desc;
76 int embedded_start = -1, embedded_end = -1;
79 rval = smiapp_read(sensor, SMIAPP_REG_U8_FRAME_FORMAT_MODEL_TYPE,
84 rval = smiapp_read(sensor, SMIAPP_REG_U8_FRAME_FORMAT_MODEL_SUBTYPE,
89 ncol_desc = (fmt_model_subtype
90 & SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_MASK)
91 >> SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_SHIFT;
92 nrow_desc = fmt_model_subtype
93 & SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NROWS_MASK;
95 dev_dbg(&client->dev, "format_model_type %s\n",
96 fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE
98 fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE
99 ? "4 byte" : "is simply bad");
101 for (i = 0; i < ncol_desc + nrow_desc; i++) {
108 if (fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE) {
111 SMIAPP_REG_U16_FRAME_FORMAT_DESCRIPTOR_2(i),
118 & SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_MASK)
119 >> SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_SHIFT;
120 pixels = desc & SMIAPP_FRAME_FORMAT_DESC_2_PIXELS_MASK;
121 } else if (fmt_model_type
122 == SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE) {
125 SMIAPP_REG_U32_FRAME_FORMAT_DESCRIPTOR_4(i),
132 & SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_MASK)
133 >> SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_SHIFT;
134 pixels = desc & SMIAPP_FRAME_FORMAT_DESC_4_PIXELS_MASK;
136 dev_dbg(&client->dev,
137 "invalid frame format model type %d\n",
148 case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED:
151 case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DUMMY:
154 case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_BLACK:
157 case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DARK:
160 case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE:
165 dev_dbg(&client->dev, "pixelcode %d\n", pixelcode);
169 dev_dbg(&client->dev, "%s pixels: %d %s\n",
170 what, pixels, which);
175 /* Handle row descriptors */
177 == SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED) {
178 embedded_start = line_count;
180 if (pixelcode == SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE
181 || pixels >= sensor->limits[SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES] / 2)
182 image_start = line_count;
183 if (embedded_start != -1 && embedded_end == -1)
184 embedded_end = line_count;
186 line_count += pixels;
189 if (embedded_start == -1 || embedded_end == -1) {
194 dev_dbg(&client->dev, "embedded data from lines %d to %d\n",
195 embedded_start, embedded_end);
196 dev_dbg(&client->dev, "image data starts at line %d\n", image_start);
201 static int smiapp_pll_configure(struct smiapp_sensor *sensor)
203 struct smiapp_pll *pll = &sensor->pll;
207 sensor, SMIAPP_REG_U16_VT_PIX_CLK_DIV, pll->vt_pix_clk_div);
212 sensor, SMIAPP_REG_U16_VT_SYS_CLK_DIV, pll->vt_sys_clk_div);
217 sensor, SMIAPP_REG_U16_PRE_PLL_CLK_DIV, pll->pre_pll_clk_div);
222 sensor, SMIAPP_REG_U16_PLL_MULTIPLIER, pll->pll_multiplier);
226 /* Lane op clock ratio does not apply here. */
228 sensor, SMIAPP_REG_U32_REQUESTED_LINK_BIT_RATE_MBPS,
229 DIV_ROUND_UP(pll->op_sys_clk_freq_hz, 1000000 / 256 / 256));
230 if (rval < 0 || sensor->minfo.smiapp_profile == SMIAPP_PROFILE_0)
234 sensor, SMIAPP_REG_U16_OP_PIX_CLK_DIV, pll->op_pix_clk_div);
239 sensor, SMIAPP_REG_U16_OP_SYS_CLK_DIV, pll->op_sys_clk_div);
242 static int smiapp_pll_update(struct smiapp_sensor *sensor)
244 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
245 struct smiapp_pll_limits lim = {
246 .min_pre_pll_clk_div = sensor->limits[SMIAPP_LIMIT_MIN_PRE_PLL_CLK_DIV],
247 .max_pre_pll_clk_div = sensor->limits[SMIAPP_LIMIT_MAX_PRE_PLL_CLK_DIV],
248 .min_pll_ip_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_PLL_IP_FREQ_HZ],
249 .max_pll_ip_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_PLL_IP_FREQ_HZ],
250 .min_pll_multiplier = sensor->limits[SMIAPP_LIMIT_MIN_PLL_MULTIPLIER],
251 .max_pll_multiplier = sensor->limits[SMIAPP_LIMIT_MAX_PLL_MULTIPLIER],
252 .min_pll_op_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_PLL_OP_FREQ_HZ],
253 .max_pll_op_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_PLL_OP_FREQ_HZ],
255 .op.min_sys_clk_div = sensor->limits[SMIAPP_LIMIT_MIN_OP_SYS_CLK_DIV],
256 .op.max_sys_clk_div = sensor->limits[SMIAPP_LIMIT_MAX_OP_SYS_CLK_DIV],
257 .op.min_pix_clk_div = sensor->limits[SMIAPP_LIMIT_MIN_OP_PIX_CLK_DIV],
258 .op.max_pix_clk_div = sensor->limits[SMIAPP_LIMIT_MAX_OP_PIX_CLK_DIV],
259 .op.min_sys_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_OP_SYS_CLK_FREQ_HZ],
260 .op.max_sys_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_OP_SYS_CLK_FREQ_HZ],
261 .op.min_pix_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_OP_PIX_CLK_FREQ_HZ],
262 .op.max_pix_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_OP_PIX_CLK_FREQ_HZ],
264 .vt.min_sys_clk_div = sensor->limits[SMIAPP_LIMIT_MIN_VT_SYS_CLK_DIV],
265 .vt.max_sys_clk_div = sensor->limits[SMIAPP_LIMIT_MAX_VT_SYS_CLK_DIV],
266 .vt.min_pix_clk_div = sensor->limits[SMIAPP_LIMIT_MIN_VT_PIX_CLK_DIV],
267 .vt.max_pix_clk_div = sensor->limits[SMIAPP_LIMIT_MAX_VT_PIX_CLK_DIV],
268 .vt.min_sys_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_VT_SYS_CLK_FREQ_HZ],
269 .vt.max_sys_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_VT_SYS_CLK_FREQ_HZ],
270 .vt.min_pix_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MIN_VT_PIX_CLK_FREQ_HZ],
271 .vt.max_pix_clk_freq_hz = sensor->limits[SMIAPP_LIMIT_MAX_VT_PIX_CLK_FREQ_HZ],
273 .min_line_length_pck_bin = sensor->limits[SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN],
274 .min_line_length_pck = sensor->limits[SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK],
276 struct smiapp_pll *pll = &sensor->pll;
279 if (sensor->minfo.smiapp_profile == SMIAPP_PROFILE_0) {
281 * Fill in operational clock divisors limits from the
282 * video timing ones. On profile 0 sensors the
283 * requirements regarding them are essentially the
284 * same as on VT ones.
289 pll->binning_horizontal = sensor->binning_horizontal;
290 pll->binning_vertical = sensor->binning_vertical;
292 sensor->link_freq->qmenu_int[sensor->link_freq->val];
293 pll->scale_m = sensor->scale_m;
294 pll->bits_per_pixel = sensor->csi_format->compressed;
296 rval = smiapp_pll_calculate(&client->dev, &lim, pll);
300 *sensor->pixel_rate_parray->p_cur.p_s64 = pll->vt_pix_clk_freq_hz;
301 *sensor->pixel_rate_csi->p_cur.p_s64 = pll->pixel_rate_csi;
309 * V4L2 Controls handling
313 static void __smiapp_update_exposure_limits(struct smiapp_sensor *sensor)
315 struct v4l2_ctrl *ctrl = sensor->exposure;
318 max = sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height
319 + sensor->vblank->val
320 - sensor->limits[SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MAX_MARGIN];
323 if (ctrl->default_value > max)
324 ctrl->default_value = max;
327 if (ctrl->cur.val > max)
334 * 1. Bits-per-pixel, descending.
335 * 2. Bits-per-pixel compressed, descending.
336 * 3. Pixel order, same as in pixel_order_str. Formats for all four pixel
337 * orders must be defined.
339 static const struct smiapp_csi_data_format smiapp_csi_data_formats[] = {
340 { V4L2_MBUS_FMT_SGRBG12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_GRBG, },
341 { V4L2_MBUS_FMT_SRGGB12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_RGGB, },
342 { V4L2_MBUS_FMT_SBGGR12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_BGGR, },
343 { V4L2_MBUS_FMT_SGBRG12_1X12, 12, 12, SMIAPP_PIXEL_ORDER_GBRG, },
344 { V4L2_MBUS_FMT_SGRBG10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_GRBG, },
345 { V4L2_MBUS_FMT_SRGGB10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_RGGB, },
346 { V4L2_MBUS_FMT_SBGGR10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_BGGR, },
347 { V4L2_MBUS_FMT_SGBRG10_1X10, 10, 10, SMIAPP_PIXEL_ORDER_GBRG, },
348 { V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_GRBG, },
349 { V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_RGGB, },
350 { V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_BGGR, },
351 { V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_GBRG, },
352 { V4L2_MBUS_FMT_SGRBG8_1X8, 8, 8, SMIAPP_PIXEL_ORDER_GRBG, },
353 { V4L2_MBUS_FMT_SRGGB8_1X8, 8, 8, SMIAPP_PIXEL_ORDER_RGGB, },
354 { V4L2_MBUS_FMT_SBGGR8_1X8, 8, 8, SMIAPP_PIXEL_ORDER_BGGR, },
355 { V4L2_MBUS_FMT_SGBRG8_1X8, 8, 8, SMIAPP_PIXEL_ORDER_GBRG, },
358 const char *pixel_order_str[] = { "GRBG", "RGGB", "BGGR", "GBRG" };
360 #define to_csi_format_idx(fmt) (((unsigned long)(fmt) \
361 - (unsigned long)smiapp_csi_data_formats) \
362 / sizeof(*smiapp_csi_data_formats))
364 static u32 smiapp_pixel_order(struct smiapp_sensor *sensor)
366 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
370 if (sensor->hflip->val)
371 flip |= SMIAPP_IMAGE_ORIENTATION_HFLIP;
373 if (sensor->vflip->val)
374 flip |= SMIAPP_IMAGE_ORIENTATION_VFLIP;
377 flip ^= sensor->hvflip_inv_mask;
379 dev_dbg(&client->dev, "flip %d\n", flip);
380 return sensor->default_pixel_order ^ flip;
383 static void smiapp_update_mbus_formats(struct smiapp_sensor *sensor)
385 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
386 unsigned int csi_format_idx =
387 to_csi_format_idx(sensor->csi_format) & ~3;
388 unsigned int internal_csi_format_idx =
389 to_csi_format_idx(sensor->internal_csi_format) & ~3;
390 unsigned int pixel_order = smiapp_pixel_order(sensor);
392 sensor->mbus_frame_fmts =
393 sensor->default_mbus_frame_fmts << pixel_order;
395 &smiapp_csi_data_formats[csi_format_idx + pixel_order];
396 sensor->internal_csi_format =
397 &smiapp_csi_data_formats[internal_csi_format_idx
400 BUG_ON(max(internal_csi_format_idx, csi_format_idx) + pixel_order
401 >= ARRAY_SIZE(smiapp_csi_data_formats));
403 dev_dbg(&client->dev, "new pixel order %s\n",
404 pixel_order_str[pixel_order]);
407 static int smiapp_set_ctrl(struct v4l2_ctrl *ctrl)
409 struct smiapp_sensor *sensor =
410 container_of(ctrl->handler, struct smiapp_subdev, ctrl_handler)
417 case V4L2_CID_ANALOGUE_GAIN:
420 SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_GLOBAL, ctrl->val);
422 case V4L2_CID_EXPOSURE:
425 SMIAPP_REG_U16_COARSE_INTEGRATION_TIME, ctrl->val);
429 if (sensor->streaming)
432 if (sensor->hflip->val)
433 orient |= SMIAPP_IMAGE_ORIENTATION_HFLIP;
435 if (sensor->vflip->val)
436 orient |= SMIAPP_IMAGE_ORIENTATION_VFLIP;
438 orient ^= sensor->hvflip_inv_mask;
439 rval = smiapp_write(sensor,
440 SMIAPP_REG_U8_IMAGE_ORIENTATION,
445 smiapp_update_mbus_formats(sensor);
449 case V4L2_CID_VBLANK:
450 exposure = sensor->exposure->val;
452 __smiapp_update_exposure_limits(sensor);
454 if (exposure > sensor->exposure->maximum) {
455 sensor->exposure->val =
456 sensor->exposure->maximum;
457 rval = smiapp_set_ctrl(
464 sensor, SMIAPP_REG_U16_FRAME_LENGTH_LINES,
465 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height
468 case V4L2_CID_HBLANK:
470 sensor, SMIAPP_REG_U16_LINE_LENGTH_PCK,
471 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].width
474 case V4L2_CID_LINK_FREQ:
475 if (sensor->streaming)
478 return smiapp_pll_update(sensor);
485 static const struct v4l2_ctrl_ops smiapp_ctrl_ops = {
486 .s_ctrl = smiapp_set_ctrl,
489 static int smiapp_init_controls(struct smiapp_sensor *sensor)
491 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
495 rval = v4l2_ctrl_handler_init(&sensor->pixel_array->ctrl_handler, 7);
498 sensor->pixel_array->ctrl_handler.lock = &sensor->mutex;
500 sensor->analog_gain = v4l2_ctrl_new_std(
501 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
502 V4L2_CID_ANALOGUE_GAIN,
503 sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN],
504 sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MAX],
505 max(sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_STEP], 1U),
506 sensor->limits[SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN]);
508 /* Exposure limits will be updated soon, use just something here. */
509 sensor->exposure = v4l2_ctrl_new_std(
510 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
511 V4L2_CID_EXPOSURE, 0, 0, 1, 0);
513 sensor->hflip = v4l2_ctrl_new_std(
514 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
515 V4L2_CID_HFLIP, 0, 1, 1, 0);
516 sensor->vflip = v4l2_ctrl_new_std(
517 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
518 V4L2_CID_VFLIP, 0, 1, 1, 0);
520 sensor->vblank = v4l2_ctrl_new_std(
521 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
522 V4L2_CID_VBLANK, 0, 1, 1, 0);
525 sensor->vblank->flags |= V4L2_CTRL_FLAG_UPDATE;
527 sensor->hblank = v4l2_ctrl_new_std(
528 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
529 V4L2_CID_HBLANK, 0, 1, 1, 0);
532 sensor->hblank->flags |= V4L2_CTRL_FLAG_UPDATE;
534 sensor->pixel_rate_parray = v4l2_ctrl_new_std(
535 &sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
536 V4L2_CID_PIXEL_RATE, 1, INT_MAX, 1, 1);
538 if (sensor->pixel_array->ctrl_handler.error) {
539 dev_err(&client->dev,
540 "pixel array controls initialization failed (%d)\n",
541 sensor->pixel_array->ctrl_handler.error);
542 rval = sensor->pixel_array->ctrl_handler.error;
546 sensor->pixel_array->sd.ctrl_handler =
547 &sensor->pixel_array->ctrl_handler;
549 v4l2_ctrl_cluster(2, &sensor->hflip);
551 rval = v4l2_ctrl_handler_init(&sensor->src->ctrl_handler, 0);
554 sensor->src->ctrl_handler.lock = &sensor->mutex;
556 for (max = 0; sensor->platform_data->op_sys_clock[max + 1]; max++);
558 sensor->link_freq = v4l2_ctrl_new_int_menu(
559 &sensor->src->ctrl_handler, &smiapp_ctrl_ops,
560 V4L2_CID_LINK_FREQ, max, 0,
561 sensor->platform_data->op_sys_clock);
563 sensor->pixel_rate_csi = v4l2_ctrl_new_std(
564 &sensor->src->ctrl_handler, &smiapp_ctrl_ops,
565 V4L2_CID_PIXEL_RATE, 1, INT_MAX, 1, 1);
567 if (sensor->src->ctrl_handler.error) {
568 dev_err(&client->dev,
569 "src controls initialization failed (%d)\n",
570 sensor->src->ctrl_handler.error);
571 rval = sensor->src->ctrl_handler.error;
575 sensor->src->sd.ctrl_handler =
576 &sensor->src->ctrl_handler;
581 v4l2_ctrl_handler_free(&sensor->pixel_array->ctrl_handler);
582 v4l2_ctrl_handler_free(&sensor->src->ctrl_handler);
587 static void smiapp_free_controls(struct smiapp_sensor *sensor)
591 for (i = 0; i < sensor->ssds_used; i++)
592 v4l2_ctrl_handler_free(&sensor->ssds[i].ctrl_handler);
595 static int smiapp_get_limits(struct smiapp_sensor *sensor, int const *limit,
598 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
603 for (i = 0; i < n; i++) {
605 sensor, smiapp_reg_limits[limit[i]].addr, &val);
608 sensor->limits[limit[i]] = val;
609 dev_dbg(&client->dev, "0x%8.8x \"%s\" = %u, 0x%x\n",
610 smiapp_reg_limits[limit[i]].addr,
611 smiapp_reg_limits[limit[i]].what, val, val);
617 static int smiapp_get_all_limits(struct smiapp_sensor *sensor)
622 for (i = 0; i < SMIAPP_LIMIT_LAST; i++) {
623 rval = smiapp_get_limits(sensor, &i, 1);
628 if (sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN] == 0)
629 smiapp_replace_limit(sensor, SMIAPP_LIMIT_SCALER_N_MIN, 16);
634 static int smiapp_get_limits_binning(struct smiapp_sensor *sensor)
636 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
637 static u32 const limits[] = {
638 SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN,
639 SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES_BIN,
640 SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN,
641 SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK_BIN,
642 SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN,
643 SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN_BIN,
644 SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN_BIN,
646 static u32 const limits_replace[] = {
647 SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES,
648 SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES,
649 SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK,
650 SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK,
651 SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK,
652 SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN,
653 SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN,
658 if (sensor->limits[SMIAPP_LIMIT_BINNING_CAPABILITY] ==
659 SMIAPP_BINNING_CAPABILITY_NO) {
660 for (i = 0; i < ARRAY_SIZE(limits); i++)
661 sensor->limits[limits[i]] =
662 sensor->limits[limits_replace[i]];
667 rval = smiapp_get_limits(sensor, limits, ARRAY_SIZE(limits));
672 * Sanity check whether the binning limits are valid. If not,
673 * use the non-binning ones.
675 if (sensor->limits[SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN]
676 && sensor->limits[SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN]
677 && sensor->limits[SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN])
680 for (i = 0; i < ARRAY_SIZE(limits); i++) {
681 dev_dbg(&client->dev,
682 "replace limit 0x%8.8x \"%s\" = %d, 0x%x\n",
683 smiapp_reg_limits[limits[i]].addr,
684 smiapp_reg_limits[limits[i]].what,
685 sensor->limits[limits_replace[i]],
686 sensor->limits[limits_replace[i]]);
687 sensor->limits[limits[i]] =
688 sensor->limits[limits_replace[i]];
694 static int smiapp_get_mbus_formats(struct smiapp_sensor *sensor)
696 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
697 unsigned int type, n;
698 unsigned int i, pixel_order;
702 sensor, SMIAPP_REG_U8_DATA_FORMAT_MODEL_TYPE, &type);
706 dev_dbg(&client->dev, "data_format_model_type %d\n", type);
708 rval = smiapp_read(sensor, SMIAPP_REG_U8_PIXEL_ORDER,
713 if (pixel_order >= ARRAY_SIZE(pixel_order_str)) {
714 dev_dbg(&client->dev, "bad pixel order %d\n", pixel_order);
718 dev_dbg(&client->dev, "pixel order %d (%s)\n", pixel_order,
719 pixel_order_str[pixel_order]);
722 case SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL:
723 n = SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL_N;
725 case SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED:
726 n = SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED_N;
732 sensor->default_pixel_order = pixel_order;
733 sensor->mbus_frame_fmts = 0;
735 for (i = 0; i < n; i++) {
740 SMIAPP_REG_U16_DATA_FORMAT_DESCRIPTOR(i), &fmt);
744 dev_dbg(&client->dev, "%u: bpp %u, compressed %u\n",
745 i, fmt >> 8, (u8)fmt);
747 for (j = 0; j < ARRAY_SIZE(smiapp_csi_data_formats); j++) {
748 const struct smiapp_csi_data_format *f =
749 &smiapp_csi_data_formats[j];
751 if (f->pixel_order != SMIAPP_PIXEL_ORDER_GRBG)
754 if (f->width != fmt >> 8 || f->compressed != (u8)fmt)
757 dev_dbg(&client->dev, "jolly good! %d\n", j);
759 sensor->default_mbus_frame_fmts |= 1 << j;
760 if (!sensor->csi_format
761 || f->width > sensor->csi_format->width
762 || (f->width == sensor->csi_format->width
764 > sensor->csi_format->compressed)) {
765 sensor->csi_format = f;
766 sensor->internal_csi_format = f;
771 if (!sensor->csi_format) {
772 dev_err(&client->dev, "no supported mbus code found\n");
776 smiapp_update_mbus_formats(sensor);
781 static void smiapp_update_blanking(struct smiapp_sensor *sensor)
783 struct v4l2_ctrl *vblank = sensor->vblank;
784 struct v4l2_ctrl *hblank = sensor->hblank;
788 sensor->limits[SMIAPP_LIMIT_MIN_FRAME_BLANKING_LINES],
789 sensor->limits[SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN] -
790 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height);
792 sensor->limits[SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES_BIN] -
793 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height;
795 vblank->val = clamp_t(int, vblank->val,
796 vblank->minimum, vblank->maximum);
797 vblank->default_value = vblank->minimum;
798 vblank->val = vblank->val;
799 vblank->cur.val = vblank->val;
803 sensor->limits[SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN] -
804 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].width,
805 sensor->limits[SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN]);
807 sensor->limits[SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK_BIN] -
808 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].width;
810 hblank->val = clamp_t(int, hblank->val,
811 hblank->minimum, hblank->maximum);
812 hblank->default_value = hblank->minimum;
813 hblank->val = hblank->val;
814 hblank->cur.val = hblank->val;
816 __smiapp_update_exposure_limits(sensor);
819 static int smiapp_update_mode(struct smiapp_sensor *sensor)
821 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
822 unsigned int binning_mode;
825 dev_dbg(&client->dev, "frame size: %dx%d\n",
826 sensor->src->crop[SMIAPP_PAD_SRC].width,
827 sensor->src->crop[SMIAPP_PAD_SRC].height);
828 dev_dbg(&client->dev, "csi format width: %d\n",
829 sensor->csi_format->width);
831 /* Binning has to be set up here; it affects limits */
832 if (sensor->binning_horizontal == 1 &&
833 sensor->binning_vertical == 1) {
837 (sensor->binning_horizontal << 4)
838 | sensor->binning_vertical;
841 sensor, SMIAPP_REG_U8_BINNING_TYPE, binning_type);
847 rval = smiapp_write(sensor, SMIAPP_REG_U8_BINNING_MODE, binning_mode);
851 /* Get updated limits due to binning */
852 rval = smiapp_get_limits_binning(sensor);
856 rval = smiapp_pll_update(sensor);
860 /* Output from pixel array, including blanking */
861 smiapp_update_blanking(sensor);
863 dev_dbg(&client->dev, "vblank\t\t%d\n", sensor->vblank->val);
864 dev_dbg(&client->dev, "hblank\t\t%d\n", sensor->hblank->val);
866 dev_dbg(&client->dev, "real timeperframe\t100/%d\n",
867 sensor->pll.vt_pix_clk_freq_hz /
868 ((sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].width
869 + sensor->hblank->val) *
870 (sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height
871 + sensor->vblank->val) / 100));
878 * SMIA++ NVM handling
881 static int smiapp_read_nvm(struct smiapp_sensor *sensor,
887 np = sensor->nvm_size / SMIAPP_NVM_PAGE_SIZE;
888 for (p = 0; p < np; p++) {
891 SMIAPP_REG_U8_DATA_TRANSFER_IF_1_PAGE_SELECT, p);
895 rval = smiapp_write(sensor,
896 SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL,
897 SMIAPP_DATA_TRANSFER_IF_1_CTRL_EN |
898 SMIAPP_DATA_TRANSFER_IF_1_CTRL_RD_EN);
902 for (i = 0; i < 1000; i++) {
905 SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS, &s);
910 if (s & SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY)
920 for (i = 0; i < SMIAPP_NVM_PAGE_SIZE; i++) {
923 SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_0 + i,
933 rval2 = smiapp_write(sensor, SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL, 0);
942 * SMIA++ CCI address control
945 static int smiapp_change_cci_addr(struct smiapp_sensor *sensor)
947 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
951 client->addr = sensor->platform_data->i2c_addr_dfl;
953 rval = smiapp_write(sensor,
954 SMIAPP_REG_U8_CCI_ADDRESS_CONTROL,
955 sensor->platform_data->i2c_addr_alt << 1);
959 client->addr = sensor->platform_data->i2c_addr_alt;
961 /* verify addr change went ok */
962 rval = smiapp_read(sensor, SMIAPP_REG_U8_CCI_ADDRESS_CONTROL, &val);
966 if (val != sensor->platform_data->i2c_addr_alt << 1)
974 * SMIA++ Mode Control
977 static int smiapp_setup_flash_strobe(struct smiapp_sensor *sensor)
979 struct smiapp_flash_strobe_parms *strobe_setup;
980 unsigned int ext_freq = sensor->platform_data->ext_clk;
982 u32 strobe_adjustment;
983 u32 strobe_width_high_rs;
986 strobe_setup = sensor->platform_data->strobe_setup;
989 * How to calculate registers related to strobe length. Please
990 * do not change, or if you do at least know what you're
993 * Sakari Ailus <sakari.ailus@iki.fi> 2010-10-25
995 * flash_strobe_length [us] / 10^6 = (tFlash_strobe_width_ctrl
996 * / EXTCLK freq [Hz]) * flash_strobe_adjustment
998 * tFlash_strobe_width_ctrl E N, [1 - 0xffff]
999 * flash_strobe_adjustment E N, [1 - 0xff]
1001 * The formula above is written as below to keep it on one
1004 * l / 10^6 = w / e * a
1006 * Let's mark w * a by x:
1014 * The strobe width must be at least as long as requested,
1015 * thus rounding upwards is needed.
1017 * x = (l * e + 10^6 - 1) / 10^6
1018 * -----------------------------
1020 * Maximum possible accuracy is wanted at all times. Thus keep
1021 * a as small as possible.
1023 * Calculate a, assuming maximum w, with rounding upwards:
1025 * a = (x + (2^16 - 1) - 1) / (2^16 - 1)
1026 * -------------------------------------
1028 * Thus, we also get w, with that a, with rounding upwards:
1030 * w = (x + a - 1) / a
1031 * -------------------
1035 * x E [1, (2^16 - 1) * (2^8 - 1)]
1037 * Substituting maximum x to the original formula (with rounding),
1038 * the maximum l is thus
1040 * (2^16 - 1) * (2^8 - 1) * 10^6 = l * e + 10^6 - 1
1042 * l = (10^6 * (2^16 - 1) * (2^8 - 1) - 10^6 + 1) / e
1043 * --------------------------------------------------
1045 * flash_strobe_length must be clamped between 1 and
1046 * (10^6 * (2^16 - 1) * (2^8 - 1) - 10^6 + 1) / EXTCLK freq.
1050 * flash_strobe_adjustment = ((flash_strobe_length *
1051 * EXTCLK freq + 10^6 - 1) / 10^6 + (2^16 - 1) - 1) / (2^16 - 1)
1053 * tFlash_strobe_width_ctrl = ((flash_strobe_length *
1054 * EXTCLK freq + 10^6 - 1) / 10^6 +
1055 * flash_strobe_adjustment - 1) / flash_strobe_adjustment
1057 tmp = div_u64(1000000ULL * ((1 << 16) - 1) * ((1 << 8) - 1) -
1058 1000000 + 1, ext_freq);
1059 strobe_setup->strobe_width_high_us =
1060 clamp_t(u32, strobe_setup->strobe_width_high_us, 1, tmp);
1062 tmp = div_u64(((u64)strobe_setup->strobe_width_high_us * (u64)ext_freq +
1063 1000000 - 1), 1000000ULL);
1064 strobe_adjustment = (tmp + (1 << 16) - 1 - 1) / ((1 << 16) - 1);
1065 strobe_width_high_rs = (tmp + strobe_adjustment - 1) /
1068 rval = smiapp_write(sensor, SMIAPP_REG_U8_FLASH_MODE_RS,
1069 strobe_setup->mode);
1073 rval = smiapp_write(sensor, SMIAPP_REG_U8_FLASH_STROBE_ADJUSTMENT,
1078 rval = smiapp_write(
1079 sensor, SMIAPP_REG_U16_TFLASH_STROBE_WIDTH_HIGH_RS_CTRL,
1080 strobe_width_high_rs);
1084 rval = smiapp_write(sensor, SMIAPP_REG_U16_TFLASH_STROBE_DELAY_RS_CTRL,
1085 strobe_setup->strobe_delay);
1089 rval = smiapp_write(sensor, SMIAPP_REG_U16_FLASH_STROBE_START_POINT,
1090 strobe_setup->stobe_start_point);
1094 rval = smiapp_write(sensor, SMIAPP_REG_U8_FLASH_TRIGGER_RS,
1095 strobe_setup->trigger);
1098 sensor->platform_data->strobe_setup->trigger = 0;
1103 /* -----------------------------------------------------------------------------
1107 static int smiapp_power_on(struct smiapp_sensor *sensor)
1109 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
1113 rval = regulator_enable(sensor->vana);
1115 dev_err(&client->dev, "failed to enable vana regulator\n");
1118 usleep_range(1000, 1000);
1120 if (sensor->platform_data->set_xclk)
1121 rval = sensor->platform_data->set_xclk(
1122 &sensor->src->sd, sensor->platform_data->ext_clk);
1124 rval = clk_prepare_enable(sensor->ext_clk);
1126 dev_dbg(&client->dev, "failed to enable xclk\n");
1129 usleep_range(1000, 1000);
1131 if (gpio_is_valid(sensor->platform_data->xshutdown))
1132 gpio_set_value(sensor->platform_data->xshutdown, 1);
1134 sleep = SMIAPP_RESET_DELAY(sensor->platform_data->ext_clk);
1135 usleep_range(sleep, sleep);
1138 * Failures to respond to the address change command have been noticed.
1139 * Those failures seem to be caused by the sensor requiring a longer
1140 * boot time than advertised. An additional 10ms delay seems to work
1141 * around the issue, but the SMIA++ I2C write retry hack makes the delay
1142 * unnecessary. The failures need to be investigated to find a proper
1143 * fix, and a delay will likely need to be added here if the I2C write
1144 * retry hack is reverted before the root cause of the boot time issue
1148 if (sensor->platform_data->i2c_addr_alt) {
1149 rval = smiapp_change_cci_addr(sensor);
1151 dev_err(&client->dev, "cci address change error\n");
1152 goto out_cci_addr_fail;
1156 rval = smiapp_write(sensor, SMIAPP_REG_U8_SOFTWARE_RESET,
1157 SMIAPP_SOFTWARE_RESET);
1159 dev_err(&client->dev, "software reset failed\n");
1160 goto out_cci_addr_fail;
1163 if (sensor->platform_data->i2c_addr_alt) {
1164 rval = smiapp_change_cci_addr(sensor);
1166 dev_err(&client->dev, "cci address change error\n");
1167 goto out_cci_addr_fail;
1171 rval = smiapp_write(sensor, SMIAPP_REG_U16_COMPRESSION_MODE,
1172 SMIAPP_COMPRESSION_MODE_SIMPLE_PREDICTOR);
1174 dev_err(&client->dev, "compression mode set failed\n");
1175 goto out_cci_addr_fail;
1178 rval = smiapp_write(
1179 sensor, SMIAPP_REG_U16_EXTCLK_FREQUENCY_MHZ,
1180 sensor->platform_data->ext_clk / (1000000 / (1 << 8)));
1182 dev_err(&client->dev, "extclk frequency set failed\n");
1183 goto out_cci_addr_fail;
1186 rval = smiapp_write(sensor, SMIAPP_REG_U8_CSI_LANE_MODE,
1187 sensor->platform_data->lanes - 1);
1189 dev_err(&client->dev, "csi lane mode set failed\n");
1190 goto out_cci_addr_fail;
1193 rval = smiapp_write(sensor, SMIAPP_REG_U8_FAST_STANDBY_CTRL,
1194 SMIAPP_FAST_STANDBY_CTRL_IMMEDIATE);
1196 dev_err(&client->dev, "fast standby set failed\n");
1197 goto out_cci_addr_fail;
1200 rval = smiapp_write(sensor, SMIAPP_REG_U8_CSI_SIGNALLING_MODE,
1201 sensor->platform_data->csi_signalling_mode);
1203 dev_err(&client->dev, "csi signalling mode set failed\n");
1204 goto out_cci_addr_fail;
1207 /* DPHY control done by sensor based on requested link rate */
1208 rval = smiapp_write(sensor, SMIAPP_REG_U8_DPHY_CTRL,
1209 SMIAPP_DPHY_CTRL_UI);
1213 rval = smiapp_call_quirk(sensor, post_poweron);
1215 dev_err(&client->dev, "post_poweron quirks failed\n");
1216 goto out_cci_addr_fail;
1219 /* Are we still initialising...? If yes, return here. */
1220 if (!sensor->pixel_array)
1223 rval = v4l2_ctrl_handler_setup(
1224 &sensor->pixel_array->ctrl_handler);
1226 goto out_cci_addr_fail;
1228 rval = v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
1230 goto out_cci_addr_fail;
1232 mutex_lock(&sensor->mutex);
1233 rval = smiapp_update_mode(sensor);
1234 mutex_unlock(&sensor->mutex);
1236 goto out_cci_addr_fail;
1241 if (gpio_is_valid(sensor->platform_data->xshutdown))
1242 gpio_set_value(sensor->platform_data->xshutdown, 0);
1243 if (sensor->platform_data->set_xclk)
1244 sensor->platform_data->set_xclk(&sensor->src->sd, 0);
1246 clk_disable_unprepare(sensor->ext_clk);
1249 regulator_disable(sensor->vana);
1253 static void smiapp_power_off(struct smiapp_sensor *sensor)
1256 * Currently power/clock to lens are enable/disabled separately
1257 * but they are essentially the same signals. So if the sensor is
1258 * powered off while the lens is powered on the sensor does not
1259 * really see a power off and next time the cci address change
1260 * will fail. So do a soft reset explicitly here.
1262 if (sensor->platform_data->i2c_addr_alt)
1263 smiapp_write(sensor,
1264 SMIAPP_REG_U8_SOFTWARE_RESET,
1265 SMIAPP_SOFTWARE_RESET);
1267 if (gpio_is_valid(sensor->platform_data->xshutdown))
1268 gpio_set_value(sensor->platform_data->xshutdown, 0);
1269 if (sensor->platform_data->set_xclk)
1270 sensor->platform_data->set_xclk(&sensor->src->sd, 0);
1272 clk_disable_unprepare(sensor->ext_clk);
1273 usleep_range(5000, 5000);
1274 regulator_disable(sensor->vana);
1275 sensor->streaming = 0;
1278 static int smiapp_set_power(struct v4l2_subdev *subdev, int on)
1280 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1283 mutex_lock(&sensor->power_mutex);
1286 * If the power count is modified from 0 to != 0 or from != 0
1287 * to 0, update the power state.
1289 if (!sensor->power_count == !on)
1293 /* Power on and perform initialisation. */
1294 ret = smiapp_power_on(sensor);
1298 smiapp_power_off(sensor);
1301 /* Update the power count. */
1302 sensor->power_count += on ? 1 : -1;
1303 WARN_ON(sensor->power_count < 0);
1306 mutex_unlock(&sensor->power_mutex);
1310 /* -----------------------------------------------------------------------------
1311 * Video stream management
1314 static int smiapp_start_streaming(struct smiapp_sensor *sensor)
1316 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
1319 mutex_lock(&sensor->mutex);
1321 rval = smiapp_write(sensor, SMIAPP_REG_U16_CSI_DATA_FORMAT,
1322 (sensor->csi_format->width << 8) |
1323 sensor->csi_format->compressed);
1327 rval = smiapp_pll_configure(sensor);
1331 /* Analog crop start coordinates */
1332 rval = smiapp_write(sensor, SMIAPP_REG_U16_X_ADDR_START,
1333 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].left);
1337 rval = smiapp_write(sensor, SMIAPP_REG_U16_Y_ADDR_START,
1338 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].top);
1342 /* Analog crop end coordinates */
1343 rval = smiapp_write(
1344 sensor, SMIAPP_REG_U16_X_ADDR_END,
1345 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].left
1346 + sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].width - 1);
1350 rval = smiapp_write(
1351 sensor, SMIAPP_REG_U16_Y_ADDR_END,
1352 sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].top
1353 + sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height - 1);
1358 * Output from pixel array, including blanking, is set using
1359 * controls below. No need to set here.
1363 if (sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
1364 == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP) {
1365 rval = smiapp_write(
1366 sensor, SMIAPP_REG_U16_DIGITAL_CROP_X_OFFSET,
1367 sensor->scaler->crop[SMIAPP_PAD_SINK].left);
1371 rval = smiapp_write(
1372 sensor, SMIAPP_REG_U16_DIGITAL_CROP_Y_OFFSET,
1373 sensor->scaler->crop[SMIAPP_PAD_SINK].top);
1377 rval = smiapp_write(
1378 sensor, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_WIDTH,
1379 sensor->scaler->crop[SMIAPP_PAD_SINK].width);
1383 rval = smiapp_write(
1384 sensor, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_HEIGHT,
1385 sensor->scaler->crop[SMIAPP_PAD_SINK].height);
1391 if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
1392 != SMIAPP_SCALING_CAPABILITY_NONE) {
1393 rval = smiapp_write(sensor, SMIAPP_REG_U16_SCALING_MODE,
1394 sensor->scaling_mode);
1398 rval = smiapp_write(sensor, SMIAPP_REG_U16_SCALE_M,
1404 /* Output size from sensor */
1405 rval = smiapp_write(sensor, SMIAPP_REG_U16_X_OUTPUT_SIZE,
1406 sensor->src->crop[SMIAPP_PAD_SRC].width);
1409 rval = smiapp_write(sensor, SMIAPP_REG_U16_Y_OUTPUT_SIZE,
1410 sensor->src->crop[SMIAPP_PAD_SRC].height);
1414 if ((sensor->flash_capability &
1415 (SMIAPP_FLASH_MODE_CAPABILITY_SINGLE_STROBE |
1416 SMIAPP_FLASH_MODE_CAPABILITY_MULTIPLE_STROBE)) &&
1417 sensor->platform_data->strobe_setup != NULL &&
1418 sensor->platform_data->strobe_setup->trigger != 0) {
1419 rval = smiapp_setup_flash_strobe(sensor);
1424 rval = smiapp_call_quirk(sensor, pre_streamon);
1426 dev_err(&client->dev, "pre_streamon quirks failed\n");
1430 rval = smiapp_write(sensor, SMIAPP_REG_U8_MODE_SELECT,
1431 SMIAPP_MODE_SELECT_STREAMING);
1434 mutex_unlock(&sensor->mutex);
1439 static int smiapp_stop_streaming(struct smiapp_sensor *sensor)
1441 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
1444 mutex_lock(&sensor->mutex);
1445 rval = smiapp_write(sensor, SMIAPP_REG_U8_MODE_SELECT,
1446 SMIAPP_MODE_SELECT_SOFTWARE_STANDBY);
1450 rval = smiapp_call_quirk(sensor, post_streamoff);
1452 dev_err(&client->dev, "post_streamoff quirks failed\n");
1455 mutex_unlock(&sensor->mutex);
1459 /* -----------------------------------------------------------------------------
1460 * V4L2 subdev video operations
1463 static int smiapp_set_stream(struct v4l2_subdev *subdev, int enable)
1465 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1468 if (sensor->streaming == enable)
1472 sensor->streaming = 1;
1473 rval = smiapp_start_streaming(sensor);
1475 sensor->streaming = 0;
1477 rval = smiapp_stop_streaming(sensor);
1478 sensor->streaming = 0;
1484 static int smiapp_enum_mbus_code(struct v4l2_subdev *subdev,
1485 struct v4l2_subdev_fh *fh,
1486 struct v4l2_subdev_mbus_code_enum *code)
1488 struct i2c_client *client = v4l2_get_subdevdata(subdev);
1489 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1494 mutex_lock(&sensor->mutex);
1496 dev_err(&client->dev, "subdev %s, pad %d, index %d\n",
1497 subdev->name, code->pad, code->index);
1499 if (subdev != &sensor->src->sd || code->pad != SMIAPP_PAD_SRC) {
1503 code->code = sensor->internal_csi_format->code;
1508 for (i = 0; i < ARRAY_SIZE(smiapp_csi_data_formats); i++) {
1509 if (sensor->mbus_frame_fmts & (1 << i))
1512 if (idx == code->index) {
1513 code->code = smiapp_csi_data_formats[i].code;
1514 dev_err(&client->dev, "found index %d, i %d, code %x\n",
1515 code->index, i, code->code);
1522 mutex_unlock(&sensor->mutex);
1527 static u32 __smiapp_get_mbus_code(struct v4l2_subdev *subdev,
1530 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1532 if (subdev == &sensor->src->sd && pad == SMIAPP_PAD_SRC)
1533 return sensor->csi_format->code;
1535 return sensor->internal_csi_format->code;
1538 static int __smiapp_get_format(struct v4l2_subdev *subdev,
1539 struct v4l2_subdev_fh *fh,
1540 struct v4l2_subdev_format *fmt)
1542 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1544 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1545 fmt->format = *v4l2_subdev_get_try_format(fh, fmt->pad);
1547 struct v4l2_rect *r;
1549 if (fmt->pad == ssd->source_pad)
1550 r = &ssd->crop[ssd->source_pad];
1554 fmt->format.code = __smiapp_get_mbus_code(subdev, fmt->pad);
1555 fmt->format.width = r->width;
1556 fmt->format.height = r->height;
1557 fmt->format.field = V4L2_FIELD_NONE;
1563 static int smiapp_get_format(struct v4l2_subdev *subdev,
1564 struct v4l2_subdev_fh *fh,
1565 struct v4l2_subdev_format *fmt)
1567 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1570 mutex_lock(&sensor->mutex);
1571 rval = __smiapp_get_format(subdev, fh, fmt);
1572 mutex_unlock(&sensor->mutex);
1577 static void smiapp_get_crop_compose(struct v4l2_subdev *subdev,
1578 struct v4l2_subdev_fh *fh,
1579 struct v4l2_rect **crops,
1580 struct v4l2_rect **comps, int which)
1582 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1585 if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1587 for (i = 0; i < subdev->entity.num_pads; i++)
1588 crops[i] = &ssd->crop[i];
1590 *comps = &ssd->compose;
1593 for (i = 0; i < subdev->entity.num_pads; i++) {
1594 crops[i] = v4l2_subdev_get_try_crop(fh, i);
1599 *comps = v4l2_subdev_get_try_compose(fh,
1606 /* Changes require propagation only on sink pad. */
1607 static void smiapp_propagate(struct v4l2_subdev *subdev,
1608 struct v4l2_subdev_fh *fh, int which,
1611 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1612 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1613 struct v4l2_rect *comp, *crops[SMIAPP_PADS];
1615 smiapp_get_crop_compose(subdev, fh, crops, &comp, which);
1618 case V4L2_SEL_TGT_CROP:
1619 comp->width = crops[SMIAPP_PAD_SINK]->width;
1620 comp->height = crops[SMIAPP_PAD_SINK]->height;
1621 if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1622 if (ssd == sensor->scaler) {
1625 SMIAPP_LIMIT_SCALER_N_MIN];
1626 sensor->scaling_mode =
1627 SMIAPP_SCALING_MODE_NONE;
1628 } else if (ssd == sensor->binner) {
1629 sensor->binning_horizontal = 1;
1630 sensor->binning_vertical = 1;
1634 case V4L2_SEL_TGT_COMPOSE:
1635 *crops[SMIAPP_PAD_SRC] = *comp;
1642 static const struct smiapp_csi_data_format
1643 *smiapp_validate_csi_data_format(struct smiapp_sensor *sensor, u32 code)
1645 const struct smiapp_csi_data_format *csi_format = sensor->csi_format;
1648 for (i = 0; i < ARRAY_SIZE(smiapp_csi_data_formats); i++) {
1649 if (sensor->mbus_frame_fmts & (1 << i)
1650 && smiapp_csi_data_formats[i].code == code)
1651 return &smiapp_csi_data_formats[i];
1657 static int smiapp_set_format(struct v4l2_subdev *subdev,
1658 struct v4l2_subdev_fh *fh,
1659 struct v4l2_subdev_format *fmt)
1661 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1662 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1663 struct v4l2_rect *crops[SMIAPP_PADS];
1665 mutex_lock(&sensor->mutex);
1668 * Media bus code is changeable on src subdev's source pad. On
1669 * other source pads we just get format here.
1671 if (fmt->pad == ssd->source_pad) {
1672 u32 code = fmt->format.code;
1673 int rval = __smiapp_get_format(subdev, fh, fmt);
1675 if (!rval && subdev == &sensor->src->sd) {
1676 const struct smiapp_csi_data_format *csi_format =
1677 smiapp_validate_csi_data_format(sensor, code);
1678 if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
1679 sensor->csi_format = csi_format;
1680 fmt->format.code = csi_format->code;
1683 mutex_unlock(&sensor->mutex);
1687 /* Sink pad. Width and height are changeable here. */
1688 fmt->format.code = __smiapp_get_mbus_code(subdev, fmt->pad);
1689 fmt->format.width &= ~1;
1690 fmt->format.height &= ~1;
1691 fmt->format.field = V4L2_FIELD_NONE;
1694 clamp(fmt->format.width,
1695 sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE],
1696 sensor->limits[SMIAPP_LIMIT_MAX_X_OUTPUT_SIZE]);
1697 fmt->format.height =
1698 clamp(fmt->format.height,
1699 sensor->limits[SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE],
1700 sensor->limits[SMIAPP_LIMIT_MAX_Y_OUTPUT_SIZE]);
1702 smiapp_get_crop_compose(subdev, fh, crops, NULL, fmt->which);
1704 crops[ssd->sink_pad]->left = 0;
1705 crops[ssd->sink_pad]->top = 0;
1706 crops[ssd->sink_pad]->width = fmt->format.width;
1707 crops[ssd->sink_pad]->height = fmt->format.height;
1708 if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
1709 ssd->sink_fmt = *crops[ssd->sink_pad];
1710 smiapp_propagate(subdev, fh, fmt->which,
1713 mutex_unlock(&sensor->mutex);
1719 * Calculate goodness of scaled image size compared to expected image
1720 * size and flags provided.
1722 #define SCALING_GOODNESS 100000
1723 #define SCALING_GOODNESS_EXTREME 100000000
1724 static int scaling_goodness(struct v4l2_subdev *subdev, int w, int ask_w,
1725 int h, int ask_h, u32 flags)
1727 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1728 struct i2c_client *client = v4l2_get_subdevdata(subdev);
1736 if (flags & V4L2_SEL_FLAG_GE) {
1738 val -= SCALING_GOODNESS;
1740 val -= SCALING_GOODNESS;
1743 if (flags & V4L2_SEL_FLAG_LE) {
1745 val -= SCALING_GOODNESS;
1747 val -= SCALING_GOODNESS;
1750 val -= abs(w - ask_w);
1751 val -= abs(h - ask_h);
1753 if (w < sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE])
1754 val -= SCALING_GOODNESS_EXTREME;
1756 dev_dbg(&client->dev, "w %d ask_w %d h %d ask_h %d goodness %d\n",
1757 w, ask_h, h, ask_h, val);
1762 static void smiapp_set_compose_binner(struct v4l2_subdev *subdev,
1763 struct v4l2_subdev_fh *fh,
1764 struct v4l2_subdev_selection *sel,
1765 struct v4l2_rect **crops,
1766 struct v4l2_rect *comp)
1768 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1770 unsigned int binh = 1, binv = 1;
1771 int best = scaling_goodness(
1773 crops[SMIAPP_PAD_SINK]->width, sel->r.width,
1774 crops[SMIAPP_PAD_SINK]->height, sel->r.height, sel->flags);
1776 for (i = 0; i < sensor->nbinning_subtypes; i++) {
1777 int this = scaling_goodness(
1779 crops[SMIAPP_PAD_SINK]->width
1780 / sensor->binning_subtypes[i].horizontal,
1782 crops[SMIAPP_PAD_SINK]->height
1783 / sensor->binning_subtypes[i].vertical,
1784 sel->r.height, sel->flags);
1787 binh = sensor->binning_subtypes[i].horizontal;
1788 binv = sensor->binning_subtypes[i].vertical;
1792 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1793 sensor->binning_vertical = binv;
1794 sensor->binning_horizontal = binh;
1797 sel->r.width = (crops[SMIAPP_PAD_SINK]->width / binh) & ~1;
1798 sel->r.height = (crops[SMIAPP_PAD_SINK]->height / binv) & ~1;
1802 * Calculate best scaling ratio and mode for given output resolution.
1804 * Try all of these: horizontal ratio, vertical ratio and smallest
1805 * size possible (horizontally).
1807 * Also try whether horizontal scaler or full scaler gives a better
1810 static void smiapp_set_compose_scaler(struct v4l2_subdev *subdev,
1811 struct v4l2_subdev_fh *fh,
1812 struct v4l2_subdev_selection *sel,
1813 struct v4l2_rect **crops,
1814 struct v4l2_rect *comp)
1816 struct i2c_client *client = v4l2_get_subdevdata(subdev);
1817 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1818 u32 min, max, a, b, max_m;
1819 u32 scale_m = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
1820 int mode = SMIAPP_SCALING_MODE_HORIZONTAL;
1826 sel->r.width = min_t(unsigned int, sel->r.width,
1827 crops[SMIAPP_PAD_SINK]->width);
1828 sel->r.height = min_t(unsigned int, sel->r.height,
1829 crops[SMIAPP_PAD_SINK]->height);
1831 a = crops[SMIAPP_PAD_SINK]->width
1832 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN] / sel->r.width;
1833 b = crops[SMIAPP_PAD_SINK]->height
1834 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN] / sel->r.height;
1835 max_m = crops[SMIAPP_PAD_SINK]->width
1836 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]
1837 / sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE];
1839 a = clamp(a, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN],
1840 sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX]);
1841 b = clamp(b, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN],
1842 sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX]);
1843 max_m = clamp(max_m, sensor->limits[SMIAPP_LIMIT_SCALER_M_MIN],
1844 sensor->limits[SMIAPP_LIMIT_SCALER_M_MAX]);
1846 dev_dbg(&client->dev, "scaling: a %d b %d max_m %d\n", a, b, max_m);
1848 min = min(max_m, min(a, b));
1849 max = min(max_m, max(a, b));
1858 try[ntry] = min + 1;
1861 try[ntry] = max + 1;
1866 for (i = 0; i < ntry; i++) {
1867 int this = scaling_goodness(
1869 crops[SMIAPP_PAD_SINK]->width
1871 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
1873 crops[SMIAPP_PAD_SINK]->height,
1877 dev_dbg(&client->dev, "trying factor %d (%d)\n", try[i], i);
1881 mode = SMIAPP_SCALING_MODE_HORIZONTAL;
1885 if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
1886 == SMIAPP_SCALING_CAPABILITY_HORIZONTAL)
1889 this = scaling_goodness(
1890 subdev, crops[SMIAPP_PAD_SINK]->width
1892 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
1894 crops[SMIAPP_PAD_SINK]->height
1896 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN],
1902 mode = SMIAPP_SCALING_MODE_BOTH;
1908 (crops[SMIAPP_PAD_SINK]->width
1910 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]) & ~1;
1911 if (mode == SMIAPP_SCALING_MODE_BOTH)
1913 (crops[SMIAPP_PAD_SINK]->height
1915 * sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN])
1918 sel->r.height = crops[SMIAPP_PAD_SINK]->height;
1920 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1921 sensor->scale_m = scale_m;
1922 sensor->scaling_mode = mode;
1925 /* We're only called on source pads. This function sets scaling. */
1926 static int smiapp_set_compose(struct v4l2_subdev *subdev,
1927 struct v4l2_subdev_fh *fh,
1928 struct v4l2_subdev_selection *sel)
1930 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1931 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1932 struct v4l2_rect *comp, *crops[SMIAPP_PADS];
1934 smiapp_get_crop_compose(subdev, fh, crops, &comp, sel->which);
1939 if (ssd == sensor->binner)
1940 smiapp_set_compose_binner(subdev, fh, sel, crops, comp);
1942 smiapp_set_compose_scaler(subdev, fh, sel, crops, comp);
1945 smiapp_propagate(subdev, fh, sel->which,
1946 V4L2_SEL_TGT_COMPOSE);
1948 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE)
1949 return smiapp_update_mode(sensor);
1954 static int __smiapp_sel_supported(struct v4l2_subdev *subdev,
1955 struct v4l2_subdev_selection *sel)
1957 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1958 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1960 /* We only implement crop in three places. */
1961 switch (sel->target) {
1962 case V4L2_SEL_TGT_CROP:
1963 case V4L2_SEL_TGT_CROP_BOUNDS:
1964 if (ssd == sensor->pixel_array
1965 && sel->pad == SMIAPP_PA_PAD_SRC)
1967 if (ssd == sensor->src
1968 && sel->pad == SMIAPP_PAD_SRC)
1970 if (ssd == sensor->scaler
1971 && sel->pad == SMIAPP_PAD_SINK
1972 && sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
1973 == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP)
1976 case V4L2_SEL_TGT_COMPOSE:
1977 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
1978 if (sel->pad == ssd->source_pad)
1980 if (ssd == sensor->binner)
1982 if (ssd == sensor->scaler
1983 && sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
1984 != SMIAPP_SCALING_CAPABILITY_NONE)
1992 static int smiapp_set_crop(struct v4l2_subdev *subdev,
1993 struct v4l2_subdev_fh *fh,
1994 struct v4l2_subdev_selection *sel)
1996 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
1997 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
1998 struct v4l2_rect *src_size, *crops[SMIAPP_PADS];
1999 struct v4l2_rect _r;
2001 smiapp_get_crop_compose(subdev, fh, crops, NULL, sel->which);
2003 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
2004 if (sel->pad == ssd->sink_pad)
2005 src_size = &ssd->sink_fmt;
2007 src_size = &ssd->compose;
2009 if (sel->pad == ssd->sink_pad) {
2012 _r.width = v4l2_subdev_get_try_format(fh, sel->pad)
2014 _r.height = v4l2_subdev_get_try_format(fh, sel->pad)
2019 v4l2_subdev_get_try_compose(
2024 if (ssd == sensor->src && sel->pad == SMIAPP_PAD_SRC) {
2029 sel->r.width = min(sel->r.width, src_size->width);
2030 sel->r.height = min(sel->r.height, src_size->height);
2032 sel->r.left = min_t(int, sel->r.left, src_size->width - sel->r.width);
2033 sel->r.top = min_t(int, sel->r.top, src_size->height - sel->r.height);
2035 *crops[sel->pad] = sel->r;
2037 if (ssd != sensor->pixel_array && sel->pad == SMIAPP_PAD_SINK)
2038 smiapp_propagate(subdev, fh, sel->which,
2044 static int __smiapp_get_selection(struct v4l2_subdev *subdev,
2045 struct v4l2_subdev_fh *fh,
2046 struct v4l2_subdev_selection *sel)
2048 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2049 struct smiapp_subdev *ssd = to_smiapp_subdev(subdev);
2050 struct v4l2_rect *comp, *crops[SMIAPP_PADS];
2051 struct v4l2_rect sink_fmt;
2054 ret = __smiapp_sel_supported(subdev, sel);
2058 smiapp_get_crop_compose(subdev, fh, crops, &comp, sel->which);
2060 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
2061 sink_fmt = ssd->sink_fmt;
2063 struct v4l2_mbus_framefmt *fmt =
2064 v4l2_subdev_get_try_format(fh, ssd->sink_pad);
2068 sink_fmt.width = fmt->width;
2069 sink_fmt.height = fmt->height;
2072 switch (sel->target) {
2073 case V4L2_SEL_TGT_CROP_BOUNDS:
2074 if (ssd == sensor->pixel_array) {
2076 sensor->limits[SMIAPP_LIMIT_X_ADDR_MAX] + 1;
2078 sensor->limits[SMIAPP_LIMIT_Y_ADDR_MAX] + 1;
2079 } else if (sel->pad == ssd->sink_pad) {
2085 case V4L2_SEL_TGT_CROP:
2086 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
2087 sel->r = *crops[sel->pad];
2089 case V4L2_SEL_TGT_COMPOSE:
2097 static int smiapp_get_selection(struct v4l2_subdev *subdev,
2098 struct v4l2_subdev_fh *fh,
2099 struct v4l2_subdev_selection *sel)
2101 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2104 mutex_lock(&sensor->mutex);
2105 rval = __smiapp_get_selection(subdev, fh, sel);
2106 mutex_unlock(&sensor->mutex);
2110 static int smiapp_set_selection(struct v4l2_subdev *subdev,
2111 struct v4l2_subdev_fh *fh,
2112 struct v4l2_subdev_selection *sel)
2114 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2117 ret = __smiapp_sel_supported(subdev, sel);
2121 mutex_lock(&sensor->mutex);
2123 sel->r.left = max(0, sel->r.left & ~1);
2124 sel->r.top = max(0, sel->r.top & ~1);
2125 sel->r.width = SMIAPP_ALIGN_DIM(sel->r.width, sel->flags);
2126 sel->r.height = SMIAPP_ALIGN_DIM(sel->r.height, sel->flags);
2128 sel->r.width = max_t(unsigned int,
2129 sensor->limits[SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE],
2131 sel->r.height = max_t(unsigned int,
2132 sensor->limits[SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE],
2135 switch (sel->target) {
2136 case V4L2_SEL_TGT_CROP:
2137 ret = smiapp_set_crop(subdev, fh, sel);
2139 case V4L2_SEL_TGT_COMPOSE:
2140 ret = smiapp_set_compose(subdev, fh, sel);
2146 mutex_unlock(&sensor->mutex);
2150 static int smiapp_get_skip_frames(struct v4l2_subdev *subdev, u32 *frames)
2152 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2154 *frames = sensor->frame_skip;
2158 /* -----------------------------------------------------------------------------
2163 smiapp_sysfs_nvm_read(struct device *dev, struct device_attribute *attr,
2166 struct v4l2_subdev *subdev = i2c_get_clientdata(to_i2c_client(dev));
2167 struct i2c_client *client = v4l2_get_subdevdata(subdev);
2168 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2169 unsigned int nbytes;
2171 if (!sensor->dev_init_done)
2174 if (!sensor->nvm_size) {
2175 /* NVM not read yet - read it now */
2176 sensor->nvm_size = sensor->platform_data->nvm_size;
2177 if (smiapp_set_power(subdev, 1) < 0)
2179 if (smiapp_read_nvm(sensor, sensor->nvm)) {
2180 dev_err(&client->dev, "nvm read failed\n");
2183 smiapp_set_power(subdev, 0);
2186 * NVM is still way below a PAGE_SIZE, so we can safely
2187 * assume this for now.
2189 nbytes = min_t(unsigned int, sensor->nvm_size, PAGE_SIZE);
2190 memcpy(buf, sensor->nvm, nbytes);
2194 static DEVICE_ATTR(nvm, S_IRUGO, smiapp_sysfs_nvm_read, NULL);
2197 smiapp_sysfs_ident_read(struct device *dev, struct device_attribute *attr,
2200 struct v4l2_subdev *subdev = i2c_get_clientdata(to_i2c_client(dev));
2201 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2202 struct smiapp_module_info *minfo = &sensor->minfo;
2204 return snprintf(buf, PAGE_SIZE, "%2.2x%4.4x%2.2x\n",
2205 minfo->manufacturer_id, minfo->model_id,
2206 minfo->revision_number_major) + 1;
2209 static DEVICE_ATTR(ident, S_IRUGO, smiapp_sysfs_ident_read, NULL);
2211 /* -----------------------------------------------------------------------------
2212 * V4L2 subdev core operations
2215 static int smiapp_identify_module(struct v4l2_subdev *subdev)
2217 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2218 struct i2c_client *client = v4l2_get_subdevdata(subdev);
2219 struct smiapp_module_info *minfo = &sensor->minfo;
2223 minfo->name = SMIAPP_NAME;
2226 rval = smiapp_read_8only(sensor, SMIAPP_REG_U8_MANUFACTURER_ID,
2227 &minfo->manufacturer_id);
2229 rval = smiapp_read_8only(sensor, SMIAPP_REG_U16_MODEL_ID,
2232 rval = smiapp_read_8only(sensor,
2233 SMIAPP_REG_U8_REVISION_NUMBER_MAJOR,
2234 &minfo->revision_number_major);
2236 rval = smiapp_read_8only(sensor,
2237 SMIAPP_REG_U8_REVISION_NUMBER_MINOR,
2238 &minfo->revision_number_minor);
2240 rval = smiapp_read_8only(sensor,
2241 SMIAPP_REG_U8_MODULE_DATE_YEAR,
2242 &minfo->module_year);
2244 rval = smiapp_read_8only(sensor,
2245 SMIAPP_REG_U8_MODULE_DATE_MONTH,
2246 &minfo->module_month);
2248 rval = smiapp_read_8only(sensor, SMIAPP_REG_U8_MODULE_DATE_DAY,
2249 &minfo->module_day);
2253 rval = smiapp_read_8only(sensor,
2254 SMIAPP_REG_U8_SENSOR_MANUFACTURER_ID,
2255 &minfo->sensor_manufacturer_id);
2257 rval = smiapp_read_8only(sensor,
2258 SMIAPP_REG_U16_SENSOR_MODEL_ID,
2259 &minfo->sensor_model_id);
2261 rval = smiapp_read_8only(sensor,
2262 SMIAPP_REG_U8_SENSOR_REVISION_NUMBER,
2263 &minfo->sensor_revision_number);
2265 rval = smiapp_read_8only(sensor,
2266 SMIAPP_REG_U8_SENSOR_FIRMWARE_VERSION,
2267 &minfo->sensor_firmware_version);
2271 rval = smiapp_read_8only(sensor, SMIAPP_REG_U8_SMIA_VERSION,
2272 &minfo->smia_version);
2274 rval = smiapp_read_8only(sensor, SMIAPP_REG_U8_SMIAPP_VERSION,
2275 &minfo->smiapp_version);
2278 dev_err(&client->dev, "sensor detection failed\n");
2282 dev_dbg(&client->dev, "module 0x%2.2x-0x%4.4x\n",
2283 minfo->manufacturer_id, minfo->model_id);
2285 dev_dbg(&client->dev,
2286 "module revision 0x%2.2x-0x%2.2x date %2.2d-%2.2d-%2.2d\n",
2287 minfo->revision_number_major, minfo->revision_number_minor,
2288 minfo->module_year, minfo->module_month, minfo->module_day);
2290 dev_dbg(&client->dev, "sensor 0x%2.2x-0x%4.4x\n",
2291 minfo->sensor_manufacturer_id, minfo->sensor_model_id);
2293 dev_dbg(&client->dev,
2294 "sensor revision 0x%2.2x firmware version 0x%2.2x\n",
2295 minfo->sensor_revision_number, minfo->sensor_firmware_version);
2297 dev_dbg(&client->dev, "smia version %2.2d smiapp version %2.2d\n",
2298 minfo->smia_version, minfo->smiapp_version);
2301 * Some modules have bad data in the lvalues below. Hope the
2302 * rvalues have better stuff. The lvalues are module
2303 * parameters whereas the rvalues are sensor parameters.
2305 if (!minfo->manufacturer_id && !minfo->model_id) {
2306 minfo->manufacturer_id = minfo->sensor_manufacturer_id;
2307 minfo->model_id = minfo->sensor_model_id;
2308 minfo->revision_number_major = minfo->sensor_revision_number;
2311 for (i = 0; i < ARRAY_SIZE(smiapp_module_idents); i++) {
2312 if (smiapp_module_idents[i].manufacturer_id
2313 != minfo->manufacturer_id)
2315 if (smiapp_module_idents[i].model_id != minfo->model_id)
2317 if (smiapp_module_idents[i].flags
2318 & SMIAPP_MODULE_IDENT_FLAG_REV_LE) {
2319 if (smiapp_module_idents[i].revision_number_major
2320 < minfo->revision_number_major)
2323 if (smiapp_module_idents[i].revision_number_major
2324 != minfo->revision_number_major)
2328 minfo->name = smiapp_module_idents[i].name;
2329 minfo->quirk = smiapp_module_idents[i].quirk;
2333 if (i >= ARRAY_SIZE(smiapp_module_idents))
2334 dev_warn(&client->dev,
2335 "no quirks for this module; let's hope it's fully compliant\n");
2337 dev_dbg(&client->dev, "the sensor is called %s, ident %2.2x%4.4x%2.2x\n",
2338 minfo->name, minfo->manufacturer_id, minfo->model_id,
2339 minfo->revision_number_major);
2341 strlcpy(subdev->name, sensor->minfo.name, sizeof(subdev->name));
2346 static const struct v4l2_subdev_ops smiapp_ops;
2347 static const struct v4l2_subdev_internal_ops smiapp_internal_ops;
2348 static const struct media_entity_operations smiapp_entity_ops;
2350 static int smiapp_registered(struct v4l2_subdev *subdev)
2352 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2353 struct i2c_client *client = v4l2_get_subdevdata(subdev);
2354 struct smiapp_pll *pll = &sensor->pll;
2355 struct smiapp_subdev *last = NULL;
2360 sensor->vana = devm_regulator_get(&client->dev, "vana");
2361 if (IS_ERR(sensor->vana)) {
2362 dev_err(&client->dev, "could not get regulator for vana\n");
2363 return PTR_ERR(sensor->vana);
2366 if (!sensor->platform_data->set_xclk) {
2367 sensor->ext_clk = devm_clk_get(&client->dev, "ext_clk");
2368 if (IS_ERR(sensor->ext_clk)) {
2369 dev_err(&client->dev, "could not get clock\n");
2370 return PTR_ERR(sensor->ext_clk);
2373 rval = clk_set_rate(sensor->ext_clk,
2374 sensor->platform_data->ext_clk);
2376 dev_err(&client->dev,
2377 "unable to set clock freq to %u\n",
2378 sensor->platform_data->ext_clk);
2383 if (gpio_is_valid(sensor->platform_data->xshutdown)) {
2384 rval = devm_gpio_request_one(
2385 &client->dev, sensor->platform_data->xshutdown, 0,
2386 "SMIA++ xshutdown");
2388 dev_err(&client->dev,
2389 "unable to acquire reset gpio %d\n",
2390 sensor->platform_data->xshutdown);
2395 rval = smiapp_power_on(sensor);
2399 rval = smiapp_identify_module(subdev);
2405 rval = smiapp_get_all_limits(sensor);
2412 * Handle Sensor Module orientation on the board.
2414 * The application of H-FLIP and V-FLIP on the sensor is modified by
2415 * the sensor orientation on the board.
2417 * For SMIAPP_BOARD_SENSOR_ORIENT_180 the default behaviour is to set
2418 * both H-FLIP and V-FLIP for normal operation which also implies
2419 * that a set/unset operation for user space HFLIP and VFLIP v4l2
2420 * controls will need to be internally inverted.
2422 * Rotation also changes the bayer pattern.
2424 if (sensor->platform_data->module_board_orient ==
2425 SMIAPP_MODULE_BOARD_ORIENT_180)
2426 sensor->hvflip_inv_mask = SMIAPP_IMAGE_ORIENTATION_HFLIP |
2427 SMIAPP_IMAGE_ORIENTATION_VFLIP;
2429 rval = smiapp_call_quirk(sensor, limits);
2431 dev_err(&client->dev, "limits quirks failed\n");
2435 rval = smiapp_get_mbus_formats(sensor);
2441 if (sensor->limits[SMIAPP_LIMIT_BINNING_CAPABILITY]) {
2444 rval = smiapp_read(sensor,
2445 SMIAPP_REG_U8_BINNING_SUBTYPES, &val);
2450 sensor->nbinning_subtypes = min_t(u8, val,
2451 SMIAPP_BINNING_SUBTYPES);
2453 for (i = 0; i < sensor->nbinning_subtypes; i++) {
2455 sensor, SMIAPP_REG_U8_BINNING_TYPE_n(i), &val);
2460 sensor->binning_subtypes[i] =
2461 *(struct smiapp_binning_subtype *)&val;
2463 dev_dbg(&client->dev, "binning %xx%x\n",
2464 sensor->binning_subtypes[i].horizontal,
2465 sensor->binning_subtypes[i].vertical);
2468 sensor->binning_horizontal = 1;
2469 sensor->binning_vertical = 1;
2471 if (device_create_file(&client->dev, &dev_attr_ident) != 0) {
2472 dev_err(&client->dev, "sysfs ident entry creation failed\n");
2476 /* SMIA++ NVM initialization - it will be read from the sensor
2477 * when it is first requested by userspace.
2479 if (sensor->minfo.smiapp_version && sensor->platform_data->nvm_size) {
2480 sensor->nvm = devm_kzalloc(&client->dev,
2481 sensor->platform_data->nvm_size, GFP_KERNEL);
2482 if (sensor->nvm == NULL) {
2483 dev_err(&client->dev, "nvm buf allocation failed\n");
2485 goto out_ident_release;
2488 if (device_create_file(&client->dev, &dev_attr_nvm) != 0) {
2489 dev_err(&client->dev, "sysfs nvm entry failed\n");
2491 goto out_ident_release;
2495 /* We consider this as profile 0 sensor if any of these are zero. */
2496 if (!sensor->limits[SMIAPP_LIMIT_MIN_OP_SYS_CLK_DIV] ||
2497 !sensor->limits[SMIAPP_LIMIT_MAX_OP_SYS_CLK_DIV] ||
2498 !sensor->limits[SMIAPP_LIMIT_MIN_OP_PIX_CLK_DIV] ||
2499 !sensor->limits[SMIAPP_LIMIT_MAX_OP_PIX_CLK_DIV]) {
2500 sensor->minfo.smiapp_profile = SMIAPP_PROFILE_0;
2501 } else if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
2502 != SMIAPP_SCALING_CAPABILITY_NONE) {
2503 if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
2504 == SMIAPP_SCALING_CAPABILITY_HORIZONTAL)
2505 sensor->minfo.smiapp_profile = SMIAPP_PROFILE_1;
2507 sensor->minfo.smiapp_profile = SMIAPP_PROFILE_2;
2508 sensor->scaler = &sensor->ssds[sensor->ssds_used];
2509 sensor->ssds_used++;
2510 } else if (sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
2511 == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP) {
2512 sensor->scaler = &sensor->ssds[sensor->ssds_used];
2513 sensor->ssds_used++;
2515 sensor->binner = &sensor->ssds[sensor->ssds_used];
2516 sensor->ssds_used++;
2517 sensor->pixel_array = &sensor->ssds[sensor->ssds_used];
2518 sensor->ssds_used++;
2520 sensor->scale_m = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
2522 for (i = 0; i < SMIAPP_SUBDEVS; i++) {
2524 struct smiapp_subdev *ssd;
2526 } const __this[] = {
2527 { sensor->scaler, "scaler", },
2528 { sensor->binner, "binner", },
2529 { sensor->pixel_array, "pixel array", },
2530 }, *_this = &__this[i];
2531 struct smiapp_subdev *this = _this->ssd;
2536 if (this != sensor->src)
2537 v4l2_subdev_init(&this->sd, &smiapp_ops);
2539 this->sensor = sensor;
2541 if (this == sensor->pixel_array) {
2545 this->source_pad = 1;
2548 snprintf(this->sd.name,
2549 sizeof(this->sd.name), "%s %s %d-%4.4x",
2550 sensor->minfo.name, _this->name,
2551 i2c_adapter_id(client->adapter), client->addr);
2553 this->sink_fmt.width =
2554 sensor->limits[SMIAPP_LIMIT_X_ADDR_MAX] + 1;
2555 this->sink_fmt.height =
2556 sensor->limits[SMIAPP_LIMIT_Y_ADDR_MAX] + 1;
2557 this->compose.width = this->sink_fmt.width;
2558 this->compose.height = this->sink_fmt.height;
2559 this->crop[this->source_pad] = this->compose;
2560 this->pads[this->source_pad].flags = MEDIA_PAD_FL_SOURCE;
2561 if (this != sensor->pixel_array) {
2562 this->crop[this->sink_pad] = this->compose;
2563 this->pads[this->sink_pad].flags = MEDIA_PAD_FL_SINK;
2566 this->sd.entity.ops = &smiapp_entity_ops;
2573 this->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
2574 this->sd.internal_ops = &smiapp_internal_ops;
2575 this->sd.owner = NULL;
2576 v4l2_set_subdevdata(&this->sd, client);
2578 rval = media_entity_init(&this->sd.entity,
2579 this->npads, this->pads, 0);
2581 dev_err(&client->dev,
2582 "media_entity_init failed\n");
2583 goto out_nvm_release;
2586 rval = media_entity_create_link(&this->sd.entity,
2590 MEDIA_LNK_FL_ENABLED |
2591 MEDIA_LNK_FL_IMMUTABLE);
2593 dev_err(&client->dev,
2594 "media_entity_create_link failed\n");
2595 goto out_nvm_release;
2598 rval = v4l2_device_register_subdev(sensor->src->sd.v4l2_dev,
2601 dev_err(&client->dev,
2602 "v4l2_device_register_subdev failed\n");
2603 goto out_nvm_release;
2609 dev_dbg(&client->dev, "profile %d\n", sensor->minfo.smiapp_profile);
2611 sensor->pixel_array->sd.entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
2614 smiapp_read_frame_fmt(sensor);
2615 rval = smiapp_init_controls(sensor);
2617 goto out_nvm_release;
2619 /* prepare PLL configuration input values */
2620 pll->bus_type = SMIAPP_PLL_BUS_TYPE_CSI2;
2621 pll->csi2.lanes = sensor->platform_data->lanes;
2622 pll->ext_clk_freq_hz = sensor->platform_data->ext_clk;
2623 pll->flags = smiapp_call_quirk(sensor, pll_flags);
2625 /* Profile 0 sensors have no separate OP clock branch. */
2626 if (sensor->minfo.smiapp_profile == SMIAPP_PROFILE_0)
2627 pll->flags |= SMIAPP_PLL_FLAG_NO_OP_CLOCKS;
2628 pll->scale_n = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
2630 rval = smiapp_update_mode(sensor);
2632 dev_err(&client->dev, "update mode failed\n");
2633 goto out_nvm_release;
2636 sensor->streaming = false;
2637 sensor->dev_init_done = true;
2639 /* check flash capability */
2640 rval = smiapp_read(sensor, SMIAPP_REG_U8_FLASH_MODE_CAPABILITY, &tmp);
2641 sensor->flash_capability = tmp;
2643 goto out_nvm_release;
2645 smiapp_power_off(sensor);
2650 device_remove_file(&client->dev, &dev_attr_nvm);
2653 device_remove_file(&client->dev, &dev_attr_ident);
2656 smiapp_power_off(sensor);
2660 static int smiapp_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
2662 struct smiapp_subdev *ssd = to_smiapp_subdev(sd);
2663 struct smiapp_sensor *sensor = ssd->sensor;
2665 smiapp_csi_data_formats[smiapp_pixel_order(sensor)].code;
2668 mutex_lock(&sensor->mutex);
2670 for (i = 0; i < ssd->npads; i++) {
2671 struct v4l2_mbus_framefmt *try_fmt =
2672 v4l2_subdev_get_try_format(fh, i);
2673 struct v4l2_rect *try_crop = v4l2_subdev_get_try_crop(fh, i);
2674 struct v4l2_rect *try_comp;
2676 try_fmt->width = sensor->limits[SMIAPP_LIMIT_X_ADDR_MAX] + 1;
2677 try_fmt->height = sensor->limits[SMIAPP_LIMIT_Y_ADDR_MAX] + 1;
2678 try_fmt->code = mbus_code;
2679 try_fmt->field = V4L2_FIELD_NONE;
2683 try_crop->width = try_fmt->width;
2684 try_crop->height = try_fmt->height;
2686 if (ssd != sensor->pixel_array)
2689 try_comp = v4l2_subdev_get_try_compose(fh, i);
2690 *try_comp = *try_crop;
2693 mutex_unlock(&sensor->mutex);
2695 return smiapp_set_power(sd, 1);
2698 static int smiapp_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
2700 return smiapp_set_power(sd, 0);
2703 static const struct v4l2_subdev_video_ops smiapp_video_ops = {
2704 .s_stream = smiapp_set_stream,
2707 static const struct v4l2_subdev_core_ops smiapp_core_ops = {
2708 .s_power = smiapp_set_power,
2711 static const struct v4l2_subdev_pad_ops smiapp_pad_ops = {
2712 .enum_mbus_code = smiapp_enum_mbus_code,
2713 .get_fmt = smiapp_get_format,
2714 .set_fmt = smiapp_set_format,
2715 .get_selection = smiapp_get_selection,
2716 .set_selection = smiapp_set_selection,
2719 static const struct v4l2_subdev_sensor_ops smiapp_sensor_ops = {
2720 .g_skip_frames = smiapp_get_skip_frames,
2723 static const struct v4l2_subdev_ops smiapp_ops = {
2724 .core = &smiapp_core_ops,
2725 .video = &smiapp_video_ops,
2726 .pad = &smiapp_pad_ops,
2727 .sensor = &smiapp_sensor_ops,
2730 static const struct media_entity_operations smiapp_entity_ops = {
2731 .link_validate = v4l2_subdev_link_validate,
2734 static const struct v4l2_subdev_internal_ops smiapp_internal_src_ops = {
2735 .registered = smiapp_registered,
2736 .open = smiapp_open,
2737 .close = smiapp_close,
2740 static const struct v4l2_subdev_internal_ops smiapp_internal_ops = {
2741 .open = smiapp_open,
2742 .close = smiapp_close,
2745 /* -----------------------------------------------------------------------------
2751 static int smiapp_suspend(struct device *dev)
2753 struct i2c_client *client = to_i2c_client(dev);
2754 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
2755 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2758 BUG_ON(mutex_is_locked(&sensor->mutex));
2760 if (sensor->power_count == 0)
2763 if (sensor->streaming)
2764 smiapp_stop_streaming(sensor);
2766 streaming = sensor->streaming;
2768 smiapp_power_off(sensor);
2770 /* save state for resume */
2771 sensor->streaming = streaming;
2776 static int smiapp_resume(struct device *dev)
2778 struct i2c_client *client = to_i2c_client(dev);
2779 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
2780 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2783 if (sensor->power_count == 0)
2786 rval = smiapp_power_on(sensor);
2790 if (sensor->streaming)
2791 rval = smiapp_start_streaming(sensor);
2798 #define smiapp_suspend NULL
2799 #define smiapp_resume NULL
2801 #endif /* CONFIG_PM */
2803 static int smiapp_probe(struct i2c_client *client,
2804 const struct i2c_device_id *devid)
2806 struct smiapp_sensor *sensor;
2808 if (client->dev.platform_data == NULL)
2811 sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL);
2815 sensor->platform_data = client->dev.platform_data;
2816 mutex_init(&sensor->mutex);
2817 mutex_init(&sensor->power_mutex);
2818 sensor->src = &sensor->ssds[sensor->ssds_used];
2820 v4l2_i2c_subdev_init(&sensor->src->sd, client, &smiapp_ops);
2821 sensor->src->sd.internal_ops = &smiapp_internal_src_ops;
2822 sensor->src->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
2823 sensor->src->sensor = sensor;
2825 sensor->src->pads[0].flags = MEDIA_PAD_FL_SOURCE;
2826 return media_entity_init(&sensor->src->sd.entity, 2,
2827 sensor->src->pads, 0);
2830 static int smiapp_remove(struct i2c_client *client)
2832 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
2833 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2836 if (sensor->power_count) {
2837 if (gpio_is_valid(sensor->platform_data->xshutdown))
2838 gpio_set_value(sensor->platform_data->xshutdown, 0);
2839 if (sensor->platform_data->set_xclk)
2840 sensor->platform_data->set_xclk(&sensor->src->sd, 0);
2842 clk_disable_unprepare(sensor->ext_clk);
2843 sensor->power_count = 0;
2846 device_remove_file(&client->dev, &dev_attr_ident);
2848 device_remove_file(&client->dev, &dev_attr_nvm);
2850 for (i = 0; i < sensor->ssds_used; i++) {
2851 v4l2_device_unregister_subdev(&sensor->ssds[i].sd);
2852 media_entity_cleanup(&sensor->ssds[i].sd.entity);
2854 smiapp_free_controls(sensor);
2859 static const struct i2c_device_id smiapp_id_table[] = {
2863 MODULE_DEVICE_TABLE(i2c, smiapp_id_table);
2865 static const struct dev_pm_ops smiapp_pm_ops = {
2866 .suspend = smiapp_suspend,
2867 .resume = smiapp_resume,
2870 static struct i2c_driver smiapp_i2c_driver = {
2872 .name = SMIAPP_NAME,
2873 .pm = &smiapp_pm_ops,
2875 .probe = smiapp_probe,
2876 .remove = smiapp_remove,
2877 .id_table = smiapp_id_table,
2880 module_i2c_driver(smiapp_i2c_driver);
2882 MODULE_AUTHOR("Sakari Ailus <sakari.ailus@iki.fi>");
2883 MODULE_DESCRIPTION("Generic SMIA/SMIA++ camera module driver");
2884 MODULE_LICENSE("GPL");