omap_hwmod.c 107 KB

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