/* Do low-level i2c byte transfer. * Returns -1 in case of an error or 0 otherwise.
*/ staticint cobalt_tx_bytes(struct cobalt_i2c_regs __iomem *regs, struct i2c_adapter *adap, bool start, bool stop,
u8 *data, u16 len)
{ unsignedlong start_time; int status; int cmd; int i;
for (i = 0; i < len; i++) { /* Setup data */
iowrite8(data[i], ®s->txr_rxr);
/* Wait for transfer to complete (TIP = 0) */
start_time = jiffies;
status = ioread8(®s->cr_sr); while (status & M00018_SR_BITMAP_TIP_MSK) { if (time_after(jiffies, start_time + adap->timeout)) return -ETIMEDOUT;
cond_resched();
status = ioread8(®s->cr_sr);
}
/* Verify ACK */ if (status & M00018_SR_BITMAP_RXACK_MSK) { /* NO ACK! */ return -EIO;
}
/* Do low-level i2c byte read. * Returns -1 in case of an error or 0 otherwise.
*/ staticint cobalt_rx_bytes(struct cobalt_i2c_regs __iomem *regs, struct i2c_adapter *adap, bool start, bool stop,
u8 *data, u16 len)
{ unsignedlong start_time; int status; int cmd; int i;
for (i = 0; i < len; i++) { /* Setup command */ if (i == 0 && start) { /* Read + Start */
cmd = M00018_CR_BITMAP_RD_MSK |
M00018_CR_BITMAP_STA_MSK;
} elseif (i == len - 1 && stop) { /* Read + Stop */
cmd = M00018_CR_BITMAP_RD_MSK |
M00018_CR_BITMAP_STO_MSK;
} else { /* Read only */
cmd = M00018_CR_BITMAP_RD_MSK;
}
/* Last byte to read, no ACK */ if (i == len - 1)
cmd |= M00018_CR_BITMAP_ACK_MSK;
/* Wait for transfer to complete (TIP = 0) */
start_time = jiffies;
status = ioread8(®s->cr_sr); while (status & M00018_SR_BITMAP_TIP_MSK) { if (time_after(jiffies, start_time + adap->timeout)) return -ETIMEDOUT;
cond_resched();
status = ioread8(®s->cr_sr);
}
/* Store data */
data[i] = ioread8(®s->txr_rxr);
} return 0;
}
/* Generate stop condition on i2c bus. * The m00018 stop isn't doing the right thing (wrong timing). * So instead send a start condition, 8 zeroes and a stop condition.
*/ staticint cobalt_stop(struct cobalt_i2c_regs __iomem *regs, struct i2c_adapter *adap)
{
u8 data = 0;
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.