]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - arch/mips/alchemy/board-mtx1.c
Merge branch 'tpm' into docs-next
[mirror_ubuntu-zesty-kernel.git] / arch / mips / alchemy / board-mtx1.c
CommitLineData
26c288f8 1/*
8e026910 2 * MTX-1 platform devices registration (Au1500)
26c288f8 3 *
a1b021d3 4 * Copyright (C) 2007-2009, Florian Fainelli <florian@openwrt.org>
26c288f8
FF
5 *
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>
8e026910
ML
22#include <linux/interrupt.h>
23#include <linux/kernel.h>
26c288f8
FF
24#include <linux/platform_device.h>
25#include <linux/leds.h>
1ff1a78c 26#include <linux/gpio.h>
f6ed10ab
FF
27#include <linux/gpio_keys.h>
28#include <linux/input.h>
95283563
YY
29#include <linux/mtd/partitions.h>
30#include <linux/mtd/physmap.h>
31#include <mtd/mtd-abi.h>
8e026910
ML
32#include <asm/bootinfo.h>
33#include <asm/reboot.h>
34#include <asm/mach-au1x00/au1000.h>
832f5dac 35#include <asm/mach-au1x00/gpio-au1000.h>
bf3a1eb8 36#include <asm/mach-au1x00/au1xxx_eth.h>
8e026910
ML
37#include <prom.h>
38
39const char *get_system_type(void)
40{
41 return "MTX-1";
42}
43
44void __init prom_init(void)
45{
46 unsigned char *memsize_str;
47 unsigned long memsize;
48
49 prom_argc = fw_arg0;
50 prom_argv = (char **)fw_arg1;
51 prom_envp = (char **)fw_arg2;
52
53 prom_init_cmdline();
54
55 memsize_str = prom_getenv("memsize");
d334c2b9 56 if (!memsize_str || kstrtoul(memsize_str, 0, &memsize))
8e026910 57 memsize = 0x04000000;
8e026910
ML
58 add_memory_region(0, memsize, BOOT_MEM_RAM);
59}
60
61void prom_putchar(unsigned char c)
62{
63 alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c);
64}
65
66static void mtx1_reset(char *c)
67{
68 /* Jump to the reset vector */
69 __asm__ __volatile__("jr\t%0" : : "r"(0xbfc00000));
70}
71
72static void mtx1_power_off(void)
73{
74 while (1)
75 asm volatile (
76 " .set mips32 \n"
77 " wait \n"
78 " .set mips0 \n");
79}
80
81void __init board_setup(void)
82{
4bd5a574 83#if IS_ENABLED(CONFIG_USB_OHCI_HCD)
8e026910
ML
84 /* Enable USB power switch */
85 alchemy_gpio_direction_output(204, 0);
4bd5a574 86#endif /* IS_ENABLED(CONFIG_USB_OHCI_HCD) */
8e026910
ML
87
88 /* Initialize sys_pinfunc */
1d09de7d 89 alchemy_wrsys(SYS_PF_NI2, AU1000_SYS_PINFUNC);
8e026910
ML
90
91 /* Initialize GPIO */
1d09de7d 92 alchemy_wrsys(~0, AU1000_SYS_TRIOUTCLR);
8e026910
ML
93 alchemy_gpio_direction_output(0, 0); /* Disable M66EN (PCI 66MHz) */
94 alchemy_gpio_direction_output(3, 1); /* Disable PCI CLKRUN# */
95 alchemy_gpio_direction_output(1, 1); /* Enable EXT_IO3 */
96 alchemy_gpio_direction_output(5, 0); /* Disable eth PHY TX_ER */
97
98 /* Enable LED and set it to green */
99 alchemy_gpio_direction_output(211, 1); /* green on */
100 alchemy_gpio_direction_output(212, 0); /* red off */
101
102 pm_power_off = mtx1_power_off;
103 _machine_halt = mtx1_power_off;
104 _machine_restart = mtx1_reset;
105
106 printk(KERN_INFO "4G Systems MTX-1 Board\n");
107}
108
109/******************************************************************************/
bf3a1eb8 110
f6ed10ab
FF
111static struct gpio_keys_button mtx1_gpio_button[] = {
112 {
113 .gpio = 207,
114 .code = BTN_0,
115 .desc = "System button",
116 }
117};
118
119static struct gpio_keys_platform_data mtx1_buttons_data = {
120 .buttons = mtx1_gpio_button,
121 .nbuttons = ARRAY_SIZE(mtx1_gpio_button),
122};
123
124static struct platform_device mtx1_button = {
125 .name = "gpio-keys",
126 .id = -1,
127 .dev = {
128 .platform_data = &mtx1_buttons_data,
129 }
130};
131
26c288f8
FF
132static struct resource mtx1_wdt_res[] = {
133 [0] = {
b7f720d6
ML
134 .start = 215,
135 .end = 215,
26c288f8
FF
136 .name = "mtx1-wdt-gpio",
137 .flags = IORESOURCE_IRQ,
138 }
139};
140
26c288f8
FF
141static struct platform_device mtx1_wdt = {
142 .name = "mtx1-wdt",
143 .id = 0,
144 .num_resources = ARRAY_SIZE(mtx1_wdt_res),
145 .resource = mtx1_wdt_res,
146};
147
148static struct gpio_led default_leds[] = {
149 {
150 .name = "mtx1:green",
151 .gpio = 211,
152 }, {
153 .name = "mtx1:red",
154 .gpio = 212,
155 },
156};
157
158static struct gpio_led_platform_data mtx1_led_data = {
159 .num_leds = ARRAY_SIZE(default_leds),
160 .leds = default_leds,
161};
162
163static struct platform_device mtx1_gpio_leds = {
164 .name = "leds-gpio",
165 .id = -1,
166 .dev = {
167 .platform_data = &mtx1_led_data,
168 }
169};
170
95283563
YY
171static struct mtd_partition mtx1_mtd_partitions[] = {
172 {
173 .name = "filesystem",
174 .size = 0x01C00000,
70342287 175 .offset = 0,
95283563
YY
176 },
177 {
178 .name = "yamon",
179 .size = 0x00100000,
70342287 180 .offset = MTDPART_OFS_APPEND,
95283563
YY
181 .mask_flags = MTD_WRITEABLE,
182 },
183 {
184 .name = "kernel",
185 .size = 0x002c0000,
70342287 186 .offset = MTDPART_OFS_APPEND,
95283563
YY
187 },
188 {
189 .name = "yamon env",
190 .size = 0x00040000,
70342287 191 .offset = MTDPART_OFS_APPEND,
95283563
YY
192 },
193};
194
195static struct physmap_flash_data mtx1_flash_data = {
196 .width = 4,
197 .nr_parts = 4,
198 .parts = mtx1_mtd_partitions,
199};
200
201static struct resource mtx1_mtd_resource = {
202 .start = 0x1e000000,
203 .end = 0x1fffffff,
204 .flags = IORESOURCE_MEM,
205};
206
207static struct platform_device mtx1_mtd = {
208 .name = "physmap-flash",
209 .dev = {
210 .platform_data = &mtx1_flash_data,
211 },
212 .num_resources = 1,
213 .resource = &mtx1_mtd_resource,
214};
215
7517de34
ML
216static struct resource alchemy_pci_host_res[] = {
217 [0] = {
218 .start = AU1500_PCI_PHYS_ADDR,
219 .end = AU1500_PCI_PHYS_ADDR + 0xfff,
220 .flags = IORESOURCE_MEM,
221 },
222};
223
224static int mtx1_pci_idsel(unsigned int devsel, int assert)
225{
226 /* This function is only necessary to support a proprietary Cardbus
227 * adapter on the mtx-1 "singleboard" variant. It triggers a custom
228 * logic chip connected to EXT_IO3 (GPIO1) to suppress IDSEL signals.
229 */
143ec74e
BR
230 udelay(1);
231
7517de34
ML
232 if (assert && devsel != 0)
233 /* Suppress signal to Cardbus */
234 alchemy_gpio_set_value(1, 0); /* set EXT_IO3 OFF */
235 else
236 alchemy_gpio_set_value(1, 1); /* set EXT_IO3 ON */
237
238 udelay(1);
239 return 1;
240}
241
242static const char mtx1_irqtab[][5] = {
243 [0] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 00 - AdapterA-Slot0 (top) */
244 [1] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 01 - AdapterA-Slot1 (bottom) */
245 [2] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 02 - AdapterB-Slot0 (top) */
246 [3] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 03 - AdapterB-Slot1 (bottom) */
247 [4] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTB, 0xff, 0xff }, /* IDSEL 04 - AdapterC-Slot0 (top) */
248 [5] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 05 - AdapterC-Slot1 (bottom) */
249 [6] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 06 - AdapterD-Slot0 (top) */
250 [7] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 07 - AdapterD-Slot1 (bottom) */
251};
252
253static int mtx1_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
254{
255 return mtx1_irqtab[slot][pin];
256}
257
258static struct alchemy_pci_platdata mtx1_pci_pd = {
259 .board_map_irq = mtx1_map_pci_irq,
260 .board_pci_idsel = mtx1_pci_idsel,
261 .pci_cfg_set = PCI_CONFIG_AEN | PCI_CONFIG_R2H | PCI_CONFIG_R1H |
262 PCI_CONFIG_CH |
263#if defined(__MIPSEB__)
264 PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM,
265#else
266 0,
267#endif
268};
269
270static struct platform_device mtx1_pci_host = {
271 .dev.platform_data = &mtx1_pci_pd,
272 .name = "alchemy-pci",
273 .id = 0,
274 .num_resources = ARRAY_SIZE(alchemy_pci_host_res),
275 .resource = alchemy_pci_host_res,
276};
277
08ebb250 278static struct platform_device *mtx1_devs[] __initdata = {
7517de34 279 &mtx1_pci_host,
26c288f8 280 &mtx1_gpio_leds,
f6ed10ab 281 &mtx1_wdt,
95283563
YY
282 &mtx1_button,
283 &mtx1_mtd,
26c288f8
FF
284};
285
bf3a1eb8
FF
286static struct au1000_eth_platform_data mtx1_au1000_eth0_pdata = {
287 .phy_search_highest_addr = 1,
8e026910 288 .phy1_search_mac0 = 1,
bf3a1eb8
FF
289};
290
26c288f8
FF
291static int __init mtx1_register_devices(void)
292{
a1b021d3
FF
293 int rc;
294
8e026910
ML
295 irq_set_irq_type(AU1500_GPIO204_INT, IRQ_TYPE_LEVEL_HIGH);
296 irq_set_irq_type(AU1500_GPIO201_INT, IRQ_TYPE_LEVEL_LOW);
297 irq_set_irq_type(AU1500_GPIO202_INT, IRQ_TYPE_LEVEL_LOW);
298 irq_set_irq_type(AU1500_GPIO203_INT, IRQ_TYPE_LEVEL_LOW);
299 irq_set_irq_type(AU1500_GPIO205_INT, IRQ_TYPE_LEVEL_LOW);
300
bf3a1eb8
FF
301 au1xxx_override_eth_cfg(0, &mtx1_au1000_eth0_pdata);
302
a1b021d3
FF
303 rc = gpio_request(mtx1_gpio_button[0].gpio,
304 mtx1_gpio_button[0].desc);
305 if (rc < 0) {
306 printk(KERN_INFO "mtx1: failed to request %d\n",
307 mtx1_gpio_button[0].gpio);
308 goto out;
309 }
310 gpio_direction_input(mtx1_gpio_button[0].gpio);
311out:
26c288f8
FF
312 return platform_add_devices(mtx1_devs, ARRAY_SIZE(mtx1_devs));
313}
26c288f8 314arch_initcall(mtx1_register_devices);