Files

121 lines
3.1 KiB
C

// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
* Copyright (c) 2019 Amlogic, Inc. All rights reserved.
*/
#ifndef __UBOOT__
#include <linux/device.h>
#include <linux/kernel.h>
#endif
#include <linux/mtd/spinand.h>
#include <linux/bitfield.h>
#define SPINAND_MFR_ICTHINK 0x20
#define ICTHINK_STATUS_ECC_NO_BITFLIPS (0)
#define ICTHINK_STATUS_ECC_1_7_BITFLIPS (1)
#define ICTHINK_STATUS_ECC_UNCOR_ERROR (2)
#define ICTHINK_STATUS_ECC_8_BITFLIPS (3)
static SPINAND_OP_VARIANTS(read_cache_variants,
//SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
//SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
static SPINAND_OP_VARIANTS(write_cache_variants,
SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
SPINAND_PROG_LOAD(true, 0, NULL, 0));
static SPINAND_OP_VARIANTS(update_cache_variants,
SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
SPINAND_PROG_LOAD(false, 0, NULL, 0));
static int xs25d4gasl_ooblayout_ecc(struct mtd_info *mtd, int section,
struct mtd_oob_region *region)
{
/* invisible and inaccessible */
return -ERANGE;
}
static int xs25d4gasl_ooblayout_free(struct mtd_info *mtd, int section,
struct mtd_oob_region *region)
{
if (section)
return -ERANGE;
/* Reserve 2 bytes for the BBM. */
region->offset = 2;
region->length = 48;
return 0;
}
static const struct mtd_ooblayout_ops xs25d4gasl_ooblayout = {
.ecc = xs25d4gasl_ooblayout_ecc,
.free = xs25d4gasl_ooblayout_free,
};
static int xs25d4gasl_ecc_get_status(struct spinand_device *spinand,
u8 status)
{
switch (FIELD_GET(STATUS_ECC_MASK, status)) {
case ICTHINK_STATUS_ECC_NO_BITFLIPS:
return 0;
case ICTHINK_STATUS_ECC_UNCOR_ERROR:
return -EBADMSG;
/* It needs to be file system friendly and should not
* cause frequent data block replacements.
*/
case ICTHINK_STATUS_ECC_1_7_BITFLIPS:
return 4;
case ICTHINK_STATUS_ECC_8_BITFLIPS:
return 8;
default:
break;
}
return -EINVAL;
}
static const struct spinand_info icthink_spinand_table[] = {
SPINAND_INFO("XS25D4GASL 3.3v", 0x04,
NAND_MEMORG(1, 2048, 64, 128, 2048, 1, 1, 1),
NAND_ECCREQ(8, 512),
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
&write_cache_variants,
&update_cache_variants),
SPINAND_HAS_QE_BIT,
SPINAND_ECCINFO(&xs25d4gasl_ooblayout,
xs25d4gasl_ecc_get_status)),
};
static int icthink_spinand_detect(struct spinand_device *spinand)
{
u8 *id = spinand->id.data;
int ret;
if (id[0] != SPINAND_MFR_ICTHINK)
return 0;
ret = spinand_match_and_init(spinand, icthink_spinand_table,
ARRAY_SIZE(icthink_spinand_table),
id + 1, 0);
if (ret)
return ret;
return 1;
}
static const struct spinand_manufacturer_ops icthink_spinand_manuf_ops = {
.detect = icthink_spinand_detect,
};
const struct spinand_manufacturer icthink_spinand_manufacturer = {
.id = SPINAND_MFR_ICTHINK,
.name = "icthink",
.ops = &icthink_spinand_manuf_ops,
};