omap_hwmod.c 115 KB

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