pinmux_arria10.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2016-2017 Intel Corporation <www.intel.com>
  4. */
  5. #include <asm/arch/pinmux.h>
  6. #include <asm/io.h>
  7. #include <common.h>
  8. #include <fdtdec.h>
  9. static int do_pinctr_pin(const void *blob, int child, const char *node_name)
  10. {
  11. int len;
  12. fdt_addr_t base_addr;
  13. fdt_size_t size;
  14. const u32 *cell;
  15. u32 offset, value;
  16. base_addr = fdtdec_get_addr_size(blob, child, "reg", &size);
  17. if (base_addr != FDT_ADDR_T_NONE) {
  18. cell = fdt_getprop(blob, child, "pinctrl-single,pins", &len);
  19. if (!cell || len <= 0)
  20. return -EFAULT;
  21. debug("%p %d\n", cell, len);
  22. for (; len > 0; len -= (2 * sizeof(u32))) {
  23. offset = fdt32_to_cpu(*cell++);
  24. value = fdt32_to_cpu(*cell++);
  25. debug("<0x%x 0x%x>\n", offset, value);
  26. writel(value, base_addr + offset);
  27. }
  28. return 0;
  29. }
  30. return -EFAULT;
  31. }
  32. static int do_pinctrl_pins(const void *blob, int node, const char *child_name)
  33. {
  34. int child, len;
  35. const char *node_name;
  36. child = fdt_first_subnode(blob, node);
  37. if (child < 0)
  38. return -EINVAL;
  39. node_name = fdt_get_name(blob, child, &len);
  40. while (node_name) {
  41. if (!strcmp(child_name, node_name))
  42. return do_pinctr_pin(blob, child, node_name);
  43. child = fdt_next_subnode(blob, child);
  44. if (child < 0)
  45. break;
  46. node_name = fdt_get_name(blob, child, &len);
  47. }
  48. return -EFAULT;
  49. }
  50. int config_dedicated_pins(const void *blob)
  51. {
  52. int node;
  53. node = fdtdec_next_compatible(blob, 0,
  54. COMPAT_ALTERA_SOCFPGA_PINCTRL_SINGLE);
  55. if (node < 0)
  56. return -EINVAL;
  57. if (do_pinctrl_pins(blob, node, "dedicated_cfg"))
  58. return -EFAULT;
  59. if (do_pinctrl_pins(blob, node, "dedicated"))
  60. return -EFAULT;
  61. return 0;
  62. }
  63. int config_pins(const void *blob, const char *pin_grp)
  64. {
  65. int node;
  66. node = fdtdec_next_compatible(blob, 0,
  67. COMPAT_ALTERA_SOCFPGA_PINCTRL_SINGLE);
  68. if (node < 0)
  69. return -EINVAL;
  70. if (do_pinctrl_pins(blob, node, pin_grp))
  71. return -EFAULT;
  72. return 0;
  73. }