From patchwork Thu Jan 23 10:30:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 23575 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5F818218BD for ; Thu, 23 Jan 2014 10:31:51 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id rd3sf4047554pab.3 for ; Thu, 23 Jan 2014 02:31:50 -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=Oop5Y2Yn7E6HihAmjI6EkNMDRHUxcLvDifXlXA2J04A=; b=IKZZIqEMhsdu9VqJbVTtMJ/8ReOUZ/m1ZiIrW9ykZEhsJw/hj/D0BY+K2XJhu+OA52 yQ/knJYb78qRjMfXT3CDtb/G7UHGLH6LFD6tJfxoOLuloC4pZ8M9yghO+M1wRgdKpguY ijtj6sLtbV1nxcaGLeTM/NDWuprOo6BcqYqfLozO527mPVVz2NMSTWNNiK4uJlKoPlWe fIZ3LbWOcNT4o0y7Tp9YfjbD/ojH8G6Kpf+NtUik24GhiIKawTcHE9odoqOJclDvIg4d qiQQumptJEIplTwDoauML3qiZFvz3EmlAN0FQUHusWLCqINrO7hgS7pNBujE4PIt/eNo 1hLA== X-Gm-Message-State: ALoCoQnqjHdUFCj5m9Zisqx/z3TqCK6Jz9ILMSA99zvbAmn9F0n5dgPYEpkDYubhABPPajdDmHjT X-Received: by 10.67.14.70 with SMTP id fe6mr2636055pad.15.1390473110650; Thu, 23 Jan 2014 02:31:50 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.128.135 with SMTP id no7ls312047qeb.65.gmail; Thu, 23 Jan 2014 02:31:50 -0800 (PST) X-Received: by 10.221.34.211 with SMTP id st19mr4118954vcb.5.1390473110515; Thu, 23 Jan 2014 02:31:50 -0800 (PST) Received: from mail-vb0-f45.google.com (mail-vb0-f45.google.com [209.85.212.45]) by mx.google.com with ESMTPS id xt2si6431907vcb.33.2014.01.23.02.31.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 02:31:50 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.45 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.45; Received: by mail-vb0-f45.google.com with SMTP id m10so943790vbh.32 for ; Thu, 23 Jan 2014 02:31:50 -0800 (PST) X-Received: by 10.221.54.65 with SMTP id vt1mr50016vcb.46.1390473110436; Thu, 23 Jan 2014 02:31:50 -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 u4csp15906vcz; Thu, 23 Jan 2014 02:31:49 -0800 (PST) X-Received: by 10.180.206.172 with SMTP id lp12mr7249032wic.46.1390473109491; Thu, 23 Jan 2014 02:31:49 -0800 (PST) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by mx.google.com with ESMTPS id ep1si8898606wib.30.2014.01.23.02.31.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 02:31:49 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.178 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.178; Received: by mail-wi0-f178.google.com with SMTP id cc10so1583765wib.17 for ; Thu, 23 Jan 2014 02:31:49 -0800 (PST) X-Received: by 10.194.2.110 with SMTP id 14mr89998wjt.96.1390473109024; Thu, 23 Jan 2014 02:31:49 -0800 (PST) Received: from localhost.localdomain ([80.76.198.141]) by mx.google.com with ESMTPSA id ay6sm21257831wjb.23.2014.01.23.02.31.46 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 02:31:48 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: linus.walleij@linaro.org, dwmw2@infradead.org, linux-mtd@lists.infradead.org, computersforpeace@gmail.com, Angus.Clark@st.com, DCG_UPD_stlinux_kernel@list.st.com, olivier.clergeaud@st.com, Lee Jones Subject: [PATCH RESEND v4 04/37] mtd: st_spi_fsm: Supply framework for device requests Date: Thu, 23 Jan 2014 10:30:52 +0000 Message-Id: <1390473085-24626-5-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1390473085-24626-1-git-send-email-lee.jones@linaro.org> References: <1390473085-24626-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.212.45 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 | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index 5badbe4..c7daeca 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -204,6 +204,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 +243,37 @@ 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 timeo = jiffies + HZ; + + while (time_before(jiffies, timeo)) { + if (stfsm_is_idle(fsm)) + return; + + cond_resched(); + } + + if (!stfsm_is_idle(fsm)) + dev_err(fsm->dev, "timeout on sequence completion\n"); +} + static int stfsm_set_mode(struct stfsm *fsm, uint32_t mode) { int ret, timeout = 10;