From patchwork Thu Mar 20 09:20:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 26637 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B57CD202E0 for ; Thu, 20 Mar 2014 09:21:27 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id j17sf2391597oag.10 for ; Thu, 20 Mar 2014 02:21:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=4wh4w9qop8vpm1E/sB18+PR9EXyjmBS3/umi9SDxC2Q=; b=L/QHua+qaf7WFgY3SOCxPTCZzCZYz6TPlT3x1VSiN28Kjgay54fXdeSTb83NwSzhLB qoE2CFHkRD++LzCjrailBTzF6r3EOL6bmGc1dr5lbn44KrCjb2IABtt1AWJiv8szQwga oLAlLoRKQbwkOpy+5pJ9+gRlPH/xPGJaXbu81J9y0XpH3JikVF4oXA5p6Jr/nOjKQgyY x7SJZao4xRSNMnXB2oEFCq7TKM9FwQ51pljfVCVyyVknrZKfE6JniLvMYAOHyUzwEz5V ttF4D6aDfPgurUCLKQ5BjcWz7c5EKrXAbqG0yd9uyVFoPU2sTd5iQ+ODZO7c0eMs6xCF Nt/Q== X-Gm-Message-State: ALoCoQk5LShvFI2/6bvuYjdQYWLPsjqX+oEN9p8fOO/01PBa73iqzT4YDkoDlqJDFXAo3k4xU2Q/ X-Received: by 10.50.2.65 with SMTP id 1mr839810igs.1.1395307287147; Thu, 20 Mar 2014 02:21:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.51.130 with SMTP id u2ls142546qga.34.gmail; Thu, 20 Mar 2014 02:21:27 -0700 (PDT) X-Received: by 10.58.220.161 with SMTP id px1mr33862395vec.13.1395307286989; Thu, 20 Mar 2014 02:21:26 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id kj3si305201vdb.51.2014.03.20.02.21.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Mar 2014 02:21:26 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.169 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.169; Received: by mail-vc0-f169.google.com with SMTP id ik5so612825vcb.28 for ; Thu, 20 Mar 2014 02:21:26 -0700 (PDT) X-Received: by 10.221.74.65 with SMTP id yv1mr3513155vcb.31.1395307286911; Thu, 20 Mar 2014 02:21:26 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.78.9 with SMTP id i9csp372494vck; Thu, 20 Mar 2014 02:21:26 -0700 (PDT) X-Received: by 10.180.103.227 with SMTP id fz3mr1692637wib.29.1395307285635; Thu, 20 Mar 2014 02:21:25 -0700 (PDT) Received: from mail-we0-f180.google.com (mail-we0-f180.google.com [74.125.82.180]) by mx.google.com with ESMTPS id n3si829129wjz.142.2014.03.20.02.21.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Mar 2014 02:21:25 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.180 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.180; Received: by mail-we0-f180.google.com with SMTP id p61so360988wes.39 for ; Thu, 20 Mar 2014 02:21:25 -0700 (PDT) X-Received: by 10.180.165.238 with SMTP id zb14mr1667486wib.51.1395307285112; Thu, 20 Mar 2014 02:21:25 -0700 (PDT) Received: from lee--X1.home (host109-148-116-196.range109-148.btcentralplus.com. [109.148.116.196]) by mx.google.com with ESMTPSA id di9sm4735120wid.6.2014.03.20.02.21.23 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Mar 2014 02:21:24 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, computersforpeace@gmail.com Cc: linux-mtd@lists.infradead.org, dwmw2@infradead.org, Angus.Clark@st.com, Lee Jones Subject: [PATCH v6 04/36] mtd: st_spi_fsm: Supply framework for device requests Date: Thu, 20 Mar 2014 09:20:36 +0000 Message-Id: <1395307268-12721-5-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1395307268-12721-1-git-send-email-lee.jones@linaro.org> References: <1395307268-12721-1-git-send-email-lee.jones@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.169 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 Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The FSM hardware works by setting a predetermined sequence of register writes. Rather than open coding them inside each functional block we're going to define them in a series of formatted 'sequence structures'. This patch provides the framework which shall be used for every action. Acked-by Angus Clark Signed-off-by: Lee Jones --- drivers/mtd/devices/st_spi_fsm.c | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index 7048ea7..5e22c86 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -194,6 +194,8 @@ #define STFSM_FLASH_SAFE_FREQ 10000000UL /* 10 MHz */ +#define STFSM_MAX_WAIT_SEQ_MS 1000 /* FSM execution time */ + struct stfsm { struct device *dev; void __iomem *base; @@ -204,6 +206,24 @@ struct stfsm { uint32_t fifo_dir_delay; }; +struct stfsm_seq { + uint32_t data_size; + uint32_t addr1; + uint32_t addr2; + uint32_t addr_cfg; + uint32_t seq_opc[5]; + uint32_t mode; + uint32_t dummy; + uint32_t status; + uint8_t seq[16]; + uint32_t seq_cfg; +} __packed __aligned(4); + +static inline int stfsm_is_idle(struct stfsm *fsm) +{ + return readl(fsm->base + SPI_FAST_SEQ_STA) & 0x10; +} + static inline uint32_t stfsm_fifo_available(struct stfsm *fsm) { return (readl(fsm->base + SPI_FAST_SEQ_STA) >> 5) & 0x7f; @@ -225,6 +245,42 @@ static void stfsm_clear_fifo(struct stfsm *fsm) } } +static inline void stfsm_load_seq(struct stfsm *fsm, + const struct stfsm_seq *seq) +{ + void __iomem *dst = fsm->base + SPI_FAST_SEQ_TRANSFER_SIZE; + const uint32_t *src = (const uint32_t *)seq; + int words = sizeof(*seq) / sizeof(*src); + + BUG_ON(!stfsm_is_idle(fsm)); + + while (words--) { + writel(*src, dst); + src++; + dst += 4; + } +} + +static void stfsm_wait_seq(struct stfsm *fsm) +{ + unsigned long deadline; + int timeout = 0; + + deadline = jiffies + msecs_to_jiffies(STFSM_MAX_WAIT_SEQ_MS); + + while (!timeout) { + if (time_after_eq(jiffies, deadline)) + timeout = 1; + + if (stfsm_is_idle(fsm)) + return; + + cond_resched(); + } + + dev_err(fsm->dev, "timeout on sequence completion\n"); +} + static int stfsm_set_mode(struct stfsm *fsm, uint32_t mode) { int ret, timeout = 10;