xref: /rk3399_ARM-atf/drivers/ti/clk/include/ti_clk_mux.h (revision a28114d66a6d43db4accef5fd5d6dab6c059e584)
1 /*
2  * Copyright (c) 2025-2026 Texas Instruments Incorporated - https://www.ti.com
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /*
8  * TI Clock Multiplexer API Header
9  *
10  * This header defines the data structures and interfaces for clock
11  * multiplexers. It provides mux data structures, parent selection
12  * interfaces, and driver operations for selecting between multiple
13  * parent clock sources with optional per-parent dividers.
14  */
15 
16 #ifndef TI_CLK_MUX_H
17 #define TI_CLK_MUX_H
18 
19 #include <ti_clk.h>
20 
21 /*
22  * Base multiplexer clock data structure
23  *
24  * This structure contains the fundamental multiplexer configuration including
25  * the number of parent options and the parent selection table.
26  */
27 struct ti_clk_data_mux {
28 	/* Base driver data structure */
29 	struct ti_clk_drv_data data;
30 	/* Number of parent clock options */
31 	uint32_t num_parents;
32 	/* Array of parent clock descriptors */
33 	const struct ti_clk_parent *parents;
34 };
35 
36 /*
37  * Register-based multiplexer clock data structure
38  *
39  * This structure defines a multiplexer implemented via a hardware register field.
40  * The parent selection index is stored in a bit field within the specified register.
41  */
42 struct ti_clk_data_mux_reg {
43 	/* Base multiplexer data */
44 	struct ti_clk_data_mux data_mux;
45 	/* Register addr containing mux selection field */
46 	uint32_t reg;
47 	/* Starting bit position of mux selection field */
48 	uint8_t bit;
49 };
50 
51 /*
52  * Multiplexer clock driver operations structure
53  *
54  * This structure extends the base clock driver with multiplexer-specific
55  * operations for getting and setting the parent clock selection.
56  */
57 struct ti_clk_drv_mux {
58 	/* Base clock driver operations */
59 	struct ti_clk_drv drv;
60 
61 	/*
62 	 * Set the parent clock for a multiplexer
63 	 */
64 	bool (*set_parent)(struct ti_clk *clkp, uint8_t parent_idx);
65 
66 	/*
67 	 * Get the current parent clock for a multiplexer
68 	 */
69 	const struct ti_clk_parent *(*get_parent)(struct ti_clk *clkp);
70 };
71 
72 /* Multiplexer driver for read-only register-based muxes */
73 extern const struct ti_clk_drv_mux ti_clk_drv_mux_reg_ro;
74 
75 /* Multiplexer driver for read-write register-based muxes */
76 extern const struct ti_clk_drv_mux ti_clk_drv_mux_reg;
77 
78 /*
79  * Gets the current parent clock of a multiplexer
80  *
81  * Dispatches to the appropriate driver-specific get_parent function to
82  * retrieve the currently selected parent clock descriptor.
83  */
84 const struct ti_clk_parent *ti_clk_mux_get_parent(struct ti_clk *clkp);
85 
86 /**
87  * ti_clk_mux_set_parent() - Sets the parent clock for a multiplexer
88  * @clkp: The multiplexer clock to modify
89  * @new_parent: Index of the new parent to select
90  *
91  * Changes the multiplexer's parent selection to the specified parent index.
92  * This may involve writing to hardware registers and updating clock frequencies.
93  *
94  * Return: True if the parent was successfully changed
95  */
96 bool ti_clk_mux_set_parent(struct ti_clk *clkp, uint8_t new_parent);
97 
98 #endif /* TI_CLK_MUX_H */
99