drivers/mtd/nand/ecc-realtek.c

Source file repositories/reference/linux-study-clean/drivers/mtd/nand/ecc-realtek.c

File Facts

System
Linux kernel
Corpus path
drivers/mtd/nand/ecc-realtek.c
Extension
.c
Size
13886 bytes
Lines
467
Domain
Driver Families
Bucket
drivers/mtd
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct rtl_ecc_engine {
	struct device *dev;
	struct nand_ecc_engine engine;
	struct mutex lock;
	char *buf;
	dma_addr_t buf_dma;
	struct regmap *regmap;
};

struct rtl_ecc_ctx {
	struct rtl_ecc_engine * rtlc;
	struct nand_ecc_req_tweak_ctx req_ctx;
	int steps;
	int bch_mode;
	int strength;
	int parity_size;
};

static const struct regmap_config rtl_ecc_regmap_config = {
	.reg_bits	= 32,
	.val_bits	= 32,
	.reg_stride	= 4,
};

static inline void *nand_to_ctx(struct nand_device *nand)
{
	return nand->ecc.ctx.priv;
}

static inline struct rtl_ecc_engine *nand_to_rtlc(struct nand_device *nand)
{
	struct nand_ecc_engine *eng = nand->ecc.engine;

	return container_of(eng, struct rtl_ecc_engine, engine);
}

static int rtl_ecc_ooblayout_ecc(struct mtd_info *mtd, int section,
				 struct mtd_oob_region *oobregion)
{
	struct nand_device *nand = mtd_to_nanddev(mtd);
	struct rtl_ecc_ctx *ctx = nand_to_ctx(nand);

	if (section < 0 || section >= ctx->steps)
		return -ERANGE;

	oobregion->offset = ctx->steps * RTL_ECC_FREE_SIZE + section * ctx->parity_size;
	oobregion->length = ctx->parity_size;

	return 0;
}

static int rtl_ecc_ooblayout_free(struct mtd_info *mtd, int section,
				  struct mtd_oob_region *oobregion)
{
	struct nand_device *nand = mtd_to_nanddev(mtd);
	struct rtl_ecc_ctx *ctx = nand_to_ctx(nand);
	int bbm;

	if (section < 0 || section >= ctx->steps)
		return -ERANGE;

	/* reserve 2 BBM bytes in first block */
	bbm = section ? 0 : 2;
	oobregion->offset = section * RTL_ECC_FREE_SIZE + bbm;
	oobregion->length = RTL_ECC_FREE_SIZE - bbm;

	return 0;
}

static const struct mtd_ooblayout_ops rtl_ecc_ooblayout_ops = {
	.ecc = rtl_ecc_ooblayout_ecc,
	.free = rtl_ecc_ooblayout_free,
};

static void rtl_ecc_kick_engine(struct rtl_ecc_ctx *ctx, int operation)
{
	struct rtl_ecc_engine *rtlc = ctx->rtlc;

	regmap_write(rtlc->regmap, RTL_ECC_CFG,
		     ctx->bch_mode | RTL_ECC_BURST_128 | RTL_ECC_DMA_PRECISE);

	regmap_write(rtlc->regmap, RTL_ECC_DMA_START, rtlc->buf_dma);
	regmap_write(rtlc->regmap, RTL_ECC_DMA_TAG, rtlc->buf_dma + RTL_ECC_BLOCK_SIZE);
	regmap_write(rtlc->regmap, RTL_ECC_DMA_TRIGGER, operation);
}

static int rtl_ecc_wait_for_engine(struct rtl_ecc_ctx *ctx)
{
	struct rtl_ecc_engine *rtlc = ctx->rtlc;
	int ret, status, bitflips;

Annotation

Implementation Notes