From patchwork Thu Nov 14 14:22:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 21504 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 219CB23FDD for ; Thu, 14 Nov 2013 14:23:09 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id qd12sf4478307ieb.0 for ; Thu, 14 Nov 2013 06:23:08 -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=eOd2D30GdzKA1zxaxc5hPgo0/D7z4h/xwmfkbG374Gs=; b=Ek1ns8NAlna84bj+71h2Xfs6UNjJffPhKjBw7ilcTNaPDa/9xL5Ug++0UEQrO8Pd6J IfhwKsiSE2+MBTIGs9l0jS7OVl2twqgUHWFYuC9J/z62EluL7+EjKREysPyWR7fSpLlX 2wK7tZIEMkdFemIvC0MTAJQU49foSbHT/Bxiw+MFWas6ieiqyVX9OdZ9JMNAoP+V/xhw qE5C1pscHw8vw8rXBvbs82Ujn+2q5I7Zc0fSya0zRJdPVNHf/t7NFzOOZEFFU+ZRVUDY PJXXvz6ABjINq/YYUt1twD80gSodIz27zqLgFpxyTgMIVXwOKyIzaqEBXiRKdD0UqryV uebA== X-Gm-Message-State: ALoCoQn42UM9uLKtL4K0aKI2StE5SwxXNFFpLEBP6Z6Wjkfhuojt+ogYdtNtrkVMdull8svV+Z6N X-Received: by 10.182.109.137 with SMTP id hs9mr612780obb.21.1384438988821; Thu, 14 Nov 2013 06:23:08 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.99.10 with SMTP id em10ls999016qeb.82.gmail; Thu, 14 Nov 2013 06:23:08 -0800 (PST) X-Received: by 10.58.181.230 with SMTP id dz6mr336704vec.35.1384438988724; Thu, 14 Nov 2013 06:23:08 -0800 (PST) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id rw8si17146824vdc.70.2013.11.14.06.23.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Nov 2013 06:23:08 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.171 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.171; Received: by mail-ve0-f171.google.com with SMTP id cz12so1910234veb.16 for ; Thu, 14 Nov 2013 06:23:08 -0800 (PST) X-Received: by 10.58.54.69 with SMTP id h5mr931957vep.25.1384438988507; Thu, 14 Nov 2013 06:23:08 -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 u4csp319813vcz; Thu, 14 Nov 2013 06:23:08 -0800 (PST) X-Received: by 10.60.45.65 with SMTP id k1mr1675295oem.48.1384438987804; Thu, 14 Nov 2013 06:23:07 -0800 (PST) Received: from mail-ob0-f179.google.com (mail-ob0-f179.google.com [209.85.214.179]) by mx.google.com with ESMTPS id kg5si30445222oeb.128.2013.11.14.06.23.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Nov 2013 06:23:07 -0800 (PST) Received-SPF: neutral (google.com: 209.85.214.179 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.214.179; Received: by mail-ob0-f179.google.com with SMTP id wn1so2235785obc.10 for ; Thu, 14 Nov 2013 06:23:06 -0800 (PST) X-Received: by 10.182.129.201 with SMTP id ny9mr1718429obb.0.1384438986497; Thu, 14 Nov 2013 06:23:06 -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.23.04 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Nov 2013 06:23:06 -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 07/10] mtd: st_spi_fsm: Add support for JEDEC ID extraction Date: Thu, 14 Nov 2013 14:22:33 +0000 Message-Id: <1384438956-31153-8-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.128.171 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 | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index 6691eaf..2899e0f 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -92,6 +92,22 @@ struct stfsm_seq { } __attribute__((__packed__, aligned(4))); #define STFSM_SEQ_SIZE sizeof(struct stfsm_seq) +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; @@ -158,6 +174,50 @@ static void stfsm_read_fifo(struct stfsm *fsm, uint32_t *buf, } } +static int 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); + + return 0; +} + +static struct flash_info * stfsm_jedec_probe(struct stfsm *fsm) +{ + u16 ext_jedec; + u32 jedec; + u8 id[5]; + int ret; + + /* + * 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. + */ + + ret = stfsm_read_jedec(fsm, id); + if (ret) { + dev_info(fsm->dev, "Error reading JEDEC ID\n"); + return NULL; + } + + jedec = id[0] << 16 | id[1] << 8 | id[2]; + 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 void stfsm_clear_fifo(struct stfsm *fsm) { uint32_t avail; @@ -310,6 +370,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;