From patchwork Tue Jun 13 05:25:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffy Chen X-Patchwork-Id: 9783153 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 67F59602C9 for ; Tue, 13 Jun 2017 05:33:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B509286D6 for ; Tue, 13 Jun 2017 05:33:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F4E1286E0; Tue, 13 Jun 2017 05:33:33 +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 081E8286D6 for ; Tue, 13 Jun 2017 05:33:32 +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:References: In-Reply-To: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:List-Owner; bh=hmkHF/2JmY86OqyJ97ojY4u8or8uHNYPeTdOjMmU2NU=; b=lAbJQaf2biaH2Rl3E5RoCzPtLQ tUyv7vr4Rz+8tPQ93yzSEq7W4AkAHLtxEVe5AGCqYq+DBGFWna+E24yfWMxDFUqBsobSC4qeAeuI6 i9RPnpeMWdy+SZI65wNzxO2yPJyZcmlH3GkW4fQlX3HXIVQ/cTspN9mvH8DPEq0pzxfalMFscyywV 21qPUawu6rpuhoghf6ZkaaogbBSdjx5m2m/lOQ94LhxEfnVyFacmHNrg8GUcZ7FAswix0zMlLonsD ZzAZbrYan6k6Z03kAFVEMYBaMPsSF8rEOmnreJF1BqM/hnKlaY0E5SNwJNC5CJGvTCFYSpP5kMID3 W4ajn1Lw==; 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 1dKeSK-0005PC-6U; Tue, 13 Jun 2017 05:33:32 +0000 Received: from regular1.263xmail.com ([211.150.99.137]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dKeLR-0002M5-9x; Tue, 13 Jun 2017 05:26:29 +0000 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.242]) by regular1.263xmail.com (Postfix) with ESMTP id 49430DB99; Tue, 13 Jun 2017 13:26:00 +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 EE78D345; Tue, 13 Jun 2017 13:25:48 +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: <7d14d72a7d13eb312721f94e8c7b8679> 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 2561KHEICC; Tue, 13 Jun 2017 13:25:51 +0800 (CST) From: Jeffy Chen To: linux-kernel@vger.kernel.org, broonie@kernel.org Subject: [PATCH v2 2/4] spi: rockchip: add support for "cs-gpios" dts property Date: Tue, 13 Jun 2017 13:25:41 +0800 Message-Id: <1497331543-8565-2-git-send-email-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1497331543-8565-1-git-send-email-jeffy.chen@rock-chips.com> References: <1497331543-8565-1-git-send-email-jeffy.chen@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170612_222626_267765_CA397D25 X-CRM114-Status: GOOD ( 10.87 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: briannorris@chromium.org, heiko@sntech.de, Jeffy Chen , dianders@chromium.org, linux-spi@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=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 1/ request cs gpios in probe for better error handling 2/ use gpiod* function (suggested by Heiko Stuebner) 3/ split dt-binding changes to new patch (suggested by Shawn Lin & Heiko Stuebner) --- Changes in v2: None drivers/spi/spi-rockchip.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c index bab9b13..ad8997b 100644 --- a/drivers/spi/spi-rockchip.c +++ b/drivers/spi/spi-rockchip.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -663,6 +663,27 @@ static bool rockchip_spi_can_dma(struct spi_master *master, return (xfer->len > rs->fifo_len); } +static int rockchip_spi_setup_cs_gpios(struct device *dev) +{ + struct device_node *np = dev->of_node; + struct gpio_desc *cs_gpio; + int i, nb; + + if (!np) + return 0; + + nb = of_gpio_named_count(np, "cs-gpios"); + for (i = 0; i < nb; i++) { + /* We support both GPIO CS and HW CS */ + cs_gpio = devm_gpiod_get_index_optional(dev, "cs", + i, GPIOD_ASIS); + if (IS_ERR(cs_gpio)) + return PTR_ERR(cs_gpio); + } + + return 0; +} + static int rockchip_spi_probe(struct platform_device *pdev) { int ret = 0; @@ -749,6 +770,7 @@ static int rockchip_spi_probe(struct platform_device *pdev) 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)) { @@ -783,6 +805,12 @@ static int rockchip_spi_probe(struct platform_device *pdev) master->dma_rx = rs->dma_rx.ch; } + ret = rockchip_spi_setup_cs_gpios(&pdev->dev); + if (ret) { + dev_err(&pdev->dev, "Failed to setup cs gpios\n"); + goto err_free_dma_rx; + } + ret = devm_spi_register_master(&pdev->dev, master); if (ret) { dev_err(&pdev->dev, "Failed to register master\n");