162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * camss-csid-4-7.c 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Qualcomm MSM Camera Subsystem - CSID (CSI Decoder) Module 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Copyright (C) 2020 Linaro Ltd. 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci#include <linux/completion.h> 1062306a36Sopenharmony_ci#include <linux/interrupt.h> 1162306a36Sopenharmony_ci#include <linux/io.h> 1262306a36Sopenharmony_ci#include <linux/kernel.h> 1362306a36Sopenharmony_ci#include <linux/of.h> 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include "camss-csid.h" 1662306a36Sopenharmony_ci#include "camss-csid-gen2.h" 1762306a36Sopenharmony_ci#include "camss.h" 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* The CSID 2 IP-block is different from the others, 2062306a36Sopenharmony_ci * and is of a bare-bones Lite version, with no PIX 2162306a36Sopenharmony_ci * interface support. As a result of that it has an 2262306a36Sopenharmony_ci * alternate register layout. 2362306a36Sopenharmony_ci */ 2462306a36Sopenharmony_ci#define IS_LITE (csid->id >= 2 ? 1 : 0) 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#define CSID_HW_VERSION 0x0 2762306a36Sopenharmony_ci#define HW_VERSION_STEPPING 0 2862306a36Sopenharmony_ci#define HW_VERSION_REVISION 16 2962306a36Sopenharmony_ci#define HW_VERSION_GENERATION 28 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#define CSID_RST_STROBES 0x10 3262306a36Sopenharmony_ci#define RST_STROBES 0 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define CSID_CSI2_RX_IRQ_STATUS 0x20 3562306a36Sopenharmony_ci#define CSID_CSI2_RX_IRQ_MASK 0x24 3662306a36Sopenharmony_ci#define CSID_CSI2_RX_IRQ_CLEAR 0x28 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#define CSID_CSI2_RDIN_IRQ_STATUS(rdi) ((IS_LITE ? 0x30 : 0x40) \ 3962306a36Sopenharmony_ci + 0x10 * (rdi)) 4062306a36Sopenharmony_ci#define CSID_CSI2_RDIN_IRQ_MASK(rdi) ((IS_LITE ? 0x34 : 0x44) \ 4162306a36Sopenharmony_ci + 0x10 * (rdi)) 4262306a36Sopenharmony_ci#define CSID_CSI2_RDIN_IRQ_CLEAR(rdi) ((IS_LITE ? 0x38 : 0x48) \ 4362306a36Sopenharmony_ci + 0x10 * (rdi)) 4462306a36Sopenharmony_ci#define CSID_CSI2_RDIN_IRQ_SET(rdi) ((IS_LITE ? 0x3C : 0x4C) \ 4562306a36Sopenharmony_ci + 0x10 * (rdi)) 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci#define CSID_TOP_IRQ_STATUS 0x70 4862306a36Sopenharmony_ci#define TOP_IRQ_STATUS_RESET_DONE 0 4962306a36Sopenharmony_ci#define CSID_TOP_IRQ_MASK 0x74 5062306a36Sopenharmony_ci#define CSID_TOP_IRQ_CLEAR 0x78 5162306a36Sopenharmony_ci#define CSID_TOP_IRQ_SET 0x7C 5262306a36Sopenharmony_ci#define CSID_IRQ_CMD 0x80 5362306a36Sopenharmony_ci#define IRQ_CMD_CLEAR 0 5462306a36Sopenharmony_ci#define IRQ_CMD_SET 4 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci#define CSID_CSI2_RX_CFG0 0x100 5762306a36Sopenharmony_ci#define CSI2_RX_CFG0_NUM_ACTIVE_LANES 0 5862306a36Sopenharmony_ci#define CSI2_RX_CFG0_DL0_INPUT_SEL 4 5962306a36Sopenharmony_ci#define CSI2_RX_CFG0_DL1_INPUT_SEL 8 6062306a36Sopenharmony_ci#define CSI2_RX_CFG0_DL2_INPUT_SEL 12 6162306a36Sopenharmony_ci#define CSI2_RX_CFG0_DL3_INPUT_SEL 16 6262306a36Sopenharmony_ci#define CSI2_RX_CFG0_PHY_NUM_SEL 20 6362306a36Sopenharmony_ci#define CSI2_RX_CFG0_PHY_TYPE_SEL 24 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci#define CSID_CSI2_RX_CFG1 0x104 6662306a36Sopenharmony_ci#define CSI2_RX_CFG1_PACKET_ECC_CORRECTION_EN 0 6762306a36Sopenharmony_ci#define CSI2_RX_CFG1_DE_SCRAMBLE_EN 1 6862306a36Sopenharmony_ci#define CSI2_RX_CFG1_VC_MODE 2 6962306a36Sopenharmony_ci#define CSI2_RX_CFG1_COMPLETE_STREAM_EN 4 7062306a36Sopenharmony_ci#define CSI2_RX_CFG1_COMPLETE_STREAM_FRAME_TIMING 5 7162306a36Sopenharmony_ci#define CSI2_RX_CFG1_MISR_EN 6 7262306a36Sopenharmony_ci#define CSI2_RX_CFG1_CGC_MODE 7 7362306a36Sopenharmony_ci#define CGC_MODE_DYNAMIC_GATING 0 7462306a36Sopenharmony_ci#define CGC_MODE_ALWAYS_ON 1 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci#define CSID_RDI_CFG0(rdi) ((IS_LITE ? 0x200 : 0x300) \ 7762306a36Sopenharmony_ci + 0x100 * (rdi)) 7862306a36Sopenharmony_ci#define RDI_CFG0_BYTE_CNTR_EN 0 7962306a36Sopenharmony_ci#define RDI_CFG0_FORMAT_MEASURE_EN 1 8062306a36Sopenharmony_ci#define RDI_CFG0_TIMESTAMP_EN 2 8162306a36Sopenharmony_ci#define RDI_CFG0_DROP_H_EN 3 8262306a36Sopenharmony_ci#define RDI_CFG0_DROP_V_EN 4 8362306a36Sopenharmony_ci#define RDI_CFG0_CROP_H_EN 5 8462306a36Sopenharmony_ci#define RDI_CFG0_CROP_V_EN 6 8562306a36Sopenharmony_ci#define RDI_CFG0_MISR_EN 7 8662306a36Sopenharmony_ci#define RDI_CFG0_CGC_MODE 8 8762306a36Sopenharmony_ci#define CGC_MODE_DYNAMIC 0 8862306a36Sopenharmony_ci#define CGC_MODE_ALWAYS_ON 1 8962306a36Sopenharmony_ci#define RDI_CFG0_PLAIN_ALIGNMENT 9 9062306a36Sopenharmony_ci#define PLAIN_ALIGNMENT_LSB 0 9162306a36Sopenharmony_ci#define PLAIN_ALIGNMENT_MSB 1 9262306a36Sopenharmony_ci#define RDI_CFG0_PLAIN_FORMAT 10 9362306a36Sopenharmony_ci#define RDI_CFG0_DECODE_FORMAT 12 9462306a36Sopenharmony_ci#define RDI_CFG0_DATA_TYPE 16 9562306a36Sopenharmony_ci#define RDI_CFG0_VIRTUAL_CHANNEL 22 9662306a36Sopenharmony_ci#define RDI_CFG0_DT_ID 27 9762306a36Sopenharmony_ci#define RDI_CFG0_EARLY_EOF_EN 29 9862306a36Sopenharmony_ci#define RDI_CFG0_PACKING_FORMAT 30 9962306a36Sopenharmony_ci#define RDI_CFG0_ENABLE 31 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci#define CSID_RDI_CFG1(rdi) ((IS_LITE ? 0x204 : 0x304)\ 10262306a36Sopenharmony_ci + 0x100 * (rdi)) 10362306a36Sopenharmony_ci#define RDI_CFG1_TIMESTAMP_STB_SEL 0 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci#define CSID_RDI_CTRL(rdi) ((IS_LITE ? 0x208 : 0x308)\ 10662306a36Sopenharmony_ci + 0x100 * (rdi)) 10762306a36Sopenharmony_ci#define RDI_CTRL_HALT_CMD 0 10862306a36Sopenharmony_ci#define HALT_CMD_HALT_AT_FRAME_BOUNDARY 0 10962306a36Sopenharmony_ci#define HALT_CMD_RESUME_AT_FRAME_BOUNDARY 1 11062306a36Sopenharmony_ci#define RDI_CTRL_HALT_MODE 2 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci#define CSID_RDI_FRM_DROP_PATTERN(rdi) ((IS_LITE ? 0x20C : 0x30C)\ 11362306a36Sopenharmony_ci + 0x100 * (rdi)) 11462306a36Sopenharmony_ci#define CSID_RDI_FRM_DROP_PERIOD(rdi) ((IS_LITE ? 0x210 : 0x310)\ 11562306a36Sopenharmony_ci + 0x100 * (rdi)) 11662306a36Sopenharmony_ci#define CSID_RDI_IRQ_SUBSAMPLE_PATTERN(rdi) ((IS_LITE ? 0x214 : 0x314)\ 11762306a36Sopenharmony_ci + 0x100 * (rdi)) 11862306a36Sopenharmony_ci#define CSID_RDI_IRQ_SUBSAMPLE_PERIOD(rdi) ((IS_LITE ? 0x218 : 0x318)\ 11962306a36Sopenharmony_ci + 0x100 * (rdi)) 12062306a36Sopenharmony_ci#define CSID_RDI_RPP_PIX_DROP_PATTERN(rdi) ((IS_LITE ? 0x224 : 0x324)\ 12162306a36Sopenharmony_ci + 0x100 * (rdi)) 12262306a36Sopenharmony_ci#define CSID_RDI_RPP_PIX_DROP_PERIOD(rdi) ((IS_LITE ? 0x228 : 0x328)\ 12362306a36Sopenharmony_ci + 0x100 * (rdi)) 12462306a36Sopenharmony_ci#define CSID_RDI_RPP_LINE_DROP_PATTERN(rdi) ((IS_LITE ? 0x22C : 0x32C)\ 12562306a36Sopenharmony_ci + 0x100 * (rdi)) 12662306a36Sopenharmony_ci#define CSID_RDI_RPP_LINE_DROP_PERIOD(rdi) ((IS_LITE ? 0x230 : 0x330)\ 12762306a36Sopenharmony_ci + 0x100 * (rdi)) 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci#define CSID_TPG_CTRL 0x600 13062306a36Sopenharmony_ci#define TPG_CTRL_TEST_EN 0 13162306a36Sopenharmony_ci#define TPG_CTRL_FS_PKT_EN 1 13262306a36Sopenharmony_ci#define TPG_CTRL_FE_PKT_EN 2 13362306a36Sopenharmony_ci#define TPG_CTRL_NUM_ACTIVE_LANES 4 13462306a36Sopenharmony_ci#define TPG_CTRL_CYCLES_BETWEEN_PKTS 8 13562306a36Sopenharmony_ci#define TPG_CTRL_NUM_TRAIL_BYTES 20 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci#define CSID_TPG_VC_CFG0 0x604 13862306a36Sopenharmony_ci#define TPG_VC_CFG0_VC_NUM 0 13962306a36Sopenharmony_ci#define TPG_VC_CFG0_NUM_ACTIVE_SLOTS 8 14062306a36Sopenharmony_ci#define NUM_ACTIVE_SLOTS_0_ENABLED 0 14162306a36Sopenharmony_ci#define NUM_ACTIVE_SLOTS_0_1_ENABLED 1 14262306a36Sopenharmony_ci#define NUM_ACTIVE_SLOTS_0_1_2_ENABLED 2 14362306a36Sopenharmony_ci#define NUM_ACTIVE_SLOTS_0_1_3_ENABLED 3 14462306a36Sopenharmony_ci#define TPG_VC_CFG0_LINE_INTERLEAVING_MODE 10 14562306a36Sopenharmony_ci#define INTELEAVING_MODE_INTERLEAVED 0 14662306a36Sopenharmony_ci#define INTELEAVING_MODE_ONE_SHOT 1 14762306a36Sopenharmony_ci#define TPG_VC_CFG0_NUM_FRAMES 16 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci#define CSID_TPG_VC_CFG1 0x608 15062306a36Sopenharmony_ci#define TPG_VC_CFG1_H_BLANKING_COUNT 0 15162306a36Sopenharmony_ci#define TPG_VC_CFG1_V_BLANKING_COUNT 12 15262306a36Sopenharmony_ci#define TPG_VC_CFG1_V_BLANK_FRAME_WIDTH_SEL 24 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci#define CSID_TPG_LFSR_SEED 0x60C 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci#define CSID_TPG_DT_n_CFG_0(n) (0x610 + (n) * 0xC) 15762306a36Sopenharmony_ci#define TPG_DT_n_CFG_0_FRAME_HEIGHT 0 15862306a36Sopenharmony_ci#define TPG_DT_n_CFG_0_FRAME_WIDTH 16 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci#define CSID_TPG_DT_n_CFG_1(n) (0x614 + (n) * 0xC) 16162306a36Sopenharmony_ci#define TPG_DT_n_CFG_1_DATA_TYPE 0 16262306a36Sopenharmony_ci#define TPG_DT_n_CFG_1_ECC_XOR_MASK 8 16362306a36Sopenharmony_ci#define TPG_DT_n_CFG_1_CRC_XOR_MASK 16 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci#define CSID_TPG_DT_n_CFG_2(n) (0x618 + (n) * 0xC) 16662306a36Sopenharmony_ci#define TPG_DT_n_CFG_2_PAYLOAD_MODE 0 16762306a36Sopenharmony_ci#define TPG_DT_n_CFG_2_USER_SPECIFIED_PAYLOAD 4 16862306a36Sopenharmony_ci#define TPG_DT_n_CFG_2_ENCODE_FORMAT 16 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci#define CSID_TPG_COLOR_BARS_CFG 0x640 17162306a36Sopenharmony_ci#define TPG_COLOR_BARS_CFG_UNICOLOR_BAR_EN 0 17262306a36Sopenharmony_ci#define TPG_COLOR_BARS_CFG_UNICOLOR_BAR_SEL 4 17362306a36Sopenharmony_ci#define TPG_COLOR_BARS_CFG_SPLIT_EN 5 17462306a36Sopenharmony_ci#define TPG_COLOR_BARS_CFG_ROTATE_PERIOD 8 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci#define CSID_TPG_COLOR_BOX_CFG 0x644 17762306a36Sopenharmony_ci#define TPG_COLOR_BOX_CFG_MODE 0 17862306a36Sopenharmony_ci#define TPG_COLOR_BOX_PATTERN_SEL 2 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_cistatic const struct csid_format csid_formats[] = { 18162306a36Sopenharmony_ci { 18262306a36Sopenharmony_ci MEDIA_BUS_FMT_UYVY8_2X8, 18362306a36Sopenharmony_ci DATA_TYPE_YUV422_8BIT, 18462306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_8_BIT, 18562306a36Sopenharmony_ci 8, 18662306a36Sopenharmony_ci 2, 18762306a36Sopenharmony_ci }, 18862306a36Sopenharmony_ci { 18962306a36Sopenharmony_ci MEDIA_BUS_FMT_VYUY8_2X8, 19062306a36Sopenharmony_ci DATA_TYPE_YUV422_8BIT, 19162306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_8_BIT, 19262306a36Sopenharmony_ci 8, 19362306a36Sopenharmony_ci 2, 19462306a36Sopenharmony_ci }, 19562306a36Sopenharmony_ci { 19662306a36Sopenharmony_ci MEDIA_BUS_FMT_YUYV8_2X8, 19762306a36Sopenharmony_ci DATA_TYPE_YUV422_8BIT, 19862306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_8_BIT, 19962306a36Sopenharmony_ci 8, 20062306a36Sopenharmony_ci 2, 20162306a36Sopenharmony_ci }, 20262306a36Sopenharmony_ci { 20362306a36Sopenharmony_ci MEDIA_BUS_FMT_YVYU8_2X8, 20462306a36Sopenharmony_ci DATA_TYPE_YUV422_8BIT, 20562306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_8_BIT, 20662306a36Sopenharmony_ci 8, 20762306a36Sopenharmony_ci 2, 20862306a36Sopenharmony_ci }, 20962306a36Sopenharmony_ci { 21062306a36Sopenharmony_ci MEDIA_BUS_FMT_SBGGR8_1X8, 21162306a36Sopenharmony_ci DATA_TYPE_RAW_8BIT, 21262306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_8_BIT, 21362306a36Sopenharmony_ci 8, 21462306a36Sopenharmony_ci 1, 21562306a36Sopenharmony_ci }, 21662306a36Sopenharmony_ci { 21762306a36Sopenharmony_ci MEDIA_BUS_FMT_SGBRG8_1X8, 21862306a36Sopenharmony_ci DATA_TYPE_RAW_8BIT, 21962306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_8_BIT, 22062306a36Sopenharmony_ci 8, 22162306a36Sopenharmony_ci 1, 22262306a36Sopenharmony_ci }, 22362306a36Sopenharmony_ci { 22462306a36Sopenharmony_ci MEDIA_BUS_FMT_SGRBG8_1X8, 22562306a36Sopenharmony_ci DATA_TYPE_RAW_8BIT, 22662306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_8_BIT, 22762306a36Sopenharmony_ci 8, 22862306a36Sopenharmony_ci 1, 22962306a36Sopenharmony_ci }, 23062306a36Sopenharmony_ci { 23162306a36Sopenharmony_ci MEDIA_BUS_FMT_SRGGB8_1X8, 23262306a36Sopenharmony_ci DATA_TYPE_RAW_8BIT, 23362306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_8_BIT, 23462306a36Sopenharmony_ci 8, 23562306a36Sopenharmony_ci 1, 23662306a36Sopenharmony_ci }, 23762306a36Sopenharmony_ci { 23862306a36Sopenharmony_ci MEDIA_BUS_FMT_SBGGR10_1X10, 23962306a36Sopenharmony_ci DATA_TYPE_RAW_10BIT, 24062306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_10_BIT, 24162306a36Sopenharmony_ci 10, 24262306a36Sopenharmony_ci 1, 24362306a36Sopenharmony_ci }, 24462306a36Sopenharmony_ci { 24562306a36Sopenharmony_ci MEDIA_BUS_FMT_SGBRG10_1X10, 24662306a36Sopenharmony_ci DATA_TYPE_RAW_10BIT, 24762306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_10_BIT, 24862306a36Sopenharmony_ci 10, 24962306a36Sopenharmony_ci 1, 25062306a36Sopenharmony_ci }, 25162306a36Sopenharmony_ci { 25262306a36Sopenharmony_ci MEDIA_BUS_FMT_SGRBG10_1X10, 25362306a36Sopenharmony_ci DATA_TYPE_RAW_10BIT, 25462306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_10_BIT, 25562306a36Sopenharmony_ci 10, 25662306a36Sopenharmony_ci 1, 25762306a36Sopenharmony_ci }, 25862306a36Sopenharmony_ci { 25962306a36Sopenharmony_ci MEDIA_BUS_FMT_SRGGB10_1X10, 26062306a36Sopenharmony_ci DATA_TYPE_RAW_10BIT, 26162306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_10_BIT, 26262306a36Sopenharmony_ci 10, 26362306a36Sopenharmony_ci 1, 26462306a36Sopenharmony_ci }, 26562306a36Sopenharmony_ci { 26662306a36Sopenharmony_ci MEDIA_BUS_FMT_Y8_1X8, 26762306a36Sopenharmony_ci DATA_TYPE_RAW_8BIT, 26862306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_8_BIT, 26962306a36Sopenharmony_ci 8, 27062306a36Sopenharmony_ci 1, 27162306a36Sopenharmony_ci }, 27262306a36Sopenharmony_ci { 27362306a36Sopenharmony_ci MEDIA_BUS_FMT_Y10_1X10, 27462306a36Sopenharmony_ci DATA_TYPE_RAW_10BIT, 27562306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_10_BIT, 27662306a36Sopenharmony_ci 10, 27762306a36Sopenharmony_ci 1, 27862306a36Sopenharmony_ci }, 27962306a36Sopenharmony_ci { 28062306a36Sopenharmony_ci MEDIA_BUS_FMT_SBGGR12_1X12, 28162306a36Sopenharmony_ci DATA_TYPE_RAW_12BIT, 28262306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_12_BIT, 28362306a36Sopenharmony_ci 12, 28462306a36Sopenharmony_ci 1, 28562306a36Sopenharmony_ci }, 28662306a36Sopenharmony_ci { 28762306a36Sopenharmony_ci MEDIA_BUS_FMT_SGBRG12_1X12, 28862306a36Sopenharmony_ci DATA_TYPE_RAW_12BIT, 28962306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_12_BIT, 29062306a36Sopenharmony_ci 12, 29162306a36Sopenharmony_ci 1, 29262306a36Sopenharmony_ci }, 29362306a36Sopenharmony_ci { 29462306a36Sopenharmony_ci MEDIA_BUS_FMT_SGRBG12_1X12, 29562306a36Sopenharmony_ci DATA_TYPE_RAW_12BIT, 29662306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_12_BIT, 29762306a36Sopenharmony_ci 12, 29862306a36Sopenharmony_ci 1, 29962306a36Sopenharmony_ci }, 30062306a36Sopenharmony_ci { 30162306a36Sopenharmony_ci MEDIA_BUS_FMT_SRGGB12_1X12, 30262306a36Sopenharmony_ci DATA_TYPE_RAW_12BIT, 30362306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_12_BIT, 30462306a36Sopenharmony_ci 12, 30562306a36Sopenharmony_ci 1, 30662306a36Sopenharmony_ci }, 30762306a36Sopenharmony_ci { 30862306a36Sopenharmony_ci MEDIA_BUS_FMT_SBGGR14_1X14, 30962306a36Sopenharmony_ci DATA_TYPE_RAW_14BIT, 31062306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_14_BIT, 31162306a36Sopenharmony_ci 14, 31262306a36Sopenharmony_ci 1, 31362306a36Sopenharmony_ci }, 31462306a36Sopenharmony_ci { 31562306a36Sopenharmony_ci MEDIA_BUS_FMT_SGBRG14_1X14, 31662306a36Sopenharmony_ci DATA_TYPE_RAW_14BIT, 31762306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_14_BIT, 31862306a36Sopenharmony_ci 14, 31962306a36Sopenharmony_ci 1, 32062306a36Sopenharmony_ci }, 32162306a36Sopenharmony_ci { 32262306a36Sopenharmony_ci MEDIA_BUS_FMT_SGRBG14_1X14, 32362306a36Sopenharmony_ci DATA_TYPE_RAW_14BIT, 32462306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_14_BIT, 32562306a36Sopenharmony_ci 14, 32662306a36Sopenharmony_ci 1, 32762306a36Sopenharmony_ci }, 32862306a36Sopenharmony_ci { 32962306a36Sopenharmony_ci MEDIA_BUS_FMT_SRGGB14_1X14, 33062306a36Sopenharmony_ci DATA_TYPE_RAW_14BIT, 33162306a36Sopenharmony_ci DECODE_FORMAT_UNCOMPRESSED_14_BIT, 33262306a36Sopenharmony_ci 14, 33362306a36Sopenharmony_ci 1, 33462306a36Sopenharmony_ci }, 33562306a36Sopenharmony_ci}; 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_cistatic void __csid_configure_stream(struct csid_device *csid, u8 enable, u8 vc) 33862306a36Sopenharmony_ci{ 33962306a36Sopenharmony_ci struct csid_testgen_config *tg = &csid->testgen; 34062306a36Sopenharmony_ci u32 val; 34162306a36Sopenharmony_ci u32 phy_sel = 0; 34262306a36Sopenharmony_ci u8 lane_cnt = csid->phy.lane_cnt; 34362306a36Sopenharmony_ci /* Source pads matching RDI channels on hardware. Pad 1 -> RDI0, Pad 2 -> RDI1, etc. */ 34462306a36Sopenharmony_ci struct v4l2_mbus_framefmt *input_format = &csid->fmt[MSM_CSID_PAD_FIRST_SRC + vc]; 34562306a36Sopenharmony_ci const struct csid_format *format = csid_get_fmt_entry(csid->formats, csid->nformats, 34662306a36Sopenharmony_ci input_format->code); 34762306a36Sopenharmony_ci 34862306a36Sopenharmony_ci if (!lane_cnt) 34962306a36Sopenharmony_ci lane_cnt = 4; 35062306a36Sopenharmony_ci 35162306a36Sopenharmony_ci if (!tg->enabled) 35262306a36Sopenharmony_ci phy_sel = csid->phy.csiphy_id; 35362306a36Sopenharmony_ci 35462306a36Sopenharmony_ci if (enable) { 35562306a36Sopenharmony_ci /* 35662306a36Sopenharmony_ci * DT_ID is a two bit bitfield that is concatenated with 35762306a36Sopenharmony_ci * the four least significant bits of the five bit VC 35862306a36Sopenharmony_ci * bitfield to generate an internal CID value. 35962306a36Sopenharmony_ci * 36062306a36Sopenharmony_ci * CSID_RDI_CFG0(vc) 36162306a36Sopenharmony_ci * DT_ID : 28:27 36262306a36Sopenharmony_ci * VC : 26:22 36362306a36Sopenharmony_ci * DT : 21:16 36462306a36Sopenharmony_ci * 36562306a36Sopenharmony_ci * CID : VC 3:0 << 2 | DT_ID 1:0 36662306a36Sopenharmony_ci */ 36762306a36Sopenharmony_ci u8 dt_id = vc & 0x03; 36862306a36Sopenharmony_ci 36962306a36Sopenharmony_ci if (tg->enabled) { 37062306a36Sopenharmony_ci /* configure one DT, infinite frames */ 37162306a36Sopenharmony_ci val = vc << TPG_VC_CFG0_VC_NUM; 37262306a36Sopenharmony_ci val |= INTELEAVING_MODE_ONE_SHOT << TPG_VC_CFG0_LINE_INTERLEAVING_MODE; 37362306a36Sopenharmony_ci val |= 0 << TPG_VC_CFG0_NUM_FRAMES; 37462306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_TPG_VC_CFG0); 37562306a36Sopenharmony_ci 37662306a36Sopenharmony_ci val = 0x740 << TPG_VC_CFG1_H_BLANKING_COUNT; 37762306a36Sopenharmony_ci val |= 0x3ff << TPG_VC_CFG1_V_BLANKING_COUNT; 37862306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_TPG_VC_CFG1); 37962306a36Sopenharmony_ci 38062306a36Sopenharmony_ci writel_relaxed(0x12345678, csid->base + CSID_TPG_LFSR_SEED); 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_ci val = (input_format->height & 0x1fff) << TPG_DT_n_CFG_0_FRAME_HEIGHT; 38362306a36Sopenharmony_ci val |= (input_format->width & 0x1fff) << TPG_DT_n_CFG_0_FRAME_WIDTH; 38462306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_TPG_DT_n_CFG_0(0)); 38562306a36Sopenharmony_ci 38662306a36Sopenharmony_ci val = format->data_type << TPG_DT_n_CFG_1_DATA_TYPE; 38762306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_TPG_DT_n_CFG_1(0)); 38862306a36Sopenharmony_ci 38962306a36Sopenharmony_ci val = (tg->mode - 1) << TPG_DT_n_CFG_2_PAYLOAD_MODE; 39062306a36Sopenharmony_ci val |= 0xBE << TPG_DT_n_CFG_2_USER_SPECIFIED_PAYLOAD; 39162306a36Sopenharmony_ci val |= format->decode_format << TPG_DT_n_CFG_2_ENCODE_FORMAT; 39262306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_TPG_DT_n_CFG_2(0)); 39362306a36Sopenharmony_ci 39462306a36Sopenharmony_ci writel_relaxed(0, csid->base + CSID_TPG_COLOR_BARS_CFG); 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_ci writel_relaxed(0, csid->base + CSID_TPG_COLOR_BOX_CFG); 39762306a36Sopenharmony_ci } 39862306a36Sopenharmony_ci 39962306a36Sopenharmony_ci val = 1 << RDI_CFG0_BYTE_CNTR_EN; 40062306a36Sopenharmony_ci val |= 1 << RDI_CFG0_FORMAT_MEASURE_EN; 40162306a36Sopenharmony_ci val |= 1 << RDI_CFG0_TIMESTAMP_EN; 40262306a36Sopenharmony_ci /* note: for non-RDI path, this should be format->decode_format */ 40362306a36Sopenharmony_ci val |= DECODE_FORMAT_PAYLOAD_ONLY << RDI_CFG0_DECODE_FORMAT; 40462306a36Sopenharmony_ci val |= format->data_type << RDI_CFG0_DATA_TYPE; 40562306a36Sopenharmony_ci val |= vc << RDI_CFG0_VIRTUAL_CHANNEL; 40662306a36Sopenharmony_ci val |= dt_id << RDI_CFG0_DT_ID; 40762306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RDI_CFG0(vc)); 40862306a36Sopenharmony_ci 40962306a36Sopenharmony_ci /* CSID_TIMESTAMP_STB_POST_IRQ */ 41062306a36Sopenharmony_ci val = 2 << RDI_CFG1_TIMESTAMP_STB_SEL; 41162306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RDI_CFG1(vc)); 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_ci val = 1; 41462306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RDI_FRM_DROP_PERIOD(vc)); 41562306a36Sopenharmony_ci 41662306a36Sopenharmony_ci val = 0; 41762306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RDI_FRM_DROP_PATTERN(vc)); 41862306a36Sopenharmony_ci 41962306a36Sopenharmony_ci val = 1; 42062306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RDI_IRQ_SUBSAMPLE_PERIOD(vc)); 42162306a36Sopenharmony_ci 42262306a36Sopenharmony_ci val = 0; 42362306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RDI_IRQ_SUBSAMPLE_PATTERN(vc)); 42462306a36Sopenharmony_ci 42562306a36Sopenharmony_ci val = 1; 42662306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RDI_RPP_PIX_DROP_PERIOD(vc)); 42762306a36Sopenharmony_ci 42862306a36Sopenharmony_ci val = 0; 42962306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RDI_RPP_PIX_DROP_PATTERN(vc)); 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_ci val = 1; 43262306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RDI_RPP_LINE_DROP_PERIOD(vc)); 43362306a36Sopenharmony_ci 43462306a36Sopenharmony_ci val = 0; 43562306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RDI_RPP_LINE_DROP_PATTERN(vc)); 43662306a36Sopenharmony_ci 43762306a36Sopenharmony_ci val = 0; 43862306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RDI_CTRL(vc)); 43962306a36Sopenharmony_ci 44062306a36Sopenharmony_ci val = readl_relaxed(csid->base + CSID_RDI_CFG0(vc)); 44162306a36Sopenharmony_ci val |= 1 << RDI_CFG0_ENABLE; 44262306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RDI_CFG0(vc)); 44362306a36Sopenharmony_ci } 44462306a36Sopenharmony_ci 44562306a36Sopenharmony_ci if (tg->enabled) { 44662306a36Sopenharmony_ci val = enable << TPG_CTRL_TEST_EN; 44762306a36Sopenharmony_ci val |= 1 << TPG_CTRL_FS_PKT_EN; 44862306a36Sopenharmony_ci val |= 1 << TPG_CTRL_FE_PKT_EN; 44962306a36Sopenharmony_ci val |= (lane_cnt - 1) << TPG_CTRL_NUM_ACTIVE_LANES; 45062306a36Sopenharmony_ci val |= 0x64 << TPG_CTRL_CYCLES_BETWEEN_PKTS; 45162306a36Sopenharmony_ci val |= 0xA << TPG_CTRL_NUM_TRAIL_BYTES; 45262306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_TPG_CTRL); 45362306a36Sopenharmony_ci } 45462306a36Sopenharmony_ci 45562306a36Sopenharmony_ci val = (lane_cnt - 1) << CSI2_RX_CFG0_NUM_ACTIVE_LANES; 45662306a36Sopenharmony_ci val |= csid->phy.lane_assign << CSI2_RX_CFG0_DL0_INPUT_SEL; 45762306a36Sopenharmony_ci val |= phy_sel << CSI2_RX_CFG0_PHY_NUM_SEL; 45862306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_CSI2_RX_CFG0); 45962306a36Sopenharmony_ci 46062306a36Sopenharmony_ci val = 1 << CSI2_RX_CFG1_PACKET_ECC_CORRECTION_EN; 46162306a36Sopenharmony_ci if (vc > 3) 46262306a36Sopenharmony_ci val |= 1 << CSI2_RX_CFG1_VC_MODE; 46362306a36Sopenharmony_ci val |= 1 << CSI2_RX_CFG1_MISR_EN; 46462306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_CSI2_RX_CFG1); 46562306a36Sopenharmony_ci 46662306a36Sopenharmony_ci if (enable) 46762306a36Sopenharmony_ci val = HALT_CMD_RESUME_AT_FRAME_BOUNDARY << RDI_CTRL_HALT_CMD; 46862306a36Sopenharmony_ci else 46962306a36Sopenharmony_ci val = HALT_CMD_HALT_AT_FRAME_BOUNDARY << RDI_CTRL_HALT_CMD; 47062306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RDI_CTRL(vc)); 47162306a36Sopenharmony_ci} 47262306a36Sopenharmony_ci 47362306a36Sopenharmony_cistatic void csid_configure_stream(struct csid_device *csid, u8 enable) 47462306a36Sopenharmony_ci{ 47562306a36Sopenharmony_ci u8 i; 47662306a36Sopenharmony_ci /* Loop through all enabled VCs and configure stream for each */ 47762306a36Sopenharmony_ci for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++) 47862306a36Sopenharmony_ci if (csid->phy.en_vc & BIT(i)) 47962306a36Sopenharmony_ci __csid_configure_stream(csid, enable, i); 48062306a36Sopenharmony_ci} 48162306a36Sopenharmony_ci 48262306a36Sopenharmony_cistatic int csid_configure_testgen_pattern(struct csid_device *csid, s32 val) 48362306a36Sopenharmony_ci{ 48462306a36Sopenharmony_ci if (val > 0 && val <= csid->testgen.nmodes) 48562306a36Sopenharmony_ci csid->testgen.mode = val; 48662306a36Sopenharmony_ci 48762306a36Sopenharmony_ci return 0; 48862306a36Sopenharmony_ci} 48962306a36Sopenharmony_ci 49062306a36Sopenharmony_ci/* 49162306a36Sopenharmony_ci * csid_hw_version - CSID hardware version query 49262306a36Sopenharmony_ci * @csid: CSID device 49362306a36Sopenharmony_ci * 49462306a36Sopenharmony_ci * Return HW version or error 49562306a36Sopenharmony_ci */ 49662306a36Sopenharmony_cistatic u32 csid_hw_version(struct csid_device *csid) 49762306a36Sopenharmony_ci{ 49862306a36Sopenharmony_ci u32 hw_version; 49962306a36Sopenharmony_ci u32 hw_gen; 50062306a36Sopenharmony_ci u32 hw_rev; 50162306a36Sopenharmony_ci u32 hw_step; 50262306a36Sopenharmony_ci 50362306a36Sopenharmony_ci hw_version = readl_relaxed(csid->base + CSID_HW_VERSION); 50462306a36Sopenharmony_ci hw_gen = (hw_version >> HW_VERSION_GENERATION) & 0xF; 50562306a36Sopenharmony_ci hw_rev = (hw_version >> HW_VERSION_REVISION) & 0xFFF; 50662306a36Sopenharmony_ci hw_step = (hw_version >> HW_VERSION_STEPPING) & 0xFFFF; 50762306a36Sopenharmony_ci dev_dbg(csid->camss->dev, "CSID HW Version = %u.%u.%u\n", 50862306a36Sopenharmony_ci hw_gen, hw_rev, hw_step); 50962306a36Sopenharmony_ci 51062306a36Sopenharmony_ci return hw_version; 51162306a36Sopenharmony_ci} 51262306a36Sopenharmony_ci 51362306a36Sopenharmony_ci/* 51462306a36Sopenharmony_ci * csid_isr - CSID module interrupt service routine 51562306a36Sopenharmony_ci * @irq: Interrupt line 51662306a36Sopenharmony_ci * @dev: CSID device 51762306a36Sopenharmony_ci * 51862306a36Sopenharmony_ci * Return IRQ_HANDLED on success 51962306a36Sopenharmony_ci */ 52062306a36Sopenharmony_cistatic irqreturn_t csid_isr(int irq, void *dev) 52162306a36Sopenharmony_ci{ 52262306a36Sopenharmony_ci struct csid_device *csid = dev; 52362306a36Sopenharmony_ci u32 val; 52462306a36Sopenharmony_ci u8 reset_done; 52562306a36Sopenharmony_ci int i; 52662306a36Sopenharmony_ci 52762306a36Sopenharmony_ci val = readl_relaxed(csid->base + CSID_TOP_IRQ_STATUS); 52862306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_TOP_IRQ_CLEAR); 52962306a36Sopenharmony_ci reset_done = val & BIT(TOP_IRQ_STATUS_RESET_DONE); 53062306a36Sopenharmony_ci 53162306a36Sopenharmony_ci val = readl_relaxed(csid->base + CSID_CSI2_RX_IRQ_STATUS); 53262306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_CSI2_RX_IRQ_CLEAR); 53362306a36Sopenharmony_ci 53462306a36Sopenharmony_ci /* Read and clear IRQ status for each enabled RDI channel */ 53562306a36Sopenharmony_ci for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++) 53662306a36Sopenharmony_ci if (csid->phy.en_vc & BIT(i)) { 53762306a36Sopenharmony_ci val = readl_relaxed(csid->base + CSID_CSI2_RDIN_IRQ_STATUS(i)); 53862306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_CSI2_RDIN_IRQ_CLEAR(i)); 53962306a36Sopenharmony_ci } 54062306a36Sopenharmony_ci 54162306a36Sopenharmony_ci val = 1 << IRQ_CMD_CLEAR; 54262306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_IRQ_CMD); 54362306a36Sopenharmony_ci 54462306a36Sopenharmony_ci if (reset_done) 54562306a36Sopenharmony_ci complete(&csid->reset_complete); 54662306a36Sopenharmony_ci 54762306a36Sopenharmony_ci return IRQ_HANDLED; 54862306a36Sopenharmony_ci} 54962306a36Sopenharmony_ci 55062306a36Sopenharmony_ci/* 55162306a36Sopenharmony_ci * csid_reset - Trigger reset on CSID module and wait to complete 55262306a36Sopenharmony_ci * @csid: CSID device 55362306a36Sopenharmony_ci * 55462306a36Sopenharmony_ci * Return 0 on success or a negative error code otherwise 55562306a36Sopenharmony_ci */ 55662306a36Sopenharmony_cistatic int csid_reset(struct csid_device *csid) 55762306a36Sopenharmony_ci{ 55862306a36Sopenharmony_ci unsigned long time; 55962306a36Sopenharmony_ci u32 val; 56062306a36Sopenharmony_ci 56162306a36Sopenharmony_ci reinit_completion(&csid->reset_complete); 56262306a36Sopenharmony_ci 56362306a36Sopenharmony_ci writel_relaxed(1, csid->base + CSID_TOP_IRQ_CLEAR); 56462306a36Sopenharmony_ci writel_relaxed(1, csid->base + CSID_IRQ_CMD); 56562306a36Sopenharmony_ci writel_relaxed(1, csid->base + CSID_TOP_IRQ_MASK); 56662306a36Sopenharmony_ci writel_relaxed(1, csid->base + CSID_IRQ_CMD); 56762306a36Sopenharmony_ci 56862306a36Sopenharmony_ci /* preserve registers */ 56962306a36Sopenharmony_ci val = 0x1e << RST_STROBES; 57062306a36Sopenharmony_ci writel_relaxed(val, csid->base + CSID_RST_STROBES); 57162306a36Sopenharmony_ci 57262306a36Sopenharmony_ci time = wait_for_completion_timeout(&csid->reset_complete, 57362306a36Sopenharmony_ci msecs_to_jiffies(CSID_RESET_TIMEOUT_MS)); 57462306a36Sopenharmony_ci if (!time) { 57562306a36Sopenharmony_ci dev_err(csid->camss->dev, "CSID reset timeout\n"); 57662306a36Sopenharmony_ci return -EIO; 57762306a36Sopenharmony_ci } 57862306a36Sopenharmony_ci 57962306a36Sopenharmony_ci return 0; 58062306a36Sopenharmony_ci} 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_cistatic u32 csid_src_pad_code(struct csid_device *csid, u32 sink_code, 58362306a36Sopenharmony_ci unsigned int match_format_idx, u32 match_code) 58462306a36Sopenharmony_ci{ 58562306a36Sopenharmony_ci switch (sink_code) { 58662306a36Sopenharmony_ci case MEDIA_BUS_FMT_SBGGR10_1X10: 58762306a36Sopenharmony_ci { 58862306a36Sopenharmony_ci u32 src_code[] = { 58962306a36Sopenharmony_ci MEDIA_BUS_FMT_SBGGR10_1X10, 59062306a36Sopenharmony_ci MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, 59162306a36Sopenharmony_ci }; 59262306a36Sopenharmony_ci 59362306a36Sopenharmony_ci return csid_find_code(src_code, ARRAY_SIZE(src_code), 59462306a36Sopenharmony_ci match_format_idx, match_code); 59562306a36Sopenharmony_ci } 59662306a36Sopenharmony_ci case MEDIA_BUS_FMT_Y10_1X10: 59762306a36Sopenharmony_ci { 59862306a36Sopenharmony_ci u32 src_code[] = { 59962306a36Sopenharmony_ci MEDIA_BUS_FMT_Y10_1X10, 60062306a36Sopenharmony_ci MEDIA_BUS_FMT_Y10_2X8_PADHI_LE, 60162306a36Sopenharmony_ci }; 60262306a36Sopenharmony_ci 60362306a36Sopenharmony_ci return csid_find_code(src_code, ARRAY_SIZE(src_code), 60462306a36Sopenharmony_ci match_format_idx, match_code); 60562306a36Sopenharmony_ci } 60662306a36Sopenharmony_ci default: 60762306a36Sopenharmony_ci if (match_format_idx > 0) 60862306a36Sopenharmony_ci return 0; 60962306a36Sopenharmony_ci 61062306a36Sopenharmony_ci return sink_code; 61162306a36Sopenharmony_ci } 61262306a36Sopenharmony_ci} 61362306a36Sopenharmony_ci 61462306a36Sopenharmony_cistatic void csid_subdev_init(struct csid_device *csid) 61562306a36Sopenharmony_ci{ 61662306a36Sopenharmony_ci csid->formats = csid_formats; 61762306a36Sopenharmony_ci csid->nformats = ARRAY_SIZE(csid_formats); 61862306a36Sopenharmony_ci csid->testgen.modes = csid_testgen_modes; 61962306a36Sopenharmony_ci csid->testgen.nmodes = CSID_PAYLOAD_MODE_NUM_SUPPORTED_GEN2; 62062306a36Sopenharmony_ci} 62162306a36Sopenharmony_ci 62262306a36Sopenharmony_ciconst struct csid_hw_ops csid_ops_gen2 = { 62362306a36Sopenharmony_ci .configure_stream = csid_configure_stream, 62462306a36Sopenharmony_ci .configure_testgen_pattern = csid_configure_testgen_pattern, 62562306a36Sopenharmony_ci .hw_version = csid_hw_version, 62662306a36Sopenharmony_ci .isr = csid_isr, 62762306a36Sopenharmony_ci .reset = csid_reset, 62862306a36Sopenharmony_ci .src_pad_code = csid_src_pad_code, 62962306a36Sopenharmony_ci .subdev_init = csid_subdev_init, 63062306a36Sopenharmony_ci}; 631