Path: blob/master/arch/powerpc/platforms/85xx/mpc85xx_mds.c
26481 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Copyright (C) 2006-2010, 2012-2013 Freescale Semiconductor, Inc.3* All rights reserved.4*5* Author: Andy Fleming <[email protected]>6*7* Based on 83xx/mpc8360e_pb.c by:8* Li Yang <[email protected]>9* Yin Olivia <[email protected]>10*11* Description:12* MPC85xx MDS board specific routines.13*/1415#include <linux/stddef.h>16#include <linux/kernel.h>17#include <linux/init.h>18#include <linux/errno.h>19#include <linux/reboot.h>20#include <linux/pci.h>21#include <linux/kdev_t.h>22#include <linux/major.h>23#include <linux/console.h>24#include <linux/delay.h>25#include <linux/seq_file.h>26#include <linux/initrd.h>27#include <linux/fsl_devices.h>28#include <linux/of.h>29#include <linux/of_address.h>30#include <linux/phy.h>31#include <linux/memblock.h>32#include <linux/fsl/guts.h>3334#include <linux/atomic.h>35#include <asm/time.h>36#include <asm/io.h>37#include <asm/machdep.h>38#include <asm/pci-bridge.h>39#include <asm/irq.h>40#include <mm/mmu_decl.h>41#include <asm/udbg.h>42#include <sysdev/fsl_soc.h>43#include <sysdev/fsl_pci.h>44#include <soc/fsl/qe/qe.h>45#include <asm/mpic.h>46#include <asm/swiotlb.h>47#include "smp.h"4849#include "mpc85xx.h"5051#if IS_BUILTIN(CONFIG_PHYLIB)5253#define MV88E1111_SCR 0x1054#define MV88E1111_SCR_125CLK 0x001055static int mpc8568_fixup_125_clock(struct phy_device *phydev)56{57int scr;58int err;5960/* Workaround for the 125 CLK Toggle */61scr = phy_read(phydev, MV88E1111_SCR);6263if (scr < 0)64return scr;6566err = phy_write(phydev, MV88E1111_SCR, scr & ~(MV88E1111_SCR_125CLK));6768if (err)69return err;7071err = phy_write(phydev, MII_BMCR, BMCR_RESET);7273if (err)74return err;7576scr = phy_read(phydev, MV88E1111_SCR);7778if (scr < 0)79return scr;8081err = phy_write(phydev, MV88E1111_SCR, scr | 0x0008);8283return err;84}8586static int mpc8568_mds_phy_fixups(struct phy_device *phydev)87{88int temp;89int err;9091/* Errata */92err = phy_write(phydev,29, 0x0006);9394if (err)95return err;9697temp = phy_read(phydev, 30);9899if (temp < 0)100return temp;101102temp = (temp & (~0x8000)) | 0x4000;103err = phy_write(phydev,30, temp);104105if (err)106return err;107108err = phy_write(phydev,29, 0x000a);109110if (err)111return err;112113temp = phy_read(phydev, 30);114115if (temp < 0)116return temp;117118temp = phy_read(phydev, 30);119120if (temp < 0)121return temp;122123temp &= ~0x0020;124125err = phy_write(phydev,30,temp);126127if (err)128return err;129130/* Disable automatic MDI/MDIX selection */131temp = phy_read(phydev, 16);132133if (temp < 0)134return temp;135136temp &= ~0x0060;137err = phy_write(phydev,16,temp);138139return err;140}141142#endif143144/* ************************************************************************145*146* Setup the architecture147*148*/149#ifdef CONFIG_QUICC_ENGINE150static void __init mpc85xx_mds_reset_ucc_phys(void)151{152struct device_node *np;153static u8 __iomem *bcsr_regs;154155/* Map BCSR area */156np = of_find_node_by_name(NULL, "bcsr");157if (!np)158return;159160bcsr_regs = of_iomap(np, 0);161of_node_put(np);162if (!bcsr_regs)163return;164165if (machine_is(mpc8568_mds)) {166#define BCSR_UCC1_GETH_EN (0x1 << 7)167#define BCSR_UCC2_GETH_EN (0x1 << 7)168#define BCSR_UCC1_MODE_MSK (0x3 << 4)169#define BCSR_UCC2_MODE_MSK (0x3 << 0)170171/* Turn off UCC1 & UCC2 */172clrbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);173clrbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);174175/* Mode is RGMII, all bits clear */176clrbits8(&bcsr_regs[11], BCSR_UCC1_MODE_MSK |177BCSR_UCC2_MODE_MSK);178179/* Turn UCC1 & UCC2 on */180setbits8(&bcsr_regs[8], BCSR_UCC1_GETH_EN);181setbits8(&bcsr_regs[9], BCSR_UCC2_GETH_EN);182} else if (machine_is(mpc8569_mds)) {183#define BCSR7_UCC12_GETHnRST (0x1 << 2)184#define BCSR8_UEM_MARVELL_RST (0x1 << 1)185#define BCSR_UCC_RGMII (0x1 << 6)186#define BCSR_UCC_RTBI (0x1 << 5)187/*188* U-Boot mangles interrupt polarity for Marvell PHYs,189* so reset built-in and UEM Marvell PHYs, this puts190* the PHYs into their normal state.191*/192clrbits8(&bcsr_regs[7], BCSR7_UCC12_GETHnRST);193setbits8(&bcsr_regs[8], BCSR8_UEM_MARVELL_RST);194195setbits8(&bcsr_regs[7], BCSR7_UCC12_GETHnRST);196clrbits8(&bcsr_regs[8], BCSR8_UEM_MARVELL_RST);197198for_each_compatible_node(np, "network", "ucc_geth") {199const unsigned int *prop;200int ucc_num;201202prop = of_get_property(np, "cell-index", NULL);203if (prop == NULL)204continue;205206ucc_num = *prop - 1;207208prop = of_get_property(np, "phy-connection-type", NULL);209if (prop == NULL)210continue;211212if (strcmp("rtbi", (const char *)prop) == 0)213clrsetbits_8(&bcsr_regs[7 + ucc_num],214BCSR_UCC_RGMII, BCSR_UCC_RTBI);215}216} else if (machine_is(p1021_mds)) {217#define BCSR11_ENET_MICRST (0x1 << 5)218/* Reset Micrel PHY */219clrbits8(&bcsr_regs[11], BCSR11_ENET_MICRST);220setbits8(&bcsr_regs[11], BCSR11_ENET_MICRST);221}222223iounmap(bcsr_regs);224}225226static void __init mpc85xx_mds_qe_init(void)227{228struct device_node *np;229230mpc85xx_qe_par_io_init();231mpc85xx_mds_reset_ucc_phys();232233if (machine_is(p1021_mds)) {234235struct ccsr_guts __iomem *guts;236237np = of_find_node_by_name(NULL, "global-utilities");238if (np) {239guts = of_iomap(np, 0);240if (!guts)241pr_err("mpc85xx-rdb: could not map global utilities register\n");242else{243/* P1021 has pins muxed for QE and other functions. To244* enable QE UEC mode, we need to set bit QE0 for UCC1245* in Eth mode, QE0 and QE3 for UCC5 in Eth mode, QE9246* and QE12 for QE MII management signals in PMUXCR247* register.248*/249setbits32(&guts->pmuxcr, MPC85xx_PMUXCR_QE(0) |250MPC85xx_PMUXCR_QE(3) |251MPC85xx_PMUXCR_QE(9) |252MPC85xx_PMUXCR_QE(12));253iounmap(guts);254}255of_node_put(np);256}257258}259}260261#else262static void __init mpc85xx_mds_qe_init(void) { }263#endif /* CONFIG_QUICC_ENGINE */264265static void __init mpc85xx_mds_setup_arch(void)266{267if (ppc_md.progress)268ppc_md.progress("mpc85xx_mds_setup_arch()", 0);269270mpc85xx_smp_init();271272mpc85xx_mds_qe_init();273274fsl_pci_assign_primary();275276swiotlb_detect_4g();277}278279#if IS_BUILTIN(CONFIG_PHYLIB)280281static int __init board_fixups(void)282{283char phy_id[20];284char *compstrs[2] = {"fsl,gianfar-mdio", "fsl,ucc-mdio"};285struct device_node *mdio;286struct resource res;287int i;288289for (i = 0; i < ARRAY_SIZE(compstrs); i++) {290mdio = of_find_compatible_node(NULL, NULL, compstrs[i]);291292of_address_to_resource(mdio, 0, &res);293snprintf(phy_id, sizeof(phy_id), "%llx:%02x",294(unsigned long long)res.start, 1);295296phy_register_fixup_for_id(phy_id, mpc8568_fixup_125_clock);297phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);298299/* Register a workaround for errata */300snprintf(phy_id, sizeof(phy_id), "%llx:%02x",301(unsigned long long)res.start, 7);302phy_register_fixup_for_id(phy_id, mpc8568_mds_phy_fixups);303304of_node_put(mdio);305}306307return 0;308}309310machine_arch_initcall(mpc8568_mds, board_fixups);311machine_arch_initcall(mpc8569_mds, board_fixups);312313#endif314315static int __init mpc85xx_publish_devices(void)316{317return mpc85xx_common_publish_devices();318}319320machine_arch_initcall(mpc8568_mds, mpc85xx_publish_devices);321machine_arch_initcall(mpc8569_mds, mpc85xx_publish_devices);322machine_arch_initcall(p1021_mds, mpc85xx_common_publish_devices);323324static void __init mpc85xx_mds_pic_init(void)325{326struct mpic *mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN |327MPIC_SINGLE_DEST_CPU,3280, 256, " OpenPIC ");329BUG_ON(mpic == NULL);330331mpic_init(mpic);332}333334define_machine(mpc8568_mds) {335.name = "MPC8568 MDS",336.compatible = "MPC85xxMDS",337.setup_arch = mpc85xx_mds_setup_arch,338.init_IRQ = mpc85xx_mds_pic_init,339.get_irq = mpic_get_irq,340.progress = udbg_progress,341#ifdef CONFIG_PCI342.pcibios_fixup_bus = fsl_pcibios_fixup_bus,343.pcibios_fixup_phb = fsl_pcibios_fixup_phb,344#endif345};346347define_machine(mpc8569_mds) {348.name = "MPC8569 MDS",349.compatible = "fsl,MPC8569EMDS",350.setup_arch = mpc85xx_mds_setup_arch,351.init_IRQ = mpc85xx_mds_pic_init,352.get_irq = mpic_get_irq,353.progress = udbg_progress,354#ifdef CONFIG_PCI355.pcibios_fixup_bus = fsl_pcibios_fixup_bus,356.pcibios_fixup_phb = fsl_pcibios_fixup_phb,357#endif358};359360define_machine(p1021_mds) {361.name = "P1021 MDS",362.compatible = "fsl,P1021MDS",363.setup_arch = mpc85xx_mds_setup_arch,364.init_IRQ = mpc85xx_mds_pic_init,365.get_irq = mpic_get_irq,366.progress = udbg_progress,367#ifdef CONFIG_PCI368.pcibios_fixup_bus = fsl_pcibios_fixup_bus,369.pcibios_fixup_phb = fsl_pcibios_fixup_phb,370#endif371};372373374