From patchwork Wed Aug 3 06:14:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Bedel X-Patchwork-Id: 655271 X-Patchwork-Delegate: marek.vasut@gmail.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 3s42q918Pyz9sR9 for ; Wed, 3 Aug 2016 16:15:01 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 03C96A74DB; Wed, 3 Aug 2016 08:14:59 +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 BdfpEmR1_Mq8; Wed, 3 Aug 2016 08:14:58 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 95785A74FB; Wed, 3 Aug 2016 08:14:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 78EE0A7514 for ; Wed, 3 Aug 2016 08:14:55 +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 AsKh3HyJYqYo for ; Wed, 3 Aug 2016 08:14:55 +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 mout.kundenserver.de (mout.kundenserver.de [212.227.126.134]) by theia.denx.de (Postfix) with ESMTPS id 1CDA6A74FB for ; Wed, 3 Aug 2016 08:14:51 +0200 (CEST) Received: from mailbox.adnet.avionic-design.de ([109.75.18.3]) by mrelayeu.kundenserver.de (mreue004) with ESMTPSA (Nemesis) id 0MR97T-1bhIZT0h39-00UX9G; Wed, 03 Aug 2016 08:14:48 +0200 Received: from localhost (localhost [127.0.0.1]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id 0A9312A2824C; Wed, 3 Aug 2016 08:14:47 +0200 (CEST) X-Virus-Scanned: amavisd-new at avionic-design.de Received: from mailbox.adnet.avionic-design.de ([127.0.0.1]) by localhost (mailbox.avionic-design.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id smzCZGIcG27i; Wed, 3 Aug 2016 08:14:46 +0200 (CEST) Received: from avionic-0020.adnet.avionic-design.de (avionic-0020.adnet.avionic-design.de [172.20.31.193]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id D636F2A28250; Wed, 3 Aug 2016 08:14:45 +0200 (CEST) From: Alban Bedel To: u-boot@lists.denx.de Date: Wed, 3 Aug 2016 08:14:42 +0200 Message-Id: <20160803061443.15601-3-alban.bedel@avionic-design.de> X-Mailer: git-send-email 2.9.2 In-Reply-To: <20160803061443.15601-1-alban.bedel@avionic-design.de> References: <20160803061443.15601-1-alban.bedel@avionic-design.de> X-Provags-ID: V03:K0:unCrP9/YiqDJ7RP824hmeFYA1a7hIpM9l8JBfk28WdfRhSnIJ/H S4SD1V7N7yCEJz4hiZf2XckgLKhn63JkVTeh2vHIkBPzIiM3j5lFcqPjMhcUMB616vEwiL6 mUVsXPr40ySE3iaEptREp1xpyGLNPqSx5PobTYNDcJa8oOP2N6Pmp8ATwle9OYDwinlIpC6 cNdTByojMJ1Ju2U6OEz2A== X-UI-Out-Filterresults: notjunk:1; V01:K0:kA5Ow3auCLc=:BD8Ytvpup6ds6wM1uYr/D8 yZZj+rnsQFq5uZf91654WZKdCPZNqrq8d+kJewiLEhYA0Xm07VKwW9JA7lNJufJU44/cuK+hB mNi6uW4bLRGAAoE1T67EKwXBZZMZpBTskBuqVGji/nGuHq8dUk01glNLx6PoaaI80+tfyWvWz FtkwiOYNp+4No/qda1ZObewIRkNBKAOsHL8Z7do5TRp/HQGBqcto/0vlQy+jYSnLG15U1jisD WyZtDV9kKw3zZC2JrXoH7h8mfBDUaOyN2TRkA6fj7oBB/cWaOKkbZJ1c+r3DP6ewGN6+KhWxY 44PcCdEEFAgN8wZyN9PdIV83+ZkNTC398s7g8SG8DVtdFC5pxbwF6TyDxq35PeCcHJ2xavGf9 /E4Sbut43kFKRYtP2hJB/ycOybGOof+Es9ofO3+fnup8Se0O6dyV6xWFhimmS74dutJCcB2FJ SmgjQjxpKOzrzGx91hgRao59R87AAg/s7daYkN1osrYtzl6t/g1bBsUweIA5znWz52yHVtpJ2 82MNCftx80cRM/fM6rAhW6KUnfvZy2B7Yby8A2C5R4bziUPS2twR6O/p02HoNM5bW07NGzlVG fJuHo/G1lqo5UGgxRFsk8hYdcc9ebAUttcGF3SYQhoV1eQxUnCxnnEXK9krD/dg58iO3zme4G NSe9arfOZHxNc6/hKFgHBCrWNgf5uA44bmLu82Nt6re5FrIQVxWY035NKXrtMaY2aZ0U= Cc: Marek Vasut , Joe Hershberger , Alban Bedel Subject: [U-Boot] [PATCH 3/4] eth: asix88179: Prepare supporting the driver model 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" Change the prototype of a few functions to allow resuing the code for the driver model. Signed-off-by: Alban Bedel --- drivers/usb/eth/asix88179.c | 71 ++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/drivers/usb/eth/asix88179.c b/drivers/usb/eth/asix88179.c index 81eae04e3402..45106ce5ef59 100644 --- a/drivers/usb/eth/asix88179.c +++ b/drivers/usb/eth/asix88179.c @@ -259,36 +259,32 @@ static int asix_read_cmd(struct ueth_data *dev, u8 cmd, u16 value, u16 index, return len == size ? 0 : ECOMM; } -static int asix_read_mac(struct eth_device *eth) +static int asix_read_mac(struct ueth_data *dev, uint8_t *enetaddr) { - struct ueth_data *dev = (struct ueth_data *)eth->priv; - u8 buf[ETH_ALEN]; + int ret; - asix_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, 6, 6, buf); - debug("asix_read_mac() returning %02x:%02x:%02x:%02x:%02x:%02x\n", - buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); + ret = asix_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, 6, 6, enetaddr); + if (ret < 0) + debug("Failed to read MAC address: %02x\n", ret); - memcpy(eth->enetaddr, buf, ETH_ALEN); - - return 0; + return ret; } -static int asix_write_mac(struct eth_device *eth) +static int asix_write_mac(struct ueth_data *dev, uint8_t *enetaddr) { - struct ueth_data *dev = (struct ueth_data *)eth->priv; int ret; ret = asix_write_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, - ETH_ALEN, eth->enetaddr); + ETH_ALEN, enetaddr); if (ret < 0) debug("Failed to set MAC address: %02x\n", ret); return ret; } -static int asix_basic_reset(struct ueth_data *dev) +static int asix_basic_reset(struct ueth_data *dev, + struct asix_private *dev_priv) { - struct asix_private *dev_priv = (struct asix_private *)dev->dev_priv; u8 buf[5]; u16 *tmp16; u8 *tmp; @@ -387,13 +383,9 @@ static int asix_wait_link(struct ueth_data *dev) } } -/* - * Asix callbacks - */ -static int asix_init(struct eth_device *eth, bd_t *bd) +static int asix_init_common(struct ueth_data *dev, + struct asix_private *dev_priv) { - struct ueth_data *dev = (struct ueth_data *)eth->priv; - struct asix_private *dev_priv = (struct asix_private *)dev->dev_priv; u8 buf[2], tmp[5], link_sts; u16 *tmp16, mode; @@ -411,7 +403,7 @@ static int asix_init(struct eth_device *eth, bd_t *bd) if (asix_wait_link(dev) != 0) { /*reset device and try again*/ printf("Reset Ethernet Device\n"); - asix_basic_reset(dev); + asix_basic_reset(dev, dev_priv); if (asix_wait_link(dev) != 0) goto out_err; } @@ -463,11 +455,10 @@ out_err: return -1; } -static int asix_send(struct eth_device *eth, void *packet, int length) +static int asix_send_common(struct ueth_data *dev, + struct asix_private *dev_priv, + void *packet, int length) { - struct ueth_data *dev = (struct ueth_data *)eth->priv; - struct asix_private *dev_priv = (struct asix_private *)dev->dev_priv; - int err; u32 packet_len, tx_hdr2; int actual_len, framesize; @@ -504,6 +495,32 @@ static int asix_send(struct eth_device *eth, void *packet, int length) return err; } +/* + * Asix callbacks + */ +static int asix_init(struct eth_device *eth, bd_t *bd) +{ + struct ueth_data *dev = (struct ueth_data *)eth->priv; + struct asix_private *dev_priv = (struct asix_private *)dev->dev_priv; + + return asix_init_common(dev, dev_priv); +} + +static int asix_write_hwaddr(struct eth_device *eth) +{ + struct ueth_data *dev = (struct ueth_data *)eth->priv; + + return asix_write_mac(dev, eth->enetaddr); +} + +static int asix_send(struct eth_device *eth, void *packet, int length) +{ + struct ueth_data *dev = (struct ueth_data *)eth->priv; + struct asix_private *dev_priv = (struct asix_private *)dev->dev_priv; + + return asix_send_common(dev, dev_priv, packet, length); +} + static int asix_recv(struct eth_device *eth) { struct ueth_data *dev = (struct ueth_data *)eth->priv; @@ -702,14 +719,14 @@ int ax88179_eth_get_info(struct usb_device *dev, struct ueth_data *ss, eth->send = asix_send; eth->recv = asix_recv; eth->halt = asix_halt; - eth->write_hwaddr = asix_write_mac; + eth->write_hwaddr = asix_write_hwaddr; eth->priv = ss; if (asix_basic_reset(ss)) return 0; /* Get the MAC address */ - if (asix_read_mac(eth)) + if (asix_read_mac(ss, eth->enetaddr)) return 0; debug("MAC %pM\n", eth->enetaddr);