wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Basic I2C functions |
| 3 | * |
| 4 | * Copyright (c) 2004 Texas Instruments |
| 5 | * |
| 6 | * This package is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the license found in the file |
| 8 | * named COPYING that should have accompanied this file. |
| 9 | * |
| 10 | * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
| 11 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 12 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * |
| 14 | * Author: Jian Zhang jzhang@ti.com, Texas Instruments |
| 15 | * |
| 16 | * Copyright (c) 2003 Wolfgang Denk, wd@denx.de |
| 17 | * Rewritten to fit into the current U-Boot framework |
| 18 | * |
| 19 | * Adapted for OMAP2420 I2C, r-woodruff2@ti.com |
| 20 | * |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 21 | * Copyright (c) 2013 Lubomir Popov <lpopov@mm-sol.com>, MM Solutions |
| 22 | * New i2c_read, i2c_write and i2c_probe functions, tested on OMAP4 |
| 23 | * (4430/60/70), OMAP5 (5430) and AM335X (3359); should work on older |
| 24 | * OMAPs and derivatives as well. The only anticipated exception would |
| 25 | * be the OMAP2420, which shall require driver modification. |
| 26 | * - Rewritten i2c_read to operate correctly with all types of chips |
| 27 | * (old function could not read consistent data from some I2C slaves). |
| 28 | * - Optimized i2c_write. |
| 29 | * - New i2c_probe, performs write access vs read. The old probe could |
| 30 | * hang the system under certain conditions (e.g. unconfigured pads). |
| 31 | * - The read/write/probe functions try to identify unconfigured bus. |
| 32 | * - Status functions now read irqstatus_raw as per TRM guidelines |
| 33 | * (except for OMAP243X and OMAP34XX). |
| 34 | * - Driver now supports up to I2C5 (OMAP5). |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 35 | * |
Hannes Schmelzer | 7935f03 | 2015-05-28 15:41:12 +0200 | [diff] [blame] | 36 | * Copyright (c) 2014 Hannes Schmelzer <oe5hpm@oevsv.at>, B&R |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 37 | * - Added support for set_speed |
| 38 | * |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 39 | */ |
| 40 | |
| 41 | #include <common.h> |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 42 | #include <dm.h> |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 43 | #include <i2c.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 44 | #include <log.h> |
wdenk | cb99da5 | 2005-01-12 00:15:14 +0000 | [diff] [blame] | 45 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 46 | #include <asm/io.h> |
Jean-Jacques Hiblot | 58994fc | 2018-12-07 14:50:42 +0100 | [diff] [blame] | 47 | #include <asm/omap_i2c.h> |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 48 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 49 | /* |
| 50 | * Provide access to architecture-specific I2C header files for platforms |
| 51 | * that are NOT yet solely relying on CONFIG_DM_I2C, CONFIG_OF_CONTROL, and |
| 52 | * the defaults provided in 'omap24xx_i2c.h' for all U-Boot stages where I2C |
| 53 | * access is desired. |
| 54 | */ |
| 55 | #ifndef CONFIG_ARCH_K3 |
| 56 | #include <asm/arch/i2c.h> |
| 57 | #endif |
| 58 | |
Steve Sakoman | 10acc71 | 2010-06-12 06:42:57 -0700 | [diff] [blame] | 59 | #include "omap24xx_i2c.h" |
| 60 | |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 61 | #define I2C_TIMEOUT 1000 |
Steve Sakoman | e2bdc13 | 2010-07-19 20:31:55 -0700 | [diff] [blame] | 62 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 63 | /* Absolutely safe for status update at 100 kHz I2C: */ |
| 64 | #define I2C_WAIT 200 |
| 65 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 66 | enum { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 67 | OMAP_I2C_REV_REG = 0, /* Only on IP V1 (OMAP34XX) */ |
| 68 | OMAP_I2C_IE_REG, /* Only on IP V1 (OMAP34XX) */ |
| 69 | OMAP_I2C_STAT_REG, |
| 70 | OMAP_I2C_WE_REG, |
| 71 | OMAP_I2C_SYSS_REG, |
| 72 | OMAP_I2C_BUF_REG, |
| 73 | OMAP_I2C_CNT_REG, |
| 74 | OMAP_I2C_DATA_REG, |
| 75 | OMAP_I2C_SYSC_REG, |
| 76 | OMAP_I2C_CON_REG, |
| 77 | OMAP_I2C_OA_REG, |
| 78 | OMAP_I2C_SA_REG, |
| 79 | OMAP_I2C_PSC_REG, |
| 80 | OMAP_I2C_SCLL_REG, |
| 81 | OMAP_I2C_SCLH_REG, |
| 82 | OMAP_I2C_SYSTEST_REG, |
| 83 | OMAP_I2C_BUFSTAT_REG, |
| 84 | /* Only on IP V2 (OMAP4430, etc.) */ |
| 85 | OMAP_I2C_IP_V2_REVNB_LO, |
| 86 | OMAP_I2C_IP_V2_REVNB_HI, |
| 87 | OMAP_I2C_IP_V2_IRQSTATUS_RAW, |
| 88 | OMAP_I2C_IP_V2_IRQENABLE_SET, |
| 89 | OMAP_I2C_IP_V2_IRQENABLE_CLR, |
| 90 | }; |
| 91 | |
| 92 | static const u8 __maybe_unused reg_map_ip_v1[] = { |
| 93 | [OMAP_I2C_REV_REG] = 0x00, |
| 94 | [OMAP_I2C_IE_REG] = 0x04, |
| 95 | [OMAP_I2C_STAT_REG] = 0x08, |
| 96 | [OMAP_I2C_WE_REG] = 0x0c, |
| 97 | [OMAP_I2C_SYSS_REG] = 0x10, |
| 98 | [OMAP_I2C_BUF_REG] = 0x14, |
| 99 | [OMAP_I2C_CNT_REG] = 0x18, |
| 100 | [OMAP_I2C_DATA_REG] = 0x1c, |
| 101 | [OMAP_I2C_SYSC_REG] = 0x20, |
| 102 | [OMAP_I2C_CON_REG] = 0x24, |
| 103 | [OMAP_I2C_OA_REG] = 0x28, |
| 104 | [OMAP_I2C_SA_REG] = 0x2c, |
| 105 | [OMAP_I2C_PSC_REG] = 0x30, |
| 106 | [OMAP_I2C_SCLL_REG] = 0x34, |
| 107 | [OMAP_I2C_SCLH_REG] = 0x38, |
| 108 | [OMAP_I2C_SYSTEST_REG] = 0x3c, |
| 109 | [OMAP_I2C_BUFSTAT_REG] = 0x40, |
| 110 | }; |
| 111 | |
| 112 | static const u8 __maybe_unused reg_map_ip_v2[] = { |
| 113 | [OMAP_I2C_STAT_REG] = 0x28, |
| 114 | [OMAP_I2C_WE_REG] = 0x34, |
| 115 | [OMAP_I2C_SYSS_REG] = 0x90, |
| 116 | [OMAP_I2C_BUF_REG] = 0x94, |
| 117 | [OMAP_I2C_CNT_REG] = 0x98, |
| 118 | [OMAP_I2C_DATA_REG] = 0x9c, |
| 119 | [OMAP_I2C_SYSC_REG] = 0x10, |
| 120 | [OMAP_I2C_CON_REG] = 0xa4, |
| 121 | [OMAP_I2C_OA_REG] = 0xa8, |
| 122 | [OMAP_I2C_SA_REG] = 0xac, |
| 123 | [OMAP_I2C_PSC_REG] = 0xb0, |
| 124 | [OMAP_I2C_SCLL_REG] = 0xb4, |
| 125 | [OMAP_I2C_SCLH_REG] = 0xb8, |
| 126 | [OMAP_I2C_SYSTEST_REG] = 0xbc, |
| 127 | [OMAP_I2C_BUFSTAT_REG] = 0xc0, |
| 128 | [OMAP_I2C_IP_V2_REVNB_LO] = 0x00, |
| 129 | [OMAP_I2C_IP_V2_REVNB_HI] = 0x04, |
| 130 | [OMAP_I2C_IP_V2_IRQSTATUS_RAW] = 0x24, |
| 131 | [OMAP_I2C_IP_V2_IRQENABLE_SET] = 0x2c, |
| 132 | [OMAP_I2C_IP_V2_IRQENABLE_CLR] = 0x30, |
| 133 | }; |
| 134 | |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 135 | struct omap_i2c { |
| 136 | struct udevice *clk; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 137 | int ip_rev; |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 138 | struct i2c *regs; |
| 139 | unsigned int speed; |
| 140 | int waitdelay; |
| 141 | int clk_id; |
| 142 | }; |
| 143 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 144 | static inline const u8 *omap_i2c_get_ip_reg_map(int ip_rev) |
| 145 | { |
| 146 | switch (ip_rev) { |
| 147 | case OMAP_I2C_REV_V1: |
| 148 | return reg_map_ip_v1; |
| 149 | case OMAP_I2C_REV_V2: |
| 150 | /* Fall through... */ |
| 151 | default: |
| 152 | return reg_map_ip_v2; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | static inline void omap_i2c_write_reg(void __iomem *base, int ip_rev, |
| 157 | u16 val, int reg) |
| 158 | { |
| 159 | writew(val, base + omap_i2c_get_ip_reg_map(ip_rev)[reg]); |
| 160 | } |
| 161 | |
| 162 | static inline u16 omap_i2c_read_reg(void __iomem *base, int ip_rev, int reg) |
| 163 | { |
| 164 | return readw(base + omap_i2c_get_ip_reg_map(ip_rev)[reg]); |
| 165 | } |
| 166 | |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 167 | static int omap24_i2c_findpsc(u32 *pscl, u32 *psch, uint speed) |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 168 | { |
Lukasz Majewski | 698a9ba | 2017-03-15 16:59:23 +0100 | [diff] [blame] | 169 | unsigned long internal_clk = 0, fclk; |
| 170 | unsigned int prescaler; |
Tom Rix | 03b2a74 | 2009-06-28 12:52:27 -0500 | [diff] [blame] | 171 | |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 172 | /* |
Lukasz Majewski | 698a9ba | 2017-03-15 16:59:23 +0100 | [diff] [blame] | 173 | * This method is only called for Standard and Fast Mode speeds |
| 174 | * |
| 175 | * For some TI SoCs it is explicitly written in TRM (e,g, SPRUHZ6G, |
| 176 | * page 5685, Table 24-7) |
| 177 | * that the internal I2C clock (after prescaler) should be between |
| 178 | * 7-12 MHz (at least for Fast Mode (FS)). |
| 179 | * |
| 180 | * Such approach is used in v4.9 Linux kernel in: |
| 181 | * ./drivers/i2c/busses/i2c-omap.c (omap_i2c_init function). |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 182 | */ |
Tom Rix | 03b2a74 | 2009-06-28 12:52:27 -0500 | [diff] [blame] | 183 | |
Lukasz Majewski | 698a9ba | 2017-03-15 16:59:23 +0100 | [diff] [blame] | 184 | speed /= 1000; /* convert speed to kHz */ |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 185 | |
Lukasz Majewski | 698a9ba | 2017-03-15 16:59:23 +0100 | [diff] [blame] | 186 | if (speed > 100) |
| 187 | internal_clk = 9600; |
| 188 | else |
| 189 | internal_clk = 4000; |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 190 | |
Lukasz Majewski | 698a9ba | 2017-03-15 16:59:23 +0100 | [diff] [blame] | 191 | fclk = I2C_IP_CLK / 1000; |
| 192 | prescaler = fclk / internal_clk; |
| 193 | prescaler = prescaler - 1; |
| 194 | |
| 195 | if (speed > 100) { |
| 196 | unsigned long scl; |
| 197 | |
| 198 | /* Fast mode */ |
| 199 | scl = internal_clk / speed; |
| 200 | *pscl = scl - (scl / 3) - I2C_FASTSPEED_SCLL_TRIM; |
| 201 | *psch = (scl / 3) - I2C_FASTSPEED_SCLH_TRIM; |
| 202 | } else { |
| 203 | /* Standard mode */ |
| 204 | *pscl = internal_clk / (speed * 2) - I2C_FASTSPEED_SCLL_TRIM; |
| 205 | *psch = internal_clk / (speed * 2) - I2C_FASTSPEED_SCLH_TRIM; |
Tom Rix | 03b2a74 | 2009-06-28 12:52:27 -0500 | [diff] [blame] | 206 | } |
Lukasz Majewski | 698a9ba | 2017-03-15 16:59:23 +0100 | [diff] [blame] | 207 | |
| 208 | debug("%s: speed [kHz]: %d psc: 0x%x sscl: 0x%x ssch: 0x%x\n", |
| 209 | __func__, speed, prescaler, *pscl, *psch); |
| 210 | |
| 211 | if (*pscl <= 0 || *psch <= 0 || prescaler <= 0) |
| 212 | return -EINVAL; |
| 213 | |
| 214 | return prescaler; |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 215 | } |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 216 | |
| 217 | /* |
| 218 | * Wait for the bus to be free by checking the Bus Busy (BB) |
| 219 | * bit to become clear |
| 220 | */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 221 | static int wait_for_bb(void __iomem *i2c_base, int ip_rev, int waitdelay) |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 222 | { |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 223 | int timeout = I2C_TIMEOUT; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 224 | int irq_stat_reg; |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 225 | u16 stat; |
| 226 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 227 | irq_stat_reg = (ip_rev == OMAP_I2C_REV_V1) ? |
| 228 | OMAP_I2C_STAT_REG : OMAP_I2C_IP_V2_IRQSTATUS_RAW; |
| 229 | |
| 230 | /* clear current interrupts */ |
| 231 | omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG); |
| 232 | |
| 233 | while ((stat = omap_i2c_read_reg(i2c_base, ip_rev, irq_stat_reg) & |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 234 | I2C_STAT_BB) && timeout--) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 235 | omap_i2c_write_reg(i2c_base, ip_rev, stat, OMAP_I2C_STAT_REG); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 236 | udelay(waitdelay); |
| 237 | } |
| 238 | |
| 239 | if (timeout <= 0) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 240 | printf("Timed out in %s: status=%04x\n", __func__, stat); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 241 | return 1; |
| 242 | } |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 243 | |
| 244 | /* clear delayed stuff */ |
| 245 | omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | /* |
| 250 | * Wait for the I2C controller to complete current action |
| 251 | * and update status |
| 252 | */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 253 | static u16 wait_for_event(void __iomem *i2c_base, int ip_rev, int waitdelay) |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 254 | { |
| 255 | u16 status; |
| 256 | int timeout = I2C_TIMEOUT; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 257 | int irq_stat_reg; |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 258 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 259 | irq_stat_reg = (ip_rev == OMAP_I2C_REV_V1) ? |
| 260 | OMAP_I2C_STAT_REG : OMAP_I2C_IP_V2_IRQSTATUS_RAW; |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 261 | do { |
| 262 | udelay(waitdelay); |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 263 | status = omap_i2c_read_reg(i2c_base, ip_rev, irq_stat_reg); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 264 | } while (!(status & |
| 265 | (I2C_STAT_ROVR | I2C_STAT_XUDF | I2C_STAT_XRDY | |
| 266 | I2C_STAT_RRDY | I2C_STAT_ARDY | I2C_STAT_NACK | |
| 267 | I2C_STAT_AL)) && timeout--); |
| 268 | |
| 269 | if (timeout <= 0) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 270 | printf("Timed out in %s: status=%04x\n", __func__, status); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 271 | /* |
| 272 | * If status is still 0 here, probably the bus pads have |
| 273 | * not been configured for I2C, and/or pull-ups are missing. |
| 274 | */ |
| 275 | printf("Check if pads/pull-ups of bus are properly configured\n"); |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 276 | omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 277 | status = 0; |
| 278 | } |
| 279 | |
| 280 | return status; |
| 281 | } |
| 282 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 283 | static void flush_fifo(void __iomem *i2c_base, int ip_rev) |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 284 | { |
| 285 | u16 stat; |
| 286 | |
| 287 | /* |
| 288 | * note: if you try and read data when its not there or ready |
| 289 | * you get a bus error |
| 290 | */ |
| 291 | while (1) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 292 | stat = omap_i2c_read_reg(i2c_base, ip_rev, OMAP_I2C_STAT_REG); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 293 | if (stat == I2C_STAT_RRDY) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 294 | omap_i2c_read_reg(i2c_base, ip_rev, OMAP_I2C_DATA_REG); |
| 295 | omap_i2c_write_reg(i2c_base, ip_rev, |
| 296 | I2C_STAT_RRDY, OMAP_I2C_STAT_REG); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 297 | udelay(1000); |
| 298 | } else |
| 299 | break; |
| 300 | } |
| 301 | } |
| 302 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 303 | static int __omap24_i2c_setspeed(void __iomem *i2c_base, int ip_rev, uint speed, |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 304 | int *waitdelay) |
| 305 | { |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 306 | int psc, fsscll = 0, fssclh = 0; |
| 307 | int hsscll = 0, hssclh = 0; |
| 308 | u32 scll = 0, sclh = 0; |
Tom Rix | 03b2a74 | 2009-06-28 12:52:27 -0500 | [diff] [blame] | 309 | |
Simon Glass | ed0a60a | 2020-01-23 11:48:20 -0700 | [diff] [blame] | 310 | if (speed >= I2C_SPEED_HIGH_RATE) { |
Tom Rix | 03b2a74 | 2009-06-28 12:52:27 -0500 | [diff] [blame] | 311 | /* High speed */ |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 312 | psc = I2C_IP_CLK / I2C_INTERNAL_SAMPLING_CLK; |
| 313 | psc -= 1; |
| 314 | if (psc < I2C_PSC_MIN) { |
| 315 | printf("Error : I2C unsupported prescaler %d\n", psc); |
| 316 | return -1; |
| 317 | } |
Tom Rix | 03b2a74 | 2009-06-28 12:52:27 -0500 | [diff] [blame] | 318 | |
| 319 | /* For first phase of HS mode */ |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 320 | fsscll = I2C_INTERNAL_SAMPLING_CLK / (2 * speed); |
| 321 | |
| 322 | fssclh = fsscll; |
Tom Rix | 03b2a74 | 2009-06-28 12:52:27 -0500 | [diff] [blame] | 323 | |
| 324 | fsscll -= I2C_HIGHSPEED_PHASE_ONE_SCLL_TRIM; |
| 325 | fssclh -= I2C_HIGHSPEED_PHASE_ONE_SCLH_TRIM; |
| 326 | if (((fsscll < 0) || (fssclh < 0)) || |
| 327 | ((fsscll > 255) || (fssclh > 255))) { |
Andreas Müller | a30293f | 2012-01-04 15:26:19 +0000 | [diff] [blame] | 328 | puts("Error : I2C initializing first phase clock\n"); |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 329 | return -1; |
Tom Rix | 03b2a74 | 2009-06-28 12:52:27 -0500 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /* For second phase of HS mode */ |
| 333 | hsscll = hssclh = I2C_INTERNAL_SAMPLING_CLK / (2 * speed); |
| 334 | |
| 335 | hsscll -= I2C_HIGHSPEED_PHASE_TWO_SCLL_TRIM; |
| 336 | hssclh -= I2C_HIGHSPEED_PHASE_TWO_SCLH_TRIM; |
| 337 | if (((fsscll < 0) || (fssclh < 0)) || |
| 338 | ((fsscll > 255) || (fssclh > 255))) { |
Andreas Müller | a30293f | 2012-01-04 15:26:19 +0000 | [diff] [blame] | 339 | puts("Error : I2C initializing second phase clock\n"); |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 340 | return -1; |
Tom Rix | 03b2a74 | 2009-06-28 12:52:27 -0500 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | scll = (unsigned int)hsscll << 8 | (unsigned int)fsscll; |
| 344 | sclh = (unsigned int)hssclh << 8 | (unsigned int)fssclh; |
| 345 | |
| 346 | } else { |
| 347 | /* Standard and fast speed */ |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 348 | psc = omap24_i2c_findpsc(&scll, &sclh, speed); |
| 349 | if (0 > psc) { |
Andreas Müller | a30293f | 2012-01-04 15:26:19 +0000 | [diff] [blame] | 350 | puts("Error : I2C initializing clock\n"); |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 351 | return -1; |
Tom Rix | 03b2a74 | 2009-06-28 12:52:27 -0500 | [diff] [blame] | 352 | } |
Tom Rix | 03b2a74 | 2009-06-28 12:52:27 -0500 | [diff] [blame] | 353 | } |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 354 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 355 | /* wait for 20 clkperiods */ |
| 356 | *waitdelay = (10000000 / speed) * 2; |
| 357 | |
| 358 | omap_i2c_write_reg(i2c_base, ip_rev, 0, OMAP_I2C_CON_REG); |
| 359 | omap_i2c_write_reg(i2c_base, ip_rev, psc, OMAP_I2C_PSC_REG); |
| 360 | omap_i2c_write_reg(i2c_base, ip_rev, scll, OMAP_I2C_SCLL_REG); |
| 361 | omap_i2c_write_reg(i2c_base, ip_rev, sclh, OMAP_I2C_SCLH_REG); |
| 362 | omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN, OMAP_I2C_CON_REG); |
| 363 | |
| 364 | /* clear all pending status */ |
| 365 | omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG); |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 366 | |
| 367 | return 0; |
| 368 | } |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 369 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 370 | static void omap24_i2c_deblock(void __iomem *i2c_base, int ip_rev) |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 371 | { |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 372 | int i; |
| 373 | u16 systest; |
| 374 | u16 orgsystest; |
| 375 | |
| 376 | /* set test mode ST_EN = 1 */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 377 | orgsystest = omap_i2c_read_reg(i2c_base, ip_rev, OMAP_I2C_SYSTEST_REG); |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 378 | systest = orgsystest; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 379 | |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 380 | /* enable testmode */ |
| 381 | systest |= I2C_SYSTEST_ST_EN; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 382 | omap_i2c_write_reg(i2c_base, ip_rev, systest, OMAP_I2C_SYSTEST_REG); |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 383 | systest &= ~I2C_SYSTEST_TMODE_MASK; |
| 384 | systest |= 3 << I2C_SYSTEST_TMODE_SHIFT; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 385 | omap_i2c_write_reg(i2c_base, ip_rev, systest, OMAP_I2C_SYSTEST_REG); |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 386 | |
| 387 | /* set SCL, SDA = 1 */ |
| 388 | systest |= I2C_SYSTEST_SCL_O | I2C_SYSTEST_SDA_O; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 389 | omap_i2c_write_reg(i2c_base, ip_rev, systest, OMAP_I2C_SYSTEST_REG); |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 390 | udelay(10); |
| 391 | |
| 392 | /* toggle scl 9 clocks */ |
| 393 | for (i = 0; i < 9; i++) { |
| 394 | /* SCL = 0 */ |
| 395 | systest &= ~I2C_SYSTEST_SCL_O; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 396 | omap_i2c_write_reg(i2c_base, ip_rev, |
| 397 | systest, OMAP_I2C_SYSTEST_REG); |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 398 | udelay(10); |
| 399 | /* SCL = 1 */ |
| 400 | systest |= I2C_SYSTEST_SCL_O; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 401 | omap_i2c_write_reg(i2c_base, ip_rev, |
| 402 | systest, OMAP_I2C_SYSTEST_REG); |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 403 | udelay(10); |
| 404 | } |
| 405 | |
| 406 | /* send stop */ |
| 407 | systest &= ~I2C_SYSTEST_SDA_O; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 408 | omap_i2c_write_reg(i2c_base, ip_rev, systest, OMAP_I2C_SYSTEST_REG); |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 409 | udelay(10); |
| 410 | systest |= I2C_SYSTEST_SCL_O | I2C_SYSTEST_SDA_O; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 411 | omap_i2c_write_reg(i2c_base, ip_rev, systest, OMAP_I2C_SYSTEST_REG); |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 412 | udelay(10); |
| 413 | |
| 414 | /* restore original mode */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 415 | omap_i2c_write_reg(i2c_base, ip_rev, orgsystest, OMAP_I2C_SYSTEST_REG); |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 416 | } |
| 417 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 418 | static void __omap24_i2c_init(void __iomem *i2c_base, int ip_rev, int speed, |
| 419 | int slaveadd, int *waitdelay) |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 420 | { |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 421 | int timeout = I2C_TIMEOUT; |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 422 | int deblock = 1; |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 423 | |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 424 | retry: |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 425 | if (omap_i2c_read_reg(i2c_base, ip_rev, OMAP_I2C_CON_REG) & |
| 426 | I2C_CON_EN) { |
| 427 | omap_i2c_write_reg(i2c_base, ip_rev, 0, OMAP_I2C_CON_REG); |
Michael Jones | 4db6786 | 2011-07-27 14:01:55 -0400 | [diff] [blame] | 428 | udelay(50000); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 431 | /* for ES2 after soft reset */ |
| 432 | omap_i2c_write_reg(i2c_base, ip_rev, 0x2, OMAP_I2C_SYSC_REG); |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 433 | udelay(1000); |
| 434 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 435 | omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN, OMAP_I2C_CON_REG); |
| 436 | while (!(omap_i2c_read_reg(i2c_base, ip_rev, OMAP_I2C_SYSS_REG) & |
| 437 | I2C_SYSS_RDONE) && timeout--) { |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 438 | if (timeout <= 0) { |
| 439 | puts("ERROR: Timeout in soft-reset\n"); |
| 440 | return; |
| 441 | } |
| 442 | udelay(1000); |
| 443 | } |
| 444 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 445 | if (__omap24_i2c_setspeed(i2c_base, ip_rev, speed, waitdelay)) { |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 446 | printf("ERROR: failed to setup I2C bus-speed!\n"); |
| 447 | return; |
| 448 | } |
Tom Rix | 03b2a74 | 2009-06-28 12:52:27 -0500 | [diff] [blame] | 449 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 450 | /* own address */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 451 | omap_i2c_write_reg(i2c_base, ip_rev, slaveadd, OMAP_I2C_OA_REG); |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 452 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 453 | if (ip_rev == OMAP_I2C_REV_V1) { |
| 454 | /* |
| 455 | * Have to enable interrupts for OMAP2/3, these IPs don't have |
| 456 | * an 'irqstatus_raw' register and we shall have to poll 'stat' |
| 457 | */ |
| 458 | omap_i2c_write_reg(i2c_base, ip_rev, I2C_IE_XRDY_IE | |
| 459 | I2C_IE_RRDY_IE | I2C_IE_ARDY_IE | |
| 460 | I2C_IE_NACK_IE | I2C_IE_AL_IE, |
| 461 | OMAP_I2C_IE_REG); |
| 462 | } |
| 463 | |
Michael Jones | 4db6786 | 2011-07-27 14:01:55 -0400 | [diff] [blame] | 464 | udelay(1000); |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 465 | flush_fifo(i2c_base, ip_rev); |
| 466 | omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG); |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 467 | |
| 468 | /* Handle possible failed I2C state */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 469 | if (wait_for_bb(i2c_base, ip_rev, *waitdelay)) |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 470 | if (deblock == 1) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 471 | omap24_i2c_deblock(i2c_base, ip_rev); |
Heiko Schocher | 0ecd655 | 2014-06-30 09:12:09 +0200 | [diff] [blame] | 472 | deblock = 0; |
| 473 | goto retry; |
| 474 | } |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 475 | } |
| 476 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 477 | /* |
| 478 | * i2c_probe: Use write access. Allows to identify addresses that are |
| 479 | * write-only (like the config register of dual-port EEPROMs) |
| 480 | */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 481 | static int __omap24_i2c_probe(void __iomem *i2c_base, int ip_rev, int waitdelay, |
| 482 | uchar chip) |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 483 | { |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 484 | u16 status; |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 485 | int res = 1; /* default = fail */ |
| 486 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 487 | if (chip == omap_i2c_read_reg(i2c_base, ip_rev, OMAP_I2C_OA_REG)) |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 488 | return res; |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 489 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 490 | /* Wait until bus is free */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 491 | if (wait_for_bb(i2c_base, ip_rev, waitdelay)) |
Vincent Stehlé | 33205e3 | 2012-12-03 05:23:16 +0000 | [diff] [blame] | 492 | return res; |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 493 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 494 | /* No data transfer, slave addr only */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 495 | omap_i2c_write_reg(i2c_base, ip_rev, chip, OMAP_I2C_SA_REG); |
| 496 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 497 | /* Stop bit needed here */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 498 | omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN | I2C_CON_MST | |
| 499 | I2C_CON_STT | I2C_CON_TRX | I2C_CON_STP, |
| 500 | OMAP_I2C_CON_REG); |
Nick Thompson | 48f7ae4 | 2011-04-11 22:37:41 +0000 | [diff] [blame] | 501 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 502 | status = wait_for_event(i2c_base, ip_rev, waitdelay); |
Vincent Stehlé | 33205e3 | 2012-12-03 05:23:16 +0000 | [diff] [blame] | 503 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 504 | if ((status & ~I2C_STAT_XRDY) == 0 || (status & I2C_STAT_AL)) { |
| 505 | /* |
| 506 | * With current high-level command implementation, notifying |
| 507 | * the user shall flood the console with 127 messages. If |
| 508 | * silent exit is desired upon unconfigured bus, remove the |
| 509 | * following 'if' section: |
| 510 | */ |
| 511 | if (status == I2C_STAT_XRDY) |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 512 | printf("i2c_probe: pads on bus probably not configured (status=0x%x)\n", |
| 513 | status); |
Vincent Stehlé | 33205e3 | 2012-12-03 05:23:16 +0000 | [diff] [blame] | 514 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 515 | goto pr_exit; |
Tom Rini | 27eed8b | 2012-05-21 06:46:29 +0000 | [diff] [blame] | 516 | } |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 517 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 518 | /* Check for ACK (!NAK) */ |
| 519 | if (!(status & I2C_STAT_NACK)) { |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 520 | res = 0; /* Device found */ |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 521 | udelay(waitdelay);/* Required by AM335X in SPL */ |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 522 | /* Abort transfer (force idle state) */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 523 | omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_MST | I2C_CON_TRX, |
| 524 | OMAP_I2C_CON_REG); /* Reset */ |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 525 | udelay(1000); |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 526 | omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN | I2C_CON_MST | |
| 527 | I2C_CON_TRX | I2C_CON_STP, |
| 528 | OMAP_I2C_CON_REG); /* STP */ |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 529 | } |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 530 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 531 | pr_exit: |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 532 | flush_fifo(i2c_base, ip_rev); |
| 533 | omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 534 | return res; |
| 535 | } |
| 536 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 537 | /* |
| 538 | * i2c_read: Function now uses a single I2C read transaction with bulk transfer |
| 539 | * of the requested number of bytes (note that the 'i2c md' command |
| 540 | * limits this to 16 bytes anyway). If CONFIG_I2C_REPEATED_START is |
| 541 | * defined in the board config header, this transaction shall be with |
| 542 | * Repeated Start (Sr) between the address and data phases; otherwise |
| 543 | * Stop-Start (P-S) shall be used (some I2C chips do require a P-S). |
| 544 | * The address (reg offset) may be 0, 1 or 2 bytes long. |
| 545 | * Function now reads correctly from chips that return more than one |
| 546 | * byte of data per addressed register (like TI temperature sensors), |
| 547 | * or that do not need a register address at all (such as some clock |
| 548 | * distributors). |
| 549 | */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 550 | static int __omap24_i2c_read(void __iomem *i2c_base, int ip_rev, int waitdelay, |
| 551 | uchar chip, uint addr, int alen, uchar *buffer, |
| 552 | int len) |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 553 | { |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 554 | int i2c_error = 0; |
| 555 | u16 status; |
| 556 | |
| 557 | if (alen < 0) { |
| 558 | puts("I2C read: addr len < 0\n"); |
| 559 | return 1; |
| 560 | } |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 561 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 562 | if (len < 0) { |
| 563 | puts("I2C read: data len < 0\n"); |
| 564 | return 1; |
| 565 | } |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 566 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 567 | if (buffer == NULL) { |
| 568 | puts("I2C read: NULL pointer passed\n"); |
| 569 | return 1; |
| 570 | } |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 571 | |
Ilya Yanok | be6c2e4 | 2012-06-08 03:12:09 +0000 | [diff] [blame] | 572 | if (alen > 2) { |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 573 | printf("I2C read: addr len %d not supported\n", alen); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 574 | return 1; |
| 575 | } |
| 576 | |
Ilya Yanok | be6c2e4 | 2012-06-08 03:12:09 +0000 | [diff] [blame] | 577 | if (addr + len > (1 << 16)) { |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 578 | puts("I2C read: address out of range\n"); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 579 | return 1; |
| 580 | } |
| 581 | |
Guy Thouret | 51c2727 | 2016-03-11 16:23:41 +0000 | [diff] [blame] | 582 | #ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW |
| 583 | /* |
| 584 | * EEPROM chips that implement "address overflow" are ones |
| 585 | * like Catalyst 24WC04/08/16 which has 9/10/11 bits of |
| 586 | * address and the extra bits end up in the "chip address" |
| 587 | * bit slots. This makes a 24WC08 (1Kbyte) chip look like |
| 588 | * four 256 byte chips. |
| 589 | * |
| 590 | * Note that we consider the length of the address field to |
| 591 | * still be one byte because the extra address bits are |
| 592 | * hidden in the chip address. |
| 593 | */ |
| 594 | if (alen > 0) |
| 595 | chip |= ((addr >> (alen * 8)) & |
| 596 | CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW); |
| 597 | #endif |
| 598 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 599 | /* Wait until bus not busy */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 600 | if (wait_for_bb(i2c_base, ip_rev, waitdelay)) |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 601 | return 1; |
| 602 | |
| 603 | /* Zero, one or two bytes reg address (offset) */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 604 | omap_i2c_write_reg(i2c_base, ip_rev, alen, OMAP_I2C_CNT_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 605 | /* Set slave address */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 606 | omap_i2c_write_reg(i2c_base, ip_rev, chip, OMAP_I2C_SA_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 607 | |
| 608 | if (alen) { |
| 609 | /* Must write reg offset first */ |
| 610 | #ifdef CONFIG_I2C_REPEATED_START |
| 611 | /* No stop bit, use Repeated Start (Sr) */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 612 | omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN | I2C_CON_MST | |
| 613 | I2C_CON_STT | I2C_CON_TRX, OMAP_I2C_CON_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 614 | #else |
| 615 | /* Stop - Start (P-S) */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 616 | omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN | I2C_CON_MST | |
| 617 | I2C_CON_STT | I2C_CON_STP | I2C_CON_TRX, |
| 618 | OMAP_I2C_CON_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 619 | #endif |
| 620 | /* Send register offset */ |
| 621 | while (1) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 622 | status = wait_for_event(i2c_base, ip_rev, waitdelay); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 623 | /* Try to identify bus that is not padconf'd for I2C */ |
| 624 | if (status == I2C_STAT_XRDY) { |
| 625 | i2c_error = 2; |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 626 | printf("i2c_read (addr phase): pads on bus probably not configured (status=0x%x)\n", |
| 627 | status); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 628 | goto rd_exit; |
| 629 | } |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 630 | if (status == 0 || (status & I2C_STAT_NACK)) { |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 631 | i2c_error = 1; |
| 632 | printf("i2c_read: error waiting for addr ACK (status=0x%x)\n", |
| 633 | status); |
| 634 | goto rd_exit; |
| 635 | } |
| 636 | if (alen) { |
| 637 | if (status & I2C_STAT_XRDY) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 638 | u8 addr_byte; |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 639 | alen--; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 640 | addr_byte = (addr >> (8 * alen)) & 0xff; |
| 641 | omap_i2c_write_reg(i2c_base, ip_rev, |
| 642 | addr_byte, |
| 643 | OMAP_I2C_DATA_REG); |
| 644 | omap_i2c_write_reg(i2c_base, ip_rev, |
| 645 | I2C_STAT_XRDY, |
| 646 | OMAP_I2C_STAT_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 647 | } |
| 648 | } |
| 649 | if (status & I2C_STAT_ARDY) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 650 | omap_i2c_write_reg(i2c_base, ip_rev, |
| 651 | I2C_STAT_ARDY, |
| 652 | OMAP_I2C_STAT_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 653 | break; |
| 654 | } |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 655 | } |
| 656 | } |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 657 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 658 | /* Set slave address */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 659 | omap_i2c_write_reg(i2c_base, ip_rev, chip, OMAP_I2C_SA_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 660 | /* Read len bytes from slave */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 661 | omap_i2c_write_reg(i2c_base, ip_rev, len, OMAP_I2C_CNT_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 662 | /* Need stop bit here */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 663 | omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN | I2C_CON_MST | |
| 664 | I2C_CON_STT | I2C_CON_STP, OMAP_I2C_CON_REG); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 665 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 666 | /* Receive data */ |
| 667 | while (1) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 668 | status = wait_for_event(i2c_base, ip_rev, waitdelay); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 669 | /* |
| 670 | * Try to identify bus that is not padconf'd for I2C. This |
| 671 | * state could be left over from previous transactions if |
| 672 | * the address phase is skipped due to alen=0. |
| 673 | */ |
| 674 | if (status == I2C_STAT_XRDY) { |
| 675 | i2c_error = 2; |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 676 | printf("i2c_read (data phase): pads on bus probably not configured (status=0x%x)\n", |
| 677 | status); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 678 | goto rd_exit; |
| 679 | } |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 680 | if (status == 0 || (status & I2C_STAT_NACK)) { |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 681 | i2c_error = 1; |
| 682 | goto rd_exit; |
| 683 | } |
| 684 | if (status & I2C_STAT_RRDY) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 685 | *buffer++ = omap_i2c_read_reg(i2c_base, ip_rev, |
| 686 | OMAP_I2C_DATA_REG); |
| 687 | omap_i2c_write_reg(i2c_base, ip_rev, |
| 688 | I2C_STAT_RRDY, OMAP_I2C_STAT_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 689 | } |
| 690 | if (status & I2C_STAT_ARDY) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 691 | omap_i2c_write_reg(i2c_base, ip_rev, |
| 692 | I2C_STAT_ARDY, OMAP_I2C_STAT_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 693 | break; |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | rd_exit: |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 698 | flush_fifo(i2c_base, ip_rev); |
| 699 | omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 700 | return i2c_error; |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 701 | } |
| 702 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 703 | /* i2c_write: Address (reg offset) may be 0, 1 or 2 bytes long. */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 704 | static int __omap24_i2c_write(void __iomem *i2c_base, int ip_rev, int waitdelay, |
| 705 | uchar chip, uint addr, int alen, uchar *buffer, |
| 706 | int len) |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 707 | { |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 708 | int i; |
| 709 | u16 status; |
| 710 | int i2c_error = 0; |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 711 | int timeout = I2C_TIMEOUT; |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 712 | |
| 713 | if (alen < 0) { |
| 714 | puts("I2C write: addr len < 0\n"); |
| 715 | return 1; |
| 716 | } |
| 717 | |
| 718 | if (len < 0) { |
| 719 | puts("I2C write: data len < 0\n"); |
| 720 | return 1; |
| 721 | } |
| 722 | |
| 723 | if (buffer == NULL) { |
| 724 | puts("I2C write: NULL pointer passed\n"); |
| 725 | return 1; |
| 726 | } |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 727 | |
Ilya Yanok | be6c2e4 | 2012-06-08 03:12:09 +0000 | [diff] [blame] | 728 | if (alen > 2) { |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 729 | printf("I2C write: addr len %d not supported\n", alen); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 730 | return 1; |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 731 | } |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 732 | |
Ilya Yanok | be6c2e4 | 2012-06-08 03:12:09 +0000 | [diff] [blame] | 733 | if (addr + len > (1 << 16)) { |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 734 | printf("I2C write: address 0x%x + 0x%x out of range\n", |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 735 | addr, len); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 736 | return 1; |
| 737 | } |
| 738 | |
Guy Thouret | 51c2727 | 2016-03-11 16:23:41 +0000 | [diff] [blame] | 739 | #ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW |
| 740 | /* |
| 741 | * EEPROM chips that implement "address overflow" are ones |
| 742 | * like Catalyst 24WC04/08/16 which has 9/10/11 bits of |
| 743 | * address and the extra bits end up in the "chip address" |
| 744 | * bit slots. This makes a 24WC08 (1Kbyte) chip look like |
| 745 | * four 256 byte chips. |
| 746 | * |
| 747 | * Note that we consider the length of the address field to |
| 748 | * still be one byte because the extra address bits are |
| 749 | * hidden in the chip address. |
| 750 | */ |
| 751 | if (alen > 0) |
| 752 | chip |= ((addr >> (alen * 8)) & |
| 753 | CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW); |
| 754 | #endif |
| 755 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 756 | /* Wait until bus not busy */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 757 | if (wait_for_bb(i2c_base, ip_rev, waitdelay)) |
Vincent Stehlé | 33205e3 | 2012-12-03 05:23:16 +0000 | [diff] [blame] | 758 | return 1; |
Michael Jones | bb54d57 | 2011-09-04 14:01:55 -0400 | [diff] [blame] | 759 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 760 | /* Start address phase - will write regoffset + len bytes data */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 761 | omap_i2c_write_reg(i2c_base, ip_rev, alen + len, OMAP_I2C_CNT_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 762 | /* Set slave address */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 763 | omap_i2c_write_reg(i2c_base, ip_rev, chip, OMAP_I2C_SA_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 764 | /* Stop bit needed here */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 765 | omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN | I2C_CON_MST | |
| 766 | I2C_CON_STT | I2C_CON_TRX | I2C_CON_STP, |
| 767 | OMAP_I2C_CON_REG); |
Michael Jones | bb54d57 | 2011-09-04 14:01:55 -0400 | [diff] [blame] | 768 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 769 | while (alen) { |
| 770 | /* Must write reg offset (one or two bytes) */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 771 | status = wait_for_event(i2c_base, ip_rev, waitdelay); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 772 | /* Try to identify bus that is not padconf'd for I2C */ |
| 773 | if (status == I2C_STAT_XRDY) { |
| 774 | i2c_error = 2; |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 775 | printf("i2c_write: pads on bus probably not configured (status=0x%x)\n", |
| 776 | status); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 777 | goto wr_exit; |
| 778 | } |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 779 | if (status == 0 || (status & I2C_STAT_NACK)) { |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 780 | i2c_error = 1; |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 781 | printf("i2c_write: error waiting for addr ACK (status=0x%x)\n", |
| 782 | status); |
| 783 | goto wr_exit; |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 784 | } |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 785 | if (status & I2C_STAT_XRDY) { |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 786 | alen--; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 787 | omap_i2c_write_reg(i2c_base, ip_rev, |
| 788 | (addr >> (8 * alen)) & 0xff, |
| 789 | OMAP_I2C_DATA_REG); |
| 790 | omap_i2c_write_reg(i2c_base, ip_rev, |
| 791 | I2C_STAT_XRDY, OMAP_I2C_STAT_REG); |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 792 | } else { |
| 793 | i2c_error = 1; |
| 794 | printf("i2c_write: bus not ready for addr Tx (status=0x%x)\n", |
| 795 | status); |
| 796 | goto wr_exit; |
| 797 | } |
| 798 | } |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 799 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 800 | /* Address phase is over, now write data */ |
| 801 | for (i = 0; i < len; i++) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 802 | status = wait_for_event(i2c_base, ip_rev, waitdelay); |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 803 | if (status == 0 || (status & I2C_STAT_NACK)) { |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 804 | i2c_error = 1; |
| 805 | printf("i2c_write: error waiting for data ACK (status=0x%x)\n", |
| 806 | status); |
| 807 | goto wr_exit; |
| 808 | } |
| 809 | if (status & I2C_STAT_XRDY) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 810 | omap_i2c_write_reg(i2c_base, ip_rev, |
| 811 | buffer[i], OMAP_I2C_DATA_REG); |
| 812 | omap_i2c_write_reg(i2c_base, ip_rev, |
| 813 | I2C_STAT_XRDY, OMAP_I2C_STAT_REG); |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 814 | } else { |
| 815 | i2c_error = 1; |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 816 | printf("i2c_write: bus not ready for data Tx (i=%d)\n", |
| 817 | i); |
| 818 | goto wr_exit; |
Patil, Rachna | a9e18c2 | 2012-01-22 23:44:12 +0000 | [diff] [blame] | 819 | } |
| 820 | } |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 821 | |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 822 | /* |
| 823 | * poll ARDY bit for making sure that last byte really has been |
| 824 | * transferred on the bus. |
| 825 | */ |
| 826 | do { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 827 | status = wait_for_event(i2c_base, ip_rev, waitdelay); |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 828 | } while (!(status & I2C_STAT_ARDY) && timeout--); |
| 829 | if (timeout <= 0) |
| 830 | printf("i2c_write: timed out writig last byte!\n"); |
Patil, Rachna | a9e18c2 | 2012-01-22 23:44:12 +0000 | [diff] [blame] | 831 | |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 832 | wr_exit: |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 833 | flush_fifo(i2c_base, ip_rev); |
| 834 | omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG); |
Tom Rini | 49fbf67 | 2012-02-20 18:49:16 +0000 | [diff] [blame] | 835 | return i2c_error; |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 836 | } |
| 837 | |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 838 | #ifndef CONFIG_DM_I2C |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 839 | /* |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 840 | * The legacy I2C functions. These need to get removed once |
| 841 | * all users of this driver are converted to DM. |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 842 | */ |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 843 | static void __iomem *omap24_get_base(struct i2c_adapter *adap) |
Dirk Behme | 7a8f657 | 2009-11-02 20:36:26 +0100 | [diff] [blame] | 844 | { |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 845 | switch (adap->hwadapnr) { |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 846 | case 0: |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 847 | return (void __iomem *)I2C_BASE1; |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 848 | break; |
| 849 | case 1: |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 850 | return (void __iomem *)I2C_BASE2; |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 851 | break; |
Adam Ford | 73010ab | 2017-08-11 06:39:13 -0500 | [diff] [blame] | 852 | #if (CONFIG_SYS_I2C_BUS_MAX > 2) |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 853 | case 2: |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 854 | return (void __iomem *)I2C_BASE3; |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 855 | break; |
Adam Ford | 73010ab | 2017-08-11 06:39:13 -0500 | [diff] [blame] | 856 | #if (CONFIG_SYS_I2C_BUS_MAX > 3) |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 857 | case 3: |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 858 | return (void __iomem *)I2C_BASE4; |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 859 | break; |
Adam Ford | 73010ab | 2017-08-11 06:39:13 -0500 | [diff] [blame] | 860 | #if (CONFIG_SYS_I2C_BUS_MAX > 4) |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 861 | case 4: |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 862 | return (void __iomem *)I2C_BASE5; |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 863 | break; |
Koen Kooi | 584ff5f | 2012-08-08 00:57:35 +0000 | [diff] [blame] | 864 | #endif |
Dirk Behme | 7a8f657 | 2009-11-02 20:36:26 +0100 | [diff] [blame] | 865 | #endif |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 866 | #endif |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 867 | default: |
| 868 | printf("wrong hwadapnr: %d\n", adap->hwadapnr); |
| 869 | break; |
Lubomir Popov | 4d98efd | 2013-06-01 06:44:38 +0000 | [diff] [blame] | 870 | } |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 871 | |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 872 | return NULL; |
| 873 | } |
Dirk Behme | 7a8f657 | 2009-11-02 20:36:26 +0100 | [diff] [blame] | 874 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 875 | static int omap24_get_ip_rev(void) |
| 876 | { |
| 877 | #ifdef CONFIG_OMAP34XX |
| 878 | return OMAP_I2C_REV_V1; |
| 879 | #else |
| 880 | return OMAP_I2C_REV_V2; |
| 881 | #endif |
| 882 | } |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 883 | |
| 884 | static int omap24_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr, |
| 885 | int alen, uchar *buffer, int len) |
| 886 | { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 887 | void __iomem *i2c_base = omap24_get_base(adap); |
| 888 | int ip_rev = omap24_get_ip_rev(); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 889 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 890 | return __omap24_i2c_read(i2c_base, ip_rev, adap->waitdelay, chip, addr, |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 891 | alen, buffer, len); |
| 892 | } |
| 893 | |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 894 | static int omap24_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr, |
| 895 | int alen, uchar *buffer, int len) |
| 896 | { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 897 | void __iomem *i2c_base = omap24_get_base(adap); |
| 898 | int ip_rev = omap24_get_ip_rev(); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 899 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 900 | return __omap24_i2c_write(i2c_base, ip_rev, adap->waitdelay, chip, addr, |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 901 | alen, buffer, len); |
| 902 | } |
| 903 | |
| 904 | static uint omap24_i2c_setspeed(struct i2c_adapter *adap, uint speed) |
| 905 | { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 906 | void __iomem *i2c_base = omap24_get_base(adap); |
| 907 | int ip_rev = omap24_get_ip_rev(); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 908 | int ret; |
| 909 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 910 | ret = __omap24_i2c_setspeed(i2c_base, ip_rev, speed, &adap->waitdelay); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 911 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 912 | pr_err("%s: set i2c speed failed\n", __func__); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 913 | return ret; |
| 914 | } |
| 915 | |
| 916 | adap->speed = speed; |
| 917 | |
| 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | static void omap24_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd) |
| 922 | { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 923 | void __iomem *i2c_base = omap24_get_base(adap); |
| 924 | int ip_rev = omap24_get_ip_rev(); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 925 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 926 | return __omap24_i2c_init(i2c_base, ip_rev, speed, slaveadd, |
| 927 | &adap->waitdelay); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | static int omap24_i2c_probe(struct i2c_adapter *adap, uchar chip) |
| 931 | { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 932 | void __iomem *i2c_base = omap24_get_base(adap); |
| 933 | int ip_rev = omap24_get_ip_rev(); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 934 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 935 | return __omap24_i2c_probe(i2c_base, ip_rev, adap->waitdelay, chip); |
Mugunthan V N | 38d943a | 2016-07-18 15:11:00 +0530 | [diff] [blame] | 936 | } |
| 937 | |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 938 | #if !defined(CONFIG_SYS_OMAP24_I2C_SPEED1) |
| 939 | #define CONFIG_SYS_OMAP24_I2C_SPEED1 CONFIG_SYS_OMAP24_I2C_SPEED |
| 940 | #endif |
| 941 | #if !defined(CONFIG_SYS_OMAP24_I2C_SLAVE1) |
| 942 | #define CONFIG_SYS_OMAP24_I2C_SLAVE1 CONFIG_SYS_OMAP24_I2C_SLAVE |
| 943 | #endif |
Dirk Behme | 7a8f657 | 2009-11-02 20:36:26 +0100 | [diff] [blame] | 944 | |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 945 | U_BOOT_I2C_ADAP_COMPLETE(omap24_0, omap24_i2c_init, omap24_i2c_probe, |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 946 | omap24_i2c_read, omap24_i2c_write, omap24_i2c_setspeed, |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 947 | CONFIG_SYS_OMAP24_I2C_SPEED, |
| 948 | CONFIG_SYS_OMAP24_I2C_SLAVE, |
| 949 | 0) |
| 950 | U_BOOT_I2C_ADAP_COMPLETE(omap24_1, omap24_i2c_init, omap24_i2c_probe, |
Hannes Petermaier | d588505 | 2014-02-03 21:22:18 +0100 | [diff] [blame] | 951 | omap24_i2c_read, omap24_i2c_write, omap24_i2c_setspeed, |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 952 | CONFIG_SYS_OMAP24_I2C_SPEED1, |
| 953 | CONFIG_SYS_OMAP24_I2C_SLAVE1, |
| 954 | 1) |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 955 | |
Adam Ford | 73010ab | 2017-08-11 06:39:13 -0500 | [diff] [blame] | 956 | #if (CONFIG_SYS_I2C_BUS_MAX > 2) |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 957 | #if !defined(CONFIG_SYS_OMAP24_I2C_SPEED2) |
| 958 | #define CONFIG_SYS_OMAP24_I2C_SPEED2 CONFIG_SYS_OMAP24_I2C_SPEED |
| 959 | #endif |
| 960 | #if !defined(CONFIG_SYS_OMAP24_I2C_SLAVE2) |
| 961 | #define CONFIG_SYS_OMAP24_I2C_SLAVE2 CONFIG_SYS_OMAP24_I2C_SLAVE |
| 962 | #endif |
Dirk Behme | 7a8f657 | 2009-11-02 20:36:26 +0100 | [diff] [blame] | 963 | |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 964 | U_BOOT_I2C_ADAP_COMPLETE(omap24_2, omap24_i2c_init, omap24_i2c_probe, |
| 965 | omap24_i2c_read, omap24_i2c_write, NULL, |
| 966 | CONFIG_SYS_OMAP24_I2C_SPEED2, |
| 967 | CONFIG_SYS_OMAP24_I2C_SLAVE2, |
| 968 | 2) |
Adam Ford | 73010ab | 2017-08-11 06:39:13 -0500 | [diff] [blame] | 969 | #if (CONFIG_SYS_I2C_BUS_MAX > 3) |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 970 | #if !defined(CONFIG_SYS_OMAP24_I2C_SPEED3) |
| 971 | #define CONFIG_SYS_OMAP24_I2C_SPEED3 CONFIG_SYS_OMAP24_I2C_SPEED |
| 972 | #endif |
| 973 | #if !defined(CONFIG_SYS_OMAP24_I2C_SLAVE3) |
| 974 | #define CONFIG_SYS_OMAP24_I2C_SLAVE3 CONFIG_SYS_OMAP24_I2C_SLAVE |
| 975 | #endif |
Steve Sakoman | 10acc71 | 2010-06-12 06:42:57 -0700 | [diff] [blame] | 976 | |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 977 | U_BOOT_I2C_ADAP_COMPLETE(omap24_3, omap24_i2c_init, omap24_i2c_probe, |
| 978 | omap24_i2c_read, omap24_i2c_write, NULL, |
| 979 | CONFIG_SYS_OMAP24_I2C_SPEED3, |
| 980 | CONFIG_SYS_OMAP24_I2C_SLAVE3, |
| 981 | 3) |
Adam Ford | 73010ab | 2017-08-11 06:39:13 -0500 | [diff] [blame] | 982 | #if (CONFIG_SYS_I2C_BUS_MAX > 4) |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 983 | #if !defined(CONFIG_SYS_OMAP24_I2C_SPEED4) |
| 984 | #define CONFIG_SYS_OMAP24_I2C_SPEED4 CONFIG_SYS_OMAP24_I2C_SPEED |
| 985 | #endif |
| 986 | #if !defined(CONFIG_SYS_OMAP24_I2C_SLAVE4) |
| 987 | #define CONFIG_SYS_OMAP24_I2C_SLAVE4 CONFIG_SYS_OMAP24_I2C_SLAVE |
| 988 | #endif |
| 989 | |
| 990 | U_BOOT_I2C_ADAP_COMPLETE(omap24_4, omap24_i2c_init, omap24_i2c_probe, |
| 991 | omap24_i2c_read, omap24_i2c_write, NULL, |
| 992 | CONFIG_SYS_OMAP24_I2C_SPEED4, |
| 993 | CONFIG_SYS_OMAP24_I2C_SLAVE4, |
| 994 | 4) |
| 995 | #endif |
| 996 | #endif |
| 997 | #endif |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 998 | |
| 999 | #else /* CONFIG_DM_I2C */ |
| 1000 | |
| 1001 | static int omap_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, int nmsgs) |
| 1002 | { |
| 1003 | struct omap_i2c *priv = dev_get_priv(bus); |
| 1004 | int ret; |
| 1005 | |
| 1006 | debug("i2c_xfer: %d messages\n", nmsgs); |
| 1007 | for (; nmsgs > 0; nmsgs--, msg++) { |
| 1008 | debug("i2c_xfer: chip=0x%x, len=0x%x\n", msg->addr, msg->len); |
| 1009 | if (msg->flags & I2C_M_RD) { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 1010 | ret = __omap24_i2c_read(priv->regs, priv->ip_rev, |
| 1011 | priv->waitdelay, |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1012 | msg->addr, 0, 0, msg->buf, |
| 1013 | msg->len); |
| 1014 | } else { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 1015 | ret = __omap24_i2c_write(priv->regs, priv->ip_rev, |
| 1016 | priv->waitdelay, |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1017 | msg->addr, 0, 0, msg->buf, |
| 1018 | msg->len); |
| 1019 | } |
| 1020 | if (ret) { |
| 1021 | debug("i2c_write: error sending\n"); |
| 1022 | return -EREMOTEIO; |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
| 1029 | static int omap_i2c_set_bus_speed(struct udevice *bus, unsigned int speed) |
| 1030 | { |
| 1031 | struct omap_i2c *priv = dev_get_priv(bus); |
| 1032 | |
| 1033 | priv->speed = speed; |
| 1034 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 1035 | return __omap24_i2c_setspeed(priv->regs, priv->ip_rev, speed, |
| 1036 | &priv->waitdelay); |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | static int omap_i2c_probe_chip(struct udevice *bus, uint chip_addr, |
| 1040 | uint chip_flags) |
| 1041 | { |
| 1042 | struct omap_i2c *priv = dev_get_priv(bus); |
| 1043 | |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 1044 | return __omap24_i2c_probe(priv->regs, priv->ip_rev, priv->waitdelay, |
| 1045 | chip_addr); |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | static int omap_i2c_probe(struct udevice *bus) |
| 1049 | { |
| 1050 | struct omap_i2c *priv = dev_get_priv(bus); |
Jean-Jacques Hiblot | 58994fc | 2018-12-07 14:50:42 +0100 | [diff] [blame] | 1051 | struct omap_i2c_platdata *plat = dev_get_platdata(bus); |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1052 | |
Jean-Jacques Hiblot | 58994fc | 2018-12-07 14:50:42 +0100 | [diff] [blame] | 1053 | priv->speed = plat->speed; |
| 1054 | priv->regs = map_physmem(plat->base, sizeof(void *), |
| 1055 | MAP_NOCACHE); |
| 1056 | priv->ip_rev = plat->ip_rev; |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 1057 | |
| 1058 | __omap24_i2c_init(priv->regs, priv->ip_rev, priv->speed, 0, |
| 1059 | &priv->waitdelay); |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1060 | |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
Adam Ford | 1f09846 | 2018-08-20 20:24:35 -0500 | [diff] [blame] | 1064 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1065 | static int omap_i2c_ofdata_to_platdata(struct udevice *bus) |
| 1066 | { |
Jean-Jacques Hiblot | 58994fc | 2018-12-07 14:50:42 +0100 | [diff] [blame] | 1067 | struct omap_i2c_platdata *plat = dev_get_platdata(bus); |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1068 | |
Jean-Jacques Hiblot | 58994fc | 2018-12-07 14:50:42 +0100 | [diff] [blame] | 1069 | plat->base = devfdt_get_addr(bus); |
Simon Glass | f0c99c5 | 2020-01-23 11:48:22 -0700 | [diff] [blame] | 1070 | plat->speed = dev_read_u32_default(bus, "clock-frequency", |
| 1071 | I2C_SPEED_STANDARD_RATE); |
Jean-Jacques Hiblot | 58994fc | 2018-12-07 14:50:42 +0100 | [diff] [blame] | 1072 | plat->ip_rev = dev_get_driver_data(bus); |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1073 | |
| 1074 | return 0; |
| 1075 | } |
| 1076 | |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1077 | static const struct udevice_id omap_i2c_ids[] = { |
Vignesh R | 3f51de3 | 2018-12-07 14:50:41 +0100 | [diff] [blame] | 1078 | { .compatible = "ti,omap3-i2c", .data = OMAP_I2C_REV_V1 }, |
| 1079 | { .compatible = "ti,omap4-i2c", .data = OMAP_I2C_REV_V2 }, |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1080 | { } |
| 1081 | }; |
Adam Ford | 1f09846 | 2018-08-20 20:24:35 -0500 | [diff] [blame] | 1082 | #endif |
| 1083 | |
| 1084 | static const struct dm_i2c_ops omap_i2c_ops = { |
| 1085 | .xfer = omap_i2c_xfer, |
| 1086 | .probe_chip = omap_i2c_probe_chip, |
| 1087 | .set_bus_speed = omap_i2c_set_bus_speed, |
| 1088 | }; |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1089 | |
| 1090 | U_BOOT_DRIVER(i2c_omap) = { |
| 1091 | .name = "i2c_omap", |
| 1092 | .id = UCLASS_I2C, |
Adam Ford | 1f09846 | 2018-08-20 20:24:35 -0500 | [diff] [blame] | 1093 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1094 | .of_match = omap_i2c_ids, |
| 1095 | .ofdata_to_platdata = omap_i2c_ofdata_to_platdata, |
Jean-Jacques Hiblot | 58994fc | 2018-12-07 14:50:42 +0100 | [diff] [blame] | 1096 | .platdata_auto_alloc_size = sizeof(struct omap_i2c_platdata), |
Adam Ford | 1f09846 | 2018-08-20 20:24:35 -0500 | [diff] [blame] | 1097 | #endif |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1098 | .probe = omap_i2c_probe, |
| 1099 | .priv_auto_alloc_size = sizeof(struct omap_i2c), |
| 1100 | .ops = &omap_i2c_ops, |
Bin Meng | a61b962 | 2018-10-24 06:36:31 -0700 | [diff] [blame] | 1101 | #if !CONFIG_IS_ENABLED(OF_CONTROL) |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1102 | .flags = DM_FLAG_PRE_RELOC, |
Bin Meng | a61b962 | 2018-10-24 06:36:31 -0700 | [diff] [blame] | 1103 | #endif |
Mugunthan V N | 560037b | 2016-07-18 15:11:01 +0530 | [diff] [blame] | 1104 | }; |
| 1105 | |
| 1106 | #endif /* CONFIG_DM_I2C */ |