2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7 * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/spinlock.h>
13 #include <linux/platform_device.h>
14 #include <linux/gpio.h>
16 #include <bcm63xx_cpu.h>
17 #include <bcm63xx_gpio.h>
18 #include <bcm63xx_io.h>
19 #include <bcm63xx_regs.h>
21 static void bcm63xx_gpio_set(struct gpio_chip *chip,
22 unsigned gpio, int val)
29 if (gpio >= chip->ngpio)
33 reg = GPIO_DATA_LO_REG;
36 reg = GPIO_DATA_HI_REG;
37 mask = 1 << (gpio - 32);
40 local_irq_save(flags);
41 tmp = bcm_gpio_readl(reg);
46 bcm_gpio_writel(tmp, reg);
47 local_irq_restore(flags);
50 static int bcm63xx_gpio_get(struct gpio_chip *chip, unsigned gpio)
55 if (gpio >= chip->ngpio)
59 reg = GPIO_DATA_LO_REG;
62 reg = GPIO_DATA_HI_REG;
63 mask = 1 << (gpio - 32);
66 return !!(bcm_gpio_readl(reg) & mask);
69 static int bcm63xx_gpio_set_direction(struct gpio_chip *chip,
70 unsigned gpio, int dir)
77 if (gpio >= chip->ngpio)
81 reg = GPIO_CTL_LO_REG;
84 reg = GPIO_CTL_HI_REG;
85 mask = 1 << (gpio - 32);
88 local_irq_save(flags);
89 tmp = bcm_gpio_readl(reg);
90 if (dir == GPIO_DIR_IN)
94 bcm_gpio_writel(tmp, reg);
95 local_irq_restore(flags);
100 static int bcm63xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
102 return bcm63xx_gpio_set_direction(chip, gpio, GPIO_DIR_IN);
105 static int bcm63xx_gpio_direction_output(struct gpio_chip *chip,
106 unsigned gpio, int value)
108 bcm63xx_gpio_set(chip, gpio, value);
109 return bcm63xx_gpio_set_direction(chip, gpio, GPIO_DIR_OUT);
113 static struct gpio_chip bcm63xx_gpio_chip = {
114 .label = "bcm63xx-gpio",
115 .direction_input = bcm63xx_gpio_direction_input,
116 .direction_output = bcm63xx_gpio_direction_output,
117 .get = bcm63xx_gpio_get,
118 .set = bcm63xx_gpio_set,
120 .ngpio = BCM63XX_GPIO_COUNT,
123 static int __init bcm63xx_gpio_init(void)
125 printk(KERN_INFO "registering %d GPIOs\n", BCM63XX_GPIO_COUNT);
126 return gpiochip_add(&bcm63xx_gpio_chip);
128 arch_initcall(bcm63xx_gpio_init);