From patchwork Sat Feb 2 23:40:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 217711 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C623C2C008E for ; Sun, 3 Feb 2013 10:40:46 +1100 (EST) Received: from localhost ([::1]:45284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1mhQ-0001TR-J8 for incoming@patchwork.ozlabs.org; Sat, 02 Feb 2013 18:40:44 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1mh6-0001J2-5N for qemu-devel@nongnu.org; Sat, 02 Feb 2013 18:40:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U1mh3-0000ob-Th for qemu-devel@nongnu.org; Sat, 02 Feb 2013 18:40:23 -0500 Received: from mail-wg0-f50.google.com ([74.125.82.50]:63133) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1mh3-0000oG-Lo for qemu-devel@nongnu.org; Sat, 02 Feb 2013 18:40:21 -0500 Received: by mail-wg0-f50.google.com with SMTP id es5so3732561wgb.17 for ; Sat, 02 Feb 2013 15:40:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=Xo2gSc/Bk88a/nMujMo731PUcPIHyvIAZyLIlcF1fZw=; b=a7AIwSgV4WJSKmuidyYSrUu7pf2ysjYTe1nbzxDa32ff/61nxNHlJu7MH6jqp+nksb Kjlv1w5I5Fc4qChHbEyk5wO4EuRQ/MdZ/XwkYgcxqu+qRcAFNgTYaL7UZdBAjFx9B13a 9qkoozNzataVzYbjKwS/SVdpbQDjd6GAg/9mBUQwb30a0mer0nubkizCQ7pn0LaECRef jbQ5YzpIgB6YrNd4PxnFeYMMx9Lupfhgr93oR9FMHfb8xKECTBCvQrSnNEi0kPELd6Mn WlV/Pd5FeRlcEAHuQ/Bx+PhsMr433wxTZGCy9K40IXDkvkgaugnhWSlQK5KAS1rbOwib FKuA== X-Received: by 10.194.83.97 with SMTP id p1mr28435464wjy.17.1359848420484; Sat, 02 Feb 2013 15:40:20 -0800 (PST) Received: from localhost (host86-136-235-200.range86-136.btcentralplus.com. [86.136.235.200]) by mx.google.com with ESMTPS id ge2sm11844324wib.4.2013.02.02.15.40.18 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 02 Feb 2013 15:40:19 -0800 (PST) Received: by localhost (Postfix, from userid 1000) id 8C8ED3E0EC8; Sat, 2 Feb 2013 23:40:16 +0000 (GMT) From: Grant Likely To: qemu-devel@nongnu.org Date: Sat, 2 Feb 2013 23:40:05 +0000 Message-Id: <1359848409-1106-5-git-send-email-grant.likely@secretlab.ca> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1359848409-1106-1-git-send-email-grant.likely@secretlab.ca> References: <1359848409-1106-1-git-send-email-grant.likely@secretlab.ca> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQm9CX1SLZY+MmX37hDXHAt1tN6NqSQ/aMIzZ+w7Gik0/QMdwOXTOzKXoN8sujravJ69qtwO X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 74.125.82.50 Cc: Peter Maydell , Anthony Liguori , Grant Likely , Paul Brook , "Edgar E. Iglesias" , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH V3 4/8] hw/mdio: Generalize phy initialization routine X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org There really isn't anything tdk-specific about tdk_init() other than the phy id registers. The function should instead be generalized for any phy, at least as far as the ID registers are concerned. For the most part the read/write behaviour should be very similar across PHYs. This patch renames tdk_{read,write,init}() to mdio_phy_*() so it can be used for any PHY. More work definitely needs to be done here to make it easy to override the default behaviour for specific PHYs, but this at least is a reasonable start. Cc: Peter Maydell Cc: Paul Brook Cc: Edgar E. Iglesias Cc: Anthony Liguori Cc: Andreas Färber Signed-off-by: Grant Likely --- hw/etraxfs_eth.c | 2 +- hw/mdio.c | 14 +++++++------- hw/mdio.h | 2 +- hw/xilinx_axienet.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c index f26e338..4d56134 100644 --- a/hw/etraxfs_eth.c +++ b/hw/etraxfs_eth.c @@ -342,7 +342,7 @@ static int fs_eth_init(SysBusDevice *dev) object_get_typename(OBJECT(s)), dev->qdev.id, s); qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); - tdk_init(&s->phy); + mdio_phy_init(&s->phy, 0x0300, 0xe400); mdio_attach(&s->mdio_bus, &s->phy, s->phyaddr); return 0; } diff --git a/hw/mdio.c b/hw/mdio.c index e5e30b6..040ecf6 100644 --- a/hw/mdio.c +++ b/hw/mdio.c @@ -43,7 +43,7 @@ * linux driver (PHYID and Diagnostics reg). * TODO: Add friendly names for the register nums. */ -static unsigned int tdk_read(struct qemu_phy *phy, unsigned int req) +static unsigned int mdio_phy_read(struct qemu_phy *phy, unsigned int req) { int regnum; unsigned r = 0; @@ -107,7 +107,7 @@ static unsigned int tdk_read(struct qemu_phy *phy, unsigned int req) return r; } -static void tdk_write(struct qemu_phy *phy, unsigned int req, unsigned int data) +static void mdio_phy_write(struct qemu_phy *phy, unsigned int req, unsigned int data) { int regnum; @@ -120,18 +120,18 @@ static void tdk_write(struct qemu_phy *phy, unsigned int req, unsigned int data) } } -void tdk_init(struct qemu_phy *phy) +void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, uint16_t id2) { phy->regs[PHY_CTRL] = 0x3100; /* PHY Id. */ - phy->regs[PHY_ID1] = 0x0300; - phy->regs[PHY_ID2] = 0xe400; + phy->regs[PHY_ID1] = id1; + phy->regs[PHY_ID2] = id2; /* Autonegotiation advertisement reg. */ phy->regs[PHY_AUTONEG_ADV] = 0x01e1; phy->link = 1; - phy->read = tdk_read; - phy->write = tdk_write; + phy->read = mdio_phy_read; + phy->write = mdio_phy_write; } void mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy, unsigned int addr) diff --git a/hw/mdio.h b/hw/mdio.h index 0ba92cd..427c9ed 100644 --- a/hw/mdio.h +++ b/hw/mdio.h @@ -88,7 +88,7 @@ struct qemu_mdio { struct qemu_phy *devs[32]; }; -void tdk_init(struct qemu_phy *phy); +void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, uint16_t id2); void mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy, unsigned int addr); uint16_t mdio_read_req(struct qemu_mdio *bus, uint8_t addr, uint8_t req); diff --git a/hw/xilinx_axienet.c b/hw/xilinx_axienet.c index ff09510..d501dbd 100644 --- a/hw/xilinx_axienet.c +++ b/hw/xilinx_axienet.c @@ -677,7 +677,7 @@ static int xilinx_enet_init(SysBusDevice *dev) object_get_typename(OBJECT(dev)), dev->qdev.id, s); qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); - tdk_init(&s->TEMAC.phy); + mdio_phy_init(&s->TEMAC.phy, 0x0300, 0xe400); mdio_attach(&s->TEMAC.mdio_bus, &s->TEMAC.phy, s->c_phyaddr); s->TEMAC.parent = s;