pinctrl-nexell.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Pinctrl driver for Nexell SoCs
  4. * (C) Copyright 2016 Nexell
  5. * Bongyu, KOO <freestyle@nexell.co.kr>
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <errno.h>
  10. #include <asm/io.h>
  11. #include "pinctrl-nexell.h"
  12. #include "pinctrl-s5pxx18.h"
  13. DECLARE_GLOBAL_DATA_PTR;
  14. /* given a pin-name, return the address of pin config registers */
  15. unsigned long pin_to_bank_base(struct udevice *dev, const char *pin_name,
  16. u32 *pin)
  17. {
  18. struct nexell_pinctrl_priv *priv = dev_get_priv(dev);
  19. const struct nexell_pin_ctrl *pin_ctrl = priv->pin_ctrl;
  20. const struct nexell_pin_bank_data *bank_data = pin_ctrl->pin_banks;
  21. u32 nr_banks = pin_ctrl->nr_banks, idx = 0;
  22. char bank[10];
  23. /*
  24. * The format of the pin name is <bank name>-<pin_number>.
  25. * Example: gpioa-4 (gpioa is the bank name and 4 is the pin number)
  26. */
  27. while (pin_name[idx] != '-') {
  28. bank[idx] = pin_name[idx];
  29. idx++;
  30. }
  31. bank[idx] = '\0';
  32. *pin = (u32)simple_strtoul(&pin_name[++idx], NULL, 10);
  33. /* lookup the pin bank data using the pin bank name */
  34. for (idx = 0; idx < nr_banks; idx++)
  35. if (!strcmp(bank, bank_data[idx].name))
  36. break;
  37. return priv->base + bank_data[idx].offset;
  38. }
  39. int nexell_pinctrl_probe(struct udevice *dev)
  40. {
  41. struct nexell_pinctrl_priv *priv;
  42. fdt_addr_t base;
  43. priv = dev_get_priv(dev);
  44. if (!priv)
  45. return -EINVAL;
  46. base = devfdt_get_addr(dev);
  47. if (base == FDT_ADDR_T_NONE)
  48. return -EINVAL;
  49. priv->base = base;
  50. priv->pin_ctrl = (struct nexell_pin_ctrl *)dev_get_driver_data(dev);
  51. s5pxx18_pinctrl_init(dev);
  52. return 0;
  53. }