2 * linux/arch/arm/mach-omap/mux.c
4 * Utility to set the Omap MUX and PULL_DWN registers from a table in mux.h
6 * Copyright (C) 2003 Nokia Corporation
8 * Written by Tony Lindgren <tony.lindgren@nokia.com>
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.
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.
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
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <asm/system.h>
30 #include <linux/spinlock.h>
33 #include <asm/arch/mux.h>
36 * Sets the Omap MUX and PULL_DWN registers based on the table
38 int omap_cfg_reg(const reg_cfg_t reg_cfg
)
40 #ifdef CONFIG_OMAP_MUX
41 static spinlock_t mux_spin_lock
= SPIN_LOCK_UNLOCKED
;
45 unsigned int reg_orig
= 0, reg
= 0, pu_pd_orig
= 0, pu_pd
= 0,
46 pull_orig
= 0, pull
= 0;
48 cfg
= ®_cfg_table
[reg_cfg
];
51 * We do a pretty long section here with lock on, but pin muxing
52 * should only happen on driver init for each driver, so it's not time
55 spin_lock_irqsave(&mux_spin_lock
, flags
);
57 /* Check the mux register in question */
59 reg_orig
= omap_readl(cfg
->mux_reg
);
61 /* The mux registers always seem to be 3 bits long */
62 reg
= reg_orig
& ~(0x7 << cfg
->mask_offset
);
64 reg
|= (cfg
->mask
<< cfg
->mask_offset
);
66 omap_writel(reg
, cfg
->mux_reg
);
69 /* Check for pull up or pull down selection on 1610 */
70 if (!cpu_is_omap1510()) {
71 if (cfg
->pu_pd_reg
&& cfg
->pull_val
) {
72 pu_pd_orig
= omap_readl(cfg
->pu_pd_reg
);
75 pu_pd
= pu_pd_orig
| (1 << cfg
->pull_bit
);
78 pu_pd
= pu_pd_orig
& ~(1 << cfg
->pull_bit
);
80 omap_writel(pu_pd
, cfg
->pu_pd_reg
);
84 /* Check for an associated pull down register */
86 pull_orig
= omap_readl(cfg
->pull_reg
);
89 /* Low bit = pull enabled */
90 pull
= pull_orig
& ~(1 << cfg
->pull_bit
);
92 /* High bit = pull disabled */
93 pull
= pull_orig
| (1 << cfg
->pull_bit
);
96 omap_writel(pull
, cfg
->pull_reg
);
99 #ifdef CONFIG_OMAP_MUX_DEBUG
101 printk("Omap: Setting register %s\n", cfg
->name
);
102 printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n",
103 cfg
->mux_reg_name
, cfg
->mux_reg
, reg_orig
, reg
);
105 if (!cpu_is_omap1510()) {
106 if (cfg
->pu_pd_reg
&& cfg
->pull_val
) {
107 printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n",
108 cfg
->pu_pd_name
, cfg
->pu_pd_reg
,
114 printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n",
115 cfg
->pull_name
, cfg
->pull_reg
, pull_orig
, pull
);
119 spin_unlock_irqrestore(&mux_spin_lock
, flags
);
125 EXPORT_SYMBOL(omap_cfg_reg
);