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 /** 9586bcfa2eSMike Turquette * 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 /** 10686bcfa2eSMike Turquette * 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 /** 1135279fc40SBoris BREZILLON * clk_get_accuracy - obtain the clock accuracy in ppb (parts per billion) 1145279fc40SBoris BREZILLON * for a clock source. 1155279fc40SBoris BREZILLON * @clk: clock source 1165279fc40SBoris BREZILLON * 1175279fc40SBoris BREZILLON * This gets the clock source accuracy expressed in ppb. 1185279fc40SBoris BREZILLON * A perfect clock returns 0. 1195279fc40SBoris BREZILLON */ 1205279fc40SBoris BREZILLON long clk_get_accuracy(struct clk *clk); 1215279fc40SBoris BREZILLON 122e59c5371SMike Turquette /** 123e59c5371SMike Turquette * clk_set_phase - adjust the phase shift of a clock signal 124e59c5371SMike Turquette * @clk: clock signal source 125e59c5371SMike Turquette * @degrees: number of degrees the signal is shifted 126e59c5371SMike Turquette * 127e59c5371SMike Turquette * Shifts the phase of a clock signal by the specified degrees. Returns 0 on 128e59c5371SMike Turquette * success, -EERROR otherwise. 129e59c5371SMike Turquette */ 130e59c5371SMike Turquette int clk_set_phase(struct clk *clk, int degrees); 131e59c5371SMike Turquette 132e59c5371SMike Turquette /** 133e59c5371SMike Turquette * clk_get_phase - return the phase shift of a clock signal 134e59c5371SMike Turquette * @clk: clock signal source 135e59c5371SMike Turquette * 136e59c5371SMike Turquette * Returns the phase shift of a clock node in degrees, otherwise returns 137e59c5371SMike Turquette * -EERROR. 138e59c5371SMike Turquette */ 139e59c5371SMike Turquette int clk_get_phase(struct clk *clk); 140e59c5371SMike Turquette 1413d3801efSMichael Turquette /** 1429fba738aSJerome Brunet * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal 1439fba738aSJerome Brunet * @clk: clock signal source 1449fba738aSJerome Brunet * @num: numerator of the duty cycle ratio to be applied 1459fba738aSJerome Brunet * @den: denominator of the duty cycle ratio to be applied 1469fba738aSJerome Brunet * 1479fba738aSJerome Brunet * Adjust the duty cycle of a clock signal by the specified ratio. Returns 0 on 1489fba738aSJerome Brunet * success, -EERROR otherwise. 1499fba738aSJerome Brunet */ 1509fba738aSJerome Brunet int clk_set_duty_cycle(struct clk *clk, unsigned int num, unsigned int den); 1519fba738aSJerome Brunet 1529fba738aSJerome Brunet /** 153*9d1c94a6SMauro Carvalho Chehab * clk_get_scaled_duty_cycle - return the duty cycle ratio of a clock signal 1549fba738aSJerome Brunet * @clk: clock signal source 1559fba738aSJerome Brunet * @scale: scaling factor to be applied to represent the ratio as an integer 1569fba738aSJerome Brunet * 1579fba738aSJerome Brunet * Returns the duty cycle ratio multiplied by the scale provided, otherwise 1589fba738aSJerome Brunet * returns -EERROR. 1599fba738aSJerome Brunet */ 1609fba738aSJerome Brunet int clk_get_scaled_duty_cycle(struct clk *clk, unsigned int scale); 1619fba738aSJerome Brunet 1629fba738aSJerome Brunet /** 1633d3801efSMichael Turquette * clk_is_match - check if two clk's point to the same hardware clock 1643d3801efSMichael Turquette * @p: clk compared against q 1653d3801efSMichael Turquette * @q: clk compared against p 1663d3801efSMichael Turquette * 1673d3801efSMichael Turquette * Returns true if the two struct clk pointers both point to the same hardware 1680e056eb5Smchehab@s-opensource.com * clock node. Put differently, returns true if @p and @q 1690e056eb5Smchehab@s-opensource.com * share the same &struct clk_core object. 1703d3801efSMichael Turquette * 1713d3801efSMichael Turquette * Returns false otherwise. Note that two NULL clks are treated as matching. 1723d3801efSMichael Turquette */ 1733d3801efSMichael Turquette bool clk_is_match(const struct clk *p, const struct clk *q); 1743d3801efSMichael Turquette 1755279fc40SBoris BREZILLON #else 1765279fc40SBoris BREZILLON 177e81b87d2SKrzysztof Kozlowski static inline int clk_notifier_register(struct clk *clk, 178e81b87d2SKrzysztof Kozlowski struct notifier_block *nb) 179e81b87d2SKrzysztof Kozlowski { 180e81b87d2SKrzysztof Kozlowski return -ENOTSUPP; 181e81b87d2SKrzysztof Kozlowski } 182e81b87d2SKrzysztof Kozlowski 183e81b87d2SKrzysztof Kozlowski static inline int clk_notifier_unregister(struct clk *clk, 184e81b87d2SKrzysztof Kozlowski struct notifier_block *nb) 185e81b87d2SKrzysztof Kozlowski { 186e81b87d2SKrzysztof Kozlowski return -ENOTSUPP; 187e81b87d2SKrzysztof Kozlowski } 188e81b87d2SKrzysztof Kozlowski 1895279fc40SBoris BREZILLON static inline long clk_get_accuracy(struct clk *clk) 1905279fc40SBoris BREZILLON { 1915279fc40SBoris BREZILLON return -ENOTSUPP; 1925279fc40SBoris BREZILLON } 1935279fc40SBoris BREZILLON 194e59c5371SMike Turquette static inline long clk_set_phase(struct clk *clk, int phase) 195e59c5371SMike Turquette { 196e59c5371SMike Turquette return -ENOTSUPP; 197e59c5371SMike Turquette } 198e59c5371SMike Turquette 199e59c5371SMike Turquette static inline long clk_get_phase(struct clk *clk) 200e59c5371SMike Turquette { 201e59c5371SMike Turquette return -ENOTSUPP; 202e59c5371SMike Turquette } 203e59c5371SMike Turquette 2049fba738aSJerome Brunet static inline int clk_set_duty_cycle(struct clk *clk, unsigned int num, 2059fba738aSJerome Brunet unsigned int den) 2069fba738aSJerome Brunet { 2079fba738aSJerome Brunet return -ENOTSUPP; 2089fba738aSJerome Brunet } 2099fba738aSJerome Brunet 2109fba738aSJerome Brunet static inline unsigned int clk_get_scaled_duty_cycle(struct clk *clk, 2119fba738aSJerome Brunet unsigned int scale) 2129fba738aSJerome Brunet { 2139fba738aSJerome Brunet return 0; 2149fba738aSJerome Brunet } 2159fba738aSJerome Brunet 2163d3801efSMichael Turquette static inline bool clk_is_match(const struct clk *p, const struct clk *q) 2173d3801efSMichael Turquette { 2183d3801efSMichael Turquette return p == q; 2193d3801efSMichael Turquette } 2203d3801efSMichael Turquette 2217e87aed9SMark Brown #endif 222b2476490SMike Turquette 223f8ce2547SRussell King /** 22493abe8e4SViresh Kumar * clk_prepare - prepare a clock source 22593abe8e4SViresh Kumar * @clk: clock source 22693abe8e4SViresh Kumar * 22793abe8e4SViresh Kumar * This prepares the clock source for use. 22893abe8e4SViresh Kumar * 22993abe8e4SViresh Kumar * Must not be called from within atomic context. 23093abe8e4SViresh Kumar */ 23193abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE 23293abe8e4SViresh Kumar int clk_prepare(struct clk *clk); 233266e4e9dSDong Aisheng int __must_check clk_bulk_prepare(int num_clks, 234266e4e9dSDong Aisheng const struct clk_bulk_data *clks); 23593abe8e4SViresh Kumar #else 23693abe8e4SViresh Kumar static inline int clk_prepare(struct clk *clk) 23793abe8e4SViresh Kumar { 23893abe8e4SViresh Kumar might_sleep(); 23993abe8e4SViresh Kumar return 0; 24093abe8e4SViresh Kumar } 241266e4e9dSDong Aisheng 242570aaec7SAndrey Smirnov static inline int __must_check 243570aaec7SAndrey Smirnov clk_bulk_prepare(int num_clks, const struct clk_bulk_data *clks) 244266e4e9dSDong Aisheng { 245266e4e9dSDong Aisheng might_sleep(); 246266e4e9dSDong Aisheng return 0; 247266e4e9dSDong Aisheng } 24893abe8e4SViresh Kumar #endif 24993abe8e4SViresh Kumar 25093abe8e4SViresh Kumar /** 25193abe8e4SViresh Kumar * clk_unprepare - undo preparation of a clock source 25293abe8e4SViresh Kumar * @clk: clock source 25393abe8e4SViresh Kumar * 25493abe8e4SViresh Kumar * This undoes a previously prepared clock. The caller must balance 25593abe8e4SViresh Kumar * the number of prepare and unprepare calls. 25693abe8e4SViresh Kumar * 25793abe8e4SViresh Kumar * Must not be called from within atomic context. 25893abe8e4SViresh Kumar */ 25993abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK_PREPARE 26093abe8e4SViresh Kumar void clk_unprepare(struct clk *clk); 261266e4e9dSDong Aisheng void clk_bulk_unprepare(int num_clks, const struct clk_bulk_data *clks); 26293abe8e4SViresh Kumar #else 26393abe8e4SViresh Kumar static inline void clk_unprepare(struct clk *clk) 26493abe8e4SViresh Kumar { 26593abe8e4SViresh Kumar might_sleep(); 26693abe8e4SViresh Kumar } 267570aaec7SAndrey Smirnov static inline void clk_bulk_unprepare(int num_clks, 268570aaec7SAndrey Smirnov const struct clk_bulk_data *clks) 269266e4e9dSDong Aisheng { 270266e4e9dSDong Aisheng might_sleep(); 271266e4e9dSDong Aisheng } 27293abe8e4SViresh Kumar #endif 27393abe8e4SViresh Kumar 27493abe8e4SViresh Kumar #ifdef CONFIG_HAVE_CLK 27593abe8e4SViresh Kumar /** 276f8ce2547SRussell King * clk_get - lookup and obtain a reference to a clock producer. 277f8ce2547SRussell King * @dev: device for clock "consumer" 278a58b3a4aSJan-Simon Möller * @id: clock consumer ID 279f8ce2547SRussell King * 280f8ce2547SRussell King * Returns a struct clk corresponding to the clock producer, or 281f8ce2547SRussell King * valid IS_ERR() condition containing errno. The implementation 282f8ce2547SRussell King * uses @dev and @id to determine the clock consumer, and thereby 283f8ce2547SRussell King * the clock producer. (IOW, @id may be identical strings, but 284f8ce2547SRussell King * clk_get may return different clock producers depending on @dev.) 285f8ce2547SRussell King * 286f8ce2547SRussell King * Drivers must assume that the clock source is not enabled. 287f7ad160bSAlex Raimondi * 288f7ad160bSAlex Raimondi * clk_get should not be called from within interrupt context. 289f8ce2547SRussell King */ 290f8ce2547SRussell King struct clk *clk_get(struct device *dev, const char *id); 291f8ce2547SRussell King 292f8ce2547SRussell King /** 293266e4e9dSDong Aisheng * clk_bulk_get - lookup and obtain a number of references to clock producer. 294266e4e9dSDong Aisheng * @dev: device for clock "consumer" 295266e4e9dSDong Aisheng * @num_clks: the number of clk_bulk_data 296266e4e9dSDong Aisheng * @clks: the clk_bulk_data table of consumer 297266e4e9dSDong Aisheng * 298266e4e9dSDong Aisheng * This helper function allows drivers to get several clk consumers in one 299266e4e9dSDong Aisheng * operation. If any of the clk cannot be acquired then any clks 300266e4e9dSDong Aisheng * that were obtained will be freed before returning to the caller. 301266e4e9dSDong Aisheng * 302266e4e9dSDong Aisheng * Returns 0 if all clocks specified in clk_bulk_data table are obtained 303266e4e9dSDong Aisheng * successfully, or valid IS_ERR() condition containing errno. 304266e4e9dSDong Aisheng * The implementation uses @dev and @clk_bulk_data.id to determine the 305266e4e9dSDong Aisheng * clock consumer, and thereby the clock producer. 306266e4e9dSDong Aisheng * The clock returned is stored in each @clk_bulk_data.clk field. 307266e4e9dSDong Aisheng * 308266e4e9dSDong Aisheng * Drivers must assume that the clock source is not enabled. 309266e4e9dSDong Aisheng * 310266e4e9dSDong Aisheng * clk_bulk_get should not be called from within interrupt context. 311266e4e9dSDong Aisheng */ 312266e4e9dSDong Aisheng int __must_check clk_bulk_get(struct device *dev, int num_clks, 313266e4e9dSDong Aisheng struct clk_bulk_data *clks); 314616e45dfSDong Aisheng /** 315616e45dfSDong Aisheng * clk_bulk_get_all - lookup and obtain all available references to clock 316616e45dfSDong Aisheng * producer. 317616e45dfSDong Aisheng * @dev: device for clock "consumer" 318616e45dfSDong Aisheng * @clks: pointer to the clk_bulk_data table of consumer 319616e45dfSDong Aisheng * 320616e45dfSDong Aisheng * This helper function allows drivers to get all clk consumers in one 321616e45dfSDong Aisheng * operation. If any of the clk cannot be acquired then any clks 322616e45dfSDong Aisheng * that were obtained will be freed before returning to the caller. 323616e45dfSDong Aisheng * 324616e45dfSDong Aisheng * Returns a positive value for the number of clocks obtained while the 325616e45dfSDong Aisheng * clock references are stored in the clk_bulk_data table in @clks field. 326616e45dfSDong Aisheng * Returns 0 if there're none and a negative value if something failed. 327616e45dfSDong Aisheng * 328616e45dfSDong Aisheng * Drivers must assume that the clock source is not enabled. 329616e45dfSDong Aisheng * 330616e45dfSDong Aisheng * clk_bulk_get should not be called from within interrupt context. 331616e45dfSDong Aisheng */ 332616e45dfSDong Aisheng int __must_check clk_bulk_get_all(struct device *dev, 333616e45dfSDong Aisheng struct clk_bulk_data **clks); 3342f25528eSSylwester Nawrocki 3352f25528eSSylwester Nawrocki /** 3362f25528eSSylwester Nawrocki * clk_bulk_get_optional - lookup and obtain a number of references to clock producer 3372f25528eSSylwester Nawrocki * @dev: device for clock "consumer" 3382f25528eSSylwester Nawrocki * @num_clks: the number of clk_bulk_data 3392f25528eSSylwester Nawrocki * @clks: the clk_bulk_data table of consumer 3402f25528eSSylwester Nawrocki * 3412f25528eSSylwester Nawrocki * Behaves the same as clk_bulk_get() except where there is no clock producer. 3422f25528eSSylwester Nawrocki * In this case, instead of returning -ENOENT, the function returns 0 and 3432f25528eSSylwester Nawrocki * NULL for a clk for which a clock producer could not be determined. 3442f25528eSSylwester Nawrocki */ 3452f25528eSSylwester Nawrocki int __must_check clk_bulk_get_optional(struct device *dev, int num_clks, 3462f25528eSSylwester Nawrocki struct clk_bulk_data *clks); 347266e4e9dSDong Aisheng /** 348618aee02SDong Aisheng * devm_clk_bulk_get - managed get multiple clk consumers 349618aee02SDong Aisheng * @dev: device for clock "consumer" 350618aee02SDong Aisheng * @num_clks: the number of clk_bulk_data 351618aee02SDong Aisheng * @clks: the clk_bulk_data table of consumer 352618aee02SDong Aisheng * 353618aee02SDong Aisheng * Return 0 on success, an errno on failure. 354618aee02SDong Aisheng * 355618aee02SDong Aisheng * This helper function allows drivers to get several clk 356618aee02SDong Aisheng * consumers in one operation with management, the clks will 357618aee02SDong Aisheng * automatically be freed when the device is unbound. 358618aee02SDong Aisheng */ 359618aee02SDong Aisheng int __must_check devm_clk_bulk_get(struct device *dev, int num_clks, 360618aee02SDong Aisheng struct clk_bulk_data *clks); 361f08c2e28SDong Aisheng /** 3629bd5ef0bSSylwester Nawrocki * devm_clk_bulk_get_optional - managed get multiple optional consumer clocks 3639bd5ef0bSSylwester Nawrocki * @dev: device for clock "consumer" 3646ee82ef0SSylwester Nawrocki * @num_clks: the number of clk_bulk_data 3659bd5ef0bSSylwester Nawrocki * @clks: pointer to the clk_bulk_data table of consumer 3669bd5ef0bSSylwester Nawrocki * 3679bd5ef0bSSylwester Nawrocki * Behaves the same as devm_clk_bulk_get() except where there is no clock 3689bd5ef0bSSylwester Nawrocki * producer. In this case, instead of returning -ENOENT, the function returns 3699bd5ef0bSSylwester Nawrocki * NULL for given clk. It is assumed all clocks in clk_bulk_data are optional. 3709bd5ef0bSSylwester Nawrocki * 3719bd5ef0bSSylwester Nawrocki * Returns 0 if all clocks specified in clk_bulk_data table are obtained 3729bd5ef0bSSylwester Nawrocki * successfully or for any clk there was no clk provider available, otherwise 3739bd5ef0bSSylwester Nawrocki * returns valid IS_ERR() condition containing errno. 3749bd5ef0bSSylwester Nawrocki * The implementation uses @dev and @clk_bulk_data.id to determine the 3759bd5ef0bSSylwester Nawrocki * clock consumer, and thereby the clock producer. 3769bd5ef0bSSylwester Nawrocki * The clock returned is stored in each @clk_bulk_data.clk field. 3779bd5ef0bSSylwester Nawrocki * 3789bd5ef0bSSylwester Nawrocki * Drivers must assume that the clock source is not enabled. 3799bd5ef0bSSylwester Nawrocki * 3809bd5ef0bSSylwester Nawrocki * clk_bulk_get should not be called from within interrupt context. 3819bd5ef0bSSylwester Nawrocki */ 3829bd5ef0bSSylwester Nawrocki int __must_check devm_clk_bulk_get_optional(struct device *dev, int num_clks, 3839bd5ef0bSSylwester Nawrocki struct clk_bulk_data *clks); 3849bd5ef0bSSylwester Nawrocki /** 385f08c2e28SDong Aisheng * devm_clk_bulk_get_all - managed get multiple clk consumers 386f08c2e28SDong Aisheng * @dev: device for clock "consumer" 387f08c2e28SDong Aisheng * @clks: pointer to the clk_bulk_data table of consumer 388f08c2e28SDong Aisheng * 389f08c2e28SDong Aisheng * Returns a positive value for the number of clocks obtained while the 390f08c2e28SDong Aisheng * clock references are stored in the clk_bulk_data table in @clks field. 391f08c2e28SDong Aisheng * Returns 0 if there're none and a negative value if something failed. 392f08c2e28SDong Aisheng * 393f08c2e28SDong Aisheng * This helper function allows drivers to get several clk 394f08c2e28SDong Aisheng * consumers in one operation with management, the clks will 395f08c2e28SDong Aisheng * automatically be freed when the device is unbound. 396f08c2e28SDong Aisheng */ 397f08c2e28SDong Aisheng 398f08c2e28SDong Aisheng int __must_check devm_clk_bulk_get_all(struct device *dev, 399f08c2e28SDong Aisheng struct clk_bulk_data **clks); 400618aee02SDong Aisheng 401618aee02SDong Aisheng /** 402a8a97db9SMark Brown * devm_clk_get - lookup and obtain a managed reference to a clock producer. 403a8a97db9SMark Brown * @dev: device for clock "consumer" 404a58b3a4aSJan-Simon Möller * @id: clock consumer ID 405a8a97db9SMark Brown * 406a8a97db9SMark Brown * Returns a struct clk corresponding to the clock producer, or 407a8a97db9SMark Brown * valid IS_ERR() condition containing errno. The implementation 408a8a97db9SMark Brown * uses @dev and @id to determine the clock consumer, and thereby 409a8a97db9SMark Brown * the clock producer. (IOW, @id may be identical strings, but 410a8a97db9SMark Brown * clk_get may return different clock producers depending on @dev.) 411a8a97db9SMark Brown * 412a8a97db9SMark Brown * Drivers must assume that the clock source is not enabled. 413a8a97db9SMark Brown * 414a8a97db9SMark Brown * devm_clk_get should not be called from within interrupt context. 415a8a97db9SMark Brown * 416a8a97db9SMark Brown * The clock will automatically be freed when the device is unbound 417a8a97db9SMark Brown * from the bus. 418a8a97db9SMark Brown */ 419a8a97db9SMark Brown struct clk *devm_clk_get(struct device *dev, const char *id); 420a8a97db9SMark Brown 421a8a97db9SMark Brown /** 42260b8f0ddSPhil Edworthy * devm_clk_get_optional - lookup and obtain a managed reference to an optional 42360b8f0ddSPhil Edworthy * clock producer. 42460b8f0ddSPhil Edworthy * @dev: device for clock "consumer" 42560b8f0ddSPhil Edworthy * @id: clock consumer ID 42660b8f0ddSPhil Edworthy * 42760b8f0ddSPhil Edworthy * Behaves the same as devm_clk_get() except where there is no clock producer. 42860b8f0ddSPhil Edworthy * In this case, instead of returning -ENOENT, the function returns NULL. 42960b8f0ddSPhil Edworthy */ 43060b8f0ddSPhil Edworthy struct clk *devm_clk_get_optional(struct device *dev, const char *id); 43160b8f0ddSPhil Edworthy 43260b8f0ddSPhil Edworthy /** 43371a2f115SKuninori Morimoto * devm_get_clk_from_child - lookup and obtain a managed reference to a 43471a2f115SKuninori Morimoto * clock producer from child node. 43571a2f115SKuninori Morimoto * @dev: device for clock "consumer" 43671a2f115SKuninori Morimoto * @np: pointer to clock consumer node 43771a2f115SKuninori Morimoto * @con_id: clock consumer ID 43871a2f115SKuninori Morimoto * 43971a2f115SKuninori Morimoto * This function parses the clocks, and uses them to look up the 44071a2f115SKuninori Morimoto * struct clk from the registered list of clock providers by using 44171a2f115SKuninori Morimoto * @np and @con_id 44271a2f115SKuninori Morimoto * 44371a2f115SKuninori Morimoto * The clock will automatically be freed when the device is unbound 44471a2f115SKuninori Morimoto * from the bus. 44571a2f115SKuninori Morimoto */ 44671a2f115SKuninori Morimoto struct clk *devm_get_clk_from_child(struct device *dev, 44771a2f115SKuninori Morimoto struct device_node *np, const char *con_id); 44855e9b8b7SJerome Brunet /** 44955e9b8b7SJerome Brunet * clk_rate_exclusive_get - get exclusivity over the rate control of a 45055e9b8b7SJerome Brunet * producer 45155e9b8b7SJerome Brunet * @clk: clock source 45255e9b8b7SJerome Brunet * 45355e9b8b7SJerome Brunet * This function allows drivers to get exclusive control over the rate of a 45455e9b8b7SJerome Brunet * provider. It prevents any other consumer to execute, even indirectly, 45555e9b8b7SJerome Brunet * opereation which could alter the rate of the provider or cause glitches 45655e9b8b7SJerome Brunet * 45755e9b8b7SJerome Brunet * If exlusivity is claimed more than once on clock, even by the same driver, 45855e9b8b7SJerome Brunet * the rate effectively gets locked as exclusivity can't be preempted. 45955e9b8b7SJerome Brunet * 46055e9b8b7SJerome Brunet * Must not be called from within atomic context. 46155e9b8b7SJerome Brunet * 46255e9b8b7SJerome Brunet * Returns success (0) or negative errno. 46355e9b8b7SJerome Brunet */ 46455e9b8b7SJerome Brunet int clk_rate_exclusive_get(struct clk *clk); 46555e9b8b7SJerome Brunet 46655e9b8b7SJerome Brunet /** 46755e9b8b7SJerome Brunet * clk_rate_exclusive_put - release exclusivity over the rate control of a 46855e9b8b7SJerome Brunet * producer 46955e9b8b7SJerome Brunet * @clk: clock source 47055e9b8b7SJerome Brunet * 47155e9b8b7SJerome Brunet * This function allows drivers to release the exclusivity it previously got 47255e9b8b7SJerome Brunet * from clk_rate_exclusive_get() 47355e9b8b7SJerome Brunet * 47455e9b8b7SJerome Brunet * The caller must balance the number of clk_rate_exclusive_get() and 47555e9b8b7SJerome Brunet * clk_rate_exclusive_put() calls. 47655e9b8b7SJerome Brunet * 47755e9b8b7SJerome Brunet * Must not be called from within atomic context. 47855e9b8b7SJerome Brunet */ 47955e9b8b7SJerome Brunet void clk_rate_exclusive_put(struct clk *clk); 48071a2f115SKuninori Morimoto 48171a2f115SKuninori Morimoto /** 482f8ce2547SRussell King * clk_enable - inform the system when the clock source should be running. 483f8ce2547SRussell King * @clk: clock source 484f8ce2547SRussell King * 485f8ce2547SRussell King * If the clock can not be enabled/disabled, this should return success. 486f8ce2547SRussell King * 48740d3e0f4SRussell King * May be called from atomic contexts. 48840d3e0f4SRussell King * 489f8ce2547SRussell King * Returns success (0) or negative errno. 490f8ce2547SRussell King */ 491f8ce2547SRussell King int clk_enable(struct clk *clk); 492f8ce2547SRussell King 493f8ce2547SRussell King /** 494266e4e9dSDong Aisheng * clk_bulk_enable - inform the system when the set of clks should be running. 495266e4e9dSDong Aisheng * @num_clks: the number of clk_bulk_data 496266e4e9dSDong Aisheng * @clks: the clk_bulk_data table of consumer 497266e4e9dSDong Aisheng * 498266e4e9dSDong Aisheng * May be called from atomic contexts. 499266e4e9dSDong Aisheng * 500266e4e9dSDong Aisheng * Returns success (0) or negative errno. 501266e4e9dSDong Aisheng */ 502266e4e9dSDong Aisheng int __must_check clk_bulk_enable(int num_clks, 503266e4e9dSDong Aisheng const struct clk_bulk_data *clks); 504266e4e9dSDong Aisheng 505266e4e9dSDong Aisheng /** 506f8ce2547SRussell King * clk_disable - inform the system when the clock source is no longer required. 507f8ce2547SRussell King * @clk: clock source 508f8ce2547SRussell King * 509f8ce2547SRussell King * Inform the system that a clock source is no longer required by 510f8ce2547SRussell King * a driver and may be shut down. 511f8ce2547SRussell King * 51240d3e0f4SRussell King * May be called from atomic contexts. 51340d3e0f4SRussell King * 514f8ce2547SRussell King * Implementation detail: if the clock source is shared between 515f8ce2547SRussell King * multiple drivers, clk_enable() calls must be balanced by the 516f8ce2547SRussell King * same number of clk_disable() calls for the clock source to be 517f8ce2547SRussell King * disabled. 518f8ce2547SRussell King */ 519f8ce2547SRussell King void clk_disable(struct clk *clk); 520f8ce2547SRussell King 521f8ce2547SRussell King /** 522266e4e9dSDong Aisheng * clk_bulk_disable - inform the system when the set of clks is no 523266e4e9dSDong Aisheng * longer required. 524266e4e9dSDong Aisheng * @num_clks: the number of clk_bulk_data 525266e4e9dSDong Aisheng * @clks: the clk_bulk_data table of consumer 526266e4e9dSDong Aisheng * 527266e4e9dSDong Aisheng * Inform the system that a set of clks is no longer required by 528266e4e9dSDong Aisheng * a driver and may be shut down. 529266e4e9dSDong Aisheng * 530266e4e9dSDong Aisheng * May be called from atomic contexts. 531266e4e9dSDong Aisheng * 532266e4e9dSDong Aisheng * Implementation detail: if the set of clks is shared between 533266e4e9dSDong Aisheng * multiple drivers, clk_bulk_enable() calls must be balanced by the 534266e4e9dSDong Aisheng * same number of clk_bulk_disable() calls for the clock source to be 535266e4e9dSDong Aisheng * disabled. 536266e4e9dSDong Aisheng */ 537266e4e9dSDong Aisheng void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks); 538266e4e9dSDong Aisheng 539266e4e9dSDong Aisheng /** 540f8ce2547SRussell King * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. 541f8ce2547SRussell King * This is only valid once the clock source has been enabled. 542f8ce2547SRussell King * @clk: clock source 543f8ce2547SRussell King */ 544f8ce2547SRussell King unsigned long clk_get_rate(struct clk *clk); 545f8ce2547SRussell King 546f8ce2547SRussell King /** 547f8ce2547SRussell King * clk_put - "free" the clock source 548f8ce2547SRussell King * @clk: clock source 549f8ce2547SRussell King * 550f8ce2547SRussell King * Note: drivers must ensure that all clk_enable calls made on this 551f8ce2547SRussell King * clock source are balanced by clk_disable calls prior to calling 552f8ce2547SRussell King * this function. 553f7ad160bSAlex Raimondi * 554f7ad160bSAlex Raimondi * clk_put should not be called from within interrupt context. 555f8ce2547SRussell King */ 556f8ce2547SRussell King void clk_put(struct clk *clk); 557f8ce2547SRussell King 558a8a97db9SMark Brown /** 559266e4e9dSDong Aisheng * clk_bulk_put - "free" the clock source 560266e4e9dSDong Aisheng * @num_clks: the number of clk_bulk_data 561266e4e9dSDong Aisheng * @clks: the clk_bulk_data table of consumer 562266e4e9dSDong Aisheng * 563266e4e9dSDong Aisheng * Note: drivers must ensure that all clk_bulk_enable calls made on this 564266e4e9dSDong Aisheng * clock source are balanced by clk_bulk_disable calls prior to calling 565266e4e9dSDong Aisheng * this function. 566266e4e9dSDong Aisheng * 567266e4e9dSDong Aisheng * clk_bulk_put should not be called from within interrupt context. 568266e4e9dSDong Aisheng */ 569266e4e9dSDong Aisheng void clk_bulk_put(int num_clks, struct clk_bulk_data *clks); 570266e4e9dSDong Aisheng 571266e4e9dSDong Aisheng /** 572616e45dfSDong Aisheng * clk_bulk_put_all - "free" all the clock source 573616e45dfSDong Aisheng * @num_clks: the number of clk_bulk_data 574616e45dfSDong Aisheng * @clks: the clk_bulk_data table of consumer 575616e45dfSDong Aisheng * 576616e45dfSDong Aisheng * Note: drivers must ensure that all clk_bulk_enable calls made on this 577616e45dfSDong Aisheng * clock source are balanced by clk_bulk_disable calls prior to calling 578616e45dfSDong Aisheng * this function. 579616e45dfSDong Aisheng * 580616e45dfSDong Aisheng * clk_bulk_put_all should not be called from within interrupt context. 581616e45dfSDong Aisheng */ 582616e45dfSDong Aisheng void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks); 583616e45dfSDong Aisheng 584616e45dfSDong Aisheng /** 585a8a97db9SMark Brown * devm_clk_put - "free" a managed clock source 586da3dae54SMasanari Iida * @dev: device used to acquire the clock 587a8a97db9SMark Brown * @clk: clock source acquired with devm_clk_get() 588a8a97db9SMark Brown * 589a8a97db9SMark Brown * Note: drivers must ensure that all clk_enable calls made on this 590a8a97db9SMark Brown * clock source are balanced by clk_disable calls prior to calling 591a8a97db9SMark Brown * this function. 592a8a97db9SMark Brown * 593a8a97db9SMark Brown * clk_put should not be called from within interrupt context. 594a8a97db9SMark Brown */ 595a8a97db9SMark Brown void devm_clk_put(struct device *dev, struct clk *clk); 596f8ce2547SRussell King 597f8ce2547SRussell King /* 598f8ce2547SRussell King * The remaining APIs are optional for machine class support. 599f8ce2547SRussell King */ 600f8ce2547SRussell King 601f8ce2547SRussell King 602f8ce2547SRussell King /** 603f8ce2547SRussell King * clk_round_rate - adjust a rate to the exact rate a clock can provide 604f8ce2547SRussell King * @clk: clock source 605f8ce2547SRussell King * @rate: desired clock rate in Hz 606f8ce2547SRussell King * 607d2d14a77SRussell King * This answers the question "if I were to pass @rate to clk_set_rate(), 608d2d14a77SRussell King * what clock rate would I end up with?" without changing the hardware 609d2d14a77SRussell King * in any way. In other words: 610d2d14a77SRussell King * 611d2d14a77SRussell King * rate = clk_round_rate(clk, r); 612d2d14a77SRussell King * 613d2d14a77SRussell King * and: 614d2d14a77SRussell King * 615d2d14a77SRussell King * clk_set_rate(clk, r); 616d2d14a77SRussell King * rate = clk_get_rate(clk); 617d2d14a77SRussell King * 618d2d14a77SRussell King * are equivalent except the former does not modify the clock hardware 619d2d14a77SRussell King * in any way. 620d2d14a77SRussell King * 621f8ce2547SRussell King * Returns rounded clock rate in Hz, or negative errno. 622f8ce2547SRussell King */ 623f8ce2547SRussell King long clk_round_rate(struct clk *clk, unsigned long rate); 624f8ce2547SRussell King 625f8ce2547SRussell King /** 626f8ce2547SRussell King * clk_set_rate - set the clock rate for a clock source 627f8ce2547SRussell King * @clk: clock source 628f8ce2547SRussell King * @rate: desired clock rate in Hz 629f8ce2547SRussell King * 63064c76b31SMartin Blumenstingl * Updating the rate starts at the top-most affected clock and then 63164c76b31SMartin Blumenstingl * walks the tree down to the bottom-most clock that needs updating. 63264c76b31SMartin Blumenstingl * 633f8ce2547SRussell King * Returns success (0) or negative errno. 634f8ce2547SRussell King */ 635f8ce2547SRussell King int clk_set_rate(struct clk *clk, unsigned long rate); 636f8ce2547SRussell King 637f8ce2547SRussell King /** 63855e9b8b7SJerome Brunet * clk_set_rate_exclusive- set the clock rate and claim exclusivity over 63955e9b8b7SJerome Brunet * clock source 64055e9b8b7SJerome Brunet * @clk: clock source 64155e9b8b7SJerome Brunet * @rate: desired clock rate in Hz 64255e9b8b7SJerome Brunet * 64355e9b8b7SJerome Brunet * This helper function allows drivers to atomically set the rate of a producer 64455e9b8b7SJerome Brunet * and claim exclusivity over the rate control of the producer. 64555e9b8b7SJerome Brunet * 64655e9b8b7SJerome Brunet * It is essentially a combination of clk_set_rate() and 64755e9b8b7SJerome Brunet * clk_rate_exclusite_get(). Caller must balance this call with a call to 64855e9b8b7SJerome Brunet * clk_rate_exclusive_put() 64955e9b8b7SJerome Brunet * 65055e9b8b7SJerome Brunet * Returns success (0) or negative errno. 65155e9b8b7SJerome Brunet */ 65255e9b8b7SJerome Brunet int clk_set_rate_exclusive(struct clk *clk, unsigned long rate); 65355e9b8b7SJerome Brunet 65455e9b8b7SJerome Brunet /** 6554e88f3deSThierry Reding * clk_has_parent - check if a clock is a possible parent for another 6564e88f3deSThierry Reding * @clk: clock source 6574e88f3deSThierry Reding * @parent: parent clock source 6584e88f3deSThierry Reding * 6594e88f3deSThierry Reding * This function can be used in drivers that need to check that a clock can be 6604e88f3deSThierry Reding * the parent of another without actually changing the parent. 6614e88f3deSThierry Reding * 6624e88f3deSThierry Reding * Returns true if @parent is a possible parent for @clk, false otherwise. 6634e88f3deSThierry Reding */ 6644e88f3deSThierry Reding bool clk_has_parent(struct clk *clk, struct clk *parent); 6654e88f3deSThierry Reding 6664e88f3deSThierry Reding /** 6671c8e6004STomeu Vizoso * clk_set_rate_range - set a rate range for a clock source 6681c8e6004STomeu Vizoso * @clk: clock source 6691c8e6004STomeu Vizoso * @min: desired minimum clock rate in Hz, inclusive 6701c8e6004STomeu Vizoso * @max: desired maximum clock rate in Hz, inclusive 6711c8e6004STomeu Vizoso * 6721c8e6004STomeu Vizoso * Returns success (0) or negative errno. 6731c8e6004STomeu Vizoso */ 6741c8e6004STomeu Vizoso int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max); 6751c8e6004STomeu Vizoso 6761c8e6004STomeu Vizoso /** 6771c8e6004STomeu Vizoso * clk_set_min_rate - set a minimum clock rate for a clock source 6781c8e6004STomeu Vizoso * @clk: clock source 6791c8e6004STomeu Vizoso * @rate: desired minimum clock rate in Hz, inclusive 6801c8e6004STomeu Vizoso * 6811c8e6004STomeu Vizoso * Returns success (0) or negative errno. 6821c8e6004STomeu Vizoso */ 6831c8e6004STomeu Vizoso int clk_set_min_rate(struct clk *clk, unsigned long rate); 6841c8e6004STomeu Vizoso 6851c8e6004STomeu Vizoso /** 6861c8e6004STomeu Vizoso * clk_set_max_rate - set a maximum clock rate for a clock source 6871c8e6004STomeu Vizoso * @clk: clock source 6881c8e6004STomeu Vizoso * @rate: desired maximum clock rate in Hz, inclusive 6891c8e6004STomeu Vizoso * 6901c8e6004STomeu Vizoso * Returns success (0) or negative errno. 6911c8e6004STomeu Vizoso */ 6921c8e6004STomeu Vizoso int clk_set_max_rate(struct clk *clk, unsigned long rate); 6931c8e6004STomeu Vizoso 6941c8e6004STomeu Vizoso /** 695f8ce2547SRussell King * clk_set_parent - set the parent clock source for this clock 696f8ce2547SRussell King * @clk: clock source 697f8ce2547SRussell King * @parent: parent clock source 698f8ce2547SRussell King * 699f8ce2547SRussell King * Returns success (0) or negative errno. 700f8ce2547SRussell King */ 701f8ce2547SRussell King int clk_set_parent(struct clk *clk, struct clk *parent); 702f8ce2547SRussell King 703f8ce2547SRussell King /** 704f8ce2547SRussell King * clk_get_parent - get the parent clock source for this clock 705f8ce2547SRussell King * @clk: clock source 706f8ce2547SRussell King * 707f8ce2547SRussell King * Returns struct clk corresponding to parent clock source, or 708f8ce2547SRussell King * valid IS_ERR() condition containing errno. 709f8ce2547SRussell King */ 710f8ce2547SRussell King struct clk *clk_get_parent(struct clk *clk); 711f8ce2547SRussell King 71205fd8e73SSascha Hauer /** 71305fd8e73SSascha Hauer * clk_get_sys - get a clock based upon the device name 71405fd8e73SSascha Hauer * @dev_id: device name 71505fd8e73SSascha Hauer * @con_id: connection ID 71605fd8e73SSascha Hauer * 71705fd8e73SSascha Hauer * Returns a struct clk corresponding to the clock producer, or 71805fd8e73SSascha Hauer * valid IS_ERR() condition containing errno. The implementation 71905fd8e73SSascha Hauer * uses @dev_id and @con_id to determine the clock consumer, and 72005fd8e73SSascha Hauer * thereby the clock producer. In contrast to clk_get() this function 72105fd8e73SSascha Hauer * takes the device name instead of the device itself for identification. 72205fd8e73SSascha Hauer * 72305fd8e73SSascha Hauer * Drivers must assume that the clock source is not enabled. 72405fd8e73SSascha Hauer * 72505fd8e73SSascha Hauer * clk_get_sys should not be called from within interrupt context. 72605fd8e73SSascha Hauer */ 72705fd8e73SSascha Hauer struct clk *clk_get_sys(const char *dev_id, const char *con_id); 72805fd8e73SSascha Hauer 7298b95d1ceSRuss Dill /** 7308b95d1ceSRuss Dill * clk_save_context - save clock context for poweroff 7318b95d1ceSRuss Dill * 7328b95d1ceSRuss Dill * Saves the context of the clock register for powerstates in which the 7338b95d1ceSRuss Dill * contents of the registers will be lost. Occurs deep within the suspend 7348b95d1ceSRuss Dill * code so locking is not necessary. 7358b95d1ceSRuss Dill */ 7368b95d1ceSRuss Dill int clk_save_context(void); 7378b95d1ceSRuss Dill 7388b95d1ceSRuss Dill /** 7398b95d1ceSRuss Dill * clk_restore_context - restore clock context after poweroff 7408b95d1ceSRuss Dill * 7418b95d1ceSRuss Dill * This occurs with all clocks enabled. Occurs deep within the resume code 7428b95d1ceSRuss Dill * so locking is not necessary. 7438b95d1ceSRuss Dill */ 7448b95d1ceSRuss Dill void clk_restore_context(void); 7458b95d1ceSRuss Dill 74693abe8e4SViresh Kumar #else /* !CONFIG_HAVE_CLK */ 74793abe8e4SViresh Kumar 74893abe8e4SViresh Kumar static inline struct clk *clk_get(struct device *dev, const char *id) 74993abe8e4SViresh Kumar { 75093abe8e4SViresh Kumar return NULL; 75193abe8e4SViresh Kumar } 75293abe8e4SViresh Kumar 7536e0d4ff4SDong Aisheng static inline int __must_check clk_bulk_get(struct device *dev, int num_clks, 754266e4e9dSDong Aisheng struct clk_bulk_data *clks) 755266e4e9dSDong Aisheng { 756266e4e9dSDong Aisheng return 0; 757266e4e9dSDong Aisheng } 758266e4e9dSDong Aisheng 7592f25528eSSylwester Nawrocki static inline int __must_check clk_bulk_get_optional(struct device *dev, 7602f25528eSSylwester Nawrocki int num_clks, struct clk_bulk_data *clks) 7612f25528eSSylwester Nawrocki { 7622f25528eSSylwester Nawrocki return 0; 7632f25528eSSylwester Nawrocki } 7642f25528eSSylwester Nawrocki 765616e45dfSDong Aisheng static inline int __must_check clk_bulk_get_all(struct device *dev, 766616e45dfSDong Aisheng struct clk_bulk_data **clks) 767616e45dfSDong Aisheng { 768616e45dfSDong Aisheng return 0; 769616e45dfSDong Aisheng } 770616e45dfSDong Aisheng 77193abe8e4SViresh Kumar static inline struct clk *devm_clk_get(struct device *dev, const char *id) 77293abe8e4SViresh Kumar { 77393abe8e4SViresh Kumar return NULL; 77493abe8e4SViresh Kumar } 77593abe8e4SViresh Kumar 77660b8f0ddSPhil Edworthy static inline struct clk *devm_clk_get_optional(struct device *dev, 77760b8f0ddSPhil Edworthy const char *id) 77860b8f0ddSPhil Edworthy { 77960b8f0ddSPhil Edworthy return NULL; 78060b8f0ddSPhil Edworthy } 78160b8f0ddSPhil Edworthy 7826e0d4ff4SDong Aisheng static inline int __must_check devm_clk_bulk_get(struct device *dev, int num_clks, 783618aee02SDong Aisheng struct clk_bulk_data *clks) 784618aee02SDong Aisheng { 785618aee02SDong Aisheng return 0; 786618aee02SDong Aisheng } 787618aee02SDong Aisheng 7889bd5ef0bSSylwester Nawrocki static inline int __must_check devm_clk_bulk_get_optional(struct device *dev, 7899bd5ef0bSSylwester Nawrocki int num_clks, struct clk_bulk_data *clks) 7909bd5ef0bSSylwester Nawrocki { 7919bd5ef0bSSylwester Nawrocki return 0; 7929bd5ef0bSSylwester Nawrocki } 7939bd5ef0bSSylwester Nawrocki 794f08c2e28SDong Aisheng static inline int __must_check devm_clk_bulk_get_all(struct device *dev, 795f08c2e28SDong Aisheng struct clk_bulk_data **clks) 796f08c2e28SDong Aisheng { 797f08c2e28SDong Aisheng 798f08c2e28SDong Aisheng return 0; 799f08c2e28SDong Aisheng } 800f08c2e28SDong Aisheng 80171a2f115SKuninori Morimoto static inline struct clk *devm_get_clk_from_child(struct device *dev, 80271a2f115SKuninori Morimoto struct device_node *np, const char *con_id) 80371a2f115SKuninori Morimoto { 80471a2f115SKuninori Morimoto return NULL; 80571a2f115SKuninori Morimoto } 80671a2f115SKuninori Morimoto 80793abe8e4SViresh Kumar static inline void clk_put(struct clk *clk) {} 80893abe8e4SViresh Kumar 809266e4e9dSDong Aisheng static inline void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) {} 810266e4e9dSDong Aisheng 811616e45dfSDong Aisheng static inline void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks) {} 812616e45dfSDong Aisheng 81393abe8e4SViresh Kumar static inline void devm_clk_put(struct device *dev, struct clk *clk) {} 81493abe8e4SViresh Kumar 81555e9b8b7SJerome Brunet 81655e9b8b7SJerome Brunet static inline int clk_rate_exclusive_get(struct clk *clk) 81755e9b8b7SJerome Brunet { 81855e9b8b7SJerome Brunet return 0; 81955e9b8b7SJerome Brunet } 82055e9b8b7SJerome Brunet 82155e9b8b7SJerome Brunet static inline void clk_rate_exclusive_put(struct clk *clk) {} 82255e9b8b7SJerome Brunet 82393abe8e4SViresh Kumar static inline int clk_enable(struct clk *clk) 82493abe8e4SViresh Kumar { 82593abe8e4SViresh Kumar return 0; 82693abe8e4SViresh Kumar } 82793abe8e4SViresh Kumar 828570aaec7SAndrey Smirnov static inline int __must_check clk_bulk_enable(int num_clks, 829570aaec7SAndrey Smirnov const struct clk_bulk_data *clks) 830266e4e9dSDong Aisheng { 831266e4e9dSDong Aisheng return 0; 832266e4e9dSDong Aisheng } 833266e4e9dSDong Aisheng 83493abe8e4SViresh Kumar static inline void clk_disable(struct clk *clk) {} 83593abe8e4SViresh Kumar 836266e4e9dSDong Aisheng 837266e4e9dSDong Aisheng static inline void clk_bulk_disable(int num_clks, 838570aaec7SAndrey Smirnov const struct clk_bulk_data *clks) {} 839266e4e9dSDong Aisheng 84093abe8e4SViresh Kumar static inline unsigned long clk_get_rate(struct clk *clk) 84193abe8e4SViresh Kumar { 84293abe8e4SViresh Kumar return 0; 84393abe8e4SViresh Kumar } 84493abe8e4SViresh Kumar 84593abe8e4SViresh Kumar static inline int clk_set_rate(struct clk *clk, unsigned long rate) 84693abe8e4SViresh Kumar { 84793abe8e4SViresh Kumar return 0; 84893abe8e4SViresh Kumar } 84993abe8e4SViresh Kumar 85055e9b8b7SJerome Brunet static inline int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) 85155e9b8b7SJerome Brunet { 85255e9b8b7SJerome Brunet return 0; 85355e9b8b7SJerome Brunet } 85455e9b8b7SJerome Brunet 85593abe8e4SViresh Kumar static inline long clk_round_rate(struct clk *clk, unsigned long rate) 85693abe8e4SViresh Kumar { 85793abe8e4SViresh Kumar return 0; 85893abe8e4SViresh Kumar } 85993abe8e4SViresh Kumar 8604e88f3deSThierry Reding static inline bool clk_has_parent(struct clk *clk, struct clk *parent) 8614e88f3deSThierry Reding { 8624e88f3deSThierry Reding return true; 8634e88f3deSThierry Reding } 8644e88f3deSThierry Reding 865b88c9f41SDmitry Osipenko static inline int clk_set_rate_range(struct clk *clk, unsigned long min, 866b88c9f41SDmitry Osipenko unsigned long max) 867b88c9f41SDmitry Osipenko { 868b88c9f41SDmitry Osipenko return 0; 869b88c9f41SDmitry Osipenko } 870b88c9f41SDmitry Osipenko 871b88c9f41SDmitry Osipenko static inline int clk_set_min_rate(struct clk *clk, unsigned long rate) 872b88c9f41SDmitry Osipenko { 873b88c9f41SDmitry Osipenko return 0; 874b88c9f41SDmitry Osipenko } 875b88c9f41SDmitry Osipenko 876b88c9f41SDmitry Osipenko static inline int clk_set_max_rate(struct clk *clk, unsigned long rate) 877b88c9f41SDmitry Osipenko { 878b88c9f41SDmitry Osipenko return 0; 879b88c9f41SDmitry Osipenko } 880b88c9f41SDmitry Osipenko 88193abe8e4SViresh Kumar static inline int clk_set_parent(struct clk *clk, struct clk *parent) 88293abe8e4SViresh Kumar { 88393abe8e4SViresh Kumar return 0; 88493abe8e4SViresh Kumar } 88593abe8e4SViresh Kumar 88693abe8e4SViresh Kumar static inline struct clk *clk_get_parent(struct clk *clk) 88793abe8e4SViresh Kumar { 88893abe8e4SViresh Kumar return NULL; 88993abe8e4SViresh Kumar } 89093abe8e4SViresh Kumar 891b81ea968SDaniel Lezcano static inline struct clk *clk_get_sys(const char *dev_id, const char *con_id) 892b81ea968SDaniel Lezcano { 893b81ea968SDaniel Lezcano return NULL; 894b81ea968SDaniel Lezcano } 8958b95d1ceSRuss Dill 8968b95d1ceSRuss Dill static inline int clk_save_context(void) 8978b95d1ceSRuss Dill { 8988b95d1ceSRuss Dill return 0; 8998b95d1ceSRuss Dill } 9008b95d1ceSRuss Dill 9018b95d1ceSRuss Dill static inline void clk_restore_context(void) {} 9028b95d1ceSRuss Dill 90393abe8e4SViresh Kumar #endif 90493abe8e4SViresh Kumar 90593abe8e4SViresh Kumar /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */ 90693abe8e4SViresh Kumar static inline int clk_prepare_enable(struct clk *clk) 90793abe8e4SViresh Kumar { 90893abe8e4SViresh Kumar int ret; 90993abe8e4SViresh Kumar 91093abe8e4SViresh Kumar ret = clk_prepare(clk); 91193abe8e4SViresh Kumar if (ret) 91293abe8e4SViresh Kumar return ret; 91393abe8e4SViresh Kumar ret = clk_enable(clk); 91493abe8e4SViresh Kumar if (ret) 91593abe8e4SViresh Kumar clk_unprepare(clk); 91693abe8e4SViresh Kumar 91793abe8e4SViresh Kumar return ret; 91893abe8e4SViresh Kumar } 91993abe8e4SViresh Kumar 92093abe8e4SViresh Kumar /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */ 92193abe8e4SViresh Kumar static inline void clk_disable_unprepare(struct clk *clk) 92293abe8e4SViresh Kumar { 92393abe8e4SViresh Kumar clk_disable(clk); 92493abe8e4SViresh Kumar clk_unprepare(clk); 92593abe8e4SViresh Kumar } 92693abe8e4SViresh Kumar 927570aaec7SAndrey Smirnov static inline int __must_check 928570aaec7SAndrey Smirnov clk_bulk_prepare_enable(int num_clks, const struct clk_bulk_data *clks) 9293c48d86cSBjorn Andersson { 9303c48d86cSBjorn Andersson int ret; 9313c48d86cSBjorn Andersson 9323c48d86cSBjorn Andersson ret = clk_bulk_prepare(num_clks, clks); 9333c48d86cSBjorn Andersson if (ret) 9343c48d86cSBjorn Andersson return ret; 9353c48d86cSBjorn Andersson ret = clk_bulk_enable(num_clks, clks); 9363c48d86cSBjorn Andersson if (ret) 9373c48d86cSBjorn Andersson clk_bulk_unprepare(num_clks, clks); 9383c48d86cSBjorn Andersson 9393c48d86cSBjorn Andersson return ret; 9403c48d86cSBjorn Andersson } 9413c48d86cSBjorn Andersson 9423c48d86cSBjorn Andersson static inline void clk_bulk_disable_unprepare(int num_clks, 943570aaec7SAndrey Smirnov const struct clk_bulk_data *clks) 9443c48d86cSBjorn Andersson { 9453c48d86cSBjorn Andersson clk_bulk_disable(num_clks, clks); 9463c48d86cSBjorn Andersson clk_bulk_unprepare(num_clks, clks); 9473c48d86cSBjorn Andersson } 9483c48d86cSBjorn Andersson 94960b8f0ddSPhil Edworthy /** 95060b8f0ddSPhil Edworthy * clk_get_optional - lookup and obtain a reference to an optional clock 95160b8f0ddSPhil Edworthy * producer. 95260b8f0ddSPhil Edworthy * @dev: device for clock "consumer" 95360b8f0ddSPhil Edworthy * @id: clock consumer ID 95460b8f0ddSPhil Edworthy * 95560b8f0ddSPhil Edworthy * Behaves the same as clk_get() except where there is no clock producer. In 95660b8f0ddSPhil Edworthy * this case, instead of returning -ENOENT, the function returns NULL. 95760b8f0ddSPhil Edworthy */ 95860b8f0ddSPhil Edworthy static inline struct clk *clk_get_optional(struct device *dev, const char *id) 95960b8f0ddSPhil Edworthy { 96060b8f0ddSPhil Edworthy struct clk *clk = clk_get(dev, id); 96160b8f0ddSPhil Edworthy 96260b8f0ddSPhil Edworthy if (clk == ERR_PTR(-ENOENT)) 96360b8f0ddSPhil Edworthy return NULL; 96460b8f0ddSPhil Edworthy 96560b8f0ddSPhil Edworthy return clk; 96660b8f0ddSPhil Edworthy } 96760b8f0ddSPhil Edworthy 968137f8a72SRob Herring #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) 969766e6a4eSGrant Likely struct clk *of_clk_get(struct device_node *np, int index); 970766e6a4eSGrant Likely struct clk *of_clk_get_by_name(struct device_node *np, const char *name); 971766e6a4eSGrant Likely struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec); 972766e6a4eSGrant Likely #else 973766e6a4eSGrant Likely static inline struct clk *of_clk_get(struct device_node *np, int index) 974766e6a4eSGrant Likely { 9759f1612d3SShawn Guo return ERR_PTR(-ENOENT); 976766e6a4eSGrant Likely } 977766e6a4eSGrant Likely static inline struct clk *of_clk_get_by_name(struct device_node *np, 978766e6a4eSGrant Likely const char *name) 979766e6a4eSGrant Likely { 9809f1612d3SShawn Guo return ERR_PTR(-ENOENT); 981766e6a4eSGrant Likely } 982428c9de5SGeert Uytterhoeven static inline struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec) 983428c9de5SGeert Uytterhoeven { 984428c9de5SGeert Uytterhoeven return ERR_PTR(-ENOENT); 985428c9de5SGeert Uytterhoeven } 986766e6a4eSGrant Likely #endif 987766e6a4eSGrant Likely 988f8ce2547SRussell King #endif 989