120142019SSimon Glass /* 220142019SSimon Glass * Copyright (c) 2014 Google, Inc 320142019SSimon Glass * 420142019SSimon Glass * SPDX-License-Identifier: GPL-2.0+ 520142019SSimon Glass */ 620142019SSimon Glass 720142019SSimon Glass #include <common.h> 8ee5ee876SMasahiro Yamada #include <linux/err.h> 920142019SSimon Glass #include <dm.h> 1020142019SSimon Glass #include <i2c.h> 1120142019SSimon Glass #include <i2c_eeprom.h> 1220142019SSimon Glass 1320142019SSimon Glass static int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, 1420142019SSimon Glass int size) 1520142019SSimon Glass { 16*d7e28918Smario.six@gdsys.cc return dm_i2c_read(dev, offset, buf, size); 1720142019SSimon Glass } 1820142019SSimon Glass 1920142019SSimon Glass static int i2c_eeprom_write(struct udevice *dev, int offset, 2020142019SSimon Glass const uint8_t *buf, int size) 2120142019SSimon Glass { 2220142019SSimon Glass return -ENODEV; 2320142019SSimon Glass } 2420142019SSimon Glass 2520142019SSimon Glass struct i2c_eeprom_ops i2c_eeprom_std_ops = { 2620142019SSimon Glass .read = i2c_eeprom_read, 2720142019SSimon Glass .write = i2c_eeprom_write, 2820142019SSimon Glass }; 2920142019SSimon Glass 30*d7e28918Smario.six@gdsys.cc static int i2c_eeprom_std_ofdata_to_platdata(struct udevice *dev) 31*d7e28918Smario.six@gdsys.cc { 32*d7e28918Smario.six@gdsys.cc struct i2c_eeprom *priv = dev_get_priv(dev); 33*d7e28918Smario.six@gdsys.cc u64 data = dev_get_driver_data(dev); 34*d7e28918Smario.six@gdsys.cc 35*d7e28918Smario.six@gdsys.cc /* 6 bit -> page size of up to 2^63 (should be sufficient) */ 36*d7e28918Smario.six@gdsys.cc priv->pagewidth = data & 0x3F; 37*d7e28918Smario.six@gdsys.cc priv->pagesize = (1 << priv->pagewidth); 38*d7e28918Smario.six@gdsys.cc 39*d7e28918Smario.six@gdsys.cc return 0; 40*d7e28918Smario.six@gdsys.cc } 41*d7e28918Smario.six@gdsys.cc 4220142019SSimon Glass int i2c_eeprom_std_probe(struct udevice *dev) 4320142019SSimon Glass { 4420142019SSimon Glass return 0; 4520142019SSimon Glass } 4620142019SSimon Glass 4720142019SSimon Glass static const struct udevice_id i2c_eeprom_std_ids[] = { 48*d7e28918Smario.six@gdsys.cc { .compatible = "i2c-eeprom", .data = 0 }, 49*d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c01a", .data = 3 }, 50*d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c02", .data = 3 }, 51*d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c04", .data = 4 }, 52*d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c08a", .data = 4 }, 53*d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c16a", .data = 4 }, 54*d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c32", .data = 5 }, 55*d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c64", .data = 5 }, 56*d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c128", .data = 6 }, 57*d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c256", .data = 6 }, 58*d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c512", .data = 6 }, 5920142019SSimon Glass { } 6020142019SSimon Glass }; 6120142019SSimon Glass 6220142019SSimon Glass U_BOOT_DRIVER(i2c_eeprom_std) = { 6320142019SSimon Glass .name = "i2c_eeprom", 6420142019SSimon Glass .id = UCLASS_I2C_EEPROM, 6520142019SSimon Glass .of_match = i2c_eeprom_std_ids, 6620142019SSimon Glass .probe = i2c_eeprom_std_probe, 67*d7e28918Smario.six@gdsys.cc .ofdata_to_platdata = i2c_eeprom_std_ofdata_to_platdata, 6820142019SSimon Glass .priv_auto_alloc_size = sizeof(struct i2c_eeprom), 6920142019SSimon Glass .ops = &i2c_eeprom_std_ops, 7020142019SSimon Glass }; 7120142019SSimon Glass 7220142019SSimon Glass UCLASS_DRIVER(i2c_eeprom) = { 7320142019SSimon Glass .id = UCLASS_I2C_EEPROM, 7420142019SSimon Glass .name = "i2c_eeprom", 7520142019SSimon Glass }; 76