diff options
author | Marian Balakowicz <m8@semihalf.com> | 2008-02-21 17:18:01 +0100 |
---|---|---|
committer | Marian Balakowicz <m8@semihalf.com> | 2008-02-21 17:18:01 +0100 |
commit | 20c93959330aba8b5bbdbfde1ef319e99eba235d (patch) | |
tree | ef82297e3aeb904f94584e6d136fac55ec32c317 /board/m501sk/eeprom.c | |
parent | 5cf746c303710329f8040d9c62ee354313e3e91f (diff) | |
parent | 928d1d77f8623c120d8763e20e1ca58df9c5c4c6 (diff) | |
download | u-boot-imx-20c93959330aba8b5bbdbfde1ef319e99eba235d.zip u-boot-imx-20c93959330aba8b5bbdbfde1ef319e99eba235d.tar.gz u-boot-imx-20c93959330aba8b5bbdbfde1ef319e99eba235d.tar.bz2 |
Merge branch 'master' of /home/git/u-boot
Diffstat (limited to 'board/m501sk/eeprom.c')
-rw-r--r-- | board/m501sk/eeprom.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/board/m501sk/eeprom.c b/board/m501sk/eeprom.c new file mode 100644 index 0000000..d86392f --- /dev/null +++ b/board/m501sk/eeprom.c @@ -0,0 +1,102 @@ +/* + * Add by Alan Lu, 07-29-2005 + * For ATMEL AT24C16 EEPROM + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <common.h> +#include <i2c.h> +#ifdef CFG_EEPROM_AT24C16 +#undef DEBUG + +void eeprom_init(void) +{ +#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) + i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE); +#endif +} + +int eeprom_read(unsigned dev_addr, unsigned offset, uchar *buffer, + unsigned cnt) +{ + int page, count = 0, i = 0; + page = offset / 0x100; + i = offset % 0x100; + + while (count < cnt) { + if (i2c_read(dev_addr|page, i++, 1, buffer+count++, 1) != 0) + return 1; + if (i > 0xff) { + page++; + i = 0; + } + } + + return 0; +} + +/* + * for CFG_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is + * 0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM. + * + * for CFG_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is + * 0x00000nxx for EEPROM address selectors and page number at n. + */ +int eeprom_write(unsigned dev_addr, unsigned offset, uchar *buffer, + unsigned cnt) +{ + int page, i = 0, count = 0; + + page = offset / 0x100; + i = offset % 0x100; + + while (count < cnt) { + if (i2c_write(dev_addr|page, i++, 1, buffer+count++, 1) != 0) + return 1; + if (i > 0xff) { + page++; + i = 0; + } + } + +#if defined(CFG_EEPROM_PAGE_WRITE_DELAY_MS) + udelay(CFG_EEPROM_PAGE_WRITE_DELAY_MS * 1000); +#endif + + return 0; +} + +#ifndef CONFIG_SPI +int eeprom_probe(unsigned dev_addr, unsigned offset) +{ + unsigned char chip; + + /* Probe the chip address */ +#if CFG_I2C_EEPROM_ADDR_LEN == 1 && !defined(CONFIG_SPI_X) + chip = offset >> 8; /* block number */ +#else + chip = offset >> 16; /* block number */ +#endif /* CFG_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */ + + chip |= dev_addr; /* insert device address */ + return (i2c_probe(chip)); +} +#endif +#endif |