Documentation:AVR32 Linux Development/How to use interupts on SW9 (stk1000) buildroot rc5

From AVRFreaks Wiki

Jump to: navigation, search

This example of an example of how to utilize the sw9 button as an interupt in linux kernel 2.6.22

The code should be compiled into a module (*.ko file) and loaded into and unloaded into the kernel using

insmod <file>
rmmod <file>

[edit] Interupt on SW9 at the stk1000

/*
 * Driver for testing interupt on the SW9 button at the stk1000
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#include <linux/input.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/input.h>

#include <asm/io.h>
#include <asm/irq.h>
#include <asm/gpio.h>
#include <asm/system.h>
#include <asm/arch/at32ap7000.h>

#define BUTTON_PIN GPIO_PIN_PB(25)
#define BUTTON_IRQ  gpio_to_irq(BUTTON_PIN)

static irqreturn_t button_interrupt(int irq, void *dev_id)
{
	printk(KERN_ALERT "int %d: interupt received. Irq number: %d\n", -EBUSY,BUTTON_PIN);
	return IRQ_HANDLED;
}

static int __init button_init(void)
{
	unsigned int ret;

	printk(KERN_ALERT "Module started\n");
	printk(KERN_ALERT "Requesting GPIO %d\n",BUTTON_PIN);
	printk(KERN_ALERT "Requesting Irq %d\n",BUTTON_IRQ);

	ret = gpio_request(BUTTON_PIN, "blah");
	if (ret < 0) {
		printk(KERN_ALERT "error %d: could not request gpio: %d\n", ret,BUTTON_PIN);
		return ret;
	}

	if (request_irq(BUTTON_IRQ, button_interrupt, 0, "button", NULL)) {
		printk(KERN_ALERT "error %d: could not request irq: %d\n", -EBUSY,BUTTON_PORT);
                return -EBUSY;
        }

	return 0;
} 

static void __exit button_exit(void)
{
	printk(KERN_ALERT "exit : removing irq: %d\n",BUTTON_IRQ);
	printk(KERN_ALERT "exit : removing button: %d\n",BUTTON_PIN);
	free_irq(BUTTON_IRQ,  NULL);
	gpio_free(BUTTON_PIN);
} 

module_init(button_init);
module_exit(button_exit);

MODULE_AUTHOR("Eirik Aanonsen");
MODULE_DESCRIPTION("Test Interrupt SW9 driver");
MODULE_LICENSE("GPL");
Personal tools