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 --- a/arch/mips/lantiq/xway/Makefile
24 +++ b/arch/mips/lantiq/xway/Makefile
26 -obj-y := pmu.o ebu.o reset.o gpio.o devices.o
27 +obj-y := pmu.o ebu.o reset.o gpio.o gpio_stp.o gpio_ebu.o devices.o
29 obj-$(CONFIG_SOC_XWAY) += clk-xway.o prom-xway.o setup-xway.o
30 obj-$(CONFIG_SOC_AMAZON_SE) += clk-ase.o prom-ase.o setup-ase.o
32 +++ b/arch/mips/lantiq/xway/gpio_ebu.c
35 + * This program is free software; you can redistribute it and/or modify it
36 + * under the terms of the GNU General Public License version 2 as published
37 + * by the Free Software Foundation.
39 + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
42 +#include <linux/init.h>
43 +#include <linux/module.h>
44 +#include <linux/types.h>
45 +#include <linux/platform_device.h>
46 +#include <linux/mutex.h>
47 +#include <linux/gpio.h>
48 +#include <linux/io.h>
50 +#include <lantiq_soc.h>
53 + * By attaching hardware latches to the EBU it is possible to create output
54 + * only gpios. This driver configures a special memory address, which when
55 + * written to outputs 16 bit to the latches.
58 +#define LTQ_EBU_BUSCON 0x1e7ff /* 16 bit access, slowest timing */
59 +#define LTQ_EBU_WP 0x80000000 /* write protect bit */
61 +/* we keep a shadow value of the last value written to the ebu */
62 +static int ltq_ebu_gpio_shadow = 0x0;
63 +static void __iomem *ltq_ebu_gpio_membase;
65 +static void ltq_ebu_apply(void)
67 + unsigned long flags;
69 + spin_lock_irqsave(&ebu_lock, flags);
70 + ltq_ebu_w32(LTQ_EBU_BUSCON, LTQ_EBU_BUSCON1);
71 + *((__u16 *)ltq_ebu_gpio_membase) = ltq_ebu_gpio_shadow;
72 + ltq_ebu_w32(LTQ_EBU_BUSCON | LTQ_EBU_WP, LTQ_EBU_BUSCON1);
73 + spin_unlock_irqrestore(&ebu_lock, flags);
76 +static void ltq_ebu_set(struct gpio_chip *chip, unsigned offset, int value)
79 + ltq_ebu_gpio_shadow |= (1 << offset);
81 + ltq_ebu_gpio_shadow &= ~(1 << offset);
85 +static int ltq_ebu_direction_output(struct gpio_chip *chip, unsigned offset,
88 + ltq_ebu_set(chip, offset, value);
93 +static struct gpio_chip ltq_ebu_chip = {
95 + .direction_output = ltq_ebu_direction_output,
100 + .owner = THIS_MODULE,
103 +static int ltq_ebu_probe(struct platform_device *pdev)
106 + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
109 + dev_err(&pdev->dev, "failed to get memory resource\n");
113 + res = devm_request_mem_region(&pdev->dev, res->start,
114 + resource_size(res), dev_name(&pdev->dev));
116 + dev_err(&pdev->dev, "failed to request memory resource\n");
120 + ltq_ebu_gpio_membase = devm_ioremap_nocache(&pdev->dev, res->start,
121 + resource_size(res));
122 + if (!ltq_ebu_gpio_membase) {
123 + dev_err(&pdev->dev, "Failed to ioremap mem region\n");
127 + /* grab the default shadow value passed form the platform code */
128 + ltq_ebu_gpio_shadow = (unsigned int) pdev->dev.platform_data;
130 + /* tell the ebu controller which memory address we will be using */
131 + ltq_ebu_w32(pdev->resource->start | 0x1, LTQ_EBU_ADDRSEL1);
133 + /* write protect the region */
134 + ltq_ebu_w32(LTQ_EBU_BUSCON | LTQ_EBU_WP, LTQ_EBU_BUSCON1);
136 + ret = gpiochip_add(<q_ebu_chip);
142 +static struct platform_driver ltq_ebu_driver = {
143 + .probe = ltq_ebu_probe,
146 + .owner = THIS_MODULE,
150 +static int __init ltq_ebu_init(void)
152 + int ret = platform_driver_register(<q_ebu_driver);
155 + pr_info("ltq_ebu : Error registering platfom driver!");
159 +postcore_initcall(ltq_ebu_init);
161 +++ b/arch/mips/lantiq/xway/gpio_stp.c
164 + * This program is free software; you can redistribute it and/or modify it
165 + * under the terms of the GNU General Public License version 2 as published
166 + * by the Free Software Foundation.
168 + * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
172 +#include <linux/slab.h>
173 +#include <linux/init.h>
174 +#include <linux/module.h>
175 +#include <linux/types.h>
176 +#include <linux/platform_device.h>
177 +#include <linux/mutex.h>
178 +#include <linux/io.h>
179 +#include <linux/gpio.h>
181 +#include <lantiq_soc.h>
183 +#define LTQ_STP_CON0 0x00
184 +#define LTQ_STP_CON1 0x04
185 +#define LTQ_STP_CPU0 0x08
186 +#define LTQ_STP_CPU1 0x0C
187 +#define LTQ_STP_AR 0x10
189 +#define LTQ_STP_CON_SWU (1 << 31)
190 +#define LTQ_STP_2HZ 0
191 +#define LTQ_STP_4HZ (1 << 23)
192 +#define LTQ_STP_8HZ (2 << 23)
193 +#define LTQ_STP_10HZ (3 << 23)
194 +#define LTQ_STP_SPEED_MASK (0xf << 23)
195 +#define LTQ_STP_UPD_FPI (1 << 31)
196 +#define LTQ_STP_UPD_MASK (3 << 30)
197 +#define LTQ_STP_ADSL_SRC (3 << 24)
199 +#define LTQ_STP_GROUP0 (1 << 0)
201 +#define LTQ_STP_RISING 0
202 +#define LTQ_STP_FALLING (1 << 26)
203 +#define LTQ_STP_EDGE_MASK (1 << 26)
205 +#define ltq_stp_r32(reg) __raw_readl(ltq_stp_membase + reg)
206 +#define ltq_stp_w32(val, reg) __raw_writel(val, ltq_stp_membase + reg)
207 +#define ltq_stp_w32_mask(clear, set, reg) \
208 + ltq_w32((ltq_r32(ltq_stp_membase + reg) & ~(clear)) | (set), \
209 + ltq_stp_membase + (reg))
211 +static int ltq_stp_shadow = 0xffff;
212 +static void __iomem *ltq_stp_membase;
214 +static void ltq_stp_set(struct gpio_chip *chip, unsigned offset, int value)
217 + ltq_stp_shadow |= (1 << offset);
219 + ltq_stp_shadow &= ~(1 << offset);
220 + ltq_stp_w32(ltq_stp_shadow, LTQ_STP_CPU0);
223 +static int ltq_stp_direction_output(struct gpio_chip *chip, unsigned offset,
226 + ltq_stp_set(chip, offset, value);
231 +static struct gpio_chip ltq_stp_chip = {
232 + .label = "ltq_stp",
233 + .direction_output = ltq_stp_direction_output,
234 + .set = ltq_stp_set,
238 + .owner = THIS_MODULE,
241 +static int ltq_stp_hw_init(void)
243 + /* the 3 pins used to control the external stp */
244 + ltq_gpio_request(4, 1, 0, 1, "stp-st");
245 + ltq_gpio_request(5, 1, 0, 1, "stp-d");
246 + ltq_gpio_request(6, 1, 0, 1, "stp-sh");
248 + /* sane defaults */
249 + ltq_stp_w32(0, LTQ_STP_AR);
250 + ltq_stp_w32(0, LTQ_STP_CPU0);
251 + ltq_stp_w32(0, LTQ_STP_CPU1);
252 + ltq_stp_w32(LTQ_STP_CON_SWU, LTQ_STP_CON0);
253 + ltq_stp_w32(0, LTQ_STP_CON1);
255 + /* rising or falling edge */
256 + ltq_stp_w32_mask(LTQ_STP_EDGE_MASK, LTQ_STP_FALLING, LTQ_STP_CON0);
258 + /* per default stp 15-0 are set */
259 + ltq_stp_w32_mask(0, LTQ_STP_GROUP0, LTQ_STP_CON1);
261 + /* stp are update periodically by the FPI bus */
262 + ltq_stp_w32_mask(LTQ_STP_UPD_MASK, LTQ_STP_UPD_FPI, LTQ_STP_CON1);
264 + /* set stp update speed */
265 + ltq_stp_w32_mask(LTQ_STP_SPEED_MASK, LTQ_STP_8HZ, LTQ_STP_CON1);
267 + /* tell the hardware that pin (led) 0 and 1 are controlled
270 + ltq_stp_w32_mask(0, LTQ_STP_ADSL_SRC, LTQ_STP_CON0);
272 + ltq_pmu_enable(PMU_LED);
276 +static int __devinit ltq_stp_probe(struct platform_device *pdev)
278 + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
283 + res = devm_request_mem_region(&pdev->dev, res->start,
284 + resource_size(res), dev_name(&pdev->dev));
286 + dev_err(&pdev->dev, "failed to request STP memory\n");
289 + ltq_stp_membase = devm_ioremap_nocache(&pdev->dev, res->start,
290 + resource_size(res));
291 + if (!ltq_stp_membase) {
292 + dev_err(&pdev->dev, "failed to remap STP memory\n");
295 + ret = gpiochip_add(<q_stp_chip);
297 + ret = ltq_stp_hw_init();
302 +static struct platform_driver ltq_stp_driver = {
303 + .probe = ltq_stp_probe,
306 + .owner = THIS_MODULE,
310 +int __init ltq_stp_init(void)
312 + int ret = platform_driver_register(<q_stp_driver);
315 + pr_info("ltq_stp: error registering platfom driver");
319 +postcore_initcall(ltq_stp_init);