drivers/w1/masters/amd_axi_w1.c
Source file repositories/reference/linux-study-clean/drivers/w1/masters/amd_axi_w1.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/w1/masters/amd_axi_w1.c- Extension
.c- Size
- 12169 bytes
- Lines
- 397
- Domain
- Driver Families
- Bucket
- drivers/w1
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/atomic.hlinux/bitfield.hlinux/clk.hlinux/interrupt.hlinux/io.hlinux/jiffies.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/types.hlinux/wait.hlinux/w1.h
Detected Declarations
struct amd_axi_w1_localfunction amd_axi_w1_wait_irq_interruptible_timeoutfunction amd_axi_w1_touch_bitfunction amd_axi_w1_read_bytefunction amd_axi_w1_write_bytefunction amd_axi_w1_reset_busfunction amd_axi_w1_resetfunction amd_axi_w1_irqfunction amd_axi_w1_probefunction amd_axi_w1_remove
Annotated Snippet
struct amd_axi_w1_local {
struct device *dev;
void __iomem *base_addr;
int irq;
atomic_t flag; /* Set on IRQ, cleared once serviced */
wait_queue_head_t wait_queue;
struct w1_bus_master bus_host;
};
/**
* amd_axi_w1_wait_irq_interruptible_timeout() - Wait for IRQ with timeout.
*
* @amd_axi_w1_local: Pointer to device structure
* @IRQ: IRQ channel to wait on
*
* Return: %0 - OK, %-EINTR - Interrupted, %-EBUSY - Timed out
*/
static int amd_axi_w1_wait_irq_interruptible_timeout(struct amd_axi_w1_local *amd_axi_w1_local,
u32 IRQ)
{
int ret;
/* Enable the IRQ requested and wait for flag to indicate it's been triggered */
iowrite32(IRQ, amd_axi_w1_local->base_addr + AXIW1_IRQE_REG);
ret = wait_event_interruptible_timeout(amd_axi_w1_local->wait_queue,
atomic_read(&amd_axi_w1_local->flag) != 0,
AXIW1_TIMEOUT);
if (ret < 0) {
dev_err(amd_axi_w1_local->dev, "Wait IRQ Interrupted\n");
return -EINTR;
}
if (!ret) {
dev_err(amd_axi_w1_local->dev, "Wait IRQ Timeout\n");
return -EBUSY;
}
atomic_set(&amd_axi_w1_local->flag, 0);
return 0;
}
/**
* amd_axi_w1_touch_bit() - Performs the touch-bit function - write a 0 or 1 and reads the level.
*
* @data: Pointer to device structure
* @bit: The level to write
*
* Return: The level read
*/
static u8 amd_axi_w1_touch_bit(void *data, u8 bit)
{
struct amd_axi_w1_local *amd_axi_w1_local = data;
u8 val = 0;
int rc;
/* Wait for READY signal to be 1 to ensure 1-wire IP is ready */
while ((ioread32(amd_axi_w1_local->base_addr + AXIW1_STAT_REG) & AXIW1_READY) == 0) {
rc = amd_axi_w1_wait_irq_interruptible_timeout(amd_axi_w1_local,
AXIW1_READY_IRQ_EN);
if (rc < 0)
return 1; /* Callee doesn't test for error. Return inactive bus state */
}
if (bit)
/* Read. Write read Bit command in register 0 */
iowrite32(AXIW1_READBIT, amd_axi_w1_local->base_addr + AXIW1_INST_REG);
else
/* Write. Write tx Bit command in instruction register with bit to transmit */
iowrite32(AXIW1_WRITEBIT + (bit & 0x01),
amd_axi_w1_local->base_addr + AXIW1_INST_REG);
/* Write Go signal and clear control reset signal in control register */
iowrite32(AXIW1_GO, amd_axi_w1_local->base_addr + AXIW1_CTRL_REG);
/* Wait for done signal to be 1 */
while ((ioread32(amd_axi_w1_local->base_addr + AXIW1_STAT_REG) & AXIW1_DONE) != 1) {
rc = amd_axi_w1_wait_irq_interruptible_timeout(amd_axi_w1_local, AXIW1_DONE_IRQ_EN);
if (rc < 0)
return 1; /* Callee doesn't test for error. Return inactive bus state */
}
/* If read, Retrieve data from register */
if (bit)
val = (u8)(ioread32(amd_axi_w1_local->base_addr + AXIW1_DATA_REG) & AXIW1_READDATA);
/* Clear Go signal in register 1 */
iowrite32(AXI_CLEAR, amd_axi_w1_local->base_addr + AXIW1_CTRL_REG);
return val;
}
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/bitfield.h`, `linux/clk.h`, `linux/interrupt.h`, `linux/io.h`, `linux/jiffies.h`, `linux/kernel.h`, `linux/mod_devicetable.h`.
- Detected declarations: `struct amd_axi_w1_local`, `function amd_axi_w1_wait_irq_interruptible_timeout`, `function amd_axi_w1_touch_bit`, `function amd_axi_w1_read_byte`, `function amd_axi_w1_write_byte`, `function amd_axi_w1_reset_bus`, `function amd_axi_w1_reset`, `function amd_axi_w1_irq`, `function amd_axi_w1_probe`, `function amd_axi_w1_remove`.
- Atlas domain: Driver Families / drivers/w1.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.