1 /* 2 * Arm SCP/MCP Software 3 * Copyright (c) 2018-2021, Arm Limited and Contributors. All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 #include "synquacer_mmap.h" 9 10 #include <internal/i2c_depend.h> 11 #include <internal/i2c_driver.h> 12 13 #include <fwk_log.h> 14 #include <fwk_macros.h> 15 16 #include <stdio.h> 17 18 typedef unsigned int ADDR_T; 19 20 #define SCB_BUILDTIME_ASSERT(x) 21 #define FILE_GRP_ID DBG_DRV_I2C 22 #define SCB_Error(x) 23 24 #if CONFIG_SOC_I2C_ENABLE_BITMAP & (1 << 0) 25 static I2C_ST_PACKET_INFO_t m_stI2C0; 26 #endif /* CONFIG_SOC_I2C_ENABLE_BITMAP & (1 << 0) */ 27 28 #if CONFIG_SOC_I2C_ENABLE_BITMAP & (1 << 1) 29 static I2C_ST_PACKET_INFO_t m_stI2C1; 30 #endif /* CONFIG_SOC_I2C_ENABLE_BITMAP & (1 << 1) */ 31 32 #if CONFIG_SOC_I2C_ENABLE_BITMAP & (1 << 2) 33 static I2C_ST_PACKET_INFO_t m_stI2C2; 34 #endif /* CONFIG_SOC_I2C_ENABLE_BITMAP & (1 << 2) */ 35 36 static const ADDR_T i2c_base_addrs[] = CONFIG_SOC_I2C_BASE_ADDRS; 37 static const I2C_TYPE i2c_types[] = CONFIG_SOC_I2C_TYPES; 38 static const I2C_EN_CH_t i2c_channels[] = CONFIG_SOC_I2C_CHANNELS; 39 static const I2C_PARAM_t i2c_params[] = CONFIG_SCB_I2C_PARAMS; 40 i2c_get_channel_structure(I2C_EN_CH_t ch)41I2C_ST_PACKET_INFO_t *i2c_get_channel_structure(I2C_EN_CH_t ch) 42 { 43 I2C_ST_PACKET_INFO_t *result = NULL; 44 45 switch (ch) { 46 #if CONFIG_SOC_I2C_ENABLE_BITMAP & (1 << 0) 47 case I2C_EN_CH0: 48 result = &m_stI2C0; 49 break; 50 #endif /* CONFIG_SOC_I2C_ENABLE_BITMAP & (1 << 0) */ 51 52 #if CONFIG_SOC_I2C_ENABLE_BITMAP & (1 << 1) 53 case I2C_EN_CH1: 54 result = &m_stI2C1; 55 break; 56 #endif /* CONFIG_SOC_I2C_ENABLE_BITMAP & (1 << 1) */ 57 58 #if CONFIG_SOC_I2C_ENABLE_BITMAP & (1 << 2) 59 case I2C_EN_CH2: 60 result = &m_stI2C2; 61 break; 62 #endif /* CONFIG_SOC_I2C_ENABLE_BITMAP & (1 << 2) */ 63 64 default: 65 result = NULL; 66 break; 67 } 68 69 return result; 70 } 71 i2c_construction(void)72void i2c_construction(void) 73 { 74 I2C_ERR_t i2c_err; 75 size_t i; 76 77 /* Check config consistency */ 78 SCB_BUILDTIME_ASSERT( 79 FWK_ARRAY_SIZE(i2c_types) == FWK_ARRAY_SIZE(i2c_base_addrs)); 80 SCB_BUILDTIME_ASSERT( 81 FWK_ARRAY_SIZE(i2c_channels) == FWK_ARRAY_SIZE(i2c_base_addrs)); 82 SCB_BUILDTIME_ASSERT( 83 FWK_ARRAY_SIZE(i2c_params) == FWK_ARRAY_SIZE(i2c_base_addrs)); 84 85 for (i = 0; i < FWK_ARRAY_SIZE(i2c_params); i++) { 86 i2c_err = f_i2c_api_initialize( 87 i2c_get_channel_structure(i2c_channels[i]), 88 i2c_base_addrs[i], 89 i2c_types[i], 90 &i2c_params[i]); 91 if (i2c_err != I2C_ERR_OK) { 92 SCB_Error(i2c_err); 93 FWK_LOG_ERR("[I2C] I2C ch#%d initialize error.", i); 94 } 95 } 96 } 97 i2c_destruction(void)98void i2c_destruction(void) 99 { 100 } 101