1 /* 2 * Copyright (c) 2021 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef __STM32MP1_I2C_H__ 16 #define __STM32MP1_I2C_H__ 17 18 #include "stm32mp1xx_hal_i2c.h" 19 #include "device_resource_if.h" 20 #include "hdf_device_desc.h" 21 #include "hdf_log.h" 22 #include "i2c_core.h" 23 #include "i2c_dev.h" 24 #include "osal_io.h" 25 #include "osal_mem.h" 26 #include "osal_spinlock.h" 27 #include "stm32mp1xx_hal.h" 28 29 #ifdef __cplusplus 30 #if __cplusplus 31 extern "C" { 32 #endif /* __cplusplus */ 33 #endif /* __cplusplus */ 34 35 #define I2C_TIMEOUT 1000 36 #define CLK_IO_MUX_BUF_SIZE 2 37 #define DATA_IO_MUX_BUF_SIZE 2 38 39 struct Mp1xxI2cCntlr { 40 struct I2cCntlr cntlr; 41 OsalSpinlock spin; 42 I2C_HandleTypeDef hi2c; 43 int16_t bus; 44 uint16_t regSize; 45 uint32_t regBasePhy; 46 uint32_t i2cClkIomux[CLK_IO_MUX_BUF_SIZE]; 47 uint32_t i2cDataIomux[DATA_IO_MUX_BUF_SIZE]; 48 }; 49 50 struct Mp1xxTransferData { 51 struct I2cMsg *msgs; 52 int16_t index; 53 int16_t count; 54 }; 55 56 enum gpioPort { 57 GPIO_A = 0, 58 GPIO_B = 1, 59 GPIO_C = 2, 60 GPIO_D = 3, 61 GPIO_E = 4, 62 GPIO_F = 5, 63 GPIO_G = 6, 64 GPIO_H = 7, 65 GPIO_I = 8, 66 GPIO_J = 9, 67 GPIO_K = 10, 68 GPIO_Z = 11, 69 }; 70 71 enum busNum { 72 I2C_1 = 1, 73 I2C_2 = 2, 74 I2C_3 = 3, 75 I2C_4 = 4, 76 I2C_5 = 5, 77 I2C_6 = 6, 78 }; 79 80 #ifdef __cplusplus 81 #if __cplusplus 82 } 83 #endif /* __cplusplus */ 84 #endif /* __cplusplus */ 85 86 #endif 87