xref: /openbmc/linux/drivers/media/i2c/ov13858.c (revision 15786f7b564eff32d8dae73d40d77dc4e3c7298f)
128cab405SChiranjeevi Rapolu // SPDX-License-Identifier: GPL-2.0
228cab405SChiranjeevi Rapolu // Copyright (c) 2017 Intel Corporation.
35fcf092eSHyungwoo Yang 
45fcf092eSHyungwoo Yang #include <linux/acpi.h>
55fcf092eSHyungwoo Yang #include <linux/i2c.h>
65fcf092eSHyungwoo Yang #include <linux/module.h>
75fcf092eSHyungwoo Yang #include <linux/pm_runtime.h>
85fcf092eSHyungwoo Yang #include <media/v4l2-ctrls.h>
95fcf092eSHyungwoo Yang #include <media/v4l2-device.h>
1074c3ddd9SJacopo Mondi #include <media/v4l2-fwnode.h>
115fcf092eSHyungwoo Yang 
125fcf092eSHyungwoo Yang #define OV13858_REG_VALUE_08BIT		1
135fcf092eSHyungwoo Yang #define OV13858_REG_VALUE_16BIT		2
145fcf092eSHyungwoo Yang #define OV13858_REG_VALUE_24BIT		3
155fcf092eSHyungwoo Yang 
165fcf092eSHyungwoo Yang #define OV13858_REG_MODE_SELECT		0x0100
175fcf092eSHyungwoo Yang #define OV13858_MODE_STANDBY		0x00
185fcf092eSHyungwoo Yang #define OV13858_MODE_STREAMING		0x01
195fcf092eSHyungwoo Yang 
205fcf092eSHyungwoo Yang #define OV13858_REG_SOFTWARE_RST	0x0103
215fcf092eSHyungwoo Yang #define OV13858_SOFTWARE_RST		0x01
225fcf092eSHyungwoo Yang 
235fcf092eSHyungwoo Yang /* PLL1 generates PCLK and MIPI_PHY_CLK */
245fcf092eSHyungwoo Yang #define OV13858_REG_PLL1_CTRL_0		0x0300
255fcf092eSHyungwoo Yang #define OV13858_REG_PLL1_CTRL_1		0x0301
265fcf092eSHyungwoo Yang #define OV13858_REG_PLL1_CTRL_2		0x0302
275fcf092eSHyungwoo Yang #define OV13858_REG_PLL1_CTRL_3		0x0303
285fcf092eSHyungwoo Yang #define OV13858_REG_PLL1_CTRL_4		0x0304
295fcf092eSHyungwoo Yang #define OV13858_REG_PLL1_CTRL_5		0x0305
305fcf092eSHyungwoo Yang 
315fcf092eSHyungwoo Yang /* PLL2 generates DAC_CLK, SCLK and SRAM_CLK */
325fcf092eSHyungwoo Yang #define OV13858_REG_PLL2_CTRL_B		0x030b
335fcf092eSHyungwoo Yang #define OV13858_REG_PLL2_CTRL_C		0x030c
345fcf092eSHyungwoo Yang #define OV13858_REG_PLL2_CTRL_D		0x030d
355fcf092eSHyungwoo Yang #define OV13858_REG_PLL2_CTRL_E		0x030e
365fcf092eSHyungwoo Yang #define OV13858_REG_PLL2_CTRL_F		0x030f
375fcf092eSHyungwoo Yang #define OV13858_REG_PLL2_CTRL_12	0x0312
385fcf092eSHyungwoo Yang #define OV13858_REG_MIPI_SC_CTRL0	0x3016
395fcf092eSHyungwoo Yang #define OV13858_REG_MIPI_SC_CTRL1	0x3022
405fcf092eSHyungwoo Yang 
415fcf092eSHyungwoo Yang /* Chip ID */
425fcf092eSHyungwoo Yang #define OV13858_REG_CHIP_ID		0x300a
435fcf092eSHyungwoo Yang #define OV13858_CHIP_ID			0x00d855
445fcf092eSHyungwoo Yang 
455fcf092eSHyungwoo Yang /* V_TIMING internal */
465fcf092eSHyungwoo Yang #define OV13858_REG_VTS			0x380e
475fcf092eSHyungwoo Yang #define OV13858_VTS_30FPS		0x0c8e /* 30 fps */
485fcf092eSHyungwoo Yang #define OV13858_VTS_60FPS		0x0648 /* 60 fps */
495fcf092eSHyungwoo Yang #define OV13858_VTS_MAX			0x7fff
505fcf092eSHyungwoo Yang 
515fcf092eSHyungwoo Yang /* HBLANK control - read only */
5289d8b615SChiranjeevi Rapolu #define OV13858_PPL_270MHZ		2244
5389d8b615SChiranjeevi Rapolu #define OV13858_PPL_540MHZ		4488
545fcf092eSHyungwoo Yang 
555fcf092eSHyungwoo Yang /* Exposure control */
565fcf092eSHyungwoo Yang #define OV13858_REG_EXPOSURE		0x3500
575fcf092eSHyungwoo Yang #define OV13858_EXPOSURE_MIN		4
585fcf092eSHyungwoo Yang #define OV13858_EXPOSURE_STEP		1
595fcf092eSHyungwoo Yang #define OV13858_EXPOSURE_DEFAULT	0x640
605fcf092eSHyungwoo Yang 
615fcf092eSHyungwoo Yang /* Analog gain control */
625fcf092eSHyungwoo Yang #define OV13858_REG_ANALOG_GAIN		0x3508
635fcf092eSHyungwoo Yang #define OV13858_ANA_GAIN_MIN		0
645fcf092eSHyungwoo Yang #define OV13858_ANA_GAIN_MAX		0x1fff
655fcf092eSHyungwoo Yang #define OV13858_ANA_GAIN_STEP		1
665fcf092eSHyungwoo Yang #define OV13858_ANA_GAIN_DEFAULT	0x80
675fcf092eSHyungwoo Yang 
685fcf092eSHyungwoo Yang /* Digital gain control */
69bfced6d1SChiranjeevi Rapolu #define OV13858_REG_B_MWB_GAIN		0x5100
70bfced6d1SChiranjeevi Rapolu #define OV13858_REG_G_MWB_GAIN		0x5102
71bfced6d1SChiranjeevi Rapolu #define OV13858_REG_R_MWB_GAIN		0x5104
72bfced6d1SChiranjeevi Rapolu #define OV13858_DGTL_GAIN_MIN		0
73bfced6d1SChiranjeevi Rapolu #define OV13858_DGTL_GAIN_MAX		16384	/* Max = 16 X */
74bfced6d1SChiranjeevi Rapolu #define OV13858_DGTL_GAIN_DEFAULT	1024	/* Default gain = 1 X */
75bfced6d1SChiranjeevi Rapolu #define OV13858_DGTL_GAIN_STEP		1	/* Each step = 1/1024 */
765fcf092eSHyungwoo Yang 
775fcf092eSHyungwoo Yang /* Test Pattern Control */
785fcf092eSHyungwoo Yang #define OV13858_REG_TEST_PATTERN	0x4503
795fcf092eSHyungwoo Yang #define OV13858_TEST_PATTERN_ENABLE	BIT(7)
805fcf092eSHyungwoo Yang #define OV13858_TEST_PATTERN_MASK	0xfc
815fcf092eSHyungwoo Yang 
825fcf092eSHyungwoo Yang /* Number of frames to skip */
835fcf092eSHyungwoo Yang #define OV13858_NUM_OF_SKIP_FRAMES	2
845fcf092eSHyungwoo Yang 
855fcf092eSHyungwoo Yang struct ov13858_reg {
865fcf092eSHyungwoo Yang 	u16 address;
875fcf092eSHyungwoo Yang 	u8 val;
885fcf092eSHyungwoo Yang };
895fcf092eSHyungwoo Yang 
905fcf092eSHyungwoo Yang struct ov13858_reg_list {
915fcf092eSHyungwoo Yang 	u32 num_of_regs;
925fcf092eSHyungwoo Yang 	const struct ov13858_reg *regs;
935fcf092eSHyungwoo Yang };
945fcf092eSHyungwoo Yang 
955fcf092eSHyungwoo Yang /* Link frequency config */
965fcf092eSHyungwoo Yang struct ov13858_link_freq_config {
975fcf092eSHyungwoo Yang 	u32 pixels_per_line;
985fcf092eSHyungwoo Yang 
995fcf092eSHyungwoo Yang 	/* PLL registers for this link frequency */
1005fcf092eSHyungwoo Yang 	struct ov13858_reg_list reg_list;
1015fcf092eSHyungwoo Yang };
1025fcf092eSHyungwoo Yang 
1035fcf092eSHyungwoo Yang /* Mode : resolution and related config&values */
1045fcf092eSHyungwoo Yang struct ov13858_mode {
1055fcf092eSHyungwoo Yang 	/* Frame width */
1065fcf092eSHyungwoo Yang 	u32 width;
1075fcf092eSHyungwoo Yang 	/* Frame height */
1085fcf092eSHyungwoo Yang 	u32 height;
1095fcf092eSHyungwoo Yang 
1105fcf092eSHyungwoo Yang 	/* V-timing */
11117fcd5f5SChiranjeevi Rapolu 	u32 vts_def;
11217fcd5f5SChiranjeevi Rapolu 	u32 vts_min;
1135fcf092eSHyungwoo Yang 
1145fcf092eSHyungwoo Yang 	/* Index of Link frequency config to be used */
1155fcf092eSHyungwoo Yang 	u32 link_freq_index;
1165fcf092eSHyungwoo Yang 	/* Default register values */
1175fcf092eSHyungwoo Yang 	struct ov13858_reg_list reg_list;
1185fcf092eSHyungwoo Yang };
1195fcf092eSHyungwoo Yang 
1205fcf092eSHyungwoo Yang /* 4224x3136 needs 1080Mbps/lane, 4 lanes */
1215fcf092eSHyungwoo Yang static const struct ov13858_reg mipi_data_rate_1080mbps[] = {
1225fcf092eSHyungwoo Yang 	/* PLL1 registers */
1235fcf092eSHyungwoo Yang 	{OV13858_REG_PLL1_CTRL_0, 0x07},
1245fcf092eSHyungwoo Yang 	{OV13858_REG_PLL1_CTRL_1, 0x01},
1255fcf092eSHyungwoo Yang 	{OV13858_REG_PLL1_CTRL_2, 0xc2},
1265fcf092eSHyungwoo Yang 	{OV13858_REG_PLL1_CTRL_3, 0x00},
1275fcf092eSHyungwoo Yang 	{OV13858_REG_PLL1_CTRL_4, 0x00},
1285fcf092eSHyungwoo Yang 	{OV13858_REG_PLL1_CTRL_5, 0x01},
1295fcf092eSHyungwoo Yang 
1305fcf092eSHyungwoo Yang 	/* PLL2 registers */
1315fcf092eSHyungwoo Yang 	{OV13858_REG_PLL2_CTRL_B, 0x05},
1325fcf092eSHyungwoo Yang 	{OV13858_REG_PLL2_CTRL_C, 0x01},
1335fcf092eSHyungwoo Yang 	{OV13858_REG_PLL2_CTRL_D, 0x0e},
1345fcf092eSHyungwoo Yang 	{OV13858_REG_PLL2_CTRL_E, 0x05},
1355fcf092eSHyungwoo Yang 	{OV13858_REG_PLL2_CTRL_F, 0x01},
1365fcf092eSHyungwoo Yang 	{OV13858_REG_PLL2_CTRL_12, 0x01},
1375fcf092eSHyungwoo Yang 	{OV13858_REG_MIPI_SC_CTRL0, 0x72},
1385fcf092eSHyungwoo Yang 	{OV13858_REG_MIPI_SC_CTRL1, 0x01},
1395fcf092eSHyungwoo Yang };
1405fcf092eSHyungwoo Yang 
1415fcf092eSHyungwoo Yang /*
1425fcf092eSHyungwoo Yang  * 2112x1568, 2112x1188, 1056x784 need 540Mbps/lane,
1435fcf092eSHyungwoo Yang  * 4 lanes
1445fcf092eSHyungwoo Yang  */
1455fcf092eSHyungwoo Yang static const struct ov13858_reg mipi_data_rate_540mbps[] = {
1465fcf092eSHyungwoo Yang 	/* PLL1 registers */
1475fcf092eSHyungwoo Yang 	{OV13858_REG_PLL1_CTRL_0, 0x07},
1485fcf092eSHyungwoo Yang 	{OV13858_REG_PLL1_CTRL_1, 0x01},
1495fcf092eSHyungwoo Yang 	{OV13858_REG_PLL1_CTRL_2, 0xc2},
1505fcf092eSHyungwoo Yang 	{OV13858_REG_PLL1_CTRL_3, 0x01},
1515fcf092eSHyungwoo Yang 	{OV13858_REG_PLL1_CTRL_4, 0x00},
1525fcf092eSHyungwoo Yang 	{OV13858_REG_PLL1_CTRL_5, 0x01},
1535fcf092eSHyungwoo Yang 
1545fcf092eSHyungwoo Yang 	/* PLL2 registers */
1555fcf092eSHyungwoo Yang 	{OV13858_REG_PLL2_CTRL_B, 0x05},
1565fcf092eSHyungwoo Yang 	{OV13858_REG_PLL2_CTRL_C, 0x01},
1575fcf092eSHyungwoo Yang 	{OV13858_REG_PLL2_CTRL_D, 0x0e},
1585fcf092eSHyungwoo Yang 	{OV13858_REG_PLL2_CTRL_E, 0x05},
1595fcf092eSHyungwoo Yang 	{OV13858_REG_PLL2_CTRL_F, 0x01},
1605fcf092eSHyungwoo Yang 	{OV13858_REG_PLL2_CTRL_12, 0x01},
1615fcf092eSHyungwoo Yang 	{OV13858_REG_MIPI_SC_CTRL0, 0x72},
1625fcf092eSHyungwoo Yang 	{OV13858_REG_MIPI_SC_CTRL1, 0x01},
1635fcf092eSHyungwoo Yang };
1645fcf092eSHyungwoo Yang 
1655fcf092eSHyungwoo Yang static const struct ov13858_reg mode_4224x3136_regs[] = {
1665fcf092eSHyungwoo Yang 	{0x3013, 0x32},
1675fcf092eSHyungwoo Yang 	{0x301b, 0xf0},
1685fcf092eSHyungwoo Yang 	{0x301f, 0xd0},
1695fcf092eSHyungwoo Yang 	{0x3106, 0x15},
1705fcf092eSHyungwoo Yang 	{0x3107, 0x23},
1715fcf092eSHyungwoo Yang 	{0x350a, 0x00},
1725fcf092eSHyungwoo Yang 	{0x350e, 0x00},
1735fcf092eSHyungwoo Yang 	{0x3510, 0x00},
1745fcf092eSHyungwoo Yang 	{0x3511, 0x02},
1755fcf092eSHyungwoo Yang 	{0x3512, 0x00},
1765fcf092eSHyungwoo Yang 	{0x3600, 0x2b},
1775fcf092eSHyungwoo Yang 	{0x3601, 0x52},
1785fcf092eSHyungwoo Yang 	{0x3602, 0x60},
1795fcf092eSHyungwoo Yang 	{0x3612, 0x05},
1805fcf092eSHyungwoo Yang 	{0x3613, 0xa4},
1815fcf092eSHyungwoo Yang 	{0x3620, 0x80},
1825fcf092eSHyungwoo Yang 	{0x3621, 0x10},
1835fcf092eSHyungwoo Yang 	{0x3622, 0x30},
1845fcf092eSHyungwoo Yang 	{0x3624, 0x1c},
1855fcf092eSHyungwoo Yang 	{0x3640, 0x10},
1865fcf092eSHyungwoo Yang 	{0x3641, 0x70},
187d365bc92SChiranjeevi Rapolu 	{0x3660, 0x04},
1885fcf092eSHyungwoo Yang 	{0x3661, 0x80},
1895fcf092eSHyungwoo Yang 	{0x3662, 0x12},
1905fcf092eSHyungwoo Yang 	{0x3664, 0x73},
1915fcf092eSHyungwoo Yang 	{0x3665, 0xa7},
1925fcf092eSHyungwoo Yang 	{0x366e, 0xff},
1935fcf092eSHyungwoo Yang 	{0x366f, 0xf4},
1945fcf092eSHyungwoo Yang 	{0x3674, 0x00},
1955fcf092eSHyungwoo Yang 	{0x3679, 0x0c},
1965fcf092eSHyungwoo Yang 	{0x367f, 0x01},
1975fcf092eSHyungwoo Yang 	{0x3680, 0x0c},
1985fcf092eSHyungwoo Yang 	{0x3681, 0x50},
1995fcf092eSHyungwoo Yang 	{0x3682, 0x50},
2005fcf092eSHyungwoo Yang 	{0x3683, 0xa9},
2015fcf092eSHyungwoo Yang 	{0x3684, 0xa9},
2025fcf092eSHyungwoo Yang 	{0x3709, 0x5f},
2035fcf092eSHyungwoo Yang 	{0x3714, 0x24},
2045fcf092eSHyungwoo Yang 	{0x371a, 0x3e},
2055fcf092eSHyungwoo Yang 	{0x3737, 0x04},
2065fcf092eSHyungwoo Yang 	{0x3738, 0xcc},
2075fcf092eSHyungwoo Yang 	{0x3739, 0x12},
2085fcf092eSHyungwoo Yang 	{0x373d, 0x26},
2095fcf092eSHyungwoo Yang 	{0x3764, 0x20},
2105fcf092eSHyungwoo Yang 	{0x3765, 0x20},
2115fcf092eSHyungwoo Yang 	{0x37a1, 0x36},
2125fcf092eSHyungwoo Yang 	{0x37a8, 0x3b},
2135fcf092eSHyungwoo Yang 	{0x37ab, 0x31},
2145fcf092eSHyungwoo Yang 	{0x37c2, 0x04},
2155fcf092eSHyungwoo Yang 	{0x37c3, 0xf1},
2165fcf092eSHyungwoo Yang 	{0x37c5, 0x00},
2175fcf092eSHyungwoo Yang 	{0x37d8, 0x03},
2185fcf092eSHyungwoo Yang 	{0x37d9, 0x0c},
2195fcf092eSHyungwoo Yang 	{0x37da, 0xc2},
2205fcf092eSHyungwoo Yang 	{0x37dc, 0x02},
2215fcf092eSHyungwoo Yang 	{0x37e0, 0x00},
2225fcf092eSHyungwoo Yang 	{0x37e1, 0x0a},
2235fcf092eSHyungwoo Yang 	{0x37e2, 0x14},
2245fcf092eSHyungwoo Yang 	{0x37e3, 0x04},
2255fcf092eSHyungwoo Yang 	{0x37e4, 0x2a},
2265fcf092eSHyungwoo Yang 	{0x37e5, 0x03},
2275fcf092eSHyungwoo Yang 	{0x37e6, 0x04},
2285fcf092eSHyungwoo Yang 	{0x3800, 0x00},
2295fcf092eSHyungwoo Yang 	{0x3801, 0x00},
2305fcf092eSHyungwoo Yang 	{0x3802, 0x00},
23158020c9fSChiranjeevi Rapolu 	{0x3803, 0x08},
2325fcf092eSHyungwoo Yang 	{0x3804, 0x10},
2335fcf092eSHyungwoo Yang 	{0x3805, 0x9f},
2345fcf092eSHyungwoo Yang 	{0x3806, 0x0c},
23558020c9fSChiranjeevi Rapolu 	{0x3807, 0x57},
2365fcf092eSHyungwoo Yang 	{0x3808, 0x10},
2375fcf092eSHyungwoo Yang 	{0x3809, 0x80},
2385fcf092eSHyungwoo Yang 	{0x380a, 0x0c},
2395fcf092eSHyungwoo Yang 	{0x380b, 0x40},
2405fcf092eSHyungwoo Yang 	{0x380c, 0x04},
2415fcf092eSHyungwoo Yang 	{0x380d, 0x62},
2425fcf092eSHyungwoo Yang 	{0x380e, 0x0c},
2435fcf092eSHyungwoo Yang 	{0x380f, 0x8e},
2445fcf092eSHyungwoo Yang 	{0x3811, 0x04},
2455fcf092eSHyungwoo Yang 	{0x3813, 0x05},
2465fcf092eSHyungwoo Yang 	{0x3814, 0x01},
2475fcf092eSHyungwoo Yang 	{0x3815, 0x01},
2485fcf092eSHyungwoo Yang 	{0x3816, 0x01},
2495fcf092eSHyungwoo Yang 	{0x3817, 0x01},
2505fcf092eSHyungwoo Yang 	{0x3820, 0xa8},
2515fcf092eSHyungwoo Yang 	{0x3821, 0x00},
2525fcf092eSHyungwoo Yang 	{0x3822, 0xc2},
2535fcf092eSHyungwoo Yang 	{0x3823, 0x18},
2545fcf092eSHyungwoo Yang 	{0x3826, 0x11},
2555fcf092eSHyungwoo Yang 	{0x3827, 0x1c},
2565fcf092eSHyungwoo Yang 	{0x3829, 0x03},
2575fcf092eSHyungwoo Yang 	{0x3832, 0x00},
2585fcf092eSHyungwoo Yang 	{0x3c80, 0x00},
2595fcf092eSHyungwoo Yang 	{0x3c87, 0x01},
2605fcf092eSHyungwoo Yang 	{0x3c8c, 0x19},
2615fcf092eSHyungwoo Yang 	{0x3c8d, 0x1c},
2625fcf092eSHyungwoo Yang 	{0x3c90, 0x00},
2635fcf092eSHyungwoo Yang 	{0x3c91, 0x00},
2645fcf092eSHyungwoo Yang 	{0x3c92, 0x00},
2655fcf092eSHyungwoo Yang 	{0x3c93, 0x00},
2665fcf092eSHyungwoo Yang 	{0x3c94, 0x40},
2675fcf092eSHyungwoo Yang 	{0x3c95, 0x54},
2685fcf092eSHyungwoo Yang 	{0x3c96, 0x34},
2695fcf092eSHyungwoo Yang 	{0x3c97, 0x04},
2705fcf092eSHyungwoo Yang 	{0x3c98, 0x00},
2715fcf092eSHyungwoo Yang 	{0x3d8c, 0x73},
2725fcf092eSHyungwoo Yang 	{0x3d8d, 0xc0},
2735fcf092eSHyungwoo Yang 	{0x3f00, 0x0b},
2745fcf092eSHyungwoo Yang 	{0x3f03, 0x00},
2755fcf092eSHyungwoo Yang 	{0x4001, 0xe0},
2765fcf092eSHyungwoo Yang 	{0x4008, 0x00},
2775fcf092eSHyungwoo Yang 	{0x4009, 0x0f},
2785fcf092eSHyungwoo Yang 	{0x4011, 0xf0},
2795fcf092eSHyungwoo Yang 	{0x4017, 0x08},
2805fcf092eSHyungwoo Yang 	{0x4050, 0x04},
2815fcf092eSHyungwoo Yang 	{0x4051, 0x0b},
2825fcf092eSHyungwoo Yang 	{0x4052, 0x00},
2835fcf092eSHyungwoo Yang 	{0x4053, 0x80},
2845fcf092eSHyungwoo Yang 	{0x4054, 0x00},
2855fcf092eSHyungwoo Yang 	{0x4055, 0x80},
2865fcf092eSHyungwoo Yang 	{0x4056, 0x00},
2875fcf092eSHyungwoo Yang 	{0x4057, 0x80},
2885fcf092eSHyungwoo Yang 	{0x4058, 0x00},
2895fcf092eSHyungwoo Yang 	{0x4059, 0x80},
2905fcf092eSHyungwoo Yang 	{0x405e, 0x20},
2915fcf092eSHyungwoo Yang 	{0x4500, 0x07},
2925fcf092eSHyungwoo Yang 	{0x4503, 0x00},
2935fcf092eSHyungwoo Yang 	{0x450a, 0x04},
2945fcf092eSHyungwoo Yang 	{0x4809, 0x04},
2955fcf092eSHyungwoo Yang 	{0x480c, 0x12},
2965fcf092eSHyungwoo Yang 	{0x481f, 0x30},
2975fcf092eSHyungwoo Yang 	{0x4833, 0x10},
2985fcf092eSHyungwoo Yang 	{0x4837, 0x0e},
2995fcf092eSHyungwoo Yang 	{0x4902, 0x01},
3005fcf092eSHyungwoo Yang 	{0x4d00, 0x03},
3015fcf092eSHyungwoo Yang 	{0x4d01, 0xc9},
3025fcf092eSHyungwoo Yang 	{0x4d02, 0xbc},
3035fcf092eSHyungwoo Yang 	{0x4d03, 0xd7},
3045fcf092eSHyungwoo Yang 	{0x4d04, 0xf0},
3055fcf092eSHyungwoo Yang 	{0x4d05, 0xa2},
3065fcf092eSHyungwoo Yang 	{0x5000, 0xfd},
3075fcf092eSHyungwoo Yang 	{0x5001, 0x01},
3085fcf092eSHyungwoo Yang 	{0x5040, 0x39},
3095fcf092eSHyungwoo Yang 	{0x5041, 0x10},
3105fcf092eSHyungwoo Yang 	{0x5042, 0x10},
3115fcf092eSHyungwoo Yang 	{0x5043, 0x84},
3125fcf092eSHyungwoo Yang 	{0x5044, 0x62},
3135fcf092eSHyungwoo Yang 	{0x5180, 0x00},
3145fcf092eSHyungwoo Yang 	{0x5181, 0x10},
3155fcf092eSHyungwoo Yang 	{0x5182, 0x02},
3165fcf092eSHyungwoo Yang 	{0x5183, 0x0f},
3175fcf092eSHyungwoo Yang 	{0x5200, 0x1b},
3185fcf092eSHyungwoo Yang 	{0x520b, 0x07},
3195fcf092eSHyungwoo Yang 	{0x520c, 0x0f},
3205fcf092eSHyungwoo Yang 	{0x5300, 0x04},
3215fcf092eSHyungwoo Yang 	{0x5301, 0x0c},
3225fcf092eSHyungwoo Yang 	{0x5302, 0x0c},
3235fcf092eSHyungwoo Yang 	{0x5303, 0x0f},
3245fcf092eSHyungwoo Yang 	{0x5304, 0x00},
3255fcf092eSHyungwoo Yang 	{0x5305, 0x70},
3265fcf092eSHyungwoo Yang 	{0x5306, 0x00},
3275fcf092eSHyungwoo Yang 	{0x5307, 0x80},
3285fcf092eSHyungwoo Yang 	{0x5308, 0x00},
3295fcf092eSHyungwoo Yang 	{0x5309, 0xa5},
3305fcf092eSHyungwoo Yang 	{0x530a, 0x00},
3315fcf092eSHyungwoo Yang 	{0x530b, 0xd3},
3325fcf092eSHyungwoo Yang 	{0x530c, 0x00},
3335fcf092eSHyungwoo Yang 	{0x530d, 0xf0},
3345fcf092eSHyungwoo Yang 	{0x530e, 0x01},
3355fcf092eSHyungwoo Yang 	{0x530f, 0x10},
3365fcf092eSHyungwoo Yang 	{0x5310, 0x01},
3375fcf092eSHyungwoo Yang 	{0x5311, 0x20},
3385fcf092eSHyungwoo Yang 	{0x5312, 0x01},
3395fcf092eSHyungwoo Yang 	{0x5313, 0x20},
3405fcf092eSHyungwoo Yang 	{0x5314, 0x01},
3415fcf092eSHyungwoo Yang 	{0x5315, 0x20},
3425fcf092eSHyungwoo Yang 	{0x5316, 0x08},
3435fcf092eSHyungwoo Yang 	{0x5317, 0x08},
3445fcf092eSHyungwoo Yang 	{0x5318, 0x10},
3455fcf092eSHyungwoo Yang 	{0x5319, 0x88},
3465fcf092eSHyungwoo Yang 	{0x531a, 0x88},
3475fcf092eSHyungwoo Yang 	{0x531b, 0xa9},
3485fcf092eSHyungwoo Yang 	{0x531c, 0xaa},
3495fcf092eSHyungwoo Yang 	{0x531d, 0x0a},
3505fcf092eSHyungwoo Yang 	{0x5405, 0x02},
3515fcf092eSHyungwoo Yang 	{0x5406, 0x67},
3525fcf092eSHyungwoo Yang 	{0x5407, 0x01},
3535fcf092eSHyungwoo Yang 	{0x5408, 0x4a},
3545fcf092eSHyungwoo Yang };
3555fcf092eSHyungwoo Yang 
3565fcf092eSHyungwoo Yang static const struct ov13858_reg mode_2112x1568_regs[] = {
3575fcf092eSHyungwoo Yang 	{0x3013, 0x32},
3585fcf092eSHyungwoo Yang 	{0x301b, 0xf0},
3595fcf092eSHyungwoo Yang 	{0x301f, 0xd0},
3605fcf092eSHyungwoo Yang 	{0x3106, 0x15},
3615fcf092eSHyungwoo Yang 	{0x3107, 0x23},
3625fcf092eSHyungwoo Yang 	{0x350a, 0x00},
3635fcf092eSHyungwoo Yang 	{0x350e, 0x00},
3645fcf092eSHyungwoo Yang 	{0x3510, 0x00},
3655fcf092eSHyungwoo Yang 	{0x3511, 0x02},
3665fcf092eSHyungwoo Yang 	{0x3512, 0x00},
3675fcf092eSHyungwoo Yang 	{0x3600, 0x2b},
3685fcf092eSHyungwoo Yang 	{0x3601, 0x52},
3695fcf092eSHyungwoo Yang 	{0x3602, 0x60},
3705fcf092eSHyungwoo Yang 	{0x3612, 0x05},
3715fcf092eSHyungwoo Yang 	{0x3613, 0xa4},
3725fcf092eSHyungwoo Yang 	{0x3620, 0x80},
3735fcf092eSHyungwoo Yang 	{0x3621, 0x10},
3745fcf092eSHyungwoo Yang 	{0x3622, 0x30},
3755fcf092eSHyungwoo Yang 	{0x3624, 0x1c},
3765fcf092eSHyungwoo Yang 	{0x3640, 0x10},
3775fcf092eSHyungwoo Yang 	{0x3641, 0x70},
378d365bc92SChiranjeevi Rapolu 	{0x3660, 0x04},
3795fcf092eSHyungwoo Yang 	{0x3661, 0x80},
3805fcf092eSHyungwoo Yang 	{0x3662, 0x10},
3815fcf092eSHyungwoo Yang 	{0x3664, 0x73},
3825fcf092eSHyungwoo Yang 	{0x3665, 0xa7},
3835fcf092eSHyungwoo Yang 	{0x366e, 0xff},
3845fcf092eSHyungwoo Yang 	{0x366f, 0xf4},
3855fcf092eSHyungwoo Yang 	{0x3674, 0x00},
3865fcf092eSHyungwoo Yang 	{0x3679, 0x0c},
3875fcf092eSHyungwoo Yang 	{0x367f, 0x01},
3885fcf092eSHyungwoo Yang 	{0x3680, 0x0c},
3895fcf092eSHyungwoo Yang 	{0x3681, 0x50},
3905fcf092eSHyungwoo Yang 	{0x3682, 0x50},
3915fcf092eSHyungwoo Yang 	{0x3683, 0xa9},
3925fcf092eSHyungwoo Yang 	{0x3684, 0xa9},
3935fcf092eSHyungwoo Yang 	{0x3709, 0x5f},
3945fcf092eSHyungwoo Yang 	{0x3714, 0x28},
3955fcf092eSHyungwoo Yang 	{0x371a, 0x3e},
3965fcf092eSHyungwoo Yang 	{0x3737, 0x08},
3975fcf092eSHyungwoo Yang 	{0x3738, 0xcc},
3985fcf092eSHyungwoo Yang 	{0x3739, 0x20},
3995fcf092eSHyungwoo Yang 	{0x373d, 0x26},
4005fcf092eSHyungwoo Yang 	{0x3764, 0x20},
4015fcf092eSHyungwoo Yang 	{0x3765, 0x20},
4025fcf092eSHyungwoo Yang 	{0x37a1, 0x36},
4035fcf092eSHyungwoo Yang 	{0x37a8, 0x3b},
4045fcf092eSHyungwoo Yang 	{0x37ab, 0x31},
4055fcf092eSHyungwoo Yang 	{0x37c2, 0x14},
4065fcf092eSHyungwoo Yang 	{0x37c3, 0xf1},
4075fcf092eSHyungwoo Yang 	{0x37c5, 0x00},
4085fcf092eSHyungwoo Yang 	{0x37d8, 0x03},
4095fcf092eSHyungwoo Yang 	{0x37d9, 0x0c},
4105fcf092eSHyungwoo Yang 	{0x37da, 0xc2},
4115fcf092eSHyungwoo Yang 	{0x37dc, 0x02},
4125fcf092eSHyungwoo Yang 	{0x37e0, 0x00},
4135fcf092eSHyungwoo Yang 	{0x37e1, 0x0a},
4145fcf092eSHyungwoo Yang 	{0x37e2, 0x14},
4155fcf092eSHyungwoo Yang 	{0x37e3, 0x08},
4165fcf092eSHyungwoo Yang 	{0x37e4, 0x38},
4175fcf092eSHyungwoo Yang 	{0x37e5, 0x03},
4185fcf092eSHyungwoo Yang 	{0x37e6, 0x08},
4195fcf092eSHyungwoo Yang 	{0x3800, 0x00},
4205fcf092eSHyungwoo Yang 	{0x3801, 0x00},
4215fcf092eSHyungwoo Yang 	{0x3802, 0x00},
4225fcf092eSHyungwoo Yang 	{0x3803, 0x00},
4235fcf092eSHyungwoo Yang 	{0x3804, 0x10},
4245fcf092eSHyungwoo Yang 	{0x3805, 0x9f},
4255fcf092eSHyungwoo Yang 	{0x3806, 0x0c},
4265fcf092eSHyungwoo Yang 	{0x3807, 0x5f},
4275fcf092eSHyungwoo Yang 	{0x3808, 0x08},
4285fcf092eSHyungwoo Yang 	{0x3809, 0x40},
4295fcf092eSHyungwoo Yang 	{0x380a, 0x06},
4305fcf092eSHyungwoo Yang 	{0x380b, 0x20},
4315fcf092eSHyungwoo Yang 	{0x380c, 0x04},
4325fcf092eSHyungwoo Yang 	{0x380d, 0x62},
4335fcf092eSHyungwoo Yang 	{0x380e, 0x0c},
4345fcf092eSHyungwoo Yang 	{0x380f, 0x8e},
4355fcf092eSHyungwoo Yang 	{0x3811, 0x04},
4365fcf092eSHyungwoo Yang 	{0x3813, 0x05},
4375fcf092eSHyungwoo Yang 	{0x3814, 0x03},
4385fcf092eSHyungwoo Yang 	{0x3815, 0x01},
4395fcf092eSHyungwoo Yang 	{0x3816, 0x03},
4405fcf092eSHyungwoo Yang 	{0x3817, 0x01},
4415fcf092eSHyungwoo Yang 	{0x3820, 0xab},
4425fcf092eSHyungwoo Yang 	{0x3821, 0x00},
4435fcf092eSHyungwoo Yang 	{0x3822, 0xc2},
4445fcf092eSHyungwoo Yang 	{0x3823, 0x18},
4455fcf092eSHyungwoo Yang 	{0x3826, 0x04},
4465fcf092eSHyungwoo Yang 	{0x3827, 0x90},
4475fcf092eSHyungwoo Yang 	{0x3829, 0x07},
4485fcf092eSHyungwoo Yang 	{0x3832, 0x00},
4495fcf092eSHyungwoo Yang 	{0x3c80, 0x00},
4505fcf092eSHyungwoo Yang 	{0x3c87, 0x01},
4515fcf092eSHyungwoo Yang 	{0x3c8c, 0x19},
4525fcf092eSHyungwoo Yang 	{0x3c8d, 0x1c},
4535fcf092eSHyungwoo Yang 	{0x3c90, 0x00},
4545fcf092eSHyungwoo Yang 	{0x3c91, 0x00},
4555fcf092eSHyungwoo Yang 	{0x3c92, 0x00},
4565fcf092eSHyungwoo Yang 	{0x3c93, 0x00},
4575fcf092eSHyungwoo Yang 	{0x3c94, 0x40},
4585fcf092eSHyungwoo Yang 	{0x3c95, 0x54},
4595fcf092eSHyungwoo Yang 	{0x3c96, 0x34},
4605fcf092eSHyungwoo Yang 	{0x3c97, 0x04},
4615fcf092eSHyungwoo Yang 	{0x3c98, 0x00},
4625fcf092eSHyungwoo Yang 	{0x3d8c, 0x73},
4635fcf092eSHyungwoo Yang 	{0x3d8d, 0xc0},
4645fcf092eSHyungwoo Yang 	{0x3f00, 0x0b},
4655fcf092eSHyungwoo Yang 	{0x3f03, 0x00},
4665fcf092eSHyungwoo Yang 	{0x4001, 0xe0},
4675fcf092eSHyungwoo Yang 	{0x4008, 0x00},
4685fcf092eSHyungwoo Yang 	{0x4009, 0x0d},
4695fcf092eSHyungwoo Yang 	{0x4011, 0xf0},
4705fcf092eSHyungwoo Yang 	{0x4017, 0x08},
4715fcf092eSHyungwoo Yang 	{0x4050, 0x04},
4725fcf092eSHyungwoo Yang 	{0x4051, 0x0b},
4735fcf092eSHyungwoo Yang 	{0x4052, 0x00},
4745fcf092eSHyungwoo Yang 	{0x4053, 0x80},
4755fcf092eSHyungwoo Yang 	{0x4054, 0x00},
4765fcf092eSHyungwoo Yang 	{0x4055, 0x80},
4775fcf092eSHyungwoo Yang 	{0x4056, 0x00},
4785fcf092eSHyungwoo Yang 	{0x4057, 0x80},
4795fcf092eSHyungwoo Yang 	{0x4058, 0x00},
4805fcf092eSHyungwoo Yang 	{0x4059, 0x80},
4815fcf092eSHyungwoo Yang 	{0x405e, 0x20},
4825fcf092eSHyungwoo Yang 	{0x4500, 0x07},
4835fcf092eSHyungwoo Yang 	{0x4503, 0x00},
4845fcf092eSHyungwoo Yang 	{0x450a, 0x04},
4855fcf092eSHyungwoo Yang 	{0x4809, 0x04},
4865fcf092eSHyungwoo Yang 	{0x480c, 0x12},
4875fcf092eSHyungwoo Yang 	{0x481f, 0x30},
4885fcf092eSHyungwoo Yang 	{0x4833, 0x10},
4895fcf092eSHyungwoo Yang 	{0x4837, 0x1c},
4905fcf092eSHyungwoo Yang 	{0x4902, 0x01},
4915fcf092eSHyungwoo Yang 	{0x4d00, 0x03},
4925fcf092eSHyungwoo Yang 	{0x4d01, 0xc9},
4935fcf092eSHyungwoo Yang 	{0x4d02, 0xbc},
4945fcf092eSHyungwoo Yang 	{0x4d03, 0xd7},
4955fcf092eSHyungwoo Yang 	{0x4d04, 0xf0},
4965fcf092eSHyungwoo Yang 	{0x4d05, 0xa2},
4975fcf092eSHyungwoo Yang 	{0x5000, 0xfd},
4985fcf092eSHyungwoo Yang 	{0x5001, 0x01},
4995fcf092eSHyungwoo Yang 	{0x5040, 0x39},
5005fcf092eSHyungwoo Yang 	{0x5041, 0x10},
5015fcf092eSHyungwoo Yang 	{0x5042, 0x10},
5025fcf092eSHyungwoo Yang 	{0x5043, 0x84},
5035fcf092eSHyungwoo Yang 	{0x5044, 0x62},
5045fcf092eSHyungwoo Yang 	{0x5180, 0x00},
5055fcf092eSHyungwoo Yang 	{0x5181, 0x10},
5065fcf092eSHyungwoo Yang 	{0x5182, 0x02},
5075fcf092eSHyungwoo Yang 	{0x5183, 0x0f},
5085fcf092eSHyungwoo Yang 	{0x5200, 0x1b},
5095fcf092eSHyungwoo Yang 	{0x520b, 0x07},
5105fcf092eSHyungwoo Yang 	{0x520c, 0x0f},
5115fcf092eSHyungwoo Yang 	{0x5300, 0x04},
5125fcf092eSHyungwoo Yang 	{0x5301, 0x0c},
5135fcf092eSHyungwoo Yang 	{0x5302, 0x0c},
5145fcf092eSHyungwoo Yang 	{0x5303, 0x0f},
5155fcf092eSHyungwoo Yang 	{0x5304, 0x00},
5165fcf092eSHyungwoo Yang 	{0x5305, 0x70},
5175fcf092eSHyungwoo Yang 	{0x5306, 0x00},
5185fcf092eSHyungwoo Yang 	{0x5307, 0x80},
5195fcf092eSHyungwoo Yang 	{0x5308, 0x00},
5205fcf092eSHyungwoo Yang 	{0x5309, 0xa5},
5215fcf092eSHyungwoo Yang 	{0x530a, 0x00},
5225fcf092eSHyungwoo Yang 	{0x530b, 0xd3},
5235fcf092eSHyungwoo Yang 	{0x530c, 0x00},
5245fcf092eSHyungwoo Yang 	{0x530d, 0xf0},
5255fcf092eSHyungwoo Yang 	{0x530e, 0x01},
5265fcf092eSHyungwoo Yang 	{0x530f, 0x10},
5275fcf092eSHyungwoo Yang 	{0x5310, 0x01},
5285fcf092eSHyungwoo Yang 	{0x5311, 0x20},
5295fcf092eSHyungwoo Yang 	{0x5312, 0x01},
5305fcf092eSHyungwoo Yang 	{0x5313, 0x20},
5315fcf092eSHyungwoo Yang 	{0x5314, 0x01},
5325fcf092eSHyungwoo Yang 	{0x5315, 0x20},
5335fcf092eSHyungwoo Yang 	{0x5316, 0x08},
5345fcf092eSHyungwoo Yang 	{0x5317, 0x08},
5355fcf092eSHyungwoo Yang 	{0x5318, 0x10},
5365fcf092eSHyungwoo Yang 	{0x5319, 0x88},
5375fcf092eSHyungwoo Yang 	{0x531a, 0x88},
5385fcf092eSHyungwoo Yang 	{0x531b, 0xa9},
5395fcf092eSHyungwoo Yang 	{0x531c, 0xaa},
5405fcf092eSHyungwoo Yang 	{0x531d, 0x0a},
5415fcf092eSHyungwoo Yang 	{0x5405, 0x02},
5425fcf092eSHyungwoo Yang 	{0x5406, 0x67},
5435fcf092eSHyungwoo Yang 	{0x5407, 0x01},
5445fcf092eSHyungwoo Yang 	{0x5408, 0x4a},
5455fcf092eSHyungwoo Yang };
5465fcf092eSHyungwoo Yang 
5475fcf092eSHyungwoo Yang static const struct ov13858_reg mode_2112x1188_regs[] = {
5485fcf092eSHyungwoo Yang 	{0x3013, 0x32},
5495fcf092eSHyungwoo Yang 	{0x301b, 0xf0},
5505fcf092eSHyungwoo Yang 	{0x301f, 0xd0},
5515fcf092eSHyungwoo Yang 	{0x3106, 0x15},
5525fcf092eSHyungwoo Yang 	{0x3107, 0x23},
5535fcf092eSHyungwoo Yang 	{0x350a, 0x00},
5545fcf092eSHyungwoo Yang 	{0x350e, 0x00},
5555fcf092eSHyungwoo Yang 	{0x3510, 0x00},
5565fcf092eSHyungwoo Yang 	{0x3511, 0x02},
5575fcf092eSHyungwoo Yang 	{0x3512, 0x00},
5585fcf092eSHyungwoo Yang 	{0x3600, 0x2b},
5595fcf092eSHyungwoo Yang 	{0x3601, 0x52},
5605fcf092eSHyungwoo Yang 	{0x3602, 0x60},
5615fcf092eSHyungwoo Yang 	{0x3612, 0x05},
5625fcf092eSHyungwoo Yang 	{0x3613, 0xa4},
5635fcf092eSHyungwoo Yang 	{0x3620, 0x80},
5645fcf092eSHyungwoo Yang 	{0x3621, 0x10},
5655fcf092eSHyungwoo Yang 	{0x3622, 0x30},
5665fcf092eSHyungwoo Yang 	{0x3624, 0x1c},
5675fcf092eSHyungwoo Yang 	{0x3640, 0x10},
5685fcf092eSHyungwoo Yang 	{0x3641, 0x70},
569d365bc92SChiranjeevi Rapolu 	{0x3660, 0x04},
5705fcf092eSHyungwoo Yang 	{0x3661, 0x80},
5715fcf092eSHyungwoo Yang 	{0x3662, 0x10},
5725fcf092eSHyungwoo Yang 	{0x3664, 0x73},
5735fcf092eSHyungwoo Yang 	{0x3665, 0xa7},
5745fcf092eSHyungwoo Yang 	{0x366e, 0xff},
5755fcf092eSHyungwoo Yang 	{0x366f, 0xf4},
5765fcf092eSHyungwoo Yang 	{0x3674, 0x00},
5775fcf092eSHyungwoo Yang 	{0x3679, 0x0c},
5785fcf092eSHyungwoo Yang 	{0x367f, 0x01},
5795fcf092eSHyungwoo Yang 	{0x3680, 0x0c},
5805fcf092eSHyungwoo Yang 	{0x3681, 0x50},
5815fcf092eSHyungwoo Yang 	{0x3682, 0x50},
5825fcf092eSHyungwoo Yang 	{0x3683, 0xa9},
5835fcf092eSHyungwoo Yang 	{0x3684, 0xa9},
5845fcf092eSHyungwoo Yang 	{0x3709, 0x5f},
5855fcf092eSHyungwoo Yang 	{0x3714, 0x28},
5865fcf092eSHyungwoo Yang 	{0x371a, 0x3e},
5875fcf092eSHyungwoo Yang 	{0x3737, 0x08},
5885fcf092eSHyungwoo Yang 	{0x3738, 0xcc},
5895fcf092eSHyungwoo Yang 	{0x3739, 0x20},
5905fcf092eSHyungwoo Yang 	{0x373d, 0x26},
5915fcf092eSHyungwoo Yang 	{0x3764, 0x20},
5925fcf092eSHyungwoo Yang 	{0x3765, 0x20},
5935fcf092eSHyungwoo Yang 	{0x37a1, 0x36},
5945fcf092eSHyungwoo Yang 	{0x37a8, 0x3b},
5955fcf092eSHyungwoo Yang 	{0x37ab, 0x31},
5965fcf092eSHyungwoo Yang 	{0x37c2, 0x14},
5975fcf092eSHyungwoo Yang 	{0x37c3, 0xf1},
5985fcf092eSHyungwoo Yang 	{0x37c5, 0x00},
5995fcf092eSHyungwoo Yang 	{0x37d8, 0x03},
6005fcf092eSHyungwoo Yang 	{0x37d9, 0x0c},
6015fcf092eSHyungwoo Yang 	{0x37da, 0xc2},
6025fcf092eSHyungwoo Yang 	{0x37dc, 0x02},
6035fcf092eSHyungwoo Yang 	{0x37e0, 0x00},
6045fcf092eSHyungwoo Yang 	{0x37e1, 0x0a},
6055fcf092eSHyungwoo Yang 	{0x37e2, 0x14},
6065fcf092eSHyungwoo Yang 	{0x37e3, 0x08},
6075fcf092eSHyungwoo Yang 	{0x37e4, 0x38},
6085fcf092eSHyungwoo Yang 	{0x37e5, 0x03},
6095fcf092eSHyungwoo Yang 	{0x37e6, 0x08},
6105fcf092eSHyungwoo Yang 	{0x3800, 0x00},
6115fcf092eSHyungwoo Yang 	{0x3801, 0x00},
6125fcf092eSHyungwoo Yang 	{0x3802, 0x01},
6135fcf092eSHyungwoo Yang 	{0x3803, 0x84},
6145fcf092eSHyungwoo Yang 	{0x3804, 0x10},
6155fcf092eSHyungwoo Yang 	{0x3805, 0x9f},
6165fcf092eSHyungwoo Yang 	{0x3806, 0x0a},
6175fcf092eSHyungwoo Yang 	{0x3807, 0xd3},
6185fcf092eSHyungwoo Yang 	{0x3808, 0x08},
6195fcf092eSHyungwoo Yang 	{0x3809, 0x40},
6205fcf092eSHyungwoo Yang 	{0x380a, 0x04},
6215fcf092eSHyungwoo Yang 	{0x380b, 0xa4},
6225fcf092eSHyungwoo Yang 	{0x380c, 0x04},
6235fcf092eSHyungwoo Yang 	{0x380d, 0x62},
6245fcf092eSHyungwoo Yang 	{0x380e, 0x0c},
6255fcf092eSHyungwoo Yang 	{0x380f, 0x8e},
6265fcf092eSHyungwoo Yang 	{0x3811, 0x08},
6275fcf092eSHyungwoo Yang 	{0x3813, 0x03},
6285fcf092eSHyungwoo Yang 	{0x3814, 0x03},
6295fcf092eSHyungwoo Yang 	{0x3815, 0x01},
6305fcf092eSHyungwoo Yang 	{0x3816, 0x03},
6315fcf092eSHyungwoo Yang 	{0x3817, 0x01},
6325fcf092eSHyungwoo Yang 	{0x3820, 0xab},
6335fcf092eSHyungwoo Yang 	{0x3821, 0x00},
6345fcf092eSHyungwoo Yang 	{0x3822, 0xc2},
6355fcf092eSHyungwoo Yang 	{0x3823, 0x18},
6365fcf092eSHyungwoo Yang 	{0x3826, 0x04},
6375fcf092eSHyungwoo Yang 	{0x3827, 0x90},
6385fcf092eSHyungwoo Yang 	{0x3829, 0x07},
6395fcf092eSHyungwoo Yang 	{0x3832, 0x00},
6405fcf092eSHyungwoo Yang 	{0x3c80, 0x00},
6415fcf092eSHyungwoo Yang 	{0x3c87, 0x01},
6425fcf092eSHyungwoo Yang 	{0x3c8c, 0x19},
6435fcf092eSHyungwoo Yang 	{0x3c8d, 0x1c},
6445fcf092eSHyungwoo Yang 	{0x3c90, 0x00},
6455fcf092eSHyungwoo Yang 	{0x3c91, 0x00},
6465fcf092eSHyungwoo Yang 	{0x3c92, 0x00},
6475fcf092eSHyungwoo Yang 	{0x3c93, 0x00},
6485fcf092eSHyungwoo Yang 	{0x3c94, 0x40},
6495fcf092eSHyungwoo Yang 	{0x3c95, 0x54},
6505fcf092eSHyungwoo Yang 	{0x3c96, 0x34},
6515fcf092eSHyungwoo Yang 	{0x3c97, 0x04},
6525fcf092eSHyungwoo Yang 	{0x3c98, 0x00},
6535fcf092eSHyungwoo Yang 	{0x3d8c, 0x73},
6545fcf092eSHyungwoo Yang 	{0x3d8d, 0xc0},
6555fcf092eSHyungwoo Yang 	{0x3f00, 0x0b},
6565fcf092eSHyungwoo Yang 	{0x3f03, 0x00},
6575fcf092eSHyungwoo Yang 	{0x4001, 0xe0},
6585fcf092eSHyungwoo Yang 	{0x4008, 0x00},
6595fcf092eSHyungwoo Yang 	{0x4009, 0x0d},
6605fcf092eSHyungwoo Yang 	{0x4011, 0xf0},
6615fcf092eSHyungwoo Yang 	{0x4017, 0x08},
6625fcf092eSHyungwoo Yang 	{0x4050, 0x04},
6635fcf092eSHyungwoo Yang 	{0x4051, 0x0b},
6645fcf092eSHyungwoo Yang 	{0x4052, 0x00},
6655fcf092eSHyungwoo Yang 	{0x4053, 0x80},
6665fcf092eSHyungwoo Yang 	{0x4054, 0x00},
6675fcf092eSHyungwoo Yang 	{0x4055, 0x80},
6685fcf092eSHyungwoo Yang 	{0x4056, 0x00},
6695fcf092eSHyungwoo Yang 	{0x4057, 0x80},
6705fcf092eSHyungwoo Yang 	{0x4058, 0x00},
6715fcf092eSHyungwoo Yang 	{0x4059, 0x80},
6725fcf092eSHyungwoo Yang 	{0x405e, 0x20},
6735fcf092eSHyungwoo Yang 	{0x4500, 0x07},
6745fcf092eSHyungwoo Yang 	{0x4503, 0x00},
6755fcf092eSHyungwoo Yang 	{0x450a, 0x04},
6765fcf092eSHyungwoo Yang 	{0x4809, 0x04},
6775fcf092eSHyungwoo Yang 	{0x480c, 0x12},
6785fcf092eSHyungwoo Yang 	{0x481f, 0x30},
6795fcf092eSHyungwoo Yang 	{0x4833, 0x10},
6805fcf092eSHyungwoo Yang 	{0x4837, 0x1c},
6815fcf092eSHyungwoo Yang 	{0x4902, 0x01},
6825fcf092eSHyungwoo Yang 	{0x4d00, 0x03},
6835fcf092eSHyungwoo Yang 	{0x4d01, 0xc9},
6845fcf092eSHyungwoo Yang 	{0x4d02, 0xbc},
6855fcf092eSHyungwoo Yang 	{0x4d03, 0xd7},
6865fcf092eSHyungwoo Yang 	{0x4d04, 0xf0},
6875fcf092eSHyungwoo Yang 	{0x4d05, 0xa2},
6885fcf092eSHyungwoo Yang 	{0x5000, 0xfd},
6895fcf092eSHyungwoo Yang 	{0x5001, 0x01},
6905fcf092eSHyungwoo Yang 	{0x5040, 0x39},
6915fcf092eSHyungwoo Yang 	{0x5041, 0x10},
6925fcf092eSHyungwoo Yang 	{0x5042, 0x10},
6935fcf092eSHyungwoo Yang 	{0x5043, 0x84},
6945fcf092eSHyungwoo Yang 	{0x5044, 0x62},
6955fcf092eSHyungwoo Yang 	{0x5180, 0x00},
6965fcf092eSHyungwoo Yang 	{0x5181, 0x10},
6975fcf092eSHyungwoo Yang 	{0x5182, 0x02},
6985fcf092eSHyungwoo Yang 	{0x5183, 0x0f},
6995fcf092eSHyungwoo Yang 	{0x5200, 0x1b},
7005fcf092eSHyungwoo Yang 	{0x520b, 0x07},
7015fcf092eSHyungwoo Yang 	{0x520c, 0x0f},
7025fcf092eSHyungwoo Yang 	{0x5300, 0x04},
7035fcf092eSHyungwoo Yang 	{0x5301, 0x0c},
7045fcf092eSHyungwoo Yang 	{0x5302, 0x0c},
7055fcf092eSHyungwoo Yang 	{0x5303, 0x0f},
7065fcf092eSHyungwoo Yang 	{0x5304, 0x00},
7075fcf092eSHyungwoo Yang 	{0x5305, 0x70},
7085fcf092eSHyungwoo Yang 	{0x5306, 0x00},
7095fcf092eSHyungwoo Yang 	{0x5307, 0x80},
7105fcf092eSHyungwoo Yang 	{0x5308, 0x00},
7115fcf092eSHyungwoo Yang 	{0x5309, 0xa5},
7125fcf092eSHyungwoo Yang 	{0x530a, 0x00},
7135fcf092eSHyungwoo Yang 	{0x530b, 0xd3},
7145fcf092eSHyungwoo Yang 	{0x530c, 0x00},
7155fcf092eSHyungwoo Yang 	{0x530d, 0xf0},
7165fcf092eSHyungwoo Yang 	{0x530e, 0x01},
7175fcf092eSHyungwoo Yang 	{0x530f, 0x10},
7185fcf092eSHyungwoo Yang 	{0x5310, 0x01},
7195fcf092eSHyungwoo Yang 	{0x5311, 0x20},
7205fcf092eSHyungwoo Yang 	{0x5312, 0x01},
7215fcf092eSHyungwoo Yang 	{0x5313, 0x20},
7225fcf092eSHyungwoo Yang 	{0x5314, 0x01},
7235fcf092eSHyungwoo Yang 	{0x5315, 0x20},
7245fcf092eSHyungwoo Yang 	{0x5316, 0x08},
7255fcf092eSHyungwoo Yang 	{0x5317, 0x08},
7265fcf092eSHyungwoo Yang 	{0x5318, 0x10},
7275fcf092eSHyungwoo Yang 	{0x5319, 0x88},
7285fcf092eSHyungwoo Yang 	{0x531a, 0x88},
7295fcf092eSHyungwoo Yang 	{0x531b, 0xa9},
7305fcf092eSHyungwoo Yang 	{0x531c, 0xaa},
7315fcf092eSHyungwoo Yang 	{0x531d, 0x0a},
7325fcf092eSHyungwoo Yang 	{0x5405, 0x02},
7335fcf092eSHyungwoo Yang 	{0x5406, 0x67},
7345fcf092eSHyungwoo Yang 	{0x5407, 0x01},
7355fcf092eSHyungwoo Yang 	{0x5408, 0x4a},
7365fcf092eSHyungwoo Yang };
7375fcf092eSHyungwoo Yang 
7385fcf092eSHyungwoo Yang static const struct ov13858_reg mode_1056x784_regs[] = {
7395fcf092eSHyungwoo Yang 	{0x3013, 0x32},
7405fcf092eSHyungwoo Yang 	{0x301b, 0xf0},
7415fcf092eSHyungwoo Yang 	{0x301f, 0xd0},
7425fcf092eSHyungwoo Yang 	{0x3106, 0x15},
7435fcf092eSHyungwoo Yang 	{0x3107, 0x23},
7445fcf092eSHyungwoo Yang 	{0x350a, 0x00},
7455fcf092eSHyungwoo Yang 	{0x350e, 0x00},
7465fcf092eSHyungwoo Yang 	{0x3510, 0x00},
7475fcf092eSHyungwoo Yang 	{0x3511, 0x02},
7485fcf092eSHyungwoo Yang 	{0x3512, 0x00},
7495fcf092eSHyungwoo Yang 	{0x3600, 0x2b},
7505fcf092eSHyungwoo Yang 	{0x3601, 0x52},
7515fcf092eSHyungwoo Yang 	{0x3602, 0x60},
7525fcf092eSHyungwoo Yang 	{0x3612, 0x05},
7535fcf092eSHyungwoo Yang 	{0x3613, 0xa4},
7545fcf092eSHyungwoo Yang 	{0x3620, 0x80},
7555fcf092eSHyungwoo Yang 	{0x3621, 0x10},
7565fcf092eSHyungwoo Yang 	{0x3622, 0x30},
7575fcf092eSHyungwoo Yang 	{0x3624, 0x1c},
7585fcf092eSHyungwoo Yang 	{0x3640, 0x10},
7595fcf092eSHyungwoo Yang 	{0x3641, 0x70},
760d365bc92SChiranjeevi Rapolu 	{0x3660, 0x04},
7615fcf092eSHyungwoo Yang 	{0x3661, 0x80},
7625fcf092eSHyungwoo Yang 	{0x3662, 0x08},
7635fcf092eSHyungwoo Yang 	{0x3664, 0x73},
7645fcf092eSHyungwoo Yang 	{0x3665, 0xa7},
7655fcf092eSHyungwoo Yang 	{0x366e, 0xff},
7665fcf092eSHyungwoo Yang 	{0x366f, 0xf4},
7675fcf092eSHyungwoo Yang 	{0x3674, 0x00},
7685fcf092eSHyungwoo Yang 	{0x3679, 0x0c},
7695fcf092eSHyungwoo Yang 	{0x367f, 0x01},
7705fcf092eSHyungwoo Yang 	{0x3680, 0x0c},
7715fcf092eSHyungwoo Yang 	{0x3681, 0x50},
7725fcf092eSHyungwoo Yang 	{0x3682, 0x50},
7735fcf092eSHyungwoo Yang 	{0x3683, 0xa9},
7745fcf092eSHyungwoo Yang 	{0x3684, 0xa9},
7755fcf092eSHyungwoo Yang 	{0x3709, 0x5f},
7765fcf092eSHyungwoo Yang 	{0x3714, 0x30},
7775fcf092eSHyungwoo Yang 	{0x371a, 0x3e},
7785fcf092eSHyungwoo Yang 	{0x3737, 0x08},
7795fcf092eSHyungwoo Yang 	{0x3738, 0xcc},
7805fcf092eSHyungwoo Yang 	{0x3739, 0x20},
7815fcf092eSHyungwoo Yang 	{0x373d, 0x26},
7825fcf092eSHyungwoo Yang 	{0x3764, 0x20},
7835fcf092eSHyungwoo Yang 	{0x3765, 0x20},
7845fcf092eSHyungwoo Yang 	{0x37a1, 0x36},
7855fcf092eSHyungwoo Yang 	{0x37a8, 0x3b},
7865fcf092eSHyungwoo Yang 	{0x37ab, 0x31},
7875fcf092eSHyungwoo Yang 	{0x37c2, 0x2c},
7885fcf092eSHyungwoo Yang 	{0x37c3, 0xf1},
7895fcf092eSHyungwoo Yang 	{0x37c5, 0x00},
7905fcf092eSHyungwoo Yang 	{0x37d8, 0x03},
7915fcf092eSHyungwoo Yang 	{0x37d9, 0x06},
7925fcf092eSHyungwoo Yang 	{0x37da, 0xc2},
7935fcf092eSHyungwoo Yang 	{0x37dc, 0x02},
7945fcf092eSHyungwoo Yang 	{0x37e0, 0x00},
7955fcf092eSHyungwoo Yang 	{0x37e1, 0x0a},
7965fcf092eSHyungwoo Yang 	{0x37e2, 0x14},
7975fcf092eSHyungwoo Yang 	{0x37e3, 0x08},
7985fcf092eSHyungwoo Yang 	{0x37e4, 0x36},
7995fcf092eSHyungwoo Yang 	{0x37e5, 0x03},
8005fcf092eSHyungwoo Yang 	{0x37e6, 0x08},
8015fcf092eSHyungwoo Yang 	{0x3800, 0x00},
8025fcf092eSHyungwoo Yang 	{0x3801, 0x00},
8035fcf092eSHyungwoo Yang 	{0x3802, 0x00},
8045fcf092eSHyungwoo Yang 	{0x3803, 0x00},
8055fcf092eSHyungwoo Yang 	{0x3804, 0x10},
8065fcf092eSHyungwoo Yang 	{0x3805, 0x9f},
8075fcf092eSHyungwoo Yang 	{0x3806, 0x0c},
8085fcf092eSHyungwoo Yang 	{0x3807, 0x5f},
8095fcf092eSHyungwoo Yang 	{0x3808, 0x04},
8105fcf092eSHyungwoo Yang 	{0x3809, 0x20},
8115fcf092eSHyungwoo Yang 	{0x380a, 0x03},
8125fcf092eSHyungwoo Yang 	{0x380b, 0x10},
8135fcf092eSHyungwoo Yang 	{0x380c, 0x04},
8145fcf092eSHyungwoo Yang 	{0x380d, 0x62},
8155fcf092eSHyungwoo Yang 	{0x380e, 0x0c},
8165fcf092eSHyungwoo Yang 	{0x380f, 0x8e},
8175fcf092eSHyungwoo Yang 	{0x3811, 0x04},
8185fcf092eSHyungwoo Yang 	{0x3813, 0x05},
8195fcf092eSHyungwoo Yang 	{0x3814, 0x07},
8205fcf092eSHyungwoo Yang 	{0x3815, 0x01},
8215fcf092eSHyungwoo Yang 	{0x3816, 0x07},
8225fcf092eSHyungwoo Yang 	{0x3817, 0x01},
8235fcf092eSHyungwoo Yang 	{0x3820, 0xac},
8245fcf092eSHyungwoo Yang 	{0x3821, 0x00},
8255fcf092eSHyungwoo Yang 	{0x3822, 0xc2},
8265fcf092eSHyungwoo Yang 	{0x3823, 0x18},
8275fcf092eSHyungwoo Yang 	{0x3826, 0x04},
8285fcf092eSHyungwoo Yang 	{0x3827, 0x48},
8295fcf092eSHyungwoo Yang 	{0x3829, 0x03},
8305fcf092eSHyungwoo Yang 	{0x3832, 0x00},
8315fcf092eSHyungwoo Yang 	{0x3c80, 0x00},
8325fcf092eSHyungwoo Yang 	{0x3c87, 0x01},
8335fcf092eSHyungwoo Yang 	{0x3c8c, 0x19},
8345fcf092eSHyungwoo Yang 	{0x3c8d, 0x1c},
8355fcf092eSHyungwoo Yang 	{0x3c90, 0x00},
8365fcf092eSHyungwoo Yang 	{0x3c91, 0x00},
8375fcf092eSHyungwoo Yang 	{0x3c92, 0x00},
8385fcf092eSHyungwoo Yang 	{0x3c93, 0x00},
8395fcf092eSHyungwoo Yang 	{0x3c94, 0x40},
8405fcf092eSHyungwoo Yang 	{0x3c95, 0x54},
8415fcf092eSHyungwoo Yang 	{0x3c96, 0x34},
8425fcf092eSHyungwoo Yang 	{0x3c97, 0x04},
8435fcf092eSHyungwoo Yang 	{0x3c98, 0x00},
8445fcf092eSHyungwoo Yang 	{0x3d8c, 0x73},
8455fcf092eSHyungwoo Yang 	{0x3d8d, 0xc0},
8465fcf092eSHyungwoo Yang 	{0x3f00, 0x0b},
8475fcf092eSHyungwoo Yang 	{0x3f03, 0x00},
8485fcf092eSHyungwoo Yang 	{0x4001, 0xe0},
8495fcf092eSHyungwoo Yang 	{0x4008, 0x00},
8505fcf092eSHyungwoo Yang 	{0x4009, 0x05},
8515fcf092eSHyungwoo Yang 	{0x4011, 0xf0},
8525fcf092eSHyungwoo Yang 	{0x4017, 0x08},
8535fcf092eSHyungwoo Yang 	{0x4050, 0x02},
8545fcf092eSHyungwoo Yang 	{0x4051, 0x05},
8555fcf092eSHyungwoo Yang 	{0x4052, 0x00},
8565fcf092eSHyungwoo Yang 	{0x4053, 0x80},
8575fcf092eSHyungwoo Yang 	{0x4054, 0x00},
8585fcf092eSHyungwoo Yang 	{0x4055, 0x80},
8595fcf092eSHyungwoo Yang 	{0x4056, 0x00},
8605fcf092eSHyungwoo Yang 	{0x4057, 0x80},
8615fcf092eSHyungwoo Yang 	{0x4058, 0x00},
8625fcf092eSHyungwoo Yang 	{0x4059, 0x80},
8635fcf092eSHyungwoo Yang 	{0x405e, 0x20},
8645fcf092eSHyungwoo Yang 	{0x4500, 0x07},
8655fcf092eSHyungwoo Yang 	{0x4503, 0x00},
8665fcf092eSHyungwoo Yang 	{0x450a, 0x04},
8675fcf092eSHyungwoo Yang 	{0x4809, 0x04},
8685fcf092eSHyungwoo Yang 	{0x480c, 0x12},
8695fcf092eSHyungwoo Yang 	{0x481f, 0x30},
8705fcf092eSHyungwoo Yang 	{0x4833, 0x10},
8715fcf092eSHyungwoo Yang 	{0x4837, 0x1e},
8725fcf092eSHyungwoo Yang 	{0x4902, 0x02},
8735fcf092eSHyungwoo Yang 	{0x4d00, 0x03},
8745fcf092eSHyungwoo Yang 	{0x4d01, 0xc9},
8755fcf092eSHyungwoo Yang 	{0x4d02, 0xbc},
8765fcf092eSHyungwoo Yang 	{0x4d03, 0xd7},
8775fcf092eSHyungwoo Yang 	{0x4d04, 0xf0},
8785fcf092eSHyungwoo Yang 	{0x4d05, 0xa2},
8795fcf092eSHyungwoo Yang 	{0x5000, 0xfd},
8805fcf092eSHyungwoo Yang 	{0x5001, 0x01},
8815fcf092eSHyungwoo Yang 	{0x5040, 0x39},
8825fcf092eSHyungwoo Yang 	{0x5041, 0x10},
8835fcf092eSHyungwoo Yang 	{0x5042, 0x10},
8845fcf092eSHyungwoo Yang 	{0x5043, 0x84},
8855fcf092eSHyungwoo Yang 	{0x5044, 0x62},
8865fcf092eSHyungwoo Yang 	{0x5180, 0x00},
8875fcf092eSHyungwoo Yang 	{0x5181, 0x10},
8885fcf092eSHyungwoo Yang 	{0x5182, 0x02},
8895fcf092eSHyungwoo Yang 	{0x5183, 0x0f},
8905fcf092eSHyungwoo Yang 	{0x5200, 0x1b},
8915fcf092eSHyungwoo Yang 	{0x520b, 0x07},
8925fcf092eSHyungwoo Yang 	{0x520c, 0x0f},
8935fcf092eSHyungwoo Yang 	{0x5300, 0x04},
8945fcf092eSHyungwoo Yang 	{0x5301, 0x0c},
8955fcf092eSHyungwoo Yang 	{0x5302, 0x0c},
8965fcf092eSHyungwoo Yang 	{0x5303, 0x0f},
8975fcf092eSHyungwoo Yang 	{0x5304, 0x00},
8985fcf092eSHyungwoo Yang 	{0x5305, 0x70},
8995fcf092eSHyungwoo Yang 	{0x5306, 0x00},
9005fcf092eSHyungwoo Yang 	{0x5307, 0x80},
9015fcf092eSHyungwoo Yang 	{0x5308, 0x00},
9025fcf092eSHyungwoo Yang 	{0x5309, 0xa5},
9035fcf092eSHyungwoo Yang 	{0x530a, 0x00},
9045fcf092eSHyungwoo Yang 	{0x530b, 0xd3},
9055fcf092eSHyungwoo Yang 	{0x530c, 0x00},
9065fcf092eSHyungwoo Yang 	{0x530d, 0xf0},
9075fcf092eSHyungwoo Yang 	{0x530e, 0x01},
9085fcf092eSHyungwoo Yang 	{0x530f, 0x10},
9095fcf092eSHyungwoo Yang 	{0x5310, 0x01},
9105fcf092eSHyungwoo Yang 	{0x5311, 0x20},
9115fcf092eSHyungwoo Yang 	{0x5312, 0x01},
9125fcf092eSHyungwoo Yang 	{0x5313, 0x20},
9135fcf092eSHyungwoo Yang 	{0x5314, 0x01},
9145fcf092eSHyungwoo Yang 	{0x5315, 0x20},
9155fcf092eSHyungwoo Yang 	{0x5316, 0x08},
9165fcf092eSHyungwoo Yang 	{0x5317, 0x08},
9175fcf092eSHyungwoo Yang 	{0x5318, 0x10},
9185fcf092eSHyungwoo Yang 	{0x5319, 0x88},
9195fcf092eSHyungwoo Yang 	{0x531a, 0x88},
9205fcf092eSHyungwoo Yang 	{0x531b, 0xa9},
9215fcf092eSHyungwoo Yang 	{0x531c, 0xaa},
9225fcf092eSHyungwoo Yang 	{0x531d, 0x0a},
9235fcf092eSHyungwoo Yang 	{0x5405, 0x02},
9245fcf092eSHyungwoo Yang 	{0x5406, 0x67},
9255fcf092eSHyungwoo Yang 	{0x5407, 0x01},
9265fcf092eSHyungwoo Yang 	{0x5408, 0x4a},
9275fcf092eSHyungwoo Yang };
9285fcf092eSHyungwoo Yang 
9295fcf092eSHyungwoo Yang static const char * const ov13858_test_pattern_menu[] = {
9305fcf092eSHyungwoo Yang 	"Disabled",
9315fcf092eSHyungwoo Yang 	"Vertical Color Bar Type 1",
9325fcf092eSHyungwoo Yang 	"Vertical Color Bar Type 2",
9335fcf092eSHyungwoo Yang 	"Vertical Color Bar Type 3",
9345fcf092eSHyungwoo Yang 	"Vertical Color Bar Type 4"
9355fcf092eSHyungwoo Yang };
9365fcf092eSHyungwoo Yang 
9375fcf092eSHyungwoo Yang /* Configurations for supported link frequencies */
9385fcf092eSHyungwoo Yang #define OV13858_NUM_OF_LINK_FREQS	2
93989d8b615SChiranjeevi Rapolu #define OV13858_LINK_FREQ_540MHZ	540000000ULL
94089d8b615SChiranjeevi Rapolu #define OV13858_LINK_FREQ_270MHZ	270000000ULL
9415fcf092eSHyungwoo Yang #define OV13858_LINK_FREQ_INDEX_0	0
9425fcf092eSHyungwoo Yang #define OV13858_LINK_FREQ_INDEX_1	1
9435fcf092eSHyungwoo Yang 
9446f2a0594SChiranjeevi Rapolu /*
9456f2a0594SChiranjeevi Rapolu  * pixel_rate = link_freq * data-rate * nr_of_lanes / bits_per_sample
9466f2a0594SChiranjeevi Rapolu  * data rate => double data rate; number of lanes => 4; bits per pixel => 10
9476f2a0594SChiranjeevi Rapolu  */
948880d45f8SSakari Ailus static u64 link_freq_to_pixel_rate(u64 f)
949880d45f8SSakari Ailus {
950880d45f8SSakari Ailus 	f *= 2 * 4;
951880d45f8SSakari Ailus 	do_div(f, 10);
952880d45f8SSakari Ailus 
953880d45f8SSakari Ailus 	return f;
954880d45f8SSakari Ailus }
9556f2a0594SChiranjeevi Rapolu 
9565fcf092eSHyungwoo Yang /* Menu items for LINK_FREQ V4L2 control */
9573bd30b24SMauro Carvalho Chehab static const s64 link_freq_menu_items[OV13858_NUM_OF_LINK_FREQS] = {
95889d8b615SChiranjeevi Rapolu 	OV13858_LINK_FREQ_540MHZ,
95989d8b615SChiranjeevi Rapolu 	OV13858_LINK_FREQ_270MHZ
9605fcf092eSHyungwoo Yang };
9615fcf092eSHyungwoo Yang 
9625fcf092eSHyungwoo Yang /* Link frequency configs */
9635fcf092eSHyungwoo Yang static const struct ov13858_link_freq_config
9645fcf092eSHyungwoo Yang 			link_freq_configs[OV13858_NUM_OF_LINK_FREQS] = {
9655fcf092eSHyungwoo Yang 	{
96689d8b615SChiranjeevi Rapolu 		.pixels_per_line = OV13858_PPL_540MHZ,
9675fcf092eSHyungwoo Yang 		.reg_list = {
9685fcf092eSHyungwoo Yang 			.num_of_regs = ARRAY_SIZE(mipi_data_rate_1080mbps),
9695fcf092eSHyungwoo Yang 			.regs = mipi_data_rate_1080mbps,
9705fcf092eSHyungwoo Yang 		}
9715fcf092eSHyungwoo Yang 	},
9725fcf092eSHyungwoo Yang 	{
97389d8b615SChiranjeevi Rapolu 		.pixels_per_line = OV13858_PPL_270MHZ,
9745fcf092eSHyungwoo Yang 		.reg_list = {
9755fcf092eSHyungwoo Yang 			.num_of_regs = ARRAY_SIZE(mipi_data_rate_540mbps),
9765fcf092eSHyungwoo Yang 			.regs = mipi_data_rate_540mbps,
9775fcf092eSHyungwoo Yang 		}
9785fcf092eSHyungwoo Yang 	}
9795fcf092eSHyungwoo Yang };
9805fcf092eSHyungwoo Yang 
9815fcf092eSHyungwoo Yang /* Mode configs */
9825fcf092eSHyungwoo Yang static const struct ov13858_mode supported_modes[] = {
9835fcf092eSHyungwoo Yang 	{
9845fcf092eSHyungwoo Yang 		.width = 4224,
9855fcf092eSHyungwoo Yang 		.height = 3136,
98617fcd5f5SChiranjeevi Rapolu 		.vts_def = OV13858_VTS_30FPS,
98717fcd5f5SChiranjeevi Rapolu 		.vts_min = OV13858_VTS_30FPS,
9885fcf092eSHyungwoo Yang 		.reg_list = {
9895fcf092eSHyungwoo Yang 			.num_of_regs = ARRAY_SIZE(mode_4224x3136_regs),
9905fcf092eSHyungwoo Yang 			.regs = mode_4224x3136_regs,
9915fcf092eSHyungwoo Yang 		},
9925fcf092eSHyungwoo Yang 		.link_freq_index = OV13858_LINK_FREQ_INDEX_0,
9935fcf092eSHyungwoo Yang 	},
9945fcf092eSHyungwoo Yang 	{
9955fcf092eSHyungwoo Yang 		.width = 2112,
9965fcf092eSHyungwoo Yang 		.height = 1568,
99717fcd5f5SChiranjeevi Rapolu 		.vts_def = OV13858_VTS_30FPS,
99817fcd5f5SChiranjeevi Rapolu 		.vts_min = 1608,
9995fcf092eSHyungwoo Yang 		.reg_list = {
10005fcf092eSHyungwoo Yang 			.num_of_regs = ARRAY_SIZE(mode_2112x1568_regs),
10015fcf092eSHyungwoo Yang 			.regs = mode_2112x1568_regs,
10025fcf092eSHyungwoo Yang 		},
10035fcf092eSHyungwoo Yang 		.link_freq_index = OV13858_LINK_FREQ_INDEX_1,
10045fcf092eSHyungwoo Yang 	},
10055fcf092eSHyungwoo Yang 	{
10065fcf092eSHyungwoo Yang 		.width = 2112,
10075fcf092eSHyungwoo Yang 		.height = 1188,
100817fcd5f5SChiranjeevi Rapolu 		.vts_def = OV13858_VTS_30FPS,
100917fcd5f5SChiranjeevi Rapolu 		.vts_min = 1608,
10105fcf092eSHyungwoo Yang 		.reg_list = {
10115fcf092eSHyungwoo Yang 			.num_of_regs = ARRAY_SIZE(mode_2112x1188_regs),
10125fcf092eSHyungwoo Yang 			.regs = mode_2112x1188_regs,
10135fcf092eSHyungwoo Yang 		},
10145fcf092eSHyungwoo Yang 		.link_freq_index = OV13858_LINK_FREQ_INDEX_1,
10155fcf092eSHyungwoo Yang 	},
10165fcf092eSHyungwoo Yang 	{
10175fcf092eSHyungwoo Yang 		.width = 1056,
10185fcf092eSHyungwoo Yang 		.height = 784,
101917fcd5f5SChiranjeevi Rapolu 		.vts_def = OV13858_VTS_30FPS,
102017fcd5f5SChiranjeevi Rapolu 		.vts_min = 804,
10215fcf092eSHyungwoo Yang 		.reg_list = {
10225fcf092eSHyungwoo Yang 			.num_of_regs = ARRAY_SIZE(mode_1056x784_regs),
10235fcf092eSHyungwoo Yang 			.regs = mode_1056x784_regs,
10245fcf092eSHyungwoo Yang 		},
10255fcf092eSHyungwoo Yang 		.link_freq_index = OV13858_LINK_FREQ_INDEX_1,
10265fcf092eSHyungwoo Yang 	}
10275fcf092eSHyungwoo Yang };
10285fcf092eSHyungwoo Yang 
10295fcf092eSHyungwoo Yang struct ov13858 {
10305fcf092eSHyungwoo Yang 	struct v4l2_subdev sd;
10315fcf092eSHyungwoo Yang 	struct media_pad pad;
10325fcf092eSHyungwoo Yang 
10335fcf092eSHyungwoo Yang 	struct v4l2_ctrl_handler ctrl_handler;
10345fcf092eSHyungwoo Yang 	/* V4L2 Controls */
10355fcf092eSHyungwoo Yang 	struct v4l2_ctrl *link_freq;
10365fcf092eSHyungwoo Yang 	struct v4l2_ctrl *pixel_rate;
10375fcf092eSHyungwoo Yang 	struct v4l2_ctrl *vblank;
10385fcf092eSHyungwoo Yang 	struct v4l2_ctrl *hblank;
10395fcf092eSHyungwoo Yang 	struct v4l2_ctrl *exposure;
10405fcf092eSHyungwoo Yang 
10415fcf092eSHyungwoo Yang 	/* Current mode */
10425fcf092eSHyungwoo Yang 	const struct ov13858_mode *cur_mode;
10435fcf092eSHyungwoo Yang 
10445fcf092eSHyungwoo Yang 	/* Mutex for serialized access */
10455fcf092eSHyungwoo Yang 	struct mutex mutex;
10465fcf092eSHyungwoo Yang 
10475fcf092eSHyungwoo Yang 	/* Streaming on/off */
10485fcf092eSHyungwoo Yang 	bool streaming;
10495fcf092eSHyungwoo Yang };
10505fcf092eSHyungwoo Yang 
10515fcf092eSHyungwoo Yang #define to_ov13858(_sd)	container_of(_sd, struct ov13858, sd)
10525fcf092eSHyungwoo Yang 
10535fcf092eSHyungwoo Yang /* Read registers up to 4 at a time */
1054a7bc5773SMauro Carvalho Chehab static int ov13858_read_reg(struct ov13858 *ov13858, u16 reg, u32 len,
1055a7bc5773SMauro Carvalho Chehab 			    u32 *val)
10565fcf092eSHyungwoo Yang {
10575fcf092eSHyungwoo Yang 	struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
10585fcf092eSHyungwoo Yang 	struct i2c_msg msgs[2];
10595fcf092eSHyungwoo Yang 	u8 *data_be_p;
10605fcf092eSHyungwoo Yang 	int ret;
1061a7bc5773SMauro Carvalho Chehab 	__be32 data_be = 0;
1062a7bc5773SMauro Carvalho Chehab 	__be16 reg_addr_be = cpu_to_be16(reg);
10635fcf092eSHyungwoo Yang 
10645fcf092eSHyungwoo Yang 	if (len > 4)
10655fcf092eSHyungwoo Yang 		return -EINVAL;
10665fcf092eSHyungwoo Yang 
10675fcf092eSHyungwoo Yang 	data_be_p = (u8 *)&data_be;
10685fcf092eSHyungwoo Yang 	/* Write register address */
10695fcf092eSHyungwoo Yang 	msgs[0].addr = client->addr;
10705fcf092eSHyungwoo Yang 	msgs[0].flags = 0;
10715fcf092eSHyungwoo Yang 	msgs[0].len = 2;
10725fcf092eSHyungwoo Yang 	msgs[0].buf = (u8 *)&reg_addr_be;
10735fcf092eSHyungwoo Yang 
10745fcf092eSHyungwoo Yang 	/* Read data from register */
10755fcf092eSHyungwoo Yang 	msgs[1].addr = client->addr;
10765fcf092eSHyungwoo Yang 	msgs[1].flags = I2C_M_RD;
10775fcf092eSHyungwoo Yang 	msgs[1].len = len;
10785fcf092eSHyungwoo Yang 	msgs[1].buf = &data_be_p[4 - len];
10795fcf092eSHyungwoo Yang 
10805fcf092eSHyungwoo Yang 	ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
10815fcf092eSHyungwoo Yang 	if (ret != ARRAY_SIZE(msgs))
10825fcf092eSHyungwoo Yang 		return -EIO;
10835fcf092eSHyungwoo Yang 
10845fcf092eSHyungwoo Yang 	*val = be32_to_cpu(data_be);
10855fcf092eSHyungwoo Yang 
10865fcf092eSHyungwoo Yang 	return 0;
10875fcf092eSHyungwoo Yang }
10885fcf092eSHyungwoo Yang 
10895fcf092eSHyungwoo Yang /* Write registers up to 4 at a time */
1090a7bc5773SMauro Carvalho Chehab static int ov13858_write_reg(struct ov13858 *ov13858, u16 reg, u32 len,
1091a7bc5773SMauro Carvalho Chehab 			     u32 __val)
10925fcf092eSHyungwoo Yang {
10935fcf092eSHyungwoo Yang 	struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
10945fcf092eSHyungwoo Yang 	int buf_i, val_i;
10955fcf092eSHyungwoo Yang 	u8 buf[6], *val_p;
1096a7bc5773SMauro Carvalho Chehab 	__be32 val;
10975fcf092eSHyungwoo Yang 
10985fcf092eSHyungwoo Yang 	if (len > 4)
10995fcf092eSHyungwoo Yang 		return -EINVAL;
11005fcf092eSHyungwoo Yang 
11015fcf092eSHyungwoo Yang 	buf[0] = reg >> 8;
11025fcf092eSHyungwoo Yang 	buf[1] = reg & 0xff;
11035fcf092eSHyungwoo Yang 
1104a7bc5773SMauro Carvalho Chehab 	val = cpu_to_be32(__val);
11055fcf092eSHyungwoo Yang 	val_p = (u8 *)&val;
11065fcf092eSHyungwoo Yang 	buf_i = 2;
11075fcf092eSHyungwoo Yang 	val_i = 4 - len;
11085fcf092eSHyungwoo Yang 
11095fcf092eSHyungwoo Yang 	while (val_i < 4)
11105fcf092eSHyungwoo Yang 		buf[buf_i++] = val_p[val_i++];
11115fcf092eSHyungwoo Yang 
11125fcf092eSHyungwoo Yang 	if (i2c_master_send(client, buf, len + 2) != len + 2)
11135fcf092eSHyungwoo Yang 		return -EIO;
11145fcf092eSHyungwoo Yang 
11155fcf092eSHyungwoo Yang 	return 0;
11165fcf092eSHyungwoo Yang }
11175fcf092eSHyungwoo Yang 
11185fcf092eSHyungwoo Yang /* Write a list of registers */
11195fcf092eSHyungwoo Yang static int ov13858_write_regs(struct ov13858 *ov13858,
11205fcf092eSHyungwoo Yang 			      const struct ov13858_reg *regs, u32 len)
11215fcf092eSHyungwoo Yang {
11225fcf092eSHyungwoo Yang 	struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
11235fcf092eSHyungwoo Yang 	int ret;
11245fcf092eSHyungwoo Yang 	u32 i;
11255fcf092eSHyungwoo Yang 
11265fcf092eSHyungwoo Yang 	for (i = 0; i < len; i++) {
11275fcf092eSHyungwoo Yang 		ret = ov13858_write_reg(ov13858, regs[i].address, 1,
11285fcf092eSHyungwoo Yang 					regs[i].val);
11295fcf092eSHyungwoo Yang 		if (ret) {
11305fcf092eSHyungwoo Yang 			dev_err_ratelimited(
11315fcf092eSHyungwoo Yang 				&client->dev,
11325fcf092eSHyungwoo Yang 				"Failed to write reg 0x%4.4x. error = %d\n",
11335fcf092eSHyungwoo Yang 				regs[i].address, ret);
11345fcf092eSHyungwoo Yang 
11355fcf092eSHyungwoo Yang 			return ret;
11365fcf092eSHyungwoo Yang 		}
11375fcf092eSHyungwoo Yang 	}
11385fcf092eSHyungwoo Yang 
11395fcf092eSHyungwoo Yang 	return 0;
11405fcf092eSHyungwoo Yang }
11415fcf092eSHyungwoo Yang 
11425fcf092eSHyungwoo Yang static int ov13858_write_reg_list(struct ov13858 *ov13858,
11435fcf092eSHyungwoo Yang 				  const struct ov13858_reg_list *r_list)
11445fcf092eSHyungwoo Yang {
11455fcf092eSHyungwoo Yang 	return ov13858_write_regs(ov13858, r_list->regs, r_list->num_of_regs);
11465fcf092eSHyungwoo Yang }
11475fcf092eSHyungwoo Yang 
11485fcf092eSHyungwoo Yang /* Open sub-device */
11495fcf092eSHyungwoo Yang static int ov13858_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
11505fcf092eSHyungwoo Yang {
11515fcf092eSHyungwoo Yang 	struct ov13858 *ov13858 = to_ov13858(sd);
11525fcf092eSHyungwoo Yang 	struct v4l2_mbus_framefmt *try_fmt = v4l2_subdev_get_try_format(sd,
11535fcf092eSHyungwoo Yang 									fh->pad,
11545fcf092eSHyungwoo Yang 									0);
11555fcf092eSHyungwoo Yang 
11565fcf092eSHyungwoo Yang 	mutex_lock(&ov13858->mutex);
11575fcf092eSHyungwoo Yang 
11585fcf092eSHyungwoo Yang 	/* Initialize try_fmt */
11595fcf092eSHyungwoo Yang 	try_fmt->width = ov13858->cur_mode->width;
11605fcf092eSHyungwoo Yang 	try_fmt->height = ov13858->cur_mode->height;
11615fcf092eSHyungwoo Yang 	try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
11625fcf092eSHyungwoo Yang 	try_fmt->field = V4L2_FIELD_NONE;
11635fcf092eSHyungwoo Yang 
11645fcf092eSHyungwoo Yang 	/* No crop or compose */
11655fcf092eSHyungwoo Yang 	mutex_unlock(&ov13858->mutex);
11665fcf092eSHyungwoo Yang 
11675fcf092eSHyungwoo Yang 	return 0;
11685fcf092eSHyungwoo Yang }
11695fcf092eSHyungwoo Yang 
11705fcf092eSHyungwoo Yang static int ov13858_update_digital_gain(struct ov13858 *ov13858, u32 d_gain)
11715fcf092eSHyungwoo Yang {
11725fcf092eSHyungwoo Yang 	int ret;
11735fcf092eSHyungwoo Yang 
1174bfced6d1SChiranjeevi Rapolu 	ret = ov13858_write_reg(ov13858, OV13858_REG_B_MWB_GAIN,
1175bfced6d1SChiranjeevi Rapolu 				OV13858_REG_VALUE_16BIT, d_gain);
11765fcf092eSHyungwoo Yang 	if (ret)
11775fcf092eSHyungwoo Yang 		return ret;
11785fcf092eSHyungwoo Yang 
1179bfced6d1SChiranjeevi Rapolu 	ret = ov13858_write_reg(ov13858, OV13858_REG_G_MWB_GAIN,
1180bfced6d1SChiranjeevi Rapolu 				OV13858_REG_VALUE_16BIT, d_gain);
1181bfced6d1SChiranjeevi Rapolu 	if (ret)
1182bfced6d1SChiranjeevi Rapolu 		return ret;
11835fcf092eSHyungwoo Yang 
1184bfced6d1SChiranjeevi Rapolu 	ret = ov13858_write_reg(ov13858, OV13858_REG_R_MWB_GAIN,
1185bfced6d1SChiranjeevi Rapolu 				OV13858_REG_VALUE_16BIT, d_gain);
1186bfced6d1SChiranjeevi Rapolu 
1187bfced6d1SChiranjeevi Rapolu 	return ret;
11885fcf092eSHyungwoo Yang }
11895fcf092eSHyungwoo Yang 
11905fcf092eSHyungwoo Yang static int ov13858_enable_test_pattern(struct ov13858 *ov13858, u32 pattern)
11915fcf092eSHyungwoo Yang {
11925fcf092eSHyungwoo Yang 	int ret;
11935fcf092eSHyungwoo Yang 	u32 val;
11945fcf092eSHyungwoo Yang 
11955fcf092eSHyungwoo Yang 	ret = ov13858_read_reg(ov13858, OV13858_REG_TEST_PATTERN,
11965fcf092eSHyungwoo Yang 			       OV13858_REG_VALUE_08BIT, &val);
11975fcf092eSHyungwoo Yang 	if (ret)
11985fcf092eSHyungwoo Yang 		return ret;
11995fcf092eSHyungwoo Yang 
12005fcf092eSHyungwoo Yang 	if (pattern) {
12015fcf092eSHyungwoo Yang 		val &= OV13858_TEST_PATTERN_MASK;
12025fcf092eSHyungwoo Yang 		val |= (pattern - 1) | OV13858_TEST_PATTERN_ENABLE;
12035fcf092eSHyungwoo Yang 	} else {
12045fcf092eSHyungwoo Yang 		val &= ~OV13858_TEST_PATTERN_ENABLE;
12055fcf092eSHyungwoo Yang 	}
12065fcf092eSHyungwoo Yang 
12075fcf092eSHyungwoo Yang 	return ov13858_write_reg(ov13858, OV13858_REG_TEST_PATTERN,
12085fcf092eSHyungwoo Yang 				 OV13858_REG_VALUE_08BIT, val);
12095fcf092eSHyungwoo Yang }
12105fcf092eSHyungwoo Yang 
12115fcf092eSHyungwoo Yang static int ov13858_set_ctrl(struct v4l2_ctrl *ctrl)
12125fcf092eSHyungwoo Yang {
12135fcf092eSHyungwoo Yang 	struct ov13858 *ov13858 = container_of(ctrl->handler,
12145fcf092eSHyungwoo Yang 					       struct ov13858, ctrl_handler);
12155fcf092eSHyungwoo Yang 	struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
12165fcf092eSHyungwoo Yang 	s64 max;
12175fcf092eSHyungwoo Yang 	int ret;
12185fcf092eSHyungwoo Yang 
12195fcf092eSHyungwoo Yang 	/* Propagate change of current control to all related controls */
12205fcf092eSHyungwoo Yang 	switch (ctrl->id) {
12215fcf092eSHyungwoo Yang 	case V4L2_CID_VBLANK:
12225fcf092eSHyungwoo Yang 		/* Update max exposure while meeting expected vblanking */
12235fcf092eSHyungwoo Yang 		max = ov13858->cur_mode->height + ctrl->val - 8;
12245fcf092eSHyungwoo Yang 		__v4l2_ctrl_modify_range(ov13858->exposure,
12255fcf092eSHyungwoo Yang 					 ov13858->exposure->minimum,
12265fcf092eSHyungwoo Yang 					 max, ov13858->exposure->step, max);
12275fcf092eSHyungwoo Yang 		break;
122826092e7eSShobhit Kukreti 	}
12295fcf092eSHyungwoo Yang 
12305fcf092eSHyungwoo Yang 	/*
12315fcf092eSHyungwoo Yang 	 * Applying V4L2 control value only happens
12325fcf092eSHyungwoo Yang 	 * when power is up for streaming
12335fcf092eSHyungwoo Yang 	 */
12344d471563SSakari Ailus 	if (!pm_runtime_get_if_in_use(&client->dev))
12355fcf092eSHyungwoo Yang 		return 0;
12365fcf092eSHyungwoo Yang 
12375fcf092eSHyungwoo Yang 	ret = 0;
12385fcf092eSHyungwoo Yang 	switch (ctrl->id) {
12395fcf092eSHyungwoo Yang 	case V4L2_CID_ANALOGUE_GAIN:
12405fcf092eSHyungwoo Yang 		ret = ov13858_write_reg(ov13858, OV13858_REG_ANALOG_GAIN,
12415fcf092eSHyungwoo Yang 					OV13858_REG_VALUE_16BIT, ctrl->val);
12425fcf092eSHyungwoo Yang 		break;
12435fcf092eSHyungwoo Yang 	case V4L2_CID_DIGITAL_GAIN:
12445fcf092eSHyungwoo Yang 		ret = ov13858_update_digital_gain(ov13858, ctrl->val);
12455fcf092eSHyungwoo Yang 		break;
12465fcf092eSHyungwoo Yang 	case V4L2_CID_EXPOSURE:
12475fcf092eSHyungwoo Yang 		ret = ov13858_write_reg(ov13858, OV13858_REG_EXPOSURE,
12485fcf092eSHyungwoo Yang 					OV13858_REG_VALUE_24BIT,
12495fcf092eSHyungwoo Yang 					ctrl->val << 4);
12505fcf092eSHyungwoo Yang 		break;
12515fcf092eSHyungwoo Yang 	case V4L2_CID_VBLANK:
12525fcf092eSHyungwoo Yang 		/* Update VTS that meets expected vertical blanking */
12535fcf092eSHyungwoo Yang 		ret = ov13858_write_reg(ov13858, OV13858_REG_VTS,
12545fcf092eSHyungwoo Yang 					OV13858_REG_VALUE_16BIT,
12555fcf092eSHyungwoo Yang 					ov13858->cur_mode->height
12565fcf092eSHyungwoo Yang 					  + ctrl->val);
12575fcf092eSHyungwoo Yang 		break;
12585fcf092eSHyungwoo Yang 	case V4L2_CID_TEST_PATTERN:
12595fcf092eSHyungwoo Yang 		ret = ov13858_enable_test_pattern(ov13858, ctrl->val);
12605fcf092eSHyungwoo Yang 		break;
12615fcf092eSHyungwoo Yang 	default:
12625fcf092eSHyungwoo Yang 		dev_info(&client->dev,
12635fcf092eSHyungwoo Yang 			 "ctrl(id:0x%x,val:0x%x) is not handled\n",
12645fcf092eSHyungwoo Yang 			 ctrl->id, ctrl->val);
12655fcf092eSHyungwoo Yang 		break;
126626092e7eSShobhit Kukreti 	}
12675fcf092eSHyungwoo Yang 
12685fcf092eSHyungwoo Yang 	pm_runtime_put(&client->dev);
12695fcf092eSHyungwoo Yang 
12705fcf092eSHyungwoo Yang 	return ret;
12715fcf092eSHyungwoo Yang }
12725fcf092eSHyungwoo Yang 
12735fcf092eSHyungwoo Yang static const struct v4l2_ctrl_ops ov13858_ctrl_ops = {
12745fcf092eSHyungwoo Yang 	.s_ctrl = ov13858_set_ctrl,
12755fcf092eSHyungwoo Yang };
12765fcf092eSHyungwoo Yang 
12775fcf092eSHyungwoo Yang static int ov13858_enum_mbus_code(struct v4l2_subdev *sd,
12785fcf092eSHyungwoo Yang 				  struct v4l2_subdev_pad_config *cfg,
12795fcf092eSHyungwoo Yang 				  struct v4l2_subdev_mbus_code_enum *code)
12805fcf092eSHyungwoo Yang {
12815fcf092eSHyungwoo Yang 	/* Only one bayer order(GRBG) is supported */
12825fcf092eSHyungwoo Yang 	if (code->index > 0)
12835fcf092eSHyungwoo Yang 		return -EINVAL;
12845fcf092eSHyungwoo Yang 
12855fcf092eSHyungwoo Yang 	code->code = MEDIA_BUS_FMT_SGRBG10_1X10;
12865fcf092eSHyungwoo Yang 
12875fcf092eSHyungwoo Yang 	return 0;
12885fcf092eSHyungwoo Yang }
12895fcf092eSHyungwoo Yang 
12905fcf092eSHyungwoo Yang static int ov13858_enum_frame_size(struct v4l2_subdev *sd,
12915fcf092eSHyungwoo Yang 				   struct v4l2_subdev_pad_config *cfg,
12925fcf092eSHyungwoo Yang 				   struct v4l2_subdev_frame_size_enum *fse)
12935fcf092eSHyungwoo Yang {
12945fcf092eSHyungwoo Yang 	if (fse->index >= ARRAY_SIZE(supported_modes))
12955fcf092eSHyungwoo Yang 		return -EINVAL;
12965fcf092eSHyungwoo Yang 
12975fcf092eSHyungwoo Yang 	if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10)
12985fcf092eSHyungwoo Yang 		return -EINVAL;
12995fcf092eSHyungwoo Yang 
13005fcf092eSHyungwoo Yang 	fse->min_width = supported_modes[fse->index].width;
13015fcf092eSHyungwoo Yang 	fse->max_width = fse->min_width;
13025fcf092eSHyungwoo Yang 	fse->min_height = supported_modes[fse->index].height;
13035fcf092eSHyungwoo Yang 	fse->max_height = fse->min_height;
13045fcf092eSHyungwoo Yang 
13055fcf092eSHyungwoo Yang 	return 0;
13065fcf092eSHyungwoo Yang }
13075fcf092eSHyungwoo Yang 
13085fcf092eSHyungwoo Yang static void ov13858_update_pad_format(const struct ov13858_mode *mode,
13095fcf092eSHyungwoo Yang 				      struct v4l2_subdev_format *fmt)
13105fcf092eSHyungwoo Yang {
13115fcf092eSHyungwoo Yang 	fmt->format.width = mode->width;
13125fcf092eSHyungwoo Yang 	fmt->format.height = mode->height;
13135fcf092eSHyungwoo Yang 	fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
13145fcf092eSHyungwoo Yang 	fmt->format.field = V4L2_FIELD_NONE;
13155fcf092eSHyungwoo Yang }
13165fcf092eSHyungwoo Yang 
13175fcf092eSHyungwoo Yang static int ov13858_do_get_pad_format(struct ov13858 *ov13858,
13185fcf092eSHyungwoo Yang 				     struct v4l2_subdev_pad_config *cfg,
13195fcf092eSHyungwoo Yang 				     struct v4l2_subdev_format *fmt)
13205fcf092eSHyungwoo Yang {
13215fcf092eSHyungwoo Yang 	struct v4l2_mbus_framefmt *framefmt;
13225fcf092eSHyungwoo Yang 	struct v4l2_subdev *sd = &ov13858->sd;
13235fcf092eSHyungwoo Yang 
13245fcf092eSHyungwoo Yang 	if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
13255fcf092eSHyungwoo Yang 		framefmt = v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
13265fcf092eSHyungwoo Yang 		fmt->format = *framefmt;
13275fcf092eSHyungwoo Yang 	} else {
13285fcf092eSHyungwoo Yang 		ov13858_update_pad_format(ov13858->cur_mode, fmt);
13295fcf092eSHyungwoo Yang 	}
13305fcf092eSHyungwoo Yang 
13315fcf092eSHyungwoo Yang 	return 0;
13325fcf092eSHyungwoo Yang }
13335fcf092eSHyungwoo Yang 
13345fcf092eSHyungwoo Yang static int ov13858_get_pad_format(struct v4l2_subdev *sd,
13355fcf092eSHyungwoo Yang 				  struct v4l2_subdev_pad_config *cfg,
13365fcf092eSHyungwoo Yang 				  struct v4l2_subdev_format *fmt)
13375fcf092eSHyungwoo Yang {
13385fcf092eSHyungwoo Yang 	struct ov13858 *ov13858 = to_ov13858(sd);
13395fcf092eSHyungwoo Yang 	int ret;
13405fcf092eSHyungwoo Yang 
13415fcf092eSHyungwoo Yang 	mutex_lock(&ov13858->mutex);
13425fcf092eSHyungwoo Yang 	ret = ov13858_do_get_pad_format(ov13858, cfg, fmt);
13435fcf092eSHyungwoo Yang 	mutex_unlock(&ov13858->mutex);
13445fcf092eSHyungwoo Yang 
13455fcf092eSHyungwoo Yang 	return ret;
13465fcf092eSHyungwoo Yang }
13475fcf092eSHyungwoo Yang 
13485fcf092eSHyungwoo Yang static int
13495fcf092eSHyungwoo Yang ov13858_set_pad_format(struct v4l2_subdev *sd,
13505fcf092eSHyungwoo Yang 		       struct v4l2_subdev_pad_config *cfg,
13515fcf092eSHyungwoo Yang 		       struct v4l2_subdev_format *fmt)
13525fcf092eSHyungwoo Yang {
13535fcf092eSHyungwoo Yang 	struct ov13858 *ov13858 = to_ov13858(sd);
13545fcf092eSHyungwoo Yang 	const struct ov13858_mode *mode;
13555fcf092eSHyungwoo Yang 	struct v4l2_mbus_framefmt *framefmt;
1356b3775edcSChiranjeevi Rapolu 	s32 vblank_def;
135717fcd5f5SChiranjeevi Rapolu 	s32 vblank_min;
13585fcf092eSHyungwoo Yang 	s64 h_blank;
13596f2a0594SChiranjeevi Rapolu 	s64 pixel_rate;
13606f2a0594SChiranjeevi Rapolu 	s64 link_freq;
13615fcf092eSHyungwoo Yang 
13625fcf092eSHyungwoo Yang 	mutex_lock(&ov13858->mutex);
13635fcf092eSHyungwoo Yang 
13645fcf092eSHyungwoo Yang 	/* Only one raw bayer(GRBG) order is supported */
13655fcf092eSHyungwoo Yang 	if (fmt->format.code != MEDIA_BUS_FMT_SGRBG10_1X10)
13665fcf092eSHyungwoo Yang 		fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
13675fcf092eSHyungwoo Yang 
1368d2dc57b1SSakari Ailus 	mode = v4l2_find_nearest_size(supported_modes,
1369d2dc57b1SSakari Ailus 				      ARRAY_SIZE(supported_modes),
1370d2dc57b1SSakari Ailus 				      width, height,
1371227b183dSSakari Ailus 				      fmt->format.width, fmt->format.height);
13725fcf092eSHyungwoo Yang 	ov13858_update_pad_format(mode, fmt);
13735fcf092eSHyungwoo Yang 	if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
13745fcf092eSHyungwoo Yang 		framefmt = v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
13755fcf092eSHyungwoo Yang 		*framefmt = fmt->format;
13765fcf092eSHyungwoo Yang 	} else {
13775fcf092eSHyungwoo Yang 		ov13858->cur_mode = mode;
13785fcf092eSHyungwoo Yang 		__v4l2_ctrl_s_ctrl(ov13858->link_freq, mode->link_freq_index);
13796f2a0594SChiranjeevi Rapolu 		link_freq = link_freq_menu_items[mode->link_freq_index];
1380880d45f8SSakari Ailus 		pixel_rate = link_freq_to_pixel_rate(link_freq);
13816f2a0594SChiranjeevi Rapolu 		__v4l2_ctrl_s_ctrl_int64(ov13858->pixel_rate, pixel_rate);
13826f2a0594SChiranjeevi Rapolu 
13835fcf092eSHyungwoo Yang 		/* Update limits and set FPS to default */
138417fcd5f5SChiranjeevi Rapolu 		vblank_def = ov13858->cur_mode->vts_def -
138517fcd5f5SChiranjeevi Rapolu 			     ov13858->cur_mode->height;
138617fcd5f5SChiranjeevi Rapolu 		vblank_min = ov13858->cur_mode->vts_min -
138717fcd5f5SChiranjeevi Rapolu 			     ov13858->cur_mode->height;
13885fcf092eSHyungwoo Yang 		__v4l2_ctrl_modify_range(
138917fcd5f5SChiranjeevi Rapolu 			ov13858->vblank, vblank_min,
13905fcf092eSHyungwoo Yang 			OV13858_VTS_MAX - ov13858->cur_mode->height, 1,
1391b3775edcSChiranjeevi Rapolu 			vblank_def);
1392b3775edcSChiranjeevi Rapolu 		__v4l2_ctrl_s_ctrl(ov13858->vblank, vblank_def);
13935fcf092eSHyungwoo Yang 		h_blank =
13945fcf092eSHyungwoo Yang 			link_freq_configs[mode->link_freq_index].pixels_per_line
13955fcf092eSHyungwoo Yang 			 - ov13858->cur_mode->width;
13965fcf092eSHyungwoo Yang 		__v4l2_ctrl_modify_range(ov13858->hblank, h_blank,
13975fcf092eSHyungwoo Yang 					 h_blank, 1, h_blank);
13985fcf092eSHyungwoo Yang 	}
13995fcf092eSHyungwoo Yang 
14005fcf092eSHyungwoo Yang 	mutex_unlock(&ov13858->mutex);
14015fcf092eSHyungwoo Yang 
14025fcf092eSHyungwoo Yang 	return 0;
14035fcf092eSHyungwoo Yang }
14045fcf092eSHyungwoo Yang 
14055fcf092eSHyungwoo Yang static int ov13858_get_skip_frames(struct v4l2_subdev *sd, u32 *frames)
14065fcf092eSHyungwoo Yang {
14075fcf092eSHyungwoo Yang 	*frames = OV13858_NUM_OF_SKIP_FRAMES;
14085fcf092eSHyungwoo Yang 
14095fcf092eSHyungwoo Yang 	return 0;
14105fcf092eSHyungwoo Yang }
14115fcf092eSHyungwoo Yang 
14125fcf092eSHyungwoo Yang /* Start streaming */
14135fcf092eSHyungwoo Yang static int ov13858_start_streaming(struct ov13858 *ov13858)
14145fcf092eSHyungwoo Yang {
14155fcf092eSHyungwoo Yang 	struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
14165fcf092eSHyungwoo Yang 	const struct ov13858_reg_list *reg_list;
14175fcf092eSHyungwoo Yang 	int ret, link_freq_index;
14185fcf092eSHyungwoo Yang 
14195fcf092eSHyungwoo Yang 	/* Get out of from software reset */
14205fcf092eSHyungwoo Yang 	ret = ov13858_write_reg(ov13858, OV13858_REG_SOFTWARE_RST,
14215fcf092eSHyungwoo Yang 				OV13858_REG_VALUE_08BIT, OV13858_SOFTWARE_RST);
14225fcf092eSHyungwoo Yang 	if (ret) {
14235fcf092eSHyungwoo Yang 		dev_err(&client->dev, "%s failed to set powerup registers\n",
14245fcf092eSHyungwoo Yang 			__func__);
14255fcf092eSHyungwoo Yang 		return ret;
14265fcf092eSHyungwoo Yang 	}
14275fcf092eSHyungwoo Yang 
14285fcf092eSHyungwoo Yang 	/* Setup PLL */
14295fcf092eSHyungwoo Yang 	link_freq_index = ov13858->cur_mode->link_freq_index;
14305fcf092eSHyungwoo Yang 	reg_list = &link_freq_configs[link_freq_index].reg_list;
14315fcf092eSHyungwoo Yang 	ret = ov13858_write_reg_list(ov13858, reg_list);
14325fcf092eSHyungwoo Yang 	if (ret) {
14335fcf092eSHyungwoo Yang 		dev_err(&client->dev, "%s failed to set plls\n", __func__);
14345fcf092eSHyungwoo Yang 		return ret;
14355fcf092eSHyungwoo Yang 	}
14365fcf092eSHyungwoo Yang 
14375fcf092eSHyungwoo Yang 	/* Apply default values of current mode */
14385fcf092eSHyungwoo Yang 	reg_list = &ov13858->cur_mode->reg_list;
14395fcf092eSHyungwoo Yang 	ret = ov13858_write_reg_list(ov13858, reg_list);
14405fcf092eSHyungwoo Yang 	if (ret) {
14415fcf092eSHyungwoo Yang 		dev_err(&client->dev, "%s failed to set mode\n", __func__);
14425fcf092eSHyungwoo Yang 		return ret;
14435fcf092eSHyungwoo Yang 	}
14445fcf092eSHyungwoo Yang 
14455fcf092eSHyungwoo Yang 	/* Apply customized values from user */
14465fcf092eSHyungwoo Yang 	ret =  __v4l2_ctrl_handler_setup(ov13858->sd.ctrl_handler);
14475fcf092eSHyungwoo Yang 	if (ret)
14485fcf092eSHyungwoo Yang 		return ret;
14495fcf092eSHyungwoo Yang 
14505fcf092eSHyungwoo Yang 	return ov13858_write_reg(ov13858, OV13858_REG_MODE_SELECT,
14515fcf092eSHyungwoo Yang 				 OV13858_REG_VALUE_08BIT,
14525fcf092eSHyungwoo Yang 				 OV13858_MODE_STREAMING);
14535fcf092eSHyungwoo Yang }
14545fcf092eSHyungwoo Yang 
14555fcf092eSHyungwoo Yang /* Stop streaming */
14565fcf092eSHyungwoo Yang static int ov13858_stop_streaming(struct ov13858 *ov13858)
14575fcf092eSHyungwoo Yang {
14585fcf092eSHyungwoo Yang 	return ov13858_write_reg(ov13858, OV13858_REG_MODE_SELECT,
14595fcf092eSHyungwoo Yang 				 OV13858_REG_VALUE_08BIT, OV13858_MODE_STANDBY);
14605fcf092eSHyungwoo Yang }
14615fcf092eSHyungwoo Yang 
14625fcf092eSHyungwoo Yang static int ov13858_set_stream(struct v4l2_subdev *sd, int enable)
14635fcf092eSHyungwoo Yang {
14645fcf092eSHyungwoo Yang 	struct ov13858 *ov13858 = to_ov13858(sd);
14655fcf092eSHyungwoo Yang 	struct i2c_client *client = v4l2_get_subdevdata(sd);
14665fcf092eSHyungwoo Yang 	int ret = 0;
14675fcf092eSHyungwoo Yang 
14685fcf092eSHyungwoo Yang 	mutex_lock(&ov13858->mutex);
14695fcf092eSHyungwoo Yang 	if (ov13858->streaming == enable) {
14705fcf092eSHyungwoo Yang 		mutex_unlock(&ov13858->mutex);
14715fcf092eSHyungwoo Yang 		return 0;
14725fcf092eSHyungwoo Yang 	}
14735fcf092eSHyungwoo Yang 
14745fcf092eSHyungwoo Yang 	if (enable) {
14755fcf092eSHyungwoo Yang 		ret = pm_runtime_get_sync(&client->dev);
14765fcf092eSHyungwoo Yang 		if (ret < 0) {
14775fcf092eSHyungwoo Yang 			pm_runtime_put_noidle(&client->dev);
14785fcf092eSHyungwoo Yang 			goto err_unlock;
14795fcf092eSHyungwoo Yang 		}
14805fcf092eSHyungwoo Yang 
14815fcf092eSHyungwoo Yang 		/*
14825fcf092eSHyungwoo Yang 		 * Apply default & customized values
14835fcf092eSHyungwoo Yang 		 * and then start streaming.
14845fcf092eSHyungwoo Yang 		 */
14855fcf092eSHyungwoo Yang 		ret = ov13858_start_streaming(ov13858);
14865fcf092eSHyungwoo Yang 		if (ret)
14875fcf092eSHyungwoo Yang 			goto err_rpm_put;
14885fcf092eSHyungwoo Yang 	} else {
14895fcf092eSHyungwoo Yang 		ov13858_stop_streaming(ov13858);
14905fcf092eSHyungwoo Yang 		pm_runtime_put(&client->dev);
14915fcf092eSHyungwoo Yang 	}
14925fcf092eSHyungwoo Yang 
14935fcf092eSHyungwoo Yang 	ov13858->streaming = enable;
14945fcf092eSHyungwoo Yang 	mutex_unlock(&ov13858->mutex);
14955fcf092eSHyungwoo Yang 
14965fcf092eSHyungwoo Yang 	return ret;
14975fcf092eSHyungwoo Yang 
14985fcf092eSHyungwoo Yang err_rpm_put:
14995fcf092eSHyungwoo Yang 	pm_runtime_put(&client->dev);
15005fcf092eSHyungwoo Yang err_unlock:
15015fcf092eSHyungwoo Yang 	mutex_unlock(&ov13858->mutex);
15025fcf092eSHyungwoo Yang 
15035fcf092eSHyungwoo Yang 	return ret;
15045fcf092eSHyungwoo Yang }
15055fcf092eSHyungwoo Yang 
15065fcf092eSHyungwoo Yang static int __maybe_unused ov13858_suspend(struct device *dev)
15075fcf092eSHyungwoo Yang {
150800dd015dSKrzysztof Kozlowski 	struct v4l2_subdev *sd = dev_get_drvdata(dev);
15095fcf092eSHyungwoo Yang 	struct ov13858 *ov13858 = to_ov13858(sd);
15105fcf092eSHyungwoo Yang 
15115fcf092eSHyungwoo Yang 	if (ov13858->streaming)
15125fcf092eSHyungwoo Yang 		ov13858_stop_streaming(ov13858);
15135fcf092eSHyungwoo Yang 
15145fcf092eSHyungwoo Yang 	return 0;
15155fcf092eSHyungwoo Yang }
15165fcf092eSHyungwoo Yang 
15175fcf092eSHyungwoo Yang static int __maybe_unused ov13858_resume(struct device *dev)
15185fcf092eSHyungwoo Yang {
151900dd015dSKrzysztof Kozlowski 	struct v4l2_subdev *sd = dev_get_drvdata(dev);
15205fcf092eSHyungwoo Yang 	struct ov13858 *ov13858 = to_ov13858(sd);
15215fcf092eSHyungwoo Yang 	int ret;
15225fcf092eSHyungwoo Yang 
15235fcf092eSHyungwoo Yang 	if (ov13858->streaming) {
15245fcf092eSHyungwoo Yang 		ret = ov13858_start_streaming(ov13858);
15255fcf092eSHyungwoo Yang 		if (ret)
15265fcf092eSHyungwoo Yang 			goto error;
15275fcf092eSHyungwoo Yang 	}
15285fcf092eSHyungwoo Yang 
15295fcf092eSHyungwoo Yang 	return 0;
15305fcf092eSHyungwoo Yang 
15315fcf092eSHyungwoo Yang error:
15325fcf092eSHyungwoo Yang 	ov13858_stop_streaming(ov13858);
1533f4b32c29SGustavo A. R. Silva 	ov13858->streaming = false;
15345fcf092eSHyungwoo Yang 	return ret;
15355fcf092eSHyungwoo Yang }
15365fcf092eSHyungwoo Yang 
15375fcf092eSHyungwoo Yang /* Verify chip ID */
15385fcf092eSHyungwoo Yang static int ov13858_identify_module(struct ov13858 *ov13858)
15395fcf092eSHyungwoo Yang {
15405fcf092eSHyungwoo Yang 	struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
15415fcf092eSHyungwoo Yang 	int ret;
15425fcf092eSHyungwoo Yang 	u32 val;
15435fcf092eSHyungwoo Yang 
15445fcf092eSHyungwoo Yang 	ret = ov13858_read_reg(ov13858, OV13858_REG_CHIP_ID,
15455fcf092eSHyungwoo Yang 			       OV13858_REG_VALUE_24BIT, &val);
15465fcf092eSHyungwoo Yang 	if (ret)
15475fcf092eSHyungwoo Yang 		return ret;
15485fcf092eSHyungwoo Yang 
15495fcf092eSHyungwoo Yang 	if (val != OV13858_CHIP_ID) {
15505fcf092eSHyungwoo Yang 		dev_err(&client->dev, "chip id mismatch: %x!=%x\n",
15515fcf092eSHyungwoo Yang 			OV13858_CHIP_ID, val);
15525fcf092eSHyungwoo Yang 		return -EIO;
15535fcf092eSHyungwoo Yang 	}
15545fcf092eSHyungwoo Yang 
15555fcf092eSHyungwoo Yang 	return 0;
15565fcf092eSHyungwoo Yang }
15575fcf092eSHyungwoo Yang 
15585fcf092eSHyungwoo Yang static const struct v4l2_subdev_video_ops ov13858_video_ops = {
15595fcf092eSHyungwoo Yang 	.s_stream = ov13858_set_stream,
15605fcf092eSHyungwoo Yang };
15615fcf092eSHyungwoo Yang 
15625fcf092eSHyungwoo Yang static const struct v4l2_subdev_pad_ops ov13858_pad_ops = {
15635fcf092eSHyungwoo Yang 	.enum_mbus_code = ov13858_enum_mbus_code,
15645fcf092eSHyungwoo Yang 	.get_fmt = ov13858_get_pad_format,
15655fcf092eSHyungwoo Yang 	.set_fmt = ov13858_set_pad_format,
15665fcf092eSHyungwoo Yang 	.enum_frame_size = ov13858_enum_frame_size,
15675fcf092eSHyungwoo Yang };
15685fcf092eSHyungwoo Yang 
15695fcf092eSHyungwoo Yang static const struct v4l2_subdev_sensor_ops ov13858_sensor_ops = {
15705fcf092eSHyungwoo Yang 	.g_skip_frames = ov13858_get_skip_frames,
15715fcf092eSHyungwoo Yang };
15725fcf092eSHyungwoo Yang 
15735fcf092eSHyungwoo Yang static const struct v4l2_subdev_ops ov13858_subdev_ops = {
15745fcf092eSHyungwoo Yang 	.video = &ov13858_video_ops,
15755fcf092eSHyungwoo Yang 	.pad = &ov13858_pad_ops,
15765fcf092eSHyungwoo Yang 	.sensor = &ov13858_sensor_ops,
15775fcf092eSHyungwoo Yang };
15785fcf092eSHyungwoo Yang 
15795fcf092eSHyungwoo Yang static const struct media_entity_operations ov13858_subdev_entity_ops = {
15805fcf092eSHyungwoo Yang 	.link_validate = v4l2_subdev_link_validate,
15815fcf092eSHyungwoo Yang };
15825fcf092eSHyungwoo Yang 
15835fcf092eSHyungwoo Yang static const struct v4l2_subdev_internal_ops ov13858_internal_ops = {
15845fcf092eSHyungwoo Yang 	.open = ov13858_open,
15855fcf092eSHyungwoo Yang };
15865fcf092eSHyungwoo Yang 
15875fcf092eSHyungwoo Yang /* Initialize control handlers */
15885fcf092eSHyungwoo Yang static int ov13858_init_controls(struct ov13858 *ov13858)
15895fcf092eSHyungwoo Yang {
15905fcf092eSHyungwoo Yang 	struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
159174c3ddd9SJacopo Mondi 	struct v4l2_fwnode_device_properties props;
15925fcf092eSHyungwoo Yang 	struct v4l2_ctrl_handler *ctrl_hdlr;
159333eea132SChiranjeevi Rapolu 	s64 exposure_max;
159417fcd5f5SChiranjeevi Rapolu 	s64 vblank_def;
159517fcd5f5SChiranjeevi Rapolu 	s64 vblank_min;
15966f2a0594SChiranjeevi Rapolu 	s64 hblank;
15976f2a0594SChiranjeevi Rapolu 	s64 pixel_rate_min;
15986f2a0594SChiranjeevi Rapolu 	s64 pixel_rate_max;
15996f2a0594SChiranjeevi Rapolu 	const struct ov13858_mode *mode;
16005fcf092eSHyungwoo Yang 	int ret;
16015fcf092eSHyungwoo Yang 
16025fcf092eSHyungwoo Yang 	ctrl_hdlr = &ov13858->ctrl_handler;
160374c3ddd9SJacopo Mondi 	ret = v4l2_ctrl_handler_init(ctrl_hdlr, 10);
16045fcf092eSHyungwoo Yang 	if (ret)
16055fcf092eSHyungwoo Yang 		return ret;
16065fcf092eSHyungwoo Yang 
16075fcf092eSHyungwoo Yang 	mutex_init(&ov13858->mutex);
16085fcf092eSHyungwoo Yang 	ctrl_hdlr->lock = &ov13858->mutex;
16095fcf092eSHyungwoo Yang 	ov13858->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr,
16105fcf092eSHyungwoo Yang 				&ov13858_ctrl_ops,
16115fcf092eSHyungwoo Yang 				V4L2_CID_LINK_FREQ,
16125fcf092eSHyungwoo Yang 				OV13858_NUM_OF_LINK_FREQS - 1,
16135fcf092eSHyungwoo Yang 				0,
16145fcf092eSHyungwoo Yang 				link_freq_menu_items);
161535629182SChiranjeevi Rapolu 	if (ov13858->link_freq)
16165fcf092eSHyungwoo Yang 		ov13858->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
16175fcf092eSHyungwoo Yang 
1618880d45f8SSakari Ailus 	pixel_rate_max = link_freq_to_pixel_rate(link_freq_menu_items[0]);
1619880d45f8SSakari Ailus 	pixel_rate_min = link_freq_to_pixel_rate(link_freq_menu_items[1]);
16205fcf092eSHyungwoo Yang 	/* By default, PIXEL_RATE is read only */
16215fcf092eSHyungwoo Yang 	ov13858->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops,
16226f2a0594SChiranjeevi Rapolu 						V4L2_CID_PIXEL_RATE,
16236f2a0594SChiranjeevi Rapolu 						pixel_rate_min, pixel_rate_max,
16246f2a0594SChiranjeevi Rapolu 						1, pixel_rate_max);
16255fcf092eSHyungwoo Yang 
16266f2a0594SChiranjeevi Rapolu 	mode = ov13858->cur_mode;
16276f2a0594SChiranjeevi Rapolu 	vblank_def = mode->vts_def - mode->height;
16286f2a0594SChiranjeevi Rapolu 	vblank_min = mode->vts_min - mode->height;
16295fcf092eSHyungwoo Yang 	ov13858->vblank = v4l2_ctrl_new_std(
16305fcf092eSHyungwoo Yang 				ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_VBLANK,
16316f2a0594SChiranjeevi Rapolu 				vblank_min, OV13858_VTS_MAX - mode->height, 1,
163217fcd5f5SChiranjeevi Rapolu 				vblank_def);
16335fcf092eSHyungwoo Yang 
16346f2a0594SChiranjeevi Rapolu 	hblank = link_freq_configs[mode->link_freq_index].pixels_per_line -
16356f2a0594SChiranjeevi Rapolu 		 mode->width;
16365fcf092eSHyungwoo Yang 	ov13858->hblank = v4l2_ctrl_new_std(
16375fcf092eSHyungwoo Yang 				ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_HBLANK,
16386f2a0594SChiranjeevi Rapolu 				hblank, hblank, 1, hblank);
163935629182SChiranjeevi Rapolu 	if (ov13858->hblank)
16405fcf092eSHyungwoo Yang 		ov13858->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
16415fcf092eSHyungwoo Yang 
16426f2a0594SChiranjeevi Rapolu 	exposure_max = mode->vts_def - 8;
16435fcf092eSHyungwoo Yang 	ov13858->exposure = v4l2_ctrl_new_std(
16445fcf092eSHyungwoo Yang 				ctrl_hdlr, &ov13858_ctrl_ops,
16455fcf092eSHyungwoo Yang 				V4L2_CID_EXPOSURE, OV13858_EXPOSURE_MIN,
164633eea132SChiranjeevi Rapolu 				exposure_max, OV13858_EXPOSURE_STEP,
16475fcf092eSHyungwoo Yang 				OV13858_EXPOSURE_DEFAULT);
16485fcf092eSHyungwoo Yang 
16495fcf092eSHyungwoo Yang 	v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
16505fcf092eSHyungwoo Yang 			  OV13858_ANA_GAIN_MIN, OV13858_ANA_GAIN_MAX,
16515fcf092eSHyungwoo Yang 			  OV13858_ANA_GAIN_STEP, OV13858_ANA_GAIN_DEFAULT);
16525fcf092eSHyungwoo Yang 
16535fcf092eSHyungwoo Yang 	/* Digital gain */
16545fcf092eSHyungwoo Yang 	v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
16555fcf092eSHyungwoo Yang 			  OV13858_DGTL_GAIN_MIN, OV13858_DGTL_GAIN_MAX,
16565fcf092eSHyungwoo Yang 			  OV13858_DGTL_GAIN_STEP, OV13858_DGTL_GAIN_DEFAULT);
16575fcf092eSHyungwoo Yang 
16585fcf092eSHyungwoo Yang 	v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov13858_ctrl_ops,
16595fcf092eSHyungwoo Yang 				     V4L2_CID_TEST_PATTERN,
16605fcf092eSHyungwoo Yang 				     ARRAY_SIZE(ov13858_test_pattern_menu) - 1,
16615fcf092eSHyungwoo Yang 				     0, 0, ov13858_test_pattern_menu);
16625fcf092eSHyungwoo Yang 	if (ctrl_hdlr->error) {
16635fcf092eSHyungwoo Yang 		ret = ctrl_hdlr->error;
16645fcf092eSHyungwoo Yang 		dev_err(&client->dev, "%s control init failed (%d)\n",
16655fcf092eSHyungwoo Yang 			__func__, ret);
16665fcf092eSHyungwoo Yang 		goto error;
16675fcf092eSHyungwoo Yang 	}
16685fcf092eSHyungwoo Yang 
166974c3ddd9SJacopo Mondi 	ret = v4l2_fwnode_device_parse(&client->dev, &props);
167074c3ddd9SJacopo Mondi 	if (ret)
167174c3ddd9SJacopo Mondi 		goto error;
167274c3ddd9SJacopo Mondi 
167374c3ddd9SJacopo Mondi 	ret = v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &ov13858_ctrl_ops,
167474c3ddd9SJacopo Mondi 					      &props);
167574c3ddd9SJacopo Mondi 	if (ret)
167674c3ddd9SJacopo Mondi 		goto error;
167774c3ddd9SJacopo Mondi 
16785fcf092eSHyungwoo Yang 	ov13858->sd.ctrl_handler = ctrl_hdlr;
16795fcf092eSHyungwoo Yang 
16805fcf092eSHyungwoo Yang 	return 0;
16815fcf092eSHyungwoo Yang 
16825fcf092eSHyungwoo Yang error:
16835fcf092eSHyungwoo Yang 	v4l2_ctrl_handler_free(ctrl_hdlr);
16845fcf092eSHyungwoo Yang 	mutex_destroy(&ov13858->mutex);
16855fcf092eSHyungwoo Yang 
16865fcf092eSHyungwoo Yang 	return ret;
16875fcf092eSHyungwoo Yang }
16885fcf092eSHyungwoo Yang 
16895fcf092eSHyungwoo Yang static void ov13858_free_controls(struct ov13858 *ov13858)
16905fcf092eSHyungwoo Yang {
16915fcf092eSHyungwoo Yang 	v4l2_ctrl_handler_free(ov13858->sd.ctrl_handler);
16925fcf092eSHyungwoo Yang 	mutex_destroy(&ov13858->mutex);
16935fcf092eSHyungwoo Yang }
16945fcf092eSHyungwoo Yang 
16955fcf092eSHyungwoo Yang static int ov13858_probe(struct i2c_client *client,
16965fcf092eSHyungwoo Yang 			 const struct i2c_device_id *devid)
16975fcf092eSHyungwoo Yang {
16985fcf092eSHyungwoo Yang 	struct ov13858 *ov13858;
16995fcf092eSHyungwoo Yang 	int ret;
17005fcf092eSHyungwoo Yang 	u32 val = 0;
17015fcf092eSHyungwoo Yang 
17025fcf092eSHyungwoo Yang 	device_property_read_u32(&client->dev, "clock-frequency", &val);
17035fcf092eSHyungwoo Yang 	if (val != 19200000)
17045fcf092eSHyungwoo Yang 		return -EINVAL;
17055fcf092eSHyungwoo Yang 
17065fcf092eSHyungwoo Yang 	ov13858 = devm_kzalloc(&client->dev, sizeof(*ov13858), GFP_KERNEL);
17075fcf092eSHyungwoo Yang 	if (!ov13858)
17085fcf092eSHyungwoo Yang 		return -ENOMEM;
17095fcf092eSHyungwoo Yang 
17105fcf092eSHyungwoo Yang 	/* Initialize subdev */
17115fcf092eSHyungwoo Yang 	v4l2_i2c_subdev_init(&ov13858->sd, client, &ov13858_subdev_ops);
17125fcf092eSHyungwoo Yang 
17135fcf092eSHyungwoo Yang 	/* Check module identity */
17145fcf092eSHyungwoo Yang 	ret = ov13858_identify_module(ov13858);
17155fcf092eSHyungwoo Yang 	if (ret) {
17165fcf092eSHyungwoo Yang 		dev_err(&client->dev, "failed to find sensor: %d\n", ret);
17175fcf092eSHyungwoo Yang 		return ret;
17185fcf092eSHyungwoo Yang 	}
17195fcf092eSHyungwoo Yang 
17205fcf092eSHyungwoo Yang 	/* Set default mode to max resolution */
17215fcf092eSHyungwoo Yang 	ov13858->cur_mode = &supported_modes[0];
17225fcf092eSHyungwoo Yang 
17235fcf092eSHyungwoo Yang 	ret = ov13858_init_controls(ov13858);
17245fcf092eSHyungwoo Yang 	if (ret)
17255fcf092eSHyungwoo Yang 		return ret;
17265fcf092eSHyungwoo Yang 
17275fcf092eSHyungwoo Yang 	/* Initialize subdev */
17285fcf092eSHyungwoo Yang 	ov13858->sd.internal_ops = &ov13858_internal_ops;
17295fcf092eSHyungwoo Yang 	ov13858->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
17305fcf092eSHyungwoo Yang 	ov13858->sd.entity.ops = &ov13858_subdev_entity_ops;
17315fcf092eSHyungwoo Yang 	ov13858->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
17325fcf092eSHyungwoo Yang 
17335fcf092eSHyungwoo Yang 	/* Initialize source pad */
17345fcf092eSHyungwoo Yang 	ov13858->pad.flags = MEDIA_PAD_FL_SOURCE;
17355fcf092eSHyungwoo Yang 	ret = media_entity_pads_init(&ov13858->sd.entity, 1, &ov13858->pad);
17365fcf092eSHyungwoo Yang 	if (ret) {
17375fcf092eSHyungwoo Yang 		dev_err(&client->dev, "%s failed:%d\n", __func__, ret);
17385fcf092eSHyungwoo Yang 		goto error_handler_free;
17395fcf092eSHyungwoo Yang 	}
17405fcf092eSHyungwoo Yang 
1741*15786f7bSSakari Ailus 	ret = v4l2_async_register_subdev_sensor(&ov13858->sd);
17425fcf092eSHyungwoo Yang 	if (ret < 0)
17435fcf092eSHyungwoo Yang 		goto error_media_entity;
17445fcf092eSHyungwoo Yang 
17455fcf092eSHyungwoo Yang 	/*
17465fcf092eSHyungwoo Yang 	 * Device is already turned on by i2c-core with ACPI domain PM.
17475fcf092eSHyungwoo Yang 	 * Enable runtime PM and turn off the device.
17485fcf092eSHyungwoo Yang 	 */
17495fcf092eSHyungwoo Yang 	pm_runtime_set_active(&client->dev);
17505fcf092eSHyungwoo Yang 	pm_runtime_enable(&client->dev);
1751d508fffbSSakari Ailus 	pm_runtime_idle(&client->dev);
17525fcf092eSHyungwoo Yang 
17535fcf092eSHyungwoo Yang 	return 0;
17545fcf092eSHyungwoo Yang 
17555fcf092eSHyungwoo Yang error_media_entity:
17565fcf092eSHyungwoo Yang 	media_entity_cleanup(&ov13858->sd.entity);
17575fcf092eSHyungwoo Yang 
17585fcf092eSHyungwoo Yang error_handler_free:
17595fcf092eSHyungwoo Yang 	ov13858_free_controls(ov13858);
17605fcf092eSHyungwoo Yang 	dev_err(&client->dev, "%s failed:%d\n", __func__, ret);
17615fcf092eSHyungwoo Yang 
17625fcf092eSHyungwoo Yang 	return ret;
17635fcf092eSHyungwoo Yang }
17645fcf092eSHyungwoo Yang 
17655fcf092eSHyungwoo Yang static int ov13858_remove(struct i2c_client *client)
17665fcf092eSHyungwoo Yang {
17675fcf092eSHyungwoo Yang 	struct v4l2_subdev *sd = i2c_get_clientdata(client);
17685fcf092eSHyungwoo Yang 	struct ov13858 *ov13858 = to_ov13858(sd);
17695fcf092eSHyungwoo Yang 
17705fcf092eSHyungwoo Yang 	v4l2_async_unregister_subdev(sd);
17715fcf092eSHyungwoo Yang 	media_entity_cleanup(&sd->entity);
17725fcf092eSHyungwoo Yang 	ov13858_free_controls(ov13858);
17735fcf092eSHyungwoo Yang 
17745fcf092eSHyungwoo Yang 	pm_runtime_disable(&client->dev);
17755fcf092eSHyungwoo Yang 
17765fcf092eSHyungwoo Yang 	return 0;
17775fcf092eSHyungwoo Yang }
17785fcf092eSHyungwoo Yang 
17795fcf092eSHyungwoo Yang static const struct i2c_device_id ov13858_id_table[] = {
17805fcf092eSHyungwoo Yang 	{"ov13858", 0},
17815fcf092eSHyungwoo Yang 	{},
17825fcf092eSHyungwoo Yang };
17835fcf092eSHyungwoo Yang 
17845fcf092eSHyungwoo Yang MODULE_DEVICE_TABLE(i2c, ov13858_id_table);
17855fcf092eSHyungwoo Yang 
17865fcf092eSHyungwoo Yang static const struct dev_pm_ops ov13858_pm_ops = {
17875fcf092eSHyungwoo Yang 	SET_SYSTEM_SLEEP_PM_OPS(ov13858_suspend, ov13858_resume)
17885fcf092eSHyungwoo Yang };
17895fcf092eSHyungwoo Yang 
17905fcf092eSHyungwoo Yang #ifdef CONFIG_ACPI
17915fcf092eSHyungwoo Yang static const struct acpi_device_id ov13858_acpi_ids[] = {
17925fcf092eSHyungwoo Yang 	{"OVTID858"},
17935fcf092eSHyungwoo Yang 	{ /* sentinel */ }
17945fcf092eSHyungwoo Yang };
17955fcf092eSHyungwoo Yang 
17965fcf092eSHyungwoo Yang MODULE_DEVICE_TABLE(acpi, ov13858_acpi_ids);
17975fcf092eSHyungwoo Yang #endif
17985fcf092eSHyungwoo Yang 
17995fcf092eSHyungwoo Yang static struct i2c_driver ov13858_i2c_driver = {
18005fcf092eSHyungwoo Yang 	.driver = {
18015fcf092eSHyungwoo Yang 		.name = "ov13858",
18025fcf092eSHyungwoo Yang 		.pm = &ov13858_pm_ops,
18035fcf092eSHyungwoo Yang 		.acpi_match_table = ACPI_PTR(ov13858_acpi_ids),
18045fcf092eSHyungwoo Yang 	},
18055fcf092eSHyungwoo Yang 	.probe = ov13858_probe,
18065fcf092eSHyungwoo Yang 	.remove = ov13858_remove,
18075fcf092eSHyungwoo Yang 	.id_table = ov13858_id_table,
18085fcf092eSHyungwoo Yang };
18095fcf092eSHyungwoo Yang 
18105fcf092eSHyungwoo Yang module_i2c_driver(ov13858_i2c_driver);
18115fcf092eSHyungwoo Yang 
18125fcf092eSHyungwoo Yang MODULE_AUTHOR("Kan, Chris <chris.kan@intel.com>");
18135fcf092eSHyungwoo Yang MODULE_AUTHOR("Rapolu, Chiranjeevi <chiranjeevi.rapolu@intel.com>");
18145fcf092eSHyungwoo Yang MODULE_AUTHOR("Yang, Hyungwoo <hyungwoo.yang@intel.com>");
18155fcf092eSHyungwoo Yang MODULE_DESCRIPTION("Omnivision ov13858 sensor driver");
18165fcf092eSHyungwoo Yang MODULE_LICENSE("GPL v2");
1817