Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 1 | /* |
| 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 Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 18 | #include <linux/init.h> |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 19 | #include <linux/pci.h> |
Grant Likely | 9fe2e79 | 2007-10-10 09:52:00 -0600 | [diff] [blame] | 20 | #include <linux/of.h> |
Al Viro | c1f807e | 2007-10-13 19:40:08 +0100 | [diff] [blame] | 21 | #include <linux/root_dev.h> |
| 22 | #include <linux/initrd.h> |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 23 | #include <asm/time.h> |
| 24 | #include <asm/io.h> |
| 25 | #include <asm/machdep.h> |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 26 | #include <asm/prom.h> |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 27 | #include <asm/mpc52xx.h> |
| 28 | |
| 29 | /* ************************************************************************ |
| 30 | * |
| 31 | * Setup the architecture |
| 32 | * |
| 33 | */ |
| 34 | |
Grant Likely | 66ffbe4 | 2008-01-24 22:25:31 -0700 | [diff] [blame] | 35 | /* mpc5200 device tree match tables */ |
| 36 | static struct of_device_id mpc5200_cdm_ids[] __initdata = { |
| 37 | { .compatible = "fsl,mpc5200-cdm", }, |
| 38 | { .compatible = "mpc5200-cdm", }, |
| 39 | {} |
| 40 | }; |
| 41 | |
| 42 | static struct of_device_id mpc5200_gpio_ids[] __initdata = { |
| 43 | { .compatible = "fsl,mpc5200-gpio", }, |
| 44 | { .compatible = "mpc5200-gpio", }, |
| 45 | {} |
| 46 | }; |
| 47 | |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 48 | /* |
| 49 | * Fix clock configuration. |
| 50 | * |
| 51 | * Firmware is supposed to be responsible for this. If you are creating a |
| 52 | * new board port, do *NOT* duplicate this code. Fix your boot firmware |
| 53 | * to set it correctly in the first place |
| 54 | */ |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 55 | static void __init |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 56 | lite5200_fix_clock_config(void) |
| 57 | { |
Grant Likely | 75ca399 | 2008-01-18 09:30:37 -0700 | [diff] [blame] | 58 | struct device_node *np; |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 59 | struct mpc52xx_cdm __iomem *cdm; |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 60 | /* Map zones */ |
Grant Likely | 66ffbe4 | 2008-01-24 22:25:31 -0700 | [diff] [blame] | 61 | np = of_find_matching_node(NULL, mpc5200_cdm_ids); |
Grant Likely | 75ca399 | 2008-01-18 09:30:37 -0700 | [diff] [blame] | 62 | cdm = of_iomap(np, 0); |
| 63 | of_node_put(np); |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 64 | if (!cdm) { |
| 65 | printk(KERN_ERR "%s() failed; expect abnormal behaviour\n", |
Harvey Harrison | e48b1b4 | 2008-03-29 08:21:07 +1100 | [diff] [blame] | 66 | __func__); |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 67 | return; |
| 68 | } |
| 69 | |
| 70 | /* Use internal 48 Mhz */ |
| 71 | out_8(&cdm->ext_48mhz_en, 0x00); |
| 72 | out_8(&cdm->fd_enable, 0x01); |
| 73 | if (in_be32(&cdm->rstcfg) & 0x40) /* Assumes 33Mhz clock */ |
| 74 | out_be16(&cdm->fd_counters, 0x0001); |
| 75 | else |
| 76 | out_be16(&cdm->fd_counters, 0x5555); |
| 77 | |
| 78 | /* Unmap the regs */ |
| 79 | iounmap(cdm); |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * Fix setting of port_config register. |
| 84 | * |
| 85 | * Firmware is supposed to be responsible for this. If you are creating a |
| 86 | * new board port, do *NOT* duplicate this code. Fix your boot firmware |
| 87 | * to set it correctly in the first place |
| 88 | */ |
| 89 | static void __init |
| 90 | lite5200_fix_port_config(void) |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 91 | { |
Grant Likely | 75ca399 | 2008-01-18 09:30:37 -0700 | [diff] [blame] | 92 | struct device_node *np; |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 93 | struct mpc52xx_gpio __iomem *gpio; |
| 94 | u32 port_config; |
| 95 | |
Grant Likely | 66ffbe4 | 2008-01-24 22:25:31 -0700 | [diff] [blame] | 96 | np = of_find_matching_node(NULL, mpc5200_gpio_ids); |
Grant Likely | 75ca399 | 2008-01-18 09:30:37 -0700 | [diff] [blame] | 97 | gpio = of_iomap(np, 0); |
| 98 | of_node_put(np); |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 99 | if (!gpio) { |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 100 | printk(KERN_ERR "%s() failed. expect abnormal behavior\n", |
Harvey Harrison | e48b1b4 | 2008-03-29 08:21:07 +1100 | [diff] [blame] | 101 | __func__); |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 102 | return; |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* Set port config */ |
| 106 | port_config = in_be32(&gpio->port_config); |
| 107 | |
| 108 | port_config &= ~0x00800000; /* 48Mhz internal, pin is GPIO */ |
| 109 | |
| 110 | port_config &= ~0x00007000; /* USB port : Differential mode */ |
| 111 | port_config |= 0x00001000; /* USB 1 only */ |
| 112 | |
| 113 | port_config &= ~0x03000000; /* ATA CS is on csb_4/5 */ |
| 114 | port_config |= 0x01000000; |
| 115 | |
| 116 | pr_debug("port_config: old:%x new:%x\n", |
| 117 | in_be32(&gpio->port_config), port_config); |
| 118 | out_be32(&gpio->port_config, port_config); |
| 119 | |
| 120 | /* Unmap zone */ |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 121 | iounmap(gpio); |
| 122 | } |
| 123 | |
Domen Puncer | 2e1ee1f | 2007-05-07 01:38:52 +1000 | [diff] [blame] | 124 | #ifdef CONFIG_PM |
Domen Puncer | 2e1ee1f | 2007-05-07 01:38:52 +1000 | [diff] [blame] | 125 | static void lite5200_suspend_prepare(void __iomem *mbar) |
| 126 | { |
| 127 | u8 pin = 1; /* GPIO_WKUP_1 (GPIO_PSC2_4) */ |
| 128 | u8 level = 0; /* wakeup on low level */ |
| 129 | mpc52xx_set_wakeup_gpio(pin, level); |
| 130 | |
| 131 | /* |
| 132 | * power down usb port |
| 133 | * this needs to be called before of-ohci suspend code |
| 134 | */ |
Domen Puncer | ee98307 | 2007-07-18 06:32:31 +1000 | [diff] [blame] | 135 | |
| 136 | /* set ports to "power switched" and "powered at the same time" |
| 137 | * USB Rh descriptor A: NPS = 0, PSM = 0 */ |
| 138 | out_be32(mbar + 0x1048, in_be32(mbar + 0x1048) & ~0x300); |
| 139 | /* USB Rh status: LPS = 1 - turn off power */ |
| 140 | out_be32(mbar + 0x1050, 0x00000001); |
Domen Puncer | 2e1ee1f | 2007-05-07 01:38:52 +1000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static void lite5200_resume_finish(void __iomem *mbar) |
| 144 | { |
Domen Puncer | ee98307 | 2007-07-18 06:32:31 +1000 | [diff] [blame] | 145 | /* USB Rh status: LPSC = 1 - turn on power */ |
| 146 | out_be32(mbar + 0x1050, 0x00010000); |
Domen Puncer | 2e1ee1f | 2007-05-07 01:38:52 +1000 | [diff] [blame] | 147 | } |
| 148 | #endif |
| 149 | |
Grant Likely | e3aba81 | 2007-02-12 13:36:55 -0700 | [diff] [blame] | 150 | static void __init lite5200_setup_arch(void) |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 151 | { |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 152 | if (ppc_md.progress) |
Grant Likely | e3aba81 | 2007-02-12 13:36:55 -0700 | [diff] [blame] | 153 | ppc_md.progress("lite5200_setup_arch()", 0); |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 154 | |
Grant Likely | c8004a2 | 2008-01-24 22:25:31 -0700 | [diff] [blame] | 155 | /* Map important registers from the internal memory map */ |
| 156 | mpc52xx_map_common_devices(); |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 157 | |
| 158 | /* Some mpc5200 & mpc5200b related configuration */ |
| 159 | mpc5200_setup_xlb_arbiter(); |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 160 | |
Grant Likely | c8004a2 | 2008-01-24 22:25:31 -0700 | [diff] [blame] | 161 | /* Fix things that firmware should have done. */ |
| 162 | lite5200_fix_clock_config(); |
| 163 | lite5200_fix_port_config(); |
Marian Balakowicz | 9dda78b | 2007-10-19 04:44:39 +1000 | [diff] [blame] | 164 | |
Domen Puncer | 2e1ee1f | 2007-05-07 01:38:52 +1000 | [diff] [blame] | 165 | #ifdef CONFIG_PM |
| 166 | mpc52xx_suspend.board_suspend_prepare = lite5200_suspend_prepare; |
| 167 | mpc52xx_suspend.board_resume_finish = lite5200_resume_finish; |
Domen Puncer | ee98307 | 2007-07-18 06:32:31 +1000 | [diff] [blame] | 168 | lite5200_pm_init(); |
Domen Puncer | 2e1ee1f | 2007-05-07 01:38:52 +1000 | [diff] [blame] | 169 | #endif |
| 170 | |
Marian Balakowicz | f584bc6 | 2007-11-10 04:11:56 +1100 | [diff] [blame] | 171 | mpc52xx_setup_pci(); |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 174 | /* |
| 175 | * Called very early, MMU is off, device-tree isn't unflattened |
| 176 | */ |
Grant Likely | e3aba81 | 2007-02-12 13:36:55 -0700 | [diff] [blame] | 177 | static int __init lite5200_probe(void) |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 178 | { |
| 179 | unsigned long node = of_get_flat_dt_root(); |
| 180 | const char *model = of_get_flat_dt_prop(node, "model", NULL); |
| 181 | |
Grant Likely | e3aba81 | 2007-02-12 13:36:55 -0700 | [diff] [blame] | 182 | if (!of_flat_dt_is_compatible(node, "fsl,lite5200") && |
| 183 | !of_flat_dt_is_compatible(node, "fsl,lite5200b")) |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 184 | return 0; |
Grant Likely | e3aba81 | 2007-02-12 13:36:55 -0700 | [diff] [blame] | 185 | pr_debug("%s board found\n", model ? model : "unknown"); |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 186 | |
| 187 | return 1; |
| 188 | } |
| 189 | |
Grant Likely | e3aba81 | 2007-02-12 13:36:55 -0700 | [diff] [blame] | 190 | define_machine(lite5200) { |
| 191 | .name = "lite5200", |
| 192 | .probe = lite5200_probe, |
| 193 | .setup_arch = lite5200_setup_arch, |
Sylvain Munaut | 5c334ee | 2007-01-02 23:29:53 +0100 | [diff] [blame] | 194 | .init = mpc52xx_declare_of_platform_devices, |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 195 | .init_IRQ = mpc52xx_init_irq, |
| 196 | .get_irq = mpc52xx_get_irq, |
Marian Balakowicz | 9dda78b | 2007-10-19 04:44:39 +1000 | [diff] [blame] | 197 | .restart = mpc52xx_restart, |
Grant Likely | 6b64253 | 2006-11-27 14:16:28 -0700 | [diff] [blame] | 198 | .calibrate_decr = generic_calibrate_decr, |
| 199 | }; |