portmux-pio.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (C) 2006, 2008 Atmel Corporation
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #ifndef __AVR32_PORTMUX_PIO_H__
  7. #define __AVR32_PORTMUX_PIO_H__
  8. #include <asm/io.h>
  9. /* PIO register offsets */
  10. #define PIO_PER 0x0000
  11. #define PIO_PDR 0x0004
  12. #define PIO_PSR 0x0008
  13. #define PIO_OER 0x0010
  14. #define PIO_ODR 0x0014
  15. #define PIO_OSR 0x0018
  16. #define PIO_IFER 0x0020
  17. #define PIO_IFDR 0x0024
  18. #define PIO_ISFR 0x0028
  19. #define PIO_SODR 0x0030
  20. #define PIO_CODR 0x0034
  21. #define PIO_ODSR 0x0038
  22. #define PIO_PDSR 0x003c
  23. #define PIO_IER 0x0040
  24. #define PIO_IDR 0x0044
  25. #define PIO_IMR 0x0048
  26. #define PIO_ISR 0x004c
  27. #define PIO_MDER 0x0050
  28. #define PIO_MDDR 0x0054
  29. #define PIO_MDSR 0x0058
  30. #define PIO_PUDR 0x0060
  31. #define PIO_PUER 0x0064
  32. #define PIO_PUSR 0x0068
  33. #define PIO_ASR 0x0070
  34. #define PIO_BSR 0x0074
  35. #define PIO_ABSR 0x0078
  36. #define PIO_OWER 0x00a0
  37. #define PIO_OWDR 0x00a4
  38. #define PIO_OWSR 0x00a8
  39. /* Hardware register access */
  40. #define pio_readl(base, reg) \
  41. __raw_readl((void *)base + PIO_##reg)
  42. #define pio_writel(base, reg, value) \
  43. __raw_writel((value), (void *)base + PIO_##reg)
  44. /* Portmux API starts here. See doc/README.AVR32-port-muxing */
  45. enum portmux_function {
  46. PORTMUX_FUNC_A,
  47. PORTMUX_FUNC_B,
  48. };
  49. /* Pull-down, buskeeper and drive strength are not supported */
  50. #define PORTMUX_DIR_INPUT (0 << 0)
  51. #define PORTMUX_DIR_OUTPUT (1 << 0)
  52. #define PORTMUX_INIT_LOW (0 << 1)
  53. #define PORTMUX_INIT_HIGH (1 << 1)
  54. #define PORTMUX_PULL_UP (1 << 2)
  55. #define PORTMUX_PULL_DOWN (0)
  56. #define PORTMUX_BUSKEEPER PORTMUX_PULL_UP
  57. #define PORTMUX_DRIVE_MIN (0)
  58. #define PORTMUX_DRIVE_LOW (0)
  59. #define PORTMUX_DRIVE_HIGH (0)
  60. #define PORTMUX_DRIVE_MAX (0)
  61. #define PORTMUX_OPEN_DRAIN (1 << 3)
  62. void portmux_select_peripheral(void *port, unsigned long pin_mask,
  63. enum portmux_function func, unsigned long flags);
  64. void portmux_select_gpio(void *port, unsigned long pin_mask,
  65. unsigned long flags);
  66. /* Internal helper functions */
  67. static inline void __pio_set_output_value(void *port, unsigned int pin,
  68. int value)
  69. {
  70. /*
  71. * value will usually be constant, but it's pretty cheap
  72. * either way.
  73. */
  74. if (value)
  75. pio_writel(port, SODR, 1 << pin);
  76. else
  77. pio_writel(port, CODR, 1 << pin);
  78. }
  79. static inline int __pio_get_input_value(void *port, unsigned int pin)
  80. {
  81. return (pio_readl(port, PDSR) >> pin) & 1;
  82. }
  83. void pio_set_output_value(unsigned int pin, int value);
  84. int pio_get_input_value(unsigned int pin);
  85. /* GPIO API starts here */
  86. /*
  87. * GCC doesn't realize that the constant case is extremely trivial,
  88. * so we need to help it make the right decision by using
  89. * always_inline.
  90. */
  91. __attribute__((always_inline))
  92. static inline void gpio_set_value(unsigned int pin, int value)
  93. {
  94. if (__builtin_constant_p(pin))
  95. __pio_set_output_value(pio_pin_to_port(pin), pin & 0x1f, value);
  96. else
  97. pio_set_output_value(pin, value);
  98. }
  99. __attribute__((always_inline))
  100. static inline int gpio_get_value(unsigned int pin)
  101. {
  102. if (__builtin_constant_p(pin))
  103. return __pio_get_input_value(pio_pin_to_port(pin), pin & 0x1f);
  104. else
  105. return pio_get_input_value(pin);
  106. }
  107. #endif /* __AVR32_PORTMUX_PIO_H__ */