From patchwork Fri Jun 29 09:40:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10495967 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 D841D6016C for ; Fri, 29 Jun 2018 09:41:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C164829708 for ; Fri, 29 Jun 2018 09:41:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B53CD29779; Fri, 29 Jun 2018 09:41:48 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5091429708 for ; Fri, 29 Jun 2018 09:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935802AbeF2JlJ (ORCPT ); Fri, 29 Jun 2018 05:41:09 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:38821 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935715AbeF2Jk6 (ORCPT ); Fri, 29 Jun 2018 05:40:58 -0400 Received: by mail-wr0-f196.google.com with SMTP id w16-v6so465357wrn.5 for ; Fri, 29 Jun 2018 02:40:58 -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=hsENybKG2M2NmdzWNb8guNW4ZYSvpwsjSUupTY9rPg0=; b=uMyVrEREEXe6AHnH4t3GsFxlQAZVfHlAkS/pUAPhPyhTWgUEPVMMDKE9mIfNbGum+n 4ci6E+9sxf6uBmheoJKteTLgSvUPbH1xbH3YCp2duPIrpILHIvMW8ysLlRga+EufhR5e /dDO1Sw079TUNVw01veLAemiVMEYFyfdN3GF1DPnDyQLop3Mg+fx9rrAI4q0pCpAaARo IPkVXBxxfDfwcyyM2e5ieiNcH+oscKgXVkjIZOjpJTTjPQ4ecHsDp5rOAb7Q4SnU2zoP DOqdMrkQ40pDhx2XlUTeClUgPgBvPQShu3kUKp38UEQihyHLq4i50bdcbELc8yloRJDB O+Qg== 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=hsENybKG2M2NmdzWNb8guNW4ZYSvpwsjSUupTY9rPg0=; b=NSUFU40eap3bkwnZ8t7ReChiM8HdK+lHozpN0RmnuF8wXGYIoFA8UrfUNHaYyBYjOb rmKT8ecU+p3FYFefN320bzEZfj6fpQoBwH7LA4+SidweF2iV4kt9nxh6geryBLu3xBFf p9kwsJLHxerqr0YQrFxmuMWh+/ZSY/lg8M/h6i0G/LLkqSZs2UikG1hL7Bpsr4LZ7BIm TPNFXYhgoGtmRY93abq0VTU3rtgNm2Q7bkoTEwi/iwrPceqpMcr01erjlR7YnygNVbG9 q/2nLu3OG1I3wpHFNwFZluBRZs4wgEbsq4C5HbZmdaN1GAPWM7yxkDr10xy+2QkMG2nq OhcA== X-Gm-Message-State: APt69E0UaPJzxaXgqPXgZ0aaEBiFv4FzmSsXinx39MDIKeWDFoaYiLSl qZVtCT5Kss6jTKw/N4xM+cCKOA== X-Google-Smtp-Source: AAOMgpcENGOBuHt5Befq9QsZygoVpxBr85bXf50QQLN9ueTuI9gkiLWod/DiCykSnHfHMsjrEKDOMQ== X-Received: by 2002:adf:8546:: with SMTP id 64-v6mr11081081wrh.223.1530265257456; Fri, 29 Jun 2018 02:40:57 -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 d102-v6sm1386394wma.10.2018.06.29.02.40.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Jun 2018 02:40:56 -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 , Jonathan Corbet Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, netdev@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 10/18] net: davinci_emac: use nvmem to retrieve the mac address Date: Fri, 29 Jun 2018 11:40:31 +0200 Message-Id: <20180629094039.7543-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180629094039.7543-1-brgl@bgdev.pl> References: <20180629094039.7543-1-brgl@bgdev.pl> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.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 | 35 +++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c index 48e6a7755811..ea303e1f7916 100644 --- a/drivers/net/ethernet/ti/davinci_emac.c +++ b/drivers/net/ethernet/ti/davinci_emac.c @@ -68,6 +68,8 @@ #include #include #include +#include +#include #include #include @@ -1696,7 +1698,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 +1709,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,10 +1778,12 @@ static int davinci_emac_probe(struct platform_device *pdev) struct cpdma_params dma_params; struct clk *emac_clk; unsigned long emac_bus_frequency; -#ifdef CONFIG_MTD + const void *mac_addr; size_t mac_addr_len; +#ifdef CONFIG_MTD struct mtd_info *mtd; #endif /* CONFIG_MTD */ + struct nvmem_cell *cell; /* obtain emac clock from kernel */ emac_clk = devm_clk_get(&pdev->dev, NULL); @@ -1831,8 +1828,28 @@ static int davinci_emac_probe(struct platform_device *pdev) } #endif /* CONFIG_MTD */ + cell = nvmem_cell_get(&pdev->dev, "mac-address"); + if (IS_ERR(cell) && PTR_ERR(cell) == -EPROBE_DEFER) { + return -EPROBE_DEFER; + } else 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;