Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
clock_control_emul.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2026 TOKITA Hiroshi
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
23
24#ifndef ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_CLOCK_CONTROL_EMUL_H_
25#define ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_CLOCK_CONTROL_EMUL_H_
26
29#include <zephyr/sys/util.h>
30
42
43/* Controllers whose selector is a plain clock identifier held in a single cell. */
44
54 const uint32_t *cells, size_t num_cells)
55{
56 return num_cells == 1U && cells[0] == (uint32_t)(uintptr_t)sys;
57}
58
67 uint32_t *value)
68{
69 *value = (uint32_t)(uintptr_t)rate;
70 return 0;
71}
72
80static inline clock_control_subsys_t
82 union clock_control_emul_subsys *storage)
83{
84 ARG_UNUSED(storage);
85
86 return (clock_control_subsys_t)(uintptr_t)cells[0];
87}
88
94#define CLOCK_CONTROL_SUBSYS_MATCH_1CELL(compat) \
95 \
96 static inline bool compat##_subsys_match(clock_control_subsys_t sys, \
97 const uint32_t *cells, size_t num_cells) \
98 { \
99 return clock_control_emul_1cell_subsys_match(sys, cells, num_cells); \
100 }
101
107#define CLOCK_CONTROL_RATE_TO_VALUE_1CELL(compat) \
108 \
109 static inline int compat##_rate_to_value(clock_control_subsys_rate_t rate, \
110 uint32_t *value) \
111 { \
112 return clock_control_emul_1cell_rate_to_value(rate, value); \
113 }
114
120#define CLOCK_CONTROL_SUBSYS_1CELL(compat) \
121 \
122 static inline clock_control_subsys_t compat##_cells_to_subsys( \
123 const uint32_t *cells, union clock_control_emul_subsys *storage) \
124 { \
125 return clock_control_emul_1cell_cells_to_subsys(cells, storage); \
126 }
127
133#define CLOCK_CONTROL_EMUL_DEFINE_1CELL(compat) \
134 CLOCK_CONTROL_SUBSYS_MATCH_1CELL(compat) \
135 CLOCK_CONTROL_RATE_TO_VALUE_1CELL(compat) \
136 CLOCK_CONTROL_SUBSYS_1CELL(compat)
137
138CLOCK_CONTROL_EMUL_DEFINE_1CELL(zephyr_clock_controller_emul_id)
139CLOCK_CONTROL_EMUL_DEFINE_1CELL(zephyr_clock_controller_emul_clkid)
140CLOCK_CONTROL_EMUL_DEFINE_1CELL(zephyr_clock_controller_emul_clk_id)
141
142/* Renesas R-Car CPG/MSSR: the selector is a {domain, module} descriptor. */
143
152static inline bool
154 const uint32_t *cells, size_t num_cells)
155{
156 const struct rcar_cpg_clk *clk = sys;
157
158 return clk != NULL && num_cells == 2U && cells[0] == clk->domain && cells[1] == clk->module;
159}
160
168static inline int
174
183static inline clock_control_subsys_t
185 union clock_control_emul_subsys *storage)
186{
187 storage->rcar_cpg_clk.domain = cells[0];
188 storage->rcar_cpg_clk.module = cells[1];
189
190 return &storage->rcar_cpg_clk;
191}
192
193#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_CLOCK_CONTROL_EMUL_H_ */
Main header file for clock control driver API.
static clock_control_subsys_t clock_control_emul_1cell_cells_to_subsys(const uint32_t *cells, union clock_control_emul_subsys *storage)
Convert one clock-id cell to a subsystem selector.
Definition clock_control_emul.h:81
static bool zephyr_clock_controller_emul_rcar_cpg_mssr_subsys_match(clock_control_subsys_t sys, const uint32_t *cells, size_t num_cells)
Match an R-Car CPG/MSSR selector against devicetree cells.
Definition clock_control_emul.h:153
static int clock_control_emul_1cell_rate_to_value(clock_control_subsys_rate_t rate, uint32_t *value)
Convert a subsystem rate to a one-cell value.
Definition clock_control_emul.h:66
static bool clock_control_emul_1cell_subsys_match(clock_control_subsys_t sys, const uint32_t *cells, size_t num_cells)
Match a one-cell clock selector against a subsystem.
Definition clock_control_emul.h:53
static clock_control_subsys_t zephyr_clock_controller_emul_rcar_cpg_mssr_cells_to_subsys(const uint32_t *cells, union clock_control_emul_subsys *storage)
Build an R-Car CPG/MSSR selector from devicetree cells.
Definition clock_control_emul.h:184
#define CLOCK_CONTROL_EMUL_DEFINE_1CELL(compat)
Define all hooks for a one-cell clock controller compatible.
Definition clock_control_emul.h:133
static int zephyr_clock_controller_emul_rcar_cpg_mssr_rate_to_value(clock_control_subsys_rate_t rate, uint32_t *value)
Convert an R-Car CPG/MSSR rate to a stored value.
Definition clock_control_emul.h:169
static int zephyr_clock_controller_emul_id_rate_to_value(clock_control_subsys_rate_t rate, uint32_t *value)
Convert a subsystem rate to a one-cell value.
Definition clock_control_emul.h:138
Clock control definitions for the Renesas R-Car CPG/MSSR controller.
void * clock_control_subsys_rate_t
Opaque handle identifying the rate of a clock controller subsystem.
Definition clock_control.h:73
void * clock_control_subsys_t
Opaque handle identifying a clock controller subsystem.
Definition clock_control.h:65
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
R-Car CPG/MSSR clock subsystem selector.
Definition renesas_cpg_mssr.h:29
uint32_t domain
Clock domain.
Definition renesas_cpg_mssr.h:30
uint32_t rate
Requested clock rate, in Hz.
Definition renesas_cpg_mssr.h:32
uint32_t module
Module (MSSR) identifier within the domain.
Definition renesas_cpg_mssr.h:31
Misc utilities.
Storage for the different subsystem selector representations.
Definition clock_control_emul.h:36
struct rcar_cpg_clk rcar_cpg_clk
R-Car CPG/MSSR selector containing a domain and module identifier.
Definition clock_control_emul.h:40
clock_control_subsys_t subsys
Scalar clock subsystem selector encoded as an opaque pointer.
Definition clock_control_emul.h:38