-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
siwx917: Add clock driver #77
Merged
jhedberg
merged 6 commits into
SiliconLabsSoftware:main
from
jerome-pouiller:add-clock-driver
Jan 15, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
882bbf3
soc: silabs: siwg917: Rename ulpuart0 in ulpuart
jerome-pouiller 8681798
soc: silabs: siwg917: Rename udma1 in ulpdma
jerome-pouiller 652a099
soc: silabs: siwg917: Rename udma0 in dma0
jerome-pouiller 8190731
soc: silabs: siwg917: Import clock_update.c
jerome-pouiller 297ddc9
drivers: clock: siwx917: Add dumb clock driver
jerome-pouiller 7cfab04
drivers: dma: siwx917: Manage the clock
jerome-pouiller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright (c) 2024 Silicon Laboratories Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
zephyr_library_amend() | ||
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_SILABS_SIWX917 clock_control_silabs_siwx917.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright (c) 2024 Silicon Laboratories Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
if CLOCK_CONTROL | ||
|
||
rsource "Kconfig.siwx917" | ||
|
||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright (c) 2024 Silicon Laboratories Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config CLOCK_CONTROL_SILABS_SIWX917 | ||
bool "SiWx917 clock control driver" | ||
default y | ||
depends on DT_HAS_SILABS_SIWX917_CLOCK_ENABLED | ||
help | ||
Enable clock management on Silicon Labs SiWx917 chips. This driver | ||
includes support for HP (High Performace), ULP (Ultra Low Power), and | ||
ULP VBAT clocks. | ||
|
||
The original hardware allow to customize the various clocks offered for | ||
every devices. This driver does not provide such customizations. It | ||
just hardcodes sane default parameters for every devices. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
/* Copyright (c) 2024 Silicon Laboratories Inc. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Poor man driver for 917 clocks. 917 includes High Performace (HP) clock | ||
* (@46000000), Ultra Lower Power (ULP) clock (@24041400) and ULP VBAT (@24048000) | ||
* | ||
*/ | ||
#include <zephyr/dt-bindings/clock/silabs/siwx917-clock.h> | ||
#include <zephyr/drivers/clock_control.h> | ||
#include <zephyr/logging/log.h> | ||
|
||
#include "rsi_power_save.h" | ||
#include "rsi_rom_ulpss_clk.h" | ||
#include "rsi_rom_clks.h" | ||
#include "clock_update.h" | ||
#include "sl_si91x_clock_manager.h" | ||
|
||
#define DT_DRV_COMPAT silabs_siwx917_clock | ||
|
||
LOG_MODULE_REGISTER(siwx917_clock, CONFIG_CLOCK_CONTROL_LOG_LEVEL); | ||
|
||
struct siwx917_clock_data { | ||
uint32_t enable; | ||
}; | ||
|
||
static int siwx917_clock_on(const struct device *dev, clock_control_subsys_t sys) | ||
{ | ||
struct siwx917_clock_data *data = dev->data; | ||
uintptr_t clockid = (uintptr_t)sys; | ||
|
||
switch (clockid) { | ||
case SIWX917_CLK_ULP_UART: | ||
RSI_PS_UlpssPeriPowerUp(ULPSS_PWRGATE_ULP_UART); | ||
RSI_ULPSS_UlpUartClkConfig(ULPCLK, ENABLE_STATIC_CLK, | ||
false, ULP_UART_ULP_32MHZ_RC_CLK, 1); | ||
break; | ||
Check notice on line 36 in drivers/clock_control/clock_control_silabs_siwx917.c GitHub Actions / complianceYou may want to run clang-format on this change
|
||
case SIWX917_CLK_ULP_I2C: | ||
RSI_PS_UlpssPeriPowerUp(ULPSS_PWRGATE_ULP_I2C); | ||
RSI_ULPSS_PeripheralEnable(ULPCLK, ULP_I2C_CLK, ENABLE_STATIC_CLK); | ||
break; | ||
case SIWX917_CLK_ULP_DMA: | ||
RSI_PS_UlpssPeriPowerUp(ULPSS_PWRGATE_ULP_UDMA); | ||
RSI_ULPSS_PeripheralEnable(ULPCLK, ULP_UDMA_CLK, ENABLE_STATIC_CLK); | ||
break; | ||
case SIWX917_CLK_UART1: | ||
RSI_PS_M4ssPeriPowerUp(M4SS_PWRGATE_ULP_EFUSE_PERI); | ||
/* RSI_CLK_UsartClkConfig() calls RSI_CLK_PeripheralClkEnable(); */ | ||
RSI_CLK_UsartClkConfig(M4CLK, ENABLE_STATIC_CLK, 0, USART1, 0, 1); | ||
break; | ||
case SIWX917_CLK_UART2: | ||
RSI_PS_M4ssPeriPowerUp(M4SS_PWRGATE_ULP_EFUSE_PERI); | ||
/* RSI_CLK_UsartClkConfig() calls RSI_CLK_PeripheralClkEnable(); */ | ||
RSI_CLK_UsartClkConfig(M4CLK, ENABLE_STATIC_CLK, 0, USART2, 0, 1); | ||
break; | ||
case SIWX917_CLK_I2C0: | ||
RSI_PS_M4ssPeriPowerUp(M4SS_PWRGATE_ULP_EFUSE_PERI); | ||
RSI_CLK_I2CClkConfig(M4CLK, true, 0); | ||
break; | ||
case SIWX917_CLK_I2C1: | ||
RSI_PS_M4ssPeriPowerUp(M4SS_PWRGATE_ULP_EFUSE_PERI); | ||
RSI_CLK_I2CClkConfig(M4CLK, true, 1); | ||
break; | ||
case SIWX917_CLK_DMA0: | ||
RSI_PS_M4ssPeriPowerUp(M4SS_PWRGATE_ULP_EFUSE_PERI); | ||
RSI_CLK_PeripheralClkEnable(M4CLK, UDMA_CLK, ENABLE_STATIC_CLK); | ||
break; | ||
default: | ||
return -EINVAL; | ||
} | ||
data->enable |= BIT(clockid); | ||
|
||
return 0; | ||
} | ||
|
||
static int siwx917_clock_off(const struct device *dev, clock_control_subsys_t sys) | ||
{ | ||
struct siwx917_clock_data *data = dev->data; | ||
uintptr_t clockid = (uintptr_t)sys; | ||
|
||
switch (clockid) { | ||
case SIWX917_CLK_ULP_I2C: | ||
RSI_ULPSS_PeripheralDisable(ULPCLK, ULP_I2C_CLK); | ||
break; | ||
case SIWX917_CLK_ULP_DMA: | ||
RSI_ULPSS_PeripheralDisable(ULPCLK, ULP_UDMA_CLK); | ||
break; | ||
case SIWX917_CLK_UART1: | ||
RSI_CLK_PeripheralClkDisable(M4CLK, USART1_CLK); | ||
break; | ||
case SIWX917_CLK_UART2: | ||
RSI_CLK_PeripheralClkDisable(M4CLK, USART2_CLK); | ||
break; | ||
case SIWX917_CLK_DMA0: | ||
RSI_CLK_PeripheralClkDisable(M4CLK, UDMA_CLK); | ||
break; | ||
case SIWX917_CLK_ULP_UART: | ||
case SIWX917_CLK_I2C0: | ||
case SIWX917_CLK_I2C1: | ||
/* Not supported */ | ||
return 0; | ||
default: | ||
return -EINVAL; | ||
} | ||
|
||
data->enable &= ~BIT(clockid); | ||
return 0; | ||
} | ||
|
||
static int siwx917_clock_get_rate(const struct device *dev, clock_control_subsys_t sys, | ||
uint32_t *rate) | ||
{ | ||
uintptr_t clockid = (uintptr_t)sys; | ||
|
||
switch (clockid) { | ||
case SIWX917_CLK_ULP_UART: | ||
*rate = RSI_CLK_GetBaseClock(ULPSS_UART); | ||
return 0; | ||
case SIWX917_CLK_UART1: | ||
*rate = RSI_CLK_GetBaseClock(M4_USART0); | ||
return 0; | ||
case SIWX917_CLK_UART2: | ||
*rate = RSI_CLK_GetBaseClock(M4_UART1); | ||
return 0; | ||
default: | ||
/* For now, no other driver need clock rate */ | ||
return -EINVAL; | ||
} | ||
} | ||
|
||
static enum clock_control_status siwx917_clock_get_status(const struct device *dev, | ||
clock_control_subsys_t sys) | ||
{ | ||
struct siwx917_clock_data *data = dev->data; | ||
uintptr_t clockid = (uintptr_t)sys; | ||
|
||
if (data->enable & BIT(clockid)) { | ||
return CLOCK_CONTROL_STATUS_ON; | ||
} else { | ||
return CLOCK_CONTROL_STATUS_OFF; | ||
} | ||
} | ||
|
||
static int siwx917_clock_init(const struct device *dev) | ||
{ | ||
SystemCoreClockUpdate(); | ||
|
||
/* Use SoC PLL at configured frequency as core clock */ | ||
sl_si91x_clock_manager_m4_set_core_clk(M4_SOCPLLCLK, CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC); | ||
|
||
/* Use interface PLL at configured frequency as peripheral clock */ | ||
sl_si91x_clock_manager_set_pll_freq(INFT_PLL, CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC, | ||
PLL_REF_CLK_VAL_XTAL); | ||
|
||
/* FIXME: Currently the clock consumer use clocks without power on them. | ||
* This should be fixed in drivers. Meanwhile, get the list of required | ||
* clocks using DT labels. | ||
*/ | ||
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ulpuart), okay) | ||
siwx917_clock_on(dev, (clock_control_subsys_t)SIWX917_CLK_ULP_UART); | ||
#endif | ||
|
||
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ulpi2c), okay) | ||
siwx917_clock_on(dev, (clock_control_subsys_t)SIWX917_CLK_ULP_I2C); | ||
#endif | ||
|
||
#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) | ||
siwx917_clock_on(dev, (clock_control_subsys_t)SIWX917_CLK_UART1); | ||
#endif | ||
|
||
#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) | ||
siwx917_clock_on(dev, (clock_control_subsys_t)SIWX917_CLK_UART2); | ||
#endif | ||
|
||
#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c0), okay) | ||
siwx917_clock_on(dev, (clock_control_subsys_t)SIWX917_CLK_I2C0); | ||
#endif | ||
|
||
#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) | ||
siwx917_clock_on(dev, (clock_control_subsys_t)SIWX917_CLK_I2C1); | ||
#endif | ||
|
||
return 0; | ||
} | ||
|
||
static const struct clock_control_driver_api siwx917_clock_api = { | ||
.on = siwx917_clock_on, | ||
.off = siwx917_clock_off, | ||
.get_rate = siwx917_clock_get_rate, | ||
.get_status = siwx917_clock_get_status, | ||
}; | ||
|
||
#define SIWX917_CLOCK_INIT(p) \ | ||
static struct siwx917_clock_data siwx917_clock_data_##p; \ | ||
DEVICE_DT_INST_DEFINE(p, siwx917_clock_init, NULL, &siwx917_clock_data_##p, NULL, \ | ||
PRE_KERNEL_1, CONFIG_CLOCK_CONTROL_INIT_PRIORITY, \ | ||
&siwx917_clock_api); | ||
Check notice on line 196 in drivers/clock_control/clock_control_silabs_siwx917.c GitHub Actions / complianceYou may want to run clang-format on this change
|
||
|
||
DT_INST_FOREACH_STATUS_OKAY(SIWX917_CLOCK_INIT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should be using
DEVICE_API()
like here:https://github.com/zephyrproject-rtos/zephyr/blob/59c94db6f052c9d848b4cec2008152d32d8ee597/drivers/clock_control/clock_control_nrf.c#L695-L700
It's a fairly new convention, so if we're not pointing at a recent enough upstream yet, then that needs to be fixed first. Most likely the same update will need to be made to any other of our downstream 917 drivers.