Files

127 lines
3.4 KiB
C
Raw Permalink Normal View History

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"
#define SPINAND_MFR_ZBIT 0x5E
2024-01-27 08:47:24 +08:00
static int zb35q01a_ecc_get_status(struct aic_spinand *flash, u8 status)
{
switch (status & STATUS_ECC_MASK) {
case STATUS_ECC_NO_BITFLIPS:
return 0;
case STATUS_ECC_HAS_1_4_BITFLIPS:
return 4;
case STATUS_ECC_UNCOR_ERROR:
return -SPINAND_ERR_ECC;
case STATUS_ECC_MASK:
2025-07-22 11:15:46 +08:00
return 8;
2024-01-27 08:47:24 +08:00
default:
break;
}
return -SPINAND_ERR;
}
2023-08-30 16:21:18 +08:00
2025-10-21 13:59:50 +08:00
static int zb35q0xb_ecc_get_status(struct aic_spinand *flash, u8 status)
{
switch (status & STATUS_ECC_MASK) {
case STATUS_ECC_NO_BITFLIPS:
return 0;
case STATUS_ECC_HAS_1_4_BITFLIPS:
return 4;
case STATUS_ECC_UNCOR_ERROR:
return -SPINAND_ERR_ECC;
default:
break;
}
return -SPINAND_ERR;
}
2025-01-08 19:12:06 +08:00
static int zb35q01a_ooblayout_user(struct aic_spinand *flash, int section,
struct aic_oob_region *region)
{
if (section > 3)
return -SPINAND_ERR;
region->offset = (16 * section) + 13;
region->length = 3;
return 0;
}
2025-07-22 11:15:46 +08:00
static int zb35q01b_ooblayout_user(struct aic_spinand *flash, int section,
struct aic_oob_region *region)
{
if (section > 3)
return -SPINAND_ERR;
region->offset = (16 * section) + 0;
2025-10-21 13:59:50 +08:00
region->length = 16;
2025-07-22 11:15:46 +08:00
return 0;
}
2025-10-21 13:59:50 +08:00
static int zb35q04b_ooblayout_user(struct aic_spinand *flash, int section,
struct aic_oob_region *region)
{
/* The ZB35Q04B lacks ECC protection for user metadata. */
return -SPINAND_ERR;
}
2023-08-30 16:21:18 +08:00
const struct aic_spinand_info zbit_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*/
2023-08-30 16:21:18 +08:00
/*ZB35Q01A*/
2024-01-27 08:47:24 +08:00
{ DEVID(0x41), PAGESIZE(2048), OOBSIZE(64), BPL(1024), PPB(64), PLANENUM(1),
2025-01-08 19:12:06 +08:00
DIE(0), "zbit 128MB: 2048+64@64@1024", cmd_cfg_table,
zb35q01a_ecc_get_status, zb35q01a_ooblayout_user },
2025-07-22 11:15:46 +08:00
/*ZB35Q01B*/
{ DEVID(0xa1), PAGESIZE(2048), OOBSIZE(64), BPL(1024), PPB(64), PLANENUM(1),
DIE(0), "zbit 128MB: 2048+64@64@1024", cmd_cfg_table,
2025-10-21 13:59:50 +08:00
zb35q0xb_ecc_get_status, zb35q01b_ooblayout_user },
/*ZB35Q02B*/
{ DEVID(0xa2), PAGESIZE(2048), OOBSIZE(64), BPL(2048), PPB(64), PLANENUM(1),
DIE(0), "zbit 256MB: 2048+64@64@2048", cmd_cfg_table,
zb35q0xb_ecc_get_status, zb35q01b_ooblayout_user },
/*ZB35Q04B*/
{ DEVID(0xa3), PAGESIZE(2048), OOBSIZE(128), BPL(2048), PPB(128), PLANENUM(1),
DIE(0), "zbit 512MB: 2048+128@128@2048", cmd_cfg_table,
zb35q0xb_ecc_get_status, zb35q04b_ooblayout_user },
2023-08-30 16:21:18 +08:00
};
const struct aic_spinand_info *zbit_spinand_detect(struct aic_spinand *flash)
{
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_ZBIT)
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], zbit_spinand_table,
2023-08-30 16:21:18 +08:00
ARRAY_SIZE(zbit_spinand_table));
};
static int zbit_spinand_init(struct aic_spinand *flash)
{
return 0;
};
static const struct spinand_manufacturer_ops zbit_spinand_manuf_ops = {
.detect = zbit_spinand_detect,
.init = zbit_spinand_init,
};
const struct spinand_manufacturer zbit_spinand_manufacturer = {
.id = SPINAND_MFR_ZBIT,
.name = "zbit",
.ops = &zbit_spinand_manuf_ops,
};