From patchwork Fri Jun 13 03:59:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naveen Krishna Chatradhi X-Patchwork-Id: 4346661 Return-Path: X-Original-To: patchwork-linux-samsung-soc@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 AD4BF9F314 for ; Fri, 13 Jun 2014 04:02:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ED7292026F for ; Fri, 13 Jun 2014 04:02:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C29EB20263 for ; Fri, 13 Jun 2014 04:02:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751320AbaFMECo (ORCPT ); Fri, 13 Jun 2014 00:02:44 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:14047 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751274AbaFMECn (ORCPT ); Fri, 13 Jun 2014 00:02:43 -0400 Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N7300DRL9WGQL00@mailout3.samsung.com>; Fri, 13 Jun 2014 13:02:40 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.125]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id 29.30.16580.0E77A935; Fri, 13 Jun 2014 13:02:40 +0900 (KST) X-AuditID: cbfee691-b7f2f6d0000040c4-db-539a77e0adc8 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 97.8A.07139.0E77A935; Fri, 13 Jun 2014 13:02:40 +0900 (KST) Received: from chnaveen-ubuntu.sisodomain.com ([107.108.83.161]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N73001949W8DA40@mmp1.samsung.com>; Fri, 13 Jun 2014 13:02:40 +0900 (KST) From: Naveen Krishna Chatradhi To: linux-arm-kernel@lists.infradead.org, spi-devel-general@lists.sourceforge.net, linux-samsung-soc@vger.kernel.org Cc: naveenkrishna.ch@gmail.com, broonie@kernel.org, grant.likely@secretlab.ca, jaswinder.singh@linaro.org, kgene.kim@samsung.com, cpgs@samsung.com, devicetree@vger.kernel.org, Tomasz Figa Subject: [PATCH 1/3 v5] spi: s3c64xx: fix broken "cs_gpios" usage in the driver Date: Fri, 13 Jun 2014 09:29:50 +0530 Message-id: <1402631992-500-1-git-send-email-ch.naveen@samsung.com> X-Mailer: git-send-email 1.7.9.5 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRmVeSWpSXmKPExsWyRsSkVvdB+axgg4dbtCymPnzCZvHykKbF /CPnWC1endnIZjF5031Gi94FV9ksNj2+xmox4/w+JotF2/4zWxyZ0shusX7GaxYHbo+ds+6y e2xa1cnmcefaHjaPzUvqPXYv+Mzk0bdlFaPHz5c6Hp83yQVwRHHZpKTmZJalFunbJXBl9DcI FGwyqZjdMYmtgbFVq4uRk0NCwERi3fLHTBC2mMSFe+vZuhi5OIQEljJKvOl9yQ5TNL3lAwtE YhGjRMux3VBOP5PEsx0tLCBVbAJmEgcXrQbq4OAQESiTmDehDqSGWeAKo0TfqtOsIDXCAv4S vz/MYASxWQRUJa5Nnwy2mlfAWWLt1G+MIL0SAgoScybZQCzexS7RvioYolxA4tvkQywQJbIS mw4wQ5RIShxccYNlAqPgAkaGVYyiqQXJBcVJ6UWmesWJucWleel6yfm5mxiBIX/637OJOxjv H7A+xJgMNG4is5Rocj4wZvJK4g2NzYwsTE1MjY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vnRlLWX1h7t9F7VemufslG+8ky/wOdzZIz3WR8t37V8v0Lz7d4lU7PO qiuxFGckGmoxFxUnAgASbc997QIAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org 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 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since, (3146bee spi: s3c64xx: Added provision for dedicated cs pin) spi-s3c64xx.c driver expects 1. chip select gpios from "cs-gpio"(singular) under the "controller-data" node of the client/slave device of the SPI. 2. "cs-gpio"(singular) entry to be present in the SPI device node. Eg of current broken usage: &spi_1 { cs-gpio <>; /* this entry is checked during probe */ ... slave_node { controller-data { cs-gpio <&gpioa2 5 0>; /* This field is parsed during .setup() */ } }; }; The following dts files which were using this driver. But, din't have the "cs-gpio" entry under SPI node. -- arch/arm/boot/dts/exynos4210-smdkv310.dts -- arch/arm/boot/dts/exynos4412-trats2.dts -- arch/arm/boot/dts/exynos5250-smdk5250.dts Also, the SPI core and many drivers moved on to using "cs-gpios" from SPI node and removed the gpio handling code from drivers (including spi-s3c64xx.c). Hence, spi-s3c64xx.c is broken since "Jun 21 11:26:12 2013" and considering the time with no compliants about the breakage. We are assuming it is safe to remove the "cs-gpio"(singular) usage from device tree binding of spi-samsung.txt and makes appropriate changes in the driver to use "cs-gpios"(plural) from SPI device node. Signed-off-by: Naveen Krishna Chatradhi Acked-by: Rob Herring Reviewed-by: Javier Martinez Canillas Tested-by: Doug Anderson Cc: Tomasz Figa --- Changes since v4: 1. Added reviewed by from Javier and Tested by from Doug Changes since v3: 1. Remove the sdd->cs_gpio and use gpio_is_valid(spi->cs_gpio) instead 2. Keep cs->line only for Non-DT platforms and use spi->cs_gpio for DT platforms .../devicetree/bindings/spi/spi-samsung.txt | 8 ++-- drivers/spi/spi-s3c64xx.c | 41 ++++++++------------ 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/Documentation/devicetree/bindings/spi/spi-samsung.txt b/Documentation/devicetree/bindings/spi/spi-samsung.txt index 86aa061..2d29dac 100644 --- a/Documentation/devicetree/bindings/spi/spi-samsung.txt +++ b/Documentation/devicetree/bindings/spi/spi-samsung.txt @@ -42,15 +42,13 @@ Optional Board Specific Properties: - num-cs: Specifies the number of chip select lines supported. If not specified, the default number of chip select lines is set to 1. +- cs-gpios: should specify GPIOs used for chipselects (see spi-bus.txt) + SPI Controller specific data in SPI slave nodes: - The spi slave nodes should provide the following information which is required by the spi controller. - - cs-gpio: A gpio specifier that specifies the gpio line used as - the slave select line by the spi controller. The format of the gpio - specifier depends on the gpio controller. - - samsung,spi-feedback-delay: The sampling phase shift to be applied on the miso line (to account for any lag in the miso line). The following are the valid values. @@ -85,6 +83,7 @@ Example: #size-cells = <0>; pinctrl-names = "default"; pinctrl-0 = <&spi0_bus>; + cs-gpios = <&gpa2 5 0>; w25q80bw@0 { #address-cells = <1>; @@ -94,7 +93,6 @@ Example: spi-max-frequency = <10000>; controller-data { - cs-gpio = <&gpa2 5 1 0 3>; samsung,spi-feedback-delay = <0>; }; diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 75a5696..b888c66 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -197,7 +197,6 @@ struct s3c64xx_spi_driver_data { struct s3c64xx_spi_dma_data tx_dma; struct s3c64xx_spi_port_config *port_conf; unsigned int port_id; - bool cs_gpio; }; static void flush_fifo(struct s3c64xx_spi_driver_data *sdd) @@ -776,17 +775,6 @@ static struct s3c64xx_spi_csinfo *s3c64xx_get_slave_ctrldata( return ERR_PTR(-ENOMEM); } - /* The CS line is asserted/deasserted by the gpio pin */ - if (sdd->cs_gpio) - cs->line = of_get_named_gpio(data_np, "cs-gpio", 0); - - if (!gpio_is_valid(cs->line)) { - dev_err(&spi->dev, "chip select gpio is not specified or invalid\n"); - kfree(cs); - of_node_put(data_np); - return ERR_PTR(-EINVAL); - } - of_property_read_u32(data_np, "samsung,spi-feedback-delay", &fb_delay); cs->fb_delay = fb_delay; of_node_put(data_np); @@ -812,6 +800,10 @@ static int s3c64xx_spi_setup(struct spi_device *spi) spi->controller_data = cs; } + /* For the non-DT platforms derive chip selects from controller data */ + if (!spi->dev.of_node) + spi->cs_gpio = cs->line; + if (IS_ERR_OR_NULL(cs)) { dev_err(&spi->dev, "No CS for SPI(%d)\n", spi->chip_select); return -ENODEV; @@ -819,17 +811,19 @@ static int s3c64xx_spi_setup(struct spi_device *spi) if (!spi_get_ctldata(spi)) { /* Request gpio only if cs line is asserted by gpio pins */ - if (sdd->cs_gpio) { - err = gpio_request_one(cs->line, GPIOF_OUT_INIT_HIGH, - dev_name(&spi->dev)); + if (gpio_is_valid(spi->cs_gpio)) { + err = gpio_request_one(spi->cs_gpio, + GPIOF_OUT_INIT_HIGH, + dev_name(&spi->dev)); if (err) { dev_err(&spi->dev, "Failed to get /CS gpio [%d]: %d\n", - cs->line, err); + spi->cs_gpio, err); goto err_gpio_req; } - - spi->cs_gpio = cs->line; + } else { + dev_err(&spi->dev, "chip select gpio is invalid\n"); + return -EINVAL; } spi_set_ctldata(spi, cs); @@ -884,7 +878,8 @@ setup_exit: /* setup() returns with device de-selected */ writel(S3C64XX_SPI_SLAVE_SIG_INACT, sdd->regs + S3C64XX_SPI_SLAVE_SEL); - gpio_free(cs->line); + if (gpio_is_valid(spi->cs_gpio)) + gpio_free(spi->cs_gpio); spi_set_ctldata(spi, NULL); err_gpio_req: @@ -900,10 +895,12 @@ static void s3c64xx_spi_cleanup(struct spi_device *spi) struct s3c64xx_spi_driver_data *sdd; sdd = spi_master_get_devdata(spi->master); - if (spi->cs_gpio) { + if (gpio_is_valid(spi->cs_gpio)) { gpio_free(spi->cs_gpio); if (spi->dev.of_node) kfree(cs); + else + spi->cs_gpio = -ENOENT; } spi_set_ctldata(spi, NULL); } @@ -1075,11 +1072,7 @@ static int s3c64xx_spi_probe(struct platform_device *pdev) sdd->cntrlr_info = sci; sdd->pdev = pdev; sdd->sfr_start = mem_res->start; - sdd->cs_gpio = true; if (pdev->dev.of_node) { - if (!of_find_property(pdev->dev.of_node, "cs-gpio", NULL)) - sdd->cs_gpio = false; - ret = of_alias_get_id(pdev->dev.of_node, "spi"); if (ret < 0) { dev_err(&pdev->dev, "failed to get alias id, errno %d\n",