-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Introduce TI EHRPWM/EPWM driver and syscon clock controller #88757
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
Open
natto1784
wants to merge
2
commits into
zephyrproject-rtos:main
Choose a base branch
from
natto1784:ehrpwm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
# Copyright (c) 2025 Texas Instruments | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config CLOCK_CONTROL_TI_SYSCON | ||
bool "TI Syscon backed gate-clock driver" | ||
default y | ||
depends on DT_HAS_TI_AM654_EHRPWM_TBCLK_ENABLED || DT_HAS_TI_AM64_EPWM_TBCLK_ENABLED || DT_HAS_TI_AM62_EPWM_TBCLK_ENABLED | ||
select SYSCON | ||
help | ||
Enable driver for TI Syscon backed gate-clock controller. |
This file contains hidden or 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,132 @@ | ||
/* | ||
* Copyright 2025 Texas Instruments | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#define DT_AM654_COMPAT ti_am654_ehrpwm_tbclk | ||
#define DT_AM64_COMPAT ti_am64_epwm_tbclk | ||
#define DT_AM62_COMPAT ti_am62_epwm_tbclk | ||
|
||
#include <zephyr/drivers/clock_control.h> | ||
#include <zephyr/drivers/syscon.h> | ||
#include <zephyr/logging/log.h> | ||
|
||
LOG_MODULE_REGISTER(ti_syscon_gate_clk, CONFIG_CLOCK_CONTROL_LOG_LEVEL); | ||
|
||
#define DEV_CFG(dev) ((struct ti_syscon_gate_clk_cfg *)(dev)->config) | ||
|
||
struct ti_syscon_gate_clk_id_data { | ||
uint32_t offset; | ||
uint32_t bit; | ||
}; | ||
|
||
#if DT_HAS_COMPAT_STATUS_OKAY(DT_AM64_COMPAT) | ||
static const struct ti_syscon_gate_clk_id_data am64_clk_ids[] = { | ||
{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8}, | ||
}; | ||
#endif | ||
|
||
#if DT_HAS_COMPAT_STATUS_OKAY(DT_AM654_COMPAT) | ||
static const struct ti_syscon_gate_clk_id_data am654_clk_ids[] = { | ||
{0x0, 0}, {0x4, 0}, {0x8, 0}, {0xc, 0}, {0x10, 0}, {0x14, 0}, | ||
}; | ||
#endif | ||
|
||
#if DT_HAS_COMPAT_STATUS_OKAY(DT_AM62_COMPAT) | ||
static const struct ti_syscon_gate_clk_id_data am62_clk_ids[] = { | ||
{0, 0}, | ||
{0, 1}, | ||
{0, 2}, | ||
}; | ||
#endif | ||
|
||
struct ti_syscon_gate_clk_cfg { | ||
mm_reg_t reg; | ||
const struct device *syscon; | ||
const struct ti_syscon_gate_clk_id_data *clk_ids; | ||
const uint32_t num_clk_ids; | ||
}; | ||
|
||
static int ti_syscon_gate_clk_enable(const struct device *dev, clock_control_subsys_t sub_system, | ||
bool enable) | ||
{ | ||
const struct ti_syscon_gate_clk_cfg *cfg = DEV_CFG(dev); | ||
uint32_t clk_id = (sub_system ? (uint32_t)sub_system : 0); | ||
uint32_t reg; | ||
uint32_t bit; | ||
uint32_t val; | ||
uint32_t rb; | ||
int err; | ||
|
||
if (clk_id >= cfg->num_clk_ids) { | ||
LOG_ERR("invalid clk id"); | ||
return -EINVAL; | ||
} | ||
|
||
reg = cfg->reg + cfg->clk_ids[clk_id].offset; | ||
bit = cfg->clk_ids[clk_id].bit; | ||
|
||
err = syscon_read_reg(cfg->syscon, reg, &val); | ||
if (err < 0) { | ||
LOG_ERR("failed to read syscon register"); | ||
return err; | ||
} | ||
|
||
if (enable) { | ||
val |= BIT(bit); | ||
} else { | ||
val &= ~BIT(bit); | ||
} | ||
|
||
err = syscon_write_reg(cfg->syscon, reg, val); | ||
if (err < 0) { | ||
LOG_ERR("failed to write syscon register"); | ||
return err; | ||
} | ||
|
||
err = syscon_read_reg(cfg->syscon, reg, &rb); | ||
if (err < 0) { | ||
LOG_ERR("failed to read syscon register"); | ||
return err; | ||
} | ||
|
||
if (rb != val) { | ||
LOG_ERR("readback does not match written value"); | ||
return -EIO; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static int ti_syscon_gate_clk_on(const struct device *dev, clock_control_subsys_t sub_system) | ||
{ | ||
return ti_syscon_gate_clk_enable(dev, sub_system, true); | ||
} | ||
|
||
static int ti_syscon_gate_clk_off(const struct device *dev, clock_control_subsys_t sub_system) | ||
{ | ||
return ti_syscon_gate_clk_enable(dev, sub_system, false); | ||
} | ||
|
||
static DEVICE_API(clock_control, ti_syscon_gate_clk_driver_api) = { | ||
.on = ti_syscon_gate_clk_on, | ||
.off = ti_syscon_gate_clk_off, | ||
}; | ||
|
||
#define TI_SYSCON_GATE_CLK_INIT(node, clks) \ | ||
static const struct ti_syscon_gate_clk_cfg ti_syscon_gate_clk_config_##node = { \ | ||
.reg = DT_REG_ADDR(node), \ | ||
.syscon = DEVICE_DT_GET(DT_PARENT(node)), \ | ||
.clk_ids = clks, \ | ||
.num_clk_ids = ARRAY_SIZE(clks), \ | ||
}; \ | ||
\ | ||
DEVICE_DT_DEFINE(node, NULL, NULL, NULL, &ti_syscon_gate_clk_config_##node, POST_KERNEL, \ | ||
CONFIG_CLOCK_CONTROL_INIT_PRIORITY, &ti_syscon_gate_clk_driver_api); | ||
|
||
/* add more compats as required */ | ||
|
||
DT_FOREACH_STATUS_OKAY_VARGS(DT_AM654_COMPAT, TI_SYSCON_GATE_CLK_INIT, am654_clk_ids) | ||
DT_FOREACH_STATUS_OKAY_VARGS(DT_AM64_COMPAT, TI_SYSCON_GATE_CLK_INIT, am64_clk_ids) | ||
DT_FOREACH_STATUS_OKAY_VARGS(DT_AM62_COMPAT, TI_SYSCON_GATE_CLK_INIT, am62_clk_ids) |
This file contains hidden or 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 hidden or 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 hidden or 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,9 @@ | ||
# Copyright (c) 2025 Texas Instruments | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config PWM_TI_AM3352_EHRPWM | ||
bool "TI EHRPWM based PWM controller" | ||
default y | ||
depends on DT_HAS_TI_AM3352_EHRPWM_ENABLED | ||
help | ||
Enable EHRPWM controller for TI SoCs |
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.
Any good way to encode this data into DT so that we don't need to keep device specific data here in the driver?
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.
Actually, I replicated this behavior from Linux where several compat strings can stay in the same driver code.
To answer your question, this can be added to the DT, provided noone has a problem with this big array of register indices in the node.