mxc_i2c.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #ifndef __ASM_ARCH_MXC_MXC_I2C_H__
  7. #define __ASM_ARCH_MXC_MXC_I2C_H__
  8. #include <asm-generic/gpio.h>
  9. #include <asm/imx-common/iomux-v3.h>
  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. struct i2c_pads_info {
  17. struct i2c_pin_ctrl scl;
  18. struct i2c_pin_ctrl sda;
  19. };
  20. /*
  21. * Information about i2c controller
  22. * struct mxc_i2c_bus - information about the i2c[x] bus
  23. * @index: i2c bus index
  24. * @base: Address of I2C bus controller
  25. * @driver_data: Flags for different platforms, such as I2C_QUIRK_FLAG.
  26. * @speed: Speed of I2C bus
  27. * @pads_info: pinctrl info for this i2c bus, will be used when pinctrl is ok.
  28. * The following two is only to be compatible with non-DM part.
  29. * @idle_bus_fn: function to force bus idle
  30. * @idle_bus_data: parameter for idle_bus_fun
  31. * For DM:
  32. * bus: The device structure for i2c bus controller
  33. * scl-gpio: specify the gpio related to SCL pin
  34. * sda-gpio: specify the gpio related to SDA pin
  35. */
  36. struct mxc_i2c_bus {
  37. /*
  38. * board file can use this index to locate which i2c_pads_info is for
  39. * i2c_idle_bus. When pinmux is implement, this entry can be
  40. * discarded. Here we do not use dev->seq, because we do not want to
  41. * export device to board file.
  42. */
  43. int index;
  44. ulong base;
  45. ulong driver_data;
  46. int speed;
  47. struct i2c_pads_info *pads_info;
  48. #ifndef CONFIG_DM_I2C
  49. int (*idle_bus_fn)(void *p);
  50. void *idle_bus_data;
  51. #else
  52. struct udevice *bus;
  53. /* Use gpio to force bus idle when bus state is abnormal */
  54. struct gpio_desc scl_gpio;
  55. struct gpio_desc sda_gpio;
  56. #endif
  57. };
  58. #if defined(CONFIG_MX6QDL)
  59. #define I2C_PADS(name, scl_i2c, scl_gpio, scl_gp, sda_i2c, sda_gpio, sda_gp) \
  60. struct i2c_pads_info mx6q_##name = { \
  61. .scl = { \
  62. .i2c_mode = MX6Q_##scl_i2c, \
  63. .gpio_mode = MX6Q_##scl_gpio, \
  64. .gp = scl_gp, \
  65. }, \
  66. .sda = { \
  67. .i2c_mode = MX6Q_##sda_i2c, \
  68. .gpio_mode = MX6Q_##sda_gpio, \
  69. .gp = sda_gp, \
  70. } \
  71. }; \
  72. struct i2c_pads_info mx6s_##name = { \
  73. .scl = { \
  74. .i2c_mode = MX6DL_##scl_i2c, \
  75. .gpio_mode = MX6DL_##scl_gpio, \
  76. .gp = scl_gp, \
  77. }, \
  78. .sda = { \
  79. .i2c_mode = MX6DL_##sda_i2c, \
  80. .gpio_mode = MX6DL_##sda_gpio, \
  81. .gp = sda_gp, \
  82. } \
  83. };
  84. #define I2C_PADS_INFO(name) \
  85. (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D)) ? \
  86. &mx6q_##name : &mx6s_##name
  87. #endif
  88. int setup_i2c(unsigned i2c_index, int speed, int slave_addr,
  89. struct i2c_pads_info *p);
  90. void bus_i2c_init(int index, int speed, int slave_addr,
  91. int (*idle_bus_fn)(void *p), void *p);
  92. int force_idle_bus(void *priv);
  93. int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus);
  94. #endif