Skip to content

Commit

Permalink
drivers: stm32_i2c: rely on DT compat ID for secure/non-secure bus state
Browse files Browse the repository at this point in the history
Change STM32 I2C driver to rely on the compatible DT property of the
node to store whether the bus is expected assigned to secure or
non-secure world. Using a non-secure I2C bus in OP-TEE on stm32mp1
platforms is something expected only on STM32MP15 variant for
compatibility with platform already supported in upstream Linux/U-Boot
components, as defined by st,stm32mp15-i2c-non-secure specific
compatible string ID.

Signed-off-by: Etienne Carriere <[email protected]>
  • Loading branch information
etienne-lms committed Dec 10, 2024
1 parent 7c98709 commit aa4b12f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
3 changes: 1 addition & 2 deletions core/arch/arm/plat-stm32mp1/drivers/stm32mp1_pmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ static void init_pmic_state(const void *fdt, int pmic_node)

static bool dt_pmic_is_secure(void)
{
return stm32mp_with_pmic() &&
i2c_handle->dt_status == DT_STATUS_OK_SEC;
return stm32mp_with_pmic() && i2c_is_secure(i2c_handle);
}

static void priv_dt_properties(const void *fdt, int regu_node,
Expand Down
14 changes: 10 additions & 4 deletions core/drivers/stm32_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,6 @@ TEE_Result stm32_i2c_get_setup_from_fdt(void *fdt, int node,
assert(info.reg != DT_INFO_INVALID_REG &&
info.reg_size != DT_INFO_INVALID_REG_SIZE);

init->dt_status = info.status;
init->pbase = info.reg;
init->reg_size = info.reg_size;

Expand Down Expand Up @@ -1628,8 +1627,10 @@ static TEE_Result stm32_get_i2c_dev(struct dt_pargs *args, void *data,
return TEE_SUCCESS;
}

static const int non_secure_bus;

static TEE_Result stm32_i2c_probe(const void *fdt, int node,
const void *compat_data __unused)
const void *compat_data)
{
TEE_Result res = TEE_SUCCESS;
int subnode = 0;
Expand All @@ -1647,7 +1648,6 @@ static TEE_Result stm32_i2c_probe(const void *fdt, int node,
if (!i2c_handle_p)
return TEE_ERROR_OUT_OF_MEMORY;

i2c_handle_p->dt_status = init_data.dt_status;
i2c_handle_p->reg_size = init_data.reg_size;
i2c_handle_p->clock = init_data.clock;
i2c_handle_p->base.pa = init_data.pbase;
Expand All @@ -1659,6 +1659,9 @@ static TEE_Result stm32_i2c_probe(const void *fdt, int node,
i2c_handle_p->pinctrl = pinctrl_active;
i2c_handle_p->pinctrl_sleep = pinctrl_idle;

if (compat_data != &non_secure_bus)
i2c_handle_p->i2c_secure = true;

init_data.analog_filter = true;
init_data.digital_filter_coef = 0;

Expand All @@ -1684,7 +1687,10 @@ static TEE_Result stm32_i2c_probe(const void *fdt, int node,
static const struct dt_device_match stm32_i2c_match_table[] = {
{ .compatible = "st,stm32mp15-i2c" },
{ .compatible = "st,stm32mp13-i2c" },
{ .compatible = "st,stm32mp15-i2c-non-secure" },
{
.compatible = "st,stm32mp15-i2c-non-secure",
.compat_data = &non_secure_bus,
},
{ }
};

Expand Down
7 changes: 2 additions & 5 deletions core/include/drivers/stm32_i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
/*
* struct stm32_i2c_init_s - STM32 I2C configuration data
*
* @dt_status: non-secure/secure status read from DT
* @pbase: I2C interface base address
* @reg_size: I2C interface register map size
* @clock: I2C bus/interface clock
Expand All @@ -50,7 +49,6 @@
* @digital_filter_coef: filter coef (below STM32_I2C_DIGITAL_FILTER_MAX)
*/
struct stm32_i2c_init_s {
unsigned int dt_status;
paddr_t pbase;
size_t reg_size;
struct clk *clock;
Expand Down Expand Up @@ -106,7 +104,6 @@ struct i2c_cfg {
* I2C bus device
* @base: I2C SoC registers base address
* @reg_size: I2C SoC registers address map size
* @dt_status: non-secure/secure status read from DT
* @clock: clock ID
* @i2c_state: Driver state ID I2C_STATE_*
* @i2c_err: Last error code I2C_ERROR_*
Expand All @@ -120,7 +117,6 @@ struct i2c_cfg {
struct i2c_handle_s {
struct io_pa_va base;
size_t reg_size;
unsigned int dt_status;
struct clk *clock;
enum i2c_state_e i2c_state;
uint32_t i2c_err;
Expand All @@ -130,6 +126,7 @@ struct i2c_handle_s {
struct pinctrl_state *pinctrl;
struct pinctrl_state *pinctrl_sleep;
struct mutex_pm_aware mu;
bool i2c_secure;
};

/*
Expand Down Expand Up @@ -278,7 +275,7 @@ void stm32_i2c_resume(struct i2c_handle_s *hi2c);
*/
static inline bool i2c_is_secure(struct i2c_handle_s *hi2c)
{
return hi2c->dt_status == DT_STATUS_OK_SEC;
return hi2c->i2c_secure;
}

#endif /* __DRIVERS_STM32_I2C_H*/

0 comments on commit aa4b12f

Please sign in to comment.