From patchwork Thu Nov 15 09:35:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 10684015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F22514E2 for ; Thu, 15 Nov 2018 09:38:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A06D52B880 for ; Thu, 15 Nov 2018 09:38:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 940572B88A; Thu, 15 Nov 2018 09:38:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 287072B880 for ; Thu, 15 Nov 2018 09:38:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=s0wBARypP6MY/xE3TyHy118rjnbUZ/qeY3mlVMcEirM=; b=n7HGvJt6uODlGJ JA4ejv5lFqyAO5KGCiuihH5GXw/JHLN24BTdPGTHH9CjlldrfBpgHubD5RO7y/FHJhqRuJiR1nuH+ FYznFZDwfM61fegSRE9s2vtlPvC/EeZxhMXZaVjtx6y4gtKvaEzQJPvRRHAMEJBT/KO8l8AzJg8Z/ JjNmhu1GObxGs2/n5TfnOGwBjRXL/63lJgDRJQQdABuiHiPumnazhHyYV6l/JWIx7J0MX+7KZsSQO Qv7VLUExaLUU7CeUUkACNyYQ7WTImM5VI43UhX/9tX93nyJDul+1M5tkZ+ORnXFdNXwoGP+GtGC8L 6FCHeY1B3fQNAjzkKdag==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNE6Y-00039q-TB; Thu, 15 Nov 2018 09:38:30 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNE4o-0001S9-BZ for linux-arm-kernel@bombadil.infradead.org; Thu, 15 Nov 2018 09:36:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=kGMR2bekpTypK6+IyYuJLwrR93xbgtPVw3DRcFIcB1s=; b=ALjI818i6bay4/k8cJuu65mtRn F1h8mFS3VGv79YJHq1z48EawS2aQKXbjqfoc2TbbqLu4ld2/38dP7Tjhwf9L6S9hyyVyjC6N0vah8 jUUxQ9XoBDnS5Hl+jbnKqvVcRTf9QQ2J+tncFgPxTTNB5WnLLZdQRUl8L0g7ayqUrZeKj0MWKH7d3 QyCziNPuuuRxxXhaPObqlzHPGrleUoQ8sz2APHill9L375p+3Lkw/Se6dvoWZAifitFIP+Cn7X7FA YyNAnHQoxwIhUjiAkLv58/M9oNq7GJOJAxbIEx/ncw1zUTDehXP75vl3TVr0itkfwbtiWwViUsP8y 6WWImcnQ==; Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76] helo=wens.csie.org) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNE4k-0000jL-L5 for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 09:36:40 +0000 Received: by wens.csie.org (Postfix, from userid 1000) id CF6DF5FD87; Thu, 15 Nov 2018 17:36:04 +0800 (CST) From: Chen-Yu Tsai To: Marcel Holtmann , Johan Hedberg , Rob Herring , Mark Rutland , Maxime Ripard Subject: [PATCH v2 07/15] Bluetooth: hci_bcm: Use "txco" and "extclk" to get clock reference Date: Thu, 15 Nov 2018 17:35:55 +0800 Message-Id: <20181115093603.26729-8-wens@csie.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115093603.26729-1-wens@csie.org> References: <20181115093603.26729-1-wens@csie.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181115_043639_192160_9F1B09B5 X-CRM114-Status: GOOD ( 19.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, Chen-Yu Tsai , Loic Poulain , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 ff73ecb8215f..1584c95c9c34 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 (dev->clk == ERR_PTR(-EPROBE_DEFER)) - return PTR_ERR(dev->clk); + if (dev->txco_clk == ERR_PTR(-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);