1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #ifndef __DRIVERS_I2C_DESIGNWARE_I2C_H__
4 #define __DRIVERS_I2C_DESIGNWARE_I2C_H__
6 #include <device/device.h>
7 #include <device/i2c.h>
10 #if CONFIG(DRIVERS_I2C_DESIGNWARE_DEBUG)
11 #define DW_I2C_DEBUG BIOS_DEBUG
14 #define DW_I2C_DEBUG BIOS_NEVER
16 #endif // CONFIG_DRIVERS_I2C_DESIGNWARE_DEBUG
19 * Timing values are in units of clock period, with the clock speed
20 * provided by the SOC in CONFIG_DRIVERS_I2C_DESIGNWARE_CLOCK_MHZ
21 * Automatic configuration is done based on requested speed, but the
22 * values may need tuned depending on the board and the number of
23 * devices present on the bus.
25 struct dw_i2c_speed_config
{
27 /* SCL high and low period count */
31 * SDA hold time should be 300ns in standard and fast modes
32 * and long enough for deterministic logic level change in
33 * fast-plus and high speed modes.
35 * [15:0] SDA TX Hold Time
36 * [23:16] SDA RX Hold Time
42 * This I2C controller has support for 3 independent speed configs but can
43 * support both FAST_PLUS and HIGH speeds through the same set of speed
44 * config registers. These are treated separately so the speed config values
45 * can be provided via ACPI to the OS.
47 #define DW_I2C_SPEED_CONFIG_COUNT 4
49 struct dw_i2c_bus_config
{
50 /* Bus should be enabled prior to ramstage with temporary base */
52 /* Bus speed in Hz, default is I2C_SPEED_FAST (400 KHz) */
54 /* If rise_time_ns is non-zero the calculations for lcnt and hcnt
55 * registers take into account the times of the bus. However, if
56 * there is a match in speed_config those register values take
60 int data_hold_time_ns
;
61 /* Specific bus speed configuration */
62 struct dw_i2c_speed_config speed_config
[DW_I2C_SPEED_CONFIG_COUNT
];
65 /* Functions to be implemented by SoC code */
67 /* Get base address for early init of I2C controllers. */
68 uintptr_t dw_i2c_get_soc_early_base(unsigned int bus
);
71 * Map given I2C bus number to devfn.
74 * otherwise, devfn(>=0) corresponding to I2C bus number.
76 int dw_i2c_soc_devfn_to_bus(unsigned int devfn
);
79 * Map given bus number to a I2C Controller.
82 * otherwise, devfn(>=0) corresponding to I2C bus number.
84 int dw_i2c_soc_bus_to_devfn(unsigned int bus
);
87 * SoC implemented callback for getting I2C bus configuration.
89 * Returns NULL if i2c config is not found
91 const struct dw_i2c_bus_config
*dw_i2c_get_soc_cfg(unsigned int bus
);
93 /* Get I2C controller base address */
94 uintptr_t dw_i2c_base_address(unsigned int bus
);
97 * Initialize this bus controller and set the speed
99 enum cb_err
dw_i2c_init(unsigned int bus
, const struct dw_i2c_bus_config
*bcfg
);
102 * Generate speed config based on clock
104 enum cb_err
dw_i2c_gen_speed_config(uintptr_t dw_i2c_addr
,
105 enum i2c_speed speed
,
106 const struct dw_i2c_bus_config
*bcfg
,
107 struct dw_i2c_speed_config
*config
);
110 * Map an i2c host controller device to a logical bus number.
113 * >=0 = logical bus number
115 int dw_i2c_soc_dev_to_bus(const struct device
*dev
);
118 * Common device_operations implementation to initialize the i2c host
121 void dw_i2c_dev_init(struct device
*dev
);
124 * Common device_operations implementation to fill ACPI SSDT table for i2c
127 void dw_i2c_acpi_fill_ssdt(const struct device
*dev
);
130 * Common device_operations implementation for i2c host controller ops.
132 extern const struct i2c_bus_operations dw_i2c_bus_ops
;
134 #endif /* __DRIVERS_I2C_DESIGNWARE_I2C_H__ */