From patchwork Tue Jun 26 10:22:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10488705 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B2E6A601A0 for ; Tue, 26 Jun 2018 10:32:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BE162874A for ; Tue, 26 Jun 2018 10:32:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FFEE28878; Tue, 26 Jun 2018 10:32:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 352DE2874A for ; Tue, 26 Jun 2018 10:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=rQV9i9pqp1LP95k31HOqWHQsezGgFqWCThHAIN7/hsk=; b=cJ7nHYhTUYJXmXXoZgkk0ewBII mGfKb7ZDpsGWvVB5o4WuwGORfuKrTxbxPv+WWQMKitR1Q7BuHxtLn9OlqoNnaDOUHynsfCoGto0Kx DUvFyOIanET045lfoasXghWd4MDXK8wifWLfztAM0z7SZFOrpHgXnv1IilCnrJ+t9nTQnuT7ZLWKX 2hwdP76NfjYmkLOO2E8lh2uZTK4lMFCkBN+lD1bDnrUsJXi93fCwCDGvjj07d5LYLQmsM4CSpQmv+ Ch2IPPNHPeIeybNGHffzDq52rPRkxgd6DImLZOYfiALAuv9Ikw+UlwtpP+tNU1/A2Vnbr8Q8ARMGT bgrYGbDA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fXlH7-0001OT-Cc; Tue, 26 Jun 2018 10:32:41 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fXl8D-0001wA-NE for linux-arm-kernel@lists.infradead.org; Tue, 26 Jun 2018 10:23:34 +0000 Received: by mail-wr0-x241.google.com with SMTP id a12-v6so16682512wro.1 for ; Tue, 26 Jun 2018 03:23:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8THROwGSGnXk0hxHJP7Nf3jSGvqc/RQbpn6H4owB8co=; b=aGsMNjy08uHjD4ofvmWtbY1E6u2AQOk76ycLsIrEaZIshKVxIGeebxZ5N/PxsDRwUZ 3MuIPfKAa7aRmWEi76HxdWwo7qGesRHyJLwDjBJb9gl2iTdQw1MX8WTvlmpFTPYIZg5A Nl0xzsfWM86wXA86ocjUfEVU88Rt6B4eJ0cncpPVeKVk1Wz2CsEDR/ddGVFqlgDN2rFY Uk5fnZ3Z0j7EsSswYbCt8LBklU+YJyGVbZzF3EY8V5xSFBo6R0Md0vKFSiSWV5DAIxyy 5XlVPFl4M8b0SEnbekTnsgGkwAOpF9G1ToDcVNJdqLSV2T8yGDepZ+u4eRJTifcm7dpB pSPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8THROwGSGnXk0hxHJP7Nf3jSGvqc/RQbpn6H4owB8co=; b=f0vB3rE33u5XKrurTtY/CXgdkk4hmHqOH3Ixtc/rbF+jJTPgjaTNYLSqTASf+ucyR0 aveTGumyIOZ4hg7m9gn2nPZYwKyguENURPH8Z7rTK26d/0dfS85D/ghmPIAZBfK29Dj/ Y18LLeM8mC7STgfp9lHo5n/0lC+3+ksjjBSjM4ZEOydqasti9jJ4hErUeGu6MfvLRFn0 tBhWWuUUzCinOHR39rUnTV2eVcj9fJ3fBM+exhSCovktIjwETY6/lv0iSsyA//OG0GLy MnocftEMjZLnNb6V5w1p6lRb6OkuCeSJe/k1X/GdJVFxqfSH5rWH59Ffxgc/cJGfrmaK Vf4A== X-Gm-Message-State: APt69E3yg33nmwuWiG5Auck1N8gyrALqxZjJYMNdNAjZBGjXjSryEI9w p0ySln1OiXQg8wDjtpl1EDjPuQ== X-Google-Smtp-Source: AAOMgpdVYc+IqN4X9kgs8dpvGni7fx/bjOfkd2kLBmertfyyFHwPcsNmIDG96JwGY+M8nzGkVNUTgw== X-Received: by 2002:adf:fed2:: with SMTP id q18-v6mr960764wrs.165.1530008603619; Tue, 26 Jun 2018 03:23:23 -0700 (PDT) Received: from brgl-bgdev.lan (LFbn-NIC-1-55-10.w2-15.abo.wanadoo.fr. [2.15.147.10]) by smtp.gmail.com with ESMTPSA id 203-v6sm2573852wmp.23.2018.06.26.03.23.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 03:23:22 -0700 (PDT) From: Bartosz Golaszewski To: Sekhar Nori , Kevin Hilman , Russell King , Grygorii Strashko , "David S . Miller" , Srinivas Kandagatla , Lukas Wunner , Rob Herring , Florian Fainelli , Dan Carpenter , Ivan Khoronzhuk , David Lechner , Greg Kroah-Hartman , Andrew Lunn Subject: [PATCH v2 07/15] net: davinci_emac: use nvmem to retrieve the mac address Date: Tue, 26 Jun 2018 12:22:37 +0200 Message-Id: <20180626102245.30711-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180626102245.30711-1-brgl@bgdev.pl> References: <20180626102245.30711-1-brgl@bgdev.pl> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180626_032329_799452_7A0E3E8E X-CRM114-Status: GOOD ( 16.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Bartosz Golaszewski MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Bartosz Golaszewski All users which store the MAC address in EEPROM now register relevant nvmem cells. Switch to retrieving the MAC address over the nvmem framework. If we can't get the nvmem cell then fall back to using the device tree. Signed-off-by: Bartosz Golaszewski --- drivers/net/ethernet/ti/davinci_emac.c | 33 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c index a1a6445b5a7e..48b70bc7b9cf 100644 --- a/drivers/net/ethernet/ti/davinci_emac.c +++ b/drivers/net/ethernet/ti/davinci_emac.c @@ -67,7 +67,7 @@ #include #include #include - +#include #include #include @@ -1696,7 +1696,6 @@ davinci_emac_of_get_pdata(struct platform_device *pdev, struct emac_priv *priv) const struct of_device_id *match; const struct emac_platform_data *auxdata; struct emac_platform_data *pdata = NULL; - const u8 *mac_addr; if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) return dev_get_platdata(&pdev->dev); @@ -1708,12 +1707,6 @@ davinci_emac_of_get_pdata(struct platform_device *pdev, struct emac_priv *priv) np = pdev->dev.of_node; pdata->version = EMAC_VERSION_2; - if (!is_valid_ether_addr(pdata->mac_addr)) { - mac_addr = of_get_mac_address(np); - if (mac_addr) - ether_addr_copy(pdata->mac_addr, mac_addr); - } - of_property_read_u32(np, "ti,davinci-ctrl-reg-offset", &pdata->ctrl_reg_offset); @@ -1783,7 +1776,9 @@ static int davinci_emac_probe(struct platform_device *pdev) struct cpdma_params dma_params; struct clk *emac_clk; unsigned long emac_bus_frequency; - + struct nvmem_cell *cell; + const void *mac_addr; + size_t mac_addr_len; /* obtain emac clock from kernel */ emac_clk = devm_clk_get(&pdev->dev, NULL); @@ -1815,8 +1810,26 @@ static int davinci_emac_probe(struct platform_device *pdev) goto err_free_netdev; } + cell = nvmem_cell_get(&pdev->dev, "mac-address"); + if (!IS_ERR(cell)) { + mac_addr = nvmem_cell_read(cell, &mac_addr_len); + if (!IS_ERR(mac_addr)) { + if (is_valid_ether_addr(mac_addr)) { + dev_info(&pdev->dev, + "Read MAC addr from EEPROM: %pM\n", + mac_addr); + ether_addr_copy(priv->mac_addr, mac_addr); + } + kfree(mac_addr); + } + nvmem_cell_put(cell); + } else { + mac_addr = of_get_mac_address(np); + if (mac_addr) + ether_addr_copy(priv->mac_addr, mac_addr); + } + /* MAC addr and PHY mask , RMII enable info from platform_data */ - memcpy(priv->mac_addr, pdata->mac_addr, ETH_ALEN); priv->phy_id = pdata->phy_id; priv->rmii_en = pdata->rmii_en; priv->version = pdata->version;