clk-provider.h 26 KB

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