From patchwork Wed Jan 8 13:46:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 22940 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 33CF5216D7 for ; Wed, 8 Jan 2014 13:48:30 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id kp14sf4505624pab.6 for ; Wed, 08 Jan 2014 05:48:29 -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=dn84xyzaqjqiolJzyuLaf9GiCgzJHS/hFsICM36tLcm+Os/RcIsPKvQcE9UHbq2KTN S/jJwfgQOYZghg+Pt4Q+Y/VTe6XgjUZuvPet7gW/xoOKCTrvn37YM7S0FPPz6HZAo39D q7V1mOMXUk6muKQLTgu5eMJE48AHh1kzIcs44TdHDHZD8cnvfJS7qmlepAC8WK/FVQ51 t1wweF4XjA9Nsq/sfYfoPbEAE/WY2LpStiFW0goNh66DS7LZdxHeVDTPPgHtjgEyQwp0 K0jV9QkmcccaYBi6JZAQmjageqTqk2xn97upI93DKrD0S+QqGa5UYPR1hDhvDpgD4GqE D+Kw== X-Gm-Message-State: ALoCoQnxotwquW0ofd/AmGBEmpvfPqlz8CMWmIWc0VFq2mJX8Cm9/d+ZZ9GRgA4HAgqRAHRjz3fM X-Received: by 10.68.254.230 with SMTP id al6mr50560377pbd.6.1389188909483; Wed, 08 Jan 2014 05:48:29 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.106.102 with SMTP id gt6ls577654qeb.78.gmail; Wed, 08 Jan 2014 05:48:29 -0800 (PST) X-Received: by 10.52.163.65 with SMTP id yg1mr66760925vdb.14.1389188909375; Wed, 08 Jan 2014 05:48:29 -0800 (PST) Received: from mail-vb0-f43.google.com (mail-vb0-f43.google.com [209.85.212.43]) by mx.google.com with ESMTPS id sg4si621525vdc.1.2014.01.08.05.48.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Jan 2014 05:48:29 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.43 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.43; Received: by mail-vb0-f43.google.com with SMTP id p6so1145543vbe.16 for ; Wed, 08 Jan 2014 05:48:29 -0800 (PST) X-Received: by 10.58.152.130 with SMTP id uy2mr1938453veb.71.1389188909271; Wed, 08 Jan 2014 05:48:29 -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.59.13.131 with SMTP id ey3csp226589ved; Wed, 8 Jan 2014 05:48:28 -0800 (PST) X-Received: by 10.194.92.7 with SMTP id ci7mr2446279wjb.58.1389188907430; Wed, 08 Jan 2014 05:48:27 -0800 (PST) Received: from mail-we0-f172.google.com (mail-we0-f172.google.com [74.125.82.172]) by mx.google.com with ESMTPS id md15si2582079wic.62.2014.01.08.05.48.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Jan 2014 05:48:27 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.172 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.172; Received: by mail-we0-f172.google.com with SMTP id p61so1479748wes.3 for ; Wed, 08 Jan 2014 05:48:27 -0800 (PST) X-Received: by 10.194.235.230 with SMTP id up6mr81324171wjc.30.1389188907030; Wed, 08 Jan 2014 05:48:27 -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 j9sm48125217wjx.18.2014.01.08.05.48.25 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Jan 2014 05:48:26 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: computersforpeace@gmail.com, angus.clark@st.com, Lee Jones Subject: [PATCH v4 04/37] mtd: st_spi_fsm: Supply framework for device requests Date: Wed, 8 Jan 2014 13:46:47 +0000 Message-Id: <1389188840-14306-5-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1389188840-14306-1-git-send-email-lee.jones@linaro.org> References: <1389188840-14306-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.43 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;