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