From patchwork Tue Jan 14 11:36:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 3485401 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 39D979F381 for ; Tue, 14 Jan 2014 11:37:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 62C98201B4 for ; Tue, 14 Jan 2014 11:37:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4E336201C7 for ; Tue, 14 Jan 2014 11:37:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751792AbaANLhF (ORCPT ); Tue, 14 Jan 2014 06:37:05 -0500 Received: from jacques.telenet-ops.be ([195.130.132.50]:43349 "EHLO jacques.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751600AbaANLhF (ORCPT ); Tue, 14 Jan 2014 06:37:05 -0500 Received: from ayla.of.borg ([84.193.72.141]) by jacques.telenet-ops.be with bizsmtp id Dncy1n00H32ts5g0JncyAG; Tue, 14 Jan 2014 12:36:59 +0100 Received: from geert by ayla.of.borg with local (Exim 4.76) (envelope-from ) id 1W32Ij-0007aS-8O; Tue, 14 Jan 2014 12:36:57 +0100 From: Geert Uytterhoeven To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH/RFC] spi: core: Fix logic mismatch in spi_master.set_cs() Date: Tue, 14 Jan 2014 12:36:51 +0100 Message-Id: <1389699411-29135-1-git-send-email-geert@linux-m68k.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 From: Geert Uytterhoeven The documentation for spi_master.set_cs() says: assert or deassert chip select, true to assert i.e. its "enable" parameter uses assertion-level logic. This does not match the implementation of spi_set_cs(), which calls spi_master.set_cs() with the wanted logical value of the chip select line, i.e. "false" to assert an active low chip select, and "true" to assert an active high chip select. Correct the implementation to use assertion-level logic. For GPIO-based chip selects, active high chip selects are still handled in spi_set_cs(), as this is a direct GPIO level. For SPI controller-based chip selects, active high chip selects must be handled by the SPI master driver, if supported (some SPI controllers have configurable chip select polarity). Signed-off-by: Geert Uytterhoeven --- drivers/spi/spi.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index a86569e1f178..eb20169e84e8 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -561,13 +561,12 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n) static void spi_set_cs(struct spi_device *spi, bool enable) { - if (spi->mode & SPI_CS_HIGH) - enable = !enable; - - if (spi->cs_gpio >= 0) + if (spi->cs_gpio >= 0) { + if (spi->mode & SPI_CS_HIGH) + enable = !enable; gpio_set_value(spi->cs_gpio, !enable); - else if (spi->master->set_cs) - spi->master->set_cs(spi, !enable); + } else if (spi->master->set_cs) + spi->master->set_cs(spi, enable); } /*