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.
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:
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
26 http://www-s.ti.com/sc/psheets/spru767a/spru767a.pdf
35 #include <asm/arch/gpio.h>
37 B) omap_cfg_reg(xxxx);
39 Description: Configure pin mux.
41 Parameter: Pin to be configured for GPIO.
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.
50 C) omap_request_gpio(int gpio)
52 Description: Request GPIO to be used.
54 Parameter: int gpio - GPIO PIN (Pin 0-63)
56 Note: Using this function, you dont have to worry about banks/modules where
59 D) omap_set_gpio_direction(int gpio, int is_input)
61 Description: This function is responsible for setting the gpio pin direction
64 Parameter: int gpio - GPIO PIN (Pin 0-63)
65 int is_input - pin direction (0 = output, 1 = input)
67 E) omap_set_gpio_dataout(int gpio, int enable)
69 Description: This function is responsible for writing to a pin.
71 Parameter: int gpio - GPIO PIN (Pin 0-63)
72 int enable - pin value (0 or 1)
74 F) omap_get_gpio_datain(int gpio)
76 Description: This function is responsible for reading pin values.
78 Parameter: int gpio - GPIO PIN (Pin 0-63)
80 G) omap_free_gpio(int gpio)
82 Description: This function is responsible for freeing the pin used.
84 Parameter: int gpio - GPIO PIN (Pin 0-63)
86 H) OMAP_GPIO_IRQ(int gpio)
88 Description: Returns the Interrupt number for the specified gpio pin.
90 Parameter: int gpio - GPIO PIN (Pin 0-63)
92 I) set_irq_type(unsigned int irq, unsigned int type)
94 Description: This function is responsible for setting the type of interrupt
97 Parameter: unsigned int irq - The interrupt number for the gpio pin.
98 unsigned int type - (IRQT_RISING = rising, IRQT_FALLING= falling)
104 1) Writing to gpio pin#3 a value 1 and reading the value of gpio pin#3.
106 #include <asm/arch/gpio.h>
108 int ret; /* Return value */
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 */
117 2) Interrupt input by gpio pin#3
119 #include <asm/arch/gpio.h>
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,....);
126 ... /* Do stuff, handle interrupts in my_int_handler */
128 free_irq(OMAP_GPIO_IRQ(3),&id); /* Freeing interrupt and gpio pin */
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>
137 OMAP GPIO API's HowTo
138 =====================
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.
144 If anything is missing, is wrong, needs extension or update, please send
145 update to Linux-omap-open-source@linux.omap.com.
147 I. GPIO Modules/Banks
148 ---------------------
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:
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
161 http://www-s.ti.com/sc/psheets/spru767a/spru767a.pdf
170 #include <asm/arch/gpio.h>
172 B) omap_cfg_reg(xxxx);
174 Description: Configure pin mux.
176 Parameter: Pin to be configured for GPIO.
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.
185 C) omap_request_gpio(int gpio)
187 Description: Request GPIO to be used.
189 Parameter: int gpio - GPIO PIN (Pin 0-63)
191 Note: Using this function, you dont have to worry about banks/modules where
194 D) omap_set_gpio_direction(int gpio, int is_input)
196 Description: This function is responsible for setting the gpio pin direction
199 Parameter: int gpio - GPIO PIN (Pin 0-63)
200 int is_input - pin direction (0 = output, 1 = input)
202 E) omap_set_gpio_dataout(int gpio, int enable)
204 Description: This function is responsible for writing to a pin.
206 Parameter: int gpio - GPIO PIN (Pin 0-63)
207 int enable - pin value (0 or 1)
209 F) omap_get_gpio_datain(int gpio)
211 Description: This function is responsible for reading pin values.
213 Parameter: int gpio - GPIO PIN (Pin 0-63)
215 G) omap_free_gpio(int gpio)
217 Description: This function is responsible for freeing the pin used.
219 Parameter: int gpio - GPIO PIN (Pin 0-63)
221 H) OMAP_GPIO_IRQ(int gpio)
223 Description: Returns the Interrupt number for the specified gpio pin.
225 Parameter: int gpio - GPIO PIN (Pin 0-63)
227 I) set_irq_type(unsigned int irq, unsigned int type)
229 Description: This function is responsible for setting the type of interrupt
232 Parameter: unsigned int irq - The interrupt number for the gpio pin.
233 unsigned int type - (IRQT_RISING = rising, IRQT_FALLING= falling)
239 1) Writing to gpio pin#3 a value 1 and reading the value of gpio pin#3.
241 #include <asm/arch/gpio.h>
243 int ret; /* Return value */
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 */
252 2) Interrupt input by gpio pin#3
254 #include <asm/arch/gpio.h>
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,....);
261 ... /* Do stuff, handle interrupts in my_int_handler */
263 free_irq(OMAP_GPIO_IRQ(3),&id); /* Freeing interrupt and gpio pin */
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>