From: Chen-Yu Tsai <wens@csie.org> To: Marcel Holtmann <marcel@holtmann.org>, Johan Hedberg <johan.hedberg@gmail.com>, Rob Herring <robh+dt@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Maxime Ripard <maxime.ripard@bootlin.com> Cc: Chen-Yu Tsai <wens@csie.org>, Loic Poulain <loic.poulain@gmail.com>, linux-bluetooth@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 09/15] Bluetooth: hci_bcm: Add support for regulator supplies Date: Thu, 15 Nov 2018 17:35:57 +0800 [thread overview] Message-ID: <20181115093603.26729-10-wens@csie.org> (raw) In-Reply-To: <20181115093603.26729-1-wens@csie.org> 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. Signed-off-by: Chen-Yu Tsai <wens@csie.org> --- drivers/bluetooth/hci_bcm.c | 39 ++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c index 345d728a5434..f2101038284e 100644 --- a/drivers/bluetooth/hci_bcm.c +++ b/drivers/bluetooth/hci_bcm.c @@ -31,6 +31,7 @@ #include <linux/property.h> #include <linux/platform_data/x86/apple.h> #include <linux/platform_device.h> +#include <linux/regulator/consumer.h> #include <linux/clk.h> #include <linux/gpio/consumer.h> #include <linux/tty.h> @@ -53,6 +54,8 @@ #define BCM_AUTOSUSPEND_DELAY 5000 /* default autosleep delay */ +#define BCM_NUM_SUPPLIES 2 + /** * struct bcm_device - device driver resources * @serdev_hu: HCI UART controller struct @@ -73,7 +76,8 @@ * @btpd: Apple ACPI method to drive BT_REG_ON pin low ("Bluetooth Power Down") * @txco_clk: external reference frequency 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; * the host UART is initially set to this baudrate so that * it can configure the Bluetooth device for @oper_speed @@ -105,7 +109,8 @@ struct bcm_device { struct clk *txco_clk; struct clk *lpo_clk; - bool clk_enabled; + struct regulator_bulk_data supplies[BCM_NUM_SUPPLIES]; + bool res_enabled; u32 init_speed; u32 oper_speed; @@ -216,17 +221,21 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered) { 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 */ err = clk_set_rate(dev->lpo_clk, 32768); if (err) { dev_err(dev->dev, "Could not set LPO clock rate\n"); - return err; + goto err_regulator_disable; } err = clk_prepare_enable(dev->lpo_clk); if (err) - return err; + goto err_regulator_disable; err = clk_prepare_enable(dev->txco_clk); if (err) @@ -241,23 +250,27 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered) if (err) goto err_revert_shutdown; - if (!powered && dev->clk_enabled) { + if (!powered && dev->res_enabled) { clk_disable_unprepare(dev->txco_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; err_revert_shutdown: dev->set_shutdown(dev, !powered); err_txco_clk_disable: - if (powered && !dev->clk_enabled) + if (powered && !dev->res_enabled) clk_disable_unprepare(dev->txco_clk); err_lpo_clk_disable: - if (powered && !dev->clk_enabled) + if (powered && !dev->res_enabled) clk_disable_unprepare(dev->lpo_clk); +err_regulator_disable: + if (powered && !dev->res_enabled) + regulator_bulk_disable(BCM_NUM_SUPPLIES, dev->supplies); return err; } @@ -936,6 +949,7 @@ static struct clk *bcm_get_txco(struct device *dev) static int bcm_get_resources(struct bcm_device *dev) { const struct dmi_system_id *dmi_id; + int err; dev->name = dev_name(dev->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_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 */ if (dev->irq <= 0) { struct gpio_desc *gpio; -- 2.19.1
WARNING: multiple messages have this Message-ID (diff)
From: wens@csie.org (Chen-Yu Tsai) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 09/15] Bluetooth: hci_bcm: Add support for regulator supplies Date: Thu, 15 Nov 2018 17:35:57 +0800 [thread overview] Message-ID: <20181115093603.26729-10-wens@csie.org> (raw) In-Reply-To: <20181115093603.26729-1-wens@csie.org> 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. Signed-off-by: Chen-Yu Tsai <wens@csie.org> --- drivers/bluetooth/hci_bcm.c | 39 ++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c index 345d728a5434..f2101038284e 100644 --- a/drivers/bluetooth/hci_bcm.c +++ b/drivers/bluetooth/hci_bcm.c @@ -31,6 +31,7 @@ #include <linux/property.h> #include <linux/platform_data/x86/apple.h> #include <linux/platform_device.h> +#include <linux/regulator/consumer.h> #include <linux/clk.h> #include <linux/gpio/consumer.h> #include <linux/tty.h> @@ -53,6 +54,8 @@ #define BCM_AUTOSUSPEND_DELAY 5000 /* default autosleep delay */ +#define BCM_NUM_SUPPLIES 2 + /** * struct bcm_device - device driver resources * @serdev_hu: HCI UART controller struct @@ -73,7 +76,8 @@ * @btpd: Apple ACPI method to drive BT_REG_ON pin low ("Bluetooth Power Down") * @txco_clk: external reference frequency 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; * the host UART is initially set to this baudrate so that * it can configure the Bluetooth device for @oper_speed @@ -105,7 +109,8 @@ struct bcm_device { struct clk *txco_clk; struct clk *lpo_clk; - bool clk_enabled; + struct regulator_bulk_data supplies[BCM_NUM_SUPPLIES]; + bool res_enabled; u32 init_speed; u32 oper_speed; @@ -216,17 +221,21 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered) { 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 */ err = clk_set_rate(dev->lpo_clk, 32768); if (err) { dev_err(dev->dev, "Could not set LPO clock rate\n"); - return err; + goto err_regulator_disable; } err = clk_prepare_enable(dev->lpo_clk); if (err) - return err; + goto err_regulator_disable; err = clk_prepare_enable(dev->txco_clk); if (err) @@ -241,23 +250,27 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered) if (err) goto err_revert_shutdown; - if (!powered && dev->clk_enabled) { + if (!powered && dev->res_enabled) { clk_disable_unprepare(dev->txco_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; err_revert_shutdown: dev->set_shutdown(dev, !powered); err_txco_clk_disable: - if (powered && !dev->clk_enabled) + if (powered && !dev->res_enabled) clk_disable_unprepare(dev->txco_clk); err_lpo_clk_disable: - if (powered && !dev->clk_enabled) + if (powered && !dev->res_enabled) clk_disable_unprepare(dev->lpo_clk); +err_regulator_disable: + if (powered && !dev->res_enabled) + regulator_bulk_disable(BCM_NUM_SUPPLIES, dev->supplies); return err; } @@ -936,6 +949,7 @@ static struct clk *bcm_get_txco(struct device *dev) static int bcm_get_resources(struct bcm_device *dev) { const struct dmi_system_id *dmi_id; + int err; dev->name = dev_name(dev->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_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 */ if (dev->irq <= 0) { struct gpio_desc *gpio; -- 2.19.1
next prev parent reply other threads:[~2018-11-15 9:36 UTC|newest] Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-11-15 9:35 [PATCH v2 00/15] ARM: sunxi: Enable Broadcom-based Bluetooth controllers Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:35 ` [PATCH v2 01/15] dt-bindings: net: broadcom-bluetooth: Fix external clock names Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:35 ` [PATCH v2 02/15] dt-bindings: net: broadcom-bluetooth: Add VBAT and VDDIO supplies Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:35 ` [PATCH v2 03/15] dt-bindings: net: broadcom-bluetooth: Add BCM20702A1 compatible string Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:35 ` [PATCH v2 04/15] dt-bindings: net: broadcom-bluetooth: Add BCM4330 " Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:35 ` [PATCH v2 05/15] Bluetooth: hci_bcm: Handle deferred probing for the clock supply Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:35 ` [PATCH v2 06/15] Bluetooth: hci_bcm: Simplify clk_get error handling Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:35 ` [PATCH v2 07/15] Bluetooth: hci_bcm: Use "txco" and "extclk" to get clock reference Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:35 ` [PATCH v2 08/15] Bluetooth: hci_bcm: Add support for LPO clock Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai [this message] 2018-11-15 9:35 ` [PATCH v2 09/15] Bluetooth: hci_bcm: Add support for regulator supplies Chen-Yu Tsai 2018-11-15 9:35 ` [PATCH v2 10/15] Bluetooth: hci_bcm: Wait for device to come out of reset after power on Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:35 ` [PATCH v2 11/15] Bluetooth: hci_bcm: Add BCM20702A1 variant Chen-Yu Tsai 2018-11-15 9:35 ` Chen-Yu Tsai 2018-11-15 9:36 ` [PATCH v2 12/15] Bluetooth: hci_bcm: Add compatible string for BCM4330 Chen-Yu Tsai 2018-11-15 9:36 ` Chen-Yu Tsai 2018-11-15 9:36 ` [PATCH v2 13/15] Bluetooth: btbcm: Add default address for BCM43430A0 Chen-Yu Tsai 2018-11-15 9:36 ` Chen-Yu Tsai 2018-11-15 9:36 ` [PATCH v2 14/15] ARM: dts: sunxi: Enable Broadcom-based Bluetooth for multiple boards Chen-Yu Tsai 2018-11-15 9:36 ` Chen-Yu Tsai 2018-11-15 9:36 ` [PATCH v2 15/15] arm64: dts: allwinner: a64: bananapi-m64: Add Bluetooth device node Chen-Yu Tsai 2018-11-15 9:36 ` Chen-Yu Tsai 2018-11-28 4:25 ` [PATCH v2 00/15] ARM: sunxi: Enable Broadcom-based Bluetooth controllers Chen-Yu Tsai 2018-11-28 4:25 ` Chen-Yu Tsai 2018-12-03 15:51 ` Chen-Yu Tsai 2018-12-03 15:51 ` Chen-Yu Tsai 2018-12-14 12:42 ` Ondřej Jirman 2018-12-14 12:42 ` Ondřej Jirman
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=20181115093603.26729-10-wens@csie.org \ --to=wens@csie.org \ --cc=devicetree@vger.kernel.org \ --cc=johan.hedberg@gmail.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-bluetooth@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=loic.poulain@gmail.com \ --cc=marcel@holtmann.org \ --cc=mark.rutland@arm.com \ --cc=maxime.ripard@bootlin.com \ --cc=robh+dt@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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.