1 From f9391211e47cdcc31f341d710efef4b3b46c333d Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Wed, 30 Mar 2011 09:27:56 +0200
4 Subject: [PATCH 08/13] MIPS: Lantiq: Add more gpio drivers
6 The XWAY family allows to extend the number of gpios by using shift registers or latches. This patch adds the 2 drivers needed for this. The extended gpios are output only.
8 [ralf@linux-mips.org: Fixed ltq_stp_probe section() attributes.]
10 Signed-off-by: John Crispin <blogic@openwrt.org>
11 Signed-off-by: Ralph Hempel <ralph.hempel@lantiq.com>
12 Cc: linux-mips@linux-mips.org
13 Patchwork: https://patchwork.linux-mips.org/patch/2258/
14 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
16 arch/mips/lantiq/xway/Makefile | 2 +-
17 arch/mips/lantiq/xway/gpio_ebu.c | 126 ++++++++++++++++++++++++++++++
18 arch/mips/lantiq/xway/gpio_stp.c | 157 ++++++++++++++++++++++++++++++++++++++
19 3 files changed, 284 insertions(+), 1 deletions(-)
20 create mode 100644 arch/mips/lantiq/xway/gpio_ebu.c
21 create mode 100644 arch/mips/lantiq/xway/gpio_stp.c
23 diff --git a/arch/mips/lantiq/xway/Makefile b/arch/mips/lantiq/xway/Makefile
24 index b1d3640..6b5e07e 100644
25 --- a/arch/mips/lantiq/xway/Makefile
26 +++ b/arch/mips/lantiq/xway/Makefile
28 -obj-y := pmu.o ebu.o reset.o gpio.o devices.o
29 +obj-y := pmu.o ebu.o reset.o gpio.o gpio_stp.o gpio_ebu.o devices.o
31 obj-$(CONFIG_SOC_XWAY) += clk-xway.o prom-xway.o setup-xway.o
32 obj-$(CONFIG_SOC_AMAZON_SE) += clk-ase.o prom-ase.o setup-ase.o
33 diff --git a/arch/mips/lantiq/xway/gpio_ebu.c b/arch/mips/lantiq/xway/gpio_ebu.c
35 index 0000000..a479355
37 +++ b/arch/mips/lantiq/xway/gpio_ebu.c
40 + * This program is free software; you can redistribute it and/or modify it
41 + * under the terms of the GNU General Public License version 2 as published
42 + * by the Free Software Foundation.
44 + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
47 +#include <linux/init.h>
48 +#include <linux/module.h>
49 +#include <linux/types.h>
50 +#include <linux/platform_device.h>
51 +#include <linux/mutex.h>
52 +#include <linux/gpio.h>
53 +#include <linux/io.h>
55 +#include <lantiq_soc.h>
58 + * By attaching hardware latches to the EBU it is possible to create output
59 + * only gpios. This driver configures a special memory address, which when
60 + * written to outputs 16 bit to the latches.
63 +#define LTQ_EBU_BUSCON 0x1e7ff /* 16 bit access, slowest timing */
64 +#define LTQ_EBU_WP 0x80000000 /* write protect bit */
66 +/* we keep a shadow value of the last value written to the ebu */
67 +static int ltq_ebu_gpio_shadow = 0x0;
68 +static void __iomem *ltq_ebu_gpio_membase;
70 +static void ltq_ebu_apply(void)
72 + unsigned long flags;
74 + spin_lock_irqsave(&ebu_lock, flags);
75 + ltq_ebu_w32(LTQ_EBU_BUSCON, LTQ_EBU_BUSCON1);
76 + *((__u16 *)ltq_ebu_gpio_membase) = ltq_ebu_gpio_shadow;
77 + ltq_ebu_w32(LTQ_EBU_BUSCON | LTQ_EBU_WP, LTQ_EBU_BUSCON1);
78 + spin_unlock_irqrestore(&ebu_lock, flags);
81 +static void ltq_ebu_set(struct gpio_chip *chip, unsigned offset, int value)
84 + ltq_ebu_gpio_shadow |= (1 << offset);
86 + ltq_ebu_gpio_shadow &= ~(1 << offset);
90 +static int ltq_ebu_direction_output(struct gpio_chip *chip, unsigned offset,
93 + ltq_ebu_set(chip, offset, value);
98 +static struct gpio_chip ltq_ebu_chip = {
100 + .direction_output = ltq_ebu_direction_output,
101 + .set = ltq_ebu_set,
105 + .owner = THIS_MODULE,
108 +static int ltq_ebu_probe(struct platform_device *pdev)
111 + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
114 + dev_err(&pdev->dev, "failed to get memory resource\n");
118 + res = devm_request_mem_region(&pdev->dev, res->start,
119 + resource_size(res), dev_name(&pdev->dev));
121 + dev_err(&pdev->dev, "failed to request memory resource\n");
125 + ltq_ebu_gpio_membase = devm_ioremap_nocache(&pdev->dev, res->start,
126 + resource_size(res));
127 + if (!ltq_ebu_gpio_membase) {
128 + dev_err(&pdev->dev, "Failed to ioremap mem region\n");
132 + /* grab the default shadow value passed form the platform code */
133 + ltq_ebu_gpio_shadow = (unsigned int) pdev->dev.platform_data;
135 + /* tell the ebu controller which memory address we will be using */
136 + ltq_ebu_w32(pdev->resource->start | 0x1, LTQ_EBU_ADDRSEL1);
138 + /* write protect the region */
139 + ltq_ebu_w32(LTQ_EBU_BUSCON | LTQ_EBU_WP, LTQ_EBU_BUSCON1);
141 + ret = gpiochip_add(<q_ebu_chip);
147 +static struct platform_driver ltq_ebu_driver = {
148 + .probe = ltq_ebu_probe,
151 + .owner = THIS_MODULE,
155 +static int __init ltq_ebu_init(void)
157 + int ret = platform_driver_register(<q_ebu_driver);
160 + pr_info("ltq_ebu : Error registering platfom driver!");
164 +postcore_initcall(ltq_ebu_init);
165 diff --git a/arch/mips/lantiq/xway/gpio_stp.c b/arch/mips/lantiq/xway/gpio_stp.c
167 index 0000000..67d59d6
169 +++ b/arch/mips/lantiq/xway/gpio_stp.c
172 + * This program is free software; you can redistribute it and/or modify it
173 + * under the terms of the GNU General Public License version 2 as published
174 + * by the Free Software Foundation.
176 + * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
180 +#include <linux/slab.h>
181 +#include <linux/init.h>
182 +#include <linux/module.h>
183 +#include <linux/types.h>
184 +#include <linux/platform_device.h>
185 +#include <linux/mutex.h>
186 +#include <linux/io.h>
187 +#include <linux/gpio.h>
189 +#include <lantiq_soc.h>
191 +#define LTQ_STP_CON0 0x00
192 +#define LTQ_STP_CON1 0x04
193 +#define LTQ_STP_CPU0 0x08
194 +#define LTQ_STP_CPU1 0x0C
195 +#define LTQ_STP_AR 0x10
197 +#define LTQ_STP_CON_SWU (1 << 31)
198 +#define LTQ_STP_2HZ 0
199 +#define LTQ_STP_4HZ (1 << 23)
200 +#define LTQ_STP_8HZ (2 << 23)
201 +#define LTQ_STP_10HZ (3 << 23)
202 +#define LTQ_STP_SPEED_MASK (0xf << 23)
203 +#define LTQ_STP_UPD_FPI (1 << 31)
204 +#define LTQ_STP_UPD_MASK (3 << 30)
205 +#define LTQ_STP_ADSL_SRC (3 << 24)
207 +#define LTQ_STP_GROUP0 (1 << 0)
209 +#define LTQ_STP_RISING 0
210 +#define LTQ_STP_FALLING (1 << 26)
211 +#define LTQ_STP_EDGE_MASK (1 << 26)
213 +#define ltq_stp_r32(reg) __raw_readl(ltq_stp_membase + reg)
214 +#define ltq_stp_w32(val, reg) __raw_writel(val, ltq_stp_membase + reg)
215 +#define ltq_stp_w32_mask(clear, set, reg) \
216 + ltq_w32((ltq_r32(ltq_stp_membase + reg) & ~(clear)) | (set), \
217 + ltq_stp_membase + (reg))
219 +static int ltq_stp_shadow = 0xffff;
220 +static void __iomem *ltq_stp_membase;
222 +static void ltq_stp_set(struct gpio_chip *chip, unsigned offset, int value)
225 + ltq_stp_shadow |= (1 << offset);
227 + ltq_stp_shadow &= ~(1 << offset);
228 + ltq_stp_w32(ltq_stp_shadow, LTQ_STP_CPU0);
231 +static int ltq_stp_direction_output(struct gpio_chip *chip, unsigned offset,
234 + ltq_stp_set(chip, offset, value);
239 +static struct gpio_chip ltq_stp_chip = {
240 + .label = "ltq_stp",
241 + .direction_output = ltq_stp_direction_output,
242 + .set = ltq_stp_set,
246 + .owner = THIS_MODULE,
249 +static int ltq_stp_hw_init(void)
251 + /* the 3 pins used to control the external stp */
252 + ltq_gpio_request(4, 1, 0, 1, "stp-st");
253 + ltq_gpio_request(5, 1, 0, 1, "stp-d");
254 + ltq_gpio_request(6, 1, 0, 1, "stp-sh");
256 + /* sane defaults */
257 + ltq_stp_w32(0, LTQ_STP_AR);
258 + ltq_stp_w32(0, LTQ_STP_CPU0);
259 + ltq_stp_w32(0, LTQ_STP_CPU1);
260 + ltq_stp_w32(LTQ_STP_CON_SWU, LTQ_STP_CON0);
261 + ltq_stp_w32(0, LTQ_STP_CON1);
263 + /* rising or falling edge */
264 + ltq_stp_w32_mask(LTQ_STP_EDGE_MASK, LTQ_STP_FALLING, LTQ_STP_CON0);
266 + /* per default stp 15-0 are set */
267 + ltq_stp_w32_mask(0, LTQ_STP_GROUP0, LTQ_STP_CON1);
269 + /* stp are update periodically by the FPI bus */
270 + ltq_stp_w32_mask(LTQ_STP_UPD_MASK, LTQ_STP_UPD_FPI, LTQ_STP_CON1);
272 + /* set stp update speed */
273 + ltq_stp_w32_mask(LTQ_STP_SPEED_MASK, LTQ_STP_8HZ, LTQ_STP_CON1);
275 + /* tell the hardware that pin (led) 0 and 1 are controlled
278 + ltq_stp_w32_mask(0, LTQ_STP_ADSL_SRC, LTQ_STP_CON0);
280 + ltq_pmu_enable(PMU_LED);
284 +static int __devinit ltq_stp_probe(struct platform_device *pdev)
286 + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
291 + res = devm_request_mem_region(&pdev->dev, res->start,
292 + resource_size(res), dev_name(&pdev->dev));
294 + dev_err(&pdev->dev, "failed to request STP memory\n");
297 + ltq_stp_membase = devm_ioremap_nocache(&pdev->dev, res->start,
298 + resource_size(res));
299 + if (!ltq_stp_membase) {
300 + dev_err(&pdev->dev, "failed to remap STP memory\n");
303 + ret = gpiochip_add(<q_stp_chip);
305 + ret = ltq_stp_hw_init();
310 +static struct platform_driver ltq_stp_driver = {
311 + .probe = ltq_stp_probe,
314 + .owner = THIS_MODULE,
318 +int __init ltq_stp_init(void)
320 + int ret = platform_driver_register(<q_stp_driver);
323 + pr_info("ltq_stp: error registering platfom driver");
327 +postcore_initcall(ltq_stp_init);