From patchwork Fri Aug 3 12:16:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balakrishna Godavarthi X-Patchwork-Id: 10555055 X-Patchwork-Delegate: agross@codeaurora.org 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 CC0551822 for ; Fri, 3 Aug 2018 12:17:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C19C12B90C for ; Fri, 3 Aug 2018 12:17:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5F9F2B984; Fri, 3 Aug 2018 12:17:28 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 499442B90C for ; Fri, 3 Aug 2018 12:17:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730822AbeHCONE (ORCPT ); Fri, 3 Aug 2018 10:13:04 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:45310 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727403AbeHCONE (ORCPT ); Fri, 3 Aug 2018 10:13:04 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id F3BE3607BD; Fri, 3 Aug 2018 12:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1533298619; bh=Zsi/y3FYCzIxxLpLK8ynqd4qhjN6NLR3ux4gMLn85FM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cccKVYOyXgsMj78E02fqSWO7+P5GOV6z96dvGYkFxryinEbLo7uyGC5EGFiMyiQQP ucKlItne3jGYNQdVwDOFXQUWwJi7pZOe7DwAEaTzPPMtINghpyFaLJo2u0U0b1weDV hNyxpxcn+GtX35+hngR9c3aAClYlRwxKn8mgQQ9Y= Received: from bgodavar-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: bgodavar@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 75BD560AD8; Fri, 3 Aug 2018 12:16:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1533298617; bh=Zsi/y3FYCzIxxLpLK8ynqd4qhjN6NLR3ux4gMLn85FM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DYfiza4q67aGJu5mSDvivaDMA3sLAuIBlBfzV+OIWTwvtj7vegIugQpl8sHaNn+Zt WivNXuB2F12Mt4ZvDzUUtZ+4TzPMvL9ho+JxI9smuV1gOdmtp4uoh4TWg82JCWG2Yv p2kFvB/0fPgXMVZp7qdFdbiqWX208+TVAUcYJNqI= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 75BD560AD8 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=bgodavar@codeaurora.org From: Balakrishna Godavarthi To: marcel@holtmann.org, johan.hedberg@gmail.com, mka@chromium.org Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-bluetooth@vger.kernel.org, thierry.escande@linaro.org, rtatiya@codeaurora.org, hemantg@codeaurora.org, linux-arm-msm@vger.kernel.org, Balakrishna Godavarthi Subject: [PATCH v15 4/7] Bluetooth: hci_qca: Add wrapper functions for setting UART speed Date: Fri, 3 Aug 2018 17:46:29 +0530 Message-Id: <20180803121632.30689-5-bgodavar@codeaurora.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180803121632.30689-1-bgodavar@codeaurora.org> References: <20180803121632.30689-1-bgodavar@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In function qca_setup, we set initial and operating speeds for Qualcomm Bluetooth SoC's. This block of code is common across different Qualcomm Bluetooth SoC's. Instead of duplicating the code, created a wrapper function to set the speeds. So that future coming SoC's can use these wrapper functions to set speeds. Signed-off-by: Balakrishna Godavarthi Reviewed-by: Matthias Kaehlcke --- drivers/bluetooth/hci_qca.c | 93 ++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 23 deletions(-) diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index 5f1c0a8fd5cd..5f8a74d65bec 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -119,6 +119,11 @@ struct qca_data { u64 votes_off; }; +enum qca_speed_type { + QCA_INIT_SPEED = 1, + QCA_OPER_SPEED +}; + struct qca_serdev { struct hci_uart serdev_hu; struct gpio_desc *bt_en; @@ -923,6 +928,61 @@ static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed) hci_uart_set_baudrate(hu, speed); } +static unsigned int qca_get_speed(struct hci_uart *hu, + enum qca_speed_type speed_type) +{ + unsigned int speed = 0; + + if (speed_type == QCA_INIT_SPEED) { + if (hu->init_speed) + speed = hu->init_speed; + else if (hu->proto->init_speed) + speed = hu->proto->init_speed; + } else { + if (hu->oper_speed) + speed = hu->oper_speed; + else if (hu->proto->oper_speed) + speed = hu->proto->oper_speed; + } + + return speed; +} + +static int qca_check_speeds(struct hci_uart *hu) +{ + if (!qca_get_speed(hu, QCA_INIT_SPEED) || + !qca_get_speed(hu, QCA_OPER_SPEED)) + return -EINVAL; + + return 0; +} + +static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type) +{ + unsigned int speed, qca_baudrate; + int ret; + + if (speed_type == QCA_INIT_SPEED) { + speed = qca_get_speed(hu, QCA_INIT_SPEED); + if (speed) + host_set_baudrate(hu, speed); + } else { + speed = qca_get_speed(hu, QCA_OPER_SPEED); + if (!speed) + return 0; + + qca_baudrate = qca_get_baudrate_value(speed); + bt_dev_info(hu->hdev, "Set UART speed to %d", speed); + ret = qca_set_baudrate(hu->hdev, qca_baudrate); + if (ret) + return ret; + + host_set_baudrate(hu, speed); + } + + return 0; +} + static int qca_setup(struct hci_uart *hu) { struct hci_dev *hdev = hu->hdev; @@ -933,37 +993,24 @@ static int qca_setup(struct hci_uart *hu) bt_dev_info(hdev, "ROME setup"); + ret = qca_check_speeds(hu); + if (ret) + return ret; + /* Patch downloading has to be done without IBS mode */ clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags); /* Setup initial baudrate */ - speed = 0; - if (hu->init_speed) - speed = hu->init_speed; - else if (hu->proto->init_speed) - speed = hu->proto->init_speed; - - if (speed) - host_set_baudrate(hu, speed); + qca_set_speed(hu, QCA_INIT_SPEED); /* Setup user speed if needed */ - speed = 0; - if (hu->oper_speed) - speed = hu->oper_speed; - else if (hu->proto->oper_speed) - speed = hu->proto->oper_speed; - + speed = qca_get_speed(hu, QCA_OPER_SPEED); if (speed) { - qca_baudrate = qca_get_baudrate_value(speed); - - bt_dev_info(hdev, "Set UART speed to %d", speed); - ret = qca_set_baudrate(hdev, qca_baudrate); - if (ret) { - bt_dev_err(hdev, "Failed to change the baud rate (%d)", - ret); + ret = qca_set_speed(hu, QCA_OPER_SPEED); + if (ret) return ret; - } - host_set_baudrate(hu, speed); + + qca_baudrate = qca_get_baudrate_value(speed); } /* Get QCA version information */