drivers/spi/spi-ljca.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-ljca.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-ljca.c- Extension
.c- Size
- 7407 bytes
- Lines
- 297
- 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/auxiliary_bus.hlinux/bitfield.hlinux/bits.hlinux/dev_printk.hlinux/module.hlinux/spi/spi.hlinux/usb/ljca.h
Detected Declarations
struct ljca_spi_init_packetstruct ljca_spi_xfer_packetstruct ljca_spi_devenum ljca_spi_cmdfunction ljca_spi_read_writefunction ljca_spi_initfunction ljca_spi_deinitfunction ljca_spi_transferfunction ljca_spi_transfer_onefunction ljca_spi_probefunction ljca_spi_dev_removefunction ljca_spi_dev_suspendfunction ljca_spi_dev_resume
Annotated Snippet
struct ljca_spi_init_packet {
u8 index;
u8 speed;
u8 mode;
} __packed;
struct ljca_spi_xfer_packet {
u8 indicator;
u8 len;
u8 data[] __counted_by(len);
} __packed;
struct ljca_spi_dev {
struct ljca_client *ljca;
struct spi_controller *controller;
struct ljca_spi_info *spi_info;
u8 speed;
u8 mode;
u8 obuf[LJCA_SPI_BUF_SIZE];
u8 ibuf[LJCA_SPI_BUF_SIZE];
};
static int ljca_spi_read_write(struct ljca_spi_dev *ljca_spi, const u8 *w_data,
u8 *r_data, int len, int id, int complete,
int cmd)
{
struct ljca_spi_xfer_packet *w_packet =
(struct ljca_spi_xfer_packet *)ljca_spi->obuf;
struct ljca_spi_xfer_packet *r_packet =
(struct ljca_spi_xfer_packet *)ljca_spi->ibuf;
int ret;
w_packet->indicator = FIELD_PREP(LJCA_SPI_XFER_INDICATOR_ID, id) |
FIELD_PREP(LJCA_SPI_XFER_INDICATOR_CMPL, complete) |
FIELD_PREP(LJCA_SPI_XFER_INDICATOR_INDEX,
ljca_spi->spi_info->id);
if (cmd == LJCA_SPI_READ) {
w_packet->len = sizeof(u16);
*(__le16 *)&w_packet->data[0] = cpu_to_le16(len);
} else {
w_packet->len = len;
memcpy(w_packet->data, w_data, len);
}
ret = ljca_transfer(ljca_spi->ljca, cmd, (u8 *)w_packet,
struct_size(w_packet, data, w_packet->len),
(u8 *)r_packet, LJCA_SPI_BUF_SIZE);
if (ret < 0)
return ret;
else if (ret < sizeof(*r_packet) || r_packet->len <= 0)
return -EIO;
if (r_data)
memcpy(r_data, r_packet->data, r_packet->len);
return 0;
}
static int ljca_spi_init(struct ljca_spi_dev *ljca_spi, u8 div, u8 mode)
{
struct ljca_spi_init_packet w_packet = {};
int ret;
if (ljca_spi->mode == mode && ljca_spi->speed == div)
return 0;
w_packet.index = ljca_spi->spi_info->id;
w_packet.speed = div;
w_packet.mode = FIELD_PREP(LJCA_SPI_CLK_MODE_POLARITY,
(mode & SPI_CPOL) ? LJCA_SPI_CLOCK_HIGH_POLARITY :
LJCA_SPI_CLOCK_LOW_POLARITY) |
FIELD_PREP(LJCA_SPI_CLK_MODE_PHASE,
(mode & SPI_CPHA) ? LJCA_SPI_CLOCK_SECOND_PHASE :
LJCA_SPI_CLOCK_FIRST_PHASE);
ret = ljca_transfer(ljca_spi->ljca, LJCA_SPI_INIT, (u8 *)&w_packet,
sizeof(w_packet), NULL, 0);
if (ret < 0)
return ret;
ljca_spi->mode = mode;
ljca_spi->speed = div;
return 0;
}
static int ljca_spi_deinit(struct ljca_spi_dev *ljca_spi)
{
Annotation
- Immediate include surface: `linux/auxiliary_bus.h`, `linux/bitfield.h`, `linux/bits.h`, `linux/dev_printk.h`, `linux/module.h`, `linux/spi/spi.h`, `linux/usb/ljca.h`.
- Detected declarations: `struct ljca_spi_init_packet`, `struct ljca_spi_xfer_packet`, `struct ljca_spi_dev`, `enum ljca_spi_cmd`, `function ljca_spi_read_write`, `function ljca_spi_init`, `function ljca_spi_deinit`, `function ljca_spi_transfer`, `function ljca_spi_transfer_one`, `function ljca_spi_probe`.
- 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.