1/*
2 * @TAG(OTHER_GPL)
3 */
4
5/*
6 * Copyright (C) 2011
7 * Stefano Babic, DENX Software Engineering, <sbabic@denx.de>
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28#pragma once
29
30#include <platsupport/io.h>
31
32/*
33 * Copyright (C) 2011
34 * Stefano Babic, DENX Software Engineering, <sbabic@denx.de>
35 *
36 * See file CREDITS for list of people who contributed to this
37 * project.
38 *
39 * This program is free software; you can redistribute it and/or
40 * modify it under the terms of the GNU General Public License as
41 * published by the Free Software Foundation; either version 2 of
42 * the License, or (at your option) any later version.
43 *
44 * This program is distributed in the hope that it will be useful,
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47 * GNU General Public License for more details.
48 *
49 * You should have received a copy of the GNU General Public License
50 * along with this program; if not, write to the Free Software
51 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
52 * MA 02111-1307 USA
53 */
54
55#ifndef __ASM_ARCH_IMX_GPIO_H
56#define __ASM_ARCH_IMX_GPIO_H
57
58#if !(defined(__KERNEL_STRICT_NAMES) || defined(__ASSEMBLY__))
59#include <stdint.h>
60/* GPIO registers */
61struct gpio_regs {
62	uint32_t gpio_dr;	/* data */
63	uint32_t gpio_dir;	/* direction */
64	uint32_t gpio_psr;	/* pad satus */
65};
66#endif
67
68#define IMX_GPIO_NR(port, index)		((((port)-1)*32)+((index)&31))
69
70#endif
71
72/*
73 * Copyright (c) 2011 The Chromium OS Authors.
74 * Copyright (c) 2011, NVIDIA Corp. All rights reserved.
75 * See file CREDITS for list of people who contributed to this
76 * project.
77 *
78 * This program is free software; you can redistribute it and/or
79 * modify it under the terms of the GNU General Public License as
80 * published by the Free Software Foundation; either version 2 of
81 * the License, or (at your option) any later version.
82 *
83 * This program is distributed in the hope that it will be useful,
84 * but WITHOUT ANY WARRANTY; without even the implied warranty of
85 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
86 * GNU General Public License for more details.
87 *
88 * You should have received a copy of the GNU General Public License
89 * along with this program; if not, write to the Free Software
90 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
91 * MA 02111-1307 USA
92 */
93
94#ifndef _ASM_GENERIC_GPIO_H_
95#define _ASM_GENERIC_GPIO_H_
96
97/*
98 * Generic GPIO API for U-Boot
99 *
100 * GPIOs are numbered from 0 to GPIO_COUNT-1 which value is defined
101 * by the SOC/architecture.
102 *
103 * Each GPIO can be an input or output. If an input then its value can
104 * be read as 0 or 1. If an output then its value can be set to 0 or 1.
105 * If you try to write an input then the value is undefined. If you try
106 * to read an output, barring something very unusual,  you will get
107 * back the value of the output that you previously set.
108 *
109 * In some cases the operation may fail, for example if the GPIO number
110 * is out of range, or the GPIO is not available because its pin is
111 * being used by another function. In that case, functions may return
112 * an error value of -1.
113 */
114
115/**
116 * Request ownership of a GPIO.
117 *
118 * @param gpio	GPIO number
119 * @param label	Name given to the GPIO
120 * @return 0 if ok, -1 on error
121 */
122int gpio_request(unsigned gpio, const char *label);
123
124/**
125 * Stop using the GPIO.  This function should not alter pin configuration.
126 *
127 * @param gpio	GPIO number
128 * @return 0 if ok, -1 on error
129 */
130int gpio_free(unsigned gpio);
131
132/**
133 * Make a GPIO an input.
134 *
135 * @param gpio	GPIO number
136 * @return 0 if ok, -1 on error
137 */
138int gpio_direction_input(unsigned gpio, ps_io_ops_t *io_ops);
139
140/**
141 * Make a GPIO an output, and set its value.
142 *
143 * @param gpio	GPIO number
144 * @param value	GPIO value (0 for low or 1 for high)
145 * @return 0 if ok, -1 on error
146 */
147int gpio_direction_output(unsigned gpio, int value, ps_io_ops_t *io_ops);
148
149/**
150 * Get a GPIO's value. This will work whether the GPIO is an input
151 * or an output.
152 *
153 * @param gpio	GPIO number
154 * @return 0 if low, 1 if high, -1 on error
155 */
156int gpio_get_value(unsigned gpio);
157
158/**
159 * Set an output GPIO's value. The GPIO must already be an output or
160 * this function may have no effect.
161 *
162 * @param gpio	GPIO number
163 * @param value	GPIO value (0 for low or 1 for high)
164 * @return 0 if ok, -1 on error
165 */
166int gpio_set_value(unsigned gpio, int value);
167
168/**
169 * Request a gpio. This should be called before any of the other functions
170 * are used on this gpio.
171 *
172 * @param gp	GPIO number
173 * @param label	User label for this GPIO
174 * @return 0 if ok, -1 on error
175 */
176int gpio_request(unsigned gpio, const char *label);
177#endif	/* _ASM_GENERIC_GPIO_H_ */
178
179