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: 154895 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3630584ljp; Mon, 7 Jan 2019 07:56:54 -0800 (PST) X-Google-Smtp-Source: ALg8bN6kf11H7hsPuhhHl4OXGom8ufJB9JM+fW9EMKwVVEzQ9m9rZSXSWQS93mjC/pCZBXFJ4um4 X-Received: by 2002:a17:902:346:: with SMTP id 64mr63491327pld.337.1546876614796; Mon, 07 Jan 2019 07:56:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546876614; cv=none; d=google.com; s=arc-20160816; b=BB7tqt4Ne1w88N8A6wL++bIzGFEgahoz0+PncCEg54CJ42T6f9/Qf2hLsEt9HbcgE4 UFKTmh7lXoGa85cfjrlYxSgJSv+3sZ+p9jO4gA8Y7p6WZtqS3jkeN6/1lXdx0LgDWtYR +w3a65h/JriG6TSD85Vkf61FYlV0yT2JmozQwXRws5y4P9IP39ZAEW/893Nr18+M2C+9 WUcKBIv1SpExd5HIl17GSoPlm2LdzYzQsjN0/ZDNj2fi5YGRlmSSXLvwuBB+NurNrnfJ u4AbzWrmfaV8R33sQcweNmALhYn07Xxu63SxiRSb+RFn+w9J3u7d5gXGbzLqswJQjDa3 7Pvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xm+Cu8zBByKaKqXFO/NKMdT+rDKwaF0UxMq7adQloU4=; b=AU7Cp1QsXfyRCqdJqX6TOkuQw9GOOEML2RKVX5jt1esEzSP146vMJ2DKSPw206GAPJ tDw3Fdmd+2x11YJ0diRATlsp/Vp67lW1kufK5TQQO3/EUw7/00lKpSm5rRNF6hep8vne NET7oCLfHyR0Se5iqAqiRiiy3FMqiqyfwv2Z5Pj0QFW72haEshOqWp/srlbMtaQKZWjy vMO1C0W4kzdBarZlGj/p4pencHhOJ2Sun65/oQzhwmD7LDkMR/z+Oktl/ryNey23Qx8a 1bslCT36c7CcLn626oTzHthduAUKNxrXarpgmqqH3hJJyi6JLty1M3TZvrEQjPx/0oVn UHIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cNU3CinQ; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 30si15959326pgv.191.2019.01.07.07.56.54; Mon, 07 Jan 2019 07:56:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cNU3CinQ; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727149AbfAGP4y (ORCPT + 1 other); Mon, 7 Jan 2019 10:56:54 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:39997 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726858AbfAGP4x (ORCPT ); Mon, 7 Jan 2019 10:56:53 -0500 Received: by mail-lj1-f196.google.com with SMTP id n18-v6so751125lji.7 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=UCoQFSWoWNL4/HurGsMtmsCQji6jPH5GrlYu7YSNqmAyfdUFqxEKRhPMDrm3xDsH1l Qb9WeIHce3I9oRGJ55sy9dvsrKaV9fD5Mj7UZND6NtJaowWFUIZMsUvgimcFFhkGxLQk XCLnmHOUl4w6lK+SBbNy53NA88TEetXielS1VgZzbOjUCDR2//7EPzvh4eDuXRfkdXNH BoXO6Czru1yoMt6+xkAh2i3h89arHmZhztr5Lyoc50liPzGANqzElrvXvo0hBaGS+QwP cBI/+d45rUOVra5ib3cWnrYVphiKOacNGLg0K3fwRU0ELNlZwHC0WWCqdmrIr0eNKe5h s4iw== X-Gm-Message-State: AJcUukdEE8N+x16XcZy7+4+QYlgxv6wFsvEQMbIM36qI3cuDGty4avIt hqeRQ41yUKs0lnrsJWCvdo9n1g== 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-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@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(-) -- 2.19.2 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);