Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2450338rdh; Wed, 27 Sep 2023 03:06:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6KMJTIPJ8k5hZWGiOEuc94IIED6ryCANq+gjzk6ZG6aYxvWE7zBfx36l9J0+4SBiYXnQI X-Received: by 2002:a05:6358:290f:b0:145:63e6:8710 with SMTP id y15-20020a056358290f00b0014563e68710mr1864190rwb.23.1695809173249; Wed, 27 Sep 2023 03:06:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695809173; cv=none; d=google.com; s=arc-20160816; b=1HlR5/wzjyH+8/HrOLdHpL/5IrM4cQx73D+N7fcPDqhjY2sWx/2xOcBFrg6gss1PhI P2c5oi9fh6a1pgHkLeYrA9B5Dg7jz+AV8FWxun3FKy/j2DatwV/eXYLHsZ6c6AAeDH7f FKwkN8tjTZtcCC2JxXmH3cNg1PrmBT7FHxMCSIaQ8MXsDxruuPoLQKFBYp2rDtO5CbbN OI9EgtHhDg3TQXaHlcYwB8r9EBFzISr57Oiwrhl7M98ztBb279q2zmnzM+lzwMjlNTDc cAOHFJmEn9OE0QqY2/c5RYIz9RCzpnvwQVctl7j7mmKjebcO7/iFgMY+ykB6XOK5kQXA wlTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=aUkktc6YvBN99AHYQSsKl/tyu+xRvLt2MgWHndIhkVM=; fh=+XH8MQ9cyShad+4RbeLJsRB264TEHIEAOESNCZLtBjA=; b=t/1qrGalIeM9P2NZImBovnCvEM0/R/oE42Nu9ax3rsKI5lJRhkZe4mNFO+/TOgadaQ CmHdXaoN9eSgay+sWdYniMVobKay4QwFQcOfEzSTA4aX7llcd7xBnCqK+HSyHxwlqNRi lJKA+aFjJS3w0nLPktwZ2XwcNS1ttoynpWWYEEKyon1C3RmF29+FOtr2H/zAr1gqnn2U MRd7KcPUIhNZN+9gM1uLIW1Z7o+CfasVfQfdGRhkCQzccjt7JmeurVQ/PAYZ6GaiW3mD o9/jp+z058V2ZMJUbipTgSsn8OYT/hSFunLymUT92HR9fFm7TxFHDH6gj1jcka7/Vbfd JfVg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id v202-20020a6361d3000000b00578bb707e70si8018240pgb.799.2023.09.27.03.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 03:06:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D16EE8216938; Wed, 27 Sep 2023 02:50:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231240AbjI0Jtj (ORCPT + 99 others); Wed, 27 Sep 2023 05:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231254AbjI0JtR (ORCPT ); Wed, 27 Sep 2023 05:49:17 -0400 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88F2910FD; Wed, 27 Sep 2023 02:49:07 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0VszxC8b_1695808144; Received: from 30.97.48.70(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VszxC8b_1695808144) by smtp.aliyun-inc.com; Wed, 27 Sep 2023 17:49:05 +0800 Message-ID: <99dc2f99-cb03-bec8-b538-3ad21750adff@linux.alibaba.com> Date: Wed, 27 Sep 2023 17:49:11 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH V2 1/2] gpio: pmic-eic-sprd: Two-dimensional arrays maintain pmic eic To: Chunyan Zhang Cc: Wenhua Lin , Linus Walleij , Andy Shevchenko , Bartosz Golaszewski , Orson Zhai , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, wenhua lin , Xiongpeng Wu References: <20230921122527.15261-1-Wenhua.Lin@unisoc.com> <20230921122527.15261-2-Wenhua.Lin@unisoc.com> <9dd68b0e-e36a-b87c-e66d-586f2442da6c@linux.alibaba.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 27 Sep 2023 02:50:08 -0700 (PDT) On 9/27/2023 5:24 PM, Chunyan Zhang wrote: > On Wed, 27 Sept 2023 at 17:04, Baolin Wang > wrote: >> >> >> >> On 9/21/2023 8:25 PM, Wenhua Lin wrote: >>> A bank PMIC EIC contains 16 EICs, and the operating registers >>> are BIT0-BIT15, such as BIT0 of the register operated by EIC0. >>> Using the one-dimensional array reg[CACHE_NR_REGS] for maintenance >>> will cause the configuration of other EICs to be affected when >>> operating a certain EIC. In order to solve this problem, the register >>> operation bits of each PMIC EIC are maintained through the two-dimensional >>> array reg[SPRD_PMIC_EIC_NR][CACHE_NR_REGS] to avoid mutual interference. >> >> LGTM. And this also deserves a Fixes tag. > > Do we really need a two-dimensional array to save 16-bit value? I also considering this, but after more thinking, I think this patch is a simple fix. Now I realized the problem is that, if we use one array to cache a bank of EICs' status, the pmic_eic->reg[] array can contain incorrect configuration for other EICs in the same bank. Yes, we can have another fix, for example, setting the pmic_eic->reg[] to some invalid values (maybe -1) in sprd_pmic_eic_bus_sync_unlock() after setting one EIC. Thus when setting another EIC, we can validate if the cached reg is a valid value, if not, we do not need to set the register. But like I said above, this seems more complicated. >> Reviewed-by: Baolin Wang >> >>> Signed-off-by: Wenhua Lin >>> --- >>> drivers/gpio/gpio-pmic-eic-sprd.c | 21 +++++++++++---------- >>> 1 file changed, 11 insertions(+), 10 deletions(-) >>> >>> diff --git a/drivers/gpio/gpio-pmic-eic-sprd.c b/drivers/gpio/gpio-pmic-eic-sprd.c >>> index c3e4d90f6b18..442968bb2490 100644 >>> --- a/drivers/gpio/gpio-pmic-eic-sprd.c >>> +++ b/drivers/gpio/gpio-pmic-eic-sprd.c >>> @@ -57,7 +57,7 @@ struct sprd_pmic_eic { >>> struct gpio_chip chip; >>> struct regmap *map; >>> u32 offset; >>> - u8 reg[CACHE_NR_REGS]; >>> + u8 reg[SPRD_PMIC_EIC_NR][CACHE_NR_REGS]; >>> struct mutex buslock; >>> int irq; >>> }; >>> @@ -151,8 +151,8 @@ static void sprd_pmic_eic_irq_mask(struct irq_data *data) >>> struct sprd_pmic_eic *pmic_eic = gpiochip_get_data(chip); >>> u32 offset = irqd_to_hwirq(data); >>> >>> - pmic_eic->reg[REG_IE] = 0; >>> - pmic_eic->reg[REG_TRIG] = 0; >>> + pmic_eic->reg[offset][REG_IE] = 0; >>> + pmic_eic->reg[offset][REG_TRIG] = 0; >>> >>> gpiochip_disable_irq(chip, offset); >>> } >>> @@ -165,8 +165,8 @@ static void sprd_pmic_eic_irq_unmask(struct irq_data *data) >>> >>> gpiochip_enable_irq(chip, offset); >>> >>> - pmic_eic->reg[REG_IE] = 1; >>> - pmic_eic->reg[REG_TRIG] = 1; >>> + pmic_eic->reg[offset][REG_IE] = 1; >>> + pmic_eic->reg[offset][REG_TRIG] = 1; >>> } >>> >>> static int sprd_pmic_eic_irq_set_type(struct irq_data *data, >>> @@ -174,13 +174,14 @@ static int sprd_pmic_eic_irq_set_type(struct irq_data *data, >>> { >>> struct gpio_chip *chip = irq_data_get_irq_chip_data(data); >>> struct sprd_pmic_eic *pmic_eic = gpiochip_get_data(chip); >>> + u32 offset = irqd_to_hwirq(data); >>> >>> switch (flow_type) { >>> case IRQ_TYPE_LEVEL_HIGH: >>> - pmic_eic->reg[REG_IEV] = 1; >>> + pmic_eic->reg[offset][REG_IEV] = 1; >>> break; >>> case IRQ_TYPE_LEVEL_LOW: >>> - pmic_eic->reg[REG_IEV] = 0; >>> + pmic_eic->reg[offset][REG_IEV] = 0; >>> break; >>> case IRQ_TYPE_EDGE_RISING: >>> case IRQ_TYPE_EDGE_FALLING: >>> @@ -222,15 +223,15 @@ static void sprd_pmic_eic_bus_sync_unlock(struct irq_data *data) >>> sprd_pmic_eic_update(chip, offset, SPRD_PMIC_EIC_IEV, 1); >>> } else { >>> sprd_pmic_eic_update(chip, offset, SPRD_PMIC_EIC_IEV, >>> - pmic_eic->reg[REG_IEV]); >>> + pmic_eic->reg[offset][REG_IEV]); >>> } >>> >>> /* Set irq unmask */ >>> sprd_pmic_eic_update(chip, offset, SPRD_PMIC_EIC_IE, >>> - pmic_eic->reg[REG_IE]); >>> + pmic_eic->reg[offset][REG_IE]); >>> /* Generate trigger start pulse for debounce EIC */ >>> sprd_pmic_eic_update(chip, offset, SPRD_PMIC_EIC_TRIG, >>> - pmic_eic->reg[REG_TRIG]); >>> + pmic_eic->reg[offset][REG_TRIG]); >>> >>> mutex_unlock(&pmic_eic->buslock); >>> }