001-mtk-0005-mips-mtmips-add-support-for-MediaTek-MT7621-SoC.patch 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904
  1. From e0c82f36ad5180d9582d353407ff1bf34a2734bb Mon Sep 17 00:00:00 2001
  2. From: Weijie Gao <[email protected]>
  3. Date: Fri, 20 May 2022 11:22:21 +0800
  4. Subject: [PATCH 05/25] mips: mtmips: add support for MediaTek MT7621 SoC
  5. This patch adds support for MediaTek MT7621 SoC.
  6. All files are dedicated for u-boot.
  7. The default build target is u-boot-mt7621.bin.
  8. The specification of this chip:
  9. https://www.mediatek.com/products/homenetworking/mt7621
  10. Reviewed-by: Daniel Schwierzeck <[email protected]>
  11. Signed-off-by: Weijie Gao <[email protected]>
  12. ---
  13. arch/mips/dts/mt7621-u-boot.dtsi | 111 ++++++
  14. arch/mips/dts/mt7621.dtsi | 349 +++++++++++++++++++
  15. arch/mips/mach-mtmips/Kconfig | 49 ++-
  16. arch/mips/mach-mtmips/Makefile | 4 +
  17. arch/mips/mach-mtmips/cpu.c | 2 +-
  18. arch/mips/mach-mtmips/mt7621/Kconfig | 95 +++++
  19. arch/mips/mach-mtmips/mt7621/Makefile | 14 +
  20. arch/mips/mach-mtmips/mt7621/init.c | 246 +++++++++++++
  21. arch/mips/mach-mtmips/mt7621/mt7621.h | 229 ++++++++++++
  22. arch/mips/mach-mtmips/mt7621/serial.c | 23 ++
  23. arch/mips/mach-mtmips/mt7621/spl/Makefile | 9 +
  24. arch/mips/mach-mtmips/mt7621/spl/cps.c | 153 ++++++++
  25. arch/mips/mach-mtmips/mt7621/spl/dram.c | 153 ++++++++
  26. arch/mips/mach-mtmips/mt7621/spl/dram.h | 39 +++
  27. arch/mips/mach-mtmips/mt7621/spl/launch.c | 100 ++++++
  28. arch/mips/mach-mtmips/mt7621/spl/launch.h | 52 +++
  29. arch/mips/mach-mtmips/mt7621/spl/launch_ll.S | 339 ++++++++++++++++++
  30. arch/mips/mach-mtmips/mt7621/spl/serial.c | 24 ++
  31. arch/mips/mach-mtmips/mt7621/spl/spl.c | 95 +++++
  32. arch/mips/mach-mtmips/mt7621/spl/start.S | 226 ++++++++++++
  33. arch/mips/mach-mtmips/mt7621/sram_init.S | 22 ++
  34. arch/mips/mach-mtmips/mt7621/tpl/Makefile | 4 +
  35. arch/mips/mach-mtmips/mt7621/tpl/start.S | 161 +++++++++
  36. arch/mips/mach-mtmips/mt7621/tpl/tpl.c | 144 ++++++++
  37. include/configs/mt7621.h | 65 ++++
  38. 25 files changed, 2702 insertions(+), 6 deletions(-)
  39. create mode 100644 arch/mips/dts/mt7621-u-boot.dtsi
  40. create mode 100644 arch/mips/dts/mt7621.dtsi
  41. create mode 100644 arch/mips/mach-mtmips/mt7621/Kconfig
  42. create mode 100644 arch/mips/mach-mtmips/mt7621/Makefile
  43. create mode 100644 arch/mips/mach-mtmips/mt7621/init.c
  44. create mode 100644 arch/mips/mach-mtmips/mt7621/mt7621.h
  45. create mode 100644 arch/mips/mach-mtmips/mt7621/serial.c
  46. create mode 100644 arch/mips/mach-mtmips/mt7621/spl/Makefile
  47. create mode 100644 arch/mips/mach-mtmips/mt7621/spl/cps.c
  48. create mode 100644 arch/mips/mach-mtmips/mt7621/spl/dram.c
  49. create mode 100644 arch/mips/mach-mtmips/mt7621/spl/dram.h
  50. create mode 100644 arch/mips/mach-mtmips/mt7621/spl/launch.c
  51. create mode 100644 arch/mips/mach-mtmips/mt7621/spl/launch.h
  52. create mode 100644 arch/mips/mach-mtmips/mt7621/spl/launch_ll.S
  53. create mode 100644 arch/mips/mach-mtmips/mt7621/spl/serial.c
  54. create mode 100644 arch/mips/mach-mtmips/mt7621/spl/spl.c
  55. create mode 100644 arch/mips/mach-mtmips/mt7621/spl/start.S
  56. create mode 100644 arch/mips/mach-mtmips/mt7621/sram_init.S
  57. create mode 100644 arch/mips/mach-mtmips/mt7621/tpl/Makefile
  58. create mode 100644 arch/mips/mach-mtmips/mt7621/tpl/start.S
  59. create mode 100644 arch/mips/mach-mtmips/mt7621/tpl/tpl.c
  60. create mode 100644 include/configs/mt7621.h
  61. --- /dev/null
  62. +++ b/arch/mips/dts/mt7621-u-boot.dtsi
  63. @@ -0,0 +1,111 @@
  64. +// SPDX-License-Identifier: GPL-2.0
  65. +/*
  66. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  67. + *
  68. + * Author: Weijie Gao <[email protected]>
  69. + */
  70. +
  71. +#include <linux/stringify.h>
  72. +
  73. +/ {
  74. + binman: binman {
  75. + multiple-images;
  76. + };
  77. +};
  78. +
  79. +&sysc {
  80. + u-boot,dm-pre-reloc;
  81. +};
  82. +
  83. +&reboot {
  84. + u-boot,dm-pre-reloc;
  85. +};
  86. +
  87. +&clkctrl {
  88. + u-boot,dm-pre-reloc;
  89. +};
  90. +
  91. +&rstctrl {
  92. + u-boot,dm-pre-reloc;
  93. +};
  94. +
  95. +&pinctrl {
  96. + u-boot,dm-pre-reloc;
  97. +};
  98. +
  99. +&uart0 {
  100. + u-boot,dm-pre-reloc;
  101. +};
  102. +
  103. +&uart1 {
  104. + u-boot,dm-pre-reloc;
  105. +};
  106. +
  107. +&uart2 {
  108. + u-boot,dm-pre-reloc;
  109. +};
  110. +
  111. +&binman {
  112. + u-boot-spl-ddr {
  113. + align = <4>;
  114. + align-size = <4>;
  115. + filename = "u-boot-spl-ddr.bin";
  116. + pad-byte = <0xff>;
  117. +
  118. + u-boot-spl {
  119. + align-end = <4>;
  120. + filename = "u-boot-spl.bin";
  121. + };
  122. +
  123. + stage_bin {
  124. + filename = "mt7621_stage_sram.bin";
  125. + type = "blob-ext";
  126. + };
  127. + };
  128. +
  129. + spl-img {
  130. + filename = "u-boot-spl-ddr.img";
  131. +
  132. + mkimage {
  133. +#ifdef CONFIG_MT7621_BOOT_FROM_NAND
  134. + args = "-T", "mtk_image", "-n", "mt7621=1",
  135. + "-a", __stringify(CONFIG_SPL_TEXT_BASE),
  136. + "-e", __stringify(CONFIG_SPL_TEXT_BASE);
  137. +#else
  138. + args = "-A", "mips", "-T", "standalone", "-O", "u-boot",
  139. + "-C", "none", "-n", "MT7621 U-Boot SPL",
  140. + "-a", __stringify(CONFIG_SPL_TEXT_BASE),
  141. + "-e", __stringify(CONFIG_SPL_TEXT_BASE);
  142. +#endif
  143. +
  144. + blob {
  145. + filename = "u-boot-spl-ddr.bin";
  146. + };
  147. + };
  148. + };
  149. +
  150. + mt7621-uboot {
  151. + filename = "u-boot-mt7621.bin";
  152. + pad-byte = <0xff>;
  153. +
  154. +#ifndef CONFIG_MT7621_BOOT_FROM_NAND
  155. + u-boot-tpl {
  156. + align-end = <4>;
  157. + filename = "u-boot-tpl.bin";
  158. + };
  159. +#endif
  160. +
  161. + spl {
  162. +#ifdef CONFIG_MT7621_BOOT_FROM_NAND
  163. + align-end = <0x1000>;
  164. +#endif
  165. + filename = "u-boot-spl-ddr.img";
  166. + type = "blob";
  167. + };
  168. +
  169. + u-boot {
  170. + filename = "u-boot-lzma.img";
  171. + type = "blob";
  172. + };
  173. + };
  174. +};
  175. --- /dev/null
  176. +++ b/arch/mips/dts/mt7621.dtsi
  177. @@ -0,0 +1,349 @@
  178. +// SPDX-License-Identifier: GPL-2.0
  179. +/*
  180. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  181. + *
  182. + * Author: Weijie Gao <[email protected]>
  183. + */
  184. +
  185. +#include <dt-bindings/clock/mt7621-clk.h>
  186. +#include <dt-bindings/reset/mt7621-reset.h>
  187. +#include <dt-bindings/phy/phy.h>
  188. +
  189. +/ {
  190. + #address-cells = <1>;
  191. + #size-cells = <1>;
  192. + compatible = "mediatek,mt7621-soc";
  193. +
  194. + cpus {
  195. + #address-cells = <1>;
  196. + #size-cells = <0>;
  197. +
  198. + cpu@0 {
  199. + device_type = "cpu";
  200. + compatible = "mips,mips1004Kc";
  201. + reg = <0>;
  202. + };
  203. +
  204. + cpu@1 {
  205. + device_type = "cpu";
  206. + compatible = "mips,mips1004Kc";
  207. + reg = <1>;
  208. + };
  209. + };
  210. +
  211. + clk48m: clk48m {
  212. + compatible = "fixed-clock";
  213. +
  214. + clock-frequency = <48000000>;
  215. +
  216. + #clock-cells = <0>;
  217. + };
  218. +
  219. + clk50m: clk50m {
  220. + compatible = "fixed-clock";
  221. +
  222. + clock-frequency = <50000000>;
  223. +
  224. + #clock-cells = <0>;
  225. + };
  226. +
  227. + sysc: sysctrl@1e000000 {
  228. + compatible = "mediatek,mt7621-sysc", "syscon";
  229. + reg = <0x1e000000 0x100>;
  230. +
  231. + clkctrl: clock-controller@1e000030 {
  232. + compatible = "mediatek,mt7621-clk";
  233. + mediatek,memc = <&memc>;
  234. +
  235. + #clock-cells = <1>;
  236. + };
  237. + };
  238. +
  239. + rstctrl: reset-controller@1e000034 {
  240. + compatible = "mediatek,mtmips-reset";
  241. + reg = <0x1e000034 0x4>;
  242. + #reset-cells = <1>;
  243. + };
  244. +
  245. + reboot: resetctl-reboot {
  246. + compatible = "resetctl-reboot";
  247. +
  248. + resets = <&rstctrl RST_SYS>;
  249. + reset-names = "sysreset";
  250. + };
  251. +
  252. + memc: memctrl@1e005000 {
  253. + compatible = "mediatek,mt7621-memc", "syscon";
  254. + reg = <0x1e005000 0x1000>;
  255. + };
  256. +
  257. + pinctrl: pinctrl@1e000060 {
  258. + compatible = "mediatek,mt7621-pinctrl";
  259. + reg = <0x1e000048 0x30>;
  260. +
  261. + pinctrl-names = "default";
  262. + pinctrl-0 = <&state_default>;
  263. +
  264. + state_default: pin_state {
  265. + };
  266. +
  267. + uart1_pins: uart1_pins {
  268. + groups = "uart1";
  269. + function = "uart";
  270. + };
  271. +
  272. + uart2_pins: uart2_pins {
  273. + groups = "uart2";
  274. + function = "uart";
  275. + };
  276. +
  277. + uart3_pins: uart3_pins {
  278. + groups = "uart3";
  279. + function = "uart";
  280. + };
  281. +
  282. + sdxc_pins: sdxc_pins {
  283. + groups = "sdxc";
  284. + function = "sdxc";
  285. + };
  286. +
  287. + spi_pins: spi_pins {
  288. + groups = "spi";
  289. + function = "spi";
  290. + };
  291. +
  292. + eth_pins: eth_pins {
  293. + mdio_pins {
  294. + groups = "mdio";
  295. + function = "mdio";
  296. + };
  297. +
  298. + rgmii1_pins {
  299. + groups = "rgmii1";
  300. + function = "rgmii";
  301. + };
  302. +
  303. + esw_pins {
  304. + groups = "esw int";
  305. + function = "esw int";
  306. + };
  307. +
  308. + mdio_pconf {
  309. + groups = "mdio";
  310. + drive-strength = <2>;
  311. + };
  312. + };
  313. + };
  314. +
  315. + watchdog: watchdog@1e000100 {
  316. + compatible = "mediatek,mt7621-wdt";
  317. + reg = <0x1e000100 0x40>;
  318. +
  319. + resets = <&rstctrl RST_TIMER>;
  320. + reset-names = "wdt";
  321. +
  322. + status = "disabled";
  323. + };
  324. +
  325. + gpio: gpio@1e000600 {
  326. + #address-cells = <1>;
  327. + #size-cells = <0>;
  328. +
  329. + compatible = "mtk,mt7621-gpio";
  330. + reg = <0x1e000600 0x100>;
  331. +
  332. + resets = <&rstctrl RST_PIO>;
  333. + reset-names = "pio";
  334. +
  335. + gpio0: bank@0 {
  336. + reg = <0>;
  337. + compatible = "mtk,mt7621-gpio-bank";
  338. + gpio-controller;
  339. + #gpio-cells = <2>;
  340. + };
  341. +
  342. + gpio1: bank@1 {
  343. + reg = <1>;
  344. + compatible = "mtk,mt7621-gpio-bank";
  345. + gpio-controller;
  346. + #gpio-cells = <2>;
  347. + };
  348. +
  349. + gpio2: bank@2 {
  350. + reg = <2>;
  351. + compatible = "mtk,mt7621-gpio-bank";
  352. + gpio-controller;
  353. + #gpio-cells = <2>;
  354. + };
  355. + };
  356. +
  357. + spi: spi@1e000b00 {
  358. + compatible = "ralink,mt7621-spi";
  359. + reg = <0x1e000b00 0x40>;
  360. +
  361. + status = "disabled";
  362. +
  363. + pinctrl-names = "default";
  364. + pinctrl-0 = <&spi_pins>;
  365. +
  366. + resets = <&rstctrl RST_SPI>;
  367. + reset-names = "spi";
  368. +
  369. + clocks = <&clkctrl MT7621_CLK_SPI>;
  370. +
  371. + #address-cells = <1>;
  372. + #size-cells = <0>;
  373. + };
  374. +
  375. + uart0: uart1@1e000c00 {
  376. + compatible = "mediatek,hsuart", "ns16550a";
  377. + reg = <0x1e000c00 0x100>;
  378. +
  379. + pinctrl-names = "default";
  380. + pinctrl-0 = <&uart1_pins>;
  381. +
  382. + clocks = <&clkctrl MT7621_CLK_UART1>;
  383. +
  384. + resets = <&rstctrl RST_UART1>;
  385. +
  386. + reg-shift = <2>;
  387. + };
  388. +
  389. + uart1: uart2@1e000d00 {
  390. + compatible = "mediatek,hsuart", "ns16550a";
  391. + reg = <0x1e000d00 0x100>;
  392. +
  393. + pinctrl-names = "default";
  394. + pinctrl-0 = <&uart2_pins>;
  395. +
  396. + clocks = <&clkctrl MT7621_CLK_UART2>;
  397. +
  398. + resets = <&rstctrl RST_UART2>;
  399. +
  400. + reg-shift = <2>;
  401. +
  402. + status = "disabled";
  403. + };
  404. +
  405. + uart2: uart3@1e000e00 {
  406. + compatible = "mediatek,hsuart", "ns16550a";
  407. + reg = <0x1e000e00 0x100>;
  408. +
  409. + pinctrl-names = "default";
  410. + pinctrl-0 = <&uart3_pins>;
  411. +
  412. + clocks = <&clkctrl MT7621_CLK_UART3>;
  413. +
  414. + resets = <&rstctrl RST_UART3>;
  415. +
  416. + reg-shift = <2>;
  417. +
  418. + status = "disabled";
  419. + };
  420. +
  421. + eth: eth@1e100000 {
  422. + compatible = "mediatek,mt7621-eth";
  423. + reg = <0x1e100000 0x20000>;
  424. + mediatek,ethsys = <&sysc>;
  425. +
  426. + pinctrl-names = "default";
  427. + pinctrl-0 = <&eth_pins>;
  428. +
  429. + resets = <&rstctrl RST_FE>, <&rstctrl RST_GMAC>, <&rstctrl RST_MCM>;
  430. + reset-names = "fe", "gmac", "mcm";
  431. +
  432. + clocks = <&clkctrl MT7621_CLK_GDMA>,
  433. + <&clkctrl MT7621_CLK_ETH>;
  434. + clock-names = "gmac", "fe";
  435. +
  436. + #address-cells = <1>;
  437. + #size-cells = <0>;
  438. +
  439. + mediatek,gmac-id = <0>;
  440. + phy-mode = "rgmii";
  441. + mediatek,switch = "mt7530";
  442. + mediatek,mcm;
  443. +
  444. + fixed-link {
  445. + speed = <1000>;
  446. + full-duplex;
  447. + };
  448. + };
  449. +
  450. + mmc: mmc@1e130000 {
  451. + compatible = "mediatek,mt7621-mmc";
  452. + reg = <0x1e130000 0x4000>;
  453. +
  454. + status = "disabled";
  455. +
  456. + bus-width = <4>;
  457. + builtin-cd = <1>;
  458. + r_smpl = <1>;
  459. +
  460. + pinctrl-names = "default";
  461. + pinctrl-0 = <&sdxc_pins>;
  462. +
  463. + clocks = <&clk50m>, <&clkctrl MT7621_CLK_SHXC>;
  464. + clock-names = "source", "hclk";
  465. +
  466. + resets = <&rstctrl RST_SDXC>;
  467. + };
  468. +
  469. + ssusb: usb@1e1c0000 {
  470. + compatible = "mediatek,mt7621-xhci", "mediatek,mtk-xhci";
  471. + reg = <0x1e1c0000 0x1000>, <0x1e1d0700 0x100>;
  472. + reg-names = "mac", "ippc";
  473. +
  474. + clocks = <&clk48m>, <&clk48m>;
  475. + clock-names = "sys_ck", "ref_ck";
  476. +
  477. + phys = <&u2port0 PHY_TYPE_USB2>,
  478. + <&u3port0 PHY_TYPE_USB3>,
  479. + <&u2port1 PHY_TYPE_USB2>;
  480. +
  481. + status = "disabled";
  482. + };
  483. +
  484. + u3phy: usb-phy@1e1d0000 {
  485. + compatible = "mediatek,mt7621-u3phy",
  486. + "mediatek,generic-tphy-v1";
  487. + reg = <0x1e1d0000 0x700>;
  488. + #address-cells = <1>;
  489. + #size-cells = <1>;
  490. + ranges;
  491. + status = "disabled";
  492. +
  493. + u2port0: usb-phy@1e1d0800 {
  494. + reg = <0x1e1d0800 0x0100>;
  495. + #phy-cells = <1>;
  496. + clocks = <&clk48m>;
  497. + clock-names = "ref";
  498. + };
  499. +
  500. + u3port0: usb-phy@1e1d0900 {
  501. + reg = <0x1e1d0900 0x0100>;
  502. + #phy-cells = <1>;
  503. + };
  504. +
  505. + u2port1: usb-phy@1e1d1000 {
  506. + reg = <0x1e1d1000 0x0100>;
  507. + #phy-cells = <1>;
  508. + clocks = <&clk48m>;
  509. + clock-names = "ref";
  510. + };
  511. + };
  512. +
  513. + i2c: i2c@1e000900 {
  514. + compatible = "i2c-gpio";
  515. +
  516. + status = "disabled";
  517. +
  518. + i2c-gpio,delay-us = <3>;
  519. +
  520. + gpios = <&gpio0 3 1>, /* PIN3 as SDA */
  521. + <&gpio0 4 1>; /* PIN4 as CLK */
  522. +
  523. + #address-cells = <1>;
  524. + #size-cells = <0>;
  525. + };
  526. +};
  527. --- a/arch/mips/mach-mtmips/Kconfig
  528. +++ b/arch/mips/mach-mtmips/Kconfig
  529. @@ -9,6 +9,7 @@ config SYS_MALLOC_F_LEN
  530. config SYS_SOC
  531. default "mt7620" if SOC_MT7620
  532. + default "mt7621" if SOC_MT7621
  533. default "mt7628" if SOC_MT7628
  534. config SYS_DCACHE_SIZE
  535. @@ -18,25 +19,45 @@ config SYS_DCACHE_LINE_SIZE
  536. default 32
  537. config SYS_ICACHE_SIZE
  538. - default 65536
  539. + default 65536 if SOC_MT7620 || SOC_MT7628
  540. + default 32768 if SOC_MT7621
  541. config SYS_ICACHE_LINE_SIZE
  542. default 32
  543. +config SYS_SCACHE_LINE_SIZE
  544. + default 32 if SOC_MT7621
  545. +
  546. config SYS_TEXT_BASE
  547. - default 0x9c000000 if !SPL
  548. - default 0x80200000 if SPL
  549. + default 0x9c000000 if !SPL && !SOC_MT7621
  550. + default 0x80200000 if SPL || SOC_MT7621
  551. config SPL_TEXT_BASE
  552. - default 0x9c000000
  553. + default 0x9c000000 if !SOC_MT7621
  554. + default 0x80100000 if SOC_MT7621
  555. +
  556. +config SPL_SIZE_LIMIT
  557. + default 0x30000 if SOC_MT7621
  558. +
  559. +config TPL_TEXT_BASE
  560. + default 0xbfc00000 if SOC_MT7621
  561. +
  562. +config TPL_MAX_SIZE
  563. + default 4096 if SOC_MT7621
  564. config SPL_PAYLOAD
  565. default "u-boot-lzma.img" if SPL_LZMA
  566. config BUILD_TARGET
  567. - default "u-boot-with-spl.bin" if SPL
  568. + default "u-boot-with-spl.bin" if SPL && !SOC_MT7621
  569. + default "u-boot-lzma.img" if SOC_MT7621
  570. default "u-boot.bin"
  571. +config MAX_MEM_SIZE
  572. + int
  573. + default 256 if SOC_MT7620 || SOC_MT7628
  574. + default 512 if SOC_MT7621
  575. +
  576. choice
  577. prompt "MediaTek MIPS SoC select"
  578. @@ -55,6 +76,23 @@ config SOC_MT7620
  579. help
  580. This supports MediaTek MT7620.
  581. +config SOC_MT7621
  582. + bool "MT7621"
  583. + select MIPS_CM
  584. + select MIPS_L2_CACHE
  585. + select SYS_CACHE_SHIFT_5
  586. + select SYS_MIPS_CACHE_INIT_RAM_LOAD
  587. + select PINCTRL_MT7621
  588. + select MTK_SERIAL
  589. + select REGMAP
  590. + select SYSCON
  591. + select BINMAN
  592. + select SUPPORT_TPL
  593. + select SPL_LOADER_SUPPORT if SPL
  594. + select SPL_INIT_STACK_WITHOUT_MALLOC_F if SPL
  595. + help
  596. + This supports MediaTek MT7621.
  597. +
  598. config SOC_MT7628
  599. bool "MT7628"
  600. select SYS_CACHE_SHIFT_5
  601. @@ -80,6 +118,7 @@ config SOC_MT7628
  602. endchoice
  603. source "arch/mips/mach-mtmips/mt7620/Kconfig"
  604. +source "arch/mips/mach-mtmips/mt7621/Kconfig"
  605. source "arch/mips/mach-mtmips/mt7628/Kconfig"
  606. endmenu
  607. --- a/arch/mips/mach-mtmips/Makefile
  608. +++ b/arch/mips/mach-mtmips/Makefile
  609. @@ -1,9 +1,13 @@
  610. # SPDX-License-Identifier: GPL-2.0+
  611. obj-y += cpu.o
  612. +
  613. +ifneq ($(CONFIG_SOC_MT7621),y)
  614. obj-y += ddr_init.o
  615. obj-y += ddr_cal.o
  616. obj-$(CONFIG_SPL_BUILD) += spl.o
  617. +endif
  618. obj-$(CONFIG_SOC_MT7620) += mt7620/
  619. +obj-$(CONFIG_SOC_MT7621) += mt7621/
  620. obj-$(CONFIG_SOC_MT7628) += mt7628/
  621. --- a/arch/mips/mach-mtmips/cpu.c
  622. +++ b/arch/mips/mach-mtmips/cpu.c
  623. @@ -16,7 +16,7 @@ DECLARE_GLOBAL_DATA_PTR;
  624. int dram_init(void)
  625. {
  626. - gd->ram_size = get_ram_size((void *)KSEG1, SZ_256M);
  627. + gd->ram_size = get_ram_size((void *)KSEG1, CONFIG_MAX_MEM_SIZE << 20);
  628. return 0;
  629. }
  630. --- /dev/null
  631. +++ b/arch/mips/mach-mtmips/mt7621/Kconfig
  632. @@ -0,0 +1,95 @@
  633. +
  634. +if SOC_MT7621
  635. +
  636. +menu "CPU & DDR configuration"
  637. +
  638. +config MT7621_CPU_FREQ
  639. + int "CPU Frequency (MHz)"
  640. + range 400 1200
  641. + default 880
  642. +
  643. +choice
  644. + prompt "DRAM Frequency"
  645. + default MT7621_DRAM_FREQ_1200
  646. +
  647. +config MT7621_DRAM_FREQ_400
  648. + bool "400MHz"
  649. +
  650. +config MT7621_DRAM_FREQ_800
  651. + bool "800MHz"
  652. +
  653. +config MT7621_DRAM_FREQ_1066
  654. + bool "1066MHz"
  655. +
  656. +config MT7621_DRAM_FREQ_1200
  657. + bool "1200MHz"
  658. +
  659. +endchoice
  660. +
  661. +choice
  662. + prompt "DDR2 timing parameters"
  663. + default MT7621_DRAM_DDR2_1024M
  664. +
  665. +config MT7621_DRAM_DDR2_512M
  666. + bool "64MB"
  667. +
  668. +config MT7621_DRAM_DDR2_1024M
  669. + bool "128MB"
  670. +
  671. +config MT7621_DRAM_DDR2_512M_W9751G6KB_A02_1066MHZ
  672. + bool "W9751G6KB_A02 @ 1066MHz (64MB)"
  673. +
  674. +config MT7621_DRAM_DDR2_1024M_W971GG6KB25_800MHZ
  675. + bool "W971GG6KB25 @ 800MHz (128MB)"
  676. +
  677. +config MT7621_DRAM_DDR2_1024M_W971GG6KB18_1066MHZ
  678. + bool "W971GG6KB18 @ 1066MHz (128MB)"
  679. +
  680. +endchoice
  681. +
  682. +choice
  683. + prompt "DDR3 timing parameters"
  684. + default MT7621_DRAM_DDR3_2048M
  685. +
  686. +config MT7621_DRAM_DDR3_1024M
  687. + bool "128MB"
  688. +
  689. +config MT7621_DRAM_DDR3_1024M_KGD
  690. + bool "128MB KGD (MT7621DA)"
  691. +
  692. +config MT7621_DRAM_DDR3_2048M
  693. + bool "256MB"
  694. +
  695. +config MT7621_DRAM_DDR3_4096M
  696. + bool "512MB"
  697. +
  698. +endchoice
  699. +
  700. +endmenu
  701. +
  702. +config DEBUG_UART_BOARD_INIT
  703. + default y
  704. +
  705. +config MT7621_BOOT_FROM_NAND
  706. + bool "Boot from NAND"
  707. + help
  708. + Select this if u-boot will boot from NAND flash. When booting from
  709. + NAND, SPL will be loaded by bootrom directly and no TPL is needed.
  710. +
  711. +choice
  712. + prompt "Board select"
  713. +
  714. +endchoice
  715. +
  716. +config SYS_CONFIG_NAME
  717. + string "Board configuration name"
  718. + default "mt7621" if BOARD_MT7621_RFB || BOARD_MT7621_NAND_RFB
  719. +
  720. +config SYS_BOARD
  721. + string "Board name"
  722. + default "mt7621" if BOARD_MT7621_RFB || BOARD_MT7621_NAND_RFB
  723. +
  724. +config SYS_VENDOR
  725. + default "mediatek" if BOARD_MT7621_RFB || BOARD_MT7621_NAND_RFB
  726. +
  727. +endif
  728. --- /dev/null
  729. +++ b/arch/mips/mach-mtmips/mt7621/Makefile
  730. @@ -0,0 +1,14 @@
  731. +# SPDX-License-Identifier: GPL-2.0
  732. +
  733. +obj-y += init.o
  734. +obj-y += serial.o
  735. +
  736. +ifeq ($(CONFIG_SPL_BUILD),y)
  737. +ifeq ($(CONFIG_TPL_BUILD),y)
  738. +obj-y += tpl/
  739. +else
  740. +obj-y += spl/
  741. +endif
  742. +
  743. +obj-y += sram_init.o
  744. +endif
  745. --- /dev/null
  746. +++ b/arch/mips/mach-mtmips/mt7621/init.c
  747. @@ -0,0 +1,246 @@
  748. +// SPDX-License-Identifier: GPL-2.0
  749. +/*
  750. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  751. + *
  752. + * Author: Weijie Gao <[email protected]>
  753. + */
  754. +
  755. +#include <clk.h>
  756. +#include <dm.h>
  757. +#include <dm/uclass.h>
  758. +#include <dt-bindings/clock/mt7621-clk.h>
  759. +#include <asm/global_data.h>
  760. +#include <linux/io.h>
  761. +#include <linux/bitfield.h>
  762. +#include "mt7621.h"
  763. +
  764. +DECLARE_GLOBAL_DATA_PTR;
  765. +
  766. +static const char *const boot_mode[(CHIP_MODE_M >> CHIP_MODE_S) + 1] = {
  767. + [1] = "NAND 2K+64",
  768. + [2] = "SPI-NOR 3-Byte Addr",
  769. + [3] = "SPI-NOR 4-Byte Addr",
  770. + [10] = "NAND 2K+128",
  771. + [11] = "NAND 4K+128",
  772. + [12] = "NAND 4K+256",
  773. +};
  774. +
  775. +int print_cpuinfo(void)
  776. +{
  777. + void __iomem *sysc = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
  778. + u32 val, ver, eco, pkg, core, dram, chipmode;
  779. + u32 cpu_clk, ddr_clk, bus_clk, xtal_clk;
  780. + struct udevice *clkdev;
  781. + const char *bootdev;
  782. + struct clk clk;
  783. + int ret;
  784. +
  785. + val = readl(sysc + SYSCTL_CHIP_REV_ID_REG);
  786. + ver = FIELD_GET(VER_ID_M, val);
  787. + eco = FIELD_GET(ECO_ID_M, val);
  788. + pkg = FIELD_GET(PKG_ID, val);
  789. + core = FIELD_GET(CPU_ID, val);
  790. +
  791. + val = readl(sysc + SYSCTL_SYSCFG0_REG);
  792. + dram = FIELD_GET(DRAM_TYPE, val);
  793. + chipmode = FIELD_GET(CHIP_MODE_M, val);
  794. +
  795. + bootdev = boot_mode[chipmode];
  796. + if (!bootdev)
  797. + bootdev = "Unsupported boot mode";
  798. +
  799. + printf("CPU: MediaTek MT7621%c ver %u, eco %u\n",
  800. + core ? (pkg ? 'A' : 'N') : 'S', ver, eco);
  801. +
  802. + printf("Boot: DDR%u, %s\n", dram ? 2 : 3, bootdev);
  803. +
  804. + ret = uclass_get_device_by_driver(UCLASS_CLK, DM_DRIVER_GET(mt7621_clk),
  805. + &clkdev);
  806. + if (ret)
  807. + return ret;
  808. +
  809. + clk.dev = clkdev;
  810. +
  811. + clk.id = MT7621_CLK_CPU;
  812. + cpu_clk = clk_get_rate(&clk);
  813. +
  814. + clk.id = MT7621_CLK_BUS;
  815. + bus_clk = clk_get_rate(&clk);
  816. +
  817. + clk.id = MT7621_CLK_DDR;
  818. + ddr_clk = clk_get_rate(&clk);
  819. +
  820. + clk.id = MT7621_CLK_XTAL;
  821. + xtal_clk = clk_get_rate(&clk);
  822. +
  823. + /* Set final timer frequency */
  824. + if (cpu_clk)
  825. + gd->arch.timer_freq = cpu_clk / 2;
  826. +
  827. + printf("Clock: CPU: %uMHz, DDR: %uMT/s, Bus: %uMHz, XTAL: %uMHz\n",
  828. + cpu_clk / 1000000, ddr_clk / 500000, bus_clk / 1000000,
  829. + xtal_clk / 1000000);
  830. +
  831. + return 0;
  832. +}
  833. +
  834. +unsigned long get_xtal_mhz(void)
  835. +{
  836. + void __iomem *sysc = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
  837. + u32 bs, xtal_sel;
  838. +
  839. + bs = readl(sysc + SYSCTL_SYSCFG0_REG);
  840. + xtal_sel = FIELD_GET(XTAL_MODE_SEL_M, bs);
  841. +
  842. + if (xtal_sel <= 2)
  843. + return 20;
  844. + else if (xtal_sel <= 5)
  845. + return 40;
  846. + else
  847. + return 25;
  848. +}
  849. +
  850. +static void xhci_config_40mhz(void __iomem *usbh)
  851. +{
  852. + writel(FIELD_PREP(SSUSB_MAC3_SYS_CK_GATE_MASK_TIME_M, 0x20) |
  853. + FIELD_PREP(SSUSB_MAC2_SYS_CK_GATE_MASK_TIME_M, 0x20) |
  854. + FIELD_PREP(SSUSB_MAC3_SYS_CK_GATE_MODE_M, 2) |
  855. + FIELD_PREP(SSUSB_MAC2_SYS_CK_GATE_MODE_M, 2) | 0x10,
  856. + usbh + SSUSB_MAC_CK_CTRL_REG);
  857. +
  858. + writel(FIELD_PREP(SSUSB_PLL_PREDIV_PE1D_M, 2) |
  859. + FIELD_PREP(SSUSB_PLL_PREDIV_U3_M, 1) |
  860. + FIELD_PREP(SSUSB_PLL_FBKDI_M, 4),
  861. + usbh + DA_SSUSB_U3PHYA_10_REG);
  862. +
  863. + writel(FIELD_PREP(SSUSB_PLL_FBKDIV_PE2H_M, 0x18) |
  864. + FIELD_PREP(SSUSB_PLL_FBKDIV_PE1D_M, 0x18) |
  865. + FIELD_PREP(SSUSB_PLL_FBKDIV_PE1H_M, 0x18) |
  866. + FIELD_PREP(SSUSB_PLL_FBKDIV_U3_M, 0x1e),
  867. + usbh + DA_SSUSB_PLL_FBKDIV_REG);
  868. +
  869. + writel(FIELD_PREP(SSUSB_PLL_PCW_NCPO_U3_M, 0x1e400000),
  870. + usbh + DA_SSUSB_PLL_PCW_NCPO_REG);
  871. +
  872. + writel(FIELD_PREP(SSUSB_PLL_SSC_DELTA1_PE1H_M, 0x25) |
  873. + FIELD_PREP(SSUSB_PLL_SSC_DELTA1_U3_M, 0x73),
  874. + usbh + DA_SSUSB_PLL_SSC_DELTA1_REG);
  875. +
  876. + writel(FIELD_PREP(SSUSB_PLL_SSC_DELTA_U3_M, 0x71) |
  877. + FIELD_PREP(SSUSB_PLL_SSC_DELTA1_PE2D_M, 0x4a),
  878. + usbh + DA_SSUSB_U3PHYA_21_REG);
  879. +
  880. + writel(FIELD_PREP(SSUSB_PLL_SSC_PRD_M, 0x140),
  881. + usbh + SSUSB_U3PHYA_9_REG);
  882. +
  883. + writel(FIELD_PREP(SSUSB_SYSPLL_PCW_NCPO_M, 0x11c00000),
  884. + usbh + SSUSB_U3PHYA_3_REG);
  885. +
  886. + writel(FIELD_PREP(SSUSB_PCIE_CLKDRV_AMP_M, 4) |
  887. + FIELD_PREP(SSUSB_SYSPLL_FBSEL_M, 1) |
  888. + FIELD_PREP(SSUSB_SYSPLL_PREDIV_M, 1),
  889. + usbh + SSUSB_U3PHYA_1_REG);
  890. +
  891. + writel(FIELD_PREP(SSUSB_SYSPLL_FBDIV_M, 0x12) |
  892. + SSUSB_SYSPLL_VCO_DIV_SEL | SSUSB_SYSPLL_FPEN |
  893. + SSUSB_SYSPLL_MONCK_EN | SSUSB_SYSPLL_VOD_EN,
  894. + usbh + SSUSB_U3PHYA_2_REG);
  895. +
  896. + writel(SSUSB_EQ_CURSEL | FIELD_PREP(SSUSB_RX_DAC_MUX_M, 8) |
  897. + FIELD_PREP(SSUSB_PCIE_SIGDET_VTH_M, 1) |
  898. + FIELD_PREP(SSUSB_PCIE_SIGDET_LPF_M, 1),
  899. + usbh + SSUSB_U3PHYA_11_REG);
  900. +
  901. + writel(FIELD_PREP(SSUSB_RING_OSC_CNTEND_M, 0x1ff) |
  902. + FIELD_PREP(SSUSB_XTAL_OSC_CNTEND_M, 0x7f) |
  903. + SSUSB_RING_BYPASS_DET,
  904. + usbh + SSUSB_B2_ROSC_0_REG);
  905. +
  906. + writel(FIELD_PREP(SSUSB_RING_OSC_FRC_RECAL_M, 3) |
  907. + SSUSB_RING_OSC_FRC_SEL,
  908. + usbh + SSUSB_B2_ROSC_1_REG);
  909. +}
  910. +
  911. +static void xhci_config_25mhz(void __iomem *usbh)
  912. +{
  913. + writel(FIELD_PREP(SSUSB_MAC3_SYS_CK_GATE_MASK_TIME_M, 0x20) |
  914. + FIELD_PREP(SSUSB_MAC2_SYS_CK_GATE_MASK_TIME_M, 0x20) |
  915. + FIELD_PREP(SSUSB_MAC3_SYS_CK_GATE_MODE_M, 2) |
  916. + FIELD_PREP(SSUSB_MAC2_SYS_CK_GATE_MODE_M, 2) | 0x10,
  917. + usbh + SSUSB_MAC_CK_CTRL_REG);
  918. +
  919. + writel(FIELD_PREP(SSUSB_PLL_PREDIV_PE1D_M, 2) |
  920. + FIELD_PREP(SSUSB_PLL_FBKDI_M, 4),
  921. + usbh + DA_SSUSB_U3PHYA_10_REG);
  922. +
  923. + writel(FIELD_PREP(SSUSB_PLL_FBKDIV_PE2H_M, 0x18) |
  924. + FIELD_PREP(SSUSB_PLL_FBKDIV_PE1D_M, 0x18) |
  925. + FIELD_PREP(SSUSB_PLL_FBKDIV_PE1H_M, 0x18) |
  926. + FIELD_PREP(SSUSB_PLL_FBKDIV_U3_M, 0x19),
  927. + usbh + DA_SSUSB_PLL_FBKDIV_REG);
  928. +
  929. + writel(FIELD_PREP(SSUSB_PLL_PCW_NCPO_U3_M, 0x18000000),
  930. + usbh + DA_SSUSB_PLL_PCW_NCPO_REG);
  931. +
  932. + writel(FIELD_PREP(SSUSB_PLL_SSC_DELTA1_PE1H_M, 0x25) |
  933. + FIELD_PREP(SSUSB_PLL_SSC_DELTA1_U3_M, 0x4a),
  934. + usbh + DA_SSUSB_PLL_SSC_DELTA1_REG);
  935. +
  936. + writel(FIELD_PREP(SSUSB_PLL_SSC_DELTA_U3_M, 0x48) |
  937. + FIELD_PREP(SSUSB_PLL_SSC_DELTA1_PE2D_M, 0x4a),
  938. + usbh + DA_SSUSB_U3PHYA_21_REG);
  939. +
  940. + writel(FIELD_PREP(SSUSB_PLL_SSC_PRD_M, 0x190),
  941. + usbh + SSUSB_U3PHYA_9_REG);
  942. +
  943. + writel(FIELD_PREP(SSUSB_SYSPLL_PCW_NCPO_M, 0xe000000),
  944. + usbh + SSUSB_U3PHYA_3_REG);
  945. +
  946. + writel(FIELD_PREP(SSUSB_PCIE_CLKDRV_AMP_M, 4) |
  947. + FIELD_PREP(SSUSB_SYSPLL_FBSEL_M, 1),
  948. + usbh + SSUSB_U3PHYA_1_REG);
  949. +
  950. + writel(FIELD_PREP(SSUSB_SYSPLL_FBDIV_M, 0xf) |
  951. + SSUSB_SYSPLL_VCO_DIV_SEL | SSUSB_SYSPLL_FPEN |
  952. + SSUSB_SYSPLL_MONCK_EN | SSUSB_SYSPLL_VOD_EN,
  953. + usbh + SSUSB_U3PHYA_2_REG);
  954. +
  955. + writel(SSUSB_EQ_CURSEL | FIELD_PREP(SSUSB_RX_DAC_MUX_M, 8) |
  956. + FIELD_PREP(SSUSB_PCIE_SIGDET_VTH_M, 1) |
  957. + FIELD_PREP(SSUSB_PCIE_SIGDET_LPF_M, 1),
  958. + usbh + SSUSB_U3PHYA_11_REG);
  959. +
  960. + writel(FIELD_PREP(SSUSB_RING_OSC_CNTEND_M, 0x1ff) |
  961. + FIELD_PREP(SSUSB_XTAL_OSC_CNTEND_M, 0x7f) |
  962. + SSUSB_RING_BYPASS_DET,
  963. + usbh + SSUSB_B2_ROSC_0_REG);
  964. +
  965. + writel(FIELD_PREP(SSUSB_RING_OSC_FRC_RECAL_M, 3) |
  966. + SSUSB_RING_OSC_FRC_SEL,
  967. + usbh + SSUSB_B2_ROSC_1_REG);
  968. +}
  969. +
  970. +void lowlevel_init(void)
  971. +{
  972. + void __iomem *usbh = ioremap_nocache(SSUSB_BASE, SSUSB_SIZE);
  973. + u32 xtal = get_xtal_mhz();
  974. +
  975. + /* Setup USB xHCI */
  976. + if (xtal == 40)
  977. + xhci_config_40mhz(usbh);
  978. + else if (xtal == 25)
  979. + xhci_config_25mhz(usbh);
  980. +}
  981. +
  982. +ulong notrace get_tbclk(void)
  983. +{
  984. + return gd->arch.timer_freq;
  985. +}
  986. +
  987. +void _machine_restart(void)
  988. +{
  989. + void __iomem *sysc = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
  990. +
  991. + while (1)
  992. + writel(SYS_RST, sysc + SYSCTL_RSTCTL_REG);
  993. +}
  994. --- /dev/null
  995. +++ b/arch/mips/mach-mtmips/mt7621/mt7621.h
  996. @@ -0,0 +1,229 @@
  997. +/* SPDX-License-Identifier: GPL-2.0 */
  998. +/*
  999. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  1000. + *
  1001. + * Author: Weijie Gao <[email protected]>
  1002. + */
  1003. +
  1004. +#ifndef _MT7621_H_
  1005. +#define _MT7621_H_
  1006. +
  1007. +#define SYSCTL_BASE 0x1e000000
  1008. +#define SYSCTL_SIZE 0x100
  1009. +#define TIMER_BASE 0x1e000100
  1010. +#define TIMER_SIZE 0x100
  1011. +#define RBUS_BASE 0x1e000400
  1012. +#define RBUS_SIZE 0x100
  1013. +#define GPIO_BASE 0x1e000600
  1014. +#define GPIO_SIZE 0x100
  1015. +#define DMA_CFG_ARB_BASE 0x1e000800
  1016. +#define DMA_CFG_ARB_SIZE 0x100
  1017. +#define SPI_BASE 0x1e000b00
  1018. +#define SPI_SIZE 0x100
  1019. +#define UART1_BASE 0x1e000c00
  1020. +#define UART1_SIZE 0x100
  1021. +#define UART2_BASE 0x1e000d00
  1022. +#define UART2_SIZE 0x100
  1023. +#define UART3_BASE 0x1e000e00
  1024. +#define UART3_SIZE 0x100
  1025. +#define NFI_BASE 0x1e003000
  1026. +#define NFI_SIZE 0x800
  1027. +#define NFI_ECC_BASE 0x1e003800
  1028. +#define NFI_ECC_SIZE 0x800
  1029. +#define DRAMC_BASE 0x1e005000
  1030. +#define DRAMC_SIZE 0x1000
  1031. +#define FE_BASE 0x1e100000
  1032. +#define FE_SIZE 0xe000
  1033. +#define GMAC_BASE 0x1e110000
  1034. +#define GMAC_SIZE 0x8000
  1035. +#define SSUSB_BASE 0x1e1c0000
  1036. +#define SSUSB_SIZE 0x40000
  1037. +
  1038. + /* GIC Base Address */
  1039. +#define MIPS_GIC_BASE 0x1fbc0000
  1040. +
  1041. + /* CPC Base Address */
  1042. +#define MIPS_CPC_BASE 0x1fbf0000
  1043. +
  1044. + /* Flash Memory-mapped Base Address */
  1045. +#define FLASH_MMAP_BASE 0x1fc00000
  1046. +#define TPL_INFO_OFFSET 0x40
  1047. +#define TPL_INFO_MAGIC 0x31323637 /* Magic "7621" */
  1048. +
  1049. +/* SRAM */
  1050. +#define FE_SRAM_BASE1 0x8000
  1051. +#define FE_SRAM_BASE2 0xa000
  1052. +
  1053. +/* SYSCTL_BASE */
  1054. +#define SYSCTL_CHIP_REV_ID_REG 0x0c
  1055. +#define CPU_ID 0x20000
  1056. +#define PKG_ID 0x10000
  1057. +#define VER_ID_S 8
  1058. +#define VER_ID_M 0xf00
  1059. +#define ECO_ID_S 0
  1060. +#define ECO_ID_M 0x0f
  1061. +
  1062. +#define SYSCTL_SYSCFG0_REG 0x10
  1063. +#define XTAL_MODE_SEL_S 6
  1064. +#define XTAL_MODE_SEL_M 0x1c0
  1065. +#define DRAM_TYPE 0x10
  1066. +#define CHIP_MODE_S 0
  1067. +#define CHIP_MODE_M 0x0f
  1068. +
  1069. +#define BOOT_SRAM_BASE_REG 0x20
  1070. +
  1071. +#define SYSCTL_CLKCFG0_REG 0x2c
  1072. +#define CPU_CLK_SEL_S 30
  1073. +#define CPU_CLK_SEL_M 0xc0000000
  1074. +#define MPLL_CFG_SEL_S 23
  1075. +#define MPLL_CFG_SEL_M 0x800000
  1076. +
  1077. +#define SYSCTL_RSTCTL_REG 0x34
  1078. +#define MCM_RST 0x04
  1079. +#define SYS_RST 0x01
  1080. +
  1081. +#define SYSCTL_CUR_CLK_STS_REG 0x44
  1082. +#define CUR_CPU_FDIV_S 8
  1083. +#define CUR_CPU_FDIV_M 0x1f00
  1084. +#define CUR_CPU_FFRAC_S 0
  1085. +#define CUR_CPU_FFRAC_M 0x1f
  1086. +
  1087. +#define SYSCTL_GPIOMODE_REG 0x60
  1088. +#define UART2_MODE_S 5
  1089. +#define UART2_MODE_M 0x60
  1090. +#define UART3_MODE_S 3
  1091. +#define UART3_MODE_M 0x18
  1092. +#define UART1_MODE 0x02
  1093. +
  1094. +/* RBUS_BASE */
  1095. +#define RBUS_DYN_CFG0_REG 0x0010
  1096. +#define CPU_FDIV_S 8
  1097. +#define CPU_FDIV_M 0x1f00
  1098. +#define CPU_FFRAC_S 0
  1099. +#define CPU_FFRAC_M 0x1f
  1100. +
  1101. +/* DMA_CFG_ARB_BASE */
  1102. +#define DMA_ROUTE_REG 0x000c
  1103. +
  1104. +/* SPI_BASE */
  1105. +#define SPI_SPACE_REG 0x003c
  1106. +#define FS_SLAVE_SEL_S 12
  1107. +#define FS_SLAVE_SEL_M 0x70000
  1108. +#define FS_CLK_SEL_S 0
  1109. +#define FS_CLK_SEL_M 0xfff
  1110. +
  1111. +/* FE_BASE */
  1112. +#define FE_RST_GLO_REG 0x0004
  1113. +#define FE_PSE_RAM 0x04
  1114. +#define FE_PSE_MEM_EN 0x02
  1115. +#define FE_PSE_RESET 0x01
  1116. +
  1117. +/* SSUSB_BASE */
  1118. +#define SSUSB_MAC_CK_CTRL_REG 0x10784
  1119. +#define SSUSB_MAC3_SYS_CK_GATE_MASK_TIME_S 16
  1120. +#define SSUSB_MAC3_SYS_CK_GATE_MASK_TIME_M 0xff0000
  1121. +#define SSUSB_MAC2_SYS_CK_GATE_MASK_TIME_S 8
  1122. +#define SSUSB_MAC2_SYS_CK_GATE_MASK_TIME_M 0xff00
  1123. +#define SSUSB_MAC3_SYS_CK_GATE_MODE_S 2
  1124. +#define SSUSB_MAC3_SYS_CK_GATE_MODE_M 0x0c
  1125. +#define SSUSB_MAC2_SYS_CK_GATE_MODE_S 0
  1126. +#define SSUSB_MAC2_SYS_CK_GATE_MODE_M 0x03
  1127. +
  1128. +#define SSUSB_B2_ROSC_0_REG 0x10a40
  1129. +#define SSUSB_RING_OSC_CNTEND_S 23
  1130. +#define SSUSB_RING_OSC_CNTEND_M 0xff800000
  1131. +#define SSUSB_XTAL_OSC_CNTEND_S 16
  1132. +#define SSUSB_XTAL_OSC_CNTEND_M 0x7f0000
  1133. +#define SSUSB_RING_BYPASS_DET 0x01
  1134. +
  1135. +#define SSUSB_B2_ROSC_1_REG 0x10a44
  1136. +#define SSUSB_RING_OSC_FRC_RECAL_S 17
  1137. +#define SSUSB_RING_OSC_FRC_RECAL_M 0x60000
  1138. +#define SSUSB_RING_OSC_FRC_SEL 0x01
  1139. +
  1140. +#define SSUSB_U3PHYA_1_REG 0x10b04
  1141. +#define SSUSB_PCIE_CLKDRV_AMP_S 27
  1142. +#define SSUSB_PCIE_CLKDRV_AMP_M 0x38000000
  1143. +#define SSUSB_SYSPLL_FBSEL_S 2
  1144. +#define SSUSB_SYSPLL_FBSEL_M 0x0c
  1145. +#define SSUSB_SYSPLL_PREDIV_S 0
  1146. +#define SSUSB_SYSPLL_PREDIV_M 0x03
  1147. +
  1148. +#define SSUSB_U3PHYA_2_REG 0x10b08
  1149. +#define SSUSB_SYSPLL_FBDIV_S 24
  1150. +#define SSUSB_SYSPLL_FBDIV_M 0x7f000000
  1151. +#define SSUSB_SYSPLL_VCO_DIV_SEL 0x200000
  1152. +#define SSUSB_SYSPLL_FPEN 0x2000
  1153. +#define SSUSB_SYSPLL_MONCK_EN 0x1000
  1154. +#define SSUSB_SYSPLL_VOD_EN 0x200
  1155. +
  1156. +#define SSUSB_U3PHYA_3_REG 0x10b10
  1157. +#define SSUSB_SYSPLL_PCW_NCPO_S 1
  1158. +#define SSUSB_SYSPLL_PCW_NCPO_M 0xfffffffe
  1159. +
  1160. +#define SSUSB_U3PHYA_9_REG 0x10b24
  1161. +#define SSUSB_PLL_SSC_PRD_S 0
  1162. +#define SSUSB_PLL_SSC_PRD_M 0xffff
  1163. +
  1164. +#define SSUSB_U3PHYA_11_REG 0x10b2c
  1165. +#define SSUSB_EQ_CURSEL 0x1000000
  1166. +#define SSUSB_RX_DAC_MUX_S 19
  1167. +#define SSUSB_RX_DAC_MUX_M 0xf80000
  1168. +#define SSUSB_PCIE_SIGDET_VTH_S 5
  1169. +#define SSUSB_PCIE_SIGDET_VTH_M 0x60
  1170. +#define SSUSB_PCIE_SIGDET_LPF_S 3
  1171. +#define SSUSB_PCIE_SIGDET_LPF_M 0x18
  1172. +
  1173. +#define DA_SSUSB_PLL_FBKDIV_REG 0x10c1c
  1174. +#define SSUSB_PLL_FBKDIV_PE2H_S 24
  1175. +#define SSUSB_PLL_FBKDIV_PE2H_M 0x7f000000
  1176. +#define SSUSB_PLL_FBKDIV_PE1D_S 16
  1177. +#define SSUSB_PLL_FBKDIV_PE1D_M 0x7f0000
  1178. +#define SSUSB_PLL_FBKDIV_PE1H_S 8
  1179. +#define SSUSB_PLL_FBKDIV_PE1H_M 0x7f00
  1180. +#define SSUSB_PLL_FBKDIV_U3_S 0
  1181. +#define SSUSB_PLL_FBKDIV_U3_M 0x7f
  1182. +
  1183. +#define DA_SSUSB_U3PHYA_10_REG 0x10c20
  1184. +#define SSUSB_PLL_PREDIV_PE1D_S 18
  1185. +#define SSUSB_PLL_PREDIV_PE1D_M 0xc0000
  1186. +#define SSUSB_PLL_PREDIV_U3_S 8
  1187. +#define SSUSB_PLL_PREDIV_U3_M 0x300
  1188. +#define SSUSB_PLL_FBKDI_S 0
  1189. +#define SSUSB_PLL_FBKDI_M 0x07
  1190. +
  1191. +#define DA_SSUSB_PLL_PCW_NCPO_REG 0x10c24
  1192. +#define SSUSB_PLL_PCW_NCPO_U3_S 0
  1193. +#define SSUSB_PLL_PCW_NCPO_U3_M 0x7fffffff
  1194. +
  1195. +#define DA_SSUSB_PLL_SSC_DELTA1_REG 0x10c38
  1196. +#define SSUSB_PLL_SSC_DELTA1_PE1H_S 16
  1197. +#define SSUSB_PLL_SSC_DELTA1_PE1H_M 0xffff0000
  1198. +#define SSUSB_PLL_SSC_DELTA1_U3_S 0
  1199. +#define SSUSB_PLL_SSC_DELTA1_U3_M 0xffff
  1200. +
  1201. +#define DA_SSUSB_U3PHYA_21_REG 0x10c40
  1202. +#define SSUSB_PLL_SSC_DELTA_U3_S 16
  1203. +#define SSUSB_PLL_SSC_DELTA_U3_M 0xffff0000
  1204. +#define SSUSB_PLL_SSC_DELTA1_PE2D_S 0
  1205. +#define SSUSB_PLL_SSC_DELTA1_PE2D_M 0xffff
  1206. +
  1207. +/* MT7621 specific CM values */
  1208. +
  1209. +/* GCR_REGx_BASE */
  1210. +#define GCR_REG0_BASE_VALUE 0x1c000000
  1211. +#define GCR_REG1_BASE_VALUE 0x60000000
  1212. +#define GCR_REG2_BASE_VALUE 0x1c000000
  1213. +#define GCR_REG3_BASE_VALUE 0x1c000000
  1214. +
  1215. +/* GCR_REGx_MASK */
  1216. +#define GCR_REG0_MASK_VALUE 0x0000fc00 /* 64M Bus */
  1217. +#define GCR_REG1_MASK_VALUE 0x0000f000 /* 256M PCI Mem */
  1218. +#define GCR_REG2_MASK_VALUE 0x0000fc00 /* unused */
  1219. +#define GCR_REG3_MASK_VALUE 0x0000fc00 /* unused */
  1220. +
  1221. +#ifndef __ASSEMBLY__
  1222. +unsigned long get_xtal_mhz(void);
  1223. +#endif
  1224. +
  1225. +#endif /* _MT7621_H_ */
  1226. --- /dev/null
  1227. +++ b/arch/mips/mach-mtmips/mt7621/serial.c
  1228. @@ -0,0 +1,23 @@
  1229. +// SPDX-License-Identifier: GPL-2.0
  1230. +/*
  1231. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  1232. + *
  1233. + * Author: Weijie Gao <[email protected]>
  1234. + */
  1235. +
  1236. +#include <asm/io.h>
  1237. +#include <asm/addrspace.h>
  1238. +#include "mt7621.h"
  1239. +
  1240. +void board_debug_uart_init(void)
  1241. +{
  1242. + void __iomem *base = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
  1243. +
  1244. +#if CONFIG_DEBUG_UART_BASE == 0xbe000c00 /* KSEG1ADDR(UART1_BASE) */
  1245. + clrbits_32(base + SYSCTL_GPIOMODE_REG, UART1_MODE);
  1246. +#elif CONFIG_DEBUG_UART_BASE == 0xbe000d00 /* KSEG1ADDR(UART2_BASE) */
  1247. + clrbits_32(base + SYSCTL_GPIOMODE_REG, UART2_MODE_M);
  1248. +#elif CONFIG_DEBUG_UART_BASE == 0xbe000e00 /* KSEG1ADDR(UART3_BASE) */
  1249. + clrbits_32(base + SYSCTL_GPIOMODE_REG, UART3_MODE_M);
  1250. +#endif
  1251. +}
  1252. --- /dev/null
  1253. +++ b/arch/mips/mach-mtmips/mt7621/spl/Makefile
  1254. @@ -0,0 +1,9 @@
  1255. +
  1256. +extra-y += start.o
  1257. +
  1258. +obj-y += spl.o
  1259. +obj-y += cps.o
  1260. +obj-y += dram.o
  1261. +obj-y += serial.o
  1262. +obj-y += launch.o
  1263. +obj-y += launch_ll.o
  1264. --- /dev/null
  1265. +++ b/arch/mips/mach-mtmips/mt7621/spl/cps.c
  1266. @@ -0,0 +1,153 @@
  1267. +// SPDX-License-Identifier: GPL-2.0
  1268. +/*
  1269. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  1270. + *
  1271. + * Author: Weijie Gao <[email protected]>
  1272. + */
  1273. +
  1274. +#include <asm/io.h>
  1275. +#include <asm/addrspace.h>
  1276. +#include <asm/mipsregs.h>
  1277. +#include <asm/cm.h>
  1278. +#include <linux/bitfield.h>
  1279. +#include "../mt7621.h"
  1280. +
  1281. +/* GIC Shared Register Bases */
  1282. +#define GIC_SH_POL_BASE 0x100
  1283. +#define GIC_SH_TRIG_BASE 0x180
  1284. +#define GIC_SH_RMASK_BASE 0x300
  1285. +#define GIC_SH_SMASK_BASE 0x380
  1286. +#define GIC_SH_MASK_BASE 0x400
  1287. +#define GIC_SH_PEND_BASE 0x480
  1288. +#define GIC_SH_MAP_PIN_BASE 0x500
  1289. +#define GIC_SH_MAP_VPE_BASE 0x2000
  1290. +
  1291. +/* GIC Registers */
  1292. +#define GIC_SH_POL31_0 (GIC_SH_POL_BASE + 0x00)
  1293. +#define GIC_SH_POL63_32 (GIC_SH_POL_BASE + 0x04)
  1294. +
  1295. +#define GIC_SH_TRIG31_0 (GIC_SH_TRIG_BASE + 0x00)
  1296. +#define GIC_SH_TRIG63_32 (GIC_SH_TRIG_BASE + 0x04)
  1297. +
  1298. +#define GIC_SH_RMASK31_0 (GIC_SH_RMASK_BASE + 0x00)
  1299. +#define GIC_SH_RMASK63_32 (GIC_SH_RMASK_BASE + 0x04)
  1300. +
  1301. +#define GIC_SH_SMASK31_0 (GIC_SH_SMASK_BASE + 0x00)
  1302. +#define GIC_SH_SMASK63_32 (GIC_SH_SMASK_BASE + 0x04)
  1303. +
  1304. +#define GIC_SH_MAP_PIN(n) (GIC_SH_MAP_PIN_BASE + (n) * 4)
  1305. +
  1306. +#define GIC_SH_MAP_VPE(n, v) (GIC_SH_MAP_VPE_BASE + (n) * 0x20 + ((v) / 32) * 4)
  1307. +#define GIC_SH_MAP_VPE31_0(n) GIC_SH_MAP_VPE(n, 0)
  1308. +
  1309. +/* GIC_SH_MAP_PIN fields */
  1310. +#define GIC_MAP_TO_PIN BIT(31)
  1311. +#define GIC_MAP_TO_NMI BIT(30)
  1312. +#define GIC_MAP GENMASK(5, 0)
  1313. +#define GIC_MAP_SHIFT 0
  1314. +
  1315. +static void cm_init(void __iomem *cm_base)
  1316. +{
  1317. + u32 gcrcfg, num_cores;
  1318. +
  1319. + gcrcfg = readl(cm_base + GCR_CONFIG);
  1320. + num_cores = FIELD_GET(GCR_CONFIG_PCORES, gcrcfg) + 1;
  1321. +
  1322. + writel((1 << num_cores) - 1, cm_base + GCR_ACCESS);
  1323. +
  1324. + writel(GCR_REG0_BASE_VALUE, cm_base + GCR_REG0_BASE);
  1325. + writel(GCR_REG1_BASE_VALUE, cm_base + GCR_REG1_BASE);
  1326. + writel(GCR_REG2_BASE_VALUE, cm_base + GCR_REG2_BASE);
  1327. + writel(GCR_REG3_BASE_VALUE, cm_base + GCR_REG3_BASE);
  1328. +
  1329. + clrsetbits_32(cm_base + GCR_REG0_MASK,
  1330. + GCR_REGn_MASK_ADDRMASK | GCR_REGn_MASK_CMTGT,
  1331. + FIELD_PREP(GCR_REGn_MASK_ADDRMASK, GCR_REG0_MASK_VALUE) |
  1332. + GCR_REGn_MASK_CMTGT_IOCU0);
  1333. +
  1334. + clrsetbits_32(cm_base + GCR_REG1_MASK,
  1335. + GCR_REGn_MASK_ADDRMASK | GCR_REGn_MASK_CMTGT,
  1336. + FIELD_PREP(GCR_REGn_MASK_ADDRMASK, GCR_REG1_MASK_VALUE) |
  1337. + GCR_REGn_MASK_CMTGT_IOCU0);
  1338. +
  1339. + clrsetbits_32(cm_base + GCR_REG2_MASK,
  1340. + GCR_REGn_MASK_ADDRMASK | GCR_REGn_MASK_CMTGT,
  1341. + FIELD_PREP(GCR_REGn_MASK_ADDRMASK, GCR_REG2_MASK_VALUE) |
  1342. + GCR_REGn_MASK_CMTGT_IOCU0);
  1343. +
  1344. + clrsetbits_32(cm_base + GCR_REG3_MASK,
  1345. + GCR_REGn_MASK_ADDRMASK | GCR_REGn_MASK_CMTGT,
  1346. + FIELD_PREP(GCR_REGn_MASK_ADDRMASK, GCR_REG3_MASK_VALUE) |
  1347. + GCR_REGn_MASK_CMTGT_IOCU0);
  1348. +
  1349. + clrbits_32(cm_base + GCR_BASE, CM_DEFAULT_TARGET_MASK);
  1350. + setbits_32(cm_base + GCR_CONTROL, GCR_CONTROL_SYNCCTL);
  1351. +}
  1352. +
  1353. +static void gic_init(void)
  1354. +{
  1355. + void __iomem *gic_base = (void *)KSEG1ADDR(MIPS_GIC_BASE);
  1356. + int i;
  1357. +
  1358. + /* Interrupt 0..5: Level Trigger, Active High */
  1359. + writel(0, gic_base + GIC_SH_TRIG31_0);
  1360. + writel(0x3f, gic_base + GIC_SH_RMASK31_0);
  1361. + writel(0x3f, gic_base + GIC_SH_POL31_0);
  1362. + writel(0x3f, gic_base + GIC_SH_SMASK31_0);
  1363. +
  1364. + /* Interrupt 56..63: Edge Trigger, Rising Edge */
  1365. + /* Hardcoded to set up the last 8 external interrupts for IPI. */
  1366. + writel(0xff000000, gic_base + GIC_SH_TRIG63_32);
  1367. + writel(0xff000000, gic_base + GIC_SH_RMASK63_32);
  1368. + writel(0xff000000, gic_base + GIC_SH_POL63_32);
  1369. + writel(0xff000000, gic_base + GIC_SH_SMASK63_32);
  1370. +
  1371. + /* Map interrupt source to particular hardware interrupt pin */
  1372. + /* source {0,1,2,3,4,5} -> pin {0,0,4,3,0,5} */
  1373. + writel(GIC_MAP_TO_PIN | 0, gic_base + GIC_SH_MAP_PIN(0));
  1374. + writel(GIC_MAP_TO_PIN | 0, gic_base + GIC_SH_MAP_PIN(1));
  1375. + writel(GIC_MAP_TO_PIN | 4, gic_base + GIC_SH_MAP_PIN(2));
  1376. + writel(GIC_MAP_TO_PIN | 3, gic_base + GIC_SH_MAP_PIN(3));
  1377. + writel(GIC_MAP_TO_PIN | 0, gic_base + GIC_SH_MAP_PIN(4));
  1378. + writel(GIC_MAP_TO_PIN | 5, gic_base + GIC_SH_MAP_PIN(5));
  1379. +
  1380. + /* source 56~59 -> pin 1, 60~63 -> pin 2 */
  1381. + writel(GIC_MAP_TO_PIN | 1, gic_base + GIC_SH_MAP_PIN(56));
  1382. + writel(GIC_MAP_TO_PIN | 1, gic_base + GIC_SH_MAP_PIN(57));
  1383. + writel(GIC_MAP_TO_PIN | 1, gic_base + GIC_SH_MAP_PIN(58));
  1384. + writel(GIC_MAP_TO_PIN | 1, gic_base + GIC_SH_MAP_PIN(59));
  1385. + writel(GIC_MAP_TO_PIN | 2, gic_base + GIC_SH_MAP_PIN(60));
  1386. + writel(GIC_MAP_TO_PIN | 2, gic_base + GIC_SH_MAP_PIN(61));
  1387. + writel(GIC_MAP_TO_PIN | 2, gic_base + GIC_SH_MAP_PIN(62));
  1388. + writel(GIC_MAP_TO_PIN | 2, gic_base + GIC_SH_MAP_PIN(63));
  1389. +
  1390. + /* Interrupt map to VPE (bit mask) */
  1391. + for (i = 0; i < 32; i++)
  1392. + writel(BIT(0), gic_base + GIC_SH_MAP_VPE31_0(i));
  1393. +
  1394. + /*
  1395. + * Direct GIC_int 56..63 to vpe 0..3
  1396. + * MIPS Linux convention that last 16 interrupts implemented be set
  1397. + * aside for IPI signaling.
  1398. + * The actual interrupts are tied low and software sends interrupts
  1399. + * via GIC_SH_WEDGE writes.
  1400. + */
  1401. + for (i = 0; i < 4; i++) {
  1402. + writel(BIT(i), gic_base + GIC_SH_MAP_VPE31_0(i + 56));
  1403. + writel(BIT(i), gic_base + GIC_SH_MAP_VPE31_0(i + 60));
  1404. + }
  1405. +}
  1406. +
  1407. +void mt7621_cps_init(void)
  1408. +{
  1409. + void __iomem *cm_base = (void *)KSEG1ADDR(CONFIG_MIPS_CM_BASE);
  1410. +
  1411. + /* Enable GIC */
  1412. + writel(MIPS_GIC_BASE | GCR_GIC_EN, cm_base + GCR_GIC_BASE);
  1413. +
  1414. + /* Enable CPC */
  1415. + writel(MIPS_CPC_BASE | GCR_CPC_EN, cm_base + GCR_CPC_BASE);
  1416. +
  1417. + gic_init();
  1418. + cm_init(cm_base);
  1419. +}
  1420. --- /dev/null
  1421. +++ b/arch/mips/mach-mtmips/mt7621/spl/dram.c
  1422. @@ -0,0 +1,153 @@
  1423. +// SPDX-License-Identifier: GPL-2.0
  1424. +/*
  1425. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  1426. + *
  1427. + * Author: Weijie Gao <[email protected]>
  1428. + */
  1429. +
  1430. +#include <vsprintf.h>
  1431. +#include <asm/io.h>
  1432. +#include <asm/sections.h>
  1433. +#include <asm/byteorder.h>
  1434. +#include <asm/addrspace.h>
  1435. +#include <linux/string.h>
  1436. +#include "../mt7621.h"
  1437. +#include "dram.h"
  1438. +
  1439. +static const u32 ddr2_act[DDR_PARAM_SIZE] = {
  1440. +#if defined(CONFIG_MT7621_DRAM_DDR2_512M)
  1441. + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x22174441,
  1442. + 0x00000000, 0xF0748661, 0x40001273, 0x9F0A0481,
  1443. + 0x0304692F, 0x15602842, 0x00008888, 0x88888888,
  1444. + 0x00000000, 0x00000000, 0x00000000, 0x07100000,
  1445. + 0x00001B63, 0x00002000, 0x00004000, 0x00006000,
  1446. + 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  1447. +#elif defined(CONFIG_MT7621_DRAM_DDR2_512M_W9751G6KB_A02_1066MHZ)
  1448. + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x33484584,
  1449. + 0x00000000, 0xF07486A1, 0x50001273, 0x9F010481,
  1450. + 0x0304693F, 0x15602842, 0x00008888, 0x88888888,
  1451. + 0x00000000, 0x00000000, 0x00000010, 0x07100000,
  1452. + 0x00001F73, 0x00002000, 0x00004000, 0x00006000,
  1453. + 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  1454. +#elif defined(CONFIG_MT7621_DRAM_DDR2_1024M_W971GG6KB25_800MHZ)
  1455. + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x22174430,
  1456. + 0x01000000, 0xF0748661, 0x40001273, 0x9F0F0481,
  1457. + 0x0304692F, 0x15602842, 0x00008888, 0x88888888,
  1458. + 0x00000000, 0x00000000, 0x00000000, 0x07100000,
  1459. + 0x00001B63, 0x00002000, 0x00004000, 0x00006000,
  1460. + 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  1461. +#elif defined(CONFIG_MT7621_DRAM_DDR2_1024M_W971GG6KB18_1066MHZ)
  1462. + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x33484584,
  1463. + 0x01000000, 0xF07486A1, 0x50001273, 0x9F070481,
  1464. + 0x0304693F, 0x15602842, 0x00008888, 0x88888888,
  1465. + 0x00000000, 0x00000000, 0x00000010, 0x07100000,
  1466. + 0x00001F73, 0x00002000, 0x00004000, 0x00006000,
  1467. + 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  1468. +#else /* CONFIG_MT7621_DRAM_DDR2_1024M */
  1469. + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x22174441,
  1470. + 0x01000000, 0xF0748661, 0x40001273, 0x9F0F0481,
  1471. + 0x0304692F, 0x15602842, 0x00008888, 0x88888888,
  1472. + 0x00000000, 0x00000000, 0x00000000, 0x07100000,
  1473. + 0x00001B63, 0x00002000, 0x00004000, 0x00006000,
  1474. + 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  1475. +#endif
  1476. +};
  1477. +
  1478. +static const u32 ddr3_act[DDR_PARAM_SIZE] = {
  1479. +#if defined(CONFIG_MT7621_DRAM_DDR3_1024M)
  1480. + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x44694683,
  1481. + 0x01000000, 0xF07486A1, 0xC287221D, 0x9F060481,
  1482. + 0x03046948, 0x15602842, 0x00008888, 0x88888888,
  1483. + 0x00000000, 0x00000000, 0x00000210, 0x07100000,
  1484. + 0x00001B61, 0x00002040, 0x00004010, 0x00006000,
  1485. + 0x0C000000, 0x07070000, 0x00000000, 0x00000000,
  1486. +#elif defined(CONFIG_MT7621_DRAM_DDR3_4096M)
  1487. + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x44694683,
  1488. + 0x01000000, 0xF07486A1, 0xC287221D, 0x9F0F0481,
  1489. + 0x03046948, 0x15602842, 0x00008888, 0x88888888,
  1490. + 0x00000000, 0x00000000, 0x00000240, 0x07100000,
  1491. + 0x00001B61, 0x00002040, 0x00004010, 0x00006000,
  1492. + 0x0C000000, 0x07070000, 0x00000000, 0x00000000,
  1493. +#elif defined(CONFIG_MT7621_DRAM_DDR3_1024M_KGD)
  1494. + 0xFF00FF00, 0xFF00FF00, 0x00000007, 0x44694683,
  1495. + 0x01000000, 0xF07406A1, 0xC287221D, 0x9F060481,
  1496. + 0x03046923, 0x152f2842, 0x00008888, 0x88888888,
  1497. + 0x00000000, 0x00000000, 0x00000210, 0x07100000,
  1498. + 0x00001B61, 0x00002040, 0x00004010, 0x00006000,
  1499. + 0x0C000000, 0x07070000, 0x000C0000, 0x00000000,
  1500. +#else /* CONFIG_MT7621_DRAM_DDR3_2048M */
  1501. + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x44694673,
  1502. + 0x01000000, 0xF07486A1, 0xC287221D, 0x9F050481,
  1503. + 0x03046948, 0x15602842, 0x00008888, 0x88888888,
  1504. + 0x00000000, 0x00000000, 0x00000220, 0x07100000,
  1505. + 0x00001B61, 0x00002040, 0x00004010, 0x00006000,
  1506. + 0x0C000000, 0x07070000, 0x00000000, 0x00000000,
  1507. +#endif
  1508. +};
  1509. +
  1510. +#if defined(CONFIG_MT7621_DRAM_FREQ_400)
  1511. +#define DDR_FREQ_PARAM 0x41000000
  1512. +#elif defined(CONFIG_MT7621_DRAM_FREQ_1066)
  1513. +#define DDR_FREQ_PARAM 0x21000000
  1514. +#elif defined(CONFIG_MT7621_DRAM_FREQ_1200)
  1515. +#define DDR_FREQ_PARAM 0x11000000
  1516. +#else /* CONFIG_MT7621_DRAM_FREQ_800 */
  1517. +#define DDR_FREQ_PARAM 0x31000000
  1518. +#endif
  1519. +
  1520. +#define RG_MEPL_FBDIV_S 4
  1521. +#define RG_MEPL_FBDIV_M 0x7f
  1522. +
  1523. +static inline void word_copy(u32 *dest, const u32 *src, u32 count)
  1524. +{
  1525. + u32 i;
  1526. +
  1527. + for (i = 0; i < count; i++)
  1528. + dest[i] = src[i];
  1529. +}
  1530. +
  1531. +static u32 calc_cpu_pll_val(void)
  1532. +{
  1533. + u32 div, baseval, fb;
  1534. +
  1535. + div = get_xtal_mhz();
  1536. +
  1537. + if (div == 40) {
  1538. + div /= 2;
  1539. + baseval = 0xc0005802;
  1540. + } else {
  1541. + baseval = 0xc0004802;
  1542. + }
  1543. +
  1544. + fb = CONFIG_MT7621_CPU_FREQ / div - 1;
  1545. + if (fb > RG_MEPL_FBDIV_M)
  1546. + fb = RG_MEPL_FBDIV_M;
  1547. +
  1548. + return baseval | (fb << RG_MEPL_FBDIV_S);
  1549. +}
  1550. +
  1551. +void prepare_stage_bin(void)
  1552. +{
  1553. + u32 stage_size;
  1554. +
  1555. + const struct stage_header *stock_stage_bin =
  1556. + (const struct stage_header *)__image_copy_end;
  1557. +
  1558. + struct stage_header *new_stage_bin =
  1559. + (struct stage_header *)STAGE_LOAD_ADDR;
  1560. +
  1561. + if (be32_to_cpu(stock_stage_bin->ep) != STAGE_LOAD_ADDR)
  1562. + panic("Invalid DDR stage binary blob\n");
  1563. +
  1564. + stage_size = be32_to_cpu(stock_stage_bin->stage_size);
  1565. +
  1566. + word_copy((u32 *)new_stage_bin, (const u32 *)stock_stage_bin,
  1567. + (stage_size + sizeof(u32) - 1) / sizeof(u32));
  1568. +
  1569. + word_copy(new_stage_bin->ddr2_act, ddr2_act, DDR_PARAM_SIZE);
  1570. + word_copy(new_stage_bin->ddr3_act, ddr3_act, DDR_PARAM_SIZE);
  1571. +
  1572. + new_stage_bin->cpu_pll_cfg = calc_cpu_pll_val();
  1573. + new_stage_bin->ddr_pll_cfg = DDR_FREQ_PARAM;
  1574. + new_stage_bin->baudrate = CONFIG_BAUDRATE;
  1575. +}
  1576. --- /dev/null
  1577. +++ b/arch/mips/mach-mtmips/mt7621/spl/dram.h
  1578. @@ -0,0 +1,39 @@
  1579. +/* SPDX-License-Identifier: GPL-2.0 */
  1580. +/*
  1581. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  1582. + *
  1583. + * Author: Weijie Gao <[email protected]>
  1584. + */
  1585. +
  1586. +#ifndef _MT7621_DRAM_H_
  1587. +#define _MT7621_DRAM_H_
  1588. +
  1589. +#define STAGE_LOAD_ADDR 0xBE108800
  1590. +
  1591. +#ifndef __ASSEMBLY__
  1592. +#include <linux/types.h>
  1593. +
  1594. +#define DDR_PARAM_SIZE 24
  1595. +
  1596. +struct stage_header {
  1597. + u32 jump_insn[2];
  1598. + u32 ep;
  1599. + u32 stage_size;
  1600. + u32 has_stage2;
  1601. + u32 next_ep;
  1602. + u32 next_size;
  1603. + u32 next_offset;
  1604. + u32 cpu_pll_cfg;
  1605. + u32 ddr_pll_cfg;
  1606. + u32 reserved2[6];
  1607. + char build_tag[32];
  1608. + u32 ddr3_act[DDR_PARAM_SIZE];
  1609. + u32 padding1[2];
  1610. + u32 ddr2_act[DDR_PARAM_SIZE];
  1611. + u32 padding2[2];
  1612. + u32 baudrate;
  1613. + u32 padding3;
  1614. +};
  1615. +#endif
  1616. +
  1617. +#endif /* _MT7621_DRAM_H_ */
  1618. --- /dev/null
  1619. +++ b/arch/mips/mach-mtmips/mt7621/spl/launch.c
  1620. @@ -0,0 +1,100 @@
  1621. +// SPDX-License-Identifier: GPL-2.0
  1622. +/*
  1623. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  1624. + *
  1625. + * Author: Weijie Gao <[email protected]>
  1626. + */
  1627. +
  1628. +#include <asm/io.h>
  1629. +#include <asm/cm.h>
  1630. +#include <asm/sections.h>
  1631. +#include <asm/addrspace.h>
  1632. +#include <asm/mipsmtregs.h>
  1633. +#include <linux/sizes.h>
  1634. +#include <time.h>
  1635. +#include <cpu_func.h>
  1636. +#include "launch.h"
  1637. +#include "../mt7621.h"
  1638. +
  1639. +/* Cluster Power Controller (CPC) offsets */
  1640. +#define CPC_CL_OTHER 0x2010
  1641. +#define CPC_CO_CMD 0x4000
  1642. +
  1643. +/* CPC_CL_OTHER fields */
  1644. +#define CPC_CL_OTHER_CORENUM_SHIFT 16
  1645. +#define CPC_CL_OTHER_CORENUM GENMASK(23, 16)
  1646. +
  1647. +/* CPC_CO_CMD */
  1648. +#define PWR_UP 3
  1649. +
  1650. +#define NUM_CORES 2
  1651. +#define NUM_CPUS 4
  1652. +#define WAIT_CPUS_TIMEOUT 4000
  1653. +
  1654. +static void copy_launch_wait_code(void)
  1655. +{
  1656. + memset((void *)KSEG1, 0, SZ_4K);
  1657. +
  1658. + memcpy((void *)KSEG1ADDR(LAUNCH_WAITCODE),
  1659. + &launch_wait_code_start,
  1660. + &launch_wait_code_end - &launch_wait_code_start);
  1661. +
  1662. + invalidate_dcache_range(KSEG0, SZ_4K);
  1663. +}
  1664. +
  1665. +static void bootup_secondary_core(void)
  1666. +{
  1667. + void __iomem *cpcbase = (void __iomem *)KSEG1ADDR(MIPS_CPC_BASE);
  1668. + int i;
  1669. +
  1670. + for (i = 1; i < NUM_CORES; i++) {
  1671. + writel(i << CPC_CL_OTHER_CORENUM_SHIFT, cpcbase + CPC_CL_OTHER);
  1672. + writel(PWR_UP, cpcbase + CPC_CO_CMD);
  1673. + }
  1674. +}
  1675. +
  1676. +void secondary_cpu_init(void)
  1677. +{
  1678. + void __iomem *sysc = (void __iomem *)KSEG1ADDR(SYSCTL_BASE);
  1679. + u32 i, dual_core = 0, cpuready = 1, cpumask = 0x03;
  1680. + ulong wait_tick;
  1681. + struct cpulaunch_t *c;
  1682. +
  1683. + /* Copy LAUNCH wait code used by other VPEs */
  1684. + copy_launch_wait_code();
  1685. +
  1686. + dual_core = readl(sysc + SYSCTL_CHIP_REV_ID_REG) & CPU_ID;
  1687. +
  1688. + if (dual_core) {
  1689. + /* Bootup secondary core for MT7621A */
  1690. + cpumask = 0x0f;
  1691. +
  1692. + /* Make BootROM/TPL redirect Core1's bootup flow to our entry point */
  1693. + writel((uintptr_t)&_start, sysc + BOOT_SRAM_BASE_REG);
  1694. +
  1695. + bootup_secondary_core();
  1696. + }
  1697. +
  1698. + /* Join the coherent domain */
  1699. + join_coherent_domain(dual_core ? 2 : 1);
  1700. +
  1701. + /* Bootup Core0/VPE1 */
  1702. + boot_vpe1();
  1703. +
  1704. + /* Wait for all CPU ready */
  1705. + wait_tick = get_timer(0) + WAIT_CPUS_TIMEOUT;
  1706. +
  1707. + while (time_before(get_timer(0), wait_tick)) {
  1708. + /* CPU0 is obviously ready */
  1709. + for (i = 1; i < NUM_CPUS; i++) {
  1710. + c = (struct cpulaunch_t *)(KSEG0ADDR(CPULAUNCH) +
  1711. + (i << LOG2CPULAUNCH));
  1712. +
  1713. + if (c->flags & LAUNCH_FREADY)
  1714. + cpuready |= BIT(i);
  1715. + }
  1716. +
  1717. + if ((cpuready & cpumask) == cpumask)
  1718. + break;
  1719. + }
  1720. +}
  1721. --- /dev/null
  1722. +++ b/arch/mips/mach-mtmips/mt7621/spl/launch.h
  1723. @@ -0,0 +1,52 @@
  1724. +/* SPDX-License-Identifier: GPL-2.0 */
  1725. +/*
  1726. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  1727. + *
  1728. + * Author: Weijie Gao <[email protected]>
  1729. + */
  1730. +
  1731. +#ifndef _LAUNCH_H_
  1732. +#define _LAUNCH_H_
  1733. +
  1734. +#ifndef __ASSEMBLY__
  1735. +
  1736. +struct cpulaunch_t {
  1737. + unsigned long pc;
  1738. + unsigned long gp;
  1739. + unsigned long sp;
  1740. + unsigned long a0;
  1741. + unsigned long _pad[3]; /* pad to cache line size to avoid thrashing */
  1742. + unsigned long flags;
  1743. +};
  1744. +
  1745. +extern char launch_wait_code_start;
  1746. +extern char launch_wait_code_end;
  1747. +
  1748. +void join_coherent_domain(int ncores);
  1749. +void boot_vpe1(void);
  1750. +
  1751. +#else
  1752. +
  1753. +#define LAUNCH_PC 0
  1754. +#define LAUNCH_GP 4
  1755. +#define LAUNCH_SP 8
  1756. +#define LAUNCH_A0 12
  1757. +#define LAUNCH_FLAGS 28
  1758. +
  1759. +#endif
  1760. +
  1761. +#define LOG2CPULAUNCH 5
  1762. +
  1763. +#define LAUNCH_FREADY 1
  1764. +#define LAUNCH_FGO 2
  1765. +#define LAUNCH_FGONE 4
  1766. +
  1767. +#define LAUNCH_WAITCODE 0x00000d00
  1768. +#define SCRLAUNCH 0x00000e00
  1769. +#define CPULAUNCH 0x00000f00
  1770. +#define NCPULAUNCH 8
  1771. +
  1772. +/* Polling period in count cycles for secondary CPU's */
  1773. +#define LAUNCHPERIOD 10000
  1774. +
  1775. +#endif /* _LAUNCH_H_ */
  1776. --- /dev/null
  1777. +++ b/arch/mips/mach-mtmips/mt7621/spl/launch_ll.S
  1778. @@ -0,0 +1,339 @@
  1779. +/* SPDX-License-Identifier: GPL-2.0 */
  1780. +/*
  1781. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  1782. + *
  1783. + * Author: Weijie Gao <[email protected]>
  1784. + */
  1785. +
  1786. +#include <asm/cm.h>
  1787. +#include <asm/asm.h>
  1788. +#include <asm/regdef.h>
  1789. +#include <asm/cacheops.h>
  1790. +#include <asm/mipsregs.h>
  1791. +#include <asm/addrspace.h>
  1792. +#include <asm/mipsmtregs.h>
  1793. +#include "launch.h"
  1794. +
  1795. + .macro cache_loop curr, end, line_sz, op
  1796. +10: cache \op, 0(\curr)
  1797. + PTR_ADDU \curr, \curr, \line_sz
  1798. + bne \curr, \end, 10b
  1799. + .endm
  1800. +
  1801. + .set mt
  1802. +
  1803. +/*
  1804. + * Join the coherent domain
  1805. + * a0 = number of cores
  1806. + */
  1807. +LEAF(join_coherent_domain)
  1808. + /*
  1809. + * Enable coherence and allow interventions from all other cores.
  1810. + * (Write access enabled via GCR_ACCESS by core 0.)
  1811. + */
  1812. + li t1, 1
  1813. + sll t1, a0
  1814. + addiu t1, -1
  1815. +
  1816. + li t0, KSEG1ADDR(CONFIG_MIPS_CM_BASE)
  1817. + sw t1, GCR_Cx_COHERENCE(t0)
  1818. + ehb
  1819. +
  1820. + move t2, zero
  1821. +
  1822. +_next_coherent_core:
  1823. + sll t1, t2, GCR_Cx_OTHER_CORENUM_SHIFT
  1824. + sw t1, GCR_Cx_OTHER(t0)
  1825. +
  1826. +_busy_wait_coherent_core:
  1827. + lw t1, GCR_CO_COHERENCE(t0)
  1828. + beqz t1, _busy_wait_coherent_core
  1829. +
  1830. + addiu t2, 1
  1831. + bne t2, a0, _next_coherent_core
  1832. +
  1833. + jr ra
  1834. + END(join_coherent_domain)
  1835. +
  1836. +/*
  1837. + * All VPEs other than VPE0 will go here.
  1838. + */
  1839. +LEAF(launch_vpe_entry)
  1840. + mfc0 t0, CP0_EBASE
  1841. + and t0, t0, MIPS_EBASE_CPUNUM
  1842. +
  1843. + /* per-VPE cpulaunch_t */
  1844. + li a0, KSEG0ADDR(CPULAUNCH)
  1845. + sll t1, t0, LOG2CPULAUNCH
  1846. + addu a0, t1
  1847. +
  1848. + /* Set CPU online flag */
  1849. + li t0, LAUNCH_FREADY
  1850. + sw t0, LAUNCH_FLAGS(a0)
  1851. +
  1852. + /* Enable count interrupt in mask, but do not enable interrupts */
  1853. + mfc0 t0, CP0_STATUS
  1854. + ori t0, STATUSF_IP7
  1855. + mtc0 t0, CP0_STATUS
  1856. +
  1857. + /* VPEs executing in wait code do not need a stack */
  1858. + li t9, KSEG0ADDR(LAUNCH_WAITCODE)
  1859. + jr t9
  1860. + END(launch_vpe_entry)
  1861. +
  1862. +/*
  1863. + * This function will not be executed in place.
  1864. + * It will be copied into memory, and VPEs other than VPE0 will be
  1865. + * started to run into this in-memory function.
  1866. + */
  1867. +LEAF(launch_wait_code)
  1868. + .globl launch_wait_code_start
  1869. +launch_wait_code_start:
  1870. +
  1871. + move t0, a0
  1872. +
  1873. +start_poll:
  1874. + /* Poll CPU go flag */
  1875. + mtc0 zero, CP0_COUNT
  1876. + li t1, LAUNCHPERIOD
  1877. + mtc0 t1, CP0_COMPARE
  1878. +
  1879. +time_wait:
  1880. + /* Software wait */
  1881. + mfc0 t2, CP0_COUNT
  1882. + subu t2, t1
  1883. + bltz t2, time_wait
  1884. +
  1885. + /* Check the launch flag */
  1886. + lw t3, LAUNCH_FLAGS(t0)
  1887. + and t3, LAUNCH_FGO
  1888. + beqz t3, start_poll
  1889. +
  1890. + /* Reset the counter and interrupts to give naive clients a chance */
  1891. + mfc0 t1, CP0_STATUS
  1892. + ins t1, zero, STATUSB_IP7, 1
  1893. + mtc0 t1, CP0_STATUS
  1894. +
  1895. + mfc0 t1, CP0_COUNT
  1896. + subu t1, 1
  1897. + mtc0 t1, CP0_COMPARE
  1898. +
  1899. + /* Jump to kernel */
  1900. + lw t9, LAUNCH_PC(t0)
  1901. + lw gp, LAUNCH_GP(t0)
  1902. + lw sp, LAUNCH_SP(t0)
  1903. + lw a0, LAUNCH_A0(t0)
  1904. + move a1, zero
  1905. + move a2, zero
  1906. + move a3, zero
  1907. + ori t3, LAUNCH_FGONE
  1908. + sw t3, LAUNCH_FLAGS(t0)
  1909. +
  1910. + jr t9
  1911. +
  1912. + .globl launch_wait_code_end
  1913. +launch_wait_code_end:
  1914. + END(launch_wait_code)
  1915. +
  1916. +/*
  1917. + * Core1 will go here.
  1918. + */
  1919. +LEAF(launch_core_entry)
  1920. + /* Disable caches */
  1921. + bal mips_cache_disable
  1922. +
  1923. + /* Initialize L1 cache only */
  1924. + li a0, CONFIG_SYS_ICACHE_SIZE
  1925. + li a1, CONFIG_SYS_ICACHE_LINE_SIZE
  1926. + li a2, CONFIG_SYS_DCACHE_SIZE
  1927. + li a3, CONFIG_SYS_DCACHE_LINE_SIZE
  1928. +
  1929. + mtc0 zero, CP0_TAGLO
  1930. + mtc0 zero, CP0_TAGLO, 2
  1931. + ehb
  1932. +
  1933. + /*
  1934. + * Initialize the I-cache first,
  1935. + */
  1936. + li t0, KSEG0
  1937. + addu t1, t0, a0
  1938. + /* clear tag to invalidate */
  1939. + cache_loop t0, t1, a1, INDEX_STORE_TAG_I
  1940. +#ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
  1941. + /* fill once, so data field parity is correct */
  1942. + PTR_LI t0, KSEG0
  1943. + cache_loop t0, t1, a1, FILL
  1944. + /* invalidate again - prudent but not strictly necessary */
  1945. + PTR_LI t0, KSEG0
  1946. + cache_loop t0, t1, a1, INDEX_STORE_TAG_I
  1947. +#endif
  1948. +
  1949. + /*
  1950. + * then initialize D-cache.
  1951. + */
  1952. + PTR_LI t0, KSEG0
  1953. + PTR_ADDU t1, t0, a2
  1954. + /* clear all tags */
  1955. + cache_loop t0, t1, a3, INDEX_STORE_TAG_D
  1956. +#ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
  1957. + /* load from each line (in cached space) */
  1958. + PTR_LI t0, KSEG0
  1959. +2: LONG_L zero, 0(t0)
  1960. + PTR_ADDU t0, a3
  1961. + bne t0, t1, 2b
  1962. + /* clear all tags */
  1963. + PTR_LI t0, KSEG0
  1964. + cache_loop t0, t1, a3, INDEX_STORE_TAG_D
  1965. +#endif
  1966. +
  1967. + /* Set Cache Mode */
  1968. + mfc0 t0, CP0_CONFIG
  1969. + li t1, CONF_CM_CACHABLE_COW
  1970. + ins t0, t1, 0, 3
  1971. + mtc0 t0, CP0_CONFIG
  1972. +
  1973. + /* Join the coherent domain */
  1974. + li a0, 2
  1975. + bal join_coherent_domain
  1976. +
  1977. + /* Bootup Core0/VPE1 */
  1978. + bal boot_vpe1
  1979. +
  1980. + b launch_vpe_entry
  1981. + END(launch_core_entry)
  1982. +
  1983. +/*
  1984. + * Bootup VPE1.
  1985. + * This subroutine must be executed from VPE0 with VPECONF0[MVP] already set.
  1986. + */
  1987. +LEAF(boot_vpe1)
  1988. + mfc0 t0, CP0_MVPCONF0
  1989. +
  1990. + /* a0 = number of TCs - 1 */
  1991. + ext a0, t0, MVPCONF0_PTC_SHIFT, 8
  1992. + beqz a0, _vpe1_init_done
  1993. +
  1994. + /* a1 = number of VPEs - 1 */
  1995. + ext a1, t0, MVPCONF0_PVPE_SHIFT, 4
  1996. + beqz a1, _vpe1_init_done
  1997. +
  1998. + /* a2 = current TC No. */
  1999. + move a2, zero
  2000. +
  2001. + /* Enter VPE Configuration State */
  2002. + mfc0 t0, CP0_MVPCONTROL
  2003. + or t0, MVPCONTROL_VPC
  2004. + mtc0 t0, CP0_MVPCONTROL
  2005. + ehb
  2006. +
  2007. +_next_tc:
  2008. + /* Set the TC number to be used on MTTR and MFTR instructions */
  2009. + mfc0 t0, CP0_VPECONTROL
  2010. + ins t0, a2, 0, 8
  2011. + mtc0 t0, CP0_VPECONTROL
  2012. + ehb
  2013. +
  2014. + /* TC0 is already bound */
  2015. + beqz a2, _next_vpe
  2016. +
  2017. + /* Halt current TC */
  2018. + li t0, TCHALT_H
  2019. + mttc0 t0, CP0_TCHALT
  2020. + ehb
  2021. +
  2022. + /* If there is spare TC, bind it to the last VPE (VPE[a1]) */
  2023. + slt t1, a1, a2
  2024. + bnez t1, _vpe_bind_tc
  2025. + move t1, a1
  2026. +
  2027. + /* Set Exclusive TC for active TC */
  2028. + mftc0 t0, CP0_VPECONF0
  2029. + ins t0, a2, VPECONF0_XTC_SHIFT, 8
  2030. + mttc0 t0, CP0_VPECONF0
  2031. +
  2032. + move t1, a2
  2033. +_vpe_bind_tc:
  2034. + /* Bind TC to a VPE */
  2035. + mftc0 t0, CP0_TCBIND
  2036. + ins t0, t1, TCBIND_CURVPE_SHIFT, 4
  2037. + mttc0 t0, CP0_TCBIND
  2038. +
  2039. + /*
  2040. + * Set up CP0_TCSTATUS register:
  2041. + * Disable Coprocessor Usable bits
  2042. + * Disable MDMX/DSP ASE
  2043. + * Clear Dirty TC
  2044. + * not dynamically allocatable
  2045. + * not allocated
  2046. + * Kernel mode
  2047. + * interrupt exempt
  2048. + * ASID 0
  2049. + */
  2050. + li t0, TCSTATUS_IXMT
  2051. + mttc0 t0, CP0_TCSTATUS
  2052. +
  2053. +_next_vpe:
  2054. + slt t1, a1, a2
  2055. + bnez t1, _done_vpe # No more VPEs
  2056. +
  2057. + /* Disable TC multi-threading */
  2058. + mftc0 t0, CP0_VPECONTROL
  2059. + ins t0, zero, VPECONTROL_TE_SHIFT, 1
  2060. + mttc0 t0, CP0_VPECONTROL
  2061. +
  2062. + /* Skip following configuration for TC0 */
  2063. + beqz a2, _done_vpe
  2064. +
  2065. + /* Deactivate VPE, set Master VPE */
  2066. + mftc0 t0, CP0_VPECONF0
  2067. + ins t0, zero, VPECONF0_VPA_SHIFT, 1
  2068. + or t0, VPECONF0_MVP
  2069. + mttc0 t0, CP0_VPECONF0
  2070. +
  2071. + mfc0 t0, CP0_STATUS
  2072. + mttc0 t0, CP0_STATUS
  2073. +
  2074. + mttc0 zero, CP0_EPC
  2075. + mttc0 zero, CP0_CAUSE
  2076. +
  2077. + mfc0 t0, CP0_CONFIG
  2078. + mttc0 t0, CP0_CONFIG
  2079. +
  2080. + /*
  2081. + * VPE1 of each core can execute cached as its L1 I$ has already
  2082. + * been initialized.
  2083. + * and the L2$ has been initialized or "disabled" via CCA override.
  2084. + */
  2085. + PTR_LA t0, _start
  2086. + mttc0 t0, CP0_TCRESTART
  2087. +
  2088. + /* Unset Interrupt Exempt, set Activate Thread */
  2089. + mftc0 t0, CP0_TCSTATUS
  2090. + ins t0, zero, TCSTATUS_IXMT_SHIFT, 1
  2091. + ori t0, TCSTATUS_A
  2092. + mttc0 t0, CP0_TCSTATUS
  2093. +
  2094. + /* Resume TC */
  2095. + mttc0 zero, CP0_TCHALT
  2096. +
  2097. + /* Activate VPE */
  2098. + mftc0 t0, CP0_VPECONF0
  2099. + ori t0, VPECONF0_VPA
  2100. + mttc0 t0, CP0_VPECONF0
  2101. +
  2102. +_done_vpe:
  2103. + addu a2, 1
  2104. + sltu t0, a0, a2
  2105. + beqz t0, _next_tc
  2106. +
  2107. + mfc0 t0, CP0_MVPCONTROL
  2108. + /* Enable all activated VPE to execute */
  2109. + ori t0, MVPCONTROL_EVP
  2110. + /* Exit VPE Configuration State */
  2111. + ins t0, zero, MVPCONTROL_VPC_SHIFT, 1
  2112. + mtc0 t0, CP0_MVPCONTROL
  2113. + ehb
  2114. +
  2115. +_vpe1_init_done:
  2116. + jr ra
  2117. + END(boot_vpe1)
  2118. --- /dev/null
  2119. +++ b/arch/mips/mach-mtmips/mt7621/spl/serial.c
  2120. @@ -0,0 +1,24 @@
  2121. +// SPDX-License-Identifier: GPL-2.0
  2122. +/*
  2123. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  2124. + *
  2125. + * Author: Weijie Gao <[email protected]>
  2126. + */
  2127. +
  2128. +#include <asm/io.h>
  2129. +#include "../mt7621.h"
  2130. +
  2131. +void mtmips_spl_serial_init(void)
  2132. +{
  2133. +#ifdef CONFIG_SPL_SERIAL
  2134. + void __iomem *base = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
  2135. +
  2136. +#if CONFIG_CONS_INDEX == 1
  2137. + clrbits_32(base + SYSCTL_GPIOMODE_REG, UART1_MODE);
  2138. +#elif CONFIG_CONS_INDEX == 2
  2139. + clrbits_32(base + SYSCTL_GPIOMODE_REG, UART2_MODE_M);
  2140. +#elif CONFIG_CONS_INDEX == 3
  2141. + clrbits_32(base + SYSCTL_GPIOMODE_REG, UART3_MODE_M);
  2142. +#endif /* CONFIG_CONS_INDEX */
  2143. +#endif /* CONFIG_SPL_SERIAL */
  2144. +}
  2145. --- /dev/null
  2146. +++ b/arch/mips/mach-mtmips/mt7621/spl/spl.c
  2147. @@ -0,0 +1,95 @@
  2148. +// SPDX-License-Identifier: GPL-2.0
  2149. +/*
  2150. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  2151. + *
  2152. + * Author: Weijie Gao <[email protected]>
  2153. + */
  2154. +
  2155. +#include <spl.h>
  2156. +#include <init.h>
  2157. +#include <image.h>
  2158. +#include <vsprintf.h>
  2159. +#include <malloc.h>
  2160. +#include <asm/io.h>
  2161. +#include <asm/sections.h>
  2162. +#include <asm/addrspace.h>
  2163. +#include <asm/byteorder.h>
  2164. +#include <asm/global_data.h>
  2165. +#include <linux/sizes.h>
  2166. +#include <mach/serial.h>
  2167. +#include "../mt7621.h"
  2168. +#include "dram.h"
  2169. +
  2170. +DECLARE_GLOBAL_DATA_PTR;
  2171. +
  2172. +struct tpl_info {
  2173. + u32 magic;
  2174. + u32 size;
  2175. +};
  2176. +
  2177. +void set_timer_freq_simple(void)
  2178. +{
  2179. + u32 div = get_xtal_mhz();
  2180. +
  2181. + /* Round down cpu freq */
  2182. + gd->arch.timer_freq = rounddown(CONFIG_MT7621_CPU_FREQ, div) * 500000;
  2183. +}
  2184. +
  2185. +void __noreturn board_init_f(ulong dummy)
  2186. +{
  2187. + spl_init();
  2188. +
  2189. +#ifdef CONFIG_SPL_SERIAL
  2190. + /*
  2191. + * mtmips_spl_serial_init() is useful if debug uart is enabled,
  2192. + * or DM based serial is not enabled.
  2193. + */
  2194. + mtmips_spl_serial_init();
  2195. + preloader_console_init();
  2196. +#endif
  2197. +
  2198. + board_init_r(NULL, 0);
  2199. +}
  2200. +
  2201. +void board_boot_order(u32 *spl_boot_list)
  2202. +{
  2203. +#ifdef CONFIG_MT7621_BOOT_FROM_NAND
  2204. + spl_boot_list[0] = BOOT_DEVICE_NAND;
  2205. +#else
  2206. + spl_boot_list[0] = BOOT_DEVICE_NOR;
  2207. +#endif
  2208. +}
  2209. +
  2210. +unsigned long spl_nor_get_uboot_base(void)
  2211. +{
  2212. + const struct tpl_info *tpli;
  2213. + const image_header_t *hdr;
  2214. + u32 addr;
  2215. +
  2216. + addr = FLASH_MMAP_BASE + TPL_INFO_OFFSET;
  2217. + tpli = (const struct tpl_info *)KSEG1ADDR(addr);
  2218. +
  2219. + if (tpli->magic == TPL_INFO_MAGIC) {
  2220. + addr = FLASH_MMAP_BASE + tpli->size;
  2221. + hdr = (const image_header_t *)KSEG1ADDR(addr);
  2222. +
  2223. + if (image_get_magic(hdr) == IH_MAGIC) {
  2224. + addr += sizeof(*hdr) + image_get_size(hdr);
  2225. + return KSEG1ADDR(addr);
  2226. + }
  2227. + }
  2228. +
  2229. + panic("Unable to locate SPL payload\n");
  2230. + return 0;
  2231. +}
  2232. +
  2233. +uint32_t spl_nand_get_uboot_raw_page(void)
  2234. +{
  2235. + const struct stage_header *sh = (const struct stage_header *)&_start;
  2236. + u32 addr;
  2237. +
  2238. + addr = image_get_header_size() + be32_to_cpu(sh->stage_size);
  2239. + addr = ALIGN(addr, SZ_4K);
  2240. +
  2241. + return addr;
  2242. +}
  2243. --- /dev/null
  2244. +++ b/arch/mips/mach-mtmips/mt7621/spl/start.S
  2245. @@ -0,0 +1,226 @@
  2246. +/* SPDX-License-Identifier: GPL-2.0 */
  2247. +/*
  2248. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  2249. + *
  2250. + * Author: Weijie Gao <[email protected]>
  2251. + */
  2252. +
  2253. +#include <asm-offsets.h>
  2254. +#include <config.h>
  2255. +#include <asm/asm.h>
  2256. +#include <asm/regdef.h>
  2257. +#include <asm/mipsregs.h>
  2258. +#include <asm/cacheops.h>
  2259. +#include <asm/addrspace.h>
  2260. +#include <asm/mipsmtregs.h>
  2261. +#include <asm/cm.h>
  2262. +#include "../mt7621.h"
  2263. +#include "dram.h"
  2264. +
  2265. +#ifndef CONFIG_SYS_INIT_SP_ADDR
  2266. +#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + \
  2267. + CONFIG_SYS_INIT_SP_OFFSET)
  2268. +#endif
  2269. +
  2270. +#define SP_ADDR_TEMP 0xbe10dff0
  2271. +
  2272. + .macro init_wr sel
  2273. + MTC0 zero, CP0_WATCHLO,\sel
  2274. + mtc0 t1, CP0_WATCHHI,\sel
  2275. + .endm
  2276. +
  2277. + .macro setup_stack_gd
  2278. + li t0, -16
  2279. + PTR_LI t1, CONFIG_SYS_INIT_SP_ADDR
  2280. + and sp, t1, t0 # force 16 byte alignment
  2281. + PTR_SUBU \
  2282. + sp, sp, GD_SIZE # reserve space for gd
  2283. + and sp, sp, t0 # force 16 byte alignment
  2284. + move k0, sp # save gd pointer
  2285. +#if CONFIG_VAL(SYS_MALLOC_F_LEN) && \
  2286. + !CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
  2287. + li t2, CONFIG_VAL(SYS_MALLOC_F_LEN)
  2288. + PTR_SUBU \
  2289. + sp, sp, t2 # reserve space for early malloc
  2290. + and sp, sp, t0 # force 16 byte alignment
  2291. +#endif
  2292. + move fp, sp
  2293. +
  2294. + /* Clear gd */
  2295. + move t0, k0
  2296. +1:
  2297. + PTR_S zero, 0(t0)
  2298. + PTR_ADDIU t0, PTRSIZE
  2299. + blt t0, t1, 1b
  2300. + nop
  2301. +
  2302. +#if CONFIG_VAL(SYS_MALLOC_F_LEN) && \
  2303. + !CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
  2304. + PTR_S sp, GD_MALLOC_BASE(k0) # gd->malloc_base offset
  2305. +#endif
  2306. + .endm
  2307. +
  2308. + .set noreorder
  2309. +
  2310. +ENTRY(_start)
  2311. + b 1f
  2312. + mtc0 zero, CP0_COUNT
  2313. +
  2314. + /* Stage header required by BootROM */
  2315. + .org 0x8
  2316. + .word 0 # ep, filled by mkimage
  2317. + .word 0 # stage_size, filled by mkimage
  2318. + .word 0 # has_stage2
  2319. + .word 0 # next_ep
  2320. + .word 0 # next_size
  2321. + .word 0 # next_offset
  2322. +
  2323. +1:
  2324. + /* Init CP0 Status */
  2325. + mfc0 t0, CP0_STATUS
  2326. + and t0, ST0_IMPL
  2327. + or t0, ST0_BEV | ST0_ERL
  2328. + mtc0 t0, CP0_STATUS
  2329. + ehb
  2330. +
  2331. + /* Clear Watch Status bits and disable watch exceptions */
  2332. + li t1, 0x7 # Clear I, R and W conditions
  2333. + init_wr 0
  2334. + init_wr 1
  2335. + init_wr 2
  2336. + init_wr 3
  2337. +
  2338. + /* Clear WP, IV and SW interrupts */
  2339. + mtc0 zero, CP0_CAUSE
  2340. +
  2341. + /* Clear timer interrupt (CP0_COUNT cleared on branch to 'reset') */
  2342. + mtc0 zero, CP0_COMPARE
  2343. +
  2344. + /* VPE1 goes to wait code directly */
  2345. + mfc0 t0, CP0_TCBIND
  2346. + andi t0, TCBIND_CURVPE
  2347. + bnez t0, launch_vpe_entry
  2348. + nop
  2349. +
  2350. + /* Core1 goes to specific launch entry */
  2351. + PTR_LI t0, KSEG1ADDR(CONFIG_MIPS_CM_BASE)
  2352. + lw t1, GCR_Cx_ID(t0)
  2353. + bnez t1, launch_core_entry
  2354. + nop
  2355. +
  2356. + /* MT7530 reset */
  2357. + li t0, KSEG1ADDR(SYSCTL_BASE)
  2358. + lw t1, SYSCTL_RSTCTL_REG(t0)
  2359. + ori t1, MCM_RST
  2360. + sw t1, SYSCTL_RSTCTL_REG(t0)
  2361. +
  2362. + /* Disable DMA route for PSE SRAM set by BootROM */
  2363. + PTR_LI t0, KSEG1ADDR(DMA_CFG_ARB_BASE)
  2364. + sw zero, DMA_ROUTE_REG(t0)
  2365. +
  2366. + /* Set CPU clock to 500MHz (Required if boot from NAND) */
  2367. + li t0, KSEG1ADDR(SYSCTL_BASE)
  2368. + lw t1, SYSCTL_CLKCFG0_REG(t0)
  2369. + ins t1, zero, 30, 2 # CPU_CLK_SEL
  2370. + sw t1, SYSCTL_CLKCFG0_REG(t0)
  2371. +
  2372. + /* Set CPU clock divider to 1/1 */
  2373. + li t0, KSEG1ADDR(RBUS_BASE)
  2374. + li t1, 0x101
  2375. + sw t1, RBUS_DYN_CFG0_REG(t0)
  2376. +
  2377. + /* (Re-)initialize the SRAM */
  2378. + bal mips_sram_init
  2379. + nop
  2380. +
  2381. + /* Set up temporary stack */
  2382. + li sp, SP_ADDR_TEMP
  2383. +
  2384. + /* Setup full CPS */
  2385. + bal mips_cm_map
  2386. + nop
  2387. +
  2388. + bal mt7621_cps_init
  2389. + nop
  2390. +
  2391. + /* Prepare for CPU/DDR initialization binary blob */
  2392. + bal prepare_stage_bin
  2393. + nop
  2394. +
  2395. + /* Call CPU/DDR initialization binary blob */
  2396. + li t9, STAGE_LOAD_ADDR
  2397. + jalr t9
  2398. + nop
  2399. +
  2400. + /* Switch CPU PLL source */
  2401. + li t0, KSEG1ADDR(SYSCTL_BASE)
  2402. + lw t1, SYSCTL_CLKCFG0_REG(t0)
  2403. + li t2, 1
  2404. + ins t1, t2, CPU_CLK_SEL_S, 2
  2405. + sw t1, SYSCTL_CLKCFG0_REG(t0)
  2406. +
  2407. + /*
  2408. + * Currently SPL is running on locked L2 cache (on KSEG0).
  2409. + * To reset the entire cache, we have to writeback SPL to DRAM first.
  2410. + * Cache flush won't work here. Use memcpy instead.
  2411. + */
  2412. +
  2413. + la a0, __text_start
  2414. + move a1, a0
  2415. + la a2, __image_copy_end
  2416. + sub a2, a2, a1
  2417. + li a3, 5
  2418. + ins a0, a3, 29, 3 # convert to KSEG1
  2419. +
  2420. + bal memcpy
  2421. + nop
  2422. +
  2423. + /* Disable caches */
  2424. + bal mips_cache_disable
  2425. + nop
  2426. +
  2427. + /* Reset caches */
  2428. + bal mips_cache_reset
  2429. + nop
  2430. +
  2431. + /* Disable SRAM */
  2432. + li t0, KSEG1ADDR(FE_BASE)
  2433. + li t1, FE_PSE_RESET
  2434. + sw t1, FE_RST_GLO_REG(t0)
  2435. +
  2436. + /* Clear the .bss section */
  2437. + la a0, __bss_start
  2438. + la a1, __bss_end
  2439. +1: sw zero, 0(a0)
  2440. + addiu a0, 4
  2441. + ble a0, a1, 1b
  2442. + nop
  2443. +
  2444. + /* Set up initial stack and global data */
  2445. + setup_stack_gd
  2446. +
  2447. +#if CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
  2448. + /* Set malloc base */
  2449. + li t0, (CONFIG_SYS_INIT_SP_ADDR + 15) & (~15)
  2450. + PTR_S t0, GD_MALLOC_BASE(k0) # gd->malloc_base offset
  2451. +#endif
  2452. +
  2453. +#if defined(CONFIG_DEBUG_UART) && defined(CONFIG_SPL_SERIAL)
  2454. + /* Earliest point to set up debug uart */
  2455. + bal debug_uart_init
  2456. + nop
  2457. +#endif
  2458. +
  2459. + /* Setup timer */
  2460. + bal set_timer_freq_simple
  2461. + nop
  2462. +
  2463. + /* Bootup secondary CPUs */
  2464. + bal secondary_cpu_init
  2465. + nop
  2466. +
  2467. + move a0, zero # a0 <-- boot_flags = 0
  2468. + bal board_init_f
  2469. + move ra, zero
  2470. +
  2471. + END(_start)
  2472. --- /dev/null
  2473. +++ b/arch/mips/mach-mtmips/mt7621/sram_init.S
  2474. @@ -0,0 +1,22 @@
  2475. +/* SPDX-License-Identifier: GPL-2.0 */
  2476. +/*
  2477. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  2478. + *
  2479. + * Author: Weijie Gao <[email protected]>
  2480. + */
  2481. +
  2482. +#include <asm/addrspace.h>
  2483. +#include <asm/asm.h>
  2484. +#include <asm/regdef.h>
  2485. +#include "mt7621.h"
  2486. +
  2487. +LEAF(mips_sram_init)
  2488. + li t0, KSEG1ADDR(FE_BASE)
  2489. + li t1, FE_PSE_RESET
  2490. + sw t1, FE_RST_GLO_REG(t0)
  2491. +
  2492. + li t1, (FE_PSE_RAM | FE_PSE_MEM_EN)
  2493. + sw t1, FE_RST_GLO_REG(t0)
  2494. +
  2495. + jr ra
  2496. + END(mips_sram_init)
  2497. --- /dev/null
  2498. +++ b/arch/mips/mach-mtmips/mt7621/tpl/Makefile
  2499. @@ -0,0 +1,4 @@
  2500. +
  2501. +extra-y += start.o
  2502. +
  2503. +obj-y += tpl.o
  2504. --- /dev/null
  2505. +++ b/arch/mips/mach-mtmips/mt7621/tpl/start.S
  2506. @@ -0,0 +1,161 @@
  2507. +/* SPDX-License-Identifier: GPL-2.0 */
  2508. +/*
  2509. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  2510. + *
  2511. + * Author: Weijie Gao <[email protected]>
  2512. + */
  2513. +
  2514. +#include <asm-offsets.h>
  2515. +#include <config.h>
  2516. +#include <asm/asm.h>
  2517. +#include <asm/regdef.h>
  2518. +#include <asm/addrspace.h>
  2519. +#include <asm/mipsregs.h>
  2520. +#include <asm/cm.h>
  2521. +#include "../mt7621.h"
  2522. +
  2523. +#define SP_ADDR_TEMP 0xbe10dff0
  2524. +
  2525. + .set noreorder
  2526. +
  2527. + .macro init_wr sel
  2528. + MTC0 zero, CP0_WATCHLO,\sel
  2529. + mtc0 t1, CP0_WATCHHI,\sel
  2530. + .endm
  2531. +
  2532. + .macro uhi_mips_exception
  2533. + move k0, t9 # preserve t9 in k0
  2534. + move k1, a0 # preserve a0 in k1
  2535. + li t9, 15 # UHI exception operation
  2536. + li a0, 0 # Use hard register context
  2537. + sdbbp 1 # Invoke UHI operation
  2538. + .endm
  2539. +
  2540. +ENTRY(_start)
  2541. + b reset
  2542. + mtc0 zero, CP0_COUNT
  2543. +
  2544. + /*
  2545. + * Store TPL size here.
  2546. + * This will be used by SPL to locate u-boot payload.
  2547. + */
  2548. + .org TPL_INFO_OFFSET
  2549. + .word TPL_INFO_MAGIC
  2550. + .word __image_copy_len
  2551. +
  2552. + /* Exception vector */
  2553. + .org 0x200
  2554. + /* TLB refill, 32 bit task */
  2555. + uhi_mips_exception
  2556. +
  2557. + .org 0x280
  2558. + /* XTLB refill, 64 bit task */
  2559. + uhi_mips_exception
  2560. +
  2561. + .org 0x300
  2562. + /* Cache error exception */
  2563. + uhi_mips_exception
  2564. +
  2565. + .org 0x380
  2566. + /* General exception */
  2567. + uhi_mips_exception
  2568. +
  2569. + .org 0x400
  2570. + /* Catch interrupt exceptions */
  2571. + uhi_mips_exception
  2572. +
  2573. + .org 0x480
  2574. + /* EJTAG debug exception */
  2575. +1: b 1b
  2576. + nop
  2577. +
  2578. + .org 0x500
  2579. +
  2580. +reset:
  2581. + /* Set KSEG0 to Uncached */
  2582. + mfc0 t0, CP0_CONFIG
  2583. + ins t0, zero, 0, 3
  2584. + ori t0, t0, CONF_CM_UNCACHED
  2585. + mtc0 t0, CP0_CONFIG
  2586. + ehb
  2587. +
  2588. + /* Check for CPU number */
  2589. + mfc0 t0, CP0_EBASE
  2590. + and t0, t0, MIPS_EBASE_CPUNUM
  2591. + beqz t0, 1f
  2592. + nop
  2593. +
  2594. + /* Secondary core goes to specified SPL entry address */
  2595. + li t0, KSEG1ADDR(SYSCTL_BASE)
  2596. + lw t0, BOOT_SRAM_BASE_REG(t0)
  2597. + jr t0
  2598. + nop
  2599. +
  2600. + /* Init CP0 Status */
  2601. +1: mfc0 t0, CP0_STATUS
  2602. + and t0, ST0_IMPL
  2603. + or t0, ST0_BEV | ST0_ERL
  2604. + mtc0 t0, CP0_STATUS
  2605. + nop
  2606. +
  2607. + /* Clear Watch Status bits and disable watch exceptions */
  2608. + li t1, 0x7 # Clear I, R and W conditions
  2609. + init_wr 0
  2610. + init_wr 1
  2611. + init_wr 2
  2612. + init_wr 3
  2613. +
  2614. + /* Clear WP, IV and SW interrupts */
  2615. + mtc0 zero, CP0_CAUSE
  2616. +
  2617. + /* Clear timer interrupt (CP0_COUNT cleared on branch to 'reset') */
  2618. + mtc0 zero, CP0_COMPARE
  2619. +
  2620. + /* Setup basic CPS */
  2621. + bal mips_cm_map
  2622. + nop
  2623. +
  2624. + li t0, KSEG1ADDR(CONFIG_MIPS_CM_BASE)
  2625. + li t1, GCR_REG0_BASE_VALUE
  2626. + sw t1, GCR_REG0_BASE(t0)
  2627. +
  2628. + li t1, ((GCR_REG0_MASK_VALUE << GCR_REGn_MASK_ADDRMASK_SHIFT) | \
  2629. + GCR_REGn_MASK_CMTGT_IOCU0)
  2630. + sw t1, GCR_REG0_MASK(t0)
  2631. +
  2632. + lw t1, GCR_BASE(t0)
  2633. + ins t1, zero, 0, 2 # CM_DEFAULT_TARGET
  2634. + sw t1, GCR_BASE(t0)
  2635. +
  2636. + lw t1, GCR_CONTROL(t0)
  2637. + li t2, GCR_CONTROL_SYNCCTL
  2638. + or t1, t1, t2
  2639. + sw t1, GCR_CONTROL(t0)
  2640. +
  2641. + /* Increase SPI frequency */
  2642. + li t0, KSEG1ADDR(SPI_BASE)
  2643. + li t1, 5
  2644. + sw t1, SPI_SPACE_REG(t0)
  2645. +
  2646. + /* Set CPU clock to 500MHz */
  2647. + li t0, KSEG1ADDR(SYSCTL_BASE)
  2648. + lw t1, SYSCTL_CLKCFG0_REG(t0)
  2649. + ins t1, zero, 30, 2 # CPU_CLK_SEL
  2650. + sw t1, SYSCTL_CLKCFG0_REG(t0)
  2651. +
  2652. + /* Set CPU clock divider to 1/1 */
  2653. + li t0, KSEG1ADDR(RBUS_BASE)
  2654. + li t1, 0x101
  2655. + sw t1, RBUS_DYN_CFG0_REG(t0)
  2656. +
  2657. + /* Initialize the SRAM */
  2658. + bal mips_sram_init
  2659. + nop
  2660. +
  2661. + /* Set up initial stack */
  2662. + li sp, SP_ADDR_TEMP
  2663. +
  2664. + bal tpl_main
  2665. + nop
  2666. +
  2667. + END(_start)
  2668. --- /dev/null
  2669. +++ b/arch/mips/mach-mtmips/mt7621/tpl/tpl.c
  2670. @@ -0,0 +1,144 @@
  2671. +// SPDX-License-Identifier: GPL-2.0
  2672. +/*
  2673. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  2674. + *
  2675. + * Author: Weijie Gao <[email protected]>
  2676. + */
  2677. +
  2678. +#include <image.h>
  2679. +#include <asm/system.h>
  2680. +#include <asm/sections.h>
  2681. +#include <asm/cacheops.h>
  2682. +#include <asm/mipsregs.h>
  2683. +#include <asm/cm.h>
  2684. +
  2685. +#define INDEX_STORE_DATA_SD 0x0f
  2686. +
  2687. +typedef void __noreturn (*image_entry_noargs_t)(void);
  2688. +
  2689. +/*
  2690. + * Lock L2 cache and fill data
  2691. + * Assume that data is 4-byte aligned and start_addr/size is 32-byte aligned
  2692. + */
  2693. +static void fill_lock_l2cache(uintptr_t dataptr, ulong start_addr, ulong size)
  2694. +{
  2695. + ulong slsize = CONFIG_SYS_DCACHE_LINE_SIZE;
  2696. + ulong end_addr = start_addr + size;
  2697. + const u32 *data = (u32 *)dataptr;
  2698. + ulong i, addr;
  2699. + u32 val;
  2700. +
  2701. + /* Clear WSC & SPR bit in ErrCtl */
  2702. + val = read_c0_ecc();
  2703. + val &= 0xcfffffff;
  2704. + write_c0_ecc(val);
  2705. + execution_hazard_barrier();
  2706. +
  2707. + for (addr = start_addr; addr < end_addr; addr += slsize) {
  2708. + /* Set STagLo to lock cache line */
  2709. + write_c0_staglo((addr & 0x1ffff800) | 0xa0);
  2710. + mips_cache(INDEX_STORE_TAG_SD, (void *)addr);
  2711. +
  2712. + /* Fill data */
  2713. + for (i = 0; i < slsize; i += 8) {
  2714. + val = *data++;
  2715. + __write_32bit_c0_register($28, 5, val); /* sdtaglo */
  2716. + val = *data++;
  2717. + __write_32bit_c0_register($29, 5, val); /* sdtaghi */
  2718. + mips_cache(INDEX_STORE_DATA_SD, (void *)(addr + i));
  2719. + }
  2720. + }
  2721. +
  2722. + sync();
  2723. +}
  2724. +
  2725. +/* A simple function to initialize MT7621's cache */
  2726. +static void mt7621_cache_init(void)
  2727. +{
  2728. + void __iomem *cm_base = (void *)KSEG1ADDR(CONFIG_MIPS_CM_BASE);
  2729. + ulong lsize = CONFIG_SYS_DCACHE_LINE_SIZE;
  2730. + ulong addr;
  2731. + u32 val;
  2732. +
  2733. + /* Enable CCA override. Set to uncached */
  2734. + val = readl(cm_base + GCR_BASE);
  2735. + val &= ~CCA_DEFAULT_OVR_MASK;
  2736. + val |= CCA_DEFAULT_OVREN | (2 << CCA_DEFAULT_OVR_SHIFT);
  2737. + writel(val, cm_base + GCR_BASE);
  2738. +
  2739. + /* Initialize L1 I-Cache */
  2740. + write_c0_taglo(0);
  2741. + write_c0_taghi(0);
  2742. +
  2743. + for (addr = 0; addr < CONFIG_SYS_ICACHE_SIZE; addr += lsize)
  2744. + mips_cache(INDEX_STORE_TAG_I, (void *)addr);
  2745. +
  2746. + /* Initialize L1 D-Cache */
  2747. + write_c0_dtaglo(0);
  2748. + __write_32bit_c0_register($29, 2, 0); /* dtaghi */
  2749. +
  2750. + for (addr = 0; addr < CONFIG_SYS_DCACHE_SIZE; addr += lsize)
  2751. + mips_cache(INDEX_STORE_TAG_D, (void *)addr);
  2752. +
  2753. + /* Initialize L2 Cache */
  2754. + write_c0_staglo(0);
  2755. + __write_32bit_c0_register($29, 4, 0); /* staghi */
  2756. +
  2757. + for (addr = 0; addr < (256 << 10); addr += lsize)
  2758. + mips_cache(INDEX_STORE_TAG_SD, (void *)addr);
  2759. +
  2760. + /* Dsiable CCA override */
  2761. + val = readl(cm_base + GCR_BASE);
  2762. + val &= ~(CCA_DEFAULT_OVR_MASK | CCA_DEFAULT_OVREN);
  2763. + writel(val, cm_base + GCR_BASE);
  2764. +
  2765. + /* Set KSEG0 to non-coherent cached (important!) */
  2766. + val = read_c0_config();
  2767. + val &= ~CONF_CM_CMASK;
  2768. + val |= CONF_CM_CACHABLE_NONCOHERENT;
  2769. + write_c0_config(val);
  2770. + execution_hazard_barrier();
  2771. +
  2772. + /* Again, invalidate L1 D-Cache */
  2773. + for (addr = 0; addr < CONFIG_SYS_DCACHE_SIZE; addr += lsize)
  2774. + mips_cache(INDEX_WRITEBACK_INV_D, (void *)addr);
  2775. +
  2776. + /* Invalidate L1 I-Cache */
  2777. + for (addr = 0; addr < CONFIG_SYS_ICACHE_SIZE; addr += lsize)
  2778. + mips_cache(INDEX_INVALIDATE_I, (void *)addr);
  2779. +
  2780. + /* Disable L2 cache bypass */
  2781. + val = read_c0_config2();
  2782. + val &= ~MIPS_CONF_IMPL;
  2783. + write_c0_config2(val);
  2784. + execution_hazard_barrier();
  2785. +}
  2786. +
  2787. +void __noreturn tpl_main(void)
  2788. +{
  2789. + const image_header_t *hdr = (const image_header_t *)__image_copy_end;
  2790. + image_entry_noargs_t image_entry;
  2791. + u32 loadaddr, size;
  2792. + uintptr_t data;
  2793. +
  2794. + /* Initialize the cache first */
  2795. + mt7621_cache_init();
  2796. +
  2797. + if (image_get_magic(hdr) != IH_MAGIC)
  2798. + goto failed;
  2799. +
  2800. + loadaddr = image_get_load(hdr);
  2801. + size = image_get_size(hdr);
  2802. + image_entry = (image_entry_noargs_t)image_get_ep(hdr);
  2803. +
  2804. + /* Load TPL image to L2 cache */
  2805. + data = (uintptr_t)__image_copy_end + sizeof(struct image_header);
  2806. + fill_lock_l2cache(data, loadaddr, size);
  2807. +
  2808. + /* Jump to SPL */
  2809. + image_entry();
  2810. +
  2811. +failed:
  2812. + for (;;)
  2813. + ;
  2814. +}
  2815. --- /dev/null
  2816. +++ b/include/configs/mt7621.h
  2817. @@ -0,0 +1,65 @@
  2818. +/* SPDX-License-Identifier: GPL-2.0 */
  2819. +/*
  2820. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  2821. + *
  2822. + * Author: Weijie Gao <[email protected]>
  2823. + */
  2824. +
  2825. +#ifndef __CONFIG_MT7621_H
  2826. +#define __CONFIG_MT7621_H
  2827. +
  2828. +#define CONFIG_SYS_MIPS_TIMER_FREQ 440000000
  2829. +
  2830. +#define CONFIG_SYS_BOOTPARAMS_LEN 0x20000
  2831. +
  2832. +#define CONFIG_SYS_SDRAM_BASE 0x80000000
  2833. +
  2834. +#define CONFIG_VERY_BIG_RAM
  2835. +#define CONFIG_MAX_MEM_MAPPED 0x1c000000
  2836. +
  2837. +#define CONFIG_SYS_INIT_SP_OFFSET 0x800000
  2838. +
  2839. +#define CONFIG_SYS_BOOTM_LEN 0x2000000
  2840. +
  2841. +#define CONFIG_SYS_MAXARGS 16
  2842. +#define CONFIG_SYS_CBSIZE 1024
  2843. +
  2844. +#define CONFIG_SYS_NONCACHED_MEMORY 0x100000
  2845. +
  2846. +/* MMC */
  2847. +#define MMC_SUPPORTS_TUNING
  2848. +
  2849. +/* NAND */
  2850. +#define CONFIG_SYS_MAX_NAND_DEVICE 1
  2851. +
  2852. +/* Serial SPL */
  2853. +#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_SERIAL)
  2854. +#define CONFIG_SYS_NS16550_MEM32
  2855. +#define CONFIG_SYS_NS16550_CLK 50000000
  2856. +#define CONFIG_SYS_NS16550_REG_SIZE -4
  2857. +#define CONFIG_SYS_NS16550_COM1 0xbe000c00
  2858. +#endif
  2859. +
  2860. +/* Serial common */
  2861. +#define CONFIG_SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200, \
  2862. + 230400, 460800, 921600 }
  2863. +
  2864. +/* SPL */
  2865. +#define CONFIG_SYS_UBOOT_START CONFIG_SYS_TEXT_BASE
  2866. +
  2867. +#ifdef CONFIG_TPL_BUILD
  2868. +#define CONFIG_SPL_START_S_PATH "arch/mips/mach-mtmips/mt7621/tpl"
  2869. +/* .bss will not be used by TPL */
  2870. +#define CONFIG_SPL_BSS_START_ADDR 0x80000000
  2871. +#define CONFIG_SPL_BSS_MAX_SIZE 0
  2872. +#else
  2873. +#define CONFIG_SPL_START_S_PATH "arch/mips/mach-mtmips/mt7621/spl"
  2874. +#define CONFIG_SPL_BSS_START_ADDR 0x80140000
  2875. +#define CONFIG_SPL_BSS_MAX_SIZE 0x80000
  2876. +#define CONFIG_SPL_MAX_SIZE 0x30000
  2877. +#endif
  2878. +
  2879. +/* Dummy value */
  2880. +#define CONFIG_SYS_UBOOT_BASE 0
  2881. +
  2882. +#endif /* __CONFIG_MT7621_H */