From patchwork Sat Dec 15 23:38:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 153941 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp955852ljp; Sat, 15 Dec 2018 15:46:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/UUayp2l/LZ55qNfVhf6xbedKjvZd576Oes9WEWJKvTcaiZIqNA3SZ7ohbhVu+woD8h+aKB X-Received: by 2002:a63:1766:: with SMTP id 38mr7308419pgx.299.1544917569667; Sat, 15 Dec 2018 15:46:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544917569; cv=none; d=google.com; s=arc-20160816; b=IxiWX9fOqzB4FAx/CkPevR+tcl5yEyPgrjPkcEA+IGhgd8Oe8fqI3u8o0qlm0fqRSI GBcni67pc5+hoocXwq9wOdL0fWAIwnzmmbjfa56YJNgR/Qffe6luvY8cTAbFqJg8mpaq MwwtEreIcEho/SWfLgScqmVS/KirWwCMTmeolete8+ieIQG75bbHxKHQj6sdysWDclSz 3DriM/dS1zHni5pjcVZ0a+Kz3fILnYnekeEpRUvPWc2gQASQwgjgUHl9PJ/MgEy4CbsG rplhVjaRH+QPKVZqyxdX872KKVsjwP6UASxloq5e7LfgNHHa/IEUil6NcHTOC/hMwgvt 8gmg== 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=AdOu5d31aFQ5LgQsJ6SO2qeANRtSbPy5gK/PxN19mo4=; b=NgAvwVLaNnsY1xrLMnhrPEqOuOMSbWh4RLI1FTxjO6YOI8g8tFcCSvv4hM6KT0pbOf 0fdmLOo2MnIWm1+cBvGrTIofZN8LBTtROZDZ71lno9HtypLEtRD+RRPKpVP/D61DNYcq IhukvXNHDqPUyoGLghs8KtFUvlD+pYmMNroQv1y/w5M1RppoWeS1TfhZntnIsL0935cF C8BxcWOugHWeKgLmzFgTLRB7ndA+ua4/9RArBYWk4dRx8PbFhtKW3b4hzgPPOmFYXCY0 Yi69gNbVsNg9ImpgDwiYDWvf3/ggBkD8dJBAYmXv+Kwu06CvaBGCqnARJ7FJ85En3EXE UjnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Wwr8azjR; 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 1si7185999pld.239.2018.12.15.15.46.09; Sat, 15 Dec 2018 15:46:09 -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=Wwr8azjR; 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 S1728203AbeLOXqJ (ORCPT + 5 others); Sat, 15 Dec 2018 18:46:09 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:39764 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727558AbeLOXqI (ORCPT ); Sat, 15 Dec 2018 18:46:08 -0500 Received: by mail-lj1-f195.google.com with SMTP id t9-v6so7945904ljh.6 for ; Sat, 15 Dec 2018 15:46:06 -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=AdOu5d31aFQ5LgQsJ6SO2qeANRtSbPy5gK/PxN19mo4=; b=Wwr8azjRTxR4AmfuF+AR9y5O+cet2FyJTsdongPuAzLD8th8MVgBl9IQ7hfl7ARaq3 rb6NO5TjMrhOopsLLs53TrlzUP/9nhr1FZkR3fFrJF3F5X7gzc4NiFMe9Skor12dfVtY Y5bAfF3vWIrQvFmq5IVw3/lOWHEwae695ln8I= 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=AdOu5d31aFQ5LgQsJ6SO2qeANRtSbPy5gK/PxN19mo4=; b=eBb84PEpBYzR1lJZ8WzmoZSKGV5mO2X06xaZs0UVONfIFKX31yCBObhvvfIY39hZpY oOJq1wDBPWW2jr/QEnQ9ue69v/DLiDZklDSO2+/wiHxfv4UJZtr/xmu+ieQ1SA4ARpPc zd0NsrDoafCYnk3GdD3fiSDkWm/bFZLtlXjpDs/he0gCJxkMooUIBEJgiIat/t4BAnZQ /GXzJqNBLi9keoLKh6u4dohjHpreKJwo+3goWpaVN4U2C6dpN7JIPjqBeT7qbRO9buxq +3lLpVXSBxfDJMww3zymCmI4J222/FF7YFvSlH1x9SmQLdQJsrpNLy8PJh9Bh2wWfurj XnZg== X-Gm-Message-State: AA+aEWa7rdUH9GFW+TO4KSQAruzFKdCxEKLSSW9kHqHitaeuyKJHRpkI 1rFgNEF0PNzY9vbI5bZnxA1nmw== X-Received: by 2002:a2e:3603:: with SMTP id d3-v6mr4513112lja.46.1544917565992; Sat, 15 Dec 2018 15:46:05 -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.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 15 Dec 2018 15:46:05 -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 , Wei Yongjun , Janek Kotas Subject: [PATCH 4/7 v1] spi: cadence: Convert to use CS GPIO descriptors Date: Sun, 16 Dec 2018 00:38:20 +0100 Message-Id: <20181215233823.1042-5-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-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This converts the Cadence SPI master driver to use GPIO descriptors for chip select handling. The Cadence driver was allocating a state container just to hold the requested GPIO line and contained lots of polarity inversion code. As this is all handled by gpiolib and a simple devm_* request in the core, and as the driver is fully device tree only, most of this code chunk goes away in favour of central handling. The setup/cleanup callbacks goes away. This driver does NOT drive the CS line by setting the value of the GPIO so it relies on the SPI core to do this, which should work just fine with the descriptors. Cc: Wei Yongjun Cc: Janek Kotas Cc: Linuxarm Signed-off-by: Linus Walleij --- drivers/spi/spi-cadence.c | 67 ++------------------------------------- 1 file changed, 2 insertions(+), 65 deletions(-) -- 2.19.2 diff --git a/drivers/spi/spi-cadence.c b/drivers/spi/spi-cadence.c index 7c88f74f7f47..e332d173dbf9 100644 --- a/drivers/spi/spi-cadence.c +++ b/drivers/spi/spi-cadence.c @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include #include @@ -128,10 +128,6 @@ struct cdns_spi { u32 is_decoded_cs; }; -struct cdns_spi_device_data { - bool gpio_requested; -}; - /* Macros for the SPI controller read/write */ static inline u32 cdns_spi_read(struct cdns_spi *xspi, u32 offset) { @@ -469,64 +465,6 @@ static int cdns_unprepare_transfer_hardware(struct spi_master *master) return 0; } -static int cdns_spi_setup(struct spi_device *spi) -{ - - int ret = -EINVAL; - struct cdns_spi_device_data *cdns_spi_data = spi_get_ctldata(spi); - - /* this is a pin managed by the controller, leave it alone */ - if (spi->cs_gpio == -ENOENT) - return 0; - - /* this seems to be the first time we're here */ - if (!cdns_spi_data) { - cdns_spi_data = kzalloc(sizeof(*cdns_spi_data), GFP_KERNEL); - if (!cdns_spi_data) - return -ENOMEM; - cdns_spi_data->gpio_requested = false; - spi_set_ctldata(spi, cdns_spi_data); - } - - /* if we haven't done so, grab the gpio */ - if (!cdns_spi_data->gpio_requested && gpio_is_valid(spi->cs_gpio)) { - ret = gpio_request_one(spi->cs_gpio, - (spi->mode & SPI_CS_HIGH) ? - GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH, - dev_name(&spi->dev)); - if (ret) - dev_err(&spi->dev, "can't request chipselect gpio %d\n", - spi->cs_gpio); - else - cdns_spi_data->gpio_requested = true; - } else { - if (gpio_is_valid(spi->cs_gpio)) { - int mode = ((spi->mode & SPI_CS_HIGH) ? - GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH); - - ret = gpio_direction_output(spi->cs_gpio, mode); - if (ret) - dev_err(&spi->dev, "chipselect gpio %d setup failed (%d)\n", - spi->cs_gpio, ret); - } - } - - return ret; -} - -static void cdns_spi_cleanup(struct spi_device *spi) -{ - struct cdns_spi_device_data *cdns_spi_data = spi_get_ctldata(spi); - - if (cdns_spi_data) { - if (cdns_spi_data->gpio_requested) - gpio_free(spi->cs_gpio); - kfree(cdns_spi_data); - spi_set_ctldata(spi, NULL); - } - -} - /** * cdns_spi_probe - Probe method for the SPI driver * @pdev: Pointer to the platform_device structure @@ -621,13 +559,12 @@ static int cdns_spi_probe(struct platform_device *pdev) goto clk_dis_all; } + master->use_gpio_descriptors = true; master->prepare_transfer_hardware = cdns_prepare_transfer_hardware; master->prepare_message = cdns_prepare_message; master->transfer_one = cdns_transfer_one; master->unprepare_transfer_hardware = cdns_unprepare_transfer_hardware; master->set_cs = cdns_spi_chipselect; - master->setup = cdns_spi_setup; - master->cleanup = cdns_spi_cleanup; master->auto_runtime_pm = true; master->mode_bits = SPI_CPOL | SPI_CPHA; From patchwork Sat Dec 15 23:38:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 153944 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp955905ljp; Sat, 15 Dec 2018 15:46:16 -0800 (PST) X-Google-Smtp-Source: AFSGD/UChKkmm+4YMLGc0/Ej9WR6Uwwhk737EqFiz6zYr4X3oWuUYy+SlO1NCO5V3Mbm9ybRryNv X-Received: by 2002:a63:1f4e:: with SMTP id q14mr7226924pgm.88.1544917576323; Sat, 15 Dec 2018 15:46:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544917576; cv=none; d=google.com; s=arc-20160816; b=VEvAXNKgXonHFSDX83S+Bm6SKIZgEd48NI4Lwf946TreO1nPj/GLXIumSe/TZqbvWm YS9mF7V2pyBOmb7PFpSgTRcdI/hO75G4/DIM6enhvfkn93+3uOu8Nm0lutP/6lkDtpKC +ft6bCM+mHEFozv75bmnjA66YMqilo7Z2OndVJrDAibQIpP3DHvOWfmbFPkSdJO+oy2q nRt3QDr6JVVzkVSs+nUM1dK2bsYZvXVVHgQcvqp4ElccZKQQqR8tG9VvsLUoUPFEaYVm 8fCO4n+DO+EvNvKgitLDvBUf+2bJEdH4WLk+cgQFRU2HwRl8+ty/Ej/2pb+Tpb50o9ux JcaQ== 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=kw40h7bKx7SEAJ/VmU1uQ3cysjIgsprCi6NOYoWS84k=; b=OBPi80OapwxGthXvP6IF2ySDBwkmm7cRi34CbqXvOFsSeck9jl8rgc81tUPlnGqJkk a3r0kvXOL7dNit1y8hjLr14HxHYahrKzZ8tkrtgFHD3GTL5doa+7Lov90hfsA3eDZsuL uImAoYZW3Iv7ky7v96jYgK8BbMV04mc89W1IR0Fl9lJRW2Yul6Clxy8pZg2lMbfOwM3L GyQClDAKCoPmiUXd7jsDkO0OrZLDTTXHt6hEQUWS/8mXBpDvnJihdkgPbqq6OATl8peL OEjrIipzdQ+3UOsy7Q8NV1BOpXD1qgqdgd5LBby3rqA6JkiTd0Qrr7wd7iiiu8Qo6Lyh UUpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=efy9fb6E; 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 1si7185999pld.239.2018.12.15.15.46.16; Sat, 15 Dec 2018 15:46:16 -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=efy9fb6E; 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 S1728718AbeLOXqP (ORCPT + 5 others); Sat, 15 Dec 2018 18:46:15 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:35282 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727256AbeLOXqP (ORCPT ); Sat, 15 Dec 2018 18:46:15 -0500 Received: by mail-lf1-f66.google.com with SMTP id e26so6902180lfc.2 for ; Sat, 15 Dec 2018 15:46:14 -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=kw40h7bKx7SEAJ/VmU1uQ3cysjIgsprCi6NOYoWS84k=; b=efy9fb6EfNUs97v7ULAo/Mt8Vd8d0xmvoypOXluCnyCw5iIgIPBnLBjVvEAZqyh0TB Ao4ZilXjAOtJyWoc7KcnTzwX7Rd4qItKsT9YuiSCCv5RTW7gRVEa85COdMj0HTu1N0t/ xzgH8rom9qexaanADQZ96C9IhhmktwrZBPkMU= 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=kw40h7bKx7SEAJ/VmU1uQ3cysjIgsprCi6NOYoWS84k=; b=BLFhie9/Fuwez5AT5IgalpRGQitORmJ+Eo+Jdse06rhmH6sUUhXfDGYPSnSb/BX0TR U/9fkrL4vizBYpXJ9Xhfh0j98imlA5AYf3S+mSiPQtFL0KHh7MBTdiuBNqhZfzkmggq6 64xaccYjuxNC5DIfc/+eXqztQfc4ABtUeoMTXlykwNJIZb7bnxubWWZyXIOO+UXO+ac2 pgzbYEknv3qHDPSmfm7kCZ4/EhYazBNrbs++eyWVtyPzQhAjIjfO2ZgOy9jTgU0CmEcM cGS/DVC7UWWbhFBu7wgKDTglXiBtkgvlNQEZhjt59M9kNDB6ZyQAnXpJtB0nGfT5Y9q2 8RwQ== X-Gm-Message-State: AA+aEWbU6pHDdLeSN70aYgw18zjR7HyEpVWS7FCvgq9BJKgS3aFR40gT vjdxeWw9HcrWTm0xnNeUVH9kpA== X-Received: by 2002:a19:3b45:: with SMTP id i66mr4792542lfa.28.1544917573595; Sat, 15 Dec 2018 15:46:13 -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.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 15 Dec 2018 15:46:12 -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 , Talel Shenhar , Simon Goldschmidt , Alexandre Belloni Subject: [PATCH 7/7 v1] spi: dw: Convert to use CS GPIO descriptors Date: Sun, 16 Dec 2018 00:38:23 +0100 Message-Id: <20181215233823.1042-8-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-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This converts the DesignWare (dw) SPI master driver to use GPIO descriptors for chip select handling. This driver has a duplicate DT parser in addition to the one in the core, sets up the line as non-asserted and relies on the core to drive the GPIOs. It is a pretty straight-forward conversion. Cc: Talel Shenhar Cc: Simon Goldschmidt Cc: Alexandre Belloni Cc: Linuxarm Signed-off-by: Linus Walleij --- drivers/spi/spi-dw-mmio.c | 22 ---------------------- drivers/spi/spi-dw.c | 9 +-------- 2 files changed, 1 insertion(+), 30 deletions(-) -- 2.19.2 diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c index 3ffb6a40fe0c..00a43c19f2a4 100644 --- a/drivers/spi/spi-dw-mmio.c +++ b/drivers/spi/spi-dw-mmio.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -184,27 +183,6 @@ static int dw_spi_mmio_probe(struct platform_device *pdev) dws->num_cs = num_cs; - if (pdev->dev.of_node) { - int i; - - for (i = 0; i < dws->num_cs; i++) { - int cs_gpio = of_get_named_gpio(pdev->dev.of_node, - "cs-gpios", i); - - if (cs_gpio == -EPROBE_DEFER) { - ret = cs_gpio; - goto out; - } - - if (gpio_is_valid(cs_gpio)) { - ret = devm_gpio_request(&pdev->dev, cs_gpio, - dev_name(&pdev->dev)); - if (ret) - goto out; - } - } - } - init_func = device_get_match_data(&pdev->dev); if (init_func) { ret = init_func(pdev, dwsmmio); diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c index b705f2bdb8b9..22a7998dbc08 100644 --- a/drivers/spi/spi-dw.c +++ b/drivers/spi/spi-dw.c @@ -20,7 +20,6 @@ #include #include #include -#include #include "spi-dw.h" @@ -425,13 +424,6 @@ static int dw_spi_setup(struct spi_device *spi) chip->tmode = SPI_TMOD_TR; - if (gpio_is_valid(spi->cs_gpio)) { - ret = gpio_direction_output(spi->cs_gpio, - !(spi->mode & SPI_CS_HIGH)); - if (ret) - return ret; - } - return 0; } @@ -496,6 +488,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws) goto err_free_master; } + master->use_gpio_descriptors = true; master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP; master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16); master->bus_num = dws->bus_num;