1 From 5a2079532dfaf5762f658370ee7a0afb686f066e 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 128/137] 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 | 76 +++++++++++++++++++++++++++++++++++++++++++++
16 4 files changed, 81 insertions(+), 1 deletion(-)
17 create mode 100644 arch/mips/ralink/pinmux.c
19 Index: linux-3.8.11/arch/mips/ralink/Makefile
20 ===================================================================
21 --- linux-3.8.11.orig/arch/mips/ralink/Makefile 2013-05-03 17:53:16.612004798 +0200
22 +++ linux-3.8.11/arch/mips/ralink/Makefile 2013-05-04 13:20:48.455042975 +0200
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 Index: linux-3.8.11/arch/mips/ralink/common.h
33 ===================================================================
34 --- linux-3.8.11.orig/arch/mips/ralink/common.h 2013-05-03 17:53:16.720004800 +0200
35 +++ linux-3.8.11/arch/mips/ralink/common.h 2013-05-04 13:20:48.055042959 +0200
38 __iomem void *plat_of_remap_node(const char *node);
40 +void ralink_pinmux(void);
42 #endif /* _RALINK_COMMON_H__ */
43 Index: linux-3.8.11/arch/mips/ralink/of.c
44 ===================================================================
45 --- linux-3.8.11.orig/arch/mips/ralink/of.c 2013-05-03 17:53:16.780004804 +0200
46 +++ linux-3.8.11/arch/mips/ralink/of.c 2013-05-04 13:20:48.055042959 +0200
48 if (of_platform_populate(NULL, of_ids, NULL, NULL))
49 panic("failed to populate DT\n");
56 Index: linux-3.8.11/arch/mips/ralink/pinmux.c
57 ===================================================================
58 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
59 +++ linux-3.8.11/arch/mips/ralink/pinmux.c 2013-05-04 13:19:22.975039268 +0200
62 + * This program is free software; you can redistribute it and/or modify it
63 + * under the terms of the GNU General Public License version 2 as published
64 + * by the Free Software Foundation.
66 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
69 +#include <linux/kernel.h>
70 +#include <linux/of.h>
72 +#include <asm/mach-ralink/ralink_regs.h>
76 +#define SYSC_REG_GPIO_MODE 0x60
78 +static int ralink_mux_mask(const char *name, struct ralink_pinmux_grp *grps, u32* mask)
80 + for (; grps->name; grps++)
81 + if (!strcmp(grps->name, name)) {
89 +void ralink_pinmux(void)
92 + struct device_node *np;
93 + struct property *prop;
94 + const char *uart, *pin;
98 + np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-sysc");
102 + of_property_for_each_string(np, "ralink,gpiomux", prop, pin) {
103 + if (!ralink_mux_mask(pin, rt_gpio_pinmux.mode, &m)) {
105 + pr_debug("pinmux: registered gpiomux \"%s\"\n", pin);
107 + pr_err("pinmux: failed to load \"%s\"\n", pin);
111 + of_property_for_each_string(np, "ralink,pinmux", prop, pin) {
112 + if (!ralink_mux_mask(pin, rt_gpio_pinmux.mode, &m)) {
114 + pr_debug("pinmux: registered pinmux \"%s\"\n", pin);
116 + pr_err("pinmux: failed to load group \"%s\"\n", pin);
120 + of_property_read_string(np, "ralink,uartmux", &uart);
122 + mode |= rt_gpio_pinmux.uart_mask << rt_gpio_pinmux.uart_shift;
123 + if (ralink_mux_mask(uart, rt_gpio_pinmux.uart, &m)) {
124 + pr_err("pinmux: failed to load uartmux \"%s\"\n", uart);
126 + if (m != rt_gpio_pinmux.uart_mask)
127 + mode &= ~(m << rt_gpio_pinmux.uart_shift);
128 + pr_debug("pinmux: registered uartmux \"%s\"\n", uart);
132 + wdt = of_get_property(np, "ralink,wdtmux", NULL);
133 + if (wdt && *wdt && rt_gpio_pinmux.wdt_reset)
134 + rt_gpio_pinmux.wdt_reset();
136 + rt_sysc_w32(mode, SYSC_REG_GPIO_MODE);