From patchwork Thu Nov 14 14:22:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 21501 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f70.google.com (mail-qe0-f70.google.com [209.85.128.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7119C23FE0 for ; Thu, 14 Nov 2013 14:23:01 +0000 (UTC) Received: by mail-qe0-f70.google.com with SMTP id 9sf654486qea.1 for ; Thu, 14 Nov 2013 06:23:01 -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=En/UT8foM0uSdWbjEA0F5mc/yjzH9okVcKF4+ft5bIE=; b=IEK1EbNyZ1i097xiaz5x0NKTLzRcAHRbIqGx1L4iOwRghL8ojH0i5krbeStV6gBJRY yf5dCOBrksSpw1hJAZUnMo2Rjkfrr8wbtDJ7kqIS9URTOb5BoOHb8U1xb8gN8Rac411I B+6UK8/jY9yWSX9VcwzUouXalurXbNQlyJ7m9KSN0BKZoEde4gab6opGRTO4+m8bISMZ yRBDExlzTSAt3ooehmZOFDtaBQJh/LqttC4ArO7kiq8Znqu1MVKAWygiIe4hWzvSbVay JxMM1RY2aUSBD3EYYScyDRibQmMmcQm1gXIkksKdalpylua64JjI0MBK7Hx2wO2fbofa UfYA== X-Gm-Message-State: ALoCoQmqdEGC8e0vqcWk2DK/JW6CBLR/nRrQWX31DU4tHLtZ5hYoyff67KqpxhYpj6AFlEu/1j/+ X-Received: by 10.236.141.139 with SMTP id g11mr930337yhj.9.1384438981138; Thu, 14 Nov 2013 06:23:01 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.35.111 with SMTP id g15ls961414qej.21.gmail; Thu, 14 Nov 2013 06:23:01 -0800 (PST) X-Received: by 10.220.144.80 with SMTP id y16mr1000112vcu.4.1384438981061; Thu, 14 Nov 2013 06:23:01 -0800 (PST) Received: from mail-vb0-f42.google.com (mail-vb0-f42.google.com [209.85.212.42]) by mx.google.com with ESMTPS id st7si17143120vdc.81.2013.11.14.06.23.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Nov 2013 06:23:01 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.42 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.42; Received: by mail-vb0-f42.google.com with SMTP id p14so1750937vbm.29 for ; Thu, 14 Nov 2013 06:23:01 -0800 (PST) X-Received: by 10.220.169.203 with SMTP id a11mr1005249vcz.26.1384438980959; Thu, 14 Nov 2013 06:23:00 -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 u4csp319806vcz; Thu, 14 Nov 2013 06:23:00 -0800 (PST) X-Received: by 10.182.149.168 with SMTP id ub8mr1664986obb.74.1384438980444; Thu, 14 Nov 2013 06:23:00 -0800 (PST) Received: from mail-oa0-f47.google.com (mail-oa0-f47.google.com [209.85.219.47]) by mx.google.com with ESMTPS id gb1si4477751obb.71.2013.11.14.06.23.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Nov 2013 06:23:00 -0800 (PST) Received-SPF: neutral (google.com: 209.85.219.47 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.219.47; Received: by mail-oa0-f47.google.com with SMTP id i7so2264424oag.6 for ; Thu, 14 Nov 2013 06:23:00 -0800 (PST) X-Received: by 10.182.66.78 with SMTP id d14mr1503210obt.99.1384438980133; Thu, 14 Nov 2013 06:23:00 -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 z5sm5585965obg.13.2013.11.14.06.22.58 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Nov 2013 06:22:59 -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, angus.clark@st.com, Lee Jones Subject: [PATCH 04/10] mtd: st_spi_fsm: Supply framework for device requests Date: Thu, 14 Nov 2013 14:22:30 +0000 Message-Id: <1384438956-31153-5-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1384438956-31153-1-git-send-email-lee.jones@linaro.org> References: <1384438956-31153-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.42 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 f560343..02619ee 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -40,11 +40,60 @@ 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) + +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;