• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006-2009 Analog Devices Inc.
3  *
4  * Licensed under the GPL-2 or later.
5  */
6 
7 #ifndef __ARCH_BLACKFIN_GPIO_H__
8 #define __ARCH_BLACKFIN_GPIO_H__
9 
10 #define gpio_bank(x)	((x) >> 4)
11 #define gpio_bit(x)	(1<<((x) & 0xF))
12 #define gpio_sub_n(x)	((x) & 0xF)
13 
14 #define GPIO_BANKSIZE	16
15 #define GPIO_BANK_NUM	DIV_ROUND_UP(MAX_BLACKFIN_GPIOS, GPIO_BANKSIZE)
16 
17 #include <mach/gpio.h>
18 
19 #define PERIPHERAL_USAGE 1
20 #define GPIO_USAGE 0
21 
22 #ifndef BFIN_GPIO_PINT
23 # define BFIN_GPIO_PINT 0
24 #endif
25 
26 #ifndef __ASSEMBLY__
27 
28 #ifndef CONFIG_PINCTRL
29 
30 #include <linux/compiler.h>
31 #include <asm/blackfin.h>
32 #include <asm/portmux.h>
33 #include <asm/irq_handler.h>
34 
35 /***********************************************************
36 *
37 * FUNCTIONS: Blackfin General Purpose Ports Access Functions
38 *
39 * INPUTS/OUTPUTS:
40 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
41 *
42 *
43 * DESCRIPTION: These functions abstract direct register access
44 *              to Blackfin processor General Purpose
45 *              Ports Regsiters
46 *
47 * CAUTION: These functions do not belong to the GPIO Driver API
48 *************************************************************
49 * MODIFICATION HISTORY :
50 **************************************************************/
51 
52 void set_gpio_dir(unsigned, unsigned short);
53 void set_gpio_inen(unsigned, unsigned short);
54 void set_gpio_polar(unsigned, unsigned short);
55 void set_gpio_edge(unsigned, unsigned short);
56 void set_gpio_both(unsigned, unsigned short);
57 void set_gpio_data(unsigned, unsigned short);
58 void set_gpio_maska(unsigned, unsigned short);
59 void set_gpio_maskb(unsigned, unsigned short);
60 void set_gpio_toggle(unsigned);
61 void set_gpiop_dir(unsigned, unsigned short);
62 void set_gpiop_inen(unsigned, unsigned short);
63 void set_gpiop_polar(unsigned, unsigned short);
64 void set_gpiop_edge(unsigned, unsigned short);
65 void set_gpiop_both(unsigned, unsigned short);
66 void set_gpiop_data(unsigned, unsigned short);
67 void set_gpiop_maska(unsigned, unsigned short);
68 void set_gpiop_maskb(unsigned, unsigned short);
69 unsigned short get_gpio_dir(unsigned);
70 unsigned short get_gpio_inen(unsigned);
71 unsigned short get_gpio_polar(unsigned);
72 unsigned short get_gpio_edge(unsigned);
73 unsigned short get_gpio_both(unsigned);
74 unsigned short get_gpio_maska(unsigned);
75 unsigned short get_gpio_maskb(unsigned);
76 unsigned short get_gpio_data(unsigned);
77 unsigned short get_gpiop_dir(unsigned);
78 unsigned short get_gpiop_inen(unsigned);
79 unsigned short get_gpiop_polar(unsigned);
80 unsigned short get_gpiop_edge(unsigned);
81 unsigned short get_gpiop_both(unsigned);
82 unsigned short get_gpiop_maska(unsigned);
83 unsigned short get_gpiop_maskb(unsigned);
84 unsigned short get_gpiop_data(unsigned);
85 
86 struct gpio_port_t {
87 	unsigned short data;
88 	unsigned short dummy1;
89 	unsigned short data_clear;
90 	unsigned short dummy2;
91 	unsigned short data_set;
92 	unsigned short dummy3;
93 	unsigned short toggle;
94 	unsigned short dummy4;
95 	unsigned short maska;
96 	unsigned short dummy5;
97 	unsigned short maska_clear;
98 	unsigned short dummy6;
99 	unsigned short maska_set;
100 	unsigned short dummy7;
101 	unsigned short maska_toggle;
102 	unsigned short dummy8;
103 	unsigned short maskb;
104 	unsigned short dummy9;
105 	unsigned short maskb_clear;
106 	unsigned short dummy10;
107 	unsigned short maskb_set;
108 	unsigned short dummy11;
109 	unsigned short maskb_toggle;
110 	unsigned short dummy12;
111 	unsigned short dir;
112 	unsigned short dummy13;
113 	unsigned short polar;
114 	unsigned short dummy14;
115 	unsigned short edge;
116 	unsigned short dummy15;
117 	unsigned short both;
118 	unsigned short dummy16;
119 	unsigned short inen;
120 };
121 
122 #ifdef BFIN_SPECIAL_GPIO_BANKS
123 void bfin_special_gpio_free(unsigned gpio);
124 int bfin_special_gpio_request(unsigned gpio, const char *label);
125 # ifdef CONFIG_PM
126 void bfin_special_gpio_pm_hibernate_restore(void);
127 void bfin_special_gpio_pm_hibernate_suspend(void);
128 # endif
129 #endif
130 
131 #ifdef CONFIG_PM
132 void bfin_gpio_pm_hibernate_restore(void);
133 void bfin_gpio_pm_hibernate_suspend(void);
134 int bfin_gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl);
135 int bfin_gpio_pm_standby_ctrl(unsigned ctrl);
136 
bfin_pm_standby_setup(void)137 static inline int bfin_pm_standby_setup(void)
138 {
139 	return bfin_gpio_pm_standby_ctrl(1);
140 }
141 
bfin_pm_standby_restore(void)142 static inline void bfin_pm_standby_restore(void)
143 {
144 	bfin_gpio_pm_standby_ctrl(0);
145 }
146 
147 
148 struct gpio_port_s {
149 	unsigned short data;
150 	unsigned short maska;
151 	unsigned short maskb;
152 	unsigned short dir;
153 	unsigned short polar;
154 	unsigned short edge;
155 	unsigned short both;
156 	unsigned short inen;
157 
158 	unsigned short fer;
159 	unsigned short reserved;
160 	unsigned short mux;
161 };
162 #endif /*CONFIG_PM*/
163 
164 /***********************************************************
165 *
166 * FUNCTIONS: Blackfin GPIO Driver
167 *
168 * INPUTS/OUTPUTS:
169 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
170 *
171 *
172 * DESCRIPTION: Blackfin GPIO Driver API
173 *
174 * CAUTION:
175 *************************************************************
176 * MODIFICATION HISTORY :
177 **************************************************************/
178 int bfin_gpio_irq_request(unsigned gpio, const char *label);
179 void bfin_gpio_irq_free(unsigned gpio);
180 void bfin_gpio_irq_prepare(unsigned gpio);
181 
irq_to_gpio(unsigned irq)182 static inline int irq_to_gpio(unsigned irq)
183 {
184 	return irq - GPIO_IRQ_BASE;
185 }
186 #endif /* CONFIG_PINCTRL */
187 
188 #include <asm/irq.h>
189 #include <asm/errno.h>
190 
191 #include <asm-generic/gpio.h>		/* cansleep wrappers */
192 
gpio_get_value(unsigned int gpio)193 static inline int gpio_get_value(unsigned int gpio)
194 {
195 	return __gpio_get_value(gpio);
196 }
197 
gpio_set_value(unsigned int gpio,int value)198 static inline void gpio_set_value(unsigned int gpio, int value)
199 {
200 	__gpio_set_value(gpio, value);
201 }
202 
gpio_cansleep(unsigned int gpio)203 static inline int gpio_cansleep(unsigned int gpio)
204 {
205 	return __gpio_cansleep(gpio);
206 }
207 
gpio_to_irq(unsigned gpio)208 static inline int gpio_to_irq(unsigned gpio)
209 {
210 	return __gpio_to_irq(gpio);
211 }
212 #endif /* __ASSEMBLY__ */
213 
214 #endif /* __ARCH_BLACKFIN_GPIO_H__ */
215