devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dinh Nguyen <dinguyen@altera.com>
To: Olof Johansson <olof@lixom.net>
Cc: dinh.linux@gmail.com, Arnd Bergmann <arnd@arndb.de>,
	Rob Herring <rob.herring@calxeda.com>,
	Pawel Moll <pawel.moll@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Stephen Warren <swarren@wwwdotorg.org>,
	Ian Campbell <ian.campbell@citrix.com>,
	devicetree@vger.kernel.org,
	Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	Pavel Machek <pavel@denx.de>,
	Jack Mitchell <jack.mitchell@dbbroadcast.co.uk>
Subject: Re: [RESEND PATCH 2/4] arm: socfpga: Add platform initialization for ethernet
Date: Mon, 12 Aug 2013 10:12:18 -0500	[thread overview]
Message-ID: <1376320338.28628.3.camel@linux-builds1> (raw)
In-Reply-To: <20130811235505.GI26757@quad.lixom.net>

On Sun, 2013-08-11 at 16:55 -0700, Olof Johansson wrote:
> Hi,
> 
> On Mon, Aug 05, 2013 at 04:58:43PM -0500, dinguyen@altera.com wrote:
> > From: Dinh Nguyen <dinguyen@altera.com>
> > 
> > Use the PHYLIB to set the correct clock and skew values to the Micrel PHY. Add
> > platform specific intilization to put the STMMAC ethernet controller into the
> > correct PHY mode.
> > 
> > Signed-off-by: Dinh Nguyen <dinguyen@altera.com>
> > Tested-by: Jack Mitchell <jack.mitchell@dbbroadcast.co.uk>
> > CC: Arnd Bergmann <arnd@arndb.de>
> > CC: Olof Johansson <olof@lixom.net>
> > Cc: Rob Herring <rob.herring@calxeda.com>
> > Cc: Pawel Moll <pawel.moll@arm.com>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: Stephen Warren <swarren@wwwdotorg.org>
> > Cc: Ian Campbell <ian.campbell@citrix.com>
> > Cc: devicetree@vger.kernel.org
> > Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> > Cc: Pavel Machek <pavel@denx.de>
> > Cc: Jack Mitchell <jack.mitchell@dbbroadcast.co.uk>
> > ---
> >  arch/arm/mach-socfpga/core.h    |    8 ++++
> >  arch/arm/mach-socfpga/socfpga.c |   85 ++++++++++++++++++++++++++++++++++++++-
> >  2 files changed, 92 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/arm/mach-socfpga/core.h b/arch/arm/mach-socfpga/core.h
> > index 572b8f7..505b8fe5 100644
> > --- a/arch/arm/mach-socfpga/core.h
> > +++ b/arch/arm/mach-socfpga/core.h
> > @@ -28,6 +28,14 @@
> >  #define RSTMGR_CTRL_SWCOLDRSTREQ	0x1	/* Cold Reset */
> >  #define RSTMGR_CTRL_SWWARMRSTREQ	0x2	/* Warm Reset */
> >  
> > +#define SYSMGR_EMACGRP_CTRL_OFFSET 0x60
> > +#define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII 0x0
> > +#define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII 0x1
> > +#define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII 0x2
> > +#define SYSMGR_EMACGRP_CTRL_PHYSEL_WIDTH 2
> > +
> > +#define SYSMGR_EMACGRP_CTRL_PHYSEL_MASK 0x00000003
> > +
> >  extern void socfpga_secondary_startup(void);
> >  extern void __iomem *socfpga_scu_base_addr;
> >  
> > diff --git a/arch/arm/mach-socfpga/socfpga.c b/arch/arm/mach-socfpga/socfpga.c
> > index bfce964..abbde76 100644
> > --- a/arch/arm/mach-socfpga/socfpga.c
> > +++ b/arch/arm/mach-socfpga/socfpga.c
> > @@ -16,10 +16,14 @@
> >   */
> >  #include <linux/clk-provider.h>
> >  #include <linux/irqchip.h>
> > +#include <linux/micrel_phy.h>
> >  #include <linux/of_address.h>
> >  #include <linux/of_irq.h>
> > +#include <linux/of_net.h>
> >  #include <linux/of_platform.h>
> >  #include <linux/reboot.h>
> > +#include <linux/stmmac.h>
> > +#include <linux/phy.h>
> >  
> >  #include <asm/hardware/cache-l2x0.h>
> >  #include <asm/mach/arch.h>
> > @@ -33,6 +37,22 @@ void __iomem *rst_manager_base_addr;
> >  void __iomem *clk_mgr_base_addr;
> >  unsigned long cpu1start_addr;
> >  
> > +static int stmmac_plat_init(struct platform_device *pdev);
> > +
> > +static struct plat_stmmacenet_data stmmacenet0_data = {
> > +	.init = &stmmac_plat_init,
> > +};
> > +
> > +static struct plat_stmmacenet_data stmmacenet1_data = {
> > +	.init = &stmmac_plat_init,
> > +};
> 
> I would prefer to see refactoring of the driver such that it gets
> the phy configuration data out of the devicetree instead of needing
> per-board callbacks.
> 
> > +
> > +static const struct of_dev_auxdata socfpga_auxdata_lookup[] __initconst = {
> > +	OF_DEV_AUXDATA("snps,dwmac-3.70a", 0xff700000, NULL, &stmmacenet0_data),
> > +	OF_DEV_AUXDATA("snps,dwmac-3.70a", 0xff702000, NULL, &stmmacenet1_data),
> > +	{/* sentinel */}
> > +};
> > +
> >  static struct map_desc scu_io_desc __initdata = {
> >  	.virtual	= SOCFPGA_SCU_VIRT_BASE,
> >  	.pfn		= 0, /* run-time */
> > @@ -58,6 +78,65 @@ static void __init socfpga_scu_map_io(void)
> >  	iotable_init(&scu_io_desc, 1);
> >  }
> >  
> > +static int ksz9021rlrn_phy_fixup(struct phy_device *phydev)
> > +{
> > +	if (IS_BUILTIN(CONFIG_PHYLIB)) {
> 
> So what happens if PHYLIB is a module?
> 
> > +		/* min rx data delay */
> > +		phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
> > +			MICREL_KSZ9021_RGMII_RX_DATA_PAD_SCEW | 0x8000);
> > +		phy_write(phydev, MICREL_KSZ9021_EXTREG_DATA_WRITE, 0x0000);
> > +
> > +		/* max rx/tx clock delay, min rx/tx control delay */
> > +		phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL,
> > +			MICREL_KSZ9021_RGMII_CLK_CTRL_PAD_SCEW | 0x8000);
> > +		phy_write(phydev, MICREL_KSZ9021_EXTREG_DATA_WRITE, 0xa0d0);
> > +		phy_write(phydev, MICREL_KSZ9021_EXTREG_CTRL, 0x104);
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +static int stmmac_plat_init(struct platform_device *pdev)
> > +{
> > +	u32 ctrl, val, shift;
> > +	int phymode;
> > +
> > +	if (of_machine_is_compatible("altr,socfpga-vt"))
> > +		return 0;
> > +
> > +	phymode = of_get_phy_mode(pdev->dev.of_node);
> > +
> > +	switch (phymode) {
> > +	case PHY_INTERFACE_MODE_RGMII:
> > +		val = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII;
> > +		break;
> > +	case PHY_INTERFACE_MODE_MII:
> > +	case PHY_INTERFACE_MODE_GMII:
> > +		val = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII;
> > +		break;
> > +	default:
> > +		pr_err("%s bad phy mode %d", __func__, phymode);
> > +		return -EINVAL;
> > +	}
> > +
> > +	if (&stmmacenet1_data == pdev->dev.platform_data)
> > +		shift = SYSMGR_EMACGRP_CTRL_PHYSEL_WIDTH;
> > +	else if (&stmmacenet0_data == pdev->dev.platform_data)
> > +		shift = 0;
> 
> This is awkward too, comparing back to the platform data to figure out which of
> the two devices you're on.
> 
> > +	else {
> > +		pr_err("%s unexpected platform data pointer\n", __func__);
> > +		return -EINVAL;
> > +	}
> > +
> > +	ctrl = readl(sys_manager_base_addr + SYSMGR_EMACGRP_CTRL_OFFSET);
> > +	ctrl &= ~(SYSMGR_EMACGRP_CTRL_PHYSEL_MASK << shift);
> > +	ctrl |= (val << shift);
> > +
> > +	writel(ctrl, (sys_manager_base_addr + SYSMGR_EMACGRP_CTRL_OFFSET));
> > +
> > +	return 0;
> > +}
> > +
> >  static void __init socfpga_map_io(void)
> >  {
> >  	socfpga_scu_map_io();
> > @@ -106,9 +185,13 @@ static void socfpga_cyclone5_restart(enum reboot_mode mode, const char *cmd)
> >  static void __init socfpga_cyclone5_init(void)
> >  {
> >  	l2x0_of_init(0, ~0UL);
> > -	of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
> > +	of_platform_populate(NULL, of_default_bus_match_table,
> > +		socfpga_auxdata_lookup, NULL);
> >  	of_clk_init(NULL);
> >  	socfpga_init_clocks();
> > +	if (IS_BUILTIN(CONFIG_PHYLIB))
> > +		phy_register_fixup_for_uid(PHY_ID_KSZ9021RLRN,
> > +			MICREL_PHY_ID_MASK, ksz9021rlrn_phy_fixup);
> 

Thanks for the review Olof. Will rework.

Dinh
> 
> -Olof
> 




  reply	other threads:[~2013-08-12 15:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-05 21:58 [RESEND PATCH 0/4] Enable ethernet support for SOCFPGA dinguyen
2013-08-05 21:58 ` [RESEND PATCH 1/4] arm: socfpga: Enable ARM_TWD for socfpga dinguyen
2013-08-06 13:35   ` Mark Rutland
2013-08-06 15:56     ` Dinh Nguyen
2013-08-07 18:53   ` Pavel Machek
2013-08-05 21:58 ` [RESEND PATCH 2/4] arm: socfpga: Add platform initialization for ethernet dinguyen
2013-08-07 18:57   ` Pavel Machek
2013-08-11 23:55   ` Olof Johansson
2013-08-12 15:12     ` Dinh Nguyen [this message]
2013-08-05 21:58 ` [RESEND PATCH 3/4] ARM: socfpga: dts: Fix entries for the ethernet entries dinguyen
2013-08-07 19:00   ` Pavel Machek
2013-08-05 21:58 ` [RESEND PATCH 4/4] arm: socfpga: Add support for SD/MMC and ethernet to defconfig dinguyen
2013-08-07 15:42   ` Pavel Machek
2013-08-08  9:01   ` Pavel Machek
2013-08-08 15:29     ` Dinh Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1376320338.28628.3.camel@linux-builds1 \
    --to=dinguyen@altera.com \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=dinh.linux@gmail.com \
    --cc=ian.campbell@citrix.com \
    --cc=jack.mitchell@dbbroadcast.co.uk \
    --cc=mark.rutland@arm.com \
    --cc=olof@lixom.net \
    --cc=pavel@denx.de \
    --cc=pawel.moll@arm.com \
    --cc=rob.herring@calxeda.com \
    --cc=swarren@wwwdotorg.org \
    --cc=thomas.petazzoni@free-electrons.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).