From patchwork Fri Nov 29 12:18:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 21862 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f70.google.com (mail-vb0-f70.google.com [209.85.212.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C448123FEA for ; Fri, 29 Nov 2013 12:19:44 +0000 (UTC) Received: by mail-vb0-f70.google.com with SMTP id x8sf21324290vbf.1 for ; Fri, 29 Nov 2013 04:19:44 -0800 (PST) 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=LFXCGqY8WlAButEfvTdTmOxUyTAXJGBFtDwmTSfJn1w=; b=nLzGifXu2b7yyEHyUH1BFlecGuIYHPjyUGelANTrynK36HPwy4o7ja+Iapgb0uFjDD sIziX37EuP3um9BgtGemGNbGdrs2mpijOL6Sg6od30SkDatX7QlGYBtw4oUc/17SjuZc BAK/rSgz40U7ELKJUfi5mjvUj1snmJxW7ZYHG8ukCfeUvE0kFofYHQgLPEO00A9slYW5 +f3rOf1IacW9Z/aZbQTnc5YmtXItY7ST9qrtabr3U+cHv0H3DS1KZFS+65tJhNiD/ER+ Kp9TTpfmhSRP2KRX/iTWMKjfkqg6hPlpV6VqPJTci6EwPrzB441bB28eygXlJRD/IDbp f3Aw== X-Gm-Message-State: ALoCoQnNUyR+coe65roYpwmrkjqbQ/FVO4NM/f67NN0ZmCDZVD/I3lmGEdxoN/hY3XSwqNm8IcEf X-Received: by 10.224.104.8 with SMTP id m8mr18179580qao.0.1385727584580; Fri, 29 Nov 2013 04:19:44 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.120.5 with SMTP id ky5ls3784129qeb.26.gmail; Fri, 29 Nov 2013 04:19:44 -0800 (PST) X-Received: by 10.52.186.228 with SMTP id fn4mr1567820vdc.34.1385727584513; Fri, 29 Nov 2013 04:19:44 -0800 (PST) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id at8si24790421vec.84.2013.11.29.04.19.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 04:19:44 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.173 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.173; Received: by mail-vc0-f173.google.com with SMTP id ia6so6582188vcb.18 for ; Fri, 29 Nov 2013 04:19:44 -0800 (PST) X-Received: by 10.52.187.66 with SMTP id fq2mr26432vdc.93.1385727584430; Fri, 29 Nov 2013 04:19:44 -0800 (PST) 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.174.196 with SMTP id u4csp87381vcz; Fri, 29 Nov 2013 04:19:43 -0800 (PST) X-Received: by 10.236.42.10 with SMTP id i10mr1892281yhb.130.1385727583802; Fri, 29 Nov 2013 04:19:43 -0800 (PST) Received: from mail-yh0-f43.google.com (mail-yh0-f43.google.com [209.85.213.43]) by mx.google.com with ESMTPS id u24si36449642yhg.106.2013.11.29.04.19.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 04:19:43 -0800 (PST) Received-SPF: neutral (google.com: 209.85.213.43 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.213.43; Received: by mail-yh0-f43.google.com with SMTP id a41so6144878yho.16 for ; Fri, 29 Nov 2013 04:19:43 -0800 (PST) X-Received: by 10.236.127.132 with SMTP id d4mr449405yhi.184.1385727583619; Fri, 29 Nov 2013 04:19:43 -0800 (PST) Received: from localhost.localdomain (cpc15-aztw25-2-0-cust493.aztw.cable.virginm.net. [92.233.57.238]) by mx.google.com with ESMTPSA id m29sm101911689yho.14.2013.11.29.04.19.41 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 04:19:43 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dwmw2@infradead.org Cc: linus.walleij@linaro.org, linux-mtd@lists.infradead.org, angus.clark@st.com, Lee Jones Subject: [PATCH v3 04/36] mtd: st_spi_fsm: Supply framework for device requests Date: Fri, 29 Nov 2013 12:18:53 +0000 Message-Id: <1385727565-25794-5-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1385727565-25794-1-git-send-email-lee.jones@linaro.org> References: <1385727565-25794-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.173 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. Signed-off-by: Lee Jones --- drivers/mtd/devices/st_spi_fsm.c | 35 +++++++++++++++++++++++++++++++++++ drivers/mtd/devices/st_spi_fsm.h | 14 ++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index fe96b47..8ac8cd9 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -25,6 +25,11 @@ #include "st_spi_fsm.h" +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; @@ -46,6 +51,36 @@ 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 = STFSM_SEQ_SIZE / sizeof(uint32_t); + + BUG_ON(!stfsm_is_idle(fsm)); + + while (words--) { + writel(*src, dst); + src++; + dst += 4; + } +} + +static void stfsm_wait_seq(struct stfsm *fsm) +{ + unsigned long timeo = jiffies + HZ; + + while (time_before(jiffies, timeo)) { + 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; diff --git a/drivers/mtd/devices/st_spi_fsm.h b/drivers/mtd/devices/st_spi_fsm.h index 4e92e58..6164142 100644 --- a/drivers/mtd/devices/st_spi_fsm.h +++ b/drivers/mtd/devices/st_spi_fsm.h @@ -199,4 +199,18 @@ 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; +} __attribute__((__packed__, aligned(4))); +#define STFSM_SEQ_SIZE sizeof(struct stfsm_seq) + #endif /* ST_SPI_FSM_H */