Skip to content

Commit 7787b15

Browse files
committed
hal: mec5: Update I2C HAL get events API
We reduced I2C HAL get events to a single API with a parameter indicating we want events for Controller mode or Target mode. Fixed some return values on some APIs and register header copyright. Signed-off-by: Scott Worley <scott.worley@microchip.com>
1 parent d61d655 commit 7787b15

File tree

3 files changed

+63
-62
lines changed

3 files changed

+63
-62
lines changed

mec5/devices/common/mec5_i2c_smb_v3_8.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6-
#ifndef _MEC5_I2C_SMB_V3_7_H
7-
#define _MEC5_I2C_SMB_V3_7_H
6+
#ifndef _MEC5_I2C_SMB_V3_8_H
7+
#define _MEC5_I2C_SMB_V3_8_H
8+
9+
#include <stdint.h>
810

911
/** @addtogroup Device_Peripheral_peripherals
1012
* @{
@@ -14,7 +16,7 @@
1416
*/
1517

1618
typedef struct mec_i2c_smb_regs { /*!< (@ 0x40004000) MEC_I2C_SMB0 Structure */
17-
19+
1820
union {
1921
__OM uint8_t CTRL; /*!< (@ 0x00000000) I2C mode Control(WO) */
2022
__IM uint8_t STATUS; /*!< (@ 0x00000000) I2C mode Status(RO) */
@@ -878,4 +880,4 @@ typedef enum { /*!< MEC_I2C_SMB0_PROM_CTRL_ARAC
878880

879881
/** @} */ /* End of group EnumValue_peripherals */
880882

881-
#endif /* _MEC5_I2C_SMB_V3_7_H */
883+
#endif /* _MEC5_I2C_SMB_V3_8_H */

mec5/drivers/mec_i2c.c

+47-45
Original file line numberDiff line numberDiff line change
@@ -1082,34 +1082,61 @@ int mec_hal_i2c_nl_cm_start_by_id(uint8_t i2c_ctrl_id, uint16_t ntx, uint16_t nr
10821082
return mec_hal_i2c_nl_cm_start(regs, ntx, nrx, flags, cm_cmd_val);
10831083
}
10841084

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.
10901090
*/
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)
10921092
{
10931093
#ifdef MEC_I2C_BASE_CHECK
10941094
if (!ctx || !ctx->base) {
1095-
return MEC_I2C_NL_CM_EVENT_NONE;
1095+
return 0;
10961096
}
10971097
#endif
10981098
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;
11021101

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+
}
11051106

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);
11121120
}
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;
11131140
}
11141141

11151142
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
13731400
return MEC_RET_OK;
13741401
}
13751402

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-
14011403
uint32_t mec_hal_i2c_nl_tm_xfr_count_get(struct mec_i2c_smb_ctx *ctx, uint8_t is_rx)
14021404
{
14031405
uint32_t cnt = 0;
14041406

14051407
#ifdef MEC_I2C_BASE_CHECK
14061408
if (!ctx || !ctx->base) {
1407-
return MEC_I2C_NL_TM_EVENT_NONE;
1409+
return 0;
14081410
}
14091411
#endif
14101412
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
14661468

14671469
#ifdef MEC_I2C_BASE_CHECK
14681470
if (!ctx || !ctx->base) {
1469-
return MEC_I2C_NL_TM_EVENT_NONE;
1471+
return 0;
14701472
}
14711473
#endif
14721474

mec5/drivers/mec_i2c_api.h

+10-13
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,15 @@ enum mec_i2c_ien {
9393
MEC_I2C_NL_IEN_AAT_POS,
9494
};
9595

96-
enum mec_i2c_nl_cm_event {
97-
MEC_I2C_NL_CM_EVENT_NONE = 0,
98-
MEC_I2C_NL_CM_EVENT_W2R,
99-
MEC_I2C_NL_CM_EVENT_ALL_DONE,
100-
};
101-
102-
enum mec_i2c_nl_tm_event {
103-
MEC_I2C_NL_TM_EVENT_NONE = 0,
104-
MEC_I2C_NL_TM_EVENT_W2R,
105-
MEC_I2C_NL_TM_EVENT_ALL_DONE,
96+
enum mec_i2c_nl_events {
97+
MEC_I2C_NL_EVENT_NACK_POS,
98+
MEC_I2C_NL_EVENT_BERR_POS,
99+
MEC_I2C_NL_EVENT_LAB_POS,
100+
MEC_I2C_NL_EVENT_IDLE_POS,
101+
MEC_I2C_NL_EVENT_PAUSE_POS,
102+
MEC_I2C_NL_EVENT_DONE_POS,
103+
MEC_I2C_NL_EVENT_DMA_DONE_POS,
104+
MEC_I2C_NL_EVENT_DMA_ERR_POS,
106105
};
107106

108107
enum mec_i2c_port {
@@ -270,7 +269,7 @@ uint32_t mec_hal_i2c_nl_cmd_get(struct mec_i2c_smb_ctx *ctx, uint8_t is_tm);
270269
int mec_hal_i2c_nl_state_get(struct mec_i2c_smb_regs *regs, struct mec_i2c_smb_nl_state *state,
271270
uint8_t is_tm);
272271

273-
uint32_t mec_hal_i2c_nl_cm_event(struct mec_i2c_smb_ctx *ctx);
272+
uint32_t mec_hal_i2c_nl_get_events(struct mec_i2c_smb_ctx *ctx, uint8_t is_tm);
274273

275274
#define MEC_I2C_NL_CM_DIR_WR 0
276275
#define MEC_I2C_NL_CM_DIR_RD 1
@@ -314,8 +313,6 @@ static inline uint8_t mec_hal_i2c_nl_shad_data_get(struct mec_i2c_smb_regs *regs
314313
int mec_hal_i2c_nl_tm_config(struct mec_i2c_smb_ctx *ctx, uint16_t ntx, uint16_t nrx,
315314
uint32_t flags);
316315

317-
uint32_t mec_hal_i2c_nl_tm_event(struct mec_i2c_smb_ctx *ctx);
318-
319316
#define MEC_I2C_NL_TM_DIR_TX 0 /* We supply data to external Controller */
320317
#define MEC_I2C_NL_TM_DIR_RX 1 /* We clock in data from external Controller */
321318

0 commit comments

Comments
 (0)