drivers/staging/greybus/spilib.c
Source file repositories/reference/linux-study-clean/drivers/staging/greybus/spilib.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/staging/greybus/spilib.c- Extension
.c- Size
- 14293 bytes
- Lines
- 570
- Domain
- Driver Families
- Bucket
- drivers/staging
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitops.hlinux/kernel.hlinux/module.hlinux/slab.hlinux/greybus.hlinux/spi/spi.hspilib.h
Detected Declarations
struct gb_spilibfunction tx_header_fit_operationfunction calc_rx_xfer_sizefunction calc_tx_xfer_sizefunction clean_xfer_statefunction is_last_xfer_donefunction setup_next_xferfunction gb_spi_decode_responsefunction gb_spi_transfer_one_messagefunction gb_spi_prepare_transfer_hardwarefunction gb_spi_unprepare_transfer_hardwarefunction gb_spi_setupfunction gb_spi_cleanupfunction gb_spi_setup_devicefunction gb_spilib_master_initfunction gb_spilib_master_exitexport gb_spilib_master_initexport gb_spilib_master_exit
Annotated Snippet
struct gb_spilib {
struct gb_connection *connection;
struct device *parent;
struct spi_transfer *first_xfer;
struct spi_transfer *last_xfer;
struct spilib_ops *ops;
u32 rx_xfer_offset;
u32 tx_xfer_offset;
u32 last_xfer_size;
unsigned int op_timeout;
u16 mode;
u16 flags;
u32 bits_per_word_mask;
u8 num_chipselect;
u32 min_speed_hz;
u32 max_speed_hz;
};
#define GB_SPI_STATE_MSG_DONE ((void *)0)
#define GB_SPI_STATE_MSG_IDLE ((void *)1)
#define GB_SPI_STATE_MSG_RUNNING ((void *)2)
#define GB_SPI_STATE_OP_READY ((void *)3)
#define GB_SPI_STATE_OP_DONE ((void *)4)
#define GB_SPI_STATE_MSG_ERROR ((void *)-1)
#define XFER_TIMEOUT_TOLERANCE 200
static struct spi_controller *get_controller_from_spi(struct gb_spilib *spi)
{
return gb_connection_get_data(spi->connection);
}
static int tx_header_fit_operation(u32 tx_size, u32 count, size_t data_max)
{
size_t headers_size;
data_max -= sizeof(struct gb_spi_transfer_request);
headers_size = (count + 1) * sizeof(struct gb_spi_transfer);
return tx_size + headers_size > data_max ? 0 : 1;
}
static size_t calc_rx_xfer_size(u32 rx_size, u32 *tx_xfer_size, u32 len,
size_t data_max)
{
size_t rx_xfer_size;
data_max -= sizeof(struct gb_spi_transfer_response);
if (rx_size + len > data_max)
rx_xfer_size = data_max - rx_size;
else
rx_xfer_size = len;
/* if this is a write_read, for symmetry read the same as write */
if (*tx_xfer_size && rx_xfer_size > *tx_xfer_size)
rx_xfer_size = *tx_xfer_size;
if (*tx_xfer_size && rx_xfer_size < *tx_xfer_size)
*tx_xfer_size = rx_xfer_size;
return rx_xfer_size;
}
static size_t calc_tx_xfer_size(u32 tx_size, u32 count, size_t len,
size_t data_max)
{
size_t headers_size;
data_max -= sizeof(struct gb_spi_transfer_request);
headers_size = (count + 1) * sizeof(struct gb_spi_transfer);
if (tx_size + headers_size + len > data_max)
return data_max - (tx_size + sizeof(struct gb_spi_transfer));
return len;
}
static void clean_xfer_state(struct gb_spilib *spi)
{
spi->first_xfer = NULL;
spi->last_xfer = NULL;
spi->rx_xfer_offset = 0;
spi->tx_xfer_offset = 0;
spi->last_xfer_size = 0;
spi->op_timeout = 0;
}
static bool is_last_xfer_done(struct gb_spilib *spi)
{
struct spi_transfer *last_xfer = spi->last_xfer;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/greybus.h`, `linux/spi/spi.h`, `spilib.h`.
- Detected declarations: `struct gb_spilib`, `function tx_header_fit_operation`, `function calc_rx_xfer_size`, `function calc_tx_xfer_size`, `function clean_xfer_state`, `function is_last_xfer_done`, `function setup_next_xfer`, `function gb_spi_decode_response`, `function gb_spi_transfer_one_message`, `function gb_spi_prepare_transfer_hardware`.
- Atlas domain: Driver Families / drivers/staging.
- Implementation status: integration 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.