Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2009 |
| 4 | * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com. |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 9b7af64 | 2020-01-23 11:48:06 -0700 | [diff] [blame] | 8 | #include <clk.h> |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 9 | #include <dm.h> |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 10 | #include <i2c.h> |
Stefan Roese | 3848120 | 2016-04-21 08:19:42 +0200 | [diff] [blame] | 11 | #include <pci.h> |
Dinh Nguyen | 08794aa | 2018-04-04 17:18:24 -0500 | [diff] [blame] | 12 | #include <reset.h> |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 13 | #include <asm/io.h> |
Vipin KUMAR | 3f64acb | 2012-02-26 23:13:29 +0000 | [diff] [blame] | 14 | #include "designware_i2c.h" |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 15 | |
Stefan Roese | abb3e13 | 2016-04-27 09:02:12 +0200 | [diff] [blame] | 16 | #ifdef CONFIG_SYS_I2C_DW_ENABLE_STATUS_UNSUPPORTED |
Simon Glass | bd9ca8d | 2019-02-16 20:24:39 -0700 | [diff] [blame] | 17 | static int dw_i2c_enable(struct i2c_regs *i2c_base, bool enable) |
Stefan Roese | 3bc33ba | 2016-04-21 08:19:38 +0200 | [diff] [blame] | 18 | { |
| 19 | u32 ena = enable ? IC_ENABLE_0B : 0; |
Stefan Roese | abb3e13 | 2016-04-27 09:02:12 +0200 | [diff] [blame] | 20 | |
| 21 | writel(ena, &i2c_base->ic_enable); |
Simon Glass | bd9ca8d | 2019-02-16 20:24:39 -0700 | [diff] [blame] | 22 | |
| 23 | return 0; |
Stefan Roese | abb3e13 | 2016-04-27 09:02:12 +0200 | [diff] [blame] | 24 | } |
| 25 | #else |
Simon Glass | bd9ca8d | 2019-02-16 20:24:39 -0700 | [diff] [blame] | 26 | static int dw_i2c_enable(struct i2c_regs *i2c_base, bool enable) |
Stefan Roese | abb3e13 | 2016-04-27 09:02:12 +0200 | [diff] [blame] | 27 | { |
| 28 | u32 ena = enable ? IC_ENABLE_0B : 0; |
Stefan Roese | 3bc33ba | 2016-04-21 08:19:38 +0200 | [diff] [blame] | 29 | int timeout = 100; |
| 30 | |
| 31 | do { |
| 32 | writel(ena, &i2c_base->ic_enable); |
| 33 | if ((readl(&i2c_base->ic_enable_status) & IC_ENABLE_0B) == ena) |
Simon Glass | bd9ca8d | 2019-02-16 20:24:39 -0700 | [diff] [blame] | 34 | return 0; |
Stefan Roese | 3bc33ba | 2016-04-21 08:19:38 +0200 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * Wait 10 times the signaling period of the highest I2C |
| 38 | * transfer supported by the driver (for 400KHz this is |
| 39 | * 25us) as described in the DesignWare I2C databook. |
| 40 | */ |
| 41 | udelay(25); |
| 42 | } while (timeout--); |
Stefan Roese | 3bc33ba | 2016-04-21 08:19:38 +0200 | [diff] [blame] | 43 | printf("timeout in %sabling I2C adapter\n", enable ? "en" : "dis"); |
Simon Glass | bd9ca8d | 2019-02-16 20:24:39 -0700 | [diff] [blame] | 44 | |
| 45 | return -ETIMEDOUT; |
Stefan Roese | 3bc33ba | 2016-04-21 08:19:38 +0200 | [diff] [blame] | 46 | } |
Stefan Roese | abb3e13 | 2016-04-27 09:02:12 +0200 | [diff] [blame] | 47 | #endif |
Stefan Roese | 3bc33ba | 2016-04-21 08:19:38 +0200 | [diff] [blame] | 48 | |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 49 | /* |
Stefan Roese | 88893c9 | 2016-04-21 08:19:39 +0200 | [diff] [blame] | 50 | * i2c_set_bus_speed - Set the i2c speed |
| 51 | * @speed: required i2c speed |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 52 | * |
Stefan Roese | 88893c9 | 2016-04-21 08:19:39 +0200 | [diff] [blame] | 53 | * Set the i2c speed. |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 54 | */ |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 55 | static unsigned int __dw_i2c_set_bus_speed(struct i2c_regs *i2c_base, |
Stefan Roese | 3848120 | 2016-04-21 08:19:42 +0200 | [diff] [blame] | 56 | struct dw_scl_sda_cfg *scl_sda_cfg, |
Ley Foon Tan | 6e85c81 | 2019-06-12 09:48:04 +0800 | [diff] [blame] | 57 | unsigned int speed, |
Simon Glass | 333dadd | 2020-01-23 11:48:09 -0700 | [diff] [blame] | 58 | unsigned int bus_clk) |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 59 | { |
Simon Glass | 333dadd | 2020-01-23 11:48:09 -0700 | [diff] [blame] | 60 | ulong bus_khz = bus_clk / 1000; |
Simon Glass | 6ed44ae | 2020-01-23 11:48:08 -0700 | [diff] [blame] | 61 | enum i2c_speed_mode i2c_spd; |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 62 | unsigned int cntl; |
| 63 | unsigned int hcnt, lcnt; |
Jun Chen | d003a37 | 2019-06-05 15:23:16 +0800 | [diff] [blame] | 64 | unsigned int ena; |
Stefan Roese | 88893c9 | 2016-04-21 08:19:39 +0200 | [diff] [blame] | 65 | |
Simon Glass | f5ef101 | 2020-01-23 11:48:07 -0700 | [diff] [blame] | 66 | /* Allow high speed if there is no config, or the config allows it */ |
| 67 | if (speed >= I2C_HIGH_SPEED && |
| 68 | (!scl_sda_cfg || scl_sda_cfg->has_high_speed)) |
| 69 | i2c_spd = IC_SPEED_MODE_HIGH; |
Stefan Roese | 88893c9 | 2016-04-21 08:19:39 +0200 | [diff] [blame] | 70 | else if (speed >= I2C_FAST_SPEED) |
| 71 | i2c_spd = IC_SPEED_MODE_FAST; |
| 72 | else |
| 73 | i2c_spd = IC_SPEED_MODE_STANDARD; |
Armando Visconti | 631e693 | 2012-03-29 20:10:17 +0000 | [diff] [blame] | 74 | |
Jun Chen | d003a37 | 2019-06-05 15:23:16 +0800 | [diff] [blame] | 75 | /* Get enable setting for restore later */ |
| 76 | ena = readl(&i2c_base->ic_enable) & IC_ENABLE_0B; |
| 77 | |
Armando Visconti | 631e693 | 2012-03-29 20:10:17 +0000 | [diff] [blame] | 78 | /* to set speed cltr must be disabled */ |
Stefan Roese | 3bc33ba | 2016-04-21 08:19:38 +0200 | [diff] [blame] | 79 | dw_i2c_enable(i2c_base, false); |
Armando Visconti | 631e693 | 2012-03-29 20:10:17 +0000 | [diff] [blame] | 80 | |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 81 | cntl = (readl(&i2c_base->ic_con) & (~IC_CON_SPD_MSK)); |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 82 | |
| 83 | switch (i2c_spd) { |
Simon Glass | f5ef101 | 2020-01-23 11:48:07 -0700 | [diff] [blame] | 84 | case IC_SPEED_MODE_HIGH: |
Stefan Roese | 3848120 | 2016-04-21 08:19:42 +0200 | [diff] [blame] | 85 | cntl |= IC_CON_SPD_SS; |
| 86 | if (scl_sda_cfg) { |
| 87 | hcnt = scl_sda_cfg->fs_hcnt; |
| 88 | lcnt = scl_sda_cfg->fs_lcnt; |
| 89 | } else { |
Simon Glass | 333dadd | 2020-01-23 11:48:09 -0700 | [diff] [blame] | 90 | hcnt = (bus_khz * MIN_HS_SCL_HIGHTIME) / NANO_TO_KILO; |
| 91 | lcnt = (bus_khz * MIN_HS_SCL_LOWTIME) / NANO_TO_KILO; |
Stefan Roese | 3848120 | 2016-04-21 08:19:42 +0200 | [diff] [blame] | 92 | } |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 93 | writel(hcnt, &i2c_base->ic_hs_scl_hcnt); |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 94 | writel(lcnt, &i2c_base->ic_hs_scl_lcnt); |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 95 | break; |
| 96 | |
| 97 | case IC_SPEED_MODE_STANDARD: |
| 98 | cntl |= IC_CON_SPD_SS; |
Stefan Roese | 3848120 | 2016-04-21 08:19:42 +0200 | [diff] [blame] | 99 | if (scl_sda_cfg) { |
| 100 | hcnt = scl_sda_cfg->ss_hcnt; |
| 101 | lcnt = scl_sda_cfg->ss_lcnt; |
| 102 | } else { |
Simon Glass | 333dadd | 2020-01-23 11:48:09 -0700 | [diff] [blame] | 103 | hcnt = (bus_khz * MIN_SS_SCL_HIGHTIME) / NANO_TO_KILO; |
| 104 | lcnt = (bus_khz * MIN_SS_SCL_LOWTIME) / NANO_TO_KILO; |
Stefan Roese | 3848120 | 2016-04-21 08:19:42 +0200 | [diff] [blame] | 105 | } |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 106 | writel(hcnt, &i2c_base->ic_ss_scl_hcnt); |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 107 | writel(lcnt, &i2c_base->ic_ss_scl_lcnt); |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 108 | break; |
| 109 | |
| 110 | case IC_SPEED_MODE_FAST: |
| 111 | default: |
| 112 | cntl |= IC_CON_SPD_FS; |
Stefan Roese | 3848120 | 2016-04-21 08:19:42 +0200 | [diff] [blame] | 113 | if (scl_sda_cfg) { |
| 114 | hcnt = scl_sda_cfg->fs_hcnt; |
| 115 | lcnt = scl_sda_cfg->fs_lcnt; |
| 116 | } else { |
Simon Glass | 333dadd | 2020-01-23 11:48:09 -0700 | [diff] [blame] | 117 | hcnt = (bus_khz * MIN_FS_SCL_HIGHTIME) / NANO_TO_KILO; |
| 118 | lcnt = (bus_khz * MIN_FS_SCL_LOWTIME) / NANO_TO_KILO; |
Stefan Roese | 3848120 | 2016-04-21 08:19:42 +0200 | [diff] [blame] | 119 | } |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 120 | writel(hcnt, &i2c_base->ic_fs_scl_hcnt); |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 121 | writel(lcnt, &i2c_base->ic_fs_scl_lcnt); |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 122 | break; |
| 123 | } |
| 124 | |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 125 | writel(cntl, &i2c_base->ic_con); |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 126 | |
Stefan Roese | 3848120 | 2016-04-21 08:19:42 +0200 | [diff] [blame] | 127 | /* Configure SDA Hold Time if required */ |
| 128 | if (scl_sda_cfg) |
| 129 | writel(scl_sda_cfg->sda_hold, &i2c_base->ic_sda_hold); |
| 130 | |
Jun Chen | d003a37 | 2019-06-05 15:23:16 +0800 | [diff] [blame] | 131 | /* Restore back i2c now speed set */ |
| 132 | if (ena == IC_ENABLE_0B) |
| 133 | dw_i2c_enable(i2c_base, true); |
Stefan Roese | f6322ebd | 2012-01-20 11:52:33 +0100 | [diff] [blame] | 134 | |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | /* |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 139 | * i2c_setaddress - Sets the target slave address |
| 140 | * @i2c_addr: target i2c address |
| 141 | * |
| 142 | * Sets the target slave address. |
| 143 | */ |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 144 | static void i2c_setaddress(struct i2c_regs *i2c_base, unsigned int i2c_addr) |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 145 | { |
Alexey Brodkin | 41c5655 | 2013-11-07 17:52:18 +0400 | [diff] [blame] | 146 | /* Disable i2c */ |
Stefan Roese | 3bc33ba | 2016-04-21 08:19:38 +0200 | [diff] [blame] | 147 | dw_i2c_enable(i2c_base, false); |
Alexey Brodkin | 41c5655 | 2013-11-07 17:52:18 +0400 | [diff] [blame] | 148 | |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 149 | writel(i2c_addr, &i2c_base->ic_tar); |
Alexey Brodkin | 41c5655 | 2013-11-07 17:52:18 +0400 | [diff] [blame] | 150 | |
| 151 | /* Enable i2c */ |
Stefan Roese | 3bc33ba | 2016-04-21 08:19:38 +0200 | [diff] [blame] | 152 | dw_i2c_enable(i2c_base, true); |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /* |
| 156 | * i2c_flush_rxfifo - Flushes the i2c RX FIFO |
| 157 | * |
| 158 | * Flushes the i2c RX FIFO |
| 159 | */ |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 160 | static void i2c_flush_rxfifo(struct i2c_regs *i2c_base) |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 161 | { |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 162 | while (readl(&i2c_base->ic_status) & IC_STATUS_RFNE) |
| 163 | readl(&i2c_base->ic_cmd_data); |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | /* |
| 167 | * i2c_wait_for_bb - Waits for bus busy |
| 168 | * |
| 169 | * Waits for bus busy |
| 170 | */ |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 171 | static int i2c_wait_for_bb(struct i2c_regs *i2c_base) |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 172 | { |
| 173 | unsigned long start_time_bb = get_timer(0); |
| 174 | |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 175 | while ((readl(&i2c_base->ic_status) & IC_STATUS_MA) || |
| 176 | !(readl(&i2c_base->ic_status) & IC_STATUS_TFE)) { |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 177 | |
| 178 | /* Evaluate timeout */ |
| 179 | if (get_timer(start_time_bb) > (unsigned long)(I2C_BYTE_TO_BB)) |
| 180 | return 1; |
| 181 | } |
| 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 186 | static int i2c_xfer_init(struct i2c_regs *i2c_base, uchar chip, uint addr, |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 187 | int alen) |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 188 | { |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 189 | if (i2c_wait_for_bb(i2c_base)) |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 190 | return 1; |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 191 | |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 192 | i2c_setaddress(i2c_base, chip); |
Chin Liang See | a0c2626 | 2014-02-04 11:56:23 -0600 | [diff] [blame] | 193 | while (alen) { |
| 194 | alen--; |
| 195 | /* high byte address going out first */ |
| 196 | writel((addr >> (alen * 8)) & 0xff, |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 197 | &i2c_base->ic_cmd_data); |
Chin Liang See | a0c2626 | 2014-02-04 11:56:23 -0600 | [diff] [blame] | 198 | } |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 199 | return 0; |
| 200 | } |
| 201 | |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 202 | static int i2c_xfer_finish(struct i2c_regs *i2c_base) |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 203 | { |
| 204 | ulong start_stop_det = get_timer(0); |
| 205 | |
| 206 | while (1) { |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 207 | if ((readl(&i2c_base->ic_raw_intr_stat) & IC_STOP_DET)) { |
| 208 | readl(&i2c_base->ic_clr_stop_det); |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 209 | break; |
| 210 | } else if (get_timer(start_stop_det) > I2C_STOPDET_TO) { |
| 211 | break; |
| 212 | } |
| 213 | } |
| 214 | |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 215 | if (i2c_wait_for_bb(i2c_base)) { |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 216 | printf("Timed out waiting for bus\n"); |
| 217 | return 1; |
| 218 | } |
| 219 | |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 220 | i2c_flush_rxfifo(i2c_base); |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 221 | |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | /* |
| 226 | * i2c_read - Read from i2c memory |
| 227 | * @chip: target i2c address |
| 228 | * @addr: address to read from |
| 229 | * @alen: |
| 230 | * @buffer: buffer for read data |
| 231 | * @len: no of bytes to be read |
| 232 | * |
| 233 | * Read from i2c memory. |
| 234 | */ |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 235 | static int __dw_i2c_read(struct i2c_regs *i2c_base, u8 dev, uint addr, |
| 236 | int alen, u8 *buffer, int len) |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 237 | { |
| 238 | unsigned long start_time_rx; |
Marek Vasut | c4bc9a8 | 2016-10-20 16:48:28 +0200 | [diff] [blame] | 239 | unsigned int active = 0; |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 240 | |
Alexey Brodkin | 7ef0036 | 2013-12-16 15:30:35 +0400 | [diff] [blame] | 241 | #ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW |
| 242 | /* |
| 243 | * EEPROM chips that implement "address overflow" are ones |
| 244 | * like Catalyst 24WC04/08/16 which has 9/10/11 bits of |
| 245 | * address and the extra bits end up in the "chip address" |
| 246 | * bit slots. This makes a 24WC08 (1Kbyte) chip look like |
| 247 | * four 256 byte chips. |
| 248 | * |
| 249 | * Note that we consider the length of the address field to |
| 250 | * still be one byte because the extra address bits are |
| 251 | * hidden in the chip address. |
| 252 | */ |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 253 | dev |= ((addr >> (alen * 8)) & CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW); |
Alexey Brodkin | 7ef0036 | 2013-12-16 15:30:35 +0400 | [diff] [blame] | 254 | addr &= ~(CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW << (alen * 8)); |
| 255 | |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 256 | debug("%s: fix addr_overflow: dev %02x addr %02x\n", __func__, dev, |
Alexey Brodkin | 7ef0036 | 2013-12-16 15:30:35 +0400 | [diff] [blame] | 257 | addr); |
| 258 | #endif |
| 259 | |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 260 | if (i2c_xfer_init(i2c_base, dev, addr, alen)) |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 261 | return 1; |
| 262 | |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 263 | start_time_rx = get_timer(0); |
| 264 | while (len) { |
Marek Vasut | c4bc9a8 | 2016-10-20 16:48:28 +0200 | [diff] [blame] | 265 | if (!active) { |
| 266 | /* |
| 267 | * Avoid writing to ic_cmd_data multiple times |
| 268 | * in case this loop spins too quickly and the |
| 269 | * ic_status RFNE bit isn't set after the first |
| 270 | * write. Subsequent writes to ic_cmd_data can |
| 271 | * trigger spurious i2c transfer. |
| 272 | */ |
| 273 | if (len == 1) |
| 274 | writel(IC_CMD | IC_STOP, &i2c_base->ic_cmd_data); |
| 275 | else |
| 276 | writel(IC_CMD, &i2c_base->ic_cmd_data); |
| 277 | active = 1; |
| 278 | } |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 279 | |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 280 | if (readl(&i2c_base->ic_status) & IC_STATUS_RFNE) { |
| 281 | *buffer++ = (uchar)readl(&i2c_base->ic_cmd_data); |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 282 | len--; |
| 283 | start_time_rx = get_timer(0); |
Marek Vasut | c4bc9a8 | 2016-10-20 16:48:28 +0200 | [diff] [blame] | 284 | active = 0; |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 285 | } else if (get_timer(start_time_rx) > I2C_BYTE_TO) { |
Marek Vasut | c4bc9a8 | 2016-10-20 16:48:28 +0200 | [diff] [blame] | 286 | return 1; |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 290 | return i2c_xfer_finish(i2c_base); |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /* |
| 294 | * i2c_write - Write to i2c memory |
| 295 | * @chip: target i2c address |
| 296 | * @addr: address to read from |
| 297 | * @alen: |
| 298 | * @buffer: buffer for read data |
| 299 | * @len: no of bytes to be read |
| 300 | * |
| 301 | * Write to i2c memory. |
| 302 | */ |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 303 | static int __dw_i2c_write(struct i2c_regs *i2c_base, u8 dev, uint addr, |
| 304 | int alen, u8 *buffer, int len) |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 305 | { |
| 306 | int nb = len; |
| 307 | unsigned long start_time_tx; |
| 308 | |
Alexey Brodkin | 7ef0036 | 2013-12-16 15:30:35 +0400 | [diff] [blame] | 309 | #ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW |
| 310 | /* |
| 311 | * EEPROM chips that implement "address overflow" are ones |
| 312 | * like Catalyst 24WC04/08/16 which has 9/10/11 bits of |
| 313 | * address and the extra bits end up in the "chip address" |
| 314 | * bit slots. This makes a 24WC08 (1Kbyte) chip look like |
| 315 | * four 256 byte chips. |
| 316 | * |
| 317 | * Note that we consider the length of the address field to |
| 318 | * still be one byte because the extra address bits are |
| 319 | * hidden in the chip address. |
| 320 | */ |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 321 | dev |= ((addr >> (alen * 8)) & CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW); |
Alexey Brodkin | 7ef0036 | 2013-12-16 15:30:35 +0400 | [diff] [blame] | 322 | addr &= ~(CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW << (alen * 8)); |
| 323 | |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 324 | debug("%s: fix addr_overflow: dev %02x addr %02x\n", __func__, dev, |
Alexey Brodkin | 7ef0036 | 2013-12-16 15:30:35 +0400 | [diff] [blame] | 325 | addr); |
| 326 | #endif |
| 327 | |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 328 | if (i2c_xfer_init(i2c_base, dev, addr, alen)) |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 329 | return 1; |
| 330 | |
| 331 | start_time_tx = get_timer(0); |
| 332 | while (len) { |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 333 | if (readl(&i2c_base->ic_status) & IC_STATUS_TFNF) { |
| 334 | if (--len == 0) { |
| 335 | writel(*buffer | IC_STOP, |
| 336 | &i2c_base->ic_cmd_data); |
| 337 | } else { |
| 338 | writel(*buffer, &i2c_base->ic_cmd_data); |
| 339 | } |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 340 | buffer++; |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 341 | start_time_tx = get_timer(0); |
| 342 | |
| 343 | } else if (get_timer(start_time_tx) > (nb * I2C_BYTE_TO)) { |
| 344 | printf("Timed out. i2c write Failed\n"); |
| 345 | return 1; |
| 346 | } |
| 347 | } |
| 348 | |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 349 | return i2c_xfer_finish(i2c_base); |
| 350 | } |
| 351 | |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 352 | /* |
| 353 | * __dw_i2c_init - Init function |
| 354 | * @speed: required i2c speed |
| 355 | * @slaveaddr: slave address for the device |
| 356 | * |
| 357 | * Initialization function. |
| 358 | */ |
Simon Glass | bd9ca8d | 2019-02-16 20:24:39 -0700 | [diff] [blame] | 359 | static int __dw_i2c_init(struct i2c_regs *i2c_base, int speed, int slaveaddr) |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 360 | { |
Simon Glass | bd9ca8d | 2019-02-16 20:24:39 -0700 | [diff] [blame] | 361 | int ret; |
| 362 | |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 363 | /* Disable i2c */ |
Simon Glass | bd9ca8d | 2019-02-16 20:24:39 -0700 | [diff] [blame] | 364 | ret = dw_i2c_enable(i2c_base, false); |
| 365 | if (ret) |
| 366 | return ret; |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 367 | |
Marek Vasut | 808aa13 | 2017-08-07 20:45:31 +0200 | [diff] [blame] | 368 | writel(IC_CON_SD | IC_CON_RE | IC_CON_SPD_FS | IC_CON_MM, |
| 369 | &i2c_base->ic_con); |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 370 | writel(IC_RX_TL, &i2c_base->ic_rx_tl); |
| 371 | writel(IC_TX_TL, &i2c_base->ic_tx_tl); |
| 372 | writel(IC_STOP_DET, &i2c_base->ic_intr_mask); |
| 373 | #ifndef CONFIG_DM_I2C |
Ley Foon Tan | 6e85c81 | 2019-06-12 09:48:04 +0800 | [diff] [blame] | 374 | __dw_i2c_set_bus_speed(i2c_base, NULL, speed, IC_CLK); |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 375 | writel(slaveaddr, &i2c_base->ic_sar); |
| 376 | #endif |
| 377 | |
| 378 | /* Enable i2c */ |
Simon Glass | bd9ca8d | 2019-02-16 20:24:39 -0700 | [diff] [blame] | 379 | ret = dw_i2c_enable(i2c_base, true); |
| 380 | if (ret) |
| 381 | return ret; |
| 382 | |
| 383 | return 0; |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | #ifndef CONFIG_DM_I2C |
| 387 | /* |
| 388 | * The legacy I2C functions. These need to get removed once |
| 389 | * all users of this driver are converted to DM. |
| 390 | */ |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 391 | static struct i2c_regs *i2c_get_base(struct i2c_adapter *adap) |
| 392 | { |
| 393 | switch (adap->hwadapnr) { |
| 394 | #if CONFIG_SYS_I2C_BUS_MAX >= 4 |
| 395 | case 3: |
| 396 | return (struct i2c_regs *)CONFIG_SYS_I2C_BASE3; |
| 397 | #endif |
| 398 | #if CONFIG_SYS_I2C_BUS_MAX >= 3 |
| 399 | case 2: |
| 400 | return (struct i2c_regs *)CONFIG_SYS_I2C_BASE2; |
| 401 | #endif |
| 402 | #if CONFIG_SYS_I2C_BUS_MAX >= 2 |
| 403 | case 1: |
| 404 | return (struct i2c_regs *)CONFIG_SYS_I2C_BASE1; |
| 405 | #endif |
| 406 | case 0: |
| 407 | return (struct i2c_regs *)CONFIG_SYS_I2C_BASE; |
| 408 | default: |
| 409 | printf("Wrong I2C-adapter number %d\n", adap->hwadapnr); |
| 410 | } |
| 411 | |
| 412 | return NULL; |
| 413 | } |
| 414 | |
| 415 | static unsigned int dw_i2c_set_bus_speed(struct i2c_adapter *adap, |
| 416 | unsigned int speed) |
| 417 | { |
| 418 | adap->speed = speed; |
Ley Foon Tan | 6e85c81 | 2019-06-12 09:48:04 +0800 | [diff] [blame] | 419 | return __dw_i2c_set_bus_speed(i2c_get_base(adap), NULL, speed, IC_CLK); |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 420 | } |
| 421 | |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 422 | static void dw_i2c_init(struct i2c_adapter *adap, int speed, int slaveaddr) |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 423 | { |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 424 | __dw_i2c_init(i2c_get_base(adap), speed, slaveaddr); |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 425 | } |
| 426 | |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 427 | static int dw_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr, |
| 428 | int alen, u8 *buffer, int len) |
| 429 | { |
| 430 | return __dw_i2c_read(i2c_get_base(adap), dev, addr, alen, buffer, len); |
| 431 | } |
| 432 | |
| 433 | static int dw_i2c_write(struct i2c_adapter *adap, u8 dev, uint addr, |
| 434 | int alen, u8 *buffer, int len) |
| 435 | { |
| 436 | return __dw_i2c_write(i2c_get_base(adap), dev, addr, alen, buffer, len); |
| 437 | } |
| 438 | |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 439 | /* dw_i2c_probe - Probe the i2c chip */ |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 440 | static int dw_i2c_probe(struct i2c_adapter *adap, u8 dev) |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 441 | { |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 442 | struct i2c_regs *i2c_base = i2c_get_base(adap); |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 443 | u32 tmp; |
Stefan Roese | f6322ebd | 2012-01-20 11:52:33 +0100 | [diff] [blame] | 444 | int ret; |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 445 | |
| 446 | /* |
| 447 | * Try to read the first location of the chip. |
| 448 | */ |
Stefan Roese | 41de766 | 2016-04-21 08:19:40 +0200 | [diff] [blame] | 449 | ret = __dw_i2c_read(i2c_base, dev, 0, 1, (uchar *)&tmp, 1); |
Stefan Roese | f6322ebd | 2012-01-20 11:52:33 +0100 | [diff] [blame] | 450 | if (ret) |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 451 | dw_i2c_init(adap, adap->speed, adap->slaveaddr); |
Stefan Roese | f6322ebd | 2012-01-20 11:52:33 +0100 | [diff] [blame] | 452 | |
| 453 | return ret; |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 454 | } |
Armando Visconti | 4a7b4ec | 2012-12-06 00:04:15 +0000 | [diff] [blame] | 455 | |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 456 | U_BOOT_I2C_ADAP_COMPLETE(dw_0, dw_i2c_init, dw_i2c_probe, dw_i2c_read, |
| 457 | dw_i2c_write, dw_i2c_set_bus_speed, |
| 458 | CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE, 0) |
Armando Visconti | 4a7b4ec | 2012-12-06 00:04:15 +0000 | [diff] [blame] | 459 | |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 460 | #if CONFIG_SYS_I2C_BUS_MAX >= 2 |
| 461 | U_BOOT_I2C_ADAP_COMPLETE(dw_1, dw_i2c_init, dw_i2c_probe, dw_i2c_read, |
| 462 | dw_i2c_write, dw_i2c_set_bus_speed, |
| 463 | CONFIG_SYS_I2C_SPEED1, CONFIG_SYS_I2C_SLAVE1, 1) |
| 464 | #endif |
Armando Visconti | 4a7b4ec | 2012-12-06 00:04:15 +0000 | [diff] [blame] | 465 | |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 466 | #if CONFIG_SYS_I2C_BUS_MAX >= 3 |
| 467 | U_BOOT_I2C_ADAP_COMPLETE(dw_2, dw_i2c_init, dw_i2c_probe, dw_i2c_read, |
| 468 | dw_i2c_write, dw_i2c_set_bus_speed, |
| 469 | CONFIG_SYS_I2C_SPEED2, CONFIG_SYS_I2C_SLAVE2, 2) |
| 470 | #endif |
Armando Visconti | 4a7b4ec | 2012-12-06 00:04:15 +0000 | [diff] [blame] | 471 | |
Stefan Roese | ef6073e | 2014-10-28 12:12:00 +0100 | [diff] [blame] | 472 | #if CONFIG_SYS_I2C_BUS_MAX >= 4 |
| 473 | U_BOOT_I2C_ADAP_COMPLETE(dw_3, dw_i2c_init, dw_i2c_probe, dw_i2c_read, |
| 474 | dw_i2c_write, dw_i2c_set_bus_speed, |
| 475 | CONFIG_SYS_I2C_SPEED3, CONFIG_SYS_I2C_SLAVE3, 3) |
Armando Visconti | 4a7b4ec | 2012-12-06 00:04:15 +0000 | [diff] [blame] | 476 | #endif |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 477 | |
| 478 | #else /* CONFIG_DM_I2C */ |
| 479 | /* The DM I2C functions */ |
| 480 | |
| 481 | static int designware_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, |
| 482 | int nmsgs) |
| 483 | { |
| 484 | struct dw_i2c *i2c = dev_get_priv(bus); |
| 485 | int ret; |
| 486 | |
| 487 | debug("i2c_xfer: %d messages\n", nmsgs); |
| 488 | for (; nmsgs > 0; nmsgs--, msg++) { |
| 489 | debug("i2c_xfer: chip=0x%x, len=0x%x\n", msg->addr, msg->len); |
| 490 | if (msg->flags & I2C_M_RD) { |
| 491 | ret = __dw_i2c_read(i2c->regs, msg->addr, 0, 0, |
| 492 | msg->buf, msg->len); |
| 493 | } else { |
| 494 | ret = __dw_i2c_write(i2c->regs, msg->addr, 0, 0, |
| 495 | msg->buf, msg->len); |
| 496 | } |
| 497 | if (ret) { |
| 498 | debug("i2c_write: error sending\n"); |
| 499 | return -EREMOTEIO; |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | static int designware_i2c_set_bus_speed(struct udevice *bus, unsigned int speed) |
| 507 | { |
| 508 | struct dw_i2c *i2c = dev_get_priv(bus); |
Ley Foon Tan | 6e85c81 | 2019-06-12 09:48:04 +0800 | [diff] [blame] | 509 | ulong rate; |
| 510 | |
| 511 | #if CONFIG_IS_ENABLED(CLK) |
| 512 | rate = clk_get_rate(&i2c->clk); |
| 513 | if (IS_ERR_VALUE(rate)) |
| 514 | return -EINVAL; |
Ley Foon Tan | 6e85c81 | 2019-06-12 09:48:04 +0800 | [diff] [blame] | 515 | #else |
| 516 | rate = IC_CLK; |
| 517 | #endif |
| 518 | return __dw_i2c_set_bus_speed(i2c->regs, i2c->scl_sda_cfg, speed, |
| 519 | rate); |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static int designware_i2c_probe_chip(struct udevice *bus, uint chip_addr, |
| 523 | uint chip_flags) |
| 524 | { |
| 525 | struct dw_i2c *i2c = dev_get_priv(bus); |
| 526 | struct i2c_regs *i2c_base = i2c->regs; |
| 527 | u32 tmp; |
| 528 | int ret; |
| 529 | |
| 530 | /* Try to read the first location of the chip */ |
| 531 | ret = __dw_i2c_read(i2c_base, chip_addr, 0, 1, (uchar *)&tmp, 1); |
| 532 | if (ret) |
| 533 | __dw_i2c_init(i2c_base, 0, 0); |
| 534 | |
| 535 | return ret; |
| 536 | } |
| 537 | |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 538 | static int designware_i2c_ofdata_to_platdata(struct udevice *bus) |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 539 | { |
| 540 | struct dw_i2c *priv = dev_get_priv(bus); |
| 541 | |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 542 | priv->regs = (struct i2c_regs *)devfdt_get_addr_ptr(bus); |
| 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | int designware_i2c_probe(struct udevice *bus) |
| 548 | { |
| 549 | struct dw_i2c *priv = dev_get_priv(bus); |
| 550 | int ret; |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 551 | |
Simon Goldschmidt | 28608a1 | 2019-03-28 21:11:48 +0100 | [diff] [blame] | 552 | ret = reset_get_bulk(bus, &priv->resets); |
Dinh Nguyen | 08794aa | 2018-04-04 17:18:24 -0500 | [diff] [blame] | 553 | if (ret) |
Simon Goldschmidt | 28608a1 | 2019-03-28 21:11:48 +0100 | [diff] [blame] | 554 | dev_warn(bus, "Can't get reset: %d\n", ret); |
| 555 | else |
| 556 | reset_deassert_bulk(&priv->resets); |
Dinh Nguyen | 08794aa | 2018-04-04 17:18:24 -0500 | [diff] [blame] | 557 | |
Ley Foon Tan | 6e85c81 | 2019-06-12 09:48:04 +0800 | [diff] [blame] | 558 | #if CONFIG_IS_ENABLED(CLK) |
| 559 | ret = clk_get_by_index(bus, 0, &priv->clk); |
| 560 | if (ret) |
| 561 | return ret; |
| 562 | |
| 563 | ret = clk_enable(&priv->clk); |
| 564 | if (ret && ret != -ENOSYS && ret != -ENOTSUPP) { |
| 565 | clk_free(&priv->clk); |
| 566 | dev_err(bus, "failed to enable clock\n"); |
| 567 | return ret; |
| 568 | } |
| 569 | #endif |
| 570 | |
Simon Glass | bd9ca8d | 2019-02-16 20:24:39 -0700 | [diff] [blame] | 571 | return __dw_i2c_init(priv->regs, 0, 0); |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 572 | } |
| 573 | |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 574 | int designware_i2c_remove(struct udevice *dev) |
Simon Goldschmidt | 28608a1 | 2019-03-28 21:11:48 +0100 | [diff] [blame] | 575 | { |
| 576 | struct dw_i2c *priv = dev_get_priv(dev); |
| 577 | |
Ley Foon Tan | 6e85c81 | 2019-06-12 09:48:04 +0800 | [diff] [blame] | 578 | #if CONFIG_IS_ENABLED(CLK) |
| 579 | clk_disable(&priv->clk); |
| 580 | clk_free(&priv->clk); |
| 581 | #endif |
| 582 | |
Simon Goldschmidt | 28608a1 | 2019-03-28 21:11:48 +0100 | [diff] [blame] | 583 | return reset_release_bulk(&priv->resets); |
| 584 | } |
| 585 | |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 586 | const struct dm_i2c_ops designware_i2c_ops = { |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 587 | .xfer = designware_i2c_xfer, |
| 588 | .probe_chip = designware_i2c_probe_chip, |
| 589 | .set_bus_speed = designware_i2c_set_bus_speed, |
| 590 | }; |
| 591 | |
| 592 | static const struct udevice_id designware_i2c_ids[] = { |
| 593 | { .compatible = "snps,designware-i2c" }, |
| 594 | { } |
| 595 | }; |
| 596 | |
| 597 | U_BOOT_DRIVER(i2c_designware) = { |
| 598 | .name = "i2c_designware", |
| 599 | .id = UCLASS_I2C, |
| 600 | .of_match = designware_i2c_ids, |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 601 | .ofdata_to_platdata = designware_i2c_ofdata_to_platdata, |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 602 | .probe = designware_i2c_probe, |
| 603 | .priv_auto_alloc_size = sizeof(struct dw_i2c), |
Simon Goldschmidt | 28608a1 | 2019-03-28 21:11:48 +0100 | [diff] [blame] | 604 | .remove = designware_i2c_remove, |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 605 | .flags = DM_FLAG_OS_PREPARE, |
Stefan Roese | 3cb2796 | 2016-04-21 08:19:41 +0200 | [diff] [blame] | 606 | .ops = &designware_i2c_ops, |
| 607 | }; |
| 608 | |
| 609 | #endif /* CONFIG_DM_I2C */ |