summaryrefslogtreecommitdiffstats
path: root/drivers/bluetooth
diff options
context:
space:
mode:
authorBjorn Andersson <bjorn.andersson@linaro.org>2019-10-17 22:24:04 -0700
committerMarcel Holtmann <marcel@holtmann.org>2019-10-17 11:12:20 +0200
commita9314e76da966da8101eb0f9f6a8ee10675e3aee (patch)
tree4ed981028a8b6a21e2a9b484e198f25fd5c152da /drivers/bluetooth
parent163d42fa83c6090071698533d33babd7bbf97147 (diff)
downloadlinux-a9314e76da966da8101eb0f9f6a8ee10675e3aee.tar.gz
linux-a9314e76da966da8101eb0f9f6a8ee10675e3aee.tar.bz2
linux-a9314e76da966da8101eb0f9f6a8ee10675e3aee.zip
Bluetooth: hci_qca: Split qca_power_setup()
Split and rename qca_power_setup() in order to simplify each code path and to clarify that it is unrelated to qca_power_off() and qca_power_setup(). Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'drivers/bluetooth')
-rw-r--r--drivers/bluetooth/hci_qca.c61
1 files changed, 36 insertions, 25 deletions
diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index df3218072b04..8ae91e0f8102 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -160,7 +160,8 @@ struct qca_serdev {
const char *firmware_name;
};
-static int qca_power_setup(struct hci_uart *hu, bool on);
+static int qca_regulator_enable(struct qca_serdev *qcadev);
+static void qca_regulator_disable(struct qca_serdev *qcadev);
static void qca_power_shutdown(struct hci_uart *hu);
static int qca_power_off(struct hci_dev *hdev);
@@ -516,7 +517,7 @@ static int qca_open(struct hci_uart *hu)
} else {
hu->init_speed = qcadev->init_speed;
hu->oper_speed = qcadev->oper_speed;
- ret = qca_power_setup(hu, true);
+ ret = qca_regulator_enable(qcadev);
if (ret) {
destroy_workqueue(qca->workqueue);
kfree_skb(qca->rx_skb);
@@ -1188,7 +1189,7 @@ static int qca_wcn3990_init(struct hci_uart *hu)
qcadev = serdev_device_get_drvdata(hu->serdev);
if (!qcadev->bt_power->vregs_on) {
serdev_device_close(hu->serdev);
- ret = qca_power_setup(hu, true);
+ ret = qca_regulator_enable(qcadev);
if (ret)
return ret;
@@ -1353,9 +1354,12 @@ static const struct qca_vreg_data qca_soc_data_wcn3998 = {
static void qca_power_shutdown(struct hci_uart *hu)
{
+ struct qca_serdev *qcadev;
struct qca_data *qca = hu->priv;
unsigned long flags;
+ qcadev = serdev_device_get_drvdata(hu->serdev);
+
/* From this point we go into power off state. But serial port is
* still open, stop queueing the IBS data and flush all the buffered
* data in skb's.
@@ -1367,7 +1371,7 @@ static void qca_power_shutdown(struct hci_uart *hu)
host_set_baudrate(hu, 2400);
qca_send_power_pulse(hu, false);
- qca_power_setup(hu, false);
+ qca_regulator_disable(qcadev);
}
static int qca_power_off(struct hci_dev *hdev)
@@ -1383,36 +1387,43 @@ static int qca_power_off(struct hci_dev *hdev)
return 0;
}
-static int qca_power_setup(struct hci_uart *hu, bool on)
+static int qca_regulator_enable(struct qca_serdev *qcadev)
{
- struct regulator_bulk_data *vreg_bulk;
- struct qca_serdev *qcadev;
- int num_vregs;
- int ret = 0;
+ struct qca_power *power = qcadev->bt_power;
+ int ret;
- qcadev = serdev_device_get_drvdata(hu->serdev);
- if (!qcadev || !qcadev->bt_power || !qcadev->bt_power->vreg_bulk)
- return -EINVAL;
+ /* Already enabled */
+ if (power->vregs_on)
+ return 0;
- vreg_bulk = qcadev->bt_power->vreg_bulk;
- num_vregs = qcadev->bt_power->num_vregs;
- BT_DBG("on: %d (%d regulators)", on, num_vregs);
- if (on && !qcadev->bt_power->vregs_on) {
- ret = regulator_bulk_enable(num_vregs, vreg_bulk);
- if (ret)
- return ret;
+ BT_DBG("enabling %d regulators)", power->num_vregs);
- qcadev->bt_power->vregs_on = true;
- } else if (!on && qcadev->bt_power->vregs_on) {
- /* turn off regulator in reverse order */
- regulator_bulk_disable(num_vregs, vreg_bulk);
+ ret = regulator_bulk_enable(power->num_vregs, power->vreg_bulk);
+ if (ret)
+ return ret;
- qcadev->bt_power->vregs_on = false;
- }
+ power->vregs_on = true;
return 0;
}
+static void qca_regulator_disable(struct qca_serdev *qcadev)
+{
+ struct qca_power *power;
+
+ if (!qcadev)
+ return;
+
+ power = qcadev->bt_power;
+
+ /* Already disabled? */
+ if (!power->vregs_on)
+ return;
+
+ regulator_bulk_disable(power->num_vregs, power->vreg_bulk);
+ power->vregs_on = false;
+}
+
static int qca_init_regulators(struct qca_power *qca,
const struct qca_vreg *vregs, size_t num_vregs)
{