diff options
-rw-r--r-- | Documentation/powerpc/dts-bindings/fsl/8xxx_gpio.txt | 40 | ||||
-rw-r--r-- | arch/powerpc/sysdev/Kconfig | 9 | ||||
-rw-r--r-- | arch/powerpc/sysdev/Makefile | 1 | ||||
-rw-r--r-- | arch/powerpc/sysdev/mpc8xxx_gpio.c | 171 |
4 files changed, 221 insertions, 0 deletions
diff --git a/Documentation/powerpc/dts-bindings/fsl/8xxx_gpio.txt b/Documentation/powerpc/dts-bindings/fsl/8xxx_gpio.txt new file mode 100644 index 000000000000..d015dcec4011 --- /dev/null +++ b/Documentation/powerpc/dts-bindings/fsl/8xxx_gpio.txt | |||
@@ -0,0 +1,40 @@ | |||
1 | GPIO controllers on MPC8xxx SoCs | ||
2 | |||
3 | This is for the non-QE/CPM/GUTs GPIO controllers as found on | ||
4 | 8349, 8572, 8610 and compatible. | ||
5 | |||
6 | Every GPIO controller node must have #gpio-cells property defined, | ||
7 | this information will be used to translate gpio-specifiers. | ||
8 | |||
9 | Required properties: | ||
10 | - compatible : "fsl,<CHIP>-gpio" followed by "fsl,mpc8349-gpio" for | ||
11 | 83xx, "fsl,mpc8572-gpio" for 85xx and "fsl,mpc8610-gpio" for 86xx. | ||
12 | - #gpio-cells : Should be two. The first cell is the pin number and the | ||
13 | second cell is used to specify optional parameters (currently unused). | ||
14 | - interrupts : Interrupt mapping for GPIO IRQ (currently unused). | ||
15 | - interrupt-parent : Phandle for the interrupt controller that | ||
16 | services interrupts for this device. | ||
17 | - gpio-controller : Marks the port as GPIO controller. | ||
18 | |||
19 | Example of gpio-controller nodes for a MPC8347 SoC: | ||
20 | |||
21 | gpio1: gpio-controller@c00 { | ||
22 | #gpio-cells = <2>; | ||
23 | compatible = "fsl,mpc8347-gpio", "fsl,mpc8349-gpio"; | ||
24 | reg = <0xc00 0x100>; | ||
25 | interrupts = <74 0x8>; | ||
26 | interrupt-parent = <&ipic>; | ||
27 | gpio-controller; | ||
28 | }; | ||
29 | |||
30 | gpio2: gpio-controller@d00 { | ||
31 | #gpio-cells = <2>; | ||
32 | compatible = "fsl,mpc8347-gpio", "fsl,mpc8349-gpio"; | ||
33 | reg = <0xd00 0x100>; | ||
34 | interrupts = <75 0x8>; | ||
35 | interrupt-parent = <&ipic>; | ||
36 | gpio-controller; | ||
37 | }; | ||
38 | |||
39 | See booting-without-of.txt for details of how to specify GPIO | ||
40 | information for devices. | ||
diff --git a/arch/powerpc/sysdev/Kconfig b/arch/powerpc/sysdev/Kconfig index 396582835cb5..d0e7bb05c3a4 100644 --- a/arch/powerpc/sysdev/Kconfig +++ b/arch/powerpc/sysdev/Kconfig | |||
@@ -7,6 +7,15 @@ config PPC4xx_PCI_EXPRESS | |||
7 | depends on PCI && 4xx | 7 | depends on PCI && 4xx |
8 | default n | 8 | default n |
9 | 9 | ||
10 | config MPC8xxx_GPIO | ||
11 | bool "MPC8xxx GPIO support" | ||
12 | depends on PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || PPC_85xx || PPC_86xx | ||
13 | select GENERIC_GPIO | ||
14 | select ARCH_REQUIRE_GPIOLIB | ||
15 | help | ||
16 | Say Y here if you're going to use hardware that connects to the | ||
17 | MPC831x/834x/837x/8572/8610 GPIOs. | ||
18 | |||
10 | config PPC_MSI_BITMAP | 19 | config PPC_MSI_BITMAP |
11 | bool | 20 | bool |
12 | depends on PCI_MSI | 21 | depends on PCI_MSI |
diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile index b6c269eb2650..55618ba9eff0 100644 --- a/arch/powerpc/sysdev/Makefile +++ b/arch/powerpc/sysdev/Makefile | |||
@@ -16,6 +16,7 @@ obj-$(CONFIG_FSL_SOC) += fsl_soc.o | |||
16 | obj-$(CONFIG_FSL_PCI) += fsl_pci.o $(fsl-msi-obj-y) | 16 | obj-$(CONFIG_FSL_PCI) += fsl_pci.o $(fsl-msi-obj-y) |
17 | obj-$(CONFIG_FSL_LBC) += fsl_lbc.o | 17 | obj-$(CONFIG_FSL_LBC) += fsl_lbc.o |
18 | obj-$(CONFIG_FSL_GTM) += fsl_gtm.o | 18 | obj-$(CONFIG_FSL_GTM) += fsl_gtm.o |
19 | obj-$(CONFIG_MPC8xxx_GPIO) += mpc8xxx_gpio.o | ||
19 | obj-$(CONFIG_RAPIDIO) += fsl_rio.o | 20 | obj-$(CONFIG_RAPIDIO) += fsl_rio.o |
20 | obj-$(CONFIG_TSI108_BRIDGE) += tsi108_pci.o tsi108_dev.o | 21 | obj-$(CONFIG_TSI108_BRIDGE) += tsi108_pci.o tsi108_dev.o |
21 | obj-$(CONFIG_QUICC_ENGINE) += qe_lib/ | 22 | obj-$(CONFIG_QUICC_ENGINE) += qe_lib/ |
diff --git a/arch/powerpc/sysdev/mpc8xxx_gpio.c b/arch/powerpc/sysdev/mpc8xxx_gpio.c new file mode 100644 index 000000000000..103eace36194 --- /dev/null +++ b/arch/powerpc/sysdev/mpc8xxx_gpio.c | |||
@@ -0,0 +1,171 @@ | |||
1 | /* | ||
2 | * GPIOs on MPC8349/8572/8610 and compatible | ||
3 | * | ||
4 | * Copyright (C) 2008 Peter Korsgaard <jacmet@sunsite.dk> | ||
5 | * | ||
6 | * This file is licensed under the terms of the GNU General Public License | ||
7 | * version 2. This program is licensed "as is" without any warranty of any | ||
8 | * kind, whether express or implied. | ||
9 | */ | ||
10 | |||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/init.h> | ||
13 | #include <linux/spinlock.h> | ||
14 | #include <linux/io.h> | ||
15 | #include <linux/of.h> | ||
16 | #include <linux/of_gpio.h> | ||
17 | #include <linux/gpio.h> | ||
18 | |||
19 | #define MPC8XXX_GPIO_PINS 32 | ||
20 | |||
21 | #define GPIO_DIR 0x00 | ||
22 | #define GPIO_ODR 0x04 | ||
23 | #define GPIO_DAT 0x08 | ||
24 | #define GPIO_IER 0x0c | ||
25 | #define GPIO_IMR 0x10 | ||
26 | #define GPIO_ICR 0x14 | ||
27 | |||
28 | struct mpc8xxx_gpio_chip { | ||
29 | struct of_mm_gpio_chip mm_gc; | ||
30 | spinlock_t lock; | ||
31 | |||
32 | /* | ||
33 | * shadowed data register to be able to clear/set output pins in | ||
34 | * open drain mode safely | ||
35 | */ | ||
36 | u32 data; | ||
37 | }; | ||
38 | |||
39 | static inline u32 mpc8xxx_gpio2mask(unsigned int gpio) | ||
40 | { | ||
41 | return 1u << (MPC8XXX_GPIO_PINS - 1 - gpio); | ||
42 | } | ||
43 | |||
44 | static inline struct mpc8xxx_gpio_chip * | ||
45 | to_mpc8xxx_gpio_chip(struct of_mm_gpio_chip *mm) | ||
46 | { | ||
47 | return container_of(mm, struct mpc8xxx_gpio_chip, mm_gc); | ||
48 | } | ||
49 | |||
50 | static void mpc8xxx_gpio_save_regs(struct of_mm_gpio_chip *mm) | ||
51 | { | ||
52 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); | ||
53 | |||
54 | mpc8xxx_gc->data = in_be32(mm->regs + GPIO_DAT); | ||
55 | } | ||
56 | |||
57 | static int mpc8xxx_gpio_get(struct gpio_chip *gc, unsigned int gpio) | ||
58 | { | ||
59 | struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); | ||
60 | |||
61 | return in_be32(mm->regs + GPIO_DAT) & mpc8xxx_gpio2mask(gpio); | ||
62 | } | ||
63 | |||
64 | static void mpc8xxx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) | ||
65 | { | ||
66 | struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); | ||
67 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); | ||
68 | unsigned long flags; | ||
69 | |||
70 | spin_lock_irqsave(&mpc8xxx_gc->lock, flags); | ||
71 | |||
72 | if (val) | ||
73 | mpc8xxx_gc->data |= mpc8xxx_gpio2mask(gpio); | ||
74 | else | ||
75 | mpc8xxx_gc->data &= ~mpc8xxx_gpio2mask(gpio); | ||
76 | |||
77 | out_be32(mm->regs + GPIO_DAT, mpc8xxx_gc->data); | ||
78 | |||
79 | spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); | ||
80 | } | ||
81 | |||
82 | static int mpc8xxx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio) | ||
83 | { | ||
84 | struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); | ||
85 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); | ||
86 | unsigned long flags; | ||
87 | |||
88 | spin_lock_irqsave(&mpc8xxx_gc->lock, flags); | ||
89 | |||
90 | clrbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio)); | ||
91 | |||
92 | spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); | ||
93 | |||
94 | return 0; | ||
95 | } | ||
96 | |||
97 | static int mpc8xxx_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) | ||
98 | { | ||
99 | struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); | ||
100 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); | ||
101 | unsigned long flags; | ||
102 | |||
103 | mpc8xxx_gpio_set(gc, gpio, val); | ||
104 | |||
105 | spin_lock_irqsave(&mpc8xxx_gc->lock, flags); | ||
106 | |||
107 | setbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio)); | ||
108 | |||
109 | spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); | ||
110 | |||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | static void __init mpc8xxx_add_controller(struct device_node *np) | ||
115 | { | ||
116 | struct mpc8xxx_gpio_chip *mpc8xxx_gc; | ||
117 | struct of_mm_gpio_chip *mm_gc; | ||
118 | struct of_gpio_chip *of_gc; | ||
119 | struct gpio_chip *gc; | ||
120 | int ret; | ||
121 | |||
122 | mpc8xxx_gc = kzalloc(sizeof(*mpc8xxx_gc), GFP_KERNEL); | ||
123 | if (!mpc8xxx_gc) { | ||
124 | ret = -ENOMEM; | ||
125 | goto err; | ||
126 | } | ||
127 | |||
128 | spin_lock_init(&mpc8xxx_gc->lock); | ||
129 | |||
130 | mm_gc = &mpc8xxx_gc->mm_gc; | ||
131 | of_gc = &mm_gc->of_gc; | ||
132 | gc = &of_gc->gc; | ||
133 | |||
134 | mm_gc->save_regs = mpc8xxx_gpio_save_regs; | ||
135 | of_gc->gpio_cells = 2; | ||
136 | gc->ngpio = MPC8XXX_GPIO_PINS; | ||
137 | gc->direction_input = mpc8xxx_gpio_dir_in; | ||
138 | gc->direction_output = mpc8xxx_gpio_dir_out; | ||
139 | gc->get = mpc8xxx_gpio_get; | ||
140 | gc->set = mpc8xxx_gpio_set; | ||
141 | |||
142 | ret = of_mm_gpiochip_add(np, mm_gc); | ||
143 | if (ret) | ||
144 | goto err; | ||
145 | |||
146 | return; | ||
147 | |||
148 | err: | ||
149 | pr_err("%s: registration failed with status %d\n", | ||
150 | np->full_name, ret); | ||
151 | kfree(mpc8xxx_gc); | ||
152 | |||
153 | return; | ||
154 | } | ||
155 | |||
156 | static int __init mpc8xxx_add_gpiochips(void) | ||
157 | { | ||
158 | struct device_node *np; | ||
159 | |||
160 | for_each_compatible_node(np, NULL, "fsl,mpc8349-gpio") | ||
161 | mpc8xxx_add_controller(np); | ||
162 | |||
163 | for_each_compatible_node(np, NULL, "fsl,mpc8572-gpio") | ||
164 | mpc8xxx_add_controller(np); | ||
165 | |||
166 | for_each_compatible_node(np, NULL, "fsl,mpc8610-gpio") | ||
167 | mpc8xxx_add_controller(np); | ||
168 | |||
169 | return 0; | ||
170 | } | ||
171 | arch_initcall(mpc8xxx_add_gpiochips); | ||