From patchwork Fri Jan 20 15:51:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 645032 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 A2C73C05027 for ; Fri, 20 Jan 2023 15:51:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230262AbjATPvl (ORCPT ); Fri, 20 Jan 2023 10:51:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230380AbjATPvi (ORCPT ); Fri, 20 Jan 2023 10:51:38 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F535C9260 for ; Fri, 20 Jan 2023 07:51:27 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id d2so5213200wrp.8 for ; Fri, 20 Jan 2023 07:51:27 -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=jji6c1AytbJ/adGMKBmPccCwXiPMA40IqqAENpcIbdM=; b=ZTQshhzu20g5AnxPUDMenwYAdejQDMjbIk0849zA8MX2atuBKZSxZbIP6eBsMDu481 6cxsI3JgUqfiWXNv2V0MlfQIETLyy1hnOq+ECzz6dSZtb1s0LAUezAjFG9C3j6cjCPXd c/mTK5dX+NwoHSPW8xZND47jongT5i3Kz5w4P5cc7wNyZ/AnVZLd80v1lkpZnnznNfWr WpVB020TxYvhid2d6P8bBWjGvXFceM1Oaq/5d3UNshxxmEGghWprZxhk1SzmpyhWBzO/ 7wdoqtBjsfKSsMwKKUmLoha4rf3O0vnsh1nSr/XyXnCLtJKKRblwtgUuKV3wkaMiZgUT GKhg== 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=jji6c1AytbJ/adGMKBmPccCwXiPMA40IqqAENpcIbdM=; b=Tu2QXJhZKqxfqvg9vCr/YNBCAPv7wTtDJ50kAtsxLQLwRsXwA1KtYbMRYbko74+jY9 vlUMPLGgLlQvxa+R/1J0qOCAGblOY4Baa+1JIYetuXwEpjHkn320dKZP/HfyKeigVmzx 0bC5K71/11JWW9DNNBhnJK/g3P4v975zT3ct/A1iZOCvVf3MJvnGWJc4pEkO+zn7nxRV Ow1g6OfQF9bHCu2+hUoKU2sqdbXfL4UUag19c0oYLq6uFN55MjnY5OpPRk8F8TL/h/T1 bzD5XW4lyleb//yriPQZPgM6F8I8AkfEuacZqYA9WWw5FYjgfd7TQs/aycwu8550BsrT J6iw== X-Gm-Message-State: AFqh2krmhZR5C/M/vV56JcFDN41BAHLdm+GfyFlOTRBGcuc/4I/8+j36 dt8wwioE0TNeoCgSgCXgJ9tpJrbu+zk= X-Google-Smtp-Source: AMrXdXs72+qb1PQYolScog7WuqQM9AyXW1XidTFmIkVI0qeKDl06gseewPzeMNd3PaLhYrqPnUYtRQ== X-Received: by 2002:a05:6000:a03:b0:2b9:9e7b:be6b with SMTP id co3-20020a0560000a0300b002b99e7bbe6bmr14346480wrb.45.1674229885977; Fri, 20 Jan 2023 07:51:25 -0800 (PST) Received: from [192.168.1.50] ([79.119.240.25]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b002bdd21f25ebsm21678853wrq.71.2023.01.20.07.51.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Jan 2023 07:51:25 -0800 (PST) Message-ID: Date: Fri, 20 Jan 2023 17:51:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Content-Language: en-US To: "linux-wireless@vger.kernel.org" Cc: Jes Sorensen , Ping-Ke Shih From: Bitterblue Smith Subject: [PATCH v2 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 Reviewed-by: Ping-Ke Shih Reviewed-by: Ping-Ke Shih Reviewed-by: Ping-Ke Shih --- v2: - Suggestion from Ping-Ke Shih: - Check for led_classdev_brightness_set inside rtl8xxxu_init_led() and for led_registered inside rtl8xxxu_deinit_led() instead of checking for them in the caller functions. --- .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 8 ++++ .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 38 +++++++++++++++++++ 2 files changed, 46 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..b25c7efcdec8 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c @@ -6955,6 +6955,40 @@ 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; + + if (!priv->fops->led_classdev_brightness_set) + return; + + 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; + + if (!priv->led_registered) + return; + + 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 +7169,8 @@ static int rtl8xxxu_probe(struct usb_interface *interface, goto err_set_intfdata; } + rtl8xxxu_init_led(priv); + return 0; err_set_intfdata: @@ -7159,6 +7195,8 @@ static void rtl8xxxu_disconnect(struct usb_interface *interface) hw = usb_get_intfdata(interface); priv = hw->priv; + rtl8xxxu_deinit_led(priv); + ieee80211_unregister_hw(hw); priv->fops->power_off(priv); From patchwork Fri Jan 20 15:52:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 645549 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 87A40C05027 for ; Fri, 20 Jan 2023 15:52:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230440AbjATPwt (ORCPT ); Fri, 20 Jan 2023 10:52:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231573AbjATPws (ORCPT ); Fri, 20 Jan 2023 10:52:48 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64F694B4A1 for ; Fri, 20 Jan 2023 07:52:46 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id f25-20020a1c6a19000000b003da221fbf48so4030774wmc.1 for ; Fri, 20 Jan 2023 07:52:46 -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=eGnHjCFuLsS9i5O2gMuu9ltzW4AuhZE76peUc2103pc=; b=GWP8DcZh1mNPVHXRgGHnMsK1nnQ9224fRJaSVoFxs7LGd4oU9h9wUl6Ym7LvRrqJeJ Pgh0o+WRS+1EN1HSPTl3N67Q7p7z1/V7TsX3o9ATZ+QXc/qB0c70WN4/fmy41s7nJeCt Mgxvw4on2eoxCGCFh/L1oOWlPFiH8T8gh39WS1oNCHfk4X06Yw59OyAsXAZF53LMvoKH 5bXNAlX7z2lGaremANaC1xFU+Wi7ZSABeCfAlauOU6AlwaSQjAlTc6hZ9lgdo8YEWmNA BiGvtFog2Uyb5sTzwZS7hPQNq3KDMOQlX/scgLhec2wj7VC8cWH313qTHcdAWWMdv9Sk AEZg== 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=eGnHjCFuLsS9i5O2gMuu9ltzW4AuhZE76peUc2103pc=; b=Vkdc7k5emxHTfijmr5iwl78JyI1pPtDva4UMZ5B8tcA9BEq/G81Svx3b+F6tKwl0pK uWVXLFDPrIFuhvzqwxT+xUmR8rbQxggpOwWQnxdVvk2LqdvJsBQ2QkweTpRAD6zZmvXi /rjLzsURe/G1+YQS7T7GYY8JHk5xh2AT/AKI/oKhb40ExE9vSBLA6UOVzNPjmefB0UiK 1qY5Ke1aqW+d1w/CufFWNwFLdf2JplqrIPGAK82sBLWpqMmQeKTOlVeFwXmOilh4f+Ab H31WAcH55ZIop3OVeH2TP9nVkqY/AD+B3eZPADfc+tuNaDL9f0uwqfMXoAiQBQXwndJF cJLA== X-Gm-Message-State: AFqh2kqmS/Xvi4ws3QfAjKY2TcmVxKeM1U/RT25hR1GxFMeXVVDCQyIn 0knitBfdBwBfxgHq5cdodFux4sB94Ds= X-Google-Smtp-Source: AMrXdXsqDSMP/cIClCk6/rFpEyWN8xXPXp70b8VrAd02SZ0IsmgSlLBMQTtr7e/8Ae9gCruKmRWXJA== X-Received: by 2002:a1c:7315:0:b0:3d3:5a4a:9101 with SMTP id d21-20020a1c7315000000b003d35a4a9101mr23104732wmb.23.1674229964827; Fri, 20 Jan 2023 07:52:44 -0800 (PST) Received: from [192.168.1.50] ([79.119.240.25]) by smtp.gmail.com with ESMTPSA id m27-20020a05600c3b1b00b003db012d49b7sm12980786wms.2.2023.01.20.07.52.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Jan 2023 07:52:44 -0800 (PST) Message-ID: <34d62bf5-3595-0c77-2ca7-be78555f765d@gmail.com> Date: Fri, 20 Jan 2023 17:52:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 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: In-Reply-To: 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 --- v2: - No change. --- .../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 Fri Jan 20 15:54:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 645031 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 E9556C05027 for ; Fri, 20 Jan 2023 15:54:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231263AbjATPym (ORCPT ); Fri, 20 Jan 2023 10:54:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231642AbjATPye (ORCPT ); Fri, 20 Jan 2023 10:54:34 -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 A6C51E050D for ; Fri, 20 Jan 2023 07:54:24 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id t5so5256321wrq.1 for ; Fri, 20 Jan 2023 07:54:24 -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=mbgUxd/FRuWN3nrz37DBIuagPrn/BWA4uSjLuDTkrWQ=; b=A+Q6KI8eikgNEmDX2+f/G6ayCSXBfCh4S6WWBih+Lqba28BphKj8YlECd6IaB62Lkn KWUg385oQx4Fv6oq55LYEuEmB30XaJwidI7ga57Rermc7h+LCek2csP8lY6sLSN15vsy v+nfmC6mOwsyl/FFQcZu267NWP0nnxoJxEyHJLVOH7RMtd81t4d6lqHHL6keb0KNyPIO 428Do+axWpST4eU1n1Ma+WUdlMomO9xSY26nvqclXX9kyyGEMFt3wn/5wt91h0pFAUei 49w7Il+2YMm5o6O8iMtbkZuo2BXr1vdO78W+k0e1u7UZB7faKdbTZrI64gUOyVYEBt2H k5lQ== 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=mbgUxd/FRuWN3nrz37DBIuagPrn/BWA4uSjLuDTkrWQ=; b=g1W5i9JpRhJn9L25s3o41uDHSgw/cI4GuadKkHepb8nfTF8XWeLoICSzwTUKUrcAjQ f0SxocuTvjdwSeJ5NJSrre5s0IalFmbIajWzQBZ7/YdDdjThsImycS91rmhXfgLspOmP A80+YIK0qgmlA2i2pUqQbMKSzunQsHVbHQNiGGyigoS1GRi5hvIcp/jw6rzaK6Bytzo3 WOB1r1zr5/NKUpFy1Kp2/xY88QkeFp2G86DkqE7CnKqaqV5KrwPYA46WJj2yreZJOr75 02maDEEw0vzW1sWrhHnYKzgGDSPzEJ799B2BF2YmonAE/4x9dVZoWzEWpCYliasUBO7r citQ== X-Gm-Message-State: AFqh2kqbqS4NQxrsa+Y3FVuzTY8BwXq6idSB6DQ9qfE7A+kdpudPyzH4 OJTJi3GI+NHq6rkr/YPM/EgyddlJqWk= X-Google-Smtp-Source: AMrXdXtAoXfBnjPlAc4vIc+8xv4urf42tRQMWBhvW9hPDFD0gbqf0h8uzeCa7tnij9GXbnxfaC53/w== X-Received: by 2002:a05:6000:689:b0:2bb:b17e:789 with SMTP id bo9-20020a056000068900b002bbb17e0789mr15164784wrb.58.1674230063179; Fri, 20 Jan 2023 07:54:23 -0800 (PST) Received: from [192.168.1.50] ([79.119.240.25]) by smtp.gmail.com with ESMTPSA id i6-20020adfe486000000b002423dc3b1a9sm35706506wrm.52.2023.01.20.07.54.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Jan 2023 07:54:22 -0800 (PST) Message-ID: <8f7fd5d7-5baa-b38b-ad2a-977dcd9edd81@gmail.com> Date: Fri, 20 Jan 2023 17:54:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 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: In-Reply-To: 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 --- v2: - No change. --- .../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 Fri Jan 20 15:55:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 645548 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 591FEC05027 for ; Fri, 20 Jan 2023 15:55:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230313AbjATPzr (ORCPT ); Fri, 20 Jan 2023 10:55:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbjATPzp (ORCPT ); Fri, 20 Jan 2023 10:55:45 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF080707D7 for ; Fri, 20 Jan 2023 07:55:18 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id q5so588712wrv.0 for ; Fri, 20 Jan 2023 07:55:18 -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=OPgudPCXIBy6FiAHmJXsCq9ARHh8PWxYE16rm8TRgaU=; b=n9TwHVB2us0yshwEPLc1rxmtTj1QaYPkrmblQhezOKREF2v1gtxJ7QqpNLI4h4/9+D wnBMtRXMoaMxHHu69rDqtoUCmbons9NqnVsGBjNcwAWGG3wpLc9euO6YD1IZLTszidnO oQMzoXnyXvBDtcKy98QxCC52P4S/htSZowyq0ZiYGHnfnPPAyNfKkMeDdNRxA9m5KIn0 OdoIgnDc0l7JearCgGFWahKUWHFNLeEGn/FWBHjolTns8afanVQxd19/N5cLuimpoLOd 4rmbYtgD3HaecxCE1XJ9LYUvYMB5w3qgkejcVNOFV81KXlYRJTXqjbMg4IOmE1z+hOIY teGg== 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=OPgudPCXIBy6FiAHmJXsCq9ARHh8PWxYE16rm8TRgaU=; b=dlD3GIicbrILT0CZ5z/tZgI8C8N12HLU/SBceAbM9XYJUusXZLWWvUSUN5mhG7ZLSW 76AitC0CPOB/S9+SmWFbJlk3Fz7Rs29hrkc4K+F2nAhHKzvGuXiHm3K/RTjQhtIdn0O6 wLZmHbklH513MRLUlIUwbiEGJ39WSJba5II+id8mVZ3QOgKh6SsxmYddIuKUCUeG5Ig5 76clFYhoE9pWgYQTAb5GZByTnGdEPEge8tUcUAhN4DlrQRq8yUUnFrDig9vMqOq6POES i1atUadRMvEL5ELaNDpU99XgYLAM0iL44w2TqV8/Lnr+HA8axqlVu2DgQyEgqkAU2OOK 0WNw== X-Gm-Message-State: AFqh2koILfLP5ovficYGt+H4ERhzrTdwmrLxHYzhUvtO+xEmMQ2zbdkZ umo6OTyQpSP0/0HNQ4Z5aAbuuTBWHC0= X-Google-Smtp-Source: AMrXdXtggqCoCofyT/Q6zYRe0VY03AqzKE8FE8NB0KVvCEvSu/rsSfhI3XzBbvbh5HdFWKplIRzWRA== X-Received: by 2002:a05:6000:3c2:b0:2bd:beff:9c47 with SMTP id b2-20020a05600003c200b002bdbeff9c47mr15405043wrg.67.1674230114086; Fri, 20 Jan 2023 07:55:14 -0800 (PST) Received: from [192.168.1.50] ([79.119.240.25]) by smtp.gmail.com with ESMTPSA id q23-20020adfb197000000b002be5bdbe40csm1874302wra.27.2023.01.20.07.55.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Jan 2023 07:55:13 -0800 (PST) Message-ID: <73323811-aa58-a1be-7867-a5d45b7ae3d6@gmail.com> Date: Fri, 20 Jan 2023 17:55:09 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 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: In-Reply-To: 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 --- v2: - No change. --- .../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),