From patchwork Wed Nov 7 10:13:02 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: 10672099 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 905C213A4 for ; Wed, 7 Nov 2018 10:17:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E7CD284E9 for ; Wed, 7 Nov 2018 10:17:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FFD028C93; Wed, 7 Nov 2018 10:17:10 +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 E8915284E9 for ; Wed, 7 Nov 2018 10:17:09 +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=nimO0f8d1RXtctjAqaS2Pkz2164fckyA8dvubVFOFCk=; b=gsFP6O/+XpaYZy KHjAAzes3ozb48v6XJwrI0V2DiqKyNmdS9jEQlMwq8UVVV9xmNHcIxoiQDgyOF9VEdqrpMIMZH2a/ pT2KgRl/u8hgiTKOzvPLi6yZFHj9p0NQQwkjQaFY4dSkBExvjdxPxViSAbjnGiGIVz3y02FOjcws0 SLBJB9M+iqRgtMhLGCXxStVNsi0xd3SRZKw1IwVMdixuFyUAkkLgYid3iSbK0z0ffuw95DmzVxz0b vMVw7bfgU/GphQG8KjxzipBKorDAt0d8f3uphsPN/4q5sH4F7WFPhl/S1RgAOyJvv8NERidoAFbq5 yyPzoDYeee3dpMe44C8Q==; 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 1gKKtR-0007j4-Bh; Wed, 07 Nov 2018 10:17:01 +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-0003bJ-7j 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=Csnn1Ll4KhKCzoeEf2PwRtDyDG6BFaURU53rlQ0R3hU=; b=iOq9ylX4ql+91UrzNUvbvd1WoI IF+WOWGEChJXPPE+QlKssgHs2upmJN7hW4Lh9JEb2hp53nXiNsNs8KY0HIAaBqAihgFS6xcrDkhjI bJlsAzt9L2d+a85luSY4jcQJiOfSGvW/crapznfw2/xVZ9jwolyxVg90qBW6vo78oeBKmYLv2RkDU lWz8sRCVnfuxZeW+lJ9Oap1zn6cV7oUfGrlKMBIVCJbOfWHnHIdbwV2VmlYhIJqEUH4MhsJoe5ZP/ AtMknpl/Ms9qXDoq5paJQwLWHjSrkxlwLLOXXjZ2TfkTC2oH2LI/KT0COIIme1V9Cgr7zfi2UtVI6 hJyDUhTA==; 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-0003BV-4i 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 9ECC25FD06; 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 09/15] Bluetooth: hci_bcm: Add support for regulator supplies Date: Wed, 7 Nov 2018 18:13:02 +0800 Message-Id: <20181107101308.7626-10-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_879312_A872086A X-CRM114-Status: GOOD ( 21.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 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 --- 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 ab6e527952a9..060001f11a98 100644 --- a/drivers/bluetooth/hci_bcm.c +++ b/drivers/bluetooth/hci_bcm.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -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;