From patchwork Fri Jan 8 13:44:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 7985891 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6E914BEEE5 for ; Fri, 8 Jan 2016 13:45:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7B695201B9 for ; Fri, 8 Jan 2016 13:45:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5EC1C2017E for ; Fri, 8 Jan 2016 13:45:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754818AbcAHNpH (ORCPT ); Fri, 8 Jan 2016 08:45:07 -0500 Received: from mezzanine.sirena.org.uk ([106.187.55.193]:42035 "EHLO mezzanine.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751994AbcAHNpE (ORCPT ); Fri, 8 Jan 2016 08:45:04 -0500 Received: from cpc11-sgyl31-2-0-cust672.sgyl.cable.virginm.net ([94.175.94.161] helo=debutante) by mezzanine.sirena.org.uk with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1aHXLf-0003gG-E6; Fri, 08 Jan 2016 13:45:00 +0000 Received: from broonie by debutante with local (Exim 4.86) (envelope-from ) id 1aHXLc-0003NY-Kd; Fri, 08 Jan 2016 13:44:56 +0000 From: Mark Brown To: Mans Rullgard , Mark Brown Cc: linux-spi@vger.kernel.org In-Reply-To: <1452211907-16074-1-git-send-email-mans@mansr.com> Message-Id: Date: Fri, 08 Jan 2016 13:44:56 +0000 X-SA-Exim-Connect-IP: 94.175.94.161 X-SA-Exim-Mail-From: broonie@sirena.org.uk X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: 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 Subject: Applied "spi: atmel: improve internal vs gpio chip-select choice" to the spi tree X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on mezzanine.sirena.org.uk) 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 The patch spi: atmel: improve internal vs gpio chip-select choice 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 3fe5e14919b7ef2792aed8cacd7d1ae3e30adcd2 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Fri, 8 Jan 2016 00:11:47 +0000 Subject: [PATCH] spi: atmel: improve internal vs gpio chip-select choice The driver currently chooses between internal chip-select or gpio based on the existence of the cs-gpios DT property which fails on non-DT systems and also enforces the same choice for all devices. This patch makes the method per device instead of per controller and fixes the selection on non-DT systems. With these changes, the chip-select method for each device is chosen according to the following priority: 1. GPIO from device tree 2. GPIO from platform data 3. Internal chip-select Tested on AVR32 ATSTK1000. Signed-off-by: Mans Rullgard Signed-off-by: Mark Brown --- drivers/spi/spi-atmel.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index aebad36391c9..8be07fb67d4d 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c @@ -310,7 +310,6 @@ struct atmel_spi { bool use_dma; bool use_pdc; - bool use_cs_gpios; /* dmaengine data */ struct atmel_spi_dma dma; @@ -324,6 +323,7 @@ struct atmel_spi { struct atmel_spi_device { unsigned int npcs_pin; u32 csr; + bool use_cs_gpio; }; #define BUFFER_SIZE PAGE_SIZE @@ -388,7 +388,7 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi) } mr = spi_readl(as, MR); - if (as->use_cs_gpios) + if (asd->use_cs_gpio) gpio_set_value(asd->npcs_pin, active); } else { u32 cpol = (spi->mode & SPI_CPOL) ? SPI_BIT(CPOL) : 0; @@ -405,7 +405,7 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi) mr = spi_readl(as, MR); mr = SPI_BFINS(PCS, ~(1 << spi->chip_select), mr); - if (as->use_cs_gpios && spi->chip_select != 0) + if (asd->use_cs_gpio && spi->chip_select != 0) gpio_set_value(asd->npcs_pin, active); spi_writel(as, MR, mr); } @@ -434,7 +434,7 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi) asd->npcs_pin, active ? " (low)" : "", mr); - if (!as->use_cs_gpios) + if (!asd->use_cs_gpio) spi_writel(as, CR, SPI_BIT(LASTXFER)); else if (atmel_spi_is_v2(as) || spi->chip_select != 0) gpio_set_value(asd->npcs_pin, !active); @@ -1221,8 +1221,6 @@ static int atmel_spi_setup(struct spi_device *spi) csr |= SPI_BIT(CPOL); if (!(spi->mode & SPI_CPHA)) csr |= SPI_BIT(NCPHA); - if (!as->use_cs_gpios) - csr |= SPI_BIT(CSAAT); /* DLYBS is mostly irrelevant since we manage chipselect using GPIOs. * @@ -1233,21 +1231,28 @@ static int atmel_spi_setup(struct spi_device *spi) csr |= SPI_BF(DLYBS, 0); csr |= SPI_BF(DLYBCT, 0); - /* chipselect must have been muxed as GPIO (e.g. in board setup) */ - npcs_pin = (unsigned long)spi->controller_data; - - if (!as->use_cs_gpios) - npcs_pin = spi->chip_select; - else if (gpio_is_valid(spi->cs_gpio)) - npcs_pin = spi->cs_gpio; - asd = spi->controller_state; if (!asd) { asd = kzalloc(sizeof(struct atmel_spi_device), GFP_KERNEL); if (!asd) return -ENOMEM; - if (as->use_cs_gpios) { + npcs_pin = (unsigned long)spi->controller_data; + + if (gpio_is_valid(spi->cs_gpio)) { + /* GPIO from DT */ + npcs_pin = spi->cs_gpio; + asd->use_cs_gpio = true; + } else if (npcs_pin && gpio_is_valid(npcs_pin)) { + /* GPIO from platform data */ + asd->use_cs_gpio = true; + } else { + /* internal chip-select */ + npcs_pin = spi->chip_select; + asd->use_cs_gpio = false; + } + + if (asd->use_cs_gpio) { ret = gpio_request(npcs_pin, dev_name(&spi->dev)); if (ret) { kfree(asd); @@ -1262,6 +1267,8 @@ static int atmel_spi_setup(struct spi_device *spi) spi->controller_state = asd; } + if (!asd->use_cs_gpio) + csr |= SPI_BIT(CSAAT); asd->csr = csr; dev_dbg(&spi->dev, @@ -1569,13 +1576,6 @@ static int atmel_spi_probe(struct platform_device *pdev) atmel_get_caps(as); - as->use_cs_gpios = true; - if (atmel_spi_is_v2(as) && - !of_get_property(pdev->dev.of_node, "cs-gpios", NULL)) { - as->use_cs_gpios = false; - master->num_chipselect = 4; - } - as->use_dma = false; as->use_pdc = false; if (as->caps.has_dma_support) {