Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp634517ybi; Fri, 14 Jun 2019 00:24:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYIBQ/I+AybD16+9xHSmBji8N6uZqiVtwiza4t3MLenehSacxVFo6toyObUdoDs6g/9n8e X-Received: by 2002:a17:90a:5884:: with SMTP id j4mr10002684pji.142.1560497083975; Fri, 14 Jun 2019 00:24:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560497083; cv=none; d=google.com; s=arc-20160816; b=B/0Jw4nzKP75VgNJknea1/+jNGJZKAxJB+Z7zvMhql5Mp5fFR4FhK4xO4djZ9Agh29 WF/zyR9T5guYA3BGamwf0i54+vRs6LEeozNZbA30uhxQmnUM2TaUpSFv6Y31hDEMboI8 BG8VM1+HxRvBO/pUu3EpeWBQvvN7D9vBxc7JOPPpc50Pky4pVIyGsMgWfeCxzoWkL2g1 5bLWh96GmuNHbJ/UNmkN6dtlGzSzgxp1uSQLSU9wPKx7/ASjtU61G2cTHNKdD+oEz8cz HPTQMBbe/laBPPa2xxdJ5C4G/uYcG9KZ/EVCBsgbWlCgYKd1rJTm30UW72V8Bsb5H0Xm SeBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=wA0SQOad2JyoqYau5laBhhB3Ex5o2ZYqw+QiitFwVgE=; b=Vhj0qnclxKb7VSSQ4CElXbXiJKTlRE0VAZ9Dh0PoJvPJEC9zYRVKQD+TAPt63I+EvJ ECo5pXcFpla7tf9M+Szi/Xt3a6DxmBBQIyuq6rhshJ1ZGQWzf6yG19+zvDbLhj5f4ey/ +C8gdOATbAZBdM6ss7Nt/56q3vRB0QARIW0+WBEdCDkxUdyeqKNIqMrbYM46DIE2AXqB uJlapelrz+m0zTfK6jiuf+OoMgrFhme8GBzIQU6HPP9pSXH7uOGcLQm0LheOThNCsDJd D9N/R6fnqDsTuewim7JcyrQ11Nh4RUdPpPhWMIAMiOxZWueJasEuM19Jnpz/KD0uF4bu iAhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si1860577pgj.219.2019.06.14.00.24.28; Fri, 14 Jun 2019 00:24:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726404AbfFNHYL (ORCPT + 99 others); Fri, 14 Jun 2019 03:24:11 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:41265 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725923AbfFNHYL (ORCPT ); Fri, 14 Jun 2019 03:24:11 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1hbgYz-0000qU-R9; Fri, 14 Jun 2019 09:23:53 +0200 Received: from sha by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1hbgYz-0006Nj-35; Fri, 14 Jun 2019 09:23:53 +0200 From: Sascha Hauer To: linux-bluetooth@vger.kernel.org Cc: Marcel Holtmann , Johan Hedberg , linux-kernel@vger.kernel.org, Loic Poulain , kernel@pengutronix.de, Sascha Hauer Subject: [PATCH 1/3] Bluetooth: hci_ldisc: Add function to wait for characters to be sent Date: Fri, 14 Jun 2019 09:23:49 +0200 Message-Id: <20190614072351.17390-2-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190614072351.17390-1-s.hauer@pengutronix.de> References: <20190614072351.17390-1-s.hauer@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-bluetooth@vger.kernel.org Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org The hci UART line discipline sends its characters in a workqueue. Some devices like the Marvell Bluetooth chips need to make sure that all queued characters are sent before switching the baudrate. This adds a function to synchronize with the workqueue. Signed-off-by: Sascha Hauer --- drivers/bluetooth/hci_ldisc.c | 8 ++++++++ drivers/bluetooth/hci_uart.h | 1 + 2 files changed, 9 insertions(+) diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index c84f985f348d..8950e07889fe 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c @@ -178,6 +178,7 @@ static void hci_uart_write_work(struct work_struct *work) goto restart; clear_bit(HCI_UART_SENDING, &hu->tx_state); + wake_up_bit(&hu->tx_state, HCI_UART_SENDING); } void hci_uart_init_work(struct work_struct *work) @@ -213,6 +214,13 @@ int hci_uart_init_ready(struct hci_uart *hu) return 0; } +int hci_uart_wait_until_sent(struct hci_uart *hu) +{ + return wait_on_bit_timeout(&hu->tx_state, HCI_UART_SENDING, + TASK_INTERRUPTIBLE, + msecs_to_jiffies(2000)); +} + /* ------- Interface to HCI layer ------ */ /* Reset device */ static int hci_uart_flush(struct hci_dev *hdev) diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h index d8cf005e3c5d..f11af3912ce6 100644 --- a/drivers/bluetooth/hci_uart.h +++ b/drivers/bluetooth/hci_uart.h @@ -100,6 +100,7 @@ int hci_uart_register_device(struct hci_uart *hu, const struct hci_uart_proto *p void hci_uart_unregister_device(struct hci_uart *hu); int hci_uart_tx_wakeup(struct hci_uart *hu); +int hci_uart_wait_until_sent(struct hci_uart *hu); int hci_uart_init_ready(struct hci_uart *hu); void hci_uart_init_work(struct work_struct *work); void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed); -- 2.20.1