![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0-only */ 0002 /* 0003 * linux/include/linux/clk.h 0004 * 0005 * Copyright (C) 2004 ARM Limited. 0006 * Written by Deep Blue Solutions Limited. 0007 * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org> 0008 */ 0009 #ifndef __LINUX_CLK_H 0010 #define __LINUX_CLK_H 0011 0012 #include <linux/err.h> 0013 #include <linux/kernel.h> 0014 #include <linux/notifier.h> 0015 0016 struct device; 0017 struct clk; 0018 struct device_node; 0019 struct of_phandle_args; 0020 0021 /** 0022 * DOC: clk notifier callback types 0023 * 0024 * PRE_RATE_CHANGE - called immediately before the clk rate is changed, 0025 * to indicate that the rate change will proceed. Drivers must 0026 * immediately terminate any operations that will be affected by the 0027 * rate change. Callbacks may either return NOTIFY_DONE, NOTIFY_OK, 0028 * NOTIFY_STOP or NOTIFY_BAD. 0029 * 0030 * ABORT_RATE_CHANGE: called if the rate change failed for some reason 0031 * after PRE_RATE_CHANGE. In this case, all registered notifiers on 0032 * the clk will be called with ABORT_RATE_CHANGE. Callbacks must 0033 * always return NOTIFY_DONE or NOTIFY_OK. 0034 * 0035 * POST_RATE_CHANGE - called after the clk rate change has successfully 0036 * completed. Callbacks must always return NOTIFY_DONE or NOTIFY_OK. 0037 * 0038 */ 0039 #define PRE_RATE_CHANGE BIT(0) 0040 #define POST_RATE_CHANGE BIT(1) 0041 #define ABORT_RATE_CHANGE BIT(2) 0042 0043 /** 0044 * struct clk_notifier - associate a clk with a notifier 0045 * @clk: struct clk * to associate the notifier with 0046 * @notifier_head: a blocking_notifier_head for this clk 0047 * @node: linked list pointers 0048 * 0049 * A list of struct clk_notifier is maintained by the notifier code. 0050 * An entry is created whenever code registers the first notifier on a 0051 * particular @clk. Future notifiers on that @clk are added to the 0052 * @notifier_head. 0053 */ 0054 struct clk_notifier { 0055 struct clk *clk; 0056 struct srcu_notifier_head notifier_head; 0057 struct list_head node; 0058 }; 0059 0060 /** 0061 * struct clk_notifier_data - rate data to pass to the notifier callback 0062 * @clk: struct clk * being changed 0063 * @old_rate: previous rate of this clk 0064 * @new_rate: new rate of this clk 0065 * 0066 * For a pre-notifier, old_rate is the clk's rate before this rate 0067 * change, and new_rate is what the rate will be in the future. For a 0068 * post-notifier, old_rate and new_rate are both set to the clk's 0069 * current rate (this was done to optimize the implementation). 0070 */ 0071 struct clk_notifier_data { 0072 struct clk *clk; 0073 unsigned long old_rate; 0074 unsigned long new_rate; 0075 }; 0076 0077 /** 0078 * struct clk_bulk_data - Data used for bulk clk operations. 0079 * 0080 * @id: clock consumer ID 0081 * @clk: struct clk * to store the associated clock 0082 * 0083 * The CLK APIs provide a series of clk_bulk_() API calls as 0084 * a convenience to consumers which require multiple clks. This 0085 * structure is used to manage data for these calls. 0086 */ 0087 struct clk_bulk_data { 0088 const char *id; 0089 struct clk *clk; 0090 }; 0091 0092 #ifdef CONFIG_COMMON_CLK 0093 0094 /** 0095 * clk_notifier_register - register a clock rate-change notifier callback 0096 * @clk: clock whose rate we are interested in 0097 * @nb: notifier block with callback function pointer 0098 * 0099 * ProTip: debugging across notifier chains can be frustrating. Make sure that 0100 * your notifier callback function prints a nice big warning in case of 0101 * failure. 0102 */ 0103 int clk_notifier_register(struct clk *clk, struct notifier_block *nb); 0104 0105 /** 0106 * clk_notifier_unregister - unregister a clock rate-change notifier callback 0107 * @clk: clock whose rate we are no longer interested in 0108 * @nb: notifier block which will be unregistered 0109 */ 0110 int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb); 0111 0112 /** 0113 * devm_clk_notifier_register - register a managed rate-change notifier callback 0114 * @dev: device for clock "consumer" 0115 * @clk: clock whose rate we are interested in 0116 * @nb: notifier block with callback function pointer 0117 * 0118 * Returns 0 on success, -EERROR otherwise 0119 */ 0120 int devm_clk_notifier_register(struct device *dev, struct clk *clk, 0121 struct notifier_block *nb); 0122 0123 /** 0124 * clk_get_accuracy - obtain the clock accuracy in ppb (parts per billion) 0125 * for a clock source. 0126 * @clk: clock source 0127 * 0128 * This gets the clock source accuracy expressed in ppb. 0129 * A perfect clock returns 0. 0130 */ 0131 long clk_get_accuracy(struct clk *clk); 0132 0133 /** 0134 * clk_set_phase - adjust the phase shift of a clock signal 0135 * @clk: clock signal source 0136 * @degrees: number of degrees the signal is shifted 0137 * 0138 * Shifts the phase of a clock signal by the specified degrees. Returns 0 on 0139 * success, -EERROR otherwise. 0140 */ 0141 int clk_set_phase(struct clk *clk, int degrees); 0142 0143 /** 0144 * clk_get_phase - return the phase shift of a clock signal 0145 * @clk: clock signal source 0146 * 0147 * Returns the phase shift of a clock node in degrees, otherwise returns 0148 * -EERROR. 0149 */ 0150 int clk_get_phase(struct clk *clk); 0151 0152 /** 0153 * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal 0154 * @clk: clock signal source 0155 * @num: numerator of the duty cycle ratio to be applied 0156 * @den: denominator of the duty cycle ratio to be applied 0157 * 0158 * Adjust the duty cycle of a clock signal by the specified ratio. Returns 0 on 0159 * success, -EERROR otherwise. 0160 */ 0161 int clk_set_duty_cycle(struct clk *clk, unsigned int num, unsigned int den); 0162 0163 /** 0164 * clk_get_scaled_duty_cycle - return the duty cycle ratio of a clock signal 0165 * @clk: clock signal source 0166 * @scale: scaling factor to be applied to represent the ratio as an integer 0167 * 0168 * Returns the duty cycle ratio multiplied by the scale provided, otherwise 0169 * returns -EERROR. 0170 */ 0171 int clk_get_scaled_duty_cycle(struct clk *clk, unsigned int scale); 0172 0173 /** 0174 * clk_is_match - check if two clk's point to the same hardware clock 0175 * @p: clk compared against q 0176 * @q: clk compared against p 0177 * 0178 * Returns true if the two struct clk pointers both point to the same hardware 0179 * clock node. Put differently, returns true if @p and @q 0180 * share the same &struct clk_core object. 0181 * 0182 * Returns false otherwise. Note that two NULL clks are treated as matching. 0183 */ 0184 bool clk_is_match(const struct clk *p, const struct clk *q); 0185 0186 #else 0187 0188 static inline int clk_notifier_register(struct clk *clk, 0189 struct notifier_block *nb) 0190 { 0191 return -ENOTSUPP; 0192 } 0193 0194 static inline int clk_notifier_unregister(struct clk *clk, 0195 struct notifier_block *nb) 0196 { 0197 return -ENOTSUPP; 0198 } 0199 0200 static inline int devm_clk_notifier_register(struct device *dev, 0201 struct clk *clk, 0202 struct notifier_block *nb) 0203 { 0204 return -ENOTSUPP; 0205 } 0206 0207 static inline long clk_get_accuracy(struct clk *clk) 0208 { 0209 return -ENOTSUPP; 0210 } 0211 0212 static inline long clk_set_phase(struct clk *clk, int phase) 0213 { 0214 return -ENOTSUPP; 0215 } 0216 0217 static inline long clk_get_phase(struct clk *clk) 0218 { 0219 return -ENOTSUPP; 0220 } 0221 0222 static inline int clk_set_duty_cycle(struct clk *clk, unsigned int num, 0223 unsigned int den) 0224 { 0225 return -ENOTSUPP; 0226 } 0227 0228 static inline unsigned int clk_get_scaled_duty_cycle(struct clk *clk, 0229 unsigned int scale) 0230 { 0231 return 0; 0232 } 0233 0234 static inline bool clk_is_match(const struct clk *p, const struct clk *q) 0235 { 0236 return p == q; 0237 } 0238 0239 #endif 0240 0241 #ifdef CONFIG_HAVE_CLK_PREPARE 0242 /** 0243 * clk_prepare - prepare a clock source 0244 * @clk: clock source 0245 * 0246 * This prepares the clock source for use. 0247 * 0248 * Must not be called from within atomic context. 0249 */ 0250 int clk_prepare(struct clk *clk); 0251 int __must_check clk_bulk_prepare(int num_clks, 0252 const struct clk_bulk_data *clks); 0253 0254 /** 0255 * clk_is_enabled_when_prepared - indicate if preparing a clock also enables it. 0256 * @clk: clock source 0257 * 0258 * Returns true if clk_prepare() implicitly enables the clock, effectively 0259 * making clk_enable()/clk_disable() no-ops, false otherwise. 0260 * 0261 * This is of interest mainly to the power management code where actually 0262 * disabling the clock also requires unpreparing it to have any material 0263 * effect. 0264 * 0265 * Regardless of the value returned here, the caller must always invoke 0266 * clk_enable() or clk_prepare_enable() and counterparts for usage counts 0267 * to be right. 0268 */ 0269 bool clk_is_enabled_when_prepared(struct clk *clk); 0270 #else 0271 static inline int clk_prepare(struct clk *clk) 0272 { 0273 might_sleep(); 0274 return 0; 0275 } 0276 0277 static inline int __must_check 0278 clk_bulk_prepare(int num_clks, const struct clk_bulk_data *clks) 0279 { 0280 might_sleep(); 0281 return 0; 0282 } 0283 0284 static inline bool clk_is_enabled_when_prepared(struct clk *clk) 0285 { 0286 return false; 0287 } 0288 #endif 0289 0290 /** 0291 * clk_unprepare - undo preparation of a clock source 0292 * @clk: clock source 0293 * 0294 * This undoes a previously prepared clock. The caller must balance 0295 * the number of prepare and unprepare calls. 0296 * 0297 * Must not be called from within atomic context. 0298 */ 0299 #ifdef CONFIG_HAVE_CLK_PREPARE 0300 void clk_unprepare(struct clk *clk); 0301 void clk_bulk_unprepare(int num_clks, const struct clk_bulk_data *clks); 0302 #else 0303 static inline void clk_unprepare(struct clk *clk) 0304 { 0305 might_sleep(); 0306 } 0307 static inline void clk_bulk_unprepare(int num_clks, 0308 const struct clk_bulk_data *clks) 0309 { 0310 might_sleep(); 0311 } 0312 #endif 0313 0314 #ifdef CONFIG_HAVE_CLK 0315 /** 0316 * clk_get - lookup and obtain a reference to a clock producer. 0317 * @dev: device for clock "consumer" 0318 * @id: clock consumer ID 0319 * 0320 * Returns a struct clk corresponding to the clock producer, or 0321 * valid IS_ERR() condition containing errno. The implementation 0322 * uses @dev and @id to determine the clock consumer, and thereby 0323 * the clock producer. (IOW, @id may be identical strings, but 0324 * clk_get may return different clock producers depending on @dev.) 0325 * 0326 * Drivers must assume that the clock source is not enabled. 0327 * 0328 * clk_get should not be called from within interrupt context. 0329 */ 0330 struct clk *clk_get(struct device *dev, const char *id); 0331 0332 /** 0333 * clk_bulk_get - lookup and obtain a number of references to clock producer. 0334 * @dev: device for clock "consumer" 0335 * @num_clks: the number of clk_bulk_data 0336 * @clks: the clk_bulk_data table of consumer 0337 * 0338 * This helper function allows drivers to get several clk consumers in one 0339 * operation. If any of the clk cannot be acquired then any clks 0340 * that were obtained will be freed before returning to the caller. 0341 * 0342 * Returns 0 if all clocks specified in clk_bulk_data table are obtained 0343 * successfully, or valid IS_ERR() condition containing errno. 0344 * The implementation uses @dev and @clk_bulk_data.id to determine the 0345 * clock consumer, and thereby the clock producer. 0346 * The clock returned is stored in each @clk_bulk_data.clk field. 0347 * 0348 * Drivers must assume that the clock source is not enabled. 0349 * 0350 * clk_bulk_get should not be called from within interrupt context. 0351 */ 0352 int __must_check clk_bulk_get(struct device *dev, int num_clks, 0353 struct clk_bulk_data *clks); 0354 /** 0355 * clk_bulk_get_all - lookup and obtain all available references to clock 0356 * producer. 0357 * @dev: device for clock "consumer" 0358 * @clks: pointer to the clk_bulk_data table of consumer 0359 * 0360 * This helper function allows drivers to get all clk consumers in one 0361 * operation. If any of the clk cannot be acquired then any clks 0362 * that were obtained will be freed before returning to the caller. 0363 * 0364 * Returns a positive value for the number of clocks obtained while the 0365 * clock references are stored in the clk_bulk_data table in @clks field. 0366 * Returns 0 if there're none and a negative value if something failed. 0367 * 0368 * Drivers must assume that the clock source is not enabled. 0369 * 0370 * clk_bulk_get should not be called from within interrupt context. 0371 */ 0372 int __must_check clk_bulk_get_all(struct device *dev, 0373 struct clk_bulk_data **clks); 0374 0375 /** 0376 * clk_bulk_get_optional - lookup and obtain a number of references to clock producer 0377 * @dev: device for clock "consumer" 0378 * @num_clks: the number of clk_bulk_data 0379 * @clks: the clk_bulk_data table of consumer 0380 * 0381 * Behaves the same as clk_bulk_get() except where there is no clock producer. 0382 * In this case, instead of returning -ENOENT, the function returns 0 and 0383 * NULL for a clk for which a clock producer could not be determined. 0384 */ 0385 int __must_check clk_bulk_get_optional(struct device *dev, int num_clks, 0386 struct clk_bulk_data *clks); 0387 /** 0388 * devm_clk_bulk_get - managed get multiple clk consumers 0389 * @dev: device for clock "consumer" 0390 * @num_clks: the number of clk_bulk_data 0391 * @clks: the clk_bulk_data table of consumer 0392 * 0393 * Return 0 on success, an errno on failure. 0394 * 0395 * This helper function allows drivers to get several clk 0396 * consumers in one operation with management, the clks will 0397 * automatically be freed when the device is unbound. 0398 */ 0399 int __must_check devm_clk_bulk_get(struct device *dev, int num_clks, 0400 struct clk_bulk_data *clks); 0401 /** 0402 * devm_clk_bulk_get_optional - managed get multiple optional consumer clocks 0403 * @dev: device for clock "consumer" 0404 * @num_clks: the number of clk_bulk_data 0405 * @clks: pointer to the clk_bulk_data table of consumer 0406 * 0407 * Behaves the same as devm_clk_bulk_get() except where there is no clock 0408 * producer. In this case, instead of returning -ENOENT, the function returns 0409 * NULL for given clk. It is assumed all clocks in clk_bulk_data are optional. 0410 * 0411 * Returns 0 if all clocks specified in clk_bulk_data table are obtained 0412 * successfully or for any clk there was no clk provider available, otherwise 0413 * returns valid IS_ERR() condition containing errno. 0414 * The implementation uses @dev and @clk_bulk_data.id to determine the 0415 * clock consumer, and thereby the clock producer. 0416 * The clock returned is stored in each @clk_bulk_data.clk field. 0417 * 0418 * Drivers must assume that the clock source is not enabled. 0419 * 0420 * clk_bulk_get should not be called from within interrupt context. 0421 */ 0422 int __must_check devm_clk_bulk_get_optional(struct device *dev, int num_clks, 0423 struct clk_bulk_data *clks); 0424 /** 0425 * devm_clk_bulk_get_all - managed get multiple clk consumers 0426 * @dev: device for clock "consumer" 0427 * @clks: pointer to the clk_bulk_data table of consumer 0428 * 0429 * Returns a positive value for the number of clocks obtained while the 0430 * clock references are stored in the clk_bulk_data table in @clks field. 0431 * Returns 0 if there're none and a negative value if something failed. 0432 * 0433 * This helper function allows drivers to get several clk 0434 * consumers in one operation with management, the clks will 0435 * automatically be freed when the device is unbound. 0436 */ 0437 0438 int __must_check devm_clk_bulk_get_all(struct device *dev, 0439 struct clk_bulk_data **clks); 0440 0441 /** 0442 * devm_clk_get - lookup and obtain a managed reference to a clock producer. 0443 * @dev: device for clock "consumer" 0444 * @id: clock consumer ID 0445 * 0446 * Context: May sleep. 0447 * 0448 * Return: a struct clk corresponding to the clock producer, or 0449 * valid IS_ERR() condition containing errno. The implementation 0450 * uses @dev and @id to determine the clock consumer, and thereby 0451 * the clock producer. (IOW, @id may be identical strings, but 0452 * clk_get may return different clock producers depending on @dev.) 0453 * 0454 * Drivers must assume that the clock source is neither prepared nor 0455 * enabled. 0456 * 0457 * The clock will automatically be freed when the device is unbound 0458 * from the bus. 0459 */ 0460 struct clk *devm_clk_get(struct device *dev, const char *id); 0461 0462 /** 0463 * devm_clk_get_prepared - devm_clk_get() + clk_prepare() 0464 * @dev: device for clock "consumer" 0465 * @id: clock consumer ID 0466 * 0467 * Context: May sleep. 0468 * 0469 * Return: a struct clk corresponding to the clock producer, or 0470 * valid IS_ERR() condition containing errno. The implementation 0471 * uses @dev and @id to determine the clock consumer, and thereby 0472 * the clock producer. (IOW, @id may be identical strings, but 0473 * clk_get may return different clock producers depending on @dev.) 0474 * 0475 * The returned clk (if valid) is prepared. Drivers must however assume 0476 * that the clock is not enabled. 0477 * 0478 * The clock will automatically be unprepared and freed when the device 0479 * is unbound from the bus. 0480 */ 0481 struct clk *devm_clk_get_prepared(struct device *dev, const char *id); 0482 0483 /** 0484 * devm_clk_get_enabled - devm_clk_get() + clk_prepare_enable() 0485 * @dev: device for clock "consumer" 0486 * @id: clock consumer ID 0487 * 0488 * Context: May sleep. 0489 * 0490 * Return: a struct clk corresponding to the clock producer, or 0491 * valid IS_ERR() condition containing errno. The implementation 0492 * uses @dev and @id to determine the clock consumer, and thereby 0493 * the clock producer. (IOW, @id may be identical strings, but 0494 * clk_get may return different clock producers depending on @dev.) 0495 * 0496 * The returned clk (if valid) is prepared and enabled. 0497 * 0498 * The clock will automatically be disabled, unprepared and freed 0499 * when the device is unbound from the bus. 0500 */ 0501 struct clk *devm_clk_get_enabled(struct device *dev, const char *id); 0502 0503 /** 0504 * devm_clk_get_optional - lookup and obtain a managed reference to an optional 0505 * clock producer. 0506 * @dev: device for clock "consumer" 0507 * @id: clock consumer ID 0508 * 0509 * Context: May sleep. 0510 * 0511 * Return: a struct clk corresponding to the clock producer, or 0512 * valid IS_ERR() condition containing errno. The implementation 0513 * uses @dev and @id to determine the clock consumer, and thereby 0514 * the clock producer. If no such clk is found, it returns NULL 0515 * which serves as a dummy clk. That's the only difference compared 0516 * to devm_clk_get(). 0517 * 0518 * Drivers must assume that the clock source is neither prepared nor 0519 * enabled. 0520 * 0521 * The clock will automatically be freed when the device is unbound 0522 * from the bus. 0523 */ 0524 struct clk *devm_clk_get_optional(struct device *dev, const char *id); 0525 0526 /** 0527 * devm_clk_get_optional_prepared - devm_clk_get_optional() + clk_prepare() 0528 * @dev: device for clock "consumer" 0529 * @id: clock consumer ID 0530 * 0531 * Context: May sleep. 0532 * 0533 * Return: a struct clk corresponding to the clock producer, or 0534 * valid IS_ERR() condition containing errno. The implementation 0535 * uses @dev and @id to determine the clock consumer, and thereby 0536 * the clock producer. If no such clk is found, it returns NULL 0537 * which serves as a dummy clk. That's the only difference compared 0538 * to devm_clk_get_prepared(). 0539 * 0540 * The returned clk (if valid) is prepared. Drivers must however 0541 * assume that the clock is not enabled. 0542 * 0543 * The clock will automatically be unprepared and freed when the 0544 * device is unbound from the bus. 0545 */ 0546 struct clk *devm_clk_get_optional_prepared(struct device *dev, const char *id); 0547 0548 /** 0549 * devm_clk_get_optional_enabled - devm_clk_get_optional() + 0550 * clk_prepare_enable() 0551 * @dev: device for clock "consumer" 0552 * @id: clock consumer ID 0553 * 0554 * Context: May sleep. 0555 * 0556 * Return: a struct clk corresponding to the clock producer, or 0557 * valid IS_ERR() condition containing errno. The implementation 0558 * uses @dev and @id to determine the clock consumer, and thereby 0559 * the clock producer. If no such clk is found, it returns NULL 0560 * which serves as a dummy clk. That's the only difference compared 0561 * to devm_clk_get_enabled(). 0562 * 0563 * The returned clk (if valid) is prepared and enabled. 0564 * 0565 * The clock will automatically be disabled, unprepared and freed 0566 * when the device is unbound from the bus. 0567 */ 0568 struct clk *devm_clk_get_optional_enabled(struct device *dev, const char *id); 0569 0570 /** 0571 * devm_get_clk_from_child - lookup and obtain a managed reference to a 0572 * clock producer from child node. 0573 * @dev: device for clock "consumer" 0574 * @np: pointer to clock consumer node 0575 * @con_id: clock consumer ID 0576 * 0577 * This function parses the clocks, and uses them to look up the 0578 * struct clk from the registered list of clock providers by using 0579 * @np and @con_id 0580 * 0581 * The clock will automatically be freed when the device is unbound 0582 * from the bus. 0583 */ 0584 struct clk *devm_get_clk_from_child(struct device *dev, 0585 struct device_node *np, const char *con_id); 0586 /** 0587 * clk_rate_exclusive_get - get exclusivity over the rate control of a 0588 * producer 0589 * @clk: clock source 0590 * 0591 * This function allows drivers to get exclusive control over the rate of a 0592 * provider. It prevents any other consumer to execute, even indirectly, 0593 * opereation which could alter the rate of the provider or cause glitches 0594 * 0595 * If exlusivity is claimed more than once on clock, even by the same driver, 0596 * the rate effectively gets locked as exclusivity can't be preempted. 0597 * 0598 * Must not be called from within atomic context. 0599 * 0600 * Returns success (0) or negative errno. 0601 */ 0602 int clk_rate_exclusive_get(struct clk *clk); 0603 0604 /** 0605 * clk_rate_exclusive_put - release exclusivity over the rate control of a 0606 * producer 0607 * @clk: clock source 0608 * 0609 * This function allows drivers to release the exclusivity it previously got 0610 * from clk_rate_exclusive_get() 0611 * 0612 * The caller must balance the number of clk_rate_exclusive_get() and 0613 * clk_rate_exclusive_put() calls. 0614 * 0615 * Must not be called from within atomic context. 0616 */ 0617 void clk_rate_exclusive_put(struct clk *clk); 0618 0619 /** 0620 * clk_enable - inform the system when the clock source should be running. 0621 * @clk: clock source 0622 * 0623 * If the clock can not be enabled/disabled, this should return success. 0624 * 0625 * May be called from atomic contexts. 0626 * 0627 * Returns success (0) or negative errno. 0628 */ 0629 int clk_enable(struct clk *clk); 0630 0631 /** 0632 * clk_bulk_enable - inform the system when the set of clks should be running. 0633 * @num_clks: the number of clk_bulk_data 0634 * @clks: the clk_bulk_data table of consumer 0635 * 0636 * May be called from atomic contexts. 0637 * 0638 * Returns success (0) or negative errno. 0639 */ 0640 int __must_check clk_bulk_enable(int num_clks, 0641 const struct clk_bulk_data *clks); 0642 0643 /** 0644 * clk_disable - inform the system when the clock source is no longer required. 0645 * @clk: clock source 0646 * 0647 * Inform the system that a clock source is no longer required by 0648 * a driver and may be shut down. 0649 * 0650 * May be called from atomic contexts. 0651 * 0652 * Implementation detail: if the clock source is shared between 0653 * multiple drivers, clk_enable() calls must be balanced by the 0654 * same number of clk_disable() calls for the clock source to be 0655 * disabled. 0656 */ 0657 void clk_disable(struct clk *clk); 0658 0659 /** 0660 * clk_bulk_disable - inform the system when the set of clks is no 0661 * longer required. 0662 * @num_clks: the number of clk_bulk_data 0663 * @clks: the clk_bulk_data table of consumer 0664 * 0665 * Inform the system that a set of clks is no longer required by 0666 * a driver and may be shut down. 0667 * 0668 * May be called from atomic contexts. 0669 * 0670 * Implementation detail: if the set of clks is shared between 0671 * multiple drivers, clk_bulk_enable() calls must be balanced by the 0672 * same number of clk_bulk_disable() calls for the clock source to be 0673 * disabled. 0674 */ 0675 void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks); 0676 0677 /** 0678 * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. 0679 * This is only valid once the clock source has been enabled. 0680 * @clk: clock source 0681 */ 0682 unsigned long clk_get_rate(struct clk *clk); 0683 0684 /** 0685 * clk_put - "free" the clock source 0686 * @clk: clock source 0687 * 0688 * Note: drivers must ensure that all clk_enable calls made on this 0689 * clock source are balanced by clk_disable calls prior to calling 0690 * this function. 0691 * 0692 * clk_put should not be called from within interrupt context. 0693 */ 0694 void clk_put(struct clk *clk); 0695 0696 /** 0697 * clk_bulk_put - "free" the clock source 0698 * @num_clks: the number of clk_bulk_data 0699 * @clks: the clk_bulk_data table of consumer 0700 * 0701 * Note: drivers must ensure that all clk_bulk_enable calls made on this 0702 * clock source are balanced by clk_bulk_disable calls prior to calling 0703 * this function. 0704 * 0705 * clk_bulk_put should not be called from within interrupt context. 0706 */ 0707 void clk_bulk_put(int num_clks, struct clk_bulk_data *clks); 0708 0709 /** 0710 * clk_bulk_put_all - "free" all the clock source 0711 * @num_clks: the number of clk_bulk_data 0712 * @clks: the clk_bulk_data table of consumer 0713 * 0714 * Note: drivers must ensure that all clk_bulk_enable calls made on this 0715 * clock source are balanced by clk_bulk_disable calls prior to calling 0716 * this function. 0717 * 0718 * clk_bulk_put_all should not be called from within interrupt context. 0719 */ 0720 void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks); 0721 0722 /** 0723 * devm_clk_put - "free" a managed clock source 0724 * @dev: device used to acquire the clock 0725 * @clk: clock source acquired with devm_clk_get() 0726 * 0727 * Note: drivers must ensure that all clk_enable calls made on this 0728 * clock source are balanced by clk_disable calls prior to calling 0729 * this function. 0730 * 0731 * clk_put should not be called from within interrupt context. 0732 */ 0733 void devm_clk_put(struct device *dev, struct clk *clk); 0734 0735 /* 0736 * The remaining APIs are optional for machine class support. 0737 */ 0738 0739 0740 /** 0741 * clk_round_rate - adjust a rate to the exact rate a clock can provide 0742 * @clk: clock source 0743 * @rate: desired clock rate in Hz 0744 * 0745 * This answers the question "if I were to pass @rate to clk_set_rate(), 0746 * what clock rate would I end up with?" without changing the hardware 0747 * in any way. In other words: 0748 * 0749 * rate = clk_round_rate(clk, r); 0750 * 0751 * and: 0752 * 0753 * clk_set_rate(clk, r); 0754 * rate = clk_get_rate(clk); 0755 * 0756 * are equivalent except the former does not modify the clock hardware 0757 * in any way. 0758 * 0759 * Returns rounded clock rate in Hz, or negative errno. 0760 */ 0761 long clk_round_rate(struct clk *clk, unsigned long rate); 0762 0763 /** 0764 * clk_set_rate - set the clock rate for a clock source 0765 * @clk: clock source 0766 * @rate: desired clock rate in Hz 0767 * 0768 * Updating the rate starts at the top-most affected clock and then 0769 * walks the tree down to the bottom-most clock that needs updating. 0770 * 0771 * Returns success (0) or negative errno. 0772 */ 0773 int clk_set_rate(struct clk *clk, unsigned long rate); 0774 0775 /** 0776 * clk_set_rate_exclusive- set the clock rate and claim exclusivity over 0777 * clock source 0778 * @clk: clock source 0779 * @rate: desired clock rate in Hz 0780 * 0781 * This helper function allows drivers to atomically set the rate of a producer 0782 * and claim exclusivity over the rate control of the producer. 0783 * 0784 * It is essentially a combination of clk_set_rate() and 0785 * clk_rate_exclusite_get(). Caller must balance this call with a call to 0786 * clk_rate_exclusive_put() 0787 * 0788 * Returns success (0) or negative errno. 0789 */ 0790 int clk_set_rate_exclusive(struct clk *clk, unsigned long rate); 0791 0792 /** 0793 * clk_has_parent - check if a clock is a possible parent for another 0794 * @clk: clock source 0795 * @parent: parent clock source 0796 * 0797 * This function can be used in drivers that need to check that a clock can be 0798 * the parent of another without actually changing the parent. 0799 * 0800 * Returns true if @parent is a possible parent for @clk, false otherwise. 0801 */ 0802 bool clk_has_parent(struct clk *clk, struct clk *parent); 0803 0804 /** 0805 * clk_set_rate_range - set a rate range for a clock source 0806 * @clk: clock source 0807 * @min: desired minimum clock rate in Hz, inclusive 0808 * @max: desired maximum clock rate in Hz, inclusive 0809 * 0810 * Returns success (0) or negative errno. 0811 */ 0812 int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max); 0813 0814 /** 0815 * clk_set_min_rate - set a minimum clock rate for a clock source 0816 * @clk: clock source 0817 * @rate: desired minimum clock rate in Hz, inclusive 0818 * 0819 * Returns success (0) or negative errno. 0820 */ 0821 int clk_set_min_rate(struct clk *clk, unsigned long rate); 0822 0823 /** 0824 * clk_set_max_rate - set a maximum clock rate for a clock source 0825 * @clk: clock source 0826 * @rate: desired maximum clock rate in Hz, inclusive 0827 * 0828 * Returns success (0) or negative errno. 0829 */ 0830 int clk_set_max_rate(struct clk *clk, unsigned long rate); 0831 0832 /** 0833 * clk_set_parent - set the parent clock source for this clock 0834 * @clk: clock source 0835 * @parent: parent clock source 0836 * 0837 * Returns success (0) or negative errno. 0838 */ 0839 int clk_set_parent(struct clk *clk, struct clk *parent); 0840 0841 /** 0842 * clk_get_parent - get the parent clock source for this clock 0843 * @clk: clock source 0844 * 0845 * Returns struct clk corresponding to parent clock source, or 0846 * valid IS_ERR() condition containing errno. 0847 */ 0848 struct clk *clk_get_parent(struct clk *clk); 0849 0850 /** 0851 * clk_get_sys - get a clock based upon the device name 0852 * @dev_id: device name 0853 * @con_id: connection ID 0854 * 0855 * Returns a struct clk corresponding to the clock producer, or 0856 * valid IS_ERR() condition containing errno. The implementation 0857 * uses @dev_id and @con_id to determine the clock consumer, and 0858 * thereby the clock producer. In contrast to clk_get() this function 0859 * takes the device name instead of the device itself for identification. 0860 * 0861 * Drivers must assume that the clock source is not enabled. 0862 * 0863 * clk_get_sys should not be called from within interrupt context. 0864 */ 0865 struct clk *clk_get_sys(const char *dev_id, const char *con_id); 0866 0867 /** 0868 * clk_save_context - save clock context for poweroff 0869 * 0870 * Saves the context of the clock register for powerstates in which the 0871 * contents of the registers will be lost. Occurs deep within the suspend 0872 * code so locking is not necessary. 0873 */ 0874 int clk_save_context(void); 0875 0876 /** 0877 * clk_restore_context - restore clock context after poweroff 0878 * 0879 * This occurs with all clocks enabled. Occurs deep within the resume code 0880 * so locking is not necessary. 0881 */ 0882 void clk_restore_context(void); 0883 0884 #else /* !CONFIG_HAVE_CLK */ 0885 0886 static inline struct clk *clk_get(struct device *dev, const char *id) 0887 { 0888 return NULL; 0889 } 0890 0891 static inline int __must_check clk_bulk_get(struct device *dev, int num_clks, 0892 struct clk_bulk_data *clks) 0893 { 0894 return 0; 0895 } 0896 0897 static inline int __must_check clk_bulk_get_optional(struct device *dev, 0898 int num_clks, struct clk_bulk_data *clks) 0899 { 0900 return 0; 0901 } 0902 0903 static inline int __must_check clk_bulk_get_all(struct device *dev, 0904 struct clk_bulk_data **clks) 0905 { 0906 return 0; 0907 } 0908 0909 static inline struct clk *devm_clk_get(struct device *dev, const char *id) 0910 { 0911 return NULL; 0912 } 0913 0914 static inline struct clk *devm_clk_get_prepared(struct device *dev, 0915 const char *id) 0916 { 0917 return NULL; 0918 } 0919 0920 static inline struct clk *devm_clk_get_enabled(struct device *dev, 0921 const char *id) 0922 { 0923 return NULL; 0924 } 0925 0926 static inline struct clk *devm_clk_get_optional(struct device *dev, 0927 const char *id) 0928 { 0929 return NULL; 0930 } 0931 0932 static inline struct clk *devm_clk_get_optional_prepared(struct device *dev, 0933 const char *id) 0934 { 0935 return NULL; 0936 } 0937 0938 static inline struct clk *devm_clk_get_optional_enabled(struct device *dev, 0939 const char *id) 0940 { 0941 return NULL; 0942 } 0943 0944 static inline int __must_check devm_clk_bulk_get(struct device *dev, int num_clks, 0945 struct clk_bulk_data *clks) 0946 { 0947 return 0; 0948 } 0949 0950 static inline int __must_check devm_clk_bulk_get_optional(struct device *dev, 0951 int num_clks, struct clk_bulk_data *clks) 0952 { 0953 return 0; 0954 } 0955 0956 static inline int __must_check devm_clk_bulk_get_all(struct device *dev, 0957 struct clk_bulk_data **clks) 0958 { 0959 0960 return 0; 0961 } 0962 0963 static inline struct clk *devm_get_clk_from_child(struct device *dev, 0964 struct device_node *np, const char *con_id) 0965 { 0966 return NULL; 0967 } 0968 0969 static inline void clk_put(struct clk *clk) {} 0970 0971 static inline void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) {} 0972 0973 static inline void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks) {} 0974 0975 static inline void devm_clk_put(struct device *dev, struct clk *clk) {} 0976 0977 0978 static inline int clk_rate_exclusive_get(struct clk *clk) 0979 { 0980 return 0; 0981 } 0982 0983 static inline void clk_rate_exclusive_put(struct clk *clk) {} 0984 0985 static inline int clk_enable(struct clk *clk) 0986 { 0987 return 0; 0988 } 0989 0990 static inline int __must_check clk_bulk_enable(int num_clks, 0991 const struct clk_bulk_data *clks) 0992 { 0993 return 0; 0994 } 0995 0996 static inline void clk_disable(struct clk *clk) {} 0997 0998 0999 static inline void clk_bulk_disable(int num_clks, 1000 const struct clk_bulk_data *clks) {} 1001 1002 static inline unsigned long clk_get_rate(struct clk *clk) 1003 { 1004 return 0; 1005 } 1006 1007 static inline int clk_set_rate(struct clk *clk, unsigned long rate) 1008 { 1009 return 0; 1010 } 1011 1012 static inline int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) 1013 { 1014 return 0; 1015 } 1016 1017 static inline long clk_round_rate(struct clk *clk, unsigned long rate) 1018 { 1019 return 0; 1020 } 1021 1022 static inline bool clk_has_parent(struct clk *clk, struct clk *parent) 1023 { 1024 return true; 1025 } 1026 1027 static inline int clk_set_rate_range(struct clk *clk, unsigned long min, 1028 unsigned long max) 1029 { 1030 return 0; 1031 } 1032 1033 static inline int clk_set_min_rate(struct clk *clk, unsigned long rate) 1034 { 1035 return 0; 1036 } 1037 1038 static inline int clk_set_max_rate(struct clk *clk, unsigned long rate) 1039 { 1040 return 0; 1041 } 1042 1043 static inline int clk_set_parent(struct clk *clk, struct clk *parent) 1044 { 1045 return 0; 1046 } 1047 1048 static inline struct clk *clk_get_parent(struct clk *clk) 1049 { 1050 return NULL; 1051 } 1052 1053 static inline struct clk *clk_get_sys(const char *dev_id, const char *con_id) 1054 { 1055 return NULL; 1056 } 1057 1058 static inline int clk_save_context(void) 1059 { 1060 return 0; 1061 } 1062 1063 static inline void clk_restore_context(void) {} 1064 1065 #endif 1066 1067 /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */ 1068 static inline int clk_prepare_enable(struct clk *clk) 1069 { 1070 int ret; 1071 1072 ret = clk_prepare(clk); 1073 if (ret) 1074 return ret; 1075 ret = clk_enable(clk); 1076 if (ret) 1077 clk_unprepare(clk); 1078 1079 return ret; 1080 } 1081 1082 /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */ 1083 static inline void clk_disable_unprepare(struct clk *clk) 1084 { 1085 clk_disable(clk); 1086 clk_unprepare(clk); 1087 } 1088 1089 static inline int __must_check 1090 clk_bulk_prepare_enable(int num_clks, const struct clk_bulk_data *clks) 1091 { 1092 int ret; 1093 1094 ret = clk_bulk_prepare(num_clks, clks); 1095 if (ret) 1096 return ret; 1097 ret = clk_bulk_enable(num_clks, clks); 1098 if (ret) 1099 clk_bulk_unprepare(num_clks, clks); 1100 1101 return ret; 1102 } 1103 1104 static inline void clk_bulk_disable_unprepare(int num_clks, 1105 const struct clk_bulk_data *clks) 1106 { 1107 clk_bulk_disable(num_clks, clks); 1108 clk_bulk_unprepare(num_clks, clks); 1109 } 1110 1111 /** 1112 * clk_drop_range - Reset any range set on that clock 1113 * @clk: clock source 1114 * 1115 * Returns success (0) or negative errno. 1116 */ 1117 static inline int clk_drop_range(struct clk *clk) 1118 { 1119 return clk_set_rate_range(clk, 0, ULONG_MAX); 1120 } 1121 1122 /** 1123 * clk_get_optional - lookup and obtain a reference to an optional clock 1124 * producer. 1125 * @dev: device for clock "consumer" 1126 * @id: clock consumer ID 1127 * 1128 * Behaves the same as clk_get() except where there is no clock producer. In 1129 * this case, instead of returning -ENOENT, the function returns NULL. 1130 */ 1131 static inline struct clk *clk_get_optional(struct device *dev, const char *id) 1132 { 1133 struct clk *clk = clk_get(dev, id); 1134 1135 if (clk == ERR_PTR(-ENOENT)) 1136 return NULL; 1137 1138 return clk; 1139 } 1140 1141 #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) 1142 struct clk *of_clk_get(struct device_node *np, int index); 1143 struct clk *of_clk_get_by_name(struct device_node *np, const char *name); 1144 struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec); 1145 #else 1146 static inline struct clk *of_clk_get(struct device_node *np, int index) 1147 { 1148 return ERR_PTR(-ENOENT); 1149 } 1150 static inline struct clk *of_clk_get_by_name(struct device_node *np, 1151 const char *name) 1152 { 1153 return ERR_PTR(-ENOENT); 1154 } 1155 static inline struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec) 1156 { 1157 return ERR_PTR(-ENOENT); 1158 } 1159 #endif 1160 1161 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |