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: 4236351 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 653319F32B for ; Sat, 24 May 2014 00:57:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A4F51203E3 for ; Sat, 24 May 2014 00:57:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6701F203EC for ; Sat, 24 May 2014 00:57:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751374AbaEXA5j (ORCPT ); Fri, 23 May 2014 20:57:39 -0400 Received: from smtp.codeaurora.org ([198.145.11.231]:54079 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751017AbaEXA5i (ORCPT ); Fri, 23 May 2014 20:57:38 -0400 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=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org, Linus Walleij , Alexandre Courbot , Jean-Christophe PLAGNIOL-VILLARD , Richard Genoud 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 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 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; }