All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harish Bandi <c-hbandi@codeaurora.org>
To: marcel@holtmann.org, johan.hedberg@gmail.com
Cc: mka@chromium.org, linux-kernel@vger.kernel.org,
	linux-bluetooth@vger.kernel.org, hemantg@codeaurora.org,
	linux-arm-msm@vger.kernel.org, bgodavar@codeaurora.org,
	anubhavg@codeaurora.org, Harish Bandi <c-hbandi@codeaurora.org>
Subject: [PATCH v1 1/2] Bluetooth: hci_qca: Added support to read the regulator values from DTS
Date: Thu,  7 Mar 2019 17:46:51 +0530	[thread overview]
Message-ID: <1551961012-23898-2-git-send-email-c-hbandi@codeaurora.org> (raw)
In-Reply-To: <1551961012-23898-1-git-send-email-c-hbandi@codeaurora.org>

wcn3990 as base chip. based on wcn3990 we have multiple bt chip sets,
with enhanced power numbers. So every chip set will have
its own power numbers, but the functionality is same as wcn3990.
With this change we read the regulator values from DTS in driver
initialization time. While initializing the regulators, it will
set the those current and voltage values. If no values set in DTS,
it will read the default values and set those values only.
This change will help in supporting multiple platforms.

Signed-off-by: Harish Bandi <c-hbandi@codeaurora.org>
---
 drivers/bluetooth/hci_qca.c | 76 ++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 68 insertions(+), 8 deletions(-)

diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index 237aea3..402336a7 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -155,7 +155,7 @@ struct qca_vreg_data {
  */
 struct qca_power {
 	struct device *dev;
-	const struct qca_vreg_data *vreg_data;
+	struct qca_vreg_data *vreg_data;
 	struct regulator_bulk_data *vreg_bulk;
 	bool vregs_on;
 };
@@ -1387,10 +1387,48 @@ static int qca_power_setup(struct hci_uart *hu, bool on)
 	return ret;
 }
 
+/*
+ * Read function to get the voltage and current values
+ * for regulators from DTS.
+ */
+static void qca_regulator_get_voltage_current(struct device *dev,
+				      struct qca_vreg *vregs)
+{
+	char prop_name[32]; /* 32 is max size of property name */
+
+	snprintf(prop_name, 32, "%s-current", vregs->name);
+	BT_DBG("Looking up %s from device tree\n", prop_name);
+
+	if (device_property_read_bool(dev, prop_name))
+		device_property_read_u32(dev, prop_name, &vregs->load_uA);
+
+	snprintf(prop_name, 32, "%s-min-voltage", vregs->name);
+	BT_DBG("Looking up %s from device tree\n", prop_name);
+
+	if (device_property_read_bool(dev, prop_name))
+		device_property_read_u32(dev, prop_name, &vregs->min_uV);
+
+	snprintf(prop_name, 32, "%s-max-voltage", vregs->name);
+	BT_DBG("Looking up %s from device tree\n", prop_name);
+
+	if (device_property_read_bool(dev, prop_name))
+		device_property_read_u32(dev, prop_name, &vregs->max_uV);
+
+	BT_DBG("current %duA selected for regulator %s", vregs->load_uA,
+		vregs->name);
+	BT_DBG("min voltage %duA selected for regulator %s", vregs->min_uV,
+		vregs->name);
+	BT_DBG("max voltage %duA selected for regulator %s", vregs->max_uV,
+		vregs->name);
+}
+
 static int qca_init_regulators(struct qca_power *qca,
-				const struct qca_vreg *vregs, size_t num_vregs)
+				const struct qca_vreg_data *data)
 {
-	int i;
+	int i, num_vregs;
+	int load_uA;
+
+	num_vregs = data->num_vregs;
 
 	qca->vreg_bulk = devm_kcalloc(qca->dev, num_vregs,
 				      sizeof(struct regulator_bulk_data),
@@ -1398,8 +1436,32 @@ static int qca_init_regulators(struct qca_power *qca,
 	if (!qca->vreg_bulk)
 		return -ENOMEM;
 
-	for (i = 0; i < num_vregs; i++)
-		qca->vreg_bulk[i].supply = vregs[i].name;
+	qca->vreg_data = devm_kzalloc(qca->dev, sizeof(struct qca_vreg_data),
+				      GFP_KERNEL);
+	if (!qca->vreg_data)
+		return -ENOMEM;
+
+	qca->vreg_data->num_vregs = num_vregs;
+
+	qca->vreg_data->vregs = devm_kzalloc(qca->dev, num_vregs *
+				      sizeof(struct qca_vreg_data),
+				      GFP_KERNEL);
+
+	if (!qca->vreg_data->vregs)
+		return -ENOMEM;
+
+	for (i = 0; i < num_vregs; i++) {
+		/* copy regulator name, min voltage, max voltage */
+		qca->vreg_data->vregs[i].name = data->vregs[i].name;
+		qca->vreg_data->vregs[i].min_uV = data->vregs[i].min_uV;
+		qca->vreg_data->vregs[i].max_uV = data->vregs[i].max_uV;
+		load_uA = data->vregs[i].load_uA;
+		qca->vreg_data->vregs[i].load_uA = load_uA;
+		qca_regulator_get_voltage_current(qca->dev,
+			&qca->vreg_data->vregs[i]);
+
+		qca->vreg_bulk[i].supply = qca->vreg_data->vregs[i].name;
+	}
 
 	return devm_regulator_bulk_get(qca->dev, num_vregs, qca->vreg_bulk);
 }
@@ -1426,9 +1488,7 @@ static int qca_serdev_probe(struct serdev_device *serdev)
 			return -ENOMEM;
 
 		qcadev->bt_power->dev = &serdev->dev;
-		qcadev->bt_power->vreg_data = data;
-		err = qca_init_regulators(qcadev->bt_power, data->vregs,
-					  data->num_vregs);
+		err = qca_init_regulators(qcadev->bt_power, data);
 		if (err) {
 			BT_ERR("Failed to init regulators:%d", err);
 			goto out;
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

  reply	other threads:[~2019-03-07 12:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-07 12:16 [PATCH v1 0/2] Enable Bluetooth functionality for wcn3998 Harish Bandi
2019-03-07 12:16 ` Harish Bandi [this message]
2019-03-07 12:16 ` [PATCH v1 2/2] dt-bindings: net: bluetooth: Add device tree bindings for QTI chip wcn3990 Harish Bandi
2019-03-07 19:18 ` [PATCH v1 0/2] Enable Bluetooth functionality for wcn3998 Matthias Kaehlcke
2019-03-08  6:39   ` c-hbandi

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=1551961012-23898-2-git-send-email-c-hbandi@codeaurora.org \
    --to=c-hbandi@codeaurora.org \
    --cc=anubhavg@codeaurora.org \
    --cc=bgodavar@codeaurora.org \
    --cc=hemantg@codeaurora.org \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=mka@chromium.org \
    --subject='Re: [PATCH v1 1/2] Bluetooth: hci_qca: Added support to read the regulator values from DTS' \
    /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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.