Thomas Gleixner | fd534e9 | 2019-05-23 11:14:39 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Florian Fainelli | 26c288f | 2007-10-23 18:55:55 +0200 | [diff] [blame] | 2 | /* |
Manuel Lauss | 8e02691 | 2011-11-10 12:06:21 +0000 | [diff] [blame] | 3 | * MTX-1 platform devices registration (Au1500) |
Florian Fainelli | 26c288f | 2007-10-23 18:55:55 +0200 | [diff] [blame] | 4 | * |
Florian Fainelli | a1b021d | 2009-08-01 23:51:20 +0200 | [diff] [blame] | 5 | * Copyright (C) 2007-2009, Florian Fainelli <florian@openwrt.org> |
Florian Fainelli | 26c288f | 2007-10-23 18:55:55 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/init.h> |
Manuel Lauss | 8e02691 | 2011-11-10 12:06:21 +0000 | [diff] [blame] | 9 | #include <linux/interrupt.h> |
| 10 | #include <linux/kernel.h> |
Florian Fainelli | 26c288f | 2007-10-23 18:55:55 +0200 | [diff] [blame] | 11 | #include <linux/platform_device.h> |
| 12 | #include <linux/leds.h> |
Sergei Shtylyov | 1ff1a78 | 2008-04-30 23:30:12 +0400 | [diff] [blame] | 13 | #include <linux/gpio.h> |
Linus Walleij | d2b911d | 2018-12-22 11:12:31 +0100 | [diff] [blame] | 14 | #include <linux/gpio/machine.h> |
Florian Fainelli | f6ed10a | 2008-01-07 19:00:46 +0100 | [diff] [blame] | 15 | #include <linux/gpio_keys.h> |
| 16 | #include <linux/input.h> |
Yoichi Yuasa | 9528356 | 2008-07-11 22:34:48 +0900 | [diff] [blame] | 17 | #include <linux/mtd/partitions.h> |
| 18 | #include <linux/mtd/physmap.h> |
| 19 | #include <mtd/mtd-abi.h> |
Manuel Lauss | 8e02691 | 2011-11-10 12:06:21 +0000 | [diff] [blame] | 20 | #include <asm/bootinfo.h> |
| 21 | #include <asm/reboot.h> |
Alexander Sverdlin | 5c93316 | 2018-07-13 17:51:56 +0200 | [diff] [blame] | 22 | #include <asm/setup.h> |
Manuel Lauss | 8e02691 | 2011-11-10 12:06:21 +0000 | [diff] [blame] | 23 | #include <asm/mach-au1x00/au1000.h> |
Alban Bedel | 832f5da | 2015-08-02 18:30:11 +0200 | [diff] [blame] | 24 | #include <asm/mach-au1x00/gpio-au1000.h> |
Florian Fainelli | bf3a1eb | 2011-02-27 19:53:53 +0100 | [diff] [blame] | 25 | #include <asm/mach-au1x00/au1xxx_eth.h> |
Manuel Lauss | 8e02691 | 2011-11-10 12:06:21 +0000 | [diff] [blame] | 26 | #include <prom.h> |
| 27 | |
| 28 | const char *get_system_type(void) |
| 29 | { |
| 30 | return "MTX-1"; |
| 31 | } |
| 32 | |
Alexander Sverdlin | 5c93316 | 2018-07-13 17:51:56 +0200 | [diff] [blame] | 33 | void prom_putchar(char c) |
Manuel Lauss | 8e02691 | 2011-11-10 12:06:21 +0000 | [diff] [blame] | 34 | { |
| 35 | alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c); |
| 36 | } |
| 37 | |
| 38 | static void mtx1_reset(char *c) |
| 39 | { |
| 40 | /* Jump to the reset vector */ |
| 41 | __asm__ __volatile__("jr\t%0" : : "r"(0xbfc00000)); |
| 42 | } |
| 43 | |
| 44 | static void mtx1_power_off(void) |
| 45 | { |
| 46 | while (1) |
| 47 | asm volatile ( |
| 48 | " .set mips32 \n" |
| 49 | " wait \n" |
| 50 | " .set mips0 \n"); |
| 51 | } |
| 52 | |
| 53 | void __init board_setup(void) |
| 54 | { |
Florian Fainelli | 4bd5a57 | 2012-01-31 18:19:03 +0100 | [diff] [blame] | 55 | #if IS_ENABLED(CONFIG_USB_OHCI_HCD) |
Manuel Lauss | 8e02691 | 2011-11-10 12:06:21 +0000 | [diff] [blame] | 56 | /* Enable USB power switch */ |
| 57 | alchemy_gpio_direction_output(204, 0); |
Florian Fainelli | 4bd5a57 | 2012-01-31 18:19:03 +0100 | [diff] [blame] | 58 | #endif /* IS_ENABLED(CONFIG_USB_OHCI_HCD) */ |
Manuel Lauss | 8e02691 | 2011-11-10 12:06:21 +0000 | [diff] [blame] | 59 | |
| 60 | /* Initialize sys_pinfunc */ |
Manuel Lauss | 1d09de7 | 2014-07-23 16:36:24 +0200 | [diff] [blame] | 61 | alchemy_wrsys(SYS_PF_NI2, AU1000_SYS_PINFUNC); |
Manuel Lauss | 8e02691 | 2011-11-10 12:06:21 +0000 | [diff] [blame] | 62 | |
| 63 | /* Initialize GPIO */ |
Manuel Lauss | 1d09de7 | 2014-07-23 16:36:24 +0200 | [diff] [blame] | 64 | alchemy_wrsys(~0, AU1000_SYS_TRIOUTCLR); |
Manuel Lauss | 8e02691 | 2011-11-10 12:06:21 +0000 | [diff] [blame] | 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 */ |
| 69 | |
| 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 */ |
| 73 | |
| 74 | pm_power_off = mtx1_power_off; |
| 75 | _machine_halt = mtx1_power_off; |
| 76 | _machine_restart = mtx1_reset; |
| 77 | |
| 78 | printk(KERN_INFO "4G Systems MTX-1 Board\n"); |
| 79 | } |
| 80 | |
| 81 | /******************************************************************************/ |
Florian Fainelli | bf3a1eb | 2011-02-27 19:53:53 +0100 | [diff] [blame] | 82 | |
Florian Fainelli | f6ed10a | 2008-01-07 19:00:46 +0100 | [diff] [blame] | 83 | static struct gpio_keys_button mtx1_gpio_button[] = { |
| 84 | { |
| 85 | .gpio = 207, |
| 86 | .code = BTN_0, |
| 87 | .desc = "System button", |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | static struct gpio_keys_platform_data mtx1_buttons_data = { |
| 92 | .buttons = mtx1_gpio_button, |
| 93 | .nbuttons = ARRAY_SIZE(mtx1_gpio_button), |
| 94 | }; |
| 95 | |
| 96 | static struct platform_device mtx1_button = { |
| 97 | .name = "gpio-keys", |
| 98 | .id = -1, |
| 99 | .dev = { |
| 100 | .platform_data = &mtx1_buttons_data, |
| 101 | } |
| 102 | }; |
| 103 | |
Linus Walleij | d2b911d | 2018-12-22 11:12:31 +0100 | [diff] [blame] | 104 | static struct gpiod_lookup_table mtx1_wdt_gpio_table = { |
| 105 | .dev_id = "mtx1-wdt.0", |
| 106 | .table = { |
| 107 | /* Global number 215 is offset 15 on Alchemy GPIO 2 */ |
| 108 | GPIO_LOOKUP("alchemy-gpio2", 15, NULL, GPIO_ACTIVE_HIGH), |
| 109 | { }, |
| 110 | }, |
Florian Fainelli | 26c288f | 2007-10-23 18:55:55 +0200 | [diff] [blame] | 111 | }; |
| 112 | |
Florian Fainelli | 26c288f | 2007-10-23 18:55:55 +0200 | [diff] [blame] | 113 | static struct platform_device mtx1_wdt = { |
| 114 | .name = "mtx1-wdt", |
| 115 | .id = 0, |
Florian Fainelli | 26c288f | 2007-10-23 18:55:55 +0200 | [diff] [blame] | 116 | }; |
| 117 | |
Arvind Yadav | 1fd88d9 | 2017-12-26 12:03:08 +0530 | [diff] [blame] | 118 | static const struct gpio_led default_leds[] = { |
Florian Fainelli | 26c288f | 2007-10-23 18:55:55 +0200 | [diff] [blame] | 119 | { |
| 120 | .name = "mtx1:green", |
| 121 | .gpio = 211, |
| 122 | }, { |
| 123 | .name = "mtx1:red", |
| 124 | .gpio = 212, |
| 125 | }, |
| 126 | }; |
| 127 | |
| 128 | static struct gpio_led_platform_data mtx1_led_data = { |
| 129 | .num_leds = ARRAY_SIZE(default_leds), |
| 130 | .leds = default_leds, |
| 131 | }; |
| 132 | |
| 133 | static struct platform_device mtx1_gpio_leds = { |
| 134 | .name = "leds-gpio", |
| 135 | .id = -1, |
| 136 | .dev = { |
| 137 | .platform_data = &mtx1_led_data, |
| 138 | } |
| 139 | }; |
| 140 | |
Yoichi Yuasa | 9528356 | 2008-07-11 22:34:48 +0900 | [diff] [blame] | 141 | static struct mtd_partition mtx1_mtd_partitions[] = { |
| 142 | { |
| 143 | .name = "filesystem", |
| 144 | .size = 0x01C00000, |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 145 | .offset = 0, |
Yoichi Yuasa | 9528356 | 2008-07-11 22:34:48 +0900 | [diff] [blame] | 146 | }, |
| 147 | { |
| 148 | .name = "yamon", |
| 149 | .size = 0x00100000, |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 150 | .offset = MTDPART_OFS_APPEND, |
Yoichi Yuasa | 9528356 | 2008-07-11 22:34:48 +0900 | [diff] [blame] | 151 | .mask_flags = MTD_WRITEABLE, |
| 152 | }, |
| 153 | { |
| 154 | .name = "kernel", |
| 155 | .size = 0x002c0000, |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 156 | .offset = MTDPART_OFS_APPEND, |
Yoichi Yuasa | 9528356 | 2008-07-11 22:34:48 +0900 | [diff] [blame] | 157 | }, |
| 158 | { |
| 159 | .name = "yamon env", |
| 160 | .size = 0x00040000, |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 161 | .offset = MTDPART_OFS_APPEND, |
Yoichi Yuasa | 9528356 | 2008-07-11 22:34:48 +0900 | [diff] [blame] | 162 | }, |
| 163 | }; |
| 164 | |
| 165 | static struct physmap_flash_data mtx1_flash_data = { |
| 166 | .width = 4, |
| 167 | .nr_parts = 4, |
| 168 | .parts = mtx1_mtd_partitions, |
| 169 | }; |
| 170 | |
| 171 | static struct resource mtx1_mtd_resource = { |
| 172 | .start = 0x1e000000, |
| 173 | .end = 0x1fffffff, |
| 174 | .flags = IORESOURCE_MEM, |
| 175 | }; |
| 176 | |
| 177 | static struct platform_device mtx1_mtd = { |
| 178 | .name = "physmap-flash", |
| 179 | .dev = { |
| 180 | .platform_data = &mtx1_flash_data, |
| 181 | }, |
| 182 | .num_resources = 1, |
| 183 | .resource = &mtx1_mtd_resource, |
| 184 | }; |
| 185 | |
Manuel Lauss | 7517de3 | 2011-08-12 11:39:44 +0200 | [diff] [blame] | 186 | static struct resource alchemy_pci_host_res[] = { |
| 187 | [0] = { |
| 188 | .start = AU1500_PCI_PHYS_ADDR, |
| 189 | .end = AU1500_PCI_PHYS_ADDR + 0xfff, |
| 190 | .flags = IORESOURCE_MEM, |
| 191 | }, |
| 192 | }; |
| 193 | |
| 194 | static int mtx1_pci_idsel(unsigned int devsel, int assert) |
| 195 | { |
| 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. |
| 199 | */ |
Bruno Randolf | 143ec74 | 2012-07-12 21:54:05 +0100 | [diff] [blame] | 200 | udelay(1); |
| 201 | |
Manuel Lauss | 7517de3 | 2011-08-12 11:39:44 +0200 | [diff] [blame] | 202 | if (assert && devsel != 0) |
| 203 | /* Suppress signal to Cardbus */ |
| 204 | alchemy_gpio_set_value(1, 0); /* set EXT_IO3 OFF */ |
| 205 | else |
| 206 | alchemy_gpio_set_value(1, 1); /* set EXT_IO3 ON */ |
| 207 | |
| 208 | udelay(1); |
| 209 | return 1; |
| 210 | } |
| 211 | |
| 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) */ |
| 221 | }; |
| 222 | |
| 223 | static int mtx1_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin) |
| 224 | { |
| 225 | return mtx1_irqtab[slot][pin]; |
| 226 | } |
| 227 | |
| 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 | |
| 232 | PCI_CONFIG_CH | |
| 233 | #if defined(__MIPSEB__) |
| 234 | PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM, |
| 235 | #else |
| 236 | 0, |
| 237 | #endif |
| 238 | }; |
| 239 | |
| 240 | static struct platform_device mtx1_pci_host = { |
| 241 | .dev.platform_data = &mtx1_pci_pd, |
| 242 | .name = "alchemy-pci", |
| 243 | .id = 0, |
| 244 | .num_resources = ARRAY_SIZE(alchemy_pci_host_res), |
| 245 | .resource = alchemy_pci_host_res, |
| 246 | }; |
| 247 | |
Bartlomiej Zolnierkiewicz | 08ebb25 | 2013-09-30 15:09:20 +0200 | [diff] [blame] | 248 | static struct platform_device *mtx1_devs[] __initdata = { |
Manuel Lauss | 7517de3 | 2011-08-12 11:39:44 +0200 | [diff] [blame] | 249 | &mtx1_pci_host, |
Florian Fainelli | 26c288f | 2007-10-23 18:55:55 +0200 | [diff] [blame] | 250 | &mtx1_gpio_leds, |
Florian Fainelli | f6ed10a | 2008-01-07 19:00:46 +0100 | [diff] [blame] | 251 | &mtx1_wdt, |
Yoichi Yuasa | 9528356 | 2008-07-11 22:34:48 +0900 | [diff] [blame] | 252 | &mtx1_button, |
| 253 | &mtx1_mtd, |
Florian Fainelli | 26c288f | 2007-10-23 18:55:55 +0200 | [diff] [blame] | 254 | }; |
| 255 | |
Florian Fainelli | bf3a1eb | 2011-02-27 19:53:53 +0100 | [diff] [blame] | 256 | static struct au1000_eth_platform_data mtx1_au1000_eth0_pdata = { |
| 257 | .phy_search_highest_addr = 1, |
Manuel Lauss | 8e02691 | 2011-11-10 12:06:21 +0000 | [diff] [blame] | 258 | .phy1_search_mac0 = 1, |
Florian Fainelli | bf3a1eb | 2011-02-27 19:53:53 +0100 | [diff] [blame] | 259 | }; |
| 260 | |
Florian Fainelli | 26c288f | 2007-10-23 18:55:55 +0200 | [diff] [blame] | 261 | static int __init mtx1_register_devices(void) |
| 262 | { |
Florian Fainelli | a1b021d | 2009-08-01 23:51:20 +0200 | [diff] [blame] | 263 | int rc; |
| 264 | |
Manuel Lauss | 8e02691 | 2011-11-10 12:06:21 +0000 | [diff] [blame] | 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); |
| 270 | |
Florian Fainelli | bf3a1eb | 2011-02-27 19:53:53 +0100 | [diff] [blame] | 271 | au1xxx_override_eth_cfg(0, &mtx1_au1000_eth0_pdata); |
| 272 | |
Florian Fainelli | a1b021d | 2009-08-01 23:51:20 +0200 | [diff] [blame] | 273 | rc = gpio_request(mtx1_gpio_button[0].gpio, |
| 274 | mtx1_gpio_button[0].desc); |
| 275 | if (rc < 0) { |
| 276 | printk(KERN_INFO "mtx1: failed to request %d\n", |
| 277 | mtx1_gpio_button[0].gpio); |
| 278 | goto out; |
| 279 | } |
| 280 | gpio_direction_input(mtx1_gpio_button[0].gpio); |
| 281 | out: |
Linus Walleij | d2b911d | 2018-12-22 11:12:31 +0100 | [diff] [blame] | 282 | gpiod_add_lookup_table(&mtx1_wdt_gpio_table); |
Florian Fainelli | 26c288f | 2007-10-23 18:55:55 +0200 | [diff] [blame] | 283 | return platform_add_devices(mtx1_devs, ARRAY_SIZE(mtx1_devs)); |
| 284 | } |
Florian Fainelli | 26c288f | 2007-10-23 18:55:55 +0200 | [diff] [blame] | 285 | arch_initcall(mtx1_register_devices); |