omap_hwmod.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011
  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. /*
  573. * XXX The clock framework should handle this, by
  574. * calling into this code. But this must wait until the
  575. * clock structures are tagged with omap_hwmod entries
  576. */
  577. if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
  578. (sf & SYSC_HAS_CLOCKACTIVITY))
  579. _set_clockactivity(oh, oh->class->sysc->clockact, &v);
  580. _write_sysconfig(v, oh);
  581. /* If slave is in SMARTIDLE, also enable wakeup */
  582. if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
  583. _enable_wakeup(oh);
  584. }
  585. /**
  586. * _sysc_idle - try to put a module into idle via OCP_SYSCONFIG
  587. * @oh: struct omap_hwmod *
  588. *
  589. * If module is marked as SWSUP_SIDLE, force the module into slave
  590. * idle; otherwise, configure it for smart-idle. If module is marked
  591. * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
  592. * configure it for smart-standby. No return value.
  593. */
  594. static void _sysc_idle(struct omap_hwmod *oh)
  595. {
  596. u8 idlemode, sf;
  597. u32 v;
  598. if (!oh->class->sysc)
  599. return;
  600. v = oh->_sysc_cache;
  601. sf = oh->class->sysc->sysc_flags;
  602. if (sf & SYSC_HAS_SIDLEMODE) {
  603. idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
  604. HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART;
  605. _set_slave_idlemode(oh, idlemode, &v);
  606. }
  607. if (sf & SYSC_HAS_MIDLEMODE) {
  608. idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ?
  609. HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART;
  610. _set_master_standbymode(oh, idlemode, &v);
  611. }
  612. _write_sysconfig(v, oh);
  613. }
  614. /**
  615. * _sysc_shutdown - force a module into idle via OCP_SYSCONFIG
  616. * @oh: struct omap_hwmod *
  617. *
  618. * Force the module into slave idle and master suspend. No return
  619. * value.
  620. */
  621. static void _sysc_shutdown(struct omap_hwmod *oh)
  622. {
  623. u32 v;
  624. u8 sf;
  625. if (!oh->class->sysc)
  626. return;
  627. v = oh->_sysc_cache;
  628. sf = oh->class->sysc->sysc_flags;
  629. if (sf & SYSC_HAS_SIDLEMODE)
  630. _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
  631. if (sf & SYSC_HAS_MIDLEMODE)
  632. _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
  633. if (sf & SYSC_HAS_AUTOIDLE)
  634. _set_module_autoidle(oh, 1, &v);
  635. _write_sysconfig(v, oh);
  636. }
  637. /**
  638. * _lookup - find an omap_hwmod by name
  639. * @name: find an omap_hwmod by name
  640. *
  641. * Return a pointer to an omap_hwmod by name, or NULL if not found.
  642. * Caller must hold omap_hwmod_mutex.
  643. */
  644. static struct omap_hwmod *_lookup(const char *name)
  645. {
  646. struct omap_hwmod *oh, *temp_oh;
  647. oh = NULL;
  648. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  649. if (!strcmp(name, temp_oh->name)) {
  650. oh = temp_oh;
  651. break;
  652. }
  653. }
  654. return oh;
  655. }
  656. /**
  657. * _init_clocks - clk_get() all clocks associated with this hwmod
  658. * @oh: struct omap_hwmod *
  659. * @data: not used; pass NULL
  660. *
  661. * Called by omap_hwmod_late_init() (after omap2_clk_init()).
  662. * Resolves all clock names embedded in the hwmod. Returns -EINVAL if
  663. * the omap_hwmod has not yet been registered or if the clocks have
  664. * already been initialized, 0 on success, or a non-zero error on
  665. * failure.
  666. */
  667. static int _init_clocks(struct omap_hwmod *oh, void *data)
  668. {
  669. int ret = 0;
  670. if (!oh || (oh->_state != _HWMOD_STATE_REGISTERED))
  671. return -EINVAL;
  672. pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
  673. ret |= _init_main_clk(oh);
  674. ret |= _init_interface_clks(oh);
  675. ret |= _init_opt_clks(oh);
  676. if (!ret)
  677. oh->_state = _HWMOD_STATE_CLKS_INITED;
  678. return 0;
  679. }
  680. /**
  681. * _wait_target_ready - wait for a module to leave slave idle
  682. * @oh: struct omap_hwmod *
  683. *
  684. * Wait for a module @oh to leave slave idle. Returns 0 if the module
  685. * does not have an IDLEST bit or if the module successfully leaves
  686. * slave idle; otherwise, pass along the return value of the
  687. * appropriate *_cm_wait_module_ready() function.
  688. */
  689. static int _wait_target_ready(struct omap_hwmod *oh)
  690. {
  691. struct omap_hwmod_ocp_if *os;
  692. int ret;
  693. if (!oh)
  694. return -EINVAL;
  695. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  696. return 0;
  697. os = oh->slaves[oh->_mpu_port_index];
  698. if (oh->flags & HWMOD_NO_IDLEST)
  699. return 0;
  700. /* XXX check module SIDLEMODE */
  701. /* XXX check clock enable states */
  702. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  703. ret = omap2_cm_wait_module_ready(oh->prcm.omap2.module_offs,
  704. oh->prcm.omap2.idlest_reg_id,
  705. oh->prcm.omap2.idlest_idle_bit);
  706. } else if (cpu_is_omap44xx()) {
  707. ret = omap4_cm_wait_module_ready(oh->prcm.omap4.clkctrl_reg);
  708. } else {
  709. BUG();
  710. };
  711. return ret;
  712. }
  713. /**
  714. * _lookup_hardreset - return the register bit shift for this hwmod/reset line
  715. * @oh: struct omap_hwmod *
  716. * @name: name of the reset line in the context of this hwmod
  717. *
  718. * Return the bit position of the reset line that match the
  719. * input name. Return -ENOENT if not found.
  720. */
  721. static u8 _lookup_hardreset(struct omap_hwmod *oh, const char *name)
  722. {
  723. int i;
  724. for (i = 0; i < oh->rst_lines_cnt; i++) {
  725. const char *rst_line = oh->rst_lines[i].name;
  726. if (!strcmp(rst_line, name)) {
  727. u8 shift = oh->rst_lines[i].rst_shift;
  728. pr_debug("omap_hwmod: %s: _lookup_hardreset: %s: %d\n",
  729. oh->name, rst_line, shift);
  730. return shift;
  731. }
  732. }
  733. return -ENOENT;
  734. }
  735. /**
  736. * _assert_hardreset - assert the HW reset line of submodules
  737. * contained in the hwmod module.
  738. * @oh: struct omap_hwmod *
  739. * @name: name of the reset line to lookup and assert
  740. *
  741. * Some IP like dsp, ipu or iva contain processor that require
  742. * an HW reset line to be assert / deassert in order to enable fully
  743. * the IP.
  744. */
  745. static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
  746. {
  747. u8 shift;
  748. if (!oh)
  749. return -EINVAL;
  750. shift = _lookup_hardreset(oh, name);
  751. if (IS_ERR_VALUE(shift))
  752. return shift;
  753. if (cpu_is_omap24xx() || cpu_is_omap34xx())
  754. return omap2_prm_assert_hardreset(oh->prcm.omap2.module_offs,
  755. shift);
  756. else if (cpu_is_omap44xx())
  757. return omap4_prm_assert_hardreset(oh->prcm.omap4.rstctrl_reg,
  758. shift);
  759. else
  760. return -EINVAL;
  761. }
  762. /**
  763. * _deassert_hardreset - deassert the HW reset line of submodules contained
  764. * in the hwmod module.
  765. * @oh: struct omap_hwmod *
  766. * @name: name of the reset line to look up and deassert
  767. *
  768. * Some IP like dsp, ipu or iva contain processor that require
  769. * an HW reset line to be assert / deassert in order to enable fully
  770. * the IP.
  771. */
  772. static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
  773. {
  774. u8 shift;
  775. int r;
  776. if (!oh)
  777. return -EINVAL;
  778. shift = _lookup_hardreset(oh, name);
  779. if (IS_ERR_VALUE(shift))
  780. return shift;
  781. if (cpu_is_omap24xx() || cpu_is_omap34xx())
  782. r = omap2_prm_deassert_hardreset(oh->prcm.omap2.module_offs,
  783. shift);
  784. else if (cpu_is_omap44xx())
  785. r = omap4_prm_deassert_hardreset(oh->prcm.omap4.rstctrl_reg,
  786. shift);
  787. else
  788. return -EINVAL;
  789. if (r == -EBUSY)
  790. pr_warning("omap_hwmod: %s: failed to hardreset\n", oh->name);
  791. return r;
  792. }
  793. /**
  794. * _read_hardreset - read the HW reset line state of submodules
  795. * contained in the hwmod module
  796. * @oh: struct omap_hwmod *
  797. * @name: name of the reset line to look up and read
  798. *
  799. * Return the state of the reset line.
  800. */
  801. static int _read_hardreset(struct omap_hwmod *oh, const char *name)
  802. {
  803. u8 shift;
  804. if (!oh)
  805. return -EINVAL;
  806. shift = _lookup_hardreset(oh, name);
  807. if (IS_ERR_VALUE(shift))
  808. return shift;
  809. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  810. return omap2_prm_is_hardreset_asserted(oh->prcm.omap2.module_offs,
  811. shift);
  812. } else if (cpu_is_omap44xx()) {
  813. return omap4_prm_is_hardreset_asserted(oh->prcm.omap4.rstctrl_reg,
  814. shift);
  815. } else {
  816. return -EINVAL;
  817. }
  818. }
  819. /**
  820. * _reset - reset an omap_hwmod
  821. * @oh: struct omap_hwmod *
  822. *
  823. * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
  824. * enabled for this to work. Returns -EINVAL if the hwmod cannot be
  825. * reset this way or if the hwmod is in the wrong state, -ETIMEDOUT if
  826. * the module did not reset in time, or 0 upon success.
  827. *
  828. * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
  829. * Starting in OMAP4, some IPs does not have SYSSTATUS register and instead
  830. * use the SYSCONFIG softreset bit to provide the status.
  831. *
  832. * Note that some IP like McBSP does have a reset control but no reset status.
  833. */
  834. static int _reset(struct omap_hwmod *oh)
  835. {
  836. u32 v;
  837. int c = 0;
  838. int ret = 0;
  839. if (!oh->class->sysc ||
  840. !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
  841. return -EINVAL;
  842. /* clocks must be on for this operation */
  843. if (oh->_state != _HWMOD_STATE_ENABLED) {
  844. pr_warning("omap_hwmod: %s: reset can only be entered from "
  845. "enabled state\n", oh->name);
  846. return -EINVAL;
  847. }
  848. /* For some modules, all optionnal clocks need to be enabled as well */
  849. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  850. _enable_optional_clocks(oh);
  851. pr_debug("omap_hwmod: %s: resetting\n", oh->name);
  852. v = oh->_sysc_cache;
  853. ret = _set_softreset(oh, &v);
  854. if (ret)
  855. goto dis_opt_clks;
  856. _write_sysconfig(v, oh);
  857. if (oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
  858. omap_test_timeout((omap_hwmod_readl(oh,
  859. oh->class->sysc->syss_offs)
  860. & SYSS_RESETDONE_MASK),
  861. MAX_MODULE_SOFTRESET_WAIT, c);
  862. else if (oh->class->sysc->sysc_flags & SYSC_HAS_RESET_STATUS)
  863. omap_test_timeout(!(omap_hwmod_readl(oh,
  864. oh->class->sysc->sysc_offs)
  865. & SYSC_TYPE2_SOFTRESET_MASK),
  866. MAX_MODULE_SOFTRESET_WAIT, c);
  867. if (c == MAX_MODULE_SOFTRESET_WAIT)
  868. pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n",
  869. oh->name, MAX_MODULE_SOFTRESET_WAIT);
  870. else
  871. pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
  872. /*
  873. * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
  874. * _wait_target_ready() or _reset()
  875. */
  876. ret = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
  877. dis_opt_clks:
  878. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  879. _disable_optional_clocks(oh);
  880. return ret;
  881. }
  882. /**
  883. * _omap_hwmod_enable - enable an omap_hwmod
  884. * @oh: struct omap_hwmod *
  885. *
  886. * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
  887. * register target. Returns -EINVAL if the hwmod is in the wrong
  888. * state or passes along the return value of _wait_target_ready().
  889. */
  890. int _omap_hwmod_enable(struct omap_hwmod *oh)
  891. {
  892. int r;
  893. if (oh->_state != _HWMOD_STATE_INITIALIZED &&
  894. oh->_state != _HWMOD_STATE_IDLE &&
  895. oh->_state != _HWMOD_STATE_DISABLED) {
  896. WARN(1, "omap_hwmod: %s: enabled state can only be entered "
  897. "from initialized, idle, or disabled state\n", oh->name);
  898. return -EINVAL;
  899. }
  900. pr_debug("omap_hwmod: %s: enabling\n", oh->name);
  901. /*
  902. * If an IP contains only one HW reset line, then de-assert it in order
  903. * to allow to enable the clocks. Otherwise the PRCM will return
  904. * Intransition status, and the init will failed.
  905. */
  906. if ((oh->_state == _HWMOD_STATE_INITIALIZED ||
  907. oh->_state == _HWMOD_STATE_DISABLED) && oh->rst_lines_cnt == 1)
  908. _deassert_hardreset(oh, oh->rst_lines[0].name);
  909. /* XXX mux balls */
  910. _add_initiator_dep(oh, mpu_oh);
  911. _enable_clocks(oh);
  912. r = _wait_target_ready(oh);
  913. if (!r) {
  914. oh->_state = _HWMOD_STATE_ENABLED;
  915. /* Access the sysconfig only if the target is ready */
  916. if (oh->class->sysc) {
  917. if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
  918. _update_sysc_cache(oh);
  919. _sysc_enable(oh);
  920. }
  921. } else {
  922. pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n",
  923. oh->name, r);
  924. }
  925. return r;
  926. }
  927. /**
  928. * _idle - idle an omap_hwmod
  929. * @oh: struct omap_hwmod *
  930. *
  931. * Idles an omap_hwmod @oh. This should be called once the hwmod has
  932. * no further work. Returns -EINVAL if the hwmod is in the wrong
  933. * state or returns 0.
  934. */
  935. int _omap_hwmod_idle(struct omap_hwmod *oh)
  936. {
  937. if (oh->_state != _HWMOD_STATE_ENABLED) {
  938. WARN(1, "omap_hwmod: %s: idle state can only be entered from "
  939. "enabled state\n", oh->name);
  940. return -EINVAL;
  941. }
  942. pr_debug("omap_hwmod: %s: idling\n", oh->name);
  943. if (oh->class->sysc)
  944. _sysc_idle(oh);
  945. _del_initiator_dep(oh, mpu_oh);
  946. _disable_clocks(oh);
  947. oh->_state = _HWMOD_STATE_IDLE;
  948. return 0;
  949. }
  950. /**
  951. * _shutdown - shutdown an omap_hwmod
  952. * @oh: struct omap_hwmod *
  953. *
  954. * Shut down an omap_hwmod @oh. This should be called when the driver
  955. * used for the hwmod is removed or unloaded or if the driver is not
  956. * used by the system. Returns -EINVAL if the hwmod is in the wrong
  957. * state or returns 0.
  958. */
  959. static int _shutdown(struct omap_hwmod *oh)
  960. {
  961. if (oh->_state != _HWMOD_STATE_IDLE &&
  962. oh->_state != _HWMOD_STATE_ENABLED) {
  963. WARN(1, "omap_hwmod: %s: disabled state can only be entered "
  964. "from idle, or enabled state\n", oh->name);
  965. return -EINVAL;
  966. }
  967. pr_debug("omap_hwmod: %s: disabling\n", oh->name);
  968. if (oh->class->sysc)
  969. _sysc_shutdown(oh);
  970. /*
  971. * If an IP contains only one HW reset line, then assert it
  972. * before disabling the clocks and shutting down the IP.
  973. */
  974. if (oh->rst_lines_cnt == 1)
  975. _assert_hardreset(oh, oh->rst_lines[0].name);
  976. /* clocks and deps are already disabled in idle */
  977. if (oh->_state == _HWMOD_STATE_ENABLED) {
  978. _del_initiator_dep(oh, mpu_oh);
  979. /* XXX what about the other system initiators here? dma, dsp */
  980. _disable_clocks(oh);
  981. }
  982. /* XXX Should this code also force-disable the optional clocks? */
  983. /* XXX mux any associated balls to safe mode */
  984. oh->_state = _HWMOD_STATE_DISABLED;
  985. return 0;
  986. }
  987. /**
  988. * _setup - do initial configuration of omap_hwmod
  989. * @oh: struct omap_hwmod *
  990. * @skip_setup_idle_p: do not idle hwmods at the end of the fn if 1
  991. *
  992. * Writes the CLOCKACTIVITY bits @clockact to the hwmod @oh
  993. * OCP_SYSCONFIG register. @skip_setup_idle is intended to be used on
  994. * a system that will not call omap_hwmod_enable() to enable devices
  995. * (e.g., a system without PM runtime). Returns -EINVAL if the hwmod
  996. * is in the wrong state or returns 0.
  997. */
  998. static int _setup(struct omap_hwmod *oh, void *data)
  999. {
  1000. int i, r;
  1001. u8 skip_setup_idle;
  1002. if (!oh || !data)
  1003. return -EINVAL;
  1004. skip_setup_idle = *(u8 *)data;
  1005. /* Set iclk autoidle mode */
  1006. if (oh->slaves_cnt > 0) {
  1007. for (i = 0; i < oh->slaves_cnt; i++) {
  1008. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  1009. struct clk *c = os->_clk;
  1010. if (!c)
  1011. continue;
  1012. if (os->flags & OCPIF_SWSUP_IDLE) {
  1013. /* XXX omap_iclk_deny_idle(c); */
  1014. } else {
  1015. /* XXX omap_iclk_allow_idle(c); */
  1016. clk_enable(c);
  1017. }
  1018. }
  1019. }
  1020. mutex_init(&oh->_mutex);
  1021. oh->_state = _HWMOD_STATE_INITIALIZED;
  1022. /*
  1023. * In the case of hwmod with hardreset that should not be
  1024. * de-assert at boot time, we have to keep the module
  1025. * initialized, because we cannot enable it properly with the
  1026. * reset asserted. Exit without warning because that behavior is
  1027. * expected.
  1028. */
  1029. if ((oh->flags & HWMOD_INIT_NO_RESET) && oh->rst_lines_cnt == 1)
  1030. return 0;
  1031. r = _omap_hwmod_enable(oh);
  1032. if (r) {
  1033. pr_warning("omap_hwmod: %s: cannot be enabled (%d)\n",
  1034. oh->name, oh->_state);
  1035. return 0;
  1036. }
  1037. if (!(oh->flags & HWMOD_INIT_NO_RESET)) {
  1038. _reset(oh);
  1039. /*
  1040. * OCP_SYSCONFIG bits need to be reprogrammed after a softreset.
  1041. * The _omap_hwmod_enable() function should be split to
  1042. * avoid the rewrite of the OCP_SYSCONFIG register.
  1043. */
  1044. if (oh->class->sysc) {
  1045. _update_sysc_cache(oh);
  1046. _sysc_enable(oh);
  1047. }
  1048. }
  1049. if (!(oh->flags & HWMOD_INIT_NO_IDLE) && !skip_setup_idle)
  1050. _omap_hwmod_idle(oh);
  1051. return 0;
  1052. }
  1053. /* Public functions */
  1054. u32 omap_hwmod_readl(struct omap_hwmod *oh, u16 reg_offs)
  1055. {
  1056. return __raw_readl(oh->_mpu_rt_va + reg_offs);
  1057. }
  1058. void omap_hwmod_writel(u32 v, struct omap_hwmod *oh, u16 reg_offs)
  1059. {
  1060. __raw_writel(v, oh->_mpu_rt_va + reg_offs);
  1061. }
  1062. /**
  1063. * omap_hwmod_set_slave_idlemode - set the hwmod's OCP slave idlemode
  1064. * @oh: struct omap_hwmod *
  1065. * @idlemode: SIDLEMODE field bits (shifted to bit 0)
  1066. *
  1067. * Sets the IP block's OCP slave idlemode in hardware, and updates our
  1068. * local copy. Intended to be used by drivers that have some erratum
  1069. * that requires direct manipulation of the SIDLEMODE bits. Returns
  1070. * -EINVAL if @oh is null, or passes along the return value from
  1071. * _set_slave_idlemode().
  1072. *
  1073. * XXX Does this function have any current users? If not, we should
  1074. * remove it; it is better to let the rest of the hwmod code handle this.
  1075. * Any users of this function should be scrutinized carefully.
  1076. */
  1077. int omap_hwmod_set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode)
  1078. {
  1079. u32 v;
  1080. int retval = 0;
  1081. if (!oh)
  1082. return -EINVAL;
  1083. v = oh->_sysc_cache;
  1084. retval = _set_slave_idlemode(oh, idlemode, &v);
  1085. if (!retval)
  1086. _write_sysconfig(v, oh);
  1087. return retval;
  1088. }
  1089. /**
  1090. * omap_hwmod_register - register a struct omap_hwmod
  1091. * @oh: struct omap_hwmod *
  1092. *
  1093. * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod
  1094. * already has been registered by the same name; -EINVAL if the
  1095. * omap_hwmod is in the wrong state, if @oh is NULL, if the
  1096. * omap_hwmod's class field is NULL; if the omap_hwmod is missing a
  1097. * name, or if the omap_hwmod's class is missing a name; or 0 upon
  1098. * success.
  1099. *
  1100. * XXX The data should be copied into bootmem, so the original data
  1101. * should be marked __initdata and freed after init. This would allow
  1102. * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note
  1103. * that the copy process would be relatively complex due to the large number
  1104. * of substructures.
  1105. */
  1106. int omap_hwmod_register(struct omap_hwmod *oh)
  1107. {
  1108. int ret, ms_id;
  1109. if (!oh || !oh->name || !oh->class || !oh->class->name ||
  1110. (oh->_state != _HWMOD_STATE_UNKNOWN))
  1111. return -EINVAL;
  1112. mutex_lock(&omap_hwmod_mutex);
  1113. pr_debug("omap_hwmod: %s: registering\n", oh->name);
  1114. if (_lookup(oh->name)) {
  1115. ret = -EEXIST;
  1116. goto ohr_unlock;
  1117. }
  1118. ms_id = _find_mpu_port_index(oh);
  1119. if (!IS_ERR_VALUE(ms_id)) {
  1120. oh->_mpu_port_index = ms_id;
  1121. oh->_mpu_rt_va = _find_mpu_rt_base(oh, oh->_mpu_port_index);
  1122. } else {
  1123. oh->_int_flags |= _HWMOD_NO_MPU_PORT;
  1124. }
  1125. list_add_tail(&oh->node, &omap_hwmod_list);
  1126. oh->_state = _HWMOD_STATE_REGISTERED;
  1127. ret = 0;
  1128. ohr_unlock:
  1129. mutex_unlock(&omap_hwmod_mutex);
  1130. return ret;
  1131. }
  1132. /**
  1133. * omap_hwmod_lookup - look up a registered omap_hwmod by name
  1134. * @name: name of the omap_hwmod to look up
  1135. *
  1136. * Given a @name of an omap_hwmod, return a pointer to the registered
  1137. * struct omap_hwmod *, or NULL upon error.
  1138. */
  1139. struct omap_hwmod *omap_hwmod_lookup(const char *name)
  1140. {
  1141. struct omap_hwmod *oh;
  1142. if (!name)
  1143. return NULL;
  1144. mutex_lock(&omap_hwmod_mutex);
  1145. oh = _lookup(name);
  1146. mutex_unlock(&omap_hwmod_mutex);
  1147. return oh;
  1148. }
  1149. /**
  1150. * omap_hwmod_for_each - call function for each registered omap_hwmod
  1151. * @fn: pointer to a callback function
  1152. * @data: void * data to pass to callback function
  1153. *
  1154. * Call @fn for each registered omap_hwmod, passing @data to each
  1155. * function. @fn must return 0 for success or any other value for
  1156. * failure. If @fn returns non-zero, the iteration across omap_hwmods
  1157. * will stop and the non-zero return value will be passed to the
  1158. * caller of omap_hwmod_for_each(). @fn is called with
  1159. * omap_hwmod_for_each() held.
  1160. */
  1161. int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
  1162. void *data)
  1163. {
  1164. struct omap_hwmod *temp_oh;
  1165. int ret;
  1166. if (!fn)
  1167. return -EINVAL;
  1168. mutex_lock(&omap_hwmod_mutex);
  1169. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  1170. ret = (*fn)(temp_oh, data);
  1171. if (ret)
  1172. break;
  1173. }
  1174. mutex_unlock(&omap_hwmod_mutex);
  1175. return ret;
  1176. }
  1177. /**
  1178. * omap_hwmod_init - init omap_hwmod code and register hwmods
  1179. * @ohs: pointer to an array of omap_hwmods to register
  1180. *
  1181. * Intended to be called early in boot before the clock framework is
  1182. * initialized. If @ohs is not null, will register all omap_hwmods
  1183. * listed in @ohs that are valid for this chip. Returns -EINVAL if
  1184. * omap_hwmod_init() has already been called or 0 otherwise.
  1185. */
  1186. int omap_hwmod_init(struct omap_hwmod **ohs)
  1187. {
  1188. struct omap_hwmod *oh;
  1189. int r;
  1190. if (inited)
  1191. return -EINVAL;
  1192. inited = 1;
  1193. if (!ohs)
  1194. return 0;
  1195. oh = *ohs;
  1196. while (oh) {
  1197. if (omap_chip_is(oh->omap_chip)) {
  1198. r = omap_hwmod_register(oh);
  1199. WARN(r, "omap_hwmod: %s: omap_hwmod_register returned "
  1200. "%d\n", oh->name, r);
  1201. }
  1202. oh = *++ohs;
  1203. }
  1204. return 0;
  1205. }
  1206. /**
  1207. * omap_hwmod_late_init - do some post-clock framework initialization
  1208. * @skip_setup_idle: if 1, do not idle hwmods in _setup()
  1209. *
  1210. * Must be called after omap2_clk_init(). Resolves the struct clk names
  1211. * to struct clk pointers for each registered omap_hwmod. Also calls
  1212. * _setup() on each hwmod. Returns 0.
  1213. */
  1214. int omap_hwmod_late_init(u8 skip_setup_idle)
  1215. {
  1216. int r;
  1217. /* XXX check return value */
  1218. r = omap_hwmod_for_each(_init_clocks, NULL);
  1219. WARN(r, "omap_hwmod: omap_hwmod_late_init(): _init_clocks failed\n");
  1220. mpu_oh = omap_hwmod_lookup(MPU_INITIATOR_NAME);
  1221. WARN(!mpu_oh, "omap_hwmod: could not find MPU initiator hwmod %s\n",
  1222. MPU_INITIATOR_NAME);
  1223. if (skip_setup_idle)
  1224. pr_debug("omap_hwmod: will leave hwmods enabled during setup\n");
  1225. omap_hwmod_for_each(_setup, &skip_setup_idle);
  1226. return 0;
  1227. }
  1228. /**
  1229. * omap_hwmod_unregister - unregister an omap_hwmod
  1230. * @oh: struct omap_hwmod *
  1231. *
  1232. * Unregisters a previously-registered omap_hwmod @oh. There's probably
  1233. * no use case for this, so it is likely to be removed in a later version.
  1234. *
  1235. * XXX Free all of the bootmem-allocated structures here when that is
  1236. * implemented. Make it clear that core code is the only code that is
  1237. * expected to unregister modules.
  1238. */
  1239. int omap_hwmod_unregister(struct omap_hwmod *oh)
  1240. {
  1241. if (!oh)
  1242. return -EINVAL;
  1243. pr_debug("omap_hwmod: %s: unregistering\n", oh->name);
  1244. mutex_lock(&omap_hwmod_mutex);
  1245. iounmap(oh->_mpu_rt_va);
  1246. list_del(&oh->node);
  1247. mutex_unlock(&omap_hwmod_mutex);
  1248. return 0;
  1249. }
  1250. /**
  1251. * omap_hwmod_enable - enable an omap_hwmod
  1252. * @oh: struct omap_hwmod *
  1253. *
  1254. * Enable an omap_hwomd @oh. Intended to be called by omap_device_enable().
  1255. * Returns -EINVAL on error or passes along the return value from _enable().
  1256. */
  1257. int omap_hwmod_enable(struct omap_hwmod *oh)
  1258. {
  1259. int r;
  1260. if (!oh)
  1261. return -EINVAL;
  1262. mutex_lock(&oh->_mutex);
  1263. r = _omap_hwmod_enable(oh);
  1264. mutex_unlock(&oh->_mutex);
  1265. return r;
  1266. }
  1267. /**
  1268. * omap_hwmod_idle - idle an omap_hwmod
  1269. * @oh: struct omap_hwmod *
  1270. *
  1271. * Idle an omap_hwomd @oh. Intended to be called by omap_device_idle().
  1272. * Returns -EINVAL on error or passes along the return value from _idle().
  1273. */
  1274. int omap_hwmod_idle(struct omap_hwmod *oh)
  1275. {
  1276. if (!oh)
  1277. return -EINVAL;
  1278. mutex_lock(&oh->_mutex);
  1279. _omap_hwmod_idle(oh);
  1280. mutex_unlock(&oh->_mutex);
  1281. return 0;
  1282. }
  1283. /**
  1284. * omap_hwmod_shutdown - shutdown an omap_hwmod
  1285. * @oh: struct omap_hwmod *
  1286. *
  1287. * Shutdown an omap_hwomd @oh. Intended to be called by
  1288. * omap_device_shutdown(). Returns -EINVAL on error or passes along
  1289. * the return value from _shutdown().
  1290. */
  1291. int omap_hwmod_shutdown(struct omap_hwmod *oh)
  1292. {
  1293. if (!oh)
  1294. return -EINVAL;
  1295. mutex_lock(&oh->_mutex);
  1296. _shutdown(oh);
  1297. mutex_unlock(&oh->_mutex);
  1298. return 0;
  1299. }
  1300. /**
  1301. * omap_hwmod_enable_clocks - enable main_clk, all interface clocks
  1302. * @oh: struct omap_hwmod *oh
  1303. *
  1304. * Intended to be called by the omap_device code.
  1305. */
  1306. int omap_hwmod_enable_clocks(struct omap_hwmod *oh)
  1307. {
  1308. mutex_lock(&oh->_mutex);
  1309. _enable_clocks(oh);
  1310. mutex_unlock(&oh->_mutex);
  1311. return 0;
  1312. }
  1313. /**
  1314. * omap_hwmod_disable_clocks - disable main_clk, all interface clocks
  1315. * @oh: struct omap_hwmod *oh
  1316. *
  1317. * Intended to be called by the omap_device code.
  1318. */
  1319. int omap_hwmod_disable_clocks(struct omap_hwmod *oh)
  1320. {
  1321. mutex_lock(&oh->_mutex);
  1322. _disable_clocks(oh);
  1323. mutex_unlock(&oh->_mutex);
  1324. return 0;
  1325. }
  1326. /**
  1327. * omap_hwmod_ocp_barrier - wait for posted writes against the hwmod to complete
  1328. * @oh: struct omap_hwmod *oh
  1329. *
  1330. * Intended to be called by drivers and core code when all posted
  1331. * writes to a device must complete before continuing further
  1332. * execution (for example, after clearing some device IRQSTATUS
  1333. * register bits)
  1334. *
  1335. * XXX what about targets with multiple OCP threads?
  1336. */
  1337. void omap_hwmod_ocp_barrier(struct omap_hwmod *oh)
  1338. {
  1339. BUG_ON(!oh);
  1340. if (!oh->class->sysc || !oh->class->sysc->sysc_flags) {
  1341. WARN(1, "omap_device: %s: OCP barrier impossible due to "
  1342. "device configuration\n", oh->name);
  1343. return;
  1344. }
  1345. /*
  1346. * Forces posted writes to complete on the OCP thread handling
  1347. * register writes
  1348. */
  1349. omap_hwmod_readl(oh, oh->class->sysc->sysc_offs);
  1350. }
  1351. /**
  1352. * omap_hwmod_reset - reset the hwmod
  1353. * @oh: struct omap_hwmod *
  1354. *
  1355. * Under some conditions, a driver may wish to reset the entire device.
  1356. * Called from omap_device code. Returns -EINVAL on error or passes along
  1357. * the return value from _reset().
  1358. */
  1359. int omap_hwmod_reset(struct omap_hwmod *oh)
  1360. {
  1361. int r;
  1362. if (!oh)
  1363. return -EINVAL;
  1364. mutex_lock(&oh->_mutex);
  1365. r = _reset(oh);
  1366. mutex_unlock(&oh->_mutex);
  1367. return r;
  1368. }
  1369. /**
  1370. * omap_hwmod_count_resources - count number of struct resources needed by hwmod
  1371. * @oh: struct omap_hwmod *
  1372. * @res: pointer to the first element of an array of struct resource to fill
  1373. *
  1374. * Count the number of struct resource array elements necessary to
  1375. * contain omap_hwmod @oh resources. Intended to be called by code
  1376. * that registers omap_devices. Intended to be used to determine the
  1377. * size of a dynamically-allocated struct resource array, before
  1378. * calling omap_hwmod_fill_resources(). Returns the number of struct
  1379. * resource array elements needed.
  1380. *
  1381. * XXX This code is not optimized. It could attempt to merge adjacent
  1382. * resource IDs.
  1383. *
  1384. */
  1385. int omap_hwmod_count_resources(struct omap_hwmod *oh)
  1386. {
  1387. int ret, i;
  1388. ret = oh->mpu_irqs_cnt + oh->sdma_reqs_cnt;
  1389. for (i = 0; i < oh->slaves_cnt; i++)
  1390. ret += oh->slaves[i]->addr_cnt;
  1391. return ret;
  1392. }
  1393. /**
  1394. * omap_hwmod_fill_resources - fill struct resource array with hwmod data
  1395. * @oh: struct omap_hwmod *
  1396. * @res: pointer to the first element of an array of struct resource to fill
  1397. *
  1398. * Fill the struct resource array @res with resource data from the
  1399. * omap_hwmod @oh. Intended to be called by code that registers
  1400. * omap_devices. See also omap_hwmod_count_resources(). Returns the
  1401. * number of array elements filled.
  1402. */
  1403. int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
  1404. {
  1405. int i, j;
  1406. int r = 0;
  1407. /* For each IRQ, DMA, memory area, fill in array.*/
  1408. for (i = 0; i < oh->mpu_irqs_cnt; i++) {
  1409. (res + r)->name = (oh->mpu_irqs + i)->name;
  1410. (res + r)->start = (oh->mpu_irqs + i)->irq;
  1411. (res + r)->end = (oh->mpu_irqs + i)->irq;
  1412. (res + r)->flags = IORESOURCE_IRQ;
  1413. r++;
  1414. }
  1415. for (i = 0; i < oh->sdma_reqs_cnt; i++) {
  1416. (res + r)->name = (oh->sdma_reqs + i)->name;
  1417. (res + r)->start = (oh->sdma_reqs + i)->dma_req;
  1418. (res + r)->end = (oh->sdma_reqs + i)->dma_req;
  1419. (res + r)->flags = IORESOURCE_DMA;
  1420. r++;
  1421. }
  1422. for (i = 0; i < oh->slaves_cnt; i++) {
  1423. struct omap_hwmod_ocp_if *os;
  1424. os = oh->slaves[i];
  1425. for (j = 0; j < os->addr_cnt; j++) {
  1426. (res + r)->start = (os->addr + j)->pa_start;
  1427. (res + r)->end = (os->addr + j)->pa_end;
  1428. (res + r)->flags = IORESOURCE_MEM;
  1429. r++;
  1430. }
  1431. }
  1432. return r;
  1433. }
  1434. /**
  1435. * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
  1436. * @oh: struct omap_hwmod *
  1437. *
  1438. * Return the powerdomain pointer associated with the OMAP module
  1439. * @oh's main clock. If @oh does not have a main clk, return the
  1440. * powerdomain associated with the interface clock associated with the
  1441. * module's MPU port. (XXX Perhaps this should use the SDMA port
  1442. * instead?) Returns NULL on error, or a struct powerdomain * on
  1443. * success.
  1444. */
  1445. struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
  1446. {
  1447. struct clk *c;
  1448. if (!oh)
  1449. return NULL;
  1450. if (oh->_clk) {
  1451. c = oh->_clk;
  1452. } else {
  1453. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  1454. return NULL;
  1455. c = oh->slaves[oh->_mpu_port_index]->_clk;
  1456. }
  1457. if (!c->clkdm)
  1458. return NULL;
  1459. return c->clkdm->pwrdm.ptr;
  1460. }
  1461. /**
  1462. * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU)
  1463. * @oh: struct omap_hwmod *
  1464. *
  1465. * Returns the virtual address corresponding to the beginning of the
  1466. * module's register target, in the address range that is intended to
  1467. * be used by the MPU. Returns the virtual address upon success or NULL
  1468. * upon error.
  1469. */
  1470. void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh)
  1471. {
  1472. if (!oh)
  1473. return NULL;
  1474. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  1475. return NULL;
  1476. if (oh->_state == _HWMOD_STATE_UNKNOWN)
  1477. return NULL;
  1478. return oh->_mpu_rt_va;
  1479. }
  1480. /**
  1481. * omap_hwmod_add_initiator_dep - add sleepdep from @init_oh to @oh
  1482. * @oh: struct omap_hwmod *
  1483. * @init_oh: struct omap_hwmod * (initiator)
  1484. *
  1485. * Add a sleep dependency between the initiator @init_oh and @oh.
  1486. * Intended to be called by DSP/Bridge code via platform_data for the
  1487. * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
  1488. * code needs to add/del initiator dependencies dynamically
  1489. * before/after accessing a device. Returns the return value from
  1490. * _add_initiator_dep().
  1491. *
  1492. * XXX Keep a usecount in the clockdomain code
  1493. */
  1494. int omap_hwmod_add_initiator_dep(struct omap_hwmod *oh,
  1495. struct omap_hwmod *init_oh)
  1496. {
  1497. return _add_initiator_dep(oh, init_oh);
  1498. }
  1499. /*
  1500. * XXX what about functions for drivers to save/restore ocp_sysconfig
  1501. * for context save/restore operations?
  1502. */
  1503. /**
  1504. * omap_hwmod_del_initiator_dep - remove sleepdep from @init_oh to @oh
  1505. * @oh: struct omap_hwmod *
  1506. * @init_oh: struct omap_hwmod * (initiator)
  1507. *
  1508. * Remove a sleep dependency between the initiator @init_oh and @oh.
  1509. * Intended to be called by DSP/Bridge code via platform_data for the
  1510. * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
  1511. * code needs to add/del initiator dependencies dynamically
  1512. * before/after accessing a device. Returns the return value from
  1513. * _del_initiator_dep().
  1514. *
  1515. * XXX Keep a usecount in the clockdomain code
  1516. */
  1517. int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh,
  1518. struct omap_hwmod *init_oh)
  1519. {
  1520. return _del_initiator_dep(oh, init_oh);
  1521. }
  1522. /**
  1523. * omap_hwmod_enable_wakeup - allow device to wake up the system
  1524. * @oh: struct omap_hwmod *
  1525. *
  1526. * Sets the module OCP socket ENAWAKEUP bit to allow the module to
  1527. * send wakeups to the PRCM. Eventually this should sets PRCM wakeup
  1528. * registers to cause the PRCM to receive wakeup events from the
  1529. * module. Does not set any wakeup routing registers beyond this
  1530. * point - if the module is to wake up any other module or subsystem,
  1531. * that must be set separately. Called by omap_device code. Returns
  1532. * -EINVAL on error or 0 upon success.
  1533. */
  1534. int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
  1535. {
  1536. if (!oh->class->sysc ||
  1537. !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
  1538. return -EINVAL;
  1539. mutex_lock(&oh->_mutex);
  1540. _enable_wakeup(oh);
  1541. mutex_unlock(&oh->_mutex);
  1542. return 0;
  1543. }
  1544. /**
  1545. * omap_hwmod_disable_wakeup - prevent device from waking the system
  1546. * @oh: struct omap_hwmod *
  1547. *
  1548. * Clears the module OCP socket ENAWAKEUP bit to prevent the module
  1549. * from sending wakeups to the PRCM. Eventually this should clear
  1550. * PRCM wakeup registers to cause the PRCM to ignore wakeup events
  1551. * from the module. Does not set any wakeup routing registers beyond
  1552. * this point - if the module is to wake up any other module or
  1553. * subsystem, that must be set separately. Called by omap_device
  1554. * code. Returns -EINVAL on error or 0 upon success.
  1555. */
  1556. int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
  1557. {
  1558. if (!oh->class->sysc ||
  1559. !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
  1560. return -EINVAL;
  1561. mutex_lock(&oh->_mutex);
  1562. _disable_wakeup(oh);
  1563. mutex_unlock(&oh->_mutex);
  1564. return 0;
  1565. }
  1566. /**
  1567. * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
  1568. * contained in the hwmod module.
  1569. * @oh: struct omap_hwmod *
  1570. * @name: name of the reset line to lookup and assert
  1571. *
  1572. * Some IP like dsp, ipu or iva contain processor that require
  1573. * an HW reset line to be assert / deassert in order to enable fully
  1574. * the IP. Returns -EINVAL if @oh is null or if the operation is not
  1575. * yet supported on this OMAP; otherwise, passes along the return value
  1576. * from _assert_hardreset().
  1577. */
  1578. int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
  1579. {
  1580. int ret;
  1581. if (!oh)
  1582. return -EINVAL;
  1583. mutex_lock(&oh->_mutex);
  1584. ret = _assert_hardreset(oh, name);
  1585. mutex_unlock(&oh->_mutex);
  1586. return ret;
  1587. }
  1588. /**
  1589. * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
  1590. * contained in the hwmod module.
  1591. * @oh: struct omap_hwmod *
  1592. * @name: name of the reset line to look up and deassert
  1593. *
  1594. * Some IP like dsp, ipu or iva contain processor that require
  1595. * an HW reset line to be assert / deassert in order to enable fully
  1596. * the IP. Returns -EINVAL if @oh is null or if the operation is not
  1597. * yet supported on this OMAP; otherwise, passes along the return value
  1598. * from _deassert_hardreset().
  1599. */
  1600. int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
  1601. {
  1602. int ret;
  1603. if (!oh)
  1604. return -EINVAL;
  1605. mutex_lock(&oh->_mutex);
  1606. ret = _deassert_hardreset(oh, name);
  1607. mutex_unlock(&oh->_mutex);
  1608. return ret;
  1609. }
  1610. /**
  1611. * omap_hwmod_read_hardreset - read the HW reset line state of submodules
  1612. * contained in the hwmod module
  1613. * @oh: struct omap_hwmod *
  1614. * @name: name of the reset line to look up and read
  1615. *
  1616. * Return the current state of the hwmod @oh's reset line named @name:
  1617. * returns -EINVAL upon parameter error or if this operation
  1618. * is unsupported on the current OMAP; otherwise, passes along the return
  1619. * value from _read_hardreset().
  1620. */
  1621. int omap_hwmod_read_hardreset(struct omap_hwmod *oh, const char *name)
  1622. {
  1623. int ret;
  1624. if (!oh)
  1625. return -EINVAL;
  1626. mutex_lock(&oh->_mutex);
  1627. ret = _read_hardreset(oh, name);
  1628. mutex_unlock(&oh->_mutex);
  1629. return ret;
  1630. }
  1631. /**
  1632. * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
  1633. * @classname: struct omap_hwmod_class name to search for
  1634. * @fn: callback function pointer to call for each hwmod in class @classname
  1635. * @user: arbitrary context data to pass to the callback function
  1636. *
  1637. * For each omap_hwmod of class @classname, call @fn. Takes
  1638. * omap_hwmod_mutex to prevent the hwmod list from changing during the
  1639. * iteration. If the callback function returns something other than
  1640. * zero, the iterator is terminated, and the callback function's return
  1641. * value is passed back to the caller. Returns 0 upon success, -EINVAL
  1642. * if @classname or @fn are NULL, or passes back the error code from @fn.
  1643. */
  1644. int omap_hwmod_for_each_by_class(const char *classname,
  1645. int (*fn)(struct omap_hwmod *oh,
  1646. void *user),
  1647. void *user)
  1648. {
  1649. struct omap_hwmod *temp_oh;
  1650. int ret = 0;
  1651. if (!classname || !fn)
  1652. return -EINVAL;
  1653. pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
  1654. __func__, classname);
  1655. mutex_lock(&omap_hwmod_mutex);
  1656. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  1657. if (!strcmp(temp_oh->class->name, classname)) {
  1658. pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
  1659. __func__, temp_oh->name);
  1660. ret = (*fn)(temp_oh, user);
  1661. if (ret)
  1662. break;
  1663. }
  1664. }
  1665. mutex_unlock(&omap_hwmod_mutex);
  1666. if (ret)
  1667. pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",
  1668. __func__, ret);
  1669. return ret;
  1670. }