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 A271DC433EF for ; Thu, 3 Mar 2022 06:29:08 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1DDC683D17; Thu, 3 Mar 2022 07:29:01 +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="AuRZ+PAJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1CACC83D1E; Thu, 3 Mar 2022 07:28:58 +0100 (CET) Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) (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 233C183B9F for ; Thu, 3 Mar 2022 07:28:52 +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-pg1-x536.google.com with SMTP id w37so3682942pga.7 for ; Wed, 02 Mar 2022 22:28:52 -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=jwcSZn9XX/aIEnCGIwznV7NjmtRekXZ6qwVE3Quh2HE=; b=AuRZ+PAJ3g6qDa1mIOJ5jG4DkrZG9Kd58GlcCZxmuQ+4+FYHT72/bJEh6Aaadlo9DA jv736hr8jzRY5mSG/sFvSf7jdujw/JJoJZJruyxkBQGlgkkQR1qj8Oe9OBWMV7Vl+sH2 GhmUdWaqMjGVVuTRKI4Wyt/KAjSexPObe0YBadGw8ccJZf4YnsIStHvZUMFLZRDb3CFj AV5A1J/VpFFGBbA2rQ0AHKuWsBWXQVPicgGaPU3vZ089rMzJfbI2kIY6EjureZaEGi33 k9a9IDNrkYVA2ErNSJmM/kHDMdXyVVyEa1nwlDrCEkvB0BvWFUTy810iK74Y40VHGlxI ekjw== 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=jwcSZn9XX/aIEnCGIwznV7NjmtRekXZ6qwVE3Quh2HE=; b=QRNWus/6tGfl/A7csBmbvR06rqb+7JWt+tRD+gyJCGiivImfj1uyzpbh8cGUq+1Rgf 1lygaFjSnuuMDZBvTAMgr3+pfkux0+ZQVDdVfJDZZcA/MCzwFE3oqV3X0kWmCUb1j5nV GZjp/r6RmFzY1io3Q/i2jYV+pz66Odk+A80jwFnjpCauVlHGE70qE5MEk0YnQi22bZfW Ebs15UT+ncI7zH7C6R4Vfn01A0+82/kJaxGQ/toUc0JgkIh6cL//Jmb0lLODFFUXbndB E6mIKJEEwO/1c9+4kmCQLNn5z7WykPbm7hBhKLDpdOuiqevDm0M+++eAWwgwZCbWZTX8 43Lw== X-Gm-Message-State: AOAM533a/iCwTb3cwepA8BZUEWQ+eQlE0NjcVs2ux5XasC3Krs+slO2m l1c7s0CKKOzEsqnr782W5PRuBq7VDdY= X-Google-Smtp-Source: ABdhPJxmfWFDw2kmCXOAQRUddGPUjO5G0L+Ny1MujSY39Bpx3Hbnttc4wxriseDS9sMuiEntGjQGjg== X-Received: by 2002:a05:6a00:1747:b0:4f3:e449:4416 with SMTP id j7-20020a056a00174700b004f3e4494416mr28517534pfc.5.1646288930206; Wed, 02 Mar 2022 22:28:50 -0800 (PST) Received: from localhost.localdomain ([123.51.145.88]) by smtp.gmail.com with ESMTPSA id b21-20020a056a000cd500b004e1e0d3ed18sm1167904pfv.2.2022.03.02.22.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 22:28:49 -0800 (PST) From: JaimeLiao To: u-boot@lists.denx.de, jagan@amarulasolutions.com, vigneshr@ti.com, miquel.raynal@bootlin.com Cc: zhengxunli@mxic.com.tw, p.yadav@ti.com, tudor.ambarus@microchip.com, jaimeliao@mxic.com.tw, JaimeLiao Subject: [PATCH v7 1/4] mtd: spi-nor: add support for Macronix Octal flash Date: Thu, 3 Mar 2022 14:28:24 +0800 Message-Id: <20220303062827.26664-2-jaimeliao.tw@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220303062827.26664-1-jaimeliao.tw@gmail.com> References: <20220303062827.26664-1-jaimeliao.tw@gmail.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean Follow patch (Allow using Micron mt35xu512aba in Octal DTR mode). Enable Octal DTR mode with 20 dummy cycles to allow running at the maximum supported frequency for adding Macronix flash in Octal DTR mode. -https://www.mxic.com.tw/Lists/Datasheet/Attachments/7841/MX25LM51245G,%203V,%20512Mb,%20v1.1.pdf Signed-off-by: JaimeLiao --- drivers/mtd/spi/spi-nor-core.c | 82 ++++++++++++++++++++++++++++++++++ include/linux/mtd/spi-nor.h | 12 ++++- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index d5d905fa5a..72250a83d1 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -3489,6 +3489,84 @@ static struct spi_nor_fixups mt35xu512aba_fixups = { }; #endif /* CONFIG_SPI_FLASH_MT35XU */ +#if CONFIG_IS_ENABLED(SPI_FLASH_MACRONIX) +/** + * spi_nor_macronix_octal_dtr_enable() - Enable octal DTR on Macronix flashes. + * @nor: pointer to a 'struct spi_nor' + * + * Set Macronix max dummy cycles 20 to allow the flash to run at fastest frequency. + * + * Return: 0 on success, -errno otherwise. + */ +static int spi_nor_macronix_octal_dtr_enable(struct spi_nor *nor) +{ + struct spi_mem_op op; + int ret; + u8 buf; + + ret = write_enable(nor); + if (ret) + return ret; + + buf = SPINOR_REG_MXIC_DC_20; + op = (struct spi_mem_op) + SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WR_CR2, 1), + SPI_MEM_OP_ADDR(4, SPINOR_REG_MXIC_CR2_DC, 1), + SPI_MEM_OP_NO_DUMMY, + SPI_MEM_OP_DATA_OUT(1, &buf, 1)); + + ret = spi_mem_exec_op(nor->spi, &op); + if (ret) + return ret; + + ret = spi_nor_wait_till_ready(nor); + if (ret) + return ret; + + nor->read_dummy = MXIC_MAX_DC; + ret = write_enable(nor); + if (ret) + return ret; + + buf = SPINOR_REG_MXIC_OPI_DTR_EN; + op = (struct spi_mem_op) + SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WR_CR2, 1), + SPI_MEM_OP_ADDR(4, SPINOR_REG_MXIC_CR2_MODE, 1), + SPI_MEM_OP_NO_DUMMY, + SPI_MEM_OP_DATA_OUT(1, &buf, 1)); + + ret = spi_mem_exec_op(nor->spi, &op); + if (ret) { + dev_err(nor->dev, "Failed to enable octal DTR mode\n"); + return ret; + } + nor->reg_proto = SNOR_PROTO_8_8_8_DTR; + + return 0; +} + +static void macronix_octal_default_init(struct spi_nor *nor) +{ + nor->octal_dtr_enable = spi_nor_macronix_octal_dtr_enable; +} + +static void macronix_octal_post_sfdp_fixup(struct spi_nor *nor, + struct spi_nor_flash_parameter *params) +{ + /* + * Adding SNOR_HWCAPS_PP_8_8_8_DTR in hwcaps.mask when + * SPI_NOR_OCTAL_DTR_READ flag exists. + */ + if (params->hwcaps.mask & SNOR_HWCAPS_READ_8_8_8_DTR) + params->hwcaps.mask |= SNOR_HWCAPS_PP_8_8_8_DTR; +} + +static struct spi_nor_fixups macronix_octal_fixups = { + .default_init = macronix_octal_default_init, + .post_sfdp = macronix_octal_post_sfdp_fixup, +}; +#endif /* CONFIG_SPI_FLASH_MACRONIX */ + /** spi_nor_octal_dtr_enable() - enable Octal DTR I/O if needed * @nor: pointer to a 'struct spi_nor' * @@ -3655,6 +3733,10 @@ void spi_nor_set_fixups(struct spi_nor *nor) if (!strcmp(nor->info->name, "mt35xu512aba")) nor->fixups = &mt35xu512aba_fixups; #endif + +#if CONFIG_IS_ENABLED(SPI_FLASH_MACRONIX) + nor->fixups = ¯onix_octal_fixups; +#endif /* SPI_FLASH_MACRONIX */ } int spi_nor_scan(struct spi_nor *nor) diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 7ddc4ba2bf..8682368f2f 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -116,8 +116,16 @@ #define XSR_RDY BIT(7) /* Ready */ /* Used for Macronix and Winbond flashes. */ -#define SPINOR_OP_EN4B 0xb7 /* Enter 4-byte mode */ -#define SPINOR_OP_EX4B 0xe9 /* Exit 4-byte mode */ +#define SPINOR_OP_EN4B 0xb7 /* Enter 4-byte mode */ +#define SPINOR_OP_EX4B 0xe9 /* Exit 4-byte mode */ +#define SPINOR_OP_RD_CR2 0x71 /* Read configuration register 2 */ +#define SPINOR_OP_WR_CR2 0x72 /* Write configuration register 2 */ +#define SPINOR_OP_MXIC_DTR_RD 0xee /* Fast Read opcode in DTR mode */ +#define SPINOR_REG_MXIC_CR2_MODE 0x00000000 /* For setting octal DTR mode */ +#define SPINOR_REG_MXIC_OPI_DTR_EN 0x2 /* Enable Octal DTR */ +#define SPINOR_REG_MXIC_CR2_DC 0x00000300 /* For setting dummy cycles */ +#define SPINOR_REG_MXIC_DC_20 0x0 /* Setting dummy cycles to 20 */ +#define MXIC_MAX_DC 20 /* Maximum value of dummy cycles */ /* Used for Spansion flashes only. */ #define SPINOR_OP_BRWR 0x17 /* Bank register write */ -- 2.17.1