From patchwork Sun Mar 29 14:03:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sperl X-Patchwork-Id: 6117051 Return-Path: X-Original-To: patchwork-linux-spi@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 2CDF1BF4A6 for ; Sun, 29 Mar 2015 14:04:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 545FA20165 for ; Sun, 29 Mar 2015 14:03:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 59F262026D for ; Sun, 29 Mar 2015 14:03:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752804AbbC2OD4 (ORCPT ); Sun, 29 Mar 2015 10:03:56 -0400 Received: from 212-186-180-163.dynamic.surfer.at ([212.186.180.163]:58074 "EHLO cgate.sperl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752546AbbC2ODz convert rfc822-to-8bit (ORCPT ); Sun, 29 Mar 2015 10:03:55 -0400 Received: from msmac.intern.sperl.org (account martin@sperl.org [10.10.10.11] verified) by sperl.org (CommuniGate Pro SMTP 6.1.2) with ESMTPSA id 6290422; Sun, 29 Mar 2015 14:03:46 +0000 From: Martin Sperl Subject: [PATCH/RFC 6/6] spi: bcm2835: set gpio-cs to high state prior to any Message-Id: Date: Sun, 29 Mar 2015 16:03:28 +0200 To: Mark Brown , Stephen Warren , lee@kernel.org, linux-spi@vger.kernel.org, linux-rpi-kernel Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) X-Mailer: Apple Mail (2.2070.6) 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 device initialization The situation has been observed that on the RPI after a reboot the GPIOs used for chip-selects are set to low when pinctl finishes setting up the direction of the pins. This can negatively impact the spi-bus and inhibit propper device detection. This (incomplete) code pulls the CS high to avoid the situation in the common case of "normal" CS-priority - it still needs a revisit to get the reverse polarity cases right as well. A variation of this probably should get moved into spi_register_master to fix this for other spi-controller as well. Signed-off-by: Martin Sperl Tested-by: Martin Sperl --- drivers/spi/spi-bcm2835.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) Applies against spi - topic/bcm2835. diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index 1d731b8..b6825a4 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -349,6 +349,26 @@ static int bcm2835_spi_setup(struct spi_device *spi) return -EINVAL; } +static void bcm2835_spi_initialsetup_gpio(struct spi_master *master) +{ + int i; + bool level; + + if (!master->cs_gpios) + return; + + for (i = 0; i < master->num_chipselect; i++) { + if (gpio_is_valid(master->cs_gpios[i])) { + /* actually we need to figure out the + * configured CSPOL of that device here, + * not sure how to do that... + */ + level = true; + gpio_set_value(master->cs_gpios[i], level); + } + } +} + static int bcm2835_spi_probe(struct platform_device *pdev) { struct spi_master *master; @@ -414,6 +434,9 @@ static int bcm2835_spi_probe(struct platform_device *pdev) goto out_clk_disable; } + /* set GPIO-CS to disabled */ + bcm2835_spi_initialsetup_gpio(master); + return 0; out_clk_disable: