From 552c341208759779e4e081160d6914cbed2f89a7 Mon Sep 17 00:00:00 2001 From: hcg Date: Wed, 7 Mar 2007 11:46:24 +0000 Subject: Added GPIO driver git-svn-id: svn://svn.openwrt.org/openwrt/trunk@6534 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- target/linux/at91-2.6/config/default | 1 + .../linux/at91-2.6/patches/003-gpio-driver.patch | 357 +++++++++++++++++++++ 2 files changed, 358 insertions(+) create mode 100644 target/linux/at91-2.6/patches/003-gpio-driver.patch (limited to 'target/linux') diff --git a/target/linux/at91-2.6/config/default b/target/linux/at91-2.6/config/default index cfcfe54a7b..05e6f7c38e 100644 --- a/target/linux/at91-2.6/config/default +++ b/target/linux/at91-2.6/config/default @@ -42,6 +42,7 @@ CONFIG_ARM_THUMB=y # CONFIG_AT91_PROGRAMMABLE_CLOCKS is not set CONFIG_AT91_SPI=y CONFIG_AT91_SPIDEV=y +CONFIG_AT91_VLIO=y # CONFIG_ATM_DUMMY is not set # CONFIG_ATM_TCP is not set CONFIG_BASE_SMALL=0 diff --git a/target/linux/at91-2.6/patches/003-gpio-driver.patch b/target/linux/at91-2.6/patches/003-gpio-driver.patch new file mode 100644 index 0000000000..c14542acc6 --- /dev/null +++ b/target/linux/at91-2.6/patches/003-gpio-driver.patch @@ -0,0 +1,357 @@ +diff -urN linux-2.6.19.2.old/arch/arm/mach-at91rm9200/gpio.c linux-2.6.19.2/arch/arm/mach-at91rm9200/gpio.c +--- linux-2.6.19.2.old/arch/arm/mach-at91rm9200/gpio.c 2007-03-06 22:49:37.000000000 +0100 ++++ linux-2.6.19.2/arch/arm/mach-at91rm9200/gpio.c 2007-03-07 10:25:41.000000000 +0100 +@@ -28,7 +28,7 @@ + + static struct at91_gpio_bank *gpio; + static int gpio_banks; +- ++static u32 pio_gpio_pin[4] = { 0, 0, 0, 0 }; + + static inline void __iomem *pin_to_controller(unsigned pin) + { +@@ -113,10 +113,13 @@ + { + void __iomem *pio = pin_to_controller(pin); + unsigned mask = pin_to_mask(pin); ++ int bank = (pin - PIN_BASE) / 32; + + if (!pio) + return -EINVAL; + ++ pio_gpio_pin[bank] |= mask; ++ + __raw_writel(mask, pio + PIO_IDR); + __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR)); + __raw_writel(mask, pio + PIO_ODR); +@@ -134,10 +137,13 @@ + { + void __iomem *pio = pin_to_controller(pin); + unsigned mask = pin_to_mask(pin); ++ int bank = (pin - PIN_BASE) / 32; + + if (!pio) + return -EINVAL; + ++ pio_gpio_pin[bank] |= mask; ++ + __raw_writel(mask, pio + PIO_IDR); + __raw_writel(mask, pio + PIO_PUDR); + __raw_writel(mask, pio + (value ? PIO_SODR : PIO_CODR)); +@@ -214,6 +220,18 @@ + } + EXPORT_SYMBOL(at91_get_gpio_value); + ++int at91_is_pin_gpio(unsigned pin) ++{ ++ void __iomem *pio = pin_to_controller(pin); ++ unsigned mask = pin_to_mask(pin); ++ int bank = (pin - PIN_BASE) / 32; ++ ++ if (!pio) ++ return -EINVAL; ++ return (pio_gpio_pin[bank] & mask) != 0; ++} ++EXPORT_SYMBOL(at91_is_pin_gpio); ++ + /*--------------------------------------------------------------------------*/ + + #ifdef CONFIG_PM +diff -urN linux-2.6.19.2.old/drivers/char/Kconfig linux-2.6.19.2/drivers/char/Kconfig +--- linux-2.6.19.2.old/drivers/char/Kconfig 2007-03-06 22:49:37.000000000 +0100 ++++ linux-2.6.19.2/drivers/char/Kconfig 2007-03-07 01:08:57.000000000 +0100 +@@ -1064,5 +1064,12 @@ + The SPI driver gives user mode access to this serial + bus on the AT91RM9200 processor. + ++config AT91_VLIO ++ tristate "Versalink LED and GPIO interface" ++ depends on ARCH_AT91RM9200 && MACH_VLINK ++ default n ++ help ++ Provides a handler for LED and GPIO in userspace ++ + endmenu + +diff -urN linux-2.6.19.2.old/drivers/char/Makefile linux-2.6.19.2/drivers/char/Makefile +--- linux-2.6.19.2.old/drivers/char/Makefile 2007-03-06 22:49:37.000000000 +0100 ++++ linux-2.6.19.2/drivers/char/Makefile 2007-03-07 01:08:05.000000000 +0100 +@@ -92,6 +92,7 @@ + obj-$(CONFIG_TELCLOCK) += tlclk.o + obj-$(CONFIG_AT91_SPI) += at91_spi.o + obj-$(CONFIG_AT91_SPIDEV) += at91_spidev.o ++obj-$(CONFIG_AT91_VLIO) += vlink_giu.o + + obj-$(CONFIG_WATCHDOG) += watchdog/ + obj-$(CONFIG_MWAVE) += mwave/ +diff -urN linux-2.6.19.2.old/drivers/char/vlink_giu.c linux-2.6.19.2/drivers/char/vlink_giu.c +--- linux-2.6.19.2.old/drivers/char/vlink_giu.c 1970-01-01 01:00:00.000000000 +0100 ++++ linux-2.6.19.2/drivers/char/vlink_giu.c 2007-03-07 01:21:21.000000000 +0100 +@@ -0,0 +1,256 @@ ++/* ++ * Driver for FDL Versalink GPIO ++ * ++ * Copyright (C) 2005 Guthrie Consulting ++ * Author: Hamish Guthrie ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++static int major; /* default is dynamic major device number */ ++module_param(major, int, 0); ++MODULE_PARM_DESC(major, "Major device number"); ++ ++#define VIO_NR_DEVS 96 ++ ++struct vio_dev { ++ struct cdev cdev; ++}; ++ ++struct vio_dev *vio_devices; ++static struct class *vio_class; ++ ++static ssize_t gpio_read(struct file *file, char __user *buf, size_t len, ++ loff_t *ppos) ++{ ++ unsigned int pin; ++ int retval; ++ char value = '0'; ++ ++ pin = iminor(file->f_dentry->d_inode); ++ ++ retval = at91_get_gpio_value(PIN_BASE + pin); ++ if (retval < 0) ++ return -EFAULT; ++ ++ value = retval + 0x30; ++ if (put_user(value, buf)) ++ return -EFAULT; ++ ++ return 1; ++} ++ ++static ssize_t gpio_write(struct file *file, const char __user *data, ++ size_t len, loff_t *ppos) ++{ ++ unsigned int pin; ++ size_t i; ++ char c; ++ int retval = 0; ++ ++ pin = iminor(file->f_dentry->d_inode); ++ ++ for (i = 0; i < len; i++) { ++ if (get_user(c, data + i)) ++ return -EFAULT; ++ ++ switch (c) { ++ case '0': ++ case '1': ++ retval = at91_set_gpio_value(PIN_BASE + pin, (int)c - 0x30); ++ if (retval < 0) ++ return -EFAULT; ++ break; ++ default: ++ break; ++ } ++ ++ if (retval < 0) ++ break; ++ } ++ ++ return i; ++} ++ ++static int gpio_open(struct inode *inode, struct file *file) ++{ ++ return nonseekable_open(inode, file); ++} ++ ++static int gpio_release(struct inode *inode, struct file *file) ++{ ++ return 0; ++} ++ ++static struct file_operations vio_fops = { ++ .owner = THIS_MODULE, ++ .read = gpio_read, ++ .write = gpio_write, ++ .open = gpio_open, ++ .release = gpio_release, ++}; ++ ++static void vio_setup_cdev(struct vio_dev *dev, int index) ++{ ++ int err, devno = MKDEV(major, index); ++ ++ cdev_init(&dev->cdev, &vio_fops); ++ dev->cdev.owner = THIS_MODULE; ++ dev->cdev.ops = &vio_fops; ++ err = cdev_add (&dev->cdev, devno, 1); ++ if (err) ++ printk(KERN_NOTICE "vio: Error %d adding vio%d", err, index); ++} ++ ++static int vio_remove(struct platform_device *dev) ++{ ++ int i; ++ dev_t devno = MKDEV(major, 0); ++ ++ if (vio_devices) { ++ for(i=0; i"); ++MODULE_DESCRIPTION("FDL Versalink GPIO Driver"); ++MODULE_LICENSE("GPL"); +diff -urN linux-2.6.19.2.old/include/asm-arm/arch-at91rm9200/gpio.h linux-2.6.19.2/include/asm-arm/arch-at91rm9200/gpio.h +--- linux-2.6.19.2.old/include/asm-arm/arch-at91rm9200/gpio.h 2007-01-10 20:10:37.000000000 +0100 ++++ linux-2.6.19.2/include/asm-arm/arch-at91rm9200/gpio.h 2007-03-07 01:17:23.000000000 +0100 +@@ -189,6 +189,7 @@ + /* callable at any time */ + extern int at91_set_gpio_value(unsigned pin, int value); + extern int at91_get_gpio_value(unsigned pin); ++extern int at91_is_pin_gpio(unsigned pin); + + /* callable only from core power-management code */ + extern void at91_gpio_suspend(void); -- cgit v1.2.3