Merge tag 'v3.10.91' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm / mach-kirkwood / openrd-setup.c
CommitLineData
b2fdb566
AC
1/*
2 * arch/arm/mach-kirkwood/openrd-setup.c
3 *
43b56074 4 * Marvell OpenRD (Base|Client|Ultimate) Board Setup
b2fdb566
AC
5 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/platform_device.h>
14#include <linux/mtd/nand.h>
15#include <linux/mtd/partitions.h>
16#include <linux/ata_platform.h>
17#include <linux/mv643xx_eth.h>
492e2bf1 18#include <linux/i2c.h>
fd2ce9c5 19#include <linux/gpio.h>
b2fdb566
AC
20#include <asm/mach-types.h>
21#include <asm/mach/arch.h>
22#include <mach/kirkwood.h>
c02cecb9 23#include <linux/platform_data/mmc-mvsdio.h>
b2fdb566
AC
24#include "common.h"
25#include "mpp.h"
26
27static struct mtd_partition openrd_nand_parts[] = {
28 {
29 .name = "u-boot",
30 .offset = 0,
31 .size = SZ_1M,
32 .mask_flags = MTD_WRITEABLE
33 }, {
34 .name = "uImage",
35 .offset = MTDPART_OFS_NXTBLK,
36 .size = SZ_4M
37 }, {
38 .name = "root",
39 .offset = MTDPART_OFS_NXTBLK,
40 .size = MTDPART_SIZ_FULL
41 },
42};
43
44static struct mv643xx_eth_platform_data openrd_ge00_data = {
45 .phy_addr = MV643XX_ETH_PHY_ADDR(8),
46};
47
48static struct mv643xx_eth_platform_data openrd_ge01_data = {
49 .phy_addr = MV643XX_ETH_PHY_ADDR(24),
50};
51
52static struct mv_sata_platform_data openrd_sata_data = {
53 .n_ports = 2,
54};
55
56static struct mvsdio_platform_data openrd_mvsdio_data = {
57 .gpio_card_detect = 29, /* MPP29 used as SD card detect */
0d0644eb 58 .gpio_write_protect = -1,
b2fdb566
AC
59};
60
61static unsigned int openrd_mpp_config[] __initdata = {
fd2ce9c5
TU
62 MPP12_SD_CLK,
63 MPP13_SD_CMD,
64 MPP14_SD_D0,
65 MPP15_SD_D1,
66 MPP16_SD_D2,
67 MPP17_SD_D3,
68 MPP28_GPIO,
b2fdb566 69 MPP29_GPIO,
fd2ce9c5
TU
70 MPP34_GPIO,
71 0
72};
73
74/* Configure MPP for UART1 */
75static unsigned int openrd_uart1_mpp_config[] __initdata = {
76 MPP13_UART1_TXD,
77 MPP14_UART1_RXD,
b2fdb566
AC
78 0
79};
80
492e2bf1 81static struct i2c_board_info i2c_board_info[] __initdata = {
82 {
83 I2C_BOARD_INFO("cs42l51", 0x4a),
84 },
85};
86
6d6761aa
AL
87static struct platform_device openrd_client_audio_device = {
88 .name = "openrd-client-audio",
89 .id = -1,
90};
91
fd2ce9c5
TU
92static int __initdata uart1;
93
94static int __init sd_uart_selection(char *str)
95{
96 uart1 = -EINVAL;
97
98 /* Default is SD. Change if required, for UART */
99 if (!str)
100 return 0;
101
102 if (!strncmp(str, "232", 3)) {
103 uart1 = 232;
104 } else if (!strncmp(str, "485", 3)) {
105 /* OpenRD-Base doesn't have RS485. Treat is as an
106 * unknown argument & just have default setting -
107 * which is SD */
108 if (machine_is_openrd_base()) {
109 uart1 = -ENODEV;
110 return 1;
111 }
112
113 uart1 = 485;
114 }
115 return 1;
116}
117/* Parse boot_command_line string kw_openrd_init_uart1=232/485 */
118__setup("kw_openrd_init_uart1=", sd_uart_selection);
119
120static int __init uart1_mpp_config(void)
121{
122 kirkwood_mpp_conf(openrd_uart1_mpp_config);
123
124 if (gpio_request(34, "SD_UART1_SEL")) {
98adf932 125 pr_err("GPIO request 34 failed for SD/UART1 selection\n");
fd2ce9c5
TU
126 return -EIO;
127 }
128
129 if (gpio_request(28, "RS232_RS485_SEL")) {
98adf932 130 pr_err("GPIO request 28 failed for RS232/RS485 selection\n");
fd2ce9c5
TU
131 gpio_free(34);
132 return -EIO;
133 }
134
135 /* Select UART1
136 * Pin # 34: 0 => UART1, 1 => SD */
137 gpio_direction_output(34, 0);
138
139 /* Select RS232 OR RS485
140 * Pin # 28: 0 => RS232, 1 => RS485 */
141 if (uart1 == 232)
142 gpio_direction_output(28, 0);
143 else
144 gpio_direction_output(28, 1);
145
146 gpio_free(34);
147 gpio_free(28);
148
149 return 0;
150}
151
b2fdb566
AC
152static void __init openrd_init(void)
153{
154 /*
155 * Basic setup. Needs to be called early.
156 */
157 kirkwood_init();
158 kirkwood_mpp_conf(openrd_mpp_config);
159
160 kirkwood_uart0_init();
161 kirkwood_nand_init(ARRAY_AND_SIZE(openrd_nand_parts), 25);
162
163 kirkwood_ehci_init();
164
43b56074
DM
165 if (machine_is_openrd_ultimate()) {
166 openrd_ge00_data.phy_addr = MV643XX_ETH_PHY_ADDR(0);
167 openrd_ge01_data.phy_addr = MV643XX_ETH_PHY_ADDR(1);
168 }
169
b2fdb566 170 kirkwood_ge00_init(&openrd_ge00_data);
43b56074 171 if (!machine_is_openrd_base())
b2fdb566 172 kirkwood_ge01_init(&openrd_ge01_data);
43b56074 173
b2fdb566 174 kirkwood_sata_init(&openrd_sata_data);
b2fdb566
AC
175
176 kirkwood_i2c_init();
492e2bf1 177
3c9e28e7 178 if (machine_is_openrd_client() || machine_is_openrd_ultimate()) {
6d6761aa 179 platform_device_register(&openrd_client_audio_device);
492e2bf1 180 i2c_register_board_info(0, i2c_board_info,
181 ARRAY_SIZE(i2c_board_info));
182 kirkwood_audio_init();
183 }
fd2ce9c5
TU
184
185 if (uart1 <= 0) {
186 if (uart1 < 0)
98adf932
AL
187 pr_err("Invalid kernel parameter to select UART1. Defaulting to SD. ERROR CODE: %d\n",
188 uart1);
fd2ce9c5
TU
189
190 /* Select SD
191 * Pin # 34: 0 => UART1, 1 => SD */
192 if (gpio_request(34, "SD_UART1_SEL")) {
98adf932 193 pr_err("GPIO request 34 failed for SD/UART1 selection\n");
fd2ce9c5
TU
194 } else {
195
196 gpio_direction_output(34, 1);
197 gpio_free(34);
198 kirkwood_sdio_init(&openrd_mvsdio_data);
199 }
200 } else {
201 if (!uart1_mpp_config())
202 kirkwood_uart1_init();
203 }
b2fdb566
AC
204}
205
206static int __init openrd_pci_init(void)
207{
43b56074
DM
208 if (machine_is_openrd_base() ||
209 machine_is_openrd_client() ||
210 machine_is_openrd_ultimate())
ffd58bd2 211 kirkwood_pcie_init(KW_PCIE0);
b2fdb566
AC
212
213 return 0;
214}
215subsys_initcall(openrd_pci_init);
216
217#ifdef CONFIG_MACH_OPENRD_BASE
218MACHINE_START(OPENRD_BASE, "Marvell OpenRD Base Board")
219 /* Maintainer: Dhaval Vasa <dhaval.vasa@einfochips.com> */
1b7bd28c 220 .atag_offset = 0x100,
b2fdb566
AC
221 .init_machine = openrd_init,
222 .map_io = kirkwood_map_io,
4ee1f6b5 223 .init_early = kirkwood_init_early,
b2fdb566 224 .init_irq = kirkwood_init_irq,
6bb27d73 225 .init_time = kirkwood_timer_init,
cb15dff4 226 .restart = kirkwood_restart,
b2fdb566
AC
227MACHINE_END
228#endif
229
230#ifdef CONFIG_MACH_OPENRD_CLIENT
231MACHINE_START(OPENRD_CLIENT, "Marvell OpenRD Client Board")
232 /* Maintainer: Dhaval Vasa <dhaval.vasa@einfochips.com> */
1b7bd28c 233 .atag_offset = 0x100,
b2fdb566
AC
234 .init_machine = openrd_init,
235 .map_io = kirkwood_map_io,
4ee1f6b5 236 .init_early = kirkwood_init_early,
b2fdb566 237 .init_irq = kirkwood_init_irq,
6bb27d73 238 .init_time = kirkwood_timer_init,
cb15dff4 239 .restart = kirkwood_restart,
b2fdb566
AC
240MACHINE_END
241#endif
43b56074
DM
242
243#ifdef CONFIG_MACH_OPENRD_ULTIMATE
244MACHINE_START(OPENRD_ULTIMATE, "Marvell OpenRD Ultimate Board")
245 /* Maintainer: Dhaval Vasa <dhaval.vasa@einfochips.com> */
1b7bd28c 246 .atag_offset = 0x100,
43b56074
DM
247 .init_machine = openrd_init,
248 .map_io = kirkwood_map_io,
4ee1f6b5 249 .init_early = kirkwood_init_early,
43b56074 250 .init_irq = kirkwood_init_irq,
6bb27d73 251 .init_time = kirkwood_timer_init,
cb15dff4 252 .restart = kirkwood_restart,
43b56074
DM
253MACHINE_END
254#endif