Patchwork [v1,1/2] Bluetooth: hci_qca: Added support to read the regulator values from DTS

login
register
mail settings
Submitter Harish Bandi
Date March 7, 2019, 12:16 p.m.
Message ID <1551961012-23898-2-git-send-email-c-hbandi@codeaurora.org>
Download mbox | patch
Permalink /patch/743311/
State New
Headers show

Comments

Harish Bandi - March 7, 2019, 12:16 p.m.
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(-)

Patch

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;