[ramips] add patches for v3.8
[15.05/openwrt.git] / target / linux / ramips / patches-3.8 / 0104-MIPS-ralink-add-pinmux-driver.patch
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
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 |    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
19
20 diff --git a/arch/mips/ralink/Makefile b/arch/mips/ralink/Makefile
21 index 939757f..39ef249 100644
22 --- a/arch/mips/ralink/Makefile
23 +++ b/arch/mips/ralink/Makefile
24 @@ -6,7 +6,7 @@
25  # Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
26  # Copyright (C) 2013 John Crispin <blogic@openwrt.org>
27  
28 -obj-y := prom.o of.o reset.o clk.o irq.o
29 +obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o
30  
31  obj-$(CONFIG_SOC_RT305X) += rt305x.o
32  
33 diff --git a/arch/mips/ralink/common.h b/arch/mips/ralink/common.h
34 index 3009903..ed99f23 100644
35 --- a/arch/mips/ralink/common.h
36 +++ b/arch/mips/ralink/common.h
37 @@ -22,9 +22,10 @@ struct ralink_pinmux {
38         struct ralink_pinmux_grp *mode;
39         struct ralink_pinmux_grp *uart;
40         int uart_shift;
41 +       u32 uart_mask;
42         void (*wdt_reset)(void);
43  };
44 -extern struct ralink_pinmux gpio_pinmux;
45 +extern struct ralink_pinmux rt_pinmux;
46  
47  struct ralink_soc_info {
48         unsigned char sys_type[RAMIPS_SYS_TYPE_LEN];
49 @@ -41,4 +42,6 @@ extern void prom_soc_init(struct ralink_soc_info *soc_info);
50  
51  __iomem void *plat_of_remap_node(const char *node);
52  
53 +void ralink_pinmux(void);
54 +
55  #endif /* _RALINK_COMMON_H__ */
56 diff --git a/arch/mips/ralink/of.c b/arch/mips/ralink/of.c
57 index 4165e70..ecf1482 100644
58 --- a/arch/mips/ralink/of.c
59 +++ b/arch/mips/ralink/of.c
60 @@ -101,6 +101,8 @@ static int __init plat_of_setup(void)
61         if (of_platform_populate(NULL, of_ids, NULL, NULL))
62                 panic("failed to populate DT\n");
63  
64 +       ralink_pinmux();
65 +
66         return 0;
67  }
68  
69 diff --git a/arch/mips/ralink/pinmux.c b/arch/mips/ralink/pinmux.c
70 new file mode 100644
71 index 0000000..7477deb
72 --- /dev/null
73 +++ b/arch/mips/ralink/pinmux.c
74 @@ -0,0 +1,76 @@
75 +/*
76 + *  This program is free software; you can redistribute it and/or modify it
77 + *  under the terms of the GNU General Public License version 2 as published
78 + *  by the Free Software Foundation.
79 + *
80 + *  Copyright (C) 2013 John Crispin <blogic@openwrt.org>
81 + */
82 +
83 +#include <linux/kernel.h>
84 +#include <linux/of.h>
85 +
86 +#include <asm/mach-ralink/ralink_regs.h>
87 +
88 +#include "common.h"
89 +
90 +#define SYSC_REG_GPIO_MODE     0x60
91 +
92 +static u32 ralink_mux_mask(const char *name, struct ralink_pinmux_grp *grps)
93 +{
94 +       for (; grps->name; grps++)
95 +               if (!strcmp(grps->name, name))
96 +                       return grps->mask;
97 +
98 +       return 0;
99 +}
100 +
101 +void ralink_pinmux(void)
102 +{
103 +       const __be32 *wdt;
104 +       struct device_node *np;
105 +       struct property *prop;
106 +       const char *uart, *pin;
107 +       u32 mode = 0;
108 +
109 +       np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-sysc");
110 +       if (!np)
111 +               return;
112 +
113 +       of_property_for_each_string(np, "ralink,gpiomux", prop, pin) {
114 +               int m = ralink_mux_mask(pin, rt_pinmux.mode);
115 +               if (m) {
116 +                       mode |= m;
117 +                       pr_debug("pinmux: registered gpiomux \"%s\"\n", pin);
118 +               } else {
119 +                       pr_err("pinmux: failed to load \"%s\"\n", pin);
120 +               }
121 +       }
122 +
123 +       of_property_for_each_string(np, "ralink,pinmmux", prop, pin) {
124 +               int m = ralink_mux_mask(pin, rt_pinmux.mode);
125 +               if (m) {
126 +                       mode &= ~m;
127 +                       pr_debug("pinmux: registered pinmux \"%s\"\n", pin);
128 +               } else {
129 +                       pr_err("pinmux: failed to load group \"%s\"\n", pin);
130 +               }
131 +       }
132 +
133 +       of_property_read_string(np, "ralink,uartmux", &uart);
134 +       if (uart) {
135 +               int m = ralink_mux_mask(uart, rt_pinmux.uart);
136 +               mode |= rt_pinmux.uart_mask << rt_pinmux.uart_shift;
137 +               if (m) {
138 +                       mode &= ~(m << rt_pinmux.uart_shift);
139 +                       pr_debug("pinmux: registered uartmux \"%s\"\n", uart);
140 +               } else {
141 +                       pr_debug("pinmux: registered uartmux \"gpio\"\n");
142 +               }
143 +       }
144 +
145 +       wdt = of_get_property(np, "ralink,wdtmux", NULL);
146 +       if (wdt && *wdt && rt_pinmux.wdt_reset)
147 +               rt_pinmux.wdt_reset();
148 +
149 +       rt_sysc_w32(mode, SYSC_REG_GPIO_MODE);
150 +}
151 diff --git a/arch/mips/ralink/rt305x.c b/arch/mips/ralink/rt305x.c
152 index 856ebff..d9ea53d 100644
153 --- a/arch/mips/ralink/rt305x.c
154 +++ b/arch/mips/ralink/rt305x.c
155 @@ -97,9 +97,6 @@ struct ralink_pinmux_grp uart_mux[] = {
156                 .mask = RT305X_GPIO_MODE_GPIO_I2S,
157                 .gpio_first = RT305X_GPIO_7,
158                 .gpio_last = RT305X_GPIO_14,
159 -       }, {
160 -               .name = "gpio",
161 -               .mask = RT305X_GPIO_MODE_GPIO,
162         }, {0}
163  };
164  
165 @@ -114,10 +111,11 @@ void rt305x_wdt_reset(void)
166         rt_sysc_w32(t, SYSC_REG_SYSTEM_CONFIG);
167  }
168  
169 -struct ralink_pinmux gpio_pinmux = {
170 +struct ralink_pinmux rt_pinmux = {
171         .mode = mode_mux,
172         .uart = uart_mux,
173         .uart_shift = RT305X_GPIO_MODE_UART0_SHIFT,
174 +       .uart_mask = RT305X_GPIO_MODE_GPIO,
175         .wdt_reset = rt305x_wdt_reset,
176  };
177  
178 -- 
179 1.7.10.4
180