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