1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * MTX-1 platform devices registration (Au1500)
5 * Copyright (C) 2007-2009, Florian Fainelli <florian@openwrt.org>
8 #include <linux/init.h>
9 #include <linux/interrupt.h>
10 #include <linux/kernel.h>
11 #include <linux/platform_device.h>
12 #include <linux/leds.h>
13 #include <linux/gpio.h>
14 #include <linux/gpio/machine.h>
15 #include <linux/gpio_keys.h>
16 #include <linux/input.h>
17 #include <linux/mtd/partitions.h>
18 #include <linux/mtd/physmap.h>
19 #include <mtd/mtd-abi.h>
20 #include <asm/bootinfo.h>
21 #include <asm/reboot.h>
22 #include <asm/setup.h>
23 #include <asm/mach-au1x00/au1000.h>
24 #include <asm/mach-au1x00/gpio-au1000.h>
25 #include <asm/mach-au1x00/au1xxx_eth.h>
28 const char *get_system_type(void)
33 void prom_putchar(char c
)
35 alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR
, c
);
38 static void mtx1_reset(char *c
)
40 /* Jump to the reset vector */
41 __asm__
__volatile__("jr\t%0" : : "r"(0xbfc00000));
44 static void mtx1_power_off(void)
53 void __init
board_setup(void)
55 #if IS_ENABLED(CONFIG_USB_OHCI_HCD)
56 /* Enable USB power switch */
57 alchemy_gpio_direction_output(204, 0);
58 #endif /* IS_ENABLED(CONFIG_USB_OHCI_HCD) */
60 /* Initialize sys_pinfunc */
61 alchemy_wrsys(SYS_PF_NI2
, AU1000_SYS_PINFUNC
);
64 alchemy_wrsys(~0, AU1000_SYS_TRIOUTCLR
);
65 alchemy_gpio_direction_output(0, 0); /* Disable M66EN (PCI 66MHz) */
66 alchemy_gpio_direction_output(3, 1); /* Disable PCI CLKRUN# */
67 alchemy_gpio_direction_output(1, 1); /* Enable EXT_IO3 */
68 alchemy_gpio_direction_output(5, 0); /* Disable eth PHY TX_ER */
70 /* Enable LED and set it to green */
71 alchemy_gpio_direction_output(211, 1); /* green on */
72 alchemy_gpio_direction_output(212, 0); /* red off */
74 pm_power_off
= mtx1_power_off
;
75 _machine_halt
= mtx1_power_off
;
76 _machine_restart
= mtx1_reset
;
78 printk(KERN_INFO
"4G Systems MTX-1 Board\n");
81 /******************************************************************************/
83 static struct gpio_keys_button mtx1_gpio_button
[] = {
87 .desc
= "System button",
91 static struct gpio_keys_platform_data mtx1_buttons_data
= {
92 .buttons
= mtx1_gpio_button
,
93 .nbuttons
= ARRAY_SIZE(mtx1_gpio_button
),
96 static struct platform_device mtx1_button
= {
100 .platform_data
= &mtx1_buttons_data
,
104 static struct gpiod_lookup_table mtx1_wdt_gpio_table
= {
105 .dev_id
= "mtx1-wdt.0",
107 /* Global number 215 is offset 15 on Alchemy GPIO 2 */
108 GPIO_LOOKUP("alchemy-gpio2", 15, NULL
, GPIO_ACTIVE_HIGH
),
113 static struct platform_device mtx1_wdt
= {
118 static const struct gpio_led default_leds
[] = {
120 .name
= "mtx1:green",
128 static struct gpio_led_platform_data mtx1_led_data
= {
129 .num_leds
= ARRAY_SIZE(default_leds
),
130 .leds
= default_leds
,
133 static struct platform_device mtx1_gpio_leds
= {
137 .platform_data
= &mtx1_led_data
,
141 static struct mtd_partition mtx1_mtd_partitions
[] = {
143 .name
= "filesystem",
150 .offset
= MTDPART_OFS_APPEND
,
151 .mask_flags
= MTD_WRITEABLE
,
156 .offset
= MTDPART_OFS_APPEND
,
161 .offset
= MTDPART_OFS_APPEND
,
165 static struct physmap_flash_data mtx1_flash_data
= {
168 .parts
= mtx1_mtd_partitions
,
171 static struct resource mtx1_mtd_resource
= {
174 .flags
= IORESOURCE_MEM
,
177 static struct platform_device mtx1_mtd
= {
178 .name
= "physmap-flash",
180 .platform_data
= &mtx1_flash_data
,
183 .resource
= &mtx1_mtd_resource
,
186 static struct resource alchemy_pci_host_res
[] = {
188 .start
= AU1500_PCI_PHYS_ADDR
,
189 .end
= AU1500_PCI_PHYS_ADDR
+ 0xfff,
190 .flags
= IORESOURCE_MEM
,
194 static int mtx1_pci_idsel(unsigned int devsel
, int assert)
196 /* This function is only necessary to support a proprietary Cardbus
197 * adapter on the mtx-1 "singleboard" variant. It triggers a custom
198 * logic chip connected to EXT_IO3 (GPIO1) to suppress IDSEL signals.
202 if (assert && devsel
!= 0)
203 /* Suppress signal to Cardbus */
204 alchemy_gpio_set_value(1, 0); /* set EXT_IO3 OFF */
206 alchemy_gpio_set_value(1, 1); /* set EXT_IO3 ON */
212 static const char mtx1_irqtab
[][5] = {
213 [0] = { -1, AU1500_PCI_INTA
, AU1500_PCI_INTA
, 0xff, 0xff }, /* IDSEL 00 - AdapterA-Slot0 (top) */
214 [1] = { -1, AU1500_PCI_INTB
, AU1500_PCI_INTA
, 0xff, 0xff }, /* IDSEL 01 - AdapterA-Slot1 (bottom) */
215 [2] = { -1, AU1500_PCI_INTC
, AU1500_PCI_INTD
, 0xff, 0xff }, /* IDSEL 02 - AdapterB-Slot0 (top) */
216 [3] = { -1, AU1500_PCI_INTD
, AU1500_PCI_INTC
, 0xff, 0xff }, /* IDSEL 03 - AdapterB-Slot1 (bottom) */
217 [4] = { -1, AU1500_PCI_INTA
, AU1500_PCI_INTB
, 0xff, 0xff }, /* IDSEL 04 - AdapterC-Slot0 (top) */
218 [5] = { -1, AU1500_PCI_INTB
, AU1500_PCI_INTA
, 0xff, 0xff }, /* IDSEL 05 - AdapterC-Slot1 (bottom) */
219 [6] = { -1, AU1500_PCI_INTC
, AU1500_PCI_INTD
, 0xff, 0xff }, /* IDSEL 06 - AdapterD-Slot0 (top) */
220 [7] = { -1, AU1500_PCI_INTD
, AU1500_PCI_INTC
, 0xff, 0xff }, /* IDSEL 07 - AdapterD-Slot1 (bottom) */
223 static int mtx1_map_pci_irq(const struct pci_dev
*d
, u8 slot
, u8 pin
)
225 return mtx1_irqtab
[slot
][pin
];
228 static struct alchemy_pci_platdata mtx1_pci_pd
= {
229 .board_map_irq
= mtx1_map_pci_irq
,
230 .board_pci_idsel
= mtx1_pci_idsel
,
231 .pci_cfg_set
= PCI_CONFIG_AEN
| PCI_CONFIG_R2H
| PCI_CONFIG_R1H
|
233 #if defined(__MIPSEB__)
234 PCI_CONFIG_SIC_HWA_DAT
| PCI_CONFIG_SM
,
240 static struct platform_device mtx1_pci_host
= {
241 .dev
.platform_data
= &mtx1_pci_pd
,
242 .name
= "alchemy-pci",
244 .num_resources
= ARRAY_SIZE(alchemy_pci_host_res
),
245 .resource
= alchemy_pci_host_res
,
248 static struct platform_device
*mtx1_devs
[] __initdata
= {
256 static struct au1000_eth_platform_data mtx1_au1000_eth0_pdata
= {
257 .phy_search_highest_addr
= 1,
258 .phy1_search_mac0
= 1,
261 static int __init
mtx1_register_devices(void)
265 irq_set_irq_type(AU1500_GPIO204_INT
, IRQ_TYPE_LEVEL_HIGH
);
266 irq_set_irq_type(AU1500_GPIO201_INT
, IRQ_TYPE_LEVEL_LOW
);
267 irq_set_irq_type(AU1500_GPIO202_INT
, IRQ_TYPE_LEVEL_LOW
);
268 irq_set_irq_type(AU1500_GPIO203_INT
, IRQ_TYPE_LEVEL_LOW
);
269 irq_set_irq_type(AU1500_GPIO205_INT
, IRQ_TYPE_LEVEL_LOW
);
271 au1xxx_override_eth_cfg(0, &mtx1_au1000_eth0_pdata
);
273 rc
= gpio_request(mtx1_gpio_button
[0].gpio
,
274 mtx1_gpio_button
[0].desc
);
276 printk(KERN_INFO
"mtx1: failed to request %d\n",
277 mtx1_gpio_button
[0].gpio
);
280 gpio_direction_input(mtx1_gpio_button
[0].gpio
);
282 gpiod_add_lookup_table(&mtx1_wdt_gpio_table
);
283 return platform_add_devices(mtx1_devs
, ARRAY_SIZE(mtx1_devs
));
285 arch_initcall(mtx1_register_devices
);