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.
9 If anything is missing, is wrong, needs extension or update, please send
10 update to Linux-omap-open-source@linux.omap.com.
12 *************************************************************
14 NOTICE: these OMAP-specific interfaces are deprecated/obsolete.
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.
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
25 *************************************************************
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:
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
41 http://www-s.ti.com/sc/psheets/spru767a/spru767a.pdf
50 #include <asm/arch/gpio.h>
52 B) omap_cfg_reg(xxxx);
54 Description: Configure pin mux.
56 Parameter: Pin to be configured for GPIO.
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.
65 C) omap_request_gpio(int gpio)
67 Description: Request GPIO to be used.
69 Parameter: int gpio - GPIO PIN (Pin 0-63)
71 Note: Using this function, you dont have to worry about banks/modules where
74 D) omap_set_gpio_direction(int gpio, int is_input)
76 Description: This function is responsible for setting the gpio pin direction
79 Parameter: int gpio - GPIO PIN (Pin 0-63)
80 int is_input - pin direction (0 = output, 1 = input)
82 E) omap_set_gpio_dataout(int gpio, int enable)
84 Description: This function is responsible for writing to a pin.
86 Parameter: int gpio - GPIO PIN (Pin 0-63)
87 int enable - pin value (0 or 1)
89 F) omap_get_gpio_datain(int gpio)
91 Description: This function is responsible for reading pin values.
93 Parameter: int gpio - GPIO PIN (Pin 0-63)
95 G) omap_free_gpio(int gpio)
97 Description: This function is responsible for freeing the pin used.
99 Parameter: int gpio - GPIO PIN (Pin 0-63)
101 H) OMAP_GPIO_IRQ(int gpio)
103 Description: Returns the Interrupt number for the specified gpio pin.
105 Parameter: int gpio - GPIO PIN (Pin 0-63)
107 I) set_irq_type(unsigned int irq, unsigned int type)
109 Description: This function is responsible for setting the type of interrupt
112 Parameter: unsigned int irq - The interrupt number for the gpio pin.
113 unsigned int type - (IRQT_RISING = rising, IRQT_FALLING= falling)
119 1) Writing to gpio pin#3 a value 1 and reading the value of gpio pin#3.
121 #include <asm/arch/gpio.h>
123 int ret; /* Return value */
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 */
132 2) Interrupt input by gpio pin#3
134 #include <asm/arch/gpio.h>
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,....);
141 ... /* Do stuff, handle interrupts in my_int_handler */
143 free_irq(OMAP_GPIO_IRQ(3),&id); /* Freeing interrupt and gpio pin */
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>
152 OMAP GPIO API's HowTo
153 =====================
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.
159 If anything is missing, is wrong, needs extension or update, please send
160 update to Linux-omap-open-source@linux.omap.com.
162 I. GPIO Modules/Banks
163 ---------------------
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:
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
176 http://www-s.ti.com/sc/psheets/spru767a/spru767a.pdf
185 #include <asm/arch/gpio.h>
187 B) omap_cfg_reg(xxxx);
189 Description: Configure pin mux.
191 Parameter: Pin to be configured for GPIO.
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.
200 C) omap_request_gpio(int gpio)
202 Description: Request GPIO to be used.
204 Parameter: int gpio - GPIO PIN (Pin 0-63)
206 Note: Using this function, you dont have to worry about banks/modules where
209 D) omap_set_gpio_direction(int gpio, int is_input)
211 Description: This function is responsible for setting the gpio pin direction
214 Parameter: int gpio - GPIO PIN (Pin 0-63)
215 int is_input - pin direction (0 = output, 1 = input)
217 E) omap_set_gpio_dataout(int gpio, int enable)
219 Description: This function is responsible for writing to a pin.
221 Parameter: int gpio - GPIO PIN (Pin 0-63)
222 int enable - pin value (0 or 1)
224 F) omap_get_gpio_datain(int gpio)
226 Description: This function is responsible for reading pin values.
228 Parameter: int gpio - GPIO PIN (Pin 0-63)
230 G) omap_free_gpio(int gpio)
232 Description: This function is responsible for freeing the pin used.
234 Parameter: int gpio - GPIO PIN (Pin 0-63)
236 H) OMAP_GPIO_IRQ(int gpio)
238 Description: Returns the Interrupt number for the specified gpio pin.
240 Parameter: int gpio - GPIO PIN (Pin 0-63)
242 I) set_irq_type(unsigned int irq, unsigned int type)
244 Description: This function is responsible for setting the type of interrupt
247 Parameter: unsigned int irq - The interrupt number for the gpio pin.
248 unsigned int type - (IRQT_RISING = rising, IRQT_FALLING= falling)
254 1) Writing to gpio pin#3 a value 1 and reading the value of gpio pin#3.
256 #include <asm/arch/gpio.h>
258 int ret; /* Return value */
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 */
267 2) Interrupt input by gpio pin#3
269 #include <asm/arch/gpio.h>
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,....);
276 ... /* Do stuff, handle interrupts in my_int_handler */
278 free_irq(OMAP_GPIO_IRQ(3),&id); /* Freeing interrupt and gpio pin */
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>