11 #include <linux/kernel.h>
13 #include <linux/module.h>
20 #define DRV_NAME "cs5535-gpio"
39 #define GPIO_DEFAULT_MASK 0x0F7FFFFF
45 static struct cs5535_gpio_chip {
46 struct gpio_chip
chip;
59 static void errata_outl(
struct cs5535_gpio_chip *
chip,
u32 val,
62 unsigned long addr = chip->base + 0x80 +
reg;
75 val |= (
inl(addr) & 0xffff);
77 val |= (
inl(addr) ^ (val >> 16));
82 static void __cs5535_gpio_set(
struct cs5535_gpio_chip *chip,
unsigned offset,
87 outl(1 << offset, chip->base + reg);
90 errata_outl(chip, 1 << (offset - 16), reg);
95 struct cs5535_gpio_chip *chip = &cs5535_gpio_chip;
99 __cs5535_gpio_set(chip, offset, reg);
100 spin_unlock_irqrestore(&chip->lock, flags);
104 static void __cs5535_gpio_clear(
struct cs5535_gpio_chip *chip,
unsigned offset,
109 outl(1 << (offset + 16), chip->base + reg);
112 errata_outl(chip, 1 << offset, reg);
117 struct cs5535_gpio_chip *chip = &cs5535_gpio_chip;
121 __cs5535_gpio_clear(chip, offset, reg);
122 spin_unlock_irqrestore(&chip->lock, flags);
128 struct cs5535_gpio_chip *chip = &cs5535_gpio_chip;
135 val =
inl(chip->base + reg);
138 val =
inl(chip->base + 0x80 + reg);
141 spin_unlock_irqrestore(&chip->lock, flags);
143 return (val & (1 << offset)) ? 1 : 0;
151 if (group > 7 || irq > 15)
156 lo &= ~(0xF << (group * 4));
157 lo |= (irq & 0xF) << (group * 4);
166 struct cs5535_gpio_chip *chip = &cs5535_gpio_chip;
173 else if (offset >= 16)
175 else if (offset >= 8)
181 val =
inl(chip->base + offset);
184 val &= ~(0xF << shift);
187 val |= ((pair & 7) << shift);
191 val |= (1 << (shift + 3));
193 outl(val, chip->base + offset);
194 spin_unlock_irqrestore(&chip->lock, flags);
202 static int chip_gpio_request(
struct gpio_chip *
c,
unsigned offset)
204 struct cs5535_gpio_chip *chip = (
struct cs5535_gpio_chip *) c;
210 if ((
mask & (1 << offset)) == 0) {
212 "pin %u is not available (check mask)\n", offset);
213 spin_unlock_irqrestore(&chip->lock, flags);
224 spin_unlock_irqrestore(&chip->lock, flags);
229 static int chip_gpio_get(
struct gpio_chip *chip,
unsigned offset)
234 static void chip_gpio_set(
struct gpio_chip *chip,
unsigned offset,
int val)
242 static int chip_direction_input(
struct gpio_chip *c,
unsigned offset)
244 struct cs5535_gpio_chip *chip = (
struct cs5535_gpio_chip *) c;
250 spin_unlock_irqrestore(&chip->lock, flags);
255 static int chip_direction_output(
struct gpio_chip *c,
unsigned offset,
int val)
257 struct cs5535_gpio_chip *chip = (
struct cs5535_gpio_chip *) c;
269 spin_unlock_irqrestore(&chip->lock, flags);
274 static const char *
const cs5535_gpio_names[] = {
275 "GPIO0",
"GPIO1",
"GPIO2",
"GPIO3",
276 "GPIO4",
"GPIO5",
"GPIO6",
"GPIO7",
277 "GPIO8",
"GPIO9",
"GPIO10",
"GPIO11",
278 "GPIO12",
"GPIO13",
"GPIO14",
"GPIO15",
279 "GPIO16",
"GPIO17",
"GPIO18",
"GPIO19",
280 "GPIO20",
"GPIO21",
"GPIO22",
NULL,
281 "GPIO24",
"GPIO25",
"GPIO26",
"GPIO27",
285 static struct cs5535_gpio_chip cs5535_gpio_chip = {
292 .names = cs5535_gpio_names,
293 .request = chip_gpio_request,
295 .get = chip_gpio_get,
296 .set = chip_gpio_set,
298 .direction_input = chip_direction_input,
299 .direction_output = chip_direction_output,
318 dev_err(&pdev->
dev,
"can't fetch device resource info\n");
323 dev_err(&pdev->
dev,
"can't request region\n");
328 cs5535_gpio_chip.base = res->
start;
329 cs5535_gpio_chip.pdev = pdev;
332 dev_info(&pdev->
dev,
"reserved resource region %pR\n", res);
341 if (mask_orig !=
mask)
342 dev_info(&pdev->
dev,
"mask changed from 0x%08lX to 0x%08lX\n",
366 dev_err(&pdev->
dev,
"unable to remove gpio_chip?\n");
380 .probe = cs5535_gpio_probe,