Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3558646pxj; Tue, 11 May 2021 07:10:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2pfaGUs2Zr7+jIihF2TQh41RMVWtI2TsjgyuJuc5H2lJLniaZFCUFITePsBBCnibqqS47 X-Received: by 2002:a2e:9f14:: with SMTP id u20mr24425919ljk.53.1620742253873; Tue, 11 May 2021 07:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620742253; cv=none; d=google.com; s=arc-20160816; b=q5a+6PgO8cjprgFSvnixpMwnwvaEbcmDbifXL4zU6r5FbwlkKX0jDti/jZLBH+zmjO 1OyjwzraLi91Frpc345IiIklHNBrcNl7b3ZBaBIJg5oYf8+udpzDOy/BFC6Je2CWVc4u dLHgj7TVv8sps1NYC9jiCEf/At75uIt9EHD5Vt/1rpYCu/bbcG63K48toUVSwfbov1uc sOTYALiLYIMBsrm7cV+UoFkwuhctfBqaD6nMVue4f9vDXUBMOG7ivf43I0C/E8OyXYID PZDuoKOjyMWh9xTl4jpEb96Hh8n3xI+UzvKZ+M5KYsIEiQoSTZZviI0ytYRxG0EJp8EB cPEA== 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:ironport-sdr:ironport-sdr; bh=GHYQF2oqLxRVH/8Dcb8WpYmssaEv6SM0LAKhWE2XXyM=; b=pKyv8bXZDONVGRf2is5fRbi9yLcmf8NDPr/nsK47LnYPiXvFScbZb3DC4Z6dW9NpAl ltD3z/jm7V6Art9ptTAe6VkcKV2oEtCm4f3JC1Ka0va5YVfg8tKLig3LTR2L282mUDiP OYX9FcDlS8gUAz9CLqzLSJovEWHuTP0VSAlPD2Zahc0c6wbbepfSDkOmBq8hr1ySGeIc C0jCrHkqLAvYLDnw2VGBc14CX/ZexQbn5eA4lXA9sAOKxWKH/CjGyR8SDMwVTRMIgJSk xlV54W29S7m1uocGju86fzhj8BQJ1QNKZec3439kgH9+j9gqIZwVchZ5jsbV2SOOzvw9 +PqA== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e11si28172643lfj.554.2021.05.11.07.10.22; Tue, 11 May 2021 07:10:53 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231519AbhEKOKF (ORCPT + 99 others); Tue, 11 May 2021 10:10:05 -0400 Received: from mga18.intel.com ([134.134.136.126]:43999 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231489AbhEKOKD (ORCPT ); Tue, 11 May 2021 10:10:03 -0400 IronPort-SDR: UUpF4Asel6K6Uq7KxUJgiWDughsd7Vt8RDVnKJC35L95jfAVvXPqTEitvWfTM6XVeJVMgCxHbV EjyqtgRqvgZw== X-IronPort-AV: E=McAfee;i="6200,9189,9981"; a="186889752" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="186889752" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 07:08:55 -0700 IronPort-SDR: 8dadsJuF5RYtBbWlx5WnJoGcWpfpwsIS5koHi4sqfYRhr9vOnvWm04+7DXJiMc6CiK7kx+9w20 CYbm84jxLdsg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="621826717" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 11 May 2021 07:08:53 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id D677314B; Tue, 11 May 2021 17:09:13 +0300 (EEST) From: Andy Shevchenko To: Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Shevchenko , Liguang Zhang , Jay Fang , Sven Van Asbroeck , Xin Hao Subject: [PATCH v2 1/1] spi: Assume GPIO CS active high in ACPI case Date: Tue, 11 May 2021 17:09:12 +0300 Message-Id: <20210511140912.30757-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); + 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) && -- 2.30.2