mfp.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * linux/arch/arm/mach-w90x900/mfp.c
  3. *
  4. * Copyright (c) 2008 Nuvoton technology corporation
  5. *
  6. * Wan ZongShun <mcuos.com@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation;version 2 of the License.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/device.h>
  15. #include <linux/list.h>
  16. #include <linux/errno.h>
  17. #include <linux/err.h>
  18. #include <linux/string.h>
  19. #include <linux/clk.h>
  20. #include <linux/mutex.h>
  21. #include <linux/io.h>
  22. #include <mach/hardware.h>
  23. #define REG_MFSEL (W90X900_VA_GCR + 0xC)
  24. #define GPSELF (0x01 << 1)
  25. #define GPSELC (0x03 << 2)
  26. #define ENKPI (0x02 << 2)
  27. #define ENNAND (0x01 << 2)
  28. #define GPSELEI0 (0x01 << 26)
  29. #define GPSELEI1 (0x01 << 27)
  30. #define GPIOG0TO1 (0x03 << 14)
  31. #define GPIOG2TO3 (0x03 << 16)
  32. #define GPIOG22TO23 (0x03 << 22)
  33. #define ENSPI (0x0a << 14)
  34. #define ENI2C0 (0x01 << 14)
  35. #define ENI2C1 (0x01 << 16)
  36. #define ENAC97 (0x02 << 22)
  37. static DEFINE_MUTEX(mfp_mutex);
  38. void mfp_set_groupf(struct device *dev)
  39. {
  40. unsigned long mfpen;
  41. const char *dev_id;
  42. BUG_ON(!dev);
  43. mutex_lock(&mfp_mutex);
  44. dev_id = dev_name(dev);
  45. mfpen = __raw_readl(REG_MFSEL);
  46. if (strcmp(dev_id, "nuc900-emc") == 0)
  47. mfpen |= GPSELF;/*enable mac*/
  48. else
  49. mfpen &= ~GPSELF;/*GPIOF[9:0]*/
  50. __raw_writel(mfpen, REG_MFSEL);
  51. mutex_unlock(&mfp_mutex);
  52. }
  53. EXPORT_SYMBOL(mfp_set_groupf);
  54. void mfp_set_groupc(struct device *dev)
  55. {
  56. unsigned long mfpen;
  57. const char *dev_id;
  58. BUG_ON(!dev);
  59. mutex_lock(&mfp_mutex);
  60. dev_id = dev_name(dev);
  61. mfpen = __raw_readl(REG_MFSEL);
  62. if (strcmp(dev_id, "nuc900-lcd") == 0)
  63. mfpen |= GPSELC;/*enable lcd*/
  64. else if (strcmp(dev_id, "nuc900-kpi") == 0) {
  65. mfpen &= (~GPSELC);/*enable kpi*/
  66. mfpen |= ENKPI;
  67. } else if (strcmp(dev_id, "nuc900-nand") == 0) {
  68. mfpen &= (~GPSELC);/*enable nand*/
  69. mfpen |= ENNAND;
  70. } else
  71. mfpen &= (~GPSELC);/*GPIOC[14:0]*/
  72. __raw_writel(mfpen, REG_MFSEL);
  73. mutex_unlock(&mfp_mutex);
  74. }
  75. EXPORT_SYMBOL(mfp_set_groupc);
  76. void mfp_set_groupi(struct device *dev)
  77. {
  78. unsigned long mfpen;
  79. const char *dev_id;
  80. BUG_ON(!dev);
  81. mutex_lock(&mfp_mutex);
  82. dev_id = dev_name(dev);
  83. mfpen = __raw_readl(REG_MFSEL);
  84. mfpen &= ~GPSELEI1;/*default gpio16*/
  85. if (strcmp(dev_id, "nuc900-wdog") == 0)
  86. mfpen |= GPSELEI1;/*enable wdog*/
  87. else if (strcmp(dev_id, "nuc900-atapi") == 0)
  88. mfpen |= GPSELEI0;/*enable atapi*/
  89. else if (strcmp(dev_id, "nuc900-keypad") == 0)
  90. mfpen &= ~GPSELEI0;/*enable keypad*/
  91. __raw_writel(mfpen, REG_MFSEL);
  92. mutex_unlock(&mfp_mutex);
  93. }
  94. EXPORT_SYMBOL(mfp_set_groupi);
  95. void mfp_set_groupg(struct device *dev)
  96. {
  97. unsigned long mfpen;
  98. const char *dev_id;
  99. BUG_ON(!dev);
  100. mutex_lock(&mfp_mutex);
  101. dev_id = dev_name(dev);
  102. mfpen = __raw_readl(REG_MFSEL);
  103. if (strcmp(dev_id, "nuc900-spi") == 0) {
  104. mfpen &= ~(GPIOG0TO1 | GPIOG2TO3);
  105. mfpen |= ENSPI;/*enable spi*/
  106. } else if (strcmp(dev_id, "nuc900-i2c0") == 0) {
  107. mfpen &= ~(GPIOG0TO1);
  108. mfpen |= ENI2C0;/*enable i2c0*/
  109. } else if (strcmp(dev_id, "nuc900-i2c1") == 0) {
  110. mfpen &= ~(GPIOG2TO3);
  111. mfpen |= ENI2C1;/*enable i2c1*/
  112. } else if (strcmp(dev_id, "nuc900-audio") == 0) {
  113. mfpen &= ~(GPIOG22TO23);
  114. mfpen |= ENAC97;/*enable AC97*/
  115. } else {
  116. mfpen &= ~(GPIOG0TO1 | GPIOG2TO3);/*GPIOG[3:0]*/
  117. }
  118. __raw_writel(mfpen, REG_MFSEL);
  119. mutex_unlock(&mfp_mutex);
  120. }
  121. EXPORT_SYMBOL(mfp_set_groupg);