blob: 5a8d190f53e4303a86037d4eaa6e688f050d1614 [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>
Al Viroc1f807e2007-10-13 19:40:08 +010021#include <linux/root_dev.h>
22#include <linux/initrd.h>
Grant Likely6b642532006-11-27 14:16:28 -070023#include <asm/time.h>
24#include <asm/io.h>
25#include <asm/machdep.h>
Grant Likely6b642532006-11-27 14:16:28 -070026#include <asm/prom.h>
Grant Likely6b642532006-11-27 14:16:28 -070027#include <asm/mpc52xx.h>
28
29/* ************************************************************************
30 *
31 * Setup the architecture
32 *
33 */
34
Grant Likely4de3b992007-10-09 14:45:28 -060035/*
36 * Fix clock configuration.
37 *
38 * Firmware is supposed to be responsible for this. If you are creating a
39 * new board port, do *NOT* duplicate this code. Fix your boot firmware
40 * to set it correctly in the first place
41 */
Grant Likely6b642532006-11-27 14:16:28 -070042static void __init
Grant Likely4de3b992007-10-09 14:45:28 -060043lite5200_fix_clock_config(void)
44{
Grant Likely75ca3992008-01-18 09:30:37 -070045 struct device_node *np;
Grant Likely4de3b992007-10-09 14:45:28 -060046 struct mpc52xx_cdm __iomem *cdm;
47
48 /* Map zones */
Grant Likely75ca3992008-01-18 09:30:37 -070049 np = of_find_compatible_node(NULL, NULL, "mpc5200-cdm");
50 cdm = of_iomap(np, 0);
51 of_node_put(np);
Grant Likely4de3b992007-10-09 14:45:28 -060052 if (!cdm) {
53 printk(KERN_ERR "%s() failed; expect abnormal behaviour\n",
54 __FUNCTION__);
55 return;
56 }
57
58 /* Use internal 48 Mhz */
59 out_8(&cdm->ext_48mhz_en, 0x00);
60 out_8(&cdm->fd_enable, 0x01);
61 if (in_be32(&cdm->rstcfg) & 0x40) /* Assumes 33Mhz clock */
62 out_be16(&cdm->fd_counters, 0x0001);
63 else
64 out_be16(&cdm->fd_counters, 0x5555);
65
66 /* Unmap the regs */
67 iounmap(cdm);
68}
69
70/*
71 * Fix setting of port_config register.
72 *
73 * Firmware is supposed to be responsible for this. If you are creating a
74 * new board port, do *NOT* duplicate this code. Fix your boot firmware
75 * to set it correctly in the first place
76 */
77static void __init
78lite5200_fix_port_config(void)
Grant Likely6b642532006-11-27 14:16:28 -070079{
Grant Likely75ca3992008-01-18 09:30:37 -070080 struct device_node *np;
Grant Likely6b642532006-11-27 14:16:28 -070081 struct mpc52xx_gpio __iomem *gpio;
82 u32 port_config;
83
Grant Likely75ca3992008-01-18 09:30:37 -070084 np = of_find_compatible_node(NULL, NULL, "mpc5200-gpio");
85 gpio = of_iomap(np, 0);
86 of_node_put(np);
Grant Likely6b642532006-11-27 14:16:28 -070087 if (!gpio) {
Grant Likely4de3b992007-10-09 14:45:28 -060088 printk(KERN_ERR "%s() failed. expect abnormal behavior\n",
89 __FUNCTION__);
90 return;
Grant Likely6b642532006-11-27 14:16:28 -070091 }
92
93 /* Set port config */
94 port_config = in_be32(&gpio->port_config);
95
96 port_config &= ~0x00800000; /* 48Mhz internal, pin is GPIO */
97
98 port_config &= ~0x00007000; /* USB port : Differential mode */
99 port_config |= 0x00001000; /* USB 1 only */
100
101 port_config &= ~0x03000000; /* ATA CS is on csb_4/5 */
102 port_config |= 0x01000000;
103
104 pr_debug("port_config: old:%x new:%x\n",
105 in_be32(&gpio->port_config), port_config);
106 out_be32(&gpio->port_config, port_config);
107
108 /* Unmap zone */
Grant Likely6b642532006-11-27 14:16:28 -0700109 iounmap(gpio);
110}
111
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000112#ifdef CONFIG_PM
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000113static void lite5200_suspend_prepare(void __iomem *mbar)
114{
115 u8 pin = 1; /* GPIO_WKUP_1 (GPIO_PSC2_4) */
116 u8 level = 0; /* wakeup on low level */
117 mpc52xx_set_wakeup_gpio(pin, level);
118
119 /*
120 * power down usb port
121 * this needs to be called before of-ohci suspend code
122 */
Domen Punceree983072007-07-18 06:32:31 +1000123
124 /* set ports to "power switched" and "powered at the same time"
125 * USB Rh descriptor A: NPS = 0, PSM = 0 */
126 out_be32(mbar + 0x1048, in_be32(mbar + 0x1048) & ~0x300);
127 /* USB Rh status: LPS = 1 - turn off power */
128 out_be32(mbar + 0x1050, 0x00000001);
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000129}
130
131static void lite5200_resume_finish(void __iomem *mbar)
132{
Domen Punceree983072007-07-18 06:32:31 +1000133 /* USB Rh status: LPSC = 1 - turn on power */
134 out_be32(mbar + 0x1050, 0x00010000);
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000135}
136#endif
137
Grant Likelye3aba812007-02-12 13:36:55 -0700138static void __init lite5200_setup_arch(void)
Grant Likely6b642532006-11-27 14:16:28 -0700139{
Grant Likely6b642532006-11-27 14:16:28 -0700140 if (ppc_md.progress)
Grant Likelye3aba812007-02-12 13:36:55 -0700141 ppc_md.progress("lite5200_setup_arch()", 0);
Grant Likely6b642532006-11-27 14:16:28 -0700142
Grant Likely4de3b992007-10-09 14:45:28 -0600143 /* Fix things that firmware should have done. */
144 lite5200_fix_clock_config();
145 lite5200_fix_port_config();
146
147 /* Some mpc5200 & mpc5200b related configuration */
148 mpc5200_setup_xlb_arbiter();
Grant Likely6b642532006-11-27 14:16:28 -0700149
Marian Balakowicz9dda78b2007-10-19 04:44:39 +1000150 /* Map wdt for mpc52xx_restart() */
151 mpc52xx_map_wdt();
152
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000153#ifdef CONFIG_PM
154 mpc52xx_suspend.board_suspend_prepare = lite5200_suspend_prepare;
155 mpc52xx_suspend.board_resume_finish = lite5200_resume_finish;
Domen Punceree983072007-07-18 06:32:31 +1000156 lite5200_pm_init();
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000157#endif
158
Marian Balakowiczf584bc62007-11-10 04:11:56 +1100159 mpc52xx_setup_pci();
Grant Likely6b642532006-11-27 14:16:28 -0700160}
161
Grant Likely6b642532006-11-27 14:16:28 -0700162/*
163 * Called very early, MMU is off, device-tree isn't unflattened
164 */
Grant Likelye3aba812007-02-12 13:36:55 -0700165static int __init lite5200_probe(void)
Grant Likely6b642532006-11-27 14:16:28 -0700166{
167 unsigned long node = of_get_flat_dt_root();
168 const char *model = of_get_flat_dt_prop(node, "model", NULL);
169
Grant Likelye3aba812007-02-12 13:36:55 -0700170 if (!of_flat_dt_is_compatible(node, "fsl,lite5200") &&
171 !of_flat_dt_is_compatible(node, "fsl,lite5200b"))
Grant Likely6b642532006-11-27 14:16:28 -0700172 return 0;
Grant Likelye3aba812007-02-12 13:36:55 -0700173 pr_debug("%s board found\n", model ? model : "unknown");
Grant Likely6b642532006-11-27 14:16:28 -0700174
175 return 1;
176}
177
Grant Likelye3aba812007-02-12 13:36:55 -0700178define_machine(lite5200) {
179 .name = "lite5200",
180 .probe = lite5200_probe,
181 .setup_arch = lite5200_setup_arch,
Sylvain Munaut5c334ee2007-01-02 23:29:53 +0100182 .init = mpc52xx_declare_of_platform_devices,
Grant Likely6b642532006-11-27 14:16:28 -0700183 .init_IRQ = mpc52xx_init_irq,
184 .get_irq = mpc52xx_get_irq,
Marian Balakowicz9dda78b2007-10-19 04:44:39 +1000185 .restart = mpc52xx_restart,
Grant Likely6b642532006-11-27 14:16:28 -0700186 .calibrate_decr = generic_calibrate_decr,
187};