linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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: linux-sunxi@googlegroups.com, 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 07/15] Bluetooth: hci_bcm: Use "txco" and "extclk" to get clock reference
Date: Wed,  7 Nov 2018 18:13:00 +0800	[thread overview]
Message-ID: <20181107101308.7626-8-wens@csie.org> (raw)
In-Reply-To: <20181107101308.7626-1-wens@csie.org>

Originally the device tree binding only specified one clock reference,
with the name "extclk". The driver simply retrieves the clock without
bothering to specify a name.

Since we added a second clock to the binding, we need to fetch the
clocks by name now. First we try the new name "txco", then fall back
to the old name "extclk", and finally try retrieving a clock without
using any name, to cover any instances where a bad device tree or
firmware worked by accident.

In the last case, we should take care that we don't get the same
clock twice when we add support for the "lpo" clock.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/bluetooth/hci_bcm.c | 41 +++++++++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
index 7f21d9ab5029..7556f8fac8aa 100644
--- a/drivers/bluetooth/hci_bcm.c
+++ b/drivers/bluetooth/hci_bcm.c
@@ -71,8 +71,8 @@
  * @btlp: Apple ACPI method to toggle BT_WAKE pin ("Bluetooth Low Power")
  * @btpu: Apple ACPI method to drive BT_REG_ON pin high ("Bluetooth Power Up")
  * @btpd: Apple ACPI method to drive BT_REG_ON pin low ("Bluetooth Power Down")
- * @clk: clock used by Bluetooth device
- * @clk_enabled: whether @clk is prepared and enabled
+ * @txco_clk: external reference frequency clock used by Bluetooth device
+ * @clk_enabled: whether @txco_clk is 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
@@ -102,7 +102,7 @@ struct bcm_device {
 	int			gpio_int_idx;
 #endif
 
-	struct clk		*clk;
+	struct clk		*txco_clk;
 	bool			clk_enabled;
 
 	u32			init_speed;
@@ -215,7 +215,7 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered)
 	int err;
 
 	if (powered && !dev->clk_enabled) {
-		err = clk_prepare_enable(dev->clk);
+		err = clk_prepare_enable(dev->txco_clk);
 		if (err)
 			return err;
 	}
@@ -229,7 +229,7 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered)
 		goto err_revert_shutdown;
 
 	if (!powered && dev->clk_enabled)
-		clk_disable_unprepare(dev->clk);
+		clk_disable_unprepare(dev->txco_clk);
 
 	dev->clk_enabled = powered;
 
@@ -239,7 +239,7 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered)
 	dev->set_shutdown(dev, !powered);
 err_clk_disable:
 	if (powered && !dev->clk_enabled)
-		clk_disable_unprepare(dev->clk);
+		clk_disable_unprepare(dev->txco_clk);
 	return err;
 }
 
@@ -896,6 +896,25 @@ static int bcm_gpio_set_shutdown(struct bcm_device *dev, bool powered)
 	return 0;
 }
 
+/* Try a bunch of names for TXCO */
+static struct clk *bcm_get_txco(struct device *dev)
+{
+	struct clk *clk;
+
+	/* New explicit name */
+	clk = devm_clk_get(dev, "txco");
+	if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
+		return clk;
+
+	/* Deprecated name */
+	clk = devm_clk_get(dev, "extclk");
+	if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
+		return clk;
+
+	/* Original code used no name at all */
+	return devm_clk_get(dev, NULL);
+}
+
 static int bcm_get_resources(struct bcm_device *dev)
 {
 	const struct dmi_system_id *dmi_id;
@@ -905,15 +924,15 @@ static int bcm_get_resources(struct bcm_device *dev)
 	if (x86_apple_machine && !bcm_apple_get_resources(dev))
 		return 0;
 
-	dev->clk = devm_clk_get(dev->dev, NULL);
+	dev->txco_clk = bcm_get_txco(dev->dev);
 
 	/* Handle deferred probing */
-	if (IS_ERR(dev->clk) && PTR_ERR(dev->clk) == -EPROBE_DEFER)
-		return PTR_ERR(dev->clk);
+	if (IS_ERR(dev->txco_clk) && PTR_ERR(dev->txco_clk) == -EPROBE_DEFER)
+		return PTR_ERR(dev->txco_clk);
 
 	/* Ignore all other errors as before */
-	if (IS_ERR(dev->clk))
-		dev->clk = NULL;
+	if (IS_ERR(dev->txco_clk))
+		dev->txco_clk = NULL;
 
 	dev->device_wakeup = devm_gpiod_get_optional(dev->dev, "device-wakeup",
 						     GPIOD_OUT_LOW);
-- 
2.19.1


  parent reply	other threads:[~2018-11-07 10:20 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-07 10:12 [PATCH 00/15] ARM: sunxi: Enable Broadcom-based Bluetooth controllers Chen-Yu Tsai
2018-11-07 10:12 ` [PATCH 01/15] dt-bindings: net: broadcom-bluetooth: Fix external clock names Chen-Yu Tsai
     [not found]   ` <5bea0ebe.1c69fb81.e15d7.98e1@mx.google.com>
2018-11-14  3:15     ` Chen-Yu Tsai
2018-11-14 15:51       ` Rob Herring
2018-11-14 16:13         ` Chen-Yu Tsai
2018-11-07 10:12 ` [PATCH 02/15] dt-bindings: net: broadcom-bluetooth: Add VBAT and VDDIO supplies Chen-Yu Tsai
2018-11-07 10:12 ` [PATCH 03/15] dt-bindings: net: broadcom-bluetooth: Add BCM20702A1 compatible string Chen-Yu Tsai
2018-11-07 10:12 ` [PATCH 04/15] dt-bindings: net: broadcom-bluetooth: Add BCM4330 " Chen-Yu Tsai
2018-11-07 10:12 ` [PATCH 05/15] Bluetooth: hci_bcm: Handle deferred probing for the clock supply Chen-Yu Tsai
2018-11-07 10:12 ` [PATCH 06/15] Bluetooth: hci_bcm: Simplify clk_get error handling Chen-Yu Tsai
2018-11-07 10:51   ` Russell King - ARM Linux
2018-11-07 10:13 ` Chen-Yu Tsai [this message]
2018-11-07 10:13 ` [PATCH 08/15] Bluetooth: hci_bcm: Add support for LPO clock Chen-Yu Tsai
2018-11-07 10:13 ` [PATCH 09/15] Bluetooth: hci_bcm: Add support for regulator supplies Chen-Yu Tsai
2018-11-07 10:13 ` [PATCH 10/15] Bluetooth: hci_bcm: Wait for device to come out of reset after power on Chen-Yu Tsai
2018-11-07 10:13 ` [PATCH 11/15] Bluetooth: hci_bcm: Add BCM20702A1 variant Chen-Yu Tsai
2018-11-07 20:36   ` Maxime Ripard
2018-11-08  6:53     ` Chen-Yu Tsai
2018-11-08  8:21       ` Maxime Ripard
2018-11-07 10:13 ` [PATCH 12/15] Bluetooth: hci_bcm: Add compatible string for BCM4330 Chen-Yu Tsai
2018-11-07 10:13 ` [PATCH 13/15] Bluetooth: btbcm: Add default address for BCM43430A0 Chen-Yu Tsai
2018-11-07 10:13 ` [PATCH 14/15] ARM: dts: sunxi: Enable Broadcom-based Bluetooth for multiple boards Chen-Yu Tsai
2018-11-08  8:24   ` Maxime Ripard
2018-11-14  5:06     ` Chen-Yu Tsai
2018-11-07 10:13 ` [PATCH 15/15] arm64: dts: allwinner: a64: bananapi-m64: Add Bluetooth device node Chen-Yu Tsai
2018-11-08  8:25   ` Maxime Ripard
2018-11-08  8:35   ` Marcel Holtmann

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=20181107101308.7626-8-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=linux-sunxi@googlegroups.com \
    --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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).