2 * Infineon/ADMTek ADM8668 WildPass GPIO support
4 * Copyright (C) 2012 Florian Fainelli <florian@openwrt.org>
6 * Licensed under the terms of GPLv2.
9 #include <linux/kernel.h>
10 #include <linux/gpio.h>
15 #define GPIO_MASK 0x3f
18 #define GPIO_OUT_OFS 6
19 #define GPIO_OE_OFS 12
21 struct adm8668_gpio_chip {
23 struct gpio_chip chip;
26 static int adm8668_gpio_dir_out(struct gpio_chip *chip,
27 unsigned offset, int value)
29 struct adm8668_gpio_chip *c =
30 container_of(chip, struct adm8668_gpio_chip, chip);
33 /* clear input, set output enable and output value */
34 mask = __raw_readl(c->base);
35 mask &= ~(1 << offset);
36 mask |= (1 << (offset + GPIO_OE_OFS));
38 mask |= (1 << (offset + GPIO_OUT_OFS));
40 mask &= ~(1 << (offset + GPIO_OUT_OFS));
41 __raw_writel(mask, c->base);
46 static int adm8668_gpio_dir_in(struct gpio_chip *chip,
49 struct adm8668_gpio_chip *c =
50 container_of(chip, struct adm8668_gpio_chip, chip);
53 mask = __raw_readl(c->base);
54 mask &= ~(((1 << (offset + GPIO_OE_OFS)) | (1 << (offset + GPIO_OUT_OFS))));
55 mask |= (1 << offset);
56 __raw_writel(mask, c->base);
61 static void adm8668_gpio_set(struct gpio_chip *chip,
62 unsigned offset, int value)
64 struct adm8668_gpio_chip *c =
65 container_of(chip, struct adm8668_gpio_chip, chip);
68 mask = __raw_readl(c->base);
70 mask |= (1 << (offset + GPIO_OUT_OFS));
72 mask &= ~(1 << (offset + GPIO_OUT_OFS));
73 __raw_writel(mask, c->base);
76 static int adm8668_gpio_get(struct gpio_chip *chip,
79 struct adm8668_gpio_chip *c =
80 container_of(chip, struct adm8668_gpio_chip, chip);
83 value = __raw_readl(c->base) & GPIO_MASK;
85 return value & (1 << offset);
88 static struct adm8668_gpio_chip adm8668_gpio_cpu = {
89 .base = (void __iomem *)KSEG1ADDR(ADM8668_CONFIG_BASE + CRGPIO_REG),
91 .label = "adm8668-cpu-gpio",
92 .direction_output = adm8668_gpio_dir_out,
93 .direction_input = adm8668_gpio_dir_in,
94 .set = adm8668_gpio_set,
95 .get = adm8668_gpio_get,
100 static struct adm8668_gpio_chip adm8668_gpio_wlan = {
101 .base = (void __iomem *)KSEG1ADDR(ADM8668_WLAN_BASE + GPIO_REG),
103 .label = "adm8668-wlan-gpio",
104 .direction_output = adm8668_gpio_dir_out,
105 .direction_input = adm8668_gpio_dir_in,
106 .set = adm8668_gpio_set,
107 .get = adm8668_gpio_get,
113 static int __init adm8668_gpio_init(void)
117 ret = gpiochip_add(&adm8668_gpio_cpu.chip);
121 return gpiochip_add(&adm8668_gpio_wlan.chip);
123 arch_initcall(adm8668_gpio_init);