Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4095153pxj; Tue, 11 May 2021 20:17:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDoXckOTKsoLlRrvPsrVJ8ojVZ3PX2OLLGsIIOMKbE8Up5z7cCpnzFNPyx+kttwzqN/lgL X-Received: by 2002:a92:bf09:: with SMTP id z9mr29799777ilh.32.1620789451194; Tue, 11 May 2021 20:17:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620789451; cv=none; d=google.com; s=arc-20160816; b=ZXYyQZEpY0IqcjRvVRVSncysYWfKy1HjPYCwfIG9aMHSUO8p9Sj/FocX+lY2fFOoQz ysW4fxTcCU5mRQhpFdJXu0mCjvqESzKqbTCA0trUDOHMnUpW2AYuVa1mz9xIv53gWXII BJAzWqMpF0qLLXFV4ZNrVM6p3ra1lpzGNfsTuw7HpKL4vNiyY22odb28jl2YfFiZ0WBp llib+USMtgBWovaJDlsTbOKnMJYToIlWErZQf+AWWgTox8SoypQlHaJQ12kXUV1jLO4A 3b2q7eL5Dcuw6WA3JWvRPuni+/Br3pD+LH2L+/drypmtAxavUxMbuhpFQtSTzSphCVCI D0TQ== 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 :mime-version:user-agent:date:message-id:references:cc:to:subject :reply-to:from; bh=fS7jwyiAj6xA2PXxsqeYBjFgPAidkyyZzrGdGcHbPGg=; b=qgIAnxu37yxuFSOFubs6SQ/mSs8QLtppHgdun85HxiX31tTYO9k05rxLCYYucVLJtq Emg9LcJzbnS1tnRZXAVJHBFATp1rKpbzcTPd66mnZmhYnhgQ3RBb2GqFp+Xb+YF4ej0f V61qYnPjT0+8wpDSEHmW9/oJsV1d0lleGrx5vzcCMvqf6af8osyF5xN/xyJGjjEVVgwj brvC6fsj5EIEjRFHv0YiY42iFmiOHkUQsEnO0GhKQXwxT4mQUQUUwpJkWGukMl1YepBO Qd6oglaGhoELyau+dOVOernmqs9DmsYM8lNaubrjD0eZ4IRFXfEX0zWAgo7lBKFOd7a7 8+Hw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c2si20814706ilr.77.2021.05.11.20.17.18; Tue, 11 May 2021 20:17:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbhELDRy (ORCPT + 99 others); Tue, 11 May 2021 23:17:54 -0400 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:51860 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbhELDRx (ORCPT ); Tue, 11 May 2021 23:17:53 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04420;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0UYbG6OP_1620789403; Received: from B-X3VXMD6M-2058.local(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0UYbG6OP_1620789403) by smtp.aliyun-inc.com(127.0.0.1); Wed, 12 May 2021 11:16:44 +0800 From: Xin Hao Reply-To: xhao@linux.alibaba.com Subject: Re: [PATCH v2 1/1] spi: Assume GPIO CS active high in ACPI case To: Andy Shevchenko , Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Liguang Zhang , Jay Fang , Sven Van Asbroeck References: <20210511140912.30757-1-andriy.shevchenko@linux.intel.com> Message-ID: Date: Wed, 12 May 2021 11:16:43 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <20210511140912.30757-1-andriy.shevchenko@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2021/5/11 下午10:09, Andy Shevchenko 写道: > Currently GPIO CS handling, when descriptors are in use, doesn't > take into consideration that in ACPI case the default polarity > is Active High and can't be altered. Instead we have to use the > per-chip definition provided by SPISerialBus() resource. > > Fixes: 766c6b63aa04 ("spi: fix client driver breakages when using GPIO descriptors") > Cc: Liguang Zhang > Cc: Jay Fang > Cc: Sven Van Asbroeck > Signed-off-by: Andy Shevchenko > Tested-by: Xin Hao > --- > v2: refactor to avoid ternary (Mark, Sven), dropped comment changes (Mark) > drivers/spi/spi.c | 22 ++++++++++++++++++---- > 1 file changed, 18 insertions(+), 4 deletions(-) > > diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c > index cd40421b8f55..36ee33514b40 100644 > --- a/drivers/spi/spi.c > +++ b/drivers/spi/spi.c > @@ -820,15 +820,29 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force) > > if (spi->cs_gpiod || gpio_is_valid(spi->cs_gpio)) { > if (!(spi->mode & SPI_NO_CS)) { > - if (spi->cs_gpiod) > - /* polarity handled by gpiolib */ > - gpiod_set_value_cansleep(spi->cs_gpiod, activate); > - else > + if (spi->cs_gpiod) { > + /* > + * Historically ACPI has no means of the GPIO polarity and > + * thus the SPISerialBus() resource defines it on the per-chip > + * basis. In order to avoid a chain of negations, the GPIO > + * polarity is considered being Active High. Even for the cases > + * when _DSD() is involved (in the updated versions of ACPI) > + * the GPIO CS polarity must be defined Active High to avoid > + * ambiguity. That's why we use enable, that takes SPI_CS_HIGH > + * into account. > + */ > + if (has_acpi_companion(&spi->dev)) > + gpiod_set_value_cansleep(spi->cs_gpiod, !enable); it worked and code changed minimally,  before ACPI & OF keeps no same rules,  this patch is ok! > + else > + /* Polarity handled by GPIO library */ > + gpiod_set_value_cansleep(spi->cs_gpiod, activate); > + } else { > /* > * invert the enable line, as active low is > * default for SPI. > */ > gpio_set_value_cansleep(spi->cs_gpio, !enable); > + } > } > /* Some SPI masters need both GPIO CS & slave_select */ > if ((spi->controller->flags & SPI_MASTER_GPIO_SS) && -- Best Regards! Xin Hao