Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2527507rdb; Tue, 12 Sep 2023 05:01:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmczS0rhspMFruR+Dpf1G2pTk3vXcCyoUtJG83YU13ThBRJx8E/F+VCYRR/vrs4mBsgM4S X-Received: by 2002:a05:6a00:439a:b0:68f:e0f0:85f4 with SMTP id bt26-20020a056a00439a00b0068fe0f085f4mr2668259pfb.25.1694520095128; Tue, 12 Sep 2023 05:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694520095; cv=none; d=google.com; s=arc-20160816; b=hN46HoU0nKf4YNHhSbvI58UORZzucG2EFmkrjHEgrem6oTCt6A3CtfKwG9RMDz6I74 1P2IrdmqC8cTcHvRf+uD10xaQq8SGuTOhXOPMrjgRMCAJxEQ/Dg6UeGwbi5WfwLJYBuA YuiMzaGXgzIkjZtmYLElpxKUB38waheCg5n4GVHB1vYbrBUeGBjxg02fXmEtdxIwgoFI 6Tt6R4IiJmZVEUcm2nnJTdPqB4fCMr3yeTay8DbcmKxHV6tfdiPa9dJswNY7TF8xuumy x1TC8tRVddYuPSDv4RQW0361eF/7Ub/Lqq9wt9ZnERr0O00eDkxBBU+wWJ3qQiyJ0ZyW WdDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=aFGY1HOJLcFKtWSz4ftiIPAjki9c8ROSkcinsliHSOw=; fh=snynw1CfNMNWtZHVdvCqMnig08VbxE5RC54evbt6uDQ=; b=M1xuR7mce/MnZL4pvsXqhJTZjnTFpCciZjQQw/oZgXDl7yGtXQeafUt8l8N8s84Ex+ I9hf0VBJk5n8byOSTydCBzO/Rum/rpjWPQEfVfO7AXh9hB9Q6tG6+fIslQX40SznJ0gU rpIQ3BHFZaCRRqejJAK3cpp9qmy6FfsWHFZum73+vIKNC7AHP7iDD9d90/KFXSlY0gBz n1TrdFvwWxcstdi2X1Xc10N08PEl3SNyy/MIoM/RPetMHk3E5vBO/+z6bEBFomfG22BE XH85nTQtG1BxVbBI+zoBrzU5kAOLgLLTHJDj0DAJQ/9iV1yCO/5D0yLs0rfI/e2n3kAk VJJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=VQYY5gfK; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e67-20020a636946000000b0056c2892bfb9si7686780pgc.644.2023.09.12.05.01.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 05:01:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=VQYY5gfK; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9732D802AF26; Tue, 12 Sep 2023 04:28:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231389AbjILL2U (ORCPT + 55 others); Tue, 12 Sep 2023 07:28:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234666AbjILL1b (ORCPT ); Tue, 12 Sep 2023 07:27:31 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 199621713; Tue, 12 Sep 2023 04:27:17 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-273527a8fdeso3664111a91.2; Tue, 12 Sep 2023 04:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694518036; x=1695122836; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=aFGY1HOJLcFKtWSz4ftiIPAjki9c8ROSkcinsliHSOw=; b=VQYY5gfKxFAE1uw9WZKonwiOyTX2W/AjQGbZuE7PabU2kn955IHdU4iJY3+Otr4Lvr RRc/z+QPKSMARaUdZTSkvl/MKicorow3aAvT+bxYV3fsvpoMHX6eVzj6o+1JaiQpWttH HGElsgw/vFuA138sjTlgLvbY7f+PzSgsiBoU5lsmbL6S3oIy4p0ZSEFl0Prmq40PrJJs ntRwu1diqVbWPI+71+X6EI8W9R7qpy/d0LI3svZ/gT5RGikBPQC2JuBSgq32yQUuqXP5 IRr1yTdrLSPbk6Z35FpOW1lxZV24r0WMXLh+w7Um0YOjuKj4JLA5LMRkqJZYOCptqZl2 zVAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694518036; x=1695122836; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aFGY1HOJLcFKtWSz4ftiIPAjki9c8ROSkcinsliHSOw=; b=OjN4DozjOl8mOLNwRxKSBnr0czoIAgXU0G6lGlW59fVyDJuyX9CmBSTNBYjMNAscGJ vnDMRkF7kCHMQLpu8Nsi5XVbT0BQByiKtZr46enJQ9W8fDoDy4/XVTOTbh7aoq5DTkki gmhRYDnno977hyhxgLo7i0AYWNui1kG+BhTN0jBZ8OorJG/k7XlEf+kDUCBjAQ0rZ7/t VvWrL6EXUVSNeD1eA7jzG2lhOyMSS8/5PwGMmY4vwqo9jW1vh0xNS9+1vI2C7EkU+PrX SMAIAirmGtlmbm7K+DljdjXlFhv6oPZDCAsHxHyjYxYdRss+P0OYBW/2lE58WlY5HKzF socw== X-Gm-Message-State: AOJu0YxT8Id815yZuUNkkl9SBoX0PD68rABE5clEOQ60jsjMj4nVqTiF PjFh7tfAgoSyM4USQtosxifYBVFQxPqLpE4u X-Received: by 2002:a17:90a:c918:b0:273:ec96:b6f9 with SMTP id v24-20020a17090ac91800b00273ec96b6f9mr7351387pjt.25.1694518036038; Tue, 12 Sep 2023 04:27:16 -0700 (PDT) Received: from localhost.localdomain (220-133-92-232.hinet-ip.hinet.net. [220.133.92.232]) by smtp.googlemail.com with ESMTPSA id fv23-20020a17090b0e9700b0026d6ad176c6sm1155618pjb.0.2023.09.12.04.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 04:27:15 -0700 (PDT) From: Zenm Chen To: Jes.Sorensen@gmail.com Cc: kvalo@kernel.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, rtl8821cerfe2@gmail.com, pkshih@realtek.com, Zenm Chen Subject: [PATCH v2] wifi: rtl8xxxu: fix LED control code of RTL8192FU Date: Tue, 12 Sep 2023 19:27:09 +0800 Message-ID: <20230912112709.22456-1-zenmchen@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Sep 2023 04:28:20 -0700 (PDT) Some of the RTL8192FU-based wifi adapters use the register "REG_LEDCFG1" to control the LED, and some of them use the register "REG_LEDCFG0" instead. Currently rtl8xxxu controls the LED via writing the values to the register "REG_LEDCFG1" only. This caused a few RTL8192FU-based wifi adapters's LED don't blink according to the network activity. This patch will make rtl8xxxu write the correct values to the both register "REG_LEDCFG0" and "REG_LEDCFG1" to fix this issue. This was tested with these two wifi adapters: ASUS USB-N13 C1 (vid=0x0b05, pid=0x18f1, rfe_type=0x1) MERCURY MW310UH (vid=0x0bda, pid=0xf192, rfe_type=0x5) Signed-off-by: Zenm Chen --- v2: - Explain why to fix the issue in this way in the commit message. - Split a long statement into short ones. - Use some of the definitions suggested by Ping-Ke Shih. --- .../realtek/rtl8xxxu/rtl8xxxu_8192f.c | 26 ++++++++++++------- .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h | 3 +++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c index 28e93835e05a..779f93afc22b 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192f.c @@ -2014,26 +2014,34 @@ static int rtl8192fu_led_brightness_set(struct led_classdev *led_cdev, struct rtl8xxxu_priv *priv = container_of(led_cdev, struct rtl8xxxu_priv, led_cdev); - u16 ledcfg; + u32 ledcfg; /* Values obtained by observing the USB traffic from the Windows driver. */ rtl8xxxu_write32(priv, REG_SW_GPIO_SHARE_CTRL_0, 0x20080); rtl8xxxu_write32(priv, REG_SW_GPIO_SHARE_CTRL_1, 0x1b0000); - ledcfg = rtl8xxxu_read16(priv, REG_LEDCFG0); + ledcfg = rtl8xxxu_read32(priv, REG_LEDCFG0); + + /* Set LED0 GPIO enabled */ + ledcfg |= LEDCFG0_LED0_GPIO_ENABLE; if (brightness == LED_OFF) { - /* Value obtained like above. */ - ledcfg = BIT(1) | BIT(7); + /* Setting REG_LEDCFG0[15:0] to 0x0000 turns LED0/LED1 off. */ + ledcfg &= ~GENMASK(15, 0); } else if (brightness == LED_ON) { - /* Value obtained like above. */ - ledcfg = BIT(1) | BIT(7) | BIT(11); + /* Setting REG_LEDCFG0[15:0] to 0x0808 turns LED0/LED1 on. */ + ledcfg &= ~GENMASK(15, 0); + ledcfg |= LEDCFG0_LED1SV | LEDCFG0_LED0SV; } else if (brightness == RTL8XXXU_HW_LED_CONTROL) { - /* Value obtained by brute force. */ - ledcfg = BIT(8) | BIT(9); + /* Setting REG_LEDCFG0[15:0] to 0x0303 enables + * hardware-controlled blinking for LED0/LED1. + * The value 0x0303 is obtained by brute force. + */ + ledcfg &= ~GENMASK(15, 0); + ledcfg |= BIT(9) | BIT(8) | BIT(1) | BIT(0); } - rtl8xxxu_write16(priv, REG_LEDCFG0, ledcfg); + rtl8xxxu_write32(priv, REG_LEDCFG0, ledcfg); return 0; } diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h index 920ee50e2115..5ce845f1d069 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h @@ -146,6 +146,9 @@ #define GPIO_INTM_EDGE_TRIG_IRQ BIT(9) #define REG_LEDCFG0 0x004c +#define LEDCFG0_LED0SV BIT(3) +#define LEDCFG0_LED1SV BIT(11) +#define LEDCFG0_LED0_GPIO_ENABLE BIT(21) #define LEDCFG0_DPDT_SELECT BIT(23) #define REG_LEDCFG1 0x004d #define LEDCFG1_HW_LED_CONTROL BIT(1) -- 2.42.0