drivers/spmi/spmi-apple-controller.c
Source file repositories/reference/linux-study-clean/drivers/spmi/spmi-apple-controller.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spmi/spmi-apple-controller.c- Extension
.c- Size
- 3994 bytes
- Lines
- 170
- Domain
- Driver Families
- Bucket
- drivers/spmi
- 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/io.hlinux/iopoll.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/spmi.h
Detected Declarations
struct apple_spmifunction apple_spmi_pack_cmdfunction apple_spmi_wait_rx_not_emptyfunction spmi_read_cmdfunction spmi_write_cmdfunction apple_spmi_probe
Annotated Snippet
struct apple_spmi {
void __iomem *regs;
};
#define poll_reg(spmi, reg, val, cond) \
readl_poll_timeout((spmi)->regs + (reg), (val), (cond), \
REG_POLL_INTERVAL_US, REG_POLL_TIMEOUT_US)
static inline u32 apple_spmi_pack_cmd(u8 opc, u8 sid, u16 saddr, size_t len)
{
return opc | sid << 8 | saddr << 16 | (len - 1) | (1 << 15);
}
/* Wait for Rx FIFO to have something */
static int apple_spmi_wait_rx_not_empty(struct spmi_controller *ctrl)
{
struct apple_spmi *spmi = spmi_controller_get_drvdata(ctrl);
int ret;
u32 status;
ret = poll_reg(spmi, SPMI_STATUS_REG, status, !(status & SPMI_RX_FIFO_EMPTY));
if (ret) {
dev_err(&ctrl->dev,
"failed to wait for RX FIFO not empty\n");
return ret;
}
return 0;
}
static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
u16 saddr, u8 *buf, size_t len)
{
struct apple_spmi *spmi = spmi_controller_get_drvdata(ctrl);
u32 spmi_cmd = apple_spmi_pack_cmd(opc, sid, saddr, len);
u32 rsp;
size_t len_read = 0;
u8 i;
int ret;
writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
ret = apple_spmi_wait_rx_not_empty(ctrl);
if (ret)
return ret;
/* Discard SPMI reply status */
readl(spmi->regs + SPMI_RSP_REG);
/* Read SPMI data reply */
while (len_read < len) {
rsp = readl(spmi->regs + SPMI_RSP_REG);
i = 0;
while ((len_read < len) && (i < 4)) {
buf[len_read++] = ((0xff << (8 * i)) & rsp) >> (8 * i);
i += 1;
}
}
return 0;
}
static int spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
u16 saddr, const u8 *buf, size_t len)
{
struct apple_spmi *spmi = spmi_controller_get_drvdata(ctrl);
u32 spmi_cmd = apple_spmi_pack_cmd(opc, sid, saddr, len);
size_t i = 0, j;
int ret;
writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
while (i < len) {
j = 0;
spmi_cmd = 0;
while ((j < 4) & (i < len))
spmi_cmd |= buf[i++] << (j++ * 8);
writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
}
ret = apple_spmi_wait_rx_not_empty(ctrl);
if (ret)
return ret;
/* Discard */
readl(spmi->regs + SPMI_RSP_REG);
return 0;
}
Annotation
- Immediate include surface: `linux/io.h`, `linux/iopoll.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/spmi.h`.
- Detected declarations: `struct apple_spmi`, `function apple_spmi_pack_cmd`, `function apple_spmi_wait_rx_not_empty`, `function spmi_read_cmd`, `function spmi_write_cmd`, `function apple_spmi_probe`.
- Atlas domain: Driver Families / drivers/spmi.
- 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.