Skip to content

Commit edca610

Browse files
committed
drivers: firmware: Clock control TISCI driver support
Support added for clock control using TISCI for devices using the binding ti,k2g-sci-clk. This driver relies on the TISCI layer to make calls to the DMSC core to set and get the clock rate and retrieve clock status. Signed-off-by: Dave Joseph <[email protected]>
1 parent 3daddb8 commit edca610

File tree

6 files changed

+174
-0
lines changed

6 files changed

+174
-0
lines changed

drivers/clock_control/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_SI32_PLL clock_control_si32_pl
132132
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_SILABS_SERIES clock_control_silabs_series.c)
133133
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_SILABS_SIWX91X clock_control_silabs_siwx91x.c)
134134
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_SMARTBOND clock_control_smartbond.c)
135+
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_TISCI clock_control_tisci.c)
135136
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_WCH_RCC clock_control_wch_rcc.c)
136137
zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_AGILEX clock_agilex.c)
137138
zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_AGILEX clock_agilex_ll.c)

drivers/clock_control/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ source "drivers/clock_control/Kconfig.silabs"
7474
source "drivers/clock_control/Kconfig.siwx91x"
7575
source "drivers/clock_control/Kconfig.smartbond"
7676
source "drivers/clock_control/Kconfig.stm32"
77+
source "drivers/clock_control/Kconfig.tisci"
7778
source "drivers/clock_control/Kconfig.wch_rcc"
7879
source "drivers/clock_control/Kconfig.xec"
7980
# zephyr-keep-sorted-stop
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright 2024 Texas Instruments Incorporated.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config CLOCK_CONTROL_TISCI
5+
bool "TI SCI Clock Control driver"
6+
default y
7+
depends on DT_HAS_TI_K2G_SCI_CLK_ENABLED
8+
help
9+
Driver for TISCI based clock control.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (c) 2025, Texas Instruments
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define DT_DRV_COMPAT ti_k2g_sci_clk
8+
9+
#include <zephyr/device.h>
10+
#include <zephyr/drivers/firmware/tisci/tisci.h>
11+
#include <zephyr/drivers/clock_control.h>
12+
#include <zephyr/drivers/clock_control/tisci_clock_control.h>
13+
#include <zephyr/devicetree.h>
14+
#include <zephyr/logging/log.h>
15+
16+
LOG_MODULE_REGISTER(ti_k2g_sci_clk, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
17+
18+
static const struct device *dmsc = DEVICE_DT_GET(DT_NODELABEL(dmsc));
19+
20+
static int tisci_get_rate(const struct device *dev, clock_control_subsys_t sys, uint32_t *rate)
21+
{
22+
struct tisci_clock_config *req = (struct tisci_clock_config *)sys;
23+
uint64_t temp_rate;
24+
int ret;
25+
26+
ret = tisci_cmd_clk_get_freq(dmsc, req->dev_id, req->clk_id, &temp_rate);
27+
if (ret) {
28+
LOG_ERR("Failed to get clock freq: dev_id=%u clk_id=%u err=%d", req->dev_id,
29+
req->clk_id, ret);
30+
return ret;
31+
}
32+
33+
*rate = (uint32_t)temp_rate;
34+
35+
return 0;
36+
}
37+
38+
static int tisci_set_rate(const struct device *dev, void *sys, void *rate)
39+
{
40+
struct tisci_clock_config *req = (struct tisci_clock_config *)sys;
41+
uint64_t freq = *((uint64_t *)rate);
42+
int ret;
43+
44+
ret = tisci_cmd_clk_set_freq(dmsc, req->dev_id, req->clk_id, freq, freq, freq);
45+
if (ret) {
46+
LOG_ERR("Failed to set clock freq: dev_id=%u clk_id=%u freq=%llu err=%d",
47+
req->dev_id, req->clk_id, freq, ret);
48+
}
49+
50+
return ret;
51+
}
52+
53+
static enum clock_control_status tisci_get_status(const struct device *dev,
54+
clock_control_subsys_t sys)
55+
{
56+
struct tisci_clock_config *req = (struct tisci_clock_config *)sys;
57+
bool req_state = true;
58+
bool curr_state = true;
59+
int ret;
60+
61+
ret = tisci_cmd_clk_is_on(dmsc, req->clk_id, req->dev_id, &req_state, &curr_state);
62+
if (ret) {
63+
LOG_ERR("Failed to get clock ON status: dev_id=%u clk_id=%u err=%d", req->dev_id,
64+
req->clk_id, ret);
65+
return CLOCK_CONTROL_STATUS_UNKNOWN;
66+
}
67+
if (curr_state) {
68+
return CLOCK_CONTROL_STATUS_ON;
69+
}
70+
if (req_state && !curr_state) {
71+
return CLOCK_CONTROL_STATUS_STARTING;
72+
}
73+
74+
curr_state = true;
75+
76+
ret = tisci_cmd_clk_is_off(dmsc, req->clk_id, req->dev_id, NULL, &curr_state);
77+
if (ret) {
78+
LOG_ERR("Failed to get clock OFF status: dev_id=%u clk_id=%u err=%d", req->dev_id,
79+
req->clk_id, ret);
80+
return CLOCK_CONTROL_STATUS_UNKNOWN;
81+
}
82+
83+
if (curr_state) {
84+
return CLOCK_CONTROL_STATUS_OFF;
85+
}
86+
87+
return CLOCK_CONTROL_STATUS_UNKNOWN;
88+
}
89+
90+
static DEVICE_API(clock_control, tisci_clock_driver_api) = {
91+
.get_rate = tisci_get_rate,
92+
.set_rate = tisci_set_rate,
93+
.get_status = tisci_get_status
94+
};
95+
96+
#define TI_K2G_SCI_CLK_INIT(_n) \
97+
DEVICE_DT_INST_DEFINE(_n, NULL, NULL, NULL, NULL, PRE_KERNEL_1, \
98+
CONFIG_CLOCK_CONTROL_INIT_PRIORITY, &tisci_clock_driver_api);
99+
100+
DT_INST_FOREACH_STATUS_OKAY(TI_K2G_SCI_CLK_INIT)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2025 Texas Instruments Incorporated.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: TI-SCI clock controller
5+
6+
compatible: "ti,k2g-sci-clk"
7+
8+
include:
9+
- clock-controller.yaml
10+
- base.yaml
11+
12+
properties:
13+
"#clock-cells":
14+
type: int
15+
required: true
16+
description: >
17+
Number of cells required to specify a clock provided by this controller.
18+
const: 2
19+
20+
clock-cells:
21+
- devid
22+
- clkid
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2025 Texas Instruments
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_TISCI_CLOCK_CONTROL_H_
7+
#define ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_TISCI_CLOCK_CONTROL_H_
8+
9+
#include <stdint.h>
10+
11+
/**
12+
* @struct tisci_clock_config
13+
* @brief Clock configuration structure
14+
*
15+
* This structure is used to define the configuration for a clock, including
16+
* the device ID and clock ID.
17+
*
18+
* @param tisci_clock_config::dev_id
19+
* Device ID associated with the clock.
20+
*
21+
* @param tisci_clock_config::clk_id
22+
* Clock ID within the device.
23+
*/
24+
struct tisci_clock_config {
25+
uint32_t dev_id;
26+
uint32_t clk_id;
27+
};
28+
29+
#define TISCI_GET_CLOCK(node_id) DEVICE_DT_GET(DT_PHANDLE(node_id, clocks))
30+
31+
#define TISCI_GET_CLOCK_DETAILS(node_id) \
32+
{ \
33+
.dev_id = DT_CLOCKS_CELL(node_id, devid), \
34+
.clk_id = DT_CLOCKS_CELL(node_id, clkid) \
35+
}
36+
37+
#define TISCI_GET_CLOCK_BY_INST(inst) TISCI_GET_CLOCK(DT_DRV_INST(inst))
38+
39+
#define TISCI_GET_CLOCK_DETAILS_BY_INST(DT_DRV_INST) TISCI_GET_CLOCK_DETAILS(DT_DRV_INST(inst))
40+
41+
#endif

0 commit comments

Comments
 (0)