mpp.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * arch/arm/mach-dove/mpp.c
  3. *
  4. * MPP functions for Marvell Dove SoCs
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/gpio.h>
  12. #include <linux/io.h>
  13. #include <plat/mpp.h>
  14. #include <mach/dove.h>
  15. #include <plat/orion-gpio.h>
  16. #include "mpp.h"
  17. struct dove_mpp_grp {
  18. int start;
  19. int end;
  20. };
  21. /* Map a group to a range of GPIO pins in that group */
  22. static const struct dove_mpp_grp dove_mpp_grp[] = {
  23. [MPP_24_39] = {
  24. .start = 24,
  25. .end = 39,
  26. },
  27. [MPP_40_45] = {
  28. .start = 40,
  29. .end = 45,
  30. },
  31. [MPP_46_51] = {
  32. .start = 46,
  33. .end = 51,
  34. },
  35. [MPP_58_61] = {
  36. .start = 58,
  37. .end = 61,
  38. },
  39. [MPP_62_63] = {
  40. .start = 62,
  41. .end = 63,
  42. },
  43. };
  44. /* Enable gpio for a range of pins. mode should be a combination of
  45. GPIO_OUTPUT_OK | GPIO_INPUT_OK */
  46. static void __init dove_mpp_gpio_mode(int start, int end, int gpio_mode)
  47. {
  48. int i;
  49. for (i = start; i <= end; i++)
  50. orion_gpio_set_valid(i, gpio_mode);
  51. }
  52. /* Dump all the extra MPP registers. The platform code will dump the
  53. registers for pins 0-23. */
  54. static void __init dove_mpp_dump_regs(void)
  55. {
  56. pr_debug("PMU_CTRL4_CTRL: %08x\n",
  57. readl(DOVE_MPP_CTRL4_VIRT_BASE));
  58. pr_debug("PMU_MPP_GENERAL_CTRL: %08x\n",
  59. readl(DOVE_PMU_MPP_GENERAL_CTRL));
  60. pr_debug("MPP_GENERAL: %08x\n", readl(DOVE_MPP_GENERAL_VIRT_BASE));
  61. }
  62. static void __init dove_mpp_cfg_nfc(int sel)
  63. {
  64. u32 mpp_gen_cfg = readl(DOVE_MPP_GENERAL_VIRT_BASE);
  65. mpp_gen_cfg &= ~0x1;
  66. mpp_gen_cfg |= sel;
  67. writel(mpp_gen_cfg, DOVE_MPP_GENERAL_VIRT_BASE);
  68. dove_mpp_gpio_mode(64, 71, GPIO_OUTPUT_OK);
  69. }
  70. static void __init dove_mpp_cfg_au1(int sel)
  71. {
  72. u32 mpp_ctrl4 = readl(DOVE_MPP_CTRL4_VIRT_BASE);
  73. u32 ssp_ctrl1 = readl(DOVE_SSP_CTRL_STATUS_1);
  74. u32 mpp_gen_ctrl = readl(DOVE_MPP_GENERAL_VIRT_BASE);
  75. u32 global_cfg_2 = readl(DOVE_GLOBAL_CONFIG_2);
  76. mpp_ctrl4 &= ~(DOVE_AU1_GPIO_SEL);
  77. ssp_ctrl1 &= ~(DOVE_SSP_ON_AU1);
  78. mpp_gen_ctrl &= ~(DOVE_AU1_SPDIFO_GPIO_EN);
  79. global_cfg_2 &= ~(DOVE_TWSI_OPTION3_GPIO);
  80. if (!sel || sel == 0x2)
  81. dove_mpp_gpio_mode(52, 57, 0);
  82. else
  83. dove_mpp_gpio_mode(52, 57, GPIO_OUTPUT_OK | GPIO_INPUT_OK);
  84. if (sel & 0x1) {
  85. global_cfg_2 |= DOVE_TWSI_OPTION3_GPIO;
  86. dove_mpp_gpio_mode(56, 57, 0);
  87. }
  88. if (sel & 0x2) {
  89. mpp_gen_ctrl |= DOVE_AU1_SPDIFO_GPIO_EN;
  90. dove_mpp_gpio_mode(57, 57, GPIO_OUTPUT_OK | GPIO_INPUT_OK);
  91. }
  92. if (sel & 0x4) {
  93. ssp_ctrl1 |= DOVE_SSP_ON_AU1;
  94. dove_mpp_gpio_mode(52, 55, 0);
  95. }
  96. if (sel & 0x8)
  97. mpp_ctrl4 |= DOVE_AU1_GPIO_SEL;
  98. writel(mpp_ctrl4, DOVE_MPP_CTRL4_VIRT_BASE);
  99. writel(ssp_ctrl1, DOVE_SSP_CTRL_STATUS_1);
  100. writel(mpp_gen_ctrl, DOVE_MPP_GENERAL_VIRT_BASE);
  101. writel(global_cfg_2, DOVE_GLOBAL_CONFIG_2);
  102. }
  103. /* Configure the group registers, enabling GPIO if sel indicates the
  104. pin is to be used for GPIO */
  105. static void __init dove_mpp_conf_grp(unsigned int *mpp_grp_list)
  106. {
  107. u32 mpp_ctrl4 = readl(DOVE_MPP_CTRL4_VIRT_BASE);
  108. int gpio_mode;
  109. for ( ; *mpp_grp_list; mpp_grp_list++) {
  110. unsigned int num = MPP_NUM(*mpp_grp_list);
  111. unsigned int sel = MPP_SEL(*mpp_grp_list);
  112. if (num > MPP_GRP_MAX) {
  113. pr_err("dove: invalid MPP GRP number (%u)\n", num);
  114. continue;
  115. }
  116. mpp_ctrl4 &= ~(0x1 << num);
  117. mpp_ctrl4 |= sel << num;
  118. gpio_mode = sel ? GPIO_OUTPUT_OK | GPIO_INPUT_OK : 0;
  119. dove_mpp_gpio_mode(dove_mpp_grp[num].start,
  120. dove_mpp_grp[num].end, gpio_mode);
  121. }
  122. writel(mpp_ctrl4, DOVE_MPP_CTRL4_VIRT_BASE);
  123. }
  124. /* Configure the various MPP pins on Dove */
  125. void __init dove_mpp_conf(unsigned int *mpp_list,
  126. unsigned int *mpp_grp_list,
  127. unsigned int grp_au1_52_57,
  128. unsigned int grp_nfc_64_71)
  129. {
  130. dove_mpp_dump_regs();
  131. /* Use platform code for pins 0-23 */
  132. orion_mpp_conf(mpp_list, 0, MPP_MAX, DOVE_MPP_VIRT_BASE);
  133. dove_mpp_conf_grp(mpp_grp_list);
  134. dove_mpp_cfg_au1(grp_au1_52_57);
  135. dove_mpp_cfg_nfc(grp_nfc_64_71);
  136. dove_mpp_dump_regs();
  137. }