microchip_flexcom.c 1.5 KB

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