drivers/spi/spi-cs42l43.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-cs42l43.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-cs42l43.c- Extension
.c- Size
- 12208 bytes
- Lines
- 460
- 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.
- 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/acpi.hlinux/array_size.hlinux/bits.hlinux/bitfield.hlinux/cleanup.hlinux/device.hlinux/errno.hlinux/gpio/consumer.hlinux/gpio/machine.hlinux/gpio/property.hlinux/mfd/cs42l43.hlinux/mfd/cs42l43-regs.hlinux/mod_devicetable.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/pm_runtime.hlinux/property.hlinux/regmap.hlinux/spi/spi.hlinux/units.h
Detected Declarations
struct cs42l43_spienum cs42l43_spi_cmdfunction cs42l43_spi_txfunction cs42l43_spi_rxfunction cs42l43_transfer_onefunction cs42l43_set_csfunction cs42l43_prepare_messagefunction cs42l43_prepare_transfer_hardwarefunction cs42l43_unprepare_transfer_hardwarefunction cs42l43_spi_max_lengthfunction cs42l43_get_speaker_id_gpiosfunction fwnode_for_each_child_nodefunction cs42l43_release_of_nodefunction cs42l43_spi_probe
Annotated Snippet
struct cs42l43_spi {
struct device *dev;
struct regmap *regmap;
struct spi_controller *ctlr;
};
static const unsigned int cs42l43_clock_divs[] = {
2, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
};
static struct spi_board_info amp_info_template = {
.modalias = "cs35l56",
.max_speed_hz = 11 * HZ_PER_MHZ,
.mode = SPI_MODE_0,
};
static int cs42l43_spi_tx(struct regmap *regmap, const u8 *buf, unsigned int len)
{
const u8 *end = buf + len;
u32 val = 0;
int ret;
while (buf < end) {
const u8 *block = min(buf + CS42L43_FIFO_SIZE, end);
while (buf < block) {
const u8 *word = min(buf + sizeof(u32), block);
int pad = (buf + sizeof(u32)) - word;
while (buf < word) {
val >>= BITS_PER_BYTE;
val |= FIELD_PREP(GENMASK(31, 24), *buf);
buf++;
}
val >>= pad * BITS_PER_BYTE;
regmap_write(regmap, CS42L43_TX_DATA, val);
}
regmap_write(regmap, CS42L43_TRAN_CONFIG8, CS42L43_SPI_TX_DONE_MASK);
ret = regmap_read_poll_timeout(regmap, CS42L43_TRAN_STATUS1,
val, (val & CS42L43_SPI_TX_REQUEST_MASK),
1000, 5000);
if (ret)
return ret;
}
return 0;
}
static int cs42l43_spi_rx(struct regmap *regmap, u8 *buf, unsigned int len)
{
u8 *end = buf + len;
u32 val;
int ret;
while (buf < end) {
u8 *block = min(buf + CS42L43_FIFO_SIZE, end);
ret = regmap_read_poll_timeout(regmap, CS42L43_TRAN_STATUS1,
val, (val & CS42L43_SPI_RX_REQUEST_MASK),
1000, 5000);
if (ret)
return ret;
while (buf < block) {
u8 *word = min(buf + sizeof(u32), block);
ret = regmap_read(regmap, CS42L43_RX_DATA, &val);
if (ret)
return ret;
while (buf < word) {
*buf = FIELD_GET(GENMASK(7, 0), val);
val >>= BITS_PER_BYTE;
buf++;
}
}
regmap_write(regmap, CS42L43_TRAN_CONFIG8, CS42L43_SPI_RX_DONE_MASK);
}
return 0;
}
static int cs42l43_transfer_one(struct spi_controller *ctlr, struct spi_device *spi,
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/array_size.h`, `linux/bits.h`, `linux/bitfield.h`, `linux/cleanup.h`, `linux/device.h`, `linux/errno.h`, `linux/gpio/consumer.h`.
- Detected declarations: `struct cs42l43_spi`, `enum cs42l43_spi_cmd`, `function cs42l43_spi_tx`, `function cs42l43_spi_rx`, `function cs42l43_transfer_one`, `function cs42l43_set_cs`, `function cs42l43_prepare_message`, `function cs42l43_prepare_transfer_hardware`, `function cs42l43_unprepare_transfer_hardware`, `function cs42l43_spi_max_length`.
- 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.