From patchwork Wed Nov 7 10:13:00 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: 10672087 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 ED41E15E9 for ; Wed, 7 Nov 2018 10:15:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBFAC284E9 for ; Wed, 7 Nov 2018 10:15:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D043328C93; Wed, 7 Nov 2018 10:15:18 +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 65FAA284E9 for ; Wed, 7 Nov 2018 10:15:18 +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=4sH0z7eHUN2xe6h3VtRFLpRakneacYJpHGmwvT78tlo=; b=euGx8XO5xm4TQA o6ScBCq/CBoP5GNhPZ/3VsR7jVBGL+oOOTiskQNc+uc1PNxXY96sE4HvfygArwxPTHkDsXoOjDB13 YS3cPU2OcYx3VMmII0Mj5ke53cnWRhPeFO8bntVd6S9G9aXSnhRo+ofbiie12QrqJPqOLtYuigRhv Ej7Uw5dTJFZ9h/GM4hozlDg2rAzqsHh60S3tMW949EoTMVNIaGjqeulmcEQd9it5oC5FjtdRne/45 ap71TEwqocY+a6KOc/Jn1raykC2rgl923sTvjNJPz1gSpUM45OZTNKiHGyEveeAgjBPWocX9sCEct To4fFZhl5hVybmpp63uQ==; 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 1gKKrk-0005Ki-81; Wed, 07 Nov 2018 10:15:16 +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 1gKKqR-0003X3-Sn for linux-arm-kernel@bombadil.infradead.org; Wed, 07 Nov 2018 10:13:55 +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=ZvovO+weA5pIiDqxKMc5PsUq+z4o8E0DbqkCngoO97U=; b=UdR7aVmCMOSoJSvCgccEJyhvPs 9bLWeA46ICXzM6JxygfIVdOr/g1o/Ky49lRNJ8g7f3kqQuWRN4CX8bgDA9Ir9k1AQbrbW1PBWUpyt 1uhU7BqsWRmONIVLuDbFlnK+z0cawyudkxjeyb62+Vlp2kdt7mpFczcrzf61mQ6JHRcbTzyMeyeyg ew2y7vXsE4bXXXoo2Aju4b8ZjWWr9RewkKTOKaxgiFDPWE8wIo0Mr8tjVno8uUv2lbCQ6K4d+3mNm RygrjY9V9VBE9eH8B3Lu8Is1S8EdV1OBZ7v45AZ5974GhIIYTAiUYlR9p3NgxLxUH3d3+G3igt1tL ozYMqA7w==; 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 1gKKqO-0003zy-Ek for linux-arm-kernel@lists.infradead.org; Wed, 07 Nov 2018 10:13:54 +0000 Received: by wens.csie.org (Postfix, from userid 1000) id 837AE5FCA9; 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 07/15] Bluetooth: hci_bcm: Use "txco" and "extclk" to get clock reference Date: Wed, 7 Nov 2018 18:13:00 +0800 Message-Id: <20181107101308.7626-8-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_051353_150345_CD46CA5D X-CRM114-Status: GOOD ( 18.63 ) 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 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 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);