Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4005171ybx; Mon, 4 Nov 2019 06:20:36 -0800 (PST) X-Google-Smtp-Source: APXvYqy20O+woRGpaJB5xZv9b4fV+kLxS7ahLZzJIz9CE3AuhrL9KDxFyqOijTWmrwQQJiXkJBA5 X-Received: by 2002:a17:907:2122:: with SMTP id qo2mr12838102ejb.12.1572877236493; Mon, 04 Nov 2019 06:20:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572877236; cv=none; d=google.com; s=arc-20160816; b=HWnUEKi9fGtFmcEmWfKasU9+5qvbl7k9/ajKnEKWsFWpkhrntR/XYfQ7ZJgIR1673s uChtYGTyi7D1mh4y+WBQH/ilpfmpDPElzw6QQS8EyX7wHSV9DYZNFla8p/n8aTo0J4zV TugdLrY9Sk3nH5QHuJQT04dzw4V1MA3EaxwbYMcHZxrhftcjrrRTS7uT1O9tVF8AdG5h xTlefWryUgwPZ8ybK0CwCUit2wRJ+sHlefO3uTZOqdfVwnxSq227weRGi2LBiflSIgrJ T4ZPyEEYahvMit9hrAXBm/dDvhfeNHY0hkVkWSbVSeE5XI54BSmNyrFr9rnBg6c+kCAO wdwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=koj8vhrIiXC4LNe3vba3s33XAQKONpQv/c7RArsnJE4=; b=rHYAjiuS40abAL2aA2i2H7wh6BVKCrhhI1UyVjfdUGwaMIIy0qfumcH7ThmfjdDCOO P/uwLtSFojPONrd8tvfycR7XXUTJvz9HdwYy8YsgJp+2xs6Od1Xb4fE0ro5Zp7xYG5yj y1g7W7409LBR71hlKBzfCJCJTSms9B55W5ZDVTIq7MgV5eJepLFBcKM+wf0dIytXIO7q dwpwlZAo5dMNHn/aaGRPl2N/lU6G0Lo40cjY2LmDlMYCXitin2Ypfj/ZgH3C21UOSsUN rvRdiNlzY48kFSe3BqLoB8ju5dJTgHsluWGkPAzelRK27XEoWsir/wPLB8Ifn5LitJ/C 2Scg== 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 y11si8188827edd.182.2019.11.04.06.20.00; Mon, 04 Nov 2019 06:20:36 -0800 (PST) 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 S1727861AbfKDOTx (ORCPT + 99 others); Mon, 4 Nov 2019 09:19:53 -0500 Received: from coyote.holtmann.net ([212.227.132.17]:40716 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727788AbfKDOTw (ORCPT ); Mon, 4 Nov 2019 09:19:52 -0500 Received: from marcel-macbook.fritz.box (p4FEFC197.dip0.t-ipconnect.de [79.239.193.151]) by mail.holtmann.org (Postfix) with ESMTPSA id EEC21CECD6; Mon, 4 Nov 2019 15:28:53 +0100 (CET) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3601.0.10\)) Subject: Re: [PATCH] Bluetooth: hci_qca: add PM support From: Marcel Holtmann In-Reply-To: <20191031104614.165120-1-tientzu@chromium.org> Date: Mon, 4 Nov 2019 15:19:50 +0100 Cc: Johan Hedberg , Balakrishna Godavarthi , Rocky Liao , Bluez mailing list , linux-kernel@vger.kernel.org Content-Transfer-Encoding: 7bit Message-Id: References: <20191031104614.165120-1-tientzu@chromium.org> To: Claire Chang X-Mailer: Apple Mail (2.3601.0.10) Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Claire, > Add PM suspend/resume callbacks for hci_qca driver. > > BT host will make sure both Rx and Tx go into sleep state in > qca_suspend. Without this, Tx may still remain in awake state, which > prevents BTSOC from entering deep sleep. For example, BlueZ will send > Set Event Mask to device when suspending and this will wake the device > Rx up. However, the Tx idle timeout on the host side is 2000 ms. If the > host is suspended before its Tx idle times out, it won't send > HCI_IBS_SLEEP_IND to the device and the device Rx will remain awake. > > We implement this by canceling relevant work in workqueue, sending > HCI_IBS_SLEEP_IND to the device and then waiting HCI_IBS_SLEEP_IND sent > by the device. > > In order to prevent the device from being awaken again after qca_suspend > is called, we introduce QCA_SUSPEND flag. QCA_SUSPEND is set in the > beginning of qca_suspend to indicate system is suspending and that we'd > like to ignore any further wake events. > > With QCA_SUSPEND and spinlock, we can avoid race condition, e.g. if > qca_enqueue acquires qca->hci_ibs_lock before qca_suspend calls > cancel_work_sync and then qca_enqueue adds a new qca->ws_awake_device > work after the previous one is cancelled. > > If BTSOC wants to wake the whole system up after qca_suspend is called, > it will keep sending HCI_IBS_WAKE_IND and uart driver will take care of > waking the system. For example, uart driver will reconfigure its Rx pin > to a normal GPIO pin and enable irq wake on that pin when suspending. > Once host detects Rx falling, the system will begin resuming. Then, the > BT host clears QCA_SUSPEND flag in qca_resume and begins dealing with > normal HCI packets. By doing so, only a few HCI_IBS_WAKE_IND packets are > lost and there is no data packet loss. > > Signed-off-by: Claire Chang > --- > drivers/bluetooth/hci_qca.c | 127 +++++++++++++++++++++++++++++++++++- > 1 file changed, 124 insertions(+), 3 deletions(-) patch has been applied to bluetooth-next tree. Regards Marcel