From patchwork Mon Jan 7 15:51:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 154890 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3630400ljp; Mon, 7 Jan 2019 07:56:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN6CC5XGw3g2seuXRnQd8z9CuIC+LU6nLM9fSdPmlygAPzlPKUAOblm1tw5DRn7PjkWjXwLg X-Received: by 2002:a63:4b60:: with SMTP id k32mr11323383pgl.186.1546876601704; Mon, 07 Jan 2019 07:56:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546876601; cv=none; d=google.com; s=arc-20160816; b=iLnB0j1AQA1VJ6k7yZfjtPvLdV1x62RM2x5VsDtpmfRdZiK5uHVOhVYUjXsBVBKn7X QAqfuLVbCrLuocXb6xuzKlsLdpet42Y4n+2ppMgk5h7dboNQ99Ptrv7y1MnXWtqvToZG dlrxlhsJd/5oUItctrIN1Z6h6dTDorsBGLo490OmZcRU0VV6KpyCakbme4esbkZt3RJM hQlsrM5Y2Rw1aMz1d0HLY4L5lD8mSh24pMVLwcaMiYN6U71sLxqSWg6XM8A2zpeYzlfw 6wz9veVFog3C7Y7an+CfQyq9VWcSnZtPl2ptjSAIuJRfAkn5vg9PkYsb10f03bDWoMVg hrZg== 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=ra+zLtqtNCVMe3JGWM08Eu1AX9L0cpRs8XQnZXyXhCc=; b=voHHWaFX3eXIorecW4Smw800e81PZ6AZDrTp4QAYpjFe7kSwPFiMLmnmjbrXe8n6LO zDSWYueUa8UedX2y2/6Pu1ZzeZnjgLXFHuMqarPAdC9C8suPGkP0gzoQsTJnoZGVQ0JR AMe9RbfAFI6W3aQBH4PISsGMQbdrg5tIl7Bua6y6EAHwS1c6DBEr2U01Kyr17MGRG/uK m8O42DVhoBnmssQ9feYP2COfl0Y8NPPsI9dVdRRFIQI0Rbl9RnJDo78s58ElWo/Khaa8 3r8tra/mmQqb/GYHIWA6il2Eb1rN8D84daP/zUgeLk2dIizFMCpuvGv/uACXNEELTaBn nekw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="N/t1dhVw"; 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 l7si3021110pgk.169.2019.01.07.07.56.41; Mon, 07 Jan 2019 07:56:41 -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="N/t1dhVw"; 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 S1726986AbfAGP4l (ORCPT + 1 other); Mon, 7 Jan 2019 10:56:41 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:36680 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726668AbfAGP4k (ORCPT ); Mon, 7 Jan 2019 10:56:40 -0500 Received: by mail-lj1-f195.google.com with SMTP id g11-v6so764996ljk.3 for ; Mon, 07 Jan 2019 07:56:38 -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=ra+zLtqtNCVMe3JGWM08Eu1AX9L0cpRs8XQnZXyXhCc=; b=N/t1dhVw7Sr02CG+WTYkYYGbG4UJ8O8XWjBokNJ+t+8rJEr1lwfONA3fBDn0VDrtys DUdkDuvux/0yyeUk5wsesPUrSRj/b0fyaM6vrJV5Y6HvW6QOI6LK36luSqiPAfBI2JC+ n6ULOwSU+ScseMbNX6cg8SVM+09ssNskz4oKA= 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=ra+zLtqtNCVMe3JGWM08Eu1AX9L0cpRs8XQnZXyXhCc=; b=ZO7mEeQoqpJT7UEq9fFOmHWp302oIfEnbWNdhgo/+S2zks7e6C6HVmJyoMr/rjm0yo PvxouYEvCHN/030Kbp36VSq1r1d2GQN+iKfQE1IRRAIoeEOY1HhEJCrZcECp7KbZZ7NK 7Eqo+dqOos7R/uHdPGDB9XKtPBmjazc1mmfSmTEeanIoWa0ItCHVijeSrhGz2eB0KEjy G/6woJrcnG2pP3+fzEoEcCDlXgXXpGjSY7eovha5H9KrEkF5wiNgMzvNceF7rxPBlR7U CoGHRWlTzH5QccMoalfaLWHZAKhRhucG2XvvYKtPczRREc0E5WlXwmEzPiltk9VKl+Ng 52Ug== X-Gm-Message-State: AA+aEWYsGIc8uPHDDgL/XsTHPufZVijhA/KxGvDKO78/wpD2WpnY4mf2 GMoZor4ouB0BcyuxxLI9g5ko2A== X-Received: by 2002:a2e:974a:: with SMTP id f10-v6mr38524207ljj.61.1546876597481; Mon, 07 Jan 2019 07:56:37 -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.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Jan 2019 07:56:36 -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 Subject: [PATCH 1/7 v2] spi: Optionally use GPIO descriptors for CS GPIOs Date: Mon, 7 Jan 2019 16:51:50 +0100 Message-Id: <20190107155156.3738-2-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 augments the SPI core to optionally use GPIO descriptors for chip select on a per-master-driver opt-in basis. Drivers using this will rely on the SPI core to look up GPIO descriptors associated with the device, such as when using device tree or board files with GPIO descriptor tables. When getting descriptors from the device tree, this will in turn activate the code in gpiolib that was added in commit 6953c57ab172 ("gpio: of: Handle SPI chipselect legacy bindings") which means that these descriptors are aware of the active low semantics that is the default for SPI CS GPIO lines and we can assume that all of these are "active high" and thus assign SPI_CS_HIGH to all CS lines on the DT path. The previously used gpio_set_value() would call down into gpiod_set_raw_value() and ignore the polarity inversion semantics. It seems like many drivers go to great lengths to set up the CS GPIO line as non-asserted, respecting SPI_CS_HIGH. We pull this out of the SPI drivers and into the core, and by simply requesting the line as GPIOD_OUT_LOW when retrieveing it from the device and relying on the gpiolib to handle any inversion semantics. This way a lot of code can be simplified and removed in each converted driver. The end goal after dealing with each driver in turn, is to delete the non-descriptor path (of_spi_register_master() for example) and let the core deal with only descriptors. The different SPI drivers have complex interactions with the core so we cannot simply change them all over, we need to use a stepwise, bisectable approach so that each driver can be converted and fixed in isolation. This patch has the intended side effect of adding support for ACPI GPIOs as it starts relying on gpiod_get_*() to get the GPIO handle associated with the device. Cc: Linuxarm Acked-by: Jonathan Cameron Tested-by: Fangjian (Turing) Signed-off-by: Linus Walleij --- ChangeLog v1-v2: - Do not initialize gpiod to NULL - Record Jonathans ACK - Record Fangjian's Tested-by - Rebase on v5.0-rc1 --- drivers/spi/spi.c | 104 ++++++++++++++++++++++++++++++++++++---- include/linux/spi/spi.h | 23 +++++++-- 2 files changed, 113 insertions(+), 14 deletions(-) -- 2.19.2 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 9a7def7c3237..13f447a67d67 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -578,7 +579,10 @@ int spi_add_device(struct spi_device *spi) goto done; } - if (ctlr->cs_gpios) + /* Descriptors take precedence */ + if (ctlr->cs_gpiods) + spi->cs_gpiod = ctlr->cs_gpiods[spi->chip_select]; + else if (ctlr->cs_gpios) spi->cs_gpio = ctlr->cs_gpios[spi->chip_select]; /* Drivers may modify this initial i/o setup, but will @@ -772,10 +776,20 @@ static void spi_set_cs(struct spi_device *spi, bool enable) if (spi->mode & SPI_CS_HIGH) enable = !enable; - if (gpio_is_valid(spi->cs_gpio)) { - /* Honour the SPI_NO_CS flag */ - if (!(spi->mode & SPI_NO_CS)) - gpio_set_value(spi->cs_gpio, !enable); + if (spi->cs_gpiod || gpio_is_valid(spi->cs_gpio)) { + /* + * Honour the SPI_NO_CS flag and invert the enable line, as + * active low is default for SPI. Execution paths that handle + * polarity inversion in gpiolib (such as device tree) will + * enforce active high using the SPI_CS_HIGH resulting in a + * double inversion through the code above. + */ + if (!(spi->mode & SPI_NO_CS)) { + if (spi->cs_gpiod) + gpiod_set_value(spi->cs_gpiod, !enable); + else + gpio_set_value(spi->cs_gpio, !enable); + } /* Some SPI masters need both GPIO CS & slave_select */ if ((spi->controller->flags & SPI_MASTER_GPIO_SS) && spi->controller->set_cs) @@ -1615,13 +1629,21 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, spi->mode |= SPI_CPHA; if (of_property_read_bool(nc, "spi-cpol")) spi->mode |= SPI_CPOL; - if (of_property_read_bool(nc, "spi-cs-high")) - spi->mode |= SPI_CS_HIGH; if (of_property_read_bool(nc, "spi-3wire")) spi->mode |= SPI_3WIRE; if (of_property_read_bool(nc, "spi-lsb-first")) spi->mode |= SPI_LSB_FIRST; + /* + * For descriptors associated with the device, polarity inversion is + * handled in the gpiolib, so all chip selects are "active high" in + * the logical sense, the gpiolib will invert the line if need be. + */ + if (ctlr->use_gpio_descriptors) + spi->mode |= SPI_CS_HIGH; + else if (of_property_read_bool(nc, "spi-cs-high")) + spi->mode |= SPI_CS_HIGH; + /* Device DUAL/QUAD mode */ if (!of_property_read_u32(nc, "spi-tx-bus-width", &value)) { switch (value) { @@ -2137,6 +2159,60 @@ static int of_spi_register_master(struct spi_controller *ctlr) } #endif +/** + * spi_get_gpio_descs() - grab chip select GPIOs for the master + * @ctlr: The SPI master to grab GPIO descriptors for + */ +static int spi_get_gpio_descs(struct spi_controller *ctlr) +{ + int nb, i; + struct gpio_desc **cs; + struct device *dev = &ctlr->dev; + + nb = gpiod_count(dev, "cs"); + ctlr->num_chipselect = max_t(int, nb, ctlr->num_chipselect); + + /* No GPIOs at all is fine, else return the error */ + if (nb == 0 || nb == -ENOENT) + return 0; + else if (nb < 0) + return nb; + + cs = devm_kcalloc(dev, ctlr->num_chipselect, sizeof(*cs), + GFP_KERNEL); + if (!cs) + return -ENOMEM; + ctlr->cs_gpiods = cs; + + for (i = 0; i < nb; i++) { + /* + * Most chipselects are active low, the inverted + * semantics are handled by special quirks in gpiolib, + * so initializing them GPIOD_OUT_LOW here means + * "unasserted", in most cases this will drive the physical + * line high. + */ + cs[i] = devm_gpiod_get_index_optional(dev, "cs", i, + GPIOD_OUT_LOW); + + if (cs[i]) { + /* + * If we find a CS GPIO, name it after the device and + * chip select line. + */ + char *gpioname; + + gpioname = devm_kasprintf(dev, GFP_KERNEL, "%s CS%d", + dev_name(dev), i); + if (!gpioname) + return -ENOMEM; + gpiod_set_consumer_name(cs[i], gpioname); + } + } + + return 0; +} + static int spi_controller_check_ops(struct spi_controller *ctlr) { /* @@ -2199,9 +2275,16 @@ int spi_register_controller(struct spi_controller *ctlr) return status; if (!spi_controller_is_slave(ctlr)) { - status = of_spi_register_master(ctlr); - if (status) - return status; + if (ctlr->use_gpio_descriptors) { + status = spi_get_gpio_descs(ctlr); + if (status) + return status; + } else { + /* Legacy code path for GPIOs from DT */ + status = of_spi_register_master(ctlr); + if (status) + return status; + } } /* even if it's just one always-selected device, there must @@ -2915,6 +2998,7 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) * cs_change is set for each transfer. */ if ((spi->mode & SPI_CS_WORD) && (!(ctlr->mode_bits & SPI_CS_WORD) || + spi->cs_gpiod || gpio_is_valid(spi->cs_gpio))) { size_t maxsize; int ret; diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 314d922ca607..916bba47d156 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -12,6 +12,7 @@ #include #include #include +#include struct dma_chan; struct property_entry; @@ -116,7 +117,10 @@ void spi_statistics_add_transfer_stats(struct spi_statistics *stats, * @modalias: Name of the driver to use with this device, or an alias * for that name. This appears in the sysfs "modalias" attribute * for driver coldplugging, and in uevents used for hotplugging - * @cs_gpio: gpio number of the chipselect line (optional, -ENOENT when + * @cs_gpio: LEGACY: gpio number of the chipselect line (optional, -ENOENT when + * not using a GPIO line) use cs_gpiod in new drivers by opting in on + * the spi_master. + * @cs_gpiod: gpio descriptor of the chipselect line (optional, NULL when * not using a GPIO line) * * @statistics: statistics for the spi_device @@ -163,7 +167,8 @@ struct spi_device { void *controller_data; char modalias[SPI_NAME_SIZE]; const char *driver_override; - int cs_gpio; /* chip select gpio */ + int cs_gpio; /* LEGACY: chip select gpio */ + struct gpio_desc *cs_gpiod; /* chip select gpio desc */ /* the statistics */ struct spi_statistics statistics; @@ -376,9 +381,17 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) * controller has native support for memory like operations. * @unprepare_message: undo any work done by prepare_message(). * @slave_abort: abort the ongoing transfer request on an SPI slave controller - * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS - * number. Any individual value may be -ENOENT for CS lines that + * @cs_gpios: LEGACY: array of GPIO descs to use as chip select lines; one per + * CS number. Any individual value may be -ENOENT for CS lines that + * are not GPIOs (driven by the SPI controller itself). Use the cs_gpiods + * in new drivers. + * @cs_gpiods: Array of GPIO descs to use as chip select lines; one per CS + * number. Any individual value may be NULL for CS lines that * are not GPIOs (driven by the SPI controller itself). + * @use_gpio_descriptors: Turns on the code in the SPI core to parse and grab + * GPIO descriptors rather than using global GPIO numbers grabbed by the + * driver. This will fill in @cs_gpiods and @cs_gpios should not be used, + * and SPI devices will have the cs_gpiod assigned rather than cs_gpio. * @statistics: statistics for the spi_controller * @dma_tx: DMA transmit channel * @dma_rx: DMA receive channel @@ -557,6 +570,8 @@ struct spi_controller { /* gpio chip select */ int *cs_gpios; + struct gpio_desc **cs_gpiods; + bool use_gpio_descriptors; /* statistics */ struct spi_statistics statistics; From patchwork Mon Jan 7 15:51:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 154894 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3630534ljp; Mon, 7 Jan 2019 07:56:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/WETt7EVDRhDNgahkCmnN0rCeu09T3LBSLoSs89K7a9lAl5VulaGzSLSGi+Kl12otBzsNML X-Received: by 2002:a62:4549:: with SMTP id s70mr62871407pfa.233.1546876610758; Mon, 07 Jan 2019 07:56:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546876610; cv=none; d=google.com; s=arc-20160816; b=P9XICdQeE6okOW10ywa5AAtzmwl/zf22E4Tut332GqTAvDEQxW44M1eKp/FQL4JMmu aRbsvheaKZVZgADkGqohkOBPJSi1L3WY5bvkasYPtOCshcbog4LyzP+0SKLHL2+PSuWL 3fcwyHLGBn4ZKncfTAAJemHcodSojAIjkJnCQod4eQkGX0zucSQ6uYcIkLpYrVH0w7gM LsSYhJV5tESBv5o/cey7TwfjHTocMitoINBwVv2kzL1p6GM6mGNFwiu7dFd8SO0Hf2Xq zgscJV6ag+ftPprbDi227F2Mag04OYtwlqkY4KC8loYvqv4O7TuAcUXbAkVVDqzHwT7r 7gzQ== 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=U/f3ju9GAcQU2D9t1vnukcnrS930aDOZrrMHtBThSv0=; b=S948JNE8s4UV3EllaUL4qU/tT7Tmi+jHqovO/WXr4UbHS6CgMuIp/isiSMcC4BDTfY C7pDT0ORS7JPJfYDOh5xW8jy0cwodUKuyhKTNIj6B0bZRQeIa7R7+kanD/qM5BFYANBm oPiXJshtI/7PK4y+wT12zoYf1A6uafPYOmiyjFzU/ZfMWxmfV1qxrzEGNxkBTabFS+xA M418xlLdhO3UDFF2QAGZvb8ESVZAGb/PkxrQR96UtMbERkFwJSLTwlIcFhmvvmjs49y5 mbk6tML4bXJKoKIVQT14NHpVQZ/kHmKib41TTJz9t79H+HL/gasMPIlGFWPZ0siXanu8 IbjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UM1SFyu6; 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 l7si3021110pgk.169.2019.01.07.07.56.50; Mon, 07 Jan 2019 07:56:50 -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=UM1SFyu6; 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 S1727373AbfAGP4u (ORCPT + 1 other); Mon, 7 Jan 2019 10:56:50 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:43310 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727788AbfAGP4u (ORCPT ); Mon, 7 Jan 2019 10:56:50 -0500 Received: by mail-lj1-f194.google.com with SMTP id q2-v6so729767lji.10 for ; Mon, 07 Jan 2019 07:56:48 -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=U/f3ju9GAcQU2D9t1vnukcnrS930aDOZrrMHtBThSv0=; b=UM1SFyu6VOe2ezjzpBKx2/3g5foqiuj7bAQfTVVs0kJrk4kxE8ncStmKououjitABI WRFxaPdPwpboTTWpkTwzKlZYzOyK2UyHXWuPD9S1pZo21S+zFN0W6hsBqimIxxHVlq5a ZGK2a97sSe5eEurZhIJVfN1qSTWeZw0idYB14= 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=U/f3ju9GAcQU2D9t1vnukcnrS930aDOZrrMHtBThSv0=; b=jLbe/jHict7SfAAGZXi/24PCZ+SoTNs/e6NM1qps2rE7d8g/Uj+cLxcXSMOaek3LAs w0irPlOsbenvhRvKYAbXFvZy1VMMmvjtxh7pLAD+5nAck694p45NUmVIYuLcsFvuZAVv 6ShG63V5CcBo43QeQjZX1wxF0/UtMyk6N9PygeTEJ4nSZf8txFLQkqzq0BlTvxmkzNUn TqnTgPQCfCVt6f4WSPAtJHe3auqeEasgzUcqEq0RrOM7GqqUnp/4ywXJr0c0JTaqUgN7 qdkTPRzEHYOy6E3XPZHm6eKQ0d5b+KnYWp8yxee7OPrrriccRcBgdZHRbbS3SA4XRmw8 cNAQ== X-Gm-Message-State: AJcUukdlibePEb26zg79fGiiPLkjJQ154eXLE/T1uEJyfFf27ouUeLE1 9HPgPbyuMjswHLxmGeuVxY7EZA== X-Received: by 2002:a2e:2d11:: with SMTP id t17-v6mr33714989ljt.159.1546876608141; Mon, 07 Jan 2019 07:56:48 -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.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Jan 2019 07:56:47 -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 , Alexander Shiyan Subject: [PATCH 5/7 v2] spi: clps711x: Convert to use CS GPIO descriptors Date: Mon, 7 Jan 2019 16:51:54 +0100 Message-Id: <20190107155156.3738-6-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 CLPS711x SPI master driver to use GPIO descriptors for chip select handling. The CLPS711x driver was merely requesting the GPIO and setting the CS line non-asserted so this was a pretty straight-forward conversion. The setup callback goes away. Cc: Alexander Shiyan Cc: Linuxarm Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebase on v5.0-rc1 --- drivers/spi/spi-clps711x.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) -- 2.19.2 diff --git a/drivers/spi/spi-clps711x.c b/drivers/spi/spi-clps711x.c index 18193df2eba8..8c03c409fc07 100644 --- a/drivers/spi/spi-clps711x.c +++ b/drivers/spi/spi-clps711x.c @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include @@ -36,25 +36,6 @@ struct spi_clps711x_data { int len; }; -static int spi_clps711x_setup(struct spi_device *spi) -{ - if (!spi->controller_state) { - int ret; - - ret = devm_gpio_request(&spi->master->dev, spi->cs_gpio, - dev_name(&spi->master->dev)); - if (ret) - return ret; - - spi->controller_state = spi; - } - - /* We are expect that SPI-device is not selected */ - gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); - - return 0; -} - static int spi_clps711x_prepare_message(struct spi_master *master, struct spi_message *msg) { @@ -125,11 +106,11 @@ static int spi_clps711x_probe(struct platform_device *pdev) if (!master) return -ENOMEM; + master->use_gpio_descriptors = true; master->bus_num = -1; master->mode_bits = SPI_CPHA | SPI_CS_HIGH; master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 8); master->dev.of_node = pdev->dev.of_node; - master->setup = spi_clps711x_setup; master->prepare_message = spi_clps711x_prepare_message; master->transfer_one = spi_clps711x_transfer_one; 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); From patchwork Mon Jan 7 15:51:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 154896 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3630613ljp; Mon, 7 Jan 2019 07:56:57 -0800 (PST) X-Google-Smtp-Source: ALg8bN6IcxPdF3qA6A+b9tFtwrrYwlHXE6nvRwJFPDW+87IBzeJfdJfEEstnCVOcTAuc9vFzdmvz X-Received: by 2002:a17:902:680f:: with SMTP id h15mr60816996plk.40.1546876617002; Mon, 07 Jan 2019 07:56:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546876616; cv=none; d=google.com; s=arc-20160816; b=ZGvXkMxHo0TnaThKo7nsjMbC9HUGDuWQnWrr5lPxoXwgmwTOK8SjtwV0aXfTGRVr7n CwI1F6lxASPCg9x9KJnKJJw+ePUCYyViESypyfuckr8Y9YB6Ci0WfwRaicsNdEPjA45X Ak7T4j3xGnY6keVMYTqq7IlMET3ugKDKEXCklCNSX/p9R/Bbp8fk/INOrXK9mioUKY4e AQavi8eQgyQwF4ch4Agsib23h3WTKCo5MES1bR1RYXeQI4Ro+DIBcM0M+dot5VkvqDOn CMdHLg5aBNRDIYQkliudhdoOOrCiuthBFZz84pKIpx5KzzCLgZEBywGOEKh1gWOhdo3a egSw== 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=dbTeetkKkenvzLrTieSfQxTaPQNcOHrf+mj+vmNzfaU=; b=cS9M/6xh8VZbW70xmSlHq1hC90c1Y8X/kr2DcgEij7qhEJaqoU5HnmCnDILLPRLI86 ShDfi9Wg3hK35vHFfvS4uSk7FKxa18VfWNHGMXrlFeMlZp/FKqZvYYzJtidEES3AQDTM OngRtcewz6jxy4PWt4Gw93+/flde3lRMnCJwqXS9QAm+XHs5rbfN/j7g6S0E9oE4BLb4 +Gxu8A57ZWoww/fi+bb40ItI0wHQPV7AJIt7wvgNR1tYWM6tLC3tKg1AU0GTu0QYZbM/ Okdi/fzJ6Z3fgtA/p/5pfPIFvQZul0XvIONCneeQEQoYMgjfY0/UXRc/C6U89dFDjS2a l+iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N1uNOoa2; 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 w11si43262427pgf.452.2019.01.07.07.56.56; Mon, 07 Jan 2019 07:56:56 -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=N1uNOoa2; 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 S1726903AbfAGP44 (ORCPT + 1 other); Mon, 7 Jan 2019 10:56:56 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:36994 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727469AbfAGP4z (ORCPT ); Mon, 7 Jan 2019 10:56:55 -0500 Received: by mail-lj1-f193.google.com with SMTP id t18-v6so763149ljd.4 for ; Mon, 07 Jan 2019 07:56:54 -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=dbTeetkKkenvzLrTieSfQxTaPQNcOHrf+mj+vmNzfaU=; b=N1uNOoa2AW/HAtLpjdEHtAPnCKtpXGgl50xhmpPWdozAwrnCWaLYMiGmyhzHvpSrHd JhzUfQLp/+SaevIh9SeHkRsSKJgX3CzSFg9huOoIAXut51wUwkapQVundnsqwA2G+RIV T6o9YLTUQ/jS8DhR0k25D68sFBZlUqqJ1e9CU= 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=dbTeetkKkenvzLrTieSfQxTaPQNcOHrf+mj+vmNzfaU=; b=Eo500J9HGpfs3n5lTllbyso9lcqVZLExpSP80XyDbqeVjivaFkyui14Sx/NFQKOooz Pz4+nypXLivv9U26zv/7IFSx6xcR9hTxDmRFn1FLm76hBH2CFvtUVZ0RfUbvhQK7ivRy Uhfskmq920b+ldF33mFAyaHk1mTYgQzgWabejdA1SwdK6Ipvl1bhFXZmsM913n/8Yfs4 u7wa/46zKFRp8XLFhhe4Yzz1zDufy3zScKzUdIME0l6AN3cs3tEbek4ZvCCeWIvqKQLu l3SzEQ/+zDOvfPNNjpal+91tgsPwU3WIin1w2A3sCDRp8H3/bRHAwnrCR4e3YKtqTpqH w+Hw== X-Gm-Message-State: AJcUukfqo8dZzUO7aqI1KhzSXggclVpd/oAI7LrL7ULr5oRRxtyJiXM1 b1QrbHXDYWFzKi8p4eIdya5Cpw== X-Received: by 2002:a2e:484:: with SMTP id a4-v6mr34176665ljf.27.1546876613517; Mon, 07 Jan 2019 07:56:53 -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.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Jan 2019 07:56:52 -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 v2] spi: dw: Convert to use CS GPIO descriptors Date: Mon, 7 Jan 2019 16:51:56 +0100 Message-Id: <20190107155156.3738-8-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 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 Tested-by: Jay Fang Reviewed-by: Alexandre Belloni Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebase on v5.0-rc1 --- 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 d0dd7814e997..4bd59a93d988 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 @@ -185,27 +184,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 2e822a56576a..531f6ce5900d 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;