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