omap_hwmod.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009
  1. /*
  2. * omap_hwmod implementation for OMAP2/3/4
  3. *
  4. * Copyright (C) 2009-2010 Nokia Corporation
  5. *
  6. * Paul Walmsley, Benoît Cousson, Kevin Hilman
  7. *
  8. * Created in collaboration with (alphabetical order): Thara Gopinath,
  9. * Tony Lindgren, Rajendra Nayak, Vikram Pandita, Sakari Poussa, Anand
  10. * Sawant, Santosh Shilimkar, Richard Woodruff
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. * This code manages "OMAP modules" (on-chip devices) and their
  17. * integration with Linux device driver and bus code.
  18. *
  19. * References:
  20. * - OMAP2420 Multimedia Processor Silicon Revision 2.1.1, 2.2 (SWPU064)
  21. * - OMAP2430 Multimedia Device POP Silicon Revision 2.1 (SWPU090)
  22. * - OMAP34xx Multimedia Device Silicon Revision 3.1 (SWPU108)
  23. * - OMAP4430 Multimedia Device Silicon Revision 1.0 (SWPU140)
  24. * - Open Core Protocol Specification 2.2
  25. *
  26. * To do:
  27. * - pin mux handling
  28. * - handle IO mapping
  29. * - bus throughput & module latency measurement code
  30. *
  31. * XXX add tests at the beginning of each function to ensure the hwmod is
  32. * in the appropriate state
  33. * XXX error return values should be checked to ensure that they are
  34. * appropriate
  35. */
  36. #undef DEBUG
  37. #include <linux/kernel.h>
  38. #include <linux/errno.h>
  39. #include <linux/io.h>
  40. #include <linux/clk.h>
  41. #include <linux/delay.h>
  42. #include <linux/err.h>
  43. #include <linux/list.h>
  44. #include <linux/mutex.h>
  45. #include <plat/common.h>
  46. #include <plat/cpu.h>
  47. #include <plat/clockdomain.h>
  48. #include <plat/powerdomain.h>
  49. #include <plat/clock.h>
  50. #include <plat/omap_hwmod.h>
  51. #include <plat/prcm.h>
  52. #include "cm.h"
  53. #include "prm.h"
  54. /* Maximum microseconds to wait for OMAP module to softreset */
  55. #define MAX_MODULE_SOFTRESET_WAIT 10000
  56. /* Name of the OMAP hwmod for the MPU */
  57. #define MPU_INITIATOR_NAME "mpu"
  58. /* omap_hwmod_list contains all registered struct omap_hwmods */
  59. static LIST_HEAD(omap_hwmod_list);
  60. static DEFINE_MUTEX(omap_hwmod_mutex);
  61. /* mpu_oh: used to add/remove MPU initiator from sleepdep list */
  62. static struct omap_hwmod *mpu_oh;
  63. /* inited: 0 if omap_hwmod_init() has not yet been called; 1 otherwise */
  64. static u8 inited;
  65. /* Private functions */
  66. /**
  67. * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
  68. * @oh: struct omap_hwmod *
  69. *
  70. * Load the current value of the hwmod OCP_SYSCONFIG register into the
  71. * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no
  72. * OCP_SYSCONFIG register or 0 upon success.
  73. */
  74. static int _update_sysc_cache(struct omap_hwmod *oh)
  75. {
  76. if (!oh->class->sysc) {
  77. WARN(1, "omap_hwmod: %s: cannot read OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
  78. return -EINVAL;
  79. }
  80. /* XXX ensure module interface clock is up */
  81. oh->_sysc_cache = omap_hwmod_readl(oh, oh->class->sysc->sysc_offs);
  82. if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
  83. oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
  84. return 0;
  85. }
  86. /**
  87. * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
  88. * @v: OCP_SYSCONFIG value to write
  89. * @oh: struct omap_hwmod *
  90. *
  91. * Write @v into the module class' OCP_SYSCONFIG register, if it has
  92. * one. No return value.
  93. */
  94. static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
  95. {
  96. if (!oh->class->sysc) {
  97. WARN(1, "omap_hwmod: %s: cannot write OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
  98. return;
  99. }
  100. /* XXX ensure module interface clock is up */
  101. if (oh->_sysc_cache != v) {
  102. oh->_sysc_cache = v;
  103. omap_hwmod_writel(v, oh, oh->class->sysc->sysc_offs);
  104. }
  105. }
  106. /**
  107. * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v
  108. * @oh: struct omap_hwmod *
  109. * @standbymode: MIDLEMODE field bits
  110. * @v: pointer to register contents to modify
  111. *
  112. * Update the master standby mode bits in @v to be @standbymode for
  113. * the @oh hwmod. Does not write to the hardware. Returns -EINVAL
  114. * upon error or 0 upon success.
  115. */
  116. static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
  117. u32 *v)
  118. {
  119. u32 mstandby_mask;
  120. u8 mstandby_shift;
  121. if (!oh->class->sysc ||
  122. !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE))
  123. return -EINVAL;
  124. if (!oh->class->sysc->sysc_fields) {
  125. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  126. return -EINVAL;
  127. }
  128. mstandby_shift = oh->class->sysc->sysc_fields->midle_shift;
  129. mstandby_mask = (0x3 << mstandby_shift);
  130. *v &= ~mstandby_mask;
  131. *v |= __ffs(standbymode) << mstandby_shift;
  132. return 0;
  133. }
  134. /**
  135. * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
  136. * @oh: struct omap_hwmod *
  137. * @idlemode: SIDLEMODE field bits
  138. * @v: pointer to register contents to modify
  139. *
  140. * Update the slave idle mode bits in @v to be @idlemode for the @oh
  141. * hwmod. Does not write to the hardware. Returns -EINVAL upon error
  142. * or 0 upon success.
  143. */
  144. static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
  145. {
  146. u32 sidle_mask;
  147. u8 sidle_shift;
  148. if (!oh->class->sysc ||
  149. !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE))
  150. return -EINVAL;
  151. if (!oh->class->sysc->sysc_fields) {
  152. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  153. return -EINVAL;
  154. }
  155. sidle_shift = oh->class->sysc->sysc_fields->sidle_shift;
  156. sidle_mask = (0x3 << sidle_shift);
  157. *v &= ~sidle_mask;
  158. *v |= __ffs(idlemode) << sidle_shift;
  159. return 0;
  160. }
  161. /**
  162. * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
  163. * @oh: struct omap_hwmod *
  164. * @clockact: CLOCKACTIVITY field bits
  165. * @v: pointer to register contents to modify
  166. *
  167. * Update the clockactivity mode bits in @v to be @clockact for the
  168. * @oh hwmod. Used for additional powersaving on some modules. Does
  169. * not write to the hardware. Returns -EINVAL upon error or 0 upon
  170. * success.
  171. */
  172. static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
  173. {
  174. u32 clkact_mask;
  175. u8 clkact_shift;
  176. if (!oh->class->sysc ||
  177. !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
  178. return -EINVAL;
  179. if (!oh->class->sysc->sysc_fields) {
  180. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  181. return -EINVAL;
  182. }
  183. clkact_shift = oh->class->sysc->sysc_fields->clkact_shift;
  184. clkact_mask = (0x3 << clkact_shift);
  185. *v &= ~clkact_mask;
  186. *v |= clockact << clkact_shift;
  187. return 0;
  188. }
  189. /**
  190. * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
  191. * @oh: struct omap_hwmod *
  192. * @v: pointer to register contents to modify
  193. *
  194. * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
  195. * error or 0 upon success.
  196. */
  197. static int _set_softreset(struct omap_hwmod *oh, u32 *v)
  198. {
  199. u32 softrst_mask;
  200. if (!oh->class->sysc ||
  201. !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
  202. return -EINVAL;
  203. if (!oh->class->sysc->sysc_fields) {
  204. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  205. return -EINVAL;
  206. }
  207. softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
  208. *v |= softrst_mask;
  209. return 0;
  210. }
  211. /**
  212. * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v
  213. * @oh: struct omap_hwmod *
  214. * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
  215. * @v: pointer to register contents to modify
  216. *
  217. * Update the module autoidle bit in @v to be @autoidle for the @oh
  218. * hwmod. The autoidle bit controls whether the module can gate
  219. * internal clocks automatically when it isn't doing anything; the
  220. * exact function of this bit varies on a per-module basis. This
  221. * function does not write to the hardware. Returns -EINVAL upon
  222. * error or 0 upon success.
  223. */
  224. static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle,
  225. u32 *v)
  226. {
  227. u32 autoidle_mask;
  228. u8 autoidle_shift;
  229. if (!oh->class->sysc ||
  230. !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE))
  231. return -EINVAL;
  232. if (!oh->class->sysc->sysc_fields) {
  233. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  234. return -EINVAL;
  235. }
  236. autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift;
  237. autoidle_mask = (0x3 << autoidle_shift);
  238. *v &= ~autoidle_mask;
  239. *v |= autoidle << autoidle_shift;
  240. return 0;
  241. }
  242. /**
  243. * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
  244. * @oh: struct omap_hwmod *
  245. *
  246. * Allow the hardware module @oh to send wakeups. Returns -EINVAL
  247. * upon error or 0 upon success.
  248. */
  249. static int _enable_wakeup(struct omap_hwmod *oh)
  250. {
  251. u32 v, wakeup_mask;
  252. if (!oh->class->sysc ||
  253. !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
  254. return -EINVAL;
  255. if (!oh->class->sysc->sysc_fields) {
  256. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  257. return -EINVAL;
  258. }
  259. wakeup_mask = (0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
  260. v = oh->_sysc_cache;
  261. v |= wakeup_mask;
  262. _write_sysconfig(v, oh);
  263. /* XXX test pwrdm_get_wken for this hwmod's subsystem */
  264. oh->_int_flags |= _HWMOD_WAKEUP_ENABLED;
  265. return 0;
  266. }
  267. /**
  268. * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
  269. * @oh: struct omap_hwmod *
  270. *
  271. * Prevent the hardware module @oh to send wakeups. Returns -EINVAL
  272. * upon error or 0 upon success.
  273. */
  274. static int _disable_wakeup(struct omap_hwmod *oh)
  275. {
  276. u32 v, wakeup_mask;
  277. if (!oh->class->sysc ||
  278. !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
  279. return -EINVAL;
  280. if (!oh->class->sysc->sysc_fields) {
  281. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  282. return -EINVAL;
  283. }
  284. wakeup_mask = (0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
  285. v = oh->_sysc_cache;
  286. v &= ~wakeup_mask;
  287. _write_sysconfig(v, oh);
  288. /* XXX test pwrdm_get_wken for this hwmod's subsystem */
  289. oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED;
  290. return 0;
  291. }
  292. /**
  293. * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
  294. * @oh: struct omap_hwmod *
  295. *
  296. * Prevent the hardware module @oh from entering idle while the
  297. * hardare module initiator @init_oh is active. Useful when a module
  298. * will be accessed by a particular initiator (e.g., if a module will
  299. * be accessed by the IVA, there should be a sleepdep between the IVA
  300. * initiator and the module). Only applies to modules in smart-idle
  301. * mode. Returns -EINVAL upon error or passes along
  302. * clkdm_add_sleepdep() value upon success.
  303. */
  304. static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
  305. {
  306. if (!oh->_clk)
  307. return -EINVAL;
  308. return clkdm_add_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
  309. }
  310. /**
  311. * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
  312. * @oh: struct omap_hwmod *
  313. *
  314. * Allow the hardware module @oh to enter idle while the hardare
  315. * module initiator @init_oh is active. Useful when a module will not
  316. * be accessed by a particular initiator (e.g., if a module will not
  317. * be accessed by the IVA, there should be no sleepdep between the IVA
  318. * initiator and the module). Only applies to modules in smart-idle
  319. * mode. Returns -EINVAL upon error or passes along
  320. * clkdm_del_sleepdep() value upon success.
  321. */
  322. static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
  323. {
  324. if (!oh->_clk)
  325. return -EINVAL;
  326. return clkdm_del_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
  327. }
  328. /**
  329. * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
  330. * @oh: struct omap_hwmod *
  331. *
  332. * Called from _init_clocks(). Populates the @oh _clk (main
  333. * functional clock pointer) if a main_clk is present. Returns 0 on
  334. * success or -EINVAL on error.
  335. */
  336. static int _init_main_clk(struct omap_hwmod *oh)
  337. {
  338. int ret = 0;
  339. if (!oh->main_clk)
  340. return 0;
  341. oh->_clk = omap_clk_get_by_name(oh->main_clk);
  342. if (!oh->_clk) {
  343. pr_warning("omap_hwmod: %s: cannot clk_get main_clk %s\n",
  344. oh->name, oh->main_clk);
  345. return -EINVAL;
  346. }
  347. if (!oh->_clk->clkdm)
  348. pr_warning("omap_hwmod: %s: missing clockdomain for %s.\n",
  349. oh->main_clk, oh->_clk->name);
  350. return ret;
  351. }
  352. /**
  353. * _init_interface_clks - get a struct clk * for the the hwmod's interface clks
  354. * @oh: struct omap_hwmod *
  355. *
  356. * Called from _init_clocks(). Populates the @oh OCP slave interface
  357. * clock pointers. Returns 0 on success or -EINVAL on error.
  358. */
  359. static int _init_interface_clks(struct omap_hwmod *oh)
  360. {
  361. struct clk *c;
  362. int i;
  363. int ret = 0;
  364. if (oh->slaves_cnt == 0)
  365. return 0;
  366. for (i = 0; i < oh->slaves_cnt; i++) {
  367. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  368. if (!os->clk)
  369. continue;
  370. c = omap_clk_get_by_name(os->clk);
  371. if (!c) {
  372. pr_warning("omap_hwmod: %s: cannot clk_get interface_clk %s\n",
  373. oh->name, os->clk);
  374. ret = -EINVAL;
  375. }
  376. os->_clk = c;
  377. }
  378. return ret;
  379. }
  380. /**
  381. * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
  382. * @oh: struct omap_hwmod *
  383. *
  384. * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk
  385. * clock pointers. Returns 0 on success or -EINVAL on error.
  386. */
  387. static int _init_opt_clks(struct omap_hwmod *oh)
  388. {
  389. struct omap_hwmod_opt_clk *oc;
  390. struct clk *c;
  391. int i;
  392. int ret = 0;
  393. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
  394. c = omap_clk_get_by_name(oc->clk);
  395. if (!c) {
  396. pr_warning("omap_hwmod: %s: cannot clk_get opt_clk %s\n",
  397. oh->name, oc->clk);
  398. ret = -EINVAL;
  399. }
  400. oc->_clk = c;
  401. }
  402. return ret;
  403. }
  404. /**
  405. * _enable_clocks - enable hwmod main clock and interface clocks
  406. * @oh: struct omap_hwmod *
  407. *
  408. * Enables all clocks necessary for register reads and writes to succeed
  409. * on the hwmod @oh. Returns 0.
  410. */
  411. static int _enable_clocks(struct omap_hwmod *oh)
  412. {
  413. int i;
  414. pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
  415. if (oh->_clk)
  416. clk_enable(oh->_clk);
  417. if (oh->slaves_cnt > 0) {
  418. for (i = 0; i < oh->slaves_cnt; i++) {
  419. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  420. struct clk *c = os->_clk;
  421. if (c && (os->flags & OCPIF_SWSUP_IDLE))
  422. clk_enable(c);
  423. }
  424. }
  425. /* The opt clocks are controlled by the device driver. */
  426. return 0;
  427. }
  428. /**
  429. * _disable_clocks - disable hwmod main clock and interface clocks
  430. * @oh: struct omap_hwmod *
  431. *
  432. * Disables the hwmod @oh main functional and interface clocks. Returns 0.
  433. */
  434. static int _disable_clocks(struct omap_hwmod *oh)
  435. {
  436. int i;
  437. pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
  438. if (oh->_clk)
  439. clk_disable(oh->_clk);
  440. if (oh->slaves_cnt > 0) {
  441. for (i = 0; i < oh->slaves_cnt; i++) {
  442. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  443. struct clk *c = os->_clk;
  444. if (c && (os->flags & OCPIF_SWSUP_IDLE))
  445. clk_disable(c);
  446. }
  447. }
  448. /* The opt clocks are controlled by the device driver. */
  449. return 0;
  450. }
  451. static void _enable_optional_clocks(struct omap_hwmod *oh)
  452. {
  453. struct omap_hwmod_opt_clk *oc;
  454. int i;
  455. pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name);
  456. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  457. if (oc->_clk) {
  458. pr_debug("omap_hwmod: enable %s:%s\n", oc->role,
  459. oc->_clk->name);
  460. clk_enable(oc->_clk);
  461. }
  462. }
  463. static void _disable_optional_clocks(struct omap_hwmod *oh)
  464. {
  465. struct omap_hwmod_opt_clk *oc;
  466. int i;
  467. pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name);
  468. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  469. if (oc->_clk) {
  470. pr_debug("omap_hwmod: disable %s:%s\n", oc->role,
  471. oc->_clk->name);
  472. clk_disable(oc->_clk);
  473. }
  474. }
  475. /**
  476. * _find_mpu_port_index - find hwmod OCP slave port ID intended for MPU use
  477. * @oh: struct omap_hwmod *
  478. *
  479. * Returns the array index of the OCP slave port that the MPU
  480. * addresses the device on, or -EINVAL upon error or not found.
  481. */
  482. static int _find_mpu_port_index(struct omap_hwmod *oh)
  483. {
  484. int i;
  485. int found = 0;
  486. if (!oh || oh->slaves_cnt == 0)
  487. return -EINVAL;
  488. for (i = 0; i < oh->slaves_cnt; i++) {
  489. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  490. if (os->user & OCP_USER_MPU) {
  491. found = 1;
  492. break;
  493. }
  494. }
  495. if (found)
  496. pr_debug("omap_hwmod: %s: MPU OCP slave port ID %d\n",
  497. oh->name, i);
  498. else
  499. pr_debug("omap_hwmod: %s: no MPU OCP slave port found\n",
  500. oh->name);
  501. return (found) ? i : -EINVAL;
  502. }
  503. /**
  504. * _find_mpu_rt_base - find hwmod register target base addr accessible by MPU
  505. * @oh: struct omap_hwmod *
  506. *
  507. * Return the virtual address of the base of the register target of
  508. * device @oh, or NULL on error.
  509. */
  510. static void __iomem *_find_mpu_rt_base(struct omap_hwmod *oh, u8 index)
  511. {
  512. struct omap_hwmod_ocp_if *os;
  513. struct omap_hwmod_addr_space *mem;
  514. int i;
  515. int found = 0;
  516. void __iomem *va_start;
  517. if (!oh || oh->slaves_cnt == 0)
  518. return NULL;
  519. os = oh->slaves[index];
  520. for (i = 0, mem = os->addr; i < os->addr_cnt; i++, mem++) {
  521. if (mem->flags & ADDR_TYPE_RT) {
  522. found = 1;
  523. break;
  524. }
  525. }
  526. if (found) {
  527. va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start);
  528. if (!va_start) {
  529. pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name);
  530. return NULL;
  531. }
  532. pr_debug("omap_hwmod: %s: MPU register target at va %p\n",
  533. oh->name, va_start);
  534. } else {
  535. pr_debug("omap_hwmod: %s: no MPU register target found\n",
  536. oh->name);
  537. }
  538. return (found) ? va_start : NULL;
  539. }
  540. /**
  541. * _sysc_enable - try to bring a module out of idle via OCP_SYSCONFIG
  542. * @oh: struct omap_hwmod *
  543. *
  544. * If module is marked as SWSUP_SIDLE, force the module out of slave
  545. * idle; otherwise, configure it for smart-idle. If module is marked
  546. * as SWSUP_MSUSPEND, force the module out of master standby;
  547. * otherwise, configure it for smart-standby. No return value.
  548. */
  549. static void _sysc_enable(struct omap_hwmod *oh)
  550. {
  551. u8 idlemode, sf;
  552. u32 v;
  553. if (!oh->class->sysc)
  554. return;
  555. v = oh->_sysc_cache;
  556. sf = oh->class->sysc->sysc_flags;
  557. if (sf & SYSC_HAS_SIDLEMODE) {
  558. idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
  559. HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
  560. _set_slave_idlemode(oh, idlemode, &v);
  561. }
  562. if (sf & SYSC_HAS_MIDLEMODE) {
  563. idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ?
  564. HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
  565. _set_master_standbymode(oh, idlemode, &v);
  566. }
  567. if (sf & SYSC_HAS_AUTOIDLE) {
  568. idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
  569. 0 : 1;
  570. _set_module_autoidle(oh, idlemode, &v);
  571. }
  572. /* XXX OCP ENAWAKEUP bit? */
  573. /*
  574. * XXX The clock framework should handle this, by
  575. * calling into this code. But this must wait until the
  576. * clock structures are tagged with omap_hwmod entries
  577. */
  578. if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
  579. (sf & SYSC_HAS_CLOCKACTIVITY))
  580. _set_clockactivity(oh, oh->class->sysc->clockact, &v);
  581. _write_sysconfig(v, oh);
  582. }
  583. /**
  584. * _sysc_idle - try to put a module into idle via OCP_SYSCONFIG
  585. * @oh: struct omap_hwmod *
  586. *
  587. * If module is marked as SWSUP_SIDLE, force the module into slave
  588. * idle; otherwise, configure it for smart-idle. If module is marked
  589. * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
  590. * configure it for smart-standby. No return value.
  591. */
  592. static void _sysc_idle(struct omap_hwmod *oh)
  593. {
  594. u8 idlemode, sf;
  595. u32 v;
  596. if (!oh->class->sysc)
  597. return;
  598. v = oh->_sysc_cache;
  599. sf = oh->class->sysc->sysc_flags;
  600. if (sf & SYSC_HAS_SIDLEMODE) {
  601. idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
  602. HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART;
  603. _set_slave_idlemode(oh, idlemode, &v);
  604. }
  605. if (sf & SYSC_HAS_MIDLEMODE) {
  606. idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ?
  607. HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART;
  608. _set_master_standbymode(oh, idlemode, &v);
  609. }
  610. _write_sysconfig(v, oh);
  611. }
  612. /**
  613. * _sysc_shutdown - force a module into idle via OCP_SYSCONFIG
  614. * @oh: struct omap_hwmod *
  615. *
  616. * Force the module into slave idle and master suspend. No return
  617. * value.
  618. */
  619. static void _sysc_shutdown(struct omap_hwmod *oh)
  620. {
  621. u32 v;
  622. u8 sf;
  623. if (!oh->class->sysc)
  624. return;
  625. v = oh->_sysc_cache;
  626. sf = oh->class->sysc->sysc_flags;
  627. if (sf & SYSC_HAS_SIDLEMODE)
  628. _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
  629. if (sf & SYSC_HAS_MIDLEMODE)
  630. _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
  631. if (sf & SYSC_HAS_AUTOIDLE)
  632. _set_module_autoidle(oh, 1, &v);
  633. _write_sysconfig(v, oh);
  634. }
  635. /**
  636. * _lookup - find an omap_hwmod by name
  637. * @name: find an omap_hwmod by name
  638. *
  639. * Return a pointer to an omap_hwmod by name, or NULL if not found.
  640. * Caller must hold omap_hwmod_mutex.
  641. */
  642. static struct omap_hwmod *_lookup(const char *name)
  643. {
  644. struct omap_hwmod *oh, *temp_oh;
  645. oh = NULL;
  646. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  647. if (!strcmp(name, temp_oh->name)) {
  648. oh = temp_oh;
  649. break;
  650. }
  651. }
  652. return oh;
  653. }
  654. /**
  655. * _init_clocks - clk_get() all clocks associated with this hwmod
  656. * @oh: struct omap_hwmod *
  657. * @data: not used; pass NULL
  658. *
  659. * Called by omap_hwmod_late_init() (after omap2_clk_init()).
  660. * Resolves all clock names embedded in the hwmod. Returns -EINVAL if
  661. * the omap_hwmod has not yet been registered or if the clocks have
  662. * already been initialized, 0 on success, or a non-zero error on
  663. * failure.
  664. */
  665. static int _init_clocks(struct omap_hwmod *oh, void *data)
  666. {
  667. int ret = 0;
  668. if (!oh || (oh->_state != _HWMOD_STATE_REGISTERED))
  669. return -EINVAL;
  670. pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
  671. ret |= _init_main_clk(oh);
  672. ret |= _init_interface_clks(oh);
  673. ret |= _init_opt_clks(oh);
  674. if (!ret)
  675. oh->_state = _HWMOD_STATE_CLKS_INITED;
  676. return 0;
  677. }
  678. /**
  679. * _wait_target_ready - wait for a module to leave slave idle
  680. * @oh: struct omap_hwmod *
  681. *
  682. * Wait for a module @oh to leave slave idle. Returns 0 if the module
  683. * does not have an IDLEST bit or if the module successfully leaves
  684. * slave idle; otherwise, pass along the return value of the
  685. * appropriate *_cm_wait_module_ready() function.
  686. */
  687. static int _wait_target_ready(struct omap_hwmod *oh)
  688. {
  689. struct omap_hwmod_ocp_if *os;
  690. int ret;
  691. if (!oh)
  692. return -EINVAL;
  693. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  694. return 0;
  695. os = oh->slaves[oh->_mpu_port_index];
  696. if (oh->flags & HWMOD_NO_IDLEST)
  697. return 0;
  698. /* XXX check module SIDLEMODE */
  699. /* XXX check clock enable states */
  700. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  701. ret = omap2_cm_wait_module_ready(oh->prcm.omap2.module_offs,
  702. oh->prcm.omap2.idlest_reg_id,
  703. oh->prcm.omap2.idlest_idle_bit);
  704. } else if (cpu_is_omap44xx()) {
  705. ret = omap4_cm_wait_module_ready(oh->prcm.omap4.clkctrl_reg);
  706. } else {
  707. BUG();
  708. };
  709. return ret;
  710. }
  711. /**
  712. * _lookup_hardreset - return the register bit shift for this hwmod/reset line
  713. * @oh: struct omap_hwmod *
  714. * @name: name of the reset line in the context of this hwmod
  715. *
  716. * Return the bit position of the reset line that match the
  717. * input name. Return -ENOENT if not found.
  718. */
  719. static u8 _lookup_hardreset(struct omap_hwmod *oh, const char *name)
  720. {
  721. int i;
  722. for (i = 0; i < oh->rst_lines_cnt; i++) {
  723. const char *rst_line = oh->rst_lines[i].name;
  724. if (!strcmp(rst_line, name)) {
  725. u8 shift = oh->rst_lines[i].rst_shift;
  726. pr_debug("omap_hwmod: %s: _lookup_hardreset: %s: %d\n",
  727. oh->name, rst_line, shift);
  728. return shift;
  729. }
  730. }
  731. return -ENOENT;
  732. }
  733. /**
  734. * _assert_hardreset - assert the HW reset line of submodules
  735. * contained in the hwmod module.
  736. * @oh: struct omap_hwmod *
  737. * @name: name of the reset line to lookup and assert
  738. *
  739. * Some IP like dsp, ipu or iva contain processor that require
  740. * an HW reset line to be assert / deassert in order to enable fully
  741. * the IP.
  742. */
  743. static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
  744. {
  745. u8 shift;
  746. if (!oh)
  747. return -EINVAL;
  748. shift = _lookup_hardreset(oh, name);
  749. if (IS_ERR_VALUE(shift))
  750. return shift;
  751. if (cpu_is_omap24xx() || cpu_is_omap34xx())
  752. return omap2_prm_assert_hardreset(oh->prcm.omap2.module_offs,
  753. shift);
  754. else if (cpu_is_omap44xx())
  755. return omap4_prm_assert_hardreset(oh->prcm.omap4.rstctrl_reg,
  756. shift);
  757. else
  758. return -EINVAL;
  759. }
  760. /**
  761. * _deassert_hardreset - deassert the HW reset line of submodules contained
  762. * in the hwmod module.
  763. * @oh: struct omap_hwmod *
  764. * @name: name of the reset line to look up and deassert
  765. *
  766. * Some IP like dsp, ipu or iva contain processor that require
  767. * an HW reset line to be assert / deassert in order to enable fully
  768. * the IP.
  769. */
  770. static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
  771. {
  772. u8 shift;
  773. int r;
  774. if (!oh)
  775. return -EINVAL;
  776. shift = _lookup_hardreset(oh, name);
  777. if (IS_ERR_VALUE(shift))
  778. return shift;
  779. if (cpu_is_omap24xx() || cpu_is_omap34xx())
  780. r = omap2_prm_deassert_hardreset(oh->prcm.omap2.module_offs,
  781. shift);
  782. else if (cpu_is_omap44xx())
  783. r = omap4_prm_deassert_hardreset(oh->prcm.omap4.rstctrl_reg,
  784. shift);
  785. else
  786. return -EINVAL;
  787. if (r == -EBUSY)
  788. pr_warning("omap_hwmod: %s: failed to hardreset\n", oh->name);
  789. return r;
  790. }
  791. /**
  792. * _read_hardreset - read the HW reset line state of submodules
  793. * contained in the hwmod module
  794. * @oh: struct omap_hwmod *
  795. * @name: name of the reset line to look up and read
  796. *
  797. * Return the state of the reset line.
  798. */
  799. static int _read_hardreset(struct omap_hwmod *oh, const char *name)
  800. {
  801. u8 shift;
  802. if (!oh)
  803. return -EINVAL;
  804. shift = _lookup_hardreset(oh, name);
  805. if (IS_ERR_VALUE(shift))
  806. return shift;
  807. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  808. return omap2_prm_is_hardreset_asserted(oh->prcm.omap2.module_offs,
  809. shift);
  810. } else if (cpu_is_omap44xx()) {
  811. return omap4_prm_is_hardreset_asserted(oh->prcm.omap4.rstctrl_reg,
  812. shift);
  813. } else {
  814. return -EINVAL;
  815. }
  816. }
  817. /**
  818. * _reset - reset an omap_hwmod
  819. * @oh: struct omap_hwmod *
  820. *
  821. * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
  822. * enabled for this to work. Returns -EINVAL if the hwmod cannot be
  823. * reset this way or if the hwmod is in the wrong state, -ETIMEDOUT if
  824. * the module did not reset in time, or 0 upon success.
  825. *
  826. * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
  827. * Starting in OMAP4, some IPs does not have SYSSTATUS register and instead
  828. * use the SYSCONFIG softreset bit to provide the status.
  829. *
  830. * Note that some IP like McBSP does have a reset control but no reset status.
  831. */
  832. static int _reset(struct omap_hwmod *oh)
  833. {
  834. u32 v;
  835. int c = 0;
  836. int ret = 0;
  837. if (!oh->class->sysc ||
  838. !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
  839. return -EINVAL;
  840. /* clocks must be on for this operation */
  841. if (oh->_state != _HWMOD_STATE_ENABLED) {
  842. pr_warning("omap_hwmod: %s: reset can only be entered from "
  843. "enabled state\n", oh->name);
  844. return -EINVAL;
  845. }
  846. /* For some modules, all optionnal clocks need to be enabled as well */
  847. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  848. _enable_optional_clocks(oh);
  849. pr_debug("omap_hwmod: %s: resetting\n", oh->name);
  850. v = oh->_sysc_cache;
  851. ret = _set_softreset(oh, &v);
  852. if (ret)
  853. goto dis_opt_clks;
  854. _write_sysconfig(v, oh);
  855. if (oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
  856. omap_test_timeout((omap_hwmod_readl(oh,
  857. oh->class->sysc->syss_offs)
  858. & SYSS_RESETDONE_MASK),
  859. MAX_MODULE_SOFTRESET_WAIT, c);
  860. else if (oh->class->sysc->sysc_flags & SYSC_HAS_RESET_STATUS)
  861. omap_test_timeout(!(omap_hwmod_readl(oh,
  862. oh->class->sysc->sysc_offs)
  863. & SYSC_TYPE2_SOFTRESET_MASK),
  864. MAX_MODULE_SOFTRESET_WAIT, c);
  865. if (c == MAX_MODULE_SOFTRESET_WAIT)
  866. pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n",
  867. oh->name, MAX_MODULE_SOFTRESET_WAIT);
  868. else
  869. pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
  870. /*
  871. * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
  872. * _wait_target_ready() or _reset()
  873. */
  874. ret = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
  875. dis_opt_clks:
  876. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  877. _disable_optional_clocks(oh);
  878. return ret;
  879. }
  880. /**
  881. * _omap_hwmod_enable - enable an omap_hwmod
  882. * @oh: struct omap_hwmod *
  883. *
  884. * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
  885. * register target. Returns -EINVAL if the hwmod is in the wrong
  886. * state or passes along the return value of _wait_target_ready().
  887. */
  888. int _omap_hwmod_enable(struct omap_hwmod *oh)
  889. {
  890. int r;
  891. if (oh->_state != _HWMOD_STATE_INITIALIZED &&
  892. oh->_state != _HWMOD_STATE_IDLE &&
  893. oh->_state != _HWMOD_STATE_DISABLED) {
  894. WARN(1, "omap_hwmod: %s: enabled state can only be entered "
  895. "from initialized, idle, or disabled state\n", oh->name);
  896. return -EINVAL;
  897. }
  898. pr_debug("omap_hwmod: %s: enabling\n", oh->name);
  899. /*
  900. * If an IP contains only one HW reset line, then de-assert it in order
  901. * to allow to enable the clocks. Otherwise the PRCM will return
  902. * Intransition status, and the init will failed.
  903. */
  904. if ((oh->_state == _HWMOD_STATE_INITIALIZED ||
  905. oh->_state == _HWMOD_STATE_DISABLED) && oh->rst_lines_cnt == 1)
  906. _deassert_hardreset(oh, oh->rst_lines[0].name);
  907. /* XXX mux balls */
  908. _add_initiator_dep(oh, mpu_oh);
  909. _enable_clocks(oh);
  910. r = _wait_target_ready(oh);
  911. if (!r) {
  912. oh->_state = _HWMOD_STATE_ENABLED;
  913. /* Access the sysconfig only if the target is ready */
  914. if (oh->class->sysc) {
  915. if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
  916. _update_sysc_cache(oh);
  917. _sysc_enable(oh);
  918. }
  919. } else {
  920. pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n",
  921. oh->name, r);
  922. }
  923. return r;
  924. }
  925. /**
  926. * _idle - idle an omap_hwmod
  927. * @oh: struct omap_hwmod *
  928. *
  929. * Idles an omap_hwmod @oh. This should be called once the hwmod has
  930. * no further work. Returns -EINVAL if the hwmod is in the wrong
  931. * state or returns 0.
  932. */
  933. int _omap_hwmod_idle(struct omap_hwmod *oh)
  934. {
  935. if (oh->_state != _HWMOD_STATE_ENABLED) {
  936. WARN(1, "omap_hwmod: %s: idle state can only be entered from "
  937. "enabled state\n", oh->name);
  938. return -EINVAL;
  939. }
  940. pr_debug("omap_hwmod: %s: idling\n", oh->name);
  941. if (oh->class->sysc)
  942. _sysc_idle(oh);
  943. _del_initiator_dep(oh, mpu_oh);
  944. _disable_clocks(oh);
  945. oh->_state = _HWMOD_STATE_IDLE;
  946. return 0;
  947. }
  948. /**
  949. * _shutdown - shutdown an omap_hwmod
  950. * @oh: struct omap_hwmod *
  951. *
  952. * Shut down an omap_hwmod @oh. This should be called when the driver
  953. * used for the hwmod is removed or unloaded or if the driver is not
  954. * used by the system. Returns -EINVAL if the hwmod is in the wrong
  955. * state or returns 0.
  956. */
  957. static int _shutdown(struct omap_hwmod *oh)
  958. {
  959. if (oh->_state != _HWMOD_STATE_IDLE &&
  960. oh->_state != _HWMOD_STATE_ENABLED) {
  961. WARN(1, "omap_hwmod: %s: disabled state can only be entered "
  962. "from idle, or enabled state\n", oh->name);
  963. return -EINVAL;
  964. }
  965. pr_debug("omap_hwmod: %s: disabling\n", oh->name);
  966. if (oh->class->sysc)
  967. _sysc_shutdown(oh);
  968. /*
  969. * If an IP contains only one HW reset line, then assert it
  970. * before disabling the clocks and shutting down the IP.
  971. */
  972. if (oh->rst_lines_cnt == 1)
  973. _assert_hardreset(oh, oh->rst_lines[0].name);
  974. /* clocks and deps are already disabled in idle */
  975. if (oh->_state == _HWMOD_STATE_ENABLED) {
  976. _del_initiator_dep(oh, mpu_oh);
  977. /* XXX what about the other system initiators here? dma, dsp */
  978. _disable_clocks(oh);
  979. }
  980. /* XXX Should this code also force-disable the optional clocks? */
  981. /* XXX mux any associated balls to safe mode */
  982. oh->_state = _HWMOD_STATE_DISABLED;
  983. return 0;
  984. }
  985. /**
  986. * _setup - do initial configuration of omap_hwmod
  987. * @oh: struct omap_hwmod *
  988. * @skip_setup_idle_p: do not idle hwmods at the end of the fn if 1
  989. *
  990. * Writes the CLOCKACTIVITY bits @clockact to the hwmod @oh
  991. * OCP_SYSCONFIG register. @skip_setup_idle is intended to be used on
  992. * a system that will not call omap_hwmod_enable() to enable devices
  993. * (e.g., a system without PM runtime). Returns -EINVAL if the hwmod
  994. * is in the wrong state or returns 0.
  995. */
  996. static int _setup(struct omap_hwmod *oh, void *data)
  997. {
  998. int i, r;
  999. u8 skip_setup_idle;
  1000. if (!oh || !data)
  1001. return -EINVAL;
  1002. skip_setup_idle = *(u8 *)data;
  1003. /* Set iclk autoidle mode */
  1004. if (oh->slaves_cnt > 0) {
  1005. for (i = 0; i < oh->slaves_cnt; i++) {
  1006. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  1007. struct clk *c = os->_clk;
  1008. if (!c)
  1009. continue;
  1010. if (os->flags & OCPIF_SWSUP_IDLE) {
  1011. /* XXX omap_iclk_deny_idle(c); */
  1012. } else {
  1013. /* XXX omap_iclk_allow_idle(c); */
  1014. clk_enable(c);
  1015. }
  1016. }
  1017. }
  1018. mutex_init(&oh->_mutex);
  1019. oh->_state = _HWMOD_STATE_INITIALIZED;
  1020. /*
  1021. * In the case of hwmod with hardreset that should not be
  1022. * de-assert at boot time, we have to keep the module
  1023. * initialized, because we cannot enable it properly with the
  1024. * reset asserted. Exit without warning because that behavior is
  1025. * expected.
  1026. */
  1027. if ((oh->flags & HWMOD_INIT_NO_RESET) && oh->rst_lines_cnt == 1)
  1028. return 0;
  1029. r = _omap_hwmod_enable(oh);
  1030. if (r) {
  1031. pr_warning("omap_hwmod: %s: cannot be enabled (%d)\n",
  1032. oh->name, oh->_state);
  1033. return 0;
  1034. }
  1035. if (!(oh->flags & HWMOD_INIT_NO_RESET)) {
  1036. _reset(oh);
  1037. /*
  1038. * OCP_SYSCONFIG bits need to be reprogrammed after a softreset.
  1039. * The _omap_hwmod_enable() function should be split to
  1040. * avoid the rewrite of the OCP_SYSCONFIG register.
  1041. */
  1042. if (oh->class->sysc) {
  1043. _update_sysc_cache(oh);
  1044. _sysc_enable(oh);
  1045. }
  1046. }
  1047. if (!(oh->flags & HWMOD_INIT_NO_IDLE) && !skip_setup_idle)
  1048. _omap_hwmod_idle(oh);
  1049. return 0;
  1050. }
  1051. /* Public functions */
  1052. u32 omap_hwmod_readl(struct omap_hwmod *oh, u16 reg_offs)
  1053. {
  1054. return __raw_readl(oh->_mpu_rt_va + reg_offs);
  1055. }
  1056. void omap_hwmod_writel(u32 v, struct omap_hwmod *oh, u16 reg_offs)
  1057. {
  1058. __raw_writel(v, oh->_mpu_rt_va + reg_offs);
  1059. }
  1060. /**
  1061. * omap_hwmod_set_slave_idlemode - set the hwmod's OCP slave idlemode
  1062. * @oh: struct omap_hwmod *
  1063. * @idlemode: SIDLEMODE field bits (shifted to bit 0)
  1064. *
  1065. * Sets the IP block's OCP slave idlemode in hardware, and updates our
  1066. * local copy. Intended to be used by drivers that have some erratum
  1067. * that requires direct manipulation of the SIDLEMODE bits. Returns
  1068. * -EINVAL if @oh is null, or passes along the return value from
  1069. * _set_slave_idlemode().
  1070. *
  1071. * XXX Does this function have any current users? If not, we should
  1072. * remove it; it is better to let the rest of the hwmod code handle this.
  1073. * Any users of this function should be scrutinized carefully.
  1074. */
  1075. int omap_hwmod_set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode)
  1076. {
  1077. u32 v;
  1078. int retval = 0;
  1079. if (!oh)
  1080. return -EINVAL;
  1081. v = oh->_sysc_cache;
  1082. retval = _set_slave_idlemode(oh, idlemode, &v);
  1083. if (!retval)
  1084. _write_sysconfig(v, oh);
  1085. return retval;
  1086. }
  1087. /**
  1088. * omap_hwmod_register - register a struct omap_hwmod
  1089. * @oh: struct omap_hwmod *
  1090. *
  1091. * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod
  1092. * already has been registered by the same name; -EINVAL if the
  1093. * omap_hwmod is in the wrong state, if @oh is NULL, if the
  1094. * omap_hwmod's class field is NULL; if the omap_hwmod is missing a
  1095. * name, or if the omap_hwmod's class is missing a name; or 0 upon
  1096. * success.
  1097. *
  1098. * XXX The data should be copied into bootmem, so the original data
  1099. * should be marked __initdata and freed after init. This would allow
  1100. * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note
  1101. * that the copy process would be relatively complex due to the large number
  1102. * of substructures.
  1103. */
  1104. int omap_hwmod_register(struct omap_hwmod *oh)
  1105. {
  1106. int ret, ms_id;
  1107. if (!oh || !oh->name || !oh->class || !oh->class->name ||
  1108. (oh->_state != _HWMOD_STATE_UNKNOWN))
  1109. return -EINVAL;
  1110. mutex_lock(&omap_hwmod_mutex);
  1111. pr_debug("omap_hwmod: %s: registering\n", oh->name);
  1112. if (_lookup(oh->name)) {
  1113. ret = -EEXIST;
  1114. goto ohr_unlock;
  1115. }
  1116. ms_id = _find_mpu_port_index(oh);
  1117. if (!IS_ERR_VALUE(ms_id)) {
  1118. oh->_mpu_port_index = ms_id;
  1119. oh->_mpu_rt_va = _find_mpu_rt_base(oh, oh->_mpu_port_index);
  1120. } else {
  1121. oh->_int_flags |= _HWMOD_NO_MPU_PORT;
  1122. }
  1123. list_add_tail(&oh->node, &omap_hwmod_list);
  1124. oh->_state = _HWMOD_STATE_REGISTERED;
  1125. ret = 0;
  1126. ohr_unlock:
  1127. mutex_unlock(&omap_hwmod_mutex);
  1128. return ret;
  1129. }
  1130. /**
  1131. * omap_hwmod_lookup - look up a registered omap_hwmod by name
  1132. * @name: name of the omap_hwmod to look up
  1133. *
  1134. * Given a @name of an omap_hwmod, return a pointer to the registered
  1135. * struct omap_hwmod *, or NULL upon error.
  1136. */
  1137. struct omap_hwmod *omap_hwmod_lookup(const char *name)
  1138. {
  1139. struct omap_hwmod *oh;
  1140. if (!name)
  1141. return NULL;
  1142. mutex_lock(&omap_hwmod_mutex);
  1143. oh = _lookup(name);
  1144. mutex_unlock(&omap_hwmod_mutex);
  1145. return oh;
  1146. }
  1147. /**
  1148. * omap_hwmod_for_each - call function for each registered omap_hwmod
  1149. * @fn: pointer to a callback function
  1150. * @data: void * data to pass to callback function
  1151. *
  1152. * Call @fn for each registered omap_hwmod, passing @data to each
  1153. * function. @fn must return 0 for success or any other value for
  1154. * failure. If @fn returns non-zero, the iteration across omap_hwmods
  1155. * will stop and the non-zero return value will be passed to the
  1156. * caller of omap_hwmod_for_each(). @fn is called with
  1157. * omap_hwmod_for_each() held.
  1158. */
  1159. int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
  1160. void *data)
  1161. {
  1162. struct omap_hwmod *temp_oh;
  1163. int ret;
  1164. if (!fn)
  1165. return -EINVAL;
  1166. mutex_lock(&omap_hwmod_mutex);
  1167. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  1168. ret = (*fn)(temp_oh, data);
  1169. if (ret)
  1170. break;
  1171. }
  1172. mutex_unlock(&omap_hwmod_mutex);
  1173. return ret;
  1174. }
  1175. /**
  1176. * omap_hwmod_init - init omap_hwmod code and register hwmods
  1177. * @ohs: pointer to an array of omap_hwmods to register
  1178. *
  1179. * Intended to be called early in boot before the clock framework is
  1180. * initialized. If @ohs is not null, will register all omap_hwmods
  1181. * listed in @ohs that are valid for this chip. Returns -EINVAL if
  1182. * omap_hwmod_init() has already been called or 0 otherwise.
  1183. */
  1184. int omap_hwmod_init(struct omap_hwmod **ohs)
  1185. {
  1186. struct omap_hwmod *oh;
  1187. int r;
  1188. if (inited)
  1189. return -EINVAL;
  1190. inited = 1;
  1191. if (!ohs)
  1192. return 0;
  1193. oh = *ohs;
  1194. while (oh) {
  1195. if (omap_chip_is(oh->omap_chip)) {
  1196. r = omap_hwmod_register(oh);
  1197. WARN(r, "omap_hwmod: %s: omap_hwmod_register returned "
  1198. "%d\n", oh->name, r);
  1199. }
  1200. oh = *++ohs;
  1201. }
  1202. return 0;
  1203. }
  1204. /**
  1205. * omap_hwmod_late_init - do some post-clock framework initialization
  1206. * @skip_setup_idle: if 1, do not idle hwmods in _setup()
  1207. *
  1208. * Must be called after omap2_clk_init(). Resolves the struct clk names
  1209. * to struct clk pointers for each registered omap_hwmod. Also calls
  1210. * _setup() on each hwmod. Returns 0.
  1211. */
  1212. int omap_hwmod_late_init(u8 skip_setup_idle)
  1213. {
  1214. int r;
  1215. /* XXX check return value */
  1216. r = omap_hwmod_for_each(_init_clocks, NULL);
  1217. WARN(r, "omap_hwmod: omap_hwmod_late_init(): _init_clocks failed\n");
  1218. mpu_oh = omap_hwmod_lookup(MPU_INITIATOR_NAME);
  1219. WARN(!mpu_oh, "omap_hwmod: could not find MPU initiator hwmod %s\n",
  1220. MPU_INITIATOR_NAME);
  1221. if (skip_setup_idle)
  1222. pr_debug("omap_hwmod: will leave hwmods enabled during setup\n");
  1223. omap_hwmod_for_each(_setup, &skip_setup_idle);
  1224. return 0;
  1225. }
  1226. /**
  1227. * omap_hwmod_unregister - unregister an omap_hwmod
  1228. * @oh: struct omap_hwmod *
  1229. *
  1230. * Unregisters a previously-registered omap_hwmod @oh. There's probably
  1231. * no use case for this, so it is likely to be removed in a later version.
  1232. *
  1233. * XXX Free all of the bootmem-allocated structures here when that is
  1234. * implemented. Make it clear that core code is the only code that is
  1235. * expected to unregister modules.
  1236. */
  1237. int omap_hwmod_unregister(struct omap_hwmod *oh)
  1238. {
  1239. if (!oh)
  1240. return -EINVAL;
  1241. pr_debug("omap_hwmod: %s: unregistering\n", oh->name);
  1242. mutex_lock(&omap_hwmod_mutex);
  1243. iounmap(oh->_mpu_rt_va);
  1244. list_del(&oh->node);
  1245. mutex_unlock(&omap_hwmod_mutex);
  1246. return 0;
  1247. }
  1248. /**
  1249. * omap_hwmod_enable - enable an omap_hwmod
  1250. * @oh: struct omap_hwmod *
  1251. *
  1252. * Enable an omap_hwomd @oh. Intended to be called by omap_device_enable().
  1253. * Returns -EINVAL on error or passes along the return value from _enable().
  1254. */
  1255. int omap_hwmod_enable(struct omap_hwmod *oh)
  1256. {
  1257. int r;
  1258. if (!oh)
  1259. return -EINVAL;
  1260. mutex_lock(&oh->_mutex);
  1261. r = _omap_hwmod_enable(oh);
  1262. mutex_unlock(&oh->_mutex);
  1263. return r;
  1264. }
  1265. /**
  1266. * omap_hwmod_idle - idle an omap_hwmod
  1267. * @oh: struct omap_hwmod *
  1268. *
  1269. * Idle an omap_hwomd @oh. Intended to be called by omap_device_idle().
  1270. * Returns -EINVAL on error or passes along the return value from _idle().
  1271. */
  1272. int omap_hwmod_idle(struct omap_hwmod *oh)
  1273. {
  1274. if (!oh)
  1275. return -EINVAL;
  1276. mutex_lock(&oh->_mutex);
  1277. _omap_hwmod_idle(oh);
  1278. mutex_unlock(&oh->_mutex);
  1279. return 0;
  1280. }
  1281. /**
  1282. * omap_hwmod_shutdown - shutdown an omap_hwmod
  1283. * @oh: struct omap_hwmod *
  1284. *
  1285. * Shutdown an omap_hwomd @oh. Intended to be called by
  1286. * omap_device_shutdown(). Returns -EINVAL on error or passes along
  1287. * the return value from _shutdown().
  1288. */
  1289. int omap_hwmod_shutdown(struct omap_hwmod *oh)
  1290. {
  1291. if (!oh)
  1292. return -EINVAL;
  1293. mutex_lock(&oh->_mutex);
  1294. _shutdown(oh);
  1295. mutex_unlock(&oh->_mutex);
  1296. return 0;
  1297. }
  1298. /**
  1299. * omap_hwmod_enable_clocks - enable main_clk, all interface clocks
  1300. * @oh: struct omap_hwmod *oh
  1301. *
  1302. * Intended to be called by the omap_device code.
  1303. */
  1304. int omap_hwmod_enable_clocks(struct omap_hwmod *oh)
  1305. {
  1306. mutex_lock(&oh->_mutex);
  1307. _enable_clocks(oh);
  1308. mutex_unlock(&oh->_mutex);
  1309. return 0;
  1310. }
  1311. /**
  1312. * omap_hwmod_disable_clocks - disable main_clk, all interface clocks
  1313. * @oh: struct omap_hwmod *oh
  1314. *
  1315. * Intended to be called by the omap_device code.
  1316. */
  1317. int omap_hwmod_disable_clocks(struct omap_hwmod *oh)
  1318. {
  1319. mutex_lock(&oh->_mutex);
  1320. _disable_clocks(oh);
  1321. mutex_unlock(&oh->_mutex);
  1322. return 0;
  1323. }
  1324. /**
  1325. * omap_hwmod_ocp_barrier - wait for posted writes against the hwmod to complete
  1326. * @oh: struct omap_hwmod *oh
  1327. *
  1328. * Intended to be called by drivers and core code when all posted
  1329. * writes to a device must complete before continuing further
  1330. * execution (for example, after clearing some device IRQSTATUS
  1331. * register bits)
  1332. *
  1333. * XXX what about targets with multiple OCP threads?
  1334. */
  1335. void omap_hwmod_ocp_barrier(struct omap_hwmod *oh)
  1336. {
  1337. BUG_ON(!oh);
  1338. if (!oh->class->sysc || !oh->class->sysc->sysc_flags) {
  1339. WARN(1, "omap_device: %s: OCP barrier impossible due to "
  1340. "device configuration\n", oh->name);
  1341. return;
  1342. }
  1343. /*
  1344. * Forces posted writes to complete on the OCP thread handling
  1345. * register writes
  1346. */
  1347. omap_hwmod_readl(oh, oh->class->sysc->sysc_offs);
  1348. }
  1349. /**
  1350. * omap_hwmod_reset - reset the hwmod
  1351. * @oh: struct omap_hwmod *
  1352. *
  1353. * Under some conditions, a driver may wish to reset the entire device.
  1354. * Called from omap_device code. Returns -EINVAL on error or passes along
  1355. * the return value from _reset().
  1356. */
  1357. int omap_hwmod_reset(struct omap_hwmod *oh)
  1358. {
  1359. int r;
  1360. if (!oh)
  1361. return -EINVAL;
  1362. mutex_lock(&oh->_mutex);
  1363. r = _reset(oh);
  1364. mutex_unlock(&oh->_mutex);
  1365. return r;
  1366. }
  1367. /**
  1368. * omap_hwmod_count_resources - count number of struct resources needed by hwmod
  1369. * @oh: struct omap_hwmod *
  1370. * @res: pointer to the first element of an array of struct resource to fill
  1371. *
  1372. * Count the number of struct resource array elements necessary to
  1373. * contain omap_hwmod @oh resources. Intended to be called by code
  1374. * that registers omap_devices. Intended to be used to determine the
  1375. * size of a dynamically-allocated struct resource array, before
  1376. * calling omap_hwmod_fill_resources(). Returns the number of struct
  1377. * resource array elements needed.
  1378. *
  1379. * XXX This code is not optimized. It could attempt to merge adjacent
  1380. * resource IDs.
  1381. *
  1382. */
  1383. int omap_hwmod_count_resources(struct omap_hwmod *oh)
  1384. {
  1385. int ret, i;
  1386. ret = oh->mpu_irqs_cnt + oh->sdma_reqs_cnt;
  1387. for (i = 0; i < oh->slaves_cnt; i++)
  1388. ret += oh->slaves[i]->addr_cnt;
  1389. return ret;
  1390. }
  1391. /**
  1392. * omap_hwmod_fill_resources - fill struct resource array with hwmod data
  1393. * @oh: struct omap_hwmod *
  1394. * @res: pointer to the first element of an array of struct resource to fill
  1395. *
  1396. * Fill the struct resource array @res with resource data from the
  1397. * omap_hwmod @oh. Intended to be called by code that registers
  1398. * omap_devices. See also omap_hwmod_count_resources(). Returns the
  1399. * number of array elements filled.
  1400. */
  1401. int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
  1402. {
  1403. int i, j;
  1404. int r = 0;
  1405. /* For each IRQ, DMA, memory area, fill in array.*/
  1406. for (i = 0; i < oh->mpu_irqs_cnt; i++) {
  1407. (res + r)->name = (oh->mpu_irqs + i)->name;
  1408. (res + r)->start = (oh->mpu_irqs + i)->irq;
  1409. (res + r)->end = (oh->mpu_irqs + i)->irq;
  1410. (res + r)->flags = IORESOURCE_IRQ;
  1411. r++;
  1412. }
  1413. for (i = 0; i < oh->sdma_reqs_cnt; i++) {
  1414. (res + r)->name = (oh->sdma_reqs + i)->name;
  1415. (res + r)->start = (oh->sdma_reqs + i)->dma_req;
  1416. (res + r)->end = (oh->sdma_reqs + i)->dma_req;
  1417. (res + r)->flags = IORESOURCE_DMA;
  1418. r++;
  1419. }
  1420. for (i = 0; i < oh->slaves_cnt; i++) {
  1421. struct omap_hwmod_ocp_if *os;
  1422. os = oh->slaves[i];
  1423. for (j = 0; j < os->addr_cnt; j++) {
  1424. (res + r)->start = (os->addr + j)->pa_start;
  1425. (res + r)->end = (os->addr + j)->pa_end;
  1426. (res + r)->flags = IORESOURCE_MEM;
  1427. r++;
  1428. }
  1429. }
  1430. return r;
  1431. }
  1432. /**
  1433. * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
  1434. * @oh: struct omap_hwmod *
  1435. *
  1436. * Return the powerdomain pointer associated with the OMAP module
  1437. * @oh's main clock. If @oh does not have a main clk, return the
  1438. * powerdomain associated with the interface clock associated with the
  1439. * module's MPU port. (XXX Perhaps this should use the SDMA port
  1440. * instead?) Returns NULL on error, or a struct powerdomain * on
  1441. * success.
  1442. */
  1443. struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
  1444. {
  1445. struct clk *c;
  1446. if (!oh)
  1447. return NULL;
  1448. if (oh->_clk) {
  1449. c = oh->_clk;
  1450. } else {
  1451. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  1452. return NULL;
  1453. c = oh->slaves[oh->_mpu_port_index]->_clk;
  1454. }
  1455. if (!c->clkdm)
  1456. return NULL;
  1457. return c->clkdm->pwrdm.ptr;
  1458. }
  1459. /**
  1460. * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU)
  1461. * @oh: struct omap_hwmod *
  1462. *
  1463. * Returns the virtual address corresponding to the beginning of the
  1464. * module's register target, in the address range that is intended to
  1465. * be used by the MPU. Returns the virtual address upon success or NULL
  1466. * upon error.
  1467. */
  1468. void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh)
  1469. {
  1470. if (!oh)
  1471. return NULL;
  1472. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  1473. return NULL;
  1474. if (oh->_state == _HWMOD_STATE_UNKNOWN)
  1475. return NULL;
  1476. return oh->_mpu_rt_va;
  1477. }
  1478. /**
  1479. * omap_hwmod_add_initiator_dep - add sleepdep from @init_oh to @oh
  1480. * @oh: struct omap_hwmod *
  1481. * @init_oh: struct omap_hwmod * (initiator)
  1482. *
  1483. * Add a sleep dependency between the initiator @init_oh and @oh.
  1484. * Intended to be called by DSP/Bridge code via platform_data for the
  1485. * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
  1486. * code needs to add/del initiator dependencies dynamically
  1487. * before/after accessing a device. Returns the return value from
  1488. * _add_initiator_dep().
  1489. *
  1490. * XXX Keep a usecount in the clockdomain code
  1491. */
  1492. int omap_hwmod_add_initiator_dep(struct omap_hwmod *oh,
  1493. struct omap_hwmod *init_oh)
  1494. {
  1495. return _add_initiator_dep(oh, init_oh);
  1496. }
  1497. /*
  1498. * XXX what about functions for drivers to save/restore ocp_sysconfig
  1499. * for context save/restore operations?
  1500. */
  1501. /**
  1502. * omap_hwmod_del_initiator_dep - remove sleepdep from @init_oh to @oh
  1503. * @oh: struct omap_hwmod *
  1504. * @init_oh: struct omap_hwmod * (initiator)
  1505. *
  1506. * Remove a sleep dependency between the initiator @init_oh and @oh.
  1507. * Intended to be called by DSP/Bridge code via platform_data for the
  1508. * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
  1509. * code needs to add/del initiator dependencies dynamically
  1510. * before/after accessing a device. Returns the return value from
  1511. * _del_initiator_dep().
  1512. *
  1513. * XXX Keep a usecount in the clockdomain code
  1514. */
  1515. int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh,
  1516. struct omap_hwmod *init_oh)
  1517. {
  1518. return _del_initiator_dep(oh, init_oh);
  1519. }
  1520. /**
  1521. * omap_hwmod_enable_wakeup - allow device to wake up the system
  1522. * @oh: struct omap_hwmod *
  1523. *
  1524. * Sets the module OCP socket ENAWAKEUP bit to allow the module to
  1525. * send wakeups to the PRCM. Eventually this should sets PRCM wakeup
  1526. * registers to cause the PRCM to receive wakeup events from the
  1527. * module. Does not set any wakeup routing registers beyond this
  1528. * point - if the module is to wake up any other module or subsystem,
  1529. * that must be set separately. Called by omap_device code. Returns
  1530. * -EINVAL on error or 0 upon success.
  1531. */
  1532. int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
  1533. {
  1534. if (!oh->class->sysc ||
  1535. !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
  1536. return -EINVAL;
  1537. mutex_lock(&oh->_mutex);
  1538. _enable_wakeup(oh);
  1539. mutex_unlock(&oh->_mutex);
  1540. return 0;
  1541. }
  1542. /**
  1543. * omap_hwmod_disable_wakeup - prevent device from waking the system
  1544. * @oh: struct omap_hwmod *
  1545. *
  1546. * Clears the module OCP socket ENAWAKEUP bit to prevent the module
  1547. * from sending wakeups to the PRCM. Eventually this should clear
  1548. * PRCM wakeup registers to cause the PRCM to ignore wakeup events
  1549. * from the module. Does not set any wakeup routing registers beyond
  1550. * this point - if the module is to wake up any other module or
  1551. * subsystem, that must be set separately. Called by omap_device
  1552. * code. Returns -EINVAL on error or 0 upon success.
  1553. */
  1554. int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
  1555. {
  1556. if (!oh->class->sysc ||
  1557. !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
  1558. return -EINVAL;
  1559. mutex_lock(&oh->_mutex);
  1560. _disable_wakeup(oh);
  1561. mutex_unlock(&oh->_mutex);
  1562. return 0;
  1563. }
  1564. /**
  1565. * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
  1566. * contained in the hwmod module.
  1567. * @oh: struct omap_hwmod *
  1568. * @name: name of the reset line to lookup and assert
  1569. *
  1570. * Some IP like dsp, ipu or iva contain processor that require
  1571. * an HW reset line to be assert / deassert in order to enable fully
  1572. * the IP. Returns -EINVAL if @oh is null or if the operation is not
  1573. * yet supported on this OMAP; otherwise, passes along the return value
  1574. * from _assert_hardreset().
  1575. */
  1576. int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
  1577. {
  1578. int ret;
  1579. if (!oh)
  1580. return -EINVAL;
  1581. mutex_lock(&oh->_mutex);
  1582. ret = _assert_hardreset(oh, name);
  1583. mutex_unlock(&oh->_mutex);
  1584. return ret;
  1585. }
  1586. /**
  1587. * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
  1588. * contained in the hwmod module.
  1589. * @oh: struct omap_hwmod *
  1590. * @name: name of the reset line to look up and deassert
  1591. *
  1592. * Some IP like dsp, ipu or iva contain processor that require
  1593. * an HW reset line to be assert / deassert in order to enable fully
  1594. * the IP. Returns -EINVAL if @oh is null or if the operation is not
  1595. * yet supported on this OMAP; otherwise, passes along the return value
  1596. * from _deassert_hardreset().
  1597. */
  1598. int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
  1599. {
  1600. int ret;
  1601. if (!oh)
  1602. return -EINVAL;
  1603. mutex_lock(&oh->_mutex);
  1604. ret = _deassert_hardreset(oh, name);
  1605. mutex_unlock(&oh->_mutex);
  1606. return ret;
  1607. }
  1608. /**
  1609. * omap_hwmod_read_hardreset - read the HW reset line state of submodules
  1610. * contained in the hwmod module
  1611. * @oh: struct omap_hwmod *
  1612. * @name: name of the reset line to look up and read
  1613. *
  1614. * Return the current state of the hwmod @oh's reset line named @name:
  1615. * returns -EINVAL upon parameter error or if this operation
  1616. * is unsupported on the current OMAP; otherwise, passes along the return
  1617. * value from _read_hardreset().
  1618. */
  1619. int omap_hwmod_read_hardreset(struct omap_hwmod *oh, const char *name)
  1620. {
  1621. int ret;
  1622. if (!oh)
  1623. return -EINVAL;
  1624. mutex_lock(&oh->_mutex);
  1625. ret = _read_hardreset(oh, name);
  1626. mutex_unlock(&oh->_mutex);
  1627. return ret;
  1628. }
  1629. /**
  1630. * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
  1631. * @classname: struct omap_hwmod_class name to search for
  1632. * @fn: callback function pointer to call for each hwmod in class @classname
  1633. * @user: arbitrary context data to pass to the callback function
  1634. *
  1635. * For each omap_hwmod of class @classname, call @fn. Takes
  1636. * omap_hwmod_mutex to prevent the hwmod list from changing during the
  1637. * iteration. If the callback function returns something other than
  1638. * zero, the iterator is terminated, and the callback function's return
  1639. * value is passed back to the caller. Returns 0 upon success, -EINVAL
  1640. * if @classname or @fn are NULL, or passes back the error code from @fn.
  1641. */
  1642. int omap_hwmod_for_each_by_class(const char *classname,
  1643. int (*fn)(struct omap_hwmod *oh,
  1644. void *user),
  1645. void *user)
  1646. {
  1647. struct omap_hwmod *temp_oh;
  1648. int ret = 0;
  1649. if (!classname || !fn)
  1650. return -EINVAL;
  1651. pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
  1652. __func__, classname);
  1653. mutex_lock(&omap_hwmod_mutex);
  1654. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  1655. if (!strcmp(temp_oh->class->name, classname)) {
  1656. pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
  1657. __func__, temp_oh->name);
  1658. ret = (*fn)(temp_oh, user);
  1659. if (ret)
  1660. break;
  1661. }
  1662. }
  1663. mutex_unlock(&omap_hwmod_mutex);
  1664. if (ret)
  1665. pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",
  1666. __func__, ret);
  1667. return ret;
  1668. }