From patchwork Wed Nov 25 09:30:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Longchamp X-Patchwork-Id: 548456 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id ECBF21402E2 for ; Wed, 25 Nov 2015 20:30:55 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5F3CB4B8DF; Wed, 25 Nov 2015 10:30:54 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fHuBTjIFjJZW; Wed, 25 Nov 2015 10:30:54 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D28DC4B8D6; Wed, 25 Nov 2015 10:30:53 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 885DC4B8D6 for ; Wed, 25 Nov 2015 10:30:49 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g0pnKLHphDLM for ; Wed, 25 Nov 2015 10:30:49 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-de.keymile.com (mail-de.keymile.com [195.8.104.250]) by theia.denx.de (Postfix) with ESMTPS id 51E634B8A6 for ; Wed, 25 Nov 2015 10:30:45 +0100 (CET) From: Valentin Longchamp To: u-boot@lists.denx.de, Tom Rini , Stefan Roese , Jagan Teki Date: Wed, 25 Nov 2015 10:30:39 +0100 Message-Id: <1448443839-26470-1-git-send-email-valentin.longchamp@keymile.com> X-Mailer: git-send-email 1.8.3.1 Received: from mailrelay by mail-de.keymile.com Cc: Valentin Longchamp , Holger Brunck Subject: [U-Boot] [PATCH v1] kirkwood_spi: move all pin multiplexing to spi_claim X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The pin multiplexing for the chip select pin was until now done in spi_setup_slave/spi_free_slave. If an SPI slave was probed, its chip select pin was never configured back to the possible alternate pin usage until spi_free_slave was called, even if the bus was released and the pins give back to the alternate function at the end of the accesses. This is now regrouped with the pin multiplexing for the MISO/MOSI/SCK signals in the spi_claim_bus/spi_release_bus. It allows to make sure that the pin multiplexing in working correctly even if an SPI slave remains "probed/active". Signed-off-by: Valentin Longchamp --- drivers/spi/kirkwood_spi.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c index e7b0982..a95ce78 100644 --- a/drivers/spi/kirkwood_spi.c +++ b/drivers/spi/kirkwood_spi.c @@ -21,22 +21,11 @@ static struct kwspi_registers *spireg = (struct kwspi_registers *)MVEBU_SPI_BASE; -#ifdef CONFIG_KIRKWOOD -static u32 cs_spi_mpp_back[2]; -#endif - struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, unsigned int max_hz, unsigned int mode) { struct spi_slave *slave; u32 data; -#ifdef CONFIG_KIRKWOOD - static const u32 kwspi_mpp_config[2][2] = { - { MPP0_SPI_SCn, 0 }, /* if cs == 0 */ - { MPP7_SPI_SCn, 0 } /* if cs != 0 */ - }; -#endif - if (!spi_cs_is_valid(bus, cs)) return NULL; @@ -58,19 +47,11 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, writel(KWSPI_SMEMRDIRQ, &spireg->irq_cause); writel(KWSPI_IRQMASK, &spireg->irq_mask); -#ifdef CONFIG_KIRKWOOD - /* program mpp registers to select SPI_CSn */ - kirkwood_mpp_conf(kwspi_mpp_config[cs ? 1 : 0], cs_spi_mpp_back); -#endif - return slave; } void spi_free_slave(struct spi_slave *slave) { -#ifdef CONFIG_KIRKWOOD - kirkwood_mpp_conf(cs_spi_mpp_back, NULL); -#endif free(slave); } @@ -83,8 +64,20 @@ __attribute__((weak)) int board_spi_claim_bus(struct spi_slave *slave) return 0; } +#ifdef CONFIG_KIRKWOOD +static u32 cs_spi_mpp_back[2]; +#endif + int spi_claim_bus(struct spi_slave *slave) { +#ifdef CONFIG_KIRKWOOD + static const u32 kwspi_mpp_config[2][2] = { + { MPP0_SPI_SCn, 0 }, /* if cs == 0 */ + { MPP7_SPI_SCn, 0 } /* if cs != 0 */ + }; + unsigned int cs = slave->cs; +#endif + #if defined(CONFIG_SYS_KW_SPI_MPP) u32 config; u32 spi_mpp_config[4]; @@ -113,6 +106,11 @@ int spi_claim_bus(struct spi_slave *slave) kirkwood_mpp_conf(spi_mpp_config, spi_mpp_backup); #endif +#ifdef CONFIG_KIRKWOOD + /* program mpp registers to select SPI_CSn */ + kirkwood_mpp_conf(kwspi_mpp_config[cs ? 1 : 0], cs_spi_mpp_back); +#endif + return board_spi_claim_bus(slave); } @@ -126,6 +124,9 @@ void spi_release_bus(struct spi_slave *slave) kirkwood_mpp_conf(spi_mpp_backup, NULL); #endif +#ifdef CONFIG_KIRKWOOD + kirkwood_mpp_conf(cs_spi_mpp_back, NULL); +#endif board_spi_release_bus(slave); }