256 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/*3 * camss-vfe.h4 *5 * Qualcomm MSM Camera Subsystem - VFE (Video Front End) Module6 *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_H11#define QC_MSM_CAMSS_VFE_H12 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#include "camss-vfe-gen1.h"21 22#define MSM_VFE_PAD_SINK 023#define MSM_VFE_PAD_SRC 124#define MSM_VFE_PADS_NUM 225 26#define MSM_VFE_IMAGE_MASTERS_NUM 727#define MSM_VFE_COMPOSITE_IRQ_NUM 428 29/* VFE halt timeout */30#define VFE_HALT_TIMEOUT_MS 10031/* Frame drop value. VAL + UPDATES - 1 should not exceed 31 */32#define VFE_FRAME_DROP_VAL 3033 34#define vfe_line_array(ptr_line) \35 ((const struct vfe_line (*)[]) &(ptr_line)[-(ptr_line)->id])36 37#define to_vfe(ptr_line) \38 container_of(vfe_line_array(ptr_line), struct vfe_device, line)39 40enum vfe_output_state {41 VFE_OUTPUT_OFF,42 VFE_OUTPUT_RESERVED,43 VFE_OUTPUT_SINGLE,44 VFE_OUTPUT_CONTINUOUS,45 VFE_OUTPUT_IDLE,46 VFE_OUTPUT_STOPPING,47 VFE_OUTPUT_ON,48};49 50enum vfe_line_id {51 VFE_LINE_NONE = -1,52 VFE_LINE_RDI0 = 0,53 VFE_LINE_RDI1 = 1,54 VFE_LINE_RDI2 = 2,55 VFE_LINE_PIX = 3,56 VFE_LINE_NUM_MAX = 457};58 59struct vfe_output {60 u8 wm_num;61 u8 wm_idx[3];62 63 struct camss_buffer *buf[2];64 struct camss_buffer *last_buffer;65 struct list_head pending_bufs;66 67 unsigned int drop_update_idx;68 69 union {70 struct {71 int active_buf;72 int wait_sof;73 } gen1;74 struct {75 int active_num;76 } gen2;77 };78 enum vfe_output_state state;79 unsigned int sequence;80 81 int wait_reg_update;82 struct completion sof;83 struct completion reg_update;84};85 86struct vfe_line {87 enum vfe_line_id id;88 struct v4l2_subdev subdev;89 struct media_pad pads[MSM_VFE_PADS_NUM];90 struct v4l2_mbus_framefmt fmt[MSM_VFE_PADS_NUM];91 struct v4l2_rect compose;92 struct v4l2_rect crop;93 struct camss_video video_out;94 struct vfe_output output;95 const struct camss_format_info *formats;96 unsigned int nformats;97};98 99struct vfe_device;100 101struct vfe_hw_ops {102 void (*enable_irq_common)(struct vfe_device *vfe);103 void (*global_reset)(struct vfe_device *vfe);104 u32 (*hw_version)(struct vfe_device *vfe);105 irqreturn_t (*isr)(int irq, void *dev);106 void (*isr_read)(struct vfe_device *vfe, u32 *value0, u32 *value1);107 void (*pm_domain_off)(struct vfe_device *vfe);108 int (*pm_domain_on)(struct vfe_device *vfe);109 void (*reg_update)(struct vfe_device *vfe, enum vfe_line_id line_id);110 void (*reg_update_clear)(struct vfe_device *vfe,111 enum vfe_line_id line_id);112 void (*subdev_init)(struct device *dev, struct vfe_device *vfe);113 int (*vfe_disable)(struct vfe_line *line);114 int (*vfe_enable)(struct vfe_line *line);115 int (*vfe_halt)(struct vfe_device *vfe);116 void (*violation_read)(struct vfe_device *vfe);117 void (*vfe_wm_stop)(struct vfe_device *vfe, u8 wm);118};119 120struct vfe_isr_ops {121 void (*reset_ack)(struct vfe_device *vfe);122 void (*halt_ack)(struct vfe_device *vfe);123 void (*reg_update)(struct vfe_device *vfe, enum vfe_line_id line_id);124 void (*sof)(struct vfe_device *vfe, enum vfe_line_id line_id);125 void (*comp_done)(struct vfe_device *vfe, u8 comp);126 void (*wm_done)(struct vfe_device *vfe, u8 wm);127};128 129struct vfe_subdev_resources {130 bool is_lite;131 u8 line_num;132 bool has_pd;133 char *pd_name;134 const struct vfe_hw_ops *hw_ops;135 const struct camss_formats *formats_rdi;136 const struct camss_formats *formats_pix;137};138 139struct vfe_device {140 struct camss *camss;141 u8 id;142 void __iomem *base;143 u32 irq;144 char irq_name[30];145 struct camss_clock *clock;146 int nclocks;147 struct completion reset_complete;148 struct completion halt_complete;149 struct mutex power_lock;150 int power_count;151 struct mutex stream_lock;152 int stream_count;153 spinlock_t output_lock;154 enum vfe_line_id wm_output_map[MSM_VFE_IMAGE_MASTERS_NUM];155 struct vfe_line line[VFE_LINE_NUM_MAX];156 u32 reg_update;157 u8 was_streaming;158 const struct vfe_subdev_resources *res;159 const struct vfe_hw_ops_gen1 *ops_gen1;160 struct vfe_isr_ops isr_ops;161 struct camss_video_ops video_ops;162 struct device *genpd;163 struct device_link *genpd_link;164};165 166struct camss_subdev_resources;167 168int msm_vfe_subdev_init(struct camss *camss, struct vfe_device *vfe,169 const struct camss_subdev_resources *res, u8 id);170 171void msm_vfe_genpd_cleanup(struct vfe_device *vfe);172 173int msm_vfe_register_entities(struct vfe_device *vfe,174 struct v4l2_device *v4l2_dev);175 176void msm_vfe_unregister_entities(struct vfe_device *vfe);177 178/*179 * vfe_buf_add_pending - Add output buffer to list of pending180 * @output: VFE output181 * @buffer: Video buffer182 */183void vfe_buf_add_pending(struct vfe_output *output, struct camss_buffer *buffer);184 185struct camss_buffer *vfe_buf_get_pending(struct vfe_output *output);186 187int vfe_flush_buffers(struct camss_video *vid, enum vb2_buffer_state state);188 189/*190 * vfe_isr_comp_done - Process composite image done interrupt191 * @vfe: VFE Device192 * @comp: Composite image id193 */194void vfe_isr_comp_done(struct vfe_device *vfe, u8 comp);195 196void vfe_isr_reset_ack(struct vfe_device *vfe);197int vfe_put_output(struct vfe_line *line);198int vfe_release_wm(struct vfe_device *vfe, u8 wm);199int vfe_reserve_wm(struct vfe_device *vfe, enum vfe_line_id line_id);200 201/*202 * vfe_reset - Trigger reset on VFE module and wait to complete203 * @vfe: VFE device204 *205 * Return 0 on success or a negative error code otherwise206 */207int vfe_reset(struct vfe_device *vfe);208 209/*210 * vfe_disable - Disable streaming on VFE line211 * @line: VFE line212 *213 * Return 0 on success or a negative error code otherwise214 */215int vfe_disable(struct vfe_line *line);216 217/*218 * vfe_pm_domain_off - Disable power domains specific to this VFE.219 * @vfe: VFE Device220 */221void vfe_pm_domain_off(struct vfe_device *vfe);222 223/*224 * vfe_pm_domain_on - Enable power domains specific to this VFE.225 * @vfe: VFE Device226 */227int vfe_pm_domain_on(struct vfe_device *vfe);228 229extern const struct camss_formats vfe_formats_rdi_8x16;230extern const struct camss_formats vfe_formats_pix_8x16;231extern const struct camss_formats vfe_formats_rdi_8x96;232extern const struct camss_formats vfe_formats_pix_8x96;233extern const struct camss_formats vfe_formats_rdi_845;234extern const struct camss_formats vfe_formats_pix_845;235 236extern const struct vfe_hw_ops vfe_ops_4_1;237extern const struct vfe_hw_ops vfe_ops_4_7;238extern const struct vfe_hw_ops vfe_ops_4_8;239extern const struct vfe_hw_ops vfe_ops_170;240extern const struct vfe_hw_ops vfe_ops_480;241 242int vfe_get(struct vfe_device *vfe);243void vfe_put(struct vfe_device *vfe);244 245/*246 * vfe_is_lite - Return if VFE is VFE lite.247 * @vfe: VFE Device248 *249 * Some VFE lites have a different register layout.250 *251 * Return whether VFE is VFE lite252 */253bool vfe_is_lite(struct vfe_device *vfe);254 255#endif /* QC_MSM_CAMSS_VFE_H */256