wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * David Mueller, ELSOFT AG, d.mueller@elsoft.ch |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* This code should work for both the S3C2400 and the S3C2410 |
| 25 | * as they seem to have the same I2C controller inside. |
| 26 | * The different address mapping is handled by the s3c24xx.h files below. |
| 27 | */ |
| 28 | |
| 29 | #include <common.h> |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 30 | #ifdef CONFIG_EXYNOS5 |
| 31 | #include <asm/arch/clk.h> |
| 32 | #include <asm/arch/cpu.h> |
| 33 | #else |
kevin.morfitt@fearnside-systems.co.uk | ac67804 | 2009-11-17 18:30:34 +0900 | [diff] [blame] | 34 | #include <asm/arch/s3c24x0_cpu.h> |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 35 | #endif |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 36 | #include <asm/io.h> |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 37 | #include <i2c.h> |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 38 | #include "s3c24x0_i2c.h" |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 39 | |
| 40 | #ifdef CONFIG_HARD_I2C |
| 41 | |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 42 | #define I2C_WRITE 0 |
| 43 | #define I2C_READ 1 |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 44 | |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 45 | #define I2C_OK 0 |
| 46 | #define I2C_NOK 1 |
| 47 | #define I2C_NACK 2 |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 48 | #define I2C_NOK_LA 3 /* Lost arbitration */ |
| 49 | #define I2C_NOK_TOUT 4 /* time out */ |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 50 | |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 51 | #define I2CSTAT_BSY 0x20 /* Busy bit */ |
| 52 | #define I2CSTAT_NACK 0x01 /* Nack bit */ |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 53 | #define I2CCON_ACKGEN 0x80 /* Acknowledge generation */ |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 54 | #define I2CCON_IRPND 0x10 /* Interrupt pending bit */ |
| 55 | #define I2C_MODE_MT 0xC0 /* Master Transmit Mode */ |
| 56 | #define I2C_MODE_MR 0x80 /* Master Receive Mode */ |
| 57 | #define I2C_START_STOP 0x20 /* START / STOP */ |
| 58 | #define I2C_TXRX_ENA 0x10 /* I2C Tx/Rx enable */ |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 59 | |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 60 | #define I2C_TIMEOUT 1 /* 1 second */ |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 61 | |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 62 | |
| 63 | static unsigned int g_current_bus; /* Stores Current I2C Bus */ |
| 64 | |
| 65 | #ifndef CONFIG_EXYNOS5 |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 66 | static int GetI2CSDA(void) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 67 | { |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 68 | struct s3c24x0_gpio *gpio = s3c24x0_get_base_gpio(); |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 69 | |
wdenk | 6dff552 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 70 | #ifdef CONFIG_S3C2410 |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 71 | return (readl(&gpio->gpedat) & 0x8000) >> 15; |
wdenk | 6dff552 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 72 | #endif |
| 73 | #ifdef CONFIG_S3C2400 |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 74 | return (readl(&gpio->pgdat) & 0x0020) >> 5; |
wdenk | 6dff552 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 75 | #endif |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 76 | } |
| 77 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 78 | #if 0 |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 79 | static void SetI2CSDA(int x) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 80 | { |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 81 | rGPEDAT = (rGPEDAT & ~0x8000) | (x & 1) << 15; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 82 | } |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 83 | #endif |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 84 | |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 85 | static void SetI2CSCL(int x) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 86 | { |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 87 | struct s3c24x0_gpio *gpio = s3c24x0_get_base_gpio(); |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 88 | |
wdenk | 6dff552 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 89 | #ifdef CONFIG_S3C2410 |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 90 | writel((readl(&gpio->gpedat) & ~0x4000) | |
| 91 | (x & 1) << 14, &gpio->gpedat); |
wdenk | 6dff552 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 92 | #endif |
| 93 | #ifdef CONFIG_S3C2400 |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 94 | writel((readl(&gpio->pgdat) & ~0x0040) | (x & 1) << 6, &gpio->pgdat); |
wdenk | 6dff552 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 95 | #endif |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 96 | } |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 97 | #endif |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 98 | |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 99 | static int WaitForXfer(struct s3c24x0_i2c *i2c) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 100 | { |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 101 | int i; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 102 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 103 | i = I2C_TIMEOUT * 10000; |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 104 | while (!(readl(&i2c->iiccon) & I2CCON_IRPND) && (i > 0)) { |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 105 | udelay(100); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 106 | i--; |
| 107 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 108 | |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 109 | return (readl(&i2c->iiccon) & I2CCON_IRPND) ? I2C_OK : I2C_NOK_TOUT; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 112 | static int IsACK(struct s3c24x0_i2c *i2c) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 113 | { |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 114 | return !(readl(&i2c->iicstat) & I2CSTAT_NACK); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 117 | static void ReadWriteByte(struct s3c24x0_i2c *i2c) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 118 | { |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 119 | writel(readl(&i2c->iiccon) & ~I2CCON_IRPND, &i2c->iiccon); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 122 | static struct s3c24x0_i2c *get_base_i2c(void) |
| 123 | { |
| 124 | #ifdef CONFIG_EXYNOS5 |
| 125 | struct s3c24x0_i2c *i2c = (struct s3c24x0_i2c *)(samsung_get_base_i2c() |
| 126 | + (EXYNOS5_I2C_SPACING |
| 127 | * g_current_bus)); |
| 128 | return i2c; |
| 129 | #else |
| 130 | return s3c24x0_get_base_i2c(); |
| 131 | #endif |
| 132 | } |
| 133 | |
| 134 | static void i2c_ch_init(struct s3c24x0_i2c *i2c, int speed, int slaveadd) |
| 135 | { |
| 136 | ulong freq, pres = 16, div; |
| 137 | #ifdef CONFIG_EXYNOS5 |
| 138 | freq = get_i2c_clk(); |
| 139 | #else |
| 140 | freq = get_PCLK(); |
| 141 | #endif |
| 142 | /* calculate prescaler and divisor values */ |
| 143 | if ((freq / pres / (16 + 1)) > speed) |
| 144 | /* set prescaler to 512 */ |
| 145 | pres = 512; |
| 146 | |
| 147 | div = 0; |
| 148 | while ((freq / pres / (div + 1)) > speed) |
| 149 | div++; |
| 150 | |
| 151 | /* set prescaler, divisor according to freq, also set ACKGEN, IRQ */ |
| 152 | writel((div & 0x0F) | 0xA0 | ((pres == 512) ? 0x40 : 0), &i2c->iiccon); |
| 153 | |
| 154 | /* init to SLAVE REVEIVE and set slaveaddr */ |
| 155 | writel(0, &i2c->iicstat); |
| 156 | writel(slaveadd, &i2c->iicadd); |
| 157 | /* program Master Transmit (and implicit STOP) */ |
| 158 | writel(I2C_MODE_MT | I2C_TXRX_ENA, &i2c->iicstat); |
| 159 | } |
| 160 | |
Rajeshwari Shinde | 178239d | 2012-07-23 21:23:54 +0000 | [diff] [blame] | 161 | /* |
| 162 | * MULTI BUS I2C support |
| 163 | */ |
| 164 | |
| 165 | #ifdef CONFIG_I2C_MULTI_BUS |
| 166 | int i2c_set_bus_num(unsigned int bus) |
| 167 | { |
| 168 | struct s3c24x0_i2c *i2c; |
| 169 | |
| 170 | if ((bus < 0) || (bus >= CONFIG_MAX_I2C_NUM)) { |
| 171 | debug("Bad bus: %d\n", bus); |
| 172 | return -1; |
| 173 | } |
| 174 | |
| 175 | g_current_bus = bus; |
| 176 | i2c = get_base_i2c(); |
| 177 | i2c_ch_init(i2c, CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | unsigned int i2c_get_bus_num(void) |
| 183 | { |
| 184 | return g_current_bus; |
| 185 | } |
| 186 | #endif |
| 187 | |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 188 | void i2c_init(int speed, int slaveadd) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 189 | { |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 190 | struct s3c24x0_i2c *i2c; |
| 191 | #ifndef CONFIG_EXYNOS5 |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 192 | struct s3c24x0_gpio *gpio = s3c24x0_get_base_gpio(); |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 193 | #endif |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 194 | int i; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 195 | |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 196 | /* By default i2c channel 0 is the current bus */ |
| 197 | g_current_bus = 0; |
| 198 | i2c = get_base_i2c(); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 199 | |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 200 | /* wait for some time to give previous transfer a chance to finish */ |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 201 | i = I2C_TIMEOUT * 1000; |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 202 | while ((readl(&i2c->iicstat) & I2CSTAT_BSY) && (i > 0)) { |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 203 | udelay(1000); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 204 | i--; |
| 205 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 206 | |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 207 | #ifndef CONFIG_EXYNOS5 |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 208 | if ((readl(&i2c->iicstat) & I2CSTAT_BSY) || GetI2CSDA() == 0) { |
wdenk | 6dff552 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 209 | #ifdef CONFIG_S3C2410 |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 210 | ulong old_gpecon = readl(&gpio->gpecon); |
wdenk | 6dff552 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 211 | #endif |
| 212 | #ifdef CONFIG_S3C2400 |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 213 | ulong old_gpecon = readl(&gpio->pgcon); |
wdenk | 6dff552 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 214 | #endif |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 215 | /* bus still busy probably by (most) previously interrupted |
| 216 | transfer */ |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 217 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 218 | #ifdef CONFIG_S3C2410 |
| 219 | /* set I2CSDA and I2CSCL (GPE15, GPE14) to GPIO */ |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 220 | writel((readl(&gpio->gpecon) & ~0xF0000000) | 0x10000000, |
| 221 | &gpio->gpecon); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 222 | #endif |
| 223 | #ifdef CONFIG_S3C2400 |
| 224 | /* set I2CSDA and I2CSCL (PG5, PG6) to GPIO */ |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 225 | writel((readl(&gpio->pgcon) & ~0x00003c00) | 0x00001000, |
| 226 | &gpio->pgcon); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 227 | #endif |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 228 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 229 | /* toggle I2CSCL until bus idle */ |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 230 | SetI2CSCL(0); |
| 231 | udelay(1000); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 232 | i = 10; |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 233 | while ((i > 0) && (GetI2CSDA() != 1)) { |
| 234 | SetI2CSCL(1); |
| 235 | udelay(1000); |
| 236 | SetI2CSCL(0); |
| 237 | udelay(1000); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 238 | i--; |
| 239 | } |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 240 | SetI2CSCL(1); |
| 241 | udelay(1000); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 242 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 243 | /* restore pin functions */ |
| 244 | #ifdef CONFIG_S3C2410 |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 245 | writel(old_gpecon, &gpio->gpecon); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 246 | #endif |
| 247 | #ifdef CONFIG_S3C2400 |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 248 | writel(old_gpecon, &gpio->pgcon); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 249 | #endif |
| 250 | } |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 251 | #endif /* #ifndef CONFIG_EXYNOS5 */ |
| 252 | i2c_ch_init(i2c, speed, slaveadd); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /* |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 256 | * cmd_type is 0 for write, 1 for read. |
| 257 | * |
| 258 | * addr_len can take any value from 0-255, it is only limited |
| 259 | * by the char, we could make it larger if needed. If it is |
| 260 | * 0 we skip the address write cycle. |
| 261 | */ |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 262 | static int i2c_transfer(struct s3c24x0_i2c *i2c, |
| 263 | unsigned char cmd_type, |
| 264 | unsigned char chip, |
| 265 | unsigned char addr[], |
| 266 | unsigned char addr_len, |
| 267 | unsigned char data[], |
| 268 | unsigned short data_len) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 269 | { |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 270 | int i, result; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 271 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 272 | if (data == 0 || data_len == 0) { |
| 273 | /*Don't support data transfer of no length or to address 0 */ |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 274 | debug("i2c_transfer: bad call\n"); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 275 | return I2C_NOK; |
| 276 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 277 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 278 | /* Check I2C bus idle */ |
| 279 | i = I2C_TIMEOUT * 1000; |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 280 | while ((readl(&i2c->iicstat) & I2CSTAT_BSY) && (i > 0)) { |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 281 | udelay(1000); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 282 | i--; |
| 283 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 284 | |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 285 | if (readl(&i2c->iicstat) & I2CSTAT_BSY) |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 286 | return I2C_NOK_TOUT; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 287 | |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 288 | writel(readl(&i2c->iiccon) | I2CCON_ACKGEN, &i2c->iiccon); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 289 | result = I2C_OK; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 290 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 291 | switch (cmd_type) { |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 292 | case I2C_WRITE: |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 293 | if (addr && addr_len) { |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 294 | writel(chip, &i2c->iicds); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 295 | /* send START */ |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 296 | writel(I2C_MODE_MT | I2C_TXRX_ENA | I2C_START_STOP, |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 297 | &i2c->iicstat); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 298 | i = 0; |
| 299 | while ((i < addr_len) && (result == I2C_OK)) { |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 300 | result = WaitForXfer(i2c); |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 301 | writel(addr[i], &i2c->iicds); |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 302 | ReadWriteByte(i2c); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 303 | i++; |
| 304 | } |
| 305 | i = 0; |
| 306 | while ((i < data_len) && (result == I2C_OK)) { |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 307 | result = WaitForXfer(i2c); |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 308 | writel(data[i], &i2c->iicds); |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 309 | ReadWriteByte(i2c); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 310 | i++; |
| 311 | } |
| 312 | } else { |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 313 | writel(chip, &i2c->iicds); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 314 | /* send START */ |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 315 | writel(I2C_MODE_MT | I2C_TXRX_ENA | I2C_START_STOP, |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 316 | &i2c->iicstat); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 317 | i = 0; |
| 318 | while ((i < data_len) && (result = I2C_OK)) { |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 319 | result = WaitForXfer(i2c); |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 320 | writel(data[i], &i2c->iicds); |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 321 | ReadWriteByte(i2c); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 322 | i++; |
| 323 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 324 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 325 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 326 | if (result == I2C_OK) |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 327 | result = WaitForXfer(i2c); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 328 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 329 | /* send STOP */ |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 330 | writel(I2C_MODE_MR | I2C_TXRX_ENA, &i2c->iicstat); |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 331 | ReadWriteByte(i2c); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 332 | break; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 333 | |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 334 | case I2C_READ: |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 335 | if (addr && addr_len) { |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 336 | writel(I2C_MODE_MT | I2C_TXRX_ENA, &i2c->iicstat); |
| 337 | writel(chip, &i2c->iicds); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 338 | /* send START */ |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 339 | writel(readl(&i2c->iicstat) | I2C_START_STOP, |
| 340 | &i2c->iicstat); |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 341 | result = WaitForXfer(i2c); |
| 342 | if (IsACK(i2c)) { |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 343 | i = 0; |
| 344 | while ((i < addr_len) && (result == I2C_OK)) { |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 345 | writel(addr[i], &i2c->iicds); |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 346 | ReadWriteByte(i2c); |
| 347 | result = WaitForXfer(i2c); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 348 | i++; |
| 349 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 350 | |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 351 | writel(chip, &i2c->iicds); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 352 | /* resend START */ |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 353 | writel(I2C_MODE_MR | I2C_TXRX_ENA | |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 354 | I2C_START_STOP, &i2c->iicstat); |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 355 | ReadWriteByte(i2c); |
| 356 | result = WaitForXfer(i2c); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 357 | i = 0; |
| 358 | while ((i < data_len) && (result == I2C_OK)) { |
| 359 | /* disable ACK for final READ */ |
| 360 | if (i == data_len - 1) |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 361 | writel(readl(&i2c->iiccon) |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 362 | & ~I2CCON_ACKGEN, |
| 363 | &i2c->iiccon); |
| 364 | ReadWriteByte(i2c); |
| 365 | result = WaitForXfer(i2c); |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 366 | data[i] = readl(&i2c->iicds); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 367 | i++; |
| 368 | } |
| 369 | } else { |
| 370 | result = I2C_NACK; |
| 371 | } |
| 372 | |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 373 | } else { |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 374 | writel(I2C_MODE_MR | I2C_TXRX_ENA, &i2c->iicstat); |
| 375 | writel(chip, &i2c->iicds); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 376 | /* send START */ |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 377 | writel(readl(&i2c->iicstat) | I2C_START_STOP, |
| 378 | &i2c->iicstat); |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 379 | result = WaitForXfer(i2c); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 380 | |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 381 | if (IsACK(i2c)) { |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 382 | i = 0; |
| 383 | while ((i < data_len) && (result == I2C_OK)) { |
| 384 | /* disable ACK for final READ */ |
| 385 | if (i == data_len - 1) |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 386 | writel(readl(&i2c->iiccon) & |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 387 | ~I2CCON_ACKGEN, |
| 388 | &i2c->iiccon); |
| 389 | ReadWriteByte(i2c); |
| 390 | result = WaitForXfer(i2c); |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 391 | data[i] = readl(&i2c->iicds); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 392 | i++; |
| 393 | } |
| 394 | } else { |
| 395 | result = I2C_NACK; |
| 396 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 397 | } |
| 398 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 399 | /* send STOP */ |
C Nauman | d9abba8 | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 400 | writel(I2C_MODE_MR | I2C_TXRX_ENA, &i2c->iicstat); |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 401 | ReadWriteByte(i2c); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 402 | break; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 403 | |
| 404 | default: |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 405 | debug("i2c_transfer: bad call\n"); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 406 | result = I2C_NOK; |
| 407 | break; |
| 408 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 409 | |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 410 | return result; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 411 | } |
| 412 | |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 413 | int i2c_probe(uchar chip) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 414 | { |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 415 | struct s3c24x0_i2c *i2c; |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 416 | uchar buf[1]; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 417 | |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 418 | i2c = get_base_i2c(); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 419 | buf[0] = 0; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 420 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 421 | /* |
| 422 | * What is needed is to send the chip address and verify that the |
| 423 | * address was <ACK>ed (i.e. there was a chip at that address which |
| 424 | * drove the data line low). |
| 425 | */ |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 426 | return i2c_transfer(i2c, I2C_READ, chip << 1, 0, 0, buf, 1) != I2C_OK; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 427 | } |
| 428 | |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 429 | int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 430 | { |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 431 | struct s3c24x0_i2c *i2c; |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 432 | uchar xaddr[4]; |
| 433 | int ret; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 434 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 435 | if (alen > 4) { |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 436 | debug("I2C read: addr len %d not supported\n", alen); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 437 | return 1; |
| 438 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 439 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 440 | if (alen > 0) { |
| 441 | xaddr[0] = (addr >> 24) & 0xFF; |
| 442 | xaddr[1] = (addr >> 16) & 0xFF; |
| 443 | xaddr[2] = (addr >> 8) & 0xFF; |
| 444 | xaddr[3] = addr & 0xFF; |
| 445 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 446 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 447 | #ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 448 | /* |
| 449 | * EEPROM chips that implement "address overflow" are ones |
| 450 | * like Catalyst 24WC04/08/16 which has 9/10/11 bits of |
| 451 | * address and the extra bits end up in the "chip address" |
| 452 | * bit slots. This makes a 24WC08 (1Kbyte) chip look like |
| 453 | * four 256 byte chips. |
| 454 | * |
| 455 | * Note that we consider the length of the address field to |
| 456 | * still be one byte because the extra address bits are |
| 457 | * hidden in the chip address. |
| 458 | */ |
| 459 | if (alen > 0) |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 460 | chip |= ((addr >> (alen * 8)) & |
| 461 | CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 462 | #endif |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 463 | i2c = get_base_i2c(); |
| 464 | ret = i2c_transfer(i2c, I2C_READ, chip << 1, &xaddr[4 - alen], alen, |
| 465 | buffer, len); |
| 466 | if (ret != 0) { |
| 467 | debug("I2c read: failed %d\n", ret); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 468 | return 1; |
| 469 | } |
| 470 | return 0; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 471 | } |
| 472 | |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 473 | int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 474 | { |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 475 | struct s3c24x0_i2c *i2c; |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 476 | uchar xaddr[4]; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 477 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 478 | if (alen > 4) { |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 479 | debug("I2C write: addr len %d not supported\n", alen); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 480 | return 1; |
| 481 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 482 | |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 483 | if (alen > 0) { |
| 484 | xaddr[0] = (addr >> 24) & 0xFF; |
| 485 | xaddr[1] = (addr >> 16) & 0xFF; |
| 486 | xaddr[2] = (addr >> 8) & 0xFF; |
| 487 | xaddr[3] = addr & 0xFF; |
| 488 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 489 | #ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 490 | /* |
| 491 | * EEPROM chips that implement "address overflow" are ones |
| 492 | * like Catalyst 24WC04/08/16 which has 9/10/11 bits of |
| 493 | * address and the extra bits end up in the "chip address" |
| 494 | * bit slots. This makes a 24WC08 (1Kbyte) chip look like |
| 495 | * four 256 byte chips. |
| 496 | * |
| 497 | * Note that we consider the length of the address field to |
| 498 | * still be one byte because the extra address bits are |
| 499 | * hidden in the chip address. |
| 500 | */ |
| 501 | if (alen > 0) |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 502 | chip |= ((addr >> (alen * 8)) & |
| 503 | CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 504 | #endif |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 505 | i2c = get_base_i2c(); |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 506 | return (i2c_transfer |
Rajeshwari Shinde | ab7e52b | 2012-07-23 21:23:53 +0000 | [diff] [blame] | 507 | (i2c, I2C_WRITE, chip << 1, &xaddr[4 - alen], alen, buffer, |
wdenk | fc3e216 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 508 | len) != 0); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 509 | } |
kevin.morfitt@fearnside-systems.co.uk | eb0ae7f | 2009-10-10 13:33:11 +0900 | [diff] [blame] | 510 | #endif /* CONFIG_HARD_I2C */ |