mxc_i2c.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #if CONFIG_IS_ENABLED(CLK)
  10. #include <clk.h>
  11. #endif
  12. struct i2c_pin_ctrl {
  13. iomux_v3_cfg_t i2c_mode;
  14. iomux_v3_cfg_t gpio_mode;
  15. unsigned char gp;
  16. unsigned char spare;
  17. };
  18. struct i2c_pads_info {
  19. struct i2c_pin_ctrl scl;
  20. struct i2c_pin_ctrl sda;
  21. };
  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
  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
  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(dev), 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. #if CONFIG_IS_ENABLED(CLK)
  51. struct clk per_clk;
  52. #endif
  53. #ifndef CONFIG_DM_I2C
  54. int (*idle_bus_fn)(void *p);
  55. void *idle_bus_data;
  56. #else
  57. struct udevice *bus;
  58. /* Use gpio to force bus idle when bus state is abnormal */
  59. struct gpio_desc scl_gpio;
  60. struct gpio_desc sda_gpio;
  61. #endif
  62. };
  63. #if defined(CONFIG_MX6QDL)
  64. #define I2C_PADS(name, scl_i2c, scl_gpio, scl_gp, sda_i2c, sda_gpio, sda_gp) \
  65. struct i2c_pads_info mx6q_##name = { \
  66. .scl = { \
  67. .i2c_mode = MX6Q_##scl_i2c, \
  68. .gpio_mode = MX6Q_##scl_gpio, \
  69. .gp = scl_gp, \
  70. }, \
  71. .sda = { \
  72. .i2c_mode = MX6Q_##sda_i2c, \
  73. .gpio_mode = MX6Q_##sda_gpio, \
  74. .gp = sda_gp, \
  75. } \
  76. }; \
  77. struct i2c_pads_info mx6s_##name = { \
  78. .scl = { \
  79. .i2c_mode = MX6DL_##scl_i2c, \
  80. .gpio_mode = MX6DL_##scl_gpio, \
  81. .gp = scl_gp, \
  82. }, \
  83. .sda = { \
  84. .i2c_mode = MX6DL_##sda_i2c, \
  85. .gpio_mode = MX6DL_##sda_gpio, \
  86. .gp = sda_gp, \
  87. } \
  88. };
  89. #define I2C_PADS_INFO(name) \
  90. (is_mx6dq() || is_mx6dqp()) ? &mx6q_##name : &mx6s_##name
  91. #endif
  92. int setup_i2c(unsigned i2c_index, int speed, int slave_addr,
  93. struct i2c_pads_info *p);
  94. void bus_i2c_init(int index, int speed, int slave_addr,
  95. int (*idle_bus_fn)(void *p), void *p);
  96. int force_idle_bus(void *priv);
  97. int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus);
  98. #endif