241 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/*3 * camss-csid.h4 *5 * Qualcomm MSM Camera Subsystem - CSID (CSI Decoder) Module6 *7 * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.8 * Copyright (C) 2015-2018 Linaro Ltd.9 */10#ifndef QC_MSM_CAMSS_CSID_H11#define QC_MSM_CAMSS_CSID_H12 13#include <linux/clk.h>14#include <linux/interrupt.h>15#include <media/media-entity.h>16#include <media/v4l2-ctrls.h>17#include <media/v4l2-device.h>18#include <media/v4l2-mediabus.h>19#include <media/v4l2-subdev.h>20 21#define MSM_CSID_PAD_SINK 022#define MSM_CSID_PAD_FIRST_SRC 123#define MSM_CSID_PADS_NUM 524 25#define MSM_CSID_PAD_SRC (MSM_CSID_PAD_FIRST_SRC)26 27/* CSID hardware can demultiplex up to 4 outputs */28#define MSM_CSID_MAX_SRC_STREAMS 429 30#define DATA_TYPE_EMBEDDED_DATA_8BIT 0x1231#define DATA_TYPE_YUV420_8BIT 0x1832#define DATA_TYPE_YUV420_10BIT 0x1933#define DATA_TYPE_YUV420_8BIT_LEGACY 0x1a34#define DATA_TYPE_YUV420_8BIT_SHIFTED 0x1c /* Chroma Shifted Pixel Sampling */35#define DATA_TYPE_YUV420_10BIT_SHIFTED 0x1d /* Chroma Shifted Pixel Sampling */36#define DATA_TYPE_YUV422_8BIT 0x1e37#define DATA_TYPE_YUV422_10BIT 0x1f38#define DATA_TYPE_RGB444 0x2039#define DATA_TYPE_RGB555 0x2140#define DATA_TYPE_RGB565 0x2241#define DATA_TYPE_RGB666 0x2342#define DATA_TYPE_RGB888 0x2443#define DATA_TYPE_RAW_24BIT 0x2744#define DATA_TYPE_RAW_6BIT 0x2845#define DATA_TYPE_RAW_7BIT 0x2946#define DATA_TYPE_RAW_8BIT 0x2a47#define DATA_TYPE_RAW_10BIT 0x2b48#define DATA_TYPE_RAW_12BIT 0x2c49#define DATA_TYPE_RAW_14BIT 0x2d50#define DATA_TYPE_RAW_16BIT 0x2e51#define DATA_TYPE_RAW_20BIT 0x2f52 53#define CSID_RESET_TIMEOUT_MS 50054 55enum csid_testgen_mode {56 CSID_PAYLOAD_MODE_DISABLED = 0,57 CSID_PAYLOAD_MODE_INCREMENTING = 1,58 CSID_PAYLOAD_MODE_ALTERNATING_55_AA = 2,59 CSID_PAYLOAD_MODE_ALL_ZEROES = 3,60 CSID_PAYLOAD_MODE_ALL_ONES = 4,61 CSID_PAYLOAD_MODE_RANDOM = 5,62 CSID_PAYLOAD_MODE_USER_SPECIFIED = 6,63 CSID_PAYLOAD_MODE_NUM_SUPPORTED_GEN1 = 6, /* excluding disabled */64 CSID_PAYLOAD_MODE_COMPLEX_PATTERN = 7,65 CSID_PAYLOAD_MODE_COLOR_BOX = 8,66 CSID_PAYLOAD_MODE_COLOR_BARS = 9,67 CSID_PAYLOAD_MODE_NUM_SUPPORTED_GEN2 = 9, /* excluding disabled */68};69 70struct csid_format_info {71 u32 code;72 u8 data_type;73 u8 decode_format;74 u8 bpp;75 u8 spp; /* bus samples per pixel */76};77 78struct csid_formats {79 unsigned int nformats;80 const struct csid_format_info *formats;81};82 83struct csid_testgen_config {84 enum csid_testgen_mode mode;85 const char * const*modes;86 u8 nmodes;87 u8 enabled;88};89 90struct csid_phy_config {91 u8 csiphy_id;92 u8 lane_cnt;93 u32 lane_assign;94 u32 en_vc;95 u8 need_vc_update;96};97 98struct csid_device;99 100struct csid_hw_ops {101 /*102 * configure_stream - Configures and starts CSID input stream103 * @csid: CSID device104 */105 void (*configure_stream)(struct csid_device *csid, u8 enable);106 107 /*108 * configure_testgen_pattern - Validates and configures output pattern mode109 * of test pattern generator110 * @csid: CSID device111 */112 int (*configure_testgen_pattern)(struct csid_device *csid, s32 val);113 114 /*115 * hw_version - Read hardware version register from hardware116 * @csid: CSID device117 */118 u32 (*hw_version)(struct csid_device *csid);119 120 /*121 * isr - CSID module interrupt service routine122 * @irq: Interrupt line123 * @dev: CSID device124 *125 * Return IRQ_HANDLED on success126 */127 irqreturn_t (*isr)(int irq, void *dev);128 129 /*130 * reset - Trigger reset on CSID module and wait to complete131 * @csid: CSID device132 *133 * Return 0 on success or a negative error code otherwise134 */135 int (*reset)(struct csid_device *csid);136 137 /*138 * src_pad_code - Pick an output/src format based on the input/sink format139 * @csid: CSID device140 * @sink_code: The sink format of the input141 * @match_format_idx: Request preferred index, as defined by subdevice csid_format.142 * Set @match_code to 0 if used.143 * @match_code: Request preferred code, set @match_format_idx to 0 if used144 *145 * Return 0 on failure or src format code otherwise146 */147 u32 (*src_pad_code)(struct csid_device *csid, u32 sink_code,148 unsigned int match_format_idx, u32 match_code);149 150 /*151 * subdev_init - Initialize CSID device according for hardware revision152 * @csid: CSID device153 */154 void (*subdev_init)(struct csid_device *csid);155};156 157struct csid_subdev_resources {158 bool is_lite;159 const struct csid_hw_ops *hw_ops;160 const struct parent_dev_ops *parent_dev_ops;161 const struct csid_formats *formats;162};163 164struct csid_device {165 struct camss *camss;166 u8 id;167 struct v4l2_subdev subdev;168 struct media_pad pads[MSM_CSID_PADS_NUM];169 void __iomem *base;170 u32 irq;171 char irq_name[30];172 struct camss_clock *clock;173 int nclocks;174 struct regulator_bulk_data *supplies;175 int num_supplies;176 struct completion reset_complete;177 struct csid_testgen_config testgen;178 struct csid_phy_config phy;179 struct v4l2_mbus_framefmt fmt[MSM_CSID_PADS_NUM];180 struct v4l2_ctrl_handler ctrls;181 struct v4l2_ctrl *testgen_mode;182 const struct csid_subdev_resources *res;183};184 185struct camss_subdev_resources;186 187/*188 * csid_find_code - Find a format code in an array using array index or format code189 * @codes: Array of format codes190 * @ncodes: Length of @code array191 * @req_format_idx: Request preferred index, as defined by subdevice csid_format.192 * Set @match_code to 0 if used.193 * @match_code: Request preferred code, set @req_format_idx to 0 if used194 *195 * Return 0 on failure or format code otherwise196 */197u32 csid_find_code(u32 *codes, unsigned int ncode,198 unsigned int match_format_idx, u32 match_code);199 200/*201 * csid_get_fmt_entry - Find csid_format_info entry with matching format code202 * @formats: Array of format csid_format_info entries203 * @nformats: Length of @nformats array204 * @code: Desired format code205 *206 * Return formats[0] on failure to find code207 */208const struct csid_format_info *csid_get_fmt_entry(const struct csid_format_info *formats,209 unsigned int nformats,210 u32 code);211 212int msm_csid_subdev_init(struct camss *camss, struct csid_device *csid,213 const struct camss_subdev_resources *res, u8 id);214 215int msm_csid_register_entity(struct csid_device *csid,216 struct v4l2_device *v4l2_dev);217 218void msm_csid_unregister_entity(struct csid_device *csid);219 220void msm_csid_get_csid_id(struct media_entity *entity, u8 *id);221 222extern const char * const csid_testgen_modes[];223 224extern const struct csid_formats csid_formats_4_1;225extern const struct csid_formats csid_formats_4_7;226extern const struct csid_formats csid_formats_gen2;227 228extern const struct csid_hw_ops csid_ops_4_1;229extern const struct csid_hw_ops csid_ops_4_7;230extern const struct csid_hw_ops csid_ops_gen2;231 232/*233 * csid_is_lite - Check if CSID is CSID lite.234 * @csid: CSID Device235 *236 * Return whether CSID is CSID lite237 */238bool csid_is_lite(struct csid_device *csid);239 240#endif /* QC_MSM_CAMSS_CSID_H */241