blob: 7b64c89a9872a365aa79341e6ec45b8d3a25a60b [file] [log] [blame]
Haavard Skinnemoenfd077f22008-09-01 14:00:07 +02001/*
2 * Copyright (C) 2008 Atmel Corporation
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22#include <common.h>
23
24#include <asm/io.h>
Andreas Bießmann94156fa2010-11-04 23:15:30 +000025#include <asm/arch/hardware.h>
Haavard Skinnemoenfd077f22008-09-01 14:00:07 +020026#include <asm/arch/gpio.h>
27
28void portmux_select_peripheral(void *port, unsigned long pin_mask,
29 enum portmux_function func, unsigned long flags)
30{
31 /* Both pull-up and pull-down set means buskeeper */
32 if (flags & PORTMUX_PULL_DOWN)
33 gpio_writel(port, PDERS, pin_mask);
34 else
35 gpio_writel(port, PDERC, pin_mask);
36 if (flags & PORTMUX_PULL_UP)
37 gpio_writel(port, PUERS, pin_mask);
38 else
39 gpio_writel(port, PUERC, pin_mask);
40
41 /* Select drive strength */
42 if (flags & PORTMUX_DRIVE_LOW)
43 gpio_writel(port, ODCR0S, pin_mask);
44 else
45 gpio_writel(port, ODCR0C, pin_mask);
46 if (flags & PORTMUX_DRIVE_HIGH)
47 gpio_writel(port, ODCR1S, pin_mask);
48 else
49 gpio_writel(port, ODCR1C, pin_mask);
50
51 /* Select function */
52 if (func & PORTMUX_FUNC_B)
53 gpio_writel(port, PMR0S, pin_mask);
54 else
55 gpio_writel(port, PMR0C, pin_mask);
56 if (func & PORTMUX_FUNC_C)
57 gpio_writel(port, PMR1S, pin_mask);
58 else
59 gpio_writel(port, PMR1C, pin_mask);
60
61 /* Disable GPIO (i.e. enable peripheral) */
62 gpio_writel(port, GPERC, pin_mask);
63}
64
65void portmux_select_gpio(void *port, unsigned long pin_mask,
66 unsigned long flags)
67{
68 /* Both pull-up and pull-down set means buskeeper */
69 if (flags & PORTMUX_PULL_DOWN)
70 gpio_writel(port, PDERS, pin_mask);
71 else
72 gpio_writel(port, PDERC, pin_mask);
73 if (flags & PORTMUX_PULL_UP)
74 gpio_writel(port, PUERS, pin_mask);
75 else
76 gpio_writel(port, PUERC, pin_mask);
77
78 /* Enable open-drain mode if requested */
79 if (flags & PORTMUX_OPEN_DRAIN)
80 gpio_writel(port, ODMERS, pin_mask);
81 else
82 gpio_writel(port, ODMERC, pin_mask);
83
84 /* Select drive strength */
85 if (flags & PORTMUX_DRIVE_LOW)
86 gpio_writel(port, ODCR0S, pin_mask);
87 else
88 gpio_writel(port, ODCR0C, pin_mask);
89 if (flags & PORTMUX_DRIVE_HIGH)
90 gpio_writel(port, ODCR1S, pin_mask);
91 else
92 gpio_writel(port, ODCR1C, pin_mask);
93
94 /* Select direction and initial pin state */
95 if (flags & PORTMUX_DIR_OUTPUT) {
96 if (flags & PORTMUX_INIT_HIGH)
97 gpio_writel(port, OVRS, pin_mask);
98 else
99 gpio_writel(port, OVRC, pin_mask);
100 gpio_writel(port, ODERS, pin_mask);
101 } else {
102 gpio_writel(port, ODERC, pin_mask);
103 }
104
105 /* Enable GPIO */
106 gpio_writel(port, GPERS, pin_mask);
107}