Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1365100imm; Tue, 2 Oct 2018 07:08:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV60UhCFa69+Se4NO91gdVo3/UiGYF9OzqCWxno6peErc5ewOjaIh2GGqpcIaAaY59Sw/nTjO X-Received: by 2002:a62:cc4:: with SMTP id 65-v6mr16646926pfm.127.1538489329776; Tue, 02 Oct 2018 07:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538489329; cv=none; d=google.com; s=arc-20160816; b=VoBdH2VFQqE1G5ZlpAeBfK5C/AutDyr0LnvMVQhnx0Y9pKdzOmUQTNke/h/81uiGz6 3jVAj36eIXa4HMUjHY0F94juW4d/+WLiL+7ooICiLxRbvc+B+daDbSKPIUcUj72p1qkn oRVtEu+2XA0mori1WuL3v//5XZ5+ouZEveLg9i7Ouo2xvgtbYycFoNSw15nNDKKGq2ZV W452r+GC//znktm40CmKWh5nglgN0XJXeGoO/lTcJ0fKYszEvhpaYyvDVjspCFJOc/Cm Yxl5v21kiFiRCRohyS1e3XKgLIOm5SAgynRgL5qSAU5+KxaRdSlwYjPJFqA4DqutkHCk 7j2A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=RArlAInfYm85PnPAzU3X45SXFsedX/L4GmDze2EOQXg=; b=T/b9FYEafWhT6C/IZd07zFN2s5jfZSObHkyEJp724QV727yxcpV6A/KGv3XQI2TURC fcQYofPF7Dlf0WlZKeA6L8G1v3xxLvZWz7IM29dvMSMjIeXPRduiGxOIoev4jFlSh3kW APlXNnNnKxXuGTLpomWFb4b9uJKhhpRXYmvaSudhXKOdsDzTHaqXexYUAMWV6OskctF6 tTWtilgxsbG1BNnaxj4AbWhr28ufrWjI0yxK+hrHIdBrY3sSsCnZPQiJIYxl6r8VZgwZ BNviCn2j3en+iHT9oRv6jJq/cXxPHosyaRO/uG7fXZAIMglsJiruj20PedwWFUzSJ2Tg VNag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g14-v6si16995207pfd.86.2018.10.02.07.08.34; Tue, 02 Oct 2018 07:08:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729323AbeJBULr (ORCPT + 99 others); Tue, 2 Oct 2018 16:11:47 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60948 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729280AbeJBULq (ORCPT ); Tue, 2 Oct 2018 16:11:46 -0400 Received: from localhost (24-104-73-23-ip-static.hfc.comcastbusiness.net [24.104.73.23]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 624D3266; Tue, 2 Oct 2018 13:28:24 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Jan=20Kundr=C3=A1t?= , Mark Brown , Sasha Levin Subject: [PATCH 4.18 108/228] spi: orion: fix CS GPIO handling again Date: Tue, 2 Oct 2018 06:23:25 -0700 Message-Id: <20181002132506.699823053@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181002132459.032960735@linuxfoundation.org> References: <20181002132459.032960735@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jan Kundrát [ Upstream commit fb9acf5f1f21f1de193523ff780bda375b4c2e21 ] The code did not de-assert any CS GPIOs before probing slaves. This means that several CS signals could be active at once, garbling the communication. Whether this was actually a problem depended on the type of the SPI device attached (so my "spidev" for userspace access worked correctly because its probe was effectively a no-op), and on the state of the GPIO pins at SoC's boot. The code was already iterating through all DT children of the SPI controller, so this change re-uses that loop for CS GPIO setup as well. This means that this might change the number of the HW CS signal which is picked for all GPIO CS devices. Previously, the lowest one was used, but we now use the first one from the DT. With this move of the code, we can also finally initialize each GPIO CS lane before registering the SPI controller (which in turn probes for slaves). I tried to fix this in 544248623b95 already, but that only did it half way by registering the GPIOs properly. That patch failed to set their logic signals early enough, though. Signed-off-by: Jan Kundrát Signed-off-by: Mark Brown Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-orion.c | 77 ++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 37 deletions(-) --- a/drivers/spi/spi-orion.c +++ b/drivers/spi/spi-orion.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -681,9 +682,9 @@ static int orion_spi_probe(struct platfo goto out_rel_axi_clk; } - /* Scan all SPI devices of this controller for direct mapped devices */ for_each_available_child_of_node(pdev->dev.of_node, np) { u32 cs; + int cs_gpio; /* Get chip-select number from the "reg" property */ status = of_property_read_u32(np, "reg", &cs); @@ -695,6 +696,44 @@ static int orion_spi_probe(struct platfo } /* + * Initialize the CS GPIO: + * - properly request the actual GPIO signal + * - de-assert the logical signal so that all GPIO CS lines + * are inactive when probing for slaves + * - find an unused physical CS which will be driven for any + * slave which uses a CS GPIO + */ + cs_gpio = of_get_named_gpio(pdev->dev.of_node, "cs-gpios", cs); + if (cs_gpio > 0) { + char *gpio_name; + int cs_flags; + + if (spi->unused_hw_gpio == -1) { + dev_info(&pdev->dev, + "Selected unused HW CS#%d for any GPIO CSes\n", + cs); + spi->unused_hw_gpio = cs; + } + + gpio_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, + "%s-CS%d", dev_name(&pdev->dev), cs); + if (!gpio_name) { + status = -ENOMEM; + goto out_rel_axi_clk; + } + + cs_flags = of_property_read_bool(np, "spi-cs-high") ? + GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH; + status = devm_gpio_request_one(&pdev->dev, cs_gpio, + cs_flags, gpio_name); + if (status) { + dev_err(&pdev->dev, + "Can't request GPIO for CS %d\n", cs); + goto out_rel_axi_clk; + } + } + + /* * Check if an address is configured for this SPI device. If * not, the MBus mapping via the 'ranges' property in the 'soc' * node is not configured and this device should not use the @@ -740,44 +779,8 @@ static int orion_spi_probe(struct platfo if (status < 0) goto out_rel_pm; - if (master->cs_gpios) { - int i; - for (i = 0; i < master->num_chipselect; ++i) { - char *gpio_name; - - if (!gpio_is_valid(master->cs_gpios[i])) { - continue; - } - - gpio_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, - "%s-CS%d", dev_name(&pdev->dev), i); - if (!gpio_name) { - status = -ENOMEM; - goto out_rel_master; - } - - status = devm_gpio_request(&pdev->dev, - master->cs_gpios[i], gpio_name); - if (status) { - dev_err(&pdev->dev, - "Can't request GPIO for CS %d\n", - master->cs_gpios[i]); - goto out_rel_master; - } - if (spi->unused_hw_gpio == -1) { - dev_info(&pdev->dev, - "Selected unused HW CS#%d for any GPIO CSes\n", - i); - spi->unused_hw_gpio = i; - } - } - } - - return status; -out_rel_master: - spi_unregister_master(master); out_rel_pm: pm_runtime_disable(&pdev->dev); out_rel_axi_clk: