From patchwork Fri Mar 17 05:03:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Ungerer X-Patchwork-Id: 9629817 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 28EAE602D6 for ; Fri, 17 Mar 2017 05:16:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 102D728677 for ; Fri, 17 Mar 2017 05:16:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 020DD2867F; Fri, 17 Mar 2017 05:16:56 +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 9F83728677 for ; Fri, 17 Mar 2017 05:16:56 +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=BC82wEkG2r4mf+Y+Egm//KNdHjbVsUUDmN/1X7l4hzU=; b=ry3UbFxVqBSLHEN9Gy/1T7D9L9 gaKHJtValmUOYWUPEHh34pC4fUyZZJvULGotLT0EXaueszaay/yYVzWLwjnZ4HT5nEqkwaEENuSq0 5IQnj6ufVTgPP3OpF9FX9W0gd0adYL8oTlerLJCG8dkZblVcSPVhDjRG+S7upw7GPH3EcjzkzrMI5 uMXR0htPebGSmuDiCLgQgSUMIIpTZAL4TN1KdUb1VKo/aKiaM8mcGDS/oOfKz1ppmJnUgb1fZtHqT 4o9nOoStu7wBe25Ai8T3Rq0U49IZwidqvBqiwE2P2/x6LhCvfzm6JrXOOpSNkH2s/mnoEYBkagLIE Ae+npcog==; 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 1cokFz-0003s9-Jg; Fri, 17 Mar 2017 05:16:55 +0000 Received: from icp-osb-irony-out1.external.iinet.net.au ([203.59.1.210]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cok2n-0006aT-GZ for linux-arm-kernel@lists.infradead.org; Fri, 17 Mar 2017 05:03:19 +0000 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2DrBACfbctY/zXSMGddHAEBBAEBCgEBg1GBa4MUmwkBAQEGlFOEHRqGCAKDBlcBAgEBAQEBAmsohRYGJ1IQGCcSVwcSiXMMs006JgKKKgExhgmPbQWcRAGSQIprhjyTTVeBBCMWCCQIQYZpLjWJVwEBAQ X-IPAS-Result: A2DrBACfbctY/zXSMGddHAEBBAEBCgEBg1GBa4MUmwkBAQEGlFOEHRqGCAKDBlcBAgEBAQEBAmsohRYGJ1IQGCcSVwcSiXMMs006JgKKKgExhgmPbQWcRAGSQIprhjyTTVeBBCMWCCQIQYZpLjWJVwEBAQ X-IronPort-AV: E=Sophos;i="5.36,175,1486396800"; d="scan'208";a="179878463" Received: from unknown (HELO goober.accelecon.com) ([103.48.210.53]) by icp-osb-irony-out1.iinet.net.au with ESMTP; 17 Mar 2017 13:02:51 +0800 From: Greg Ungerer To: linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/2] spi: imx: fix use of native chip-selects with devicetree Date: Fri, 17 Mar 2017 15:03:03 +1000 Message-Id: <1489726983-17706-3-git-send-email-gerg@linux-m68k.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1489726983-17706-1-git-send-email-gerg@linux-m68k.org> References: <1489726983-17706-1-git-send-email-gerg@linux-m68k.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170316_220317_806623_D93115ED X-CRM114-Status: GOOD ( 10.95 ) 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: fabio.estevam@nxp.com, shawnguo@kernel.org, Greg Ungerer , kernel@pengutronix.de 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 The commonly used mechanism of specifying the hardware or native chip-select on an SPI device in devicetree (that is "cs-gpios = <0>") does not result in the native chip-select being configured for use. So external SPI devices that require use of the native chip-select will not work. You can successfully specify native chip-selects if using a platform setup by specifying the cs-gpio as negative offset by 32. And that works correctly. You cannot use the same method in devicetree. The logic in the spi-imx.c driver during probe uses core spi function of_spi_register_master() in spi.c to parse the "cs-gpios" devicetree tag. For valid GPIO values that will be recorded for use, all other entries in the cs_gpios list will be set to -ENOENT. So entries like "<0>" will be set to -ENOENT in the cs_gpios list. When the SPI device registers are setup the code will use the GPIO listed in the cs_gpios list for the desired chip-select. If the cs_gpio is less then 0 then it is intended to be for a native chip-select, and its cs_gpio value is added to 32 to get the chipselect number to use. Problem is that with devicetree this can only ever be -ENOENT (which is -2), and that alone results in an invalid chip-select number. But also doesn't allow selection of the native chip-select at all. To fix, if the cs_gpio specified for this spi device is not a valid GPIO then use the "chip_select" (that is the native chip-select number) for hardware setup. Signed-off-by: Greg Ungerer Acked-by: Shawn Guo --- drivers/spi/spi-imx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index 9a7c62f..dbb482c 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c @@ -516,8 +516,8 @@ static int mx31_config(struct spi_device *spi, struct spi_imx_config *config) reg |= MX31_CSPICTRL_POL; if (spi->mode & SPI_CS_HIGH) reg |= MX31_CSPICTRL_SSPOL; - if (spi->cs_gpio < 0) - reg |= (spi->cs_gpio + 32) << + if (!gpio_is_valid(spi->cs_gpio)) + reg |= (spi->chip_select) << (is_imx35_cspi(spi_imx) ? MX35_CSPICTRL_CS_SHIFT : MX31_CSPICTRL_CS_SHIFT); @@ -608,8 +608,8 @@ static int mx21_config(struct spi_device *spi, struct spi_imx_config *config) reg |= MX21_CSPICTRL_POL; if (spi->mode & SPI_CS_HIGH) reg |= MX21_CSPICTRL_SSPOL; - if (spi->cs_gpio < 0) - reg |= (spi->cs_gpio + 32) << MX21_CSPICTRL_CS_SHIFT; + if (!gpio_is_valid(spi->cs_gpio)) + reg |= spi->chip_select << MX21_CSPICTRL_CS_SHIFT; writel(reg, spi_imx->base + MXC_CSPICTRL);