mfp-pxa2xx.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. static inline int __mfp_validate(int mfp)
  79. {
  80. int gpio = mfp_to_gpio(mfp);
  81. if ((mfp > MFP_PIN_GPIO127) || !gpio_desc[gpio].valid) {
  82. pr_warning("%s: GPIO%d is invalid pin\n", __func__, gpio);
  83. return -1;
  84. }
  85. return gpio;
  86. }
  87. void pxa2xx_mfp_config(unsigned long *mfp_cfgs, int num)
  88. {
  89. unsigned long flags;
  90. unsigned long *c;
  91. int i, gpio;
  92. for (i = 0, c = mfp_cfgs; i < num; i++, c++) {
  93. gpio = __mfp_validate(MFP_PIN(*c));
  94. if (gpio < 0)
  95. continue;
  96. local_irq_save(flags);
  97. gpio_desc[gpio].config = *c;
  98. __mfp_config_gpio(gpio, *c);
  99. local_irq_restore(flags);
  100. }
  101. }
  102. int gpio_set_wake(unsigned int gpio, unsigned int on)
  103. {
  104. struct gpio_desc *d;
  105. unsigned long c;
  106. if (gpio > mfp_to_gpio(MFP_PIN_GPIO127))
  107. return -EINVAL;
  108. d = &gpio_desc[gpio];
  109. c = d->config;
  110. if (!d->valid)
  111. return -EINVAL;
  112. if (d->keypad_gpio)
  113. return -EINVAL;
  114. if (d->can_wakeup && (c & MFP_LPM_CAN_WAKEUP)) {
  115. if (on) {
  116. PWER |= d->mask;
  117. if (c & MFP_LPM_EDGE_RISE)
  118. PRER |= d->mask;
  119. else
  120. PRER &= ~d->mask;
  121. if (c & MFP_LPM_EDGE_FALL)
  122. PFER |= d->mask;
  123. else
  124. PFER &= ~d->mask;
  125. } else {
  126. PWER &= ~d->mask;
  127. PRER &= ~d->mask;
  128. PFER &= ~d->mask;
  129. }
  130. }
  131. return 0;
  132. }
  133. #ifdef CONFIG_PXA25x
  134. static int __init pxa25x_mfp_init(void)
  135. {
  136. int i;
  137. if (cpu_is_pxa25x()) {
  138. for (i = 0; i <= 84; i++)
  139. gpio_desc[i].valid = 1;
  140. for (i = 0; i <= 15; i++) {
  141. gpio_desc[i].can_wakeup = 1;
  142. gpio_desc[i].mask = GPIO_bit(i);
  143. }
  144. }
  145. return 0;
  146. }
  147. postcore_initcall(pxa25x_mfp_init);
  148. #endif /* CONFIG_PXA25x */
  149. #ifdef CONFIG_PXA27x
  150. static int pxa27x_pkwr_gpio[] = {
  151. 13, 16, 17, 34, 36, 37, 38, 39, 90, 91, 93, 94,
  152. 95, 96, 97, 98, 99, 100, 101, 102
  153. };
  154. int keypad_set_wake(unsigned int on)
  155. {
  156. unsigned int i, gpio, mask = 0;
  157. if (!on) {
  158. PKWR = 0;
  159. return 0;
  160. }
  161. for (i = 0; i < ARRAY_SIZE(pxa27x_pkwr_gpio); i++) {
  162. gpio = pxa27x_pkwr_gpio[i];
  163. if (gpio_desc[gpio].config & MFP_LPM_CAN_WAKEUP)
  164. mask |= gpio_desc[gpio].mask;
  165. }
  166. PKWR = mask;
  167. return 0;
  168. }
  169. static int __init pxa27x_mfp_init(void)
  170. {
  171. int i, gpio;
  172. if (cpu_is_pxa27x()) {
  173. for (i = 0; i <= 120; i++) {
  174. /* skip GPIO2, 5, 6, 7, 8, they are not
  175. * valid pins allow configuration
  176. */
  177. if (i == 2 || i == 5 || i == 6 ||
  178. i == 7 || i == 8)
  179. continue;
  180. gpio_desc[i].valid = 1;
  181. }
  182. /* Keypad GPIOs */
  183. for (i = 0; i < ARRAY_SIZE(pxa27x_pkwr_gpio); i++) {
  184. gpio = pxa27x_pkwr_gpio[i];
  185. gpio_desc[gpio].can_wakeup = 1;
  186. gpio_desc[gpio].keypad_gpio = 1;
  187. gpio_desc[gpio].mask = 1 << i;
  188. }
  189. /* Overwrite GPIO13 as a PWER wakeup source */
  190. for (i = 0; i <= 15; i++) {
  191. /* skip GPIO2, 5, 6, 7, 8 */
  192. if (GPIO_bit(i) & 0x1e4)
  193. continue;
  194. gpio_desc[i].can_wakeup = 1;
  195. gpio_desc[i].mask = GPIO_bit(i);
  196. }
  197. gpio_desc[35].can_wakeup = 1;
  198. gpio_desc[35].mask = PWER_WE35;
  199. }
  200. return 0;
  201. }
  202. postcore_initcall(pxa27x_mfp_init);
  203. #endif /* CONFIG_PXA27x */