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