Skip to content

Commit 578fbca

Browse files
alvsunhenrikbrixandersen
authored andcommitted
soc: nuvoton: reg: add i3c target registers and soc functions
As title. Signed-off-by: Alvis Sun <[email protected]>
1 parent f522edb commit 578fbca

File tree

6 files changed

+556
-146
lines changed

6 files changed

+556
-146
lines changed

drivers/i3c/i3c_npcx.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,79 @@
2121
#include <zephyr/logging/log.h>
2222
LOG_MODULE_REGISTER(npcx_i3c, CONFIG_I3C_LOG_LEVEL);
2323

24+
/* MCONFIG options */
25+
#define MCONFIG_CTRENA_OFF 0x0
26+
#define MCONFIG_CTRENA_ON 0x1
27+
#define MCONFIG_CTRENA_CAPABLE 0x2
28+
#define MCONFIG_HKEEP_EXT_SDA_SCL 0x3
29+
30+
/* MCTRL options */
31+
#define MCTRL_REQUEST_NONE 0 /* None */
32+
#define MCTRL_REQUEST_EMITSTARTADDR 1 /* Emit a START */
33+
#define MCTRL_REQUEST_EMITSTOP 2 /* Emit a STOP */
34+
#define MCTRL_REQUEST_IBIACKNACK 3 /* Manually ACK or NACK an IBI */
35+
#define MCTRL_REQUEST_PROCESSDAA 4 /* Starts the DAA process */
36+
#define MCTRL_REQUEST_FORCEEXIT 6 /* Emit HDR Exit Pattern */
37+
/* Emits a START with address 7Eh when a slave pulls I3C_SDA low to request an IBI */
38+
#define MCTRL_REQUEST_AUTOIBI 7
39+
40+
/* ACK with mandatory byte determined by IBIRULES or ACK with no mandatory byte */
41+
#define MCTRL_IBIRESP_ACK 0
42+
#define MCTRL_IBIRESP_NACK 1 /* NACK */
43+
#define MCTRL_IBIRESP_ACK_MANDATORY 2 /* ACK with mandatory byte */
44+
#define MCTRL_IBIRESP_MANUAL 3
45+
46+
/* For REQUEST = EmitStartAddr */
47+
enum npcx_i3c_mctrl_type {
48+
NPCX_I3C_MCTRL_TYPE_I3C,
49+
NPCX_I3C_MCTRL_TYPE_I2C,
50+
NPCX_I3C_MCTRL_TYPE_I3C_HDR_DDR,
51+
};
52+
53+
/* For REQUEST = ForceExit/Target Reset */
54+
#define MCTRL_TYPE_HDR_EXIT 0
55+
#define MCTRL_TYPE_TGT_RESTART 2
56+
57+
/* MSTATUS options */
58+
#define MSTATUS_STATE_IDLE 0x0
59+
#define MSTATUS_STATE_TGTREQ 0x1
60+
#define MSTATUS_STATE_NORMACT 0x3 /* SDR message mode */
61+
#define MSTATUS_STATE_MSGDDR 0x4
62+
#define MSTATUS_STATE_DAA 0x5
63+
#define MSTATUS_STATE_IBIACK 0x6
64+
#define MSTATUS_STATE_IBIRCV 0x7
65+
#define MSTATUS_IBITYPE_NONE 0x0
66+
#define MSTATUS_IBITYPE_IBI 0x1
67+
#define MSTATUS_IBITYPE_CR 0x2
68+
#define MSTATUS_IBITYPE_HJ 0x3
69+
70+
/* IBIRULES */
71+
#define IBIRULES_ADDR_MSK 0x3F
72+
#define IBIRULES_ADDR_SHIFT 0x6
73+
74+
/* MDMACTRL options */
75+
#define MDMA_DMAFB_DISABLE 0x0
76+
#define MDMA_DMAFB_EN_ONE_FRAME 0x1
77+
#define MDMA_DMAFB_EN_MANUAL 0x2
78+
#define MDMA_DMATB_DISABLE 0x0
79+
#define MDMA_DMATB_EN_ONE_FRAME 0x1
80+
#define MDMA_DMATB_EN_MANUAL 0x2
81+
82+
/* CTRL options */
83+
#define CTRL_EVENT_NORMAL 0
84+
#define CTRL_EVENT_IBI 1
85+
#define CTRL_EVENT_CNTLR_REQ 2
86+
#define CTRL_EVENT_HJ 3
87+
88+
/* STATUS options */
89+
#define STATUS_EVDET_NONE 0
90+
#define STATUS_EVDET_REQ_NOT_SENT 1
91+
#define STATUS_EVDET_REQ_SENT_NACKED 2
92+
#define STATUS_EVDET_REQ_SENT_ACKED 3
93+
94+
/*******************************************************************************
95+
* Local Constants Definition
96+
******************************************************************************/
2497
#define NPCX_I3C_CHK_TIMEOUT_US 10000 /* Timeout for checking register status */
2598
#define I3C_SCL_PP_FREQ_MAX_MHZ 12500000
2699
#define I3C_SCL_OD_FREQ_MAX_MHZ 4170000

include/zephyr/drivers/i3c/i3c_npcx.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2020 Nuvoton Technology Corporation.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_DRIVERS_I3C_I3C_NPCX_H_
8+
#define ZEPHYR_DRIVERS_I3C_I3C_NPCX_H_
9+
10+
#include <zephyr/device.h>
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
#ifdef CONFIG_I3C_NPCX_DMA
17+
18+
/**
19+
* @brief Configures the application's buffer for use in MDMA mode.
20+
*
21+
* @param dev Pointer to the device structure for the driver instance.
22+
* @param mdma_rd_buf Pointer to storage for read data
23+
* @param mdma_rd_buf_size Length of the buffer to storage for read data
24+
* @param mdma_wr_buf Pointer to the data to be written
25+
* @param mdma_wr_buf_size Length of the buffer to be written
26+
*/
27+
void npcx_i3c_target_set_mdma_buff(const struct device *dev, uint8_t *mdma_rd_buf,
28+
uint16_t mdma_rd_buf_size, uint8_t *mdma_wr_buf,
29+
uint16_t mdma_wr_buf_size);
30+
31+
/**
32+
* @brief Retrieves the count of data received via MDMA.
33+
*
34+
* @param dev Pointer to the device structure for the driver instance.
35+
*
36+
* @return The number of data bytes read from the bus.
37+
*/
38+
uint16_t npcx_i3c_target_get_mdmafb_count(const struct device *dev);
39+
40+
/**
41+
* @brief Retrieves the count of data written to the bus via MDMA.
42+
*
43+
* @param dev Pointer to the device structure for the driver instance.
44+
*
45+
* @return The number of data bytes written to the bus.
46+
*/
47+
uint16_t npcx_i3c_target_get_mdmatb_count(const struct device *dev);
48+
49+
#endif
50+
51+
#ifdef __cplusplus
52+
}
53+
#endif
54+
55+
#endif /* ZEPHYR_DRIVERS_I3C_I3C_NPCX_H_ */

0 commit comments

Comments
 (0)