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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/dma-mapping.hlinux/mtd/nand.hlinux/mutex.hlinux/platform_device.hlinux/regmap.h
Detected Declarations
struct rtl_ecc_enginestruct rtl_ecc_ctxfunction rtl_ecc_ooblayout_eccfunction rtl_ecc_ooblayout_freefunction rtl_ecc_kick_enginefunction rtl_ecc_wait_for_enginefunction rtl_ecc_run_enginefunction rtl_ecc_prepare_io_reqfunction rtl_ecc_finish_io_reqfunction rtl_ecc_check_supportfunction rtl_ecc_init_ctxfunction rtl_ecc_cleanup_ctxfunction rtl_ecc_probefunction rtl_ecc_remove
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
- Immediate include surface: `linux/bitfield.h`, `linux/dma-mapping.h`, `linux/mtd/nand.h`, `linux/mutex.h`, `linux/platform_device.h`, `linux/regmap.h`.
- Detected declarations: `struct rtl_ecc_engine`, `struct rtl_ecc_ctx`, `function rtl_ecc_ooblayout_ecc`, `function rtl_ecc_ooblayout_free`, `function rtl_ecc_kick_engine`, `function rtl_ecc_wait_for_engine`, `function rtl_ecc_run_engine`, `function rtl_ecc_prepare_io_req`, `function rtl_ecc_finish_io_req`, `function rtl_ecc_check_support`.
- Atlas domain: Driver Families / drivers/mtd.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.