Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2680934pxj; Mon, 31 May 2021 08:07:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziEQl53VTjrh4wK22ewyTJmWh0mVnDlX/mtXevaWUjxN6WS8Nkd179kdYihabSubMiZIec X-Received: by 2002:a17:906:128e:: with SMTP id k14mr23223651ejb.485.1622473671641; Mon, 31 May 2021 08:07:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622473671; cv=none; d=google.com; s=arc-20160816; b=DctVmRr6leLWgou5gnlistMxKEpRXqArb+7G8D+9Z26E55cYZ6wviRHtV1dV2g7BZv bXAcQ1PeTzZnUisZKCMuMHcEI3PJHqLDYLskq6MqAZu4UENoec6W/u4ExTZGDRkLIewu tUW+wl0Mczt9dqHs/RVlBgEdlCC1jLdMQMcPZt9MB1yVcgud+nvA640gtrNsrMXSwa5R O2q+KFpCBSojNtZeAA1icFIeLY+DJ2jzNUcC8fK+qeHX/dRcfOtoln+5T+8Wkgm0J4vs z4A/NXkv1CrYAdwh673sttWsSH2FkEm2XItUP6QHv3RHTKwN6vkzEFwxncXZNj7tIAxP b6/Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dnvBfUZobmmriPQnVZz0n+i4z4dEs4ZuE0XOYBrSPxg=; b=CZteKACc1vFOLW+6OTv0kg/01k/df3BZfAIYd+IypTiSYDEASqL/1uutc9Q0JmVF2d 6Myl06fSOHrRtiPFaXyEd81OLlWgB/kFY8vhd0KvpfSYbUQs2iEXM3+t8slt5/fRFSbI 1qjzZt+OYVaMvsYAdcj1gyEY43lCMCPGp7cmI01/7qD6ziCrJhd4vTliNGaOtLg5e18F 9wIKYO2fTHbc0EQ3KPxD8ERZf9LLnaHEGw4wouYCCMM4vih9pEY21JN9Ma7+Y+RYaKvZ mOX9F09d0WU9hbmOm2tj3B1kxH7IpqK4Yc/Fc8mR+qZ70E71wlXMncCy0LEfHtJoADGI pDhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=j6Z+V7iO; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c11si13519716edw.282.2021.05.31.08.07.29; Mon, 31 May 2021 08:07:51 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=j6Z+V7iO; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230464AbhEaPID (ORCPT + 99 others); Mon, 31 May 2021 11:08:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:40182 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233460AbhEaOJY (ORCPT ); Mon, 31 May 2021 10:09:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3C1B061461; Mon, 31 May 2021 13:40:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468410; bh=6ZOBp95rw4h/8YnRs5mvXTJ5grO4wqegQKxjVp5celU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j6Z+V7iOgpad40QHAgJ+EXVDkcjbhyEMPO/g8KKXOuQw1Tq+Ue3q9xipxzz/MwPu3 i2yIKz7I6zbt7PoRgD+XVA+3rkk+bxogCBsRfus3z4XXowk+2xYyU6yi+NQHQ/+h/S dc9GQQl8LZxCjLQN/f0WlUfqNlbDrPJaPaA5vu7Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liguang Zhang , Jay Fang , Sven Van Asbroeck , Andy Shevchenko , Xin Hao , Mark Brown , Sasha Levin Subject: [PATCH 5.10 197/252] spi: Assume GPIO CS active high in ACPI case Date: Mon, 31 May 2021 15:14:22 +0200 Message-Id: <20210531130704.713282925@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Shevchenko [ Upstream commit 6b69546912a57ff8c31061f98e56383cc0beffd3 ] 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 Link: https://lore.kernel.org/r/20210511140912.30757-1-andriy.shevchenko@linux.intel.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 419de3d40481..a6f1e94af13c 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -814,16 +814,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, - enable1); - 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, enable1); + } 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