omap_hwmod.c 99 KB

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