1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * This contain platform specific code for APM PPC460EX based Canyonlands
4  * board.
5  *
6  * Copyright (c) 2010, Applied Micro Circuits Corporation
7  * Author: Rupjyoti Sarmah <rsarmah@apm.com>
8  */
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <asm/pci-bridge.h>
12 #include <asm/ppc4xx.h>
13 #include <asm/udbg.h>
14 #include <asm/uic.h>
15 #include <linux/of_address.h>
16 #include <linux/of_platform.h>
17 #include <linux/delay.h>
18 #include "44x.h"
19 
20 #define BCSR_USB_EN	0x11
21 
22 static const struct of_device_id ppc460ex_of_bus[] __initconst = {
23 	{ .compatible = "ibm,plb4", },
24 	{ .compatible = "ibm,opb", },
25 	{ .compatible = "ibm,ebc", },
26 	{ .compatible = "simple-bus", },
27 	{},
28 };
29 
30 static int __init ppc460ex_device_probe(void)
31 {
32 	of_platform_bus_probe(NULL, ppc460ex_of_bus, NULL);
33 
34 	return 0;
35 }
36 machine_device_initcall(canyonlands, ppc460ex_device_probe);
37 
38 /* Using this code only for the Canyonlands board.  */
39 
40 static int __init ppc460ex_probe(void)
41 {
42 	if (of_machine_is_compatible("amcc,canyonlands")) {
43 		pci_set_flags(PCI_REASSIGN_ALL_RSRC);
44 		return 1;
45 	}
46 	return 0;
47 }
48 
49 /* USB PHY fixup code on Canyonlands kit. */
50 
51 static int __init ppc460ex_canyonlands_fixup(void)
52 {
53 	u8 __iomem *bcsr ;
54 	void __iomem *vaddr;
55 	struct device_node *np;
56 	int ret = 0;
57 
58 	np = of_find_compatible_node(NULL, NULL, "amcc,ppc460ex-bcsr");
59 	if (!np) {
60 		printk(KERN_ERR "failed did not find amcc, ppc460ex bcsr node\n");
61 		return -ENODEV;
62 	}
63 
64 	bcsr = of_iomap(np, 0);
65 	of_node_put(np);
66 
67 	if (!bcsr) {
68 		printk(KERN_CRIT "Could not remap bcsr\n");
69 		ret = -ENODEV;
70 		goto err_bcsr;
71 	}
72 
73 	np = of_find_compatible_node(NULL, NULL, "ibm,ppc4xx-gpio");
74 	if (!np) {
75 		printk(KERN_ERR "failed did not find ibm,ppc4xx-gpio node\n");
76 		return -ENODEV;
77 	}
78 
79 	vaddr = of_iomap(np, 0);
80 	of_node_put(np);
81 
82 	if (!vaddr) {
83 		printk(KERN_CRIT "Could not get gpio node address\n");
84 		ret = -ENODEV;
85 		goto err_gpio;
86 	}
87 	/* Disable USB, through the BCSR7 bits */
88 	setbits8(&bcsr[7], BCSR_USB_EN);
89 
90 	/* Wait for a while after reset */
91 	msleep(100);
92 
93 	/* Enable USB here */
94 	clrbits8(&bcsr[7], BCSR_USB_EN);
95 
96 	/*
97 	 * Configure multiplexed gpio16 and gpio19 as alternate1 output
98 	 * source after USB reset. In this configuration gpio16 will be
99 	 * USB2HStop and gpio19 will be USB2DStop. For more details refer to
100 	 * table 34-7 of PPC460EX user manual.
101 	 */
102 	setbits32((vaddr + GPIO0_OSRH), 0x42000000);
103 	setbits32((vaddr + GPIO0_TSRH), 0x42000000);
104 err_gpio:
105 	iounmap(vaddr);
106 err_bcsr:
107 	iounmap(bcsr);
108 	return ret;
109 }
110 machine_device_initcall(canyonlands, ppc460ex_canyonlands_fixup);
111 define_machine(canyonlands) {
112 	.name = "Canyonlands",
113 	.probe = ppc460ex_probe,
114 	.progress = udbg_progress,
115 	.init_IRQ = uic_init_tree,
116 	.get_irq = uic_get_irq,
117 	.restart = ppc4xx_reset_system,
118 	.calibrate_decr = generic_calibrate_decr,
119 };
120