mux.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * linux/arch/arm/plat-omap/mux.c
  3. *
  4. * Utility to set the Omap MUX and PULL_DWN registers from a table in mux.h
  5. *
  6. * Copyright (C) 2003 - 2005 Nokia Corporation
  7. *
  8. * Written by Tony Lindgren <tony.lindgren@nokia.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #include <linux/module.h>
  26. #include <linux/init.h>
  27. #include <linux/kernel.h>
  28. #include <asm/system.h>
  29. #include <asm/io.h>
  30. #include <linux/spinlock.h>
  31. #include <asm/arch/mux.h>
  32. #ifdef CONFIG_OMAP_MUX
  33. #define OMAP24XX_L4_BASE 0x48000000
  34. #define OMAP24XX_PULL_ENA (1 << 3)
  35. #define OMAP24XX_PULL_UP (1 << 4)
  36. static struct pin_config * pin_table;
  37. static unsigned long pin_table_sz;
  38. extern struct pin_config * omap730_pins;
  39. extern struct pin_config * omap1xxx_pins;
  40. extern struct pin_config * omap24xx_pins;
  41. int __init omap_mux_register(struct pin_config * pins, unsigned long size)
  42. {
  43. pin_table = pins;
  44. pin_table_sz = size;
  45. return 0;
  46. }
  47. /*
  48. * Sets the Omap MUX and PULL_DWN registers based on the table
  49. */
  50. int __init_or_module omap_cfg_reg(const unsigned long index)
  51. {
  52. static DEFINE_SPINLOCK(mux_spin_lock);
  53. unsigned long flags;
  54. struct pin_config *cfg;
  55. unsigned int reg_orig = 0, reg = 0, pu_pd_orig = 0, pu_pd = 0,
  56. pull_orig = 0, pull = 0;
  57. unsigned int mask, warn = 0;
  58. if (!pin_table)
  59. BUG();
  60. if (index >= pin_table_sz) {
  61. printk(KERN_ERR "Invalid pin mux index: %lu (%lu)\n",
  62. index, pin_table_sz);
  63. dump_stack();
  64. return -ENODEV;
  65. }
  66. cfg = (struct pin_config *)&pin_table[index];
  67. if (cpu_is_omap24xx()) {
  68. u8 reg = 0;
  69. reg |= cfg->mask & 0x7;
  70. if (cfg->pull_val)
  71. reg |= OMAP24XX_PULL_ENA;
  72. if(cfg->pu_pd_val)
  73. reg |= OMAP24XX_PULL_UP;
  74. #if defined(CONFIG_OMAP_MUX_DEBUG) || defined(CONFIG_OMAP_MUX_WARNINGS)
  75. {
  76. u8 orig = omap_readb(OMAP24XX_L4_BASE + cfg->mux_reg);
  77. u8 debug = 0;
  78. #ifdef CONFIG_OMAP_MUX_DEBUG
  79. debug = cfg->debug;
  80. #endif
  81. warn = (orig != reg);
  82. if (debug || warn)
  83. printk("MUX: setup %s (0x%08x): 0x%02x -> 0x%02x\n",
  84. cfg->name,
  85. OMAP24XX_L4_BASE + cfg->mux_reg,
  86. orig, reg);
  87. }
  88. #endif
  89. omap_writeb(reg, OMAP24XX_L4_BASE + cfg->mux_reg);
  90. return 0;
  91. }
  92. /* Check the mux register in question */
  93. if (cfg->mux_reg) {
  94. unsigned tmp1, tmp2;
  95. spin_lock_irqsave(&mux_spin_lock, flags);
  96. reg_orig = omap_readl(cfg->mux_reg);
  97. /* The mux registers always seem to be 3 bits long */
  98. mask = (0x7 << cfg->mask_offset);
  99. tmp1 = reg_orig & mask;
  100. reg = reg_orig & ~mask;
  101. tmp2 = (cfg->mask << cfg->mask_offset);
  102. reg |= tmp2;
  103. if (tmp1 != tmp2)
  104. warn = 1;
  105. omap_writel(reg, cfg->mux_reg);
  106. spin_unlock_irqrestore(&mux_spin_lock, flags);
  107. }
  108. /* Check for pull up or pull down selection on 1610 */
  109. if (!cpu_is_omap15xx()) {
  110. if (cfg->pu_pd_reg && cfg->pull_val) {
  111. spin_lock_irqsave(&mux_spin_lock, flags);
  112. pu_pd_orig = omap_readl(cfg->pu_pd_reg);
  113. mask = 1 << cfg->pull_bit;
  114. if (cfg->pu_pd_val) {
  115. if (!(pu_pd_orig & mask))
  116. warn = 1;
  117. /* Use pull up */
  118. pu_pd = pu_pd_orig | mask;
  119. } else {
  120. if (pu_pd_orig & mask)
  121. warn = 1;
  122. /* Use pull down */
  123. pu_pd = pu_pd_orig & ~mask;
  124. }
  125. omap_writel(pu_pd, cfg->pu_pd_reg);
  126. spin_unlock_irqrestore(&mux_spin_lock, flags);
  127. }
  128. }
  129. /* Check for an associated pull down register */
  130. if (cfg->pull_reg) {
  131. spin_lock_irqsave(&mux_spin_lock, flags);
  132. pull_orig = omap_readl(cfg->pull_reg);
  133. mask = 1 << cfg->pull_bit;
  134. if (cfg->pull_val) {
  135. if (pull_orig & mask)
  136. warn = 1;
  137. /* Low bit = pull enabled */
  138. pull = pull_orig & ~mask;
  139. } else {
  140. if (!(pull_orig & mask))
  141. warn = 1;
  142. /* High bit = pull disabled */
  143. pull = pull_orig | mask;
  144. }
  145. omap_writel(pull, cfg->pull_reg);
  146. spin_unlock_irqrestore(&mux_spin_lock, flags);
  147. }
  148. if (warn) {
  149. #ifdef CONFIG_OMAP_MUX_WARNINGS
  150. printk(KERN_WARNING "MUX: initialized %s\n", cfg->name);
  151. #endif
  152. }
  153. #ifdef CONFIG_OMAP_MUX_DEBUG
  154. if (cfg->debug || warn) {
  155. printk("MUX: Setting register %s\n", cfg->name);
  156. printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n",
  157. cfg->mux_reg_name, cfg->mux_reg, reg_orig, reg);
  158. if (!cpu_is_omap15xx()) {
  159. if (cfg->pu_pd_reg && cfg->pull_val) {
  160. printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n",
  161. cfg->pu_pd_name, cfg->pu_pd_reg,
  162. pu_pd_orig, pu_pd);
  163. }
  164. }
  165. if (cfg->pull_reg)
  166. printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n",
  167. cfg->pull_name, cfg->pull_reg, pull_orig, pull);
  168. }
  169. #endif
  170. #ifdef CONFIG_OMAP_MUX_ERRORS
  171. return warn ? -ETXTBSY : 0;
  172. #else
  173. return 0;
  174. #endif
  175. }
  176. EXPORT_SYMBOL(omap_cfg_reg);
  177. #else
  178. #define omap_mux_init() do {} while(0)
  179. #define omap_cfg_reg(x) do {} while(0)
  180. #endif /* CONFIG_OMAP_MUX */