1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * MTX-1 platform devices registration (Au1500) 4 * 5 * Copyright (C) 2007-2009, Florian Fainelli <florian@openwrt.org> 6 */ 7 8 #include <linux/init.h> 9 #include <linux/interrupt.h> 10 #include <linux/kernel.h> 11 #include <linux/platform_device.h> 12 #include <linux/property.h> 13 #include <linux/gpio/machine.h> 14 #include <linux/gpio/property.h> 15 #include <linux/input.h> 16 #include <linux/mtd/partitions.h> 17 #include <linux/mtd/physmap.h> 18 #include <mtd/mtd-abi.h> 19 #include <asm/bootinfo.h> 20 #include <asm/reboot.h> 21 #include <asm/setup.h> 22 #include <asm/mach-au1x00/au1000.h> 23 #include <asm/mach-au1x00/gpio-au1000.h> 24 #include <asm/mach-au1x00/au1xxx_eth.h> 25 #include <prom.h> 26 27 const char *get_system_type(void) 28 { 29 return "MTX-1"; 30 } 31 32 void prom_putchar(char c) 33 { 34 alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c); 35 } 36 37 static void mtx1_reset(char *c) 38 { 39 /* Jump to the reset vector */ 40 __asm__ __volatile__("jr\t%0" : : "r"(0xbfc00000)); 41 } 42 43 static void mtx1_power_off(void) 44 { 45 while (1) 46 asm volatile ( 47 " .set mips32 \n" 48 " wait \n" 49 " .set mips0 \n"); 50 } 51 52 void __init board_setup(void) 53 { 54 #if IS_ENABLED(CONFIG_USB_OHCI_HCD) 55 /* Enable USB power switch */ 56 alchemy_gpio_direction_output(204, 0); 57 #endif /* IS_ENABLED(CONFIG_USB_OHCI_HCD) */ 58 59 /* Initialize sys_pinfunc */ 60 alchemy_wrsys(SYS_PF_NI2, AU1000_SYS_PINFUNC); 61 62 /* Initialize GPIO */ 63 alchemy_wrsys(~0, AU1000_SYS_TRIOUTCLR); 64 alchemy_gpio_direction_output(0, 0); /* Disable M66EN (PCI 66MHz) */ 65 alchemy_gpio_direction_output(3, 1); /* Disable PCI CLKRUN# */ 66 alchemy_gpio_direction_output(1, 1); /* Enable EXT_IO3 */ 67 alchemy_gpio_direction_output(5, 0); /* Disable eth PHY TX_ER */ 68 69 /* Enable LED and set it to green */ 70 alchemy_gpio_direction_output(211, 1); /* green on */ 71 alchemy_gpio_direction_output(212, 0); /* red off */ 72 73 pm_power_off = mtx1_power_off; 74 _machine_halt = mtx1_power_off; 75 _machine_restart = mtx1_reset; 76 77 printk(KERN_INFO "4G Systems MTX-1 Board\n"); 78 } 79 80 /******************************************************************************/ 81 82 static const struct software_node mtx1_gpio_keys_node = { 83 .name = "mtx1-gpio-keys", 84 }; 85 86 static const struct property_entry mtx1_button_props[] = { 87 PROPERTY_ENTRY_U32("linux,code", BTN_0), 88 PROPERTY_ENTRY_GPIO("gpios", &alchemy_gpio2_node, 7, GPIO_ACTIVE_HIGH), 89 PROPERTY_ENTRY_STRING("label", "System button"), 90 { } 91 }; 92 93 static const struct software_node mtx1_button_node = { 94 .parent = &mtx1_gpio_keys_node, 95 .properties = mtx1_button_props, 96 }; 97 98 static const struct software_node * const mtx1_gpio_keys_swnodes[] __initconst = { 99 &mtx1_gpio_keys_node, 100 &mtx1_button_node, 101 NULL 102 }; 103 104 static void __init mtx1_keys_init(void) 105 { 106 struct platform_device_info keys_info = { 107 .name = "gpio-keys", 108 .id = PLATFORM_DEVID_NONE, 109 }; 110 struct platform_device *pd; 111 int err; 112 113 err = software_node_register_node_group(mtx1_gpio_keys_swnodes); 114 if (err) { 115 pr_err("failed to register gpio-keys software nodes: %d\n", err); 116 return; 117 } 118 119 keys_info.fwnode = software_node_fwnode(&mtx1_gpio_keys_node); 120 121 pd = platform_device_register_full(&keys_info); 122 err = PTR_ERR_OR_ZERO(pd); 123 if (err) 124 pr_err("failed to create gpio-keys device: %d\n", err); 125 } 126 127 static const struct property_entry mtx1_wdt_props[] = { 128 /* Global number 215 is offset 15 on Alchemy GPIO 2 */ 129 PROPERTY_ENTRY_GPIO("gpios", &alchemy_gpio2_node, 15, GPIO_ACTIVE_HIGH), 130 { } 131 }; 132 133 static const struct platform_device_info mtx1_wdt_info __initconst = { 134 .name = "mtx1-wdt", 135 .id = 0, 136 .properties = mtx1_wdt_props, 137 }; 138 139 static void __init mtx1_wdt_init(void) 140 { 141 struct platform_device *pd; 142 int err; 143 144 pd = platform_device_register_full(&mtx1_wdt_info); 145 err = PTR_ERR_OR_ZERO(pd); 146 if (err) 147 pr_err("failed to create watchdog device: %d\n", err); 148 } 149 150 static const struct software_node mtx1_gpio_leds_node = { 151 .name = "mtx1-leds", 152 }; 153 154 static const struct property_entry mtx1_green_led_props[] = { 155 PROPERTY_ENTRY_GPIO("gpios", &alchemy_gpio2_node, 11, GPIO_ACTIVE_HIGH), 156 { } 157 }; 158 159 static const struct software_node mtx1_green_led_node = { 160 .name = "mtx1:green", 161 .parent = &mtx1_gpio_leds_node, 162 .properties = mtx1_green_led_props, 163 }; 164 165 static const struct property_entry mtx1_red_led_props[] = { 166 PROPERTY_ENTRY_GPIO("gpios", &alchemy_gpio2_node, 12, GPIO_ACTIVE_HIGH), 167 { } 168 }; 169 170 static const struct software_node mtx1_red_led_node = { 171 .name = "mtx1:red", 172 .parent = &mtx1_gpio_leds_node, 173 .properties = mtx1_red_led_props, 174 }; 175 176 static const struct software_node * const mtx1_gpio_leds_swnodes[] __initconst = { 177 &mtx1_gpio_leds_node, 178 &mtx1_green_led_node, 179 &mtx1_red_led_node, 180 NULL 181 }; 182 183 static void __init mtx1_leds_init(void) 184 { 185 const struct platform_device_info pdevinfo = { 186 .name = "leds-gpio", 187 .id = PLATFORM_DEVID_NONE, 188 .swnode = &mtx1_gpio_leds_node, 189 }; 190 struct platform_device *led_dev; 191 int err; 192 193 err = software_node_register_node_group(mtx1_gpio_leds_swnodes); 194 if (err) { 195 pr_err("failed to register LED software nodes: %d\n", err); 196 return; 197 } 198 199 led_dev = platform_device_register_full(&pdevinfo); 200 err = PTR_ERR_OR_ZERO(led_dev); 201 if (err) 202 pr_err("failed to create LED device: %d\n", err); 203 } 204 205 static struct mtd_partition mtx1_mtd_partitions[] = { 206 { 207 .name = "filesystem", 208 .size = 0x01C00000, 209 .offset = 0, 210 }, 211 { 212 .name = "yamon", 213 .size = 0x00100000, 214 .offset = MTDPART_OFS_APPEND, 215 .mask_flags = MTD_WRITEABLE, 216 }, 217 { 218 .name = "kernel", 219 .size = 0x002c0000, 220 .offset = MTDPART_OFS_APPEND, 221 }, 222 { 223 .name = "yamon env", 224 .size = 0x00040000, 225 .offset = MTDPART_OFS_APPEND, 226 }, 227 }; 228 229 static struct physmap_flash_data mtx1_flash_data = { 230 .width = 4, 231 .nr_parts = 4, 232 .parts = mtx1_mtd_partitions, 233 }; 234 235 static struct resource mtx1_mtd_resource = { 236 .start = 0x1e000000, 237 .end = 0x1fffffff, 238 .flags = IORESOURCE_MEM, 239 }; 240 241 static struct platform_device mtx1_mtd = { 242 .name = "physmap-flash", 243 .dev = { 244 .platform_data = &mtx1_flash_data, 245 }, 246 .num_resources = 1, 247 .resource = &mtx1_mtd_resource, 248 }; 249 250 static struct resource alchemy_pci_host_res[] = { 251 [0] = { 252 .start = AU1500_PCI_PHYS_ADDR, 253 .end = AU1500_PCI_PHYS_ADDR + 0xfff, 254 .flags = IORESOURCE_MEM, 255 }, 256 }; 257 258 static int mtx1_pci_idsel(unsigned int devsel, int assert) 259 { 260 /* This function is only necessary to support a proprietary Cardbus 261 * adapter on the mtx-1 "singleboard" variant. It triggers a custom 262 * logic chip connected to EXT_IO3 (GPIO1) to suppress IDSEL signals. 263 */ 264 udelay(1); 265 266 if (assert && devsel != 0) 267 /* Suppress signal to Cardbus */ 268 alchemy_gpio_set_value(1, 0); /* set EXT_IO3 OFF */ 269 else 270 alchemy_gpio_set_value(1, 1); /* set EXT_IO3 ON */ 271 272 udelay(1); 273 return 1; 274 } 275 276 static const char mtx1_irqtab[][5] = { 277 [0] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 00 - AdapterA-Slot0 (top) */ 278 [1] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 01 - AdapterA-Slot1 (bottom) */ 279 [2] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 02 - AdapterB-Slot0 (top) */ 280 [3] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 03 - AdapterB-Slot1 (bottom) */ 281 [4] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTB, 0xff, 0xff }, /* IDSEL 04 - AdapterC-Slot0 (top) */ 282 [5] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 05 - AdapterC-Slot1 (bottom) */ 283 [6] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 06 - AdapterD-Slot0 (top) */ 284 [7] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 07 - AdapterD-Slot1 (bottom) */ 285 }; 286 287 static int mtx1_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin) 288 { 289 return mtx1_irqtab[slot][pin]; 290 } 291 292 static struct alchemy_pci_platdata mtx1_pci_pd = { 293 .board_map_irq = mtx1_map_pci_irq, 294 .board_pci_idsel = mtx1_pci_idsel, 295 .pci_cfg_set = PCI_CONFIG_AEN | PCI_CONFIG_R2H | PCI_CONFIG_R1H | 296 PCI_CONFIG_CH | 297 #if defined(__MIPSEB__) 298 PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM, 299 #else 300 0, 301 #endif 302 }; 303 304 static struct platform_device mtx1_pci_host = { 305 .dev.platform_data = &mtx1_pci_pd, 306 .name = "alchemy-pci", 307 .id = 0, 308 .num_resources = ARRAY_SIZE(alchemy_pci_host_res), 309 .resource = alchemy_pci_host_res, 310 }; 311 312 static struct platform_device *mtx1_devs[] __initdata = { 313 &mtx1_pci_host, 314 &mtx1_mtd, 315 }; 316 317 static struct au1000_eth_platform_data mtx1_au1000_eth0_pdata = { 318 .phy_search_highest_addr = 1, 319 .phy1_search_mac0 = 1, 320 }; 321 322 static int __init mtx1_register_devices(void) 323 { 324 int rc; 325 326 irq_set_irq_type(AU1500_GPIO204_INT, IRQ_TYPE_LEVEL_HIGH); 327 irq_set_irq_type(AU1500_GPIO201_INT, IRQ_TYPE_LEVEL_LOW); 328 irq_set_irq_type(AU1500_GPIO202_INT, IRQ_TYPE_LEVEL_LOW); 329 irq_set_irq_type(AU1500_GPIO203_INT, IRQ_TYPE_LEVEL_LOW); 330 irq_set_irq_type(AU1500_GPIO205_INT, IRQ_TYPE_LEVEL_LOW); 331 332 au1xxx_override_eth_cfg(0, &mtx1_au1000_eth0_pdata); 333 334 rc = platform_add_devices(mtx1_devs, ARRAY_SIZE(mtx1_devs)); 335 if (rc) 336 return rc; 337 338 mtx1_leds_init(); 339 mtx1_wdt_init(); 340 mtx1_keys_init(); 341 342 return 0; 343 } 344 arch_initcall(mtx1_register_devices); 345