Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0D48C2B9F4 for ; Mon, 28 Jun 2021 13:31:38 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5DC6161C3D for ; Mon, 28 Jun 2021 13:31:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5DC6161C3D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8387C82DE8; Mon, 28 Jun 2021 15:31:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 0929B82DC9; Mon, 28 Jun 2021 15:31:17 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id E171F82DC1 for ; Mon, 28 Jun 2021 15:31:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2A1AF1042; Mon, 28 Jun 2021 06:31:11 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 489203F718; Mon, 28 Jun 2021 06:31:10 -0700 (PDT) From: Andre Przywara To: Joe Hershberger , Ramon Fried Cc: u-boot@lists.denx.de, Marek Vasut Subject: [PATCH 2/2] net: smc911x: Determine bus width at runtime Date: Mon, 28 Jun 2021 14:30:31 +0100 Message-Id: <20210628133031.17765-3-andre.przywara@arm.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20210628133031.17765-1-andre.przywara@arm.com> References: <20210628133031.17765-1-andre.przywara@arm.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean The SMC911x Ethernet MACs can be integrated using a 16 or 32-bit bus. The driver needs to know about this choice, which is the reason for us having a Kconfig symbol for that. Now this bus width is already described using a devicetree property, and since the driver is DM compliant and is using the DT now, we should query this at runtime. We leave the Kconfig choice around, in case the DT is missing this property. Signed-off-by: Andre Przywara --- drivers/net/smc911x.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c index d596d96f4b3..3afebee4402 100644 --- a/drivers/net/smc911x.c +++ b/drivers/net/smc911x.c @@ -28,6 +28,7 @@ struct smc911x_priv { phys_addr_t iobase; const struct chip_id *chipid; unsigned char enetaddr[6]; + bool use_32_bit_io; }; static const struct chip_id chip_ids[] = { @@ -48,28 +49,24 @@ static const struct chip_id chip_ids[] = { #define DRIVERNAME "smc911x" -#if defined (CONFIG_SMC911X_32_BIT) static u32 smc911x_reg_read(struct smc911x_priv *priv, u32 offset) { - return readl(priv->iobase + offset); -} + if (priv->use_32_bit_io) + return readl(priv->iobase + offset); -static void smc911x_reg_write(struct smc911x_priv *priv, u32 offset, u32 val) -{ - writel(val, priv->iobase + offset); -} -#else -static u32 smc911x_reg_read(struct smc911x_priv *priv, u32 offset) -{ return (readw(priv->iobase + offset) & 0xffff) | (readw(priv->iobase + offset + 2) << 16); } + static void smc911x_reg_write(struct smc911x_priv *priv, u32 offset, u32 val) { - writew(val & 0xffff, priv->iobase + offset); - writew(val >> 16, priv->iobase + offset + 2); + if (priv->use_32_bit_io) { + writel(val, priv->iobase + offset); + } else { + writew(val & 0xffff, priv->iobase + offset); + writew(val >> 16, priv->iobase + offset + 2); + } } -#endif /* CONFIG_SMC911X_32_BIT */ static u32 smc911x_get_mac_csr(struct smc911x_priv *priv, u8 reg) { @@ -493,6 +490,8 @@ int smc911x_initialize(u8 dev_num, int base_addr) priv->iobase = base_addr; priv->dev.iobase = base_addr; + priv->use_32_bit_io = CONFIG_IS_ENABLED(SMC911X_32_BIT); + /* Try to detect chip. Will fail if not present. */ ret = smc911x_detect_chip(priv); if (ret) { @@ -603,10 +602,18 @@ static int smc911x_of_to_plat(struct udevice *dev) { struct smc911x_priv *priv = dev_get_priv(dev); struct eth_pdata *pdata = dev_get_plat(dev); + u32 io_width; + int ret; pdata->iobase = dev_read_addr(dev); priv->iobase = pdata->iobase; + ret = dev_read_u32(dev, "reg-io-width", &io_width); + if (!ret) + priv->use_32_bit_io = (io_width == 4); + else + priv->use_32_bit_io = CONFIG_IS_ENABLED(SMC911X_32_BIT); + return 0; } -- 2.17.5