1 /* 2 * Copyright (c) 2014 Google, Inc 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <linux/err.h> 9 #include <dm.h> 10 #include <i2c.h> 11 #include <i2c_eeprom.h> 12 13 static int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, 14 int size) 15 { 16 return dm_i2c_read(dev, offset, buf, size); 17 } 18 19 static int i2c_eeprom_write(struct udevice *dev, int offset, 20 const uint8_t *buf, int size) 21 { 22 return -ENODEV; 23 } 24 25 struct i2c_eeprom_ops i2c_eeprom_std_ops = { 26 .read = i2c_eeprom_read, 27 .write = i2c_eeprom_write, 28 }; 29 30 static int i2c_eeprom_std_ofdata_to_platdata(struct udevice *dev) 31 { 32 struct i2c_eeprom *priv = dev_get_priv(dev); 33 u64 data = dev_get_driver_data(dev); 34 35 /* 6 bit -> page size of up to 2^63 (should be sufficient) */ 36 priv->pagewidth = data & 0x3F; 37 priv->pagesize = (1 << priv->pagewidth); 38 39 return 0; 40 } 41 42 int i2c_eeprom_std_probe(struct udevice *dev) 43 { 44 return 0; 45 } 46 47 static const struct udevice_id i2c_eeprom_std_ids[] = { 48 { .compatible = "i2c-eeprom", .data = 0 }, 49 { .compatible = "atmel,24c01a", .data = 3 }, 50 { .compatible = "atmel,24c02", .data = 3 }, 51 { .compatible = "atmel,24c04", .data = 4 }, 52 { .compatible = "atmel,24c08a", .data = 4 }, 53 { .compatible = "atmel,24c16a", .data = 4 }, 54 { .compatible = "atmel,24c32", .data = 5 }, 55 { .compatible = "atmel,24c64", .data = 5 }, 56 { .compatible = "atmel,24c128", .data = 6 }, 57 { .compatible = "atmel,24c256", .data = 6 }, 58 { .compatible = "atmel,24c512", .data = 6 }, 59 { } 60 }; 61 62 U_BOOT_DRIVER(i2c_eeprom_std) = { 63 .name = "i2c_eeprom", 64 .id = UCLASS_I2C_EEPROM, 65 .of_match = i2c_eeprom_std_ids, 66 .probe = i2c_eeprom_std_probe, 67 .ofdata_to_platdata = i2c_eeprom_std_ofdata_to_platdata, 68 .priv_auto_alloc_size = sizeof(struct i2c_eeprom), 69 .ops = &i2c_eeprom_std_ops, 70 }; 71 72 UCLASS_DRIVER(i2c_eeprom) = { 73 .id = UCLASS_I2C_EEPROM, 74 .name = "i2c_eeprom", 75 }; 76