i2c_eeprom.c 1.8 KB

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