Pull request for u-boot-nand-20240617

The first patch is by Arseniy Krasnov and adds support for OTP area
 access on MX30LFxG18AC chip series.
 
 The second patch is by John Watts and adds MTD dependency in Kconfig
 for UBI.
 
 The last patch is by Ravi Minnikanti and fixes bitflip return value on
 page read.
 -----BEGIN PGP SIGNATURE-----
 
 iQJYBAABCgBCFiEE6GOTDNYiFygVXvMmQBtB6IWRjvEFAmZwMAIkHGRhcmlvLmJp
 bmFjY2hpQGFtYXJ1bGFzb2x1dGlvbnMuY29tAAoJEEAbQeiFkY7xYakQAIFBx0ow
 qXLRTlOo5KSOt805zKk16wHDg8PqAQvetb3q4ZFZ4eh/BmPxiTT+To3RAwd/w7jR
 1xsimpT7KsT3AZVrISiNbs7v9jMzc8M2ZDyFeoUjZvjLNjINSa/yeTbl+a9DhGKI
 yAMOWLrlTjFEWMswaTgNHkzrC719j8/yzQcEbU0bsBHCyBgHxv4JDQlz5TMkAJrm
 WCoaZBLq/p4W099Bz2uL/Qsp1DAWO9cxYyHAd/WcYmah1Q7Z87V/THy1QjO0LLQX
 2ifCTwfOxeWBtSuTBq6LvG61TKCKQAq2Kf01PwfW3uh+Vy2kbef2xdJNiyDj2Lsl
 YLN0HPLZOhLOTME1V/HRvYesgmxebWznS9SKMxPk8Y+5iv5DKrHXPnfL1lT6KnJ3
 +FHN18Hmz0AipXl2nBEEkjWlrd1W04hp5sRPZD36Tz4syKHAqKUKngTnqAaF6JfU
 bL2Q/NIO4JMOmutAmVSDw4fkvYRpohlj22QSz+lXje7s2RaHOA7prv/kEbrvyAOP
 6HI8O1jG0nc6Hag4AQH1poE9wc8qgrBspxb7Pccb3DloMj82TsUO5fLEcw8qDExq
 GKDyibCN7h0BF0a1oDVFUUaOsx/Uu4jzZZQwKbHDi02iYRny6ibcPWJmzTey77px
 QNt32lyt7H97Bj/+RKSBT1a1RrAksX9BpnLk
 =c1MJ
 -----END PGP SIGNATURE-----

Merge tag 'u-boot-nand-20240617' of https://source.denx.de/u-boot/custodians/u-boot-nand-flash

Pull request for u-boot-nand-20240617

The first patch is by Arseniy Krasnov and adds support for OTP area
access on MX30LFxG18AC chip series.

The second patch is by John Watts and adds MTD dependency in Kconfig
for UBI.

The last patch is by Ravi Minnikanti and fixes bitflip return value on
page read.
This commit is contained in:
Tom Rini 2024-06-17 09:27:28 -06:00
commit 16324b43db
3 changed files with 176 additions and 0 deletions

View File

@ -16,13 +16,183 @@
* GNU General Public License for more details.
*/
#include <dm/device_compat.h>
#include <linux/mtd/rawnand.h>
#define ONFI_FEATURE_ADDR_30LFXG18AC_OTP 0x90
#define MACRONIX_30LFXG18AC_OTP_START_PAGE 2
#define MACRONIX_30LFXG18AC_OTP_PAGES 30
#define MACRONIX_30LFXG18AC_OTP_PAGE_SIZE 2112
#define MACRONIX_30LFXG18AC_OTP_SIZE_BYTES \
(MACRONIX_30LFXG18AC_OTP_PAGES * \
MACRONIX_30LFXG18AC_OTP_PAGE_SIZE)
#define MACRONIX_30LFXG18AC_OTP_EN BIT(0)
static int macronix_30lfxg18ac_get_otp_info(struct mtd_info *mtd, size_t len,
size_t *retlen,
struct otp_info *buf)
{
if (len < sizeof(*buf))
return -EINVAL;
/* Always report that OTP is unlocked. Reason is that this
* type of flash chip doesn't provide way to check that OTP
* is locked or not: subfeature parameter is implemented as
* volatile register. Technically OTP region could be locked
* and become readonly, but as there is no way to check it,
* don't allow to lock it ('_lock_user_prot_reg' callback
* always returns -EOPNOTSUPP) and thus we report that OTP
* is unlocked.
*/
buf->locked = 0;
buf->start = 0;
buf->length = MACRONIX_30LFXG18AC_OTP_SIZE_BYTES;
*retlen = sizeof(*buf);
return 0;
}
static int macronix_30lfxg18ac_otp_enable(struct nand_chip *nand)
{
u8 feature_buf[ONFI_SUBFEATURE_PARAM_LEN] = { 0 };
struct mtd_info *mtd;
mtd = nand_to_mtd(nand);
feature_buf[0] = MACRONIX_30LFXG18AC_OTP_EN;
return nand->onfi_set_features(mtd, nand, ONFI_FEATURE_ADDR_30LFXG18AC_OTP, feature_buf);
}
static int macronix_30lfxg18ac_otp_disable(struct nand_chip *nand)
{
u8 feature_buf[ONFI_SUBFEATURE_PARAM_LEN] = { 0 };
struct mtd_info *mtd;
mtd = nand_to_mtd(nand);
return nand->onfi_set_features(mtd, nand, ONFI_FEATURE_ADDR_30LFXG18AC_OTP, feature_buf);
}
static int __macronix_30lfxg18ac_rw_otp(struct mtd_info *mtd,
loff_t offs_in_flash,
size_t len, size_t *retlen,
u_char *buf, bool write)
{
struct nand_chip *nand;
size_t bytes_handled;
off_t offs_in_page;
u64 page;
int ret;
nand = mtd_to_nand(mtd);
nand->select_chip(mtd, 0);
ret = macronix_30lfxg18ac_otp_enable(nand);
if (ret)
goto out_otp;
page = offs_in_flash;
/* 'page' will be result of division. */
offs_in_page = do_div(page, MACRONIX_30LFXG18AC_OTP_PAGE_SIZE);
bytes_handled = 0;
while (bytes_handled < len &&
page < MACRONIX_30LFXG18AC_OTP_PAGES) {
size_t bytes_to_handle;
u64 phys_page = page + MACRONIX_30LFXG18AC_OTP_START_PAGE;
bytes_to_handle = min_t(size_t, len - bytes_handled,
MACRONIX_30LFXG18AC_OTP_PAGE_SIZE -
offs_in_page);
if (write)
ret = nand_prog_page_op(nand, phys_page, offs_in_page,
&buf[bytes_handled], bytes_to_handle);
else
ret = nand_read_page_op(nand, phys_page, offs_in_page,
&buf[bytes_handled], bytes_to_handle);
if (ret)
goto out_otp;
bytes_handled += bytes_to_handle;
offs_in_page = 0;
page++;
}
*retlen = bytes_handled;
out_otp:
if (ret)
dev_err(mtd->dev, "failed to perform OTP IO: %i\n", ret);
ret = macronix_30lfxg18ac_otp_disable(nand);
if (ret)
dev_err(mtd->dev, "failed to leave OTP mode after %s\n",
write ? "write" : "read");
nand->select_chip(mtd, -1);
return ret;
}
static int macronix_30lfxg18ac_write_otp(struct mtd_info *mtd, loff_t to,
size_t len, size_t *rlen,
u_char *buf)
{
return __macronix_30lfxg18ac_rw_otp(mtd, to, len, rlen, (u_char *)buf,
true);
}
static int macronix_30lfxg18ac_read_otp(struct mtd_info *mtd, loff_t from,
size_t len, size_t *rlen,
u_char *buf)
{
return __macronix_30lfxg18ac_rw_otp(mtd, from, len, rlen, buf, false);
}
static int macronix_30lfxg18ac_lock_otp(struct mtd_info *mtd, loff_t from,
size_t len)
{
/* See comment in 'macronix_30lfxg18ac_get_otp_info()'. */
return -EOPNOTSUPP;
}
static void macronix_nand_setup_otp(struct nand_chip *chip)
{
static const char * const supported_otp_models[] = {
"MX30LF1G18AC",
"MX30LF2G18AC",
"MX30LF4G18AC",
};
int i;
if (!chip->onfi_version ||
!(le16_to_cpu(chip->onfi_params.opt_cmd)
& ONFI_OPT_CMD_SET_GET_FEATURES))
return;
for (i = 0; i < ARRAY_SIZE(supported_otp_models); i++) {
if (!strcmp(chip->onfi_params.model, supported_otp_models[i])) {
struct mtd_info *mtd;
mtd = nand_to_mtd(chip);
mtd->_get_user_prot_info = macronix_30lfxg18ac_get_otp_info;
mtd->_read_user_prot_reg = macronix_30lfxg18ac_read_otp;
mtd->_write_user_prot_reg = macronix_30lfxg18ac_write_otp;
mtd->_lock_user_prot_reg = macronix_30lfxg18ac_lock_otp;
return;
}
}
}
static int macronix_nand_init(struct nand_chip *chip)
{
if (nand_is_slc(chip))
chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
macronix_nand_setup_otp(chip);
return 0;
}

View File

@ -800,6 +800,11 @@ static void prepare_start_command(struct pxa3xx_nand_info *info, int command)
info->ecc_err_cnt = 0;
info->ndcb3 = 0;
info->need_wait = 0;
/*
* Reset max_bitflips to zero. Once command is complete,
* max_bitflips for this READ is returned in ecc.read_page()
*/
info->max_bitflips = 0;
switch (command) {
case NAND_CMD_READ0:

View File

@ -9,6 +9,7 @@ config UBI_SILENCE_MSG
config MTD_UBI
bool "Enable UBI - Unsorted block images"
depends on MTD
select RBTREE
select MTD_PARTITIONS
help