// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2023 Intel Corporation.
*/
#include <asm/unaligned.h>
#include <linux/acpi.h>
#include <linux/bitfield.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/pm_runtime.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/v4l2-event.h>
#include <media/v4l2-fwnode.h>
#define OV01A10_LINK_FREQ_400MHZ 400000000ULL
#define OV01A10_SCLK 40000000LL
#define OV01A10_DATA_LANES 1
#define OV01A10_REG_CHIP_ID 0x300a
#define OV01A10_CHIP_ID 0x560141
#define OV01A10_REG_MODE_SELECT 0x0100
#define OV01A10_MODE_STANDBY 0x00
#define OV01A10_MODE_STREAMING 0x01
/* pixel array */
#define OV01A10_PIXEL_ARRAY_WIDTH 1296
#define OV01A10_PIXEL_ARRAY_HEIGHT 816
#define OV01A10_ACITVE_WIDTH 1280
#define OV01A10_ACITVE_HEIGHT 800
/* vertical and horizontal timings */
#define OV01A10_REG_VTS 0x380e
#define OV01A10_VTS_DEF 0x0380
#define OV01A10_VTS_MIN 0x0380
#define OV01A10_VTS_MAX 0xffff
#define OV01A10_HTS_DEF 1488
/* exposure controls */
#define OV01A10_REG_EXPOSURE 0x3501
#define OV01A10_EXPOSURE_MIN 4
#define OV01A10_EXPOSURE_MAX_MARGIN 8
#define OV01A10_EXPOSURE_STEP 1
/* analog gain controls */
#define OV01A10_REG_ANALOG_GAIN 0x3508
#define OV01A10_ANAL_GAIN_MIN 0x100
#define OV01A10_ANAL_GAIN_MAX 0xffff
#define OV01A10_ANAL_GAIN_STEP 1
/* digital gain controls */
#define OV01A10_REG_DIGITAL_GAIN_B 0x350a
#define OV01A10_REG_DIGITAL_GAIN_GB 0x3510
#define OV01A10_REG_DIGITAL_GAIN_GR 0x3513
#define OV01A10_REG_DIGITAL_GAIN_R 0x3516
#define OV01A10_DGTL_GAIN_MIN 0
#define OV01A10_DGTL_GAIN_MAX 0x3ffff
#define OV01A10_DGTL_GAIN_STEP 1
#define OV01A10_DGTL_GAIN_DEFAULT 1024
/* test pattern control */
#define OV01A10_REG_TEST_PATTERN 0x4503
#define OV01A10_TEST_PATTERN_ENABLE BIT(7)
#define OV01A10_LINK_FREQ_400MHZ_INDEX 0
/* flip and mirror control */
#define OV01A10_REG_FORMAT1 0x3820
#define OV01A10_VFLIP_MASK BIT(4)
#define OV01A10_HFLIP_MASK BIT(3)
/* window offset */
#define OV01A10_REG_X_WIN 0x3811
#define OV01A10_REG_Y_WIN 0x3813
struct ov01a10_reg {
u16 address;
u8 val;
};
struct ov01a10_reg_list {
u32 num_of_regs;
const struct ov01a10_reg *regs;
};
struct ov01a10_link_freq_config {
const struct ov01a10_reg_list reg_list;
};
struct ov01a10_mode {
u32 width;
u32 height;
u32 hts;
u32 vts_def;
u32 vts_min;
u32 link_freq_index;
const struct ov01a10_reg_list reg_list;
};
static const struct ov01a10_reg mipi_data_rate_720mbps[] = {
{0x0103, 0x01},
{0x0302, 0x00},
{0x0303, 0x06},
{0x0304, 0x01},
{0x0305, 0xe0},
{0x0306, 0x00},
{0x0308, 0x01},
{0x0309, 0x00},
{0x030c, 0x01},
{0x0322, 0x01},
{0x0323, 0x06},
{0x0324, 0x01},
{0x0325, 0x68},
};
static const struct ov01a10_reg sensor_1280x800_setting[] = {
{0x3002, 0xa1},
{0x301e, 0xf0},
{0x3022, 0x01},
{0x3501, 0x03},
{0x3502, 0x78},
{0x3504, 0x0c},
{0x3508, 0x01},
{0x3509, 0x00},
{0x3601, 0xc0},
{0x3603, 0x71},
{0x3610, 0x68},
{0x3611, 0x86},
{0x3640, 0x10},
{0x3641, 0x80},
{0x3642, 0xdc},
{0x3646, 0x55},
{0x3647, 0x57},
{0x364b, 0x00},
{0x3653, 0x10},
{0x3655, 0x00},
{0x3656, 0x00},
{0x365f, 0x0f},
{0x3661, 0x45},
{0x3662, 0x24},
{0x3663, 0x11},
{0x3664, 0x07},
{0x3709, 0x34},
{0x370b, 0x6f},
{0x3714, 0x22},
{0x371b, 0x27},
{0x371c, 0x67},
{0x371d, 0xa7},
{0x371e, 0xe7},
{0x3730, 0x81},
{0x3733, 0x10},
{0x3734, 0x40},
{0x3737, 0x04},
{0x3739, 0x1c},
{0x3767, 0x00},
{0x376c, 0x81},
{0x3772, 0x14},
{0x37c2, 0x04},
{0x37d8, 0x03},
{0x37d9, 0x0c},
{0x37e0, 0x00},
{0x37e1, 0x08},
{0x37e2, 0x10},
{0x37e3, 0x04},
{0x37e4, 0x04},
{0x37e5, 0x03},
{0x37e6, 0x04},
{0x3800, 0x00},
{0x3801, 0x00},
{0x3802, 0x00},
{0x3803, 0x00},
{0x3804, 0x05},
{0x3805, 0x0f},
{0x3806, 0x03},
{0x3807, 0x2f},
{0x3808, 0x05},
{0x3809, 0x00},
{0x380a, 0x03},
{0x380b, 0x20},
{0x380c, 0x02},
{0x380d, 0xe8},
{0x380e, 0x03},
{0x380f, 0x80},
{0x3810, 0x00},
{0x3811, 0x08},
{0x3812, 0x00},
{0x3813, 0x08},
{0x3814, 0x01},
{0x3815, 0x01},
{0x3816, 0x01},
{0x3817, 0x01},
{0x3820, 0xa0},
{0x3822, 0x13},
{0x3832, 0x28},
{0x3833, 0x10},
{0x3b00, 0x00},
{0x3c80, 0x00},
{0x3c88, 0x02},
{0x3c8c, 0x07},
{0x3c8d, 0x40},
{0x3cc7, 0x80},
{0x4000, 0xc3},
{0x4001, 0xe0},
{0x4003, 0x40},
{0x4008, 0x02},
{0x4009, 0x19},
{0x400a, 0x01},
{0x400b, 0x6c},
{0x4011, 0x00},
{0x4041, 0x00},
{0x4300, 0xff},
{0x4301, 0x00},
{0x4302, 0x0f},
{0x4503, 0x00},
{0x4601, 0x50},
{0x4800, 0x64},
{0x481f, 0x34},
{0x4825, 0x33},
{0x4837, 0x11},
{0x4881, 0x40},
{0x4883, 0x01},
{0x4890, 0x00},
{0x4901, 0x00},
{0x4902, 0x00},
{0x4b00, 0x2a},
{0x4b0d, 0x00},
{0x450a, 0x04},
{0x450b, 0x00},
{0x5000, 0x65},
{0x5200, 0x18},
{0x5004, 0x00},
{0x5080, 0x40},
{0x0305, 0xf4},
{0x0325,