From 59b6defa2b2db1b51f772e8ef6af2617463c8f80 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 11 Jan 2013 03:19:01 +0000 Subject: mxs: mmc: Drop unused members from struct mxsmmc_priv The clock data are not used by the driver, drop them. Signed-off-by: Marek Vasut Cc: Andy Fleming Cc: Fabio Estevam Cc: Stefano Babic --- drivers/mmc/mxsmmc.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'drivers') diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c index 024df592f2..aa3d1b005e 100644 --- a/drivers/mmc/mxsmmc.c +++ b/drivers/mmc/mxsmmc.c @@ -47,8 +47,6 @@ struct mxsmmc_priv { int id; struct mxs_ssp_regs *regs; - uint32_t clkseq_bypass; - uint32_t *clkctrl_ssp; uint32_t buswidth; int (*mmc_is_wp)(int); struct mxs_dma_desc *desc; @@ -355,8 +353,6 @@ static int mxsmmc_init(struct mmc *mmc) int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int)) { - struct mxs_clkctrl_regs *clkctrl_regs = - (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE; struct mmc *mmc = NULL; struct mxsmmc_priv *priv = NULL; int ret; @@ -387,23 +383,15 @@ int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int)) switch (id) { case 0: priv->regs = (struct mxs_ssp_regs *)MXS_SSP0_BASE; - priv->clkseq_bypass = CLKCTRL_CLKSEQ_BYPASS_SSP0; - priv->clkctrl_ssp = &clkctrl_regs->hw_clkctrl_ssp0; break; case 1: priv->regs = (struct mxs_ssp_regs *)MXS_SSP1_BASE; - priv->clkseq_bypass = CLKCTRL_CLKSEQ_BYPASS_SSP1; - priv->clkctrl_ssp = &clkctrl_regs->hw_clkctrl_ssp1; break; case 2: priv->regs = (struct mxs_ssp_regs *)MXS_SSP2_BASE; - priv->clkseq_bypass = CLKCTRL_CLKSEQ_BYPASS_SSP2; - priv->clkctrl_ssp = &clkctrl_regs->hw_clkctrl_ssp2; break; case 3: priv->regs = (struct mxs_ssp_regs *)MXS_SSP3_BASE; - priv->clkseq_bypass = CLKCTRL_CLKSEQ_BYPASS_SSP3; - priv->clkctrl_ssp = &clkctrl_regs->hw_clkctrl_ssp3; break; } -- cgit v1.2.1 From 14e26bcfa700b507a805eb30c72e3b6a1ba19d7f Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 11 Jan 2013 03:19:02 +0000 Subject: mxs: ssp: Pull out the SSP bus to regs conversion Create function which converts SSP bus number to SSP register pointer. This functionality is reimplemented multiple times in the code, thus make one common implementation. Moreover, make it a switch(), since the SSP ports are not mapped in such nice linear fashion on MX23, therefore having it a switch will simplify things there. Signed-off-by: Marek Vasut Cc: Andy Fleming Cc: Fabio Estevam Cc: Stefano Babic --- drivers/mmc/mxsmmc.c | 15 +-------------- drivers/spi/mxs_spi.c | 5 +---- 2 files changed, 2 insertions(+), 18 deletions(-) (limited to 'drivers') diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c index aa3d1b005e..2fd9ccc18e 100644 --- a/drivers/mmc/mxsmmc.c +++ b/drivers/mmc/mxsmmc.c @@ -380,20 +380,7 @@ int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int)) priv->mmc_is_wp = wp; priv->id = id; - switch (id) { - case 0: - priv->regs = (struct mxs_ssp_regs *)MXS_SSP0_BASE; - break; - case 1: - priv->regs = (struct mxs_ssp_regs *)MXS_SSP1_BASE; - break; - case 2: - priv->regs = (struct mxs_ssp_regs *)MXS_SSP2_BASE; - break; - case 3: - priv->regs = (struct mxs_ssp_regs *)MXS_SSP3_BASE; - break; - } + priv->regs = mxs_ssp_regs_by_bus(id); sprintf(mmc->name, "MXS MMC"); mmc->send_cmd = mxsmmc_send_cmd; diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c index 42e4c9952e..31cd77d31c 100644 --- a/drivers/spi/mxs_spi.c +++ b/drivers/spi/mxs_spi.c @@ -80,7 +80,6 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, unsigned int max_hz, unsigned int mode) { struct mxs_spi_slave *mxs_slave; - uint32_t addr; struct mxs_ssp_regs *ssp_regs; int reg; @@ -96,13 +95,11 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, if (mxs_dma_init_channel(bus)) goto err_init; - addr = MXS_SSP0_BASE + (bus * MXS_SPI_PORT_OFFSET); - mxs_slave->slave.bus = bus; mxs_slave->slave.cs = cs; mxs_slave->max_khz = max_hz / 1000; mxs_slave->mode = mode; - mxs_slave->regs = (struct mxs_ssp_regs *)addr; + mxs_slave->regs = mxs_ssp_regs_by_bus(bus); ssp_regs = mxs_slave->regs; reg = readl(&ssp_regs->hw_ssp_ctrl0); -- cgit v1.2.1 From bf48fcb61b8af9a6fb79d65a3868636e8289c696 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Fri, 11 Jan 2013 03:19:03 +0000 Subject: mxs: clock: Use 'mxs' prefix for methods Signed-off-by: Otavio Salvador Cc: Fabio Estevam Cc: Marek Vasut Cc: Stefano Babic --- drivers/mmc/mxsmmc.c | 4 ++-- drivers/spi/mxs_spi.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c index 2fd9ccc18e..76878d08c3 100644 --- a/drivers/mmc/mxsmmc.c +++ b/drivers/mmc/mxsmmc.c @@ -304,7 +304,7 @@ static void mxsmmc_set_ios(struct mmc *mmc) /* Set the clock speed */ if (mmc->clock) - mx28_set_ssp_busclock(priv->id, mmc->clock / 1000); + mxs_set_ssp_busclock(priv->id, mmc->clock / 1000); switch (mmc->bus_width) { case 1: @@ -341,7 +341,7 @@ static int mxsmmc_init(struct mmc *mmc) SSP_CTRL1_SSP_MODE_SD_MMC | SSP_CTRL1_WORD_LENGTH_EIGHT_BITS); /* Set initial bit clock 400 KHz */ - mx28_set_ssp_busclock(priv->id, 400); + mxs_set_ssp_busclock(priv->id, 400); /* Send initial 74 clock cycles (185 us @ 400 KHz)*/ writel(SSP_CMD0_CONT_CLKING_EN, &ssp_regs->hw_ssp_cmd0_set); diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c index 31cd77d31c..bb865b7f4c 100644 --- a/drivers/spi/mxs_spi.c +++ b/drivers/spi/mxs_spi.c @@ -137,7 +137,7 @@ int spi_claim_bus(struct spi_slave *slave) writel(0, &ssp_regs->hw_ssp_cmd0); - mx28_set_ssp_busclock(slave->bus, mxs_slave->max_khz); + mxs_set_ssp_busclock(slave->bus, mxs_slave->max_khz); return 0; } -- cgit v1.2.1 From 1a3c5ffe4f060455a8121093dc82e005b632c9b4 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 11 Jan 2013 03:19:14 +0000 Subject: mmc: Limit the number of used SSP ports on MX23 The MX23 can only use two SSP ports. Signed-off-by: Marek Vasut Cc: Andy Fleming Cc: Fabio Estevam Cc: Otavio Salvador Cc: Stefano Babic --- drivers/mmc/mxsmmc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c index 76878d08c3..0c4cd54b79 100644 --- a/drivers/mmc/mxsmmc.c +++ b/drivers/mmc/mxsmmc.c @@ -356,6 +356,16 @@ int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int)) struct mmc *mmc = NULL; struct mxsmmc_priv *priv = NULL; int ret; +#if defined(CONFIG_MX23) + const unsigned int mxsmmc_max_id = 2; + const unsigned int mxsmmc_clk_id = 0; +#elif defined(CONFIG_MX28) + const unsigned int mxsmmc_max_id = 4; + const unsigned int mxsmmc_clk_id = id; +#endif + + if (id >= mxsmmc_max_id) + return -ENODEV; mmc = malloc(sizeof(struct mmc)); if (!mmc) @@ -401,7 +411,7 @@ int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int)) * CLOCK_RATE could be any integer from 0 to 255. */ mmc->f_min = 400000; - mmc->f_max = mxc_get_clock(MXC_SSP0_CLK + id) * 1000 / 2; + mmc->f_max = mxc_get_clock(MXC_SSP0_CLK + mxsmmc_clk_id) * 1000 / 2; mmc->b_max = 0x20; mmc_register(mmc); -- cgit v1.2.1 From 09439c3197bb19e091ce160b398451517a8fe1b0 Mon Sep 17 00:00:00 2001 From: Troy Kisky Date: Mon, 22 Oct 2012 16:40:40 +0000 Subject: net: fec_mxc: delete CONFIG_FEC_MXC_MULTI It is more logical to test for CONFIG_FEC_MXC_PHYADDR to determine whether to define the function fecmxc_initialize. Signed-off-by: Troy Kisky --- drivers/net/fec_mxc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index 3e232c7cbc..6596ceb3dc 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -1021,7 +1021,7 @@ err1: return ret; } -#ifndef CONFIG_FEC_MXC_MULTI +#ifdef CONFIG_FEC_MXC_PHYADDR int fecmxc_initialize(bd_t *bd) { int lout = 1; -- cgit v1.2.1 From 575c5cc06f63d02fda73c7b29c6d782de4df6393 Mon Sep 17 00:00:00 2001 From: Troy Kisky Date: Mon, 22 Oct 2012 16:40:41 +0000 Subject: net: fec_mxc: change fec_mii_setspeed parameter Only the hardware ethernet registers are needed for this function, so don't pass the more general structure. I'm trying to separate MII and fec. This also fixes MX28 fec_mii_setspeed use on secondary ethernet port This was found by inspection of the code and should be checked on real hardware. Signed-off-by: Troy Kisky --- drivers/net/fec_mxc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index 6596ceb3dc..eb89e573cb 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -135,15 +135,15 @@ static int fec_mdio_read(struct ethernet_regs *eth, uint8_t phyAddr, return val; } -static void fec_mii_setspeed(struct fec_priv *fec) +static void fec_mii_setspeed(struct ethernet_regs *eth) { /* * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock * and do not drop the Preamble. */ writel((((imx_get_fecclk() / 1000000) + 2) / 5) << 1, - &fec->eth->mii_speed); - debug("%s: mii_speed %08x\n", __func__, readl(&fec->eth->mii_speed)); + ð->mii_speed); + debug("%s: mii_speed %08x\n", __func__, readl(ð->mii_speed)); } static int fec_mdio_write(struct ethernet_regs *eth, uint8_t phyAddr, @@ -611,7 +611,7 @@ static int fec_init(struct eth_device *dev, bd_t* bd) fec_reg_setup(fec); if (fec->xcv_type != SEVENWIRE) - fec_mii_setspeed(fec); + fec_mii_setspeed(fec->bus->priv); /* * Set Opcode/Pause Duration Register @@ -966,7 +966,6 @@ static int fec_probe(bd_t *bd, int dev_id, int phy_id, uint32_t base_addr) } fec_reg_setup(fec); - fec_mii_setspeed(fec); if (dev_id == -1) { sprintf(edev->name, "FEC"); @@ -995,6 +994,7 @@ static int fec_probe(bd_t *bd, int dev_id, int phy_id, uint32_t base_addr) #else bus->priv = fec->eth; #endif + fec_mii_setspeed(bus->priv); ret = mdio_register(bus); if (ret) { printf("mdio_register failed\n"); -- cgit v1.2.1 From eef2448039c43493b2f9def6f257f1006fb0e956 Mon Sep 17 00:00:00 2001 From: Troy Kisky Date: Mon, 22 Oct 2012 16:40:42 +0000 Subject: net: fec_mxc: have fecmxc_initialize call fecmxc_initialize_multi Having only one call to fec_probe will ease the changing of its parameters. Signed-off-by: Troy Kisky --- drivers/net/fec_mxc.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'drivers') diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index eb89e573cb..f7384ad708 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -1021,27 +1021,19 @@ err1: return ret; } -#ifdef CONFIG_FEC_MXC_PHYADDR -int fecmxc_initialize(bd_t *bd) -{ - int lout = 1; - - debug("eth_init: fec_probe(bd)\n"); - lout = fec_probe(bd, -1, CONFIG_FEC_MXC_PHYADDR, IMX_FEC_BASE); - - return lout; -} -#endif - int fecmxc_initialize_multi(bd_t *bd, int dev_id, int phy_id, uint32_t addr) { - int lout = 1; - debug("eth_init: fec_probe(bd, %i, %i) @ %08x\n", dev_id, phy_id, addr); - lout = fec_probe(bd, dev_id, phy_id, addr); + return fec_probe(bd, dev_id, phy_id, addr); +} - return lout; +#ifdef CONFIG_FEC_MXC_PHYADDR +int fecmxc_initialize(bd_t *bd) +{ + return fecmxc_initialize_multi(bd, -1, CONFIG_FEC_MXC_PHYADDR, + IMX_FEC_BASE); } +#endif #ifndef CONFIG_PHYLIB int fecmxc_register_mii_postcall(struct eth_device *dev, int (*cb)(int)) -- cgit v1.2.1 From 1adb406b014176f0c1a925e4d3e9aae556dfe571 Mon Sep 17 00:00:00 2001 From: Troy Kisky Date: Mon, 22 Oct 2012 16:40:43 +0000 Subject: phy: add phy_find_by_mask/phy_connect_dev It is useful to be able to try a range of possible phy addresses to connect. Also, an ethernet device is not required to use phy_find_by_mask leading to better separation of mii vs ethernet, as suggested by Andy Fleming. Signed-off-by: Troy Kisky --- drivers/net/phy/phy.c | 128 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 50 deletions(-) (limited to 'drivers') diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 1ffa791dce..d0ed7666ed 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -31,6 +31,7 @@ #include #include #include +#include /* Generic PHY support and helper functions */ @@ -574,6 +575,61 @@ static int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id) return 0; } +static struct phy_device *create_phy_by_mask(struct mii_dev *bus, + unsigned phy_mask, int devad, phy_interface_t interface) +{ + u32 phy_id = 0xffffffff; + while (phy_mask) { + int addr = ffs(phy_mask) - 1; + int r = get_phy_id(bus, addr, devad, &phy_id); + if (r < 0) + return ERR_PTR(r); + /* If the PHY ID is mostly f's, we didn't find anything */ + if ((phy_id & 0x1fffffff) != 0x1fffffff) + return phy_device_create(bus, addr, phy_id, interface); + phy_mask &= ~(1 << addr); + } + return NULL; +} + +static struct phy_device *search_for_existing_phy(struct mii_dev *bus, + unsigned phy_mask, phy_interface_t interface) +{ + /* If we have one, return the existing device, with new interface */ + while (phy_mask) { + int addr = ffs(phy_mask) - 1; + if (bus->phymap[addr]) { + bus->phymap[addr]->interface = interface; + return bus->phymap[addr]; + } + phy_mask &= ~(1 << addr); + } + return NULL; +} + +static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, + unsigned phy_mask, phy_interface_t interface) +{ + int i; + struct phy_device *phydev; + + phydev = search_for_existing_phy(bus, phy_mask, interface); + if (phydev) + return phydev; + /* Try Standard (ie Clause 22) access */ + /* Otherwise we have to try Clause 45 */ + for (i = 0; i < 5; i++) { + phydev = create_phy_by_mask(bus, phy_mask, + i ? i : MDIO_DEVAD_NONE, interface); + if (IS_ERR(phydev)) + return NULL; + if (phydev) + return phydev; + } + printf("Phy not found\n"); + return phy_device_create(bus, ffs(phy_mask) - 1, 0xffffffff, interface); +} + /** * get_phy_device - reads the specified PHY device and returns its @phy_device struct * @bus: the target MII bus @@ -585,38 +641,7 @@ static int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id) static struct phy_device *get_phy_device(struct mii_dev *bus, int addr, phy_interface_t interface) { - u32 phy_id = 0x1fffffff; - int i; - int r; - - /* If we have one, return the existing device, with new interface */ - if (bus->phymap[addr]) { - bus->phymap[addr]->interface = interface; - - return bus->phymap[addr]; - } - - /* Try Standard (ie Clause 22) access */ - r = get_phy_id(bus, addr, MDIO_DEVAD_NONE, &phy_id); - if (r) - return NULL; - - /* If the PHY ID is mostly f's, we didn't find anything */ - if ((phy_id & 0x1fffffff) != 0x1fffffff) - return phy_device_create(bus, addr, phy_id, interface); - - /* Otherwise we have to try Clause 45 */ - for (i = 1; i < 5; i++) { - r = get_phy_id(bus, addr, i, &phy_id); - if (r) - return NULL; - - /* If the phy_id is mostly Fs, there is no device there */ - if ((phy_id & 0x1fffffff) != 0x1fffffff) - break; - } - - return phy_device_create(bus, addr, phy_id, interface); + return get_phy_device_by_mask(bus, 1 << addr, interface); } int phy_reset(struct phy_device *phydev) @@ -689,38 +714,41 @@ int miiphy_reset(const char *devname, unsigned char addr) return phy_reset(phydev); } -struct phy_device *phy_connect(struct mii_dev *bus, int addr, - struct eth_device *dev, - phy_interface_t interface) +struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask, + phy_interface_t interface) { - struct phy_device *phydev; - /* Reset the bus */ if (bus->reset) bus->reset(bus); /* Wait 15ms to make sure the PHY has come out of hard reset */ udelay(15000); + return get_phy_device_by_mask(bus, phy_mask, interface); +} - phydev = get_phy_device(bus, addr, interface); - - if (!phydev) { - printf("Could not get PHY for %s:%d\n", bus->name, addr); - - return NULL; - } - +void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev) +{ /* Soft Reset the PHY */ phy_reset(phydev); - - if (phydev->dev) + if (phydev->dev) { printf("%s:%d is connected to %s. Reconnecting to %s\n", - bus->name, addr, phydev->dev->name, dev->name); - + phydev->bus->name, phydev->addr, + phydev->dev->name, dev->name); + } phydev->dev = dev; - debug("%s connected to %s\n", dev->name, phydev->drv->name); +} + +struct phy_device *phy_connect(struct mii_dev *bus, int addr, + struct eth_device *dev, phy_interface_t interface) +{ + struct phy_device *phydev; + phydev = phy_find_by_mask(bus, 1 << addr, interface); + if (phydev) + phy_connect_dev(phydev, dev); + else + printf("Could not get PHY for %s: addr %d\n", bus->name, addr); return phydev; } -- cgit v1.2.1 From ef8e3a3bbf0720068b7bf6e4f182c17679f94fa2 Mon Sep 17 00:00:00 2001 From: Troy Kisky Date: Mon, 22 Oct 2012 16:40:44 +0000 Subject: net: fec_mxc: use fec_set_dev_name to set name This allows us to create the phydev before calling fec_probe in later patch. Signed-off-by: Troy Kisky --- drivers/net/fec_mxc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'drivers') diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index f7384ad708..7e2721070e 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -915,6 +915,11 @@ static int fec_recv(struct eth_device *dev) return len; } +static void fec_set_dev_name(char *dest, int dev_id) +{ + sprintf(dest, (dev_id == -1) ? "FEC" : "FEC%i", dev_id); +} + static int fec_probe(bd_t *bd, int dev_id, int phy_id, uint32_t base_addr) { struct eth_device *edev; @@ -967,13 +972,8 @@ static int fec_probe(bd_t *bd, int dev_id, int phy_id, uint32_t base_addr) fec_reg_setup(fec); - if (dev_id == -1) { - sprintf(edev->name, "FEC"); - fec->dev_id = 0; - } else { - sprintf(edev->name, "FEC%i", dev_id); - fec->dev_id = dev_id; - } + fec_set_dev_name(edev->name, dev_id); + fec->dev_id = (dev_id == -1) ? 0 : dev_id; fec->phy_id = phy_id; bus = mdio_alloc(); @@ -984,7 +984,7 @@ static int fec_probe(bd_t *bd, int dev_id, int phy_id, uint32_t base_addr) } bus->read = fec_phy_read; bus->write = fec_phy_write; - sprintf(bus->name, edev->name); + fec_set_dev_name(bus->name, dev_id); #ifdef CONFIG_MX28 /* * The i.MX28 has two ethernet interfaces, but they are not equal. -- cgit v1.2.1 From 4dc27eed5230c485ef8016ccea6ea0abbd937d98 Mon Sep 17 00:00:00 2001 From: Troy Kisky Date: Mon, 22 Oct 2012 16:40:45 +0000 Subject: net: fec_mxc: only call phy_connect in fec_probe This allows us to create the phydev before calling fec_probe in later patch. Signed-off-by: Troy Kisky --- drivers/net/fec_mxc.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'drivers') diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index 7e2721070e..913c5617b2 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -392,21 +392,6 @@ static int fec_set_hwaddr(struct eth_device *dev) return 0; } -static void fec_eth_phy_config(struct eth_device *dev) -{ -#ifdef CONFIG_PHYLIB - struct fec_priv *fec = (struct fec_priv *)dev->priv; - struct phy_device *phydev; - - phydev = phy_connect(fec->bus, fec->phy_id, dev, - PHY_INTERFACE_MODE_RGMII); - if (phydev) { - fec->phydev = phydev; - phy_config(phydev); - } -#endif -} - /* * Do initial configuration of the FEC registers */ @@ -511,9 +496,7 @@ static int fec_open(struct eth_device *edev) #endif #ifdef CONFIG_PHYLIB - if (!fec->phydev) - fec_eth_phy_config(edev); - if (fec->phydev) { + { /* Start up the PHY */ int ret = phy_startup(fec->phydev); @@ -523,8 +506,6 @@ static int fec_open(struct eth_device *edev) return ret; } speed = fec->phydev->speed; - } else { - speed = _100BASET; } #else miiphy_wait_aneg(edev); @@ -922,6 +903,7 @@ static void fec_set_dev_name(char *dest, int dev_id) static int fec_probe(bd_t *bd, int dev_id, int phy_id, uint32_t base_addr) { + struct phy_device *phydev; struct eth_device *edev; struct fec_priv *fec; struct mii_dev *bus; @@ -1010,7 +992,16 @@ static int fec_probe(bd_t *bd, int dev_id, int phy_id, uint32_t base_addr) memcpy(edev->enetaddr, ethaddr, 6); } /* Configure phy */ - fec_eth_phy_config(edev); +#ifdef CONFIG_PHYLIB + phydev = phy_connect(fec->bus, phy_id, edev, PHY_INTERFACE_MODE_RGMII); + if (!phydev) { + free(bus); + ret = -ENOMEM; + goto err3; + } + fec->phydev = phydev; + phy_config(phydev); +#endif return ret; err3: -- cgit v1.2.1 From fe428b909b83f0ef83d1fbc7a446bfb60bc4fe01 Mon Sep 17 00:00:00 2001 From: Troy Kisky Date: Mon, 22 Oct 2012 16:40:46 +0000 Subject: net: fec_mxc: get phydev before fec_probe Signed-off-by: Troy Kisky --- drivers/net/fec_mxc.c | 117 ++++++++++++++++++++++++++++++++------------------ drivers/net/fec_mxc.h | 2 +- 2 files changed, 76 insertions(+), 43 deletions(-) (limited to 'drivers') diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index 913c5617b2..4dbcdca4a0 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -901,12 +901,16 @@ static void fec_set_dev_name(char *dest, int dev_id) sprintf(dest, (dev_id == -1) ? "FEC" : "FEC%i", dev_id); } -static int fec_probe(bd_t *bd, int dev_id, int phy_id, uint32_t base_addr) +#ifdef CONFIG_PHYLIB +int fec_probe(bd_t *bd, int dev_id, uint32_t base_addr, + struct mii_dev *bus, struct phy_device *phydev) +#else +static int fec_probe(bd_t *bd, int dev_id, uint32_t base_addr, + struct mii_dev *bus, int phy_id) +#endif { - struct phy_device *phydev; struct eth_device *edev; struct fec_priv *fec; - struct mii_dev *bus; unsigned char ethaddr[6]; uint32_t start; int ret = 0; @@ -953,69 +957,98 @@ static int fec_probe(bd_t *bd, int dev_id, int phy_id, uint32_t base_addr) } fec_reg_setup(fec); - fec_set_dev_name(edev->name, dev_id); fec->dev_id = (dev_id == -1) ? 0 : dev_id; + fec->bus = bus; + fec_mii_setspeed(bus->priv); +#ifdef CONFIG_PHYLIB + fec->phydev = phydev; + phy_connect_dev(phydev, edev); + /* Configure phy */ + phy_config(phydev); +#else fec->phy_id = phy_id; +#endif + eth_register(edev); + + if (fec_get_hwaddr(edev, dev_id, ethaddr) == 0) { + debug("got MAC%d address from fuse: %pM\n", dev_id, ethaddr); + memcpy(edev->enetaddr, ethaddr, 6); + } + return ret; +err3: + free(fec); +err2: + free(edev); +err1: + return ret; +} + +struct mii_dev *fec_get_miibus(uint32_t base_addr, int dev_id) +{ + struct ethernet_regs *eth = (struct ethernet_regs *)base_addr; + struct mii_dev *bus; + int ret; bus = mdio_alloc(); if (!bus) { printf("mdio_alloc failed\n"); - ret = -ENOMEM; - goto err3; + return NULL; } bus->read = fec_phy_read; bus->write = fec_phy_write; + bus->priv = eth; fec_set_dev_name(bus->name, dev_id); + + ret = mdio_register(bus); + if (ret) { + printf("mdio_register failed\n"); + free(bus); + return NULL; + } + fec_mii_setspeed(eth); + return bus; +} + +int fecmxc_initialize_multi(bd_t *bd, int dev_id, int phy_id, uint32_t addr) +{ + uint32_t base_mii; + struct mii_dev *bus = NULL; +#ifdef CONFIG_PHYLIB + struct phy_device *phydev = NULL; +#endif + int ret; + #ifdef CONFIG_MX28 /* * The i.MX28 has two ethernet interfaces, but they are not equal. * Only the first one can access the MDIO bus. */ - bus->priv = (struct ethernet_regs *)MXS_ENET0_BASE; + base_mii = MXS_ENET0_BASE; #else - bus->priv = fec->eth; + base_mii = addr; #endif - fec_mii_setspeed(bus->priv); - ret = mdio_register(bus); - if (ret) { - printf("mdio_register failed\n"); - free(bus); - ret = -ENOMEM; - goto err3; - } - fec->bus = bus; - eth_register(edev); - - if (fec_get_hwaddr(edev, dev_id, ethaddr) == 0) { - debug("got MAC%d address from fuse: %pM\n", dev_id, ethaddr); - memcpy(edev->enetaddr, ethaddr, 6); - } - /* Configure phy */ + debug("eth_init: fec_probe(bd, %i, %i) @ %08x\n", dev_id, phy_id, addr); + bus = fec_get_miibus(base_mii, dev_id); + if (!bus) + return -ENOMEM; #ifdef CONFIG_PHYLIB - phydev = phy_connect(fec->bus, phy_id, edev, PHY_INTERFACE_MODE_RGMII); + phydev = phy_find_by_mask(bus, 1 << phy_id, PHY_INTERFACE_MODE_RGMII); if (!phydev) { free(bus); - ret = -ENOMEM; - goto err3; + return -ENOMEM; } - fec->phydev = phydev; - phy_config(phydev); + ret = fec_probe(bd, dev_id, addr, bus, phydev); +#else + ret = fec_probe(bd, dev_id, addr, bus, phy_id); #endif + if (ret) { +#ifdef CONFIG_PHYLIB + free(phydev); +#endif + free(bus); + } return ret; - -err3: - free(fec); -err2: - free(edev); -err1: - return ret; -} - -int fecmxc_initialize_multi(bd_t *bd, int dev_id, int phy_id, uint32_t addr) -{ - debug("eth_init: fec_probe(bd, %i, %i) @ %08x\n", dev_id, phy_id, addr); - return fec_probe(bd, dev_id, phy_id, addr); } #ifdef CONFIG_FEC_MXC_PHYADDR diff --git a/drivers/net/fec_mxc.h b/drivers/net/fec_mxc.h index 203285af9a..b8f0da36cd 100644 --- a/drivers/net/fec_mxc.h +++ b/drivers/net/fec_mxc.h @@ -271,11 +271,11 @@ struct fec_priv { bd_t *bd; uint8_t *tdb_ptr; int dev_id; - int phy_id; struct mii_dev *bus; #ifdef CONFIG_PHYLIB struct phy_device *phydev; #else + int phy_id; int (*mii_postcall)(int); #endif }; -- cgit v1.2.1 From 0e5c05efb4c6ff91c556eff347d023463a96503b Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 22 Jan 2013 15:01:00 +0000 Subject: mxs: dma: Fix APBH DMA driver for MX23 The MX23 has less channels for the APBH DMA, sligtly different register layout and some bits in those registers are placed differently. Reflect this in the driver. This patch fixes MMC/DMA issue on MX23. Signed-off-by: Marek Vasut Cc: Otavio Salvador Cc: Fabio Estevam Cc: Stefano Babic --- drivers/dma/apbh_dma.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/dma/apbh_dma.c b/drivers/dma/apbh_dma.c index 37a941cc5b..0c1cd831e0 100644 --- a/drivers/dma/apbh_dma.c +++ b/drivers/dma/apbh_dma.c @@ -223,13 +223,19 @@ static int mxs_dma_reset(int channel) struct mxs_apbh_regs *apbh_regs = (struct mxs_apbh_regs *)MXS_APBH_BASE; int ret; +#if defined(CONFIG_MX23) + uint32_t setreg = (uint32_t)(&apbh_regs->hw_apbh_ctrl0_set); + uint32_t offset = APBH_CTRL0_RESET_CHANNEL_OFFSET; +#elif defined(CONFIG_MX28) + uint32_t setreg = (uint32_t)(&apbh_regs->hw_apbh_channel_ctrl_set); + uint32_t offset = APBH_CHANNEL_CTRL_RESET_CHANNEL_OFFSET; +#endif ret = mxs_dma_validate_chan(channel); if (ret) return ret; - writel(1 << (channel + APBH_CHANNEL_CTRL_RESET_CHANNEL_OFFSET), - &apbh_regs->hw_apbh_channel_ctrl_set); + writel(1 << (channel + offset), setreg); return 0; } -- cgit v1.2.1 From 8000d8a8260c95727b6357a638a5e80625d7a899 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Tue, 22 Jan 2013 15:01:02 +0000 Subject: mxs: mmc: Fix MMC reset on iMX23 This does the same reset mask as done in v3.7 Linux kernel code. The block is properly configured for MMC operation that way. Signed-off-by: Otavio Salvador Cc: Marek Vasut Cc: Fabio Estevam Cc: Stefano Babic --- drivers/mmc/mxsmmc.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c index 0c4cd54b79..9d71202ef3 100644 --- a/drivers/mmc/mxsmmc.c +++ b/drivers/mmc/mxsmmc.c @@ -334,11 +334,17 @@ static int mxsmmc_init(struct mmc *mmc) /* Reset SSP */ mxs_reset_block(&ssp_regs->hw_ssp_ctrl0_reg); - /* 8 bits word length in MMC mode */ - clrsetbits_le32(&ssp_regs->hw_ssp_ctrl1, - SSP_CTRL1_SSP_MODE_MASK | SSP_CTRL1_WORD_LENGTH_MASK | - SSP_CTRL1_DMA_ENABLE, - SSP_CTRL1_SSP_MODE_SD_MMC | SSP_CTRL1_WORD_LENGTH_EIGHT_BITS); + /* Reconfigure the SSP block for MMC operation */ + writel(SSP_CTRL1_SSP_MODE_SD_MMC | + SSP_CTRL1_WORD_LENGTH_EIGHT_BITS | + SSP_CTRL1_DMA_ENABLE | + SSP_CTRL1_POLARITY | + SSP_CTRL1_RECV_TIMEOUT_IRQ_EN | + SSP_CTRL1_DATA_CRC_IRQ_EN | + SSP_CTRL1_DATA_TIMEOUT_IRQ_EN | + SSP_CTRL1_RESP_TIMEOUT_IRQ_EN | + SSP_CTRL1_RESP_ERR_IRQ_EN, + &ssp_regs->hw_ssp_ctrl1_set); /* Set initial bit clock 400 KHz */ mxs_set_ssp_busclock(priv->id, 400); -- cgit v1.2.1 From 90bc2bf29780c2d238bb0c898d3a6cc6ec73922a Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 22 Jan 2013 15:01:03 +0000 Subject: mxs: mmc: Allow overriding default card detect implementation Some MXS based boards do not implement the card-detect signal. Allow user to specify alternate card-detect implementation. Signed-off-by: Marek Vasut Cc: Otavio Salvador Cc: Fabio Estevam Cc: Stefano Babic --- drivers/mmc/mxsmmc.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c index 9d71202ef3..023dbd5bc2 100644 --- a/drivers/mmc/mxsmmc.c +++ b/drivers/mmc/mxsmmc.c @@ -49,12 +49,23 @@ struct mxsmmc_priv { struct mxs_ssp_regs *regs; uint32_t buswidth; int (*mmc_is_wp)(int); + int (*mmc_cd)(int); struct mxs_dma_desc *desc; }; #define MXSMMC_MAX_TIMEOUT 10000 #define MXSMMC_SMALL_TRANSFER 512 +static int mxsmmc_cd(struct mxsmmc_priv *priv) +{ + struct mxs_ssp_regs *ssp_regs = priv->regs; + + if (priv->mmc_cd) + return priv->mmc_cd(priv->id); + + return !(readl(&ssp_regs->hw_ssp_status) & SSP_STATUS_CARD_DETECT); +} + static int mxsmmc_send_cmd_pio(struct mxsmmc_priv *priv, struct mmc_data *data) { struct mxs_ssp_regs *ssp_regs = priv->regs; @@ -166,7 +177,7 @@ mxsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data) } /* See if card is present */ - if (readl(&ssp_regs->hw_ssp_status) & SSP_STATUS_CARD_DETECT) { + if (!mxsmmc_cd(priv)) { printf("MMC%d: No card detected!\n", mmc->block_dev.dev); return NO_CARD_ERR; } @@ -357,7 +368,7 @@ static int mxsmmc_init(struct mmc *mmc) return 0; } -int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int)) +int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int)) { struct mmc *mmc = NULL; struct mxsmmc_priv *priv = NULL; @@ -395,6 +406,7 @@ int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int)) return ret; priv->mmc_is_wp = wp; + priv->mmc_cd = cd; priv->id = id; priv->regs = mxs_ssp_regs_by_bus(id); -- cgit v1.2.1 From e5b380ac68c86ec8c579421658152b1a90828c17 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 22 Jan 2013 15:01:04 +0000 Subject: mxs: mmc: Fix the MMC driver for MX23 The MX23 has different layout of DMA channels. Fix the MMC driver to support MX23. Signed-off-by: Marek Vasut Cc: Otavio Salvador Cc: Fabio Estevam Cc: Stefano Babic --- drivers/mmc/mxsmmc.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c index 023dbd5bc2..a72f66cc7a 100644 --- a/drivers/mmc/mxsmmc.c +++ b/drivers/mmc/mxsmmc.c @@ -53,6 +53,12 @@ struct mxsmmc_priv { struct mxs_dma_desc *desc; }; +#if defined(CONFIG_MX23) +static const unsigned int mxsmmc_id_offset = 1; +#elif defined(CONFIG_MX28) +static const unsigned int mxsmmc_id_offset = 0; +#endif + #define MXSMMC_MAX_TIMEOUT 10000 #define MXSMMC_SMALL_TRANSFER 512 @@ -131,7 +137,7 @@ static int mxsmmc_send_cmd_dma(struct mxsmmc_priv *priv, struct mmc_data *data) priv->desc->cmd.data |= MXS_DMA_DESC_IRQ | MXS_DMA_DESC_DEC_SEM | (data_count << MXS_DMA_DESC_BYTES_OFFSET); - dmach = MXS_DMA_CHANNEL_AHB_APBH_SSP0 + priv->id; + dmach = MXS_DMA_CHANNEL_AHB_APBH_SSP0 + priv->id + mxsmmc_id_offset; mxs_dma_desc_append(dmach, priv->desc); if (mxs_dma_go(dmach)) { bounce_buffer_stop(&bbstate); @@ -222,14 +228,25 @@ mxsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data) } ctrl0 |= SSP_CTRL0_DATA_XFER; + + reg = data->blocksize * data->blocks; +#if defined(CONFIG_MX23) + ctrl0 |= reg & SSP_CTRL0_XFER_COUNT_MASK; + + clrsetbits_le32(&ssp_regs->hw_ssp_cmd0, + SSP_CMD0_BLOCK_SIZE_MASK | SSP_CMD0_BLOCK_COUNT_MASK, + ((data->blocks - 1) << SSP_CMD0_BLOCK_COUNT_OFFSET) | + ((ffs(data->blocksize) - 1) << + SSP_CMD0_BLOCK_SIZE_OFFSET)); +#elif defined(CONFIG_MX28) + writel(reg, &ssp_regs->hw_ssp_xfer_size); + reg = ((data->blocks - 1) << SSP_BLOCK_SIZE_BLOCK_COUNT_OFFSET) | ((ffs(data->blocksize) - 1) << SSP_BLOCK_SIZE_BLOCK_SIZE_OFFSET); writel(reg, &ssp_regs->hw_ssp_block_size); - - reg = data->blocksize * data->blocks; - writel(reg, &ssp_regs->hw_ssp_xfer_size); +#endif } /* Kick off the command */ @@ -401,7 +418,7 @@ int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int)) return -ENOMEM; } - ret = mxs_dma_init_channel(id); + ret = mxs_dma_init_channel(id + mxsmmc_id_offset); if (ret) return ret; -- cgit v1.2.1