|
| 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