Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Troy Kisky | d4fdc99 | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved. |
Troy Kisky | d4fdc99 | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 4 | */ |
| 5 | #ifndef __ASM_ARCH_MXC_MXC_I2C_H__ |
| 6 | #define __ASM_ARCH_MXC_MXC_I2C_H__ |
Peng Fan | 4f1a581 | 2016-03-11 16:47:50 +0800 | [diff] [blame] | 7 | #include <asm-generic/gpio.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 8 | #include <asm/mach-imx/iomux-v3.h> |
Troy Kisky | d4fdc99 | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 9 | |
| 10 | struct i2c_pin_ctrl { |
| 11 | iomux_v3_cfg_t i2c_mode; |
| 12 | iomux_v3_cfg_t gpio_mode; |
| 13 | unsigned char gp; |
| 14 | unsigned char spare; |
| 15 | }; |
| 16 | |
| 17 | struct i2c_pads_info { |
| 18 | struct i2c_pin_ctrl scl; |
| 19 | struct i2c_pin_ctrl sda; |
| 20 | }; |
| 21 | |
Peng Fan | 8262cb1 | 2015-05-15 07:29:12 +0800 | [diff] [blame] | 22 | /* |
| 23 | * Information about i2c controller |
| 24 | * struct mxc_i2c_bus - information about the i2c[x] bus |
| 25 | * @index: i2c bus index |
| 26 | * @base: Address of I2C bus controller |
| 27 | * @driver_data: Flags for different platforms, such as I2C_QUIRK_FLAG. |
| 28 | * @speed: Speed of I2C bus |
| 29 | * @pads_info: pinctrl info for this i2c bus, will be used when pinctrl is ok. |
| 30 | * The following two is only to be compatible with non-DM part. |
| 31 | * @idle_bus_fn: function to force bus idle |
| 32 | * @idle_bus_data: parameter for idle_bus_fun |
Peng Fan | 4f1a581 | 2016-03-11 16:47:50 +0800 | [diff] [blame] | 33 | * For DM: |
| 34 | * bus: The device structure for i2c bus controller |
| 35 | * scl-gpio: specify the gpio related to SCL pin |
| 36 | * sda-gpio: specify the gpio related to SDA pin |
Peng Fan | 8262cb1 | 2015-05-15 07:29:12 +0800 | [diff] [blame] | 37 | */ |
| 38 | struct mxc_i2c_bus { |
| 39 | /* |
| 40 | * board file can use this index to locate which i2c_pads_info is for |
| 41 | * i2c_idle_bus. When pinmux is implement, this entry can be |
| 42 | * discarded. Here we do not use dev->seq, because we do not want to |
| 43 | * export device to board file. |
| 44 | */ |
| 45 | int index; |
| 46 | ulong base; |
| 47 | ulong driver_data; |
| 48 | int speed; |
| 49 | struct i2c_pads_info *pads_info; |
| 50 | #ifndef CONFIG_DM_I2C |
| 51 | int (*idle_bus_fn)(void *p); |
| 52 | void *idle_bus_data; |
Peng Fan | 4f1a581 | 2016-03-11 16:47:50 +0800 | [diff] [blame] | 53 | #else |
| 54 | struct udevice *bus; |
| 55 | /* Use gpio to force bus idle when bus state is abnormal */ |
| 56 | struct gpio_desc scl_gpio; |
| 57 | struct gpio_desc sda_gpio; |
Peng Fan | 8262cb1 | 2015-05-15 07:29:12 +0800 | [diff] [blame] | 58 | #endif |
| 59 | }; |
| 60 | |
Nikita Kiryanov | ef73783 | 2014-08-20 15:08:54 +0300 | [diff] [blame] | 61 | #if defined(CONFIG_MX6QDL) |
| 62 | #define I2C_PADS(name, scl_i2c, scl_gpio, scl_gp, sda_i2c, sda_gpio, sda_gp) \ |
| 63 | struct i2c_pads_info mx6q_##name = { \ |
| 64 | .scl = { \ |
| 65 | .i2c_mode = MX6Q_##scl_i2c, \ |
| 66 | .gpio_mode = MX6Q_##scl_gpio, \ |
| 67 | .gp = scl_gp, \ |
| 68 | }, \ |
| 69 | .sda = { \ |
| 70 | .i2c_mode = MX6Q_##sda_i2c, \ |
| 71 | .gpio_mode = MX6Q_##sda_gpio, \ |
| 72 | .gp = sda_gp, \ |
| 73 | } \ |
| 74 | }; \ |
| 75 | struct i2c_pads_info mx6s_##name = { \ |
| 76 | .scl = { \ |
| 77 | .i2c_mode = MX6DL_##scl_i2c, \ |
| 78 | .gpio_mode = MX6DL_##scl_gpio, \ |
| 79 | .gp = scl_gp, \ |
| 80 | }, \ |
| 81 | .sda = { \ |
| 82 | .i2c_mode = MX6DL_##sda_i2c, \ |
| 83 | .gpio_mode = MX6DL_##sda_gpio, \ |
| 84 | .gp = sda_gp, \ |
| 85 | } \ |
| 86 | }; |
| 87 | |
| 88 | |
| 89 | #define I2C_PADS_INFO(name) \ |
Eran Matityahu | 22538ac | 2018-01-26 16:11:37 +0200 | [diff] [blame] | 90 | (is_mx6dq() || is_mx6dqp()) ? &mx6q_##name : &mx6s_##name |
Nikita Kiryanov | ef73783 | 2014-08-20 15:08:54 +0300 | [diff] [blame] | 91 | #endif |
| 92 | |
Simon Glass | 8d91436 | 2014-10-01 19:57:24 -0600 | [diff] [blame] | 93 | int setup_i2c(unsigned i2c_index, int speed, int slave_addr, |
| 94 | struct i2c_pads_info *p); |
Peng Fan | 8262cb1 | 2015-05-15 07:29:12 +0800 | [diff] [blame] | 95 | void bus_i2c_init(int index, int speed, int slave_addr, |
Troy Kisky | d4fdc99 | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 96 | int (*idle_bus_fn)(void *p), void *p); |
Peng Fan | 8262cb1 | 2015-05-15 07:29:12 +0800 | [diff] [blame] | 97 | int force_idle_bus(void *priv); |
| 98 | int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus); |
Troy Kisky | d4fdc99 | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 99 | #endif |