1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2f8ce2547SRussell King /* 3f8ce2547SRussell King * linux/include/linux/clk.h 4f8ce2547SRussell King * 5f8ce2547SRussell King * Copyright (C) 2004 ARM Limited. 6f8ce2547SRussell King * Written by Deep Blue Solutions Limited. 7b2476490SMike Turquette * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org> 8f8ce2547SRussell King */ 9686f8c5dSTodd Poynor #ifndef __LINUX_CLK_H 10686f8c5dSTodd Poynor #define __LINUX_CLK_H 11f8ce2547SRussell King 129f1612d3SShawn Guo #include <linux/err.h> 1340d3e0f4SRussell King #include <linux/kernel.h> 14b2476490SMike Turquette #include <linux/notifier.h> 1540d3e0f4SRussell King 16f8ce2547SRussell King struct device; 17f8ce2547SRussell King struct clk; 1871a2f115SKuninori Morimoto struct device_node; 1971a2f115SKuninori Morimoto struct of_phandle_args; 20f8ce2547SRussell King 21b2476490SMike Turquette /** 22b2476490SMike Turquette * DOC: clk notifier callback types 23b2476490SMike Turquette * 24b2476490SMike Turquette * PRE_RATE_CHANGE - called immediately before the clk rate is changed, 25b2476490SMike Turquette * to indicate that the rate change will proceed. Drivers must 26b2476490SMike Turquette * immediately terminate any operations that will be affected by the 27fb72a059SSoren Brinkmann * rate change. Callbacks may either return NOTIFY_DONE, NOTIFY_OK, 28fb72a059SSoren Brinkmann * NOTIFY_STOP or NOTIFY_BAD. 29b2476490SMike Turquette * 30b2476490SMike Turquette * ABORT_RATE_CHANGE: called if the rate change failed for some reason 31b2476490SMike Turquette * after PRE_RATE_CHANGE. In this case, all registered notifiers on 32b2476490SMike Turquette * the clk will be called with ABORT_RATE_CHANGE. Callbacks must 33fb72a059SSoren Brinkmann * always return NOTIFY_DONE or NOTIFY_OK. 34b2476490SMike Turquette * 35b2476490SMike Turquette * POST_RATE_CHANGE - called after the clk rate change has successfully 36fb72a059SSoren Brinkmann * completed. Callbacks must always return NOTIFY_DONE or NOTIFY_OK. 37b2476490SMike Turquette * 38b2476490SMike Turquette */ 39b2476490SMike Turquette #define PRE_RATE_CHANGE BIT(0) 40b2476490SMike Turquette #define POST_RATE_CHANGE BIT(1) 41b2476490SMike Turquette #define ABORT_RATE_CHANGE BIT(2) 42b2476490SMike Turquette 43b2476490SMike Turquette /** 44b2476490SMike Turquette * struct clk_notifier - associate a clk with a notifier 45b2476490SMike Turquette * @clk: struct clk * to associate the notifier with 46b2476490SMike Turquette * @notifier_head: a blocking_notifier_head for this clk 47b2476490SMike Turquette * @node: linked list pointers 48b2476490SMike Turquette * 49b2476490SMike Turquette * A list of struct clk_notifier is maintained by the notifier code. 50b2476490SMike Turquette * An entry is created whenever code registers the first notifier on a 51b2476490SMike Turquette * particular @clk. Future notifiers on that @clk are added to the 52b2476490SMike Turquette * @notifier_head. 53b2476490SMike Turquette */ 54b2476490SMike Turquette struct clk_notifier { 55b2476490SMike Turquette struct clk *clk; 56b2476490SMike Turquette struct srcu_notifier_head notifier_head; 57b2476490SMike Turquette struct list_head node; 58b2476490SMike Turquette }; 59b2476490SMike Turquette 60b2476490SMike Turquette /** 61b2476490SMike Turquette * struct clk_notifier_data - rate data to pass to the notifier callback 62b2476490SMike Turquette * @clk: struct clk * being changed 63b2476490SMike Turquette * @old_rate: previous rate of this clk 64b2476490SMike Turquette * @new_rate: new rate of this clk 65b2476490SMike Turquette * 66b2476490SMike Turquette * For a pre-notifier, old_rate is the clk's rate before this rate 67b2476490SMike Turquette * change, and new_rate is what the rate will be in the future. For a 68b2476490SMike Turquette * post-notifier, old_rate and new_rate are both set to the clk's 69b2476490SMike Turquette * current rate (this was done to optimize the implementation). 70b2476490SMike Turquette */ 71b2476490SMike Turquette struct clk_notifier_data { 72b2476490SMike Turquette struct clk *clk; 73b2476490SMike Turquette unsigned long old_rate; 74b2476490SMike Turquette unsigned long new_rate; 75b2476490SMike Turquette }; 76b2476490SMike Turquette 77266e4e9dSDong Aisheng /** 78266e4e9dSDong Aisheng * struct clk_bulk_data - Data used for bulk clk operations. 79266e4e9dSDong Aisheng * 80266e4e9dSDong Aisheng * @id: clock consumer ID 81266e4e9dSDong Aisheng * @clk: struct clk * to store the associated clock 82266e4e9dSDong Aisheng * 83266e4e9dSDong Aisheng * The CLK APIs provide a series of clk_bulk_() API calls as 84266e4e9dSDong Aisheng * a convenience to consumers which require multiple clks. This 85266e4e9dSDong Aisheng * structure is used to manage data for these calls. 86266e4e9dSDong Aisheng */ 87266e4e9dSDong Aisheng struct clk_bulk_data { 88266e4e9dSDong Aisheng const char *id; 89266e4e9dSDong Aisheng struct clk *clk; 90266e4e9dSDong Aisheng }; 91266e4e9dSDong Aisheng 92e81b87d2SKrzysztof Kozlowski #ifdef CONFIG_COMMON_CLK 93e81b87d2SKrzysztof Kozlowski 9486bcfa2eSMike Turquette /** 95b90f3726SRandy Dunlap * clk_notifier_register - register a clock rate-change notifier callback 9686bcfa2eSMike Turquette * @clk: clock whose rate we are interested in 9786bcfa2eSMike Turquette * @nb: notifier block with callback function pointer 9886bcfa2eSMike Turquette * 9986bcfa2eSMike Turquette * ProTip: debugging across notifier chains can be frustrating. Make sure that 10086bcfa2eSMike Turquette * your notifier callback function prints a nice big warning in case of 10186bcfa2eSMike Turquette * failure. 10286bcfa2eSMike Turquette */ 103b2476490SMike Turquette int clk_notifier_register(struct clk *clk, struct notifier_block *nb); 104b2476490SMike Turquette 10586bcfa2eSMike Turquette /** 106b90f3726SRandy Dunlap * clk_notifier_unregister - unregister a clock rate-change notifier callback 10786bcfa2eSMike Turquette * @clk: clock whose rate we are no longer interested in 10886bcfa2eSMike Turquette * @nb: notifier block which will be unregistered 10986bcfa2eSMike Turquette */ 110b2476490SMike Turquette int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb); 111b2476490SMike Turquette 1125279fc40SBoris BREZILLON /** 1136d30d50dSJerome Brunet * devm_clk_notifier_register - register a managed rate-change notifier callback 1146d30d50dSJerome Brunet * @dev: device for clock "consumer" 1156d30d50dSJerome Brunet * @clk: clock whose rate we are interested in 1166d30d50dSJerome Brunet * @nb: notifier block with callback function pointer 1176d30d50dSJerome Brunet * 1186d30d50dSJerome Brunet * Returns 0 on success, -EERROR otherwise 1196d30d50dSJerome Brunet */ 120e6fb7aeeSJerome Brunet int devm_clk_notifier_register(struct device *dev, struct clk *clk, 121e6fb7aeeSJerome Brunet struct notifier_block *nb); 1226d30d50dSJerome Brunet 1236d30d50dSJerome Brunet /** 1245279fc40SBoris BREZILLON * clk_get_accuracy - obtain the clock accuracy in ppb (parts per billion) 1255279fc40SBoris BREZILLON * for a clock source. 1265279fc40SBoris BREZILLON * @clk: clock source 1275279fc40SBoris BREZILLON * 1285279fc40SBoris BREZILLON * This gets the clock source accuracy expressed in ppb. 1295279fc40SBoris BREZILLON * A perfect clock returns 0. 1305279fc40SBoris BREZILLON */ 1315279fc40SBoris BREZILLON long clk_get_accuracy(struct clk *clk); 1325279fc40SBoris BREZILLON 133e59c5371SMike Turquette /** 134e59c5371SMike Turquette * clk_set_phase - adjust the phase shift of a clock signal 135e59c5371SMike Turquette * @clk: clock signal source 136e59c5371SMike Turquette * @degrees: number of degrees the signal is shifted 137e59c5371SMike Turquette * 138e59c5371SMike Turquette * Shifts the phase of a clock signal by the specified degrees. Returns 0 on 139e59c5371SMike Turquette * success, -EERROR otherwise. 140e59c5371SMike Turquette */ 141e59c5371SMike Turquette int clk_set_phase(struct clk *clk, int degrees); 142e59c5371SMike Turquette 143e59c5371SMike Turquette /** 144e59c5371SMike Turquette * clk_get_phase - return the phase shift of a clock signal 145e59c5371SMike Turquette * @clk: clock signal source 146e59c5371SMike Turquette * 147e59c5371SMike Turquette * Returns the phase shift of a clock node in degrees, otherwise returns 148e59c5371SMike Turquette * -EERROR. 149e59c5371SMike Turquette */ 150e59c5371SMike Turquette int clk_get_phase(struct clk *clk); 151e59c5371SMike Turquette 1523d3801efSMichael Turquette /** 1539fba738aSJerome Brunet * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal 1549fba738aSJerome Brunet * @clk: clock signal source 1559fba738aSJerome Brunet * @num: numerator of the duty cycle ratio to be applied 1569fba738aSJerome Brunet * @den: denominator of the duty cycle ratio to be applied 1579fba738aSJerome Brunet * 1589fba738aSJerome Brunet * Adjust the duty cycle of a clock signal by the specified ratio. Returns 0 on 1599fba738aSJerome Brunet * success, -EERROR otherwise. 1609fba738aSJerome Brunet */ 1619fba738aSJerome Brunet int clk_set_duty_cycle(struct clk *clk, unsigned int num, unsigned int den); 1629fba738aSJerome Brunet 1639fba738aSJerome Brunet /** 1649d1c94a6SMauro Carvalho Chehab * clk_get_scaled_duty_cycle - return the duty cycle ratio of a clock signal 1659fba738aSJerome Brunet * @clk: clock signal source 1669fba738aSJerome Brunet * @scale: scaling factor to be applied to represent the ratio as an integer 1679fba738aSJerome Brunet * 1689fba738aSJerome Brunet * Returns the duty cycle ratio multiplied by the scale provided, otherwise 1699fba738aSJerome Brunet * returns -EERROR. 1709fba738aSJerome Brunet */ 1719fba738aSJerome Brunet int clk_get_scaled_duty_cycle(struct clk *clk, unsigned int scale); 1729fba738aSJerome Brunet 1739fba738aSJerome Brunet /** 1743d3801efSMichael Turquette * clk_is_match - check if two clk's point to the same hardware clock 1753d3801efSMichael Turquette * @p: clk compared against q 1763d3801efSMichael Turquette * @q: clk compared against p 1773d3801efSMichael Turquette * 1783d3801efSMichael Turquette * Returns true if the two struct clk pointers both point to the same hardware 1790e056eb5Smchehab@s-opensource.com * clock node. Put differently, returns true if @p and @q 1800e056eb5Smchehab@s-opensource.com * share the same &struct clk_core object. 1813d3801efSMichael Turquette * 1823d3801efSMichael Turquette * Returns false otherwise. Note that two NULL clks are treated as matching. 1833d3801efSMichael Turquette */ 1843d3801efSMichael Turquette bool clk_is_match(const struct clk *p, const struct clk *q); 1853d3801efSMichael Turquette 1865279fc40SBoris BREZILLON #else 1875279fc40SBoris BREZILLON 188e81b87d2SKrzysztof Kozlowski static inline int clk_notifier_register(struct clk *clk, 189e81b87d2SKrzysztof Kozlowski struct notifier_block *nb) 190e81b87d2SKrzysztof Kozlowski { 191e81b87d2SKrzysztof Kozlowski return -ENOTSUPP; 192e81b87d2SKrzysztof Kozlowski } 193e81b87d2SKrzysztof Kozlowski 194e81b87d2SKrzysztof Kozlowski static inline int clk_notifier_unregister(struct clk *clk, 195e81b87d2SKrzysztof Kozlowski struct notifier_block *nb) 196e81b87d2SKrzysztof Kozlowski { 197e81b87d2SKrzysztof Kozlowski return -ENOTSUPP; 198e81b87d2SKrzysztof Kozlowski } 199e81b87d2SKrzysztof Kozlowski 200e6fb7aeeSJerome Brunet static inline int devm_clk_notifier_register(struct device *dev, 201e6fb7aeeSJerome Brunet struct clk *clk, 202e6fb7aeeSJerome Brunet struct notifier_block *nb) 203e6fb7aeeSJerome Brunet { 204e6fb7aeeSJerome Brunet return -ENOTSUPP; 205e6fb7aeeSJerome Brunet } 206e6fb7aeeSJerome Brunet 2075279fc40SBoris BREZILLON static inline long clk_get_accuracy(struct clk *clk) 2085279fc40SBoris BREZILLON { 2095279fc40SBoris BREZILLON return -ENOTSUPP; 2105279fc40SBoris BREZILLON } 2115279fc40SBoris BREZILLON 212e59c5371SMike Turquette static inline long clk_set_phase(struct clk *clk, int phase) 213e59c5371SMike Turquette { 214e59c5371SMike Turquette return -ENOTSUPP; 215e59c5371SMike Turquette } 216e59c5371SMike Turquette 217e59c5371SMike Turquette static inline long clk_get_phase(struct clk *clk) 218e59c5371SMike Turquette { 219e59c5371SMike Turquette return -ENOTSUPP; 220e59c5371SMike Turquette } 221e59c5371SMike Turquette 2229fba738aSJerome Brunet static inline int clk_set_duty_cycle(struct clk *clk, unsigned int num, 2239fba738aSJerome Brunet unsigned int den) 2249fba738aSJerome Brunet { 2259fba738aSJerome Brunet return -ENOTSUPP; 2269fba738aSJerome Brunet } 2279fba738aSJerome Brunet 2289fba738aSJerome Brunet static inline unsigned int clk_get_scaled_duty_cycle(struct clk *clk, 2299fba738aSJerome Brunet unsigned int scale) 2309fba738aSJerome Brunet { 2319fba738aSJerome Brunet return 0; 2329fba738aSJerome Brunet } 2339fba738aSJerome Brunet 2343d3801efSMichael Turquette static inline bool clk_is_match(const struct clk *p, const struct clk *q) 2353d3801efSMichael Turquette { 2363d3801efSMichael Turquette return p == q; 2373d3801efSMichael Turquette } 2383d3801efSMichael Turquette 2397e87aed9SMark Brown #endif 240b2476490SMike Turquette 2410bfa0820SNicolas Pitre #ifdef CONFIG_HAVE_CLK_PREPARE 242f8ce2547SRussell King /** 24393abe8e4SViresh Kumar * clk_prepare - prepare a clock source 24493abe8e4SViresh Kumar * @clk: clock source 24593abe8e4SViresh Kumar * 24693abe8e4SViresh Kumar * This prepares the clock source for use. 24793abe8e4SViresh Kumar * 24893abe8e4SViresh Kumar * Must not be called from within atomic context. 24993abe8e4SViresh Kumar */ 25093abe8e4SViresh Kumar int clk_prepare(struct clk *clk); 251266e4e9dSDong Aisheng int __must_check clk_bulk_prepare(int num_clks, 252266e4e9dSDong Aisheng const struct clk_bulk_data *clks); 2530bfa0820SNicolas Pitre 2540bfa0820SNicolas Pitre /** 2550bfa0820SNicolas Pitre * clk_is_enabled_when_prepared - indicate if preparing a clock also enables it. 2560bfa0820SNicolas Pitre * @clk: clock source 2570bfa0820SNicolas Pitre * 2580bfa0820SNicolas Pitre * Returns true if clk_prepare() implicitly enables the clock, effectively 2590bfa0820SNicolas Pitre * making clk_enable()/clk_disable() no-ops, false otherwise. 2600bfa0820SNicolas Pitre * 2610bfa0820SNicolas Pitre * This is of interest mainly to the power management code where actually 2620bfa0820SNicolas Pitre * disabling the clock also requires unpreparing it to have any material 2630bfa0820SNicolas Pitre * effect. 2640bfa0820SNicolas Pitre * 2650bfa0820SNicolas Pitre * Regardless of the value returned here, the caller must always invoke 2660bfa0820SNicolas Pitre * clk_enable() or clk_prepare_enable() and counterparts for usage counts 2670bfa0820SNicolas Pitre * to be right. 2680bfa0820SNicolas Pitre */ 2690bfa0820SNicolas Pitre bool clk_is_enabled_when_prepared(struct clk *clk); 27093abe8e4SViresh Kumar #else 27193abe8e4SViresh Kumar static inline int clk_prepare(struct clk *clk) 27293abe8e4SViresh Kumar { 27393abe8e4SViresh Kumar might_sleep(); 27493abe8e4SViresh Kumar return 0; 27593abe8e4SViresh Kumar } 276266e4e9dSDong Aisheng 277570aaec7SAndrey Smirnov static inline int __must_check 278570aaec7SAndrey Smirnov clk_bulk_prepare(int num_clks, const struct clk_bulk_data *clks) 279266e4e9dSDong Aisheng { 280266e4e9dSDong Aisheng might_sleep(); 281266e4e9dSDong Aisheng return 0; 282266e4e9dSDong Aisheng } 2830bfa0820SNicolas Pitre 2840bfa0820SNicolas Pitre static inline bool clk_is_enabled_when_prepared(struct clk *clk) 2850bfa0820SNicolas Pitre { 2860bfa0820SNicolas Pitre return false; 2870bfa0820SNicolas Pitre } 28893abe8e4SViresh Kumar #endif 28993abe8e4SViresh Kumar 29093abe8e4SViresh Kumar /** 29193abe8e4SViresh Kumar * clk_unprepare - undo preparation of a clock source 29293abe8e4SViresh Kumar * @clk: clock source 29393abe8e4SViresh Kumar * 29493abe8e4SViresh Kumar * This undoes a previously prepared clock. The caller must balance 29593abe8e4SViresh Kumar * the number of prepare and unprepare calls. 29693abe8e4SViresh Kumar * 29793abe8e4SViresh Kumar * Must not be called from within atomic context. 29893abe8e4SViresh Kumar */ 29993abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE 30093abe8e4SViresh Kumar void clk_unprepare(struct clk *clk); 301266e4e9dSDong Aisheng void clk_bulk_unprepare(int num_clks, const struct clk_bulk_data *clks); 30293abe8e4SViresh Kumar #else 30393abe8e4SViresh Kumar static inline void clk_unprepare(struct clk *clk) 30493abe8e4SViresh Kumar { 30593abe8e4SViresh Kumar might_sleep(); 30693abe8e4SViresh Kumar } 307570aaec7SAndrey Smirnov static inline void clk_bulk_unprepare(int num_clks, 308570aaec7SAndrey Smirnov const struct clk_bulk_data *clks) 309266e4e9dSDong Aisheng { 310266e4e9dSDong Aisheng might_sleep(); 311266e4e9dSDong Aisheng } 31293abe8e4SViresh Kumar #endif 31393abe8e4SViresh Kumar 31493abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK 31593abe8e4SViresh Kumar /** 316f8ce2547SRussell King * clk_get - lookup and obtain a reference to a clock producer. 317f8ce2547SRussell King * @dev: device for clock "consumer" 318a58b3a4aSJan-Simon Möller * @id: clock consumer ID 319f8ce2547SRussell King * 320f8ce2547SRussell King * Returns a struct clk corresponding to the clock producer, or 321f8ce2547SRussell King * valid IS_ERR() condition containing errno. The implementation 322f8ce2547SRussell King * uses @dev and @id to determine the clock consumer, and thereby 323f8ce2547SRussell King * the clock producer. (IOW, @id may be identical strings, but 324f8ce2547SRussell King * clk_get may return different clock producers depending on @dev.) 325f8ce2547SRussell King * 326f8ce2547SRussell King * Drivers must assume that the clock source is not enabled. 327f7ad160bSAlex Raimondi * 328f7ad160bSAlex Raimondi * clk_get should not be called from within interrupt context. 329f8ce2547SRussell King */ 330f8ce2547SRussell King struct clk *clk_get(struct device *dev, const char *id); 331f8ce2547SRussell King 332f8ce2547SRussell King /** 333266e4e9dSDong Aisheng * clk_bulk_get - lookup and obtain a number of references to clock producer. 334266e4e9dSDong Aisheng * @dev: device for clock "consumer" 335266e4e9dSDong Aisheng * @num_clks: the number of clk_bulk_data 336266e4e9dSDong Aisheng * @clks: the clk_bulk_data table of consumer 337266e4e9dSDong Aisheng * 338266e4e9dSDong Aisheng * This helper function allows drivers to get several clk consumers in one 339266e4e9dSDong Aisheng * operation. If any of the clk cannot be acquired then any clks 340266e4e9dSDong Aisheng * that were obtained will be freed before returning to the caller. 341266e4e9dSDong Aisheng * 342266e4e9dSDong Aisheng * Returns 0 if all clocks specified in clk_bulk_data table are obtained 343266e4e9dSDong Aisheng * successfully, or valid IS_ERR() condition containing errno. 344266e4e9dSDong Aisheng * The implementation uses @dev and @clk_bulk_data.id to determine the 345266e4e9dSDong Aisheng * clock consumer, and thereby the clock producer. 346266e4e9dSDong Aisheng * The clock returned is stored in each @clk_bulk_data.clk field. 347266e4e9dSDong Aisheng * 348266e4e9dSDong Aisheng * Drivers must assume that the clock source is not enabled. 349266e4e9dSDong Aisheng * 350266e4e9dSDong Aisheng * clk_bulk_get should not be called from within interrupt context. 351266e4e9dSDong Aisheng */ 352266e4e9dSDong Aisheng int __must_check clk_bulk_get(struct device *dev, int num_clks, 353266e4e9dSDong Aisheng struct clk_bulk_data *clks); 354616e45dfSDong Aisheng /** 355616e45dfSDong Aisheng * clk_bulk_get_all - lookup and obtain all available references to clock 356616e45dfSDong Aisheng * producer. 357616e45dfSDong Aisheng * @dev: device for clock "consumer" 358616e45dfSDong Aisheng * @clks: pointer to the clk_bulk_data table of consumer 359616e45dfSDong Aisheng * 360616e45dfSDong Aisheng * This helper function allows drivers to get all clk consumers in one 361616e45dfSDong Aisheng * operation. If any of the clk cannot be acquired then any clks 362616e45dfSDong Aisheng * that were obtained will be freed before returning to the caller. 363616e45dfSDong Aisheng * 364616e45dfSDong Aisheng * Returns a positive value for the number of clocks obtained while the 365616e45dfSDong Aisheng * clock references are stored in the clk_bulk_data table in @clks field. 366616e45dfSDong Aisheng * Returns 0 if there're none and a negative value if something failed. 367616e45dfSDong Aisheng * 368616e45dfSDong Aisheng * Drivers must assume that the clock source is not enabled. 369616e45dfSDong Aisheng * 370616e45dfSDong Aisheng * clk_bulk_get should not be called from within interrupt context. 371616e45dfSDong Aisheng */ 372616e45dfSDong Aisheng int __must_check clk_bulk_get_all(struct device *dev, 373616e45dfSDong Aisheng struct clk_bulk_data **clks); 3742f25528eSSylwester Nawrocki 3752f25528eSSylwester Nawrocki /** 3762f25528eSSylwester Nawrocki * clk_bulk_get_optional - lookup and obtain a number of references to clock producer 3772f25528eSSylwester Nawrocki * @dev: device for clock "consumer" 3782f25528eSSylwester Nawrocki * @num_clks: the number of clk_bulk_data 3792f25528eSSylwester Nawrocki * @clks: the clk_bulk_data table of consumer 3802f25528eSSylwester Nawrocki * 3812f25528eSSylwester Nawrocki * Behaves the same as clk_bulk_get() except where there is no clock producer. 3822f25528eSSylwester Nawrocki * In this case, instead of returning -ENOENT, the function returns 0 and 3832f25528eSSylwester Nawrocki * NULL for a clk for which a clock producer could not be determined. 3842f25528eSSylwester Nawrocki */ 3852f25528eSSylwester Nawrocki int __must_check clk_bulk_get_optional(struct device *dev, int num_clks, 3862f25528eSSylwester Nawrocki struct clk_bulk_data *clks); 387266e4e9dSDong Aisheng /** 388618aee02SDong Aisheng * devm_clk_bulk_get - managed get multiple clk consumers 389618aee02SDong Aisheng * @dev: device for clock "consumer" 390618aee02SDong Aisheng * @num_clks: the number of clk_bulk_data 391618aee02SDong Aisheng * @clks: the clk_bulk_data table of consumer 392618aee02SDong Aisheng * 393618aee02SDong Aisheng * Return 0 on success, an errno on failure. 394618aee02SDong Aisheng * 395618aee02SDong Aisheng * This helper function allows drivers to get several clk 396618aee02SDong Aisheng * consumers in one operation with management, the clks will 397618aee02SDong Aisheng * automatically be freed when the device is unbound. 398618aee02SDong Aisheng */ 399618aee02SDong Aisheng int __must_check devm_clk_bulk_get(struct device *dev, int num_clks, 400618aee02SDong Aisheng struct clk_bulk_data *clks); 401f08c2e28SDong Aisheng /** 4029bd5ef0bSSylwester Nawrocki * devm_clk_bulk_get_optional - managed get multiple optional consumer clocks 4039bd5ef0bSSylwester Nawrocki * @dev: device for clock "consumer" 4046ee82ef0SSylwester Nawrocki * @num_clks: the number of clk_bulk_data 4059bd5ef0bSSylwester Nawrocki * @clks: pointer to the clk_bulk_data table of consumer 4069bd5ef0bSSylwester Nawrocki * 4079bd5ef0bSSylwester Nawrocki * Behaves the same as devm_clk_bulk_get() except where there is no clock 4089bd5ef0bSSylwester Nawrocki * producer. In this case, instead of returning -ENOENT, the function returns 4099bd5ef0bSSylwester Nawrocki * NULL for given clk. It is assumed all clocks in clk_bulk_data are optional. 4109bd5ef0bSSylwester Nawrocki * 4119bd5ef0bSSylwester Nawrocki * Returns 0 if all clocks specified in clk_bulk_data table are obtained 4129bd5ef0bSSylwester Nawrocki * successfully or for any clk there was no clk provider available, otherwise 4139bd5ef0bSSylwester Nawrocki * returns valid IS_ERR() condition containing errno. 4149bd5ef0bSSylwester Nawrocki * The implementation uses @dev and @clk_bulk_data.id to determine the 4159bd5ef0bSSylwester Nawrocki * clock consumer, and thereby the clock producer. 4169bd5ef0bSSylwester Nawrocki * The clock returned is stored in each @clk_bulk_data.clk field. 4179bd5ef0bSSylwester Nawrocki * 4189bd5ef0bSSylwester Nawrocki * Drivers must assume that the clock source is not enabled. 4199bd5ef0bSSylwester Nawrocki * 4209bd5ef0bSSylwester Nawrocki * clk_bulk_get should not be called from within interrupt context. 4219bd5ef0bSSylwester Nawrocki */ 4229bd5ef0bSSylwester Nawrocki int __must_check devm_clk_bulk_get_optional(struct device *dev, int num_clks, 4239bd5ef0bSSylwester Nawrocki struct clk_bulk_data *clks); 4249bd5ef0bSSylwester Nawrocki /** 425f08c2e28SDong Aisheng * devm_clk_bulk_get_all - managed get multiple clk consumers 426f08c2e28SDong Aisheng * @dev: device for clock "consumer" 427f08c2e28SDong Aisheng * @clks: pointer to the clk_bulk_data table of consumer 428f08c2e28SDong Aisheng * 429f08c2e28SDong Aisheng * Returns a positive value for the number of clocks obtained while the 430f08c2e28SDong Aisheng * clock references are stored in the clk_bulk_data table in @clks field. 431f08c2e28SDong Aisheng * Returns 0 if there're none and a negative value if something failed. 432f08c2e28SDong Aisheng * 433f08c2e28SDong Aisheng * This helper function allows drivers to get several clk 434f08c2e28SDong Aisheng * consumers in one operation with management, the clks will 435f08c2e28SDong Aisheng * automatically be freed when the device is unbound. 436f08c2e28SDong Aisheng */ 437f08c2e28SDong Aisheng 438f08c2e28SDong Aisheng int __must_check devm_clk_bulk_get_all(struct device *dev, 439f08c2e28SDong Aisheng struct clk_bulk_data **clks); 440618aee02SDong Aisheng 441618aee02SDong Aisheng /** 442a8a97db9SMark Brown * devm_clk_get - lookup and obtain a managed reference to a clock producer. 443a8a97db9SMark Brown * @dev: device for clock "consumer" 444a58b3a4aSJan-Simon Möller * @id: clock consumer ID 445a8a97db9SMark Brown * 446af89cd45SUwe Kleine-König * Context: May sleep. 447af89cd45SUwe Kleine-König * 448af89cd45SUwe Kleine-König * Return: a struct clk corresponding to the clock producer, or 449a8a97db9SMark Brown * valid IS_ERR() condition containing errno. The implementation 450a8a97db9SMark Brown * uses @dev and @id to determine the clock consumer, and thereby 451a8a97db9SMark Brown * the clock producer. (IOW, @id may be identical strings, but 452a8a97db9SMark Brown * clk_get may return different clock producers depending on @dev.) 453a8a97db9SMark Brown * 454af89cd45SUwe Kleine-König * Drivers must assume that the clock source is neither prepared nor 455af89cd45SUwe Kleine-König * enabled. 456a8a97db9SMark Brown * 457a8a97db9SMark Brown * The clock will automatically be freed when the device is unbound 458a8a97db9SMark Brown * from the bus. 459a8a97db9SMark Brown */ 460a8a97db9SMark Brown struct clk *devm_clk_get(struct device *dev, const char *id); 461a8a97db9SMark Brown 462a8a97db9SMark Brown /** 463*7ef9651eSUwe Kleine-König * devm_clk_get_prepared - devm_clk_get() + clk_prepare() 464*7ef9651eSUwe Kleine-König * @dev: device for clock "consumer" 465*7ef9651eSUwe Kleine-König * @id: clock consumer ID 466*7ef9651eSUwe Kleine-König * 467*7ef9651eSUwe Kleine-König * Context: May sleep. 468*7ef9651eSUwe Kleine-König * 469*7ef9651eSUwe Kleine-König * Return: a struct clk corresponding to the clock producer, or 470*7ef9651eSUwe Kleine-König * valid IS_ERR() condition containing errno. The implementation 471*7ef9651eSUwe Kleine-König * uses @dev and @id to determine the clock consumer, and thereby 472*7ef9651eSUwe Kleine-König * the clock producer. (IOW, @id may be identical strings, but 473*7ef9651eSUwe Kleine-König * clk_get may return different clock producers depending on @dev.) 474*7ef9651eSUwe Kleine-König * 475*7ef9651eSUwe Kleine-König * The returned clk (if valid) is prepared. Drivers must however assume 476*7ef9651eSUwe Kleine-König * that the clock is not enabled. 477*7ef9651eSUwe Kleine-König * 478*7ef9651eSUwe Kleine-König * The clock will automatically be unprepared and freed when the device 479*7ef9651eSUwe Kleine-König * is unbound from the bus. 480*7ef9651eSUwe Kleine-König */ 481*7ef9651eSUwe Kleine-König struct clk *devm_clk_get_prepared(struct device *dev, const char *id); 482*7ef9651eSUwe Kleine-König 483*7ef9651eSUwe Kleine-König /** 484*7ef9651eSUwe Kleine-König * devm_clk_get_enabled - devm_clk_get() + clk_prepare_enable() 485*7ef9651eSUwe Kleine-König * @dev: device for clock "consumer" 486*7ef9651eSUwe Kleine-König * @id: clock consumer ID 487*7ef9651eSUwe Kleine-König * 488*7ef9651eSUwe Kleine-König * Context: May sleep. 489*7ef9651eSUwe Kleine-König * 490*7ef9651eSUwe Kleine-König * Return: a struct clk corresponding to the clock producer, or 491*7ef9651eSUwe Kleine-König * valid IS_ERR() condition containing errno. The implementation 492*7ef9651eSUwe Kleine-König * uses @dev and @id to determine the clock consumer, and thereby 493*7ef9651eSUwe Kleine-König * the clock producer. (IOW, @id may be identical strings, but 494*7ef9651eSUwe Kleine-König * clk_get may return different clock producers depending on @dev.) 495*7ef9651eSUwe Kleine-König * 496*7ef9651eSUwe Kleine-König * The returned clk (if valid) is prepared and enabled. 497*7ef9651eSUwe Kleine-König * 498*7ef9651eSUwe Kleine-König * The clock will automatically be disabled, unprepared and freed 499*7ef9651eSUwe Kleine-König * when the device is unbound from the bus. 500*7ef9651eSUwe Kleine-König */ 501*7ef9651eSUwe Kleine-König struct clk *devm_clk_get_enabled(struct device *dev, const char *id); 502*7ef9651eSUwe Kleine-König 503*7ef9651eSUwe Kleine-König /** 50460b8f0ddSPhil Edworthy * devm_clk_get_optional - lookup and obtain a managed reference to an optional 50560b8f0ddSPhil Edworthy * clock producer. 50660b8f0ddSPhil Edworthy * @dev: device for clock "consumer" 50760b8f0ddSPhil Edworthy * @id: clock consumer ID 50860b8f0ddSPhil Edworthy * 509af89cd45SUwe Kleine-König * Context: May sleep. 510af89cd45SUwe Kleine-König * 511af89cd45SUwe Kleine-König * Return: a struct clk corresponding to the clock producer, or 512af89cd45SUwe Kleine-König * valid IS_ERR() condition containing errno. The implementation 513af89cd45SUwe Kleine-König * uses @dev and @id to determine the clock consumer, and thereby 514af89cd45SUwe Kleine-König * the clock producer. If no such clk is found, it returns NULL 515af89cd45SUwe Kleine-König * which serves as a dummy clk. That's the only difference compared 516af89cd45SUwe Kleine-König * to devm_clk_get(). 517af89cd45SUwe Kleine-König * 518af89cd45SUwe Kleine-König * Drivers must assume that the clock source is neither prepared nor 519af89cd45SUwe Kleine-König * enabled. 520af89cd45SUwe Kleine-König * 521af89cd45SUwe Kleine-König * The clock will automatically be freed when the device is unbound 522af89cd45SUwe Kleine-König * from the bus. 52360b8f0ddSPhil Edworthy */ 52460b8f0ddSPhil Edworthy struct clk *devm_clk_get_optional(struct device *dev, const char *id); 52560b8f0ddSPhil Edworthy 52660b8f0ddSPhil Edworthy /** 527*7ef9651eSUwe Kleine-König * devm_clk_get_optional_prepared - devm_clk_get_optional() + clk_prepare() 528*7ef9651eSUwe Kleine-König * @dev: device for clock "consumer" 529*7ef9651eSUwe Kleine-König * @id: clock consumer ID 530*7ef9651eSUwe Kleine-König * 531*7ef9651eSUwe Kleine-König * Context: May sleep. 532*7ef9651eSUwe Kleine-König * 533*7ef9651eSUwe Kleine-König * Return: a struct clk corresponding to the clock producer, or 534*7ef9651eSUwe Kleine-König * valid IS_ERR() condition containing errno. The implementation 535*7ef9651eSUwe Kleine-König * uses @dev and @id to determine the clock consumer, and thereby 536*7ef9651eSUwe Kleine-König * the clock producer. If no such clk is found, it returns NULL 537*7ef9651eSUwe Kleine-König * which serves as a dummy clk. That's the only difference compared 538*7ef9651eSUwe Kleine-König * to devm_clk_get_prepared(). 539*7ef9651eSUwe Kleine-König * 540*7ef9651eSUwe Kleine-König * The returned clk (if valid) is prepared. Drivers must however 541*7ef9651eSUwe Kleine-König * assume that the clock is not enabled. 542*7ef9651eSUwe Kleine-König * 543*7ef9651eSUwe Kleine-König * The clock will automatically be unprepared and freed when the 544*7ef9651eSUwe Kleine-König * device is unbound from the bus. 545*7ef9651eSUwe Kleine-König */ 546*7ef9651eSUwe Kleine-König struct clk *devm_clk_get_optional_prepared(struct device *dev, const char *id); 547*7ef9651eSUwe Kleine-König 548*7ef9651eSUwe Kleine-König /** 549*7ef9651eSUwe Kleine-König * devm_clk_get_optional_enabled - devm_clk_get_optional() + 550*7ef9651eSUwe Kleine-König * clk_prepare_enable() 551*7ef9651eSUwe Kleine-König * @dev: device for clock "consumer" 552*7ef9651eSUwe Kleine-König * @id: clock consumer ID 553*7ef9651eSUwe Kleine-König * 554*7ef9651eSUwe Kleine-König * Context: May sleep. 555*7ef9651eSUwe Kleine-König * 556*7ef9651eSUwe Kleine-König * Return: a struct clk corresponding to the clock producer, or 557*7ef9651eSUwe Kleine-König * valid IS_ERR() condition containing errno. The implementation 558*7ef9651eSUwe Kleine-König * uses @dev and @id to determine the clock consumer, and thereby 559*7ef9651eSUwe Kleine-König * the clock producer. If no such clk is found, it returns NULL 560*7ef9651eSUwe Kleine-König * which serves as a dummy clk. That's the only difference compared 561*7ef9651eSUwe Kleine-König * to devm_clk_get_enabled(). 562*7ef9651eSUwe Kleine-König * 563*7ef9651eSUwe Kleine-König * The returned clk (if valid) is prepared and enabled. 564*7ef9651eSUwe Kleine-König * 565*7ef9651eSUwe Kleine-König * The clock will automatically be disabled, unprepared and freed 566*7ef9651eSUwe Kleine-König * when the device is unbound from the bus. 567*7ef9651eSUwe Kleine-König */ 568*7ef9651eSUwe Kleine-König struct clk *devm_clk_get_optional_enabled(struct device *dev, const char *id); 569*7ef9651eSUwe Kleine-König 570*7ef9651eSUwe Kleine-König /** 57171a2f115SKuninori Morimoto * devm_get_clk_from_child - lookup and obtain a managed reference to a 57271a2f115SKuninori Morimoto * clock producer from child node. 57371a2f115SKuninori Morimoto * @dev: device for clock "consumer" 57471a2f115SKuninori Morimoto * @np: pointer to clock consumer node 57571a2f115SKuninori Morimoto * @con_id: clock consumer ID 57671a2f115SKuninori Morimoto * 57771a2f115SKuninori Morimoto * This function parses the clocks, and uses them to look up the 57871a2f115SKuninori Morimoto * struct clk from the registered list of clock providers by using 57971a2f115SKuninori Morimoto * @np and @con_id 58071a2f115SKuninori Morimoto * 58171a2f115SKuninori Morimoto * The clock will automatically be freed when the device is unbound 58271a2f115SKuninori Morimoto * from the bus. 58371a2f115SKuninori Morimoto */ 58471a2f115SKuninori Morimoto struct clk *devm_get_clk_from_child(struct device *dev, 58571a2f115SKuninori Morimoto struct device_node *np, const char *con_id); 58655e9b8b7SJerome Brunet /** 58755e9b8b7SJerome Brunet * clk_rate_exclusive_get - get exclusivity over the rate control of a 58855e9b8b7SJerome Brunet * producer 58955e9b8b7SJerome Brunet * @clk: clock source 59055e9b8b7SJerome Brunet * 59155e9b8b7SJerome Brunet * This function allows drivers to get exclusive control over the rate of a 59255e9b8b7SJerome Brunet * provider. It prevents any other consumer to execute, even indirectly, 59355e9b8b7SJerome Brunet * opereation which could alter the rate of the provider or cause glitches 59455e9b8b7SJerome Brunet * 59555e9b8b7SJerome Brunet * If exlusivity is claimed more than once on clock, even by the same driver, 59655e9b8b7SJerome Brunet * the rate effectively gets locked as exclusivity can't be preempted. 59755e9b8b7SJerome Brunet * 59855e9b8b7SJerome Brunet * Must not be called from within atomic context. 59955e9b8b7SJerome Brunet * 60055e9b8b7SJerome Brunet * Returns success (0) or negative errno. 60155e9b8b7SJerome Brunet */ 60255e9b8b7SJerome Brunet int clk_rate_exclusive_get(struct clk *clk); 60355e9b8b7SJerome Brunet 60455e9b8b7SJerome Brunet /** 60555e9b8b7SJerome Brunet * clk_rate_exclusive_put - release exclusivity over the rate control of a 60655e9b8b7SJerome Brunet * producer 60755e9b8b7SJerome Brunet * @clk: clock source 60855e9b8b7SJerome Brunet * 60955e9b8b7SJerome Brunet * This function allows drivers to release the exclusivity it previously got 61055e9b8b7SJerome Brunet * from clk_rate_exclusive_get() 61155e9b8b7SJerome Brunet * 61255e9b8b7SJerome Brunet * The caller must balance the number of clk_rate_exclusive_get() and 61355e9b8b7SJerome Brunet * clk_rate_exclusive_put() calls. 61455e9b8b7SJerome Brunet * 61555e9b8b7SJerome Brunet * Must not be called from within atomic context. 61655e9b8b7SJerome Brunet */ 61755e9b8b7SJerome Brunet void clk_rate_exclusive_put(struct clk *clk); 61871a2f115SKuninori Morimoto 61971a2f115SKuninori Morimoto /** 620f8ce2547SRussell King * clk_enable - inform the system when the clock source should be running. 621f8ce2547SRussell King * @clk: clock source 622f8ce2547SRussell King * 623f8ce2547SRussell King * If the clock can not be enabled/disabled, this should return success. 624f8ce2547SRussell King * 62540d3e0f4SRussell King * May be called from atomic contexts. 62640d3e0f4SRussell King * 627f8ce2547SRussell King * Returns success (0) or negative errno. 628f8ce2547SRussell King */ 629f8ce2547SRussell King int clk_enable(struct clk *clk); 630f8ce2547SRussell King 631f8ce2547SRussell King /** 632266e4e9dSDong Aisheng * clk_bulk_enable - inform the system when the set of clks should be running. 633266e4e9dSDong Aisheng * @num_clks: the number of clk_bulk_data 634266e4e9dSDong Aisheng * @clks: the clk_bulk_data table of consumer 635266e4e9dSDong Aisheng * 636266e4e9dSDong Aisheng * May be called from atomic contexts. 637266e4e9dSDong Aisheng * 638266e4e9dSDong Aisheng * Returns success (0) or negative errno. 639266e4e9dSDong Aisheng */ 640266e4e9dSDong Aisheng int __must_check clk_bulk_enable(int num_clks, 641266e4e9dSDong Aisheng const struct clk_bulk_data *clks); 642266e4e9dSDong Aisheng 643266e4e9dSDong Aisheng /** 644f8ce2547SRussell King * clk_disable - inform the system when the clock source is no longer required. 645f8ce2547SRussell King * @clk: clock source 646f8ce2547SRussell King * 647f8ce2547SRussell King * Inform the system that a clock source is no longer required by 648f8ce2547SRussell King * a driver and may be shut down. 649f8ce2547SRussell King * 65040d3e0f4SRussell King * May be called from atomic contexts. 65140d3e0f4SRussell King * 652f8ce2547SRussell King * Implementation detail: if the clock source is shared between 653f8ce2547SRussell King * multiple drivers, clk_enable() calls must be balanced by the 654f8ce2547SRussell King * same number of clk_disable() calls for the clock source to be 655f8ce2547SRussell King * disabled. 656f8ce2547SRussell King */ 657f8ce2547SRussell King void clk_disable(struct clk *clk); 658f8ce2547SRussell King 659f8ce2547SRussell King /** 660266e4e9dSDong Aisheng * clk_bulk_disable - inform the system when the set of clks is no 661266e4e9dSDong Aisheng * longer required. 662266e4e9dSDong Aisheng * @num_clks: the number of clk_bulk_data 663266e4e9dSDong Aisheng * @clks: the clk_bulk_data table of consumer 664266e4e9dSDong Aisheng * 665266e4e9dSDong Aisheng * Inform the system that a set of clks is no longer required by 666266e4e9dSDong Aisheng * a driver and may be shut down. 667266e4e9dSDong Aisheng * 668266e4e9dSDong Aisheng * May be called from atomic contexts. 669266e4e9dSDong Aisheng * 670266e4e9dSDong Aisheng * Implementation detail: if the set of clks is shared between 671266e4e9dSDong Aisheng * multiple drivers, clk_bulk_enable() calls must be balanced by the 672266e4e9dSDong Aisheng * same number of clk_bulk_disable() calls for the clock source to be 673266e4e9dSDong Aisheng * disabled. 674266e4e9dSDong Aisheng */ 675266e4e9dSDong Aisheng void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks); 676266e4e9dSDong Aisheng 677266e4e9dSDong Aisheng /** 678f8ce2547SRussell King * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. 679f8ce2547SRussell King * This is only valid once the clock source has been enabled. 680f8ce2547SRussell King * @clk: clock source 681f8ce2547SRussell King */ 682f8ce2547SRussell King unsigned long clk_get_rate(struct clk *clk); 683f8ce2547SRussell King 684f8ce2547SRussell King /** 685f8ce2547SRussell King * clk_put - "free" the clock source 686f8ce2547SRussell King * @clk: clock source 687f8ce2547SRussell King * 688f8ce2547SRussell King * Note: drivers must ensure that all clk_enable calls made on this 689f8ce2547SRussell King * clock source are balanced by clk_disable calls prior to calling 690f8ce2547SRussell King * this function. 691f7ad160bSAlex Raimondi * 692f7ad160bSAlex Raimondi * clk_put should not be called from within interrupt context. 693f8ce2547SRussell King */ 694f8ce2547SRussell King void clk_put(struct clk *clk); 695f8ce2547SRussell King 696a8a97db9SMark Brown /** 697266e4e9dSDong Aisheng * clk_bulk_put - "free" the clock source 698266e4e9dSDong Aisheng * @num_clks: the number of clk_bulk_data 699266e4e9dSDong Aisheng * @clks: the clk_bulk_data table of consumer 700266e4e9dSDong Aisheng * 701266e4e9dSDong Aisheng * Note: drivers must ensure that all clk_bulk_enable calls made on this 702266e4e9dSDong Aisheng * clock source are balanced by clk_bulk_disable calls prior to calling 703266e4e9dSDong Aisheng * this function. 704266e4e9dSDong Aisheng * 705266e4e9dSDong Aisheng * clk_bulk_put should not be called from within interrupt context. 706266e4e9dSDong Aisheng */ 707266e4e9dSDong Aisheng void clk_bulk_put(int num_clks, struct clk_bulk_data *clks); 708266e4e9dSDong Aisheng 709266e4e9dSDong Aisheng /** 710616e45dfSDong Aisheng * clk_bulk_put_all - "free" all the clock source 711616e45dfSDong Aisheng * @num_clks: the number of clk_bulk_data 712616e45dfSDong Aisheng * @clks: the clk_bulk_data table of consumer 713616e45dfSDong Aisheng * 714616e45dfSDong Aisheng * Note: drivers must ensure that all clk_bulk_enable calls made on this 715616e45dfSDong Aisheng * clock source are balanced by clk_bulk_disable calls prior to calling 716616e45dfSDong Aisheng * this function. 717616e45dfSDong Aisheng * 718616e45dfSDong Aisheng * clk_bulk_put_all should not be called from within interrupt context. 719616e45dfSDong Aisheng */ 720616e45dfSDong Aisheng void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks); 721616e45dfSDong Aisheng 722616e45dfSDong Aisheng /** 723a8a97db9SMark Brown * devm_clk_put - "free" a managed clock source 724da3dae54SMasanari Iida * @dev: device used to acquire the clock 725a8a97db9SMark Brown * @clk: clock source acquired with devm_clk_get() 726a8a97db9SMark Brown * 727a8a97db9SMark Brown * Note: drivers must ensure that all clk_enable calls made on this 728a8a97db9SMark Brown * clock source are balanced by clk_disable calls prior to calling 729a8a97db9SMark Brown * this function. 730a8a97db9SMark Brown * 731a8a97db9SMark Brown * clk_put should not be called from within interrupt context. 732a8a97db9SMark Brown */ 733a8a97db9SMark Brown void devm_clk_put(struct device *dev, struct clk *clk); 734f8ce2547SRussell King 735f8ce2547SRussell King /* 736f8ce2547SRussell King * The remaining APIs are optional for machine class support. 737f8ce2547SRussell King */ 738f8ce2547SRussell King 739f8ce2547SRussell King 740f8ce2547SRussell King /** 741f8ce2547SRussell King * clk_round_rate - adjust a rate to the exact rate a clock can provide 742f8ce2547SRussell King * @clk: clock source 743f8ce2547SRussell King * @rate: desired clock rate in Hz 744f8ce2547SRussell King * 745d2d14a77SRussell King * This answers the question "if I were to pass @rate to clk_set_rate(), 746d2d14a77SRussell King * what clock rate would I end up with?" without changing the hardware 747d2d14a77SRussell King * in any way. In other words: 748d2d14a77SRussell King * 749d2d14a77SRussell King * rate = clk_round_rate(clk, r); 750d2d14a77SRussell King * 751d2d14a77SRussell King * and: 752d2d14a77SRussell King * 753d2d14a77SRussell King * clk_set_rate(clk, r); 754d2d14a77SRussell King * rate = clk_get_rate(clk); 755d2d14a77SRussell King * 756d2d14a77SRussell King * are equivalent except the former does not modify the clock hardware 757d2d14a77SRussell King * in any way. 758d2d14a77SRussell King * 759f8ce2547SRussell King * Returns rounded clock rate in Hz, or negative errno. 760f8ce2547SRussell King */ 761f8ce2547SRussell King long clk_round_rate(struct clk *clk, unsigned long rate); 762f8ce2547SRussell King 763f8ce2547SRussell King /** 764f8ce2547SRussell King * clk_set_rate - set the clock rate for a clock source 765f8ce2547SRussell King * @clk: clock source 766f8ce2547SRussell King * @rate: desired clock rate in Hz 767f8ce2547SRussell King * 76864c76b31SMartin Blumenstingl * Updating the rate starts at the top-most affected clock and then 76964c76b31SMartin Blumenstingl * walks the tree down to the bottom-most clock that needs updating. 77064c76b31SMartin Blumenstingl * 771f8ce2547SRussell King * Returns success (0) or negative errno. 772f8ce2547SRussell King */ 773f8ce2547SRussell King int clk_set_rate(struct clk *clk, unsigned long rate); 774f8ce2547SRussell King 775f8ce2547SRussell King /** 77655e9b8b7SJerome Brunet * clk_set_rate_exclusive- set the clock rate and claim exclusivity over 77755e9b8b7SJerome Brunet * clock source 77855e9b8b7SJerome Brunet * @clk: clock source 77955e9b8b7SJerome Brunet * @rate: desired clock rate in Hz 78055e9b8b7SJerome Brunet * 78155e9b8b7SJerome Brunet * This helper function allows drivers to atomically set the rate of a producer 78255e9b8b7SJerome Brunet * and claim exclusivity over the rate control of the producer. 78355e9b8b7SJerome Brunet * 78455e9b8b7SJerome Brunet * It is essentially a combination of clk_set_rate() and 78555e9b8b7SJerome Brunet * clk_rate_exclusite_get(). Caller must balance this call with a call to 78655e9b8b7SJerome Brunet * clk_rate_exclusive_put() 78755e9b8b7SJerome Brunet * 78855e9b8b7SJerome Brunet * Returns success (0) or negative errno. 78955e9b8b7SJerome Brunet */ 79055e9b8b7SJerome Brunet int clk_set_rate_exclusive(struct clk *clk, unsigned long rate); 79155e9b8b7SJerome Brunet 79255e9b8b7SJerome Brunet /** 7934e88f3deSThierry Reding * clk_has_parent - check if a clock is a possible parent for another 7944e88f3deSThierry Reding * @clk: clock source 7954e88f3deSThierry Reding * @parent: parent clock source 7964e88f3deSThierry Reding * 7974e88f3deSThierry Reding * This function can be used in drivers that need to check that a clock can be 7984e88f3deSThierry Reding * the parent of another without actually changing the parent. 7994e88f3deSThierry Reding * 8004e88f3deSThierry Reding * Returns true if @parent is a possible parent for @clk, false otherwise. 8014e88f3deSThierry Reding */ 8024e88f3deSThierry Reding bool clk_has_parent(struct clk *clk, struct clk *parent); 8034e88f3deSThierry Reding 8044e88f3deSThierry Reding /** 8051c8e6004STomeu Vizoso * clk_set_rate_range - set a rate range for a clock source 8061c8e6004STomeu Vizoso * @clk: clock source 8071c8e6004STomeu Vizoso * @min: desired minimum clock rate in Hz, inclusive 8081c8e6004STomeu Vizoso * @max: desired maximum clock rate in Hz, inclusive 8091c8e6004STomeu Vizoso * 8101c8e6004STomeu Vizoso * Returns success (0) or negative errno. 8111c8e6004STomeu Vizoso */ 8121c8e6004STomeu Vizoso int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max); 8131c8e6004STomeu Vizoso 8141c8e6004STomeu Vizoso /** 8151c8e6004STomeu Vizoso * clk_set_min_rate - set a minimum clock rate for a clock source 8161c8e6004STomeu Vizoso * @clk: clock source 8171c8e6004STomeu Vizoso * @rate: desired minimum clock rate in Hz, inclusive 8181c8e6004STomeu Vizoso * 8191c8e6004STomeu Vizoso * Returns success (0) or negative errno. 8201c8e6004STomeu Vizoso */ 8211c8e6004STomeu Vizoso int clk_set_min_rate(struct clk *clk, unsigned long rate); 8221c8e6004STomeu Vizoso 8231c8e6004STomeu Vizoso /** 8241c8e6004STomeu Vizoso * clk_set_max_rate - set a maximum clock rate for a clock source 8251c8e6004STomeu Vizoso * @clk: clock source 8261c8e6004STomeu Vizoso * @rate: desired maximum clock rate in Hz, inclusive 8271c8e6004STomeu Vizoso * 8281c8e6004STomeu Vizoso * Returns success (0) or negative errno. 8291c8e6004STomeu Vizoso */ 8301c8e6004STomeu Vizoso int clk_set_max_rate(struct clk *clk, unsigned long rate); 8311c8e6004STomeu Vizoso 8321c8e6004STomeu Vizoso /** 833f8ce2547SRussell King * clk_set_parent - set the parent clock source for this clock 834f8ce2547SRussell King * @clk: clock source 835f8ce2547SRussell King * @parent: parent clock source 836f8ce2547SRussell King * 837f8ce2547SRussell King * Returns success (0) or negative errno. 838f8ce2547SRussell King */ 839f8ce2547SRussell King int clk_set_parent(struct clk *clk, struct clk *parent); 840f8ce2547SRussell King 841f8ce2547SRussell King /** 842f8ce2547SRussell King * clk_get_parent - get the parent clock source for this clock 843f8ce2547SRussell King * @clk: clock source 844f8ce2547SRussell King * 845f8ce2547SRussell King * Returns struct clk corresponding to parent clock source, or 846f8ce2547SRussell King * valid IS_ERR() condition containing errno. 847f8ce2547SRussell King */ 848f8ce2547SRussell King struct clk *clk_get_parent(struct clk *clk); 849f8ce2547SRussell King 85005fd8e73SSascha Hauer /** 85105fd8e73SSascha Hauer * clk_get_sys - get a clock based upon the device name 85205fd8e73SSascha Hauer * @dev_id: device name 85305fd8e73SSascha Hauer * @con_id: connection ID 85405fd8e73SSascha Hauer * 85505fd8e73SSascha Hauer * Returns a struct clk corresponding to the clock producer, or 85605fd8e73SSascha Hauer * valid IS_ERR() condition containing errno. The implementation 85705fd8e73SSascha Hauer * uses @dev_id and @con_id to determine the clock consumer, and 85805fd8e73SSascha Hauer * thereby the clock producer. In contrast to clk_get() this function 85905fd8e73SSascha Hauer * takes the device name instead of the device itself for identification. 86005fd8e73SSascha Hauer * 86105fd8e73SSascha Hauer * Drivers must assume that the clock source is not enabled. 86205fd8e73SSascha Hauer * 86305fd8e73SSascha Hauer * clk_get_sys should not be called from within interrupt context. 86405fd8e73SSascha Hauer */ 86505fd8e73SSascha Hauer struct clk *clk_get_sys(const char *dev_id, const char *con_id); 86605fd8e73SSascha Hauer 8678b95d1ceSRuss Dill /** 8688b95d1ceSRuss Dill * clk_save_context - save clock context for poweroff 8698b95d1ceSRuss Dill * 8708b95d1ceSRuss Dill * Saves the context of the clock register for powerstates in which the 8718b95d1ceSRuss Dill * contents of the registers will be lost. Occurs deep within the suspend 8728b95d1ceSRuss Dill * code so locking is not necessary. 8738b95d1ceSRuss Dill */ 8748b95d1ceSRuss Dill int clk_save_context(void); 8758b95d1ceSRuss Dill 8768b95d1ceSRuss Dill /** 8778b95d1ceSRuss Dill * clk_restore_context - restore clock context after poweroff 8788b95d1ceSRuss Dill * 8798b95d1ceSRuss Dill * This occurs with all clocks enabled. Occurs deep within the resume code 8808b95d1ceSRuss Dill * so locking is not necessary. 8818b95d1ceSRuss Dill */ 8828b95d1ceSRuss Dill void clk_restore_context(void); 8838b95d1ceSRuss Dill 88493abe8e4SViresh Kumar #else /* !CONFIG_HAVE_CLK */ 88593abe8e4SViresh Kumar 88693abe8e4SViresh Kumar static inline struct clk *clk_get(struct device *dev, const char *id) 88793abe8e4SViresh Kumar { 88893abe8e4SViresh Kumar return NULL; 88993abe8e4SViresh Kumar } 89093abe8e4SViresh Kumar 8916e0d4ff4SDong Aisheng static inline int __must_check clk_bulk_get(struct device *dev, int num_clks, 892266e4e9dSDong Aisheng struct clk_bulk_data *clks) 893266e4e9dSDong Aisheng { 894266e4e9dSDong Aisheng return 0; 895266e4e9dSDong Aisheng } 896266e4e9dSDong Aisheng 8972f25528eSSylwester Nawrocki static inline int __must_check clk_bulk_get_optional(struct device *dev, 8982f25528eSSylwester Nawrocki int num_clks, struct clk_bulk_data *clks) 8992f25528eSSylwester Nawrocki { 9002f25528eSSylwester Nawrocki return 0; 9012f25528eSSylwester Nawrocki } 9022f25528eSSylwester Nawrocki 903616e45dfSDong Aisheng static inline int __must_check clk_bulk_get_all(struct device *dev, 904616e45dfSDong Aisheng struct clk_bulk_data **clks) 905616e45dfSDong Aisheng { 906616e45dfSDong Aisheng return 0; 907616e45dfSDong Aisheng } 908616e45dfSDong Aisheng 90993abe8e4SViresh Kumar static inline struct clk *devm_clk_get(struct device *dev, const char *id) 91093abe8e4SViresh Kumar { 91193abe8e4SViresh Kumar return NULL; 91293abe8e4SViresh Kumar } 91393abe8e4SViresh Kumar 914*7ef9651eSUwe Kleine-König static inline struct clk *devm_clk_get_prepared(struct device *dev, 915*7ef9651eSUwe Kleine-König const char *id) 916*7ef9651eSUwe Kleine-König { 917*7ef9651eSUwe Kleine-König return NULL; 918*7ef9651eSUwe Kleine-König } 919*7ef9651eSUwe Kleine-König 920*7ef9651eSUwe Kleine-König static inline struct clk *devm_clk_get_enabled(struct device *dev, 921*7ef9651eSUwe Kleine-König const char *id) 922*7ef9651eSUwe Kleine-König { 923*7ef9651eSUwe Kleine-König return NULL; 924*7ef9651eSUwe Kleine-König } 925*7ef9651eSUwe Kleine-König 92660b8f0ddSPhil Edworthy static inline struct clk *devm_clk_get_optional(struct device *dev, 92760b8f0ddSPhil Edworthy const char *id) 92860b8f0ddSPhil Edworthy { 92960b8f0ddSPhil Edworthy return NULL; 93060b8f0ddSPhil Edworthy } 93160b8f0ddSPhil Edworthy 932*7ef9651eSUwe Kleine-König static inline struct clk *devm_clk_get_optional_prepared(struct device *dev, 933*7ef9651eSUwe Kleine-König const char *id) 934*7ef9651eSUwe Kleine-König { 935*7ef9651eSUwe Kleine-König return NULL; 936*7ef9651eSUwe Kleine-König } 937*7ef9651eSUwe Kleine-König 938*7ef9651eSUwe Kleine-König static inline struct clk *devm_clk_get_optional_enabled(struct device *dev, 939*7ef9651eSUwe Kleine-König const char *id) 940*7ef9651eSUwe Kleine-König { 941*7ef9651eSUwe Kleine-König return NULL; 942*7ef9651eSUwe Kleine-König } 943*7ef9651eSUwe Kleine-König 9446e0d4ff4SDong Aisheng static inline int __must_check devm_clk_bulk_get(struct device *dev, int num_clks, 945618aee02SDong Aisheng struct clk_bulk_data *clks) 946618aee02SDong Aisheng { 947618aee02SDong Aisheng return 0; 948618aee02SDong Aisheng } 949618aee02SDong Aisheng 9509bd5ef0bSSylwester Nawrocki static inline int __must_check devm_clk_bulk_get_optional(struct device *dev, 9519bd5ef0bSSylwester Nawrocki int num_clks, struct clk_bulk_data *clks) 9529bd5ef0bSSylwester Nawrocki { 9539bd5ef0bSSylwester Nawrocki return 0; 9549bd5ef0bSSylwester Nawrocki } 9559bd5ef0bSSylwester Nawrocki 956f08c2e28SDong Aisheng static inline int __must_check devm_clk_bulk_get_all(struct device *dev, 957f08c2e28SDong Aisheng struct clk_bulk_data **clks) 958f08c2e28SDong Aisheng { 959f08c2e28SDong Aisheng 960f08c2e28SDong Aisheng return 0; 961f08c2e28SDong Aisheng } 962f08c2e28SDong Aisheng 96371a2f115SKuninori Morimoto static inline struct clk *devm_get_clk_from_child(struct device *dev, 96471a2f115SKuninori Morimoto struct device_node *np, const char *con_id) 96571a2f115SKuninori Morimoto { 96671a2f115SKuninori Morimoto return NULL; 96771a2f115SKuninori Morimoto } 96871a2f115SKuninori Morimoto 96993abe8e4SViresh Kumar static inline void clk_put(struct clk *clk) {} 97093abe8e4SViresh Kumar 971266e4e9dSDong Aisheng static inline void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) {} 972266e4e9dSDong Aisheng 973616e45dfSDong Aisheng static inline void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks) {} 974616e45dfSDong Aisheng 97593abe8e4SViresh Kumar static inline void devm_clk_put(struct device *dev, struct clk *clk) {} 97693abe8e4SViresh Kumar 97755e9b8b7SJerome Brunet 97855e9b8b7SJerome Brunet static inline int clk_rate_exclusive_get(struct clk *clk) 97955e9b8b7SJerome Brunet { 98055e9b8b7SJerome Brunet return 0; 98155e9b8b7SJerome Brunet } 98255e9b8b7SJerome Brunet 98355e9b8b7SJerome Brunet static inline void clk_rate_exclusive_put(struct clk *clk) {} 98455e9b8b7SJerome Brunet 98593abe8e4SViresh Kumar static inline int clk_enable(struct clk *clk) 98693abe8e4SViresh Kumar { 98793abe8e4SViresh Kumar return 0; 98893abe8e4SViresh Kumar } 98993abe8e4SViresh Kumar 990570aaec7SAndrey Smirnov static inline int __must_check clk_bulk_enable(int num_clks, 991570aaec7SAndrey Smirnov const struct clk_bulk_data *clks) 992266e4e9dSDong Aisheng { 993266e4e9dSDong Aisheng return 0; 994266e4e9dSDong Aisheng } 995266e4e9dSDong Aisheng 99693abe8e4SViresh Kumar static inline void clk_disable(struct clk *clk) {} 99793abe8e4SViresh Kumar 998266e4e9dSDong Aisheng 999266e4e9dSDong Aisheng static inline void clk_bulk_disable(int num_clks, 1000570aaec7SAndrey Smirnov const struct clk_bulk_data *clks) {} 1001266e4e9dSDong Aisheng 100293abe8e4SViresh Kumar static inline unsigned long clk_get_rate(struct clk *clk) 100393abe8e4SViresh Kumar { 100493abe8e4SViresh Kumar return 0; 100593abe8e4SViresh Kumar } 100693abe8e4SViresh Kumar 100793abe8e4SViresh Kumar static inline int clk_set_rate(struct clk *clk, unsigned long rate) 100893abe8e4SViresh Kumar { 100993abe8e4SViresh Kumar return 0; 101093abe8e4SViresh Kumar } 101193abe8e4SViresh Kumar 101255e9b8b7SJerome Brunet static inline int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) 101355e9b8b7SJerome Brunet { 101455e9b8b7SJerome Brunet return 0; 101555e9b8b7SJerome Brunet } 101655e9b8b7SJerome Brunet 101793abe8e4SViresh Kumar static inline long clk_round_rate(struct clk *clk, unsigned long rate) 101893abe8e4SViresh Kumar { 101993abe8e4SViresh Kumar return 0; 102093abe8e4SViresh Kumar } 102193abe8e4SViresh Kumar 10224e88f3deSThierry Reding static inline bool clk_has_parent(struct clk *clk, struct clk *parent) 10234e88f3deSThierry Reding { 10244e88f3deSThierry Reding return true; 10254e88f3deSThierry Reding } 10264e88f3deSThierry Reding 1027b88c9f41SDmitry Osipenko static inline int clk_set_rate_range(struct clk *clk, unsigned long min, 1028b88c9f41SDmitry Osipenko unsigned long max) 1029b88c9f41SDmitry Osipenko { 1030b88c9f41SDmitry Osipenko return 0; 1031b88c9f41SDmitry Osipenko } 1032b88c9f41SDmitry Osipenko 1033b88c9f41SDmitry Osipenko static inline int clk_set_min_rate(struct clk *clk, unsigned long rate) 1034b88c9f41SDmitry Osipenko { 1035b88c9f41SDmitry Osipenko return 0; 1036b88c9f41SDmitry Osipenko } 1037b88c9f41SDmitry Osipenko 1038b88c9f41SDmitry Osipenko static inline int clk_set_max_rate(struct clk *clk, unsigned long rate) 1039b88c9f41SDmitry Osipenko { 1040b88c9f41SDmitry Osipenko return 0; 1041b88c9f41SDmitry Osipenko } 1042b88c9f41SDmitry Osipenko 104393abe8e4SViresh Kumar static inline int clk_set_parent(struct clk *clk, struct clk *parent) 104493abe8e4SViresh Kumar { 104593abe8e4SViresh Kumar return 0; 104693abe8e4SViresh Kumar } 104793abe8e4SViresh Kumar 104893abe8e4SViresh Kumar static inline struct clk *clk_get_parent(struct clk *clk) 104993abe8e4SViresh Kumar { 105093abe8e4SViresh Kumar return NULL; 105193abe8e4SViresh Kumar } 105293abe8e4SViresh Kumar 1053b81ea968SDaniel Lezcano static inline struct clk *clk_get_sys(const char *dev_id, const char *con_id) 1054b81ea968SDaniel Lezcano { 1055b81ea968SDaniel Lezcano return NULL; 1056b81ea968SDaniel Lezcano } 10578b95d1ceSRuss Dill 10588b95d1ceSRuss Dill static inline int clk_save_context(void) 10598b95d1ceSRuss Dill { 10608b95d1ceSRuss Dill return 0; 10618b95d1ceSRuss Dill } 10628b95d1ceSRuss Dill 10638b95d1ceSRuss Dill static inline void clk_restore_context(void) {} 10648b95d1ceSRuss Dill 106593abe8e4SViresh Kumar #endif 106693abe8e4SViresh Kumar 106793abe8e4SViresh Kumar /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */ 106893abe8e4SViresh Kumar static inline int clk_prepare_enable(struct clk *clk) 106993abe8e4SViresh Kumar { 107093abe8e4SViresh Kumar int ret; 107193abe8e4SViresh Kumar 107293abe8e4SViresh Kumar ret = clk_prepare(clk); 107393abe8e4SViresh Kumar if (ret) 107493abe8e4SViresh Kumar return ret; 107593abe8e4SViresh Kumar ret = clk_enable(clk); 107693abe8e4SViresh Kumar if (ret) 107793abe8e4SViresh Kumar clk_unprepare(clk); 107893abe8e4SViresh Kumar 107993abe8e4SViresh Kumar return ret; 108093abe8e4SViresh Kumar } 108193abe8e4SViresh Kumar 108293abe8e4SViresh Kumar /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */ 108393abe8e4SViresh Kumar static inline void clk_disable_unprepare(struct clk *clk) 108493abe8e4SViresh Kumar { 108593abe8e4SViresh Kumar clk_disable(clk); 108693abe8e4SViresh Kumar clk_unprepare(clk); 108793abe8e4SViresh Kumar } 108893abe8e4SViresh Kumar 1089570aaec7SAndrey Smirnov static inline int __must_check 1090570aaec7SAndrey Smirnov clk_bulk_prepare_enable(int num_clks, const struct clk_bulk_data *clks) 10913c48d86cSBjorn Andersson { 10923c48d86cSBjorn Andersson int ret; 10933c48d86cSBjorn Andersson 10943c48d86cSBjorn Andersson ret = clk_bulk_prepare(num_clks, clks); 10953c48d86cSBjorn Andersson if (ret) 10963c48d86cSBjorn Andersson return ret; 10973c48d86cSBjorn Andersson ret = clk_bulk_enable(num_clks, clks); 10983c48d86cSBjorn Andersson if (ret) 10993c48d86cSBjorn Andersson clk_bulk_unprepare(num_clks, clks); 11003c48d86cSBjorn Andersson 11013c48d86cSBjorn Andersson return ret; 11023c48d86cSBjorn Andersson } 11033c48d86cSBjorn Andersson 11043c48d86cSBjorn Andersson static inline void clk_bulk_disable_unprepare(int num_clks, 1105570aaec7SAndrey Smirnov const struct clk_bulk_data *clks) 11063c48d86cSBjorn Andersson { 11073c48d86cSBjorn Andersson clk_bulk_disable(num_clks, clks); 11083c48d86cSBjorn Andersson clk_bulk_unprepare(num_clks, clks); 11093c48d86cSBjorn Andersson } 11103c48d86cSBjorn Andersson 111160b8f0ddSPhil Edworthy /** 1112c9744843SMaxime Ripard * clk_drop_range - Reset any range set on that clock 1113c9744843SMaxime Ripard * @clk: clock source 1114c9744843SMaxime Ripard * 1115c9744843SMaxime Ripard * Returns success (0) or negative errno. 1116c9744843SMaxime Ripard */ 1117c9744843SMaxime Ripard static inline int clk_drop_range(struct clk *clk) 1118c9744843SMaxime Ripard { 1119c9744843SMaxime Ripard return clk_set_rate_range(clk, 0, ULONG_MAX); 1120c9744843SMaxime Ripard } 1121c9744843SMaxime Ripard 1122c9744843SMaxime Ripard /** 112360b8f0ddSPhil Edworthy * clk_get_optional - lookup and obtain a reference to an optional clock 112460b8f0ddSPhil Edworthy * producer. 112560b8f0ddSPhil Edworthy * @dev: device for clock "consumer" 112660b8f0ddSPhil Edworthy * @id: clock consumer ID 112760b8f0ddSPhil Edworthy * 112860b8f0ddSPhil Edworthy * Behaves the same as clk_get() except where there is no clock producer. In 112960b8f0ddSPhil Edworthy * this case, instead of returning -ENOENT, the function returns NULL. 113060b8f0ddSPhil Edworthy */ 113160b8f0ddSPhil Edworthy static inline struct clk *clk_get_optional(struct device *dev, const char *id) 113260b8f0ddSPhil Edworthy { 113360b8f0ddSPhil Edworthy struct clk *clk = clk_get(dev, id); 113460b8f0ddSPhil Edworthy 113560b8f0ddSPhil Edworthy if (clk == ERR_PTR(-ENOENT)) 113660b8f0ddSPhil Edworthy return NULL; 113760b8f0ddSPhil Edworthy 113860b8f0ddSPhil Edworthy return clk; 113960b8f0ddSPhil Edworthy } 114060b8f0ddSPhil Edworthy 1141137f8a72SRob Herring #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) 1142766e6a4eSGrant Likely struct clk *of_clk_get(struct device_node *np, int index); 1143766e6a4eSGrant Likely struct clk *of_clk_get_by_name(struct device_node *np, const char *name); 1144766e6a4eSGrant Likely struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec); 1145766e6a4eSGrant Likely #else 1146766e6a4eSGrant Likely static inline struct clk *of_clk_get(struct device_node *np, int index) 1147766e6a4eSGrant Likely { 11489f1612d3SShawn Guo return ERR_PTR(-ENOENT); 1149766e6a4eSGrant Likely } 1150766e6a4eSGrant Likely static inline struct clk *of_clk_get_by_name(struct device_node *np, 1151766e6a4eSGrant Likely const char *name) 1152766e6a4eSGrant Likely { 11539f1612d3SShawn Guo return ERR_PTR(-ENOENT); 1154766e6a4eSGrant Likely } 1155428c9de5SGeert Uytterhoeven static inline struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec) 1156428c9de5SGeert Uytterhoeven { 1157428c9de5SGeert Uytterhoeven return ERR_PTR(-ENOENT); 1158428c9de5SGeert Uytterhoeven } 1159766e6a4eSGrant Likely #endif 1160766e6a4eSGrant Likely 1161f8ce2547SRussell King #endif 1162