alarmDataOperation.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822
  1. /*
  2. * omap_hwmod implementation for OMAP2/3/4
  3. *
  4. * Copyright (C) 2009-2011 Nokia Corporation
  5. * Copyright (C) 2011-2012 Texas Instruments, Inc.
  6. *
  7. * Paul Walmsley, Benoît Cousson, Kevin Hilman
  8. *
  9. * Created in collaboration with (alphabetical order): Thara Gopinath,
  10. * Tony Lindgren, Rajendra Nayak, Vikram Pandita, Sakari Poussa, Anand
  11. * Sawant, Santosh Shilimkar, Richard Woodruff
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. *
  17. * Introduction
  18. * ------------
  19. * One way to view an OMAP SoC is as a collection of largely unrelated
  20. * IP blocks connected by interconnects. The IP blocks include
  21. * devices such as ARM processors, audio serial interfaces, UARTs,
  22. * etc. Some of these devices, like the DSP, are created by TI;
  23. * others, like the SGX, largely originate from external vendors. In
  24. * TI's documentation, on-chip devices are referred to as "OMAP
  25. * modules." Some of these IP blocks are identical across several
  26. * OMAP versions. Others are revised frequently.
  27. *
  28. * These OMAP modules are tied together by various interconnects.
  29. * Most of the address and data flow between modules is via OCP-based
  30. * interconnects such as the L3 and L4 buses; but there are other
  31. * interconnects that distribute the hardware clock tree, handle idle
  32. * and reset signaling, supply power, and connect the modules to
  33. * various pads or balls on the OMAP package.
  34. *
  35. * OMAP hwmod provides a consistent way to describe the on-chip
  36. * hardware blocks and their integration into the rest of the chip.
  37. * This description can be automatically generated from the TI
  38. * hardware database. OMAP hwmod provides a standard, consistent API
  39. * to reset, enable, idle, and disable these hardware blocks. And
  40. * hwmod provides a way for other core code, such as the Linux device
  41. * code or the OMAP power management and address space mapping code,
  42. * to query the hardware database.
  43. *
  44. * Using hwmod
  45. * -----------
  46. * Drivers won't call hwmod functions directly. That is done by the
  47. * omap_device code, and in rare occasions, by custom integration code
  48. * in arch/arm/ *omap*. The omap_device code includes functions to
  49. * build a struct platform_device using omap_hwmod data, and that is
  50. * currently how hwmod data is communicated to drivers and to the
  51. * Linux driver model. Most drivers will call omap_hwmod functions only
  52. * indirectly, via pm_runtime*() functions.
  53. *
  54. * From a layering perspective, here is where the OMAP hwmod code
  55. * fits into the kernel software stack:
  56. *
  57. * +-------------------------------+
  58. * | Device driver code |
  59. * | (e.g., drivers/) |
  60. * +-------------------------------+
  61. * | Linux driver model |
  62. * | (platform_device / |
  63. * | platform_driver data/code) |
  64. * +-------------------------------+
  65. * | OMAP core-driver integration |
  66. * |(arch/arm/mach-omap2/devices.c)|
  67. * +-------------------------------+
  68. * | omap_device code |
  69. * | (../plat-omap/omap_device.c) |
  70. * +-------------------------------+
  71. * ----> | omap_hwmod code/data | <-----
  72. * | (../mach-omap2/omap_hwmod*) |
  73. * +-------------------------------+
  74. * | OMAP clock/PRCM/register fns |
  75. * | (__raw_{read,write}l, clk*) |
  76. * +-------------------------------+
  77. *
  78. * Device drivers should not contain any OMAP-specific code or data in
  79. * them. They should only contain code to operate the IP block that
  80. * the driver is responsible for. This is because these IP blocks can
  81. * also appear in other SoCs, either from TI (such as DaVinci) or from
  82. * other manufacturers; and drivers should be reusable across other
  83. * platforms.
  84. *
  85. * The OMAP hwmod code also will attempt to reset and idle all on-chip
  86. * devices upon boot. The goal here is for the kernel to be
  87. * completely self-reliant and independent from bootloaders. This is
  88. * to ensure a repeatable configuration, both to ensure consistent
  89. * runtime behavior, and to make it easier for others to reproduce
  90. * bugs.
  91. *
  92. * OMAP module activity states
  93. * ---------------------------
  94. * The hwmod code considers modules to be in one of several activity
  95. * states. IP blocks start out in an UNKNOWN state, then once they
  96. * are registered via the hwmod code, proceed to the REGISTERED state.
  97. * Once their clock names are resolved to clock pointers, the module
  98. * enters the CLKS_INITED state; and finally, once the module has been
  99. * reset and the integration registers programmed, the INITIALIZED state
  100. * is entered. The hwmod code will then place the module into either
  101. * the IDLE state to save power, or in the case of a critical system
  102. * module, the ENABLED state.
  103. *
  104. * OMAP core integration code can then call omap_hwmod*() functions
  105. * directly to move the module between the IDLE, ENABLED, and DISABLED
  106. * states, as needed. This is done during both the PM idle loop, and
  107. * in the OMAP core integration code's implementation of the PM runtime
  108. * functions.
  109. *
  110. * References
  111. * ----------
  112. * This is a partial list.
  113. * - OMAP2420 Multimedia Processor Silicon Revision 2.1.1, 2.2 (SWPU064)
  114. * - OMAP2430 Multimedia Device POP Silicon Revision 2.1 (SWPU090)
  115. * - OMAP34xx Multimedia Device Silicon Revision 3.1 (SWPU108)
  116. * - OMAP4430 Multimedia Device Silicon Revision 1.0 (SWPU140)
  117. * - Open Core Protocol Specification 2.2
  118. *
  119. * To do:
  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-provider.h>
  133. #include <linux/delay.h>
  134. #include <linux/err.h>
  135. #include <linux/list.h>
  136. #include <linux/mutex.h>
  137. #include <linux/spinlock.h>
  138. #include <linux/slab.h>
  139. #include <linux/bootmem.h>
  140. #include "clock.h"
  141. #include "omap_hwmod.h"
  142. #include "soc.h"
  143. #include "common.h"
  144. #include "clockdomain.h"
  145. #include "powerdomain.h"
  146. #include "cm2xxx.h"
  147. #include "cm3xxx.h"
  148. #include "cminst44xx.h"
  149. #include "cm33xx.h"
  150. #include "prm.h"
  151. #include "prm3xxx.h"
  152. #include "prm44xx.h"
  153. #include "prm33xx.h"
  154. #include "prminst44xx.h"
  155. #include "mux.h"
  156. #include "pm.h"
  157. /* Name of the OMAP hwmod for the MPU */
  158. #define MPU_INITIATOR_NAME "mpu"
  159. /*
  160. * Number of struct omap_hwmod_link records per struct
  161. * omap_hwmod_ocp_if record (master->slave and slave->master)
  162. */
  163. #define LINKS_PER_OCP_IF 2
  164. /**
  165. * struct omap_hwmod_soc_ops - fn ptrs for some SoC-specific operations
  166. * @enable_module: function to enable a module (via MODULEMODE)
  167. * @disable_module: function to disable a module (via MODULEMODE)
  168. *
  169. * XXX Eventually this functionality will be hidden inside the PRM/CM
  170. * device drivers. Until then, this should avoid huge blocks of cpu_is_*()
  171. * conditionals in this code.
  172. */
  173. struct omap_hwmod_soc_ops {
  174. void (*enable_module)(struct omap_hwmod *oh);
  175. int (*disable_module)(struct omap_hwmod *oh);
  176. int (*wait_target_ready)(struct omap_hwmod *oh);
  177. int (*assert_hardreset)(struct omap_hwmod *oh,
  178. struct omap_hwmod_rst_info *ohri);
  179. int (*deassert_hardreset)(struct omap_hwmod *oh,
  180. struct omap_hwmod_rst_info *ohri);
  181. int (*is_hardreset_asserted)(struct omap_hwmod *oh,
  182. struct omap_hwmod_rst_info *ohri);
  183. int (*init_clkdm)(struct omap_hwmod *oh);
  184. void (*update_context_lost)(struct omap_hwmod *oh);
  185. int (*get_context_lost)(struct omap_hwmod *oh);
  186. };
  187. /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
  188. static struct omap_hwmod_soc_ops soc_ops;
  189. /* omap_hwmod_list contains all registered struct omap_hwmods */
  190. static LIST_HEAD(omap_hwmod_list);
  191. /* mpu_oh: used to add/remove MPU initiator from sleepdep list */
  192. static struct omap_hwmod *mpu_oh;
  193. /* io_chain_lock: used to serialize reconfigurations of the I/O chain */
  194. static DEFINE_SPINLOCK(io_chain_lock);
  195. /*
  196. * linkspace: ptr to a buffer that struct omap_hwmod_link records are
  197. * allocated from - used to reduce the number of small memory
  198. * allocations, which has a significant impact on performance
  199. */
  200. static struct omap_hwmod_link *linkspace;
  201. /*
  202. * free_ls, max_ls: array indexes into linkspace; representing the
  203. * next free struct omap_hwmod_link index, and the maximum number of
  204. * struct omap_hwmod_link records allocated (respectively)
  205. */
  206. static unsigned short free_ls, max_ls, ls_supp;
  207. /* inited: set to true once the hwmod code is initialized */
  208. static bool inited;
  209. /* Private functions */
  210. /**
  211. * _fetch_next_ocp_if - return the next OCP interface in a list
  212. * @p: ptr to a ptr to the list_head inside the ocp_if to return
  213. * @i: pointer to the index of the element pointed to by @p in the list
  214. *
  215. * Return a pointer to the struct omap_hwmod_ocp_if record
  216. * containing the struct list_head pointed to by @p, and increment
  217. * @p such that a future call to this routine will return the next
  218. * record.
  219. */
  220. static struct omap_hwmod_ocp_if *_fetch_next_ocp_if(struct list_head **p,
  221. int *i)
  222. {
  223. struct omap_hwmod_ocp_if *oi;
  224. oi = list_entry(*p, struct omap_hwmod_link, node)->ocp_if;
  225. *p = (*p)->next;
  226. *i = *i + 1;
  227. return oi;
  228. }
  229. /**
  230. * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
  231. * @oh: struct omap_hwmod *
  232. *
  233. * Load the current value of the hwmod OCP_SYSCONFIG register into the
  234. * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no
  235. * OCP_SYSCONFIG register or 0 upon success.
  236. */
  237. static int _update_sysc_cache(struct omap_hwmod *oh)
  238. {
  239. if (!oh->class->sysc) {
  240. WARN(1, "omap_hwmod: %s: cannot read OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
  241. return -EINVAL;
  242. }
  243. /* XXX ensure module interface clock is up */
  244. oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
  245. if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
  246. oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
  247. return 0;
  248. }
  249. /**
  250. * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
  251. * @v: OCP_SYSCONFIG value to write
  252. * @oh: struct omap_hwmod *
  253. *
  254. * Write @v into the module class' OCP_SYSCONFIG register, if it has
  255. * one. No return value.
  256. */
  257. static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
  258. {
  259. if (!oh->class->sysc) {
  260. WARN(1, "omap_hwmod: %s: cannot write OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
  261. return;
  262. }
  263. /* XXX ensure module interface clock is up */
  264. /* Module might have lost context, always update cache and register */
  265. oh->_sysc_cache = v;
  266. omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs);
  267. }
  268. /**
  269. * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v
  270. * @oh: struct omap_hwmod *
  271. * @standbymode: MIDLEMODE field bits
  272. * @v: pointer to register contents to modify
  273. *
  274. * Update the master standby mode bits in @v to be @standbymode for
  275. * the @oh hwmod. Does not write to the hardware. Returns -EINVAL
  276. * upon error or 0 upon success.
  277. */
  278. static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
  279. u32 *v)
  280. {
  281. u32 mstandby_mask;
  282. u8 mstandby_shift;
  283. if (!oh->class->sysc ||
  284. !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE))
  285. return -EINVAL;
  286. if (!oh->class->sysc->sysc_fields) {
  287. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  288. return -EINVAL;
  289. }
  290. mstandby_shift = oh->class->sysc->sysc_fields->midle_shift;
  291. mstandby_mask = (0x3 << mstandby_shift);
  292. *v &= ~mstandby_mask;
  293. *v |= __ffs(standbymode) << mstandby_shift;
  294. return 0;
  295. }
  296. /**
  297. * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
  298. * @oh: struct omap_hwmod *
  299. * @idlemode: SIDLEMODE field bits
  300. * @v: pointer to register contents to modify
  301. *
  302. * Update the slave idle mode bits in @v to be @idlemode for the @oh
  303. * hwmod. Does not write to the hardware. Returns -EINVAL upon error
  304. * or 0 upon success.
  305. */
  306. static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
  307. {
  308. u32 sidle_mask;
  309. u8 sidle_shift;
  310. if (!oh->class->sysc ||
  311. !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE))
  312. return -EINVAL;
  313. if (!oh->class->sysc->sysc_fields) {
  314. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  315. return -EINVAL;
  316. }
  317. sidle_shift = oh->class->sysc->sysc_fields->sidle_shift;
  318. sidle_mask = (0x3 << sidle_shift);
  319. *v &= ~sidle_mask;
  320. *v |= __ffs(idlemode) << sidle_shift;
  321. return 0;
  322. }
  323. /**
  324. * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
  325. * @oh: struct omap_hwmod *
  326. * @clockact: CLOCKACTIVITY field bits
  327. * @v: pointer to register contents to modify
  328. *
  329. * Update the clockactivity mode bits in @v to be @clockact for the
  330. * @oh hwmod. Used for additional powersaving on some modules. Does
  331. * not write to the hardware. Returns -EINVAL upon error or 0 upon
  332. * success.
  333. */
  334. static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
  335. {
  336. u32 clkact_mask;
  337. u8 clkact_shift;
  338. if (!oh->class->sysc ||
  339. !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
  340. return -EINVAL;
  341. if (!oh->class->sysc->sysc_fields) {
  342. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  343. return -EINVAL;
  344. }
  345. clkact_shift = oh->class->sysc->sysc_fields->clkact_shift;
  346. clkact_mask = (0x3 << clkact_shift);
  347. *v &= ~clkact_mask;
  348. *v |= clockact << clkact_shift;
  349. return 0;
  350. }
  351. /**
  352. * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
  353. * @oh: struct omap_hwmod *
  354. * @v: pointer to register contents to modify
  355. *
  356. * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
  357. * error or 0 upon success.
  358. */
  359. static int _set_softreset(struct omap_hwmod *oh, u32 *v)
  360. {
  361. u32 softrst_mask;
  362. if (!oh->class->sysc ||
  363. !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
  364. return -EINVAL;
  365. if (!oh->class->sysc->sysc_fields) {
  366. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  367. return -EINVAL;
  368. }
  369. softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
  370. *v |= softrst_mask;
  371. return 0;
  372. }
  373. /**
  374. * _wait_softreset_complete - wait for an OCP softreset to complete
  375. * @oh: struct omap_hwmod * to wait on
  376. *
  377. * Wait until the IP block represented by @oh reports that its OCP
  378. * softreset is complete. This can be triggered by software (see
  379. * _ocp_softreset()) or by hardware upon returning from off-mode (one
  380. * example is HSMMC). Waits for up to MAX_MODULE_SOFTRESET_WAIT
  381. * microseconds. Returns the number of microseconds waited.
  382. */
  383. static int _wait_softreset_complete(struct omap_hwmod *oh)
  384. {
  385. struct omap_hwmod_class_sysconfig *sysc;
  386. u32 softrst_mask;
  387. int c = 0;
  388. sysc = oh->class->sysc;
  389. if (sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
  390. omap_test_timeout((omap_hwmod_read(oh, sysc->syss_offs)
  391. & SYSS_RESETDONE_MASK),
  392. MAX_MODULE_SOFTRESET_WAIT, c);
  393. else if (sysc->sysc_flags & SYSC_HAS_RESET_STATUS) {
  394. softrst_mask = (0x1 << sysc->sysc_fields->srst_shift);
  395. omap_test_timeout(!(omap_hwmod_read(oh, sysc->sysc_offs)
  396. & softrst_mask),
  397. MAX_MODULE_SOFTRESET_WAIT, c);
  398. }
  399. return c;
  400. }
  401. /**
  402. * _set_dmadisable: set OCP_SYSCONFIG.DMADISABLE bit in @v
  403. * @oh: struct omap_hwmod *
  404. *
  405. * The DMADISABLE bit is a semi-automatic bit present in sysconfig register
  406. * of some modules. When the DMA must perform read/write accesses, the
  407. * DMADISABLE bit is cleared by the hardware. But when the DMA must stop
  408. * for power management, software must set the DMADISABLE bit back to 1.
  409. *
  410. * Set the DMADISABLE bit in @v for hwmod @oh. Returns -EINVAL upon
  411. * error or 0 upon success.
  412. */
  413. static int _set_dmadisable(struct omap_hwmod *oh)
  414. {
  415. u32 v;
  416. u32 dmadisable_mask;
  417. if (!oh->class->sysc ||
  418. !(oh->class->sysc->sysc_flags & SYSC_HAS_DMADISABLE))
  419. return -EINVAL;
  420. if (!oh->class->sysc->sysc_fields) {
  421. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  422. return -EINVAL;
  423. }
  424. /* clocks must be on for this operation */
  425. if (oh->_state != _HWMOD_STATE_ENABLED) {
  426. pr_warn("omap_hwmod: %s: dma can be disabled only from enabled state\n", oh->name);
  427. return -EINVAL;
  428. }
  429. pr_debug("omap_hwmod: %s: setting DMADISABLE\n", oh->name);
  430. v = oh->_sysc_cache;
  431. dmadisable_mask =
  432. (0x1 << oh->class->sysc->sysc_fields->dmadisable_shift);
  433. v |= dmadisable_mask;
  434. _write_sysconfig(v, oh);
  435. return 0;
  436. }
  437. /**
  438. * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v
  439. * @oh: struct omap_hwmod *
  440. * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
  441. * @v: pointer to register contents to modify
  442. *
  443. * Update the module autoidle bit in @v to be @autoidle for the @oh
  444. * hwmod. The autoidle bit controls whether the module can gate
  445. * internal clocks automatically when it isn't doing anything; the
  446. * exact function of this bit varies on a per-module basis. This
  447. * function does not write to the hardware. Returns -EINVAL upon
  448. * error or 0 upon success.
  449. */
  450. static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle,
  451. u32 *v)
  452. {
  453. u32 autoidle_mask;
  454. u8 autoidle_shift;
  455. if (!oh->class->sysc ||
  456. !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE))
  457. return -EINVAL;
  458. if (!oh->class->sysc->sysc_fields) {
  459. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  460. return -EINVAL;
  461. }
  462. autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift;
  463. autoidle_mask = (0x1 << autoidle_shift);
  464. *v &= ~autoidle_mask;
  465. *v |= autoidle << autoidle_shift;
  466. return 0;
  467. }
  468. /**
  469. * _set_idle_ioring_wakeup - enable/disable IO pad wakeup on hwmod idle for mux
  470. * @oh: struct omap_hwmod *
  471. * @set_wake: bool value indicating to set (true) or clear (false) wakeup enable
  472. *
  473. * Set or clear the I/O pad wakeup flag in the mux entries for the
  474. * hwmod @oh. This function changes the @oh->mux->pads_dynamic array
  475. * in memory. If the hwmod is currently idled, and the new idle
  476. * values don't match the previous ones, this function will also
  477. * update the SCM PADCTRL registers. Otherwise, if the hwmod is not
  478. * currently idled, this function won't touch the hardware: the new
  479. * mux settings are written to the SCM PADCTRL registers when the
  480. * hwmod is idled. No return value.
  481. */
  482. static void _set_idle_ioring_wakeup(struct omap_hwmod *oh, bool set_wake)
  483. {
  484. struct omap_device_pad *pad;
  485. bool change = false;
  486. u16 prev_idle;
  487. int j;
  488. if (!oh->mux || !oh->mux->enabled)
  489. return;
  490. for (j = 0; j < oh->mux->nr_pads_dynamic; j++) {
  491. pad = oh->mux->pads_dynamic[j];
  492. if (!(pad->flags & OMAP_DEVICE_PAD_WAKEUP))
  493. continue;
  494. prev_idle = pad->idle;
  495. if (set_wake)
  496. pad->idle |= OMAP_WAKEUP_EN;
  497. else
  498. pad->idle &= ~OMAP_WAKEUP_EN;
  499. if (prev_idle != pad->idle)
  500. change = true;
  501. }
  502. if (change && oh->_state == _HWMOD_STATE_IDLE)
  503. omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
  504. }
  505. /**
  506. * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
  507. * @oh: struct omap_hwmod *
  508. *
  509. * Allow the hardware module @oh to send wakeups. Returns -EINVAL
  510. * upon error or 0 upon success.
  511. */
  512. static int _enable_wakeup(struct omap_hwmod *oh, u32 *v)
  513. {
  514. if (!oh->class->sysc ||
  515. !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
  516. (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
  517. (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
  518. return -EINVAL;
  519. if (!oh->class->sysc->sysc_fields) {
  520. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  521. return -EINVAL;
  522. }
  523. if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
  524. *v |= 0x1 << oh->class->sysc->sysc_fields->enwkup_shift;
  525. if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
  526. _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
  527. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  528. _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
  529. /* XXX test pwrdm_get_wken for this hwmod's subsystem */
  530. oh->_int_flags |= _HWMOD_WAKEUP_ENABLED;
  531. return 0;
  532. }
  533. /**
  534. * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
  535. * @oh: struct omap_hwmod *
  536. *
  537. * Prevent the hardware module @oh to send wakeups. Returns -EINVAL
  538. * upon error or 0 upon success.
  539. */
  540. static int _disable_wakeup(struct omap_hwmod *oh, u32 *v)
  541. {
  542. if (!oh->class->sysc ||
  543. !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
  544. (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
  545. (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
  546. return -EINVAL;
  547. if (!oh->class->sysc->sysc_fields) {
  548. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  549. return -EINVAL;
  550. }
  551. if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
  552. *v &= ~(0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
  553. if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
  554. _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v);
  555. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  556. _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART, v);
  557. /* XXX test pwrdm_get_wken for this hwmod's subsystem */
  558. oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED;
  559. return 0;
  560. }
  561. static struct clockdomain *_get_clkdm(struct omap_hwmod *oh)
  562. {
  563. struct clk_hw_omap *clk;
  564. if (oh->clkdm) {
  565. return oh->clkdm;
  566. } else if (oh->_clk) {
  567. clk = to_clk_hw_omap(__clk_get_hw(oh->_clk));
  568. return clk->clkdm;
  569. }
  570. return NULL;
  571. }
  572. /**
  573. * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
  574. * @oh: struct omap_hwmod *
  575. *
  576. * Prevent the hardware module @oh from entering idle while the
  577. * hardare module initiator @init_oh is active. Useful when a module
  578. * will be accessed by a particular initiator (e.g., if a module will
  579. * be accessed by the IVA, there should be a sleepdep between the IVA
  580. * initiator and the module). Only applies to modules in smart-idle
  581. * mode. If the clockdomain is marked as not needing autodeps, return
  582. * 0 without doing anything. Otherwise, returns -EINVAL upon error or
  583. * passes along clkdm_add_sleepdep() value upon success.
  584. */
  585. static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
  586. {
  587. struct clockdomain *clkdm, *init_clkdm;
  588. clkdm = _get_clkdm(oh);
  589. init_clkdm = _get_clkdm(init_oh);
  590. if (!clkdm || !init_clkdm)
  591. return -EINVAL;
  592. if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS)
  593. return 0;
  594. return clkdm_add_sleepdep(clkdm, init_clkdm);
  595. }
  596. /**
  597. * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
  598. * @oh: struct omap_hwmod *
  599. *
  600. * Allow the hardware module @oh to enter idle while the hardare
  601. * module initiator @init_oh is active. Useful when a module will not
  602. * be accessed by a particular initiator (e.g., if a module will not
  603. * be accessed by the IVA, there should be no sleepdep between the IVA
  604. * initiator and the module). Only applies to modules in smart-idle
  605. * mode. If the clockdomain is marked as not needing autodeps, return
  606. * 0 without doing anything. Returns -EINVAL upon error or passes
  607. * along clkdm_del_sleepdep() value upon success.
  608. */
  609. static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
  610. {
  611. struct clockdomain *clkdm, *init_clkdm;
  612. clkdm = _get_clkdm(oh);
  613. init_clkdm = _get_clkdm(init_oh);
  614. if (!clkdm || !init_clkdm)
  615. return -EINVAL;
  616. if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS)
  617. return 0;
  618. return clkdm_del_sleepdep(clkdm, init_clkdm);
  619. }
  620. /**
  621. * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
  622. * @oh: struct omap_hwmod *
  623. *
  624. * Called from _init_clocks(). Populates the @oh _clk (main
  625. * functional clock pointer) if a main_clk is present. Returns 0 on
  626. * success or -EINVAL on error.
  627. */
  628. static int _init_main_clk(struct omap_hwmod *oh)
  629. {
  630. int ret = 0;
  631. if (!oh->main_clk)
  632. return 0;
  633. oh->_clk = clk_get(NULL, oh->main_clk);
  634. if (IS_ERR(oh->_clk)) {
  635. pr_warning("omap_hwmod: %s: cannot clk_get main_clk %s\n",
  636. oh->name, oh->main_clk);
  637. return -EINVAL;
  638. }
  639. /*
  640. * HACK: This needs a re-visit once clk_prepare() is implemented
  641. * to do something meaningful. Today its just a no-op.
  642. * If clk_prepare() is used at some point to do things like
  643. * voltage scaling etc, then this would have to be moved to
  644. * some point where subsystems like i2c and pmic become
  645. * available.
  646. */
  647. clk_prepare(oh->_clk);
  648. if (!_get_clkdm(oh))
  649. pr_debug("omap_hwmod: %s: missing clockdomain for %s.\n",
  650. oh->name, oh->main_clk);
  651. return ret;
  652. }
  653. /**
  654. * _init_interface_clks - get a struct clk * for the the hwmod's interface clks
  655. * @oh: struct omap_hwmod *
  656. *
  657. * Called from _init_clocks(). Populates the @oh OCP slave interface
  658. * clock pointers. Returns 0 on success or -EINVAL on error.
  659. */
  660. static int _init_interface_clks(struct omap_hwmod *oh)
  661. {
  662. struct omap_hwmod_ocp_if *os;
  663. struct list_head *p;
  664. struct clk *c;
  665. int i = 0;
  666. int ret = 0;
  667. p = oh->slave_ports.next;
  668. while (i < oh->slaves_cnt) {
  669. os = _fetch_next_ocp_if(&p, &i);
  670. if (!os->clk)
  671. continue;
  672. c = clk_get(NULL, os->clk);
  673. if (IS_ERR(c)) {
  674. pr_warning("omap_hwmod: %s: cannot clk_get interface_clk %s\n",
  675. oh->name, os->clk);
  676. ret = -EINVAL;
  677. }
  678. os->_clk = c;
  679. /*
  680. * HACK: This needs a re-visit once clk_prepare() is implemented
  681. * to do something meaningful. Today its just a no-op.
  682. * If clk_prepare() is used at some point to do things like
  683. * voltage scaling etc, then this would have to be moved to
  684. * some point where subsystems like i2c and pmic become
  685. * available.
  686. */
  687. clk_prepare(os->_clk);
  688. }
  689. return ret;
  690. }
  691. /**
  692. * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
  693. * @oh: struct omap_hwmod *
  694. *
  695. * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk
  696. * clock pointers. Returns 0 on success or -EINVAL on error.
  697. */
  698. static int _init_opt_clks(struct omap_hwmod *oh)
  699. {
  700. struct omap_hwmod_opt_clk *oc;
  701. struct clk *c;
  702. int i;
  703. int ret = 0;
  704. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
  705. c = clk_get(NULL, oc->clk);
  706. if (IS_ERR(c)) {
  707. pr_warning("omap_hwmod: %s: cannot clk_get opt_clk %s\n",
  708. oh->name, oc->clk);
  709. ret = -EINVAL;
  710. }
  711. oc->_clk = c;
  712. /*
  713. * HACK: This needs a re-visit once clk_prepare() is implemented
  714. * to do something meaningful. Today its just a no-op.
  715. * If clk_prepare() is used at some point to do things like
  716. * voltage scaling etc, then this would have to be moved to
  717. * some point where subsystems like i2c and pmic become
  718. * available.
  719. */
  720. clk_prepare(oc->_clk);
  721. }
  722. return ret;
  723. }
  724. /**
  725. * _enable_clocks - enable hwmod main clock and interface clocks
  726. * @oh: struct omap_hwmod *
  727. *
  728. * Enables all clocks necessary for register reads and writes to succeed
  729. * on the hwmod @oh. Returns 0.
  730. */
  731. static int _enable_clocks(struct omap_hwmod *oh)
  732. {
  733. struct omap_hwmod_ocp_if *os;
  734. struct list_head *p;
  735. int i = 0;
  736. pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
  737. if (oh->_clk)
  738. clk_enable(oh->_clk);
  739. p = oh->slave_ports.next;
  740. while (i < oh->slaves_cnt) {
  741. os = _fetch_next_ocp_if(&p, &i);
  742. if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
  743. clk_enable(os->_clk);
  744. }
  745. /* The opt clocks are controlled by the device driver. */
  746. return 0;
  747. }
  748. /**
  749. * _disable_clocks - disable hwmod main clock and interface clocks
  750. * @oh: struct omap_hwmod *
  751. *
  752. * Disables the hwmod @oh main functional and interface clocks. Returns 0.
  753. */
  754. static int _disable_clocks(struct omap_hwmod *oh)
  755. {
  756. struct omap_hwmod_ocp_if *os;
  757. struct list_head *p;
  758. int i = 0;
  759. pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
  760. if (oh->_clk)
  761. clk_disable(oh->_clk);
  762. p = oh->slave_ports.next;
  763. while (i < oh->slaves_cnt) {
  764. os = _fetch_next_ocp_if(&p, &i);
  765. if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
  766. clk_disable(os->_clk);
  767. }
  768. /* The opt clocks are controlled by the device driver. */
  769. return 0;
  770. }
  771. static void _enable_optional_clocks(struct omap_hwmod *oh)
  772. {
  773. struct omap_hwmod_opt_clk *oc;
  774. int i;
  775. pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name);
  776. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  777. if (oc->_clk) {
  778. pr_debug("omap_hwmod: enable %s:%s\n", oc->role,
  779. __clk_get_name(oc->_clk));
  780. clk_enable(oc->_clk);
  781. }
  782. }
  783. static void _disable_optional_clocks(struct omap_hwmod *oh)
  784. {
  785. struct omap_hwmod_opt_clk *oc;
  786. int i;
  787. pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name);
  788. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  789. if (oc->_clk) {
  790. pr_debug("omap_hwmod: disable %s:%s\n", oc->role,
  791. __clk_get_name(oc->_clk));
  792. clk_disable(oc->_clk);
  793. }
  794. }
  795. /**
  796. * _omap4_enable_module - enable CLKCTRL modulemode on OMAP4
  797. * @oh: struct omap_hwmod *
  798. *
  799. * Enables the PRCM module mode related to the hwmod @oh.
  800. * No return value.
  801. */
  802. static void _omap4_enable_module(struct omap_hwmod *oh)
  803. {
  804. if (!oh->clkdm || !oh->prcm.omap4.modulemode)
  805. return;
  806. pr_debug("omap_hwmod: %s: %s: %d\n",
  807. oh->name, __func__, oh->prcm.omap4.modulemode);
  808. omap4_cminst_module_enable(oh->prcm.omap4.modulemode,
  809. oh->clkdm->prcm_partition,
  810. oh->clkdm->cm_inst,
  811. oh->clkdm->clkdm_offs,
  812. oh->prcm.omap4.clkctrl_offs);
  813. }
  814. /**
  815. * _am33xx_enable_module - enable CLKCTRL modulemode on AM33XX
  816. * @oh: struct omap_hwmod *
  817. *
  818. * Enables the PRCM module mode related to the hwmod @oh.
  819. * No return value.
  820. */
  821. static void _am33xx_enable_module(struct omap_hwmod *oh)
  822. {
  823. if (!oh->clkdm || !oh->prcm.omap4.modulemode)
  824. return;
  825. pr_debug("omap_hwmod: %s: %s: %d\n",
  826. oh->name, __func__, oh->prcm.omap4.modulemode);
  827. am33xx_cm_module_enable(oh->prcm.omap4.modulemode, oh->clkdm->cm_inst,
  828. oh->clkdm->clkdm_offs,
  829. oh->prcm.omap4.clkctrl_offs);
  830. }
  831. /**
  832. * _omap4_wait_target_disable - wait for a module to be disabled on OMAP4
  833. * @oh: struct omap_hwmod *
  834. *
  835. * Wait for a module @oh to enter slave idle. Returns 0 if the module
  836. * does not have an IDLEST bit or if the module successfully enters
  837. * slave idle; otherwise, pass along the return value of the
  838. * appropriate *_cm*_wait_module_idle() function.
  839. */
  840. static int _omap4_wait_target_disable(struct omap_hwmod *oh)
  841. {
  842. if (!oh)
  843. return -EINVAL;
  844. if (oh->_int_flags & _HWMOD_NO_MPU_PORT || !oh->clkdm)
  845. return 0;
  846. if (oh->flags & HWMOD_NO_IDLEST)
  847. return 0;
  848. return omap4_cminst_wait_module_idle(oh->clkdm->prcm_partition,
  849. oh->clkdm->cm_inst,
  850. oh->clkdm->clkdm_offs,
  851. oh->prcm.omap4.clkctrl_offs);
  852. }
  853. /**
  854. * _am33xx_wait_target_disable - wait for a module to be disabled on AM33XX
  855. * @oh: struct omap_hwmod *
  856. *
  857. * Wait for a module @oh to enter slave idle. Returns 0 if the module
  858. * does not have an IDLEST bit or if the module successfully enters
  859. * slave idle; otherwise, pass along the return value of the
  860. * appropriate *_cm*_wait_module_idle() function.
  861. */
  862. static int _am33xx_wait_target_disable(struct omap_hwmod *oh)
  863. {
  864. if (!oh)
  865. return -EINVAL;
  866. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  867. return 0;
  868. if (oh->flags & HWMOD_NO_IDLEST)
  869. return 0;
  870. return am33xx_cm_wait_module_idle(oh->clkdm->cm_inst,
  871. oh->clkdm->clkdm_offs,
  872. oh->prcm.omap4.clkctrl_offs);
  873. }
  874. /**
  875. * _count_mpu_irqs - count the number of MPU IRQ lines associated with @oh
  876. * @oh: struct omap_hwmod *oh
  877. *
  878. * Count and return the number of MPU IRQs associated with the hwmod
  879. * @oh. Used to allocate struct resource data. Returns 0 if @oh is
  880. * NULL.
  881. */
  882. static int _count_mpu_irqs(struct omap_hwmod *oh)
  883. {
  884. struct omap_hwmod_irq_info *ohii;
  885. int i = 0;
  886. if (!oh || !oh->mpu_irqs)
  887. return 0;
  888. do {
  889. ohii = &oh->mpu_irqs[i++];
  890. } while (ohii->irq != -1);
  891. return i-1;
  892. }
  893. /**
  894. * _count_sdma_reqs - count the number of SDMA request lines associated with @oh
  895. * @oh: struct omap_hwmod *oh
  896. *
  897. * Count and return the number of SDMA request lines associated with
  898. * the hwmod @oh. Used to allocate struct resource data. Returns 0
  899. * if @oh is NULL.
  900. */
  901. static int _count_sdma_reqs(struct omap_hwmod *oh)
  902. {
  903. struct omap_hwmod_dma_info *ohdi;
  904. int i = 0;
  905. if (!oh || !oh->sdma_reqs)
  906. return 0;
  907. do {
  908. ohdi = &oh->sdma_reqs[i++];
  909. } while (ohdi->dma_req != -1);
  910. return i-1;
  911. }
  912. /**
  913. * _count_ocp_if_addr_spaces - count the number of address space entries for @oh
  914. * @oh: struct omap_hwmod *oh
  915. *
  916. * Count and return the number of address space ranges associated with
  917. * the hwmod @oh. Used to allocate struct resource data. Returns 0
  918. * if @oh is NULL.
  919. */
  920. static int _count_ocp_if_addr_spaces(struct omap_hwmod_ocp_if *os)
  921. {
  922. struct omap_hwmod_addr_space *mem;
  923. int i = 0;
  924. if (!os || !os->addr)
  925. return 0;
  926. do {
  927. mem = &os->addr[i++];
  928. } while (mem->pa_start != mem->pa_end);
  929. return i-1;
  930. }
  931. /**
  932. * _get_mpu_irq_by_name - fetch MPU interrupt line number by name
  933. * @oh: struct omap_hwmod * to operate on
  934. * @name: pointer to the name of the MPU interrupt number to fetch (optional)
  935. * @irq: pointer to an unsigned int to store the MPU IRQ number to
  936. *
  937. * Retrieve a MPU hardware IRQ line number named by @name associated
  938. * with the IP block pointed to by @oh. The IRQ number will be filled
  939. * into the address pointed to by @dma. When @name is non-null, the
  940. * IRQ line number associated with the named entry will be returned.
  941. * If @name is null, the first matching entry will be returned. Data
  942. * order is not meaningful in hwmod data, so callers are strongly
  943. * encouraged to use a non-null @name whenever possible to avoid
  944. * unpredictable effects if hwmod data is later added that causes data
  945. * ordering to change. Returns 0 upon success or a negative error
  946. * code upon error.
  947. */
  948. static int _get_mpu_irq_by_name(struct omap_hwmod *oh, const char *name,
  949. unsigned int *irq)
  950. {
  951. int i;
  952. bool found = false;
  953. if (!oh->mpu_irqs)
  954. return -ENOENT;
  955. i = 0;
  956. while (oh->mpu_irqs[i].irq != -1) {
  957. if (name == oh->mpu_irqs[i].name ||
  958. !strcmp(name, oh->mpu_irqs[i].name)) {
  959. found = true;
  960. break;
  961. }
  962. i++;
  963. }
  964. if (!found)
  965. return -ENOENT;
  966. *irq = oh->mpu_irqs[i].irq;
  967. return 0;
  968. }
  969. /**
  970. * _get_sdma_req_by_name - fetch SDMA request line ID by name
  971. * @oh: struct omap_hwmod * to operate on
  972. * @name: pointer to the name of the SDMA request line to fetch (optional)
  973. * @dma: pointer to an unsigned int to store the request line ID to
  974. *
  975. * Retrieve an SDMA request line ID named by @name on the IP block
  976. * pointed to by @oh. The ID will be filled into the address pointed
  977. * to by @dma. When @name is non-null, the request line ID associated
  978. * with the named entry will be returned. If @name is null, the first
  979. * matching entry will be returned. Data order is not meaningful in
  980. * hwmod data, so callers are strongly encouraged to use a non-null
  981. * @name whenever possible to avoid unpredictable effects if hwmod
  982. * data is later added that causes data ordering to change. Returns 0
  983. * upon success or a negative error code upon error.
  984. */
  985. static int _get_sdma_req_by_name(struct omap_hwmod *oh, const char *name,
  986. unsigned int *dma)
  987. {
  988. int i;
  989. bool found = false;
  990. if (!oh->sdma_reqs)
  991. return -ENOENT;
  992. i = 0;
  993. while (oh->sdma_reqs[i].dma_req != -1) {
  994. if (name == oh->sdma_reqs[i].name ||
  995. !strcmp(name, oh->sdma_reqs[i].name)) {
  996. found = true;
  997. break;
  998. }
  999. i++;
  1000. }
  1001. if (!found)
  1002. return -ENOENT;
  1003. *dma = oh->sdma_reqs[i].dma_req;
  1004. return 0;
  1005. }
  1006. /**
  1007. * _get_addr_space_by_name - fetch address space start & end by name
  1008. * @oh: struct omap_hwmod * to operate on
  1009. * @name: pointer to the name of the address space to fetch (optional)
  1010. * @pa_start: pointer to a u32 to store the starting address to
  1011. * @pa_end: pointer to a u32 to store the ending address to
  1012. *
  1013. * Retrieve address space start and end addresses for the IP block
  1014. * pointed to by @oh. The data will be filled into the addresses
  1015. * pointed to by @pa_start and @pa_end. When @name is non-null, the
  1016. * address space data associated with the named entry will be
  1017. * returned. If @name is null, the first matching entry will be
  1018. * returned. Data order is not meaningful in hwmod data, so callers
  1019. * are strongly encouraged to use a non-null @name whenever possible
  1020. * to avoid unpredictable effects if hwmod data is later added that
  1021. * causes data ordering to change. Returns 0 upon success or a
  1022. * negative error code upon error.
  1023. */
  1024. static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name,
  1025. u32 *pa_start, u32 *pa_end)
  1026. {
  1027. int i, j;
  1028. struct omap_hwmod_ocp_if *os;
  1029. struct list_head *p = NULL;
  1030. bool found = false;
  1031. p = oh->slave_ports.next;
  1032. i = 0;
  1033. while (i < oh->slaves_cnt) {
  1034. os = _fetch_next_ocp_if(&p, &i);
  1035. if (!os->addr)
  1036. return -ENOENT;
  1037. j = 0;
  1038. while (os->addr[j].pa_start != os->addr[j].pa_end) {
  1039. if (name == os->addr[j].name ||
  1040. !strcmp(name, os->addr[j].name)) {
  1041. found = true;
  1042. break;
  1043. }
  1044. j++;
  1045. }
  1046. if (found)
  1047. break;
  1048. }
  1049. if (!found)
  1050. return -ENOENT;
  1051. *pa_start = os->addr[j].pa_start;
  1052. *pa_end = os->addr[j].pa_end;
  1053. return 0;
  1054. }
  1055. /**
  1056. * _save_mpu_port_index - find and save the index to @oh's MPU port
  1057. * @oh: struct omap_hwmod *
  1058. *
  1059. * Determines the array index of the OCP slave port that the MPU uses
  1060. * to address the device, and saves it into the struct omap_hwmod.
  1061. * Intended to be called during hwmod registration only. No return
  1062. * value.
  1063. */
  1064. static void __init _save_mpu_port_index(struct omap_hwmod *oh)
  1065. {
  1066. struct omap_hwmod_ocp_if *os = NULL;
  1067. struct list_head *p;
  1068. int i = 0;
  1069. if (!oh)
  1070. return;
  1071. oh->_int_flags |= _HWMOD_NO_MPU_PORT;
  1072. p = oh->slave_ports.next;
  1073. while (i < oh->slaves_cnt) {
  1074. os = _fetch_next_ocp_if(&p, &i);
  1075. if (os->user & OCP_USER_MPU) {
  1076. oh->_mpu_port = os;
  1077. oh->_int_flags &= ~_HWMOD_NO_MPU_PORT;
  1078. break;
  1079. }
  1080. }
  1081. return;
  1082. }
  1083. /**
  1084. * _find_mpu_rt_port - return omap_hwmod_ocp_if accessible by the MPU
  1085. * @oh: struct omap_hwmod *
  1086. *
  1087. * Given a pointer to a struct omap_hwmod record @oh, return a pointer
  1088. * to the struct omap_hwmod_ocp_if record that is used by the MPU to
  1089. * communicate with the IP block. This interface need not be directly
  1090. * connected to the MPU (and almost certainly is not), but is directly
  1091. * connected to the IP block represented by @oh. Returns a pointer
  1092. * to the struct omap_hwmod_ocp_if * upon success, or returns NULL upon
  1093. * error or if there does not appear to be a path from the MPU to this
  1094. * IP block.
  1095. */
  1096. static struct omap_hwmod_ocp_if *_find_mpu_rt_port(struct omap_hwmod *oh)
  1097. {
  1098. if (!oh || oh->_int_flags & _HWMOD_NO_MPU_PORT || oh->slaves_cnt == 0)
  1099. return NULL;
  1100. return oh->_mpu_port;
  1101. };
  1102. /**
  1103. * _find_mpu_rt_addr_space - return MPU register target address space for @oh
  1104. * @oh: struct omap_hwmod *
  1105. *
  1106. * Returns a pointer to the struct omap_hwmod_addr_space record representing
  1107. * the register target MPU address space; or returns NULL upon error.
  1108. */
  1109. static struct omap_hwmod_addr_space * __init _find_mpu_rt_addr_space(struct omap_hwmod *oh)
  1110. {
  1111. struct omap_hwmod_ocp_if *os;
  1112. struct omap_hwmod_addr_space *mem;
  1113. int found = 0, i = 0;
  1114. os = _find_mpu_rt_port(oh);
  1115. if (!os || !os->addr)
  1116. return NULL;
  1117. do {
  1118. mem = &os->addr[i++];
  1119. if (mem->flags & ADDR_TYPE_RT)
  1120. found = 1;
  1121. } while (!found && mem->pa_start != mem->pa_end);
  1122. return (found) ? mem : NULL;
  1123. }
  1124. /**
  1125. * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG
  1126. * @oh: struct omap_hwmod *
  1127. *
  1128. * Ensure that the OCP_SYSCONFIG register for the IP block represented
  1129. * by @oh is set to indicate to the PRCM that the IP block is active.
  1130. * Usually this means placing the module into smart-idle mode and
  1131. * smart-standby, but if there is a bug in the automatic idle handling
  1132. * for the IP block, it may need to be placed into the force-idle or
  1133. * no-idle variants of these modes. No return value.
  1134. */
  1135. static void _enable_sysc(struct omap_hwmod *oh)
  1136. {
  1137. u8 idlemode, sf;
  1138. u32 v;
  1139. bool clkdm_act;
  1140. struct clockdomain *clkdm;
  1141. if (!oh->class->sysc)
  1142. return;
  1143. /*
  1144. * Wait until reset has completed, this is needed as the IP
  1145. * block is reset automatically by hardware in some cases
  1146. * (off-mode for example), and the drivers require the
  1147. * IP to be ready when they access it
  1148. */
  1149. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  1150. _enable_optional_clocks(oh);
  1151. _wait_softreset_complete(oh);
  1152. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  1153. _disable_optional_clocks(oh);
  1154. v = oh->_sysc_cache;
  1155. sf = oh->class->sysc->sysc_flags;
  1156. clkdm = _get_clkdm(oh);
  1157. if (sf & SYSC_HAS_SIDLEMODE) {
  1158. clkdm_act = (clkdm && clkdm->flags & CLKDM_ACTIVE_WITH_MPU);
  1159. if (clkdm_act && !(oh->class->sysc->idlemodes &
  1160. (SIDLE_SMART | SIDLE_SMART_WKUP)))
  1161. idlemode = HWMOD_IDLEMODE_FORCE;
  1162. else
  1163. idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
  1164. HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
  1165. _set_slave_idlemode(oh, idlemode, &v);
  1166. }
  1167. if (sf & SYSC_HAS_MIDLEMODE) {
  1168. if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
  1169. idlemode = HWMOD_IDLEMODE_NO;
  1170. } else {
  1171. if (sf & SYSC_HAS_ENAWAKEUP)
  1172. _enable_wakeup(oh, &v);
  1173. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  1174. idlemode = HWMOD_IDLEMODE_SMART_WKUP;
  1175. else
  1176. idlemode = HWMOD_IDLEMODE_SMART;
  1177. }
  1178. _set_master_standbymode(oh, idlemode, &v);
  1179. }
  1180. /*
  1181. * XXX The clock framework should handle this, by
  1182. * calling into this code. But this must wait until the
  1183. * clock structures are tagged with omap_hwmod entries
  1184. */
  1185. if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
  1186. (sf & SYSC_HAS_CLOCKACTIVITY))
  1187. _set_clockactivity(oh, oh->class->sysc->clockact, &v);
  1188. /* If slave is in SMARTIDLE, also enable wakeup */
  1189. if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
  1190. _enable_wakeup(oh, &v);
  1191. _write_sysconfig(v, oh);
  1192. /*
  1193. * Set the autoidle bit only after setting the smartidle bit
  1194. * Setting this will not have any impact on the other modules.
  1195. */
  1196. if (sf & SYSC_HAS_AUTOIDLE) {
  1197. idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
  1198. 0 : 1;
  1199. _set_module_autoidle(oh, idlemode, &v);
  1200. _write_sysconfig(v, oh);
  1201. }
  1202. }
  1203. /**
  1204. * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG
  1205. * @oh: struct omap_hwmod *
  1206. *
  1207. * If module is marked as SWSUP_SIDLE, force the module into slave
  1208. * idle; otherwise, configure it for smart-idle. If module is marked
  1209. * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
  1210. * configure it for smart-standby. No return value.
  1211. */
  1212. static void _idle_sysc(struct omap_hwmod *oh)
  1213. {
  1214. u8 idlemode, sf;
  1215. u32 v;
  1216. if (!oh->class->sysc)
  1217. return;
  1218. v = oh->_sysc_cache;
  1219. sf = oh->class->sysc->sysc_flags;
  1220. if (sf & SYSC_HAS_SIDLEMODE) {
  1221. /* XXX What about HWMOD_IDLEMODE_SMART_WKUP? */
  1222. if (oh->flags & HWMOD_SWSUP_SIDLE ||
  1223. !(oh->class->sysc->idlemodes &
  1224. (SIDLE_SMART | SIDLE_SMART_WKUP)))
  1225. idlemode = HWMOD_IDLEMODE_FORCE;
  1226. else
  1227. idlemode = HWMOD_IDLEMODE_SMART;
  1228. _set_slave_idlemode(oh, idlemode, &v);
  1229. }
  1230. if (sf & SYSC_HAS_MIDLEMODE) {
  1231. if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
  1232. idlemode = HWMOD_IDLEMODE_FORCE;
  1233. } else {
  1234. if (sf & SYSC_HAS_ENAWAKEUP)
  1235. _enable_wakeup(oh, &v);
  1236. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  1237. idlemode = HWMOD_IDLEMODE_SMART_WKUP;
  1238. else
  1239. idlemode = HWMOD_IDLEMODE_SMART;
  1240. }
  1241. _set_master_standbymode(oh, idlemode, &v);
  1242. }
  1243. /* If slave is in SMARTIDLE, also enable wakeup */
  1244. if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
  1245. _enable_wakeup(oh, &v);
  1246. _write_sysconfig(v, oh);
  1247. }
  1248. /**
  1249. * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG
  1250. * @oh: struct omap_hwmod *
  1251. *
  1252. * Force the module into slave idle and master suspend. No return
  1253. * value.
  1254. */
  1255. static void _shutdown_sysc(struct omap_hwmod *oh)
  1256. {
  1257. u32 v;
  1258. u8 sf;
  1259. if (!oh->class->sysc)
  1260. return;
  1261. v = oh->_sysc_cache;
  1262. sf = oh->class->sysc->sysc_flags;
  1263. if (sf & SYSC_HAS_SIDLEMODE)
  1264. _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
  1265. if (sf & SYSC_HAS_MIDLEMODE)
  1266. _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
  1267. if (sf & SYSC_HAS_AUTOIDLE)
  1268. _set_module_autoidle(oh, 1, &v);
  1269. _write_sysconfig(v, oh);
  1270. }
  1271. /**
  1272. * _lookup - find an omap_hwmod by name
  1273. * @name: find an omap_hwmod by name
  1274. *
  1275. * Return a pointer to an omap_hwmod by name, or NULL if not found.
  1276. */
  1277. static struct omap_hwmod *_lookup(const char *name)
  1278. {
  1279. struct omap_hwmod *oh, *temp_oh;
  1280. oh = NULL;
  1281. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  1282. if (!strcmp(name, temp_oh->name)) {
  1283. oh = temp_oh;
  1284. break;
  1285. }
  1286. }
  1287. return oh;
  1288. }
  1289. /**
  1290. * _init_clkdm - look up a clockdomain name, store pointer in omap_hwmod
  1291. * @oh: struct omap_hwmod *
  1292. *
  1293. * Convert a clockdomain name stored in a struct omap_hwmod into a
  1294. * clockdomain pointer, and save it into the struct omap_hwmod.
  1295. * Return -EINVAL if the clkdm_name lookup failed.
  1296. */
  1297. static int _init_clkdm(struct omap_hwmod *oh)
  1298. {
  1299. if (!oh->clkdm_name) {
  1300. pr_debug("omap_hwmod: %s: missing clockdomain\n", oh->name);
  1301. return 0;
  1302. }
  1303. oh->clkdm = clkdm_lookup(oh->clkdm_name);
  1304. if (!oh->clkdm) {
  1305. pr_warning("omap_hwmod: %s: could not associate to clkdm %s\n",
  1306. oh->name, oh->clkdm_name);
  1307. return -EINVAL;
  1308. }
  1309. pr_debug("omap_hwmod: %s: associated to clkdm %s\n",
  1310. oh->name, oh->clkdm_name);
  1311. return 0;
  1312. }
  1313. /**
  1314. * _init_clocks - clk_get() all clocks associated with this hwmod. Retrieve as
  1315. * well the clockdomain.
  1316. * @oh: struct omap_hwmod *
  1317. * @data: not used; pass NULL
  1318. *
  1319. * Called by omap_hwmod_setup_*() (after omap2_clk_init()).
  1320. * Resolves all clock names embedded in the hwmod. Returns 0 on
  1321. * success, or a negative error code on failure.
  1322. */
  1323. static int _init_clocks(struct omap_hwmod *oh, void *data)
  1324. {
  1325. int ret = 0;
  1326. if (oh->_state != _HWMOD_STATE_REGISTERED)
  1327. return 0;
  1328. pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
  1329. if (soc_ops.init_clkdm)
  1330. ret |= soc_ops.init_clkdm(oh);
  1331. ret |= _init_main_clk(oh);
  1332. ret |= _init_interface_clks(oh);
  1333. ret |= _init_opt_clks(oh);
  1334. if (!ret)
  1335. oh->_state = _HWMOD_STATE_CLKS_INITED;
  1336. else
  1337. pr_warning("omap_hwmod: %s: cannot _init_clocks\n", oh->name);
  1338. return ret;
  1339. }
  1340. /**
  1341. * _lookup_hardreset - fill register bit info for this hwmod/reset line
  1342. * @oh: struct omap_hwmod *
  1343. * @name: name of the reset line in the context of this hwmod
  1344. * @ohri: struct omap_hwmod_rst_info * that this function will fill in
  1345. *
  1346. * Return the bit position of the reset line that match the
  1347. * input name. Return -ENOENT if not found.
  1348. */
  1349. static int _lookup_hardreset(struct omap_hwmod *oh, const char *name,
  1350. struct omap_hwmod_rst_info *ohri)
  1351. {
  1352. int i;
  1353. for (i = 0; i < oh->rst_lines_cnt; i++) {
  1354. const char *rst_line = oh->rst_lines[i].name;
  1355. if (!strcmp(rst_line, name)) {
  1356. ohri->rst_shift = oh->rst_lines[i].rst_shift;
  1357. ohri->st_shift = oh->rst_lines[i].st_shift;
  1358. pr_debug("omap_hwmod: %s: %s: %s: rst %d st %d\n",
  1359. oh->name, __func__, rst_line, ohri->rst_shift,
  1360. ohri->st_shift);
  1361. return 0;
  1362. }
  1363. }
  1364. return -ENOENT;
  1365. }
  1366. /**
  1367. * _assert_hardreset - assert the HW reset line of submodules
  1368. * contained in the hwmod module.
  1369. * @oh: struct omap_hwmod *
  1370. * @name: name of the reset line to lookup and assert
  1371. *
  1372. * Some IP like dsp, ipu or iva contain processor that require an HW
  1373. * reset line to be assert / deassert in order to enable fully the IP.
  1374. * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
  1375. * asserting the hardreset line on the currently-booted SoC, or passes
  1376. * along the return value from _lookup_hardreset() or the SoC's
  1377. * assert_hardreset code.
  1378. */
  1379. static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
  1380. {
  1381. struct omap_hwmod_rst_info ohri;
  1382. int ret = -EINVAL;
  1383. if (!oh)
  1384. return -EINVAL;
  1385. if (!soc_ops.assert_hardreset)
  1386. return -ENOSYS;
  1387. ret = _lookup_hardreset(oh, name, &ohri);
  1388. if (ret < 0)
  1389. return ret;
  1390. ret = soc_ops.assert_hardreset(oh, &ohri);
  1391. return ret;
  1392. }
  1393. /**
  1394. * _deassert_hardreset - deassert the HW reset line of submodules contained
  1395. * in the hwmod module.
  1396. * @oh: struct omap_hwmod *
  1397. * @name: name of the reset line to look up and deassert
  1398. *
  1399. * Some IP like dsp, ipu or iva contain processor that require an HW
  1400. * reset line to be assert / deassert in order to enable fully the IP.
  1401. * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
  1402. * deasserting the hardreset line on the currently-booted SoC, or passes
  1403. * along the return value from _lookup_hardreset() or the SoC's
  1404. * deassert_hardreset code.
  1405. */
  1406. static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
  1407. {
  1408. struct omap_hwmod_rst_info ohri;
  1409. int ret = -EINVAL;
  1410. int hwsup = 0;
  1411. if (!oh)
  1412. return -EINVAL;
  1413. if (!soc_ops.deassert_hardreset)
  1414. return -ENOSYS;
  1415. ret = _lookup_hardreset(oh, name, &ohri);
  1416. if (IS_ERR_VALUE(ret))
  1417. return ret;
  1418. if (oh->clkdm) {
  1419. /*
  1420. * A clockdomain must be in SW_SUP otherwise reset
  1421. * might not be completed. The clockdomain can be set
  1422. * in HW_AUTO only when the module become ready.
  1423. */
  1424. hwsup = clkdm_in_hwsup(oh->clkdm);
  1425. ret = clkdm_hwmod_enable(oh->clkdm, oh);
  1426. if (ret) {
  1427. WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
  1428. oh->name, oh->clkdm->name, ret);
  1429. return ret;
  1430. }
  1431. }
  1432. _enable_clocks(oh);
  1433. if (soc_ops.enable_module)
  1434. soc_ops.enable_module(oh);
  1435. ret = soc_ops.deassert_hardreset(oh, &ohri);
  1436. if (soc_ops.disable_module)
  1437. soc_ops.disable_module(oh);
  1438. _disable_clocks(oh);
  1439. if (ret == -EBUSY)
  1440. pr_warning("omap_hwmod: %s: failed to hardreset\n", oh->name);
  1441. if (!ret) {
  1442. /*
  1443. * Set the clockdomain to HW_AUTO, assuming that the
  1444. * previous state was HW_AUTO.
  1445. */
  1446. if (oh->clkdm && hwsup)
  1447. clkdm_allow_idle(oh->clkdm);
  1448. } else {
  1449. if (oh->clkdm)
  1450. clkdm_hwmod_disable(oh->clkdm, oh);
  1451. }
  1452. return ret;
  1453. }
  1454. /**
  1455. * _read_hardreset - read the HW reset line state of submodules
  1456. * contained in the hwmod module
  1457. * @oh: struct omap_hwmod *
  1458. * @name: name of the reset line to look up and read
  1459. *
  1460. * Return the state of the reset line. Returns -EINVAL if @oh is
  1461. * null, -ENOSYS if we have no way of reading the hardreset line
  1462. * status on the currently-booted SoC, or passes along the return
  1463. * value from _lookup_hardreset() or the SoC's is_hardreset_asserted
  1464. * code.
  1465. */
  1466. static int _read_hardreset(struct omap_hwmod *oh, const char *name)
  1467. {
  1468. struct omap_hwmod_rst_info ohri;
  1469. int ret = -EINVAL;
  1470. if (!oh)
  1471. return -EINVAL;
  1472. if (!soc_ops.is_hardreset_asserted)
  1473. return -ENOSYS;
  1474. ret = _lookup_hardreset(oh, name, &ohri);
  1475. if (ret < 0)
  1476. return ret;
  1477. return soc_ops.is_hardreset_asserted(oh, &ohri);
  1478. }
  1479. /**
  1480. * _are_all_hardreset_lines_asserted - return true if the @oh is hard-reset
  1481. * @oh: struct omap_hwmod *
  1482. *
  1483. * If all hardreset lines associated with @oh are asserted, then return true.
  1484. * Otherwise, if part of @oh is out hardreset or if no hardreset lines
  1485. * associated with @oh are asserted, then return false.
  1486. * This function is used to avoid executing some parts of the IP block
  1487. * enable/disable sequence if its hardreset line is set.
  1488. */
  1489. static bool _are_all_hardreset_lines_asserted(struct omap_hwmod *oh)
  1490. {
  1491. int i, rst_cnt = 0;
  1492. if (oh->rst_lines_cnt == 0)
  1493. return false;
  1494. for (i = 0; i < oh->rst_lines_cnt; i++)
  1495. if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
  1496. rst_cnt++;
  1497. if (oh->rst_lines_cnt == rst_cnt)
  1498. return true;
  1499. return false;
  1500. }
  1501. /**
  1502. * _are_any_hardreset_lines_asserted - return true if any part of @oh is
  1503. * hard-reset
  1504. * @oh: struct omap_hwmod *
  1505. *
  1506. * If any hardreset lines associated with @oh are asserted, then
  1507. * return true. Otherwise, if no hardreset lines associated with @oh
  1508. * are asserted, or if @oh has no hardreset lines, then return false.
  1509. * This function is used to avoid executing some parts of the IP block
  1510. * enable/disable sequence if any hardreset line is set.
  1511. */
  1512. static bool _are_any_hardreset_lines_asserted(struct omap_hwmod *oh)
  1513. {
  1514. int rst_cnt = 0;
  1515. int i;
  1516. for (i = 0; i < oh->rst_lines_cnt && rst_cnt == 0; i++)
  1517. if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
  1518. rst_cnt++;
  1519. return (rst_cnt) ? true : false;
  1520. }
  1521. /**
  1522. * _omap4_disable_module - enable CLKCTRL modulemode on OMAP4
  1523. * @oh: struct omap_hwmod *
  1524. *
  1525. * Disable the PRCM module mode related to the hwmod @oh.
  1526. * Return EINVAL if the modulemode is not supported and 0 in case of success.
  1527. */
  1528. static int _omap4_disable_module(struct omap_hwmod *oh)
  1529. {
  1530. int v;
  1531. if (!oh->clkdm || !oh->prcm.omap4.modulemode)
  1532. return -EINVAL;
  1533. /*
  1534. * Since integration code might still be doing something, only
  1535. * disable if all lines are under hardreset.
  1536. */
  1537. if (_are_any_hardreset_lines_asserted(oh))
  1538. return 0;
  1539. pr_debug("omap_hwmod: %s: %s\n", oh->name, __func__);
  1540. omap4_cminst_module_disable(oh->clkdm->prcm_partition,
  1541. oh->clkdm->cm_inst,
  1542. oh->clkdm->clkdm_offs,
  1543. oh->prcm.omap4.clkctrl_offs);
  1544. v = _omap4_wait_target_disable(oh);
  1545. if (v)
  1546. pr_warn("omap_hwmod: %s: _wait_target_disable failed\n",
  1547. oh->name);