From patchwork Thu Dec 27 21:54:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 1913751 Return-Path: X-Original-To: patchwork-spi-devel-general@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by patchwork2.kernel.org (Postfix) with ESMTP id 2BC34DF2A2 for ; Thu, 27 Dec 2012 22:11:53 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ToLg5-0004xu-Vx; Thu, 27 Dec 2012 22:11:50 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ToLg3-0004xn-Mk for spi-devel-general@lists.sourceforge.net; Thu, 27 Dec 2012 22:11:47 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of free-electrons.com designates 94.23.32.191 as permitted sender) client-ip=94.23.32.191; envelope-from=maxime.ripard@free-electrons.com; helo=mail.free-electrons.com; Received: from mail.free-electrons.com ([94.23.32.191]) by sog-mx-1.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1ToLfz-0005Az-MV for spi-devel-general@lists.sourceforge.net; Thu, 27 Dec 2012 22:11:47 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id 4EA10219; Thu, 27 Dec 2012 22:55:29 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.3.2 Received: from localhost (37-8-165-175.coucou-networks.fr [37.8.165.175]) by mail.free-electrons.com (Postfix) with ESMTPSA id 601681F3; Thu, 27 Dec 2012 22:55:10 +0100 (CET) From: Maxime Ripard To: linux-arm-kernel@lists.infradead.org, Shawn Guo Subject: [PATCH 1/2] spi: spi-gpio: Add checks for the dt properties Date: Thu, 27 Dec 2012 22:54:47 +0100 Message-Id: <1356645288-10110-2-git-send-email-maxime.ripard@free-electrons.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1356645288-10110-1-git-send-email-maxime.ripard@free-electrons.com> References: <1356645288-10110-1-git-send-email-maxime.ripard@free-electrons.com> X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1ToLfz-0005Az-MV Cc: spi-devel-general@lists.sourceforge.net, Brian Lilly X-BeenThere: spi-devel-general@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux SPI core/device drivers discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: spi-devel-general-bounces@lists.sourceforge.net The bindings assumed that the gpios properties were always there, which made the NO_TX and NO_RX mode not usable from device tree. Add extra checks to make sure that the driver can work if either MOSI or MISO is not used. Signed-off-by: Maxime Ripard --- drivers/spi/spi-gpio.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index c7cf0b7..9ddef55 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -365,9 +365,26 @@ static int spi_gpio_probe_dt(struct platform_device *pdev) if (!pdata) return -ENOMEM; - pdata->sck = of_get_named_gpio(np, "gpio-sck", 0); - pdata->miso = of_get_named_gpio(np, "gpio-miso", 0); - pdata->mosi = of_get_named_gpio(np, "gpio-mosi", 0); + ret = of_get_named_gpio(np, "gpio-sck", 0); + if (ret < 0) { + dev_err(&pdev->dev, "gpio-sck property not found\n"); + goto error_free; + } + pdata->sck = ret; + + ret = of_get_named_gpio(np, "gpio-miso", 0); + if (ret < 0) { + dev_info(&pdev->dev, "gpio-miso property not found, switching to no-rx mode\n"); + pdata->miso = SPI_GPIO_NO_MISO; + } else + pdata->miso = ret; + + ret = of_get_named_gpio(np, "gpio-mosi", 0); + if (ret < 0) { + dev_info(&pdev->dev, "gpio-mosi property not found, switching to no-tx mode\n"); + pdata->mosi = SPI_GPIO_NO_MOSI; + } else + pdata->mosi = ret; ret = of_property_read_u32(np, "num-chipselects", &tmp); if (ret < 0) {