18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * camss-vfe-4-7.c 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Qualcomm MSM Camera Subsystem - VFE (Video Front End) Module v4.7 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. 88c2ecf20Sopenharmony_ci * Copyright (C) 2015-2018 Linaro Ltd. 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 128c2ecf20Sopenharmony_ci#include <linux/io.h> 138c2ecf20Sopenharmony_ci#include <linux/iopoll.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include "camss-vfe.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define VFE_0_HW_VERSION 0x000 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define VFE_0_GLOBAL_RESET_CMD 0x018 208c2ecf20Sopenharmony_ci#define VFE_0_GLOBAL_RESET_CMD_CORE BIT(0) 218c2ecf20Sopenharmony_ci#define VFE_0_GLOBAL_RESET_CMD_CAMIF BIT(1) 228c2ecf20Sopenharmony_ci#define VFE_0_GLOBAL_RESET_CMD_BUS BIT(2) 238c2ecf20Sopenharmony_ci#define VFE_0_GLOBAL_RESET_CMD_BUS_BDG BIT(3) 248c2ecf20Sopenharmony_ci#define VFE_0_GLOBAL_RESET_CMD_REGISTER BIT(4) 258c2ecf20Sopenharmony_ci#define VFE_0_GLOBAL_RESET_CMD_PM BIT(5) 268c2ecf20Sopenharmony_ci#define VFE_0_GLOBAL_RESET_CMD_BUS_MISR BIT(6) 278c2ecf20Sopenharmony_ci#define VFE_0_GLOBAL_RESET_CMD_TESTGEN BIT(7) 288c2ecf20Sopenharmony_ci#define VFE_0_GLOBAL_RESET_CMD_DSP BIT(8) 298c2ecf20Sopenharmony_ci#define VFE_0_GLOBAL_RESET_CMD_IDLE_CGC BIT(9) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define VFE_0_MODULE_LENS_EN 0x040 328c2ecf20Sopenharmony_ci#define VFE_0_MODULE_LENS_EN_DEMUX BIT(2) 338c2ecf20Sopenharmony_ci#define VFE_0_MODULE_LENS_EN_CHROMA_UPSAMPLE BIT(3) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define VFE_0_MODULE_ZOOM_EN 0x04c 368c2ecf20Sopenharmony_ci#define VFE_0_MODULE_ZOOM_EN_SCALE_ENC BIT(1) 378c2ecf20Sopenharmony_ci#define VFE_0_MODULE_ZOOM_EN_CROP_ENC BIT(2) 388c2ecf20Sopenharmony_ci#define VFE_0_MODULE_ZOOM_EN_REALIGN_BUF BIT(9) 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#define VFE_0_CORE_CFG 0x050 418c2ecf20Sopenharmony_ci#define VFE_0_CORE_CFG_PIXEL_PATTERN_YCBYCR 0x4 428c2ecf20Sopenharmony_ci#define VFE_0_CORE_CFG_PIXEL_PATTERN_YCRYCB 0x5 438c2ecf20Sopenharmony_ci#define VFE_0_CORE_CFG_PIXEL_PATTERN_CBYCRY 0x6 448c2ecf20Sopenharmony_ci#define VFE_0_CORE_CFG_PIXEL_PATTERN_CRYCBY 0x7 458c2ecf20Sopenharmony_ci#define VFE_0_CORE_CFG_COMPOSITE_REG_UPDATE_EN BIT(4) 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define VFE_0_IRQ_CMD 0x058 488c2ecf20Sopenharmony_ci#define VFE_0_IRQ_CMD_GLOBAL_CLEAR BIT(0) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_0 0x05c 518c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_0_CAMIF_SOF BIT(0) 528c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_0_CAMIF_EOF BIT(1) 538c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_0_RDIn_REG_UPDATE(n) BIT((n) + 5) 548c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_0_line_n_REG_UPDATE(n) \ 558c2ecf20Sopenharmony_ci ((n) == VFE_LINE_PIX ? BIT(4) : VFE_0_IRQ_MASK_0_RDIn_REG_UPDATE(n)) 568c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_0_IMAGE_MASTER_n_PING_PONG(n) BIT((n) + 8) 578c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_0_IMAGE_COMPOSITE_DONE_n(n) BIT((n) + 25) 588c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_0_RESET_ACK BIT(31) 598c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_1 0x060 608c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_1_CAMIF_ERROR BIT(0) 618c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_1_VIOLATION BIT(7) 628c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_1_BUS_BDG_HALT_ACK BIT(8) 638c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_1_IMAGE_MASTER_n_BUS_OVERFLOW(n) BIT((n) + 9) 648c2ecf20Sopenharmony_ci#define VFE_0_IRQ_MASK_1_RDIn_SOF(n) BIT((n) + 29) 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci#define VFE_0_IRQ_CLEAR_0 0x064 678c2ecf20Sopenharmony_ci#define VFE_0_IRQ_CLEAR_1 0x068 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#define VFE_0_IRQ_STATUS_0 0x06c 708c2ecf20Sopenharmony_ci#define VFE_0_IRQ_STATUS_0_CAMIF_SOF BIT(0) 718c2ecf20Sopenharmony_ci#define VFE_0_IRQ_STATUS_0_RDIn_REG_UPDATE(n) BIT((n) + 5) 728c2ecf20Sopenharmony_ci#define VFE_0_IRQ_STATUS_0_line_n_REG_UPDATE(n) \ 738c2ecf20Sopenharmony_ci ((n) == VFE_LINE_PIX ? BIT(4) : VFE_0_IRQ_STATUS_0_RDIn_REG_UPDATE(n)) 748c2ecf20Sopenharmony_ci#define VFE_0_IRQ_STATUS_0_IMAGE_MASTER_n_PING_PONG(n) BIT((n) + 8) 758c2ecf20Sopenharmony_ci#define VFE_0_IRQ_STATUS_0_IMAGE_COMPOSITE_DONE_n(n) BIT((n) + 25) 768c2ecf20Sopenharmony_ci#define VFE_0_IRQ_STATUS_0_RESET_ACK BIT(31) 778c2ecf20Sopenharmony_ci#define VFE_0_IRQ_STATUS_1 0x070 788c2ecf20Sopenharmony_ci#define VFE_0_IRQ_STATUS_1_VIOLATION BIT(7) 798c2ecf20Sopenharmony_ci#define VFE_0_IRQ_STATUS_1_BUS_BDG_HALT_ACK BIT(8) 808c2ecf20Sopenharmony_ci#define VFE_0_IRQ_STATUS_1_RDIn_SOF(n) BIT((n) + 29) 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci#define VFE_0_IRQ_COMPOSITE_MASK_0 0x074 838c2ecf20Sopenharmony_ci#define VFE_0_VIOLATION_STATUS 0x07c 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define VFE_0_BUS_CMD 0x80 868c2ecf20Sopenharmony_ci#define VFE_0_BUS_CMD_Mx_RLD_CMD(x) BIT(x) 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci#define VFE_0_BUS_CFG 0x084 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#define VFE_0_BUS_XBAR_CFG_x(x) (0x90 + 0x4 * ((x) / 2)) 918c2ecf20Sopenharmony_ci#define VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_EN BIT(2) 928c2ecf20Sopenharmony_ci#define VFE_0_BUS_XBAR_CFG_x_M_REALIGN_BUF_EN BIT(3) 938c2ecf20Sopenharmony_ci#define VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_SWAP_INTRA (0x1 << 4) 948c2ecf20Sopenharmony_ci#define VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_SWAP_INTER (0x2 << 4) 958c2ecf20Sopenharmony_ci#define VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_SWAP_INTER_INTRA (0x3 << 4) 968c2ecf20Sopenharmony_ci#define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_SHIFT 8 978c2ecf20Sopenharmony_ci#define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_LUMA 0x0 988c2ecf20Sopenharmony_ci#define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_VAL_RDI0 0xc 998c2ecf20Sopenharmony_ci#define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_VAL_RDI1 0xd 1008c2ecf20Sopenharmony_ci#define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_VAL_RDI2 0xe 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_CFG(n) (0x0a0 + 0x2c * (n)) 1038c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_CFG_WR_PATH_SHIFT 0 1048c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_PING_ADDR(n) (0x0a4 + 0x2c * (n)) 1058c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_PONG_ADDR(n) (0x0ac + 0x2c * (n)) 1068c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG(n) (0x0b4 + 0x2c * (n)) 1078c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG_FRM_BASED_SHIFT 1 1088c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG_FRM_DROP_PER_SHIFT 2 1098c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG_FRM_DROP_PER_MASK (0x1f << 2) 1108c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_UB_CFG(n) (0x0b8 + 0x2c * (n)) 1118c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_UB_CFG_OFFSET_SHIFT 16 1128c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_IMAGE_SIZE(n) (0x0bc + 0x2c * (n)) 1138c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_BUFFER_CFG(n) (0x0c0 + 0x2c * (n)) 1148c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_FRAMEDROP_PATTERN(n) \ 1158c2ecf20Sopenharmony_ci (0x0c4 + 0x2c * (n)) 1168c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_IRQ_SUBSAMPLE_PATTERN(n) \ 1178c2ecf20Sopenharmony_ci (0x0c8 + 0x2c * (n)) 1188c2ecf20Sopenharmony_ci#define VFE_0_BUS_IMAGE_MASTER_n_WR_IRQ_SUBSAMPLE_PATTERN_DEF 0xffffffff 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci#define VFE_0_BUS_PING_PONG_STATUS 0x338 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_CMD 0x400 1238c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_CMD_HALT_REQ 1 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_QOS_CFG_0 0x404 1268c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_QOS_CFG_0_CFG 0xaaa9aaa9 1278c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_QOS_CFG_1 0x408 1288c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_QOS_CFG_2 0x40c 1298c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_QOS_CFG_3 0x410 1308c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_QOS_CFG_4 0x414 1318c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_QOS_CFG_5 0x418 1328c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_QOS_CFG_6 0x41c 1338c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_QOS_CFG_7 0x420 1348c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_QOS_CFG_7_CFG 0x0001aaa9 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_0 0x424 1378c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_0_CFG 0xcccc0011 1388c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_1 0x428 1398c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_2 0x42c 1408c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_3 0x430 1418c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_4 0x434 1428c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_5 0x438 1438c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_6 0x43c 1448c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_7 0x440 1458c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_8 0x444 1468c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_9 0x448 1478c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_10 0x44c 1488c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_11 0x450 1498c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_12 0x454 1508c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_13 0x458 1518c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_14 0x45c 1528c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_15 0x460 1538c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_16 0x464 1548c2ecf20Sopenharmony_ci#define VFE_0_BUS_BDG_DS_CFG_16_CFG 0x40000103 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci#define VFE_0_RDI_CFG_x(x) (0x46c + (0x4 * (x))) 1578c2ecf20Sopenharmony_ci#define VFE_0_RDI_CFG_x_RDI_STREAM_SEL_SHIFT 28 1588c2ecf20Sopenharmony_ci#define VFE_0_RDI_CFG_x_RDI_STREAM_SEL_MASK (0xf << 28) 1598c2ecf20Sopenharmony_ci#define VFE_0_RDI_CFG_x_RDI_M0_SEL_SHIFT 4 1608c2ecf20Sopenharmony_ci#define VFE_0_RDI_CFG_x_RDI_M0_SEL_MASK (0xf << 4) 1618c2ecf20Sopenharmony_ci#define VFE_0_RDI_CFG_x_RDI_EN_BIT BIT(2) 1628c2ecf20Sopenharmony_ci#define VFE_0_RDI_CFG_x_MIPI_EN_BITS 0x3 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_CMD 0x478 1658c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_CMD_DISABLE_FRAME_BOUNDARY 0 1668c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_CMD_ENABLE_FRAME_BOUNDARY 1 1678c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_CMD_NO_CHANGE 3 1688c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_CMD_CLEAR_CAMIF_STATUS BIT(2) 1698c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_CFG 0x47c 1708c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_CFG_VFE_OUTPUT_EN BIT(6) 1718c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_FRAME_CFG 0x484 1728c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_WINDOW_WIDTH_CFG 0x488 1738c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_WINDOW_HEIGHT_CFG 0x48c 1748c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_SUBSAMPLE_CFG 0x490 1758c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_IRQ_FRAMEDROP_PATTERN 0x498 1768c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_IRQ_SUBSAMPLE_PATTERN 0x49c 1778c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_STATUS 0x4a4 1788c2ecf20Sopenharmony_ci#define VFE_0_CAMIF_STATUS_HALT BIT(31) 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci#define VFE_0_REG_UPDATE 0x4ac 1818c2ecf20Sopenharmony_ci#define VFE_0_REG_UPDATE_RDIn(n) BIT(1 + (n)) 1828c2ecf20Sopenharmony_ci#define VFE_0_REG_UPDATE_line_n(n) \ 1838c2ecf20Sopenharmony_ci ((n) == VFE_LINE_PIX ? 1 : VFE_0_REG_UPDATE_RDIn(n)) 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_CFG 0x560 1868c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_CFG_PERIOD 0x3 1878c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_GAIN_0 0x564 1888c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_GAIN_0_CH0_EVEN (0x80 << 0) 1898c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_GAIN_0_CH0_ODD (0x80 << 16) 1908c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_GAIN_1 0x568 1918c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_GAIN_1_CH1 (0x80 << 0) 1928c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_GAIN_1_CH2 (0x80 << 16) 1938c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_EVEN_CFG 0x574 1948c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_EVEN_CFG_PATTERN_YUYV 0x9cac 1958c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_EVEN_CFG_PATTERN_YVYU 0xac9c 1968c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_EVEN_CFG_PATTERN_UYVY 0xc9ca 1978c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_EVEN_CFG_PATTERN_VYUY 0xcac9 1988c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_ODD_CFG 0x578 1998c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_ODD_CFG_PATTERN_YUYV 0x9cac 2008c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_ODD_CFG_PATTERN_YVYU 0xac9c 2018c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_ODD_CFG_PATTERN_UYVY 0xc9ca 2028c2ecf20Sopenharmony_ci#define VFE_0_DEMUX_ODD_CFG_PATTERN_VYUY 0xcac9 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci#define VFE_0_SCALE_ENC_Y_CFG 0x91c 2058c2ecf20Sopenharmony_ci#define VFE_0_SCALE_ENC_Y_H_IMAGE_SIZE 0x920 2068c2ecf20Sopenharmony_ci#define VFE_0_SCALE_ENC_Y_H_PHASE 0x924 2078c2ecf20Sopenharmony_ci#define VFE_0_SCALE_ENC_Y_V_IMAGE_SIZE 0x934 2088c2ecf20Sopenharmony_ci#define VFE_0_SCALE_ENC_Y_V_PHASE 0x938 2098c2ecf20Sopenharmony_ci#define VFE_0_SCALE_ENC_CBCR_CFG 0x948 2108c2ecf20Sopenharmony_ci#define VFE_0_SCALE_ENC_CBCR_H_IMAGE_SIZE 0x94c 2118c2ecf20Sopenharmony_ci#define VFE_0_SCALE_ENC_CBCR_H_PHASE 0x950 2128c2ecf20Sopenharmony_ci#define VFE_0_SCALE_ENC_CBCR_V_IMAGE_SIZE 0x960 2138c2ecf20Sopenharmony_ci#define VFE_0_SCALE_ENC_CBCR_V_PHASE 0x964 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci#define VFE_0_CROP_ENC_Y_WIDTH 0x974 2168c2ecf20Sopenharmony_ci#define VFE_0_CROP_ENC_Y_HEIGHT 0x978 2178c2ecf20Sopenharmony_ci#define VFE_0_CROP_ENC_CBCR_WIDTH 0x97c 2188c2ecf20Sopenharmony_ci#define VFE_0_CROP_ENC_CBCR_HEIGHT 0x980 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci#define VFE_0_CLAMP_ENC_MAX_CFG 0x984 2218c2ecf20Sopenharmony_ci#define VFE_0_CLAMP_ENC_MAX_CFG_CH0 (0xff << 0) 2228c2ecf20Sopenharmony_ci#define VFE_0_CLAMP_ENC_MAX_CFG_CH1 (0xff << 8) 2238c2ecf20Sopenharmony_ci#define VFE_0_CLAMP_ENC_MAX_CFG_CH2 (0xff << 16) 2248c2ecf20Sopenharmony_ci#define VFE_0_CLAMP_ENC_MIN_CFG 0x988 2258c2ecf20Sopenharmony_ci#define VFE_0_CLAMP_ENC_MIN_CFG_CH0 (0x0 << 0) 2268c2ecf20Sopenharmony_ci#define VFE_0_CLAMP_ENC_MIN_CFG_CH1 (0x0 << 8) 2278c2ecf20Sopenharmony_ci#define VFE_0_CLAMP_ENC_MIN_CFG_CH2 (0x0 << 16) 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci#define VFE_0_REALIGN_BUF_CFG 0xaac 2308c2ecf20Sopenharmony_ci#define VFE_0_REALIGN_BUF_CFG_CB_ODD_PIXEL BIT(2) 2318c2ecf20Sopenharmony_ci#define VFE_0_REALIGN_BUF_CFG_CR_ODD_PIXEL BIT(3) 2328c2ecf20Sopenharmony_ci#define VFE_0_REALIGN_BUF_CFG_HSUB_ENABLE BIT(4) 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci#define CAMIF_TIMEOUT_SLEEP_US 1000 2358c2ecf20Sopenharmony_ci#define CAMIF_TIMEOUT_ALL_US 1000000 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci#define MSM_VFE_VFE0_UB_SIZE 2047 2388c2ecf20Sopenharmony_ci#define MSM_VFE_VFE0_UB_SIZE_RDI (MSM_VFE_VFE0_UB_SIZE / 3) 2398c2ecf20Sopenharmony_ci#define MSM_VFE_VFE1_UB_SIZE 1535 2408c2ecf20Sopenharmony_ci#define MSM_VFE_VFE1_UB_SIZE_RDI (MSM_VFE_VFE1_UB_SIZE / 3) 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_cistatic void vfe_hw_version_read(struct vfe_device *vfe, struct device *dev) 2438c2ecf20Sopenharmony_ci{ 2448c2ecf20Sopenharmony_ci u32 hw_version = readl_relaxed(vfe->base + VFE_0_HW_VERSION); 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci dev_err(dev, "VFE HW Version = 0x%08x\n", hw_version); 2478c2ecf20Sopenharmony_ci} 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_cistatic u16 vfe_get_ub_size(u8 vfe_id) 2508c2ecf20Sopenharmony_ci{ 2518c2ecf20Sopenharmony_ci if (vfe_id == 0) 2528c2ecf20Sopenharmony_ci return MSM_VFE_VFE0_UB_SIZE_RDI; 2538c2ecf20Sopenharmony_ci else if (vfe_id == 1) 2548c2ecf20Sopenharmony_ci return MSM_VFE_VFE1_UB_SIZE_RDI; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci return 0; 2578c2ecf20Sopenharmony_ci} 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_cistatic inline void vfe_reg_clr(struct vfe_device *vfe, u32 reg, u32 clr_bits) 2608c2ecf20Sopenharmony_ci{ 2618c2ecf20Sopenharmony_ci u32 bits = readl_relaxed(vfe->base + reg); 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci writel_relaxed(bits & ~clr_bits, vfe->base + reg); 2648c2ecf20Sopenharmony_ci} 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_cistatic inline void vfe_reg_set(struct vfe_device *vfe, u32 reg, u32 set_bits) 2678c2ecf20Sopenharmony_ci{ 2688c2ecf20Sopenharmony_ci u32 bits = readl_relaxed(vfe->base + reg); 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci writel_relaxed(bits | set_bits, vfe->base + reg); 2718c2ecf20Sopenharmony_ci} 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_cistatic void vfe_global_reset(struct vfe_device *vfe) 2748c2ecf20Sopenharmony_ci{ 2758c2ecf20Sopenharmony_ci u32 reset_bits = VFE_0_GLOBAL_RESET_CMD_IDLE_CGC | 2768c2ecf20Sopenharmony_ci VFE_0_GLOBAL_RESET_CMD_DSP | 2778c2ecf20Sopenharmony_ci VFE_0_GLOBAL_RESET_CMD_TESTGEN | 2788c2ecf20Sopenharmony_ci VFE_0_GLOBAL_RESET_CMD_BUS_MISR | 2798c2ecf20Sopenharmony_ci VFE_0_GLOBAL_RESET_CMD_PM | 2808c2ecf20Sopenharmony_ci VFE_0_GLOBAL_RESET_CMD_REGISTER | 2818c2ecf20Sopenharmony_ci VFE_0_GLOBAL_RESET_CMD_BUS_BDG | 2828c2ecf20Sopenharmony_ci VFE_0_GLOBAL_RESET_CMD_BUS | 2838c2ecf20Sopenharmony_ci VFE_0_GLOBAL_RESET_CMD_CAMIF | 2848c2ecf20Sopenharmony_ci VFE_0_GLOBAL_RESET_CMD_CORE; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci writel_relaxed(BIT(31), vfe->base + VFE_0_IRQ_MASK_0); 2878c2ecf20Sopenharmony_ci wmb(); 2888c2ecf20Sopenharmony_ci writel_relaxed(reset_bits, vfe->base + VFE_0_GLOBAL_RESET_CMD); 2898c2ecf20Sopenharmony_ci} 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_cistatic void vfe_halt_request(struct vfe_device *vfe) 2928c2ecf20Sopenharmony_ci{ 2938c2ecf20Sopenharmony_ci writel_relaxed(VFE_0_BUS_BDG_CMD_HALT_REQ, 2948c2ecf20Sopenharmony_ci vfe->base + VFE_0_BUS_BDG_CMD); 2958c2ecf20Sopenharmony_ci} 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_cistatic void vfe_halt_clear(struct vfe_device *vfe) 2988c2ecf20Sopenharmony_ci{ 2998c2ecf20Sopenharmony_ci writel_relaxed(0x0, vfe->base + VFE_0_BUS_BDG_CMD); 3008c2ecf20Sopenharmony_ci} 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_cistatic void vfe_wm_enable(struct vfe_device *vfe, u8 wm, u8 enable) 3038c2ecf20Sopenharmony_ci{ 3048c2ecf20Sopenharmony_ci if (enable) 3058c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_BUS_IMAGE_MASTER_n_WR_CFG(wm), 3068c2ecf20Sopenharmony_ci 1 << VFE_0_BUS_IMAGE_MASTER_n_WR_CFG_WR_PATH_SHIFT); 3078c2ecf20Sopenharmony_ci else 3088c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, VFE_0_BUS_IMAGE_MASTER_n_WR_CFG(wm), 3098c2ecf20Sopenharmony_ci 1 << VFE_0_BUS_IMAGE_MASTER_n_WR_CFG_WR_PATH_SHIFT); 3108c2ecf20Sopenharmony_ci} 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_cistatic void vfe_wm_frame_based(struct vfe_device *vfe, u8 wm, u8 enable) 3138c2ecf20Sopenharmony_ci{ 3148c2ecf20Sopenharmony_ci if (enable) 3158c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG(wm), 3168c2ecf20Sopenharmony_ci 1 << VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG_FRM_BASED_SHIFT); 3178c2ecf20Sopenharmony_ci else 3188c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG(wm), 3198c2ecf20Sopenharmony_ci 1 << VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG_FRM_BASED_SHIFT); 3208c2ecf20Sopenharmony_ci} 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci#define CALC_WORD(width, M, N) (((width) * (M) + (N) - 1) / (N)) 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_cistatic int vfe_word_per_line_by_pixel(u32 format, u32 pixel_per_line) 3258c2ecf20Sopenharmony_ci{ 3268c2ecf20Sopenharmony_ci int val = 0; 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci switch (format) { 3298c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV12: 3308c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV21: 3318c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV16: 3328c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV61: 3338c2ecf20Sopenharmony_ci val = CALC_WORD(pixel_per_line, 1, 8); 3348c2ecf20Sopenharmony_ci break; 3358c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_YUYV: 3368c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_YVYU: 3378c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_UYVY: 3388c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_VYUY: 3398c2ecf20Sopenharmony_ci val = CALC_WORD(pixel_per_line, 2, 8); 3408c2ecf20Sopenharmony_ci break; 3418c2ecf20Sopenharmony_ci } 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci return val; 3448c2ecf20Sopenharmony_ci} 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_cistatic int vfe_word_per_line_by_bytes(u32 bytes_per_line) 3478c2ecf20Sopenharmony_ci{ 3488c2ecf20Sopenharmony_ci return CALC_WORD(bytes_per_line, 1, 8); 3498c2ecf20Sopenharmony_ci} 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_cistatic void vfe_get_wm_sizes(struct v4l2_pix_format_mplane *pix, u8 plane, 3528c2ecf20Sopenharmony_ci u16 *width, u16 *height, u16 *bytesperline) 3538c2ecf20Sopenharmony_ci{ 3548c2ecf20Sopenharmony_ci switch (pix->pixelformat) { 3558c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV12: 3568c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV21: 3578c2ecf20Sopenharmony_ci *width = pix->width; 3588c2ecf20Sopenharmony_ci *height = pix->height; 3598c2ecf20Sopenharmony_ci *bytesperline = pix->plane_fmt[0].bytesperline; 3608c2ecf20Sopenharmony_ci if (plane == 1) 3618c2ecf20Sopenharmony_ci *height /= 2; 3628c2ecf20Sopenharmony_ci break; 3638c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV16: 3648c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV61: 3658c2ecf20Sopenharmony_ci *width = pix->width; 3668c2ecf20Sopenharmony_ci *height = pix->height; 3678c2ecf20Sopenharmony_ci *bytesperline = pix->plane_fmt[0].bytesperline; 3688c2ecf20Sopenharmony_ci break; 3698c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_YUYV: 3708c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_YVYU: 3718c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_VYUY: 3728c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_UYVY: 3738c2ecf20Sopenharmony_ci *width = pix->width; 3748c2ecf20Sopenharmony_ci *height = pix->height; 3758c2ecf20Sopenharmony_ci *bytesperline = pix->plane_fmt[plane].bytesperline; 3768c2ecf20Sopenharmony_ci break; 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci } 3798c2ecf20Sopenharmony_ci} 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_cistatic void vfe_wm_line_based(struct vfe_device *vfe, u32 wm, 3828c2ecf20Sopenharmony_ci struct v4l2_pix_format_mplane *pix, 3838c2ecf20Sopenharmony_ci u8 plane, u32 enable) 3848c2ecf20Sopenharmony_ci{ 3858c2ecf20Sopenharmony_ci u32 reg; 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci if (enable) { 3888c2ecf20Sopenharmony_ci u16 width = 0, height = 0, bytesperline = 0, wpl; 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci vfe_get_wm_sizes(pix, plane, &width, &height, &bytesperline); 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci wpl = vfe_word_per_line_by_pixel(pix->pixelformat, width); 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci reg = height - 1; 3958c2ecf20Sopenharmony_ci reg |= ((wpl + 3) / 4 - 1) << 16; 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + 3988c2ecf20Sopenharmony_ci VFE_0_BUS_IMAGE_MASTER_n_WR_IMAGE_SIZE(wm)); 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci wpl = vfe_word_per_line_by_bytes(bytesperline); 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci reg = 0x3; 4038c2ecf20Sopenharmony_ci reg |= (height - 1) << 2; 4048c2ecf20Sopenharmony_ci reg |= ((wpl + 1) / 2) << 16; 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + 4078c2ecf20Sopenharmony_ci VFE_0_BUS_IMAGE_MASTER_n_WR_BUFFER_CFG(wm)); 4088c2ecf20Sopenharmony_ci } else { 4098c2ecf20Sopenharmony_ci writel_relaxed(0, vfe->base + 4108c2ecf20Sopenharmony_ci VFE_0_BUS_IMAGE_MASTER_n_WR_IMAGE_SIZE(wm)); 4118c2ecf20Sopenharmony_ci writel_relaxed(0, vfe->base + 4128c2ecf20Sopenharmony_ci VFE_0_BUS_IMAGE_MASTER_n_WR_BUFFER_CFG(wm)); 4138c2ecf20Sopenharmony_ci } 4148c2ecf20Sopenharmony_ci} 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_cistatic void vfe_wm_set_framedrop_period(struct vfe_device *vfe, u8 wm, u8 per) 4178c2ecf20Sopenharmony_ci{ 4188c2ecf20Sopenharmony_ci u32 reg; 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci reg = readl_relaxed(vfe->base + 4218c2ecf20Sopenharmony_ci VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG(wm)); 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci reg &= ~(VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG_FRM_DROP_PER_MASK); 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci reg |= (per << VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG_FRM_DROP_PER_SHIFT) 4268c2ecf20Sopenharmony_ci & VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG_FRM_DROP_PER_MASK; 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci writel_relaxed(reg, 4298c2ecf20Sopenharmony_ci vfe->base + VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG(wm)); 4308c2ecf20Sopenharmony_ci} 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_cistatic void vfe_wm_set_framedrop_pattern(struct vfe_device *vfe, u8 wm, 4338c2ecf20Sopenharmony_ci u32 pattern) 4348c2ecf20Sopenharmony_ci{ 4358c2ecf20Sopenharmony_ci writel_relaxed(pattern, 4368c2ecf20Sopenharmony_ci vfe->base + VFE_0_BUS_IMAGE_MASTER_n_WR_FRAMEDROP_PATTERN(wm)); 4378c2ecf20Sopenharmony_ci} 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_cistatic void vfe_wm_set_ub_cfg(struct vfe_device *vfe, u8 wm, 4408c2ecf20Sopenharmony_ci u16 offset, u16 depth) 4418c2ecf20Sopenharmony_ci{ 4428c2ecf20Sopenharmony_ci u32 reg; 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci reg = (offset << VFE_0_BUS_IMAGE_MASTER_n_WR_UB_CFG_OFFSET_SHIFT) | 4458c2ecf20Sopenharmony_ci depth; 4468c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + VFE_0_BUS_IMAGE_MASTER_n_WR_UB_CFG(wm)); 4478c2ecf20Sopenharmony_ci} 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_cistatic void vfe_bus_reload_wm(struct vfe_device *vfe, u8 wm) 4508c2ecf20Sopenharmony_ci{ 4518c2ecf20Sopenharmony_ci wmb(); 4528c2ecf20Sopenharmony_ci writel_relaxed(VFE_0_BUS_CMD_Mx_RLD_CMD(wm), vfe->base + VFE_0_BUS_CMD); 4538c2ecf20Sopenharmony_ci wmb(); 4548c2ecf20Sopenharmony_ci} 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_cistatic void vfe_wm_set_ping_addr(struct vfe_device *vfe, u8 wm, u32 addr) 4578c2ecf20Sopenharmony_ci{ 4588c2ecf20Sopenharmony_ci writel_relaxed(addr, 4598c2ecf20Sopenharmony_ci vfe->base + VFE_0_BUS_IMAGE_MASTER_n_WR_PING_ADDR(wm)); 4608c2ecf20Sopenharmony_ci} 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_cistatic void vfe_wm_set_pong_addr(struct vfe_device *vfe, u8 wm, u32 addr) 4638c2ecf20Sopenharmony_ci{ 4648c2ecf20Sopenharmony_ci writel_relaxed(addr, 4658c2ecf20Sopenharmony_ci vfe->base + VFE_0_BUS_IMAGE_MASTER_n_WR_PONG_ADDR(wm)); 4668c2ecf20Sopenharmony_ci} 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_cistatic int vfe_wm_get_ping_pong_status(struct vfe_device *vfe, u8 wm) 4698c2ecf20Sopenharmony_ci{ 4708c2ecf20Sopenharmony_ci u32 reg; 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci reg = readl_relaxed(vfe->base + VFE_0_BUS_PING_PONG_STATUS); 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci return (reg >> wm) & 0x1; 4758c2ecf20Sopenharmony_ci} 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_cistatic void vfe_bus_enable_wr_if(struct vfe_device *vfe, u8 enable) 4788c2ecf20Sopenharmony_ci{ 4798c2ecf20Sopenharmony_ci if (enable) 4808c2ecf20Sopenharmony_ci writel_relaxed(0x101, vfe->base + VFE_0_BUS_CFG); 4818c2ecf20Sopenharmony_ci else 4828c2ecf20Sopenharmony_ci writel_relaxed(0, vfe->base + VFE_0_BUS_CFG); 4838c2ecf20Sopenharmony_ci} 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_cistatic void vfe_bus_connect_wm_to_rdi(struct vfe_device *vfe, u8 wm, 4868c2ecf20Sopenharmony_ci enum vfe_line_id id) 4878c2ecf20Sopenharmony_ci{ 4888c2ecf20Sopenharmony_ci u32 reg; 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci reg = VFE_0_RDI_CFG_x_MIPI_EN_BITS; 4918c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_RDI_CFG_x(0), reg); 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci reg = VFE_0_RDI_CFG_x_RDI_EN_BIT; 4948c2ecf20Sopenharmony_ci reg |= ((3 * id) << VFE_0_RDI_CFG_x_RDI_STREAM_SEL_SHIFT) & 4958c2ecf20Sopenharmony_ci VFE_0_RDI_CFG_x_RDI_STREAM_SEL_MASK; 4968c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_RDI_CFG_x(id), reg); 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_ci switch (id) { 4998c2ecf20Sopenharmony_ci case VFE_LINE_RDI0: 5008c2ecf20Sopenharmony_ci default: 5018c2ecf20Sopenharmony_ci reg = VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_VAL_RDI0 << 5028c2ecf20Sopenharmony_ci VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_SHIFT; 5038c2ecf20Sopenharmony_ci break; 5048c2ecf20Sopenharmony_ci case VFE_LINE_RDI1: 5058c2ecf20Sopenharmony_ci reg = VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_VAL_RDI1 << 5068c2ecf20Sopenharmony_ci VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_SHIFT; 5078c2ecf20Sopenharmony_ci break; 5088c2ecf20Sopenharmony_ci case VFE_LINE_RDI2: 5098c2ecf20Sopenharmony_ci reg = VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_VAL_RDI2 << 5108c2ecf20Sopenharmony_ci VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_SHIFT; 5118c2ecf20Sopenharmony_ci break; 5128c2ecf20Sopenharmony_ci } 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci if (wm % 2 == 1) 5158c2ecf20Sopenharmony_ci reg <<= 16; 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_BUS_XBAR_CFG_x(wm), reg); 5188c2ecf20Sopenharmony_ci} 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_cistatic void vfe_wm_set_subsample(struct vfe_device *vfe, u8 wm) 5218c2ecf20Sopenharmony_ci{ 5228c2ecf20Sopenharmony_ci writel_relaxed(VFE_0_BUS_IMAGE_MASTER_n_WR_IRQ_SUBSAMPLE_PATTERN_DEF, 5238c2ecf20Sopenharmony_ci vfe->base + 5248c2ecf20Sopenharmony_ci VFE_0_BUS_IMAGE_MASTER_n_WR_IRQ_SUBSAMPLE_PATTERN(wm)); 5258c2ecf20Sopenharmony_ci} 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_cistatic void vfe_bus_disconnect_wm_from_rdi(struct vfe_device *vfe, u8 wm, 5288c2ecf20Sopenharmony_ci enum vfe_line_id id) 5298c2ecf20Sopenharmony_ci{ 5308c2ecf20Sopenharmony_ci u32 reg; 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci reg = VFE_0_RDI_CFG_x_RDI_EN_BIT; 5338c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, VFE_0_RDI_CFG_x(id), reg); 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci switch (id) { 5368c2ecf20Sopenharmony_ci case VFE_LINE_RDI0: 5378c2ecf20Sopenharmony_ci default: 5388c2ecf20Sopenharmony_ci reg = VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_VAL_RDI0 << 5398c2ecf20Sopenharmony_ci VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_SHIFT; 5408c2ecf20Sopenharmony_ci break; 5418c2ecf20Sopenharmony_ci case VFE_LINE_RDI1: 5428c2ecf20Sopenharmony_ci reg = VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_VAL_RDI1 << 5438c2ecf20Sopenharmony_ci VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_SHIFT; 5448c2ecf20Sopenharmony_ci break; 5458c2ecf20Sopenharmony_ci case VFE_LINE_RDI2: 5468c2ecf20Sopenharmony_ci reg = VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_VAL_RDI2 << 5478c2ecf20Sopenharmony_ci VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_SHIFT; 5488c2ecf20Sopenharmony_ci break; 5498c2ecf20Sopenharmony_ci } 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci if (wm % 2 == 1) 5528c2ecf20Sopenharmony_ci reg <<= 16; 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, VFE_0_BUS_XBAR_CFG_x(wm), reg); 5558c2ecf20Sopenharmony_ci} 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_cistatic void vfe_set_xbar_cfg(struct vfe_device *vfe, struct vfe_output *output, 5588c2ecf20Sopenharmony_ci u8 enable) 5598c2ecf20Sopenharmony_ci{ 5608c2ecf20Sopenharmony_ci struct vfe_line *line = container_of(output, struct vfe_line, output); 5618c2ecf20Sopenharmony_ci u32 p = line->video_out.active_fmt.fmt.pix_mp.pixelformat; 5628c2ecf20Sopenharmony_ci u32 reg; 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci switch (p) { 5658c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV12: 5668c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV21: 5678c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV16: 5688c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV61: 5698c2ecf20Sopenharmony_ci reg = VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_LUMA << 5708c2ecf20Sopenharmony_ci VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_SHIFT; 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci if (output->wm_idx[0] % 2 == 1) 5738c2ecf20Sopenharmony_ci reg <<= 16; 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci if (enable) 5768c2ecf20Sopenharmony_ci vfe_reg_set(vfe, 5778c2ecf20Sopenharmony_ci VFE_0_BUS_XBAR_CFG_x(output->wm_idx[0]), 5788c2ecf20Sopenharmony_ci reg); 5798c2ecf20Sopenharmony_ci else 5808c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, 5818c2ecf20Sopenharmony_ci VFE_0_BUS_XBAR_CFG_x(output->wm_idx[0]), 5828c2ecf20Sopenharmony_ci reg); 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci reg = VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_EN; 5858c2ecf20Sopenharmony_ci if (p == V4L2_PIX_FMT_NV12 || p == V4L2_PIX_FMT_NV16) 5868c2ecf20Sopenharmony_ci reg |= VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_SWAP_INTER_INTRA; 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci if (output->wm_idx[1] % 2 == 1) 5898c2ecf20Sopenharmony_ci reg <<= 16; 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci if (enable) 5928c2ecf20Sopenharmony_ci vfe_reg_set(vfe, 5938c2ecf20Sopenharmony_ci VFE_0_BUS_XBAR_CFG_x(output->wm_idx[1]), 5948c2ecf20Sopenharmony_ci reg); 5958c2ecf20Sopenharmony_ci else 5968c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, 5978c2ecf20Sopenharmony_ci VFE_0_BUS_XBAR_CFG_x(output->wm_idx[1]), 5988c2ecf20Sopenharmony_ci reg); 5998c2ecf20Sopenharmony_ci break; 6008c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_YUYV: 6018c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_YVYU: 6028c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_VYUY: 6038c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_UYVY: 6048c2ecf20Sopenharmony_ci reg = VFE_0_BUS_XBAR_CFG_x_M_REALIGN_BUF_EN; 6058c2ecf20Sopenharmony_ci reg |= VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_EN; 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci if (p == V4L2_PIX_FMT_YUYV || p == V4L2_PIX_FMT_YVYU) 6088c2ecf20Sopenharmony_ci reg |= VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_SWAP_INTER_INTRA; 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_ci if (output->wm_idx[0] % 2 == 1) 6118c2ecf20Sopenharmony_ci reg <<= 16; 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci if (enable) 6148c2ecf20Sopenharmony_ci vfe_reg_set(vfe, 6158c2ecf20Sopenharmony_ci VFE_0_BUS_XBAR_CFG_x(output->wm_idx[0]), 6168c2ecf20Sopenharmony_ci reg); 6178c2ecf20Sopenharmony_ci else 6188c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, 6198c2ecf20Sopenharmony_ci VFE_0_BUS_XBAR_CFG_x(output->wm_idx[0]), 6208c2ecf20Sopenharmony_ci reg); 6218c2ecf20Sopenharmony_ci break; 6228c2ecf20Sopenharmony_ci default: 6238c2ecf20Sopenharmony_ci break; 6248c2ecf20Sopenharmony_ci } 6258c2ecf20Sopenharmony_ci} 6268c2ecf20Sopenharmony_ci 6278c2ecf20Sopenharmony_cistatic void vfe_set_realign_cfg(struct vfe_device *vfe, struct vfe_line *line, 6288c2ecf20Sopenharmony_ci u8 enable) 6298c2ecf20Sopenharmony_ci{ 6308c2ecf20Sopenharmony_ci u32 p = line->video_out.active_fmt.fmt.pix_mp.pixelformat; 6318c2ecf20Sopenharmony_ci u32 val = VFE_0_MODULE_ZOOM_EN_REALIGN_BUF; 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci if (p != V4L2_PIX_FMT_YUYV && p != V4L2_PIX_FMT_YVYU && 6348c2ecf20Sopenharmony_ci p != V4L2_PIX_FMT_VYUY && p != V4L2_PIX_FMT_UYVY) 6358c2ecf20Sopenharmony_ci return; 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci if (enable) { 6388c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_MODULE_ZOOM_EN, val); 6398c2ecf20Sopenharmony_ci } else { 6408c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, VFE_0_MODULE_ZOOM_EN, val); 6418c2ecf20Sopenharmony_ci return; 6428c2ecf20Sopenharmony_ci } 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_ci val = VFE_0_REALIGN_BUF_CFG_HSUB_ENABLE; 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci if (p == V4L2_PIX_FMT_UYVY || p == V4L2_PIX_FMT_YUYV) 6478c2ecf20Sopenharmony_ci val |= VFE_0_REALIGN_BUF_CFG_CR_ODD_PIXEL; 6488c2ecf20Sopenharmony_ci else 6498c2ecf20Sopenharmony_ci val |= VFE_0_REALIGN_BUF_CFG_CB_ODD_PIXEL; 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_REALIGN_BUF_CFG); 6528c2ecf20Sopenharmony_ci} 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_cistatic void vfe_set_rdi_cid(struct vfe_device *vfe, enum vfe_line_id id, u8 cid) 6558c2ecf20Sopenharmony_ci{ 6568c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, VFE_0_RDI_CFG_x(id), 6578c2ecf20Sopenharmony_ci VFE_0_RDI_CFG_x_RDI_M0_SEL_MASK); 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_RDI_CFG_x(id), 6608c2ecf20Sopenharmony_ci cid << VFE_0_RDI_CFG_x_RDI_M0_SEL_SHIFT); 6618c2ecf20Sopenharmony_ci} 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_cistatic void vfe_reg_update(struct vfe_device *vfe, enum vfe_line_id line_id) 6648c2ecf20Sopenharmony_ci{ 6658c2ecf20Sopenharmony_ci vfe->reg_update |= VFE_0_REG_UPDATE_line_n(line_id); 6668c2ecf20Sopenharmony_ci wmb(); 6678c2ecf20Sopenharmony_ci writel_relaxed(vfe->reg_update, vfe->base + VFE_0_REG_UPDATE); 6688c2ecf20Sopenharmony_ci wmb(); 6698c2ecf20Sopenharmony_ci} 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_cistatic inline void vfe_reg_update_clear(struct vfe_device *vfe, 6728c2ecf20Sopenharmony_ci enum vfe_line_id line_id) 6738c2ecf20Sopenharmony_ci{ 6748c2ecf20Sopenharmony_ci vfe->reg_update &= ~VFE_0_REG_UPDATE_line_n(line_id); 6758c2ecf20Sopenharmony_ci} 6768c2ecf20Sopenharmony_ci 6778c2ecf20Sopenharmony_cistatic void vfe_enable_irq_wm_line(struct vfe_device *vfe, u8 wm, 6788c2ecf20Sopenharmony_ci enum vfe_line_id line_id, u8 enable) 6798c2ecf20Sopenharmony_ci{ 6808c2ecf20Sopenharmony_ci u32 irq_en0 = VFE_0_IRQ_MASK_0_IMAGE_MASTER_n_PING_PONG(wm) | 6818c2ecf20Sopenharmony_ci VFE_0_IRQ_MASK_0_line_n_REG_UPDATE(line_id); 6828c2ecf20Sopenharmony_ci u32 irq_en1 = VFE_0_IRQ_MASK_1_IMAGE_MASTER_n_BUS_OVERFLOW(wm) | 6838c2ecf20Sopenharmony_ci VFE_0_IRQ_MASK_1_RDIn_SOF(line_id); 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_ci if (enable) { 6868c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_IRQ_MASK_0, irq_en0); 6878c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_IRQ_MASK_1, irq_en1); 6888c2ecf20Sopenharmony_ci } else { 6898c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, VFE_0_IRQ_MASK_0, irq_en0); 6908c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, VFE_0_IRQ_MASK_1, irq_en1); 6918c2ecf20Sopenharmony_ci } 6928c2ecf20Sopenharmony_ci} 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_cistatic void vfe_enable_irq_pix_line(struct vfe_device *vfe, u8 comp, 6958c2ecf20Sopenharmony_ci enum vfe_line_id line_id, u8 enable) 6968c2ecf20Sopenharmony_ci{ 6978c2ecf20Sopenharmony_ci struct vfe_output *output = &vfe->line[line_id].output; 6988c2ecf20Sopenharmony_ci unsigned int i; 6998c2ecf20Sopenharmony_ci u32 irq_en0; 7008c2ecf20Sopenharmony_ci u32 irq_en1; 7018c2ecf20Sopenharmony_ci u32 comp_mask = 0; 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_ci irq_en0 = VFE_0_IRQ_MASK_0_CAMIF_SOF; 7048c2ecf20Sopenharmony_ci irq_en0 |= VFE_0_IRQ_MASK_0_CAMIF_EOF; 7058c2ecf20Sopenharmony_ci irq_en0 |= VFE_0_IRQ_MASK_0_IMAGE_COMPOSITE_DONE_n(comp); 7068c2ecf20Sopenharmony_ci irq_en0 |= VFE_0_IRQ_MASK_0_line_n_REG_UPDATE(line_id); 7078c2ecf20Sopenharmony_ci irq_en1 = VFE_0_IRQ_MASK_1_CAMIF_ERROR; 7088c2ecf20Sopenharmony_ci for (i = 0; i < output->wm_num; i++) { 7098c2ecf20Sopenharmony_ci irq_en1 |= VFE_0_IRQ_MASK_1_IMAGE_MASTER_n_BUS_OVERFLOW( 7108c2ecf20Sopenharmony_ci output->wm_idx[i]); 7118c2ecf20Sopenharmony_ci comp_mask |= (1 << output->wm_idx[i]) << comp * 8; 7128c2ecf20Sopenharmony_ci } 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci if (enable) { 7158c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_IRQ_MASK_0, irq_en0); 7168c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_IRQ_MASK_1, irq_en1); 7178c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_IRQ_COMPOSITE_MASK_0, comp_mask); 7188c2ecf20Sopenharmony_ci } else { 7198c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, VFE_0_IRQ_MASK_0, irq_en0); 7208c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, VFE_0_IRQ_MASK_1, irq_en1); 7218c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, VFE_0_IRQ_COMPOSITE_MASK_0, comp_mask); 7228c2ecf20Sopenharmony_ci } 7238c2ecf20Sopenharmony_ci} 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_cistatic void vfe_enable_irq_common(struct vfe_device *vfe) 7268c2ecf20Sopenharmony_ci{ 7278c2ecf20Sopenharmony_ci u32 irq_en0 = VFE_0_IRQ_MASK_0_RESET_ACK; 7288c2ecf20Sopenharmony_ci u32 irq_en1 = VFE_0_IRQ_MASK_1_VIOLATION | 7298c2ecf20Sopenharmony_ci VFE_0_IRQ_MASK_1_BUS_BDG_HALT_ACK; 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_IRQ_MASK_0, irq_en0); 7328c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_IRQ_MASK_1, irq_en1); 7338c2ecf20Sopenharmony_ci} 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_cistatic void vfe_set_demux_cfg(struct vfe_device *vfe, struct vfe_line *line) 7368c2ecf20Sopenharmony_ci{ 7378c2ecf20Sopenharmony_ci u32 val, even_cfg, odd_cfg; 7388c2ecf20Sopenharmony_ci 7398c2ecf20Sopenharmony_ci writel_relaxed(VFE_0_DEMUX_CFG_PERIOD, vfe->base + VFE_0_DEMUX_CFG); 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci val = VFE_0_DEMUX_GAIN_0_CH0_EVEN | VFE_0_DEMUX_GAIN_0_CH0_ODD; 7428c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_DEMUX_GAIN_0); 7438c2ecf20Sopenharmony_ci 7448c2ecf20Sopenharmony_ci val = VFE_0_DEMUX_GAIN_1_CH1 | VFE_0_DEMUX_GAIN_1_CH2; 7458c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_DEMUX_GAIN_1); 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_ci switch (line->fmt[MSM_VFE_PAD_SINK].code) { 7488c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_YUYV8_2X8: 7498c2ecf20Sopenharmony_ci even_cfg = VFE_0_DEMUX_EVEN_CFG_PATTERN_YUYV; 7508c2ecf20Sopenharmony_ci odd_cfg = VFE_0_DEMUX_ODD_CFG_PATTERN_YUYV; 7518c2ecf20Sopenharmony_ci break; 7528c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_YVYU8_2X8: 7538c2ecf20Sopenharmony_ci even_cfg = VFE_0_DEMUX_EVEN_CFG_PATTERN_YVYU; 7548c2ecf20Sopenharmony_ci odd_cfg = VFE_0_DEMUX_ODD_CFG_PATTERN_YVYU; 7558c2ecf20Sopenharmony_ci break; 7568c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_UYVY8_2X8: 7578c2ecf20Sopenharmony_ci default: 7588c2ecf20Sopenharmony_ci even_cfg = VFE_0_DEMUX_EVEN_CFG_PATTERN_UYVY; 7598c2ecf20Sopenharmony_ci odd_cfg = VFE_0_DEMUX_ODD_CFG_PATTERN_UYVY; 7608c2ecf20Sopenharmony_ci break; 7618c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_VYUY8_2X8: 7628c2ecf20Sopenharmony_ci even_cfg = VFE_0_DEMUX_EVEN_CFG_PATTERN_VYUY; 7638c2ecf20Sopenharmony_ci odd_cfg = VFE_0_DEMUX_ODD_CFG_PATTERN_VYUY; 7648c2ecf20Sopenharmony_ci break; 7658c2ecf20Sopenharmony_ci } 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_ci writel_relaxed(even_cfg, vfe->base + VFE_0_DEMUX_EVEN_CFG); 7688c2ecf20Sopenharmony_ci writel_relaxed(odd_cfg, vfe->base + VFE_0_DEMUX_ODD_CFG); 7698c2ecf20Sopenharmony_ci} 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_cistatic inline u8 vfe_calc_interp_reso(u16 input, u16 output) 7728c2ecf20Sopenharmony_ci{ 7738c2ecf20Sopenharmony_ci if (input / output >= 16) 7748c2ecf20Sopenharmony_ci return 0; 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_ci if (input / output >= 8) 7778c2ecf20Sopenharmony_ci return 1; 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ci if (input / output >= 4) 7808c2ecf20Sopenharmony_ci return 2; 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ci return 3; 7838c2ecf20Sopenharmony_ci} 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_cistatic void vfe_set_scale_cfg(struct vfe_device *vfe, struct vfe_line *line) 7868c2ecf20Sopenharmony_ci{ 7878c2ecf20Sopenharmony_ci u32 p = line->video_out.active_fmt.fmt.pix_mp.pixelformat; 7888c2ecf20Sopenharmony_ci u32 reg; 7898c2ecf20Sopenharmony_ci u16 input, output; 7908c2ecf20Sopenharmony_ci u8 interp_reso; 7918c2ecf20Sopenharmony_ci u32 phase_mult; 7928c2ecf20Sopenharmony_ci 7938c2ecf20Sopenharmony_ci writel_relaxed(0x3, vfe->base + VFE_0_SCALE_ENC_Y_CFG); 7948c2ecf20Sopenharmony_ci 7958c2ecf20Sopenharmony_ci input = line->fmt[MSM_VFE_PAD_SINK].width - 1; 7968c2ecf20Sopenharmony_ci output = line->compose.width - 1; 7978c2ecf20Sopenharmony_ci reg = (output << 16) | input; 7988c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + VFE_0_SCALE_ENC_Y_H_IMAGE_SIZE); 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci interp_reso = vfe_calc_interp_reso(input, output); 8018c2ecf20Sopenharmony_ci phase_mult = input * (1 << (14 + interp_reso)) / output; 8028c2ecf20Sopenharmony_ci reg = (interp_reso << 28) | phase_mult; 8038c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + VFE_0_SCALE_ENC_Y_H_PHASE); 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci input = line->fmt[MSM_VFE_PAD_SINK].height - 1; 8068c2ecf20Sopenharmony_ci output = line->compose.height - 1; 8078c2ecf20Sopenharmony_ci reg = (output << 16) | input; 8088c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + VFE_0_SCALE_ENC_Y_V_IMAGE_SIZE); 8098c2ecf20Sopenharmony_ci 8108c2ecf20Sopenharmony_ci interp_reso = vfe_calc_interp_reso(input, output); 8118c2ecf20Sopenharmony_ci phase_mult = input * (1 << (14 + interp_reso)) / output; 8128c2ecf20Sopenharmony_ci reg = (interp_reso << 28) | phase_mult; 8138c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + VFE_0_SCALE_ENC_Y_V_PHASE); 8148c2ecf20Sopenharmony_ci 8158c2ecf20Sopenharmony_ci writel_relaxed(0x3, vfe->base + VFE_0_SCALE_ENC_CBCR_CFG); 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_ci input = line->fmt[MSM_VFE_PAD_SINK].width - 1; 8188c2ecf20Sopenharmony_ci output = line->compose.width / 2 - 1; 8198c2ecf20Sopenharmony_ci reg = (output << 16) | input; 8208c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + VFE_0_SCALE_ENC_CBCR_H_IMAGE_SIZE); 8218c2ecf20Sopenharmony_ci 8228c2ecf20Sopenharmony_ci interp_reso = vfe_calc_interp_reso(input, output); 8238c2ecf20Sopenharmony_ci phase_mult = input * (1 << (14 + interp_reso)) / output; 8248c2ecf20Sopenharmony_ci reg = (interp_reso << 28) | phase_mult; 8258c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + VFE_0_SCALE_ENC_CBCR_H_PHASE); 8268c2ecf20Sopenharmony_ci 8278c2ecf20Sopenharmony_ci input = line->fmt[MSM_VFE_PAD_SINK].height - 1; 8288c2ecf20Sopenharmony_ci output = line->compose.height - 1; 8298c2ecf20Sopenharmony_ci if (p == V4L2_PIX_FMT_NV12 || p == V4L2_PIX_FMT_NV21) 8308c2ecf20Sopenharmony_ci output = line->compose.height / 2 - 1; 8318c2ecf20Sopenharmony_ci reg = (output << 16) | input; 8328c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + VFE_0_SCALE_ENC_CBCR_V_IMAGE_SIZE); 8338c2ecf20Sopenharmony_ci 8348c2ecf20Sopenharmony_ci interp_reso = vfe_calc_interp_reso(input, output); 8358c2ecf20Sopenharmony_ci phase_mult = input * (1 << (14 + interp_reso)) / output; 8368c2ecf20Sopenharmony_ci reg = (interp_reso << 28) | phase_mult; 8378c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + VFE_0_SCALE_ENC_CBCR_V_PHASE); 8388c2ecf20Sopenharmony_ci} 8398c2ecf20Sopenharmony_ci 8408c2ecf20Sopenharmony_cistatic void vfe_set_crop_cfg(struct vfe_device *vfe, struct vfe_line *line) 8418c2ecf20Sopenharmony_ci{ 8428c2ecf20Sopenharmony_ci u32 p = line->video_out.active_fmt.fmt.pix_mp.pixelformat; 8438c2ecf20Sopenharmony_ci u32 reg; 8448c2ecf20Sopenharmony_ci u16 first, last; 8458c2ecf20Sopenharmony_ci 8468c2ecf20Sopenharmony_ci first = line->crop.left; 8478c2ecf20Sopenharmony_ci last = line->crop.left + line->crop.width - 1; 8488c2ecf20Sopenharmony_ci reg = (first << 16) | last; 8498c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + VFE_0_CROP_ENC_Y_WIDTH); 8508c2ecf20Sopenharmony_ci 8518c2ecf20Sopenharmony_ci first = line->crop.top; 8528c2ecf20Sopenharmony_ci last = line->crop.top + line->crop.height - 1; 8538c2ecf20Sopenharmony_ci reg = (first << 16) | last; 8548c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + VFE_0_CROP_ENC_Y_HEIGHT); 8558c2ecf20Sopenharmony_ci 8568c2ecf20Sopenharmony_ci first = line->crop.left / 2; 8578c2ecf20Sopenharmony_ci last = line->crop.left / 2 + line->crop.width / 2 - 1; 8588c2ecf20Sopenharmony_ci reg = (first << 16) | last; 8598c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + VFE_0_CROP_ENC_CBCR_WIDTH); 8608c2ecf20Sopenharmony_ci 8618c2ecf20Sopenharmony_ci first = line->crop.top; 8628c2ecf20Sopenharmony_ci last = line->crop.top + line->crop.height - 1; 8638c2ecf20Sopenharmony_ci if (p == V4L2_PIX_FMT_NV12 || p == V4L2_PIX_FMT_NV21) { 8648c2ecf20Sopenharmony_ci first = line->crop.top / 2; 8658c2ecf20Sopenharmony_ci last = line->crop.top / 2 + line->crop.height / 2 - 1; 8668c2ecf20Sopenharmony_ci } 8678c2ecf20Sopenharmony_ci reg = (first << 16) | last; 8688c2ecf20Sopenharmony_ci writel_relaxed(reg, vfe->base + VFE_0_CROP_ENC_CBCR_HEIGHT); 8698c2ecf20Sopenharmony_ci} 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_cistatic void vfe_set_clamp_cfg(struct vfe_device *vfe) 8728c2ecf20Sopenharmony_ci{ 8738c2ecf20Sopenharmony_ci u32 val = VFE_0_CLAMP_ENC_MAX_CFG_CH0 | 8748c2ecf20Sopenharmony_ci VFE_0_CLAMP_ENC_MAX_CFG_CH1 | 8758c2ecf20Sopenharmony_ci VFE_0_CLAMP_ENC_MAX_CFG_CH2; 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_CLAMP_ENC_MAX_CFG); 8788c2ecf20Sopenharmony_ci 8798c2ecf20Sopenharmony_ci val = VFE_0_CLAMP_ENC_MIN_CFG_CH0 | 8808c2ecf20Sopenharmony_ci VFE_0_CLAMP_ENC_MIN_CFG_CH1 | 8818c2ecf20Sopenharmony_ci VFE_0_CLAMP_ENC_MIN_CFG_CH2; 8828c2ecf20Sopenharmony_ci 8838c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_CLAMP_ENC_MIN_CFG); 8848c2ecf20Sopenharmony_ci} 8858c2ecf20Sopenharmony_ci 8868c2ecf20Sopenharmony_cistatic void vfe_set_qos(struct vfe_device *vfe) 8878c2ecf20Sopenharmony_ci{ 8888c2ecf20Sopenharmony_ci u32 val = VFE_0_BUS_BDG_QOS_CFG_0_CFG; 8898c2ecf20Sopenharmony_ci u32 val7 = VFE_0_BUS_BDG_QOS_CFG_7_CFG; 8908c2ecf20Sopenharmony_ci 8918c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_QOS_CFG_0); 8928c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_QOS_CFG_1); 8938c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_QOS_CFG_2); 8948c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_QOS_CFG_3); 8958c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_QOS_CFG_4); 8968c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_QOS_CFG_5); 8978c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_QOS_CFG_6); 8988c2ecf20Sopenharmony_ci writel_relaxed(val7, vfe->base + VFE_0_BUS_BDG_QOS_CFG_7); 8998c2ecf20Sopenharmony_ci} 9008c2ecf20Sopenharmony_ci 9018c2ecf20Sopenharmony_cistatic void vfe_set_ds(struct vfe_device *vfe) 9028c2ecf20Sopenharmony_ci{ 9038c2ecf20Sopenharmony_ci u32 val = VFE_0_BUS_BDG_DS_CFG_0_CFG; 9048c2ecf20Sopenharmony_ci u32 val16 = VFE_0_BUS_BDG_DS_CFG_16_CFG; 9058c2ecf20Sopenharmony_ci 9068c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_0); 9078c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_1); 9088c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_2); 9098c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_3); 9108c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_4); 9118c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_5); 9128c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_6); 9138c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_7); 9148c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_8); 9158c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_9); 9168c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_10); 9178c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_11); 9188c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_12); 9198c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_13); 9208c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_14); 9218c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_BUS_BDG_DS_CFG_15); 9228c2ecf20Sopenharmony_ci writel_relaxed(val16, vfe->base + VFE_0_BUS_BDG_DS_CFG_16); 9238c2ecf20Sopenharmony_ci} 9248c2ecf20Sopenharmony_ci 9258c2ecf20Sopenharmony_cistatic void vfe_set_cgc_override(struct vfe_device *vfe, u8 wm, u8 enable) 9268c2ecf20Sopenharmony_ci{ 9278c2ecf20Sopenharmony_ci /* empty */ 9288c2ecf20Sopenharmony_ci} 9298c2ecf20Sopenharmony_ci 9308c2ecf20Sopenharmony_cistatic void vfe_set_camif_cfg(struct vfe_device *vfe, struct vfe_line *line) 9318c2ecf20Sopenharmony_ci{ 9328c2ecf20Sopenharmony_ci u32 val; 9338c2ecf20Sopenharmony_ci 9348c2ecf20Sopenharmony_ci switch (line->fmt[MSM_VFE_PAD_SINK].code) { 9358c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_YUYV8_2X8: 9368c2ecf20Sopenharmony_ci val = VFE_0_CORE_CFG_PIXEL_PATTERN_YCBYCR; 9378c2ecf20Sopenharmony_ci break; 9388c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_YVYU8_2X8: 9398c2ecf20Sopenharmony_ci val = VFE_0_CORE_CFG_PIXEL_PATTERN_YCRYCB; 9408c2ecf20Sopenharmony_ci break; 9418c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_UYVY8_2X8: 9428c2ecf20Sopenharmony_ci default: 9438c2ecf20Sopenharmony_ci val = VFE_0_CORE_CFG_PIXEL_PATTERN_CBYCRY; 9448c2ecf20Sopenharmony_ci break; 9458c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_VYUY8_2X8: 9468c2ecf20Sopenharmony_ci val = VFE_0_CORE_CFG_PIXEL_PATTERN_CRYCBY; 9478c2ecf20Sopenharmony_ci break; 9488c2ecf20Sopenharmony_ci } 9498c2ecf20Sopenharmony_ci 9508c2ecf20Sopenharmony_ci val |= VFE_0_CORE_CFG_COMPOSITE_REG_UPDATE_EN; 9518c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_CORE_CFG); 9528c2ecf20Sopenharmony_ci 9538c2ecf20Sopenharmony_ci val = line->fmt[MSM_VFE_PAD_SINK].width * 2 - 1; 9548c2ecf20Sopenharmony_ci val |= (line->fmt[MSM_VFE_PAD_SINK].height - 1) << 16; 9558c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_CAMIF_FRAME_CFG); 9568c2ecf20Sopenharmony_ci 9578c2ecf20Sopenharmony_ci val = line->fmt[MSM_VFE_PAD_SINK].width * 2 - 1; 9588c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_CAMIF_WINDOW_WIDTH_CFG); 9598c2ecf20Sopenharmony_ci 9608c2ecf20Sopenharmony_ci val = line->fmt[MSM_VFE_PAD_SINK].height - 1; 9618c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_CAMIF_WINDOW_HEIGHT_CFG); 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_ci val = 0xffffffff; 9648c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_CAMIF_SUBSAMPLE_CFG); 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_ci val = 0xffffffff; 9678c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_CAMIF_IRQ_FRAMEDROP_PATTERN); 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_ci val = 0xffffffff; 9708c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_CAMIF_IRQ_SUBSAMPLE_PATTERN); 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_ci val = VFE_0_RDI_CFG_x_MIPI_EN_BITS; 9738c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_RDI_CFG_x(0), val); 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_ci val = VFE_0_CAMIF_CFG_VFE_OUTPUT_EN; 9768c2ecf20Sopenharmony_ci writel_relaxed(val, vfe->base + VFE_0_CAMIF_CFG); 9778c2ecf20Sopenharmony_ci} 9788c2ecf20Sopenharmony_ci 9798c2ecf20Sopenharmony_cistatic void vfe_set_camif_cmd(struct vfe_device *vfe, u8 enable) 9808c2ecf20Sopenharmony_ci{ 9818c2ecf20Sopenharmony_ci u32 cmd; 9828c2ecf20Sopenharmony_ci 9838c2ecf20Sopenharmony_ci cmd = VFE_0_CAMIF_CMD_CLEAR_CAMIF_STATUS | VFE_0_CAMIF_CMD_NO_CHANGE; 9848c2ecf20Sopenharmony_ci writel_relaxed(cmd, vfe->base + VFE_0_CAMIF_CMD); 9858c2ecf20Sopenharmony_ci wmb(); 9868c2ecf20Sopenharmony_ci 9878c2ecf20Sopenharmony_ci if (enable) 9888c2ecf20Sopenharmony_ci cmd = VFE_0_CAMIF_CMD_ENABLE_FRAME_BOUNDARY; 9898c2ecf20Sopenharmony_ci else 9908c2ecf20Sopenharmony_ci cmd = VFE_0_CAMIF_CMD_DISABLE_FRAME_BOUNDARY; 9918c2ecf20Sopenharmony_ci 9928c2ecf20Sopenharmony_ci writel_relaxed(cmd, vfe->base + VFE_0_CAMIF_CMD); 9938c2ecf20Sopenharmony_ci} 9948c2ecf20Sopenharmony_ci 9958c2ecf20Sopenharmony_cistatic void vfe_set_module_cfg(struct vfe_device *vfe, u8 enable) 9968c2ecf20Sopenharmony_ci{ 9978c2ecf20Sopenharmony_ci u32 val_lens = VFE_0_MODULE_LENS_EN_DEMUX | 9988c2ecf20Sopenharmony_ci VFE_0_MODULE_LENS_EN_CHROMA_UPSAMPLE; 9998c2ecf20Sopenharmony_ci u32 val_zoom = VFE_0_MODULE_ZOOM_EN_SCALE_ENC | 10008c2ecf20Sopenharmony_ci VFE_0_MODULE_ZOOM_EN_CROP_ENC; 10018c2ecf20Sopenharmony_ci 10028c2ecf20Sopenharmony_ci if (enable) { 10038c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_MODULE_LENS_EN, val_lens); 10048c2ecf20Sopenharmony_ci vfe_reg_set(vfe, VFE_0_MODULE_ZOOM_EN, val_zoom); 10058c2ecf20Sopenharmony_ci } else { 10068c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, VFE_0_MODULE_LENS_EN, val_lens); 10078c2ecf20Sopenharmony_ci vfe_reg_clr(vfe, VFE_0_MODULE_ZOOM_EN, val_zoom); 10088c2ecf20Sopenharmony_ci } 10098c2ecf20Sopenharmony_ci} 10108c2ecf20Sopenharmony_ci 10118c2ecf20Sopenharmony_cistatic int vfe_camif_wait_for_stop(struct vfe_device *vfe, struct device *dev) 10128c2ecf20Sopenharmony_ci{ 10138c2ecf20Sopenharmony_ci u32 val; 10148c2ecf20Sopenharmony_ci int ret; 10158c2ecf20Sopenharmony_ci 10168c2ecf20Sopenharmony_ci ret = readl_poll_timeout(vfe->base + VFE_0_CAMIF_STATUS, 10178c2ecf20Sopenharmony_ci val, 10188c2ecf20Sopenharmony_ci (val & VFE_0_CAMIF_STATUS_HALT), 10198c2ecf20Sopenharmony_ci CAMIF_TIMEOUT_SLEEP_US, 10208c2ecf20Sopenharmony_ci CAMIF_TIMEOUT_ALL_US); 10218c2ecf20Sopenharmony_ci if (ret < 0) 10228c2ecf20Sopenharmony_ci dev_err(dev, "%s: camif stop timeout\n", __func__); 10238c2ecf20Sopenharmony_ci 10248c2ecf20Sopenharmony_ci return ret; 10258c2ecf20Sopenharmony_ci} 10268c2ecf20Sopenharmony_ci 10278c2ecf20Sopenharmony_cistatic void vfe_isr_read(struct vfe_device *vfe, u32 *value0, u32 *value1) 10288c2ecf20Sopenharmony_ci{ 10298c2ecf20Sopenharmony_ci *value0 = readl_relaxed(vfe->base + VFE_0_IRQ_STATUS_0); 10308c2ecf20Sopenharmony_ci *value1 = readl_relaxed(vfe->base + VFE_0_IRQ_STATUS_1); 10318c2ecf20Sopenharmony_ci 10328c2ecf20Sopenharmony_ci writel_relaxed(*value0, vfe->base + VFE_0_IRQ_CLEAR_0); 10338c2ecf20Sopenharmony_ci writel_relaxed(*value1, vfe->base + VFE_0_IRQ_CLEAR_1); 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_ci wmb(); 10368c2ecf20Sopenharmony_ci writel_relaxed(VFE_0_IRQ_CMD_GLOBAL_CLEAR, vfe->base + VFE_0_IRQ_CMD); 10378c2ecf20Sopenharmony_ci} 10388c2ecf20Sopenharmony_ci 10398c2ecf20Sopenharmony_cistatic void vfe_violation_read(struct vfe_device *vfe) 10408c2ecf20Sopenharmony_ci{ 10418c2ecf20Sopenharmony_ci u32 violation = readl_relaxed(vfe->base + VFE_0_VIOLATION_STATUS); 10428c2ecf20Sopenharmony_ci 10438c2ecf20Sopenharmony_ci pr_err_ratelimited("VFE: violation = 0x%08x\n", violation); 10448c2ecf20Sopenharmony_ci} 10458c2ecf20Sopenharmony_ci 10468c2ecf20Sopenharmony_ci/* 10478c2ecf20Sopenharmony_ci * vfe_isr - ISPIF module interrupt handler 10488c2ecf20Sopenharmony_ci * @irq: Interrupt line 10498c2ecf20Sopenharmony_ci * @dev: VFE device 10508c2ecf20Sopenharmony_ci * 10518c2ecf20Sopenharmony_ci * Return IRQ_HANDLED on success 10528c2ecf20Sopenharmony_ci */ 10538c2ecf20Sopenharmony_cistatic irqreturn_t vfe_isr(int irq, void *dev) 10548c2ecf20Sopenharmony_ci{ 10558c2ecf20Sopenharmony_ci struct vfe_device *vfe = dev; 10568c2ecf20Sopenharmony_ci u32 value0, value1; 10578c2ecf20Sopenharmony_ci int i, j; 10588c2ecf20Sopenharmony_ci 10598c2ecf20Sopenharmony_ci vfe->ops->isr_read(vfe, &value0, &value1); 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci trace_printk("VFE: status0 = 0x%08x, status1 = 0x%08x\n", 10628c2ecf20Sopenharmony_ci value0, value1); 10638c2ecf20Sopenharmony_ci 10648c2ecf20Sopenharmony_ci if (value0 & VFE_0_IRQ_STATUS_0_RESET_ACK) 10658c2ecf20Sopenharmony_ci vfe->isr_ops.reset_ack(vfe); 10668c2ecf20Sopenharmony_ci 10678c2ecf20Sopenharmony_ci if (value1 & VFE_0_IRQ_STATUS_1_VIOLATION) 10688c2ecf20Sopenharmony_ci vfe->ops->violation_read(vfe); 10698c2ecf20Sopenharmony_ci 10708c2ecf20Sopenharmony_ci if (value1 & VFE_0_IRQ_STATUS_1_BUS_BDG_HALT_ACK) 10718c2ecf20Sopenharmony_ci vfe->isr_ops.halt_ack(vfe); 10728c2ecf20Sopenharmony_ci 10738c2ecf20Sopenharmony_ci for (i = VFE_LINE_RDI0; i <= VFE_LINE_PIX; i++) 10748c2ecf20Sopenharmony_ci if (value0 & VFE_0_IRQ_STATUS_0_line_n_REG_UPDATE(i)) 10758c2ecf20Sopenharmony_ci vfe->isr_ops.reg_update(vfe, i); 10768c2ecf20Sopenharmony_ci 10778c2ecf20Sopenharmony_ci if (value0 & VFE_0_IRQ_STATUS_0_CAMIF_SOF) 10788c2ecf20Sopenharmony_ci vfe->isr_ops.sof(vfe, VFE_LINE_PIX); 10798c2ecf20Sopenharmony_ci 10808c2ecf20Sopenharmony_ci for (i = VFE_LINE_RDI0; i <= VFE_LINE_RDI2; i++) 10818c2ecf20Sopenharmony_ci if (value1 & VFE_0_IRQ_STATUS_1_RDIn_SOF(i)) 10828c2ecf20Sopenharmony_ci vfe->isr_ops.sof(vfe, i); 10838c2ecf20Sopenharmony_ci 10848c2ecf20Sopenharmony_ci for (i = 0; i < MSM_VFE_COMPOSITE_IRQ_NUM; i++) 10858c2ecf20Sopenharmony_ci if (value0 & VFE_0_IRQ_STATUS_0_IMAGE_COMPOSITE_DONE_n(i)) { 10868c2ecf20Sopenharmony_ci vfe->isr_ops.comp_done(vfe, i); 10878c2ecf20Sopenharmony_ci for (j = 0; j < ARRAY_SIZE(vfe->wm_output_map); j++) 10888c2ecf20Sopenharmony_ci if (vfe->wm_output_map[j] == VFE_LINE_PIX) 10898c2ecf20Sopenharmony_ci value0 &= ~VFE_0_IRQ_MASK_0_IMAGE_MASTER_n_PING_PONG(j); 10908c2ecf20Sopenharmony_ci } 10918c2ecf20Sopenharmony_ci 10928c2ecf20Sopenharmony_ci for (i = 0; i < MSM_VFE_IMAGE_MASTERS_NUM; i++) 10938c2ecf20Sopenharmony_ci if (value0 & VFE_0_IRQ_STATUS_0_IMAGE_MASTER_n_PING_PONG(i)) 10948c2ecf20Sopenharmony_ci vfe->isr_ops.wm_done(vfe, i); 10958c2ecf20Sopenharmony_ci 10968c2ecf20Sopenharmony_ci return IRQ_HANDLED; 10978c2ecf20Sopenharmony_ci} 10988c2ecf20Sopenharmony_ci 10998c2ecf20Sopenharmony_ciconst struct vfe_hw_ops vfe_ops_4_7 = { 11008c2ecf20Sopenharmony_ci .hw_version_read = vfe_hw_version_read, 11018c2ecf20Sopenharmony_ci .get_ub_size = vfe_get_ub_size, 11028c2ecf20Sopenharmony_ci .global_reset = vfe_global_reset, 11038c2ecf20Sopenharmony_ci .halt_request = vfe_halt_request, 11048c2ecf20Sopenharmony_ci .halt_clear = vfe_halt_clear, 11058c2ecf20Sopenharmony_ci .wm_enable = vfe_wm_enable, 11068c2ecf20Sopenharmony_ci .wm_frame_based = vfe_wm_frame_based, 11078c2ecf20Sopenharmony_ci .wm_line_based = vfe_wm_line_based, 11088c2ecf20Sopenharmony_ci .wm_set_framedrop_period = vfe_wm_set_framedrop_period, 11098c2ecf20Sopenharmony_ci .wm_set_framedrop_pattern = vfe_wm_set_framedrop_pattern, 11108c2ecf20Sopenharmony_ci .wm_set_ub_cfg = vfe_wm_set_ub_cfg, 11118c2ecf20Sopenharmony_ci .bus_reload_wm = vfe_bus_reload_wm, 11128c2ecf20Sopenharmony_ci .wm_set_ping_addr = vfe_wm_set_ping_addr, 11138c2ecf20Sopenharmony_ci .wm_set_pong_addr = vfe_wm_set_pong_addr, 11148c2ecf20Sopenharmony_ci .wm_get_ping_pong_status = vfe_wm_get_ping_pong_status, 11158c2ecf20Sopenharmony_ci .bus_enable_wr_if = vfe_bus_enable_wr_if, 11168c2ecf20Sopenharmony_ci .bus_connect_wm_to_rdi = vfe_bus_connect_wm_to_rdi, 11178c2ecf20Sopenharmony_ci .wm_set_subsample = vfe_wm_set_subsample, 11188c2ecf20Sopenharmony_ci .bus_disconnect_wm_from_rdi = vfe_bus_disconnect_wm_from_rdi, 11198c2ecf20Sopenharmony_ci .set_xbar_cfg = vfe_set_xbar_cfg, 11208c2ecf20Sopenharmony_ci .set_realign_cfg = vfe_set_realign_cfg, 11218c2ecf20Sopenharmony_ci .set_rdi_cid = vfe_set_rdi_cid, 11228c2ecf20Sopenharmony_ci .reg_update = vfe_reg_update, 11238c2ecf20Sopenharmony_ci .reg_update_clear = vfe_reg_update_clear, 11248c2ecf20Sopenharmony_ci .enable_irq_wm_line = vfe_enable_irq_wm_line, 11258c2ecf20Sopenharmony_ci .enable_irq_pix_line = vfe_enable_irq_pix_line, 11268c2ecf20Sopenharmony_ci .enable_irq_common = vfe_enable_irq_common, 11278c2ecf20Sopenharmony_ci .set_demux_cfg = vfe_set_demux_cfg, 11288c2ecf20Sopenharmony_ci .set_scale_cfg = vfe_set_scale_cfg, 11298c2ecf20Sopenharmony_ci .set_crop_cfg = vfe_set_crop_cfg, 11308c2ecf20Sopenharmony_ci .set_clamp_cfg = vfe_set_clamp_cfg, 11318c2ecf20Sopenharmony_ci .set_qos = vfe_set_qos, 11328c2ecf20Sopenharmony_ci .set_ds = vfe_set_ds, 11338c2ecf20Sopenharmony_ci .set_cgc_override = vfe_set_cgc_override, 11348c2ecf20Sopenharmony_ci .set_camif_cfg = vfe_set_camif_cfg, 11358c2ecf20Sopenharmony_ci .set_camif_cmd = vfe_set_camif_cmd, 11368c2ecf20Sopenharmony_ci .set_module_cfg = vfe_set_module_cfg, 11378c2ecf20Sopenharmony_ci .camif_wait_for_stop = vfe_camif_wait_for_stop, 11388c2ecf20Sopenharmony_ci .isr_read = vfe_isr_read, 11398c2ecf20Sopenharmony_ci .violation_read = vfe_violation_read, 11408c2ecf20Sopenharmony_ci .isr = vfe_isr, 11418c2ecf20Sopenharmony_ci}; 1142