183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
220142019SSimon Glass /*
320142019SSimon Glass * Copyright (c) 2014 Google, Inc
420142019SSimon Glass */
520142019SSimon Glass
620142019SSimon Glass #include <common.h>
7ee5ee876SMasahiro Yamada #include <linux/err.h>
820142019SSimon Glass #include <dm.h>
920142019SSimon Glass #include <i2c.h>
1020142019SSimon Glass #include <i2c_eeprom.h>
1120142019SSimon Glass
i2c_eeprom_read(struct udevice * dev,int offset,uint8_t * buf,int size)128880efbdSJonas Karlman int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, int size)
138880efbdSJonas Karlman {
148880efbdSJonas Karlman const struct i2c_eeprom_ops *ops = device_get_ops(dev);
158880efbdSJonas Karlman
168880efbdSJonas Karlman if (!ops->read)
178880efbdSJonas Karlman return -ENOSYS;
188880efbdSJonas Karlman
198880efbdSJonas Karlman return ops->read(dev, offset, buf, size);
208880efbdSJonas Karlman }
218880efbdSJonas Karlman
i2c_eeprom_write(struct udevice * dev,int offset,uint8_t * buf,int size)228880efbdSJonas Karlman int i2c_eeprom_write(struct udevice *dev, int offset, uint8_t *buf, int size)
238880efbdSJonas Karlman {
248880efbdSJonas Karlman const struct i2c_eeprom_ops *ops = device_get_ops(dev);
258880efbdSJonas Karlman
268880efbdSJonas Karlman if (!ops->write)
278880efbdSJonas Karlman return -ENOSYS;
288880efbdSJonas Karlman
298880efbdSJonas Karlman return ops->write(dev, offset, buf, size);
308880efbdSJonas Karlman }
318880efbdSJonas Karlman
i2c_eeprom_std_read(struct udevice * dev,int offset,uint8_t * buf,int size)328880efbdSJonas Karlman static int i2c_eeprom_std_read(struct udevice *dev, int offset, uint8_t *buf,
3320142019SSimon Glass int size)
3420142019SSimon Glass {
35d7e28918Smario.six@gdsys.cc return dm_i2c_read(dev, offset, buf, size);
3620142019SSimon Glass }
3720142019SSimon Glass
i2c_eeprom_std_write(struct udevice * dev,int offset,const uint8_t * buf,int size)388880efbdSJonas Karlman static int i2c_eeprom_std_write(struct udevice *dev, int offset,
3920142019SSimon Glass const uint8_t *buf, int size)
4020142019SSimon Glass {
4120142019SSimon Glass return -ENODEV;
4220142019SSimon Glass }
4320142019SSimon Glass
445e75ea15SMasahiro Yamada static const struct i2c_eeprom_ops i2c_eeprom_std_ops = {
458880efbdSJonas Karlman .read = i2c_eeprom_std_read,
468880efbdSJonas Karlman .write = i2c_eeprom_std_write,
4720142019SSimon Glass };
4820142019SSimon Glass
i2c_eeprom_std_ofdata_to_platdata(struct udevice * dev)49d7e28918Smario.six@gdsys.cc static int i2c_eeprom_std_ofdata_to_platdata(struct udevice *dev)
50d7e28918Smario.six@gdsys.cc {
51d7e28918Smario.six@gdsys.cc struct i2c_eeprom *priv = dev_get_priv(dev);
52d7e28918Smario.six@gdsys.cc u64 data = dev_get_driver_data(dev);
53d7e28918Smario.six@gdsys.cc
54d7e28918Smario.six@gdsys.cc /* 6 bit -> page size of up to 2^63 (should be sufficient) */
55d7e28918Smario.six@gdsys.cc priv->pagewidth = data & 0x3F;
56d7e28918Smario.six@gdsys.cc priv->pagesize = (1 << priv->pagewidth);
57d7e28918Smario.six@gdsys.cc
58d7e28918Smario.six@gdsys.cc return 0;
59d7e28918Smario.six@gdsys.cc }
60d7e28918Smario.six@gdsys.cc
i2c_eeprom_std_probe(struct udevice * dev)615e75ea15SMasahiro Yamada static int i2c_eeprom_std_probe(struct udevice *dev)
6220142019SSimon Glass {
6320142019SSimon Glass return 0;
6420142019SSimon Glass }
6520142019SSimon Glass
6620142019SSimon Glass static const struct udevice_id i2c_eeprom_std_ids[] = {
67d7e28918Smario.six@gdsys.cc { .compatible = "i2c-eeprom", .data = 0 },
6872640667SWenyou Yang { .compatible = "microchip,24aa02e48", .data = 3 },
69d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c01a", .data = 3 },
70d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c02", .data = 3 },
71d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c04", .data = 4 },
72*e38cef9fSMichal Simek { .compatible = "atmel,24c08", .data = 4 },
73d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c08a", .data = 4 },
74d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c16a", .data = 4 },
75de656752SWenyou Yang { .compatible = "atmel,24mac402", .data = 4 },
76d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c32", .data = 5 },
77d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c64", .data = 5 },
78d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c128", .data = 6 },
79d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c256", .data = 6 },
80d7e28918Smario.six@gdsys.cc { .compatible = "atmel,24c512", .data = 6 },
8120142019SSimon Glass { }
8220142019SSimon Glass };
8320142019SSimon Glass
8420142019SSimon Glass U_BOOT_DRIVER(i2c_eeprom_std) = {
8520142019SSimon Glass .name = "i2c_eeprom",
8620142019SSimon Glass .id = UCLASS_I2C_EEPROM,
8720142019SSimon Glass .of_match = i2c_eeprom_std_ids,
8820142019SSimon Glass .probe = i2c_eeprom_std_probe,
89d7e28918Smario.six@gdsys.cc .ofdata_to_platdata = i2c_eeprom_std_ofdata_to_platdata,
9020142019SSimon Glass .priv_auto_alloc_size = sizeof(struct i2c_eeprom),
9120142019SSimon Glass .ops = &i2c_eeprom_std_ops,
9220142019SSimon Glass };
9320142019SSimon Glass
9420142019SSimon Glass UCLASS_DRIVER(i2c_eeprom) = {
9520142019SSimon Glass .id = UCLASS_I2C_EEPROM,
9620142019SSimon Glass .name = "i2c_eeprom",
9720142019SSimon Glass };
98