blob: 9969dbab19e36e3f2bd1210c93840bc85bfd7f16 [file] [log] [blame]
Florian Fainelli26c288f2007-10-23 18:55:55 +02001/*
Manuel Lauss8e026912011-11-10 12:06:21 +00002 * MTX-1 platform devices registration (Au1500)
Florian Fainelli26c288f2007-10-23 18:55:55 +02003 *
Florian Fainellia1b021d2009-08-01 23:51:20 +02004 * Copyright (C) 2007-2009, Florian Fainelli <florian@openwrt.org>
Florian Fainelli26c288f2007-10-23 18:55:55 +02005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <linux/init.h>
Manuel Lauss8e026912011-11-10 12:06:21 +000022#include <linux/interrupt.h>
23#include <linux/kernel.h>
Florian Fainelli26c288f2007-10-23 18:55:55 +020024#include <linux/platform_device.h>
25#include <linux/leds.h>
Sergei Shtylyov1ff1a782008-04-30 23:30:12 +040026#include <linux/gpio.h>
Florian Fainellif6ed10a2008-01-07 19:00:46 +010027#include <linux/gpio_keys.h>
28#include <linux/input.h>
Yoichi Yuasa95283562008-07-11 22:34:48 +090029#include <linux/mtd/partitions.h>
30#include <linux/mtd/physmap.h>
31#include <mtd/mtd-abi.h>
Manuel Lauss8e026912011-11-10 12:06:21 +000032#include <asm/bootinfo.h>
33#include <asm/reboot.h>
34#include <asm/mach-au1x00/au1000.h>
Florian Fainellibf3a1eb2011-02-27 19:53:53 +010035#include <asm/mach-au1x00/au1xxx_eth.h>
Manuel Lauss8e026912011-11-10 12:06:21 +000036#include <prom.h>
37
38const char *get_system_type(void)
39{
40 return "MTX-1";
41}
42
43void __init prom_init(void)
44{
45 unsigned char *memsize_str;
46 unsigned long memsize;
47
48 prom_argc = fw_arg0;
49 prom_argv = (char **)fw_arg1;
50 prom_envp = (char **)fw_arg2;
51
52 prom_init_cmdline();
53
54 memsize_str = prom_getenv("memsize");
55 if (!memsize_str)
56 memsize = 0x04000000;
57 else
58 strict_strtoul(memsize_str, 0, &memsize);
59 add_memory_region(0, memsize, BOOT_MEM_RAM);
60}
61
62void prom_putchar(unsigned char c)
63{
64 alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c);
65}
66
67static void mtx1_reset(char *c)
68{
69 /* Jump to the reset vector */
70 __asm__ __volatile__("jr\t%0" : : "r"(0xbfc00000));
71}
72
73static void mtx1_power_off(void)
74{
75 while (1)
76 asm volatile (
77 " .set mips32 \n"
78 " wait \n"
79 " .set mips0 \n");
80}
81
82void __init board_setup(void)
83{
Florian Fainelli4bd5a572012-01-31 18:19:03 +010084#if IS_ENABLED(CONFIG_USB_OHCI_HCD)
Manuel Lauss8e026912011-11-10 12:06:21 +000085 /* Enable USB power switch */
86 alchemy_gpio_direction_output(204, 0);
Florian Fainelli4bd5a572012-01-31 18:19:03 +010087#endif /* IS_ENABLED(CONFIG_USB_OHCI_HCD) */
Manuel Lauss8e026912011-11-10 12:06:21 +000088
89 /* Initialize sys_pinfunc */
90 au_writel(SYS_PF_NI2, SYS_PINFUNC);
91
92 /* Initialize GPIO */
93 au_writel(~0, KSEG1ADDR(AU1000_SYS_PHYS_ADDR) + SYS_TRIOUTCLR);
94 alchemy_gpio_direction_output(0, 0); /* Disable M66EN (PCI 66MHz) */
95 alchemy_gpio_direction_output(3, 1); /* Disable PCI CLKRUN# */
96 alchemy_gpio_direction_output(1, 1); /* Enable EXT_IO3 */
97 alchemy_gpio_direction_output(5, 0); /* Disable eth PHY TX_ER */
98
99 /* Enable LED and set it to green */
100 alchemy_gpio_direction_output(211, 1); /* green on */
101 alchemy_gpio_direction_output(212, 0); /* red off */
102
103 pm_power_off = mtx1_power_off;
104 _machine_halt = mtx1_power_off;
105 _machine_restart = mtx1_reset;
106
107 printk(KERN_INFO "4G Systems MTX-1 Board\n");
108}
109
110/******************************************************************************/
Florian Fainellibf3a1eb2011-02-27 19:53:53 +0100111
Florian Fainellif6ed10a2008-01-07 19:00:46 +0100112static struct gpio_keys_button mtx1_gpio_button[] = {
113 {
114 .gpio = 207,
115 .code = BTN_0,
116 .desc = "System button",
117 }
118};
119
120static struct gpio_keys_platform_data mtx1_buttons_data = {
121 .buttons = mtx1_gpio_button,
122 .nbuttons = ARRAY_SIZE(mtx1_gpio_button),
123};
124
125static struct platform_device mtx1_button = {
126 .name = "gpio-keys",
127 .id = -1,
128 .dev = {
129 .platform_data = &mtx1_buttons_data,
130 }
131};
132
Florian Fainelli26c288f2007-10-23 18:55:55 +0200133static struct resource mtx1_wdt_res[] = {
134 [0] = {
Manuel Laussb7f720d2011-05-08 10:42:20 +0200135 .start = 215,
136 .end = 215,
Florian Fainelli26c288f2007-10-23 18:55:55 +0200137 .name = "mtx1-wdt-gpio",
138 .flags = IORESOURCE_IRQ,
139 }
140};
141
Florian Fainelli26c288f2007-10-23 18:55:55 +0200142static struct platform_device mtx1_wdt = {
143 .name = "mtx1-wdt",
144 .id = 0,
145 .num_resources = ARRAY_SIZE(mtx1_wdt_res),
146 .resource = mtx1_wdt_res,
147};
148
149static struct gpio_led default_leds[] = {
150 {
151 .name = "mtx1:green",
152 .gpio = 211,
153 }, {
154 .name = "mtx1:red",
155 .gpio = 212,
156 },
157};
158
159static struct gpio_led_platform_data mtx1_led_data = {
160 .num_leds = ARRAY_SIZE(default_leds),
161 .leds = default_leds,
162};
163
164static struct platform_device mtx1_gpio_leds = {
165 .name = "leds-gpio",
166 .id = -1,
167 .dev = {
168 .platform_data = &mtx1_led_data,
169 }
170};
171
Yoichi Yuasa95283562008-07-11 22:34:48 +0900172static struct mtd_partition mtx1_mtd_partitions[] = {
173 {
174 .name = "filesystem",
175 .size = 0x01C00000,
Ralf Baechle70342282013-01-22 12:59:30 +0100176 .offset = 0,
Yoichi Yuasa95283562008-07-11 22:34:48 +0900177 },
178 {
179 .name = "yamon",
180 .size = 0x00100000,
Ralf Baechle70342282013-01-22 12:59:30 +0100181 .offset = MTDPART_OFS_APPEND,
Yoichi Yuasa95283562008-07-11 22:34:48 +0900182 .mask_flags = MTD_WRITEABLE,
183 },
184 {
185 .name = "kernel",
186 .size = 0x002c0000,
Ralf Baechle70342282013-01-22 12:59:30 +0100187 .offset = MTDPART_OFS_APPEND,
Yoichi Yuasa95283562008-07-11 22:34:48 +0900188 },
189 {
190 .name = "yamon env",
191 .size = 0x00040000,
Ralf Baechle70342282013-01-22 12:59:30 +0100192 .offset = MTDPART_OFS_APPEND,
Yoichi Yuasa95283562008-07-11 22:34:48 +0900193 },
194};
195
196static struct physmap_flash_data mtx1_flash_data = {
197 .width = 4,
198 .nr_parts = 4,
199 .parts = mtx1_mtd_partitions,
200};
201
202static struct resource mtx1_mtd_resource = {
203 .start = 0x1e000000,
204 .end = 0x1fffffff,
205 .flags = IORESOURCE_MEM,
206};
207
208static struct platform_device mtx1_mtd = {
209 .name = "physmap-flash",
210 .dev = {
211 .platform_data = &mtx1_flash_data,
212 },
213 .num_resources = 1,
214 .resource = &mtx1_mtd_resource,
215};
216
Manuel Lauss7517de32011-08-12 11:39:44 +0200217static struct resource alchemy_pci_host_res[] = {
218 [0] = {
219 .start = AU1500_PCI_PHYS_ADDR,
220 .end = AU1500_PCI_PHYS_ADDR + 0xfff,
221 .flags = IORESOURCE_MEM,
222 },
223};
224
225static int mtx1_pci_idsel(unsigned int devsel, int assert)
226{
227 /* This function is only necessary to support a proprietary Cardbus
228 * adapter on the mtx-1 "singleboard" variant. It triggers a custom
229 * logic chip connected to EXT_IO3 (GPIO1) to suppress IDSEL signals.
230 */
Bruno Randolf143ec742012-07-12 21:54:05 +0100231 udelay(1);
232
Manuel Lauss7517de32011-08-12 11:39:44 +0200233 if (assert && devsel != 0)
234 /* Suppress signal to Cardbus */
235 alchemy_gpio_set_value(1, 0); /* set EXT_IO3 OFF */
236 else
237 alchemy_gpio_set_value(1, 1); /* set EXT_IO3 ON */
238
239 udelay(1);
240 return 1;
241}
242
243static const char mtx1_irqtab[][5] = {
244 [0] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 00 - AdapterA-Slot0 (top) */
245 [1] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 01 - AdapterA-Slot1 (bottom) */
246 [2] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 02 - AdapterB-Slot0 (top) */
247 [3] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 03 - AdapterB-Slot1 (bottom) */
248 [4] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTB, 0xff, 0xff }, /* IDSEL 04 - AdapterC-Slot0 (top) */
249 [5] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 05 - AdapterC-Slot1 (bottom) */
250 [6] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 06 - AdapterD-Slot0 (top) */
251 [7] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 07 - AdapterD-Slot1 (bottom) */
252};
253
254static int mtx1_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
255{
256 return mtx1_irqtab[slot][pin];
257}
258
259static struct alchemy_pci_platdata mtx1_pci_pd = {
260 .board_map_irq = mtx1_map_pci_irq,
261 .board_pci_idsel = mtx1_pci_idsel,
262 .pci_cfg_set = PCI_CONFIG_AEN | PCI_CONFIG_R2H | PCI_CONFIG_R1H |
263 PCI_CONFIG_CH |
264#if defined(__MIPSEB__)
265 PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM,
266#else
267 0,
268#endif
269};
270
271static struct platform_device mtx1_pci_host = {
272 .dev.platform_data = &mtx1_pci_pd,
273 .name = "alchemy-pci",
274 .id = 0,
275 .num_resources = ARRAY_SIZE(alchemy_pci_host_res),
276 .resource = alchemy_pci_host_res,
277};
278
Bartlomiej Zolnierkiewicz08ebb252013-09-30 15:09:20 +0200279static struct platform_device *mtx1_devs[] __initdata = {
Manuel Lauss7517de32011-08-12 11:39:44 +0200280 &mtx1_pci_host,
Florian Fainelli26c288f2007-10-23 18:55:55 +0200281 &mtx1_gpio_leds,
Florian Fainellif6ed10a2008-01-07 19:00:46 +0100282 &mtx1_wdt,
Yoichi Yuasa95283562008-07-11 22:34:48 +0900283 &mtx1_button,
284 &mtx1_mtd,
Florian Fainelli26c288f2007-10-23 18:55:55 +0200285};
286
Florian Fainellibf3a1eb2011-02-27 19:53:53 +0100287static struct au1000_eth_platform_data mtx1_au1000_eth0_pdata = {
288 .phy_search_highest_addr = 1,
Manuel Lauss8e026912011-11-10 12:06:21 +0000289 .phy1_search_mac0 = 1,
Florian Fainellibf3a1eb2011-02-27 19:53:53 +0100290};
291
Florian Fainelli26c288f2007-10-23 18:55:55 +0200292static int __init mtx1_register_devices(void)
293{
Florian Fainellia1b021d2009-08-01 23:51:20 +0200294 int rc;
295
Manuel Lauss8e026912011-11-10 12:06:21 +0000296 irq_set_irq_type(AU1500_GPIO204_INT, IRQ_TYPE_LEVEL_HIGH);
297 irq_set_irq_type(AU1500_GPIO201_INT, IRQ_TYPE_LEVEL_LOW);
298 irq_set_irq_type(AU1500_GPIO202_INT, IRQ_TYPE_LEVEL_LOW);
299 irq_set_irq_type(AU1500_GPIO203_INT, IRQ_TYPE_LEVEL_LOW);
300 irq_set_irq_type(AU1500_GPIO205_INT, IRQ_TYPE_LEVEL_LOW);
301
Florian Fainellibf3a1eb2011-02-27 19:53:53 +0100302 au1xxx_override_eth_cfg(0, &mtx1_au1000_eth0_pdata);
303
Florian Fainellia1b021d2009-08-01 23:51:20 +0200304 rc = gpio_request(mtx1_gpio_button[0].gpio,
305 mtx1_gpio_button[0].desc);
306 if (rc < 0) {
307 printk(KERN_INFO "mtx1: failed to request %d\n",
308 mtx1_gpio_button[0].gpio);
309 goto out;
310 }
311 gpio_direction_input(mtx1_gpio_button[0].gpio);
312out:
Florian Fainelli26c288f2007-10-23 18:55:55 +0200313 return platform_add_devices(mtx1_devs, ARRAY_SIZE(mtx1_devs));
314}
Florian Fainelli26c288f2007-10-23 18:55:55 +0200315arch_initcall(mtx1_register_devices);