linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Erik Stromdahl <erik.stromdahl@gmail.com>
To: kvalo@qca.qualcomm.com, linux-wireless@vger.kernel.org,
	ath10k@lists.infradead.org
Cc: Erik Stromdahl <erik.stromdahl@gmail.com>
Subject: [RFC 06/12] ath10k: bmi: Added SOC reg read/write functions
Date: Mon, 14 Nov 2016 17:33:36 +0100	[thread overview]
Message-ID: <1479141222-8493-7-git-send-email-erik.stromdahl@gmail.com> (raw)
In-Reply-To: <1479141222-8493-1-git-send-email-erik.stromdahl@gmail.com>

Added functions implementing the following BMI commands:

BMI_READ_SOC_REGISTER
BMI_WRITE_SOC_REGISTER

Reading and writing BMI registers is sometimes needed for
SDIO chipsets.

Signed-off-by: Erik Stromdahl <erik.stromdahl@gmail.com>
---
 drivers/net/wireless/ath/ath10k/bmi.c |   79 ++++++++++++++++++++++++++++++++-
 drivers/net/wireless/ath/ath10k/bmi.h |    4 ++
 2 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ath/ath10k/bmi.c b/drivers/net/wireless/ath/ath10k/bmi.c
index 2872d34..1c378a2 100644
--- a/drivers/net/wireless/ath/ath10k/bmi.c
+++ b/drivers/net/wireless/ath/ath10k/bmi.c
@@ -97,7 +97,8 @@ int ath10k_bmi_read_memory(struct ath10k *ar,
 	u32 rxlen;
 	int ret;
 
-	ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi read address 0x%x length %d\n",
+	ath10k_dbg(ar, ATH10K_DBG_BMI,
+		   "bmi read memory address 0x%x length %d\n",
 		   address, length);
 
 	if (ar->bmi.done_sent) {
@@ -137,7 +138,8 @@ int ath10k_bmi_write_memory(struct ath10k *ar,
 	u32 txlen;
 	int ret;
 
-	ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi write address 0x%x length %d\n",
+	ath10k_dbg(ar, ATH10K_DBG_BMI,
+		   "bmi write memory address 0x%x length %d\n",
 		   address, length);
 
 	if (ar->bmi.done_sent) {
@@ -175,6 +177,79 @@ int ath10k_bmi_write_memory(struct ath10k *ar,
 	return 0;
 }
 
+int ath10k_bmi_read_soc_reg(struct ath10k *ar,
+			    u32 address, u32 *regval)
+{
+	struct bmi_cmd cmd;
+	union bmi_resp resp;
+	u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.read_soc_reg);
+	u32 rxlen;
+	int ret;
+
+	ath10k_dbg(ar, ATH10K_DBG_BMI,
+		   "bmi read SOC register address 0x%x\n",
+		   address);
+
+	if (ar->bmi.done_sent) {
+		ath10k_warn(ar, "command disallowed\n");
+		return -EBUSY;
+	}
+
+	rxlen = sizeof(resp.read_soc_reg.value);
+
+	cmd.id                = __cpu_to_le32(BMI_READ_SOC_REGISTER);
+	cmd.read_soc_reg.addr = __cpu_to_le32(address);
+
+	ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, cmdlen,
+					  &resp, &rxlen);
+	if (ret) {
+		ath10k_warn(ar, "unable to read from the device (%d)\n",
+			    ret);
+		return ret;
+	}
+
+	if (rxlen != sizeof(resp.read_soc_reg.value)) {
+		ath10k_warn(ar, "Unexpected read len: %u (expected %u)\n",
+			    rxlen, sizeof(resp.read_soc_reg.value));
+		return ret;
+	}
+
+	*regval = __le32_to_cpu(resp.read_soc_reg.value);
+
+	return 0;
+}
+
+int ath10k_bmi_write_soc_reg(struct ath10k *ar,
+			     u32 address, u32 regval)
+{
+	struct bmi_cmd cmd;
+	u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.write_soc_reg);
+	int ret;
+
+	ath10k_dbg(ar, ATH10K_DBG_BMI,
+		   "bmi write SOC register address 0x%x\n",
+		   address);
+
+	if (ar->bmi.done_sent) {
+		ath10k_warn(ar, "command disallowed\n");
+		return -EBUSY;
+	}
+
+	cmd.id                  = __cpu_to_le32(BMI_WRITE_SOC_REGISTER);
+	cmd.write_soc_reg.addr  = __cpu_to_le32(address);
+	cmd.write_soc_reg.value = __cpu_to_le32(regval);
+
+	ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, cmdlen,
+					  NULL, NULL);
+	if (ret) {
+		ath10k_warn(ar, "unable to write to the device (%d)\n",
+			    ret);
+		return ret;
+	}
+
+	return 0;
+}
+
 int ath10k_bmi_execute(struct ath10k *ar, u32 address, u32 param, u32 *result)
 {
 	struct bmi_cmd cmd;
diff --git a/drivers/net/wireless/ath/ath10k/bmi.h b/drivers/net/wireless/ath/ath10k/bmi.h
index 7d3231a..a867867 100644
--- a/drivers/net/wireless/ath/ath10k/bmi.h
+++ b/drivers/net/wireless/ath/ath10k/bmi.h
@@ -201,6 +201,10 @@ int ath10k_bmi_read_memory(struct ath10k *ar, u32 address,
 			   void *buffer, u32 length);
 int ath10k_bmi_write_memory(struct ath10k *ar, u32 address,
 			    const void *buffer, u32 length);
+int ath10k_bmi_read_soc_reg(struct ath10k *ar,
+			    u32 address, u32 *regval);
+int ath10k_bmi_write_soc_reg(struct ath10k *ar,
+			     u32 address, u32 regval);
 
 #define ath10k_bmi_read32(ar, item, val)				\
 	({								\
-- 
1.7.9.5

  parent reply	other threads:[~2016-11-14 16:35 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-14 16:33 [RFC 00/12] ath10k sdio support Erik Stromdahl
2016-11-14 16:33 ` [RFC 01/12] ath10k: htc: made static function public Erik Stromdahl
2016-11-14 16:33 ` [RFC 02/12] ath10k: htc: rx trailer lookahead support Erik Stromdahl
2016-11-15  9:57   ` Michal Kazior
2016-11-15 17:31     ` Erik Stromdahl
2016-11-16 13:53       ` Valo, Kalle
2016-11-14 16:33 ` [RFC 03/12] ath10k: htc: Changed order of wait target and ep connect Erik Stromdahl
2016-11-15 10:13   ` Michal Kazior
2016-11-15 17:07     ` Erik Stromdahl
2016-11-16 14:29       ` Michal Kazior
2016-11-14 16:33 ` [RFC 04/12] ath10k: htc: refactorization Erik Stromdahl
2016-11-15 10:19   ` Michal Kazior
2016-11-17 16:32     ` Erik Stromdahl
2016-11-18 14:49       ` Michal Kazior
2016-11-14 16:33 ` [RFC 05/12] ath10k: htc: Added ATH10K_HTC_FLAG_BUNDLE_LSB Erik Stromdahl
2016-11-15 10:25   ` Michal Kazior
2016-11-15 10:46     ` Valo, Kalle
2016-11-14 16:33 ` Erik Stromdahl [this message]
2016-11-15 10:28   ` [RFC 06/12] ath10k: bmi: Added SOC reg read/write functions Michal Kazior
2016-11-15 17:11     ` Erik Stromdahl
2016-11-14 16:33 ` [RFC 07/12] ath10k: Added SDIO dbg masks Erik Stromdahl
2016-11-14 16:33 ` [RFC 08/12] ath10k: Added ATH10K_BUS_SDIO enum Erik Stromdahl
2016-11-14 16:33 ` [RFC 09/12] ath10k: Mailbox address definitions Erik Stromdahl
2016-11-15 10:31   ` Michal Kazior
2016-11-15 10:48     ` Valo, Kalle
2016-11-14 16:33 ` [RFC 10/12] ath10k: Added QCA65XX hw definition Erik Stromdahl
2016-11-15 10:34   ` Michal Kazior
2016-11-15 10:54     ` Valo, Kalle
2016-11-15 18:34       ` Erik Stromdahl
2016-11-14 16:33 ` [RFC 11/12] ath10k: Added more host_interest members Erik Stromdahl
2016-11-14 16:33 ` [RFC 12/12] ath10k: Added sdio support Erik Stromdahl

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=1479141222-8493-7-git-send-email-erik.stromdahl@gmail.com \
    --to=erik.stromdahl@gmail.com \
    --cc=ath10k@lists.infradead.org \
    --cc=kvalo@qca.qualcomm.com \
    --cc=linux-wireless@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).