omap2.c 142 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877
  1. /*
  2. * TI OMAP processors emulation.
  3. *
  4. * Copyright (C) 2007-2008 Nokia Corporation
  5. * Written by Andrzej Zaborowski <andrew@openedhand.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 or
  10. * (at your option) version 3 of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. #include "hw.h"
  22. #include "arm-misc.h"
  23. #include "omap.h"
  24. #include "sysemu.h"
  25. #include "qemu-timer.h"
  26. #include "qemu-char.h"
  27. #include "flash.h"
  28. #include "soc_dma.h"
  29. #include "audio/audio.h"
  30. /* GP timers */
  31. struct omap_gp_timer_s {
  32. qemu_irq irq;
  33. qemu_irq wkup;
  34. qemu_irq in;
  35. qemu_irq out;
  36. omap_clk clk;
  37. QEMUTimer *timer;
  38. QEMUTimer *match;
  39. struct omap_target_agent_s *ta;
  40. int in_val;
  41. int out_val;
  42. int64_t time;
  43. int64_t rate;
  44. int64_t ticks_per_sec;
  45. int16_t config;
  46. int status;
  47. int it_ena;
  48. int wu_ena;
  49. int enable;
  50. int inout;
  51. int capt2;
  52. int pt;
  53. enum {
  54. gpt_trigger_none, gpt_trigger_overflow, gpt_trigger_both
  55. } trigger;
  56. enum {
  57. gpt_capture_none, gpt_capture_rising,
  58. gpt_capture_falling, gpt_capture_both
  59. } capture;
  60. int scpwm;
  61. int ce;
  62. int pre;
  63. int ptv;
  64. int ar;
  65. int st;
  66. int posted;
  67. uint32_t val;
  68. uint32_t load_val;
  69. uint32_t capture_val[2];
  70. uint32_t match_val;
  71. int capt_num;
  72. uint16_t writeh; /* LSB */
  73. uint16_t readh; /* MSB */
  74. };
  75. #define GPT_TCAR_IT (1 << 2)
  76. #define GPT_OVF_IT (1 << 1)
  77. #define GPT_MAT_IT (1 << 0)
  78. static inline void omap_gp_timer_intr(struct omap_gp_timer_s *timer, int it)
  79. {
  80. if (timer->it_ena & it) {
  81. if (!timer->status)
  82. qemu_irq_raise(timer->irq);
  83. timer->status |= it;
  84. /* Or are the status bits set even when masked?
  85. * i.e. is masking applied before or after the status register? */
  86. }
  87. if (timer->wu_ena & it)
  88. qemu_irq_pulse(timer->wkup);
  89. }
  90. static inline void omap_gp_timer_out(struct omap_gp_timer_s *timer, int level)
  91. {
  92. if (!timer->inout && timer->out_val != level) {
  93. timer->out_val = level;
  94. qemu_set_irq(timer->out, level);
  95. }
  96. }
  97. static inline uint32_t omap_gp_timer_read(struct omap_gp_timer_s *timer)
  98. {
  99. uint64_t distance;
  100. if (timer->st && timer->rate) {
  101. distance = qemu_get_clock(vm_clock) - timer->time;
  102. distance = muldiv64(distance, timer->rate, timer->ticks_per_sec);
  103. if (distance >= 0xffffffff - timer->val)
  104. return 0xffffffff;
  105. else
  106. return timer->val + distance;
  107. } else
  108. return timer->val;
  109. }
  110. static inline void omap_gp_timer_sync(struct omap_gp_timer_s *timer)
  111. {
  112. if (timer->st) {
  113. timer->val = omap_gp_timer_read(timer);
  114. timer->time = qemu_get_clock(vm_clock);
  115. }
  116. }
  117. static inline void omap_gp_timer_update(struct omap_gp_timer_s *timer)
  118. {
  119. int64_t expires, matches;
  120. if (timer->st && timer->rate) {
  121. expires = muldiv64(0x100000000ll - timer->val,
  122. timer->ticks_per_sec, timer->rate);
  123. qemu_mod_timer(timer->timer, timer->time + expires);
  124. if (timer->ce && timer->match_val >= timer->val) {
  125. matches = muldiv64(timer->match_val - timer->val,
  126. timer->ticks_per_sec, timer->rate);
  127. qemu_mod_timer(timer->match, timer->time + matches);
  128. } else
  129. qemu_del_timer(timer->match);
  130. } else {
  131. qemu_del_timer(timer->timer);
  132. qemu_del_timer(timer->match);
  133. omap_gp_timer_out(timer, timer->scpwm);
  134. }
  135. }
  136. static inline void omap_gp_timer_trigger(struct omap_gp_timer_s *timer)
  137. {
  138. if (timer->pt)
  139. /* TODO in overflow-and-match mode if the first event to
  140. * occur is the match, don't toggle. */
  141. omap_gp_timer_out(timer, !timer->out_val);
  142. else
  143. /* TODO inverted pulse on timer->out_val == 1? */
  144. qemu_irq_pulse(timer->out);
  145. }
  146. static void omap_gp_timer_tick(void *opaque)
  147. {
  148. struct omap_gp_timer_s *timer = (struct omap_gp_timer_s *) opaque;
  149. if (!timer->ar) {
  150. timer->st = 0;
  151. timer->val = 0;
  152. } else {
  153. timer->val = timer->load_val;
  154. timer->time = qemu_get_clock(vm_clock);
  155. }
  156. if (timer->trigger == gpt_trigger_overflow ||
  157. timer->trigger == gpt_trigger_both)
  158. omap_gp_timer_trigger(timer);
  159. omap_gp_timer_intr(timer, GPT_OVF_IT);
  160. omap_gp_timer_update(timer);
  161. }
  162. static void omap_gp_timer_match(void *opaque)
  163. {
  164. struct omap_gp_timer_s *timer = (struct omap_gp_timer_s *) opaque;
  165. if (timer->trigger == gpt_trigger_both)
  166. omap_gp_timer_trigger(timer);
  167. omap_gp_timer_intr(timer, GPT_MAT_IT);
  168. }
  169. static void omap_gp_timer_input(void *opaque, int line, int on)
  170. {
  171. struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
  172. int trigger;
  173. switch (s->capture) {
  174. default:
  175. case gpt_capture_none:
  176. trigger = 0;
  177. break;
  178. case gpt_capture_rising:
  179. trigger = !s->in_val && on;
  180. break;
  181. case gpt_capture_falling:
  182. trigger = s->in_val && !on;
  183. break;
  184. case gpt_capture_both:
  185. trigger = (s->in_val == !on);
  186. break;
  187. }
  188. s->in_val = on;
  189. if (s->inout && trigger && s->capt_num < 2) {
  190. s->capture_val[s->capt_num] = omap_gp_timer_read(s);
  191. if (s->capt2 == s->capt_num ++)
  192. omap_gp_timer_intr(s, GPT_TCAR_IT);
  193. }
  194. }
  195. static void omap_gp_timer_clk_update(void *opaque, int line, int on)
  196. {
  197. struct omap_gp_timer_s *timer = (struct omap_gp_timer_s *) opaque;
  198. omap_gp_timer_sync(timer);
  199. timer->rate = on ? omap_clk_getrate(timer->clk) : 0;
  200. omap_gp_timer_update(timer);
  201. }
  202. static void omap_gp_timer_clk_setup(struct omap_gp_timer_s *timer)
  203. {
  204. omap_clk_adduser(timer->clk,
  205. qemu_allocate_irqs(omap_gp_timer_clk_update, timer, 1)[0]);
  206. timer->rate = omap_clk_getrate(timer->clk);
  207. }
  208. static void omap_gp_timer_reset(struct omap_gp_timer_s *s)
  209. {
  210. s->config = 0x000;
  211. s->status = 0;
  212. s->it_ena = 0;
  213. s->wu_ena = 0;
  214. s->inout = 0;
  215. s->capt2 = 0;
  216. s->capt_num = 0;
  217. s->pt = 0;
  218. s->trigger = gpt_trigger_none;
  219. s->capture = gpt_capture_none;
  220. s->scpwm = 0;
  221. s->ce = 0;
  222. s->pre = 0;
  223. s->ptv = 0;
  224. s->ar = 0;
  225. s->st = 0;
  226. s->posted = 1;
  227. s->val = 0x00000000;
  228. s->load_val = 0x00000000;
  229. s->capture_val[0] = 0x00000000;
  230. s->capture_val[1] = 0x00000000;
  231. s->match_val = 0x00000000;
  232. omap_gp_timer_update(s);
  233. }
  234. static uint32_t omap_gp_timer_readw(void *opaque, target_phys_addr_t addr)
  235. {
  236. struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
  237. switch (addr) {
  238. case 0x00: /* TIDR */
  239. return 0x21;
  240. case 0x10: /* TIOCP_CFG */
  241. return s->config;
  242. case 0x14: /* TISTAT */
  243. /* ??? When's this bit reset? */
  244. return 1; /* RESETDONE */
  245. case 0x18: /* TISR */
  246. return s->status;
  247. case 0x1c: /* TIER */
  248. return s->it_ena;
  249. case 0x20: /* TWER */
  250. return s->wu_ena;
  251. case 0x24: /* TCLR */
  252. return (s->inout << 14) |
  253. (s->capt2 << 13) |
  254. (s->pt << 12) |
  255. (s->trigger << 10) |
  256. (s->capture << 8) |
  257. (s->scpwm << 7) |
  258. (s->ce << 6) |
  259. (s->pre << 5) |
  260. (s->ptv << 2) |
  261. (s->ar << 1) |
  262. (s->st << 0);
  263. case 0x28: /* TCRR */
  264. return omap_gp_timer_read(s);
  265. case 0x2c: /* TLDR */
  266. return s->load_val;
  267. case 0x30: /* TTGR */
  268. return 0xffffffff;
  269. case 0x34: /* TWPS */
  270. return 0x00000000; /* No posted writes pending. */
  271. case 0x38: /* TMAR */
  272. return s->match_val;
  273. case 0x3c: /* TCAR1 */
  274. return s->capture_val[0];
  275. case 0x40: /* TSICR */
  276. return s->posted << 2;
  277. case 0x44: /* TCAR2 */
  278. return s->capture_val[1];
  279. }
  280. OMAP_BAD_REG(addr);
  281. return 0;
  282. }
  283. static uint32_t omap_gp_timer_readh(void *opaque, target_phys_addr_t addr)
  284. {
  285. struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
  286. uint32_t ret;
  287. if (addr & 2)
  288. return s->readh;
  289. else {
  290. ret = omap_gp_timer_readw(opaque, addr);
  291. s->readh = ret >> 16;
  292. return ret & 0xffff;
  293. }
  294. }
  295. static CPUReadMemoryFunc *omap_gp_timer_readfn[] = {
  296. omap_badwidth_read32,
  297. omap_gp_timer_readh,
  298. omap_gp_timer_readw,
  299. };
  300. static void omap_gp_timer_write(void *opaque, target_phys_addr_t addr,
  301. uint32_t value)
  302. {
  303. struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
  304. switch (addr) {
  305. case 0x00: /* TIDR */
  306. case 0x14: /* TISTAT */
  307. case 0x34: /* TWPS */
  308. case 0x3c: /* TCAR1 */
  309. case 0x44: /* TCAR2 */
  310. OMAP_RO_REG(addr);
  311. break;
  312. case 0x10: /* TIOCP_CFG */
  313. s->config = value & 0x33d;
  314. if (((value >> 3) & 3) == 3) /* IDLEMODE */
  315. fprintf(stderr, "%s: illegal IDLEMODE value in TIOCP_CFG\n",
  316. __FUNCTION__);
  317. if (value & 2) /* SOFTRESET */
  318. omap_gp_timer_reset(s);
  319. break;
  320. case 0x18: /* TISR */
  321. if (value & GPT_TCAR_IT)
  322. s->capt_num = 0;
  323. if (s->status && !(s->status &= ~value))
  324. qemu_irq_lower(s->irq);
  325. break;
  326. case 0x1c: /* TIER */
  327. s->it_ena = value & 7;
  328. break;
  329. case 0x20: /* TWER */
  330. s->wu_ena = value & 7;
  331. break;
  332. case 0x24: /* TCLR */
  333. omap_gp_timer_sync(s);
  334. s->inout = (value >> 14) & 1;
  335. s->capt2 = (value >> 13) & 1;
  336. s->pt = (value >> 12) & 1;
  337. s->trigger = (value >> 10) & 3;
  338. if (s->capture == gpt_capture_none &&
  339. ((value >> 8) & 3) != gpt_capture_none)
  340. s->capt_num = 0;
  341. s->capture = (value >> 8) & 3;
  342. s->scpwm = (value >> 7) & 1;
  343. s->ce = (value >> 6) & 1;
  344. s->pre = (value >> 5) & 1;
  345. s->ptv = (value >> 2) & 7;
  346. s->ar = (value >> 1) & 1;
  347. s->st = (value >> 0) & 1;
  348. if (s->inout && s->trigger != gpt_trigger_none)
  349. fprintf(stderr, "%s: GP timer pin must be an output "
  350. "for this trigger mode\n", __FUNCTION__);
  351. if (!s->inout && s->capture != gpt_capture_none)
  352. fprintf(stderr, "%s: GP timer pin must be an input "
  353. "for this capture mode\n", __FUNCTION__);
  354. if (s->trigger == gpt_trigger_none)
  355. omap_gp_timer_out(s, s->scpwm);
  356. /* TODO: make sure this doesn't overflow 32-bits */
  357. s->ticks_per_sec = ticks_per_sec << (s->pre ? s->ptv + 1 : 0);
  358. omap_gp_timer_update(s);
  359. break;
  360. case 0x28: /* TCRR */
  361. s->time = qemu_get_clock(vm_clock);
  362. s->val = value;
  363. omap_gp_timer_update(s);
  364. break;
  365. case 0x2c: /* TLDR */
  366. s->load_val = value;
  367. break;
  368. case 0x30: /* TTGR */
  369. s->time = qemu_get_clock(vm_clock);
  370. s->val = s->load_val;
  371. omap_gp_timer_update(s);
  372. break;
  373. case 0x38: /* TMAR */
  374. omap_gp_timer_sync(s);
  375. s->match_val = value;
  376. omap_gp_timer_update(s);
  377. break;
  378. case 0x40: /* TSICR */
  379. s->posted = (value >> 2) & 1;
  380. if (value & 2) /* How much exactly are we supposed to reset? */
  381. omap_gp_timer_reset(s);
  382. break;
  383. default:
  384. OMAP_BAD_REG(addr);
  385. }
  386. }
  387. static void omap_gp_timer_writeh(void *opaque, target_phys_addr_t addr,
  388. uint32_t value)
  389. {
  390. struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
  391. if (addr & 2)
  392. return omap_gp_timer_write(opaque, addr, (value << 16) | s->writeh);
  393. else
  394. s->writeh = (uint16_t) value;
  395. }
  396. static CPUWriteMemoryFunc *omap_gp_timer_writefn[] = {
  397. omap_badwidth_write32,
  398. omap_gp_timer_writeh,
  399. omap_gp_timer_write,
  400. };
  401. struct omap_gp_timer_s *omap_gp_timer_init(struct omap_target_agent_s *ta,
  402. qemu_irq irq, omap_clk fclk, omap_clk iclk)
  403. {
  404. int iomemtype;
  405. struct omap_gp_timer_s *s = (struct omap_gp_timer_s *)
  406. qemu_mallocz(sizeof(struct omap_gp_timer_s));
  407. s->ta = ta;
  408. s->irq = irq;
  409. s->clk = fclk;
  410. s->timer = qemu_new_timer(vm_clock, omap_gp_timer_tick, s);
  411. s->match = qemu_new_timer(vm_clock, omap_gp_timer_match, s);
  412. s->in = qemu_allocate_irqs(omap_gp_timer_input, s, 1)[0];
  413. omap_gp_timer_reset(s);
  414. omap_gp_timer_clk_setup(s);
  415. iomemtype = l4_register_io_memory(0, omap_gp_timer_readfn,
  416. omap_gp_timer_writefn, s);
  417. omap_l4_attach(ta, 0, iomemtype);
  418. return s;
  419. }
  420. /* 32-kHz Sync Timer of the OMAP2 */
  421. static uint32_t omap_synctimer_read(struct omap_synctimer_s *s) {
  422. return muldiv64(qemu_get_clock(vm_clock), 0x8000, ticks_per_sec);
  423. }
  424. static void omap_synctimer_reset(struct omap_synctimer_s *s)
  425. {
  426. s->val = omap_synctimer_read(s);
  427. }
  428. static uint32_t omap_synctimer_readw(void *opaque, target_phys_addr_t addr)
  429. {
  430. struct omap_synctimer_s *s = (struct omap_synctimer_s *) opaque;
  431. switch (addr) {
  432. case 0x00: /* 32KSYNCNT_REV */
  433. return 0x21;
  434. case 0x10: /* CR */
  435. return omap_synctimer_read(s) - s->val;
  436. }
  437. OMAP_BAD_REG(addr);
  438. return 0;
  439. }
  440. static uint32_t omap_synctimer_readh(void *opaque, target_phys_addr_t addr)
  441. {
  442. struct omap_synctimer_s *s = (struct omap_synctimer_s *) opaque;
  443. uint32_t ret;
  444. if (addr & 2)
  445. return s->readh;
  446. else {
  447. ret = omap_synctimer_readw(opaque, addr);
  448. s->readh = ret >> 16;
  449. return ret & 0xffff;
  450. }
  451. }
  452. static CPUReadMemoryFunc *omap_synctimer_readfn[] = {
  453. omap_badwidth_read32,
  454. omap_synctimer_readh,
  455. omap_synctimer_readw,
  456. };
  457. static void omap_synctimer_write(void *opaque, target_phys_addr_t addr,
  458. uint32_t value)
  459. {
  460. OMAP_BAD_REG(addr);
  461. }
  462. static CPUWriteMemoryFunc *omap_synctimer_writefn[] = {
  463. omap_badwidth_write32,
  464. omap_synctimer_write,
  465. omap_synctimer_write,
  466. };
  467. void omap_synctimer_init(struct omap_target_agent_s *ta,
  468. struct omap_mpu_state_s *mpu, omap_clk fclk, omap_clk iclk)
  469. {
  470. struct omap_synctimer_s *s = &mpu->synctimer;
  471. omap_synctimer_reset(s);
  472. omap_l4_attach(ta, 0, l4_register_io_memory(0,
  473. omap_synctimer_readfn, omap_synctimer_writefn, s));
  474. }
  475. /* General-Purpose Interface of OMAP2 */
  476. struct omap2_gpio_s {
  477. qemu_irq irq[2];
  478. qemu_irq wkup;
  479. qemu_irq *in;
  480. qemu_irq handler[32];
  481. uint8_t config[2];
  482. uint32_t inputs;
  483. uint32_t outputs;
  484. uint32_t dir;
  485. uint32_t level[2];
  486. uint32_t edge[2];
  487. uint32_t mask[2];
  488. uint32_t wumask;
  489. uint32_t ints[2];
  490. uint32_t debounce;
  491. uint8_t delay;
  492. };
  493. static inline void omap_gpio_module_int_update(struct omap2_gpio_s *s,
  494. int line)
  495. {
  496. qemu_set_irq(s->irq[line], s->ints[line] & s->mask[line]);
  497. }
  498. static void omap_gpio_module_wake(struct omap2_gpio_s *s, int line)
  499. {
  500. if (!(s->config[0] & (1 << 2))) /* ENAWAKEUP */
  501. return;
  502. if (!(s->config[0] & (3 << 3))) /* Force Idle */
  503. return;
  504. if (!(s->wumask & (1 << line)))
  505. return;
  506. qemu_irq_raise(s->wkup);
  507. }
  508. static inline void omap_gpio_module_out_update(struct omap2_gpio_s *s,
  509. uint32_t diff)
  510. {
  511. int ln;
  512. s->outputs ^= diff;
  513. diff &= ~s->dir;
  514. while ((ln = ffs(diff))) {
  515. ln --;
  516. qemu_set_irq(s->handler[ln], (s->outputs >> ln) & 1);
  517. diff &= ~(1 << ln);
  518. }
  519. }
  520. static void omap_gpio_module_level_update(struct omap2_gpio_s *s, int line)
  521. {
  522. s->ints[line] |= s->dir &
  523. ((s->inputs & s->level[1]) | (~s->inputs & s->level[0]));
  524. omap_gpio_module_int_update(s, line);
  525. }
  526. static inline void omap_gpio_module_int(struct omap2_gpio_s *s, int line)
  527. {
  528. s->ints[0] |= 1 << line;
  529. omap_gpio_module_int_update(s, 0);
  530. s->ints[1] |= 1 << line;
  531. omap_gpio_module_int_update(s, 1);
  532. omap_gpio_module_wake(s, line);
  533. }
  534. static void omap_gpio_module_set(void *opaque, int line, int level)
  535. {
  536. struct omap2_gpio_s *s = (struct omap2_gpio_s *) opaque;
  537. if (level) {
  538. if (s->dir & (1 << line) & ((~s->inputs & s->edge[0]) | s->level[1]))
  539. omap_gpio_module_int(s, line);
  540. s->inputs |= 1 << line;
  541. } else {
  542. if (s->dir & (1 << line) & ((s->inputs & s->edge[1]) | s->level[0]))
  543. omap_gpio_module_int(s, line);
  544. s->inputs &= ~(1 << line);
  545. }
  546. }
  547. static void omap_gpio_module_reset(struct omap2_gpio_s *s)
  548. {
  549. s->config[0] = 0;
  550. s->config[1] = 2;
  551. s->ints[0] = 0;
  552. s->ints[1] = 0;
  553. s->mask[0] = 0;
  554. s->mask[1] = 0;
  555. s->wumask = 0;
  556. s->dir = ~0;
  557. s->level[0] = 0;
  558. s->level[1] = 0;
  559. s->edge[0] = 0;
  560. s->edge[1] = 0;
  561. s->debounce = 0;
  562. s->delay = 0;
  563. }
  564. static uint32_t omap_gpio_module_read(void *opaque, target_phys_addr_t addr)
  565. {
  566. struct omap2_gpio_s *s = (struct omap2_gpio_s *) opaque;
  567. switch (addr) {
  568. case 0x00: /* GPIO_REVISION */
  569. return 0x18;
  570. case 0x10: /* GPIO_SYSCONFIG */
  571. return s->config[0];
  572. case 0x14: /* GPIO_SYSSTATUS */
  573. return 0x01;
  574. case 0x18: /* GPIO_IRQSTATUS1 */
  575. return s->ints[0];
  576. case 0x1c: /* GPIO_IRQENABLE1 */
  577. case 0x60: /* GPIO_CLEARIRQENABLE1 */
  578. case 0x64: /* GPIO_SETIRQENABLE1 */
  579. return s->mask[0];
  580. case 0x20: /* GPIO_WAKEUPENABLE */
  581. case 0x80: /* GPIO_CLEARWKUENA */
  582. case 0x84: /* GPIO_SETWKUENA */
  583. return s->wumask;
  584. case 0x28: /* GPIO_IRQSTATUS2 */
  585. return s->ints[1];
  586. case 0x2c: /* GPIO_IRQENABLE2 */
  587. case 0x70: /* GPIO_CLEARIRQENABLE2 */
  588. case 0x74: /* GPIO_SETIREQNEABLE2 */
  589. return s->mask[1];
  590. case 0x30: /* GPIO_CTRL */
  591. return s->config[1];
  592. case 0x34: /* GPIO_OE */
  593. return s->dir;
  594. case 0x38: /* GPIO_DATAIN */
  595. return s->inputs;
  596. case 0x3c: /* GPIO_DATAOUT */
  597. case 0x90: /* GPIO_CLEARDATAOUT */
  598. case 0x94: /* GPIO_SETDATAOUT */
  599. return s->outputs;
  600. case 0x40: /* GPIO_LEVELDETECT0 */
  601. return s->level[0];
  602. case 0x44: /* GPIO_LEVELDETECT1 */
  603. return s->level[1];
  604. case 0x48: /* GPIO_RISINGDETECT */
  605. return s->edge[0];
  606. case 0x4c: /* GPIO_FALLINGDETECT */
  607. return s->edge[1];
  608. case 0x50: /* GPIO_DEBOUNCENABLE */
  609. return s->debounce;
  610. case 0x54: /* GPIO_DEBOUNCINGTIME */
  611. return s->delay;
  612. }
  613. OMAP_BAD_REG(addr);
  614. return 0;
  615. }
  616. static void omap_gpio_module_write(void *opaque, target_phys_addr_t addr,
  617. uint32_t value)
  618. {
  619. struct omap2_gpio_s *s = (struct omap2_gpio_s *) opaque;
  620. uint32_t diff;
  621. int ln;
  622. switch (addr) {
  623. case 0x00: /* GPIO_REVISION */
  624. case 0x14: /* GPIO_SYSSTATUS */
  625. case 0x38: /* GPIO_DATAIN */
  626. OMAP_RO_REG(addr);
  627. break;
  628. case 0x10: /* GPIO_SYSCONFIG */
  629. if (((value >> 3) & 3) == 3)
  630. fprintf(stderr, "%s: bad IDLEMODE value\n", __FUNCTION__);
  631. if (value & 2)
  632. omap_gpio_module_reset(s);
  633. s->config[0] = value & 0x1d;
  634. break;
  635. case 0x18: /* GPIO_IRQSTATUS1 */
  636. if (s->ints[0] & value) {
  637. s->ints[0] &= ~value;
  638. omap_gpio_module_level_update(s, 0);
  639. }
  640. break;
  641. case 0x1c: /* GPIO_IRQENABLE1 */
  642. s->mask[0] = value;
  643. omap_gpio_module_int_update(s, 0);
  644. break;
  645. case 0x20: /* GPIO_WAKEUPENABLE */
  646. s->wumask = value;
  647. break;
  648. case 0x28: /* GPIO_IRQSTATUS2 */
  649. if (s->ints[1] & value) {
  650. s->ints[1] &= ~value;
  651. omap_gpio_module_level_update(s, 1);
  652. }
  653. break;
  654. case 0x2c: /* GPIO_IRQENABLE2 */
  655. s->mask[1] = value;
  656. omap_gpio_module_int_update(s, 1);
  657. break;
  658. case 0x30: /* GPIO_CTRL */
  659. s->config[1] = value & 7;
  660. break;
  661. case 0x34: /* GPIO_OE */
  662. diff = s->outputs & (s->dir ^ value);
  663. s->dir = value;
  664. value = s->outputs & ~s->dir;
  665. while ((ln = ffs(diff))) {
  666. diff &= ~(1 <<-- ln);
  667. qemu_set_irq(s->handler[ln], (value >> ln) & 1);
  668. }
  669. omap_gpio_module_level_update(s, 0);
  670. omap_gpio_module_level_update(s, 1);
  671. break;
  672. case 0x3c: /* GPIO_DATAOUT */
  673. omap_gpio_module_out_update(s, s->outputs ^ value);
  674. break;
  675. case 0x40: /* GPIO_LEVELDETECT0 */
  676. s->level[0] = value;
  677. omap_gpio_module_level_update(s, 0);
  678. omap_gpio_module_level_update(s, 1);
  679. break;
  680. case 0x44: /* GPIO_LEVELDETECT1 */
  681. s->level[1] = value;
  682. omap_gpio_module_level_update(s, 0);
  683. omap_gpio_module_level_update(s, 1);
  684. break;
  685. case 0x48: /* GPIO_RISINGDETECT */
  686. s->edge[0] = value;
  687. break;
  688. case 0x4c: /* GPIO_FALLINGDETECT */
  689. s->edge[1] = value;
  690. break;
  691. case 0x50: /* GPIO_DEBOUNCENABLE */
  692. s->debounce = value;
  693. break;
  694. case 0x54: /* GPIO_DEBOUNCINGTIME */
  695. s->delay = value;
  696. break;
  697. case 0x60: /* GPIO_CLEARIRQENABLE1 */
  698. s->mask[0] &= ~value;
  699. omap_gpio_module_int_update(s, 0);
  700. break;
  701. case 0x64: /* GPIO_SETIRQENABLE1 */
  702. s->mask[0] |= value;
  703. omap_gpio_module_int_update(s, 0);
  704. break;
  705. case 0x70: /* GPIO_CLEARIRQENABLE2 */
  706. s->mask[1] &= ~value;
  707. omap_gpio_module_int_update(s, 1);
  708. break;
  709. case 0x74: /* GPIO_SETIREQNEABLE2 */
  710. s->mask[1] |= value;
  711. omap_gpio_module_int_update(s, 1);
  712. break;
  713. case 0x80: /* GPIO_CLEARWKUENA */
  714. s->wumask &= ~value;
  715. break;
  716. case 0x84: /* GPIO_SETWKUENA */
  717. s->wumask |= value;
  718. break;
  719. case 0x90: /* GPIO_CLEARDATAOUT */
  720. omap_gpio_module_out_update(s, s->outputs & value);
  721. break;
  722. case 0x94: /* GPIO_SETDATAOUT */
  723. omap_gpio_module_out_update(s, ~s->outputs & value);
  724. break;
  725. default:
  726. OMAP_BAD_REG(addr);
  727. return;
  728. }
  729. }
  730. static uint32_t omap_gpio_module_readp(void *opaque, target_phys_addr_t addr)
  731. {
  732. return omap_gpio_module_readp(opaque, addr) >> ((addr & 3) << 3);
  733. }
  734. static void omap_gpio_module_writep(void *opaque, target_phys_addr_t addr,
  735. uint32_t value)
  736. {
  737. uint32_t cur = 0;
  738. uint32_t mask = 0xffff;
  739. switch (addr & ~3) {
  740. case 0x00: /* GPIO_REVISION */
  741. case 0x14: /* GPIO_SYSSTATUS */
  742. case 0x38: /* GPIO_DATAIN */
  743. OMAP_RO_REG(addr);
  744. break;
  745. case 0x10: /* GPIO_SYSCONFIG */
  746. case 0x1c: /* GPIO_IRQENABLE1 */
  747. case 0x20: /* GPIO_WAKEUPENABLE */
  748. case 0x2c: /* GPIO_IRQENABLE2 */
  749. case 0x30: /* GPIO_CTRL */
  750. case 0x34: /* GPIO_OE */
  751. case 0x3c: /* GPIO_DATAOUT */
  752. case 0x40: /* GPIO_LEVELDETECT0 */
  753. case 0x44: /* GPIO_LEVELDETECT1 */
  754. case 0x48: /* GPIO_RISINGDETECT */
  755. case 0x4c: /* GPIO_FALLINGDETECT */
  756. case 0x50: /* GPIO_DEBOUNCENABLE */
  757. case 0x54: /* GPIO_DEBOUNCINGTIME */
  758. cur = omap_gpio_module_read(opaque, addr & ~3) &
  759. ~(mask << ((addr & 3) << 3));
  760. /* Fall through. */
  761. case 0x18: /* GPIO_IRQSTATUS1 */
  762. case 0x28: /* GPIO_IRQSTATUS2 */
  763. case 0x60: /* GPIO_CLEARIRQENABLE1 */
  764. case 0x64: /* GPIO_SETIRQENABLE1 */
  765. case 0x70: /* GPIO_CLEARIRQENABLE2 */
  766. case 0x74: /* GPIO_SETIREQNEABLE2 */
  767. case 0x80: /* GPIO_CLEARWKUENA */
  768. case 0x84: /* GPIO_SETWKUENA */
  769. case 0x90: /* GPIO_CLEARDATAOUT */
  770. case 0x94: /* GPIO_SETDATAOUT */
  771. value <<= (addr & 3) << 3;
  772. omap_gpio_module_write(opaque, addr, cur | value);
  773. break;
  774. default:
  775. OMAP_BAD_REG(addr);
  776. return;
  777. }
  778. }
  779. static CPUReadMemoryFunc *omap_gpio_module_readfn[] = {
  780. omap_gpio_module_readp,
  781. omap_gpio_module_readp,
  782. omap_gpio_module_read,
  783. };
  784. static CPUWriteMemoryFunc *omap_gpio_module_writefn[] = {
  785. omap_gpio_module_writep,
  786. omap_gpio_module_writep,
  787. omap_gpio_module_write,
  788. };
  789. static void omap_gpio_module_init(struct omap2_gpio_s *s,
  790. struct omap_target_agent_s *ta, int region,
  791. qemu_irq mpu, qemu_irq dsp, qemu_irq wkup,
  792. omap_clk fclk, omap_clk iclk)
  793. {
  794. int iomemtype;
  795. s->irq[0] = mpu;
  796. s->irq[1] = dsp;
  797. s->wkup = wkup;
  798. s->in = qemu_allocate_irqs(omap_gpio_module_set, s, 32);
  799. iomemtype = l4_register_io_memory(0, omap_gpio_module_readfn,
  800. omap_gpio_module_writefn, s);
  801. omap_l4_attach(ta, region, iomemtype);
  802. }
  803. struct omap_gpif_s {
  804. struct omap2_gpio_s module[5];
  805. int modules;
  806. int autoidle;
  807. int gpo;
  808. };
  809. static void omap_gpif_reset(struct omap_gpif_s *s)
  810. {
  811. int i;
  812. for (i = 0; i < s->modules; i ++)
  813. omap_gpio_module_reset(s->module + i);
  814. s->autoidle = 0;
  815. s->gpo = 0;
  816. }
  817. static uint32_t omap_gpif_top_read(void *opaque, target_phys_addr_t addr)
  818. {
  819. struct omap_gpif_s *s = (struct omap_gpif_s *) opaque;
  820. switch (addr) {
  821. case 0x00: /* IPGENERICOCPSPL_REVISION */
  822. return 0x18;
  823. case 0x10: /* IPGENERICOCPSPL_SYSCONFIG */
  824. return s->autoidle;
  825. case 0x14: /* IPGENERICOCPSPL_SYSSTATUS */
  826. return 0x01;
  827. case 0x18: /* IPGENERICOCPSPL_IRQSTATUS */
  828. return 0x00;
  829. case 0x40: /* IPGENERICOCPSPL_GPO */
  830. return s->gpo;
  831. case 0x50: /* IPGENERICOCPSPL_GPI */
  832. return 0x00;
  833. }
  834. OMAP_BAD_REG(addr);
  835. return 0;
  836. }
  837. static void omap_gpif_top_write(void *opaque, target_phys_addr_t addr,
  838. uint32_t value)
  839. {
  840. struct omap_gpif_s *s = (struct omap_gpif_s *) opaque;
  841. switch (addr) {
  842. case 0x00: /* IPGENERICOCPSPL_REVISION */
  843. case 0x14: /* IPGENERICOCPSPL_SYSSTATUS */
  844. case 0x18: /* IPGENERICOCPSPL_IRQSTATUS */
  845. case 0x50: /* IPGENERICOCPSPL_GPI */
  846. OMAP_RO_REG(addr);
  847. break;
  848. case 0x10: /* IPGENERICOCPSPL_SYSCONFIG */
  849. if (value & (1 << 1)) /* SOFTRESET */
  850. omap_gpif_reset(s);
  851. s->autoidle = value & 1;
  852. break;
  853. case 0x40: /* IPGENERICOCPSPL_GPO */
  854. s->gpo = value & 1;
  855. break;
  856. default:
  857. OMAP_BAD_REG(addr);
  858. return;
  859. }
  860. }
  861. static CPUReadMemoryFunc *omap_gpif_top_readfn[] = {
  862. omap_gpif_top_read,
  863. omap_gpif_top_read,
  864. omap_gpif_top_read,
  865. };
  866. static CPUWriteMemoryFunc *omap_gpif_top_writefn[] = {
  867. omap_gpif_top_write,
  868. omap_gpif_top_write,
  869. omap_gpif_top_write,
  870. };
  871. struct omap_gpif_s *omap2_gpio_init(struct omap_target_agent_s *ta,
  872. qemu_irq *irq, omap_clk *fclk, omap_clk iclk, int modules)
  873. {
  874. int iomemtype, i;
  875. struct omap_gpif_s *s = (struct omap_gpif_s *)
  876. qemu_mallocz(sizeof(struct omap_gpif_s));
  877. int region[4] = { 0, 2, 4, 5 };
  878. s->modules = modules;
  879. for (i = 0; i < modules; i ++)
  880. omap_gpio_module_init(s->module + i, ta, region[i],
  881. irq[i], 0, 0, fclk[i], iclk);
  882. omap_gpif_reset(s);
  883. iomemtype = l4_register_io_memory(0, omap_gpif_top_readfn,
  884. omap_gpif_top_writefn, s);
  885. omap_l4_attach(ta, 1, iomemtype);
  886. return s;
  887. }
  888. qemu_irq *omap2_gpio_in_get(struct omap_gpif_s *s, int start)
  889. {
  890. if (start >= s->modules * 32 || start < 0)
  891. cpu_abort(cpu_single_env, "%s: No GPIO line %i\n",
  892. __FUNCTION__, start);
  893. return s->module[start >> 5].in + (start & 31);
  894. }
  895. void omap2_gpio_out_set(struct omap_gpif_s *s, int line, qemu_irq handler)
  896. {
  897. if (line >= s->modules * 32 || line < 0)
  898. cpu_abort(cpu_single_env, "%s: No GPIO line %i\n", __FUNCTION__, line);
  899. s->module[line >> 5].handler[line & 31] = handler;
  900. }
  901. /* Multichannel SPI */
  902. struct omap_mcspi_s {
  903. qemu_irq irq;
  904. int chnum;
  905. uint32_t sysconfig;
  906. uint32_t systest;
  907. uint32_t irqst;
  908. uint32_t irqen;
  909. uint32_t wken;
  910. uint32_t control;
  911. struct omap_mcspi_ch_s {
  912. qemu_irq txdrq;
  913. qemu_irq rxdrq;
  914. uint32_t (*txrx)(void *opaque, uint32_t, int);
  915. void *opaque;
  916. uint32_t tx;
  917. uint32_t rx;
  918. uint32_t config;
  919. uint32_t status;
  920. uint32_t control;
  921. } ch[4];
  922. };
  923. static inline void omap_mcspi_interrupt_update(struct omap_mcspi_s *s)
  924. {
  925. qemu_set_irq(s->irq, s->irqst & s->irqen);
  926. }
  927. static inline void omap_mcspi_dmarequest_update(struct omap_mcspi_ch_s *ch)
  928. {
  929. qemu_set_irq(ch->txdrq,
  930. (ch->control & 1) && /* EN */
  931. (ch->config & (1 << 14)) && /* DMAW */
  932. (ch->status & (1 << 1)) && /* TXS */
  933. ((ch->config >> 12) & 3) != 1); /* TRM */
  934. qemu_set_irq(ch->rxdrq,
  935. (ch->control & 1) && /* EN */
  936. (ch->config & (1 << 15)) && /* DMAW */
  937. (ch->status & (1 << 0)) && /* RXS */
  938. ((ch->config >> 12) & 3) != 2); /* TRM */
  939. }
  940. static void omap_mcspi_transfer_run(struct omap_mcspi_s *s, int chnum)
  941. {
  942. struct omap_mcspi_ch_s *ch = s->ch + chnum;
  943. if (!(ch->control & 1)) /* EN */
  944. return;
  945. if ((ch->status & (1 << 0)) && /* RXS */
  946. ((ch->config >> 12) & 3) != 2 && /* TRM */
  947. !(ch->config & (1 << 19))) /* TURBO */
  948. goto intr_update;
  949. if ((ch->status & (1 << 1)) && /* TXS */
  950. ((ch->config >> 12) & 3) != 1) /* TRM */
  951. goto intr_update;
  952. if (!(s->control & 1) || /* SINGLE */
  953. (ch->config & (1 << 20))) { /* FORCE */
  954. if (ch->txrx)
  955. ch->rx = ch->txrx(ch->opaque, ch->tx, /* WL */
  956. 1 + (0x1f & (ch->config >> 7)));
  957. }
  958. ch->tx = 0;
  959. ch->status |= 1 << 2; /* EOT */
  960. ch->status |= 1 << 1; /* TXS */
  961. if (((ch->config >> 12) & 3) != 2) /* TRM */
  962. ch->status |= 1 << 0; /* RXS */
  963. intr_update:
  964. if ((ch->status & (1 << 0)) && /* RXS */
  965. ((ch->config >> 12) & 3) != 2 && /* TRM */
  966. !(ch->config & (1 << 19))) /* TURBO */
  967. s->irqst |= 1 << (2 + 4 * chnum); /* RX_FULL */
  968. if ((ch->status & (1 << 1)) && /* TXS */
  969. ((ch->config >> 12) & 3) != 1) /* TRM */
  970. s->irqst |= 1 << (0 + 4 * chnum); /* TX_EMPTY */
  971. omap_mcspi_interrupt_update(s);
  972. omap_mcspi_dmarequest_update(ch);
  973. }
  974. static void omap_mcspi_reset(struct omap_mcspi_s *s)
  975. {
  976. int ch;
  977. s->sysconfig = 0;
  978. s->systest = 0;
  979. s->irqst = 0;
  980. s->irqen = 0;
  981. s->wken = 0;
  982. s->control = 4;
  983. for (ch = 0; ch < 4; ch ++) {
  984. s->ch[ch].config = 0x060000;
  985. s->ch[ch].status = 2; /* TXS */
  986. s->ch[ch].control = 0;
  987. omap_mcspi_dmarequest_update(s->ch + ch);
  988. }
  989. omap_mcspi_interrupt_update(s);
  990. }
  991. static uint32_t omap_mcspi_read(void *opaque, target_phys_addr_t addr)
  992. {
  993. struct omap_mcspi_s *s = (struct omap_mcspi_s *) opaque;
  994. int ch = 0;
  995. uint32_t ret;
  996. switch (addr) {
  997. case 0x00: /* MCSPI_REVISION */
  998. return 0x91;
  999. case 0x10: /* MCSPI_SYSCONFIG */
  1000. return s->sysconfig;
  1001. case 0x14: /* MCSPI_SYSSTATUS */
  1002. return 1; /* RESETDONE */
  1003. case 0x18: /* MCSPI_IRQSTATUS */
  1004. return s->irqst;
  1005. case 0x1c: /* MCSPI_IRQENABLE */
  1006. return s->irqen;
  1007. case 0x20: /* MCSPI_WAKEUPENABLE */
  1008. return s->wken;
  1009. case 0x24: /* MCSPI_SYST */
  1010. return s->systest;
  1011. case 0x28: /* MCSPI_MODULCTRL */
  1012. return s->control;
  1013. case 0x68: ch ++;
  1014. case 0x54: ch ++;
  1015. case 0x40: ch ++;
  1016. case 0x2c: /* MCSPI_CHCONF */
  1017. return s->ch[ch].config;
  1018. case 0x6c: ch ++;
  1019. case 0x58: ch ++;
  1020. case 0x44: ch ++;
  1021. case 0x30: /* MCSPI_CHSTAT */
  1022. return s->ch[ch].status;
  1023. case 0x70: ch ++;
  1024. case 0x5c: ch ++;
  1025. case 0x48: ch ++;
  1026. case 0x34: /* MCSPI_CHCTRL */
  1027. return s->ch[ch].control;
  1028. case 0x74: ch ++;
  1029. case 0x60: ch ++;
  1030. case 0x4c: ch ++;
  1031. case 0x38: /* MCSPI_TX */
  1032. return s->ch[ch].tx;
  1033. case 0x78: ch ++;
  1034. case 0x64: ch ++;
  1035. case 0x50: ch ++;
  1036. case 0x3c: /* MCSPI_RX */
  1037. s->ch[ch].status &= ~(1 << 0); /* RXS */
  1038. ret = s->ch[ch].rx;
  1039. omap_mcspi_transfer_run(s, ch);
  1040. return ret;
  1041. }
  1042. OMAP_BAD_REG(addr);
  1043. return 0;
  1044. }
  1045. static void omap_mcspi_write(void *opaque, target_phys_addr_t addr,
  1046. uint32_t value)
  1047. {
  1048. struct omap_mcspi_s *s = (struct omap_mcspi_s *) opaque;
  1049. int ch = 0;
  1050. switch (addr) {
  1051. case 0x00: /* MCSPI_REVISION */
  1052. case 0x14: /* MCSPI_SYSSTATUS */
  1053. case 0x30: /* MCSPI_CHSTAT0 */
  1054. case 0x3c: /* MCSPI_RX0 */
  1055. case 0x44: /* MCSPI_CHSTAT1 */
  1056. case 0x50: /* MCSPI_RX1 */
  1057. case 0x58: /* MCSPI_CHSTAT2 */
  1058. case 0x64: /* MCSPI_RX2 */
  1059. case 0x6c: /* MCSPI_CHSTAT3 */
  1060. case 0x78: /* MCSPI_RX3 */
  1061. OMAP_RO_REG(addr);
  1062. return;
  1063. case 0x10: /* MCSPI_SYSCONFIG */
  1064. if (value & (1 << 1)) /* SOFTRESET */
  1065. omap_mcspi_reset(s);
  1066. s->sysconfig = value & 0x31d;
  1067. break;
  1068. case 0x18: /* MCSPI_IRQSTATUS */
  1069. if (!((s->control & (1 << 3)) && (s->systest & (1 << 11)))) {
  1070. s->irqst &= ~value;
  1071. omap_mcspi_interrupt_update(s);
  1072. }
  1073. break;
  1074. case 0x1c: /* MCSPI_IRQENABLE */
  1075. s->irqen = value & 0x1777f;
  1076. omap_mcspi_interrupt_update(s);
  1077. break;
  1078. case 0x20: /* MCSPI_WAKEUPENABLE */
  1079. s->wken = value & 1;
  1080. break;
  1081. case 0x24: /* MCSPI_SYST */
  1082. if (s->control & (1 << 3)) /* SYSTEM_TEST */
  1083. if (value & (1 << 11)) { /* SSB */
  1084. s->irqst |= 0x1777f;
  1085. omap_mcspi_interrupt_update(s);
  1086. }
  1087. s->systest = value & 0xfff;
  1088. break;
  1089. case 0x28: /* MCSPI_MODULCTRL */
  1090. if (value & (1 << 3)) /* SYSTEM_TEST */
  1091. if (s->systest & (1 << 11)) { /* SSB */
  1092. s->irqst |= 0x1777f;
  1093. omap_mcspi_interrupt_update(s);
  1094. }
  1095. s->control = value & 0xf;
  1096. break;
  1097. case 0x68: ch ++;
  1098. case 0x54: ch ++;
  1099. case 0x40: ch ++;
  1100. case 0x2c: /* MCSPI_CHCONF */
  1101. if ((value ^ s->ch[ch].config) & (3 << 14)) /* DMAR | DMAW */
  1102. omap_mcspi_dmarequest_update(s->ch + ch);
  1103. if (((value >> 12) & 3) == 3) /* TRM */
  1104. fprintf(stderr, "%s: invalid TRM value (3)\n", __FUNCTION__);
  1105. if (((value >> 7) & 0x1f) < 3) /* WL */
  1106. fprintf(stderr, "%s: invalid WL value (%i)\n",
  1107. __FUNCTION__, (value >> 7) & 0x1f);
  1108. s->ch[ch].config = value & 0x7fffff;
  1109. break;
  1110. case 0x70: ch ++;
  1111. case 0x5c: ch ++;
  1112. case 0x48: ch ++;
  1113. case 0x34: /* MCSPI_CHCTRL */
  1114. if (value & ~s->ch[ch].control & 1) { /* EN */
  1115. s->ch[ch].control |= 1;
  1116. omap_mcspi_transfer_run(s, ch);
  1117. } else
  1118. s->ch[ch].control = value & 1;
  1119. break;
  1120. case 0x74: ch ++;
  1121. case 0x60: ch ++;
  1122. case 0x4c: ch ++;
  1123. case 0x38: /* MCSPI_TX */
  1124. s->ch[ch].tx = value;
  1125. s->ch[ch].status &= ~(1 << 1); /* TXS */
  1126. omap_mcspi_transfer_run(s, ch);
  1127. break;
  1128. default:
  1129. OMAP_BAD_REG(addr);
  1130. return;
  1131. }
  1132. }
  1133. static CPUReadMemoryFunc *omap_mcspi_readfn[] = {
  1134. omap_badwidth_read32,
  1135. omap_badwidth_read32,
  1136. omap_mcspi_read,
  1137. };
  1138. static CPUWriteMemoryFunc *omap_mcspi_writefn[] = {
  1139. omap_badwidth_write32,
  1140. omap_badwidth_write32,
  1141. omap_mcspi_write,
  1142. };
  1143. struct omap_mcspi_s *omap_mcspi_init(struct omap_target_agent_s *ta, int chnum,
  1144. qemu_irq irq, qemu_irq *drq, omap_clk fclk, omap_clk iclk)
  1145. {
  1146. int iomemtype;
  1147. struct omap_mcspi_s *s = (struct omap_mcspi_s *)
  1148. qemu_mallocz(sizeof(struct omap_mcspi_s));
  1149. struct omap_mcspi_ch_s *ch = s->ch;
  1150. s->irq = irq;
  1151. s->chnum = chnum;
  1152. while (chnum --) {
  1153. ch->txdrq = *drq ++;
  1154. ch->rxdrq = *drq ++;
  1155. ch ++;
  1156. }
  1157. omap_mcspi_reset(s);
  1158. iomemtype = l4_register_io_memory(0, omap_mcspi_readfn,
  1159. omap_mcspi_writefn, s);
  1160. omap_l4_attach(ta, 0, iomemtype);
  1161. return s;
  1162. }
  1163. void omap_mcspi_attach(struct omap_mcspi_s *s,
  1164. uint32_t (*txrx)(void *opaque, uint32_t, int), void *opaque,
  1165. int chipselect)
  1166. {
  1167. if (chipselect < 0 || chipselect >= s->chnum)
  1168. cpu_abort(cpu_single_env, "%s: Bad chipselect %i\n",
  1169. __FUNCTION__, chipselect);
  1170. s->ch[chipselect].txrx = txrx;
  1171. s->ch[chipselect].opaque = opaque;
  1172. }
  1173. /* Enhanced Audio Controller (CODEC only) */
  1174. struct omap_eac_s {
  1175. qemu_irq irq;
  1176. uint16_t sysconfig;
  1177. uint8_t config[4];
  1178. uint8_t control;
  1179. uint8_t address;
  1180. uint16_t data;
  1181. uint8_t vtol;
  1182. uint8_t vtsl;
  1183. uint16_t mixer;
  1184. uint16_t gain[4];
  1185. uint8_t att;
  1186. uint16_t max[7];
  1187. struct {
  1188. qemu_irq txdrq;
  1189. qemu_irq rxdrq;
  1190. uint32_t (*txrx)(void *opaque, uint32_t, int);
  1191. void *opaque;
  1192. #define EAC_BUF_LEN 1024
  1193. uint32_t rxbuf[EAC_BUF_LEN];
  1194. int rxoff;
  1195. int rxlen;
  1196. int rxavail;
  1197. uint32_t txbuf[EAC_BUF_LEN];
  1198. int txlen;
  1199. int txavail;
  1200. int enable;
  1201. int rate;
  1202. uint16_t config[4];
  1203. /* These need to be moved to the actual codec */
  1204. QEMUSoundCard card;
  1205. SWVoiceIn *in_voice;
  1206. SWVoiceOut *out_voice;
  1207. int hw_enable;
  1208. } codec;
  1209. struct {
  1210. uint8_t control;
  1211. uint16_t config;
  1212. } modem, bt;
  1213. };
  1214. static inline void omap_eac_interrupt_update(struct omap_eac_s *s)
  1215. {
  1216. qemu_set_irq(s->irq, (s->codec.config[1] >> 14) & 1); /* AURDI */
  1217. }
  1218. static inline void omap_eac_in_dmarequest_update(struct omap_eac_s *s)
  1219. {
  1220. qemu_set_irq(s->codec.rxdrq, (s->codec.rxavail || s->codec.rxlen) &&
  1221. ((s->codec.config[1] >> 12) & 1)); /* DMAREN */
  1222. }
  1223. static inline void omap_eac_out_dmarequest_update(struct omap_eac_s *s)
  1224. {
  1225. qemu_set_irq(s->codec.txdrq, s->codec.txlen < s->codec.txavail &&
  1226. ((s->codec.config[1] >> 11) & 1)); /* DMAWEN */
  1227. }
  1228. static inline void omap_eac_in_refill(struct omap_eac_s *s)
  1229. {
  1230. int left = MIN(EAC_BUF_LEN - s->codec.rxlen, s->codec.rxavail) << 2;
  1231. int start = ((s->codec.rxoff + s->codec.rxlen) & (EAC_BUF_LEN - 1)) << 2;
  1232. int leftwrap = MIN(left, (EAC_BUF_LEN << 2) - start);
  1233. int recv = 1;
  1234. uint8_t *buf = (uint8_t *) s->codec.rxbuf + start;
  1235. left -= leftwrap;
  1236. start = 0;
  1237. while (leftwrap && (recv = AUD_read(s->codec.in_voice, buf + start,
  1238. leftwrap)) > 0) { /* Be defensive */
  1239. start += recv;
  1240. leftwrap -= recv;
  1241. }
  1242. if (recv <= 0)
  1243. s->codec.rxavail = 0;
  1244. else
  1245. s->codec.rxavail -= start >> 2;
  1246. s->codec.rxlen += start >> 2;
  1247. if (recv > 0 && left > 0) {
  1248. start = 0;
  1249. while (left && (recv = AUD_read(s->codec.in_voice,
  1250. (uint8_t *) s->codec.rxbuf + start,
  1251. left)) > 0) { /* Be defensive */
  1252. start += recv;
  1253. left -= recv;
  1254. }
  1255. if (recv <= 0)
  1256. s->codec.rxavail = 0;
  1257. else
  1258. s->codec.rxavail -= start >> 2;
  1259. s->codec.rxlen += start >> 2;
  1260. }
  1261. }
  1262. static inline void omap_eac_out_empty(struct omap_eac_s *s)
  1263. {
  1264. int left = s->codec.txlen << 2;
  1265. int start = 0;
  1266. int sent = 1;
  1267. while (left && (sent = AUD_write(s->codec.out_voice,
  1268. (uint8_t *) s->codec.txbuf + start,
  1269. left)) > 0) { /* Be defensive */
  1270. start += sent;
  1271. left -= sent;
  1272. }
  1273. if (!sent) {
  1274. s->codec.txavail = 0;
  1275. omap_eac_out_dmarequest_update(s);
  1276. }
  1277. if (start)
  1278. s->codec.txlen = 0;
  1279. }
  1280. static void omap_eac_in_cb(void *opaque, int avail_b)
  1281. {
  1282. struct omap_eac_s *s = (struct omap_eac_s *) opaque;
  1283. s->codec.rxavail = avail_b >> 2;
  1284. omap_eac_in_refill(s);
  1285. /* TODO: possibly discard current buffer if overrun */
  1286. omap_eac_in_dmarequest_update(s);
  1287. }
  1288. static void omap_eac_out_cb(void *opaque, int free_b)
  1289. {
  1290. struct omap_eac_s *s = (struct omap_eac_s *) opaque;
  1291. s->codec.txavail = free_b >> 2;
  1292. if (s->codec.txlen)
  1293. omap_eac_out_empty(s);
  1294. else
  1295. omap_eac_out_dmarequest_update(s);
  1296. }
  1297. static void omap_eac_enable_update(struct omap_eac_s *s)
  1298. {
  1299. s->codec.enable = !(s->codec.config[1] & 1) && /* EACPWD */
  1300. (s->codec.config[1] & 2) && /* AUDEN */
  1301. s->codec.hw_enable;
  1302. }
  1303. static const int omap_eac_fsint[4] = {
  1304. 8000,
  1305. 11025,
  1306. 22050,
  1307. 44100,
  1308. };
  1309. static const int omap_eac_fsint2[8] = {
  1310. 8000,
  1311. 11025,
  1312. 22050,
  1313. 44100,
  1314. 48000,
  1315. 0, 0, 0,
  1316. };
  1317. static const int omap_eac_fsint3[16] = {
  1318. 8000,
  1319. 11025,
  1320. 16000,
  1321. 22050,
  1322. 24000,
  1323. 32000,
  1324. 44100,
  1325. 48000,
  1326. 0, 0, 0, 0, 0, 0, 0, 0,
  1327. };
  1328. static void omap_eac_rate_update(struct omap_eac_s *s)
  1329. {
  1330. int fsint[3];
  1331. fsint[2] = (s->codec.config[3] >> 9) & 0xf;
  1332. fsint[1] = (s->codec.config[2] >> 0) & 0x7;
  1333. fsint[0] = (s->codec.config[0] >> 6) & 0x3;
  1334. if (fsint[2] < 0xf)
  1335. s->codec.rate = omap_eac_fsint3[fsint[2]];
  1336. else if (fsint[1] < 0x7)
  1337. s->codec.rate = omap_eac_fsint2[fsint[1]];
  1338. else
  1339. s->codec.rate = omap_eac_fsint[fsint[0]];
  1340. }
  1341. static void omap_eac_volume_update(struct omap_eac_s *s)
  1342. {
  1343. /* TODO */
  1344. }
  1345. static void omap_eac_format_update(struct omap_eac_s *s)
  1346. {
  1347. struct audsettings fmt;
  1348. /* The hardware buffers at most one sample */
  1349. if (s->codec.rxlen)
  1350. s->codec.rxlen = 1;
  1351. if (s->codec.in_voice) {
  1352. AUD_set_active_in(s->codec.in_voice, 0);
  1353. AUD_close_in(&s->codec.card, s->codec.in_voice);
  1354. s->codec.in_voice = 0;
  1355. }
  1356. if (s->codec.out_voice) {
  1357. omap_eac_out_empty(s);
  1358. AUD_set_active_out(s->codec.out_voice, 0);
  1359. AUD_close_out(&s->codec.card, s->codec.out_voice);
  1360. s->codec.out_voice = 0;
  1361. s->codec.txavail = 0;
  1362. }
  1363. /* Discard what couldn't be written */
  1364. s->codec.txlen = 0;
  1365. omap_eac_enable_update(s);
  1366. if (!s->codec.enable)
  1367. return;
  1368. omap_eac_rate_update(s);
  1369. fmt.endianness = ((s->codec.config[0] >> 8) & 1); /* LI_BI */
  1370. fmt.nchannels = ((s->codec.config[0] >> 10) & 1) ? 2 : 1; /* MN_ST */
  1371. fmt.freq = s->codec.rate;
  1372. /* TODO: signedness possibly depends on the CODEC hardware - or
  1373. * does I2S specify it? */
  1374. /* All register writes are 16 bits so we we store 16-bit samples
  1375. * in the buffers regardless of AGCFR[B8_16] value. */
  1376. fmt.fmt = AUD_FMT_U16;
  1377. s->codec.in_voice = AUD_open_in(&s->codec.card, s->codec.in_voice,
  1378. "eac.codec.in", s, omap_eac_in_cb, &fmt);
  1379. s->codec.out_voice = AUD_open_out(&s->codec.card, s->codec.out_voice,
  1380. "eac.codec.out", s, omap_eac_out_cb, &fmt);
  1381. omap_eac_volume_update(s);
  1382. AUD_set_active_in(s->codec.in_voice, 1);
  1383. AUD_set_active_out(s->codec.out_voice, 1);
  1384. }
  1385. static void omap_eac_reset(struct omap_eac_s *s)
  1386. {
  1387. s->sysconfig = 0;
  1388. s->config[0] = 0x0c;
  1389. s->config[1] = 0x09;
  1390. s->config[2] = 0xab;
  1391. s->config[3] = 0x03;
  1392. s->control = 0x00;
  1393. s->address = 0x00;
  1394. s->data = 0x0000;
  1395. s->vtol = 0x00;
  1396. s->vtsl = 0x00;
  1397. s->mixer = 0x0000;
  1398. s->gain[0] = 0xe7e7;
  1399. s->gain[1] = 0x6767;
  1400. s->gain[2] = 0x6767;
  1401. s->gain[3] = 0x6767;
  1402. s->att = 0xce;
  1403. s->max[0] = 0;
  1404. s->max[1] = 0;
  1405. s->max[2] = 0;
  1406. s->max[3] = 0;
  1407. s->max[4] = 0;
  1408. s->max[5] = 0;
  1409. s->max[6] = 0;
  1410. s->modem.control = 0x00;
  1411. s->modem.config = 0x0000;
  1412. s->bt.control = 0x00;
  1413. s->bt.config = 0x0000;
  1414. s->codec.config[0] = 0x0649;
  1415. s->codec.config[1] = 0x0000;
  1416. s->codec.config[2] = 0x0007;
  1417. s->codec.config[3] = 0x1ffc;
  1418. s->codec.rxoff = 0;
  1419. s->codec.rxlen = 0;
  1420. s->codec.txlen = 0;
  1421. s->codec.rxavail = 0;
  1422. s->codec.txavail = 0;
  1423. omap_eac_format_update(s);
  1424. omap_eac_interrupt_update(s);
  1425. }
  1426. static uint32_t omap_eac_read(void *opaque, target_phys_addr_t addr)
  1427. {
  1428. struct omap_eac_s *s = (struct omap_eac_s *) opaque;
  1429. uint32_t ret;
  1430. switch (addr) {
  1431. case 0x000: /* CPCFR1 */
  1432. return s->config[0];
  1433. case 0x004: /* CPCFR2 */
  1434. return s->config[1];
  1435. case 0x008: /* CPCFR3 */
  1436. return s->config[2];
  1437. case 0x00c: /* CPCFR4 */
  1438. return s->config[3];
  1439. case 0x010: /* CPTCTL */
  1440. return s->control | ((s->codec.rxavail + s->codec.rxlen > 0) << 7) |
  1441. ((s->codec.txlen < s->codec.txavail) << 5);
  1442. case 0x014: /* CPTTADR */
  1443. return s->address;
  1444. case 0x018: /* CPTDATL */
  1445. return s->data & 0xff;
  1446. case 0x01c: /* CPTDATH */
  1447. return s->data >> 8;
  1448. case 0x020: /* CPTVSLL */
  1449. return s->vtol;
  1450. case 0x024: /* CPTVSLH */
  1451. return s->vtsl | (3 << 5); /* CRDY1 | CRDY2 */
  1452. case 0x040: /* MPCTR */
  1453. return s->modem.control;
  1454. case 0x044: /* MPMCCFR */
  1455. return s->modem.config;
  1456. case 0x060: /* BPCTR */
  1457. return s->bt.control;
  1458. case 0x064: /* BPMCCFR */
  1459. return s->bt.config;
  1460. case 0x080: /* AMSCFR */
  1461. return s->mixer;
  1462. case 0x084: /* AMVCTR */
  1463. return s->gain[0];
  1464. case 0x088: /* AM1VCTR */
  1465. return s->gain[1];
  1466. case 0x08c: /* AM2VCTR */
  1467. return s->gain[2];
  1468. case 0x090: /* AM3VCTR */
  1469. return s->gain[3];
  1470. case 0x094: /* ASTCTR */
  1471. return s->att;
  1472. case 0x098: /* APD1LCR */
  1473. return s->max[0];
  1474. case 0x09c: /* APD1RCR */
  1475. return s->max[1];
  1476. case 0x0a0: /* APD2LCR */
  1477. return s->max[2];
  1478. case 0x0a4: /* APD2RCR */
  1479. return s->max[3];
  1480. case 0x0a8: /* APD3LCR */
  1481. return s->max[4];
  1482. case 0x0ac: /* APD3RCR */
  1483. return s->max[5];
  1484. case 0x0b0: /* APD4R */
  1485. return s->max[6];
  1486. case 0x0b4: /* ADWR */
  1487. /* This should be write-only? Docs list it as read-only. */
  1488. return 0x0000;
  1489. case 0x0b8: /* ADRDR */
  1490. if (likely(s->codec.rxlen > 1)) {
  1491. ret = s->codec.rxbuf[s->codec.rxoff ++];
  1492. s->codec.rxlen --;
  1493. s->codec.rxoff &= EAC_BUF_LEN - 1;
  1494. return ret;
  1495. } else if (s->codec.rxlen) {
  1496. ret = s->codec.rxbuf[s->codec.rxoff ++];
  1497. s->codec.rxlen --;
  1498. s->codec.rxoff &= EAC_BUF_LEN - 1;
  1499. if (s->codec.rxavail)
  1500. omap_eac_in_refill(s);
  1501. omap_eac_in_dmarequest_update(s);
  1502. return ret;
  1503. }
  1504. return 0x0000;
  1505. case 0x0bc: /* AGCFR */
  1506. return s->codec.config[0];
  1507. case 0x0c0: /* AGCTR */
  1508. return s->codec.config[1] | ((s->codec.config[1] & 2) << 14);
  1509. case 0x0c4: /* AGCFR2 */
  1510. return s->codec.config[2];
  1511. case 0x0c8: /* AGCFR3 */
  1512. return s->codec.config[3];
  1513. case 0x0cc: /* MBPDMACTR */
  1514. case 0x0d0: /* MPDDMARR */
  1515. case 0x0d8: /* MPUDMARR */
  1516. case 0x0e4: /* BPDDMARR */
  1517. case 0x0ec: /* BPUDMARR */
  1518. return 0x0000;
  1519. case 0x100: /* VERSION_NUMBER */
  1520. return 0x0010;
  1521. case 0x104: /* SYSCONFIG */
  1522. return s->sysconfig;
  1523. case 0x108: /* SYSSTATUS */
  1524. return 1 | 0xe; /* RESETDONE | stuff */
  1525. }
  1526. OMAP_BAD_REG(addr);
  1527. return 0;
  1528. }
  1529. static void omap_eac_write(void *opaque, target_phys_addr_t addr,
  1530. uint32_t value)
  1531. {
  1532. struct omap_eac_s *s = (struct omap_eac_s *) opaque;
  1533. switch (addr) {
  1534. case 0x098: /* APD1LCR */
  1535. case 0x09c: /* APD1RCR */
  1536. case 0x0a0: /* APD2LCR */
  1537. case 0x0a4: /* APD2RCR */
  1538. case 0x0a8: /* APD3LCR */
  1539. case 0x0ac: /* APD3RCR */
  1540. case 0x0b0: /* APD4R */
  1541. case 0x0b8: /* ADRDR */
  1542. case 0x0d0: /* MPDDMARR */
  1543. case 0x0d8: /* MPUDMARR */
  1544. case 0x0e4: /* BPDDMARR */
  1545. case 0x0ec: /* BPUDMARR */
  1546. case 0x100: /* VERSION_NUMBER */
  1547. case 0x108: /* SYSSTATUS */
  1548. OMAP_RO_REG(addr);
  1549. return;
  1550. case 0x000: /* CPCFR1 */
  1551. s->config[0] = value & 0xff;
  1552. omap_eac_format_update(s);
  1553. break;
  1554. case 0x004: /* CPCFR2 */
  1555. s->config[1] = value & 0xff;
  1556. omap_eac_format_update(s);
  1557. break;
  1558. case 0x008: /* CPCFR3 */
  1559. s->config[2] = value & 0xff;
  1560. omap_eac_format_update(s);
  1561. break;
  1562. case 0x00c: /* CPCFR4 */
  1563. s->config[3] = value & 0xff;
  1564. omap_eac_format_update(s);
  1565. break;
  1566. case 0x010: /* CPTCTL */
  1567. /* Assuming TXF and TXE bits are read-only... */
  1568. s->control = value & 0x5f;
  1569. omap_eac_interrupt_update(s);
  1570. break;
  1571. case 0x014: /* CPTTADR */
  1572. s->address = value & 0xff;
  1573. break;
  1574. case 0x018: /* CPTDATL */
  1575. s->data &= 0xff00;
  1576. s->data |= value & 0xff;
  1577. break;
  1578. case 0x01c: /* CPTDATH */
  1579. s->data &= 0x00ff;
  1580. s->data |= value << 8;
  1581. break;
  1582. case 0x020: /* CPTVSLL */
  1583. s->vtol = value & 0xf8;
  1584. break;
  1585. case 0x024: /* CPTVSLH */
  1586. s->vtsl = value & 0x9f;
  1587. break;
  1588. case 0x040: /* MPCTR */
  1589. s->modem.control = value & 0x8f;
  1590. break;
  1591. case 0x044: /* MPMCCFR */
  1592. s->modem.config = value & 0x7fff;
  1593. break;
  1594. case 0x060: /* BPCTR */
  1595. s->bt.control = value & 0x8f;
  1596. break;
  1597. case 0x064: /* BPMCCFR */
  1598. s->bt.config = value & 0x7fff;
  1599. break;
  1600. case 0x080: /* AMSCFR */
  1601. s->mixer = value & 0x0fff;
  1602. break;
  1603. case 0x084: /* AMVCTR */
  1604. s->gain[0] = value & 0xffff;
  1605. break;
  1606. case 0x088: /* AM1VCTR */
  1607. s->gain[1] = value & 0xff7f;
  1608. break;
  1609. case 0x08c: /* AM2VCTR */
  1610. s->gain[2] = value & 0xff7f;
  1611. break;
  1612. case 0x090: /* AM3VCTR */
  1613. s->gain[3] = value & 0xff7f;
  1614. break;
  1615. case 0x094: /* ASTCTR */
  1616. s->att = value & 0xff;
  1617. break;
  1618. case 0x0b4: /* ADWR */
  1619. s->codec.txbuf[s->codec.txlen ++] = value;
  1620. if (unlikely(s->codec.txlen == EAC_BUF_LEN ||
  1621. s->codec.txlen == s->codec.txavail)) {
  1622. if (s->codec.txavail)
  1623. omap_eac_out_empty(s);
  1624. /* Discard what couldn't be written */
  1625. s->codec.txlen = 0;
  1626. }
  1627. break;
  1628. case 0x0bc: /* AGCFR */
  1629. s->codec.config[0] = value & 0x07ff;
  1630. omap_eac_format_update(s);
  1631. break;
  1632. case 0x0c0: /* AGCTR */
  1633. s->codec.config[1] = value & 0x780f;
  1634. omap_eac_format_update(s);
  1635. break;
  1636. case 0x0c4: /* AGCFR2 */
  1637. s->codec.config[2] = value & 0x003f;
  1638. omap_eac_format_update(s);
  1639. break;
  1640. case 0x0c8: /* AGCFR3 */
  1641. s->codec.config[3] = value & 0xffff;
  1642. omap_eac_format_update(s);
  1643. break;
  1644. case 0x0cc: /* MBPDMACTR */
  1645. case 0x0d4: /* MPDDMAWR */
  1646. case 0x0e0: /* MPUDMAWR */
  1647. case 0x0e8: /* BPDDMAWR */
  1648. case 0x0f0: /* BPUDMAWR */
  1649. break;
  1650. case 0x104: /* SYSCONFIG */
  1651. if (value & (1 << 1)) /* SOFTRESET */
  1652. omap_eac_reset(s);
  1653. s->sysconfig = value & 0x31d;
  1654. break;
  1655. default:
  1656. OMAP_BAD_REG(addr);
  1657. return;
  1658. }
  1659. }
  1660. static CPUReadMemoryFunc *omap_eac_readfn[] = {
  1661. omap_badwidth_read16,
  1662. omap_eac_read,
  1663. omap_badwidth_read16,
  1664. };
  1665. static CPUWriteMemoryFunc *omap_eac_writefn[] = {
  1666. omap_badwidth_write16,
  1667. omap_eac_write,
  1668. omap_badwidth_write16,
  1669. };
  1670. struct omap_eac_s *omap_eac_init(struct omap_target_agent_s *ta,
  1671. qemu_irq irq, qemu_irq *drq, omap_clk fclk, omap_clk iclk)
  1672. {
  1673. int iomemtype;
  1674. struct omap_eac_s *s = (struct omap_eac_s *)
  1675. qemu_mallocz(sizeof(struct omap_eac_s));
  1676. s->irq = irq;
  1677. s->codec.rxdrq = *drq ++;
  1678. s->codec.txdrq = *drq ++;
  1679. omap_eac_reset(s);
  1680. #ifdef HAS_AUDIO
  1681. /* TODO: do AUD_init globally for machine */
  1682. AUD_register_card(AUD_init(), "OMAP EAC", &s->codec.card);
  1683. iomemtype = cpu_register_io_memory(0, omap_eac_readfn,
  1684. omap_eac_writefn, s);
  1685. omap_l4_attach(ta, 0, iomemtype);
  1686. #endif
  1687. return s;
  1688. }
  1689. /* STI/XTI (emulation interface) console - reverse engineered only */
  1690. struct omap_sti_s {
  1691. qemu_irq irq;
  1692. CharDriverState *chr;
  1693. uint32_t sysconfig;
  1694. uint32_t systest;
  1695. uint32_t irqst;
  1696. uint32_t irqen;
  1697. uint32_t clkcontrol;
  1698. uint32_t serial_config;
  1699. };
  1700. #define STI_TRACE_CONSOLE_CHANNEL 239
  1701. #define STI_TRACE_CONTROL_CHANNEL 253
  1702. static inline void omap_sti_interrupt_update(struct omap_sti_s *s)
  1703. {
  1704. qemu_set_irq(s->irq, s->irqst & s->irqen);
  1705. }
  1706. static void omap_sti_reset(struct omap_sti_s *s)
  1707. {
  1708. s->sysconfig = 0;
  1709. s->irqst = 0;
  1710. s->irqen = 0;
  1711. s->clkcontrol = 0;
  1712. s->serial_config = 0;
  1713. omap_sti_interrupt_update(s);
  1714. }
  1715. static uint32_t omap_sti_read(void *opaque, target_phys_addr_t addr)
  1716. {
  1717. struct omap_sti_s *s = (struct omap_sti_s *) opaque;
  1718. switch (addr) {
  1719. case 0x00: /* STI_REVISION */
  1720. return 0x10;
  1721. case 0x10: /* STI_SYSCONFIG */
  1722. return s->sysconfig;
  1723. case 0x14: /* STI_SYSSTATUS / STI_RX_STATUS / XTI_SYSSTATUS */
  1724. return 0x00;
  1725. case 0x18: /* STI_IRQSTATUS */
  1726. return s->irqst;
  1727. case 0x1c: /* STI_IRQSETEN / STI_IRQCLREN */
  1728. return s->irqen;
  1729. case 0x24: /* STI_ER / STI_DR / XTI_TRACESELECT */
  1730. case 0x28: /* STI_RX_DR / XTI_RXDATA */
  1731. /* TODO */
  1732. return 0;
  1733. case 0x2c: /* STI_CLK_CTRL / XTI_SCLKCRTL */
  1734. return s->clkcontrol;
  1735. case 0x30: /* STI_SERIAL_CFG / XTI_SCONFIG */
  1736. return s->serial_config;
  1737. }
  1738. OMAP_BAD_REG(addr);
  1739. return 0;
  1740. }
  1741. static void omap_sti_write(void *opaque, target_phys_addr_t addr,
  1742. uint32_t value)
  1743. {
  1744. struct omap_sti_s *s = (struct omap_sti_s *) opaque;
  1745. switch (addr) {
  1746. case 0x00: /* STI_REVISION */
  1747. case 0x14: /* STI_SYSSTATUS / STI_RX_STATUS / XTI_SYSSTATUS */
  1748. OMAP_RO_REG(addr);
  1749. return;
  1750. case 0x10: /* STI_SYSCONFIG */
  1751. if (value & (1 << 1)) /* SOFTRESET */
  1752. omap_sti_reset(s);
  1753. s->sysconfig = value & 0xfe;
  1754. break;
  1755. case 0x18: /* STI_IRQSTATUS */
  1756. s->irqst &= ~value;
  1757. omap_sti_interrupt_update(s);
  1758. break;
  1759. case 0x1c: /* STI_IRQSETEN / STI_IRQCLREN */
  1760. s->irqen = value & 0xffff;
  1761. omap_sti_interrupt_update(s);
  1762. break;
  1763. case 0x2c: /* STI_CLK_CTRL / XTI_SCLKCRTL */
  1764. s->clkcontrol = value & 0xff;
  1765. break;
  1766. case 0x30: /* STI_SERIAL_CFG / XTI_SCONFIG */
  1767. s->serial_config = value & 0xff;
  1768. break;
  1769. case 0x24: /* STI_ER / STI_DR / XTI_TRACESELECT */
  1770. case 0x28: /* STI_RX_DR / XTI_RXDATA */
  1771. /* TODO */
  1772. return;
  1773. default:
  1774. OMAP_BAD_REG(addr);
  1775. return;
  1776. }
  1777. }
  1778. static CPUReadMemoryFunc *omap_sti_readfn[] = {
  1779. omap_badwidth_read32,
  1780. omap_badwidth_read32,
  1781. omap_sti_read,
  1782. };
  1783. static CPUWriteMemoryFunc *omap_sti_writefn[] = {
  1784. omap_badwidth_write32,
  1785. omap_badwidth_write32,
  1786. omap_sti_write,
  1787. };
  1788. static uint32_t omap_sti_fifo_read(void *opaque, target_phys_addr_t addr)
  1789. {
  1790. OMAP_BAD_REG(addr);
  1791. return 0;
  1792. }
  1793. static void omap_sti_fifo_write(void *opaque, target_phys_addr_t addr,
  1794. uint32_t value)
  1795. {
  1796. struct omap_sti_s *s = (struct omap_sti_s *) opaque;
  1797. int ch = addr >> 6;
  1798. uint8_t byte = value;
  1799. if (ch == STI_TRACE_CONTROL_CHANNEL) {
  1800. /* Flush channel <i>value</i>. */
  1801. qemu_chr_write(s->chr, (const uint8_t *) "\r", 1);
  1802. } else if (ch == STI_TRACE_CONSOLE_CHANNEL || 1) {
  1803. if (value == 0xc0 || value == 0xc3) {
  1804. /* Open channel <i>ch</i>. */
  1805. } else if (value == 0x00)
  1806. qemu_chr_write(s->chr, (const uint8_t *) "\n", 1);
  1807. else
  1808. qemu_chr_write(s->chr, &byte, 1);
  1809. }
  1810. }
  1811. static CPUReadMemoryFunc *omap_sti_fifo_readfn[] = {
  1812. omap_sti_fifo_read,
  1813. omap_badwidth_read8,
  1814. omap_badwidth_read8,
  1815. };
  1816. static CPUWriteMemoryFunc *omap_sti_fifo_writefn[] = {
  1817. omap_sti_fifo_write,
  1818. omap_badwidth_write8,
  1819. omap_badwidth_write8,
  1820. };
  1821. static struct omap_sti_s *omap_sti_init(struct omap_target_agent_s *ta,
  1822. target_phys_addr_t channel_base, qemu_irq irq, omap_clk clk,
  1823. CharDriverState *chr)
  1824. {
  1825. int iomemtype;
  1826. struct omap_sti_s *s = (struct omap_sti_s *)
  1827. qemu_mallocz(sizeof(struct omap_sti_s));
  1828. s->irq = irq;
  1829. omap_sti_reset(s);
  1830. s->chr = chr ?: qemu_chr_open("null", "null", NULL);
  1831. iomemtype = l4_register_io_memory(0, omap_sti_readfn,
  1832. omap_sti_writefn, s);
  1833. omap_l4_attach(ta, 0, iomemtype);
  1834. iomemtype = cpu_register_io_memory(0, omap_sti_fifo_readfn,
  1835. omap_sti_fifo_writefn, s);
  1836. cpu_register_physical_memory(channel_base, 0x10000, iomemtype);
  1837. return s;
  1838. }
  1839. /* L4 Interconnect */
  1840. struct omap_target_agent_s {
  1841. struct omap_l4_s *bus;
  1842. int regions;
  1843. struct omap_l4_region_s *start;
  1844. target_phys_addr_t base;
  1845. uint32_t component;
  1846. uint32_t control;
  1847. uint32_t status;
  1848. };
  1849. struct omap_l4_s {
  1850. target_phys_addr_t base;
  1851. int ta_num;
  1852. struct omap_target_agent_s ta[0];
  1853. };
  1854. #ifdef L4_MUX_HACK
  1855. static int omap_l4_io_entries;
  1856. static int omap_cpu_io_entry;
  1857. static struct omap_l4_entry {
  1858. CPUReadMemoryFunc **mem_read;
  1859. CPUWriteMemoryFunc **mem_write;
  1860. void *opaque;
  1861. } *omap_l4_io_entry;
  1862. static CPUReadMemoryFunc **omap_l4_io_readb_fn;
  1863. static CPUReadMemoryFunc **omap_l4_io_readh_fn;
  1864. static CPUReadMemoryFunc **omap_l4_io_readw_fn;
  1865. static CPUWriteMemoryFunc **omap_l4_io_writeb_fn;
  1866. static CPUWriteMemoryFunc **omap_l4_io_writeh_fn;
  1867. static CPUWriteMemoryFunc **omap_l4_io_writew_fn;
  1868. static void **omap_l4_io_opaque;
  1869. int l4_register_io_memory(int io_index, CPUReadMemoryFunc **mem_read,
  1870. CPUWriteMemoryFunc **mem_write, void *opaque)
  1871. {
  1872. omap_l4_io_entry[omap_l4_io_entries].mem_read = mem_read;
  1873. omap_l4_io_entry[omap_l4_io_entries].mem_write = mem_write;
  1874. omap_l4_io_entry[omap_l4_io_entries].opaque = opaque;
  1875. return omap_l4_io_entries ++;
  1876. }
  1877. static uint32_t omap_l4_io_readb(void *opaque, target_phys_addr_t addr)
  1878. {
  1879. unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
  1880. return omap_l4_io_readb_fn[i](omap_l4_io_opaque[i], addr);
  1881. }
  1882. static uint32_t omap_l4_io_readh(void *opaque, target_phys_addr_t addr)
  1883. {
  1884. unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
  1885. return omap_l4_io_readh_fn[i](omap_l4_io_opaque[i], addr);
  1886. }
  1887. static uint32_t omap_l4_io_readw(void *opaque, target_phys_addr_t addr)
  1888. {
  1889. unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
  1890. return omap_l4_io_readw_fn[i](omap_l4_io_opaque[i], addr);
  1891. }
  1892. static void omap_l4_io_writeb(void *opaque, target_phys_addr_t addr,
  1893. uint32_t value)
  1894. {
  1895. unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
  1896. return omap_l4_io_writeb_fn[i](omap_l4_io_opaque[i], addr, value);
  1897. }
  1898. static void omap_l4_io_writeh(void *opaque, target_phys_addr_t addr,
  1899. uint32_t value)
  1900. {
  1901. unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
  1902. return omap_l4_io_writeh_fn[i](omap_l4_io_opaque[i], addr, value);
  1903. }
  1904. static void omap_l4_io_writew(void *opaque, target_phys_addr_t addr,
  1905. uint32_t value)
  1906. {
  1907. unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
  1908. return omap_l4_io_writew_fn[i](omap_l4_io_opaque[i], addr, value);
  1909. }
  1910. static CPUReadMemoryFunc *omap_l4_io_readfn[] = {
  1911. omap_l4_io_readb,
  1912. omap_l4_io_readh,
  1913. omap_l4_io_readw,
  1914. };
  1915. static CPUWriteMemoryFunc *omap_l4_io_writefn[] = {
  1916. omap_l4_io_writeb,
  1917. omap_l4_io_writeh,
  1918. omap_l4_io_writew,
  1919. };
  1920. #endif
  1921. struct omap_l4_s *omap_l4_init(target_phys_addr_t base, int ta_num)
  1922. {
  1923. struct omap_l4_s *bus = qemu_mallocz(
  1924. sizeof(*bus) + ta_num * sizeof(*bus->ta));
  1925. bus->ta_num = ta_num;
  1926. bus->base = base;
  1927. #ifdef L4_MUX_HACK
  1928. omap_l4_io_entries = 1;
  1929. omap_l4_io_entry = qemu_mallocz(125 * sizeof(*omap_l4_io_entry));
  1930. omap_cpu_io_entry =
  1931. cpu_register_io_memory(0, omap_l4_io_readfn,
  1932. omap_l4_io_writefn, bus);
  1933. # define L4_PAGES (0xb4000 / TARGET_PAGE_SIZE)
  1934. omap_l4_io_readb_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
  1935. omap_l4_io_readh_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
  1936. omap_l4_io_readw_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
  1937. omap_l4_io_writeb_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
  1938. omap_l4_io_writeh_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
  1939. omap_l4_io_writew_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
  1940. omap_l4_io_opaque = qemu_mallocz(sizeof(void *) * L4_PAGES);
  1941. #endif
  1942. return bus;
  1943. }
  1944. static uint32_t omap_l4ta_read(void *opaque, target_phys_addr_t addr)
  1945. {
  1946. struct omap_target_agent_s *s = (struct omap_target_agent_s *) opaque;
  1947. switch (addr) {
  1948. case 0x00: /* COMPONENT */
  1949. return s->component;
  1950. case 0x20: /* AGENT_CONTROL */
  1951. return s->control;
  1952. case 0x28: /* AGENT_STATUS */
  1953. return s->status;
  1954. }
  1955. OMAP_BAD_REG(addr);
  1956. return 0;
  1957. }
  1958. static void omap_l4ta_write(void *opaque, target_phys_addr_t addr,
  1959. uint32_t value)
  1960. {
  1961. struct omap_target_agent_s *s = (struct omap_target_agent_s *) opaque;
  1962. switch (addr) {
  1963. case 0x00: /* COMPONENT */
  1964. case 0x28: /* AGENT_STATUS */
  1965. OMAP_RO_REG(addr);
  1966. break;
  1967. case 0x20: /* AGENT_CONTROL */
  1968. s->control = value & 0x01000700;
  1969. if (value & 1) /* OCP_RESET */
  1970. s->status &= ~1; /* REQ_TIMEOUT */
  1971. break;
  1972. default:
  1973. OMAP_BAD_REG(addr);
  1974. }
  1975. }
  1976. static CPUReadMemoryFunc *omap_l4ta_readfn[] = {
  1977. omap_badwidth_read16,
  1978. omap_l4ta_read,
  1979. omap_badwidth_read16,
  1980. };
  1981. static CPUWriteMemoryFunc *omap_l4ta_writefn[] = {
  1982. omap_badwidth_write32,
  1983. omap_badwidth_write32,
  1984. omap_l4ta_write,
  1985. };
  1986. #define L4TA(n) (n)
  1987. #define L4TAO(n) ((n) + 39)
  1988. static struct omap_l4_region_s {
  1989. target_phys_addr_t offset;
  1990. size_t size;
  1991. int access;
  1992. } omap_l4_region[125] = {
  1993. [ 1] = { 0x40800, 0x800, 32 }, /* Initiator agent */
  1994. [ 2] = { 0x41000, 0x1000, 32 }, /* Link agent */
  1995. [ 0] = { 0x40000, 0x800, 32 }, /* Address and protection */
  1996. [ 3] = { 0x00000, 0x1000, 32 | 16 | 8 }, /* System Control and Pinout */
  1997. [ 4] = { 0x01000, 0x1000, 32 | 16 | 8 }, /* L4TAO1 */
  1998. [ 5] = { 0x04000, 0x1000, 32 | 16 }, /* 32K Timer */
  1999. [ 6] = { 0x05000, 0x1000, 32 | 16 | 8 }, /* L4TAO2 */
  2000. [ 7] = { 0x08000, 0x800, 32 }, /* PRCM Region A */
  2001. [ 8] = { 0x08800, 0x800, 32 }, /* PRCM Region B */
  2002. [ 9] = { 0x09000, 0x1000, 32 | 16 | 8 }, /* L4TAO */
  2003. [ 10] = { 0x12000, 0x1000, 32 | 16 | 8 }, /* Test (BCM) */
  2004. [ 11] = { 0x13000, 0x1000, 32 | 16 | 8 }, /* L4TA1 */
  2005. [ 12] = { 0x14000, 0x1000, 32 }, /* Test/emulation (TAP) */
  2006. [ 13] = { 0x15000, 0x1000, 32 | 16 | 8 }, /* L4TA2 */
  2007. [ 14] = { 0x18000, 0x1000, 32 | 16 | 8 }, /* GPIO1 */
  2008. [ 16] = { 0x1a000, 0x1000, 32 | 16 | 8 }, /* GPIO2 */
  2009. [ 18] = { 0x1c000, 0x1000, 32 | 16 | 8 }, /* GPIO3 */
  2010. [ 19] = { 0x1e000, 0x1000, 32 | 16 | 8 }, /* GPIO4 */
  2011. [ 15] = { 0x19000, 0x1000, 32 | 16 | 8 }, /* Quad GPIO TOP */
  2012. [ 17] = { 0x1b000, 0x1000, 32 | 16 | 8 }, /* L4TA3 */
  2013. [ 20] = { 0x20000, 0x1000, 32 | 16 | 8 }, /* WD Timer 1 (Secure) */
  2014. [ 22] = { 0x22000, 0x1000, 32 | 16 | 8 }, /* WD Timer 2 (OMAP) */
  2015. [ 21] = { 0x21000, 0x1000, 32 | 16 | 8 }, /* Dual WD timer TOP */
  2016. [ 23] = { 0x23000, 0x1000, 32 | 16 | 8 }, /* L4TA4 */
  2017. [ 24] = { 0x28000, 0x1000, 32 | 16 | 8 }, /* GP Timer 1 */
  2018. [ 25] = { 0x29000, 0x1000, 32 | 16 | 8 }, /* L4TA7 */
  2019. [ 26] = { 0x48000, 0x2000, 32 | 16 | 8 }, /* Emulation (ARM11ETB) */
  2020. [ 27] = { 0x4a000, 0x1000, 32 | 16 | 8 }, /* L4TA9 */
  2021. [ 28] = { 0x50000, 0x400, 32 | 16 | 8 }, /* Display top */
  2022. [ 29] = { 0x50400, 0x400, 32 | 16 | 8 }, /* Display control */
  2023. [ 30] = { 0x50800, 0x400, 32 | 16 | 8 }, /* Display RFBI */
  2024. [ 31] = { 0x50c00, 0x400, 32 | 16 | 8 }, /* Display encoder */
  2025. [ 32] = { 0x51000, 0x1000, 32 | 16 | 8 }, /* L4TA10 */
  2026. [ 33] = { 0x52000, 0x400, 32 | 16 | 8 }, /* Camera top */
  2027. [ 34] = { 0x52400, 0x400, 32 | 16 | 8 }, /* Camera core */
  2028. [ 35] = { 0x52800, 0x400, 32 | 16 | 8 }, /* Camera DMA */
  2029. [ 36] = { 0x52c00, 0x400, 32 | 16 | 8 }, /* Camera MMU */
  2030. [ 37] = { 0x53000, 0x1000, 32 | 16 | 8 }, /* L4TA11 */
  2031. [ 38] = { 0x56000, 0x1000, 32 | 16 | 8 }, /* sDMA */
  2032. [ 39] = { 0x57000, 0x1000, 32 | 16 | 8 }, /* L4TA12 */
  2033. [ 40] = { 0x58000, 0x1000, 32 | 16 | 8 }, /* SSI top */
  2034. [ 41] = { 0x59000, 0x1000, 32 | 16 | 8 }, /* SSI GDD */
  2035. [ 42] = { 0x5a000, 0x1000, 32 | 16 | 8 }, /* SSI Port1 */
  2036. [ 43] = { 0x5b000, 0x1000, 32 | 16 | 8 }, /* SSI Port2 */
  2037. [ 44] = { 0x5c000, 0x1000, 32 | 16 | 8 }, /* L4TA13 */
  2038. [ 45] = { 0x5e000, 0x1000, 32 | 16 | 8 }, /* USB OTG */
  2039. [ 46] = { 0x5f000, 0x1000, 32 | 16 | 8 }, /* L4TAO4 */
  2040. [ 47] = { 0x60000, 0x1000, 32 | 16 | 8 }, /* Emulation (WIN_TRACER1SDRC) */
  2041. [ 48] = { 0x61000, 0x1000, 32 | 16 | 8 }, /* L4TA14 */
  2042. [ 49] = { 0x62000, 0x1000, 32 | 16 | 8 }, /* Emulation (WIN_TRACER2GPMC) */
  2043. [ 50] = { 0x63000, 0x1000, 32 | 16 | 8 }, /* L4TA15 */
  2044. [ 51] = { 0x64000, 0x1000, 32 | 16 | 8 }, /* Emulation (WIN_TRACER3OCM) */
  2045. [ 52] = { 0x65000, 0x1000, 32 | 16 | 8 }, /* L4TA16 */
  2046. [ 53] = { 0x66000, 0x300, 32 | 16 | 8 }, /* Emulation (WIN_TRACER4L4) */
  2047. [ 54] = { 0x67000, 0x1000, 32 | 16 | 8 }, /* L4TA17 */
  2048. [ 55] = { 0x68000, 0x1000, 32 | 16 | 8 }, /* Emulation (XTI) */
  2049. [ 56] = { 0x69000, 0x1000, 32 | 16 | 8 }, /* L4TA18 */
  2050. [ 57] = { 0x6a000, 0x1000, 16 | 8 }, /* UART1 */
  2051. [ 58] = { 0x6b000, 0x1000, 32 | 16 | 8 }, /* L4TA19 */
  2052. [ 59] = { 0x6c000, 0x1000, 16 | 8 }, /* UART2 */
  2053. [ 60] = { 0x6d000, 0x1000, 32 | 16 | 8 }, /* L4TA20 */
  2054. [ 61] = { 0x6e000, 0x1000, 16 | 8 }, /* UART3 */
  2055. [ 62] = { 0x6f000, 0x1000, 32 | 16 | 8 }, /* L4TA21 */
  2056. [ 63] = { 0x70000, 0x1000, 16 }, /* I2C1 */
  2057. [ 64] = { 0x71000, 0x1000, 32 | 16 | 8 }, /* L4TAO5 */
  2058. [ 65] = { 0x72000, 0x1000, 16 }, /* I2C2 */
  2059. [ 66] = { 0x73000, 0x1000, 32 | 16 | 8 }, /* L4TAO6 */
  2060. [ 67] = { 0x74000, 0x1000, 16 }, /* McBSP1 */
  2061. [ 68] = { 0x75000, 0x1000, 32 | 16 | 8 }, /* L4TAO7 */
  2062. [ 69] = { 0x76000, 0x1000, 16 }, /* McBSP2 */
  2063. [ 70] = { 0x77000, 0x1000, 32 | 16 | 8 }, /* L4TAO8 */
  2064. [ 71] = { 0x24000, 0x1000, 32 | 16 | 8 }, /* WD Timer 3 (DSP) */
  2065. [ 72] = { 0x25000, 0x1000, 32 | 16 | 8 }, /* L4TA5 */
  2066. [ 73] = { 0x26000, 0x1000, 32 | 16 | 8 }, /* WD Timer 4 (IVA) */
  2067. [ 74] = { 0x27000, 0x1000, 32 | 16 | 8 }, /* L4TA6 */
  2068. [ 75] = { 0x2a000, 0x1000, 32 | 16 | 8 }, /* GP Timer 2 */
  2069. [ 76] = { 0x2b000, 0x1000, 32 | 16 | 8 }, /* L4TA8 */
  2070. [ 77] = { 0x78000, 0x1000, 32 | 16 | 8 }, /* GP Timer 3 */
  2071. [ 78] = { 0x79000, 0x1000, 32 | 16 | 8 }, /* L4TA22 */
  2072. [ 79] = { 0x7a000, 0x1000, 32 | 16 | 8 }, /* GP Timer 4 */
  2073. [ 80] = { 0x7b000, 0x1000, 32 | 16 | 8 }, /* L4TA23 */
  2074. [ 81] = { 0x7c000, 0x1000, 32 | 16 | 8 }, /* GP Timer 5 */
  2075. [ 82] = { 0x7d000, 0x1000, 32 | 16 | 8 }, /* L4TA24 */
  2076. [ 83] = { 0x7e000, 0x1000, 32 | 16 | 8 }, /* GP Timer 6 */
  2077. [ 84] = { 0x7f000, 0x1000, 32 | 16 | 8 }, /* L4TA25 */
  2078. [ 85] = { 0x80000, 0x1000, 32 | 16 | 8 }, /* GP Timer 7 */
  2079. [ 86] = { 0x81000, 0x1000, 32 | 16 | 8 }, /* L4TA26 */
  2080. [ 87] = { 0x82000, 0x1000, 32 | 16 | 8 }, /* GP Timer 8 */
  2081. [ 88] = { 0x83000, 0x1000, 32 | 16 | 8 }, /* L4TA27 */
  2082. [ 89] = { 0x84000, 0x1000, 32 | 16 | 8 }, /* GP Timer 9 */
  2083. [ 90] = { 0x85000, 0x1000, 32 | 16 | 8 }, /* L4TA28 */
  2084. [ 91] = { 0x86000, 0x1000, 32 | 16 | 8 }, /* GP Timer 10 */
  2085. [ 92] = { 0x87000, 0x1000, 32 | 16 | 8 }, /* L4TA29 */
  2086. [ 93] = { 0x88000, 0x1000, 32 | 16 | 8 }, /* GP Timer 11 */
  2087. [ 94] = { 0x89000, 0x1000, 32 | 16 | 8 }, /* L4TA30 */
  2088. [ 95] = { 0x8a000, 0x1000, 32 | 16 | 8 }, /* GP Timer 12 */
  2089. [ 96] = { 0x8b000, 0x1000, 32 | 16 | 8 }, /* L4TA31 */
  2090. [ 97] = { 0x90000, 0x1000, 16 }, /* EAC */
  2091. [ 98] = { 0x91000, 0x1000, 32 | 16 | 8 }, /* L4TA32 */
  2092. [ 99] = { 0x92000, 0x1000, 16 }, /* FAC */
  2093. [100] = { 0x93000, 0x1000, 32 | 16 | 8 }, /* L4TA33 */
  2094. [101] = { 0x94000, 0x1000, 32 | 16 | 8 }, /* IPC (MAILBOX) */
  2095. [102] = { 0x95000, 0x1000, 32 | 16 | 8 }, /* L4TA34 */
  2096. [103] = { 0x98000, 0x1000, 32 | 16 | 8 }, /* SPI1 */
  2097. [104] = { 0x99000, 0x1000, 32 | 16 | 8 }, /* L4TA35 */
  2098. [105] = { 0x9a000, 0x1000, 32 | 16 | 8 }, /* SPI2 */
  2099. [106] = { 0x9b000, 0x1000, 32 | 16 | 8 }, /* L4TA36 */
  2100. [107] = { 0x9c000, 0x1000, 16 | 8 }, /* MMC SDIO */
  2101. [108] = { 0x9d000, 0x1000, 32 | 16 | 8 }, /* L4TAO9 */
  2102. [109] = { 0x9e000, 0x1000, 32 | 16 | 8 }, /* MS_PRO */
  2103. [110] = { 0x9f000, 0x1000, 32 | 16 | 8 }, /* L4TAO10 */
  2104. [111] = { 0xa0000, 0x1000, 32 }, /* RNG */
  2105. [112] = { 0xa1000, 0x1000, 32 | 16 | 8 }, /* L4TAO11 */
  2106. [113] = { 0xa2000, 0x1000, 32 }, /* DES3DES */
  2107. [114] = { 0xa3000, 0x1000, 32 | 16 | 8 }, /* L4TAO12 */
  2108. [115] = { 0xa4000, 0x1000, 32 }, /* SHA1MD5 */
  2109. [116] = { 0xa5000, 0x1000, 32 | 16 | 8 }, /* L4TAO13 */
  2110. [117] = { 0xa6000, 0x1000, 32 }, /* AES */
  2111. [118] = { 0xa7000, 0x1000, 32 | 16 | 8 }, /* L4TA37 */
  2112. [119] = { 0xa8000, 0x2000, 32 }, /* PKA */
  2113. [120] = { 0xaa000, 0x1000, 32 | 16 | 8 }, /* L4TA38 */
  2114. [121] = { 0xb0000, 0x1000, 32 }, /* MG */
  2115. [122] = { 0xb1000, 0x1000, 32 | 16 | 8 },
  2116. [123] = { 0xb2000, 0x1000, 32 }, /* HDQ/1-Wire */
  2117. [124] = { 0xb3000, 0x1000, 32 | 16 | 8 }, /* L4TA39 */
  2118. };
  2119. static struct omap_l4_agent_info_s {
  2120. int ta;
  2121. int region;
  2122. int regions;
  2123. int ta_region;
  2124. } omap_l4_agent_info[54] = {
  2125. { 0, 0, 3, 2 }, /* L4IA initiatior agent */
  2126. { L4TAO(1), 3, 2, 1 }, /* Control and pinout module */
  2127. { L4TAO(2), 5, 2, 1 }, /* 32K timer */
  2128. { L4TAO(3), 7, 3, 2 }, /* PRCM */
  2129. { L4TA(1), 10, 2, 1 }, /* BCM */
  2130. { L4TA(2), 12, 2, 1 }, /* Test JTAG */
  2131. { L4TA(3), 14, 6, 3 }, /* Quad GPIO */
  2132. { L4TA(4), 20, 4, 3 }, /* WD timer 1/2 */
  2133. { L4TA(7), 24, 2, 1 }, /* GP timer 1 */
  2134. { L4TA(9), 26, 2, 1 }, /* ATM11 ETB */
  2135. { L4TA(10), 28, 5, 4 }, /* Display subsystem */
  2136. { L4TA(11), 33, 5, 4 }, /* Camera subsystem */
  2137. { L4TA(12), 38, 2, 1 }, /* sDMA */
  2138. { L4TA(13), 40, 5, 4 }, /* SSI */
  2139. { L4TAO(4), 45, 2, 1 }, /* USB */
  2140. { L4TA(14), 47, 2, 1 }, /* Win Tracer1 */
  2141. { L4TA(15), 49, 2, 1 }, /* Win Tracer2 */
  2142. { L4TA(16), 51, 2, 1 }, /* Win Tracer3 */
  2143. { L4TA(17), 53, 2, 1 }, /* Win Tracer4 */
  2144. { L4TA(18), 55, 2, 1 }, /* XTI */
  2145. { L4TA(19), 57, 2, 1 }, /* UART1 */
  2146. { L4TA(20), 59, 2, 1 }, /* UART2 */
  2147. { L4TA(21), 61, 2, 1 }, /* UART3 */
  2148. { L4TAO(5), 63, 2, 1 }, /* I2C1 */
  2149. { L4TAO(6), 65, 2, 1 }, /* I2C2 */
  2150. { L4TAO(7), 67, 2, 1 }, /* McBSP1 */
  2151. { L4TAO(8), 69, 2, 1 }, /* McBSP2 */
  2152. { L4TA(5), 71, 2, 1 }, /* WD Timer 3 (DSP) */
  2153. { L4TA(6), 73, 2, 1 }, /* WD Timer 4 (IVA) */
  2154. { L4TA(8), 75, 2, 1 }, /* GP Timer 2 */
  2155. { L4TA(22), 77, 2, 1 }, /* GP Timer 3 */
  2156. { L4TA(23), 79, 2, 1 }, /* GP Timer 4 */
  2157. { L4TA(24), 81, 2, 1 }, /* GP Timer 5 */
  2158. { L4TA(25), 83, 2, 1 }, /* GP Timer 6 */
  2159. { L4TA(26), 85, 2, 1 }, /* GP Timer 7 */
  2160. { L4TA(27), 87, 2, 1 }, /* GP Timer 8 */
  2161. { L4TA(28), 89, 2, 1 }, /* GP Timer 9 */
  2162. { L4TA(29), 91, 2, 1 }, /* GP Timer 10 */
  2163. { L4TA(30), 93, 2, 1 }, /* GP Timer 11 */
  2164. { L4TA(31), 95, 2, 1 }, /* GP Timer 12 */
  2165. { L4TA(32), 97, 2, 1 }, /* EAC */
  2166. { L4TA(33), 99, 2, 1 }, /* FAC */
  2167. { L4TA(34), 101, 2, 1 }, /* IPC */
  2168. { L4TA(35), 103, 2, 1 }, /* SPI1 */
  2169. { L4TA(36), 105, 2, 1 }, /* SPI2 */
  2170. { L4TAO(9), 107, 2, 1 }, /* MMC SDIO */
  2171. { L4TAO(10), 109, 2, 1 },
  2172. { L4TAO(11), 111, 2, 1 }, /* RNG */
  2173. { L4TAO(12), 113, 2, 1 }, /* DES3DES */
  2174. { L4TAO(13), 115, 2, 1 }, /* SHA1MD5 */
  2175. { L4TA(37), 117, 2, 1 }, /* AES */
  2176. { L4TA(38), 119, 2, 1 }, /* PKA */
  2177. { -1, 121, 2, 1 },
  2178. { L4TA(39), 123, 2, 1 }, /* HDQ/1-Wire */
  2179. };
  2180. #define omap_l4ta(bus, cs) omap_l4ta_get(bus, L4TA(cs))
  2181. #define omap_l4tao(bus, cs) omap_l4ta_get(bus, L4TAO(cs))
  2182. struct omap_target_agent_s *omap_l4ta_get(struct omap_l4_s *bus, int cs)
  2183. {
  2184. int i, iomemtype;
  2185. struct omap_target_agent_s *ta = 0;
  2186. struct omap_l4_agent_info_s *info = 0;
  2187. for (i = 0; i < bus->ta_num; i ++)
  2188. if (omap_l4_agent_info[i].ta == cs) {
  2189. ta = &bus->ta[i];
  2190. info = &omap_l4_agent_info[i];
  2191. break;
  2192. }
  2193. if (!ta) {
  2194. fprintf(stderr, "%s: bad target agent (%i)\n", __FUNCTION__, cs);
  2195. exit(-1);
  2196. }
  2197. ta->bus = bus;
  2198. ta->start = &omap_l4_region[info->region];
  2199. ta->regions = info->regions;
  2200. ta->component = ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
  2201. ta->status = 0x00000000;
  2202. ta->control = 0x00000200; /* XXX 01000200 for L4TAO */
  2203. iomemtype = l4_register_io_memory(0, omap_l4ta_readfn,
  2204. omap_l4ta_writefn, ta);
  2205. ta->base = omap_l4_attach(ta, info->ta_region, iomemtype);
  2206. return ta;
  2207. }
  2208. target_phys_addr_t omap_l4_attach(struct omap_target_agent_s *ta, int region,
  2209. int iotype)
  2210. {
  2211. target_phys_addr_t base;
  2212. ssize_t size;
  2213. #ifdef L4_MUX_HACK
  2214. int i;
  2215. #endif
  2216. if (region < 0 || region >= ta->regions) {
  2217. fprintf(stderr, "%s: bad io region (%i)\n", __FUNCTION__, region);
  2218. exit(-1);
  2219. }
  2220. base = ta->bus->base + ta->start[region].offset;
  2221. size = ta->start[region].size;
  2222. if (iotype) {
  2223. #ifndef L4_MUX_HACK
  2224. cpu_register_physical_memory(base, size, iotype);
  2225. #else
  2226. cpu_register_physical_memory(base, size, omap_cpu_io_entry);
  2227. i = (base - ta->bus->base) / TARGET_PAGE_SIZE;
  2228. for (; size > 0; size -= TARGET_PAGE_SIZE, i ++) {
  2229. omap_l4_io_readb_fn[i] = omap_l4_io_entry[iotype].mem_read[0];
  2230. omap_l4_io_readh_fn[i] = omap_l4_io_entry[iotype].mem_read[1];
  2231. omap_l4_io_readw_fn[i] = omap_l4_io_entry[iotype].mem_read[2];
  2232. omap_l4_io_writeb_fn[i] = omap_l4_io_entry[iotype].mem_write[0];
  2233. omap_l4_io_writeh_fn[i] = omap_l4_io_entry[iotype].mem_write[1];
  2234. omap_l4_io_writew_fn[i] = omap_l4_io_entry[iotype].mem_write[2];
  2235. omap_l4_io_opaque[i] = omap_l4_io_entry[iotype].opaque;
  2236. }
  2237. #endif
  2238. }
  2239. return base;
  2240. }
  2241. /* TEST-Chip-level TAP */
  2242. static uint32_t omap_tap_read(void *opaque, target_phys_addr_t addr)
  2243. {
  2244. struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
  2245. switch (addr) {
  2246. case 0x204: /* IDCODE_reg */
  2247. switch (s->mpu_model) {
  2248. case omap2420:
  2249. case omap2422:
  2250. case omap2423:
  2251. return 0x5b5d902f; /* ES 2.2 */
  2252. case omap2430:
  2253. return 0x5b68a02f; /* ES 2.2 */
  2254. case omap3430:
  2255. return 0x1b7ae02f; /* ES 2 */
  2256. default:
  2257. cpu_abort(cpu_single_env, "%s: Bad mpu model\n", __FUNCTION__);
  2258. }
  2259. case 0x208: /* PRODUCTION_ID_reg for OMAP2 */
  2260. case 0x210: /* PRODUCTION_ID_reg for OMAP3 */
  2261. switch (s->mpu_model) {
  2262. case omap2420:
  2263. return 0x000254f0; /* POP ESHS2.1.1 in N91/93/95, ES2 in N800 */
  2264. case omap2422:
  2265. return 0x000400f0;
  2266. case omap2423:
  2267. return 0x000800f0;
  2268. case omap2430:
  2269. return 0x000000f0;
  2270. case omap3430:
  2271. return 0x000000f0;
  2272. default:
  2273. cpu_abort(cpu_single_env, "%s: Bad mpu model\n", __FUNCTION__);
  2274. }
  2275. case 0x20c:
  2276. switch (s->mpu_model) {
  2277. case omap2420:
  2278. case omap2422:
  2279. case omap2423:
  2280. return 0xcafeb5d9; /* ES 2.2 */
  2281. case omap2430:
  2282. return 0xcafeb68a; /* ES 2.2 */
  2283. case omap3430:
  2284. return 0xcafeb7ae; /* ES 2 */
  2285. default:
  2286. cpu_abort(cpu_single_env, "%s: Bad mpu model\n", __FUNCTION__);
  2287. }
  2288. case 0x218: /* DIE_ID_reg */
  2289. return ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
  2290. case 0x21c: /* DIE_ID_reg */
  2291. return 0x54 << 24;
  2292. case 0x220: /* DIE_ID_reg */
  2293. return ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
  2294. case 0x224: /* DIE_ID_reg */
  2295. return ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
  2296. }
  2297. OMAP_BAD_REG(addr);
  2298. return 0;
  2299. }
  2300. static void omap_tap_write(void *opaque, target_phys_addr_t addr,
  2301. uint32_t value)
  2302. {
  2303. OMAP_BAD_REG(addr);
  2304. }
  2305. static CPUReadMemoryFunc *omap_tap_readfn[] = {
  2306. omap_badwidth_read32,
  2307. omap_badwidth_read32,
  2308. omap_tap_read,
  2309. };
  2310. static CPUWriteMemoryFunc *omap_tap_writefn[] = {
  2311. omap_badwidth_write32,
  2312. omap_badwidth_write32,
  2313. omap_tap_write,
  2314. };
  2315. void omap_tap_init(struct omap_target_agent_s *ta,
  2316. struct omap_mpu_state_s *mpu)
  2317. {
  2318. omap_l4_attach(ta, 0, l4_register_io_memory(0,
  2319. omap_tap_readfn, omap_tap_writefn, mpu));
  2320. }
  2321. /* Power, Reset, and Clock Management */
  2322. struct omap_prcm_s {
  2323. qemu_irq irq[3];
  2324. struct omap_mpu_state_s *mpu;
  2325. uint32_t irqst[3];
  2326. uint32_t irqen[3];
  2327. uint32_t sysconfig;
  2328. uint32_t voltctrl;
  2329. uint32_t scratch[20];
  2330. uint32_t clksrc[1];
  2331. uint32_t clkout[1];
  2332. uint32_t clkemul[1];
  2333. uint32_t clkpol[1];
  2334. uint32_t clksel[8];
  2335. uint32_t clken[12];
  2336. uint32_t clkctrl[4];
  2337. uint32_t clkidle[7];
  2338. uint32_t setuptime[2];
  2339. uint32_t wkup[3];
  2340. uint32_t wken[3];
  2341. uint32_t wkst[3];
  2342. uint32_t rst[4];
  2343. uint32_t rstctrl[1];
  2344. uint32_t power[4];
  2345. uint32_t rsttime_wkup;
  2346. uint32_t ev;
  2347. uint32_t evtime[2];
  2348. int dpll_lock, apll_lock[2];
  2349. };
  2350. static void omap_prcm_int_update(struct omap_prcm_s *s, int dom)
  2351. {
  2352. qemu_set_irq(s->irq[dom], s->irqst[dom] & s->irqen[dom]);
  2353. /* XXX or is the mask applied before PRCM_IRQSTATUS_* ? */
  2354. }
  2355. static uint32_t omap_prcm_read(void *opaque, target_phys_addr_t addr)
  2356. {
  2357. struct omap_prcm_s *s = (struct omap_prcm_s *) opaque;
  2358. uint32_t ret;
  2359. switch (addr) {
  2360. case 0x000: /* PRCM_REVISION */
  2361. return 0x10;
  2362. case 0x010: /* PRCM_SYSCONFIG */
  2363. return s->sysconfig;
  2364. case 0x018: /* PRCM_IRQSTATUS_MPU */
  2365. return s->irqst[0];
  2366. case 0x01c: /* PRCM_IRQENABLE_MPU */
  2367. return s->irqen[0];
  2368. case 0x050: /* PRCM_VOLTCTRL */
  2369. return s->voltctrl;
  2370. case 0x054: /* PRCM_VOLTST */
  2371. return s->voltctrl & 3;
  2372. case 0x060: /* PRCM_CLKSRC_CTRL */
  2373. return s->clksrc[0];
  2374. case 0x070: /* PRCM_CLKOUT_CTRL */
  2375. return s->clkout[0];
  2376. case 0x078: /* PRCM_CLKEMUL_CTRL */
  2377. return s->clkemul[0];
  2378. case 0x080: /* PRCM_CLKCFG_CTRL */
  2379. case 0x084: /* PRCM_CLKCFG_STATUS */
  2380. return 0;
  2381. case 0x090: /* PRCM_VOLTSETUP */
  2382. return s->setuptime[0];
  2383. case 0x094: /* PRCM_CLKSSETUP */
  2384. return s->setuptime[1];
  2385. case 0x098: /* PRCM_POLCTRL */
  2386. return s->clkpol[0];
  2387. case 0x0b0: /* GENERAL_PURPOSE1 */
  2388. case 0x0b4: /* GENERAL_PURPOSE2 */
  2389. case 0x0b8: /* GENERAL_PURPOSE3 */
  2390. case 0x0bc: /* GENERAL_PURPOSE4 */
  2391. case 0x0c0: /* GENERAL_PURPOSE5 */
  2392. case 0x0c4: /* GENERAL_PURPOSE6 */
  2393. case 0x0c8: /* GENERAL_PURPOSE7 */
  2394. case 0x0cc: /* GENERAL_PURPOSE8 */
  2395. case 0x0d0: /* GENERAL_PURPOSE9 */
  2396. case 0x0d4: /* GENERAL_PURPOSE10 */
  2397. case 0x0d8: /* GENERAL_PURPOSE11 */
  2398. case 0x0dc: /* GENERAL_PURPOSE12 */
  2399. case 0x0e0: /* GENERAL_PURPOSE13 */
  2400. case 0x0e4: /* GENERAL_PURPOSE14 */
  2401. case 0x0e8: /* GENERAL_PURPOSE15 */
  2402. case 0x0ec: /* GENERAL_PURPOSE16 */
  2403. case 0x0f0: /* GENERAL_PURPOSE17 */
  2404. case 0x0f4: /* GENERAL_PURPOSE18 */
  2405. case 0x0f8: /* GENERAL_PURPOSE19 */
  2406. case 0x0fc: /* GENERAL_PURPOSE20 */
  2407. return s->scratch[(addr - 0xb0) >> 2];
  2408. case 0x140: /* CM_CLKSEL_MPU */
  2409. return s->clksel[0];
  2410. case 0x148: /* CM_CLKSTCTRL_MPU */
  2411. return s->clkctrl[0];
  2412. case 0x158: /* RM_RSTST_MPU */
  2413. return s->rst[0];
  2414. case 0x1c8: /* PM_WKDEP_MPU */
  2415. return s->wkup[0];
  2416. case 0x1d4: /* PM_EVGENCTRL_MPU */
  2417. return s->ev;
  2418. case 0x1d8: /* PM_EVEGENONTIM_MPU */
  2419. return s->evtime[0];
  2420. case 0x1dc: /* PM_EVEGENOFFTIM_MPU */
  2421. return s->evtime[1];
  2422. case 0x1e0: /* PM_PWSTCTRL_MPU */
  2423. return s->power[0];
  2424. case 0x1e4: /* PM_PWSTST_MPU */
  2425. return 0;
  2426. case 0x200: /* CM_FCLKEN1_CORE */
  2427. return s->clken[0];
  2428. case 0x204: /* CM_FCLKEN2_CORE */
  2429. return s->clken[1];
  2430. case 0x210: /* CM_ICLKEN1_CORE */
  2431. return s->clken[2];
  2432. case 0x214: /* CM_ICLKEN2_CORE */
  2433. return s->clken[3];
  2434. case 0x21c: /* CM_ICLKEN4_CORE */
  2435. return s->clken[4];
  2436. case 0x220: /* CM_IDLEST1_CORE */
  2437. /* TODO: check the actual iclk status */
  2438. return 0x7ffffff9;
  2439. case 0x224: /* CM_IDLEST2_CORE */
  2440. /* TODO: check the actual iclk status */
  2441. return 0x00000007;
  2442. case 0x22c: /* CM_IDLEST4_CORE */
  2443. /* TODO: check the actual iclk status */
  2444. return 0x0000001f;
  2445. case 0x230: /* CM_AUTOIDLE1_CORE */
  2446. return s->clkidle[0];
  2447. case 0x234: /* CM_AUTOIDLE2_CORE */
  2448. return s->clkidle[1];
  2449. case 0x238: /* CM_AUTOIDLE3_CORE */
  2450. return s->clkidle[2];
  2451. case 0x23c: /* CM_AUTOIDLE4_CORE */
  2452. return s->clkidle[3];
  2453. case 0x240: /* CM_CLKSEL1_CORE */
  2454. return s->clksel[1];
  2455. case 0x244: /* CM_CLKSEL2_CORE */
  2456. return s->clksel[2];
  2457. case 0x248: /* CM_CLKSTCTRL_CORE */
  2458. return s->clkctrl[1];
  2459. case 0x2a0: /* PM_WKEN1_CORE */
  2460. return s->wken[0];
  2461. case 0x2a4: /* PM_WKEN2_CORE */
  2462. return s->wken[1];
  2463. case 0x2b0: /* PM_WKST1_CORE */
  2464. return s->wkst[0];
  2465. case 0x2b4: /* PM_WKST2_CORE */
  2466. return s->wkst[1];
  2467. case 0x2c8: /* PM_WKDEP_CORE */
  2468. return 0x1e;
  2469. case 0x2e0: /* PM_PWSTCTRL_CORE */
  2470. return s->power[1];
  2471. case 0x2e4: /* PM_PWSTST_CORE */
  2472. return 0x000030 | (s->power[1] & 0xfc00);
  2473. case 0x300: /* CM_FCLKEN_GFX */
  2474. return s->clken[5];
  2475. case 0x310: /* CM_ICLKEN_GFX */
  2476. return s->clken[6];
  2477. case 0x320: /* CM_IDLEST_GFX */
  2478. /* TODO: check the actual iclk status */
  2479. return 0x00000001;
  2480. case 0x340: /* CM_CLKSEL_GFX */
  2481. return s->clksel[3];
  2482. case 0x348: /* CM_CLKSTCTRL_GFX */
  2483. return s->clkctrl[2];
  2484. case 0x350: /* RM_RSTCTRL_GFX */
  2485. return s->rstctrl[0];
  2486. case 0x358: /* RM_RSTST_GFX */
  2487. return s->rst[1];
  2488. case 0x3c8: /* PM_WKDEP_GFX */
  2489. return s->wkup[1];
  2490. case 0x3e0: /* PM_PWSTCTRL_GFX */
  2491. return s->power[2];
  2492. case 0x3e4: /* PM_PWSTST_GFX */
  2493. return s->power[2] & 3;
  2494. case 0x400: /* CM_FCLKEN_WKUP */
  2495. return s->clken[7];
  2496. case 0x410: /* CM_ICLKEN_WKUP */
  2497. return s->clken[8];
  2498. case 0x420: /* CM_IDLEST_WKUP */
  2499. /* TODO: check the actual iclk status */
  2500. return 0x0000003f;
  2501. case 0x430: /* CM_AUTOIDLE_WKUP */
  2502. return s->clkidle[4];
  2503. case 0x440: /* CM_CLKSEL_WKUP */
  2504. return s->clksel[4];
  2505. case 0x450: /* RM_RSTCTRL_WKUP */
  2506. return 0;
  2507. case 0x454: /* RM_RSTTIME_WKUP */
  2508. return s->rsttime_wkup;
  2509. case 0x458: /* RM_RSTST_WKUP */
  2510. return s->rst[2];
  2511. case 0x4a0: /* PM_WKEN_WKUP */
  2512. return s->wken[2];
  2513. case 0x4b0: /* PM_WKST_WKUP */
  2514. return s->wkst[2];
  2515. case 0x500: /* CM_CLKEN_PLL */
  2516. return s->clken[9];
  2517. case 0x520: /* CM_IDLEST_CKGEN */
  2518. ret = 0x0000070 | (s->apll_lock[0] << 9) | (s->apll_lock[1] << 8);
  2519. if (!(s->clksel[6] & 3))
  2520. /* Core uses 32-kHz clock */
  2521. ret |= 3 << 0;
  2522. else if (!s->dpll_lock)
  2523. /* DPLL not locked, core uses ref_clk */
  2524. ret |= 1 << 0;
  2525. else
  2526. /* Core uses DPLL */
  2527. ret |= 2 << 0;
  2528. return ret;
  2529. case 0x530: /* CM_AUTOIDLE_PLL */
  2530. return s->clkidle[5];
  2531. case 0x540: /* CM_CLKSEL1_PLL */
  2532. return s->clksel[5];
  2533. case 0x544: /* CM_CLKSEL2_PLL */
  2534. return s->clksel[6];
  2535. case 0x800: /* CM_FCLKEN_DSP */
  2536. return s->clken[10];
  2537. case 0x810: /* CM_ICLKEN_DSP */
  2538. return s->clken[11];
  2539. case 0x820: /* CM_IDLEST_DSP */
  2540. /* TODO: check the actual iclk status */
  2541. return 0x00000103;
  2542. case 0x830: /* CM_AUTOIDLE_DSP */
  2543. return s->clkidle[6];
  2544. case 0x840: /* CM_CLKSEL_DSP */
  2545. return s->clksel[7];
  2546. case 0x848: /* CM_CLKSTCTRL_DSP */
  2547. return s->clkctrl[3];
  2548. case 0x850: /* RM_RSTCTRL_DSP */
  2549. return 0;
  2550. case 0x858: /* RM_RSTST_DSP */
  2551. return s->rst[3];
  2552. case 0x8c8: /* PM_WKDEP_DSP */
  2553. return s->wkup[2];
  2554. case 0x8e0: /* PM_PWSTCTRL_DSP */
  2555. return s->power[3];
  2556. case 0x8e4: /* PM_PWSTST_DSP */
  2557. return 0x008030 | (s->power[3] & 0x3003);
  2558. case 0x8f0: /* PRCM_IRQSTATUS_DSP */
  2559. return s->irqst[1];
  2560. case 0x8f4: /* PRCM_IRQENABLE_DSP */
  2561. return s->irqen[1];
  2562. case 0x8f8: /* PRCM_IRQSTATUS_IVA */
  2563. return s->irqst[2];
  2564. case 0x8fc: /* PRCM_IRQENABLE_IVA */
  2565. return s->irqen[2];
  2566. }
  2567. OMAP_BAD_REG(addr);
  2568. return 0;
  2569. }
  2570. static void omap_prcm_apll_update(struct omap_prcm_s *s)
  2571. {
  2572. int mode[2];
  2573. mode[0] = (s->clken[9] >> 6) & 3;
  2574. s->apll_lock[0] = (mode[0] == 3);
  2575. mode[1] = (s->clken[9] >> 2) & 3;
  2576. s->apll_lock[1] = (mode[1] == 3);
  2577. /* TODO: update clocks */
  2578. if (mode[0] == 1 || mode[0] == 2 || mode[1] == 1 || mode[2] == 2)
  2579. fprintf(stderr, "%s: bad EN_54M_PLL or bad EN_96M_PLL\n",
  2580. __FUNCTION__);
  2581. }
  2582. static void omap_prcm_dpll_update(struct omap_prcm_s *s)
  2583. {
  2584. omap_clk dpll = omap_findclk(s->mpu, "dpll");
  2585. omap_clk dpll_x2 = omap_findclk(s->mpu, "dpll");
  2586. omap_clk core = omap_findclk(s->mpu, "core_clk");
  2587. int mode = (s->clken[9] >> 0) & 3;
  2588. int mult, div;
  2589. mult = (s->clksel[5] >> 12) & 0x3ff;
  2590. div = (s->clksel[5] >> 8) & 0xf;
  2591. if (mult == 0 || mult == 1)
  2592. mode = 1; /* Bypass */
  2593. s->dpll_lock = 0;
  2594. switch (mode) {
  2595. case 0:
  2596. fprintf(stderr, "%s: bad EN_DPLL\n", __FUNCTION__);
  2597. break;
  2598. case 1: /* Low-power bypass mode (Default) */
  2599. case 2: /* Fast-relock bypass mode */
  2600. omap_clk_setrate(dpll, 1, 1);
  2601. omap_clk_setrate(dpll_x2, 1, 1);
  2602. break;
  2603. case 3: /* Lock mode */
  2604. s->dpll_lock = 1; /* After 20 FINT cycles (ref_clk / (div + 1)). */
  2605. omap_clk_setrate(dpll, div + 1, mult);
  2606. omap_clk_setrate(dpll_x2, div + 1, mult * 2);
  2607. break;
  2608. }
  2609. switch ((s->clksel[6] >> 0) & 3) {
  2610. case 0:
  2611. omap_clk_reparent(core, omap_findclk(s->mpu, "clk32-kHz"));
  2612. break;
  2613. case 1:
  2614. omap_clk_reparent(core, dpll);
  2615. break;
  2616. case 2:
  2617. /* Default */
  2618. omap_clk_reparent(core, dpll_x2);
  2619. break;
  2620. case 3:
  2621. fprintf(stderr, "%s: bad CORE_CLK_SRC\n", __FUNCTION__);
  2622. break;
  2623. }
  2624. }
  2625. static void omap_prcm_write(void *opaque, target_phys_addr_t addr,
  2626. uint32_t value)
  2627. {
  2628. struct omap_prcm_s *s = (struct omap_prcm_s *) opaque;
  2629. switch (addr) {
  2630. case 0x000: /* PRCM_REVISION */
  2631. case 0x054: /* PRCM_VOLTST */
  2632. case 0x084: /* PRCM_CLKCFG_STATUS */
  2633. case 0x1e4: /* PM_PWSTST_MPU */
  2634. case 0x220: /* CM_IDLEST1_CORE */
  2635. case 0x224: /* CM_IDLEST2_CORE */
  2636. case 0x22c: /* CM_IDLEST4_CORE */
  2637. case 0x2c8: /* PM_WKDEP_CORE */
  2638. case 0x2e4: /* PM_PWSTST_CORE */
  2639. case 0x320: /* CM_IDLEST_GFX */
  2640. case 0x3e4: /* PM_PWSTST_GFX */
  2641. case 0x420: /* CM_IDLEST_WKUP */
  2642. case 0x520: /* CM_IDLEST_CKGEN */
  2643. case 0x820: /* CM_IDLEST_DSP */
  2644. case 0x8e4: /* PM_PWSTST_DSP */
  2645. OMAP_RO_REG(addr);
  2646. return;
  2647. case 0x010: /* PRCM_SYSCONFIG */
  2648. s->sysconfig = value & 1;
  2649. break;
  2650. case 0x018: /* PRCM_IRQSTATUS_MPU */
  2651. s->irqst[0] &= ~value;
  2652. omap_prcm_int_update(s, 0);
  2653. break;
  2654. case 0x01c: /* PRCM_IRQENABLE_MPU */
  2655. s->irqen[0] = value & 0x3f;
  2656. omap_prcm_int_update(s, 0);
  2657. break;
  2658. case 0x050: /* PRCM_VOLTCTRL */
  2659. s->voltctrl = value & 0xf1c3;
  2660. break;
  2661. case 0x060: /* PRCM_CLKSRC_CTRL */
  2662. s->clksrc[0] = value & 0xdb;
  2663. /* TODO update clocks */
  2664. break;
  2665. case 0x070: /* PRCM_CLKOUT_CTRL */
  2666. s->clkout[0] = value & 0xbbbb;
  2667. /* TODO update clocks */
  2668. break;
  2669. case 0x078: /* PRCM_CLKEMUL_CTRL */
  2670. s->clkemul[0] = value & 1;
  2671. /* TODO update clocks */
  2672. break;
  2673. case 0x080: /* PRCM_CLKCFG_CTRL */
  2674. break;
  2675. case 0x090: /* PRCM_VOLTSETUP */
  2676. s->setuptime[0] = value & 0xffff;
  2677. break;
  2678. case 0x094: /* PRCM_CLKSSETUP */
  2679. s->setuptime[1] = value & 0xffff;
  2680. break;
  2681. case 0x098: /* PRCM_POLCTRL */
  2682. s->clkpol[0] = value & 0x701;
  2683. break;
  2684. case 0x0b0: /* GENERAL_PURPOSE1 */
  2685. case 0x0b4: /* GENERAL_PURPOSE2 */
  2686. case 0x0b8: /* GENERAL_PURPOSE3 */
  2687. case 0x0bc: /* GENERAL_PURPOSE4 */
  2688. case 0x0c0: /* GENERAL_PURPOSE5 */
  2689. case 0x0c4: /* GENERAL_PURPOSE6 */
  2690. case 0x0c8: /* GENERAL_PURPOSE7 */
  2691. case 0x0cc: /* GENERAL_PURPOSE8 */
  2692. case 0x0d0: /* GENERAL_PURPOSE9 */
  2693. case 0x0d4: /* GENERAL_PURPOSE10 */
  2694. case 0x0d8: /* GENERAL_PURPOSE11 */
  2695. case 0x0dc: /* GENERAL_PURPOSE12 */
  2696. case 0x0e0: /* GENERAL_PURPOSE13 */
  2697. case 0x0e4: /* GENERAL_PURPOSE14 */
  2698. case 0x0e8: /* GENERAL_PURPOSE15 */
  2699. case 0x0ec: /* GENERAL_PURPOSE16 */
  2700. case 0x0f0: /* GENERAL_PURPOSE17 */
  2701. case 0x0f4: /* GENERAL_PURPOSE18 */
  2702. case 0x0f8: /* GENERAL_PURPOSE19 */
  2703. case 0x0fc: /* GENERAL_PURPOSE20 */
  2704. s->scratch[(addr - 0xb0) >> 2] = value;
  2705. break;
  2706. case 0x140: /* CM_CLKSEL_MPU */
  2707. s->clksel[0] = value & 0x1f;
  2708. /* TODO update clocks */
  2709. break;
  2710. case 0x148: /* CM_CLKSTCTRL_MPU */
  2711. s->clkctrl[0] = value & 0x1f;
  2712. break;
  2713. case 0x158: /* RM_RSTST_MPU */
  2714. s->rst[0] &= ~value;
  2715. break;
  2716. case 0x1c8: /* PM_WKDEP_MPU */
  2717. s->wkup[0] = value & 0x15;
  2718. break;
  2719. case 0x1d4: /* PM_EVGENCTRL_MPU */
  2720. s->ev = value & 0x1f;
  2721. break;
  2722. case 0x1d8: /* PM_EVEGENONTIM_MPU */
  2723. s->evtime[0] = value;
  2724. break;
  2725. case 0x1dc: /* PM_EVEGENOFFTIM_MPU */
  2726. s->evtime[1] = value;
  2727. break;
  2728. case 0x1e0: /* PM_PWSTCTRL_MPU */
  2729. s->power[0] = value & 0xc0f;
  2730. break;
  2731. case 0x200: /* CM_FCLKEN1_CORE */
  2732. s->clken[0] = value & 0xbfffffff;
  2733. /* TODO update clocks */
  2734. /* The EN_EAC bit only gets/puts func_96m_clk. */
  2735. break;
  2736. case 0x204: /* CM_FCLKEN2_CORE */
  2737. s->clken[1] = value & 0x00000007;
  2738. /* TODO update clocks */
  2739. break;
  2740. case 0x210: /* CM_ICLKEN1_CORE */
  2741. s->clken[2] = value & 0xfffffff9;
  2742. /* TODO update clocks */
  2743. /* The EN_EAC bit only gets/puts core_l4_iclk. */
  2744. break;
  2745. case 0x214: /* CM_ICLKEN2_CORE */
  2746. s->clken[3] = value & 0x00000007;
  2747. /* TODO update clocks */
  2748. break;
  2749. case 0x21c: /* CM_ICLKEN4_CORE */
  2750. s->clken[4] = value & 0x0000001f;
  2751. /* TODO update clocks */
  2752. break;
  2753. case 0x230: /* CM_AUTOIDLE1_CORE */
  2754. s->clkidle[0] = value & 0xfffffff9;
  2755. /* TODO update clocks */
  2756. break;
  2757. case 0x234: /* CM_AUTOIDLE2_CORE */
  2758. s->clkidle[1] = value & 0x00000007;
  2759. /* TODO update clocks */
  2760. break;
  2761. case 0x238: /* CM_AUTOIDLE3_CORE */
  2762. s->clkidle[2] = value & 0x00000007;
  2763. /* TODO update clocks */
  2764. break;
  2765. case 0x23c: /* CM_AUTOIDLE4_CORE */
  2766. s->clkidle[3] = value & 0x0000001f;
  2767. /* TODO update clocks */
  2768. break;
  2769. case 0x240: /* CM_CLKSEL1_CORE */
  2770. s->clksel[1] = value & 0x0fffbf7f;
  2771. /* TODO update clocks */
  2772. break;
  2773. case 0x244: /* CM_CLKSEL2_CORE */
  2774. s->clksel[2] = value & 0x00fffffc;
  2775. /* TODO update clocks */
  2776. break;
  2777. case 0x248: /* CM_CLKSTCTRL_CORE */
  2778. s->clkctrl[1] = value & 0x7;
  2779. break;
  2780. case 0x2a0: /* PM_WKEN1_CORE */
  2781. s->wken[0] = value & 0x04667ff8;
  2782. break;
  2783. case 0x2a4: /* PM_WKEN2_CORE */
  2784. s->wken[1] = value & 0x00000005;
  2785. break;
  2786. case 0x2b0: /* PM_WKST1_CORE */
  2787. s->wkst[0] &= ~value;
  2788. break;
  2789. case 0x2b4: /* PM_WKST2_CORE */
  2790. s->wkst[1] &= ~value;
  2791. break;
  2792. case 0x2e0: /* PM_PWSTCTRL_CORE */
  2793. s->power[1] = (value & 0x00fc3f) | (1 << 2);
  2794. break;
  2795. case 0x300: /* CM_FCLKEN_GFX */
  2796. s->clken[5] = value & 6;
  2797. /* TODO update clocks */
  2798. break;
  2799. case 0x310: /* CM_ICLKEN_GFX */
  2800. s->clken[6] = value & 1;
  2801. /* TODO update clocks */
  2802. break;
  2803. case 0x340: /* CM_CLKSEL_GFX */
  2804. s->clksel[3] = value & 7;
  2805. /* TODO update clocks */
  2806. break;
  2807. case 0x348: /* CM_CLKSTCTRL_GFX */
  2808. s->clkctrl[2] = value & 1;
  2809. break;
  2810. case 0x350: /* RM_RSTCTRL_GFX */
  2811. s->rstctrl[0] = value & 1;
  2812. /* TODO: reset */
  2813. break;
  2814. case 0x358: /* RM_RSTST_GFX */
  2815. s->rst[1] &= ~value;
  2816. break;
  2817. case 0x3c8: /* PM_WKDEP_GFX */
  2818. s->wkup[1] = value & 0x13;
  2819. break;
  2820. case 0x3e0: /* PM_PWSTCTRL_GFX */
  2821. s->power[2] = (value & 0x00c0f) | (3 << 2);
  2822. break;
  2823. case 0x400: /* CM_FCLKEN_WKUP */
  2824. s->clken[7] = value & 0xd;
  2825. /* TODO update clocks */
  2826. break;
  2827. case 0x410: /* CM_ICLKEN_WKUP */
  2828. s->clken[8] = value & 0x3f;
  2829. /* TODO update clocks */
  2830. break;
  2831. case 0x430: /* CM_AUTOIDLE_WKUP */
  2832. s->clkidle[4] = value & 0x0000003f;
  2833. /* TODO update clocks */
  2834. break;
  2835. case 0x440: /* CM_CLKSEL_WKUP */
  2836. s->clksel[4] = value & 3;
  2837. /* TODO update clocks */
  2838. break;
  2839. case 0x450: /* RM_RSTCTRL_WKUP */
  2840. /* TODO: reset */
  2841. if (value & 2)
  2842. qemu_system_reset_request();
  2843. break;
  2844. case 0x454: /* RM_RSTTIME_WKUP */
  2845. s->rsttime_wkup = value & 0x1fff;
  2846. break;
  2847. case 0x458: /* RM_RSTST_WKUP */
  2848. s->rst[2] &= ~value;
  2849. break;
  2850. case 0x4a0: /* PM_WKEN_WKUP */
  2851. s->wken[2] = value & 0x00000005;
  2852. break;
  2853. case 0x4b0: /* PM_WKST_WKUP */
  2854. s->wkst[2] &= ~value;
  2855. break;
  2856. case 0x500: /* CM_CLKEN_PLL */
  2857. if (value & 0xffffff30)
  2858. fprintf(stderr, "%s: write 0s in CM_CLKEN_PLL for "
  2859. "future compatiblity\n", __FUNCTION__);
  2860. if ((s->clken[9] ^ value) & 0xcc) {
  2861. s->clken[9] &= ~0xcc;
  2862. s->clken[9] |= value & 0xcc;
  2863. omap_prcm_apll_update(s);
  2864. }
  2865. if ((s->clken[9] ^ value) & 3) {
  2866. s->clken[9] &= ~3;
  2867. s->clken[9] |= value & 3;
  2868. omap_prcm_dpll_update(s);
  2869. }
  2870. break;
  2871. case 0x530: /* CM_AUTOIDLE_PLL */
  2872. s->clkidle[5] = value & 0x000000cf;
  2873. /* TODO update clocks */
  2874. break;
  2875. case 0x540: /* CM_CLKSEL1_PLL */
  2876. if (value & 0xfc4000d7)
  2877. fprintf(stderr, "%s: write 0s in CM_CLKSEL1_PLL for "
  2878. "future compatiblity\n", __FUNCTION__);
  2879. if ((s->clksel[5] ^ value) & 0x003fff00) {
  2880. s->clksel[5] = value & 0x03bfff28;
  2881. omap_prcm_dpll_update(s);
  2882. }
  2883. /* TODO update the other clocks */
  2884. s->clksel[5] = value & 0x03bfff28;
  2885. break;
  2886. case 0x544: /* CM_CLKSEL2_PLL */
  2887. if (value & ~3)
  2888. fprintf(stderr, "%s: write 0s in CM_CLKSEL2_PLL[31:2] for "
  2889. "future compatiblity\n", __FUNCTION__);
  2890. if (s->clksel[6] != (value & 3)) {
  2891. s->clksel[6] = value & 3;
  2892. omap_prcm_dpll_update(s);
  2893. }
  2894. break;
  2895. case 0x800: /* CM_FCLKEN_DSP */
  2896. s->clken[10] = value & 0x501;
  2897. /* TODO update clocks */
  2898. break;
  2899. case 0x810: /* CM_ICLKEN_DSP */
  2900. s->clken[11] = value & 0x2;
  2901. /* TODO update clocks */
  2902. break;
  2903. case 0x830: /* CM_AUTOIDLE_DSP */
  2904. s->clkidle[6] = value & 0x2;
  2905. /* TODO update clocks */
  2906. break;
  2907. case 0x840: /* CM_CLKSEL_DSP */
  2908. s->clksel[7] = value & 0x3fff;
  2909. /* TODO update clocks */
  2910. break;
  2911. case 0x848: /* CM_CLKSTCTRL_DSP */
  2912. s->clkctrl[3] = value & 0x101;
  2913. break;
  2914. case 0x850: /* RM_RSTCTRL_DSP */
  2915. /* TODO: reset */
  2916. break;
  2917. case 0x858: /* RM_RSTST_DSP */
  2918. s->rst[3] &= ~value;
  2919. break;
  2920. case 0x8c8: /* PM_WKDEP_DSP */
  2921. s->wkup[2] = value & 0x13;
  2922. break;
  2923. case 0x8e0: /* PM_PWSTCTRL_DSP */
  2924. s->power[3] = (value & 0x03017) | (3 << 2);
  2925. break;
  2926. case 0x8f0: /* PRCM_IRQSTATUS_DSP */
  2927. s->irqst[1] &= ~value;
  2928. omap_prcm_int_update(s, 1);
  2929. break;
  2930. case 0x8f4: /* PRCM_IRQENABLE_DSP */
  2931. s->irqen[1] = value & 0x7;
  2932. omap_prcm_int_update(s, 1);
  2933. break;
  2934. case 0x8f8: /* PRCM_IRQSTATUS_IVA */
  2935. s->irqst[2] &= ~value;
  2936. omap_prcm_int_update(s, 2);
  2937. break;
  2938. case 0x8fc: /* PRCM_IRQENABLE_IVA */
  2939. s->irqen[2] = value & 0x7;
  2940. omap_prcm_int_update(s, 2);
  2941. break;
  2942. default:
  2943. OMAP_BAD_REG(addr);
  2944. return;
  2945. }
  2946. }
  2947. static CPUReadMemoryFunc *omap_prcm_readfn[] = {
  2948. omap_badwidth_read32,
  2949. omap_badwidth_read32,
  2950. omap_prcm_read,
  2951. };
  2952. static CPUWriteMemoryFunc *omap_prcm_writefn[] = {
  2953. omap_badwidth_write32,
  2954. omap_badwidth_write32,
  2955. omap_prcm_write,
  2956. };
  2957. static void omap_prcm_reset(struct omap_prcm_s *s)
  2958. {
  2959. s->sysconfig = 0;
  2960. s->irqst[0] = 0;
  2961. s->irqst[1] = 0;
  2962. s->irqst[2] = 0;
  2963. s->irqen[0] = 0;
  2964. s->irqen[1] = 0;
  2965. s->irqen[2] = 0;
  2966. s->voltctrl = 0x1040;
  2967. s->ev = 0x14;
  2968. s->evtime[0] = 0;
  2969. s->evtime[1] = 0;
  2970. s->clkctrl[0] = 0;
  2971. s->clkctrl[1] = 0;
  2972. s->clkctrl[2] = 0;
  2973. s->clkctrl[3] = 0;
  2974. s->clken[1] = 7;
  2975. s->clken[3] = 7;
  2976. s->clken[4] = 0;
  2977. s->clken[5] = 0;
  2978. s->clken[6] = 0;
  2979. s->clken[7] = 0xc;
  2980. s->clken[8] = 0x3e;
  2981. s->clken[9] = 0x0d;
  2982. s->clken[10] = 0;
  2983. s->clken[11] = 0;
  2984. s->clkidle[0] = 0;
  2985. s->clkidle[2] = 7;
  2986. s->clkidle[3] = 0;
  2987. s->clkidle[4] = 0;
  2988. s->clkidle[5] = 0x0c;
  2989. s->clkidle[6] = 0;
  2990. s->clksel[0] = 0x01;
  2991. s->clksel[1] = 0x02100121;
  2992. s->clksel[2] = 0x00000000;
  2993. s->clksel[3] = 0x01;
  2994. s->clksel[4] = 0;
  2995. s->clksel[7] = 0x0121;
  2996. s->wkup[0] = 0x15;
  2997. s->wkup[1] = 0x13;
  2998. s->wkup[2] = 0x13;
  2999. s->wken[0] = 0x04667ff8;
  3000. s->wken[1] = 0x00000005;
  3001. s->wken[2] = 5;
  3002. s->wkst[0] = 0;
  3003. s->wkst[1] = 0;
  3004. s->wkst[2] = 0;
  3005. s->power[0] = 0x00c;
  3006. s->power[1] = 4;
  3007. s->power[2] = 0x0000c;
  3008. s->power[3] = 0x14;
  3009. s->rstctrl[0] = 1;
  3010. s->rst[3] = 1;
  3011. omap_prcm_apll_update(s);
  3012. omap_prcm_dpll_update(s);
  3013. }
  3014. static void omap_prcm_coldreset(struct omap_prcm_s *s)
  3015. {
  3016. s->setuptime[0] = 0;
  3017. s->setuptime[1] = 0;
  3018. memset(&s->scratch, 0, sizeof(s->scratch));
  3019. s->rst[0] = 0x01;
  3020. s->rst[1] = 0x00;
  3021. s->rst[2] = 0x01;
  3022. s->clken[0] = 0;
  3023. s->clken[2] = 0;
  3024. s->clkidle[1] = 0;
  3025. s->clksel[5] = 0;
  3026. s->clksel[6] = 2;
  3027. s->clksrc[0] = 0x43;
  3028. s->clkout[0] = 0x0303;
  3029. s->clkemul[0] = 0;
  3030. s->clkpol[0] = 0x100;
  3031. s->rsttime_wkup = 0x1002;
  3032. omap_prcm_reset(s);
  3033. }
  3034. struct omap_prcm_s *omap_prcm_init(struct omap_target_agent_s *ta,
  3035. qemu_irq mpu_int, qemu_irq dsp_int, qemu_irq iva_int,
  3036. struct omap_mpu_state_s *mpu)
  3037. {
  3038. int iomemtype;
  3039. struct omap_prcm_s *s = (struct omap_prcm_s *)
  3040. qemu_mallocz(sizeof(struct omap_prcm_s));
  3041. s->irq[0] = mpu_int;
  3042. s->irq[1] = dsp_int;
  3043. s->irq[2] = iva_int;
  3044. s->mpu = mpu;
  3045. omap_prcm_coldreset(s);
  3046. iomemtype = l4_register_io_memory(0, omap_prcm_readfn,
  3047. omap_prcm_writefn, s);
  3048. omap_l4_attach(ta, 0, iomemtype);
  3049. omap_l4_attach(ta, 1, iomemtype);
  3050. return s;
  3051. }
  3052. /* System and Pinout control */
  3053. struct omap_sysctl_s {
  3054. struct omap_mpu_state_s *mpu;
  3055. uint32_t sysconfig;
  3056. uint32_t devconfig;
  3057. uint32_t psaconfig;
  3058. uint32_t padconf[0x45];
  3059. uint8_t obs;
  3060. uint32_t msuspendmux[5];
  3061. };
  3062. static uint32_t omap_sysctl_read8(void *opaque, target_phys_addr_t addr)
  3063. {
  3064. struct omap_sysctl_s *s = (struct omap_sysctl_s *) opaque;
  3065. int pad_offset, byte_offset;
  3066. int value;
  3067. switch (addr) {
  3068. case 0x030 ... 0x140: /* CONTROL_PADCONF - only used in the POP */
  3069. pad_offset = (addr - 0x30) >> 2;
  3070. byte_offset = (addr - 0x30) & (4 - 1);
  3071. value = s->padconf[pad_offset];
  3072. value = (value >> (byte_offset * 8)) & 0xff;
  3073. return value;
  3074. default:
  3075. break;
  3076. }
  3077. OMAP_BAD_REG(addr);
  3078. return 0;
  3079. }
  3080. static uint32_t omap_sysctl_read(void *opaque, target_phys_addr_t addr)
  3081. {
  3082. struct omap_sysctl_s *s = (struct omap_sysctl_s *) opaque;
  3083. switch (addr) {
  3084. case 0x000: /* CONTROL_REVISION */
  3085. return 0x20;
  3086. case 0x010: /* CONTROL_SYSCONFIG */
  3087. return s->sysconfig;
  3088. case 0x030 ... 0x140: /* CONTROL_PADCONF - only used in the POP */
  3089. return s->padconf[(addr - 0x30) >> 2];
  3090. case 0x270: /* CONTROL_DEBOBS */
  3091. return s->obs;
  3092. case 0x274: /* CONTROL_DEVCONF */
  3093. return s->devconfig;
  3094. case 0x28c: /* CONTROL_EMU_SUPPORT */
  3095. return 0;
  3096. case 0x290: /* CONTROL_MSUSPENDMUX_0 */
  3097. return s->msuspendmux[0];
  3098. case 0x294: /* CONTROL_MSUSPENDMUX_1 */
  3099. return s->msuspendmux[1];
  3100. case 0x298: /* CONTROL_MSUSPENDMUX_2 */
  3101. return s->msuspendmux[2];
  3102. case 0x29c: /* CONTROL_MSUSPENDMUX_3 */
  3103. return s->msuspendmux[3];
  3104. case 0x2a0: /* CONTROL_MSUSPENDMUX_4 */
  3105. return s->msuspendmux[4];
  3106. case 0x2a4: /* CONTROL_MSUSPENDMUX_5 */
  3107. return 0;
  3108. case 0x2b8: /* CONTROL_PSA_CTRL */
  3109. return s->psaconfig;
  3110. case 0x2bc: /* CONTROL_PSA_CMD */
  3111. case 0x2c0: /* CONTROL_PSA_VALUE */
  3112. return 0;
  3113. case 0x2b0: /* CONTROL_SEC_CTRL */
  3114. return 0x800000f1;
  3115. case 0x2d0: /* CONTROL_SEC_EMU */
  3116. return 0x80000015;
  3117. case 0x2d4: /* CONTROL_SEC_TAP */
  3118. return 0x8000007f;
  3119. case 0x2b4: /* CONTROL_SEC_TEST */
  3120. case 0x2f0: /* CONTROL_SEC_STATUS */
  3121. case 0x2f4: /* CONTROL_SEC_ERR_STATUS */
  3122. /* Secure mode is not present on general-pusrpose device. Outside
  3123. * secure mode these values cannot be read or written. */
  3124. return 0;
  3125. case 0x2d8: /* CONTROL_OCM_RAM_PERM */
  3126. return 0xff;
  3127. case 0x2dc: /* CONTROL_OCM_PUB_RAM_ADD */
  3128. case 0x2e0: /* CONTROL_EXT_SEC_RAM_START_ADD */
  3129. case 0x2e4: /* CONTROL_EXT_SEC_RAM_STOP_ADD */
  3130. /* No secure mode so no Extended Secure RAM present. */
  3131. return 0;
  3132. case 0x2f8: /* CONTROL_STATUS */
  3133. /* Device Type => General-purpose */
  3134. return 0x0300;
  3135. case 0x2fc: /* CONTROL_GENERAL_PURPOSE_STATUS */
  3136. case 0x300: /* CONTROL_RPUB_KEY_H_0 */
  3137. case 0x304: /* CONTROL_RPUB_KEY_H_1 */
  3138. case 0x308: /* CONTROL_RPUB_KEY_H_2 */
  3139. case 0x30c: /* CONTROL_RPUB_KEY_H_3 */
  3140. return 0xdecafbad;
  3141. case 0x310: /* CONTROL_RAND_KEY_0 */
  3142. case 0x314: /* CONTROL_RAND_KEY_1 */
  3143. case 0x318: /* CONTROL_RAND_KEY_2 */
  3144. case 0x31c: /* CONTROL_RAND_KEY_3 */
  3145. case 0x320: /* CONTROL_CUST_KEY_0 */
  3146. case 0x324: /* CONTROL_CUST_KEY_1 */
  3147. case 0x330: /* CONTROL_TEST_KEY_0 */
  3148. case 0x334: /* CONTROL_TEST_KEY_1 */
  3149. case 0x338: /* CONTROL_TEST_KEY_2 */
  3150. case 0x33c: /* CONTROL_TEST_KEY_3 */
  3151. case 0x340: /* CONTROL_TEST_KEY_4 */
  3152. case 0x344: /* CONTROL_TEST_KEY_5 */
  3153. case 0x348: /* CONTROL_TEST_KEY_6 */
  3154. case 0x34c: /* CONTROL_TEST_KEY_7 */
  3155. case 0x350: /* CONTROL_TEST_KEY_8 */
  3156. case 0x354: /* CONTROL_TEST_KEY_9 */
  3157. /* Can only be accessed in secure mode and when C_FieldAccEnable
  3158. * bit is set in CONTROL_SEC_CTRL.
  3159. * TODO: otherwise an interconnect access error is generated. */
  3160. return 0;
  3161. }
  3162. OMAP_BAD_REG(addr);
  3163. return 0;
  3164. }
  3165. static void omap_sysctl_write8(void *opaque, target_phys_addr_t addr,
  3166. uint32_t value)
  3167. {
  3168. struct omap_sysctl_s *s = (struct omap_sysctl_s *) opaque;
  3169. int pad_offset, byte_offset;
  3170. int prev_value;
  3171. switch (addr) {
  3172. case 0x030 ... 0x140: /* CONTROL_PADCONF - only used in the POP */
  3173. pad_offset = (addr - 0x30) >> 2;
  3174. byte_offset = (addr - 0x30) & (4 - 1);
  3175. prev_value = s->padconf[pad_offset];
  3176. prev_value &= ~(0xff << (byte_offset * 8));
  3177. prev_value |= ((value & 0x1f1f1f1f) << (byte_offset * 8)) & 0x1f1f1f1f;
  3178. s->padconf[pad_offset] = prev_value;
  3179. break;
  3180. default:
  3181. OMAP_BAD_REG(addr);
  3182. break;
  3183. }
  3184. }
  3185. static void omap_sysctl_write(void *opaque, target_phys_addr_t addr,
  3186. uint32_t value)
  3187. {
  3188. struct omap_sysctl_s *s = (struct omap_sysctl_s *) opaque;
  3189. switch (addr) {
  3190. case 0x000: /* CONTROL_REVISION */
  3191. case 0x2a4: /* CONTROL_MSUSPENDMUX_5 */
  3192. case 0x2c0: /* CONTROL_PSA_VALUE */
  3193. case 0x2f8: /* CONTROL_STATUS */
  3194. case 0x2fc: /* CONTROL_GENERAL_PURPOSE_STATUS */
  3195. case 0x300: /* CONTROL_RPUB_KEY_H_0 */
  3196. case 0x304: /* CONTROL_RPUB_KEY_H_1 */
  3197. case 0x308: /* CONTROL_RPUB_KEY_H_2 */
  3198. case 0x30c: /* CONTROL_RPUB_KEY_H_3 */
  3199. case 0x310: /* CONTROL_RAND_KEY_0 */
  3200. case 0x314: /* CONTROL_RAND_KEY_1 */
  3201. case 0x318: /* CONTROL_RAND_KEY_2 */
  3202. case 0x31c: /* CONTROL_RAND_KEY_3 */
  3203. case 0x320: /* CONTROL_CUST_KEY_0 */
  3204. case 0x324: /* CONTROL_CUST_KEY_1 */
  3205. case 0x330: /* CONTROL_TEST_KEY_0 */
  3206. case 0x334: /* CONTROL_TEST_KEY_1 */
  3207. case 0x338: /* CONTROL_TEST_KEY_2 */
  3208. case 0x33c: /* CONTROL_TEST_KEY_3 */
  3209. case 0x340: /* CONTROL_TEST_KEY_4 */
  3210. case 0x344: /* CONTROL_TEST_KEY_5 */
  3211. case 0x348: /* CONTROL_TEST_KEY_6 */
  3212. case 0x34c: /* CONTROL_TEST_KEY_7 */
  3213. case 0x350: /* CONTROL_TEST_KEY_8 */
  3214. case 0x354: /* CONTROL_TEST_KEY_9 */
  3215. OMAP_RO_REG(addr);
  3216. return;
  3217. case 0x010: /* CONTROL_SYSCONFIG */
  3218. s->sysconfig = value & 0x1e;
  3219. break;
  3220. case 0x030 ... 0x140: /* CONTROL_PADCONF - only used in the POP */
  3221. /* XXX: should check constant bits */
  3222. s->padconf[(addr - 0x30) >> 2] = value & 0x1f1f1f1f;
  3223. break;
  3224. case 0x270: /* CONTROL_DEBOBS */
  3225. s->obs = value & 0xff;
  3226. break;
  3227. case 0x274: /* CONTROL_DEVCONF */
  3228. s->devconfig = value & 0xffffc7ff;
  3229. break;
  3230. case 0x28c: /* CONTROL_EMU_SUPPORT */
  3231. break;
  3232. case 0x290: /* CONTROL_MSUSPENDMUX_0 */
  3233. s->msuspendmux[0] = value & 0x3fffffff;
  3234. break;
  3235. case 0x294: /* CONTROL_MSUSPENDMUX_1 */
  3236. s->msuspendmux[1] = value & 0x3fffffff;
  3237. break;
  3238. case 0x298: /* CONTROL_MSUSPENDMUX_2 */
  3239. s->msuspendmux[2] = value & 0x3fffffff;
  3240. break;
  3241. case 0x29c: /* CONTROL_MSUSPENDMUX_3 */
  3242. s->msuspendmux[3] = value & 0x3fffffff;
  3243. break;
  3244. case 0x2a0: /* CONTROL_MSUSPENDMUX_4 */
  3245. s->msuspendmux[4] = value & 0x3fffffff;
  3246. break;
  3247. case 0x2b8: /* CONTROL_PSA_CTRL */
  3248. s->psaconfig = value & 0x1c;
  3249. s->psaconfig |= (value & 0x20) ? 2 : 1;
  3250. break;
  3251. case 0x2bc: /* CONTROL_PSA_CMD */
  3252. break;
  3253. case 0x2b0: /* CONTROL_SEC_CTRL */
  3254. case 0x2b4: /* CONTROL_SEC_TEST */
  3255. case 0x2d0: /* CONTROL_SEC_EMU */
  3256. case 0x2d4: /* CONTROL_SEC_TAP */
  3257. case 0x2d8: /* CONTROL_OCM_RAM_PERM */
  3258. case 0x2dc: /* CONTROL_OCM_PUB_RAM_ADD */
  3259. case 0x2e0: /* CONTROL_EXT_SEC_RAM_START_ADD */
  3260. case 0x2e4: /* CONTROL_EXT_SEC_RAM_STOP_ADD */
  3261. case 0x2f0: /* CONTROL_SEC_STATUS */
  3262. case 0x2f4: /* CONTROL_SEC_ERR_STATUS */
  3263. break;
  3264. default:
  3265. OMAP_BAD_REG(addr);
  3266. return;
  3267. }
  3268. }
  3269. static CPUReadMemoryFunc *omap_sysctl_readfn[] = {
  3270. omap_sysctl_read8,
  3271. omap_badwidth_read32, /* TODO */
  3272. omap_sysctl_read,
  3273. };
  3274. static CPUWriteMemoryFunc *omap_sysctl_writefn[] = {
  3275. omap_sysctl_write8,
  3276. omap_badwidth_write32, /* TODO */
  3277. omap_sysctl_write,
  3278. };
  3279. static void omap_sysctl_reset(struct omap_sysctl_s *s)
  3280. {
  3281. /* (power-on reset) */
  3282. s->sysconfig = 0;
  3283. s->obs = 0;
  3284. s->devconfig = 0x0c000000;
  3285. s->msuspendmux[0] = 0x00000000;
  3286. s->msuspendmux[1] = 0x00000000;
  3287. s->msuspendmux[2] = 0x00000000;
  3288. s->msuspendmux[3] = 0x00000000;
  3289. s->msuspendmux[4] = 0x00000000;
  3290. s->psaconfig = 1;
  3291. s->padconf[0x00] = 0x000f0f0f;
  3292. s->padconf[0x01] = 0x00000000;
  3293. s->padconf[0x02] = 0x00000000;
  3294. s->padconf[0x03] = 0x00000000;
  3295. s->padconf[0x04] = 0x00000000;
  3296. s->padconf[0x05] = 0x00000000;
  3297. s->padconf[0x06] = 0x00000000;
  3298. s->padconf[0x07] = 0x00000000;
  3299. s->padconf[0x08] = 0x08080800;
  3300. s->padconf[0x09] = 0x08080808;
  3301. s->padconf[0x0a] = 0x08080808;
  3302. s->padconf[0x0b] = 0x08080808;
  3303. s->padconf[0x0c] = 0x08080808;
  3304. s->padconf[0x0d] = 0x08080800;
  3305. s->padconf[0x0e] = 0x08080808;
  3306. s->padconf[0x0f] = 0x08080808;
  3307. s->padconf[0x10] = 0x18181808; /* | 0x07070700 if SBoot3 */
  3308. s->padconf[0x11] = 0x18181818; /* | 0x07070707 if SBoot3 */
  3309. s->padconf[0x12] = 0x18181818; /* | 0x07070707 if SBoot3 */
  3310. s->padconf[0x13] = 0x18181818; /* | 0x07070707 if SBoot3 */
  3311. s->padconf[0x14] = 0x18181818; /* | 0x00070707 if SBoot3 */
  3312. s->padconf[0x15] = 0x18181818;
  3313. s->padconf[0x16] = 0x18181818; /* | 0x07000000 if SBoot3 */
  3314. s->padconf[0x17] = 0x1f001f00;
  3315. s->padconf[0x18] = 0x1f1f1f1f;
  3316. s->padconf[0x19] = 0x00000000;
  3317. s->padconf[0x1a] = 0x1f180000;
  3318. s->padconf[0x1b] = 0x00001f1f;
  3319. s->padconf[0x1c] = 0x1f001f00;
  3320. s->padconf[0x1d] = 0x00000000;
  3321. s->padconf[0x1e] = 0x00000000;
  3322. s->padconf[0x1f] = 0x08000000;
  3323. s->padconf[0x20] = 0x08080808;
  3324. s->padconf[0x21] = 0x08080808;
  3325. s->padconf[0x22] = 0x0f080808;
  3326. s->padconf[0x23] = 0x0f0f0f0f;
  3327. s->padconf[0x24] = 0x000f0f0f;
  3328. s->padconf[0x25] = 0x1f1f1f0f;
  3329. s->padconf[0x26] = 0x080f0f1f;
  3330. s->padconf[0x27] = 0x070f1808;
  3331. s->padconf[0x28] = 0x0f070707;
  3332. s->padconf[0x29] = 0x000f0f1f;
  3333. s->padconf[0x2a] = 0x0f0f0f1f;
  3334. s->padconf[0x2b] = 0x08000000;
  3335. s->padconf[0x2c] = 0x0000001f;
  3336. s->padconf[0x2d] = 0x0f0f1f00;
  3337. s->padconf[0x2e] = 0x1f1f0f0f;
  3338. s->padconf[0x2f] = 0x0f1f1f1f;
  3339. s->padconf[0x30] = 0x0f0f0f0f;
  3340. s->padconf[0x31] = 0x0f1f0f1f;
  3341. s->padconf[0x32] = 0x0f0f0f0f;
  3342. s->padconf[0x33] = 0x0f1f0f1f;
  3343. s->padconf[0x34] = 0x1f1f0f0f;
  3344. s->padconf[0x35] = 0x0f0f1f1f;
  3345. s->padconf[0x36] = 0x0f0f1f0f;
  3346. s->padconf[0x37] = 0x0f0f0f0f;
  3347. s->padconf[0x38] = 0x1f18180f;
  3348. s->padconf[0x39] = 0x1f1f1f1f;
  3349. s->padconf[0x3a] = 0x00001f1f;
  3350. s->padconf[0x3b] = 0x00000000;
  3351. s->padconf[0x3c] = 0x00000000;
  3352. s->padconf[0x3d] = 0x0f0f0f0f;
  3353. s->padconf[0x3e] = 0x18000f0f;
  3354. s->padconf[0x3f] = 0x00070000;
  3355. s->padconf[0x40] = 0x00000707;
  3356. s->padconf[0x41] = 0x0f1f0700;
  3357. s->padconf[0x42] = 0x1f1f070f;
  3358. s->padconf[0x43] = 0x0008081f;
  3359. s->padconf[0x44] = 0x00000800;
  3360. }
  3361. struct omap_sysctl_s *omap_sysctl_init(struct omap_target_agent_s *ta,
  3362. omap_clk iclk, struct omap_mpu_state_s *mpu)
  3363. {
  3364. int iomemtype;
  3365. struct omap_sysctl_s *s = (struct omap_sysctl_s *)
  3366. qemu_mallocz(sizeof(struct omap_sysctl_s));
  3367. s->mpu = mpu;
  3368. omap_sysctl_reset(s);
  3369. iomemtype = l4_register_io_memory(0, omap_sysctl_readfn,
  3370. omap_sysctl_writefn, s);
  3371. omap_l4_attach(ta, 0, iomemtype);
  3372. return s;
  3373. }
  3374. /* SDRAM Controller Subsystem */
  3375. struct omap_sdrc_s {
  3376. uint8_t config;
  3377. };
  3378. static void omap_sdrc_reset(struct omap_sdrc_s *s)
  3379. {
  3380. s->config = 0x10;
  3381. }
  3382. static uint32_t omap_sdrc_read(void *opaque, target_phys_addr_t addr)
  3383. {
  3384. struct omap_sdrc_s *s = (struct omap_sdrc_s *) opaque;
  3385. switch (addr) {
  3386. case 0x00: /* SDRC_REVISION */
  3387. return 0x20;
  3388. case 0x10: /* SDRC_SYSCONFIG */
  3389. return s->config;
  3390. case 0x14: /* SDRC_SYSSTATUS */
  3391. return 1; /* RESETDONE */
  3392. case 0x40: /* SDRC_CS_CFG */
  3393. case 0x44: /* SDRC_SHARING */
  3394. case 0x48: /* SDRC_ERR_ADDR */
  3395. case 0x4c: /* SDRC_ERR_TYPE */
  3396. case 0x60: /* SDRC_DLLA_SCTRL */
  3397. case 0x64: /* SDRC_DLLA_STATUS */
  3398. case 0x68: /* SDRC_DLLB_CTRL */
  3399. case 0x6c: /* SDRC_DLLB_STATUS */
  3400. case 0x70: /* SDRC_POWER */
  3401. case 0x80: /* SDRC_MCFG_0 */
  3402. case 0x84: /* SDRC_MR_0 */
  3403. case 0x88: /* SDRC_EMR1_0 */
  3404. case 0x8c: /* SDRC_EMR2_0 */
  3405. case 0x90: /* SDRC_EMR3_0 */
  3406. case 0x94: /* SDRC_DCDL1_CTRL */
  3407. case 0x98: /* SDRC_DCDL2_CTRL */
  3408. case 0x9c: /* SDRC_ACTIM_CTRLA_0 */
  3409. case 0xa0: /* SDRC_ACTIM_CTRLB_0 */
  3410. case 0xa4: /* SDRC_RFR_CTRL_0 */
  3411. case 0xa8: /* SDRC_MANUAL_0 */
  3412. case 0xb0: /* SDRC_MCFG_1 */
  3413. case 0xb4: /* SDRC_MR_1 */
  3414. case 0xb8: /* SDRC_EMR1_1 */
  3415. case 0xbc: /* SDRC_EMR2_1 */
  3416. case 0xc0: /* SDRC_EMR3_1 */
  3417. case 0xc4: /* SDRC_ACTIM_CTRLA_1 */
  3418. case 0xc8: /* SDRC_ACTIM_CTRLB_1 */
  3419. case 0xd4: /* SDRC_RFR_CTRL_1 */
  3420. case 0xd8: /* SDRC_MANUAL_1 */
  3421. return 0x00;
  3422. }
  3423. OMAP_BAD_REG(addr);
  3424. return 0;
  3425. }
  3426. static void omap_sdrc_write(void *opaque, target_phys_addr_t addr,
  3427. uint32_t value)
  3428. {
  3429. struct omap_sdrc_s *s = (struct omap_sdrc_s *) opaque;
  3430. switch (addr) {
  3431. case 0x00: /* SDRC_REVISION */
  3432. case 0x14: /* SDRC_SYSSTATUS */
  3433. case 0x48: /* SDRC_ERR_ADDR */
  3434. case 0x64: /* SDRC_DLLA_STATUS */
  3435. case 0x6c: /* SDRC_DLLB_STATUS */
  3436. OMAP_RO_REG(addr);
  3437. return;
  3438. case 0x10: /* SDRC_SYSCONFIG */
  3439. if ((value >> 3) != 0x2)
  3440. fprintf(stderr, "%s: bad SDRAM idle mode %i\n",
  3441. __FUNCTION__, value >> 3);
  3442. if (value & 2)
  3443. omap_sdrc_reset(s);
  3444. s->config = value & 0x18;
  3445. break;
  3446. case 0x40: /* SDRC_CS_CFG */
  3447. case 0x44: /* SDRC_SHARING */
  3448. case 0x4c: /* SDRC_ERR_TYPE */
  3449. case 0x60: /* SDRC_DLLA_SCTRL */
  3450. case 0x68: /* SDRC_DLLB_CTRL */
  3451. case 0x70: /* SDRC_POWER */
  3452. case 0x80: /* SDRC_MCFG_0 */
  3453. case 0x84: /* SDRC_MR_0 */
  3454. case 0x88: /* SDRC_EMR1_0 */
  3455. case 0x8c: /* SDRC_EMR2_0 */
  3456. case 0x90: /* SDRC_EMR3_0 */
  3457. case 0x94: /* SDRC_DCDL1_CTRL */
  3458. case 0x98: /* SDRC_DCDL2_CTRL */
  3459. case 0x9c: /* SDRC_ACTIM_CTRLA_0 */
  3460. case 0xa0: /* SDRC_ACTIM_CTRLB_0 */
  3461. case 0xa4: /* SDRC_RFR_CTRL_0 */
  3462. case 0xa8: /* SDRC_MANUAL_0 */
  3463. case 0xb0: /* SDRC_MCFG_1 */
  3464. case 0xb4: /* SDRC_MR_1 */
  3465. case 0xb8: /* SDRC_EMR1_1 */
  3466. case 0xbc: /* SDRC_EMR2_1 */
  3467. case 0xc0: /* SDRC_EMR3_1 */
  3468. case 0xc4: /* SDRC_ACTIM_CTRLA_1 */
  3469. case 0xc8: /* SDRC_ACTIM_CTRLB_1 */
  3470. case 0xd4: /* SDRC_RFR_CTRL_1 */
  3471. case 0xd8: /* SDRC_MANUAL_1 */
  3472. break;
  3473. default:
  3474. OMAP_BAD_REG(addr);
  3475. return;
  3476. }
  3477. }
  3478. static CPUReadMemoryFunc *omap_sdrc_readfn[] = {
  3479. omap_badwidth_read32,
  3480. omap_badwidth_read32,
  3481. omap_sdrc_read,
  3482. };
  3483. static CPUWriteMemoryFunc *omap_sdrc_writefn[] = {
  3484. omap_badwidth_write32,
  3485. omap_badwidth_write32,
  3486. omap_sdrc_write,
  3487. };
  3488. struct omap_sdrc_s *omap_sdrc_init(target_phys_addr_t base)
  3489. {
  3490. int iomemtype;
  3491. struct omap_sdrc_s *s = (struct omap_sdrc_s *)
  3492. qemu_mallocz(sizeof(struct omap_sdrc_s));
  3493. omap_sdrc_reset(s);
  3494. iomemtype = cpu_register_io_memory(0, omap_sdrc_readfn,
  3495. omap_sdrc_writefn, s);
  3496. cpu_register_physical_memory(base, 0x1000, iomemtype);
  3497. return s;
  3498. }
  3499. /* General-Purpose Memory Controller */
  3500. struct omap_gpmc_s {
  3501. qemu_irq irq;
  3502. uint8_t sysconfig;
  3503. uint16_t irqst;
  3504. uint16_t irqen;
  3505. uint16_t timeout;
  3506. uint16_t config;
  3507. uint32_t prefconfig[2];
  3508. int prefcontrol;
  3509. int preffifo;
  3510. int prefcount;
  3511. struct omap_gpmc_cs_file_s {
  3512. uint32_t config[7];
  3513. target_phys_addr_t base;
  3514. size_t size;
  3515. int iomemtype;
  3516. void (*base_update)(void *opaque, target_phys_addr_t new);
  3517. void (*unmap)(void *opaque);
  3518. void *opaque;
  3519. } cs_file[8];
  3520. int ecc_cs;
  3521. int ecc_ptr;
  3522. uint32_t ecc_cfg;
  3523. struct ecc_state_s ecc[9];
  3524. };
  3525. static void omap_gpmc_int_update(struct omap_gpmc_s *s)
  3526. {
  3527. qemu_set_irq(s->irq, s->irqen & s->irqst);
  3528. }
  3529. static void omap_gpmc_cs_map(struct omap_gpmc_cs_file_s *f, int base, int mask)
  3530. {
  3531. /* TODO: check for overlapping regions and report access errors */
  3532. if ((mask != 0x8 && mask != 0xc && mask != 0xe && mask != 0xf) ||
  3533. (base < 0 || base >= 0x40) ||
  3534. (base & 0x0f & ~mask)) {
  3535. fprintf(stderr, "%s: wrong cs address mapping/decoding!\n",
  3536. __FUNCTION__);
  3537. return;
  3538. }
  3539. if (!f->opaque)
  3540. return;
  3541. f->base = base << 24;
  3542. f->size = (0x0fffffff & ~(mask << 24)) + 1;
  3543. /* TODO: rather than setting the size of the mapping (which should be
  3544. * constant), the mask should cause wrapping of the address space, so
  3545. * that the same memory becomes accessible at every <i>size</i> bytes
  3546. * starting from <i>base</i>. */
  3547. if (f->iomemtype)
  3548. cpu_register_physical_memory(f->base, f->size, f->iomemtype);
  3549. if (f->base_update)
  3550. f->base_update(f->opaque, f->base);
  3551. }
  3552. static void omap_gpmc_cs_unmap(struct omap_gpmc_cs_file_s *f)
  3553. {
  3554. if (f->size) {
  3555. if (f->unmap)
  3556. f->unmap(f->opaque);
  3557. if (f->iomemtype)
  3558. cpu_register_physical_memory(f->base, f->size, IO_MEM_UNASSIGNED);
  3559. f->base = 0;
  3560. f->size = 0;
  3561. }
  3562. }
  3563. static void omap_gpmc_reset(struct omap_gpmc_s *s)
  3564. {
  3565. int i;
  3566. s->sysconfig = 0;
  3567. s->irqst = 0;
  3568. s->irqen = 0;
  3569. omap_gpmc_int_update(s);
  3570. s->timeout = 0;
  3571. s->config = 0xa00;
  3572. s->prefconfig[0] = 0x00004000;
  3573. s->prefconfig[1] = 0x00000000;
  3574. s->prefcontrol = 0;
  3575. s->preffifo = 0;
  3576. s->prefcount = 0;
  3577. for (i = 0; i < 8; i ++) {
  3578. if (s->cs_file[i].config[6] & (1 << 6)) /* CSVALID */
  3579. omap_gpmc_cs_unmap(s->cs_file + i);
  3580. s->cs_file[i].config[0] = i ? 1 << 12 : 0;
  3581. s->cs_file[i].config[1] = 0x101001;
  3582. s->cs_file[i].config[2] = 0x020201;
  3583. s->cs_file[i].config[3] = 0x10031003;
  3584. s->cs_file[i].config[4] = 0x10f1111;
  3585. s->cs_file[i].config[5] = 0;
  3586. s->cs_file[i].config[6] = 0xf00 | (i ? 0 : 1 << 6);
  3587. if (s->cs_file[i].config[6] & (1 << 6)) /* CSVALID */
  3588. omap_gpmc_cs_map(&s->cs_file[i],
  3589. s->cs_file[i].config[6] & 0x1f, /* MASKADDR */
  3590. (s->cs_file[i].config[6] >> 8 & 0xf)); /* BASEADDR */
  3591. }
  3592. omap_gpmc_cs_map(s->cs_file, 0, 0xf);
  3593. s->ecc_cs = 0;
  3594. s->ecc_ptr = 0;
  3595. s->ecc_cfg = 0x3fcff000;
  3596. for (i = 0; i < 9; i ++)
  3597. ecc_reset(&s->ecc[i]);
  3598. }
  3599. static uint32_t omap_gpmc_read(void *opaque, target_phys_addr_t addr)
  3600. {
  3601. struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
  3602. int cs;
  3603. struct omap_gpmc_cs_file_s *f;
  3604. switch (addr) {
  3605. case 0x000: /* GPMC_REVISION */
  3606. return 0x20;
  3607. case 0x010: /* GPMC_SYSCONFIG */
  3608. return s->sysconfig;
  3609. case 0x014: /* GPMC_SYSSTATUS */
  3610. return 1; /* RESETDONE */
  3611. case 0x018: /* GPMC_IRQSTATUS */
  3612. return s->irqst;
  3613. case 0x01c: /* GPMC_IRQENABLE */
  3614. return s->irqen;
  3615. case 0x040: /* GPMC_TIMEOUT_CONTROL */
  3616. return s->timeout;
  3617. case 0x044: /* GPMC_ERR_ADDRESS */
  3618. case 0x048: /* GPMC_ERR_TYPE */
  3619. return 0;
  3620. case 0x050: /* GPMC_CONFIG */
  3621. return s->config;
  3622. case 0x054: /* GPMC_STATUS */
  3623. return 0x001;
  3624. case 0x060 ... 0x1d4:
  3625. cs = (addr - 0x060) / 0x30;
  3626. addr -= cs * 0x30;
  3627. f = s->cs_file + cs;
  3628. switch (addr) {
  3629. case 0x60: /* GPMC_CONFIG1 */
  3630. return f->config[0];
  3631. case 0x64: /* GPMC_CONFIG2 */
  3632. return f->config[1];
  3633. case 0x68: /* GPMC_CONFIG3 */
  3634. return f->config[2];
  3635. case 0x6c: /* GPMC_CONFIG4 */
  3636. return f->config[3];
  3637. case 0x70: /* GPMC_CONFIG5 */
  3638. return f->config[4];
  3639. case 0x74: /* GPMC_CONFIG6 */
  3640. return f->config[5];
  3641. case 0x78: /* GPMC_CONFIG7 */
  3642. return f->config[6];
  3643. case 0x84: /* GPMC_NAND_DATA */
  3644. return 0;
  3645. }
  3646. break;
  3647. case 0x1e0: /* GPMC_PREFETCH_CONFIG1 */
  3648. return s->prefconfig[0];
  3649. case 0x1e4: /* GPMC_PREFETCH_CONFIG2 */
  3650. return s->prefconfig[1];
  3651. case 0x1ec: /* GPMC_PREFETCH_CONTROL */
  3652. return s->prefcontrol;
  3653. case 0x1f0: /* GPMC_PREFETCH_STATUS */
  3654. return (s->preffifo << 24) |
  3655. ((s->preffifo >
  3656. ((s->prefconfig[0] >> 8) & 0x7f) ? 1 : 0) << 16) |
  3657. s->prefcount;
  3658. case 0x1f4: /* GPMC_ECC_CONFIG */
  3659. return s->ecc_cs;
  3660. case 0x1f8: /* GPMC_ECC_CONTROL */
  3661. return s->ecc_ptr;
  3662. case 0x1fc: /* GPMC_ECC_SIZE_CONFIG */
  3663. return s->ecc_cfg;
  3664. case 0x200 ... 0x220: /* GPMC_ECC_RESULT */
  3665. cs = (addr & 0x1f) >> 2;
  3666. /* TODO: check correctness */
  3667. return
  3668. ((s->ecc[cs].cp & 0x07) << 0) |
  3669. ((s->ecc[cs].cp & 0x38) << 13) |
  3670. ((s->ecc[cs].lp[0] & 0x1ff) << 3) |
  3671. ((s->ecc[cs].lp[1] & 0x1ff) << 19);
  3672. case 0x230: /* GPMC_TESTMODE_CTRL */
  3673. return 0;
  3674. case 0x234: /* GPMC_PSA_LSB */
  3675. case 0x238: /* GPMC_PSA_MSB */
  3676. return 0x00000000;
  3677. }
  3678. OMAP_BAD_REG(addr);
  3679. return 0;
  3680. }
  3681. static void omap_gpmc_write(void *opaque, target_phys_addr_t addr,
  3682. uint32_t value)
  3683. {
  3684. struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
  3685. int cs;
  3686. struct omap_gpmc_cs_file_s *f;
  3687. switch (addr) {
  3688. case 0x000: /* GPMC_REVISION */
  3689. case 0x014: /* GPMC_SYSSTATUS */
  3690. case 0x054: /* GPMC_STATUS */
  3691. case 0x1f0: /* GPMC_PREFETCH_STATUS */
  3692. case 0x200 ... 0x220: /* GPMC_ECC_RESULT */
  3693. case 0x234: /* GPMC_PSA_LSB */
  3694. case 0x238: /* GPMC_PSA_MSB */
  3695. OMAP_RO_REG(addr);
  3696. break;
  3697. case 0x010: /* GPMC_SYSCONFIG */
  3698. if ((value >> 3) == 0x3)
  3699. fprintf(stderr, "%s: bad SDRAM idle mode %i\n",
  3700. __FUNCTION__, value >> 3);
  3701. if (value & 2)
  3702. omap_gpmc_reset(s);
  3703. s->sysconfig = value & 0x19;
  3704. break;
  3705. case 0x018: /* GPMC_IRQSTATUS */
  3706. s->irqen = ~value;
  3707. omap_gpmc_int_update(s);
  3708. break;
  3709. case 0x01c: /* GPMC_IRQENABLE */
  3710. s->irqen = value & 0xf03;
  3711. omap_gpmc_int_update(s);
  3712. break;
  3713. case 0x040: /* GPMC_TIMEOUT_CONTROL */
  3714. s->timeout = value & 0x1ff1;
  3715. break;
  3716. case 0x044: /* GPMC_ERR_ADDRESS */
  3717. case 0x048: /* GPMC_ERR_TYPE */
  3718. break;
  3719. case 0x050: /* GPMC_CONFIG */
  3720. s->config = value & 0xf13;
  3721. break;
  3722. case 0x060 ... 0x1d4:
  3723. cs = (addr - 0x060) / 0x30;
  3724. addr -= cs * 0x30;
  3725. f = s->cs_file + cs;
  3726. switch (addr) {
  3727. case 0x60: /* GPMC_CONFIG1 */
  3728. f->config[0] = value & 0xffef3e13;
  3729. break;
  3730. case 0x64: /* GPMC_CONFIG2 */
  3731. f->config[1] = value & 0x001f1f8f;
  3732. break;
  3733. case 0x68: /* GPMC_CONFIG3 */
  3734. f->config[2] = value & 0x001f1f8f;
  3735. break;
  3736. case 0x6c: /* GPMC_CONFIG4 */
  3737. f->config[3] = value & 0x1f8f1f8f;
  3738. break;
  3739. case 0x70: /* GPMC_CONFIG5 */
  3740. f->config[4] = value & 0x0f1f1f1f;
  3741. break;
  3742. case 0x74: /* GPMC_CONFIG6 */
  3743. f->config[5] = value & 0x00000fcf;
  3744. break;
  3745. case 0x78: /* GPMC_CONFIG7 */
  3746. if ((f->config[6] ^ value) & 0xf7f) {
  3747. if (f->config[6] & (1 << 6)) /* CSVALID */
  3748. omap_gpmc_cs_unmap(f);
  3749. if (value & (1 << 6)) /* CSVALID */
  3750. omap_gpmc_cs_map(f, value & 0x1f, /* MASKADDR */
  3751. (value >> 8 & 0xf)); /* BASEADDR */
  3752. }
  3753. f->config[6] = value & 0x00000f7f;
  3754. break;
  3755. case 0x7c: /* GPMC_NAND_COMMAND */
  3756. case 0x80: /* GPMC_NAND_ADDRESS */
  3757. case 0x84: /* GPMC_NAND_DATA */
  3758. break;
  3759. default:
  3760. goto bad_reg;
  3761. }
  3762. break;
  3763. case 0x1e0: /* GPMC_PREFETCH_CONFIG1 */
  3764. s->prefconfig[0] = value & 0x7f8f7fbf;
  3765. /* TODO: update interrupts, fifos, dmas */
  3766. break;
  3767. case 0x1e4: /* GPMC_PREFETCH_CONFIG2 */
  3768. s->prefconfig[1] = value & 0x3fff;
  3769. break;
  3770. case 0x1ec: /* GPMC_PREFETCH_CONTROL */
  3771. s->prefcontrol = value & 1;
  3772. if (s->prefcontrol) {
  3773. if (s->prefconfig[0] & 1)
  3774. s->preffifo = 0x40;
  3775. else
  3776. s->preffifo = 0x00;
  3777. }
  3778. /* TODO: start */
  3779. break;
  3780. case 0x1f4: /* GPMC_ECC_CONFIG */
  3781. s->ecc_cs = 0x8f;
  3782. break;
  3783. case 0x1f8: /* GPMC_ECC_CONTROL */
  3784. if (value & (1 << 8))
  3785. for (cs = 0; cs < 9; cs ++)
  3786. ecc_reset(&s->ecc[cs]);
  3787. s->ecc_ptr = value & 0xf;
  3788. if (s->ecc_ptr == 0 || s->ecc_ptr > 9) {
  3789. s->ecc_ptr = 0;
  3790. s->ecc_cs &= ~1;
  3791. }
  3792. break;
  3793. case 0x1fc: /* GPMC_ECC_SIZE_CONFIG */
  3794. s->ecc_cfg = value & 0x3fcff1ff;
  3795. break;
  3796. case 0x230: /* GPMC_TESTMODE_CTRL */
  3797. if (value & 7)
  3798. fprintf(stderr, "%s: test mode enable attempt\n", __FUNCTION__);
  3799. break;
  3800. default:
  3801. bad_reg:
  3802. OMAP_BAD_REG(addr);
  3803. return;
  3804. }
  3805. }
  3806. static CPUReadMemoryFunc *omap_gpmc_readfn[] = {
  3807. omap_badwidth_read32, /* TODO */
  3808. omap_badwidth_read32, /* TODO */
  3809. omap_gpmc_read,
  3810. };
  3811. static CPUWriteMemoryFunc *omap_gpmc_writefn[] = {
  3812. omap_badwidth_write32, /* TODO */
  3813. omap_badwidth_write32, /* TODO */
  3814. omap_gpmc_write,
  3815. };
  3816. struct omap_gpmc_s *omap_gpmc_init(target_phys_addr_t base, qemu_irq irq)
  3817. {
  3818. int iomemtype;
  3819. struct omap_gpmc_s *s = (struct omap_gpmc_s *)
  3820. qemu_mallocz(sizeof(struct omap_gpmc_s));
  3821. omap_gpmc_reset(s);
  3822. iomemtype = cpu_register_io_memory(0, omap_gpmc_readfn,
  3823. omap_gpmc_writefn, s);
  3824. cpu_register_physical_memory(base, 0x1000, iomemtype);
  3825. return s;
  3826. }
  3827. void omap_gpmc_attach(struct omap_gpmc_s *s, int cs, int iomemtype,
  3828. void (*base_upd)(void *opaque, target_phys_addr_t new),
  3829. void (*unmap)(void *opaque), void *opaque)
  3830. {
  3831. struct omap_gpmc_cs_file_s *f;
  3832. if (cs < 0 || cs >= 8) {
  3833. fprintf(stderr, "%s: bad chip-select %i\n", __FUNCTION__, cs);
  3834. exit(-1);
  3835. }
  3836. f = &s->cs_file[cs];
  3837. f->iomemtype = iomemtype;
  3838. f->base_update = base_upd;
  3839. f->unmap = unmap;
  3840. f->opaque = opaque;
  3841. if (f->config[6] & (1 << 6)) /* CSVALID */
  3842. omap_gpmc_cs_map(f, f->config[6] & 0x1f, /* MASKADDR */
  3843. (f->config[6] >> 8 & 0xf)); /* BASEADDR */
  3844. }
  3845. /* General chip reset */
  3846. static void omap2_mpu_reset(void *opaque)
  3847. {
  3848. struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
  3849. omap_inth_reset(mpu->ih[0]);
  3850. omap_dma_reset(mpu->dma);
  3851. omap_prcm_reset(mpu->prcm);
  3852. omap_sysctl_reset(mpu->sysc);
  3853. omap_gp_timer_reset(mpu->gptimer[0]);
  3854. omap_gp_timer_reset(mpu->gptimer[1]);
  3855. omap_gp_timer_reset(mpu->gptimer[2]);
  3856. omap_gp_timer_reset(mpu->gptimer[3]);
  3857. omap_gp_timer_reset(mpu->gptimer[4]);
  3858. omap_gp_timer_reset(mpu->gptimer[5]);
  3859. omap_gp_timer_reset(mpu->gptimer[6]);
  3860. omap_gp_timer_reset(mpu->gptimer[7]);
  3861. omap_gp_timer_reset(mpu->gptimer[8]);
  3862. omap_gp_timer_reset(mpu->gptimer[9]);
  3863. omap_gp_timer_reset(mpu->gptimer[10]);
  3864. omap_gp_timer_reset(mpu->gptimer[11]);
  3865. omap_synctimer_reset(&mpu->synctimer);
  3866. omap_sdrc_reset(mpu->sdrc);
  3867. omap_gpmc_reset(mpu->gpmc);
  3868. omap_dss_reset(mpu->dss);
  3869. omap_uart_reset(mpu->uart[0]);
  3870. omap_uart_reset(mpu->uart[1]);
  3871. omap_uart_reset(mpu->uart[2]);
  3872. omap_mmc_reset(mpu->mmc);
  3873. omap_gpif_reset(mpu->gpif);
  3874. omap_mcspi_reset(mpu->mcspi[0]);
  3875. omap_mcspi_reset(mpu->mcspi[1]);
  3876. omap_i2c_reset(mpu->i2c[0]);
  3877. omap_i2c_reset(mpu->i2c[1]);
  3878. cpu_reset(mpu->env);
  3879. }
  3880. static int omap2_validate_addr(struct omap_mpu_state_s *s,
  3881. target_phys_addr_t addr)
  3882. {
  3883. return 1;
  3884. }
  3885. static const struct dma_irq_map omap2_dma_irq_map[] = {
  3886. { 0, OMAP_INT_24XX_SDMA_IRQ0 },
  3887. { 0, OMAP_INT_24XX_SDMA_IRQ1 },
  3888. { 0, OMAP_INT_24XX_SDMA_IRQ2 },
  3889. { 0, OMAP_INT_24XX_SDMA_IRQ3 },
  3890. };
  3891. struct omap_mpu_state_s *omap2420_mpu_init(unsigned long sdram_size,
  3892. const char *core)
  3893. {
  3894. struct omap_mpu_state_s *s = (struct omap_mpu_state_s *)
  3895. qemu_mallocz(sizeof(struct omap_mpu_state_s));
  3896. ram_addr_t sram_base, q2_base;
  3897. qemu_irq *cpu_irq;
  3898. qemu_irq dma_irqs[4];
  3899. omap_clk gpio_clks[4];
  3900. int sdindex;
  3901. int i;
  3902. /* Core */
  3903. s->mpu_model = omap2420;
  3904. s->env = cpu_init(core ?: "arm1136-r2");
  3905. if (!s->env) {
  3906. fprintf(stderr, "Unable to find CPU definition\n");
  3907. exit(1);
  3908. }
  3909. s->sdram_size = sdram_size;
  3910. s->sram_size = OMAP242X_SRAM_SIZE;
  3911. s->wakeup = qemu_allocate_irqs(omap_mpu_wakeup, s, 1)[0];
  3912. /* Clocks */
  3913. omap_clk_init(s);
  3914. /* Memory-mapped stuff */
  3915. cpu_register_physical_memory(OMAP2_Q2_BASE, s->sdram_size,
  3916. (q2_base = qemu_ram_alloc(s->sdram_size)) | IO_MEM_RAM);
  3917. cpu_register_physical_memory(OMAP2_SRAM_BASE, s->sram_size,
  3918. (sram_base = qemu_ram_alloc(s->sram_size)) | IO_MEM_RAM);
  3919. s->l4 = omap_l4_init(OMAP2_L4_BASE, 54);
  3920. /* Actually mapped at any 2K boundary in the ARM11 private-peripheral if */
  3921. cpu_irq = arm_pic_init_cpu(s->env);
  3922. s->ih[0] = omap2_inth_init(0x480fe000, 0x1000, 3, &s->irq[0],
  3923. cpu_irq[ARM_PIC_CPU_IRQ], cpu_irq[ARM_PIC_CPU_FIQ],
  3924. omap_findclk(s, "mpu_intc_fclk"),
  3925. omap_findclk(s, "mpu_intc_iclk"));
  3926. s->prcm = omap_prcm_init(omap_l4tao(s->l4, 3),
  3927. s->irq[0][OMAP_INT_24XX_PRCM_MPU_IRQ], NULL, NULL, s);
  3928. s->sysc = omap_sysctl_init(omap_l4tao(s->l4, 1),
  3929. omap_findclk(s, "omapctrl_iclk"), s);
  3930. for (i = 0; i < 4; i ++)
  3931. dma_irqs[i] =
  3932. s->irq[omap2_dma_irq_map[i].ih][omap2_dma_irq_map[i].intr];
  3933. s->dma = omap_dma4_init(0x48056000, dma_irqs, s, 256, 32,
  3934. omap_findclk(s, "sdma_iclk"),
  3935. omap_findclk(s, "sdma_fclk"));
  3936. s->port->addr_valid = omap2_validate_addr;
  3937. /* Register SDRAM and SRAM ports for fast DMA transfers. */
  3938. soc_dma_port_add_mem_ram(s->dma, q2_base, OMAP2_Q2_BASE, s->sdram_size);
  3939. soc_dma_port_add_mem_ram(s->dma, sram_base, OMAP2_SRAM_BASE, s->sram_size);
  3940. s->uart[0] = omap2_uart_init(omap_l4ta(s->l4, 19),
  3941. s->irq[0][OMAP_INT_24XX_UART1_IRQ],
  3942. omap_findclk(s, "uart1_fclk"),
  3943. omap_findclk(s, "uart1_iclk"),
  3944. s->drq[OMAP24XX_DMA_UART1_TX],
  3945. s->drq[OMAP24XX_DMA_UART1_RX], serial_hds[0]);
  3946. s->uart[1] = omap2_uart_init(omap_l4ta(s->l4, 20),
  3947. s->irq[0][OMAP_INT_24XX_UART2_IRQ],
  3948. omap_findclk(s, "uart2_fclk"),
  3949. omap_findclk(s, "uart2_iclk"),
  3950. s->drq[OMAP24XX_DMA_UART2_TX],
  3951. s->drq[OMAP24XX_DMA_UART2_RX],
  3952. serial_hds[0] ? serial_hds[1] : 0);
  3953. s->uart[2] = omap2_uart_init(omap_l4ta(s->l4, 21),
  3954. s->irq[0][OMAP_INT_24XX_UART3_IRQ],
  3955. omap_findclk(s, "uart3_fclk"),
  3956. omap_findclk(s, "uart3_iclk"),
  3957. s->drq[OMAP24XX_DMA_UART3_TX],
  3958. s->drq[OMAP24XX_DMA_UART3_RX],
  3959. serial_hds[0] && serial_hds[1] ? serial_hds[2] : 0);
  3960. s->gptimer[0] = omap_gp_timer_init(omap_l4ta(s->l4, 7),
  3961. s->irq[0][OMAP_INT_24XX_GPTIMER1],
  3962. omap_findclk(s, "wu_gpt1_clk"),
  3963. omap_findclk(s, "wu_l4_iclk"));
  3964. s->gptimer[1] = omap_gp_timer_init(omap_l4ta(s->l4, 8),
  3965. s->irq[0][OMAP_INT_24XX_GPTIMER2],
  3966. omap_findclk(s, "core_gpt2_clk"),
  3967. omap_findclk(s, "core_l4_iclk"));
  3968. s->gptimer[2] = omap_gp_timer_init(omap_l4ta(s->l4, 22),
  3969. s->irq[0][OMAP_INT_24XX_GPTIMER3],
  3970. omap_findclk(s, "core_gpt3_clk"),
  3971. omap_findclk(s, "core_l4_iclk"));
  3972. s->gptimer[3] = omap_gp_timer_init(omap_l4ta(s->l4, 23),
  3973. s->irq[0][OMAP_INT_24XX_GPTIMER4],
  3974. omap_findclk(s, "core_gpt4_clk"),
  3975. omap_findclk(s, "core_l4_iclk"));
  3976. s->gptimer[4] = omap_gp_timer_init(omap_l4ta(s->l4, 24),
  3977. s->irq[0][OMAP_INT_24XX_GPTIMER5],
  3978. omap_findclk(s, "core_gpt5_clk"),
  3979. omap_findclk(s, "core_l4_iclk"));
  3980. s->gptimer[5] = omap_gp_timer_init(omap_l4ta(s->l4, 25),
  3981. s->irq[0][OMAP_INT_24XX_GPTIMER6],
  3982. omap_findclk(s, "core_gpt6_clk"),
  3983. omap_findclk(s, "core_l4_iclk"));
  3984. s->gptimer[6] = omap_gp_timer_init(omap_l4ta(s->l4, 26),
  3985. s->irq[0][OMAP_INT_24XX_GPTIMER7],
  3986. omap_findclk(s, "core_gpt7_clk"),
  3987. omap_findclk(s, "core_l4_iclk"));
  3988. s->gptimer[7] = omap_gp_timer_init(omap_l4ta(s->l4, 27),
  3989. s->irq[0][OMAP_INT_24XX_GPTIMER8],
  3990. omap_findclk(s, "core_gpt8_clk"),
  3991. omap_findclk(s, "core_l4_iclk"));
  3992. s->gptimer[8] = omap_gp_timer_init(omap_l4ta(s->l4, 28),
  3993. s->irq[0][OMAP_INT_24XX_GPTIMER9],
  3994. omap_findclk(s, "core_gpt9_clk"),
  3995. omap_findclk(s, "core_l4_iclk"));
  3996. s->gptimer[9] = omap_gp_timer_init(omap_l4ta(s->l4, 29),
  3997. s->irq[0][OMAP_INT_24XX_GPTIMER10],
  3998. omap_findclk(s, "core_gpt10_clk"),
  3999. omap_findclk(s, "core_l4_iclk"));
  4000. s->gptimer[10] = omap_gp_timer_init(omap_l4ta(s->l4, 30),
  4001. s->irq[0][OMAP_INT_24XX_GPTIMER11],
  4002. omap_findclk(s, "core_gpt11_clk"),
  4003. omap_findclk(s, "core_l4_iclk"));
  4004. s->gptimer[11] = omap_gp_timer_init(omap_l4ta(s->l4, 31),
  4005. s->irq[0][OMAP_INT_24XX_GPTIMER12],
  4006. omap_findclk(s, "core_gpt12_clk"),
  4007. omap_findclk(s, "core_l4_iclk"));
  4008. omap_tap_init(omap_l4ta(s->l4, 2), s);
  4009. omap_synctimer_init(omap_l4tao(s->l4, 2), s,
  4010. omap_findclk(s, "clk32-kHz"),
  4011. omap_findclk(s, "core_l4_iclk"));
  4012. s->i2c[0] = omap2_i2c_init(omap_l4tao(s->l4, 5),
  4013. s->irq[0][OMAP_INT_24XX_I2C1_IRQ],
  4014. &s->drq[OMAP24XX_DMA_I2C1_TX],
  4015. omap_findclk(s, "i2c1.fclk"),
  4016. omap_findclk(s, "i2c1.iclk"));
  4017. s->i2c[1] = omap2_i2c_init(omap_l4tao(s->l4, 6),
  4018. s->irq[0][OMAP_INT_24XX_I2C2_IRQ],
  4019. &s->drq[OMAP24XX_DMA_I2C2_TX],
  4020. omap_findclk(s, "i2c2.fclk"),
  4021. omap_findclk(s, "i2c2.iclk"));
  4022. gpio_clks[0] = omap_findclk(s, "gpio1_dbclk");
  4023. gpio_clks[1] = omap_findclk(s, "gpio2_dbclk");
  4024. gpio_clks[2] = omap_findclk(s, "gpio3_dbclk");
  4025. gpio_clks[3] = omap_findclk(s, "gpio4_dbclk");
  4026. s->gpif = omap2_gpio_init(omap_l4ta(s->l4, 3),
  4027. &s->irq[0][OMAP_INT_24XX_GPIO_BANK1],
  4028. gpio_clks, omap_findclk(s, "gpio_iclk"), 4);
  4029. s->sdrc = omap_sdrc_init(0x68009000);
  4030. s->gpmc = omap_gpmc_init(0x6800a000, s->irq[0][OMAP_INT_24XX_GPMC_IRQ]);
  4031. sdindex = drive_get_index(IF_SD, 0, 0);
  4032. if (sdindex == -1) {
  4033. fprintf(stderr, "qemu: missing SecureDigital device\n");
  4034. exit(1);
  4035. }
  4036. s->mmc = omap2_mmc_init(omap_l4tao(s->l4, 9), drives_table[sdindex].bdrv,
  4037. s->irq[0][OMAP_INT_24XX_MMC_IRQ],
  4038. &s->drq[OMAP24XX_DMA_MMC1_TX],
  4039. omap_findclk(s, "mmc_fclk"), omap_findclk(s, "mmc_iclk"));
  4040. s->mcspi[0] = omap_mcspi_init(omap_l4ta(s->l4, 35), 4,
  4041. s->irq[0][OMAP_INT_24XX_MCSPI1_IRQ],
  4042. &s->drq[OMAP24XX_DMA_SPI1_TX0],
  4043. omap_findclk(s, "spi1_fclk"),
  4044. omap_findclk(s, "spi1_iclk"));
  4045. s->mcspi[1] = omap_mcspi_init(omap_l4ta(s->l4, 36), 2,
  4046. s->irq[0][OMAP_INT_24XX_MCSPI2_IRQ],
  4047. &s->drq[OMAP24XX_DMA_SPI2_TX0],
  4048. omap_findclk(s, "spi2_fclk"),
  4049. omap_findclk(s, "spi2_iclk"));
  4050. s->dss = omap_dss_init(omap_l4ta(s->l4, 10), 0x68000800,
  4051. /* XXX wire M_IRQ_25, D_L2_IRQ_30 and I_IRQ_13 together */
  4052. s->irq[0][OMAP_INT_24XX_DSS_IRQ], s->drq[OMAP24XX_DMA_DSS],
  4053. omap_findclk(s, "dss_clk1"), omap_findclk(s, "dss_clk2"),
  4054. omap_findclk(s, "dss_54m_clk"),
  4055. omap_findclk(s, "dss_l3_iclk"),
  4056. omap_findclk(s, "dss_l4_iclk"));
  4057. omap_sti_init(omap_l4ta(s->l4, 18), 0x54000000,
  4058. s->irq[0][OMAP_INT_24XX_STI], omap_findclk(s, "emul_ck"),
  4059. serial_hds[0] && serial_hds[1] && serial_hds[2] ?
  4060. serial_hds[3] : 0);
  4061. s->eac = omap_eac_init(omap_l4ta(s->l4, 32),
  4062. s->irq[0][OMAP_INT_24XX_EAC_IRQ],
  4063. /* Ten consecutive lines */
  4064. &s->drq[OMAP24XX_DMA_EAC_AC_RD],
  4065. omap_findclk(s, "func_96m_clk"),
  4066. omap_findclk(s, "core_l4_iclk"));
  4067. /* All register mappings (includin those not currenlty implemented):
  4068. * SystemControlMod 48000000 - 48000fff
  4069. * SystemControlL4 48001000 - 48001fff
  4070. * 32kHz Timer Mod 48004000 - 48004fff
  4071. * 32kHz Timer L4 48005000 - 48005fff
  4072. * PRCM ModA 48008000 - 480087ff
  4073. * PRCM ModB 48008800 - 48008fff
  4074. * PRCM L4 48009000 - 48009fff
  4075. * TEST-BCM Mod 48012000 - 48012fff
  4076. * TEST-BCM L4 48013000 - 48013fff
  4077. * TEST-TAP Mod 48014000 - 48014fff
  4078. * TEST-TAP L4 48015000 - 48015fff
  4079. * GPIO1 Mod 48018000 - 48018fff
  4080. * GPIO Top 48019000 - 48019fff
  4081. * GPIO2 Mod 4801a000 - 4801afff
  4082. * GPIO L4 4801b000 - 4801bfff
  4083. * GPIO3 Mod 4801c000 - 4801cfff
  4084. * GPIO4 Mod 4801e000 - 4801efff
  4085. * WDTIMER1 Mod 48020000 - 48010fff
  4086. * WDTIMER Top 48021000 - 48011fff
  4087. * WDTIMER2 Mod 48022000 - 48012fff
  4088. * WDTIMER L4 48023000 - 48013fff
  4089. * WDTIMER3 Mod 48024000 - 48014fff
  4090. * WDTIMER3 L4 48025000 - 48015fff
  4091. * WDTIMER4 Mod 48026000 - 48016fff
  4092. * WDTIMER4 L4 48027000 - 48017fff
  4093. * GPTIMER1 Mod 48028000 - 48018fff
  4094. * GPTIMER1 L4 48029000 - 48019fff
  4095. * GPTIMER2 Mod 4802a000 - 4801afff
  4096. * GPTIMER2 L4 4802b000 - 4801bfff
  4097. * L4-Config AP 48040000 - 480407ff
  4098. * L4-Config IP 48040800 - 48040fff
  4099. * L4-Config LA 48041000 - 48041fff
  4100. * ARM11ETB Mod 48048000 - 48049fff
  4101. * ARM11ETB L4 4804a000 - 4804afff
  4102. * DISPLAY Top 48050000 - 480503ff
  4103. * DISPLAY DISPC 48050400 - 480507ff
  4104. * DISPLAY RFBI 48050800 - 48050bff
  4105. * DISPLAY VENC 48050c00 - 48050fff
  4106. * DISPLAY L4 48051000 - 48051fff
  4107. * CAMERA Top 48052000 - 480523ff
  4108. * CAMERA core 48052400 - 480527ff
  4109. * CAMERA DMA 48052800 - 48052bff
  4110. * CAMERA MMU 48052c00 - 48052fff
  4111. * CAMERA L4 48053000 - 48053fff
  4112. * SDMA Mod 48056000 - 48056fff
  4113. * SDMA L4 48057000 - 48057fff
  4114. * SSI Top 48058000 - 48058fff
  4115. * SSI GDD 48059000 - 48059fff
  4116. * SSI Port1 4805a000 - 4805afff
  4117. * SSI Port2 4805b000 - 4805bfff
  4118. * SSI L4 4805c000 - 4805cfff
  4119. * USB Mod 4805e000 - 480fefff
  4120. * USB L4 4805f000 - 480fffff
  4121. * WIN_TRACER1 Mod 48060000 - 48060fff
  4122. * WIN_TRACER1 L4 48061000 - 48061fff
  4123. * WIN_TRACER2 Mod 48062000 - 48062fff
  4124. * WIN_TRACER2 L4 48063000 - 48063fff
  4125. * WIN_TRACER3 Mod 48064000 - 48064fff
  4126. * WIN_TRACER3 L4 48065000 - 48065fff
  4127. * WIN_TRACER4 Top 48066000 - 480660ff
  4128. * WIN_TRACER4 ETT 48066100 - 480661ff
  4129. * WIN_TRACER4 WT 48066200 - 480662ff
  4130. * WIN_TRACER4 L4 48067000 - 48067fff
  4131. * XTI Mod 48068000 - 48068fff
  4132. * XTI L4 48069000 - 48069fff
  4133. * UART1 Mod 4806a000 - 4806afff
  4134. * UART1 L4 4806b000 - 4806bfff
  4135. * UART2 Mod 4806c000 - 4806cfff
  4136. * UART2 L4 4806d000 - 4806dfff
  4137. * UART3 Mod 4806e000 - 4806efff
  4138. * UART3 L4 4806f000 - 4806ffff
  4139. * I2C1 Mod 48070000 - 48070fff
  4140. * I2C1 L4 48071000 - 48071fff
  4141. * I2C2 Mod 48072000 - 48072fff
  4142. * I2C2 L4 48073000 - 48073fff
  4143. * McBSP1 Mod 48074000 - 48074fff
  4144. * McBSP1 L4 48075000 - 48075fff
  4145. * McBSP2 Mod 48076000 - 48076fff
  4146. * McBSP2 L4 48077000 - 48077fff
  4147. * GPTIMER3 Mod 48078000 - 48078fff
  4148. * GPTIMER3 L4 48079000 - 48079fff
  4149. * GPTIMER4 Mod 4807a000 - 4807afff
  4150. * GPTIMER4 L4 4807b000 - 4807bfff
  4151. * GPTIMER5 Mod 4807c000 - 4807cfff
  4152. * GPTIMER5 L4 4807d000 - 4807dfff
  4153. * GPTIMER6 Mod 4807e000 - 4807efff
  4154. * GPTIMER6 L4 4807f000 - 4807ffff
  4155. * GPTIMER7 Mod 48080000 - 48080fff
  4156. * GPTIMER7 L4 48081000 - 48081fff
  4157. * GPTIMER8 Mod 48082000 - 48082fff
  4158. * GPTIMER8 L4 48083000 - 48083fff
  4159. * GPTIMER9 Mod 48084000 - 48084fff
  4160. * GPTIMER9 L4 48085000 - 48085fff
  4161. * GPTIMER10 Mod 48086000 - 48086fff
  4162. * GPTIMER10 L4 48087000 - 48087fff
  4163. * GPTIMER11 Mod 48088000 - 48088fff
  4164. * GPTIMER11 L4 48089000 - 48089fff
  4165. * GPTIMER12 Mod 4808a000 - 4808afff
  4166. * GPTIMER12 L4 4808b000 - 4808bfff
  4167. * EAC Mod 48090000 - 48090fff
  4168. * EAC L4 48091000 - 48091fff
  4169. * FAC Mod 48092000 - 48092fff
  4170. * FAC L4 48093000 - 48093fff
  4171. * MAILBOX Mod 48094000 - 48094fff
  4172. * MAILBOX L4 48095000 - 48095fff
  4173. * SPI1 Mod 48098000 - 48098fff
  4174. * SPI1 L4 48099000 - 48099fff
  4175. * SPI2 Mod 4809a000 - 4809afff
  4176. * SPI2 L4 4809b000 - 4809bfff
  4177. * MMC/SDIO Mod 4809c000 - 4809cfff
  4178. * MMC/SDIO L4 4809d000 - 4809dfff
  4179. * MS_PRO Mod 4809e000 - 4809efff
  4180. * MS_PRO L4 4809f000 - 4809ffff
  4181. * RNG Mod 480a0000 - 480a0fff
  4182. * RNG L4 480a1000 - 480a1fff
  4183. * DES3DES Mod 480a2000 - 480a2fff
  4184. * DES3DES L4 480a3000 - 480a3fff
  4185. * SHA1MD5 Mod 480a4000 - 480a4fff
  4186. * SHA1MD5 L4 480a5000 - 480a5fff
  4187. * AES Mod 480a6000 - 480a6fff
  4188. * AES L4 480a7000 - 480a7fff
  4189. * PKA Mod 480a8000 - 480a9fff
  4190. * PKA L4 480aa000 - 480aafff
  4191. * MG Mod 480b0000 - 480b0fff
  4192. * MG L4 480b1000 - 480b1fff
  4193. * HDQ/1-wire Mod 480b2000 - 480b2fff
  4194. * HDQ/1-wire L4 480b3000 - 480b3fff
  4195. * MPU interrupt 480fe000 - 480fefff
  4196. * STI channel base 54000000 - 5400ffff
  4197. * IVA RAM 5c000000 - 5c01ffff
  4198. * IVA ROM 5c020000 - 5c027fff
  4199. * IMG_BUF_A 5c040000 - 5c040fff
  4200. * IMG_BUF_B 5c042000 - 5c042fff
  4201. * VLCDS 5c048000 - 5c0487ff
  4202. * IMX_COEF 5c049000 - 5c04afff
  4203. * IMX_CMD 5c051000 - 5c051fff
  4204. * VLCDQ 5c053000 - 5c0533ff
  4205. * VLCDH 5c054000 - 5c054fff
  4206. * SEQ_CMD 5c055000 - 5c055fff
  4207. * IMX_REG 5c056000 - 5c0560ff
  4208. * VLCD_REG 5c056100 - 5c0561ff
  4209. * SEQ_REG 5c056200 - 5c0562ff
  4210. * IMG_BUF_REG 5c056300 - 5c0563ff
  4211. * SEQIRQ_REG 5c056400 - 5c0564ff
  4212. * OCP_REG 5c060000 - 5c060fff
  4213. * SYSC_REG 5c070000 - 5c070fff
  4214. * MMU_REG 5d000000 - 5d000fff
  4215. * sDMA R 68000400 - 680005ff
  4216. * sDMA W 68000600 - 680007ff
  4217. * Display Control 68000800 - 680009ff
  4218. * DSP subsystem 68000a00 - 68000bff
  4219. * MPU subsystem 68000c00 - 68000dff
  4220. * IVA subsystem 68001000 - 680011ff
  4221. * USB 68001200 - 680013ff
  4222. * Camera 68001400 - 680015ff
  4223. * VLYNQ (firewall) 68001800 - 68001bff
  4224. * VLYNQ 68001e00 - 68001fff
  4225. * SSI 68002000 - 680021ff
  4226. * L4 68002400 - 680025ff
  4227. * DSP (firewall) 68002800 - 68002bff
  4228. * DSP subsystem 68002e00 - 68002fff
  4229. * IVA (firewall) 68003000 - 680033ff
  4230. * IVA 68003600 - 680037ff
  4231. * GFX 68003a00 - 68003bff
  4232. * CMDWR emulation 68003c00 - 68003dff
  4233. * SMS 68004000 - 680041ff
  4234. * OCM 68004200 - 680043ff
  4235. * GPMC 68004400 - 680045ff
  4236. * RAM (firewall) 68005000 - 680053ff
  4237. * RAM (err login) 68005400 - 680057ff
  4238. * ROM (firewall) 68005800 - 68005bff
  4239. * ROM (err login) 68005c00 - 68005fff
  4240. * GPMC (firewall) 68006000 - 680063ff
  4241. * GPMC (err login) 68006400 - 680067ff
  4242. * SMS (err login) 68006c00 - 68006fff
  4243. * SMS registers 68008000 - 68008fff
  4244. * SDRC registers 68009000 - 68009fff
  4245. * GPMC registers 6800a000 6800afff
  4246. */
  4247. qemu_register_reset(omap2_mpu_reset, s);
  4248. return s;
  4249. }