omap_hwmod.c 104 KB

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