From patchwork Sat Apr 25 11:51:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 464490 X-Patchwork-Delegate: hdegoede@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id E9A141400B7 for ; Sat, 25 Apr 2015 21:52:18 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 190734BDEC; Sat, 25 Apr 2015 13:52:13 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dDSH964PHjtm; Sat, 25 Apr 2015 13:52:12 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 172264BDEE; Sat, 25 Apr 2015 13:52:08 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D99484BDBE for ; Sat, 25 Apr 2015 13:52:02 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id y-rueng_pNI7 for ; Sat, 25 Apr 2015 13:52:02 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by theia.denx.de (Postfix) with ESMTPS id 557BC4BDBF for ; Sat, 25 Apr 2015 13:52:00 +0200 (CEST) Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 0DA028E3FB; Sat, 25 Apr 2015 11:51:59 +0000 (UTC) Received: from shalem.localdomain.com (vpn1-6-3.ams2.redhat.com [10.36.6.3]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3PBpnRW013362; Sat, 25 Apr 2015 07:51:57 -0400 From: Hans de Goede To: Ian Campbell , Simon Glass , Stefan Roese Date: Sat, 25 Apr 2015 13:51:48 +0200 Message-Id: <1429962708-12065-5-git-send-email-hdegoede@redhat.com> In-Reply-To: <1429962708-12065-1-git-send-email-hdegoede@redhat.com> References: <1429962708-12065-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 4/4] sunxi: emac: Add driver model support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Modify the sunxi-emac eth driver to support driver model. Signed-off-by: Hans de Goede --- arch/arm/cpu/armv7/sunxi/board.c | 4 +- drivers/net/sunxi_emac.c | 81 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/arch/arm/cpu/armv7/sunxi/board.c b/arch/arm/cpu/armv7/sunxi/board.c index 7e9cf11..cde13ef 100644 --- a/arch/arm/cpu/armv7/sunxi/board.c +++ b/arch/arm/cpu/armv7/sunxi/board.c @@ -12,7 +12,9 @@ #include #include +#ifndef CONFIG_DM_ETH #include +#endif #include #include #ifdef CONFIG_SPL_BUILD @@ -224,7 +226,7 @@ int cpu_eth_init(bd_t *bis) mdelay(200); #endif -#ifdef CONFIG_SUNXI_EMAC +#if defined CONFIG_SUNXI_EMAC && !defined CONFIG_DM_ETH rc = sunxi_emac_initialize(bis); if (rc < 0) { printf("sunxi: failed to initialize emac\n"); diff --git a/drivers/net/sunxi_emac.c b/drivers/net/sunxi_emac.c index e43b1e7..306a022 100644 --- a/drivers/net/sunxi_emac.c +++ b/drivers/net/sunxi_emac.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -160,6 +161,9 @@ struct emac_eth_dev { struct mii_dev *bus; struct phy_device *phydev; int link_printed; +#ifdef CONFIG_DM_ETH + uchar rx_buf[EMAC_RX_BUFSIZE]; +#endif }; struct emac_rxhdr { @@ -509,6 +513,7 @@ static void sunxi_emac_board_setup(struct emac_eth_dev *priv) clrsetbits_le32(®s->mac_mcfg, 0xf << 2, 0xd << 2); } +#ifndef CONFIG_DM_ETH static int sunxi_emac_eth_init(struct eth_device *dev, bd_t *bis) { return _sunxi_emac_eth_init(dev->priv, dev->enetaddr); @@ -573,3 +578,79 @@ int sunxi_emac_initialize(void) return sunxi_emac_init_phy(priv, dev); } +#endif + +#ifdef CONFIG_DM_ETH +static int sunxi_emac_eth_start(struct udevice *dev) +{ + struct eth_pdata *pdata = dev_get_platdata(dev); + + return _sunxi_emac_eth_init(dev->priv, pdata->enetaddr); +} + +static int sunxi_emac_eth_send(struct udevice *dev, void *packet, int length) +{ + struct emac_eth_dev *priv = dev_get_priv(dev); + + return _sunxi_emac_eth_send(priv, packet, length); +} + +static int sunxi_emac_eth_recv(struct udevice *dev, uchar **packetp) +{ + struct emac_eth_dev *priv = dev_get_priv(dev); + int rx_len; + + rx_len = _sunxi_emac_eth_recv(priv, priv->rx_buf); + *packetp = priv->rx_buf; + + return rx_len; +} + +static void sunxi_emac_eth_stop(struct udevice *dev) +{ + /* Nothing to do here */ +} + +static int sunxi_emac_eth_probe(struct udevice *dev) +{ + struct eth_pdata *pdata = dev_get_platdata(dev); + struct emac_eth_dev *priv = dev_get_priv(dev); + + priv->regs = (struct emac_regs *)pdata->iobase; + sunxi_emac_board_setup(priv); + + return sunxi_emac_init_phy(priv, dev); +} + +static const struct eth_ops sunxi_emac_eth_ops = { + .start = sunxi_emac_eth_start, + .send = sunxi_emac_eth_send, + .recv = sunxi_emac_eth_recv, + .stop = sunxi_emac_eth_stop, +}; + +static int sunxi_emac_eth_ofdata_to_platdata(struct udevice *dev) +{ + struct eth_pdata *pdata = dev_get_platdata(dev); + + pdata->iobase = dev_get_addr(dev); + + return 0; +} + +static const struct udevice_id sunxi_emac_eth_ids[] = { + { .compatible = "allwinner,sun4i-a10-emac" }, + { } +}; + +U_BOOT_DRIVER(eth_sunxi_emac) = { + .name = "eth_sunxi_emac", + .id = UCLASS_ETH, + .of_match = sunxi_emac_eth_ids, + .ofdata_to_platdata = sunxi_emac_eth_ofdata_to_platdata, + .probe = sunxi_emac_eth_probe, + .ops = &sunxi_emac_eth_ops, + .priv_auto_alloc_size = sizeof(struct emac_eth_dev), + .platdata_auto_alloc_size = sizeof(struct eth_pdata), +}; +#endif