From patchwork Mon Jan 11 16:33:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cyrille Pitchen X-Patchwork-Id: 8006591 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0C8EF9F1C0 for ; Mon, 11 Jan 2016 16:35:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2DD142028D for ; Mon, 11 Jan 2016 16:35:15 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E7C82024C for ; Mon, 11 Jan 2016 16:35:14 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aIfPp-00051o-50; Mon, 11 Jan 2016 16:33:57 +0000 Received: from eusmtp01.atmel.com ([212.144.249.243]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aIfPk-0004oE-Rg for linux-arm-kernel@lists.infradead.org; Mon, 11 Jan 2016 16:33:54 +0000 Received: from HNOCHT01.corp.atmel.com (10.161.30.161) by eusmtp01.atmel.com (10.161.101.31) with Microsoft SMTP Server (TLS) id 14.3.235.1; Mon, 11 Jan 2016 17:33:27 +0100 Received: from [10.159.226.191] (10.161.30.18) by HNOCHT01.corp.atmel.com (10.161.30.161) with Microsoft SMTP Server (TLS) id 14.3.235.1; Mon, 11 Jan 2016 17:33:29 +0100 Subject: Re: [PATCH] spi: atmel: improve internal vs gpio chip-select choice To: Nicolas Ferre , Mans Rullgard , Mark Brown , , , linux-arm-kernel , "Yang, Wenyou" References: <1452211907-16074-1-git-send-email-mans@mansr.com> <5693C9A3.9040403@atmel.com> From: Cyrille Pitchen Message-ID: <5693D957.30103@atmel.com> Date: Mon, 11 Jan 2016 17:33:27 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <5693C9A3.9040403@atmel.com> X-Originating-IP: [10.161.30.18] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160111_083353_438969_AB36A0D7 X-CRM114-Status: GOOD ( 14.82 ) X-Spam-Score: -4.2 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Mans, Le 11/01/2016 16:26, Nicolas Ferre a écrit : > Le 08/01/2016 01:11, Mans Rullgard a écrit : [...] >> @@ -1569,13 +1576,6 @@ static int atmel_spi_probe(struct platform_device *pdev) >> >> atmel_get_caps(as); >> >> - as->use_cs_gpios = true; >> - if (atmel_spi_is_v2(as) && > > I don't see this atmel_spi_is_v2() test in the resulting code anymore: > did you make sure that the v1 of the peripheral is protected? > >> - !of_get_property(pdev->dev.of_node, "cs-gpios", NULL)) { >> - as->use_cs_gpios = false; >> - master->num_chipselect = 4; > > This line is pretty important: you mustn't remove it blindly! > > Actually, few lines above master->num_chipselect is initialized with: master->dev.of_node = pdev->dev.of_node; [...] master->num_chipselect = master->dev.of_node ? 0 : 4; So 0 in the case of DT support, 4 otherwise. Now looking at the source code of spi_register_master(), this function: 1 - calls of_spi_register_master(), which initializes master->num_chipselect: nb = of_gpio_name_count(np, "cs-gpios"); master->num_chipselect = max_t(int, nb, master->num_chipselect); if (nb == 0 || nb == -ENOENT) return 0; 2 - check master->num_chipselect with: if (master->num_chipselect == 0) return -EINVAL; It means that in the case of DT support, master->num_chipselect was initialized according to the value of the "cs-gpios" DT property. Hence this property used to be mandatory but now we want it to be optional for hardware version 2 and later. This is why we added a check "hw version >= 2 and cs-gpios missing". In such a case the master->num_chipselect was initialized to 4 so spi_register_master() does not fail with -EINVAL. I have applied the following fix after your patch and now the driver works again on sama5d2: >> - } >> - >> as->use_dma = false; >> as->use_pdc = false; >> if (as->caps.has_dma_support) { >> > > So, sorry but it's a NACK for me. > > Bye, > Best regards, Cyrille --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c @@ -1576,6 +1576,11 @@ static int atmel_spi_probe(struct platform_device *pdev) atmel_get_caps(as); + if (atmel_spi_is_v2(as) && + master->dev.of_node && + !of_get_property(master->dev.of_node, "cs-gpios", NULL)) + master->num_chipselect = 4; + as->use_dma = false; as->use_pdc = false; if (as->caps.has_dma_support) {