omap_hwmod.c 56 KB

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