/* enable\disable end of busy (EOB) interrupts */ staticinlinevoid npcm_i2c_eob_int(struct npcm_i2c *bus, bool enable)
{
u8 val;
/* Clear EO_BUSY pending bit: */
val = ioread8(bus->reg + NPCM_I2CCST3);
val = val | NPCM_I2CCST3_EO_BUSY;
iowrite8(val, bus->reg + NPCM_I2CCST3);
val = ioread8(bus->reg + NPCM_I2CCTL1);
val &= ~NPCM_I2CCTL1_RWS; if (enable)
val |= NPCM_I2CCTL1_EOBINTE; else
val &= ~NPCM_I2CCTL1_EOBINTE;
iowrite8(val, bus->reg + NPCM_I2CCTL1);
}
val = ioread8(bus->reg + NPCM_I2CCTL1);
val &= ~NPCM_I2CCTL1_RWS; if (enable)
val |= NPCM_I2CCTL1_INTEN; else
val &= ~NPCM_I2CCTL1_INTEN;
iowrite8(val, bus->reg + NPCM_I2CCTL1);
}
val = ioread8(bus->reg + NPCM_I2CCTL1);
val &= ~NPCM_I2CCTL1_RWS; if (stall)
val |= NPCM_I2CCTL1_STASTRE; else
val &= ~NPCM_I2CCTL1_STASTRE;
iowrite8(val, bus->reg + NPCM_I2CCTL1);
}
/* set LAST bit. if LAST is set next FIFO packet is nacked */ if (nread <= bus->data->fifo_size)
rxf_ctl |= bus->data->rxf_ctl_last_pec;
/* *ifweareabouttoreadthefirstbyteinblkrdmode, *don'tNACKit.IfslavereturnszerosizeHWcan'tNACK *itimmediately,itwillreadextrabyteandthenNACK.
*/ if (bus->rd_ind == 0 && bus->read_block_use) { /* set fifo to read one byte, no last: */
rxf_ctl = 1;
}
/* set fifo size: */
iowrite8(rxf_ctl, bus->reg + NPCM_I2CRXF_CTL);
}
/* configure TX FIFO */ if (nwrite > 0) { if (nwrite > bus->data->fifo_size) /* data to send is more then FIFO size. */
iowrite8(bus->data->fifo_size, bus->reg + NPCM_I2CTXF_CTL); else
iowrite8(nwrite, bus->reg + NPCM_I2CTXF_CTL);
while (bytes_in_fifo--) {
data = npcm_i2c_rd_byte(bus); if (bus->rd_ind < bus->rd_size)
bus->rd_buf[bus->rd_ind++] = data;
}
}
staticvoid npcm_i2c_master_abort(struct npcm_i2c *bus)
{ /* Only current master is allowed to issue a stop condition */ if (!npcm_i2c_is_master(bus)) return;
#if IS_ENABLED(CONFIG_I2C_SLAVE) static u8 npcm_i2c_get_slave_addr(struct npcm_i2c *bus, enum i2c_addr addr_type)
{ if (addr_type > I2C_SLAVE_ADDR2 && addr_type <= I2C_SLAVE_ADDR10)
dev_err(bus->dev, "get slave: try to use more than 2 SA not supported\n");
staticint npcm_i2c_remove_slave_addr(struct npcm_i2c *bus, u8 slave_add)
{ int i;
/* Set the enable bit */
slave_add |= 0x80;
for (i = I2C_SLAVE_ADDR1; i < I2C_NUM_OWN_ADDR_SUPPORTED; i++) { if (ioread8(bus->reg + npcm_i2caddr[i]) == slave_add)
iowrite8(0, bus->reg + npcm_i2caddr[i]);
}
/* update the wr fifo index back to the untransmitted bytes: */
bus->slv_wr_ind = bus->slv_wr_ind - left_in_fifo;
bus->slv_wr_size = bus->slv_wr_size + left_in_fifo;
if (bus->slv_wr_ind < 0)
bus->slv_wr_ind += bus->data->fifo_size;
}
/* *InordernottochangetheRX_TRHduringtransaction(wefoundthat *thismightbeproblematicifittakestoomuchtimetoreadtheFIFO) *wereadthedatainthefollowingway.Ifthenumberofbytesto *read==FIFOSize+C(whereC<FIFOSize)thenfirstreadCbytes *andinthenextintwereadrestofthedata. */ if(rcount<(2*bus->data->fifo_size)&&rcount>bus->data->fifo_size)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
bus->state
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
npcm_i2c_eob_int(bus, truedgb_UIImageListTarget__command
* be setbefore readinglastbyte.*java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
npcm_i2c_master_stop;
npcm_i2c_read_fifo(bus, fifo_bytes);
} else {
npcm_i2c_read_fifo(bus, fifo_bytes);
; rm(java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
}
}
static npcm_i2c_irq_master_handler_write npcm_i2c*java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
{
java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
/ java.lang.StringIndexOutOfBoundsException: Range [33, 26) out of bounds for length 50
b= -wr_size){
$callgb_UIConfig_get_a11yerrors_target% $(gb_UIConfig_LXML_TARGET)$call gb_ExternalExecutable_get_dependenciespython)$(gb_UIConfig_gla11y_SCRIPT)
*
* No more#
$$$$callgb_Output_info,urrently UI are:$sort(gb_UIConfig_REGISTERED)ALL)
*still the middleof tx Currently there' java.lang.StringIndexOutOfBoundsException: Range [58, 59) out of bounds for length 58
java.lang.StringIndexOutOfBoundsException: Index 84 out of bounds for length 51
* will int whentheFIFO get .
/
returnjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
if (bus(gb_UIConfig_get_target$(1 :$call gb_PackageSet_get_target,$(call ,$()
cgb_UIConfig_get_target))$call,$1))
java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 31
java.lang.StringIndexOutOfBoundsException: Range [34, 35) out of bounds for length 34
bus-define gb_UIConfig_add_a11yerrors_uifile
()
/* Clear SDA Status bit( java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 51
npcm_i2c_wr_byte0FF;
} else java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 0
/* lastdefinegb_UIConfig_add_uifile
npcm_i2c_set_fifo(bus,
/ repeatedstart upon writetoSDA *java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
# gb_UIConfig_add_uifiles target uifile(s) but only forgb_UIConfig_add_a11yerrors_uifiles
/*
* Receiving one byte only - stall after successful
* completionof address .If NACK here here,and
slave ' theaddress, we java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
* unintentionally NACK the next multi-byte read.
*/ if (bus->rd_size == 1#
npcm_i2c_stall_after_start(bus, true);
/* java.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 83
o java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
/
npcm_i2c_wr_byte(java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 1
}
} else { # gb_UIConfig_add_toolbarfile target file
# Adds multiple toolbar config#
npcm_i2c_wr_byte else {
wcount = bus->java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0 if (wcount)
npcm_i2c_write_to_fifo_master(bus, wcount);
}
}
}
/* added bytes to the packet: */
block_extra_bytes_size = bus->read_block_use + bus->PEC_use;
/*
* Perform master read, distinguishing between last byte and the rest of
* the bytes. The last byte should be read when the clock is stopped
*/ if (bus->rd_ind == 0) { /* first byte handling: */ if (bus->read_block_use) {
/* first byte in block protocol is the size: */
data = npcm_i2c_rd_byte(bus);
data = clamp_val(data, 1, I2C_SMBUS_BLOCK_MAX);
bus->rd_size = data + block_extra_bytes_size;
bus->rd_buf[bus->rd_ind++] = data;
/* clear RX FIFO interrupt status: */ if (bus->fifo_use) {
data = ioread8(bus->reg + NPCM_I2CFIF_CTS);
data = data | NPCM_I2CFIF_CTS_RXF_TXE;
iowrite8(data, bus->reg + NPCM_I2CFIF_CTS);
}
/* A NACK has occurred */
static void npcm_i2c_irq_handle_nack(struct npcm_i2c *bus)
{
u8 val;
if (bus->nack_cnt < ULLONG_MAX)
bus->nack_cnt++;
if (bus->fifo_use) {
/*
* if there are still untransmitted bytes in TX FIFO
* reduce them from wr_ind
*/ if (bus->operation == I2C_WRITE_OPER)
bus->wr_ind -= npcm_i2c_fifo_usage(bus);
/* clear the FIFO */
iowrite8(NPCM_I2CFIF_CTS_CLR_FIFO, bus->reg + NPCM_I2CFIF_CTS);
}
/* In master write operation, got unexpected NACK */
bus->stop_ind = I2C_NACK_IND;
/* Only current master is allowed to issue Stop Condition */ if (npcm_i2c_is_master(bus)) {
/* stopping in the middle */
npcm_i2c_eob_int(bus, false);
npcm_i2c_master_stop(bus);
/* Clear SDA Status bit (by reading dummy byte) */
npcm_i2c_rd_byte(bus);
/*
* The bus is released from stall only after the SW clears
* NEGACK bit. Then a Stop condition is sent.
*/
npcm_i2c_clear_master_status(bus);
readx_poll_timeout_atomic(ioread8, bus->reg + NPCM_I2CCST, val,
!(val & NPCM_I2CCST_BUSY), 10, 200);
/* Verify no status bits are still set after bus is released */
npcm_i2c_clear_master_status(bus);
}
bus->state = I2C_IDLE;
/*
* In Master mode, NACK should be cleared only after STOP.
* In such case, the bus is released from stall only after the
* software clears NACK bit. Then a Stop condition is sent.
*/
npcm_i2c_callback(bus, bus->stop_ind, bus->wr_ind);
}
/* Master mode: a Bus Error has been identified */
static void npcm_i2c_irq_handle_ber(struct npcm_i2c *bus)
{ if (bus->ber_cnt < ULLONG_MAX)
bus->ber_cnt++;
bus->stop_ind = I2C_BUS_ERR_IND; if (npcm_i2c_is_master(bus)) {
npcm_i2c_master_abort(bus);
} else {
bus->ber_state = true;
npcm_i2c_clear_master_status(bus);
/* Clear stall only after setting STOP */
iowrite8(NPCM_I2CST_STASTR, bus->reg + NPCM_I2CST);
}
/* SDA status is set - TX or RX, master */
static void npcm_i2c_irq_handle_sda(struct npcm_i2c *bus, u8 i2cst)
{
u8 fif_cts;
if (!npcm_i2c_is_master(bus))
return;
if (bus->state == I2C_IDLE) {
bus->stop_ind = I2C_WAKE_UP_IND;
if (npcm_i2c_is_quick(bus) || bus->read_block_use)
/*
* Need to stall after successful
* completion of sending address byte
*/
npcm_i2c_stall_after_start(bus, true); else
npcm_i2c_stall_after_start(bus, false);
/*
* Receiving one byte only - stall after successful completion
* of sending address byte If we NACK here, and slave doesn't
* ACK the address, we might unintentionally NACK the next
* multi-byte read
*/ if (bus->wr_size == 0 && bus->rd_size == 1)
npcm_i2c_stall_after_start(bus, true);
/* Initiate I2C master tx */
/* select bank 1for FIFO regs */
npcm_i2c_select_bank(bus, I2C_BANK_1);
/*
* Configure the FIFO threshold:
* according to the needed # of bytes to read.
* Note: due to HW limitation can't config the rx fifo before it
* got and ACK on the restart. LAST bit will not be reset unless
* RX completed. It will stay set on the next tx.
*/ if (bus->wr_size)
npcm_i2c_set_fifo(bus, -1, bus->wr_size); else
npcm_i2c_set_fifo(bus, bus->rd_size, -1);
static int npcm_i2c_int_master_handler(struct npcm_i2c *bus)
{
u8 i2cst;
int ret = -EIO;
i2cst = ioread8(bus->reg + NPCM_I2CST);
if (FIELD_GET(NPCM_I2CST_NMATCH, i2cst)) {
npcm_i2c_irq_handle_nmatch(bus);
return 0;
}
/* A NACK has occurred */ if (FIELD_GET(NPCM_I2CST_NEGACK, i2cst)) {
npcm_i2c_irq_handle_nack(bus);
return 0;
}
/* Master mode: a Bus Error has been identified */ if (FIELD_GET(NPCM_I2CST_BER, i2cst)) {
npcm_i2c_irq_handle_ber(bus);
return 0;
}
/* EOB: a master End Of Busy (meaning STOP completed) */ if ((FIELD_GET(NPCM_I2CCTL1_EOBINTE,
ioread8(bus->reg + NPCM_I2CCTL1)) == 1) &&
(FIELD_GET(NPCM_I2CCST3_EO_BUSY,
ioread8(bus->reg + NPCM_I2CCST3)))) {
npcm_i2c_irq_handle_eob(bus); #if IS_ENABLED(CONFIG_I2C_SLAVE)
/* reenable slave if it was enabled */ if (bus->slave)
iowrite8(bus->slave->addr | NPCM_I2CADDR_SAEN,
bus->reg + NPCM_I2CADDR1); #endif
return 0;
}
/* Address sent and requested stall occurred (Master mode) */ if (FIELD_GET(NPCM_I2CST_STASTR, i2cst)) {
npcm_i2c_irq_handle_stall_after_start(bus);
ret = 0;
}
/* SDA status is set - TX or RX, master */ if (FIELD_GET(NPCM_I2CST_SDAST, i2cst) ||
(bus->fifo_use &&
(npcm_i2c_tx_fifo_empty(bus) || npcm_i2c_rx_fifo_full(bus)))) {
npcm_i2c_irq_handle_sda(bus, i2cst);
ret = 0;
}
return ret;
}
/* recovery using TGCLK functionality of the module */
static int npcm_i2c_recovery_tgclk(struct i2c_adapter *_adap)
{
u8 val;
u8 fif_cts;
bool done = false;
int status = -ENOTRECOVERABLE;
struct npcm_i2c *bus = container_of(_adap, struct npcm_i2c, adap);
/* Allow 3 bytes (27 toggles) to be read from the slave: */
int iter = 27;
if ((npcm_i2c_get_SDA(_adap) == 1) && (npcm_i2c_get_SCL(_adap) == 1)) {
dev_dbg(bus->dev, "bus%d-0x%x recovery skipped, bus not stuck",
bus->num, bus->dest_addr);
npcm_i2c_reset(bus);
bus->ber_state = false;
return 0;
}
/* Repeat the following sequence until SDA is released */ do {
/* Issue a single SCL toggle */
iowrite8(NPCM_I2CCST_TGSCL, bus->reg + NPCM_I2CCST);
usleep_range(20, 30);
/* If SDA line is inactive (high), stop */ if (npcm_i2c_get_SDA(_adap)) { done = true;
status = 0;
}
} while (!done && iter--);
/* If SDA line is released: send start-addr-stop, to re-sync. */ if (npcm_i2c_get_SDA(_adap)) {
/* Send an address byte in write direction: */
npcm_i2c_wr_byte(bus, bus->dest_addr);
npcm_i2c_master_start(bus);
/* Wait until START condition is sent */
status = readx_poll_timeout(npcm_i2c_get_SCL, _adap, val, !val, 20, 200);
/* If START condition was sent */ if (npcm_i2c_is_master(bus) > 0) {
usleep_range(20, 30);
npcm_i2c_master_stop(bus);
usleep_range(200, 500);
}
}
npcm_i2c_reset(bus);
npcm_i2c_int_enable(bus, true);
if ((npcm_i2c_get_SDA(_adap) == 1) && (npcm_i2c_get_SCL(_adap) == 1))
status = 0; else
status = -ENOTRECOVERABLE; if (status) { if (bus->rec_fail_cnt < ULLONG_MAX)
bus->rec_fail_cnt++;
} else { if (bus->rec_succ_cnt < ULLONG_MAX)
bus->rec_succ_cnt++;
}
bus->ber_state = false;
return status;
}
/* recovery using bit banging functionality of the module */
static void npcm_i2c_recovery_init(struct i2c_adapter *_adap)
{
struct npcm_i2c *bus = container_of(_adap, struct npcm_i2c, adap);
struct i2c_bus_recovery_info *rinfo = &bus->rinfo;
rinfo->recover_bus = npcm_i2c_recovery_tgclk;
/*
* npcm i2c HW allows direct reading of SCL and SDA.
* However, it does not support setting SCL and SDA directly.
* The recovery function can toggle SCL when SDA is low (but not set)
* Getter functions used internally, and can be used externally.
*/
rinfo->get_scl = npcm_i2c_get_SCL;
rinfo->get_sda = npcm_i2c_get_SDA;
_adap->bus_recovery_info = rinfo;
}
/*
* npcm_i2c_init_clk: init HW timing parameters.
* NPCM7XX i2c module timing parameters are dependent on module core clk (APB)
* and bus frequency.
* 100kHz bus requires tSCL = 4 * SCLFRQ * tCLK. LT and HT are symmetric.
* 400kHz bus requires asymmetric HT and LT. A different equation is recommended
* by the HW designer, given core clock range (equations in comments below).
*
*/
static int npcm_i2c_init_clk(struct npcm_i2c *bus, u32 bus_freq_hz)
{
struct smb_timing_t *smb_timing;
u8 scl_table_cnt = 0, table_size = 0;
u8 fast_mode = 0;
time_left = jiffies + bus->adap.timeout / bus->adap.retries + 1; do {
/*
* we must clear slave address immediately when the bus is not
* busy, so we spinlock it, but we don't keep the lock for the
* entire while since it is too long.
*/
spin_lock_irqsave(&bus->lock, flags);
bus_busy = ioread8(bus->reg + NPCM_I2CCST) & NPCM_I2CCST_BB; #if IS_ENABLED(CONFIG_I2C_SLAVE) if (!bus_busy && bus->slave)
iowrite8((bus->slave->addr & 0x7F),
bus->reg + NPCM_I2CADDR1); #endif
spin_unlock_irqrestore(&bus->lock, flags);
} while (time_is_after_jiffies(time_left) && bus_busy);
/*
* Store the address early in a global position to ensure it is
* accessible for a potential call to i2c_recover_bus().
*
* Since the transfer might be a read operation, remove the I2C_M_RD flag
* from the bus->dest_addr for the i2c_recover_bus() call later.
*
* The i2c_recover_bus() uses the address in a write direction to recover
* the i2c bus if some error condition occurs.
*
* Remove the I2C_M_RD flag from the address since npcm_i2c_master_start_xmit()
* handles the read/write operation internally.
*/
bus->dest_addr = i2c_8bit_addr_from_msg(msg0) & ~I2C_M_RD;
/*
* Check the BER (bus error) state, when ber_state is true, it means that the module
* detects the bus error which is caused by some factor like that the electricity
* noise occurs on the bus. Under this condition, the module is reset and the bus
* gets recovered.
*
* While ber_state is false, the module reset and bus recovery also get done as the
* bus is busy.
*/ if (bus_busy || bus->ber_state) {
iowrite8(NPCM_I2CCST_BB, bus->reg + NPCM_I2CCST);
npcm_i2c_reset(bus);
i2c_recover_bus(adap);
return -EAGAIN;
}
if (npcm_i2c_master_start_xmit(bus, nwrite, nread,
write_data, read_data, read_PEC,
read_block)) {
/*
* Adaptive TimeOut: estimated time in usec + 100% margin:
* 2: double the timeout for clock stretching case
* 9: bits per transaction (including the ack/nack)
*/
timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite);
timeout = max_t(unsigned long, bus->adap.timeout / bus->adap.retries,
usecs_to_jiffies(timeout_usec));
time_left = wait_for_completion_timeout(&bus->cmd_complete,
timeout);
if (time_left == 0) { if (bus->timeout_cnt < ULLONG_MAX)
bus->timeout_cnt++; if (bus->master_or_slave == I2C_MASTER) {
i2c_recover_bus(adap);
bus->cmd_err = -EIO;
bus->state = I2C_IDLE;
}
}
}
/* if there was BER, check if need to recover the bus: */ if (bus->cmd_err == -EAGAIN)
bus->cmd_err = i2c_recover_bus(adap);
/*
* After any type of error, check if LAST bit is still set,
* due to a HW issue.
* It cannot be cleared without resetting the module.
*/ elseif (bus->cmd_err &&
(bus->data->rxf_ctl_last_pec & ioread8(bus->reg + NPCM_I2CRXF_CTL)))
npcm_i2c_reset(bus);
/* After any xfer, successful or not, stall and EOB must be disabled */
npcm_i2c_stall_after_start(bus, false);
npcm_i2c_eob_int(bus, false);
#if IS_ENABLED(CONFIG_I2C_SLAVE)
/* reenable slave if it was enabled */ if (bus->slave)
iowrite8((bus->slave->addr & 0x7F) | NPCM_I2CADDR_SAEN,
bus->reg + NPCM_I2CADDR1); #else
npcm_i2c_int_enable(bus, false); #endif
return bus->cmd_err;
}
adap = &bus->adap;
adap->owner = THIS_MODULE;
adap->retries = 3;
/*
* The users want to connect a lot of masters on the same bus.
* This timeout is used to determine the time it takes to take bus ownership.
* The transactions are very long, so waiting 35ms is not enough.
*/
adap->timeout = 2 * HZ;
adap->algo = &npcm_i2c_algo;
adap->quirks = &npcm_i2c_quirks;
adap->algo_data = bus;
adap->dev.parent = &pdev->dev;
adap->dev.of_node = pdev->dev.of_node;
adap->nr = pdev->id;
irq = platform_get_irq(pdev, 0); if (irq < 0)
return irq;
/*
* Disable the interrupt to avoid the interrupt handler being triggered
* incorrectly by the asynchronous interrupt status since the machine
* might do a warm reset during the last smbus/i2c transfer session.
*/
npcm_i2c_int_enable(bus, false);
ret = devm_request_irq(bus->dev, irq, npcm_i2c_bus_irq, 0,
dev_name(bus->dev), bus); if (ret)
return ret;
ret = __npcm_i2c_init(bus, pdev); if (ret)
return ret;
npcm_i2c_recovery_init(adap);
i2c_set_adapdata(adap, bus);
snprintf(bus->adap.name, sizeof(bus->adap.name), "npcm_i2c_%d",
bus->num);
ret = i2c_add_numbered_adapter(&bus->adap); if (ret)
return ret;
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.