From patchwork Fri Nov 22 16:22:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 21684 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 897B623FDC for ; Fri, 22 Nov 2013 16:23:31 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id i17sf1723636qcy.10 for ; Fri, 22 Nov 2013 08:23:31 -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=j7Rs0ymi2PRS6ZFN9Dkm7LVLvVB1hYpfUhJKSS1Tf8g=; b=Rxl8M2A2Og6jPu5+a2rW5jRmJyD10Cem/5fhh8LEqYUC/gWQUt5j01owoj373HeyKS KylgvgZF2chHOzKFKchMKEwT1QPfa86hDBiNeARFdn2AWcdQanOChxvX0DnJe9kH/acj Sj6yLDNV4if2EjyHJ2PF2c2RRCr1izNBhyo5C62EJc8mU0bwT0iAhZg7VYMUXogOf0kI U6VRmuYO9O8Qm6erlGvmod99IUROtwXAR21sGO2d21BGzEkNXnqoBe2oFUNYQ3UiYxGu HD/xhw37gvb22a8HuzPbVkfRqGkF/W2z3juKPkQYX9g5Lg3ozmbcFG8HdqHHfSysEy4s dk0g== X-Gm-Message-State: ALoCoQlX6BoidhFZwWBomqARf0JcyMYjh0ixllPm58TlfSJ34swKy9eX8zR/oz5lTlCDFk1cTYh7 X-Received: by 10.236.90.67 with SMTP id d43mr6457436yhf.36.1385137411383; Fri, 22 Nov 2013 08:23:31 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.120.5 with SMTP id ky5ls1072131qeb.26.gmail; Fri, 22 Nov 2013 08:23:31 -0800 (PST) X-Received: by 10.58.133.77 with SMTP id pa13mr12106185veb.21.1385137411267; Fri, 22 Nov 2013 08:23:31 -0800 (PST) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id z8si12891956vcu.47.2013.11.22.08.23.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Nov 2013 08:23:31 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.177 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.177; Received: by mail-vc0-f177.google.com with SMTP id hv10so977035vcb.36 for ; Fri, 22 Nov 2013 08:23:31 -0800 (PST) X-Received: by 10.52.30.19 with SMTP id o19mr1852940vdh.35.1385137411186; Fri, 22 Nov 2013 08:23:31 -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 u4csp51491vcz; Fri, 22 Nov 2013 08:23:30 -0800 (PST) X-Received: by 10.68.221.233 with SMTP id qh9mr3632682pbc.103.1385137410305; Fri, 22 Nov 2013 08:23:30 -0800 (PST) Received: from mail-pb0-f49.google.com (mail-pb0-f49.google.com [209.85.160.49]) by mx.google.com with ESMTPS id il5si4909554pbb.174.2013.11.22.08.23.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Nov 2013 08:23:30 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.49 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.160.49; Received: by mail-pb0-f49.google.com with SMTP id jt11so1482735pbb.8 for ; Fri, 22 Nov 2013 08:23:29 -0800 (PST) X-Received: by 10.66.248.227 with SMTP id yp3mr13108536pac.116.1385137409903; Fri, 22 Nov 2013 08:23:29 -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 qz9sm52962938pbc.3.2013.11.22.08.23.27 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Nov 2013 08:23:29 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dwmw2@infradead.org, linux-mtd@lists.infradead.org, angus.clark@st.com Cc: linus.walleij@linaro.org, Lee Jones Subject: [PATCH 04/23] mtd: st_spi_fsm: Supply framework for device requests Date: Fri, 22 Nov 2013 16:22:41 +0000 Message-Id: <1385137380-28968-5-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1385137380-28968-1-git-send-email-lee.jones@linaro.org> References: <1385137380-28968-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.177 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..e671029 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -25,11 +25,46 @@ #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; } +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 void stfsm_clear_fifo(struct stfsm *fsm) { uint32_t avail; 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 */