i2c_eeprom.c 2.4 KB

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