mfp-pxa2xx.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * linux/arch/arm/mach-pxa/mfp-pxa2xx.c
  3. *
  4. * PXA2xx pin mux configuration support
  5. *
  6. * The GPIOs on PXA2xx can be configured as one of many alternate
  7. * functions, this is by concept samilar to the MFP configuration
  8. * on PXA3xx, what's more important, the low power pin state and
  9. * wakeup detection are also supported by the same framework.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/sysdev.h>
  19. #include <asm/arch/hardware.h>
  20. #include <asm/arch/pxa-regs.h>
  21. #include <asm/arch/pxa2xx-regs.h>
  22. #include <asm/arch/mfp-pxa2xx.h>
  23. #include "generic.h"
  24. #define PGSR(x) __REG2(0x40F00020, ((x) & 0x60) >> 3)
  25. #define PWER_WE35 (1 << 24)
  26. struct gpio_desc {
  27. unsigned valid : 1;
  28. unsigned can_wakeup : 1;
  29. unsigned keypad_gpio : 1;
  30. unsigned int mask; /* bit mask in PWER or PKWR */
  31. unsigned long config;
  32. };
  33. static struct gpio_desc gpio_desc[MFP_PIN_GPIO127 + 1];
  34. static int __mfp_config_gpio(unsigned gpio, unsigned long c)
  35. {
  36. unsigned long gafr, mask = GPIO_bit(gpio);
  37. int fn;
  38. fn = MFP_AF(c);
  39. if (fn > 3)
  40. return -EINVAL;
  41. /* alternate function and direction */
  42. gafr = GAFR(gpio) & ~(0x3 << ((gpio & 0xf) * 2));
  43. GAFR(gpio) = gafr | (fn << ((gpio & 0xf) * 2));
  44. if (c & MFP_DIR_OUT)
  45. GPDR(gpio) |= mask;
  46. else
  47. GPDR(gpio) &= ~mask;
  48. /* low power state */
  49. switch (c & MFP_LPM_STATE_MASK) {
  50. case MFP_LPM_DRIVE_HIGH:
  51. PGSR(gpio) |= mask;
  52. break;
  53. case MFP_LPM_DRIVE_LOW:
  54. PGSR(gpio) &= ~mask;
  55. break;
  56. case MFP_LPM_INPUT:
  57. break;
  58. default:
  59. pr_warning("%s: invalid low power state for GPIO%d\n",
  60. __func__, gpio);
  61. return -EINVAL;
  62. }
  63. /* give early warning if MFP_LPM_CAN_WAKEUP is set on the
  64. * configurations of those pins not able to wakeup
  65. */
  66. if ((c & MFP_LPM_CAN_WAKEUP) && !gpio_desc[gpio].can_wakeup) {
  67. pr_warning("%s: GPIO%d unable to wakeup\n",
  68. __func__, gpio);
  69. return -EINVAL;
  70. }
  71. if ((c & MFP_LPM_CAN_WAKEUP) && (c & MFP_DIR_OUT)) {
  72. pr_warning("%s: output GPIO%d unable to wakeup\n",
  73. __func__, gpio);
  74. return -EINVAL;
  75. }
  76. return 0;
  77. }
  78. void pxa2xx_mfp_config(unsigned long *mfp_cfgs, int num)
  79. {
  80. unsigned long flags;
  81. unsigned long *c;
  82. int i, gpio;
  83. for (i = 0, c = mfp_cfgs; i < num; i++, c++) {
  84. gpio = mfp_to_gpio(MFP_PIN(*c));
  85. if (!gpio_desc[gpio].valid) {
  86. pr_warning("%s: GPIO%d is invalid pin\n",
  87. __func__, gpio);
  88. continue;
  89. }
  90. local_irq_save(flags);
  91. gpio_desc[gpio].config = *c;
  92. __mfp_config_gpio(gpio, *c);
  93. local_irq_restore(flags);
  94. }
  95. }
  96. int gpio_set_wake(unsigned int gpio, unsigned int on)
  97. {
  98. struct gpio_desc *d;
  99. unsigned long c;
  100. if (gpio > mfp_to_gpio(MFP_PIN_GPIO127))
  101. return -EINVAL;
  102. d = &gpio_desc[gpio];
  103. c = d->config;
  104. if (!d->valid)
  105. return -EINVAL;
  106. if (d->keypad_gpio)
  107. return -EINVAL;
  108. if (d->can_wakeup && (c & MFP_LPM_CAN_WAKEUP)) {
  109. if (on) {
  110. PWER |= d->mask;
  111. if (c & MFP_LPM_EDGE_RISE)
  112. PRER |= d->mask;
  113. else
  114. PRER &= ~d->mask;
  115. if (c & MFP_LPM_EDGE_FALL)
  116. PFER |= d->mask;
  117. else
  118. PFER &= ~d->mask;
  119. } else {
  120. PWER &= ~d->mask;
  121. PRER &= ~d->mask;
  122. PFER &= ~d->mask;
  123. }
  124. }
  125. return 0;
  126. }
  127. #ifdef CONFIG_PXA25x
  128. static int __init pxa25x_mfp_init(void)
  129. {
  130. int i;
  131. if (cpu_is_pxa25x()) {
  132. for (i = 0; i <= 84; i++)
  133. gpio_desc[i].valid = 1;
  134. for (i = 0; i <= 15; i++) {
  135. gpio_desc[i].can_wakeup = 1;
  136. gpio_desc[i].mask = GPIO_bit(i);
  137. }
  138. }
  139. return 0;
  140. }
  141. postcore_initcall(pxa25x_mfp_init);
  142. #endif /* CONFIG_PXA25x */
  143. #ifdef CONFIG_PXA27x
  144. static int pxa27x_pkwr_gpio[] = {
  145. 13, 16, 17, 34, 36, 37, 38, 39, 90, 91, 93, 94,
  146. 95, 96, 97, 98, 99, 100, 101, 102
  147. };
  148. int keypad_set_wake(unsigned int on)
  149. {
  150. unsigned int i, gpio, mask = 0;
  151. if (!on) {
  152. PKWR = 0;
  153. return 0;
  154. }
  155. for (i = 0; i < ARRAY_SIZE(pxa27x_pkwr_gpio); i++) {
  156. gpio = pxa27x_pkwr_gpio[i];
  157. if (gpio_desc[gpio].config & MFP_LPM_CAN_WAKEUP)
  158. mask |= gpio_desc[gpio].mask;
  159. }
  160. PKWR = mask;
  161. return 0;
  162. }
  163. static int __init pxa27x_mfp_init(void)
  164. {
  165. int i, gpio;
  166. if (cpu_is_pxa27x()) {
  167. for (i = 0; i <= 120; i++) {
  168. /* skip GPIO2, 5, 6, 7, 8, they are not
  169. * valid pins allow configuration
  170. */
  171. if (i == 2 || i == 5 || i == 6 ||
  172. i == 7 || i == 8)
  173. continue;
  174. gpio_desc[i].valid = 1;
  175. }
  176. /* Keypad GPIOs */
  177. for (i = 0; i < ARRAY_SIZE(pxa27x_pkwr_gpio); i++) {
  178. gpio = pxa27x_pkwr_gpio[i];
  179. gpio_desc[gpio].can_wakeup = 1;
  180. gpio_desc[gpio].keypad_gpio = 1;
  181. gpio_desc[gpio].mask = 1 << i;
  182. }
  183. /* Overwrite GPIO13 as a PWER wakeup source */
  184. for (i = 0; i <= 15; i++) {
  185. /* skip GPIO2, 5, 6, 7, 8 */
  186. if (GPIO_bit(i) & 0x1e4)
  187. continue;
  188. gpio_desc[i].can_wakeup = 1;
  189. gpio_desc[i].mask = GPIO_bit(i);
  190. }
  191. gpio_desc[35].can_wakeup = 1;
  192. gpio_desc[35].mask = PWER_WE35;
  193. }
  194. return 0;
  195. }
  196. postcore_initcall(pxa27x_mfp_init);
  197. #endif /* CONFIG_PXA27x */