Created
May 21, 2012 18:34
-
-
Save 17twenty/2763814 to your computer and use it in GitHub Desktop.
Kernel Module to turn GPIO1_6 on and off
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> /* Needed by all modules */ | |
#include <linux/kernel.h> /* Needed for KERN_INFO */ | |
#include <linux/init.h> /* Needed for the macros */ | |
#include <plat/gpio.h> | |
#include <plat/am33xx.h> | |
#include <asm/io.h> | |
#define DEVICE_NAME "led_drv" | |
static __iomem unsigned char *gpio1_start; | |
static int __init hello_start(void) | |
{ | |
unsigned int value; | |
unsigned long flags = 0; | |
printk(KERN_INFO "Lights on\n"); | |
request_mem_region (AM33XX_GPIO1_BASE, 0x1000, DEVICE_NAME); | |
/* Map io memory */ | |
gpio1_start = ioremap(AM33XX_GPIO1_BASE, 0x1000); | |
if (gpio1_start == NULL) { | |
printk ("Cannot map memory\n"); | |
return -EIO; | |
} | |
local_irq_save(flags); | |
/* Set the 6th bit in the output enable to turn the GPIO into an output */ | |
value = __raw_readl(gpio1_start + OMAP4_GPIO_OE); | |
value &= ~(1 << 6); | |
__raw_writel(value, gpio1_start + OMAP4_GPIO_OE); | |
/* Set the pin to a 1 in setdataout to turn on */ | |
value = __raw_readl(gpio1_start + OMAP4_GPIO_SETDATAOUT); | |
value |= 1 << 6; | |
__raw_writel(value, gpio1_start + OMAP4_GPIO_SETDATAOUT); | |
local_irq_restore(flags); | |
return 0; | |
} | |
static void __exit hello_end(void) | |
{ | |
unsigned int value; | |
unsigned long flags = 0; | |
local_irq_save(flags); | |
/* Set the pin to a 1 in cleardataout to turn it off */ | |
value = __raw_readl(gpio1_start + OMAP4_GPIO_CLEARDATAOUT); | |
value |= 1 << 6; | |
__raw_writel(value, gpio1_start + OMAP4_GPIO_CLEARDATAOUT); | |
local_irq_restore(flags); | |
iounmap (gpio1_start); | |
release_mem_region (AM33XX_GPIO1_BASE, 0x1000); | |
printk(KERN_INFO "Lights off\n"); | |
} | |
module_init(hello_start); | |
module_exit(hello_end); | |
MODULE_LICENSE("GPL"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment