drivers/mtd/nand/ecc-mtk.c
Source file repositories/reference/linux-study-clean/drivers/mtd/nand/ecc-mtk.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/nand/ecc-mtk.c- Extension
.c- Size
- 14341 bytes
- Lines
- 622
- Domain
- Driver Families
- Bucket
- drivers/mtd
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/platform_device.hlinux/dma-mapping.hlinux/interrupt.hlinux/clk.hlinux/module.hlinux/iopoll.hlinux/of.hlinux/of_platform.hlinux/mutex.hlinux/mtd/nand-ecc-mtk.h
Detected Declarations
struct mtk_ecc_capsstruct mtk_eccenum mtk_ecc_regsfunction mtk_ecc_wait_idlefunction mtk_ecc_irqfunction mtk_ecc_configfunction mtk_ecc_get_statsfunction mtk_ecc_releasefunction mtk_ecc_hw_initfunction mtk_ecc_enablefunction mtk_ecc_disablefunction mtk_ecc_wait_donefunction mtk_ecc_encodefunction mtk_ecc_adjust_strengthfunction mtk_ecc_get_parity_bitsfunction mtk_ecc_probefunction mtk_ecc_suspendfunction mtk_ecc_resumeexport mtk_ecc_get_statsexport mtk_ecc_releaseexport of_mtk_ecc_getexport mtk_ecc_enableexport mtk_ecc_disableexport mtk_ecc_wait_doneexport mtk_ecc_encodeexport mtk_ecc_adjust_strengthexport mtk_ecc_get_parity_bits
Annotated Snippet
struct mtk_ecc_caps {
u32 err_mask;
u32 err_shift;
const u8 *ecc_strength;
const u32 *ecc_regs;
u8 num_ecc_strength;
u8 ecc_mode_shift;
u32 parity_bits;
int pg_irq_sel;
};
struct mtk_ecc {
struct device *dev;
const struct mtk_ecc_caps *caps;
void __iomem *regs;
struct clk *clk;
struct completion done;
struct mutex lock;
u32 sectors;
u8 *eccdata;
};
/* ecc strength that each IP supports */
static const u8 ecc_strength_mt2701[] = {
4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36,
40, 44, 48, 52, 56, 60
};
static const u8 ecc_strength_mt2712[] = {
4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36,
40, 44, 48, 52, 56, 60, 68, 72, 80
};
static const u8 ecc_strength_mt7622[] = {
4, 6, 8, 10, 12
};
static const u8 ecc_strength_mt7986[] = {
4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24
};
enum mtk_ecc_regs {
ECC_ENCPAR00,
ECC_ENCIRQ_EN,
ECC_ENCIRQ_STA,
ECC_DECDONE,
ECC_DECIRQ_EN,
ECC_DECIRQ_STA,
};
static int mt2701_ecc_regs[] = {
[ECC_ENCPAR00] = 0x10,
[ECC_ENCIRQ_EN] = 0x80,
[ECC_ENCIRQ_STA] = 0x84,
[ECC_DECDONE] = 0x124,
[ECC_DECIRQ_EN] = 0x200,
[ECC_DECIRQ_STA] = 0x204,
};
static int mt2712_ecc_regs[] = {
[ECC_ENCPAR00] = 0x300,
[ECC_ENCIRQ_EN] = 0x80,
[ECC_ENCIRQ_STA] = 0x84,
[ECC_DECDONE] = 0x124,
[ECC_DECIRQ_EN] = 0x200,
[ECC_DECIRQ_STA] = 0x204,
};
static int mt7622_ecc_regs[] = {
[ECC_ENCPAR00] = 0x10,
[ECC_ENCIRQ_EN] = 0x30,
[ECC_ENCIRQ_STA] = 0x34,
[ECC_DECDONE] = 0x11c,
[ECC_DECIRQ_EN] = 0x140,
[ECC_DECIRQ_STA] = 0x144,
};
static inline void mtk_ecc_wait_idle(struct mtk_ecc *ecc,
enum mtk_ecc_operation op)
{
struct device *dev = ecc->dev;
u32 val;
int ret;
ret = readl_poll_timeout_atomic(ecc->regs + ECC_IDLE_REG(op), val,
val & ECC_IDLE_MASK,
10, ECC_TIMEOUT);
if (ret)
Annotation
- Immediate include surface: `linux/platform_device.h`, `linux/dma-mapping.h`, `linux/interrupt.h`, `linux/clk.h`, `linux/module.h`, `linux/iopoll.h`, `linux/of.h`, `linux/of_platform.h`.
- Detected declarations: `struct mtk_ecc_caps`, `struct mtk_ecc`, `enum mtk_ecc_regs`, `function mtk_ecc_wait_idle`, `function mtk_ecc_irq`, `function mtk_ecc_config`, `function mtk_ecc_get_stats`, `function mtk_ecc_release`, `function mtk_ecc_hw_init`, `function mtk_ecc_enable`.
- Atlas domain: Driver Families / drivers/mtd.
- Implementation status: integration 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.