]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - Documentation/arm/OMAP/gpio
Merge current mainline tree into linux-omap tree
[linux-2.6-omap-h63xx.git] / Documentation / arm / OMAP / gpio
1
2                          OMAP GPIO API's HowTo
3                          =====================
4
5 This document is a short summary how to use OMAP Linux GPIO API. It is
6 mainly focussed on OMAP5912 OSK, but should fit with extensions (more
7 or less GPIOs) to other OMAP processors as well.
8
9 If anything is missing, is wrong, needs extension or update, please send
10 update to Linux-omap-open-source@linux.omap.com.
11
12 I. GPIO Modules/Banks
13 ---------------------
14
15 OMAP5912 OSK has 64 GPIOs (general purpose IO pins). These are organized
16 in four modules (banks) with 16 pins each. OMAP GPIO API doesn't distinguish
17 between modules and numbers the pins from 0 - 63:
18
19 A) GPIO MODULE/BANK 0 - PIN  0-15
20 B) GPIO MODULE/BANK 1 - PIN 16-31
21 C) GPIO MODULE/BANK 2 - PIN 32-47
22 D) GPIO MODULE/BANK 3 - PIN 48-63
23
24 See
25
26 http://www-s.ti.com/sc/psheets/spru767a/spru767a.pdf
27
28 for more details.
29
30 II. GPIO API's
31 --------------
32
33 A) Include
34
35 #include <asm/arch/gpio.h>
36
37 B) omap_cfg_reg(xxxx);
38
39 Description: Configure pin mux.
40
41 Parameter: Pin to be configured for GPIO.
42
43 Note: This function may only be necessary for some GPIO pins. Because OMAP
44       chip itself has less real hardware pins than necessary to use all
45       its functionality at the same time, some pins share different
46       functions (called pin multiplexing, short pin mux). E.g. one pin may
47       be used for serial interface *or* GPIO. Check if this is the case for
48       the GPIO you want to use and if you have to configure the pin mux.
49
50 C) omap_request_gpio(int gpio)
51
52 Description: Request GPIO to be used.
53
54 Parameter: int gpio - GPIO PIN (Pin 0-63)
55
56 Note: Using this function, you dont have to worry about banks/modules where
57       the gpio pin is.
58
59 D) omap_set_gpio_direction(int gpio, int is_input)
60
61 Description: This function is responsible for setting the gpio pin direction
62              (input or output).
63
64 Parameter: int gpio - GPIO PIN (Pin 0-63)
65            int is_input - pin direction (0 = output, 1 = input)
66
67 E) omap_set_gpio_dataout(int gpio, int enable)
68
69 Description: This function is responsible for writing to a pin.
70
71 Parameter: int gpio - GPIO PIN (Pin 0-63)
72            int enable - pin value (0 or 1)
73
74 F) omap_get_gpio_datain(int gpio)
75
76 Description: This function is responsible for reading pin values.
77
78 Parameter: int gpio - GPIO PIN (Pin 0-63)
79
80 G) omap_free_gpio(int gpio)
81
82 Description: This function is responsible for freeing the pin used.
83
84 Parameter: int gpio - GPIO PIN (Pin 0-63)
85
86 H) OMAP_GPIO_IRQ(int gpio)
87
88 Description: Returns the Interrupt number for the specified gpio pin.
89
90 Parameter: int gpio - GPIO PIN (Pin 0-63)
91
92 I) set_irq_type(unsigned int irq, unsigned int type)
93
94 Description: This function is responsible for setting the type of interrupt
95              (RISING or FALLING).
96
97 Parameter: unsigned int irq - The interrupt number for the gpio pin.
98            unsigned int type - (IRQT_RISING = rising, IRQT_FALLING= falling)
99
100
101 III. Example
102 ------------
103
104 1) Writing to gpio pin#3 a value 1 and reading the value of gpio pin#3.
105
106 #include <asm/arch/gpio.h>
107
108 int ret;                       /* Return value */
109
110 omap_request_gpio(3);          /* Request for gpio pin */
111 omap_set_gpio_direction(3,0);
112 omap_set_set_dataout(3,1);     /* Writing a 1 to gpio pin # 3: */
113 ret = omap_get_datain(3);      /* Reading the value of pin # 3 */
114 printk("value of pin # 3 = %d\n",ret);
115 omap_free_gpio(3);             /* Freeing gpio pin # 3 */
116
117 2) Interrupt input by gpio pin#3
118
119 #include <asm/arch/gpio.h>
120
121 omap_request_gpio(3);         /* Request for gpio pin */
122 omap_set_gpio_direction(3,0);
123 set_irq_type(OMAP_GPIO_IRQ(3),IRQT_RISING); /* Setting up pin for interrupt */
124 request_irq(OMAP_GPIO_IRQ(3), (void *)&my_int_handler, SA_SHIRQ,....);
125
126 ...                         /* Do stuff, handle interrupts in my_int_handler */
127
128 free_irq(OMAP_GPIO_IRQ(3),&id); /*  Freeing interrupt and gpio pin */
129 omap_free_gpio(3);
130
131 ------------------------------------------------------------------
132 Last modified 14. August 2006
133 The OMAP Linux Kernel Team
134 Arnold <abo_gwapo@yahoo.com>
135 Dirk Behme <dirk.behme@gmail.com>
136
137                          OMAP GPIO API's HowTo
138                          =====================
139
140 This document is a short summary how to use OMAP Linux GPIO API. It is
141 mainly focussed on OMAP5912 OSK, but should fit with extensions (more
142 or less GPIOs) to other OMAP processors as well.
143
144 If anything is missing, is wrong, needs extension or update, please send
145 update to Linux-omap-open-source@linux.omap.com.
146
147 I. GPIO Modules/Banks
148 ---------------------
149
150 OMAP5912 OSK has 64 GPIOs (general purpose IO pins). These are organized
151 in four modules (banks) with 16 pins each. OMAP GPIO API doesn't distinguish
152 between modules and numbers the pins from 0 - 63:
153
154 A) GPIO MODULE/BANK 0 - PIN  0-15
155 B) GPIO MODULE/BANK 1 - PIN 16-31
156 C) GPIO MODULE/BANK 2 - PIN 32-47
157 D) GPIO MODULE/BANK 3 - PIN 48-63
158
159 See
160
161 http://www-s.ti.com/sc/psheets/spru767a/spru767a.pdf
162
163 for more details.
164
165 II. GPIO API's
166 --------------
167
168 A) Include
169
170 #include <asm/arch/gpio.h>
171
172 B) omap_cfg_reg(xxxx);
173
174 Description: Configure pin mux.
175
176 Parameter: Pin to be configured for GPIO.
177
178 Note: This function may only be necessary for some GPIO pins. Because OMAP
179       chip itself has less real hardware pins than necessary to use all
180       its functionality at the same time, some pins share different
181       functions (called pin multiplexing, short pin mux). E.g. one pin may
182       be used for serial interface *or* GPIO. Check if this is the case for
183       the GPIO you want to use and if you have to configure the pin mux.
184
185 C) omap_request_gpio(int gpio)
186
187 Description: Request GPIO to be used.
188
189 Parameter: int gpio - GPIO PIN (Pin 0-63)
190
191 Note: Using this function, you dont have to worry about banks/modules where
192       the gpio pin is.
193
194 D) omap_set_gpio_direction(int gpio, int is_input)
195
196 Description: This function is responsible for setting the gpio pin direction
197              (input or output).
198
199 Parameter: int gpio - GPIO PIN (Pin 0-63)
200            int is_input - pin direction (0 = output, 1 = input)
201
202 E) omap_set_gpio_dataout(int gpio, int enable)
203
204 Description: This function is responsible for writing to a pin.
205
206 Parameter: int gpio - GPIO PIN (Pin 0-63)
207            int enable - pin value (0 or 1)
208
209 F) omap_get_gpio_datain(int gpio)
210
211 Description: This function is responsible for reading pin values.
212
213 Parameter: int gpio - GPIO PIN (Pin 0-63)
214
215 G) omap_free_gpio(int gpio)
216
217 Description: This function is responsible for freeing the pin used.
218
219 Parameter: int gpio - GPIO PIN (Pin 0-63)
220
221 H) OMAP_GPIO_IRQ(int gpio)
222
223 Description: Returns the Interrupt number for the specified gpio pin.
224
225 Parameter: int gpio - GPIO PIN (Pin 0-63)
226
227 I) set_irq_type(unsigned int irq, unsigned int type)
228
229 Description: This function is responsible for setting the type of interrupt
230              (RISING or FALLING).
231
232 Parameter: unsigned int irq - The interrupt number for the gpio pin.
233            unsigned int type - (IRQT_RISING = rising, IRQT_FALLING= falling)
234
235
236 III. Example
237 ------------
238
239 1) Writing to gpio pin#3 a value 1 and reading the value of gpio pin#3.
240
241 #include <asm/arch/gpio.h>
242
243 int ret;                       /* Return value */
244
245 omap_request_gpio(3);          /* Request for gpio pin */
246 omap_set_gpio_direction(3,0);
247 omap_set_set_dataout(3,1);     /* Writing a 1 to gpio pin # 3: */
248 ret = omap_get_datain(3);      /* Reading the value of pin # 3 */
249 printk("value of pin # 3 = %d\n",ret);
250 omap_free_gpio(3);             /* Freeing gpio pin # 3 */
251
252 2) Interrupt input by gpio pin#3
253
254 #include <asm/arch/gpio.h>
255
256 omap_request_gpio(3);         /* Request for gpio pin */
257 omap_set_gpio_direction(3,0);
258 set_irq_type(OMAP_GPIO_IRQ(3),IRQT_RISING); /* Setting up pin for interrupt */
259 request_irq(OMAP_GPIO_IRQ(3), (void *)&my_int_handler, SA_SHIRQ,....);
260
261 ...                         /* Do stuff, handle interrupts in my_int_handler */
262
263 free_irq(OMAP_GPIO_IRQ(3),&id); /*  Freeing interrupt and gpio pin */
264 omap_free_gpio(3);
265
266 ------------------------------------------------------------------
267 Last modified 14. August 2006
268 The OMAP Linux Kernel Team
269 Arnold <abo_gwapo@yahoo.com>
270 Dirk Behme <dirk.behme@gmail.com>