microchip_flexcom.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 <misc.h>
  10. #include <asm/io.h>
  11. struct microchip_flexcom_regs {
  12. u32 cr;
  13. };
  14. struct microchip_flexcom_platdata {
  15. struct microchip_flexcom_regs *regs;
  16. u32 flexcom_mode;
  17. };
  18. static int microchip_flexcom_ofdata_to_platdata(struct udevice *dev)
  19. {
  20. struct microchip_flexcom_platdata *plat = dev_get_platdata(dev);
  21. int ret;
  22. plat->regs = map_physmem(devfdt_get_addr(dev),
  23. sizeof(struct microchip_flexcom_regs),
  24. MAP_NOCACHE);
  25. ret = dev_read_u32(dev, "atmel,flexcom-mode", &plat->flexcom_mode);
  26. if (IS_ERR_VALUE(ret)) {
  27. debug("Missing atmel,flexcom-mode property\n");
  28. return ret;
  29. }
  30. /*
  31. * The mode must have only 2 bits. If any other bits are set,
  32. * the value is not supported.
  33. */
  34. if (plat->flexcom_mode & 0xfffffffc) {
  35. debug("Wrong atmel,flexcom-mode property\n");
  36. return -EINVAL;
  37. }
  38. writel(plat->flexcom_mode, &plat->regs->cr);
  39. return 0;
  40. }
  41. static const struct udevice_id microchip_flexcom_ids[] = {
  42. { .compatible = "atmel,sama5d2-flexcom" },
  43. { .compatible = "microchip,flexcom" },
  44. {}
  45. };
  46. U_BOOT_DRIVER(microchip_flexcom) = {
  47. .name = "microchip_flexcom",
  48. .id = UCLASS_MISC,
  49. .of_match = microchip_flexcom_ids,
  50. .ofdata_to_platdata = microchip_flexcom_ofdata_to_platdata,
  51. .platdata_auto_alloc_size = sizeof(struct microchip_flexcom_platdata),
  52. };