mux.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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/config.h>
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/kernel.h>
  29. #include <asm/system.h>
  30. #include <asm/io.h>
  31. #include <linux/spinlock.h>
  32. #include <asm/arch/mux.h>
  33. #ifdef CONFIG_OMAP_MUX
  34. #define OMAP24XX_L4_BASE 0x48000000
  35. #define OMAP24XX_PULL_ENA (1 << 3)
  36. #define OMAP24XX_PULL_UP (1 << 4)
  37. static struct pin_config * pin_table;
  38. static unsigned long pin_table_sz;
  39. extern struct pin_config * omap730_pins;
  40. extern struct pin_config * omap1xxx_pins;
  41. extern struct pin_config * omap24xx_pins;
  42. int __init omap_mux_register(struct pin_config * pins, unsigned long size)
  43. {
  44. pin_table = pins;
  45. pin_table_sz = size;
  46. return 0;
  47. }
  48. /*
  49. * Sets the Omap MUX and PULL_DWN registers based on the table
  50. */
  51. int __init_or_module omap_cfg_reg(const unsigned long index)
  52. {
  53. static DEFINE_SPINLOCK(mux_spin_lock);
  54. unsigned long flags;
  55. struct pin_config *cfg;
  56. unsigned int reg_orig = 0, reg = 0, pu_pd_orig = 0, pu_pd = 0,
  57. pull_orig = 0, pull = 0;
  58. unsigned int mask, warn = 0;
  59. if (!pin_table)
  60. BUG();
  61. if (index >= pin_table_sz) {
  62. printk(KERN_ERR "Invalid pin mux index: %lu (%lu)\n",
  63. index, pin_table_sz);
  64. dump_stack();
  65. return -ENODEV;
  66. }
  67. cfg = (struct pin_config *)&pin_table[index];
  68. if (cpu_is_omap24xx()) {
  69. u8 reg = 0;
  70. reg |= cfg->mask & 0x7;
  71. if (cfg->pull_val)
  72. reg |= OMAP24XX_PULL_ENA;
  73. if(cfg->pu_pd_val)
  74. reg |= OMAP24XX_PULL_UP;
  75. #ifdef CONFIG_OMAP_MUX_DEBUG
  76. printk("Muxing %s (0x%08x): 0x%02x -> 0x%02x\n",
  77. cfg->name, OMAP24XX_L4_BASE + cfg->mux_reg,
  78. omap_readb(OMAP24XX_L4_BASE + cfg->mux_reg), reg);
  79. #endif
  80. omap_writeb(reg, OMAP24XX_L4_BASE + cfg->mux_reg);
  81. return 0;
  82. }
  83. /* Check the mux register in question */
  84. if (cfg->mux_reg) {
  85. unsigned tmp1, tmp2;
  86. spin_lock_irqsave(&mux_spin_lock, flags);
  87. reg_orig = omap_readl(cfg->mux_reg);
  88. /* The mux registers always seem to be 3 bits long */
  89. mask = (0x7 << cfg->mask_offset);
  90. tmp1 = reg_orig & mask;
  91. reg = reg_orig & ~mask;
  92. tmp2 = (cfg->mask << cfg->mask_offset);
  93. reg |= tmp2;
  94. if (tmp1 != tmp2)
  95. warn = 1;
  96. omap_writel(reg, cfg->mux_reg);
  97. spin_unlock_irqrestore(&mux_spin_lock, flags);
  98. }
  99. /* Check for pull up or pull down selection on 1610 */
  100. if (!cpu_is_omap1510()) {
  101. if (cfg->pu_pd_reg && cfg->pull_val) {
  102. spin_lock_irqsave(&mux_spin_lock, flags);
  103. pu_pd_orig = omap_readl(cfg->pu_pd_reg);
  104. mask = 1 << cfg->pull_bit;
  105. if (cfg->pu_pd_val) {
  106. if (!(pu_pd_orig & mask))
  107. warn = 1;
  108. /* Use pull up */
  109. pu_pd = pu_pd_orig | mask;
  110. } else {
  111. if (pu_pd_orig & mask)
  112. warn = 1;
  113. /* Use pull down */
  114. pu_pd = pu_pd_orig & ~mask;
  115. }
  116. omap_writel(pu_pd, cfg->pu_pd_reg);
  117. spin_unlock_irqrestore(&mux_spin_lock, flags);
  118. }
  119. }
  120. /* Check for an associated pull down register */
  121. if (cfg->pull_reg) {
  122. spin_lock_irqsave(&mux_spin_lock, flags);
  123. pull_orig = omap_readl(cfg->pull_reg);
  124. mask = 1 << cfg->pull_bit;
  125. if (cfg->pull_val) {
  126. if (pull_orig & mask)
  127. warn = 1;
  128. /* Low bit = pull enabled */
  129. pull = pull_orig & ~mask;
  130. } else {
  131. if (!(pull_orig & mask))
  132. warn = 1;
  133. /* High bit = pull disabled */
  134. pull = pull_orig | mask;
  135. }
  136. omap_writel(pull, cfg->pull_reg);
  137. spin_unlock_irqrestore(&mux_spin_lock, flags);
  138. }
  139. if (warn) {
  140. #ifdef CONFIG_OMAP_MUX_WARNINGS
  141. printk(KERN_WARNING "MUX: initialized %s\n", cfg->name);
  142. #endif
  143. }
  144. #ifdef CONFIG_OMAP_MUX_DEBUG
  145. if (cfg->debug || warn) {
  146. printk("MUX: Setting register %s\n", cfg->name);
  147. printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n",
  148. cfg->mux_reg_name, cfg->mux_reg, reg_orig, reg);
  149. if (!cpu_is_omap1510()) {
  150. if (cfg->pu_pd_reg && cfg->pull_val) {
  151. printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n",
  152. cfg->pu_pd_name, cfg->pu_pd_reg,
  153. pu_pd_orig, pu_pd);
  154. }
  155. }
  156. if (cfg->pull_reg)
  157. printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n",
  158. cfg->pull_name, cfg->pull_reg, pull_orig, pull);
  159. }
  160. #endif
  161. #ifdef CONFIG_OMAP_MUX_ERRORS
  162. return warn ? -ETXTBSY : 0;
  163. #else
  164. return 0;
  165. #endif
  166. }
  167. EXPORT_SYMBOL(omap_cfg_reg);
  168. #else
  169. #define omap_mux_init() do {} while(0)
  170. #define omap_cfg_reg(x) do {} while(0)
  171. #endif /* CONFIG_OMAP_MUX */