blob: 7b5c97d0fc30474def4a71119d4f93dbb7f79b7b [file] [log] [blame]
John Rigbya3f9d652011-04-19 10:42:40 +00001/*
2 * Copyright (C) ST-Ericsson SA 2009
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
23#ifndef _UX500_GPIO_h
24#define _UX500_GPIO_h
25
26#include <asm/types.h>
27#include <asm/io.h>
28#include <asm/errno.h>
29
30#include <asm/arch/sys_proto.h>
31#include <asm/arch/u8500.h>
32
33#define GPIO_TOTAL_PINS 268
34
35#define GPIO_PINS_PER_BLOCK 32
36#define GPIO_BLOCKS_COUNT (GPIO_TOTAL_PINS/GPIO_PINS_PER_BLOCK + 1)
37#define GPIO_BLOCK(pin) (((pin + GPIO_PINS_PER_BLOCK) >> 5) - 1)
38
39
40struct gpio_register {
Wolfgang Denk99763352011-06-02 23:18:32 +020041 u32 gpio_dat; /* data register : 0x000 */
42 u32 gpio_dats; /* data Set register : 0x004 */
43 u32 gpio_datc; /* data Clear register : 0x008 */
44 u32 gpio_pdis; /* Pull disable register : 0x00C */
45 u32 gpio_dir; /* data direction register : 0x010 */
46 u32 gpio_dirs; /* data dir Set register : 0x014 */
47 u32 gpio_dirc; /* data dir Clear register : 0x018 */
48 u32 gpio_slpm; /* Sleep mode register : 0x01C */
49 u32 gpio_afsa; /* AltFun A Select reg : 0x020 */
50 u32 gpio_afsb; /* AltFun B Select reg : 0x024 */
51 u32 gpio_lowemi;/* low EMI Select reg : 0x028 */
John Rigbya3f9d652011-04-19 10:42:40 +000052 u32 reserved_1[(0x040 - 0x02C) >> 2]; /*0x028-0x3C Reserved*/
Wolfgang Denk99763352011-06-02 23:18:32 +020053 u32 gpio_rimsc; /* rising edge intr set/clear : 0x040 */
54 u32 gpio_fimsc; /* falling edge intr set/clear register : 0x044 */
55 u32 gpio_mis; /* masked interrupt status register : 0x048 */
56 u32 gpio_ic; /* Interrupt Clear register : 0x04C */
57 u32 gpio_rwimsc;/* Rising-edge Wakeup IMSC register : 0x050 */
58 u32 gpio_fwimsc;/* Falling-edge Wakeup IMSC register : 0x054 */
59 u32 gpio_wks; /* Wakeup Status register : 0x058 */
John Rigbya3f9d652011-04-19 10:42:40 +000060};
61
62/* Error values returned by functions */
63enum gpio_error {
64 GPIO_OK = 0,
65 GPIO_UNSUPPORTED_HW = -2,
66 GPIO_UNSUPPORTED_FEATURE = -3,
67 GPIO_INVALID_PARAMETER = -4,
68 GPIO_REQUEST_NOT_APPLICABLE = -5,
69 GPIO_REQUEST_PENDING = -6,
70 GPIO_NOT_CONFIGURED = -7,
71 GPIO_INTERNAL_ERROR = -8,
72 GPIO_INTERNAL_EVENT = 1,
73 GPIO_REMAINING_EVENT = 2,
74 GPIO_NO_MORE_PENDING_EVENT = 3,
75 GPIO_INVALID_CLIENT = -25,
76 GPIO_INVALID_PIN = -26,
77 GPIO_PIN_BUSY = -27,
78 GPIO_PIN_NOT_ALLOCATED = -28,
79 GPIO_WRONG_CLIENT = -29,
80 GPIO_UNSUPPORTED_ALTFUNC = -30,
81};
82
83/*GPIO DEVICE ID */
84enum gpio_device_id {
85 GPIO_DEVICE_ID_0,
86 GPIO_DEVICE_ID_1,
87 GPIO_DEVICE_ID_2,
88 GPIO_DEVICE_ID_3,
89 GPIO_DEVICE_ID_INVALID
90};
91
92/*
93 * Alternate Function:
94 * refered in altfun_table to pointout particular altfun to be enabled
95 * when using GPIO_ALT_FUNCTION A/B/C enable/disable operation
96 */
97enum gpio_alt_function {
98 GPIO_ALT_UART_0_MODEM,
99 GPIO_ALT_UART_0_NO_MODEM,
100 GPIO_ALT_UART_1,
101 GPIO_ALT_UART_2,
102 GPIO_ALT_I2C_0,
103 GPIO_ALT_I2C_1,
104 GPIO_ALT_I2C_2,
105 GPIO_ALT_I2C_3,
106 GPIO_ALT_MSP_0,
107 GPIO_ALT_MSP_1,
108 GPIO_ALT_MSP_2,
109 GPIO_ALT_MSP_3,
110 GPIO_ALT_MSP_4,
111 GPIO_ALT_MSP_5,
112 GPIO_ALT_SSP_0,
113 GPIO_ALT_SSP_1,
114 GPIO_ALT_MM_CARD0,
115 GPIO_ALT_SD_CARD0,
116 GPIO_ALT_DMA_0,
117 GPIO_ALT_DMA_1,
118 GPIO_ALT_HSI0,
119 GPIO_ALT_CCIR656_INPUT,
120 GPIO_ALT_CCIR656_OUTPUT,
121 GPIO_ALT_LCD_PANEL,
122 GPIO_ALT_MDIF,
123 GPIO_ALT_SDRAM,
124 GPIO_ALT_HAMAC_AUDIO_DBG,
125 GPIO_ALT_HAMAC_VIDEO_DBG,
126 GPIO_ALT_CLOCK_RESET,
127 GPIO_ALT_TSP,
128 GPIO_ALT_IRDA,
129 GPIO_ALT_USB_MINIMUM,
130 GPIO_ALT_USB_I2C,
131 GPIO_ALT_OWM,
132 GPIO_ALT_PWL,
133 GPIO_ALT_FSMC,
134 GPIO_ALT_COMP_FLASH,
135 GPIO_ALT_SRAM_NOR_FLASH,
136 GPIO_ALT_FSMC_ADDLINE_0_TO_15,
137 GPIO_ALT_SCROLL_KEY,
138 GPIO_ALT_MSHC,
139 GPIO_ALT_HPI,
140 GPIO_ALT_USB_OTG,
141 GPIO_ALT_SDIO,
142 GPIO_ALT_HSMMC,
143 GPIO_ALT_FSMC_ADD_DATA_0_TO_25,
144 GPIO_ALT_HSI1,
145 GPIO_ALT_NOR,
146 GPIO_ALT_NAND,
147 GPIO_ALT_KEYPAD,
148 GPIO_ALT_VPIP,
149 GPIO_ALT_CAM,
150 GPIO_ALT_CCP1,
151 GPIO_ALT_EMMC,
152 GPIO_ALT_POP_EMMC,
153 GPIO_ALT_FUNMAX /* Add new alt func before this */
154};
155
156/* Defines pin assignment(Software mode or Alternate mode) */
157enum gpio_mode {
158 GPIO_MODE_LEAVE_UNCHANGED, /* Parameter will be ignored */
159 GPIO_MODE_SOFTWARE, /* Pin connected to GPIO (SW controlled) */
160 GPIO_ALTF_A, /* Pin connected to altfunc 1 (HW periph 1) */
161 GPIO_ALTF_B, /* Pin connected to altfunc 2 (HW periph 2) */
162 GPIO_ALTF_C, /* Pin connected to altfunc 3 (HW periph 3) */
163 GPIO_ALTF_FIND, /* Pin connected to altfunc 3 (HW periph 3) */
164 GPIO_ALTF_DISABLE /* Pin connected to altfunc 3 (HW periph 3) */
165};
166
167/* Defines GPIO pin direction */
168enum gpio_direction {
169 GPIO_DIR_LEAVE_UNCHANGED, /* Parameter will be ignored */
170 GPIO_DIR_INPUT, /* GPIO set as input */
171 GPIO_DIR_OUTPUT /* GPIO set as output */
172};
173
174/* Interrupt trigger mode */
175enum gpio_trig {
176 GPIO_TRIG_LEAVE_UNCHANGED, /* Parameter will be ignored */
177 GPIO_TRIG_DISABLE, /* Trigger no IT */
178 GPIO_TRIG_RISING_EDGE, /* Trigger an IT on rising edge */
179 GPIO_TRIG_FALLING_EDGE, /* Trigger an IT on falling edge */
180 GPIO_TRIG_BOTH_EDGES, /* Trigger an IT on rising and falling edge */
181 GPIO_TRIG_HIGH_LEVEL, /* Trigger an IT on high level */
182 GPIO_TRIG_LOW_LEVEL /* Trigger an IT on low level */
183};
184
185/* Configuration parameters for one GPIO pin.*/
186struct gpio_config {
187 enum gpio_mode mode;
188 enum gpio_direction direction;
189 enum gpio_trig trig;
190 char *dev_name; /* Who owns the gpio pin */
191};
192
193/* GPIO pin data*/
194enum gpio_data {
195 GPIO_DATA_LOW,
196 GPIO_DATA_HIGH
197};
198
199/* GPIO behaviour in sleep mode */
200enum gpio_sleep_mode {
201 GPIO_SLEEP_MODE_LEAVE_UNCHANGED, /* Parameter will be ignored */
202 GPIO_SLEEP_MODE_INPUT_DEFAULTVOLT, /* GPIO is an input with pull
203 up/down enabled when in sleep
204 mode. */
205 GPIO_SLEEP_MODE_CONTROLLED_BY_GPIO /* GPIO pin is controlled by
206 GPIO IP. So mode, direction
207 and data values for GPIO pin
208 in sleep mode are determined
209 by configuration set to GPIO
210 pin before entering to sleep
211 mode. */
212};
213
214/* GPIO ability to wake the system up from sleep mode.*/
215enum gpio_wake {
216 GPIO_WAKE_LEAVE_UNCHANGED, /* Parameter will be ignored */
217 GPIO_WAKE_DISABLE, /* No wake of system from sleep mode. */
218 GPIO_WAKE_LOW_LEVEL, /* Wake the system up on a LOW level. */
219 GPIO_WAKE_HIGH_LEVEL, /* Wake the system up on a HIGH level. */
220 GPIO_WAKE_RISING_EDGE, /* Wake the system up on a RISING edge. */
221 GPIO_WAKE_FALLING_EDGE, /* Wake the system up on a FALLING edge. */
222 GPIO_WAKE_BOTH_EDGES /* Wake the system up on both RISE and FALL. */
223};
224
225/* Configuration parameters for one GPIO pin in sleep mode.*/
226struct gpio_sleep_config {
227 enum gpio_sleep_mode sleep_mode;/* GPIO behaviour in sleep mode. */
228 enum gpio_wake wake; /* GPIO ability to wake up system. */
229};
230
231extern int gpio_setpinconfig(int pin_id, struct gpio_config *pin_config);
232extern int gpio_resetpinconfig(int pin_id, char *dev_name);
233extern int gpio_writepin(int pin_id, enum gpio_data value, char *dev_name);
234extern int gpio_readpin(int pin_id, enum gpio_data *value);
235extern int gpio_altfuncenable(enum gpio_alt_function altfunc,
236 char *dev_name);
237extern int gpio_altfuncdisable(enum gpio_alt_function altfunc,
238 char *dev_name);
239
240struct gpio_altfun_data {
241 u16 altfun;
242 u16 start;
243 u16 end;
244 u16 cont;
245 u8 type;
246};
247#endif