clk-provider.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /*
  2. * linux/include/linux/clk-provider.h
  3. *
  4. * Copyright (c) 2010-2011 Jeremy Kerr <jeremy.kerr@canonical.com>
  5. * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef __LINUX_CLK_PROVIDER_H
  12. #define __LINUX_CLK_PROVIDER_H
  13. #include <linux/clk.h>
  14. #include <linux/io.h>
  15. #include <linux/of.h>
  16. #ifdef CONFIG_COMMON_CLK
  17. /*
  18. * flags used across common struct clk. these flags should only affect the
  19. * top-level framework. custom flags for dealing with hardware specifics
  20. * belong in struct clk_foo
  21. */
  22. #define CLK_SET_RATE_GATE BIT(0) /* must be gated across rate change */
  23. #define CLK_SET_PARENT_GATE BIT(1) /* must be gated across re-parent */
  24. #define CLK_SET_RATE_PARENT BIT(2) /* propagate rate change up one level */
  25. #define CLK_IGNORE_UNUSED BIT(3) /* do not gate even if unused */
  26. #define CLK_IS_ROOT BIT(4) /* root clk, has no parent */
  27. #define CLK_IS_BASIC BIT(5) /* Basic clk, can't do a to_clk_foo() */
  28. #define CLK_GET_RATE_NOCACHE BIT(6) /* do not use the cached clk rate */
  29. #define CLK_SET_RATE_NO_REPARENT BIT(7) /* don't re-parent on rate change */
  30. #define CLK_GET_ACCURACY_NOCACHE BIT(8) /* do not use the cached clk accuracy */
  31. struct clk_hw;
  32. struct dentry;
  33. /**
  34. * struct clk_ops - Callback operations for hardware clocks; these are to
  35. * be provided by the clock implementation, and will be called by drivers
  36. * through the clk_* api.
  37. *
  38. * @prepare: Prepare the clock for enabling. This must not return until
  39. * the clock is fully prepared, and it's safe to call clk_enable.
  40. * This callback is intended to allow clock implementations to
  41. * do any initialisation that may sleep. Called with
  42. * prepare_lock held.
  43. *
  44. * @unprepare: Release the clock from its prepared state. This will typically
  45. * undo any work done in the @prepare callback. Called with
  46. * prepare_lock held.
  47. *
  48. * @is_prepared: Queries the hardware to determine if the clock is prepared.
  49. * This function is allowed to sleep. Optional, if this op is not
  50. * set then the prepare count will be used.
  51. *
  52. * @unprepare_unused: Unprepare the clock atomically. Only called from
  53. * clk_disable_unused for prepare clocks with special needs.
  54. * Called with prepare mutex held. This function may sleep.
  55. *
  56. * @enable: Enable the clock atomically. This must not return until the
  57. * clock is generating a valid clock signal, usable by consumer
  58. * devices. Called with enable_lock held. This function must not
  59. * sleep.
  60. *
  61. * @disable: Disable the clock atomically. Called with enable_lock held.
  62. * This function must not sleep.
  63. *
  64. * @is_enabled: Queries the hardware to determine if the clock is enabled.
  65. * This function must not sleep. Optional, if this op is not
  66. * set then the enable count will be used.
  67. *
  68. * @disable_unused: Disable the clock atomically. Only called from
  69. * clk_disable_unused for gate clocks with special needs.
  70. * Called with enable_lock held. This function must not
  71. * sleep.
  72. *
  73. * @recalc_rate Recalculate the rate of this clock, by querying hardware. The
  74. * parent rate is an input parameter. It is up to the caller to
  75. * ensure that the prepare_mutex is held across this call.
  76. * Returns the calculated rate. Optional, but recommended - if
  77. * this op is not set then clock rate will be initialized to 0.
  78. *
  79. * @round_rate: Given a target rate as input, returns the closest rate actually
  80. * supported by the clock. The parent rate is an input/output
  81. * parameter.
  82. *
  83. * @determine_rate: Given a target rate as input, returns the closest rate
  84. * actually supported by the clock, and optionally the parent clock
  85. * that should be used to provide the clock rate.
  86. *
  87. * @set_parent: Change the input source of this clock; for clocks with multiple
  88. * possible parents specify a new parent by passing in the index
  89. * as a u8 corresponding to the parent in either the .parent_names
  90. * or .parents arrays. This function in affect translates an
  91. * array index into the value programmed into the hardware.
  92. * Returns 0 on success, -EERROR otherwise.
  93. *
  94. * @get_parent: Queries the hardware to determine the parent of a clock. The
  95. * return value is a u8 which specifies the index corresponding to
  96. * the parent clock. This index can be applied to either the
  97. * .parent_names or .parents arrays. In short, this function
  98. * translates the parent value read from hardware into an array
  99. * index. Currently only called when the clock is initialized by
  100. * __clk_init. This callback is mandatory for clocks with
  101. * multiple parents. It is optional (and unnecessary) for clocks
  102. * with 0 or 1 parents.
  103. *
  104. * @set_rate: Change the rate of this clock. The requested rate is specified
  105. * by the second argument, which should typically be the return
  106. * of .round_rate call. The third argument gives the parent rate
  107. * which is likely helpful for most .set_rate implementation.
  108. * Returns 0 on success, -EERROR otherwise.
  109. *
  110. * @set_rate_and_parent: Change the rate and the parent of this clock. The
  111. * requested rate is specified by the second argument, which
  112. * should typically be the return of .round_rate call. The
  113. * third argument gives the parent rate which is likely helpful
  114. * for most .set_rate_and_parent implementation. The fourth
  115. * argument gives the parent index. This callback is optional (and
  116. * unnecessary) for clocks with 0 or 1 parents as well as
  117. * for clocks that can tolerate switching the rate and the parent
  118. * separately via calls to .set_parent and .set_rate.
  119. * Returns 0 on success, -EERROR otherwise.
  120. *
  121. * @recalc_accuracy: Recalculate the accuracy of this clock. The clock accuracy
  122. * is expressed in ppb (parts per billion). The parent accuracy is
  123. * an input parameter.
  124. * Returns the calculated accuracy. Optional - if this op is not
  125. * set then clock accuracy will be initialized to parent accuracy
  126. * or 0 (perfect clock) if clock has no parent.
  127. *
  128. * @get_phase: Queries the hardware to get the current phase of a clock.
  129. * Returned values are 0-359 degrees on success, negative
  130. * error codes on failure.
  131. *
  132. * @set_phase: Shift the phase this clock signal in degrees specified
  133. * by the second argument. Valid values for degrees are
  134. * 0-359. Return 0 on success, otherwise -EERROR.
  135. *
  136. * @init: Perform platform-specific initialization magic.
  137. * This is not not used by any of the basic clock types.
  138. * Please consider other ways of solving initialization problems
  139. * before using this callback, as its use is discouraged.
  140. *
  141. * @debug_init: Set up type-specific debugfs entries for this clock. This
  142. * is called once, after the debugfs directory entry for this
  143. * clock has been created. The dentry pointer representing that
  144. * directory is provided as an argument. Called with
  145. * prepare_lock held. Returns 0 on success, -EERROR otherwise.
  146. *
  147. *
  148. * The clk_enable/clk_disable and clk_prepare/clk_unprepare pairs allow
  149. * implementations to split any work between atomic (enable) and sleepable
  150. * (prepare) contexts. If enabling a clock requires code that might sleep,
  151. * this must be done in clk_prepare. Clock enable code that will never be
  152. * called in a sleepable context may be implemented in clk_enable.
  153. *
  154. * Typically, drivers will call clk_prepare when a clock may be needed later
  155. * (eg. when a device is opened), and clk_enable when the clock is actually
  156. * required (eg. from an interrupt). Note that clk_prepare MUST have been
  157. * called before clk_enable.
  158. */
  159. struct clk_ops {
  160. int (*prepare)(struct clk_hw *hw);
  161. void (*unprepare)(struct clk_hw *hw);
  162. int (*is_prepared)(struct clk_hw *hw);
  163. void (*unprepare_unused)(struct clk_hw *hw);
  164. int (*enable)(struct clk_hw *hw);
  165. void (*disable)(struct clk_hw *hw);
  166. int (*is_enabled)(struct clk_hw *hw);
  167. void (*disable_unused)(struct clk_hw *hw);
  168. unsigned long (*recalc_rate)(struct clk_hw *hw,
  169. unsigned long parent_rate);
  170. long (*round_rate)(struct clk_hw *hw, unsigned long rate,
  171. unsigned long *parent_rate);
  172. long (*determine_rate)(struct clk_hw *hw, unsigned long rate,
  173. unsigned long *best_parent_rate,
  174. struct clk **best_parent_clk);
  175. int (*set_parent)(struct clk_hw *hw, u8 index);
  176. u8 (*get_parent)(struct clk_hw *hw);
  177. int (*set_rate)(struct clk_hw *hw, unsigned long rate,
  178. unsigned long parent_rate);
  179. int (*set_rate_and_parent)(struct clk_hw *hw,
  180. unsigned long rate,
  181. unsigned long parent_rate, u8 index);
  182. unsigned long (*recalc_accuracy)(struct clk_hw *hw,
  183. unsigned long parent_accuracy);
  184. int (*get_phase)(struct clk_hw *hw);
  185. int (*set_phase)(struct clk_hw *hw, int degrees);
  186. void (*init)(struct clk_hw *hw);
  187. int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
  188. };
  189. /**
  190. * struct clk_init_data - holds init data that's common to all clocks and is
  191. * shared between the clock provider and the common clock framework.
  192. *
  193. * @name: clock name
  194. * @ops: operations this clock supports
  195. * @parent_names: array of string names for all possible parents
  196. * @num_parents: number of possible parents
  197. * @flags: framework-level hints and quirks
  198. */
  199. struct clk_init_data {
  200. const char *name;
  201. const struct clk_ops *ops;
  202. const char **parent_names;
  203. u8 num_parents;
  204. unsigned long flags;
  205. };
  206. /**
  207. * struct clk_hw - handle for traversing from a struct clk to its corresponding
  208. * hardware-specific structure. struct clk_hw should be declared within struct
  209. * clk_foo and then referenced by the struct clk instance that uses struct
  210. * clk_foo's clk_ops
  211. *
  212. * @clk: pointer to the struct clk instance that points back to this struct
  213. * clk_hw instance
  214. *
  215. * @init: pointer to struct clk_init_data that contains the init data shared
  216. * with the common clock framework.
  217. */
  218. struct clk_hw {
  219. struct clk *clk;
  220. const struct clk_init_data *init;
  221. };
  222. /*
  223. * DOC: Basic clock implementations common to many platforms
  224. *
  225. * Each basic clock hardware type is comprised of a structure describing the
  226. * clock hardware, implementations of the relevant callbacks in struct clk_ops,
  227. * unique flags for that hardware type, a registration function and an
  228. * alternative macro for static initialization
  229. */
  230. /**
  231. * struct clk_fixed_rate - fixed-rate clock
  232. * @hw: handle between common and hardware-specific interfaces
  233. * @fixed_rate: constant frequency of clock
  234. */
  235. struct clk_fixed_rate {
  236. struct clk_hw hw;
  237. unsigned long fixed_rate;
  238. unsigned long fixed_accuracy;
  239. u8 flags;
  240. };
  241. extern const struct clk_ops clk_fixed_rate_ops;
  242. struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
  243. const char *parent_name, unsigned long flags,
  244. unsigned long fixed_rate);
  245. struct clk *clk_register_fixed_rate_with_accuracy(struct device *dev,
  246. const char *name, const char *parent_name, unsigned long flags,
  247. unsigned long fixed_rate, unsigned long fixed_accuracy);
  248. void of_fixed_clk_setup(struct device_node *np);
  249. /**
  250. * struct clk_gate - gating clock
  251. *
  252. * @hw: handle between common and hardware-specific interfaces
  253. * @reg: register controlling gate
  254. * @bit_idx: single bit controlling gate
  255. * @flags: hardware-specific flags
  256. * @lock: register lock
  257. *
  258. * Clock which can gate its output. Implements .enable & .disable
  259. *
  260. * Flags:
  261. * CLK_GATE_SET_TO_DISABLE - by default this clock sets the bit at bit_idx to
  262. * enable the clock. Setting this flag does the opposite: setting the bit
  263. * disable the clock and clearing it enables the clock
  264. * CLK_GATE_HIWORD_MASK - The gate settings are only in lower 16-bit
  265. * of this register, and mask of gate bits are in higher 16-bit of this
  266. * register. While setting the gate bits, higher 16-bit should also be
  267. * updated to indicate changing gate bits.
  268. */
  269. struct clk_gate {
  270. struct clk_hw hw;
  271. void __iomem *reg;
  272. u8 bit_idx;
  273. u8 flags;
  274. spinlock_t *lock;
  275. };
  276. #define CLK_GATE_SET_TO_DISABLE BIT(0)
  277. #define CLK_GATE_HIWORD_MASK BIT(1)
  278. extern const struct clk_ops clk_gate_ops;
  279. struct clk *clk_register_gate(struct device *dev, const char *name,
  280. const char *parent_name, unsigned long flags,
  281. void __iomem *reg, u8 bit_idx,
  282. u8 clk_gate_flags, spinlock_t *lock);
  283. struct clk_div_table {
  284. unsigned int val;
  285. unsigned int div;
  286. };
  287. /**
  288. * struct clk_divider - adjustable divider clock
  289. *
  290. * @hw: handle between common and hardware-specific interfaces
  291. * @reg: register containing the divider
  292. * @shift: shift to the divider bit field
  293. * @width: width of the divider bit field
  294. * @table: array of value/divider pairs, last entry should have div = 0
  295. * @lock: register lock
  296. *
  297. * Clock with an adjustable divider affecting its output frequency. Implements
  298. * .recalc_rate, .set_rate and .round_rate
  299. *
  300. * Flags:
  301. * CLK_DIVIDER_ONE_BASED - by default the divisor is the value read from the
  302. * register plus one. If CLK_DIVIDER_ONE_BASED is set then the divider is
  303. * the raw value read from the register, with the value of zero considered
  304. * invalid, unless CLK_DIVIDER_ALLOW_ZERO is set.
  305. * CLK_DIVIDER_POWER_OF_TWO - clock divisor is 2 raised to the value read from
  306. * the hardware register
  307. * CLK_DIVIDER_ALLOW_ZERO - Allow zero divisors. For dividers which have
  308. * CLK_DIVIDER_ONE_BASED set, it is possible to end up with a zero divisor.
  309. * Some hardware implementations gracefully handle this case and allow a
  310. * zero divisor by not modifying their input clock
  311. * (divide by one / bypass).
  312. * CLK_DIVIDER_HIWORD_MASK - The divider settings are only in lower 16-bit
  313. * of this register, and mask of divider bits are in higher 16-bit of this
  314. * register. While setting the divider bits, higher 16-bit should also be
  315. * updated to indicate changing divider bits.
  316. * CLK_DIVIDER_ROUND_CLOSEST - Makes the best calculated divider to be rounded
  317. * to the closest integer instead of the up one.
  318. * CLK_DIVIDER_READ_ONLY - The divider settings are preconfigured and should
  319. * not be changed by the clock framework.
  320. */
  321. struct clk_divider {
  322. struct clk_hw hw;
  323. void __iomem *reg;
  324. u8 shift;
  325. u8 width;
  326. u8 flags;
  327. const struct clk_div_table *table;
  328. spinlock_t *lock;
  329. };
  330. #define CLK_DIVIDER_ONE_BASED BIT(0)
  331. #define CLK_DIVIDER_POWER_OF_TWO BIT(1)
  332. #define CLK_DIVIDER_ALLOW_ZERO BIT(2)
  333. #define CLK_DIVIDER_HIWORD_MASK BIT(3)
  334. #define CLK_DIVIDER_ROUND_CLOSEST BIT(4)
  335. #define CLK_DIVIDER_READ_ONLY BIT(5)
  336. extern const struct clk_ops clk_divider_ops;
  337. struct clk *clk_register_divider(struct device *dev, const char *name,
  338. const char *parent_name, unsigned long flags,
  339. void __iomem *reg, u8 shift, u8 width,
  340. u8 clk_divider_flags, spinlock_t *lock);
  341. struct clk *clk_register_divider_table(struct device *dev, const char *name,
  342. const char *parent_name, unsigned long flags,
  343. void __iomem *reg, u8 shift, u8 width,
  344. u8 clk_divider_flags, const struct clk_div_table *table,
  345. spinlock_t *lock);
  346. /**
  347. * struct clk_mux - multiplexer clock
  348. *
  349. * @hw: handle between common and hardware-specific interfaces
  350. * @reg: register controlling multiplexer
  351. * @shift: shift to multiplexer bit field
  352. * @width: width of mutliplexer bit field
  353. * @flags: hardware-specific flags
  354. * @lock: register lock
  355. *
  356. * Clock with multiple selectable parents. Implements .get_parent, .set_parent
  357. * and .recalc_rate
  358. *
  359. * Flags:
  360. * CLK_MUX_INDEX_ONE - register index starts at 1, not 0
  361. * CLK_MUX_INDEX_BIT - register index is a single bit (power of two)
  362. * CLK_MUX_HIWORD_MASK - The mux settings are only in lower 16-bit of this
  363. * register, and mask of mux bits are in higher 16-bit of this register.
  364. * While setting the mux bits, higher 16-bit should also be updated to
  365. * indicate changing mux bits.
  366. */
  367. struct clk_mux {
  368. struct clk_hw hw;
  369. void __iomem *reg;
  370. u32 *table;
  371. u32 mask;
  372. u8 shift;
  373. u8 flags;
  374. spinlock_t *lock;
  375. };
  376. #define CLK_MUX_INDEX_ONE BIT(0)
  377. #define CLK_MUX_INDEX_BIT BIT(1)
  378. #define CLK_MUX_HIWORD_MASK BIT(2)
  379. #define CLK_MUX_READ_ONLY BIT(3) /* mux setting cannot be changed */
  380. extern const struct clk_ops clk_mux_ops;
  381. extern const struct clk_ops clk_mux_ro_ops;
  382. struct clk *clk_register_mux(struct device *dev, const char *name,
  383. const char **parent_names, u8 num_parents, unsigned long flags,
  384. void __iomem *reg, u8 shift, u8 width,
  385. u8 clk_mux_flags, spinlock_t *lock);
  386. struct clk *clk_register_mux_table(struct device *dev, const char *name,
  387. const char **parent_names, u8 num_parents, unsigned long flags,
  388. void __iomem *reg, u8 shift, u32 mask,
  389. u8 clk_mux_flags, u32 *table, spinlock_t *lock);
  390. void of_fixed_factor_clk_setup(struct device_node *node);
  391. /**
  392. * struct clk_fixed_factor - fixed multiplier and divider clock
  393. *
  394. * @hw: handle between common and hardware-specific interfaces
  395. * @mult: multiplier
  396. * @div: divider
  397. *
  398. * Clock with a fixed multiplier and divider. The output frequency is the
  399. * parent clock rate divided by div and multiplied by mult.
  400. * Implements .recalc_rate, .set_rate and .round_rate
  401. */
  402. struct clk_fixed_factor {
  403. struct clk_hw hw;
  404. unsigned int mult;
  405. unsigned int div;
  406. };
  407. extern struct clk_ops clk_fixed_factor_ops;
  408. struct clk *clk_register_fixed_factor(struct device *dev, const char *name,
  409. const char *parent_name, unsigned long flags,
  410. unsigned int mult, unsigned int div);
  411. /**
  412. * struct clk_fractional_divider - adjustable fractional divider clock
  413. *
  414. * @hw: handle between common and hardware-specific interfaces
  415. * @reg: register containing the divider
  416. * @mshift: shift to the numerator bit field
  417. * @mwidth: width of the numerator bit field
  418. * @nshift: shift to the denominator bit field
  419. * @nwidth: width of the denominator bit field
  420. * @lock: register lock
  421. *
  422. * Clock with adjustable fractional divider affecting its output frequency.
  423. */
  424. struct clk_fractional_divider {
  425. struct clk_hw hw;
  426. void __iomem *reg;
  427. u8 mshift;
  428. u32 mmask;
  429. u8 nshift;
  430. u32 nmask;
  431. u8 flags;
  432. spinlock_t *lock;
  433. };
  434. extern const struct clk_ops clk_fractional_divider_ops;
  435. struct clk *clk_register_fractional_divider(struct device *dev,
  436. const char *name, const char *parent_name, unsigned long flags,
  437. void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth,
  438. u8 clk_divider_flags, spinlock_t *lock);
  439. /***
  440. * struct clk_composite - aggregate clock of mux, divider and gate clocks
  441. *
  442. * @hw: handle between common and hardware-specific interfaces
  443. * @mux_hw: handle between composite and hardware-specific mux clock
  444. * @rate_hw: handle between composite and hardware-specific rate clock
  445. * @gate_hw: handle between composite and hardware-specific gate clock
  446. * @mux_ops: clock ops for mux
  447. * @rate_ops: clock ops for rate
  448. * @gate_ops: clock ops for gate
  449. */
  450. struct clk_composite {
  451. struct clk_hw hw;
  452. struct clk_ops ops;
  453. struct clk_hw *mux_hw;
  454. struct clk_hw *rate_hw;
  455. struct clk_hw *gate_hw;
  456. const struct clk_ops *mux_ops;
  457. const struct clk_ops *rate_ops;
  458. const struct clk_ops *gate_ops;
  459. };
  460. struct clk *clk_register_composite(struct device *dev, const char *name,
  461. const char **parent_names, int num_parents,
  462. struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
  463. struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
  464. struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
  465. unsigned long flags);
  466. /***
  467. * struct clk_gpio_gate - gpio gated clock
  468. *
  469. * @hw: handle between common and hardware-specific interfaces
  470. * @gpiod: gpio descriptor
  471. *
  472. * Clock with a gpio control for enabling and disabling the parent clock.
  473. * Implements .enable, .disable and .is_enabled
  474. */
  475. struct clk_gpio {
  476. struct clk_hw hw;
  477. struct gpio_desc *gpiod;
  478. };
  479. extern const struct clk_ops clk_gpio_gate_ops;
  480. struct clk *clk_register_gpio_gate(struct device *dev, const char *name,
  481. const char *parent_name, struct gpio_desc *gpio,
  482. unsigned long flags);
  483. void of_gpio_clk_gate_setup(struct device_node *node);
  484. /**
  485. * clk_register - allocate a new clock, register it and return an opaque cookie
  486. * @dev: device that is registering this clock
  487. * @hw: link to hardware-specific clock data
  488. *
  489. * clk_register is the primary interface for populating the clock tree with new
  490. * clock nodes. It returns a pointer to the newly allocated struct clk which
  491. * cannot be dereferenced by driver code but may be used in conjuction with the
  492. * rest of the clock API. In the event of an error clk_register will return an
  493. * error code; drivers must test for an error code after calling clk_register.
  494. */
  495. struct clk *clk_register(struct device *dev, struct clk_hw *hw);
  496. struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw);
  497. void clk_unregister(struct clk *clk);
  498. void devm_clk_unregister(struct device *dev, struct clk *clk);
  499. /* helper functions */
  500. const char *__clk_get_name(struct clk *clk);
  501. struct clk_hw *__clk_get_hw(struct clk *clk);
  502. u8 __clk_get_num_parents(struct clk *clk);
  503. struct clk *__clk_get_parent(struct clk *clk);
  504. struct clk *clk_get_parent_by_index(struct clk *clk, u8 index);
  505. unsigned int __clk_get_enable_count(struct clk *clk);
  506. unsigned int __clk_get_prepare_count(struct clk *clk);
  507. unsigned long __clk_get_rate(struct clk *clk);
  508. unsigned long __clk_get_accuracy(struct clk *clk);
  509. unsigned long __clk_get_flags(struct clk *clk);
  510. bool __clk_is_prepared(struct clk *clk);
  511. bool __clk_is_enabled(struct clk *clk);
  512. struct clk *__clk_lookup(const char *name);
  513. long __clk_mux_determine_rate(struct clk_hw *hw, unsigned long rate,
  514. unsigned long *best_parent_rate,
  515. struct clk **best_parent_p);
  516. /*
  517. * FIXME clock api without lock protection
  518. */
  519. int __clk_prepare(struct clk *clk);
  520. void __clk_unprepare(struct clk *clk);
  521. void __clk_reparent(struct clk *clk, struct clk *new_parent);
  522. unsigned long __clk_round_rate(struct clk *clk, unsigned long rate);
  523. struct of_device_id;
  524. typedef void (*of_clk_init_cb_t)(struct device_node *);
  525. struct clk_onecell_data {
  526. struct clk **clks;
  527. unsigned int clk_num;
  528. };
  529. extern struct of_device_id __clk_of_table;
  530. #define CLK_OF_DECLARE(name, compat, fn) OF_DECLARE_1(clk, name, compat, fn)
  531. #ifdef CONFIG_OF
  532. int of_clk_add_provider(struct device_node *np,
  533. struct clk *(*clk_src_get)(struct of_phandle_args *args,
  534. void *data),
  535. void *data);
  536. void of_clk_del_provider(struct device_node *np);
  537. struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
  538. void *data);
  539. struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
  540. int of_clk_get_parent_count(struct device_node *np);
  541. const char *of_clk_get_parent_name(struct device_node *np, int index);
  542. void of_clk_init(const struct of_device_id *matches);
  543. #else /* !CONFIG_OF */
  544. static inline int of_clk_add_provider(struct device_node *np,
  545. struct clk *(*clk_src_get)(struct of_phandle_args *args,
  546. void *data),
  547. void *data)
  548. {
  549. return 0;
  550. }
  551. #define of_clk_del_provider(np) \
  552. { while (0); }
  553. static inline struct clk *of_clk_src_simple_get(
  554. struct of_phandle_args *clkspec, void *data)
  555. {
  556. return ERR_PTR(-ENOENT);
  557. }
  558. static inline struct clk *of_clk_src_onecell_get(
  559. struct of_phandle_args *clkspec, void *data)
  560. {
  561. return ERR_PTR(-ENOENT);
  562. }
  563. static inline const char *of_clk_get_parent_name(struct device_node *np,
  564. int index)
  565. {
  566. return NULL;
  567. }
  568. #define of_clk_init(matches) \
  569. { while (0); }
  570. #endif /* CONFIG_OF */
  571. /*
  572. * wrap access to peripherals in accessor routines
  573. * for improved portability across platforms
  574. */
  575. #if IS_ENABLED(CONFIG_PPC)
  576. static inline u32 clk_readl(u32 __iomem *reg)
  577. {
  578. return ioread32be(reg);
  579. }
  580. static inline void clk_writel(u32 val, u32 __iomem *reg)
  581. {
  582. iowrite32be(val, reg);
  583. }
  584. #else /* platform dependent I/O accessors */
  585. static inline u32 clk_readl(u32 __iomem *reg)
  586. {
  587. return readl(reg);
  588. }
  589. static inline void clk_writel(u32 val, u32 __iomem *reg)
  590. {
  591. writel(val, reg);
  592. }
  593. #endif /* platform dependent I/O accessors */
  594. #ifdef CONFIG_DEBUG_FS
  595. struct dentry *clk_debugfs_add_file(struct clk *clk, char *name, umode_t mode,
  596. void *data, const struct file_operations *fops);
  597. #endif
  598. #endif /* CONFIG_COMMON_CLK */
  599. #endif /* CLK_PROVIDER_H */