mux.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. #ifdef CONFIG_OMAP_MUX_DEBUG
  75. printk("Muxing %s (0x%08x): 0x%02x -> 0x%02x\n",
  76. cfg->name, OMAP24XX_L4_BASE + cfg->mux_reg,
  77. omap_readb(OMAP24XX_L4_BASE + cfg->mux_reg), reg);
  78. #endif
  79. omap_writeb(reg, OMAP24XX_L4_BASE + cfg->mux_reg);
  80. return 0;
  81. }
  82. /* Check the mux register in question */
  83. if (cfg->mux_reg) {
  84. unsigned tmp1, tmp2;
  85. spin_lock_irqsave(&mux_spin_lock, flags);
  86. reg_orig = omap_readl(cfg->mux_reg);
  87. /* The mux registers always seem to be 3 bits long */
  88. mask = (0x7 << cfg->mask_offset);
  89. tmp1 = reg_orig & mask;
  90. reg = reg_orig & ~mask;
  91. tmp2 = (cfg->mask << cfg->mask_offset);
  92. reg |= tmp2;
  93. if (tmp1 != tmp2)
  94. warn = 1;
  95. omap_writel(reg, cfg->mux_reg);
  96. spin_unlock_irqrestore(&mux_spin_lock, flags);
  97. }
  98. /* Check for pull up or pull down selection on 1610 */
  99. if (!cpu_is_omap1510()) {
  100. if (cfg->pu_pd_reg && cfg->pull_val) {
  101. spin_lock_irqsave(&mux_spin_lock, flags);
  102. pu_pd_orig = omap_readl(cfg->pu_pd_reg);
  103. mask = 1 << cfg->pull_bit;
  104. if (cfg->pu_pd_val) {
  105. if (!(pu_pd_orig & mask))
  106. warn = 1;
  107. /* Use pull up */
  108. pu_pd = pu_pd_orig | mask;
  109. } else {
  110. if (pu_pd_orig & mask)
  111. warn = 1;
  112. /* Use pull down */
  113. pu_pd = pu_pd_orig & ~mask;
  114. }
  115. omap_writel(pu_pd, cfg->pu_pd_reg);
  116. spin_unlock_irqrestore(&mux_spin_lock, flags);
  117. }
  118. }
  119. /* Check for an associated pull down register */
  120. if (cfg->pull_reg) {
  121. spin_lock_irqsave(&mux_spin_lock, flags);
  122. pull_orig = omap_readl(cfg->pull_reg);
  123. mask = 1 << cfg->pull_bit;
  124. if (cfg->pull_val) {
  125. if (pull_orig & mask)
  126. warn = 1;
  127. /* Low bit = pull enabled */
  128. pull = pull_orig & ~mask;
  129. } else {
  130. if (!(pull_orig & mask))
  131. warn = 1;
  132. /* High bit = pull disabled */
  133. pull = pull_orig | mask;
  134. }
  135. omap_writel(pull, cfg->pull_reg);
  136. spin_unlock_irqrestore(&mux_spin_lock, flags);
  137. }
  138. if (warn) {
  139. #ifdef CONFIG_OMAP_MUX_WARNINGS
  140. printk(KERN_WARNING "MUX: initialized %s\n", cfg->name);
  141. #endif
  142. }
  143. #ifdef CONFIG_OMAP_MUX_DEBUG
  144. if (cfg->debug || warn) {
  145. printk("MUX: Setting register %s\n", cfg->name);
  146. printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n",
  147. cfg->mux_reg_name, cfg->mux_reg, reg_orig, reg);
  148. if (!cpu_is_omap1510()) {
  149. if (cfg->pu_pd_reg && cfg->pull_val) {
  150. printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n",
  151. cfg->pu_pd_name, cfg->pu_pd_reg,
  152. pu_pd_orig, pu_pd);
  153. }
  154. }
  155. if (cfg->pull_reg)
  156. printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n",
  157. cfg->pull_name, cfg->pull_reg, pull_orig, pull);
  158. }
  159. #endif
  160. #ifdef CONFIG_OMAP_MUX_ERRORS
  161. return warn ? -ETXTBSY : 0;
  162. #else
  163. return 0;
  164. #endif
  165. }
  166. EXPORT_SYMBOL(omap_cfg_reg);
  167. #else
  168. #define omap_mux_init() do {} while(0)
  169. #define omap_cfg_reg(x) do {} while(0)
  170. #endif /* CONFIG_OMAP_MUX */