From patchwork Thu Jan 23 10:30:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 313558 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D72142C0082 for ; Thu, 23 Jan 2014 22:26:51 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W6Hco-0006fs-47; Thu, 23 Jan 2014 10:35:07 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W6Hc7-0003Ma-H2; Thu, 23 Jan 2014 10:34:23 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W6HaK-00032H-68 for linux-mtd@merlin.infradead.org; Thu, 23 Jan 2014 10:32:32 +0000 Received: from mail-wg0-f43.google.com ([74.125.82.43]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W6Ha7-0004fG-3s for linux-mtd@lists.infradead.org; Thu, 23 Jan 2014 10:32:24 +0000 Received: by mail-wg0-f43.google.com with SMTP id y10so1278410wgg.22 for ; Thu, 23 Jan 2014 02:31:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VDd5dHU48zoEKPc+RMAfIJfdplrvRYQ03I4FF9JQMfk=; b=Ir6y4mFiqNUm1rC3fshF2soth3KD96rl/FMO/coKDA9TE4UeT5RRsOjfrPaTO6vURP bgmAx2KGPSFxUfnQYYvfVjEFpk5WYc8FdSUDAPKGcC5BtVR35bpJW/3v3G/FZhlBqR4R +9W6V9YVmD9BuxGMrPK2mlGkzpZpFqR3m605QgG260g33yQbPkWvQeTKhatwX/FeC4TU bMOwybFVjvA859EsbJY8yhWdp6FE82f61/gTG7HrLd50uRemfNeDuAE9VXKEiKFfYeX4 AWNBtn3dYD57Cu6b8j0voHLz5x/SSZM5WUmf6omPJq0gUOECAxldAPfcTHDaAJuffVLd caFA== X-Gm-Message-State: ALoCoQnVwGYcHDzk7ff5fI9VCT16trwPrypc6Ku/BRoZrUQJVb5fLA/fb6tX416VSKFEt+TX4m+P X-Received: by 10.194.2.70 with SMTP id 6mr5980356wjs.25.1390473117530; Thu, 23 Jan 2014 02:31:57 -0800 (PST) Received: from localhost.localdomain ([80.76.198.141]) by mx.google.com with ESMTPSA id ay6sm21257831wjb.23.2014.01.23.02.31.54 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 02:31:56 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND v4 07/37] mtd: st_spi_fsm: Add support for JEDEC ID extraction Date: Thu, 23 Jan 2014 10:30:55 +0000 Message-Id: <1390473085-24626-8-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1390473085-24626-1-git-send-email-lee.jones@linaro.org> References: <1390473085-24626-1-git-send-email-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140123_103219_395334_C2FD0350 X-CRM114-Status: GOOD ( 14.42 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.2 on casper.infradead.org summary: Content analysis details: (-0.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.43 listed in list.dnswl.org] Cc: olivier.clergeaud@st.com, Angus.Clark@st.com, Lee Jones , linus.walleij@linaro.org, linux-mtd@lists.infradead.org, computersforpeace@gmail.com, dwmw2@infradead.org, DCG_UPD_stlinux_kernel@list.st.com X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 bb0f20a..8a10f16 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -255,6 +255,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; @@ -338,6 +354,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; @@ -474,6 +526,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;