diff options
author | Baruch Siach <baruch@tkos.co.il> | 2013-12-12 04:18:41 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2013-12-12 08:33:14 -0500 |
commit | 3b31d0eca5fd8d7d485c7cb7319a5cd6a3207726 (patch) | |
tree | b5e0c8075f4f2b0bca12b8d15e8d7048ce2b1168 /drivers/gpio | |
parent | bcc0562c776e4b09c7b9f24cddb8724fbe7a3fa5 (diff) |
gpio: driver for Xtensa GPIO32
GPIO32 is a standard optional extension to the Xtensa architecture
core that provides preconfigured output and input ports for intra
SoC signaling. The GPIO32 option is implemented as 32bit Tensilica
Instruction Extension (TIE) output state called EXPSTATE, and 32bit
input wire called IMPWIRE. This driver treats input and output
states as two distinct devices.
v3:
* Use BUG() in xtensa_impwire_set_value() to indicate that
it should never be called (Linus Walleij)
v2:
* Address the comments of Linus Walleij:
- Add a few comments
- Expand commit log message
- Use the BIT() macro for bit offsets
- Rewrite CPENABLE handling as static inlines
- Use device_initcall()
* Depend on !SMP for reason explained in the comments (Marc Gauthier)
* Use XCHAL_CP_ID_XTIOP to enable/disable GPIO32 only
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/Kconfig | 8 | ||||
-rw-r--r-- | drivers/gpio/Makefile | 1 | ||||
-rw-r--r-- | drivers/gpio/gpio-xtensa.c | 163 |
3 files changed, 172 insertions, 0 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 4127f68412eb..02e8d5350f8b 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
@@ -288,6 +288,14 @@ config GPIO_XILINX | |||
288 | help | 288 | help |
289 | Say yes here to support the Xilinx FPGA GPIO device | 289 | Say yes here to support the Xilinx FPGA GPIO device |
290 | 290 | ||
291 | config GPIO_XTENSA | ||
292 | bool "Xtensa GPIO32 support" | ||
293 | depends on XTENSA | ||
294 | depends on !SMP | ||
295 | help | ||
296 | Say yes here to support the Xtensa internal GPIO32 IMPWIRE (input) | ||
297 | and EXPSTATE (output) ports | ||
298 | |||
291 | config GPIO_VR41XX | 299 | config GPIO_VR41XX |
292 | tristate "NEC VR4100 series General-purpose I/O Uint support" | 300 | tristate "NEC VR4100 series General-purpose I/O Uint support" |
293 | depends on CPU_VR41XX | 301 | depends on CPU_VR41XX |
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index ee95154cb1d2..699e7cd96584 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
@@ -96,3 +96,4 @@ obj-$(CONFIG_GPIO_WM831X) += gpio-wm831x.o | |||
96 | obj-$(CONFIG_GPIO_WM8350) += gpio-wm8350.o | 96 | obj-$(CONFIG_GPIO_WM8350) += gpio-wm8350.o |
97 | obj-$(CONFIG_GPIO_WM8994) += gpio-wm8994.o | 97 | obj-$(CONFIG_GPIO_WM8994) += gpio-wm8994.o |
98 | obj-$(CONFIG_GPIO_XILINX) += gpio-xilinx.o | 98 | obj-$(CONFIG_GPIO_XILINX) += gpio-xilinx.o |
99 | obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o | ||
diff --git a/drivers/gpio/gpio-xtensa.c b/drivers/gpio/gpio-xtensa.c new file mode 100644 index 000000000000..1d136eceda62 --- /dev/null +++ b/drivers/gpio/gpio-xtensa.c | |||
@@ -0,0 +1,163 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2013 TangoTec Ltd. | ||
3 | * Author: Baruch Siach <baruch@tkos.co.il> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * Driver for the Xtensa LX4 GPIO32 Option | ||
10 | * | ||
11 | * Documentation: Xtensa LX4 Microprocessor Data Book, Section 2.22 | ||
12 | * | ||
13 | * GPIO32 is a standard optional extension to the Xtensa architecture core that | ||
14 | * provides preconfigured output and input ports for intra SoC signaling. The | ||
15 | * GPIO32 option is implemented as 32bit Tensilica Instruction Extension (TIE) | ||
16 | * output state called EXPSTATE, and 32bit input wire called IMPWIRE. This | ||
17 | * driver treats input and output states as two distinct devices. | ||
18 | * | ||
19 | * Access to GPIO32 specific instructions is controlled by the CPENABLE | ||
20 | * (Coprocessor Enable Bits) register. By default Xtensa Linux startup code | ||
21 | * disables access to all coprocessors. This driver sets the CPENABLE bit | ||
22 | * corresponding to GPIO32 before any GPIO32 specific instruction, and restores | ||
23 | * CPENABLE state after that. | ||
24 | * | ||
25 | * This driver is currently incompatible with SMP. The GPIO32 extension is not | ||
26 | * guaranteed to be available in all cores. Moreover, each core controls a | ||
27 | * different set of IO wires. A theoretical SMP aware version of this driver | ||
28 | * would need to have a per core workqueue to do the actual GPIO manipulation. | ||
29 | */ | ||
30 | |||
31 | #include <linux/err.h> | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/gpio.h> | ||
34 | #include <linux/bitops.h> | ||
35 | #include <linux/platform_device.h> | ||
36 | |||
37 | #include <asm/coprocessor.h> /* CPENABLE read/write macros */ | ||
38 | |||
39 | #ifndef XCHAL_CP_ID_XTIOP | ||
40 | #error GPIO32 option is not enabled for your xtensa core variant | ||
41 | #endif | ||
42 | |||
43 | static inline unsigned long enable_cp(unsigned long *cpenable) | ||
44 | { | ||
45 | unsigned long flags; | ||
46 | |||
47 | local_irq_save(flags); | ||
48 | RSR_CPENABLE(*cpenable); | ||
49 | WSR_CPENABLE(*cpenable | BIT(XCHAL_CP_ID_XTIOP)); | ||
50 | |||
51 | return flags; | ||
52 | } | ||
53 | |||
54 | static inline void disable_cp(unsigned long flags, unsigned long cpenable) | ||
55 | { | ||
56 | WSR_CPENABLE(cpenable); | ||
57 | local_irq_restore(flags); | ||
58 | } | ||
59 | |||
60 | static int xtensa_impwire_get_direction(struct gpio_chip *gc, unsigned offset) | ||
61 | { | ||
62 | return 1; /* input only */ | ||
63 | } | ||
64 | |||
65 | static int xtensa_impwire_get_value(struct gpio_chip *gc, unsigned offset) | ||
66 | { | ||
67 | unsigned long flags, saved_cpenable; | ||
68 | u32 impwire; | ||
69 | |||
70 | flags = enable_cp(&saved_cpenable); | ||
71 | __asm__ __volatile__("read_impwire %0" : "=a" (impwire)); | ||
72 | disable_cp(flags, saved_cpenable); | ||
73 | |||
74 | return !!(impwire & BIT(offset)); | ||
75 | } | ||
76 | |||
77 | static void xtensa_impwire_set_value(struct gpio_chip *gc, unsigned offset, | ||
78 | int value) | ||
79 | { | ||
80 | BUG(); /* output only; should never be called */ | ||
81 | } | ||
82 | |||
83 | static int xtensa_expstate_get_direction(struct gpio_chip *gc, unsigned offset) | ||
84 | { | ||
85 | return 0; /* output only */ | ||
86 | } | ||
87 | |||
88 | static int xtensa_expstate_get_value(struct gpio_chip *gc, unsigned offset) | ||
89 | { | ||
90 | unsigned long flags, saved_cpenable; | ||
91 | u32 expstate; | ||
92 | |||
93 | flags = enable_cp(&saved_cpenable); | ||
94 | __asm__ __volatile__("rur.expstate %0" : "=a" (expstate)); | ||
95 | disable_cp(flags, saved_cpenable); | ||
96 | |||
97 | return !!(expstate & BIT(offset)); | ||
98 | } | ||
99 | |||
100 | static void xtensa_expstate_set_value(struct gpio_chip *gc, unsigned offset, | ||
101 | int value) | ||
102 | { | ||
103 | unsigned long flags, saved_cpenable; | ||
104 | u32 mask = BIT(offset); | ||
105 | u32 val = value ? BIT(offset) : 0; | ||
106 | |||
107 | flags = enable_cp(&saved_cpenable); | ||
108 | __asm__ __volatile__("wrmsk_expstate %0, %1" | ||
109 | :: "a" (val), "a" (mask)); | ||
110 | disable_cp(flags, saved_cpenable); | ||
111 | } | ||
112 | |||
113 | static struct gpio_chip impwire_chip = { | ||
114 | .label = "impwire", | ||
115 | .base = -1, | ||
116 | .ngpio = 32, | ||
117 | .get_direction = xtensa_impwire_get_direction, | ||
118 | .get = xtensa_impwire_get_value, | ||
119 | .set = xtensa_impwire_set_value, | ||
120 | }; | ||
121 | |||
122 | static struct gpio_chip expstate_chip = { | ||
123 | .label = "expstate", | ||
124 | .base = -1, | ||
125 | .ngpio = 32, | ||
126 | .get_direction = xtensa_expstate_get_direction, | ||
127 | .get = xtensa_expstate_get_value, | ||
128 | .set = xtensa_expstate_set_value, | ||
129 | }; | ||
130 | |||
131 | static int xtensa_gpio_probe(struct platform_device *pdev) | ||
132 | { | ||
133 | int ret; | ||
134 | |||
135 | ret = gpiochip_add(&impwire_chip); | ||
136 | if (ret) | ||
137 | return ret; | ||
138 | return gpiochip_add(&expstate_chip); | ||
139 | } | ||
140 | |||
141 | static struct platform_driver xtensa_gpio_driver = { | ||
142 | .driver = { | ||
143 | .name = "xtensa-gpio", | ||
144 | .owner = THIS_MODULE, | ||
145 | }, | ||
146 | .probe = xtensa_gpio_probe, | ||
147 | }; | ||
148 | |||
149 | static int __init xtensa_gpio_init(void) | ||
150 | { | ||
151 | struct platform_device *pdev; | ||
152 | |||
153 | pdev = platform_device_register_simple("xtensa-gpio", 0, NULL, 0); | ||
154 | if (IS_ERR(pdev)) | ||
155 | return PTR_ERR(pdev); | ||
156 | |||
157 | return platform_driver_register(&xtensa_gpio_driver); | ||
158 | } | ||
159 | device_initcall(xtensa_gpio_init); | ||
160 | |||
161 | MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); | ||
162 | MODULE_DESCRIPTION("Xtensa LX4 GPIO32 driver"); | ||
163 | MODULE_LICENSE("GPL"); | ||