ds24xxx.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. *
  4. * Copyright (c) 2015 Free Electrons
  5. * Copyright (c) 2015 NextThing Co
  6. * Copyright (c) 2018 Microchip Technology, Inc.
  7. *
  8. */
  9. #include <common.h>
  10. #include <linux/err.h>
  11. #include <dm.h>
  12. #include <w1-eeprom.h>
  13. #include <w1.h>
  14. #define W1_F2D_READ_EEPROM 0xf0
  15. static int ds24xxx_read_buf(struct udevice *dev, unsigned int offset,
  16. u8 *buf, unsigned int count)
  17. {
  18. w1_reset_select(dev);
  19. w1_write_byte(dev, W1_F2D_READ_EEPROM);
  20. w1_write_byte(dev, offset & 0xff);
  21. w1_write_byte(dev, offset >> 8);
  22. return w1_read_buf(dev, buf, count);
  23. }
  24. static int ds24xxx_probe(struct udevice *dev)
  25. {
  26. struct w1_device *w1;
  27. w1 = dev_get_parent_plat(dev);
  28. w1->id = 0;
  29. return 0;
  30. }
  31. static const struct w1_eeprom_ops ds24xxx_ops = {
  32. .read_buf = ds24xxx_read_buf,
  33. };
  34. static const struct udevice_id ds24xxx_id[] = {
  35. { .compatible = "maxim,ds24b33", .data = W1_FAMILY_DS24B33 },
  36. { .compatible = "maxim,ds2431", .data = W1_FAMILY_DS2431 },
  37. { },
  38. };
  39. U_BOOT_DRIVER(ds24xxx) = {
  40. .name = "ds24xxx",
  41. .id = UCLASS_W1_EEPROM,
  42. .of_match = ds24xxx_id,
  43. .ops = &ds24xxx_ops,
  44. .probe = ds24xxx_probe,
  45. };
  46. u8 family_supported[] = {
  47. W1_FAMILY_DS24B33,
  48. W1_FAMILY_DS2431,
  49. };
  50. U_BOOT_W1_DEVICE(ds24xxx, family_supported);