omap_hwmod.c 87 KB

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