1 From c7107291df4035794c67d7a904fe7419fedc5922 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Mon, 22 Apr 2013 23:11:42 +0200
4 Subject: [PATCH 45/79] MIPS: ralink: add pinmux driver
6 Add code to setup the pinmux on ralonk SoC. The SoC has a single 32 bit register
7 for this functionality with simple on/off bits. Building a full featured pinctrl
8 driver would be overkill.
10 Signed-off-by: John Crispin <blogic@openwrt.org>
12 arch/mips/ralink/Makefile | 2 +-
13 arch/mips/ralink/common.h | 2 ++
14 arch/mips/ralink/of.c | 2 ++
15 arch/mips/ralink/pinmux.c | 77 +++++++++++++++++++++++++++++++++++++++++++++
16 4 files changed, 82 insertions(+), 1 deletion(-)
17 create mode 100644 arch/mips/ralink/pinmux.c
19 diff --git a/arch/mips/ralink/Makefile b/arch/mips/ralink/Makefile
20 index 38cf1a8..341b4de 100644
21 --- a/arch/mips/ralink/Makefile
22 +++ b/arch/mips/ralink/Makefile
24 # Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
25 # Copyright (C) 2013 John Crispin <blogic@openwrt.org>
27 -obj-y := prom.o of.o reset.o clk.o irq.o
28 +obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o
30 obj-$(CONFIG_SOC_RT288X) += rt288x.o
31 obj-$(CONFIG_SOC_RT305X) += rt305x.o
32 diff --git a/arch/mips/ralink/common.h b/arch/mips/ralink/common.h
33 index 83144c3..f113fd6 100644
34 --- a/arch/mips/ralink/common.h
35 +++ b/arch/mips/ralink/common.h
36 @@ -50,4 +50,6 @@ extern void prom_soc_init(struct ralink_soc_info *soc_info);
38 __iomem void *plat_of_remap_node(const char *node);
40 +void ralink_pinmux(void);
42 #endif /* _RALINK_COMMON_H__ */
43 diff --git a/arch/mips/ralink/of.c b/arch/mips/ralink/of.c
44 index fb15695..f916774 100644
45 --- a/arch/mips/ralink/of.c
46 +++ b/arch/mips/ralink/of.c
47 @@ -110,6 +110,8 @@ static int __init plat_of_setup(void)
48 if (of_platform_populate(NULL, of_ids, NULL, NULL))
49 panic("failed to populate DT\n");
56 diff --git a/arch/mips/ralink/pinmux.c b/arch/mips/ralink/pinmux.c
58 index 0000000..1720216
60 +++ b/arch/mips/ralink/pinmux.c
63 + * This program is free software; you can redistribute it and/or modify it
64 + * under the terms of the GNU General Public License version 2 as published
65 + * by the Free Software Foundation.
67 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
70 +#include <linux/kernel.h>
71 +#include <linux/of.h>
73 +#include <asm/mach-ralink/ralink_regs.h>
77 +#define SYSC_REG_GPIO_MODE 0x60
79 +static int ralink_mux_mask(const char *name, struct ralink_pinmux_grp *grps, u32* mask)
81 + for (; grps && grps->name; grps++)
82 + if (!strcmp(grps->name, name)) {
90 +void ralink_pinmux(void)
93 + struct device_node *np;
94 + struct property *prop;
95 + const char *uart, *pin;
99 + np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-sysc");
103 + of_property_for_each_string(np, "ralink,gpiomux", prop, pin) {
104 + if (!ralink_mux_mask(pin, rt_gpio_pinmux.mode, &m)) {
106 + pr_debug("pinmux: registered gpiomux \"%s\"\n", pin);
108 + pr_err("pinmux: failed to load \"%s\"\n", pin);
112 + of_property_for_each_string(np, "ralink,pinmux", prop, pin) {
113 + if (!ralink_mux_mask(pin, rt_gpio_pinmux.mode, &m)) {
115 + pr_debug("pinmux: registered pinmux \"%s\"\n", pin);
117 + pr_err("pinmux: failed to load group \"%s\"\n", pin);
121 + of_property_read_string(np, "ralink,uartmux", &uart);
123 + mode &= ~(rt_gpio_pinmux.uart_mask << rt_gpio_pinmux.uart_shift);
124 + if (ralink_mux_mask(uart, rt_gpio_pinmux.uart, &m)) {
125 + pr_err("pinmux: failed to load uartmux \"%s\"\n", uart);
126 + mode |= rt_gpio_pinmux.uart_mask << rt_gpio_pinmux.uart_shift;
128 + mode |= m << rt_gpio_pinmux.uart_shift;
129 + pr_debug("pinmux: registered uartmux \"%s\"\n", uart);
133 + wdt = of_get_property(np, "ralink,wdtmux", NULL);
134 + if (wdt && *wdt && rt_gpio_pinmux.wdt_reset)
135 + rt_gpio_pinmux.wdt_reset();
137 + rt_sysc_w32(mode, SYSC_REG_GPIO_MODE);