Skip to content

Commit 6bd0da6

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 <d-joseph@ti.com>
1 parent 9983ff7 commit 6bd0da6

File tree

6 files changed

+162
-0
lines changed

6 files changed

+162
-0
lines changed

drivers/clock_control/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_NRF2_GLOBAL_HSFLL clock_cont
4949
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RTS5912_SCCON clock_control_rts5912_sccon.c)
5050
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_NRF2_AUDIOPLL clock_control_nrf2_audiopll.c)
5151
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_IT51XXX clock_control_it51xxx.c)
52+
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_TISCI clock_control_tisci.c)
5253

5354
if(CONFIG_CLOCK_CONTROL_NRF2)
5455
zephyr_library_sources(clock_control_nrf2_common.c)

drivers/clock_control/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,6 @@ source "drivers/clock_control/Kconfig.wch_rcc"
114114

115115
source "drivers/clock_control/Kconfig.it51xxx"
116116

117+
source "drivers/clock_control/Kconfig.tisci"
118+
117119
endif # CLOCK_CONTROL

drivers/clock_control/Kconfig.tisci

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: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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> // for ti_sci_cmd_clk_get_freq, ti_sci_cmd_clk_set_freq, ti_sci_cmd_clk_is_on, ti_sci_cmd_clk_is_off
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+
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 = tisci_cmd_clk_get_freq(dmsc, req->dev_id, req->clk_id, &temp_rate);
25+
26+
if (ret) {
27+
LOG_ERR("Failed to get clock freq: dev_id=%u clk_id=%u err=%d", req->dev_id,
28+
req->clk_id, ret);
29+
return ret;
30+
}
31+
32+
*rate = (uint32_t)temp_rate;
33+
return 0;
34+
}
35+
36+
static int tisci_set_rate(const struct device *dev, void *sys, void *rate)
37+
{
38+
struct tisci_clock_config *req = (struct tisci_clock_config *)sys;
39+
uint64_t freq = *((uint64_t *)rate);
40+
int ret = tisci_cmd_clk_set_freq(dmsc, req->dev_id, req->clk_id, freq, freq, freq);
41+
if (ret) {
42+
LOG_ERR("Failed to set clock freq: dev_id=%u clk_id=%u freq=%llu err=%d",
43+
req->dev_id, req->clk_id, freq, ret);
44+
}
45+
return ret;
46+
}
47+
48+
static inline enum clock_control_status tisci_get_status(const struct device *dev,
49+
clock_control_subsys_t sys)
50+
{
51+
enum clock_control_status state = CLOCK_CONTROL_STATUS_UNKNOWN;
52+
struct tisci_clock_config *req = (struct tisci_clock_config *)sys;
53+
bool req_state = true;
54+
bool curr_state = true;
55+
int ret;
56+
57+
ret = tisci_cmd_clk_is_on(dmsc, req->clk_id, req->dev_id, &req_state, &curr_state);
58+
if (ret) {
59+
LOG_ERR("Failed to get clock ON status: dev_id=%u clk_id=%u err=%d", req->dev_id,
60+
req->clk_id, ret);
61+
return CLOCK_CONTROL_STATUS_UNKNOWN;
62+
}
63+
if (curr_state) {
64+
return CLOCK_CONTROL_STATUS_ON;
65+
}
66+
if (req_state && !curr_state) {
67+
return CLOCK_CONTROL_STATUS_STARTING;
68+
}
69+
curr_state = true;
70+
ret = tisci_cmd_clk_is_off(dmsc, req->clk_id, req->dev_id, NULL, &curr_state);
71+
if (ret) {
72+
LOG_ERR("Failed to get clock OFF status: dev_id=%u clk_id=%u err=%d", req->dev_id,
73+
req->clk_id, ret);
74+
return CLOCK_CONTROL_STATUS_UNKNOWN;
75+
}
76+
if (curr_state) {
77+
return CLOCK_CONTROL_STATUS_OFF;
78+
}
79+
return state;
80+
}
81+
82+
static DEVICE_API(clock_control, tisci_clock_driver_api) = {
83+
.get_rate = tisci_get_rate, .set_rate = tisci_set_rate, .get_status = tisci_get_status};
84+
85+
#define TI_K2G_SCI_CLK_INIT(_n) \
86+
DEVICE_DT_INST_DEFINE(_n, NULL, NULL, NULL, NULL, PRE_KERNEL_1, \
87+
CONFIG_CLOCK_CONTROL_INIT_PRIORITY, &tisci_clock_driver_api);
88+
89+
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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2025 Texas Instruments
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_DRIVERS_CLOCK_CONTROL_TISCI_CLOCK_CONTROL_H_
8+
#define ZEPHYR_DRIVERS_CLOCK_CONTROL_TISCI_CLOCK_CONTROL_H_
9+
10+
/**
11+
* @struct tisci_clock_config
12+
* @brief Clock configuration structure
13+
*
14+
* This structure is used to define the configuration for a clock, including
15+
* the device ID and clock ID.
16+
*
17+
* @param tisci_clock_config::dev_id
18+
* Device ID associated with the clock.
19+
*
20+
* @param tisci_clock_config::clk_id
21+
* Clock ID within the device.
22+
*/
23+
#include <stdint.h>
24+
struct tisci_clock_config {
25+
uint32_t dev_id;
26+
uint32_t clk_id;
27+
};
28+
29+
#define TISCI_GET_CLOCK(_dev) DEVICE_DT_GET(DT_PHANDLE(DT_NODELABEL(_dev), clocks))
30+
31+
#define TISCI_GET_CLOCK_DETAILS(_dev) \
32+
{.dev_id = DT_CLOCKS_CELL(DT_NODELABEL(_dev), devid), \
33+
.clk_id = DT_CLOCKS_CELL(DT_NODELABEL(_dev), clkid)}
34+
35+
#define TISCI_GET_CLOCK_BY_INST(inst) DEVICE_DT_INST_GET(inst)
36+
37+
#define TISCI_GET_CLOCK_DETAILS_BY_INST(inst) \
38+
{.dev_id = DT_INST_CLOCKS_CELL(inst, devid), .clk_id = DT_INST_CLOCKS_CELL(inst, clkid)}
39+
#endif

0 commit comments

Comments
 (0)