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