From patchwork Mon Jan 7 15:51:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 154891 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3630436ljp; Mon, 7 Jan 2019 07:56:44 -0800 (PST) X-Google-Smtp-Source: ALg8bN4rN5bKiqfig5yA+tZUebWLp8MdfHRt6FVrnItVgVhPB6LMlNAGrLM+4thJR6d5c4xYg6EO X-Received: by 2002:a17:902:161:: with SMTP id 88mr63226833plb.306.1546876604211; Mon, 07 Jan 2019 07:56:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546876604; cv=none; d=google.com; s=arc-20160816; b=lmZRwaX5yCA4RXAVIrOOF9R/wChkxu1uhkBEJP9GLUguxHeBlogbu547a5V7gC+DIz Cw8d8b6X2MPip2X98Syj4xaXOcL5S51hFGggu91U1Scg66Oz8oellgovWU3gsCaW1SVF fOzbZWUkAPiOMljM8VsI2QuEdUEcAKyXZc3N4dBFJe9IIgC7yceUxWDpfo7Gx0egC4GZ nC9B8qGdIroBIBxqjYLl2rcUdpJEdqKddq66mzfqaeFeC3/IxXrouWSQma27pl9v35up rYKJXw7YdLhcO1EB9PAVL0TwQkf2IMNxF3D89hXZFaCI9BWS5a5mEPgwoo8Qhy0rvFuP ab1w== 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=329rMIw7dk8N5WV5b3QguRojP7Xyn99GAFQEKXGZQEs=; b=YhXWsTE9bFTRFe9NrJbTc3QIhIRcq+VZcC5L9nq2Fl2JTt3KRMI6nY7stppGnAJDqQ wT5lWYOrNlbqnyj4GwsGXH2whlZ8cq6mMvnYxXw6K/EJ+y3XB01/cA/WJpWFmGPjnlS6 AC0XNDF0U9FM/26ekWkXz1B1iS9BjEn8G5308dlxPyZZEQuZc4H7XvzroUQOmyFtzfnA J1NB9Ic/cYd5BK7TV2K+ab5oKcFPkPzoXnnsCJ4TCWqN1ZjEAz76nOow4xH6dG0T6ROD Pfrs9QVajcRqFwqstiFfK3otf8TnARl1O7MXrtZDNsZ+ROZjluxPTDdk5G9GroH2rsTR wrkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gN+y+595; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-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 l7si3021110pgk.169.2019.01.07.07.56.44; Mon, 07 Jan 2019 07:56:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-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=gN+y+595; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-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 S1727316AbfAGP4n (ORCPT + 5 others); Mon, 7 Jan 2019 10:56:43 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:41299 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726858AbfAGP4m (ORCPT ); Mon, 7 Jan 2019 10:56:42 -0500 Received: by mail-lj1-f193.google.com with SMTP id k15-v6so738141ljc.8 for ; Mon, 07 Jan 2019 07:56:40 -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=329rMIw7dk8N5WV5b3QguRojP7Xyn99GAFQEKXGZQEs=; b=gN+y+595Yove8MadqCNy4hJYDphMRQorwd3AT4DqAFybqXz9B3OTmVHv3faKVeokKW SX/fZfKgigizvQTgwmAGNVeaLTz37oSVF31sKhb1na/oe10Uc2pL+sh/VDzr5Yw+iQzp qKC0qCVwEIv4Ash7Ktxpaxqp9ei0Dzjyg/NHM= 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=329rMIw7dk8N5WV5b3QguRojP7Xyn99GAFQEKXGZQEs=; b=h9R1xucOi0gj+3fCbhnLf4LDGNCk0wRWZd/8g0BI79FfEl2Yb+x/un90fzlo6bac0I 5IBRKD3LML1/w+PItpmW1Ujw46CDkFPNWQW/SX12Oz881vqwO7trNA06ClBPVzPkRPYZ RPkHhtRdnjDO3I09VJrxepgHwUu2g3tKI1CA/qBvPsephk2ozRHibyVl/8kkCKMEsPw8 IZNRnSQEiDhL3h8g7uMwlqKkNuWFTshxpSQNQFxkIdEemaAliFq6DdwKg+e9Lem/dv58 fonGHFkGJQE8p/A3EVcUuqlVVq1CSYQIO6LnjfJf6bYrDUVzXtPFlvbDPH5bdP9BKfZw adwg== X-Gm-Message-State: AJcUukdyhrNdh+yT5qUtU7oKHCDtMwuivmAak333QGg6ZtEkTQhOvimc N/qrhVVi+9NGu6d0N8r2u6Hqng== X-Received: by 2002:a2e:9bc3:: with SMTP id w3-v6mr33347697ljj.70.1546876599911; Mon, 07 Jan 2019 07:56:39 -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.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Jan 2019 07:56:38 -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 , Felix Fietkau , Alban Bedel Subject: [PATCH 2/7 v2] spi: ath79: Convert to use CS GPIO descriptors Date: Mon, 7 Jan 2019 16:51:51 +0100 Message-Id: <20190107155156.3738-3-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 ATH79 SPI master driver to use GPIO descriptors for chip select handling. The ATH79 driver was requesting the GPIO and driving it from the bitbang .chipselect callback. Do not request it anymore as the SPI core will request it, remove the line inversion semantics for the GPIO case (handled by gpiolib) and let the SPI core deal with requesting the GPIO line from the device tree node of the controller. This driver can be instantiated from a board file (no device tree) but the board files only use native CS (no GPIO lines) so we should be fine just letting the SPI core grab the GPIO from the device. The fact that the driver is actively driving the GPIO in the ath79_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. Cc: Felix Fietkau Cc: Alban Bedel Cc: Linuxarm Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebase on v5.0-rc1 --- drivers/spi/spi-ath79.c | 42 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) -- 2.19.2 diff --git a/drivers/spi/spi-ath79.c b/drivers/spi/spi-ath79.c index 3f6b657394de..ed1068ac055f 100644 --- a/drivers/spi/spi-ath79.c +++ b/drivers/spi/spi-ath79.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include @@ -78,9 +78,16 @@ static void ath79_spi_chipselect(struct spi_device *spi, int is_active) ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base); } - if (gpio_is_valid(spi->cs_gpio)) { - /* SPI is normally active-low */ - gpio_set_value_cansleep(spi->cs_gpio, cs_high); + if (spi->cs_gpiod) { + /* + * SPI chipselect is normally active-low, but + * inversion semantics are handled by gpiolib. + * + * FIXME: is this ever used? The driver doesn't + * set SPI_MASTER_GPIO_SS so this callback should not + * get called if a CS GPIO is found by the SPI core. + */ + gpiod_set_value_cansleep(spi->cs_gpiod, is_active); } else { u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select); @@ -118,21 +125,8 @@ static void ath79_spi_disable(struct ath79_spi *sp) static int ath79_spi_setup_cs(struct spi_device *spi) { struct ath79_spi *sp = ath79_spidev_to_sp(spi); - int status; - status = 0; - if (gpio_is_valid(spi->cs_gpio)) { - unsigned long flags; - - flags = GPIOF_DIR_OUT; - if (spi->mode & SPI_CS_HIGH) - flags |= GPIOF_INIT_LOW; - else - flags |= GPIOF_INIT_HIGH; - - status = gpio_request_one(spi->cs_gpio, flags, - dev_name(&spi->dev)); - } else { + if (!spi->cs_gpiod) { u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select); if (spi->mode & SPI_CS_HIGH) @@ -143,13 +137,7 @@ static int ath79_spi_setup_cs(struct spi_device *spi) ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base); } - return status; -} - -static void ath79_spi_cleanup_cs(struct spi_device *spi) -{ - if (gpio_is_valid(spi->cs_gpio)) - gpio_free(spi->cs_gpio); + return 0; } static int ath79_spi_setup(struct spi_device *spi) @@ -163,15 +151,12 @@ static int ath79_spi_setup(struct spi_device *spi) } status = spi_bitbang_setup(spi); - if (status && !spi->controller_state) - ath79_spi_cleanup_cs(spi); return status; } static void ath79_spi_cleanup(struct spi_device *spi) { - ath79_spi_cleanup_cs(spi); spi_bitbang_cleanup(spi); } @@ -225,6 +210,7 @@ static int ath79_spi_probe(struct platform_device *pdev) pdata = dev_get_platdata(&pdev->dev); + master->use_gpio_descriptors = true; master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); master->setup = ath79_spi_setup; master->cleanup = ath79_spi_cleanup;