1 /* 2 * Copyright (c) 2023 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #include "hpm_mipi_csi_drv.h" 9 10 mipi_csi_get_defconfig(mipi_csi_config_t * cfg)11void mipi_csi_get_defconfig(mipi_csi_config_t *cfg) 12 { 13 cfg->data_type = mipi_csi_data_type_rgb565; 14 cfg->lanes = 2; 15 } 16 mipi_csi_init(MIPI_CSI_Type * ptr,mipi_csi_config_t * cfg)17void mipi_csi_init(MIPI_CSI_Type *ptr, mipi_csi_config_t *cfg) 18 { 19 ptr->CSI2_RESETN = 0x01; 20 ptr->IPI_SOFTRSTN = 0x01; 21 22 if (cfg->lanes < 1 || cfg->lanes > 2) 23 cfg->lanes = 2; 24 ptr->N_LANES = MIPI_CSI_N_LANES_N_LANES_SET(cfg->lanes - 1); 25 26 /* 27 * only camera mode 28 */ 29 ptr->IPI_MODE = MIPI_CSI_IPI_MODE_IPI_ENABLE_MASK; 30 ptr->IPI_DATA_TYPE = (ptr->IPI_DATA_TYPE & ~(MIPI_CSI_IPI_DATA_TYPE_IPI_DATA_TYPE_MASK)) | 31 MIPI_CSI_IPI_DATA_TYPE_IPI_DATA_TYPE_SET(cfg->data_type); 32 33 ptr->IPI_MEM_FLASH |= MIPI_CSI_IPI_MEM_FLASH_IPI_AUTO_FLUSH_MASK; 34 35 /* 36 * [16]: 0: Controller selects it automatically 37 */ 38 ptr->IPI_ADV_FEATURES = 0; 39 40 ptr->IPI_HSD_TIME = 20; 41 ptr->IPI_HSA_TIME = 0; 42 } 43 mipi_csi_phy_poweron(MIPI_CSI_Type * ptr)44void mipi_csi_phy_poweron(MIPI_CSI_Type *ptr) 45 { 46 /* 47 * MIPI CSI : PHY 48 * ---------------------------- 49 * PHY_SHUTDOWNZ : ~iddqen 50 * DPHY_RSTZ : hw_rst_n 51 */ 52 ptr->DPHY_RSTZ = 0x01; 53 ptr->PHY_SHUTDOWNZ = 0x01; 54 } 55 mipi_csi_phy_powerdown(MIPI_CSI_Type * ptr)56void mipi_csi_phy_powerdown(MIPI_CSI_Type *ptr) 57 { 58 /* 59 * MIPI CSI : PHY 60 * ---------------------------- 61 * PHY_SHUTDOWNZ : ~iddqen 62 * DPHY_RSTZ : hw_rst_n 63 */ 64 ptr->DPHY_RSTZ = 0x00; 65 ptr->PHY_SHUTDOWNZ = 0x00; 66 } 67 68 69