Path: blob/master/arch/powerpc/platforms/82xx/ep8248e.c
10820 views
/*1* Embedded Planet EP8248E support2*3* Copyright 2007 Freescale Semiconductor, Inc.4* Author: Scott Wood <[email protected]>5*6* This program is free software; you can redistribute it and/or modify it7* under the terms of the GNU General Public License as published by the8* Free Software Foundation; either version 2 of the License, or (at your9* option) any later version.10*/1112#include <linux/init.h>13#include <linux/interrupt.h>14#include <linux/fsl_devices.h>15#include <linux/mdio-bitbang.h>16#include <linux/of_mdio.h>17#include <linux/slab.h>18#include <linux/of_platform.h>1920#include <asm/io.h>21#include <asm/cpm2.h>22#include <asm/udbg.h>23#include <asm/machdep.h>24#include <asm/time.h>25#include <asm/mpc8260.h>26#include <asm/prom.h>2728#include <sysdev/fsl_soc.h>29#include <sysdev/cpm2_pic.h>3031#include "pq2.h"3233static u8 __iomem *ep8248e_bcsr;34static struct device_node *ep8248e_bcsr_node;3536#define BCSR7_SCC2_ENABLE 0x103738#define BCSR8_PHY1_ENABLE 0x8039#define BCSR8_PHY1_POWER 0x4040#define BCSR8_PHY2_ENABLE 0x2041#define BCSR8_PHY2_POWER 0x1042#define BCSR8_MDIO_READ 0x0443#define BCSR8_MDIO_CLOCK 0x0244#define BCSR8_MDIO_DATA 0x014546#define BCSR9_USB_ENABLE 0x8047#define BCSR9_USB_POWER 0x4048#define BCSR9_USB_HOST 0x2049#define BCSR9_USB_FULL_SPEED_TARGET 0x105051static void __init ep8248e_pic_init(void)52{53struct device_node *np = of_find_compatible_node(NULL, NULL, "fsl,pq2-pic");54if (!np) {55printk(KERN_ERR "PIC init: can not find cpm-pic node\n");56return;57}5859cpm2_pic_init(np);60of_node_put(np);61}6263static void ep8248e_set_mdc(struct mdiobb_ctrl *ctrl, int level)64{65if (level)66setbits8(&ep8248e_bcsr[8], BCSR8_MDIO_CLOCK);67else68clrbits8(&ep8248e_bcsr[8], BCSR8_MDIO_CLOCK);6970/* Read back to flush the write. */71in_8(&ep8248e_bcsr[8]);72}7374static void ep8248e_set_mdio_dir(struct mdiobb_ctrl *ctrl, int output)75{76if (output)77clrbits8(&ep8248e_bcsr[8], BCSR8_MDIO_READ);78else79setbits8(&ep8248e_bcsr[8], BCSR8_MDIO_READ);8081/* Read back to flush the write. */82in_8(&ep8248e_bcsr[8]);83}8485static void ep8248e_set_mdio_data(struct mdiobb_ctrl *ctrl, int data)86{87if (data)88setbits8(&ep8248e_bcsr[8], BCSR8_MDIO_DATA);89else90clrbits8(&ep8248e_bcsr[8], BCSR8_MDIO_DATA);9192/* Read back to flush the write. */93in_8(&ep8248e_bcsr[8]);94}9596static int ep8248e_get_mdio_data(struct mdiobb_ctrl *ctrl)97{98return in_8(&ep8248e_bcsr[8]) & BCSR8_MDIO_DATA;99}100101static const struct mdiobb_ops ep8248e_mdio_ops = {102.set_mdc = ep8248e_set_mdc,103.set_mdio_dir = ep8248e_set_mdio_dir,104.set_mdio_data = ep8248e_set_mdio_data,105.get_mdio_data = ep8248e_get_mdio_data,106.owner = THIS_MODULE,107};108109static struct mdiobb_ctrl ep8248e_mdio_ctrl = {110.ops = &ep8248e_mdio_ops,111};112113static int __devinit ep8248e_mdio_probe(struct platform_device *ofdev)114{115struct mii_bus *bus;116struct resource res;117struct device_node *node;118int ret;119120node = of_get_parent(ofdev->dev.of_node);121of_node_put(node);122if (node != ep8248e_bcsr_node)123return -ENODEV;124125ret = of_address_to_resource(ofdev->dev.of_node, 0, &res);126if (ret)127return ret;128129bus = alloc_mdio_bitbang(&ep8248e_mdio_ctrl);130if (!bus)131return -ENOMEM;132133bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);134if (bus->irq == NULL) {135ret = -ENOMEM;136goto err_free_bus;137}138139bus->name = "ep8248e-mdio-bitbang";140bus->parent = &ofdev->dev;141snprintf(bus->id, MII_BUS_ID_SIZE, "%x", res.start);142143ret = of_mdiobus_register(bus, ofdev->dev.of_node);144if (ret)145goto err_free_irq;146147return 0;148err_free_irq:149kfree(bus->irq);150err_free_bus:151free_mdio_bitbang(bus);152return ret;153}154155static int ep8248e_mdio_remove(struct platform_device *ofdev)156{157BUG();158return 0;159}160161static const struct of_device_id ep8248e_mdio_match[] = {162{163.compatible = "fsl,ep8248e-mdio-bitbang",164},165{},166};167168static struct platform_driver ep8248e_mdio_driver = {169.driver = {170.name = "ep8248e-mdio-bitbang",171.owner = THIS_MODULE,172.of_match_table = ep8248e_mdio_match,173},174.probe = ep8248e_mdio_probe,175.remove = ep8248e_mdio_remove,176};177178struct cpm_pin {179int port, pin, flags;180};181182static __initdata struct cpm_pin ep8248e_pins[] = {183/* SMC1 */184{2, 4, CPM_PIN_INPUT | CPM_PIN_PRIMARY},185{2, 5, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},186187/* SCC1 */188{2, 14, CPM_PIN_INPUT | CPM_PIN_PRIMARY},189{2, 15, CPM_PIN_INPUT | CPM_PIN_PRIMARY},190{3, 29, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},191{3, 30, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},192{3, 31, CPM_PIN_INPUT | CPM_PIN_PRIMARY},193194/* FCC1 */195{0, 14, CPM_PIN_INPUT | CPM_PIN_PRIMARY},196{0, 15, CPM_PIN_INPUT | CPM_PIN_PRIMARY},197{0, 16, CPM_PIN_INPUT | CPM_PIN_PRIMARY},198{0, 17, CPM_PIN_INPUT | CPM_PIN_PRIMARY},199{0, 18, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},200{0, 19, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},201{0, 20, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},202{0, 21, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},203{0, 26, CPM_PIN_INPUT | CPM_PIN_SECONDARY},204{0, 27, CPM_PIN_INPUT | CPM_PIN_SECONDARY},205{0, 28, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},206{0, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},207{0, 30, CPM_PIN_INPUT | CPM_PIN_SECONDARY},208{0, 31, CPM_PIN_INPUT | CPM_PIN_SECONDARY},209{2, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY},210{2, 22, CPM_PIN_INPUT | CPM_PIN_PRIMARY},211212/* FCC2 */213{1, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY},214{1, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY},215{1, 20, CPM_PIN_INPUT | CPM_PIN_PRIMARY},216{1, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY},217{1, 22, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},218{1, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},219{1, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},220{1, 25, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},221{1, 26, CPM_PIN_INPUT | CPM_PIN_PRIMARY},222{1, 27, CPM_PIN_INPUT | CPM_PIN_PRIMARY},223{1, 28, CPM_PIN_INPUT | CPM_PIN_PRIMARY},224{1, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},225{1, 30, CPM_PIN_INPUT | CPM_PIN_PRIMARY},226{1, 31, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},227{2, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY},228{2, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY},229230/* I2C */231{4, 14, CPM_PIN_INPUT | CPM_PIN_SECONDARY},232{4, 15, CPM_PIN_INPUT | CPM_PIN_SECONDARY},233234/* USB */235{2, 10, CPM_PIN_INPUT | CPM_PIN_PRIMARY},236{2, 11, CPM_PIN_INPUT | CPM_PIN_PRIMARY},237{2, 20, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},238{2, 24, CPM_PIN_INPUT | CPM_PIN_PRIMARY},239{3, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},240{3, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},241{3, 25, CPM_PIN_INPUT | CPM_PIN_PRIMARY},242};243244static void __init init_ioports(void)245{246int i;247248for (i = 0; i < ARRAY_SIZE(ep8248e_pins); i++) {249const struct cpm_pin *pin = &ep8248e_pins[i];250cpm2_set_pin(pin->port, pin->pin, pin->flags);251}252253cpm2_smc_clk_setup(CPM_CLK_SMC1, CPM_BRG7);254cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_RX);255cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_TX);256cpm2_clk_setup(CPM_CLK_SCC3, CPM_CLK8, CPM_CLK_TX); /* USB */257cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK11, CPM_CLK_RX);258cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK10, CPM_CLK_TX);259cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK13, CPM_CLK_RX);260cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK14, CPM_CLK_TX);261}262263static void __init ep8248e_setup_arch(void)264{265if (ppc_md.progress)266ppc_md.progress("ep8248e_setup_arch()", 0);267268cpm2_reset();269270/* When this is set, snooping CPM DMA from RAM causes271* machine checks. See erratum SIU18.272*/273clrbits32(&cpm2_immr->im_siu_conf.siu_82xx.sc_bcr, MPC82XX_BCR_PLDP);274275ep8248e_bcsr_node =276of_find_compatible_node(NULL, NULL, "fsl,ep8248e-bcsr");277if (!ep8248e_bcsr_node) {278printk(KERN_ERR "No bcsr in device tree\n");279return;280}281282ep8248e_bcsr = of_iomap(ep8248e_bcsr_node, 0);283if (!ep8248e_bcsr) {284printk(KERN_ERR "Cannot map BCSR registers\n");285of_node_put(ep8248e_bcsr_node);286ep8248e_bcsr_node = NULL;287return;288}289290setbits8(&ep8248e_bcsr[7], BCSR7_SCC2_ENABLE);291setbits8(&ep8248e_bcsr[8], BCSR8_PHY1_ENABLE | BCSR8_PHY1_POWER |292BCSR8_PHY2_ENABLE | BCSR8_PHY2_POWER);293294init_ioports();295296if (ppc_md.progress)297ppc_md.progress("ep8248e_setup_arch(), finish", 0);298}299300static __initdata struct of_device_id of_bus_ids[] = {301{ .compatible = "simple-bus", },302{ .compatible = "fsl,ep8248e-bcsr", },303{},304};305306static int __init declare_of_platform_devices(void)307{308of_platform_bus_probe(NULL, of_bus_ids, NULL);309platform_driver_register(&ep8248e_mdio_driver);310311return 0;312}313machine_device_initcall(ep8248e, declare_of_platform_devices);314315/*316* Called very early, device-tree isn't unflattened317*/318static int __init ep8248e_probe(void)319{320unsigned long root = of_get_flat_dt_root();321return of_flat_dt_is_compatible(root, "fsl,ep8248e");322}323324define_machine(ep8248e)325{326.name = "Embedded Planet EP8248E",327.probe = ep8248e_probe,328.setup_arch = ep8248e_setup_arch,329.init_IRQ = ep8248e_pic_init,330.get_irq = cpm2_get_irq,331.calibrate_decr = generic_calibrate_decr,332.restart = pq2_restart,333.progress = udbg_progress,334};335336337