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: 10488625 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 17219602B3 for ; Tue, 26 Jun 2018 10:25:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C92826E38 for ; Tue, 26 Jun 2018 10:25:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0143E28606; Tue, 26 Jun 2018 10:25:25 +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 9A72526E38 for ; Tue, 26 Jun 2018 10:25:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934749AbeFZKXb (ORCPT ); Tue, 26 Jun 2018 06:23:31 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:36908 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934769AbeFZKXY (ORCPT ); Tue, 26 Jun 2018 06:23:24 -0400 Received: by mail-wr0-f193.google.com with SMTP id k6-v6so16661802wrp.4 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=nXKhNhXR8svQnzZ/4uuULXvjYfU9sJwwnTQOh3vUqKMnatgYGd+x0q0XG9OMEBx0ld DSyI+V+lx5DHZ3hKJc5nCdcnnNFbpDrf0/t/9F0gCRqB5vwZJnjqW1cc35YYMZ3eIW4m qpStawStvs2qNoDTa+J0ahZ+/g5+CyBP2IyjTw/8EZCWLZ0P0m3TzIgjTepdGmmCRuKG aUt/F8RO+209EPnOe5babZJN31tdwkzifjStFSpILGpdnKbNJQ8szpERbG4ZAAs9QXtg T1qxrSmlra8WtiTHhv7hJmMhQxT0o3Jih0W8Ypo1IoOdV2QkPjC8iOdVKa+/usQccTaa uX3Q== X-Gm-Message-State: APt69E1h+Cch6NaVSYyiostl+B+OCGaIfx+ZSoxFram0d74ueWV750LD xmx39BIGu19c3AkAUnC078isog== 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 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 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> 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, 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;