omap_hwmod.c 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791
  1. /*
  2. * omap_hwmod implementation for OMAP2/3/4
  3. *
  4. * Copyright (C) 2009-2011 Nokia Corporation
  5. * Copyright (C) 2011 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.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 "common.h"
  140. #include <plat/cpu.h>
  141. #include "clockdomain.h"
  142. #include "powerdomain.h"
  143. #include <plat/clock.h>
  144. #include <plat/omap_hwmod.h>
  145. #include <plat/prcm.h>
  146. #include "cm2xxx_3xxx.h"
  147. #include "cminst44xx.h"
  148. #include "prm2xxx_3xxx.h"
  149. #include "prm44xx.h"
  150. #include "prminst44xx.h"
  151. #include "mux.h"
  152. /* Maximum microseconds to wait for OMAP module to softreset */
  153. #define MAX_MODULE_SOFTRESET_WAIT 10000
  154. /* Name of the OMAP hwmod for the MPU */
  155. #define MPU_INITIATOR_NAME "mpu"
  156. /* omap_hwmod_list contains all registered struct omap_hwmods */
  157. static LIST_HEAD(omap_hwmod_list);
  158. /* mpu_oh: used to add/remove MPU initiator from sleepdep list */
  159. static struct omap_hwmod *mpu_oh;
  160. /* Private functions */
  161. /**
  162. * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
  163. * @oh: struct omap_hwmod *
  164. *
  165. * Load the current value of the hwmod OCP_SYSCONFIG register into the
  166. * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no
  167. * OCP_SYSCONFIG register or 0 upon success.
  168. */
  169. static int _update_sysc_cache(struct omap_hwmod *oh)
  170. {
  171. if (!oh->class->sysc) {
  172. WARN(1, "omap_hwmod: %s: cannot read OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
  173. return -EINVAL;
  174. }
  175. /* XXX ensure module interface clock is up */
  176. oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
  177. if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
  178. oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
  179. return 0;
  180. }
  181. /**
  182. * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
  183. * @v: OCP_SYSCONFIG value to write
  184. * @oh: struct omap_hwmod *
  185. *
  186. * Write @v into the module class' OCP_SYSCONFIG register, if it has
  187. * one. No return value.
  188. */
  189. static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
  190. {
  191. if (!oh->class->sysc) {
  192. WARN(1, "omap_hwmod: %s: cannot write OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
  193. return;
  194. }
  195. /* XXX ensure module interface clock is up */
  196. /* Module might have lost context, always update cache and register */
  197. oh->_sysc_cache = v;
  198. omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs);
  199. }
  200. /**
  201. * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v
  202. * @oh: struct omap_hwmod *
  203. * @standbymode: MIDLEMODE field bits
  204. * @v: pointer to register contents to modify
  205. *
  206. * Update the master standby mode bits in @v to be @standbymode for
  207. * the @oh hwmod. Does not write to the hardware. Returns -EINVAL
  208. * upon error or 0 upon success.
  209. */
  210. static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
  211. u32 *v)
  212. {
  213. u32 mstandby_mask;
  214. u8 mstandby_shift;
  215. if (!oh->class->sysc ||
  216. !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE))
  217. return -EINVAL;
  218. if (!oh->class->sysc->sysc_fields) {
  219. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  220. return -EINVAL;
  221. }
  222. mstandby_shift = oh->class->sysc->sysc_fields->midle_shift;
  223. mstandby_mask = (0x3 << mstandby_shift);
  224. *v &= ~mstandby_mask;
  225. *v |= __ffs(standbymode) << mstandby_shift;
  226. return 0;
  227. }
  228. /**
  229. * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
  230. * @oh: struct omap_hwmod *
  231. * @idlemode: SIDLEMODE field bits
  232. * @v: pointer to register contents to modify
  233. *
  234. * Update the slave idle mode bits in @v to be @idlemode for the @oh
  235. * hwmod. Does not write to the hardware. Returns -EINVAL upon error
  236. * or 0 upon success.
  237. */
  238. static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
  239. {
  240. u32 sidle_mask;
  241. u8 sidle_shift;
  242. if (!oh->class->sysc ||
  243. !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE))
  244. return -EINVAL;
  245. if (!oh->class->sysc->sysc_fields) {
  246. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  247. return -EINVAL;
  248. }
  249. sidle_shift = oh->class->sysc->sysc_fields->sidle_shift;
  250. sidle_mask = (0x3 << sidle_shift);
  251. *v &= ~sidle_mask;
  252. *v |= __ffs(idlemode) << sidle_shift;
  253. return 0;
  254. }
  255. /**
  256. * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
  257. * @oh: struct omap_hwmod *
  258. * @clockact: CLOCKACTIVITY field bits
  259. * @v: pointer to register contents to modify
  260. *
  261. * Update the clockactivity mode bits in @v to be @clockact for the
  262. * @oh hwmod. Used for additional powersaving on some modules. Does
  263. * not write to the hardware. Returns -EINVAL upon error or 0 upon
  264. * success.
  265. */
  266. static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
  267. {
  268. u32 clkact_mask;
  269. u8 clkact_shift;
  270. if (!oh->class->sysc ||
  271. !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
  272. return -EINVAL;
  273. if (!oh->class->sysc->sysc_fields) {
  274. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  275. return -EINVAL;
  276. }
  277. clkact_shift = oh->class->sysc->sysc_fields->clkact_shift;
  278. clkact_mask = (0x3 << clkact_shift);
  279. *v &= ~clkact_mask;
  280. *v |= clockact << clkact_shift;
  281. return 0;
  282. }
  283. /**
  284. * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
  285. * @oh: struct omap_hwmod *
  286. * @v: pointer to register contents to modify
  287. *
  288. * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
  289. * error or 0 upon success.
  290. */
  291. static int _set_softreset(struct omap_hwmod *oh, u32 *v)
  292. {
  293. u32 softrst_mask;
  294. if (!oh->class->sysc ||
  295. !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
  296. return -EINVAL;
  297. if (!oh->class->sysc->sysc_fields) {
  298. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  299. return -EINVAL;
  300. }
  301. softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
  302. *v |= softrst_mask;
  303. return 0;
  304. }
  305. /**
  306. * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v
  307. * @oh: struct omap_hwmod *
  308. * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
  309. * @v: pointer to register contents to modify
  310. *
  311. * Update the module autoidle bit in @v to be @autoidle for the @oh
  312. * hwmod. The autoidle bit controls whether the module can gate
  313. * internal clocks automatically when it isn't doing anything; the
  314. * exact function of this bit varies on a per-module basis. This
  315. * function does not write to the hardware. Returns -EINVAL upon
  316. * error or 0 upon success.
  317. */
  318. static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle,
  319. u32 *v)
  320. {
  321. u32 autoidle_mask;
  322. u8 autoidle_shift;
  323. if (!oh->class->sysc ||
  324. !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE))
  325. return -EINVAL;
  326. if (!oh->class->sysc->sysc_fields) {
  327. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  328. return -EINVAL;
  329. }
  330. autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift;
  331. autoidle_mask = (0x1 << autoidle_shift);
  332. *v &= ~autoidle_mask;
  333. *v |= autoidle << autoidle_shift;
  334. return 0;
  335. }
  336. /**
  337. * _set_idle_ioring_wakeup - enable/disable IO pad wakeup on hwmod idle for mux
  338. * @oh: struct omap_hwmod *
  339. * @set_wake: bool value indicating to set (true) or clear (false) wakeup enable
  340. *
  341. * Set or clear the I/O pad wakeup flag in the mux entries for the
  342. * hwmod @oh. This function changes the @oh->mux->pads_dynamic array
  343. * in memory. If the hwmod is currently idled, and the new idle
  344. * values don't match the previous ones, this function will also
  345. * update the SCM PADCTRL registers. Otherwise, if the hwmod is not
  346. * currently idled, this function won't touch the hardware: the new
  347. * mux settings are written to the SCM PADCTRL registers when the
  348. * hwmod is idled. No return value.
  349. */
  350. static void _set_idle_ioring_wakeup(struct omap_hwmod *oh, bool set_wake)
  351. {
  352. struct omap_device_pad *pad;
  353. bool change = false;
  354. u16 prev_idle;
  355. int j;
  356. if (!oh->mux || !oh->mux->enabled)
  357. return;
  358. for (j = 0; j < oh->mux->nr_pads_dynamic; j++) {
  359. pad = oh->mux->pads_dynamic[j];
  360. if (!(pad->flags & OMAP_DEVICE_PAD_WAKEUP))
  361. continue;
  362. prev_idle = pad->idle;
  363. if (set_wake)
  364. pad->idle |= OMAP_WAKEUP_EN;
  365. else
  366. pad->idle &= ~OMAP_WAKEUP_EN;
  367. if (prev_idle != pad->idle)
  368. change = true;
  369. }
  370. if (change && oh->_state == _HWMOD_STATE_IDLE)
  371. omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
  372. }
  373. /**
  374. * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
  375. * @oh: struct omap_hwmod *
  376. *
  377. * Allow the hardware module @oh to send wakeups. Returns -EINVAL
  378. * upon error or 0 upon success.
  379. */
  380. static int _enable_wakeup(struct omap_hwmod *oh, u32 *v)
  381. {
  382. if (!oh->class->sysc ||
  383. !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
  384. (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
  385. (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
  386. return -EINVAL;
  387. if (!oh->class->sysc->sysc_fields) {
  388. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  389. return -EINVAL;
  390. }
  391. if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
  392. *v |= 0x1 << oh->class->sysc->sysc_fields->enwkup_shift;
  393. if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
  394. _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
  395. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  396. _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
  397. /* XXX test pwrdm_get_wken for this hwmod's subsystem */
  398. oh->_int_flags |= _HWMOD_WAKEUP_ENABLED;
  399. return 0;
  400. }
  401. /**
  402. * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
  403. * @oh: struct omap_hwmod *
  404. *
  405. * Prevent the hardware module @oh to send wakeups. Returns -EINVAL
  406. * upon error or 0 upon success.
  407. */
  408. static int _disable_wakeup(struct omap_hwmod *oh, u32 *v)
  409. {
  410. if (!oh->class->sysc ||
  411. !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
  412. (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
  413. (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
  414. return -EINVAL;
  415. if (!oh->class->sysc->sysc_fields) {
  416. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  417. return -EINVAL;
  418. }
  419. if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
  420. *v &= ~(0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
  421. if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
  422. _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v);
  423. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  424. _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
  425. /* XXX test pwrdm_get_wken for this hwmod's subsystem */
  426. oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED;
  427. return 0;
  428. }
  429. /**
  430. * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
  431. * @oh: struct omap_hwmod *
  432. *
  433. * Prevent the hardware module @oh from entering idle while the
  434. * hardare module initiator @init_oh is active. Useful when a module
  435. * will be accessed by a particular initiator (e.g., if a module will
  436. * be accessed by the IVA, there should be a sleepdep between the IVA
  437. * initiator and the module). Only applies to modules in smart-idle
  438. * mode. If the clockdomain is marked as not needing autodeps, return
  439. * 0 without doing anything. Otherwise, returns -EINVAL upon error or
  440. * passes along clkdm_add_sleepdep() value upon success.
  441. */
  442. static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
  443. {
  444. if (!oh->_clk)
  445. return -EINVAL;
  446. if (oh->_clk->clkdm && oh->_clk->clkdm->flags & CLKDM_NO_AUTODEPS)
  447. return 0;
  448. return clkdm_add_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
  449. }
  450. /**
  451. * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
  452. * @oh: struct omap_hwmod *
  453. *
  454. * Allow the hardware module @oh to enter idle while the hardare
  455. * module initiator @init_oh is active. Useful when a module will not
  456. * be accessed by a particular initiator (e.g., if a module will not
  457. * be accessed by the IVA, there should be no sleepdep between the IVA
  458. * initiator and the module). Only applies to modules in smart-idle
  459. * mode. If the clockdomain is marked as not needing autodeps, return
  460. * 0 without doing anything. Returns -EINVAL upon error or passes
  461. * along clkdm_del_sleepdep() value upon success.
  462. */
  463. static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
  464. {
  465. if (!oh->_clk)
  466. return -EINVAL;
  467. if (oh->_clk->clkdm && oh->_clk->clkdm->flags & CLKDM_NO_AUTODEPS)
  468. return 0;
  469. return clkdm_del_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
  470. }
  471. /**
  472. * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
  473. * @oh: struct omap_hwmod *
  474. *
  475. * Called from _init_clocks(). Populates the @oh _clk (main
  476. * functional clock pointer) if a main_clk is present. Returns 0 on
  477. * success or -EINVAL on error.
  478. */
  479. static int _init_main_clk(struct omap_hwmod *oh)
  480. {
  481. int ret = 0;
  482. if (!oh->main_clk)
  483. return 0;
  484. oh->_clk = omap_clk_get_by_name(oh->main_clk);
  485. if (!oh->_clk) {
  486. pr_warning("omap_hwmod: %s: cannot clk_get main_clk %s\n",
  487. oh->name, oh->main_clk);
  488. return -EINVAL;
  489. }
  490. if (!oh->_clk->clkdm)
  491. pr_warning("omap_hwmod: %s: missing clockdomain for %s.\n",
  492. oh->main_clk, oh->_clk->name);
  493. return ret;
  494. }
  495. /**
  496. * _init_interface_clks - get a struct clk * for the the hwmod's interface clks
  497. * @oh: struct omap_hwmod *
  498. *
  499. * Called from _init_clocks(). Populates the @oh OCP slave interface
  500. * clock pointers. Returns 0 on success or -EINVAL on error.
  501. */
  502. static int _init_interface_clks(struct omap_hwmod *oh)
  503. {
  504. struct clk *c;
  505. int i;
  506. int ret = 0;
  507. if (oh->slaves_cnt == 0)
  508. return 0;
  509. for (i = 0; i < oh->slaves_cnt; i++) {
  510. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  511. if (!os->clk)
  512. continue;
  513. c = omap_clk_get_by_name(os->clk);
  514. if (!c) {
  515. pr_warning("omap_hwmod: %s: cannot clk_get interface_clk %s\n",
  516. oh->name, os->clk);
  517. ret = -EINVAL;
  518. }
  519. os->_clk = c;
  520. }
  521. return ret;
  522. }
  523. /**
  524. * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
  525. * @oh: struct omap_hwmod *
  526. *
  527. * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk
  528. * clock pointers. Returns 0 on success or -EINVAL on error.
  529. */
  530. static int _init_opt_clks(struct omap_hwmod *oh)
  531. {
  532. struct omap_hwmod_opt_clk *oc;
  533. struct clk *c;
  534. int i;
  535. int ret = 0;
  536. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
  537. c = omap_clk_get_by_name(oc->clk);
  538. if (!c) {
  539. pr_warning("omap_hwmod: %s: cannot clk_get opt_clk %s\n",
  540. oh->name, oc->clk);
  541. ret = -EINVAL;
  542. }
  543. oc->_clk = c;
  544. }
  545. return ret;
  546. }
  547. /**
  548. * _enable_clocks - enable hwmod main clock and interface clocks
  549. * @oh: struct omap_hwmod *
  550. *
  551. * Enables all clocks necessary for register reads and writes to succeed
  552. * on the hwmod @oh. Returns 0.
  553. */
  554. static int _enable_clocks(struct omap_hwmod *oh)
  555. {
  556. int i;
  557. pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
  558. if (oh->_clk)
  559. clk_enable(oh->_clk);
  560. if (oh->slaves_cnt > 0) {
  561. for (i = 0; i < oh->slaves_cnt; i++) {
  562. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  563. struct clk *c = os->_clk;
  564. if (c && (os->flags & OCPIF_SWSUP_IDLE))
  565. clk_enable(c);
  566. }
  567. }
  568. /* The opt clocks are controlled by the device driver. */
  569. return 0;
  570. }
  571. /**
  572. * _disable_clocks - disable hwmod main clock and interface clocks
  573. * @oh: struct omap_hwmod *
  574. *
  575. * Disables the hwmod @oh main functional and interface clocks. Returns 0.
  576. */
  577. static int _disable_clocks(struct omap_hwmod *oh)
  578. {
  579. int i;
  580. pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
  581. if (oh->_clk)
  582. clk_disable(oh->_clk);
  583. if (oh->slaves_cnt > 0) {
  584. for (i = 0; i < oh->slaves_cnt; i++) {
  585. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  586. struct clk *c = os->_clk;
  587. if (c && (os->flags & OCPIF_SWSUP_IDLE))
  588. clk_disable(c);
  589. }
  590. }
  591. /* The opt clocks are controlled by the device driver. */
  592. return 0;
  593. }
  594. static void _enable_optional_clocks(struct omap_hwmod *oh)
  595. {
  596. struct omap_hwmod_opt_clk *oc;
  597. int i;
  598. pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name);
  599. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  600. if (oc->_clk) {
  601. pr_debug("omap_hwmod: enable %s:%s\n", oc->role,
  602. oc->_clk->name);
  603. clk_enable(oc->_clk);
  604. }
  605. }
  606. static void _disable_optional_clocks(struct omap_hwmod *oh)
  607. {
  608. struct omap_hwmod_opt_clk *oc;
  609. int i;
  610. pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name);
  611. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  612. if (oc->_clk) {
  613. pr_debug("omap_hwmod: disable %s:%s\n", oc->role,
  614. oc->_clk->name);
  615. clk_disable(oc->_clk);
  616. }
  617. }
  618. /**
  619. * _enable_module - enable CLKCTRL modulemode on OMAP4
  620. * @oh: struct omap_hwmod *
  621. *
  622. * Enables the PRCM module mode related to the hwmod @oh.
  623. * No return value.
  624. */
  625. static void _enable_module(struct omap_hwmod *oh)
  626. {
  627. /* The module mode does not exist prior OMAP4 */
  628. if (cpu_is_omap24xx() || cpu_is_omap34xx())
  629. return;
  630. if (!oh->clkdm || !oh->prcm.omap4.modulemode)
  631. return;
  632. pr_debug("omap_hwmod: %s: _enable_module: %d\n",
  633. oh->name, oh->prcm.omap4.modulemode);
  634. omap4_cminst_module_enable(oh->prcm.omap4.modulemode,
  635. oh->clkdm->prcm_partition,
  636. oh->clkdm->cm_inst,
  637. oh->clkdm->clkdm_offs,
  638. oh->prcm.omap4.clkctrl_offs);
  639. }
  640. /**
  641. * _omap4_wait_target_disable - wait for a module to be disabled on OMAP4
  642. * @oh: struct omap_hwmod *
  643. *
  644. * Wait for a module @oh to enter slave idle. Returns 0 if the module
  645. * does not have an IDLEST bit or if the module successfully enters
  646. * slave idle; otherwise, pass along the return value of the
  647. * appropriate *_cm*_wait_module_idle() function.
  648. */
  649. static int _omap4_wait_target_disable(struct omap_hwmod *oh)
  650. {
  651. if (!cpu_is_omap44xx())
  652. return 0;
  653. if (!oh)
  654. return -EINVAL;
  655. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  656. return 0;
  657. if (oh->flags & HWMOD_NO_IDLEST)
  658. return 0;
  659. return omap4_cminst_wait_module_idle(oh->clkdm->prcm_partition,
  660. oh->clkdm->cm_inst,
  661. oh->clkdm->clkdm_offs,
  662. oh->prcm.omap4.clkctrl_offs);
  663. }
  664. /**
  665. * _omap4_disable_module - enable CLKCTRL modulemode on OMAP4
  666. * @oh: struct omap_hwmod *
  667. *
  668. * Disable the PRCM module mode related to the hwmod @oh.
  669. * Return EINVAL if the modulemode is not supported and 0 in case of success.
  670. */
  671. static int _omap4_disable_module(struct omap_hwmod *oh)
  672. {
  673. int v;
  674. /* The module mode does not exist prior OMAP4 */
  675. if (!cpu_is_omap44xx())
  676. return -EINVAL;
  677. if (!oh->clkdm || !oh->prcm.omap4.modulemode)
  678. return -EINVAL;
  679. pr_debug("omap_hwmod: %s: %s\n", oh->name, __func__);
  680. omap4_cminst_module_disable(oh->clkdm->prcm_partition,
  681. oh->clkdm->cm_inst,
  682. oh->clkdm->clkdm_offs,
  683. oh->prcm.omap4.clkctrl_offs);
  684. v = _omap4_wait_target_disable(oh);
  685. if (v)
  686. pr_warn("omap_hwmod: %s: _wait_target_disable failed\n",
  687. oh->name);
  688. return 0;
  689. }
  690. /**
  691. * _count_mpu_irqs - count the number of MPU IRQ lines associated with @oh
  692. * @oh: struct omap_hwmod *oh
  693. *
  694. * Count and return the number of MPU IRQs associated with the hwmod
  695. * @oh. Used to allocate struct resource data. Returns 0 if @oh is
  696. * NULL.
  697. */
  698. static int _count_mpu_irqs(struct omap_hwmod *oh)
  699. {
  700. struct omap_hwmod_irq_info *ohii;
  701. int i = 0;
  702. if (!oh || !oh->mpu_irqs)
  703. return 0;
  704. do {
  705. ohii = &oh->mpu_irqs[i++];
  706. } while (ohii->irq != -1);
  707. return i-1;
  708. }
  709. /**
  710. * _count_sdma_reqs - count the number of SDMA request lines associated with @oh
  711. * @oh: struct omap_hwmod *oh
  712. *
  713. * Count and return the number of SDMA request lines associated with
  714. * the hwmod @oh. Used to allocate struct resource data. Returns 0
  715. * if @oh is NULL.
  716. */
  717. static int _count_sdma_reqs(struct omap_hwmod *oh)
  718. {
  719. struct omap_hwmod_dma_info *ohdi;
  720. int i = 0;
  721. if (!oh || !oh->sdma_reqs)
  722. return 0;
  723. do {
  724. ohdi = &oh->sdma_reqs[i++];
  725. } while (ohdi->dma_req != -1);
  726. return i-1;
  727. }
  728. /**
  729. * _count_ocp_if_addr_spaces - count the number of address space entries for @oh
  730. * @oh: struct omap_hwmod *oh
  731. *
  732. * Count and return the number of address space ranges associated with
  733. * the hwmod @oh. Used to allocate struct resource data. Returns 0
  734. * if @oh is NULL.
  735. */
  736. static int _count_ocp_if_addr_spaces(struct omap_hwmod_ocp_if *os)
  737. {
  738. struct omap_hwmod_addr_space *mem;
  739. int i = 0;
  740. if (!os || !os->addr)
  741. return 0;
  742. do {
  743. mem = &os->addr[i++];
  744. } while (mem->pa_start != mem->pa_end);
  745. return i-1;
  746. }
  747. /**
  748. * _find_mpu_port_index - find hwmod OCP slave port ID intended for MPU use
  749. * @oh: struct omap_hwmod *
  750. *
  751. * Returns the array index of the OCP slave port that the MPU
  752. * addresses the device on, or -EINVAL upon error or not found.
  753. */
  754. static int __init _find_mpu_port_index(struct omap_hwmod *oh)
  755. {
  756. int i;
  757. int found = 0;
  758. if (!oh || oh->slaves_cnt == 0)
  759. return -EINVAL;
  760. for (i = 0; i < oh->slaves_cnt; i++) {
  761. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  762. if (os->user & OCP_USER_MPU) {
  763. found = 1;
  764. break;
  765. }
  766. }
  767. if (found)
  768. pr_debug("omap_hwmod: %s: MPU OCP slave port ID %d\n",
  769. oh->name, i);
  770. else
  771. pr_debug("omap_hwmod: %s: no MPU OCP slave port found\n",
  772. oh->name);
  773. return (found) ? i : -EINVAL;
  774. }
  775. /**
  776. * _find_mpu_rt_base - find hwmod register target base addr accessible by MPU
  777. * @oh: struct omap_hwmod *
  778. *
  779. * Return the virtual address of the base of the register target of
  780. * device @oh, or NULL on error.
  781. */
  782. static void __iomem * __init _find_mpu_rt_base(struct omap_hwmod *oh, u8 index)
  783. {
  784. struct omap_hwmod_ocp_if *os;
  785. struct omap_hwmod_addr_space *mem;
  786. int i = 0, found = 0;
  787. void __iomem *va_start;
  788. if (!oh || oh->slaves_cnt == 0)
  789. return NULL;
  790. os = oh->slaves[index];
  791. if (!os->addr)
  792. return NULL;
  793. do {
  794. mem = &os->addr[i++];
  795. if (mem->flags & ADDR_TYPE_RT)
  796. found = 1;
  797. } while (!found && mem->pa_start != mem->pa_end);
  798. if (found) {
  799. va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start);
  800. if (!va_start) {
  801. pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name);
  802. return NULL;
  803. }
  804. pr_debug("omap_hwmod: %s: MPU register target at va %p\n",
  805. oh->name, va_start);
  806. } else {
  807. pr_debug("omap_hwmod: %s: no MPU register target found\n",
  808. oh->name);
  809. }
  810. return (found) ? va_start : NULL;
  811. }
  812. /**
  813. * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG
  814. * @oh: struct omap_hwmod *
  815. *
  816. * If module is marked as SWSUP_SIDLE, force the module out of slave
  817. * idle; otherwise, configure it for smart-idle. If module is marked
  818. * as SWSUP_MSUSPEND, force the module out of master standby;
  819. * otherwise, configure it for smart-standby. No return value.
  820. */
  821. static void _enable_sysc(struct omap_hwmod *oh)
  822. {
  823. u8 idlemode, sf;
  824. u32 v;
  825. if (!oh->class->sysc)
  826. return;
  827. v = oh->_sysc_cache;
  828. sf = oh->class->sysc->sysc_flags;
  829. if (sf & SYSC_HAS_SIDLEMODE) {
  830. idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
  831. HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
  832. _set_slave_idlemode(oh, idlemode, &v);
  833. }
  834. if (sf & SYSC_HAS_MIDLEMODE) {
  835. if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
  836. idlemode = HWMOD_IDLEMODE_NO;
  837. } else {
  838. if (sf & SYSC_HAS_ENAWAKEUP)
  839. _enable_wakeup(oh, &v);
  840. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  841. idlemode = HWMOD_IDLEMODE_SMART_WKUP;
  842. else
  843. idlemode = HWMOD_IDLEMODE_SMART;
  844. }
  845. _set_master_standbymode(oh, idlemode, &v);
  846. }
  847. /*
  848. * XXX The clock framework should handle this, by
  849. * calling into this code. But this must wait until the
  850. * clock structures are tagged with omap_hwmod entries
  851. */
  852. if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
  853. (sf & SYSC_HAS_CLOCKACTIVITY))
  854. _set_clockactivity(oh, oh->class->sysc->clockact, &v);
  855. /* If slave is in SMARTIDLE, also enable wakeup */
  856. if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
  857. _enable_wakeup(oh, &v);
  858. _write_sysconfig(v, oh);
  859. /*
  860. * Set the autoidle bit only after setting the smartidle bit
  861. * Setting this will not have any impact on the other modules.
  862. */
  863. if (sf & SYSC_HAS_AUTOIDLE) {
  864. idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
  865. 0 : 1;
  866. _set_module_autoidle(oh, idlemode, &v);
  867. _write_sysconfig(v, oh);
  868. }
  869. }
  870. /**
  871. * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG
  872. * @oh: struct omap_hwmod *
  873. *
  874. * If module is marked as SWSUP_SIDLE, force the module into slave
  875. * idle; otherwise, configure it for smart-idle. If module is marked
  876. * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
  877. * configure it for smart-standby. No return value.
  878. */
  879. static void _idle_sysc(struct omap_hwmod *oh)
  880. {
  881. u8 idlemode, sf;
  882. u32 v;
  883. if (!oh->class->sysc)
  884. return;
  885. v = oh->_sysc_cache;
  886. sf = oh->class->sysc->sysc_flags;
  887. if (sf & SYSC_HAS_SIDLEMODE) {
  888. idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
  889. HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART;
  890. _set_slave_idlemode(oh, idlemode, &v);
  891. }
  892. if (sf & SYSC_HAS_MIDLEMODE) {
  893. if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
  894. idlemode = HWMOD_IDLEMODE_FORCE;
  895. } else {
  896. if (sf & SYSC_HAS_ENAWAKEUP)
  897. _enable_wakeup(oh, &v);
  898. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  899. idlemode = HWMOD_IDLEMODE_SMART_WKUP;
  900. else
  901. idlemode = HWMOD_IDLEMODE_SMART;
  902. }
  903. _set_master_standbymode(oh, idlemode, &v);
  904. }
  905. /* If slave is in SMARTIDLE, also enable wakeup */
  906. if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
  907. _enable_wakeup(oh, &v);
  908. _write_sysconfig(v, oh);
  909. }
  910. /**
  911. * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG
  912. * @oh: struct omap_hwmod *
  913. *
  914. * Force the module into slave idle and master suspend. No return
  915. * value.
  916. */
  917. static void _shutdown_sysc(struct omap_hwmod *oh)
  918. {
  919. u32 v;
  920. u8 sf;
  921. if (!oh->class->sysc)
  922. return;
  923. v = oh->_sysc_cache;
  924. sf = oh->class->sysc->sysc_flags;
  925. if (sf & SYSC_HAS_SIDLEMODE)
  926. _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
  927. if (sf & SYSC_HAS_MIDLEMODE)
  928. _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
  929. if (sf & SYSC_HAS_AUTOIDLE)
  930. _set_module_autoidle(oh, 1, &v);
  931. _write_sysconfig(v, oh);
  932. }
  933. /**
  934. * _lookup - find an omap_hwmod by name
  935. * @name: find an omap_hwmod by name
  936. *
  937. * Return a pointer to an omap_hwmod by name, or NULL if not found.
  938. */
  939. static struct omap_hwmod *_lookup(const char *name)
  940. {
  941. struct omap_hwmod *oh, *temp_oh;
  942. oh = NULL;
  943. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  944. if (!strcmp(name, temp_oh->name)) {
  945. oh = temp_oh;
  946. break;
  947. }
  948. }
  949. return oh;
  950. }
  951. /**
  952. * _init_clkdm - look up a clockdomain name, store pointer in omap_hwmod
  953. * @oh: struct omap_hwmod *
  954. *
  955. * Convert a clockdomain name stored in a struct omap_hwmod into a
  956. * clockdomain pointer, and save it into the struct omap_hwmod.
  957. * return -EINVAL if clkdm_name does not exist or if the lookup failed.
  958. */
  959. static int _init_clkdm(struct omap_hwmod *oh)
  960. {
  961. if (cpu_is_omap24xx() || cpu_is_omap34xx())
  962. return 0;
  963. if (!oh->clkdm_name) {
  964. pr_warning("omap_hwmod: %s: no clkdm_name\n", oh->name);
  965. return -EINVAL;
  966. }
  967. oh->clkdm = clkdm_lookup(oh->clkdm_name);
  968. if (!oh->clkdm) {
  969. pr_warning("omap_hwmod: %s: could not associate to clkdm %s\n",
  970. oh->name, oh->clkdm_name);
  971. return -EINVAL;
  972. }
  973. pr_debug("omap_hwmod: %s: associated to clkdm %s\n",
  974. oh->name, oh->clkdm_name);
  975. return 0;
  976. }
  977. /**
  978. * _init_clocks - clk_get() all clocks associated with this hwmod. Retrieve as
  979. * well the clockdomain.
  980. * @oh: struct omap_hwmod *
  981. * @data: not used; pass NULL
  982. *
  983. * Called by omap_hwmod_setup_*() (after omap2_clk_init()).
  984. * Resolves all clock names embedded in the hwmod. Returns 0 on
  985. * success, or a negative error code on failure.
  986. */
  987. static int _init_clocks(struct omap_hwmod *oh, void *data)
  988. {
  989. int ret = 0;
  990. if (oh->_state != _HWMOD_STATE_REGISTERED)
  991. return 0;
  992. pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
  993. ret |= _init_main_clk(oh);
  994. ret |= _init_interface_clks(oh);
  995. ret |= _init_opt_clks(oh);
  996. ret |= _init_clkdm(oh);
  997. if (!ret)
  998. oh->_state = _HWMOD_STATE_CLKS_INITED;
  999. else
  1000. pr_warning("omap_hwmod: %s: cannot _init_clocks\n", oh->name);
  1001. return ret;
  1002. }
  1003. /**
  1004. * _wait_target_ready - wait for a module to leave slave idle
  1005. * @oh: struct omap_hwmod *
  1006. *
  1007. * Wait for a module @oh to leave slave idle. Returns 0 if the module
  1008. * does not have an IDLEST bit or if the module successfully leaves
  1009. * slave idle; otherwise, pass along the return value of the
  1010. * appropriate *_cm*_wait_module_ready() function.
  1011. */
  1012. static int _wait_target_ready(struct omap_hwmod *oh)
  1013. {
  1014. struct omap_hwmod_ocp_if *os;
  1015. int ret;
  1016. if (!oh)
  1017. return -EINVAL;
  1018. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  1019. return 0;
  1020. os = oh->slaves[oh->_mpu_port_index];
  1021. if (oh->flags & HWMOD_NO_IDLEST)
  1022. return 0;
  1023. /* XXX check module SIDLEMODE */
  1024. /* XXX check clock enable states */
  1025. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  1026. ret = omap2_cm_wait_module_ready(oh->prcm.omap2.module_offs,
  1027. oh->prcm.omap2.idlest_reg_id,
  1028. oh->prcm.omap2.idlest_idle_bit);
  1029. } else if (cpu_is_omap44xx()) {
  1030. if (!oh->clkdm)
  1031. return -EINVAL;
  1032. ret = omap4_cminst_wait_module_ready(oh->clkdm->prcm_partition,
  1033. oh->clkdm->cm_inst,
  1034. oh->clkdm->clkdm_offs,
  1035. oh->prcm.omap4.clkctrl_offs);
  1036. } else {
  1037. BUG();
  1038. };
  1039. return ret;
  1040. }
  1041. /**
  1042. * _lookup_hardreset - fill register bit info for this hwmod/reset line
  1043. * @oh: struct omap_hwmod *
  1044. * @name: name of the reset line in the context of this hwmod
  1045. * @ohri: struct omap_hwmod_rst_info * that this function will fill in
  1046. *
  1047. * Return the bit position of the reset line that match the
  1048. * input name. Return -ENOENT if not found.
  1049. */
  1050. static u8 _lookup_hardreset(struct omap_hwmod *oh, const char *name,
  1051. struct omap_hwmod_rst_info *ohri)
  1052. {
  1053. int i;
  1054. for (i = 0; i < oh->rst_lines_cnt; i++) {
  1055. const char *rst_line = oh->rst_lines[i].name;
  1056. if (!strcmp(rst_line, name)) {
  1057. ohri->rst_shift = oh->rst_lines[i].rst_shift;
  1058. ohri->st_shift = oh->rst_lines[i].st_shift;
  1059. pr_debug("omap_hwmod: %s: %s: %s: rst %d st %d\n",
  1060. oh->name, __func__, rst_line, ohri->rst_shift,
  1061. ohri->st_shift);
  1062. return 0;
  1063. }
  1064. }
  1065. return -ENOENT;
  1066. }
  1067. /**
  1068. * _assert_hardreset - assert the HW reset line of submodules
  1069. * contained in the hwmod module.
  1070. * @oh: struct omap_hwmod *
  1071. * @name: name of the reset line to lookup and assert
  1072. *
  1073. * Some IP like dsp, ipu or iva contain processor that require
  1074. * an HW reset line to be assert / deassert in order to enable fully
  1075. * the IP.
  1076. */
  1077. static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
  1078. {
  1079. struct omap_hwmod_rst_info ohri;
  1080. u8 ret;
  1081. if (!oh)
  1082. return -EINVAL;
  1083. ret = _lookup_hardreset(oh, name, &ohri);
  1084. if (IS_ERR_VALUE(ret))
  1085. return ret;
  1086. if (cpu_is_omap24xx() || cpu_is_omap34xx())
  1087. return omap2_prm_assert_hardreset(oh->prcm.omap2.module_offs,
  1088. ohri.rst_shift);
  1089. else if (cpu_is_omap44xx())
  1090. return omap4_prminst_assert_hardreset(ohri.rst_shift,
  1091. oh->clkdm->pwrdm.ptr->prcm_partition,
  1092. oh->clkdm->pwrdm.ptr->prcm_offs,
  1093. oh->prcm.omap4.rstctrl_offs);
  1094. else
  1095. return -EINVAL;
  1096. }
  1097. /**
  1098. * _deassert_hardreset - deassert the HW reset line of submodules contained
  1099. * in the hwmod module.
  1100. * @oh: struct omap_hwmod *
  1101. * @name: name of the reset line to look up and deassert
  1102. *
  1103. * Some IP like dsp, ipu or iva contain processor that require
  1104. * an HW reset line to be assert / deassert in order to enable fully
  1105. * the IP.
  1106. */
  1107. static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
  1108. {
  1109. struct omap_hwmod_rst_info ohri;
  1110. int ret;
  1111. if (!oh)
  1112. return -EINVAL;
  1113. ret = _lookup_hardreset(oh, name, &ohri);
  1114. if (IS_ERR_VALUE(ret))
  1115. return ret;
  1116. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  1117. ret = omap2_prm_deassert_hardreset(oh->prcm.omap2.module_offs,
  1118. ohri.rst_shift,
  1119. ohri.st_shift);
  1120. } else if (cpu_is_omap44xx()) {
  1121. if (ohri.st_shift)
  1122. pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n",
  1123. oh->name, name);
  1124. ret = omap4_prminst_deassert_hardreset(ohri.rst_shift,
  1125. oh->clkdm->pwrdm.ptr->prcm_partition,
  1126. oh->clkdm->pwrdm.ptr->prcm_offs,
  1127. oh->prcm.omap4.rstctrl_offs);
  1128. } else {
  1129. return -EINVAL;
  1130. }
  1131. if (ret == -EBUSY)
  1132. pr_warning("omap_hwmod: %s: failed to hardreset\n", oh->name);
  1133. return ret;
  1134. }
  1135. /**
  1136. * _read_hardreset - read the HW reset line state of submodules
  1137. * contained in the hwmod module
  1138. * @oh: struct omap_hwmod *
  1139. * @name: name of the reset line to look up and read
  1140. *
  1141. * Return the state of the reset line.
  1142. */
  1143. static int _read_hardreset(struct omap_hwmod *oh, const char *name)
  1144. {
  1145. struct omap_hwmod_rst_info ohri;
  1146. u8 ret;
  1147. if (!oh)
  1148. return -EINVAL;
  1149. ret = _lookup_hardreset(oh, name, &ohri);
  1150. if (IS_ERR_VALUE(ret))
  1151. return ret;
  1152. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  1153. return omap2_prm_is_hardreset_asserted(oh->prcm.omap2.module_offs,
  1154. ohri.st_shift);
  1155. } else if (cpu_is_omap44xx()) {
  1156. return omap4_prminst_is_hardreset_asserted(ohri.rst_shift,
  1157. oh->clkdm->pwrdm.ptr->prcm_partition,
  1158. oh->clkdm->pwrdm.ptr->prcm_offs,
  1159. oh->prcm.omap4.rstctrl_offs);
  1160. } else {
  1161. return -EINVAL;
  1162. }
  1163. }
  1164. /**
  1165. * _ocp_softreset - reset an omap_hwmod via the OCP_SYSCONFIG bit
  1166. * @oh: struct omap_hwmod *
  1167. *
  1168. * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
  1169. * enabled for this to work. Returns -EINVAL if the hwmod cannot be
  1170. * reset this way or if the hwmod is in the wrong state, -ETIMEDOUT if
  1171. * the module did not reset in time, or 0 upon success.
  1172. *
  1173. * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
  1174. * Starting in OMAP4, some IPs do not have SYSSTATUS registers and instead
  1175. * use the SYSCONFIG softreset bit to provide the status.
  1176. *
  1177. * Note that some IP like McBSP do have reset control but don't have
  1178. * reset status.
  1179. */
  1180. static int _ocp_softreset(struct omap_hwmod *oh)
  1181. {
  1182. u32 v, softrst_mask;
  1183. int c = 0;
  1184. int ret = 0;
  1185. if (!oh->class->sysc ||
  1186. !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
  1187. return -EINVAL;
  1188. /* clocks must be on for this operation */
  1189. if (oh->_state != _HWMOD_STATE_ENABLED) {
  1190. pr_warning("omap_hwmod: %s: reset can only be entered from "
  1191. "enabled state\n", oh->name);
  1192. return -EINVAL;
  1193. }
  1194. /* For some modules, all optionnal clocks need to be enabled as well */
  1195. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  1196. _enable_optional_clocks(oh);
  1197. pr_debug("omap_hwmod: %s: resetting via OCP SOFTRESET\n", oh->name);
  1198. v = oh->_sysc_cache;
  1199. ret = _set_softreset(oh, &v);
  1200. if (ret)
  1201. goto dis_opt_clks;
  1202. _write_sysconfig(v, oh);
  1203. if (oh->class->sysc->srst_udelay)
  1204. udelay(oh->class->sysc->srst_udelay);
  1205. if (oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
  1206. omap_test_timeout((omap_hwmod_read(oh,
  1207. oh->class->sysc->syss_offs)
  1208. & SYSS_RESETDONE_MASK),
  1209. MAX_MODULE_SOFTRESET_WAIT, c);
  1210. else if (oh->class->sysc->sysc_flags & SYSC_HAS_RESET_STATUS) {
  1211. softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
  1212. omap_test_timeout(!(omap_hwmod_read(oh,
  1213. oh->class->sysc->sysc_offs)
  1214. & softrst_mask),
  1215. MAX_MODULE_SOFTRESET_WAIT, c);
  1216. }
  1217. if (c == MAX_MODULE_SOFTRESET_WAIT)
  1218. pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n",
  1219. oh->name, MAX_MODULE_SOFTRESET_WAIT);
  1220. else
  1221. pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
  1222. /*
  1223. * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
  1224. * _wait_target_ready() or _reset()
  1225. */
  1226. ret = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
  1227. dis_opt_clks:
  1228. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  1229. _disable_optional_clocks(oh);
  1230. return ret;
  1231. }
  1232. /**
  1233. * _reset - reset an omap_hwmod
  1234. * @oh: struct omap_hwmod *
  1235. *
  1236. * Resets an omap_hwmod @oh. The default software reset mechanism for
  1237. * most OMAP IP blocks is triggered via the OCP_SYSCONFIG.SOFTRESET
  1238. * bit. However, some hwmods cannot be reset via this method: some
  1239. * are not targets and therefore have no OCP header registers to
  1240. * access; others (like the IVA) have idiosyncratic reset sequences.
  1241. * So for these relatively rare cases, custom reset code can be
  1242. * supplied in the struct omap_hwmod_class .reset function pointer.
  1243. * Passes along the return value from either _reset() or the custom
  1244. * reset function - these must return -EINVAL if the hwmod cannot be
  1245. * reset this way or if the hwmod is in the wrong state, -ETIMEDOUT if
  1246. * the module did not reset in time, or 0 upon success.
  1247. */
  1248. static int _reset(struct omap_hwmod *oh)
  1249. {
  1250. int ret;
  1251. pr_debug("omap_hwmod: %s: resetting\n", oh->name);
  1252. /*
  1253. * XXX We're not resetting modules with hardreset lines
  1254. * automatically here. Should we do this also, or just expect
  1255. * those modules to define custom reset functions?
  1256. */
  1257. ret = (oh->class->reset) ? oh->class->reset(oh) : _ocp_softreset(oh);
  1258. if (oh->class->sysc) {
  1259. _update_sysc_cache(oh);
  1260. _enable_sysc(oh);
  1261. }
  1262. return ret;
  1263. }
  1264. /**
  1265. * _enable - enable an omap_hwmod
  1266. * @oh: struct omap_hwmod *
  1267. *
  1268. * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
  1269. * register target. Returns -EINVAL if the hwmod is in the wrong
  1270. * state or passes along the return value of _wait_target_ready().
  1271. */
  1272. static int _enable(struct omap_hwmod *oh)
  1273. {
  1274. int r, i;
  1275. int hwsup = 0;
  1276. pr_debug("omap_hwmod: %s: enabling\n", oh->name);
  1277. /*
  1278. * hwmods with HWMOD_INIT_NO_IDLE flag set are left
  1279. * in enabled state at init.
  1280. * Now that someone is really trying to enable them,
  1281. * just ensure that the hwmod mux is set.
  1282. */
  1283. if (oh->_int_flags & _HWMOD_SKIP_ENABLE) {
  1284. /*
  1285. * If the caller has mux data populated, do the mux'ing
  1286. * which wouldn't have been done as part of the _enable()
  1287. * done during setup.
  1288. */
  1289. if (oh->mux)
  1290. omap_hwmod_mux(oh->mux, _HWMOD_STATE_ENABLED);
  1291. oh->_int_flags &= ~_HWMOD_SKIP_ENABLE;
  1292. return 0;
  1293. }
  1294. if (oh->_state != _HWMOD_STATE_INITIALIZED &&
  1295. oh->_state != _HWMOD_STATE_IDLE &&
  1296. oh->_state != _HWMOD_STATE_DISABLED) {
  1297. WARN(1, "omap_hwmod: %s: enabled state can only be entered from initialized, idle, or disabled state\n",
  1298. oh->name);
  1299. return -EINVAL;
  1300. }
  1301. /*
  1302. * If an IP contains HW reset lines, then de-assert them in order
  1303. * to allow the module state transition. Otherwise the PRCM will return
  1304. * Intransition status, and the init will failed.
  1305. */
  1306. if (oh->_state == _HWMOD_STATE_INITIALIZED ||
  1307. oh->_state == _HWMOD_STATE_DISABLED)
  1308. for (i = 0; i < oh->rst_lines_cnt; i++)
  1309. _deassert_hardreset(oh, oh->rst_lines[i].name);
  1310. /* Mux pins for device runtime if populated */
  1311. if (oh->mux && (!oh->mux->enabled ||
  1312. ((oh->_state == _HWMOD_STATE_IDLE) &&
  1313. oh->mux->pads_dynamic)))
  1314. omap_hwmod_mux(oh->mux, _HWMOD_STATE_ENABLED);
  1315. _add_initiator_dep(oh, mpu_oh);
  1316. if (oh->clkdm) {
  1317. /*
  1318. * A clockdomain must be in SW_SUP before enabling
  1319. * completely the module. The clockdomain can be set
  1320. * in HW_AUTO only when the module become ready.
  1321. */
  1322. hwsup = clkdm_in_hwsup(oh->clkdm);
  1323. r = clkdm_hwmod_enable(oh->clkdm, oh);
  1324. if (r) {
  1325. WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
  1326. oh->name, oh->clkdm->name, r);
  1327. return r;
  1328. }
  1329. }
  1330. _enable_clocks(oh);
  1331. _enable_module(oh);
  1332. r = _wait_target_ready(oh);
  1333. if (!r) {
  1334. /*
  1335. * Set the clockdomain to HW_AUTO only if the target is ready,
  1336. * assuming that the previous state was HW_AUTO
  1337. */
  1338. if (oh->clkdm && hwsup)
  1339. clkdm_allow_idle(oh->clkdm);
  1340. oh->_state = _HWMOD_STATE_ENABLED;
  1341. /* Access the sysconfig only if the target is ready */
  1342. if (oh->class->sysc) {
  1343. if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
  1344. _update_sysc_cache(oh);
  1345. _enable_sysc(oh);
  1346. }
  1347. } else {
  1348. _disable_clocks(oh);
  1349. pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n",
  1350. oh->name, r);
  1351. if (oh->clkdm)
  1352. clkdm_hwmod_disable(oh->clkdm, oh);
  1353. }
  1354. return r;
  1355. }
  1356. /**
  1357. * _idle - idle an omap_hwmod
  1358. * @oh: struct omap_hwmod *
  1359. *
  1360. * Idles an omap_hwmod @oh. This should be called once the hwmod has
  1361. * no further work. Returns -EINVAL if the hwmod is in the wrong
  1362. * state or returns 0.
  1363. */
  1364. static int _idle(struct omap_hwmod *oh)
  1365. {
  1366. pr_debug("omap_hwmod: %s: idling\n", oh->name);
  1367. if (oh->_state != _HWMOD_STATE_ENABLED) {
  1368. WARN(1, "omap_hwmod: %s: idle state can only be entered from enabled state\n",
  1369. oh->name);
  1370. return -EINVAL;
  1371. }
  1372. if (oh->class->sysc)
  1373. _idle_sysc(oh);
  1374. _del_initiator_dep(oh, mpu_oh);
  1375. _omap4_disable_module(oh);
  1376. /*
  1377. * The module must be in idle mode before disabling any parents
  1378. * clocks. Otherwise, the parent clock might be disabled before
  1379. * the module transition is done, and thus will prevent the
  1380. * transition to complete properly.
  1381. */
  1382. _disable_clocks(oh);
  1383. if (oh->clkdm)
  1384. clkdm_hwmod_disable(oh->clkdm, oh);
  1385. /* Mux pins for device idle if populated */
  1386. if (oh->mux && oh->mux->pads_dynamic)
  1387. omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
  1388. oh->_state = _HWMOD_STATE_IDLE;
  1389. return 0;
  1390. }
  1391. /**
  1392. * omap_hwmod_set_ocp_autoidle - set the hwmod's OCP autoidle bit
  1393. * @oh: struct omap_hwmod *
  1394. * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
  1395. *
  1396. * Sets the IP block's OCP autoidle bit in hardware, and updates our
  1397. * local copy. Intended to be used by drivers that require
  1398. * direct manipulation of the AUTOIDLE bits.
  1399. * Returns -EINVAL if @oh is null or is not in the ENABLED state, or passes
  1400. * along the return value from _set_module_autoidle().
  1401. *
  1402. * Any users of this function should be scrutinized carefully.
  1403. */
  1404. int omap_hwmod_set_ocp_autoidle(struct omap_hwmod *oh, u8 autoidle)
  1405. {
  1406. u32 v;
  1407. int retval = 0;
  1408. unsigned long flags;
  1409. if (!oh || oh->_state != _HWMOD_STATE_ENABLED)
  1410. return -EINVAL;
  1411. spin_lock_irqsave(&oh->_lock, flags);
  1412. v = oh->_sysc_cache;
  1413. retval = _set_module_autoidle(oh, autoidle, &v);
  1414. if (!retval)
  1415. _write_sysconfig(v, oh);
  1416. spin_unlock_irqrestore(&oh->_lock, flags);
  1417. return retval;
  1418. }
  1419. /**
  1420. * _shutdown - shutdown an omap_hwmod
  1421. * @oh: struct omap_hwmod *
  1422. *
  1423. * Shut down an omap_hwmod @oh. This should be called when the driver
  1424. * used for the hwmod is removed or unloaded or if the driver is not
  1425. * used by the system. Returns -EINVAL if the hwmod is in the wrong
  1426. * state or returns 0.
  1427. */
  1428. static int _shutdown(struct omap_hwmod *oh)
  1429. {
  1430. int ret, i;
  1431. u8 prev_state;
  1432. if (oh->_state != _HWMOD_STATE_IDLE &&
  1433. oh->_state != _HWMOD_STATE_ENABLED) {
  1434. WARN(1, "omap_hwmod: %s: disabled state can only be entered from idle, or enabled state\n",
  1435. oh->name);
  1436. return -EINVAL;
  1437. }
  1438. pr_debug("omap_hwmod: %s: disabling\n", oh->name);
  1439. if (oh->class->pre_shutdown) {
  1440. prev_state = oh->_state;
  1441. if (oh->_state == _HWMOD_STATE_IDLE)
  1442. _enable(oh);
  1443. ret = oh->class->pre_shutdown(oh);
  1444. if (ret) {
  1445. if (prev_state == _HWMOD_STATE_IDLE)
  1446. _idle(oh);
  1447. return ret;
  1448. }
  1449. }
  1450. if (oh->class->sysc) {
  1451. if (oh->_state == _HWMOD_STATE_IDLE)
  1452. _enable(oh);
  1453. _shutdown_sysc(oh);
  1454. }
  1455. /* clocks and deps are already disabled in idle */
  1456. if (oh->_state == _HWMOD_STATE_ENABLED) {
  1457. _del_initiator_dep(oh, mpu_oh);
  1458. /* XXX what about the other system initiators here? dma, dsp */
  1459. _omap4_disable_module(oh);
  1460. _disable_clocks(oh);
  1461. if (oh->clkdm)
  1462. clkdm_hwmod_disable(oh->clkdm, oh);
  1463. }
  1464. /* XXX Should this code also force-disable the optional clocks? */
  1465. for (i = 0; i < oh->rst_lines_cnt; i++)
  1466. _assert_hardreset(oh, oh->rst_lines[i].name);
  1467. /* Mux pins to safe mode or use populated off mode values */
  1468. if (oh->mux)
  1469. omap_hwmod_mux(oh->mux, _HWMOD_STATE_DISABLED);
  1470. oh->_state = _HWMOD_STATE_DISABLED;
  1471. return 0;
  1472. }
  1473. /**
  1474. * _setup - do initial configuration of omap_hwmod
  1475. * @oh: struct omap_hwmod *
  1476. *
  1477. * Writes the CLOCKACTIVITY bits @clockact to the hwmod @oh
  1478. * OCP_SYSCONFIG register. Returns 0.
  1479. */
  1480. static int _setup(struct omap_hwmod *oh, void *data)
  1481. {
  1482. int i, r;
  1483. u8 postsetup_state;
  1484. if (oh->_state != _HWMOD_STATE_CLKS_INITED)
  1485. return 0;
  1486. /* Set iclk autoidle mode */
  1487. if (oh->slaves_cnt > 0) {
  1488. for (i = 0; i < oh->slaves_cnt; i++) {
  1489. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  1490. struct clk *c = os->_clk;
  1491. if (!c)
  1492. continue;
  1493. if (os->flags & OCPIF_SWSUP_IDLE) {
  1494. /* XXX omap_iclk_deny_idle(c); */
  1495. } else {
  1496. /* XXX omap_iclk_allow_idle(c); */
  1497. clk_enable(c);
  1498. }
  1499. }
  1500. }
  1501. oh->_state = _HWMOD_STATE_INITIALIZED;
  1502. /*
  1503. * In the case of hwmod with hardreset that should not be
  1504. * de-assert at boot time, we have to keep the module
  1505. * initialized, because we cannot enable it properly with the
  1506. * reset asserted. Exit without warning because that behavior is
  1507. * expected.
  1508. */
  1509. if ((oh->flags & HWMOD_INIT_NO_RESET) && oh->rst_lines_cnt > 0)
  1510. return 0;
  1511. r = _enable(oh);
  1512. if (r) {
  1513. pr_warning("omap_hwmod: %s: cannot be enabled (%d)\n",
  1514. oh->name, oh->_state);
  1515. return 0;
  1516. }
  1517. if (!(oh->flags & HWMOD_INIT_NO_RESET))
  1518. _reset(oh);
  1519. postsetup_state = oh->_postsetup_state;
  1520. if (postsetup_state == _HWMOD_STATE_UNKNOWN)
  1521. postsetup_state = _HWMOD_STATE_ENABLED;
  1522. /*
  1523. * XXX HWMOD_INIT_NO_IDLE does not belong in hwmod data -
  1524. * it should be set by the core code as a runtime flag during startup
  1525. */
  1526. if ((oh->flags & HWMOD_INIT_NO_IDLE) &&
  1527. (postsetup_state == _HWMOD_STATE_IDLE)) {
  1528. oh->_int_flags |= _HWMOD_SKIP_ENABLE;
  1529. postsetup_state = _HWMOD_STATE_ENABLED;
  1530. }
  1531. if (postsetup_state == _HWMOD_STATE_IDLE)
  1532. _idle(oh);
  1533. else if (postsetup_state == _HWMOD_STATE_DISABLED)
  1534. _shutdown(oh);
  1535. else if (postsetup_state != _HWMOD_STATE_ENABLED)
  1536. WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
  1537. oh->name, postsetup_state);
  1538. return 0;
  1539. }
  1540. /**
  1541. * _register - register a struct omap_hwmod
  1542. * @oh: struct omap_hwmod *
  1543. *
  1544. * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod
  1545. * already has been registered by the same name; -EINVAL if the
  1546. * omap_hwmod is in the wrong state, if @oh is NULL, if the
  1547. * omap_hwmod's class field is NULL; if the omap_hwmod is missing a
  1548. * name, or if the omap_hwmod's class is missing a name; or 0 upon
  1549. * success.
  1550. *
  1551. * XXX The data should be copied into bootmem, so the original data
  1552. * should be marked __initdata and freed after init. This would allow
  1553. * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note
  1554. * that the copy process would be relatively complex due to the large number
  1555. * of substructures.
  1556. */
  1557. static int __init _register(struct omap_hwmod *oh)
  1558. {
  1559. int ms_id;
  1560. if (!oh || !oh->name || !oh->class || !oh->class->name ||
  1561. (oh->_state != _HWMOD_STATE_UNKNOWN))
  1562. return -EINVAL;
  1563. pr_debug("omap_hwmod: %s: registering\n", oh->name);
  1564. if (_lookup(oh->name))
  1565. return -EEXIST;
  1566. ms_id = _find_mpu_port_index(oh);
  1567. if (!IS_ERR_VALUE(ms_id))
  1568. oh->_mpu_port_index = ms_id;
  1569. else
  1570. oh->_int_flags |= _HWMOD_NO_MPU_PORT;
  1571. list_add_tail(&oh->node, &omap_hwmod_list);
  1572. spin_lock_init(&oh->_lock);
  1573. oh->_state = _HWMOD_STATE_REGISTERED;
  1574. /*
  1575. * XXX Rather than doing a strcmp(), this should test a flag
  1576. * set in the hwmod data, inserted by the autogenerator code.
  1577. */
  1578. if (!strcmp(oh->name, MPU_INITIATOR_NAME))
  1579. mpu_oh = oh;
  1580. return 0;
  1581. }
  1582. /* Public functions */
  1583. u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs)
  1584. {
  1585. if (oh->flags & HWMOD_16BIT_REG)
  1586. return __raw_readw(oh->_mpu_rt_va + reg_offs);
  1587. else
  1588. return __raw_readl(oh->_mpu_rt_va + reg_offs);
  1589. }
  1590. void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs)
  1591. {
  1592. if (oh->flags & HWMOD_16BIT_REG)
  1593. __raw_writew(v, oh->_mpu_rt_va + reg_offs);
  1594. else
  1595. __raw_writel(v, oh->_mpu_rt_va + reg_offs);
  1596. }
  1597. /**
  1598. * omap_hwmod_softreset - reset a module via SYSCONFIG.SOFTRESET bit
  1599. * @oh: struct omap_hwmod *
  1600. *
  1601. * This is a public function exposed to drivers. Some drivers may need to do
  1602. * some settings before and after resetting the device. Those drivers after
  1603. * doing the necessary settings could use this function to start a reset by
  1604. * setting the SYSCONFIG.SOFTRESET bit.
  1605. */
  1606. int omap_hwmod_softreset(struct omap_hwmod *oh)
  1607. {
  1608. u32 v;
  1609. int ret;
  1610. if (!oh || !(oh->_sysc_cache))
  1611. return -EINVAL;
  1612. v = oh->_sysc_cache;
  1613. ret = _set_softreset(oh, &v);
  1614. if (ret)
  1615. goto error;
  1616. _write_sysconfig(v, oh);
  1617. error:
  1618. return ret;
  1619. }
  1620. /**
  1621. * omap_hwmod_set_slave_idlemode - set the hwmod's OCP slave idlemode
  1622. * @oh: struct omap_hwmod *
  1623. * @idlemode: SIDLEMODE field bits (shifted to bit 0)
  1624. *
  1625. * Sets the IP block's OCP slave idlemode in hardware, and updates our
  1626. * local copy. Intended to be used by drivers that have some erratum
  1627. * that requires direct manipulation of the SIDLEMODE bits. Returns
  1628. * -EINVAL if @oh is null, or passes along the return value from
  1629. * _set_slave_idlemode().
  1630. *
  1631. * XXX Does this function have any current users? If not, we should
  1632. * remove it; it is better to let the rest of the hwmod code handle this.
  1633. * Any users of this function should be scrutinized carefully.
  1634. */
  1635. int omap_hwmod_set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode)
  1636. {
  1637. u32 v;
  1638. int retval = 0;
  1639. if (!oh)
  1640. return -EINVAL;
  1641. v = oh->_sysc_cache;
  1642. retval = _set_slave_idlemode(oh, idlemode, &v);
  1643. if (!retval)
  1644. _write_sysconfig(v, oh);
  1645. return retval;
  1646. }
  1647. /**
  1648. * omap_hwmod_lookup - look up a registered omap_hwmod by name
  1649. * @name: name of the omap_hwmod to look up
  1650. *
  1651. * Given a @name of an omap_hwmod, return a pointer to the registered
  1652. * struct omap_hwmod *, or NULL upon error.
  1653. */
  1654. struct omap_hwmod *omap_hwmod_lookup(const char *name)
  1655. {
  1656. struct omap_hwmod *oh;
  1657. if (!name)
  1658. return NULL;
  1659. oh = _lookup(name);
  1660. return oh;
  1661. }
  1662. /**
  1663. * omap_hwmod_for_each - call function for each registered omap_hwmod
  1664. * @fn: pointer to a callback function
  1665. * @data: void * data to pass to callback function
  1666. *
  1667. * Call @fn for each registered omap_hwmod, passing @data to each
  1668. * function. @fn must return 0 for success or any other value for
  1669. * failure. If @fn returns non-zero, the iteration across omap_hwmods
  1670. * will stop and the non-zero return value will be passed to the
  1671. * caller of omap_hwmod_for_each(). @fn is called with
  1672. * omap_hwmod_for_each() held.
  1673. */
  1674. int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
  1675. void *data)
  1676. {
  1677. struct omap_hwmod *temp_oh;
  1678. int ret = 0;
  1679. if (!fn)
  1680. return -EINVAL;
  1681. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  1682. ret = (*fn)(temp_oh, data);
  1683. if (ret)
  1684. break;
  1685. }
  1686. return ret;
  1687. }
  1688. /**
  1689. * omap_hwmod_register - register an array of hwmods
  1690. * @ohs: pointer to an array of omap_hwmods to register
  1691. *
  1692. * Intended to be called early in boot before the clock framework is
  1693. * initialized. If @ohs is not null, will register all omap_hwmods
  1694. * listed in @ohs that are valid for this chip. Returns 0.
  1695. */
  1696. int __init omap_hwmod_register(struct omap_hwmod **ohs)
  1697. {
  1698. int r, i;
  1699. if (!ohs)
  1700. return 0;
  1701. i = 0;
  1702. do {
  1703. r = _register(ohs[i]);
  1704. WARN(r, "omap_hwmod: %s: _register returned %d\n", ohs[i]->name,
  1705. r);
  1706. } while (ohs[++i]);
  1707. return 0;
  1708. }
  1709. /*
  1710. * _populate_mpu_rt_base - populate the virtual address for a hwmod
  1711. *
  1712. * Must be called only from omap_hwmod_setup_*() so ioremap works properly.
  1713. * Assumes the caller takes care of locking if needed.
  1714. */
  1715. static int __init _populate_mpu_rt_base(struct omap_hwmod *oh, void *data)
  1716. {
  1717. if (oh->_state != _HWMOD_STATE_REGISTERED)
  1718. return 0;
  1719. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  1720. return 0;
  1721. oh->_mpu_rt_va = _find_mpu_rt_base(oh, oh->_mpu_port_index);
  1722. return 0;
  1723. }
  1724. /**
  1725. * omap_hwmod_setup_one - set up a single hwmod
  1726. * @oh_name: const char * name of the already-registered hwmod to set up
  1727. *
  1728. * Must be called after omap2_clk_init(). Resolves the struct clk
  1729. * names to struct clk pointers for each registered omap_hwmod. Also
  1730. * calls _setup() on each hwmod. Returns -EINVAL upon error or 0 upon
  1731. * success.
  1732. */
  1733. int __init omap_hwmod_setup_one(const char *oh_name)
  1734. {
  1735. struct omap_hwmod *oh;
  1736. int r;
  1737. pr_debug("omap_hwmod: %s: %s\n", oh_name, __func__);
  1738. if (!mpu_oh) {
  1739. pr_err("omap_hwmod: %s: cannot setup_one: MPU initiator hwmod %s not yet registered\n",
  1740. oh_name, MPU_INITIATOR_NAME);
  1741. return -EINVAL;
  1742. }
  1743. oh = _lookup(oh_name);
  1744. if (!oh) {
  1745. WARN(1, "omap_hwmod: %s: hwmod not yet registered\n", oh_name);
  1746. return -EINVAL;
  1747. }
  1748. if (mpu_oh->_state == _HWMOD_STATE_REGISTERED && oh != mpu_oh)
  1749. omap_hwmod_setup_one(MPU_INITIATOR_NAME);
  1750. r = _populate_mpu_rt_base(oh, NULL);
  1751. if (IS_ERR_VALUE(r)) {
  1752. WARN(1, "omap_hwmod: %s: couldn't set mpu_rt_base\n", oh_name);
  1753. return -EINVAL;
  1754. }
  1755. r = _init_clocks(oh, NULL);
  1756. if (IS_ERR_VALUE(r)) {
  1757. WARN(1, "omap_hwmod: %s: couldn't init clocks\n", oh_name);
  1758. return -EINVAL;
  1759. }
  1760. _setup(oh, NULL);
  1761. return 0;
  1762. }
  1763. /**
  1764. * omap_hwmod_setup - do some post-clock framework initialization
  1765. *
  1766. * Must be called after omap2_clk_init(). Resolves the struct clk names
  1767. * to struct clk pointers for each registered omap_hwmod. Also calls
  1768. * _setup() on each hwmod. Returns 0 upon success.
  1769. */
  1770. static int __init omap_hwmod_setup_all(void)
  1771. {
  1772. int r;
  1773. if (!mpu_oh) {
  1774. pr_err("omap_hwmod: %s: MPU initiator hwmod %s not yet registered\n",
  1775. __func__, MPU_INITIATOR_NAME);
  1776. return -EINVAL;
  1777. }
  1778. r = omap_hwmod_for_each(_populate_mpu_rt_base, NULL);
  1779. r = omap_hwmod_for_each(_init_clocks, NULL);
  1780. WARN(IS_ERR_VALUE(r),
  1781. "omap_hwmod: %s: _init_clocks failed\n", __func__);
  1782. omap_hwmod_for_each(_setup, NULL);
  1783. return 0;
  1784. }
  1785. core_initcall(omap_hwmod_setup_all);
  1786. /**
  1787. * omap_hwmod_enable - enable an omap_hwmod
  1788. * @oh: struct omap_hwmod *
  1789. *
  1790. * Enable an omap_hwmod @oh. Intended to be called by omap_device_enable().
  1791. * Returns -EINVAL on error or passes along the return value from _enable().
  1792. */
  1793. int omap_hwmod_enable(struct omap_hwmod *oh)
  1794. {
  1795. int r;
  1796. unsigned long flags;
  1797. if (!oh)
  1798. return -EINVAL;
  1799. spin_lock_irqsave(&oh->_lock, flags);
  1800. r = _enable(oh);
  1801. spin_unlock_irqrestore(&oh->_lock, flags);
  1802. return r;
  1803. }
  1804. /**
  1805. * omap_hwmod_idle - idle an omap_hwmod
  1806. * @oh: struct omap_hwmod *
  1807. *
  1808. * Idle an omap_hwmod @oh. Intended to be called by omap_device_idle().
  1809. * Returns -EINVAL on error or passes along the return value from _idle().
  1810. */
  1811. int omap_hwmod_idle(struct omap_hwmod *oh)
  1812. {
  1813. unsigned long flags;
  1814. if (!oh)
  1815. return -EINVAL;
  1816. spin_lock_irqsave(&oh->_lock, flags);
  1817. _idle(oh);
  1818. spin_unlock_irqrestore(&oh->_lock, flags);
  1819. return 0;
  1820. }
  1821. /**
  1822. * omap_hwmod_shutdown - shutdown an omap_hwmod
  1823. * @oh: struct omap_hwmod *
  1824. *
  1825. * Shutdown an omap_hwmod @oh. Intended to be called by
  1826. * omap_device_shutdown(). Returns -EINVAL on error or passes along
  1827. * the return value from _shutdown().
  1828. */
  1829. int omap_hwmod_shutdown(struct omap_hwmod *oh)
  1830. {
  1831. unsigned long flags;
  1832. if (!oh)
  1833. return -EINVAL;
  1834. spin_lock_irqsave(&oh->_lock, flags);
  1835. _shutdown(oh);
  1836. spin_unlock_irqrestore(&oh->_lock, flags);
  1837. return 0;
  1838. }
  1839. /**
  1840. * omap_hwmod_enable_clocks - enable main_clk, all interface clocks
  1841. * @oh: struct omap_hwmod *oh
  1842. *
  1843. * Intended to be called by the omap_device code.
  1844. */
  1845. int omap_hwmod_enable_clocks(struct omap_hwmod *oh)
  1846. {
  1847. unsigned long flags;
  1848. spin_lock_irqsave(&oh->_lock, flags);
  1849. _enable_clocks(oh);
  1850. spin_unlock_irqrestore(&oh->_lock, flags);
  1851. return 0;
  1852. }
  1853. /**
  1854. * omap_hwmod_disable_clocks - disable main_clk, all interface clocks
  1855. * @oh: struct omap_hwmod *oh
  1856. *
  1857. * Intended to be called by the omap_device code.
  1858. */
  1859. int omap_hwmod_disable_clocks(struct omap_hwmod *oh)
  1860. {
  1861. unsigned long flags;
  1862. spin_lock_irqsave(&oh->_lock, flags);
  1863. _disable_clocks(oh);
  1864. spin_unlock_irqrestore(&oh->_lock, flags);
  1865. return 0;
  1866. }
  1867. /**
  1868. * omap_hwmod_ocp_barrier - wait for posted writes against the hwmod to complete
  1869. * @oh: struct omap_hwmod *oh
  1870. *
  1871. * Intended to be called by drivers and core code when all posted
  1872. * writes to a device must complete before continuing further
  1873. * execution (for example, after clearing some device IRQSTATUS
  1874. * register bits)
  1875. *
  1876. * XXX what about targets with multiple OCP threads?
  1877. */
  1878. void omap_hwmod_ocp_barrier(struct omap_hwmod *oh)
  1879. {
  1880. BUG_ON(!oh);
  1881. if (!oh->class->sysc || !oh->class->sysc->sysc_flags) {
  1882. WARN(1, "omap_device: %s: OCP barrier impossible due to device configuration\n",
  1883. oh->name);
  1884. return;
  1885. }
  1886. /*
  1887. * Forces posted writes to complete on the OCP thread handling
  1888. * register writes
  1889. */
  1890. omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
  1891. }
  1892. /**
  1893. * omap_hwmod_reset - reset the hwmod
  1894. * @oh: struct omap_hwmod *
  1895. *
  1896. * Under some conditions, a driver may wish to reset the entire device.
  1897. * Called from omap_device code. Returns -EINVAL on error or passes along
  1898. * the return value from _reset().
  1899. */
  1900. int omap_hwmod_reset(struct omap_hwmod *oh)
  1901. {
  1902. int r;
  1903. unsigned long flags;
  1904. if (!oh)
  1905. return -EINVAL;
  1906. spin_lock_irqsave(&oh->_lock, flags);
  1907. r = _reset(oh);
  1908. spin_unlock_irqrestore(&oh->_lock, flags);
  1909. return r;
  1910. }
  1911. /**
  1912. * omap_hwmod_count_resources - count number of struct resources needed by hwmod
  1913. * @oh: struct omap_hwmod *
  1914. * @res: pointer to the first element of an array of struct resource to fill
  1915. *
  1916. * Count the number of struct resource array elements necessary to
  1917. * contain omap_hwmod @oh resources. Intended to be called by code
  1918. * that registers omap_devices. Intended to be used to determine the
  1919. * size of a dynamically-allocated struct resource array, before
  1920. * calling omap_hwmod_fill_resources(). Returns the number of struct
  1921. * resource array elements needed.
  1922. *
  1923. * XXX This code is not optimized. It could attempt to merge adjacent
  1924. * resource IDs.
  1925. *
  1926. */
  1927. int omap_hwmod_count_resources(struct omap_hwmod *oh)
  1928. {
  1929. int ret, i;
  1930. ret = _count_mpu_irqs(oh) + _count_sdma_reqs(oh);
  1931. for (i = 0; i < oh->slaves_cnt; i++)
  1932. ret += _count_ocp_if_addr_spaces(oh->slaves[i]);
  1933. return ret;
  1934. }
  1935. /**
  1936. * omap_hwmod_fill_resources - fill struct resource array with hwmod data
  1937. * @oh: struct omap_hwmod *
  1938. * @res: pointer to the first element of an array of struct resource to fill
  1939. *
  1940. * Fill the struct resource array @res with resource data from the
  1941. * omap_hwmod @oh. Intended to be called by code that registers
  1942. * omap_devices. See also omap_hwmod_count_resources(). Returns the
  1943. * number of array elements filled.
  1944. */
  1945. int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
  1946. {
  1947. int i, j, mpu_irqs_cnt, sdma_reqs_cnt;
  1948. int r = 0;
  1949. /* For each IRQ, DMA, memory area, fill in array.*/
  1950. mpu_irqs_cnt = _count_mpu_irqs(oh);
  1951. for (i = 0; i < mpu_irqs_cnt; i++) {
  1952. (res + r)->name = (oh->mpu_irqs + i)->name;
  1953. (res + r)->start = (oh->mpu_irqs + i)->irq;
  1954. (res + r)->end = (oh->mpu_irqs + i)->irq;
  1955. (res + r)->flags = IORESOURCE_IRQ;
  1956. r++;
  1957. }
  1958. sdma_reqs_cnt = _count_sdma_reqs(oh);
  1959. for (i = 0; i < sdma_reqs_cnt; i++) {
  1960. (res + r)->name = (oh->sdma_reqs + i)->name;
  1961. (res + r)->start = (oh->sdma_reqs + i)->dma_req;
  1962. (res + r)->end = (oh->sdma_reqs + i)->dma_req;
  1963. (res + r)->flags = IORESOURCE_DMA;
  1964. r++;
  1965. }
  1966. for (i = 0; i < oh->slaves_cnt; i++) {
  1967. struct omap_hwmod_ocp_if *os;
  1968. int addr_cnt;
  1969. os = oh->slaves[i];
  1970. addr_cnt = _count_ocp_if_addr_spaces(os);
  1971. for (j = 0; j < addr_cnt; j++) {
  1972. (res + r)->name = (os->addr + j)->name;
  1973. (res + r)->start = (os->addr + j)->pa_start;
  1974. (res + r)->end = (os->addr + j)->pa_end;
  1975. (res + r)->flags = IORESOURCE_MEM;
  1976. r++;
  1977. }
  1978. }
  1979. return r;
  1980. }
  1981. /**
  1982. * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
  1983. * @oh: struct omap_hwmod *
  1984. *
  1985. * Return the powerdomain pointer associated with the OMAP module
  1986. * @oh's main clock. If @oh does not have a main clk, return the
  1987. * powerdomain associated with the interface clock associated with the
  1988. * module's MPU port. (XXX Perhaps this should use the SDMA port
  1989. * instead?) Returns NULL on error, or a struct powerdomain * on
  1990. * success.
  1991. */
  1992. struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
  1993. {
  1994. struct clk *c;
  1995. if (!oh)
  1996. return NULL;
  1997. if (oh->_clk) {
  1998. c = oh->_clk;
  1999. } else {
  2000. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  2001. return NULL;
  2002. c = oh->slaves[oh->_mpu_port_index]->_clk;
  2003. }
  2004. if (!c->clkdm)
  2005. return NULL;
  2006. return c->clkdm->pwrdm.ptr;
  2007. }
  2008. /**
  2009. * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU)
  2010. * @oh: struct omap_hwmod *
  2011. *
  2012. * Returns the virtual address corresponding to the beginning of the
  2013. * module's register target, in the address range that is intended to
  2014. * be used by the MPU. Returns the virtual address upon success or NULL
  2015. * upon error.
  2016. */
  2017. void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh)
  2018. {
  2019. if (!oh)
  2020. return NULL;
  2021. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  2022. return NULL;
  2023. if (oh->_state == _HWMOD_STATE_UNKNOWN)
  2024. return NULL;
  2025. return oh->_mpu_rt_va;
  2026. }
  2027. /**
  2028. * omap_hwmod_add_initiator_dep - add sleepdep from @init_oh to @oh
  2029. * @oh: struct omap_hwmod *
  2030. * @init_oh: struct omap_hwmod * (initiator)
  2031. *
  2032. * Add a sleep dependency between the initiator @init_oh and @oh.
  2033. * Intended to be called by DSP/Bridge code via platform_data for the
  2034. * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
  2035. * code needs to add/del initiator dependencies dynamically
  2036. * before/after accessing a device. Returns the return value from
  2037. * _add_initiator_dep().
  2038. *
  2039. * XXX Keep a usecount in the clockdomain code
  2040. */
  2041. int omap_hwmod_add_initiator_dep(struct omap_hwmod *oh,
  2042. struct omap_hwmod *init_oh)
  2043. {
  2044. return _add_initiator_dep(oh, init_oh);
  2045. }
  2046. /*
  2047. * XXX what about functions for drivers to save/restore ocp_sysconfig
  2048. * for context save/restore operations?
  2049. */
  2050. /**
  2051. * omap_hwmod_del_initiator_dep - remove sleepdep from @init_oh to @oh
  2052. * @oh: struct omap_hwmod *
  2053. * @init_oh: struct omap_hwmod * (initiator)
  2054. *
  2055. * Remove a sleep dependency between the initiator @init_oh and @oh.
  2056. * Intended to be called by DSP/Bridge code via platform_data for the
  2057. * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
  2058. * code needs to add/del initiator dependencies dynamically
  2059. * before/after accessing a device. Returns the return value from
  2060. * _del_initiator_dep().
  2061. *
  2062. * XXX Keep a usecount in the clockdomain code
  2063. */
  2064. int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh,
  2065. struct omap_hwmod *init_oh)
  2066. {
  2067. return _del_initiator_dep(oh, init_oh);
  2068. }
  2069. /**
  2070. * omap_hwmod_enable_wakeup - allow device to wake up the system
  2071. * @oh: struct omap_hwmod *
  2072. *
  2073. * Sets the module OCP socket ENAWAKEUP bit to allow the module to
  2074. * send wakeups to the PRCM, and enable I/O ring wakeup events for
  2075. * this IP block if it has dynamic mux entries. Eventually this
  2076. * should set PRCM wakeup registers to cause the PRCM to receive
  2077. * wakeup events from the module. Does not set any wakeup routing
  2078. * registers beyond this point - if the module is to wake up any other
  2079. * module or subsystem, that must be set separately. Called by
  2080. * omap_device code. Returns -EINVAL on error or 0 upon success.
  2081. */
  2082. int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
  2083. {
  2084. unsigned long flags;
  2085. u32 v;
  2086. spin_lock_irqsave(&oh->_lock, flags);
  2087. if (oh->class->sysc &&
  2088. (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
  2089. v = oh->_sysc_cache;
  2090. _enable_wakeup(oh, &v);
  2091. _write_sysconfig(v, oh);
  2092. }
  2093. _set_idle_ioring_wakeup(oh, true);
  2094. spin_unlock_irqrestore(&oh->_lock, flags);
  2095. return 0;
  2096. }
  2097. /**
  2098. * omap_hwmod_disable_wakeup - prevent device from waking the system
  2099. * @oh: struct omap_hwmod *
  2100. *
  2101. * Clears the module OCP socket ENAWAKEUP bit to prevent the module
  2102. * from sending wakeups to the PRCM, and disable I/O ring wakeup
  2103. * events for this IP block if it has dynamic mux entries. Eventually
  2104. * this should clear PRCM wakeup registers to cause the PRCM to ignore
  2105. * wakeup events from the module. Does not set any wakeup routing
  2106. * registers beyond this point - if the module is to wake up any other
  2107. * module or subsystem, that must be set separately. Called by
  2108. * omap_device code. Returns -EINVAL on error or 0 upon success.
  2109. */
  2110. int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
  2111. {
  2112. unsigned long flags;
  2113. u32 v;
  2114. spin_lock_irqsave(&oh->_lock, flags);
  2115. if (oh->class->sysc &&
  2116. (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
  2117. v = oh->_sysc_cache;
  2118. _disable_wakeup(oh, &v);
  2119. _write_sysconfig(v, oh);
  2120. }
  2121. _set_idle_ioring_wakeup(oh, false);
  2122. spin_unlock_irqrestore(&oh->_lock, flags);
  2123. return 0;
  2124. }
  2125. /**
  2126. * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
  2127. * contained in the hwmod module.
  2128. * @oh: struct omap_hwmod *
  2129. * @name: name of the reset line to lookup and assert
  2130. *
  2131. * Some IP like dsp, ipu or iva contain processor that require
  2132. * an HW reset line to be assert / deassert in order to enable fully
  2133. * the IP. Returns -EINVAL if @oh is null or if the operation is not
  2134. * yet supported on this OMAP; otherwise, passes along the return value
  2135. * from _assert_hardreset().
  2136. */
  2137. int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
  2138. {
  2139. int ret;
  2140. unsigned long flags;
  2141. if (!oh)
  2142. return -EINVAL;
  2143. spin_lock_irqsave(&oh->_lock, flags);
  2144. ret = _assert_hardreset(oh, name);
  2145. spin_unlock_irqrestore(&oh->_lock, flags);
  2146. return ret;
  2147. }
  2148. /**
  2149. * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
  2150. * contained in the hwmod module.
  2151. * @oh: struct omap_hwmod *
  2152. * @name: name of the reset line to look up and deassert
  2153. *
  2154. * Some IP like dsp, ipu or iva contain processor that require
  2155. * an HW reset line to be assert / deassert in order to enable fully
  2156. * the IP. Returns -EINVAL if @oh is null or if the operation is not
  2157. * yet supported on this OMAP; otherwise, passes along the return value
  2158. * from _deassert_hardreset().
  2159. */
  2160. int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
  2161. {
  2162. int ret;
  2163. unsigned long flags;
  2164. if (!oh)
  2165. return -EINVAL;
  2166. spin_lock_irqsave(&oh->_lock, flags);
  2167. ret = _deassert_hardreset(oh, name);
  2168. spin_unlock_irqrestore(&oh->_lock, flags);
  2169. return ret;
  2170. }
  2171. /**
  2172. * omap_hwmod_read_hardreset - read the HW reset line state of submodules
  2173. * contained in the hwmod module
  2174. * @oh: struct omap_hwmod *
  2175. * @name: name of the reset line to look up and read
  2176. *
  2177. * Return the current state of the hwmod @oh's reset line named @name:
  2178. * returns -EINVAL upon parameter error or if this operation
  2179. * is unsupported on the current OMAP; otherwise, passes along the return
  2180. * value from _read_hardreset().
  2181. */
  2182. int omap_hwmod_read_hardreset(struct omap_hwmod *oh, const char *name)
  2183. {
  2184. int ret;
  2185. unsigned long flags;
  2186. if (!oh)
  2187. return -EINVAL;
  2188. spin_lock_irqsave(&oh->_lock, flags);
  2189. ret = _read_hardreset(oh, name);
  2190. spin_unlock_irqrestore(&oh->_lock, flags);
  2191. return ret;
  2192. }
  2193. /**
  2194. * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
  2195. * @classname: struct omap_hwmod_class name to search for
  2196. * @fn: callback function pointer to call for each hwmod in class @classname
  2197. * @user: arbitrary context data to pass to the callback function
  2198. *
  2199. * For each omap_hwmod of class @classname, call @fn.
  2200. * If the callback function returns something other than
  2201. * zero, the iterator is terminated, and the callback function's return
  2202. * value is passed back to the caller. Returns 0 upon success, -EINVAL
  2203. * if @classname or @fn are NULL, or passes back the error code from @fn.
  2204. */
  2205. int omap_hwmod_for_each_by_class(const char *classname,
  2206. int (*fn)(struct omap_hwmod *oh,
  2207. void *user),
  2208. void *user)
  2209. {
  2210. struct omap_hwmod *temp_oh;
  2211. int ret = 0;
  2212. if (!classname || !fn)
  2213. return -EINVAL;
  2214. pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
  2215. __func__, classname);
  2216. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  2217. if (!strcmp(temp_oh->class->name, classname)) {
  2218. pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
  2219. __func__, temp_oh->name);
  2220. ret = (*fn)(temp_oh, user);
  2221. if (ret)
  2222. break;
  2223. }
  2224. }
  2225. if (ret)
  2226. pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",
  2227. __func__, ret);
  2228. return ret;
  2229. }
  2230. /**
  2231. * omap_hwmod_set_postsetup_state - set the post-_setup() state for this hwmod
  2232. * @oh: struct omap_hwmod *
  2233. * @state: state that _setup() should leave the hwmod in
  2234. *
  2235. * Sets the hwmod state that @oh will enter at the end of _setup()
  2236. * (called by omap_hwmod_setup_*()). Only valid to call between
  2237. * calling omap_hwmod_register() and omap_hwmod_setup_*(). Returns
  2238. * 0 upon success or -EINVAL if there is a problem with the arguments
  2239. * or if the hwmod is in the wrong state.
  2240. */
  2241. int omap_hwmod_set_postsetup_state(struct omap_hwmod *oh, u8 state)
  2242. {
  2243. int ret;
  2244. unsigned long flags;
  2245. if (!oh)
  2246. return -EINVAL;
  2247. if (state != _HWMOD_STATE_DISABLED &&
  2248. state != _HWMOD_STATE_ENABLED &&
  2249. state != _HWMOD_STATE_IDLE)
  2250. return -EINVAL;
  2251. spin_lock_irqsave(&oh->_lock, flags);
  2252. if (oh->_state != _HWMOD_STATE_REGISTERED) {
  2253. ret = -EINVAL;
  2254. goto ohsps_unlock;
  2255. }
  2256. oh->_postsetup_state = state;
  2257. ret = 0;
  2258. ohsps_unlock:
  2259. spin_unlock_irqrestore(&oh->_lock, flags);
  2260. return ret;
  2261. }
  2262. /**
  2263. * omap_hwmod_get_context_loss_count - get lost context count
  2264. * @oh: struct omap_hwmod *
  2265. *
  2266. * Query the powerdomain of of @oh to get the context loss
  2267. * count for this device.
  2268. *
  2269. * Returns the context loss count of the powerdomain assocated with @oh
  2270. * upon success, or zero if no powerdomain exists for @oh.
  2271. */
  2272. int omap_hwmod_get_context_loss_count(struct omap_hwmod *oh)
  2273. {
  2274. struct powerdomain *pwrdm;
  2275. int ret = 0;
  2276. pwrdm = omap_hwmod_get_pwrdm(oh);
  2277. if (pwrdm)
  2278. ret = pwrdm_get_context_loss_count(pwrdm);
  2279. return ret;
  2280. }
  2281. /**
  2282. * omap_hwmod_no_setup_reset - prevent a hwmod from being reset upon setup
  2283. * @oh: struct omap_hwmod *
  2284. *
  2285. * Prevent the hwmod @oh from being reset during the setup process.
  2286. * Intended for use by board-*.c files on boards with devices that
  2287. * cannot tolerate being reset. Must be called before the hwmod has
  2288. * been set up. Returns 0 upon success or negative error code upon
  2289. * failure.
  2290. */
  2291. int omap_hwmod_no_setup_reset(struct omap_hwmod *oh)
  2292. {
  2293. if (!oh)
  2294. return -EINVAL;
  2295. if (oh->_state != _HWMOD_STATE_REGISTERED) {
  2296. pr_err("omap_hwmod: %s: cannot prevent setup reset; in wrong state\n",
  2297. oh->name);
  2298. return -EINVAL;
  2299. }
  2300. oh->flags |= HWMOD_INIT_NO_RESET;
  2301. return 0;
  2302. }
  2303. /**
  2304. * omap_hwmod_pad_route_irq - route an I/O pad wakeup to a particular MPU IRQ
  2305. * @oh: struct omap_hwmod * containing hwmod mux entries
  2306. * @pad_idx: array index in oh->mux of the hwmod mux entry to route wakeup
  2307. * @irq_idx: the hwmod mpu_irqs array index of the IRQ to trigger on wakeup
  2308. *
  2309. * When an I/O pad wakeup arrives for the dynamic or wakeup hwmod mux
  2310. * entry number @pad_idx for the hwmod @oh, trigger the interrupt
  2311. * service routine for the hwmod's mpu_irqs array index @irq_idx. If
  2312. * this function is not called for a given pad_idx, then the ISR
  2313. * associated with @oh's first MPU IRQ will be triggered when an I/O
  2314. * pad wakeup occurs on that pad. Note that @pad_idx is the index of
  2315. * the _dynamic or wakeup_ entry: if there are other entries not
  2316. * marked with OMAP_DEVICE_PAD_WAKEUP or OMAP_DEVICE_PAD_REMUX, these
  2317. * entries are NOT COUNTED in the dynamic pad index. This function
  2318. * must be called separately for each pad that requires its interrupt
  2319. * to be re-routed this way. Returns -EINVAL if there is an argument
  2320. * problem or if @oh does not have hwmod mux entries or MPU IRQs;
  2321. * returns -ENOMEM if memory cannot be allocated; or 0 upon success.
  2322. *
  2323. * XXX This function interface is fragile. Rather than using array
  2324. * indexes, which are subject to unpredictable change, it should be
  2325. * using hwmod IRQ names, and some other stable key for the hwmod mux
  2326. * pad records.
  2327. */
  2328. int omap_hwmod_pad_route_irq(struct omap_hwmod *oh, int pad_idx, int irq_idx)
  2329. {
  2330. int nr_irqs;
  2331. might_sleep();
  2332. if (!oh || !oh->mux || !oh->mpu_irqs || pad_idx < 0 ||
  2333. pad_idx >= oh->mux->nr_pads_dynamic)
  2334. return -EINVAL;
  2335. /* Check the number of available mpu_irqs */
  2336. for (nr_irqs = 0; oh->mpu_irqs[nr_irqs].irq >= 0; nr_irqs++)
  2337. ;
  2338. if (irq_idx >= nr_irqs)
  2339. return -EINVAL;
  2340. if (!oh->mux->irqs) {
  2341. /* XXX What frees this? */
  2342. oh->mux->irqs = kzalloc(sizeof(int) * oh->mux->nr_pads_dynamic,
  2343. GFP_KERNEL);
  2344. if (!oh->mux->irqs)
  2345. return -ENOMEM;
  2346. }
  2347. oh->mux->irqs[pad_idx] = irq_idx;
  2348. return 0;
  2349. }