Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 // Copyright (c) 2017 Intel Corporation.
0003 
0004 #include <linux/acpi.h>
0005 #include <linux/i2c.h>
0006 #include <linux/module.h>
0007 #include <linux/pm_runtime.h>
0008 #include <media/v4l2-ctrls.h>
0009 #include <media/v4l2-device.h>
0010 #include <media/v4l2-event.h>
0011 #include <media/v4l2-fwnode.h>
0012 
0013 #define OV5670_REG_CHIP_ID      0x300a
0014 #define OV5670_CHIP_ID          0x005670
0015 
0016 #define OV5670_REG_MODE_SELECT      0x0100
0017 #define OV5670_MODE_STANDBY     0x00
0018 #define OV5670_MODE_STREAMING       0x01
0019 
0020 #define OV5670_REG_SOFTWARE_RST     0x0103
0021 #define OV5670_SOFTWARE_RST     0x01
0022 
0023 /* vertical-timings from sensor */
0024 #define OV5670_REG_VTS          0x380e
0025 #define OV5670_VTS_30FPS        0x0808 /* default for 30 fps */
0026 #define OV5670_VTS_MAX          0xffff
0027 
0028 /* horizontal-timings from sensor */
0029 #define OV5670_REG_HTS          0x380c
0030 
0031 /*
0032  * Pixels-per-line(PPL) = Time-per-line * pixel-rate
0033  * In OV5670, Time-per-line = HTS/SCLK.
0034  * HTS is fixed for all resolutions, not recommended to change.
0035  */
0036 #define OV5670_FIXED_PPL        2724    /* Pixels per line */
0037 
0038 /* Exposure controls from sensor */
0039 #define OV5670_REG_EXPOSURE     0x3500
0040 #define OV5670_EXPOSURE_MIN     4
0041 #define OV5670_EXPOSURE_STEP        1
0042 
0043 /* Analog gain controls from sensor */
0044 #define OV5670_REG_ANALOG_GAIN      0x3508
0045 #define ANALOG_GAIN_MIN         0
0046 #define ANALOG_GAIN_MAX         8191
0047 #define ANALOG_GAIN_STEP        1
0048 #define ANALOG_GAIN_DEFAULT     128
0049 
0050 /* Digital gain controls from sensor */
0051 #define OV5670_REG_R_DGTL_GAIN      0x5032
0052 #define OV5670_REG_G_DGTL_GAIN      0x5034
0053 #define OV5670_REG_B_DGTL_GAIN      0x5036
0054 #define OV5670_DGTL_GAIN_MIN        0
0055 #define OV5670_DGTL_GAIN_MAX        4095
0056 #define OV5670_DGTL_GAIN_STEP       1
0057 #define OV5670_DGTL_GAIN_DEFAULT    1024
0058 
0059 /* Test Pattern Control */
0060 #define OV5670_REG_TEST_PATTERN     0x4303
0061 #define OV5670_TEST_PATTERN_ENABLE  BIT(3)
0062 #define OV5670_REG_TEST_PATTERN_CTRL    0x4320
0063 
0064 #define OV5670_REG_VALUE_08BIT      1
0065 #define OV5670_REG_VALUE_16BIT      2
0066 #define OV5670_REG_VALUE_24BIT      3
0067 
0068 /* Initial number of frames to skip to avoid possible garbage */
0069 #define OV5670_NUM_OF_SKIP_FRAMES   2
0070 
0071 struct ov5670_reg {
0072     u16 address;
0073     u8 val;
0074 };
0075 
0076 struct ov5670_reg_list {
0077     u32 num_of_regs;
0078     const struct ov5670_reg *regs;
0079 };
0080 
0081 struct ov5670_link_freq_config {
0082     u32 pixel_rate;
0083     const struct ov5670_reg_list reg_list;
0084 };
0085 
0086 struct ov5670_mode {
0087     /* Frame width in pixels */
0088     u32 width;
0089 
0090     /* Frame height in pixels */
0091     u32 height;
0092 
0093     /* Default vertical timining size */
0094     u32 vts_def;
0095 
0096     /* Min vertical timining size */
0097     u32 vts_min;
0098 
0099     /* Link frequency needed for this resolution */
0100     u32 link_freq_index;
0101 
0102     /* Sensor register settings for this resolution */
0103     const struct ov5670_reg_list reg_list;
0104 };
0105 
0106 static const struct ov5670_reg mipi_data_rate_840mbps[] = {
0107     {0x0300, 0x04},
0108     {0x0301, 0x00},
0109     {0x0302, 0x84},
0110     {0x0303, 0x00},
0111     {0x0304, 0x03},
0112     {0x0305, 0x01},
0113     {0x0306, 0x01},
0114     {0x030a, 0x00},
0115     {0x030b, 0x00},
0116     {0x030c, 0x00},
0117     {0x030d, 0x26},
0118     {0x030e, 0x00},
0119     {0x030f, 0x06},
0120     {0x0312, 0x01},
0121     {0x3031, 0x0a},
0122 };
0123 
0124 static const struct ov5670_reg mode_2592x1944_regs[] = {
0125     {0x3000, 0x00},
0126     {0x3002, 0x21},
0127     {0x3005, 0xf0},
0128     {0x3007, 0x00},
0129     {0x3015, 0x0f},
0130     {0x3018, 0x32},
0131     {0x301a, 0xf0},
0132     {0x301b, 0xf0},
0133     {0x301c, 0xf0},
0134     {0x301d, 0xf0},
0135     {0x301e, 0xf0},
0136     {0x3030, 0x00},
0137     {0x3031, 0x0a},
0138     {0x303c, 0xff},
0139     {0x303e, 0xff},
0140     {0x3040, 0xf0},
0141     {0x3041, 0x00},
0142     {0x3042, 0xf0},
0143     {0x3106, 0x11},
0144     {0x3500, 0x00},
0145     {0x3501, 0x80},
0146     {0x3502, 0x00},
0147     {0x3503, 0x04},
0148     {0x3504, 0x03},
0149     {0x3505, 0x83},
0150     {0x3508, 0x04},
0151     {0x3509, 0x00},
0152     {0x350e, 0x04},
0153     {0x350f, 0x00},
0154     {0x3510, 0x00},
0155     {0x3511, 0x02},
0156     {0x3512, 0x00},
0157     {0x3601, 0xc8},
0158     {0x3610, 0x88},
0159     {0x3612, 0x48},
0160     {0x3614, 0x5b},
0161     {0x3615, 0x96},
0162     {0x3621, 0xd0},
0163     {0x3622, 0x00},
0164     {0x3623, 0x00},
0165     {0x3633, 0x13},
0166     {0x3634, 0x13},
0167     {0x3635, 0x13},
0168     {0x3636, 0x13},
0169     {0x3645, 0x13},
0170     {0x3646, 0x82},
0171     {0x3650, 0x00},
0172     {0x3652, 0xff},
0173     {0x3655, 0x20},
0174     {0x3656, 0xff},
0175     {0x365a, 0xff},
0176     {0x365e, 0xff},
0177     {0x3668, 0x00},
0178     {0x366a, 0x07},
0179     {0x366e, 0x10},
0180     {0x366d, 0x00},
0181     {0x366f, 0x80},
0182     {0x3700, 0x28},
0183     {0x3701, 0x10},
0184     {0x3702, 0x3a},
0185     {0x3703, 0x19},
0186     {0x3704, 0x10},
0187     {0x3705, 0x00},
0188     {0x3706, 0x66},
0189     {0x3707, 0x08},
0190     {0x3708, 0x34},
0191     {0x3709, 0x40},
0192     {0x370a, 0x01},
0193     {0x370b, 0x1b},
0194     {0x3714, 0x24},
0195     {0x371a, 0x3e},
0196     {0x3733, 0x00},
0197     {0x3734, 0x00},
0198     {0x373a, 0x05},
0199     {0x373b, 0x06},
0200     {0x373c, 0x0a},
0201     {0x373f, 0xa0},
0202     {0x3755, 0x00},
0203     {0x3758, 0x00},
0204     {0x375b, 0x0e},
0205     {0x3766, 0x5f},
0206     {0x3768, 0x00},
0207     {0x3769, 0x22},
0208     {0x3773, 0x08},
0209     {0x3774, 0x1f},
0210     {0x3776, 0x06},
0211     {0x37a0, 0x88},
0212     {0x37a1, 0x5c},
0213     {0x37a7, 0x88},
0214     {0x37a8, 0x70},
0215     {0x37aa, 0x88},
0216     {0x37ab, 0x48},
0217     {0x37b3, 0x66},
0218     {0x37c2, 0x04},
0219     {0x37c5, 0x00},
0220     {0x37c8, 0x00},
0221     {0x3800, 0x00},
0222     {0x3801, 0x0c},
0223     {0x3802, 0x00},
0224     {0x3803, 0x04},
0225     {0x3804, 0x0a},
0226     {0x3805, 0x33},
0227     {0x3806, 0x07},
0228     {0x3807, 0xa3},
0229     {0x3808, 0x0a},
0230     {0x3809, 0x20},
0231     {0x380a, 0x07},
0232     {0x380b, 0x98},
0233     {0x380c, 0x06},
0234     {0x380d, 0x90},
0235     {0x380e, 0x08},
0236     {0x380f, 0x08},
0237     {0x3811, 0x04},
0238     {0x3813, 0x02},
0239     {0x3814, 0x01},
0240     {0x3815, 0x01},
0241     {0x3816, 0x00},
0242     {0x3817, 0x00},
0243     {0x3818, 0x00},
0244     {0x3819, 0x00},
0245     {0x3820, 0x84},
0246     {0x3821, 0x46},
0247     {0x3822, 0x48},
0248     {0x3826, 0x00},
0249     {0x3827, 0x08},
0250     {0x382a, 0x01},
0251     {0x382b, 0x01},
0252     {0x3830, 0x08},
0253     {0x3836, 0x02},
0254     {0x3837, 0x00},
0255     {0x3838, 0x10},
0256     {0x3841, 0xff},
0257     {0x3846, 0x48},
0258     {0x3861, 0x00},
0259     {0x3862, 0x04},
0260     {0x3863, 0x06},
0261     {0x3a11, 0x01},
0262     {0x3a12, 0x78},
0263     {0x3b00, 0x00},
0264     {0x3b02, 0x00},
0265     {0x3b03, 0x00},
0266     {0x3b04, 0x00},
0267     {0x3b05, 0x00},
0268     {0x3c00, 0x89},
0269     {0x3c01, 0xab},
0270     {0x3c02, 0x01},
0271     {0x3c03, 0x00},
0272     {0x3c04, 0x00},
0273     {0x3c05, 0x03},
0274     {0x3c06, 0x00},
0275     {0x3c07, 0x05},
0276     {0x3c0c, 0x00},
0277     {0x3c0d, 0x00},
0278     {0x3c0e, 0x00},
0279     {0x3c0f, 0x00},
0280     {0x3c40, 0x00},
0281     {0x3c41, 0xa3},
0282     {0x3c43, 0x7d},
0283     {0x3c45, 0xd7},
0284     {0x3c47, 0xfc},
0285     {0x3c50, 0x05},
0286     {0x3c52, 0xaa},
0287     {0x3c54, 0x71},
0288     {0x3c56, 0x80},
0289     {0x3d85, 0x17},
0290     {0x3f03, 0x00},
0291     {0x3f0a, 0x00},
0292     {0x3f0b, 0x00},
0293     {0x4001, 0x60},
0294     {0x4009, 0x0d},
0295     {0x4020, 0x00},
0296     {0x4021, 0x00},
0297     {0x4022, 0x00},
0298     {0x4023, 0x00},
0299     {0x4024, 0x00},
0300     {0x4025, 0x00},
0301     {0x4026, 0x00},
0302     {0x4027, 0x00},
0303     {0x4028, 0x00},
0304     {0x4029, 0x00},
0305     {0x402a, 0x00},
0306     {0x402b, 0x00},
0307     {0x402c, 0x00},
0308     {0x402d, 0x00},
0309     {0x402e, 0x00},
0310     {0x402f, 0x00},
0311     {0x4040, 0x00},
0312     {0x4041, 0x03},
0313     {0x4042, 0x00},
0314     {0x4043, 0x7A},
0315     {0x4044, 0x00},
0316     {0x4045, 0x7A},
0317     {0x4046, 0x00},
0318     {0x4047, 0x7A},
0319     {0x4048, 0x00},
0320     {0x4049, 0x7A},
0321     {0x4307, 0x30},
0322     {0x4500, 0x58},
0323     {0x4501, 0x04},
0324     {0x4502, 0x40},
0325     {0x4503, 0x10},
0326     {0x4508, 0xaa},
0327     {0x4509, 0xaa},
0328     {0x450a, 0x00},
0329     {0x450b, 0x00},
0330     {0x4600, 0x01},
0331     {0x4601, 0x03},
0332     {0x4700, 0xa4},
0333     {0x4800, 0x4c},
0334     {0x4816, 0x53},
0335     {0x481f, 0x40},
0336     {0x4837, 0x13},
0337     {0x5000, 0x56},
0338     {0x5001, 0x01},
0339     {0x5002, 0x28},
0340     {0x5004, 0x0c},
0341     {0x5006, 0x0c},
0342     {0x5007, 0xe0},
0343     {0x5008, 0x01},
0344     {0x5009, 0xb0},
0345     {0x5901, 0x00},
0346     {0x5a01, 0x00},
0347     {0x5a03, 0x00},
0348     {0x5a04, 0x0c},
0349     {0x5a05, 0xe0},
0350     {0x5a06, 0x09},
0351     {0x5a07, 0xb0},
0352     {0x5a08, 0x06},
0353     {0x5e00, 0x00},
0354     {0x3734, 0x40},
0355     {0x5b00, 0x01},
0356     {0x5b01, 0x10},
0357     {0x5b02, 0x01},
0358     {0x5b03, 0xdb},
0359     {0x3d8c, 0x71},
0360     {0x3d8d, 0xea},
0361     {0x4017, 0x08},
0362     {0x3618, 0x2a},
0363     {0x5780, 0x3e},
0364     {0x5781, 0x0f},
0365     {0x5782, 0x44},
0366     {0x5783, 0x02},
0367     {0x5784, 0x01},
0368     {0x5785, 0x01},
0369     {0x5786, 0x00},
0370     {0x5787, 0x04},
0371     {0x5788, 0x02},
0372     {0x5789, 0x0f},
0373     {0x578a, 0xfd},
0374     {0x578b, 0xf5},
0375     {0x578c, 0xf5},
0376     {0x578d, 0x03},
0377     {0x578e, 0x08},
0378     {0x578f, 0x0c},
0379     {0x5790, 0x08},
0380     {0x5791, 0x06},
0381     {0x5792, 0x00},
0382     {0x5793, 0x52},
0383     {0x5794, 0xa3},
0384     {0x3503, 0x00},
0385     {0x5045, 0x05},
0386     {0x4003, 0x40},
0387     {0x5048, 0x40}
0388 };
0389 
0390 static const struct ov5670_reg mode_1296x972_regs[] = {
0391     {0x3000, 0x00},
0392     {0x3002, 0x21},
0393     {0x3005, 0xf0},
0394     {0x3007, 0x00},
0395     {0x3015, 0x0f},
0396     {0x3018, 0x32},
0397     {0x301a, 0xf0},
0398     {0x301b, 0xf0},
0399     {0x301c, 0xf0},
0400     {0x301d, 0xf0},
0401     {0x301e, 0xf0},
0402     {0x3030, 0x00},
0403     {0x3031, 0x0a},
0404     {0x303c, 0xff},
0405     {0x303e, 0xff},
0406     {0x3040, 0xf0},
0407     {0x3041, 0x00},
0408     {0x3042, 0xf0},
0409     {0x3106, 0x11},
0410     {0x3500, 0x00},
0411     {0x3501, 0x80},
0412     {0x3502, 0x00},
0413     {0x3503, 0x04},
0414     {0x3504, 0x03},
0415     {0x3505, 0x83},
0416     {0x3508, 0x07},
0417     {0x3509, 0x80},
0418     {0x350e, 0x04},
0419     {0x350f, 0x00},
0420     {0x3510, 0x00},
0421     {0x3511, 0x02},
0422     {0x3512, 0x00},
0423     {0x3601, 0xc8},
0424     {0x3610, 0x88},
0425     {0x3612, 0x48},
0426     {0x3614, 0x5b},
0427     {0x3615, 0x96},
0428     {0x3621, 0xd0},
0429     {0x3622, 0x00},
0430     {0x3623, 0x00},
0431     {0x3633, 0x13},
0432     {0x3634, 0x13},
0433     {0x3635, 0x13},
0434     {0x3636, 0x13},
0435     {0x3645, 0x13},
0436     {0x3646, 0x82},
0437     {0x3650, 0x00},
0438     {0x3652, 0xff},
0439     {0x3655, 0x20},
0440     {0x3656, 0xff},
0441     {0x365a, 0xff},
0442     {0x365e, 0xff},
0443     {0x3668, 0x00},
0444     {0x366a, 0x07},
0445     {0x366e, 0x08},
0446     {0x366d, 0x00},
0447     {0x366f, 0x80},
0448     {0x3700, 0x28},
0449     {0x3701, 0x10},
0450     {0x3702, 0x3a},
0451     {0x3703, 0x19},
0452     {0x3704, 0x10},
0453     {0x3705, 0x00},
0454     {0x3706, 0x66},
0455     {0x3707, 0x08},
0456     {0x3708, 0x34},
0457     {0x3709, 0x40},
0458     {0x370a, 0x01},
0459     {0x370b, 0x1b},
0460     {0x3714, 0x24},
0461     {0x371a, 0x3e},
0462     {0x3733, 0x00},
0463     {0x3734, 0x00},
0464     {0x373a, 0x05},
0465     {0x373b, 0x06},
0466     {0x373c, 0x0a},
0467     {0x373f, 0xa0},
0468     {0x3755, 0x00},
0469     {0x3758, 0x00},
0470     {0x375b, 0x0e},
0471     {0x3766, 0x5f},
0472     {0x3768, 0x00},
0473     {0x3769, 0x22},
0474     {0x3773, 0x08},
0475     {0x3774, 0x1f},
0476     {0x3776, 0x06},
0477     {0x37a0, 0x88},
0478     {0x37a1, 0x5c},
0479     {0x37a7, 0x88},
0480     {0x37a8, 0x70},
0481     {0x37aa, 0x88},
0482     {0x37ab, 0x48},
0483     {0x37b3, 0x66},
0484     {0x37c2, 0x04},
0485     {0x37c5, 0x00},
0486     {0x37c8, 0x00},
0487     {0x3800, 0x00},
0488     {0x3801, 0x0c},
0489     {0x3802, 0x00},
0490     {0x3803, 0x04},
0491     {0x3804, 0x0a},
0492     {0x3805, 0x33},
0493     {0x3806, 0x07},
0494     {0x3807, 0xa3},
0495     {0x3808, 0x05},
0496     {0x3809, 0x10},
0497     {0x380a, 0x03},
0498     {0x380b, 0xcc},
0499     {0x380c, 0x06},
0500     {0x380d, 0x90},
0501     {0x380e, 0x08},
0502     {0x380f, 0x08},
0503     {0x3811, 0x04},
0504     {0x3813, 0x04},
0505     {0x3814, 0x03},
0506     {0x3815, 0x01},
0507     {0x3816, 0x00},
0508     {0x3817, 0x00},
0509     {0x3818, 0x00},
0510     {0x3819, 0x00},
0511     {0x3820, 0x94},
0512     {0x3821, 0x47},
0513     {0x3822, 0x48},
0514     {0x3826, 0x00},
0515     {0x3827, 0x08},
0516     {0x382a, 0x03},
0517     {0x382b, 0x01},
0518     {0x3830, 0x08},
0519     {0x3836, 0x02},
0520     {0x3837, 0x00},
0521     {0x3838, 0x10},
0522     {0x3841, 0xff},
0523     {0x3846, 0x48},
0524     {0x3861, 0x00},
0525     {0x3862, 0x04},
0526     {0x3863, 0x06},
0527     {0x3a11, 0x01},
0528     {0x3a12, 0x78},
0529     {0x3b00, 0x00},
0530     {0x3b02, 0x00},
0531     {0x3b03, 0x00},
0532     {0x3b04, 0x00},
0533     {0x3b05, 0x00},
0534     {0x3c00, 0x89},
0535     {0x3c01, 0xab},
0536     {0x3c02, 0x01},
0537     {0x3c03, 0x00},
0538     {0x3c04, 0x00},
0539     {0x3c05, 0x03},
0540     {0x3c06, 0x00},
0541     {0x3c07, 0x05},
0542     {0x3c0c, 0x00},
0543     {0x3c0d, 0x00},
0544     {0x3c0e, 0x00},
0545     {0x3c0f, 0x00},
0546     {0x3c40, 0x00},
0547     {0x3c41, 0xa3},
0548     {0x3c43, 0x7d},
0549     {0x3c45, 0xd7},
0550     {0x3c47, 0xfc},
0551     {0x3c50, 0x05},
0552     {0x3c52, 0xaa},
0553     {0x3c54, 0x71},
0554     {0x3c56, 0x80},
0555     {0x3d85, 0x17},
0556     {0x3f03, 0x00},
0557     {0x3f0a, 0x00},
0558     {0x3f0b, 0x00},
0559     {0x4001, 0x60},
0560     {0x4009, 0x05},
0561     {0x4020, 0x00},
0562     {0x4021, 0x00},
0563     {0x4022, 0x00},
0564     {0x4023, 0x00},
0565     {0x4024, 0x00},
0566     {0x4025, 0x00},
0567     {0x4026, 0x00},
0568     {0x4027, 0x00},
0569     {0x4028, 0x00},
0570     {0x4029, 0x00},
0571     {0x402a, 0x00},
0572     {0x402b, 0x00},
0573     {0x402c, 0x00},
0574     {0x402d, 0x00},
0575     {0x402e, 0x00},
0576     {0x402f, 0x00},
0577     {0x4040, 0x00},
0578     {0x4041, 0x03},
0579     {0x4042, 0x00},
0580     {0x4043, 0x7A},
0581     {0x4044, 0x00},
0582     {0x4045, 0x7A},
0583     {0x4046, 0x00},
0584     {0x4047, 0x7A},
0585     {0x4048, 0x00},
0586     {0x4049, 0x7A},
0587     {0x4307, 0x30},
0588     {0x4500, 0x58},
0589     {0x4501, 0x04},
0590     {0x4502, 0x48},
0591     {0x4503, 0x10},
0592     {0x4508, 0x55},
0593     {0x4509, 0x55},
0594     {0x450a, 0x00},
0595     {0x450b, 0x00},
0596     {0x4600, 0x00},
0597     {0x4601, 0x81},
0598     {0x4700, 0xa4},
0599     {0x4800, 0x4c},
0600     {0x4816, 0x53},
0601     {0x481f, 0x40},
0602     {0x4837, 0x13},
0603     {0x5000, 0x56},
0604     {0x5001, 0x01},
0605     {0x5002, 0x28},
0606     {0x5004, 0x0c},
0607     {0x5006, 0x0c},
0608     {0x5007, 0xe0},
0609     {0x5008, 0x01},
0610     {0x5009, 0xb0},
0611     {0x5901, 0x00},
0612     {0x5a01, 0x00},
0613     {0x5a03, 0x00},
0614     {0x5a04, 0x0c},
0615     {0x5a05, 0xe0},
0616     {0x5a06, 0x09},
0617     {0x5a07, 0xb0},
0618     {0x5a08, 0x06},
0619     {0x5e00, 0x00},
0620     {0x3734, 0x40},
0621     {0x5b00, 0x01},
0622     {0x5b01, 0x10},
0623     {0x5b02, 0x01},
0624     {0x5b03, 0xdb},
0625     {0x3d8c, 0x71},
0626     {0x3d8d, 0xea},
0627     {0x4017, 0x10},
0628     {0x3618, 0x2a},
0629     {0x5780, 0x3e},
0630     {0x5781, 0x0f},
0631     {0x5782, 0x44},
0632     {0x5783, 0x02},
0633     {0x5784, 0x01},
0634     {0x5785, 0x01},
0635     {0x5786, 0x00},
0636     {0x5787, 0x04},
0637     {0x5788, 0x02},
0638     {0x5789, 0x0f},
0639     {0x578a, 0xfd},
0640     {0x578b, 0xf5},
0641     {0x578c, 0xf5},
0642     {0x578d, 0x03},
0643     {0x578e, 0x08},
0644     {0x578f, 0x0c},
0645     {0x5790, 0x08},
0646     {0x5791, 0x04},
0647     {0x5792, 0x00},
0648     {0x5793, 0x52},
0649     {0x5794, 0xa3},
0650     {0x3503, 0x00},
0651     {0x5045, 0x05},
0652     {0x4003, 0x40},
0653     {0x5048, 0x40}
0654 };
0655 
0656 static const struct ov5670_reg mode_648x486_regs[] = {
0657     {0x3000, 0x00},
0658     {0x3002, 0x21},
0659     {0x3005, 0xf0},
0660     {0x3007, 0x00},
0661     {0x3015, 0x0f},
0662     {0x3018, 0x32},
0663     {0x301a, 0xf0},
0664     {0x301b, 0xf0},
0665     {0x301c, 0xf0},
0666     {0x301d, 0xf0},
0667     {0x301e, 0xf0},
0668     {0x3030, 0x00},
0669     {0x3031, 0x0a},
0670     {0x303c, 0xff},
0671     {0x303e, 0xff},
0672     {0x3040, 0xf0},
0673     {0x3041, 0x00},
0674     {0x3042, 0xf0},
0675     {0x3106, 0x11},
0676     {0x3500, 0x00},
0677     {0x3501, 0x80},
0678     {0x3502, 0x00},
0679     {0x3503, 0x04},
0680     {0x3504, 0x03},
0681     {0x3505, 0x83},
0682     {0x3508, 0x04},
0683     {0x3509, 0x00},
0684     {0x350e, 0x04},
0685     {0x350f, 0x00},
0686     {0x3510, 0x00},
0687     {0x3511, 0x02},
0688     {0x3512, 0x00},
0689     {0x3601, 0xc8},
0690     {0x3610, 0x88},
0691     {0x3612, 0x48},
0692     {0x3614, 0x5b},
0693     {0x3615, 0x96},
0694     {0x3621, 0xd0},
0695     {0x3622, 0x00},
0696     {0x3623, 0x04},
0697     {0x3633, 0x13},
0698     {0x3634, 0x13},
0699     {0x3635, 0x13},
0700     {0x3636, 0x13},
0701     {0x3645, 0x13},
0702     {0x3646, 0x82},
0703     {0x3650, 0x00},
0704     {0x3652, 0xff},
0705     {0x3655, 0x20},
0706     {0x3656, 0xff},
0707     {0x365a, 0xff},
0708     {0x365e, 0xff},
0709     {0x3668, 0x00},
0710     {0x366a, 0x07},
0711     {0x366e, 0x08},
0712     {0x366d, 0x00},
0713     {0x366f, 0x80},
0714     {0x3700, 0x28},
0715     {0x3701, 0x10},
0716     {0x3702, 0x3a},
0717     {0x3703, 0x19},
0718     {0x3704, 0x10},
0719     {0x3705, 0x00},
0720     {0x3706, 0x66},
0721     {0x3707, 0x08},
0722     {0x3708, 0x34},
0723     {0x3709, 0x40},
0724     {0x370a, 0x01},
0725     {0x370b, 0x1b},
0726     {0x3714, 0x24},
0727     {0x371a, 0x3e},
0728     {0x3733, 0x00},
0729     {0x3734, 0x00},
0730     {0x373a, 0x05},
0731     {0x373b, 0x06},
0732     {0x373c, 0x0a},
0733     {0x373f, 0xa0},
0734     {0x3755, 0x00},
0735     {0x3758, 0x00},
0736     {0x375b, 0x0e},
0737     {0x3766, 0x5f},
0738     {0x3768, 0x00},
0739     {0x3769, 0x22},
0740     {0x3773, 0x08},
0741     {0x3774, 0x1f},
0742     {0x3776, 0x06},
0743     {0x37a0, 0x88},
0744     {0x37a1, 0x5c},
0745     {0x37a7, 0x88},
0746     {0x37a8, 0x70},
0747     {0x37aa, 0x88},
0748     {0x37ab, 0x48},
0749     {0x37b3, 0x66},
0750     {0x37c2, 0x04},
0751     {0x37c5, 0x00},
0752     {0x37c8, 0x00},
0753     {0x3800, 0x00},
0754     {0x3801, 0x0c},
0755     {0x3802, 0x00},
0756     {0x3803, 0x04},
0757     {0x3804, 0x0a},
0758     {0x3805, 0x33},
0759     {0x3806, 0x07},
0760     {0x3807, 0xa3},
0761     {0x3808, 0x02},
0762     {0x3809, 0x88},
0763     {0x380a, 0x01},
0764     {0x380b, 0xe6},
0765     {0x380c, 0x06},
0766     {0x380d, 0x90},
0767     {0x380e, 0x08},
0768     {0x380f, 0x08},
0769     {0x3811, 0x04},
0770     {0x3813, 0x02},
0771     {0x3814, 0x07},
0772     {0x3815, 0x01},
0773     {0x3816, 0x00},
0774     {0x3817, 0x00},
0775     {0x3818, 0x00},
0776     {0x3819, 0x00},
0777     {0x3820, 0x94},
0778     {0x3821, 0xc6},
0779     {0x3822, 0x48},
0780     {0x3826, 0x00},
0781     {0x3827, 0x08},
0782     {0x382a, 0x07},
0783     {0x382b, 0x01},
0784     {0x3830, 0x08},
0785     {0x3836, 0x02},
0786     {0x3837, 0x00},
0787     {0x3838, 0x10},
0788     {0x3841, 0xff},
0789     {0x3846, 0x48},
0790     {0x3861, 0x00},
0791     {0x3862, 0x04},
0792     {0x3863, 0x06},
0793     {0x3a11, 0x01},
0794     {0x3a12, 0x78},
0795     {0x3b00, 0x00},
0796     {0x3b02, 0x00},
0797     {0x3b03, 0x00},
0798     {0x3b04, 0x00},
0799     {0x3b05, 0x00},
0800     {0x3c00, 0x89},
0801     {0x3c01, 0xab},
0802     {0x3c02, 0x01},
0803     {0x3c03, 0x00},
0804     {0x3c04, 0x00},
0805     {0x3c05, 0x03},
0806     {0x3c06, 0x00},
0807     {0x3c07, 0x05},
0808     {0x3c0c, 0x00},
0809     {0x3c0d, 0x00},
0810     {0x3c0e, 0x00},
0811     {0x3c0f, 0x00},
0812     {0x3c40, 0x00},
0813     {0x3c41, 0xa3},
0814     {0x3c43, 0x7d},
0815     {0x3c45, 0xd7},
0816     {0x3c47, 0xfc},
0817     {0x3c50, 0x05},
0818     {0x3c52, 0xaa},
0819     {0x3c54, 0x71},
0820     {0x3c56, 0x80},
0821     {0x3d85, 0x17},
0822     {0x3f03, 0x00},
0823     {0x3f0a, 0x00},
0824     {0x3f0b, 0x00},
0825     {0x4001, 0x60},
0826     {0x4009, 0x05},
0827     {0x4020, 0x00},
0828     {0x4021, 0x00},
0829     {0x4022, 0x00},
0830     {0x4023, 0x00},
0831     {0x4024, 0x00},
0832     {0x4025, 0x00},
0833     {0x4026, 0x00},
0834     {0x4027, 0x00},
0835     {0x4028, 0x00},
0836     {0x4029, 0x00},
0837     {0x402a, 0x00},
0838     {0x402b, 0x00},
0839     {0x402c, 0x00},
0840     {0x402d, 0x00},
0841     {0x402e, 0x00},
0842     {0x402f, 0x00},
0843     {0x4040, 0x00},
0844     {0x4041, 0x03},
0845     {0x4042, 0x00},
0846     {0x4043, 0x7A},
0847     {0x4044, 0x00},
0848     {0x4045, 0x7A},
0849     {0x4046, 0x00},
0850     {0x4047, 0x7A},
0851     {0x4048, 0x00},
0852     {0x4049, 0x7A},
0853     {0x4307, 0x30},
0854     {0x4500, 0x58},
0855     {0x4501, 0x04},
0856     {0x4502, 0x40},
0857     {0x4503, 0x10},
0858     {0x4508, 0x55},
0859     {0x4509, 0x55},
0860     {0x450a, 0x02},
0861     {0x450b, 0x00},
0862     {0x4600, 0x00},
0863     {0x4601, 0x40},
0864     {0x4700, 0xa4},
0865     {0x4800, 0x4c},
0866     {0x4816, 0x53},
0867     {0x481f, 0x40},
0868     {0x4837, 0x13},
0869     {0x5000, 0x56},
0870     {0x5001, 0x01},
0871     {0x5002, 0x28},
0872     {0x5004, 0x0c},
0873     {0x5006, 0x0c},
0874     {0x5007, 0xe0},
0875     {0x5008, 0x01},
0876     {0x5009, 0xb0},
0877     {0x5901, 0x00},
0878     {0x5a01, 0x00},
0879     {0x5a03, 0x00},
0880     {0x5a04, 0x0c},
0881     {0x5a05, 0xe0},
0882     {0x5a06, 0x09},
0883     {0x5a07, 0xb0},
0884     {0x5a08, 0x06},
0885     {0x5e00, 0x00},
0886     {0x3734, 0x40},
0887     {0x5b00, 0x01},
0888     {0x5b01, 0x10},
0889     {0x5b02, 0x01},
0890     {0x5b03, 0xdb},
0891     {0x3d8c, 0x71},
0892     {0x3d8d, 0xea},
0893     {0x4017, 0x10},
0894     {0x3618, 0x2a},
0895     {0x5780, 0x3e},
0896     {0x5781, 0x0f},
0897     {0x5782, 0x44},
0898     {0x5783, 0x02},
0899     {0x5784, 0x01},
0900     {0x5785, 0x01},
0901     {0x5786, 0x00},
0902     {0x5787, 0x04},
0903     {0x5788, 0x02},
0904     {0x5789, 0x0f},
0905     {0x578a, 0xfd},
0906     {0x578b, 0xf5},
0907     {0x578c, 0xf5},
0908     {0x578d, 0x03},
0909     {0x578e, 0x08},
0910     {0x578f, 0x0c},
0911     {0x5790, 0x08},
0912     {0x5791, 0x06},
0913     {0x5792, 0x00},
0914     {0x5793, 0x52},
0915     {0x5794, 0xa3},
0916     {0x3503, 0x00},
0917     {0x5045, 0x05},
0918     {0x4003, 0x40},
0919     {0x5048, 0x40}
0920 };
0921 
0922 static const struct ov5670_reg mode_2560x1440_regs[] = {
0923     {0x3000, 0x00},
0924     {0x3002, 0x21},
0925     {0x3005, 0xf0},
0926     {0x3007, 0x00},
0927     {0x3015, 0x0f},
0928     {0x3018, 0x32},
0929     {0x301a, 0xf0},
0930     {0x301b, 0xf0},
0931     {0x301c, 0xf0},
0932     {0x301d, 0xf0},
0933     {0x301e, 0xf0},
0934     {0x3030, 0x00},
0935     {0x3031, 0x0a},
0936     {0x303c, 0xff},
0937     {0x303e, 0xff},
0938     {0x3040, 0xf0},
0939     {0x3041, 0x00},
0940     {0x3042, 0xf0},
0941     {0x3106, 0x11},
0942     {0x3500, 0x00},
0943     {0x3501, 0x80},
0944     {0x3502, 0x00},
0945     {0x3503, 0x04},
0946     {0x3504, 0x03},
0947     {0x3505, 0x83},
0948     {0x3508, 0x04},
0949     {0x3509, 0x00},
0950     {0x350e, 0x04},
0951     {0x350f, 0x00},
0952     {0x3510, 0x00},
0953     {0x3511, 0x02},
0954     {0x3512, 0x00},
0955     {0x3601, 0xc8},
0956     {0x3610, 0x88},
0957     {0x3612, 0x48},
0958     {0x3614, 0x5b},
0959     {0x3615, 0x96},
0960     {0x3621, 0xd0},
0961     {0x3622, 0x00},
0962     {0x3623, 0x00},
0963     {0x3633, 0x13},
0964     {0x3634, 0x13},
0965     {0x3635, 0x13},
0966     {0x3636, 0x13},
0967     {0x3645, 0x13},
0968     {0x3646, 0x82},
0969     {0x3650, 0x00},
0970     {0x3652, 0xff},
0971     {0x3655, 0x20},
0972     {0x3656, 0xff},
0973     {0x365a, 0xff},
0974     {0x365e, 0xff},
0975     {0x3668, 0x00},
0976     {0x366a, 0x07},
0977     {0x366e, 0x10},
0978     {0x366d, 0x00},
0979     {0x366f, 0x80},
0980     {0x3700, 0x28},
0981     {0x3701, 0x10},
0982     {0x3702, 0x3a},
0983     {0x3703, 0x19},
0984     {0x3704, 0x10},
0985     {0x3705, 0x00},
0986     {0x3706, 0x66},
0987     {0x3707, 0x08},
0988     {0x3708, 0x34},
0989     {0x3709, 0x40},
0990     {0x370a, 0x01},
0991     {0x370b, 0x1b},
0992     {0x3714, 0x24},
0993     {0x371a, 0x3e},
0994     {0x3733, 0x00},
0995     {0x3734, 0x00},
0996     {0x373a, 0x05},
0997     {0x373b, 0x06},
0998     {0x373c, 0x0a},
0999     {0x373f, 0xa0},
1000     {0x3755, 0x00},
1001     {0x3758, 0x00},
1002     {0x375b, 0x0e},
1003     {0x3766, 0x5f},
1004     {0x3768, 0x00},
1005     {0x3769, 0x22},
1006     {0x3773, 0x08},
1007     {0x3774, 0x1f},
1008     {0x3776, 0x06},
1009     {0x37a0, 0x88},
1010     {0x37a1, 0x5c},
1011     {0x37a7, 0x88},
1012     {0x37a8, 0x70},
1013     {0x37aa, 0x88},
1014     {0x37ab, 0x48},
1015     {0x37b3, 0x66},
1016     {0x37c2, 0x04},
1017     {0x37c5, 0x00},
1018     {0x37c8, 0x00},
1019     {0x3800, 0x00},
1020     {0x3801, 0x0c},
1021     {0x3802, 0x00},
1022     {0x3803, 0x04},
1023     {0x3804, 0x0a},
1024     {0x3805, 0x33},
1025     {0x3806, 0x07},
1026     {0x3807, 0xa3},
1027     {0x3808, 0x0a},
1028     {0x3809, 0x00},
1029     {0x380a, 0x05},
1030     {0x380b, 0xa0},
1031     {0x380c, 0x06},
1032     {0x380d, 0x90},
1033     {0x380e, 0x08},
1034     {0x380f, 0x08},
1035     {0x3811, 0x04},
1036     {0x3813, 0x02},
1037     {0x3814, 0x01},
1038     {0x3815, 0x01},
1039     {0x3816, 0x00},
1040     {0x3817, 0x00},
1041     {0x3818, 0x00},
1042     {0x3819, 0x00},
1043     {0x3820, 0x84},
1044     {0x3821, 0x46},
1045     {0x3822, 0x48},
1046     {0x3826, 0x00},
1047     {0x3827, 0x08},
1048     {0x382a, 0x01},
1049     {0x382b, 0x01},
1050     {0x3830, 0x08},
1051     {0x3836, 0x02},
1052     {0x3837, 0x00},
1053     {0x3838, 0x10},
1054     {0x3841, 0xff},
1055     {0x3846, 0x48},
1056     {0x3861, 0x00},
1057     {0x3862, 0x04},
1058     {0x3863, 0x06},
1059     {0x3a11, 0x01},
1060     {0x3a12, 0x78},
1061     {0x3b00, 0x00},
1062     {0x3b02, 0x00},
1063     {0x3b03, 0x00},
1064     {0x3b04, 0x00},
1065     {0x3b05, 0x00},
1066     {0x3c00, 0x89},
1067     {0x3c01, 0xab},
1068     {0x3c02, 0x01},
1069     {0x3c03, 0x00},
1070     {0x3c04, 0x00},
1071     {0x3c05, 0x03},
1072     {0x3c06, 0x00},
1073     {0x3c07, 0x05},
1074     {0x3c0c, 0x00},
1075     {0x3c0d, 0x00},
1076     {0x3c0e, 0x00},
1077     {0x3c0f, 0x00},
1078     {0x3c40, 0x00},
1079     {0x3c41, 0xa3},
1080     {0x3c43, 0x7d},
1081     {0x3c45, 0xd7},
1082     {0x3c47, 0xfc},
1083     {0x3c50, 0x05},
1084     {0x3c52, 0xaa},
1085     {0x3c54, 0x71},
1086     {0x3c56, 0x80},
1087     {0x3d85, 0x17},
1088     {0x3f03, 0x00},
1089     {0x3f0a, 0x00},
1090     {0x3f0b, 0x00},
1091     {0x4001, 0x60},
1092     {0x4009, 0x0d},
1093     {0x4020, 0x00},
1094     {0x4021, 0x00},
1095     {0x4022, 0x00},
1096     {0x4023, 0x00},
1097     {0x4024, 0x00},
1098     {0x4025, 0x00},
1099     {0x4026, 0x00},
1100     {0x4027, 0x00},
1101     {0x4028, 0x00},
1102     {0x4029, 0x00},
1103     {0x402a, 0x00},
1104     {0x402b, 0x00},
1105     {0x402c, 0x00},
1106     {0x402d, 0x00},
1107     {0x402e, 0x00},
1108     {0x402f, 0x00},
1109     {0x4040, 0x00},
1110     {0x4041, 0x03},
1111     {0x4042, 0x00},
1112     {0x4043, 0x7A},
1113     {0x4044, 0x00},
1114     {0x4045, 0x7A},
1115     {0x4046, 0x00},
1116     {0x4047, 0x7A},
1117     {0x4048, 0x00},
1118     {0x4049, 0x7A},
1119     {0x4307, 0x30},
1120     {0x4500, 0x58},
1121     {0x4501, 0x04},
1122     {0x4502, 0x40},
1123     {0x4503, 0x10},
1124     {0x4508, 0xaa},
1125     {0x4509, 0xaa},
1126     {0x450a, 0x00},
1127     {0x450b, 0x00},
1128     {0x4600, 0x01},
1129     {0x4601, 0x00},
1130     {0x4700, 0xa4},
1131     {0x4800, 0x4c},
1132     {0x4816, 0x53},
1133     {0x481f, 0x40},
1134     {0x4837, 0x13},
1135     {0x5000, 0x56},
1136     {0x5001, 0x01},
1137     {0x5002, 0x28},
1138     {0x5004, 0x0c},
1139     {0x5006, 0x0c},
1140     {0x5007, 0xe0},
1141     {0x5008, 0x01},
1142     {0x5009, 0xb0},
1143     {0x5901, 0x00},
1144     {0x5a01, 0x00},
1145     {0x5a03, 0x00},
1146     {0x5a04, 0x0c},
1147     {0x5a05, 0xe0},
1148     {0x5a06, 0x09},
1149     {0x5a07, 0xb0},
1150     {0x5a08, 0x06},
1151     {0x5e00, 0x00},
1152     {0x3734, 0x40},
1153     {0x5b00, 0x01},
1154     {0x5b01, 0x10},
1155     {0x5b02, 0x01},
1156     {0x5b03, 0xdb},
1157     {0x3d8c, 0x71},
1158     {0x3d8d, 0xea},
1159     {0x4017, 0x08},
1160     {0x3618, 0x2a},
1161     {0x5780, 0x3e},
1162     {0x5781, 0x0f},
1163     {0x5782, 0x44},
1164     {0x5783, 0x02},
1165     {0x5784, 0x01},
1166     {0x5785, 0x01},
1167     {0x5786, 0x00},
1168     {0x5787, 0x04},
1169     {0x5788, 0x02},
1170     {0x5789, 0x0f},
1171     {0x578a, 0xfd},
1172     {0x578b, 0xf5},
1173     {0x578c, 0xf5},
1174     {0x578d, 0x03},
1175     {0x578e, 0x08},
1176     {0x578f, 0x0c},
1177     {0x5790, 0x08},
1178     {0x5791, 0x06},
1179     {0x5792, 0x00},
1180     {0x5793, 0x52},
1181     {0x5794, 0xa3},
1182     {0x5045, 0x05},
1183     {0x4003, 0x40},
1184     {0x5048, 0x40}
1185 };
1186 
1187 static const struct ov5670_reg mode_1280x720_regs[] = {
1188     {0x3000, 0x00},
1189     {0x3002, 0x21},
1190     {0x3005, 0xf0},
1191     {0x3007, 0x00},
1192     {0x3015, 0x0f},
1193     {0x3018, 0x32},
1194     {0x301a, 0xf0},
1195     {0x301b, 0xf0},
1196     {0x301c, 0xf0},
1197     {0x301d, 0xf0},
1198     {0x301e, 0xf0},
1199     {0x3030, 0x00},
1200     {0x3031, 0x0a},
1201     {0x303c, 0xff},
1202     {0x303e, 0xff},
1203     {0x3040, 0xf0},
1204     {0x3041, 0x00},
1205     {0x3042, 0xf0},
1206     {0x3106, 0x11},
1207     {0x3500, 0x00},
1208     {0x3501, 0x80},
1209     {0x3502, 0x00},
1210     {0x3503, 0x04},
1211     {0x3504, 0x03},
1212     {0x3505, 0x83},
1213     {0x3508, 0x04},
1214     {0x3509, 0x00},
1215     {0x350e, 0x04},
1216     {0x350f, 0x00},
1217     {0x3510, 0x00},
1218     {0x3511, 0x02},
1219     {0x3512, 0x00},
1220     {0x3601, 0xc8},
1221     {0x3610, 0x88},
1222     {0x3612, 0x48},
1223     {0x3614, 0x5b},
1224     {0x3615, 0x96},
1225     {0x3621, 0xd0},
1226     {0x3622, 0x00},
1227     {0x3623, 0x00},
1228     {0x3633, 0x13},
1229     {0x3634, 0x13},
1230     {0x3635, 0x13},
1231     {0x3636, 0x13},
1232     {0x3645, 0x13},
1233     {0x3646, 0x82},
1234     {0x3650, 0x00},
1235     {0x3652, 0xff},
1236     {0x3655, 0x20},
1237     {0x3656, 0xff},
1238     {0x365a, 0xff},
1239     {0x365e, 0xff},
1240     {0x3668, 0x00},
1241     {0x366a, 0x07},
1242     {0x366e, 0x08},
1243     {0x366d, 0x00},
1244     {0x366f, 0x80},
1245     {0x3700, 0x28},
1246     {0x3701, 0x10},
1247     {0x3702, 0x3a},
1248     {0x3703, 0x19},
1249     {0x3704, 0x10},
1250     {0x3705, 0x00},
1251     {0x3706, 0x66},
1252     {0x3707, 0x08},
1253     {0x3708, 0x34},
1254     {0x3709, 0x40},
1255     {0x370a, 0x01},
1256     {0x370b, 0x1b},
1257     {0x3714, 0x24},
1258     {0x371a, 0x3e},
1259     {0x3733, 0x00},
1260     {0x3734, 0x00},
1261     {0x373a, 0x05},
1262     {0x373b, 0x06},
1263     {0x373c, 0x0a},
1264     {0x373f, 0xa0},
1265     {0x3755, 0x00},
1266     {0x3758, 0x00},
1267     {0x375b, 0x0e},
1268     {0x3766, 0x5f},
1269     {0x3768, 0x00},
1270     {0x3769, 0x22},
1271     {0x3773, 0x08},
1272     {0x3774, 0x1f},
1273     {0x3776, 0x06},
1274     {0x37a0, 0x88},
1275     {0x37a1, 0x5c},
1276     {0x37a7, 0x88},
1277     {0x37a8, 0x70},
1278     {0x37aa, 0x88},
1279     {0x37ab, 0x48},
1280     {0x37b3, 0x66},
1281     {0x37c2, 0x04},
1282     {0x37c5, 0x00},
1283     {0x37c8, 0x00},
1284     {0x3800, 0x00},
1285     {0x3801, 0x0c},
1286     {0x3802, 0x00},
1287     {0x3803, 0x04},
1288     {0x3804, 0x0a},
1289     {0x3805, 0x33},
1290     {0x3806, 0x07},
1291     {0x3807, 0xa3},
1292     {0x3808, 0x05},
1293     {0x3809, 0x00},
1294     {0x380a, 0x02},
1295     {0x380b, 0xd0},
1296     {0x380c, 0x06},
1297     {0x380d, 0x90},
1298     {0x380e, 0x08},
1299     {0x380f, 0x08},
1300     {0x3811, 0x04},
1301     {0x3813, 0x02},
1302     {0x3814, 0x03},
1303     {0x3815, 0x01},
1304     {0x3816, 0x00},
1305     {0x3817, 0x00},
1306     {0x3818, 0x00},
1307     {0x3819, 0x00},
1308     {0x3820, 0x94},
1309     {0x3821, 0x47},
1310     {0x3822, 0x48},
1311     {0x3826, 0x00},
1312     {0x3827, 0x08},
1313     {0x382a, 0x03},
1314     {0x382b, 0x01},
1315     {0x3830, 0x08},
1316     {0x3836, 0x02},
1317     {0x3837, 0x00},
1318     {0x3838, 0x10},
1319     {0x3841, 0xff},
1320     {0x3846, 0x48},
1321     {0x3861, 0x00},
1322     {0x3862, 0x04},
1323     {0x3863, 0x06},
1324     {0x3a11, 0x01},
1325     {0x3a12, 0x78},
1326     {0x3b00, 0x00},
1327     {0x3b02, 0x00},
1328     {0x3b03, 0x00},
1329     {0x3b04, 0x00},
1330     {0x3b05, 0x00},
1331     {0x3c00, 0x89},
1332     {0x3c01, 0xab},
1333     {0x3c02, 0x01},
1334     {0x3c03, 0x00},
1335     {0x3c04, 0x00},
1336     {0x3c05, 0x03},
1337     {0x3c06, 0x00},
1338     {0x3c07, 0x05},
1339     {0x3c0c, 0x00},
1340     {0x3c0d, 0x00},
1341     {0x3c0e, 0x00},
1342     {0x3c0f, 0x00},
1343     {0x3c40, 0x00},
1344     {0x3c41, 0xa3},
1345     {0x3c43, 0x7d},
1346     {0x3c45, 0xd7},
1347     {0x3c47, 0xfc},
1348     {0x3c50, 0x05},
1349     {0x3c52, 0xaa},
1350     {0x3c54, 0x71},
1351     {0x3c56, 0x80},
1352     {0x3d85, 0x17},
1353     {0x3f03, 0x00},
1354     {0x3f0a, 0x00},
1355     {0x3f0b, 0x00},
1356     {0x4001, 0x60},
1357     {0x4009, 0x05},
1358     {0x4020, 0x00},
1359     {0x4021, 0x00},
1360     {0x4022, 0x00},
1361     {0x4023, 0x00},
1362     {0x4024, 0x00},
1363     {0x4025, 0x00},
1364     {0x4026, 0x00},
1365     {0x4027, 0x00},
1366     {0x4028, 0x00},
1367     {0x4029, 0x00},
1368     {0x402a, 0x00},
1369     {0x402b, 0x00},
1370     {0x402c, 0x00},
1371     {0x402d, 0x00},
1372     {0x402e, 0x00},
1373     {0x402f, 0x00},
1374     {0x4040, 0x00},
1375     {0x4041, 0x03},
1376     {0x4042, 0x00},
1377     {0x4043, 0x7A},
1378     {0x4044, 0x00},
1379     {0x4045, 0x7A},
1380     {0x4046, 0x00},
1381     {0x4047, 0x7A},
1382     {0x4048, 0x00},
1383     {0x4049, 0x7A},
1384     {0x4307, 0x30},
1385     {0x4500, 0x58},
1386     {0x4501, 0x04},
1387     {0x4502, 0x48},
1388     {0x4503, 0x10},
1389     {0x4508, 0x55},
1390     {0x4509, 0x55},
1391     {0x450a, 0x00},
1392     {0x450b, 0x00},
1393     {0x4600, 0x00},
1394     {0x4601, 0x80},
1395     {0x4700, 0xa4},
1396     {0x4800, 0x4c},
1397     {0x4816, 0x53},
1398     {0x481f, 0x40},
1399     {0x4837, 0x13},
1400     {0x5000, 0x56},
1401     {0x5001, 0x01},
1402     {0x5002, 0x28},
1403     {0x5004, 0x0c},
1404     {0x5006, 0x0c},
1405     {0x5007, 0xe0},
1406     {0x5008, 0x01},
1407     {0x5009, 0xb0},
1408     {0x5901, 0x00},
1409     {0x5a01, 0x00},
1410     {0x5a03, 0x00},
1411     {0x5a04, 0x0c},
1412     {0x5a05, 0xe0},
1413     {0x5a06, 0x09},
1414     {0x5a07, 0xb0},
1415     {0x5a08, 0x06},
1416     {0x5e00, 0x00},
1417     {0x3734, 0x40},
1418     {0x5b00, 0x01},
1419     {0x5b01, 0x10},
1420     {0x5b02, 0x01},
1421     {0x5b03, 0xdb},
1422     {0x3d8c, 0x71},
1423     {0x3d8d, 0xea},
1424     {0x4017, 0x10},
1425     {0x3618, 0x2a},
1426     {0x5780, 0x3e},
1427     {0x5781, 0x0f},
1428     {0x5782, 0x44},
1429     {0x5783, 0x02},
1430     {0x5784, 0x01},
1431     {0x5785, 0x01},
1432     {0x5786, 0x00},
1433     {0x5787, 0x04},
1434     {0x5788, 0x02},
1435     {0x5789, 0x0f},
1436     {0x578a, 0xfd},
1437     {0x578b, 0xf5},
1438     {0x578c, 0xf5},
1439     {0x578d, 0x03},
1440     {0x578e, 0x08},
1441     {0x578f, 0x0c},
1442     {0x5790, 0x08},
1443     {0x5791, 0x06},
1444     {0x5792, 0x00},
1445     {0x5793, 0x52},
1446     {0x5794, 0xa3},
1447     {0x3503, 0x00},
1448     {0x5045, 0x05},
1449     {0x4003, 0x40},
1450     {0x5048, 0x40}
1451 };
1452 
1453 static const struct ov5670_reg mode_640x360_regs[] = {
1454     {0x3000, 0x00},
1455     {0x3002, 0x21},
1456     {0x3005, 0xf0},
1457     {0x3007, 0x00},
1458     {0x3015, 0x0f},
1459     {0x3018, 0x32},
1460     {0x301a, 0xf0},
1461     {0x301b, 0xf0},
1462     {0x301c, 0xf0},
1463     {0x301d, 0xf0},
1464     {0x301e, 0xf0},
1465     {0x3030, 0x00},
1466     {0x3031, 0x0a},
1467     {0x303c, 0xff},
1468     {0x303e, 0xff},
1469     {0x3040, 0xf0},
1470     {0x3041, 0x00},
1471     {0x3042, 0xf0},
1472     {0x3106, 0x11},
1473     {0x3500, 0x00},
1474     {0x3501, 0x80},
1475     {0x3502, 0x00},
1476     {0x3503, 0x04},
1477     {0x3504, 0x03},
1478     {0x3505, 0x83},
1479     {0x3508, 0x04},
1480     {0x3509, 0x00},
1481     {0x350e, 0x04},
1482     {0x350f, 0x00},
1483     {0x3510, 0x00},
1484     {0x3511, 0x02},
1485     {0x3512, 0x00},
1486     {0x3601, 0xc8},
1487     {0x3610, 0x88},
1488     {0x3612, 0x48},
1489     {0x3614, 0x5b},
1490     {0x3615, 0x96},
1491     {0x3621, 0xd0},
1492     {0x3622, 0x00},
1493     {0x3623, 0x04},
1494     {0x3633, 0x13},
1495     {0x3634, 0x13},
1496     {0x3635, 0x13},
1497     {0x3636, 0x13},
1498     {0x3645, 0x13},
1499     {0x3646, 0x82},
1500     {0x3650, 0x00},
1501     {0x3652, 0xff},
1502     {0x3655, 0x20},
1503     {0x3656, 0xff},
1504     {0x365a, 0xff},
1505     {0x365e, 0xff},
1506     {0x3668, 0x00},
1507     {0x366a, 0x07},
1508     {0x366e, 0x08},
1509     {0x366d, 0x00},
1510     {0x366f, 0x80},
1511     {0x3700, 0x28},
1512     {0x3701, 0x10},
1513     {0x3702, 0x3a},
1514     {0x3703, 0x19},
1515     {0x3704, 0x10},
1516     {0x3705, 0x00},
1517     {0x3706, 0x66},
1518     {0x3707, 0x08},
1519     {0x3708, 0x34},
1520     {0x3709, 0x40},
1521     {0x370a, 0x01},
1522     {0x370b, 0x1b},
1523     {0x3714, 0x24},
1524     {0x371a, 0x3e},
1525     {0x3733, 0x00},
1526     {0x3734, 0x00},
1527     {0x373a, 0x05},
1528     {0x373b, 0x06},
1529     {0x373c, 0x0a},
1530     {0x373f, 0xa0},
1531     {0x3755, 0x00},
1532     {0x3758, 0x00},
1533     {0x375b, 0x0e},
1534     {0x3766, 0x5f},
1535     {0x3768, 0x00},
1536     {0x3769, 0x22},
1537     {0x3773, 0x08},
1538     {0x3774, 0x1f},
1539     {0x3776, 0x06},
1540     {0x37a0, 0x88},
1541     {0x37a1, 0x5c},
1542     {0x37a7, 0x88},
1543     {0x37a8, 0x70},
1544     {0x37aa, 0x88},
1545     {0x37ab, 0x48},
1546     {0x37b3, 0x66},
1547     {0x37c2, 0x04},
1548     {0x37c5, 0x00},
1549     {0x37c8, 0x00},
1550     {0x3800, 0x00},
1551     {0x3801, 0x0c},
1552     {0x3802, 0x00},
1553     {0x3803, 0x04},
1554     {0x3804, 0x0a},
1555     {0x3805, 0x33},
1556     {0x3806, 0x07},
1557     {0x3807, 0xa3},
1558     {0x3808, 0x02},
1559     {0x3809, 0x80},
1560     {0x380a, 0x01},
1561     {0x380b, 0x68},
1562     {0x380c, 0x06},
1563     {0x380d, 0x90},
1564     {0x380e, 0x08},
1565     {0x380f, 0x08},
1566     {0x3811, 0x04},
1567     {0x3813, 0x02},
1568     {0x3814, 0x07},
1569     {0x3815, 0x01},
1570     {0x3816, 0x00},
1571     {0x3817, 0x00},
1572     {0x3818, 0x00},
1573     {0x3819, 0x00},
1574     {0x3820, 0x94},
1575     {0x3821, 0xc6},
1576     {0x3822, 0x48},
1577     {0x3826, 0x00},
1578     {0x3827, 0x08},
1579     {0x382a, 0x07},
1580     {0x382b, 0x01},
1581     {0x3830, 0x08},
1582     {0x3836, 0x02},
1583     {0x3837, 0x00},
1584     {0x3838, 0x10},
1585     {0x3841, 0xff},
1586     {0x3846, 0x48},
1587     {0x3861, 0x00},
1588     {0x3862, 0x04},
1589     {0x3863, 0x06},
1590     {0x3a11, 0x01},
1591     {0x3a12, 0x78},
1592     {0x3b00, 0x00},
1593     {0x3b02, 0x00},
1594     {0x3b03, 0x00},
1595     {0x3b04, 0x00},
1596     {0x3b05, 0x00},
1597     {0x3c00, 0x89},
1598     {0x3c01, 0xab},
1599     {0x3c02, 0x01},
1600     {0x3c03, 0x00},
1601     {0x3c04, 0x00},
1602     {0x3c05, 0x03},
1603     {0x3c06, 0x00},
1604     {0x3c07, 0x05},
1605     {0x3c0c, 0x00},
1606     {0x3c0d, 0x00},
1607     {0x3c0e, 0x00},
1608     {0x3c0f, 0x00},
1609     {0x3c40, 0x00},
1610     {0x3c41, 0xa3},
1611     {0x3c43, 0x7d},
1612     {0x3c45, 0xd7},
1613     {0x3c47, 0xfc},
1614     {0x3c50, 0x05},
1615     {0x3c52, 0xaa},
1616     {0x3c54, 0x71},
1617     {0x3c56, 0x80},
1618     {0x3d85, 0x17},
1619     {0x3f03, 0x00},
1620     {0x3f0a, 0x00},
1621     {0x3f0b, 0x00},
1622     {0x4001, 0x60},
1623     {0x4009, 0x05},
1624     {0x4020, 0x00},
1625     {0x4021, 0x00},
1626     {0x4022, 0x00},
1627     {0x4023, 0x00},
1628     {0x4024, 0x00},
1629     {0x4025, 0x00},
1630     {0x4026, 0x00},
1631     {0x4027, 0x00},
1632     {0x4028, 0x00},
1633     {0x4029, 0x00},
1634     {0x402a, 0x00},
1635     {0x402b, 0x00},
1636     {0x402c, 0x00},
1637     {0x402d, 0x00},
1638     {0x402e, 0x00},
1639     {0x402f, 0x00},
1640     {0x4040, 0x00},
1641     {0x4041, 0x03},
1642     {0x4042, 0x00},
1643     {0x4043, 0x7A},
1644     {0x4044, 0x00},
1645     {0x4045, 0x7A},
1646     {0x4046, 0x00},
1647     {0x4047, 0x7A},
1648     {0x4048, 0x00},
1649     {0x4049, 0x7A},
1650     {0x4307, 0x30},
1651     {0x4500, 0x58},
1652     {0x4501, 0x04},
1653     {0x4502, 0x40},
1654     {0x4503, 0x10},
1655     {0x4508, 0x55},
1656     {0x4509, 0x55},
1657     {0x450a, 0x02},
1658     {0x450b, 0x00},
1659     {0x4600, 0x00},
1660     {0x4601, 0x40},
1661     {0x4700, 0xa4},
1662     {0x4800, 0x4c},
1663     {0x4816, 0x53},
1664     {0x481f, 0x40},
1665     {0x4837, 0x13},
1666     {0x5000, 0x56},
1667     {0x5001, 0x01},
1668     {0x5002, 0x28},
1669     {0x5004, 0x0c},
1670     {0x5006, 0x0c},
1671     {0x5007, 0xe0},
1672     {0x5008, 0x01},
1673     {0x5009, 0xb0},
1674     {0x5901, 0x00},
1675     {0x5a01, 0x00},
1676     {0x5a03, 0x00},
1677     {0x5a04, 0x0c},
1678     {0x5a05, 0xe0},
1679     {0x5a06, 0x09},
1680     {0x5a07, 0xb0},
1681     {0x5a08, 0x06},
1682     {0x5e00, 0x00},
1683     {0x3734, 0x40},
1684     {0x5b00, 0x01},
1685     {0x5b01, 0x10},
1686     {0x5b02, 0x01},
1687     {0x5b03, 0xdb},
1688     {0x3d8c, 0x71},
1689     {0x3d8d, 0xea},
1690     {0x4017, 0x10},
1691     {0x3618, 0x2a},
1692     {0x5780, 0x3e},
1693     {0x5781, 0x0f},
1694     {0x5782, 0x44},
1695     {0x5783, 0x02},
1696     {0x5784, 0x01},
1697     {0x5785, 0x01},
1698     {0x5786, 0x00},
1699     {0x5787, 0x04},
1700     {0x5788, 0x02},
1701     {0x5789, 0x0f},
1702     {0x578a, 0xfd},
1703     {0x578b, 0xf5},
1704     {0x578c, 0xf5},
1705     {0x578d, 0x03},
1706     {0x578e, 0x08},
1707     {0x578f, 0x0c},
1708     {0x5790, 0x08},
1709     {0x5791, 0x06},
1710     {0x5792, 0x00},
1711     {0x5793, 0x52},
1712     {0x5794, 0xa3},
1713     {0x3503, 0x00},
1714     {0x5045, 0x05},
1715     {0x4003, 0x40},
1716     {0x5048, 0x40}
1717 };
1718 
1719 static const char * const ov5670_test_pattern_menu[] = {
1720     "Disabled",
1721     "Vertical Color Bar Type 1",
1722 };
1723 
1724 /* Supported link frequencies */
1725 #define OV5670_LINK_FREQ_422MHZ     422400000
1726 #define OV5670_LINK_FREQ_422MHZ_INDEX   0
1727 static const struct ov5670_link_freq_config link_freq_configs[] = {
1728     {
1729         /* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
1730         .pixel_rate = (OV5670_LINK_FREQ_422MHZ * 2 * 2) / 10,
1731         .reg_list = {
1732             .num_of_regs = ARRAY_SIZE(mipi_data_rate_840mbps),
1733             .regs = mipi_data_rate_840mbps,
1734         }
1735     }
1736 };
1737 
1738 static const s64 link_freq_menu_items[] = {
1739     OV5670_LINK_FREQ_422MHZ
1740 };
1741 
1742 /*
1743  * OV5670 sensor supports following resolutions with full FOV:
1744  * 4:3  ==> {2592x1944, 1296x972, 648x486}
1745  * 16:9 ==> {2560x1440, 1280x720, 640x360}
1746  */
1747 static const struct ov5670_mode supported_modes[] = {
1748     {
1749         .width = 2592,
1750         .height = 1944,
1751         .vts_def = OV5670_VTS_30FPS,
1752         .vts_min = OV5670_VTS_30FPS,
1753         .reg_list = {
1754             .num_of_regs = ARRAY_SIZE(mode_2592x1944_regs),
1755             .regs = mode_2592x1944_regs,
1756         },
1757         .link_freq_index = OV5670_LINK_FREQ_422MHZ_INDEX,
1758     },
1759     {
1760         .width = 1296,
1761         .height = 972,
1762         .vts_def = OV5670_VTS_30FPS,
1763         .vts_min = 996,
1764         .reg_list = {
1765             .num_of_regs = ARRAY_SIZE(mode_1296x972_regs),
1766             .regs = mode_1296x972_regs,
1767         },
1768         .link_freq_index = OV5670_LINK_FREQ_422MHZ_INDEX,
1769     },
1770     {
1771         .width = 648,
1772         .height = 486,
1773         .vts_def = OV5670_VTS_30FPS,
1774         .vts_min = 516,
1775         .reg_list = {
1776             .num_of_regs = ARRAY_SIZE(mode_648x486_regs),
1777             .regs = mode_648x486_regs,
1778         },
1779         .link_freq_index = OV5670_LINK_FREQ_422MHZ_INDEX,
1780     },
1781     {
1782         .width = 2560,
1783         .height = 1440,
1784         .vts_def = OV5670_VTS_30FPS,
1785         .vts_min = OV5670_VTS_30FPS,
1786         .reg_list = {
1787             .num_of_regs = ARRAY_SIZE(mode_2560x1440_regs),
1788             .regs = mode_2560x1440_regs,
1789         },
1790         .link_freq_index = OV5670_LINK_FREQ_422MHZ_INDEX,
1791     },
1792     {
1793         .width = 1280,
1794         .height = 720,
1795         .vts_def = OV5670_VTS_30FPS,
1796         .vts_min = 1020,
1797         .reg_list = {
1798             .num_of_regs = ARRAY_SIZE(mode_1280x720_regs),
1799             .regs = mode_1280x720_regs,
1800         },
1801         .link_freq_index = OV5670_LINK_FREQ_422MHZ_INDEX,
1802     },
1803     {
1804         .width = 640,
1805         .height = 360,
1806         .vts_def = OV5670_VTS_30FPS,
1807         .vts_min = 510,
1808         .reg_list = {
1809             .num_of_regs = ARRAY_SIZE(mode_640x360_regs),
1810             .regs = mode_640x360_regs,
1811         },
1812         .link_freq_index = OV5670_LINK_FREQ_422MHZ_INDEX,
1813     }
1814 };
1815 
1816 struct ov5670 {
1817     struct v4l2_subdev sd;
1818     struct media_pad pad;
1819 
1820     struct v4l2_ctrl_handler ctrl_handler;
1821     /* V4L2 Controls */
1822     struct v4l2_ctrl *link_freq;
1823     struct v4l2_ctrl *pixel_rate;
1824     struct v4l2_ctrl *vblank;
1825     struct v4l2_ctrl *hblank;
1826     struct v4l2_ctrl *exposure;
1827 
1828     /* Current mode */
1829     const struct ov5670_mode *cur_mode;
1830 
1831     /* To serialize asynchronus callbacks */
1832     struct mutex mutex;
1833 
1834     /* Streaming on/off */
1835     bool streaming;
1836     /* True if the device has been identified */
1837     bool identified;
1838 };
1839 
1840 #define to_ov5670(_sd)  container_of(_sd, struct ov5670, sd)
1841 
1842 /* Read registers up to 4 at a time */
1843 static int ov5670_read_reg(struct ov5670 *ov5670, u16 reg, unsigned int len,
1844                u32 *val)
1845 {
1846     struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
1847     struct i2c_msg msgs[2];
1848     u8 *data_be_p;
1849     __be32 data_be = 0;
1850     __be16 reg_addr_be = cpu_to_be16(reg);
1851     int ret;
1852 
1853     if (len > 4)
1854         return -EINVAL;
1855 
1856     data_be_p = (u8 *)&data_be;
1857     /* Write register address */
1858     msgs[0].addr = client->addr;
1859     msgs[0].flags = 0;
1860     msgs[0].len = 2;
1861     msgs[0].buf = (u8 *)&reg_addr_be;
1862 
1863     /* Read data from register */
1864     msgs[1].addr = client->addr;
1865     msgs[1].flags = I2C_M_RD;
1866     msgs[1].len = len;
1867     msgs[1].buf = &data_be_p[4 - len];
1868 
1869     ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
1870     if (ret != ARRAY_SIZE(msgs))
1871         return -EIO;
1872 
1873     *val = be32_to_cpu(data_be);
1874 
1875     return 0;
1876 }
1877 
1878 /* Write registers up to 4 at a time */
1879 static int ov5670_write_reg(struct ov5670 *ov5670, u16 reg, unsigned int len,
1880                 u32 val)
1881 {
1882     struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
1883     int buf_i;
1884     int val_i;
1885     u8 buf[6];
1886     u8 *val_p;
1887     __be32 tmp;
1888 
1889     if (len > 4)
1890         return -EINVAL;
1891 
1892     buf[0] = reg >> 8;
1893     buf[1] = reg & 0xff;
1894 
1895     tmp = cpu_to_be32(val);
1896     val_p = (u8 *)&tmp;
1897     buf_i = 2;
1898     val_i = 4 - len;
1899 
1900     while (val_i < 4)
1901         buf[buf_i++] = val_p[val_i++];
1902 
1903     if (i2c_master_send(client, buf, len + 2) != len + 2)
1904         return -EIO;
1905 
1906     return 0;
1907 }
1908 
1909 /* Write a list of registers */
1910 static int ov5670_write_regs(struct ov5670 *ov5670,
1911                  const struct ov5670_reg *regs, unsigned int len)
1912 {
1913     struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
1914     unsigned int i;
1915     int ret;
1916 
1917     for (i = 0; i < len; i++) {
1918         ret = ov5670_write_reg(ov5670, regs[i].address, 1, regs[i].val);
1919         if (ret) {
1920             dev_err_ratelimited(
1921                 &client->dev,
1922                 "Failed to write reg 0x%4.4x. error = %d\n",
1923                 regs[i].address, ret);
1924 
1925             return ret;
1926         }
1927     }
1928 
1929     return 0;
1930 }
1931 
1932 static int ov5670_write_reg_list(struct ov5670 *ov5670,
1933                  const struct ov5670_reg_list *r_list)
1934 {
1935     return ov5670_write_regs(ov5670, r_list->regs, r_list->num_of_regs);
1936 }
1937 
1938 /* Open sub-device */
1939 static int ov5670_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1940 {
1941     struct ov5670 *ov5670 = to_ov5670(sd);
1942     struct v4l2_mbus_framefmt *try_fmt =
1943                 v4l2_subdev_get_try_format(sd, fh->state, 0);
1944 
1945     mutex_lock(&ov5670->mutex);
1946 
1947     /* Initialize try_fmt */
1948     try_fmt->width = ov5670->cur_mode->width;
1949     try_fmt->height = ov5670->cur_mode->height;
1950     try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
1951     try_fmt->field = V4L2_FIELD_NONE;
1952 
1953     /* No crop or compose */
1954     mutex_unlock(&ov5670->mutex);
1955 
1956     return 0;
1957 }
1958 
1959 static int ov5670_update_digital_gain(struct ov5670 *ov5670, u32 d_gain)
1960 {
1961     int ret;
1962 
1963     ret = ov5670_write_reg(ov5670, OV5670_REG_R_DGTL_GAIN,
1964                    OV5670_REG_VALUE_16BIT, d_gain);
1965     if (ret)
1966         return ret;
1967 
1968     ret = ov5670_write_reg(ov5670, OV5670_REG_G_DGTL_GAIN,
1969                    OV5670_REG_VALUE_16BIT, d_gain);
1970     if (ret)
1971         return ret;
1972 
1973     return ov5670_write_reg(ov5670, OV5670_REG_B_DGTL_GAIN,
1974                 OV5670_REG_VALUE_16BIT, d_gain);
1975 }
1976 
1977 static int ov5670_enable_test_pattern(struct ov5670 *ov5670, u32 pattern)
1978 {
1979     u32 val;
1980     int ret;
1981 
1982     /* Set the bayer order that we support */
1983     ret = ov5670_write_reg(ov5670, OV5670_REG_TEST_PATTERN_CTRL,
1984                    OV5670_REG_VALUE_08BIT, 0);
1985     if (ret)
1986         return ret;
1987 
1988     ret = ov5670_read_reg(ov5670, OV5670_REG_TEST_PATTERN,
1989                   OV5670_REG_VALUE_08BIT, &val);
1990     if (ret)
1991         return ret;
1992 
1993     if (pattern)
1994         val |= OV5670_TEST_PATTERN_ENABLE;
1995     else
1996         val &= ~OV5670_TEST_PATTERN_ENABLE;
1997 
1998     return ov5670_write_reg(ov5670, OV5670_REG_TEST_PATTERN,
1999                 OV5670_REG_VALUE_08BIT, val);
2000 }
2001 
2002 /* Initialize control handlers */
2003 static int ov5670_set_ctrl(struct v4l2_ctrl *ctrl)
2004 {
2005     struct ov5670 *ov5670 = container_of(ctrl->handler,
2006                          struct ov5670, ctrl_handler);
2007     struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2008     s64 max;
2009     int ret = 0;
2010 
2011     /* Propagate change of current control to all related controls */
2012     switch (ctrl->id) {
2013     case V4L2_CID_VBLANK:
2014         /* Update max exposure while meeting expected vblanking */
2015         max = ov5670->cur_mode->height + ctrl->val - 8;
2016         __v4l2_ctrl_modify_range(ov5670->exposure,
2017                      ov5670->exposure->minimum, max,
2018                      ov5670->exposure->step, max);
2019         break;
2020     }
2021 
2022     /* V4L2 controls values will be applied only when power is already up */
2023     if (!pm_runtime_get_if_in_use(&client->dev))
2024         return 0;
2025 
2026     switch (ctrl->id) {
2027     case V4L2_CID_ANALOGUE_GAIN:
2028         ret = ov5670_write_reg(ov5670, OV5670_REG_ANALOG_GAIN,
2029                        OV5670_REG_VALUE_16BIT, ctrl->val);
2030         break;
2031     case V4L2_CID_DIGITAL_GAIN:
2032         ret = ov5670_update_digital_gain(ov5670, ctrl->val);
2033         break;
2034     case V4L2_CID_EXPOSURE:
2035         /* 4 least significant bits of expsoure are fractional part */
2036         ret = ov5670_write_reg(ov5670, OV5670_REG_EXPOSURE,
2037                        OV5670_REG_VALUE_24BIT, ctrl->val << 4);
2038         break;
2039     case V4L2_CID_VBLANK:
2040         /* Update VTS that meets expected vertical blanking */
2041         ret = ov5670_write_reg(ov5670, OV5670_REG_VTS,
2042                        OV5670_REG_VALUE_16BIT,
2043                        ov5670->cur_mode->height + ctrl->val);
2044         break;
2045     case V4L2_CID_TEST_PATTERN:
2046         ret = ov5670_enable_test_pattern(ov5670, ctrl->val);
2047         break;
2048     default:
2049         dev_info(&client->dev, "%s Unhandled id:0x%x, val:0x%x\n",
2050              __func__, ctrl->id, ctrl->val);
2051         break;
2052     }
2053 
2054     pm_runtime_put(&client->dev);
2055 
2056     return ret;
2057 }
2058 
2059 static const struct v4l2_ctrl_ops ov5670_ctrl_ops = {
2060     .s_ctrl = ov5670_set_ctrl,
2061 };
2062 
2063 /* Initialize control handlers */
2064 static int ov5670_init_controls(struct ov5670 *ov5670)
2065 {
2066     struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2067     struct v4l2_fwnode_device_properties props;
2068     struct v4l2_ctrl_handler *ctrl_hdlr;
2069     s64 vblank_max;
2070     s64 vblank_def;
2071     s64 vblank_min;
2072     s64 exposure_max;
2073     int ret;
2074 
2075     ctrl_hdlr = &ov5670->ctrl_handler;
2076     ret = v4l2_ctrl_handler_init(ctrl_hdlr, 10);
2077     if (ret)
2078         return ret;
2079 
2080     ctrl_hdlr->lock = &ov5670->mutex;
2081     ov5670->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr,
2082                            &ov5670_ctrl_ops,
2083                            V4L2_CID_LINK_FREQ,
2084                            0, 0, link_freq_menu_items);
2085     if (ov5670->link_freq)
2086         ov5670->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
2087 
2088     /* By default, V4L2_CID_PIXEL_RATE is read only */
2089     ov5670->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
2090                            V4L2_CID_PIXEL_RATE,
2091                            link_freq_configs[0].pixel_rate,
2092                            link_freq_configs[0].pixel_rate,
2093                            1,
2094                            link_freq_configs[0].pixel_rate);
2095 
2096     vblank_max = OV5670_VTS_MAX - ov5670->cur_mode->height;
2097     vblank_def = ov5670->cur_mode->vts_def - ov5670->cur_mode->height;
2098     vblank_min = ov5670->cur_mode->vts_min - ov5670->cur_mode->height;
2099     ov5670->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
2100                        V4L2_CID_VBLANK, vblank_min,
2101                        vblank_max, 1, vblank_def);
2102 
2103     ov5670->hblank = v4l2_ctrl_new_std(
2104                 ctrl_hdlr, &ov5670_ctrl_ops, V4L2_CID_HBLANK,
2105                 OV5670_FIXED_PPL - ov5670->cur_mode->width,
2106                 OV5670_FIXED_PPL - ov5670->cur_mode->width, 1,
2107                 OV5670_FIXED_PPL - ov5670->cur_mode->width);
2108     if (ov5670->hblank)
2109         ov5670->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
2110 
2111     /* Get min, max, step, default from sensor */
2112     v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
2113               ANALOG_GAIN_MIN, ANALOG_GAIN_MAX, ANALOG_GAIN_STEP,
2114               ANALOG_GAIN_DEFAULT);
2115 
2116     /* Digital gain */
2117     v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
2118               OV5670_DGTL_GAIN_MIN, OV5670_DGTL_GAIN_MAX,
2119               OV5670_DGTL_GAIN_STEP, OV5670_DGTL_GAIN_DEFAULT);
2120 
2121     /* Get min, max, step, default from sensor */
2122     exposure_max = ov5670->cur_mode->vts_def - 8;
2123     ov5670->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
2124                          V4L2_CID_EXPOSURE,
2125                          OV5670_EXPOSURE_MIN,
2126                          exposure_max, OV5670_EXPOSURE_STEP,
2127                          exposure_max);
2128 
2129     v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov5670_ctrl_ops,
2130                      V4L2_CID_TEST_PATTERN,
2131                      ARRAY_SIZE(ov5670_test_pattern_menu) - 1,
2132                      0, 0, ov5670_test_pattern_menu);
2133 
2134     if (ctrl_hdlr->error) {
2135         ret = ctrl_hdlr->error;
2136         goto error;
2137     }
2138 
2139     ret = v4l2_fwnode_device_parse(&client->dev, &props);
2140     if (ret)
2141         goto error;
2142 
2143     ret = v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &ov5670_ctrl_ops,
2144                           &props);
2145     if (ret)
2146         goto error;
2147 
2148     ov5670->sd.ctrl_handler = ctrl_hdlr;
2149 
2150     return 0;
2151 
2152 error:
2153     v4l2_ctrl_handler_free(ctrl_hdlr);
2154 
2155     return ret;
2156 }
2157 
2158 static int ov5670_enum_mbus_code(struct v4l2_subdev *sd,
2159                  struct v4l2_subdev_state *sd_state,
2160                  struct v4l2_subdev_mbus_code_enum *code)
2161 {
2162     /* Only one bayer order GRBG is supported */
2163     if (code->index > 0)
2164         return -EINVAL;
2165 
2166     code->code = MEDIA_BUS_FMT_SGRBG10_1X10;
2167 
2168     return 0;
2169 }
2170 
2171 static int ov5670_enum_frame_size(struct v4l2_subdev *sd,
2172                   struct v4l2_subdev_state *sd_state,
2173                   struct v4l2_subdev_frame_size_enum *fse)
2174 {
2175     if (fse->index >= ARRAY_SIZE(supported_modes))
2176         return -EINVAL;
2177 
2178     if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10)
2179         return -EINVAL;
2180 
2181     fse->min_width = supported_modes[fse->index].width;
2182     fse->max_width = fse->min_width;
2183     fse->min_height = supported_modes[fse->index].height;
2184     fse->max_height = fse->min_height;
2185 
2186     return 0;
2187 }
2188 
2189 static void ov5670_update_pad_format(const struct ov5670_mode *mode,
2190                      struct v4l2_subdev_format *fmt)
2191 {
2192     fmt->format.width = mode->width;
2193     fmt->format.height = mode->height;
2194     fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
2195     fmt->format.field = V4L2_FIELD_NONE;
2196 }
2197 
2198 static int ov5670_do_get_pad_format(struct ov5670 *ov5670,
2199                     struct v4l2_subdev_state *sd_state,
2200                     struct v4l2_subdev_format *fmt)
2201 {
2202     if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
2203         fmt->format = *v4l2_subdev_get_try_format(&ov5670->sd,
2204                               sd_state,
2205                               fmt->pad);
2206     else
2207         ov5670_update_pad_format(ov5670->cur_mode, fmt);
2208 
2209     return 0;
2210 }
2211 
2212 static int ov5670_get_pad_format(struct v4l2_subdev *sd,
2213                  struct v4l2_subdev_state *sd_state,
2214                  struct v4l2_subdev_format *fmt)
2215 {
2216     struct ov5670 *ov5670 = to_ov5670(sd);
2217     int ret;
2218 
2219     mutex_lock(&ov5670->mutex);
2220     ret = ov5670_do_get_pad_format(ov5670, sd_state, fmt);
2221     mutex_unlock(&ov5670->mutex);
2222 
2223     return ret;
2224 }
2225 
2226 static int ov5670_set_pad_format(struct v4l2_subdev *sd,
2227                  struct v4l2_subdev_state *sd_state,
2228                  struct v4l2_subdev_format *fmt)
2229 {
2230     struct ov5670 *ov5670 = to_ov5670(sd);
2231     const struct ov5670_mode *mode;
2232     s32 vblank_def;
2233     s32 h_blank;
2234 
2235     mutex_lock(&ov5670->mutex);
2236 
2237     fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
2238 
2239     mode = v4l2_find_nearest_size(supported_modes,
2240                       ARRAY_SIZE(supported_modes),
2241                       width, height,
2242                       fmt->format.width, fmt->format.height);
2243     ov5670_update_pad_format(mode, fmt);
2244     if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
2245         *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad) = fmt->format;
2246     } else {
2247         ov5670->cur_mode = mode;
2248         __v4l2_ctrl_s_ctrl(ov5670->link_freq, mode->link_freq_index);
2249         __v4l2_ctrl_s_ctrl_int64(
2250             ov5670->pixel_rate,
2251             link_freq_configs[mode->link_freq_index].pixel_rate);
2252         /* Update limits and set FPS to default */
2253         vblank_def = ov5670->cur_mode->vts_def -
2254                  ov5670->cur_mode->height;
2255         __v4l2_ctrl_modify_range(
2256             ov5670->vblank,
2257             ov5670->cur_mode->vts_min - ov5670->cur_mode->height,
2258             OV5670_VTS_MAX - ov5670->cur_mode->height, 1,
2259             vblank_def);
2260         __v4l2_ctrl_s_ctrl(ov5670->vblank, vblank_def);
2261         h_blank = OV5670_FIXED_PPL - ov5670->cur_mode->width;
2262         __v4l2_ctrl_modify_range(ov5670->hblank, h_blank, h_blank, 1,
2263                      h_blank);
2264     }
2265 
2266     mutex_unlock(&ov5670->mutex);
2267 
2268     return 0;
2269 }
2270 
2271 static int ov5670_get_skip_frames(struct v4l2_subdev *sd, u32 *frames)
2272 {
2273     *frames = OV5670_NUM_OF_SKIP_FRAMES;
2274 
2275     return 0;
2276 }
2277 
2278 /* Verify chip ID */
2279 static int ov5670_identify_module(struct ov5670 *ov5670)
2280 {
2281     struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2282     int ret;
2283     u32 val;
2284 
2285     if (ov5670->identified)
2286         return 0;
2287 
2288     ret = ov5670_read_reg(ov5670, OV5670_REG_CHIP_ID,
2289                   OV5670_REG_VALUE_24BIT, &val);
2290     if (ret)
2291         return ret;
2292 
2293     if (val != OV5670_CHIP_ID) {
2294         dev_err(&client->dev, "chip id mismatch: %x!=%x\n",
2295             OV5670_CHIP_ID, val);
2296         return -ENXIO;
2297     }
2298 
2299     ov5670->identified = true;
2300 
2301     return 0;
2302 }
2303 
2304 /* Prepare streaming by writing default values and customized values */
2305 static int ov5670_start_streaming(struct ov5670 *ov5670)
2306 {
2307     struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2308     const struct ov5670_reg_list *reg_list;
2309     int link_freq_index;
2310     int ret;
2311 
2312     ret = ov5670_identify_module(ov5670);
2313     if (ret)
2314         return ret;
2315 
2316     /* Get out of from software reset */
2317     ret = ov5670_write_reg(ov5670, OV5670_REG_SOFTWARE_RST,
2318                    OV5670_REG_VALUE_08BIT, OV5670_SOFTWARE_RST);
2319     if (ret) {
2320         dev_err(&client->dev, "%s failed to set powerup registers\n",
2321             __func__);
2322         return ret;
2323     }
2324 
2325     /* Setup PLL */
2326     link_freq_index = ov5670->cur_mode->link_freq_index;
2327     reg_list = &link_freq_configs[link_freq_index].reg_list;
2328     ret = ov5670_write_reg_list(ov5670, reg_list);
2329     if (ret) {
2330         dev_err(&client->dev, "%s failed to set plls\n", __func__);
2331         return ret;
2332     }
2333 
2334     /* Apply default values of current mode */
2335     reg_list = &ov5670->cur_mode->reg_list;
2336     ret = ov5670_write_reg_list(ov5670, reg_list);
2337     if (ret) {
2338         dev_err(&client->dev, "%s failed to set mode\n", __func__);
2339         return ret;
2340     }
2341 
2342     ret = __v4l2_ctrl_handler_setup(ov5670->sd.ctrl_handler);
2343     if (ret)
2344         return ret;
2345 
2346     /* Write stream on list */
2347     ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT,
2348                    OV5670_REG_VALUE_08BIT, OV5670_MODE_STREAMING);
2349     if (ret) {
2350         dev_err(&client->dev, "%s failed to set stream\n", __func__);
2351         return ret;
2352     }
2353 
2354     return 0;
2355 }
2356 
2357 static int ov5670_stop_streaming(struct ov5670 *ov5670)
2358 {
2359     struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2360     int ret;
2361 
2362     ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT,
2363                    OV5670_REG_VALUE_08BIT, OV5670_MODE_STANDBY);
2364     if (ret)
2365         dev_err(&client->dev, "%s failed to set stream\n", __func__);
2366 
2367     /* Return success even if it was an error, as there is nothing the
2368      * caller can do about it.
2369      */
2370     return 0;
2371 }
2372 
2373 static int ov5670_set_stream(struct v4l2_subdev *sd, int enable)
2374 {
2375     struct ov5670 *ov5670 = to_ov5670(sd);
2376     struct i2c_client *client = v4l2_get_subdevdata(sd);
2377     int ret = 0;
2378 
2379     mutex_lock(&ov5670->mutex);
2380     if (ov5670->streaming == enable)
2381         goto unlock_and_return;
2382 
2383     if (enable) {
2384         ret = pm_runtime_resume_and_get(&client->dev);
2385         if (ret < 0)
2386             goto unlock_and_return;
2387 
2388         ret = ov5670_start_streaming(ov5670);
2389         if (ret)
2390             goto error;
2391     } else {
2392         ret = ov5670_stop_streaming(ov5670);
2393         pm_runtime_put(&client->dev);
2394     }
2395     ov5670->streaming = enable;
2396     goto unlock_and_return;
2397 
2398 error:
2399     pm_runtime_put(&client->dev);
2400 
2401 unlock_and_return:
2402     mutex_unlock(&ov5670->mutex);
2403 
2404     return ret;
2405 }
2406 
2407 static int __maybe_unused ov5670_suspend(struct device *dev)
2408 {
2409     struct v4l2_subdev *sd = dev_get_drvdata(dev);
2410     struct ov5670 *ov5670 = to_ov5670(sd);
2411 
2412     if (ov5670->streaming)
2413         ov5670_stop_streaming(ov5670);
2414 
2415     return 0;
2416 }
2417 
2418 static int __maybe_unused ov5670_resume(struct device *dev)
2419 {
2420     struct v4l2_subdev *sd = dev_get_drvdata(dev);
2421     struct ov5670 *ov5670 = to_ov5670(sd);
2422     int ret;
2423 
2424     if (ov5670->streaming) {
2425         ret = ov5670_start_streaming(ov5670);
2426         if (ret) {
2427             ov5670_stop_streaming(ov5670);
2428             return ret;
2429         }
2430     }
2431 
2432     return 0;
2433 }
2434 
2435 static const struct v4l2_subdev_core_ops ov5670_core_ops = {
2436     .log_status = v4l2_ctrl_subdev_log_status,
2437     .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
2438     .unsubscribe_event = v4l2_event_subdev_unsubscribe,
2439 };
2440 
2441 static const struct v4l2_subdev_video_ops ov5670_video_ops = {
2442     .s_stream = ov5670_set_stream,
2443 };
2444 
2445 static const struct v4l2_subdev_pad_ops ov5670_pad_ops = {
2446     .enum_mbus_code = ov5670_enum_mbus_code,
2447     .get_fmt = ov5670_get_pad_format,
2448     .set_fmt = ov5670_set_pad_format,
2449     .enum_frame_size = ov5670_enum_frame_size,
2450 };
2451 
2452 static const struct v4l2_subdev_sensor_ops ov5670_sensor_ops = {
2453     .g_skip_frames = ov5670_get_skip_frames,
2454 };
2455 
2456 static const struct v4l2_subdev_ops ov5670_subdev_ops = {
2457     .core = &ov5670_core_ops,
2458     .video = &ov5670_video_ops,
2459     .pad = &ov5670_pad_ops,
2460     .sensor = &ov5670_sensor_ops,
2461 };
2462 
2463 static const struct media_entity_operations ov5670_subdev_entity_ops = {
2464     .link_validate = v4l2_subdev_link_validate,
2465 };
2466 
2467 static const struct v4l2_subdev_internal_ops ov5670_internal_ops = {
2468     .open = ov5670_open,
2469 };
2470 
2471 static int ov5670_probe(struct i2c_client *client)
2472 {
2473     struct ov5670 *ov5670;
2474     const char *err_msg;
2475     u32 input_clk = 0;
2476     bool full_power;
2477     int ret;
2478 
2479     device_property_read_u32(&client->dev, "clock-frequency", &input_clk);
2480     if (input_clk != 19200000)
2481         return -EINVAL;
2482 
2483     ov5670 = devm_kzalloc(&client->dev, sizeof(*ov5670), GFP_KERNEL);
2484     if (!ov5670) {
2485         ret = -ENOMEM;
2486         err_msg = "devm_kzalloc() error";
2487         goto error_print;
2488     }
2489 
2490     /* Initialize subdev */
2491     v4l2_i2c_subdev_init(&ov5670->sd, client, &ov5670_subdev_ops);
2492 
2493     full_power = acpi_dev_state_d0(&client->dev);
2494     if (full_power) {
2495         /* Check module identity */
2496         ret = ov5670_identify_module(ov5670);
2497         if (ret) {
2498             err_msg = "ov5670_identify_module() error";
2499             goto error_print;
2500         }
2501     }
2502 
2503     mutex_init(&ov5670->mutex);
2504 
2505     /* Set default mode to max resolution */
2506     ov5670->cur_mode = &supported_modes[0];
2507 
2508     ret = ov5670_init_controls(ov5670);
2509     if (ret) {
2510         err_msg = "ov5670_init_controls() error";
2511         goto error_mutex_destroy;
2512     }
2513 
2514     ov5670->sd.internal_ops = &ov5670_internal_ops;
2515     ov5670->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
2516                 V4L2_SUBDEV_FL_HAS_EVENTS;
2517     ov5670->sd.entity.ops = &ov5670_subdev_entity_ops;
2518     ov5670->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
2519 
2520     /* Source pad initialization */
2521     ov5670->pad.flags = MEDIA_PAD_FL_SOURCE;
2522     ret = media_entity_pads_init(&ov5670->sd.entity, 1, &ov5670->pad);
2523     if (ret) {
2524         err_msg = "media_entity_pads_init() error";
2525         goto error_handler_free;
2526     }
2527 
2528     /* Async register for subdev */
2529     ret = v4l2_async_register_subdev_sensor(&ov5670->sd);
2530     if (ret < 0) {
2531         err_msg = "v4l2_async_register_subdev() error";
2532         goto error_entity_cleanup;
2533     }
2534 
2535     ov5670->streaming = false;
2536 
2537     /* Set the device's state to active if it's in D0 state. */
2538     if (full_power)
2539         pm_runtime_set_active(&client->dev);
2540     pm_runtime_enable(&client->dev);
2541     pm_runtime_idle(&client->dev);
2542 
2543     return 0;
2544 
2545 error_entity_cleanup:
2546     media_entity_cleanup(&ov5670->sd.entity);
2547 
2548 error_handler_free:
2549     v4l2_ctrl_handler_free(ov5670->sd.ctrl_handler);
2550 
2551 error_mutex_destroy:
2552     mutex_destroy(&ov5670->mutex);
2553 
2554 error_print:
2555     dev_err(&client->dev, "%s: %s %d\n", __func__, err_msg, ret);
2556 
2557     return ret;
2558 }
2559 
2560 static int ov5670_remove(struct i2c_client *client)
2561 {
2562     struct v4l2_subdev *sd = i2c_get_clientdata(client);
2563     struct ov5670 *ov5670 = to_ov5670(sd);
2564 
2565     v4l2_async_unregister_subdev(sd);
2566     media_entity_cleanup(&sd->entity);
2567     v4l2_ctrl_handler_free(sd->ctrl_handler);
2568     mutex_destroy(&ov5670->mutex);
2569 
2570     pm_runtime_disable(&client->dev);
2571 
2572     return 0;
2573 }
2574 
2575 static const struct dev_pm_ops ov5670_pm_ops = {
2576     SET_SYSTEM_SLEEP_PM_OPS(ov5670_suspend, ov5670_resume)
2577 };
2578 
2579 #ifdef CONFIG_ACPI
2580 static const struct acpi_device_id ov5670_acpi_ids[] = {
2581     { "INT3479" },
2582     { /* sentinel */ }
2583 };
2584 
2585 MODULE_DEVICE_TABLE(acpi, ov5670_acpi_ids);
2586 #endif
2587 
2588 static struct i2c_driver ov5670_i2c_driver = {
2589     .driver = {
2590         .name = "ov5670",
2591         .pm = &ov5670_pm_ops,
2592         .acpi_match_table = ACPI_PTR(ov5670_acpi_ids),
2593     },
2594     .probe_new = ov5670_probe,
2595     .remove = ov5670_remove,
2596     .flags = I2C_DRV_ACPI_WAIVE_D0_PROBE,
2597 };
2598 
2599 module_i2c_driver(ov5670_i2c_driver);
2600 
2601 MODULE_AUTHOR("Rapolu, Chiranjeevi <chiranjeevi.rapolu@intel.com>");
2602 MODULE_AUTHOR("Yang, Hyungwoo");
2603 MODULE_DESCRIPTION("Omnivision ov5670 sensor driver");
2604 MODULE_LICENSE("GPL v2");