From patchwork Thu Feb 20 17:55:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murali Karicheri X-Patchwork-Id: 25084 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f198.google.com (mail-vc0-f198.google.com [209.85.220.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 48F3A203C6 for ; Thu, 20 Feb 2014 17:58:28 +0000 (UTC) Received: by mail-vc0-f198.google.com with SMTP id lf12sf4030381vcb.5 for ; Thu, 20 Feb 2014 09:58:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=WbuSm3PXDUZKLHS2NEfCiuGsr1PPE2olRyGVvBzHJYg=; b=CFVLIklSkGcN7/bSzi5oA7Q5opACb3Rx8FymsPrEWcnOx4MGRRgvKsuIOWtxzMeyNt 0Mz4j4D9hlB9JCmahmEv+u6oidV88rgXposCfDXGwGBbRmJ+Gn/ynVmXKSgGbgCYyoI6 /AdyzNCqJtOSJLmYvCpSMCA/QO0AbAlf19Cip4kFqXjIBGj58DweorSDetFnJYYqjn1s EDCGUNr4sS1exYENLMCZi4IG/+w7YoRxBpGVdiZ2tMvu0bH/6jQ4O4u1lPIWdYPWnXdb X/GZaHRNsrObRKZ9fnTJOPSNCurx5MEiHZUoF0qNi+QUxw6KrFIpFlQYYIYRsaWt7xE0 7O4Q== X-Gm-Message-State: ALoCoQlA5/5zYFY0WWqGa05gTvZLlRinwlIH5wNTqiFjH3mEkGcYnPoSmHT3yfCbEXwUT9nTrvFB X-Received: by 10.236.228.228 with SMTP id f94mr1109707yhq.43.1392919108024; Thu, 20 Feb 2014 09:58:28 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.37.135 with SMTP id r7ls634646qgr.25.gmail; Thu, 20 Feb 2014 09:58:27 -0800 (PST) X-Received: by 10.221.20.199 with SMTP id qp7mr1814154vcb.24.1392919107892; Thu, 20 Feb 2014 09:58:27 -0800 (PST) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id ke3si1774639veb.103.2014.02.20.09.58.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Feb 2014 09:58:27 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ks9so2135803vcb.25 for ; Thu, 20 Feb 2014 09:58:27 -0800 (PST) X-Received: by 10.220.81.71 with SMTP id w7mr1703856vck.71.1392919107790; Thu, 20 Feb 2014 09:58:27 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp77646vcz; Thu, 20 Feb 2014 09:58:27 -0800 (PST) X-Received: by 10.204.70.13 with SMTP id b13mr883087bkj.159.1392919106832; Thu, 20 Feb 2014 09:58:26 -0800 (PST) Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id qo3si2519144bkb.294.2014.02.20.09.58.26 for ; Thu, 20 Feb 2014 09:58:26 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9BADF4B63A; Thu, 20 Feb 2014 18:57:57 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 A2kxspb0iB2A; Thu, 20 Feb 2014 18:57:57 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 67F894B625; Thu, 20 Feb 2014 18:56:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 59AAA4B5FA for ; Thu, 20 Feb 2014 18:56:29 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 fUGa-75m24qf for ; Thu, 20 Feb 2014 18:56:26 +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 arroyo.ext.ti.com (arroyo.ext.ti.com [192.94.94.40]) by theia.denx.de (Postfix) with ESMTPS id 597E14B62B for ; Thu, 20 Feb 2014 18:56:03 +0100 (CET) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id s1KHu1SG009478 for ; Thu, 20 Feb 2014 11:56:01 -0600 Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1KHu0Lq029318 for ; Thu, 20 Feb 2014 11:56:01 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Thu, 20 Feb 2014 11:56:00 -0600 Received: from ares-ubuntu.am.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1KHu0xt005118; Thu, 20 Feb 2014 11:56:00 -0600 Received: from a0868495 by ares-ubuntu.am.dhcp.ti.com with local (Exim 4.76) (envelope-from ) id 1WGXqq-00044Q-My; Thu, 20 Feb 2014 12:56:00 -0500 From: Murali Karicheri To: , Date: Thu, 20 Feb 2014 12:55:13 -0500 Message-ID: <1392918914-15564-12-git-send-email-m-karicheri2@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1392918914-15564-1-git-send-email-m-karicheri2@ti.com> References: <1392918914-15564-1-git-send-email-m-karicheri2@ti.com> MIME-Version: 1.0 Cc: Rex Chang Subject: [U-Boot] [U-Boot PATCH v2 11/12] spi: davinci: add support for multiple bus and chip select X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m-karicheri2@ti.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Rex Chang Currently davinci spi driver supports only bus 0 cs 0. This patch allows driver to support bus 1 and bus 2 with configurable number of chip selects. Also defaults are selected in a way to avoid regression on other platforms that uses davinci spi driver and has only one spi bus. Signed-off-by: Rex Chang Signed-off-by: Murali Karicheri --- drivers/spi/davinci_spi.c | 62 ++++++++++++++++++++++++++++++++++++++++++--- drivers/spi/davinci_spi.h | 33 ++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 4 deletions(-) diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c index e3fb321..c708a04 100644 --- a/drivers/spi/davinci_spi.c +++ b/drivers/spi/davinci_spi.c @@ -23,7 +23,7 @@ void spi_init() struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, unsigned int max_hz, unsigned int mode) { - struct davinci_spi_slave *ds; + struct davinci_spi_slave *ds; if (!spi_cs_is_valid(bus, cs)) return NULL; @@ -32,7 +32,27 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, if (!ds) return NULL; - ds->regs = (struct davinci_spi_regs *)CONFIG_SYS_SPI_BASE; + ds->slave.bus = bus; + ds->slave.cs = cs; + + switch (bus) { + case SPI0_BUS: + ds->regs = (struct davinci_spi_regs *)SPI0_BASE; + break; +#ifdef CONFIG_SYS_SPI1 + case SPI1_BUS: + ds->regs = (struct davinci_spi_regs *)SPI0_BASE; + break; +#endif +#ifdef CONFIG_SYS_SPI2 + case SPI2_BUS: + ds->regs = (struct davinci_spi_regs *)SPI2_BASE; + break; +#endif + default: /* Invalid bus number */ + return NULL; + } + ds->freq = max_hz; return &ds->slave; @@ -59,7 +79,7 @@ int spi_claim_bus(struct spi_slave *slave) writel(SPIGCR1_MASTER_MASK | SPIGCR1_CLKMOD_MASK, &ds->regs->gcr1); /* CS, CLK, SIMO and SOMI are functional pins */ - writel((SPIPC0_EN0FUN_MASK | SPIPC0_CLKFUN_MASK | + writel(((1 << slave->cs) | SPIPC0_CLKFUN_MASK | SPIPC0_DOFUN_MASK | SPIPC0_DIFUN_MASK), &ds->regs->pc0); /* setup format */ @@ -262,9 +282,43 @@ out: return 0; } +#ifdef CONFIG_SYS_SPI1 +static int bus1_cs_valid(unsigned int bus, unsigned int cs) +{ + if ((bus == SPI1_BUS) && (cs < SPI1_NUM_CS)) + return 1; + return 0; +} +#else +static int bus1_cs_valid(unsigned int bus, unsigned int cs) +{ + return 0; +} +#endif + +#ifdef CONFIG_SYS_SPI2 +static int bus2_cs_valid(unsigned int bus, unsigned int cs) +{ + if ((bus == SPI2_BUS) && (cs < SPI2_NUM_CS)) + return 1; + return 0; +} +#else +static int bus2_cs_valid(unsigned int bus, unsigned int cs) +{ + return 0; +} +#endif + int spi_cs_is_valid(unsigned int bus, unsigned int cs) { - return bus == 0 && cs == 0; + if ((bus == SPI0_BUS) && (cs < SPI0_NUM_CS)) + return 1; + else if (bus1_cs_valid(bus, cs)) + return 1; + else if (bus2_cs_valid(bus, cs)) + return 1; + return 0; } void spi_cs_activate(struct spi_slave *slave) diff --git a/drivers/spi/davinci_spi.h b/drivers/spi/davinci_spi.h index 33f69b5..d4612d3 100644 --- a/drivers/spi/davinci_spi.h +++ b/drivers/spi/davinci_spi.h @@ -74,6 +74,39 @@ struct davinci_spi_regs { /* SPIDEF */ #define SPIDEF_CSDEF0_MASK BIT(0) +#define SPI0_BUS 0 +#define SPI0_BASE CONFIG_SYS_SPI_BASE +/* + * Define default SPI0_NUM_CS as 1 for existing platforms that uses this + * driver. Platform can configure number of CS using CONFIG_SYS_SPI0_NUM_CS + * if more than one CS is supported and by defining CONFIG_SYS_SPI0. + */ +#ifndef CONFIG_SYS_SPI0 +#define SPI0_NUM_CS 1 +#else +#define SPI0_NUM_CS CONFIG_SYS_SPI0_NUM_CS +#endif + +/* + * define CONFIG_SYS_SPI1 when platform has spi-1 device (bus #1) and + * CONFIG_SYS_SPI1_NUM_CS defines number of CS on this bus + */ +#ifdef CONFIG_SYS_SPI1 +#define SPI1_BUS 1 +#define SPI1_NUM_CS CONFIG_SYS_SPI1_NUM_CS +#define SPI1_BASE CONFIG_SYS_SPI1_BASE +#endif + +/* + * define CONFIG_SYS_SPI2 when platform has spi-2 device (bus #2) and + * CONFIG_SYS_SPI2_NUM_CS defines number of CS on this bus + */ +#ifdef CONFIG_SYS_SPI2 +#define SPI2_BUS 2 +#define SPI2_NUM_CS CONFIG_SYS_SPI2_NUM_CS +#define SPI2_BASE CONFIG_SYS_SPI2_BASE +#endif + struct davinci_spi_slave { struct spi_slave slave; struct davinci_spi_regs *regs;