/* * this is the low level routine to read/write a bit on the One Wire * interface on the hardware. It does write 0 if parameter bit is set * to 0, otherwise a write 1/read. */ static u8 mxc_w1_ds2_touch_bit(void *data, u8 bit) { struct mxc_w1_device *mdev = data; void __iomem *ctrl_addr = mdev->regs + MXC_W1_CONTROL; unsigned int timeout_cnt = 400; /* Takes max. 120us according to * datasheet. */ writeb(MXC_W1_CONTROL_WR(bit), ctrl_addr); while (timeout_cnt--) { if (!(readb(ctrl_addr) & MXC_W1_CONTROL_WR(bit))) break; udelay(1); } return !!(readb(ctrl_addr) & MXC_W1_CONTROL_RDST); }
/* * this is the low level routine to read/write a bit on the One Wire * interface on the hardware. It does write 0 if parameter bit is set * to 0, otherwise a write 1/read. */ static u8 mxc_w1_ds2_touch_bit(void *data, u8 bit) { struct mxc_w1_device *dev = data; unsigned long timeout; writeb(MXC_W1_CONTROL_WR(bit), dev->regs + MXC_W1_CONTROL); /* Wait for read/write bit (60us, Max 120us), use 200us for sure */ timeout = jiffies + usecs_to_jiffies(200); udelay(60); do { u8 ctrl = readb(dev->regs + MXC_W1_CONTROL); /* RDST bit is valid after the WR1/RD bit is self-cleared */ if (!(ctrl & MXC_W1_CONTROL_WR(bit))) return !!(ctrl & MXC_W1_CONTROL_RDST); } while (time_is_after_jiffies(timeout)); return 0; }