drivers/mtd/nand/raw/hisi504_nand.c
Source file repositories/reference/linux-study-clean/drivers/mtd/nand/raw/hisi504_nand.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/nand/raw/hisi504_nand.c- Extension
.c- Size
- 23708 bytes
- Lines
- 870
- 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/of.hlinux/mtd/mtd.hlinux/sizes.hlinux/clk.hlinux/slab.hlinux/module.hlinux/delay.hlinux/interrupt.hlinux/mtd/rawnand.hlinux/dma-mapping.hlinux/platform_device.hlinux/mtd/partitions.h
Detected Declarations
struct hinfc_hostfunction hinfc_readfunction hinfc_writefunction wait_controller_finishedfunction hisi_nfc_dma_transferfunction hisi_nfc_send_cmd_pageprogfunction hisi_nfc_send_cmd_readstartfunction hisi_nfc_send_cmd_erasefunction hisi_nfc_send_cmd_readidfunction hisi_nfc_send_cmd_statusfunction hisi_nfc_send_cmd_resetfunction hisi_nfc_select_chipfunction hisi_nfc_read_bytefunction hisi_nfc_write_buffunction hisi_nfc_read_buffunction set_addrfunction hisi_nfc_cmdfuncfunction hinfc_irq_handlefunction hisi_nand_read_page_hweccfunction hisi_nand_read_oobfunction hisi_nand_write_page_hweccfunction hisi_nfc_host_initfunction hisi_ooblayout_eccfunction hisi_ooblayout_freefunction hisi_nfc_ecc_probefunction hisi_nfc_attach_chipfunction hisi_nfc_probefunction hisi_nfc_removefunction hisi_nfc_suspendfunction hisi_nfc_resume
Annotated Snippet
struct hinfc_host {
struct nand_chip chip;
struct device *dev;
void __iomem *iobase;
void __iomem *mmio;
struct completion cmd_complete;
unsigned int offset;
unsigned int command;
int chipselect;
unsigned int addr_cycle;
u32 addr_value[2];
u32 cache_addr_value[2];
char *buffer;
dma_addr_t dma_buffer;
dma_addr_t dma_oob;
int version;
unsigned int irq_status; /* interrupt status */
};
static inline unsigned int hinfc_read(struct hinfc_host *host, unsigned int reg)
{
return readl(host->iobase + reg);
}
static inline void hinfc_write(struct hinfc_host *host, unsigned int value,
unsigned int reg)
{
writel(value, host->iobase + reg);
}
static void wait_controller_finished(struct hinfc_host *host)
{
unsigned long timeout = jiffies + HINFC504_NFC_TIMEOUT;
int val;
while (time_before(jiffies, timeout)) {
val = hinfc_read(host, HINFC504_STATUS);
if (host->command == NAND_CMD_ERASE2) {
/* nfc is ready */
while (!(val & HINFC504_READY)) {
usleep_range(500, 1000);
val = hinfc_read(host, HINFC504_STATUS);
}
return;
}
if (val & HINFC504_READY)
return;
}
/* wait cmd timeout */
dev_err(host->dev, "Wait NAND controller exec cmd timeout.\n");
}
static void hisi_nfc_dma_transfer(struct hinfc_host *host, int todev)
{
struct nand_chip *chip = &host->chip;
struct mtd_info *mtd = nand_to_mtd(chip);
unsigned long val;
int ret;
hinfc_write(host, host->dma_buffer, HINFC504_DMA_ADDR_DATA);
hinfc_write(host, host->dma_oob, HINFC504_DMA_ADDR_OOB);
if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_NONE) {
hinfc_write(host, ((mtd->oobsize & HINFC504_DMA_LEN_OOB_MASK)
<< HINFC504_DMA_LEN_OOB_SHIFT), HINFC504_DMA_LEN);
hinfc_write(host, HINFC504_DMA_PARA_DATA_RW_EN
| HINFC504_DMA_PARA_OOB_RW_EN, HINFC504_DMA_PARA);
} else {
if (host->command == NAND_CMD_READOOB)
hinfc_write(host, HINFC504_DMA_PARA_OOB_RW_EN
| HINFC504_DMA_PARA_OOB_EDC_EN
| HINFC504_DMA_PARA_OOB_ECC_EN, HINFC504_DMA_PARA);
else
hinfc_write(host, HINFC504_DMA_PARA_DATA_RW_EN
| HINFC504_DMA_PARA_OOB_RW_EN
| HINFC504_DMA_PARA_DATA_EDC_EN
| HINFC504_DMA_PARA_OOB_EDC_EN
| HINFC504_DMA_PARA_DATA_ECC_EN
| HINFC504_DMA_PARA_OOB_ECC_EN, HINFC504_DMA_PARA);
}
val = (HINFC504_DMA_CTRL_DMA_START | HINFC504_DMA_CTRL_BURST4_EN
| HINFC504_DMA_CTRL_BURST8_EN | HINFC504_DMA_CTRL_BURST16_EN
| HINFC504_DMA_CTRL_DATA_AREA_EN | HINFC504_DMA_CTRL_OOB_AREA_EN
| ((host->addr_cycle == 4 ? 1 : 0)
<< HINFC504_DMA_CTRL_ADDR_NUM_SHIFT)
Annotation
- Immediate include surface: `linux/of.h`, `linux/mtd/mtd.h`, `linux/sizes.h`, `linux/clk.h`, `linux/slab.h`, `linux/module.h`, `linux/delay.h`, `linux/interrupt.h`.
- Detected declarations: `struct hinfc_host`, `function hinfc_read`, `function hinfc_write`, `function wait_controller_finished`, `function hisi_nfc_dma_transfer`, `function hisi_nfc_send_cmd_pageprog`, `function hisi_nfc_send_cmd_readstart`, `function hisi_nfc_send_cmd_erase`, `function hisi_nfc_send_cmd_readid`, `function hisi_nfc_send_cmd_status`.
- 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.