summaryrefslogtreecommitdiff
path: root/drivers/media/platform/starfive/stf_isp.h
blob: 64ee98e63997cf4149782876b7c8bcf86d755638 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2021 StarFive Technology Co., Ltd.
 */
#ifndef STF_ISP_H
#define STF_ISP_H

#include <media/v4l2-subdev.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/media-entity.h>
#include <video/stf-vin.h>

#define STF_ISP_PAD_SINK     0
#define STF_ISP_PAD_SRC      1
#define STF_ISP_PADS_NUM     2

#define STF_ISP0_SETFILE     "stf_isp0_fw.bin"
#define STF_ISP1_SETFILE     "stf_isp1_fw.bin"
#define FILENAME_MAX_LEN     30

#define SCALER_RATIO_MAX     1  // no compose function
#define STF_ISP_REG_OFFSET_MAX  0x0FFF
#define STF_ISP_REG_DELAY_MAX   100

#define ISP_REG_CSIINTS_ADDR    0x00000008
#define ISP_REG_DUMP_CFG_0      0x00000024
#define ISP_REG_DUMP_CFG_1      0x00000028
#define ISP_REG_IESHD_ADDR      0x00000A50

struct stfisp_fw_info {
	char __user filename[FILENAME_MAX_LEN];
};

#define VIDIOC_STFISP_LOAD_FW \
        _IOW('V', BASE_VIDIOC_PRIVATE + 1, struct stfisp_fw_info)

struct isp_format {
	u32 code;
	u8 bpp;
};

typedef struct {
	u32 addr;
	u32 val;
	u32 mask;
	u32 delay_ms;
} regval_t;

struct reg_table {
	const regval_t *regval;
	int regval_num;
};

struct stf_isp_dev;
enum subdev_type;

struct isp_hw_ops {
	int (*isp_clk_enable)(struct stf_isp_dev *isp_dev);
	int (*isp_clk_disable)(struct stf_isp_dev *isp_dev);
	int (*isp_reset)(struct stf_isp_dev *isp_dev);
	int (*isp_config_set)(struct stf_isp_dev *isp_dev);
	int (*isp_set_format)(struct stf_isp_dev *isp_dev,
			struct v4l2_rect *crop, u32 mcode);
			// u32 width, u32 height);
	int (*isp_stream_set)(struct stf_isp_dev *isp_dev, int on);
};

struct isp_ctrls {
	struct v4l2_ctrl_handler handler;
	struct v4l2_ctrl *pixel_rate;
	struct {
		struct v4l2_ctrl *auto_exp;
		struct v4l2_ctrl *exposure;
	};
	struct {
		struct v4l2_ctrl *auto_wb;
		struct v4l2_ctrl *blue_balance;
		struct v4l2_ctrl *red_balance;
	};
	struct {
		struct v4l2_ctrl *auto_gain;
		struct v4l2_ctrl *gain;
	};
	struct v4l2_ctrl *brightness;
	struct v4l2_ctrl *light_freq;
	struct v4l2_ctrl *saturation;
	struct v4l2_ctrl *contrast;
	struct v4l2_ctrl *hue;
	struct v4l2_ctrl *test_pattern;
	struct v4l2_ctrl *hflip;
	struct v4l2_ctrl *vflip;
};

struct isp_setfile {
	struct reg_table settings;
	const u8 *data;
	unsigned int size;
	unsigned int state;
};

struct stf_isp_dev {
	enum subdev_type sdev_type;  // must be frist
	struct stfcamss *stfcamss;
	atomic_t ref_count;
	u8 id;
	struct v4l2_subdev subdev;
	struct media_pad pads[STF_ISP_PADS_NUM];
	struct v4l2_mbus_framefmt fmt[STF_ISP_PADS_NUM];
	struct v4l2_rect compose;
	struct v4l2_rect crop;
	const struct isp_format *formats;
	unsigned int nformats;
	struct isp_hw_ops *hw_ops;
	struct mutex stream_lock;
	int stream_count;

	struct isp_ctrls ctrls;
	struct mutex setfile_lock;
	struct isp_setfile setfile;
};

extern int stf_isp_subdev_init(struct stfcamss *stfcamss, int id);
extern int stf_isp_register(struct stf_isp_dev *isp_dev,
		struct v4l2_device *v4l2_dev);
extern int stf_isp_unregister(struct stf_isp_dev *isp_dev);
extern struct isp_hw_ops isp_ops;
extern void dump_isp_reg(void *__iomem ispbase, int id);

#endif /* STF_ISP_H */