From patchwork Mon Jan 7 15:51:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 1021398 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="cNU3CinQ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43YKlC2B75z9sDP for ; Tue, 8 Jan 2019 02:56:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726858AbfAGP4y (ORCPT ); Mon, 7 Jan 2019 10:56:54 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:43316 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbfAGP4x (ORCPT ); Mon, 7 Jan 2019 10:56:53 -0500 Received: by mail-lj1-f196.google.com with SMTP id q2-v6so729896lji.10 for ; Mon, 07 Jan 2019 07:56:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xm+Cu8zBByKaKqXFO/NKMdT+rDKwaF0UxMq7adQloU4=; b=cNU3CinQW5zo+xIEt9jIp1uVC/k98YkuxcHznXMZTCmp7f3D8ApD9Ivh3xdIjhKFdP 1gvnijaMMnhcH7jMmlW1J4s81rcULhdwu4AQYZ4TxnGbft57cWaE6uw+lHCzjZcdj+AS blmvVOWy0/PIIDhCKKYVhTvzvs7nwcWjBpnXQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xm+Cu8zBByKaKqXFO/NKMdT+rDKwaF0UxMq7adQloU4=; b=OydP27OG8qkjV0Und7j2ksX9xsi6OihuLjVTcFJ9Bnsfc0bQu79xvmNj8D2RhzqCMF 03v0RVVywlC3cqrBD3K+AKF96b06jY/kSqTHWkxm4Fxh4jAQmzQ1DLe6rO6kpElrrd+h Xfmjfbusc6u4mjYvAtJ6nK76gSlBY4jRVBqTHCbC7vSjdNqHce3jqvyogAuEvSmblxp2 5h2dHTxxzDFKaFPvR0XOW3RA6KSOCmTPVUYAX9SJlOoLDbsmNSJO9EXgGNwcKV02S2o6 5IhFpgW3BgUHCdhxFvIu0Akz55lHWKdBPOFM7F/rcqViTgUlCXgoZqIHeXZtpmByRFaG 4lmw== X-Gm-Message-State: AJcUukdcEkb3rKSO6pV82j3UI07Fk38y54f8w8ue0SEYcGFwTO2Ajj/7 CYPoVoKKX6VqCxDA8zvHVLHbhbT4548PRff3 X-Google-Smtp-Source: ALg8bN4LTx2UbXCh/GRhuKn0F2YfZfhlOdEDdsIRjJXg5oHOMFRes9fTg3D+nn7rGzTo1UUgCpklMw== X-Received: by 2002:a2e:9b52:: with SMTP id o18-v6mr33691891ljj.108.1546876611000; Mon, 07 Jan 2019 07:56:51 -0800 (PST) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id t22sm13269164lfb.0.2019.01.07.07.56.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Jan 2019 07:56:49 -0800 (PST) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski , linuxarm@huawei.com, Linus Walleij , David Lechner Subject: [PATCH 6/7 v2] spi: davinci: Convert to use CS GPIO descriptors Date: Mon, 7 Jan 2019 16:51:55 +0100 Message-Id: <20190107155156.3738-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190107155156.3738-1-linus.walleij@linaro.org> References: <20190107155156.3738-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This converts the DaVinci SPI master driver to use GPIO descriptors for chip select handling. DaVinci parses the device tree a second time for the chip select GPIOs (no relying on the parsing already happening in the SPI core) and handles inversion semantics locally. We simply drop the extra parsing and set up and move the CS handling to the core and gpiolib. The fact that the driver is actively driving the GPIO in the davinci_spi_chipselect() callback is confusing since the host does not set SPI_MASTER_GPIO_SS so this should not ever get called when using GPIO CS. I put in a comment about this. This driver also supports instantiation from board files, but these are all using native chip selects so no problem with GPIO lines here. Cc: David Lechner Cc: Bartosz Golaszewski Cc: Linuxarm Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebase on v5.0-rc1 --- drivers/spi/spi-davinci.c | 53 ++++++++++----------------------------- 1 file changed, 13 insertions(+), 40 deletions(-) diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c index 56adec83f8fc..5870afe3845b 100644 --- a/drivers/spi/spi-davinci.c +++ b/drivers/spi/spi-davinci.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include #include @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -222,12 +221,17 @@ static void davinci_spi_chipselect(struct spi_device *spi, int value) * Board specific chip select logic decides the polarity and cs * line for the controller */ - if (spi->cs_gpio >= 0) { + if (spi->cs_gpiod) { + /* + * FIXME: is this code ever executed? This host does not + * set SPI_MASTER_GPIO_SS so this chipselect callback should + * not get called from the SPI core when we are using + * GPIOs for chip select. + */ if (value == BITBANG_CS_ACTIVE) - gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH); + gpiod_set_value(spi->cs_gpiod, 1); else - gpio_set_value(spi->cs_gpio, - !(spi->mode & SPI_CS_HIGH)); + gpiod_set_value(spi->cs_gpiod, 0); } else { if (value == BITBANG_CS_ACTIVE) { if (!(spi->mode & SPI_CS_WORD)) @@ -418,7 +422,6 @@ static int davinci_spi_of_setup(struct spi_device *spi) */ static int davinci_spi_setup(struct spi_device *spi) { - int retval = 0; struct davinci_spi *dspi; struct spi_master *master = spi->master; struct device_node *np = spi->dev.of_node; @@ -427,21 +430,11 @@ static int davinci_spi_setup(struct spi_device *spi) dspi = spi_master_get_devdata(spi->master); if (!(spi->mode & SPI_NO_CS)) { - if (np && (master->cs_gpios != NULL) && (spi->cs_gpio >= 0)) { - retval = gpio_direction_output( - spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); + if (np && spi->cs_gpiod) internal_cs = false; - } - - if (retval) { - dev_err(&spi->dev, "GPIO %d setup failed (%d)\n", - spi->cs_gpio, retval); - return retval; - } - if (internal_cs) { + if (internal_cs) set_io_bits(dspi->base + SPIPC0, 1 << spi->chip_select); - } } if (spi->mode & SPI_READY) @@ -962,6 +955,7 @@ static int davinci_spi_probe(struct platform_device *pdev) if (ret) goto free_master; + master->use_gpio_descriptors = true; master->dev.of_node = pdev->dev.of_node; master->bus_num = pdev->id; master->num_chipselect = pdata->num_chipselect; @@ -980,27 +974,6 @@ static int davinci_spi_probe(struct platform_device *pdev) if (dspi->version == SPI_VERSION_2) dspi->bitbang.flags |= SPI_READY; - if (pdev->dev.of_node) { - int i; - - for (i = 0; i < pdata->num_chipselect; i++) { - int cs_gpio = of_get_named_gpio(pdev->dev.of_node, - "cs-gpios", i); - - if (cs_gpio == -EPROBE_DEFER) { - ret = cs_gpio; - goto free_clk; - } - - if (gpio_is_valid(cs_gpio)) { - ret = devm_gpio_request(&pdev->dev, cs_gpio, - dev_name(&pdev->dev)); - if (ret) - goto free_clk; - } - } - } - dspi->bitbang.txrx_bufs = davinci_spi_bufs; ret = davinci_spi_request_dma(dspi);