mfp.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 GPSELD (0x0f << 4)
  27. #define GPSELEI0 (0x01 << 26)
  28. #define GPSELEI1 (0x01 << 27)
  29. #define GPIOG0TO1 (0x03 << 14)
  30. #define GPIOG2TO3 (0x03 << 16)
  31. #define GPIOG22TO23 (0x03 << 22)
  32. #define GPIOG18TO20 (0x07 << 18)
  33. #define ENSPI (0x0a << 14)
  34. #define ENI2C0 (0x01 << 14)
  35. #define ENI2C1 (0x01 << 16)
  36. #define ENAC97 (0x02 << 22)
  37. #define ENSD1 (0x02 << 18)
  38. #define ENSD0 (0x0a << 4)
  39. #define ENKPI (0x02 << 2)
  40. #define ENNAND (0x01 << 2)
  41. static DEFINE_MUTEX(mfp_mutex);
  42. void mfp_set_groupf(struct device *dev)
  43. {
  44. unsigned long mfpen;
  45. const char *dev_id;
  46. BUG_ON(!dev);
  47. mutex_lock(&mfp_mutex);
  48. dev_id = dev_name(dev);
  49. mfpen = __raw_readl(REG_MFSEL);
  50. if (strcmp(dev_id, "nuc900-emc") == 0)
  51. mfpen |= GPSELF;/*enable mac*/
  52. else
  53. mfpen &= ~GPSELF;/*GPIOF[9:0]*/
  54. __raw_writel(mfpen, REG_MFSEL);
  55. mutex_unlock(&mfp_mutex);
  56. }
  57. EXPORT_SYMBOL(mfp_set_groupf);
  58. void mfp_set_groupc(struct device *dev)
  59. {
  60. unsigned long mfpen;
  61. const char *dev_id;
  62. BUG_ON(!dev);
  63. mutex_lock(&mfp_mutex);
  64. dev_id = dev_name(dev);
  65. mfpen = __raw_readl(REG_MFSEL);
  66. if (strcmp(dev_id, "nuc900-lcd") == 0)
  67. mfpen |= GPSELC;/*enable lcd*/
  68. else if (strcmp(dev_id, "nuc900-kpi") == 0) {
  69. mfpen &= (~GPSELC);/*enable kpi*/
  70. mfpen |= ENKPI;
  71. } else if (strcmp(dev_id, "nuc900-nand") == 0) {
  72. mfpen &= (~GPSELC);/*enable nand*/
  73. mfpen |= ENNAND;
  74. } else
  75. mfpen &= (~GPSELC);/*GPIOC[14:0]*/
  76. __raw_writel(mfpen, REG_MFSEL);
  77. mutex_unlock(&mfp_mutex);
  78. }
  79. EXPORT_SYMBOL(mfp_set_groupc);
  80. void mfp_set_groupi(struct device *dev)
  81. {
  82. unsigned long mfpen;
  83. const char *dev_id;
  84. BUG_ON(!dev);
  85. mutex_lock(&mfp_mutex);
  86. dev_id = dev_name(dev);
  87. mfpen = __raw_readl(REG_MFSEL);
  88. mfpen &= ~GPSELEI1;/*default gpio16*/
  89. if (strcmp(dev_id, "nuc900-wdog") == 0)
  90. mfpen |= GPSELEI1;/*enable wdog*/
  91. else if (strcmp(dev_id, "nuc900-atapi") == 0)
  92. mfpen |= GPSELEI0;/*enable atapi*/
  93. else if (strcmp(dev_id, "nuc900-keypad") == 0)
  94. mfpen &= ~GPSELEI0;/*enable keypad*/
  95. __raw_writel(mfpen, REG_MFSEL);
  96. mutex_unlock(&mfp_mutex);
  97. }
  98. EXPORT_SYMBOL(mfp_set_groupi);
  99. void mfp_set_groupg(struct device *dev, const char *subname)
  100. {
  101. unsigned long mfpen;
  102. const char *dev_id;
  103. BUG_ON((!dev) && (!subname));
  104. mutex_lock(&mfp_mutex);
  105. if (subname != NULL)
  106. dev_id = subname;
  107. else
  108. dev_id = dev_name(dev);
  109. mfpen = __raw_readl(REG_MFSEL);
  110. if (strcmp(dev_id, "nuc900-spi") == 0) {
  111. mfpen &= ~(GPIOG0TO1 | GPIOG2TO3);
  112. mfpen |= ENSPI;/*enable spi*/
  113. } else if (strcmp(dev_id, "nuc900-i2c0") == 0) {
  114. mfpen &= ~(GPIOG0TO1);
  115. mfpen |= ENI2C0;/*enable i2c0*/
  116. } else if (strcmp(dev_id, "nuc900-i2c1") == 0) {
  117. mfpen &= ~(GPIOG2TO3);
  118. mfpen |= ENI2C1;/*enable i2c1*/
  119. } else if (strcmp(dev_id, "nuc900-ac97") == 0) {
  120. mfpen &= ~(GPIOG22TO23);
  121. mfpen |= ENAC97;/*enable AC97*/
  122. } else if (strcmp(dev_id, "nuc900-mmc-port1") == 0) {
  123. mfpen &= ~(GPIOG18TO20);
  124. mfpen |= (ENSD1 | 0x01);/*enable sd1*/
  125. } else {
  126. mfpen &= ~(GPIOG0TO1 | GPIOG2TO3);/*GPIOG[3:0]*/
  127. }
  128. __raw_writel(mfpen, REG_MFSEL);
  129. mutex_unlock(&mfp_mutex);
  130. }
  131. EXPORT_SYMBOL(mfp_set_groupg);
  132. void mfp_set_groupd(struct device *dev, const char *subname)
  133. {
  134. unsigned long mfpen;
  135. const char *dev_id;
  136. BUG_ON((!dev) && (!subname));
  137. mutex_lock(&mfp_mutex);
  138. if (subname != NULL)
  139. dev_id = subname;
  140. else
  141. dev_id = dev_name(dev);
  142. mfpen = __raw_readl(REG_MFSEL);
  143. if (strcmp(dev_id, "nuc900-mmc-port0") == 0) {
  144. mfpen &= ~GPSELD;/*enable sd0*/
  145. mfpen |= ENSD0;
  146. } else
  147. mfpen &= (~GPSELD);
  148. __raw_writel(mfpen, REG_MFSEL);
  149. mutex_unlock(&mfp_mutex);
  150. }
  151. EXPORT_SYMBOL(mfp_set_groupd);