1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * ov16a1q camera driver
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2023 Rockchip Electronics Co., Ltd.
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * V0.0X01.0X00 first version.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun //#define DEBUG
11*4882a593Smuzhiyun #include <linux/clk.h>
12*4882a593Smuzhiyun #include <linux/device.h>
13*4882a593Smuzhiyun #include <linux/delay.h>
14*4882a593Smuzhiyun #include <linux/gpio/consumer.h>
15*4882a593Smuzhiyun #include <linux/i2c.h>
16*4882a593Smuzhiyun #include <linux/module.h>
17*4882a593Smuzhiyun #include <linux/pm_runtime.h>
18*4882a593Smuzhiyun #include <linux/regulator/consumer.h>
19*4882a593Smuzhiyun #include <linux/sysfs.h>
20*4882a593Smuzhiyun #include <linux/slab.h>
21*4882a593Smuzhiyun #include <linux/version.h>
22*4882a593Smuzhiyun #include <linux/compat.h>
23*4882a593Smuzhiyun #include <linux/rk-camera-module.h>
24*4882a593Smuzhiyun #include <media/media-entity.h>
25*4882a593Smuzhiyun #include <media/v4l2-async.h>
26*4882a593Smuzhiyun #include <media/v4l2-ctrls.h>
27*4882a593Smuzhiyun #include <media/v4l2-subdev.h>
28*4882a593Smuzhiyun #include <linux/pinctrl/consumer.h>
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x00)
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #ifndef V4L2_CID_DIGITAL_GAIN
33*4882a593Smuzhiyun #define V4L2_CID_DIGITAL_GAIN V4L2_CID_GAIN
34*4882a593Smuzhiyun #endif
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun #define OV16A1Q_LINK_FREQ_726MHZ 726000000U
37*4882a593Smuzhiyun #define OV16A1Q_LINK_FREQ_378MHZ 378000000U
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun /* pixel rate = link frequency * 2 * lanes / BITS_PER_SAMPLE */
40*4882a593Smuzhiyun #define OV16A1Q_PIXEL_RATE (OV16A1Q_LINK_FREQ_726MHZ * 2LL * 4LL / 10LL)
41*4882a593Smuzhiyun #define OV16A1Q_XVCLK_FREQ 24000000
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun #define CHIP_ID 0x561641
44*4882a593Smuzhiyun #define OV16A1Q_REG_CHIP_ID 0x300a
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun #define OV16A1Q_REG_CTRL_MODE 0x0100
47*4882a593Smuzhiyun #define OV16A1Q_MODE_SW_STANDBY 0x0
48*4882a593Smuzhiyun #define OV16A1Q_MODE_STREAMING BIT(0)
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun #define OV16A1Q_REG_EXPOSURE_H 0x3500
51*4882a593Smuzhiyun #define OV16A1Q_REG_EXPOSURE_M 0x3501
52*4882a593Smuzhiyun #define OV16A1Q_REG_EXPOSURE_L 0x3502
53*4882a593Smuzhiyun #define OV16A1Q_EXPOSURE_MIN 4
54*4882a593Smuzhiyun #define OV16A1Q_EXPOSURE_STEP 1
55*4882a593Smuzhiyun #define OV16A1Q_VTS_MAX 0x7ff7
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun #define OV16A1Q_REG_AGAIN_H 0x3508
58*4882a593Smuzhiyun #define OV16A1Q_REG_AGAIN_L 0x3509
59*4882a593Smuzhiyun #define OV16A1Q_REG_DAGAIN_H_B 0x350A
60*4882a593Smuzhiyun #define OV16A1Q_REG_DAGAIN_M_B 0x350B
61*4882a593Smuzhiyun #define OV16A1Q_REG_DAGAIN_L_B 0x350C
62*4882a593Smuzhiyun #define OV16A1Q_GAIN_MIN 0x80
63*4882a593Smuzhiyun #define OV16A1Q_GAIN_MAX 0x3df61
64*4882a593Smuzhiyun #define OV16A1Q_GAIN_STEP 1
65*4882a593Smuzhiyun #define OV16A1Q_GAIN_DEFAULT 0x80
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun #define OV16A1Q_SOFTWARE_RESET_REG 0x0103
68*4882a593Smuzhiyun #define OV16A1Q_REG_ISP_X_WIN 0x3810
69*4882a593Smuzhiyun #define OV16A1Q_REG_ISP_Y_WIN 0x3812
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun #define OV16A1Q_GROUP_UPDATE_ADDRESS 0x3208
72*4882a593Smuzhiyun #define OV16A1Q_GROUP_UPDATE_START_DATA 0x00
73*4882a593Smuzhiyun #define OV16A1Q_GROUP_UPDATE_END_DATA 0x10
74*4882a593Smuzhiyun #define OV16A1Q_GROUP_UPDATE_LAUNCH 0xA0
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun #define OV16A1Q_REG_TEST_PATTERN 0x5081
77*4882a593Smuzhiyun #define OV16A1Q_TEST_PATTERN_ENABLE 0x01
78*4882a593Smuzhiyun #define OV16A1Q_TEST_PATTERN_DISABLE 0x0
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun #define OV16A1Q_REG_VTS_H 0x380e
81*4882a593Smuzhiyun #define OV16A1Q_REG_VTS_L 0x380f
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun #define OV16A1Q_FLIP_REG 0x3820
84*4882a593Smuzhiyun #define OV16A1Q_MIRROR_REG 0x3821
85*4882a593Smuzhiyun #define MIRROR_BIT_MASK BIT(2)
86*4882a593Smuzhiyun #define FLIP_BIT_MASK BIT(2)
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun #define OV16A1Q_FETCH_EXP_H(VAL) (((VAL) >> 16) & 0x7F)
89*4882a593Smuzhiyun #define OV16A1Q_FETCH_EXP_M(VAL) (((VAL) >> 8) & 0xFF)
90*4882a593Smuzhiyun #define OV16A1Q_FETCH_EXP_L(VAL) ((VAL) & 0xFF)
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun #define OV16A1Q_FETCH_AGAIN_H(VAL) (((VAL) >> 8) & 0x7F)
93*4882a593Smuzhiyun #define OV16A1Q_FETCH_AGAIN_L(VAL) ((VAL) & 0xFE)
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun #define OV16A1Q_FETCH_DGAIN_H(VAL) (((VAL) >> 16) & 0x0F)
96*4882a593Smuzhiyun #define OV16A1Q_FETCH_DGAIN_M(VAL) (((VAL) >> 8) & 0xFF)
97*4882a593Smuzhiyun #define OV16A1Q_FETCH_DGAIN_L(VAL) ((VAL) & 0xC0)
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun #define OV16A1Q_FETCH_VTS_H(VAL) (((VAL) >> 8) & 0x7F)
100*4882a593Smuzhiyun #define OV16A1Q_FETCH_VTS_L(VAL) ((VAL) & 0xFF)
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun #define REG_NULL 0xFFFF
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun #define OV16A1Q_REG_VALUE_08BIT 1
105*4882a593Smuzhiyun #define OV16A1Q_REG_VALUE_16BIT 2
106*4882a593Smuzhiyun #define OV16A1Q_REG_VALUE_24BIT 3
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun #define OV16A1Q_LANES 4
109*4882a593Smuzhiyun #define OV16A1Q_BITS_PER_SAMPLE 10
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun #define OF_CAMERA_PINCTRL_STATE_DEFAULT "rockchip,camera_default"
112*4882a593Smuzhiyun #define OF_CAMERA_PINCTRL_STATE_SLEEP "rockchip,camera_sleep"
113*4882a593Smuzhiyun #define OF_CAMERA_HDR_MODE "rockchip,camera-hdr-mode"
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun #define OV16A1Q_NAME "ov16a1q"
116*4882a593Smuzhiyun #define OV16A1Q_MEDIA_BUS_FMT MEDIA_BUS_FMT_SBGGR10_1X10
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun static const char * const ov16a1q_supply_names[] = {
119*4882a593Smuzhiyun "avdd", /* Analog power */
120*4882a593Smuzhiyun "dovdd", /* Digital I/O power */
121*4882a593Smuzhiyun "dvdd", /* Digital core power */
122*4882a593Smuzhiyun };
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun #define OV16A1Q_NUM_SUPPLIES ARRAY_SIZE(ov16a1q_supply_names)
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun struct regval {
127*4882a593Smuzhiyun u16 addr;
128*4882a593Smuzhiyun u8 val;
129*4882a593Smuzhiyun };
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun struct ov16a1q_mode {
132*4882a593Smuzhiyun u32 width;
133*4882a593Smuzhiyun u32 height;
134*4882a593Smuzhiyun struct v4l2_fract max_fps;
135*4882a593Smuzhiyun u32 hts_def;
136*4882a593Smuzhiyun u32 vts_def;
137*4882a593Smuzhiyun u32 exp_def;
138*4882a593Smuzhiyun u32 link_freq_idx;
139*4882a593Smuzhiyun u32 bpp;
140*4882a593Smuzhiyun const struct regval *reg_list;
141*4882a593Smuzhiyun u32 hdr_mode;
142*4882a593Smuzhiyun u32 vc[PAD_MAX];
143*4882a593Smuzhiyun };
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun struct ov16a1q {
146*4882a593Smuzhiyun struct i2c_client *client;
147*4882a593Smuzhiyun struct clk *xvclk;
148*4882a593Smuzhiyun struct gpio_desc *power_gpio;
149*4882a593Smuzhiyun struct gpio_desc *reset_gpio;
150*4882a593Smuzhiyun struct gpio_desc *pwdn_gpio;
151*4882a593Smuzhiyun struct regulator_bulk_data supplies[OV16A1Q_NUM_SUPPLIES];
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun struct pinctrl *pinctrl;
154*4882a593Smuzhiyun struct pinctrl_state *pins_default;
155*4882a593Smuzhiyun struct pinctrl_state *pins_sleep;
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun struct v4l2_subdev subdev;
158*4882a593Smuzhiyun struct media_pad pad;
159*4882a593Smuzhiyun struct v4l2_ctrl_handler ctrl_handler;
160*4882a593Smuzhiyun struct v4l2_ctrl *exposure;
161*4882a593Smuzhiyun struct v4l2_ctrl *anal_gain;
162*4882a593Smuzhiyun struct v4l2_ctrl *digi_gain;
163*4882a593Smuzhiyun struct v4l2_ctrl *hblank;
164*4882a593Smuzhiyun struct v4l2_ctrl *vblank;
165*4882a593Smuzhiyun struct v4l2_ctrl *pixel_rate;
166*4882a593Smuzhiyun struct v4l2_ctrl *link_freq;
167*4882a593Smuzhiyun struct v4l2_ctrl *test_pattern;
168*4882a593Smuzhiyun struct v4l2_ctrl *h_flip;
169*4882a593Smuzhiyun struct v4l2_ctrl *v_flip;
170*4882a593Smuzhiyun struct mutex mutex;
171*4882a593Smuzhiyun bool streaming;
172*4882a593Smuzhiyun bool power_on;
173*4882a593Smuzhiyun const struct ov16a1q_mode *cur_mode;
174*4882a593Smuzhiyun u32 cfg_num;
175*4882a593Smuzhiyun u32 module_index;
176*4882a593Smuzhiyun const char *module_facing;
177*4882a593Smuzhiyun const char *module_name;
178*4882a593Smuzhiyun const char *len_name;
179*4882a593Smuzhiyun };
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun #define to_ov16a1q(sd) container_of(sd, struct ov16a1q, subdev)
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun /*
184*4882a593Smuzhiyun * Xclk 24Mhz
185*4882a593Smuzhiyun */
186*4882a593Smuzhiyun static const struct regval ov16a1q_global_regs[] = {
187*4882a593Smuzhiyun {0x0103, 0x01},
188*4882a593Smuzhiyun {0x0102, 0x00},
189*4882a593Smuzhiyun {0x0301, 0x48},
190*4882a593Smuzhiyun {0x0302, 0x31},
191*4882a593Smuzhiyun {0x0303, 0x04},
192*4882a593Smuzhiyun {0x0305, 0xc2},
193*4882a593Smuzhiyun {0x0306, 0x00},
194*4882a593Smuzhiyun {0x0320, 0x02},
195*4882a593Smuzhiyun {0x0323, 0x04},
196*4882a593Smuzhiyun {0x0326, 0xd8},
197*4882a593Smuzhiyun {0x0327, 0x0b},
198*4882a593Smuzhiyun {0x0329, 0x01},
199*4882a593Smuzhiyun {0x0343, 0x04},
200*4882a593Smuzhiyun {0x0344, 0x01},
201*4882a593Smuzhiyun {0x0345, 0x2c},
202*4882a593Smuzhiyun {0x0346, 0xc0},
203*4882a593Smuzhiyun {0x034a, 0x07},
204*4882a593Smuzhiyun {0x300e, 0x22},
205*4882a593Smuzhiyun {0x3012, 0x41},
206*4882a593Smuzhiyun {0x3016, 0xd2},
207*4882a593Smuzhiyun {0x3018, 0x70},
208*4882a593Smuzhiyun {0x301e, 0x98},
209*4882a593Smuzhiyun {0x3025, 0x03},
210*4882a593Smuzhiyun {0x3026, 0x10},
211*4882a593Smuzhiyun {0x3027, 0x08},
212*4882a593Smuzhiyun {0x3102, 0x00},
213*4882a593Smuzhiyun {0x3400, 0x04},
214*4882a593Smuzhiyun {0x3406, 0x04},
215*4882a593Smuzhiyun {0x3408, 0x04},
216*4882a593Smuzhiyun {0x3421, 0x09},
217*4882a593Smuzhiyun {0x3422, 0x20},
218*4882a593Smuzhiyun {0x3423, 0x15},
219*4882a593Smuzhiyun {0x3424, 0x40},
220*4882a593Smuzhiyun {0x3425, 0x14},
221*4882a593Smuzhiyun {0x3426, 0x04},
222*4882a593Smuzhiyun {0x3504, 0x08},
223*4882a593Smuzhiyun {0x3508, 0x01},
224*4882a593Smuzhiyun {0x3509, 0x00},
225*4882a593Smuzhiyun {0x350a, 0x01},
226*4882a593Smuzhiyun {0x350b, 0x00},
227*4882a593Smuzhiyun {0x350c, 0x00},
228*4882a593Smuzhiyun {0x3548, 0x01},
229*4882a593Smuzhiyun {0x3549, 0x00},
230*4882a593Smuzhiyun {0x354a, 0x01},
231*4882a593Smuzhiyun {0x354b, 0x00},
232*4882a593Smuzhiyun {0x354c, 0x00},
233*4882a593Smuzhiyun {0x3600, 0xff},
234*4882a593Smuzhiyun {0x3602, 0x42},
235*4882a593Smuzhiyun {0x3603, 0x7b},
236*4882a593Smuzhiyun {0x3608, 0x9b},
237*4882a593Smuzhiyun {0x360a, 0x69},
238*4882a593Smuzhiyun {0x360b, 0x53},
239*4882a593Smuzhiyun {0x3618, 0xc0},
240*4882a593Smuzhiyun {0x361a, 0x8b},
241*4882a593Smuzhiyun {0x361d, 0x20},
242*4882a593Smuzhiyun {0x361e, 0x30},
243*4882a593Smuzhiyun {0x361f, 0x01},
244*4882a593Smuzhiyun {0x3620, 0x89},
245*4882a593Smuzhiyun {0x3624, 0x8f},
246*4882a593Smuzhiyun {0x3629, 0x09},
247*4882a593Smuzhiyun {0x362e, 0x50},
248*4882a593Smuzhiyun {0x3631, 0xe2},
249*4882a593Smuzhiyun {0x3632, 0xe2},
250*4882a593Smuzhiyun {0x3634, 0x10},
251*4882a593Smuzhiyun {0x3635, 0x10},
252*4882a593Smuzhiyun {0x3636, 0x10},
253*4882a593Smuzhiyun {0x3639, 0xa6},
254*4882a593Smuzhiyun {0x363a, 0xaa},
255*4882a593Smuzhiyun {0x363b, 0x0c},
256*4882a593Smuzhiyun {0x363c, 0x16},
257*4882a593Smuzhiyun {0x363d, 0x29},
258*4882a593Smuzhiyun {0x363e, 0x4f},
259*4882a593Smuzhiyun {0x3642, 0xa8},
260*4882a593Smuzhiyun {0x3652, 0x00},
261*4882a593Smuzhiyun {0x3653, 0x00},
262*4882a593Smuzhiyun {0x3654, 0x8a},
263*4882a593Smuzhiyun {0x3656, 0x0c},
264*4882a593Smuzhiyun {0x3657, 0x8e},
265*4882a593Smuzhiyun {0x3660, 0x80},
266*4882a593Smuzhiyun {0x3663, 0x00},
267*4882a593Smuzhiyun {0x3664, 0x00},
268*4882a593Smuzhiyun {0x3668, 0x05},
269*4882a593Smuzhiyun {0x3669, 0x05},
270*4882a593Smuzhiyun {0x370d, 0x10},
271*4882a593Smuzhiyun {0x370e, 0x05},
272*4882a593Smuzhiyun {0x370f, 0x10},
273*4882a593Smuzhiyun {0x3711, 0x01},
274*4882a593Smuzhiyun {0x3712, 0x09},
275*4882a593Smuzhiyun {0x3713, 0x40},
276*4882a593Smuzhiyun {0x3714, 0xe4},
277*4882a593Smuzhiyun {0x3716, 0x04},
278*4882a593Smuzhiyun {0x3717, 0x01},
279*4882a593Smuzhiyun {0x3718, 0x02},
280*4882a593Smuzhiyun {0x3719, 0x01},
281*4882a593Smuzhiyun {0x371a, 0x02},
282*4882a593Smuzhiyun {0x371b, 0x02},
283*4882a593Smuzhiyun {0x371c, 0x01},
284*4882a593Smuzhiyun {0x371d, 0x02},
285*4882a593Smuzhiyun {0x371e, 0x12},
286*4882a593Smuzhiyun {0x371f, 0x02},
287*4882a593Smuzhiyun {0x3720, 0x14},
288*4882a593Smuzhiyun {0x3721, 0x12},
289*4882a593Smuzhiyun {0x3722, 0x44},
290*4882a593Smuzhiyun {0x3723, 0x60},
291*4882a593Smuzhiyun {0x372f, 0x34},
292*4882a593Smuzhiyun {0x3726, 0x21},
293*4882a593Smuzhiyun {0x37d0, 0x02},
294*4882a593Smuzhiyun {0x37d1, 0x10},
295*4882a593Smuzhiyun {0x37db, 0x08},
296*4882a593Smuzhiyun {0x3808, 0x12},
297*4882a593Smuzhiyun {0x3809, 0x30},
298*4882a593Smuzhiyun {0x380a, 0x0d},
299*4882a593Smuzhiyun {0x380b, 0xa8},
300*4882a593Smuzhiyun {0x380c, 0x03},
301*4882a593Smuzhiyun {0x380d, 0x52},
302*4882a593Smuzhiyun {0x380e, 0x0f},
303*4882a593Smuzhiyun {0x380f, 0x51},
304*4882a593Smuzhiyun {0x3814, 0x11},
305*4882a593Smuzhiyun {0x3815, 0x11},
306*4882a593Smuzhiyun {0x3820, 0x00},
307*4882a593Smuzhiyun {0x3821, 0x06},
308*4882a593Smuzhiyun {0x3822, 0x00},
309*4882a593Smuzhiyun {0x3823, 0x04},
310*4882a593Smuzhiyun {0x3837, 0x10},
311*4882a593Smuzhiyun {0x383c, 0x34},
312*4882a593Smuzhiyun {0x383d, 0xff},
313*4882a593Smuzhiyun {0x383e, 0x0d},
314*4882a593Smuzhiyun {0x383f, 0x22},
315*4882a593Smuzhiyun {0x3857, 0x00},
316*4882a593Smuzhiyun {0x388f, 0x00},
317*4882a593Smuzhiyun {0x3890, 0x00},
318*4882a593Smuzhiyun {0x3891, 0x00},
319*4882a593Smuzhiyun {0x3d81, 0x10},
320*4882a593Smuzhiyun {0x3d83, 0x0c},
321*4882a593Smuzhiyun {0x3d84, 0x00},
322*4882a593Smuzhiyun {0x3d85, 0x1b},
323*4882a593Smuzhiyun {0x3d88, 0x00},
324*4882a593Smuzhiyun {0x3d89, 0x00},
325*4882a593Smuzhiyun {0x3d8a, 0x00},
326*4882a593Smuzhiyun {0x3d8b, 0x01},
327*4882a593Smuzhiyun {0x3d8c, 0x77},
328*4882a593Smuzhiyun {0x3d8d, 0xa0},
329*4882a593Smuzhiyun {0x3f00, 0x02},
330*4882a593Smuzhiyun {0x3f0c, 0x07},
331*4882a593Smuzhiyun {0x3f0d, 0x2f},
332*4882a593Smuzhiyun {0x4012, 0x0d},
333*4882a593Smuzhiyun {0x4015, 0x04},
334*4882a593Smuzhiyun {0x4016, 0x1b},
335*4882a593Smuzhiyun {0x4017, 0x04},
336*4882a593Smuzhiyun {0x4018, 0x0b},
337*4882a593Smuzhiyun {0x401b, 0x1f},
338*4882a593Smuzhiyun {0x401e, 0x01},
339*4882a593Smuzhiyun {0x401f, 0x38},
340*4882a593Smuzhiyun {0x4500, 0x20},
341*4882a593Smuzhiyun {0x4501, 0x6a},
342*4882a593Smuzhiyun {0x4502, 0xb4},
343*4882a593Smuzhiyun {0x4586, 0x00},
344*4882a593Smuzhiyun {0x4588, 0x02},
345*4882a593Smuzhiyun {0x4640, 0x01},
346*4882a593Smuzhiyun {0x4641, 0x04},
347*4882a593Smuzhiyun {0x4643, 0x00},
348*4882a593Smuzhiyun {0x4645, 0x03},
349*4882a593Smuzhiyun {0x4806, 0x40},
350*4882a593Smuzhiyun {0x480e, 0x00},
351*4882a593Smuzhiyun {0x4815, 0x2b},
352*4882a593Smuzhiyun {0x481b, 0x3c},
353*4882a593Smuzhiyun {0x4833, 0x18},
354*4882a593Smuzhiyun {0x4837, 0x08},
355*4882a593Smuzhiyun {0x484b, 0x07},
356*4882a593Smuzhiyun {0x4850, 0x41},
357*4882a593Smuzhiyun {0x4860, 0x00},
358*4882a593Smuzhiyun {0x4861, 0xec},
359*4882a593Smuzhiyun {0x4864, 0x00},
360*4882a593Smuzhiyun {0x4883, 0x00},
361*4882a593Smuzhiyun {0x4888, 0x10},
362*4882a593Smuzhiyun {0x4a00, 0x10},
363*4882a593Smuzhiyun {0x4e00, 0x00},
364*4882a593Smuzhiyun {0x4e01, 0x04},
365*4882a593Smuzhiyun {0x4e02, 0x01},
366*4882a593Smuzhiyun {0x4e03, 0x00},
367*4882a593Smuzhiyun {0x4e04, 0x08},
368*4882a593Smuzhiyun {0x4e05, 0x04},
369*4882a593Smuzhiyun {0x4e06, 0x00},
370*4882a593Smuzhiyun {0x4e07, 0x13},
371*4882a593Smuzhiyun {0x4e08, 0x01},
372*4882a593Smuzhiyun {0x4e09, 0x00},
373*4882a593Smuzhiyun {0x4e0a, 0x15},
374*4882a593Smuzhiyun {0x4e0b, 0x0e},
375*4882a593Smuzhiyun {0x4e0c, 0x00},
376*4882a593Smuzhiyun {0x4e0d, 0x17},
377*4882a593Smuzhiyun {0x4e0e, 0x07},
378*4882a593Smuzhiyun {0x4e0f, 0x00},
379*4882a593Smuzhiyun {0x4e10, 0x19},
380*4882a593Smuzhiyun {0x4e11, 0x06},
381*4882a593Smuzhiyun {0x4e12, 0x00},
382*4882a593Smuzhiyun {0x4e13, 0x1b},
383*4882a593Smuzhiyun {0x4e14, 0x08},
384*4882a593Smuzhiyun {0x4e15, 0x00},
385*4882a593Smuzhiyun {0x4e16, 0x1f},
386*4882a593Smuzhiyun {0x4e17, 0x08},
387*4882a593Smuzhiyun {0x4e18, 0x00},
388*4882a593Smuzhiyun {0x4e19, 0x21},
389*4882a593Smuzhiyun {0x4e1a, 0x0e},
390*4882a593Smuzhiyun {0x4e1b, 0x00},
391*4882a593Smuzhiyun {0x4e1c, 0x2d},
392*4882a593Smuzhiyun {0x4e1d, 0x30},
393*4882a593Smuzhiyun {0x4e1e, 0x00},
394*4882a593Smuzhiyun {0x4e1f, 0x6a},
395*4882a593Smuzhiyun {0x4e20, 0x05},
396*4882a593Smuzhiyun {0x4e21, 0x00},
397*4882a593Smuzhiyun {0x4e22, 0x6c},
398*4882a593Smuzhiyun {0x4e23, 0x05},
399*4882a593Smuzhiyun {0x4e24, 0x00},
400*4882a593Smuzhiyun {0x4e25, 0x6e},
401*4882a593Smuzhiyun {0x4e26, 0x39},
402*4882a593Smuzhiyun {0x4e27, 0x00},
403*4882a593Smuzhiyun {0x4e28, 0x7a},
404*4882a593Smuzhiyun {0x4e29, 0x6d},
405*4882a593Smuzhiyun {0x4e2a, 0x00},
406*4882a593Smuzhiyun {0x4e2b, 0x00},
407*4882a593Smuzhiyun {0x4e2c, 0x00},
408*4882a593Smuzhiyun {0x4e2d, 0x00},
409*4882a593Smuzhiyun {0x4e2e, 0x00},
410*4882a593Smuzhiyun {0x4e2f, 0x00},
411*4882a593Smuzhiyun {0x4e30, 0x00},
412*4882a593Smuzhiyun {0x4e31, 0x00},
413*4882a593Smuzhiyun {0x4e32, 0x00},
414*4882a593Smuzhiyun {0x4e33, 0x00},
415*4882a593Smuzhiyun {0x4e34, 0x00},
416*4882a593Smuzhiyun {0x4e35, 0x00},
417*4882a593Smuzhiyun {0x4e36, 0x00},
418*4882a593Smuzhiyun {0x4e37, 0x00},
419*4882a593Smuzhiyun {0x4e38, 0x00},
420*4882a593Smuzhiyun {0x4e39, 0x00},
421*4882a593Smuzhiyun {0x4e3a, 0x00},
422*4882a593Smuzhiyun {0x4e3b, 0x00},
423*4882a593Smuzhiyun {0x4e3c, 0x00},
424*4882a593Smuzhiyun {0x4e3d, 0x00},
425*4882a593Smuzhiyun {0x4e3e, 0x00},
426*4882a593Smuzhiyun {0x4e3f, 0x00},
427*4882a593Smuzhiyun {0x4e40, 0x00},
428*4882a593Smuzhiyun {0x4e41, 0x00},
429*4882a593Smuzhiyun {0x4e42, 0x00},
430*4882a593Smuzhiyun {0x4e43, 0x00},
431*4882a593Smuzhiyun {0x4e44, 0x00},
432*4882a593Smuzhiyun {0x4e45, 0x00},
433*4882a593Smuzhiyun {0x4e46, 0x00},
434*4882a593Smuzhiyun {0x4e47, 0x00},
435*4882a593Smuzhiyun {0x4e48, 0x00},
436*4882a593Smuzhiyun {0x4e49, 0x00},
437*4882a593Smuzhiyun {0x4e4a, 0x00},
438*4882a593Smuzhiyun {0x4e4b, 0x00},
439*4882a593Smuzhiyun {0x4e4c, 0x00},
440*4882a593Smuzhiyun {0x4e4d, 0x00},
441*4882a593Smuzhiyun {0x4e4e, 0x00},
442*4882a593Smuzhiyun {0x4e4f, 0x00},
443*4882a593Smuzhiyun {0x4e50, 0x00},
444*4882a593Smuzhiyun {0x4e51, 0x00},
445*4882a593Smuzhiyun {0x4e52, 0x00},
446*4882a593Smuzhiyun {0x4e53, 0x00},
447*4882a593Smuzhiyun {0x4e54, 0x00},
448*4882a593Smuzhiyun {0x4e55, 0x00},
449*4882a593Smuzhiyun {0x4e56, 0x00},
450*4882a593Smuzhiyun {0x4e57, 0x00},
451*4882a593Smuzhiyun {0x4e58, 0x00},
452*4882a593Smuzhiyun {0x4e59, 0x00},
453*4882a593Smuzhiyun {0x4e5a, 0x00},
454*4882a593Smuzhiyun {0x4e5b, 0x00},
455*4882a593Smuzhiyun {0x4e5c, 0x00},
456*4882a593Smuzhiyun {0x4e5d, 0x00},
457*4882a593Smuzhiyun {0x4e5e, 0x00},
458*4882a593Smuzhiyun {0x4e5f, 0x00},
459*4882a593Smuzhiyun {0x4e60, 0x00},
460*4882a593Smuzhiyun {0x4e61, 0x00},
461*4882a593Smuzhiyun {0x4e62, 0x00},
462*4882a593Smuzhiyun {0x4e63, 0x00},
463*4882a593Smuzhiyun {0x4e64, 0x00},
464*4882a593Smuzhiyun {0x4e65, 0x00},
465*4882a593Smuzhiyun {0x4e66, 0x00},
466*4882a593Smuzhiyun {0x4e67, 0x00},
467*4882a593Smuzhiyun {0x4e68, 0x00},
468*4882a593Smuzhiyun {0x4e69, 0x00},
469*4882a593Smuzhiyun {0x4e6a, 0x00},
470*4882a593Smuzhiyun {0x4e6b, 0x00},
471*4882a593Smuzhiyun {0x4e6c, 0x00},
472*4882a593Smuzhiyun {0x4e6d, 0x00},
473*4882a593Smuzhiyun {0x4e6e, 0x00},
474*4882a593Smuzhiyun {0x4e6f, 0x00},
475*4882a593Smuzhiyun {0x4e70, 0x00},
476*4882a593Smuzhiyun {0x4e71, 0x00},
477*4882a593Smuzhiyun {0x4e72, 0x00},
478*4882a593Smuzhiyun {0x4e73, 0x00},
479*4882a593Smuzhiyun {0x4e74, 0x00},
480*4882a593Smuzhiyun {0x4e75, 0x00},
481*4882a593Smuzhiyun {0x4e76, 0x00},
482*4882a593Smuzhiyun {0x4e77, 0x00},
483*4882a593Smuzhiyun {0x4e78, 0x1c},
484*4882a593Smuzhiyun {0x4e79, 0x1e},
485*4882a593Smuzhiyun {0x4e7a, 0x00},
486*4882a593Smuzhiyun {0x4e7b, 0x00},
487*4882a593Smuzhiyun {0x4e7c, 0x2c},
488*4882a593Smuzhiyun {0x4e7d, 0x2f},
489*4882a593Smuzhiyun {0x4e7e, 0x79},
490*4882a593Smuzhiyun {0x4e7f, 0x7b},
491*4882a593Smuzhiyun {0x4e80, 0x0a},
492*4882a593Smuzhiyun {0x4e81, 0x31},
493*4882a593Smuzhiyun {0x4e82, 0x66},
494*4882a593Smuzhiyun {0x4e83, 0x81},
495*4882a593Smuzhiyun {0x4e84, 0x03},
496*4882a593Smuzhiyun {0x4e85, 0x40},
497*4882a593Smuzhiyun {0x4e86, 0x02},
498*4882a593Smuzhiyun {0x4e87, 0x09},
499*4882a593Smuzhiyun {0x4e88, 0x43},
500*4882a593Smuzhiyun {0x4e89, 0x53},
501*4882a593Smuzhiyun {0x4e8a, 0x32},
502*4882a593Smuzhiyun {0x4e8b, 0x67},
503*4882a593Smuzhiyun {0x4e8c, 0x05},
504*4882a593Smuzhiyun {0x4e8d, 0x83},
505*4882a593Smuzhiyun {0x4e8e, 0x00},
506*4882a593Smuzhiyun {0x4e8f, 0x00},
507*4882a593Smuzhiyun {0x4e90, 0x00},
508*4882a593Smuzhiyun {0x4e91, 0x00},
509*4882a593Smuzhiyun {0x4e92, 0x00},
510*4882a593Smuzhiyun {0x4e93, 0x00},
511*4882a593Smuzhiyun {0x4e94, 0x00},
512*4882a593Smuzhiyun {0x4e95, 0x00},
513*4882a593Smuzhiyun {0x4e96, 0x00},
514*4882a593Smuzhiyun {0x4e97, 0x00},
515*4882a593Smuzhiyun {0x4e98, 0x00},
516*4882a593Smuzhiyun {0x4e99, 0x00},
517*4882a593Smuzhiyun {0x4e9a, 0x00},
518*4882a593Smuzhiyun {0x4e9b, 0x00},
519*4882a593Smuzhiyun {0x4e9c, 0x00},
520*4882a593Smuzhiyun {0x4e9d, 0x00},
521*4882a593Smuzhiyun {0x4e9e, 0x00},
522*4882a593Smuzhiyun {0x4e9f, 0x00},
523*4882a593Smuzhiyun {0x4ea0, 0x00},
524*4882a593Smuzhiyun {0x4ea1, 0x00},
525*4882a593Smuzhiyun {0x4ea2, 0x00},
526*4882a593Smuzhiyun {0x4ea3, 0x00},
527*4882a593Smuzhiyun {0x4ea4, 0x00},
528*4882a593Smuzhiyun {0x4ea5, 0x00},
529*4882a593Smuzhiyun {0x4ea6, 0x1e},
530*4882a593Smuzhiyun {0x4ea7, 0x20},
531*4882a593Smuzhiyun {0x4ea8, 0x32},
532*4882a593Smuzhiyun {0x4ea9, 0x6d},
533*4882a593Smuzhiyun {0x4eaa, 0x18},
534*4882a593Smuzhiyun {0x4eab, 0x7f},
535*4882a593Smuzhiyun {0x4eac, 0x00},
536*4882a593Smuzhiyun {0x4ead, 0x00},
537*4882a593Smuzhiyun {0x4eae, 0x7c},
538*4882a593Smuzhiyun {0x4eaf, 0x07},
539*4882a593Smuzhiyun {0x4eb0, 0x7c},
540*4882a593Smuzhiyun {0x4eb1, 0x07},
541*4882a593Smuzhiyun {0x4eb2, 0x07},
542*4882a593Smuzhiyun {0x4eb3, 0x1c},
543*4882a593Smuzhiyun {0x4eb4, 0x07},
544*4882a593Smuzhiyun {0x4eb5, 0x1c},
545*4882a593Smuzhiyun {0x4eb6, 0x07},
546*4882a593Smuzhiyun {0x4eb7, 0x1c},
547*4882a593Smuzhiyun {0x4eb8, 0x07},
548*4882a593Smuzhiyun {0x4eb9, 0x1c},
549*4882a593Smuzhiyun {0x4eba, 0x07},
550*4882a593Smuzhiyun {0x4ebb, 0x14},
551*4882a593Smuzhiyun {0x4ebc, 0x07},
552*4882a593Smuzhiyun {0x4ebd, 0x1c},
553*4882a593Smuzhiyun {0x4ebe, 0x07},
554*4882a593Smuzhiyun {0x4ebf, 0x1c},
555*4882a593Smuzhiyun {0x4ec0, 0x07},
556*4882a593Smuzhiyun {0x4ec1, 0x1c},
557*4882a593Smuzhiyun {0x4ec2, 0x07},
558*4882a593Smuzhiyun {0x4ec3, 0x1c},
559*4882a593Smuzhiyun {0x4ec4, 0x2c},
560*4882a593Smuzhiyun {0x4ec5, 0x2f},
561*4882a593Smuzhiyun {0x4ec6, 0x79},
562*4882a593Smuzhiyun {0x4ec7, 0x7b},
563*4882a593Smuzhiyun {0x4ec8, 0x7c},
564*4882a593Smuzhiyun {0x4ec9, 0x07},
565*4882a593Smuzhiyun {0x4eca, 0x7c},
566*4882a593Smuzhiyun {0x4ecb, 0x07},
567*4882a593Smuzhiyun {0x4ecc, 0x00},
568*4882a593Smuzhiyun {0x4ecd, 0x00},
569*4882a593Smuzhiyun {0x4ece, 0x07},
570*4882a593Smuzhiyun {0x4ecf, 0x31},
571*4882a593Smuzhiyun {0x4ed0, 0x69},
572*4882a593Smuzhiyun {0x4ed1, 0x7f},
573*4882a593Smuzhiyun {0x4ed2, 0x67},
574*4882a593Smuzhiyun {0x4ed3, 0x00},
575*4882a593Smuzhiyun {0x4ed4, 0x00},
576*4882a593Smuzhiyun {0x4ed5, 0x00},
577*4882a593Smuzhiyun {0x4ed6, 0x7c},
578*4882a593Smuzhiyun {0x4ed7, 0x07},
579*4882a593Smuzhiyun {0x4ed8, 0x7c},
580*4882a593Smuzhiyun {0x4ed9, 0x07},
581*4882a593Smuzhiyun {0x4eda, 0x33},
582*4882a593Smuzhiyun {0x4edb, 0x7f},
583*4882a593Smuzhiyun {0x4edc, 0x00},
584*4882a593Smuzhiyun {0x4edd, 0x16},
585*4882a593Smuzhiyun {0x4ede, 0x00},
586*4882a593Smuzhiyun {0x4edf, 0x00},
587*4882a593Smuzhiyun {0x4ee0, 0x32},
588*4882a593Smuzhiyun {0x4ee1, 0x70},
589*4882a593Smuzhiyun {0x4ee2, 0x01},
590*4882a593Smuzhiyun {0x4ee3, 0x30},
591*4882a593Smuzhiyun {0x4ee4, 0x22},
592*4882a593Smuzhiyun {0x4ee5, 0x28},
593*4882a593Smuzhiyun {0x4ee6, 0x6f},
594*4882a593Smuzhiyun {0x4ee7, 0x75},
595*4882a593Smuzhiyun {0x4ee8, 0x00},
596*4882a593Smuzhiyun {0x4ee9, 0x00},
597*4882a593Smuzhiyun {0x4eea, 0x30},
598*4882a593Smuzhiyun {0x4eeb, 0x7f},
599*4882a593Smuzhiyun {0x4eec, 0x00},
600*4882a593Smuzhiyun {0x4eed, 0x00},
601*4882a593Smuzhiyun {0x4eee, 0x00},
602*4882a593Smuzhiyun {0x4eef, 0x00},
603*4882a593Smuzhiyun {0x4ef0, 0x69},
604*4882a593Smuzhiyun {0x4ef1, 0x7f},
605*4882a593Smuzhiyun {0x4ef2, 0x07},
606*4882a593Smuzhiyun {0x4ef3, 0x30},
607*4882a593Smuzhiyun {0x4ef4, 0x32},
608*4882a593Smuzhiyun {0x4ef5, 0x09},
609*4882a593Smuzhiyun {0x4ef6, 0x7d},
610*4882a593Smuzhiyun {0x4ef7, 0x65},
611*4882a593Smuzhiyun {0x4ef8, 0x00},
612*4882a593Smuzhiyun {0x4ef9, 0x00},
613*4882a593Smuzhiyun {0x4efa, 0x00},
614*4882a593Smuzhiyun {0x4efb, 0x00},
615*4882a593Smuzhiyun {0x4efc, 0x7f},
616*4882a593Smuzhiyun {0x4efd, 0x09},
617*4882a593Smuzhiyun {0x4efe, 0x7f},
618*4882a593Smuzhiyun {0x4eff, 0x09},
619*4882a593Smuzhiyun {0x4f00, 0x1e},
620*4882a593Smuzhiyun {0x4f01, 0x7c},
621*4882a593Smuzhiyun {0x4f02, 0x7f},
622*4882a593Smuzhiyun {0x4f03, 0x09},
623*4882a593Smuzhiyun {0x4f04, 0x7f},
624*4882a593Smuzhiyun {0x4f05, 0x0b},
625*4882a593Smuzhiyun {0x4f06, 0x7c},
626*4882a593Smuzhiyun {0x4f07, 0x02},
627*4882a593Smuzhiyun {0x4f08, 0x7c},
628*4882a593Smuzhiyun {0x4f09, 0x02},
629*4882a593Smuzhiyun {0x4f0a, 0x32},
630*4882a593Smuzhiyun {0x4f0b, 0x64},
631*4882a593Smuzhiyun {0x4f0c, 0x32},
632*4882a593Smuzhiyun {0x4f0d, 0x64},
633*4882a593Smuzhiyun {0x4f0e, 0x32},
634*4882a593Smuzhiyun {0x4f0f, 0x64},
635*4882a593Smuzhiyun {0x4f10, 0x32},
636*4882a593Smuzhiyun {0x4f11, 0x64},
637*4882a593Smuzhiyun {0x4f12, 0x31},
638*4882a593Smuzhiyun {0x4f13, 0x4f},
639*4882a593Smuzhiyun {0x4f14, 0x83},
640*4882a593Smuzhiyun {0x4f15, 0x84},
641*4882a593Smuzhiyun {0x4f16, 0x63},
642*4882a593Smuzhiyun {0x4f17, 0x64},
643*4882a593Smuzhiyun {0x4f18, 0x83},
644*4882a593Smuzhiyun {0x4f19, 0x84},
645*4882a593Smuzhiyun {0x4f1a, 0x31},
646*4882a593Smuzhiyun {0x4f1b, 0x32},
647*4882a593Smuzhiyun {0x4f1c, 0x7b},
648*4882a593Smuzhiyun {0x4f1d, 0x7c},
649*4882a593Smuzhiyun {0x4f1e, 0x2f},
650*4882a593Smuzhiyun {0x4f1f, 0x30},
651*4882a593Smuzhiyun {0x4f20, 0x30},
652*4882a593Smuzhiyun {0x4f21, 0x69},
653*4882a593Smuzhiyun {0x4d06, 0x08},
654*4882a593Smuzhiyun {0x5000, 0x01},
655*4882a593Smuzhiyun {0x5001, 0x40},
656*4882a593Smuzhiyun {0x5002, 0x53},
657*4882a593Smuzhiyun {0x5003, 0x42},
658*4882a593Smuzhiyun {0x5004, 0x08},
659*4882a593Smuzhiyun {0x5005, 0x00},
660*4882a593Smuzhiyun {0x5012, 0x60},
661*4882a593Smuzhiyun {0x5038, 0x00},
662*4882a593Smuzhiyun {0x5081, 0x00},
663*4882a593Smuzhiyun {0x5180, 0x00},
664*4882a593Smuzhiyun {0x5181, 0x10},
665*4882a593Smuzhiyun {0x5182, 0x07},
666*4882a593Smuzhiyun {0x5183, 0x8f},
667*4882a593Smuzhiyun {0x5184, 0x03},
668*4882a593Smuzhiyun {0x5208, 0xC2},
669*4882a593Smuzhiyun {0x5820, 0xc5},
670*4882a593Smuzhiyun {0x5854, 0x00},
671*4882a593Smuzhiyun {0x58cb, 0x03},
672*4882a593Smuzhiyun {0x5bd0, 0x15},
673*4882a593Smuzhiyun {0x5bd1, 0x02},
674*4882a593Smuzhiyun {0x5c0e, 0x11},
675*4882a593Smuzhiyun {0x5c11, 0x00},
676*4882a593Smuzhiyun {0x5c16, 0x02},
677*4882a593Smuzhiyun {0x5c17, 0x01},
678*4882a593Smuzhiyun {0x5c1a, 0x04},
679*4882a593Smuzhiyun {0x5c1b, 0x03},
680*4882a593Smuzhiyun {0x5c21, 0x10},
681*4882a593Smuzhiyun {0x5c22, 0x10},
682*4882a593Smuzhiyun {0x5c23, 0x04},
683*4882a593Smuzhiyun {0x5c24, 0x0c},
684*4882a593Smuzhiyun {0x5c25, 0x04},
685*4882a593Smuzhiyun {0x5c26, 0x0c},
686*4882a593Smuzhiyun {0x5c27, 0x04},
687*4882a593Smuzhiyun {0x5c28, 0x0c},
688*4882a593Smuzhiyun {0x5c29, 0x04},
689*4882a593Smuzhiyun {0x5c2a, 0x0c},
690*4882a593Smuzhiyun {0x5c2b, 0x01},
691*4882a593Smuzhiyun {0x5c2c, 0x01},
692*4882a593Smuzhiyun {0x5c2e, 0x08},
693*4882a593Smuzhiyun {0x5c30, 0x04},
694*4882a593Smuzhiyun {0x5c35, 0x03},
695*4882a593Smuzhiyun {0x5c36, 0x03},
696*4882a593Smuzhiyun {0x5c37, 0x03},
697*4882a593Smuzhiyun {0x5c38, 0x03},
698*4882a593Smuzhiyun {0x5d00, 0xff},
699*4882a593Smuzhiyun {0x5d01, 0x0f},
700*4882a593Smuzhiyun {0x5d02, 0x80},
701*4882a593Smuzhiyun {0x5d03, 0x44},
702*4882a593Smuzhiyun {0x5d05, 0xfc},
703*4882a593Smuzhiyun {0x5d06, 0x0b},
704*4882a593Smuzhiyun {0x5d08, 0x10},
705*4882a593Smuzhiyun {0x5d09, 0x10},
706*4882a593Smuzhiyun {0x5d0a, 0x04},
707*4882a593Smuzhiyun {0x5d0b, 0x0c},
708*4882a593Smuzhiyun {0x5d0c, 0x04},
709*4882a593Smuzhiyun {0x5d0d, 0x0c},
710*4882a593Smuzhiyun {0x5d0e, 0x04},
711*4882a593Smuzhiyun {0x5d0f, 0x0c},
712*4882a593Smuzhiyun {0x5d10, 0x04},
713*4882a593Smuzhiyun {0x5d11, 0x0c},
714*4882a593Smuzhiyun {0x5d12, 0x01},
715*4882a593Smuzhiyun {0x5d13, 0x01},
716*4882a593Smuzhiyun {0x5d15, 0x10},
717*4882a593Smuzhiyun {0x5d16, 0x10},
718*4882a593Smuzhiyun {0x5d17, 0x10},
719*4882a593Smuzhiyun {0x5d18, 0x10},
720*4882a593Smuzhiyun {0x5d1a, 0x10},
721*4882a593Smuzhiyun {0x5d1b, 0x10},
722*4882a593Smuzhiyun {0x5d1c, 0x10},
723*4882a593Smuzhiyun {0x5d1d, 0x10},
724*4882a593Smuzhiyun {0x5d1e, 0x04},
725*4882a593Smuzhiyun {0x5d1f, 0x04},
726*4882a593Smuzhiyun {0x5d20, 0x04},
727*4882a593Smuzhiyun {0x5d27, 0x64},
728*4882a593Smuzhiyun {0x5d28, 0xc8},
729*4882a593Smuzhiyun {0x5d29, 0x96},
730*4882a593Smuzhiyun {0x5d2a, 0xff},
731*4882a593Smuzhiyun {0x5d2b, 0xc8},
732*4882a593Smuzhiyun {0x5d2c, 0xff},
733*4882a593Smuzhiyun {0x5d2d, 0x04},
734*4882a593Smuzhiyun {0x5d34, 0x00},
735*4882a593Smuzhiyun {0x5d35, 0x08},
736*4882a593Smuzhiyun {0x5d36, 0x00},
737*4882a593Smuzhiyun {0x5d37, 0x04},
738*4882a593Smuzhiyun {0x5d4a, 0x00},
739*4882a593Smuzhiyun {0x5d4c, 0x00},
740*4882a593Smuzhiyun {REG_NULL, 0x00},
741*4882a593Smuzhiyun };
742*4882a593Smuzhiyun
743*4882a593Smuzhiyun /*
744*4882a593Smuzhiyun * Xclk 24Mhz
745*4882a593Smuzhiyun * max_framerate 30fps
746*4882a593Smuzhiyun */
747*4882a593Smuzhiyun static const struct regval ov16a1q_4656x3496_30fps_regs[] = {
748*4882a593Smuzhiyun {0x0100, 0x00},
749*4882a593Smuzhiyun {0x0305, 0x6b},
750*4882a593Smuzhiyun {0x0307, 0x00},
751*4882a593Smuzhiyun {0x4837, 0x0b},
752*4882a593Smuzhiyun {0x0329, 0x01},
753*4882a593Smuzhiyun {0x0344, 0x01},
754*4882a593Smuzhiyun {0x0345, 0x2c},
755*4882a593Smuzhiyun {0x034a, 0x07},
756*4882a593Smuzhiyun {0x3608, 0x9b},
757*4882a593Smuzhiyun {0x360a, 0x69},
758*4882a593Smuzhiyun {0x361a, 0x8b},
759*4882a593Smuzhiyun {0x361e, 0x30},
760*4882a593Smuzhiyun {0x3639, 0xa6},
761*4882a593Smuzhiyun {0x363a, 0xaa},
762*4882a593Smuzhiyun {0x3642, 0xa8},
763*4882a593Smuzhiyun {0x3654, 0x8a},
764*4882a593Smuzhiyun {0x3656, 0x0c},
765*4882a593Smuzhiyun {0x3663, 0x00},
766*4882a593Smuzhiyun {0x370e, 0x05},
767*4882a593Smuzhiyun {0x3712, 0x09},
768*4882a593Smuzhiyun {0x3713, 0x40},
769*4882a593Smuzhiyun {0x3714, 0xe4},
770*4882a593Smuzhiyun {0x37d0, 0x02},
771*4882a593Smuzhiyun {0x37d1, 0x10},
772*4882a593Smuzhiyun {0x37db, 0x08},
773*4882a593Smuzhiyun {0x3808, 0x12},
774*4882a593Smuzhiyun {0x3809, 0x30},
775*4882a593Smuzhiyun {0x380a, 0x0d},
776*4882a593Smuzhiyun {0x380b, 0xa8},
777*4882a593Smuzhiyun {0x380c, 0x03},
778*4882a593Smuzhiyun {0x380d, 0x52},
779*4882a593Smuzhiyun {0x380e, 0x0f},
780*4882a593Smuzhiyun {0x380f, 0x50},
781*4882a593Smuzhiyun {0x3814, 0x11},
782*4882a593Smuzhiyun {0x3815, 0x11},
783*4882a593Smuzhiyun {0x3820, 0x00},
784*4882a593Smuzhiyun {0x3821, 0x06},
785*4882a593Smuzhiyun {0x3822, 0x00},
786*4882a593Smuzhiyun {0x383c, 0x34},
787*4882a593Smuzhiyun {0x383f, 0x22},
788*4882a593Smuzhiyun {0x4015, 0x04},
789*4882a593Smuzhiyun {0x4016, 0x1b},
790*4882a593Smuzhiyun {0x4017, 0x04},
791*4882a593Smuzhiyun {0x4018, 0x0b},
792*4882a593Smuzhiyun {0x401b, 0x1f},
793*4882a593Smuzhiyun {0x401f, 0x38},
794*4882a593Smuzhiyun {0x4500, 0x20},
795*4882a593Smuzhiyun {0x4501, 0x6a},
796*4882a593Smuzhiyun {0x4502, 0xb4},
797*4882a593Smuzhiyun {0x4e05, 0x04},
798*4882a593Smuzhiyun {0x4e11, 0x06},
799*4882a593Smuzhiyun {0x4e1d, 0x30},
800*4882a593Smuzhiyun {0x4e26, 0x39},
801*4882a593Smuzhiyun {0x4e29, 0x6d},
802*4882a593Smuzhiyun {0x5000, 0x01},
803*4882a593Smuzhiyun {0x5001, 0x40},
804*4882a593Smuzhiyun {0x5003, 0x42},
805*4882a593Smuzhiyun {0x5820, 0xc5},
806*4882a593Smuzhiyun {0x5854, 0x00},
807*4882a593Smuzhiyun {0x5bd0, 0x15},
808*4882a593Smuzhiyun {0x5c0e, 0x11},
809*4882a593Smuzhiyun {0x5c11, 0x00},
810*4882a593Smuzhiyun {0x5c16, 0x02},
811*4882a593Smuzhiyun {0x5c17, 0x01},
812*4882a593Smuzhiyun {0x5c1a, 0x04},
813*4882a593Smuzhiyun {0x5c1b, 0x03},
814*4882a593Smuzhiyun {0x5c21, 0x10},
815*4882a593Smuzhiyun {0x5c22, 0x10},
816*4882a593Smuzhiyun {0x5c23, 0x04},
817*4882a593Smuzhiyun {0x5c24, 0x0c},
818*4882a593Smuzhiyun {0x5c25, 0x04},
819*4882a593Smuzhiyun {0x5c26, 0x0c},
820*4882a593Smuzhiyun {0x5c27, 0x04},
821*4882a593Smuzhiyun {0x5c28, 0x0c},
822*4882a593Smuzhiyun {0x5c29, 0x04},
823*4882a593Smuzhiyun {0x5c2a, 0x0c},
824*4882a593Smuzhiyun {0x5c2b, 0x01},
825*4882a593Smuzhiyun {0x5c2c, 0x01},
826*4882a593Smuzhiyun {0x5d01, 0x0f},
827*4882a593Smuzhiyun {0x5d08, 0x10},
828*4882a593Smuzhiyun {0x5d09, 0x10},
829*4882a593Smuzhiyun {0x5d0a, 0x04},
830*4882a593Smuzhiyun {0x5d0b, 0x0c},
831*4882a593Smuzhiyun {0x5d0c, 0x04},
832*4882a593Smuzhiyun {0x5d0d, 0x0c},
833*4882a593Smuzhiyun {0x5d0e, 0x04},
834*4882a593Smuzhiyun {0x5d0f, 0x0c},
835*4882a593Smuzhiyun {0x5d10, 0x04},
836*4882a593Smuzhiyun {0x5d11, 0x0c},
837*4882a593Smuzhiyun {0x5d12, 0x01},
838*4882a593Smuzhiyun {0x5d13, 0x01},
839*4882a593Smuzhiyun {0x3500, 0x00},
840*4882a593Smuzhiyun {0x3501, 0x0f},
841*4882a593Smuzhiyun {0x3502, 0x48},
842*4882a593Smuzhiyun {0x3508, 0x01},
843*4882a593Smuzhiyun {0x3509, 0x00},
844*4882a593Smuzhiyun {0x0100, 0x01},
845*4882a593Smuzhiyun {REG_NULL, 0x00},
846*4882a593Smuzhiyun };
847*4882a593Smuzhiyun
848*4882a593Smuzhiyun static const struct regval ov16a1q_2328x1748_30fps_regs[] = {
849*4882a593Smuzhiyun {0x0100, 0x00},
850*4882a593Smuzhiyun {0x0305, 0x7a},
851*4882a593Smuzhiyun {0x0307, 0x01},
852*4882a593Smuzhiyun {0x4837, 0x15},
853*4882a593Smuzhiyun {0x0329, 0x01},
854*4882a593Smuzhiyun {0x0344, 0x01},
855*4882a593Smuzhiyun {0x0345, 0x2c},
856*4882a593Smuzhiyun {0x034a, 0x07},
857*4882a593Smuzhiyun {0x3608, 0x75},
858*4882a593Smuzhiyun {0x360a, 0x69},
859*4882a593Smuzhiyun {0x361a, 0x8b},
860*4882a593Smuzhiyun {0x361e, 0x30},
861*4882a593Smuzhiyun {0x3639, 0x93},
862*4882a593Smuzhiyun {0x363a, 0x99},
863*4882a593Smuzhiyun {0x3642, 0x98},
864*4882a593Smuzhiyun {0x3654, 0x8a},
865*4882a593Smuzhiyun {0x3656, 0x0c},
866*4882a593Smuzhiyun {0x3663, 0x00},
867*4882a593Smuzhiyun {0x370e, 0x05},
868*4882a593Smuzhiyun {0x3712, 0x08},
869*4882a593Smuzhiyun {0x3713, 0xc0},
870*4882a593Smuzhiyun {0x3714, 0xe2},
871*4882a593Smuzhiyun {0x37d0, 0x02},
872*4882a593Smuzhiyun {0x37d1, 0x10},
873*4882a593Smuzhiyun {0x37db, 0x04},
874*4882a593Smuzhiyun {0x3808, 0x09},
875*4882a593Smuzhiyun {0x3809, 0x18},
876*4882a593Smuzhiyun {0x380a, 0x06},
877*4882a593Smuzhiyun {0x380b, 0xd4},
878*4882a593Smuzhiyun {0x380c, 0x03},
879*4882a593Smuzhiyun {0x380d, 0x52},
880*4882a593Smuzhiyun {0x380e, 0x0f},
881*4882a593Smuzhiyun {0x380f, 0x50},
882*4882a593Smuzhiyun {0x3814, 0x22},
883*4882a593Smuzhiyun {0x3815, 0x22},
884*4882a593Smuzhiyun {0x3820, 0x01},
885*4882a593Smuzhiyun {0x3821, 0x0c},
886*4882a593Smuzhiyun {0x3822, 0x00},
887*4882a593Smuzhiyun {0x383c, 0x22},
888*4882a593Smuzhiyun {0x383f, 0x33},
889*4882a593Smuzhiyun {0x4015, 0x02},
890*4882a593Smuzhiyun {0x4016, 0x0d},
891*4882a593Smuzhiyun {0x4017, 0x00},
892*4882a593Smuzhiyun {0x4018, 0x07},
893*4882a593Smuzhiyun {0x401b, 0x1f},
894*4882a593Smuzhiyun {0x401f, 0xfe},
895*4882a593Smuzhiyun {0x4500, 0x20},
896*4882a593Smuzhiyun {0x4501, 0x6a},
897*4882a593Smuzhiyun {0x4502, 0xe4},
898*4882a593Smuzhiyun {0x4e05, 0x04},
899*4882a593Smuzhiyun {0x4e11, 0x06},
900*4882a593Smuzhiyun {0x4e1d, 0x25},
901*4882a593Smuzhiyun {0x4e26, 0x44},
902*4882a593Smuzhiyun {0x4e29, 0x6d},
903*4882a593Smuzhiyun {0x5000, 0x09},
904*4882a593Smuzhiyun {0x5001, 0x42},
905*4882a593Smuzhiyun {0x5003, 0x42},
906*4882a593Smuzhiyun {0x5820, 0xc5},
907*4882a593Smuzhiyun {0x5854, 0x00},
908*4882a593Smuzhiyun {0x5bd0, 0x19},
909*4882a593Smuzhiyun {0x5c0e, 0x13},
910*4882a593Smuzhiyun {0x5c11, 0x00},
911*4882a593Smuzhiyun {0x5c16, 0x01},
912*4882a593Smuzhiyun {0x5c17, 0x00},
913*4882a593Smuzhiyun {0x5c1a, 0x00},
914*4882a593Smuzhiyun {0x5c1b, 0x00},
915*4882a593Smuzhiyun {0x5c21, 0x08},
916*4882a593Smuzhiyun {0x5c22, 0x08},
917*4882a593Smuzhiyun {0x5c23, 0x02},
918*4882a593Smuzhiyun {0x5c24, 0x06},
919*4882a593Smuzhiyun {0x5c25, 0x02},
920*4882a593Smuzhiyun {0x5c26, 0x06},
921*4882a593Smuzhiyun {0x5c27, 0x02},
922*4882a593Smuzhiyun {0x5c28, 0x06},
923*4882a593Smuzhiyun {0x5c29, 0x02},
924*4882a593Smuzhiyun {0x5c2a, 0x06},
925*4882a593Smuzhiyun {0x5c2b, 0x00},
926*4882a593Smuzhiyun {0x5c2c, 0x00},
927*4882a593Smuzhiyun {0x5d01, 0x07},
928*4882a593Smuzhiyun {0x5d08, 0x08},
929*4882a593Smuzhiyun {0x5d09, 0x08},
930*4882a593Smuzhiyun {0x5d0a, 0x02},
931*4882a593Smuzhiyun {0x5d0b, 0x06},
932*4882a593Smuzhiyun {0x5d0c, 0x02},
933*4882a593Smuzhiyun {0x5d0d, 0x06},
934*4882a593Smuzhiyun {0x5d0e, 0x02},
935*4882a593Smuzhiyun {0x5d0f, 0x06},
936*4882a593Smuzhiyun {0x5d10, 0x02},
937*4882a593Smuzhiyun {0x5d11, 0x06},
938*4882a593Smuzhiyun {0x5d12, 0x00},
939*4882a593Smuzhiyun {0x5d13, 0x00},
940*4882a593Smuzhiyun {0x3500, 0x00},
941*4882a593Smuzhiyun {0x3501, 0x0f},
942*4882a593Smuzhiyun {0x3502, 0x48},
943*4882a593Smuzhiyun {0x3508, 0x01},
944*4882a593Smuzhiyun {0x3509, 0x00},
945*4882a593Smuzhiyun {0x0100, 0x01},
946*4882a593Smuzhiyun //{0x0100, 0x01},
947*4882a593Smuzhiyun {REG_NULL, 0x00},
948*4882a593Smuzhiyun };
949*4882a593Smuzhiyun
950*4882a593Smuzhiyun static const struct ov16a1q_mode supported_modes[] = {
951*4882a593Smuzhiyun {
952*4882a593Smuzhiyun .width = 4656,
953*4882a593Smuzhiyun .height = 3496,
954*4882a593Smuzhiyun .max_fps = {
955*4882a593Smuzhiyun .numerator = 10000,
956*4882a593Smuzhiyun .denominator = 300000,
957*4882a593Smuzhiyun },
958*4882a593Smuzhiyun .exp_def = 0x0f4a,
959*4882a593Smuzhiyun .hts_def = 0x0352 * 6,
960*4882a593Smuzhiyun .vts_def = 0x0f51,
961*4882a593Smuzhiyun .bpp = 10,
962*4882a593Smuzhiyun .reg_list = ov16a1q_4656x3496_30fps_regs,
963*4882a593Smuzhiyun .link_freq_idx = 0,
964*4882a593Smuzhiyun .hdr_mode = NO_HDR,
965*4882a593Smuzhiyun .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
966*4882a593Smuzhiyun },
967*4882a593Smuzhiyun {
968*4882a593Smuzhiyun .width = 2328,
969*4882a593Smuzhiyun .height = 1748,
970*4882a593Smuzhiyun .max_fps = {
971*4882a593Smuzhiyun .numerator = 10000,
972*4882a593Smuzhiyun .denominator = 300000,
973*4882a593Smuzhiyun },
974*4882a593Smuzhiyun .exp_def = 0x0f4a,
975*4882a593Smuzhiyun .hts_def = 0x0352 * 3,
976*4882a593Smuzhiyun .vts_def = 0x0f50,
977*4882a593Smuzhiyun .bpp = 10,
978*4882a593Smuzhiyun .reg_list = ov16a1q_2328x1748_30fps_regs,
979*4882a593Smuzhiyun .link_freq_idx = 1,
980*4882a593Smuzhiyun .hdr_mode = NO_HDR,
981*4882a593Smuzhiyun .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0,
982*4882a593Smuzhiyun },
983*4882a593Smuzhiyun };
984*4882a593Smuzhiyun
985*4882a593Smuzhiyun static const s64 link_freq_items[] = {
986*4882a593Smuzhiyun OV16A1Q_LINK_FREQ_726MHZ,
987*4882a593Smuzhiyun OV16A1Q_LINK_FREQ_378MHZ,
988*4882a593Smuzhiyun };
989*4882a593Smuzhiyun
990*4882a593Smuzhiyun static const char * const ov16a1q_test_pattern_menu[] = {
991*4882a593Smuzhiyun "Disabled",
992*4882a593Smuzhiyun "Vertical Color Bar Type 1",
993*4882a593Smuzhiyun "Vertical Color Bar Type 2",
994*4882a593Smuzhiyun "Vertical Color Bar Type 3",
995*4882a593Smuzhiyun "Vertical Color Bar Type 4"
996*4882a593Smuzhiyun };
997*4882a593Smuzhiyun
998*4882a593Smuzhiyun /* Write registers up to 4 at a time */
ov16a1q_write_reg(struct i2c_client * client,u16 reg,u32 len,u32 val)999*4882a593Smuzhiyun static int ov16a1q_write_reg(struct i2c_client *client, u16 reg,
1000*4882a593Smuzhiyun u32 len, u32 val)
1001*4882a593Smuzhiyun {
1002*4882a593Smuzhiyun u32 buf_i, val_i;
1003*4882a593Smuzhiyun u8 buf[6];
1004*4882a593Smuzhiyun u8 *val_p;
1005*4882a593Smuzhiyun __be32 val_be;
1006*4882a593Smuzhiyun
1007*4882a593Smuzhiyun dev_dbg(&client->dev, "write reg(0x%x val:0x%x)!\n", reg, val);
1008*4882a593Smuzhiyun
1009*4882a593Smuzhiyun if (len > 4)
1010*4882a593Smuzhiyun return -EINVAL;
1011*4882a593Smuzhiyun
1012*4882a593Smuzhiyun buf[0] = reg >> 8;
1013*4882a593Smuzhiyun buf[1] = reg & 0xff;
1014*4882a593Smuzhiyun
1015*4882a593Smuzhiyun val_be = cpu_to_be32(val);
1016*4882a593Smuzhiyun val_p = (u8 *)&val_be;
1017*4882a593Smuzhiyun buf_i = 2;
1018*4882a593Smuzhiyun val_i = 4 - len;
1019*4882a593Smuzhiyun
1020*4882a593Smuzhiyun while (val_i < 4)
1021*4882a593Smuzhiyun buf[buf_i++] = val_p[val_i++];
1022*4882a593Smuzhiyun
1023*4882a593Smuzhiyun if (i2c_master_send(client, buf, len + 2) != len + 2)
1024*4882a593Smuzhiyun return -EIO;
1025*4882a593Smuzhiyun
1026*4882a593Smuzhiyun return 0;
1027*4882a593Smuzhiyun }
1028*4882a593Smuzhiyun
ov16a1q_write_array(struct i2c_client * client,const struct regval * regs)1029*4882a593Smuzhiyun static int ov16a1q_write_array(struct i2c_client *client,
1030*4882a593Smuzhiyun const struct regval *regs)
1031*4882a593Smuzhiyun {
1032*4882a593Smuzhiyun u32 i;
1033*4882a593Smuzhiyun int ret = 0;
1034*4882a593Smuzhiyun
1035*4882a593Smuzhiyun for (i = 0; ret == 0 && regs[i].addr != REG_NULL; i++)
1036*4882a593Smuzhiyun ret = ov16a1q_write_reg(client, regs[i].addr,
1037*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1038*4882a593Smuzhiyun regs[i].val);
1039*4882a593Smuzhiyun
1040*4882a593Smuzhiyun return ret;
1041*4882a593Smuzhiyun }
1042*4882a593Smuzhiyun
1043*4882a593Smuzhiyun /* Read registers up to 4 at a time */
ov16a1q_read_reg(struct i2c_client * client,u16 reg,unsigned int len,u32 * val)1044*4882a593Smuzhiyun static int ov16a1q_read_reg(struct i2c_client *client, u16 reg,
1045*4882a593Smuzhiyun unsigned int len, u32 *val)
1046*4882a593Smuzhiyun {
1047*4882a593Smuzhiyun struct i2c_msg msgs[2];
1048*4882a593Smuzhiyun u8 *data_be_p;
1049*4882a593Smuzhiyun __be32 data_be = 0;
1050*4882a593Smuzhiyun __be16 reg_addr_be = cpu_to_be16(reg);
1051*4882a593Smuzhiyun int ret;
1052*4882a593Smuzhiyun
1053*4882a593Smuzhiyun if (len > 4 || !len)
1054*4882a593Smuzhiyun return -EINVAL;
1055*4882a593Smuzhiyun
1056*4882a593Smuzhiyun data_be_p = (u8 *)&data_be;
1057*4882a593Smuzhiyun /* Write register address */
1058*4882a593Smuzhiyun msgs[0].addr = client->addr;
1059*4882a593Smuzhiyun msgs[0].flags = 0;
1060*4882a593Smuzhiyun msgs[0].len = 2;
1061*4882a593Smuzhiyun msgs[0].buf = (u8 *)®_addr_be;
1062*4882a593Smuzhiyun
1063*4882a593Smuzhiyun /* Read data from register */
1064*4882a593Smuzhiyun msgs[1].addr = client->addr;
1065*4882a593Smuzhiyun msgs[1].flags = I2C_M_RD;
1066*4882a593Smuzhiyun msgs[1].len = len;
1067*4882a593Smuzhiyun msgs[1].buf = &data_be_p[4 - len];
1068*4882a593Smuzhiyun
1069*4882a593Smuzhiyun ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
1070*4882a593Smuzhiyun if (ret != ARRAY_SIZE(msgs))
1071*4882a593Smuzhiyun return -EIO;
1072*4882a593Smuzhiyun
1073*4882a593Smuzhiyun *val = be32_to_cpu(data_be);
1074*4882a593Smuzhiyun
1075*4882a593Smuzhiyun return 0;
1076*4882a593Smuzhiyun }
1077*4882a593Smuzhiyun
ov16a1q_get_reso_dist(const struct ov16a1q_mode * mode,struct v4l2_mbus_framefmt * framefmt)1078*4882a593Smuzhiyun static int ov16a1q_get_reso_dist(const struct ov16a1q_mode *mode,
1079*4882a593Smuzhiyun struct v4l2_mbus_framefmt *framefmt)
1080*4882a593Smuzhiyun {
1081*4882a593Smuzhiyun return abs(mode->width - framefmt->width) +
1082*4882a593Smuzhiyun abs(mode->height - framefmt->height);
1083*4882a593Smuzhiyun }
1084*4882a593Smuzhiyun
1085*4882a593Smuzhiyun static const struct ov16a1q_mode *
ov16a1q_find_best_fit(struct v4l2_subdev_format * fmt)1086*4882a593Smuzhiyun ov16a1q_find_best_fit(struct v4l2_subdev_format *fmt)
1087*4882a593Smuzhiyun {
1088*4882a593Smuzhiyun struct v4l2_mbus_framefmt *framefmt = &fmt->format;
1089*4882a593Smuzhiyun int dist;
1090*4882a593Smuzhiyun int cur_best_fit = 0;
1091*4882a593Smuzhiyun int cur_best_fit_dist = -1;
1092*4882a593Smuzhiyun unsigned int i;
1093*4882a593Smuzhiyun
1094*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(supported_modes); i++) {
1095*4882a593Smuzhiyun dist = ov16a1q_get_reso_dist(&supported_modes[i], framefmt);
1096*4882a593Smuzhiyun if (cur_best_fit_dist == -1 || dist < cur_best_fit_dist) {
1097*4882a593Smuzhiyun cur_best_fit_dist = dist;
1098*4882a593Smuzhiyun cur_best_fit = i;
1099*4882a593Smuzhiyun }
1100*4882a593Smuzhiyun }
1101*4882a593Smuzhiyun
1102*4882a593Smuzhiyun return &supported_modes[cur_best_fit];
1103*4882a593Smuzhiyun }
1104*4882a593Smuzhiyun
ov16a1q_set_fmt(struct v4l2_subdev * sd,struct v4l2_subdev_pad_config * cfg,struct v4l2_subdev_format * fmt)1105*4882a593Smuzhiyun static int ov16a1q_set_fmt(struct v4l2_subdev *sd,
1106*4882a593Smuzhiyun struct v4l2_subdev_pad_config *cfg,
1107*4882a593Smuzhiyun struct v4l2_subdev_format *fmt)
1108*4882a593Smuzhiyun {
1109*4882a593Smuzhiyun struct ov16a1q *ov16a1q = to_ov16a1q(sd);
1110*4882a593Smuzhiyun const struct ov16a1q_mode *mode;
1111*4882a593Smuzhiyun s64 h_blank, vblank_def;
1112*4882a593Smuzhiyun u64 pixel_rate = 0;
1113*4882a593Smuzhiyun u32 lane_num = OV16A1Q_LANES;
1114*4882a593Smuzhiyun
1115*4882a593Smuzhiyun mutex_lock(&ov16a1q->mutex);
1116*4882a593Smuzhiyun
1117*4882a593Smuzhiyun mode = ov16a1q_find_best_fit(fmt);
1118*4882a593Smuzhiyun fmt->format.code = OV16A1Q_MEDIA_BUS_FMT;
1119*4882a593Smuzhiyun fmt->format.width = mode->width;
1120*4882a593Smuzhiyun fmt->format.height = mode->height;
1121*4882a593Smuzhiyun fmt->format.field = V4L2_FIELD_NONE;
1122*4882a593Smuzhiyun if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1123*4882a593Smuzhiyun #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1124*4882a593Smuzhiyun *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;
1125*4882a593Smuzhiyun #else
1126*4882a593Smuzhiyun mutex_unlock(&ov16a1q->mutex);
1127*4882a593Smuzhiyun return -ENOTTY;
1128*4882a593Smuzhiyun #endif
1129*4882a593Smuzhiyun } else {
1130*4882a593Smuzhiyun ov16a1q->cur_mode = mode;
1131*4882a593Smuzhiyun h_blank = mode->hts_def - mode->width;
1132*4882a593Smuzhiyun __v4l2_ctrl_modify_range(ov16a1q->hblank, h_blank,
1133*4882a593Smuzhiyun h_blank, 1, h_blank);
1134*4882a593Smuzhiyun vblank_def = mode->vts_def - mode->height;
1135*4882a593Smuzhiyun __v4l2_ctrl_modify_range(ov16a1q->vblank, vblank_def,
1136*4882a593Smuzhiyun OV16A1Q_VTS_MAX - mode->height,
1137*4882a593Smuzhiyun 1, vblank_def);
1138*4882a593Smuzhiyun __v4l2_ctrl_s_ctrl(ov16a1q->vblank, vblank_def);
1139*4882a593Smuzhiyun pixel_rate = (u32)link_freq_items[mode->link_freq_idx] / mode->bpp * 2 * lane_num;
1140*4882a593Smuzhiyun
1141*4882a593Smuzhiyun __v4l2_ctrl_s_ctrl_int64(ov16a1q->pixel_rate,
1142*4882a593Smuzhiyun pixel_rate);
1143*4882a593Smuzhiyun __v4l2_ctrl_s_ctrl(ov16a1q->link_freq,
1144*4882a593Smuzhiyun mode->link_freq_idx);
1145*4882a593Smuzhiyun }
1146*4882a593Smuzhiyun dev_info(&ov16a1q->client->dev, "%s: mode->link_freq_idx(%d)",
1147*4882a593Smuzhiyun __func__, mode->link_freq_idx);
1148*4882a593Smuzhiyun
1149*4882a593Smuzhiyun mutex_unlock(&ov16a1q->mutex);
1150*4882a593Smuzhiyun
1151*4882a593Smuzhiyun return 0;
1152*4882a593Smuzhiyun }
1153*4882a593Smuzhiyun
ov16a1q_get_fmt(struct v4l2_subdev * sd,struct v4l2_subdev_pad_config * cfg,struct v4l2_subdev_format * fmt)1154*4882a593Smuzhiyun static int ov16a1q_get_fmt(struct v4l2_subdev *sd,
1155*4882a593Smuzhiyun struct v4l2_subdev_pad_config *cfg,
1156*4882a593Smuzhiyun struct v4l2_subdev_format *fmt)
1157*4882a593Smuzhiyun {
1158*4882a593Smuzhiyun struct ov16a1q *ov16a1q = to_ov16a1q(sd);
1159*4882a593Smuzhiyun const struct ov16a1q_mode *mode = ov16a1q->cur_mode;
1160*4882a593Smuzhiyun
1161*4882a593Smuzhiyun mutex_lock(&ov16a1q->mutex);
1162*4882a593Smuzhiyun if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1163*4882a593Smuzhiyun #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1164*4882a593Smuzhiyun fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
1165*4882a593Smuzhiyun #else
1166*4882a593Smuzhiyun mutex_unlock(&ov16a1q->mutex);
1167*4882a593Smuzhiyun return -ENOTTY;
1168*4882a593Smuzhiyun #endif
1169*4882a593Smuzhiyun } else {
1170*4882a593Smuzhiyun fmt->format.width = mode->width;
1171*4882a593Smuzhiyun fmt->format.height = mode->height;
1172*4882a593Smuzhiyun fmt->format.code = OV16A1Q_MEDIA_BUS_FMT;
1173*4882a593Smuzhiyun fmt->format.field = V4L2_FIELD_NONE;
1174*4882a593Smuzhiyun if (fmt->pad < PAD_MAX && mode->hdr_mode != NO_HDR)
1175*4882a593Smuzhiyun fmt->reserved[0] = mode->vc[fmt->pad];
1176*4882a593Smuzhiyun else
1177*4882a593Smuzhiyun fmt->reserved[0] = mode->vc[PAD0];
1178*4882a593Smuzhiyun }
1179*4882a593Smuzhiyun mutex_unlock(&ov16a1q->mutex);
1180*4882a593Smuzhiyun
1181*4882a593Smuzhiyun return 0;
1182*4882a593Smuzhiyun }
1183*4882a593Smuzhiyun
ov16a1q_enum_mbus_code(struct v4l2_subdev * sd,struct v4l2_subdev_pad_config * cfg,struct v4l2_subdev_mbus_code_enum * code)1184*4882a593Smuzhiyun static int ov16a1q_enum_mbus_code(struct v4l2_subdev *sd,
1185*4882a593Smuzhiyun struct v4l2_subdev_pad_config *cfg,
1186*4882a593Smuzhiyun struct v4l2_subdev_mbus_code_enum *code)
1187*4882a593Smuzhiyun {
1188*4882a593Smuzhiyun if (code->index != 0)
1189*4882a593Smuzhiyun return -EINVAL;
1190*4882a593Smuzhiyun code->code = OV16A1Q_MEDIA_BUS_FMT;
1191*4882a593Smuzhiyun
1192*4882a593Smuzhiyun return 0;
1193*4882a593Smuzhiyun }
1194*4882a593Smuzhiyun
ov16a1q_enum_frame_sizes(struct v4l2_subdev * sd,struct v4l2_subdev_pad_config * cfg,struct v4l2_subdev_frame_size_enum * fse)1195*4882a593Smuzhiyun static int ov16a1q_enum_frame_sizes(struct v4l2_subdev *sd,
1196*4882a593Smuzhiyun struct v4l2_subdev_pad_config *cfg,
1197*4882a593Smuzhiyun struct v4l2_subdev_frame_size_enum *fse)
1198*4882a593Smuzhiyun {
1199*4882a593Smuzhiyun struct ov16a1q *ov16a1q = to_ov16a1q(sd);
1200*4882a593Smuzhiyun
1201*4882a593Smuzhiyun if (fse->index >= ov16a1q->cfg_num)
1202*4882a593Smuzhiyun return -EINVAL;
1203*4882a593Smuzhiyun
1204*4882a593Smuzhiyun if (fse->code != OV16A1Q_MEDIA_BUS_FMT)
1205*4882a593Smuzhiyun return -EINVAL;
1206*4882a593Smuzhiyun
1207*4882a593Smuzhiyun fse->min_width = supported_modes[fse->index].width;
1208*4882a593Smuzhiyun fse->max_width = supported_modes[fse->index].width;
1209*4882a593Smuzhiyun fse->max_height = supported_modes[fse->index].height;
1210*4882a593Smuzhiyun fse->min_height = supported_modes[fse->index].height;
1211*4882a593Smuzhiyun
1212*4882a593Smuzhiyun return 0;
1213*4882a593Smuzhiyun }
1214*4882a593Smuzhiyun
ov16a1q_enable_test_pattern(struct ov16a1q * ov16a1q,u32 pattern)1215*4882a593Smuzhiyun static int ov16a1q_enable_test_pattern(struct ov16a1q *ov16a1q, u32 pattern)
1216*4882a593Smuzhiyun {
1217*4882a593Smuzhiyun u32 val;
1218*4882a593Smuzhiyun
1219*4882a593Smuzhiyun if (pattern)
1220*4882a593Smuzhiyun val = ((pattern - 1) << 4) | OV16A1Q_TEST_PATTERN_ENABLE;
1221*4882a593Smuzhiyun else
1222*4882a593Smuzhiyun val = OV16A1Q_TEST_PATTERN_DISABLE;
1223*4882a593Smuzhiyun
1224*4882a593Smuzhiyun return ov16a1q_write_reg(ov16a1q->client,
1225*4882a593Smuzhiyun OV16A1Q_REG_TEST_PATTERN,
1226*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1227*4882a593Smuzhiyun val);
1228*4882a593Smuzhiyun }
1229*4882a593Smuzhiyun
ov16a1q_g_frame_interval(struct v4l2_subdev * sd,struct v4l2_subdev_frame_interval * fi)1230*4882a593Smuzhiyun static int ov16a1q_g_frame_interval(struct v4l2_subdev *sd,
1231*4882a593Smuzhiyun struct v4l2_subdev_frame_interval *fi)
1232*4882a593Smuzhiyun {
1233*4882a593Smuzhiyun struct ov16a1q *ov16a1q = to_ov16a1q(sd);
1234*4882a593Smuzhiyun const struct ov16a1q_mode *mode = ov16a1q->cur_mode;
1235*4882a593Smuzhiyun
1236*4882a593Smuzhiyun fi->interval = mode->max_fps;
1237*4882a593Smuzhiyun
1238*4882a593Smuzhiyun return 0;
1239*4882a593Smuzhiyun }
1240*4882a593Smuzhiyun
ov16a1q_get_module_inf(struct ov16a1q * ov16a1q,struct rkmodule_inf * inf)1241*4882a593Smuzhiyun static void ov16a1q_get_module_inf(struct ov16a1q *ov16a1q,
1242*4882a593Smuzhiyun struct rkmodule_inf *inf)
1243*4882a593Smuzhiyun {
1244*4882a593Smuzhiyun memset(inf, 0, sizeof(*inf));
1245*4882a593Smuzhiyun strscpy(inf->base.sensor, OV16A1Q_NAME, sizeof(inf->base.sensor));
1246*4882a593Smuzhiyun strscpy(inf->base.module, ov16a1q->module_name,
1247*4882a593Smuzhiyun sizeof(inf->base.module));
1248*4882a593Smuzhiyun strscpy(inf->base.lens, ov16a1q->len_name, sizeof(inf->base.lens));
1249*4882a593Smuzhiyun }
1250*4882a593Smuzhiyun
ov16a1q_ioctl(struct v4l2_subdev * sd,unsigned int cmd,void * arg)1251*4882a593Smuzhiyun static long ov16a1q_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1252*4882a593Smuzhiyun {
1253*4882a593Smuzhiyun struct ov16a1q *ov16a1q = to_ov16a1q(sd);
1254*4882a593Smuzhiyun struct rkmodule_hdr_cfg *hdr_cfg;
1255*4882a593Smuzhiyun long ret = 0;
1256*4882a593Smuzhiyun u32 i, h, w;
1257*4882a593Smuzhiyun u32 stream = 0;
1258*4882a593Smuzhiyun
1259*4882a593Smuzhiyun switch (cmd) {
1260*4882a593Smuzhiyun case RKMODULE_SET_HDR_CFG:
1261*4882a593Smuzhiyun hdr_cfg = (struct rkmodule_hdr_cfg *)arg;
1262*4882a593Smuzhiyun w = ov16a1q->cur_mode->width;
1263*4882a593Smuzhiyun h = ov16a1q->cur_mode->height;
1264*4882a593Smuzhiyun for (i = 0; i < ov16a1q->cfg_num; i++) {
1265*4882a593Smuzhiyun if (w == supported_modes[i].width &&
1266*4882a593Smuzhiyun h == supported_modes[i].height &&
1267*4882a593Smuzhiyun supported_modes[i].hdr_mode == hdr_cfg->hdr_mode) {
1268*4882a593Smuzhiyun ov16a1q->cur_mode = &supported_modes[i];
1269*4882a593Smuzhiyun break;
1270*4882a593Smuzhiyun }
1271*4882a593Smuzhiyun }
1272*4882a593Smuzhiyun if (i == ov16a1q->cfg_num) {
1273*4882a593Smuzhiyun dev_err(&ov16a1q->client->dev,
1274*4882a593Smuzhiyun "not find hdr mode:%d %dx%d config\n",
1275*4882a593Smuzhiyun hdr_cfg->hdr_mode, w, h);
1276*4882a593Smuzhiyun ret = -EINVAL;
1277*4882a593Smuzhiyun } else {
1278*4882a593Smuzhiyun w = ov16a1q->cur_mode->hts_def - ov16a1q->cur_mode->width;
1279*4882a593Smuzhiyun h = ov16a1q->cur_mode->vts_def - ov16a1q->cur_mode->height;
1280*4882a593Smuzhiyun __v4l2_ctrl_modify_range(ov16a1q->hblank, w, w, 1, w);
1281*4882a593Smuzhiyun __v4l2_ctrl_modify_range(ov16a1q->vblank, h,
1282*4882a593Smuzhiyun OV16A1Q_VTS_MAX - ov16a1q->cur_mode->height,
1283*4882a593Smuzhiyun 1, h);
1284*4882a593Smuzhiyun dev_info(&ov16a1q->client->dev,
1285*4882a593Smuzhiyun "sensor mode: %d\n",
1286*4882a593Smuzhiyun ov16a1q->cur_mode->hdr_mode);
1287*4882a593Smuzhiyun }
1288*4882a593Smuzhiyun break;
1289*4882a593Smuzhiyun case RKMODULE_GET_HDR_CFG:
1290*4882a593Smuzhiyun hdr_cfg = (struct rkmodule_hdr_cfg *)arg;
1291*4882a593Smuzhiyun hdr_cfg->esp.mode = HDR_NORMAL_VC;
1292*4882a593Smuzhiyun hdr_cfg->hdr_mode = ov16a1q->cur_mode->hdr_mode;
1293*4882a593Smuzhiyun break;
1294*4882a593Smuzhiyun case RKMODULE_GET_MODULE_INFO:
1295*4882a593Smuzhiyun ov16a1q_get_module_inf(ov16a1q, (struct rkmodule_inf *)arg);
1296*4882a593Smuzhiyun break;
1297*4882a593Smuzhiyun case RKMODULE_SET_QUICK_STREAM:
1298*4882a593Smuzhiyun
1299*4882a593Smuzhiyun stream = *((u32 *)arg);
1300*4882a593Smuzhiyun
1301*4882a593Smuzhiyun if (stream)
1302*4882a593Smuzhiyun ret = ov16a1q_write_reg(ov16a1q->client,
1303*4882a593Smuzhiyun OV16A1Q_REG_CTRL_MODE,
1304*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1305*4882a593Smuzhiyun OV16A1Q_MODE_STREAMING);
1306*4882a593Smuzhiyun else
1307*4882a593Smuzhiyun ret = ov16a1q_write_reg(ov16a1q->client,
1308*4882a593Smuzhiyun OV16A1Q_REG_CTRL_MODE,
1309*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1310*4882a593Smuzhiyun OV16A1Q_MODE_SW_STANDBY);
1311*4882a593Smuzhiyun break;
1312*4882a593Smuzhiyun default:
1313*4882a593Smuzhiyun ret = -ENOIOCTLCMD;
1314*4882a593Smuzhiyun break;
1315*4882a593Smuzhiyun }
1316*4882a593Smuzhiyun
1317*4882a593Smuzhiyun return ret;
1318*4882a593Smuzhiyun }
1319*4882a593Smuzhiyun
1320*4882a593Smuzhiyun #ifdef CONFIG_COMPAT
ov16a1q_compat_ioctl32(struct v4l2_subdev * sd,unsigned int cmd,unsigned long arg)1321*4882a593Smuzhiyun static long ov16a1q_compat_ioctl32(struct v4l2_subdev *sd,
1322*4882a593Smuzhiyun unsigned int cmd, unsigned long arg)
1323*4882a593Smuzhiyun {
1324*4882a593Smuzhiyun void __user *up = compat_ptr(arg);
1325*4882a593Smuzhiyun struct rkmodule_inf *inf;
1326*4882a593Smuzhiyun struct rkmodule_awb_cfg *cfg;
1327*4882a593Smuzhiyun struct rkmodule_hdr_cfg *hdr;
1328*4882a593Smuzhiyun long ret = 0;
1329*4882a593Smuzhiyun u32 stream = 0;
1330*4882a593Smuzhiyun
1331*4882a593Smuzhiyun switch (cmd) {
1332*4882a593Smuzhiyun case RKMODULE_GET_MODULE_INFO:
1333*4882a593Smuzhiyun inf = kzalloc(sizeof(*inf), GFP_KERNEL);
1334*4882a593Smuzhiyun if (!inf) {
1335*4882a593Smuzhiyun ret = -ENOMEM;
1336*4882a593Smuzhiyun return ret;
1337*4882a593Smuzhiyun }
1338*4882a593Smuzhiyun
1339*4882a593Smuzhiyun ret = ov16a1q_ioctl(sd, cmd, inf);
1340*4882a593Smuzhiyun if (!ret) {
1341*4882a593Smuzhiyun ret = copy_to_user(up, inf, sizeof(*inf));
1342*4882a593Smuzhiyun if (ret)
1343*4882a593Smuzhiyun ret = -EFAULT;
1344*4882a593Smuzhiyun }
1345*4882a593Smuzhiyun kfree(inf);
1346*4882a593Smuzhiyun break;
1347*4882a593Smuzhiyun case RKMODULE_AWB_CFG:
1348*4882a593Smuzhiyun cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
1349*4882a593Smuzhiyun if (!cfg) {
1350*4882a593Smuzhiyun ret = -ENOMEM;
1351*4882a593Smuzhiyun return ret;
1352*4882a593Smuzhiyun }
1353*4882a593Smuzhiyun
1354*4882a593Smuzhiyun ret = copy_from_user(cfg, up, sizeof(*cfg));
1355*4882a593Smuzhiyun if (!ret)
1356*4882a593Smuzhiyun ret = ov16a1q_ioctl(sd, cmd, cfg);
1357*4882a593Smuzhiyun else
1358*4882a593Smuzhiyun ret = -EFAULT;
1359*4882a593Smuzhiyun kfree(cfg);
1360*4882a593Smuzhiyun break;
1361*4882a593Smuzhiyun case RKMODULE_GET_HDR_CFG:
1362*4882a593Smuzhiyun hdr = kzalloc(sizeof(*hdr), GFP_KERNEL);
1363*4882a593Smuzhiyun if (!hdr) {
1364*4882a593Smuzhiyun ret = -ENOMEM;
1365*4882a593Smuzhiyun return ret;
1366*4882a593Smuzhiyun }
1367*4882a593Smuzhiyun
1368*4882a593Smuzhiyun ret = ov16a1q_ioctl(sd, cmd, hdr);
1369*4882a593Smuzhiyun if (!ret) {
1370*4882a593Smuzhiyun if (copy_to_user(up, hdr, sizeof(*hdr))) {
1371*4882a593Smuzhiyun kfree(hdr);
1372*4882a593Smuzhiyun return -EFAULT;
1373*4882a593Smuzhiyun }
1374*4882a593Smuzhiyun }
1375*4882a593Smuzhiyun kfree(hdr);
1376*4882a593Smuzhiyun break;
1377*4882a593Smuzhiyun case RKMODULE_SET_HDR_CFG:
1378*4882a593Smuzhiyun hdr = kzalloc(sizeof(*hdr), GFP_KERNEL);
1379*4882a593Smuzhiyun if (!hdr) {
1380*4882a593Smuzhiyun ret = -ENOMEM;
1381*4882a593Smuzhiyun return ret;
1382*4882a593Smuzhiyun }
1383*4882a593Smuzhiyun
1384*4882a593Smuzhiyun if (copy_from_user(hdr, up, sizeof(*hdr))) {
1385*4882a593Smuzhiyun kfree(hdr);
1386*4882a593Smuzhiyun return -EFAULT;
1387*4882a593Smuzhiyun }
1388*4882a593Smuzhiyun ret = ov16a1q_ioctl(sd, cmd, hdr);
1389*4882a593Smuzhiyun kfree(hdr);
1390*4882a593Smuzhiyun break;
1391*4882a593Smuzhiyun case RKMODULE_SET_QUICK_STREAM:
1392*4882a593Smuzhiyun ret = copy_from_user(&stream, up, sizeof(u32));
1393*4882a593Smuzhiyun if (!ret)
1394*4882a593Smuzhiyun ret = ov16a1q_ioctl(sd, cmd, &stream);
1395*4882a593Smuzhiyun else
1396*4882a593Smuzhiyun ret = -EFAULT;
1397*4882a593Smuzhiyun break;
1398*4882a593Smuzhiyun default:
1399*4882a593Smuzhiyun ret = -ENOIOCTLCMD;
1400*4882a593Smuzhiyun break;
1401*4882a593Smuzhiyun }
1402*4882a593Smuzhiyun
1403*4882a593Smuzhiyun return ret;
1404*4882a593Smuzhiyun }
1405*4882a593Smuzhiyun #endif
1406*4882a593Smuzhiyun
__ov16a1q_start_stream(struct ov16a1q * ov16a1q)1407*4882a593Smuzhiyun static int __ov16a1q_start_stream(struct ov16a1q *ov16a1q)
1408*4882a593Smuzhiyun {
1409*4882a593Smuzhiyun int ret;
1410*4882a593Smuzhiyun
1411*4882a593Smuzhiyun ret = ov16a1q_write_array(ov16a1q->client, ov16a1q->cur_mode->reg_list);
1412*4882a593Smuzhiyun if (ret)
1413*4882a593Smuzhiyun return ret;
1414*4882a593Smuzhiyun
1415*4882a593Smuzhiyun /* In case these controls are set before streaming */
1416*4882a593Smuzhiyun mutex_unlock(&ov16a1q->mutex);
1417*4882a593Smuzhiyun ret = v4l2_ctrl_handler_setup(&ov16a1q->ctrl_handler);
1418*4882a593Smuzhiyun mutex_lock(&ov16a1q->mutex);
1419*4882a593Smuzhiyun if (ret)
1420*4882a593Smuzhiyun return ret;
1421*4882a593Smuzhiyun
1422*4882a593Smuzhiyun return ov16a1q_write_reg(ov16a1q->client,
1423*4882a593Smuzhiyun OV16A1Q_REG_CTRL_MODE,
1424*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1425*4882a593Smuzhiyun OV16A1Q_MODE_STREAMING);
1426*4882a593Smuzhiyun }
1427*4882a593Smuzhiyun
__ov16a1q_stop_stream(struct ov16a1q * ov16a1q)1428*4882a593Smuzhiyun static int __ov16a1q_stop_stream(struct ov16a1q *ov16a1q)
1429*4882a593Smuzhiyun {
1430*4882a593Smuzhiyun return ov16a1q_write_reg(ov16a1q->client,
1431*4882a593Smuzhiyun OV16A1Q_REG_CTRL_MODE,
1432*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1433*4882a593Smuzhiyun OV16A1Q_MODE_SW_STANDBY);
1434*4882a593Smuzhiyun }
1435*4882a593Smuzhiyun
ov16a1q_s_stream(struct v4l2_subdev * sd,int on)1436*4882a593Smuzhiyun static int ov16a1q_s_stream(struct v4l2_subdev *sd, int on)
1437*4882a593Smuzhiyun {
1438*4882a593Smuzhiyun struct ov16a1q *ov16a1q = to_ov16a1q(sd);
1439*4882a593Smuzhiyun struct i2c_client *client = ov16a1q->client;
1440*4882a593Smuzhiyun int ret = 0;
1441*4882a593Smuzhiyun
1442*4882a593Smuzhiyun dev_info(&client->dev, "%s: on: %d, %dx%d@%d\n", __func__, on,
1443*4882a593Smuzhiyun ov16a1q->cur_mode->width,
1444*4882a593Smuzhiyun ov16a1q->cur_mode->height,
1445*4882a593Smuzhiyun DIV_ROUND_CLOSEST(ov16a1q->cur_mode->max_fps.denominator,
1446*4882a593Smuzhiyun ov16a1q->cur_mode->max_fps.numerator));
1447*4882a593Smuzhiyun
1448*4882a593Smuzhiyun mutex_lock(&ov16a1q->mutex);
1449*4882a593Smuzhiyun on = !!on;
1450*4882a593Smuzhiyun if (on == ov16a1q->streaming)
1451*4882a593Smuzhiyun goto unlock_and_return;
1452*4882a593Smuzhiyun
1453*4882a593Smuzhiyun if (on) {
1454*4882a593Smuzhiyun ret = pm_runtime_get_sync(&client->dev);
1455*4882a593Smuzhiyun if (ret < 0) {
1456*4882a593Smuzhiyun pm_runtime_put_noidle(&client->dev);
1457*4882a593Smuzhiyun goto unlock_and_return;
1458*4882a593Smuzhiyun }
1459*4882a593Smuzhiyun
1460*4882a593Smuzhiyun ret = __ov16a1q_start_stream(ov16a1q);
1461*4882a593Smuzhiyun if (ret) {
1462*4882a593Smuzhiyun v4l2_err(sd, "start stream failed while write regs\n");
1463*4882a593Smuzhiyun pm_runtime_put(&client->dev);
1464*4882a593Smuzhiyun goto unlock_and_return;
1465*4882a593Smuzhiyun }
1466*4882a593Smuzhiyun } else {
1467*4882a593Smuzhiyun __ov16a1q_stop_stream(ov16a1q);
1468*4882a593Smuzhiyun pm_runtime_put(&client->dev);
1469*4882a593Smuzhiyun }
1470*4882a593Smuzhiyun
1471*4882a593Smuzhiyun ov16a1q->streaming = on;
1472*4882a593Smuzhiyun
1473*4882a593Smuzhiyun unlock_and_return:
1474*4882a593Smuzhiyun mutex_unlock(&ov16a1q->mutex);
1475*4882a593Smuzhiyun
1476*4882a593Smuzhiyun return ret;
1477*4882a593Smuzhiyun }
1478*4882a593Smuzhiyun
ov16a1q_s_power(struct v4l2_subdev * sd,int on)1479*4882a593Smuzhiyun static int ov16a1q_s_power(struct v4l2_subdev *sd, int on)
1480*4882a593Smuzhiyun {
1481*4882a593Smuzhiyun struct ov16a1q *ov16a1q = to_ov16a1q(sd);
1482*4882a593Smuzhiyun struct i2c_client *client = ov16a1q->client;
1483*4882a593Smuzhiyun int ret = 0;
1484*4882a593Smuzhiyun
1485*4882a593Smuzhiyun mutex_lock(&ov16a1q->mutex);
1486*4882a593Smuzhiyun
1487*4882a593Smuzhiyun /* If the power state is not modified - no work to do. */
1488*4882a593Smuzhiyun if (ov16a1q->power_on == !!on)
1489*4882a593Smuzhiyun goto unlock_and_return;
1490*4882a593Smuzhiyun
1491*4882a593Smuzhiyun if (on) {
1492*4882a593Smuzhiyun ret = pm_runtime_get_sync(&client->dev);
1493*4882a593Smuzhiyun if (ret < 0) {
1494*4882a593Smuzhiyun pm_runtime_put_noidle(&client->dev);
1495*4882a593Smuzhiyun goto unlock_and_return;
1496*4882a593Smuzhiyun }
1497*4882a593Smuzhiyun
1498*4882a593Smuzhiyun ret = ov16a1q_write_array(ov16a1q->client, ov16a1q_global_regs);
1499*4882a593Smuzhiyun if (ret) {
1500*4882a593Smuzhiyun v4l2_err(sd, "could not set init registers\n");
1501*4882a593Smuzhiyun pm_runtime_put_noidle(&client->dev);
1502*4882a593Smuzhiyun goto unlock_and_return;
1503*4882a593Smuzhiyun }
1504*4882a593Smuzhiyun
1505*4882a593Smuzhiyun ov16a1q->power_on = true;
1506*4882a593Smuzhiyun } else {
1507*4882a593Smuzhiyun pm_runtime_put(&client->dev);
1508*4882a593Smuzhiyun ov16a1q->power_on = false;
1509*4882a593Smuzhiyun }
1510*4882a593Smuzhiyun
1511*4882a593Smuzhiyun unlock_and_return:
1512*4882a593Smuzhiyun mutex_unlock(&ov16a1q->mutex);
1513*4882a593Smuzhiyun
1514*4882a593Smuzhiyun return ret;
1515*4882a593Smuzhiyun }
1516*4882a593Smuzhiyun
1517*4882a593Smuzhiyun /* Calculate the delay in us by clock rate and clock cycles */
ov16a1q_cal_delay(u32 cycles)1518*4882a593Smuzhiyun static inline u32 ov16a1q_cal_delay(u32 cycles)
1519*4882a593Smuzhiyun {
1520*4882a593Smuzhiyun return DIV_ROUND_UP(cycles, OV16A1Q_XVCLK_FREQ / 1000 / 1000);
1521*4882a593Smuzhiyun }
1522*4882a593Smuzhiyun
__ov16a1q_power_on(struct ov16a1q * ov16a1q)1523*4882a593Smuzhiyun static int __ov16a1q_power_on(struct ov16a1q *ov16a1q)
1524*4882a593Smuzhiyun {
1525*4882a593Smuzhiyun int ret;
1526*4882a593Smuzhiyun u32 delay_us;
1527*4882a593Smuzhiyun struct device *dev = &ov16a1q->client->dev;
1528*4882a593Smuzhiyun
1529*4882a593Smuzhiyun if (!IS_ERR(ov16a1q->power_gpio))
1530*4882a593Smuzhiyun gpiod_set_value_cansleep(ov16a1q->power_gpio, 1);
1531*4882a593Smuzhiyun
1532*4882a593Smuzhiyun usleep_range(1000, 2000);
1533*4882a593Smuzhiyun
1534*4882a593Smuzhiyun if (!IS_ERR_OR_NULL(ov16a1q->pins_default)) {
1535*4882a593Smuzhiyun ret = pinctrl_select_state(ov16a1q->pinctrl,
1536*4882a593Smuzhiyun ov16a1q->pins_default);
1537*4882a593Smuzhiyun if (ret < 0)
1538*4882a593Smuzhiyun dev_err(dev, "could not set pins\n");
1539*4882a593Smuzhiyun }
1540*4882a593Smuzhiyun ret = clk_set_rate(ov16a1q->xvclk, OV16A1Q_XVCLK_FREQ);
1541*4882a593Smuzhiyun if (ret < 0)
1542*4882a593Smuzhiyun dev_warn(dev, "Failed to set xvclk rate (24MHz)\n");
1543*4882a593Smuzhiyun if (clk_get_rate(ov16a1q->xvclk) != OV16A1Q_XVCLK_FREQ)
1544*4882a593Smuzhiyun dev_warn(dev, "xvclk mismatched, modes are based on 24MHz\n");
1545*4882a593Smuzhiyun ret = clk_prepare_enable(ov16a1q->xvclk);
1546*4882a593Smuzhiyun if (ret < 0) {
1547*4882a593Smuzhiyun dev_err(dev, "Failed to enable xvclk\n");
1548*4882a593Smuzhiyun return ret;
1549*4882a593Smuzhiyun }
1550*4882a593Smuzhiyun if (!IS_ERR(ov16a1q->reset_gpio))
1551*4882a593Smuzhiyun gpiod_set_value_cansleep(ov16a1q->reset_gpio, 0);
1552*4882a593Smuzhiyun
1553*4882a593Smuzhiyun ret = regulator_bulk_enable(OV16A1Q_NUM_SUPPLIES, ov16a1q->supplies);
1554*4882a593Smuzhiyun if (ret < 0) {
1555*4882a593Smuzhiyun dev_err(dev, "Failed to enable regulators\n");
1556*4882a593Smuzhiyun goto disable_clk;
1557*4882a593Smuzhiyun }
1558*4882a593Smuzhiyun
1559*4882a593Smuzhiyun if (!IS_ERR(ov16a1q->reset_gpio))
1560*4882a593Smuzhiyun gpiod_set_value_cansleep(ov16a1q->reset_gpio, 1);
1561*4882a593Smuzhiyun
1562*4882a593Smuzhiyun usleep_range(5000, 6000);
1563*4882a593Smuzhiyun if (!IS_ERR(ov16a1q->pwdn_gpio))
1564*4882a593Smuzhiyun gpiod_set_value_cansleep(ov16a1q->pwdn_gpio, 1);
1565*4882a593Smuzhiyun
1566*4882a593Smuzhiyun /* 8192 cycles prior to first SCCB transaction */
1567*4882a593Smuzhiyun delay_us = ov16a1q_cal_delay(8192);
1568*4882a593Smuzhiyun usleep_range(delay_us * 2, delay_us * 3);
1569*4882a593Smuzhiyun
1570*4882a593Smuzhiyun return 0;
1571*4882a593Smuzhiyun
1572*4882a593Smuzhiyun disable_clk:
1573*4882a593Smuzhiyun clk_disable_unprepare(ov16a1q->xvclk);
1574*4882a593Smuzhiyun
1575*4882a593Smuzhiyun return ret;
1576*4882a593Smuzhiyun }
1577*4882a593Smuzhiyun
__ov16a1q_power_off(struct ov16a1q * ov16a1q)1578*4882a593Smuzhiyun static void __ov16a1q_power_off(struct ov16a1q *ov16a1q)
1579*4882a593Smuzhiyun {
1580*4882a593Smuzhiyun int ret;
1581*4882a593Smuzhiyun struct device *dev = &ov16a1q->client->dev;
1582*4882a593Smuzhiyun
1583*4882a593Smuzhiyun if (!IS_ERR(ov16a1q->pwdn_gpio))
1584*4882a593Smuzhiyun gpiod_set_value_cansleep(ov16a1q->pwdn_gpio, 0);
1585*4882a593Smuzhiyun clk_disable_unprepare(ov16a1q->xvclk);
1586*4882a593Smuzhiyun if (!IS_ERR(ov16a1q->reset_gpio))
1587*4882a593Smuzhiyun gpiod_set_value_cansleep(ov16a1q->reset_gpio, 0);
1588*4882a593Smuzhiyun
1589*4882a593Smuzhiyun if (!IS_ERR_OR_NULL(ov16a1q->pins_sleep)) {
1590*4882a593Smuzhiyun ret = pinctrl_select_state(ov16a1q->pinctrl,
1591*4882a593Smuzhiyun ov16a1q->pins_sleep);
1592*4882a593Smuzhiyun if (ret < 0)
1593*4882a593Smuzhiyun dev_dbg(dev, "could not set pins\n");
1594*4882a593Smuzhiyun }
1595*4882a593Smuzhiyun if (!IS_ERR(ov16a1q->power_gpio))
1596*4882a593Smuzhiyun gpiod_set_value_cansleep(ov16a1q->power_gpio, 0);
1597*4882a593Smuzhiyun
1598*4882a593Smuzhiyun regulator_bulk_disable(OV16A1Q_NUM_SUPPLIES, ov16a1q->supplies);
1599*4882a593Smuzhiyun }
1600*4882a593Smuzhiyun
ov16a1q_runtime_resume(struct device * dev)1601*4882a593Smuzhiyun static int ov16a1q_runtime_resume(struct device *dev)
1602*4882a593Smuzhiyun {
1603*4882a593Smuzhiyun struct i2c_client *client = to_i2c_client(dev);
1604*4882a593Smuzhiyun struct v4l2_subdev *sd = i2c_get_clientdata(client);
1605*4882a593Smuzhiyun struct ov16a1q *ov16a1q = to_ov16a1q(sd);
1606*4882a593Smuzhiyun
1607*4882a593Smuzhiyun return __ov16a1q_power_on(ov16a1q);
1608*4882a593Smuzhiyun }
1609*4882a593Smuzhiyun
ov16a1q_runtime_suspend(struct device * dev)1610*4882a593Smuzhiyun static int ov16a1q_runtime_suspend(struct device *dev)
1611*4882a593Smuzhiyun {
1612*4882a593Smuzhiyun struct i2c_client *client = to_i2c_client(dev);
1613*4882a593Smuzhiyun struct v4l2_subdev *sd = i2c_get_clientdata(client);
1614*4882a593Smuzhiyun struct ov16a1q *ov16a1q = to_ov16a1q(sd);
1615*4882a593Smuzhiyun
1616*4882a593Smuzhiyun __ov16a1q_power_off(ov16a1q);
1617*4882a593Smuzhiyun
1618*4882a593Smuzhiyun return 0;
1619*4882a593Smuzhiyun }
1620*4882a593Smuzhiyun
1621*4882a593Smuzhiyun #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
ov16a1q_open(struct v4l2_subdev * sd,struct v4l2_subdev_fh * fh)1622*4882a593Smuzhiyun static int ov16a1q_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1623*4882a593Smuzhiyun {
1624*4882a593Smuzhiyun struct ov16a1q *ov16a1q = to_ov16a1q(sd);
1625*4882a593Smuzhiyun struct v4l2_mbus_framefmt *try_fmt =
1626*4882a593Smuzhiyun v4l2_subdev_get_try_format(sd, fh->pad, 0);
1627*4882a593Smuzhiyun const struct ov16a1q_mode *def_mode = &supported_modes[0];
1628*4882a593Smuzhiyun
1629*4882a593Smuzhiyun mutex_lock(&ov16a1q->mutex);
1630*4882a593Smuzhiyun /* Initialize try_fmt */
1631*4882a593Smuzhiyun try_fmt->width = def_mode->width;
1632*4882a593Smuzhiyun try_fmt->height = def_mode->height;
1633*4882a593Smuzhiyun try_fmt->code = OV16A1Q_MEDIA_BUS_FMT;
1634*4882a593Smuzhiyun try_fmt->field = V4L2_FIELD_NONE;
1635*4882a593Smuzhiyun
1636*4882a593Smuzhiyun mutex_unlock(&ov16a1q->mutex);
1637*4882a593Smuzhiyun /* No crop or compose */
1638*4882a593Smuzhiyun
1639*4882a593Smuzhiyun return 0;
1640*4882a593Smuzhiyun }
1641*4882a593Smuzhiyun #endif
1642*4882a593Smuzhiyun
ov16a1q_enum_frame_interval(struct v4l2_subdev * sd,struct v4l2_subdev_pad_config * cfg,struct v4l2_subdev_frame_interval_enum * fie)1643*4882a593Smuzhiyun static int ov16a1q_enum_frame_interval(struct v4l2_subdev *sd,
1644*4882a593Smuzhiyun struct v4l2_subdev_pad_config *cfg,
1645*4882a593Smuzhiyun struct v4l2_subdev_frame_interval_enum *fie)
1646*4882a593Smuzhiyun {
1647*4882a593Smuzhiyun if (fie->index >= ARRAY_SIZE(supported_modes))
1648*4882a593Smuzhiyun return -EINVAL;
1649*4882a593Smuzhiyun
1650*4882a593Smuzhiyun fie->code = OV16A1Q_MEDIA_BUS_FMT;
1651*4882a593Smuzhiyun fie->width = supported_modes[fie->index].width;
1652*4882a593Smuzhiyun fie->height = supported_modes[fie->index].height;
1653*4882a593Smuzhiyun fie->interval = supported_modes[fie->index].max_fps;
1654*4882a593Smuzhiyun fie->reserved[0] = supported_modes[fie->index].hdr_mode;
1655*4882a593Smuzhiyun
1656*4882a593Smuzhiyun return 0;
1657*4882a593Smuzhiyun }
1658*4882a593Smuzhiyun
ov16a1q_g_mbus_config(struct v4l2_subdev * sd,unsigned int pad,struct v4l2_mbus_config * config)1659*4882a593Smuzhiyun static int ov16a1q_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad,
1660*4882a593Smuzhiyun struct v4l2_mbus_config *config)
1661*4882a593Smuzhiyun {
1662*4882a593Smuzhiyun if (2 == OV16A1Q_LANES) {
1663*4882a593Smuzhiyun config->type = V4L2_MBUS_CSI2_DPHY;
1664*4882a593Smuzhiyun config->flags = V4L2_MBUS_CSI2_2_LANE |
1665*4882a593Smuzhiyun V4L2_MBUS_CSI2_CHANNEL_0 |
1666*4882a593Smuzhiyun V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
1667*4882a593Smuzhiyun } else if (4 == OV16A1Q_LANES) {
1668*4882a593Smuzhiyun config->type = V4L2_MBUS_CSI2_DPHY;
1669*4882a593Smuzhiyun config->flags = V4L2_MBUS_CSI2_4_LANE |
1670*4882a593Smuzhiyun V4L2_MBUS_CSI2_CHANNEL_0 |
1671*4882a593Smuzhiyun V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
1672*4882a593Smuzhiyun }
1673*4882a593Smuzhiyun
1674*4882a593Smuzhiyun return 0;
1675*4882a593Smuzhiyun }
1676*4882a593Smuzhiyun
1677*4882a593Smuzhiyun #define CROP_START(SRC, DST) (((SRC) - (DST)) / 2 / 4 * 4)
1678*4882a593Smuzhiyun #define DST_WIDTH_2320 2320
1679*4882a593Smuzhiyun #define DST_HEIGHT_1744 1744
1680*4882a593Smuzhiyun /*
1681*4882a593Smuzhiyun * The resolution of the driver configuration needs to be exactly
1682*4882a593Smuzhiyun * the same as the current output resolution of the sensor,
1683*4882a593Smuzhiyun * the input width of the isp needs to be 16 aligned,
1684*4882a593Smuzhiyun * the input height of the isp needs to be 8 aligned.
1685*4882a593Smuzhiyun * Can be cropped to standard resolution by this function,
1686*4882a593Smuzhiyun * otherwise it will crop out strange resolution according
1687*4882a593Smuzhiyun * to the alignment rules.
1688*4882a593Smuzhiyun */
ov16a1q_get_selection(struct v4l2_subdev * sd,struct v4l2_subdev_pad_config * cfg,struct v4l2_subdev_selection * sel)1689*4882a593Smuzhiyun static int ov16a1q_get_selection(struct v4l2_subdev *sd,
1690*4882a593Smuzhiyun struct v4l2_subdev_pad_config *cfg,
1691*4882a593Smuzhiyun struct v4l2_subdev_selection *sel)
1692*4882a593Smuzhiyun {
1693*4882a593Smuzhiyun struct ov16a1q *ov16a1q = to_ov16a1q(sd);
1694*4882a593Smuzhiyun
1695*4882a593Smuzhiyun if (sel->target == V4L2_SEL_TGT_CROP_BOUNDS) {
1696*4882a593Smuzhiyun if (ov16a1q->cur_mode->width == 2328) {
1697*4882a593Smuzhiyun sel->r.left = CROP_START(ov16a1q->cur_mode->width, DST_WIDTH_2320);
1698*4882a593Smuzhiyun sel->r.width = DST_WIDTH_2320;
1699*4882a593Smuzhiyun sel->r.top = CROP_START(ov16a1q->cur_mode->height, DST_HEIGHT_1744);
1700*4882a593Smuzhiyun sel->r.height = DST_HEIGHT_1744;
1701*4882a593Smuzhiyun } else {
1702*4882a593Smuzhiyun sel->r.left = 0;
1703*4882a593Smuzhiyun sel->r.width = ov16a1q->cur_mode->width;
1704*4882a593Smuzhiyun sel->r.top = 0;
1705*4882a593Smuzhiyun sel->r.height = ov16a1q->cur_mode->height;
1706*4882a593Smuzhiyun }
1707*4882a593Smuzhiyun return 0;
1708*4882a593Smuzhiyun }
1709*4882a593Smuzhiyun
1710*4882a593Smuzhiyun return -EINVAL;
1711*4882a593Smuzhiyun }
1712*4882a593Smuzhiyun
1713*4882a593Smuzhiyun static const struct dev_pm_ops ov16a1q_pm_ops = {
1714*4882a593Smuzhiyun SET_RUNTIME_PM_OPS(ov16a1q_runtime_suspend,
1715*4882a593Smuzhiyun ov16a1q_runtime_resume, NULL)
1716*4882a593Smuzhiyun };
1717*4882a593Smuzhiyun
1718*4882a593Smuzhiyun #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1719*4882a593Smuzhiyun static const struct v4l2_subdev_internal_ops ov16a1q_internal_ops = {
1720*4882a593Smuzhiyun .open = ov16a1q_open,
1721*4882a593Smuzhiyun };
1722*4882a593Smuzhiyun #endif
1723*4882a593Smuzhiyun
1724*4882a593Smuzhiyun static const struct v4l2_subdev_core_ops ov16a1q_core_ops = {
1725*4882a593Smuzhiyun .s_power = ov16a1q_s_power,
1726*4882a593Smuzhiyun .ioctl = ov16a1q_ioctl,
1727*4882a593Smuzhiyun #ifdef CONFIG_COMPAT
1728*4882a593Smuzhiyun .compat_ioctl32 = ov16a1q_compat_ioctl32,
1729*4882a593Smuzhiyun #endif
1730*4882a593Smuzhiyun };
1731*4882a593Smuzhiyun
1732*4882a593Smuzhiyun static const struct v4l2_subdev_video_ops ov16a1q_video_ops = {
1733*4882a593Smuzhiyun .s_stream = ov16a1q_s_stream,
1734*4882a593Smuzhiyun .g_frame_interval = ov16a1q_g_frame_interval,
1735*4882a593Smuzhiyun };
1736*4882a593Smuzhiyun
1737*4882a593Smuzhiyun static const struct v4l2_subdev_pad_ops ov16a1q_pad_ops = {
1738*4882a593Smuzhiyun .enum_mbus_code = ov16a1q_enum_mbus_code,
1739*4882a593Smuzhiyun .enum_frame_size = ov16a1q_enum_frame_sizes,
1740*4882a593Smuzhiyun .enum_frame_interval = ov16a1q_enum_frame_interval,
1741*4882a593Smuzhiyun .get_fmt = ov16a1q_get_fmt,
1742*4882a593Smuzhiyun .set_fmt = ov16a1q_set_fmt,
1743*4882a593Smuzhiyun .get_selection = ov16a1q_get_selection,
1744*4882a593Smuzhiyun .get_mbus_config = ov16a1q_g_mbus_config,
1745*4882a593Smuzhiyun };
1746*4882a593Smuzhiyun
1747*4882a593Smuzhiyun static const struct v4l2_subdev_ops ov16a1q_subdev_ops = {
1748*4882a593Smuzhiyun .core = &ov16a1q_core_ops,
1749*4882a593Smuzhiyun .video = &ov16a1q_video_ops,
1750*4882a593Smuzhiyun .pad = &ov16a1q_pad_ops,
1751*4882a593Smuzhiyun };
1752*4882a593Smuzhiyun
ov16a1q_set_ctrl(struct v4l2_ctrl * ctrl)1753*4882a593Smuzhiyun static int ov16a1q_set_ctrl(struct v4l2_ctrl *ctrl)
1754*4882a593Smuzhiyun {
1755*4882a593Smuzhiyun struct ov16a1q *ov16a1q = container_of(ctrl->handler,
1756*4882a593Smuzhiyun struct ov16a1q, ctrl_handler);
1757*4882a593Smuzhiyun struct i2c_client *client = ov16a1q->client;
1758*4882a593Smuzhiyun s64 max;
1759*4882a593Smuzhiyun int ret = 0;
1760*4882a593Smuzhiyun u32 again, dgain;
1761*4882a593Smuzhiyun u32 val = 0, x_win = 0, y_win = 0;
1762*4882a593Smuzhiyun
1763*4882a593Smuzhiyun /* Propagate change of current control to all related controls */
1764*4882a593Smuzhiyun switch (ctrl->id) {
1765*4882a593Smuzhiyun case V4L2_CID_VBLANK:
1766*4882a593Smuzhiyun /* Update max exposure while meeting expected vblanking */
1767*4882a593Smuzhiyun max = ov16a1q->cur_mode->height + ctrl->val - 4;
1768*4882a593Smuzhiyun __v4l2_ctrl_modify_range(ov16a1q->exposure,
1769*4882a593Smuzhiyun ov16a1q->exposure->minimum, max,
1770*4882a593Smuzhiyun ov16a1q->exposure->step,
1771*4882a593Smuzhiyun ov16a1q->exposure->default_value);
1772*4882a593Smuzhiyun break;
1773*4882a593Smuzhiyun }
1774*4882a593Smuzhiyun
1775*4882a593Smuzhiyun if (!pm_runtime_get_if_in_use(&client->dev))
1776*4882a593Smuzhiyun return 0;
1777*4882a593Smuzhiyun
1778*4882a593Smuzhiyun switch (ctrl->id) {
1779*4882a593Smuzhiyun case V4L2_CID_EXPOSURE:
1780*4882a593Smuzhiyun /* 4 least significant bits of expsoure are fractional part */
1781*4882a593Smuzhiyun ret |= ov16a1q_write_reg(ov16a1q->client,
1782*4882a593Smuzhiyun OV16A1Q_REG_EXPOSURE_H,
1783*4882a593Smuzhiyun OV16A1Q_REG_VALUE_24BIT,
1784*4882a593Smuzhiyun ctrl->val & 0x7fffff);
1785*4882a593Smuzhiyun dev_dbg(&client->dev, "set exposure 0x%x\n",
1786*4882a593Smuzhiyun ctrl->val);
1787*4882a593Smuzhiyun break;
1788*4882a593Smuzhiyun case V4L2_CID_ANALOGUE_GAIN:
1789*4882a593Smuzhiyun if (ctrl->val > 1984) {// >15.5x
1790*4882a593Smuzhiyun dgain = ctrl->val * 10 / 155;
1791*4882a593Smuzhiyun again = 1984;
1792*4882a593Smuzhiyun } else {
1793*4882a593Smuzhiyun dgain = 1024;
1794*4882a593Smuzhiyun again = ctrl->val;
1795*4882a593Smuzhiyun }
1796*4882a593Smuzhiyun ret |= ov16a1q_write_reg(ov16a1q->client,
1797*4882a593Smuzhiyun OV16A1Q_REG_AGAIN_H,
1798*4882a593Smuzhiyun OV16A1Q_REG_VALUE_16BIT,
1799*4882a593Smuzhiyun (again << 1) & 0x7ffe);
1800*4882a593Smuzhiyun ret |= ov16a1q_write_reg(ov16a1q->client,
1801*4882a593Smuzhiyun OV16A1Q_REG_DAGAIN_H_B,
1802*4882a593Smuzhiyun OV16A1Q_REG_VALUE_24BIT,
1803*4882a593Smuzhiyun (dgain << 6) & 0xfffc0);
1804*4882a593Smuzhiyun
1805*4882a593Smuzhiyun dev_dbg(&client->dev, "set gain 0x%x set analog gain 0x%x digital gain 0x%x\n",
1806*4882a593Smuzhiyun ctrl->val, again, dgain);
1807*4882a593Smuzhiyun break;
1808*4882a593Smuzhiyun case V4L2_CID_VBLANK:
1809*4882a593Smuzhiyun ret = ov16a1q_write_reg(ov16a1q->client,
1810*4882a593Smuzhiyun OV16A1Q_REG_VTS_H,
1811*4882a593Smuzhiyun OV16A1Q_REG_VALUE_16BIT,
1812*4882a593Smuzhiyun ctrl->val + ov16a1q->cur_mode->height);
1813*4882a593Smuzhiyun break;
1814*4882a593Smuzhiyun case V4L2_CID_TEST_PATTERN:
1815*4882a593Smuzhiyun ret = ov16a1q_enable_test_pattern(ov16a1q, ctrl->val);
1816*4882a593Smuzhiyun break;
1817*4882a593Smuzhiyun case V4L2_CID_HFLIP:
1818*4882a593Smuzhiyun ret = ov16a1q_read_reg(ov16a1q->client, OV16A1Q_MIRROR_REG,
1819*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1820*4882a593Smuzhiyun &val);
1821*4882a593Smuzhiyun if (ctrl->val)
1822*4882a593Smuzhiyun val |= MIRROR_BIT_MASK;
1823*4882a593Smuzhiyun else
1824*4882a593Smuzhiyun val &= ~MIRROR_BIT_MASK;
1825*4882a593Smuzhiyun
1826*4882a593Smuzhiyun ret |= ov16a1q_read_reg(ov16a1q->client, OV16A1Q_REG_ISP_X_WIN,
1827*4882a593Smuzhiyun OV16A1Q_REG_VALUE_16BIT,
1828*4882a593Smuzhiyun &x_win);
1829*4882a593Smuzhiyun
1830*4882a593Smuzhiyun if ((x_win == 0x0010) && (val & 0x04))
1831*4882a593Smuzhiyun x_win = 0x0011;
1832*4882a593Smuzhiyun else if ((x_win == 0x0011) && (!(val & 0x04)))
1833*4882a593Smuzhiyun x_win = 0x0010;
1834*4882a593Smuzhiyun
1835*4882a593Smuzhiyun ret |= ov16a1q_write_reg(ov16a1q->client,
1836*4882a593Smuzhiyun OV16A1Q_GROUP_UPDATE_ADDRESS,
1837*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1838*4882a593Smuzhiyun OV16A1Q_GROUP_UPDATE_START_DATA);
1839*4882a593Smuzhiyun
1840*4882a593Smuzhiyun ret |= ov16a1q_write_reg(ov16a1q->client, OV16A1Q_MIRROR_REG,
1841*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1842*4882a593Smuzhiyun val);
1843*4882a593Smuzhiyun ret |= ov16a1q_write_reg(ov16a1q->client, OV16A1Q_REG_ISP_X_WIN,
1844*4882a593Smuzhiyun OV16A1Q_REG_VALUE_16BIT,
1845*4882a593Smuzhiyun x_win);
1846*4882a593Smuzhiyun
1847*4882a593Smuzhiyun ret |= ov16a1q_write_reg(ov16a1q->client,
1848*4882a593Smuzhiyun OV16A1Q_GROUP_UPDATE_ADDRESS,
1849*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1850*4882a593Smuzhiyun OV16A1Q_GROUP_UPDATE_END_DATA);
1851*4882a593Smuzhiyun ret |= ov16a1q_write_reg(ov16a1q->client,
1852*4882a593Smuzhiyun OV16A1Q_GROUP_UPDATE_ADDRESS,
1853*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1854*4882a593Smuzhiyun OV16A1Q_GROUP_UPDATE_LAUNCH);
1855*4882a593Smuzhiyun break;
1856*4882a593Smuzhiyun case V4L2_CID_VFLIP:
1857*4882a593Smuzhiyun ret = ov16a1q_read_reg(ov16a1q->client, OV16A1Q_FLIP_REG,
1858*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1859*4882a593Smuzhiyun &val);
1860*4882a593Smuzhiyun if (ctrl->val)
1861*4882a593Smuzhiyun val |= FLIP_BIT_MASK;
1862*4882a593Smuzhiyun else
1863*4882a593Smuzhiyun val &= ~FLIP_BIT_MASK;
1864*4882a593Smuzhiyun
1865*4882a593Smuzhiyun ret |= ov16a1q_read_reg(ov16a1q->client, OV16A1Q_REG_ISP_Y_WIN,
1866*4882a593Smuzhiyun OV16A1Q_REG_VALUE_16BIT,
1867*4882a593Smuzhiyun &y_win);
1868*4882a593Smuzhiyun
1869*4882a593Smuzhiyun if ((y_win == 0x0004) && (val & 0x04))
1870*4882a593Smuzhiyun y_win = 0x0005;
1871*4882a593Smuzhiyun else if ((y_win == 0x0005) && (!(val & 0x04)))
1872*4882a593Smuzhiyun y_win = 0x0004;
1873*4882a593Smuzhiyun
1874*4882a593Smuzhiyun ret |= ov16a1q_write_reg(ov16a1q->client,
1875*4882a593Smuzhiyun OV16A1Q_GROUP_UPDATE_ADDRESS,
1876*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1877*4882a593Smuzhiyun OV16A1Q_GROUP_UPDATE_START_DATA);
1878*4882a593Smuzhiyun
1879*4882a593Smuzhiyun ret |= ov16a1q_write_reg(ov16a1q->client, OV16A1Q_FLIP_REG,
1880*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1881*4882a593Smuzhiyun val);
1882*4882a593Smuzhiyun ret |= ov16a1q_write_reg(ov16a1q->client, OV16A1Q_REG_ISP_Y_WIN,
1883*4882a593Smuzhiyun OV16A1Q_REG_VALUE_16BIT,
1884*4882a593Smuzhiyun y_win);
1885*4882a593Smuzhiyun
1886*4882a593Smuzhiyun ret |= ov16a1q_write_reg(ov16a1q->client,
1887*4882a593Smuzhiyun OV16A1Q_GROUP_UPDATE_ADDRESS,
1888*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1889*4882a593Smuzhiyun OV16A1Q_GROUP_UPDATE_END_DATA);
1890*4882a593Smuzhiyun ret |= ov16a1q_write_reg(ov16a1q->client,
1891*4882a593Smuzhiyun OV16A1Q_GROUP_UPDATE_ADDRESS,
1892*4882a593Smuzhiyun OV16A1Q_REG_VALUE_08BIT,
1893*4882a593Smuzhiyun OV16A1Q_GROUP_UPDATE_LAUNCH);
1894*4882a593Smuzhiyun break;
1895*4882a593Smuzhiyun default:
1896*4882a593Smuzhiyun dev_warn(&client->dev, "%s Unhandled id:0x%x, val:0x%x\n",
1897*4882a593Smuzhiyun __func__, ctrl->id, ctrl->val);
1898*4882a593Smuzhiyun break;
1899*4882a593Smuzhiyun }
1900*4882a593Smuzhiyun
1901*4882a593Smuzhiyun pm_runtime_put(&client->dev);
1902*4882a593Smuzhiyun
1903*4882a593Smuzhiyun return ret;
1904*4882a593Smuzhiyun }
1905*4882a593Smuzhiyun
1906*4882a593Smuzhiyun static const struct v4l2_ctrl_ops ov16a1q_ctrl_ops = {
1907*4882a593Smuzhiyun .s_ctrl = ov16a1q_set_ctrl,
1908*4882a593Smuzhiyun };
1909*4882a593Smuzhiyun
ov16a1q_initialize_controls(struct ov16a1q * ov16a1q)1910*4882a593Smuzhiyun static int ov16a1q_initialize_controls(struct ov16a1q *ov16a1q)
1911*4882a593Smuzhiyun {
1912*4882a593Smuzhiyun const struct ov16a1q_mode *mode;
1913*4882a593Smuzhiyun struct v4l2_ctrl_handler *handler;
1914*4882a593Smuzhiyun s64 exposure_max, vblank_def;
1915*4882a593Smuzhiyun u32 h_blank;
1916*4882a593Smuzhiyun int ret;
1917*4882a593Smuzhiyun u64 dst_pixel_rate = 0;
1918*4882a593Smuzhiyun u32 lane_num = OV16A1Q_LANES;
1919*4882a593Smuzhiyun
1920*4882a593Smuzhiyun handler = &ov16a1q->ctrl_handler;
1921*4882a593Smuzhiyun mode = ov16a1q->cur_mode;
1922*4882a593Smuzhiyun ret = v4l2_ctrl_handler_init(handler, 9);
1923*4882a593Smuzhiyun if (ret)
1924*4882a593Smuzhiyun return ret;
1925*4882a593Smuzhiyun handler->lock = &ov16a1q->mutex;
1926*4882a593Smuzhiyun
1927*4882a593Smuzhiyun ov16a1q->link_freq = v4l2_ctrl_new_int_menu(handler, NULL,
1928*4882a593Smuzhiyun V4L2_CID_LINK_FREQ,
1929*4882a593Smuzhiyun 0, 0, link_freq_items);
1930*4882a593Smuzhiyun
1931*4882a593Smuzhiyun dst_pixel_rate = (u32)link_freq_items[mode->link_freq_idx] / mode->bpp * 2 * lane_num;
1932*4882a593Smuzhiyun
1933*4882a593Smuzhiyun ov16a1q->pixel_rate = v4l2_ctrl_new_std(handler, NULL,
1934*4882a593Smuzhiyun V4L2_CID_PIXEL_RATE,
1935*4882a593Smuzhiyun 0, OV16A1Q_PIXEL_RATE,
1936*4882a593Smuzhiyun 1, dst_pixel_rate);
1937*4882a593Smuzhiyun
1938*4882a593Smuzhiyun __v4l2_ctrl_s_ctrl(ov16a1q->link_freq,
1939*4882a593Smuzhiyun mode->link_freq_idx);
1940*4882a593Smuzhiyun
1941*4882a593Smuzhiyun h_blank = mode->hts_def - mode->width;
1942*4882a593Smuzhiyun ov16a1q->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK,
1943*4882a593Smuzhiyun h_blank, h_blank, 1, h_blank);
1944*4882a593Smuzhiyun if (ov16a1q->hblank)
1945*4882a593Smuzhiyun ov16a1q->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1946*4882a593Smuzhiyun
1947*4882a593Smuzhiyun vblank_def = mode->vts_def - mode->height;
1948*4882a593Smuzhiyun ov16a1q->vblank = v4l2_ctrl_new_std(handler, &ov16a1q_ctrl_ops,
1949*4882a593Smuzhiyun V4L2_CID_VBLANK, vblank_def,
1950*4882a593Smuzhiyun OV16A1Q_VTS_MAX - mode->height,
1951*4882a593Smuzhiyun 1, vblank_def);
1952*4882a593Smuzhiyun
1953*4882a593Smuzhiyun exposure_max = mode->vts_def - 4;
1954*4882a593Smuzhiyun ov16a1q->exposure = v4l2_ctrl_new_std(handler, &ov16a1q_ctrl_ops,
1955*4882a593Smuzhiyun V4L2_CID_EXPOSURE, OV16A1Q_EXPOSURE_MIN,
1956*4882a593Smuzhiyun exposure_max, OV16A1Q_EXPOSURE_STEP,
1957*4882a593Smuzhiyun mode->exp_def);
1958*4882a593Smuzhiyun
1959*4882a593Smuzhiyun ov16a1q->anal_gain = v4l2_ctrl_new_std(handler, &ov16a1q_ctrl_ops,
1960*4882a593Smuzhiyun V4L2_CID_ANALOGUE_GAIN, OV16A1Q_GAIN_MIN,
1961*4882a593Smuzhiyun OV16A1Q_GAIN_MAX, OV16A1Q_GAIN_STEP,
1962*4882a593Smuzhiyun OV16A1Q_GAIN_DEFAULT);
1963*4882a593Smuzhiyun
1964*4882a593Smuzhiyun ov16a1q->test_pattern = v4l2_ctrl_new_std_menu_items(handler,
1965*4882a593Smuzhiyun &ov16a1q_ctrl_ops, V4L2_CID_TEST_PATTERN,
1966*4882a593Smuzhiyun ARRAY_SIZE(ov16a1q_test_pattern_menu) - 1,
1967*4882a593Smuzhiyun 0, 0, ov16a1q_test_pattern_menu);
1968*4882a593Smuzhiyun
1969*4882a593Smuzhiyun ov16a1q->h_flip = v4l2_ctrl_new_std(handler, &ov16a1q_ctrl_ops,
1970*4882a593Smuzhiyun V4L2_CID_HFLIP, 0, 1, 1, 0);
1971*4882a593Smuzhiyun
1972*4882a593Smuzhiyun ov16a1q->v_flip = v4l2_ctrl_new_std(handler, &ov16a1q_ctrl_ops,
1973*4882a593Smuzhiyun V4L2_CID_VFLIP, 0, 1, 1, 0);
1974*4882a593Smuzhiyun
1975*4882a593Smuzhiyun if (handler->error) {
1976*4882a593Smuzhiyun ret = handler->error;
1977*4882a593Smuzhiyun dev_err(&ov16a1q->client->dev,
1978*4882a593Smuzhiyun "Failed to init controls(%d)\n", ret);
1979*4882a593Smuzhiyun goto err_free_handler;
1980*4882a593Smuzhiyun }
1981*4882a593Smuzhiyun
1982*4882a593Smuzhiyun ov16a1q->subdev.ctrl_handler = handler;
1983*4882a593Smuzhiyun
1984*4882a593Smuzhiyun return 0;
1985*4882a593Smuzhiyun
1986*4882a593Smuzhiyun err_free_handler:
1987*4882a593Smuzhiyun v4l2_ctrl_handler_free(handler);
1988*4882a593Smuzhiyun
1989*4882a593Smuzhiyun return ret;
1990*4882a593Smuzhiyun }
1991*4882a593Smuzhiyun
ov16a1q_check_sensor_id(struct ov16a1q * ov16a1q,struct i2c_client * client)1992*4882a593Smuzhiyun static int ov16a1q_check_sensor_id(struct ov16a1q *ov16a1q,
1993*4882a593Smuzhiyun struct i2c_client *client)
1994*4882a593Smuzhiyun {
1995*4882a593Smuzhiyun struct device *dev = &ov16a1q->client->dev;
1996*4882a593Smuzhiyun u32 id = 0;
1997*4882a593Smuzhiyun int ret;
1998*4882a593Smuzhiyun
1999*4882a593Smuzhiyun ret = ov16a1q_read_reg(client, OV16A1Q_REG_CHIP_ID,
2000*4882a593Smuzhiyun OV16A1Q_REG_VALUE_24BIT, &id);
2001*4882a593Smuzhiyun if (id != CHIP_ID) {
2002*4882a593Smuzhiyun dev_err(dev, "Unexpected sensor id(%06x), ret(%d)\n", id, ret);
2003*4882a593Smuzhiyun return -ENODEV;
2004*4882a593Smuzhiyun }
2005*4882a593Smuzhiyun
2006*4882a593Smuzhiyun dev_info(dev, "Detected OV%06x sensor\n", CHIP_ID);
2007*4882a593Smuzhiyun
2008*4882a593Smuzhiyun return 0;
2009*4882a593Smuzhiyun }
2010*4882a593Smuzhiyun
ov16a1q_configure_regulators(struct ov16a1q * ov16a1q)2011*4882a593Smuzhiyun static int ov16a1q_configure_regulators(struct ov16a1q *ov16a1q)
2012*4882a593Smuzhiyun {
2013*4882a593Smuzhiyun unsigned int i;
2014*4882a593Smuzhiyun
2015*4882a593Smuzhiyun for (i = 0; i < OV16A1Q_NUM_SUPPLIES; i++)
2016*4882a593Smuzhiyun ov16a1q->supplies[i].supply = ov16a1q_supply_names[i];
2017*4882a593Smuzhiyun
2018*4882a593Smuzhiyun return devm_regulator_bulk_get(&ov16a1q->client->dev,
2019*4882a593Smuzhiyun OV16A1Q_NUM_SUPPLIES,
2020*4882a593Smuzhiyun ov16a1q->supplies);
2021*4882a593Smuzhiyun }
2022*4882a593Smuzhiyun
ov16a1q_probe(struct i2c_client * client,const struct i2c_device_id * id)2023*4882a593Smuzhiyun static int ov16a1q_probe(struct i2c_client *client,
2024*4882a593Smuzhiyun const struct i2c_device_id *id)
2025*4882a593Smuzhiyun {
2026*4882a593Smuzhiyun struct device *dev = &client->dev;
2027*4882a593Smuzhiyun struct device_node *node = dev->of_node;
2028*4882a593Smuzhiyun struct ov16a1q *ov16a1q;
2029*4882a593Smuzhiyun struct v4l2_subdev *sd;
2030*4882a593Smuzhiyun char facing[2];
2031*4882a593Smuzhiyun int ret;
2032*4882a593Smuzhiyun u32 i, hdr_mode = 0;
2033*4882a593Smuzhiyun
2034*4882a593Smuzhiyun dev_info(dev, "driver version: %02x.%02x.%02x",
2035*4882a593Smuzhiyun DRIVER_VERSION >> 16,
2036*4882a593Smuzhiyun (DRIVER_VERSION & 0xff00) >> 8,
2037*4882a593Smuzhiyun DRIVER_VERSION & 0x00ff);
2038*4882a593Smuzhiyun
2039*4882a593Smuzhiyun ov16a1q = devm_kzalloc(dev, sizeof(*ov16a1q), GFP_KERNEL);
2040*4882a593Smuzhiyun if (!ov16a1q)
2041*4882a593Smuzhiyun return -ENOMEM;
2042*4882a593Smuzhiyun
2043*4882a593Smuzhiyun ret = of_property_read_u32(node, RKMODULE_CAMERA_MODULE_INDEX,
2044*4882a593Smuzhiyun &ov16a1q->module_index);
2045*4882a593Smuzhiyun ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_FACING,
2046*4882a593Smuzhiyun &ov16a1q->module_facing);
2047*4882a593Smuzhiyun ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_NAME,
2048*4882a593Smuzhiyun &ov16a1q->module_name);
2049*4882a593Smuzhiyun ret |= of_property_read_string(node, RKMODULE_CAMERA_LENS_NAME,
2050*4882a593Smuzhiyun &ov16a1q->len_name);
2051*4882a593Smuzhiyun if (ret) {
2052*4882a593Smuzhiyun dev_err(dev, "could not get module information!\n");
2053*4882a593Smuzhiyun return -EINVAL;
2054*4882a593Smuzhiyun }
2055*4882a593Smuzhiyun
2056*4882a593Smuzhiyun ret = of_property_read_u32(node, OF_CAMERA_HDR_MODE,
2057*4882a593Smuzhiyun &hdr_mode);
2058*4882a593Smuzhiyun if (ret) {
2059*4882a593Smuzhiyun hdr_mode = NO_HDR;
2060*4882a593Smuzhiyun dev_warn(dev, " Get hdr mode failed! no hdr default\n");
2061*4882a593Smuzhiyun }
2062*4882a593Smuzhiyun ov16a1q->cfg_num = ARRAY_SIZE(supported_modes);
2063*4882a593Smuzhiyun for (i = 0; i < ov16a1q->cfg_num; i++) {
2064*4882a593Smuzhiyun if (hdr_mode == supported_modes[i].hdr_mode) {
2065*4882a593Smuzhiyun ov16a1q->cur_mode = &supported_modes[i];
2066*4882a593Smuzhiyun break;
2067*4882a593Smuzhiyun }
2068*4882a593Smuzhiyun }
2069*4882a593Smuzhiyun
2070*4882a593Smuzhiyun ov16a1q->client = client;
2071*4882a593Smuzhiyun
2072*4882a593Smuzhiyun ov16a1q->xvclk = devm_clk_get(dev, "xvclk");
2073*4882a593Smuzhiyun if (IS_ERR(ov16a1q->xvclk)) {
2074*4882a593Smuzhiyun dev_err(dev, "Failed to get xvclk\n");
2075*4882a593Smuzhiyun return -EINVAL;
2076*4882a593Smuzhiyun }
2077*4882a593Smuzhiyun
2078*4882a593Smuzhiyun ov16a1q->power_gpio = devm_gpiod_get(dev, "power", GPIOD_OUT_LOW);
2079*4882a593Smuzhiyun if (IS_ERR(ov16a1q->power_gpio))
2080*4882a593Smuzhiyun dev_warn(dev, "Failed to get power-gpios, maybe no use\n");
2081*4882a593Smuzhiyun
2082*4882a593Smuzhiyun ov16a1q->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
2083*4882a593Smuzhiyun if (IS_ERR(ov16a1q->reset_gpio))
2084*4882a593Smuzhiyun dev_warn(dev, "Failed to get reset-gpios\n");
2085*4882a593Smuzhiyun
2086*4882a593Smuzhiyun ov16a1q->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW);
2087*4882a593Smuzhiyun if (IS_ERR(ov16a1q->pwdn_gpio))
2088*4882a593Smuzhiyun dev_warn(dev, "Failed to get pwdn-gpios\n");
2089*4882a593Smuzhiyun
2090*4882a593Smuzhiyun ret = ov16a1q_configure_regulators(ov16a1q);
2091*4882a593Smuzhiyun if (ret) {
2092*4882a593Smuzhiyun dev_err(dev, "Failed to get power regulators\n");
2093*4882a593Smuzhiyun return ret;
2094*4882a593Smuzhiyun }
2095*4882a593Smuzhiyun
2096*4882a593Smuzhiyun ov16a1q->pinctrl = devm_pinctrl_get(dev);
2097*4882a593Smuzhiyun if (!IS_ERR(ov16a1q->pinctrl)) {
2098*4882a593Smuzhiyun ov16a1q->pins_default =
2099*4882a593Smuzhiyun pinctrl_lookup_state(ov16a1q->pinctrl,
2100*4882a593Smuzhiyun OF_CAMERA_PINCTRL_STATE_DEFAULT);
2101*4882a593Smuzhiyun if (IS_ERR(ov16a1q->pins_default))
2102*4882a593Smuzhiyun dev_err(dev, "could not get default pinstate\n");
2103*4882a593Smuzhiyun
2104*4882a593Smuzhiyun ov16a1q->pins_sleep =
2105*4882a593Smuzhiyun pinctrl_lookup_state(ov16a1q->pinctrl,
2106*4882a593Smuzhiyun OF_CAMERA_PINCTRL_STATE_SLEEP);
2107*4882a593Smuzhiyun if (IS_ERR(ov16a1q->pins_sleep))
2108*4882a593Smuzhiyun dev_err(dev, "could not get sleep pinstate\n");
2109*4882a593Smuzhiyun }
2110*4882a593Smuzhiyun
2111*4882a593Smuzhiyun mutex_init(&ov16a1q->mutex);
2112*4882a593Smuzhiyun
2113*4882a593Smuzhiyun sd = &ov16a1q->subdev;
2114*4882a593Smuzhiyun v4l2_i2c_subdev_init(sd, client, &ov16a1q_subdev_ops);
2115*4882a593Smuzhiyun ret = ov16a1q_initialize_controls(ov16a1q);
2116*4882a593Smuzhiyun if (ret)
2117*4882a593Smuzhiyun goto err_destroy_mutex;
2118*4882a593Smuzhiyun
2119*4882a593Smuzhiyun ret = __ov16a1q_power_on(ov16a1q);
2120*4882a593Smuzhiyun if (ret)
2121*4882a593Smuzhiyun goto err_free_handler;
2122*4882a593Smuzhiyun
2123*4882a593Smuzhiyun ret = ov16a1q_check_sensor_id(ov16a1q, client);
2124*4882a593Smuzhiyun if (ret)
2125*4882a593Smuzhiyun goto err_power_off;
2126*4882a593Smuzhiyun
2127*4882a593Smuzhiyun #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
2128*4882a593Smuzhiyun sd->internal_ops = &ov16a1q_internal_ops;
2129*4882a593Smuzhiyun sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
2130*4882a593Smuzhiyun #endif
2131*4882a593Smuzhiyun #if defined(CONFIG_MEDIA_CONTROLLER)
2132*4882a593Smuzhiyun ov16a1q->pad.flags = MEDIA_PAD_FL_SOURCE;
2133*4882a593Smuzhiyun sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
2134*4882a593Smuzhiyun ret = media_entity_pads_init(&sd->entity, 1, &ov16a1q->pad);
2135*4882a593Smuzhiyun if (ret < 0)
2136*4882a593Smuzhiyun goto err_power_off;
2137*4882a593Smuzhiyun #endif
2138*4882a593Smuzhiyun
2139*4882a593Smuzhiyun memset(facing, 0, sizeof(facing));
2140*4882a593Smuzhiyun if (strcmp(ov16a1q->module_facing, "back") == 0)
2141*4882a593Smuzhiyun facing[0] = 'b';
2142*4882a593Smuzhiyun else
2143*4882a593Smuzhiyun facing[0] = 'f';
2144*4882a593Smuzhiyun
2145*4882a593Smuzhiyun snprintf(sd->name, sizeof(sd->name), "m%02d_%s_%s %s",
2146*4882a593Smuzhiyun ov16a1q->module_index, facing,
2147*4882a593Smuzhiyun OV16A1Q_NAME, dev_name(sd->dev));
2148*4882a593Smuzhiyun ret = v4l2_async_register_subdev_sensor_common(sd);
2149*4882a593Smuzhiyun if (ret) {
2150*4882a593Smuzhiyun dev_err(dev, "v4l2 async register subdev failed\n");
2151*4882a593Smuzhiyun goto err_clean_entity;
2152*4882a593Smuzhiyun }
2153*4882a593Smuzhiyun
2154*4882a593Smuzhiyun pm_runtime_set_active(dev);
2155*4882a593Smuzhiyun pm_runtime_enable(dev);
2156*4882a593Smuzhiyun pm_runtime_idle(dev);
2157*4882a593Smuzhiyun
2158*4882a593Smuzhiyun return 0;
2159*4882a593Smuzhiyun
2160*4882a593Smuzhiyun err_clean_entity:
2161*4882a593Smuzhiyun #if defined(CONFIG_MEDIA_CONTROLLER)
2162*4882a593Smuzhiyun media_entity_cleanup(&sd->entity);
2163*4882a593Smuzhiyun #endif
2164*4882a593Smuzhiyun err_power_off:
2165*4882a593Smuzhiyun __ov16a1q_power_off(ov16a1q);
2166*4882a593Smuzhiyun err_free_handler:
2167*4882a593Smuzhiyun v4l2_ctrl_handler_free(&ov16a1q->ctrl_handler);
2168*4882a593Smuzhiyun err_destroy_mutex:
2169*4882a593Smuzhiyun mutex_destroy(&ov16a1q->mutex);
2170*4882a593Smuzhiyun
2171*4882a593Smuzhiyun return ret;
2172*4882a593Smuzhiyun }
2173*4882a593Smuzhiyun
ov16a1q_remove(struct i2c_client * client)2174*4882a593Smuzhiyun static int ov16a1q_remove(struct i2c_client *client)
2175*4882a593Smuzhiyun {
2176*4882a593Smuzhiyun struct v4l2_subdev *sd = i2c_get_clientdata(client);
2177*4882a593Smuzhiyun struct ov16a1q *ov16a1q = to_ov16a1q(sd);
2178*4882a593Smuzhiyun
2179*4882a593Smuzhiyun v4l2_async_unregister_subdev(sd);
2180*4882a593Smuzhiyun #if defined(CONFIG_MEDIA_CONTROLLER)
2181*4882a593Smuzhiyun media_entity_cleanup(&sd->entity);
2182*4882a593Smuzhiyun #endif
2183*4882a593Smuzhiyun v4l2_ctrl_handler_free(&ov16a1q->ctrl_handler);
2184*4882a593Smuzhiyun mutex_destroy(&ov16a1q->mutex);
2185*4882a593Smuzhiyun
2186*4882a593Smuzhiyun pm_runtime_disable(&client->dev);
2187*4882a593Smuzhiyun if (!pm_runtime_status_suspended(&client->dev))
2188*4882a593Smuzhiyun __ov16a1q_power_off(ov16a1q);
2189*4882a593Smuzhiyun pm_runtime_set_suspended(&client->dev);
2190*4882a593Smuzhiyun
2191*4882a593Smuzhiyun return 0;
2192*4882a593Smuzhiyun }
2193*4882a593Smuzhiyun
2194*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_OF)
2195*4882a593Smuzhiyun static const struct of_device_id ov16a1q_of_match[] = {
2196*4882a593Smuzhiyun { .compatible = "ovti,ov16a1q" },
2197*4882a593Smuzhiyun {},
2198*4882a593Smuzhiyun };
2199*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, ov16a1q_of_match);
2200*4882a593Smuzhiyun #endif
2201*4882a593Smuzhiyun
2202*4882a593Smuzhiyun static const struct i2c_device_id ov16a1q_match_id[] = {
2203*4882a593Smuzhiyun { "ovti,ov16a1q", 0 },
2204*4882a593Smuzhiyun {},
2205*4882a593Smuzhiyun };
2206*4882a593Smuzhiyun
2207*4882a593Smuzhiyun static struct i2c_driver ov16a1q_i2c_driver = {
2208*4882a593Smuzhiyun .driver = {
2209*4882a593Smuzhiyun .name = OV16A1Q_NAME,
2210*4882a593Smuzhiyun .pm = &ov16a1q_pm_ops,
2211*4882a593Smuzhiyun .of_match_table = of_match_ptr(ov16a1q_of_match),
2212*4882a593Smuzhiyun },
2213*4882a593Smuzhiyun .probe = &ov16a1q_probe,
2214*4882a593Smuzhiyun .remove = &ov16a1q_remove,
2215*4882a593Smuzhiyun .id_table = ov16a1q_match_id,
2216*4882a593Smuzhiyun };
2217*4882a593Smuzhiyun
sensor_mod_init(void)2218*4882a593Smuzhiyun static int __init sensor_mod_init(void)
2219*4882a593Smuzhiyun {
2220*4882a593Smuzhiyun return i2c_add_driver(&ov16a1q_i2c_driver);
2221*4882a593Smuzhiyun }
2222*4882a593Smuzhiyun
sensor_mod_exit(void)2223*4882a593Smuzhiyun static void __exit sensor_mod_exit(void)
2224*4882a593Smuzhiyun {
2225*4882a593Smuzhiyun i2c_del_driver(&ov16a1q_i2c_driver);
2226*4882a593Smuzhiyun }
2227*4882a593Smuzhiyun
2228*4882a593Smuzhiyun device_initcall_sync(sensor_mod_init);
2229*4882a593Smuzhiyun module_exit(sensor_mod_exit);
2230*4882a593Smuzhiyun
2231*4882a593Smuzhiyun MODULE_DESCRIPTION("OmniVision ov16a1q sensor driver");
2232*4882a593Smuzhiyun MODULE_LICENSE("GPL");
2233