i2c_eeprom.c 2.4 KB

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