diff options
author | Kyungmin Park <kyungmin.park@samsung.com> | 2011-05-23 04:27:38 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2011-05-26 19:31:22 -0400 |
commit | fed6a0224714bd414bff91833e0bd5775a3e9c66 (patch) | |
tree | 24019b4f2b596c802167cb4484186e20a545e206 /drivers/gpio | |
parent | bc6f5cf6484a509cfe0533b8ddf8b8ca60f35557 (diff) |
gpio: Move to Samsung common GPIO library to drivers/gpio
It's common gpiolib for recent Samsung SoCs. Move to drivers/gpio
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/Kconfig | 6 | ||||
-rw-r--r-- | drivers/gpio/Makefile | 1 | ||||
-rw-r--r-- | drivers/gpio/gpio-plat-samsung.c | 206 |
3 files changed, 213 insertions, 0 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index ebd1124b0764..3735c051074f 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
@@ -86,6 +86,12 @@ config GPIO_IT8761E | |||
86 | help | 86 | help |
87 | Say yes here to support GPIO functionality of IT8761E super I/O chip. | 87 | Say yes here to support GPIO functionality of IT8761E super I/O chip. |
88 | 88 | ||
89 | config GPIO_PLAT_SAMSUNG | ||
90 | bool "Samsung SoCs GPIO library support" | ||
91 | default y if SAMSUNG_GPIOLIB_4BIT | ||
92 | help | ||
93 | Say yes here to support Samsung SoCs GPIO library | ||
94 | |||
89 | config GPIO_PL061 | 95 | config GPIO_PL061 |
90 | bool "PrimeCell PL061 GPIO support" | 96 | bool "PrimeCell PL061 GPIO support" |
91 | depends on ARM_AMBA | 97 | depends on ARM_AMBA |
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 7481e7da2adb..426483f60d63 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
@@ -8,6 +8,7 @@ obj-$(CONFIG_GPIO_ADP5520) += adp5520-gpio.o | |||
8 | obj-$(CONFIG_GPIO_ADP5588) += adp5588-gpio.o | 8 | obj-$(CONFIG_GPIO_ADP5588) += adp5588-gpio.o |
9 | obj-$(CONFIG_GPIO_BASIC_MMIO_CORE) += basic_mmio_gpio.o | 9 | obj-$(CONFIG_GPIO_BASIC_MMIO_CORE) += basic_mmio_gpio.o |
10 | obj-$(CONFIG_GPIO_BASIC_MMIO) += basic_mmio_gpio.o | 10 | obj-$(CONFIG_GPIO_BASIC_MMIO) += basic_mmio_gpio.o |
11 | obj-$(CONFIG_GPIO_PLAT_SAMSUNG) += gpio-plat-samsung.o | ||
11 | obj-$(CONFIG_GPIO_LANGWELL) += langwell_gpio.o | 12 | obj-$(CONFIG_GPIO_LANGWELL) += langwell_gpio.o |
12 | obj-$(CONFIG_GPIO_MAX730X) += max730x.o | 13 | obj-$(CONFIG_GPIO_MAX730X) += max730x.o |
13 | obj-$(CONFIG_GPIO_MAX7300) += max7300.o | 14 | obj-$(CONFIG_GPIO_MAX7300) += max7300.o |
diff --git a/drivers/gpio/gpio-plat-samsung.c b/drivers/gpio/gpio-plat-samsung.c new file mode 100644 index 000000000000..ea37c0461788 --- /dev/null +++ b/drivers/gpio/gpio-plat-samsung.c | |||
@@ -0,0 +1,206 @@ | |||
1 | /* arch/arm/plat-samsung/gpiolib.c | ||
2 | * | ||
3 | * Copyright 2008 Openmoko, Inc. | ||
4 | * Copyright 2008 Simtec Electronics | ||
5 | * Ben Dooks <ben@simtec.co.uk> | ||
6 | * http://armlinux.simtec.co.uk/ | ||
7 | * | ||
8 | * Copyright (c) 2009 Samsung Electronics Co., Ltd. | ||
9 | * http://www.samsung.com/ | ||
10 | * | ||
11 | * SAMSUNG - GPIOlib support | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License version 2 as | ||
15 | * published by the Free Software Foundation. | ||
16 | */ | ||
17 | |||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/irq.h> | ||
20 | #include <linux/io.h> | ||
21 | #include <linux/gpio.h> | ||
22 | #include <plat/gpio-core.h> | ||
23 | #include <plat/gpio-cfg.h> | ||
24 | #include <plat/gpio-cfg-helpers.h> | ||
25 | |||
26 | #ifndef DEBUG_GPIO | ||
27 | #define gpio_dbg(x...) do { } while (0) | ||
28 | #else | ||
29 | #define gpio_dbg(x...) printk(KERN_DEBUG x) | ||
30 | #endif | ||
31 | |||
32 | /* The samsung_gpiolib_4bit routines are to control the gpio banks where | ||
33 | * the gpio configuration register (GPxCON) has 4 bits per GPIO, as the | ||
34 | * following example: | ||
35 | * | ||
36 | * base + 0x00: Control register, 4 bits per gpio | ||
37 | * gpio n: 4 bits starting at (4*n) | ||
38 | * 0000 = input, 0001 = output, others mean special-function | ||
39 | * base + 0x04: Data register, 1 bit per gpio | ||
40 | * bit n: data bit n | ||
41 | * | ||
42 | * Note, since the data register is one bit per gpio and is at base + 0x4 | ||
43 | * we can use s3c_gpiolib_get and s3c_gpiolib_set to change the state of | ||
44 | * the output. | ||
45 | */ | ||
46 | |||
47 | static int samsung_gpiolib_4bit_input(struct gpio_chip *chip, | ||
48 | unsigned int offset) | ||
49 | { | ||
50 | struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip); | ||
51 | void __iomem *base = ourchip->base; | ||
52 | unsigned long con; | ||
53 | |||
54 | con = __raw_readl(base + GPIOCON_OFF); | ||
55 | con &= ~(0xf << con_4bit_shift(offset)); | ||
56 | __raw_writel(con, base + GPIOCON_OFF); | ||
57 | |||
58 | gpio_dbg("%s: %p: CON now %08lx\n", __func__, base, con); | ||
59 | |||
60 | return 0; | ||
61 | } | ||
62 | |||
63 | static int samsung_gpiolib_4bit_output(struct gpio_chip *chip, | ||
64 | unsigned int offset, int value) | ||
65 | { | ||
66 | struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip); | ||
67 | void __iomem *base = ourchip->base; | ||
68 | unsigned long con; | ||
69 | unsigned long dat; | ||
70 | |||
71 | con = __raw_readl(base + GPIOCON_OFF); | ||
72 | con &= ~(0xf << con_4bit_shift(offset)); | ||
73 | con |= 0x1 << con_4bit_shift(offset); | ||
74 | |||
75 | dat = __raw_readl(base + GPIODAT_OFF); | ||
76 | |||
77 | if (value) | ||
78 | dat |= 1 << offset; | ||
79 | else | ||
80 | dat &= ~(1 << offset); | ||
81 | |||
82 | __raw_writel(dat, base + GPIODAT_OFF); | ||
83 | __raw_writel(con, base + GPIOCON_OFF); | ||
84 | __raw_writel(dat, base + GPIODAT_OFF); | ||
85 | |||
86 | gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat); | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | /* The next set of routines are for the case where the GPIO configuration | ||
92 | * registers are 4 bits per GPIO but there is more than one register (the | ||
93 | * bank has more than 8 GPIOs. | ||
94 | * | ||
95 | * This case is the similar to the 4 bit case, but the registers are as | ||
96 | * follows: | ||
97 | * | ||
98 | * base + 0x00: Control register, 4 bits per gpio (lower 8 GPIOs) | ||
99 | * gpio n: 4 bits starting at (4*n) | ||
100 | * 0000 = input, 0001 = output, others mean special-function | ||
101 | * base + 0x04: Control register, 4 bits per gpio (up to 8 additions GPIOs) | ||
102 | * gpio n: 4 bits starting at (4*n) | ||
103 | * 0000 = input, 0001 = output, others mean special-function | ||
104 | * base + 0x08: Data register, 1 bit per gpio | ||
105 | * bit n: data bit n | ||
106 | * | ||
107 | * To allow us to use the s3c_gpiolib_get and s3c_gpiolib_set routines we | ||
108 | * store the 'base + 0x4' address so that these routines see the data | ||
109 | * register at ourchip->base + 0x04. | ||
110 | */ | ||
111 | |||
112 | static int samsung_gpiolib_4bit2_input(struct gpio_chip *chip, | ||
113 | unsigned int offset) | ||
114 | { | ||
115 | struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip); | ||
116 | void __iomem *base = ourchip->base; | ||
117 | void __iomem *regcon = base; | ||
118 | unsigned long con; | ||
119 | |||
120 | if (offset > 7) | ||
121 | offset -= 8; | ||
122 | else | ||
123 | regcon -= 4; | ||
124 | |||
125 | con = __raw_readl(regcon); | ||
126 | con &= ~(0xf << con_4bit_shift(offset)); | ||
127 | __raw_writel(con, regcon); | ||
128 | |||
129 | gpio_dbg("%s: %p: CON %08lx\n", __func__, base, con); | ||
130 | |||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | static int samsung_gpiolib_4bit2_output(struct gpio_chip *chip, | ||
135 | unsigned int offset, int value) | ||
136 | { | ||
137 | struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip); | ||
138 | void __iomem *base = ourchip->base; | ||
139 | void __iomem *regcon = base; | ||
140 | unsigned long con; | ||
141 | unsigned long dat; | ||
142 | unsigned con_offset = offset; | ||
143 | |||
144 | if (con_offset > 7) | ||
145 | con_offset -= 8; | ||
146 | else | ||
147 | regcon -= 4; | ||
148 | |||
149 | con = __raw_readl(regcon); | ||
150 | con &= ~(0xf << con_4bit_shift(con_offset)); | ||
151 | con |= 0x1 << con_4bit_shift(con_offset); | ||
152 | |||
153 | dat = __raw_readl(base + GPIODAT_OFF); | ||
154 | |||
155 | if (value) | ||
156 | dat |= 1 << offset; | ||
157 | else | ||
158 | dat &= ~(1 << offset); | ||
159 | |||
160 | __raw_writel(dat, base + GPIODAT_OFF); | ||
161 | __raw_writel(con, regcon); | ||
162 | __raw_writel(dat, base + GPIODAT_OFF); | ||
163 | |||
164 | gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat); | ||
165 | |||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | void __init samsung_gpiolib_add_4bit(struct s3c_gpio_chip *chip) | ||
170 | { | ||
171 | chip->chip.direction_input = samsung_gpiolib_4bit_input; | ||
172 | chip->chip.direction_output = samsung_gpiolib_4bit_output; | ||
173 | chip->pm = __gpio_pm(&s3c_gpio_pm_4bit); | ||
174 | } | ||
175 | |||
176 | void __init samsung_gpiolib_add_4bit2(struct s3c_gpio_chip *chip) | ||
177 | { | ||
178 | chip->chip.direction_input = samsung_gpiolib_4bit2_input; | ||
179 | chip->chip.direction_output = samsung_gpiolib_4bit2_output; | ||
180 | chip->pm = __gpio_pm(&s3c_gpio_pm_4bit); | ||
181 | } | ||
182 | |||
183 | void __init samsung_gpiolib_add_4bit_chips(struct s3c_gpio_chip *chip, | ||
184 | int nr_chips) | ||
185 | { | ||
186 | for (; nr_chips > 0; nr_chips--, chip++) { | ||
187 | samsung_gpiolib_add_4bit(chip); | ||
188 | s3c_gpiolib_add(chip); | ||
189 | } | ||
190 | } | ||
191 | |||
192 | void __init samsung_gpiolib_add_4bit2_chips(struct s3c_gpio_chip *chip, | ||
193 | int nr_chips) | ||
194 | { | ||
195 | for (; nr_chips > 0; nr_chips--, chip++) { | ||
196 | samsung_gpiolib_add_4bit2(chip); | ||
197 | s3c_gpiolib_add(chip); | ||
198 | } | ||
199 | } | ||
200 | |||
201 | void __init samsung_gpiolib_add_2bit_chips(struct s3c_gpio_chip *chip, | ||
202 | int nr_chips) | ||
203 | { | ||
204 | for (; nr_chips > 0; nr_chips--, chip++) | ||
205 | s3c_gpiolib_add(chip); | ||
206 | } | ||