blob: 0caa3d955c3b2b6948c620104c21f63fe5589ccc [file] [log] [blame]
Grant Likely6b642532006-11-27 14:16:28 -07001/*
2 * Freescale Lite5200 board support
3 *
4 * Written by: Grant Likely <grant.likely@secretlab.ca>
5 *
6 * Copyright (C) Secret Lab Technologies Ltd. 2006. All rights reserved.
7 * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved.
8 *
9 * Description:
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 */
15
16#undef DEBUG
17
Grant Likely6b642532006-11-27 14:16:28 -070018#include <linux/init.h>
Grant Likely6b642532006-11-27 14:16:28 -070019#include <linux/pci.h>
Grant Likely9fe2e792007-10-10 09:52:00 -060020#include <linux/of.h>
Grant Likely6b642532006-11-27 14:16:28 -070021#include <asm/time.h>
22#include <asm/io.h>
23#include <asm/machdep.h>
Grant Likely6b642532006-11-27 14:16:28 -070024#include <asm/prom.h>
Grant Likely6b642532006-11-27 14:16:28 -070025#include <asm/mpc52xx.h>
26
27/* ************************************************************************
28 *
29 * Setup the architecture
30 *
31 */
32
Grant Likely4de3b992007-10-09 14:45:28 -060033/*
34 * Fix clock configuration.
35 *
36 * Firmware is supposed to be responsible for this. If you are creating a
37 * new board port, do *NOT* duplicate this code. Fix your boot firmware
38 * to set it correctly in the first place
39 */
Grant Likely6b642532006-11-27 14:16:28 -070040static void __init
Grant Likely4de3b992007-10-09 14:45:28 -060041lite5200_fix_clock_config(void)
42{
43 struct mpc52xx_cdm __iomem *cdm;
44
45 /* Map zones */
46 cdm = mpc52xx_find_and_map("mpc5200-cdm");
47 if (!cdm) {
48 printk(KERN_ERR "%s() failed; expect abnormal behaviour\n",
49 __FUNCTION__);
50 return;
51 }
52
53 /* Use internal 48 Mhz */
54 out_8(&cdm->ext_48mhz_en, 0x00);
55 out_8(&cdm->fd_enable, 0x01);
56 if (in_be32(&cdm->rstcfg) & 0x40) /* Assumes 33Mhz clock */
57 out_be16(&cdm->fd_counters, 0x0001);
58 else
59 out_be16(&cdm->fd_counters, 0x5555);
60
61 /* Unmap the regs */
62 iounmap(cdm);
63}
64
65/*
66 * Fix setting of port_config register.
67 *
68 * Firmware is supposed to be responsible for this. If you are creating a
69 * new board port, do *NOT* duplicate this code. Fix your boot firmware
70 * to set it correctly in the first place
71 */
72static void __init
73lite5200_fix_port_config(void)
Grant Likely6b642532006-11-27 14:16:28 -070074{
75 struct mpc52xx_gpio __iomem *gpio;
76 u32 port_config;
77
Grant Likelye3aba812007-02-12 13:36:55 -070078 gpio = mpc52xx_find_and_map("mpc5200-gpio");
Grant Likely6b642532006-11-27 14:16:28 -070079 if (!gpio) {
Grant Likely4de3b992007-10-09 14:45:28 -060080 printk(KERN_ERR "%s() failed. expect abnormal behavior\n",
81 __FUNCTION__);
82 return;
Grant Likely6b642532006-11-27 14:16:28 -070083 }
84
85 /* Set port config */
86 port_config = in_be32(&gpio->port_config);
87
88 port_config &= ~0x00800000; /* 48Mhz internal, pin is GPIO */
89
90 port_config &= ~0x00007000; /* USB port : Differential mode */
91 port_config |= 0x00001000; /* USB 1 only */
92
93 port_config &= ~0x03000000; /* ATA CS is on csb_4/5 */
94 port_config |= 0x01000000;
95
96 pr_debug("port_config: old:%x new:%x\n",
97 in_be32(&gpio->port_config), port_config);
98 out_be32(&gpio->port_config, port_config);
99
100 /* Unmap zone */
Grant Likely6b642532006-11-27 14:16:28 -0700101 iounmap(gpio);
102}
103
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000104#ifdef CONFIG_PM
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000105static void lite5200_suspend_prepare(void __iomem *mbar)
106{
107 u8 pin = 1; /* GPIO_WKUP_1 (GPIO_PSC2_4) */
108 u8 level = 0; /* wakeup on low level */
109 mpc52xx_set_wakeup_gpio(pin, level);
110
111 /*
112 * power down usb port
113 * this needs to be called before of-ohci suspend code
114 */
Domen Punceree983072007-07-18 06:32:31 +1000115
116 /* set ports to "power switched" and "powered at the same time"
117 * USB Rh descriptor A: NPS = 0, PSM = 0 */
118 out_be32(mbar + 0x1048, in_be32(mbar + 0x1048) & ~0x300);
119 /* USB Rh status: LPS = 1 - turn off power */
120 out_be32(mbar + 0x1050, 0x00000001);
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000121}
122
123static void lite5200_resume_finish(void __iomem *mbar)
124{
Domen Punceree983072007-07-18 06:32:31 +1000125 /* USB Rh status: LPSC = 1 - turn on power */
126 out_be32(mbar + 0x1050, 0x00010000);
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000127}
128#endif
129
Grant Likelye3aba812007-02-12 13:36:55 -0700130static void __init lite5200_setup_arch(void)
Grant Likely6b642532006-11-27 14:16:28 -0700131{
Jon Loeliger7888fbf2007-07-28 04:24:52 +1000132#ifdef CONFIG_PCI
Grant Likely6b642532006-11-27 14:16:28 -0700133 struct device_node *np;
Jon Loeliger7888fbf2007-07-28 04:24:52 +1000134#endif
Grant Likely6b642532006-11-27 14:16:28 -0700135
136 if (ppc_md.progress)
Grant Likelye3aba812007-02-12 13:36:55 -0700137 ppc_md.progress("lite5200_setup_arch()", 0);
Grant Likely6b642532006-11-27 14:16:28 -0700138
Grant Likely4de3b992007-10-09 14:45:28 -0600139 /* Fix things that firmware should have done. */
140 lite5200_fix_clock_config();
141 lite5200_fix_port_config();
142
143 /* Some mpc5200 & mpc5200b related configuration */
144 mpc5200_setup_xlb_arbiter();
Grant Likely6b642532006-11-27 14:16:28 -0700145
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000146#ifdef CONFIG_PM
147 mpc52xx_suspend.board_suspend_prepare = lite5200_suspend_prepare;
148 mpc52xx_suspend.board_resume_finish = lite5200_resume_finish;
Domen Punceree983072007-07-18 06:32:31 +1000149 lite5200_pm_init();
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000150#endif
151
Grant Likelyf42963f2006-12-12 15:13:19 -0700152#ifdef CONFIG_PCI
John Rigby6ec36702007-04-07 08:57:37 +1000153 np = of_find_node_by_type(NULL, "pci");
154 if (np) {
Grant Likelyf42963f2006-12-12 15:13:19 -0700155 mpc52xx_add_bridge(np);
John Rigby6ec36702007-04-07 08:57:37 +1000156 of_node_put(np);
157 }
Grant Likelyf42963f2006-12-12 15:13:19 -0700158#endif
159
Grant Likely6b642532006-11-27 14:16:28 -0700160#ifdef CONFIG_BLK_DEV_INITRD
161 if (initrd_start)
162 ROOT_DEV = Root_RAM0;
163 else
164#endif
165#ifdef CONFIG_ROOT_NFS
166 ROOT_DEV = Root_NFS;
167#else
168 ROOT_DEV = Root_HDA1;
169#endif
170
171}
172
Grant Likely6b642532006-11-27 14:16:28 -0700173/*
174 * Called very early, MMU is off, device-tree isn't unflattened
175 */
Grant Likelye3aba812007-02-12 13:36:55 -0700176static int __init lite5200_probe(void)
Grant Likely6b642532006-11-27 14:16:28 -0700177{
178 unsigned long node = of_get_flat_dt_root();
179 const char *model = of_get_flat_dt_prop(node, "model", NULL);
180
Grant Likelye3aba812007-02-12 13:36:55 -0700181 if (!of_flat_dt_is_compatible(node, "fsl,lite5200") &&
182 !of_flat_dt_is_compatible(node, "fsl,lite5200b"))
Grant Likely6b642532006-11-27 14:16:28 -0700183 return 0;
Grant Likelye3aba812007-02-12 13:36:55 -0700184 pr_debug("%s board found\n", model ? model : "unknown");
Grant Likely6b642532006-11-27 14:16:28 -0700185
186 return 1;
187}
188
Grant Likelye3aba812007-02-12 13:36:55 -0700189define_machine(lite5200) {
190 .name = "lite5200",
191 .probe = lite5200_probe,
192 .setup_arch = lite5200_setup_arch,
Sylvain Munaut5c334ee2007-01-02 23:29:53 +0100193 .init = mpc52xx_declare_of_platform_devices,
Grant Likely6b642532006-11-27 14:16:28 -0700194 .init_IRQ = mpc52xx_init_irq,
195 .get_irq = mpc52xx_get_irq,
Grant Likely6b642532006-11-27 14:16:28 -0700196 .calibrate_decr = generic_calibrate_decr,
197};