Lines Matching +full:npcm750 +full:- +full:gcr

1 // SPDX-License-Identifier: GPL-2.0
125 #define NPCM_I2CTXF_CTL 0x12 /* Tx-FIFO Control */
128 #define NPCM_I2CTXF_STS 0x1A /* Tx-FIFO Status */
129 #define NPCM_I2CRXF_STS 0x1C /* Rx-FIFO Status */
130 #define NPCM_I2CRXF_CTL 0x1E /* Rx-FIFO Control */
343 u8 i2cctl3 = ioread8(bus->reg + NPCM_I2CCTL3); in npcm_i2c_select_bank()
349 iowrite8(i2cctl3, bus->reg + NPCM_I2CCTL3); in npcm_i2c_select_bank()
354 bus->stop_ind = I2C_NO_STATUS_IND; in npcm_i2c_init_params()
355 bus->rd_size = 0; in npcm_i2c_init_params()
356 bus->wr_size = 0; in npcm_i2c_init_params()
357 bus->rd_ind = 0; in npcm_i2c_init_params()
358 bus->wr_ind = 0; in npcm_i2c_init_params()
359 bus->read_block_use = false; in npcm_i2c_init_params()
360 bus->int_time_stamp = 0; in npcm_i2c_init_params()
361 bus->PEC_use = false; in npcm_i2c_init_params()
362 bus->PEC_mask = 0; in npcm_i2c_init_params()
364 if (bus->slave) in npcm_i2c_init_params()
365 bus->master_or_slave = I2C_SLAVE; in npcm_i2c_init_params()
371 iowrite8(data, bus->reg + NPCM_I2CSDA); in npcm_i2c_wr_byte()
376 return ioread8(bus->reg + NPCM_I2CSDA); in npcm_i2c_rd_byte()
383 return !!(I2CCTL3_SCL_LVL & ioread8(bus->reg + NPCM_I2CCTL3)); in npcm_i2c_get_SCL()
390 return !!(I2CCTL3_SDA_LVL & ioread8(bus->reg + NPCM_I2CCTL3)); in npcm_i2c_get_SDA()
395 if (bus->operation == I2C_READ_OPER) in npcm_i2c_get_index()
396 return bus->rd_ind; in npcm_i2c_get_index()
397 if (bus->operation == I2C_WRITE_OPER) in npcm_i2c_get_index()
398 return bus->wr_ind; in npcm_i2c_get_index()
405 return bus->wr_size == 0 && bus->rd_size == 0; in npcm_i2c_is_quick()
417 iowrite8(0, bus->reg + npcm_i2caddr[i]); in npcm_i2c_disable()
421 i2cctl2 = ioread8(bus->reg + NPCM_I2CCTL2); in npcm_i2c_disable()
423 iowrite8(i2cctl2, bus->reg + NPCM_I2CCTL2); in npcm_i2c_disable()
425 bus->state = I2C_DISABLE; in npcm_i2c_disable()
430 u8 i2cctl2 = ioread8(bus->reg + NPCM_I2CCTL2); in npcm_i2c_enable()
433 iowrite8(i2cctl2, bus->reg + NPCM_I2CCTL2); in npcm_i2c_enable()
434 bus->state = I2C_IDLE; in npcm_i2c_enable()
443 val = ioread8(bus->reg + NPCM_I2CCST3); in npcm_i2c_eob_int()
445 iowrite8(val, bus->reg + NPCM_I2CCST3); in npcm_i2c_eob_int()
447 val = ioread8(bus->reg + NPCM_I2CCTL1); in npcm_i2c_eob_int()
453 iowrite8(val, bus->reg + NPCM_I2CCTL1); in npcm_i2c_eob_int()
460 tx_fifo_sts = ioread8(bus->reg + NPCM_I2CTXF_STS); in npcm_i2c_tx_fifo_empty()
462 if ((tx_fifo_sts & bus->data->txf_sts_tx_bytes) == 0) in npcm_i2c_tx_fifo_empty()
473 rx_fifo_sts = ioread8(bus->reg + NPCM_I2CRXF_STS); in npcm_i2c_rx_fifo_full()
475 if ((rx_fifo_sts & bus->data->rxf_sts_rx_bytes) == 0) in npcm_i2c_rx_fifo_full()
486 val = ioread8(bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_clear_fifo_int()
488 iowrite8(val, bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_clear_fifo_int()
495 val = ioread8(bus->reg + NPCM_I2CTXF_STS); in npcm_i2c_clear_tx_fifo()
497 iowrite8(val, bus->reg + NPCM_I2CTXF_STS); in npcm_i2c_clear_tx_fifo()
504 val = ioread8(bus->reg + NPCM_I2CRXF_STS); in npcm_i2c_clear_rx_fifo()
506 iowrite8(val, bus->reg + NPCM_I2CRXF_STS); in npcm_i2c_clear_rx_fifo()
513 val = ioread8(bus->reg + NPCM_I2CCTL1); in npcm_i2c_int_enable()
519 iowrite8(val, bus->reg + NPCM_I2CCTL1); in npcm_i2c_int_enable()
526 val = ioread8(bus->reg + NPCM_I2CCTL1); in npcm_i2c_master_start()
529 iowrite8(val, bus->reg + NPCM_I2CCTL1); in npcm_i2c_master_start()
542 val = ioread8(bus->reg + NPCM_I2CCTL1); in npcm_i2c_master_stop()
545 iowrite8(val, bus->reg + NPCM_I2CCTL1); in npcm_i2c_master_stop()
547 if (!bus->fifo_use) in npcm_i2c_master_stop()
552 if (bus->operation == I2C_READ_OPER) in npcm_i2c_master_stop()
557 iowrite8(0, bus->reg + NPCM_I2CTXF_CTL); in npcm_i2c_master_stop()
564 val = ioread8(bus->reg + NPCM_I2CCTL1); in npcm_i2c_stall_after_start()
570 iowrite8(val, bus->reg + NPCM_I2CCTL1); in npcm_i2c_stall_after_start()
577 val = ioread8(bus->reg + NPCM_I2CCTL1); in npcm_i2c_nack()
580 iowrite8(val, bus->reg + NPCM_I2CCTL1); in npcm_i2c_nack()
589 iowrite8(val, bus->reg + NPCM_I2CST); in npcm_i2c_clear_master_status()
598 i2cctl1 = ioread8(bus->reg + NPCM_I2CCTL1); in npcm_i2c_slave_int_enable()
604 iowrite8(i2cctl1, bus->reg + NPCM_I2CCTL1); in npcm_i2c_slave_int_enable()
616 i2cctl1 = ioread8(bus->reg + NPCM_I2CCTL1); in npcm_i2c_slave_enable()
621 iowrite8(i2cctl1, bus->reg + NPCM_I2CCTL1); in npcm_i2c_slave_enable()
624 i2cctl3 = ioread8(bus->reg + NPCM_I2CCTL3); in npcm_i2c_slave_enable()
629 iowrite8(i2cctl3, bus->reg + NPCM_I2CCTL3); in npcm_i2c_slave_enable()
633 dev_err(bus->dev, "try to enable more than 2 SA not supported\n"); in npcm_i2c_slave_enable()
636 return -EFAULT; in npcm_i2c_slave_enable()
639 iowrite8(sa_reg, bus->reg + npcm_i2caddr[addr_type]); in npcm_i2c_slave_enable()
657 i2cctl1 = ioread8(bus->reg + NPCM_I2CCTL1); in npcm_i2c_reset()
664 iowrite8(i2cctl1, bus->reg + NPCM_I2CCTL1); in npcm_i2c_reset()
667 iowrite8(NPCM_I2CCST_BB, bus->reg + NPCM_I2CCST); in npcm_i2c_reset()
668 iowrite8(0xFF, bus->reg + NPCM_I2CST); in npcm_i2c_reset()
674 iowrite8(NPCM_I2CFIF_CTS_CLR_FIFO, bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_reset()
677 if (bus->slave) { in npcm_i2c_reset()
678 addr = bus->slave->addr; in npcm_i2c_reset()
686 bus->state = I2C_IDLE; in npcm_i2c_reset()
691 return !!FIELD_GET(NPCM_I2CST_MASTER, ioread8(bus->reg + NPCM_I2CST)); in npcm_i2c_is_master()
701 msgs = bus->msgs; in npcm_i2c_callback()
702 msgs_num = bus->msgs_num; in npcm_i2c_callback()
704 * check that transaction was not timed-out, and msgs still in npcm_i2c_callback()
710 if (completion_done(&bus->cmd_complete)) in npcm_i2c_callback()
715 bus->cmd_err = bus->msgs_num; in npcm_i2c_callback()
716 if (bus->tx_complete_cnt < ULLONG_MAX) in npcm_i2c_callback()
717 bus->tx_complete_cnt++; in npcm_i2c_callback()
721 if (bus->msgs) { in npcm_i2c_callback()
732 bus->cmd_err = -ENXIO; in npcm_i2c_callback()
737 bus->cmd_err = -EAGAIN; in npcm_i2c_callback()
747 bus->operation = I2C_NO_OPER; in npcm_i2c_callback()
749 if (bus->slave) in npcm_i2c_callback()
750 bus->master_or_slave = I2C_SLAVE; in npcm_i2c_callback()
753 complete(&bus->cmd_complete); in npcm_i2c_callback()
758 if (bus->operation == I2C_WRITE_OPER) in npcm_i2c_fifo_usage()
759 return (bus->data->txf_sts_tx_bytes & in npcm_i2c_fifo_usage()
760 ioread8(bus->reg + NPCM_I2CTXF_STS)); in npcm_i2c_fifo_usage()
761 if (bus->operation == I2C_READ_OPER) in npcm_i2c_fifo_usage()
762 return (bus->data->rxf_sts_rx_bytes & in npcm_i2c_fifo_usage()
763 ioread8(bus->reg + NPCM_I2CRXF_STS)); in npcm_i2c_fifo_usage()
775 size_free_fifo = bus->data->fifo_size - npcm_i2c_fifo_usage(bus); in npcm_i2c_write_to_fifo_master()
776 while (max_bytes-- && size_free_fifo) { in npcm_i2c_write_to_fifo_master()
777 if (bus->wr_ind < bus->wr_size) in npcm_i2c_write_to_fifo_master()
778 npcm_i2c_wr_byte(bus, bus->wr_buf[bus->wr_ind++]); in npcm_i2c_write_to_fifo_master()
781 size_free_fifo = bus->data->fifo_size - npcm_i2c_fifo_usage(bus); in npcm_i2c_write_to_fifo_master()
787 * configure the FIFO before using it. If nread is -1 RX FIFO will not be
794 if (!bus->fifo_use) in npcm_i2c_set_fifo()
802 rxf_ctl = min_t(int, nread, bus->data->fifo_size); in npcm_i2c_set_fifo()
805 if (nread <= bus->data->fifo_size) in npcm_i2c_set_fifo()
806 rxf_ctl |= bus->data->rxf_ctl_last_pec; in npcm_i2c_set_fifo()
813 if (bus->rd_ind == 0 && bus->read_block_use) { in npcm_i2c_set_fifo()
819 iowrite8(rxf_ctl, bus->reg + NPCM_I2CRXF_CTL); in npcm_i2c_set_fifo()
824 if (nwrite > bus->data->fifo_size) in npcm_i2c_set_fifo()
826 iowrite8(bus->data->fifo_size, bus->reg + NPCM_I2CTXF_CTL); in npcm_i2c_set_fifo()
828 iowrite8(nwrite, bus->reg + NPCM_I2CTXF_CTL); in npcm_i2c_set_fifo()
838 while (bytes_in_fifo--) { in npcm_i2c_read_fifo()
840 if (bus->rd_ind < bus->rd_size) in npcm_i2c_read_fifo()
841 bus->rd_buf[bus->rd_ind++] = data; in npcm_i2c_read_fifo()
862 dev_err(bus->dev, "get slave: try to use more than 2 SA not supported\n"); in npcm_i2c_get_slave_addr()
864 slave_add = ioread8(bus->reg + npcm_i2caddr[(int)addr_type]); in npcm_i2c_get_slave_addr()
877 if (ioread8(bus->reg + npcm_i2caddr[i]) == slave_add) in npcm_i2c_remove_slave_addr()
878 iowrite8(0, bus->reg + npcm_i2caddr[i]); in npcm_i2c_remove_slave_addr()
892 iowrite8(0, bus->reg + NPCM_I2CTXF_CTL); in npcm_i2c_write_fifo_slave()
893 while (max_bytes-- && bus->data->fifo_size != npcm_i2c_fifo_usage(bus)) { in npcm_i2c_write_fifo_slave()
894 if (bus->slv_wr_size <= 0) in npcm_i2c_write_fifo_slave()
896 bus->slv_wr_ind = bus->slv_wr_ind & (bus->data->fifo_size - 1); in npcm_i2c_write_fifo_slave()
897 npcm_i2c_wr_byte(bus, bus->slv_wr_buf[bus->slv_wr_ind]); in npcm_i2c_write_fifo_slave()
898 bus->slv_wr_ind++; in npcm_i2c_write_fifo_slave()
899 bus->slv_wr_ind = bus->slv_wr_ind & (bus->data->fifo_size - 1); in npcm_i2c_write_fifo_slave()
900 bus->slv_wr_size--; in npcm_i2c_write_fifo_slave()
908 if (!bus->slave) in npcm_i2c_read_fifo_slave()
911 while (bytes_in_fifo--) { in npcm_i2c_read_fifo_slave()
914 bus->slv_rd_ind = bus->slv_rd_ind & (bus->data->fifo_size - 1); in npcm_i2c_read_fifo_slave()
915 bus->slv_rd_buf[bus->slv_rd_ind] = data; in npcm_i2c_read_fifo_slave()
916 bus->slv_rd_ind++; in npcm_i2c_read_fifo_slave()
919 if (bus->slv_rd_ind == 1 && bus->read_block_use) in npcm_i2c_read_fifo_slave()
920 bus->slv_rd_size = data + bus->PEC_use + 1; in npcm_i2c_read_fifo_slave()
929 int ret = bus->slv_wr_ind; in npcm_i2c_slave_get_wr_buf()
932 for (i = 0; i < bus->data->fifo_size; i++) { in npcm_i2c_slave_get_wr_buf()
933 if (bus->slv_wr_size >= bus->data->fifo_size) in npcm_i2c_slave_get_wr_buf()
935 if (bus->state == I2C_SLAVE_MATCH) { in npcm_i2c_slave_get_wr_buf()
936 i2c_slave_event(bus->slave, I2C_SLAVE_READ_REQUESTED, &value); in npcm_i2c_slave_get_wr_buf()
937 bus->state = I2C_OPER_STARTED; in npcm_i2c_slave_get_wr_buf()
939 i2c_slave_event(bus->slave, I2C_SLAVE_READ_PROCESSED, &value); in npcm_i2c_slave_get_wr_buf()
941 ind = (bus->slv_wr_ind + bus->slv_wr_size) & (bus->data->fifo_size - 1); in npcm_i2c_slave_get_wr_buf()
942 bus->slv_wr_buf[ind] = value; in npcm_i2c_slave_get_wr_buf()
943 bus->slv_wr_size++; in npcm_i2c_slave_get_wr_buf()
945 return bus->data->fifo_size - ret; in npcm_i2c_slave_get_wr_buf()
952 for (i = 0; i < bus->slv_rd_ind; i++) in npcm_i2c_slave_send_rd_buf()
953 i2c_slave_event(bus->slave, I2C_SLAVE_WRITE_RECEIVED, in npcm_i2c_slave_send_rd_buf()
954 &bus->slv_rd_buf[i]); in npcm_i2c_slave_send_rd_buf()
959 if (bus->slv_rd_ind) { in npcm_i2c_slave_send_rd_buf()
960 bus->slv_wr_size = 0; in npcm_i2c_slave_send_rd_buf()
961 bus->slv_wr_ind = 0; in npcm_i2c_slave_send_rd_buf()
964 bus->slv_rd_ind = 0; in npcm_i2c_slave_send_rd_buf()
965 bus->slv_rd_size = bus->adap.quirks->max_read_len; in npcm_i2c_slave_send_rd_buf()
974 bus->state = I2C_OPER_STARTED; in npcm_i2c_slave_receive()
975 bus->operation = I2C_READ_OPER; in npcm_i2c_slave_receive()
976 bus->slv_rd_size = nread; in npcm_i2c_slave_receive()
977 bus->slv_rd_ind = 0; in npcm_i2c_slave_receive()
979 iowrite8(0, bus->reg + NPCM_I2CTXF_CTL); in npcm_i2c_slave_receive()
980 iowrite8(bus->data->fifo_size, bus->reg + NPCM_I2CRXF_CTL); in npcm_i2c_slave_receive()
991 bus->operation = I2C_WRITE_OPER; in npcm_i2c_slave_xmit()
1004 * NACK on read will be once reached to bus->adap->quirks->max_read_len.
1013 left_in_fifo = bus->data->txf_sts_tx_bytes & in npcm_i2c_slave_wr_buf_sync()
1014 ioread8(bus->reg + NPCM_I2CTXF_STS); in npcm_i2c_slave_wr_buf_sync()
1017 if (left_in_fifo >= bus->data->fifo_size || in npcm_i2c_slave_wr_buf_sync()
1018 bus->slv_wr_size >= bus->data->fifo_size) in npcm_i2c_slave_wr_buf_sync()
1022 bus->slv_wr_ind = bus->slv_wr_ind - left_in_fifo; in npcm_i2c_slave_wr_buf_sync()
1023 bus->slv_wr_size = bus->slv_wr_size + left_in_fifo; in npcm_i2c_slave_wr_buf_sync()
1025 if (bus->slv_wr_ind < 0) in npcm_i2c_slave_wr_buf_sync()
1026 bus->slv_wr_ind += bus->data->fifo_size; in npcm_i2c_slave_wr_buf_sync()
1031 if (NPCM_I2CST_XMIT & ioread8(bus->reg + NPCM_I2CST)) { in npcm_i2c_slave_rd_wr()
1036 bus->operation = I2C_WRITE_OPER; in npcm_i2c_slave_rd_wr()
1037 npcm_i2c_slave_xmit(bus, bus->adap.quirks->max_write_len, in npcm_i2c_slave_rd_wr()
1038 bus->slv_wr_buf); in npcm_i2c_slave_rd_wr()
1046 bus->operation = I2C_READ_OPER; in npcm_i2c_slave_rd_wr()
1048 bus->stop_ind = I2C_SLAVE_RCV_IND; in npcm_i2c_slave_rd_wr()
1050 npcm_i2c_slave_receive(bus, bus->adap.quirks->max_read_len, in npcm_i2c_slave_rd_wr()
1051 bus->slv_rd_buf); in npcm_i2c_slave_rd_wr()
1059 u8 i2cst = ioread8(bus->reg + NPCM_I2CST); in npcm_i2c_int_slave_handler()
1063 bus->stop_ind = I2C_NACK_IND; in npcm_i2c_int_slave_handler()
1065 if (bus->fifo_use) in npcm_i2c_int_slave_handler()
1068 bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_int_slave_handler()
1071 bus->stop_ind = I2C_NO_STATUS_IND; in npcm_i2c_int_slave_handler()
1072 bus->operation = I2C_NO_OPER; in npcm_i2c_int_slave_handler()
1073 bus->own_slave_addr = 0xFF; in npcm_i2c_int_slave_handler()
1079 iowrite8(NPCM_I2CST_NEGACK, bus->reg + NPCM_I2CST); in npcm_i2c_int_slave_handler()
1090 bus->stop_ind = I2C_BUS_ERR_IND; in npcm_i2c_int_slave_handler()
1093 iowrite8(NPCM_I2CFIF_CTS_CLR_FIFO, bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_int_slave_handler()
1095 bus->state = I2C_IDLE; in npcm_i2c_int_slave_handler()
1101 if (completion_done(&bus->cmd_complete) == false) { in npcm_i2c_int_slave_handler()
1102 bus->cmd_err = -EIO; in npcm_i2c_int_slave_handler()
1103 complete(&bus->cmd_complete); in npcm_i2c_int_slave_handler()
1105 bus->own_slave_addr = 0xFF; in npcm_i2c_int_slave_handler()
1106 iowrite8(NPCM_I2CST_BER, bus->reg + NPCM_I2CST); in npcm_i2c_int_slave_handler()
1114 bus->stop_ind = I2C_SLAVE_DONE_IND; in npcm_i2c_int_slave_handler()
1116 if (bus->operation == I2C_READ_OPER) in npcm_i2c_int_slave_handler()
1123 bus->stop_ind = I2C_NO_STATUS_IND; in npcm_i2c_int_slave_handler()
1130 bus->operation = I2C_NO_OPER; in npcm_i2c_int_slave_handler()
1131 bus->own_slave_addr = 0xFF; in npcm_i2c_int_slave_handler()
1132 i2c_slave_event(bus->slave, I2C_SLAVE_STOP, 0); in npcm_i2c_int_slave_handler()
1133 iowrite8(NPCM_I2CST_SLVSTP, bus->reg + NPCM_I2CST); in npcm_i2c_int_slave_handler()
1134 if (bus->fifo_use) { in npcm_i2c_int_slave_handler()
1140 bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_int_slave_handler()
1142 bus->state = I2C_IDLE; in npcm_i2c_int_slave_handler()
1146 /* restart condition occurred and Rx-FIFO was not empty */ in npcm_i2c_int_slave_handler()
1147 if (bus->fifo_use && FIELD_GET(NPCM_I2CFIF_CTS_SLVRSTR, in npcm_i2c_int_slave_handler()
1148 ioread8(bus->reg + NPCM_I2CFIF_CTS))) { in npcm_i2c_int_slave_handler()
1149 bus->stop_ind = I2C_SLAVE_RESTART_IND; in npcm_i2c_int_slave_handler()
1150 bus->master_or_slave = I2C_SLAVE; in npcm_i2c_int_slave_handler()
1151 if (bus->operation == I2C_READ_OPER) in npcm_i2c_int_slave_handler()
1153 bus->operation = I2C_WRITE_OPER; in npcm_i2c_int_slave_handler()
1154 iowrite8(0, bus->reg + NPCM_I2CRXF_CTL); in npcm_i2c_int_slave_handler()
1157 iowrite8(val, bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_int_slave_handler()
1167 bus->master_or_slave = I2C_SLAVE; in npcm_i2c_int_slave_handler()
1171 iowrite8(0, bus->reg + NPCM_I2CTXF_CTL); in npcm_i2c_int_slave_handler()
1172 iowrite8(bus->data->fifo_size, bus->reg + NPCM_I2CRXF_CTL); in npcm_i2c_int_slave_handler()
1174 bus->operation = I2C_WRITE_OPER; in npcm_i2c_int_slave_handler()
1176 i2c_slave_event(bus->slave, I2C_SLAVE_WRITE_REQUESTED, in npcm_i2c_int_slave_handler()
1178 bus->operation = I2C_READ_OPER; in npcm_i2c_int_slave_handler()
1180 if (bus->own_slave_addr == 0xFF) { in npcm_i2c_int_slave_handler()
1182 val = ioread8(bus->reg + NPCM_I2CCST); in npcm_i2c_int_slave_handler()
1189 i2ccst3 = ioread8(bus->reg + NPCM_I2CCST3); in npcm_i2c_int_slave_handler()
1190 i2ccst2 = ioread8(bus->reg + NPCM_I2CCST2); in npcm_i2c_int_slave_handler()
1203 bus->own_slave_addr = addr; in npcm_i2c_int_slave_handler()
1204 if (bus->PEC_mask & BIT(info)) in npcm_i2c_int_slave_handler()
1205 bus->PEC_use = true; in npcm_i2c_int_slave_handler()
1207 bus->PEC_use = false; in npcm_i2c_int_slave_handler()
1210 bus->own_slave_addr = 0; in npcm_i2c_int_slave_handler()
1212 bus->own_slave_addr = 0x61; in npcm_i2c_int_slave_handler()
1221 * (regular write-read mode) in npcm_i2c_int_slave_handler()
1223 if ((bus->state == I2C_OPER_STARTED && in npcm_i2c_int_slave_handler()
1224 bus->operation == I2C_READ_OPER && in npcm_i2c_int_slave_handler()
1225 bus->stop_ind == I2C_SLAVE_XMIT_IND) || in npcm_i2c_int_slave_handler()
1226 bus->stop_ind == I2C_SLAVE_RCV_IND) { in npcm_i2c_int_slave_handler()
1228 bus->stop_ind = I2C_SLAVE_RESTART_IND; in npcm_i2c_int_slave_handler()
1233 bus->stop_ind = I2C_SLAVE_XMIT_IND; in npcm_i2c_int_slave_handler()
1235 bus->stop_ind = I2C_SLAVE_RCV_IND; in npcm_i2c_int_slave_handler()
1236 bus->state = I2C_SLAVE_MATCH; in npcm_i2c_int_slave_handler()
1238 iowrite8(NPCM_I2CST_NMATCH, bus->reg + NPCM_I2CST); in npcm_i2c_int_slave_handler()
1242 /* Slave SDA status is set - tx or rx */ in npcm_i2c_int_slave_handler()
1244 (bus->fifo_use && in npcm_i2c_int_slave_handler()
1247 iowrite8(NPCM_I2CST_SDAST, bus->reg + NPCM_I2CST); in npcm_i2c_int_slave_handler()
1266 struct npcm_i2c *bus = i2c_get_adapdata(client->adapter); in npcm_i2c_reg_slave()
1268 bus->slave = client; in npcm_i2c_reg_slave()
1270 if (client->flags & I2C_CLIENT_TEN) in npcm_i2c_reg_slave()
1271 return -EAFNOSUPPORT; in npcm_i2c_reg_slave()
1273 spin_lock_irqsave(&bus->lock, lock_flags); in npcm_i2c_reg_slave()
1276 bus->slv_rd_size = 0; in npcm_i2c_reg_slave()
1277 bus->slv_wr_size = 0; in npcm_i2c_reg_slave()
1278 bus->slv_rd_ind = 0; in npcm_i2c_reg_slave()
1279 bus->slv_wr_ind = 0; in npcm_i2c_reg_slave()
1280 if (client->flags & I2C_CLIENT_PEC) in npcm_i2c_reg_slave()
1281 bus->PEC_use = true; in npcm_i2c_reg_slave()
1283 dev_info(bus->dev, "i2c%d register slave SA=0x%x, PEC=%d\n", bus->num, in npcm_i2c_reg_slave()
1284 client->addr, bus->PEC_use); in npcm_i2c_reg_slave()
1286 npcm_i2c_slave_enable(bus, I2C_SLAVE_ADDR1, client->addr, true); in npcm_i2c_reg_slave()
1292 spin_unlock_irqrestore(&bus->lock, lock_flags); in npcm_i2c_reg_slave()
1298 struct npcm_i2c *bus = client->adapter->algo_data; in npcm_i2c_unreg_slave()
1301 spin_lock_irqsave(&bus->lock, lock_flags); in npcm_i2c_unreg_slave()
1302 if (!bus->slave) { in npcm_i2c_unreg_slave()
1303 spin_unlock_irqrestore(&bus->lock, lock_flags); in npcm_i2c_unreg_slave()
1304 return -EINVAL; in npcm_i2c_unreg_slave()
1307 npcm_i2c_remove_slave_addr(bus, client->addr); in npcm_i2c_unreg_slave()
1308 bus->slave = NULL; in npcm_i2c_unreg_slave()
1309 spin_unlock_irqrestore(&bus->lock, lock_flags); in npcm_i2c_unreg_slave()
1321 rcount = bus->rd_size - bus->rd_ind; in npcm_i2c_master_fifo_read()
1330 if (rcount < (2 * bus->data->fifo_size) && rcount > bus->data->fifo_size) in npcm_i2c_master_fifo_read()
1331 fifo_bytes = rcount - bus->data->fifo_size; in npcm_i2c_master_fifo_read()
1334 /* last bytes are about to be read - end of tx */ in npcm_i2c_master_fifo_read()
1335 bus->state = I2C_STOP_PENDING; in npcm_i2c_master_fifo_read()
1336 bus->stop_ind = ind; in npcm_i2c_master_fifo_read()
1343 rcount = bus->rd_size - bus->rd_ind; in npcm_i2c_master_fifo_read()
1344 npcm_i2c_set_fifo(bus, rcount, -1); in npcm_i2c_master_fifo_read()
1352 if (bus->fifo_use) in npcm_i2c_irq_master_handler_write()
1355 /* Master write operation - last byte handling */ in npcm_i2c_irq_master_handler_write()
1356 if (bus->wr_ind == bus->wr_size) { in npcm_i2c_irq_master_handler_write()
1357 if (bus->fifo_use && npcm_i2c_fifo_usage(bus) > 0) in npcm_i2c_irq_master_handler_write()
1367 if (bus->rd_size == 0) { in npcm_i2c_irq_master_handler_write()
1370 bus->state = I2C_STOP_PENDING; in npcm_i2c_irq_master_handler_write()
1371 bus->stop_ind = I2C_MASTER_DONE_IND; in npcm_i2c_irq_master_handler_write()
1377 /* last write-byte written on previous int - restart */ in npcm_i2c_irq_master_handler_write()
1378 npcm_i2c_set_fifo(bus, bus->rd_size, -1); in npcm_i2c_irq_master_handler_write()
1383 * Receiving one byte only - stall after successful in npcm_i2c_irq_master_handler_write()
1386 * unintentionally NACK the next multi-byte read. in npcm_i2c_irq_master_handler_write()
1388 if (bus->rd_size == 1) in npcm_i2c_irq_master_handler_write()
1392 bus->operation = I2C_READ_OPER; in npcm_i2c_irq_master_handler_write()
1394 npcm_i2c_wr_byte(bus, bus->dest_addr | 0x1); in npcm_i2c_irq_master_handler_write()
1398 if (!bus->fifo_use || bus->wr_size == 1) { in npcm_i2c_irq_master_handler_write()
1399 npcm_i2c_wr_byte(bus, bus->wr_buf[bus->wr_ind++]); in npcm_i2c_irq_master_handler_write()
1401 wcount = bus->wr_size - bus->wr_ind; in npcm_i2c_irq_master_handler_write()
1402 npcm_i2c_set_fifo(bus, -1, wcount); in npcm_i2c_irq_master_handler_write()
1415 block_extra_bytes_size = bus->read_block_use + bus->PEC_use; in npcm_i2c_irq_master_handler_read()
1421 if (bus->rd_ind == 0) { /* first byte handling: */ in npcm_i2c_irq_master_handler_read()
1422 if (bus->read_block_use) { in npcm_i2c_irq_master_handler_read()
1426 bus->rd_size = data + block_extra_bytes_size; in npcm_i2c_irq_master_handler_read()
1427 bus->rd_buf[bus->rd_ind++] = data; in npcm_i2c_irq_master_handler_read()
1430 if (bus->fifo_use) { in npcm_i2c_irq_master_handler_read()
1431 data = ioread8(bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_irq_master_handler_read()
1433 iowrite8(data, bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_irq_master_handler_read()
1436 npcm_i2c_set_fifo(bus, bus->rd_size - 1, -1); in npcm_i2c_irq_master_handler_read()
1443 if (bus->rd_size == block_extra_bytes_size && in npcm_i2c_irq_master_handler_read()
1444 bus->read_block_use) { in npcm_i2c_irq_master_handler_read()
1445 bus->state = I2C_STOP_PENDING; in npcm_i2c_irq_master_handler_read()
1446 bus->stop_ind = I2C_BLOCK_BYTES_ERR_IND; in npcm_i2c_irq_master_handler_read()
1447 bus->cmd_err = -EIO; in npcm_i2c_irq_master_handler_read()
1459 iowrite8(NPCM_I2CST_NMATCH, bus->reg + NPCM_I2CST); in npcm_i2c_irq_handle_nmatch()
1461 bus->stop_ind = I2C_BUS_ERR_IND; in npcm_i2c_irq_handle_nmatch()
1462 npcm_i2c_callback(bus, bus->stop_ind, npcm_i2c_get_index(bus)); in npcm_i2c_irq_handle_nmatch()
1470 if (bus->nack_cnt < ULLONG_MAX) in npcm_i2c_irq_handle_nack()
1471 bus->nack_cnt++; in npcm_i2c_irq_handle_nack()
1473 if (bus->fifo_use) { in npcm_i2c_irq_handle_nack()
1478 if (bus->operation == I2C_WRITE_OPER) in npcm_i2c_irq_handle_nack()
1479 bus->wr_ind -= npcm_i2c_fifo_usage(bus); in npcm_i2c_irq_handle_nack()
1482 iowrite8(NPCM_I2CFIF_CTS_CLR_FIFO, bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_irq_handle_nack()
1486 bus->stop_ind = I2C_NACK_IND; in npcm_i2c_irq_handle_nack()
1501 readx_poll_timeout_atomic(ioread8, bus->reg + NPCM_I2CCST, val, in npcm_i2c_irq_handle_nack()
1506 bus->state = I2C_IDLE; in npcm_i2c_irq_handle_nack()
1513 npcm_i2c_callback(bus, bus->stop_ind, bus->wr_ind); in npcm_i2c_irq_handle_nack()
1519 if (bus->ber_cnt < ULLONG_MAX) in npcm_i2c_irq_handle_ber()
1520 bus->ber_cnt++; in npcm_i2c_irq_handle_ber()
1521 bus->stop_ind = I2C_BUS_ERR_IND; in npcm_i2c_irq_handle_ber()
1525 bus->ber_state = true; in npcm_i2c_irq_handle_ber()
1529 iowrite8(NPCM_I2CCST_BB, bus->reg + NPCM_I2CCST); in npcm_i2c_irq_handle_ber()
1531 bus->cmd_err = -EAGAIN; in npcm_i2c_irq_handle_ber()
1532 npcm_i2c_callback(bus, bus->stop_ind, npcm_i2c_get_index(bus)); in npcm_i2c_irq_handle_ber()
1534 bus->state = I2C_IDLE; in npcm_i2c_irq_handle_ber()
1541 bus->state = I2C_IDLE; in npcm_i2c_irq_handle_eob()
1542 npcm_i2c_callback(bus, bus->stop_ind, bus->rd_ind); in npcm_i2c_irq_handle_eob()
1549 bus->state = I2C_STOP_PENDING; in npcm_i2c_irq_handle_stall_after_start()
1550 bus->stop_ind = I2C_MASTER_DONE_IND; in npcm_i2c_irq_handle_stall_after_start()
1553 } else if ((bus->rd_size == 1) && !bus->read_block_use) { in npcm_i2c_irq_handle_stall_after_start()
1555 * Receiving one byte only - set NACK after ensuring in npcm_i2c_irq_handle_stall_after_start()
1561 /* Reset stall-after-address-byte */ in npcm_i2c_irq_handle_stall_after_start()
1565 iowrite8(NPCM_I2CST_STASTR, bus->reg + NPCM_I2CST); in npcm_i2c_irq_handle_stall_after_start()
1568 /* SDA status is set - TX or RX, master */
1576 if (bus->state == I2C_IDLE) { in npcm_i2c_irq_handle_sda()
1577 bus->stop_ind = I2C_WAKE_UP_IND; in npcm_i2c_irq_handle_sda()
1579 if (npcm_i2c_is_quick(bus) || bus->read_block_use) in npcm_i2c_irq_handle_sda()
1589 * Receiving one byte only - stall after successful completion in npcm_i2c_irq_handle_sda()
1592 * multi-byte read in npcm_i2c_irq_handle_sda()
1594 if (bus->wr_size == 0 && bus->rd_size == 1) in npcm_i2c_irq_handle_sda()
1602 fif_cts = ioread8(bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_irq_handle_sda()
1607 iowrite8(fif_cts, bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_irq_handle_sda()
1609 /* re-enable */ in npcm_i2c_irq_handle_sda()
1611 iowrite8(fif_cts, bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_irq_handle_sda()
1620 if (bus->wr_size) in npcm_i2c_irq_handle_sda()
1621 npcm_i2c_set_fifo(bus, -1, bus->wr_size); in npcm_i2c_irq_handle_sda()
1623 npcm_i2c_set_fifo(bus, bus->rd_size, -1); in npcm_i2c_irq_handle_sda()
1625 bus->state = I2C_OPER_STARTED; in npcm_i2c_irq_handle_sda()
1627 if (npcm_i2c_is_quick(bus) || bus->wr_size) in npcm_i2c_irq_handle_sda()
1628 npcm_i2c_wr_byte(bus, bus->dest_addr); in npcm_i2c_irq_handle_sda()
1630 npcm_i2c_wr_byte(bus, bus->dest_addr | BIT(0)); in npcm_i2c_irq_handle_sda()
1633 if (bus->operation == I2C_WRITE_OPER) in npcm_i2c_irq_handle_sda()
1635 else if (bus->operation == I2C_READ_OPER) in npcm_i2c_irq_handle_sda()
1643 int ret = -EIO; in npcm_i2c_int_master_handler()
1645 i2cst = ioread8(bus->reg + NPCM_I2CST); in npcm_i2c_int_master_handler()
1665 ioread8(bus->reg + NPCM_I2CCTL1)) == 1) && in npcm_i2c_int_master_handler()
1667 ioread8(bus->reg + NPCM_I2CCST3)))) { in npcm_i2c_int_master_handler()
1678 /* SDA status is set - TX or RX, master */ in npcm_i2c_int_master_handler()
1680 (bus->fifo_use && in npcm_i2c_int_master_handler()
1695 int status = -ENOTRECOVERABLE; in npcm_i2c_recovery_tgclk()
1701 dev_dbg(bus->dev, "bus%d-0x%x recovery skipped, bus not stuck", in npcm_i2c_recovery_tgclk()
1702 bus->num, bus->dest_addr); in npcm_i2c_recovery_tgclk()
1704 bus->ber_state = false; in npcm_i2c_recovery_tgclk()
1711 iowrite8(NPCM_I2CCST_BB, bus->reg + NPCM_I2CCST); in npcm_i2c_recovery_tgclk()
1714 iowrite8(0, bus->reg + NPCM_I2CRXF_CTL); in npcm_i2c_recovery_tgclk()
1715 iowrite8(0, bus->reg + NPCM_I2CTXF_CTL); in npcm_i2c_recovery_tgclk()
1722 fif_cts = ioread8(bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_recovery_tgclk()
1725 iowrite8(fif_cts, bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_recovery_tgclk()
1726 npcm_i2c_set_fifo(bus, -1, 0); in npcm_i2c_recovery_tgclk()
1731 iowrite8(NPCM_I2CCST_TGSCL, bus->reg + NPCM_I2CCST); in npcm_i2c_recovery_tgclk()
1738 } while (!done && iter--); in npcm_i2c_recovery_tgclk()
1740 /* If SDA line is released: send start-addr-stop, to re-sync. */ in npcm_i2c_recovery_tgclk()
1743 npcm_i2c_wr_byte(bus, bus->dest_addr); in npcm_i2c_recovery_tgclk()
1761 status = -ENOTRECOVERABLE; in npcm_i2c_recovery_tgclk()
1763 if (bus->rec_fail_cnt < ULLONG_MAX) in npcm_i2c_recovery_tgclk()
1764 bus->rec_fail_cnt++; in npcm_i2c_recovery_tgclk()
1766 if (bus->rec_succ_cnt < ULLONG_MAX) in npcm_i2c_recovery_tgclk()
1767 bus->rec_succ_cnt++; in npcm_i2c_recovery_tgclk()
1769 bus->ber_state = false; in npcm_i2c_recovery_tgclk()
1777 struct i2c_bus_recovery_info *rinfo = &bus->rinfo; in npcm_i2c_recovery_init()
1779 rinfo->recover_bus = npcm_i2c_recovery_tgclk; in npcm_i2c_recovery_init()
1787 rinfo->get_scl = npcm_i2c_get_SCL; in npcm_i2c_recovery_init()
1788 rinfo->get_sda = npcm_i2c_get_SDA; in npcm_i2c_recovery_init()
1789 _adap->bus_recovery_info = rinfo; in npcm_i2c_recovery_init()
1817 src_clk_khz = bus->apb_clk / 1000; in npcm_i2c_init_clk()
1819 bus->bus_freq = bus_freq_hz; in npcm_i2c_init_clk()
1826 return -EDOM; in npcm_i2c_init_clk()
1843 return -EDOM; in npcm_i2c_init_clk()
1867 return -EDOM; in npcm_i2c_init_clk()
1876 * SDA hold time: (HLDT-7) * T(CLK) >= 120 in npcm_i2c_init_clk()
1888 return -EINVAL; in npcm_i2c_init_clk()
1895 return -EDOM; in npcm_i2c_init_clk()
1900 bus->reg + NPCM_I2CCTL2); in npcm_i2c_init_clk()
1904 bus->reg + NPCM_I2CCTL3); in npcm_i2c_init_clk()
1912 * k1 = 2 * SCLLT7-0 -> Low Time = k1 / 2 in npcm_i2c_init_clk()
1913 * k2 = 2 * SCLLT7-0 -> High Time = k2 / 2 in npcm_i2c_init_clk()
1915 iowrite8(k1 / 2, bus->reg + NPCM_I2CSCLLT); in npcm_i2c_init_clk()
1916 iowrite8(k2 / 2, bus->reg + NPCM_I2CSCLHT); in npcm_i2c_init_clk()
1918 iowrite8(dbnct, bus->reg + NPCM_I2CCTL5); in npcm_i2c_init_clk()
1921 iowrite8(hldt, bus->reg + NPCM_I2CCTL4); in npcm_i2c_init_clk()
1936 if ((bus->state != I2C_DISABLE && bus->state != I2C_IDLE) || in npcm_i2c_init_module()
1938 return -EINVAL; in npcm_i2c_init_module()
1944 if (FIELD_GET(I2C_VER_FIFO_EN, ioread8(bus->reg + I2C_VER))) { in npcm_i2c_init_module()
1945 bus->fifo_use = true; in npcm_i2c_init_module()
1947 val = ioread8(bus->reg + NPCM_I2CFIF_CTL); in npcm_i2c_init_module()
1949 iowrite8(val, bus->reg + NPCM_I2CFIF_CTL); in npcm_i2c_init_module()
1952 bus->fifo_use = false; in npcm_i2c_init_module()
1958 dev_err(bus->dev, "npcm_i2c_init_clk failed\n"); in npcm_i2c_init_module()
1964 bus->state = I2C_IDLE; in npcm_i2c_init_module()
1965 val = ioread8(bus->reg + NPCM_I2CCTL1); in npcm_i2c_init_module()
1967 iowrite8(val, bus->reg + NPCM_I2CCTL1); in npcm_i2c_init_module()
1972 if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) { in npcm_i2c_init_module()
1973 dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num); in npcm_i2c_init_module()
1974 dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap), in npcm_i2c_init_module()
1975 npcm_i2c_get_SCL(&bus->adap)); in npcm_i2c_init_module()
1976 return -ENXIO; in npcm_i2c_init_module()
1989 bus->state = I2C_DISABLE; in __npcm_i2c_init()
1990 bus->master_or_slave = I2C_SLAVE; in __npcm_i2c_init()
1991 bus->int_time_stamp = 0; in __npcm_i2c_init()
1993 bus->slave = NULL; in __npcm_i2c_init()
1996 ret = device_property_read_u32(&pdev->dev, "clock-frequency", in __npcm_i2c_init()
1999 dev_info(&pdev->dev, "Could not read clock-frequency property"); in __npcm_i2c_init()
2005 dev_err(&pdev->dev, "npcm_i2c_init_module failed\n"); in __npcm_i2c_init()
2017 bus->master_or_slave = I2C_MASTER; in npcm_i2c_bus_irq()
2019 if (bus->master_or_slave == I2C_MASTER) { in npcm_i2c_bus_irq()
2020 bus->int_time_stamp = jiffies; in npcm_i2c_bus_irq()
2025 if (bus->slave) { in npcm_i2c_bus_irq()
2026 bus->master_or_slave = I2C_SLAVE; in npcm_i2c_bus_irq()
2042 if (bus->state != I2C_IDLE) { in npcm_i2c_master_start_xmit()
2043 bus->cmd_err = -EBUSY; in npcm_i2c_master_start_xmit()
2046 bus->dest_addr = slave_addr << 1; in npcm_i2c_master_start_xmit()
2047 bus->wr_buf = write_data; in npcm_i2c_master_start_xmit()
2048 bus->wr_size = nwrite; in npcm_i2c_master_start_xmit()
2049 bus->wr_ind = 0; in npcm_i2c_master_start_xmit()
2050 bus->rd_buf = read_data; in npcm_i2c_master_start_xmit()
2051 bus->rd_size = nread; in npcm_i2c_master_start_xmit()
2052 bus->rd_ind = 0; in npcm_i2c_master_start_xmit()
2053 bus->PEC_use = 0; in npcm_i2c_master_start_xmit()
2057 bus->PEC_use = use_PEC; in npcm_i2c_master_start_xmit()
2059 bus->read_block_use = use_read_block; in npcm_i2c_master_start_xmit()
2061 bus->operation = I2C_READ_OPER; in npcm_i2c_master_start_xmit()
2063 bus->operation = I2C_WRITE_OPER; in npcm_i2c_master_start_xmit()
2064 if (bus->fifo_use) { in npcm_i2c_master_start_xmit()
2069 i2cfif_cts = ioread8(bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_master_start_xmit()
2072 iowrite8(i2cfif_cts, bus->reg + NPCM_I2CFIF_CTS); in npcm_i2c_master_start_xmit()
2075 bus->state = I2C_IDLE; in npcm_i2c_master_start_xmit()
2096 if (bus->state == I2C_DISABLE) { in npcm_i2c_master_xfer()
2097 dev_err(bus->dev, "I2C%d module is disabled", bus->num); in npcm_i2c_master_xfer()
2098 return -EINVAL; in npcm_i2c_master_xfer()
2102 slave_addr = msg0->addr; in npcm_i2c_master_xfer()
2103 if (msg0->flags & I2C_M_RD) { /* read */ in npcm_i2c_master_xfer()
2106 read_data = msg0->buf; in npcm_i2c_master_xfer()
2107 if (msg0->flags & I2C_M_RECV_LEN) { in npcm_i2c_master_xfer()
2110 if (msg0->flags & I2C_CLIENT_PEC) in npcm_i2c_master_xfer()
2113 nread = msg0->len; in npcm_i2c_master_xfer()
2116 nwrite = msg0->len; in npcm_i2c_master_xfer()
2117 write_data = msg0->buf; in npcm_i2c_master_xfer()
2122 read_data = msg1->buf; in npcm_i2c_master_xfer()
2123 if (msg1->flags & I2C_M_RECV_LEN) { in npcm_i2c_master_xfer()
2126 if (msg1->flags & I2C_CLIENT_PEC) in npcm_i2c_master_xfer()
2129 nread = msg1->len; in npcm_i2c_master_xfer()
2140 timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite); in npcm_i2c_master_xfer()
2141 timeout = max_t(unsigned long, bus->adap.timeout, usecs_to_jiffies(timeout_usec)); in npcm_i2c_master_xfer()
2143 dev_err(bus->dev, "i2c%d buffer too big\n", bus->num); in npcm_i2c_master_xfer()
2144 return -EINVAL; in npcm_i2c_master_xfer()
2154 spin_lock_irqsave(&bus->lock, flags); in npcm_i2c_master_xfer()
2155 bus_busy = ioread8(bus->reg + NPCM_I2CCST) & NPCM_I2CCST_BB; in npcm_i2c_master_xfer()
2157 if (!bus_busy && bus->slave) in npcm_i2c_master_xfer()
2158 iowrite8((bus->slave->addr & 0x7F), in npcm_i2c_master_xfer()
2159 bus->reg + NPCM_I2CADDR1); in npcm_i2c_master_xfer()
2161 spin_unlock_irqrestore(&bus->lock, flags); in npcm_i2c_master_xfer()
2174 if (bus_busy || bus->ber_state) { in npcm_i2c_master_xfer()
2175 iowrite8(NPCM_I2CCST_BB, bus->reg + NPCM_I2CCST); in npcm_i2c_master_xfer()
2178 return -EAGAIN; in npcm_i2c_master_xfer()
2182 bus->dest_addr = slave_addr; in npcm_i2c_master_xfer()
2183 bus->msgs = msgs; in npcm_i2c_master_xfer()
2184 bus->msgs_num = num; in npcm_i2c_master_xfer()
2185 bus->cmd_err = 0; in npcm_i2c_master_xfer()
2186 bus->read_block_use = read_block; in npcm_i2c_master_xfer()
2188 reinit_completion(&bus->cmd_complete); in npcm_i2c_master_xfer()
2195 time_left = wait_for_completion_timeout(&bus->cmd_complete, in npcm_i2c_master_xfer()
2199 if (bus->timeout_cnt < ULLONG_MAX) in npcm_i2c_master_xfer()
2200 bus->timeout_cnt++; in npcm_i2c_master_xfer()
2201 if (bus->master_or_slave == I2C_MASTER) { in npcm_i2c_master_xfer()
2203 bus->cmd_err = -EIO; in npcm_i2c_master_xfer()
2204 bus->state = I2C_IDLE; in npcm_i2c_master_xfer()
2210 if (bus->cmd_err == -EAGAIN) in npcm_i2c_master_xfer()
2211 bus->cmd_err = i2c_recover_bus(adap); in npcm_i2c_master_xfer()
2218 else if (bus->cmd_err && in npcm_i2c_master_xfer()
2219 (bus->data->rxf_ctl_last_pec & ioread8(bus->reg + NPCM_I2CRXF_CTL))) in npcm_i2c_master_xfer()
2228 if (bus->slave) in npcm_i2c_master_xfer()
2229 iowrite8((bus->slave->addr & 0x7F) | NPCM_I2CADDR_SAEN, in npcm_i2c_master_xfer()
2230 bus->reg + NPCM_I2CADDR1); in npcm_i2c_master_xfer()
2234 return bus->cmd_err; in npcm_i2c_master_xfer()
2264 debugfs_create_u64("ber_cnt", 0444, bus->adap.debugfs, &bus->ber_cnt); in npcm_i2c_init_debugfs()
2265 debugfs_create_u64("nack_cnt", 0444, bus->adap.debugfs, &bus->nack_cnt); in npcm_i2c_init_debugfs()
2266 debugfs_create_u64("rec_succ_cnt", 0444, bus->adap.debugfs, &bus->rec_succ_cnt); in npcm_i2c_init_debugfs()
2267 debugfs_create_u64("rec_fail_cnt", 0444, bus->adap.debugfs, &bus->rec_fail_cnt); in npcm_i2c_init_debugfs()
2268 debugfs_create_u64("timeout_cnt", 0444, bus->adap.debugfs, &bus->timeout_cnt); in npcm_i2c_init_debugfs()
2269 debugfs_create_u64("tx_complete_cnt", 0444, bus->adap.debugfs, &bus->tx_complete_cnt); in npcm_i2c_init_debugfs()
2274 struct device_node *np = pdev->dev.of_node; in npcm_i2c_probe_bus()
2276 struct device *dev = &pdev->dev; in npcm_i2c_probe_bus()
2283 bus = devm_kzalloc(&pdev->dev, sizeof(*bus), GFP_KERNEL); in npcm_i2c_probe_bus()
2285 return -ENOMEM; in npcm_i2c_probe_bus()
2287 bus->dev = &pdev->dev; in npcm_i2c_probe_bus()
2289 bus->data = of_device_get_match_data(dev); in npcm_i2c_probe_bus()
2290 if (!bus->data) { in npcm_i2c_probe_bus()
2292 return -EINVAL; in npcm_i2c_probe_bus()
2295 bus->num = of_alias_get_id(pdev->dev.of_node, "i2c"); in npcm_i2c_probe_bus()
2297 i2c_clk = devm_clk_get(&pdev->dev, NULL); in npcm_i2c_probe_bus()
2300 bus->apb_clk = clk_get_rate(i2c_clk); in npcm_i2c_probe_bus()
2302 gcr_regmap = syscon_regmap_lookup_by_phandle(np, "nuvoton,sys-mgr"); in npcm_i2c_probe_bus()
2304 gcr_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-gcr"); in npcm_i2c_probe_bus()
2308 regmap_write(gcr_regmap, NPCM_I2CSEGCTL, bus->data->segctl_init_val); in npcm_i2c_probe_bus()
2310 bus->reg = devm_platform_ioremap_resource(pdev, 0); in npcm_i2c_probe_bus()
2311 if (IS_ERR(bus->reg)) in npcm_i2c_probe_bus()
2312 return PTR_ERR(bus->reg); in npcm_i2c_probe_bus()
2314 spin_lock_init(&bus->lock); in npcm_i2c_probe_bus()
2315 init_completion(&bus->cmd_complete); in npcm_i2c_probe_bus()
2317 adap = &bus->adap; in npcm_i2c_probe_bus()
2318 adap->owner = THIS_MODULE; in npcm_i2c_probe_bus()
2319 adap->retries = 3; in npcm_i2c_probe_bus()
2320 adap->timeout = msecs_to_jiffies(35); in npcm_i2c_probe_bus()
2321 adap->algo = &npcm_i2c_algo; in npcm_i2c_probe_bus()
2322 adap->quirks = &npcm_i2c_quirks; in npcm_i2c_probe_bus()
2323 adap->algo_data = bus; in npcm_i2c_probe_bus()
2324 adap->dev.parent = &pdev->dev; in npcm_i2c_probe_bus()
2325 adap->dev.of_node = pdev->dev.of_node; in npcm_i2c_probe_bus()
2326 adap->nr = pdev->id; in npcm_i2c_probe_bus()
2332 ret = devm_request_irq(bus->dev, irq, npcm_i2c_bus_irq, 0, in npcm_i2c_probe_bus()
2333 dev_name(bus->dev), bus); in npcm_i2c_probe_bus()
2345 snprintf(bus->adap.name, sizeof(bus->adap.name), "npcm_i2c_%d", in npcm_i2c_probe_bus()
2346 bus->num); in npcm_i2c_probe_bus()
2347 ret = i2c_add_numbered_adapter(&bus->adap); in npcm_i2c_probe_bus()
2361 spin_lock_irqsave(&bus->lock, lock_flags); in npcm_i2c_remove_bus()
2363 spin_unlock_irqrestore(&bus->lock, lock_flags); in npcm_i2c_remove_bus()
2364 i2c_del_adapter(&bus->adap); in npcm_i2c_remove_bus()
2368 { .compatible = "nuvoton,npcm750-i2c", .data = &npxm7xx_i2c_data },
2369 { .compatible = "nuvoton,npcm845-i2c", .data = &npxm8xx_i2c_data },
2378 .name = "nuvoton-i2c",