From patchwork Thu Jul 27 22:03:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 9867557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BCD0E6038F for ; Thu, 27 Jul 2017 22:03:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0D4C28896 for ; Thu, 27 Jul 2017 22:03:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5FA228893; Thu, 27 Jul 2017 22:03:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7C4728896 for ; Thu, 27 Jul 2017 22:03:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751656AbdG0WDe (ORCPT ); Thu, 27 Jul 2017 18:03:34 -0400 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:48281 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751616AbdG0WDd (ORCPT ); Thu, 27 Jul 2017 18:03:33 -0400 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 9CC498448C; Fri, 28 Jul 2017 10:03:24 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail; t=1501193004; bh=FOCr4bNoAa+oDGd9+/8tbo3mEdZBvfxcu+w3/X48goA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NksCs102oilF+vxyJVUjcIBoD+jdjThROffFDsCB+GnLiI7IyeYPTfXQ4UjqWTsLn /VkgezPTeerWMZ0S7QafyjKkT/4lSvyGIbRoeIRKan3B8jdV63XiPEhxY4i2qjk7hu h5au9Gq1TXISrfhJeAGIeJebjwBLMWaRFmJ76mvA= Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7, 5, 8, 10121) id ; Fri, 28 Jul 2017 10:03:23 +1200 Received: from chrisp-dl.ws.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by smtp (Postfix) with ESMTP id E2D1513F218; Fri, 28 Jul 2017 10:03:29 +1200 (NZST) Received: by chrisp-dl.ws.atlnz.lc (Postfix, from userid 1030) id C2B431E231A; Fri, 28 Jul 2017 10:03:22 +1200 (NZST) From: Chris Packham To: andy.shevchenko@gmail.com Cc: linux-spi@vger.kernel.org Subject: [RFC PATCH v2 10/12] spi: core: convert spi_master to use gpio_desc Date: Fri, 28 Jul 2017 10:03:20 +1200 Message-Id: <20170727220322.26654-11-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170727220322.26654-1-chris.packham@alliedtelesis.co.nz> References: <20170727220322.26654-1-chris.packham@alliedtelesis.co.nz> 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 Instead of numeric gpios make struct spi_master hold an array of struct gpio_desc. For now struct spi_device still maintains a numeric gpio which will be updated in a subsequent change. Signed-off-by: Chris Packham --- drivers/spi/spi-ep93xx.c | 18 ++++++++---------- drivers/spi/spi-imx.c | 25 +++++++++---------------- drivers/spi/spi-mt65xx.c | 13 ------------- drivers/spi/spi.c | 23 +++++++++++++++++------ include/linux/spi/spi.h | 2 +- 5 files changed, 35 insertions(+), 46 deletions(-) diff --git a/drivers/spi/spi-ep93xx.c b/drivers/spi/spi-ep93xx.c index d48d0508a886..9d8328fee737 100644 --- a/drivers/spi/spi-ep93xx.c +++ b/drivers/spi/spi-ep93xx.c @@ -672,7 +672,7 @@ static int ep93xx_spi_probe(struct platform_device *pdev) master->num_chipselect = info->num_chipselect; master->cs_gpios = devm_kzalloc(&master->dev, - sizeof(int) * master->num_chipselect, + sizeof(*master->cs_gpios) * master->num_chipselect, GFP_KERNEL); if (!master->cs_gpios) { error = -ENOMEM; @@ -680,19 +680,17 @@ static int ep93xx_spi_probe(struct platform_device *pdev) } for (i = 0; i < master->num_chipselect; i++) { - master->cs_gpios[i] = info->chipselect[i]; + struct gpio_desc *cs; - if (!gpio_is_valid(master->cs_gpios[i])) - continue; - - error = devm_gpio_request_one(&pdev->dev, master->cs_gpios[i], - GPIOF_OUT_INIT_HIGH, - "ep93xx-spi"); - if (error) { + cs = devm_gpiod_get_index(&pdev->dev, "spi-cs", i, + GPIOD_OUT_HIGH); + if (IS_ERR(cs)) { dev_err(&pdev->dev, "could not request cs gpio %d\n", - master->cs_gpios[i]); + i); + error = PTR_ERR(cs); goto fail_release_master; } + master->cs_gpios[i] = cs; } platform_set_drvdata(pdev, master); diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index 930e47597db3..d240aa4082c8 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c @@ -1229,12 +1229,18 @@ static int spi_imx_probe(struct platform_device *pdev) if (mxc_platform_info) { master->num_chipselect = mxc_platform_info->num_chipselect; master->cs_gpios = devm_kzalloc(&master->dev, - sizeof(int) * master->num_chipselect, GFP_KERNEL); + sizeof(*master->cs_gpios) * master->num_chipselect, GFP_KERNEL); if (!master->cs_gpios) return -ENOMEM; - for (i = 0; i < master->num_chipselect; i++) - master->cs_gpios[i] = mxc_platform_info->chipselect[i]; + for (i = 0; i < master->num_chipselect; i++) { + struct gpio_desc *cs; + + cs = devm_gpiod_get_index(&pdev->dev, "spi-cs", i, + GPIOD_OUT_HIGH); + if (!IS_ERR(cs)) + master->cs_gpios[i] = cs; + } } spi_imx->bitbang.chipselect = spi_imx_chipselect; @@ -1327,19 +1333,6 @@ static int spi_imx_probe(struct platform_device *pdev) goto out_clk_put; } - for (i = 0; i < master->num_chipselect; i++) { - if (!gpio_is_valid(master->cs_gpios[i])) - continue; - - ret = devm_gpio_request(&pdev->dev, master->cs_gpios[i], - DRIVER_NAME); - if (ret) { - dev_err(&pdev->dev, "Can't get CS GPIO %i\n", - master->cs_gpios[i]); - goto out_clk_put; - } - } - dev_info(&pdev->dev, "probed\n"); clk_disable(spi_imx->clk_ipg); diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c index 86bf45667a04..91a498e25cbb 100644 --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c @@ -732,19 +732,6 @@ static int mtk_spi_probe(struct platform_device *pdev) ret = -EINVAL; goto err_disable_runtime_pm; } - - if (master->cs_gpios) { - for (i = 0; i < master->num_chipselect; i++) { - ret = devm_gpio_request(&pdev->dev, - master->cs_gpios[i], - dev_name(&pdev->dev)); - if (ret) { - dev_err(&pdev->dev, - "can't get CS GPIO %i\n", i); - goto err_disable_runtime_pm; - } - } - } } return 0; diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 918a53c884dd..3860f0c84e1a 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -40,6 +40,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -531,7 +532,9 @@ int spi_add_device(struct spi_device *spi) } if (ctlr->cs_gpios) - spi->cs_gpio = ctlr->cs_gpios[spi->chip_select]; + spi->cs_gpio = desc_to_gpio(ctlr->cs_gpios[spi->chip_select]); + else + spi->cs_gpio = -ENOENT; /* Drivers may modify this initial i/o setup, but will * normally rely on the device being setup. Devices @@ -1988,7 +1991,8 @@ EXPORT_SYMBOL_GPL(__spi_alloc_controller); #ifdef CONFIG_OF static int of_spi_register_master(struct spi_controller *ctlr) { - int nb, i, *cs; + int nb, i; + struct gpio_desc **cs; struct device_node *np = ctlr->dev.of_node; if (!np) @@ -2003,7 +2007,8 @@ static int of_spi_register_master(struct spi_controller *ctlr) else if (nb < 0) return nb; - cs = devm_kzalloc(&ctlr->dev, sizeof(int) * ctlr->num_chipselect, + cs = devm_kzalloc(&ctlr->dev, + sizeof(*ctlr->cs_gpios) * ctlr->num_chipselect, GFP_KERNEL); ctlr->cs_gpios = cs; @@ -2011,10 +2016,16 @@ static int of_spi_register_master(struct spi_controller *ctlr) return -ENOMEM; for (i = 0; i < ctlr->num_chipselect; i++) - cs[i] = -ENOENT; + cs[i] = NULL; + + for (i = 0; i < nb; i++) { + struct gpio_desc *gpio; - for (i = 0; i < nb; i++) - cs[i] = of_get_named_gpio(np, "cs-gpios", i); + gpio = devm_gpiod_get_index(&ctlr->dev, "cs", i, + GPIOD_OUT_HIGH); + if (!IS_ERR(gpio)) + cs[i] = gpio; + } return 0; } diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 7b2170bfd6e7..7e170db7bc9d 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -565,7 +565,7 @@ struct spi_controller { struct spi_message *message); /* gpio chip select */ - int *cs_gpios; + struct gpio_desc **cs_gpios; /* statistics */ struct spi_statistics statistics;