From patchwork Sun Jul 31 04:24:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guodong Xu X-Patchwork-Id: 9253271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 37E5460865 for ; Sun, 31 Jul 2016 04:28:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CF5A2846F for ; Sun, 31 Jul 2016 04:28:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0BB5028481; Sun, 31 Jul 2016 04:28:38 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6FBF32846F for ; Sun, 31 Jul 2016 04:28:37 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bTiJT-0001z3-AT; Sun, 31 Jul 2016 04:25:19 +0000 Received: from mail-pa0-x235.google.com ([2607:f8b0:400e:c03::235]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bTiJO-0000ni-TM for linux-arm-kernel@lists.infradead.org; Sun, 31 Jul 2016 04:25:16 +0000 Received: by mail-pa0-x235.google.com with SMTP id iw10so42392145pac.2 for ; Sat, 30 Jul 2016 21:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=7WqtmWuzlll2y0dJCMGgtJwG44mmwwM2cTea1tNFVBI=; b=U1JZ2/6BT/lM9xivrvyA3GyQYTG6Y5cFw3n6RRmTozQged9+OaADEIWHEPmfVRWo8a 8KaHvaZ30ISrHqW8tlQCPcTLxLAj9mDsn05GU2grH4hw5B24EJ0xZIR2yVk2F/jlFhow 82YAYuMACGSYw+OV1KKVsSfRDZXHRdefJa5b4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7WqtmWuzlll2y0dJCMGgtJwG44mmwwM2cTea1tNFVBI=; b=HVjDtSlzlx7qoHVey8TeTrJKgVaXZre2A7IBzMaJBq08GAtTmtyOvUctdFZHx2np0l WZNm4WutTyCJRj6+Ys5wnPoIsIxCi3cqVQdQOhKze/f4ug04KAhQpyXt0sq4YnmwxH5v kdS+d4K680tJchjoVV+dHmEU/lhKB+v5w/2oTZspRDXzZvWjMjVC19c3GkzRmtLh9ck/ osfxLkN0i1cNuhWUyn6mYhtzjCByW3upr2tfq614wINvaF1InLd8CgXK8sZHn4bvfhzX sVPG5SQSaqdIAyFHPrEkuXOV59Z2+oe07G+JWHvq97uCOMtv2VFkoDnP4WcX9yHMPQZ0 gN0Q== X-Gm-Message-State: AEkoouspq5fsUyOgufVVbmCJiw21Cwx9ytZI5zZTn8qkaPio2w/yxlMSp4qT+an0IZLWxY0P X-Received: by 10.66.177.7 with SMTP id cm7mr83420297pac.132.1469939093220; Sat, 30 Jul 2016 21:24:53 -0700 (PDT) Received: from localhost.localdomain ([45.56.152.3]) by smtp.gmail.com with ESMTPSA id wa9sm35485562pac.35.2016.07.30.21.24.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 30 Jul 2016 21:24:52 -0700 (PDT) From: Guodong Xu To: marcel@holtmann.org, gustavo@padovan.org, johan.hedberg@gmail.com, davem@davemloft.net Subject: [PATCH v2] Bluetooth: Add LED triggers for HCI frames tx and rx Date: Sun, 31 Jul 2016 12:24:44 +0800 Message-Id: <1469939084-15603-1-git-send-email-guodong.xu@linaro.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160730_212515_215567_E44B18E2 X-CRM114-Status: GOOD ( 13.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-bluetooth@vger.kernel.org, Guodong Xu , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org MIME-Version: 1.0 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 Two LED triggers are added into hci_dev: tx_led and rx_led. Upon ACL/SCO packets available in tx or rx, the LEDs will blink. For each hci registration, two triggers are added into LED subsystem: [hdev->name]-tx and [hdev-name]-rx. Refer to Documentation/leds/leds-class.txt for usage. Verified on HiKey 96boards, which uses HiSilicon hi6220 SoC and TI WL1835 WiFi/BT combo chip. Signed-off-by: Guodong Xu --- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_core.c | 6 ++++++ net/bluetooth/leds.c | 17 +++++++++++++++++ net/bluetooth/leds.h | 2 ++ 4 files changed, 26 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index dc71473..37b8dd9 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -398,6 +398,7 @@ struct hci_dev { bdaddr_t rpa; struct led_trigger *power_led; + struct led_trigger *tx_led, *rx_led; int (*open)(struct hci_dev *hdev); int (*close)(struct hci_dev *hdev); diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 45a9fc6..956dce1 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3833,6 +3833,7 @@ static void hci_sched_acl(struct hci_dev *hdev) if (!hci_conn_num(hdev, AMP_LINK) && hdev->dev_type == HCI_AMP) return; + hci_leds_blink_oneshot(hdev->tx_led); switch (hdev->flow_ctl_mode) { case HCI_FLOW_CTL_MODE_PACKET_BASED: hci_sched_acl_pkt(hdev); @@ -3856,6 +3857,7 @@ static void hci_sched_sco(struct hci_dev *hdev) if (!hci_conn_num(hdev, SCO_LINK)) return; + hci_leds_blink_oneshot(hdev->tx_led); while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, "e))) { while (quote-- && (skb = skb_dequeue(&conn->data_q))) { BT_DBG("skb %p len %d", skb, skb->len); @@ -3879,6 +3881,7 @@ static void hci_sched_esco(struct hci_dev *hdev) if (!hci_conn_num(hdev, ESCO_LINK)) return; + hci_leds_blink_oneshot(hdev->tx_led); while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK, "e))) { while (quote-- && (skb = skb_dequeue(&conn->data_q))) { @@ -3911,6 +3914,7 @@ static void hci_sched_le(struct hci_dev *hdev) hci_link_tx_to(hdev, LE_LINK); } + hci_leds_blink_oneshot(hdev->tx_led); cnt = hdev->le_pkts ? hdev->le_cnt : hdev->acl_cnt; tmp = cnt; while (cnt && (chan = hci_chan_sent(hdev, LE_LINK, "e))) { @@ -3990,6 +3994,7 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) if (conn) { hci_conn_enter_active_mode(conn, BT_POWER_FORCE_ACTIVE_OFF); + hci_leds_blink_oneshot(hdev->rx_led); /* Send to upper protocol */ l2cap_recv_acldata(conn, skb, flags); @@ -4022,6 +4027,7 @@ static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) hci_dev_unlock(hdev); if (conn) { + hci_leds_blink_oneshot(hdev->rx_led); /* Send to upper protocol */ sco_recv_scodata(conn, skb); return; diff --git a/net/bluetooth/leds.c b/net/bluetooth/leds.c index 8319c84..ae10c5d 100644 --- a/net/bluetooth/leds.c +++ b/net/bluetooth/leds.c @@ -19,6 +19,8 @@ struct hci_basic_led_trigger { #define to_hci_basic_led_trigger(arg) container_of(arg, \ struct hci_basic_led_trigger, led_trigger) +#define BLUETOOTH_BLINK_DELAY 50 /* ms */ + void hci_leds_update_powered(struct hci_dev *hdev, bool enabled) { if (hdev->power_led) @@ -37,6 +39,17 @@ static void power_activate(struct led_classdev *led_cdev) led_trigger_event(led_cdev->trigger, powered ? LED_FULL : LED_OFF); } +void hci_leds_blink_oneshot(struct led_trigger *trig) +{ + unsigned long led_delay = BLUETOOTH_BLINK_DELAY; + + if (!trig) + return; + + BT_DBG("led_trig %p", trig); + led_trigger_blink_oneshot(trig, &led_delay, &led_delay, 0); +} + static struct led_trigger *led_allocate_basic(struct hci_dev *hdev, void (*activate)(struct led_classdev *led_cdev), const char *name) @@ -71,4 +84,8 @@ void hci_leds_init(struct hci_dev *hdev) { /* initialize power_led */ hdev->power_led = led_allocate_basic(hdev, power_activate, "power"); + /* initialize tx_led */ + hdev->tx_led = led_allocate_basic(hdev, NULL, "tx"); + /* initialize rx_led */ + hdev->rx_led = led_allocate_basic(hdev, NULL, "rx"); } diff --git a/net/bluetooth/leds.h b/net/bluetooth/leds.h index a9c4d6e..9b1cccd 100644 --- a/net/bluetooth/leds.h +++ b/net/bluetooth/leds.h @@ -9,8 +9,10 @@ #if IS_ENABLED(CONFIG_BT_LEDS) void hci_leds_update_powered(struct hci_dev *hdev, bool enabled); void hci_leds_init(struct hci_dev *hdev); +void hci_leds_blink_oneshot(struct led_trigger *trig); #else static inline void hci_leds_update_powered(struct hci_dev *hdev, bool enabled) {} static inline void hci_leds_init(struct hci_dev *hdev) {} +static inline void hci_leds_blink_oneshot(struct led_trigger *trig) {} #endif