Commit 5f3c9098 authored by Florian Fainelli's avatar Florian Fainelli Committed by Ralf Baechle

MIPS: AR7: Implement gpiolib

This patch implements gpiolib for the AR7 SoC.
Signed-off-by: default avatarFlorian Fainelli <florian@openwrt.org>
To: linux-mips@linux-mips.org
Patchwork: http://patchwork.linux-mips.org/patch/816/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent 69b427cd
...@@ -41,7 +41,7 @@ config AR7 ...@@ -41,7 +41,7 @@ config AR7
select SYS_SUPPORTS_32BIT_KERNEL select SYS_SUPPORTS_32BIT_KERNEL
select SYS_SUPPORTS_LITTLE_ENDIAN select SYS_SUPPORTS_LITTLE_ENDIAN
select SYS_SUPPORTS_ZBOOT_UART16550 select SYS_SUPPORTS_ZBOOT_UART16550
select GENERIC_GPIO select ARCH_REQUIRE_GPIOLIB
select GCD select GCD
select VLYNQ select VLYNQ
help help
......
/* /*
* Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org> * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
* Copyright (C) 2007 Eugene Konev <ejka@openwrt.org> * Copyright (C) 2007 Eugene Konev <ejka@openwrt.org>
* Copyright (C) 2009 Florian Fainelli <florian@openwrt.org>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -18,31 +19,113 @@ ...@@ -18,31 +19,113 @@
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/gpio.h>
#include <asm/mach-ar7/gpio.h> #include <asm/mach-ar7/gpio.h>
static const char *ar7_gpio_list[AR7_GPIO_MAX]; struct ar7_gpio_chip {
void __iomem *regs;
struct gpio_chip chip;
};
int gpio_request(unsigned gpio, const char *label) static int ar7_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
{ {
if (gpio >= AR7_GPIO_MAX) struct ar7_gpio_chip *gpch =
return -EINVAL; container_of(chip, struct ar7_gpio_chip, chip);
void __iomem *gpio_in = gpch->regs + AR7_GPIO_INPUT;
if (ar7_gpio_list[gpio]) return readl(gpio_in) & (1 << gpio);
return -EBUSY; }
static void ar7_gpio_set_value(struct gpio_chip *chip,
unsigned gpio, int value)
{
struct ar7_gpio_chip *gpch =
container_of(chip, struct ar7_gpio_chip, chip);
void __iomem *gpio_out = gpch->regs + AR7_GPIO_OUTPUT;
unsigned tmp;
tmp = readl(gpio_out) & ~(1 << gpio);
if (value)
tmp |= 1 << gpio;
writel(tmp, gpio_out);
}
static int ar7_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
{
struct ar7_gpio_chip *gpch =
container_of(chip, struct ar7_gpio_chip, chip);
void __iomem *gpio_dir = gpch->regs + AR7_GPIO_DIR;
if (label) writel(readl(gpio_dir) | (1 << gpio), gpio_dir);
ar7_gpio_list[gpio] = label;
else
ar7_gpio_list[gpio] = "busy";
return 0; return 0;
} }
EXPORT_SYMBOL(gpio_request);
void gpio_free(unsigned gpio) static int ar7_gpio_direction_output(struct gpio_chip *chip,
unsigned gpio, int value)
{ {
BUG_ON(!ar7_gpio_list[gpio]); struct ar7_gpio_chip *gpch =
ar7_gpio_list[gpio] = NULL; container_of(chip, struct ar7_gpio_chip, chip);
void __iomem *gpio_dir = gpch->regs + AR7_GPIO_DIR;
ar7_gpio_set_value(chip, gpio, value);
writel(readl(gpio_dir) & ~(1 << gpio), gpio_dir);
return 0;
}
static struct ar7_gpio_chip ar7_gpio_chip = {
.chip = {
.label = "ar7-gpio",
.direction_input = ar7_gpio_direction_input,
.direction_output = ar7_gpio_direction_output,
.set = ar7_gpio_set_value,
.get = ar7_gpio_get_value,
.base = 0,
.ngpio = AR7_GPIO_MAX,
}
};
int ar7_gpio_enable(unsigned gpio)
{
void __iomem *gpio_en = ar7_gpio_chip.regs + AR7_GPIO_ENABLE;
writel(readl(gpio_en) | (1 << gpio), gpio_en);
return 0;
}
EXPORT_SYMBOL(ar7_gpio_enable);
int ar7_gpio_disable(unsigned gpio)
{
void __iomem *gpio_en = ar7_gpio_chip.regs + AR7_GPIO_ENABLE;
writel(readl(gpio_en) & ~(1 << gpio), gpio_en);
return 0;
}
EXPORT_SYMBOL(ar7_gpio_disable);
static int __init ar7_gpio_init(void)
{
int ret;
ar7_gpio_chip.regs = ioremap_nocache(AR7_REGS_GPIO,
AR7_REGS_GPIO + 0x10);
if (!ar7_gpio_chip.regs) {
printk(KERN_ERR "ar7-gpio: failed to ioremap regs\n");
return -ENOMEM;
}
ret = gpiochip_add(&ar7_gpio_chip.chip);
if (ret) {
printk(KERN_ERR "ar7-gpio: failed to add gpiochip\n");
return ret;
}
printk(KERN_INFO "ar7-gpio: registered %d GPIOs\n",
ar7_gpio_chip.chip.ngpio);
return ret;
} }
EXPORT_SYMBOL(gpio_free); arch_initcall(ar7_gpio_init);
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/phy_fixed.h> #include <linux/phy_fixed.h>
#include <linux/gpio.h>
#include <asm/addrspace.h> #include <asm/addrspace.h>
#include <asm/mach-ar7/ar7.h> #include <asm/mach-ar7/ar7.h>
......
/* /*
* Copyright (C) 2007 Florian Fainelli <florian@openwrt.org> * Copyright (C) 2007-2009 Florian Fainelli <florian@openwrt.org>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -22,88 +22,18 @@ ...@@ -22,88 +22,18 @@
#include <asm/mach-ar7/ar7.h> #include <asm/mach-ar7/ar7.h>
#define AR7_GPIO_MAX 32 #define AR7_GPIO_MAX 32
#define NR_BUILTIN_GPIO AR7_GPIO_MAX
extern int gpio_request(unsigned gpio, const char *label); #define gpio_to_irq(gpio) NULL
extern void gpio_free(unsigned gpio);
/* Common GPIO layer */ #define gpio_get_value __gpio_get_value
static inline int gpio_get_value(unsigned gpio) #define gpio_set_value __gpio_set_value
{
void __iomem *gpio_in =
(void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_INPUT);
return readl(gpio_in) & (1 << gpio); #define gpio_cansleep __gpio_cansleep
}
static inline void gpio_set_value(unsigned gpio, int value)
{
void __iomem *gpio_out =
(void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_OUTPUT);
unsigned tmp;
tmp = readl(gpio_out) & ~(1 << gpio);
if (value)
tmp |= 1 << gpio;
writel(tmp, gpio_out);
}
static inline int gpio_direction_input(unsigned gpio)
{
void __iomem *gpio_dir =
(void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
if (gpio >= AR7_GPIO_MAX)
return -EINVAL;
writel(readl(gpio_dir) | (1 << gpio), gpio_dir);
return 0;
}
static inline int gpio_direction_output(unsigned gpio, int value)
{
void __iomem *gpio_dir =
(void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
if (gpio >= AR7_GPIO_MAX)
return -EINVAL;
gpio_set_value(gpio, value);
writel(readl(gpio_dir) & ~(1 << gpio), gpio_dir);
return 0;
}
static inline int gpio_to_irq(unsigned gpio)
{
return -EINVAL;
}
static inline int irq_to_gpio(unsigned irq)
{
return -EINVAL;
}
/* Board specific GPIO functions */ /* Board specific GPIO functions */
static inline int ar7_gpio_enable(unsigned gpio) int ar7_gpio_enable(unsigned gpio);
{ int ar7_gpio_disable(unsigned gpio);
void __iomem *gpio_en =
(void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
writel(readl(gpio_en) | (1 << gpio), gpio_en);
return 0;
}
static inline int ar7_gpio_disable(unsigned gpio)
{
void __iomem *gpio_en =
(void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
writel(readl(gpio_en) & ~(1 << gpio), gpio_en);
return 0;
}
#include <asm-generic/gpio.h> #include <asm-generic/gpio.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment