提交 a994955c 编写于 作者: M Mark A. Greer 提交者: Kevin Hilman

davinci: Make GPIO code more generic

The current gpio code needs to know the number of
gpio irqs there are and what the bank irq number is.
To determine those values, it checks the SoC type.

It also assumes that the base address and the number
of irqs the interrupt controller uses is fixed.

To clean up the SoC checks and make it support
different base addresses and interrupt controllers,
have the SoC-specific code set those values in
the soc_info structure and have the gpio code
reference them there.
Signed-off-by: NMark A. Greer <mgreer@mvista.com>
Signed-off-by: NKevin Hilman <khilman@deeprootsystems.com>
上级 951d6f6d
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/gpio.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
...@@ -647,6 +648,9 @@ static struct davinci_soc_info davinci_soc_info_dm355 = { ...@@ -647,6 +648,9 @@ static struct davinci_soc_info davinci_soc_info_dm355 = {
.intc_irq_num = DAVINCI_N_AINTC_IRQ, .intc_irq_num = DAVINCI_N_AINTC_IRQ,
.timer_info = &dm355_timer_info, .timer_info = &dm355_timer_info,
.wdt_base = IO_ADDRESS(DAVINCI_WDOG_BASE), .wdt_base = IO_ADDRESS(DAVINCI_WDOG_BASE),
.gpio_base = IO_ADDRESS(DAVINCI_GPIO_BASE),
.gpio_num = 104,
.gpio_irq = IRQ_DM355_GPIOBNK0,
}; };
void __init dm355_init(void) void __init dm355_init(void)
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/gpio.h>
#include <asm/mach/map.h> #include <asm/mach/map.h>
...@@ -590,6 +591,9 @@ static struct davinci_soc_info davinci_soc_info_dm644x = { ...@@ -590,6 +591,9 @@ static struct davinci_soc_info davinci_soc_info_dm644x = {
.intc_irq_num = DAVINCI_N_AINTC_IRQ, .intc_irq_num = DAVINCI_N_AINTC_IRQ,
.timer_info = &dm644x_timer_info, .timer_info = &dm644x_timer_info,
.wdt_base = IO_ADDRESS(DAVINCI_WDOG_BASE), .wdt_base = IO_ADDRESS(DAVINCI_WDOG_BASE),
.gpio_base = IO_ADDRESS(DAVINCI_GPIO_BASE),
.gpio_num = 71,
.gpio_irq = IRQ_GPIOBNK0,
}; };
void __init dm644x_init(void) void __init dm644x_init(void)
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/gpio.h>
#include <asm/mach/map.h> #include <asm/mach/map.h>
...@@ -569,6 +570,9 @@ static struct davinci_soc_info davinci_soc_info_dm646x = { ...@@ -569,6 +570,9 @@ static struct davinci_soc_info davinci_soc_info_dm646x = {
.intc_irq_num = DAVINCI_N_AINTC_IRQ, .intc_irq_num = DAVINCI_N_AINTC_IRQ,
.timer_info = &dm646x_timer_info, .timer_info = &dm646x_timer_info,
.wdt_base = IO_ADDRESS(DAVINCI_WDOG_BASE), .wdt_base = IO_ADDRESS(DAVINCI_WDOG_BASE),
.gpio_base = IO_ADDRESS(DAVINCI_GPIO_BASE),
.gpio_num = 43, /* Only 33 usable */
.gpio_irq = IRQ_DM646X_GPIOBNK0,
}; };
void __init dm646x_init(void) void __init dm646x_init(void)
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <mach/cputype.h> #include <mach/cputype.h>
#include <mach/irqs.h> #include <mach/irqs.h>
#include <mach/hardware.h> #include <mach/hardware.h>
#include <mach/common.h>
#include <mach/gpio.h> #include <mach/gpio.h>
#include <asm/mach/irq.h> #include <asm/mach/irq.h>
...@@ -37,8 +38,6 @@ struct davinci_gpio { ...@@ -37,8 +38,6 @@ struct davinci_gpio {
static struct davinci_gpio chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)]; static struct davinci_gpio chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)];
static unsigned __initdata ngpio;
/* create a non-inlined version */ /* create a non-inlined version */
static struct gpio_controller __iomem * __init gpio2controller(unsigned gpio) static struct gpio_controller __iomem * __init gpio2controller(unsigned gpio)
{ {
...@@ -116,23 +115,16 @@ davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ...@@ -116,23 +115,16 @@ davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
static int __init davinci_gpio_setup(void) static int __init davinci_gpio_setup(void)
{ {
int i, base; int i, base;
unsigned ngpio;
struct davinci_soc_info *soc_info = &davinci_soc_info;
/* The gpio banks conceptually expose a segmented bitmap, /*
* The gpio banks conceptually expose a segmented bitmap,
* and "ngpio" is one more than the largest zero-based * and "ngpio" is one more than the largest zero-based
* bit index that's valid. * bit index that's valid.
*/ */
if (cpu_is_davinci_dm355()) { /* or dm335() */ ngpio = soc_info->gpio_num;
ngpio = 104; if (ngpio == 0) {
} else if (cpu_is_davinci_dm644x()) { /* or dm337() */
ngpio = 71;
} else if (cpu_is_davinci_dm646x()) {
/* NOTE: each bank has several "reserved" bits,
* unusable as GPIOs. Only 33 of the GPIO numbers
* are usable, and we're not rejecting the others.
*/
ngpio = 43;
} else {
/* if cpu_is_davinci_dm643x() ngpio = 111 */
pr_err("GPIO setup: how many GPIOs?\n"); pr_err("GPIO setup: how many GPIOs?\n");
return -EINVAL; return -EINVAL;
} }
...@@ -279,17 +271,15 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc) ...@@ -279,17 +271,15 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc)
static int __init davinci_gpio_irq_setup(void) static int __init davinci_gpio_irq_setup(void)
{ {
unsigned gpio, irq, bank; unsigned gpio, irq, bank;
unsigned bank_irq;
struct clk *clk; struct clk *clk;
u32 binten = 0; u32 binten = 0;
unsigned ngpio, bank_irq;
struct davinci_soc_info *soc_info = &davinci_soc_info;
ngpio = soc_info->gpio_num;
if (cpu_is_davinci_dm355()) { /* or dm335() */ bank_irq = soc_info->gpio_irq;
bank_irq = IRQ_DM355_GPIOBNK0; if (bank_irq == 0) {
} else if (cpu_is_davinci_dm644x()) {
bank_irq = IRQ_GPIOBNK0;
} else if (cpu_is_davinci_dm646x()) {
bank_irq = IRQ_DM646X_GPIOBNK0;
} else {
printk(KERN_ERR "Don't know first GPIO bank IRQ.\n"); printk(KERN_ERR "Don't know first GPIO bank IRQ.\n");
return -EINVAL; return -EINVAL;
} }
...@@ -329,8 +319,7 @@ static int __init davinci_gpio_irq_setup(void) ...@@ -329,8 +319,7 @@ static int __init davinci_gpio_irq_setup(void)
/* BINTEN -- per-bank interrupt enable. genirq would also let these /* BINTEN -- per-bank interrupt enable. genirq would also let these
* bits be set/cleared dynamically. * bits be set/cleared dynamically.
*/ */
__raw_writel(binten, (void *__iomem) __raw_writel(binten, soc_info->gpio_base + 0x08);
IO_ADDRESS(DAVINCI_GPIO_BASE + 0x08));
printk(KERN_INFO "DaVinci: %d gpio irqs\n", irq - gpio_to_irq(0)); printk(KERN_INFO "DaVinci: %d gpio irqs\n", irq - gpio_to_irq(0));
......
...@@ -58,6 +58,9 @@ struct davinci_soc_info { ...@@ -58,6 +58,9 @@ struct davinci_soc_info {
unsigned long intc_irq_num; unsigned long intc_irq_num;
struct davinci_timer_info *timer_info; struct davinci_timer_info *timer_info;
void __iomem *wdt_base; void __iomem *wdt_base;
void __iomem *gpio_base;
unsigned gpio_num;
unsigned gpio_irq;
}; };
extern struct davinci_soc_info davinci_soc_info; extern struct davinci_soc_info davinci_soc_info;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <asm-generic/gpio.h> #include <asm-generic/gpio.h>
#include <mach/irqs.h> #include <mach/irqs.h>
#include <mach/common.h>
#define DAVINCI_GPIO_BASE 0x01C67000 #define DAVINCI_GPIO_BASE 0x01C67000
...@@ -67,15 +68,16 @@ static inline struct gpio_controller *__iomem ...@@ -67,15 +68,16 @@ static inline struct gpio_controller *__iomem
__gpio_to_controller(unsigned gpio) __gpio_to_controller(unsigned gpio)
{ {
void *__iomem ptr; void *__iomem ptr;
void __iomem *base = davinci_soc_info.gpio_base;
if (gpio < 32 * 1) if (gpio < 32 * 1)
ptr = IO_ADDRESS(DAVINCI_GPIO_BASE + 0x10); ptr = base + 0x10;
else if (gpio < 32 * 2) else if (gpio < 32 * 2)
ptr = IO_ADDRESS(DAVINCI_GPIO_BASE + 0x38); ptr = base + 0x38;
else if (gpio < 32 * 3) else if (gpio < 32 * 3)
ptr = IO_ADDRESS(DAVINCI_GPIO_BASE + 0x60); ptr = base + 0x60;
else if (gpio < 32 * 4) else if (gpio < 32 * 4)
ptr = IO_ADDRESS(DAVINCI_GPIO_BASE + 0x88); ptr = base + 0x88;
else else
ptr = NULL; ptr = NULL;
return ptr; return ptr;
...@@ -142,13 +144,13 @@ static inline int gpio_to_irq(unsigned gpio) ...@@ -142,13 +144,13 @@ static inline int gpio_to_irq(unsigned gpio)
{ {
if (gpio >= DAVINCI_N_GPIO) if (gpio >= DAVINCI_N_GPIO)
return -EINVAL; return -EINVAL;
return DAVINCI_N_AINTC_IRQ + gpio; return davinci_soc_info.intc_irq_num + gpio;
} }
static inline int irq_to_gpio(unsigned irq) static inline int irq_to_gpio(unsigned irq)
{ {
/* caller guarantees gpio_to_irq() succeeded */ /* caller guarantees gpio_to_irq() succeeded */
return irq - DAVINCI_N_AINTC_IRQ; return irq - davinci_soc_info.intc_irq_num;
} }
#endif /* __DAVINCI_GPIO_H */ #endif /* __DAVINCI_GPIO_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册