Hi,<br><br>Thanks for all your replies. Now I want to enable interrupts on some GPIO pins(GPIO pins number 224, 225, 226, 227, 228 and 229 i.e gpiochip224's pins 0 to 5). I configured these pins as input(GPIOF_IN) during gpio request. I am able to request gpio pins successfully.<br>
<br>#define GPIO_CHIP0_BASE 192<br>#define GPIO_CHIP0_COUNT 32<br><br>#define GPIO_CHIP1_BASE 224<br>#define GPIO_CHIP1_COUNT 32<br><br>#define GPIO(chip, pin) (GPIO_CHIP##chip##_BASE + (pin))<br><br>/* Initial GPIO pins setting. */<br>
static struct gpio gpio_pins[] = { <br> { GPIO(1, 0), GPIOF_IN, "Chip 1, Pin 0" },<br> { GPIO(1, 1), GPIOF_IN, "Chip 1, Pin 1" },<br> { GPIO(1, 2), GPIOF_IN, "Chip 1, Pin 2" },<br>
{ GPIO(1, 3), GPIOF_IN, "Chip 1, Pin 3" },<br> { GPIO(1, 4), GPIOF_IN, "Chip 1, Pin 4" },<br> { GPIO(1, 5), GPIOF_IN, "Chip 1, Pin 5" },<br>};<br><br>
static __init int gpio_module_init(void)<br>{<br> int err;<br> dev_t devno = 0;<br><br> printk(KERN_INFO "GPIO Driver Version 0.1\n");<br><br> /* resuest the gpio pin */<br> err = gpio_request_array(gpio_pins, ARRAY_SIZE(gpio_pins));<br>
if (err) {<br> printk(KERN_WARNING "gpio: unable to request gpio pins\n");<br> return -EBUSY;<br> }<br><br> /* register interrupts handlers */<br> err = gpio_request_irq_array(gpio_irq_pins, ARRAY_SIZE(gpio_irq_pins));<br>
if (err) {<br> printk(KERN_WARNING "gpio: unable to register interrupt handler.\n");<br> goto interrupt_fail;<br> }<br>.<br>.<br>.<br>}<br><br>Now in order to enable interrupts I have to set the bits corresponding to these pins in gpiochp Interrupt Mask Register. <br>
<br>My first question is that is there any gpio API call available for doing this? OR I have to manually memory map the gpio IMR register and set bit manually? For the time being I have manually set the IMR bit(using memory map). <br>
<br>Second, in order to register an interrupt handler on a gpio pin, I need a IRQ number, so how am I going to get that number? From the Documentation/gpio.txt, it looks to me that gpio_to_irq() function should give me the irq number, but when I tried to use it, it gives me an error.<br>
<br>#define GPIO_CHIP0_BASE 192<br>
#define GPIO_CHIP0_COUNT 32<br>
<br>
#define GPIO_CHIP1_BASE 224<br>
#define GPIO_CHIP1_COUNT 32<br>
<br>
#define GPIO(chip, pin) (GPIO_CHIP##chip##_BASE + (pin))<br><br>static struct gpio_irq gpio_irq_pins[] = {<br> { GPIO(1, 0), IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW },<br> { GPIO(1, 1), IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW },<br>
{ GPIO(1, 2), IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW },<br> { GPIO(1, 3), IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW },<br> { GPIO(1, 4), IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW },<br> { GPIO(1, 5), IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW },<br>
};<br><br>int gpio_request_irq_array(struct gpio_irq *array, size_t num)<br>{<br> int i, err, irq;<br><br> for (i = 0; i < num; i++, array++) {<br> /* get the irq number corresponding to the gpio pin */<br> irq = gpio_to_irq(array->gpio);<br>
if (irq < 0) {<br> printk(KERN_ERR "gpio: Trying to get irq number for GPIO%d\n", array->gpio);<br> err = -EINVAL;<br> goto err_free;<br> } <br> printd("gpio: irq number for GPIO%d = %d(i=%d)\n", array->gpio, irq, i); <br>
<br> /* set the irq type for the gpio pin */<br> err = set_irq_type(irq, array->type);<br> if (err)<br> goto err_free;<br><br> /* register irq handler */<br> err = request_irq(irq, gpio_irq_handler, IRQF_SHARED, "GPIO Driver", NULL);<br>
if (err) {<br> printk(KERN_ERR "gpio: can't get assigned irq for GPIO%d\n", array->gpio);<br> goto err_free;<br> } <br> }<br> return 0;<br><br>err_free:<br> while (i--)<br> free_irq(gpio_to_irq((--array)->gpio), NULL);<br>
return err;<br>}<br><br>Given above is my driver code, I have implemented a function named
"gpio_request_irq_array" which works in same manner as that of
"gpio_request_array". I am calling in the init function, see the init
code given initially. Now when I load it on my MPC837xERDB board, it gives the following errors.<br><br>[ 1812.776420] GPIO Driver Version 0.1<br>[ 1812.779985] gpio: Trying to get irq number for GPIO224<br>[ 1812.785126] gpio: unable to register interrupt handler.<br>
insmod: error inserting './gpio.ko': -1 Invalid parameters<br><br>Thanks in advance<br>Ravi Gupta<br>