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: 7580411 Return-Path: X-Original-To: patchwork-linux-spi@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 D4BD89F1C2 for ; Mon, 9 Nov 2015 04:15:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0D40E203B4 for ; Mon, 9 Nov 2015 04:15:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1BA292044C for ; Mon, 9 Nov 2015 04:15:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752372AbbKIEO5 (ORCPT ); Sun, 8 Nov 2015 23:14:57 -0500 Received: from mail-pa0-f48.google.com ([209.85.220.48]:35958 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752128AbbKIEO4 (ORCPT ); Sun, 8 Nov 2015 23:14:56 -0500 Received: by pacdm15 with SMTP id dm15so161090211pac.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=Aufiucm4NDraf9K4OV8tiHlaLZTTbdrOBbW61UxvYyLFZhMvmrMh0xJX25SEe4qDGK HU9xKZJkcbYy5zULbaXtt2EIvxB+aZqCEemSXWnSE8kK9j1ISOAhk1uJQUUbmV/SeQdq 3hXO1AeVwPgkb1DMwnfN0dUj97k2Uhs8TAv30n421tW3soLD8d1suyDy8caFhVW/mZTF VsKNotwMO6aIY9oA+CnJGHZr37I3UaESPkVP3NQizE7JQBBvMtUCzVVZcwFMq/SbsYpG T3pzMokA8oYl91zLq3+K9l6HBqX425qhC0AOuc8rX375EaKzghN7zXKvTo5s3sdJaOs7 ZkOw== X-Gm-Message-State: ALoCoQnm0shK5u/E0VcFdg9NENFrs0r+7Rj0RLWPgN7CGC4Q4aHELKrjEqCaE+dSxMWF156/piqw 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 Cc: Leilk Liu , Matthias Brugger , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org 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 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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; + } } } }