From patchwork Mon Jun 12 06:14:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffy Chen X-Patchwork-Id: 9780467 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 6211060212 for ; Mon, 12 Jun 2017 06:15:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F52227968 for ; Mon, 12 Jun 2017 06:15:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4333426E69; Mon, 12 Jun 2017 06:15:00 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ADB4E26E69 for ; Mon, 12 Jun 2017 06:14:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=l9Owe8vrt17uMAdKL7ObQB+b5ElCtaUkPOCAY2FJvRk=; b=Mj7 Ut2h/LsUw3y5fCE9ayPPJwRjeLhMqD6K2uirA6G1JoYIrqUIBKtvWNvYo2bcmAzMQC/qhF34ANsaY t4SLXCZfeemEW4Jd52FSvKXvCoDPbeh4ZyxJkT/eeCNG8OyB1y7PdL+wPQc42iVyrOwVgfhohhiAQ kuKylqvemkDiCea5BO0EaSyAW3CeK1s9asX5b+5LbiuB4o0XZ8ToKyXH1VopkIxHcybE/miKqlBls m41JsLD1xoCNwFMVHdHsyKEdPOR7Jw7E/oVTErRetl66yHUuPEKlqAa5qg3VJWh30d5YelT/TNWW9 y0e9uar2Llj3sf8e3hKi7KkOgn0lOYw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dKIcs-0005tG-Im; Mon, 12 Jun 2017 06:14:58 +0000 Received: from regular1.263xmail.com ([211.150.99.140]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dKIco-0005rj-CI; Mon, 12 Jun 2017 06:14:57 +0000 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.224]) by regular1.263xmail.com (Postfix) with ESMTP id A9E7B4CAE; Mon, 12 Jun 2017 14:14:22 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTP id 947E9308; Mon, 12 Jun 2017 14:14:19 +0800 (CST) X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: linux-kernel@vger.kernel.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: X-ATTACHMENT-NUM: 0 X-SENDER: cjf@rock-chips.com X-DNS-TYPE: 0 Received: from localhost (unknown [103.29.142.67]) by smtp.263.net (Postfix) whith ESMTP id 21180PB24OV; Mon, 12 Jun 2017 14:14:23 +0800 (CST) From: Jeffy Chen To: linux-kernel@vger.kernel.org, broonie@kernel.org Subject: [PATCH 1/2] spi: rockchip: add support for "cs-gpios" dts property Date: Mon, 12 Jun 2017 14:14:15 +0800 Message-Id: <1497248057-16550-1-git-send-email-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.1.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170611_231454_988124_6575F27C X-CRM114-Status: UNSURE ( 9.42 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, briannorris@chromium.org, heiko@sntech.de, Jeffy Chen , dianders@chromium.org, linux-spi@vger.kernel.org, linux-rockchip@lists.infradead.org, Rob Herring , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Support using "cs-gpios" property to specify cs gpios. Signed-off-by: Jeffy Chen --- .../devicetree/bindings/spi/spi-rockchip.txt | 2 + drivers/spi/spi-rockchip.c | 52 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/Documentation/devicetree/bindings/spi/spi-rockchip.txt b/Documentation/devicetree/bindings/spi/spi-rockchip.txt index 83da493..02171b2 100644 --- a/Documentation/devicetree/bindings/spi/spi-rockchip.txt +++ b/Documentation/devicetree/bindings/spi/spi-rockchip.txt @@ -17,6 +17,7 @@ Required Properties: region. - interrupts: The interrupt number to the cpu. The interrupt specifier format depends on the interrupt controller. +- cs-gpios : Specifies the gpio pins to be used for chipselects. - clocks: Must contain an entry for each entry in clock-names. - clock-names: Shall be "spiclk" for the transfer-clock, and "apb_pclk" for the peripheral clock. @@ -48,6 +49,7 @@ Example: #address-cells = <1>; #size-cells = <0>; interrupts = ; + cs-gpios = <&gpio2 23 GPIO_ACTIVE_HIGH>; clocks = <&cru SCLK_SPI0>, <&cru PCLK_SPI0>; clock-names = "spiclk", "apb_pclk"; pinctrl-0 = <&spi1_pins>; diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c index acf31f3..04694e1 100644 --- a/drivers/spi/spi-rockchip.c +++ b/drivers/spi/spi-rockchip.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -201,6 +202,10 @@ struct rockchip_spi { struct dma_slave_caps dma_caps; }; +struct rockchip_spi_data { + bool cs_gpio_requested; +}; + static inline void spi_enable_chip(struct rockchip_spi *rs, int enable) { writel_relaxed((enable ? 1 : 0), rs->regs + ROCKCHIP_SPI_SSIENR); @@ -297,6 +302,50 @@ static void rockchip_spi_set_cs(struct spi_device *spi, bool enable) pm_runtime_put_sync(rs->dev); } +static int rockchip_spi_setup(struct spi_device *spi) +{ + int ret = 0; + unsigned long flags = (spi->mode & SPI_CS_HIGH) ? + GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH; + struct rockchip_spi_data *data = spi_get_ctldata(spi); + + if (!gpio_is_valid(spi->cs_gpio)) + return 0; + + if (!data) { + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + spi_set_ctldata(spi, data); + } + + if (!data->cs_gpio_requested) { + ret = gpio_request_one(spi->cs_gpio, flags, + dev_name(&spi->dev)); + if (!ret) + data->cs_gpio_requested = 1; + } else + ret = gpio_direction_output(spi->cs_gpio, flags); + + if (ret < 0) + dev_err(&spi->dev, "Failed to setup cs gpio(%d): %d\n", + spi->cs_gpio, ret); + + return ret; +} + +static void rockchip_spi_cleanup(struct spi_device *spi) +{ + struct rockchip_spi_data *data = spi_get_ctldata(spi); + + if (data) { + if (data->cs_gpio_requested) + gpio_free(spi->cs_gpio); + kfree(data); + spi_set_ctldata(spi, NULL); + } +} + static int rockchip_spi_prepare_message(struct spi_master *master, struct spi_message *msg) { @@ -744,11 +793,14 @@ static int rockchip_spi_probe(struct platform_device *pdev) master->bits_per_word_mask = SPI_BPW_MASK(16) | SPI_BPW_MASK(8); master->set_cs = rockchip_spi_set_cs; + master->setup = rockchip_spi_setup; + master->cleanup = rockchip_spi_cleanup; master->prepare_message = rockchip_spi_prepare_message; master->unprepare_message = rockchip_spi_unprepare_message; master->transfer_one = rockchip_spi_transfer_one; master->max_transfer_size = rockchip_spi_max_transfer_size; master->handle_err = rockchip_spi_handle_err; + master->flags = SPI_MASTER_GPIO_SS; rs->dma_tx.ch = dma_request_chan(rs->dev, "tx"); if (IS_ERR(rs->dma_tx.ch)) {