blob: de55bc0584b5d6cadaa24572db3302dbd0ea19ea [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 Likely22ae7822010-07-29 11:49:01 -060021#include <linux/of_address.h>
Al Viroc1f807e2007-10-13 19:40:08 +010022#include <linux/root_dev.h>
23#include <linux/initrd.h>
Grant Likely6b642532006-11-27 14:16:28 -070024#include <asm/time.h>
25#include <asm/io.h>
26#include <asm/machdep.h>
Grant Likely6b642532006-11-27 14:16:28 -070027#include <asm/prom.h>
Grant Likely6b642532006-11-27 14:16:28 -070028#include <asm/mpc52xx.h>
29
30/* ************************************************************************
31 *
32 * Setup the architecture
33 *
34 */
35
Grant Likely66ffbe42008-01-24 22:25:31 -070036/* mpc5200 device tree match tables */
37static struct of_device_id mpc5200_cdm_ids[] __initdata = {
38 { .compatible = "fsl,mpc5200-cdm", },
39 { .compatible = "mpc5200-cdm", },
40 {}
41};
42
43static struct of_device_id mpc5200_gpio_ids[] __initdata = {
44 { .compatible = "fsl,mpc5200-gpio", },
45 { .compatible = "mpc5200-gpio", },
46 {}
47};
48
Grant Likely4de3b992007-10-09 14:45:28 -060049/*
50 * Fix clock configuration.
51 *
52 * Firmware is supposed to be responsible for this. If you are creating a
53 * new board port, do *NOT* duplicate this code. Fix your boot firmware
54 * to set it correctly in the first place
55 */
Grant Likely6b642532006-11-27 14:16:28 -070056static void __init
Grant Likely4de3b992007-10-09 14:45:28 -060057lite5200_fix_clock_config(void)
58{
Grant Likely75ca3992008-01-18 09:30:37 -070059 struct device_node *np;
Grant Likely4de3b992007-10-09 14:45:28 -060060 struct mpc52xx_cdm __iomem *cdm;
Grant Likely4de3b992007-10-09 14:45:28 -060061 /* Map zones */
Grant Likely66ffbe42008-01-24 22:25:31 -070062 np = of_find_matching_node(NULL, mpc5200_cdm_ids);
Grant Likely75ca3992008-01-18 09:30:37 -070063 cdm = of_iomap(np, 0);
64 of_node_put(np);
Grant Likely4de3b992007-10-09 14:45:28 -060065 if (!cdm) {
66 printk(KERN_ERR "%s() failed; expect abnormal behaviour\n",
Harvey Harrisone48b1b42008-03-29 08:21:07 +110067 __func__);
Grant Likely4de3b992007-10-09 14:45:28 -060068 return;
69 }
70
71 /* Use internal 48 Mhz */
72 out_8(&cdm->ext_48mhz_en, 0x00);
73 out_8(&cdm->fd_enable, 0x01);
74 if (in_be32(&cdm->rstcfg) & 0x40) /* Assumes 33Mhz clock */
75 out_be16(&cdm->fd_counters, 0x0001);
76 else
77 out_be16(&cdm->fd_counters, 0x5555);
78
79 /* Unmap the regs */
80 iounmap(cdm);
81}
82
83/*
84 * Fix setting of port_config register.
85 *
86 * Firmware is supposed to be responsible for this. If you are creating a
87 * new board port, do *NOT* duplicate this code. Fix your boot firmware
88 * to set it correctly in the first place
89 */
90static void __init
91lite5200_fix_port_config(void)
Grant Likely6b642532006-11-27 14:16:28 -070092{
Grant Likely75ca3992008-01-18 09:30:37 -070093 struct device_node *np;
Grant Likely6b642532006-11-27 14:16:28 -070094 struct mpc52xx_gpio __iomem *gpio;
95 u32 port_config;
96
Grant Likely66ffbe42008-01-24 22:25:31 -070097 np = of_find_matching_node(NULL, mpc5200_gpio_ids);
Grant Likely75ca3992008-01-18 09:30:37 -070098 gpio = of_iomap(np, 0);
99 of_node_put(np);
Grant Likely6b642532006-11-27 14:16:28 -0700100 if (!gpio) {
Grant Likely4de3b992007-10-09 14:45:28 -0600101 printk(KERN_ERR "%s() failed. expect abnormal behavior\n",
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100102 __func__);
Grant Likely4de3b992007-10-09 14:45:28 -0600103 return;
Grant Likely6b642532006-11-27 14:16:28 -0700104 }
105
106 /* Set port config */
107 port_config = in_be32(&gpio->port_config);
108
109 port_config &= ~0x00800000; /* 48Mhz internal, pin is GPIO */
110
111 port_config &= ~0x00007000; /* USB port : Differential mode */
112 port_config |= 0x00001000; /* USB 1 only */
113
114 port_config &= ~0x03000000; /* ATA CS is on csb_4/5 */
115 port_config |= 0x01000000;
116
117 pr_debug("port_config: old:%x new:%x\n",
118 in_be32(&gpio->port_config), port_config);
119 out_be32(&gpio->port_config, port_config);
120
121 /* Unmap zone */
Grant Likely6b642532006-11-27 14:16:28 -0700122 iounmap(gpio);
123}
124
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000125#ifdef CONFIG_PM
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000126static void lite5200_suspend_prepare(void __iomem *mbar)
127{
128 u8 pin = 1; /* GPIO_WKUP_1 (GPIO_PSC2_4) */
129 u8 level = 0; /* wakeup on low level */
130 mpc52xx_set_wakeup_gpio(pin, level);
131
132 /*
133 * power down usb port
134 * this needs to be called before of-ohci suspend code
135 */
Domen Punceree983072007-07-18 06:32:31 +1000136
137 /* set ports to "power switched" and "powered at the same time"
138 * USB Rh descriptor A: NPS = 0, PSM = 0 */
139 out_be32(mbar + 0x1048, in_be32(mbar + 0x1048) & ~0x300);
140 /* USB Rh status: LPS = 1 - turn off power */
141 out_be32(mbar + 0x1050, 0x00000001);
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000142}
143
144static void lite5200_resume_finish(void __iomem *mbar)
145{
Domen Punceree983072007-07-18 06:32:31 +1000146 /* USB Rh status: LPSC = 1 - turn on power */
147 out_be32(mbar + 0x1050, 0x00010000);
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000148}
149#endif
150
Grant Likelye3aba812007-02-12 13:36:55 -0700151static void __init lite5200_setup_arch(void)
Grant Likely6b642532006-11-27 14:16:28 -0700152{
Grant Likely6b642532006-11-27 14:16:28 -0700153 if (ppc_md.progress)
Grant Likelye3aba812007-02-12 13:36:55 -0700154 ppc_md.progress("lite5200_setup_arch()", 0);
Grant Likely6b642532006-11-27 14:16:28 -0700155
Grant Likelyc8004a22008-01-24 22:25:31 -0700156 /* Map important registers from the internal memory map */
157 mpc52xx_map_common_devices();
Grant Likely4de3b992007-10-09 14:45:28 -0600158
159 /* Some mpc5200 & mpc5200b related configuration */
160 mpc5200_setup_xlb_arbiter();
Grant Likely6b642532006-11-27 14:16:28 -0700161
Grant Likelyc8004a22008-01-24 22:25:31 -0700162 /* Fix things that firmware should have done. */
163 lite5200_fix_clock_config();
164 lite5200_fix_port_config();
Marian Balakowicz9dda78b2007-10-19 04:44:39 +1000165
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000166#ifdef CONFIG_PM
167 mpc52xx_suspend.board_suspend_prepare = lite5200_suspend_prepare;
168 mpc52xx_suspend.board_resume_finish = lite5200_resume_finish;
Domen Punceree983072007-07-18 06:32:31 +1000169 lite5200_pm_init();
Domen Puncer2e1ee1f2007-05-07 01:38:52 +1000170#endif
171
Marian Balakowiczf584bc62007-11-10 04:11:56 +1100172 mpc52xx_setup_pci();
Grant Likely6b642532006-11-27 14:16:28 -0700173}
174
Grant Likely6b642532006-11-27 14:16:28 -0700175/*
176 * Called very early, MMU is off, device-tree isn't unflattened
177 */
Grant Likelye3aba812007-02-12 13:36:55 -0700178static int __init lite5200_probe(void)
Grant Likely6b642532006-11-27 14:16:28 -0700179{
180 unsigned long node = of_get_flat_dt_root();
181 const char *model = of_get_flat_dt_prop(node, "model", NULL);
182
Grant Likelye3aba812007-02-12 13:36:55 -0700183 if (!of_flat_dt_is_compatible(node, "fsl,lite5200") &&
184 !of_flat_dt_is_compatible(node, "fsl,lite5200b"))
Grant Likely6b642532006-11-27 14:16:28 -0700185 return 0;
Grant Likelye3aba812007-02-12 13:36:55 -0700186 pr_debug("%s board found\n", model ? model : "unknown");
Grant Likely6b642532006-11-27 14:16:28 -0700187
188 return 1;
189}
190
Grant Likelye3aba812007-02-12 13:36:55 -0700191define_machine(lite5200) {
192 .name = "lite5200",
193 .probe = lite5200_probe,
194 .setup_arch = lite5200_setup_arch,
Sylvain Munaut5c334ee2007-01-02 23:29:53 +0100195 .init = mpc52xx_declare_of_platform_devices,
Grant Likely6b642532006-11-27 14:16:28 -0700196 .init_IRQ = mpc52xx_init_irq,
197 .get_irq = mpc52xx_get_irq,
Marian Balakowicz9dda78b2007-10-19 04:44:39 +1000198 .restart = mpc52xx_restart,
Grant Likely6b642532006-11-27 14:16:28 -0700199 .calibrate_decr = generic_calibrate_decr,
200};