2023-08-30 16:21:18 +08:00
|
|
|
/*
|
2025-07-22 11:15:46 +08:00
|
|
|
* Copyright (c) 2023-2025, ArtInChip Technology Co., Ltd
|
2023-08-30 16:21:18 +08:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
|
|
|
|
* Authors: xuan.wen <xuan.wen@artinchip.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "inc/spinand.h"
|
|
|
|
|
#include "inc/manufacturer.h"
|
|
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
#define SPINAND_MFR_XTX 0x0B
|
|
|
|
|
|
2023-08-30 16:21:18 +08:00
|
|
|
#define XTX_CFG_QUAD_ENABLE BIT(0)
|
|
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
#define XT26G01C_STATUS_ECC_MASK (0xF << 4)
|
|
|
|
|
#define XT26G01C_STATUS_ECC_NO_BITFLIPS (0 << 4)
|
|
|
|
|
#define XT26G01C_STATUS_ECC_UNCOR_ERROR (0xF << 4)
|
2025-07-22 11:15:46 +08:00
|
|
|
#define XT26G01C_STATUS_ECC_BITS_CORRECTED(a) ((a & XT26G01C_STATUS_ECC_MASK) >> 4)
|
|
|
|
|
|
2025-01-08 19:12:06 +08:00
|
|
|
#define XT26G02D_STATUS_ECC_MASK GENMASK(5, 4)
|
|
|
|
|
#define XT26G02D_STATUS_ECC_NO_ERROR (0)
|
|
|
|
|
#define XT26G02D_STATUS_ECC_UNCOR_ERROR BIT(5)
|
2025-07-22 11:15:46 +08:00
|
|
|
|
2025-01-08 19:12:06 +08:00
|
|
|
#define XT26G01B_STATUS_ECC_UNCOR_ERROR BIT(7)
|
2024-01-27 08:47:24 +08:00
|
|
|
|
|
|
|
|
int xt26g01c_ecc_get_status(struct aic_spinand *flash, u8 status)
|
|
|
|
|
{
|
|
|
|
|
switch (status & XT26G01C_STATUS_ECC_MASK) {
|
|
|
|
|
case XT26G01C_STATUS_ECC_NO_BITFLIPS:
|
|
|
|
|
return 0;
|
|
|
|
|
case XT26G01C_STATUS_ECC_UNCOR_ERROR:
|
|
|
|
|
return -SPINAND_ERR_ECC;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-22 11:15:46 +08:00
|
|
|
return XT26G01C_STATUS_ECC_BITS_CORRECTED(status);
|
2024-01-27 08:47:24 +08:00
|
|
|
}
|
2023-08-30 16:21:18 +08:00
|
|
|
|
2025-01-08 19:12:06 +08:00
|
|
|
int xt26g02d_ecc_get_status(struct aic_spinand *flash, u8 status)
|
|
|
|
|
{
|
2025-07-22 11:15:46 +08:00
|
|
|
u8 bits_flip = 0, temp = 0;
|
|
|
|
|
|
2025-01-08 19:12:06 +08:00
|
|
|
switch (status & XT26G02D_STATUS_ECC_MASK) {
|
|
|
|
|
case XT26G02D_STATUS_ECC_NO_ERROR:
|
|
|
|
|
return 0;
|
|
|
|
|
case XT26G02D_STATUS_ECC_UNCOR_ERROR:
|
|
|
|
|
return -SPINAND_ERR_ECC;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-22 11:15:46 +08:00
|
|
|
temp = status & XT26G01C_STATUS_ECC_MASK;
|
|
|
|
|
bits_flip = ((temp & 0x30) >> 2) | ((temp & 0xc0) >> 6);
|
|
|
|
|
|
|
|
|
|
return bits_flip;
|
2025-01-08 19:12:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int xt26g11c_ecc_get_status(struct aic_spinand *flash, u8 status)
|
|
|
|
|
{
|
|
|
|
|
switch (status & XT26G02D_STATUS_ECC_MASK) {
|
|
|
|
|
case XT26G02D_STATUS_ECC_NO_ERROR:
|
|
|
|
|
return 0;
|
|
|
|
|
case XT26G02D_STATUS_ECC_UNCOR_ERROR:
|
|
|
|
|
return -SPINAND_ERR_ECC;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return status & XT26G02D_STATUS_ECC_MASK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int xt26g01b_ecc_get_status(struct aic_spinand *flash, u8 status)
|
|
|
|
|
{
|
|
|
|
|
switch (status & XT26G01C_STATUS_ECC_MASK) {
|
|
|
|
|
case XT26G02D_STATUS_ECC_NO_ERROR:
|
|
|
|
|
return 0;
|
|
|
|
|
case XT26G01B_STATUS_ECC_UNCOR_ERROR:
|
|
|
|
|
return -SPINAND_ERR_ECC;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return status & XT26G01C_STATUS_ECC_MASK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int xt26g01c_ooblayout_user(struct aic_spinand *flash, int section,
|
2025-07-22 11:15:46 +08:00
|
|
|
struct aic_oob_region *region)
|
2025-01-08 19:12:06 +08:00
|
|
|
{
|
2025-07-22 11:15:46 +08:00
|
|
|
if (section > 1)
|
2025-01-08 19:12:06 +08:00
|
|
|
return -SPINAND_ERR;
|
|
|
|
|
|
2025-07-22 11:15:46 +08:00
|
|
|
region->offset = 0;
|
|
|
|
|
region->length = 64;
|
2025-01-08 19:12:06 +08:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int xt26g02d_ooblayout_user(struct aic_spinand *flash, int section,
|
2025-07-22 11:15:46 +08:00
|
|
|
struct aic_oob_region *region)
|
2025-01-08 19:12:06 +08:00
|
|
|
{
|
2025-07-22 11:15:46 +08:00
|
|
|
if (section > 1)
|
2025-01-08 19:12:06 +08:00
|
|
|
return -SPINAND_ERR;
|
|
|
|
|
|
2025-07-22 11:15:46 +08:00
|
|
|
region->offset = 0;
|
|
|
|
|
region->length = 64;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int xt26g04d_ooblayout_user(struct aic_spinand *flash, int section,
|
|
|
|
|
struct aic_oob_region *region)
|
|
|
|
|
{
|
|
|
|
|
if (section > 1)
|
|
|
|
|
return -SPINAND_ERR;
|
|
|
|
|
|
|
|
|
|
region->offset = 0;
|
|
|
|
|
region->length = 128;
|
2025-01-08 19:12:06 +08:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 16:21:18 +08:00
|
|
|
const struct aic_spinand_info xtx_spinand_table[] = {
|
2024-01-27 08:47:24 +08:00
|
|
|
/*devid page_size oob_size block_per_lun pages_per_eraseblock planes_per_lun
|
|
|
|
|
is_die_select*/
|
2025-07-22 11:15:46 +08:00
|
|
|
/*XT26G01C device*/
|
|
|
|
|
{ DEVID(0x11), PAGESIZE(2048), OOBSIZE(128), BPL(1024), PPB(64),
|
|
|
|
|
PLANENUM(1), DIE(0), "XTX 128MB: 2048+128@64@1024", cmd_cfg_table,
|
|
|
|
|
xt26g01c_ecc_get_status, xt26g01c_ooblayout_user },
|
|
|
|
|
/*XT26G01D device*/
|
|
|
|
|
{ DEVID(0x31), PAGESIZE(2048), OOBSIZE(128), BPL(1024), PPB(64),
|
|
|
|
|
PLANENUM(1), DIE(0), "XTX 128MB: 2048+128@64@1024", cmd_cfg_table,
|
|
|
|
|
xt26g02d_ecc_get_status, xt26g01c_ooblayout_user },
|
|
|
|
|
/*XT26G04D device */
|
|
|
|
|
{ DEVID(0x33), PAGESIZE(4096), OOBSIZE(256), BPL(2048), PPB(64), PLANENUM(1),
|
|
|
|
|
DIE(0), "XTX 512MB: 4096+256@64@2048", cmd_cfg_table,
|
|
|
|
|
xt26g02d_ecc_get_status, xt26g04d_ooblayout_user },
|
|
|
|
|
/*XT26G02D device */
|
|
|
|
|
{ DEVID(0x32), PAGESIZE(2048), OOBSIZE(128), BPL(2048), PPB(64), PLANENUM(1),
|
|
|
|
|
DIE(0), "XTX 256MB: 2048+128@64@2048", cmd_cfg_table,
|
|
|
|
|
xt26g02d_ecc_get_status, xt26g02d_ooblayout_user },
|
2025-01-08 19:12:06 +08:00
|
|
|
/*XT26G04C device */
|
|
|
|
|
{ DEVID(0x13), PAGESIZE(4096), OOBSIZE(256), BPL(2048), PPB(64),
|
|
|
|
|
PLANENUM(1), DIE(0), "XTX 512MB: 4096+256@64@2048", cmd_cfg_table,
|
2025-07-22 11:15:46 +08:00
|
|
|
xt26g01c_ecc_get_status, xt26g02d_ooblayout_user },
|
|
|
|
|
/*XT26G02C device*/
|
|
|
|
|
{ DEVID(0x12), PAGESIZE(2048), OOBSIZE(128), BPL(2048), PPB(64),
|
|
|
|
|
PLANENUM(1), DIE(0), "XTX 256MB: 2048+128@64@2048", cmd_cfg_table,
|
|
|
|
|
xt26g01c_ecc_get_status, xt26g01c_ooblayout_user },
|
2025-01-08 19:12:06 +08:00
|
|
|
|
2025-07-22 11:15:46 +08:00
|
|
|
// todo: the next 2 devices has no datasheet
|
2025-01-08 19:12:06 +08:00
|
|
|
/*XT26G01B device*/
|
|
|
|
|
{ DEVID(0xF1), PAGESIZE(2048), OOBSIZE(64), BPL(1024), PPB(64),
|
|
|
|
|
PLANENUM(1), DIE(0), "XTX 128MB: 2048+64@64@1024", cmd_cfg_table,
|
|
|
|
|
xt26g01b_ecc_get_status, xt26g01c_ooblayout_user },
|
2023-08-30 16:21:18 +08:00
|
|
|
/*XT26G11C device*/
|
2024-01-27 08:47:24 +08:00
|
|
|
{ DEVID(0x15), PAGESIZE(2048), OOBSIZE(128), BPL(1024), PPB(64),
|
2025-01-08 19:12:06 +08:00
|
|
|
PLANENUM(1), DIE(0), "XTX 128MB: 2048+128@64@1024", cmd_cfg_table,
|
|
|
|
|
xt26g11c_ecc_get_status, xt26g01c_ooblayout_user },
|
2023-08-30 16:21:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const struct aic_spinand_info *xtx_spinand_detect(struct aic_spinand *flash)
|
|
|
|
|
{
|
|
|
|
|
/*XT26G11C XT26G02C device id 1 Bity*/
|
2024-09-30 17:06:01 +08:00
|
|
|
u8 *id = flash->id.data;
|
2023-08-30 16:21:18 +08:00
|
|
|
|
2024-09-30 17:06:01 +08:00
|
|
|
if (id[0] != SPINAND_MFR_XTX)
|
2023-08-30 16:21:18 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
2024-09-30 17:06:01 +08:00
|
|
|
return spinand_match_and_init(&id[1], xtx_spinand_table,
|
2023-08-30 16:21:18 +08:00
|
|
|
ARRAY_SIZE(xtx_spinand_table));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int xtx_spinand_init(struct aic_spinand *flash)
|
|
|
|
|
{
|
|
|
|
|
/* Enable quad mode */
|
|
|
|
|
return spinand_config_set(flash, XTX_CFG_QUAD_ENABLE, XTX_CFG_QUAD_ENABLE);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct spinand_manufacturer_ops xtx_spinand_manuf_ops = {
|
|
|
|
|
.detect = xtx_spinand_detect,
|
|
|
|
|
.init = xtx_spinand_init,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const struct spinand_manufacturer xtx_spinand_manufacturer = {
|
|
|
|
|
.id = SPINAND_MFR_XTX,
|
|
|
|
|
.name = "XTX",
|
|
|
|
|
.ops = &xtx_spinand_manuf_ops,
|
|
|
|
|
};
|