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
*/ staticint 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;
}
/** * 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;
}
/** * amd_axi_w1_read_byte - Performs the read byte function. * * @data: Pointer to device structure * Return: The value read
*/ static u8 amd_axi_w1_read_byte(void *data)
{ 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 0xFF; /* Return inactive bus state */
}
/* 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 0xFF; /* Return inactive bus state */
}
/* Retrieve LSB bit in data register to get RX byte */
val = (u8)(ioread32(amd_axi_w1_local->base_addr + AXIW1_DATA_REG) & 0x000000FF);
/* Clear Go signal in control register */
iowrite32(AXI_CLEAR, amd_axi_w1_local->base_addr + AXIW1_CTRL_REG);
return val;
}
/** * amd_axi_w1_write_byte - Performs the write byte function. * * @data: The ds2482 channel pointer * @val: The value to write
*/ staticvoid amd_axi_w1_write_byte(void *data, u8 val)
{ struct amd_axi_w1_local *amd_axi_w1_local = data; 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;
}
/* Write tx Byte command in instruction register with bit to transmit */
iowrite32(AXIW1_WRITEBYTE + val, amd_axi_w1_local->base_addr + AXIW1_INST_REG);
/* Write Go signal and clear control reset signal in register 1 */
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;
}
/* Clear Go signal in control register */
iowrite32(AXI_CLEAR, amd_axi_w1_local->base_addr + AXIW1_CTRL_REG);
}
/** * amd_axi_w1_reset_bus() - Issues a reset bus sequence. * * @data: the bus host data struct * Return: 0=Device present, 1=No device present or error
*/ static u8 amd_axi_w1_reset_bus(void *data)
{ struct amd_axi_w1_local *amd_axi_w1_local = data;
u8 val = 0; int rc;
/* Reset 1-wire Axi IP */
iowrite32(AXI_RESET, amd_axi_w1_local->base_addr + AXIW1_CTRL_REG);
/* 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; /* Something went wrong with the hardware */
} /* Write Initialization command in instruction register */
iowrite32(AXIW1_INITPRES, amd_axi_w1_local->base_addr + AXIW1_INST_REG);
/* Write Go signal and clear control reset signal in register 1 */
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; /* Something went wrong with the hardware */
} /* Retrieve MSB bit in status register to get failure bit */ if ((ioread32(amd_axi_w1_local->base_addr + AXIW1_STAT_REG) & AXIW1_PRESENCE) != 0)
val = 1;
/* Clear Go signal in control register */
iowrite32(AXI_CLEAR, amd_axi_w1_local->base_addr + AXIW1_CTRL_REG);
return val;
}
/* Reset the 1-wire AXI IP. Put the IP in reset state and clear registers */ staticvoid amd_axi_w1_reset(struct amd_axi_w1_local *amd_axi_w1_local)
{
iowrite32(AXI_RESET, amd_axi_w1_local->base_addr + AXIW1_CTRL_REG);
iowrite32(AXI_CLEAR, amd_axi_w1_local->base_addr + AXIW1_INST_REG);
iowrite32(AXI_CLEAR, amd_axi_w1_local->base_addr + AXIW1_IRQE_REG);
iowrite32(AXI_CLEAR, amd_axi_w1_local->base_addr + AXIW1_STAT_REG);
iowrite32(AXI_CLEAR, amd_axi_w1_local->base_addr + AXIW1_DATA_REG);
}
/* Initialize wait queue and flag */
init_waitqueue_head(&lp->wait_queue);
clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(clk)) return PTR_ERR(clk);
/* Verify IP presence in HW */ if (ioread32(lp->base_addr + AXIW1_IPID_REG) != AXIW1_IPID) {
dev_err(dev, "AMD 1-wire IP not detected in hardware\n"); return -ENODEV;
}
/* * Allow for future driver expansion supporting new hardware features * This driver currently only supports hardware 1.x, but include logic * to detect if a potentially incompatible future version is used * by reading major version ID. It is highly undesirable for new IP versions * to break the API, but this code will at least allow for graceful failure * should that happen. Future new features can be enabled by hardware * incrementing the minor version and augmenting the driver to detect capability * using the minor version number
*/
val = ioread32(lp->base_addr + AXIW1_IPVER_REG);
ver_major = FIELD_GET(AXIW1_MAJORVER_MASK, val);
ver_minor = FIELD_GET(AXIW1_MINORVER_MASK, val);
if (ver_major != 1) {
dev_err(dev, "AMD AXI W1 host version %u.%u is not supported by this driver",
ver_major, ver_minor); return -ENODEV;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.