18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * ov5695 driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/clk.h> 98c2ecf20Sopenharmony_ci#include <linux/device.h> 108c2ecf20Sopenharmony_ci#include <linux/delay.h> 118c2ecf20Sopenharmony_ci#include <linux/gpio/consumer.h> 128c2ecf20Sopenharmony_ci#include <linux/i2c.h> 138c2ecf20Sopenharmony_ci#include <linux/module.h> 148c2ecf20Sopenharmony_ci#include <linux/pm_runtime.h> 158c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h> 168c2ecf20Sopenharmony_ci#include <linux/sysfs.h> 178c2ecf20Sopenharmony_ci#include <media/media-entity.h> 188c2ecf20Sopenharmony_ci#include <media/v4l2-async.h> 198c2ecf20Sopenharmony_ci#include <media/v4l2-ctrls.h> 208c2ecf20Sopenharmony_ci#include <media/v4l2-subdev.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#ifndef V4L2_CID_DIGITAL_GAIN 238c2ecf20Sopenharmony_ci#define V4L2_CID_DIGITAL_GAIN V4L2_CID_GAIN 248c2ecf20Sopenharmony_ci#endif 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/* 45Mhz * 4 Binning */ 278c2ecf20Sopenharmony_ci#define OV5695_PIXEL_RATE (45 * 1000 * 1000 * 4) 288c2ecf20Sopenharmony_ci#define OV5695_XVCLK_FREQ 24000000 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define CHIP_ID 0x005695 318c2ecf20Sopenharmony_ci#define OV5695_REG_CHIP_ID 0x300a 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define OV5695_REG_CTRL_MODE 0x0100 348c2ecf20Sopenharmony_ci#define OV5695_MODE_SW_STANDBY 0x0 358c2ecf20Sopenharmony_ci#define OV5695_MODE_STREAMING BIT(0) 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define OV5695_REG_EXPOSURE 0x3500 388c2ecf20Sopenharmony_ci#define OV5695_EXPOSURE_MIN 4 398c2ecf20Sopenharmony_ci#define OV5695_EXPOSURE_STEP 1 408c2ecf20Sopenharmony_ci#define OV5695_VTS_MAX 0x7fff 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define OV5695_REG_ANALOG_GAIN 0x3509 438c2ecf20Sopenharmony_ci#define ANALOG_GAIN_MIN 0x10 448c2ecf20Sopenharmony_ci#define ANALOG_GAIN_MAX 0xf8 458c2ecf20Sopenharmony_ci#define ANALOG_GAIN_STEP 1 468c2ecf20Sopenharmony_ci#define ANALOG_GAIN_DEFAULT 0xf8 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define OV5695_REG_DIGI_GAIN_H 0x350a 498c2ecf20Sopenharmony_ci#define OV5695_REG_DIGI_GAIN_L 0x350b 508c2ecf20Sopenharmony_ci#define OV5695_DIGI_GAIN_L_MASK 0x3f 518c2ecf20Sopenharmony_ci#define OV5695_DIGI_GAIN_H_SHIFT 6 528c2ecf20Sopenharmony_ci#define OV5695_DIGI_GAIN_MIN 0 538c2ecf20Sopenharmony_ci#define OV5695_DIGI_GAIN_MAX (0x4000 - 1) 548c2ecf20Sopenharmony_ci#define OV5695_DIGI_GAIN_STEP 1 558c2ecf20Sopenharmony_ci#define OV5695_DIGI_GAIN_DEFAULT 1024 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define OV5695_REG_TEST_PATTERN 0x4503 588c2ecf20Sopenharmony_ci#define OV5695_TEST_PATTERN_ENABLE 0x80 598c2ecf20Sopenharmony_ci#define OV5695_TEST_PATTERN_DISABLE 0x0 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#define OV5695_REG_VTS 0x380e 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#define REG_NULL 0xFFFF 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci#define OV5695_REG_VALUE_08BIT 1 668c2ecf20Sopenharmony_ci#define OV5695_REG_VALUE_16BIT 2 678c2ecf20Sopenharmony_ci#define OV5695_REG_VALUE_24BIT 3 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#define OV5695_LANES 2 708c2ecf20Sopenharmony_ci#define OV5695_BITS_PER_SAMPLE 10 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistatic const char * const ov5695_supply_names[] = { 738c2ecf20Sopenharmony_ci "avdd", /* Analog power */ 748c2ecf20Sopenharmony_ci "dovdd", /* Digital I/O power */ 758c2ecf20Sopenharmony_ci "dvdd", /* Digital core power */ 768c2ecf20Sopenharmony_ci}; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#define OV5695_NUM_SUPPLIES ARRAY_SIZE(ov5695_supply_names) 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistruct regval { 818c2ecf20Sopenharmony_ci u16 addr; 828c2ecf20Sopenharmony_ci u8 val; 838c2ecf20Sopenharmony_ci}; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_cistruct ov5695_mode { 868c2ecf20Sopenharmony_ci u32 width; 878c2ecf20Sopenharmony_ci u32 height; 888c2ecf20Sopenharmony_ci u32 max_fps; 898c2ecf20Sopenharmony_ci u32 hts_def; 908c2ecf20Sopenharmony_ci u32 vts_def; 918c2ecf20Sopenharmony_ci u32 exp_def; 928c2ecf20Sopenharmony_ci const struct regval *reg_list; 938c2ecf20Sopenharmony_ci}; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_cistruct ov5695 { 968c2ecf20Sopenharmony_ci struct i2c_client *client; 978c2ecf20Sopenharmony_ci struct clk *xvclk; 988c2ecf20Sopenharmony_ci struct gpio_desc *reset_gpio; 998c2ecf20Sopenharmony_ci struct regulator_bulk_data supplies[OV5695_NUM_SUPPLIES]; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci struct v4l2_subdev subdev; 1028c2ecf20Sopenharmony_ci struct media_pad pad; 1038c2ecf20Sopenharmony_ci struct v4l2_ctrl_handler ctrl_handler; 1048c2ecf20Sopenharmony_ci struct v4l2_ctrl *exposure; 1058c2ecf20Sopenharmony_ci struct v4l2_ctrl *anal_gain; 1068c2ecf20Sopenharmony_ci struct v4l2_ctrl *digi_gain; 1078c2ecf20Sopenharmony_ci struct v4l2_ctrl *hblank; 1088c2ecf20Sopenharmony_ci struct v4l2_ctrl *vblank; 1098c2ecf20Sopenharmony_ci struct v4l2_ctrl *test_pattern; 1108c2ecf20Sopenharmony_ci struct mutex mutex; 1118c2ecf20Sopenharmony_ci bool streaming; 1128c2ecf20Sopenharmony_ci const struct ov5695_mode *cur_mode; 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci#define to_ov5695(sd) container_of(sd, struct ov5695, subdev) 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci/* 1188c2ecf20Sopenharmony_ci * Xclk 24Mhz 1198c2ecf20Sopenharmony_ci * Pclk 45Mhz 1208c2ecf20Sopenharmony_ci * linelength 672(0x2a0) 1218c2ecf20Sopenharmony_ci * framelength 2232(0x8b8) 1228c2ecf20Sopenharmony_ci * grabwindow_width 1296 1238c2ecf20Sopenharmony_ci * grabwindow_height 972 1248c2ecf20Sopenharmony_ci * max_framerate 30fps 1258c2ecf20Sopenharmony_ci * mipi_datarate per lane 840Mbps 1268c2ecf20Sopenharmony_ci */ 1278c2ecf20Sopenharmony_cistatic const struct regval ov5695_global_regs[] = { 1288c2ecf20Sopenharmony_ci {0x0103, 0x01}, 1298c2ecf20Sopenharmony_ci {0x0100, 0x00}, 1308c2ecf20Sopenharmony_ci {0x0300, 0x04}, 1318c2ecf20Sopenharmony_ci {0x0301, 0x00}, 1328c2ecf20Sopenharmony_ci {0x0302, 0x69}, 1338c2ecf20Sopenharmony_ci {0x0303, 0x00}, 1348c2ecf20Sopenharmony_ci {0x0304, 0x00}, 1358c2ecf20Sopenharmony_ci {0x0305, 0x01}, 1368c2ecf20Sopenharmony_ci {0x0307, 0x00}, 1378c2ecf20Sopenharmony_ci {0x030b, 0x00}, 1388c2ecf20Sopenharmony_ci {0x030c, 0x00}, 1398c2ecf20Sopenharmony_ci {0x030d, 0x1e}, 1408c2ecf20Sopenharmony_ci {0x030e, 0x04}, 1418c2ecf20Sopenharmony_ci {0x030f, 0x03}, 1428c2ecf20Sopenharmony_ci {0x0312, 0x01}, 1438c2ecf20Sopenharmony_ci {0x3000, 0x00}, 1448c2ecf20Sopenharmony_ci {0x3002, 0xa1}, 1458c2ecf20Sopenharmony_ci {0x3008, 0x00}, 1468c2ecf20Sopenharmony_ci {0x3010, 0x00}, 1478c2ecf20Sopenharmony_ci {0x3022, 0x51}, 1488c2ecf20Sopenharmony_ci {0x3106, 0x15}, 1498c2ecf20Sopenharmony_ci {0x3107, 0x01}, 1508c2ecf20Sopenharmony_ci {0x3108, 0x05}, 1518c2ecf20Sopenharmony_ci {0x3500, 0x00}, 1528c2ecf20Sopenharmony_ci {0x3501, 0x45}, 1538c2ecf20Sopenharmony_ci {0x3502, 0x00}, 1548c2ecf20Sopenharmony_ci {0x3503, 0x08}, 1558c2ecf20Sopenharmony_ci {0x3504, 0x03}, 1568c2ecf20Sopenharmony_ci {0x3505, 0x8c}, 1578c2ecf20Sopenharmony_ci {0x3507, 0x03}, 1588c2ecf20Sopenharmony_ci {0x3508, 0x00}, 1598c2ecf20Sopenharmony_ci {0x3509, 0x10}, 1608c2ecf20Sopenharmony_ci {0x350c, 0x00}, 1618c2ecf20Sopenharmony_ci {0x350d, 0x80}, 1628c2ecf20Sopenharmony_ci {0x3510, 0x00}, 1638c2ecf20Sopenharmony_ci {0x3511, 0x02}, 1648c2ecf20Sopenharmony_ci {0x3512, 0x00}, 1658c2ecf20Sopenharmony_ci {0x3601, 0x55}, 1668c2ecf20Sopenharmony_ci {0x3602, 0x58}, 1678c2ecf20Sopenharmony_ci {0x3614, 0x30}, 1688c2ecf20Sopenharmony_ci {0x3615, 0x77}, 1698c2ecf20Sopenharmony_ci {0x3621, 0x08}, 1708c2ecf20Sopenharmony_ci {0x3624, 0x40}, 1718c2ecf20Sopenharmony_ci {0x3633, 0x0c}, 1728c2ecf20Sopenharmony_ci {0x3634, 0x0c}, 1738c2ecf20Sopenharmony_ci {0x3635, 0x0c}, 1748c2ecf20Sopenharmony_ci {0x3636, 0x0c}, 1758c2ecf20Sopenharmony_ci {0x3638, 0x00}, 1768c2ecf20Sopenharmony_ci {0x3639, 0x00}, 1778c2ecf20Sopenharmony_ci {0x363a, 0x00}, 1788c2ecf20Sopenharmony_ci {0x363b, 0x00}, 1798c2ecf20Sopenharmony_ci {0x363c, 0xff}, 1808c2ecf20Sopenharmony_ci {0x363d, 0xfa}, 1818c2ecf20Sopenharmony_ci {0x3650, 0x44}, 1828c2ecf20Sopenharmony_ci {0x3651, 0x44}, 1838c2ecf20Sopenharmony_ci {0x3652, 0x44}, 1848c2ecf20Sopenharmony_ci {0x3653, 0x44}, 1858c2ecf20Sopenharmony_ci {0x3654, 0x44}, 1868c2ecf20Sopenharmony_ci {0x3655, 0x44}, 1878c2ecf20Sopenharmony_ci {0x3656, 0x44}, 1888c2ecf20Sopenharmony_ci {0x3657, 0x44}, 1898c2ecf20Sopenharmony_ci {0x3660, 0x00}, 1908c2ecf20Sopenharmony_ci {0x3661, 0x00}, 1918c2ecf20Sopenharmony_ci {0x3662, 0x00}, 1928c2ecf20Sopenharmony_ci {0x366a, 0x00}, 1938c2ecf20Sopenharmony_ci {0x366e, 0x0c}, 1948c2ecf20Sopenharmony_ci {0x3673, 0x04}, 1958c2ecf20Sopenharmony_ci {0x3700, 0x14}, 1968c2ecf20Sopenharmony_ci {0x3703, 0x0c}, 1978c2ecf20Sopenharmony_ci {0x3715, 0x01}, 1988c2ecf20Sopenharmony_ci {0x3733, 0x10}, 1998c2ecf20Sopenharmony_ci {0x3734, 0x40}, 2008c2ecf20Sopenharmony_ci {0x373f, 0xa0}, 2018c2ecf20Sopenharmony_ci {0x3765, 0x20}, 2028c2ecf20Sopenharmony_ci {0x37a1, 0x1d}, 2038c2ecf20Sopenharmony_ci {0x37a8, 0x26}, 2048c2ecf20Sopenharmony_ci {0x37ab, 0x14}, 2058c2ecf20Sopenharmony_ci {0x37c2, 0x04}, 2068c2ecf20Sopenharmony_ci {0x37cb, 0x09}, 2078c2ecf20Sopenharmony_ci {0x37cc, 0x13}, 2088c2ecf20Sopenharmony_ci {0x37cd, 0x1f}, 2098c2ecf20Sopenharmony_ci {0x37ce, 0x1f}, 2108c2ecf20Sopenharmony_ci {0x3800, 0x00}, 2118c2ecf20Sopenharmony_ci {0x3801, 0x00}, 2128c2ecf20Sopenharmony_ci {0x3802, 0x00}, 2138c2ecf20Sopenharmony_ci {0x3803, 0x00}, 2148c2ecf20Sopenharmony_ci {0x3804, 0x0a}, 2158c2ecf20Sopenharmony_ci {0x3805, 0x3f}, 2168c2ecf20Sopenharmony_ci {0x3806, 0x07}, 2178c2ecf20Sopenharmony_ci {0x3807, 0xaf}, 2188c2ecf20Sopenharmony_ci {0x3808, 0x05}, 2198c2ecf20Sopenharmony_ci {0x3809, 0x10}, 2208c2ecf20Sopenharmony_ci {0x380a, 0x03}, 2218c2ecf20Sopenharmony_ci {0x380b, 0xcc}, 2228c2ecf20Sopenharmony_ci {0x380c, 0x02}, 2238c2ecf20Sopenharmony_ci {0x380d, 0xa0}, 2248c2ecf20Sopenharmony_ci {0x380e, 0x08}, 2258c2ecf20Sopenharmony_ci {0x380f, 0xb8}, 2268c2ecf20Sopenharmony_ci {0x3810, 0x00}, 2278c2ecf20Sopenharmony_ci {0x3811, 0x06}, 2288c2ecf20Sopenharmony_ci {0x3812, 0x00}, 2298c2ecf20Sopenharmony_ci {0x3813, 0x06}, 2308c2ecf20Sopenharmony_ci {0x3814, 0x03}, 2318c2ecf20Sopenharmony_ci {0x3815, 0x01}, 2328c2ecf20Sopenharmony_ci {0x3816, 0x03}, 2338c2ecf20Sopenharmony_ci {0x3817, 0x01}, 2348c2ecf20Sopenharmony_ci {0x3818, 0x00}, 2358c2ecf20Sopenharmony_ci {0x3819, 0x00}, 2368c2ecf20Sopenharmony_ci {0x381a, 0x00}, 2378c2ecf20Sopenharmony_ci {0x381b, 0x01}, 2388c2ecf20Sopenharmony_ci {0x3820, 0x8b}, 2398c2ecf20Sopenharmony_ci {0x3821, 0x01}, 2408c2ecf20Sopenharmony_ci {0x3c80, 0x08}, 2418c2ecf20Sopenharmony_ci {0x3c82, 0x00}, 2428c2ecf20Sopenharmony_ci {0x3c83, 0x00}, 2438c2ecf20Sopenharmony_ci {0x3c88, 0x00}, 2448c2ecf20Sopenharmony_ci {0x3d85, 0x14}, 2458c2ecf20Sopenharmony_ci {0x3f02, 0x08}, 2468c2ecf20Sopenharmony_ci {0x3f03, 0x10}, 2478c2ecf20Sopenharmony_ci {0x4008, 0x02}, 2488c2ecf20Sopenharmony_ci {0x4009, 0x09}, 2498c2ecf20Sopenharmony_ci {0x404e, 0x20}, 2508c2ecf20Sopenharmony_ci {0x4501, 0x00}, 2518c2ecf20Sopenharmony_ci {0x4502, 0x10}, 2528c2ecf20Sopenharmony_ci {0x4800, 0x00}, 2538c2ecf20Sopenharmony_ci {0x481f, 0x2a}, 2548c2ecf20Sopenharmony_ci {0x4837, 0x13}, 2558c2ecf20Sopenharmony_ci {0x5000, 0x17}, 2568c2ecf20Sopenharmony_ci {0x5780, 0x3e}, 2578c2ecf20Sopenharmony_ci {0x5781, 0x0f}, 2588c2ecf20Sopenharmony_ci {0x5782, 0x44}, 2598c2ecf20Sopenharmony_ci {0x5783, 0x02}, 2608c2ecf20Sopenharmony_ci {0x5784, 0x01}, 2618c2ecf20Sopenharmony_ci {0x5785, 0x01}, 2628c2ecf20Sopenharmony_ci {0x5786, 0x00}, 2638c2ecf20Sopenharmony_ci {0x5787, 0x04}, 2648c2ecf20Sopenharmony_ci {0x5788, 0x02}, 2658c2ecf20Sopenharmony_ci {0x5789, 0x0f}, 2668c2ecf20Sopenharmony_ci {0x578a, 0xfd}, 2678c2ecf20Sopenharmony_ci {0x578b, 0xf5}, 2688c2ecf20Sopenharmony_ci {0x578c, 0xf5}, 2698c2ecf20Sopenharmony_ci {0x578d, 0x03}, 2708c2ecf20Sopenharmony_ci {0x578e, 0x08}, 2718c2ecf20Sopenharmony_ci {0x578f, 0x0c}, 2728c2ecf20Sopenharmony_ci {0x5790, 0x08}, 2738c2ecf20Sopenharmony_ci {0x5791, 0x06}, 2748c2ecf20Sopenharmony_ci {0x5792, 0x00}, 2758c2ecf20Sopenharmony_ci {0x5793, 0x52}, 2768c2ecf20Sopenharmony_ci {0x5794, 0xa3}, 2778c2ecf20Sopenharmony_ci {0x5b00, 0x00}, 2788c2ecf20Sopenharmony_ci {0x5b01, 0x1c}, 2798c2ecf20Sopenharmony_ci {0x5b02, 0x00}, 2808c2ecf20Sopenharmony_ci {0x5b03, 0x7f}, 2818c2ecf20Sopenharmony_ci {0x5b05, 0x6c}, 2828c2ecf20Sopenharmony_ci {0x5e10, 0xfc}, 2838c2ecf20Sopenharmony_ci {0x4010, 0xf1}, 2848c2ecf20Sopenharmony_ci {0x3503, 0x08}, 2858c2ecf20Sopenharmony_ci {0x3505, 0x8c}, 2868c2ecf20Sopenharmony_ci {0x3507, 0x03}, 2878c2ecf20Sopenharmony_ci {0x3508, 0x00}, 2888c2ecf20Sopenharmony_ci {0x3509, 0xf8}, 2898c2ecf20Sopenharmony_ci {REG_NULL, 0x00}, 2908c2ecf20Sopenharmony_ci}; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci/* 2938c2ecf20Sopenharmony_ci * Xclk 24Mhz 2948c2ecf20Sopenharmony_ci * Pclk 45Mhz 2958c2ecf20Sopenharmony_ci * linelength 740(0x2e4) 2968c2ecf20Sopenharmony_ci * framelength 2024(0x7e8) 2978c2ecf20Sopenharmony_ci * grabwindow_width 2592 2988c2ecf20Sopenharmony_ci * grabwindow_height 1944 2998c2ecf20Sopenharmony_ci * max_framerate 30fps 3008c2ecf20Sopenharmony_ci * mipi_datarate per lane 840Mbps 3018c2ecf20Sopenharmony_ci */ 3028c2ecf20Sopenharmony_cistatic const struct regval ov5695_2592x1944_regs[] = { 3038c2ecf20Sopenharmony_ci {0x3501, 0x7e}, 3048c2ecf20Sopenharmony_ci {0x366e, 0x18}, 3058c2ecf20Sopenharmony_ci {0x3800, 0x00}, 3068c2ecf20Sopenharmony_ci {0x3801, 0x00}, 3078c2ecf20Sopenharmony_ci {0x3802, 0x00}, 3088c2ecf20Sopenharmony_ci {0x3803, 0x04}, 3098c2ecf20Sopenharmony_ci {0x3804, 0x0a}, 3108c2ecf20Sopenharmony_ci {0x3805, 0x3f}, 3118c2ecf20Sopenharmony_ci {0x3806, 0x07}, 3128c2ecf20Sopenharmony_ci {0x3807, 0xab}, 3138c2ecf20Sopenharmony_ci {0x3808, 0x0a}, 3148c2ecf20Sopenharmony_ci {0x3809, 0x20}, 3158c2ecf20Sopenharmony_ci {0x380a, 0x07}, 3168c2ecf20Sopenharmony_ci {0x380b, 0x98}, 3178c2ecf20Sopenharmony_ci {0x380c, 0x02}, 3188c2ecf20Sopenharmony_ci {0x380d, 0xe4}, 3198c2ecf20Sopenharmony_ci {0x380e, 0x07}, 3208c2ecf20Sopenharmony_ci {0x380f, 0xe8}, 3218c2ecf20Sopenharmony_ci {0x3811, 0x06}, 3228c2ecf20Sopenharmony_ci {0x3813, 0x08}, 3238c2ecf20Sopenharmony_ci {0x3814, 0x01}, 3248c2ecf20Sopenharmony_ci {0x3816, 0x01}, 3258c2ecf20Sopenharmony_ci {0x3817, 0x01}, 3268c2ecf20Sopenharmony_ci {0x3820, 0x88}, 3278c2ecf20Sopenharmony_ci {0x3821, 0x00}, 3288c2ecf20Sopenharmony_ci {0x4501, 0x00}, 3298c2ecf20Sopenharmony_ci {0x4008, 0x04}, 3308c2ecf20Sopenharmony_ci {0x4009, 0x13}, 3318c2ecf20Sopenharmony_ci {REG_NULL, 0x00}, 3328c2ecf20Sopenharmony_ci}; 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci/* 3358c2ecf20Sopenharmony_ci * Xclk 24Mhz 3368c2ecf20Sopenharmony_ci * Pclk 45Mhz 3378c2ecf20Sopenharmony_ci * linelength 672(0x2a0) 3388c2ecf20Sopenharmony_ci * framelength 2232(0x8b8) 3398c2ecf20Sopenharmony_ci * grabwindow_width 1920 3408c2ecf20Sopenharmony_ci * grabwindow_height 1080 3418c2ecf20Sopenharmony_ci * max_framerate 30fps 3428c2ecf20Sopenharmony_ci * mipi_datarate per lane 840Mbps 3438c2ecf20Sopenharmony_ci */ 3448c2ecf20Sopenharmony_cistatic const struct regval ov5695_1920x1080_regs[] = { 3458c2ecf20Sopenharmony_ci {0x3501, 0x45}, 3468c2ecf20Sopenharmony_ci {0x366e, 0x18}, 3478c2ecf20Sopenharmony_ci {0x3800, 0x01}, 3488c2ecf20Sopenharmony_ci {0x3801, 0x50}, 3498c2ecf20Sopenharmony_ci {0x3802, 0x01}, 3508c2ecf20Sopenharmony_ci {0x3803, 0xb8}, 3518c2ecf20Sopenharmony_ci {0x3804, 0x08}, 3528c2ecf20Sopenharmony_ci {0x3805, 0xef}, 3538c2ecf20Sopenharmony_ci {0x3806, 0x05}, 3548c2ecf20Sopenharmony_ci {0x3807, 0xf7}, 3558c2ecf20Sopenharmony_ci {0x3808, 0x07}, 3568c2ecf20Sopenharmony_ci {0x3809, 0x80}, 3578c2ecf20Sopenharmony_ci {0x380a, 0x04}, 3588c2ecf20Sopenharmony_ci {0x380b, 0x38}, 3598c2ecf20Sopenharmony_ci {0x380c, 0x02}, 3608c2ecf20Sopenharmony_ci {0x380d, 0xa0}, 3618c2ecf20Sopenharmony_ci {0x380e, 0x08}, 3628c2ecf20Sopenharmony_ci {0x380f, 0xb8}, 3638c2ecf20Sopenharmony_ci {0x3811, 0x06}, 3648c2ecf20Sopenharmony_ci {0x3813, 0x04}, 3658c2ecf20Sopenharmony_ci {0x3814, 0x01}, 3668c2ecf20Sopenharmony_ci {0x3816, 0x01}, 3678c2ecf20Sopenharmony_ci {0x3817, 0x01}, 3688c2ecf20Sopenharmony_ci {0x3820, 0x88}, 3698c2ecf20Sopenharmony_ci {0x3821, 0x00}, 3708c2ecf20Sopenharmony_ci {0x4501, 0x00}, 3718c2ecf20Sopenharmony_ci {0x4008, 0x04}, 3728c2ecf20Sopenharmony_ci {0x4009, 0x13}, 3738c2ecf20Sopenharmony_ci {REG_NULL, 0x00} 3748c2ecf20Sopenharmony_ci}; 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci/* 3778c2ecf20Sopenharmony_ci * Xclk 24Mhz 3788c2ecf20Sopenharmony_ci * Pclk 45Mhz 3798c2ecf20Sopenharmony_ci * linelength 740(0x02e4) 3808c2ecf20Sopenharmony_ci * framelength 1012(0x03f4) 3818c2ecf20Sopenharmony_ci * grabwindow_width 1296 3828c2ecf20Sopenharmony_ci * grabwindow_height 972 3838c2ecf20Sopenharmony_ci * max_framerate 60fps 3848c2ecf20Sopenharmony_ci * mipi_datarate per lane 840Mbps 3858c2ecf20Sopenharmony_ci */ 3868c2ecf20Sopenharmony_cistatic const struct regval ov5695_1296x972_regs[] = { 3878c2ecf20Sopenharmony_ci {0x0103, 0x01}, 3888c2ecf20Sopenharmony_ci {0x0100, 0x00}, 3898c2ecf20Sopenharmony_ci {0x0300, 0x04}, 3908c2ecf20Sopenharmony_ci {0x0301, 0x00}, 3918c2ecf20Sopenharmony_ci {0x0302, 0x69}, 3928c2ecf20Sopenharmony_ci {0x0303, 0x00}, 3938c2ecf20Sopenharmony_ci {0x0304, 0x00}, 3948c2ecf20Sopenharmony_ci {0x0305, 0x01}, 3958c2ecf20Sopenharmony_ci {0x0307, 0x00}, 3968c2ecf20Sopenharmony_ci {0x030b, 0x00}, 3978c2ecf20Sopenharmony_ci {0x030c, 0x00}, 3988c2ecf20Sopenharmony_ci {0x030d, 0x1e}, 3998c2ecf20Sopenharmony_ci {0x030e, 0x04}, 4008c2ecf20Sopenharmony_ci {0x030f, 0x03}, 4018c2ecf20Sopenharmony_ci {0x0312, 0x01}, 4028c2ecf20Sopenharmony_ci {0x3000, 0x00}, 4038c2ecf20Sopenharmony_ci {0x3002, 0xa1}, 4048c2ecf20Sopenharmony_ci {0x3008, 0x00}, 4058c2ecf20Sopenharmony_ci {0x3010, 0x00}, 4068c2ecf20Sopenharmony_ci {0x3016, 0x32}, 4078c2ecf20Sopenharmony_ci {0x3022, 0x51}, 4088c2ecf20Sopenharmony_ci {0x3106, 0x15}, 4098c2ecf20Sopenharmony_ci {0x3107, 0x01}, 4108c2ecf20Sopenharmony_ci {0x3108, 0x05}, 4118c2ecf20Sopenharmony_ci {0x3500, 0x00}, 4128c2ecf20Sopenharmony_ci {0x3501, 0x3e}, 4138c2ecf20Sopenharmony_ci {0x3502, 0x00}, 4148c2ecf20Sopenharmony_ci {0x3503, 0x08}, 4158c2ecf20Sopenharmony_ci {0x3504, 0x03}, 4168c2ecf20Sopenharmony_ci {0x3505, 0x8c}, 4178c2ecf20Sopenharmony_ci {0x3507, 0x03}, 4188c2ecf20Sopenharmony_ci {0x3508, 0x00}, 4198c2ecf20Sopenharmony_ci {0x3509, 0x10}, 4208c2ecf20Sopenharmony_ci {0x350c, 0x00}, 4218c2ecf20Sopenharmony_ci {0x350d, 0x80}, 4228c2ecf20Sopenharmony_ci {0x3510, 0x00}, 4238c2ecf20Sopenharmony_ci {0x3511, 0x02}, 4248c2ecf20Sopenharmony_ci {0x3512, 0x00}, 4258c2ecf20Sopenharmony_ci {0x3601, 0x55}, 4268c2ecf20Sopenharmony_ci {0x3602, 0x58}, 4278c2ecf20Sopenharmony_ci {0x3611, 0x58}, 4288c2ecf20Sopenharmony_ci {0x3614, 0x30}, 4298c2ecf20Sopenharmony_ci {0x3615, 0x77}, 4308c2ecf20Sopenharmony_ci {0x3621, 0x08}, 4318c2ecf20Sopenharmony_ci {0x3624, 0x40}, 4328c2ecf20Sopenharmony_ci {0x3633, 0x0c}, 4338c2ecf20Sopenharmony_ci {0x3634, 0x0c}, 4348c2ecf20Sopenharmony_ci {0x3635, 0x0c}, 4358c2ecf20Sopenharmony_ci {0x3636, 0x0c}, 4368c2ecf20Sopenharmony_ci {0x3638, 0x00}, 4378c2ecf20Sopenharmony_ci {0x3639, 0x00}, 4388c2ecf20Sopenharmony_ci {0x363a, 0x00}, 4398c2ecf20Sopenharmony_ci {0x363b, 0x00}, 4408c2ecf20Sopenharmony_ci {0x363c, 0xff}, 4418c2ecf20Sopenharmony_ci {0x363d, 0xfa}, 4428c2ecf20Sopenharmony_ci {0x3650, 0x44}, 4438c2ecf20Sopenharmony_ci {0x3651, 0x44}, 4448c2ecf20Sopenharmony_ci {0x3652, 0x44}, 4458c2ecf20Sopenharmony_ci {0x3653, 0x44}, 4468c2ecf20Sopenharmony_ci {0x3654, 0x44}, 4478c2ecf20Sopenharmony_ci {0x3655, 0x44}, 4488c2ecf20Sopenharmony_ci {0x3656, 0x44}, 4498c2ecf20Sopenharmony_ci {0x3657, 0x44}, 4508c2ecf20Sopenharmony_ci {0x3660, 0x00}, 4518c2ecf20Sopenharmony_ci {0x3661, 0x00}, 4528c2ecf20Sopenharmony_ci {0x3662, 0x00}, 4538c2ecf20Sopenharmony_ci {0x366a, 0x00}, 4548c2ecf20Sopenharmony_ci {0x366e, 0x0c}, 4558c2ecf20Sopenharmony_ci {0x3673, 0x04}, 4568c2ecf20Sopenharmony_ci {0x3700, 0x14}, 4578c2ecf20Sopenharmony_ci {0x3703, 0x0c}, 4588c2ecf20Sopenharmony_ci {0x3706, 0x24}, 4598c2ecf20Sopenharmony_ci {0x3714, 0x27}, 4608c2ecf20Sopenharmony_ci {0x3715, 0x01}, 4618c2ecf20Sopenharmony_ci {0x3716, 0x00}, 4628c2ecf20Sopenharmony_ci {0x3717, 0x02}, 4638c2ecf20Sopenharmony_ci {0x3733, 0x10}, 4648c2ecf20Sopenharmony_ci {0x3734, 0x40}, 4658c2ecf20Sopenharmony_ci {0x373f, 0xa0}, 4668c2ecf20Sopenharmony_ci {0x3765, 0x20}, 4678c2ecf20Sopenharmony_ci {0x37a1, 0x1d}, 4688c2ecf20Sopenharmony_ci {0x37a8, 0x26}, 4698c2ecf20Sopenharmony_ci {0x37ab, 0x14}, 4708c2ecf20Sopenharmony_ci {0x37c2, 0x04}, 4718c2ecf20Sopenharmony_ci {0x37c3, 0xf0}, 4728c2ecf20Sopenharmony_ci {0x37cb, 0x09}, 4738c2ecf20Sopenharmony_ci {0x37cc, 0x13}, 4748c2ecf20Sopenharmony_ci {0x37cd, 0x1f}, 4758c2ecf20Sopenharmony_ci {0x37ce, 0x1f}, 4768c2ecf20Sopenharmony_ci {0x3800, 0x00}, 4778c2ecf20Sopenharmony_ci {0x3801, 0x00}, 4788c2ecf20Sopenharmony_ci {0x3802, 0x00}, 4798c2ecf20Sopenharmony_ci {0x3803, 0x00}, 4808c2ecf20Sopenharmony_ci {0x3804, 0x0a}, 4818c2ecf20Sopenharmony_ci {0x3805, 0x3f}, 4828c2ecf20Sopenharmony_ci {0x3806, 0x07}, 4838c2ecf20Sopenharmony_ci {0x3807, 0xaf}, 4848c2ecf20Sopenharmony_ci {0x3808, 0x05}, 4858c2ecf20Sopenharmony_ci {0x3809, 0x10}, 4868c2ecf20Sopenharmony_ci {0x380a, 0x03}, 4878c2ecf20Sopenharmony_ci {0x380b, 0xcc}, 4888c2ecf20Sopenharmony_ci {0x380c, 0x02}, 4898c2ecf20Sopenharmony_ci {0x380d, 0xe4}, 4908c2ecf20Sopenharmony_ci {0x380e, 0x03}, 4918c2ecf20Sopenharmony_ci {0x380f, 0xf4}, 4928c2ecf20Sopenharmony_ci {0x3810, 0x00}, 4938c2ecf20Sopenharmony_ci {0x3811, 0x00}, 4948c2ecf20Sopenharmony_ci {0x3812, 0x00}, 4958c2ecf20Sopenharmony_ci {0x3813, 0x06}, 4968c2ecf20Sopenharmony_ci {0x3814, 0x03}, 4978c2ecf20Sopenharmony_ci {0x3815, 0x01}, 4988c2ecf20Sopenharmony_ci {0x3816, 0x03}, 4998c2ecf20Sopenharmony_ci {0x3817, 0x01}, 5008c2ecf20Sopenharmony_ci {0x3818, 0x00}, 5018c2ecf20Sopenharmony_ci {0x3819, 0x00}, 5028c2ecf20Sopenharmony_ci {0x381a, 0x00}, 5038c2ecf20Sopenharmony_ci {0x381b, 0x01}, 5048c2ecf20Sopenharmony_ci {0x3820, 0x8b}, 5058c2ecf20Sopenharmony_ci {0x3821, 0x01}, 5068c2ecf20Sopenharmony_ci {0x3c80, 0x08}, 5078c2ecf20Sopenharmony_ci {0x3c82, 0x00}, 5088c2ecf20Sopenharmony_ci {0x3c83, 0x00}, 5098c2ecf20Sopenharmony_ci {0x3c88, 0x00}, 5108c2ecf20Sopenharmony_ci {0x3d85, 0x14}, 5118c2ecf20Sopenharmony_ci {0x3f02, 0x08}, 5128c2ecf20Sopenharmony_ci {0x3f03, 0x10}, 5138c2ecf20Sopenharmony_ci {0x4008, 0x02}, 5148c2ecf20Sopenharmony_ci {0x4009, 0x09}, 5158c2ecf20Sopenharmony_ci {0x404e, 0x20}, 5168c2ecf20Sopenharmony_ci {0x4501, 0x00}, 5178c2ecf20Sopenharmony_ci {0x4502, 0x10}, 5188c2ecf20Sopenharmony_ci {0x4800, 0x00}, 5198c2ecf20Sopenharmony_ci {0x481f, 0x2a}, 5208c2ecf20Sopenharmony_ci {0x4837, 0x13}, 5218c2ecf20Sopenharmony_ci {0x5000, 0x13}, 5228c2ecf20Sopenharmony_ci {0x5780, 0x3e}, 5238c2ecf20Sopenharmony_ci {0x5781, 0x0f}, 5248c2ecf20Sopenharmony_ci {0x5782, 0x44}, 5258c2ecf20Sopenharmony_ci {0x5783, 0x02}, 5268c2ecf20Sopenharmony_ci {0x5784, 0x01}, 5278c2ecf20Sopenharmony_ci {0x5785, 0x01}, 5288c2ecf20Sopenharmony_ci {0x5786, 0x00}, 5298c2ecf20Sopenharmony_ci {0x5787, 0x04}, 5308c2ecf20Sopenharmony_ci {0x5788, 0x02}, 5318c2ecf20Sopenharmony_ci {0x5789, 0x0f}, 5328c2ecf20Sopenharmony_ci {0x578a, 0xfd}, 5338c2ecf20Sopenharmony_ci {0x578b, 0xf5}, 5348c2ecf20Sopenharmony_ci {0x578c, 0xf5}, 5358c2ecf20Sopenharmony_ci {0x578d, 0x03}, 5368c2ecf20Sopenharmony_ci {0x578e, 0x08}, 5378c2ecf20Sopenharmony_ci {0x578f, 0x0c}, 5388c2ecf20Sopenharmony_ci {0x5790, 0x08}, 5398c2ecf20Sopenharmony_ci {0x5791, 0x06}, 5408c2ecf20Sopenharmony_ci {0x5792, 0x00}, 5418c2ecf20Sopenharmony_ci {0x5793, 0x52}, 5428c2ecf20Sopenharmony_ci {0x5794, 0xa3}, 5438c2ecf20Sopenharmony_ci {0x5b00, 0x00}, 5448c2ecf20Sopenharmony_ci {0x5b01, 0x1c}, 5458c2ecf20Sopenharmony_ci {0x5b02, 0x00}, 5468c2ecf20Sopenharmony_ci {0x5b03, 0x7f}, 5478c2ecf20Sopenharmony_ci {0x5b05, 0x6c}, 5488c2ecf20Sopenharmony_ci {0x5e10, 0xfc}, 5498c2ecf20Sopenharmony_ci {0x4010, 0xf1}, 5508c2ecf20Sopenharmony_ci {0x3503, 0x08}, 5518c2ecf20Sopenharmony_ci {0x3505, 0x8c}, 5528c2ecf20Sopenharmony_ci {0x3507, 0x03}, 5538c2ecf20Sopenharmony_ci {0x3508, 0x00}, 5548c2ecf20Sopenharmony_ci {0x3509, 0xf8}, 5558c2ecf20Sopenharmony_ci {0x0100, 0x01}, 5568c2ecf20Sopenharmony_ci {REG_NULL, 0x00} 5578c2ecf20Sopenharmony_ci}; 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci/* 5608c2ecf20Sopenharmony_ci * Xclk 24Mhz 5618c2ecf20Sopenharmony_ci * Pclk 45Mhz 5628c2ecf20Sopenharmony_ci * linelength 672(0x2a0) 5638c2ecf20Sopenharmony_ci * framelength 2232(0x8b8) 5648c2ecf20Sopenharmony_ci * grabwindow_width 1280 5658c2ecf20Sopenharmony_ci * grabwindow_height 720 5668c2ecf20Sopenharmony_ci * max_framerate 30fps 5678c2ecf20Sopenharmony_ci * mipi_datarate per lane 840Mbps 5688c2ecf20Sopenharmony_ci */ 5698c2ecf20Sopenharmony_cistatic const struct regval ov5695_1280x720_regs[] = { 5708c2ecf20Sopenharmony_ci {0x3501, 0x45}, 5718c2ecf20Sopenharmony_ci {0x366e, 0x0c}, 5728c2ecf20Sopenharmony_ci {0x3800, 0x00}, 5738c2ecf20Sopenharmony_ci {0x3801, 0x00}, 5748c2ecf20Sopenharmony_ci {0x3802, 0x01}, 5758c2ecf20Sopenharmony_ci {0x3803, 0x00}, 5768c2ecf20Sopenharmony_ci {0x3804, 0x0a}, 5778c2ecf20Sopenharmony_ci {0x3805, 0x3f}, 5788c2ecf20Sopenharmony_ci {0x3806, 0x06}, 5798c2ecf20Sopenharmony_ci {0x3807, 0xaf}, 5808c2ecf20Sopenharmony_ci {0x3808, 0x05}, 5818c2ecf20Sopenharmony_ci {0x3809, 0x00}, 5828c2ecf20Sopenharmony_ci {0x380a, 0x02}, 5838c2ecf20Sopenharmony_ci {0x380b, 0xd0}, 5848c2ecf20Sopenharmony_ci {0x380c, 0x02}, 5858c2ecf20Sopenharmony_ci {0x380d, 0xa0}, 5868c2ecf20Sopenharmony_ci {0x380e, 0x08}, 5878c2ecf20Sopenharmony_ci {0x380f, 0xb8}, 5888c2ecf20Sopenharmony_ci {0x3811, 0x06}, 5898c2ecf20Sopenharmony_ci {0x3813, 0x02}, 5908c2ecf20Sopenharmony_ci {0x3814, 0x03}, 5918c2ecf20Sopenharmony_ci {0x3816, 0x03}, 5928c2ecf20Sopenharmony_ci {0x3817, 0x01}, 5938c2ecf20Sopenharmony_ci {0x3820, 0x8b}, 5948c2ecf20Sopenharmony_ci {0x3821, 0x01}, 5958c2ecf20Sopenharmony_ci {0x4501, 0x00}, 5968c2ecf20Sopenharmony_ci {0x4008, 0x02}, 5978c2ecf20Sopenharmony_ci {0x4009, 0x09}, 5988c2ecf20Sopenharmony_ci {REG_NULL, 0x00} 5998c2ecf20Sopenharmony_ci}; 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci/* 6028c2ecf20Sopenharmony_ci * Xclk 24Mhz 6038c2ecf20Sopenharmony_ci * Pclk 45Mhz 6048c2ecf20Sopenharmony_ci * linelength 672(0x2a0) 6058c2ecf20Sopenharmony_ci * framelength 558(0x22e) 6068c2ecf20Sopenharmony_ci * grabwindow_width 640 6078c2ecf20Sopenharmony_ci * grabwindow_height 480 6088c2ecf20Sopenharmony_ci * max_framerate 120fps 6098c2ecf20Sopenharmony_ci * mipi_datarate per lane 840Mbps 6108c2ecf20Sopenharmony_ci */ 6118c2ecf20Sopenharmony_cistatic const struct regval ov5695_640x480_regs[] = { 6128c2ecf20Sopenharmony_ci {0x3501, 0x22}, 6138c2ecf20Sopenharmony_ci {0x366e, 0x0c}, 6148c2ecf20Sopenharmony_ci {0x3800, 0x00}, 6158c2ecf20Sopenharmony_ci {0x3801, 0x00}, 6168c2ecf20Sopenharmony_ci {0x3802, 0x00}, 6178c2ecf20Sopenharmony_ci {0x3803, 0x08}, 6188c2ecf20Sopenharmony_ci {0x3804, 0x0a}, 6198c2ecf20Sopenharmony_ci {0x3805, 0x3f}, 6208c2ecf20Sopenharmony_ci {0x3806, 0x07}, 6218c2ecf20Sopenharmony_ci {0x3807, 0xa7}, 6228c2ecf20Sopenharmony_ci {0x3808, 0x02}, 6238c2ecf20Sopenharmony_ci {0x3809, 0x80}, 6248c2ecf20Sopenharmony_ci {0x380a, 0x01}, 6258c2ecf20Sopenharmony_ci {0x380b, 0xe0}, 6268c2ecf20Sopenharmony_ci {0x380c, 0x02}, 6278c2ecf20Sopenharmony_ci {0x380d, 0xa0}, 6288c2ecf20Sopenharmony_ci {0x380e, 0x02}, 6298c2ecf20Sopenharmony_ci {0x380f, 0x2e}, 6308c2ecf20Sopenharmony_ci {0x3811, 0x06}, 6318c2ecf20Sopenharmony_ci {0x3813, 0x04}, 6328c2ecf20Sopenharmony_ci {0x3814, 0x07}, 6338c2ecf20Sopenharmony_ci {0x3816, 0x05}, 6348c2ecf20Sopenharmony_ci {0x3817, 0x03}, 6358c2ecf20Sopenharmony_ci {0x3820, 0x8d}, 6368c2ecf20Sopenharmony_ci {0x3821, 0x01}, 6378c2ecf20Sopenharmony_ci {0x4501, 0x00}, 6388c2ecf20Sopenharmony_ci {0x4008, 0x02}, 6398c2ecf20Sopenharmony_ci {0x4009, 0x09}, 6408c2ecf20Sopenharmony_ci {REG_NULL, 0x00} 6418c2ecf20Sopenharmony_ci}; 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_cistatic const struct ov5695_mode supported_modes[] = { 6448c2ecf20Sopenharmony_ci { 6458c2ecf20Sopenharmony_ci .width = 2592, 6468c2ecf20Sopenharmony_ci .height = 1944, 6478c2ecf20Sopenharmony_ci .max_fps = 30, 6488c2ecf20Sopenharmony_ci .exp_def = 0x0450, 6498c2ecf20Sopenharmony_ci .hts_def = 0x02e4 * 4, 6508c2ecf20Sopenharmony_ci .vts_def = 0x07e8, 6518c2ecf20Sopenharmony_ci .reg_list = ov5695_2592x1944_regs, 6528c2ecf20Sopenharmony_ci }, 6538c2ecf20Sopenharmony_ci { 6548c2ecf20Sopenharmony_ci .width = 1920, 6558c2ecf20Sopenharmony_ci .height = 1080, 6568c2ecf20Sopenharmony_ci .max_fps = 30, 6578c2ecf20Sopenharmony_ci .exp_def = 0x0450, 6588c2ecf20Sopenharmony_ci .hts_def = 0x02a0 * 4, 6598c2ecf20Sopenharmony_ci .vts_def = 0x08b8, 6608c2ecf20Sopenharmony_ci .reg_list = ov5695_1920x1080_regs, 6618c2ecf20Sopenharmony_ci }, 6628c2ecf20Sopenharmony_ci { 6638c2ecf20Sopenharmony_ci .width = 1296, 6648c2ecf20Sopenharmony_ci .height = 972, 6658c2ecf20Sopenharmony_ci .max_fps = 60, 6668c2ecf20Sopenharmony_ci .exp_def = 0x03e0, 6678c2ecf20Sopenharmony_ci .hts_def = 0x02e4 * 4, 6688c2ecf20Sopenharmony_ci .vts_def = 0x03f4, 6698c2ecf20Sopenharmony_ci .reg_list = ov5695_1296x972_regs, 6708c2ecf20Sopenharmony_ci }, 6718c2ecf20Sopenharmony_ci { 6728c2ecf20Sopenharmony_ci .width = 1280, 6738c2ecf20Sopenharmony_ci .height = 720, 6748c2ecf20Sopenharmony_ci .max_fps = 30, 6758c2ecf20Sopenharmony_ci .exp_def = 0x0450, 6768c2ecf20Sopenharmony_ci .hts_def = 0x02a0 * 4, 6778c2ecf20Sopenharmony_ci .vts_def = 0x08b8, 6788c2ecf20Sopenharmony_ci .reg_list = ov5695_1280x720_regs, 6798c2ecf20Sopenharmony_ci }, 6808c2ecf20Sopenharmony_ci { 6818c2ecf20Sopenharmony_ci .width = 640, 6828c2ecf20Sopenharmony_ci .height = 480, 6838c2ecf20Sopenharmony_ci .max_fps = 120, 6848c2ecf20Sopenharmony_ci .exp_def = 0x0450, 6858c2ecf20Sopenharmony_ci .hts_def = 0x02a0 * 4, 6868c2ecf20Sopenharmony_ci .vts_def = 0x022e, 6878c2ecf20Sopenharmony_ci .reg_list = ov5695_640x480_regs, 6888c2ecf20Sopenharmony_ci }, 6898c2ecf20Sopenharmony_ci}; 6908c2ecf20Sopenharmony_ci 6918c2ecf20Sopenharmony_ci#define OV5695_LINK_FREQ_420MHZ 420000000 6928c2ecf20Sopenharmony_cistatic const s64 link_freq_menu_items[] = { 6938c2ecf20Sopenharmony_ci OV5695_LINK_FREQ_420MHZ 6948c2ecf20Sopenharmony_ci}; 6958c2ecf20Sopenharmony_ci 6968c2ecf20Sopenharmony_cistatic const char * const ov5695_test_pattern_menu[] = { 6978c2ecf20Sopenharmony_ci "Disabled", 6988c2ecf20Sopenharmony_ci "Vertical Color Bar Type 1", 6998c2ecf20Sopenharmony_ci "Vertical Color Bar Type 2", 7008c2ecf20Sopenharmony_ci "Vertical Color Bar Type 3", 7018c2ecf20Sopenharmony_ci "Vertical Color Bar Type 4" 7028c2ecf20Sopenharmony_ci}; 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_ci/* Write registers up to 4 at a time */ 7058c2ecf20Sopenharmony_cistatic int ov5695_write_reg(struct i2c_client *client, u16 reg, 7068c2ecf20Sopenharmony_ci u32 len, u32 val) 7078c2ecf20Sopenharmony_ci{ 7088c2ecf20Sopenharmony_ci u32 buf_i, val_i; 7098c2ecf20Sopenharmony_ci u8 buf[6]; 7108c2ecf20Sopenharmony_ci u8 *val_p; 7118c2ecf20Sopenharmony_ci __be32 val_be; 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ci if (len > 4) 7148c2ecf20Sopenharmony_ci return -EINVAL; 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_ci buf[0] = reg >> 8; 7178c2ecf20Sopenharmony_ci buf[1] = reg & 0xff; 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_ci val_be = cpu_to_be32(val); 7208c2ecf20Sopenharmony_ci val_p = (u8 *)&val_be; 7218c2ecf20Sopenharmony_ci buf_i = 2; 7228c2ecf20Sopenharmony_ci val_i = 4 - len; 7238c2ecf20Sopenharmony_ci 7248c2ecf20Sopenharmony_ci while (val_i < 4) 7258c2ecf20Sopenharmony_ci buf[buf_i++] = val_p[val_i++]; 7268c2ecf20Sopenharmony_ci 7278c2ecf20Sopenharmony_ci if (i2c_master_send(client, buf, len + 2) != len + 2) 7288c2ecf20Sopenharmony_ci return -EIO; 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_ci return 0; 7318c2ecf20Sopenharmony_ci} 7328c2ecf20Sopenharmony_ci 7338c2ecf20Sopenharmony_cistatic int ov5695_write_array(struct i2c_client *client, 7348c2ecf20Sopenharmony_ci const struct regval *regs) 7358c2ecf20Sopenharmony_ci{ 7368c2ecf20Sopenharmony_ci u32 i; 7378c2ecf20Sopenharmony_ci int ret = 0; 7388c2ecf20Sopenharmony_ci 7398c2ecf20Sopenharmony_ci for (i = 0; ret == 0 && regs[i].addr != REG_NULL; i++) 7408c2ecf20Sopenharmony_ci ret = ov5695_write_reg(client, regs[i].addr, 7418c2ecf20Sopenharmony_ci OV5695_REG_VALUE_08BIT, regs[i].val); 7428c2ecf20Sopenharmony_ci 7438c2ecf20Sopenharmony_ci return ret; 7448c2ecf20Sopenharmony_ci} 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci/* Read registers up to 4 at a time */ 7478c2ecf20Sopenharmony_cistatic int ov5695_read_reg(struct i2c_client *client, u16 reg, unsigned int len, 7488c2ecf20Sopenharmony_ci u32 *val) 7498c2ecf20Sopenharmony_ci{ 7508c2ecf20Sopenharmony_ci struct i2c_msg msgs[2]; 7518c2ecf20Sopenharmony_ci u8 *data_be_p; 7528c2ecf20Sopenharmony_ci __be32 data_be = 0; 7538c2ecf20Sopenharmony_ci __be16 reg_addr_be = cpu_to_be16(reg); 7548c2ecf20Sopenharmony_ci int ret; 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci if (len > 4) 7578c2ecf20Sopenharmony_ci return -EINVAL; 7588c2ecf20Sopenharmony_ci 7598c2ecf20Sopenharmony_ci data_be_p = (u8 *)&data_be; 7608c2ecf20Sopenharmony_ci /* Write register address */ 7618c2ecf20Sopenharmony_ci msgs[0].addr = client->addr; 7628c2ecf20Sopenharmony_ci msgs[0].flags = 0; 7638c2ecf20Sopenharmony_ci msgs[0].len = 2; 7648c2ecf20Sopenharmony_ci msgs[0].buf = (u8 *)®_addr_be; 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci /* Read data from register */ 7678c2ecf20Sopenharmony_ci msgs[1].addr = client->addr; 7688c2ecf20Sopenharmony_ci msgs[1].flags = I2C_M_RD; 7698c2ecf20Sopenharmony_ci msgs[1].len = len; 7708c2ecf20Sopenharmony_ci msgs[1].buf = &data_be_p[4 - len]; 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 7738c2ecf20Sopenharmony_ci if (ret != ARRAY_SIZE(msgs)) 7748c2ecf20Sopenharmony_ci return -EIO; 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_ci *val = be32_to_cpu(data_be); 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci return 0; 7798c2ecf20Sopenharmony_ci} 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_cistatic int ov5695_get_reso_dist(const struct ov5695_mode *mode, 7828c2ecf20Sopenharmony_ci struct v4l2_mbus_framefmt *framefmt) 7838c2ecf20Sopenharmony_ci{ 7848c2ecf20Sopenharmony_ci return abs(mode->width - framefmt->width) + 7858c2ecf20Sopenharmony_ci abs(mode->height - framefmt->height); 7868c2ecf20Sopenharmony_ci} 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_cistatic const struct ov5695_mode * 7898c2ecf20Sopenharmony_ciov5695_find_best_fit(struct v4l2_subdev_format *fmt) 7908c2ecf20Sopenharmony_ci{ 7918c2ecf20Sopenharmony_ci struct v4l2_mbus_framefmt *framefmt = &fmt->format; 7928c2ecf20Sopenharmony_ci int dist; 7938c2ecf20Sopenharmony_ci int cur_best_fit = 0; 7948c2ecf20Sopenharmony_ci int cur_best_fit_dist = -1; 7958c2ecf20Sopenharmony_ci int i; 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(supported_modes); i++) { 7988c2ecf20Sopenharmony_ci dist = ov5695_get_reso_dist(&supported_modes[i], framefmt); 7998c2ecf20Sopenharmony_ci if (cur_best_fit_dist == -1 || dist < cur_best_fit_dist) { 8008c2ecf20Sopenharmony_ci cur_best_fit_dist = dist; 8018c2ecf20Sopenharmony_ci cur_best_fit = i; 8028c2ecf20Sopenharmony_ci } 8038c2ecf20Sopenharmony_ci } 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci return &supported_modes[cur_best_fit]; 8068c2ecf20Sopenharmony_ci} 8078c2ecf20Sopenharmony_ci 8088c2ecf20Sopenharmony_cistatic int ov5695_set_fmt(struct v4l2_subdev *sd, 8098c2ecf20Sopenharmony_ci struct v4l2_subdev_pad_config *cfg, 8108c2ecf20Sopenharmony_ci struct v4l2_subdev_format *fmt) 8118c2ecf20Sopenharmony_ci{ 8128c2ecf20Sopenharmony_ci struct ov5695 *ov5695 = to_ov5695(sd); 8138c2ecf20Sopenharmony_ci const struct ov5695_mode *mode; 8148c2ecf20Sopenharmony_ci s64 h_blank, vblank_def; 8158c2ecf20Sopenharmony_ci 8168c2ecf20Sopenharmony_ci mutex_lock(&ov5695->mutex); 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci mode = ov5695_find_best_fit(fmt); 8198c2ecf20Sopenharmony_ci fmt->format.code = MEDIA_BUS_FMT_SBGGR10_1X10; 8208c2ecf20Sopenharmony_ci fmt->format.width = mode->width; 8218c2ecf20Sopenharmony_ci fmt->format.height = mode->height; 8228c2ecf20Sopenharmony_ci fmt->format.field = V4L2_FIELD_NONE; 8238c2ecf20Sopenharmony_ci if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 8248c2ecf20Sopenharmony_ci#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API 8258c2ecf20Sopenharmony_ci *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format; 8268c2ecf20Sopenharmony_ci#endif 8278c2ecf20Sopenharmony_ci } else { 8288c2ecf20Sopenharmony_ci ov5695->cur_mode = mode; 8298c2ecf20Sopenharmony_ci h_blank = mode->hts_def - mode->width; 8308c2ecf20Sopenharmony_ci __v4l2_ctrl_modify_range(ov5695->hblank, h_blank, 8318c2ecf20Sopenharmony_ci h_blank, 1, h_blank); 8328c2ecf20Sopenharmony_ci vblank_def = mode->vts_def - mode->height; 8338c2ecf20Sopenharmony_ci __v4l2_ctrl_modify_range(ov5695->vblank, vblank_def, 8348c2ecf20Sopenharmony_ci OV5695_VTS_MAX - mode->height, 8358c2ecf20Sopenharmony_ci 1, vblank_def); 8368c2ecf20Sopenharmony_ci } 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_ci mutex_unlock(&ov5695->mutex); 8398c2ecf20Sopenharmony_ci 8408c2ecf20Sopenharmony_ci return 0; 8418c2ecf20Sopenharmony_ci} 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_cistatic int ov5695_get_fmt(struct v4l2_subdev *sd, 8448c2ecf20Sopenharmony_ci struct v4l2_subdev_pad_config *cfg, 8458c2ecf20Sopenharmony_ci struct v4l2_subdev_format *fmt) 8468c2ecf20Sopenharmony_ci{ 8478c2ecf20Sopenharmony_ci struct ov5695 *ov5695 = to_ov5695(sd); 8488c2ecf20Sopenharmony_ci const struct ov5695_mode *mode = ov5695->cur_mode; 8498c2ecf20Sopenharmony_ci 8508c2ecf20Sopenharmony_ci mutex_lock(&ov5695->mutex); 8518c2ecf20Sopenharmony_ci if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 8528c2ecf20Sopenharmony_ci#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API 8538c2ecf20Sopenharmony_ci fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad); 8548c2ecf20Sopenharmony_ci#else 8558c2ecf20Sopenharmony_ci mutex_unlock(&ov5695->mutex); 8568c2ecf20Sopenharmony_ci return -EINVAL; 8578c2ecf20Sopenharmony_ci#endif 8588c2ecf20Sopenharmony_ci } else { 8598c2ecf20Sopenharmony_ci fmt->format.width = mode->width; 8608c2ecf20Sopenharmony_ci fmt->format.height = mode->height; 8618c2ecf20Sopenharmony_ci fmt->format.code = MEDIA_BUS_FMT_SBGGR10_1X10; 8628c2ecf20Sopenharmony_ci fmt->format.field = V4L2_FIELD_NONE; 8638c2ecf20Sopenharmony_ci } 8648c2ecf20Sopenharmony_ci mutex_unlock(&ov5695->mutex); 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_ci return 0; 8678c2ecf20Sopenharmony_ci} 8688c2ecf20Sopenharmony_ci 8698c2ecf20Sopenharmony_cistatic int ov5695_enum_mbus_code(struct v4l2_subdev *sd, 8708c2ecf20Sopenharmony_ci struct v4l2_subdev_pad_config *cfg, 8718c2ecf20Sopenharmony_ci struct v4l2_subdev_mbus_code_enum *code) 8728c2ecf20Sopenharmony_ci{ 8738c2ecf20Sopenharmony_ci if (code->index != 0) 8748c2ecf20Sopenharmony_ci return -EINVAL; 8758c2ecf20Sopenharmony_ci code->code = MEDIA_BUS_FMT_SBGGR10_1X10; 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci return 0; 8788c2ecf20Sopenharmony_ci} 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_cistatic int ov5695_enum_frame_sizes(struct v4l2_subdev *sd, 8818c2ecf20Sopenharmony_ci struct v4l2_subdev_pad_config *cfg, 8828c2ecf20Sopenharmony_ci struct v4l2_subdev_frame_size_enum *fse) 8838c2ecf20Sopenharmony_ci{ 8848c2ecf20Sopenharmony_ci if (fse->index >= ARRAY_SIZE(supported_modes)) 8858c2ecf20Sopenharmony_ci return -EINVAL; 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_ci if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10) 8888c2ecf20Sopenharmony_ci return -EINVAL; 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_ci fse->min_width = supported_modes[fse->index].width; 8918c2ecf20Sopenharmony_ci fse->max_width = supported_modes[fse->index].width; 8928c2ecf20Sopenharmony_ci fse->max_height = supported_modes[fse->index].height; 8938c2ecf20Sopenharmony_ci fse->min_height = supported_modes[fse->index].height; 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci return 0; 8968c2ecf20Sopenharmony_ci} 8978c2ecf20Sopenharmony_ci 8988c2ecf20Sopenharmony_cistatic int ov5695_enable_test_pattern(struct ov5695 *ov5695, u32 pattern) 8998c2ecf20Sopenharmony_ci{ 9008c2ecf20Sopenharmony_ci u32 val; 9018c2ecf20Sopenharmony_ci 9028c2ecf20Sopenharmony_ci if (pattern) 9038c2ecf20Sopenharmony_ci val = (pattern - 1) | OV5695_TEST_PATTERN_ENABLE; 9048c2ecf20Sopenharmony_ci else 9058c2ecf20Sopenharmony_ci val = OV5695_TEST_PATTERN_DISABLE; 9068c2ecf20Sopenharmony_ci 9078c2ecf20Sopenharmony_ci return ov5695_write_reg(ov5695->client, OV5695_REG_TEST_PATTERN, 9088c2ecf20Sopenharmony_ci OV5695_REG_VALUE_08BIT, val); 9098c2ecf20Sopenharmony_ci} 9108c2ecf20Sopenharmony_ci 9118c2ecf20Sopenharmony_cistatic int __ov5695_start_stream(struct ov5695 *ov5695) 9128c2ecf20Sopenharmony_ci{ 9138c2ecf20Sopenharmony_ci int ret; 9148c2ecf20Sopenharmony_ci 9158c2ecf20Sopenharmony_ci ret = ov5695_write_array(ov5695->client, ov5695_global_regs); 9168c2ecf20Sopenharmony_ci if (ret) 9178c2ecf20Sopenharmony_ci return ret; 9188c2ecf20Sopenharmony_ci ret = ov5695_write_array(ov5695->client, ov5695->cur_mode->reg_list); 9198c2ecf20Sopenharmony_ci if (ret) 9208c2ecf20Sopenharmony_ci return ret; 9218c2ecf20Sopenharmony_ci 9228c2ecf20Sopenharmony_ci /* In case these controls are set before streaming */ 9238c2ecf20Sopenharmony_ci ret = __v4l2_ctrl_handler_setup(&ov5695->ctrl_handler); 9248c2ecf20Sopenharmony_ci if (ret) 9258c2ecf20Sopenharmony_ci return ret; 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_ci return ov5695_write_reg(ov5695->client, OV5695_REG_CTRL_MODE, 9288c2ecf20Sopenharmony_ci OV5695_REG_VALUE_08BIT, OV5695_MODE_STREAMING); 9298c2ecf20Sopenharmony_ci} 9308c2ecf20Sopenharmony_ci 9318c2ecf20Sopenharmony_cistatic int __ov5695_stop_stream(struct ov5695 *ov5695) 9328c2ecf20Sopenharmony_ci{ 9338c2ecf20Sopenharmony_ci return ov5695_write_reg(ov5695->client, OV5695_REG_CTRL_MODE, 9348c2ecf20Sopenharmony_ci OV5695_REG_VALUE_08BIT, OV5695_MODE_SW_STANDBY); 9358c2ecf20Sopenharmony_ci} 9368c2ecf20Sopenharmony_ci 9378c2ecf20Sopenharmony_cistatic int ov5695_s_stream(struct v4l2_subdev *sd, int on) 9388c2ecf20Sopenharmony_ci{ 9398c2ecf20Sopenharmony_ci struct ov5695 *ov5695 = to_ov5695(sd); 9408c2ecf20Sopenharmony_ci struct i2c_client *client = ov5695->client; 9418c2ecf20Sopenharmony_ci int ret = 0; 9428c2ecf20Sopenharmony_ci 9438c2ecf20Sopenharmony_ci mutex_lock(&ov5695->mutex); 9448c2ecf20Sopenharmony_ci on = !!on; 9458c2ecf20Sopenharmony_ci if (on == ov5695->streaming) 9468c2ecf20Sopenharmony_ci goto unlock_and_return; 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_ci if (on) { 9498c2ecf20Sopenharmony_ci ret = pm_runtime_get_sync(&client->dev); 9508c2ecf20Sopenharmony_ci if (ret < 0) { 9518c2ecf20Sopenharmony_ci pm_runtime_put_noidle(&client->dev); 9528c2ecf20Sopenharmony_ci goto unlock_and_return; 9538c2ecf20Sopenharmony_ci } 9548c2ecf20Sopenharmony_ci 9558c2ecf20Sopenharmony_ci ret = __ov5695_start_stream(ov5695); 9568c2ecf20Sopenharmony_ci if (ret) { 9578c2ecf20Sopenharmony_ci v4l2_err(sd, "start stream failed while write regs\n"); 9588c2ecf20Sopenharmony_ci pm_runtime_put(&client->dev); 9598c2ecf20Sopenharmony_ci goto unlock_and_return; 9608c2ecf20Sopenharmony_ci } 9618c2ecf20Sopenharmony_ci } else { 9628c2ecf20Sopenharmony_ci __ov5695_stop_stream(ov5695); 9638c2ecf20Sopenharmony_ci pm_runtime_put(&client->dev); 9648c2ecf20Sopenharmony_ci } 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_ci ov5695->streaming = on; 9678c2ecf20Sopenharmony_ci 9688c2ecf20Sopenharmony_ciunlock_and_return: 9698c2ecf20Sopenharmony_ci mutex_unlock(&ov5695->mutex); 9708c2ecf20Sopenharmony_ci 9718c2ecf20Sopenharmony_ci return ret; 9728c2ecf20Sopenharmony_ci} 9738c2ecf20Sopenharmony_ci 9748c2ecf20Sopenharmony_cistatic int __ov5695_power_on(struct ov5695 *ov5695) 9758c2ecf20Sopenharmony_ci{ 9768c2ecf20Sopenharmony_ci int i, ret; 9778c2ecf20Sopenharmony_ci struct device *dev = &ov5695->client->dev; 9788c2ecf20Sopenharmony_ci 9798c2ecf20Sopenharmony_ci ret = clk_prepare_enable(ov5695->xvclk); 9808c2ecf20Sopenharmony_ci if (ret < 0) { 9818c2ecf20Sopenharmony_ci dev_err(dev, "Failed to enable xvclk\n"); 9828c2ecf20Sopenharmony_ci return ret; 9838c2ecf20Sopenharmony_ci } 9848c2ecf20Sopenharmony_ci 9858c2ecf20Sopenharmony_ci gpiod_set_value_cansleep(ov5695->reset_gpio, 1); 9868c2ecf20Sopenharmony_ci 9878c2ecf20Sopenharmony_ci /* 9888c2ecf20Sopenharmony_ci * The hardware requires the regulators to be powered on in order, 9898c2ecf20Sopenharmony_ci * so enable them one by one. 9908c2ecf20Sopenharmony_ci */ 9918c2ecf20Sopenharmony_ci for (i = 0; i < OV5695_NUM_SUPPLIES; i++) { 9928c2ecf20Sopenharmony_ci ret = regulator_enable(ov5695->supplies[i].consumer); 9938c2ecf20Sopenharmony_ci if (ret) { 9948c2ecf20Sopenharmony_ci dev_err(dev, "Failed to enable %s: %d\n", 9958c2ecf20Sopenharmony_ci ov5695->supplies[i].supply, ret); 9968c2ecf20Sopenharmony_ci goto disable_reg_clk; 9978c2ecf20Sopenharmony_ci } 9988c2ecf20Sopenharmony_ci } 9998c2ecf20Sopenharmony_ci 10008c2ecf20Sopenharmony_ci gpiod_set_value_cansleep(ov5695->reset_gpio, 0); 10018c2ecf20Sopenharmony_ci 10028c2ecf20Sopenharmony_ci usleep_range(1000, 1200); 10038c2ecf20Sopenharmony_ci 10048c2ecf20Sopenharmony_ci return 0; 10058c2ecf20Sopenharmony_ci 10068c2ecf20Sopenharmony_cidisable_reg_clk: 10078c2ecf20Sopenharmony_ci for (--i; i >= 0; i--) 10088c2ecf20Sopenharmony_ci regulator_disable(ov5695->supplies[i].consumer); 10098c2ecf20Sopenharmony_ci clk_disable_unprepare(ov5695->xvclk); 10108c2ecf20Sopenharmony_ci 10118c2ecf20Sopenharmony_ci return ret; 10128c2ecf20Sopenharmony_ci} 10138c2ecf20Sopenharmony_ci 10148c2ecf20Sopenharmony_cistatic void __ov5695_power_off(struct ov5695 *ov5695) 10158c2ecf20Sopenharmony_ci{ 10168c2ecf20Sopenharmony_ci struct device *dev = &ov5695->client->dev; 10178c2ecf20Sopenharmony_ci int i, ret; 10188c2ecf20Sopenharmony_ci 10198c2ecf20Sopenharmony_ci clk_disable_unprepare(ov5695->xvclk); 10208c2ecf20Sopenharmony_ci gpiod_set_value_cansleep(ov5695->reset_gpio, 1); 10218c2ecf20Sopenharmony_ci 10228c2ecf20Sopenharmony_ci /* 10238c2ecf20Sopenharmony_ci * The hardware requires the regulators to be powered off in order, 10248c2ecf20Sopenharmony_ci * so disable them one by one. 10258c2ecf20Sopenharmony_ci */ 10268c2ecf20Sopenharmony_ci for (i = OV5695_NUM_SUPPLIES - 1; i >= 0; i--) { 10278c2ecf20Sopenharmony_ci ret = regulator_disable(ov5695->supplies[i].consumer); 10288c2ecf20Sopenharmony_ci if (ret) 10298c2ecf20Sopenharmony_ci dev_err(dev, "Failed to disable %s: %d\n", 10308c2ecf20Sopenharmony_ci ov5695->supplies[i].supply, ret); 10318c2ecf20Sopenharmony_ci } 10328c2ecf20Sopenharmony_ci} 10338c2ecf20Sopenharmony_ci 10348c2ecf20Sopenharmony_cistatic int __maybe_unused ov5695_runtime_resume(struct device *dev) 10358c2ecf20Sopenharmony_ci{ 10368c2ecf20Sopenharmony_ci struct i2c_client *client = to_i2c_client(dev); 10378c2ecf20Sopenharmony_ci struct v4l2_subdev *sd = i2c_get_clientdata(client); 10388c2ecf20Sopenharmony_ci struct ov5695 *ov5695 = to_ov5695(sd); 10398c2ecf20Sopenharmony_ci 10408c2ecf20Sopenharmony_ci return __ov5695_power_on(ov5695); 10418c2ecf20Sopenharmony_ci} 10428c2ecf20Sopenharmony_ci 10438c2ecf20Sopenharmony_cistatic int __maybe_unused ov5695_runtime_suspend(struct device *dev) 10448c2ecf20Sopenharmony_ci{ 10458c2ecf20Sopenharmony_ci struct i2c_client *client = to_i2c_client(dev); 10468c2ecf20Sopenharmony_ci struct v4l2_subdev *sd = i2c_get_clientdata(client); 10478c2ecf20Sopenharmony_ci struct ov5695 *ov5695 = to_ov5695(sd); 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci __ov5695_power_off(ov5695); 10508c2ecf20Sopenharmony_ci 10518c2ecf20Sopenharmony_ci return 0; 10528c2ecf20Sopenharmony_ci} 10538c2ecf20Sopenharmony_ci 10548c2ecf20Sopenharmony_ci#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API 10558c2ecf20Sopenharmony_cistatic int ov5695_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) 10568c2ecf20Sopenharmony_ci{ 10578c2ecf20Sopenharmony_ci struct ov5695 *ov5695 = to_ov5695(sd); 10588c2ecf20Sopenharmony_ci struct v4l2_mbus_framefmt *try_fmt = 10598c2ecf20Sopenharmony_ci v4l2_subdev_get_try_format(sd, fh->pad, 0); 10608c2ecf20Sopenharmony_ci const struct ov5695_mode *def_mode = &supported_modes[0]; 10618c2ecf20Sopenharmony_ci 10628c2ecf20Sopenharmony_ci mutex_lock(&ov5695->mutex); 10638c2ecf20Sopenharmony_ci /* Initialize try_fmt */ 10648c2ecf20Sopenharmony_ci try_fmt->width = def_mode->width; 10658c2ecf20Sopenharmony_ci try_fmt->height = def_mode->height; 10668c2ecf20Sopenharmony_ci try_fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10; 10678c2ecf20Sopenharmony_ci try_fmt->field = V4L2_FIELD_NONE; 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ci mutex_unlock(&ov5695->mutex); 10708c2ecf20Sopenharmony_ci /* No crop or compose */ 10718c2ecf20Sopenharmony_ci 10728c2ecf20Sopenharmony_ci return 0; 10738c2ecf20Sopenharmony_ci} 10748c2ecf20Sopenharmony_ci#endif 10758c2ecf20Sopenharmony_ci 10768c2ecf20Sopenharmony_cistatic const struct dev_pm_ops ov5695_pm_ops = { 10778c2ecf20Sopenharmony_ci SET_RUNTIME_PM_OPS(ov5695_runtime_suspend, 10788c2ecf20Sopenharmony_ci ov5695_runtime_resume, NULL) 10798c2ecf20Sopenharmony_ci}; 10808c2ecf20Sopenharmony_ci 10818c2ecf20Sopenharmony_ci#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API 10828c2ecf20Sopenharmony_cistatic const struct v4l2_subdev_internal_ops ov5695_internal_ops = { 10838c2ecf20Sopenharmony_ci .open = ov5695_open, 10848c2ecf20Sopenharmony_ci}; 10858c2ecf20Sopenharmony_ci#endif 10868c2ecf20Sopenharmony_ci 10878c2ecf20Sopenharmony_cistatic const struct v4l2_subdev_video_ops ov5695_video_ops = { 10888c2ecf20Sopenharmony_ci .s_stream = ov5695_s_stream, 10898c2ecf20Sopenharmony_ci}; 10908c2ecf20Sopenharmony_ci 10918c2ecf20Sopenharmony_cistatic const struct v4l2_subdev_pad_ops ov5695_pad_ops = { 10928c2ecf20Sopenharmony_ci .enum_mbus_code = ov5695_enum_mbus_code, 10938c2ecf20Sopenharmony_ci .enum_frame_size = ov5695_enum_frame_sizes, 10948c2ecf20Sopenharmony_ci .get_fmt = ov5695_get_fmt, 10958c2ecf20Sopenharmony_ci .set_fmt = ov5695_set_fmt, 10968c2ecf20Sopenharmony_ci}; 10978c2ecf20Sopenharmony_ci 10988c2ecf20Sopenharmony_cistatic const struct v4l2_subdev_ops ov5695_subdev_ops = { 10998c2ecf20Sopenharmony_ci .video = &ov5695_video_ops, 11008c2ecf20Sopenharmony_ci .pad = &ov5695_pad_ops, 11018c2ecf20Sopenharmony_ci}; 11028c2ecf20Sopenharmony_ci 11038c2ecf20Sopenharmony_cistatic int ov5695_set_ctrl(struct v4l2_ctrl *ctrl) 11048c2ecf20Sopenharmony_ci{ 11058c2ecf20Sopenharmony_ci struct ov5695 *ov5695 = container_of(ctrl->handler, 11068c2ecf20Sopenharmony_ci struct ov5695, ctrl_handler); 11078c2ecf20Sopenharmony_ci struct i2c_client *client = ov5695->client; 11088c2ecf20Sopenharmony_ci s64 max; 11098c2ecf20Sopenharmony_ci int ret = 0; 11108c2ecf20Sopenharmony_ci 11118c2ecf20Sopenharmony_ci /* Propagate change of current control to all related controls */ 11128c2ecf20Sopenharmony_ci switch (ctrl->id) { 11138c2ecf20Sopenharmony_ci case V4L2_CID_VBLANK: 11148c2ecf20Sopenharmony_ci /* Update max exposure while meeting expected vblanking */ 11158c2ecf20Sopenharmony_ci max = ov5695->cur_mode->height + ctrl->val - 4; 11168c2ecf20Sopenharmony_ci __v4l2_ctrl_modify_range(ov5695->exposure, 11178c2ecf20Sopenharmony_ci ov5695->exposure->minimum, max, 11188c2ecf20Sopenharmony_ci ov5695->exposure->step, 11198c2ecf20Sopenharmony_ci ov5695->exposure->default_value); 11208c2ecf20Sopenharmony_ci break; 11218c2ecf20Sopenharmony_ci } 11228c2ecf20Sopenharmony_ci 11238c2ecf20Sopenharmony_ci if (!pm_runtime_get_if_in_use(&client->dev)) 11248c2ecf20Sopenharmony_ci return 0; 11258c2ecf20Sopenharmony_ci 11268c2ecf20Sopenharmony_ci switch (ctrl->id) { 11278c2ecf20Sopenharmony_ci case V4L2_CID_EXPOSURE: 11288c2ecf20Sopenharmony_ci /* 4 least significant bits of expsoure are fractional part */ 11298c2ecf20Sopenharmony_ci ret = ov5695_write_reg(ov5695->client, OV5695_REG_EXPOSURE, 11308c2ecf20Sopenharmony_ci OV5695_REG_VALUE_24BIT, ctrl->val << 4); 11318c2ecf20Sopenharmony_ci break; 11328c2ecf20Sopenharmony_ci case V4L2_CID_ANALOGUE_GAIN: 11338c2ecf20Sopenharmony_ci ret = ov5695_write_reg(ov5695->client, OV5695_REG_ANALOG_GAIN, 11348c2ecf20Sopenharmony_ci OV5695_REG_VALUE_08BIT, ctrl->val); 11358c2ecf20Sopenharmony_ci break; 11368c2ecf20Sopenharmony_ci case V4L2_CID_DIGITAL_GAIN: 11378c2ecf20Sopenharmony_ci ret = ov5695_write_reg(ov5695->client, OV5695_REG_DIGI_GAIN_L, 11388c2ecf20Sopenharmony_ci OV5695_REG_VALUE_08BIT, 11398c2ecf20Sopenharmony_ci ctrl->val & OV5695_DIGI_GAIN_L_MASK); 11408c2ecf20Sopenharmony_ci ret = ov5695_write_reg(ov5695->client, OV5695_REG_DIGI_GAIN_H, 11418c2ecf20Sopenharmony_ci OV5695_REG_VALUE_08BIT, 11428c2ecf20Sopenharmony_ci ctrl->val >> OV5695_DIGI_GAIN_H_SHIFT); 11438c2ecf20Sopenharmony_ci break; 11448c2ecf20Sopenharmony_ci case V4L2_CID_VBLANK: 11458c2ecf20Sopenharmony_ci ret = ov5695_write_reg(ov5695->client, OV5695_REG_VTS, 11468c2ecf20Sopenharmony_ci OV5695_REG_VALUE_16BIT, 11478c2ecf20Sopenharmony_ci ctrl->val + ov5695->cur_mode->height); 11488c2ecf20Sopenharmony_ci break; 11498c2ecf20Sopenharmony_ci case V4L2_CID_TEST_PATTERN: 11508c2ecf20Sopenharmony_ci ret = ov5695_enable_test_pattern(ov5695, ctrl->val); 11518c2ecf20Sopenharmony_ci break; 11528c2ecf20Sopenharmony_ci default: 11538c2ecf20Sopenharmony_ci dev_warn(&client->dev, "%s Unhandled id:0x%x, val:0x%x\n", 11548c2ecf20Sopenharmony_ci __func__, ctrl->id, ctrl->val); 11558c2ecf20Sopenharmony_ci break; 11568c2ecf20Sopenharmony_ci } 11578c2ecf20Sopenharmony_ci 11588c2ecf20Sopenharmony_ci pm_runtime_put(&client->dev); 11598c2ecf20Sopenharmony_ci 11608c2ecf20Sopenharmony_ci return ret; 11618c2ecf20Sopenharmony_ci} 11628c2ecf20Sopenharmony_ci 11638c2ecf20Sopenharmony_cistatic const struct v4l2_ctrl_ops ov5695_ctrl_ops = { 11648c2ecf20Sopenharmony_ci .s_ctrl = ov5695_set_ctrl, 11658c2ecf20Sopenharmony_ci}; 11668c2ecf20Sopenharmony_ci 11678c2ecf20Sopenharmony_cistatic int ov5695_initialize_controls(struct ov5695 *ov5695) 11688c2ecf20Sopenharmony_ci{ 11698c2ecf20Sopenharmony_ci const struct ov5695_mode *mode; 11708c2ecf20Sopenharmony_ci struct v4l2_ctrl_handler *handler; 11718c2ecf20Sopenharmony_ci struct v4l2_ctrl *ctrl; 11728c2ecf20Sopenharmony_ci s64 exposure_max, vblank_def; 11738c2ecf20Sopenharmony_ci u32 h_blank; 11748c2ecf20Sopenharmony_ci int ret; 11758c2ecf20Sopenharmony_ci 11768c2ecf20Sopenharmony_ci handler = &ov5695->ctrl_handler; 11778c2ecf20Sopenharmony_ci mode = ov5695->cur_mode; 11788c2ecf20Sopenharmony_ci ret = v4l2_ctrl_handler_init(handler, 8); 11798c2ecf20Sopenharmony_ci if (ret) 11808c2ecf20Sopenharmony_ci return ret; 11818c2ecf20Sopenharmony_ci handler->lock = &ov5695->mutex; 11828c2ecf20Sopenharmony_ci 11838c2ecf20Sopenharmony_ci ctrl = v4l2_ctrl_new_int_menu(handler, NULL, V4L2_CID_LINK_FREQ, 11848c2ecf20Sopenharmony_ci 0, 0, link_freq_menu_items); 11858c2ecf20Sopenharmony_ci if (ctrl) 11868c2ecf20Sopenharmony_ci ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; 11878c2ecf20Sopenharmony_ci 11888c2ecf20Sopenharmony_ci v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE, 11898c2ecf20Sopenharmony_ci 0, OV5695_PIXEL_RATE, 1, OV5695_PIXEL_RATE); 11908c2ecf20Sopenharmony_ci 11918c2ecf20Sopenharmony_ci h_blank = mode->hts_def - mode->width; 11928c2ecf20Sopenharmony_ci ov5695->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, 11938c2ecf20Sopenharmony_ci h_blank, h_blank, 1, h_blank); 11948c2ecf20Sopenharmony_ci if (ov5695->hblank) 11958c2ecf20Sopenharmony_ci ov5695->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; 11968c2ecf20Sopenharmony_ci 11978c2ecf20Sopenharmony_ci vblank_def = mode->vts_def - mode->height; 11988c2ecf20Sopenharmony_ci ov5695->vblank = v4l2_ctrl_new_std(handler, &ov5695_ctrl_ops, 11998c2ecf20Sopenharmony_ci V4L2_CID_VBLANK, vblank_def, 12008c2ecf20Sopenharmony_ci OV5695_VTS_MAX - mode->height, 12018c2ecf20Sopenharmony_ci 1, vblank_def); 12028c2ecf20Sopenharmony_ci 12038c2ecf20Sopenharmony_ci exposure_max = mode->vts_def - 4; 12048c2ecf20Sopenharmony_ci ov5695->exposure = v4l2_ctrl_new_std(handler, &ov5695_ctrl_ops, 12058c2ecf20Sopenharmony_ci V4L2_CID_EXPOSURE, OV5695_EXPOSURE_MIN, 12068c2ecf20Sopenharmony_ci exposure_max, OV5695_EXPOSURE_STEP, 12078c2ecf20Sopenharmony_ci mode->exp_def); 12088c2ecf20Sopenharmony_ci 12098c2ecf20Sopenharmony_ci ov5695->anal_gain = v4l2_ctrl_new_std(handler, &ov5695_ctrl_ops, 12108c2ecf20Sopenharmony_ci V4L2_CID_ANALOGUE_GAIN, ANALOG_GAIN_MIN, 12118c2ecf20Sopenharmony_ci ANALOG_GAIN_MAX, ANALOG_GAIN_STEP, 12128c2ecf20Sopenharmony_ci ANALOG_GAIN_DEFAULT); 12138c2ecf20Sopenharmony_ci 12148c2ecf20Sopenharmony_ci /* Digital gain */ 12158c2ecf20Sopenharmony_ci ov5695->digi_gain = v4l2_ctrl_new_std(handler, &ov5695_ctrl_ops, 12168c2ecf20Sopenharmony_ci V4L2_CID_DIGITAL_GAIN, OV5695_DIGI_GAIN_MIN, 12178c2ecf20Sopenharmony_ci OV5695_DIGI_GAIN_MAX, OV5695_DIGI_GAIN_STEP, 12188c2ecf20Sopenharmony_ci OV5695_DIGI_GAIN_DEFAULT); 12198c2ecf20Sopenharmony_ci 12208c2ecf20Sopenharmony_ci ov5695->test_pattern = v4l2_ctrl_new_std_menu_items(handler, 12218c2ecf20Sopenharmony_ci &ov5695_ctrl_ops, V4L2_CID_TEST_PATTERN, 12228c2ecf20Sopenharmony_ci ARRAY_SIZE(ov5695_test_pattern_menu) - 1, 12238c2ecf20Sopenharmony_ci 0, 0, ov5695_test_pattern_menu); 12248c2ecf20Sopenharmony_ci 12258c2ecf20Sopenharmony_ci if (handler->error) { 12268c2ecf20Sopenharmony_ci ret = handler->error; 12278c2ecf20Sopenharmony_ci dev_err(&ov5695->client->dev, 12288c2ecf20Sopenharmony_ci "Failed to init controls(%d)\n", ret); 12298c2ecf20Sopenharmony_ci goto err_free_handler; 12308c2ecf20Sopenharmony_ci } 12318c2ecf20Sopenharmony_ci 12328c2ecf20Sopenharmony_ci ov5695->subdev.ctrl_handler = handler; 12338c2ecf20Sopenharmony_ci 12348c2ecf20Sopenharmony_ci return 0; 12358c2ecf20Sopenharmony_ci 12368c2ecf20Sopenharmony_cierr_free_handler: 12378c2ecf20Sopenharmony_ci v4l2_ctrl_handler_free(handler); 12388c2ecf20Sopenharmony_ci 12398c2ecf20Sopenharmony_ci return ret; 12408c2ecf20Sopenharmony_ci} 12418c2ecf20Sopenharmony_ci 12428c2ecf20Sopenharmony_cistatic int ov5695_check_sensor_id(struct ov5695 *ov5695, 12438c2ecf20Sopenharmony_ci struct i2c_client *client) 12448c2ecf20Sopenharmony_ci{ 12458c2ecf20Sopenharmony_ci struct device *dev = &ov5695->client->dev; 12468c2ecf20Sopenharmony_ci u32 id = 0; 12478c2ecf20Sopenharmony_ci int ret; 12488c2ecf20Sopenharmony_ci 12498c2ecf20Sopenharmony_ci ret = ov5695_read_reg(client, OV5695_REG_CHIP_ID, 12508c2ecf20Sopenharmony_ci OV5695_REG_VALUE_24BIT, &id); 12518c2ecf20Sopenharmony_ci if (id != CHIP_ID) { 12528c2ecf20Sopenharmony_ci dev_err(dev, "Unexpected sensor id(%06x), ret(%d)\n", id, ret); 12538c2ecf20Sopenharmony_ci return ret; 12548c2ecf20Sopenharmony_ci } 12558c2ecf20Sopenharmony_ci 12568c2ecf20Sopenharmony_ci dev_info(dev, "Detected OV%06x sensor\n", CHIP_ID); 12578c2ecf20Sopenharmony_ci 12588c2ecf20Sopenharmony_ci return 0; 12598c2ecf20Sopenharmony_ci} 12608c2ecf20Sopenharmony_ci 12618c2ecf20Sopenharmony_cistatic int ov5695_configure_regulators(struct ov5695 *ov5695) 12628c2ecf20Sopenharmony_ci{ 12638c2ecf20Sopenharmony_ci int i; 12648c2ecf20Sopenharmony_ci 12658c2ecf20Sopenharmony_ci for (i = 0; i < OV5695_NUM_SUPPLIES; i++) 12668c2ecf20Sopenharmony_ci ov5695->supplies[i].supply = ov5695_supply_names[i]; 12678c2ecf20Sopenharmony_ci 12688c2ecf20Sopenharmony_ci return devm_regulator_bulk_get(&ov5695->client->dev, 12698c2ecf20Sopenharmony_ci OV5695_NUM_SUPPLIES, 12708c2ecf20Sopenharmony_ci ov5695->supplies); 12718c2ecf20Sopenharmony_ci} 12728c2ecf20Sopenharmony_ci 12738c2ecf20Sopenharmony_cistatic int ov5695_probe(struct i2c_client *client, 12748c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 12758c2ecf20Sopenharmony_ci{ 12768c2ecf20Sopenharmony_ci struct device *dev = &client->dev; 12778c2ecf20Sopenharmony_ci struct ov5695 *ov5695; 12788c2ecf20Sopenharmony_ci struct v4l2_subdev *sd; 12798c2ecf20Sopenharmony_ci int ret; 12808c2ecf20Sopenharmony_ci 12818c2ecf20Sopenharmony_ci ov5695 = devm_kzalloc(dev, sizeof(*ov5695), GFP_KERNEL); 12828c2ecf20Sopenharmony_ci if (!ov5695) 12838c2ecf20Sopenharmony_ci return -ENOMEM; 12848c2ecf20Sopenharmony_ci 12858c2ecf20Sopenharmony_ci ov5695->client = client; 12868c2ecf20Sopenharmony_ci ov5695->cur_mode = &supported_modes[0]; 12878c2ecf20Sopenharmony_ci 12888c2ecf20Sopenharmony_ci ov5695->xvclk = devm_clk_get(dev, "xvclk"); 12898c2ecf20Sopenharmony_ci if (IS_ERR(ov5695->xvclk)) { 12908c2ecf20Sopenharmony_ci dev_err(dev, "Failed to get xvclk\n"); 12918c2ecf20Sopenharmony_ci return -EINVAL; 12928c2ecf20Sopenharmony_ci } 12938c2ecf20Sopenharmony_ci ret = clk_set_rate(ov5695->xvclk, OV5695_XVCLK_FREQ); 12948c2ecf20Sopenharmony_ci if (ret < 0) { 12958c2ecf20Sopenharmony_ci dev_err(dev, "Failed to set xvclk rate (24MHz)\n"); 12968c2ecf20Sopenharmony_ci return ret; 12978c2ecf20Sopenharmony_ci } 12988c2ecf20Sopenharmony_ci if (clk_get_rate(ov5695->xvclk) != OV5695_XVCLK_FREQ) 12998c2ecf20Sopenharmony_ci dev_warn(dev, "xvclk mismatched, modes are based on 24MHz\n"); 13008c2ecf20Sopenharmony_ci 13018c2ecf20Sopenharmony_ci ov5695->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); 13028c2ecf20Sopenharmony_ci if (IS_ERR(ov5695->reset_gpio)) { 13038c2ecf20Sopenharmony_ci dev_err(dev, "Failed to get reset-gpios\n"); 13048c2ecf20Sopenharmony_ci return -EINVAL; 13058c2ecf20Sopenharmony_ci } 13068c2ecf20Sopenharmony_ci 13078c2ecf20Sopenharmony_ci ret = ov5695_configure_regulators(ov5695); 13088c2ecf20Sopenharmony_ci if (ret) { 13098c2ecf20Sopenharmony_ci dev_err(dev, "Failed to get power regulators\n"); 13108c2ecf20Sopenharmony_ci return ret; 13118c2ecf20Sopenharmony_ci } 13128c2ecf20Sopenharmony_ci 13138c2ecf20Sopenharmony_ci mutex_init(&ov5695->mutex); 13148c2ecf20Sopenharmony_ci 13158c2ecf20Sopenharmony_ci sd = &ov5695->subdev; 13168c2ecf20Sopenharmony_ci v4l2_i2c_subdev_init(sd, client, &ov5695_subdev_ops); 13178c2ecf20Sopenharmony_ci ret = ov5695_initialize_controls(ov5695); 13188c2ecf20Sopenharmony_ci if (ret) 13198c2ecf20Sopenharmony_ci goto err_destroy_mutex; 13208c2ecf20Sopenharmony_ci 13218c2ecf20Sopenharmony_ci ret = __ov5695_power_on(ov5695); 13228c2ecf20Sopenharmony_ci if (ret) 13238c2ecf20Sopenharmony_ci goto err_free_handler; 13248c2ecf20Sopenharmony_ci 13258c2ecf20Sopenharmony_ci ret = ov5695_check_sensor_id(ov5695, client); 13268c2ecf20Sopenharmony_ci if (ret) 13278c2ecf20Sopenharmony_ci goto err_power_off; 13288c2ecf20Sopenharmony_ci 13298c2ecf20Sopenharmony_ci#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API 13308c2ecf20Sopenharmony_ci sd->internal_ops = &ov5695_internal_ops; 13318c2ecf20Sopenharmony_ci sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; 13328c2ecf20Sopenharmony_ci#endif 13338c2ecf20Sopenharmony_ci#if defined(CONFIG_MEDIA_CONTROLLER) 13348c2ecf20Sopenharmony_ci ov5695->pad.flags = MEDIA_PAD_FL_SOURCE; 13358c2ecf20Sopenharmony_ci sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; 13368c2ecf20Sopenharmony_ci ret = media_entity_pads_init(&sd->entity, 1, &ov5695->pad); 13378c2ecf20Sopenharmony_ci if (ret < 0) 13388c2ecf20Sopenharmony_ci goto err_power_off; 13398c2ecf20Sopenharmony_ci#endif 13408c2ecf20Sopenharmony_ci 13418c2ecf20Sopenharmony_ci ret = v4l2_async_register_subdev_sensor_common(sd); 13428c2ecf20Sopenharmony_ci if (ret) { 13438c2ecf20Sopenharmony_ci dev_err(dev, "v4l2 async register subdev failed\n"); 13448c2ecf20Sopenharmony_ci goto err_clean_entity; 13458c2ecf20Sopenharmony_ci } 13468c2ecf20Sopenharmony_ci 13478c2ecf20Sopenharmony_ci pm_runtime_set_active(dev); 13488c2ecf20Sopenharmony_ci pm_runtime_enable(dev); 13498c2ecf20Sopenharmony_ci pm_runtime_idle(dev); 13508c2ecf20Sopenharmony_ci 13518c2ecf20Sopenharmony_ci return 0; 13528c2ecf20Sopenharmony_ci 13538c2ecf20Sopenharmony_cierr_clean_entity: 13548c2ecf20Sopenharmony_ci#if defined(CONFIG_MEDIA_CONTROLLER) 13558c2ecf20Sopenharmony_ci media_entity_cleanup(&sd->entity); 13568c2ecf20Sopenharmony_ci#endif 13578c2ecf20Sopenharmony_cierr_power_off: 13588c2ecf20Sopenharmony_ci __ov5695_power_off(ov5695); 13598c2ecf20Sopenharmony_cierr_free_handler: 13608c2ecf20Sopenharmony_ci v4l2_ctrl_handler_free(&ov5695->ctrl_handler); 13618c2ecf20Sopenharmony_cierr_destroy_mutex: 13628c2ecf20Sopenharmony_ci mutex_destroy(&ov5695->mutex); 13638c2ecf20Sopenharmony_ci 13648c2ecf20Sopenharmony_ci return ret; 13658c2ecf20Sopenharmony_ci} 13668c2ecf20Sopenharmony_ci 13678c2ecf20Sopenharmony_cistatic int ov5695_remove(struct i2c_client *client) 13688c2ecf20Sopenharmony_ci{ 13698c2ecf20Sopenharmony_ci struct v4l2_subdev *sd = i2c_get_clientdata(client); 13708c2ecf20Sopenharmony_ci struct ov5695 *ov5695 = to_ov5695(sd); 13718c2ecf20Sopenharmony_ci 13728c2ecf20Sopenharmony_ci v4l2_async_unregister_subdev(sd); 13738c2ecf20Sopenharmony_ci#if defined(CONFIG_MEDIA_CONTROLLER) 13748c2ecf20Sopenharmony_ci media_entity_cleanup(&sd->entity); 13758c2ecf20Sopenharmony_ci#endif 13768c2ecf20Sopenharmony_ci v4l2_ctrl_handler_free(&ov5695->ctrl_handler); 13778c2ecf20Sopenharmony_ci mutex_destroy(&ov5695->mutex); 13788c2ecf20Sopenharmony_ci 13798c2ecf20Sopenharmony_ci pm_runtime_disable(&client->dev); 13808c2ecf20Sopenharmony_ci if (!pm_runtime_status_suspended(&client->dev)) 13818c2ecf20Sopenharmony_ci __ov5695_power_off(ov5695); 13828c2ecf20Sopenharmony_ci pm_runtime_set_suspended(&client->dev); 13838c2ecf20Sopenharmony_ci 13848c2ecf20Sopenharmony_ci return 0; 13858c2ecf20Sopenharmony_ci} 13868c2ecf20Sopenharmony_ci 13878c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_OF) 13888c2ecf20Sopenharmony_cistatic const struct of_device_id ov5695_of_match[] = { 13898c2ecf20Sopenharmony_ci { .compatible = "ovti,ov5695" }, 13908c2ecf20Sopenharmony_ci {}, 13918c2ecf20Sopenharmony_ci}; 13928c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, ov5695_of_match); 13938c2ecf20Sopenharmony_ci#endif 13948c2ecf20Sopenharmony_ci 13958c2ecf20Sopenharmony_cistatic struct i2c_driver ov5695_i2c_driver = { 13968c2ecf20Sopenharmony_ci .driver = { 13978c2ecf20Sopenharmony_ci .name = "ov5695", 13988c2ecf20Sopenharmony_ci .pm = &ov5695_pm_ops, 13998c2ecf20Sopenharmony_ci .of_match_table = of_match_ptr(ov5695_of_match), 14008c2ecf20Sopenharmony_ci }, 14018c2ecf20Sopenharmony_ci .probe = &ov5695_probe, 14028c2ecf20Sopenharmony_ci .remove = &ov5695_remove, 14038c2ecf20Sopenharmony_ci}; 14048c2ecf20Sopenharmony_ci 14058c2ecf20Sopenharmony_cimodule_i2c_driver(ov5695_i2c_driver); 14068c2ecf20Sopenharmony_ci 14078c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("OmniVision ov5695 sensor driver"); 14088c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 1409