From patchwork Thu Feb 20 14:43:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 3687611 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 93C26BF13A for ; Thu, 20 Feb 2014 14:48:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AEF7B20155 for ; Thu, 20 Feb 2014 14:48:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B6CB720142 for ; Thu, 20 Feb 2014 14:48:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753526AbaBTOqj (ORCPT ); Thu, 20 Feb 2014 09:46:39 -0500 Received: from andre.telenet-ops.be ([195.130.132.53]:46187 "EHLO andre.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753558AbaBTOnY (ORCPT ); Thu, 20 Feb 2014 09:43:24 -0500 Received: from ayla.of.borg ([84.193.72.141]) by andre.telenet-ops.be with bizsmtp id UejP1n00s32ts5g01ejPr7; Thu, 20 Feb 2014 15:43:23 +0100 Received: from geert by ayla.of.borg with local (Exim 4.76) (envelope-from ) id 1WGUqR-0005ga-ES; Thu, 20 Feb 2014 15:43:23 +0100 From: Geert Uytterhoeven To: Mark Brown Cc: Takashi Yoshii , Magnus Damm , linux-spi@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 05/10] spi: sh-msiof: Use the core cs_gpio field, and make it optional Date: Thu, 20 Feb 2014 15:43:04 +0100 Message-Id: <1392907389-21798-6-git-send-email-geert@linux-m68k.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1392907389-21798-1-git-send-email-geert@linux-m68k.org> References: <1392907389-21798-1-git-send-email-geert@linux-m68k.org> 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.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 From: Geert Uytterhoeven In current implementation, CS is controlled by GPIO, which is passed through spi->controller_data. However, the MSIOF HW module has a function to output CS by itself, which is already enabled and actual switch will be done by pinmux. Store the GPIO number in the core cs_gpio field, and ignore it if it is an invalid (negative) GPIO number. Loosely based on a patch from Takashi Yoshii . Signed-off-by: Geert Uytterhoeven Cc: Takashi Yoshii --- drivers/spi/spi-sh-msiof.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c index 79e14586049b..92515c1ececa 100644 --- a/drivers/spi/spi-sh-msiof.c +++ b/drivers/spi/spi-sh-msiof.c @@ -445,6 +445,21 @@ static int sh_msiof_spi_setup_transfer(struct spi_device *spi, return spi_bitbang_setup_transfer(spi, t); } +static int sh_msiof_spi_setup(struct spi_device *spi) +{ + struct device_node *np = spi->master->dev.of_node; + + if (!np) { + /* + * Use spi->controller_data for CS (same strategy as spi_gpio), + * if any. otherwise let HW control CS + */ + spi->cs_gpio = (uintptr_t)spi->controller_data; + } + + return spi_bitbang_setup(spi); +} + static void sh_msiof_spi_chipselect(struct spi_device *spi, int is_on) { struct sh_msiof_spi_priv *p = spi_master_get_devdata(spi->master); @@ -470,8 +485,8 @@ static void sh_msiof_spi_chipselect(struct spi_device *spi, int is_on) !!(spi->mode & SPI_CS_HIGH)); } - /* use spi->controller data for CS (same strategy as spi_gpio) */ - gpio_set_value((uintptr_t)spi->controller_data, value); + if (spi->cs_gpio >= 0) + gpio_set_value(spi->cs_gpio, value); if (is_on == BITBANG_CS_INACTIVE) { if (test_and_clear_bit(0, &p->flags)) { @@ -758,7 +773,7 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) master->bus_num = pdev->id; master->dev.of_node = pdev->dev.of_node; master->num_chipselect = p->info->num_chipselect; - master->setup = spi_bitbang_setup; + master->setup = sh_msiof_spi_setup; master->cleanup = spi_bitbang_cleanup; p->bitbang.master = master;