1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
8 #include <asm/unaligned.h>
10 #include <linux/clk.h>
11 #include <linux/delay.h>
12 #include <linux/device.h>
13 #include <linux/gpio/consumer.h>
14 #include <linux/i2c.h>
15 #include <linux/module.h>
17 #include <linux/pm_runtime.h>
18 #include <linux/property.h>
19 #include <linux/regulator/consumer.h>
20 #include <linux/slab.h>
22 #include <media/media-entity.h>
23 #include <media/v4l2-async.h>
24 #include <media/v4l2-common.h>
25 #include <media/v4l2-ctrls.h>
26 #include <media/v4l2-device.h>
27 #include <media/v4l2-event.h>
28 #include <media/v4l2-fwnode.h>
29 #include <media/v4l2-mediabus.h>
30 #include <media/v4l2-subdev.h>
32 #define OV8858_LINK_FREQ 360000000U
33 #define OV8858_XVCLK_FREQ 24000000
35 #define OV8858_REG_SIZE_SHIFT 16
36 #define OV8858_REG_ADDR_MASK 0xffff
37 #define OV8858_REG_8BIT(n) ((1U << OV8858_REG_SIZE_SHIFT) | (n))
38 #define OV8858_REG_16BIT(n) ((2U << OV8858_REG_SIZE_SHIFT) | (n))
39 #define OV8858_REG_24BIT(n) ((3U << OV8858_REG_SIZE_SHIFT) | (n))
41 #define OV8858_REG_SC_CTRL0100 OV8858_REG_8BIT(0x0100)
42 #define OV8858_MODE_SW_STANDBY 0x0
43 #define OV8858_MODE_STREAMING 0x1
45 #define OV8858_REG_CHIP_ID OV8858_REG_24BIT(0x300a)
46 #define OV8858_CHIP_ID 0x008858
48 #define OV8858_REG_SUB_ID OV8858_REG_8BIT(0x302a)
49 #define OV8858_R1A 0xb0
50 #define OV8858_R2A 0xb2
52 #define OV8858_REG_LONG_EXPO OV8858_REG_24BIT(0x3500)
53 #define OV8858_EXPOSURE_MIN 4
54 #define OV8858_EXPOSURE_STEP 1
55 #define OV8858_EXPOSURE_MARGIN 4
57 #define OV8858_REG_LONG_GAIN OV8858_REG_16BIT(0x3508)
58 #define OV8858_LONG_GAIN_MIN 0x0
59 #define OV8858_LONG_GAIN_MAX 0x7ff
60 #define OV8858_LONG_GAIN_STEP 1
61 #define OV8858_LONG_GAIN_DEFAULT 0x80
63 #define OV8858_REG_LONG_DIGIGAIN OV8858_REG_16BIT(0x350a)
64 #define OV8858_LONG_DIGIGAIN_H_MASK 0x3fc0
65 #define OV8858_LONG_DIGIGAIN_L_MASK 0x3f
66 #define OV8858_LONG_DIGIGAIN_H_SHIFT 2
67 #define OV8858_LONG_DIGIGAIN_MIN 0x0
68 #define OV8858_LONG_DIGIGAIN_MAX 0x3fff
69 #define OV8858_LONG_DIGIGAIN_STEP 1
70 #define OV8858_LONG_DIGIGAIN_DEFAULT 0x200
72 #define OV8858_REG_VTS OV8858_REG_16BIT(0x380e)
73 #define OV8858_VTS_MAX 0x7fff
75 #define OV8858_REG_TEST_PATTERN OV8858_REG_8BIT(0x5e00)
76 #define OV8858_TEST_PATTERN_ENABLE 0x80
77 #define OV8858_TEST_PATTERN_DISABLE 0x0
79 #define REG_NULL 0xffff
81 static const char * const ov8858_supply_names[] = {
82 "avdd", /* Analog power */
83 "dovdd", /* Digital I/O power */
84 "dvdd", /* Digital core power */
93 const struct regval *mode_2lanes;
94 const struct regval *mode_4lanes;
103 const struct regval_modes reg_modes;
108 struct gpio_desc *reset_gpio;
109 struct gpio_desc *pwdn_gpio;
110 struct regulator_bulk_data supplies[ARRAY_SIZE(ov8858_supply_names)];
112 struct v4l2_subdev subdev;
113 struct media_pad pad;
115 struct v4l2_ctrl_handler ctrl_handler;
116 struct v4l2_ctrl *exposure;
117 struct v4l2_ctrl *hblank;
118 struct v4l2_ctrl *vblank;
120 const struct regval *global_regs;
122 unsigned int num_lanes;
125 static inline struct ov8858 *sd_to_ov8858(struct v4l2_subdev *sd)
127 return container_of(sd, struct ov8858, subdev);
130 static const struct regval ov8858_global_regs_r1a[] = {
400 static const struct regval ov8858_global_regs_r2a_2lane[] = {
402 * MIPI=720Mbps, SysClk=144Mhz,Dac Clock=360Mhz.
403 * v00_01_00 (05/29/2014) : initial setting
404 * AM19 : 3617 <- 0xC0
405 * AM20 : change FWC_6K_EN to be default 0x3618=0x5a
407 {0x0103, 0x01}, /* software reset */
408 {0x0100, 0x00}, /* software standby */
409 {0x0302, 0x1e}, /* pll1_multi */
410 {0x0303, 0x00}, /* pll1_divm */
411 {0x0304, 0x03}, /* pll1_div_mipi */
412 {0x030e, 0x02}, /* pll2_rdiv */
413 {0x030f, 0x04}, /* pll2_divsp */
414 {0x0312, 0x03}, /* pll2_pre_div0, pll2_r_divdac */
415 {0x031e, 0x0c}, /* pll1_no_lat */
457 {0x3018, 0x32}, /* MIPI 2 lane */
458 {0x3020, 0x93}, /* Clock switch output normal, pclk_div =/1 */
459 {0x3022, 0x01}, /* pd_mipi enable when rst_sync */
460 {0x3031, 0x0a}, /* MIPI 10-bit mode */
462 {0x3106, 0x01}, /* sclk_div, sclk_pre_div */
473 {0x3500, 0x00}, /* exposure H */
474 {0x3501, 0x4d}, /* exposure M */
475 {0x3502, 0x40}, /* exposure L */
476 {0x3503, 0x80}, /* gain delay ?, exposure delay 1 frame, real gain */
477 {0x3505, 0x80}, /* gain option */
478 {0x3508, 0x02}, /* gain H */
479 {0x3509, 0x00}, /* gain L */
480 {0x350c, 0x00}, /* short gain H */
481 {0x350d, 0x80}, /* short gain L */
482 {0x3510, 0x00}, /* short exposure H */
483 {0x3511, 0x02}, /* short exposure M */
484 {0x3512, 0x00}, /* short exposure L */
581 {0x3800, 0x00}, /* x start H */
582 {0x3801, 0x0c}, /* x start L */
583 {0x3802, 0x00}, /* y start H */
584 {0x3803, 0x0c}, /* y start L */
585 {0x3804, 0x0c}, /* x end H */
586 {0x3805, 0xd3}, /* x end L */
587 {0x3806, 0x09}, /* y end H */
588 {0x3807, 0xa3}, /* y end L */
589 {0x3808, 0x06}, /* x output size H */
590 {0x3809, 0x60}, /* x output size L */
591 {0x380a, 0x04}, /* y output size H */
592 {0x380b, 0xc8}, /* y output size L */
593 {0x380c, 0x07}, /* HTS H */
594 {0x380d, 0x88}, /* HTS L */
595 {0x380e, 0x04}, /* VTS H */
596 {0x380f, 0xdc}, /* VTS L */
597 {0x3810, 0x00}, /* ISP x win H */
598 {0x3811, 0x04}, /* ISP x win L */
599 {0x3813, 0x02}, /* ISP y win L */
600 {0x3814, 0x03}, /* x odd inc */
601 {0x3815, 0x01}, /* x even inc */
602 {0x3820, 0x00}, /* vflip off */
603 {0x3821, 0x67}, /* mirror on, bin on */
604 {0x382a, 0x03}, /* y odd inc */
605 {0x382b, 0x01}, /* y even inc */
609 {0x3841, 0xff}, /* window auto size enable */
611 {0x3d85, 0x16}, /* OTP power up load data enable with BIST */
612 {0x3d8c, 0x73}, /* OTP setting start High */
613 {0x3d8d, 0xde}, /* OTP setting start Low */
616 {0x4000, 0xf1}, /* out_range_trig, format_chg_trig */
617 {0x4001, 0x10}, /* total 128 black column */
618 {0x4005, 0x10}, /* BLC target L */
619 {0x4002, 0x27}, /* value used to limit BLC offset */
620 {0x4009, 0x81}, /* final BLC offset limitation enable */
621 {0x400b, 0x0c}, /* DCBLC on, DCBLC manual mode on */
622 {0x401b, 0x00}, /* zero line R coefficient */
623 {0x401d, 0x00}, /* zoro line T coefficient */
624 {0x4020, 0x00}, /* Anchor left start H */
625 {0x4021, 0x04}, /* Anchor left start L */
626 {0x4022, 0x06}, /* Anchor left end H */
627 {0x4023, 0x00}, /* Anchor left end L */
628 {0x4024, 0x0f}, /* Anchor right start H */
629 {0x4025, 0x2a}, /* Anchor right start L */
630 {0x4026, 0x0f}, /* Anchor right end H */
631 {0x4027, 0x2b}, /* Anchor right end L */
632 {0x4028, 0x00}, /* top zero line start */
633 {0x4029, 0x02}, /* top zero line number */
634 {0x402a, 0x04}, /* top black line start */
635 {0x402b, 0x04}, /* top black line number */
636 {0x402c, 0x00}, /* bottom zero line start */
637 {0x402d, 0x02}, /* bottom zoro line number */
638 {0x402e, 0x04}, /* bottom black line start */
639 {0x402f, 0x04}, /* bottom black line number */
640 {0x401f, 0x00}, /* interpolation x/y disable, Anchor one disable */
642 {0x403d, 0x04}, /* md_precision_en */
643 {0x4300, 0xff}, /* clip max H */
644 {0x4301, 0x00}, /* clip min H */
645 {0x4302, 0x0f}, /* clip min L, clip max L */
651 {0x481f, 0x32}, /* clk prepare min */
652 {0x4837, 0x16}, /* global timing */
653 {0x4850, 0x10}, /* lane 1 = 1, lane 0 = 0 */
654 {0x4851, 0x32}, /* lane 3 = 3, lane 2 = 2 */
657 {0x4d00, 0x04}, /* temperature sensor */
662 {0x4d05, 0xff}, /* temperature sensor */
663 {0x5000, 0xfe}, /* lenc on, slave/master AWB gain/statistics enable */
664 {0x5001, 0x01}, /* BLC on */
665 {0x5002, 0x08}, /* H scale off, WBMATCH off, OTP_DPC */
666 {0x5003, 0x20}, /* DPC_DBC buffer control enable, WB */
667 {0x501e, 0x93}, /* enable digital gain */
669 {0x5780, 0x3e}, /* DPC */
689 {0x5794, 0xa3}, /* DPC */
690 {0x5871, 0x0d}, /* Lenc */
695 {0x58f8, 0x3d}, /* Lenc */
696 {0x5901, 0x00}, /* H skip off, V skip off */
697 {0x5b00, 0x02}, /* OTP DPC start address */
698 {0x5b01, 0x10}, /* OTP DPC start address */
699 {0x5b02, 0x03}, /* OTP DPC end address */
700 {0x5b03, 0xcf}, /* OTP DPC end address */
701 {0x5b05, 0x6c}, /* recover method = 2b11, */
702 {0x5e00, 0x00}, /* use 0x3ff to test pattern off */
703 {0x5e01, 0x41}, /* window cut enable */
705 {0x4825, 0x3a}, /* lpx_p_min */
706 {0x4826, 0x40}, /* hs_prepare_min */
707 {0x4808, 0x25}, /* wake up delay in 1/1024 s */
712 {0x400d, 0x10}, /* BLC offset trigger L */
713 {0x4040, 0x04}, /* BLC gain th2 */
714 {0x403e, 0x04}, /* BLC gain th1 */
715 {0x4041, 0xc6}, /* BLC */
723 * max_framerate 30fps
724 * mipi_datarate per lane 720Mbps
726 static const struct regval ov8858_1632x1224_regs_2lane[] = {
728 * MIPI=720Mbps, SysClk=144Mhz,Dac Clock=360Mhz.
729 * v00_01_00 (05/29/2014) : initial setting
730 * AM19 : 3617 <- 0xC0
731 * AM20 : change FWC_6K_EN to be default 0x3618=0x5a
734 {0x3501, 0x4d}, /* exposure M */
735 {0x3502, 0x40}, /* exposure L */
737 {0x3808, 0x06}, /* x output size H */
738 {0x3809, 0x60}, /* x output size L */
739 {0x380a, 0x04}, /* y output size H */
740 {0x380b, 0xc8}, /* y output size L */
741 {0x380c, 0x07}, /* HTS H */
742 {0x380d, 0x88}, /* HTS L */
743 {0x380e, 0x04}, /* VTS H */
744 {0x380f, 0xdc}, /* VTS L */
745 {0x3814, 0x03}, /* x odd inc */
746 {0x3821, 0x67}, /* mirror on, bin on */
747 {0x382a, 0x03}, /* y odd inc */
751 {0x4001, 0x10}, /* total 128 black column */
752 {0x4022, 0x06}, /* Anchor left end H */
753 {0x4023, 0x00}, /* Anchor left end L */
754 {0x4025, 0x2a}, /* Anchor right start L */
755 {0x4027, 0x2b}, /* Anchor right end L */
756 {0x402b, 0x04}, /* top black line number */
757 {0x402f, 0x04}, /* bottom black line number */
768 * max_framerate 15fps
769 * mipi_datarate per lane 720Mbps
771 static const struct regval ov8858_3264x2448_regs_2lane[] = {
773 {0x3501, 0x9a}, /* exposure M */
774 {0x3502, 0x20}, /* exposure L */
776 {0x3808, 0x0c}, /* x output size H */
777 {0x3809, 0xc0}, /* x output size L */
778 {0x380a, 0x09}, /* y output size H */
779 {0x380b, 0x90}, /* y output size L */
780 {0x380c, 0x07}, /* HTS H */
781 {0x380d, 0x94}, /* HTS L */
782 {0x380e, 0x09}, /* VTS H */
783 {0x380f, 0xaa}, /* VTS L */
784 {0x3814, 0x01}, /* x odd inc */
785 {0x3821, 0x46}, /* mirror on, bin off */
786 {0x382a, 0x01}, /* y odd inc */
790 {0x4001, 0x00}, /* total 256 black column */
791 {0x4022, 0x0c}, /* Anchor left end H */
792 {0x4023, 0x60}, /* Anchor left end L */
793 {0x4025, 0x36}, /* Anchor right start L */
794 {0x4027, 0x37}, /* Anchor right end L */
795 {0x402b, 0x08}, /* top black line number */
796 {0x402f, 0x08}, /* bottom black line number */
804 static const struct regval ov8858_global_regs_r2a_4lane[] = {
806 * MIPI=720Mbps, SysClk=144Mhz,Dac Clock=360Mhz.
807 * v00_01_00 (05/29/2014) : initial setting
808 * AM19 : 3617 <- 0xC0
809 * AM20 : change FWC_6K_EN to be default 0x3618=0x5a
811 {0x0103, 0x01}, /* software reset for OVTATool only */
812 {0x0103, 0x01}, /* software reset */
813 {0x0100, 0x00}, /* software standby */
814 {0x0302, 0x1e}, /* pll1_multi */
815 {0x0303, 0x00}, /* pll1_divm */
816 {0x0304, 0x03}, /* pll1_div_mipi */
817 {0x030e, 0x00}, /* pll2_rdiv */
818 {0x030f, 0x04}, /* pll2_divsp */
819 {0x0312, 0x01}, /* pll2_pre_div0, pll2_r_divdac */
820 {0x031e, 0x0c}, /* pll1_no_lat */
862 {0x3018, 0x72}, /* MIPI 4 lane */
863 {0x3020, 0x93}, /* Clock switch output normal, pclk_div =/1 */
864 {0x3022, 0x01}, /* pd_mipi enable when rst_sync */
865 {0x3031, 0x0a}, /* MIPI 10-bit mode */
867 {0x3106, 0x01}, /* sclk_div, sclk_pre_div */
878 {0x3500, 0x00}, /* exposure H */
879 {0x3501, 0x4d}, /* exposure M */
880 {0x3502, 0x40}, /* exposure L */
881 {0x3503, 0x80}, /* gain delay ?, exposure delay 1 frame, real gain */
882 {0x3505, 0x80}, /* gain option */
883 {0x3508, 0x02}, /* gain H */
884 {0x3509, 0x00}, /* gain L */
885 {0x350c, 0x00}, /* short gain H */
886 {0x350d, 0x80}, /* short gain L */
887 {0x3510, 0x00}, /* short exposure H */
888 {0x3511, 0x02}, /* short exposure M */
889 {0x3512, 0x00}, /* short exposure L */
986 {0x3800, 0x00}, /* x start H */
987 {0x3801, 0x0c}, /* x start L */
988 {0x3802, 0x00}, /* y start H */
989 {0x3803, 0x0c}, /* y start L */
990 {0x3804, 0x0c}, /* x end H */
991 {0x3805, 0xd3}, /* x end L */
992 {0x3806, 0x09}, /* y end H */
993 {0x3807, 0xa3}, /* y end L */
994 {0x3808, 0x06}, /* x output size H */
995 {0x3809, 0x60}, /* x output size L */
996 {0x380a, 0x04}, /* y output size H */
997 {0x380b, 0xc8}, /* y output size L */
998 {0x380c, 0x07}, /* HTS H */
999 {0x380d, 0x88}, /* HTS L */
1000 {0x380e, 0x04}, /* VTS H */
1001 {0x380f, 0xdc}, /* VTS L */
1002 {0x3810, 0x00}, /* ISP x win H */
1003 {0x3811, 0x04}, /* ISP x win L */
1004 {0x3813, 0x02}, /* ISP y win L */
1005 {0x3814, 0x03}, /* x odd inc */
1006 {0x3815, 0x01}, /* x even inc */
1007 {0x3820, 0x00}, /* vflip off */
1008 {0x3821, 0x67}, /* mirror on, bin o */
1009 {0x382a, 0x03}, /* y odd inc */
1010 {0x382b, 0x01}, /* y even inc */
1014 {0x3841, 0xff}, /* window auto size enable */
1016 {0x3d85, 0x16}, /* OTP power up load data/setting enable */
1017 {0x3d8c, 0x73}, /* OTP setting start High */
1018 {0x3d8d, 0xde}, /* OTP setting start Low */
1021 {0x4000, 0xf1}, /* out_range/format_chg/gain/exp_chg trig enable */
1022 {0x4001, 0x10}, /* total 128 black column */
1023 {0x4005, 0x10}, /* BLC target L */
1024 {0x4002, 0x27}, /* value used to limit BLC offset */
1025 {0x4009, 0x81}, /* final BLC offset limitation enable */
1026 {0x400b, 0x0c}, /* DCBLC on, DCBLC manual mode on */
1027 {0x401b, 0x00}, /* zero line R coefficient */
1028 {0x401d, 0x00}, /* zoro line T coefficient */
1029 {0x4020, 0x00}, /* Anchor left start H */
1030 {0x4021, 0x04}, /* Anchor left start L */
1031 {0x4022, 0x06}, /* Anchor left end H */
1032 {0x4023, 0x00}, /* Anchor left end L */
1033 {0x4024, 0x0f}, /* Anchor right start H */
1034 {0x4025, 0x2a}, /* Anchor right start L */
1035 {0x4026, 0x0f}, /* Anchor right end H */
1036 {0x4027, 0x2b}, /* Anchor right end L */
1037 {0x4028, 0x00}, /* top zero line start */
1038 {0x4029, 0x02}, /* top zero line number */
1039 {0x402a, 0x04}, /* top black line start */
1040 {0x402b, 0x04}, /* top black line number */
1041 {0x402c, 0x00}, /* bottom zero line start */
1042 {0x402d, 0x02}, /* bottom zoro line number */
1043 {0x402e, 0x04}, /* bottom black line start */
1044 {0x402f, 0x04}, /* bottom black line number */
1045 {0x401f, 0x00}, /* interpolation x/y disable, Anchor one disable */
1047 {0x403d, 0x04}, /* md_precision_en */
1048 {0x4300, 0xff}, /* clip max H */
1049 {0x4301, 0x00}, /* clip min H */
1050 {0x4302, 0x0f}, /* clip min L, clip max L */
1056 {0x481f, 0x32}, /* clk prepare min */
1057 {0x4837, 0x16}, /* global timing */
1058 {0x4850, 0x10}, /* lane 1 = 1, lane 0 = 0 */
1059 {0x4851, 0x32}, /* lane 3 = 3, lane 2 = 2 */
1062 {0x4d00, 0x04}, /* temperature sensor */
1067 {0x4d05, 0xff}, /* temperature sensor */
1068 {0x5000, 0xfe}, /* lenc on, slave/master AWB gain/statistics enable */
1069 {0x5001, 0x01}, /* BLC on */
1070 {0x5002, 0x08}, /* WBMATCH sensor's gain, H scale/WBMATCH/OTP_DPC off */
1071 {0x5003, 0x20}, /* DPC_DBC buffer control enable, WB */
1072 {0x501e, 0x93}, /* enable digital gain */
1074 {0x5780, 0x3e}, /* DPC */
1094 {0x5794, 0xa3}, /* DPC */
1095 {0x5871, 0x0d}, /* Lenc */
1100 {0x58f8, 0x3d}, /* Lenc */
1101 {0x5901, 0x00}, /* H skip off, V skip off */
1102 {0x5b00, 0x02}, /* OTP DPC start address */
1103 {0x5b01, 0x10}, /* OTP DPC start address */
1104 {0x5b02, 0x03}, /* OTP DPC end address */
1105 {0x5b03, 0xcf}, /* OTP DPC end address */
1106 {0x5b05, 0x6c}, /* recover method = 2b11 */
1107 {0x5e00, 0x00}, /* use 0x3ff to test pattern off */
1108 {0x5e01, 0x41}, /* window cut enable */
1110 {0x4825, 0x3a}, /* lpx_p_min */
1111 {0x4826, 0x40}, /* hs_prepare_min */
1112 {0x4808, 0x25}, /* wake up delay in 1/1024 s */
1117 {0x400d, 0x10}, /* BLC offset trigger L */
1118 {0x4040, 0x04}, /* BLC gain th2 */
1119 {0x403e, 0x04}, /* BLC gain th1 */
1120 {0x4041, 0xc6}, /* BLC */
1128 * max_framerate 60fps
1129 * mipi_datarate per lane 720Mbps
1131 static const struct regval ov8858_1632x1224_regs_4lane[] = {
1133 {0x3501, 0x4d}, /* exposure M */
1134 {0x3502, 0x40}, /* exposure L */
1135 {0x3808, 0x06}, /* x output size H */
1136 {0x3809, 0x60}, /* x output size L */
1137 {0x380a, 0x04}, /* y output size H */
1138 {0x380b, 0xc8}, /* y output size L */
1139 {0x380c, 0x07}, /* HTS H */
1140 {0x380d, 0x88}, /* HTS L */
1141 {0x380e, 0x04}, /* VTS H */
1142 {0x380f, 0xdc}, /* VTS L */
1143 {0x3814, 0x03}, /* x odd inc */
1144 {0x3821, 0x67}, /* mirror on, bin on */
1145 {0x382a, 0x03}, /* y odd inc */
1149 {0x4001, 0x10}, /* total 128 black column */
1150 {0x4022, 0x06}, /* Anchor left end H */
1151 {0x4023, 0x00}, /* Anchor left end L */
1152 {0x4025, 0x2a}, /* Anchor right start L */
1153 {0x4027, 0x2b}, /* Anchor right end L */
1154 {0x402b, 0x04}, /* top black line number */
1155 {0x402f, 0x04}, /* bottom black line number */
1166 * max_framerate 30fps
1167 * mipi_datarate per lane 720Mbps
1169 static const struct regval ov8858_3264x2448_regs_4lane[] = {
1171 {0x3501, 0x9a}, /* exposure M */
1172 {0x3502, 0x20}, /* exposure L */
1173 {0x3808, 0x0c}, /* x output size H */
1174 {0x3809, 0xc0}, /* x output size L */
1175 {0x380a, 0x09}, /* y output size H */
1176 {0x380b, 0x90}, /* y output size L */
1177 {0x380c, 0x07}, /* HTS H */
1178 {0x380d, 0x94}, /* HTS L */
1179 {0x380e, 0x09}, /* VTS H */
1180 {0x380f, 0xaa}, /* VTS L */
1181 {0x3814, 0x01}, /* x odd inc */
1182 {0x3821, 0x46}, /* mirror on, bin off */
1183 {0x382a, 0x01}, /* y odd inc */
1187 {0x4001, 0x00}, /* total 256 black column */
1188 {0x4022, 0x0c}, /* Anchor left end H */
1189 {0x4023, 0x60}, /* Anchor left end L */
1190 {0x4025, 0x36}, /* Anchor right start L */
1191 {0x4027, 0x37}, /* Anchor right end L */
1192 {0x402b, 0x08}, /* top black line number */
1193 {0x402f, 0x08}, /* interpolation x/y disable, Anchor one disable */
1201 static const struct ov8858_mode ov8858_modes[] = {
1206 .hts_def = 1940 * 2,
1209 .mode_2lanes = ov8858_3264x2448_regs_2lane,
1210 .mode_4lanes = ov8858_3264x2448_regs_4lane,
1217 .hts_def = 1928 * 2,
1220 .mode_2lanes = ov8858_1632x1224_regs_2lane,
1221 .mode_4lanes = ov8858_1632x1224_regs_4lane,
1226 static const s64 link_freq_menu_items[] = {
1230 static const char * const ov8858_test_pattern_menu[] = {
1232 "Vertical Color Bar Type 1",
1233 "Vertical Color Bar Type 2",
1234 "Vertical Color Bar Type 3",
1235 "Vertical Color Bar Type 4"
1238 /* ----------------------------------------------------------------------------
1242 static int ov8858_write(struct ov8858 *ov8858, u32 reg, u32 val, int *err)
1244 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev);
1245 unsigned int len = (reg >> OV8858_REG_SIZE_SHIFT) & 3;
1246 u16 addr = reg & OV8858_REG_ADDR_MASK;
1253 put_unaligned_be16(addr, buf);
1254 put_unaligned_be32(val << (8 * (4 - len)), buf + 2);
1256 ret = i2c_master_send(client, buf, len + 2);
1257 if (ret != len + 2) {
1258 ret = ret < 0 ? ret : -EIO;
1262 dev_err(&client->dev,
1263 "Failed to write reg %u: %d\n", addr, ret);
1270 static int ov8858_write_array(struct ov8858 *ov8858, const struct regval *regs)
1275 for (i = 0; ret == 0 && regs[i].addr != REG_NULL; ++i) {
1276 ov8858_write(ov8858, OV8858_REG_8BIT(regs[i].addr),
1283 static int ov8858_read(struct ov8858 *ov8858, u32 reg, u32 *val)
1285 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev);
1286 __be16 reg_addr_be = cpu_to_be16(reg & OV8858_REG_ADDR_MASK);
1287 unsigned int len = (reg >> OV8858_REG_SIZE_SHIFT) & 3;
1288 struct i2c_msg msgs[2];
1293 data_be_p = (u8 *)&data_be;
1295 /* Write register address */
1296 msgs[0].addr = client->addr;
1299 msgs[0].buf = (u8 *)®_addr_be;
1301 /* Read data from register */
1302 msgs[1].addr = client->addr;
1303 msgs[1].flags = I2C_M_RD;
1305 msgs[1].buf = &data_be_p[4 - len];
1307 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
1308 if (ret != ARRAY_SIZE(msgs)) {
1309 ret = ret < 0 ? ret : -EIO;
1310 dev_err(&client->dev,
1311 "Failed to read reg %u: %d\n", reg, ret);
1315 *val = be32_to_cpu(data_be);
1320 /* ----------------------------------------------------------------------------
1324 static int ov8858_start_stream(struct ov8858 *ov8858,
1325 struct v4l2_subdev_state *state)
1327 struct v4l2_mbus_framefmt *format;
1328 const struct ov8858_mode *mode;
1329 const struct regval *reg_list;
1332 ret = ov8858_write_array(ov8858, ov8858->global_regs);
1336 format = v4l2_subdev_get_pad_format(&ov8858->subdev, state, 0);
1337 mode = v4l2_find_nearest_size(ov8858_modes, ARRAY_SIZE(ov8858_modes),
1338 width, height, format->width,
1341 reg_list = ov8858->num_lanes == 4
1342 ? mode->reg_modes.mode_4lanes
1343 : mode->reg_modes.mode_2lanes;
1345 ret = ov8858_write_array(ov8858, reg_list);
1349 /* 200 usec max to let PLL stabilize. */
1352 ret = __v4l2_ctrl_handler_setup(&ov8858->ctrl_handler);
1356 ret = ov8858_write(ov8858, OV8858_REG_SC_CTRL0100,
1357 OV8858_MODE_STREAMING, NULL);
1361 /* t5 (fixed) = 10msec before entering streaming state */
1367 static int ov8858_stop_stream(struct ov8858 *ov8858)
1369 return ov8858_write(ov8858, OV8858_REG_SC_CTRL0100,
1370 OV8858_MODE_SW_STANDBY, NULL);
1373 static int ov8858_s_stream(struct v4l2_subdev *sd, int on)
1375 struct i2c_client *client = v4l2_get_subdevdata(sd);
1376 struct ov8858 *ov8858 = sd_to_ov8858(sd);
1377 struct v4l2_subdev_state *state;
1380 state = v4l2_subdev_lock_and_get_active_state(sd);
1383 ret = pm_runtime_resume_and_get(&client->dev);
1385 goto unlock_and_return;
1387 ret = ov8858_start_stream(ov8858, state);
1389 dev_err(&client->dev, "Failed to start streaming\n");
1390 pm_runtime_put_sync(&client->dev);
1391 goto unlock_and_return;
1394 ov8858_stop_stream(ov8858);
1395 pm_runtime_mark_last_busy(&client->dev);
1396 pm_runtime_put_autosuspend(&client->dev);
1400 v4l2_subdev_unlock_state(state);
1405 static const struct v4l2_subdev_video_ops ov8858_video_ops = {
1406 .s_stream = ov8858_s_stream,
1409 /* ----------------------------------------------------------------------------
1413 static int ov8858_set_fmt(struct v4l2_subdev *sd,
1414 struct v4l2_subdev_state *state,
1415 struct v4l2_subdev_format *fmt)
1417 struct ov8858 *ov8858 = sd_to_ov8858(sd);
1418 const struct ov8858_mode *mode;
1419 s64 h_blank, vblank_def;
1421 mode = v4l2_find_nearest_size(ov8858_modes, ARRAY_SIZE(ov8858_modes),
1422 width, height, fmt->format.width,
1423 fmt->format.height);
1425 fmt->format.code = MEDIA_BUS_FMT_SBGGR10_1X10;
1426 fmt->format.width = mode->width;
1427 fmt->format.height = mode->height;
1428 fmt->format.field = V4L2_FIELD_NONE;
1430 /* Store the format in the current subdev state. */
1431 *v4l2_subdev_get_pad_format(sd, state, 0) = fmt->format;
1433 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
1436 /* Adjust control limits when a new mode is applied. */
1437 h_blank = mode->hts_def - mode->width;
1438 __v4l2_ctrl_modify_range(ov8858->hblank, h_blank, h_blank, 1,
1441 vblank_def = mode->vts_def - mode->height;
1442 __v4l2_ctrl_modify_range(ov8858->vblank, vblank_def,
1443 OV8858_VTS_MAX - mode->height, 1,
1449 static int ov8858_enum_frame_sizes(struct v4l2_subdev *sd,
1450 struct v4l2_subdev_state *state,
1451 struct v4l2_subdev_frame_size_enum *fse)
1453 if (fse->index >= ARRAY_SIZE(ov8858_modes))
1456 if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10)
1459 fse->min_width = ov8858_modes[fse->index].width;
1460 fse->max_width = ov8858_modes[fse->index].width;
1461 fse->max_height = ov8858_modes[fse->index].height;
1462 fse->min_height = ov8858_modes[fse->index].height;
1467 static int ov8858_enum_mbus_code(struct v4l2_subdev *sd,
1468 struct v4l2_subdev_state *state,
1469 struct v4l2_subdev_mbus_code_enum *code)
1471 if (code->index != 0)
1474 code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
1479 static int ov8858_init_cfg(struct v4l2_subdev *sd,
1480 struct v4l2_subdev_state *sd_state)
1482 const struct ov8858_mode *def_mode = &ov8858_modes[0];
1483 struct v4l2_subdev_format fmt = {
1484 .which = V4L2_SUBDEV_FORMAT_TRY,
1486 .width = def_mode->width,
1487 .height = def_mode->height,
1491 ov8858_set_fmt(sd, sd_state, &fmt);
1496 static const struct v4l2_subdev_pad_ops ov8858_pad_ops = {
1497 .init_cfg = ov8858_init_cfg,
1498 .enum_mbus_code = ov8858_enum_mbus_code,
1499 .enum_frame_size = ov8858_enum_frame_sizes,
1500 .get_fmt = v4l2_subdev_get_fmt,
1501 .set_fmt = ov8858_set_fmt,
1504 static const struct v4l2_subdev_core_ops ov8858_core_ops = {
1505 .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
1506 .unsubscribe_event = v4l2_event_subdev_unsubscribe,
1509 static const struct v4l2_subdev_ops ov8858_subdev_ops = {
1510 .core = &ov8858_core_ops,
1511 .video = &ov8858_video_ops,
1512 .pad = &ov8858_pad_ops,
1515 /* ----------------------------------------------------------------------------
1519 static int ov8858_enable_test_pattern(struct ov8858 *ov8858, u32 pattern)
1524 val = (pattern - 1) | OV8858_TEST_PATTERN_ENABLE;
1526 val = OV8858_TEST_PATTERN_DISABLE;
1528 return ov8858_write(ov8858, OV8858_REG_TEST_PATTERN, val, NULL);
1531 static int ov8858_set_ctrl(struct v4l2_ctrl *ctrl)
1533 struct ov8858 *ov8858 = container_of(ctrl->handler,
1534 struct ov8858, ctrl_handler);
1536 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev);
1537 struct v4l2_mbus_framefmt *format;
1538 struct v4l2_subdev_state *state;
1544 * The control handler and the subdev state use the same mutex and the
1545 * mutex is guaranteed to be locked:
1546 * - by the core when s_ctrl is called int the VIDIOC_S_CTRL call path
1547 * - by the driver when s_ctrl is called in the s_stream(1) call path
1549 state = v4l2_subdev_get_locked_active_state(&ov8858->subdev);
1550 format = v4l2_subdev_get_pad_format(&ov8858->subdev, state, 0);
1552 /* Propagate change of current control to all related controls */
1554 case V4L2_CID_VBLANK:
1555 /* Update max exposure while meeting expected vblanking */
1556 max_exp = format->height + ctrl->val - OV8858_EXPOSURE_MARGIN;
1557 __v4l2_ctrl_modify_range(ov8858->exposure,
1558 ov8858->exposure->minimum, max_exp,
1559 ov8858->exposure->step,
1560 ov8858->exposure->default_value);
1564 if (!pm_runtime_get_if_in_use(&client->dev))
1568 case V4L2_CID_EXPOSURE:
1569 /* 4 least significant bits of exposure are fractional part */
1570 ret = ov8858_write(ov8858, OV8858_REG_LONG_EXPO,
1571 ctrl->val << 4, NULL);
1573 case V4L2_CID_ANALOGUE_GAIN:
1574 ret = ov8858_write(ov8858, OV8858_REG_LONG_GAIN,
1577 case V4L2_CID_DIGITAL_GAIN:
1579 * Digital gain is assembled as:
1580 * 0x350a[7:0] = dgain[13:6]
1581 * 0x350b[5:0] = dgain[5:0]
1582 * Reassemble the control value to write it in one go.
1584 digi_gain = (ctrl->val & OV8858_LONG_DIGIGAIN_L_MASK)
1585 | ((ctrl->val & OV8858_LONG_DIGIGAIN_H_MASK) <<
1586 OV8858_LONG_DIGIGAIN_H_SHIFT);
1587 ret = ov8858_write(ov8858, OV8858_REG_LONG_DIGIGAIN,
1590 case V4L2_CID_VBLANK:
1591 ret = ov8858_write(ov8858, OV8858_REG_VTS,
1592 ctrl->val + format->height, NULL);
1594 case V4L2_CID_TEST_PATTERN:
1595 ret = ov8858_enable_test_pattern(ov8858, ctrl->val);
1599 dev_warn(&client->dev, "%s Unhandled id: 0x%x\n",
1600 __func__, ctrl->id);
1604 pm_runtime_put(&client->dev);
1609 static const struct v4l2_ctrl_ops ov8858_ctrl_ops = {
1610 .s_ctrl = ov8858_set_ctrl,
1613 /* ----------------------------------------------------------------------------
1617 static int ov8858_power_on(struct ov8858 *ov8858)
1619 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev);
1620 struct device *dev = &client->dev;
1621 unsigned long delay_us;
1624 if (clk_get_rate(ov8858->xvclk) != OV8858_XVCLK_FREQ)
1625 dev_warn(dev, "xvclk mismatched, modes are based on 24MHz\n");
1627 ret = clk_prepare_enable(ov8858->xvclk);
1629 dev_err(dev, "Failed to enable xvclk\n");
1633 ret = regulator_bulk_enable(ARRAY_SIZE(ov8858_supply_names),
1636 dev_err(dev, "Failed to enable regulators\n");
1641 * The chip manual only suggests 8192 cycles prior to first SCCB
1642 * transaction, but a double sleep between the release of gpios
1643 * helps with sporadic failures observed at probe time.
1645 delay_us = DIV_ROUND_UP(8192, OV8858_XVCLK_FREQ / 1000 / 1000);
1647 gpiod_set_value_cansleep(ov8858->reset_gpio, 0);
1649 gpiod_set_value_cansleep(ov8858->pwdn_gpio, 0);
1655 clk_disable_unprepare(ov8858->xvclk);
1660 static void ov8858_power_off(struct ov8858 *ov8858)
1662 gpiod_set_value_cansleep(ov8858->pwdn_gpio, 1);
1663 clk_disable_unprepare(ov8858->xvclk);
1664 gpiod_set_value_cansleep(ov8858->reset_gpio, 1);
1666 regulator_bulk_disable(ARRAY_SIZE(ov8858_supply_names),
1670 static int ov8858_runtime_resume(struct device *dev)
1672 struct i2c_client *client = to_i2c_client(dev);
1673 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1674 struct ov8858 *ov8858 = sd_to_ov8858(sd);
1676 return ov8858_power_on(ov8858);
1679 static int ov8858_runtime_suspend(struct device *dev)
1681 struct i2c_client *client = to_i2c_client(dev);
1682 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1683 struct ov8858 *ov8858 = sd_to_ov8858(sd);
1685 ov8858_power_off(ov8858);
1690 static const struct dev_pm_ops ov8858_pm_ops = {
1691 SET_RUNTIME_PM_OPS(ov8858_runtime_suspend,
1692 ov8858_runtime_resume, NULL)
1695 /* ----------------------------------------------------------------------------
1696 * Probe and initialization
1699 static int ov8858_init_ctrls(struct ov8858 *ov8858)
1701 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev);
1702 struct v4l2_ctrl_handler *handler = &ov8858->ctrl_handler;
1703 const struct ov8858_mode *mode = &ov8858_modes[0];
1704 struct v4l2_fwnode_device_properties props;
1705 s64 exposure_max, vblank_def;
1706 unsigned int pixel_rate;
1707 struct v4l2_ctrl *ctrl;
1711 ret = v4l2_ctrl_handler_init(handler, 10);
1715 ctrl = v4l2_ctrl_new_int_menu(handler, NULL, V4L2_CID_LINK_FREQ,
1716 0, 0, link_freq_menu_items);
1718 ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1720 /* pixel rate = link frequency * 2 * lanes / bpp */
1721 pixel_rate = OV8858_LINK_FREQ * 2 * ov8858->num_lanes / 10;
1722 v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE,
1723 0, pixel_rate, 1, pixel_rate);
1725 h_blank = mode->hts_def - mode->width;
1726 ov8858->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK,
1727 h_blank, h_blank, 1, h_blank);
1729 ov8858->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1731 vblank_def = mode->vts_def - mode->height;
1732 ov8858->vblank = v4l2_ctrl_new_std(handler, &ov8858_ctrl_ops,
1733 V4L2_CID_VBLANK, vblank_def,
1734 OV8858_VTS_MAX - mode->height,
1737 exposure_max = mode->vts_def - OV8858_EXPOSURE_MARGIN;
1738 ov8858->exposure = v4l2_ctrl_new_std(handler, &ov8858_ctrl_ops,
1740 OV8858_EXPOSURE_MIN,
1741 exposure_max, OV8858_EXPOSURE_STEP,
1744 v4l2_ctrl_new_std(handler, &ov8858_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
1745 OV8858_LONG_GAIN_MIN, OV8858_LONG_GAIN_MAX,
1746 OV8858_LONG_GAIN_STEP, OV8858_LONG_GAIN_DEFAULT);
1748 v4l2_ctrl_new_std(handler, &ov8858_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
1749 OV8858_LONG_DIGIGAIN_MIN, OV8858_LONG_DIGIGAIN_MAX,
1750 OV8858_LONG_DIGIGAIN_STEP,
1751 OV8858_LONG_DIGIGAIN_DEFAULT);
1753 v4l2_ctrl_new_std_menu_items(handler, &ov8858_ctrl_ops,
1754 V4L2_CID_TEST_PATTERN,
1755 ARRAY_SIZE(ov8858_test_pattern_menu) - 1,
1756 0, 0, ov8858_test_pattern_menu);
1758 if (handler->error) {
1759 ret = handler->error;
1760 goto err_free_handler;
1763 ret = v4l2_fwnode_device_parse(&client->dev, &props);
1765 goto err_free_handler;
1767 ret = v4l2_ctrl_new_fwnode_properties(handler, &ov8858_ctrl_ops,
1770 goto err_free_handler;
1772 ov8858->subdev.ctrl_handler = handler;
1777 dev_err(&client->dev, "Failed to init controls: %d\n", ret);
1778 v4l2_ctrl_handler_free(handler);
1783 static int ov8858_check_sensor_id(struct ov8858 *ov8858)
1785 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev);
1789 ret = ov8858_read(ov8858, OV8858_REG_CHIP_ID, &id);
1793 if (id != OV8858_CHIP_ID) {
1794 dev_err(&client->dev, "Unexpected sensor id 0x%x\n", id);
1798 ret = ov8858_read(ov8858, OV8858_REG_SUB_ID, &id);
1802 dev_info(&client->dev, "Detected OV8858 sensor, revision 0x%x\n", id);
1804 if (id == OV8858_R2A) {
1805 /* R2A supports 2 and 4 lanes modes. */
1806 ov8858->global_regs = ov8858->num_lanes == 4
1807 ? ov8858_global_regs_r2a_4lane
1808 : ov8858_global_regs_r2a_2lane;
1809 } else if (ov8858->num_lanes == 2) {
1811 * R1A only supports 2 lanes mode and it's only partially
1814 ov8858->global_regs = ov8858_global_regs_r1a;
1815 dev_warn(&client->dev, "R1A may not work well!\n");
1817 dev_err(&client->dev,
1818 "Unsupported number of data lanes for R1A revision.\n");
1825 static int ov8858_configure_regulators(struct ov8858 *ov8858)
1827 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev);
1830 for (i = 0; i < ARRAY_SIZE(ov8858_supply_names); i++)
1831 ov8858->supplies[i].supply = ov8858_supply_names[i];
1833 return devm_regulator_bulk_get(&client->dev,
1834 ARRAY_SIZE(ov8858_supply_names),
1838 static int ov8858_parse_of(struct ov8858 *ov8858)
1840 struct v4l2_fwnode_endpoint vep = { .bus_type = V4L2_MBUS_CSI2_DPHY };
1841 struct i2c_client *client = v4l2_get_subdevdata(&ov8858->subdev);
1842 struct device *dev = &client->dev;
1843 struct fwnode_handle *endpoint;
1846 endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
1848 dev_err(dev, "Failed to get endpoint\n");
1852 ret = v4l2_fwnode_endpoint_parse(endpoint, &vep);
1854 dev_err(dev, "Failed to parse endpoint: %d\n", ret);
1855 fwnode_handle_put(endpoint);
1859 ov8858->num_lanes = vep.bus.mipi_csi2.num_data_lanes;
1860 switch (ov8858->num_lanes) {
1865 dev_err(dev, "Unsupported number of data lanes %u\n",
1867 fwnode_handle_put(endpoint);
1871 ov8858->subdev.fwnode = endpoint;
1876 static int ov8858_probe(struct i2c_client *client)
1878 struct device *dev = &client->dev;
1879 struct v4l2_subdev *sd;
1880 struct ov8858 *ov8858;
1883 ov8858 = devm_kzalloc(dev, sizeof(*ov8858), GFP_KERNEL);
1887 ov8858->xvclk = devm_clk_get(dev, "xvclk");
1888 if (IS_ERR(ov8858->xvclk))
1889 return dev_err_probe(dev, PTR_ERR(ov8858->xvclk),
1890 "Failed to get xvclk\n");
1892 ov8858->reset_gpio = devm_gpiod_get_optional(dev, "reset",
1894 if (IS_ERR(ov8858->reset_gpio))
1895 return dev_err_probe(dev, PTR_ERR(ov8858->reset_gpio),
1896 "Failed to get reset gpio\n");
1898 ov8858->pwdn_gpio = devm_gpiod_get_optional(dev, "powerdown",
1900 if (IS_ERR(ov8858->pwdn_gpio))
1901 return dev_err_probe(dev, PTR_ERR(ov8858->pwdn_gpio),
1902 "Failed to get powerdown gpio\n");
1904 v4l2_i2c_subdev_init(&ov8858->subdev, client, &ov8858_subdev_ops);
1906 ret = ov8858_configure_regulators(ov8858);
1908 return dev_err_probe(dev, ret, "Failed to get regulators\n");
1910 ret = ov8858_parse_of(ov8858);
1914 ret = ov8858_init_ctrls(ov8858);
1916 goto err_put_fwnode;
1918 sd = &ov8858->subdev;
1919 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
1920 ov8858->pad.flags = MEDIA_PAD_FL_SOURCE;
1921 sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
1922 ret = media_entity_pads_init(&sd->entity, 1, &ov8858->pad);
1924 goto err_free_handler;
1926 sd->state_lock = ov8858->ctrl_handler.lock;
1927 ret = v4l2_subdev_init_finalize(sd);
1929 dev_err(&client->dev, "Subdev initialization error %d\n", ret);
1930 goto err_clean_entity;
1933 ret = ov8858_power_on(ov8858);
1935 goto err_clean_entity;
1937 pm_runtime_set_active(dev);
1938 pm_runtime_get_noresume(dev);
1939 pm_runtime_enable(dev);
1941 ret = ov8858_check_sensor_id(ov8858);
1945 pm_runtime_set_autosuspend_delay(dev, 1000);
1946 pm_runtime_use_autosuspend(dev);
1948 ret = v4l2_async_register_subdev_sensor(sd);
1950 dev_err(dev, "v4l2 async register subdev failed\n");
1954 pm_runtime_mark_last_busy(dev);
1955 pm_runtime_put_autosuspend(dev);
1960 pm_runtime_disable(dev);
1961 pm_runtime_put_noidle(dev);
1962 ov8858_power_off(ov8858);
1964 media_entity_cleanup(&sd->entity);
1966 v4l2_ctrl_handler_free(&ov8858->ctrl_handler);
1968 fwnode_handle_put(ov8858->subdev.fwnode);
1973 static void ov8858_remove(struct i2c_client *client)
1975 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1976 struct ov8858 *ov8858 = sd_to_ov8858(sd);
1978 v4l2_async_unregister_subdev(sd);
1979 media_entity_cleanup(&sd->entity);
1980 v4l2_ctrl_handler_free(&ov8858->ctrl_handler);
1981 fwnode_handle_put(ov8858->subdev.fwnode);
1983 pm_runtime_disable(&client->dev);
1984 if (!pm_runtime_status_suspended(&client->dev))
1985 ov8858_power_off(ov8858);
1986 pm_runtime_set_suspended(&client->dev);
1989 static const struct of_device_id ov8858_of_match[] = {
1990 { .compatible = "ovti,ov8858" },
1993 MODULE_DEVICE_TABLE(of, ov8858_of_match);
1995 static struct i2c_driver ov8858_i2c_driver = {
1998 .pm = &ov8858_pm_ops,
1999 .of_match_table = ov8858_of_match,
2001 .probe_new = &ov8858_probe,
2002 .remove = &ov8858_remove,
2005 module_i2c_driver(ov8858_i2c_driver);
2007 MODULE_DESCRIPTION("OmniVision OV8858 sensor driver");
2008 MODULE_LICENSE("GPL");