linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alban <albeu@free.fr>
To: QCA ath9k Development <ath9k-devel@qca.qualcomm.com>
Cc: John Crispin <john@phrozen.org>, Alban <albeu@free.fr>,
	Kalle Valo <kvalo@codeaurora.org>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 4/7] ath9k: Add support for reading the MAC address with nvmem
Date: Mon, 13 Mar 2017 22:05:12 +0100	[thread overview]
Message-ID: <1489439116-4233-4-git-send-email-albeu@free.fr> (raw)
In-Reply-To: <1489439116-4233-1-git-send-email-albeu@free.fr>

On embedded platforms the MAC address is often stored in flash,
use nvmem to read it if the platform data or DT didn't specify one.

Signed-off-by: Alban <albeu@free.fr>
---
 drivers/net/wireless/ath/ath9k/init.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index 054f254..36b51a5 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -594,6 +594,35 @@ static int ath9k_of_init(struct ath_softc *sc)
 	return 0;
 }
 
+static int ath9k_get_nvmem_address(struct ath_softc *sc)
+{
+	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
+	struct nvmem_cell *cell;
+	size_t cell_size;
+	int err = 0;
+	void *mac;
+
+	cell = nvmem_cell_get(sc->dev, "address");
+	if (IS_ERR(cell))
+		return PTR_ERR(cell);
+
+	mac = nvmem_cell_read(cell, &cell_size);
+	nvmem_cell_put(cell);
+
+	if (IS_ERR(mac))
+		return PTR_ERR(mac);
+
+	if (cell_size == 6) {
+		ether_addr_copy(common->macaddr, mac);
+	} else {
+		dev_err(sc->dev, "nvmem 'address' cell has invalid size\n");
+		err = -EINVAL;
+	}
+
+	kfree(mac);
+	return err;
+}
+
 static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
 			    const struct ath_bus_ops *bus_ops)
 {
@@ -656,6 +685,10 @@ static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
 	if (ret)
 		return ret;
 
+	/* If no MAC address has been set yet try to use nvmem */
+	if (!is_valid_ether_addr(common->macaddr))
+		ath9k_get_nvmem_address(sc);
+
 	/* If the EEPROM hasn't been retrieved via firmware request
 	 * use the nvmem API insted.
 	 */
-- 
2.7.4

  parent reply	other threads:[~2017-03-13 21:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-13 21:05 [PATCH 1/7] Documentation: dt: net: Update the ath9k binding for SoC devices Alban
2017-03-13 21:05 ` [PATCH 2/7] ath9k: ahb: Add OF support Alban
2017-03-14 11:17   ` Sergei Shtylyov
2017-03-13 21:05 ` [PATCH 3/7] ath9k: Add support for reading the EEPROM data using the nvmem API Alban
2017-03-13 22:17   ` Rafał Miłecki
2017-03-13 23:53   ` Christian Lamparter
2017-03-23 14:43     ` Alban
2017-03-24 16:24       ` Christian Lamparter
2017-03-13 21:05 ` Alban [this message]
2017-03-13 21:05 ` [PATCH 5/7] ath9k: of: Use the clk API to get the reference clock rate Alban
2017-03-13 22:17   ` Rafał Miłecki
2017-03-13 21:05 ` [PATCH 6/7] ath9k: Allow using the reset API for the external reset Alban
2017-03-13 21:05 ` [PATCH 7/7] ath9k: hw: Reset the device with the external reset before init Alban
2017-03-20 22:06 ` [PATCH 1/7] Documentation: dt: net: Update the ath9k binding for SoC devices Rob Herring
2017-03-27 16:11 ` Christian Lamparter
2017-03-28  8:44   ` Alban
2017-03-28 14:53     ` Christian Lamparter
2017-03-28 15:18       ` Andrew Lunn
2017-03-28 16:21         ` Christian Lamparter
2017-03-28 16:41           ` Andrew Lunn
2017-03-28 17:09             ` Christian Lamparter
2017-04-05 10:09 ` Kalle Valo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1489439116-4233-4-git-send-email-albeu@free.fr \
    --to=albeu@free.fr \
    --cc=ath9k-devel@qca.qualcomm.com \
    --cc=john@phrozen.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).