1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2023 Jacopo Mondi <jacopo.mondi@ideasonboard.com>
4 * Copyright (C) 2022 Nicholas Roth <nicholas@rothemail.net>
5 * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
8 #include <linux/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-fwnode.h>
28 #include <media/v4l2-mediabus.h>
29 #include <media/v4l2-subdev.h>
31 #define OV8858_LINK_FREQ 360000000U
32 #define OV8858_XVCLK_FREQ 24000000
34 #define OV8858_REG_SIZE_SHIFT 16
35 #define OV8858_REG_ADDR_MASK 0xffff
36 #define OV8858_REG_8BIT(n) ((1U << OV8858_REG_SIZE_SHIFT) | (n))
37 #define OV8858_REG_16BIT(n) ((2U << OV8858_REG_SIZE_SHIFT) | (n))
38 #define OV8858_REG_24BIT(n) ((3U << OV8858_REG_SIZE_SHIFT) | (n))
40 #define OV8858_REG_SC_CTRL0100 OV8858_REG_8BIT(0x0100)
41 #define OV8858_MODE_SW_STANDBY 0x0
42 #define OV8858_MODE_STREAMING 0x1
44 #define OV8858_REG_CHIP_ID OV8858_REG_24BIT(0x300a)
45 #define OV8858_CHIP_ID 0x008858
47 #define OV8858_REG_SUB_ID OV8858_REG_8BIT(0x302a)
48 #define OV8858_R1A 0xb0
49 #define OV8858_R2A 0xb2
51 #define OV8858_REG_LONG_EXPO OV8858_REG_24BIT(0x3500)
52 #define OV8858_EXPOSURE_MIN 4
53 #define OV8858_EXPOSURE_STEP 1
54 #define OV8858_EXPOSURE_MARGIN 4
56 #define OV8858_REG_LONG_GAIN OV8858_REG_16BIT(0x3508)
57 #define OV8858_LONG_GAIN_MIN 0x0
58 #define OV8858_LONG_GAIN_MAX 0x7ff
59 #define OV8858_LONG_GAIN_STEP 1
60 #define OV8858_LONG_GAIN_DEFAULT 0x80
62 #define OV8858_REG_LONG_DIGIGAIN OV8858_REG_16BIT(0x350a)
63 #define OV8858_LONG_DIGIGAIN_H_MASK 0x3fc0
64 #define OV8858_LONG_DIGIGAIN_L_MASK 0x3f
65 #define OV8858_LONG_DIGIGAIN_H_SHIFT 2
66 #define OV8858_LONG_DIGIGAIN_MIN 0x0
67 #define OV8858_LONG_DIGIGAIN_MAX 0x3fff
68 #define OV8858_LONG_DIGIGAIN_STEP 1
69 #define OV8858_LONG_DIGIGAIN_DEFAULT 0x200
71 #define OV8858_REG_VTS OV8858_REG_16BIT(0x380e)
72 #define OV8858_VTS_MAX 0x7fff
74 #define OV8858_REG_TEST_PATTERN OV8858_REG_8BIT(0x5e00)
75 #define OV8858_TEST_PATTERN_ENABLE 0x80
76 #define OV8858_TEST_PATTERN_DISABLE 0x0
78 #define REG_NULL 0xffff
80 static const char * const ov8858_supply_names
[] = {
81 "avdd", /* Analog power */
82 "dovdd", /* Digital I/O power */
83 "dvdd", /* Digital core power */
92 const struct regval
*mode_2lanes
;
93 const struct regval
*mode_4lanes
;
102 const struct regval_modes reg_modes
;
107 struct gpio_desc
*reset_gpio
;
108 struct gpio_desc
*pwdn_gpio
;
109 struct regulator_bulk_data supplies
[ARRAY_SIZE(ov8858_supply_names
)];
111 struct v4l2_subdev subdev
;
112 struct media_pad pad
;
114 struct v4l2_ctrl_handler ctrl_handler
;
115 struct v4l2_ctrl
*exposure
;
116 struct v4l2_ctrl
*hblank
;
117 struct v4l2_ctrl
*vblank
;
119 const struct regval
*global_regs
;
121 unsigned int num_lanes
;
124 static inline struct ov8858
*sd_to_ov8858(struct v4l2_subdev
*sd
)
126 return container_of(sd
, struct ov8858
, subdev
);
129 static const struct regval ov8858_global_regs_r1a
[] = {
399 static const struct regval ov8858_global_regs_r2a_2lane
[] = {
401 * MIPI=720Mbps, SysClk=144Mhz,Dac Clock=360Mhz.
402 * v00_01_00 (05/29/2014) : initial setting
403 * AM19 : 3617 <- 0xC0
404 * AM20 : change FWC_6K_EN to be default 0x3618=0x5a
406 {0x0103, 0x01}, /* software reset */
407 {0x0100, 0x00}, /* software standby */
408 {0x0302, 0x1e}, /* pll1_multi */
409 {0x0303, 0x00}, /* pll1_divm */
410 {0x0304, 0x03}, /* pll1_div_mipi */
411 {0x030e, 0x02}, /* pll2_rdiv */
412 {0x030f, 0x04}, /* pll2_divsp */
413 {0x0312, 0x03}, /* pll2_pre_div0, pll2_r_divdac */
414 {0x031e, 0x0c}, /* pll1_no_lat */
456 {0x3018, 0x32}, /* MIPI 2 lane */
457 {0x3020, 0x93}, /* Clock switch output normal, pclk_div =/1 */
458 {0x3022, 0x01}, /* pd_mipi enable when rst_sync */
459 {0x3031, 0x0a}, /* MIPI 10-bit mode */
461 {0x3106, 0x01}, /* sclk_div, sclk_pre_div */
472 {0x3500, 0x00}, /* exposure H */
473 {0x3501, 0x4d}, /* exposure M */
474 {0x3502, 0x40}, /* exposure L */
475 {0x3503, 0x80}, /* gain delay ?, exposure delay 1 frame, real gain */
476 {0x3505, 0x80}, /* gain option */
477 {0x3508, 0x02}, /* gain H */
478 {0x3509, 0x00}, /* gain L */
479 {0x350c, 0x00}, /* short gain H */
480 {0x350d, 0x80}, /* short gain L */
481 {0x3510, 0x00}, /* short exposure H */
482 {0x3511, 0x02}, /* short exposure M */
483 {0x3512, 0x00}, /* short exposure L */
580 {0x3800, 0x00}, /* x start H */
581 {0x3801, 0x0c}, /* x start L */
582 {0x3802, 0x00}, /* y start H */
583 {0x3803, 0x0c}, /* y start L */
584 {0x3804, 0x0c}, /* x end H */
585 {0x3805, 0xd3}, /* x end L */
586 {0x3806, 0x09}, /* y end H */
587 {0x3807, 0xa3}, /* y end L */
588 {0x3808, 0x06}, /* x output size H */
589 {0x3809, 0x60}, /* x output size L */
590 {0x380a, 0x04}, /* y output size H */
591 {0x380b, 0xc8}, /* y output size L */
592 {0x380c, 0x07}, /* HTS H */
593 {0x380d, 0x88}, /* HTS L */
594 {0x380e, 0x04}, /* VTS H */
595 {0x380f, 0xdc}, /* VTS L */
596 {0x3810, 0x00}, /* ISP x win H */
597 {0x3811, 0x04}, /* ISP x win L */
598 {0x3813, 0x02}, /* ISP y win L */
599 {0x3814, 0x03}, /* x odd inc */
600 {0x3815, 0x01}, /* x even inc */
601 {0x3820, 0x00}, /* vflip off */
602 {0x3821, 0x67}, /* mirror on, bin on */
603 {0x382a, 0x03}, /* y odd inc */
604 {0x382b, 0x01}, /* y even inc */
608 {0x3841, 0xff}, /* window auto size enable */
610 {0x3d85, 0x16}, /* OTP power up load data enable with BIST */
611 {0x3d8c, 0x73}, /* OTP setting start High */
612 {0x3d8d, 0xde}, /* OTP setting start Low */
615 {0x4000, 0xf1}, /* out_range_trig, format_chg_trig */
616 {0x4001, 0x10}, /* total 128 black column */
617 {0x4005, 0x10}, /* BLC target L */
618 {0x4002, 0x27}, /* value used to limit BLC offset */
619 {0x4009, 0x81}, /* final BLC offset limitation enable */
620 {0x400b, 0x0c}, /* DCBLC on, DCBLC manual mode on */
621 {0x401b, 0x00}, /* zero line R coefficient */
622 {0x401d, 0x00}, /* zoro line T coefficient */
623 {0x4020, 0x00}, /* Anchor left start H */
624 {0x4021, 0x04}, /* Anchor left start L */
625 {0x4022, 0x06}, /* Anchor left end H */
626 {0x4023, 0x00}, /* Anchor left end L */
627 {0x4024, 0x0f}, /* Anchor right start H */
628 {0x4025, 0x2a}, /* Anchor right start L */
629 {0x4026, 0x0f}, /* Anchor right end H */
630 {0x4027, 0x2b}, /* Anchor right end L */
631 {0x4028, 0x00}, /* top zero line start */
632 {0x4029, 0x02}, /* top zero line number */
633 {0x402a, 0x04}, /* top black line start */
634 {0x402b, 0x04}, /* top black line number */
635 {0x402c, 0x00}, /* bottom zero line start */
636 {0x402d, 0x02}, /* bottom zoro line number */
637 {0x402e, 0x04}, /* bottom black line start */
638 {0x402f, 0x04}, /* bottom black line number */
639 {0x401f, 0x00}, /* interpolation x/y disable, Anchor one disable */
641 {0x403d, 0x04}, /* md_precision_en */
642 {0x4300, 0xff}, /* clip max H */
643 {0x4301, 0x00}, /* clip min H */
644 {0x4302, 0x0f}, /* clip min L, clip max L */
650 {0x481f, 0x32}, /* clk prepare min */
651 {0x4837, 0x16}, /* global timing */
652 {0x4850, 0x10}, /* lane 1 = 1, lane 0 = 0 */
653 {0x4851, 0x32}, /* lane 3 = 3, lane 2 = 2 */
656 {0x4d00, 0x04}, /* temperature sensor */
661 {0x4d05, 0xff}, /* temperature sensor */
662 {0x5000, 0xfe}, /* lenc on, slave/master AWB gain/statistics enable */
663 {0x5001, 0x01}, /* BLC on */
664 {0x5002, 0x08}, /* H scale off, WBMATCH off, OTP_DPC */
665 {0x5003, 0x20}, /* DPC_DBC buffer control enable, WB */
666 {0x501e, 0x93}, /* enable digital gain */
668 {0x5780, 0x3e}, /* DPC */
688 {0x5794, 0xa3}, /* DPC */
689 {0x5871, 0x0d}, /* Lenc */
694 {0x58f8, 0x3d}, /* Lenc */
695 {0x5901, 0x00}, /* H skip off, V skip off */
696 {0x5b00, 0x02}, /* OTP DPC start address */
697 {0x5b01, 0x10}, /* OTP DPC start address */
698 {0x5b02, 0x03}, /* OTP DPC end address */
699 {0x5b03, 0xcf}, /* OTP DPC end address */
700 {0x5b05, 0x6c}, /* recover method = 2b11, */
701 {0x5e00, 0x00}, /* use 0x3ff to test pattern off */
702 {0x5e01, 0x41}, /* window cut enable */
704 {0x4825, 0x3a}, /* lpx_p_min */
705 {0x4826, 0x40}, /* hs_prepare_min */
706 {0x4808, 0x25}, /* wake up delay in 1/1024 s */
711 {0x400d, 0x10}, /* BLC offset trigger L */
712 {0x4040, 0x04}, /* BLC gain th2 */
713 {0x403e, 0x04}, /* BLC gain th1 */
714 {0x4041, 0xc6}, /* BLC */
722 * max_framerate 30fps
723 * mipi_datarate per lane 720Mbps
725 static const struct regval ov8858_1632x1224_regs_2lane
[] = {
727 * MIPI=720Mbps, SysClk=144Mhz,Dac Clock=360Mhz.
728 * v00_01_00 (05/29/2014) : initial setting
729 * AM19 : 3617 <- 0xC0
730 * AM20 : change FWC_6K_EN to be default 0x3618=0x5a
733 {0x3501, 0x4d}, /* exposure M */
734 {0x3502, 0x40}, /* exposure L */
736 {0x3808, 0x06}, /* x output size H */
737 {0x3809, 0x60}, /* x output size L */
738 {0x380a, 0x04}, /* y output size H */
739 {0x380b, 0xc8}, /* y output size L */
740 {0x380c, 0x07}, /* HTS H */
741 {0x380d, 0x88}, /* HTS L */
742 {0x380e, 0x04}, /* VTS H */
743 {0x380f, 0xdc}, /* VTS L */
744 {0x3814, 0x03}, /* x odd inc */
745 {0x3821, 0x67}, /* mirror on, bin on */
746 {0x382a, 0x03}, /* y odd inc */
750 {0x4001, 0x10}, /* total 128 black column */
751 {0x4022, 0x06}, /* Anchor left end H */
752 {0x4023, 0x00}, /* Anchor left end L */
753 {0x4025, 0x2a}, /* Anchor right start L */
754 {0x4027, 0x2b}, /* Anchor right end L */
755 {0x402b, 0x04}, /* top black line number */
756 {0x402f, 0x04}, /* bottom black line number */
767 * max_framerate 15fps
768 * mipi_datarate per lane 720Mbps
770 static const struct regval ov8858_3264x2448_regs_2lane
[] = {
772 {0x3501, 0x9a}, /* exposure M */
773 {0x3502, 0x20}, /* exposure L */
775 {0x3808, 0x0c}, /* x output size H */
776 {0x3809, 0xc0}, /* x output size L */
777 {0x380a, 0x09}, /* y output size H */
778 {0x380b, 0x90}, /* y output size L */
779 {0x380c, 0x07}, /* HTS H */
780 {0x380d, 0x94}, /* HTS L */
781 {0x380e, 0x09}, /* VTS H */
782 {0x380f, 0xaa}, /* VTS L */
783 {0x3814, 0x01}, /* x odd inc */
784 {0x3821, 0x46}, /* mirror on, bin off */
785 {0x382a, 0x01}, /* y odd inc */
789 {0x4001, 0x00}, /* total 256 black column */
790 {0x4022, 0x0c}, /* Anchor left end H */
791 {0x4023, 0x60}, /* Anchor left end L */
792 {0x4025, 0x36}, /* Anchor right start L */
793 {0x4027, 0x37}, /* Anchor right end L */
794 {0x402b, 0x08}, /* top black line number */
795 {0x402f, 0x08}, /* bottom black line number */
803 static const struct regval ov8858_global_regs_r2a_4lane
[] = {
805 * MIPI=720Mbps, SysClk=144Mhz,Dac Clock=360Mhz.
806 * v00_01_00 (05/29/2014) : initial setting
807 * AM19 : 3617 <- 0xC0
808 * AM20 : change FWC_6K_EN to be default 0x3618=0x5a
810 {0x0103, 0x01}, /* software reset for OVTATool only */
811 {0x0103, 0x01}, /* software reset */
812 {0x0100, 0x00}, /* software standby */
813 {0x0302, 0x1e}, /* pll1_multi */
814 {0x0303, 0x00}, /* pll1_divm */
815 {0x0304, 0x03}, /* pll1_div_mipi */
816 {0x030e, 0x00}, /* pll2_rdiv */
817 {0x030f, 0x04}, /* pll2_divsp */
818 {0x0312, 0x01}, /* pll2_pre_div0, pll2_r_divdac */
819 {0x031e, 0x0c}, /* pll1_no_lat */
861 {0x3018, 0x72}, /* MIPI 4 lane */
862 {0x3020, 0x93}, /* Clock switch output normal, pclk_div =/1 */
863 {0x3022, 0x01}, /* pd_mipi enable when rst_sync */
864 {0x3031, 0x0a}, /* MIPI 10-bit mode */
866 {0x3106, 0x01}, /* sclk_div, sclk_pre_div */
877 {0x3500, 0x00}, /* exposure H */
878 {0x3501, 0x4d}, /* exposure M */
879 {0x3502, 0x40}, /* exposure L */
880 {0x3503, 0x80}, /* gain delay ?, exposure delay 1 frame, real gain */
881 {0x3505, 0x80}, /* gain option */
882 {0x3508, 0x02}, /* gain H */
883 {0x3509, 0x00}, /* gain L */
884 {0x350c, 0x00}, /* short gain H */
885 {0x350d, 0x80}, /* short gain L */
886 {0x3510, 0x00}, /* short exposure H */
887 {0x3511, 0x02}, /* short exposure M */
888 {0x3512, 0x00}, /* short exposure L */
985 {0x3800, 0x00}, /* x start H */
986 {0x3801, 0x0c}, /* x start L */
987 {0x3802, 0x00}, /* y start H */
988 {0x3803, 0x0c}, /* y start L */
989 {0x3804, 0x0c}, /* x end H */
990 {0x3805, 0xd3}, /* x end L */
991 {0x3806, 0x09}, /* y end H */
992 {0x3807, 0xa3}, /* y end L */
993 {0x3808, 0x06}, /* x output size H */
994 {0x3809, 0x60}, /* x output size L */
995 {0x380a, 0x04}, /* y output size H */
996 {0x380b, 0xc8}, /* y output size L */
997 {0x380c, 0x07}, /* HTS H */
998 {0x380d, 0x88}, /* HTS L */
999 {0x380e, 0x04}, /* VTS H */
1000 {0x380f, 0xdc}, /* VTS L */
1001 {0x3810, 0x00}, /* ISP x win H */
1002 {0x3811, 0x04}, /* ISP x win L */
1003 {0x3813, 0x02}, /* ISP y win L */
1004 {0x3814, 0x03}, /* x odd inc */
1005 {0x3815, 0x01}, /* x even inc */
1006 {0x3820, 0x00}, /* vflip off */
1007 {0x3821, 0x67}, /* mirror on, bin o */
1008 {0x382a, 0x03}, /* y odd inc */
1009 {0x382b, 0x01}, /* y even inc */
1013 {0x3841, 0xff}, /* window auto size enable */
1015 {0x3d85, 0x16}, /* OTP power up load data/setting enable */
1016 {0x3d8c, 0x73}, /* OTP setting start High */
1017 {0x3d8d, 0xde}, /* OTP setting start Low */
1020 {0x4000, 0xf1}, /* out_range/format_chg/gain/exp_chg trig enable */
1021 {0x4001, 0x10}, /* total 128 black column */
1022 {0x4005, 0x10}, /* BLC target L */
1023 {0x4002, 0x27}, /* value used to limit BLC offset */
1024 {0x4009, 0x81}, /* final BLC offset limitation enable */
1025 {0x400b, 0x0c}, /* DCBLC on, DCBLC manual mode on */
1026 {0x401b, 0x00}, /* zero line R coefficient */
1027 {0x401d, 0x00}, /* zoro line T coefficient */
1028 {0x4020, 0x00}, /* Anchor left start H */
1029 {0x4021, 0x04}, /* Anchor left start L */
1030 {0x4022, 0x06}, /* Anchor left end H */
1031 {0x4023, 0x00}, /* Anchor left end L */
1032 {0x4024, 0x0f}, /* Anchor right start H */
1033 {0x4025, 0x2a}, /* Anchor right start L */
1034 {0x4026, 0x0f}, /* Anchor right end H */
1035 {0x4027, 0x2b}, /* Anchor right end L */
1036 {0x4028, 0x00}, /* top zero line start */
1037 {0x4029, 0x02}, /* top zero line number */
1038 {0x402a, 0x04}, /* top black line start */
1039 {0x402b, 0x04}, /* top black line number */
1040 {0x402c, 0x00}, /* bottom zero line start */
1041 {0x402d, 0x02}, /* bottom zoro line number */
1042 {0x402e, 0x04}, /* bottom black line start */
1043 {0x402f, 0x04}, /* bottom black line number */
1044 {0x401f, 0x00}, /* interpolation x/y disable, Anchor one disable */
1046 {0x403d, 0x04}, /* md_precision_en */
1047 {0x4300, 0xff}, /* clip max H */
1048 {0x4301, 0x00}, /* clip min H */
1049 {0x4302, 0x0f}, /* clip min L, clip max L */
1055 {0x481f, 0x32}, /* clk prepare min */
1056 {0x4837, 0x16}, /* global timing */
1057 {0x4850, 0x10}, /* lane 1 = 1, lane 0 = 0 */
1058 {0x4851, 0x32}, /* lane 3 = 3, lane 2 = 2 */
1061 {0x4d00, 0x04}, /* temperature sensor */
1066 {0x4d05, 0xff}, /* temperature sensor */
1067 {0x5000, 0xfe}, /* lenc on, slave/master AWB gain/statistics enable */
1068 {0x5001, 0x01}, /* BLC on */
1069 {0x5002, 0x08}, /* WBMATCH sensor's gain, H scale/WBMATCH/OTP_DPC off */
1070 {0x5003, 0x20}, /* DPC_DBC buffer control enable, WB */
1071 {0x501e, 0x93}, /* enable digital gain */
1073 {0x5780, 0x3e}, /* DPC */
1093 {0x5794, 0xa3}, /* DPC */
1094 {0x5871, 0x0d}, /* Lenc */
1099 {0x58f8, 0x3d}, /* Lenc */
1100 {0x5901, 0x00}, /* H skip off, V skip off */
1101 {0x5b00, 0x02}, /* OTP DPC start address */
1102 {0x5b01, 0x10}, /* OTP DPC start address */
1103 {0x5b02, 0x03}, /* OTP DPC end address */
1104 {0x5b03, 0xcf}, /* OTP DPC end address */
1105 {0x5b05, 0x6c}, /* recover method = 2b11 */
1106 {0x5e00, 0x00}, /* use 0x3ff to test pattern off */
1107 {0x5e01, 0x41}, /* window cut enable */
1109 {0x4825, 0x3a}, /* lpx_p_min */
1110 {0x4826, 0x40}, /* hs_prepare_min */
1111 {0x4808, 0x25}, /* wake up delay in 1/1024 s */
1116 {0x400d, 0x10}, /* BLC offset trigger L */
1117 {0x4040, 0x04}, /* BLC gain th2 */
1118 {0x403e, 0x04}, /* BLC gain th1 */
1119 {0x4041, 0xc6}, /* BLC */
1127 * max_framerate 60fps
1128 * mipi_datarate per lane 720Mbps
1130 static const struct regval ov8858_1632x1224_regs_4lane
[] = {
1132 {0x3501, 0x4d}, /* exposure M */
1133 {0x3502, 0x40}, /* exposure L */
1134 {0x3808, 0x06}, /* x output size H */
1135 {0x3809, 0x60}, /* x output size L */
1136 {0x380a, 0x04}, /* y output size H */
1137 {0x380b, 0xc8}, /* y output size L */
1138 {0x380c, 0x07}, /* HTS H */
1139 {0x380d, 0x88}, /* HTS L */
1140 {0x380e, 0x04}, /* VTS H */
1141 {0x380f, 0xdc}, /* VTS L */
1142 {0x3814, 0x03}, /* x odd inc */
1143 {0x3821, 0x67}, /* mirror on, bin on */
1144 {0x382a, 0x03}, /* y odd inc */
1148 {0x4001, 0x10}, /* total 128 black column */
1149 {0x4022, 0x06}, /* Anchor left end H */
1150 {0x4023, 0x00}, /* Anchor left end L */
1151 {0x4025, 0x2a}, /* Anchor right start L */
1152 {0x4027, 0x2b}, /* Anchor right end L */
1153 {0x402b, 0x04}, /* top black line number */
1154 {0x402f, 0x04}, /* bottom black line number */
1165 * max_framerate 30fps
1166 * mipi_datarate per lane 720Mbps
1168 static const struct regval ov8858_3264x2448_regs_4lane
[] = {
1170 {0x3501, 0x9a}, /* exposure M */
1171 {0x3502, 0x20}, /* exposure L */
1172 {0x3808, 0x0c}, /* x output size H */
1173 {0x3809, 0xc0}, /* x output size L */
1174 {0x380a, 0x09}, /* y output size H */
1175 {0x380b, 0x90}, /* y output size L */
1176 {0x380c, 0x07}, /* HTS H */
1177 {0x380d, 0x94}, /* HTS L */
1178 {0x380e, 0x09}, /* VTS H */
1179 {0x380f, 0xaa}, /* VTS L */
1180 {0x3814, 0x01}, /* x odd inc */
1181 {0x3821, 0x46}, /* mirror on, bin off */
1182 {0x382a, 0x01}, /* y odd inc */
1186 {0x4001, 0x00}, /* total 256 black column */
1187 {0x4022, 0x0c}, /* Anchor left end H */
1188 {0x4023, 0x60}, /* Anchor left end L */
1189 {0x4025, 0x36}, /* Anchor right start L */
1190 {0x4027, 0x37}, /* Anchor right end L */
1191 {0x402b, 0x08}, /* top black line number */
1192 {0x402f, 0x08}, /* interpolation x/y disable, Anchor one disable */
1200 static const struct ov8858_mode ov8858_modes
[] = {
1205 .hts_def
= 1940 * 2,
1208 .mode_2lanes
= ov8858_3264x2448_regs_2lane
,
1209 .mode_4lanes
= ov8858_3264x2448_regs_4lane
,
1216 .hts_def
= 1928 * 2,
1219 .mode_2lanes
= ov8858_1632x1224_regs_2lane
,
1220 .mode_4lanes
= ov8858_1632x1224_regs_4lane
,
1225 static const s64 link_freq_menu_items
[] = {
1229 static const char * const ov8858_test_pattern_menu
[] = {
1231 "Vertical Color Bar Type 1",
1232 "Vertical Color Bar Type 2",
1233 "Vertical Color Bar Type 3",
1234 "Vertical Color Bar Type 4"
1237 /* ----------------------------------------------------------------------------
1241 static int ov8858_write(struct ov8858
*ov8858
, u32 reg
, u32 val
, int *err
)
1243 struct i2c_client
*client
= v4l2_get_subdevdata(&ov8858
->subdev
);
1244 unsigned int len
= (reg
>> OV8858_REG_SIZE_SHIFT
) & 3;
1245 u16 addr
= reg
& OV8858_REG_ADDR_MASK
;
1252 put_unaligned_be16(addr
, buf
);
1253 put_unaligned_be32(val
<< (8 * (4 - len
)), buf
+ 2);
1255 ret
= i2c_master_send(client
, buf
, len
+ 2);
1256 if (ret
!= len
+ 2) {
1257 ret
= ret
< 0 ? ret
: -EIO
;
1261 dev_err(&client
->dev
,
1262 "Failed to write reg %u: %d\n", addr
, ret
);
1269 static int ov8858_write_array(struct ov8858
*ov8858
, const struct regval
*regs
)
1274 for (i
= 0; ret
== 0 && regs
[i
].addr
!= REG_NULL
; ++i
) {
1275 ov8858_write(ov8858
, OV8858_REG_8BIT(regs
[i
].addr
),
1282 static int ov8858_read(struct ov8858
*ov8858
, u32 reg
, u32
*val
)
1284 struct i2c_client
*client
= v4l2_get_subdevdata(&ov8858
->subdev
);
1285 __be16 reg_addr_be
= cpu_to_be16(reg
& OV8858_REG_ADDR_MASK
);
1286 unsigned int len
= (reg
>> OV8858_REG_SIZE_SHIFT
) & 3;
1287 struct i2c_msg msgs
[2];
1292 data_be_p
= (u8
*)&data_be
;
1294 /* Write register address */
1295 msgs
[0].addr
= client
->addr
;
1298 msgs
[0].buf
= (u8
*)®_addr_be
;
1300 /* Read data from register */
1301 msgs
[1].addr
= client
->addr
;
1302 msgs
[1].flags
= I2C_M_RD
;
1304 msgs
[1].buf
= &data_be_p
[4 - len
];
1306 ret
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
1307 if (ret
!= ARRAY_SIZE(msgs
)) {
1308 ret
= ret
< 0 ? ret
: -EIO
;
1309 dev_err(&client
->dev
,
1310 "Failed to read reg %u: %d\n", reg
, ret
);
1314 *val
= be32_to_cpu(data_be
);
1319 /* ----------------------------------------------------------------------------
1323 static int ov8858_start_stream(struct ov8858
*ov8858
,
1324 struct v4l2_subdev_state
*state
)
1326 struct v4l2_mbus_framefmt
*format
;
1327 const struct ov8858_mode
*mode
;
1328 const struct regval
*reg_list
;
1331 ret
= ov8858_write_array(ov8858
, ov8858
->global_regs
);
1335 format
= v4l2_subdev_state_get_format(state
, 0);
1336 mode
= v4l2_find_nearest_size(ov8858_modes
, ARRAY_SIZE(ov8858_modes
),
1337 width
, height
, format
->width
,
1340 reg_list
= ov8858
->num_lanes
== 4
1341 ? mode
->reg_modes
.mode_4lanes
1342 : mode
->reg_modes
.mode_2lanes
;
1344 ret
= ov8858_write_array(ov8858
, reg_list
);
1348 /* 200 usec max to let PLL stabilize. */
1351 ret
= __v4l2_ctrl_handler_setup(&ov8858
->ctrl_handler
);
1355 ret
= ov8858_write(ov8858
, OV8858_REG_SC_CTRL0100
,
1356 OV8858_MODE_STREAMING
, NULL
);
1360 /* t5 (fixed) = 10msec before entering streaming state */
1366 static int ov8858_stop_stream(struct ov8858
*ov8858
)
1368 return ov8858_write(ov8858
, OV8858_REG_SC_CTRL0100
,
1369 OV8858_MODE_SW_STANDBY
, NULL
);
1372 static int ov8858_s_stream(struct v4l2_subdev
*sd
, int on
)
1374 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
1375 struct ov8858
*ov8858
= sd_to_ov8858(sd
);
1376 struct v4l2_subdev_state
*state
;
1379 state
= v4l2_subdev_lock_and_get_active_state(sd
);
1382 ret
= pm_runtime_resume_and_get(&client
->dev
);
1384 goto unlock_and_return
;
1386 ret
= ov8858_start_stream(ov8858
, state
);
1388 dev_err(&client
->dev
, "Failed to start streaming\n");
1389 pm_runtime_put_sync(&client
->dev
);
1390 goto unlock_and_return
;
1393 ov8858_stop_stream(ov8858
);
1394 pm_runtime_mark_last_busy(&client
->dev
);
1395 pm_runtime_put_autosuspend(&client
->dev
);
1399 v4l2_subdev_unlock_state(state
);
1404 static const struct v4l2_subdev_video_ops ov8858_video_ops
= {
1405 .s_stream
= ov8858_s_stream
,
1408 /* ----------------------------------------------------------------------------
1412 static int ov8858_set_fmt(struct v4l2_subdev
*sd
,
1413 struct v4l2_subdev_state
*state
,
1414 struct v4l2_subdev_format
*fmt
)
1416 struct ov8858
*ov8858
= sd_to_ov8858(sd
);
1417 const struct ov8858_mode
*mode
;
1418 s64 h_blank
, vblank_def
;
1420 mode
= v4l2_find_nearest_size(ov8858_modes
, ARRAY_SIZE(ov8858_modes
),
1421 width
, height
, fmt
->format
.width
,
1422 fmt
->format
.height
);
1424 fmt
->format
.code
= MEDIA_BUS_FMT_SBGGR10_1X10
;
1425 fmt
->format
.width
= mode
->width
;
1426 fmt
->format
.height
= mode
->height
;
1427 fmt
->format
.field
= V4L2_FIELD_NONE
;
1429 /* Store the format in the current subdev state. */
1430 *v4l2_subdev_state_get_format(state
, 0) = fmt
->format
;
1432 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
)
1435 /* Adjust control limits when a new mode is applied. */
1436 h_blank
= mode
->hts_def
- mode
->width
;
1437 __v4l2_ctrl_modify_range(ov8858
->hblank
, h_blank
, h_blank
, 1,
1440 vblank_def
= mode
->vts_def
- mode
->height
;
1441 __v4l2_ctrl_modify_range(ov8858
->vblank
, vblank_def
,
1442 OV8858_VTS_MAX
- mode
->height
, 1,
1448 static int ov8858_enum_frame_sizes(struct v4l2_subdev
*sd
,
1449 struct v4l2_subdev_state
*state
,
1450 struct v4l2_subdev_frame_size_enum
*fse
)
1452 if (fse
->index
>= ARRAY_SIZE(ov8858_modes
))
1455 if (fse
->code
!= MEDIA_BUS_FMT_SBGGR10_1X10
)
1458 fse
->min_width
= ov8858_modes
[fse
->index
].width
;
1459 fse
->max_width
= ov8858_modes
[fse
->index
].width
;
1460 fse
->max_height
= ov8858_modes
[fse
->index
].height
;
1461 fse
->min_height
= ov8858_modes
[fse
->index
].height
;
1466 static int ov8858_enum_mbus_code(struct v4l2_subdev
*sd
,
1467 struct v4l2_subdev_state
*state
,
1468 struct v4l2_subdev_mbus_code_enum
*code
)
1470 if (code
->index
!= 0)
1473 code
->code
= MEDIA_BUS_FMT_SBGGR10_1X10
;
1478 static int ov8858_init_state(struct v4l2_subdev
*sd
,
1479 struct v4l2_subdev_state
*sd_state
)
1481 const struct ov8858_mode
*def_mode
= &ov8858_modes
[0];
1482 struct v4l2_subdev_format fmt
= {
1483 .which
= V4L2_SUBDEV_FORMAT_TRY
,
1485 .width
= def_mode
->width
,
1486 .height
= def_mode
->height
,
1490 ov8858_set_fmt(sd
, sd_state
, &fmt
);
1495 static const struct v4l2_subdev_pad_ops ov8858_pad_ops
= {
1496 .enum_mbus_code
= ov8858_enum_mbus_code
,
1497 .enum_frame_size
= ov8858_enum_frame_sizes
,
1498 .get_fmt
= v4l2_subdev_get_fmt
,
1499 .set_fmt
= ov8858_set_fmt
,
1502 static const struct v4l2_subdev_ops ov8858_subdev_ops
= {
1503 .video
= &ov8858_video_ops
,
1504 .pad
= &ov8858_pad_ops
,
1507 static const struct v4l2_subdev_internal_ops ov8858_internal_ops
= {
1508 .init_state
= ov8858_init_state
,
1511 /* ----------------------------------------------------------------------------
1515 static int ov8858_enable_test_pattern(struct ov8858
*ov8858
, u32 pattern
)
1520 val
= (pattern
- 1) | OV8858_TEST_PATTERN_ENABLE
;
1522 val
= OV8858_TEST_PATTERN_DISABLE
;
1524 return ov8858_write(ov8858
, OV8858_REG_TEST_PATTERN
, val
, NULL
);
1527 static int ov8858_set_ctrl(struct v4l2_ctrl
*ctrl
)
1529 struct ov8858
*ov8858
= container_of(ctrl
->handler
,
1530 struct ov8858
, ctrl_handler
);
1532 struct i2c_client
*client
= v4l2_get_subdevdata(&ov8858
->subdev
);
1533 struct v4l2_mbus_framefmt
*format
;
1534 struct v4l2_subdev_state
*state
;
1540 * The control handler and the subdev state use the same mutex and the
1541 * mutex is guaranteed to be locked:
1542 * - by the core when s_ctrl is called int the VIDIOC_S_CTRL call path
1543 * - by the driver when s_ctrl is called in the s_stream(1) call path
1545 state
= v4l2_subdev_get_locked_active_state(&ov8858
->subdev
);
1546 format
= v4l2_subdev_state_get_format(state
, 0);
1548 /* Propagate change of current control to all related controls */
1550 case V4L2_CID_VBLANK
:
1551 /* Update max exposure while meeting expected vblanking */
1552 max_exp
= format
->height
+ ctrl
->val
- OV8858_EXPOSURE_MARGIN
;
1553 __v4l2_ctrl_modify_range(ov8858
->exposure
,
1554 ov8858
->exposure
->minimum
, max_exp
,
1555 ov8858
->exposure
->step
,
1556 ov8858
->exposure
->default_value
);
1560 if (!pm_runtime_get_if_in_use(&client
->dev
))
1564 case V4L2_CID_EXPOSURE
:
1565 /* 4 least significant bits of exposure are fractional part */
1566 ret
= ov8858_write(ov8858
, OV8858_REG_LONG_EXPO
,
1567 ctrl
->val
<< 4, NULL
);
1569 case V4L2_CID_ANALOGUE_GAIN
:
1570 ret
= ov8858_write(ov8858
, OV8858_REG_LONG_GAIN
,
1573 case V4L2_CID_DIGITAL_GAIN
:
1575 * Digital gain is assembled as:
1576 * 0x350a[7:0] = dgain[13:6]
1577 * 0x350b[5:0] = dgain[5:0]
1578 * Reassemble the control value to write it in one go.
1580 digi_gain
= (ctrl
->val
& OV8858_LONG_DIGIGAIN_L_MASK
)
1581 | ((ctrl
->val
& OV8858_LONG_DIGIGAIN_H_MASK
) <<
1582 OV8858_LONG_DIGIGAIN_H_SHIFT
);
1583 ret
= ov8858_write(ov8858
, OV8858_REG_LONG_DIGIGAIN
,
1586 case V4L2_CID_VBLANK
:
1587 ret
= ov8858_write(ov8858
, OV8858_REG_VTS
,
1588 ctrl
->val
+ format
->height
, NULL
);
1590 case V4L2_CID_TEST_PATTERN
:
1591 ret
= ov8858_enable_test_pattern(ov8858
, ctrl
->val
);
1595 dev_warn(&client
->dev
, "%s Unhandled id: 0x%x\n",
1596 __func__
, ctrl
->id
);
1600 pm_runtime_put(&client
->dev
);
1605 static const struct v4l2_ctrl_ops ov8858_ctrl_ops
= {
1606 .s_ctrl
= ov8858_set_ctrl
,
1609 /* ----------------------------------------------------------------------------
1613 static int ov8858_power_on(struct ov8858
*ov8858
)
1615 struct i2c_client
*client
= v4l2_get_subdevdata(&ov8858
->subdev
);
1616 struct device
*dev
= &client
->dev
;
1617 unsigned long delay_us
;
1620 if (clk_get_rate(ov8858
->xvclk
) != OV8858_XVCLK_FREQ
)
1621 dev_warn(dev
, "xvclk mismatched, modes are based on 24MHz\n");
1623 ret
= clk_prepare_enable(ov8858
->xvclk
);
1625 dev_err(dev
, "Failed to enable xvclk\n");
1629 ret
= regulator_bulk_enable(ARRAY_SIZE(ov8858_supply_names
),
1632 dev_err(dev
, "Failed to enable regulators\n");
1637 * The chip manual only suggests 8192 cycles prior to first SCCB
1638 * transaction, but a double sleep between the release of gpios
1639 * helps with sporadic failures observed at probe time.
1641 delay_us
= DIV_ROUND_UP(8192, OV8858_XVCLK_FREQ
/ 1000 / 1000);
1643 gpiod_set_value_cansleep(ov8858
->reset_gpio
, 0);
1645 gpiod_set_value_cansleep(ov8858
->pwdn_gpio
, 0);
1651 clk_disable_unprepare(ov8858
->xvclk
);
1656 static void ov8858_power_off(struct ov8858
*ov8858
)
1658 gpiod_set_value_cansleep(ov8858
->pwdn_gpio
, 1);
1659 clk_disable_unprepare(ov8858
->xvclk
);
1660 gpiod_set_value_cansleep(ov8858
->reset_gpio
, 1);
1662 regulator_bulk_disable(ARRAY_SIZE(ov8858_supply_names
),
1666 static int ov8858_runtime_resume(struct device
*dev
)
1668 struct i2c_client
*client
= to_i2c_client(dev
);
1669 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
1670 struct ov8858
*ov8858
= sd_to_ov8858(sd
);
1672 return ov8858_power_on(ov8858
);
1675 static int ov8858_runtime_suspend(struct device
*dev
)
1677 struct i2c_client
*client
= to_i2c_client(dev
);
1678 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
1679 struct ov8858
*ov8858
= sd_to_ov8858(sd
);
1681 ov8858_power_off(ov8858
);
1686 static const struct dev_pm_ops ov8858_pm_ops
= {
1687 SET_RUNTIME_PM_OPS(ov8858_runtime_suspend
,
1688 ov8858_runtime_resume
, NULL
)
1691 /* ----------------------------------------------------------------------------
1692 * Probe and initialization
1695 static int ov8858_init_ctrls(struct ov8858
*ov8858
)
1697 struct i2c_client
*client
= v4l2_get_subdevdata(&ov8858
->subdev
);
1698 struct v4l2_ctrl_handler
*handler
= &ov8858
->ctrl_handler
;
1699 const struct ov8858_mode
*mode
= &ov8858_modes
[0];
1700 struct v4l2_fwnode_device_properties props
;
1701 s64 exposure_max
, vblank_def
;
1702 unsigned int pixel_rate
;
1703 struct v4l2_ctrl
*ctrl
;
1707 ret
= v4l2_ctrl_handler_init(handler
, 10);
1711 ctrl
= v4l2_ctrl_new_int_menu(handler
, NULL
, V4L2_CID_LINK_FREQ
,
1712 0, 0, link_freq_menu_items
);
1714 ctrl
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
1716 /* pixel rate = link frequency * 2 * lanes / bpp */
1717 pixel_rate
= OV8858_LINK_FREQ
* 2 * ov8858
->num_lanes
/ 10;
1718 v4l2_ctrl_new_std(handler
, NULL
, V4L2_CID_PIXEL_RATE
,
1719 0, pixel_rate
, 1, pixel_rate
);
1721 h_blank
= mode
->hts_def
- mode
->width
;
1722 ov8858
->hblank
= v4l2_ctrl_new_std(handler
, NULL
, V4L2_CID_HBLANK
,
1723 h_blank
, h_blank
, 1, h_blank
);
1725 ov8858
->hblank
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
1727 vblank_def
= mode
->vts_def
- mode
->height
;
1728 ov8858
->vblank
= v4l2_ctrl_new_std(handler
, &ov8858_ctrl_ops
,
1729 V4L2_CID_VBLANK
, vblank_def
,
1730 OV8858_VTS_MAX
- mode
->height
,
1733 exposure_max
= mode
->vts_def
- OV8858_EXPOSURE_MARGIN
;
1734 ov8858
->exposure
= v4l2_ctrl_new_std(handler
, &ov8858_ctrl_ops
,
1736 OV8858_EXPOSURE_MIN
,
1737 exposure_max
, OV8858_EXPOSURE_STEP
,
1740 v4l2_ctrl_new_std(handler
, &ov8858_ctrl_ops
, V4L2_CID_ANALOGUE_GAIN
,
1741 OV8858_LONG_GAIN_MIN
, OV8858_LONG_GAIN_MAX
,
1742 OV8858_LONG_GAIN_STEP
, OV8858_LONG_GAIN_DEFAULT
);
1744 v4l2_ctrl_new_std(handler
, &ov8858_ctrl_ops
, V4L2_CID_DIGITAL_GAIN
,
1745 OV8858_LONG_DIGIGAIN_MIN
, OV8858_LONG_DIGIGAIN_MAX
,
1746 OV8858_LONG_DIGIGAIN_STEP
,
1747 OV8858_LONG_DIGIGAIN_DEFAULT
);
1749 v4l2_ctrl_new_std_menu_items(handler
, &ov8858_ctrl_ops
,
1750 V4L2_CID_TEST_PATTERN
,
1751 ARRAY_SIZE(ov8858_test_pattern_menu
) - 1,
1752 0, 0, ov8858_test_pattern_menu
);
1754 if (handler
->error
) {
1755 ret
= handler
->error
;
1756 goto err_free_handler
;
1759 ret
= v4l2_fwnode_device_parse(&client
->dev
, &props
);
1761 goto err_free_handler
;
1763 ret
= v4l2_ctrl_new_fwnode_properties(handler
, &ov8858_ctrl_ops
,
1766 goto err_free_handler
;
1768 ov8858
->subdev
.ctrl_handler
= handler
;
1773 dev_err(&client
->dev
, "Failed to init controls: %d\n", ret
);
1774 v4l2_ctrl_handler_free(handler
);
1779 static int ov8858_check_sensor_id(struct ov8858
*ov8858
)
1781 struct i2c_client
*client
= v4l2_get_subdevdata(&ov8858
->subdev
);
1785 ret
= ov8858_read(ov8858
, OV8858_REG_CHIP_ID
, &id
);
1789 if (id
!= OV8858_CHIP_ID
) {
1790 dev_err(&client
->dev
, "Unexpected sensor id 0x%x\n", id
);
1794 ret
= ov8858_read(ov8858
, OV8858_REG_SUB_ID
, &id
);
1798 dev_info(&client
->dev
, "Detected OV8858 sensor, revision 0x%x\n", id
);
1800 if (id
== OV8858_R2A
) {
1801 /* R2A supports 2 and 4 lanes modes. */
1802 ov8858
->global_regs
= ov8858
->num_lanes
== 4
1803 ? ov8858_global_regs_r2a_4lane
1804 : ov8858_global_regs_r2a_2lane
;
1805 } else if (ov8858
->num_lanes
== 2) {
1807 * R1A only supports 2 lanes mode and it's only partially
1810 ov8858
->global_regs
= ov8858_global_regs_r1a
;
1811 dev_warn(&client
->dev
, "R1A may not work well!\n");
1813 dev_err(&client
->dev
,
1814 "Unsupported number of data lanes for R1A revision.\n");
1821 static int ov8858_configure_regulators(struct ov8858
*ov8858
)
1823 struct i2c_client
*client
= v4l2_get_subdevdata(&ov8858
->subdev
);
1826 for (i
= 0; i
< ARRAY_SIZE(ov8858_supply_names
); i
++)
1827 ov8858
->supplies
[i
].supply
= ov8858_supply_names
[i
];
1829 return devm_regulator_bulk_get(&client
->dev
,
1830 ARRAY_SIZE(ov8858_supply_names
),
1834 static int ov8858_parse_of(struct ov8858
*ov8858
)
1836 struct v4l2_fwnode_endpoint vep
= { .bus_type
= V4L2_MBUS_CSI2_DPHY
};
1837 struct i2c_client
*client
= v4l2_get_subdevdata(&ov8858
->subdev
);
1838 struct device
*dev
= &client
->dev
;
1839 struct fwnode_handle
*endpoint
;
1842 endpoint
= fwnode_graph_get_next_endpoint(dev_fwnode(dev
), NULL
);
1844 dev_err(dev
, "Failed to get endpoint\n");
1848 ret
= v4l2_fwnode_endpoint_parse(endpoint
, &vep
);
1849 fwnode_handle_put(endpoint
);
1851 dev_err(dev
, "Failed to parse endpoint: %d\n", ret
);
1855 ov8858
->num_lanes
= vep
.bus
.mipi_csi2
.num_data_lanes
;
1856 switch (ov8858
->num_lanes
) {
1861 dev_err(dev
, "Unsupported number of data lanes %u\n",
1869 static int ov8858_probe(struct i2c_client
*client
)
1871 struct device
*dev
= &client
->dev
;
1872 struct v4l2_subdev
*sd
;
1873 struct ov8858
*ov8858
;
1876 ov8858
= devm_kzalloc(dev
, sizeof(*ov8858
), GFP_KERNEL
);
1880 ov8858
->xvclk
= devm_clk_get(dev
, "xvclk");
1881 if (IS_ERR(ov8858
->xvclk
))
1882 return dev_err_probe(dev
, PTR_ERR(ov8858
->xvclk
),
1883 "Failed to get xvclk\n");
1885 ov8858
->reset_gpio
= devm_gpiod_get_optional(dev
, "reset",
1887 if (IS_ERR(ov8858
->reset_gpio
))
1888 return dev_err_probe(dev
, PTR_ERR(ov8858
->reset_gpio
),
1889 "Failed to get reset gpio\n");
1891 ov8858
->pwdn_gpio
= devm_gpiod_get_optional(dev
, "powerdown",
1893 if (IS_ERR(ov8858
->pwdn_gpio
))
1894 return dev_err_probe(dev
, PTR_ERR(ov8858
->pwdn_gpio
),
1895 "Failed to get powerdown gpio\n");
1897 v4l2_i2c_subdev_init(&ov8858
->subdev
, client
, &ov8858_subdev_ops
);
1898 ov8858
->subdev
.internal_ops
= &ov8858_internal_ops
;
1900 ret
= ov8858_configure_regulators(ov8858
);
1902 return dev_err_probe(dev
, ret
, "Failed to get regulators\n");
1904 ret
= ov8858_parse_of(ov8858
);
1908 ret
= ov8858_init_ctrls(ov8858
);
1912 sd
= &ov8858
->subdev
;
1913 sd
->flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
1914 ov8858
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
1915 sd
->entity
.function
= MEDIA_ENT_F_CAM_SENSOR
;
1916 ret
= media_entity_pads_init(&sd
->entity
, 1, &ov8858
->pad
);
1918 goto err_free_handler
;
1920 sd
->state_lock
= ov8858
->ctrl_handler
.lock
;
1921 ret
= v4l2_subdev_init_finalize(sd
);
1923 dev_err(&client
->dev
, "Subdev initialization error %d\n", ret
);
1924 goto err_clean_entity
;
1927 ret
= ov8858_power_on(ov8858
);
1929 goto err_clean_entity
;
1931 pm_runtime_set_active(dev
);
1932 pm_runtime_get_noresume(dev
);
1933 pm_runtime_enable(dev
);
1935 ret
= ov8858_check_sensor_id(ov8858
);
1939 pm_runtime_set_autosuspend_delay(dev
, 1000);
1940 pm_runtime_use_autosuspend(dev
);
1942 ret
= v4l2_async_register_subdev_sensor(sd
);
1944 dev_err(dev
, "v4l2 async register subdev failed\n");
1948 pm_runtime_mark_last_busy(dev
);
1949 pm_runtime_put_autosuspend(dev
);
1954 pm_runtime_disable(dev
);
1955 pm_runtime_put_noidle(dev
);
1956 ov8858_power_off(ov8858
);
1958 media_entity_cleanup(&sd
->entity
);
1960 v4l2_ctrl_handler_free(&ov8858
->ctrl_handler
);
1965 static void ov8858_remove(struct i2c_client
*client
)
1967 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
1968 struct ov8858
*ov8858
= sd_to_ov8858(sd
);
1970 v4l2_async_unregister_subdev(sd
);
1971 media_entity_cleanup(&sd
->entity
);
1972 v4l2_ctrl_handler_free(&ov8858
->ctrl_handler
);
1974 pm_runtime_disable(&client
->dev
);
1975 if (!pm_runtime_status_suspended(&client
->dev
))
1976 ov8858_power_off(ov8858
);
1977 pm_runtime_set_suspended(&client
->dev
);
1980 static const struct of_device_id ov8858_of_match
[] = {
1981 { .compatible
= "ovti,ov8858" },
1984 MODULE_DEVICE_TABLE(of
, ov8858_of_match
);
1986 static struct i2c_driver ov8858_i2c_driver
= {
1989 .pm
= &ov8858_pm_ops
,
1990 .of_match_table
= ov8858_of_match
,
1992 .probe
= ov8858_probe
,
1993 .remove
= ov8858_remove
,
1996 module_i2c_driver(ov8858_i2c_driver
);
1998 MODULE_DESCRIPTION("OmniVision OV8858 sensor driver");
1999 MODULE_LICENSE("GPL");