omap_hwmod.c 117 KB

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