Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2832872rwb; Fri, 20 Jan 2023 07:57:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXtk4MbJNkDYSenH/O5bTB75Ow6GAh8vqNkd5NQ7DNO8PYxCQl+xJe+F22H6Ei1HJLZSTqMG X-Received: by 2002:a17:906:3f94:b0:861:4671:a834 with SMTP id b20-20020a1709063f9400b008614671a834mr14400119ejj.71.1674230244856; Fri, 20 Jan 2023 07:57:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674230244; cv=none; d=google.com; s=arc-20160816; b=FSn+yIxbYNto4D+LZQg1wa1qqYORWiAAEf4DAliXzO5dNp+w50lWko3fPc8JidI8jw HrjSHTlDPkFv97o+CdI1crQaYGixS2HY6DR/Xuldnb+fSnNjWh/OIgchyPTZk0e2aRM5 KkqrBHvf/d1meEj3O9348MemkC1rkrWQPFJC1FfG6zPolkpclQhr1Mi9NYctssodZYvt OxWqX8I1AcK0ArPjBw+7lP3LYv4WXrWmctC+FDAry7Oodrp7joi04IGE0ezfFhhpU9mB 2/bkx1Jxwr80Dnv2iSbBSeoEsNqXI+j47z1WHO41pmy8W1YN6PP2uUU1DdVieryfox4W VNzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id :dkim-signature; bh=jji6c1AytbJ/adGMKBmPccCwXiPMA40IqqAENpcIbdM=; b=R6rpJMxiWEINsK1fAybjL8qZak2N93MM01IplOOi3eObXHoDmbCjrxHfBFpAOaL/4e JO/CwCapEC3cVti0RgSFvcTn2y3q4rRFPFrbuD4EO5f4TUJYqTCt6+rX3thpAXZoIE5G csPJGdojDdIQ4eDo5FwuD8FFQ3UUBRoyhAr7OyrwR8EwiDL5Wv3y70Gi7cyj4YTuTXch v7O1YmiXhL/DPmhHsWBPy0kx4LY/aGmj1c80SqjQn6pc/0ZcqaG3LBERzs6EHyyKgXRP p9kcGDhieI4cQTV1TgAKOtxaNt1CXwcN+7CxW3vqsZIGMzfTeEuG/ZSpWomlCCUFouLo tOYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZTQshhzu; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb16-20020a170907161000b0086f0552517asi22228917ejc.830.2023.01.20.07.57.05; Fri, 20 Jan 2023 07:57:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZTQshhzu; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230262AbjATPvl (ORCPT + 63 others); 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-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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 --- 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); -- 2.39.1