From patchwork Thu Mar 20 09:20:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 26639 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f198.google.com (mail-vc0-f198.google.com [209.85.220.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3730F202E0 for ; Thu, 20 Mar 2014 09:21:31 +0000 (UTC) Received: by mail-vc0-f198.google.com with SMTP id il7sf1424831vcb.5 for ; Thu, 20 Mar 2014 02:21:30 -0700 (PDT) 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=GItIyLjpo2t0SJy/50LykJYrAh00yvDSTGSJlT36MG0=; b=gXdGhH2FuquROOr/LR7aW+o429ndh1F2H8MDLuWjJd+X6AKxBk1T4Cx1F21mRr3WrU BL/GJ3rdEuN4mtDwtUYUIWoxBbQbLINbQfAE5y2vsbxVAZJN1CsXiS7jV/sabUpq7q76 UKYdULWwHpXPMSihIGEHMlsQxD/j9cnSawm0bnHYMYPJ+9Iw45zPi+o042GBEJJe+RMY 7XC334OyVUt2ZdOoT7O432CmW3BYHqUnOcPV+Ztfi2ipZbVFETT0Cc2Qog24zMxFOvNa Ou1sto4XSxcTV0edrW0Wksqn0EhibnoVD2v/MDNviuypfyhAvY71GzBvA59GJvirWjuE RWPA== X-Gm-Message-State: ALoCoQn2xhXH5UVlxqdrxEXs3WyF6mjBRcyRV/qYGXrTmnl06aPgXR93ybsC5TCm6pf/R4SRVJA2 X-Received: by 10.236.92.15 with SMTP id i15mr1788778yhf.8.1395307290926; Thu, 20 Mar 2014 02:21:30 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.34.36 with SMTP id k33ls176048qgk.20.gmail; Thu, 20 Mar 2014 02:21:30 -0700 (PDT) X-Received: by 10.52.139.237 with SMTP id rb13mr3762574vdb.33.1395307290824; Thu, 20 Mar 2014 02:21:30 -0700 (PDT) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx.google.com with ESMTPS id vd8si297593vdc.142.2014.03.20.02.21.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Mar 2014 02:21:30 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.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.128.173; Received: by mail-ve0-f173.google.com with SMTP id oy12so596096veb.18 for ; Thu, 20 Mar 2014 02:21:30 -0700 (PDT) X-Received: by 10.220.139.198 with SMTP id f6mr36844vcu.47.1395307290750; Thu, 20 Mar 2014 02:21:30 -0700 (PDT) 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.78.9 with SMTP id i9csp372500vck; Thu, 20 Mar 2014 02:21:30 -0700 (PDT) X-Received: by 10.181.13.40 with SMTP id ev8mr1830090wid.0.1395307289437; Thu, 20 Mar 2014 02:21:29 -0700 (PDT) Received: from mail-wg0-f47.google.com (mail-wg0-f47.google.com [74.125.82.47]) by mx.google.com with ESMTPS id c4si863790wjb.13.2014.03.20.02.21.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Mar 2014 02:21:29 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.47 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.47; Received: by mail-wg0-f47.google.com with SMTP id x12so363727wgg.6 for ; Thu, 20 Mar 2014 02:21:28 -0700 (PDT) X-Received: by 10.180.37.178 with SMTP id z18mr1776807wij.46.1395307288876; Thu, 20 Mar 2014 02:21:28 -0700 (PDT) Received: from lee--X1.home (host109-148-116-196.range109-148.btcentralplus.com. [109.148.116.196]) by mx.google.com with ESMTPSA id di9sm4735120wid.6.2014.03.20.02.21.27 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Mar 2014 02:21:28 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, computersforpeace@gmail.com Cc: linux-mtd@lists.infradead.org, dwmw2@infradead.org, Angus.Clark@st.com, Lee Jones Subject: [PATCH v6 06/36] mtd: st_spi_fsm: Add support for JEDEC ID extraction Date: Thu, 20 Mar 2014 09:20:38 +0000 Message-Id: <1395307268-12721-7-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1395307268-12721-1-git-send-email-lee.jones@linaro.org> References: <1395307268-12721-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.128.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: , Once we start supporting devices it will be handy go detect them dynamically. This will be done using the chip's unique JEDEC ID. This patch allows us to extract a device's JEDEC ID using the a predefined FSM register write sequence. Acked-by Angus Clark Signed-off-by: Lee Jones --- drivers/mtd/devices/st_spi_fsm.c | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index 73e0f27..9fc0b19 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -219,6 +219,22 @@ struct stfsm_seq { uint32_t seq_cfg; } __packed __aligned(4); +static struct stfsm_seq stfsm_seq_read_jedec = { + .data_size = TRANSFER_SIZE(8), + .seq_opc[0] = (SEQ_OPC_PADS_1 | + SEQ_OPC_CYCLES(8) | + SEQ_OPC_OPCODE(FLASH_CMD_RDID)), + .seq = { + STFSM_INST_CMD1, + STFSM_INST_DATA_READ, + STFSM_INST_STOP, + }, + .seq_cfg = (SEQ_CFG_PADS_1 | + SEQ_CFG_READNOTWRITE | + SEQ_CFG_CSDEASSERT | + SEQ_CFG_STARTSEQ), +}; + static inline int stfsm_is_idle(struct stfsm *fsm) { return readl(fsm->base + SPI_FAST_SEQ_STA) & 0x10; @@ -307,6 +323,42 @@ static void stfsm_read_fifo(struct stfsm *fsm, uint32_t *buf, } } +static void stfsm_read_jedec(struct stfsm *fsm, uint8_t *const jedec) +{ + const struct stfsm_seq *seq = &stfsm_seq_read_jedec; + uint32_t tmp[2]; + + stfsm_load_seq(fsm, seq); + + stfsm_read_fifo(fsm, tmp, 8); + + memcpy(jedec, tmp, 5); + + stfsm_wait_seq(fsm); +} + +static struct flash_info *stfsm_jedec_probe(struct stfsm *fsm) +{ + u16 ext_jedec; + u32 jedec; + u8 id[5]; + + stfsm_read_jedec(fsm, id); + + jedec = id[0] << 16 | id[1] << 8 | id[2]; + /* + * JEDEC also defines an optional "extended device information" + * string for after vendor-specific data, after the three bytes + * we use here. Supporting some chips might require using it. + */ + ext_jedec = id[3] << 8 | id[4]; + + dev_dbg(fsm->dev, "JEDEC = 0x%08x [%02x %02x %02x %02x %02x]\n", + jedec, id[0], id[1], id[2], id[3], id[4]); + + return NULL; +} + static int stfsm_set_mode(struct stfsm *fsm, uint32_t mode) { int ret, timeout = 10; @@ -436,6 +488,9 @@ static int stfsm_probe(struct platform_device *pdev) return ret; } + /* Detect SPI FLASH device */ + stfsm_jedec_probe(fsm); + fsm->mtd.dev.parent = &pdev->dev; fsm->mtd.type = MTD_NORFLASH; fsm->mtd.writesize = 4;