1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * camss-vfe.h
4  *
5  * Qualcomm MSM Camera Subsystem - VFE (Video Front End) Module
6  *
7  * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
8  * Copyright (C) 2015-2018 Linaro Ltd.
9  */
10 #ifndef QC_MSM_CAMSS_VFE_H
11 #define QC_MSM_CAMSS_VFE_H
12 
13 #include <linux/clk.h>
14 #include <linux/spinlock_types.h>
15 #include <media/media-entity.h>
16 #include <media/v4l2-device.h>
17 #include <media/v4l2-subdev.h>
18 
19 #include "camss-video.h"
20 
21 #define MSM_VFE_PAD_SINK 0
22 #define MSM_VFE_PAD_SRC 1
23 #define MSM_VFE_PADS_NUM 2
24 
25 #define MSM_VFE_LINE_NUM 4
26 #define MSM_VFE_IMAGE_MASTERS_NUM 7
27 #define MSM_VFE_COMPOSITE_IRQ_NUM 4
28 
29 enum vfe_output_state {
30 	VFE_OUTPUT_OFF,
31 	VFE_OUTPUT_RESERVED,
32 	VFE_OUTPUT_SINGLE,
33 	VFE_OUTPUT_CONTINUOUS,
34 	VFE_OUTPUT_IDLE,
35 	VFE_OUTPUT_STOPPING
36 };
37 
38 enum vfe_line_id {
39 	VFE_LINE_NONE = -1,
40 	VFE_LINE_RDI0 = 0,
41 	VFE_LINE_RDI1 = 1,
42 	VFE_LINE_RDI2 = 2,
43 	VFE_LINE_PIX = 3
44 };
45 
46 struct vfe_output {
47 	u8 wm_num;
48 	u8 wm_idx[3];
49 
50 	int active_buf;
51 	struct camss_buffer *buf[2];
52 	struct camss_buffer *last_buffer;
53 	struct list_head pending_bufs;
54 
55 	unsigned int drop_update_idx;
56 
57 	enum vfe_output_state state;
58 	unsigned int sequence;
59 	int wait_sof;
60 	int wait_reg_update;
61 	struct completion sof;
62 	struct completion reg_update;
63 };
64 
65 struct vfe_line {
66 	enum vfe_line_id id;
67 	struct v4l2_subdev subdev;
68 	struct media_pad pads[MSM_VFE_PADS_NUM];
69 	struct v4l2_mbus_framefmt fmt[MSM_VFE_PADS_NUM];
70 	struct v4l2_rect compose;
71 	struct v4l2_rect crop;
72 	struct camss_video video_out;
73 	struct vfe_output output;
74 	const struct vfe_format *formats;
75 	unsigned int nformats;
76 };
77 
78 struct vfe_device;
79 
80 struct vfe_hw_ops {
81 	void (*hw_version_read)(struct vfe_device *vfe, struct device *dev);
82 	u16 (*get_ub_size)(u8 vfe_id);
83 	void (*global_reset)(struct vfe_device *vfe);
84 	void (*halt_request)(struct vfe_device *vfe);
85 	void (*halt_clear)(struct vfe_device *vfe);
86 	void (*wm_enable)(struct vfe_device *vfe, u8 wm, u8 enable);
87 	void (*wm_frame_based)(struct vfe_device *vfe, u8 wm, u8 enable);
88 	void (*wm_line_based)(struct vfe_device *vfe, u32 wm,
89 			      struct v4l2_pix_format_mplane *pix,
90 			      u8 plane, u32 enable);
91 	void (*wm_set_framedrop_period)(struct vfe_device *vfe, u8 wm, u8 per);
92 	void (*wm_set_framedrop_pattern)(struct vfe_device *vfe, u8 wm,
93 					 u32 pattern);
94 	void (*wm_set_ub_cfg)(struct vfe_device *vfe, u8 wm, u16 offset,
95 			      u16 depth);
96 	void (*bus_reload_wm)(struct vfe_device *vfe, u8 wm);
97 	void (*wm_set_ping_addr)(struct vfe_device *vfe, u8 wm, u32 addr);
98 	void (*wm_set_pong_addr)(struct vfe_device *vfe, u8 wm, u32 addr);
99 	int (*wm_get_ping_pong_status)(struct vfe_device *vfe, u8 wm);
100 	void (*bus_enable_wr_if)(struct vfe_device *vfe, u8 enable);
101 	void (*bus_connect_wm_to_rdi)(struct vfe_device *vfe, u8 wm,
102 				      enum vfe_line_id id);
103 	void (*wm_set_subsample)(struct vfe_device *vfe, u8 wm);
104 	void (*bus_disconnect_wm_from_rdi)(struct vfe_device *vfe, u8 wm,
105 					   enum vfe_line_id id);
106 	void (*set_xbar_cfg)(struct vfe_device *vfe, struct vfe_output *output,
107 			     u8 enable);
108 	void (*set_rdi_cid)(struct vfe_device *vfe, enum vfe_line_id id,
109 			    u8 cid);
110 	void (*set_realign_cfg)(struct vfe_device *vfe, struct vfe_line *line,
111 				u8 enable);
112 	void (*reg_update)(struct vfe_device *vfe, enum vfe_line_id line_id);
113 	void (*reg_update_clear)(struct vfe_device *vfe,
114 				 enum vfe_line_id line_id);
115 	void (*enable_irq_wm_line)(struct vfe_device *vfe, u8 wm,
116 				   enum vfe_line_id line_id, u8 enable);
117 	void (*enable_irq_pix_line)(struct vfe_device *vfe, u8 comp,
118 				    enum vfe_line_id line_id, u8 enable);
119 	void (*enable_irq_common)(struct vfe_device *vfe);
120 	void (*set_demux_cfg)(struct vfe_device *vfe, struct vfe_line *line);
121 	void (*set_scale_cfg)(struct vfe_device *vfe, struct vfe_line *line);
122 	void (*set_crop_cfg)(struct vfe_device *vfe, struct vfe_line *line);
123 	void (*set_clamp_cfg)(struct vfe_device *vfe);
124 	void (*set_qos)(struct vfe_device *vfe);
125 	void (*set_ds)(struct vfe_device *vfe);
126 	void (*set_cgc_override)(struct vfe_device *vfe, u8 wm, u8 enable);
127 	void (*set_camif_cfg)(struct vfe_device *vfe, struct vfe_line *line);
128 	void (*set_camif_cmd)(struct vfe_device *vfe, u8 enable);
129 	void (*set_module_cfg)(struct vfe_device *vfe, u8 enable);
130 	int (*camif_wait_for_stop)(struct vfe_device *vfe, struct device *dev);
131 	void (*isr_read)(struct vfe_device *vfe, u32 *value0, u32 *value1);
132 	void (*violation_read)(struct vfe_device *vfe);
133 	irqreturn_t (*isr)(int irq, void *dev);
134 };
135 
136 struct vfe_isr_ops {
137 	void (*reset_ack)(struct vfe_device *vfe);
138 	void (*halt_ack)(struct vfe_device *vfe);
139 	void (*reg_update)(struct vfe_device *vfe, enum vfe_line_id line_id);
140 	void (*sof)(struct vfe_device *vfe, enum vfe_line_id line_id);
141 	void (*comp_done)(struct vfe_device *vfe, u8 comp);
142 	void (*wm_done)(struct vfe_device *vfe, u8 wm);
143 };
144 
145 struct vfe_device {
146 	struct camss *camss;
147 	u8 id;
148 	void __iomem *base;
149 	u32 irq;
150 	char irq_name[30];
151 	struct camss_clock *clock;
152 	int nclocks;
153 	struct completion reset_complete;
154 	struct completion halt_complete;
155 	struct mutex power_lock;
156 	int power_count;
157 	struct mutex stream_lock;
158 	int stream_count;
159 	spinlock_t output_lock;
160 	enum vfe_line_id wm_output_map[MSM_VFE_IMAGE_MASTERS_NUM];
161 	struct vfe_line line[MSM_VFE_LINE_NUM];
162 	u32 reg_update;
163 	u8 was_streaming;
164 	const struct vfe_hw_ops *ops;
165 	struct vfe_isr_ops isr_ops;
166 };
167 
168 struct resources;
169 
170 int msm_vfe_subdev_init(struct camss *camss, struct vfe_device *vfe,
171 			const struct resources *res, u8 id);
172 
173 int msm_vfe_register_entities(struct vfe_device *vfe,
174 			      struct v4l2_device *v4l2_dev);
175 
176 void msm_vfe_unregister_entities(struct vfe_device *vfe);
177 
178 void msm_vfe_get_vfe_id(struct media_entity *entity, u8 *id);
179 void msm_vfe_get_vfe_line_id(struct media_entity *entity, enum vfe_line_id *id);
180 
181 extern const struct vfe_hw_ops vfe_ops_4_1;
182 extern const struct vfe_hw_ops vfe_ops_4_7;
183 extern const struct vfe_hw_ops vfe_ops_4_8;
184 
185 #endif /* QC_MSM_CAMSS_VFE_H */
186