drivers/mtd/chips/cfi_cmdset_0002.c
Source file repositories/reference/linux-study-clean/drivers/mtd/chips/cfi_cmdset_0002.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/chips/cfi_cmdset_0002.c- Extension
.c- Size
- 85570 bytes
- Lines
- 3113
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/module.hlinux/types.hlinux/kernel.hlinux/sched.hasm/io.hasm/byteorder.hlinux/errno.hlinux/slab.hlinux/delay.hlinux/interrupt.hlinux/reboot.hlinux/of.hlinux/mtd/map.hlinux/mtd/mtd.hlinux/mtd/cfi.hlinux/mtd/xip.hfwh_lock.h
Detected Declarations
struct ppb_lockenum cfi_quirksfunction cfi_use_status_regfunction cfi_check_err_statusfunction cfi_tell_featuresfunction fixup_amd_bootblockfunction fixup_use_write_buffersfunction fixup_convert_atmel_prifunction fixup_use_secsifunction fixup_use_erase_chipfunction chipsfunction fixup_old_sst_eraseregionfunction fixup_sst39vffunction fixup_sst39vf_rev_bfunction fixup_sst38vf640x_sectorsizefunction fixup_s29gl064n_sectorsfunction fixup_s29gl032n_sectorsfunction fixup_s29ns512p_sectorsfunction fixup_quirksfunction cfi_fixup_major_minorfunction is_m29ewfunction cfi_fixup_m29ew_erase_suspendfunction M29EWfunction donefunction chip_goodfunction get_chipfunction put_chipfunction elsefunction xip_enablefunction xip_udelayfunction do_read_onechipfunction cfi_amdstd_readfunction otp_enterfunction otp_exitfunction do_read_secsi_onechipfunction cfi_amdstd_secsi_readfunction do_otp_writefunction do_otp_lockfunction cfi_amdstd_otp_walkfunction cfi_amdstd_get_fact_prot_infofunction cfi_amdstd_get_user_prot_infofunction cfi_amdstd_read_fact_prot_regfunction cfi_amdstd_read_user_prot_regfunction cfi_amdstd_write_user_prot_regfunction cfi_amdstd_lock_user_prot_regfunction do_write_oneword_oncefunction do_write_oneword_startfunction do_write_oneword_done
Annotated Snippet
struct ppb_lock {
struct flchip *chip;
unsigned long adr;
int locked;
};
#define DO_XXLOCK_ONEBLOCK_LOCK ((void *)1)
#define DO_XXLOCK_ONEBLOCK_UNLOCK ((void *)2)
#define DO_XXLOCK_ONEBLOCK_GETLOCK ((void *)3)
static int __maybe_unused do_ppb_xxlock(struct map_info *map,
struct flchip *chip,
unsigned long adr, int len, void *thunk)
{
struct cfi_private *cfi = map->fldrv_priv;
unsigned long timeo;
int ret;
adr += chip->start;
mutex_lock(&chip->mutex);
ret = get_chip(map, chip, adr, FL_LOCKING);
if (ret) {
mutex_unlock(&chip->mutex);
return ret;
}
pr_debug("MTD %s(): XXLOCK 0x%08lx len %d\n", __func__, adr, len);
cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi,
cfi->device_type, NULL);
cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi,
cfi->device_type, NULL);
/* PPB entry command */
cfi_send_gen_cmd(0xC0, cfi->addr_unlock1, chip->start, map, cfi,
cfi->device_type, NULL);
if (thunk == DO_XXLOCK_ONEBLOCK_LOCK) {
chip->state = FL_LOCKING;
map_write(map, CMD(0xA0), adr);
map_write(map, CMD(0x00), adr);
} else if (thunk == DO_XXLOCK_ONEBLOCK_UNLOCK) {
/*
* Unlocking of one specific sector is not supported, so we
* have to unlock all sectors of this device instead
*/
chip->state = FL_UNLOCKING;
map_write(map, CMD(0x80), chip->start);
map_write(map, CMD(0x30), chip->start);
} else if (thunk == DO_XXLOCK_ONEBLOCK_GETLOCK) {
chip->state = FL_JEDEC_QUERY;
/* Return locked status: 0->locked, 1->unlocked */
ret = !cfi_read_query(map, adr);
} else
BUG();
/*
* Wait for some time as unlocking of all sectors takes quite long
*/
timeo = jiffies + msecs_to_jiffies(2000); /* 2s max (un)locking */
for (;;) {
if (chip_ready(map, chip, adr, NULL))
break;
if (time_after(jiffies, timeo)) {
printk(KERN_ERR "Waiting for chip to be ready timed out.\n");
ret = -EIO;
break;
}
UDELAY(map, chip, adr, 1);
}
/* Exit BC commands */
map_write(map, CMD(0x90), chip->start);
map_write(map, CMD(0x00), chip->start);
chip->state = FL_READY;
put_chip(map, chip, adr);
mutex_unlock(&chip->mutex);
return ret;
}
static int __maybe_unused cfi_ppb_lock(struct mtd_info *mtd, loff_t ofs,
uint64_t len)
{
return cfi_varsize_frob(mtd, do_ppb_xxlock, ofs, len,
DO_XXLOCK_ONEBLOCK_LOCK);
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/types.h`, `linux/kernel.h`, `linux/sched.h`, `asm/io.h`, `asm/byteorder.h`, `linux/errno.h`, `linux/slab.h`.
- Detected declarations: `struct ppb_lock`, `enum cfi_quirks`, `function cfi_use_status_reg`, `function cfi_check_err_status`, `function cfi_tell_features`, `function fixup_amd_bootblock`, `function fixup_use_write_buffers`, `function fixup_convert_atmel_pri`, `function fixup_use_secsi`, `function fixup_use_erase_chip`.
- Atlas domain: Driver Families / drivers/mtd.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.