1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2021, Bootlin 4 */ 5 6 #ifndef __DRIVERS_CLK_DT_H 7 #define __DRIVERS_CLK_DT_H 8 9 #include <kernel/dt.h> 10 #include <kernel/dt_driver.h> 11 #include <stdint.h> 12 #include <sys/queue.h> 13 14 /** 15 * CLK_DT_DECLARE - Declare a clock driver 16 * @__name: Clock driver name 17 * @__compat: Compatible string 18 * @__probe: Clock probe function 19 */ 20 #define CLK_DT_DECLARE(__name, __compat, __probe) \ 21 static const struct dt_device_match __name ## _match_table[] = { \ 22 { .compatible = __compat }, \ 23 { } \ 24 }; \ 25 const struct dt_driver __name ## _dt_driver __dt_driver = { \ 26 .name = # __name, \ 27 .type = DT_DRIVER_CLK, \ 28 .match_table = __name ## _match_table, \ 29 .probe = __probe, \ 30 } 31 32 /** 33 * clk_dt_get_by_idx - Get a clock at a specific index in "clocks" property 34 * 35 * @fdt: Device tree to work on 36 * @nodeoffset: Node offset of the subnode containing a clock property 37 * @clk_idx: Clock index to get 38 * Returns a clk struct pointer matching the clock at index clk_idx in clocks 39 * property or NULL if no clock match the given index. 40 */ 41 struct clk *clk_dt_get_by_idx(const void *fdt, int nodeoffset, 42 unsigned int clk_idx); 43 44 /** 45 * clk_dt_get_by_name - Get a clock matching a name in the "clock-names" 46 * property 47 * 48 * @fdt: Device tree to work on 49 * @nodeoffset: Node offset of the subnode containing a clock property 50 * @name: Clock name to get 51 * Returns a clk struct pointer matching the name in "clock-names" property or 52 * NULL if no clock match the given name. 53 */ 54 struct clk *clk_dt_get_by_name(const void *fdt, int nodeoffset, 55 const char *name); 56 57 /** 58 * clk_dt_get_func - Typedef of function to get clock from devicetree properties 59 * 60 * @args: Pointer to devicetree description of the clock to parse 61 * @data: Pointer to data given at clk_dt_register_clk_provider() call 62 * 63 * Returns a clk struct pointer pointing to a clock matching the devicetree 64 * description or NULL if invalid description. 65 */ 66 typedef struct clk *(*clk_dt_get_func)(struct dt_driver_phandle_args *args, 67 void *data); 68 69 /** 70 * clk_dt_register_clk_provider - Register a clock provider 71 * 72 * @fdt: Device tree to work on 73 * @nodeoffset: Node offset of the clock 74 * @get_dt_clk: Callback to match the devicetree clock with a clock struct 75 * @data: Data which will be passed to the get_dt_clk callback 76 * Returns TEE_Result value 77 */ 78 static inline 79 TEE_Result clk_dt_register_clk_provider(const void *fdt, int nodeoffset, 80 clk_dt_get_func get_dt_clk, void *data) 81 { 82 return dt_driver_register_provider(fdt, nodeoffset, 83 (get_of_device_func)get_dt_clk, 84 data, DT_DRIVER_CLK); 85 } 86 87 /** 88 * clk_dt_get_simple_clk: simple clock matching function for single clock 89 * providers 90 */ 91 static inline 92 struct clk *clk_dt_get_simple_clk(struct dt_driver_phandle_args *args __unused, 93 void *data) 94 { 95 return data; 96 } 97 98 #endif /* __DRIVERS_CLK_DT_H */ 99