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