1552a848eSStefano Babic /* 2552a848eSStefano Babic * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved. 3552a848eSStefano Babic * 4552a848eSStefano Babic * SPDX-License-Identifier: GPL-2.0+ 5552a848eSStefano Babic */ 6552a848eSStefano Babic #ifndef __ASM_ARCH_MXC_MXC_I2C_H__ 7552a848eSStefano Babic #define __ASM_ARCH_MXC_MXC_I2C_H__ 8552a848eSStefano Babic #include <asm-generic/gpio.h> 9552a848eSStefano Babic #include <asm/mach-imx/iomux-v3.h> 10552a848eSStefano Babic 11552a848eSStefano Babic struct i2c_pin_ctrl { 12552a848eSStefano Babic iomux_v3_cfg_t i2c_mode; 13552a848eSStefano Babic iomux_v3_cfg_t gpio_mode; 14552a848eSStefano Babic unsigned char gp; 15552a848eSStefano Babic unsigned char spare; 16552a848eSStefano Babic }; 17552a848eSStefano Babic 18552a848eSStefano Babic struct i2c_pads_info { 19552a848eSStefano Babic struct i2c_pin_ctrl scl; 20552a848eSStefano Babic struct i2c_pin_ctrl sda; 21552a848eSStefano Babic }; 22552a848eSStefano Babic 23552a848eSStefano Babic /* 24552a848eSStefano Babic * Information about i2c controller 25552a848eSStefano Babic * struct mxc_i2c_bus - information about the i2c[x] bus 26552a848eSStefano Babic * @index: i2c bus index 27552a848eSStefano Babic * @base: Address of I2C bus controller 28552a848eSStefano Babic * @driver_data: Flags for different platforms, such as I2C_QUIRK_FLAG. 29552a848eSStefano Babic * @speed: Speed of I2C bus 30552a848eSStefano Babic * @pads_info: pinctrl info for this i2c bus, will be used when pinctrl is ok. 31552a848eSStefano Babic * The following two is only to be compatible with non-DM part. 32552a848eSStefano Babic * @idle_bus_fn: function to force bus idle 33552a848eSStefano Babic * @idle_bus_data: parameter for idle_bus_fun 34552a848eSStefano Babic * For DM: 35552a848eSStefano Babic * bus: The device structure for i2c bus controller 36552a848eSStefano Babic * scl-gpio: specify the gpio related to SCL pin 37552a848eSStefano Babic * sda-gpio: specify the gpio related to SDA pin 38552a848eSStefano Babic */ 39552a848eSStefano Babic struct mxc_i2c_bus { 40552a848eSStefano Babic /* 41552a848eSStefano Babic * board file can use this index to locate which i2c_pads_info is for 42552a848eSStefano Babic * i2c_idle_bus. When pinmux is implement, this entry can be 43552a848eSStefano Babic * discarded. Here we do not use dev->seq, because we do not want to 44552a848eSStefano Babic * export device to board file. 45552a848eSStefano Babic */ 46552a848eSStefano Babic int index; 47552a848eSStefano Babic ulong base; 48552a848eSStefano Babic ulong driver_data; 49552a848eSStefano Babic int speed; 50552a848eSStefano Babic struct i2c_pads_info *pads_info; 51552a848eSStefano Babic #ifndef CONFIG_DM_I2C 52552a848eSStefano Babic int (*idle_bus_fn)(void *p); 53552a848eSStefano Babic void *idle_bus_data; 54552a848eSStefano Babic #else 55552a848eSStefano Babic struct udevice *bus; 56552a848eSStefano Babic /* Use gpio to force bus idle when bus state is abnormal */ 57552a848eSStefano Babic struct gpio_desc scl_gpio; 58552a848eSStefano Babic struct gpio_desc sda_gpio; 59552a848eSStefano Babic #endif 60552a848eSStefano Babic }; 61552a848eSStefano Babic 62552a848eSStefano Babic #if defined(CONFIG_MX6QDL) 63552a848eSStefano Babic #define I2C_PADS(name, scl_i2c, scl_gpio, scl_gp, sda_i2c, sda_gpio, sda_gp) \ 64552a848eSStefano Babic struct i2c_pads_info mx6q_##name = { \ 65552a848eSStefano Babic .scl = { \ 66552a848eSStefano Babic .i2c_mode = MX6Q_##scl_i2c, \ 67552a848eSStefano Babic .gpio_mode = MX6Q_##scl_gpio, \ 68552a848eSStefano Babic .gp = scl_gp, \ 69552a848eSStefano Babic }, \ 70552a848eSStefano Babic .sda = { \ 71552a848eSStefano Babic .i2c_mode = MX6Q_##sda_i2c, \ 72552a848eSStefano Babic .gpio_mode = MX6Q_##sda_gpio, \ 73552a848eSStefano Babic .gp = sda_gp, \ 74552a848eSStefano Babic } \ 75552a848eSStefano Babic }; \ 76552a848eSStefano Babic struct i2c_pads_info mx6s_##name = { \ 77552a848eSStefano Babic .scl = { \ 78552a848eSStefano Babic .i2c_mode = MX6DL_##scl_i2c, \ 79552a848eSStefano Babic .gpio_mode = MX6DL_##scl_gpio, \ 80552a848eSStefano Babic .gp = scl_gp, \ 81552a848eSStefano Babic }, \ 82552a848eSStefano Babic .sda = { \ 83552a848eSStefano Babic .i2c_mode = MX6DL_##sda_i2c, \ 84552a848eSStefano Babic .gpio_mode = MX6DL_##sda_gpio, \ 85552a848eSStefano Babic .gp = sda_gp, \ 86552a848eSStefano Babic } \ 87552a848eSStefano Babic }; 88552a848eSStefano Babic 89552a848eSStefano Babic 90552a848eSStefano Babic #define I2C_PADS_INFO(name) \ 91*a1ffd9e2SEran Matityahu (is_mx6dq() || is_mx6dqp()) ? &mx6q_##name : &mx6s_##name 92552a848eSStefano Babic #endif 93552a848eSStefano Babic 94552a848eSStefano Babic int setup_i2c(unsigned i2c_index, int speed, int slave_addr, 95552a848eSStefano Babic struct i2c_pads_info *p); 96552a848eSStefano Babic void bus_i2c_init(int index, int speed, int slave_addr, 97552a848eSStefano Babic int (*idle_bus_fn)(void *p), void *p); 98552a848eSStefano Babic int force_idle_bus(void *priv); 99552a848eSStefano Babic int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus); 100552a848eSStefano Babic #endif 101