From nobody Thu Nov 28 21:48:53 2024 Received: from chessie.everett.org (chessie.fmt1.pfcs.com [66.220.13.234]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24F1914F126; Thu, 26 Sep 2024 15:52:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.220.13.234 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727365926; cv=none; b=YNaVgz03IMudE9PvMrbXZQ3NdqZYv3s3hTTu8bn8u9fcbpjZkxSRpHzJvRIDH21tjkAczroAxHrcFxIA04btBJObXb3Vv5bkYyHKNvJUcUyJC9d2ZFhzuin+tZyt/vASmxaJ6Ct+YeVy6DjVyDxQI9o2vk3g+zSNnK6yxCP2CUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727365926; c=relaxed/simple; bh=Qr/l+vZFdvyH7+K+qB1D2fBazVlpK6prp1qocN+hsnI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pUqapBAWVNiBeeYikOI5Xzfbv9cDroxoNGmViW5Z/xrzfKtT44GGKnWXluC7jEyvyhJjCxTAyjBMrb6ecFx71QijvvJxliqVNFbdekV9bBBdqa5c0hhPWOYutslIvdJ/73nyCumNhyEkCnpQFxjeBQzTHNipkRnYYujeLyIrMTI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=nwtime.org; spf=pass smtp.mailfrom=nwtime.org; arc=none smtp.client-ip=66.220.13.234 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=nwtime.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nwtime.org Received: from localhost.localdomain (ip-77-25-16-238.web.vodafone.de [77.25.16.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by chessie.everett.org (Postfix) with ESMTPSA id 4XDylB1SflzMRBN; Thu, 26 Sep 2024 15:51:50 +0000 (UTC) From: Erez Geva To: linux-mtd@lists.infradead.org, Tudor Ambarus , Pratyush Yadav , Michael Walle Cc: linux-kernel@vger.kernel.org, Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , Esben Haabendal , Erez Geva Subject: [PATCH v6 1/3] mtd: spi-nor: core: make OTP configuration dynamic Date: Thu, 26 Sep 2024 17:51:25 +0200 Message-Id: <20240926155127.2450246-2-erezgeva@nwtime.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240926155127.2450246-1-erezgeva@nwtime.org> References: <20240926155127.2450246-1-erezgeva@nwtime.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Erez Geva Currently the OTP configuration are constant in compile time. However in some situation we need to update or change the device OTP configuration dynamically on runtime. Signed-off-by: Erez Geva --- drivers/mtd/spi-nor/core.c | 4 +++- drivers/mtd/spi-nor/core.h | 2 +- drivers/mtd/spi-nor/otp.c | 6 +++--- drivers/mtd/spi-nor/winbond.c | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 9d6e85bf227b..1e7a64fd4b1a 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -2911,7 +2911,9 @@ static void spi_nor_init_default_params(struct spi_no= r *nor) struct device_node *np =3D spi_nor_get_flash_node(nor); =20 params->quad_enable =3D spi_nor_sr2_bit1_quad_enable; - params->otp.org =3D info->otp; + memset(¶ms->otp.org, 0, sizeof(struct spi_nor_otp_organization)); + if (info->otp) + memcpy(¶ms->otp.org, info->otp, sizeof(struct spi_nor_otp_organizati= on)); =20 /* Default to 16-bit Write Status (01h) Command */ nor->flags |=3D SNOR_F_HAS_16BIT_SR; diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index 1516b6d0dc37..b678cb8ae5a1 100644 --- a/drivers/mtd/spi-nor/core.h +++ b/drivers/mtd/spi-nor/core.h @@ -326,7 +326,7 @@ struct spi_nor_otp_ops { * @ops: OTP access ops */ struct spi_nor_otp { - const struct spi_nor_otp_organization *org; + struct spi_nor_otp_organization org; const struct spi_nor_otp_ops *ops; }; =20 diff --git a/drivers/mtd/spi-nor/otp.c b/drivers/mtd/spi-nor/otp.c index 9a729aa3452d..ffb7ffeb9030 100644 --- a/drivers/mtd/spi-nor/otp.c +++ b/drivers/mtd/spi-nor/otp.c @@ -11,8 +11,8 @@ =20 #include "core.h" =20 -#define spi_nor_otp_region_len(nor) ((nor)->params->otp.org->len) -#define spi_nor_otp_n_regions(nor) ((nor)->params->otp.org->n_regions) +#define spi_nor_otp_region_len(nor) ((nor)->params->otp.org.len) +#define spi_nor_otp_n_regions(nor) ((nor)->params->otp.org.n_regions) =20 /** * spi_nor_otp_read_secr() - read security register @@ -222,7 +222,7 @@ int spi_nor_otp_is_locked_sr2(struct spi_nor *nor, unsi= gned int region) =20 static loff_t spi_nor_otp_region_start(const struct spi_nor *nor, unsigned= int region) { - const struct spi_nor_otp_organization *org =3D nor->params->otp.org; + const struct spi_nor_otp_organization *org =3D &nor->params->otp.org; =20 return org->base + region * org->offset; } diff --git a/drivers/mtd/spi-nor/winbond.c b/drivers/mtd/spi-nor/winbond.c index 9f7ce5763e71..b60df00e43b9 100644 --- a/drivers/mtd/spi-nor/winbond.c +++ b/drivers/mtd/spi-nor/winbond.c @@ -333,7 +333,7 @@ static int winbond_nor_late_init(struct spi_nor *nor) { struct spi_nor_flash_parameter *params =3D nor->params; =20 - if (params->otp.org) + if (params->otp.org.n_regions) params->otp.ops =3D &winbond_nor_otp_ops; =20 /* --=20 2.39.5 From nobody Thu Nov 28 21:48:53 2024 Received: from chessie.everett.org (chessie.fmt1.pfcs.com [66.220.13.234]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E314715886D; Thu, 26 Sep 2024 15:52:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.220.13.234 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727365928; cv=none; b=K3l5aN8oRiduaEL+EgXtwW/ZxYi+9HPtYI9ogLe+irbsA2wHArCMoP+1+momaPE3mxJBBrDWutI4G1KNw/AYrrWE3AWiVoSAZbV37UEq+kBoCU+CXuKgm1nhdEP6QIybQ16magWYMrZHCI8dWwjnWdzpsAiyH8PGRLyhy1KO/Wg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727365928; c=relaxed/simple; bh=F0d8g/19I40omcb5YFeGKdHESITWeIl1HBH9AF8+vYc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=W7ufh0rWmGdMRAlU+fhfvq6Z6S+ZVaynWkp7lNDtsR62xMROWDkc+rfkhQR+AXvIZ1pNFTi15iWPVVRska+h+y+9h159jtdN7+UXxelN2CXZiIpR9iqS+vnfhGxK3H2IXoGxznSbosrDvCgnpb4j146NMLXQ0ltcOtKoJRtH8Bs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=nwtime.org; spf=pass smtp.mailfrom=nwtime.org; arc=none smtp.client-ip=66.220.13.234 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=nwtime.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nwtime.org Received: from localhost.localdomain (ip-77-25-16-238.web.vodafone.de [77.25.16.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by chessie.everett.org (Postfix) with ESMTPSA id 4XDylF0ng9zMRC3; Thu, 26 Sep 2024 15:51:52 +0000 (UTC) From: Erez Geva To: linux-mtd@lists.infradead.org, Tudor Ambarus , Pratyush Yadav , Michael Walle Cc: linux-kernel@vger.kernel.org, Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , Esben Haabendal , Erez Geva Subject: [PATCH v6 2/3] mtd: spi-nor: core: add generic functions Date: Thu, 26 Sep 2024 17:51:26 +0200 Message-Id: <20240926155127.2450246-3-erezgeva@nwtime.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240926155127.2450246-1-erezgeva@nwtime.org> References: <20240926155127.2450246-1-erezgeva@nwtime.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Erez Geva Create a new internal function, spi_nor_send_cmd_internal() to reduce duplicate code. Add generic functions for use by vendor callbacks. The functions contain dispatching for using SPIMEM or using an SPI controller. It is better to leave this kind of dispatcher, out side of vendor specific code. In this patch series we use the new functions in Macronix new OTP callbacks. The new added functions: - Send an opcode without address or data. - Read a register value. - Write a register value. Signed-off-by: Erez Geva --- drivers/mtd/spi-nor/core.c | 130 +++++++++++++++++++++++++++---------- drivers/mtd/spi-nor/core.h | 27 +------- 2 files changed, 99 insertions(+), 58 deletions(-) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 1e7a64fd4b1a..d184386da1d6 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -354,53 +354,134 @@ int spi_nor_write_any_volatile_reg(struct spi_nor *n= or, struct spi_mem_op *op, } =20 /** - * spi_nor_write_enable() - Set write enable latch with Write Enable comma= nd. + * spi_nor_send_cmd_internal() - Send instruction without address or data = to the chip. * @nor: pointer to 'struct spi_nor'. + * @opcode: Command to send * * Return: 0 on success, -errno otherwise. */ -int spi_nor_write_enable(struct spi_nor *nor) +static inline int spi_nor_send_cmd_internal(struct spi_nor *nor, u8 opcode) { int ret; =20 if (nor->spimem) { - struct spi_mem_op op =3D SPI_NOR_WREN_OP; + struct spi_mem_op op =3D SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 0), + SPI_MEM_OP_NO_ADDR, + SPI_MEM_OP_NO_DUMMY, + SPI_MEM_OP_NO_DATA); =20 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); =20 ret =3D spi_mem_exec_op(nor->spimem, &op); } else { - ret =3D spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WREN, - NULL, 0); + ret =3D spi_nor_controller_ops_write_reg(nor, opcode, NULL, 0); } =20 - if (ret) - dev_dbg(nor->dev, "error %d on Write Enable\n", ret); + return ret; +} + +/** + * spi_nor_send_cmd() - Send instruction without address or data to the ch= ip. + * @nor: pointer to 'struct spi_nor'. + * @opcode: Command to send + * + * Return: 0 on success, -errno otherwise. + */ +int spi_nor_send_cmd(struct spi_nor *nor, u8 opcode) +{ + int ret; + + ret =3D spi_nor_send_cmd_internal(nor, opcode); =20 return ret; } =20 /** - * spi_nor_write_disable() - Send Write Disable instruction to the chip. + * spi_nor_read_reg() - Send instruction without address or data to the ch= ip. * @nor: pointer to 'struct spi_nor'. + * @opcode: Command to send + * @len: register value length * * Return: 0 on success, -errno otherwise. */ -int spi_nor_write_disable(struct spi_nor *nor) +int spi_nor_read_reg(struct spi_nor *nor, u8 opcode, size_t len) { int ret; =20 if (nor->spimem) { - struct spi_mem_op op =3D SPI_NOR_WRDI_OP; + struct spi_mem_op op =3D SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 0), + SPI_MEM_OP_NO_ADDR, + SPI_MEM_OP_NO_DUMMY, + SPI_MEM_OP_DATA_IN(len, nor->bouncebuf, 0)); =20 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); =20 ret =3D spi_mem_exec_op(nor->spimem, &op); } else { - ret =3D spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRDI, - NULL, 0); + ret =3D spi_nor_controller_ops_read_reg(nor, opcode, nor->bouncebuf, len= ); } =20 + return ret; +} + +/* + * spi_nor_write_reg() - Send instruction without address or data to the c= hip. + * @nor: pointer to 'struct spi_nor'. + * @opcode: Command to send + * @len: register value length + * + * Return: 0 on success, -errno otherwise. + */ +int spi_nor_write_reg(struct spi_nor *nor, u8 opcode, size_t len) +{ + int ret; + + if (nor->spimem) { + struct spi_mem_op op =3D SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 0), + SPI_MEM_OP_NO_ADDR, + SPI_MEM_OP_NO_DUMMY, + SPI_MEM_OP_DATA_OUT(len, nor->bouncebuf, 0)); + + spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); + + ret =3D spi_mem_exec_op(nor->spimem, &op); + } else { + ret =3D spi_nor_controller_ops_write_reg(nor, opcode, nor->bouncebuf, le= n); + } + + return ret; +} + +/** + * spi_nor_write_enable() - Set write enable latch with Write Enable comma= nd. + * @nor: pointer to 'struct spi_nor'. + * + * Return: 0 on success, -errno otherwise. + */ +int spi_nor_write_enable(struct spi_nor *nor) +{ + int ret; + + ret =3D spi_nor_send_cmd_internal(nor, SPINOR_OP_WREN); + + if (ret) + dev_dbg(nor->dev, "error %d on Write Enable\n", ret); + + return ret; +} + +/** + * spi_nor_write_disable() - Send Write Disable instruction to the chip. + * @nor: pointer to 'struct spi_nor'. + * + * Return: 0 on success, -errno otherwise. + */ +int spi_nor_write_disable(struct spi_nor *nor) +{ + int ret; + + ret =3D spi_nor_send_cmd_internal(nor, SPINOR_OP_WRDI); + if (ret) dev_dbg(nor->dev, "error %d on Write Disable\n", ret); =20 @@ -521,18 +602,8 @@ int spi_nor_set_4byte_addr_mode_en4b_ex4b(struct spi_n= or *nor, bool enable) { int ret; =20 - if (nor->spimem) { - struct spi_mem_op op =3D SPI_NOR_EN4B_EX4B_OP(enable); - - spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); - - ret =3D spi_mem_exec_op(nor->spimem, &op); - } else { - ret =3D spi_nor_controller_ops_write_reg(nor, - enable ? SPINOR_OP_EN4B : - SPINOR_OP_EX4B, - NULL, 0); - } + ret =3D spi_nor_send_cmd_internal(nor, enable ? SPINOR_OP_EN4B : + SPINOR_OP_EX4B); =20 if (ret) dev_dbg(nor->dev, "error %d setting 4-byte mode\n", ret); @@ -765,16 +836,7 @@ int spi_nor_global_block_unlock(struct spi_nor *nor) if (ret) return ret; =20 - if (nor->spimem) { - struct spi_mem_op op =3D SPI_NOR_GBULK_OP; - - spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); - - ret =3D spi_mem_exec_op(nor->spimem, &op); - } else { - ret =3D spi_nor_controller_ops_write_reg(nor, SPINOR_OP_GBULK, - NULL, 0); - } + ret =3D spi_nor_send_cmd_internal(nor, SPINOR_OP_GBULK); =20 if (ret) { dev_dbg(nor->dev, "error %d on Global Block Unlock\n", ret); diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index b678cb8ae5a1..b26e211bcfab 100644 --- a/drivers/mtd/spi-nor/core.h +++ b/drivers/mtd/spi-nor/core.h @@ -25,18 +25,6 @@ SPI_MEM_OP_DUMMY(ndummy, 0), \ SPI_MEM_OP_DATA_IN(len, buf, 0)) =20 -#define SPI_NOR_WREN_OP \ - SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WREN, 0), \ - SPI_MEM_OP_NO_ADDR, \ - SPI_MEM_OP_NO_DUMMY, \ - SPI_MEM_OP_NO_DATA) - -#define SPI_NOR_WRDI_OP \ - SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WRDI, 0), \ - SPI_MEM_OP_NO_ADDR, \ - SPI_MEM_OP_NO_DUMMY, \ - SPI_MEM_OP_NO_DATA) - #define SPI_NOR_RDSR_OP(buf) \ SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDSR, 0), \ SPI_MEM_OP_NO_ADDR, \ @@ -67,24 +55,12 @@ SPI_MEM_OP_NO_DUMMY, \ SPI_MEM_OP_DATA_IN(1, buf, 0)) =20 -#define SPI_NOR_EN4B_EX4B_OP(enable) \ - SPI_MEM_OP(SPI_MEM_OP_CMD(enable ? SPINOR_OP_EN4B : SPINOR_OP_EX4B, 0), \ - SPI_MEM_OP_NO_ADDR, \ - SPI_MEM_OP_NO_DUMMY, \ - SPI_MEM_OP_NO_DATA) - #define SPI_NOR_BRWR_OP(buf) \ SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_BRWR, 0), \ SPI_MEM_OP_NO_ADDR, \ SPI_MEM_OP_NO_DUMMY, \ SPI_MEM_OP_DATA_OUT(1, buf, 0)) =20 -#define SPI_NOR_GBULK_OP \ - SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_GBULK, 0), \ - SPI_MEM_OP_NO_ADDR, \ - SPI_MEM_OP_NO_DUMMY, \ - SPI_MEM_OP_NO_DATA) - #define SPI_NOR_DIE_ERASE_OP(opcode, addr_nbytes, addr, dice) \ SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 0), \ SPI_MEM_OP_ADDR(dice ? addr_nbytes : 0, addr, 0), \ @@ -599,6 +575,9 @@ extern const struct attribute_group *spi_nor_sysfs_grou= ps[]; void spi_nor_spimem_setup_op(const struct spi_nor *nor, struct spi_mem_op *op, const enum spi_nor_protocol proto); +int spi_nor_send_cmd(struct spi_nor *nor, u8 opcode); +int spi_nor_read_reg(struct spi_nor *nor, u8 opcode, size_t len); +int spi_nor_write_reg(struct spi_nor *nor, u8 opcode, size_t len); int spi_nor_write_enable(struct spi_nor *nor); int spi_nor_write_disable(struct spi_nor *nor); int spi_nor_set_4byte_addr_mode_en4b_ex4b(struct spi_nor *nor, bool enable= ); --=20 2.39.5 From nobody Thu Nov 28 21:48:53 2024 Received: from chessie.everett.org (chessie.fmt1.pfcs.com [66.220.13.234]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0038315B0EB; Thu, 26 Sep 2024 15:52:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.220.13.234 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727365931; cv=none; b=ZICoWXhPWtrWBfIqDCqpdII5/ELH60fHx5MnHjGRuXZUc2rY2hdY5o3UUrv+M7mjX4fQP7IBShSYSlhWLbZmj/WcRlkfQ+cQ4qbV/hD9micVRHLAffVx8loFvMqRSUpRnS9unQJji3WfYjdBarQQU6+zOx4+MvN2fXrX+O5zN7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727365931; c=relaxed/simple; bh=BClKuSrVJ/0jBjhwm01n2LfswUZWSekAFNWx/+cezTI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AxUGhztamHOoGo5hriw8pDnm6bOMADRpVnzjTShJqTYSqxFNXJOaVT2t4jN6Pu+l5ztK7MbJns7dEN8itJNak7pdA2vW8e2AbbeQVYk0KL4ISf7qzyLRcJycRkp2lEk4uCeXXVdOGl8oIajD78mD3KEsGGeoeePxUiHYvK2AZaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=nwtime.org; spf=pass smtp.mailfrom=nwtime.org; arc=none smtp.client-ip=66.220.13.234 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=nwtime.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nwtime.org Received: from localhost.localdomain (ip-77-25-16-238.web.vodafone.de [77.25.16.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by chessie.everett.org (Postfix) with ESMTPSA id 4XDylJ03KGzMRC4; Thu, 26 Sep 2024 15:51:55 +0000 (UTC) From: Erez Geva To: linux-mtd@lists.infradead.org, Tudor Ambarus , Pratyush Yadav , Michael Walle Cc: linux-kernel@vger.kernel.org, Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , Esben Haabendal , Erez Geva Subject: [PATCH v6 3/3] mtd: spi-nor: macronix: add support for OTP Date: Thu, 26 Sep 2024 17:51:27 +0200 Message-Id: <20240926155127.2450246-4-erezgeva@nwtime.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240926155127.2450246-1-erezgeva@nwtime.org> References: <20240926155127.2450246-1-erezgeva@nwtime.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Erez Geva Macronix SPI-NOR support OTP. Add callbacks to read, write and lock the OTP. Notice Macronix OTP do not support erase. Every bit written with '0', can not be changed further. Notice Macronix OTP do not support single region lock! The locking includes all regions at once! Signed-off-by: Erez Geva --- Notes: * My initial Macronix OTP code was tested with MX25l12833F. * As I no longer have that hardware. =20 * I now testing with MX25L3233F connected to my BeagleBone Black * through an 8-PIN SOP (200mil). * The BeagleBone Black runs with Debian GNU/Linux 12. * And use Kernel 6.6.32-ti-arm32-r5 build with * arm-linux-gnueabihf-gcc gcc version 12.2.0 (Debian 12.2.0-14). =20 * With current kernel, the driver do not read the SFDP of MX25L3233F. * The patch to read the SFDP is NOT part of this patch seria =20 $ cat /sys/bus/spi/devices/spi0.0/spi-nor/jedec_id c22016 $ cat /sys/bus/spi/devices/spi0.0/spi-nor/manufacturer macronix $ cat /sys/bus/spi/devices/spi0.0/spi-nor/partname mx25l3205d $ xxd -p /sys/bus/spi/devices/spi0.0/spi-nor/sfdp 53464450000101ff00000109300000ffc2000104600000ffffffffffffff ffffffffffffffffffffffffffffffffffffe520f1ffffffff0144eb086b 083b04bbeeffffffffff00ffffff00ff0c200f5210d800ffffffffffffff ffffffffffff003650269ef97764fecfffffffffffff $ sha256sum /sys/bus/spi/devices/spi0.0/spi-nor/sfdp 22d5d34af77c3628300056a0fc4bfbeafa027f544998852cf27f7cebf7881196 /sys/= bus/spi/devices/spi0.0/spi-nor/sfdp =20 $ cat /sys/kernel/debug/spi-nor/spi0.0/capabilities Supported read modes by the flash 1S-1S-1S opcode 0x03 mode cycles 0 dummy cycles 0 1S-1S-2S opcode 0x3b mode cycles 0 dummy cycles 8 1S-2S-2S opcode 0xbb mode cycles 0 dummy cycles 4 1S-1S-4S opcode 0x6b mode cycles 0 dummy cycles 8 1S-4S-4S opcode 0xeb mode cycles 2 dummy cycles 4 =20 Supported page program modes by the flash 1S-1S-1S opcode 0x02 =20 $ cat /sys/kernel/debug/spi-nor/spi0.0/params name mx25l3205d id c2 20 16 c2 20 16 size 4.00 MiB write size 1 page size 256 address nbytes 3 flags HAS_16BIT_SR =20 opcodes read 0x03 dummy cycles 0 erase 0x20 program 0x02 8D extension none =20 protocols read 1S-1S-1S write 1S-1S-1S register 1S-1S-1S =20 erase commands 20 (4.00 KiB) [1] 52 (32.0 KiB) [2] d8 (64.0 KiB) [3] c7 (4.00 MiB) =20 sector map region (in hex) | erase mask | flags ------------------+------------+---------- 00000000-003fffff | [ 123] | =20 # mtd_debug info /dev/mtd0 mtd.type =3D MTD_NORFLASH mtd.flags =3D MTD_CAP_NORFLASH mtd.size =3D 4194304 (4M) mtd.erasesize =3D 4096 (4K) mtd.writesize =3D 1 mtd.oobsize =3D 0 regions =3D 0 =20 * The BeagleBone Black SPI is very slow, Tests are slow. =20 # dd if=3D/dev/urandom of=3D./spi_test bs=3D1M count=3D2 2+0 records in 2+0 records out 2097152 bytes (2.1 MB, 2.0 MiB) copied, 0.0682607 s, 30.7 MB/s =20 # time mtd_debug erase /dev/mtd0 0 2097152 Erased 2097152 bytes from address 0x00000000 in flash =20 real 0m12.703s user 0m0.000s sys 0m12.692s =20 # time mtd_debug read /dev/mtd0 0 2097152 spi_read Copied 2097152 bytes from address 0x00000000 in flash to spi_read =20 real 0m1.942s user 0m0.000s sys 0m0.053s =20 # hexdump spi_read 0000000 ffff ffff ffff ffff ffff ffff ffff ffff * 0200000 =20 # sha256sum spi_read 4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5 spi_r= ead =20 # time mtd_debug write /dev/mtd0 0 2097152 spi_test Copied 2097152 bytes from spi_test to address 0x00000000 in flash =20 real 0m5.883s user 0m0.006s sys 0m3.970s =20 # time mtd_debug read /dev/mtd0 0 2097152 spi_read Copied 2097152 bytes from address 0x00000000 in flash to spi_read =20 real 0m2.208s user 0m0.003s sys 0m0.063s =20 # sha256sum spi* f4f5d1d0a4fef487037cdb3f1be0f9aab68ca32f2dbe8782c927f03adf623ec3 spi_r= ead f4f5d1d0a4fef487037cdb3f1be0f9aab68ca32f2dbe8782c927f03adf623ec3 spi_t= est =20 # time mtd_debug erase /dev/mtd0 0 2097152 Erased 2097152 bytes from address 0x00000000 in flash =20 real 0m12.126s user 0m0.001s sys 0m12.115s =20 # time mtd_debug read /dev/mtd0 0 2097152 spi_read Copied 2097152 bytes from address 0x00000000 in flash to spi_read =20 real 0m2.611s user 0m0.000s sys 0m0.064s =20 # sha256sum spi* 4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5 spi_r= ead f4f5d1d0a4fef487037cdb3f1be0f9aab68ca32f2dbe8782c927f03adf623ec3 spi_t= est =20 * MX25L3233F OTP uses 1 region of size of 4096 bits =20 * I configure 1 OTP region with 512 bytes length. * The OTP configure is NOT part of this patch seria =20 # flash_otp_info -u /dev/mtd0 Number of OTP user blocks on /dev/mtd0: 1 block 0: offset =3D 0x0000 size =3D 512 bytes [unlocked] =20 # flash_otp_dump -u /dev/mtd0 OTP user data for /dev/mtd0 0x0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0010: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0020: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0030: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0040: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0050: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0060: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0070: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0090: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x00a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x00b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x00c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x00d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x00e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x00f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0110: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0120: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0130: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0140: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0150: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0160: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0170: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0180: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0190: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x01a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x01b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x01c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x01d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x01e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x01f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff =20 * Macronix OTP does not support erase! * flash_otp_erase =20 # printf '\xde\xad%.0s' {1..256} | flash_otp_write -u /dev/mtd0 0 Writing OTP user data on /dev/mtd0 at offset 0x0 Wrote 512 bytes of OTP user data =20 # flash_otp_dump -u /dev/mtd0 OTP user data for /dev/mtd0 0x0000: de ad de ad de ad de ad de ad de ad de ad de ad 0x0010: de ad de ad de ad de ad de ad de ad de ad de ad 0x0020: de ad de ad de ad de ad de ad de ad de ad de ad 0x0030: de ad de ad de ad de ad de ad de ad de ad de ad 0x0040: de ad de ad de ad de ad de ad de ad de ad de ad 0x0050: de ad de ad de ad de ad de ad de ad de ad de ad 0x0060: de ad de ad de ad de ad de ad de ad de ad de ad 0x0070: de ad de ad de ad de ad de ad de ad de ad de ad 0x0080: de ad de ad de ad de ad de ad de ad de ad de ad 0x0090: de ad de ad de ad de ad de ad de ad de ad de ad 0x00a0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00b0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00c0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00d0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00e0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00f0: de ad de ad de ad de ad de ad de ad de ad de ad 0x0100: de ad de ad de ad de ad de ad de ad de ad de ad 0x0110: de ad de ad de ad de ad de ad de ad de ad de ad 0x0120: de ad de ad de ad de ad de ad de ad de ad de ad 0x0130: de ad de ad de ad de ad de ad de ad de ad de ad 0x0140: de ad de ad de ad de ad de ad de ad de ad de ad 0x0150: de ad de ad de ad de ad de ad de ad de ad de ad 0x0160: de ad de ad de ad de ad de ad de ad de ad de ad 0x0170: de ad de ad de ad de ad de ad de ad de ad de ad 0x0180: de ad de ad de ad de ad de ad de ad de ad de ad 0x0190: de ad de ad de ad de ad de ad de ad de ad de ad 0x01a0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01b0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01c0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01d0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01e0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01f0: de ad de ad de ad de ad de ad de ad de ad de ad =20 # flash_otp_info -u /dev/mtd0 Number of OTP user blocks on /dev/mtd0: 1 block 0: offset =3D 0x0000 size =3D 512 bytes [unlocked] =20 # printf '\xff\xff%.0s' {1..256} | flash_otp_write -u /dev/mtd0 0 Writing OTP user data on /dev/mtd0 at offset 0x0 Wrote 512 bytes of OTP user data =20 # We cannot overwrite '0' with '1'! =20 # flash_otp_dump -u /dev/mtd0 OTP user data for /dev/mtd0 0x0000: de ad de ad de ad de ad de ad de ad de ad de ad 0x0010: de ad de ad de ad de ad de ad de ad de ad de ad 0x0020: de ad de ad de ad de ad de ad de ad de ad de ad 0x0030: de ad de ad de ad de ad de ad de ad de ad de ad 0x0040: de ad de ad de ad de ad de ad de ad de ad de ad 0x0050: de ad de ad de ad de ad de ad de ad de ad de ad 0x0060: de ad de ad de ad de ad de ad de ad de ad de ad 0x0070: de ad de ad de ad de ad de ad de ad de ad de ad 0x0080: de ad de ad de ad de ad de ad de ad de ad de ad 0x0090: de ad de ad de ad de ad de ad de ad de ad de ad 0x00a0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00b0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00c0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00d0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00e0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00f0: de ad de ad de ad de ad de ad de ad de ad de ad 0x0100: de ad de ad de ad de ad de ad de ad de ad de ad 0x0110: de ad de ad de ad de ad de ad de ad de ad de ad 0x0120: de ad de ad de ad de ad de ad de ad de ad de ad 0x0130: de ad de ad de ad de ad de ad de ad de ad de ad 0x0140: de ad de ad de ad de ad de ad de ad de ad de ad 0x0150: de ad de ad de ad de ad de ad de ad de ad de ad 0x0160: de ad de ad de ad de ad de ad de ad de ad de ad 0x0170: de ad de ad de ad de ad de ad de ad de ad de ad 0x0180: de ad de ad de ad de ad de ad de ad de ad de ad 0x0190: de ad de ad de ad de ad de ad de ad de ad de ad 0x01a0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01b0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01c0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01d0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01e0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01f0: de ad de ad de ad de ad de ad de ad de ad de ad =20 # flash_otp_lock -u /dev/mtd0 0 512 About to lock OTP user data on /dev/mtd0 from 0x0 to 0x200 flash_otp_lock: Are you sure? (y/N) y Done. =20 # flash_otp_info -u /dev/mtd0 Number of OTP user blocks on /dev/mtd0: 1 block 0: offset =3D 0x0000 size =3D 512 bytes [locked] =20 # printf '\x00\x00%.0s' {1..256} | flash_otp_write -u /dev/mtd0 0 Writing OTP user data on /dev/mtd0 at offset 0x0 write(): Read-only file system =20 # flash_otp_dump -u /dev/mtd0 OTP user data for /dev/mtd0 0x0000: de ad de ad de ad de ad de ad de ad de ad de ad 0x0010: de ad de ad de ad de ad de ad de ad de ad de ad 0x0020: de ad de ad de ad de ad de ad de ad de ad de ad 0x0030: de ad de ad de ad de ad de ad de ad de ad de ad 0x0040: de ad de ad de ad de ad de ad de ad de ad de ad 0x0050: de ad de ad de ad de ad de ad de ad de ad de ad 0x0060: de ad de ad de ad de ad de ad de ad de ad de ad 0x0070: de ad de ad de ad de ad de ad de ad de ad de ad 0x0080: de ad de ad de ad de ad de ad de ad de ad de ad 0x0090: de ad de ad de ad de ad de ad de ad de ad de ad 0x00a0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00b0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00c0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00d0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00e0: de ad de ad de ad de ad de ad de ad de ad de ad 0x00f0: de ad de ad de ad de ad de ad de ad de ad de ad 0x0100: de ad de ad de ad de ad de ad de ad de ad de ad 0x0110: de ad de ad de ad de ad de ad de ad de ad de ad 0x0120: de ad de ad de ad de ad de ad de ad de ad de ad 0x0130: de ad de ad de ad de ad de ad de ad de ad de ad 0x0140: de ad de ad de ad de ad de ad de ad de ad de ad 0x0150: de ad de ad de ad de ad de ad de ad de ad de ad 0x0160: de ad de ad de ad de ad de ad de ad de ad de ad 0x0170: de ad de ad de ad de ad de ad de ad de ad de ad 0x0180: de ad de ad de ad de ad de ad de ad de ad de ad 0x0190: de ad de ad de ad de ad de ad de ad de ad de ad 0x01a0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01b0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01c0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01d0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01e0: de ad de ad de ad de ad de ad de ad de ad de ad 0x01f0: de ad de ad de ad de ad de ad de ad de ad de ad drivers/mtd/spi-nor/macronix.c | 167 +++++++++++++++++++++++++++++++++ include/linux/mtd/spi-nor.h | 9 ++ 2 files changed, 176 insertions(+) diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c index ea6be95e75a5..bee62e9051d6 100644 --- a/drivers/mtd/spi-nor/macronix.c +++ b/drivers/mtd/spi-nor/macronix.c @@ -8,6 +8,162 @@ =20 #include "core.h" =20 +/** + * macronix_nor_otp_enter() - Send Enter Secured OTP instruction to the ch= ip. + * @nor: pointer to 'struct spi_nor'. + * + * Return: 0 on success, -errno otherwise. + */ +static int macronix_nor_otp_enter(struct spi_nor *nor) +{ + int error; + + error =3D spi_nor_send_cmd(nor, SPINOR_OP_ENSO); + if (error) + dev_dbg(nor->dev, "error %d on Macronix Enter Secured OTP\n", error); + + return error; +} + +/** + * macronix_nor_otp_exit() - Send Exit Secured OTP instruction to the chip. + * @nor: pointer to 'struct spi_nor'. + * + * Return: 0 on success, -errno otherwise. + */ +static int macronix_nor_otp_exit(struct spi_nor *nor) +{ + int error; + + error =3D spi_nor_send_cmd(nor, SPINOR_OP_EXSO); + if (error) + dev_dbg(nor->dev, "error %d on Macronix Exit Secured OTP\n", error); + + return error; +} + +/** + * macronix_nor_otp_read() - read OTP data + * @nor: pointer to 'struct spi_nor' + * @addr: offset to read from + * @len: number of bytes to read + * @buf: pointer to dst buffer + * + * Return: number of bytes read successfully, -errno otherwise + */ +static int macronix_nor_otp_read(struct spi_nor *nor, loff_t addr, size_t = len, u8 *buf) +{ + int ret, error; + + error =3D macronix_nor_otp_enter(nor); + if (error) + return error; + + ret =3D spi_nor_read_data(nor, addr, len, buf); + + error =3D macronix_nor_otp_exit(nor); + + if (ret < 0) + dev_dbg(nor->dev, "error %d on Macronix read OTP data\n", ret); + else if (error) + return error; + + return ret; +} + +/** + * macronix_nor_otp_write() - write data to OTP + * @nor: pointer to 'struct spi_nor' + * @addr: offset to write to + * @len: number of bytes to write + * @buf: pointer to src buffer + * + * Return: number of bytes written successfully, -errno otherwise + */ +static int macronix_nor_otp_write(struct spi_nor *nor, loff_t addr, size_t= len, const u8 *buf) +{ + int error, ret =3D 0; + + error =3D macronix_nor_otp_enter(nor); + if (error) + return error; + + error =3D spi_nor_write_enable(nor); + if (error) + goto otp_write_err; + + ret =3D spi_nor_write_data(nor, addr, len, buf); + if (ret < 0) { + dev_dbg(nor->dev, "error %d on Macronix write OTP data\n", ret); + goto otp_write_err; + } + + error =3D spi_nor_wait_till_ready(nor); + if (error) + dev_dbg(nor->dev, "error %d on Macronix waiting write OTP finish\n", err= or); + +otp_write_err: + + error =3D macronix_nor_otp_exit(nor); + + return ret; +} + +/** + * macronix_nor_otp_lock() - lock the OTP + * @nor: pointer to 'struct spi_nor' + * @region: OTP region + * + * Return: 0 on success, -errno otherwise. + */ +static int macronix_nor_otp_lock(struct spi_nor *nor, unsigned int region) +{ + int error; + u8 *rdscur =3D nor->bouncebuf; + + error =3D spi_nor_read_reg(nor, SPINOR_OP_RDSCUR, 1); + if (error) { + dev_dbg(nor->dev, "error %d on read security register\n", error); + return error; + } + + if (rdscur[0] & SEC_REG_LDSO) + return 0; + + error =3D spi_nor_write_enable(nor); + if (error) { + dev_dbg(nor->dev, "error %d on enable write before update security regis= ter\n", + error); + return error; + } + + error =3D spi_nor_send_cmd(nor, SPINOR_OP_WRSCUR); + if (error) + dev_dbg(nor->dev, "error %d on update security register\n", error); + + return error; +} + +/** + * macronix_nor_otp_is_locked() - get the OTP lock status + * @nor: pointer to 'struct spi_nor' + * @region: OTP region + * + * Return: 1 on lock, 0 on not locked, -errno otherwise. + */ +static int macronix_nor_otp_is_locked(struct spi_nor *nor, unsigned int re= gion) +{ + int error; + u8 *rdscur =3D nor->bouncebuf; + + error =3D spi_nor_read_reg(nor, SPINOR_OP_RDSCUR, 1); + if (error) { + dev_dbg(nor->dev, "error %d on read security register\n", error); + return error; + } + return rdscur[0] & SEC_REG_LDSO ? 1 : 0; +} + static int mx25l25635_post_bfpt_fixups(struct spi_nor *nor, const struct sfdp_parameter_header *bfpt_header, @@ -190,8 +346,19 @@ static void macronix_nor_default_init(struct spi_nor *= nor) nor->params->quad_enable =3D spi_nor_sr1_bit6_quad_enable; } =20 +static const struct spi_nor_otp_ops macronix_nor_otp_ops =3D { + .read =3D macronix_nor_otp_read, + .write =3D macronix_nor_otp_write, + /* .erase =3D Macronix OTP do not support erase, */ + .lock =3D macronix_nor_otp_lock, + .is_locked =3D macronix_nor_otp_is_locked, +}; + static int macronix_nor_late_init(struct spi_nor *nor) { + if (nor->params->otp.org.n_regions) + nor->params->otp.ops =3D ¯onix_nor_otp_ops; + if (!nor->params->set_4byte_addr_mode) nor->params->set_4byte_addr_mode =3D spi_nor_set_4byte_addr_mode_en4b_ex= 4b; =20 diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index cdcfe0fd2e7d..ef834e7fc0ac 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -81,6 +81,15 @@ #define SPINOR_OP_BP 0x02 /* Byte program */ #define SPINOR_OP_AAI_WP 0xad /* Auto address increment word program */ =20 +/* Macronix OTP registers. */ +#define SPINOR_OP_RDSCUR 0x2b /* read security register */ +#define SPINOR_OP_WRSCUR 0x2f /* write security register */ +#define SPINOR_OP_ENSO 0xb1 /* enter secured OTP */ +#define SPINOR_OP_EXSO 0xc1 /* exit secured OTP */ + +/* Macronix security register values */ +#define SEC_REG_LDSO BIT(1) /* Lock-down Secured OTP */ + /* Used for Macronix and Winbond flashes. */ #define SPINOR_OP_EN4B 0xb7 /* Enter 4-byte mode */ #define SPINOR_OP_EX4B 0xe9 /* Exit 4-byte mode */ --=20 2.39.5