From patchwork Fri Dec 2 09:49:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edmund Berenson X-Patchwork-Id: 28843 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp748150wrr; Fri, 2 Dec 2022 02:11:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf6AR/r/W1dCd5FgonVHA+2jHnaTJSZsyNgMZupOjpisvGiuAOOY7S1BxN0ZOL9W/t8xA5Ta X-Received: by 2002:aa7:dbd8:0:b0:467:60fa:b629 with SMTP id v24-20020aa7dbd8000000b0046760fab629mr62175568edt.281.1669975919405; Fri, 02 Dec 2022 02:11:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669975919; cv=none; d=google.com; s=arc-20160816; b=e4hV+/MXbydiT5PRg8bM13VH2nDrOljzDHI5V+d3/EpUR82qyIJV6mQo0G1GX9Tpw7 3Yi+4R7JyJssJe9DUKqUfOV9EZaZiK6yTx7HpjErPjCUR2bgMEvUR/JICtklUwTtFk75 pJItwELuier7Sy4xDLryk3HYG4JU8WdBqGnFfCJpvDa+m0smDi+JoILYBoX+TQKz1bXC myFKrncFzroXAmZ8X/ogjGpMEiWVaNAK/9/QJgVUB9gyso/Caprnj76RqD57C0Nrh6VA o80pNOBP89cKMZPhuF7wJFcDNbU4rDIeZtK2ow9slJSgvbtb6SjsFRGW9S6XDrVq5pop VlRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from; bh=koYeDer2OKQB/YOtbGJMawW5/gIPGccMAlegO3peTzs=; b=TrVpwSDjuM+6LRkYDqC8xIO1NkE+VmSo2aNfoQZ8JrBkWLSvs2JedYh+ykWJBxkGLm ogWZH1D3Nh0wvEmz6MrmeGCgfT4PomekQgv5nyzuW54oOmO3SMM5ESt/8phUE7wEhfWs 8IpBE6ajGRBr/zUR0foouMPm6/w0YbACFZYxJkxmd9eWLW8bcgiPf2/BChS7GJOoBcNE c1vmKB7CeMdXi3XMJU+P4w3fgqE6J9yYNVwC2MIcVbXXNQ7nT+hkLGsjk41tsPbRaSrq hIASRkppOJ7mneoGFTlhwpUAEGXvJhoulTcN5tIJ/o21Yd2ih1hIhuhhlQe7wNk9Ubxw /vlQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o9-20020a170906974900b00791994dfb9esi6541211ejy.491.2022.12.02.02.11.36; Fri, 02 Dec 2022 02:11:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233059AbiLBJti (ORCPT + 99 others); Fri, 2 Dec 2022 04:49:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232272AbiLBJta (ORCPT ); Fri, 2 Dec 2022 04:49:30 -0500 Received: from mx1.emlix.com (mx1.emlix.com [136.243.223.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5618BC9376 for ; Fri, 2 Dec 2022 01:49:29 -0800 (PST) Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id 0E82C5FEEB; Fri, 2 Dec 2022 10:49:28 +0100 (CET) From: Edmund Berenson Cc: Edmund Berenson , Lukasz Zemla , Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] spi: execute set_cs function before gpio cs is activated Date: Fri, 2 Dec 2022 10:49:26 +0100 Message-Id: <20221202094926.9113-1-edmund.berenson@emlix.com> X-Mailer: git-send-email 2.37.4 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751096669361443742?= X-GMAIL-MSGID: =?utf-8?q?1751096669361443742?= In some cases it is necessary to adjust the spi controller configuration before gpio cs is set. For example if spi devices requiring different cpol are used from the same controller the adjustment to cpol has to be made before gpio is activated. To achieve this set_cs should be executed before gpio cs and necessary adjustments can be made inside of controller driver. Suggested-by: Lukasz Zemla Signed-off-by: Edmund Berenson --- drivers/spi/spi.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 5f9aedd1f0b6..bf2a67184969 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -976,6 +976,11 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force) enable = !enable; if (spi->cs_gpiod) { + /* Some SPI masters need both GPIO CS & slave_select */ + if ((spi->controller->flags & SPI_MASTER_GPIO_SS) && + spi->controller->set_cs) + spi->controller->set_cs(spi, !enable); + if (!(spi->mode & SPI_NO_CS)) { /* * Historically ACPI has no means of the GPIO polarity and @@ -993,10 +998,6 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force) /* Polarity handled by GPIO library */ gpiod_set_value_cansleep(spi->cs_gpiod, activate); } - /* Some SPI masters need both GPIO CS & slave_select */ - if ((spi->controller->flags & SPI_MASTER_GPIO_SS) && - spi->controller->set_cs) - spi->controller->set_cs(spi, !enable); } else if (spi->controller->set_cs) { spi->controller->set_cs(spi, !enable); }