From patchwork Mon Nov 9 04:14:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Boichat X-Patchwork-Id: 7580431 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 94D74C05C6 for ; Mon, 9 Nov 2015 04:17:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8C57420705 for ; Mon, 9 Nov 2015 04:17:04 +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 B7BF920701 for ; Mon, 9 Nov 2015 04:17:03 +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 1ZvdrU-00067W-32; Mon, 09 Nov 2015 04:15:20 +0000 Received: from mail-pa0-x22a.google.com ([2607:f8b0:400e:c03::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZvdrR-0004uq-6c for linux-arm-kernel@lists.infradead.org; Mon, 09 Nov 2015 04:15:17 +0000 Received: by pacdm15 with SMTP id dm15so161090212pac.3 for ; Sun, 08 Nov 2015 20:14:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=LqPm5ottIe/VpeS8Xx3qxAppn03PcE9PZQ9MyaMP6Us=; b=D0q9/3bpQTMDlYvaiouphkHFvbou9i9RtPnJ9h7r3kJERd+OM5jcJ9ZXD/dMGTCwEA 2hk0a4QA9aVpOjFgbAd7jpwiRope7Vxq9J1xtasDbSbsSg2IITQZFlfuUk17rMbfb3Ab tkz+MfJG81pGQY5ZFmnRXQw0jzA7ojnxOaaEw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=LqPm5ottIe/VpeS8Xx3qxAppn03PcE9PZQ9MyaMP6Us=; b=KaoiEJ+1+ivp3batjA0IsTqEeaQkbUQArgMr6dto0PiRLXlRdmKjhTbHA8gZV8b6Nk m4zKqgfuyasOG25tMxHyDF2+te1dG1p6A5HrK4OaUkhQ+86014sILvIu8Tb+v5CDQ6zU xbJm9w9BKBAkOwYQzjRSOaIWxTfd/lp8zwydB0h0VwYTmI6MK8rn5OOGFOkhGEkkYlh/ 5RDrtulIA/NWn92bkId38gVKPqJf/Hr0Zhnf3hedF01QO6KkCS8YQdRrhIe+hQkqL+Wz lpHr9c0TCKFn6uobBOmgUPfVwT5IiLQ/FMXgnfDKRWjyxKe+6LXLql9Uqjh7W3xYLoyr lPhA== X-Gm-Message-State: ALoCoQmhM5VIvSfjdRHtP+pjVzVrv7WCv6RIx9zJ8wVS9d59lHHNd3rW6qtRgaOq1NAvTeEZRhny X-Received: by 10.66.123.72 with SMTP id ly8mr36747010pab.92.1447042495986; Sun, 08 Nov 2015 20:14:55 -0800 (PST) Received: from drinkcat.tpe.corp.google.com ([172.30.210.53]) by smtp.gmail.com with ESMTPSA id h10sm4579915pat.7.2015.11.08.20.14.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Nov 2015 20:14:55 -0800 (PST) From: Nicolas Boichat To: Mark Brown Subject: [PATCH v2] spi: mediatek: single device does not require cs_gpios Date: Mon, 9 Nov 2015 12:14:51 +0800 Message-Id: <1447042491-1199-1-git-send-email-drinkcat@chromium.org> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151108_201517_368559_8354775D X-CRM114-Status: GOOD ( 16.60 ) X-Spam-Score: -2.7 (--) 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: , Cc: Leilk Liu , linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , 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-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_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 When only one device is present, it is not necessary to specify cs_gpios, as the CS line can be controlled by the hardware module. Without this patch, older device tree bindings used before 37457607 "spi: mediatek: mt8173 spi multiple devices support" would cause a panic on boot. This fixes the crash, and re-introduces backward compatibility. Signed-off-by: Nicolas Boichat Acked-by: Leilk Liu --- v2: Use gpio_is_valid() Applies on top of broonie/spi.git/for-next. drivers/spi/spi-mt65xx.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c index 563954a..7840067 100644 --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c @@ -410,7 +410,7 @@ static int mtk_spi_setup(struct spi_device *spi) if (!spi->controller_data) spi->controller_data = (void *)&mtk_default_chip_info; - if (mdata->dev_comp->need_pad_sel) + if (mdata->dev_comp->need_pad_sel && gpio_is_valid(spi->cs_gpio)) gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); return 0; @@ -632,13 +632,23 @@ static int mtk_spi_probe(struct platform_device *pdev) goto err_put_master; } - for (i = 0; i < master->num_chipselect; i++) { - ret = devm_gpio_request(&pdev->dev, master->cs_gpios[i], - dev_name(&pdev->dev)); - if (ret) { - dev_err(&pdev->dev, - "can't get CS GPIO %i\n", i); - goto err_put_master; + if (!master->cs_gpios && master->num_chipselect > 1) { + dev_err(&pdev->dev, + "cs_gpios not specified and num_chipselect > 1\n"); + ret = -EINVAL; + goto err_put_master; + } + + if (master->cs_gpios) { + for (i = 0; i < master->num_chipselect; i++) { + ret = devm_gpio_request(&pdev->dev, + master->cs_gpios[i], + dev_name(&pdev->dev)); + if (ret) { + dev_err(&pdev->dev, + "can't get CS GPIO %i\n", i); + goto err_put_master; + } } } }