clk-provider.h 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2010-2011 Jeremy Kerr <[email protected]>
  4. * Copyright (C) 2011-2012 Linaro Ltd <[email protected]>
  5. */
  6. #ifndef __LINUX_CLK_PROVIDER_H
  7. #define __LINUX_CLK_PROVIDER_H
  8. #include <linux/of.h>
  9. #include <linux/of_clk.h>
  10. /*
  11. * flags used across common struct clk. these flags should only affect the
  12. * top-level framework. custom flags for dealing with hardware specifics
  13. * belong in struct clk_foo
  14. *
  15. * Please update clk_flags[] in drivers/clk/clk.c when making changes here!
  16. */
  17. #define CLK_SET_RATE_GATE BIT(0) /* must be gated across rate change */
  18. #define CLK_SET_PARENT_GATE BIT(1) /* must be gated across re-parent */
  19. #define CLK_SET_RATE_PARENT BIT(2) /* propagate rate change up one level */
  20. #define CLK_IGNORE_UNUSED BIT(3) /* do not gate even if unused */
  21. /* unused */
  22. /* unused */
  23. #define CLK_GET_RATE_NOCACHE BIT(6) /* do not use the cached clk rate */
  24. #define CLK_SET_RATE_NO_REPARENT BIT(7) /* don't re-parent on rate change */
  25. #define CLK_GET_ACCURACY_NOCACHE BIT(8) /* do not use the cached clk accuracy */
  26. #define CLK_RECALC_NEW_RATES BIT(9) /* recalc rates after notifications */
  27. #define CLK_SET_RATE_UNGATE BIT(10) /* clock needs to run to set rate */
  28. #define CLK_IS_CRITICAL BIT(11) /* do not gate, ever */
  29. /* parents need enable during gate/ungate, set rate and re-parent */
  30. #define CLK_OPS_PARENT_ENABLE BIT(12)
  31. /* duty cycle call may be forwarded to the parent clock */
  32. #define CLK_DUTY_CYCLE_PARENT BIT(13)
  33. #define CLK_DONT_HOLD_STATE BIT(14) /* Don't hold state */
  34. struct clk;
  35. struct clk_hw;
  36. struct clk_core;
  37. struct dentry;
  38. /**
  39. * struct clk_rate_request - Structure encoding the clk constraints that
  40. * a clock user might require.
  41. *
  42. * Should be initialized by calling clk_hw_init_rate_request().
  43. *
  44. * @rate: Requested clock rate. This field will be adjusted by
  45. * clock drivers according to hardware capabilities.
  46. * @min_rate: Minimum rate imposed by clk users.
  47. * @max_rate: Maximum rate imposed by clk users.
  48. * @best_parent_rate: The best parent rate a parent can provide to fulfill the
  49. * requested constraints.
  50. * @best_parent_hw: The most appropriate parent clock that fulfills the
  51. * requested constraints.
  52. *
  53. */
  54. struct clk_rate_request {
  55. unsigned long rate;
  56. unsigned long min_rate;
  57. unsigned long max_rate;
  58. unsigned long best_parent_rate;
  59. struct clk_hw *best_parent_hw;
  60. };
  61. void clk_hw_init_rate_request(const struct clk_hw *hw,
  62. struct clk_rate_request *req,
  63. unsigned long rate);
  64. void clk_hw_forward_rate_request(const struct clk_hw *core,
  65. const struct clk_rate_request *old_req,
  66. const struct clk_hw *parent,
  67. struct clk_rate_request *req,
  68. unsigned long parent_rate);
  69. /**
  70. * struct clk_duty - Structure encoding the duty cycle ratio of a clock
  71. *
  72. * @num: Numerator of the duty cycle ratio
  73. * @den: Denominator of the duty cycle ratio
  74. */
  75. struct clk_duty {
  76. unsigned int num;
  77. unsigned int den;
  78. };
  79. /**
  80. * struct clk_ops - Callback operations for hardware clocks; these are to
  81. * be provided by the clock implementation, and will be called by drivers
  82. * through the clk_* api.
  83. *
  84. * @prepare: Prepare the clock for enabling. This must not return until
  85. * the clock is fully prepared, and it's safe to call clk_enable.
  86. * This callback is intended to allow clock implementations to
  87. * do any initialisation that may sleep. Called with
  88. * prepare_lock held.
  89. *
  90. * @unprepare: Release the clock from its prepared state. This will typically
  91. * undo any work done in the @prepare callback. Called with
  92. * prepare_lock held.
  93. *
  94. * @is_prepared: Queries the hardware to determine if the clock is prepared.
  95. * This function is allowed to sleep. Optional, if this op is not
  96. * set then the prepare count will be used.
  97. *
  98. * @unprepare_unused: Unprepare the clock atomically. Only called from
  99. * clk_disable_unused for prepare clocks with special needs.
  100. * Called with prepare mutex held. This function may sleep.
  101. *
  102. * @enable: Enable the clock atomically. This must not return until the
  103. * clock is generating a valid clock signal, usable by consumer
  104. * devices. Called with enable_lock held. This function must not
  105. * sleep.
  106. *
  107. * @disable: Disable the clock atomically. Called with enable_lock held.
  108. * This function must not sleep.
  109. *
  110. * @is_enabled: Queries the hardware to determine if the clock is enabled.
  111. * This function must not sleep. Optional, if this op is not
  112. * set then the enable count will be used.
  113. *
  114. * @disable_unused: Disable the clock atomically. Only called from
  115. * clk_disable_unused for gate clocks with special needs.
  116. * Called with enable_lock held. This function must not
  117. * sleep.
  118. *
  119. * @save_context: Save the context of the clock in prepration for poweroff.
  120. *
  121. * @restore_context: Restore the context of the clock after a restoration
  122. * of power.
  123. *
  124. * @recalc_rate: Recalculate the rate of this clock, by querying hardware. The
  125. * parent rate is an input parameter. It is up to the caller to
  126. * ensure that the prepare_mutex is held across this call. If the
  127. * driver cannot figure out a rate for this clock, it must return
  128. * 0. Returns the calculated rate. Optional, but recommended - if
  129. * this op is not set then clock rate will be initialized to 0.
  130. *
  131. * @round_rate: Given a target rate as input, returns the closest rate actually
  132. * supported by the clock. The parent rate is an input/output
  133. * parameter.
  134. *
  135. * @determine_rate: Given a target rate as input, returns the closest rate
  136. * actually supported by the clock, and optionally the parent clock
  137. * that should be used to provide the clock rate.
  138. *
  139. * @set_parent: Change the input source of this clock; for clocks with multiple
  140. * possible parents specify a new parent by passing in the index
  141. * as a u8 corresponding to the parent in either the .parent_names
  142. * or .parents arrays. This function in affect translates an
  143. * array index into the value programmed into the hardware.
  144. * Returns 0 on success, -EERROR otherwise.
  145. *
  146. * @get_parent: Queries the hardware to determine the parent of a clock. The
  147. * return value is a u8 which specifies the index corresponding to
  148. * the parent clock. This index can be applied to either the
  149. * .parent_names or .parents arrays. In short, this function
  150. * translates the parent value read from hardware into an array
  151. * index. Currently only called when the clock is initialized by
  152. * __clk_init. This callback is mandatory for clocks with
  153. * multiple parents. It is optional (and unnecessary) for clocks
  154. * with 0 or 1 parents.
  155. *
  156. * @set_rate: Change the rate of this clock. The requested rate is specified
  157. * by the second argument, which should typically be the return
  158. * of .round_rate call. The third argument gives the parent rate
  159. * which is likely helpful for most .set_rate implementation.
  160. * Returns 0 on success, -EERROR otherwise.
  161. *
  162. * @set_rate_and_parent: Change the rate and the parent of this clock. The
  163. * requested rate is specified by the second argument, which
  164. * should typically be the return of .round_rate call. The
  165. * third argument gives the parent rate which is likely helpful
  166. * for most .set_rate_and_parent implementation. The fourth
  167. * argument gives the parent index. This callback is optional (and
  168. * unnecessary) for clocks with 0 or 1 parents as well as
  169. * for clocks that can tolerate switching the rate and the parent
  170. * separately via calls to .set_parent and .set_rate.
  171. * Returns 0 on success, -EERROR otherwise.
  172. *
  173. * @recalc_accuracy: Recalculate the accuracy of this clock. The clock accuracy
  174. * is expressed in ppb (parts per billion). The parent accuracy is
  175. * an input parameter.
  176. * Returns the calculated accuracy. Optional - if this op is not
  177. * set then clock accuracy will be initialized to parent accuracy
  178. * or 0 (perfect clock) if clock has no parent.
  179. *
  180. * @get_phase: Queries the hardware to get the current phase of a clock.
  181. * Returned values are 0-359 degrees on success, negative
  182. * error codes on failure.
  183. *
  184. * @set_phase: Shift the phase this clock signal in degrees specified
  185. * by the second argument. Valid values for degrees are
  186. * 0-359. Return 0 on success, otherwise -EERROR.
  187. *
  188. * @get_duty_cycle: Queries the hardware to get the current duty cycle ratio
  189. * of a clock. Returned values denominator cannot be 0 and must be
  190. * superior or equal to the numerator.
  191. *
  192. * @set_duty_cycle: Apply the duty cycle ratio to this clock signal specified by
  193. * the numerator (2nd argurment) and denominator (3rd argument).
  194. * Argument must be a valid ratio (denominator > 0
  195. * and >= numerator) Return 0 on success, otherwise -EERROR.
  196. *
  197. * @init: Perform platform-specific initialization magic.
  198. * This is not used by any of the basic clock types.
  199. * This callback exist for HW which needs to perform some
  200. * initialisation magic for CCF to get an accurate view of the
  201. * clock. It may also be used dynamic resource allocation is
  202. * required. It shall not used to deal with clock parameters,
  203. * such as rate or parents.
  204. * Returns 0 on success, -EERROR otherwise.
  205. *
  206. * @terminate: Free any resource allocated by init.
  207. *
  208. * @debug_init: Set up type-specific debugfs entries for this clock. This
  209. * is called once, after the debugfs directory entry for this
  210. * clock has been created. The dentry pointer representing that
  211. * directory is provided as an argument. Called with
  212. * prepare_lock held. Returns 0 on success, -EERROR otherwise.
  213. *
  214. * @pre_rate_change: Optional callback for a clock to fulfill its rate
  215. * change requirements before any rate change has occurred in
  216. * its clock tree. Returns 0 on success, -EERROR otherwise.
  217. *
  218. * @post_rate_change: Optional callback for a clock to clean up any
  219. * requirements that were needed while the clock and its tree
  220. * was changing states. Returns 0 on success, -EERROR otherwise.
  221. *
  222. * The clk_enable/clk_disable and clk_prepare/clk_unprepare pairs allow
  223. * implementations to split any work between atomic (enable) and sleepable
  224. * (prepare) contexts. If enabling a clock requires code that might sleep,
  225. * this must be done in clk_prepare. Clock enable code that will never be
  226. * called in a sleepable context may be implemented in clk_enable.
  227. *
  228. * Typically, drivers will call clk_prepare when a clock may be needed later
  229. * (eg. when a device is opened), and clk_enable when the clock is actually
  230. * required (eg. from an interrupt). Note that clk_prepare MUST have been
  231. * called before clk_enable.
  232. */
  233. struct clk_ops {
  234. int (*prepare)(struct clk_hw *hw);
  235. void (*unprepare)(struct clk_hw *hw);
  236. int (*is_prepared)(struct clk_hw *hw);
  237. void (*unprepare_unused)(struct clk_hw *hw);
  238. int (*enable)(struct clk_hw *hw);
  239. void (*disable)(struct clk_hw *hw);
  240. int (*is_enabled)(struct clk_hw *hw);
  241. void (*disable_unused)(struct clk_hw *hw);
  242. int (*save_context)(struct clk_hw *hw);
  243. void (*restore_context)(struct clk_hw *hw);
  244. unsigned long (*recalc_rate)(struct clk_hw *hw,
  245. unsigned long parent_rate);
  246. long (*round_rate)(struct clk_hw *hw, unsigned long rate,
  247. unsigned long *parent_rate);
  248. int (*determine_rate)(struct clk_hw *hw,
  249. struct clk_rate_request *req);
  250. int (*set_parent)(struct clk_hw *hw, u8 index);
  251. u8 (*get_parent)(struct clk_hw *hw);
  252. int (*set_rate)(struct clk_hw *hw, unsigned long rate,
  253. unsigned long parent_rate);
  254. int (*set_rate_and_parent)(struct clk_hw *hw,
  255. unsigned long rate,
  256. unsigned long parent_rate, u8 index);
  257. unsigned long (*recalc_accuracy)(struct clk_hw *hw,
  258. unsigned long parent_accuracy);
  259. int (*get_phase)(struct clk_hw *hw);
  260. int (*set_phase)(struct clk_hw *hw, int degrees);
  261. int (*get_duty_cycle)(struct clk_hw *hw,
  262. struct clk_duty *duty);
  263. int (*set_duty_cycle)(struct clk_hw *hw,
  264. struct clk_duty *duty);
  265. int (*init)(struct clk_hw *hw);
  266. void (*terminate)(struct clk_hw *hw);
  267. void (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
  268. int (*pre_rate_change)(struct clk_hw *hw,
  269. unsigned long rate,
  270. unsigned long new_rate);
  271. int (*post_rate_change)(struct clk_hw *hw,
  272. unsigned long old_rate,
  273. unsigned long rate);
  274. };
  275. /**
  276. * struct clk_parent_data - clk parent information
  277. * @hw: parent clk_hw pointer (used for clk providers with internal clks)
  278. * @fw_name: parent name local to provider registering clk
  279. * @name: globally unique parent name (used as a fallback)
  280. * @index: parent index local to provider registering clk (if @fw_name absent)
  281. */
  282. struct clk_parent_data {
  283. const struct clk_hw *hw;
  284. const char *fw_name;
  285. const char *name;
  286. int index;
  287. };
  288. /**
  289. * struct clk_init_data - holds init data that's common to all clocks and is
  290. * shared between the clock provider and the common clock framework.
  291. *
  292. * @name: clock name
  293. * @ops: operations this clock supports
  294. * @parent_names: array of string names for all possible parents
  295. * @parent_data: array of parent data for all possible parents (when some
  296. * parents are external to the clk controller)
  297. * @parent_hws: array of pointers to all possible parents (when all parents
  298. * are internal to the clk controller)
  299. * @num_parents: number of possible parents
  300. * @flags: framework-level hints and quirks
  301. */
  302. struct clk_init_data {
  303. const char *name;
  304. const struct clk_ops *ops;
  305. /* Only one of the following three should be assigned */
  306. const char * const *parent_names;
  307. const struct clk_parent_data *parent_data;
  308. const struct clk_hw **parent_hws;
  309. u8 num_parents;
  310. unsigned long flags;
  311. };
  312. /**
  313. * struct clk_hw - handle for traversing from a struct clk to its corresponding
  314. * hardware-specific structure. struct clk_hw should be declared within struct
  315. * clk_foo and then referenced by the struct clk instance that uses struct
  316. * clk_foo's clk_ops
  317. *
  318. * @core: pointer to the struct clk_core instance that points back to this
  319. * struct clk_hw instance
  320. *
  321. * @clk: pointer to the per-user struct clk instance that can be used to call
  322. * into the clk API
  323. *
  324. * @init: pointer to struct clk_init_data that contains the init data shared
  325. * with the common clock framework. This pointer will be set to NULL once
  326. * a clk_register() variant is called on this clk_hw pointer.
  327. */
  328. struct clk_hw {
  329. struct clk_core *core;
  330. struct clk *clk;
  331. const struct clk_init_data *init;
  332. };
  333. /*
  334. * DOC: Basic clock implementations common to many platforms
  335. *
  336. * Each basic clock hardware type is comprised of a structure describing the
  337. * clock hardware, implementations of the relevant callbacks in struct clk_ops,
  338. * unique flags for that hardware type, a registration function and an
  339. * alternative macro for static initialization
  340. */
  341. /**
  342. * struct clk_fixed_rate - fixed-rate clock
  343. * @hw: handle between common and hardware-specific interfaces
  344. * @fixed_rate: constant frequency of clock
  345. * @fixed_accuracy: constant accuracy of clock in ppb (parts per billion)
  346. * @flags: hardware specific flags
  347. *
  348. * Flags:
  349. * * CLK_FIXED_RATE_PARENT_ACCURACY - Use the accuracy of the parent clk
  350. * instead of what's set in @fixed_accuracy.
  351. */
  352. struct clk_fixed_rate {
  353. struct clk_hw hw;
  354. unsigned long fixed_rate;
  355. unsigned long fixed_accuracy;
  356. unsigned long flags;
  357. };
  358. #define CLK_FIXED_RATE_PARENT_ACCURACY BIT(0)
  359. extern const struct clk_ops clk_fixed_rate_ops;
  360. struct clk_hw *__clk_hw_register_fixed_rate(struct device *dev,
  361. struct device_node *np, const char *name,
  362. const char *parent_name, const struct clk_hw *parent_hw,
  363. const struct clk_parent_data *parent_data, unsigned long flags,
  364. unsigned long fixed_rate, unsigned long fixed_accuracy,
  365. unsigned long clk_fixed_flags, bool devm);
  366. struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
  367. const char *parent_name, unsigned long flags,
  368. unsigned long fixed_rate);
  369. /**
  370. * clk_hw_register_fixed_rate - register fixed-rate clock with the clock
  371. * framework
  372. * @dev: device that is registering this clock
  373. * @name: name of this clock
  374. * @parent_name: name of clock's parent
  375. * @flags: framework-specific flags
  376. * @fixed_rate: non-adjustable clock rate
  377. */
  378. #define clk_hw_register_fixed_rate(dev, name, parent_name, flags, fixed_rate) \
  379. __clk_hw_register_fixed_rate((dev), NULL, (name), (parent_name), NULL, \
  380. NULL, (flags), (fixed_rate), 0, 0, false)
  381. /**
  382. * devm_clk_hw_register_fixed_rate - register fixed-rate clock with the clock
  383. * framework
  384. * @dev: device that is registering this clock
  385. * @name: name of this clock
  386. * @parent_name: name of clock's parent
  387. * @flags: framework-specific flags
  388. * @fixed_rate: non-adjustable clock rate
  389. */
  390. #define devm_clk_hw_register_fixed_rate(dev, name, parent_name, flags, fixed_rate) \
  391. __clk_hw_register_fixed_rate((dev), NULL, (name), (parent_name), NULL, \
  392. NULL, (flags), (fixed_rate), 0, 0, true)
  393. /**
  394. * clk_hw_register_fixed_rate_parent_hw - register fixed-rate clock with
  395. * the clock framework
  396. * @dev: device that is registering this clock
  397. * @name: name of this clock
  398. * @parent_hw: pointer to parent clk
  399. * @flags: framework-specific flags
  400. * @fixed_rate: non-adjustable clock rate
  401. */
  402. #define clk_hw_register_fixed_rate_parent_hw(dev, name, parent_hw, flags, \
  403. fixed_rate) \
  404. __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, (parent_hw), \
  405. NULL, (flags), (fixed_rate), 0, 0, false)
  406. /**
  407. * clk_hw_register_fixed_rate_parent_data - register fixed-rate clock with
  408. * the clock framework
  409. * @dev: device that is registering this clock
  410. * @name: name of this clock
  411. * @parent_data: parent clk data
  412. * @flags: framework-specific flags
  413. * @fixed_rate: non-adjustable clock rate
  414. */
  415. #define clk_hw_register_fixed_rate_parent_data(dev, name, parent_hw, flags, \
  416. fixed_rate) \
  417. __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, NULL, \
  418. (parent_data), (flags), (fixed_rate), 0, \
  419. 0, false)
  420. /**
  421. * clk_hw_register_fixed_rate_with_accuracy - register fixed-rate clock with
  422. * the clock framework
  423. * @dev: device that is registering this clock
  424. * @name: name of this clock
  425. * @parent_name: name of clock's parent
  426. * @flags: framework-specific flags
  427. * @fixed_rate: non-adjustable clock rate
  428. * @fixed_accuracy: non-adjustable clock accuracy
  429. */
  430. #define clk_hw_register_fixed_rate_with_accuracy(dev, name, parent_name, \
  431. flags, fixed_rate, \
  432. fixed_accuracy) \
  433. __clk_hw_register_fixed_rate((dev), NULL, (name), (parent_name), \
  434. NULL, NULL, (flags), (fixed_rate), \
  435. (fixed_accuracy), 0, false)
  436. /**
  437. * clk_hw_register_fixed_rate_with_accuracy_parent_hw - register fixed-rate
  438. * clock with the clock framework
  439. * @dev: device that is registering this clock
  440. * @name: name of this clock
  441. * @parent_hw: pointer to parent clk
  442. * @flags: framework-specific flags
  443. * @fixed_rate: non-adjustable clock rate
  444. * @fixed_accuracy: non-adjustable clock accuracy
  445. */
  446. #define clk_hw_register_fixed_rate_with_accuracy_parent_hw(dev, name, \
  447. parent_hw, flags, fixed_rate, fixed_accuracy) \
  448. __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, (parent_hw) \
  449. NULL, NULL, (flags), (fixed_rate), \
  450. (fixed_accuracy), 0, false)
  451. /**
  452. * clk_hw_register_fixed_rate_with_accuracy_parent_data - register fixed-rate
  453. * clock with the clock framework
  454. * @dev: device that is registering this clock
  455. * @name: name of this clock
  456. * @parent_data: name of clock's parent
  457. * @flags: framework-specific flags
  458. * @fixed_rate: non-adjustable clock rate
  459. * @fixed_accuracy: non-adjustable clock accuracy
  460. */
  461. #define clk_hw_register_fixed_rate_with_accuracy_parent_data(dev, name, \
  462. parent_data, flags, fixed_rate, fixed_accuracy) \
  463. __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, NULL, \
  464. (parent_data), NULL, (flags), \
  465. (fixed_rate), (fixed_accuracy), 0, false)
  466. /**
  467. * clk_hw_register_fixed_rate_parent_accuracy - register fixed-rate clock with
  468. * the clock framework
  469. * @dev: device that is registering this clock
  470. * @name: name of this clock
  471. * @parent_data: name of clock's parent
  472. * @flags: framework-specific flags
  473. * @fixed_rate: non-adjustable clock rate
  474. */
  475. #define clk_hw_register_fixed_rate_parent_accuracy(dev, name, parent_data, \
  476. flags, fixed_rate) \
  477. __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, NULL, \
  478. (parent_data), (flags), (fixed_rate), 0, \
  479. CLK_FIXED_RATE_PARENT_ACCURACY, false)
  480. void clk_unregister_fixed_rate(struct clk *clk);
  481. void clk_hw_unregister_fixed_rate(struct clk_hw *hw);
  482. void of_fixed_clk_setup(struct device_node *np);
  483. /**
  484. * struct clk_gate - gating clock
  485. *
  486. * @hw: handle between common and hardware-specific interfaces
  487. * @reg: register controlling gate
  488. * @bit_idx: single bit controlling gate
  489. * @flags: hardware-specific flags
  490. * @lock: register lock
  491. *
  492. * Clock which can gate its output. Implements .enable & .disable
  493. *
  494. * Flags:
  495. * CLK_GATE_SET_TO_DISABLE - by default this clock sets the bit at bit_idx to
  496. * enable the clock. Setting this flag does the opposite: setting the bit
  497. * disable the clock and clearing it enables the clock
  498. * CLK_GATE_HIWORD_MASK - The gate settings are only in lower 16-bit
  499. * of this register, and mask of gate bits are in higher 16-bit of this
  500. * register. While setting the gate bits, higher 16-bit should also be
  501. * updated to indicate changing gate bits.
  502. * CLK_GATE_BIG_ENDIAN - by default little endian register accesses are used for
  503. * the gate register. Setting this flag makes the register accesses big
  504. * endian.
  505. */
  506. struct clk_gate {
  507. struct clk_hw hw;
  508. void __iomem *reg;
  509. u8 bit_idx;
  510. u8 flags;
  511. spinlock_t *lock;
  512. };
  513. #define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
  514. #define CLK_GATE_SET_TO_DISABLE BIT(0)
  515. #define CLK_GATE_HIWORD_MASK BIT(1)
  516. #define CLK_GATE_BIG_ENDIAN BIT(2)
  517. extern const struct clk_ops clk_gate_ops;
  518. struct clk_hw *__clk_hw_register_gate(struct device *dev,
  519. struct device_node *np, const char *name,
  520. const char *parent_name, const struct clk_hw *parent_hw,
  521. const struct clk_parent_data *parent_data,
  522. unsigned long flags,
  523. void __iomem *reg, u8 bit_idx,
  524. u8 clk_gate_flags, spinlock_t *lock);
  525. struct clk_hw *__devm_clk_hw_register_gate(struct device *dev,
  526. struct device_node *np, const char *name,
  527. const char *parent_name, const struct clk_hw *parent_hw,
  528. const struct clk_parent_data *parent_data,
  529. unsigned long flags,
  530. void __iomem *reg, u8 bit_idx,
  531. u8 clk_gate_flags, spinlock_t *lock);
  532. struct clk *clk_register_gate(struct device *dev, const char *name,
  533. const char *parent_name, unsigned long flags,
  534. void __iomem *reg, u8 bit_idx,
  535. u8 clk_gate_flags, spinlock_t *lock);
  536. /**
  537. * clk_hw_register_gate - register a gate clock with the clock framework
  538. * @dev: device that is registering this clock
  539. * @name: name of this clock
  540. * @parent_name: name of this clock's parent
  541. * @flags: framework-specific flags for this clock
  542. * @reg: register address to control gating of this clock
  543. * @bit_idx: which bit in the register controls gating of this clock
  544. * @clk_gate_flags: gate-specific flags for this clock
  545. * @lock: shared register lock for this clock
  546. */
  547. #define clk_hw_register_gate(dev, name, parent_name, flags, reg, bit_idx, \
  548. clk_gate_flags, lock) \
  549. __clk_hw_register_gate((dev), NULL, (name), (parent_name), NULL, \
  550. NULL, (flags), (reg), (bit_idx), \
  551. (clk_gate_flags), (lock))
  552. /**
  553. * clk_hw_register_gate_parent_hw - register a gate clock with the clock
  554. * framework
  555. * @dev: device that is registering this clock
  556. * @name: name of this clock
  557. * @parent_hw: pointer to parent clk
  558. * @flags: framework-specific flags for this clock
  559. * @reg: register address to control gating of this clock
  560. * @bit_idx: which bit in the register controls gating of this clock
  561. * @clk_gate_flags: gate-specific flags for this clock
  562. * @lock: shared register lock for this clock
  563. */
  564. #define clk_hw_register_gate_parent_hw(dev, name, parent_hw, flags, reg, \
  565. bit_idx, clk_gate_flags, lock) \
  566. __clk_hw_register_gate((dev), NULL, (name), NULL, (parent_hw), \
  567. NULL, (flags), (reg), (bit_idx), \
  568. (clk_gate_flags), (lock))
  569. /**
  570. * clk_hw_register_gate_parent_data - register a gate clock with the clock
  571. * framework
  572. * @dev: device that is registering this clock
  573. * @name: name of this clock
  574. * @parent_data: parent clk data
  575. * @flags: framework-specific flags for this clock
  576. * @reg: register address to control gating of this clock
  577. * @bit_idx: which bit in the register controls gating of this clock
  578. * @clk_gate_flags: gate-specific flags for this clock
  579. * @lock: shared register lock for this clock
  580. */
  581. #define clk_hw_register_gate_parent_data(dev, name, parent_data, flags, reg, \
  582. bit_idx, clk_gate_flags, lock) \
  583. __clk_hw_register_gate((dev), NULL, (name), NULL, NULL, (parent_data), \
  584. (flags), (reg), (bit_idx), \
  585. (clk_gate_flags), (lock))
  586. /**
  587. * devm_clk_hw_register_gate - register a gate clock with the clock framework
  588. * @dev: device that is registering this clock
  589. * @name: name of this clock
  590. * @parent_name: name of this clock's parent
  591. * @flags: framework-specific flags for this clock
  592. * @reg: register address to control gating of this clock
  593. * @bit_idx: which bit in the register controls gating of this clock
  594. * @clk_gate_flags: gate-specific flags for this clock
  595. * @lock: shared register lock for this clock
  596. */
  597. #define devm_clk_hw_register_gate(dev, name, parent_name, flags, reg, bit_idx,\
  598. clk_gate_flags, lock) \
  599. __devm_clk_hw_register_gate((dev), NULL, (name), (parent_name), NULL, \
  600. NULL, (flags), (reg), (bit_idx), \
  601. (clk_gate_flags), (lock))
  602. void clk_unregister_gate(struct clk *clk);
  603. void clk_hw_unregister_gate(struct clk_hw *hw);
  604. int clk_gate_is_enabled(struct clk_hw *hw);
  605. struct clk_div_table {
  606. unsigned int val;
  607. unsigned int div;
  608. };
  609. /**
  610. * struct clk_divider - adjustable divider clock
  611. *
  612. * @hw: handle between common and hardware-specific interfaces
  613. * @reg: register containing the divider
  614. * @shift: shift to the divider bit field
  615. * @width: width of the divider bit field
  616. * @table: array of value/divider pairs, last entry should have div = 0
  617. * @lock: register lock
  618. *
  619. * Clock with an adjustable divider affecting its output frequency. Implements
  620. * .recalc_rate, .set_rate and .round_rate
  621. *
  622. * @flags:
  623. * CLK_DIVIDER_ONE_BASED - by default the divisor is the value read from the
  624. * register plus one. If CLK_DIVIDER_ONE_BASED is set then the divider is
  625. * the raw value read from the register, with the value of zero considered
  626. * invalid, unless CLK_DIVIDER_ALLOW_ZERO is set.
  627. * CLK_DIVIDER_POWER_OF_TWO - clock divisor is 2 raised to the value read from
  628. * the hardware register
  629. * CLK_DIVIDER_ALLOW_ZERO - Allow zero divisors. For dividers which have
  630. * CLK_DIVIDER_ONE_BASED set, it is possible to end up with a zero divisor.
  631. * Some hardware implementations gracefully handle this case and allow a
  632. * zero divisor by not modifying their input clock
  633. * (divide by one / bypass).
  634. * CLK_DIVIDER_HIWORD_MASK - The divider settings are only in lower 16-bit
  635. * of this register, and mask of divider bits are in higher 16-bit of this
  636. * register. While setting the divider bits, higher 16-bit should also be
  637. * updated to indicate changing divider bits.
  638. * CLK_DIVIDER_ROUND_CLOSEST - Makes the best calculated divider to be rounded
  639. * to the closest integer instead of the up one.
  640. * CLK_DIVIDER_READ_ONLY - The divider settings are preconfigured and should
  641. * not be changed by the clock framework.
  642. * CLK_DIVIDER_MAX_AT_ZERO - For dividers which are like CLK_DIVIDER_ONE_BASED
  643. * except when the value read from the register is zero, the divisor is
  644. * 2^width of the field.
  645. * CLK_DIVIDER_BIG_ENDIAN - By default little endian register accesses are used
  646. * for the divider register. Setting this flag makes the register accesses
  647. * big endian.
  648. */
  649. struct clk_divider {
  650. struct clk_hw hw;
  651. void __iomem *reg;
  652. u8 shift;
  653. u8 width;
  654. u8 flags;
  655. const struct clk_div_table *table;
  656. spinlock_t *lock;
  657. };
  658. #define clk_div_mask(width) ((1 << (width)) - 1)
  659. #define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
  660. #define CLK_DIVIDER_ONE_BASED BIT(0)
  661. #define CLK_DIVIDER_POWER_OF_TWO BIT(1)
  662. #define CLK_DIVIDER_ALLOW_ZERO BIT(2)
  663. #define CLK_DIVIDER_HIWORD_MASK BIT(3)
  664. #define CLK_DIVIDER_ROUND_CLOSEST BIT(4)
  665. #define CLK_DIVIDER_READ_ONLY BIT(5)
  666. #define CLK_DIVIDER_MAX_AT_ZERO BIT(6)
  667. #define CLK_DIVIDER_BIG_ENDIAN BIT(7)
  668. extern const struct clk_ops clk_divider_ops;
  669. extern const struct clk_ops clk_divider_ro_ops;
  670. unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate,
  671. unsigned int val, const struct clk_div_table *table,
  672. unsigned long flags, unsigned long width);
  673. long divider_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
  674. unsigned long rate, unsigned long *prate,
  675. const struct clk_div_table *table,
  676. u8 width, unsigned long flags);
  677. long divider_ro_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
  678. unsigned long rate, unsigned long *prate,
  679. const struct clk_div_table *table, u8 width,
  680. unsigned long flags, unsigned int val);
  681. int divider_determine_rate(struct clk_hw *hw, struct clk_rate_request *req,
  682. const struct clk_div_table *table, u8 width,
  683. unsigned long flags);
  684. int divider_ro_determine_rate(struct clk_hw *hw, struct clk_rate_request *req,
  685. const struct clk_div_table *table, u8 width,
  686. unsigned long flags, unsigned int val);
  687. int divider_get_val(unsigned long rate, unsigned long parent_rate,
  688. const struct clk_div_table *table, u8 width,
  689. unsigned long flags);
  690. struct clk_hw *__clk_hw_register_divider(struct device *dev,
  691. struct device_node *np, const char *name,
  692. const char *parent_name, const struct clk_hw *parent_hw,
  693. const struct clk_parent_data *parent_data, unsigned long flags,
  694. void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
  695. const struct clk_div_table *table, spinlock_t *lock);
  696. struct clk_hw *__devm_clk_hw_register_divider(struct device *dev,
  697. struct device_node *np, const char *name,
  698. const char *parent_name, const struct clk_hw *parent_hw,
  699. const struct clk_parent_data *parent_data, unsigned long flags,
  700. void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
  701. const struct clk_div_table *table, spinlock_t *lock);
  702. struct clk *clk_register_divider_table(struct device *dev, const char *name,
  703. const char *parent_name, unsigned long flags,
  704. void __iomem *reg, u8 shift, u8 width,
  705. u8 clk_divider_flags, const struct clk_div_table *table,
  706. spinlock_t *lock);
  707. /**
  708. * clk_register_divider - register a divider clock with the clock framework
  709. * @dev: device registering this clock
  710. * @name: name of this clock
  711. * @parent_name: name of clock's parent
  712. * @flags: framework-specific flags
  713. * @reg: register address to adjust divider
  714. * @shift: number of bits to shift the bitfield
  715. * @width: width of the bitfield
  716. * @clk_divider_flags: divider-specific flags for this clock
  717. * @lock: shared register lock for this clock
  718. */
  719. #define clk_register_divider(dev, name, parent_name, flags, reg, shift, width, \
  720. clk_divider_flags, lock) \
  721. clk_register_divider_table((dev), (name), (parent_name), (flags), \
  722. (reg), (shift), (width), \
  723. (clk_divider_flags), NULL, (lock))
  724. /**
  725. * clk_hw_register_divider - register a divider clock with the clock framework
  726. * @dev: device registering this clock
  727. * @name: name of this clock
  728. * @parent_name: name of clock's parent
  729. * @flags: framework-specific flags
  730. * @reg: register address to adjust divider
  731. * @shift: number of bits to shift the bitfield
  732. * @width: width of the bitfield
  733. * @clk_divider_flags: divider-specific flags for this clock
  734. * @lock: shared register lock for this clock
  735. */
  736. #define clk_hw_register_divider(dev, name, parent_name, flags, reg, shift, \
  737. width, clk_divider_flags, lock) \
  738. __clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL, \
  739. NULL, (flags), (reg), (shift), (width), \
  740. (clk_divider_flags), NULL, (lock))
  741. /**
  742. * clk_hw_register_divider_parent_hw - register a divider clock with the clock
  743. * framework
  744. * @dev: device registering this clock
  745. * @name: name of this clock
  746. * @parent_hw: pointer to parent clk
  747. * @flags: framework-specific flags
  748. * @reg: register address to adjust divider
  749. * @shift: number of bits to shift the bitfield
  750. * @width: width of the bitfield
  751. * @clk_divider_flags: divider-specific flags for this clock
  752. * @lock: shared register lock for this clock
  753. */
  754. #define clk_hw_register_divider_parent_hw(dev, name, parent_hw, flags, reg, \
  755. shift, width, clk_divider_flags, \
  756. lock) \
  757. __clk_hw_register_divider((dev), NULL, (name), NULL, (parent_hw), \
  758. NULL, (flags), (reg), (shift), (width), \
  759. (clk_divider_flags), NULL, (lock))
  760. /**
  761. * clk_hw_register_divider_parent_data - register a divider clock with the clock
  762. * framework
  763. * @dev: device registering this clock
  764. * @name: name of this clock
  765. * @parent_data: parent clk data
  766. * @flags: framework-specific flags
  767. * @reg: register address to adjust divider
  768. * @shift: number of bits to shift the bitfield
  769. * @width: width of the bitfield
  770. * @clk_divider_flags: divider-specific flags for this clock
  771. * @lock: shared register lock for this clock
  772. */
  773. #define clk_hw_register_divider_parent_data(dev, name, parent_data, flags, \
  774. reg, shift, width, \
  775. clk_divider_flags, lock) \
  776. __clk_hw_register_divider((dev), NULL, (name), NULL, NULL, \
  777. (parent_data), (flags), (reg), (shift), \
  778. (width), (clk_divider_flags), NULL, (lock))
  779. /**
  780. * clk_hw_register_divider_table - register a table based divider clock with
  781. * the clock framework
  782. * @dev: device registering this clock
  783. * @name: name of this clock
  784. * @parent_name: name of clock's parent
  785. * @flags: framework-specific flags
  786. * @reg: register address to adjust divider
  787. * @shift: number of bits to shift the bitfield
  788. * @width: width of the bitfield
  789. * @clk_divider_flags: divider-specific flags for this clock
  790. * @table: array of divider/value pairs ending with a div set to 0
  791. * @lock: shared register lock for this clock
  792. */
  793. #define clk_hw_register_divider_table(dev, name, parent_name, flags, reg, \
  794. shift, width, clk_divider_flags, table, \
  795. lock) \
  796. __clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL, \
  797. NULL, (flags), (reg), (shift), (width), \
  798. (clk_divider_flags), (table), (lock))
  799. /**
  800. * clk_hw_register_divider_table_parent_hw - register a table based divider
  801. * clock with the clock framework
  802. * @dev: device registering this clock
  803. * @name: name of this clock
  804. * @parent_hw: pointer to parent clk
  805. * @flags: framework-specific flags
  806. * @reg: register address to adjust divider
  807. * @shift: number of bits to shift the bitfield
  808. * @width: width of the bitfield
  809. * @clk_divider_flags: divider-specific flags for this clock
  810. * @table: array of divider/value pairs ending with a div set to 0
  811. * @lock: shared register lock for this clock
  812. */
  813. #define clk_hw_register_divider_table_parent_hw(dev, name, parent_hw, flags, \
  814. reg, shift, width, \
  815. clk_divider_flags, table, \
  816. lock) \
  817. __clk_hw_register_divider((dev), NULL, (name), NULL, (parent_hw), \
  818. NULL, (flags), (reg), (shift), (width), \
  819. (clk_divider_flags), (table), (lock))
  820. /**
  821. * clk_hw_register_divider_table_parent_data - register a table based divider
  822. * clock with the clock framework
  823. * @dev: device registering this clock
  824. * @name: name of this clock
  825. * @parent_data: parent clk data
  826. * @flags: framework-specific flags
  827. * @reg: register address to adjust divider
  828. * @shift: number of bits to shift the bitfield
  829. * @width: width of the bitfield
  830. * @clk_divider_flags: divider-specific flags for this clock
  831. * @table: array of divider/value pairs ending with a div set to 0
  832. * @lock: shared register lock for this clock
  833. */
  834. #define clk_hw_register_divider_table_parent_data(dev, name, parent_data, \
  835. flags, reg, shift, width, \
  836. clk_divider_flags, table, \
  837. lock) \
  838. __clk_hw_register_divider((dev), NULL, (name), NULL, NULL, \
  839. (parent_data), (flags), (reg), (shift), \
  840. (width), (clk_divider_flags), (table), \
  841. (lock))
  842. /**
  843. * devm_clk_hw_register_divider - register a divider clock with the clock framework
  844. * @dev: device registering this clock
  845. * @name: name of this clock
  846. * @parent_name: name of clock's parent
  847. * @flags: framework-specific flags
  848. * @reg: register address to adjust divider
  849. * @shift: number of bits to shift the bitfield
  850. * @width: width of the bitfield
  851. * @clk_divider_flags: divider-specific flags for this clock
  852. * @lock: shared register lock for this clock
  853. */
  854. #define devm_clk_hw_register_divider(dev, name, parent_name, flags, reg, shift, \
  855. width, clk_divider_flags, lock) \
  856. __devm_clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL, \
  857. NULL, (flags), (reg), (shift), (width), \
  858. (clk_divider_flags), NULL, (lock))
  859. /**
  860. * devm_clk_hw_register_divider_parent_hw - register a divider clock with the clock framework
  861. * @dev: device registering this clock
  862. * @name: name of this clock
  863. * @parent_hw: pointer to parent clk
  864. * @flags: framework-specific flags
  865. * @reg: register address to adjust divider
  866. * @shift: number of bits to shift the bitfield
  867. * @width: width of the bitfield
  868. * @clk_divider_flags: divider-specific flags for this clock
  869. * @lock: shared register lock for this clock
  870. */
  871. #define devm_clk_hw_register_divider_parent_hw(dev, name, parent_hw, flags, \
  872. reg, shift, width, \
  873. clk_divider_flags, lock) \
  874. __devm_clk_hw_register_divider((dev), NULL, (name), NULL, \
  875. (parent_hw), NULL, (flags), (reg), \
  876. (shift), (width), (clk_divider_flags), \
  877. NULL, (lock))
  878. /**
  879. * devm_clk_hw_register_divider_table - register a table based divider clock
  880. * with the clock framework (devres variant)
  881. * @dev: device registering this clock
  882. * @name: name of this clock
  883. * @parent_name: name of clock's parent
  884. * @flags: framework-specific flags
  885. * @reg: register address to adjust divider
  886. * @shift: number of bits to shift the bitfield
  887. * @width: width of the bitfield
  888. * @clk_divider_flags: divider-specific flags for this clock
  889. * @table: array of divider/value pairs ending with a div set to 0
  890. * @lock: shared register lock for this clock
  891. */
  892. #define devm_clk_hw_register_divider_table(dev, name, parent_name, flags, \
  893. reg, shift, width, \
  894. clk_divider_flags, table, lock) \
  895. __devm_clk_hw_register_divider((dev), NULL, (name), (parent_name), \
  896. NULL, NULL, (flags), (reg), (shift), \
  897. (width), (clk_divider_flags), (table), \
  898. (lock))
  899. void clk_unregister_divider(struct clk *clk);
  900. void clk_hw_unregister_divider(struct clk_hw *hw);
  901. /**
  902. * struct clk_mux - multiplexer clock
  903. *
  904. * @hw: handle between common and hardware-specific interfaces
  905. * @reg: register controlling multiplexer
  906. * @table: array of register values corresponding to the parent index
  907. * @shift: shift to multiplexer bit field
  908. * @mask: mask of mutliplexer bit field
  909. * @flags: hardware-specific flags
  910. * @lock: register lock
  911. *
  912. * Clock with multiple selectable parents. Implements .get_parent, .set_parent
  913. * and .recalc_rate
  914. *
  915. * Flags:
  916. * CLK_MUX_INDEX_ONE - register index starts at 1, not 0
  917. * CLK_MUX_INDEX_BIT - register index is a single bit (power of two)
  918. * CLK_MUX_HIWORD_MASK - The mux settings are only in lower 16-bit of this
  919. * register, and mask of mux bits are in higher 16-bit of this register.
  920. * While setting the mux bits, higher 16-bit should also be updated to
  921. * indicate changing mux bits.
  922. * CLK_MUX_READ_ONLY - The mux registers can't be written, only read in the
  923. * .get_parent clk_op.
  924. * CLK_MUX_ROUND_CLOSEST - Use the parent rate that is closest to the desired
  925. * frequency.
  926. * CLK_MUX_BIG_ENDIAN - By default little endian register accesses are used for
  927. * the mux register. Setting this flag makes the register accesses big
  928. * endian.
  929. */
  930. struct clk_mux {
  931. struct clk_hw hw;
  932. void __iomem *reg;
  933. const u32 *table;
  934. u32 mask;
  935. u8 shift;
  936. u8 flags;
  937. spinlock_t *lock;
  938. };
  939. #define to_clk_mux(_hw) container_of(_hw, struct clk_mux, hw)
  940. #define CLK_MUX_INDEX_ONE BIT(0)
  941. #define CLK_MUX_INDEX_BIT BIT(1)
  942. #define CLK_MUX_HIWORD_MASK BIT(2)
  943. #define CLK_MUX_READ_ONLY BIT(3) /* mux can't be changed */
  944. #define CLK_MUX_ROUND_CLOSEST BIT(4)
  945. #define CLK_MUX_BIG_ENDIAN BIT(5)
  946. extern const struct clk_ops clk_mux_ops;
  947. extern const struct clk_ops clk_mux_ro_ops;
  948. struct clk_hw *__clk_hw_register_mux(struct device *dev, struct device_node *np,
  949. const char *name, u8 num_parents,
  950. const char * const *parent_names,
  951. const struct clk_hw **parent_hws,
  952. const struct clk_parent_data *parent_data,
  953. unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
  954. u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
  955. struct clk_hw *__devm_clk_hw_register_mux(struct device *dev, struct device_node *np,
  956. const char *name, u8 num_parents,
  957. const char * const *parent_names,
  958. const struct clk_hw **parent_hws,
  959. const struct clk_parent_data *parent_data,
  960. unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
  961. u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
  962. struct clk *clk_register_mux_table(struct device *dev, const char *name,
  963. const char * const *parent_names, u8 num_parents,
  964. unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
  965. u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
  966. #define clk_register_mux(dev, name, parent_names, num_parents, flags, reg, \
  967. shift, width, clk_mux_flags, lock) \
  968. clk_register_mux_table((dev), (name), (parent_names), (num_parents), \
  969. (flags), (reg), (shift), BIT((width)) - 1, \
  970. (clk_mux_flags), NULL, (lock))
  971. #define clk_hw_register_mux_table(dev, name, parent_names, num_parents, \
  972. flags, reg, shift, mask, clk_mux_flags, \
  973. table, lock) \
  974. __clk_hw_register_mux((dev), NULL, (name), (num_parents), \
  975. (parent_names), NULL, NULL, (flags), (reg), \
  976. (shift), (mask), (clk_mux_flags), (table), \
  977. (lock))
  978. #define clk_hw_register_mux_table_parent_data(dev, name, parent_data, \
  979. num_parents, flags, reg, shift, mask, \
  980. clk_mux_flags, table, lock) \
  981. __clk_hw_register_mux((dev), NULL, (name), (num_parents), \
  982. NULL, NULL, (parent_data), (flags), (reg), \
  983. (shift), (mask), (clk_mux_flags), (table), \
  984. (lock))
  985. #define clk_hw_register_mux(dev, name, parent_names, num_parents, flags, reg, \
  986. shift, width, clk_mux_flags, lock) \
  987. __clk_hw_register_mux((dev), NULL, (name), (num_parents), \
  988. (parent_names), NULL, NULL, (flags), (reg), \
  989. (shift), BIT((width)) - 1, (clk_mux_flags), \
  990. NULL, (lock))
  991. #define clk_hw_register_mux_hws(dev, name, parent_hws, num_parents, flags, \
  992. reg, shift, width, clk_mux_flags, lock) \
  993. __clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, \
  994. (parent_hws), NULL, (flags), (reg), (shift), \
  995. BIT((width)) - 1, (clk_mux_flags), NULL, (lock))
  996. #define clk_hw_register_mux_parent_data(dev, name, parent_data, num_parents, \
  997. flags, reg, shift, width, \
  998. clk_mux_flags, lock) \
  999. __clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, NULL, \
  1000. (parent_data), (flags), (reg), (shift), \
  1001. BIT((width)) - 1, (clk_mux_flags), NULL, (lock))
  1002. #define clk_hw_register_mux_parent_data_table(dev, name, parent_data, \
  1003. num_parents, flags, reg, shift, \
  1004. width, clk_mux_flags, table, \
  1005. lock) \
  1006. __clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, NULL, \
  1007. (parent_data), (flags), (reg), (shift), \
  1008. BIT((width)) - 1, (clk_mux_flags), table, (lock))
  1009. #define devm_clk_hw_register_mux(dev, name, parent_names, num_parents, flags, reg, \
  1010. shift, width, clk_mux_flags, lock) \
  1011. __devm_clk_hw_register_mux((dev), NULL, (name), (num_parents), \
  1012. (parent_names), NULL, NULL, (flags), (reg), \
  1013. (shift), BIT((width)) - 1, (clk_mux_flags), \
  1014. NULL, (lock))
  1015. #define devm_clk_hw_register_mux_parent_hws(dev, name, parent_hws, \
  1016. num_parents, flags, reg, shift, \
  1017. width, clk_mux_flags, lock) \
  1018. __devm_clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, \
  1019. (parent_hws), NULL, (flags), (reg), \
  1020. (shift), BIT((width)) - 1, \
  1021. (clk_mux_flags), NULL, (lock))
  1022. #define devm_clk_hw_register_mux_parent_data_table(dev, name, parent_data, \
  1023. num_parents, flags, reg, shift, \
  1024. width, clk_mux_flags, table, \
  1025. lock) \
  1026. __devm_clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, \
  1027. NULL, (parent_data), (flags), (reg), (shift), \
  1028. BIT((width)) - 1, (clk_mux_flags), table, (lock))
  1029. int clk_mux_val_to_index(struct clk_hw *hw, const u32 *table, unsigned int flags,
  1030. unsigned int val);
  1031. unsigned int clk_mux_index_to_val(const u32 *table, unsigned int flags, u8 index);
  1032. void clk_unregister_mux(struct clk *clk);
  1033. void clk_hw_unregister_mux(struct clk_hw *hw);
  1034. void of_fixed_factor_clk_setup(struct device_node *node);
  1035. /**
  1036. * struct clk_fixed_factor - fixed multiplier and divider clock
  1037. *
  1038. * @hw: handle between common and hardware-specific interfaces
  1039. * @mult: multiplier
  1040. * @div: divider
  1041. *
  1042. * Clock with a fixed multiplier and divider. The output frequency is the
  1043. * parent clock rate divided by div and multiplied by mult.
  1044. * Implements .recalc_rate, .set_rate and .round_rate
  1045. */
  1046. struct clk_fixed_factor {
  1047. struct clk_hw hw;
  1048. unsigned int mult;
  1049. unsigned int div;
  1050. };
  1051. #define to_clk_fixed_factor(_hw) container_of(_hw, struct clk_fixed_factor, hw)
  1052. extern const struct clk_ops clk_fixed_factor_ops;
  1053. struct clk *clk_register_fixed_factor(struct device *dev, const char *name,
  1054. const char *parent_name, unsigned long flags,
  1055. unsigned int mult, unsigned int div);
  1056. void clk_unregister_fixed_factor(struct clk *clk);
  1057. struct clk_hw *clk_hw_register_fixed_factor(struct device *dev,
  1058. const char *name, const char *parent_name, unsigned long flags,
  1059. unsigned int mult, unsigned int div);
  1060. void clk_hw_unregister_fixed_factor(struct clk_hw *hw);
  1061. struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev,
  1062. const char *name, const char *parent_name, unsigned long flags,
  1063. unsigned int mult, unsigned int div);
  1064. struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev,
  1065. const char *name, unsigned int index, unsigned long flags,
  1066. unsigned int mult, unsigned int div);
  1067. struct clk_hw *devm_clk_hw_register_fixed_factor_parent_hw(struct device *dev,
  1068. const char *name, const struct clk_hw *parent_hw,
  1069. unsigned long flags, unsigned int mult, unsigned int div);
  1070. struct clk_hw *clk_hw_register_fixed_factor_parent_hw(struct device *dev,
  1071. const char *name, const struct clk_hw *parent_hw,
  1072. unsigned long flags, unsigned int mult, unsigned int div);
  1073. /**
  1074. * struct clk_fractional_divider - adjustable fractional divider clock
  1075. *
  1076. * @hw: handle between common and hardware-specific interfaces
  1077. * @reg: register containing the divider
  1078. * @mshift: shift to the numerator bit field
  1079. * @mwidth: width of the numerator bit field
  1080. * @nshift: shift to the denominator bit field
  1081. * @nwidth: width of the denominator bit field
  1082. * @approximation: clk driver's callback for calculating the divider clock
  1083. * @lock: register lock
  1084. *
  1085. * Clock with adjustable fractional divider affecting its output frequency.
  1086. *
  1087. * @flags:
  1088. * CLK_FRAC_DIVIDER_ZERO_BASED - by default the numerator and denominator
  1089. * is the value read from the register. If CLK_FRAC_DIVIDER_ZERO_BASED
  1090. * is set then the numerator and denominator are both the value read
  1091. * plus one.
  1092. * CLK_FRAC_DIVIDER_BIG_ENDIAN - By default little endian register accesses are
  1093. * used for the divider register. Setting this flag makes the register
  1094. * accesses big endian.
  1095. * CLK_FRAC_DIVIDER_POWER_OF_TWO_PS - By default the resulting fraction might
  1096. * be saturated and the caller will get quite far from the good enough
  1097. * approximation. Instead the caller may require, by setting this flag,
  1098. * to shift left by a few bits in case, when the asked one is quite small
  1099. * to satisfy the desired range of denominator. It assumes that on the
  1100. * caller's side the power-of-two capable prescaler exists.
  1101. */
  1102. struct clk_fractional_divider {
  1103. struct clk_hw hw;
  1104. void __iomem *reg;
  1105. u8 mshift;
  1106. u8 mwidth;
  1107. u32 mmask;
  1108. u8 nshift;
  1109. u8 nwidth;
  1110. u32 nmask;
  1111. u8 flags;
  1112. void (*approximation)(struct clk_hw *hw,
  1113. unsigned long rate, unsigned long *parent_rate,
  1114. unsigned long *m, unsigned long *n);
  1115. spinlock_t *lock;
  1116. };
  1117. #define to_clk_fd(_hw) container_of(_hw, struct clk_fractional_divider, hw)
  1118. #define CLK_FRAC_DIVIDER_ZERO_BASED BIT(0)
  1119. #define CLK_FRAC_DIVIDER_BIG_ENDIAN BIT(1)
  1120. #define CLK_FRAC_DIVIDER_POWER_OF_TWO_PS BIT(2)
  1121. struct clk *clk_register_fractional_divider(struct device *dev,
  1122. const char *name, const char *parent_name, unsigned long flags,
  1123. void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth,
  1124. u8 clk_divider_flags, spinlock_t *lock);
  1125. struct clk_hw *clk_hw_register_fractional_divider(struct device *dev,
  1126. const char *name, const char *parent_name, unsigned long flags,
  1127. void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth,
  1128. u8 clk_divider_flags, spinlock_t *lock);
  1129. void clk_hw_unregister_fractional_divider(struct clk_hw *hw);
  1130. /**
  1131. * struct clk_multiplier - adjustable multiplier clock
  1132. *
  1133. * @hw: handle between common and hardware-specific interfaces
  1134. * @reg: register containing the multiplier
  1135. * @shift: shift to the multiplier bit field
  1136. * @width: width of the multiplier bit field
  1137. * @lock: register lock
  1138. *
  1139. * Clock with an adjustable multiplier affecting its output frequency.
  1140. * Implements .recalc_rate, .set_rate and .round_rate
  1141. *
  1142. * @flags:
  1143. * CLK_MULTIPLIER_ZERO_BYPASS - By default, the multiplier is the value read
  1144. * from the register, with 0 being a valid value effectively
  1145. * zeroing the output clock rate. If CLK_MULTIPLIER_ZERO_BYPASS is
  1146. * set, then a null multiplier will be considered as a bypass,
  1147. * leaving the parent rate unmodified.
  1148. * CLK_MULTIPLIER_ROUND_CLOSEST - Makes the best calculated divider to be
  1149. * rounded to the closest integer instead of the down one.
  1150. * CLK_MULTIPLIER_BIG_ENDIAN - By default little endian register accesses are
  1151. * used for the multiplier register. Setting this flag makes the register
  1152. * accesses big endian.
  1153. */
  1154. struct clk_multiplier {
  1155. struct clk_hw hw;
  1156. void __iomem *reg;
  1157. u8 shift;
  1158. u8 width;
  1159. u8 flags;
  1160. spinlock_t *lock;
  1161. };
  1162. #define to_clk_multiplier(_hw) container_of(_hw, struct clk_multiplier, hw)
  1163. #define CLK_MULTIPLIER_ZERO_BYPASS BIT(0)
  1164. #define CLK_MULTIPLIER_ROUND_CLOSEST BIT(1)
  1165. #define CLK_MULTIPLIER_BIG_ENDIAN BIT(2)
  1166. extern const struct clk_ops clk_multiplier_ops;
  1167. /***
  1168. * struct clk_composite - aggregate clock of mux, divider and gate clocks
  1169. *
  1170. * @hw: handle between common and hardware-specific interfaces
  1171. * @mux_hw: handle between composite and hardware-specific mux clock
  1172. * @rate_hw: handle between composite and hardware-specific rate clock
  1173. * @gate_hw: handle between composite and hardware-specific gate clock
  1174. * @mux_ops: clock ops for mux
  1175. * @rate_ops: clock ops for rate
  1176. * @gate_ops: clock ops for gate
  1177. */
  1178. struct clk_composite {
  1179. struct clk_hw hw;
  1180. struct clk_ops ops;
  1181. struct clk_hw *mux_hw;
  1182. struct clk_hw *rate_hw;
  1183. struct clk_hw *gate_hw;
  1184. const struct clk_ops *mux_ops;
  1185. const struct clk_ops *rate_ops;
  1186. const struct clk_ops *gate_ops;
  1187. };
  1188. #define to_clk_composite(_hw) container_of(_hw, struct clk_composite, hw)
  1189. struct clk *clk_register_composite(struct device *dev, const char *name,
  1190. const char * const *parent_names, int num_parents,
  1191. struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
  1192. struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
  1193. struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
  1194. unsigned long flags);
  1195. struct clk *clk_register_composite_pdata(struct device *dev, const char *name,
  1196. const struct clk_parent_data *parent_data, int num_parents,
  1197. struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
  1198. struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
  1199. struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
  1200. unsigned long flags);
  1201. void clk_unregister_composite(struct clk *clk);
  1202. struct clk_hw *clk_hw_register_composite(struct device *dev, const char *name,
  1203. const char * const *parent_names, int num_parents,
  1204. struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
  1205. struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
  1206. struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
  1207. unsigned long flags);
  1208. struct clk_hw *clk_hw_register_composite_pdata(struct device *dev,
  1209. const char *name,
  1210. const struct clk_parent_data *parent_data, int num_parents,
  1211. struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
  1212. struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
  1213. struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
  1214. unsigned long flags);
  1215. struct clk_hw *devm_clk_hw_register_composite_pdata(struct device *dev,
  1216. const char *name, const struct clk_parent_data *parent_data,
  1217. int num_parents,
  1218. struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
  1219. struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
  1220. struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
  1221. unsigned long flags);
  1222. void clk_hw_unregister_composite(struct clk_hw *hw);
  1223. struct clk *clk_register(struct device *dev, struct clk_hw *hw);
  1224. struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw);
  1225. int __must_check clk_hw_register(struct device *dev, struct clk_hw *hw);
  1226. int __must_check devm_clk_hw_register(struct device *dev, struct clk_hw *hw);
  1227. int __must_check of_clk_hw_register(struct device_node *node, struct clk_hw *hw);
  1228. void clk_unregister(struct clk *clk);
  1229. void clk_hw_unregister(struct clk_hw *hw);
  1230. void clk_sync_state(struct device *dev);
  1231. /* helper functions */
  1232. const char *__clk_get_name(const struct clk *clk);
  1233. const char *clk_hw_get_name(const struct clk_hw *hw);
  1234. #ifdef CONFIG_COMMON_CLK
  1235. struct clk_hw *__clk_get_hw(struct clk *clk);
  1236. #else
  1237. static inline struct clk_hw *__clk_get_hw(struct clk *clk)
  1238. {
  1239. return (struct clk_hw *)clk;
  1240. }
  1241. #endif
  1242. struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *con_id);
  1243. struct clk *devm_clk_hw_get_clk(struct device *dev, struct clk_hw *hw,
  1244. const char *con_id);
  1245. unsigned int clk_hw_get_num_parents(const struct clk_hw *hw);
  1246. struct clk_hw *clk_hw_get_parent(const struct clk_hw *hw);
  1247. struct clk_hw *clk_hw_get_parent_by_index(const struct clk_hw *hw,
  1248. unsigned int index);
  1249. int clk_hw_get_parent_index(struct clk_hw *hw);
  1250. int clk_hw_set_parent(struct clk_hw *hw, struct clk_hw *new_parent);
  1251. unsigned int __clk_get_enable_count(struct clk *clk);
  1252. unsigned long clk_hw_get_rate(const struct clk_hw *hw);
  1253. unsigned long clk_hw_get_flags(const struct clk_hw *hw);
  1254. #define clk_hw_can_set_rate_parent(hw) \
  1255. (clk_hw_get_flags((hw)) & CLK_SET_RATE_PARENT)
  1256. bool clk_hw_is_prepared(const struct clk_hw *hw);
  1257. bool clk_hw_rate_is_protected(const struct clk_hw *hw);
  1258. bool clk_hw_is_enabled(const struct clk_hw *hw);
  1259. bool __clk_is_enabled(struct clk *clk);
  1260. struct clk *__clk_lookup(const char *name);
  1261. int __clk_mux_determine_rate(struct clk_hw *hw,
  1262. struct clk_rate_request *req);
  1263. int __clk_determine_rate(struct clk_hw *core, struct clk_rate_request *req);
  1264. int __clk_mux_determine_rate_closest(struct clk_hw *hw,
  1265. struct clk_rate_request *req);
  1266. int clk_mux_determine_rate_flags(struct clk_hw *hw,
  1267. struct clk_rate_request *req,
  1268. unsigned long flags);
  1269. void clk_hw_reparent(struct clk_hw *hw, struct clk_hw *new_parent);
  1270. void clk_hw_get_rate_range(struct clk_hw *hw, unsigned long *min_rate,
  1271. unsigned long *max_rate);
  1272. void clk_hw_set_rate_range(struct clk_hw *hw, unsigned long min_rate,
  1273. unsigned long max_rate);
  1274. static inline void __clk_hw_set_clk(struct clk_hw *dst, struct clk_hw *src)
  1275. {
  1276. dst->clk = src->clk;
  1277. dst->core = src->core;
  1278. }
  1279. static inline long divider_round_rate(struct clk_hw *hw, unsigned long rate,
  1280. unsigned long *prate,
  1281. const struct clk_div_table *table,
  1282. u8 width, unsigned long flags)
  1283. {
  1284. return divider_round_rate_parent(hw, clk_hw_get_parent(hw),
  1285. rate, prate, table, width, flags);
  1286. }
  1287. static inline long divider_ro_round_rate(struct clk_hw *hw, unsigned long rate,
  1288. unsigned long *prate,
  1289. const struct clk_div_table *table,
  1290. u8 width, unsigned long flags,
  1291. unsigned int val)
  1292. {
  1293. return divider_ro_round_rate_parent(hw, clk_hw_get_parent(hw),
  1294. rate, prate, table, width, flags,
  1295. val);
  1296. }
  1297. /*
  1298. * FIXME clock api without lock protection
  1299. */
  1300. unsigned long clk_hw_round_rate(struct clk_hw *hw, unsigned long rate);
  1301. struct clk_onecell_data {
  1302. struct clk **clks;
  1303. unsigned int clk_num;
  1304. };
  1305. struct clk_hw_onecell_data {
  1306. unsigned int num;
  1307. struct clk_hw *hws[];
  1308. };
  1309. #define CLK_OF_DECLARE(name, compat, fn) \
  1310. static void __init __##name##_of_clk_init_declare(struct device_node *np) \
  1311. { \
  1312. fn(np); \
  1313. fwnode_dev_initialized(of_fwnode_handle(np), true); \
  1314. } \
  1315. OF_DECLARE_1(clk, name, compat, __##name##_of_clk_init_declare)
  1316. /*
  1317. * Use this macro when you have a driver that requires two initialization
  1318. * routines, one at of_clk_init(), and one at platform device probe
  1319. */
  1320. #define CLK_OF_DECLARE_DRIVER(name, compat, fn) \
  1321. static void __init name##_of_clk_init_driver(struct device_node *np) \
  1322. { \
  1323. of_node_clear_flag(np, OF_POPULATED); \
  1324. fn(np); \
  1325. } \
  1326. OF_DECLARE_1(clk, name, compat, name##_of_clk_init_driver)
  1327. #define CLK_HW_INIT(_name, _parent, _ops, _flags) \
  1328. (&(struct clk_init_data) { \
  1329. .flags = _flags, \
  1330. .name = _name, \
  1331. .parent_names = (const char *[]) { _parent }, \
  1332. .num_parents = 1, \
  1333. .ops = _ops, \
  1334. })
  1335. #define CLK_HW_INIT_HW(_name, _parent, _ops, _flags) \
  1336. (&(struct clk_init_data) { \
  1337. .flags = _flags, \
  1338. .name = _name, \
  1339. .parent_hws = (const struct clk_hw*[]) { _parent }, \
  1340. .num_parents = 1, \
  1341. .ops = _ops, \
  1342. })
  1343. /*
  1344. * This macro is intended for drivers to be able to share the otherwise
  1345. * individual struct clk_hw[] compound literals created by the compiler
  1346. * when using CLK_HW_INIT_HW. It does NOT support multiple parents.
  1347. */
  1348. #define CLK_HW_INIT_HWS(_name, _parent, _ops, _flags) \
  1349. (&(struct clk_init_data) { \
  1350. .flags = _flags, \
  1351. .name = _name, \
  1352. .parent_hws = _parent, \
  1353. .num_parents = 1, \
  1354. .ops = _ops, \
  1355. })
  1356. #define CLK_HW_INIT_FW_NAME(_name, _parent, _ops, _flags) \
  1357. (&(struct clk_init_data) { \
  1358. .flags = _flags, \
  1359. .name = _name, \
  1360. .parent_data = (const struct clk_parent_data[]) { \
  1361. { .fw_name = _parent }, \
  1362. }, \
  1363. .num_parents = 1, \
  1364. .ops = _ops, \
  1365. })
  1366. #define CLK_HW_INIT_PARENTS(_name, _parents, _ops, _flags) \
  1367. (&(struct clk_init_data) { \
  1368. .flags = _flags, \
  1369. .name = _name, \
  1370. .parent_names = _parents, \
  1371. .num_parents = ARRAY_SIZE(_parents), \
  1372. .ops = _ops, \
  1373. })
  1374. #define CLK_HW_INIT_PARENTS_HW(_name, _parents, _ops, _flags) \
  1375. (&(struct clk_init_data) { \
  1376. .flags = _flags, \
  1377. .name = _name, \
  1378. .parent_hws = _parents, \
  1379. .num_parents = ARRAY_SIZE(_parents), \
  1380. .ops = _ops, \
  1381. })
  1382. #define CLK_HW_INIT_PARENTS_DATA(_name, _parents, _ops, _flags) \
  1383. (&(struct clk_init_data) { \
  1384. .flags = _flags, \
  1385. .name = _name, \
  1386. .parent_data = _parents, \
  1387. .num_parents = ARRAY_SIZE(_parents), \
  1388. .ops = _ops, \
  1389. })
  1390. #define CLK_HW_INIT_NO_PARENT(_name, _ops, _flags) \
  1391. (&(struct clk_init_data) { \
  1392. .flags = _flags, \
  1393. .name = _name, \
  1394. .parent_names = NULL, \
  1395. .num_parents = 0, \
  1396. .ops = _ops, \
  1397. })
  1398. #define CLK_FIXED_FACTOR(_struct, _name, _parent, \
  1399. _div, _mult, _flags) \
  1400. struct clk_fixed_factor _struct = { \
  1401. .div = _div, \
  1402. .mult = _mult, \
  1403. .hw.init = CLK_HW_INIT(_name, \
  1404. _parent, \
  1405. &clk_fixed_factor_ops, \
  1406. _flags), \
  1407. }
  1408. #define CLK_FIXED_FACTOR_HW(_struct, _name, _parent, \
  1409. _div, _mult, _flags) \
  1410. struct clk_fixed_factor _struct = { \
  1411. .div = _div, \
  1412. .mult = _mult, \
  1413. .hw.init = CLK_HW_INIT_HW(_name, \
  1414. _parent, \
  1415. &clk_fixed_factor_ops, \
  1416. _flags), \
  1417. }
  1418. /*
  1419. * This macro allows the driver to reuse the _parent array for multiple
  1420. * fixed factor clk declarations.
  1421. */
  1422. #define CLK_FIXED_FACTOR_HWS(_struct, _name, _parent, \
  1423. _div, _mult, _flags) \
  1424. struct clk_fixed_factor _struct = { \
  1425. .div = _div, \
  1426. .mult = _mult, \
  1427. .hw.init = CLK_HW_INIT_HWS(_name, \
  1428. _parent, \
  1429. &clk_fixed_factor_ops, \
  1430. _flags), \
  1431. }
  1432. #define CLK_FIXED_FACTOR_FW_NAME(_struct, _name, _parent, \
  1433. _div, _mult, _flags) \
  1434. struct clk_fixed_factor _struct = { \
  1435. .div = _div, \
  1436. .mult = _mult, \
  1437. .hw.init = CLK_HW_INIT_FW_NAME(_name, \
  1438. _parent, \
  1439. &clk_fixed_factor_ops, \
  1440. _flags), \
  1441. }
  1442. #ifdef CONFIG_OF
  1443. int of_clk_add_provider(struct device_node *np,
  1444. struct clk *(*clk_src_get)(struct of_phandle_args *args,
  1445. void *data),
  1446. void *data);
  1447. int of_clk_add_hw_provider(struct device_node *np,
  1448. struct clk_hw *(*get)(struct of_phandle_args *clkspec,
  1449. void *data),
  1450. void *data);
  1451. int devm_of_clk_add_hw_provider(struct device *dev,
  1452. struct clk_hw *(*get)(struct of_phandle_args *clkspec,
  1453. void *data),
  1454. void *data);
  1455. void of_clk_del_provider(struct device_node *np);
  1456. struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
  1457. void *data);
  1458. struct clk_hw *of_clk_hw_simple_get(struct of_phandle_args *clkspec,
  1459. void *data);
  1460. struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
  1461. struct clk_hw *of_clk_hw_onecell_get(struct of_phandle_args *clkspec,
  1462. void *data);
  1463. int of_clk_parent_fill(struct device_node *np, const char **parents,
  1464. unsigned int size);
  1465. int of_clk_detect_critical(struct device_node *np, int index,
  1466. unsigned long *flags);
  1467. #else /* !CONFIG_OF */
  1468. static inline int of_clk_add_provider(struct device_node *np,
  1469. struct clk *(*clk_src_get)(struct of_phandle_args *args,
  1470. void *data),
  1471. void *data)
  1472. {
  1473. return 0;
  1474. }
  1475. static inline int of_clk_add_hw_provider(struct device_node *np,
  1476. struct clk_hw *(*get)(struct of_phandle_args *clkspec,
  1477. void *data),
  1478. void *data)
  1479. {
  1480. return 0;
  1481. }
  1482. static inline int devm_of_clk_add_hw_provider(struct device *dev,
  1483. struct clk_hw *(*get)(struct of_phandle_args *clkspec,
  1484. void *data),
  1485. void *data)
  1486. {
  1487. return 0;
  1488. }
  1489. static inline void of_clk_del_provider(struct device_node *np) {}
  1490. static inline struct clk *of_clk_src_simple_get(
  1491. struct of_phandle_args *clkspec, void *data)
  1492. {
  1493. return ERR_PTR(-ENOENT);
  1494. }
  1495. static inline struct clk_hw *
  1496. of_clk_hw_simple_get(struct of_phandle_args *clkspec, void *data)
  1497. {
  1498. return ERR_PTR(-ENOENT);
  1499. }
  1500. static inline struct clk *of_clk_src_onecell_get(
  1501. struct of_phandle_args *clkspec, void *data)
  1502. {
  1503. return ERR_PTR(-ENOENT);
  1504. }
  1505. static inline struct clk_hw *
  1506. of_clk_hw_onecell_get(struct of_phandle_args *clkspec, void *data)
  1507. {
  1508. return ERR_PTR(-ENOENT);
  1509. }
  1510. static inline int of_clk_parent_fill(struct device_node *np,
  1511. const char **parents, unsigned int size)
  1512. {
  1513. return 0;
  1514. }
  1515. static inline int of_clk_detect_critical(struct device_node *np, int index,
  1516. unsigned long *flags)
  1517. {
  1518. return 0;
  1519. }
  1520. #endif /* CONFIG_OF */
  1521. void clk_gate_restore_context(struct clk_hw *hw);
  1522. #endif /* CLK_PROVIDER_H */