From patchwork Tue Jan 17 22:02:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 13105135 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16501C00A5A for ; Tue, 17 Jan 2023 22:24:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229531AbjAQWY1 (ORCPT ); Tue, 17 Jan 2023 17:24:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230031AbjAQWXa (ORCPT ); Tue, 17 Jan 2023 17:23:30 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DD7C45F79 for ; Tue, 17 Jan 2023 14:03:29 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id l8so6242343wms.3 for ; Tue, 17 Jan 2023 14:03:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:subject:from:cc:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Xzk8b3fBqLsf5katRnJV2feS2sUT/0Rm8pDNg5Jrg8o=; b=c6Zq1tNb7QfP2GVSG9wrOsObblDAoWx6AThJG6HA05mWlMZ9lUZWy620JynGaG5USy IughVsceKmiHzISZ92mYWAKh8rrjRefAT8yGdGGTVgLcO7MpSro8xG1nZ+i208rpahcJ rUF+cGuEKOg236z8Dggzz2y4ij4buSTvgjDxTGNO5PNJNzSrnA4zThg6LUzcAzEX4CYw d28BtVrrF0Me14JX8GvC5UQ4Gv5DF4JNhXsrV82Bbft9Ub+81vvXmmYi3njHsqf2Ujcs inCbbqh0Zmxm3mBG3ZcyccQrwetlaFUFCYbPeiQoCSqAmnPsu4ftFDBGUIem0UMP1Zvp gNOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:subject:from:cc:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Xzk8b3fBqLsf5katRnJV2feS2sUT/0Rm8pDNg5Jrg8o=; b=CPWollwY2K6h1whgPDw/Lgb4uFtwwNPor3QI7wHZRtP/0iLrL6eTwEQfrvgo9kkDYG R+g+WUbUyYn1rfvd5e9IjTANu64dUcz0Ncu6WCURvcRsnJKgffDZbMgjmawaIAjbZU+l JrlgTiUbmsZzd0G9pfpgFE/UeeAoTbYy9tJSJNiud5k+4t2ikHwDVqBHooqb2hWfsNlV N1Gd1jb62AIP2udRTyq5lv6G7fQI6V5M4rCje/2S4+gY+UUPjtCI5ynhsxRcbmXGqxFY dQzX8/u7zsOroRZMNQ9CfnmdRiorL7AOx8G7c+L6d/+fjbAnErb6mTPJPqLDEGgDI49o JVqg== X-Gm-Message-State: AFqh2koZB3baxOEQIa0EuTrg9XCjNAfKbCJ21tU1AY/a+jbphR5rnMK6 cYzBATgCi3BXHfTrguKNHFNUQH+s3OI= X-Google-Smtp-Source: AMrXdXtsFS+oEorqL5PF48d1Db1NbH67mDk4tQXqdSQXcZiaLQWWYRMwYdz8jmQW+MHsJUibtK8+EA== X-Received: by 2002:a05:600c:4f92:b0:3cf:88c3:d008 with SMTP id n18-20020a05600c4f9200b003cf88c3d008mr13135043wmq.28.1673992980309; Tue, 17 Jan 2023 14:03:00 -0800 (PST) Received: from [192.168.1.50] ([79.119.240.114]) by smtp.gmail.com with ESMTPSA id j35-20020a05600c1c2300b003c71358a42dsm112988wms.18.2023.01.17.14.02.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Jan 2023 14:02:59 -0800 (PST) Message-ID: <5c03ae42-a2fd-b39a-e754-f52d8528a167@gmail.com> Date: Wed, 18 Jan 2023 00:02:58 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Content-Language: en-US To: "linux-wireless@vger.kernel.org" Cc: Jes Sorensen , Ping-Ke Shih From: Bitterblue Smith Subject: [PATCH 1/4] wifi: rtl8xxxu: Register the LED and make it blink Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org If the chip can have an LED, register a struct led_classdev and enable hardware-controlled blinking. When the chip is not transmitting or receiving anything the LED is off. Otherwise the LED will blink faster or slower according to the throughput. The LED can be controlled from userspace by writing 0, 1, or 2 to /sys/class/leds/rtl8xxxu-usbX-Y/brightness: 0 - solid off. 1 - solid on. 2 - hardware-controlled blinking. In this patch none of the chips advertise having an LED. That will be added in the next patches. Signed-off-by: Bitterblue Smith --- .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 8 +++++ .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 34 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h index 90268479d3ad..c8cee4a24755 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h @@ -1443,6 +1443,8 @@ struct rtl8xxxu_cfo_tracking { u32 packet_count_pre; }; +#define RTL8XXXU_HW_LED_CONTROL 2 + struct rtl8xxxu_priv { struct ieee80211_hw *hw; struct usb_device *udev; @@ -1564,6 +1566,10 @@ struct rtl8xxxu_priv { struct rtl8xxxu_ra_report ra_report; struct rtl8xxxu_cfo_tracking cfo_tracking; struct rtl8xxxu_ra_info ra_info; + + bool led_registered; + char led_name[32]; + struct led_classdev led_cdev; }; struct rtl8xxxu_rx_urb { @@ -1613,6 +1619,8 @@ struct rtl8xxxu_fileops { u32 rts_rate); void (*set_crystal_cap) (struct rtl8xxxu_priv *priv, u8 crystal_cap); s8 (*cck_rssi) (struct rtl8xxxu_priv *priv, u8 cck_agc_rpt); + int (*led_classdev_brightness_set) (struct led_classdev *led_cdev, + enum led_brightness brightness); int writeN_block_size; int rx_agg_buf_size; char tx_desc_size; diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c index 35dc777c1fba..b27edd503c23 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c @@ -6955,6 +6955,34 @@ static int rtl8xxxu_parse_usb(struct rtl8xxxu_priv *priv, return ret; } +static void rtl8xxxu_init_led(struct rtl8xxxu_priv *priv) +{ + struct led_classdev *led = &priv->led_cdev; + + led->brightness_set_blocking = priv->fops->led_classdev_brightness_set; + + snprintf(priv->led_name, sizeof(priv->led_name), + "rtl8xxxu-usb%s", dev_name(&priv->udev->dev)); + led->name = priv->led_name; + led->max_brightness = RTL8XXXU_HW_LED_CONTROL; + + if (led_classdev_register(&priv->udev->dev, led)) + return; + + priv->led_registered = true; + + led->brightness = led->max_brightness; + priv->fops->led_classdev_brightness_set(led, led->brightness); +} + +static void rtl8xxxu_deinit_led(struct rtl8xxxu_priv *priv) +{ + struct led_classdev *led = &priv->led_cdev; + + priv->fops->led_classdev_brightness_set(led, LED_OFF); + led_classdev_unregister(led); +} + static int rtl8xxxu_probe(struct usb_interface *interface, const struct usb_device_id *id) { @@ -7135,6 +7163,9 @@ static int rtl8xxxu_probe(struct usb_interface *interface, goto err_set_intfdata; } + if (priv->fops->led_classdev_brightness_set) + rtl8xxxu_init_led(priv); + return 0; err_set_intfdata: @@ -7159,6 +7190,9 @@ static void rtl8xxxu_disconnect(struct usb_interface *interface) hw = usb_get_intfdata(interface); priv = hw->priv; + if (priv->led_registered) + rtl8xxxu_deinit_led(priv); + ieee80211_unregister_hw(hw); priv->fops->power_off(priv); From patchwork Tue Jan 17 22:04:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 13105136 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDB4EC00A5A for ; Tue, 17 Jan 2023 22:26:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229765AbjAQW0S (ORCPT ); Tue, 17 Jan 2023 17:26:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229732AbjAQWZv (ORCPT ); Tue, 17 Jan 2023 17:25:51 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 138727F9B7 for ; Tue, 17 Jan 2023 14:04:07 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id b5so10918679wrn.0 for ; Tue, 17 Jan 2023 14:04:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=JLy1kCz5UNSqomVwOwqBMNik0CT6fDAtXmToAhAg8Uk=; b=KVraa78SesXaCaLgojVFxs5yDr5mEaAwj4W0YjI4Pumw8mRo6QLGDI7IK0ohE4/AON EzHN9zh2r884zJg1fjfuJvDQ1s28/cYoVuFC0LTIuN67DIjcBM9gqYLbVzUY3P5aWe4w 2VNR3zqbKa04riNfQhbS+kUKShstb9sakGe+vhokXPayx4i3sCgHRiBjC80utH8m+LsK CcdpY6Xs/itu36x9xngT0O8Nkm42U2zpprvczgoaSh7UXIjkpKLcjyFKZOsG21hOTgd0 ozO232aThcZaJISwMej/MX+KKhX/A/QfdHIcKla6J6ymuoCNAqb8XGTq9x4lvX7vSDV/ PXRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JLy1kCz5UNSqomVwOwqBMNik0CT6fDAtXmToAhAg8Uk=; b=ZSbUKK0Xg00E9+QSdz4zdcWtwHBCadNo1hADq6S/4n8+arm4oJEQmhujnXUl99xObb 2p+aKPkaxFfiw5udvzQevYBrBAnPLUtHh4Cgz2DXWiDVkSwLRz8GqFgTTgwzFj7EgIWc ow7vt0MtmZGMH7xpbf8fUsvfp0QQVUrHcsY2YuNWL4JLv336Ah+7rQYz3hHQdLyuu68v tPh1EqdMleXdh1l4S6zKo2z3Rno5Fk+zkrdBx4p4gvZz+op5Zll1ljsxfWUYQ40Lh0Mb 1V1wFRhBmh6WdJFX3VbG8sQlQB5LugbKRVKQBDIeWypO9dawCPMGc7eeXvJPfp1cF9Gb 0C2A== X-Gm-Message-State: AFqh2kqmlhk+jj2nCmN5IHyOynDqppWw1PPed6R+WTH1el0SYReCh9PM FUY1W9H+r2iFwxxIc6W8YCdNAeVz2Eg= X-Google-Smtp-Source: AMrXdXudzILa8y2E9YPltzAQDDseW9OKNEdp8Ec5PyB6cY0ZsvAbI2ovTvlzCNiAx6dfl2w1029BwA== X-Received: by 2002:adf:de81:0:b0:2bd:dc5c:7e4c with SMTP id w1-20020adfde81000000b002bddc5c7e4cmr3932652wrl.15.1673993046211; Tue, 17 Jan 2023 14:04:06 -0800 (PST) Received: from [192.168.1.50] ([79.119.240.114]) by smtp.gmail.com with ESMTPSA id g11-20020a5d488b000000b002bc7e5a1171sm22869593wrq.116.2023.01.17.14.04.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Jan 2023 14:04:05 -0800 (PST) Message-ID: <77a0ec12-3711-7f21-5b99-95388f0648b1@gmail.com> Date: Wed, 18 Jan 2023 00:04:04 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: [PATCH 2/4] wifi: rtl8xxxu: Add LED control code for RTL8188EU Content-Language: en-US From: Bitterblue Smith To: "linux-wireless@vger.kernel.org" Cc: Jes Sorensen , Ping-Ke Shih References: <5c03ae42-a2fd-b39a-e754-f52d8528a167@gmail.com> In-Reply-To: <5c03ae42-a2fd-b39a-e754-f52d8528a167@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org By default the LED will blink when there is some activity. This was tested with a TP-Link TL-WN725N. Signed-off-by: Bitterblue Smith Reviewed-by: Ping-Ke Shih --- .../realtek/rtl8xxxu/rtl8xxxu_8188e.c | 25 +++++++++++++++++++ .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h | 4 +++ 2 files changed, 29 insertions(+) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c index 08f3b93ad8d0..a99ddb41cd24 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c @@ -1350,6 +1350,30 @@ static s8 rtl8188e_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt) return rx_pwr_all; } +static int rtl8188eu_led_brightness_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct rtl8xxxu_priv *priv = container_of(led_cdev, + struct rtl8xxxu_priv, + led_cdev); + u8 ledcfg = rtl8xxxu_read8(priv, REG_LEDCFG2); + + if (brightness == LED_OFF) { + ledcfg &= ~LEDCFG2_HW_LED_CONTROL; + ledcfg |= LEDCFG2_SW_LED_CONTROL | LEDCFG2_SW_LED_DISABLE; + } else if (brightness == LED_ON) { + ledcfg &= ~(LEDCFG2_HW_LED_CONTROL | LEDCFG2_SW_LED_DISABLE); + ledcfg |= LEDCFG2_SW_LED_CONTROL; + } else if (brightness == RTL8XXXU_HW_LED_CONTROL) { + ledcfg &= ~LEDCFG2_SW_LED_DISABLE; + ledcfg |= LEDCFG2_HW_LED_CONTROL | LEDCFG2_HW_LED_ENABLE; + } + + rtl8xxxu_write8(priv, REG_LEDCFG2, ledcfg); + + return 0; +} + static void rtl8188e_set_tx_rpt_timing(struct rtl8xxxu_ra_info *ra, u8 timing) { u8 idx; @@ -1851,6 +1875,7 @@ struct rtl8xxxu_fileops rtl8188eu_fops = { .fill_txdesc = rtl8xxxu_fill_txdesc_v3, .set_crystal_cap = rtl8188f_set_crystal_cap, .cck_rssi = rtl8188e_cck_rssi, + .led_classdev_brightness_set = rtl8188eu_led_brightness_set, .writeN_block_size = 128, .rx_desc_size = sizeof(struct rtl8xxxu_rxdesc16), .tx_desc_size = sizeof(struct rtl8xxxu_txdesc32), diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h index 5818b2378bab..d510ce27b1b4 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h @@ -148,6 +148,10 @@ #define LEDCFG0_DPDT_SELECT BIT(23) #define REG_LEDCFG1 0x004d #define REG_LEDCFG2 0x004e +#define LEDCFG2_HW_LED_CONTROL BIT(1) +#define LEDCFG2_HW_LED_ENABLE BIT(5) +#define LEDCFG2_SW_LED_DISABLE BIT(3) +#define LEDCFG2_SW_LED_CONTROL BIT(5) #define LEDCFG2_DPDT_SELECT BIT(7) #define REG_LEDCFG3 0x004f #define REG_LEDCFG REG_LEDCFG2 From patchwork Tue Jan 17 22:05:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 13105137 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30019C38142 for ; Tue, 17 Jan 2023 22:27:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229748AbjAQW1u (ORCPT ); Tue, 17 Jan 2023 17:27:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbjAQW0w (ORCPT ); Tue, 17 Jan 2023 17:26:52 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F10DBF5ED for ; Tue, 17 Jan 2023 14:05:11 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id l8so6245884wms.3 for ; Tue, 17 Jan 2023 14:05:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=7a3Zpknh1kjtBdBo4Hw/KvpGh+L2eeCDBsAjPGHPdhc=; b=mbPcIZaBLMRjEx2TQBHTDzOQiYuEhsRucvUaN02rRUZsLBXQpOO3dKRlGMiD4DmU+g qqluJJo0y9Mrk5kiQn5W6D1/fyo+hNpsoNbmmoksjXy5fu0fVU12AY1gIHjD7kYwfxit TxLHkk0apaAKO/ib6Oda+Id5aoUmw70cMQRsxU7WaR+rqRd/XNReuKtqbxrgmdR1+KB5 LGCppApJbqzd+RVpyl05HeEe7LJ1gBTLieAnCMrMTLvkZFf17VuosNqlQwY/k5uj+2RY bVXS1laXwMIForxo/I7IeLyeFOUmDLKDMM+MGCgujjeRrQVDBJRgKiNbCiHItgqmx8kN k1XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7a3Zpknh1kjtBdBo4Hw/KvpGh+L2eeCDBsAjPGHPdhc=; b=g0zPT/bhBJZIEoYTjbMfFccznd/NlvzlNyKMYaytD3oS62efWuTRyQYghq0FVH//Ai ZDZ9mBR56pNXH7O7ks7RoNlASk/T4G/FDhCRF1YkX8oYLXeZri0qFpSfecSIU/nU9zAY mwOBRzwVT7cLsAEgm1QCNtsMVKzFrHZ3VWyOOynUUGzaeiTnigsv/NxxmlziMrOOfwZz uGNY1bArRS3On4BlaHLfPDRa/LlceHguppr/8h4NL1yfYewkHIZLjtAQU95UufAh0cIT 1ogg5DkqIAZTQzBmPusQpJhqumelndKXZkrIBqrxRQX9clI2hggn2X58GAftxyi7kLNg gusQ== X-Gm-Message-State: AFqh2kq/pbpMfmC7eUNCFGLIevHbndtZosRy6ctZqVG+V7RqYPoFuIS8 uTBmKxiGSf/I33oXaQbFuBfNZHO83uU= X-Google-Smtp-Source: AMrXdXsz73mDXulFyHVNFvQvDt73uITQv9qbzW5z9u3c5h5qn5bery04xmRGyJRNII8CjPb3tBLY8A== X-Received: by 2002:a05:600c:3d9b:b0:3db:fc4:d003 with SMTP id bi27-20020a05600c3d9b00b003db0fc4d003mr760646wmb.33.1673993104281; Tue, 17 Jan 2023 14:05:04 -0800 (PST) Received: from [192.168.1.50] ([79.119.240.114]) by smtp.gmail.com with ESMTPSA id fk6-20020a05600c0cc600b003c6b70a4d69sm42010wmb.42.2023.01.17.14.05.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Jan 2023 14:05:03 -0800 (PST) Message-ID: <5f105f2e-a829-d0b1-92ac-a0ab90511c38@gmail.com> Date: Wed, 18 Jan 2023 00:05:03 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: [PATCH 3/4] wifi: rtl8xxxu: Add LED control code for RTL8192EU Content-Language: en-US From: Bitterblue Smith To: "linux-wireless@vger.kernel.org" Cc: Jes Sorensen , Ping-Ke Shih References: <5c03ae42-a2fd-b39a-e754-f52d8528a167@gmail.com> In-Reply-To: <5c03ae42-a2fd-b39a-e754-f52d8528a167@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org By default the LED will blink when there is some activity. This was tested with a cheap "HT-WR813" from Aliexpress. Signed-off-by: Bitterblue Smith Reviewed-by: Ping-Ke Shih --- .../realtek/rtl8xxxu/rtl8xxxu_8192e.c | 24 +++++++++++++++++++ .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c index 4a1c9bcafe31..5cfc00237f42 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c @@ -1764,6 +1764,29 @@ static s8 rtl8192e_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt) return rx_pwr_all; } +static int rtl8192eu_led_brightness_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct rtl8xxxu_priv *priv = container_of(led_cdev, + struct rtl8xxxu_priv, + led_cdev); + u8 ledcfg = rtl8xxxu_read8(priv, REG_LEDCFG1); + + if (brightness == LED_OFF) { + ledcfg &= ~LEDCFG1_HW_LED_CONTROL; + ledcfg |= LEDCFG1_LED_DISABLE; + } else if (brightness == LED_ON) { + ledcfg &= ~(LEDCFG1_HW_LED_CONTROL | LEDCFG1_LED_DISABLE); + } else if (brightness == RTL8XXXU_HW_LED_CONTROL) { + ledcfg &= ~LEDCFG1_LED_DISABLE; + ledcfg |= LEDCFG1_HW_LED_CONTROL; + } + + rtl8xxxu_write8(priv, REG_LEDCFG1, ledcfg); + + return 0; +} + struct rtl8xxxu_fileops rtl8192eu_fops = { .identify_chip = rtl8192eu_identify_chip, .parse_efuse = rtl8192eu_parse_efuse, @@ -1788,6 +1811,7 @@ struct rtl8xxxu_fileops rtl8192eu_fops = { .fill_txdesc = rtl8xxxu_fill_txdesc_v2, .set_crystal_cap = rtl8723a_set_crystal_cap, .cck_rssi = rtl8192e_cck_rssi, + .led_classdev_brightness_set = rtl8192eu_led_brightness_set, .writeN_block_size = 128, .tx_desc_size = sizeof(struct rtl8xxxu_txdesc40), .rx_desc_size = sizeof(struct rtl8xxxu_rxdesc24), diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h index d510ce27b1b4..5849fa4e1566 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h @@ -147,6 +147,8 @@ #define REG_LEDCFG0 0x004c #define LEDCFG0_DPDT_SELECT BIT(23) #define REG_LEDCFG1 0x004d +#define LEDCFG1_HW_LED_CONTROL BIT(1) +#define LEDCFG1_LED_DISABLE BIT(7) #define REG_LEDCFG2 0x004e #define LEDCFG2_HW_LED_CONTROL BIT(1) #define LEDCFG2_HW_LED_ENABLE BIT(5) From patchwork Tue Jan 17 22:05:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 13105140 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71672C00A5A for ; Tue, 17 Jan 2023 22:28:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229510AbjAQW2j (ORCPT ); Tue, 17 Jan 2023 17:28:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbjAQW1q (ORCPT ); Tue, 17 Jan 2023 17:27:46 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98D6E5CFCB for ; Tue, 17 Jan 2023 14:06:01 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id b7so6097066wrt.3 for ; Tue, 17 Jan 2023 14:06:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=CX8hTnGqPq0dkyhSl1D/8iviiGz5rnkOBochjNST6f8=; b=BOg7gHpLJ8PUED61KwPMeGtJ+kA9X5UN+chw4+t/QYZoTRk4q2wFoPV/S8TfF4rvQu ecKANHTSngZtVPpktKdwzigNYPNqyQ3D+I9LKBfHGo3Fbg998RDXjGAhu7YiSDPBhsrW iJp+A7s4FqOB5gVF6LHNfZtFNAzWM84GR5tEh/9mXfPLIna46xPYU/aa1b7Rs1s/7l2N 2oBmZ3ZxaBdHmjOXhmg3cuJKhKjKtNjETQSEVnyWJa0QkbXfiXxwmErWpfLEY2Nvl1PC WnNUotv2B8zHIBMC+shqRizoR5vLhwqK32mqL6vdz6jN03jZp+P9xfPtGDgHhwvvdGt0 pQkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CX8hTnGqPq0dkyhSl1D/8iviiGz5rnkOBochjNST6f8=; b=CC+BXYZQjf1ph/AErCnLyAY9d+uhNqp3T3HZUc/oU9MTnUOyNQbol0e/nNZS/kOFfd bvrihGee5LXjewO9lU1rKJJ03PmI74Pr8GZdsO+7aa8FSAIiNzXDmLmRhFV9zVKgytBe neIM2dwBm2KWB7I/wd2d1euOb/bI7Eg7HrQub7RlF/Az0aLAqWHV8N5mVq7mnymlkMao Jeb4zvO0BDZKq8dSTpelif9o6PhOypi5FeB/HugUnouLz0eWCvSqtb3jUsB1x2lYOS78 VSEyrstfaeiLMbMkc6zx2x726zJ2/PLVKV5BdttkuyCwdSfiw9HkwBU60y/JdNwrPiqt DMEw== X-Gm-Message-State: AFqh2krYZF/XQ0LSZk3Rtkjpsw7z7KVpzgKI0teHw9aclmH/jWrxlkGR Qr5mhF9fD3XtGgbAt6r/gvc4LifvAGM= X-Google-Smtp-Source: AMrXdXuxFIDOWQl9i4M61A8qPhdeE7U//3vUi25kCjx4B2q9QDVXz1SPNJRCMZiArHJz86x4sL9hww== X-Received: by 2002:a5d:5954:0:b0:2bd:bdb5:baf1 with SMTP id e20-20020a5d5954000000b002bdbdb5baf1mr3888201wri.10.1673993160059; Tue, 17 Jan 2023 14:06:00 -0800 (PST) Received: from [192.168.1.50] ([79.119.240.114]) by smtp.gmail.com with ESMTPSA id r18-20020a5d4952000000b002bdda9856b5sm14157779wrs.50.2023.01.17.14.05.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Jan 2023 14:05:59 -0800 (PST) Message-ID: Date: Wed, 18 Jan 2023 00:05:58 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: [PATCH 4/4] wifi: rtl8xxxu: Add LED control code for RTL8723AU Content-Language: en-US From: Bitterblue Smith To: "linux-wireless@vger.kernel.org" Cc: Jes Sorensen , Ping-Ke Shih References: <5c03ae42-a2fd-b39a-e754-f52d8528a167@gmail.com> In-Reply-To: <5c03ae42-a2fd-b39a-e754-f52d8528a167@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org By default the LED will blink when there is some activity. This is only compile tested. Signed-off-by: Bitterblue Smith Reviewed-by: Ping-Ke Shih --- .../realtek/rtl8xxxu/rtl8xxxu_8723a.c | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c index 5ed523db2d87..5e7b58d395ba 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c @@ -457,6 +457,30 @@ s8 rtl8723a_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt) return rx_pwr_all; } +static int rtl8723au_led_brightness_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct rtl8xxxu_priv *priv = container_of(led_cdev, + struct rtl8xxxu_priv, + led_cdev); + u8 ledcfg = rtl8xxxu_read8(priv, REG_LEDCFG2); + + if (brightness == LED_OFF) { + ledcfg &= ~LEDCFG2_HW_LED_CONTROL; + ledcfg |= LEDCFG2_SW_LED_CONTROL | LEDCFG2_SW_LED_DISABLE; + } else if (brightness == LED_ON) { + ledcfg &= ~(LEDCFG2_HW_LED_CONTROL | LEDCFG2_SW_LED_DISABLE); + ledcfg |= LEDCFG2_SW_LED_CONTROL; + } else if (brightness == RTL8XXXU_HW_LED_CONTROL) { + ledcfg &= ~LEDCFG2_SW_LED_DISABLE; + ledcfg |= LEDCFG2_HW_LED_CONTROL | LEDCFG2_HW_LED_ENABLE; + } + + rtl8xxxu_write8(priv, REG_LEDCFG2, ledcfg); + + return 0; +} + struct rtl8xxxu_fileops rtl8723au_fops = { .identify_chip = rtl8723au_identify_chip, .parse_efuse = rtl8723au_parse_efuse, @@ -482,6 +506,7 @@ struct rtl8xxxu_fileops rtl8723au_fops = { .fill_txdesc = rtl8xxxu_fill_txdesc_v1, .set_crystal_cap = rtl8723a_set_crystal_cap, .cck_rssi = rtl8723a_cck_rssi, + .led_classdev_brightness_set = rtl8723au_led_brightness_set, .writeN_block_size = 1024, .rx_agg_buf_size = 16000, .tx_desc_size = sizeof(struct rtl8xxxu_txdesc32),