From patchwork Thu Jan 9 12:31:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 3459871 Return-Path: X-Original-To: patchwork-linux-arm@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 A30589F384 for ; Thu, 9 Jan 2014 12:38:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7CAB920120 for ; Thu, 9 Jan 2014 12:38:54 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 312672011B for ; Thu, 9 Jan 2014 12:38:53 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W1Er1-00031s-MS; Thu, 09 Jan 2014 12:36:56 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W1EqY-000439-SO; Thu, 09 Jan 2014 12:36:26 +0000 Received: from mail-we0-f180.google.com ([74.125.82.180]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W1Epd-0003tI-Ar for linux-arm-kernel@lists.infradead.org; Thu, 09 Jan 2014 12:35:35 +0000 Received: by mail-we0-f180.google.com with SMTP id t61so2717045wes.11 for ; Thu, 09 Jan 2014 04:35:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tdMVvA2byWRIkixbkq2UKsmgQJ3TEI6V+ZS3u2FYvLM=; b=SyArI/uwOD8KtEMfBM43AH9doBGnp5mC7SC/SCDo29O/GDDTLEnGBsQrEMjDzBrk1h ut/rgCIC3X+ufxwWRgAFRDl3Imh0xclHwl9S432j/IriawdQTG+QxbNi3RWQ3fJYVmaf raBqRheZcx5Vw5ecGxFIM9DcK8aIDlWLtbxo3/hXtdorr2rgrhFT5q5GBACfM9K439ET JyidDIchchz9GE8hhPIWZhdnIcMom5l14TAm5oRCfwcqr9lGG4ycDzzjSgyYYLAue1Mz lsHvK7syVN0QC13A9KQfDg00xrJ8CZqKUtfErVhEgKxWFb0LZBqfcK6H8AqZbKaAU/pE wf8A== X-Received: by 10.180.206.138 with SMTP id lo10mr3020710wic.25.1389270907721; Thu, 09 Jan 2014 04:35:07 -0800 (PST) Received: from stedf17-labo202.ds.jdsu.net. (4-161.80-90.static-ip.oleane.fr. [90.80.161.4]) by mx.google.com with ESMTPSA id t10sm7454854wia.6.2014.01.09.04.35.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Jan 2014 04:35:06 -0800 (PST) From: Jean-Jacques Hiblot To: nicolas.ferre@atmel.com, b.brezillon@overkiz.com, arnd@arndb.de Subject: [PATCH v2 06/12] at91: smc: Adds helper functions to validate and clip the smc timings. Date: Thu, 9 Jan 2014 13:31:43 +0100 Message-Id: <1389270709-32662-7-git-send-email-jjhiblot@traphandler.com> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1389270709-32662-1-git-send-email-jjhiblot@traphandler.com> References: <1389270709-32662-1-git-send-email-jjhiblot@traphandler.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140109_073529_540842_7329DBEC X-CRM114-Status: GOOD ( 13.42 ) X-Spam-Score: -2.6 (--) Cc: Jean-Jacques Hiblot , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 This patchs implememnts 2 functions to help with the configuration of a chip-select's timing: * sam9_smc_check_cs_configuration : checks that the values would fit in the registers. * sam9_smc_clip_cs_configuration : clip the values to their maximum. Signed-off-by: Jean-Jacques Hiblot --- arch/arm/mach-at91/include/mach/at91sam9_smc.h | 2 + arch/arm/mach-at91/sam9_smc.c | 77 ++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/arch/arm/mach-at91/include/mach/at91sam9_smc.h b/arch/arm/mach-at91/include/mach/at91sam9_smc.h index c3e29311..615ac56 100644 --- a/arch/arm/mach-at91/include/mach/at91sam9_smc.h +++ b/arch/arm/mach-at91/include/mach/at91sam9_smc.h @@ -47,6 +47,8 @@ extern void sam9_smc_read_mode(int id, int cs, struct sam9_smc_config *config); extern void sam9_smc_write_mode(int id, int cs, struct sam9_smc_config *config); extern void sam9_smc_cs_read(void __iomem *, struct sam9_smc_config *config); extern void sam9_smc_cs_configure(void __iomem *, struct sam9_smc_config *cfg); +extern int sam9_smc_check_cs_configuration(struct sam9_smc_config *config); +extern void sam9_smc_clip_cs_configuration(struct sam9_smc_config *config); #endif #define AT91_SMC_SETUP 0x00 /* Setup Register for CS n */ diff --git a/arch/arm/mach-at91/sam9_smc.c b/arch/arm/mach-at91/sam9_smc.c index d7a6156..fe3c492 100644 --- a/arch/arm/mach-at91/sam9_smc.c +++ b/arch/arm/mach-at91/sam9_smc.c @@ -23,6 +23,83 @@ static void __iomem *smc_base_addr[2]; +static int count_trailing_zeroes(u32 x) +{ + int ret = 0; + if (!(x & 0xFFFF)) { + ret += 16; + x = x >> 16; + } + if (!(x & 0xFF)) { + ret += 8; + x = x >> 8; + } + if (!(x & 0xF)) { + ret += 4; + x = x >> 4; + } + if (!(x & 0x3)) { + ret += 2; + x = x >> 2; + } + if (!(x & 0x1)) { + ret += 1; + x = x >> 1; + } + if (!(x & 0x1)) + ret += 1; + + return ret; +} + + +#define __CHECK_CFG(config, x, y) do {\ + if (x##_(config->y) > x) {\ + pr_debug("error: %s (0x%x) is out of range\n", #y,\ + config->y >> count_trailing_zeroes(x));\ + return -EINVAL;\ + } \ + } while (0) + +int sam9_smc_check_cs_configuration(struct sam9_smc_config *config) +{ + __CHECK_CFG(config, AT91_SMC_NWESETUP, nwe_setup); + __CHECK_CFG(config, AT91_SMC_NCS_WRSETUP, ncs_write_setup); + __CHECK_CFG(config, AT91_SMC_NRDSETUP, nrd_setup); + __CHECK_CFG(config, AT91_SMC_NCS_RDSETUP, ncs_read_setup); + __CHECK_CFG(config, AT91_SMC_NWEPULSE, nwe_pulse); + __CHECK_CFG(config, AT91_SMC_NCS_WRPULSE, ncs_write_pulse); + __CHECK_CFG(config, AT91_SMC_NRDPULSE, nrd_pulse); + __CHECK_CFG(config, AT91_SMC_NCS_RDPULSE, ncs_read_pulse); + __CHECK_CFG(config, AT91_SMC_NWECYCLE, write_cycle); + __CHECK_CFG(config, AT91_SMC_NRDCYCLE, read_cycle); + __CHECK_CFG(config, AT91_SMC_TDF, tdf_cycles); + return 0; +} + +#define __CLIP_CFG(config, x, y) do {\ + if (x##_(config->y) > x) {\ + config->y = x >> count_trailing_zeroes(x);\ + pr_debug("clipping %s to %d\n", #y, config->y);\ + } \ + } while (0) + +void sam9_smc_clip_cs_configuration(struct sam9_smc_config *config) +{ + __CLIP_CFG(config, AT91_SMC_NWESETUP, nwe_setup); + __CLIP_CFG(config, AT91_SMC_NCS_WRSETUP, ncs_write_setup); + __CLIP_CFG(config, AT91_SMC_NRDSETUP, nrd_setup); + __CLIP_CFG(config, AT91_SMC_NCS_RDSETUP, ncs_read_setup); + __CLIP_CFG(config, AT91_SMC_NWEPULSE, nwe_pulse); + __CLIP_CFG(config, AT91_SMC_NCS_WRPULSE, ncs_write_pulse); + __CLIP_CFG(config, AT91_SMC_NRDPULSE, nrd_pulse); + __CLIP_CFG(config, AT91_SMC_NCS_RDPULSE, ncs_read_pulse); + __CLIP_CFG(config, AT91_SMC_NWECYCLE, write_cycle); + __CLIP_CFG(config, AT91_SMC_NRDCYCLE, read_cycle); + __CLIP_CFG(config, AT91_SMC_TDF, tdf_cycles); + +} + static void sam9_smc_cs_write_mode(void __iomem *base, struct sam9_smc_config *config) {