-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Move STM32 MCO configuration from Kconfig to dts #68846
Closed
benjaminbjornsson
wants to merge
3
commits into
zephyrproject-rtos:main
from
benjaminbjornsson:add-mco-driver
Closed
Changes from 1 commit
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) 2024 Benjamin Björnsson <benjamin.bjornsson@gmail.com> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#define DT_DRV_COMPAT st_stm32_mco_clock | ||
|
||
#include <zephyr/arch/common/sys_bitops.h> | ||
#include <zephyr/device.h> | ||
#include <zephyr/devicetree.h> | ||
#include <zephyr/drivers/clock_control/stm32_clock_control.h> | ||
#include <zephyr/drivers/pinctrl.h> | ||
|
||
#include <stdint.h> | ||
|
||
struct clock_control_stm32_mco_config { | ||
uint32_t base; | ||
const struct stm32_pclken *pclken; | ||
size_t pclk_len; | ||
const struct pinctrl_dev_config *pcfg; | ||
}; | ||
|
||
static int clock_control_stm32_mco_init(const struct device *dev) | ||
{ | ||
const struct clock_control_stm32_mco_config *config = dev->config; | ||
|
||
for (int i = 0; i < config->pclk_len; i++) { | ||
sys_clear_bits(config->base + STM32_CLOCK_REG_GET(config->pclken->enr), | ||
STM32_CLOCK_MASK_GET(config->pclken[i].enr) | ||
<< STM32_CLOCK_SHIFT_GET(config->pclken[i].enr)); | ||
sys_set_bits(config->base + STM32_CLOCK_REG_GET(config->pclken->enr), | ||
STM32_CLOCK_VAL_GET(config->pclken[i].enr) | ||
<< STM32_CLOCK_SHIFT_GET(config->pclken[i].enr)); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
#define STM32_MCO_INIT(inst) \ | ||
PINCTRL_DT_INST_DEFINE(inst); \ | ||
\ | ||
static const struct stm32_pclken pclken_##inst[] = STM32_DT_INST_CLOCKS(inst); \ | ||
\ | ||
static struct clock_control_stm32_mco_config clk_cfg_##inst = { \ | ||
.base = DT_REG_ADDR(DT_INST_CLOCKS_CTLR(inst)), \ | ||
.pclken = pclken_##inst, \ | ||
.pclk_len = DT_INST_NUM_CLOCKS(inst), \ | ||
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ | ||
}; \ | ||
\ | ||
DEVICE_DT_INST_DEFINE(inst, &clock_control_stm32_mco_init, \ | ||
NULL, NULL, &clk_cfg_##inst, \ | ||
PRE_KERNEL_1, CONFIG_CLOCK_CONTROL_INIT_PRIORITY, \ | ||
NULL); | ||
|
||
DT_INST_FOREACH_STATUS_OKAY(STM32_MCO_INIT) | ||
|
||
#define GET_DEV(node_id) DEVICE_DT_GET(node_id), | ||
|
||
static int stm32_mco_pinctrl_init(void) | ||
{ | ||
const struct device *dev_list[] = {DT_FOREACH_STATUS_OKAY(st_stm32_mco_clock, GET_DEV)}; | ||
int list_len = ARRAY_SIZE(dev_list); | ||
|
||
for (int i = 0; i < list_len; i++) { | ||
const struct clock_control_stm32_mco_config *config = dev_list[i]->config; | ||
int res = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); | ||
if (res < 0) { | ||
return res; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
/* Need to be initialised after GPIO driver */ | ||
SYS_INIT(stm32_mco_pinctrl_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); |
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,16 @@ | ||
# Copyright (c) 2023 Benjamin Björnsson <benjamin.bjornsson@gmail.com> | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
description: STM32 MCO Clock | ||
|
||
compatible: "st,stm32-mco-clock" | ||
|
||
include: [pinctrl-device.yaml, base.yaml] | ||
|
||
properties: | ||
|
||
pinctrl-0: | ||
required: true | ||
|
||
pinctrl-names: | ||
required: true |
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.
Altenatively, this could remain a routine of the clock_control diver (called before clock configuretion) and as such, reuse
stm32_clock_control_on
internal calls.