static void it8709_wait(struct ite_dev *dev) { int i = 0; for (i = 0; i < 15000; i++) { udelay(2); if (it8709_rm(dev, IT8709_MODE) == IT8709_IDLE) break; } }
static int it8709_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size) { int fifo, read = 0; ite_dbg("%s called", __func__); fifo = it8709_rm(dev, IT8709_RFSR) & IT85_RXFBC; while (fifo > 0 && buf_size > 0) { *(buf++) = it8709_rm(dev, IT8709_FIFO + read); fifo--; read++; buf_size--; } it8709_wm(dev, 0, IT8709_RFSR); return read; }
/* read the value of a CIR register */ static u8 it8709_rr(struct ite_dev *dev, int index) { /* just wait in case the previous access was a write */ it8709_wait(dev); it8709_wm(dev, index, IT8709_REG_IDX); it8709_wm(dev, IT8709_READ, IT8709_MODE); /* wait for the read data to be available */ it8709_wait(dev); /* return the read value */ return it8709_rm(dev, IT8709_REG_VAL); }
static void it8709_wait(struct ite_dev *dev) { int i = 0; /* * loop until device tells it's ready to continue * iterations count is usually ~750 but can sometimes achieve 13000 */ for (i = 0; i < 15000; i++) { udelay(2); if (it8709_rm(dev, IT8709_MODE) == IT8709_IDLE) break; } }
static u8 it8709_rr(struct ite_dev *dev, int index) { it8709_wait(dev); it8709_wm(dev, index, IT8709_REG_IDX); it8709_wm(dev, IT8709_READ, IT8709_MODE); it8709_wait(dev); return it8709_rm(dev, IT8709_REG_VAL); }
/* read up to buf_size bytes from the RX FIFO; to be called with the spinlock * held */ static int it8709_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size) { int fifo, read = 0; ite_dbg("%s called", __func__); /* read how many bytes are still in the FIFO */ fifo = it8709_rm(dev, IT8709_RFSR) & IT85_RXFBC; while (fifo > 0 && buf_size > 0) { *(buf++) = it8709_rm(dev, IT8709_FIFO + read); fifo--; read++; buf_size--; } /* 'clear' the FIFO by setting the writing index to 0; this is * completely bound to be racy, but we can't help it, since it's a * limitation of the protocol */ it8709_wm(dev, 0, IT8709_RFSR); return read; }
/* retrieve a bitmask of the current causes for a pending interrupt; this may * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN * */ static int it8709_get_irq_causes(struct ite_dev *dev) { u8 iflags; int ret = 0; ite_dbg("%s called", __func__); /* read the interrupt flags */ iflags = it8709_rm(dev, IT8709_IIR); if (iflags & IT85_TLDLI) ret |= ITE_IRQ_TX_FIFO; if (iflags & IT85_RDAI) ret |= ITE_IRQ_RX_FIFO; if (iflags & IT85_RFOI) ret |= ITE_IRQ_RX_FIFO_OVERRUN; return ret; }