Commit 75d11676 authored by Chen-Yu Tsai's avatar Chen-Yu Tsai Committed by Marcel Holtmann

Bluetooth: hci_bcm: Add support for regulator supplies

The Broadcom Bluetooth chips have two power inputs, VBAT and VDDIO.
The former provides overall power for the chip, while the latter powers
the I/O pins and buffers.

Model these two as regulator supplies, and let the driver manage them
in the same way as it does the clock supply.
Tested-by: default avatarOndrej Jirman <megous@megous.com>
Signed-off-by: default avatarChen-Yu Tsai <wens@csie.org>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 90bc07cc
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <linux/property.h> #include <linux/property.h>
#include <linux/platform_data/x86/apple.h> #include <linux/platform_data/x86/apple.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/tty.h> #include <linux/tty.h>
...@@ -53,6 +54,8 @@ ...@@ -53,6 +54,8 @@
#define BCM_AUTOSUSPEND_DELAY 5000 /* default autosleep delay */ #define BCM_AUTOSUSPEND_DELAY 5000 /* default autosleep delay */
#define BCM_NUM_SUPPLIES 2
/** /**
* struct bcm_device - device driver resources * struct bcm_device - device driver resources
* @serdev_hu: HCI UART controller struct * @serdev_hu: HCI UART controller struct
...@@ -73,7 +76,8 @@ ...@@ -73,7 +76,8 @@
* @btpd: Apple ACPI method to drive BT_REG_ON pin low ("Bluetooth Power Down") * @btpd: Apple ACPI method to drive BT_REG_ON pin low ("Bluetooth Power Down")
* @txco_clk: external reference frequency clock used by Bluetooth device * @txco_clk: external reference frequency clock used by Bluetooth device
* @lpo_clk: external LPO clock used by Bluetooth device * @lpo_clk: external LPO clock used by Bluetooth device
* @clk_enabled: whether clocks are prepared and enabled * @supplies: VBAT and VDDIO supplies used by Bluetooth device
* @res_enabled: whether clocks and supplies are prepared and enabled
* @init_speed: default baudrate of Bluetooth device; * @init_speed: default baudrate of Bluetooth device;
* the host UART is initially set to this baudrate so that * the host UART is initially set to this baudrate so that
* it can configure the Bluetooth device for @oper_speed * it can configure the Bluetooth device for @oper_speed
...@@ -105,7 +109,8 @@ struct bcm_device { ...@@ -105,7 +109,8 @@ struct bcm_device {
struct clk *txco_clk; struct clk *txco_clk;
struct clk *lpo_clk; struct clk *lpo_clk;
bool clk_enabled; struct regulator_bulk_data supplies[BCM_NUM_SUPPLIES];
bool res_enabled;
u32 init_speed; u32 init_speed;
u32 oper_speed; u32 oper_speed;
...@@ -216,17 +221,21 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered) ...@@ -216,17 +221,21 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered)
{ {
int err; int err;
if (powered && !dev->clk_enabled) { if (powered && !dev->res_enabled) {
err = regulator_bulk_enable(BCM_NUM_SUPPLIES, dev->supplies);
if (err)
return err;
/* LPO clock needs to be 32.768 kHz */ /* LPO clock needs to be 32.768 kHz */
err = clk_set_rate(dev->lpo_clk, 32768); err = clk_set_rate(dev->lpo_clk, 32768);
if (err) { if (err) {
dev_err(dev->dev, "Could not set LPO clock rate\n"); dev_err(dev->dev, "Could not set LPO clock rate\n");
return err; goto err_regulator_disable;
} }
err = clk_prepare_enable(dev->lpo_clk); err = clk_prepare_enable(dev->lpo_clk);
if (err) if (err)
return err; goto err_regulator_disable;
err = clk_prepare_enable(dev->txco_clk); err = clk_prepare_enable(dev->txco_clk);
if (err) if (err)
...@@ -241,23 +250,27 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered) ...@@ -241,23 +250,27 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered)
if (err) if (err)
goto err_revert_shutdown; goto err_revert_shutdown;
if (!powered && dev->clk_enabled) { if (!powered && dev->res_enabled) {
clk_disable_unprepare(dev->txco_clk); clk_disable_unprepare(dev->txco_clk);
clk_disable_unprepare(dev->lpo_clk); clk_disable_unprepare(dev->lpo_clk);
regulator_bulk_disable(BCM_NUM_SUPPLIES, dev->supplies);
} }
dev->clk_enabled = powered; dev->res_enabled = powered;
return 0; return 0;
err_revert_shutdown: err_revert_shutdown:
dev->set_shutdown(dev, !powered); dev->set_shutdown(dev, !powered);
err_txco_clk_disable: err_txco_clk_disable:
if (powered && !dev->clk_enabled) if (powered && !dev->res_enabled)
clk_disable_unprepare(dev->txco_clk); clk_disable_unprepare(dev->txco_clk);
err_lpo_clk_disable: err_lpo_clk_disable:
if (powered && !dev->clk_enabled) if (powered && !dev->res_enabled)
clk_disable_unprepare(dev->lpo_clk); clk_disable_unprepare(dev->lpo_clk);
err_regulator_disable:
if (powered && !dev->res_enabled)
regulator_bulk_disable(BCM_NUM_SUPPLIES, dev->supplies);
return err; return err;
} }
...@@ -936,6 +949,7 @@ static struct clk *bcm_get_txco(struct device *dev) ...@@ -936,6 +949,7 @@ static struct clk *bcm_get_txco(struct device *dev)
static int bcm_get_resources(struct bcm_device *dev) static int bcm_get_resources(struct bcm_device *dev)
{ {
const struct dmi_system_id *dmi_id; const struct dmi_system_id *dmi_id;
int err;
dev->name = dev_name(dev->dev); dev->name = dev_name(dev->dev);
...@@ -978,6 +992,13 @@ static int bcm_get_resources(struct bcm_device *dev) ...@@ -978,6 +992,13 @@ static int bcm_get_resources(struct bcm_device *dev)
dev->set_device_wakeup = bcm_gpio_set_device_wakeup; dev->set_device_wakeup = bcm_gpio_set_device_wakeup;
dev->set_shutdown = bcm_gpio_set_shutdown; dev->set_shutdown = bcm_gpio_set_shutdown;
dev->supplies[0].supply = "vbat";
dev->supplies[1].supply = "vddio";
err = devm_regulator_bulk_get(dev->dev, BCM_NUM_SUPPLIES,
dev->supplies);
if (err)
return err;
/* IRQ can be declared in ACPI table as Interrupt or GpioInt */ /* IRQ can be declared in ACPI table as Interrupt or GpioInt */
if (dev->irq <= 0) { if (dev->irq <= 0) {
struct gpio_desc *gpio; struct gpio_desc *gpio;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment