drivers/mtd/devices/docg3.c
Source file repositories/reference/linux-study-clean/drivers/mtd/devices/docg3.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/devices/docg3.c- Extension
.c- Size
- 57450 bytes
- Lines
- 2085
- 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.
- 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/errno.hlinux/of.hlinux/platform_device.hlinux/string.hlinux/slab.hlinux/io.hlinux/delay.hlinux/mtd/mtd.hlinux/mtd/partitions.hlinux/bitmap.hlinux/bitrev.hlinux/bch.hlinux/debugfs.hlinux/seq_file.hdocg3.h
Detected Declarations
function docg3_ooblayout_eccfunction docg3_ooblayout_freefunction doc_readbfunction doc_readwfunction doc_writebfunction doc_writewfunction doc_flash_commandfunction doc_flash_sequencefunction doc_flash_addressfunction doc_register_readbfunction doc_register_readwfunction msleepfunction is_prot_seq_errorfunction doc_is_readyfunction doc_wait_readyfunction doc_reset_seqfunction doc_read_data_areafunction doc_write_data_areafunction blocksfunction doc_set_asic_modefunction doc_set_device_idfunction datafunction doc_setup_addr_sectorfunction doc_setup_writeaddr_sectorfunction doc_read_seekfunction doc_write_seekfunction ECCfunction ECCfunction doc_ecc_disablefunction doc_hamming_ecc_initfunction flipsfunction doc_read_page_preparefunction doc_read_page_getbytesfunction doc_write_page_putbytesfunction doc_get_bch_hw_eccfunction doc_page_finishfunction doc_read_page_finishfunction calc_block_sectorfunction doc_read_oobfunction doc_reload_bbtfunction doc_block_isbadfunction planefunction statusfunction doc_write_erase_wait_statusfunction doc_erase_blockfunction doc_erasefunction pagefunction doc_guess_autoecc
Annotated Snippet
if (dst16) {
*dst16 = data16;
dst16++;
}
}
if (cdr) {
doc_writew(docg3, DOC_IOSPACE_DATA | DOC_READADDR_ONE_BYTE,
DOC_READADDRESS);
doc_delay(docg3, 1);
dst8 = (u8 *)dst16;
for (i = 0; i < cdr; i++) {
data8 = doc_readb(docg3, DOC_IOSPACE_DATA);
if (dst8) {
*dst8 = data8;
dst8++;
}
}
}
}
/**
* doc_write_data_area - Write data into data area
* @docg3: the device
* @buf: the buffer to get input bytes from
* @len: the length to write
*
* Writes bytes into flash data. Handles the single byte / even bytes writes.
*/
static void doc_write_data_area(struct docg3 *docg3, const void *buf, int len)
{
int i, cdr, len4;
u16 *src16;
u8 *src8;
doc_dbg("doc_write_data_area(buf=%p, len=%d)\n", buf, len);
cdr = len & 0x3;
len4 = len - cdr;
doc_writew(docg3, DOC_IOSPACE_DATA, DOC_READADDRESS);
src16 = (u16 *)buf;
for (i = 0; i < len4; i += 2) {
doc_writew(docg3, *src16, DOC_IOSPACE_DATA);
src16++;
}
src8 = (u8 *)src16;
for (i = 0; i < cdr; i++) {
doc_writew(docg3, DOC_IOSPACE_DATA | DOC_READADDR_ONE_BYTE,
DOC_READADDRESS);
doc_writeb(docg3, *src8, DOC_IOSPACE_DATA);
src8++;
}
}
/**
* doc_set_reliable_mode - Sets the flash to normal or reliable data mode
* @docg3: the device
*
* The reliable data mode is a bit slower than the fast mode, but less errors
* occur. Entering the reliable mode cannot be done without entering the fast
* mode first.
*
* In reliable mode, pages 2*n and 2*n+1 are clones. Writing to page 0 of blocks
* (4,5) make the hardware write also to page 1 of blocks blocks(4,5). Reading
* from page 0 of blocks (4,5) or from page 1 of blocks (4,5) gives the same
* result, which is a logical and between bytes from page 0 and page 1 (which is
* consistent with the fact that writing to a page is _clearing_ bits of that
* page).
*/
static void doc_set_reliable_mode(struct docg3 *docg3)
{
static char *strmode[] = { "normal", "fast", "reliable", "invalid" };
doc_dbg("doc_set_reliable_mode(%s)\n", strmode[docg3->reliable]);
switch (docg3->reliable) {
case 0:
break;
case 1:
doc_flash_sequence(docg3, DOC_SEQ_SET_FASTMODE);
doc_flash_command(docg3, DOC_CMD_FAST_MODE);
break;
case 2:
doc_flash_sequence(docg3, DOC_SEQ_SET_RELIABLEMODE);
doc_flash_command(docg3, DOC_CMD_FAST_MODE);
doc_flash_command(docg3, DOC_CMD_RELIABLE_MODE);
break;
default:
doc_err("doc_set_reliable_mode(): invalid mode\n");
break;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/errno.h`, `linux/of.h`, `linux/platform_device.h`, `linux/string.h`, `linux/slab.h`, `linux/io.h`.
- Detected declarations: `function docg3_ooblayout_ecc`, `function docg3_ooblayout_free`, `function doc_readb`, `function doc_readw`, `function doc_writeb`, `function doc_writew`, `function doc_flash_command`, `function doc_flash_sequence`, `function doc_flash_address`, `function doc_register_readb`.
- 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.
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.