omap_hwmod.c 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205
  1. /*
  2. * omap_hwmod implementation for OMAP2/3/4
  3. *
  4. * Copyright (C) 2009-2011 Nokia Corporation
  5. * Copyright (C) 2011-2012 Texas Instruments, Inc.
  6. *
  7. * Paul Walmsley, Benoît Cousson, Kevin Hilman
  8. *
  9. * Created in collaboration with (alphabetical order): Thara Gopinath,
  10. * Tony Lindgren, Rajendra Nayak, Vikram Pandita, Sakari Poussa, Anand
  11. * Sawant, Santosh Shilimkar, Richard Woodruff
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. *
  17. * Introduction
  18. * ------------
  19. * One way to view an OMAP SoC is as a collection of largely unrelated
  20. * IP blocks connected by interconnects. The IP blocks include
  21. * devices such as ARM processors, audio serial interfaces, UARTs,
  22. * etc. Some of these devices, like the DSP, are created by TI;
  23. * others, like the SGX, largely originate from external vendors. In
  24. * TI's documentation, on-chip devices are referred to as "OMAP
  25. * modules." Some of these IP blocks are identical across several
  26. * OMAP versions. Others are revised frequently.
  27. *
  28. * These OMAP modules are tied together by various interconnects.
  29. * Most of the address and data flow between modules is via OCP-based
  30. * interconnects such as the L3 and L4 buses; but there are other
  31. * interconnects that distribute the hardware clock tree, handle idle
  32. * and reset signaling, supply power, and connect the modules to
  33. * various pads or balls on the OMAP package.
  34. *
  35. * OMAP hwmod provides a consistent way to describe the on-chip
  36. * hardware blocks and their integration into the rest of the chip.
  37. * This description can be automatically generated from the TI
  38. * hardware database. OMAP hwmod provides a standard, consistent API
  39. * to reset, enable, idle, and disable these hardware blocks. And
  40. * hwmod provides a way for other core code, such as the Linux device
  41. * code or the OMAP power management and address space mapping code,
  42. * to query the hardware database.
  43. *
  44. * Using hwmod
  45. * -----------
  46. * Drivers won't call hwmod functions directly. That is done by the
  47. * omap_device code, and in rare occasions, by custom integration code
  48. * in arch/arm/ *omap*. The omap_device code includes functions to
  49. * build a struct platform_device using omap_hwmod data, and that is
  50. * currently how hwmod data is communicated to drivers and to the
  51. * Linux driver model. Most drivers will call omap_hwmod functions only
  52. * indirectly, via pm_runtime*() functions.
  53. *
  54. * From a layering perspective, here is where the OMAP hwmod code
  55. * fits into the kernel software stack:
  56. *
  57. * +-------------------------------+
  58. * | Device driver code |
  59. * | (e.g., drivers/) |
  60. * +-------------------------------+
  61. * | Linux driver model |
  62. * | (platform_device / |
  63. * | platform_driver data/code) |
  64. * +-------------------------------+
  65. * | OMAP core-driver integration |
  66. * |(arch/arm/mach-omap2/devices.c)|
  67. * +-------------------------------+
  68. * | omap_device code |
  69. * | (../plat-omap/omap_device.c) |
  70. * +-------------------------------+
  71. * ----> | omap_hwmod code/data | <-----
  72. * | (../mach-omap2/omap_hwmod*) |
  73. * +-------------------------------+
  74. * | OMAP clock/PRCM/register fns |
  75. * | (__raw_{read,write}l, clk*) |
  76. * +-------------------------------+
  77. *
  78. * Device drivers should not contain any OMAP-specific code or data in
  79. * them. They should only contain code to operate the IP block that
  80. * the driver is responsible for. This is because these IP blocks can
  81. * also appear in other SoCs, either from TI (such as DaVinci) or from
  82. * other manufacturers; and drivers should be reusable across other
  83. * platforms.
  84. *
  85. * The OMAP hwmod code also will attempt to reset and idle all on-chip
  86. * devices upon boot. The goal here is for the kernel to be
  87. * completely self-reliant and independent from bootloaders. This is
  88. * to ensure a repeatable configuration, both to ensure consistent
  89. * runtime behavior, and to make it easier for others to reproduce
  90. * bugs.
  91. *
  92. * OMAP module activity states
  93. * ---------------------------
  94. * The hwmod code considers modules to be in one of several activity
  95. * states. IP blocks start out in an UNKNOWN state, then once they
  96. * are registered via the hwmod code, proceed to the REGISTERED state.
  97. * Once their clock names are resolved to clock pointers, the module
  98. * enters the CLKS_INITED state; and finally, once the module has been
  99. * reset and the integration registers programmed, the INITIALIZED state
  100. * is entered. The hwmod code will then place the module into either
  101. * the IDLE state to save power, or in the case of a critical system
  102. * module, the ENABLED state.
  103. *
  104. * OMAP core integration code can then call omap_hwmod*() functions
  105. * directly to move the module between the IDLE, ENABLED, and DISABLED
  106. * states, as needed. This is done during both the PM idle loop, and
  107. * in the OMAP core integration code's implementation of the PM runtime
  108. * functions.
  109. *
  110. * References
  111. * ----------
  112. * This is a partial list.
  113. * - OMAP2420 Multimedia Processor Silicon Revision 2.1.1, 2.2 (SWPU064)
  114. * - OMAP2430 Multimedia Device POP Silicon Revision 2.1 (SWPU090)
  115. * - OMAP34xx Multimedia Device Silicon Revision 3.1 (SWPU108)
  116. * - OMAP4430 Multimedia Device Silicon Revision 1.0 (SWPU140)
  117. * - Open Core Protocol Specification 2.2
  118. *
  119. * To do:
  120. * - handle IO mapping
  121. * - bus throughput & module latency measurement code
  122. *
  123. * XXX add tests at the beginning of each function to ensure the hwmod is
  124. * in the appropriate state
  125. * XXX error return values should be checked to ensure that they are
  126. * appropriate
  127. */
  128. #undef DEBUG
  129. #include <linux/kernel.h>
  130. #include <linux/errno.h>
  131. #include <linux/io.h>
  132. #include <linux/clk.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. * _fetch_next_ocp_if - return @i'th OCP interface in an array
  163. * @p: ptr to a ptr to the list_head inside the ocp_if to return (not yet used)
  164. * @old: ptr to an array of struct omap_hwmod_ocp_if records
  165. * @i: pointer to the index into the @old array
  166. *
  167. * Return a pointer to the next struct omap_hwmod_ocp_if record in a
  168. * sequence. Currently returns a struct omap_hwmod_ocp_if record
  169. * corresponding to the element index pointed to by @i in the @old
  170. * array, and increments the index pointed to by @i.
  171. */
  172. static struct omap_hwmod_ocp_if *_fetch_next_ocp_if(struct list_head **p,
  173. struct omap_hwmod_ocp_if **old,
  174. int *i)
  175. {
  176. struct omap_hwmod_ocp_if *oi;
  177. oi = old[*i];
  178. *i = *i + 1;
  179. return oi;
  180. }
  181. /**
  182. * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
  183. * @oh: struct omap_hwmod *
  184. *
  185. * Load the current value of the hwmod OCP_SYSCONFIG register into the
  186. * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no
  187. * OCP_SYSCONFIG register or 0 upon success.
  188. */
  189. static int _update_sysc_cache(struct omap_hwmod *oh)
  190. {
  191. if (!oh->class->sysc) {
  192. WARN(1, "omap_hwmod: %s: cannot read OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
  193. return -EINVAL;
  194. }
  195. /* XXX ensure module interface clock is up */
  196. oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
  197. if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
  198. oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
  199. return 0;
  200. }
  201. /**
  202. * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
  203. * @v: OCP_SYSCONFIG value to write
  204. * @oh: struct omap_hwmod *
  205. *
  206. * Write @v into the module class' OCP_SYSCONFIG register, if it has
  207. * one. No return value.
  208. */
  209. static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
  210. {
  211. if (!oh->class->sysc) {
  212. WARN(1, "omap_hwmod: %s: cannot write OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
  213. return;
  214. }
  215. /* XXX ensure module interface clock is up */
  216. /* Module might have lost context, always update cache and register */
  217. oh->_sysc_cache = v;
  218. omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs);
  219. }
  220. /**
  221. * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v
  222. * @oh: struct omap_hwmod *
  223. * @standbymode: MIDLEMODE field bits
  224. * @v: pointer to register contents to modify
  225. *
  226. * Update the master standby mode bits in @v to be @standbymode for
  227. * the @oh hwmod. Does not write to the hardware. Returns -EINVAL
  228. * upon error or 0 upon success.
  229. */
  230. static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
  231. u32 *v)
  232. {
  233. u32 mstandby_mask;
  234. u8 mstandby_shift;
  235. if (!oh->class->sysc ||
  236. !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE))
  237. return -EINVAL;
  238. if (!oh->class->sysc->sysc_fields) {
  239. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  240. return -EINVAL;
  241. }
  242. mstandby_shift = oh->class->sysc->sysc_fields->midle_shift;
  243. mstandby_mask = (0x3 << mstandby_shift);
  244. *v &= ~mstandby_mask;
  245. *v |= __ffs(standbymode) << mstandby_shift;
  246. return 0;
  247. }
  248. /**
  249. * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
  250. * @oh: struct omap_hwmod *
  251. * @idlemode: SIDLEMODE field bits
  252. * @v: pointer to register contents to modify
  253. *
  254. * Update the slave idle mode bits in @v to be @idlemode for the @oh
  255. * hwmod. Does not write to the hardware. Returns -EINVAL upon error
  256. * or 0 upon success.
  257. */
  258. static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
  259. {
  260. u32 sidle_mask;
  261. u8 sidle_shift;
  262. if (!oh->class->sysc ||
  263. !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE))
  264. return -EINVAL;
  265. if (!oh->class->sysc->sysc_fields) {
  266. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  267. return -EINVAL;
  268. }
  269. sidle_shift = oh->class->sysc->sysc_fields->sidle_shift;
  270. sidle_mask = (0x3 << sidle_shift);
  271. *v &= ~sidle_mask;
  272. *v |= __ffs(idlemode) << sidle_shift;
  273. return 0;
  274. }
  275. /**
  276. * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
  277. * @oh: struct omap_hwmod *
  278. * @clockact: CLOCKACTIVITY field bits
  279. * @v: pointer to register contents to modify
  280. *
  281. * Update the clockactivity mode bits in @v to be @clockact for the
  282. * @oh hwmod. Used for additional powersaving on some modules. Does
  283. * not write to the hardware. Returns -EINVAL upon error or 0 upon
  284. * success.
  285. */
  286. static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
  287. {
  288. u32 clkact_mask;
  289. u8 clkact_shift;
  290. if (!oh->class->sysc ||
  291. !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
  292. return -EINVAL;
  293. if (!oh->class->sysc->sysc_fields) {
  294. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  295. return -EINVAL;
  296. }
  297. clkact_shift = oh->class->sysc->sysc_fields->clkact_shift;
  298. clkact_mask = (0x3 << clkact_shift);
  299. *v &= ~clkact_mask;
  300. *v |= clockact << clkact_shift;
  301. return 0;
  302. }
  303. /**
  304. * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
  305. * @oh: struct omap_hwmod *
  306. * @v: pointer to register contents to modify
  307. *
  308. * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
  309. * error or 0 upon success.
  310. */
  311. static int _set_softreset(struct omap_hwmod *oh, u32 *v)
  312. {
  313. u32 softrst_mask;
  314. if (!oh->class->sysc ||
  315. !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
  316. return -EINVAL;
  317. if (!oh->class->sysc->sysc_fields) {
  318. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  319. return -EINVAL;
  320. }
  321. softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
  322. *v |= softrst_mask;
  323. return 0;
  324. }
  325. /**
  326. * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v
  327. * @oh: struct omap_hwmod *
  328. * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
  329. * @v: pointer to register contents to modify
  330. *
  331. * Update the module autoidle bit in @v to be @autoidle for the @oh
  332. * hwmod. The autoidle bit controls whether the module can gate
  333. * internal clocks automatically when it isn't doing anything; the
  334. * exact function of this bit varies on a per-module basis. This
  335. * function does not write to the hardware. Returns -EINVAL upon
  336. * error or 0 upon success.
  337. */
  338. static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle,
  339. u32 *v)
  340. {
  341. u32 autoidle_mask;
  342. u8 autoidle_shift;
  343. if (!oh->class->sysc ||
  344. !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE))
  345. return -EINVAL;
  346. if (!oh->class->sysc->sysc_fields) {
  347. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  348. return -EINVAL;
  349. }
  350. autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift;
  351. autoidle_mask = (0x1 << autoidle_shift);
  352. *v &= ~autoidle_mask;
  353. *v |= autoidle << autoidle_shift;
  354. return 0;
  355. }
  356. /**
  357. * _set_idle_ioring_wakeup - enable/disable IO pad wakeup on hwmod idle for mux
  358. * @oh: struct omap_hwmod *
  359. * @set_wake: bool value indicating to set (true) or clear (false) wakeup enable
  360. *
  361. * Set or clear the I/O pad wakeup flag in the mux entries for the
  362. * hwmod @oh. This function changes the @oh->mux->pads_dynamic array
  363. * in memory. If the hwmod is currently idled, and the new idle
  364. * values don't match the previous ones, this function will also
  365. * update the SCM PADCTRL registers. Otherwise, if the hwmod is not
  366. * currently idled, this function won't touch the hardware: the new
  367. * mux settings are written to the SCM PADCTRL registers when the
  368. * hwmod is idled. No return value.
  369. */
  370. static void _set_idle_ioring_wakeup(struct omap_hwmod *oh, bool set_wake)
  371. {
  372. struct omap_device_pad *pad;
  373. bool change = false;
  374. u16 prev_idle;
  375. int j;
  376. if (!oh->mux || !oh->mux->enabled)
  377. return;
  378. for (j = 0; j < oh->mux->nr_pads_dynamic; j++) {
  379. pad = oh->mux->pads_dynamic[j];
  380. if (!(pad->flags & OMAP_DEVICE_PAD_WAKEUP))
  381. continue;
  382. prev_idle = pad->idle;
  383. if (set_wake)
  384. pad->idle |= OMAP_WAKEUP_EN;
  385. else
  386. pad->idle &= ~OMAP_WAKEUP_EN;
  387. if (prev_idle != pad->idle)
  388. change = true;
  389. }
  390. if (change && oh->_state == _HWMOD_STATE_IDLE)
  391. omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
  392. }
  393. /**
  394. * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
  395. * @oh: struct omap_hwmod *
  396. *
  397. * Allow the hardware module @oh to send wakeups. Returns -EINVAL
  398. * upon error or 0 upon success.
  399. */
  400. static int _enable_wakeup(struct omap_hwmod *oh, u32 *v)
  401. {
  402. if (!oh->class->sysc ||
  403. !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
  404. (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
  405. (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
  406. return -EINVAL;
  407. if (!oh->class->sysc->sysc_fields) {
  408. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  409. return -EINVAL;
  410. }
  411. if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
  412. *v |= 0x1 << oh->class->sysc->sysc_fields->enwkup_shift;
  413. if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
  414. _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
  415. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  416. _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
  417. /* XXX test pwrdm_get_wken for this hwmod's subsystem */
  418. oh->_int_flags |= _HWMOD_WAKEUP_ENABLED;
  419. return 0;
  420. }
  421. /**
  422. * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
  423. * @oh: struct omap_hwmod *
  424. *
  425. * Prevent the hardware module @oh to send wakeups. Returns -EINVAL
  426. * upon error or 0 upon success.
  427. */
  428. static int _disable_wakeup(struct omap_hwmod *oh, u32 *v)
  429. {
  430. if (!oh->class->sysc ||
  431. !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
  432. (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
  433. (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
  434. return -EINVAL;
  435. if (!oh->class->sysc->sysc_fields) {
  436. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  437. return -EINVAL;
  438. }
  439. if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
  440. *v &= ~(0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
  441. if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
  442. _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v);
  443. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  444. _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
  445. /* XXX test pwrdm_get_wken for this hwmod's subsystem */
  446. oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED;
  447. return 0;
  448. }
  449. /**
  450. * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
  451. * @oh: struct omap_hwmod *
  452. *
  453. * Prevent the hardware module @oh from entering idle while the
  454. * hardare module initiator @init_oh is active. Useful when a module
  455. * will be accessed by a particular initiator (e.g., if a module will
  456. * be accessed by the IVA, there should be a sleepdep between the IVA
  457. * initiator and the module). Only applies to modules in smart-idle
  458. * mode. If the clockdomain is marked as not needing autodeps, return
  459. * 0 without doing anything. Otherwise, returns -EINVAL upon error or
  460. * passes along clkdm_add_sleepdep() value upon success.
  461. */
  462. static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
  463. {
  464. if (!oh->_clk)
  465. return -EINVAL;
  466. if (oh->_clk->clkdm && oh->_clk->clkdm->flags & CLKDM_NO_AUTODEPS)
  467. return 0;
  468. return clkdm_add_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
  469. }
  470. /**
  471. * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
  472. * @oh: struct omap_hwmod *
  473. *
  474. * Allow the hardware module @oh to enter idle while the hardare
  475. * module initiator @init_oh is active. Useful when a module will not
  476. * be accessed by a particular initiator (e.g., if a module will not
  477. * be accessed by the IVA, there should be no sleepdep between the IVA
  478. * initiator and the module). Only applies to modules in smart-idle
  479. * mode. If the clockdomain is marked as not needing autodeps, return
  480. * 0 without doing anything. Returns -EINVAL upon error or passes
  481. * along clkdm_del_sleepdep() value upon success.
  482. */
  483. static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
  484. {
  485. if (!oh->_clk)
  486. return -EINVAL;
  487. if (oh->_clk->clkdm && oh->_clk->clkdm->flags & CLKDM_NO_AUTODEPS)
  488. return 0;
  489. return clkdm_del_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
  490. }
  491. /**
  492. * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
  493. * @oh: struct omap_hwmod *
  494. *
  495. * Called from _init_clocks(). Populates the @oh _clk (main
  496. * functional clock pointer) if a main_clk is present. Returns 0 on
  497. * success or -EINVAL on error.
  498. */
  499. static int _init_main_clk(struct omap_hwmod *oh)
  500. {
  501. int ret = 0;
  502. if (!oh->main_clk)
  503. return 0;
  504. oh->_clk = omap_clk_get_by_name(oh->main_clk);
  505. if (!oh->_clk) {
  506. pr_warning("omap_hwmod: %s: cannot clk_get main_clk %s\n",
  507. oh->name, oh->main_clk);
  508. return -EINVAL;
  509. }
  510. if (!oh->_clk->clkdm)
  511. pr_warning("omap_hwmod: %s: missing clockdomain for %s.\n",
  512. oh->main_clk, oh->_clk->name);
  513. return ret;
  514. }
  515. /**
  516. * _init_interface_clks - get a struct clk * for the the hwmod's interface clks
  517. * @oh: struct omap_hwmod *
  518. *
  519. * Called from _init_clocks(). Populates the @oh OCP slave interface
  520. * clock pointers. Returns 0 on success or -EINVAL on error.
  521. */
  522. static int _init_interface_clks(struct omap_hwmod *oh)
  523. {
  524. struct omap_hwmod_ocp_if *os;
  525. struct clk *c;
  526. int i = 0;
  527. int ret = 0;
  528. while (i < oh->slaves_cnt) {
  529. os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
  530. if (!os->clk)
  531. continue;
  532. c = omap_clk_get_by_name(os->clk);
  533. if (!c) {
  534. pr_warning("omap_hwmod: %s: cannot clk_get interface_clk %s\n",
  535. oh->name, os->clk);
  536. ret = -EINVAL;
  537. }
  538. os->_clk = c;
  539. }
  540. return ret;
  541. }
  542. /**
  543. * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
  544. * @oh: struct omap_hwmod *
  545. *
  546. * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk
  547. * clock pointers. Returns 0 on success or -EINVAL on error.
  548. */
  549. static int _init_opt_clks(struct omap_hwmod *oh)
  550. {
  551. struct omap_hwmod_opt_clk *oc;
  552. struct clk *c;
  553. int i;
  554. int ret = 0;
  555. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
  556. c = omap_clk_get_by_name(oc->clk);
  557. if (!c) {
  558. pr_warning("omap_hwmod: %s: cannot clk_get opt_clk %s\n",
  559. oh->name, oc->clk);
  560. ret = -EINVAL;
  561. }
  562. oc->_clk = c;
  563. }
  564. return ret;
  565. }
  566. /**
  567. * _enable_clocks - enable hwmod main clock and interface clocks
  568. * @oh: struct omap_hwmod *
  569. *
  570. * Enables all clocks necessary for register reads and writes to succeed
  571. * on the hwmod @oh. Returns 0.
  572. */
  573. static int _enable_clocks(struct omap_hwmod *oh)
  574. {
  575. struct omap_hwmod_ocp_if *os;
  576. int i = 0;
  577. pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
  578. if (oh->_clk)
  579. clk_enable(oh->_clk);
  580. while (i < oh->slaves_cnt) {
  581. os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
  582. if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
  583. clk_enable(os->_clk);
  584. }
  585. /* The opt clocks are controlled by the device driver. */
  586. return 0;
  587. }
  588. /**
  589. * _disable_clocks - disable hwmod main clock and interface clocks
  590. * @oh: struct omap_hwmod *
  591. *
  592. * Disables the hwmod @oh main functional and interface clocks. Returns 0.
  593. */
  594. static int _disable_clocks(struct omap_hwmod *oh)
  595. {
  596. struct omap_hwmod_ocp_if *os;
  597. int i = 0;
  598. pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
  599. if (oh->_clk)
  600. clk_disable(oh->_clk);
  601. while (i < oh->slaves_cnt) {
  602. os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
  603. if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
  604. clk_disable(os->_clk);
  605. }
  606. /* The opt clocks are controlled by the device driver. */
  607. return 0;
  608. }
  609. static void _enable_optional_clocks(struct omap_hwmod *oh)
  610. {
  611. struct omap_hwmod_opt_clk *oc;
  612. int i;
  613. pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name);
  614. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  615. if (oc->_clk) {
  616. pr_debug("omap_hwmod: enable %s:%s\n", oc->role,
  617. oc->_clk->name);
  618. clk_enable(oc->_clk);
  619. }
  620. }
  621. static void _disable_optional_clocks(struct omap_hwmod *oh)
  622. {
  623. struct omap_hwmod_opt_clk *oc;
  624. int i;
  625. pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name);
  626. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  627. if (oc->_clk) {
  628. pr_debug("omap_hwmod: disable %s:%s\n", oc->role,
  629. oc->_clk->name);
  630. clk_disable(oc->_clk);
  631. }
  632. }
  633. /**
  634. * _enable_module - enable CLKCTRL modulemode on OMAP4
  635. * @oh: struct omap_hwmod *
  636. *
  637. * Enables the PRCM module mode related to the hwmod @oh.
  638. * No return value.
  639. */
  640. static void _enable_module(struct omap_hwmod *oh)
  641. {
  642. /* The module mode does not exist prior OMAP4 */
  643. if (cpu_is_omap24xx() || cpu_is_omap34xx())
  644. return;
  645. if (!oh->clkdm || !oh->prcm.omap4.modulemode)
  646. return;
  647. pr_debug("omap_hwmod: %s: _enable_module: %d\n",
  648. oh->name, oh->prcm.omap4.modulemode);
  649. omap4_cminst_module_enable(oh->prcm.omap4.modulemode,
  650. oh->clkdm->prcm_partition,
  651. oh->clkdm->cm_inst,
  652. oh->clkdm->clkdm_offs,
  653. oh->prcm.omap4.clkctrl_offs);
  654. }
  655. /**
  656. * _omap4_wait_target_disable - wait for a module to be disabled on OMAP4
  657. * @oh: struct omap_hwmod *
  658. *
  659. * Wait for a module @oh to enter slave idle. Returns 0 if the module
  660. * does not have an IDLEST bit or if the module successfully enters
  661. * slave idle; otherwise, pass along the return value of the
  662. * appropriate *_cm*_wait_module_idle() function.
  663. */
  664. static int _omap4_wait_target_disable(struct omap_hwmod *oh)
  665. {
  666. if (!cpu_is_omap44xx())
  667. return 0;
  668. if (!oh)
  669. return -EINVAL;
  670. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  671. return 0;
  672. if (oh->flags & HWMOD_NO_IDLEST)
  673. return 0;
  674. return omap4_cminst_wait_module_idle(oh->clkdm->prcm_partition,
  675. oh->clkdm->cm_inst,
  676. oh->clkdm->clkdm_offs,
  677. oh->prcm.omap4.clkctrl_offs);
  678. }
  679. /**
  680. * _count_mpu_irqs - count the number of MPU IRQ lines associated with @oh
  681. * @oh: struct omap_hwmod *oh
  682. *
  683. * Count and return the number of MPU IRQs associated with the hwmod
  684. * @oh. Used to allocate struct resource data. Returns 0 if @oh is
  685. * NULL.
  686. */
  687. static int _count_mpu_irqs(struct omap_hwmod *oh)
  688. {
  689. struct omap_hwmod_irq_info *ohii;
  690. int i = 0;
  691. if (!oh || !oh->mpu_irqs)
  692. return 0;
  693. do {
  694. ohii = &oh->mpu_irqs[i++];
  695. } while (ohii->irq != -1);
  696. return i-1;
  697. }
  698. /**
  699. * _count_sdma_reqs - count the number of SDMA request lines associated with @oh
  700. * @oh: struct omap_hwmod *oh
  701. *
  702. * Count and return the number of SDMA request lines associated with
  703. * the hwmod @oh. Used to allocate struct resource data. Returns 0
  704. * if @oh is NULL.
  705. */
  706. static int _count_sdma_reqs(struct omap_hwmod *oh)
  707. {
  708. struct omap_hwmod_dma_info *ohdi;
  709. int i = 0;
  710. if (!oh || !oh->sdma_reqs)
  711. return 0;
  712. do {
  713. ohdi = &oh->sdma_reqs[i++];
  714. } while (ohdi->dma_req != -1);
  715. return i-1;
  716. }
  717. /**
  718. * _count_ocp_if_addr_spaces - count the number of address space entries for @oh
  719. * @oh: struct omap_hwmod *oh
  720. *
  721. * Count and return the number of address space ranges associated with
  722. * the hwmod @oh. Used to allocate struct resource data. Returns 0
  723. * if @oh is NULL.
  724. */
  725. static int _count_ocp_if_addr_spaces(struct omap_hwmod_ocp_if *os)
  726. {
  727. struct omap_hwmod_addr_space *mem;
  728. int i = 0;
  729. if (!os || !os->addr)
  730. return 0;
  731. do {
  732. mem = &os->addr[i++];
  733. } while (mem->pa_start != mem->pa_end);
  734. return i-1;
  735. }
  736. /**
  737. * _get_mpu_irq_by_name - fetch MPU interrupt line number by name
  738. * @oh: struct omap_hwmod * to operate on
  739. * @name: pointer to the name of the MPU interrupt number to fetch (optional)
  740. * @irq: pointer to an unsigned int to store the MPU IRQ number to
  741. *
  742. * Retrieve a MPU hardware IRQ line number named by @name associated
  743. * with the IP block pointed to by @oh. The IRQ number will be filled
  744. * into the address pointed to by @dma. When @name is non-null, the
  745. * IRQ line number associated with the named entry will be returned.
  746. * If @name is null, the first matching entry will be returned. Data
  747. * order is not meaningful in hwmod data, so callers are strongly
  748. * encouraged to use a non-null @name whenever possible to avoid
  749. * unpredictable effects if hwmod data is later added that causes data
  750. * ordering to change. Returns 0 upon success or a negative error
  751. * code upon error.
  752. */
  753. static int _get_mpu_irq_by_name(struct omap_hwmod *oh, const char *name,
  754. unsigned int *irq)
  755. {
  756. int i;
  757. bool found = false;
  758. if (!oh->mpu_irqs)
  759. return -ENOENT;
  760. i = 0;
  761. while (oh->mpu_irqs[i].irq != -1) {
  762. if (name == oh->mpu_irqs[i].name ||
  763. !strcmp(name, oh->mpu_irqs[i].name)) {
  764. found = true;
  765. break;
  766. }
  767. i++;
  768. }
  769. if (!found)
  770. return -ENOENT;
  771. *irq = oh->mpu_irqs[i].irq;
  772. return 0;
  773. }
  774. /**
  775. * _get_sdma_req_by_name - fetch SDMA request line ID by name
  776. * @oh: struct omap_hwmod * to operate on
  777. * @name: pointer to the name of the SDMA request line to fetch (optional)
  778. * @dma: pointer to an unsigned int to store the request line ID to
  779. *
  780. * Retrieve an SDMA request line ID named by @name on the IP block
  781. * pointed to by @oh. The ID will be filled into the address pointed
  782. * to by @dma. When @name is non-null, the request line ID associated
  783. * with the named entry will be returned. If @name is null, the first
  784. * matching entry will be returned. Data order is not meaningful in
  785. * hwmod data, so callers are strongly encouraged to use a non-null
  786. * @name whenever possible to avoid unpredictable effects if hwmod
  787. * data is later added that causes data ordering to change. Returns 0
  788. * upon success or a negative error code upon error.
  789. */
  790. static int _get_sdma_req_by_name(struct omap_hwmod *oh, const char *name,
  791. unsigned int *dma)
  792. {
  793. int i;
  794. bool found = false;
  795. if (!oh->sdma_reqs)
  796. return -ENOENT;
  797. i = 0;
  798. while (oh->sdma_reqs[i].dma_req != -1) {
  799. if (name == oh->sdma_reqs[i].name ||
  800. !strcmp(name, oh->sdma_reqs[i].name)) {
  801. found = true;
  802. break;
  803. }
  804. i++;
  805. }
  806. if (!found)
  807. return -ENOENT;
  808. *dma = oh->sdma_reqs[i].dma_req;
  809. return 0;
  810. }
  811. /**
  812. * _get_addr_space_by_name - fetch address space start & end by name
  813. * @oh: struct omap_hwmod * to operate on
  814. * @name: pointer to the name of the address space to fetch (optional)
  815. * @pa_start: pointer to a u32 to store the starting address to
  816. * @pa_end: pointer to a u32 to store the ending address to
  817. *
  818. * Retrieve address space start and end addresses for the IP block
  819. * pointed to by @oh. The data will be filled into the addresses
  820. * pointed to by @pa_start and @pa_end. When @name is non-null, the
  821. * address space data associated with the named entry will be
  822. * returned. If @name is null, the first matching entry will be
  823. * returned. Data order is not meaningful in hwmod data, so callers
  824. * are strongly encouraged to use a non-null @name whenever possible
  825. * to avoid unpredictable effects if hwmod data is later added that
  826. * causes data ordering to change. Returns 0 upon success or a
  827. * negative error code upon error.
  828. */
  829. static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name,
  830. u32 *pa_start, u32 *pa_end)
  831. {
  832. int i, j;
  833. struct omap_hwmod_ocp_if *os;
  834. bool found = false;
  835. i = 0;
  836. while (i < oh->slaves_cnt) {
  837. os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
  838. if (!os->addr)
  839. return -ENOENT;
  840. j = 0;
  841. while (os->addr[j].pa_start != os->addr[j].pa_end) {
  842. if (name == os->addr[j].name ||
  843. !strcmp(name, os->addr[j].name)) {
  844. found = true;
  845. break;
  846. }
  847. j++;
  848. }
  849. if (found)
  850. break;
  851. }
  852. if (!found)
  853. return -ENOENT;
  854. *pa_start = os->addr[j].pa_start;
  855. *pa_end = os->addr[j].pa_end;
  856. return 0;
  857. }
  858. /**
  859. * _find_mpu_port_index - find hwmod OCP slave port ID intended for MPU use
  860. * @oh: struct omap_hwmod *
  861. *
  862. * Returns the array index of the OCP slave port that the MPU
  863. * addresses the device on, or -EINVAL upon error or not found.
  864. */
  865. static int __init _find_mpu_port_index(struct omap_hwmod *oh)
  866. {
  867. struct omap_hwmod_ocp_if *os;
  868. int i = 0;
  869. int found = 0;
  870. if (!oh)
  871. return -EINVAL;
  872. while (i < oh->slaves_cnt) {
  873. os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
  874. if (os->user & OCP_USER_MPU) {
  875. found = 1;
  876. break;
  877. }
  878. }
  879. if (found)
  880. pr_debug("omap_hwmod: %s: MPU OCP slave port ID %d\n",
  881. oh->name, i - 1);
  882. else
  883. pr_debug("omap_hwmod: %s: no MPU OCP slave port found\n",
  884. oh->name);
  885. return (found) ? (i - 1) : -EINVAL;
  886. }
  887. /**
  888. * _find_mpu_rt_port - return omap_hwmod_ocp_if accessible by the MPU
  889. * @oh: struct omap_hwmod *
  890. *
  891. * Given a pointer to a struct omap_hwmod record @oh, return a pointer
  892. * to the struct omap_hwmod_ocp_if record that is used by the MPU to
  893. * communicate with the IP block. This interface need not be directly
  894. * connected to the MPU (and almost certainly is not), but is directly
  895. * connected to the IP block represented by @oh. Returns a pointer
  896. * to the struct omap_hwmod_ocp_if * upon success, or returns NULL upon
  897. * error or if there does not appear to be a path from the MPU to this
  898. * IP block.
  899. */
  900. static struct omap_hwmod_ocp_if *_find_mpu_rt_port(struct omap_hwmod *oh)
  901. {
  902. if (!oh || oh->_int_flags & _HWMOD_NO_MPU_PORT || oh->slaves_cnt == 0)
  903. return NULL;
  904. return oh->slaves[oh->_mpu_port_index];
  905. };
  906. /**
  907. * _find_mpu_rt_addr_space - return MPU register target address space for @oh
  908. * @oh: struct omap_hwmod *
  909. *
  910. * Returns a pointer to the struct omap_hwmod_addr_space record representing
  911. * the register target MPU address space; or returns NULL upon error.
  912. */
  913. static struct omap_hwmod_addr_space * __init _find_mpu_rt_addr_space(struct omap_hwmod *oh)
  914. {
  915. struct omap_hwmod_ocp_if *os;
  916. struct omap_hwmod_addr_space *mem;
  917. int found = 0, i = 0;
  918. os = _find_mpu_rt_port(oh);
  919. if (!os->addr)
  920. return NULL;
  921. do {
  922. mem = &os->addr[i++];
  923. if (mem->flags & ADDR_TYPE_RT)
  924. found = 1;
  925. } while (!found && mem->pa_start != mem->pa_end);
  926. return (found) ? mem : NULL;
  927. }
  928. /**
  929. * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG
  930. * @oh: struct omap_hwmod *
  931. *
  932. * If module is marked as SWSUP_SIDLE, force the module out of slave
  933. * idle; otherwise, configure it for smart-idle. If module is marked
  934. * as SWSUP_MSUSPEND, force the module out of master standby;
  935. * otherwise, configure it for smart-standby. No return value.
  936. */
  937. static void _enable_sysc(struct omap_hwmod *oh)
  938. {
  939. u8 idlemode, sf;
  940. u32 v;
  941. if (!oh->class->sysc)
  942. return;
  943. v = oh->_sysc_cache;
  944. sf = oh->class->sysc->sysc_flags;
  945. if (sf & SYSC_HAS_SIDLEMODE) {
  946. idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
  947. HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
  948. _set_slave_idlemode(oh, idlemode, &v);
  949. }
  950. if (sf & SYSC_HAS_MIDLEMODE) {
  951. if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
  952. idlemode = HWMOD_IDLEMODE_NO;
  953. } else {
  954. if (sf & SYSC_HAS_ENAWAKEUP)
  955. _enable_wakeup(oh, &v);
  956. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  957. idlemode = HWMOD_IDLEMODE_SMART_WKUP;
  958. else
  959. idlemode = HWMOD_IDLEMODE_SMART;
  960. }
  961. _set_master_standbymode(oh, idlemode, &v);
  962. }
  963. /*
  964. * XXX The clock framework should handle this, by
  965. * calling into this code. But this must wait until the
  966. * clock structures are tagged with omap_hwmod entries
  967. */
  968. if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
  969. (sf & SYSC_HAS_CLOCKACTIVITY))
  970. _set_clockactivity(oh, oh->class->sysc->clockact, &v);
  971. /* If slave is in SMARTIDLE, also enable wakeup */
  972. if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
  973. _enable_wakeup(oh, &v);
  974. _write_sysconfig(v, oh);
  975. /*
  976. * Set the autoidle bit only after setting the smartidle bit
  977. * Setting this will not have any impact on the other modules.
  978. */
  979. if (sf & SYSC_HAS_AUTOIDLE) {
  980. idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
  981. 0 : 1;
  982. _set_module_autoidle(oh, idlemode, &v);
  983. _write_sysconfig(v, oh);
  984. }
  985. }
  986. /**
  987. * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG
  988. * @oh: struct omap_hwmod *
  989. *
  990. * If module is marked as SWSUP_SIDLE, force the module into slave
  991. * idle; otherwise, configure it for smart-idle. If module is marked
  992. * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
  993. * configure it for smart-standby. No return value.
  994. */
  995. static void _idle_sysc(struct omap_hwmod *oh)
  996. {
  997. u8 idlemode, sf;
  998. u32 v;
  999. if (!oh->class->sysc)
  1000. return;
  1001. v = oh->_sysc_cache;
  1002. sf = oh->class->sysc->sysc_flags;
  1003. if (sf & SYSC_HAS_SIDLEMODE) {
  1004. idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
  1005. HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART;
  1006. _set_slave_idlemode(oh, idlemode, &v);
  1007. }
  1008. if (sf & SYSC_HAS_MIDLEMODE) {
  1009. if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
  1010. idlemode = HWMOD_IDLEMODE_FORCE;
  1011. } else {
  1012. if (sf & SYSC_HAS_ENAWAKEUP)
  1013. _enable_wakeup(oh, &v);
  1014. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  1015. idlemode = HWMOD_IDLEMODE_SMART_WKUP;
  1016. else
  1017. idlemode = HWMOD_IDLEMODE_SMART;
  1018. }
  1019. _set_master_standbymode(oh, idlemode, &v);
  1020. }
  1021. /* If slave is in SMARTIDLE, also enable wakeup */
  1022. if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
  1023. _enable_wakeup(oh, &v);
  1024. _write_sysconfig(v, oh);
  1025. }
  1026. /**
  1027. * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG
  1028. * @oh: struct omap_hwmod *
  1029. *
  1030. * Force the module into slave idle and master suspend. No return
  1031. * value.
  1032. */
  1033. static void _shutdown_sysc(struct omap_hwmod *oh)
  1034. {
  1035. u32 v;
  1036. u8 sf;
  1037. if (!oh->class->sysc)
  1038. return;
  1039. v = oh->_sysc_cache;
  1040. sf = oh->class->sysc->sysc_flags;
  1041. if (sf & SYSC_HAS_SIDLEMODE)
  1042. _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
  1043. if (sf & SYSC_HAS_MIDLEMODE)
  1044. _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
  1045. if (sf & SYSC_HAS_AUTOIDLE)
  1046. _set_module_autoidle(oh, 1, &v);
  1047. _write_sysconfig(v, oh);
  1048. }
  1049. /**
  1050. * _lookup - find an omap_hwmod by name
  1051. * @name: find an omap_hwmod by name
  1052. *
  1053. * Return a pointer to an omap_hwmod by name, or NULL if not found.
  1054. */
  1055. static struct omap_hwmod *_lookup(const char *name)
  1056. {
  1057. struct omap_hwmod *oh, *temp_oh;
  1058. oh = NULL;
  1059. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  1060. if (!strcmp(name, temp_oh->name)) {
  1061. oh = temp_oh;
  1062. break;
  1063. }
  1064. }
  1065. return oh;
  1066. }
  1067. /**
  1068. * _init_clkdm - look up a clockdomain name, store pointer in omap_hwmod
  1069. * @oh: struct omap_hwmod *
  1070. *
  1071. * Convert a clockdomain name stored in a struct omap_hwmod into a
  1072. * clockdomain pointer, and save it into the struct omap_hwmod.
  1073. * return -EINVAL if clkdm_name does not exist or if the lookup failed.
  1074. */
  1075. static int _init_clkdm(struct omap_hwmod *oh)
  1076. {
  1077. if (cpu_is_omap24xx() || cpu_is_omap34xx())
  1078. return 0;
  1079. if (!oh->clkdm_name) {
  1080. pr_warning("omap_hwmod: %s: no clkdm_name\n", oh->name);
  1081. return -EINVAL;
  1082. }
  1083. oh->clkdm = clkdm_lookup(oh->clkdm_name);
  1084. if (!oh->clkdm) {
  1085. pr_warning("omap_hwmod: %s: could not associate to clkdm %s\n",
  1086. oh->name, oh->clkdm_name);
  1087. return -EINVAL;
  1088. }
  1089. pr_debug("omap_hwmod: %s: associated to clkdm %s\n",
  1090. oh->name, oh->clkdm_name);
  1091. return 0;
  1092. }
  1093. /**
  1094. * _init_clocks - clk_get() all clocks associated with this hwmod. Retrieve as
  1095. * well the clockdomain.
  1096. * @oh: struct omap_hwmod *
  1097. * @data: not used; pass NULL
  1098. *
  1099. * Called by omap_hwmod_setup_*() (after omap2_clk_init()).
  1100. * Resolves all clock names embedded in the hwmod. Returns 0 on
  1101. * success, or a negative error code on failure.
  1102. */
  1103. static int _init_clocks(struct omap_hwmod *oh, void *data)
  1104. {
  1105. int ret = 0;
  1106. if (oh->_state != _HWMOD_STATE_REGISTERED)
  1107. return 0;
  1108. pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
  1109. ret |= _init_main_clk(oh);
  1110. ret |= _init_interface_clks(oh);
  1111. ret |= _init_opt_clks(oh);
  1112. ret |= _init_clkdm(oh);
  1113. if (!ret)
  1114. oh->_state = _HWMOD_STATE_CLKS_INITED;
  1115. else
  1116. pr_warning("omap_hwmod: %s: cannot _init_clocks\n", oh->name);
  1117. return ret;
  1118. }
  1119. /**
  1120. * _wait_target_ready - wait for a module to leave slave idle
  1121. * @oh: struct omap_hwmod *
  1122. *
  1123. * Wait for a module @oh to leave slave idle. Returns 0 if the module
  1124. * does not have an IDLEST bit or if the module successfully leaves
  1125. * slave idle; otherwise, pass along the return value of the
  1126. * appropriate *_cm*_wait_module_ready() function.
  1127. */
  1128. static int _wait_target_ready(struct omap_hwmod *oh)
  1129. {
  1130. struct omap_hwmod_ocp_if *os;
  1131. int ret;
  1132. if (!oh)
  1133. return -EINVAL;
  1134. if (oh->flags & HWMOD_NO_IDLEST)
  1135. return 0;
  1136. os = _find_mpu_rt_port(oh);
  1137. if (!os)
  1138. return 0;
  1139. /* XXX check module SIDLEMODE */
  1140. /* XXX check clock enable states */
  1141. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  1142. ret = omap2_cm_wait_module_ready(oh->prcm.omap2.module_offs,
  1143. oh->prcm.omap2.idlest_reg_id,
  1144. oh->prcm.omap2.idlest_idle_bit);
  1145. } else if (cpu_is_omap44xx()) {
  1146. if (!oh->clkdm)
  1147. return -EINVAL;
  1148. ret = omap4_cminst_wait_module_ready(oh->clkdm->prcm_partition,
  1149. oh->clkdm->cm_inst,
  1150. oh->clkdm->clkdm_offs,
  1151. oh->prcm.omap4.clkctrl_offs);
  1152. } else {
  1153. BUG();
  1154. };
  1155. return ret;
  1156. }
  1157. /**
  1158. * _lookup_hardreset - fill register bit info for this hwmod/reset line
  1159. * @oh: struct omap_hwmod *
  1160. * @name: name of the reset line in the context of this hwmod
  1161. * @ohri: struct omap_hwmod_rst_info * that this function will fill in
  1162. *
  1163. * Return the bit position of the reset line that match the
  1164. * input name. Return -ENOENT if not found.
  1165. */
  1166. static u8 _lookup_hardreset(struct omap_hwmod *oh, const char *name,
  1167. struct omap_hwmod_rst_info *ohri)
  1168. {
  1169. int i;
  1170. for (i = 0; i < oh->rst_lines_cnt; i++) {
  1171. const char *rst_line = oh->rst_lines[i].name;
  1172. if (!strcmp(rst_line, name)) {
  1173. ohri->rst_shift = oh->rst_lines[i].rst_shift;
  1174. ohri->st_shift = oh->rst_lines[i].st_shift;
  1175. pr_debug("omap_hwmod: %s: %s: %s: rst %d st %d\n",
  1176. oh->name, __func__, rst_line, ohri->rst_shift,
  1177. ohri->st_shift);
  1178. return 0;
  1179. }
  1180. }
  1181. return -ENOENT;
  1182. }
  1183. /**
  1184. * _assert_hardreset - assert the HW reset line of submodules
  1185. * contained in the hwmod module.
  1186. * @oh: struct omap_hwmod *
  1187. * @name: name of the reset line to lookup and assert
  1188. *
  1189. * Some IP like dsp, ipu or iva contain processor that require
  1190. * an HW reset line to be assert / deassert in order to enable fully
  1191. * the IP.
  1192. */
  1193. static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
  1194. {
  1195. struct omap_hwmod_rst_info ohri;
  1196. u8 ret;
  1197. if (!oh)
  1198. return -EINVAL;
  1199. ret = _lookup_hardreset(oh, name, &ohri);
  1200. if (IS_ERR_VALUE(ret))
  1201. return ret;
  1202. if (cpu_is_omap24xx() || cpu_is_omap34xx())
  1203. return omap2_prm_assert_hardreset(oh->prcm.omap2.module_offs,
  1204. ohri.rst_shift);
  1205. else if (cpu_is_omap44xx())
  1206. return omap4_prminst_assert_hardreset(ohri.rst_shift,
  1207. oh->clkdm->pwrdm.ptr->prcm_partition,
  1208. oh->clkdm->pwrdm.ptr->prcm_offs,
  1209. oh->prcm.omap4.rstctrl_offs);
  1210. else
  1211. return -EINVAL;
  1212. }
  1213. /**
  1214. * _deassert_hardreset - deassert the HW reset line of submodules contained
  1215. * in the hwmod module.
  1216. * @oh: struct omap_hwmod *
  1217. * @name: name of the reset line to look up and deassert
  1218. *
  1219. * Some IP like dsp, ipu or iva contain processor that require
  1220. * an HW reset line to be assert / deassert in order to enable fully
  1221. * the IP.
  1222. */
  1223. static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
  1224. {
  1225. struct omap_hwmod_rst_info ohri;
  1226. int ret;
  1227. if (!oh)
  1228. return -EINVAL;
  1229. ret = _lookup_hardreset(oh, name, &ohri);
  1230. if (IS_ERR_VALUE(ret))
  1231. return ret;
  1232. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  1233. ret = omap2_prm_deassert_hardreset(oh->prcm.omap2.module_offs,
  1234. ohri.rst_shift,
  1235. ohri.st_shift);
  1236. } else if (cpu_is_omap44xx()) {
  1237. if (ohri.st_shift)
  1238. pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n",
  1239. oh->name, name);
  1240. ret = omap4_prminst_deassert_hardreset(ohri.rst_shift,
  1241. oh->clkdm->pwrdm.ptr->prcm_partition,
  1242. oh->clkdm->pwrdm.ptr->prcm_offs,
  1243. oh->prcm.omap4.rstctrl_offs);
  1244. } else {
  1245. return -EINVAL;
  1246. }
  1247. if (ret == -EBUSY)
  1248. pr_warning("omap_hwmod: %s: failed to hardreset\n", oh->name);
  1249. return ret;
  1250. }
  1251. /**
  1252. * _read_hardreset - read the HW reset line state of submodules
  1253. * contained in the hwmod module
  1254. * @oh: struct omap_hwmod *
  1255. * @name: name of the reset line to look up and read
  1256. *
  1257. * Return the state of the reset line.
  1258. */
  1259. static int _read_hardreset(struct omap_hwmod *oh, const char *name)
  1260. {
  1261. struct omap_hwmod_rst_info ohri;
  1262. u8 ret;
  1263. if (!oh)
  1264. return -EINVAL;
  1265. ret = _lookup_hardreset(oh, name, &ohri);
  1266. if (IS_ERR_VALUE(ret))
  1267. return ret;
  1268. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  1269. return omap2_prm_is_hardreset_asserted(oh->prcm.omap2.module_offs,
  1270. ohri.st_shift);
  1271. } else if (cpu_is_omap44xx()) {
  1272. return omap4_prminst_is_hardreset_asserted(ohri.rst_shift,
  1273. oh->clkdm->pwrdm.ptr->prcm_partition,
  1274. oh->clkdm->pwrdm.ptr->prcm_offs,
  1275. oh->prcm.omap4.rstctrl_offs);
  1276. } else {
  1277. return -EINVAL;
  1278. }
  1279. }
  1280. /**
  1281. * _are_any_hardreset_lines_asserted - return true if part of @oh is hard-reset
  1282. * @oh: struct omap_hwmod *
  1283. *
  1284. * If any hardreset line associated with @oh is asserted, then return true.
  1285. * Otherwise, if @oh has no hardreset lines associated with it, or if
  1286. * no hardreset lines associated with @oh are asserted, then return false.
  1287. * This function is used to avoid executing some parts of the IP block
  1288. * enable/disable sequence if a hardreset line is set.
  1289. */
  1290. static bool _are_any_hardreset_lines_asserted(struct omap_hwmod *oh)
  1291. {
  1292. int i;
  1293. if (oh->rst_lines_cnt == 0)
  1294. return false;
  1295. for (i = 0; i < oh->rst_lines_cnt; i++)
  1296. if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
  1297. return true;
  1298. return false;
  1299. }
  1300. /**
  1301. * _omap4_disable_module - enable CLKCTRL modulemode on OMAP4
  1302. * @oh: struct omap_hwmod *
  1303. *
  1304. * Disable the PRCM module mode related to the hwmod @oh.
  1305. * Return EINVAL if the modulemode is not supported and 0 in case of success.
  1306. */
  1307. static int _omap4_disable_module(struct omap_hwmod *oh)
  1308. {
  1309. int v;
  1310. /* The module mode does not exist prior OMAP4 */
  1311. if (!cpu_is_omap44xx())
  1312. return -EINVAL;
  1313. if (!oh->clkdm || !oh->prcm.omap4.modulemode)
  1314. return -EINVAL;
  1315. pr_debug("omap_hwmod: %s: %s\n", oh->name, __func__);
  1316. omap4_cminst_module_disable(oh->clkdm->prcm_partition,
  1317. oh->clkdm->cm_inst,
  1318. oh->clkdm->clkdm_offs,
  1319. oh->prcm.omap4.clkctrl_offs);
  1320. if (_are_any_hardreset_lines_asserted(oh))
  1321. return 0;
  1322. v = _omap4_wait_target_disable(oh);
  1323. if (v)
  1324. pr_warn("omap_hwmod: %s: _wait_target_disable failed\n",
  1325. oh->name);
  1326. return 0;
  1327. }
  1328. /**
  1329. * _ocp_softreset - reset an omap_hwmod via the OCP_SYSCONFIG bit
  1330. * @oh: struct omap_hwmod *
  1331. *
  1332. * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
  1333. * enabled for this to work. Returns -ENOENT if the hwmod cannot be
  1334. * reset this way, -EINVAL if the hwmod is in the wrong state,
  1335. * -ETIMEDOUT if the module did not reset in time, or 0 upon success.
  1336. *
  1337. * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
  1338. * Starting in OMAP4, some IPs do not have SYSSTATUS registers and instead
  1339. * use the SYSCONFIG softreset bit to provide the status.
  1340. *
  1341. * Note that some IP like McBSP do have reset control but don't have
  1342. * reset status.
  1343. */
  1344. static int _ocp_softreset(struct omap_hwmod *oh)
  1345. {
  1346. u32 v, softrst_mask;
  1347. int c = 0;
  1348. int ret = 0;
  1349. if (!oh->class->sysc ||
  1350. !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
  1351. return -ENOENT;
  1352. /* clocks must be on for this operation */
  1353. if (oh->_state != _HWMOD_STATE_ENABLED) {
  1354. pr_warning("omap_hwmod: %s: reset can only be entered from "
  1355. "enabled state\n", oh->name);
  1356. return -EINVAL;
  1357. }
  1358. /* For some modules, all optionnal clocks need to be enabled as well */
  1359. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  1360. _enable_optional_clocks(oh);
  1361. pr_debug("omap_hwmod: %s: resetting via OCP SOFTRESET\n", oh->name);
  1362. v = oh->_sysc_cache;
  1363. ret = _set_softreset(oh, &v);
  1364. if (ret)
  1365. goto dis_opt_clks;
  1366. _write_sysconfig(v, oh);
  1367. if (oh->class->sysc->srst_udelay)
  1368. udelay(oh->class->sysc->srst_udelay);
  1369. if (oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
  1370. omap_test_timeout((omap_hwmod_read(oh,
  1371. oh->class->sysc->syss_offs)
  1372. & SYSS_RESETDONE_MASK),
  1373. MAX_MODULE_SOFTRESET_WAIT, c);
  1374. else if (oh->class->sysc->sysc_flags & SYSC_HAS_RESET_STATUS) {
  1375. softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
  1376. omap_test_timeout(!(omap_hwmod_read(oh,
  1377. oh->class->sysc->sysc_offs)
  1378. & softrst_mask),
  1379. MAX_MODULE_SOFTRESET_WAIT, c);
  1380. }
  1381. if (c == MAX_MODULE_SOFTRESET_WAIT)
  1382. pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n",
  1383. oh->name, MAX_MODULE_SOFTRESET_WAIT);
  1384. else
  1385. pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
  1386. /*
  1387. * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
  1388. * _wait_target_ready() or _reset()
  1389. */
  1390. ret = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
  1391. dis_opt_clks:
  1392. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  1393. _disable_optional_clocks(oh);
  1394. return ret;
  1395. }
  1396. /**
  1397. * _reset - reset an omap_hwmod
  1398. * @oh: struct omap_hwmod *
  1399. *
  1400. * Resets an omap_hwmod @oh. If the module has a custom reset
  1401. * function pointer defined, then call it to reset the IP block, and
  1402. * pass along its return value to the caller. Otherwise, if the IP
  1403. * block has an OCP_SYSCONFIG register with a SOFTRESET bitfield
  1404. * associated with it, call a function to reset the IP block via that
  1405. * method, and pass along the return value to the caller. Finally, if
  1406. * the IP block has some hardreset lines associated with it, assert
  1407. * all of those, but do _not_ deassert them. (This is because driver
  1408. * authors have expressed an apparent requirement to control the
  1409. * deassertion of the hardreset lines themselves.)
  1410. *
  1411. * The default software reset mechanism for most OMAP IP blocks is
  1412. * triggered via the OCP_SYSCONFIG.SOFTRESET bit. However, some
  1413. * hwmods cannot be reset via this method. Some are not targets and
  1414. * therefore have no OCP header registers to access. Others (like the
  1415. * IVA) have idiosyncratic reset sequences. So for these relatively
  1416. * rare cases, custom reset code can be supplied in the struct
  1417. * omap_hwmod_class .reset function pointer. Passes along the return
  1418. * value from either _ocp_softreset() or the custom reset function -
  1419. * these must return -EINVAL if the hwmod cannot be reset this way or
  1420. * if the hwmod is in the wrong state, -ETIMEDOUT if the module did
  1421. * not reset in time, or 0 upon success.
  1422. */
  1423. static int _reset(struct omap_hwmod *oh)
  1424. {
  1425. int i, r;
  1426. pr_debug("omap_hwmod: %s: resetting\n", oh->name);
  1427. if (oh->class->reset) {
  1428. r = oh->class->reset(oh);
  1429. } else {
  1430. if (oh->rst_lines_cnt > 0) {
  1431. for (i = 0; i < oh->rst_lines_cnt; i++)
  1432. _assert_hardreset(oh, oh->rst_lines[i].name);
  1433. return 0;
  1434. } else {
  1435. r = _ocp_softreset(oh);
  1436. if (r == -ENOENT)
  1437. r = 0;
  1438. }
  1439. }
  1440. /*
  1441. * OCP_SYSCONFIG bits need to be reprogrammed after a
  1442. * softreset. The _enable() function should be split to avoid
  1443. * the rewrite of the OCP_SYSCONFIG register.
  1444. */
  1445. if (oh->class->sysc) {
  1446. _update_sysc_cache(oh);
  1447. _enable_sysc(oh);
  1448. }
  1449. return r;
  1450. }
  1451. /**
  1452. * _enable - enable an omap_hwmod
  1453. * @oh: struct omap_hwmod *
  1454. *
  1455. * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
  1456. * register target. Returns -EINVAL if the hwmod is in the wrong
  1457. * state or passes along the return value of _wait_target_ready().
  1458. */
  1459. static int _enable(struct omap_hwmod *oh)
  1460. {
  1461. int r;
  1462. int hwsup = 0;
  1463. pr_debug("omap_hwmod: %s: enabling\n", oh->name);
  1464. /*
  1465. * hwmods with HWMOD_INIT_NO_IDLE flag set are left in enabled
  1466. * state at init. Now that someone is really trying to enable
  1467. * them, just ensure that the hwmod mux is set.
  1468. */
  1469. if (oh->_int_flags & _HWMOD_SKIP_ENABLE) {
  1470. /*
  1471. * If the caller has mux data populated, do the mux'ing
  1472. * which wouldn't have been done as part of the _enable()
  1473. * done during setup.
  1474. */
  1475. if (oh->mux)
  1476. omap_hwmod_mux(oh->mux, _HWMOD_STATE_ENABLED);
  1477. oh->_int_flags &= ~_HWMOD_SKIP_ENABLE;
  1478. return 0;
  1479. }
  1480. if (oh->_state != _HWMOD_STATE_INITIALIZED &&
  1481. oh->_state != _HWMOD_STATE_IDLE &&
  1482. oh->_state != _HWMOD_STATE_DISABLED) {
  1483. WARN(1, "omap_hwmod: %s: enabled state can only be entered from initialized, idle, or disabled state\n",
  1484. oh->name);
  1485. return -EINVAL;
  1486. }
  1487. /*
  1488. * If an IP block contains HW reset lines and any of them are
  1489. * asserted, we let integration code associated with that
  1490. * block handle the enable. We've received very little
  1491. * information on what those driver authors need, and until
  1492. * detailed information is provided and the driver code is
  1493. * posted to the public lists, this is probably the best we
  1494. * can do.
  1495. */
  1496. if (_are_any_hardreset_lines_asserted(oh))
  1497. return 0;
  1498. /* Mux pins for device runtime if populated */
  1499. if (oh->mux && (!oh->mux->enabled ||
  1500. ((oh->_state == _HWMOD_STATE_IDLE) &&
  1501. oh->mux->pads_dynamic)))
  1502. omap_hwmod_mux(oh->mux, _HWMOD_STATE_ENABLED);
  1503. _add_initiator_dep(oh, mpu_oh);
  1504. if (oh->clkdm) {
  1505. /*
  1506. * A clockdomain must be in SW_SUP before enabling
  1507. * completely the module. The clockdomain can be set
  1508. * in HW_AUTO only when the module become ready.
  1509. */
  1510. hwsup = clkdm_in_hwsup(oh->clkdm);
  1511. r = clkdm_hwmod_enable(oh->clkdm, oh);
  1512. if (r) {
  1513. WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
  1514. oh->name, oh->clkdm->name, r);
  1515. return r;
  1516. }
  1517. }
  1518. _enable_clocks(oh);
  1519. _enable_module(oh);
  1520. r = _wait_target_ready(oh);
  1521. if (!r) {
  1522. /*
  1523. * Set the clockdomain to HW_AUTO only if the target is ready,
  1524. * assuming that the previous state was HW_AUTO
  1525. */
  1526. if (oh->clkdm && hwsup)
  1527. clkdm_allow_idle(oh->clkdm);
  1528. oh->_state = _HWMOD_STATE_ENABLED;
  1529. /* Access the sysconfig only if the target is ready */
  1530. if (oh->class->sysc) {
  1531. if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
  1532. _update_sysc_cache(oh);
  1533. _enable_sysc(oh);
  1534. }
  1535. } else {
  1536. _disable_clocks(oh);
  1537. pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n",
  1538. oh->name, r);
  1539. if (oh->clkdm)
  1540. clkdm_hwmod_disable(oh->clkdm, oh);
  1541. }
  1542. return r;
  1543. }
  1544. /**
  1545. * _idle - idle an omap_hwmod
  1546. * @oh: struct omap_hwmod *
  1547. *
  1548. * Idles an omap_hwmod @oh. This should be called once the hwmod has
  1549. * no further work. Returns -EINVAL if the hwmod is in the wrong
  1550. * state or returns 0.
  1551. */
  1552. static int _idle(struct omap_hwmod *oh)
  1553. {
  1554. pr_debug("omap_hwmod: %s: idling\n", oh->name);
  1555. if (oh->_state != _HWMOD_STATE_ENABLED) {
  1556. WARN(1, "omap_hwmod: %s: idle state can only be entered from enabled state\n",
  1557. oh->name);
  1558. return -EINVAL;
  1559. }
  1560. if (_are_any_hardreset_lines_asserted(oh))
  1561. return 0;
  1562. if (oh->class->sysc)
  1563. _idle_sysc(oh);
  1564. _del_initiator_dep(oh, mpu_oh);
  1565. _omap4_disable_module(oh);
  1566. /*
  1567. * The module must be in idle mode before disabling any parents
  1568. * clocks. Otherwise, the parent clock might be disabled before
  1569. * the module transition is done, and thus will prevent the
  1570. * transition to complete properly.
  1571. */
  1572. _disable_clocks(oh);
  1573. if (oh->clkdm)
  1574. clkdm_hwmod_disable(oh->clkdm, oh);
  1575. /* Mux pins for device idle if populated */
  1576. if (oh->mux && oh->mux->pads_dynamic)
  1577. omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
  1578. oh->_state = _HWMOD_STATE_IDLE;
  1579. return 0;
  1580. }
  1581. /**
  1582. * omap_hwmod_set_ocp_autoidle - set the hwmod's OCP autoidle bit
  1583. * @oh: struct omap_hwmod *
  1584. * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
  1585. *
  1586. * Sets the IP block's OCP autoidle bit in hardware, and updates our
  1587. * local copy. Intended to be used by drivers that require
  1588. * direct manipulation of the AUTOIDLE bits.
  1589. * Returns -EINVAL if @oh is null or is not in the ENABLED state, or passes
  1590. * along the return value from _set_module_autoidle().
  1591. *
  1592. * Any users of this function should be scrutinized carefully.
  1593. */
  1594. int omap_hwmod_set_ocp_autoidle(struct omap_hwmod *oh, u8 autoidle)
  1595. {
  1596. u32 v;
  1597. int retval = 0;
  1598. unsigned long flags;
  1599. if (!oh || oh->_state != _HWMOD_STATE_ENABLED)
  1600. return -EINVAL;
  1601. spin_lock_irqsave(&oh->_lock, flags);
  1602. v = oh->_sysc_cache;
  1603. retval = _set_module_autoidle(oh, autoidle, &v);
  1604. if (!retval)
  1605. _write_sysconfig(v, oh);
  1606. spin_unlock_irqrestore(&oh->_lock, flags);
  1607. return retval;
  1608. }
  1609. /**
  1610. * _shutdown - shutdown an omap_hwmod
  1611. * @oh: struct omap_hwmod *
  1612. *
  1613. * Shut down an omap_hwmod @oh. This should be called when the driver
  1614. * used for the hwmod is removed or unloaded or if the driver is not
  1615. * used by the system. Returns -EINVAL if the hwmod is in the wrong
  1616. * state or returns 0.
  1617. */
  1618. static int _shutdown(struct omap_hwmod *oh)
  1619. {
  1620. int ret, i;
  1621. u8 prev_state;
  1622. if (oh->_state != _HWMOD_STATE_IDLE &&
  1623. oh->_state != _HWMOD_STATE_ENABLED) {
  1624. WARN(1, "omap_hwmod: %s: disabled state can only be entered from idle, or enabled state\n",
  1625. oh->name);
  1626. return -EINVAL;
  1627. }
  1628. if (_are_any_hardreset_lines_asserted(oh))
  1629. return 0;
  1630. pr_debug("omap_hwmod: %s: disabling\n", oh->name);
  1631. if (oh->class->pre_shutdown) {
  1632. prev_state = oh->_state;
  1633. if (oh->_state == _HWMOD_STATE_IDLE)
  1634. _enable(oh);
  1635. ret = oh->class->pre_shutdown(oh);
  1636. if (ret) {
  1637. if (prev_state == _HWMOD_STATE_IDLE)
  1638. _idle(oh);
  1639. return ret;
  1640. }
  1641. }
  1642. if (oh->class->sysc) {
  1643. if (oh->_state == _HWMOD_STATE_IDLE)
  1644. _enable(oh);
  1645. _shutdown_sysc(oh);
  1646. }
  1647. /* clocks and deps are already disabled in idle */
  1648. if (oh->_state == _HWMOD_STATE_ENABLED) {
  1649. _del_initiator_dep(oh, mpu_oh);
  1650. /* XXX what about the other system initiators here? dma, dsp */
  1651. _omap4_disable_module(oh);
  1652. _disable_clocks(oh);
  1653. if (oh->clkdm)
  1654. clkdm_hwmod_disable(oh->clkdm, oh);
  1655. }
  1656. /* XXX Should this code also force-disable the optional clocks? */
  1657. for (i = 0; i < oh->rst_lines_cnt; i++)
  1658. _assert_hardreset(oh, oh->rst_lines[i].name);
  1659. /* Mux pins to safe mode or use populated off mode values */
  1660. if (oh->mux)
  1661. omap_hwmod_mux(oh->mux, _HWMOD_STATE_DISABLED);
  1662. oh->_state = _HWMOD_STATE_DISABLED;
  1663. return 0;
  1664. }
  1665. /**
  1666. * _init_mpu_rt_base - populate the virtual address for a hwmod
  1667. * @oh: struct omap_hwmod * to locate the virtual address
  1668. *
  1669. * Cache the virtual address used by the MPU to access this IP block's
  1670. * registers. This address is needed early so the OCP registers that
  1671. * are part of the device's address space can be ioremapped properly.
  1672. * No return value.
  1673. */
  1674. static void __init _init_mpu_rt_base(struct omap_hwmod *oh, void *data)
  1675. {
  1676. struct omap_hwmod_addr_space *mem;
  1677. void __iomem *va_start;
  1678. if (!oh)
  1679. return;
  1680. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  1681. return;
  1682. mem = _find_mpu_rt_addr_space(oh);
  1683. if (!mem) {
  1684. pr_debug("omap_hwmod: %s: no MPU register target found\n",
  1685. oh->name);
  1686. return;
  1687. }
  1688. va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start);
  1689. if (!va_start) {
  1690. pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name);
  1691. return;
  1692. }
  1693. pr_debug("omap_hwmod: %s: MPU register target at va %p\n",
  1694. oh->name, va_start);
  1695. oh->_mpu_rt_va = va_start;
  1696. }
  1697. /**
  1698. * _init - initialize internal data for the hwmod @oh
  1699. * @oh: struct omap_hwmod *
  1700. * @n: (unused)
  1701. *
  1702. * Look up the clocks and the address space used by the MPU to access
  1703. * registers belonging to the hwmod @oh. @oh must already be
  1704. * registered at this point. This is the first of two phases for
  1705. * hwmod initialization. Code called here does not touch any hardware
  1706. * registers, it simply prepares internal data structures. Returns 0
  1707. * upon success or if the hwmod isn't registered, or -EINVAL upon
  1708. * failure.
  1709. */
  1710. static int __init _init(struct omap_hwmod *oh, void *data)
  1711. {
  1712. int r;
  1713. if (oh->_state != _HWMOD_STATE_REGISTERED)
  1714. return 0;
  1715. _init_mpu_rt_base(oh, NULL);
  1716. r = _init_clocks(oh, NULL);
  1717. if (IS_ERR_VALUE(r)) {
  1718. WARN(1, "omap_hwmod: %s: couldn't init clocks\n", oh->name);
  1719. return -EINVAL;
  1720. }
  1721. oh->_state = _HWMOD_STATE_INITIALIZED;
  1722. return 0;
  1723. }
  1724. /**
  1725. * _setup_iclk_autoidle - configure an IP block's interface clocks
  1726. * @oh: struct omap_hwmod *
  1727. *
  1728. * Set up the module's interface clocks. XXX This function is still mostly
  1729. * a stub; implementing this properly requires iclk autoidle usecounting in
  1730. * the clock code. No return value.
  1731. */
  1732. static void __init _setup_iclk_autoidle(struct omap_hwmod *oh)
  1733. {
  1734. struct omap_hwmod_ocp_if *os;
  1735. int i = 0;
  1736. if (oh->_state != _HWMOD_STATE_INITIALIZED)
  1737. return;
  1738. while (i < oh->slaves_cnt) {
  1739. os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
  1740. if (!os->_clk)
  1741. continue;
  1742. if (os->flags & OCPIF_SWSUP_IDLE) {
  1743. /* XXX omap_iclk_deny_idle(c); */
  1744. } else {
  1745. /* XXX omap_iclk_allow_idle(c); */
  1746. clk_enable(os->_clk);
  1747. }
  1748. }
  1749. return;
  1750. }
  1751. /**
  1752. * _setup_reset - reset an IP block during the setup process
  1753. * @oh: struct omap_hwmod *
  1754. *
  1755. * Reset the IP block corresponding to the hwmod @oh during the setup
  1756. * process. The IP block is first enabled so it can be successfully
  1757. * reset. Returns 0 upon success or a negative error code upon
  1758. * failure.
  1759. */
  1760. static int __init _setup_reset(struct omap_hwmod *oh)
  1761. {
  1762. int r;
  1763. if (oh->_state != _HWMOD_STATE_INITIALIZED)
  1764. return -EINVAL;
  1765. if (oh->rst_lines_cnt == 0) {
  1766. r = _enable(oh);
  1767. if (r) {
  1768. pr_warning("omap_hwmod: %s: cannot be enabled for reset (%d)\n",
  1769. oh->name, oh->_state);
  1770. return -EINVAL;
  1771. }
  1772. }
  1773. if (!(oh->flags & HWMOD_INIT_NO_RESET))
  1774. r = _reset(oh);
  1775. return r;
  1776. }
  1777. /**
  1778. * _setup_postsetup - transition to the appropriate state after _setup
  1779. * @oh: struct omap_hwmod *
  1780. *
  1781. * Place an IP block represented by @oh into a "post-setup" state --
  1782. * either IDLE, ENABLED, or DISABLED. ("post-setup" simply means that
  1783. * this function is called at the end of _setup().) The postsetup
  1784. * state for an IP block can be changed by calling
  1785. * omap_hwmod_enter_postsetup_state() early in the boot process,
  1786. * before one of the omap_hwmod_setup*() functions are called for the
  1787. * IP block.
  1788. *
  1789. * The IP block stays in this state until a PM runtime-based driver is
  1790. * loaded for that IP block. A post-setup state of IDLE is
  1791. * appropriate for almost all IP blocks with runtime PM-enabled
  1792. * drivers, since those drivers are able to enable the IP block. A
  1793. * post-setup state of ENABLED is appropriate for kernels with PM
  1794. * runtime disabled. The DISABLED state is appropriate for unusual IP
  1795. * blocks such as the MPU WDTIMER on kernels without WDTIMER drivers
  1796. * included, since the WDTIMER starts running on reset and will reset
  1797. * the MPU if left active.
  1798. *
  1799. * This post-setup mechanism is deprecated. Once all of the OMAP
  1800. * drivers have been converted to use PM runtime, and all of the IP
  1801. * block data and interconnect data is available to the hwmod code, it
  1802. * should be possible to replace this mechanism with a "lazy reset"
  1803. * arrangement. In a "lazy reset" setup, each IP block is enabled
  1804. * when the driver first probes, then all remaining IP blocks without
  1805. * drivers are either shut down or enabled after the drivers have
  1806. * loaded. However, this cannot take place until the above
  1807. * preconditions have been met, since otherwise the late reset code
  1808. * has no way of knowing which IP blocks are in use by drivers, and
  1809. * which ones are unused.
  1810. *
  1811. * No return value.
  1812. */
  1813. static void __init _setup_postsetup(struct omap_hwmod *oh)
  1814. {
  1815. u8 postsetup_state;
  1816. if (oh->rst_lines_cnt > 0)
  1817. return;
  1818. postsetup_state = oh->_postsetup_state;
  1819. if (postsetup_state == _HWMOD_STATE_UNKNOWN)
  1820. postsetup_state = _HWMOD_STATE_ENABLED;
  1821. /*
  1822. * XXX HWMOD_INIT_NO_IDLE does not belong in hwmod data -
  1823. * it should be set by the core code as a runtime flag during startup
  1824. */
  1825. if ((oh->flags & HWMOD_INIT_NO_IDLE) &&
  1826. (postsetup_state == _HWMOD_STATE_IDLE)) {
  1827. oh->_int_flags |= _HWMOD_SKIP_ENABLE;
  1828. postsetup_state = _HWMOD_STATE_ENABLED;
  1829. }
  1830. if (postsetup_state == _HWMOD_STATE_IDLE)
  1831. _idle(oh);
  1832. else if (postsetup_state == _HWMOD_STATE_DISABLED)
  1833. _shutdown(oh);
  1834. else if (postsetup_state != _HWMOD_STATE_ENABLED)
  1835. WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
  1836. oh->name, postsetup_state);
  1837. return;
  1838. }
  1839. /**
  1840. * _setup - prepare IP block hardware for use
  1841. * @oh: struct omap_hwmod *
  1842. * @n: (unused, pass NULL)
  1843. *
  1844. * Configure the IP block represented by @oh. This may include
  1845. * enabling the IP block, resetting it, and placing it into a
  1846. * post-setup state, depending on the type of IP block and applicable
  1847. * flags. IP blocks are reset to prevent any previous configuration
  1848. * by the bootloader or previous operating system from interfering
  1849. * with power management or other parts of the system. The reset can
  1850. * be avoided; see omap_hwmod_no_setup_reset(). This is the second of
  1851. * two phases for hwmod initialization. Code called here generally
  1852. * affects the IP block hardware, or system integration hardware
  1853. * associated with the IP block. Returns 0.
  1854. */
  1855. static int __init _setup(struct omap_hwmod *oh, void *data)
  1856. {
  1857. if (oh->_state != _HWMOD_STATE_INITIALIZED)
  1858. return 0;
  1859. _setup_iclk_autoidle(oh);
  1860. if (!_setup_reset(oh))
  1861. _setup_postsetup(oh);
  1862. return 0;
  1863. }
  1864. /**
  1865. * _register - register a struct omap_hwmod
  1866. * @oh: struct omap_hwmod *
  1867. *
  1868. * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod
  1869. * already has been registered by the same name; -EINVAL if the
  1870. * omap_hwmod is in the wrong state, if @oh is NULL, if the
  1871. * omap_hwmod's class field is NULL; if the omap_hwmod is missing a
  1872. * name, or if the omap_hwmod's class is missing a name; or 0 upon
  1873. * success.
  1874. *
  1875. * XXX The data should be copied into bootmem, so the original data
  1876. * should be marked __initdata and freed after init. This would allow
  1877. * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note
  1878. * that the copy process would be relatively complex due to the large number
  1879. * of substructures.
  1880. */
  1881. static int __init _register(struct omap_hwmod *oh)
  1882. {
  1883. int ms_id;
  1884. if (!oh || !oh->name || !oh->class || !oh->class->name ||
  1885. (oh->_state != _HWMOD_STATE_UNKNOWN))
  1886. return -EINVAL;
  1887. pr_debug("omap_hwmod: %s: registering\n", oh->name);
  1888. if (_lookup(oh->name))
  1889. return -EEXIST;
  1890. ms_id = _find_mpu_port_index(oh);
  1891. if (!IS_ERR_VALUE(ms_id))
  1892. oh->_mpu_port_index = ms_id;
  1893. else
  1894. oh->_int_flags |= _HWMOD_NO_MPU_PORT;
  1895. list_add_tail(&oh->node, &omap_hwmod_list);
  1896. spin_lock_init(&oh->_lock);
  1897. oh->_state = _HWMOD_STATE_REGISTERED;
  1898. /*
  1899. * XXX Rather than doing a strcmp(), this should test a flag
  1900. * set in the hwmod data, inserted by the autogenerator code.
  1901. */
  1902. if (!strcmp(oh->name, MPU_INITIATOR_NAME))
  1903. mpu_oh = oh;
  1904. return 0;
  1905. }
  1906. /* Public functions */
  1907. u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs)
  1908. {
  1909. if (oh->flags & HWMOD_16BIT_REG)
  1910. return __raw_readw(oh->_mpu_rt_va + reg_offs);
  1911. else
  1912. return __raw_readl(oh->_mpu_rt_va + reg_offs);
  1913. }
  1914. void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs)
  1915. {
  1916. if (oh->flags & HWMOD_16BIT_REG)
  1917. __raw_writew(v, oh->_mpu_rt_va + reg_offs);
  1918. else
  1919. __raw_writel(v, oh->_mpu_rt_va + reg_offs);
  1920. }
  1921. /**
  1922. * omap_hwmod_softreset - reset a module via SYSCONFIG.SOFTRESET bit
  1923. * @oh: struct omap_hwmod *
  1924. *
  1925. * This is a public function exposed to drivers. Some drivers may need to do
  1926. * some settings before and after resetting the device. Those drivers after
  1927. * doing the necessary settings could use this function to start a reset by
  1928. * setting the SYSCONFIG.SOFTRESET bit.
  1929. */
  1930. int omap_hwmod_softreset(struct omap_hwmod *oh)
  1931. {
  1932. u32 v;
  1933. int ret;
  1934. if (!oh || !(oh->_sysc_cache))
  1935. return -EINVAL;
  1936. v = oh->_sysc_cache;
  1937. ret = _set_softreset(oh, &v);
  1938. if (ret)
  1939. goto error;
  1940. _write_sysconfig(v, oh);
  1941. error:
  1942. return ret;
  1943. }
  1944. /**
  1945. * omap_hwmod_set_slave_idlemode - set the hwmod's OCP slave idlemode
  1946. * @oh: struct omap_hwmod *
  1947. * @idlemode: SIDLEMODE field bits (shifted to bit 0)
  1948. *
  1949. * Sets the IP block's OCP slave idlemode in hardware, and updates our
  1950. * local copy. Intended to be used by drivers that have some erratum
  1951. * that requires direct manipulation of the SIDLEMODE bits. Returns
  1952. * -EINVAL if @oh is null, or passes along the return value from
  1953. * _set_slave_idlemode().
  1954. *
  1955. * XXX Does this function have any current users? If not, we should
  1956. * remove it; it is better to let the rest of the hwmod code handle this.
  1957. * Any users of this function should be scrutinized carefully.
  1958. */
  1959. int omap_hwmod_set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode)
  1960. {
  1961. u32 v;
  1962. int retval = 0;
  1963. if (!oh)
  1964. return -EINVAL;
  1965. v = oh->_sysc_cache;
  1966. retval = _set_slave_idlemode(oh, idlemode, &v);
  1967. if (!retval)
  1968. _write_sysconfig(v, oh);
  1969. return retval;
  1970. }
  1971. /**
  1972. * omap_hwmod_lookup - look up a registered omap_hwmod by name
  1973. * @name: name of the omap_hwmod to look up
  1974. *
  1975. * Given a @name of an omap_hwmod, return a pointer to the registered
  1976. * struct omap_hwmod *, or NULL upon error.
  1977. */
  1978. struct omap_hwmod *omap_hwmod_lookup(const char *name)
  1979. {
  1980. struct omap_hwmod *oh;
  1981. if (!name)
  1982. return NULL;
  1983. oh = _lookup(name);
  1984. return oh;
  1985. }
  1986. /**
  1987. * omap_hwmod_for_each - call function for each registered omap_hwmod
  1988. * @fn: pointer to a callback function
  1989. * @data: void * data to pass to callback function
  1990. *
  1991. * Call @fn for each registered omap_hwmod, passing @data to each
  1992. * function. @fn must return 0 for success or any other value for
  1993. * failure. If @fn returns non-zero, the iteration across omap_hwmods
  1994. * will stop and the non-zero return value will be passed to the
  1995. * caller of omap_hwmod_for_each(). @fn is called with
  1996. * omap_hwmod_for_each() held.
  1997. */
  1998. int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
  1999. void *data)
  2000. {
  2001. struct omap_hwmod *temp_oh;
  2002. int ret = 0;
  2003. if (!fn)
  2004. return -EINVAL;
  2005. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  2006. ret = (*fn)(temp_oh, data);
  2007. if (ret)
  2008. break;
  2009. }
  2010. return ret;
  2011. }
  2012. /**
  2013. * omap_hwmod_register - register an array of hwmods
  2014. * @ohs: pointer to an array of omap_hwmods to register
  2015. *
  2016. * Intended to be called early in boot before the clock framework is
  2017. * initialized. If @ohs is not null, will register all omap_hwmods
  2018. * listed in @ohs that are valid for this chip. Returns 0.
  2019. */
  2020. int __init omap_hwmod_register(struct omap_hwmod **ohs)
  2021. {
  2022. int r, i;
  2023. if (!ohs)
  2024. return 0;
  2025. i = 0;
  2026. do {
  2027. r = _register(ohs[i]);
  2028. WARN(r, "omap_hwmod: %s: _register returned %d\n", ohs[i]->name,
  2029. r);
  2030. } while (ohs[++i]);
  2031. return 0;
  2032. }
  2033. /**
  2034. * _ensure_mpu_hwmod_is_setup - ensure the MPU SS hwmod is init'ed and set up
  2035. * @oh: pointer to the hwmod currently being set up (usually not the MPU)
  2036. *
  2037. * If the hwmod data corresponding to the MPU subsystem IP block
  2038. * hasn't been initialized and set up yet, do so now. This must be
  2039. * done first since sleep dependencies may be added from other hwmods
  2040. * to the MPU. Intended to be called only by omap_hwmod_setup*(). No
  2041. * return value.
  2042. */
  2043. static void __init _ensure_mpu_hwmod_is_setup(struct omap_hwmod *oh)
  2044. {
  2045. if (!mpu_oh || mpu_oh->_state == _HWMOD_STATE_UNKNOWN)
  2046. pr_err("omap_hwmod: %s: MPU initiator hwmod %s not yet registered\n",
  2047. __func__, MPU_INITIATOR_NAME);
  2048. else if (mpu_oh->_state == _HWMOD_STATE_REGISTERED && oh != mpu_oh)
  2049. omap_hwmod_setup_one(MPU_INITIATOR_NAME);
  2050. }
  2051. /**
  2052. * omap_hwmod_setup_one - set up a single hwmod
  2053. * @oh_name: const char * name of the already-registered hwmod to set up
  2054. *
  2055. * Initialize and set up a single hwmod. Intended to be used for a
  2056. * small number of early devices, such as the timer IP blocks used for
  2057. * the scheduler clock. Must be called after omap2_clk_init().
  2058. * Resolves the struct clk names to struct clk pointers for each
  2059. * registered omap_hwmod. Also calls _setup() on each hwmod. Returns
  2060. * -EINVAL upon error or 0 upon success.
  2061. */
  2062. int __init omap_hwmod_setup_one(const char *oh_name)
  2063. {
  2064. struct omap_hwmod *oh;
  2065. pr_debug("omap_hwmod: %s: %s\n", oh_name, __func__);
  2066. oh = _lookup(oh_name);
  2067. if (!oh) {
  2068. WARN(1, "omap_hwmod: %s: hwmod not yet registered\n", oh_name);
  2069. return -EINVAL;
  2070. }
  2071. _ensure_mpu_hwmod_is_setup(oh);
  2072. _init(oh, NULL);
  2073. _setup(oh, NULL);
  2074. return 0;
  2075. }
  2076. /**
  2077. * omap_hwmod_setup_all - set up all registered IP blocks
  2078. *
  2079. * Initialize and set up all IP blocks registered with the hwmod code.
  2080. * Must be called after omap2_clk_init(). Resolves the struct clk
  2081. * names to struct clk pointers for each registered omap_hwmod. Also
  2082. * calls _setup() on each hwmod. Returns 0 upon success.
  2083. */
  2084. static int __init omap_hwmod_setup_all(void)
  2085. {
  2086. _ensure_mpu_hwmod_is_setup(NULL);
  2087. omap_hwmod_for_each(_init, NULL);
  2088. omap_hwmod_for_each(_setup, NULL);
  2089. return 0;
  2090. }
  2091. core_initcall(omap_hwmod_setup_all);
  2092. /**
  2093. * omap_hwmod_enable - enable an omap_hwmod
  2094. * @oh: struct omap_hwmod *
  2095. *
  2096. * Enable an omap_hwmod @oh. Intended to be called by omap_device_enable().
  2097. * Returns -EINVAL on error or passes along the return value from _enable().
  2098. */
  2099. int omap_hwmod_enable(struct omap_hwmod *oh)
  2100. {
  2101. int r;
  2102. unsigned long flags;
  2103. if (!oh)
  2104. return -EINVAL;
  2105. spin_lock_irqsave(&oh->_lock, flags);
  2106. r = _enable(oh);
  2107. spin_unlock_irqrestore(&oh->_lock, flags);
  2108. return r;
  2109. }
  2110. /**
  2111. * omap_hwmod_idle - idle an omap_hwmod
  2112. * @oh: struct omap_hwmod *
  2113. *
  2114. * Idle an omap_hwmod @oh. Intended to be called by omap_device_idle().
  2115. * Returns -EINVAL on error or passes along the return value from _idle().
  2116. */
  2117. int omap_hwmod_idle(struct omap_hwmod *oh)
  2118. {
  2119. unsigned long flags;
  2120. if (!oh)
  2121. return -EINVAL;
  2122. spin_lock_irqsave(&oh->_lock, flags);
  2123. _idle(oh);
  2124. spin_unlock_irqrestore(&oh->_lock, flags);
  2125. return 0;
  2126. }
  2127. /**
  2128. * omap_hwmod_shutdown - shutdown an omap_hwmod
  2129. * @oh: struct omap_hwmod *
  2130. *
  2131. * Shutdown an omap_hwmod @oh. Intended to be called by
  2132. * omap_device_shutdown(). Returns -EINVAL on error or passes along
  2133. * the return value from _shutdown().
  2134. */
  2135. int omap_hwmod_shutdown(struct omap_hwmod *oh)
  2136. {
  2137. unsigned long flags;
  2138. if (!oh)
  2139. return -EINVAL;
  2140. spin_lock_irqsave(&oh->_lock, flags);
  2141. _shutdown(oh);
  2142. spin_unlock_irqrestore(&oh->_lock, flags);
  2143. return 0;
  2144. }
  2145. /**
  2146. * omap_hwmod_enable_clocks - enable main_clk, all interface clocks
  2147. * @oh: struct omap_hwmod *oh
  2148. *
  2149. * Intended to be called by the omap_device code.
  2150. */
  2151. int omap_hwmod_enable_clocks(struct omap_hwmod *oh)
  2152. {
  2153. unsigned long flags;
  2154. spin_lock_irqsave(&oh->_lock, flags);
  2155. _enable_clocks(oh);
  2156. spin_unlock_irqrestore(&oh->_lock, flags);
  2157. return 0;
  2158. }
  2159. /**
  2160. * omap_hwmod_disable_clocks - disable main_clk, all interface clocks
  2161. * @oh: struct omap_hwmod *oh
  2162. *
  2163. * Intended to be called by the omap_device code.
  2164. */
  2165. int omap_hwmod_disable_clocks(struct omap_hwmod *oh)
  2166. {
  2167. unsigned long flags;
  2168. spin_lock_irqsave(&oh->_lock, flags);
  2169. _disable_clocks(oh);
  2170. spin_unlock_irqrestore(&oh->_lock, flags);
  2171. return 0;
  2172. }
  2173. /**
  2174. * omap_hwmod_ocp_barrier - wait for posted writes against the hwmod to complete
  2175. * @oh: struct omap_hwmod *oh
  2176. *
  2177. * Intended to be called by drivers and core code when all posted
  2178. * writes to a device must complete before continuing further
  2179. * execution (for example, after clearing some device IRQSTATUS
  2180. * register bits)
  2181. *
  2182. * XXX what about targets with multiple OCP threads?
  2183. */
  2184. void omap_hwmod_ocp_barrier(struct omap_hwmod *oh)
  2185. {
  2186. BUG_ON(!oh);
  2187. if (!oh->class->sysc || !oh->class->sysc->sysc_flags) {
  2188. WARN(1, "omap_device: %s: OCP barrier impossible due to device configuration\n",
  2189. oh->name);
  2190. return;
  2191. }
  2192. /*
  2193. * Forces posted writes to complete on the OCP thread handling
  2194. * register writes
  2195. */
  2196. omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
  2197. }
  2198. /**
  2199. * omap_hwmod_reset - reset the hwmod
  2200. * @oh: struct omap_hwmod *
  2201. *
  2202. * Under some conditions, a driver may wish to reset the entire device.
  2203. * Called from omap_device code. Returns -EINVAL on error or passes along
  2204. * the return value from _reset().
  2205. */
  2206. int omap_hwmod_reset(struct omap_hwmod *oh)
  2207. {
  2208. int r;
  2209. unsigned long flags;
  2210. if (!oh)
  2211. return -EINVAL;
  2212. spin_lock_irqsave(&oh->_lock, flags);
  2213. r = _reset(oh);
  2214. spin_unlock_irqrestore(&oh->_lock, flags);
  2215. return r;
  2216. }
  2217. /*
  2218. * IP block data retrieval functions
  2219. */
  2220. /**
  2221. * omap_hwmod_count_resources - count number of struct resources needed by hwmod
  2222. * @oh: struct omap_hwmod *
  2223. * @res: pointer to the first element of an array of struct resource to fill
  2224. *
  2225. * Count the number of struct resource array elements necessary to
  2226. * contain omap_hwmod @oh resources. Intended to be called by code
  2227. * that registers omap_devices. Intended to be used to determine the
  2228. * size of a dynamically-allocated struct resource array, before
  2229. * calling omap_hwmod_fill_resources(). Returns the number of struct
  2230. * resource array elements needed.
  2231. *
  2232. * XXX This code is not optimized. It could attempt to merge adjacent
  2233. * resource IDs.
  2234. *
  2235. */
  2236. int omap_hwmod_count_resources(struct omap_hwmod *oh)
  2237. {
  2238. struct omap_hwmod_ocp_if *os;
  2239. int ret;
  2240. int i = 0;
  2241. ret = _count_mpu_irqs(oh) + _count_sdma_reqs(oh);
  2242. while (i < oh->slaves_cnt) {
  2243. os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
  2244. ret += _count_ocp_if_addr_spaces(os);
  2245. }
  2246. return ret;
  2247. }
  2248. /**
  2249. * omap_hwmod_fill_resources - fill struct resource array with hwmod data
  2250. * @oh: struct omap_hwmod *
  2251. * @res: pointer to the first element of an array of struct resource to fill
  2252. *
  2253. * Fill the struct resource array @res with resource data from the
  2254. * omap_hwmod @oh. Intended to be called by code that registers
  2255. * omap_devices. See also omap_hwmod_count_resources(). Returns the
  2256. * number of array elements filled.
  2257. */
  2258. int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
  2259. {
  2260. struct omap_hwmod_ocp_if *os;
  2261. int i, j, mpu_irqs_cnt, sdma_reqs_cnt, addr_cnt;
  2262. int r = 0;
  2263. /* For each IRQ, DMA, memory area, fill in array.*/
  2264. mpu_irqs_cnt = _count_mpu_irqs(oh);
  2265. for (i = 0; i < mpu_irqs_cnt; i++) {
  2266. (res + r)->name = (oh->mpu_irqs + i)->name;
  2267. (res + r)->start = (oh->mpu_irqs + i)->irq;
  2268. (res + r)->end = (oh->mpu_irqs + i)->irq;
  2269. (res + r)->flags = IORESOURCE_IRQ;
  2270. r++;
  2271. }
  2272. sdma_reqs_cnt = _count_sdma_reqs(oh);
  2273. for (i = 0; i < sdma_reqs_cnt; i++) {
  2274. (res + r)->name = (oh->sdma_reqs + i)->name;
  2275. (res + r)->start = (oh->sdma_reqs + i)->dma_req;
  2276. (res + r)->end = (oh->sdma_reqs + i)->dma_req;
  2277. (res + r)->flags = IORESOURCE_DMA;
  2278. r++;
  2279. }
  2280. i = 0;
  2281. while (i < oh->slaves_cnt) {
  2282. os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
  2283. addr_cnt = _count_ocp_if_addr_spaces(os);
  2284. for (j = 0; j < addr_cnt; j++) {
  2285. (res + r)->name = (os->addr + j)->name;
  2286. (res + r)->start = (os->addr + j)->pa_start;
  2287. (res + r)->end = (os->addr + j)->pa_end;
  2288. (res + r)->flags = IORESOURCE_MEM;
  2289. r++;
  2290. }
  2291. }
  2292. return r;
  2293. }
  2294. /**
  2295. * omap_hwmod_get_resource_byname - fetch IP block integration data by name
  2296. * @oh: struct omap_hwmod * to operate on
  2297. * @type: one of the IORESOURCE_* constants from include/linux/ioport.h
  2298. * @name: pointer to the name of the data to fetch (optional)
  2299. * @rsrc: pointer to a struct resource, allocated by the caller
  2300. *
  2301. * Retrieve MPU IRQ, SDMA request line, or address space start/end
  2302. * data for the IP block pointed to by @oh. The data will be filled
  2303. * into a struct resource record pointed to by @rsrc. The struct
  2304. * resource must be allocated by the caller. When @name is non-null,
  2305. * the data associated with the matching entry in the IRQ/SDMA/address
  2306. * space hwmod data arrays will be returned. If @name is null, the
  2307. * first array entry will be returned. Data order is not meaningful
  2308. * in hwmod data, so callers are strongly encouraged to use a non-null
  2309. * @name whenever possible to avoid unpredictable effects if hwmod
  2310. * data is later added that causes data ordering to change. This
  2311. * function is only intended for use by OMAP core code. Device
  2312. * drivers should not call this function - the appropriate bus-related
  2313. * data accessor functions should be used instead. Returns 0 upon
  2314. * success or a negative error code upon error.
  2315. */
  2316. int omap_hwmod_get_resource_byname(struct omap_hwmod *oh, unsigned int type,
  2317. const char *name, struct resource *rsrc)
  2318. {
  2319. int r;
  2320. unsigned int irq, dma;
  2321. u32 pa_start, pa_end;
  2322. if (!oh || !rsrc)
  2323. return -EINVAL;
  2324. if (type == IORESOURCE_IRQ) {
  2325. r = _get_mpu_irq_by_name(oh, name, &irq);
  2326. if (r)
  2327. return r;
  2328. rsrc->start = irq;
  2329. rsrc->end = irq;
  2330. } else if (type == IORESOURCE_DMA) {
  2331. r = _get_sdma_req_by_name(oh, name, &dma);
  2332. if (r)
  2333. return r;
  2334. rsrc->start = dma;
  2335. rsrc->end = dma;
  2336. } else if (type == IORESOURCE_MEM) {
  2337. r = _get_addr_space_by_name(oh, name, &pa_start, &pa_end);
  2338. if (r)
  2339. return r;
  2340. rsrc->start = pa_start;
  2341. rsrc->end = pa_end;
  2342. } else {
  2343. return -EINVAL;
  2344. }
  2345. rsrc->flags = type;
  2346. rsrc->name = name;
  2347. return 0;
  2348. }
  2349. /**
  2350. * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
  2351. * @oh: struct omap_hwmod *
  2352. *
  2353. * Return the powerdomain pointer associated with the OMAP module
  2354. * @oh's main clock. If @oh does not have a main clk, return the
  2355. * powerdomain associated with the interface clock associated with the
  2356. * module's MPU port. (XXX Perhaps this should use the SDMA port
  2357. * instead?) Returns NULL on error, or a struct powerdomain * on
  2358. * success.
  2359. */
  2360. struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
  2361. {
  2362. struct clk *c;
  2363. struct omap_hwmod_ocp_if *oi;
  2364. if (!oh)
  2365. return NULL;
  2366. if (oh->_clk) {
  2367. c = oh->_clk;
  2368. } else {
  2369. oi = _find_mpu_rt_port(oh);
  2370. if (!oi)
  2371. return NULL;
  2372. c = oi->_clk;
  2373. }
  2374. if (!c->clkdm)
  2375. return NULL;
  2376. return c->clkdm->pwrdm.ptr;
  2377. }
  2378. /**
  2379. * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU)
  2380. * @oh: struct omap_hwmod *
  2381. *
  2382. * Returns the virtual address corresponding to the beginning of the
  2383. * module's register target, in the address range that is intended to
  2384. * be used by the MPU. Returns the virtual address upon success or NULL
  2385. * upon error.
  2386. */
  2387. void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh)
  2388. {
  2389. if (!oh)
  2390. return NULL;
  2391. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  2392. return NULL;
  2393. if (oh->_state == _HWMOD_STATE_UNKNOWN)
  2394. return NULL;
  2395. return oh->_mpu_rt_va;
  2396. }
  2397. /**
  2398. * omap_hwmod_add_initiator_dep - add sleepdep from @init_oh to @oh
  2399. * @oh: struct omap_hwmod *
  2400. * @init_oh: struct omap_hwmod * (initiator)
  2401. *
  2402. * Add a sleep dependency between the initiator @init_oh and @oh.
  2403. * Intended to be called by DSP/Bridge code via platform_data for the
  2404. * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
  2405. * code needs to add/del initiator dependencies dynamically
  2406. * before/after accessing a device. Returns the return value from
  2407. * _add_initiator_dep().
  2408. *
  2409. * XXX Keep a usecount in the clockdomain code
  2410. */
  2411. int omap_hwmod_add_initiator_dep(struct omap_hwmod *oh,
  2412. struct omap_hwmod *init_oh)
  2413. {
  2414. return _add_initiator_dep(oh, init_oh);
  2415. }
  2416. /*
  2417. * XXX what about functions for drivers to save/restore ocp_sysconfig
  2418. * for context save/restore operations?
  2419. */
  2420. /**
  2421. * omap_hwmod_del_initiator_dep - remove sleepdep from @init_oh to @oh
  2422. * @oh: struct omap_hwmod *
  2423. * @init_oh: struct omap_hwmod * (initiator)
  2424. *
  2425. * Remove a sleep dependency between the initiator @init_oh and @oh.
  2426. * Intended to be called by DSP/Bridge code via platform_data for the
  2427. * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
  2428. * code needs to add/del initiator dependencies dynamically
  2429. * before/after accessing a device. Returns the return value from
  2430. * _del_initiator_dep().
  2431. *
  2432. * XXX Keep a usecount in the clockdomain code
  2433. */
  2434. int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh,
  2435. struct omap_hwmod *init_oh)
  2436. {
  2437. return _del_initiator_dep(oh, init_oh);
  2438. }
  2439. /**
  2440. * omap_hwmod_enable_wakeup - allow device to wake up the system
  2441. * @oh: struct omap_hwmod *
  2442. *
  2443. * Sets the module OCP socket ENAWAKEUP bit to allow the module to
  2444. * send wakeups to the PRCM, and enable I/O ring wakeup events for
  2445. * this IP block if it has dynamic mux entries. Eventually this
  2446. * should set PRCM wakeup registers to cause the PRCM to receive
  2447. * wakeup events from the module. Does not set any wakeup routing
  2448. * registers beyond this point - if the module is to wake up any other
  2449. * module or subsystem, that must be set separately. Called by
  2450. * omap_device code. Returns -EINVAL on error or 0 upon success.
  2451. */
  2452. int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
  2453. {
  2454. unsigned long flags;
  2455. u32 v;
  2456. spin_lock_irqsave(&oh->_lock, flags);
  2457. if (oh->class->sysc &&
  2458. (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
  2459. v = oh->_sysc_cache;
  2460. _enable_wakeup(oh, &v);
  2461. _write_sysconfig(v, oh);
  2462. }
  2463. _set_idle_ioring_wakeup(oh, true);
  2464. spin_unlock_irqrestore(&oh->_lock, flags);
  2465. return 0;
  2466. }
  2467. /**
  2468. * omap_hwmod_disable_wakeup - prevent device from waking the system
  2469. * @oh: struct omap_hwmod *
  2470. *
  2471. * Clears the module OCP socket ENAWAKEUP bit to prevent the module
  2472. * from sending wakeups to the PRCM, and disable I/O ring wakeup
  2473. * events for this IP block if it has dynamic mux entries. Eventually
  2474. * this should clear PRCM wakeup registers to cause the PRCM to ignore
  2475. * wakeup events from the module. Does not set any wakeup routing
  2476. * registers beyond this point - if the module is to wake up any other
  2477. * module or subsystem, that must be set separately. Called by
  2478. * omap_device code. Returns -EINVAL on error or 0 upon success.
  2479. */
  2480. int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
  2481. {
  2482. unsigned long flags;
  2483. u32 v;
  2484. spin_lock_irqsave(&oh->_lock, flags);
  2485. if (oh->class->sysc &&
  2486. (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
  2487. v = oh->_sysc_cache;
  2488. _disable_wakeup(oh, &v);
  2489. _write_sysconfig(v, oh);
  2490. }
  2491. _set_idle_ioring_wakeup(oh, false);
  2492. spin_unlock_irqrestore(&oh->_lock, flags);
  2493. return 0;
  2494. }
  2495. /**
  2496. * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
  2497. * contained in the hwmod module.
  2498. * @oh: struct omap_hwmod *
  2499. * @name: name of the reset line to lookup and assert
  2500. *
  2501. * Some IP like dsp, ipu or iva contain processor that require
  2502. * an HW reset line to be assert / deassert in order to enable fully
  2503. * the IP. Returns -EINVAL if @oh is null or if the operation is not
  2504. * yet supported on this OMAP; otherwise, passes along the return value
  2505. * from _assert_hardreset().
  2506. */
  2507. int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
  2508. {
  2509. int ret;
  2510. unsigned long flags;
  2511. if (!oh)
  2512. return -EINVAL;
  2513. spin_lock_irqsave(&oh->_lock, flags);
  2514. ret = _assert_hardreset(oh, name);
  2515. spin_unlock_irqrestore(&oh->_lock, flags);
  2516. return ret;
  2517. }
  2518. /**
  2519. * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
  2520. * contained in the hwmod module.
  2521. * @oh: struct omap_hwmod *
  2522. * @name: name of the reset line to look up and deassert
  2523. *
  2524. * Some IP like dsp, ipu or iva contain processor that require
  2525. * an HW reset line to be assert / deassert in order to enable fully
  2526. * the IP. Returns -EINVAL if @oh is null or if the operation is not
  2527. * yet supported on this OMAP; otherwise, passes along the return value
  2528. * from _deassert_hardreset().
  2529. */
  2530. int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
  2531. {
  2532. int ret;
  2533. unsigned long flags;
  2534. if (!oh)
  2535. return -EINVAL;
  2536. spin_lock_irqsave(&oh->_lock, flags);
  2537. ret = _deassert_hardreset(oh, name);
  2538. spin_unlock_irqrestore(&oh->_lock, flags);
  2539. return ret;
  2540. }
  2541. /**
  2542. * omap_hwmod_read_hardreset - read the HW reset line state of submodules
  2543. * contained in the hwmod module
  2544. * @oh: struct omap_hwmod *
  2545. * @name: name of the reset line to look up and read
  2546. *
  2547. * Return the current state of the hwmod @oh's reset line named @name:
  2548. * returns -EINVAL upon parameter error or if this operation
  2549. * is unsupported on the current OMAP; otherwise, passes along the return
  2550. * value from _read_hardreset().
  2551. */
  2552. int omap_hwmod_read_hardreset(struct omap_hwmod *oh, const char *name)
  2553. {
  2554. int ret;
  2555. unsigned long flags;
  2556. if (!oh)
  2557. return -EINVAL;
  2558. spin_lock_irqsave(&oh->_lock, flags);
  2559. ret = _read_hardreset(oh, name);
  2560. spin_unlock_irqrestore(&oh->_lock, flags);
  2561. return ret;
  2562. }
  2563. /**
  2564. * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
  2565. * @classname: struct omap_hwmod_class name to search for
  2566. * @fn: callback function pointer to call for each hwmod in class @classname
  2567. * @user: arbitrary context data to pass to the callback function
  2568. *
  2569. * For each omap_hwmod of class @classname, call @fn.
  2570. * If the callback function returns something other than
  2571. * zero, the iterator is terminated, and the callback function's return
  2572. * value is passed back to the caller. Returns 0 upon success, -EINVAL
  2573. * if @classname or @fn are NULL, or passes back the error code from @fn.
  2574. */
  2575. int omap_hwmod_for_each_by_class(const char *classname,
  2576. int (*fn)(struct omap_hwmod *oh,
  2577. void *user),
  2578. void *user)
  2579. {
  2580. struct omap_hwmod *temp_oh;
  2581. int ret = 0;
  2582. if (!classname || !fn)
  2583. return -EINVAL;
  2584. pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
  2585. __func__, classname);
  2586. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  2587. if (!strcmp(temp_oh->class->name, classname)) {
  2588. pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
  2589. __func__, temp_oh->name);
  2590. ret = (*fn)(temp_oh, user);
  2591. if (ret)
  2592. break;
  2593. }
  2594. }
  2595. if (ret)
  2596. pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",
  2597. __func__, ret);
  2598. return ret;
  2599. }
  2600. /**
  2601. * omap_hwmod_set_postsetup_state - set the post-_setup() state for this hwmod
  2602. * @oh: struct omap_hwmod *
  2603. * @state: state that _setup() should leave the hwmod in
  2604. *
  2605. * Sets the hwmod state that @oh will enter at the end of _setup()
  2606. * (called by omap_hwmod_setup_*()). See also the documentation
  2607. * for _setup_postsetup(), above. Returns 0 upon success or
  2608. * -EINVAL if there is a problem with the arguments or if the hwmod is
  2609. * in the wrong state.
  2610. */
  2611. int omap_hwmod_set_postsetup_state(struct omap_hwmod *oh, u8 state)
  2612. {
  2613. int ret;
  2614. unsigned long flags;
  2615. if (!oh)
  2616. return -EINVAL;
  2617. if (state != _HWMOD_STATE_DISABLED &&
  2618. state != _HWMOD_STATE_ENABLED &&
  2619. state != _HWMOD_STATE_IDLE)
  2620. return -EINVAL;
  2621. spin_lock_irqsave(&oh->_lock, flags);
  2622. if (oh->_state != _HWMOD_STATE_REGISTERED) {
  2623. ret = -EINVAL;
  2624. goto ohsps_unlock;
  2625. }
  2626. oh->_postsetup_state = state;
  2627. ret = 0;
  2628. ohsps_unlock:
  2629. spin_unlock_irqrestore(&oh->_lock, flags);
  2630. return ret;
  2631. }
  2632. /**
  2633. * omap_hwmod_get_context_loss_count - get lost context count
  2634. * @oh: struct omap_hwmod *
  2635. *
  2636. * Query the powerdomain of of @oh to get the context loss
  2637. * count for this device.
  2638. *
  2639. * Returns the context loss count of the powerdomain assocated with @oh
  2640. * upon success, or zero if no powerdomain exists for @oh.
  2641. */
  2642. int omap_hwmod_get_context_loss_count(struct omap_hwmod *oh)
  2643. {
  2644. struct powerdomain *pwrdm;
  2645. int ret = 0;
  2646. pwrdm = omap_hwmod_get_pwrdm(oh);
  2647. if (pwrdm)
  2648. ret = pwrdm_get_context_loss_count(pwrdm);
  2649. return ret;
  2650. }
  2651. /**
  2652. * omap_hwmod_no_setup_reset - prevent a hwmod from being reset upon setup
  2653. * @oh: struct omap_hwmod *
  2654. *
  2655. * Prevent the hwmod @oh from being reset during the setup process.
  2656. * Intended for use by board-*.c files on boards with devices that
  2657. * cannot tolerate being reset. Must be called before the hwmod has
  2658. * been set up. Returns 0 upon success or negative error code upon
  2659. * failure.
  2660. */
  2661. int omap_hwmod_no_setup_reset(struct omap_hwmod *oh)
  2662. {
  2663. if (!oh)
  2664. return -EINVAL;
  2665. if (oh->_state != _HWMOD_STATE_REGISTERED) {
  2666. pr_err("omap_hwmod: %s: cannot prevent setup reset; in wrong state\n",
  2667. oh->name);
  2668. return -EINVAL;
  2669. }
  2670. oh->flags |= HWMOD_INIT_NO_RESET;
  2671. return 0;
  2672. }
  2673. /**
  2674. * omap_hwmod_pad_route_irq - route an I/O pad wakeup to a particular MPU IRQ
  2675. * @oh: struct omap_hwmod * containing hwmod mux entries
  2676. * @pad_idx: array index in oh->mux of the hwmod mux entry to route wakeup
  2677. * @irq_idx: the hwmod mpu_irqs array index of the IRQ to trigger on wakeup
  2678. *
  2679. * When an I/O pad wakeup arrives for the dynamic or wakeup hwmod mux
  2680. * entry number @pad_idx for the hwmod @oh, trigger the interrupt
  2681. * service routine for the hwmod's mpu_irqs array index @irq_idx. If
  2682. * this function is not called for a given pad_idx, then the ISR
  2683. * associated with @oh's first MPU IRQ will be triggered when an I/O
  2684. * pad wakeup occurs on that pad. Note that @pad_idx is the index of
  2685. * the _dynamic or wakeup_ entry: if there are other entries not
  2686. * marked with OMAP_DEVICE_PAD_WAKEUP or OMAP_DEVICE_PAD_REMUX, these
  2687. * entries are NOT COUNTED in the dynamic pad index. This function
  2688. * must be called separately for each pad that requires its interrupt
  2689. * to be re-routed this way. Returns -EINVAL if there is an argument
  2690. * problem or if @oh does not have hwmod mux entries or MPU IRQs;
  2691. * returns -ENOMEM if memory cannot be allocated; or 0 upon success.
  2692. *
  2693. * XXX This function interface is fragile. Rather than using array
  2694. * indexes, which are subject to unpredictable change, it should be
  2695. * using hwmod IRQ names, and some other stable key for the hwmod mux
  2696. * pad records.
  2697. */
  2698. int omap_hwmod_pad_route_irq(struct omap_hwmod *oh, int pad_idx, int irq_idx)
  2699. {
  2700. int nr_irqs;
  2701. might_sleep();
  2702. if (!oh || !oh->mux || !oh->mpu_irqs || pad_idx < 0 ||
  2703. pad_idx >= oh->mux->nr_pads_dynamic)
  2704. return -EINVAL;
  2705. /* Check the number of available mpu_irqs */
  2706. for (nr_irqs = 0; oh->mpu_irqs[nr_irqs].irq >= 0; nr_irqs++)
  2707. ;
  2708. if (irq_idx >= nr_irqs)
  2709. return -EINVAL;
  2710. if (!oh->mux->irqs) {
  2711. /* XXX What frees this? */
  2712. oh->mux->irqs = kzalloc(sizeof(int) * oh->mux->nr_pads_dynamic,
  2713. GFP_KERNEL);
  2714. if (!oh->mux->irqs)
  2715. return -ENOMEM;
  2716. }
  2717. oh->mux->irqs[pad_idx] = irq_idx;
  2718. return 0;
  2719. }