From: <mar...@us...> - 2007-02-27 16:28:58
|
Revision: 883 http://svn.sourceforge.net/hackndev/?rev=883&view=rev Author: marex_z71 Date: 2007-02-27 08:28:55 -0800 (Tue, 27 Feb 2007) Log Message: ----------- l4p: Fix GPIOed and GPIOed-NG and make them a self-standing module available under DRIVERS->MISC, also remove them from palmld Modified Paths: -------------- linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/Kconfig linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/Makefile linux4palm/linux/trunk/drivers/misc/Kconfig linux4palm/linux/trunk/drivers/misc/Makefile Added Paths: ----------- linux4palm/linux/trunk/drivers/misc/gpioed-ng.c linux4palm/linux/trunk/drivers/misc/gpioed.c Removed Paths: ------------- linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/gpioed-ng.c linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/gpioed.c Modified: linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/Kconfig =================================================================== --- linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/Kconfig 2007-02-27 13:58:12 UTC (rev 882) +++ linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/Kconfig 2007-02-27 16:28:55 UTC (rev 883) @@ -21,17 +21,3 @@ config PALMLD_IDE tristate "Palm LifeDrive IDE driver" depends on MACH_XSCALE_PALMLD - -config GPIOED - tristate "GPIOED" - depends on MACH_XSCALE_PALMLD - default n - help - Gpioed: only for debuging and testing! - -config GPIOEDNG - tristate "GPIOEDNG" - depends on MACH_XSCALE_PALMLD - default n - help - Gpioed-ng: only for debuging and testing! Modified: linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/Makefile =================================================================== --- linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/Makefile 2007-02-27 13:58:12 UTC (rev 882) +++ linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/Makefile 2007-02-27 16:28:55 UTC (rev 883) @@ -7,6 +7,4 @@ obj-$(CONFIG_PALMLD_USB) += palmld_usb.o obj-$(CONFIG_PALMLD_IDE) += palmld_ide.o obj-$(CONFIG_PM) += palmld_pm.o -obj-$(CONFIG_GPIOED) += gpioed.o -obj-$(CONFIG_GPIOEDNG) += gpioed-ng.o Deleted: linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/gpioed-ng.c =================================================================== --- linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/gpioed-ng.c 2007-02-27 13:58:12 UTC (rev 882) +++ linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/gpioed-ng.c 2007-02-27 16:28:55 UTC (rev 883) @@ -1,175 +0,0 @@ -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/proc_fs.h> - -#include <linux/interrupt.h> -#include <asm/irq.h> -#include <asm/mach/arch.h> -#include <asm/mach/map.h> -#include <asm/mach-types.h> -#include <asm/hardware.h> -#include <linux/sched.h> -#include <linux/workqueue.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/irqs.h> -#include <asm/uaccess.h> - -#include <linux/debugfs.h> -#include <linux/seq_file.h> - -#define PROCFS_NAME "gpio" -#define DEBUGFS_NAME "gpio" - -static struct proc_dir_entry *proc_intf; -static struct dentry *debugfs_intf; - -#define PROCFS_MAX_SIZE 20 - -static char procfs_buffer[PROCFS_MAX_SIZE]; -static unsigned long procfs_buffer_size = 0; - -#define GPIO_TEST(reg, gp) (reg(gp) & GPIO_bit(gp)) -static int dfs_show(struct seq_file *s, void *_) -{ - int i,afn; - seq_printf(s, "GPIO lines status:\n"); - - for(i=0;i<121;i++) { - afn = (GAFR(i) & (0x3 << (((i) & 0xf)*2))) >> (((i) & 0xf)*2); - seq_printf(s, "%s%d: %s %s %s %s %lx\n", - i<10?"0":"", - i, - GPIO_TEST(GPLR, i)?"*":" ", - GPIO_TEST(GPDR, i)?"->":"<-", - GPIO_TEST(GRER, i)?"_/":" ", - GPIO_TEST(GFER, i)?"\\_":" ", - afn); - - } - - return 0; -} - -static int dfs_open(struct inode *inode, struct file *file) -{ - return single_open(file, dfs_show, inode->u.generic_ip); -} - -static struct file_operations debug_fops = { - .open = dfs_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static void gpio_set(int id, int on) -{ - do { - if (on) - GPSR(id) = GPIO_bit(id); - else - GPCR(id) = GPIO_bit(id); - } while (0); -} - -void set_afn(int gpio, int fn) -{ - int gafr; - gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2)); - GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2)); -} - -void handle_request() -{ - char *p = NULL; - unsigned long id = simple_strtoul(procfs_buffer+2, &p, 10); - switch(procfs_buffer[0]) { - case 'L': - gpio_set(id, 1); - printk(KERN_ERR "GPIOed: GPIO %lu set high\n", id); - break; - case 'l': - gpio_set(id, 0); - printk(KERN_ERR "GPIOed: GPIO %lu set low\n", id); - break; - case 'd': - GPDR(id) &= ~(GPIO_bit(id)); - break; - case 'D': - GPDR(id) |= GPIO_bit(id); - break; - case '0': - set_afn(id, 0); - break; - case '1': - set_afn(id, 1); - break; - case '2': - set_afn(id, 2); - break; - default: - printk(KERN_ERR "GPIOed: Unknown request\n"); - break; - } -} - - -int procfile_write(struct file *file, const char *buffer, unsigned long count, void *data) -{ - procfs_buffer_size = count; - if (procfs_buffer_size > PROCFS_MAX_SIZE ) { - procfs_buffer_size = PROCFS_MAX_SIZE; - } - - /* write data to the buffer */ - if ( copy_from_user(procfs_buffer, buffer, procfs_buffer_size) ) { - return -EFAULT; - } - - handle_request(); - - return procfs_buffer_size; -} - - -static int __init gpioed_init(void) -{ - proc_intf = create_proc_entry(PROCFS_NAME, 0644, NULL); - if (proc_intf == NULL) { - remove_proc_entry(PROCFS_NAME, &proc_root); - printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", PROCFS_NAME); - return -ENOMEM; - } - - /*proc_intf->read_proc = procfile_read;*/ - proc_intf->write_proc = procfile_write; - proc_intf->owner = THIS_MODULE; - proc_intf->mode = S_IFREG | S_IRUGO; - proc_intf->uid = 0; - proc_intf->gid = 0; - proc_intf->size = 37; - - debugfs_intf = debugfs_create_file(DEBUGFS_NAME, S_IRUGO, NULL, NULL, &debug_fops); - - printk(KERN_INFO "/proc/%s created\n", PROCFS_NAME); - - return 0; -} - -static void __exit gpioed_exit(void) -{ - debugfs_remove(debugfs_intf); - remove_proc_entry(PROCFS_NAME, &proc_root); - printk(KERN_INFO "/proc/%s removed\n", PROCFS_NAME); -} - - -/*** Some more stuff ***/ -module_init(gpioed_init); -module_exit(gpioed_exit); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Vladimir \"Farcaller\" Pouzanov <far...@gm...>"); -MODULE_DESCRIPTION("GPIO editor for PXA26x, second edition"); - Deleted: linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/gpioed.c =================================================================== --- linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/gpioed.c 2007-02-27 13:58:12 UTC (rev 882) +++ linux4palm/linux/trunk/arch/arm/mach-pxa/palmld/gpioed.c 2007-02-27 16:28:55 UTC (rev 883) @@ -1,227 +0,0 @@ -/*** Basic includes ***/ -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/proc_fs.h> -#include <linux/irq.h> - -#include <linux/interrupt.h> -#include <asm/irq.h> -#include <asm/mach/arch.h> -#include <asm/mach/map.h> -#include <asm/mach-types.h> -#include <asm/hardware.h> -#include <linux/sched.h> -#include <linux/workqueue.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/irqs.h> -#include <asm/uaccess.h> - -/*** GPIO macros ***/ -#define GET_PALMT3_GPIO(gpio) \ - (GPLR(GPIO_NR_PALMT3_ ## gpio) & GPIO_bit(GPIO_NR_PALMT3_ ## gpio)) - -#define SET_PALMT3_GPIO(gpio, setp) \ - do { \ - if (setp) \ - GPSR(GPIO_NR_PALMT3_ ## gpio) = GPIO_bit(GPIO_NR_PALMT3_ ## gpio); \ - else \ - GPCR(GPIO_NR_PALMT3_ ## gpio) = GPIO_bit(GPIO_NR_PALMT3_ ## gpio); \ - } while (0) - -#define SET_PALMT3_GPIO_N(gpio, setp) \ - do { \ - if (setp) \ - GPCR(GPIO_NR_PALMT3_ ## gpio) = GPIO_bit(GPIO_NR_PALMT3_ ## gpio); \ - else \ - GPSR(GPIO_NR_PALMT3_ ## gpio) = GPIO_bit(GPIO_NR_PALMT3_ ## gpio); \ - } while (0) - -#define GET_GPIO_REG(reg,gpio) (GP##reg(gpio) & GPIO_bit(gpio)) -#define GET_GPIO(gpio) GET_GPIO_REG(LR, gpio) - -/*** /proc interface ***/ -static struct proc_dir_entry *proc_intf; -#define procfs_name "gpioed" -#define PROCFS_MAX_SIZE 20 - -static char procfs_buffer[PROCFS_MAX_SIZE]; -static unsigned long procfs_buffer_size = 0; - -int procfile_read(char *buffer, char **buffer_location, off_t offset, int buffer_length, int *eof, void *data) -{ - int ret; - - if (offset > 0) { - /* we have finished to read, return 0 */ - ret = 0; - } else { - /* fill the buffer, return the buffer size */ - ret = sprintf(buffer, "HelloWorld!\n"); - } - return ret; -} - -void handle_request(void); - -int procfile_write(struct file *file, const char *buffer, unsigned long count, void *data) -{ - procfs_buffer_size = count; - if (procfs_buffer_size > PROCFS_MAX_SIZE ) { - procfs_buffer_size = PROCFS_MAX_SIZE; - } - - /* write data to the buffer */ - if ( copy_from_user(procfs_buffer, buffer, procfs_buffer_size) ) { - return -EFAULT; - } - - handle_request(); - - return procfs_buffer_size; -} - -/*** IRQ (GPIO) handling ***/ -static struct workqueue_struct *my_workqueue; -#define MY_WORK_QUEUE_NAME "GPIOed" - -static void handle_gpio(void* irq) -{ - int gpn = (int)irq; - printk(KERN_ERR "*** GPIO *** %d *** is *** %s ***\n", gpn, GET_GPIO(gpn) ? "high" : "low "); -} - -irqreturn_t gpio_irq(int irq, void *dev_id, struct pt_regs *regs) -{ - static int initialised = 0; - static struct work_struct task; - - if (initialised == 0) { - INIT_WORK(&task, handle_gpio); - initialised = 1; - } else { - PREPARE_WORK(&task, handle_gpio, dev_id); - } - - queue_work(my_workqueue, &task); - - return IRQ_HANDLED; -} - -/*** GPIO R/W ***/ -static int gpio_get(int id) -{ - return GET_GPIO(id); -} - -static void gpio_set(int id, int on) -{ - do { - if (on) - GPSR(id) = GPIO_bit(id); - else - GPCR(id) = GPIO_bit(id); - } while (0); -} - -static int gpio_watch(int x) -{ - int ret; - ret = request_irq (IRQ_GPIO(x), gpio_irq, SA_SAMPLE_RANDOM, "test_handler", (void*)x); - set_irq_type (IRQ_GPIO(x), IRQT_BOTHEDGE); - if(ret!=0) { - printk(KERN_ERR "GPIOed: failed to register for GPIO %d\n", x); - return 1; - } else { - printk(KERN_ERR "GPIOed: Registered GPIO %d\n", x); - return 0; - } -} - -/*** Request handler ***/ -void handle_request() -{ - char *p = NULL; - unsigned long base = 10; - unsigned long id; - - if((procfs_buffer[0] == 'P') || (procfs_buffer[0] == 'V')) - base = 16; - id = simple_strtoul(procfs_buffer+2, &p, base); - switch(procfs_buffer[0]) { - case 'r': - printk(KERN_ERR "GPIOed: GPIO %lu is %s\n", id, gpio_get(id)?"high":"low "); - break; - case 's': - gpio_watch(id); - break; - case 'h': - gpio_set(id, 1); - printk(KERN_ERR "GPIOed: GPIO %lu set high\n", id); - break; - case 'l': - gpio_set(id, 0); - printk(KERN_ERR "GPIOed: GPIO %lu set low\n", id); - break; - case 'd': - printk(KERN_ERR "GPIOed: GPIO %lu is %s\n", id, GET_GPIO_REG(DR,id)?"output":"input"); - break; - - case 'P': - printk(KERN_ERR "GPIOed: P-V for 0x%x is 0x%x\n", id, (unsigned int)phys_to_virt(id)); - break; - case 'V': - printk(KERN_ERR "GPIOed: V-P for 0x%x is 0x%x\n", id, (unsigned int)virt_to_phys(id)); - break; - case 'D': - base = *((unsigned int*)id); - printk(KERN_ERR "GPIOed: 0x%x = 0x%x\n", id, base); - break; - default: - printk(KERN_ERR "GPIOed: Unknown request\n"); - break; - } -} - -/*** init&exit ***/ -static int __init gpioed_init(void) -{ - my_workqueue = create_workqueue(MY_WORK_QUEUE_NAME); - - proc_intf = create_proc_entry(procfs_name, 0644, NULL); - if (proc_intf == NULL) { - remove_proc_entry(procfs_name, &proc_root); - printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", - procfs_name); - return -ENOMEM; - } - - proc_intf->read_proc = procfile_read; - proc_intf->write_proc = procfile_write; - proc_intf->owner = THIS_MODULE; - proc_intf->mode = S_IFREG | S_IRUGO; - proc_intf->uid = 0; - proc_intf->gid = 0; - proc_intf->size = 37; - - printk(KERN_INFO "/proc/%s created\n", procfs_name); - - return 0; -} - -static void __exit gpioed_exit(void) -{ - destroy_workqueue(my_workqueue); - remove_proc_entry(procfs_name, &proc_root); - printk(KERN_INFO "/proc/%s removed\n", procfs_name); -} - - -/*** Some more stuff ***/ -module_init(gpioed_init); -module_exit(gpioed_exit); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Vladimir \"Farcaller\" Pouzanov <far...@gm...>"); -MODULE_DESCRIPTION("GPIO editor for PXA26x"); - Modified: linux4palm/linux/trunk/drivers/misc/Kconfig =================================================================== --- linux4palm/linux/trunk/drivers/misc/Kconfig 2007-02-27 13:58:12 UTC (rev 882) +++ linux4palm/linux/trunk/drivers/misc/Kconfig 2007-02-27 16:28:55 UTC (rev 883) @@ -34,6 +34,20 @@ Say Y here to enable monitoring of battery and charger using sysfs interface. +config GPIOED + tristate "GPIOED" + depends on ARCH_PXA + default n + help + Gpioed: only for debuging and testing! + +config GPIOEDNG + tristate "GPIOEDNG" + depends on ARCH_PXA + default n + help + Gpioed-ng: only for debuging and testing! + menu "Multimedia Capabilities Port drivers" config MCP Modified: linux4palm/linux/trunk/drivers/misc/Makefile =================================================================== --- linux4palm/linux/trunk/drivers/misc/Makefile 2007-02-27 13:58:12 UTC (rev 882) +++ linux4palm/linux/trunk/drivers/misc/Makefile 2007-02-27 16:28:55 UTC (rev 883) @@ -13,6 +13,8 @@ obj-$(CONFIG_BATTCHARGE_MONITOR) += battchargemon.o +obj-$(CONFIG_GPIOED) += gpioed.o +obj-$(CONFIG_GPIOEDNG) += gpioed-ng.o obj-$(CONFIG_MCP) += mcp-core.o obj-$(CONFIG_MCP_SA1100) += mcp-sa1100.o Added: linux4palm/linux/trunk/drivers/misc/gpioed-ng.c =================================================================== --- linux4palm/linux/trunk/drivers/misc/gpioed-ng.c (rev 0) +++ linux4palm/linux/trunk/drivers/misc/gpioed-ng.c 2007-02-27 16:28:55 UTC (rev 883) @@ -0,0 +1,175 @@ +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/proc_fs.h> + +#include <linux/interrupt.h> +#include <asm/irq.h> +#include <asm/mach/arch.h> +#include <asm/mach/map.h> +#include <asm/mach-types.h> +#include <asm/hardware.h> +#include <linux/sched.h> +#include <linux/workqueue.h> +#include <asm/arch/pxa-regs.h> +#include <asm/arch/irqs.h> +#include <asm/uaccess.h> + +#include <linux/debugfs.h> +#include <linux/seq_file.h> + +#define PROCFS_NAME "gpio" +#define DEBUGFS_NAME "gpio" + +static struct proc_dir_entry *proc_intf; +static struct dentry *debugfs_intf; + +#define PROCFS_MAX_SIZE 20 + +static char procfs_buffer[PROCFS_MAX_SIZE]; +static unsigned long procfs_buffer_size = 0; + +#define GPIO_TEST(reg, gp) (reg(gp) & GPIO_bit(gp)) +static int dfs_show(struct seq_file *s, void *_) +{ + int i,afn; + seq_printf(s, "GPIO lines status:\n"); + + for(i=0;i<121;i++) { + afn = (GAFR(i) & (0x3 << (((i) & 0xf)*2))) >> (((i) & 0xf)*2); + seq_printf(s, "%s%d: %s %s %s %s %08x\n", + i<10?"0":"", + i, + GPIO_TEST(GPLR, i)?"*":" ", + GPIO_TEST(GPDR, i)?"->":"<-", + GPIO_TEST(GRER, i)?"_/":" ", + GPIO_TEST(GFER, i)?"\\_":" ", + afn); + + } + + return 0; +} + +static int dfs_open(struct inode *inode, struct file *file) +{ + return single_open(file, dfs_show, inode->i_private); +} + +static struct file_operations debug_fops = { + .open = dfs_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static void gpio_set(int id, int on) +{ + do { + if (on) + GPSR(id) = GPIO_bit(id); + else + GPCR(id) = GPIO_bit(id); + } while (0); +} + +void set_afn(int gpio, int fn) +{ + int gafr; + gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2)); + GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2)); +} + +void handle_request(void) +{ + char *p = NULL; + unsigned long id = simple_strtoul(procfs_buffer+2, &p, 10); + switch(procfs_buffer[0]) { + case 'L': + gpio_set(id, 1); + printk(KERN_ERR "GPIOed: GPIO %lu set high\n", id); + break; + case 'l': + gpio_set(id, 0); + printk(KERN_ERR "GPIOed: GPIO %lu set low\n", id); + break; + case 'd': + GPDR(id) &= ~(GPIO_bit(id)); + break; + case 'D': + GPDR(id) |= GPIO_bit(id); + break; + case '0': + set_afn(id, 0); + break; + case '1': + set_afn(id, 1); + break; + case '2': + set_afn(id, 2); + break; + default: + printk(KERN_ERR "GPIOed: Unknown request\n"); + break; + } +} + + +int procfile_write(struct file *file, const char *buffer, unsigned long count, void *data) +{ + procfs_buffer_size = count; + if (procfs_buffer_size > PROCFS_MAX_SIZE ) { + procfs_buffer_size = PROCFS_MAX_SIZE; + } + + /* write data to the buffer */ + if ( copy_from_user(procfs_buffer, buffer, procfs_buffer_size) ) { + return -EFAULT; + } + + handle_request(); + + return procfs_buffer_size; +} + + +static int __init gpioed_init(void) +{ + proc_intf = create_proc_entry(PROCFS_NAME, 0644, NULL); + if (proc_intf == NULL) { + remove_proc_entry(PROCFS_NAME, &proc_root); + printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", PROCFS_NAME); + return -ENOMEM; + } + + /*proc_intf->read_proc = procfile_read;*/ + proc_intf->write_proc = procfile_write; + proc_intf->owner = THIS_MODULE; + proc_intf->mode = S_IFREG | S_IRUGO; + proc_intf->uid = 0; + proc_intf->gid = 0; + proc_intf->size = 37; + + debugfs_intf = debugfs_create_file(DEBUGFS_NAME, S_IRUGO, NULL, NULL, &debug_fops); + + printk(KERN_INFO "/proc/%s created\n", PROCFS_NAME); + + return 0; +} + +static void __exit gpioed_exit(void) +{ + debugfs_remove(debugfs_intf); + remove_proc_entry(PROCFS_NAME, &proc_root); + printk(KERN_INFO "/proc/%s removed\n", PROCFS_NAME); +} + + +/*** Some more stuff ***/ +module_init(gpioed_init); +module_exit(gpioed_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Vladimir \"Farcaller\" Pouzanov <far...@gm...>"); +MODULE_DESCRIPTION("GPIO editor for PXA26x, second edition"); + Added: linux4palm/linux/trunk/drivers/misc/gpioed.c =================================================================== --- linux4palm/linux/trunk/drivers/misc/gpioed.c (rev 0) +++ linux4palm/linux/trunk/drivers/misc/gpioed.c 2007-02-27 16:28:55 UTC (rev 883) @@ -0,0 +1,210 @@ +/*** Basic includes ***/ +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/proc_fs.h> +#include <linux/irq.h> + +#include <linux/interrupt.h> +#include <asm/irq.h> +#include <asm/mach/arch.h> +#include <asm/mach/map.h> +#include <asm/mach-types.h> +#include <asm/hardware.h> +#include <linux/sched.h> +#include <linux/workqueue.h> +#include <asm/arch/pxa-regs.h> +#include <asm/arch/irqs.h> +#include <asm/uaccess.h> + +#define GET_GPIO_REG(reg,gpio) (GP##reg(gpio) & GPIO_bit(gpio)) +#define GET_GPIO(gpio) GET_GPIO_REG(LR, gpio) + +/*** /proc interface ***/ +static struct proc_dir_entry *proc_intf; +#define procfs_name "gpioed" +#define PROCFS_MAX_SIZE 20 + +static char procfs_buffer[PROCFS_MAX_SIZE]; +static unsigned long procfs_buffer_size = 0; +unsigned int gpioed_irq; + +int procfile_read(char *buffer, char **buffer_location, off_t offset, int buffer_length, int *eof, void *data) +{ + int ret; + + if (offset > 0) { + /* we have finished to read, return 0 */ + ret = 0; + } else { + /* fill the buffer, return the buffer size */ + ret = sprintf(buffer, "HelloWorld!\n"); + } + return ret; +} + +void handle_request(void); + +int procfile_write(struct file *file, const char *buffer, unsigned long count, void *data) +{ + procfs_buffer_size = count; + if (procfs_buffer_size > PROCFS_MAX_SIZE ) { + procfs_buffer_size = PROCFS_MAX_SIZE; + } + + /* write data to the buffer */ + if ( copy_from_user(procfs_buffer, buffer, procfs_buffer_size) ) { + return -EFAULT; + } + + handle_request(); + + return procfs_buffer_size; +} + +/*** IRQ (GPIO) handling ***/ +static struct workqueue_struct *my_workqueue; +#define MY_WORK_QUEUE_NAME "GPIOed" + +static void handle_gpio(struct work_struct *work) +{ + printk(KERN_ERR "*** GPIO *** %d *** is *** %s ***\n", + gpioed_irq, GET_GPIO(gpioed_irq) ? "high" : "low "); +} + +irqreturn_t gpio_irq(int irq, void *dev_id) +{ + static int initialised = 0; + struct work_struct gpioed_ws; + + gpioed_irq=(int)irq; + + if (initialised == 0) { + INIT_WORK(&gpioed_ws, handle_gpio); + initialised = 1; + } else { + PREPARE_WORK(&gpioed_ws, handle_gpio); + } + + queue_work(my_workqueue, &gpioed_ws); + + return IRQ_HANDLED; +} + +/*** GPIO R/W ***/ +static int gpio_get(int id) +{ + return GET_GPIO(id); +} + +static void gpio_set(int id, int on) +{ + do { + if (on) + GPSR(id) = GPIO_bit(id); + else + GPCR(id) = GPIO_bit(id); + } while (0); +} + +static int gpio_watch(int x) +{ + int ret; + ret = request_irq (IRQ_GPIO(x), gpio_irq, SA_SAMPLE_RANDOM, "test_handler", (void*)x); + set_irq_type (IRQ_GPIO(x), IRQT_BOTHEDGE); + if(ret!=0) { + printk(KERN_ERR "GPIOed: failed to register for GPIO %d\n", x); + return 1; + } else { + printk(KERN_ERR "GPIOed: Registered GPIO %d\n", x); + return 0; + } +} + +/*** Request handler ***/ +void handle_request() +{ + char *p = NULL; + unsigned long base = 10; + unsigned long id; + + if((procfs_buffer[0] == 'P') || (procfs_buffer[0] == 'V')) + base = 16; + id = simple_strtoul(procfs_buffer+2, &p, base); + switch(procfs_buffer[0]) { + case 'r': + printk(KERN_ERR "GPIOed: GPIO %lu is %s\n", id, gpio_get(id)?"high":"low "); + break; + case 's': + gpio_watch(id); + break; + case 'h': + gpio_set(id, 1); + printk(KERN_ERR "GPIOed: GPIO %lu set high\n", id); + break; + case 'l': + gpio_set(id, 0); + printk(KERN_ERR "GPIOed: GPIO %lu set low\n", id); + break; + case 'd': + printk(KERN_ERR "GPIOed: GPIO %lu is %s\n", id, GET_GPIO_REG(DR,id)?"output":"input"); + break; + + case 'P': + printk(KERN_ERR "GPIOed: P-V for 0x%lu is 0x%x\n", id, (unsigned int)phys_to_virt(id)); + break; + case 'V': + printk(KERN_ERR "GPIOed: V-P for 0x%lu is 0x%x\n", id, (unsigned int)virt_to_phys(&id)); + break; + case 'D': + base = *((unsigned int*)id); + printk(KERN_ERR "GPIOed: 0x%lu = 0x%lu\n", id, base); + break; + default: + printk(KERN_ERR "GPIOed: Unknown request\n"); + break; + } +} + +/*** init&exit ***/ +static int __init gpioed_init(void) +{ + my_workqueue = create_workqueue(MY_WORK_QUEUE_NAME); + + proc_intf = create_proc_entry(procfs_name, 0644, NULL); + if (proc_intf == NULL) { + remove_proc_entry(procfs_name, &proc_root); + printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", + procfs_name); + return -ENOMEM; + } + + proc_intf->read_proc = procfile_read; + proc_intf->write_proc = procfile_write; + proc_intf->owner = THIS_MODULE; + proc_intf->mode = S_IFREG | S_IRUGO; + proc_intf->uid = 0; + proc_intf->gid = 0; + proc_intf->size = 37; + + printk(KERN_INFO "/proc/%s created\n", procfs_name); + + return 0; +} + +static void __exit gpioed_exit(void) +{ + destroy_workqueue(my_workqueue); + remove_proc_entry(procfs_name, &proc_root); + printk(KERN_INFO "/proc/%s removed\n", procfs_name); +} + + +/*** Some more stuff ***/ +module_init(gpioed_init); +module_exit(gpioed_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Vladimir \"Farcaller\" Pouzanov <far...@gm...>"); +MODULE_DESCRIPTION("GPIO editor for PXA2xx"); + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |