From patchwork Fri Nov 29 12:18:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 21865 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f197.google.com (mail-ve0-f197.google.com [209.85.128.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EE6FB23FC4 for ; Fri, 29 Nov 2013 12:19:51 +0000 (UTC) Received: by mail-ve0-f197.google.com with SMTP id oz11sf23153759veb.4 for ; Fri, 29 Nov 2013 04:19:51 -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=W7d18tQ33A2dR1xqyiKgNeG+yvjGMcDh18tRjTHaz8M=; b=aS94gzDQ1IOncJ/uqf+K+KJOHCjfpbnMfovfJk8RSBdDfEKTi9Cxv5aLSzdijc6UHU 3kQLj7qL5m06rcL4ZBuHIA0Vfcx1zI7/o7WBuGgSFonqSgYc3xkBvPkjvUfZpNit4wQK XEElmzqTDPgoyABpaL7mBRk5vOygx7FKLgPEjYNOKqK/ONb75EEHr+k1jPRfdtM18sp8 3udRgjnxsvUrQqKlU4nXk13zsoOfNodUAMn9iJzCL2CDY0j+3l0kwUyLgWHZ+jQeRFZh SqWB/a01f2mnMipCuQogjxptdKkL+qvDvdKVEaa27V44jZ6ptl/C3KBnddWhyN0k+bgG XFgA== X-Gm-Message-State: ALoCoQlqkbeDYJeRRj7MhO3Oc0aWBAfze0Pi+NEqy6lzy9d6bGeSziknapHo0dfYWFK7DPfoAd6/ X-Received: by 10.58.54.97 with SMTP id i1mr605583vep.40.1385727591802; Fri, 29 Nov 2013 04:19:51 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.104.76 with SMTP id gc12ls1988251qeb.44.gmail; Fri, 29 Nov 2013 04:19:51 -0800 (PST) X-Received: by 10.220.252.71 with SMTP id mv7mr26195vcb.68.1385727591686; Fri, 29 Nov 2013 04:19:51 -0800 (PST) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id mh9si24794406vec.64.2013.11.29.04.19.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 04:19:51 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.178 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.178; Received: by mail-ve0-f178.google.com with SMTP id c14so7128727vea.9 for ; Fri, 29 Nov 2013 04:19:51 -0800 (PST) X-Received: by 10.52.35.41 with SMTP id e9mr30501vdj.79.1385727591618; Fri, 29 Nov 2013 04:19:51 -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 u4csp87393vcz; Fri, 29 Nov 2013 04:19:49 -0800 (PST) X-Received: by 10.224.148.9 with SMTP id n9mr11416016qav.32.1385727589639; Fri, 29 Nov 2013 04:19:49 -0800 (PST) Received: from mail-yh0-f44.google.com (mail-yh0-f44.google.com [209.85.213.44]) by mx.google.com with ESMTPS id b15si13699605qey.20.2013.11.29.04.19.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 04:19:49 -0800 (PST) Received-SPF: neutral (google.com: 209.85.213.44 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.213.44; Received: by mail-yh0-f44.google.com with SMTP id f64so6700613yha.3 for ; Fri, 29 Nov 2013 04:19:49 -0800 (PST) X-Received: by 10.236.74.73 with SMTP id w49mr1938915yhd.87.1385727589379; Fri, 29 Nov 2013 04:19:49 -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 m29sm101911689yho.14.2013.11.29.04.19.47 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 04:19:48 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dwmw2@infradead.org Cc: linus.walleij@linaro.org, linux-mtd@lists.infradead.org, angus.clark@st.com, Lee Jones Subject: [PATCH v3 07/36] mtd: st_spi_fsm: Add support for JEDEC ID extraction Date: Fri, 29 Nov 2013 12:18:56 +0000 Message-Id: <1385727565-25794-8-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1385727565-25794-1-git-send-email-lee.jones@linaro.org> References: <1385727565-25794-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.178 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. 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 05fa834..fe19ec3 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -25,6 +25,22 @@ #include "st_spi_fsm.h" +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; @@ -107,6 +123,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; @@ -243,6 +295,9 @@ static int stfsm_probe(struct platform_device *pdev) return ret; } + /* Detect SPI FLASH device */ + stfsm_jedec_probe(fsm); + platform_set_drvdata(pdev, fsm); fsm->mtd.dev.parent = &pdev->dev;