From patchwork Sat Dec 15 23:38:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 153943 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp955888ljp; Sat, 15 Dec 2018 15:46:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/W+/da5ZqU7ryKQflCiWQ386h7tjbZSF5ZC7H+IoQNMCd3WSFOWQqbGCjhvtJpbARAOGk48 X-Received: by 2002:a17:902:7296:: with SMTP id d22mr8096868pll.265.1544917573823; Sat, 15 Dec 2018 15:46:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544917573; cv=none; d=google.com; s=arc-20160816; b=w5J5e4V9rloJl1Wm5/a0m5fN5DKlEJskt1PXu2orhDmab2ok+01hXRcsc/yEeSw1EP +RQXtoej1zTgqBrMoGYA5V0kF0fiuwQdC3rM0+wIk0WJQ1dwELrNXFSoTEt1VgPtpXky DHEJ9MMQXlVUjUt4+XdmMy9D2daYkFUNA5lN43u+/o0bD4N3HtU/yWf9dQ67GuszMMFa OmoMgtrhhQQ9+uomNMEL1V560IDJhuD4ateJhzid1hyjGnc1n/0q2PbDm3q5E9GkQqXE hREXOluC44tJ4gIMI+9PO1tWbEKRL91/33R+rFGyFvZ4//3IYLE7nr2sSmDyvUoINRjM bHIw== 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=+QVluDsAh2KxwyVgFTK4TpkVU9aWMBwmEKsmYxoK/Rw=; b=qRlbBi265rpSiJs+/9zwIVV3N6VJDLrxWRaMA5+onjUX7g8NgnGDtUl/beSUk3p+nK jMXiJzJB2OqDyZ3KsUgEl+ytsTJd5jiI+zff6sLip5iDS6m9gwvj2hQ0GSeuJkIW+v69 2pJU5VAviyVR0aHhmxI4B/rQjeQUM5dxkyjvAM3u1NzeNR+RKsVVdTvPSPt9HBf9XKGb YMUfcSgna7249Xicf3D2msFBw5t9lhT8u8ENeAYJ4SPIQXlkD0H7Zk61VKd8fAQhKInp OSNSGOd/Uye4dMgDDBfCp/6GnJl5an7CqEfOyVheZgs4g7PslgWGeUNGKVJa7KdTNe8Q 3b3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aG3aq7yl; 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 1si7185999pld.239.2018.12.15.15.46.13; Sat, 15 Dec 2018 15:46:13 -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=aG3aq7yl; 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 S1728593AbeLOXqN (ORCPT + 1 other); Sat, 15 Dec 2018 18:46:13 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:34809 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727256AbeLOXqN (ORCPT ); Sat, 15 Dec 2018 18:46:13 -0500 Received: by mail-lj1-f196.google.com with SMTP id u6-v6so7976702ljd.1 for ; Sat, 15 Dec 2018 15:46:10 -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=+QVluDsAh2KxwyVgFTK4TpkVU9aWMBwmEKsmYxoK/Rw=; b=aG3aq7ylSyaYGwCyBe7eIqpyTzNqaGRrHhRNlSSjaHS9UJLXxicmSIp2ja6Tc0Lr0a DPzBuZMr2Ta+M4tE9Nyb5b/NCe9V0p9yJyiIjJJFG2tNYz5xJyRcptxuplcN2zOU34Nf 8cjLU0F2AKlGErr5dAUn1w2lL7KNlC3ilNj3c= 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=+QVluDsAh2KxwyVgFTK4TpkVU9aWMBwmEKsmYxoK/Rw=; b=sY8YMhaTIurVD47b33epSb0O8df9Qo5AFof1YSk9MYwwW2GQEQ1P7eGYDQjRuVJvfx YUEZcW8R/42SBHBfGsh0sRKt+dJq0IVGiCJ2/JSJEeFLeO71bIYYSqKZ+N4ZNyL54b0f ejhWjx+8d2NTZ0agWpujcg2dh/2Utd5UDNr/j+7v1C48mME6Uan30vh/Cw33vf9xhFlO DTI/87asClv878iC/BMwTlKEkpYuTioN6PYjWADqvjXUgJ05P/yH4Nil6NBNs7CqGlOg FBsybTXFD09W8o9432kqgGkNVoN3cnWk1d5Q08Gl+vMxHCrYRj0UrVGgryaegkEFoT3n o0Tw== X-Gm-Message-State: AA+aEWYqBMEDMB9NjaVEW8ARJCJA9mShGikQyV8B0qSg3hiRgE6zzXCC tqG9SIbj6w0BfcxBwSiCMC9tZQ== X-Received: by 2002:a2e:4601:: with SMTP id t1-v6mr5041487lja.111.1544917570088; Sat, 15 Dec 2018 15:46:10 -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 v19sm1709880lfe.69.2018.12.15.15.46.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 15 Dec 2018 15:46:08 -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 v1] spi: davinci: Convert to use CS GPIO descriptors Date: Sun, 16 Dec 2018 00:38:22 +0100 Message-Id: <20181215233823.1042-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181215233823.1042-1-linus.walleij@linaro.org> References: <20181215233823.1042-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 --- 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);