2
* Copyright (C) 2008 Atmel Corporation
4
* See file CREDITS for list of people who contributed to this
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.
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.
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,
25
#include <asm/arch/memory-map.h>
26
#include <asm/arch/gpio.h>
28
void portmux_select_peripheral(void *port, unsigned long pin_mask,
29
enum portmux_function func, unsigned long flags)
31
/* Both pull-up and pull-down set means buskeeper */
32
if (flags & PORTMUX_PULL_DOWN)
33
gpio_writel(port, PDERS, pin_mask);
35
gpio_writel(port, PDERC, pin_mask);
36
if (flags & PORTMUX_PULL_UP)
37
gpio_writel(port, PUERS, pin_mask);
39
gpio_writel(port, PUERC, pin_mask);
41
/* Select drive strength */
42
if (flags & PORTMUX_DRIVE_LOW)
43
gpio_writel(port, ODCR0S, pin_mask);
45
gpio_writel(port, ODCR0C, pin_mask);
46
if (flags & PORTMUX_DRIVE_HIGH)
47
gpio_writel(port, ODCR1S, pin_mask);
49
gpio_writel(port, ODCR1C, pin_mask);
52
if (func & PORTMUX_FUNC_B)
53
gpio_writel(port, PMR0S, pin_mask);
55
gpio_writel(port, PMR0C, pin_mask);
56
if (func & PORTMUX_FUNC_C)
57
gpio_writel(port, PMR1S, pin_mask);
59
gpio_writel(port, PMR1C, pin_mask);
61
/* Disable GPIO (i.e. enable peripheral) */
62
gpio_writel(port, GPERC, pin_mask);
65
void portmux_select_gpio(void *port, unsigned long pin_mask,
68
/* Both pull-up and pull-down set means buskeeper */
69
if (flags & PORTMUX_PULL_DOWN)
70
gpio_writel(port, PDERS, pin_mask);
72
gpio_writel(port, PDERC, pin_mask);
73
if (flags & PORTMUX_PULL_UP)
74
gpio_writel(port, PUERS, pin_mask);
76
gpio_writel(port, PUERC, pin_mask);
78
/* Enable open-drain mode if requested */
79
if (flags & PORTMUX_OPEN_DRAIN)
80
gpio_writel(port, ODMERS, pin_mask);
82
gpio_writel(port, ODMERC, pin_mask);
84
/* Select drive strength */
85
if (flags & PORTMUX_DRIVE_LOW)
86
gpio_writel(port, ODCR0S, pin_mask);
88
gpio_writel(port, ODCR0C, pin_mask);
89
if (flags & PORTMUX_DRIVE_HIGH)
90
gpio_writel(port, ODCR1S, pin_mask);
92
gpio_writel(port, ODCR1C, pin_mask);
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);
99
gpio_writel(port, OVRC, pin_mask);
100
gpio_writel(port, ODERS, pin_mask);
102
gpio_writel(port, ODERC, pin_mask);
106
gpio_writel(port, GPERS, pin_mask);