From patchwork Fri Jan 26 22:56:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Kundr=C3=A1t?= X-Patchwork-Id: 10187175 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E4A8C60211 for ; Fri, 26 Jan 2018 23:03:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D777B29B88 for ; Fri, 26 Jan 2018 23:03:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBA1C2A820; Fri, 26 Jan 2018 23:03:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C97D129B88 for ; Fri, 26 Jan 2018 23:03:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751465AbeAZXDE (ORCPT ); Fri, 26 Jan 2018 18:03:04 -0500 Received: from office2.cesnet.cz ([195.113.144.244]:44178 "EHLO office2.cesnet.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751431AbeAZXDD (ORCPT ); Fri, 26 Jan 2018 18:03:03 -0500 Received: from localhost (unknown [IPv6:2001:718:1:2c:4c87:d4a8:de7f:541e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by office2.cesnet.cz (Postfix) with ESMTPSA id 39FAB400064; Sat, 27 Jan 2018 00:03:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cesnet.cz; s=office2; t=1517007782; bh=icWjwoLRTNxBCf3GkzbwVkX6UVZEBvVHTUS8Tagz6Rg=; h=Resent-Date:Resent-From:Resent-To:Resent-Cc:In-Reply-To: References:From:Date:Subject:To:Cc; b=CR6hoVWdLFArW45WeEBlQRa2H+44UU8z9sKbgqZsShwRKOaNkH+rXVXDl7EyVVxlB jlJwtAXjmYSWcY5/0/P7ASEk8kqAzqU6uj3SW2J0u5H5WVmwc1mg1Tl5fac2bVyllF HQN5EItq0f+GP4BNUmmYG0BNKTG8CZ+gI7Hog8c4= Message-Id: <92369661c99f83e656004288fcc06a510b4b8c58.1517007569.git.jan.kundrat@cesnet.cz> In-Reply-To: References: From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Fri, 26 Jan 2018 23:56:10 +0100 Subject: [PATCH v2] spi: orion: Rework GPIO CS handling MIME-Version: 1.0 To: linux-spi@vger.kernel.org, Geert Uytterhoeven , Chris Packham Cc: Mark Brown , Andy Shevchenko , Gregory CLEMENT , Christophe JAILLET Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP - Claim the GPIO from the driver, not via DT bindings or through the platform code - Find an unused HW CS signal because Orion needs to drive one for each SPI transaction The spi-orion.c was the only driver which supported (or cared about) the CS GPIO, while it wasn't actually requesting it. This change means that the DT bindings should stop hogging the GPIO CS pins because it's now being handled by the driver. Signed-off-by: Jan Kundrát --- Changes v1..v2: A complete rework of "spi: orion: Allow specifying which HW CS to use with a GPIO CS" (https://patchwork.kernel.org/patch/10182583/) --- drivers/spi/spi-orion.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c index deca63e82ff6..b341235d2947 100644 --- a/drivers/spi/spi-orion.c +++ b/drivers/spi/spi-orion.c @@ -96,6 +96,7 @@ struct orion_spi { struct clk *clk; struct clk *axi_clk; const struct orion_spi_dev *devdata; + int unused_hw_gpio; struct orion_direct_acc direct_access[ORION_NUM_CHIPSELECTS]; }; @@ -324,13 +325,13 @@ static void orion_spi_set_cs(struct spi_device *spi, bool enable) struct orion_spi *orion_spi; int cs; + orion_spi = spi_master_get_devdata(spi->master); + if (gpio_is_valid(spi->cs_gpio)) - cs = 0; + cs = orion_spi->unused_hw_gpio; else cs = spi->chip_select; - orion_spi = spi_master_get_devdata(spi->master); - orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, ORION_SPI_CS_MASK); orion_spi_setbits(orion_spi, ORION_SPI_IF_CTRL_REG, ORION_SPI_CS(cs)); @@ -498,6 +499,9 @@ static int orion_spi_transfer_one(struct spi_master *master, static int orion_spi_setup(struct spi_device *spi) { + if (gpio_is_valid(spi->cs_gpio)) { + gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); + } return orion_spi_setup_transfer(spi, NULL); } @@ -620,6 +624,7 @@ static int orion_spi_probe(struct platform_device *pdev) spi = spi_master_get_devdata(master); spi->master = master; + spi->unused_hw_gpio = -1; of_id = of_match_device(orion_spi_of_match_table, &pdev->dev); devdata = (of_id) ? of_id->data : &orion_spi_dev_data; @@ -731,8 +736,44 @@ static int orion_spi_probe(struct platform_device *pdev) 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: