1 From 806a489c720767f63bf5046c2ccd87ded9549c1c Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sat, 16 Mar 2013 00:50:57 +0100
4 Subject: [PATCH 104/121] 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 | 5 ++-
14 arch/mips/ralink/of.c | 2 ++
15 arch/mips/ralink/pinmux.c | 76 +++++++++++++++++++++++++++++++++++++++++++++
16 arch/mips/ralink/rt305x.c | 6 ++--
17 5 files changed, 85 insertions(+), 6 deletions(-)
18 create mode 100644 arch/mips/ralink/pinmux.c
20 --- a/arch/mips/ralink/Makefile
21 +++ b/arch/mips/ralink/Makefile
23 # Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
24 # Copyright (C) 2013 John Crispin <blogic@openwrt.org>
26 -obj-y := prom.o of.o reset.o clk.o irq.o
27 +obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o
29 obj-$(CONFIG_SOC_RT305X) += rt305x.o
31 --- a/arch/mips/ralink/common.h
32 +++ b/arch/mips/ralink/common.h
33 @@ -22,9 +22,10 @@ struct ralink_pinmux {
34 struct ralink_pinmux_grp *mode;
35 struct ralink_pinmux_grp *uart;
38 void (*wdt_reset)(void);
40 -extern struct ralink_pinmux gpio_pinmux;
41 +extern struct ralink_pinmux rt_pinmux;
43 struct ralink_soc_info {
44 unsigned char sys_type[RAMIPS_SYS_TYPE_LEN];
45 @@ -41,4 +42,6 @@ extern void prom_soc_init(struct ralink_
47 __iomem void *plat_of_remap_node(const char *node);
49 +void ralink_pinmux(void);
51 #endif /* _RALINK_COMMON_H__ */
52 --- a/arch/mips/ralink/of.c
53 +++ b/arch/mips/ralink/of.c
54 @@ -101,6 +101,8 @@ static int __init plat_of_setup(void)
55 if (of_platform_populate(NULL, of_ids, NULL, NULL))
56 panic("failed to populate DT\n");
64 +++ b/arch/mips/ralink/pinmux.c
67 + * This program is free software; you can redistribute it and/or modify it
68 + * under the terms of the GNU General Public License version 2 as published
69 + * by the Free Software Foundation.
71 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
74 +#include <linux/kernel.h>
75 +#include <linux/of.h>
77 +#include <asm/mach-ralink/ralink_regs.h>
81 +#define SYSC_REG_GPIO_MODE 0x60
83 +static u32 ralink_mux_mask(const char *name, struct ralink_pinmux_grp *grps)
85 + for (; grps->name; grps++)
86 + if (!strcmp(grps->name, name))
92 +void ralink_pinmux(void)
95 + struct device_node *np;
96 + struct property *prop;
97 + const char *uart, *pin;
100 + np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-sysc");
104 + of_property_for_each_string(np, "ralink,gpiomux", prop, pin) {
105 + int m = ralink_mux_mask(pin, rt_pinmux.mode);
108 + pr_debug("pinmux: registered gpiomux \"%s\"\n", pin);
110 + pr_err("pinmux: failed to load \"%s\"\n", pin);
114 + of_property_for_each_string(np, "ralink,pinmux", prop, pin) {
115 + int m = ralink_mux_mask(pin, rt_pinmux.mode);
118 + pr_debug("pinmux: registered pinmux \"%s\"\n", pin);
120 + pr_err("pinmux: failed to load group \"%s\"\n", pin);
124 + of_property_read_string(np, "ralink,uartmux", &uart);
126 + int m = ralink_mux_mask(uart, rt_pinmux.uart);
127 + mode |= rt_pinmux.uart_mask << rt_pinmux.uart_shift;
129 + mode &= ~(m << rt_pinmux.uart_shift);
130 + pr_debug("pinmux: registered uartmux \"%s\"\n", uart);
132 + pr_debug("pinmux: registered uartmux \"gpio\"\n");
136 + wdt = of_get_property(np, "ralink,wdtmux", NULL);
137 + if (wdt && *wdt && rt_pinmux.wdt_reset)
138 + rt_pinmux.wdt_reset();
140 + rt_sysc_w32(mode, SYSC_REG_GPIO_MODE);
142 --- a/arch/mips/ralink/rt305x.c
143 +++ b/arch/mips/ralink/rt305x.c
144 @@ -97,9 +97,6 @@ struct ralink_pinmux_grp uart_mux[] = {
145 .mask = RT305X_GPIO_MODE_GPIO_I2S,
146 .gpio_first = RT305X_GPIO_7,
147 .gpio_last = RT305X_GPIO_14,
150 - .mask = RT305X_GPIO_MODE_GPIO,
154 @@ -114,10 +111,11 @@ void rt305x_wdt_reset(void)
155 rt_sysc_w32(t, SYSC_REG_SYSTEM_CONFIG);
158 -struct ralink_pinmux gpio_pinmux = {
159 +struct ralink_pinmux rt_pinmux = {
162 .uart_shift = RT305X_GPIO_MODE_UART0_SHIFT,
163 + .uart_mask = RT305X_GPIO_MODE_GPIO,
164 .wdt_reset = rt305x_wdt_reset,