Skip to content

Commit 69a713b

Browse files
Ta Minh NhatKhiemNguyenT
authored andcommitted
hal: renesas: ra: add portable implementation for r_i3c
Initial support for rp_i3c. Signed-off-by: Ta Minh Nhat <[email protected]>
1 parent ae1ac54 commit 69a713b

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

zephyr/ra/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_CRC
1212
portable/src/rp_crc/rp_crc.c)
1313
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_SSI
1414
portable/src/rp_ssi/rp_ssi.c)
15+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_I3C
16+
portable/src/rp_i3c/rp_i3c.c)

zephyr/ra/portable/inc/rp_i3c.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/*******************************************************************************************************************//**
8+
* @addtogroup I3C
9+
* @{
10+
**********************************************************************************************************************/
11+
12+
#ifndef RP_I3C_H
13+
#define RP_I3C_H
14+
15+
/***********************************************************************************************************************
16+
* Includes
17+
**********************************************************************************************************************/
18+
#include "r_i3c.h"
19+
20+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
21+
FSP_HEADER
22+
23+
/***********************************************************************************************************************
24+
* Public APIs
25+
**********************************************************************************************************************/
26+
27+
fsp_err_t R_I3C_MasterDeviceTableGet(i3c_ctrl_t * const p_api_ctrl,
28+
uint32_t device_index,
29+
i3c_device_table_cfg_t * const p_device_table_cfg);
30+
fsp_err_t R_I3C_MasterDeviceTableReset(i3c_ctrl_t * const p_api_ctrl, uint32_t device_index);
31+
32+
/*******************************************************************************************************************//**
33+
* @} (end defgroup I3C)
34+
**********************************************************************************************************************/
35+
36+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
37+
FSP_FOOTER
38+
39+
#endif
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/***********************************************************************************************************************
8+
* Includes
9+
**********************************************************************************************************************/
10+
#include "r_i3c.h"
11+
#include "r_i3c_cfg.h"
12+
#include "rp_i3c.h"
13+
14+
/***********************************************************************************************************************
15+
* Macro definitions
16+
**********************************************************************************************************************/
17+
18+
/* Bitfield definitions for Command Descriptor fields. */
19+
#define R_I3C0_DATBAS0_DVDYAD_Parity_Msk (1U << 23)
20+
21+
/*******************************************************************************************************************//**
22+
* Configure an entry in the master device table. This function is called in master mode in order to configure
23+
* the devices on the I3C bus. It may also be called in slave mode when the slave receives the DEFSVLS command.
24+
*
25+
* @retval FSP_SUCCESS Open successful.
26+
* @retval FSP_ERR_ASSERTION An argument was NULL.
27+
* @retval FSP_ERR_NOT_OPEN This instance has not been opened yet.
28+
* @retval FSP_ERR_UNSUPPORTED Mastership requests must be rejected is slave support is disabled.
29+
**********************************************************************************************************************/
30+
fsp_err_t R_I3C_MasterDeviceTableGet (i3c_ctrl_t * const p_api_ctrl,
31+
uint32_t device_index,
32+
i3c_device_table_cfg_t * const p_device_table_cfg)
33+
{
34+
#if I3C_CFG_MASTER_SUPPORT
35+
i3c_instance_ctrl_t * p_ctrl = (i3c_instance_ctrl_t *) p_api_ctrl;
36+
37+
uint32_t volatile * p_datbasn_reg = NULL;
38+
uint32_t datbasn = 0;
39+
40+
if (I3C_DEVICE_INDEX_EXTENDED_DEVICE == device_index)
41+
{
42+
p_datbasn_reg = &p_ctrl->p_reg->EXDATBAS;
43+
}
44+
else
45+
{
46+
/* Compute the address of the DATBASn register. */
47+
uint32_t address_offset = (uint32_t) (&p_ctrl->p_reg->DATBAS1 - &p_ctrl->p_reg->DATBAS0);
48+
p_datbasn_reg = (uint32_t *) (&p_ctrl->p_reg->DATBAS0 + device_index * address_offset);
49+
}
50+
51+
datbasn = *((uint32_t *)p_datbasn_reg);
52+
53+
if (I3C_DEVICE_INDEX_EXTENDED_DEVICE != device_index)
54+
{
55+
p_device_table_cfg->ibi_payload = (uint8_t) ((datbasn & R_I3C0_DATBAS0_DVIBIPL_Msk) >> R_I3C0_DATBAS0_DVIBIPL_Pos);
56+
p_device_table_cfg->ibi_accept = (uint8_t) !((datbasn & R_I3C0_DATBAS0_DVSIRRJ_Msk) >> R_I3C0_DATBAS0_DVSIRRJ_Pos);
57+
p_device_table_cfg->master_request_accept = (uint8_t) !((datbasn & R_I3C0_DATBAS0_DVMRRJ_Msk) >> R_I3C0_DATBAS0_DVMRRJ_Pos);
58+
}
59+
60+
p_device_table_cfg->static_address = (uint8_t) (datbasn & R_I3C0_DATBAS0_DVSTAD_Msk) >> R_I3C0_DATBAS0_DVSTAD_Pos;
61+
p_device_table_cfg->dynamic_address = (uint8_t) ((datbasn & R_I3C0_DATBAS0_DVDYAD_Msk & (~R_I3C0_DATBAS0_DVDYAD_Parity_Msk)) >> R_I3C0_DATBAS0_DVDYAD_Pos);
62+
63+
uint32_t dvtyp = (datbasn & R_I3C0_DATBAS0_DVTYP_Msk) >> R_I3C0_DATBAS0_DVTYP_Pos;
64+
65+
if (dvtyp)
66+
{
67+
p_device_table_cfg->device_protocol = I3C_DEVICE_PROTOCOL_I2C;
68+
}
69+
else
70+
{
71+
p_device_table_cfg->device_protocol = I3C_DEVICE_PROTOCOL_I3C;
72+
}
73+
74+
return FSP_SUCCESS;
75+
#else
76+
FSP_PARAMETER_NOT_USED(p_api_ctrl);
77+
FSP_PARAMETER_NOT_USED(device_index);
78+
FSP_PARAMETER_NOT_USED(p_device_table_cfg);
79+
80+
return FSP_ERR_UNSUPPORTED;
81+
#endif
82+
}
83+
84+
fsp_err_t R_I3C_MasterDeviceTableReset (i3c_ctrl_t * const p_api_ctrl,
85+
uint32_t device_index)
86+
{
87+
#if I3C_CFG_MASTER_SUPPORT
88+
i3c_instance_ctrl_t * p_ctrl = (i3c_instance_ctrl_t *) p_api_ctrl;
89+
90+
uint32_t volatile * p_datbasn_reg = NULL;
91+
92+
if (I3C_DEVICE_INDEX_EXTENDED_DEVICE == device_index)
93+
{
94+
p_datbasn_reg = &p_ctrl->p_reg->EXDATBAS;
95+
}
96+
else
97+
{
98+
/* Compute the address of the DATBASn register. */
99+
uint32_t address_offset = (uint32_t) (&p_ctrl->p_reg->DATBAS1 - &p_ctrl->p_reg->DATBAS0);
100+
p_datbasn_reg = (uint32_t *) (&p_ctrl->p_reg->DATBAS0 + device_index * address_offset);
101+
}
102+
103+
/* Reset the DATBASn register. */
104+
*p_datbasn_reg = (uint32_t) 0U;
105+
106+
return FSP_SUCCESS;
107+
#else
108+
FSP_PARAMETER_NOT_USED(p_api_ctrl);
109+
FSP_PARAMETER_NOT_USED(device_index);
110+
111+
return FSP_ERR_UNSUPPORTED;
112+
#endif
113+
}

0 commit comments

Comments
 (0)