soc_pinmux.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2019 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file pinmux interface for Actions SoC
  8. */
  9. #include <errno.h>
  10. #include <kernel.h>
  11. #include "soc.h"
  12. int acts_pinmux_set(unsigned int pin, unsigned int mode)
  13. {
  14. unsigned int key, ctl_reg, val;
  15. if (pin >= GPIO_MAX_PIN_NUM)
  16. return -EINVAL;
  17. ctl_reg = GPIO_REG_CTL(GPIO_REG_BASE, pin);
  18. key = irq_lock();
  19. val = (sys_read32(ctl_reg) & ~PINMUX_MODE_MASK) | mode;
  20. sys_write32(val, ctl_reg);
  21. irq_unlock(key);
  22. return 0;
  23. }
  24. int acts_pinmux_get(unsigned int pin, unsigned int *mode)
  25. {
  26. unsigned int ctl_reg = GPIO_REG_CTL(GPIO_REG_BASE, pin);
  27. *mode = sys_read32(ctl_reg) & PINMUX_MODE_MASK;
  28. return 0;
  29. }
  30. void acts_pinmux_setup_pins(const struct acts_pin_config *pinconf, int pins)
  31. {
  32. int i;
  33. for (i = 0; i < pins; i++) {
  34. acts_pinmux_set(pinconf[i].pin_num, pinconf[i].mode);
  35. //printk("pin=%d, ctl_reg=0x%x\n", pinconf[i].pin_num,
  36. // pinconf[i].mode);
  37. }
  38. }
  39. static int acts_pinctl_reg_set(unsigned int pin, unsigned int val)
  40. {
  41. unsigned int key, ctl_reg;
  42. if (pin >= GPIO_MAX_PIN_NUM)
  43. return -EINVAL;
  44. ctl_reg = GPIO_REG_CTL(GPIO_REG_BASE, pin);
  45. key = irq_lock();
  46. sys_write32(val, ctl_reg);
  47. irq_unlock(key);
  48. return 0;
  49. }
  50. void acts_pinctl_reg_setup_pins(const struct acts_pin_config *pinconf, int pins)
  51. {
  52. int i;
  53. for (i = 0; i < pins; i++) {
  54. acts_pinctl_reg_set(pinconf[i].pin_num, pinconf[i].mode);
  55. }
  56. }