summaryrefslogtreecommitdiff
path: root/drivers/media/platform/starfive/v4l2_driver/stf_csiphy.h
blob: 7c954692f2d1c1226a1515baed7b0e4c74f10a1b (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* SPDX-License-Identifier: GPL-2.0
 *
 * Copyright (C) 2021-2023 StarFive Technology Co., Ltd.
 *
 */

#ifndef STF_CSIPHY_H
#define STF_CSIPHY_H

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

#define STF_CSIPHY_NAME "stf_csiphy"

#define STF_CSIPHY_PAD_SINK     0
#define STF_CSIPHY_PAD_SRC      1
#define STF_CSIPHY_PADS_NUM     2

#define STF_CSI2_MAX_DATA_LANES      4

union static_config {
	u32 raw;
	struct {
		u32 sel                 : 2;
		u32 rsvd_6              : 2;
		u32 v2p0_support_enable : 1;
		u32 rsvd_5              : 3;
		u32 lane_nb             : 3;
		u32 rsvd_4              : 5;
		u32 dl0_map             : 3;
		u32 rsvd_3              : 1;
		u32 dl1_map             : 3;
		u32 rsvd_2              : 1;
		u32 dl2_map             : 3;
		u32 rsvd_1              : 1;
		u32 dl3_map             : 3;
		u32 rsvd_0              : 1;
	} bits;
};

union error_bypass_cfg {
	u32 value;
	struct {
		u32 crc             :  1;
		u32 ecc             :  1;
		u32 data_id         :  1;
		u32 rsvd_0          : 29;
	};
};

union stream_monitor_ctrl {
	u32 value;
	struct {
		u32 lb_vc             : 4;
		u32 lb_en             : 1;
		u32 timer_vc          : 4;
		u32 timer_en          : 1;
		u32 timer_eof         : 1;
		u32 frame_mon_vc      : 4;
		u32 frame_mon_en      : 1;
		u32 frame_length      : 16;
	};
};

union stream_cfg {
	u32 value;
	struct {
		u32 interface_mode :  1;
		u32 ls_le_mode     :  1;
		u32 rsvd_3         :  2;
		u32 num_pixels     :  2;
		u32 rsvd_2         :  2;
		u32 fifo_mode      :  2;
		u32 rsvd_1         :  2;
		u32 bpp_bypass     :  3;
		u32 rsvd_0         :  1;
		u32 fifo_fill      : 16;
	};
};

union dphy_lane_ctrl {
	u32 raw;
	struct {
		u32 dl0_en    : 1;
		u32 dl1_en    : 1;
		u32 dl2_en    : 1;
		u32 dl3_en    : 1;
		u32 cl_en     : 1;
		u32 rsvd_1    : 7;
		u32 dl0_reset : 1;
		u32 dl1_reset : 1;
		u32 dl2_reset : 1;
		u32 dl3_reset : 1;
		u32 cl_reset  : 1;
		u32 rsvd_0    : 15;
	} bits;
};

union dphy_lane_swap {
	u32 raw;
	struct {
		u32 rx_1c2c_sel        : 1;
		u32 lane_swap_clk      : 3;
		u32 lane_swap_clk1     : 3;
		u32 lane_swap_lan0     : 3;
		u32 lane_swap_lan1     : 3;
		u32 lane_swap_lan2     : 3;
		u32 lane_swap_lan3     : 3;
		u32 dpdn_swap_clk      : 1;
		u32 dpdn_swap_clk1     : 1;
		u32 dpdn_swap_lan0     : 1;
		u32 dpdn_swap_lan1     : 1;
		u32 dpdn_swap_lan2     : 1;
		u32 dpdn_swap_lan3     : 1;
		u32 hs_freq_chang_clk0 : 1;
		u32 hs_freq_chang_clk1 : 1;
		u32 reserved           : 5;
	} bits;
};

union dphy_lane_en {
	u32 raw;
	struct {
		u32 gpio_en		: 6;
		u32 mp_test_mode_sel	: 5;
		u32 mp_test_en		: 1;
		u32 dphy_enable_lan0	: 1;
		u32 dphy_enable_lan1	: 1;
		u32 dphy_enable_lan2	: 1;
		u32 dphy_enable_lan3	: 1;
		u32 rsvd_0		: 16;
	} bits;
};

struct csiphy_format {
	u32 code;
	u8 bpp;
};

struct csi2phy_cfg {
	unsigned int flags;
	unsigned char data_lanes[STF_CSI2_MAX_DATA_LANES];
	unsigned char clock_lane;
	unsigned char num_data_lanes;
	bool lane_polarities[1 + STF_CSI2_MAX_DATA_LANES];
};

struct csi2phy_cfg2 {
	unsigned char data_lanes[STF_CSI2_MAX_DATA_LANES];
	unsigned char num_data_lanes;
	unsigned char num_clks;
	unsigned char clock_lane;
	unsigned char clock1_lane;
	bool lane_polarities[2 + STF_CSI2_MAX_DATA_LANES];
};

struct stf_csiphy_dev;

struct csiphy_hw_ops {
	int (*csiphy_clk_enable)(struct stf_csiphy_dev *csiphy_dev);
	int (*csiphy_clk_disable)(struct stf_csiphy_dev *csiphy_dev);
	int (*csiphy_config_set)(struct stf_csiphy_dev *csiphy_dev);
	int (*csiphy_stream_set)(struct stf_csiphy_dev *csiphy_dev, int on);
};

struct stf_csiphy_dev {
	struct stfcamss *stfcamss;
	struct csi2phy_cfg *csiphy;
	struct v4l2_subdev subdev;
	struct media_pad pads[STF_CSIPHY_PADS_NUM];
	struct v4l2_mbus_framefmt fmt[STF_CSIPHY_PADS_NUM];
	const struct csiphy_format *formats;
	unsigned int nformats;
	struct csiphy_hw_ops *hw_ops;
	struct mutex stream_lock;
	int stream_count;
};

extern int stf_csiphy_subdev_init(struct stfcamss *stfcamss);
extern int stf_csiphy_register(struct stf_csiphy_dev *csiphy_dev,
			struct v4l2_device *v4l2_dev);
extern int stf_csiphy_unregister(struct stf_csiphy_dev *csiphy_dev);

extern struct csiphy_hw_ops csiphy_ops;

#endif /* STF_CSIPHY_H */