From patchwork Thu May 25 04:30:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 9747683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A1B5460209 for ; Thu, 25 May 2017 04:31:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDB892766D for ; Thu, 25 May 2017 04:31:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B122427852; Thu, 25 May 2017 04:31:44 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 677B52766D for ; Thu, 25 May 2017 04:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941730AbdEYEbm (ORCPT ); Thu, 25 May 2017 00:31:42 -0400 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:53093 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S941738AbdEYEax (ORCPT ); Thu, 25 May 2017 00:30:53 -0400 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 2DB0C8448F; Thu, 25 May 2017 16:30:48 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail; t=1495686648; bh=KdSjK72a7lOunzlHMjGNuuz+qaYYMmpm4OYEDr04Sxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nmk+nueFWFZbiW9rxhltzgy4nX3BlyY0w8Y//0wf3l1h/V0guMibnA5XMniNTMF7P mlMpRzSEjaVS9e/smrxSadEJl4ifBoRR79F0UGzhReBxpXLFTKOS0aGtDBxUN/FoMs U0xptqwJwVVnYUaKdxeOSDdNzg/T0M/+SuRKxsqc= Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7, 5, 7, 9061) id ; Thu, 25 May 2017 16:30:48 +1200 Received: from chrisp-dl.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by smtp (Postfix) with ESMTP id 23B6C13EFA0; Thu, 25 May 2017 16:30:48 +1200 (NZST) Received: by chrisp-dl.atlnz.lc (Postfix, from userid 1030) id DAEE31E1DA3; Thu, 25 May 2017 16:30:45 +1200 (NZST) From: Chris Packham To: broonie@kernel.org, andy.shevchenko@gmail.com, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, rmallon@gmail.com, shawnguo@kernel.org Cc: linux@armlinux.org.uk, Chris Packham Subject: [RFC PATCH 1/5] spi: use gpio_desc instead of numeric gpio Date: Thu, 25 May 2017 16:30:39 +1200 Message-Id: <20170525043043.1930-2-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170525043043.1930-1-chris.packham@alliedtelesis.co.nz> References: <20170525043043.1930-1-chris.packham@alliedtelesis.co.nz> 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 By using a gpio_desc and gpiod_set_value() instead of a numeric gpio and gpio_set_value() the gpio flags are taken into account. This is useful when using a gpio chip-select to supplement a controllers native chip-select. Signed-off-by: Chris Packham --- (I've included this in this series for context, ultimately it should not be needed once everything is using gpio_desc) My specific use-case is I have a board that uses the spi-orion driver but only has one CS pin available. In order to access two spi slave devices the board has a 1-of-2 decoder/demultiplexer which is driven via a gpio. The problem is that for one of the 2 slave devices the gpio level required is opposite to the chip-select so I can't simply specify "spi-cs-high". With this change I can flag the gpio as active low and the gpio subsystem takes care of the additional inversion required. drivers/spi/spi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 6f87fec409b5..b39c0f9956dd 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -725,7 +725,10 @@ static void spi_set_cs(struct spi_device *spi, bool enable) enable = !enable; if (gpio_is_valid(spi->cs_gpio)) { - gpio_set_value(spi->cs_gpio, !enable); + struct gpio_desc *gpio = gpio_to_desc(spi->cs_gpio); + + if (gpio) + gpiod_set_value(gpio, !enable); /* Some SPI masters need both GPIO CS & slave_select */ if ((spi->master->flags & SPI_MASTER_GPIO_SS) && spi->master->set_cs)