1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2014 Google, Inc
8 #include <linux/kernel.h>
11 #include <i2c_eeprom.h>
13 int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, int size)
15 const struct i2c_eeprom_ops *ops = device_get_ops(dev);
20 return ops->read(dev, offset, buf, size);
23 int i2c_eeprom_write(struct udevice *dev, int offset, uint8_t *buf, int size)
25 const struct i2c_eeprom_ops *ops = device_get_ops(dev);
30 return ops->write(dev, offset, buf, size);
33 static int i2c_eeprom_std_read(struct udevice *dev, int offset, uint8_t *buf,
36 return dm_i2c_read(dev, offset, buf, size);
39 static int i2c_eeprom_std_write(struct udevice *dev, int offset,
40 const uint8_t *buf, int size)
42 struct i2c_eeprom *priv = dev_get_priv(dev);
46 int write_size = min_t(int, size, priv->pagesize);
48 ret = dm_i2c_write(dev, offset, buf, write_size);
62 static const struct i2c_eeprom_ops i2c_eeprom_std_ops = {
63 .read = i2c_eeprom_std_read,
64 .write = i2c_eeprom_std_write,
67 static int i2c_eeprom_std_ofdata_to_platdata(struct udevice *dev)
69 struct i2c_eeprom *priv = dev_get_priv(dev);
70 u64 data = dev_get_driver_data(dev);
73 if (dev_read_u32(dev, "pagesize", &pagesize) == 0) {
74 priv->pagesize = pagesize;
78 /* 6 bit -> page size of up to 2^63 (should be sufficient) */
79 priv->pagewidth = data & 0x3F;
80 priv->pagesize = (1 << priv->pagewidth);
85 static int i2c_eeprom_std_probe(struct udevice *dev)
90 static const struct udevice_id i2c_eeprom_std_ids[] = {
91 { .compatible = "i2c-eeprom", .data = 0 },
92 { .compatible = "microchip,24aa02e48", .data = 3 },
93 { .compatible = "atmel,24c01a", .data = 3 },
94 { .compatible = "atmel,24c02", .data = 3 },
95 { .compatible = "atmel,24c04", .data = 4 },
96 { .compatible = "atmel,24c08", .data = 4 },
97 { .compatible = "atmel,24c08a", .data = 4 },
98 { .compatible = "atmel,24c16a", .data = 4 },
99 { .compatible = "atmel,24mac402", .data = 4 },
100 { .compatible = "atmel,24c32", .data = 5 },
101 { .compatible = "atmel,24c64", .data = 5 },
102 { .compatible = "atmel,24c128", .data = 6 },
103 { .compatible = "atmel,24c256", .data = 6 },
104 { .compatible = "atmel,24c512", .data = 6 },
108 U_BOOT_DRIVER(i2c_eeprom_std) = {
109 .name = "i2c_eeprom",
110 .id = UCLASS_I2C_EEPROM,
111 .of_match = i2c_eeprom_std_ids,
112 .probe = i2c_eeprom_std_probe,
113 .ofdata_to_platdata = i2c_eeprom_std_ofdata_to_platdata,
114 .priv_auto_alloc_size = sizeof(struct i2c_eeprom),
115 .ops = &i2c_eeprom_std_ops,
118 UCLASS_DRIVER(i2c_eeprom) = {
119 .id = UCLASS_I2C_EEPROM,
120 .name = "i2c_eeprom",