drivers/mtd/nand/raw/loongson-nand-controller.c
Source file repositories/reference/linux-study-clean/drivers/mtd/nand/raw/loongson-nand-controller.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/nand/raw/loongson-nand-controller.c- Extension
.c- Size
- 28383 bytes
- Lines
- 1025
- 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/kernel.hlinux/module.hlinux/dmaengine.hlinux/dma-mapping.hlinux/iopoll.hlinux/mtd/mtd.hlinux/mtd/rawnand.hlinux/of.hlinux/platform_device.hlinux/regmap.hlinux/sizes.h
Detected Declarations
struct loongson_nand_hoststruct loongson_nand_opstruct loongson_nand_datastruct loongson_nand_hostfunction loongson_nand_op_cmd_mappingfunction loongson_nand_parse_instructionsfunction loongson_nand_set_addr_csfunction ls1b_nand_set_addrfunction ls1c_nand_set_addrfunction loongson_nand_trigger_opfunction loongson_nand_wait_for_op_donefunction loongson_nand_dma_callbackfunction loongson_nand_dma_transferfunction loongson_nand_data_type_execfunction loongson_nand_misc_type_execfunction loongson_nand_zerolen_type_execfunction loongson_nand_read_id_type_execfunction loongson_nand_read_status_type_execfunction loongson_nand_is_valid_cmdfunction loongson_nand_is_valid_cmd_seqfunction loongson_nand_check_opfunction loongson_nand_exec_opfunction loongson_nand_get_chip_capacityfunction loongson_nand_attach_chipfunction loongson_nand_controller_cleanupfunction ls2k1000_nand_apbdma_configfunction loongson_nand_controller_initfunction loongson_nand_chip_initfunction loongson_nand_probefunction loongson_nand_remove
Annotated Snippet
struct loongson_nand_op {
char addrs[LOONGSON_NAND_MAX_ADDR_CYC];
unsigned int naddrs;
unsigned int addrs_offset;
unsigned int aligned_offset;
unsigned int cmd_reg;
unsigned int row_start;
unsigned int rdy_timeout_ms;
unsigned int orig_len;
bool is_readid;
bool is_erase;
bool is_write;
bool is_read;
bool is_change_column;
size_t len;
char *buf;
};
struct loongson_nand_data {
unsigned int max_id_cycle;
unsigned int id_cycle_field;
unsigned int status_field;
unsigned int op_scope_field;
unsigned int hold_cycle;
unsigned int wait_cycle;
unsigned int nand_cs;
unsigned int dma_bits;
int (*dma_config)(struct device *dev);
void (*set_addr)(struct loongson_nand_host *host, struct loongson_nand_op *op);
};
struct loongson_nand_host {
struct device *dev;
struct nand_chip chip;
struct nand_controller controller;
const struct loongson_nand_data *data;
unsigned int addr_cs_field;
void __iomem *reg_base;
struct regmap *regmap;
/* DMA Engine stuff */
dma_addr_t dma_base;
struct dma_chan *dma_chan;
dma_cookie_t dma_cookie;
struct completion dma_complete;
};
static const struct regmap_config loongson_nand_regmap_config = {
.reg_bits = 32,
.val_bits = 32,
.reg_stride = 4,
};
static int loongson_nand_op_cmd_mapping(struct nand_chip *chip, struct loongson_nand_op *op,
u8 opcode)
{
struct loongson_nand_host *host = nand_get_controller_data(chip);
op->row_start = chip->page_shift + 1;
/* The controller abstracts the following NAND operations. */
switch (opcode) {
case NAND_CMD_STATUS:
op->cmd_reg = LOONGSON_NAND_CMD_STATUS;
break;
case NAND_CMD_RESET:
op->cmd_reg = LOONGSON_NAND_CMD_RESET;
break;
case NAND_CMD_READID:
op->is_readid = true;
op->cmd_reg = LOONGSON_NAND_CMD_READID;
break;
case NAND_CMD_ERASE1:
op->is_erase = true;
op->addrs_offset = LOONGSON_NAND_COL_ADDR_CYC;
break;
case NAND_CMD_ERASE2:
if (!op->is_erase)
return -EOPNOTSUPP;
/* During erasing, row_start differs from the default value. */
op->row_start = chip->page_shift;
op->cmd_reg = LOONGSON_NAND_CMD_ERASE;
break;
case NAND_CMD_SEQIN:
op->is_write = true;
break;
case NAND_CMD_PAGEPROG:
if (!op->is_write)
return -EOPNOTSUPP;
op->cmd_reg = LOONGSON_NAND_CMD_WRITE;
break;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/dmaengine.h`, `linux/dma-mapping.h`, `linux/iopoll.h`, `linux/mtd/mtd.h`, `linux/mtd/rawnand.h`, `linux/of.h`.
- Detected declarations: `struct loongson_nand_host`, `struct loongson_nand_op`, `struct loongson_nand_data`, `struct loongson_nand_host`, `function loongson_nand_op_cmd_mapping`, `function loongson_nand_parse_instructions`, `function loongson_nand_set_addr_cs`, `function ls1b_nand_set_addr`, `function ls1c_nand_set_addr`, `function loongson_nand_trigger_op`.
- 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.