aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/linux/linux-kirkwood/0004-ARM-Kirkwood-OpenRD-SD-UART1-selection.patch
blob: 1cb93047a0bddf4f923606cbd0b2ca7792b53800 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
From 3423306f9b0aa3f9f4b41338565e18d9c3bf0bb2 Mon Sep 17 00:00:00 2001
From: Tanmay Upadhyay <tanmay.upadhyay@einfochips.com>
Date: Fri, 25 Dec 2009 15:02:12 +0530
Subject: [PATCH] ARM: Kirkwood: OpenRD: SD/UART1 selection

To select UART1, pass "uart=232" (for RS232) OR "uart=485" (for RS485) in the
boot argument. To select SDIO lines pass "uart=no". SDIO lines will be selected
by default in absence of this parameter.

Signed-off-by: Tanmay Upadhyay <tanmay.upadhyay@einfochips.com>
---
 arch/arm/mach-kirkwood/openrd_base-setup.c   |   61 +++++++++++++++++++++++++-
 arch/arm/mach-kirkwood/openrd_client-setup.c |   59 ++++++++++++++++++++++++-
 2 files changed, 117 insertions(+), 3 deletions(-)

Index: git/arch/arm/mach-kirkwood/openrd_base-setup.c
===================================================================
--- git.orig/arch/arm/mach-kirkwood/openrd_base-setup.c
+++ git/arch/arm/mach-kirkwood/openrd_base-setup.c
@@ -15,6 +15,7 @@
 #include <linux/ata_platform.h>
 #include <linux/mv643xx_eth.h>
 #include <linux/gpio.h>
+#include <linux/io.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <mach/kirkwood.h>
@@ -51,16 +52,53 @@ static struct mvsdio_platform_data openr
 };
 
 static unsigned int openrd_base_mpp_config[] __initdata = {
-	MPP29_GPIO,	
+	MPP12_SD_CLK,
+	MPP13_SD_CMD,
+	MPP14_SD_D0,
+	MPP15_SD_D1,
+	MPP16_SD_D2,
+	MPP17_SD_D3,
+	MPP29_GPIO,
 	0
 };
 
+static int uart1;
+
+static void sd_uart_selection(void)
+{
+	char *ptr = NULL;
+
+	/* Parse boot_command_line string uart=no/232/485 */
+	ptr = strstr(boot_command_line, "uart=");
+
+	/* Default is SD. Change if required, for UART */
+	if (ptr != NULL) {
+		if (!strncmp(ptr + 5, "232", 3)) {
+			/* Configure MPP for UART */
+			openrd_base_mpp_config[1] = MPP13_UART1_TXD;
+			openrd_base_mpp_config[2] = MPP14_UART1_RXD;
+
+			uart1 = 232;
+		} else if (!strncmp(ptr + 5, "485", 3)) {
+			/* Configure MPP for UART */
+			openrd_base_mpp_config[1] = MPP13_UART1_TXD;
+			openrd_base_mpp_config[2] = MPP14_UART1_RXD;
+
+			uart1 = 485;
+		}
+	}
+}
+
 static void __init openrd_base_init(void)
 {
 	/*
 	 * Basic setup. Needs to be called early.
 	 */
 	kirkwood_init();
+
+	/* This function modifies MPP config according to boot argument */
+	sd_uart_selection();
+
 	kirkwood_mpp_conf(openrd_base_mpp_config);
 
 	kirkwood_uart0_init();
@@ -70,7 +108,26 @@ static void __init openrd_base_init(void
 
 	kirkwood_ge00_init(&openrd_base_ge00_data);
 	kirkwood_sata_init(&openrd_base_sata_data);
-	kirkwood_sdio_init(&openrd_base_mvsdio_data);
+
+	if (!uart1) {
+		/* Select SD
+		 * Pin # 34: 0 => UART1, 1 => SD */
+		writel(readl(GPIO_OUT(34)) | 4, GPIO_OUT(34));
+
+		kirkwood_sdio_init(&openrd_base_mvsdio_data);
+	} else {
+		/* Select UART1
+		 * Pin # 34: 0 => UART1, 1 => SD */
+		writel(readl(GPIO_OUT(34)) & ~(4), GPIO_OUT(34));
+
+		/* Select RS232 OR RS485
+		 * Pin # 28: 0 => RS232, 1 => RS485 */
+		if (uart1 == 232)
+			writel(readl(GPIO_OUT(28)) & ~(0x10000000),
+				GPIO_OUT(28));
+		else
+			writel(readl(GPIO_OUT(28)) | 0x10000000, GPIO_OUT(28));
+	}
 
 	kirkwood_i2c_init();
 }
Index: git/arch/arm/mach-kirkwood/openrd_client-setup.c
===================================================================
--- git.orig/arch/arm/mach-kirkwood/openrd_client-setup.c
+++ git/arch/arm/mach-kirkwood/openrd_client-setup.c
@@ -16,6 +16,7 @@
 #include <linux/mv643xx_eth.h>
 #include <linux/mv88fx_audio.h>
 #include <linux/gpio.h>
+#include <linux/io.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <mach/kirkwood.h>
@@ -56,6 +57,12 @@ static struct mvsdio_platform_data openr
 };
 
 static unsigned int openrd_client_mpp_config[] __initdata = {
+	MPP12_SD_CLK,
+	MPP13_SD_CMD,
+	MPP14_SD_D0,
+	MPP15_SD_D1,
+	MPP16_SD_D2,
+	MPP17_SD_D3,
 	MPP29_GPIO,
 	0
 };
@@ -77,12 +84,43 @@ static struct mv88fx_snd_platform_data o
 };
 #endif
 
+static int uart1;
+
+static void sd_uart_selection(void)
+{
+	char *ptr = NULL;
+
+	/* Parse boot_command_line string uart=no/232/485 */
+	ptr = strstr(boot_command_line, "uart=");
+
+	/* Default is SD. Change if required, for UART */
+	if (ptr != NULL) {
+		if (!strncmp(ptr + 5, "232", 3)) {
+			/* Configure MPP for UART */
+			openrd_client_mpp_config[1] = MPP13_UART1_TXD;
+			openrd_client_mpp_config[2] = MPP14_UART1_RXD;
+
+			uart1 = 232;
+		} else if (!strncmp(ptr + 5, "485", 3)) {
+			/* Configure MPP for UART */
+			openrd_client_mpp_config[1] = MPP13_UART1_TXD;
+			openrd_client_mpp_config[2] = MPP14_UART1_RXD;
+
+			uart1 = 485;
+		}
+	}
+}
+
 static void __init openrd_client_init(void)
 {
 	/*
 	 * Basic setup. Needs to be called early.
 	 */
 	kirkwood_init();
+
+	/* This function modifies MPP config according to boot argument */
+	sd_uart_selection();
+
 	kirkwood_mpp_conf(openrd_client_mpp_config);
 
 	kirkwood_uart0_init();
@@ -95,7 +133,26 @@ static void __init openrd_client_init(vo
 	kirkwood_ge01_init(&openrd_client_ge01_data);
 
 	kirkwood_sata_init(&openrd_client_sata_data);
-	kirkwood_sdio_init(&openrd_client_mvsdio_data);
+
+	if (!uart1) {
+		/* Select SD
+		 * Pin # 34: 0 => UART1, 1 => SD */
+		writel(readl(GPIO_OUT(34)) | 4, GPIO_OUT(34));
+
+		kirkwood_sdio_init(&openrd_client_mvsdio_data);
+	} else {
+		/* Select UART1
+		 * Pin # 34: 0 => UART1, 1 => SD */
+		writel(readl(GPIO_OUT(34)) & ~(4), GPIO_OUT(34));
+
+		/* Select RS232 OR RS485
+		 * Pin # 28: 0 => RS232, 1 => RS485 */
+		if (uart1 == 232)
+			writel(readl(GPIO_OUT(28)) & ~(0x10000000),
+				GPIO_OUT(28));
+		else
+			writel(readl(GPIO_OUT(28)) | 0x10000000, GPIO_OUT(28));
+	}
 
 	kirkwood_i2c_init();
 #if defined(CONFIG_SND_MV88FX_SOC) || defined(CONFIG_SND_MV88FX_SOC_MODULE)