mxc_i2c.h 2.7 KB

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