blob: a54976e7889fb13dcf1a429efb938a062036785d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vipin KUMARfc9589f2010-01-15 19:15:44 +05302/*
3 * (C) Copyright 2009
Patrick Delaunaya6b185e2022-05-20 18:38:10 +02004 * Vipin Kumar, STMicroelectronics, vipin.kumar@st.com.
Vipin KUMARfc9589f2010-01-15 19:15:44 +05305 */
6
Simon Glass9b7af642020-01-23 11:48:06 -07007#include <clk.h>
Stefan Roese3cb27962016-04-21 08:19:41 +02008#include <dm.h>
Stefan Roeseef6073e2014-10-28 12:12:00 +01009#include <i2c.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070011#include <malloc.h>
Stefan Roese38481202016-04-21 08:19:42 +020012#include <pci.h>
Dinh Nguyen08794aa2018-04-04 17:18:24 -050013#include <reset.h>
Vipin KUMARfc9589f2010-01-15 19:15:44 +053014#include <asm/io.h>
Simon Glassdbd79542020-05-10 11:40:11 -060015#include <linux/delay.h>
Vipin KUMAR3f64acb2012-02-26 23:13:29 +000016#include "designware_i2c.h"
Simon Glass9bc15642020-02-03 07:36:16 -070017#include <dm/device_compat.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070018#include <linux/err.h>
Vipin KUMARfc9589f2010-01-15 19:15:44 +053019
Raul E Rangel057be512020-04-22 10:13:54 -060020/*
21 * This assigned unique hex value is constant and is derived from the two ASCII
22 * letters 'DW' followed by a 16-bit unsigned number
23 */
24#define DW_I2C_COMP_TYPE 0x44570140
25
Heinrich Schuchardtd6d67fc2023-10-13 15:09:39 +020026/*
27 * This constant is used to calculate when during the clock high phase the data
28 * bit shall be read. The value was copied from the Linux v6.5 function
29 * i2c_dw_scl_hcnt() which provides the following explanation:
30 *
31 * "This is just an experimental rule: the tHD;STA period turned out to be
32 * proportinal to (_HCNT + 3). With this setting, we could meet both tHIGH and
33 * tHD;STA timing specs."
34 */
35#define T_HD_STA_OFFSET 3
36
Simon Glassbd9ca8d2019-02-16 20:24:39 -070037static int dw_i2c_enable(struct i2c_regs *i2c_base, bool enable)
Stefan Roeseabb3e132016-04-27 09:02:12 +020038{
39 u32 ena = enable ? IC_ENABLE_0B : 0;
Stefan Roese3bc33ba2016-04-21 08:19:38 +020040 int timeout = 100;
41
42 do {
43 writel(ena, &i2c_base->ic_enable);
44 if ((readl(&i2c_base->ic_enable_status) & IC_ENABLE_0B) == ena)
Simon Glassbd9ca8d2019-02-16 20:24:39 -070045 return 0;
Stefan Roese3bc33ba2016-04-21 08:19:38 +020046
47 /*
48 * Wait 10 times the signaling period of the highest I2C
49 * transfer supported by the driver (for 400KHz this is
50 * 25us) as described in the DesignWare I2C databook.
51 */
52 udelay(25);
53 } while (timeout--);
Stefan Roese3bc33ba2016-04-21 08:19:38 +020054 printf("timeout in %sabling I2C adapter\n", enable ? "en" : "dis");
Simon Glassbd9ca8d2019-02-16 20:24:39 -070055
56 return -ETIMEDOUT;
Stefan Roese3bc33ba2016-04-21 08:19:38 +020057}
58
Simon Glassc7181102020-01-23 11:48:14 -070059/* High and low times in different speed modes (in ns) */
60enum {
61 /* SDA Hold Time */
62 DEFAULT_SDA_HOLD_TIME = 300,
63};
64
65/**
66 * calc_counts() - Convert a period to a number of IC clk cycles
67 *
68 * @ic_clk: Input clock in Hz
69 * @period_ns: Period to represent, in ns
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010070 * Return: calculated count
Simon Glassc7181102020-01-23 11:48:14 -070071 */
72static uint calc_counts(uint ic_clk, uint period_ns)
73{
74 return DIV_ROUND_UP(ic_clk / 1000 * period_ns, NANO_TO_KILO);
75}
76
77/**
78 * struct i2c_mode_info - Information about an I2C speed mode
79 *
80 * Each speed mode has its own characteristics. This struct holds these to aid
81 * calculations in dw_i2c_calc_timing().
82 *
83 * @speed: Speed in Hz
84 * @min_scl_lowtime_ns: Minimum value for SCL low period in ns
85 * @min_scl_hightime_ns: Minimum value for SCL high period in ns
86 * @def_rise_time_ns: Default rise time in ns
87 * @def_fall_time_ns: Default fall time in ns
88 */
89struct i2c_mode_info {
90 int speed;
91 int min_scl_hightime_ns;
92 int min_scl_lowtime_ns;
93 int def_rise_time_ns;
94 int def_fall_time_ns;
95};
96
97static const struct i2c_mode_info info_for_mode[] = {
98 [IC_SPEED_MODE_STANDARD] = {
Simon Glassac77bae2020-01-23 11:48:18 -070099 I2C_SPEED_STANDARD_RATE,
Simon Glassc7181102020-01-23 11:48:14 -0700100 MIN_SS_SCL_HIGHTIME,
101 MIN_SS_SCL_LOWTIME,
102 1000,
103 300,
104 },
105 [IC_SPEED_MODE_FAST] = {
Simon Glassac77bae2020-01-23 11:48:18 -0700106 I2C_SPEED_FAST_RATE,
Simon Glassc7181102020-01-23 11:48:14 -0700107 MIN_FS_SCL_HIGHTIME,
108 MIN_FS_SCL_LOWTIME,
109 300,
110 300,
111 },
Simon Glass45649222020-01-23 11:48:23 -0700112 [IC_SPEED_MODE_FAST_PLUS] = {
113 I2C_SPEED_FAST_PLUS_RATE,
114 MIN_FP_SCL_HIGHTIME,
115 MIN_FP_SCL_LOWTIME,
116 260,
117 500,
118 },
Simon Glassc7181102020-01-23 11:48:14 -0700119 [IC_SPEED_MODE_HIGH] = {
Simon Glassac77bae2020-01-23 11:48:18 -0700120 I2C_SPEED_HIGH_RATE,
Simon Glassc7181102020-01-23 11:48:14 -0700121 MIN_HS_SCL_HIGHTIME,
122 MIN_HS_SCL_LOWTIME,
123 120,
124 120,
125 },
126};
127
128/**
129 * dw_i2c_calc_timing() - Calculate the timings to use for a bus
130 *
131 * @priv: Bus private information (NULL if not using driver model)
132 * @mode: Speed mode to use
133 * @ic_clk: IC clock speed in Hz
134 * @spk_cnt: Spike-suppression count
135 * @config: Returns value to use
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100136 * Return: 0 if OK, -EINVAL if the calculation failed due to invalid data
Simon Glassc7181102020-01-23 11:48:14 -0700137 */
138static int dw_i2c_calc_timing(struct dw_i2c *priv, enum i2c_speed_mode mode,
139 int ic_clk, int spk_cnt,
140 struct dw_i2c_speed_config *config)
141{
142 int fall_cnt, rise_cnt, min_tlow_cnt, min_thigh_cnt;
143 int hcnt, lcnt, period_cnt, diff, tot;
144 int sda_hold_time_ns, scl_rise_time_ns, scl_fall_time_ns;
145 const struct i2c_mode_info *info;
146
147 /*
148 * Find the period, rise, fall, min tlow, and min thigh in terms of
149 * counts of the IC clock
150 */
151 info = &info_for_mode[mode];
152 period_cnt = ic_clk / info->speed;
153 scl_rise_time_ns = priv && priv->scl_rise_time_ns ?
154 priv->scl_rise_time_ns : info->def_rise_time_ns;
155 scl_fall_time_ns = priv && priv->scl_fall_time_ns ?
156 priv->scl_fall_time_ns : info->def_fall_time_ns;
157 rise_cnt = calc_counts(ic_clk, scl_rise_time_ns);
158 fall_cnt = calc_counts(ic_clk, scl_fall_time_ns);
159 min_tlow_cnt = calc_counts(ic_clk, info->min_scl_lowtime_ns);
160 min_thigh_cnt = calc_counts(ic_clk, info->min_scl_hightime_ns);
161
Simon Glass46aadb62020-07-07 21:32:27 -0600162 debug("dw_i2c: mode %d, ic_clk %d, speed %d, period %d rise %d fall %d tlow %d thigh %d spk %d\n",
163 mode, ic_clk, info->speed, period_cnt, rise_cnt, fall_cnt,
164 min_tlow_cnt, min_thigh_cnt, spk_cnt);
Simon Glassc7181102020-01-23 11:48:14 -0700165
166 /*
167 * Back-solve for hcnt and lcnt according to the following equations:
Heinrich Schuchardtd6d67fc2023-10-13 15:09:39 +0200168 * SCL_High_time = [(HCNT + IC_*_SPKLEN + T_HD_STA_OFFSET) * ic_clk] + SCL_Fall_time
Simon Glassc7181102020-01-23 11:48:14 -0700169 * SCL_Low_time = [(LCNT + 1) * ic_clk] - SCL_Fall_time + SCL_Rise_time
170 */
Heinrich Schuchardtd6d67fc2023-10-13 15:09:39 +0200171 hcnt = min_thigh_cnt - fall_cnt - T_HD_STA_OFFSET - spk_cnt;
Simon Glassc7181102020-01-23 11:48:14 -0700172 lcnt = min_tlow_cnt - rise_cnt + fall_cnt - 1;
173
174 if (hcnt < 0 || lcnt < 0) {
175 debug("dw_i2c: bad counts. hcnt = %d lcnt = %d\n", hcnt, lcnt);
Simon Glass46aadb62020-07-07 21:32:27 -0600176 return log_msg_ret("counts", -EINVAL);
Simon Glassc7181102020-01-23 11:48:14 -0700177 }
178
179 /*
180 * Now add things back up to ensure the period is hit. If it is off,
181 * split the difference and bias to lcnt for remainder
182 */
Heinrich Schuchardtd6d67fc2023-10-13 15:09:39 +0200183 tot = hcnt + lcnt + T_HD_STA_OFFSET + spk_cnt + rise_cnt + 1;
Simon Glassc7181102020-01-23 11:48:14 -0700184
185 if (tot < period_cnt) {
186 diff = (period_cnt - tot) / 2;
187 hcnt += diff;
188 lcnt += diff;
Heinrich Schuchardtd6d67fc2023-10-13 15:09:39 +0200189 tot = hcnt + lcnt + T_HD_STA_OFFSET + spk_cnt + rise_cnt + 1;
Simon Glassc7181102020-01-23 11:48:14 -0700190 lcnt += period_cnt - tot;
191 }
192
193 config->scl_lcnt = lcnt;
194 config->scl_hcnt = hcnt;
195
196 /* Use internal default unless other value is specified */
197 sda_hold_time_ns = priv && priv->sda_hold_time_ns ?
198 priv->sda_hold_time_ns : DEFAULT_SDA_HOLD_TIME;
199 config->sda_hold = calc_counts(ic_clk, sda_hold_time_ns);
200
201 debug("dw_i2c: hcnt = %d lcnt = %d sda hold = %d\n", hcnt, lcnt,
202 config->sda_hold);
203
204 return 0;
205}
206
Simon Glass02b880e2020-04-22 10:13:53 -0600207/**
208 * calc_bus_speed() - Calculate the config to use for a particular i2c speed
209 *
210 * @priv: Private information for the driver (NULL if not using driver model)
211 * @i2c_base: Registers for the I2C controller
212 * @speed: Required i2c speed in Hz
213 * @bus_clk: Input clock to the I2C controller in Hz (e.g. IC_CLK)
214 * @config: Returns the config to use for this speed
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100215 * Return: 0 if OK, -ve on error
Simon Glass02b880e2020-04-22 10:13:53 -0600216 */
217static int calc_bus_speed(struct dw_i2c *priv, struct i2c_regs *regs, int speed,
218 ulong bus_clk, struct dw_i2c_speed_config *config)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530219{
Simon Glass60e0c3a2020-01-23 11:48:12 -0700220 const struct dw_scl_sda_cfg *scl_sda_cfg = NULL;
Simon Glass6ed44ae2020-01-23 11:48:08 -0700221 enum i2c_speed_mode i2c_spd;
Simon Glassc38e2b32020-01-23 11:48:15 -0700222 int spk_cnt;
Simon Glassc7181102020-01-23 11:48:14 -0700223 int ret;
Stefan Roese88893c92016-04-21 08:19:39 +0200224
Simon Glass60e0c3a2020-01-23 11:48:12 -0700225 if (priv)
226 scl_sda_cfg = priv->scl_sda_cfg;
Simon Glassf5ef1012020-01-23 11:48:07 -0700227 /* Allow high speed if there is no config, or the config allows it */
Jun Chen3ce27d42020-03-02 16:58:56 +0800228 if (speed >= I2C_SPEED_HIGH_RATE)
Simon Glassf5ef1012020-01-23 11:48:07 -0700229 i2c_spd = IC_SPEED_MODE_HIGH;
Simon Glass45649222020-01-23 11:48:23 -0700230 else if (speed >= I2C_SPEED_FAST_PLUS_RATE)
Simon Glass55397682020-02-13 13:24:55 -0700231 i2c_spd = IC_SPEED_MODE_FAST_PLUS;
232 else if (speed >= I2C_SPEED_FAST_RATE)
Stefan Roese88893c92016-04-21 08:19:39 +0200233 i2c_spd = IC_SPEED_MODE_FAST;
234 else
235 i2c_spd = IC_SPEED_MODE_STANDARD;
Armando Visconti631e6932012-03-29 20:10:17 +0000236
Jun Chenef6677e2020-03-02 16:58:55 +0800237 /* Check is high speed possible and fall back to fast mode if not */
238 if (i2c_spd == IC_SPEED_MODE_HIGH) {
Simon Glass02b880e2020-04-22 10:13:53 -0600239 u32 comp_param1;
240
241 comp_param1 = readl(&regs->comp_param1);
Jun Chenef6677e2020-03-02 16:58:55 +0800242 if ((comp_param1 & DW_IC_COMP_PARAM_1_SPEED_MODE_MASK)
243 != DW_IC_COMP_PARAM_1_SPEED_MODE_HIGH)
244 i2c_spd = IC_SPEED_MODE_FAST;
245 }
246
Simon Glassc38e2b32020-01-23 11:48:15 -0700247 /* Get the proper spike-suppression count based on target speed */
248 if (!priv || !priv->has_spk_cnt)
249 spk_cnt = 0;
250 else if (i2c_spd >= IC_SPEED_MODE_HIGH)
Simon Glassc5294192020-01-23 11:48:25 -0700251 spk_cnt = readl(&regs->hs_spklen);
Simon Glassc38e2b32020-01-23 11:48:15 -0700252 else
Simon Glassc5294192020-01-23 11:48:25 -0700253 spk_cnt = readl(&regs->fs_spklen);
Simon Glass245ec0b2020-01-23 11:48:13 -0700254 if (scl_sda_cfg) {
Simon Glassc5294192020-01-23 11:48:25 -0700255 config->sda_hold = scl_sda_cfg->sda_hold;
Simon Glass245ec0b2020-01-23 11:48:13 -0700256 if (i2c_spd == IC_SPEED_MODE_STANDARD) {
Simon Glassc5294192020-01-23 11:48:25 -0700257 config->scl_hcnt = scl_sda_cfg->ss_hcnt;
258 config->scl_lcnt = scl_sda_cfg->ss_lcnt;
Jun Chenc191f542020-03-02 16:58:57 +0800259 } else if (i2c_spd == IC_SPEED_MODE_HIGH) {
260 config->scl_hcnt = scl_sda_cfg->hs_hcnt;
261 config->scl_lcnt = scl_sda_cfg->hs_lcnt;
Simon Glass245ec0b2020-01-23 11:48:13 -0700262 } else {
Simon Glassc5294192020-01-23 11:48:25 -0700263 config->scl_hcnt = scl_sda_cfg->fs_hcnt;
264 config->scl_lcnt = scl_sda_cfg->fs_lcnt;
Simon Glass245ec0b2020-01-23 11:48:13 -0700265 }
Simon Glassc7181102020-01-23 11:48:14 -0700266 } else {
Simon Glassc38e2b32020-01-23 11:48:15 -0700267 ret = dw_i2c_calc_timing(priv, i2c_spd, bus_clk, spk_cnt,
Simon Glassc5294192020-01-23 11:48:25 -0700268 config);
Simon Glassc7181102020-01-23 11:48:14 -0700269 if (ret)
270 return log_msg_ret("gen_confg", ret);
Simon Glass245ec0b2020-01-23 11:48:13 -0700271 }
Simon Glassc5294192020-01-23 11:48:25 -0700272 config->speed_mode = i2c_spd;
273
274 return 0;
275}
276
Simon Glass02b880e2020-04-22 10:13:53 -0600277/**
278 * _dw_i2c_set_bus_speed() - Set the i2c speed
Simon Glassc5294192020-01-23 11:48:25 -0700279 *
Simon Glass02b880e2020-04-22 10:13:53 -0600280 * @priv: Private information for the driver (NULL if not using driver model)
281 * @i2c_base: Registers for the I2C controller
282 * @speed: Required i2c speed in Hz
283 * @bus_clk: Input clock to the I2C controller in Hz (e.g. IC_CLK)
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100284 * Return: 0 if OK, -ve on error
Simon Glassc5294192020-01-23 11:48:25 -0700285 */
286static int _dw_i2c_set_bus_speed(struct dw_i2c *priv, struct i2c_regs *i2c_base,
287 unsigned int speed, unsigned int bus_clk)
288{
289 struct dw_i2c_speed_config config;
290 unsigned int cntl;
291 unsigned int ena;
292 int ret;
293
Simon Glass02b880e2020-04-22 10:13:53 -0600294 ret = calc_bus_speed(priv, i2c_base, speed, bus_clk, &config);
Simon Glassc5294192020-01-23 11:48:25 -0700295 if (ret)
296 return ret;
297
298 /* Get enable setting for restore later */
299 ena = readl(&i2c_base->ic_enable) & IC_ENABLE_0B;
300
301 /* to set speed cltr must be disabled */
302 dw_i2c_enable(i2c_base, false);
303
304 cntl = (readl(&i2c_base->ic_con) & (~IC_CON_SPD_MSK));
Simon Glass245ec0b2020-01-23 11:48:13 -0700305
Simon Glassc5294192020-01-23 11:48:25 -0700306 switch (config.speed_mode) {
Simon Glassf5ef1012020-01-23 11:48:07 -0700307 case IC_SPEED_MODE_HIGH:
Jun Chen635cf512020-03-02 16:58:54 +0800308 cntl |= IC_CON_SPD_HS;
Simon Glass245ec0b2020-01-23 11:48:13 -0700309 writel(config.scl_hcnt, &i2c_base->ic_hs_scl_hcnt);
310 writel(config.scl_lcnt, &i2c_base->ic_hs_scl_lcnt);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530311 break;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530312 case IC_SPEED_MODE_STANDARD:
313 cntl |= IC_CON_SPD_SS;
Simon Glass245ec0b2020-01-23 11:48:13 -0700314 writel(config.scl_hcnt, &i2c_base->ic_ss_scl_hcnt);
315 writel(config.scl_lcnt, &i2c_base->ic_ss_scl_lcnt);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530316 break;
Simon Glass45649222020-01-23 11:48:23 -0700317 case IC_SPEED_MODE_FAST_PLUS:
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530318 case IC_SPEED_MODE_FAST:
319 default:
320 cntl |= IC_CON_SPD_FS;
Simon Glass245ec0b2020-01-23 11:48:13 -0700321 writel(config.scl_hcnt, &i2c_base->ic_fs_scl_hcnt);
322 writel(config.scl_lcnt, &i2c_base->ic_fs_scl_lcnt);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530323 break;
324 }
325
Stefan Roeseef6073e2014-10-28 12:12:00 +0100326 writel(cntl, &i2c_base->ic_con);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530327
Stefan Roese38481202016-04-21 08:19:42 +0200328 /* Configure SDA Hold Time if required */
Simon Glass245ec0b2020-01-23 11:48:13 -0700329 if (config.sda_hold)
330 writel(config.sda_hold, &i2c_base->ic_sda_hold);
Stefan Roese38481202016-04-21 08:19:42 +0200331
Jun Chend003a372019-06-05 15:23:16 +0800332 /* Restore back i2c now speed set */
333 if (ena == IC_ENABLE_0B)
334 dw_i2c_enable(i2c_base, true);
Simon Glass3908d902020-07-07 21:32:29 -0600335 if (priv)
336 priv->config = config;
337
338 return 0;
339}
340
341int dw_i2c_gen_speed_config(const struct udevice *dev, int speed_hz,
342 struct dw_i2c_speed_config *config)
343{
344 struct dw_i2c *priv = dev_get_priv(dev);
345 ulong rate;
346 int ret;
347
348#if CONFIG_IS_ENABLED(CLK)
349 rate = clk_get_rate(&priv->clk);
350 if (IS_ERR_VALUE(rate))
351 return log_msg_ret("clk", -EINVAL);
352#else
353 rate = IC_CLK;
354#endif
355
356 ret = calc_bus_speed(priv, priv->regs, speed_hz, rate, config);
357 if (ret)
358 printf("%s: ret=%d\n", __func__, ret);
359 if (ret)
360 return log_msg_ret("calc_bus_speed", ret);
Stefan Roesef6322ebd2012-01-20 11:52:33 +0100361
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530362 return 0;
363}
364
365/*
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530366 * i2c_setaddress - Sets the target slave address
367 * @i2c_addr: target i2c address
368 *
369 * Sets the target slave address.
370 */
Stefan Roese41de7662016-04-21 08:19:40 +0200371static void i2c_setaddress(struct i2c_regs *i2c_base, unsigned int i2c_addr)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530372{
Alexey Brodkin41c56552013-11-07 17:52:18 +0400373 /* Disable i2c */
Stefan Roese3bc33ba2016-04-21 08:19:38 +0200374 dw_i2c_enable(i2c_base, false);
Alexey Brodkin41c56552013-11-07 17:52:18 +0400375
Stefan Roeseef6073e2014-10-28 12:12:00 +0100376 writel(i2c_addr, &i2c_base->ic_tar);
Alexey Brodkin41c56552013-11-07 17:52:18 +0400377
378 /* Enable i2c */
Stefan Roese3bc33ba2016-04-21 08:19:38 +0200379 dw_i2c_enable(i2c_base, true);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530380}
381
382/*
383 * i2c_flush_rxfifo - Flushes the i2c RX FIFO
384 *
385 * Flushes the i2c RX FIFO
386 */
Stefan Roese41de7662016-04-21 08:19:40 +0200387static void i2c_flush_rxfifo(struct i2c_regs *i2c_base)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530388{
Stefan Roeseef6073e2014-10-28 12:12:00 +0100389 while (readl(&i2c_base->ic_status) & IC_STATUS_RFNE)
390 readl(&i2c_base->ic_cmd_data);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530391}
392
393/*
394 * i2c_wait_for_bb - Waits for bus busy
395 *
396 * Waits for bus busy
397 */
Stefan Roese41de7662016-04-21 08:19:40 +0200398static int i2c_wait_for_bb(struct i2c_regs *i2c_base)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530399{
400 unsigned long start_time_bb = get_timer(0);
401
Stefan Roeseef6073e2014-10-28 12:12:00 +0100402 while ((readl(&i2c_base->ic_status) & IC_STATUS_MA) ||
403 !(readl(&i2c_base->ic_status) & IC_STATUS_TFE)) {
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530404
405 /* Evaluate timeout */
406 if (get_timer(start_time_bb) > (unsigned long)(I2C_BYTE_TO_BB))
Wojciech Szamocki69b0fa12025-05-23 12:57:07 +0200407 return -ETIMEDOUT;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530408 }
409
410 return 0;
411}
412
Stefan Roese41de7662016-04-21 08:19:40 +0200413static int i2c_xfer_init(struct i2c_regs *i2c_base, uchar chip, uint addr,
Stefan Roeseef6073e2014-10-28 12:12:00 +0100414 int alen)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530415{
Wojciech Szamocki69b0fa12025-05-23 12:57:07 +0200416 int ret = i2c_wait_for_bb(i2c_base);
417
418 if (ret)
419 return ret;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530420
Stefan Roese41de7662016-04-21 08:19:40 +0200421 i2c_setaddress(i2c_base, chip);
Chin Liang Seea0c26262014-02-04 11:56:23 -0600422 while (alen) {
423 alen--;
424 /* high byte address going out first */
425 writel((addr >> (alen * 8)) & 0xff,
Stefan Roeseef6073e2014-10-28 12:12:00 +0100426 &i2c_base->ic_cmd_data);
Chin Liang Seea0c26262014-02-04 11:56:23 -0600427 }
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530428 return 0;
429}
430
Stefan Roese41de7662016-04-21 08:19:40 +0200431static int i2c_xfer_finish(struct i2c_regs *i2c_base)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530432{
433 ulong start_stop_det = get_timer(0);
Wojciech Szamocki69b0fa12025-05-23 12:57:07 +0200434 int ret;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530435
436 while (1) {
Stefan Roeseef6073e2014-10-28 12:12:00 +0100437 if ((readl(&i2c_base->ic_raw_intr_stat) & IC_STOP_DET)) {
438 readl(&i2c_base->ic_clr_stop_det);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530439 break;
440 } else if (get_timer(start_stop_det) > I2C_STOPDET_TO) {
441 break;
442 }
443 }
444
Wojciech Szamocki69b0fa12025-05-23 12:57:07 +0200445 ret = i2c_wait_for_bb(i2c_base);
446 if (ret) {
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530447 printf("Timed out waiting for bus\n");
Wojciech Szamocki69b0fa12025-05-23 12:57:07 +0200448 return ret;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530449 }
450
Stefan Roese41de7662016-04-21 08:19:40 +0200451 i2c_flush_rxfifo(i2c_base);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530452
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530453 return 0;
454}
455
456/*
457 * i2c_read - Read from i2c memory
458 * @chip: target i2c address
459 * @addr: address to read from
460 * @alen:
461 * @buffer: buffer for read data
462 * @len: no of bytes to be read
463 *
464 * Read from i2c memory.
465 */
Stefan Roese41de7662016-04-21 08:19:40 +0200466static int __dw_i2c_read(struct i2c_regs *i2c_base, u8 dev, uint addr,
467 int alen, u8 *buffer, int len)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530468{
469 unsigned long start_time_rx;
Marek Vasutc4bc9a82016-10-20 16:48:28 +0200470 unsigned int active = 0;
Wojciech Szamocki69b0fa12025-05-23 12:57:07 +0200471 int ret;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530472
Alexey Brodkin7ef00362013-12-16 15:30:35 +0400473#ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW
474 /*
475 * EEPROM chips that implement "address overflow" are ones
476 * like Catalyst 24WC04/08/16 which has 9/10/11 bits of
477 * address and the extra bits end up in the "chip address"
478 * bit slots. This makes a 24WC08 (1Kbyte) chip look like
479 * four 256 byte chips.
480 *
481 * Note that we consider the length of the address field to
482 * still be one byte because the extra address bits are
483 * hidden in the chip address.
484 */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100485 dev |= ((addr >> (alen * 8)) & CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW);
Alexey Brodkin7ef00362013-12-16 15:30:35 +0400486 addr &= ~(CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW << (alen * 8));
487
Stefan Roeseef6073e2014-10-28 12:12:00 +0100488 debug("%s: fix addr_overflow: dev %02x addr %02x\n", __func__, dev,
Alexey Brodkin7ef00362013-12-16 15:30:35 +0400489 addr);
490#endif
491
Wojciech Szamocki69b0fa12025-05-23 12:57:07 +0200492 ret = i2c_xfer_init(i2c_base, dev, addr, alen);
493 if (ret)
494 return ret;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530495
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530496 start_time_rx = get_timer(0);
497 while (len) {
Marek Vasutc4bc9a82016-10-20 16:48:28 +0200498 if (!active) {
499 /*
500 * Avoid writing to ic_cmd_data multiple times
501 * in case this loop spins too quickly and the
502 * ic_status RFNE bit isn't set after the first
503 * write. Subsequent writes to ic_cmd_data can
504 * trigger spurious i2c transfer.
505 */
506 if (len == 1)
507 writel(IC_CMD | IC_STOP, &i2c_base->ic_cmd_data);
508 else
509 writel(IC_CMD, &i2c_base->ic_cmd_data);
510 active = 1;
511 }
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530512
Stefan Roeseef6073e2014-10-28 12:12:00 +0100513 if (readl(&i2c_base->ic_status) & IC_STATUS_RFNE) {
514 *buffer++ = (uchar)readl(&i2c_base->ic_cmd_data);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530515 len--;
516 start_time_rx = get_timer(0);
Marek Vasutc4bc9a82016-10-20 16:48:28 +0200517 active = 0;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530518 } else if (get_timer(start_time_rx) > I2C_BYTE_TO) {
Wojciech Szamocki69b0fa12025-05-23 12:57:07 +0200519 return -ETIMEDOUT;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530520 }
521 }
522
Stefan Roese41de7662016-04-21 08:19:40 +0200523 return i2c_xfer_finish(i2c_base);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530524}
525
526/*
527 * i2c_write - Write to i2c memory
528 * @chip: target i2c address
529 * @addr: address to read from
530 * @alen:
531 * @buffer: buffer for read data
532 * @len: no of bytes to be read
533 *
534 * Write to i2c memory.
535 */
Stefan Roese41de7662016-04-21 08:19:40 +0200536static int __dw_i2c_write(struct i2c_regs *i2c_base, u8 dev, uint addr,
537 int alen, u8 *buffer, int len)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530538{
539 int nb = len;
540 unsigned long start_time_tx;
Wojciech Szamocki69b0fa12025-05-23 12:57:07 +0200541 int ret;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530542
Alexey Brodkin7ef00362013-12-16 15:30:35 +0400543#ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW
544 /*
545 * EEPROM chips that implement "address overflow" are ones
546 * like Catalyst 24WC04/08/16 which has 9/10/11 bits of
547 * address and the extra bits end up in the "chip address"
548 * bit slots. This makes a 24WC08 (1Kbyte) chip look like
549 * four 256 byte chips.
550 *
551 * Note that we consider the length of the address field to
552 * still be one byte because the extra address bits are
553 * hidden in the chip address.
554 */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100555 dev |= ((addr >> (alen * 8)) & CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW);
Alexey Brodkin7ef00362013-12-16 15:30:35 +0400556 addr &= ~(CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW << (alen * 8));
557
Stefan Roeseef6073e2014-10-28 12:12:00 +0100558 debug("%s: fix addr_overflow: dev %02x addr %02x\n", __func__, dev,
Alexey Brodkin7ef00362013-12-16 15:30:35 +0400559 addr);
560#endif
561
Wojciech Szamocki69b0fa12025-05-23 12:57:07 +0200562 ret = i2c_xfer_init(i2c_base, dev, addr, alen);
563 if (ret)
564 return ret;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530565
566 start_time_tx = get_timer(0);
567 while (len) {
Stefan Roeseef6073e2014-10-28 12:12:00 +0100568 if (readl(&i2c_base->ic_status) & IC_STATUS_TFNF) {
569 if (--len == 0) {
570 writel(*buffer | IC_STOP,
571 &i2c_base->ic_cmd_data);
572 } else {
573 writel(*buffer, &i2c_base->ic_cmd_data);
574 }
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530575 buffer++;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530576 start_time_tx = get_timer(0);
577
578 } else if (get_timer(start_time_tx) > (nb * I2C_BYTE_TO)) {
579 printf("Timed out. i2c write Failed\n");
Wojciech Szamocki69b0fa12025-05-23 12:57:07 +0200580 return -ETIMEDOUT;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530581 }
582 }
583
Stefan Roese41de7662016-04-21 08:19:40 +0200584 return i2c_xfer_finish(i2c_base);
585}
586
Stefan Roese3cb27962016-04-21 08:19:41 +0200587/*
588 * __dw_i2c_init - Init function
589 * @speed: required i2c speed
590 * @slaveaddr: slave address for the device
591 *
592 * Initialization function.
593 */
Simon Glassbd9ca8d2019-02-16 20:24:39 -0700594static int __dw_i2c_init(struct i2c_regs *i2c_base, int speed, int slaveaddr)
Stefan Roese3cb27962016-04-21 08:19:41 +0200595{
Simon Glassbd9ca8d2019-02-16 20:24:39 -0700596 int ret;
597
Stefan Roese3cb27962016-04-21 08:19:41 +0200598 /* Disable i2c */
Simon Glassbd9ca8d2019-02-16 20:24:39 -0700599 ret = dw_i2c_enable(i2c_base, false);
600 if (ret)
601 return ret;
Stefan Roese3cb27962016-04-21 08:19:41 +0200602
Marek Vasut808aa132017-08-07 20:45:31 +0200603 writel(IC_CON_SD | IC_CON_RE | IC_CON_SPD_FS | IC_CON_MM,
604 &i2c_base->ic_con);
Stefan Roese3cb27962016-04-21 08:19:41 +0200605 writel(IC_RX_TL, &i2c_base->ic_rx_tl);
606 writel(IC_TX_TL, &i2c_base->ic_tx_tl);
607 writel(IC_STOP_DET, &i2c_base->ic_intr_mask);
Igor Opaniukf7c91762021-02-09 13:52:45 +0200608#if !CONFIG_IS_ENABLED(DM_I2C)
Simon Glassc5294192020-01-23 11:48:25 -0700609 _dw_i2c_set_bus_speed(NULL, i2c_base, speed, IC_CLK);
Stefan Roese3cb27962016-04-21 08:19:41 +0200610 writel(slaveaddr, &i2c_base->ic_sar);
611#endif
612
613 /* Enable i2c */
Simon Glassbd9ca8d2019-02-16 20:24:39 -0700614 ret = dw_i2c_enable(i2c_base, true);
615 if (ret)
616 return ret;
617
618 return 0;
Stefan Roese3cb27962016-04-21 08:19:41 +0200619}
620
Igor Opaniukf7c91762021-02-09 13:52:45 +0200621#if !CONFIG_IS_ENABLED(DM_I2C)
Stefan Roese3cb27962016-04-21 08:19:41 +0200622/*
623 * The legacy I2C functions. These need to get removed once
624 * all users of this driver are converted to DM.
625 */
Stefan Roese41de7662016-04-21 08:19:40 +0200626static struct i2c_regs *i2c_get_base(struct i2c_adapter *adap)
627{
628 switch (adap->hwadapnr) {
629#if CONFIG_SYS_I2C_BUS_MAX >= 4
630 case 3:
631 return (struct i2c_regs *)CONFIG_SYS_I2C_BASE3;
632#endif
633#if CONFIG_SYS_I2C_BUS_MAX >= 3
634 case 2:
635 return (struct i2c_regs *)CONFIG_SYS_I2C_BASE2;
636#endif
637#if CONFIG_SYS_I2C_BUS_MAX >= 2
638 case 1:
639 return (struct i2c_regs *)CONFIG_SYS_I2C_BASE1;
640#endif
641 case 0:
642 return (struct i2c_regs *)CONFIG_SYS_I2C_BASE;
643 default:
644 printf("Wrong I2C-adapter number %d\n", adap->hwadapnr);
645 }
646
647 return NULL;
648}
649
650static unsigned int dw_i2c_set_bus_speed(struct i2c_adapter *adap,
651 unsigned int speed)
652{
653 adap->speed = speed;
Simon Glassc5294192020-01-23 11:48:25 -0700654 return _dw_i2c_set_bus_speed(NULL, i2c_get_base(adap), speed, IC_CLK);
Stefan Roese41de7662016-04-21 08:19:40 +0200655}
656
Stefan Roese3cb27962016-04-21 08:19:41 +0200657static void dw_i2c_init(struct i2c_adapter *adap, int speed, int slaveaddr)
Stefan Roese41de7662016-04-21 08:19:40 +0200658{
Stefan Roese3cb27962016-04-21 08:19:41 +0200659 __dw_i2c_init(i2c_get_base(adap), speed, slaveaddr);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530660}
661
Stefan Roese41de7662016-04-21 08:19:40 +0200662static int dw_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr,
663 int alen, u8 *buffer, int len)
664{
665 return __dw_i2c_read(i2c_get_base(adap), dev, addr, alen, buffer, len);
666}
667
668static int dw_i2c_write(struct i2c_adapter *adap, u8 dev, uint addr,
669 int alen, u8 *buffer, int len)
670{
671 return __dw_i2c_write(i2c_get_base(adap), dev, addr, alen, buffer, len);
672}
673
Stefan Roese3cb27962016-04-21 08:19:41 +0200674/* dw_i2c_probe - Probe the i2c chip */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100675static int dw_i2c_probe(struct i2c_adapter *adap, u8 dev)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530676{
Stefan Roese41de7662016-04-21 08:19:40 +0200677 struct i2c_regs *i2c_base = i2c_get_base(adap);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530678 u32 tmp;
Stefan Roesef6322ebd2012-01-20 11:52:33 +0100679 int ret;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530680
681 /*
682 * Try to read the first location of the chip.
683 */
Stefan Roese41de7662016-04-21 08:19:40 +0200684 ret = __dw_i2c_read(i2c_base, dev, 0, 1, (uchar *)&tmp, 1);
Stefan Roesef6322ebd2012-01-20 11:52:33 +0100685 if (ret)
Stefan Roeseef6073e2014-10-28 12:12:00 +0100686 dw_i2c_init(adap, adap->speed, adap->slaveaddr);
Stefan Roesef6322ebd2012-01-20 11:52:33 +0100687
688 return ret;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530689}
Armando Visconti4a7b4ec2012-12-06 00:04:15 +0000690
Stefan Roeseef6073e2014-10-28 12:12:00 +0100691U_BOOT_I2C_ADAP_COMPLETE(dw_0, dw_i2c_init, dw_i2c_probe, dw_i2c_read,
692 dw_i2c_write, dw_i2c_set_bus_speed,
693 CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE, 0)
Armando Visconti4a7b4ec2012-12-06 00:04:15 +0000694
Stefan Roese3cb27962016-04-21 08:19:41 +0200695#else /* CONFIG_DM_I2C */
696/* The DM I2C functions */
697
698static int designware_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
699 int nmsgs)
700{
701 struct dw_i2c *i2c = dev_get_priv(bus);
702 int ret;
703
704 debug("i2c_xfer: %d messages\n", nmsgs);
705 for (; nmsgs > 0; nmsgs--, msg++) {
706 debug("i2c_xfer: chip=0x%x, len=0x%x\n", msg->addr, msg->len);
707 if (msg->flags & I2C_M_RD) {
708 ret = __dw_i2c_read(i2c->regs, msg->addr, 0, 0,
709 msg->buf, msg->len);
710 } else {
711 ret = __dw_i2c_write(i2c->regs, msg->addr, 0, 0,
712 msg->buf, msg->len);
713 }
714 if (ret) {
715 debug("i2c_write: error sending\n");
716 return -EREMOTEIO;
717 }
718 }
719
720 return 0;
721}
722
723static int designware_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
724{
725 struct dw_i2c *i2c = dev_get_priv(bus);
Ley Foon Tan6e85c812019-06-12 09:48:04 +0800726 ulong rate;
727
728#if CONFIG_IS_ENABLED(CLK)
729 rate = clk_get_rate(&i2c->clk);
730 if (IS_ERR_VALUE(rate))
Simon Glass46aadb62020-07-07 21:32:27 -0600731 return log_ret(-EINVAL);
Ley Foon Tan6e85c812019-06-12 09:48:04 +0800732#else
733 rate = IC_CLK;
734#endif
Simon Glassc5294192020-01-23 11:48:25 -0700735 return _dw_i2c_set_bus_speed(i2c, i2c->regs, speed, rate);
Stefan Roese3cb27962016-04-21 08:19:41 +0200736}
737
738static int designware_i2c_probe_chip(struct udevice *bus, uint chip_addr,
739 uint chip_flags)
740{
741 struct dw_i2c *i2c = dev_get_priv(bus);
742 struct i2c_regs *i2c_base = i2c->regs;
743 u32 tmp;
744 int ret;
745
746 /* Try to read the first location of the chip */
747 ret = __dw_i2c_read(i2c_base, chip_addr, 0, 1, (uchar *)&tmp, 1);
748 if (ret)
749 __dw_i2c_init(i2c_base, 0, 0);
750
751 return ret;
752}
753
Simon Glassaad29ae2020-12-03 16:55:21 -0700754int designware_i2c_of_to_plat(struct udevice *bus)
Stefan Roese3cb27962016-04-21 08:19:41 +0200755{
756 struct dw_i2c *priv = dev_get_priv(bus);
Simon Glass8de5ae82020-01-23 11:48:26 -0700757 int ret;
Stefan Roese3cb27962016-04-21 08:19:41 +0200758
Simon Glass9e5d1742020-01-23 11:48:11 -0700759 if (!priv->regs)
Masahiro Yamada32822d02020-08-04 14:14:43 +0900760 priv->regs = dev_read_addr_ptr(bus);
Simon Glass9e5d1742020-01-23 11:48:11 -0700761 dev_read_u32(bus, "i2c-scl-rising-time-ns", &priv->scl_rise_time_ns);
762 dev_read_u32(bus, "i2c-scl-falling-time-ns", &priv->scl_fall_time_ns);
763 dev_read_u32(bus, "i2c-sda-hold-time-ns", &priv->sda_hold_time_ns);
Simon Glasse2be5532019-12-06 21:41:40 -0700764
Simon Goldschmidt28608a12019-03-28 21:11:48 +0100765 ret = reset_get_bulk(bus, &priv->resets);
Simon Glass93557162020-11-09 07:12:49 -0700766 if (ret) {
767 if (ret != -ENOTSUPP)
768 dev_warn(bus, "Can't get reset: %d\n", ret);
769 } else {
Simon Goldschmidt28608a12019-03-28 21:11:48 +0100770 reset_deassert_bulk(&priv->resets);
Simon Glass93557162020-11-09 07:12:49 -0700771 }
Dinh Nguyen08794aa2018-04-04 17:18:24 -0500772
Ley Foon Tan6e85c812019-06-12 09:48:04 +0800773#if CONFIG_IS_ENABLED(CLK)
774 ret = clk_get_by_index(bus, 0, &priv->clk);
775 if (ret)
776 return ret;
777
778 ret = clk_enable(&priv->clk);
779 if (ret && ret != -ENOSYS && ret != -ENOTSUPP) {
Ley Foon Tan6e85c812019-06-12 09:48:04 +0800780 dev_err(bus, "failed to enable clock\n");
781 return ret;
782 }
783#endif
784
Simon Glass8de5ae82020-01-23 11:48:26 -0700785 return 0;
786}
787
788int designware_i2c_probe(struct udevice *bus)
789{
790 struct dw_i2c *priv = dev_get_priv(bus);
Raul E Rangel057be512020-04-22 10:13:54 -0600791 uint comp_type;
792
793 comp_type = readl(&priv->regs->comp_type);
794 if (comp_type != DW_I2C_COMP_TYPE) {
795 log_err("I2C bus %s has unknown type %#x\n", bus->name,
796 comp_type);
797 return -ENXIO;
798 }
799
Simon Glass9a096302020-09-27 18:46:23 -0600800 log_debug("I2C bus %s version %#x\n", bus->name,
801 readl(&priv->regs->comp_version));
Simon Glass8de5ae82020-01-23 11:48:26 -0700802
Simon Glassbd9ca8d2019-02-16 20:24:39 -0700803 return __dw_i2c_init(priv->regs, 0, 0);
Stefan Roese3cb27962016-04-21 08:19:41 +0200804}
805
Simon Glasse2be5532019-12-06 21:41:40 -0700806int designware_i2c_remove(struct udevice *dev)
Simon Goldschmidt28608a12019-03-28 21:11:48 +0100807{
808 struct dw_i2c *priv = dev_get_priv(dev);
809
Ley Foon Tan6e85c812019-06-12 09:48:04 +0800810#if CONFIG_IS_ENABLED(CLK)
811 clk_disable(&priv->clk);
Ley Foon Tan6e85c812019-06-12 09:48:04 +0800812#endif
813
Simon Goldschmidt28608a12019-03-28 21:11:48 +0100814 return reset_release_bulk(&priv->resets);
815}
816
Simon Glasse2be5532019-12-06 21:41:40 -0700817const struct dm_i2c_ops designware_i2c_ops = {
Stefan Roese3cb27962016-04-21 08:19:41 +0200818 .xfer = designware_i2c_xfer,
819 .probe_chip = designware_i2c_probe_chip,
820 .set_bus_speed = designware_i2c_set_bus_speed,
821};
822
823static const struct udevice_id designware_i2c_ids[] = {
824 { .compatible = "snps,designware-i2c" },
825 { }
826};
827
828U_BOOT_DRIVER(i2c_designware) = {
829 .name = "i2c_designware",
830 .id = UCLASS_I2C,
831 .of_match = designware_i2c_ids,
Simon Glassaad29ae2020-12-03 16:55:21 -0700832 .of_to_plat = designware_i2c_of_to_plat,
Stefan Roese3cb27962016-04-21 08:19:41 +0200833 .probe = designware_i2c_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700834 .priv_auto = sizeof(struct dw_i2c),
Simon Goldschmidt28608a12019-03-28 21:11:48 +0100835 .remove = designware_i2c_remove,
Simon Glasse2be5532019-12-06 21:41:40 -0700836 .flags = DM_FLAG_OS_PREPARE,
Stefan Roese3cb27962016-04-21 08:19:41 +0200837 .ops = &designware_i2c_ops,
838};
839
840#endif /* CONFIG_DM_I2C */