Skip to content

Commit

Permalink
drivers: stm32_i2c: use compatible st,stm32mp15-i2c-non-secure
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]>
Acked-by: Gatien Chevallier <[email protected]>
  • Loading branch information
etienne-lms authored and jforissier committed Jan 24, 2025
1 parent 234a510 commit ded2078
Show file tree
Hide file tree
Showing 3 changed files with 14 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
15 changes: 11 additions & 4 deletions core/drivers/stm32_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ struct i2c_request {
unsigned int timeout_ms;
};

/* Place holder for STM32MP15 non-secure I2C bus compat data */
static const int non_secure_bus;

static vaddr_t get_base(struct i2c_handle_s *hi2c)
{
return io_pa_or_va_secure(&hi2c->base, hi2c->reg_size);
Expand Down Expand Up @@ -695,7 +698,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 @@ -1629,7 +1631,7 @@ static TEE_Result stm32_get_i2c_dev(struct dt_pargs *args, void *data,
}

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 +1649,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 +1660,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 +1688,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 ded2078

Please sign in to comment.