Skip to content

Commit a3643a2

Browse files
author
Patrice Chotard
committed
memory: stm32-omi: Fix period_ps overflow
In both drivers hyperbus-stm32.c and stm32-ospi.c, period_ps is computed using the following formula: period_ps = NSEC_PER_SEC / (bus_freq / 1000) In case bus freq < 15.259 Mhz, we got period_ps > 65535 which can't be stored in a u16. Convert period_ps from u16 to u32 to fix this issue. Update stm32_omi_find_byp_cmd() and stm32_omi_dlyb_configure() prototype accordingly. Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com> Change-Id: If8736e6bad4c5c6f240fd01a4829a441f1edb711 Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/u-boot/+/557861 ACI: CIBUILD <MDG-smet-aci-builds@list.st.com>
1 parent 8f510cb commit a3643a2

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

drivers/memory/stm32-omi.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ int stm32_omi_dlyb_set_cr(struct udevice *dev, u32 dlyb_cr)
175175
{
176176
bool bypass_mode = false;
177177
int ret;
178-
u16 period_ps;
178+
u32 period_ps;
179179
u8 rx_tap, tx_tap;
180180

181181
period_ps = FIELD_GET(DLYBOS_BYP_CMD_MASK, dlyb_cr);
@@ -210,9 +210,9 @@ static const u16 dlybos_delay_ps[STM32_DLYBOS_DELAY_NB] = {
210210
22336, 23968, 25568, 27168, 28768, 30400, 32000, 33600, 35232, 36832, 38432, 40032
211211
};
212212

213-
static u32 stm32_omi_find_byp_cmd(u16 period_ps)
213+
static u32 stm32_omi_find_byp_cmd(u32 period_ps)
214214
{
215-
u16 half_period_ps = period_ps / 2;
215+
u32 half_period_ps = period_ps / 2;
216216
u8 max = STM32_DLYBOS_DELAY_NB - 1;
217217
u8 i, min = 0;
218218

@@ -249,7 +249,7 @@ void stm32_omi_dlyb_stop(struct udevice *dev)
249249
}
250250

251251
int stm32_omi_dlyb_configure(struct udevice *dev,
252-
bool bypass_mode, u16 period_ps)
252+
bool bypass_mode, u32 period_ps)
253253
{
254254
struct stm32_omi_plat *omi_plat = dev_get_plat(dev);
255255
u32 sr, mask, val;

drivers/mtd/stm32_hyperbus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static int stm32_hb_calibrate(struct stm32_hb_priv *priv)
189189
{
190190
struct stm32_omi_plat *omi_plat = dev_get_plat(priv->omi_dev);
191191
u32 prescaler;
192-
u16 period_ps = 0;
192+
u32 period_ps = 0;
193193
u8 window_len = 0;
194194
int ret;
195195
bool bypass_mode = false;

drivers/spi/stm32_ospi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ static int stm32_ospi_dtr_calibration(struct udevice *bus)
455455
phys_addr_t regs_base = omi_plat->regs_base;
456456
u32 dcr2, prescaler;
457457
uint bus_freq;
458-
u16 period_ps = 0;
458+
u32 period_ps = 0;
459459
u8 window_len = 0;
460460
int ret;
461461
bool bypass_mode = false;

include/stm32_omi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ struct stm32_tap_window {
173173
};
174174

175175
int stm32_omi_dlyb_configure(struct udevice *dev,
176-
bool bypass_mode, u16 period_ps);
176+
bool bypass_mode, u32 period_ps);
177177
int stm32_omi_dlyb_find_tap(struct udevice *dev, bool rx_only, u8 *window_len);
178178
int stm32_omi_dlyb_set_cr(struct udevice *dev, u32 dlyb_cr);
179179
void stm32_omi_dlyb_get_cr(struct udevice *dev, u32 *dlyb_cr);

0 commit comments

Comments
 (0)