From patchwork Sat Jul 8 08:41:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 9831437 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 78F48602A0 for ; Sat, 8 Jul 2017 08:41:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65BE228516 for ; Sat, 8 Jul 2017 08:41:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56DA128528; Sat, 8 Jul 2017 08:41:56 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AFA0828516 for ; Sat, 8 Jul 2017 08:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Date:Message-ID:Subject: From:To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=1g3C60IHXVe8/nVcCuZ1ZGwMD2ICfagNMvLI6MhxTlk=; b=eH9Nl8X04HBY6H Vzfd5zrnD+YPJExrZcOLLU4+Sdn33BSs5wt2FXiug78/MhV+yCSL37M/NxnJaaTQut+Vd8zj5WnUx 2IbtPwsrFxdUlh6PiI5QHuRiPTKD07DX8lnN75ul301smzqNULC78DiepaKdDqXzDkXwbJjr5a3nn Cudwq21rEDXNkz7y16t6UCCGaYWxh501224ebFNerKK+M0PpRC6L+AGVcfedwCw92tHSqhlc/984p p2VFlrZqHIBv0q8/BdT0WLy0tMPD5r4MuuxMY5r62AktGLgO2hBJF5jU+6gejhJcVKecw9wjl23iK /hpOGvEfz6A2RneT6rBg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dTlJH-0001bv-Tx; Sat, 08 Jul 2017 08:41:51 +0000 Received: from mout.web.de ([212.227.15.4]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dTlJD-0001bN-H9 for linux-arm-kernel@lists.infradead.org; Sat, 08 Jul 2017 08:41:49 +0000 Received: from md1f2u6c.ww002.siemens.net ([95.157.57.47]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LlayN-1e4kXo0erH-00bLfL; Sat, 08 Jul 2017 10:41:19 +0200 To: Daniel Mack , Haojian Zhuang , Robert Jarzmik , Mark Brown From: Jan Kiszka Subject: [PATCH] spi: pxa2xx: Only claim CS GPIOs when the slave device is created Message-ID: <90b3e14d-0077-9a25-9d90-ab340577af57@web.de> Date: Sat, 8 Jul 2017 10:41:18 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 Content-Language: en-US X-Provags-ID: V03:K0:KuIvbXI0h5ewTMhoqRUDK2EF5slVwI3pMSdPO5W3jFBnKhXXC7e 4H3ENfXj4DWLWBVFBdOUluAENLSMjvn3hXBudYXDbh1Ez6yRopSqRjyNVPK3ElaZ2IJD+Cy XWuPBSfnBMR3YclcMcmqAZbuTs9Nwn4R9DK4BpuIOe/WbpY4sUyFSUxhG5ot4iTkYQU7y6V 2340AzN0yk45iJtIRZisQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:XcNB3WZobtk=:9ulR+/7JSyZLL/5BjHT/IJ svBW5KQEnPkeuw+6Dujax4KnU5wa1UygbuaZzvaIDmZyb42bdj7hDl4SGhCLNXgsgMjOUKM6u KLSZPke1DL9yINRKPe00pDrlVLxVvm9OaDH3qJ2Ic/S5WivWpEf6q3vioGiZzmWDl0yMw9Yjn hOKqx5WtAW21pewEj6NEXvAriYgxTOC+kkakXALPE3Y3fbdIHKOPc4NYMps4b3GDFFwgEC4VJ Q3BJScc2bUs1IwLesFED9UOlEYrnHTalCyyCEUCySuItpVktd+NygU9HD9HKjO3UoXzWdxC7H 3abMOPdQkEm3KrN98SYqf1B35bQKEM+3Zytx5AlKTaLRqgfGyHtd1i8pTbbROXcn59zSc7xiM bG7TW7aE9kbFyzNMi0coVvyHo+pN/2M2GItOWIdYgfvMMb8N7iDkvLFS3aH3quxwRkjUglWcj n/kHHkL0gDhW7tqAR9Ek2/J4bt7kw+8O0inFzyaIlCdOjodxJ4BzIa8Yts2NHDhjn0P2qSLC7 ujrne9hy6sieOxoYWxsQdDu1eJJDUVHW9wTGuAn3QUyhVPLRUVlLErIRGDM6/ePrypkWD/mws 3PTSCrl2pFyXQM4CDqW0rBHiA9BG9iea/jPXQkbHPW3oDCDRUgxxQor0VA4Qx1A/hxrQ7YtYt ptN11MWd45yQPLFCZfwLUq0qlVA0gVZGcJmmB57ik7eaMRnEJKxacD4dl4xFfwybDvYcXQJOU qFStXyOwUrP1HUfRnKeSwXcWGFtlhAakTPZ+N2jK/AgtMu9soEW4p2aI77QhZiHMQ35Xg1ytT krXK28K X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170708_014147_936819_773B5FA0 X-CRM114-Status: GOOD ( 17.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linux Kernel Mailing List , linux-arm-kernel , linux-spi@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jan Kiszka Avoid hogging chip select GPIOs just because they are listed for the master. They might be mulitplexed and, if no slave device is attached, used for different purposes. Moreover, this strategy avoids having to allocate a cs_gpiods structure. Tested on the IOT2000 where the second SPI bus is connected to an Arduino-compatible connector and multiplexed between SPI, GPIO and PWM usage. Signed-off-by: Jan Kiszka --- drivers/spi/spi-pxa2xx.c | 59 +++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index 38d053682892..be991266a6ce 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c @@ -1213,21 +1213,33 @@ static int setup_cs(struct spi_device *spi, struct chip_data *chip, struct pxa2xx_spi_chip *chip_info) { struct driver_data *drv_data = spi_master_get_devdata(spi->master); + struct device *pdev = &drv_data->pdev->dev; + struct gpio_desc *gpiod; int err = 0; + int count; if (chip == NULL) return 0; - if (drv_data->cs_gpiods) { - struct gpio_desc *gpiod; + count = gpiod_count(pdev, "cs"); + if (count > 0) { + if (spi->chip_select >= count) + return -EINVAL; + + gpiod = gpiod_get_index(pdev, "cs", spi->chip_select, + GPIOD_OUT_HIGH); + if (IS_ERR(gpiod)) { + /* Means use native chip select */ + if (PTR_ERR(gpiod) == -ENOENT) + return 0; - gpiod = drv_data->cs_gpiods[spi->chip_select]; - if (gpiod) { - chip->gpio_cs = desc_to_gpio(gpiod); - chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH; - gpiod_set_value(gpiod, chip->gpio_cs_inverted); + return PTR_ERR(gpiod); } + chip->gpio_cs = desc_to_gpio(gpiod); + chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH; + gpiod_set_value(gpiod, chip->gpio_cs_inverted); + return 0; } @@ -1415,8 +1427,7 @@ static void cleanup(struct spi_device *spi) if (!chip) return; - if (drv_data->ssp_type != CE4100_SSP && !drv_data->cs_gpiods && - gpio_is_valid(chip->gpio_cs)) + if (drv_data->ssp_type != CE4100_SSP && gpio_is_valid(chip->gpio_cs)) gpio_free(chip->gpio_cs); kfree(chip); @@ -1752,38 +1763,10 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) master->num_chipselect = platform_info->num_chipselect; count = gpiod_count(&pdev->dev, "cs"); - if (count > 0) { - int i; - + if (count > 0) master->num_chipselect = max_t(int, count, master->num_chipselect); - drv_data->cs_gpiods = devm_kcalloc(&pdev->dev, - master->num_chipselect, sizeof(struct gpio_desc *), - GFP_KERNEL); - if (!drv_data->cs_gpiods) { - status = -ENOMEM; - goto out_error_clock_enabled; - } - - for (i = 0; i < master->num_chipselect; i++) { - struct gpio_desc *gpiod; - - gpiod = devm_gpiod_get_index(dev, "cs", i, - GPIOD_OUT_HIGH); - if (IS_ERR(gpiod)) { - /* Means use native chip select */ - if (PTR_ERR(gpiod) == -ENOENT) - continue; - - status = (int)PTR_ERR(gpiod); - goto out_error_clock_enabled; - } else { - drv_data->cs_gpiods[i] = gpiod; - } - } - } - tasklet_init(&drv_data->pump_transfers, pump_transfers, (unsigned long)drv_data);