drivers/mtd/nand/raw/mtk_nand.c
Source file repositories/reference/linux-study-clean/drivers/mtd/nand/raw/mtk_nand.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/nand/raw/mtk_nand.c- Extension
.c- Size
- 41518 bytes
- Lines
- 1658
- 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.
- 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/delay.hlinux/clk.hlinux/mtd/rawnand.hlinux/mtd/mtd.hlinux/module.hlinux/iopoll.hlinux/of.hlinux/mtd/nand-ecc-mtk.h
Detected Declarations
struct mtk_nfc_capsstruct mtk_nfc_bad_mark_ctlstruct mtk_nfc_fdmstruct mtk_nfc_nand_chipstruct mtk_nfc_clkstruct mtk_nfcfunction mtk_data_lenfunction nfi_writelfunction nfi_writewfunction nfi_writebfunction nfi_readlfunction nfi_readwfunction nfi_readbfunction mtk_nfc_hw_resetfunction mtk_nfc_send_commandfunction mtk_nfc_send_addressfunction mtk_nfc_hw_runtime_configfunction mtk_nfc_wait_ioreadyfunction mtk_nfc_read_bytefunction mtk_nfc_read_buffunction mtk_nfc_write_bytefunction mtk_nfc_write_buffunction mtk_nfc_exec_instrfunction mtk_nfc_select_targetfunction mtk_nfc_exec_opfunction mtk_nfc_setup_interfacefunction mtk_nfc_sector_encodefunction mtk_nfc_no_bad_mark_swapfunction mtk_nfc_format_subpagefunction mtk_nfc_format_pagefunction mtk_nfc_read_fdmfunction mtk_nfc_write_fdmfunction mtk_nfc_do_write_pagefunction mtk_nfc_write_pagefunction mtk_nfc_write_page_hweccfunction mtk_nfc_write_page_rawfunction mtk_nfc_write_subpage_hweccfunction mtk_nfc_write_oob_stdfunction mtk_nfc_update_ecc_statsfunction mtk_nfc_read_subpagefunction mtk_nfc_read_subpage_hweccfunction mtk_nfc_read_page_hweccfunction mtk_nfc_read_page_rawfunction mtk_nfc_read_oob_stdfunction mtk_nfc_hw_initfunction mtk_nfc_irqfunction mtk_nfc_ooblayout_freefunction mtk_nfc_ooblayout_ecc
Annotated Snippet
struct mtk_nfc_caps {
const u8 *spare_size;
u8 num_spare_size;
u8 pageformat_spare_shift;
u8 nfi_clk_div;
u8 max_sector;
u32 max_sector_size;
};
struct mtk_nfc_bad_mark_ctl {
void (*bm_swap)(struct mtd_info *, u8 *buf, int raw);
u32 sec;
u32 pos;
};
/*
* FDM: region used to store free OOB data
*/
struct mtk_nfc_fdm {
u32 reg_size;
u32 ecc_size;
};
struct mtk_nfc_nand_chip {
struct list_head node;
struct nand_chip nand;
struct mtk_nfc_bad_mark_ctl bad_mark;
struct mtk_nfc_fdm fdm;
u32 spare_per_sector;
int nsels;
u8 sels[] __counted_by(nsels);
/* nothing after this field */
};
struct mtk_nfc_clk {
struct clk *nfi_clk;
struct clk *pad_clk;
};
struct mtk_nfc {
struct nand_controller controller;
struct mtk_ecc_config ecc_cfg;
struct mtk_nfc_clk clk;
struct mtk_ecc *ecc;
struct device *dev;
const struct mtk_nfc_caps *caps;
void __iomem *regs;
struct completion done;
struct list_head chips;
u8 *buffer;
unsigned long assigned_cs;
};
/*
* supported spare size of each IP.
* order should be the same with the spare size bitfiled defination of
* register NFI_PAGEFMT.
*/
static const u8 spare_size_mt2701[] = {
16, 26, 27, 28, 32, 36, 40, 44, 48, 49, 50, 51, 52, 62, 63, 64
};
static const u8 spare_size_mt2712[] = {
16, 26, 27, 28, 32, 36, 40, 44, 48, 49, 50, 51, 52, 62, 61, 63, 64, 67,
74
};
static const u8 spare_size_mt7622[] = {
16, 26, 27, 28
};
static inline struct mtk_nfc_nand_chip *to_mtk_nand(struct nand_chip *nand)
{
return container_of(nand, struct mtk_nfc_nand_chip, nand);
}
static inline u8 *data_ptr(struct nand_chip *chip, const u8 *p, int i)
{
return (u8 *)p + i * chip->ecc.size;
}
static inline u8 *oob_ptr(struct nand_chip *chip, int i)
{
struct mtk_nfc_nand_chip *mtk_nand = to_mtk_nand(chip);
Annotation
- Immediate include surface: `linux/platform_device.h`, `linux/dma-mapping.h`, `linux/interrupt.h`, `linux/delay.h`, `linux/clk.h`, `linux/mtd/rawnand.h`, `linux/mtd/mtd.h`, `linux/module.h`.
- Detected declarations: `struct mtk_nfc_caps`, `struct mtk_nfc_bad_mark_ctl`, `struct mtk_nfc_fdm`, `struct mtk_nfc_nand_chip`, `struct mtk_nfc_clk`, `struct mtk_nfc`, `function mtk_data_len`, `function nfi_writel`, `function nfi_writew`, `function nfi_writeb`.
- Atlas domain: Driver Families / drivers/mtd.
- Implementation status: source implementation candidate.
- 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.