1 // SPDX-License-Identifier: GPL-2.0
3 * A V4L2 driver for Sony IMX219 cameras.
4 * Copyright (C) 2019, Raspberry Pi (Trading) Ltd
6 * Based on Sony imx258 camera driver
7 * Copyright (C) 2018 Intel Corporation
9 * DT / fwnode changes, and regulator / GPIO control taken from imx214 driver
10 * Copyright 2018 Qtechnology A/S
12 * Flip handling taken from the Sony IMX319 driver.
13 * Copyright (C) 2018 Intel Corporation
17 #include <linux/clk.h>
18 #include <linux/delay.h>
19 #include <linux/gpio/consumer.h>
20 #include <linux/i2c.h>
21 #include <linux/module.h>
22 #include <linux/pm_runtime.h>
23 #include <linux/regulator/consumer.h>
24 #include <media/v4l2-ctrls.h>
25 #include <media/v4l2-device.h>
26 #include <media/v4l2-event.h>
27 #include <media/v4l2-fwnode.h>
28 #include <media/v4l2-mediabus.h>
29 #include <asm/unaligned.h>
31 #define IMX219_REG_VALUE_08BIT 1
32 #define IMX219_REG_VALUE_16BIT 2
34 #define IMX219_REG_MODE_SELECT 0x0100
35 #define IMX219_MODE_STANDBY 0x00
36 #define IMX219_MODE_STREAMING 0x01
39 #define IMX219_REG_CHIP_ID 0x0000
40 #define IMX219_CHIP_ID 0x0219
42 /* External clock frequency is 24.0M */
43 #define IMX219_XCLK_FREQ 24000000
45 /* Pixel rate is fixed for all the modes */
46 #define IMX219_PIXEL_RATE 182400000
47 #define IMX219_PIXEL_RATE_4LANE 280800000
49 #define IMX219_DEFAULT_LINK_FREQ 456000000
50 #define IMX219_DEFAULT_LINK_FREQ_4LANE 363000000
52 #define IMX219_REG_CSI_LANE_MODE 0x0114
53 #define IMX219_CSI_2_LANE_MODE 0x01
54 #define IMX219_CSI_4_LANE_MODE 0x03
56 /* V_TIMING internal */
57 #define IMX219_REG_VTS 0x0160
58 #define IMX219_VTS_15FPS 0x0dc6
59 #define IMX219_VTS_30FPS_1080P 0x06e3
60 #define IMX219_VTS_30FPS_BINNED 0x06e3
61 #define IMX219_VTS_30FPS_640x480 0x06e3
62 #define IMX219_VTS_MAX 0xffff
64 #define IMX219_VBLANK_MIN 4
67 #define IMX219_FLL_MIN 0x08a6
68 #define IMX219_FLL_MAX 0xffff
69 #define IMX219_FLL_STEP 1
70 #define IMX219_FLL_DEFAULT 0x0c98
72 /* HBLANK control - read only */
73 #define IMX219_PPL_DEFAULT 3448
75 /* Exposure control */
76 #define IMX219_REG_EXPOSURE 0x015a
77 #define IMX219_EXPOSURE_MIN 4
78 #define IMX219_EXPOSURE_STEP 1
79 #define IMX219_EXPOSURE_DEFAULT 0x640
80 #define IMX219_EXPOSURE_MAX 65535
82 /* Analog gain control */
83 #define IMX219_REG_ANALOG_GAIN 0x0157
84 #define IMX219_ANA_GAIN_MIN 0
85 #define IMX219_ANA_GAIN_MAX 232
86 #define IMX219_ANA_GAIN_STEP 1
87 #define IMX219_ANA_GAIN_DEFAULT 0x0
89 /* Digital gain control */
90 #define IMX219_REG_DIGITAL_GAIN 0x0158
91 #define IMX219_DGTL_GAIN_MIN 0x0100
92 #define IMX219_DGTL_GAIN_MAX 0x0fff
93 #define IMX219_DGTL_GAIN_DEFAULT 0x0100
94 #define IMX219_DGTL_GAIN_STEP 1
96 #define IMX219_REG_ORIENTATION 0x0172
99 #define IMX219_REG_BINNING_MODE 0x0174
100 #define IMX219_BINNING_NONE 0x0000
101 #define IMX219_BINNING_2X2 0x0101
102 #define IMX219_BINNING_2X2_ANALOG 0x0303
104 /* Test Pattern Control */
105 #define IMX219_REG_TEST_PATTERN 0x0600
106 #define IMX219_TEST_PATTERN_DISABLE 0
107 #define IMX219_TEST_PATTERN_SOLID_COLOR 1
108 #define IMX219_TEST_PATTERN_COLOR_BARS 2
109 #define IMX219_TEST_PATTERN_GREY_COLOR 3
110 #define IMX219_TEST_PATTERN_PN9 4
112 /* Test pattern colour components */
113 #define IMX219_REG_TESTP_RED 0x0602
114 #define IMX219_REG_TESTP_GREENR 0x0604
115 #define IMX219_REG_TESTP_BLUE 0x0606
116 #define IMX219_REG_TESTP_GREENB 0x0608
117 #define IMX219_TESTP_COLOUR_MIN 0
118 #define IMX219_TESTP_COLOUR_MAX 0x03ff
119 #define IMX219_TESTP_COLOUR_STEP 1
120 #define IMX219_TESTP_RED_DEFAULT IMX219_TESTP_COLOUR_MAX
121 #define IMX219_TESTP_GREENR_DEFAULT 0
122 #define IMX219_TESTP_BLUE_DEFAULT 0
123 #define IMX219_TESTP_GREENB_DEFAULT 0
125 /* IMX219 native and active pixel array size. */
126 #define IMX219_NATIVE_WIDTH 3296U
127 #define IMX219_NATIVE_HEIGHT 2480U
128 #define IMX219_PIXEL_ARRAY_LEFT 8U
129 #define IMX219_PIXEL_ARRAY_TOP 8U
130 #define IMX219_PIXEL_ARRAY_WIDTH 3280U
131 #define IMX219_PIXEL_ARRAY_HEIGHT 2464U
138 struct imx219_reg_list {
139 unsigned int num_of_regs;
140 const struct imx219_reg *regs;
143 /* Mode : resolution and related config&values */
150 /* Analog crop rectangle. */
151 struct v4l2_rect crop;
154 unsigned int vts_def;
156 /* Default register values */
157 struct imx219_reg_list reg_list;
159 /* 2x2 binning is used */
163 static const struct imx219_reg imx219_common_regs[] = {
164 {0x0100, 0x00}, /* Mode Select */
166 /* To Access Addresses 3000-5fff, send the following commands */
174 /* PLL Clock Table */
175 {0x0301, 0x05}, /* VTPXCK_DIV */
176 {0x0303, 0x01}, /* VTSYSCK_DIV */
177 {0x0304, 0x03}, /* PREPLLCK_VT_DIV 0x03 = AUTO set */
178 {0x0305, 0x03}, /* PREPLLCK_OP_DIV 0x03 = AUTO set */
179 {0x0306, 0x00}, /* PLL_VT_MPY */
181 {0x030b, 0x01}, /* OP_SYS_CLK_DIV */
182 {0x030c, 0x00}, /* PLL_OP_MPY */
185 /* Undocumented registers */
199 /* Frame Bank Register Group "A" */
200 {0x0162, 0x0d}, /* Line_Length_A */
202 {0x0170, 0x01}, /* X_ODD_INC_A */
203 {0x0171, 0x01}, /* Y_ODD_INC_A */
205 /* Output setup registers */
206 {0x0114, 0x01}, /* CSI 2-Lane Mode */
207 {0x0128, 0x00}, /* DPHY Auto Mode */
208 {0x012a, 0x18}, /* EXCK_Freq */
213 * Register sets lifted off the i2C interface from the Raspberry Pi firmware
215 * 3280x2464 = mode 2, 1920x1080 = mode 1, 1640x1232 = mode 4, 640x480 = mode 7.
217 static const struct imx219_reg mode_3280x2464_regs[] = {
236 static const struct imx219_reg mode_1920_1080_regs[] = {
255 static const struct imx219_reg mode_1640_1232_regs[] = {
274 static const struct imx219_reg mode_640_480_regs[] = {
293 static const struct imx219_reg raw8_framefmt_regs[] = {
299 static const struct imx219_reg raw10_framefmt_regs[] = {
305 static const s64 imx219_link_freq_menu[] = {
306 IMX219_DEFAULT_LINK_FREQ,
309 static const s64 imx219_link_freq_4lane_menu[] = {
310 IMX219_DEFAULT_LINK_FREQ_4LANE,
313 static const char * const imx219_test_pattern_menu[] = {
321 static const int imx219_test_pattern_val[] = {
322 IMX219_TEST_PATTERN_DISABLE,
323 IMX219_TEST_PATTERN_COLOR_BARS,
324 IMX219_TEST_PATTERN_SOLID_COLOR,
325 IMX219_TEST_PATTERN_GREY_COLOR,
326 IMX219_TEST_PATTERN_PN9,
329 /* regulator supplies */
330 static const char * const imx219_supply_name[] = {
331 /* Supplies can be enabled in any order */
332 "VANA", /* Analog (2.8V) supply */
333 "VDIG", /* Digital Core (1.8V) supply */
334 "VDDL", /* IF (1.2V) supply */
337 #define IMX219_NUM_SUPPLIES ARRAY_SIZE(imx219_supply_name)
340 * The supported formats.
341 * This table MUST contain 4 entries per format, to cover the various flip
342 * combinations in the order
348 static const u32 codes[] = {
349 MEDIA_BUS_FMT_SRGGB10_1X10,
350 MEDIA_BUS_FMT_SGRBG10_1X10,
351 MEDIA_BUS_FMT_SGBRG10_1X10,
352 MEDIA_BUS_FMT_SBGGR10_1X10,
354 MEDIA_BUS_FMT_SRGGB8_1X8,
355 MEDIA_BUS_FMT_SGRBG8_1X8,
356 MEDIA_BUS_FMT_SGBRG8_1X8,
357 MEDIA_BUS_FMT_SBGGR8_1X8,
361 * Initialisation delay between XCLR low->high and the moment when the sensor
362 * can start capture (i.e. can leave software stanby) must be not less than:
363 * t4 + max(t5, t6 + <time to initialize the sensor register over I2C>)
365 * t4 is fixed, and is max 200uS,
366 * t5 is fixed, and is 6000uS,
367 * t6 depends on the sensor external clock, and is max 32000 clock periods.
368 * As per sensor datasheet, the external clock must be from 6MHz to 27MHz.
369 * So for any acceptable external clock t6 is always within the range of
370 * 1185 to 5333 uS, and is always less than t5.
371 * For this reason this is always safe to wait (t4 + t5) = 6200 uS, then
372 * initialize the sensor over I2C, and then exit the software standby.
374 * This start-up time can be optimized a bit more, if we start the writes
375 * over I2C after (t4+t6), but before (t4+t5) expires. But then sensor
376 * initialization over I2C may complete before (t4+t5) expires, and we must
377 * ensure that capture is not started before (t4+t5).
379 * This delay doesn't account for the power supply startup time. If needed,
380 * this should be taken care of via the regulator framework. E.g. in the
381 * case of DT for regulator-fixed one should define the startup-delay-us
384 #define IMX219_XCLR_MIN_DELAY_US 6200
385 #define IMX219_XCLR_DELAY_RANGE_US 1000
388 static const struct imx219_mode supported_modes[] = {
390 /* 8MPix 15fps mode */
394 .left = IMX219_PIXEL_ARRAY_LEFT,
395 .top = IMX219_PIXEL_ARRAY_TOP,
399 .vts_def = IMX219_VTS_15FPS,
401 .num_of_regs = ARRAY_SIZE(mode_3280x2464_regs),
402 .regs = mode_3280x2464_regs,
407 /* 1080P 30fps cropped */
416 .vts_def = IMX219_VTS_30FPS_1080P,
418 .num_of_regs = ARRAY_SIZE(mode_1920_1080_regs),
419 .regs = mode_1920_1080_regs,
424 /* 2x2 binned 30fps mode */
428 .left = IMX219_PIXEL_ARRAY_LEFT,
429 .top = IMX219_PIXEL_ARRAY_TOP,
433 .vts_def = IMX219_VTS_30FPS_BINNED,
435 .num_of_regs = ARRAY_SIZE(mode_1640_1232_regs),
436 .regs = mode_1640_1232_regs,
441 /* 640x480 30fps mode */
450 .vts_def = IMX219_VTS_30FPS_640x480,
452 .num_of_regs = ARRAY_SIZE(mode_640_480_regs),
453 .regs = mode_640_480_regs,
460 struct v4l2_subdev sd;
461 struct media_pad pad;
463 struct v4l2_mbus_framefmt fmt;
465 struct clk *xclk; /* system clock to IMX219 */
468 struct gpio_desc *reset_gpio;
469 struct regulator_bulk_data supplies[IMX219_NUM_SUPPLIES];
471 struct v4l2_ctrl_handler ctrl_handler;
473 struct v4l2_ctrl *pixel_rate;
474 struct v4l2_ctrl *link_freq;
475 struct v4l2_ctrl *exposure;
476 struct v4l2_ctrl *vflip;
477 struct v4l2_ctrl *hflip;
478 struct v4l2_ctrl *vblank;
479 struct v4l2_ctrl *hblank;
482 const struct imx219_mode *mode;
485 * Mutex for serialized access:
486 * Protect sensor module set pad format and start/stop streaming safely.
490 /* Streaming on/off */
493 /* Two or Four lanes */
497 static inline struct imx219 *to_imx219(struct v4l2_subdev *_sd)
499 return container_of(_sd, struct imx219, sd);
502 /* Read registers up to 2 at a time */
503 static int imx219_read_reg(struct imx219 *imx219, u16 reg, u32 len, u32 *val)
505 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
506 struct i2c_msg msgs[2];
507 u8 addr_buf[2] = { reg >> 8, reg & 0xff };
508 u8 data_buf[4] = { 0, };
514 /* Write register address */
515 msgs[0].addr = client->addr;
517 msgs[0].len = ARRAY_SIZE(addr_buf);
518 msgs[0].buf = addr_buf;
520 /* Read data from register */
521 msgs[1].addr = client->addr;
522 msgs[1].flags = I2C_M_RD;
524 msgs[1].buf = &data_buf[4 - len];
526 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
527 if (ret != ARRAY_SIZE(msgs))
530 *val = get_unaligned_be32(data_buf);
535 /* Write registers up to 2 at a time */
536 static int imx219_write_reg(struct imx219 *imx219, u16 reg, u32 len, u32 val)
538 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
544 put_unaligned_be16(reg, buf);
545 put_unaligned_be32(val << (8 * (4 - len)), buf + 2);
546 if (i2c_master_send(client, buf, len + 2) != len + 2)
552 /* Write a list of registers */
553 static int imx219_write_regs(struct imx219 *imx219,
554 const struct imx219_reg *regs, u32 len)
556 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
560 for (i = 0; i < len; i++) {
561 ret = imx219_write_reg(imx219, regs[i].address, 1, regs[i].val);
563 dev_err_ratelimited(&client->dev,
564 "Failed to write reg 0x%4.4x. error = %d\n",
565 regs[i].address, ret);
574 /* Get bayer order based on flip setting. */
575 static u32 imx219_get_format_code(struct imx219 *imx219, u32 code)
579 lockdep_assert_held(&imx219->mutex);
581 for (i = 0; i < ARRAY_SIZE(codes); i++)
582 if (codes[i] == code)
585 if (i >= ARRAY_SIZE(codes))
588 i = (i & ~3) | (imx219->vflip->val ? 2 : 0) |
589 (imx219->hflip->val ? 1 : 0);
594 static void imx219_set_default_format(struct imx219 *imx219)
596 struct v4l2_mbus_framefmt *fmt;
599 fmt->code = MEDIA_BUS_FMT_SRGGB10_1X10;
600 fmt->colorspace = V4L2_COLORSPACE_SRGB;
601 fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace);
602 fmt->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true,
605 fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace);
606 fmt->width = supported_modes[0].width;
607 fmt->height = supported_modes[0].height;
608 fmt->field = V4L2_FIELD_NONE;
611 static int imx219_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
613 struct imx219 *imx219 = to_imx219(sd);
614 struct v4l2_mbus_framefmt *try_fmt =
615 v4l2_subdev_get_try_format(sd, fh->state, 0);
616 struct v4l2_rect *try_crop;
618 mutex_lock(&imx219->mutex);
620 /* Initialize try_fmt */
621 try_fmt->width = supported_modes[0].width;
622 try_fmt->height = supported_modes[0].height;
623 try_fmt->code = imx219_get_format_code(imx219,
624 MEDIA_BUS_FMT_SRGGB10_1X10);
625 try_fmt->field = V4L2_FIELD_NONE;
627 /* Initialize try_crop rectangle. */
628 try_crop = v4l2_subdev_get_try_crop(sd, fh->state, 0);
629 try_crop->top = IMX219_PIXEL_ARRAY_TOP;
630 try_crop->left = IMX219_PIXEL_ARRAY_LEFT;
631 try_crop->width = IMX219_PIXEL_ARRAY_WIDTH;
632 try_crop->height = IMX219_PIXEL_ARRAY_HEIGHT;
634 mutex_unlock(&imx219->mutex);
639 static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
641 struct imx219 *imx219 =
642 container_of(ctrl->handler, struct imx219, ctrl_handler);
643 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
646 if (ctrl->id == V4L2_CID_VBLANK) {
647 int exposure_max, exposure_def;
649 /* Update max exposure while meeting expected vblanking */
650 exposure_max = imx219->mode->height + ctrl->val - 4;
651 exposure_def = (exposure_max < IMX219_EXPOSURE_DEFAULT) ?
652 exposure_max : IMX219_EXPOSURE_DEFAULT;
653 __v4l2_ctrl_modify_range(imx219->exposure,
654 imx219->exposure->minimum,
655 exposure_max, imx219->exposure->step,
660 * Applying V4L2 control value only happens
661 * when power is up for streaming
663 if (pm_runtime_get_if_in_use(&client->dev) == 0)
667 case V4L2_CID_ANALOGUE_GAIN:
668 ret = imx219_write_reg(imx219, IMX219_REG_ANALOG_GAIN,
669 IMX219_REG_VALUE_08BIT, ctrl->val);
671 case V4L2_CID_EXPOSURE:
672 ret = imx219_write_reg(imx219, IMX219_REG_EXPOSURE,
673 IMX219_REG_VALUE_16BIT, ctrl->val);
675 case V4L2_CID_DIGITAL_GAIN:
676 ret = imx219_write_reg(imx219, IMX219_REG_DIGITAL_GAIN,
677 IMX219_REG_VALUE_16BIT, ctrl->val);
679 case V4L2_CID_TEST_PATTERN:
680 ret = imx219_write_reg(imx219, IMX219_REG_TEST_PATTERN,
681 IMX219_REG_VALUE_16BIT,
682 imx219_test_pattern_val[ctrl->val]);
686 ret = imx219_write_reg(imx219, IMX219_REG_ORIENTATION, 1,
688 imx219->vflip->val << 1);
690 case V4L2_CID_VBLANK:
691 ret = imx219_write_reg(imx219, IMX219_REG_VTS,
692 IMX219_REG_VALUE_16BIT,
693 imx219->mode->height + ctrl->val);
695 case V4L2_CID_TEST_PATTERN_RED:
696 ret = imx219_write_reg(imx219, IMX219_REG_TESTP_RED,
697 IMX219_REG_VALUE_16BIT, ctrl->val);
699 case V4L2_CID_TEST_PATTERN_GREENR:
700 ret = imx219_write_reg(imx219, IMX219_REG_TESTP_GREENR,
701 IMX219_REG_VALUE_16BIT, ctrl->val);
703 case V4L2_CID_TEST_PATTERN_BLUE:
704 ret = imx219_write_reg(imx219, IMX219_REG_TESTP_BLUE,
705 IMX219_REG_VALUE_16BIT, ctrl->val);
707 case V4L2_CID_TEST_PATTERN_GREENB:
708 ret = imx219_write_reg(imx219, IMX219_REG_TESTP_GREENB,
709 IMX219_REG_VALUE_16BIT, ctrl->val);
712 dev_info(&client->dev,
713 "ctrl(id:0x%x,val:0x%x) is not handled\n",
714 ctrl->id, ctrl->val);
719 pm_runtime_put(&client->dev);
724 static const struct v4l2_ctrl_ops imx219_ctrl_ops = {
725 .s_ctrl = imx219_set_ctrl,
728 static int imx219_enum_mbus_code(struct v4l2_subdev *sd,
729 struct v4l2_subdev_state *sd_state,
730 struct v4l2_subdev_mbus_code_enum *code)
732 struct imx219 *imx219 = to_imx219(sd);
734 if (code->index >= (ARRAY_SIZE(codes) / 4))
737 mutex_lock(&imx219->mutex);
738 code->code = imx219_get_format_code(imx219, codes[code->index * 4]);
739 mutex_unlock(&imx219->mutex);
744 static int imx219_enum_frame_size(struct v4l2_subdev *sd,
745 struct v4l2_subdev_state *sd_state,
746 struct v4l2_subdev_frame_size_enum *fse)
748 struct imx219 *imx219 = to_imx219(sd);
751 if (fse->index >= ARRAY_SIZE(supported_modes))
754 mutex_lock(&imx219->mutex);
755 code = imx219_get_format_code(imx219, fse->code);
756 mutex_unlock(&imx219->mutex);
757 if (fse->code != code)
760 fse->min_width = supported_modes[fse->index].width;
761 fse->max_width = fse->min_width;
762 fse->min_height = supported_modes[fse->index].height;
763 fse->max_height = fse->min_height;
768 static void imx219_reset_colorspace(struct v4l2_mbus_framefmt *fmt)
770 fmt->colorspace = V4L2_COLORSPACE_SRGB;
771 fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace);
772 fmt->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true,
775 fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace);
778 static void imx219_update_pad_format(struct imx219 *imx219,
779 const struct imx219_mode *mode,
780 struct v4l2_subdev_format *fmt)
782 fmt->format.width = mode->width;
783 fmt->format.height = mode->height;
784 fmt->format.field = V4L2_FIELD_NONE;
785 imx219_reset_colorspace(&fmt->format);
788 static int __imx219_get_pad_format(struct imx219 *imx219,
789 struct v4l2_subdev_state *sd_state,
790 struct v4l2_subdev_format *fmt)
792 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
793 struct v4l2_mbus_framefmt *try_fmt =
794 v4l2_subdev_get_try_format(&imx219->sd, sd_state,
796 /* update the code which could change due to vflip or hflip: */
797 try_fmt->code = imx219_get_format_code(imx219, try_fmt->code);
798 fmt->format = *try_fmt;
800 imx219_update_pad_format(imx219, imx219->mode, fmt);
801 fmt->format.code = imx219_get_format_code(imx219,
808 static int imx219_get_pad_format(struct v4l2_subdev *sd,
809 struct v4l2_subdev_state *sd_state,
810 struct v4l2_subdev_format *fmt)
812 struct imx219 *imx219 = to_imx219(sd);
815 mutex_lock(&imx219->mutex);
816 ret = __imx219_get_pad_format(imx219, sd_state, fmt);
817 mutex_unlock(&imx219->mutex);
822 static int imx219_set_pad_format(struct v4l2_subdev *sd,
823 struct v4l2_subdev_state *sd_state,
824 struct v4l2_subdev_format *fmt)
826 struct imx219 *imx219 = to_imx219(sd);
827 const struct imx219_mode *mode;
828 struct v4l2_mbus_framefmt *framefmt;
829 int exposure_max, exposure_def, hblank;
832 mutex_lock(&imx219->mutex);
834 for (i = 0; i < ARRAY_SIZE(codes); i++)
835 if (codes[i] == fmt->format.code)
837 if (i >= ARRAY_SIZE(codes))
840 /* Bayer order varies with flips */
841 fmt->format.code = imx219_get_format_code(imx219, codes[i]);
843 mode = v4l2_find_nearest_size(supported_modes,
844 ARRAY_SIZE(supported_modes),
846 fmt->format.width, fmt->format.height);
847 imx219_update_pad_format(imx219, mode, fmt);
848 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
849 framefmt = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
850 *framefmt = fmt->format;
851 } else if (imx219->mode != mode ||
852 imx219->fmt.code != fmt->format.code) {
853 imx219->fmt = fmt->format;
855 /* Update limits and set FPS to default */
856 __v4l2_ctrl_modify_range(imx219->vblank, IMX219_VBLANK_MIN,
857 IMX219_VTS_MAX - mode->height, 1,
858 mode->vts_def - mode->height);
859 __v4l2_ctrl_s_ctrl(imx219->vblank,
860 mode->vts_def - mode->height);
861 /* Update max exposure while meeting expected vblanking */
862 exposure_max = mode->vts_def - 4;
863 exposure_def = (exposure_max < IMX219_EXPOSURE_DEFAULT) ?
864 exposure_max : IMX219_EXPOSURE_DEFAULT;
865 __v4l2_ctrl_modify_range(imx219->exposure,
866 imx219->exposure->minimum,
867 exposure_max, imx219->exposure->step,
870 * Currently PPL is fixed to IMX219_PPL_DEFAULT, so hblank
871 * depends on mode->width only, and is not changeble in any
872 * way other than changing the mode.
874 hblank = IMX219_PPL_DEFAULT - mode->width;
875 __v4l2_ctrl_modify_range(imx219->hblank, hblank, hblank, 1,
879 mutex_unlock(&imx219->mutex);
884 static int imx219_set_framefmt(struct imx219 *imx219)
886 switch (imx219->fmt.code) {
887 case MEDIA_BUS_FMT_SRGGB8_1X8:
888 case MEDIA_BUS_FMT_SGRBG8_1X8:
889 case MEDIA_BUS_FMT_SGBRG8_1X8:
890 case MEDIA_BUS_FMT_SBGGR8_1X8:
891 return imx219_write_regs(imx219, raw8_framefmt_regs,
892 ARRAY_SIZE(raw8_framefmt_regs));
894 case MEDIA_BUS_FMT_SRGGB10_1X10:
895 case MEDIA_BUS_FMT_SGRBG10_1X10:
896 case MEDIA_BUS_FMT_SGBRG10_1X10:
897 case MEDIA_BUS_FMT_SBGGR10_1X10:
898 return imx219_write_regs(imx219, raw10_framefmt_regs,
899 ARRAY_SIZE(raw10_framefmt_regs));
905 static int imx219_set_binning(struct imx219 *imx219)
907 if (!imx219->mode->binning) {
908 return imx219_write_reg(imx219, IMX219_REG_BINNING_MODE,
909 IMX219_REG_VALUE_16BIT,
910 IMX219_BINNING_NONE);
913 switch (imx219->fmt.code) {
914 case MEDIA_BUS_FMT_SRGGB8_1X8:
915 case MEDIA_BUS_FMT_SGRBG8_1X8:
916 case MEDIA_BUS_FMT_SGBRG8_1X8:
917 case MEDIA_BUS_FMT_SBGGR8_1X8:
918 return imx219_write_reg(imx219, IMX219_REG_BINNING_MODE,
919 IMX219_REG_VALUE_16BIT,
920 IMX219_BINNING_2X2_ANALOG);
922 case MEDIA_BUS_FMT_SRGGB10_1X10:
923 case MEDIA_BUS_FMT_SGRBG10_1X10:
924 case MEDIA_BUS_FMT_SGBRG10_1X10:
925 case MEDIA_BUS_FMT_SBGGR10_1X10:
926 return imx219_write_reg(imx219, IMX219_REG_BINNING_MODE,
927 IMX219_REG_VALUE_16BIT,
934 static const struct v4l2_rect *
935 __imx219_get_pad_crop(struct imx219 *imx219,
936 struct v4l2_subdev_state *sd_state,
937 unsigned int pad, enum v4l2_subdev_format_whence which)
940 case V4L2_SUBDEV_FORMAT_TRY:
941 return v4l2_subdev_get_try_crop(&imx219->sd, sd_state, pad);
942 case V4L2_SUBDEV_FORMAT_ACTIVE:
943 return &imx219->mode->crop;
949 static int imx219_get_selection(struct v4l2_subdev *sd,
950 struct v4l2_subdev_state *sd_state,
951 struct v4l2_subdev_selection *sel)
953 switch (sel->target) {
954 case V4L2_SEL_TGT_CROP: {
955 struct imx219 *imx219 = to_imx219(sd);
957 mutex_lock(&imx219->mutex);
958 sel->r = *__imx219_get_pad_crop(imx219, sd_state, sel->pad,
960 mutex_unlock(&imx219->mutex);
965 case V4L2_SEL_TGT_NATIVE_SIZE:
968 sel->r.width = IMX219_NATIVE_WIDTH;
969 sel->r.height = IMX219_NATIVE_HEIGHT;
973 case V4L2_SEL_TGT_CROP_DEFAULT:
974 case V4L2_SEL_TGT_CROP_BOUNDS:
975 sel->r.top = IMX219_PIXEL_ARRAY_TOP;
976 sel->r.left = IMX219_PIXEL_ARRAY_LEFT;
977 sel->r.width = IMX219_PIXEL_ARRAY_WIDTH;
978 sel->r.height = IMX219_PIXEL_ARRAY_HEIGHT;
986 static int imx219_configure_lanes(struct imx219 *imx219)
988 return imx219_write_reg(imx219, IMX219_REG_CSI_LANE_MODE,
989 IMX219_REG_VALUE_08BIT, (imx219->lanes == 2) ?
990 IMX219_CSI_2_LANE_MODE : IMX219_CSI_4_LANE_MODE);
993 static int imx219_start_streaming(struct imx219 *imx219)
995 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
996 const struct imx219_reg_list *reg_list;
999 ret = pm_runtime_resume_and_get(&client->dev);
1003 /* Send all registers that are common to all modes */
1004 ret = imx219_write_regs(imx219, imx219_common_regs, ARRAY_SIZE(imx219_common_regs));
1006 dev_err(&client->dev, "%s failed to send mfg header\n", __func__);
1010 /* Configure two or four Lane mode */
1011 ret = imx219_configure_lanes(imx219);
1013 dev_err(&client->dev, "%s failed to configure lanes\n", __func__);
1017 /* Apply default values of current mode */
1018 reg_list = &imx219->mode->reg_list;
1019 ret = imx219_write_regs(imx219, reg_list->regs, reg_list->num_of_regs);
1021 dev_err(&client->dev, "%s failed to set mode\n", __func__);
1025 ret = imx219_set_framefmt(imx219);
1027 dev_err(&client->dev, "%s failed to set frame format: %d\n",
1032 ret = imx219_set_binning(imx219);
1034 dev_err(&client->dev, "%s failed to set binning: %d\n",
1039 /* Apply customized values from user */
1040 ret = __v4l2_ctrl_handler_setup(imx219->sd.ctrl_handler);
1044 /* set stream on register */
1045 ret = imx219_write_reg(imx219, IMX219_REG_MODE_SELECT,
1046 IMX219_REG_VALUE_08BIT, IMX219_MODE_STREAMING);
1050 /* vflip and hflip cannot change during streaming */
1051 __v4l2_ctrl_grab(imx219->vflip, true);
1052 __v4l2_ctrl_grab(imx219->hflip, true);
1057 pm_runtime_put(&client->dev);
1061 static void imx219_stop_streaming(struct imx219 *imx219)
1063 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
1066 /* set stream off register */
1067 ret = imx219_write_reg(imx219, IMX219_REG_MODE_SELECT,
1068 IMX219_REG_VALUE_08BIT, IMX219_MODE_STANDBY);
1070 dev_err(&client->dev, "%s failed to set stream\n", __func__);
1072 __v4l2_ctrl_grab(imx219->vflip, false);
1073 __v4l2_ctrl_grab(imx219->hflip, false);
1075 pm_runtime_put(&client->dev);
1078 static int imx219_set_stream(struct v4l2_subdev *sd, int enable)
1080 struct imx219 *imx219 = to_imx219(sd);
1083 mutex_lock(&imx219->mutex);
1084 if (imx219->streaming == enable) {
1085 mutex_unlock(&imx219->mutex);
1091 * Apply default & customized values
1092 * and then start streaming.
1094 ret = imx219_start_streaming(imx219);
1098 imx219_stop_streaming(imx219);
1101 imx219->streaming = enable;
1103 mutex_unlock(&imx219->mutex);
1108 mutex_unlock(&imx219->mutex);
1113 /* Power/clock management functions */
1114 static int imx219_power_on(struct device *dev)
1116 struct v4l2_subdev *sd = dev_get_drvdata(dev);
1117 struct imx219 *imx219 = to_imx219(sd);
1120 ret = regulator_bulk_enable(IMX219_NUM_SUPPLIES,
1123 dev_err(dev, "%s: failed to enable regulators\n",
1128 ret = clk_prepare_enable(imx219->xclk);
1130 dev_err(dev, "%s: failed to enable clock\n",
1135 gpiod_set_value_cansleep(imx219->reset_gpio, 1);
1136 usleep_range(IMX219_XCLR_MIN_DELAY_US,
1137 IMX219_XCLR_MIN_DELAY_US + IMX219_XCLR_DELAY_RANGE_US);
1142 regulator_bulk_disable(IMX219_NUM_SUPPLIES, imx219->supplies);
1147 static int imx219_power_off(struct device *dev)
1149 struct v4l2_subdev *sd = dev_get_drvdata(dev);
1150 struct imx219 *imx219 = to_imx219(sd);
1152 gpiod_set_value_cansleep(imx219->reset_gpio, 0);
1153 regulator_bulk_disable(IMX219_NUM_SUPPLIES, imx219->supplies);
1154 clk_disable_unprepare(imx219->xclk);
1159 static int __maybe_unused imx219_suspend(struct device *dev)
1161 struct v4l2_subdev *sd = dev_get_drvdata(dev);
1162 struct imx219 *imx219 = to_imx219(sd);
1164 if (imx219->streaming)
1165 imx219_stop_streaming(imx219);
1170 static int __maybe_unused imx219_resume(struct device *dev)
1172 struct v4l2_subdev *sd = dev_get_drvdata(dev);
1173 struct imx219 *imx219 = to_imx219(sd);
1176 if (imx219->streaming) {
1177 ret = imx219_start_streaming(imx219);
1185 imx219_stop_streaming(imx219);
1186 imx219->streaming = false;
1191 static int imx219_get_regulators(struct imx219 *imx219)
1193 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
1196 for (i = 0; i < IMX219_NUM_SUPPLIES; i++)
1197 imx219->supplies[i].supply = imx219_supply_name[i];
1199 return devm_regulator_bulk_get(&client->dev,
1200 IMX219_NUM_SUPPLIES,
1204 /* Verify chip ID */
1205 static int imx219_identify_module(struct imx219 *imx219)
1207 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
1211 ret = imx219_read_reg(imx219, IMX219_REG_CHIP_ID,
1212 IMX219_REG_VALUE_16BIT, &val);
1214 dev_err(&client->dev, "failed to read chip id %x\n",
1219 if (val != IMX219_CHIP_ID) {
1220 dev_err(&client->dev, "chip id mismatch: %x!=%x\n",
1221 IMX219_CHIP_ID, val);
1228 static const struct v4l2_subdev_core_ops imx219_core_ops = {
1229 .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
1230 .unsubscribe_event = v4l2_event_subdev_unsubscribe,
1233 static const struct v4l2_subdev_video_ops imx219_video_ops = {
1234 .s_stream = imx219_set_stream,
1237 static const struct v4l2_subdev_pad_ops imx219_pad_ops = {
1238 .enum_mbus_code = imx219_enum_mbus_code,
1239 .get_fmt = imx219_get_pad_format,
1240 .set_fmt = imx219_set_pad_format,
1241 .get_selection = imx219_get_selection,
1242 .enum_frame_size = imx219_enum_frame_size,
1245 static const struct v4l2_subdev_ops imx219_subdev_ops = {
1246 .core = &imx219_core_ops,
1247 .video = &imx219_video_ops,
1248 .pad = &imx219_pad_ops,
1251 static const struct v4l2_subdev_internal_ops imx219_internal_ops = {
1252 .open = imx219_open,
1255 static unsigned long imx219_get_pixel_rate(struct imx219 *imx219)
1257 return (imx219->lanes == 2) ? IMX219_PIXEL_RATE : IMX219_PIXEL_RATE_4LANE;
1260 /* Initialize control handlers */
1261 static int imx219_init_controls(struct imx219 *imx219)
1263 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
1264 struct v4l2_ctrl_handler *ctrl_hdlr;
1265 unsigned int height = imx219->mode->height;
1266 struct v4l2_fwnode_device_properties props;
1267 int exposure_max, exposure_def, hblank;
1270 ctrl_hdlr = &imx219->ctrl_handler;
1271 ret = v4l2_ctrl_handler_init(ctrl_hdlr, 12);
1275 mutex_init(&imx219->mutex);
1276 ctrl_hdlr->lock = &imx219->mutex;
1278 /* By default, PIXEL_RATE is read only */
1279 imx219->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops,
1280 V4L2_CID_PIXEL_RATE,
1281 imx219_get_pixel_rate(imx219),
1282 imx219_get_pixel_rate(imx219), 1,
1283 imx219_get_pixel_rate(imx219));
1286 v4l2_ctrl_new_int_menu(ctrl_hdlr, &imx219_ctrl_ops,
1288 ARRAY_SIZE(imx219_link_freq_menu) - 1, 0,
1289 (imx219->lanes == 2) ? imx219_link_freq_menu :
1290 imx219_link_freq_4lane_menu);
1291 if (imx219->link_freq)
1292 imx219->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1294 /* Initial vblank/hblank/exposure parameters based on current mode */
1295 imx219->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops,
1296 V4L2_CID_VBLANK, IMX219_VBLANK_MIN,
1297 IMX219_VTS_MAX - height, 1,
1298 imx219->mode->vts_def - height);
1299 hblank = IMX219_PPL_DEFAULT - imx219->mode->width;
1300 imx219->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops,
1301 V4L2_CID_HBLANK, hblank, hblank,
1304 imx219->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1305 exposure_max = imx219->mode->vts_def - 4;
1306 exposure_def = (exposure_max < IMX219_EXPOSURE_DEFAULT) ?
1307 exposure_max : IMX219_EXPOSURE_DEFAULT;
1308 imx219->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops,
1310 IMX219_EXPOSURE_MIN, exposure_max,
1311 IMX219_EXPOSURE_STEP,
1314 v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
1315 IMX219_ANA_GAIN_MIN, IMX219_ANA_GAIN_MAX,
1316 IMX219_ANA_GAIN_STEP, IMX219_ANA_GAIN_DEFAULT);
1318 v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
1319 IMX219_DGTL_GAIN_MIN, IMX219_DGTL_GAIN_MAX,
1320 IMX219_DGTL_GAIN_STEP, IMX219_DGTL_GAIN_DEFAULT);
1322 imx219->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops,
1323 V4L2_CID_HFLIP, 0, 1, 1, 0);
1325 imx219->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT;
1327 imx219->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops,
1328 V4L2_CID_VFLIP, 0, 1, 1, 0);
1330 imx219->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT;
1332 v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &imx219_ctrl_ops,
1333 V4L2_CID_TEST_PATTERN,
1334 ARRAY_SIZE(imx219_test_pattern_menu) - 1,
1335 0, 0, imx219_test_pattern_menu);
1336 for (i = 0; i < 4; i++) {
1338 * The assumption is that
1339 * V4L2_CID_TEST_PATTERN_GREENR == V4L2_CID_TEST_PATTERN_RED + 1
1340 * V4L2_CID_TEST_PATTERN_BLUE == V4L2_CID_TEST_PATTERN_RED + 2
1341 * V4L2_CID_TEST_PATTERN_GREENB == V4L2_CID_TEST_PATTERN_RED + 3
1343 v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops,
1344 V4L2_CID_TEST_PATTERN_RED + i,
1345 IMX219_TESTP_COLOUR_MIN,
1346 IMX219_TESTP_COLOUR_MAX,
1347 IMX219_TESTP_COLOUR_STEP,
1348 IMX219_TESTP_COLOUR_MAX);
1349 /* The "Solid color" pattern is white by default */
1352 if (ctrl_hdlr->error) {
1353 ret = ctrl_hdlr->error;
1354 dev_err(&client->dev, "%s control init failed (%d)\n",
1359 ret = v4l2_fwnode_device_parse(&client->dev, &props);
1363 ret = v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &imx219_ctrl_ops,
1368 imx219->sd.ctrl_handler = ctrl_hdlr;
1373 v4l2_ctrl_handler_free(ctrl_hdlr);
1374 mutex_destroy(&imx219->mutex);
1379 static void imx219_free_controls(struct imx219 *imx219)
1381 v4l2_ctrl_handler_free(imx219->sd.ctrl_handler);
1382 mutex_destroy(&imx219->mutex);
1385 static int imx219_check_hwcfg(struct device *dev, struct imx219 *imx219)
1387 struct fwnode_handle *endpoint;
1388 struct v4l2_fwnode_endpoint ep_cfg = {
1389 .bus_type = V4L2_MBUS_CSI2_DPHY
1393 endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
1395 dev_err(dev, "endpoint node not found\n");
1399 if (v4l2_fwnode_endpoint_alloc_parse(endpoint, &ep_cfg)) {
1400 dev_err(dev, "could not parse endpoint\n");
1404 /* Check the number of MIPI CSI2 data lanes */
1405 if (ep_cfg.bus.mipi_csi2.num_data_lanes != 2 &&
1406 ep_cfg.bus.mipi_csi2.num_data_lanes != 4) {
1407 dev_err(dev, "only 2 or 4 data lanes are currently supported\n");
1410 imx219->lanes = ep_cfg.bus.mipi_csi2.num_data_lanes;
1412 /* Check the link frequency set in device tree */
1413 if (!ep_cfg.nr_of_link_frequencies) {
1414 dev_err(dev, "link-frequency property not found in DT\n");
1418 if (ep_cfg.nr_of_link_frequencies != 1 ||
1419 (ep_cfg.link_frequencies[0] != ((imx219->lanes == 2) ?
1420 IMX219_DEFAULT_LINK_FREQ : IMX219_DEFAULT_LINK_FREQ_4LANE))) {
1421 dev_err(dev, "Link frequency not supported: %lld\n",
1422 ep_cfg.link_frequencies[0]);
1429 v4l2_fwnode_endpoint_free(&ep_cfg);
1430 fwnode_handle_put(endpoint);
1435 static int imx219_probe(struct i2c_client *client)
1437 struct device *dev = &client->dev;
1438 struct imx219 *imx219;
1441 imx219 = devm_kzalloc(&client->dev, sizeof(*imx219), GFP_KERNEL);
1445 v4l2_i2c_subdev_init(&imx219->sd, client, &imx219_subdev_ops);
1447 /* Check the hardware configuration in device tree */
1448 if (imx219_check_hwcfg(dev, imx219))
1451 /* Get system clock (xclk) */
1452 imx219->xclk = devm_clk_get(dev, NULL);
1453 if (IS_ERR(imx219->xclk)) {
1454 dev_err(dev, "failed to get xclk\n");
1455 return PTR_ERR(imx219->xclk);
1458 imx219->xclk_freq = clk_get_rate(imx219->xclk);
1459 if (imx219->xclk_freq != IMX219_XCLK_FREQ) {
1460 dev_err(dev, "xclk frequency not supported: %d Hz\n",
1465 ret = imx219_get_regulators(imx219);
1467 dev_err(dev, "failed to get regulators\n");
1471 /* Request optional enable pin */
1472 imx219->reset_gpio = devm_gpiod_get_optional(dev, "reset",
1476 * The sensor must be powered for imx219_identify_module()
1477 * to be able to read the CHIP_ID register
1479 ret = imx219_power_on(dev);
1483 ret = imx219_identify_module(imx219);
1485 goto error_power_off;
1487 /* Set default mode to max resolution */
1488 imx219->mode = &supported_modes[0];
1490 /* sensor doesn't enter LP-11 state upon power up until and unless
1491 * streaming is started, so upon power up switch the modes to:
1492 * streaming -> standby
1494 ret = imx219_write_reg(imx219, IMX219_REG_MODE_SELECT,
1495 IMX219_REG_VALUE_08BIT, IMX219_MODE_STREAMING);
1497 goto error_power_off;
1498 usleep_range(100, 110);
1500 /* put sensor back to standby mode */
1501 ret = imx219_write_reg(imx219, IMX219_REG_MODE_SELECT,
1502 IMX219_REG_VALUE_08BIT, IMX219_MODE_STANDBY);
1504 goto error_power_off;
1505 usleep_range(100, 110);
1507 ret = imx219_init_controls(imx219);
1509 goto error_power_off;
1511 /* Initialize subdev */
1512 imx219->sd.internal_ops = &imx219_internal_ops;
1513 imx219->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
1514 V4L2_SUBDEV_FL_HAS_EVENTS;
1515 imx219->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
1517 /* Initialize source pad */
1518 imx219->pad.flags = MEDIA_PAD_FL_SOURCE;
1520 /* Initialize default format */
1521 imx219_set_default_format(imx219);
1523 ret = media_entity_pads_init(&imx219->sd.entity, 1, &imx219->pad);
1525 dev_err(dev, "failed to init entity pads: %d\n", ret);
1526 goto error_handler_free;
1529 ret = v4l2_async_register_subdev_sensor(&imx219->sd);
1531 dev_err(dev, "failed to register sensor sub-device: %d\n", ret);
1532 goto error_media_entity;
1535 /* Enable runtime PM and turn off the device */
1536 pm_runtime_set_active(dev);
1537 pm_runtime_enable(dev);
1538 pm_runtime_idle(dev);
1543 media_entity_cleanup(&imx219->sd.entity);
1546 imx219_free_controls(imx219);
1549 imx219_power_off(dev);
1554 static void imx219_remove(struct i2c_client *client)
1556 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1557 struct imx219 *imx219 = to_imx219(sd);
1559 v4l2_async_unregister_subdev(sd);
1560 media_entity_cleanup(&sd->entity);
1561 imx219_free_controls(imx219);
1563 pm_runtime_disable(&client->dev);
1564 if (!pm_runtime_status_suspended(&client->dev))
1565 imx219_power_off(&client->dev);
1566 pm_runtime_set_suspended(&client->dev);
1569 static const struct of_device_id imx219_dt_ids[] = {
1570 { .compatible = "sony,imx219" },
1573 MODULE_DEVICE_TABLE(of, imx219_dt_ids);
1575 static const struct dev_pm_ops imx219_pm_ops = {
1576 SET_SYSTEM_SLEEP_PM_OPS(imx219_suspend, imx219_resume)
1577 SET_RUNTIME_PM_OPS(imx219_power_off, imx219_power_on, NULL)
1580 static struct i2c_driver imx219_i2c_driver = {
1583 .of_match_table = imx219_dt_ids,
1584 .pm = &imx219_pm_ops,
1586 .probe_new = imx219_probe,
1587 .remove = imx219_remove,
1590 module_i2c_driver(imx219_i2c_driver);
1593 MODULE_DESCRIPTION("Sony IMX219 sensor driver");
1594 MODULE_LICENSE("GPL v2");