Skip to content

Commit 7bd828b

Browse files
jerome-pouillerasmellby
authored andcommitted
drivers: spi: siwx91x: Simplify gspi_siwx91x_pick_lower_freq()
Since actual_hz is no more needed, we can simplify gspi_siwx91x_pick_lower_freq(). Signed-off-by: Jérôme Pouiller <[email protected]> Upstream-status: pr <zephyrproject-rtos#100762>
1 parent 9f31828 commit 7bd828b

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

drivers/spi/spi_silabs_siwx91x_gspi.c

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,17 @@ static bool spi_siwx91x_is_dma_enabled_instance(const struct device *dev)
7676
#endif
7777
}
7878

79-
void gspi_siwx91x_pick_lower_freq(uint32_t clock_hz, uint32_t requested_hz, uint32_t *actual_hz_out,
80-
uint32_t *div_out)
79+
static uint32_t gspi_siwx91x_get_divider(uint32_t clock_hz, uint32_t requested_hz)
8180
{
82-
/* Calculate divider that ensures freq <= requested */
8381
uint32_t divider = DIV_ROUND_UP(clock_hz, 2 * requested_hz);
84-
uint32_t actual_hz;
82+
uint32_t actual_freq = clock_hz / (2U * divider);
8583

86-
if (divider == 0U) {
87-
divider = 1U;
84+
if (requested_hz != actual_freq) {
85+
LOG_INF("Requested %u Hz, programmed %u Hz (divider=%u)",
86+
requested_hz, actual_freq, divider);
8887
}
8988

90-
/* Compute the actual achievable frequency */
91-
actual_hz = clock_hz / (2U * divider);
92-
93-
if (actual_hz_out) {
94-
*actual_hz_out = actual_hz;
95-
}
96-
97-
if (div_out) {
98-
*div_out = divider;
99-
}
89+
return divider;
10090
}
10191

10292
static int gspi_siwx91x_config(const struct device *dev, const struct spi_config *spi_cfg,
@@ -105,7 +95,6 @@ static int gspi_siwx91x_config(const struct device *dev, const struct spi_config
10595
__maybe_unused struct gspi_siwx91x_data *data = dev->data;
10696
const struct gspi_siwx91x_config *cfg = dev->config;
10797
uint32_t clk_div_factor;
108-
uint32_t actual_freq;
10998
uint32_t clock_rate;
11099
int ret;
111100
__maybe_unused int channel_filter;
@@ -142,13 +131,7 @@ static int gspi_siwx91x_config(const struct device *dev, const struct spi_config
142131
if (ret) {
143132
return ret;
144133
}
145-
146-
gspi_siwx91x_pick_lower_freq(clock_rate, spi_cfg->frequency, &actual_freq,
147-
&clk_div_factor);
148-
if (spi_cfg->frequency != actual_freq) {
149-
LOG_INF("Requested %u Hz, programmed %u Hz (divider=%u)",
150-
spi_cfg->frequency, actual_freq, clk_div_factor);
151-
}
134+
clk_div_factor = gspi_siwx91x_get_divider(clock_rate, spi_cfg->frequency);
152135
}
153136

154137
/* Set the clock divider factor */

0 commit comments

Comments
 (0)