From patchwork Sat Mar 30 09:31:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sperl X-Patchwork-Id: 10878211 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 27CA61669 for ; Sat, 30 Mar 2019 09:31:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12968290CC for ; Sat, 30 Mar 2019 09:31:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 071F9290D6; Sat, 30 Mar 2019 09:31:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA4C0290CC for ; Sat, 30 Mar 2019 09:31:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730430AbfC3Jb2 (ORCPT ); Sat, 30 Mar 2019 05:31:28 -0400 Received: from 212-186-180-163.static.upcbusiness.at ([212.186.180.163]:55020 "EHLO cgate.sperl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730372AbfC3Jb2 (ORCPT ); Sat, 30 Mar 2019 05:31:28 -0400 Received: from hc1.intern.sperl.org (account martin@sperl.org [10.10.10.59] verified) by sperl.org (CommuniGate Pro SMTP 6.2.1 _community_) with ESMTPSA id 7760023; Sat, 30 Mar 2019 09:31:13 +0000 From: kernel@martin.sperl.org To: Mark Brown , Eric Anholt , Stefan Wahren , Hubert Denkmair , linux-spi@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org Cc: Martin Sperl Subject: [PATCH V3 7/9] spi: bcm2835aux: setup gpio-cs to output and correct level during setup Date: Sat, 30 Mar 2019 09:31:04 +0000 Message-Id: <20190330093106.20723-8-kernel@martin.sperl.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190330093106.20723-1-kernel@martin.sperl.org> References: <20190330093106.20723-1-kernel@martin.sperl.org> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Sperl Setup gpio-cs to the correct levels during setup and also make the gpio definitely an output GPIO. This is transparently fixing some badly configured DTs in the process where cs-gpio is set but the gpios are still configured with native cs. It also makes 100% sure that the initial CS levels are as expected - especially on systems with devices on a bus with mixed CS_HIGH/CS_LOW settings. Fixes: 1ea29b39f4c812ec ("spi: bcm2835aux: add bcm2835 auxiliary spi device...") Signed-off-by: Martin Sperl --- Changelog: V2 -> V3: rebased duo to changes in Patch 6 drivers/spi/spi-bcm2835aux.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/drivers/spi/spi-bcm2835aux.c b/drivers/spi/spi-bcm2835aux.c index a105db371417..99414319001a 100644 --- a/drivers/spi/spi-bcm2835aux.c +++ b/drivers/spi/spi-bcm2835aux.c @@ -403,8 +403,20 @@ static int bcm2835aux_spi_setup(struct spi_device *spi) /* sanity check for native cs */ if (spi->mode & SPI_NO_CS) return 0; - if (gpio_is_valid(spi->cs_gpio)) - return 0; + if (gpio_is_valid(spi->cs_gpio)) { + /* with gpio-cs set the GPIO to the correct level + * and as output (in case the dt has the gpio not configured + * as output but native cs) + */ + ret = gpio_direction_output(spi->cs_gpio, + (spi->mode & SPI_CS_HIGH) ? 0 : 1); + if (ret) + dev_err(&spi->dev, + "could not set gpio %i as output: %i\n", + spi->cs_gpio, ret); + + return ret; + } /* for dt-backwards compatibility: only support native on CS0 * known things not supported with broken native CS: