aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2012-05-16 16:17:38 -0400
committerRalf Baechle <ralf@linux-mips.org>2012-05-21 09:31:53 -0400
commita36e9a1c5fa67cdc965fe011f1d04317adb35953 (patch)
tree8fc82e50f53c718c0e12785fb63f3fbeb270b383 /drivers/gpio
parent5238f7bc356670ba702057c7de7f07909133f788 (diff)
GPIO: MIPS: lantiq: convert gpio-mm-lantiq to OF and of_mm_gpio
Implements OF support and convert to of_mm_gpio. By attaching hardware latches to the External Bus Unit (EBU) on Lantiq SoC, it is possible to create output only gpios. This driver configures a special memory address, which when written to, outputs 16 bit to the latches. Signed-off-by: John Crispin <blogic@openwrt.org> Cc: linux-kernel@vger.kernel.org Cc: linux-mips@linux-mips.org Acked-by: Grant Likely <grant.likely@secretlab.ca> Patchwork: https://patchwork.linux-mips.org/patch/3840/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpio-mm-lantiq.c146
1 files changed, 89 insertions, 57 deletions
diff --git a/drivers/gpio/gpio-mm-lantiq.c b/drivers/gpio/gpio-mm-lantiq.c
index b91c7f17f10..2983dfbd066 100644
--- a/drivers/gpio/gpio-mm-lantiq.c
+++ b/drivers/gpio/gpio-mm-lantiq.c
@@ -3,16 +3,19 @@
3 * under the terms of the GNU General Public License version 2 as published 3 * under the terms of the GNU General Public License version 2 as published
4 * by the Free Software Foundation. 4 * by the Free Software Foundation.
5 * 5 *
6 * Copyright (C) 2010 John Crispin <blogic@openwrt.org> 6 * Copyright (C) 2012 John Crispin <blogic@openwrt.org>
7 */ 7 */
8 8
9#include <linux/init.h> 9#include <linux/init.h>
10#include <linux/export.h> 10#include <linux/module.h>
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/mutex.h> 13#include <linux/mutex.h>
14#include <linux/gpio.h> 14#include <linux/gpio.h>
15#include <linux/of.h>
16#include <linux/of_gpio.h>
15#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/slab.h>
16 19
17#include <lantiq_soc.h> 20#include <lantiq_soc.h>
18 21
@@ -25,102 +28,131 @@
25#define LTQ_EBU_BUSCON 0x1e7ff /* 16 bit access, slowest timing */ 28#define LTQ_EBU_BUSCON 0x1e7ff /* 16 bit access, slowest timing */
26#define LTQ_EBU_WP 0x80000000 /* write protect bit */ 29#define LTQ_EBU_WP 0x80000000 /* write protect bit */
27 30
28/* we keep a shadow value of the last value written to the ebu */ 31struct ltq_mm {
29static int ltq_ebu_gpio_shadow = 0x0; 32 struct of_mm_gpio_chip mmchip;
30static void __iomem *ltq_ebu_gpio_membase; 33 u16 shadow; /* shadow the latches state */
34};
31 35
32static void ltq_ebu_apply(void) 36/**
37 * ltq_mm_apply() - write the shadow value to the ebu address.
38 * @chip: Pointer to our private data structure.
39 *
40 * Write the shadow value to the EBU to set the gpios. We need to set the
41 * global EBU lock to make sure that PCI/MTD dont break.
42 */
43static void ltq_mm_apply(struct ltq_mm *chip)
33{ 44{
34 unsigned long flags; 45 unsigned long flags;
35 46
36 spin_lock_irqsave(&ebu_lock, flags); 47 spin_lock_irqsave(&ebu_lock, flags);
37 ltq_ebu_w32(LTQ_EBU_BUSCON, LTQ_EBU_BUSCON1); 48 ltq_ebu_w32(LTQ_EBU_BUSCON, LTQ_EBU_BUSCON1);
38 *((__u16 *)ltq_ebu_gpio_membase) = ltq_ebu_gpio_shadow; 49 __raw_writew(chip->shadow, chip->mmchip.regs);
39 ltq_ebu_w32(LTQ_EBU_BUSCON | LTQ_EBU_WP, LTQ_EBU_BUSCON1); 50 ltq_ebu_w32(LTQ_EBU_BUSCON | LTQ_EBU_WP, LTQ_EBU_BUSCON1);
40 spin_unlock_irqrestore(&ebu_lock, flags); 51 spin_unlock_irqrestore(&ebu_lock, flags);
41} 52}
42 53
43static void ltq_ebu_set(struct gpio_chip *chip, unsigned offset, int value) 54/**
55 * ltq_mm_set() - gpio_chip->set - set gpios.
56 * @gc: Pointer to gpio_chip device structure.
57 * @gpio: GPIO signal number.
58 * @val: Value to be written to specified signal.
59 *
60 * Set the shadow value and call ltq_mm_apply.
61 */
62static void ltq_mm_set(struct gpio_chip *gc, unsigned offset, int value)
44{ 63{
64 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
65 struct ltq_mm *chip =
66 container_of(mm_gc, struct ltq_mm, mmchip);
67
45 if (value) 68 if (value)
46 ltq_ebu_gpio_shadow |= (1 << offset); 69 chip->shadow |= (1 << offset);
47 else 70 else
48 ltq_ebu_gpio_shadow &= ~(1 << offset); 71 chip->shadow &= ~(1 << offset);
49 ltq_ebu_apply(); 72 ltq_mm_apply(chip);
50} 73}
51 74
52static int ltq_ebu_direction_output(struct gpio_chip *chip, unsigned offset, 75/**
53 int value) 76 * ltq_mm_dir_out() - gpio_chip->dir_out - set gpio direction.
77 * @gc: Pointer to gpio_chip device structure.
78 * @gpio: GPIO signal number.
79 * @val: Value to be written to specified signal.
80 *
81 * Same as ltq_mm_set, always returns 0.
82 */
83static int ltq_mm_dir_out(struct gpio_chip *gc, unsigned offset, int value)
54{ 84{
55 ltq_ebu_set(chip, offset, value); 85 ltq_mm_set(gc, offset, value);
56 86
57 return 0; 87 return 0;
58} 88}
59 89
60static struct gpio_chip ltq_ebu_chip = { 90/**
61 .label = "ltq_ebu", 91 * ltq_mm_save_regs() - Set initial values of GPIO pins
62 .direction_output = ltq_ebu_direction_output, 92 * @mm_gc: pointer to memory mapped GPIO chip structure
63 .set = ltq_ebu_set, 93 */
64 .base = 72, 94static void ltq_mm_save_regs(struct of_mm_gpio_chip *mm_gc)
65 .ngpio = 16, 95{
66 .can_sleep = 1, 96 struct ltq_mm *chip =
67 .owner = THIS_MODULE, 97 container_of(mm_gc, struct ltq_mm, mmchip);
68}; 98
99 /* tell the ebu controller which memory address we will be using */
100 ltq_ebu_w32(CPHYSADDR(chip->mmchip.regs) | 0x1, LTQ_EBU_ADDRSEL1);
101
102 ltq_mm_apply(chip);
103}
69 104
70static int ltq_ebu_probe(struct platform_device *pdev) 105static int ltq_mm_probe(struct platform_device *pdev)
71{ 106{
72 int ret = 0;
73 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 107 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
108 struct ltq_mm *chip;
109 const __be32 *shadow;
110 int ret = 0;
74 111
75 if (!res) { 112 if (!res) {
76 dev_err(&pdev->dev, "failed to get memory resource\n"); 113 dev_err(&pdev->dev, "failed to get memory resource\n");
77 return -ENOENT; 114 return -ENOENT;
78 } 115 }
79 116
80 res = devm_request_mem_region(&pdev->dev, res->start, 117 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
81 resource_size(res), dev_name(&pdev->dev)); 118 if (!chip)
82 if (!res) {
83 dev_err(&pdev->dev, "failed to request memory resource\n");
84 return -EBUSY;
85 }
86
87 ltq_ebu_gpio_membase = devm_ioremap_nocache(&pdev->dev, res->start,
88 resource_size(res));
89 if (!ltq_ebu_gpio_membase) {
90 dev_err(&pdev->dev, "Failed to ioremap mem region\n");
91 return -ENOMEM; 119 return -ENOMEM;
92 }
93 120
94 /* grab the default shadow value passed form the platform code */ 121 chip->mmchip.gc.ngpio = 16;
95 ltq_ebu_gpio_shadow = (unsigned int) pdev->dev.platform_data; 122 chip->mmchip.gc.label = "gpio-mm-ltq";
123 chip->mmchip.gc.direction_output = ltq_mm_dir_out;
124 chip->mmchip.gc.set = ltq_mm_set;
125 chip->mmchip.save_regs = ltq_mm_save_regs;
96 126
97 /* tell the ebu controller which memory address we will be using */ 127 /* store the shadow value if one was passed by the devicetree */
98 ltq_ebu_w32(pdev->resource->start | 0x1, LTQ_EBU_ADDRSEL1); 128 shadow = of_get_property(pdev->dev.of_node, "lantiq,shadow", NULL);
129 if (shadow)
130 chip->shadow = be32_to_cpu(*shadow);
99 131
100 /* write protect the region */ 132 ret = of_mm_gpiochip_add(pdev->dev.of_node, &chip->mmchip);
101 ltq_ebu_w32(LTQ_EBU_BUSCON | LTQ_EBU_WP, LTQ_EBU_BUSCON1); 133 if (ret)
102 134 kfree(chip);
103 ret = gpiochip_add(&ltq_ebu_chip);
104 if (!ret)
105 ltq_ebu_apply();
106 return ret; 135 return ret;
107} 136}
108 137
109static struct platform_driver ltq_ebu_driver = { 138static const struct of_device_id ltq_mm_match[] = {
110 .probe = ltq_ebu_probe, 139 { .compatible = "lantiq,gpio-mm" },
140 {},
141};
142MODULE_DEVICE_TABLE(of, ltq_mm_match);
143
144static struct platform_driver ltq_mm_driver = {
145 .probe = ltq_mm_probe,
111 .driver = { 146 .driver = {
112 .name = "ltq_ebu", 147 .name = "gpio-mm-ltq",
113 .owner = THIS_MODULE, 148 .owner = THIS_MODULE,
149 .of_match_table = ltq_mm_match,
114 }, 150 },
115}; 151};
116 152
117static int __init ltq_ebu_init(void) 153static int __init ltq_mm_init(void)
118{ 154{
119 int ret = platform_driver_register(&ltq_ebu_driver); 155 return platform_driver_register(&ltq_mm_driver);
120
121 if (ret)
122 pr_info("ltq_ebu : Error registering platfom driver!");
123 return ret;
124} 156}
125 157
126postcore_initcall(ltq_ebu_init); 158subsys_initcall(ltq_mm_init);