1 /* SPDX-License-Identifier: GPL-2.0 */
5 * Qualcomm MSM Camera Subsystem - VFE (Video Front End) Module
7 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
8 * Copyright (C) 2015-2018 Linaro Ltd.
10 #ifndef QC_MSM_CAMSS_VFE_H
11 #define QC_MSM_CAMSS_VFE_H
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>
19 #include "camss-video.h"
20 #include "camss-vfe-gen1.h"
22 #define MSM_VFE_PAD_SINK 0
23 #define MSM_VFE_PAD_SRC 1
24 #define MSM_VFE_PADS_NUM 2
26 #define MSM_VFE_IMAGE_MASTERS_NUM 7
27 #define MSM_VFE_COMPOSITE_IRQ_NUM 4
29 /* VFE halt timeout */
30 #define VFE_HALT_TIMEOUT_MS 100
31 /* Frame drop value. VAL + UPDATES - 1 should not exceed 31 */
32 #define VFE_FRAME_DROP_VAL 30
34 #define vfe_line_array(ptr_line) \
35 ((const struct vfe_line (*)[]) &(ptr_line)[-(ptr_line)->id])
37 #define to_vfe(ptr_line) \
38 container_of(vfe_line_array(ptr_line), struct vfe_device, line)
40 enum vfe_output_state {
44 VFE_OUTPUT_CONTINUOUS,
55 VFE_LINE_NUM_GEN2 = 3,
57 VFE_LINE_NUM_GEN1 = 4,
65 struct camss_buffer *buf[2];
66 struct camss_buffer *last_buffer;
67 struct list_head pending_bufs;
69 unsigned int drop_update_idx;
80 enum vfe_output_state state;
81 unsigned int sequence;
84 struct completion sof;
85 struct completion reg_update;
90 struct v4l2_subdev subdev;
91 struct media_pad pads[MSM_VFE_PADS_NUM];
92 struct v4l2_mbus_framefmt fmt[MSM_VFE_PADS_NUM];
93 struct v4l2_rect compose;
94 struct v4l2_rect crop;
95 struct camss_video video_out;
96 struct vfe_output output;
97 const struct vfe_format *formats;
98 unsigned int nformats;
104 void (*enable_irq_common)(struct vfe_device *vfe);
105 void (*global_reset)(struct vfe_device *vfe);
106 void (*hw_version_read)(struct vfe_device *vfe, struct device *dev);
107 irqreturn_t (*isr)(int irq, void *dev);
108 void (*isr_read)(struct vfe_device *vfe, u32 *value0, u32 *value1);
109 void (*pm_domain_off)(struct vfe_device *vfe);
110 int (*pm_domain_on)(struct vfe_device *vfe);
111 void (*reg_update)(struct vfe_device *vfe, enum vfe_line_id line_id);
112 void (*reg_update_clear)(struct vfe_device *vfe,
113 enum vfe_line_id line_id);
114 void (*subdev_init)(struct device *dev, struct vfe_device *vfe);
115 int (*vfe_disable)(struct vfe_line *line);
116 int (*vfe_enable)(struct vfe_line *line);
117 int (*vfe_halt)(struct vfe_device *vfe);
118 void (*violation_read)(struct vfe_device *vfe);
122 void (*reset_ack)(struct vfe_device *vfe);
123 void (*halt_ack)(struct vfe_device *vfe);
124 void (*reg_update)(struct vfe_device *vfe, enum vfe_line_id line_id);
125 void (*sof)(struct vfe_device *vfe, enum vfe_line_id line_id);
126 void (*comp_done)(struct vfe_device *vfe, u8 comp);
127 void (*wm_done)(struct vfe_device *vfe, u8 wm);
136 struct camss_clock *clock;
138 struct completion reset_complete;
139 struct completion halt_complete;
140 struct mutex power_lock;
142 struct mutex stream_lock;
144 spinlock_t output_lock;
145 enum vfe_line_id wm_output_map[MSM_VFE_IMAGE_MASTERS_NUM];
146 struct vfe_line line[VFE_LINE_NUM_MAX];
150 const struct vfe_hw_ops *ops;
151 const struct vfe_hw_ops_gen1 *ops_gen1;
152 struct vfe_isr_ops isr_ops;
153 struct camss_video_ops video_ops;
158 int msm_vfe_subdev_init(struct camss *camss, struct vfe_device *vfe,
159 const struct resources *res, u8 id);
161 int msm_vfe_register_entities(struct vfe_device *vfe,
162 struct v4l2_device *v4l2_dev);
164 void msm_vfe_unregister_entities(struct vfe_device *vfe);
166 void msm_vfe_get_vfe_id(struct media_entity *entity, u8 *id);
167 void msm_vfe_get_vfe_line_id(struct media_entity *entity, enum vfe_line_id *id);
170 * vfe_buf_add_pending - Add output buffer to list of pending
171 * @output: VFE output
172 * @buffer: Video buffer
174 void vfe_buf_add_pending(struct vfe_output *output, struct camss_buffer *buffer);
176 struct camss_buffer *vfe_buf_get_pending(struct vfe_output *output);
178 int vfe_flush_buffers(struct camss_video *vid, enum vb2_buffer_state state);
181 * vfe_isr_comp_done - Process composite image done interrupt
183 * @comp: Composite image id
185 void vfe_isr_comp_done(struct vfe_device *vfe, u8 comp);
187 void vfe_isr_reset_ack(struct vfe_device *vfe);
188 int vfe_put_output(struct vfe_line *line);
189 int vfe_release_wm(struct vfe_device *vfe, u8 wm);
190 int vfe_reserve_wm(struct vfe_device *vfe, enum vfe_line_id line_id);
193 * vfe_reset - Trigger reset on VFE module and wait to complete
196 * Return 0 on success or a negative error code otherwise
198 int vfe_reset(struct vfe_device *vfe);
200 extern const struct vfe_hw_ops vfe_ops_4_1;
201 extern const struct vfe_hw_ops vfe_ops_4_7;
202 extern const struct vfe_hw_ops vfe_ops_4_8;
203 extern const struct vfe_hw_ops vfe_ops_170;
205 #endif /* QC_MSM_CAMSS_VFE_H */