blob: 5b44d05ca53e8a6f89b0e5d9c0e80cb095527309 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Robin Getz96f10502009-09-24 14:11:24 +00002 * Copyright 2006-2009 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -07003 *
Robin Getz96f10502009-09-24 14:11:24 +00004 * Licensed under the GPL-2 or later.
Bryan Wu1394f032007-05-06 14:50:22 -07005 */
6
Bryan Wu1394f032007-05-06 14:50:22 -07007#ifndef __ARCH_BLACKFIN_GPIO_H__
8#define __ARCH_BLACKFIN_GPIO_H__
9
Michael Hennericha4f0b32c2008-11-18 17:48:22 +080010#define gpio_bank(x) ((x) >> 4)
11#define gpio_bit(x) (1<<((x) & 0xF))
12#define gpio_sub_n(x) ((x) & 0xF)
Bryan Wu1394f032007-05-06 14:50:22 -070013
Bryan Wu2e8ca592008-11-18 17:48:22 +080014#define GPIO_BANKSIZE 16
15#define GPIO_BANK_NUM DIV_ROUND_UP(MAX_BLACKFIN_GPIOS, GPIO_BANKSIZE)
Bryan Wu1394f032007-05-06 14:50:22 -070016
Michael Hennerich983e1012009-01-07 23:14:39 +080017#include <mach/gpio.h>
18
Bryan Wu1394f032007-05-06 14:50:22 -070019#define GPIO_0 0
20#define GPIO_1 1
21#define GPIO_2 2
22#define GPIO_3 3
23#define GPIO_4 4
24#define GPIO_5 5
25#define GPIO_6 6
26#define GPIO_7 7
27#define GPIO_8 8
28#define GPIO_9 9
29#define GPIO_10 10
30#define GPIO_11 11
31#define GPIO_12 12
32#define GPIO_13 13
33#define GPIO_14 14
34#define GPIO_15 15
35#define GPIO_16 16
36#define GPIO_17 17
37#define GPIO_18 18
38#define GPIO_19 19
39#define GPIO_20 20
40#define GPIO_21 21
41#define GPIO_22 22
42#define GPIO_23 23
43#define GPIO_24 24
44#define GPIO_25 25
45#define GPIO_26 26
46#define GPIO_27 27
47#define GPIO_28 28
48#define GPIO_29 29
49#define GPIO_30 30
50#define GPIO_31 31
51#define GPIO_32 32
52#define GPIO_33 33
53#define GPIO_34 34
54#define GPIO_35 35
55#define GPIO_36 36
56#define GPIO_37 37
57#define GPIO_38 38
58#define GPIO_39 39
59#define GPIO_40 40
60#define GPIO_41 41
61#define GPIO_42 42
62#define GPIO_43 43
63#define GPIO_44 44
64#define GPIO_45 45
65#define GPIO_46 46
66#define GPIO_47 47
67
Bryan Wu1394f032007-05-06 14:50:22 -070068#define PERIPHERAL_USAGE 1
69#define GPIO_USAGE 0
70
Bryan Wu1394f032007-05-06 14:50:22 -070071#ifndef __ASSEMBLY__
72
73/***********************************************************
74*
75* FUNCTIONS: Blackfin General Purpose Ports Access Functions
76*
77* INPUTS/OUTPUTS:
78* gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
79*
80*
81* DESCRIPTION: These functions abstract direct register access
82* to Blackfin processor General Purpose
83* Ports Regsiters
84*
85* CAUTION: These functions do not belong to the GPIO Driver API
86*************************************************************
87* MODIFICATION HISTORY :
88**************************************************************/
89
Mike Frysinger269647d2009-03-28 20:32:57 +080090#ifndef CONFIG_BF54x
Michael Hennericha2c8cfe2008-01-22 17:20:10 +080091void set_gpio_dir(unsigned, unsigned short);
92void set_gpio_inen(unsigned, unsigned short);
93void set_gpio_polar(unsigned, unsigned short);
94void set_gpio_edge(unsigned, unsigned short);
95void set_gpio_both(unsigned, unsigned short);
96void set_gpio_data(unsigned, unsigned short);
97void set_gpio_maska(unsigned, unsigned short);
98void set_gpio_maskb(unsigned, unsigned short);
99void set_gpio_toggle(unsigned);
100void set_gpiop_dir(unsigned, unsigned short);
101void set_gpiop_inen(unsigned, unsigned short);
102void set_gpiop_polar(unsigned, unsigned short);
103void set_gpiop_edge(unsigned, unsigned short);
104void set_gpiop_both(unsigned, unsigned short);
105void set_gpiop_data(unsigned, unsigned short);
106void set_gpiop_maska(unsigned, unsigned short);
107void set_gpiop_maskb(unsigned, unsigned short);
108unsigned short get_gpio_dir(unsigned);
109unsigned short get_gpio_inen(unsigned);
110unsigned short get_gpio_polar(unsigned);
111unsigned short get_gpio_edge(unsigned);
112unsigned short get_gpio_both(unsigned);
113unsigned short get_gpio_maska(unsigned);
114unsigned short get_gpio_maskb(unsigned);
115unsigned short get_gpio_data(unsigned);
116unsigned short get_gpiop_dir(unsigned);
117unsigned short get_gpiop_inen(unsigned);
118unsigned short get_gpiop_polar(unsigned);
119unsigned short get_gpiop_edge(unsigned);
120unsigned short get_gpiop_both(unsigned);
121unsigned short get_gpiop_maska(unsigned);
122unsigned short get_gpiop_maskb(unsigned);
123unsigned short get_gpiop_data(unsigned);
Bryan Wu1394f032007-05-06 14:50:22 -0700124
125struct gpio_port_t {
126 unsigned short data;
127 unsigned short dummy1;
128 unsigned short data_clear;
129 unsigned short dummy2;
130 unsigned short data_set;
131 unsigned short dummy3;
132 unsigned short toggle;
133 unsigned short dummy4;
134 unsigned short maska;
135 unsigned short dummy5;
136 unsigned short maska_clear;
137 unsigned short dummy6;
138 unsigned short maska_set;
139 unsigned short dummy7;
140 unsigned short maska_toggle;
141 unsigned short dummy8;
142 unsigned short maskb;
143 unsigned short dummy9;
144 unsigned short maskb_clear;
145 unsigned short dummy10;
146 unsigned short maskb_set;
147 unsigned short dummy11;
148 unsigned short maskb_toggle;
149 unsigned short dummy12;
150 unsigned short dir;
151 unsigned short dummy13;
152 unsigned short polar;
153 unsigned short dummy14;
154 unsigned short edge;
155 unsigned short dummy15;
156 unsigned short both;
157 unsigned short dummy16;
158 unsigned short inen;
159};
Roy Huang24a07a12007-07-12 22:41:45 +0800160#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700161
162#ifdef CONFIG_PM
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800163
164unsigned int bfin_pm_standby_setup(void);
165void bfin_pm_standby_restore(void);
166
167void bfin_gpio_pm_hibernate_restore(void);
168void bfin_gpio_pm_hibernate_suspend(void);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800169
170#ifndef CONFIG_BF54x
Bryan Wu1394f032007-05-06 14:50:22 -0700171#define PM_WAKE_RISING 0x1
172#define PM_WAKE_FALLING 0x2
173#define PM_WAKE_HIGH 0x4
174#define PM_WAKE_LOW 0x8
175#define PM_WAKE_BOTH_EDGES (PM_WAKE_RISING | PM_WAKE_FALLING)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800176#define PM_WAKE_IGNORE 0xF0
Bryan Wu1394f032007-05-06 14:50:22 -0700177
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800178int gpio_pm_wakeup_request(unsigned gpio, unsigned char type);
179void gpio_pm_wakeup_free(unsigned gpio);
Bryan Wu1394f032007-05-06 14:50:22 -0700180
181struct gpio_port_s {
182 unsigned short data;
Bryan Wu1394f032007-05-06 14:50:22 -0700183 unsigned short maska;
Bryan Wu1394f032007-05-06 14:50:22 -0700184 unsigned short maskb;
Bryan Wu1394f032007-05-06 14:50:22 -0700185 unsigned short dir;
186 unsigned short polar;
187 unsigned short edge;
188 unsigned short both;
189 unsigned short inen;
190
191 unsigned short fer;
Michael Hennerich581d62a2007-06-14 13:30:23 +0800192 unsigned short reserved;
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800193 unsigned short mux;
Bryan Wu1394f032007-05-06 14:50:22 -0700194};
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800195#endif /*CONFIG_BF54x*/
Bryan Wu1394f032007-05-06 14:50:22 -0700196#endif /*CONFIG_PM*/
Bryan Wu1394f032007-05-06 14:50:22 -0700197/***********************************************************
198*
199* FUNCTIONS: Blackfin GPIO Driver
200*
201* INPUTS/OUTPUTS:
202* gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
203*
204*
205* DESCRIPTION: Blackfin GPIO Driver API
206*
207* CAUTION:
208*************************************************************
209* MODIFICATION HISTORY :
210**************************************************************/
211
Michael Hennericha4f0b32c2008-11-18 17:48:22 +0800212int bfin_gpio_request(unsigned gpio, const char *label);
213void bfin_gpio_free(unsigned gpio);
Graf Yang9570ff42009-01-07 23:14:38 +0800214int bfin_gpio_irq_request(unsigned gpio, const char *label);
215void bfin_gpio_irq_free(unsigned gpio);
Michael Hennericha4f0b32c2008-11-18 17:48:22 +0800216int bfin_gpio_direction_input(unsigned gpio);
217int bfin_gpio_direction_output(unsigned gpio, int value);
218int bfin_gpio_get_value(unsigned gpio);
219void bfin_gpio_set_value(unsigned gpio, int value);
Bryan Wu1394f032007-05-06 14:50:22 -0700220
Michael Hennericha4f0b32c2008-11-18 17:48:22 +0800221#ifdef CONFIG_GPIOLIB
222#include <asm-generic/gpio.h> /* cansleep wrappers */
223
224static inline int gpio_get_value(unsigned int gpio)
225{
226 if (gpio < MAX_BLACKFIN_GPIOS)
227 return bfin_gpio_get_value(gpio);
228 else
229 return __gpio_get_value(gpio);
230}
231
232static inline void gpio_set_value(unsigned int gpio, int value)
233{
234 if (gpio < MAX_BLACKFIN_GPIOS)
235 bfin_gpio_set_value(gpio, value);
236 else
237 __gpio_set_value(gpio, value);
238}
239
240static inline int gpio_cansleep(unsigned int gpio)
241{
242 return __gpio_cansleep(gpio);
243}
244
245#else /* !CONFIG_GPIOLIB */
246
247static inline int gpio_request(unsigned gpio, const char *label)
248{
249 return bfin_gpio_request(gpio, label);
250}
251
252static inline void gpio_free(unsigned gpio)
253{
254 return bfin_gpio_free(gpio);
255}
256
257static inline int gpio_direction_input(unsigned gpio)
258{
259 return bfin_gpio_direction_input(gpio);
260}
261
262static inline int gpio_direction_output(unsigned gpio, int value)
263{
264 return bfin_gpio_direction_output(gpio, value);
265}
266
267static inline int gpio_get_value(unsigned gpio)
268{
269 return bfin_gpio_get_value(gpio);
270}
271
272static inline void gpio_set_value(unsigned gpio, int value)
273{
274 return bfin_gpio_set_value(gpio, value);
275}
Bryan Wu1394f032007-05-06 14:50:22 -0700276
Michael Hennerich301af292007-07-24 15:35:53 +0800277#include <asm-generic/gpio.h> /* cansleep wrappers */
Michael Hennericha4f0b32c2008-11-18 17:48:22 +0800278#endif /* !CONFIG_GPIOLIB */
Michael Hennerich301af292007-07-24 15:35:53 +0800279#include <asm/irq.h>
280
281static inline int gpio_to_irq(unsigned gpio)
282{
Michael Henneriche1312bf2009-03-28 21:18:45 +0800283 if (likely(gpio < MAX_BLACKFIN_GPIOS))
284 return gpio + GPIO_IRQ_BASE;
285
286 return -EINVAL;
Michael Hennerich301af292007-07-24 15:35:53 +0800287}
288
289static inline int irq_to_gpio(unsigned irq)
290{
291 return (irq - GPIO_IRQ_BASE);
292}
293
Bryan Wu1394f032007-05-06 14:50:22 -0700294#endif /* __ASSEMBLY__ */
295
296#endif /* __ARCH_BLACKFIN_GPIO_H__ */