@@ -1082,34 +1082,61 @@ int mec_hal_i2c_nl_cm_start_by_id(uint8_t i2c_ctrl_id, uint16_t ntx, uint16_t nr
1082
1082
return mec_hal_i2c_nl_cm_start (regs , ntx , nrx , flags , cm_cmd_val );
1083
1083
}
1084
1084
1085
- /* I2C-NL FSM clears MRUN and MPROCEED when both wrCnt and rdCnt transition to 0.
1086
- * MRUN==1 and MPROCEED is cleared to 0 when FSM requires software to reconfigure
1087
- * DMA for the direction change from write to read. After the Rpt-Start and rdAddr
1088
- * are transmitted and (n)ACK'd the FSM clears MPROCEED only.
1089
- * NOTE: any error should clear MRUN and MPROCEED.
1085
+ /* I2C-NL FSM clears MRUN and MPROCEED when both wrCnt and rdCnt transition to
1086
+ * 0. MRUN==1 and MPROCEED is cleared to 0 when FSM requires software to
1087
+ * reconfigure DMA for the direction change from write to read. After the
1088
+ * Rpt-Start and rdAddr are transmitted and (n)ACK'd the FSM clears MPROCEED
1089
+ * only. NOTE: any error should clear MRUN and MPROCEED.
1090
1090
*/
1091
- uint32_t mec_hal_i2c_nl_cm_event (struct mec_i2c_smb_ctx * ctx )
1091
+ uint32_t mec_hal_i2c_nl_get_events (struct mec_i2c_smb_ctx * ctx , uint8_t is_tm )
1092
1092
{
1093
1093
#ifdef MEC_I2C_BASE_CHECK
1094
1094
if (!ctx || !ctx -> base ) {
1095
- return MEC_I2C_NL_CM_EVENT_NONE ;
1095
+ return 0 ;
1096
1096
}
1097
1097
#endif
1098
1098
struct mec_i2c_smb_regs * regs = ctx -> base ;
1099
- uint32_t cm_cmd = regs -> CM_CMD ;
1100
- uint16_t wrcnt = (uint16_t )((regs -> EXTLEN & 0xffu ) << 8 );
1101
- uint16_t rdcnt = (uint16_t )(regs -> EXTLEN & 0xff00u );
1099
+ uint32_t cfg = 0 , cmd = 0 , sts = 0 , events = 0 , extlen = 0 ;
1100
+ uint32_t rdcnt = 0 , wrcnt = 0 ;
1102
1101
1103
- wrcnt |= (uint16_t )((cm_cmd >> 16 ) & 0xffu );
1104
- rdcnt |= (uint16_t )((cm_cmd >> 24 ) & 0xffu );
1102
+ cmd = regs -> CM_CMD ;
1103
+ if (is_tm ) {
1104
+ cmd = regs -> TM_CMD ;
1105
+ }
1105
1106
1106
- if (!cm_cmd && !(ctx -> wrcnt || ctx -> rdcnt )) {
1107
- return MEC_I2C_NL_CM_EVENT_ALL_DONE ;
1108
- } else if (rdcnt && !wrcnt && ((cm_cmd & 0x03u ) == 0x01 )) {
1109
- return MEC_I2C_NL_CM_EVENT_W2R ;
1110
- } else {
1111
- return MEC_I2C_NL_CM_EVENT_NONE ;
1107
+ extlen = regs -> EXTLEN ;
1108
+ wrcnt = ((extlen & 0xffu ) << 8 ) | ((cmd >> 16 ) & 0xffu );
1109
+ rdcnt = (extlen & 0xff00u ) | ((cmd >> 24 ) & 0xffu );
1110
+
1111
+ cfg = regs -> CONFIG ;
1112
+ sts = (regs -> COMPL & 0xffffff00u ) | (regs -> STATUS & 0xffu );
1113
+
1114
+ if ((cfg & sts ) & MEC_BIT (MEC_I2C_SMB_COMPL_IDLE_Pos )) { /* same bit position */
1115
+ events |= MEC_BIT (MEC_I2C_NL_EVENT_IDLE_POS );
1116
+ }
1117
+
1118
+ if (sts & MEC_BIT (4 )) {
1119
+ events |= MEC_BIT (MEC_I2C_NL_EVENT_BERR_POS );
1112
1120
}
1121
+
1122
+ if (sts & MEC_BIT (1 )) {
1123
+ events |= MEC_BIT (MEC_I2C_NL_EVENT_LAB_POS );
1124
+ }
1125
+
1126
+ if (sts & MEC_BIT (24 )) {
1127
+ events |= MEC_BIT (MEC_I2C_NL_EVENT_NACK_POS );
1128
+ }
1129
+
1130
+ /* Write-to-Read turn around is wrcnt==0, rdcnd!=0, and cmd[1:0]==01b */
1131
+ if ((cmd & 0x03u ) == 0x01u ) {
1132
+ events |= MEC_BIT (MEC_I2C_NL_EVENT_PAUSE_POS );
1133
+ }
1134
+
1135
+ if (!rdcnt && !wrcnt && !(cmd & 0x03u )) {
1136
+ events |= MEC_BIT (MEC_I2C_NL_EVENT_DONE_POS );
1137
+ }
1138
+
1139
+ return events ;
1113
1140
}
1114
1141
1115
1142
int mec_hal_i2c_nl_cmd_clear (struct mec_i2c_smb_ctx * ctx , uint8_t is_tm )
@@ -1373,38 +1400,13 @@ int mec_hal_i2c_nl_tm_config(struct mec_i2c_smb_ctx *ctx, uint16_t ntx, uint16_t
1373
1400
return MEC_RET_OK ;
1374
1401
}
1375
1402
1376
- uint32_t mec_hal_i2c_nl_tm_event (struct mec_i2c_smb_ctx * ctx )
1377
- {
1378
- #ifdef MEC_I2C_BASE_CHECK
1379
- if (!ctx || !ctx -> base ) {
1380
- return MEC_I2C_NL_TM_EVENT_NONE ;
1381
- }
1382
- #endif
1383
- struct mec_i2c_smb_regs * regs = ctx -> base ;
1384
- uint32_t tm_cmd = regs -> TM_CMD ;
1385
- uint32_t elen = regs -> EXTLEN ;
1386
- uint16_t wrcnt = (uint16_t )((elen >> 8 ) & 0xff00u );
1387
- uint16_t rdcnt = (uint16_t )((elen >> 16 ) & 0xff00u );
1388
-
1389
- wrcnt |= (uint16_t )((tm_cmd >> 8 ) & 0xffu );
1390
- rdcnt |= (uint16_t )((tm_cmd >> 16 ) & 0xffu );
1391
-
1392
- if (!tm_cmd && (ctx -> wrcnt || ctx -> rdcnt )) {
1393
- return MEC_I2C_NL_TM_EVENT_ALL_DONE ;
1394
- } else if (rdcnt && !wrcnt && ((tm_cmd & 0x03u ) == 0x01 )) {
1395
- return MEC_I2C_NL_TM_EVENT_W2R ;
1396
- } else {
1397
- return MEC_I2C_NL_TM_EVENT_NONE ;
1398
- }
1399
- }
1400
-
1401
1403
uint32_t mec_hal_i2c_nl_tm_xfr_count_get (struct mec_i2c_smb_ctx * ctx , uint8_t is_rx )
1402
1404
{
1403
1405
uint32_t cnt = 0 ;
1404
1406
1405
1407
#ifdef MEC_I2C_BASE_CHECK
1406
1408
if (!ctx || !ctx -> base ) {
1407
- return MEC_I2C_NL_TM_EVENT_NONE ;
1409
+ return 0 ;
1408
1410
}
1409
1411
#endif
1410
1412
struct mec_i2c_smb_regs * regs = ctx -> base ;
@@ -1466,7 +1468,7 @@ uint32_t mec_hal_i2c_nl_tm_transfered(struct mec_i2c_smb_ctx *ctx, uint8_t is_rx
1466
1468
1467
1469
#ifdef MEC_I2C_BASE_CHECK
1468
1470
if (!ctx || !ctx -> base ) {
1469
- return MEC_I2C_NL_TM_EVENT_NONE ;
1471
+ return 0 ;
1470
1472
}
1471
1473
#endif
1472
1474
0 commit comments