From patchwork Mon Jul 14 05:41:44 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: 4542591 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 A8B039F295 for ; Mon, 14 Jul 2014 05:45:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AD1052013D for ; Mon, 14 Jul 2014 05:45:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 284DC20172 for ; Mon, 14 Jul 2014 05:45:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753004AbaGNFpQ (ORCPT ); Mon, 14 Jul 2014 01:45:16 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:24521 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752321AbaGNFpN (ORCPT ); Mon, 14 Jul 2014 01:45:13 -0400 Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N8O000RBTBBK370@mailout2.samsung.com>; Mon, 14 Jul 2014 14:45:11 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.124]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id 53.F0.24374.76E63C35; Mon, 14 Jul 2014 14:45:11 +0900 (KST) X-AuditID: cbfee68d-b7fd46d000005f36-3e-53c36e67e236 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 10.A2.05196.76E63C35; Mon, 14 Jul 2014 14:45:11 +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 <0N8O00G1ETB5S4P0@mmp1.samsung.com>; Mon, 14 Jul 2014 14:45:11 +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 v6] spi: s3c64xx: fix broken "cs_gpios" usage in the driver Date: Mon, 14 Jul 2014 11:11:44 +0530 Message-id: <1405316506-27855-2-git-send-email-ch.naveen@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1405316506-27855-1-git-send-email-ch.naveen@samsung.com> References: <1405316506-27855-1-git-send-email-ch.naveen@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprGIsWRmVeSWpSXmKPExsWyRsSkRjc973CwQdNTLYupD5+wWbw8pGkx /8g5VotXZzayWUzedJ/RonfBVTaLTY+vsVrMOL+PyWLRtv/MFkemNLJbrJ/xmsWB22PnrLvs HptWdbJ53Lm2h81j85J6j90LPjN59G1Zxejx86WOx+dNcgEcUVw2Kak5mWWpRfp2CVwZnb9e sRQsMKnovdXH2MD4W7OLkZNDQsBE4ufuLcwQtpjEhXvr2boYuTiEBJYySjx//4ARpuje6tNQ iUWMEn8vz4dy+pkkfs0+zApSxSZgJnFw0Wr2LkYODhGBMol5E+pAapgFrjBK9K06DVYjLOAv 0dqymgXEZhFQlTjafZAJxOYVcJWYv3QqC0ivhICCxJxJNiBhTgE3ib07/oKVCAGVLDi4jhVk poTAKXaJ16uWM0LMEZD4NvkQVK+sxKY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HfgTuUdj 8vm3Ofb5526Wye/vrIqZyJizZ/6UVP7/ijXSSkJ+9nVVH1v67v7LlEzp5K1hmvZw6TQlU6/X r97u6dwaMP31zwm+F7Lubr7tZffKceLF00dlkubp8jz5qnZO6eirvQdf9Sz6pLz1h7hJ8dEp suF/VwrI8wul9Xu8XcnrrsRSnJFoqMVcVJwIAJ8/cr7YAgAA 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=-6.9 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 Reviewed-by: Tomasz Figa --- Changes since v5: Fixed the "making a GPIO chip select mandatory" bug. 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 | 38 ++++++++------------ 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/Documentation/devicetree/bindings/spi/spi-samsung.txt b/Documentation/devicetree/bindings/spi/spi-samsung.txt index 655b665..792efba 100644 --- a/Documentation/devicetree/bindings/spi/spi-samsung.txt +++ b/Documentation/devicetree/bindings/spi/spi-samsung.txt @@ -39,15 +39,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..b61ff3d 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,16 @@ 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; } spi_set_ctldata(spi, cs); @@ -884,7 +875,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 +892,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 +1069,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",