microchip_flexcom.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2019, Microchip Technology, Inc.
  4. * Author: Eugen Hristev <eugen.hristev@microchip.com>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <log.h>
  10. #include <misc.h>
  11. #include <asm/io.h>
  12. #include <linux/err.h>
  13. struct microchip_flexcom_regs {
  14. u32 cr;
  15. };
  16. struct microchip_flexcom_plat {
  17. struct microchip_flexcom_regs *regs;
  18. u32 flexcom_mode;
  19. };
  20. static int microchip_flexcom_of_to_plat(struct udevice *dev)
  21. {
  22. struct microchip_flexcom_plat *plat = dev_get_plat(dev);
  23. int ret;
  24. plat->regs = map_physmem(dev_read_addr(dev),
  25. sizeof(struct microchip_flexcom_regs),
  26. MAP_NOCACHE);
  27. ret = dev_read_u32(dev, "atmel,flexcom-mode", &plat->flexcom_mode);
  28. if (IS_ERR_VALUE(ret)) {
  29. debug("Missing atmel,flexcom-mode property\n");
  30. return ret;
  31. }
  32. /*
  33. * The mode must have only 2 bits. If any other bits are set,
  34. * the value is not supported.
  35. */
  36. if (plat->flexcom_mode & 0xfffffffc) {
  37. debug("Wrong atmel,flexcom-mode property\n");
  38. return -EINVAL;
  39. }
  40. writel(plat->flexcom_mode, &plat->regs->cr);
  41. return 0;
  42. }
  43. static const struct udevice_id microchip_flexcom_ids[] = {
  44. { .compatible = "atmel,sama5d2-flexcom" },
  45. { .compatible = "microchip,flexcom" },
  46. {}
  47. };
  48. U_BOOT_DRIVER(microchip_flexcom) = {
  49. .name = "microchip_flexcom",
  50. .id = UCLASS_MISC,
  51. .of_match = microchip_flexcom_ids,
  52. .of_to_plat = microchip_flexcom_of_to_plat,
  53. .plat_auto = sizeof(struct microchip_flexcom_plat),
  54. };