drivers/fpga/microchip-spi.c
Source file repositories/reference/linux-study-clean/drivers/fpga/microchip-spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/fpga/microchip-spi.c- Extension
.c- Size
- 9960 bytes
- Lines
- 413
- Domain
- Driver Families
- Bucket
- drivers/fpga
- 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.
- 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/unaligned.hlinux/delay.hlinux/fpga/fpga-mgr.hlinux/iopoll.hlinux/module.hlinux/of.hlinux/spi/spi.h
Detected Declarations
struct mpf_privfunction mpf_read_statusfunction mpf_ops_statefunction mpf_ops_parse_headerfunction mpf_poll_statusfunction mpf_spi_writefunction mpf_spi_write_then_readfunction mpf_ops_write_initfunction mpf_spi_frame_writefunction mpf_ops_writefunction mpf_ops_write_completefunction mpf_probe
Annotated Snippet
struct mpf_priv {
struct spi_device *spi;
bool program_mode;
u8 tx __aligned(ARCH_KMALLOC_MINALIGN);
u8 rx;
};
static int mpf_read_status(struct mpf_priv *priv)
{
/*
* HW status is returned on MISO in the first byte after CS went
* active. However, first reading can be inadequate, so we submit
* two identical SPI transfers and use result of the later one.
*/
struct spi_transfer xfers[2] = {
{
.tx_buf = &priv->tx,
.rx_buf = &priv->rx,
.len = 1,
.cs_change = 1,
}, {
.tx_buf = &priv->tx,
.rx_buf = &priv->rx,
.len = 1,
},
};
u8 status;
int ret;
priv->tx = MPF_SPI_READ_STATUS;
ret = spi_sync_transfer(priv->spi, xfers, 2);
if (ret)
return ret;
status = priv->rx;
if ((status & MPF_STATUS_SPI_VIOLATION) ||
(status & MPF_STATUS_SPI_ERROR))
return -EIO;
return status;
}
static enum fpga_mgr_states mpf_ops_state(struct fpga_manager *mgr)
{
struct mpf_priv *priv = mgr->priv;
bool program_mode;
int status;
program_mode = priv->program_mode;
status = mpf_read_status(priv);
if (!program_mode && !status)
return FPGA_MGR_STATE_OPERATING;
return FPGA_MGR_STATE_UNKNOWN;
}
static int mpf_ops_parse_header(struct fpga_manager *mgr,
struct fpga_image_info *info,
const char *buf, size_t count)
{
size_t component_size_byte_num, component_size_byte_off,
components_size_start, bitstream_start,
block_id_offset, block_start_offset;
u8 header_size, blocks_num, block_id;
u32 block_start, component_size;
u16 components_num, i;
if (!buf) {
dev_err(&mgr->dev, "Image buffer is not provided\n");
return -EINVAL;
}
header_size = *(buf + MPF_HEADER_SIZE_OFFSET);
if (header_size > count) {
info->header_size = header_size;
return -EAGAIN;
}
/*
* Go through look-up table to find out where actual bitstream starts
* and where sizes of components of the bitstream lies.
*/
blocks_num = *(buf + header_size - 1);
block_id_offset = header_size + MPF_LOOKUP_TABLE_BLOCK_ID_OFFSET;
block_start_offset = header_size + MPF_LOOKUP_TABLE_BLOCK_START_OFFSET;
header_size += blocks_num * MPF_LOOKUP_TABLE_RECORD_SIZE;
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/delay.h`, `linux/fpga/fpga-mgr.h`, `linux/iopoll.h`, `linux/module.h`, `linux/of.h`, `linux/spi/spi.h`.
- Detected declarations: `struct mpf_priv`, `function mpf_read_status`, `function mpf_ops_state`, `function mpf_ops_parse_header`, `function mpf_poll_status`, `function mpf_spi_write`, `function mpf_spi_write_then_read`, `function mpf_ops_write_init`, `function mpf_spi_frame_write`, `function mpf_ops_write`.
- Atlas domain: Driver Families / drivers/fpga.
- 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.