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