Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5A095C433EF for ; Wed, 29 Dec 2021 05:57:16 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 10E8E8342C; Wed, 29 Dec 2021 06:56:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="VaWxNvzn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 768CF8307C; Wed, 29 Dec 2021 06:56:44 +0100 (CET) Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3D38B830D5 for ; Wed, 29 Dec 2021 06:56:39 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jaimeliao.tw@gmail.com Received: by mail-pj1-x1034.google.com with SMTP id x1-20020a17090a2b0100b001b103e48cfaso14099613pjc.0 for ; Tue, 28 Dec 2021 21:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TvXDu5sfTDto3Ui2+qs1YcZE8MoIHW4ZLPxkM3Eo+4Q=; b=VaWxNvznh0hAvzY1c7UszmPTFH/wiDyKSUbVfCe3jQMhylUyZqgGTuz5S2PBWHaP/u wn271Aw4EZiMYe64fRtg4DNbGd3hLPvRj1p6KLrnVOvGmlKNc0JYWyzjoMNs/kv6mYX8 kVvF4qo0DYv18CdMiLO3Okql5vW7XSTTd56ulIhID4KMVgfuR+h59N7hzBkfQId+mOTg VEs+0wn/9IAbRkU4f/v7l2iVRSuuywCPuBWn+tFjalkBfQTwFJCNZhq1Z4c0iqbiR6LL pqc3pCVCq+qWAqkNmO05wepU2pe66akqylarxe7kl2Zxnu4BTCNzt1WYaf60toE8GKr1 Fssw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TvXDu5sfTDto3Ui2+qs1YcZE8MoIHW4ZLPxkM3Eo+4Q=; b=RqjT7R15WsfVFZPIRGpaPdQbjar9ba6BWE1XfJQ0+Vk+LVWLjVCu0mb71UympP7GXW SkfumjsI3G57TH1b6VrLLYWfV1s8BbxIDrpS1mImqlqMtlJzPi5T1mfQ9COshxGU6+cl SidbC7aruAyf+1UZJoyslN00Fc4yVzZ/+VxYpX5MNhYmAbaMXZHK9HxCP5FYtQbE+MiQ zMqk9olYEGaeZY9334/7DIHi7yLE2IPgoXjCt4Ep9tTZVK5RA1iGcsHQqZZ1gneH4sx9 KttUMaUiHqur6R0NRWFgAgltX86CkpyInILhS/bN7wHD8Fkx+mX72w2KkC9zsWUGSp+5 YKzQ== X-Gm-Message-State: AOAM530YlFAn6Ar+HY63na/11m+lr4AWDfG9n3LNkbPM8jofl7HdvUE1 bw2gfinxIUjHEmAAK4uPgXMYgPzMFZ0= X-Google-Smtp-Source: ABdhPJzeQzA6VOezR5WLQGcQ5EObahajOuNVn844w35U9KRU77+Va21YKNbGmkjrwI3nWTOl2NT5Rg== X-Received: by 2002:a17:902:c652:b0:148:f1a5:b7c6 with SMTP id s18-20020a170902c65200b00148f1a5b7c6mr25385697pls.30.1640757397525; Tue, 28 Dec 2021 21:56:37 -0800 (PST) Received: from localhost.localdomain ([123.51.145.88]) by smtp.gmail.com with ESMTPSA id oa9sm22156096pjb.31.2021.12.28.21.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Dec 2021 21:56:37 -0800 (PST) From: JaimeLiao To: u-boot@lists.denx.de, jagan@amarulasoutions.com, vigneshr@ti.com, miquel.raynal@bootlin.com Cc: zhengxunli@mxic.com.tw, jaimeliao@mxic.com.tw, JaimeLiao Subject: [PATCH v6 4/4] mtd: spi-nor: Parse SFDP SCCR Map Date: Wed, 29 Dec 2021 13:56:20 +0800 Message-Id: <20211229055620.1466-5-jaimeliao.tw@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211229055620.1466-1-jaimeliao.tw@gmail.com> References: <20211229055620.1466-1-jaimeliao.tw@gmail.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Parse SCCR 22nd dword and check DTR Octal Mode Enable Volatile bit for Octal DTR enable Signed-off-by: JaimeLiao --- drivers/mtd/spi/spi-nor-core.c | 52 ++++++++++++++++++++++++++++++++++ include/linux/mtd/spi-nor.h | 1 + 2 files changed, 53 insertions(+) diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index 2b6947cefc..14c33aea10 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -63,6 +63,10 @@ struct sfdp_parameter_header { #define SFDP_SECTOR_MAP_ID 0xff81 /* Sector Map Table */ #define SFDP_SST_ID 0x01bf /* Manufacturer specific Table */ #define SFDP_PROFILE1_ID 0xff05 /* xSPI Profile 1.0 Table */ +#define SFDP_SCCR_MAP_ID 0xff87 /* + * Status, Control and Configuration + * Register Map. + */ #define SFDP_SIGNATURE 0x50444653U #define SFDP_JESD216_MAJOR 1 @@ -172,6 +176,9 @@ struct sfdp_header { #define PROFILE1_DWORD5_DUMMY_100MHZ GENMASK(11, 7) #define PROFILE1_DUMMY_DEFAULT 20 +/* Status, Control and Configuration Register Map(SCCR) */ +#define SCCR_DWORD22_OCTAL_DTR_EN_VOLATILE BIT(31) + struct sfdp_bfpt { u32 dwords[BFPT_DWORD_MAX]; }; @@ -2434,6 +2441,45 @@ out: return ret; } +/** + * spi_nor_parse_sccr() - Parse the Status, Control and Configuration Register + * Map. + * @nor: pointer to a 'struct spi_nor' + * @sccr_header: pointer to the 'struct sfdp_parameter_header' describing + * the SCCR Map table length and version. + * + * Return: 0 on success, -errno otherwise. + */ +static int spi_nor_parse_sccr(struct spi_nor *nor, + const struct sfdp_parameter_header *sccr_header) +{ + u32 *table, opcode, addr; + size_t len; + int ret, i; + u8 dummy; + + len = sccr_header->length * sizeof(*table); + table = kmalloc(len, GFP_KERNEL); + if (!table) + return -ENOMEM; + + addr = SFDP_PARAM_HEADER_PTP(sccr_header); + ret = spi_nor_read_sfdp(nor, addr, len, table); + if (ret) + goto out; + + /* Fix endianness of the table DWORDs. */ + for (i = 0; i < sccr_header->length; i++) + table[i] = le32_to_cpu(table[i]); + + if (FIELD_GET(SCCR_DWORD22_OCTAL_DTR_EN_VOLATILE, table[22])) + nor->flags |= SNOR_F_IO_MODE_EN_VOLATILE; + +out: + kfree(table); + return ret; +} + /** * spi_nor_parse_sfdp() - parse the Serial Flash Discoverable Parameters. * @nor: pointer to a 'struct spi_nor' @@ -2539,6 +2585,9 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor, case SFDP_PROFILE1_ID: err = spi_nor_parse_profile1(nor, param_header, params); break; + case SFDP_SCCR_MAP_ID: + err = spi_nor_parse_sccr(nor, param_header); + break; default: break; @@ -3584,6 +3633,9 @@ static int spi_nor_octal_dtr_enable(struct spi_nor *nor) nor->write_proto == SNOR_PROTO_8_8_8_DTR)) return 0; + if (!(nor->flags & SNOR_F_IO_MODE_EN_VOLATILE)) + return 0; + ret = nor->octal_dtr_enable(nor); if (ret) return ret; diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 8682368f2f..10c7b6e4c3 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -287,6 +287,7 @@ enum spi_nor_option_flags { SNOR_F_USE_CLSR = BIT(5), SNOR_F_BROKEN_RESET = BIT(6), SNOR_F_SOFT_RESET = BIT(7), + SNOR_F_IO_MODE_EN_VOLATILE = BIT(8), }; struct spi_nor; -- 2.17.1