1 /* linux/arch/arm/plat-s3c/gpio.c
3 * Copyright 2008 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 * http://armlinux.simtec.co.uk/
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/kernel.h>
15 #include <linux/init.h>
17 #include <linux/gpio.h>
19 #include <plat/gpio-core.h>
21 /* Default routines for controlling GPIO, based on the original S3C24XX
22 * GPIO functions which deal with the case where each gpio bank of the
23 * chip is as following:
25 * base + 0x00: Control register, 2 bits per gpio
26 * gpio n: 2 bits starting at (2*n)
27 * 00 = input, 01 = output, others mean special-function
28 * base + 0x04: Data register, 1 bit per gpio
32 static int s3c_gpiolib_input(struct gpio_chip *chip, unsigned offset)
34 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
35 void __iomem *base = ourchip->base;
39 local_irq_save(flags);
41 con = __raw_readl(base + 0x00);
42 con &= ~(3 << (offset * 2));
44 __raw_writel(con, base + 0x00);
46 local_irq_restore(flags);
50 static int s3c_gpiolib_output(struct gpio_chip *chip,
51 unsigned offset, int value)
53 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
54 void __iomem *base = ourchip->base;
59 local_irq_save(flags);
61 dat = __raw_readl(base + 0x04);
62 dat &= ~(1 << offset);
65 __raw_writel(dat, base + 0x04);
67 con = __raw_readl(base + 0x00);
68 con &= ~(3 << (offset * 2));
69 con |= 1 << (offset * 2);
71 __raw_writel(con, base + 0x00);
72 __raw_writel(dat, base + 0x04);
74 local_irq_restore(flags);
78 static void s3c_gpiolib_set(struct gpio_chip *chip,
79 unsigned offset, int value)
81 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
82 void __iomem *base = ourchip->base;
86 local_irq_save(flags);
88 dat = __raw_readl(base + 0x04);
89 dat &= ~(1 << offset);
92 __raw_writel(dat, base + 0x04);
94 local_irq_restore(flags);
97 static int s3c_gpiolib_get(struct gpio_chip *chip, unsigned offset)
99 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
102 val = __raw_readl(ourchip->base + 0x04);
109 __init void s3c_gpiolib_add(struct s3c_gpio_chip *chip)
111 struct gpio_chip *gc = &chip->chip;
117 if (!gc->direction_input)
118 gc->direction_input = s3c_gpiolib_input;
119 if (!gc->direction_output)
120 gc->direction_output = s3c_gpiolib_output;
122 gc->set = s3c_gpiolib_set;
124 gc->get = s3c_gpiolib_get;
126 /* gpiochip_add() prints own failure message on error. */