blob: a29f94e3ba4648b02b19515023a2660d2c69822b [file] [log] [blame]
Haavard Skinnemoenab0df362008-08-29 21:09:49 +02001/*
2 * Copyright (C) 2006, 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>
25#include <asm/arch/memory-map.h>
26#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 if (flags & PORTMUX_PULL_UP)
32 pio_writel(port, PUER, pin_mask);
33 else
34 pio_writel(port, PUDR, pin_mask);
35
36 switch (func) {
37 case PORTMUX_FUNC_A:
38 pio_writel(port, ASR, pin_mask);
39 break;
40 case PORTMUX_FUNC_B:
41 pio_writel(port, BSR, pin_mask);
42 break;
43 }
44
45 pio_writel(port, PDR, pin_mask);
46}
47
48void portmux_select_gpio(void *port, unsigned long pin_mask,
49 unsigned long flags)
50{
51 if (flags & PORTMUX_PULL_UP)
52 pio_writel(port, PUER, pin_mask);
53 else
54 pio_writel(port, PUDR, pin_mask);
55
56 if (flags & PORTMUX_OPEN_DRAIN)
57 pio_writel(port, MDER, pin_mask);
58 else
59 pio_writel(port, MDDR, pin_mask);
60
61 if (flags & PORTMUX_DIR_OUTPUT) {
62 if (flags & PORTMUX_INIT_HIGH)
63 pio_writel(port, SODR, pin_mask);
64 else
65 pio_writel(port, CODR, pin_mask);
66 pio_writel(port, OER, pin_mask);
67 } else {
68 pio_writel(port, ODR, pin_mask);
69 }
70
71 pio_writel(port, PER, pin_mask);
72}
73
74void pio_set_output_value(unsigned int pin, int value)
75{
76 void *port = pio_pin_to_port(pin);
77
78 if (!port)
79 panic("Invalid GPIO pin %u\n", pin);
80
81 __pio_set_output_value(port, pin & 0x1f, value);
82}
83
84int pio_get_input_value(unsigned int pin)
85{
86 void *port = pio_pin_to_port(pin);
87
88 if (!port)
89 panic("Invalid GPIO pin %u\n", pin);
90
91 return __pio_get_input_value(port, pin & 0x1f);
92}