[ramips] fix typo pinmmux -> pinmux
[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 --- a/arch/mips/ralink/Makefile
21 +++ b/arch/mips/ralink/Makefile
22 @@ -6,7 +6,7 @@
23  # Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
24  # Copyright (C) 2013 John Crispin <blogic@openwrt.org>
25  
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
28  
29  obj-$(CONFIG_SOC_RT305X) += rt305x.o
30  
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;
36         int uart_shift;
37 +       u32 uart_mask;
38         void (*wdt_reset)(void);
39  };
40 -extern struct ralink_pinmux gpio_pinmux;
41 +extern struct ralink_pinmux rt_pinmux;
42  
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_
46  
47  __iomem void *plat_of_remap_node(const char *node);
48  
49 +void ralink_pinmux(void);
50 +
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");
57  
58 +       ralink_pinmux();
59 +
60         return 0;
61  }
62  
63 --- /dev/null
64 +++ b/arch/mips/ralink/pinmux.c
65 @@ -0,0 +1,76 @@
66 +/*
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.
70 + *
71 + *  Copyright (C) 2013 John Crispin <blogic@openwrt.org>
72 + */
73 +
74 +#include <linux/kernel.h>
75 +#include <linux/of.h>
76 +
77 +#include <asm/mach-ralink/ralink_regs.h>
78 +
79 +#include "common.h"
80 +
81 +#define SYSC_REG_GPIO_MODE     0x60
82 +
83 +static u32 ralink_mux_mask(const char *name, struct ralink_pinmux_grp *grps)
84 +{
85 +       for (; grps->name; grps++)
86 +               if (!strcmp(grps->name, name))
87 +                       return grps->mask;
88 +
89 +       return 0;
90 +}
91 +
92 +void ralink_pinmux(void)
93 +{
94 +       const __be32 *wdt;
95 +       struct device_node *np;
96 +       struct property *prop;
97 +       const char *uart, *pin;
98 +       u32 mode = 0;
99 +
100 +       np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-sysc");
101 +       if (!np)
102 +               return;
103 +
104 +       of_property_for_each_string(np, "ralink,gpiomux", prop, pin) {
105 +               int m = ralink_mux_mask(pin, rt_pinmux.mode);
106 +               if (m) {
107 +                       mode |= m;
108 +                       pr_debug("pinmux: registered gpiomux \"%s\"\n", pin);
109 +               } else {
110 +                       pr_err("pinmux: failed to load \"%s\"\n", pin);
111 +               }
112 +       }
113 +
114 +       of_property_for_each_string(np, "ralink,pinmux", prop, pin) {
115 +               int m = ralink_mux_mask(pin, rt_pinmux.mode);
116 +               if (m) {
117 +                       mode &= ~m;
118 +                       pr_debug("pinmux: registered pinmux \"%s\"\n", pin);
119 +               } else {
120 +                       pr_err("pinmux: failed to load group \"%s\"\n", pin);
121 +               }
122 +       }
123 +
124 +       of_property_read_string(np, "ralink,uartmux", &uart);
125 +       if (uart) {
126 +               int m = ralink_mux_mask(uart, rt_pinmux.uart);
127 +               mode |= rt_pinmux.uart_mask << rt_pinmux.uart_shift;
128 +               if (m) {
129 +                       mode &= ~(m << rt_pinmux.uart_shift);
130 +                       pr_debug("pinmux: registered uartmux \"%s\"\n", uart);
131 +               } else {
132 +                       pr_debug("pinmux: registered uartmux \"gpio\"\n");
133 +               }
134 +       }
135 +
136 +       wdt = of_get_property(np, "ralink,wdtmux", NULL);
137 +       if (wdt && *wdt && rt_pinmux.wdt_reset)
138 +               rt_pinmux.wdt_reset();
139 +
140 +       rt_sysc_w32(mode, SYSC_REG_GPIO_MODE);
141 +}
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,
148 -       }, {
149 -               .name = "gpio",
150 -               .mask = RT305X_GPIO_MODE_GPIO,
151         }, {0}
152  };
153  
154 @@ -114,10 +111,11 @@ void rt305x_wdt_reset(void)
155         rt_sysc_w32(t, SYSC_REG_SYSTEM_CONFIG);
156  }
157  
158 -struct ralink_pinmux gpio_pinmux = {
159 +struct ralink_pinmux rt_pinmux = {
160         .mode = mode_mux,
161         .uart = uart_mux,
162         .uart_shift = RT305X_GPIO_MODE_UART0_SHIFT,
163 +       .uart_mask = RT305X_GPIO_MODE_GPIO,
164         .wdt_reset = rt305x_wdt_reset,
165  };
166