bf84dd9ebe984197b251994f807925b36785fb43
[openwrt/staging/mkresin.git] / target / linux / ramips / patches-3.8 / 0128-MIPS-ralink-add-pinmux-driver.patch
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
5
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.
9
10 Signed-off-by: John Crispin <blogic@openwrt.org>
11 ---
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
18
19 --- a/arch/mips/ralink/Makefile
20 +++ b/arch/mips/ralink/Makefile
21 @@ -6,7 +6,7 @@
22 # Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
23 # Copyright (C) 2013 John Crispin <blogic@openwrt.org>
24
25 -obj-y := prom.o of.o reset.o clk.o irq.o
26 +obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o
27
28 obj-$(CONFIG_SOC_RT288X) += rt288x.o
29 obj-$(CONFIG_SOC_RT305X) += rt305x.o
30 --- a/arch/mips/ralink/common.h
31 +++ b/arch/mips/ralink/common.h
32 @@ -50,4 +50,6 @@ extern void prom_soc_init(struct ralink_
33
34 __iomem void *plat_of_remap_node(const char *node);
35
36 +void ralink_pinmux(void);
37 +
38 #endif /* _RALINK_COMMON_H__ */
39 --- a/arch/mips/ralink/of.c
40 +++ b/arch/mips/ralink/of.c
41 @@ -110,6 +110,8 @@ static int __init plat_of_setup(void)
42 if (of_platform_populate(NULL, of_ids, NULL, NULL))
43 panic("failed to populate DT\n");
44
45 + ralink_pinmux();
46 +
47 return 0;
48 }
49
50 --- /dev/null
51 +++ b/arch/mips/ralink/pinmux.c
52 @@ -0,0 +1,76 @@
53 +/*
54 + * This program is free software; you can redistribute it and/or modify it
55 + * under the terms of the GNU General Public License version 2 as published
56 + * by the Free Software Foundation.
57 + *
58 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
59 + */
60 +
61 +#include <linux/kernel.h>
62 +#include <linux/of.h>
63 +
64 +#include <asm/mach-ralink/ralink_regs.h>
65 +
66 +#include "common.h"
67 +
68 +#define SYSC_REG_GPIO_MODE 0x60
69 +
70 +static u32 ralink_mux_mask(const char *name, struct ralink_pinmux_grp *grps)
71 +{
72 + for (; grps->name; grps++)
73 + if (!strcmp(grps->name, name))
74 + return grps->mask;
75 +
76 + return 0;
77 +}
78 +
79 +void ralink_pinmux(void)
80 +{
81 + const __be32 *wdt;
82 + struct device_node *np;
83 + struct property *prop;
84 + const char *uart, *pin;
85 + u32 mode = 0;
86 +
87 + np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-sysc");
88 + if (!np)
89 + return;
90 +
91 + of_property_for_each_string(np, "ralink,gpiomux", prop, pin) {
92 + int m = ralink_mux_mask(pin, rt_gpio_pinmux.mode);
93 + if (m) {
94 + mode |= m;
95 + pr_debug("pinmux: registered gpiomux \"%s\"\n", pin);
96 + } else {
97 + pr_err("pinmux: failed to load \"%s\"\n", pin);
98 + }
99 + }
100 +
101 + of_property_for_each_string(np, "ralink,pinmux", prop, pin) {
102 + int m = ralink_mux_mask(pin, rt_gpio_pinmux.mode);
103 + if (m) {
104 + mode &= ~m;
105 + pr_debug("pinmux: registered pinmux \"%s\"\n", pin);
106 + } else {
107 + pr_err("pinmux: failed to load group \"%s\"\n", pin);
108 + }
109 + }
110 +
111 + of_property_read_string(np, "ralink,uartmux", &uart);
112 + if (uart) {
113 + int m = ralink_mux_mask(uart, rt_gpio_pinmux.uart);
114 + mode |= rt_gpio_pinmux.uart_mask << rt_gpio_pinmux.uart_shift;
115 + if (m) {
116 + mode &= ~(m << rt_gpio_pinmux.uart_shift);
117 + pr_debug("pinmux: registered uartmux \"%s\"\n", uart);
118 + } else {
119 + pr_debug("pinmux: registered uartmux \"gpio\"\n");
120 + }
121 + }
122 +
123 + wdt = of_get_property(np, "ralink,wdtmux", NULL);
124 + if (wdt && *wdt && rt_gpio_pinmux.wdt_reset)
125 + rt_gpio_pinmux.wdt_reset();
126 +
127 + rt_sysc_w32(mode, SYSC_REG_GPIO_MODE);
128 +}