Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved. |
| 3 | * |
| 4 | * Author: Li Yang <LeoLi@freescale.com> |
| 5 | * Yin Olivia <Hong-hua.Yin@freescale.com> |
| 6 | * |
| 7 | * Description: |
Kumar Gala | 322d05a | 2007-02-17 10:13:56 -0600 | [diff] [blame] | 8 | * MPC8360E MDS board specific routines. |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 9 | * |
| 10 | * Changelog: |
| 11 | * Jun 21, 2006 Initial version |
| 12 | * |
Kumar Gala | 322d05a | 2007-02-17 10:13:56 -0600 | [diff] [blame] | 13 | * This program is free software; you can redistribute it and/or modify it |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 14 | * under the terms of the GNU General Public License as published by the |
| 15 | * Free Software Foundation; either version 2 of the License, or (at your |
| 16 | * option) any later version. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/stddef.h> |
| 20 | #include <linux/kernel.h> |
Anton Vorontsov | 78c7705 | 2008-12-03 22:27:52 +0300 | [diff] [blame] | 21 | #include <linux/compiler.h> |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 22 | #include <linux/init.h> |
| 23 | #include <linux/errno.h> |
| 24 | #include <linux/reboot.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/kdev_t.h> |
| 27 | #include <linux/major.h> |
| 28 | #include <linux/console.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/seq_file.h> |
| 31 | #include <linux/root_dev.h> |
| 32 | #include <linux/initrd.h> |
Jon Loeliger | 882407b | 2007-11-06 12:11:13 -0600 | [diff] [blame] | 33 | #include <linux/of_platform.h> |
| 34 | #include <linux/of_device.h> |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 35 | |
| 36 | #include <asm/system.h> |
Arun Sharma | 6006349 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 37 | #include <linux/atomic.h> |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 38 | #include <asm/time.h> |
| 39 | #include <asm/io.h> |
| 40 | #include <asm/machdep.h> |
| 41 | #include <asm/ipic.h> |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 42 | #include <asm/irq.h> |
| 43 | #include <asm/prom.h> |
| 44 | #include <asm/udbg.h> |
| 45 | #include <sysdev/fsl_soc.h> |
John Rigby | 76fe1ff | 2008-06-26 11:07:57 -0600 | [diff] [blame] | 46 | #include <sysdev/fsl_pci.h> |
Anton Vorontsov | c9c5e52 | 2008-12-18 19:37:31 +0300 | [diff] [blame] | 47 | #include <sysdev/simple_gpio.h> |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 48 | #include <asm/qe.h> |
| 49 | #include <asm/qe_ic.h> |
| 50 | |
| 51 | #include "mpc83xx.h" |
| 52 | |
| 53 | #undef DEBUG |
| 54 | #ifdef DEBUG |
| 55 | #define DBG(fmt...) udbg_printf(fmt) |
| 56 | #else |
| 57 | #define DBG(fmt...) |
| 58 | #endif |
| 59 | |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 60 | /* ************************************************************************ |
| 61 | * |
| 62 | * Setup the architecture |
| 63 | * |
| 64 | */ |
Kumar Gala | 322d05a | 2007-02-17 10:13:56 -0600 | [diff] [blame] | 65 | static void __init mpc836x_mds_setup_arch(void) |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 66 | { |
| 67 | struct device_node *np; |
Anton Vorontsov | 78c7705 | 2008-12-03 22:27:52 +0300 | [diff] [blame] | 68 | u8 __iomem *bcsr_regs = NULL; |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 69 | |
| 70 | if (ppc_md.progress) |
Kumar Gala | 322d05a | 2007-02-17 10:13:56 -0600 | [diff] [blame] | 71 | ppc_md.progress("mpc836x_mds_setup_arch()", 0); |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 72 | |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 73 | /* Map BCSR area */ |
| 74 | np = of_find_node_by_name(NULL, "bcsr"); |
Anton Vorontsov | 78c7705 | 2008-12-03 22:27:52 +0300 | [diff] [blame] | 75 | if (np) { |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 76 | struct resource res; |
| 77 | |
| 78 | of_address_to_resource(np, 0, &res); |
Joe Perches | 28f65c1 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 79 | bcsr_regs = ioremap(res.start, resource_size(&res)); |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 80 | of_node_put(np); |
| 81 | } |
| 82 | |
Dmitry Eremin-Solenikov | bede480 | 2011-11-17 18:48:48 +0400 | [diff] [blame] | 83 | mpc83xx_setup_pci(); |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 84 | |
| 85 | #ifdef CONFIG_QUICC_ENGINE |
| 86 | qe_reset(); |
| 87 | |
Li Yang | 06cd939 | 2007-01-17 14:42:22 +0800 | [diff] [blame] | 88 | if ((np = of_find_node_by_name(NULL, "par_io")) != NULL) { |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 89 | par_io_init(np); |
| 90 | of_node_put(np); |
| 91 | |
| 92 | for (np = NULL; (np = of_find_node_by_name(np, "ucc")) != NULL;) |
| 93 | par_io_of_config(np); |
Anton Vorontsov | c9c5e52 | 2008-12-18 19:37:31 +0300 | [diff] [blame] | 94 | #ifdef CONFIG_QE_USB |
| 95 | /* Must fixup Par IO before QE GPIO chips are registered. */ |
| 96 | par_io_config_pin(1, 2, 1, 0, 3, 0); /* USBOE */ |
| 97 | par_io_config_pin(1, 3, 1, 0, 3, 0); /* USBTP */ |
| 98 | par_io_config_pin(1, 8, 1, 0, 1, 0); /* USBTN */ |
| 99 | par_io_config_pin(1, 10, 2, 0, 3, 0); /* USBRXD */ |
| 100 | par_io_config_pin(1, 9, 2, 1, 3, 0); /* USBRP */ |
| 101 | par_io_config_pin(1, 11, 2, 1, 3, 0); /* USBRN */ |
| 102 | par_io_config_pin(2, 20, 2, 0, 1, 0); /* CLK21 */ |
| 103 | #endif /* CONFIG_QE_USB */ |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | if ((np = of_find_compatible_node(NULL, "network", "ucc_geth")) |
| 107 | != NULL){ |
Kim Phillips | 29a50a8 | 2007-11-05 12:15:51 -0600 | [diff] [blame] | 108 | uint svid; |
| 109 | |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 110 | /* Reset the Ethernet PHY */ |
Kim Phillips | 29a50a8 | 2007-11-05 12:15:51 -0600 | [diff] [blame] | 111 | #define BCSR9_GETHRST 0x20 |
| 112 | clrbits8(&bcsr_regs[9], BCSR9_GETHRST); |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 113 | udelay(1000); |
Kim Phillips | 29a50a8 | 2007-11-05 12:15:51 -0600 | [diff] [blame] | 114 | setbits8(&bcsr_regs[9], BCSR9_GETHRST); |
| 115 | |
| 116 | /* handle mpc8360ea rev.2.1 erratum 2: RGMII Timing */ |
| 117 | svid = mfspr(SPRN_SVR); |
| 118 | if (svid == 0x80480021) { |
| 119 | void __iomem *immap; |
| 120 | |
| 121 | immap = ioremap(get_immrbase() + 0x14a8, 8); |
| 122 | |
| 123 | /* |
| 124 | * IMMR + 0x14A8[4:5] = 11 (clk delay for UCC 2) |
| 125 | * IMMR + 0x14A8[18:19] = 11 (clk delay for UCC 1) |
| 126 | */ |
| 127 | setbits32(immap, 0x0c003000); |
| 128 | |
| 129 | /* |
| 130 | * IMMR + 0x14AC[20:27] = 10101010 |
| 131 | * (data delay for both UCC's) |
| 132 | */ |
| 133 | clrsetbits_be32(immap + 4, 0xff0, 0xaa0); |
| 134 | |
| 135 | iounmap(immap); |
| 136 | } |
| 137 | |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 138 | iounmap(bcsr_regs); |
| 139 | of_node_put(np); |
| 140 | } |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 141 | #endif /* CONFIG_QUICC_ENGINE */ |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 142 | } |
| 143 | |
Dmitry Eremin-Solenikov | 7669d58 | 2011-11-17 18:48:47 +0400 | [diff] [blame] | 144 | machine_device_initcall(mpc836x_mds, mpc83xx_declare_of_platform_devices); |
Li Yang | f5a37b0 | 2006-10-11 19:04:22 +0800 | [diff] [blame] | 145 | |
Anton Vorontsov | c9c5e52 | 2008-12-18 19:37:31 +0300 | [diff] [blame] | 146 | #ifdef CONFIG_QE_USB |
| 147 | static int __init mpc836x_usb_cfg(void) |
| 148 | { |
| 149 | u8 __iomem *bcsr; |
| 150 | struct device_node *np; |
| 151 | const char *mode; |
| 152 | int ret = 0; |
| 153 | |
| 154 | np = of_find_compatible_node(NULL, NULL, "fsl,mpc8360mds-bcsr"); |
| 155 | if (!np) |
| 156 | return -ENODEV; |
| 157 | |
| 158 | bcsr = of_iomap(np, 0); |
| 159 | of_node_put(np); |
| 160 | if (!bcsr) |
| 161 | return -ENOMEM; |
| 162 | |
| 163 | np = of_find_compatible_node(NULL, NULL, "fsl,mpc8323-qe-usb"); |
| 164 | if (!np) { |
| 165 | ret = -ENODEV; |
| 166 | goto err; |
| 167 | } |
| 168 | |
| 169 | #define BCSR8_TSEC1M_MASK (0x3 << 6) |
| 170 | #define BCSR8_TSEC1M_RGMII (0x0 << 6) |
| 171 | #define BCSR8_TSEC2M_MASK (0x3 << 4) |
| 172 | #define BCSR8_TSEC2M_RGMII (0x0 << 4) |
| 173 | /* |
| 174 | * Default is GMII (2), but we should set it to RGMII (0) if we use |
| 175 | * USB (Eth PHY is in RGMII mode anyway). |
| 176 | */ |
| 177 | clrsetbits_8(&bcsr[8], BCSR8_TSEC1M_MASK | BCSR8_TSEC2M_MASK, |
| 178 | BCSR8_TSEC1M_RGMII | BCSR8_TSEC2M_RGMII); |
| 179 | |
| 180 | #define BCSR13_USBMASK 0x0f |
| 181 | #define BCSR13_nUSBEN 0x08 /* 1 - Disable, 0 - Enable */ |
| 182 | #define BCSR13_USBSPEED 0x04 /* 1 - Full, 0 - Low */ |
| 183 | #define BCSR13_USBMODE 0x02 /* 1 - Host, 0 - Function */ |
| 184 | #define BCSR13_nUSBVCC 0x01 /* 1 - gets VBUS, 0 - supplies VBUS */ |
| 185 | |
| 186 | clrsetbits_8(&bcsr[13], BCSR13_USBMASK, BCSR13_USBSPEED); |
| 187 | |
| 188 | mode = of_get_property(np, "mode", NULL); |
| 189 | if (mode && !strcmp(mode, "peripheral")) { |
| 190 | setbits8(&bcsr[13], BCSR13_nUSBVCC); |
| 191 | qe_usb_clock_set(QE_CLK21, 48000000); |
| 192 | } else { |
| 193 | setbits8(&bcsr[13], BCSR13_USBMODE); |
| 194 | /* |
| 195 | * The BCSR GPIOs are used to control power and |
| 196 | * speed of the USB transceiver. This is needed for |
| 197 | * the USB Host only. |
| 198 | */ |
| 199 | simple_gpiochip_init("fsl,mpc8360mds-bcsr-gpio"); |
| 200 | } |
| 201 | |
| 202 | of_node_put(np); |
| 203 | err: |
| 204 | iounmap(bcsr); |
| 205 | return ret; |
| 206 | } |
| 207 | machine_arch_initcall(mpc836x_mds, mpc836x_usb_cfg); |
| 208 | #endif /* CONFIG_QE_USB */ |
| 209 | |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 210 | /* |
| 211 | * Called very early, MMU is off, device-tree isn't unflattened |
| 212 | */ |
Kumar Gala | 322d05a | 2007-02-17 10:13:56 -0600 | [diff] [blame] | 213 | static int __init mpc836x_mds_probe(void) |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 214 | { |
Kumar Gala | 336c3c2 | 2007-02-17 09:10:44 -0600 | [diff] [blame] | 215 | unsigned long root = of_get_flat_dt_root(); |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 216 | |
Kumar Gala | 336c3c2 | 2007-02-17 09:10:44 -0600 | [diff] [blame] | 217 | return of_flat_dt_is_compatible(root, "MPC836xMDS"); |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 218 | } |
| 219 | |
Kumar Gala | 322d05a | 2007-02-17 10:13:56 -0600 | [diff] [blame] | 220 | define_machine(mpc836x_mds) { |
| 221 | .name = "MPC836x MDS", |
| 222 | .probe = mpc836x_mds_probe, |
| 223 | .setup_arch = mpc836x_mds_setup_arch, |
Dmitry Eremin-Solenikov | d4fb5eb | 2011-07-22 23:55:42 +0400 | [diff] [blame] | 224 | .init_IRQ = mpc83xx_ipic_and_qe_init_IRQ, |
Kumar Gala | 322d05a | 2007-02-17 10:13:56 -0600 | [diff] [blame] | 225 | .get_irq = ipic_get_irq, |
| 226 | .restart = mpc83xx_restart, |
| 227 | .time_init = mpc83xx_time_init, |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 228 | .calibrate_decr = generic_calibrate_decr, |
Kumar Gala | 322d05a | 2007-02-17 10:13:56 -0600 | [diff] [blame] | 229 | .progress = udbg_progress, |
Li Yang | bc141de | 2006-10-03 23:17:51 -0500 | [diff] [blame] | 230 | }; |