From patchwork Thu Jun 28 14:32:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10494129 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 6F2A560230 for ; Thu, 28 Jun 2018 14:37:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 562D32A09A for ; Thu, 28 Jun 2018 14:37:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4820D2A0BB; Thu, 28 Jun 2018 14:37:39 +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 D36B92A09A for ; Thu, 28 Jun 2018 14:37:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966683AbeF1OhW (ORCPT ); Thu, 28 Jun 2018 10:37:22 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:42285 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966675AbeF1OdW (ORCPT ); Thu, 28 Jun 2018 10:33:22 -0400 Received: by mail-wr0-f193.google.com with SMTP id p1-v6so5765309wrs.9 for ; Thu, 28 Jun 2018 07:33:22 -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=Rf2gDpQel0CMmPIbPeaqaroqdpvX5xTV2oFTJ5rX1D8=; b=DBmKp7WS70ZAcJ59cbevilxx46PglUqRS/aPjd4ZNLfzDIC9My3cDKDLvV6r4ugN1z lxestNBb0zM5pb7E5q+nwDzavY8rKeT0gdBt8C3gFL4mB5Ly3YQ+DL9gU2uWXr03ER6S AZ/NUU9HnAZiR4c9mwaXTHWEFIme7RiTWJtGXeBpYOtmttHzeLD+qftMhf0AfGRbwdSs VVWmggehyHXfecAPcmnw+R3wIyLEOleFEqnw55xrSgQCQafPvQ8ECAK3iz+Bj0maujH3 2XbFFa6KpXwt4nkaU4WFNy1uT7MgMzPcIX89xFFQ36hENeofnFxQhIzlR//E+1CdHjb4 D2eg== 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=Rf2gDpQel0CMmPIbPeaqaroqdpvX5xTV2oFTJ5rX1D8=; b=aa+ll1uPyQXDHKyn+2OmOwZM8IAUN00NgMA9HxE3ZFSCcWf/TK46mHHoc7E4tLuHA/ 1m4fllQhbKuziSmb/zSuVBrC97JtsZMcqHMH/0h3Ek2+uI7yG05Bs/RTCfBxUiil998O Crx6A8Nlcxzi2H6U2jgCCKKTmWFxkAHsnyb+UqtjGhlN/4ozy0BrfU4G6ncgK5XJwzBP gqWT41sGkEc56BvRkCJOoYHItjCkEXdl7pOZnZsRHJr/3yEF3czorG8V6jXsMjN5rxbN WcAUIpwB1lPceif65ajXmI8OvHP62StsDd6LGk5uwqiYK1KNXkqK/fnmMc2VoSiKbplW 9qZg== X-Gm-Message-State: APt69E0R9fTXMkX7GmdpyD5HxhkL4bgT0l8G+iSPBVXo4Ou3rMmdh+nG mdRJnp8cfSzlRVnLXd5GcbktLw== X-Google-Smtp-Source: AAOMgpdt/pmFO6zWyJvUOuG4pzS0cmpi/7xFMqe28s+6lg7bl5bjOF41n6J0Ak2QrpNrcC0I+rEohw== X-Received: by 2002:a5d:41c5:: with SMTP id e5-v6mr8904508wrq.25.1530196401660; Thu, 28 Jun 2018 07:33:21 -0700 (PDT) Received: from brgl-bgdev.baylibre.local (AStLambert-681-1-87-41.w90-86.abo.wanadoo.fr. [90.86.29.41]) by smtp.gmail.com with ESMTPSA id 4-v6sm8037499wmh.14.2018.06.28.07.33.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 07:33:21 -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 v3 10/18] net: davinci_emac: use nvmem to retrieve the mac address Date: Thu, 28 Jun 2018 16:32:36 +0200 Message-Id: <20180628143244.4561-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180628143244.4561-1-brgl@bgdev.pl> References: <20180628143244.4561-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 | 33 +++++++++++++++++++------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c index 17cfe093b8cf..7608169e643f 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); @@ -1830,8 +1827,26 @@ static int davinci_emac_probe(struct platform_device *pdev) } #endif /* CONFIG_MTD */ + 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;