1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2014 Google, Inc
10 #include <i2c_eeprom.h>
12 int i2c_eeprom_read(struct udevice
*dev
, int offset
, uint8_t *buf
, int size
)
14 const struct i2c_eeprom_ops
*ops
= device_get_ops(dev
);
19 return ops
->read(dev
, offset
, buf
, size
);
22 int i2c_eeprom_write(struct udevice
*dev
, int offset
, uint8_t *buf
, int size
)
24 const struct i2c_eeprom_ops
*ops
= device_get_ops(dev
);
29 return ops
->write(dev
, offset
, buf
, size
);
32 static int i2c_eeprom_std_read(struct udevice
*dev
, int offset
, uint8_t *buf
,
35 return dm_i2c_read(dev
, offset
, buf
, size
);
38 static int i2c_eeprom_std_write(struct udevice
*dev
, int offset
,
39 const uint8_t *buf
, int size
)
44 static const struct i2c_eeprom_ops i2c_eeprom_std_ops
= {
45 .read
= i2c_eeprom_std_read
,
46 .write
= i2c_eeprom_std_write
,
49 static int i2c_eeprom_std_ofdata_to_platdata(struct udevice
*dev
)
51 struct i2c_eeprom
*priv
= dev_get_priv(dev
);
52 u64 data
= dev_get_driver_data(dev
);
54 /* 6 bit -> page size of up to 2^63 (should be sufficient) */
55 priv
->pagewidth
= data
& 0x3F;
56 priv
->pagesize
= (1 << priv
->pagewidth
);
61 static int i2c_eeprom_std_probe(struct udevice
*dev
)
66 static const struct udevice_id i2c_eeprom_std_ids
[] = {
67 { .compatible
= "i2c-eeprom", .data
= 0 },
68 { .compatible
= "microchip,24aa02e48", .data
= 3 },
69 { .compatible
= "atmel,24c01a", .data
= 3 },
70 { .compatible
= "atmel,24c02", .data
= 3 },
71 { .compatible
= "atmel,24c04", .data
= 4 },
72 { .compatible
= "atmel,24c08a", .data
= 4 },
73 { .compatible
= "atmel,24c16a", .data
= 4 },
74 { .compatible
= "atmel,24mac402", .data
= 4 },
75 { .compatible
= "atmel,24c32", .data
= 5 },
76 { .compatible
= "atmel,24c64", .data
= 5 },
77 { .compatible
= "atmel,24c128", .data
= 6 },
78 { .compatible
= "atmel,24c256", .data
= 6 },
79 { .compatible
= "atmel,24c512", .data
= 6 },
83 U_BOOT_DRIVER(i2c_eeprom_std
) = {
85 .id
= UCLASS_I2C_EEPROM
,
86 .of_match
= i2c_eeprom_std_ids
,
87 .probe
= i2c_eeprom_std_probe
,
88 .ofdata_to_platdata
= i2c_eeprom_std_ofdata_to_platdata
,
89 .priv_auto_alloc_size
= sizeof(struct i2c_eeprom
),
90 .ops
= &i2c_eeprom_std_ops
,
93 UCLASS_DRIVER(i2c_eeprom
) = {
94 .id
= UCLASS_I2C_EEPROM
,