From patchwork Wed Nov 7 10:13:01 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: 10672109 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 7042513A4 for ; Wed, 7 Nov 2018 10:17:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CD6E28BD4 for ; Wed, 7 Nov 2018 10:17:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50508284E9; Wed, 7 Nov 2018 10:17:49 +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 D7BEE284E9 for ; Wed, 7 Nov 2018 10:17:48 +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=qCqjX/0n+zmSoej9DdssbRU/JqmDbr7V2qWXefCqPEo=; b=C3f8+qjcJIeSRi 8CCR0Bj44147yNMPsksH5ubTh0gtcSL2WG7w5uJYtNVIcBpz2WcqXLL1Q7zpekTlP2NAf9lRCqayr mvwRe5/L39DOJz9wyRzyjiSw9xc4k/ytQzj6rgs2PrYQy2R64NVzppalemvcbgzOCFYdJBGoHOn3u YUYRFpirW0A4+BKdbIwHp3ELyMcRWB3uYi0uqmjJJDu+llhPWDJw/ulb+qlxdbD/uN5aW6++xZkfI FEP9GeXdBWhlIe6phegKYiirp5TT0BMXyf+k2NFBvJbqHsRRPzHr6yrOylk52jHuKsvEsN6USaYUV gyqqZvSWgLTHrQnfMVtA==; 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 1gKKu1-0008HP-74; Wed, 07 Nov 2018 10:17:37 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gKKqU-0003bI-8A for linux-arm-kernel@bombadil.infradead.org; Wed, 07 Nov 2018 10:13:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=rTOuliGIjKVIpgXDbBKUtquS6GgSP+DvLVbzGur5nvI=; b=jtNi+k5jBZuZ001uTQqGznuJ/U STWkAnoIqS2j8xtqOYbvO8RcwugGBv6xAr+t6SyRR6dAhNBWFUL+Zo7saqTd8cpAgXG8F3I2aJAuI xvugjpko7zLkNkJUMxyXHJjoI9PlgVYlp+G19fYHV7SLPrISPi7RjLRdejnNSh/UOBGVmHgt5k0GA hI4OmAholcdvXNVJHqzxwe4BH/bOGkW71KUleI8CP3VBAPjY8GA67KXCXuGcmXcfCXFD/2SpcyPKe sviGVASVVZ8Yid1gWPWADB6Z6FcoilSehNuHRwXQ2yKgeHv/jsO4HrJpKWltwdKI7ohLBgriTm0Wg pNSYcoCA==; Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76] helo=wens.csie.org) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gKKqP-0003B9-4d for linux-arm-kernel@lists.infradead.org; Wed, 07 Nov 2018 10:13:56 +0000 Received: by wens.csie.org (Postfix, from userid 1000) id 93B4D5FD46; Wed, 7 Nov 2018 18:13:16 +0800 (CST) From: Chen-Yu Tsai To: Marcel Holtmann , Johan Hedberg , Rob Herring , Mark Rutland , Maxime Ripard Subject: [PATCH 08/15] Bluetooth: hci_bcm: Add support for LPO clock Date: Wed, 7 Nov 2018 18:13:01 +0800 Message-Id: <20181107101308.7626-9-wens@csie.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181107101308.7626-1-wens@csie.org> References: <20181107101308.7626-1-wens@csie.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181107_101353_896834_A249BDBD X-CRM114-Status: GOOD ( 20.41 ) 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, Chen-Yu Tsai , linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-sunxi@googlegroups.com, 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 The Broadcom Bluetooth controllers support a secondary LPO clock at 32.768 kHz. This external clock provides low power timing, and also a way to detect the frequency of the main reference clock. On many designs without NVRAM and a non-default reference clock, this must be used or the controller will not function correctly. Signed-off-by: Chen-Yu Tsai --- drivers/bluetooth/hci_bcm.c | 41 ++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c index 7556f8fac8aa..ab6e527952a9 100644 --- a/drivers/bluetooth/hci_bcm.c +++ b/drivers/bluetooth/hci_bcm.c @@ -72,7 +72,8 @@ * @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") * @txco_clk: external reference frequency clock used by Bluetooth device - * @clk_enabled: whether @txco_clk is prepared and enabled + * @lpo_clk: external LPO clock used by Bluetooth device + * @clk_enabled: whether clocks 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 @@ -103,6 +104,7 @@ struct bcm_device { #endif struct clk *txco_clk; + struct clk *lpo_clk; bool clk_enabled; u32 init_speed; @@ -215,21 +217,34 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered) int err; if (powered && !dev->clk_enabled) { - err = clk_prepare_enable(dev->txco_clk); + /* 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; + } + + err = clk_prepare_enable(dev->lpo_clk); if (err) return err; + + err = clk_prepare_enable(dev->txco_clk); + if (err) + goto err_lpo_clk_disable; } err = dev->set_shutdown(dev, powered); if (err) - goto err_clk_disable; + goto err_txco_clk_disable; err = dev->set_device_wakeup(dev, powered); if (err) goto err_revert_shutdown; - if (!powered && dev->clk_enabled) + if (!powered && dev->clk_enabled) { clk_disable_unprepare(dev->txco_clk); + clk_disable_unprepare(dev->lpo_clk); + } dev->clk_enabled = powered; @@ -237,9 +252,12 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered) err_revert_shutdown: dev->set_shutdown(dev, !powered); -err_clk_disable: +err_txco_clk_disable: if (powered && !dev->clk_enabled) clk_disable_unprepare(dev->txco_clk); +err_lpo_clk_disable: + if (powered && !dev->clk_enabled) + clk_disable_unprepare(dev->lpo_clk); return err; } @@ -934,6 +952,19 @@ static int bcm_get_resources(struct bcm_device *dev) if (IS_ERR(dev->txco_clk)) dev->txco_clk = NULL; + dev->lpo_clk = devm_clk_get(dev->dev, "lpo"); + if (IS_ERR(dev->lpo_clk) && PTR_ERR(dev->lpo_clk) == -EPROBE_DEFER) + return PTR_ERR(dev->lpo_clk); + + if (IS_ERR(dev->lpo_clk)) + dev->lpo_clk = NULL; + + /* Check if we accidentally fetched the lpo clock twice */ + if (dev->lpo_clk && clk_is_match(dev->lpo_clk, dev->txco_clk)) { + devm_clk_put(dev->dev, dev->txco_clk); + dev->txco_clk = NULL; + } + dev->device_wakeup = devm_gpiod_get_optional(dev->dev, "device-wakeup", GPIOD_OUT_LOW); if (IS_ERR(dev->device_wakeup))