1 /* 2 * Copyright (c) 2006-2023, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2021-01-13 Lyons first version 9 * 2021-06-23 RiceChen refactor 10 */ 11 12 #ifndef __DRV_I2C_H__ 13 #define __DRV_I2C_H__ 14 15 #include <board.h> 16 #include "drv_common.h" 17 18 #include "fsl_iomuxc.h" 19 #include "fsl_clock.h" 20 #include "fsl_i2c.h" 21 22 #define IMX_I2C_IRQ_MODE 23 24 struct imx6ull_i2c_config 25 { 26 void *hw_base; /* hardware physical address base */ 27 I2C_Type *I2C; 28 char *name; 29 rt_uint32_t baud_rate; 30 rt_uint32_t clk_ip_name; 31 rt_uint32_t irq_num; 32 33 struct imx6ull_iomuxc scl_gpio; 34 struct imx6ull_iomuxc sda_gpio; 35 36 i2c_master_handle_t master_handle; 37 }; 38 39 struct imx6ull_i2c_bus 40 { 41 struct rt_i2c_bus_device parent; 42 struct imx6ull_i2c_config *config; 43 }; 44 45 #ifdef BSP_USING_I2C1 46 #define I2C1_BUS_CONFIG \ 47 { \ 48 .I2C = I2C1, \ 49 .name = "i2c1", \ 50 .clk_ip_name = kCLOCK_I2c1S, \ 51 .baud_rate = I2C1_BAUD_RATE, \ 52 .irq_num = IMX_INT_I2C1, \ 53 .scl_gpio = {IOMUXC_UART4_TX_DATA_I2C1_SCL, 1, 0x70B0}, \ 54 .sda_gpio = {IOMUXC_UART4_RX_DATA_I2C1_SDA, 1, 0x70B0}, \ 55 } 56 #endif /* BSP_USING_I2C1 */ 57 58 #ifdef BSP_USING_I2C2 59 #define I2C2_BUS_CONFIG \ 60 { \ 61 .I2C = I2C2, \ 62 .name = "i2c2", \ 63 .clk_ip_name = kCLOCK_I2c2S, \ 64 .baud_rate = I2C2_BAUD_RATE, \ 65 .irq_num = IMX_INT_I2C2, \ 66 .scl_gpio = {IOMUXC_UART5_TX_DATA_I2C2_SCL, 1, 0x70B0}, \ 67 .sda_gpio = {IOMUXC_UART5_RX_DATA_I2C2_SDA, 1, 0x70B0}, \ 68 } 69 #endif /* BSP_USING_I2C2 */ 70 71 #ifdef BSP_USING_I2C3 72 #define I2C3_BUS_CONFIG \ 73 { \ 74 .I2C = I2C3, \ 75 .name = "i2c3", \ 76 .clk_ip_name = kCLOCK_I2c3S, \ 77 .baud_rate = I2C3_BAUD_RATE, \ 78 .irq_num = IMX_INT_I2C3, \ 79 .scl_gpio = {IOMUXC_ENET2_RX_DATA0_I2C3_SCL, 1, 0x70B0}, \ 80 .sda_gpio = {IOMUXC_ENET2_RX_DATA1_I2C3_SDA, 1, 0x70B0}, \ 81 } 82 #endif /* BSP_USING_I2C3 */ 83 84 #ifdef BSP_USING_I2C4 85 #define I2C4_BUS_CONFIG \ 86 { \ 87 .I2C = I2C4, \ 88 .name = "i2c4", \ 89 .clk_ip_name = kCLOCK_I2c4S, \ 90 .baud_rate = I2C4_BAUD_RATE, \ 91 .irq_num = IMX_INT_I2C4, \ 92 .scl_gpio = {IOMUXC_UART2_TX_DATA_I2C4_SCL, 1, 0x70B0}, \ 93 .sda_gpio = {IOMUXC_UART2_RX_DATA_I2C4_SDA, 1, 0x70B0}, \ 94 } 95 #endif /* BSP_USING_I2C4 */ 96 97 #endif 98