From patchwork Mon Jul 17 16:07:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 9845583 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 A3A286037F for ; Mon, 17 Jul 2017 16:07:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95C6C2679B for ; Mon, 17 Jul 2017 16:07:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A98827E5A; Mon, 17 Jul 2017 16:07:38 +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 autolearn=unavailable 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 0FDCB2679B for ; Mon, 17 Jul 2017 16:07:38 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Date: Message-Id:In-Reply-To:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: References:List-Owner; bh=TCPVnER9FKf/rMABRRENGcpzlV3e5OmQla3tOqliii4=; b=a1E Gs3VxxeDkEOWRQDdrca9dpRCHoOjlR0PoQzsAIE9oc1I+hOMv0BJcGvT10kjGsReiJ1CNDTV492CL 9L/9YbJRA5odQmdjqHkKKcCKTTUmJ1/p24uE+nU0To004tFWt1k8Jl7H18j9XQ2fIiHy89Om/JzTg T44EyE2jd1uGAeihU0ZhleO+ay4RxPLerc0h8MazabufORLIZ8wOO1dAxA2uNxF50FxRs46rhPw57 I83rzQPrcjBbOgtZuKV28FlEH+MdtqX8YqVTTY2iOwUIyp5AyXiUa/RKdW9EMMcEpKrVJwtJib0rg QVI9YhO3ti+ltcf1MLhmQGszS6iIS7A==; 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 1dX8YZ-0008BO-FL; Mon, 17 Jul 2017 16:07:35 +0000 Received: from mezzanine.sirena.org.uk ([2400:8900::f03c:91ff:fedb:4f4]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dX8YU-00089Q-NT for linux-arm-kernel@lists.infradead.org; Mon, 17 Jul 2017 16:07:33 +0000 Received: from debutante.sirena.org.uk ([2001:470:1f1d:6b5::3] helo=debutante) by mezzanine.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1dX8Y5-0002x8-1w; Mon, 17 Jul 2017 16:07:07 +0000 Received: from broonie by debutante with local (Exim 4.89) (envelope-from ) id 1dX8Y2-0005II-GS; Mon, 17 Jul 2017 17:07:02 +0100 From: Mark Brown To: Jan Kiszka In-Reply-To: <90b3e14d-0077-9a25-9d90-ab340577af57@web.de> Message-Id: Date: Mon, 17 Jul 2017 17:07:02 +0100 X-SA-Exim-Connect-IP: 2001:470:1f1d:6b5::3 X-SA-Exim-Mail-From: broonie@sirena.org.uk Subject: Applied "spi: pxa2xx: Only claim CS GPIOs when the slave device is created" to the spi tree X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: No (on mezzanine.sirena.org.uk); Unknown failure X-Bad-Reply: In-Reply-To but no 'Re:' in Subject. X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170717_090730_987094_4EA05F45 X-CRM114-Status: GOOD ( 22.04 ) 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 , Haojian Zhuang , linux-spi@vger.kernel.org, Mark Brown , linux-arm-kernel , Robert Jarzmik , Daniel Mack MIME-Version: 1.0 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 The patch spi: pxa2xx: Only claim CS GPIOs when the slave device is created has been applied to the spi tree at git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark From 676a4e3bab445d53fca4756865e2c0e2a87c38d6 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Sat, 8 Jul 2017 10:41:18 +0200 Subject: [PATCH] spi: pxa2xx: Only claim CS GPIOs when the slave device is created 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 Signed-off-by: Mark Brown --- 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);