mfp-pxa2xx.c 4.8 KB

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