From patchwork Sat May 24 00:57:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 4236361 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0569CBF90B for ; Sat, 24 May 2014 01:00:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 61675203E9 for ; Sat, 24 May 2014 01:00:08 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BE00B203E5 for ; Sat, 24 May 2014 01:00:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wo0Hg-0001rP-Se; Sat, 24 May 2014 00:58:00 +0000 Received: from smtp.codeaurora.org ([198.145.11.231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wo0He-0001mF-Eo for linux-arm-kernel@lists.infradead.org; Sat, 24 May 2014 00:57:59 +0000 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 71B4C13EFFB; Sat, 24 May 2014 00:57:37 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id 5FB3B13F37A; Sat, 24 May 2014 00:57:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from sboyd-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: sboyd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id A912813EFFB; Sat, 24 May 2014 00:57:36 +0000 (UTC) From: Stephen Boyd To: Mark Brown Subject: [PATCH] spi: Set cs-gpios to output direction Date: Fri, 23 May 2014 17:57:34 -0700 Message-Id: <1400893054-16126-1-git-send-email-sboyd@codeaurora.org> X-Mailer: git-send-email 1.9.0.1.gd5ccf8c X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140523_175758_516226_F450568D X-CRM114-Status: GOOD ( 20.46 ) X-Spam-Score: -0.7 (/) Cc: Alexandre Courbot , Richard Genoud , linux-arm-msm@vger.kernel.org, Linus Walleij , linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, Jean-Christophe PLAGNIOL-VILLARD , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Some gpios used for cs-gpios may not be configured for output by default. In these cases gpio_set_value() won't have any effect and so the chip select line won't toggle. Request the cs-gpios and set them to output direction once we know if the chip select is default high or default low. Cc: Linus Walleij Cc: Alexandre Courbot Cc: Jean-Christophe PLAGNIOL-VILLARD Cc: Richard Genoud Signed-off-by: Stephen Boyd --- I wonder if we should request the gpios when the master controller probes or when a spi device is added? We only know what the default value should be when the spi device is added. On the other hand, we should probably fail probe if the gpio controller isn't ready when the spi master controller probes. Also, is it better to convert this over to the gpiod interfaces? drivers/spi/spi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 074f55f5d5ec..00f6365b3f87 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -431,8 +431,10 @@ int spi_add_device(struct spi_device *spi) goto done; } - if (master->cs_gpios) + if (master->cs_gpios) { spi->cs_gpio = master->cs_gpios[spi->chip_select]; + gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); + } /* Drivers may modify this initial i/o setup, but will * normally rely on the device being setup. Devices @@ -1512,8 +1514,11 @@ static int of_spi_register_master(struct spi_master *master) for (i = 0; i < master->num_chipselect; i++) cs[i] = -ENOENT; - for (i = 0; i < nb; i++) + for (i = 0; i < nb; i++) { cs[i] = of_get_named_gpio(np, "cs-gpios", i); + devm_gpio_request(&master->dev, cs[i], "spi-cs"); + } + return 0; }