drivers/spi/spi-mxic.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-mxic.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-mxic.c- Extension
.c- Size
- 21732 bytes
- Lines
- 861
- Domain
- Driver Families
- Bucket
- drivers/spi
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/io.hlinux/iopoll.hlinux/module.hlinux/mtd/nand.hlinux/mtd/nand-ecc-mxic.hlinux/platform_device.hlinux/pm_runtime.hlinux/spi/spi.hlinux/spi/spi-mem.h
Detected Declarations
struct mxic_spifunction mxic_spi_clk_enablefunction mxic_spi_clk_disablefunction mxic_spi_set_input_delay_dqsfunction mxic_spi_clk_setupfunction mxic_spi_set_freqfunction mxic_spi_hw_initfunction mxic_spi_prep_hc_cfgfunction mxic_spi_mem_prep_op_cfgfunction mxic_spi_data_xferfunction mxic_spi_mem_dirmap_readfunction mxic_spi_mem_dirmap_writefunction mxic_spi_mem_supports_opfunction mxic_spi_mem_dirmap_createfunction mxic_spi_mem_exec_opfunction mxic_spi_set_csfunction mxic_spi_transfer_onefunction mxic_spi_mem_ecc_init_ctxfunction mxic_spi_mem_ecc_cleanup_ctxfunction mxic_spi_mem_ecc_prepare_io_reqfunction mxic_spi_mem_ecc_finish_io_reqfunction mxic_spi_mem_ecc_removefunction mxic_spi_mem_ecc_probefunction mxic_spi_runtime_suspendfunction mxic_spi_runtime_resumefunction mxic_spi_probefunction mxic_spi_remove
Annotated Snippet
struct mxic_spi {
struct device *dev;
struct clk *ps_clk;
struct clk *send_clk;
struct clk *send_dly_clk;
void __iomem *regs;
u32 cur_speed_hz;
struct {
void __iomem *map;
dma_addr_t dma;
size_t size;
} linear;
struct {
bool use_pipelined_conf;
struct nand_ecc_engine *pipelined_engine;
void *ctx;
} ecc;
};
static int mxic_spi_clk_enable(struct mxic_spi *mxic)
{
int ret;
ret = clk_prepare_enable(mxic->send_clk);
if (ret)
return ret;
ret = clk_prepare_enable(mxic->send_dly_clk);
if (ret)
goto err_send_dly_clk;
return ret;
err_send_dly_clk:
clk_disable_unprepare(mxic->send_clk);
return ret;
}
static void mxic_spi_clk_disable(struct mxic_spi *mxic)
{
clk_disable_unprepare(mxic->send_clk);
clk_disable_unprepare(mxic->send_dly_clk);
}
static void mxic_spi_set_input_delay_dqs(struct mxic_spi *mxic, u8 idly_code)
{
writel(IDLY_CODE_VAL(0, idly_code) |
IDLY_CODE_VAL(1, idly_code) |
IDLY_CODE_VAL(2, idly_code) |
IDLY_CODE_VAL(3, idly_code),
mxic->regs + IDLY_CODE(0));
writel(IDLY_CODE_VAL(4, idly_code) |
IDLY_CODE_VAL(5, idly_code) |
IDLY_CODE_VAL(6, idly_code) |
IDLY_CODE_VAL(7, idly_code),
mxic->regs + IDLY_CODE(1));
}
static int mxic_spi_clk_setup(struct mxic_spi *mxic, unsigned long freq)
{
int ret;
ret = clk_set_rate(mxic->send_clk, freq);
if (ret)
return ret;
ret = clk_set_rate(mxic->send_dly_clk, freq);
if (ret)
return ret;
/*
* A constant delay range from 0x0 ~ 0x1F for input delay,
* the unit is 78 ps, the max input delay is 2.418 ns.
*/
mxic_spi_set_input_delay_dqs(mxic, 0xf);
/*
* Phase degree = 360 * freq * output-delay
* where output-delay is a constant value 1 ns in FPGA.
*
* Get Phase degree = 360 * freq * 1 ns
* = 360 * freq * 1 sec / 1000000000
* = 9 * freq / 25000000
*/
ret = clk_set_phase(mxic->send_dly_clk, 9 * freq / 25000000);
if (ret)
return ret;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/io.h`, `linux/iopoll.h`, `linux/module.h`, `linux/mtd/nand.h`, `linux/mtd/nand-ecc-mxic.h`, `linux/platform_device.h`, `linux/pm_runtime.h`.
- Detected declarations: `struct mxic_spi`, `function mxic_spi_clk_enable`, `function mxic_spi_clk_disable`, `function mxic_spi_set_input_delay_dqs`, `function mxic_spi_clk_setup`, `function mxic_spi_set_freq`, `function mxic_spi_hw_init`, `function mxic_spi_prep_hc_cfg`, `function mxic_spi_mem_prep_op_cfg`, `function mxic_spi_data_xfer`.
- Atlas domain: Driver Families / drivers/spi.
- Implementation status: source implementation candidate.
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.