feature.c 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047
  1. /*
  2. * Copyright (C) 1996-2001 Paul Mackerras (paulus@cs.anu.edu.au)
  3. * Ben. Herrenschmidt (benh@kernel.crashing.org)
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. *
  10. * TODO:
  11. *
  12. * - Replace mdelay with some schedule loop if possible
  13. * - Shorten some obfuscated delays on some routines (like modem
  14. * power)
  15. * - Refcount some clocks (see darwin)
  16. * - Split split split...
  17. *
  18. */
  19. #include <linux/types.h>
  20. #include <linux/init.h>
  21. #include <linux/delay.h>
  22. #include <linux/kernel.h>
  23. #include <linux/sched.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/adb.h>
  26. #include <linux/pmu.h>
  27. #include <linux/ioport.h>
  28. #include <linux/pci.h>
  29. #include <asm/sections.h>
  30. #include <asm/errno.h>
  31. #include <asm/ohare.h>
  32. #include <asm/heathrow.h>
  33. #include <asm/keylargo.h>
  34. #include <asm/uninorth.h>
  35. #include <asm/io.h>
  36. #include <asm/prom.h>
  37. #include <asm/machdep.h>
  38. #include <asm/pmac_feature.h>
  39. #include <asm/dbdma.h>
  40. #include <asm/pci-bridge.h>
  41. #include <asm/pmac_low_i2c.h>
  42. #undef DEBUG_FEATURE
  43. #ifdef DEBUG_FEATURE
  44. #define DBG(fmt...) printk(KERN_DEBUG fmt)
  45. #else
  46. #define DBG(fmt...)
  47. #endif
  48. #ifdef CONFIG_6xx
  49. extern int powersave_lowspeed;
  50. #endif
  51. extern int powersave_nap;
  52. extern struct device_node *k2_skiplist[2];
  53. /*
  54. * We use a single global lock to protect accesses. Each driver has
  55. * to take care of its own locking
  56. */
  57. DEFINE_SPINLOCK(feature_lock);
  58. #define LOCK(flags) spin_lock_irqsave(&feature_lock, flags);
  59. #define UNLOCK(flags) spin_unlock_irqrestore(&feature_lock, flags);
  60. /*
  61. * Instance of some macio stuffs
  62. */
  63. struct macio_chip macio_chips[MAX_MACIO_CHIPS];
  64. struct macio_chip *macio_find(struct device_node *child, int type)
  65. {
  66. while(child) {
  67. int i;
  68. for (i=0; i < MAX_MACIO_CHIPS && macio_chips[i].of_node; i++)
  69. if (child == macio_chips[i].of_node &&
  70. (!type || macio_chips[i].type == type))
  71. return &macio_chips[i];
  72. child = child->parent;
  73. }
  74. return NULL;
  75. }
  76. EXPORT_SYMBOL_GPL(macio_find);
  77. static const char *macio_names[] =
  78. {
  79. "Unknown",
  80. "Grand Central",
  81. "OHare",
  82. "OHareII",
  83. "Heathrow",
  84. "Gatwick",
  85. "Paddington",
  86. "Keylargo",
  87. "Pangea",
  88. "Intrepid",
  89. "K2",
  90. "Shasta",
  91. };
  92. struct device_node *uninorth_node;
  93. u32 __iomem *uninorth_base;
  94. static u32 uninorth_rev;
  95. static int uninorth_maj;
  96. static void __iomem *u3_ht_base;
  97. /*
  98. * For each motherboard family, we have a table of functions pointers
  99. * that handle the various features.
  100. */
  101. typedef long (*feature_call)(struct device_node *node, long param, long value);
  102. struct feature_table_entry {
  103. unsigned int selector;
  104. feature_call function;
  105. };
  106. struct pmac_mb_def
  107. {
  108. const char* model_string;
  109. const char* model_name;
  110. int model_id;
  111. struct feature_table_entry* features;
  112. unsigned long board_flags;
  113. };
  114. static struct pmac_mb_def pmac_mb;
  115. /*
  116. * Here are the chip specific feature functions
  117. */
  118. static inline int simple_feature_tweak(struct device_node *node, int type,
  119. int reg, u32 mask, int value)
  120. {
  121. struct macio_chip* macio;
  122. unsigned long flags;
  123. macio = macio_find(node, type);
  124. if (!macio)
  125. return -ENODEV;
  126. LOCK(flags);
  127. if (value)
  128. MACIO_BIS(reg, mask);
  129. else
  130. MACIO_BIC(reg, mask);
  131. (void)MACIO_IN32(reg);
  132. UNLOCK(flags);
  133. return 0;
  134. }
  135. #ifndef CONFIG_POWER4
  136. static long ohare_htw_scc_enable(struct device_node *node, long param,
  137. long value)
  138. {
  139. struct macio_chip* macio;
  140. unsigned long chan_mask;
  141. unsigned long fcr;
  142. unsigned long flags;
  143. int htw, trans;
  144. unsigned long rmask;
  145. macio = macio_find(node, 0);
  146. if (!macio)
  147. return -ENODEV;
  148. if (!strcmp(node->name, "ch-a"))
  149. chan_mask = MACIO_FLAG_SCCA_ON;
  150. else if (!strcmp(node->name, "ch-b"))
  151. chan_mask = MACIO_FLAG_SCCB_ON;
  152. else
  153. return -ENODEV;
  154. htw = (macio->type == macio_heathrow || macio->type == macio_paddington
  155. || macio->type == macio_gatwick);
  156. /* On these machines, the HRW_SCC_TRANS_EN_N bit mustn't be touched */
  157. trans = (pmac_mb.model_id != PMAC_TYPE_YOSEMITE &&
  158. pmac_mb.model_id != PMAC_TYPE_YIKES);
  159. if (value) {
  160. #ifdef CONFIG_ADB_PMU
  161. if ((param & 0xfff) == PMAC_SCC_IRDA)
  162. pmu_enable_irled(1);
  163. #endif /* CONFIG_ADB_PMU */
  164. LOCK(flags);
  165. fcr = MACIO_IN32(OHARE_FCR);
  166. /* Check if scc cell need enabling */
  167. if (!(fcr & OH_SCC_ENABLE)) {
  168. fcr |= OH_SCC_ENABLE;
  169. if (htw) {
  170. /* Side effect: this will also power up the
  171. * modem, but it's too messy to figure out on which
  172. * ports this controls the tranceiver and on which
  173. * it controls the modem
  174. */
  175. if (trans)
  176. fcr &= ~HRW_SCC_TRANS_EN_N;
  177. MACIO_OUT32(OHARE_FCR, fcr);
  178. fcr |= (rmask = HRW_RESET_SCC);
  179. MACIO_OUT32(OHARE_FCR, fcr);
  180. } else {
  181. fcr |= (rmask = OH_SCC_RESET);
  182. MACIO_OUT32(OHARE_FCR, fcr);
  183. }
  184. UNLOCK(flags);
  185. (void)MACIO_IN32(OHARE_FCR);
  186. mdelay(15);
  187. LOCK(flags);
  188. fcr &= ~rmask;
  189. MACIO_OUT32(OHARE_FCR, fcr);
  190. }
  191. if (chan_mask & MACIO_FLAG_SCCA_ON)
  192. fcr |= OH_SCCA_IO;
  193. if (chan_mask & MACIO_FLAG_SCCB_ON)
  194. fcr |= OH_SCCB_IO;
  195. MACIO_OUT32(OHARE_FCR, fcr);
  196. macio->flags |= chan_mask;
  197. UNLOCK(flags);
  198. if (param & PMAC_SCC_FLAG_XMON)
  199. macio->flags |= MACIO_FLAG_SCC_LOCKED;
  200. } else {
  201. if (macio->flags & MACIO_FLAG_SCC_LOCKED)
  202. return -EPERM;
  203. LOCK(flags);
  204. fcr = MACIO_IN32(OHARE_FCR);
  205. if (chan_mask & MACIO_FLAG_SCCA_ON)
  206. fcr &= ~OH_SCCA_IO;
  207. if (chan_mask & MACIO_FLAG_SCCB_ON)
  208. fcr &= ~OH_SCCB_IO;
  209. MACIO_OUT32(OHARE_FCR, fcr);
  210. if ((fcr & (OH_SCCA_IO | OH_SCCB_IO)) == 0) {
  211. fcr &= ~OH_SCC_ENABLE;
  212. if (htw && trans)
  213. fcr |= HRW_SCC_TRANS_EN_N;
  214. MACIO_OUT32(OHARE_FCR, fcr);
  215. }
  216. macio->flags &= ~(chan_mask);
  217. UNLOCK(flags);
  218. mdelay(10);
  219. #ifdef CONFIG_ADB_PMU
  220. if ((param & 0xfff) == PMAC_SCC_IRDA)
  221. pmu_enable_irled(0);
  222. #endif /* CONFIG_ADB_PMU */
  223. }
  224. return 0;
  225. }
  226. static long ohare_floppy_enable(struct device_node *node, long param,
  227. long value)
  228. {
  229. return simple_feature_tweak(node, macio_ohare,
  230. OHARE_FCR, OH_FLOPPY_ENABLE, value);
  231. }
  232. static long ohare_mesh_enable(struct device_node *node, long param, long value)
  233. {
  234. return simple_feature_tweak(node, macio_ohare,
  235. OHARE_FCR, OH_MESH_ENABLE, value);
  236. }
  237. static long ohare_ide_enable(struct device_node *node, long param, long value)
  238. {
  239. switch(param) {
  240. case 0:
  241. /* For some reason, setting the bit in set_initial_features()
  242. * doesn't stick. I'm still investigating... --BenH.
  243. */
  244. if (value)
  245. simple_feature_tweak(node, macio_ohare,
  246. OHARE_FCR, OH_IOBUS_ENABLE, 1);
  247. return simple_feature_tweak(node, macio_ohare,
  248. OHARE_FCR, OH_IDE0_ENABLE, value);
  249. case 1:
  250. return simple_feature_tweak(node, macio_ohare,
  251. OHARE_FCR, OH_BAY_IDE_ENABLE, value);
  252. default:
  253. return -ENODEV;
  254. }
  255. }
  256. static long ohare_ide_reset(struct device_node *node, long param, long value)
  257. {
  258. switch(param) {
  259. case 0:
  260. return simple_feature_tweak(node, macio_ohare,
  261. OHARE_FCR, OH_IDE0_RESET_N, !value);
  262. case 1:
  263. return simple_feature_tweak(node, macio_ohare,
  264. OHARE_FCR, OH_IDE1_RESET_N, !value);
  265. default:
  266. return -ENODEV;
  267. }
  268. }
  269. static long ohare_sleep_state(struct device_node *node, long param, long value)
  270. {
  271. struct macio_chip* macio = &macio_chips[0];
  272. if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
  273. return -EPERM;
  274. if (value == 1) {
  275. MACIO_BIC(OHARE_FCR, OH_IOBUS_ENABLE);
  276. } else if (value == 0) {
  277. MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
  278. }
  279. return 0;
  280. }
  281. static long heathrow_modem_enable(struct device_node *node, long param,
  282. long value)
  283. {
  284. struct macio_chip* macio;
  285. u8 gpio;
  286. unsigned long flags;
  287. macio = macio_find(node, macio_unknown);
  288. if (!macio)
  289. return -ENODEV;
  290. gpio = MACIO_IN8(HRW_GPIO_MODEM_RESET) & ~1;
  291. if (!value) {
  292. LOCK(flags);
  293. MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio);
  294. UNLOCK(flags);
  295. (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
  296. mdelay(250);
  297. }
  298. if (pmac_mb.model_id != PMAC_TYPE_YOSEMITE &&
  299. pmac_mb.model_id != PMAC_TYPE_YIKES) {
  300. LOCK(flags);
  301. if (value)
  302. MACIO_BIC(HEATHROW_FCR, HRW_SCC_TRANS_EN_N);
  303. else
  304. MACIO_BIS(HEATHROW_FCR, HRW_SCC_TRANS_EN_N);
  305. UNLOCK(flags);
  306. (void)MACIO_IN32(HEATHROW_FCR);
  307. mdelay(250);
  308. }
  309. if (value) {
  310. LOCK(flags);
  311. MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio | 1);
  312. (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
  313. UNLOCK(flags); mdelay(250); LOCK(flags);
  314. MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio);
  315. (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
  316. UNLOCK(flags); mdelay(250); LOCK(flags);
  317. MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio | 1);
  318. (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
  319. UNLOCK(flags); mdelay(250);
  320. }
  321. return 0;
  322. }
  323. static long heathrow_floppy_enable(struct device_node *node, long param,
  324. long value)
  325. {
  326. return simple_feature_tweak(node, macio_unknown,
  327. HEATHROW_FCR,
  328. HRW_SWIM_ENABLE|HRW_BAY_FLOPPY_ENABLE,
  329. value);
  330. }
  331. static long heathrow_mesh_enable(struct device_node *node, long param,
  332. long value)
  333. {
  334. struct macio_chip* macio;
  335. unsigned long flags;
  336. macio = macio_find(node, macio_unknown);
  337. if (!macio)
  338. return -ENODEV;
  339. LOCK(flags);
  340. /* Set clear mesh cell enable */
  341. if (value)
  342. MACIO_BIS(HEATHROW_FCR, HRW_MESH_ENABLE);
  343. else
  344. MACIO_BIC(HEATHROW_FCR, HRW_MESH_ENABLE);
  345. (void)MACIO_IN32(HEATHROW_FCR);
  346. udelay(10);
  347. /* Set/Clear termination power */
  348. if (value)
  349. MACIO_BIC(HEATHROW_MBCR, 0x04000000);
  350. else
  351. MACIO_BIS(HEATHROW_MBCR, 0x04000000);
  352. (void)MACIO_IN32(HEATHROW_MBCR);
  353. udelay(10);
  354. UNLOCK(flags);
  355. return 0;
  356. }
  357. static long heathrow_ide_enable(struct device_node *node, long param,
  358. long value)
  359. {
  360. switch(param) {
  361. case 0:
  362. return simple_feature_tweak(node, macio_unknown,
  363. HEATHROW_FCR, HRW_IDE0_ENABLE, value);
  364. case 1:
  365. return simple_feature_tweak(node, macio_unknown,
  366. HEATHROW_FCR, HRW_BAY_IDE_ENABLE, value);
  367. default:
  368. return -ENODEV;
  369. }
  370. }
  371. static long heathrow_ide_reset(struct device_node *node, long param,
  372. long value)
  373. {
  374. switch(param) {
  375. case 0:
  376. return simple_feature_tweak(node, macio_unknown,
  377. HEATHROW_FCR, HRW_IDE0_RESET_N, !value);
  378. case 1:
  379. return simple_feature_tweak(node, macio_unknown,
  380. HEATHROW_FCR, HRW_IDE1_RESET_N, !value);
  381. default:
  382. return -ENODEV;
  383. }
  384. }
  385. static long heathrow_bmac_enable(struct device_node *node, long param,
  386. long value)
  387. {
  388. struct macio_chip* macio;
  389. unsigned long flags;
  390. macio = macio_find(node, 0);
  391. if (!macio)
  392. return -ENODEV;
  393. if (value) {
  394. LOCK(flags);
  395. MACIO_BIS(HEATHROW_FCR, HRW_BMAC_IO_ENABLE);
  396. MACIO_BIS(HEATHROW_FCR, HRW_BMAC_RESET);
  397. UNLOCK(flags);
  398. (void)MACIO_IN32(HEATHROW_FCR);
  399. mdelay(10);
  400. LOCK(flags);
  401. MACIO_BIC(HEATHROW_FCR, HRW_BMAC_RESET);
  402. UNLOCK(flags);
  403. (void)MACIO_IN32(HEATHROW_FCR);
  404. mdelay(10);
  405. } else {
  406. LOCK(flags);
  407. MACIO_BIC(HEATHROW_FCR, HRW_BMAC_IO_ENABLE);
  408. UNLOCK(flags);
  409. }
  410. return 0;
  411. }
  412. static long heathrow_sound_enable(struct device_node *node, long param,
  413. long value)
  414. {
  415. struct macio_chip* macio;
  416. unsigned long flags;
  417. /* B&W G3 and Yikes don't support that properly (the
  418. * sound appear to never come back after beeing shut down).
  419. */
  420. if (pmac_mb.model_id == PMAC_TYPE_YOSEMITE ||
  421. pmac_mb.model_id == PMAC_TYPE_YIKES)
  422. return 0;
  423. macio = macio_find(node, 0);
  424. if (!macio)
  425. return -ENODEV;
  426. if (value) {
  427. LOCK(flags);
  428. MACIO_BIS(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
  429. MACIO_BIC(HEATHROW_FCR, HRW_SOUND_POWER_N);
  430. UNLOCK(flags);
  431. (void)MACIO_IN32(HEATHROW_FCR);
  432. } else {
  433. LOCK(flags);
  434. MACIO_BIS(HEATHROW_FCR, HRW_SOUND_POWER_N);
  435. MACIO_BIC(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
  436. UNLOCK(flags);
  437. }
  438. return 0;
  439. }
  440. static u32 save_fcr[6];
  441. static u32 save_mbcr;
  442. static struct dbdma_regs save_dbdma[13];
  443. static struct dbdma_regs save_alt_dbdma[13];
  444. static void dbdma_save(struct macio_chip *macio, struct dbdma_regs *save)
  445. {
  446. int i;
  447. /* Save state & config of DBDMA channels */
  448. for (i = 0; i < 13; i++) {
  449. volatile struct dbdma_regs __iomem * chan = (void __iomem *)
  450. (macio->base + ((0x8000+i*0x100)>>2));
  451. save[i].cmdptr_hi = in_le32(&chan->cmdptr_hi);
  452. save[i].cmdptr = in_le32(&chan->cmdptr);
  453. save[i].intr_sel = in_le32(&chan->intr_sel);
  454. save[i].br_sel = in_le32(&chan->br_sel);
  455. save[i].wait_sel = in_le32(&chan->wait_sel);
  456. }
  457. }
  458. static void dbdma_restore(struct macio_chip *macio, struct dbdma_regs *save)
  459. {
  460. int i;
  461. /* Save state & config of DBDMA channels */
  462. for (i = 0; i < 13; i++) {
  463. volatile struct dbdma_regs __iomem * chan = (void __iomem *)
  464. (macio->base + ((0x8000+i*0x100)>>2));
  465. out_le32(&chan->control, (ACTIVE|DEAD|WAKE|FLUSH|PAUSE|RUN)<<16);
  466. while (in_le32(&chan->status) & ACTIVE)
  467. mb();
  468. out_le32(&chan->cmdptr_hi, save[i].cmdptr_hi);
  469. out_le32(&chan->cmdptr, save[i].cmdptr);
  470. out_le32(&chan->intr_sel, save[i].intr_sel);
  471. out_le32(&chan->br_sel, save[i].br_sel);
  472. out_le32(&chan->wait_sel, save[i].wait_sel);
  473. }
  474. }
  475. static void heathrow_sleep(struct macio_chip *macio, int secondary)
  476. {
  477. if (secondary) {
  478. dbdma_save(macio, save_alt_dbdma);
  479. save_fcr[2] = MACIO_IN32(0x38);
  480. save_fcr[3] = MACIO_IN32(0x3c);
  481. } else {
  482. dbdma_save(macio, save_dbdma);
  483. save_fcr[0] = MACIO_IN32(0x38);
  484. save_fcr[1] = MACIO_IN32(0x3c);
  485. save_mbcr = MACIO_IN32(0x34);
  486. /* Make sure sound is shut down */
  487. MACIO_BIS(HEATHROW_FCR, HRW_SOUND_POWER_N);
  488. MACIO_BIC(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
  489. /* This seems to be necessary as well or the fan
  490. * keeps coming up and battery drains fast */
  491. MACIO_BIC(HEATHROW_FCR, HRW_IOBUS_ENABLE);
  492. MACIO_BIC(HEATHROW_FCR, HRW_IDE0_RESET_N);
  493. /* Make sure eth is down even if module or sleep
  494. * won't work properly */
  495. MACIO_BIC(HEATHROW_FCR, HRW_BMAC_IO_ENABLE | HRW_BMAC_RESET);
  496. }
  497. /* Make sure modem is shut down */
  498. MACIO_OUT8(HRW_GPIO_MODEM_RESET,
  499. MACIO_IN8(HRW_GPIO_MODEM_RESET) & ~1);
  500. MACIO_BIS(HEATHROW_FCR, HRW_SCC_TRANS_EN_N);
  501. MACIO_BIC(HEATHROW_FCR, OH_SCCA_IO|OH_SCCB_IO|HRW_SCC_ENABLE);
  502. /* Let things settle */
  503. (void)MACIO_IN32(HEATHROW_FCR);
  504. }
  505. static void heathrow_wakeup(struct macio_chip *macio, int secondary)
  506. {
  507. if (secondary) {
  508. MACIO_OUT32(0x38, save_fcr[2]);
  509. (void)MACIO_IN32(0x38);
  510. mdelay(1);
  511. MACIO_OUT32(0x3c, save_fcr[3]);
  512. (void)MACIO_IN32(0x38);
  513. mdelay(10);
  514. dbdma_restore(macio, save_alt_dbdma);
  515. } else {
  516. MACIO_OUT32(0x38, save_fcr[0] | HRW_IOBUS_ENABLE);
  517. (void)MACIO_IN32(0x38);
  518. mdelay(1);
  519. MACIO_OUT32(0x3c, save_fcr[1]);
  520. (void)MACIO_IN32(0x38);
  521. mdelay(1);
  522. MACIO_OUT32(0x34, save_mbcr);
  523. (void)MACIO_IN32(0x38);
  524. mdelay(10);
  525. dbdma_restore(macio, save_dbdma);
  526. }
  527. }
  528. static long heathrow_sleep_state(struct device_node *node, long param,
  529. long value)
  530. {
  531. if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
  532. return -EPERM;
  533. if (value == 1) {
  534. if (macio_chips[1].type == macio_gatwick)
  535. heathrow_sleep(&macio_chips[0], 1);
  536. heathrow_sleep(&macio_chips[0], 0);
  537. } else if (value == 0) {
  538. heathrow_wakeup(&macio_chips[0], 0);
  539. if (macio_chips[1].type == macio_gatwick)
  540. heathrow_wakeup(&macio_chips[0], 1);
  541. }
  542. return 0;
  543. }
  544. static long core99_scc_enable(struct device_node *node, long param, long value)
  545. {
  546. struct macio_chip* macio;
  547. unsigned long flags;
  548. unsigned long chan_mask;
  549. u32 fcr;
  550. macio = macio_find(node, 0);
  551. if (!macio)
  552. return -ENODEV;
  553. if (!strcmp(node->name, "ch-a"))
  554. chan_mask = MACIO_FLAG_SCCA_ON;
  555. else if (!strcmp(node->name, "ch-b"))
  556. chan_mask = MACIO_FLAG_SCCB_ON;
  557. else
  558. return -ENODEV;
  559. if (value) {
  560. int need_reset_scc = 0;
  561. int need_reset_irda = 0;
  562. LOCK(flags);
  563. fcr = MACIO_IN32(KEYLARGO_FCR0);
  564. /* Check if scc cell need enabling */
  565. if (!(fcr & KL0_SCC_CELL_ENABLE)) {
  566. fcr |= KL0_SCC_CELL_ENABLE;
  567. need_reset_scc = 1;
  568. }
  569. if (chan_mask & MACIO_FLAG_SCCA_ON) {
  570. fcr |= KL0_SCCA_ENABLE;
  571. /* Don't enable line drivers for I2S modem */
  572. if ((param & 0xfff) == PMAC_SCC_I2S1)
  573. fcr &= ~KL0_SCC_A_INTF_ENABLE;
  574. else
  575. fcr |= KL0_SCC_A_INTF_ENABLE;
  576. }
  577. if (chan_mask & MACIO_FLAG_SCCB_ON) {
  578. fcr |= KL0_SCCB_ENABLE;
  579. /* Perform irda specific inits */
  580. if ((param & 0xfff) == PMAC_SCC_IRDA) {
  581. fcr &= ~KL0_SCC_B_INTF_ENABLE;
  582. fcr |= KL0_IRDA_ENABLE;
  583. fcr |= KL0_IRDA_CLK32_ENABLE | KL0_IRDA_CLK19_ENABLE;
  584. fcr |= KL0_IRDA_SOURCE1_SEL;
  585. fcr &= ~(KL0_IRDA_FAST_CONNECT|KL0_IRDA_DEFAULT1|KL0_IRDA_DEFAULT0);
  586. fcr &= ~(KL0_IRDA_SOURCE2_SEL|KL0_IRDA_HIGH_BAND);
  587. need_reset_irda = 1;
  588. } else
  589. fcr |= KL0_SCC_B_INTF_ENABLE;
  590. }
  591. MACIO_OUT32(KEYLARGO_FCR0, fcr);
  592. macio->flags |= chan_mask;
  593. if (need_reset_scc) {
  594. MACIO_BIS(KEYLARGO_FCR0, KL0_SCC_RESET);
  595. (void)MACIO_IN32(KEYLARGO_FCR0);
  596. UNLOCK(flags);
  597. mdelay(15);
  598. LOCK(flags);
  599. MACIO_BIC(KEYLARGO_FCR0, KL0_SCC_RESET);
  600. }
  601. if (need_reset_irda) {
  602. MACIO_BIS(KEYLARGO_FCR0, KL0_IRDA_RESET);
  603. (void)MACIO_IN32(KEYLARGO_FCR0);
  604. UNLOCK(flags);
  605. mdelay(15);
  606. LOCK(flags);
  607. MACIO_BIC(KEYLARGO_FCR0, KL0_IRDA_RESET);
  608. }
  609. UNLOCK(flags);
  610. if (param & PMAC_SCC_FLAG_XMON)
  611. macio->flags |= MACIO_FLAG_SCC_LOCKED;
  612. } else {
  613. if (macio->flags & MACIO_FLAG_SCC_LOCKED)
  614. return -EPERM;
  615. LOCK(flags);
  616. fcr = MACIO_IN32(KEYLARGO_FCR0);
  617. if (chan_mask & MACIO_FLAG_SCCA_ON)
  618. fcr &= ~KL0_SCCA_ENABLE;
  619. if (chan_mask & MACIO_FLAG_SCCB_ON) {
  620. fcr &= ~KL0_SCCB_ENABLE;
  621. /* Perform irda specific clears */
  622. if ((param & 0xfff) == PMAC_SCC_IRDA) {
  623. fcr &= ~KL0_IRDA_ENABLE;
  624. fcr &= ~(KL0_IRDA_CLK32_ENABLE | KL0_IRDA_CLK19_ENABLE);
  625. fcr &= ~(KL0_IRDA_FAST_CONNECT|KL0_IRDA_DEFAULT1|KL0_IRDA_DEFAULT0);
  626. fcr &= ~(KL0_IRDA_SOURCE1_SEL|KL0_IRDA_SOURCE2_SEL|KL0_IRDA_HIGH_BAND);
  627. }
  628. }
  629. MACIO_OUT32(KEYLARGO_FCR0, fcr);
  630. if ((fcr & (KL0_SCCA_ENABLE | KL0_SCCB_ENABLE)) == 0) {
  631. fcr &= ~KL0_SCC_CELL_ENABLE;
  632. MACIO_OUT32(KEYLARGO_FCR0, fcr);
  633. }
  634. macio->flags &= ~(chan_mask);
  635. UNLOCK(flags);
  636. mdelay(10);
  637. }
  638. return 0;
  639. }
  640. static long
  641. core99_modem_enable(struct device_node *node, long param, long value)
  642. {
  643. struct macio_chip* macio;
  644. u8 gpio;
  645. unsigned long flags;
  646. /* Hack for internal USB modem */
  647. if (node == NULL) {
  648. if (macio_chips[0].type != macio_keylargo)
  649. return -ENODEV;
  650. node = macio_chips[0].of_node;
  651. }
  652. macio = macio_find(node, 0);
  653. if (!macio)
  654. return -ENODEV;
  655. gpio = MACIO_IN8(KL_GPIO_MODEM_RESET);
  656. gpio |= KEYLARGO_GPIO_OUTPUT_ENABLE;
  657. gpio &= ~KEYLARGO_GPIO_OUTOUT_DATA;
  658. if (!value) {
  659. LOCK(flags);
  660. MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
  661. UNLOCK(flags);
  662. (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
  663. mdelay(250);
  664. }
  665. LOCK(flags);
  666. if (value) {
  667. MACIO_BIC(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
  668. UNLOCK(flags);
  669. (void)MACIO_IN32(KEYLARGO_FCR2);
  670. mdelay(250);
  671. } else {
  672. MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
  673. UNLOCK(flags);
  674. }
  675. if (value) {
  676. LOCK(flags);
  677. MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
  678. (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
  679. UNLOCK(flags); mdelay(250); LOCK(flags);
  680. MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
  681. (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
  682. UNLOCK(flags); mdelay(250); LOCK(flags);
  683. MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
  684. (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
  685. UNLOCK(flags); mdelay(250);
  686. }
  687. return 0;
  688. }
  689. static long
  690. pangea_modem_enable(struct device_node *node, long param, long value)
  691. {
  692. struct macio_chip* macio;
  693. u8 gpio;
  694. unsigned long flags;
  695. /* Hack for internal USB modem */
  696. if (node == NULL) {
  697. if (macio_chips[0].type != macio_pangea &&
  698. macio_chips[0].type != macio_intrepid)
  699. return -ENODEV;
  700. node = macio_chips[0].of_node;
  701. }
  702. macio = macio_find(node, 0);
  703. if (!macio)
  704. return -ENODEV;
  705. gpio = MACIO_IN8(KL_GPIO_MODEM_RESET);
  706. gpio |= KEYLARGO_GPIO_OUTPUT_ENABLE;
  707. gpio &= ~KEYLARGO_GPIO_OUTOUT_DATA;
  708. if (!value) {
  709. LOCK(flags);
  710. MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
  711. UNLOCK(flags);
  712. (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
  713. mdelay(250);
  714. }
  715. LOCK(flags);
  716. if (value) {
  717. MACIO_OUT8(KL_GPIO_MODEM_POWER,
  718. KEYLARGO_GPIO_OUTPUT_ENABLE);
  719. UNLOCK(flags);
  720. (void)MACIO_IN32(KEYLARGO_FCR2);
  721. mdelay(250);
  722. } else {
  723. MACIO_OUT8(KL_GPIO_MODEM_POWER,
  724. KEYLARGO_GPIO_OUTPUT_ENABLE | KEYLARGO_GPIO_OUTOUT_DATA);
  725. UNLOCK(flags);
  726. }
  727. if (value) {
  728. LOCK(flags);
  729. MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
  730. (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
  731. UNLOCK(flags); mdelay(250); LOCK(flags);
  732. MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
  733. (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
  734. UNLOCK(flags); mdelay(250); LOCK(flags);
  735. MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
  736. (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
  737. UNLOCK(flags); mdelay(250);
  738. }
  739. return 0;
  740. }
  741. static long
  742. core99_ata100_enable(struct device_node *node, long value)
  743. {
  744. unsigned long flags;
  745. struct pci_dev *pdev = NULL;
  746. u8 pbus, pid;
  747. int rc;
  748. if (uninorth_rev < 0x24)
  749. return -ENODEV;
  750. LOCK(flags);
  751. if (value)
  752. UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_ATA100);
  753. else
  754. UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_ATA100);
  755. (void)UN_IN(UNI_N_CLOCK_CNTL);
  756. UNLOCK(flags);
  757. udelay(20);
  758. if (value) {
  759. if (pci_device_from_OF_node(node, &pbus, &pid) == 0)
  760. pdev = pci_get_bus_and_slot(pbus, pid);
  761. if (pdev == NULL)
  762. return 0;
  763. rc = pci_enable_device(pdev);
  764. if (rc == 0)
  765. pci_set_master(pdev);
  766. pci_dev_put(pdev);
  767. if (rc)
  768. return rc;
  769. }
  770. return 0;
  771. }
  772. static long
  773. core99_ide_enable(struct device_node *node, long param, long value)
  774. {
  775. /* Bus ID 0 to 2 are KeyLargo based IDE, busID 3 is U2
  776. * based ata-100
  777. */
  778. switch(param) {
  779. case 0:
  780. return simple_feature_tweak(node, macio_unknown,
  781. KEYLARGO_FCR1, KL1_EIDE0_ENABLE, value);
  782. case 1:
  783. return simple_feature_tweak(node, macio_unknown,
  784. KEYLARGO_FCR1, KL1_EIDE1_ENABLE, value);
  785. case 2:
  786. return simple_feature_tweak(node, macio_unknown,
  787. KEYLARGO_FCR1, KL1_UIDE_ENABLE, value);
  788. case 3:
  789. return core99_ata100_enable(node, value);
  790. default:
  791. return -ENODEV;
  792. }
  793. }
  794. static long
  795. core99_ide_reset(struct device_node *node, long param, long value)
  796. {
  797. switch(param) {
  798. case 0:
  799. return simple_feature_tweak(node, macio_unknown,
  800. KEYLARGO_FCR1, KL1_EIDE0_RESET_N, !value);
  801. case 1:
  802. return simple_feature_tweak(node, macio_unknown,
  803. KEYLARGO_FCR1, KL1_EIDE1_RESET_N, !value);
  804. case 2:
  805. return simple_feature_tweak(node, macio_unknown,
  806. KEYLARGO_FCR1, KL1_UIDE_RESET_N, !value);
  807. default:
  808. return -ENODEV;
  809. }
  810. }
  811. static long
  812. core99_gmac_enable(struct device_node *node, long param, long value)
  813. {
  814. unsigned long flags;
  815. LOCK(flags);
  816. if (value)
  817. UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_GMAC);
  818. else
  819. UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_GMAC);
  820. (void)UN_IN(UNI_N_CLOCK_CNTL);
  821. UNLOCK(flags);
  822. udelay(20);
  823. return 0;
  824. }
  825. static long
  826. core99_gmac_phy_reset(struct device_node *node, long param, long value)
  827. {
  828. unsigned long flags;
  829. struct macio_chip *macio;
  830. macio = &macio_chips[0];
  831. if (macio->type != macio_keylargo && macio->type != macio_pangea &&
  832. macio->type != macio_intrepid)
  833. return -ENODEV;
  834. LOCK(flags);
  835. MACIO_OUT8(KL_GPIO_ETH_PHY_RESET, KEYLARGO_GPIO_OUTPUT_ENABLE);
  836. (void)MACIO_IN8(KL_GPIO_ETH_PHY_RESET);
  837. UNLOCK(flags);
  838. mdelay(10);
  839. LOCK(flags);
  840. MACIO_OUT8(KL_GPIO_ETH_PHY_RESET, /*KEYLARGO_GPIO_OUTPUT_ENABLE | */
  841. KEYLARGO_GPIO_OUTOUT_DATA);
  842. UNLOCK(flags);
  843. mdelay(10);
  844. return 0;
  845. }
  846. static long
  847. core99_sound_chip_enable(struct device_node *node, long param, long value)
  848. {
  849. struct macio_chip* macio;
  850. unsigned long flags;
  851. macio = macio_find(node, 0);
  852. if (!macio)
  853. return -ENODEV;
  854. /* Do a better probe code, screamer G4 desktops &
  855. * iMacs can do that too, add a recalibrate in
  856. * the driver as well
  857. */
  858. if (pmac_mb.model_id == PMAC_TYPE_PISMO ||
  859. pmac_mb.model_id == PMAC_TYPE_TITANIUM) {
  860. LOCK(flags);
  861. if (value)
  862. MACIO_OUT8(KL_GPIO_SOUND_POWER,
  863. KEYLARGO_GPIO_OUTPUT_ENABLE |
  864. KEYLARGO_GPIO_OUTOUT_DATA);
  865. else
  866. MACIO_OUT8(KL_GPIO_SOUND_POWER,
  867. KEYLARGO_GPIO_OUTPUT_ENABLE);
  868. (void)MACIO_IN8(KL_GPIO_SOUND_POWER);
  869. UNLOCK(flags);
  870. }
  871. return 0;
  872. }
  873. static long
  874. core99_airport_enable(struct device_node *node, long param, long value)
  875. {
  876. struct macio_chip* macio;
  877. unsigned long flags;
  878. int state;
  879. macio = macio_find(node, 0);
  880. if (!macio)
  881. return -ENODEV;
  882. /* Hint: we allow passing of macio itself for the sake of the
  883. * sleep code
  884. */
  885. if (node != macio->of_node &&
  886. (!node->parent || node->parent != macio->of_node))
  887. return -ENODEV;
  888. state = (macio->flags & MACIO_FLAG_AIRPORT_ON) != 0;
  889. if (value == state)
  890. return 0;
  891. if (value) {
  892. /* This code is a reproduction of OF enable-cardslot
  893. * and init-wireless methods, slightly hacked until
  894. * I got it working.
  895. */
  896. LOCK(flags);
  897. MACIO_OUT8(KEYLARGO_GPIO_0+0xf, 5);
  898. (void)MACIO_IN8(KEYLARGO_GPIO_0+0xf);
  899. UNLOCK(flags);
  900. mdelay(10);
  901. LOCK(flags);
  902. MACIO_OUT8(KEYLARGO_GPIO_0+0xf, 4);
  903. (void)MACIO_IN8(KEYLARGO_GPIO_0+0xf);
  904. UNLOCK(flags);
  905. mdelay(10);
  906. LOCK(flags);
  907. MACIO_BIC(KEYLARGO_FCR2, KL2_CARDSEL_16);
  908. (void)MACIO_IN32(KEYLARGO_FCR2);
  909. udelay(10);
  910. MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xb, 0);
  911. (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xb);
  912. udelay(10);
  913. MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xa, 0x28);
  914. (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xa);
  915. udelay(10);
  916. MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xd, 0x28);
  917. (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xd);
  918. udelay(10);
  919. MACIO_OUT8(KEYLARGO_GPIO_0+0xd, 0x28);
  920. (void)MACIO_IN8(KEYLARGO_GPIO_0+0xd);
  921. udelay(10);
  922. MACIO_OUT8(KEYLARGO_GPIO_0+0xe, 0x28);
  923. (void)MACIO_IN8(KEYLARGO_GPIO_0+0xe);
  924. UNLOCK(flags);
  925. udelay(10);
  926. MACIO_OUT32(0x1c000, 0);
  927. mdelay(1);
  928. MACIO_OUT8(0x1a3e0, 0x41);
  929. (void)MACIO_IN8(0x1a3e0);
  930. udelay(10);
  931. LOCK(flags);
  932. MACIO_BIS(KEYLARGO_FCR2, KL2_CARDSEL_16);
  933. (void)MACIO_IN32(KEYLARGO_FCR2);
  934. UNLOCK(flags);
  935. mdelay(100);
  936. macio->flags |= MACIO_FLAG_AIRPORT_ON;
  937. } else {
  938. LOCK(flags);
  939. MACIO_BIC(KEYLARGO_FCR2, KL2_CARDSEL_16);
  940. (void)MACIO_IN32(KEYLARGO_FCR2);
  941. MACIO_OUT8(KL_GPIO_AIRPORT_0, 0);
  942. MACIO_OUT8(KL_GPIO_AIRPORT_1, 0);
  943. MACIO_OUT8(KL_GPIO_AIRPORT_2, 0);
  944. MACIO_OUT8(KL_GPIO_AIRPORT_3, 0);
  945. MACIO_OUT8(KL_GPIO_AIRPORT_4, 0);
  946. (void)MACIO_IN8(KL_GPIO_AIRPORT_4);
  947. UNLOCK(flags);
  948. macio->flags &= ~MACIO_FLAG_AIRPORT_ON;
  949. }
  950. return 0;
  951. }
  952. #ifdef CONFIG_SMP
  953. static long
  954. core99_reset_cpu(struct device_node *node, long param, long value)
  955. {
  956. unsigned int reset_io = 0;
  957. unsigned long flags;
  958. struct macio_chip *macio;
  959. struct device_node *np;
  960. struct device_node *cpus;
  961. const int dflt_reset_lines[] = { KL_GPIO_RESET_CPU0,
  962. KL_GPIO_RESET_CPU1,
  963. KL_GPIO_RESET_CPU2,
  964. KL_GPIO_RESET_CPU3 };
  965. macio = &macio_chips[0];
  966. if (macio->type != macio_keylargo)
  967. return -ENODEV;
  968. cpus = of_find_node_by_path("/cpus");
  969. if (cpus == NULL)
  970. return -ENODEV;
  971. for (np = cpus->child; np != NULL; np = np->sibling) {
  972. const u32 *num = of_get_property(np, "reg", NULL);
  973. const u32 *rst = of_get_property(np, "soft-reset", NULL);
  974. if (num == NULL || rst == NULL)
  975. continue;
  976. if (param == *num) {
  977. reset_io = *rst;
  978. break;
  979. }
  980. }
  981. of_node_put(cpus);
  982. if (np == NULL || reset_io == 0)
  983. reset_io = dflt_reset_lines[param];
  984. LOCK(flags);
  985. MACIO_OUT8(reset_io, KEYLARGO_GPIO_OUTPUT_ENABLE);
  986. (void)MACIO_IN8(reset_io);
  987. udelay(1);
  988. MACIO_OUT8(reset_io, 0);
  989. (void)MACIO_IN8(reset_io);
  990. UNLOCK(flags);
  991. return 0;
  992. }
  993. #endif /* CONFIG_SMP */
  994. static long
  995. core99_usb_enable(struct device_node *node, long param, long value)
  996. {
  997. struct macio_chip *macio;
  998. unsigned long flags;
  999. const char *prop;
  1000. int number;
  1001. u32 reg;
  1002. macio = &macio_chips[0];
  1003. if (macio->type != macio_keylargo && macio->type != macio_pangea &&
  1004. macio->type != macio_intrepid)
  1005. return -ENODEV;
  1006. prop = of_get_property(node, "AAPL,clock-id", NULL);
  1007. if (!prop)
  1008. return -ENODEV;
  1009. if (strncmp(prop, "usb0u048", 8) == 0)
  1010. number = 0;
  1011. else if (strncmp(prop, "usb1u148", 8) == 0)
  1012. number = 2;
  1013. else if (strncmp(prop, "usb2u248", 8) == 0)
  1014. number = 4;
  1015. else
  1016. return -ENODEV;
  1017. /* Sorry for the brute-force locking, but this is only used during
  1018. * sleep and the timing seem to be critical
  1019. */
  1020. LOCK(flags);
  1021. if (value) {
  1022. /* Turn ON */
  1023. if (number == 0) {
  1024. MACIO_BIC(KEYLARGO_FCR0, (KL0_USB0_PAD_SUSPEND0 | KL0_USB0_PAD_SUSPEND1));
  1025. (void)MACIO_IN32(KEYLARGO_FCR0);
  1026. UNLOCK(flags);
  1027. mdelay(1);
  1028. LOCK(flags);
  1029. MACIO_BIS(KEYLARGO_FCR0, KL0_USB0_CELL_ENABLE);
  1030. } else if (number == 2) {
  1031. MACIO_BIC(KEYLARGO_FCR0, (KL0_USB1_PAD_SUSPEND0 | KL0_USB1_PAD_SUSPEND1));
  1032. UNLOCK(flags);
  1033. (void)MACIO_IN32(KEYLARGO_FCR0);
  1034. mdelay(1);
  1035. LOCK(flags);
  1036. MACIO_BIS(KEYLARGO_FCR0, KL0_USB1_CELL_ENABLE);
  1037. } else if (number == 4) {
  1038. MACIO_BIC(KEYLARGO_FCR1, (KL1_USB2_PAD_SUSPEND0 | KL1_USB2_PAD_SUSPEND1));
  1039. UNLOCK(flags);
  1040. (void)MACIO_IN32(KEYLARGO_FCR1);
  1041. mdelay(1);
  1042. LOCK(flags);
  1043. MACIO_BIS(KEYLARGO_FCR1, KL1_USB2_CELL_ENABLE);
  1044. }
  1045. if (number < 4) {
  1046. reg = MACIO_IN32(KEYLARGO_FCR4);
  1047. reg &= ~(KL4_PORT_WAKEUP_ENABLE(number) | KL4_PORT_RESUME_WAKE_EN(number) |
  1048. KL4_PORT_CONNECT_WAKE_EN(number) | KL4_PORT_DISCONNECT_WAKE_EN(number));
  1049. reg &= ~(KL4_PORT_WAKEUP_ENABLE(number+1) | KL4_PORT_RESUME_WAKE_EN(number+1) |
  1050. KL4_PORT_CONNECT_WAKE_EN(number+1) | KL4_PORT_DISCONNECT_WAKE_EN(number+1));
  1051. MACIO_OUT32(KEYLARGO_FCR4, reg);
  1052. (void)MACIO_IN32(KEYLARGO_FCR4);
  1053. udelay(10);
  1054. } else {
  1055. reg = MACIO_IN32(KEYLARGO_FCR3);
  1056. reg &= ~(KL3_IT_PORT_WAKEUP_ENABLE(0) | KL3_IT_PORT_RESUME_WAKE_EN(0) |
  1057. KL3_IT_PORT_CONNECT_WAKE_EN(0) | KL3_IT_PORT_DISCONNECT_WAKE_EN(0));
  1058. reg &= ~(KL3_IT_PORT_WAKEUP_ENABLE(1) | KL3_IT_PORT_RESUME_WAKE_EN(1) |
  1059. KL3_IT_PORT_CONNECT_WAKE_EN(1) | KL3_IT_PORT_DISCONNECT_WAKE_EN(1));
  1060. MACIO_OUT32(KEYLARGO_FCR3, reg);
  1061. (void)MACIO_IN32(KEYLARGO_FCR3);
  1062. udelay(10);
  1063. }
  1064. if (macio->type == macio_intrepid) {
  1065. /* wait for clock stopped bits to clear */
  1066. u32 test0 = 0, test1 = 0;
  1067. u32 status0, status1;
  1068. int timeout = 1000;
  1069. UNLOCK(flags);
  1070. switch (number) {
  1071. case 0:
  1072. test0 = UNI_N_CLOCK_STOPPED_USB0;
  1073. test1 = UNI_N_CLOCK_STOPPED_USB0PCI;
  1074. break;
  1075. case 2:
  1076. test0 = UNI_N_CLOCK_STOPPED_USB1;
  1077. test1 = UNI_N_CLOCK_STOPPED_USB1PCI;
  1078. break;
  1079. case 4:
  1080. test0 = UNI_N_CLOCK_STOPPED_USB2;
  1081. test1 = UNI_N_CLOCK_STOPPED_USB2PCI;
  1082. break;
  1083. }
  1084. do {
  1085. if (--timeout <= 0) {
  1086. printk(KERN_ERR "core99_usb_enable: "
  1087. "Timeout waiting for clocks\n");
  1088. break;
  1089. }
  1090. mdelay(1);
  1091. status0 = UN_IN(UNI_N_CLOCK_STOP_STATUS0);
  1092. status1 = UN_IN(UNI_N_CLOCK_STOP_STATUS1);
  1093. } while ((status0 & test0) | (status1 & test1));
  1094. LOCK(flags);
  1095. }
  1096. } else {
  1097. /* Turn OFF */
  1098. if (number < 4) {
  1099. reg = MACIO_IN32(KEYLARGO_FCR4);
  1100. reg |= KL4_PORT_WAKEUP_ENABLE(number) | KL4_PORT_RESUME_WAKE_EN(number) |
  1101. KL4_PORT_CONNECT_WAKE_EN(number) | KL4_PORT_DISCONNECT_WAKE_EN(number);
  1102. reg |= KL4_PORT_WAKEUP_ENABLE(number+1) | KL4_PORT_RESUME_WAKE_EN(number+1) |
  1103. KL4_PORT_CONNECT_WAKE_EN(number+1) | KL4_PORT_DISCONNECT_WAKE_EN(number+1);
  1104. MACIO_OUT32(KEYLARGO_FCR4, reg);
  1105. (void)MACIO_IN32(KEYLARGO_FCR4);
  1106. udelay(1);
  1107. } else {
  1108. reg = MACIO_IN32(KEYLARGO_FCR3);
  1109. reg |= KL3_IT_PORT_WAKEUP_ENABLE(0) | KL3_IT_PORT_RESUME_WAKE_EN(0) |
  1110. KL3_IT_PORT_CONNECT_WAKE_EN(0) | KL3_IT_PORT_DISCONNECT_WAKE_EN(0);
  1111. reg |= KL3_IT_PORT_WAKEUP_ENABLE(1) | KL3_IT_PORT_RESUME_WAKE_EN(1) |
  1112. KL3_IT_PORT_CONNECT_WAKE_EN(1) | KL3_IT_PORT_DISCONNECT_WAKE_EN(1);
  1113. MACIO_OUT32(KEYLARGO_FCR3, reg);
  1114. (void)MACIO_IN32(KEYLARGO_FCR3);
  1115. udelay(1);
  1116. }
  1117. if (number == 0) {
  1118. if (macio->type != macio_intrepid)
  1119. MACIO_BIC(KEYLARGO_FCR0, KL0_USB0_CELL_ENABLE);
  1120. (void)MACIO_IN32(KEYLARGO_FCR0);
  1121. udelay(1);
  1122. MACIO_BIS(KEYLARGO_FCR0, (KL0_USB0_PAD_SUSPEND0 | KL0_USB0_PAD_SUSPEND1));
  1123. (void)MACIO_IN32(KEYLARGO_FCR0);
  1124. } else if (number == 2) {
  1125. if (macio->type != macio_intrepid)
  1126. MACIO_BIC(KEYLARGO_FCR0, KL0_USB1_CELL_ENABLE);
  1127. (void)MACIO_IN32(KEYLARGO_FCR0);
  1128. udelay(1);
  1129. MACIO_BIS(KEYLARGO_FCR0, (KL0_USB1_PAD_SUSPEND0 | KL0_USB1_PAD_SUSPEND1));
  1130. (void)MACIO_IN32(KEYLARGO_FCR0);
  1131. } else if (number == 4) {
  1132. udelay(1);
  1133. MACIO_BIS(KEYLARGO_FCR1, (KL1_USB2_PAD_SUSPEND0 | KL1_USB2_PAD_SUSPEND1));
  1134. (void)MACIO_IN32(KEYLARGO_FCR1);
  1135. }
  1136. udelay(1);
  1137. }
  1138. UNLOCK(flags);
  1139. return 0;
  1140. }
  1141. static long
  1142. core99_firewire_enable(struct device_node *node, long param, long value)
  1143. {
  1144. unsigned long flags;
  1145. struct macio_chip *macio;
  1146. macio = &macio_chips[0];
  1147. if (macio->type != macio_keylargo && macio->type != macio_pangea &&
  1148. macio->type != macio_intrepid)
  1149. return -ENODEV;
  1150. if (!(macio->flags & MACIO_FLAG_FW_SUPPORTED))
  1151. return -ENODEV;
  1152. LOCK(flags);
  1153. if (value) {
  1154. UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_FW);
  1155. (void)UN_IN(UNI_N_CLOCK_CNTL);
  1156. } else {
  1157. UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_FW);
  1158. (void)UN_IN(UNI_N_CLOCK_CNTL);
  1159. }
  1160. UNLOCK(flags);
  1161. mdelay(1);
  1162. return 0;
  1163. }
  1164. static long
  1165. core99_firewire_cable_power(struct device_node *node, long param, long value)
  1166. {
  1167. unsigned long flags;
  1168. struct macio_chip *macio;
  1169. /* Trick: we allow NULL node */
  1170. if ((pmac_mb.board_flags & PMAC_MB_HAS_FW_POWER) == 0)
  1171. return -ENODEV;
  1172. macio = &macio_chips[0];
  1173. if (macio->type != macio_keylargo && macio->type != macio_pangea &&
  1174. macio->type != macio_intrepid)
  1175. return -ENODEV;
  1176. if (!(macio->flags & MACIO_FLAG_FW_SUPPORTED))
  1177. return -ENODEV;
  1178. LOCK(flags);
  1179. if (value) {
  1180. MACIO_OUT8(KL_GPIO_FW_CABLE_POWER , 0);
  1181. MACIO_IN8(KL_GPIO_FW_CABLE_POWER);
  1182. udelay(10);
  1183. } else {
  1184. MACIO_OUT8(KL_GPIO_FW_CABLE_POWER , 4);
  1185. MACIO_IN8(KL_GPIO_FW_CABLE_POWER); udelay(10);
  1186. }
  1187. UNLOCK(flags);
  1188. mdelay(1);
  1189. return 0;
  1190. }
  1191. static long
  1192. intrepid_aack_delay_enable(struct device_node *node, long param, long value)
  1193. {
  1194. unsigned long flags;
  1195. if (uninorth_rev < 0xd2)
  1196. return -ENODEV;
  1197. LOCK(flags);
  1198. if (param)
  1199. UN_BIS(UNI_N_AACK_DELAY, UNI_N_AACK_DELAY_ENABLE);
  1200. else
  1201. UN_BIC(UNI_N_AACK_DELAY, UNI_N_AACK_DELAY_ENABLE);
  1202. UNLOCK(flags);
  1203. return 0;
  1204. }
  1205. #endif /* CONFIG_POWER4 */
  1206. static long
  1207. core99_read_gpio(struct device_node *node, long param, long value)
  1208. {
  1209. struct macio_chip *macio = &macio_chips[0];
  1210. return MACIO_IN8(param);
  1211. }
  1212. static long
  1213. core99_write_gpio(struct device_node *node, long param, long value)
  1214. {
  1215. struct macio_chip *macio = &macio_chips[0];
  1216. MACIO_OUT8(param, (u8)(value & 0xff));
  1217. return 0;
  1218. }
  1219. #ifdef CONFIG_POWER4
  1220. static long g5_gmac_enable(struct device_node *node, long param, long value)
  1221. {
  1222. struct macio_chip *macio = &macio_chips[0];
  1223. unsigned long flags;
  1224. if (node == NULL)
  1225. return -ENODEV;
  1226. LOCK(flags);
  1227. if (value) {
  1228. MACIO_BIS(KEYLARGO_FCR1, K2_FCR1_GMAC_CLK_ENABLE);
  1229. mb();
  1230. k2_skiplist[0] = NULL;
  1231. } else {
  1232. k2_skiplist[0] = node;
  1233. mb();
  1234. MACIO_BIC(KEYLARGO_FCR1, K2_FCR1_GMAC_CLK_ENABLE);
  1235. }
  1236. UNLOCK(flags);
  1237. mdelay(1);
  1238. return 0;
  1239. }
  1240. static long g5_fw_enable(struct device_node *node, long param, long value)
  1241. {
  1242. struct macio_chip *macio = &macio_chips[0];
  1243. unsigned long flags;
  1244. if (node == NULL)
  1245. return -ENODEV;
  1246. LOCK(flags);
  1247. if (value) {
  1248. MACIO_BIS(KEYLARGO_FCR1, K2_FCR1_FW_CLK_ENABLE);
  1249. mb();
  1250. k2_skiplist[1] = NULL;
  1251. } else {
  1252. k2_skiplist[1] = node;
  1253. mb();
  1254. MACIO_BIC(KEYLARGO_FCR1, K2_FCR1_FW_CLK_ENABLE);
  1255. }
  1256. UNLOCK(flags);
  1257. mdelay(1);
  1258. return 0;
  1259. }
  1260. static long g5_mpic_enable(struct device_node *node, long param, long value)
  1261. {
  1262. unsigned long flags;
  1263. struct device_node *parent = of_get_parent(node);
  1264. int is_u3;
  1265. if (parent == NULL)
  1266. return 0;
  1267. is_u3 = strcmp(parent->name, "u3") == 0 ||
  1268. strcmp(parent->name, "u4") == 0;
  1269. of_node_put(parent);
  1270. if (!is_u3)
  1271. return 0;
  1272. LOCK(flags);
  1273. UN_BIS(U3_TOGGLE_REG, U3_MPIC_RESET | U3_MPIC_OUTPUT_ENABLE);
  1274. UNLOCK(flags);
  1275. return 0;
  1276. }
  1277. static long g5_eth_phy_reset(struct device_node *node, long param, long value)
  1278. {
  1279. struct macio_chip *macio = &macio_chips[0];
  1280. struct device_node *phy;
  1281. int need_reset;
  1282. /*
  1283. * We must not reset the combo PHYs, only the BCM5221 found in
  1284. * the iMac G5.
  1285. */
  1286. phy = of_get_next_child(node, NULL);
  1287. if (!phy)
  1288. return -ENODEV;
  1289. need_reset = of_device_is_compatible(phy, "B5221");
  1290. of_node_put(phy);
  1291. if (!need_reset)
  1292. return 0;
  1293. /* PHY reset is GPIO 29, not in device-tree unfortunately */
  1294. MACIO_OUT8(K2_GPIO_EXTINT_0 + 29,
  1295. KEYLARGO_GPIO_OUTPUT_ENABLE | KEYLARGO_GPIO_OUTOUT_DATA);
  1296. /* Thankfully, this is now always called at a time when we can
  1297. * schedule by sungem.
  1298. */
  1299. msleep(10);
  1300. MACIO_OUT8(K2_GPIO_EXTINT_0 + 29, 0);
  1301. return 0;
  1302. }
  1303. static long g5_i2s_enable(struct device_node *node, long param, long value)
  1304. {
  1305. /* Very crude implementation for now */
  1306. struct macio_chip *macio = &macio_chips[0];
  1307. unsigned long flags;
  1308. int cell;
  1309. u32 fcrs[3][3] = {
  1310. { 0,
  1311. K2_FCR1_I2S0_CELL_ENABLE |
  1312. K2_FCR1_I2S0_CLK_ENABLE_BIT | K2_FCR1_I2S0_ENABLE,
  1313. KL3_I2S0_CLK18_ENABLE
  1314. },
  1315. { KL0_SCC_A_INTF_ENABLE,
  1316. K2_FCR1_I2S1_CELL_ENABLE |
  1317. K2_FCR1_I2S1_CLK_ENABLE_BIT | K2_FCR1_I2S1_ENABLE,
  1318. KL3_I2S1_CLK18_ENABLE
  1319. },
  1320. { KL0_SCC_B_INTF_ENABLE,
  1321. SH_FCR1_I2S2_CELL_ENABLE |
  1322. SH_FCR1_I2S2_CLK_ENABLE_BIT | SH_FCR1_I2S2_ENABLE,
  1323. SH_FCR3_I2S2_CLK18_ENABLE
  1324. },
  1325. };
  1326. if (macio->type != macio_keylargo2 && macio->type != macio_shasta)
  1327. return -ENODEV;
  1328. if (strncmp(node->name, "i2s-", 4))
  1329. return -ENODEV;
  1330. cell = node->name[4] - 'a';
  1331. switch(cell) {
  1332. case 0:
  1333. case 1:
  1334. break;
  1335. case 2:
  1336. if (macio->type == macio_shasta)
  1337. break;
  1338. default:
  1339. return -ENODEV;
  1340. }
  1341. LOCK(flags);
  1342. if (value) {
  1343. MACIO_BIC(KEYLARGO_FCR0, fcrs[cell][0]);
  1344. MACIO_BIS(KEYLARGO_FCR1, fcrs[cell][1]);
  1345. MACIO_BIS(KEYLARGO_FCR3, fcrs[cell][2]);
  1346. } else {
  1347. MACIO_BIC(KEYLARGO_FCR3, fcrs[cell][2]);
  1348. MACIO_BIC(KEYLARGO_FCR1, fcrs[cell][1]);
  1349. MACIO_BIS(KEYLARGO_FCR0, fcrs[cell][0]);
  1350. }
  1351. udelay(10);
  1352. UNLOCK(flags);
  1353. return 0;
  1354. }
  1355. #ifdef CONFIG_SMP
  1356. static long g5_reset_cpu(struct device_node *node, long param, long value)
  1357. {
  1358. unsigned int reset_io = 0;
  1359. unsigned long flags;
  1360. struct macio_chip *macio;
  1361. struct device_node *np;
  1362. struct device_node *cpus;
  1363. macio = &macio_chips[0];
  1364. if (macio->type != macio_keylargo2 && macio->type != macio_shasta)
  1365. return -ENODEV;
  1366. cpus = of_find_node_by_path("/cpus");
  1367. if (cpus == NULL)
  1368. return -ENODEV;
  1369. for (np = cpus->child; np != NULL; np = np->sibling) {
  1370. const u32 *num = of_get_property(np, "reg", NULL);
  1371. const u32 *rst = of_get_property(np, "soft-reset", NULL);
  1372. if (num == NULL || rst == NULL)
  1373. continue;
  1374. if (param == *num) {
  1375. reset_io = *rst;
  1376. break;
  1377. }
  1378. }
  1379. of_node_put(cpus);
  1380. if (np == NULL || reset_io == 0)
  1381. return -ENODEV;
  1382. LOCK(flags);
  1383. MACIO_OUT8(reset_io, KEYLARGO_GPIO_OUTPUT_ENABLE);
  1384. (void)MACIO_IN8(reset_io);
  1385. udelay(1);
  1386. MACIO_OUT8(reset_io, 0);
  1387. (void)MACIO_IN8(reset_io);
  1388. UNLOCK(flags);
  1389. return 0;
  1390. }
  1391. #endif /* CONFIG_SMP */
  1392. /*
  1393. * This can be called from pmac_smp so isn't static
  1394. *
  1395. * This takes the second CPU off the bus on dual CPU machines
  1396. * running UP
  1397. */
  1398. void g5_phy_disable_cpu1(void)
  1399. {
  1400. if (uninorth_maj == 3)
  1401. UN_OUT(U3_API_PHY_CONFIG_1, 0);
  1402. }
  1403. #endif /* CONFIG_POWER4 */
  1404. #ifndef CONFIG_POWER4
  1405. #ifdef CONFIG_PM
  1406. static u32 save_gpio_levels[2];
  1407. static u8 save_gpio_extint[KEYLARGO_GPIO_EXTINT_CNT];
  1408. static u8 save_gpio_normal[KEYLARGO_GPIO_CNT];
  1409. static u32 save_unin_clock_ctl;
  1410. static void keylargo_shutdown(struct macio_chip *macio, int sleep_mode)
  1411. {
  1412. u32 temp;
  1413. if (sleep_mode) {
  1414. mdelay(1);
  1415. MACIO_BIS(KEYLARGO_FCR0, KL0_USB_REF_SUSPEND);
  1416. (void)MACIO_IN32(KEYLARGO_FCR0);
  1417. mdelay(1);
  1418. }
  1419. MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
  1420. KL0_SCC_CELL_ENABLE |
  1421. KL0_IRDA_ENABLE | KL0_IRDA_CLK32_ENABLE |
  1422. KL0_IRDA_CLK19_ENABLE);
  1423. MACIO_BIC(KEYLARGO_MBCR, KL_MBCR_MB0_DEV_MASK);
  1424. MACIO_BIS(KEYLARGO_MBCR, KL_MBCR_MB0_IDE_ENABLE);
  1425. MACIO_BIC(KEYLARGO_FCR1,
  1426. KL1_AUDIO_SEL_22MCLK | KL1_AUDIO_CLK_ENABLE_BIT |
  1427. KL1_AUDIO_CLK_OUT_ENABLE | KL1_AUDIO_CELL_ENABLE |
  1428. KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
  1429. KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
  1430. KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
  1431. KL1_EIDE0_ENABLE | KL1_EIDE0_RESET_N |
  1432. KL1_EIDE1_ENABLE | KL1_EIDE1_RESET_N |
  1433. KL1_UIDE_ENABLE);
  1434. MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
  1435. MACIO_BIC(KEYLARGO_FCR2, KL2_IOBUS_ENABLE);
  1436. temp = MACIO_IN32(KEYLARGO_FCR3);
  1437. if (macio->rev >= 2) {
  1438. temp |= KL3_SHUTDOWN_PLL2X;
  1439. if (sleep_mode)
  1440. temp |= KL3_SHUTDOWN_PLL_TOTAL;
  1441. }
  1442. temp |= KL3_SHUTDOWN_PLLKW6 | KL3_SHUTDOWN_PLLKW4 |
  1443. KL3_SHUTDOWN_PLLKW35;
  1444. if (sleep_mode)
  1445. temp |= KL3_SHUTDOWN_PLLKW12;
  1446. temp &= ~(KL3_CLK66_ENABLE | KL3_CLK49_ENABLE | KL3_CLK45_ENABLE
  1447. | KL3_CLK31_ENABLE | KL3_I2S1_CLK18_ENABLE | KL3_I2S0_CLK18_ENABLE);
  1448. if (sleep_mode)
  1449. temp &= ~(KL3_TIMER_CLK18_ENABLE | KL3_VIA_CLK16_ENABLE);
  1450. MACIO_OUT32(KEYLARGO_FCR3, temp);
  1451. /* Flush posted writes & wait a bit */
  1452. (void)MACIO_IN32(KEYLARGO_FCR0); mdelay(1);
  1453. }
  1454. static void pangea_shutdown(struct macio_chip *macio, int sleep_mode)
  1455. {
  1456. u32 temp;
  1457. MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
  1458. KL0_SCC_CELL_ENABLE |
  1459. KL0_USB0_CELL_ENABLE | KL0_USB1_CELL_ENABLE);
  1460. MACIO_BIC(KEYLARGO_FCR1,
  1461. KL1_AUDIO_SEL_22MCLK | KL1_AUDIO_CLK_ENABLE_BIT |
  1462. KL1_AUDIO_CLK_OUT_ENABLE | KL1_AUDIO_CELL_ENABLE |
  1463. KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
  1464. KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
  1465. KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
  1466. KL1_UIDE_ENABLE);
  1467. if (pmac_mb.board_flags & PMAC_MB_MOBILE)
  1468. MACIO_BIC(KEYLARGO_FCR1, KL1_UIDE_RESET_N);
  1469. MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
  1470. temp = MACIO_IN32(KEYLARGO_FCR3);
  1471. temp |= KL3_SHUTDOWN_PLLKW6 | KL3_SHUTDOWN_PLLKW4 |
  1472. KL3_SHUTDOWN_PLLKW35;
  1473. temp &= ~(KL3_CLK49_ENABLE | KL3_CLK45_ENABLE | KL3_CLK31_ENABLE
  1474. | KL3_I2S0_CLK18_ENABLE | KL3_I2S1_CLK18_ENABLE);
  1475. if (sleep_mode)
  1476. temp &= ~(KL3_VIA_CLK16_ENABLE | KL3_TIMER_CLK18_ENABLE);
  1477. MACIO_OUT32(KEYLARGO_FCR3, temp);
  1478. /* Flush posted writes & wait a bit */
  1479. (void)MACIO_IN32(KEYLARGO_FCR0); mdelay(1);
  1480. }
  1481. static void intrepid_shutdown(struct macio_chip *macio, int sleep_mode)
  1482. {
  1483. u32 temp;
  1484. MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
  1485. KL0_SCC_CELL_ENABLE);
  1486. MACIO_BIC(KEYLARGO_FCR1,
  1487. KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
  1488. KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
  1489. KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
  1490. KL1_EIDE0_ENABLE);
  1491. if (pmac_mb.board_flags & PMAC_MB_MOBILE)
  1492. MACIO_BIC(KEYLARGO_FCR1, KL1_UIDE_RESET_N);
  1493. temp = MACIO_IN32(KEYLARGO_FCR3);
  1494. temp &= ~(KL3_CLK49_ENABLE | KL3_CLK45_ENABLE |
  1495. KL3_I2S1_CLK18_ENABLE | KL3_I2S0_CLK18_ENABLE);
  1496. if (sleep_mode)
  1497. temp &= ~(KL3_TIMER_CLK18_ENABLE | KL3_IT_VIA_CLK32_ENABLE);
  1498. MACIO_OUT32(KEYLARGO_FCR3, temp);
  1499. /* Flush posted writes & wait a bit */
  1500. (void)MACIO_IN32(KEYLARGO_FCR0);
  1501. mdelay(10);
  1502. }
  1503. static int
  1504. core99_sleep(void)
  1505. {
  1506. struct macio_chip *macio;
  1507. int i;
  1508. macio = &macio_chips[0];
  1509. if (macio->type != macio_keylargo && macio->type != macio_pangea &&
  1510. macio->type != macio_intrepid)
  1511. return -ENODEV;
  1512. /* We power off the wireless slot in case it was not done
  1513. * by the driver. We don't power it on automatically however
  1514. */
  1515. if (macio->flags & MACIO_FLAG_AIRPORT_ON)
  1516. core99_airport_enable(macio->of_node, 0, 0);
  1517. /* We power off the FW cable. Should be done by the driver... */
  1518. if (macio->flags & MACIO_FLAG_FW_SUPPORTED) {
  1519. core99_firewire_enable(NULL, 0, 0);
  1520. core99_firewire_cable_power(NULL, 0, 0);
  1521. }
  1522. /* We make sure int. modem is off (in case driver lost it) */
  1523. if (macio->type == macio_keylargo)
  1524. core99_modem_enable(macio->of_node, 0, 0);
  1525. else
  1526. pangea_modem_enable(macio->of_node, 0, 0);
  1527. /* We make sure the sound is off as well */
  1528. core99_sound_chip_enable(macio->of_node, 0, 0);
  1529. /*
  1530. * Save various bits of KeyLargo
  1531. */
  1532. /* Save the state of the various GPIOs */
  1533. save_gpio_levels[0] = MACIO_IN32(KEYLARGO_GPIO_LEVELS0);
  1534. save_gpio_levels[1] = MACIO_IN32(KEYLARGO_GPIO_LEVELS1);
  1535. for (i=0; i<KEYLARGO_GPIO_EXTINT_CNT; i++)
  1536. save_gpio_extint[i] = MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+i);
  1537. for (i=0; i<KEYLARGO_GPIO_CNT; i++)
  1538. save_gpio_normal[i] = MACIO_IN8(KEYLARGO_GPIO_0+i);
  1539. /* Save the FCRs */
  1540. if (macio->type == macio_keylargo)
  1541. save_mbcr = MACIO_IN32(KEYLARGO_MBCR);
  1542. save_fcr[0] = MACIO_IN32(KEYLARGO_FCR0);
  1543. save_fcr[1] = MACIO_IN32(KEYLARGO_FCR1);
  1544. save_fcr[2] = MACIO_IN32(KEYLARGO_FCR2);
  1545. save_fcr[3] = MACIO_IN32(KEYLARGO_FCR3);
  1546. save_fcr[4] = MACIO_IN32(KEYLARGO_FCR4);
  1547. if (macio->type == macio_pangea || macio->type == macio_intrepid)
  1548. save_fcr[5] = MACIO_IN32(KEYLARGO_FCR5);
  1549. /* Save state & config of DBDMA channels */
  1550. dbdma_save(macio, save_dbdma);
  1551. /*
  1552. * Turn off as much as we can
  1553. */
  1554. if (macio->type == macio_pangea)
  1555. pangea_shutdown(macio, 1);
  1556. else if (macio->type == macio_intrepid)
  1557. intrepid_shutdown(macio, 1);
  1558. else if (macio->type == macio_keylargo)
  1559. keylargo_shutdown(macio, 1);
  1560. /*
  1561. * Put the host bridge to sleep
  1562. */
  1563. save_unin_clock_ctl = UN_IN(UNI_N_CLOCK_CNTL);
  1564. /* Note: do not switch GMAC off, driver does it when necessary, WOL must keep it
  1565. * enabled !
  1566. */
  1567. UN_OUT(UNI_N_CLOCK_CNTL, save_unin_clock_ctl &
  1568. ~(/*UNI_N_CLOCK_CNTL_GMAC|*/UNI_N_CLOCK_CNTL_FW/*|UNI_N_CLOCK_CNTL_PCI*/));
  1569. udelay(100);
  1570. UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_SLEEPING);
  1571. UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_SLEEP);
  1572. mdelay(10);
  1573. /*
  1574. * FIXME: A bit of black magic with OpenPIC (don't ask me why)
  1575. */
  1576. if (pmac_mb.model_id == PMAC_TYPE_SAWTOOTH) {
  1577. MACIO_BIS(0x506e0, 0x00400000);
  1578. MACIO_BIS(0x506e0, 0x80000000);
  1579. }
  1580. return 0;
  1581. }
  1582. static int
  1583. core99_wake_up(void)
  1584. {
  1585. struct macio_chip *macio;
  1586. int i;
  1587. macio = &macio_chips[0];
  1588. if (macio->type != macio_keylargo && macio->type != macio_pangea &&
  1589. macio->type != macio_intrepid)
  1590. return -ENODEV;
  1591. /*
  1592. * Wakeup the host bridge
  1593. */
  1594. UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_NORMAL);
  1595. udelay(10);
  1596. UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_RUNNING);
  1597. udelay(10);
  1598. /*
  1599. * Restore KeyLargo
  1600. */
  1601. if (macio->type == macio_keylargo) {
  1602. MACIO_OUT32(KEYLARGO_MBCR, save_mbcr);
  1603. (void)MACIO_IN32(KEYLARGO_MBCR); udelay(10);
  1604. }
  1605. MACIO_OUT32(KEYLARGO_FCR0, save_fcr[0]);
  1606. (void)MACIO_IN32(KEYLARGO_FCR0); udelay(10);
  1607. MACIO_OUT32(KEYLARGO_FCR1, save_fcr[1]);
  1608. (void)MACIO_IN32(KEYLARGO_FCR1); udelay(10);
  1609. MACIO_OUT32(KEYLARGO_FCR2, save_fcr[2]);
  1610. (void)MACIO_IN32(KEYLARGO_FCR2); udelay(10);
  1611. MACIO_OUT32(KEYLARGO_FCR3, save_fcr[3]);
  1612. (void)MACIO_IN32(KEYLARGO_FCR3); udelay(10);
  1613. MACIO_OUT32(KEYLARGO_FCR4, save_fcr[4]);
  1614. (void)MACIO_IN32(KEYLARGO_FCR4); udelay(10);
  1615. if (macio->type == macio_pangea || macio->type == macio_intrepid) {
  1616. MACIO_OUT32(KEYLARGO_FCR5, save_fcr[5]);
  1617. (void)MACIO_IN32(KEYLARGO_FCR5); udelay(10);
  1618. }
  1619. dbdma_restore(macio, save_dbdma);
  1620. MACIO_OUT32(KEYLARGO_GPIO_LEVELS0, save_gpio_levels[0]);
  1621. MACIO_OUT32(KEYLARGO_GPIO_LEVELS1, save_gpio_levels[1]);
  1622. for (i=0; i<KEYLARGO_GPIO_EXTINT_CNT; i++)
  1623. MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+i, save_gpio_extint[i]);
  1624. for (i=0; i<KEYLARGO_GPIO_CNT; i++)
  1625. MACIO_OUT8(KEYLARGO_GPIO_0+i, save_gpio_normal[i]);
  1626. /* FIXME more black magic with OpenPIC ... */
  1627. if (pmac_mb.model_id == PMAC_TYPE_SAWTOOTH) {
  1628. MACIO_BIC(0x506e0, 0x00400000);
  1629. MACIO_BIC(0x506e0, 0x80000000);
  1630. }
  1631. UN_OUT(UNI_N_CLOCK_CNTL, save_unin_clock_ctl);
  1632. udelay(100);
  1633. return 0;
  1634. }
  1635. #endif /* CONFIG_PM */
  1636. static long
  1637. core99_sleep_state(struct device_node *node, long param, long value)
  1638. {
  1639. /* Param == 1 means to enter the "fake sleep" mode that is
  1640. * used for CPU speed switch
  1641. */
  1642. if (param == 1) {
  1643. if (value == 1) {
  1644. UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_SLEEPING);
  1645. UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_IDLE2);
  1646. } else {
  1647. UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_NORMAL);
  1648. udelay(10);
  1649. UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_RUNNING);
  1650. udelay(10);
  1651. }
  1652. return 0;
  1653. }
  1654. if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
  1655. return -EPERM;
  1656. #ifdef CONFIG_PM
  1657. if (value == 1)
  1658. return core99_sleep();
  1659. else if (value == 0)
  1660. return core99_wake_up();
  1661. #endif /* CONFIG_PM */
  1662. return 0;
  1663. }
  1664. #endif /* CONFIG_POWER4 */
  1665. static long
  1666. generic_dev_can_wake(struct device_node *node, long param, long value)
  1667. {
  1668. /* Todo: eventually check we are really dealing with on-board
  1669. * video device ...
  1670. */
  1671. if (pmac_mb.board_flags & PMAC_MB_MAY_SLEEP)
  1672. pmac_mb.board_flags |= PMAC_MB_CAN_SLEEP;
  1673. return 0;
  1674. }
  1675. static long generic_get_mb_info(struct device_node *node, long param, long value)
  1676. {
  1677. switch(param) {
  1678. case PMAC_MB_INFO_MODEL:
  1679. return pmac_mb.model_id;
  1680. case PMAC_MB_INFO_FLAGS:
  1681. return pmac_mb.board_flags;
  1682. case PMAC_MB_INFO_NAME:
  1683. /* hack hack hack... but should work */
  1684. *((const char **)value) = pmac_mb.model_name;
  1685. return 0;
  1686. }
  1687. return -EINVAL;
  1688. }
  1689. /*
  1690. * Table definitions
  1691. */
  1692. /* Used on any machine
  1693. */
  1694. static struct feature_table_entry any_features[] = {
  1695. { PMAC_FTR_GET_MB_INFO, generic_get_mb_info },
  1696. { PMAC_FTR_DEVICE_CAN_WAKE, generic_dev_can_wake },
  1697. { 0, NULL }
  1698. };
  1699. #ifndef CONFIG_POWER4
  1700. /* OHare based motherboards. Currently, we only use these on the
  1701. * 2400,3400 and 3500 series powerbooks. Some older desktops seem
  1702. * to have issues with turning on/off those asic cells
  1703. */
  1704. static struct feature_table_entry ohare_features[] = {
  1705. { PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },
  1706. { PMAC_FTR_SWIM3_ENABLE, ohare_floppy_enable },
  1707. { PMAC_FTR_MESH_ENABLE, ohare_mesh_enable },
  1708. { PMAC_FTR_IDE_ENABLE, ohare_ide_enable},
  1709. { PMAC_FTR_IDE_RESET, ohare_ide_reset},
  1710. { PMAC_FTR_SLEEP_STATE, ohare_sleep_state },
  1711. { 0, NULL }
  1712. };
  1713. /* Heathrow desktop machines (Beige G3).
  1714. * Separated as some features couldn't be properly tested
  1715. * and the serial port control bits appear to confuse it.
  1716. */
  1717. static struct feature_table_entry heathrow_desktop_features[] = {
  1718. { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
  1719. { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
  1720. { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
  1721. { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
  1722. { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
  1723. { 0, NULL }
  1724. };
  1725. /* Heathrow based laptop, that is the Wallstreet and mainstreet
  1726. * powerbooks.
  1727. */
  1728. static struct feature_table_entry heathrow_laptop_features[] = {
  1729. { PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },
  1730. { PMAC_FTR_MODEM_ENABLE, heathrow_modem_enable },
  1731. { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
  1732. { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
  1733. { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
  1734. { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
  1735. { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
  1736. { PMAC_FTR_SOUND_CHIP_ENABLE, heathrow_sound_enable },
  1737. { PMAC_FTR_SLEEP_STATE, heathrow_sleep_state },
  1738. { 0, NULL }
  1739. };
  1740. /* Paddington based machines
  1741. * The lombard (101) powerbook, first iMac models, B&W G3 and Yikes G4.
  1742. */
  1743. static struct feature_table_entry paddington_features[] = {
  1744. { PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },
  1745. { PMAC_FTR_MODEM_ENABLE, heathrow_modem_enable },
  1746. { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
  1747. { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
  1748. { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
  1749. { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
  1750. { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
  1751. { PMAC_FTR_SOUND_CHIP_ENABLE, heathrow_sound_enable },
  1752. { PMAC_FTR_SLEEP_STATE, heathrow_sleep_state },
  1753. { 0, NULL }
  1754. };
  1755. /* Core99 & MacRISC 2 machines (all machines released since the
  1756. * iBook (included), that is all AGP machines, except pangea
  1757. * chipset. The pangea chipset is the "combo" UniNorth/KeyLargo
  1758. * used on iBook2 & iMac "flow power".
  1759. */
  1760. static struct feature_table_entry core99_features[] = {
  1761. { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
  1762. { PMAC_FTR_MODEM_ENABLE, core99_modem_enable },
  1763. { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
  1764. { PMAC_FTR_IDE_RESET, core99_ide_reset },
  1765. { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
  1766. { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
  1767. { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
  1768. { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
  1769. { PMAC_FTR_USB_ENABLE, core99_usb_enable },
  1770. { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
  1771. { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
  1772. #ifdef CONFIG_PM
  1773. { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
  1774. #endif
  1775. #ifdef CONFIG_SMP
  1776. { PMAC_FTR_RESET_CPU, core99_reset_cpu },
  1777. #endif /* CONFIG_SMP */
  1778. { PMAC_FTR_READ_GPIO, core99_read_gpio },
  1779. { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
  1780. { 0, NULL }
  1781. };
  1782. /* RackMac
  1783. */
  1784. static struct feature_table_entry rackmac_features[] = {
  1785. { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
  1786. { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
  1787. { PMAC_FTR_IDE_RESET, core99_ide_reset },
  1788. { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
  1789. { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
  1790. { PMAC_FTR_USB_ENABLE, core99_usb_enable },
  1791. { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
  1792. { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
  1793. { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
  1794. #ifdef CONFIG_SMP
  1795. { PMAC_FTR_RESET_CPU, core99_reset_cpu },
  1796. #endif /* CONFIG_SMP */
  1797. { PMAC_FTR_READ_GPIO, core99_read_gpio },
  1798. { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
  1799. { 0, NULL }
  1800. };
  1801. /* Pangea features
  1802. */
  1803. static struct feature_table_entry pangea_features[] = {
  1804. { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
  1805. { PMAC_FTR_MODEM_ENABLE, pangea_modem_enable },
  1806. { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
  1807. { PMAC_FTR_IDE_RESET, core99_ide_reset },
  1808. { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
  1809. { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
  1810. { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
  1811. { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
  1812. { PMAC_FTR_USB_ENABLE, core99_usb_enable },
  1813. { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
  1814. { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
  1815. { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
  1816. { PMAC_FTR_READ_GPIO, core99_read_gpio },
  1817. { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
  1818. { 0, NULL }
  1819. };
  1820. /* Intrepid features
  1821. */
  1822. static struct feature_table_entry intrepid_features[] = {
  1823. { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
  1824. { PMAC_FTR_MODEM_ENABLE, pangea_modem_enable },
  1825. { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
  1826. { PMAC_FTR_IDE_RESET, core99_ide_reset },
  1827. { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
  1828. { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
  1829. { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
  1830. { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
  1831. { PMAC_FTR_USB_ENABLE, core99_usb_enable },
  1832. { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
  1833. { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
  1834. { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
  1835. { PMAC_FTR_READ_GPIO, core99_read_gpio },
  1836. { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
  1837. { PMAC_FTR_AACK_DELAY_ENABLE, intrepid_aack_delay_enable },
  1838. { 0, NULL }
  1839. };
  1840. #else /* CONFIG_POWER4 */
  1841. /* G5 features
  1842. */
  1843. static struct feature_table_entry g5_features[] = {
  1844. { PMAC_FTR_GMAC_ENABLE, g5_gmac_enable },
  1845. { PMAC_FTR_1394_ENABLE, g5_fw_enable },
  1846. { PMAC_FTR_ENABLE_MPIC, g5_mpic_enable },
  1847. { PMAC_FTR_GMAC_PHY_RESET, g5_eth_phy_reset },
  1848. { PMAC_FTR_SOUND_CHIP_ENABLE, g5_i2s_enable },
  1849. #ifdef CONFIG_SMP
  1850. { PMAC_FTR_RESET_CPU, g5_reset_cpu },
  1851. #endif /* CONFIG_SMP */
  1852. { PMAC_FTR_READ_GPIO, core99_read_gpio },
  1853. { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
  1854. { 0, NULL }
  1855. };
  1856. #endif /* CONFIG_POWER4 */
  1857. static struct pmac_mb_def pmac_mb_defs[] = {
  1858. #ifndef CONFIG_POWER4
  1859. /*
  1860. * Desktops
  1861. */
  1862. { "AAPL,8500", "PowerMac 8500/8600",
  1863. PMAC_TYPE_PSURGE, NULL,
  1864. 0
  1865. },
  1866. { "AAPL,9500", "PowerMac 9500/9600",
  1867. PMAC_TYPE_PSURGE, NULL,
  1868. 0
  1869. },
  1870. { "AAPL,7200", "PowerMac 7200",
  1871. PMAC_TYPE_PSURGE, NULL,
  1872. 0
  1873. },
  1874. { "AAPL,7300", "PowerMac 7200/7300",
  1875. PMAC_TYPE_PSURGE, NULL,
  1876. 0
  1877. },
  1878. { "AAPL,7500", "PowerMac 7500",
  1879. PMAC_TYPE_PSURGE, NULL,
  1880. 0
  1881. },
  1882. { "AAPL,ShinerESB", "Apple Network Server",
  1883. PMAC_TYPE_ANS, NULL,
  1884. 0
  1885. },
  1886. { "AAPL,e407", "Alchemy",
  1887. PMAC_TYPE_ALCHEMY, NULL,
  1888. 0
  1889. },
  1890. { "AAPL,e411", "Gazelle",
  1891. PMAC_TYPE_GAZELLE, NULL,
  1892. 0
  1893. },
  1894. { "AAPL,Gossamer", "PowerMac G3 (Gossamer)",
  1895. PMAC_TYPE_GOSSAMER, heathrow_desktop_features,
  1896. 0
  1897. },
  1898. { "AAPL,PowerMac G3", "PowerMac G3 (Silk)",
  1899. PMAC_TYPE_SILK, heathrow_desktop_features,
  1900. 0
  1901. },
  1902. { "PowerMac1,1", "Blue&White G3",
  1903. PMAC_TYPE_YOSEMITE, paddington_features,
  1904. 0
  1905. },
  1906. { "PowerMac1,2", "PowerMac G4 PCI Graphics",
  1907. PMAC_TYPE_YIKES, paddington_features,
  1908. 0
  1909. },
  1910. { "PowerMac2,1", "iMac FireWire",
  1911. PMAC_TYPE_FW_IMAC, core99_features,
  1912. PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
  1913. },
  1914. { "PowerMac2,2", "iMac FireWire",
  1915. PMAC_TYPE_FW_IMAC, core99_features,
  1916. PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
  1917. },
  1918. { "PowerMac3,1", "PowerMac G4 AGP Graphics",
  1919. PMAC_TYPE_SAWTOOTH, core99_features,
  1920. PMAC_MB_OLD_CORE99
  1921. },
  1922. { "PowerMac3,2", "PowerMac G4 AGP Graphics",
  1923. PMAC_TYPE_SAWTOOTH, core99_features,
  1924. PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
  1925. },
  1926. { "PowerMac3,3", "PowerMac G4 AGP Graphics",
  1927. PMAC_TYPE_SAWTOOTH, core99_features,
  1928. PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
  1929. },
  1930. { "PowerMac3,4", "PowerMac G4 Silver",
  1931. PMAC_TYPE_QUICKSILVER, core99_features,
  1932. PMAC_MB_MAY_SLEEP
  1933. },
  1934. { "PowerMac3,5", "PowerMac G4 Silver",
  1935. PMAC_TYPE_QUICKSILVER, core99_features,
  1936. PMAC_MB_MAY_SLEEP
  1937. },
  1938. { "PowerMac3,6", "PowerMac G4 Windtunnel",
  1939. PMAC_TYPE_WINDTUNNEL, core99_features,
  1940. PMAC_MB_MAY_SLEEP,
  1941. },
  1942. { "PowerMac4,1", "iMac \"Flower Power\"",
  1943. PMAC_TYPE_PANGEA_IMAC, pangea_features,
  1944. PMAC_MB_MAY_SLEEP
  1945. },
  1946. { "PowerMac4,2", "Flat panel iMac",
  1947. PMAC_TYPE_FLAT_PANEL_IMAC, pangea_features,
  1948. PMAC_MB_CAN_SLEEP
  1949. },
  1950. { "PowerMac4,4", "eMac",
  1951. PMAC_TYPE_EMAC, core99_features,
  1952. PMAC_MB_MAY_SLEEP
  1953. },
  1954. { "PowerMac5,1", "PowerMac G4 Cube",
  1955. PMAC_TYPE_CUBE, core99_features,
  1956. PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
  1957. },
  1958. { "PowerMac6,1", "Flat panel iMac",
  1959. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  1960. PMAC_MB_MAY_SLEEP,
  1961. },
  1962. { "PowerMac6,3", "Flat panel iMac",
  1963. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  1964. PMAC_MB_MAY_SLEEP,
  1965. },
  1966. { "PowerMac6,4", "eMac",
  1967. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  1968. PMAC_MB_MAY_SLEEP,
  1969. },
  1970. { "PowerMac10,1", "Mac mini",
  1971. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  1972. PMAC_MB_MAY_SLEEP,
  1973. },
  1974. { "iMac,1", "iMac (first generation)",
  1975. PMAC_TYPE_ORIG_IMAC, paddington_features,
  1976. 0
  1977. },
  1978. /*
  1979. * Xserve's
  1980. */
  1981. { "RackMac1,1", "XServe",
  1982. PMAC_TYPE_RACKMAC, rackmac_features,
  1983. 0,
  1984. },
  1985. { "RackMac1,2", "XServe rev. 2",
  1986. PMAC_TYPE_RACKMAC, rackmac_features,
  1987. 0,
  1988. },
  1989. /*
  1990. * Laptops
  1991. */
  1992. { "AAPL,3400/2400", "PowerBook 3400",
  1993. PMAC_TYPE_HOOPER, ohare_features,
  1994. PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
  1995. },
  1996. { "AAPL,3500", "PowerBook 3500",
  1997. PMAC_TYPE_KANGA, ohare_features,
  1998. PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
  1999. },
  2000. { "AAPL,PowerBook1998", "PowerBook Wallstreet",
  2001. PMAC_TYPE_WALLSTREET, heathrow_laptop_features,
  2002. PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
  2003. },
  2004. { "PowerBook1,1", "PowerBook 101 (Lombard)",
  2005. PMAC_TYPE_101_PBOOK, paddington_features,
  2006. PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
  2007. },
  2008. { "PowerBook2,1", "iBook (first generation)",
  2009. PMAC_TYPE_ORIG_IBOOK, core99_features,
  2010. PMAC_MB_CAN_SLEEP | PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE
  2011. },
  2012. { "PowerBook2,2", "iBook FireWire",
  2013. PMAC_TYPE_FW_IBOOK, core99_features,
  2014. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER |
  2015. PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE
  2016. },
  2017. { "PowerBook3,1", "PowerBook Pismo",
  2018. PMAC_TYPE_PISMO, core99_features,
  2019. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER |
  2020. PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE
  2021. },
  2022. { "PowerBook3,2", "PowerBook Titanium",
  2023. PMAC_TYPE_TITANIUM, core99_features,
  2024. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2025. },
  2026. { "PowerBook3,3", "PowerBook Titanium II",
  2027. PMAC_TYPE_TITANIUM2, core99_features,
  2028. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2029. },
  2030. { "PowerBook3,4", "PowerBook Titanium III",
  2031. PMAC_TYPE_TITANIUM3, core99_features,
  2032. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2033. },
  2034. { "PowerBook3,5", "PowerBook Titanium IV",
  2035. PMAC_TYPE_TITANIUM4, core99_features,
  2036. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2037. },
  2038. { "PowerBook4,1", "iBook 2",
  2039. PMAC_TYPE_IBOOK2, pangea_features,
  2040. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2041. },
  2042. { "PowerBook4,2", "iBook 2",
  2043. PMAC_TYPE_IBOOK2, pangea_features,
  2044. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2045. },
  2046. { "PowerBook4,3", "iBook 2 rev. 2",
  2047. PMAC_TYPE_IBOOK2, pangea_features,
  2048. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2049. },
  2050. { "PowerBook5,1", "PowerBook G4 17\"",
  2051. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2052. PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2053. },
  2054. { "PowerBook5,2", "PowerBook G4 15\"",
  2055. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2056. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2057. },
  2058. { "PowerBook5,3", "PowerBook G4 17\"",
  2059. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2060. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2061. },
  2062. { "PowerBook5,4", "PowerBook G4 15\"",
  2063. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2064. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2065. },
  2066. { "PowerBook5,5", "PowerBook G4 17\"",
  2067. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2068. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2069. },
  2070. { "PowerBook5,6", "PowerBook G4 15\"",
  2071. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2072. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2073. },
  2074. { "PowerBook5,7", "PowerBook G4 17\"",
  2075. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2076. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2077. },
  2078. { "PowerBook5,8", "PowerBook G4 15\"",
  2079. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2080. PMAC_MB_MAY_SLEEP | PMAC_MB_MOBILE,
  2081. },
  2082. { "PowerBook5,9", "PowerBook G4 17\"",
  2083. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2084. PMAC_MB_MAY_SLEEP | PMAC_MB_MOBILE,
  2085. },
  2086. { "PowerBook6,1", "PowerBook G4 12\"",
  2087. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2088. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2089. },
  2090. { "PowerBook6,2", "PowerBook G4",
  2091. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2092. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2093. },
  2094. { "PowerBook6,3", "iBook G4",
  2095. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2096. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2097. },
  2098. { "PowerBook6,4", "PowerBook G4 12\"",
  2099. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2100. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2101. },
  2102. { "PowerBook6,5", "iBook G4",
  2103. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2104. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2105. },
  2106. { "PowerBook6,7", "iBook G4",
  2107. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2108. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2109. },
  2110. { "PowerBook6,8", "PowerBook G4 12\"",
  2111. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2112. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2113. },
  2114. #else /* CONFIG_POWER4 */
  2115. { "PowerMac7,2", "PowerMac G5",
  2116. PMAC_TYPE_POWERMAC_G5, g5_features,
  2117. 0,
  2118. },
  2119. #ifdef CONFIG_PPC64
  2120. { "PowerMac7,3", "PowerMac G5",
  2121. PMAC_TYPE_POWERMAC_G5, g5_features,
  2122. 0,
  2123. },
  2124. { "PowerMac8,1", "iMac G5",
  2125. PMAC_TYPE_IMAC_G5, g5_features,
  2126. 0,
  2127. },
  2128. { "PowerMac9,1", "PowerMac G5",
  2129. PMAC_TYPE_POWERMAC_G5_U3L, g5_features,
  2130. 0,
  2131. },
  2132. { "PowerMac11,2", "PowerMac G5 Dual Core",
  2133. PMAC_TYPE_POWERMAC_G5_U3L, g5_features,
  2134. 0,
  2135. },
  2136. { "PowerMac12,1", "iMac G5 (iSight)",
  2137. PMAC_TYPE_POWERMAC_G5_U3L, g5_features,
  2138. 0,
  2139. },
  2140. { "RackMac3,1", "XServe G5",
  2141. PMAC_TYPE_XSERVE_G5, g5_features,
  2142. 0,
  2143. },
  2144. #endif /* CONFIG_PPC64 */
  2145. #endif /* CONFIG_POWER4 */
  2146. };
  2147. /*
  2148. * The toplevel feature_call callback
  2149. */
  2150. long pmac_do_feature_call(unsigned int selector, ...)
  2151. {
  2152. struct device_node *node;
  2153. long param, value;
  2154. int i;
  2155. feature_call func = NULL;
  2156. va_list args;
  2157. if (pmac_mb.features)
  2158. for (i=0; pmac_mb.features[i].function; i++)
  2159. if (pmac_mb.features[i].selector == selector) {
  2160. func = pmac_mb.features[i].function;
  2161. break;
  2162. }
  2163. if (!func)
  2164. for (i=0; any_features[i].function; i++)
  2165. if (any_features[i].selector == selector) {
  2166. func = any_features[i].function;
  2167. break;
  2168. }
  2169. if (!func)
  2170. return -ENODEV;
  2171. va_start(args, selector);
  2172. node = (struct device_node*)va_arg(args, void*);
  2173. param = va_arg(args, long);
  2174. value = va_arg(args, long);
  2175. va_end(args);
  2176. return func(node, param, value);
  2177. }
  2178. static int __init probe_motherboard(void)
  2179. {
  2180. int i;
  2181. struct macio_chip *macio = &macio_chips[0];
  2182. const char *model = NULL;
  2183. struct device_node *dt;
  2184. int ret = 0;
  2185. /* Lookup known motherboard type in device-tree. First try an
  2186. * exact match on the "model" property, then try a "compatible"
  2187. * match is none is found.
  2188. */
  2189. dt = of_find_node_by_name(NULL, "device-tree");
  2190. if (dt != NULL)
  2191. model = of_get_property(dt, "model", NULL);
  2192. for(i=0; model && i<ARRAY_SIZE(pmac_mb_defs); i++) {
  2193. if (strcmp(model, pmac_mb_defs[i].model_string) == 0) {
  2194. pmac_mb = pmac_mb_defs[i];
  2195. goto found;
  2196. }
  2197. }
  2198. for(i=0; i<ARRAY_SIZE(pmac_mb_defs); i++) {
  2199. if (machine_is_compatible(pmac_mb_defs[i].model_string)) {
  2200. pmac_mb = pmac_mb_defs[i];
  2201. goto found;
  2202. }
  2203. }
  2204. /* Fallback to selection depending on mac-io chip type */
  2205. switch(macio->type) {
  2206. #ifndef CONFIG_POWER4
  2207. case macio_grand_central:
  2208. pmac_mb.model_id = PMAC_TYPE_PSURGE;
  2209. pmac_mb.model_name = "Unknown PowerSurge";
  2210. break;
  2211. case macio_ohare:
  2212. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_OHARE;
  2213. pmac_mb.model_name = "Unknown OHare-based";
  2214. break;
  2215. case macio_heathrow:
  2216. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_HEATHROW;
  2217. pmac_mb.model_name = "Unknown Heathrow-based";
  2218. pmac_mb.features = heathrow_desktop_features;
  2219. break;
  2220. case macio_paddington:
  2221. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_PADDINGTON;
  2222. pmac_mb.model_name = "Unknown Paddington-based";
  2223. pmac_mb.features = paddington_features;
  2224. break;
  2225. case macio_keylargo:
  2226. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_CORE99;
  2227. pmac_mb.model_name = "Unknown Keylargo-based";
  2228. pmac_mb.features = core99_features;
  2229. break;
  2230. case macio_pangea:
  2231. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_PANGEA;
  2232. pmac_mb.model_name = "Unknown Pangea-based";
  2233. pmac_mb.features = pangea_features;
  2234. break;
  2235. case macio_intrepid:
  2236. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_INTREPID;
  2237. pmac_mb.model_name = "Unknown Intrepid-based";
  2238. pmac_mb.features = intrepid_features;
  2239. break;
  2240. #else /* CONFIG_POWER4 */
  2241. case macio_keylargo2:
  2242. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_K2;
  2243. pmac_mb.model_name = "Unknown K2-based";
  2244. pmac_mb.features = g5_features;
  2245. break;
  2246. case macio_shasta:
  2247. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_SHASTA;
  2248. pmac_mb.model_name = "Unknown Shasta-based";
  2249. pmac_mb.features = g5_features;
  2250. break;
  2251. #endif /* CONFIG_POWER4 */
  2252. default:
  2253. ret = -ENODEV;
  2254. goto done;
  2255. }
  2256. found:
  2257. #ifndef CONFIG_POWER4
  2258. /* Fixup Hooper vs. Comet */
  2259. if (pmac_mb.model_id == PMAC_TYPE_HOOPER) {
  2260. u32 __iomem * mach_id_ptr = ioremap(0xf3000034, 4);
  2261. if (!mach_id_ptr) {
  2262. ret = -ENODEV;
  2263. goto done;
  2264. }
  2265. /* Here, I used to disable the media-bay on comet. It
  2266. * appears this is wrong, the floppy connector is actually
  2267. * a kind of media-bay and works with the current driver.
  2268. */
  2269. if (__raw_readl(mach_id_ptr) & 0x20000000UL)
  2270. pmac_mb.model_id = PMAC_TYPE_COMET;
  2271. iounmap(mach_id_ptr);
  2272. }
  2273. /* Set default value of powersave_nap on machines that support it.
  2274. * It appears that uninorth rev 3 has a problem with it, we don't
  2275. * enable it on those. In theory, the flush-on-lock property is
  2276. * supposed to be set when not supported, but I'm not very confident
  2277. * that all Apple OF revs did it properly, I do it the paranoid way.
  2278. */
  2279. while (uninorth_base && uninorth_rev > 3) {
  2280. struct device_node *cpus = of_find_node_by_path("/cpus");
  2281. struct device_node *np;
  2282. if (!cpus || !cpus->child) {
  2283. printk(KERN_WARNING "Can't find CPU(s) in device tree !\n");
  2284. of_node_put(cpus);
  2285. break;
  2286. }
  2287. np = cpus->child;
  2288. /* Nap mode not supported on SMP */
  2289. if (np->sibling) {
  2290. of_node_put(cpus);
  2291. break;
  2292. }
  2293. /* Nap mode not supported if flush-on-lock property is present */
  2294. if (of_get_property(np, "flush-on-lock", NULL)) {
  2295. of_node_put(cpus);
  2296. break;
  2297. }
  2298. of_node_put(cpus);
  2299. powersave_nap = 1;
  2300. printk(KERN_DEBUG "Processor NAP mode on idle enabled.\n");
  2301. break;
  2302. }
  2303. /* On CPUs that support it (750FX), lowspeed by default during
  2304. * NAP mode
  2305. */
  2306. powersave_lowspeed = 1;
  2307. #else /* CONFIG_POWER4 */
  2308. powersave_nap = 1;
  2309. #endif /* CONFIG_POWER4 */
  2310. /* Check for "mobile" machine */
  2311. if (model && (strncmp(model, "PowerBook", 9) == 0
  2312. || strncmp(model, "iBook", 5) == 0))
  2313. pmac_mb.board_flags |= PMAC_MB_MOBILE;
  2314. printk(KERN_INFO "PowerMac motherboard: %s\n", pmac_mb.model_name);
  2315. done:
  2316. of_node_put(dt);
  2317. return ret;
  2318. }
  2319. /* Initialize the Core99 UniNorth host bridge and memory controller
  2320. */
  2321. static void __init probe_uninorth(void)
  2322. {
  2323. const u32 *addrp;
  2324. phys_addr_t address;
  2325. unsigned long actrl;
  2326. /* Locate core99 Uni-N */
  2327. uninorth_node = of_find_node_by_name(NULL, "uni-n");
  2328. uninorth_maj = 1;
  2329. /* Locate G5 u3 */
  2330. if (uninorth_node == NULL) {
  2331. uninorth_node = of_find_node_by_name(NULL, "u3");
  2332. uninorth_maj = 3;
  2333. }
  2334. /* Locate G5 u4 */
  2335. if (uninorth_node == NULL) {
  2336. uninorth_node = of_find_node_by_name(NULL, "u4");
  2337. uninorth_maj = 4;
  2338. }
  2339. if (uninorth_node == NULL) {
  2340. uninorth_maj = 0;
  2341. return;
  2342. }
  2343. addrp = of_get_property(uninorth_node, "reg", NULL);
  2344. if (addrp == NULL)
  2345. return;
  2346. address = of_translate_address(uninorth_node, addrp);
  2347. if (address == 0)
  2348. return;
  2349. uninorth_base = ioremap(address, 0x40000);
  2350. if (uninorth_base == NULL)
  2351. return;
  2352. uninorth_rev = in_be32(UN_REG(UNI_N_VERSION));
  2353. if (uninorth_maj == 3 || uninorth_maj == 4) {
  2354. u3_ht_base = ioremap(address + U3_HT_CONFIG_BASE, 0x1000);
  2355. if (u3_ht_base == NULL) {
  2356. iounmap(uninorth_base);
  2357. return;
  2358. }
  2359. }
  2360. printk(KERN_INFO "Found %s memory controller & host bridge"
  2361. " @ 0x%08x revision: 0x%02x\n", uninorth_maj == 3 ? "U3" :
  2362. uninorth_maj == 4 ? "U4" : "UniNorth",
  2363. (unsigned int)address, uninorth_rev);
  2364. printk(KERN_INFO "Mapped at 0x%08lx\n", (unsigned long)uninorth_base);
  2365. /* Set the arbitrer QAck delay according to what Apple does
  2366. */
  2367. if (uninorth_rev < 0x11) {
  2368. actrl = UN_IN(UNI_N_ARB_CTRL) & ~UNI_N_ARB_CTRL_QACK_DELAY_MASK;
  2369. actrl |= ((uninorth_rev < 3) ? UNI_N_ARB_CTRL_QACK_DELAY105 :
  2370. UNI_N_ARB_CTRL_QACK_DELAY) <<
  2371. UNI_N_ARB_CTRL_QACK_DELAY_SHIFT;
  2372. UN_OUT(UNI_N_ARB_CTRL, actrl);
  2373. }
  2374. /* Some more magic as done by them in recent MacOS X on UniNorth
  2375. * revs 1.5 to 2.O and Pangea. Seem to toggle the UniN Maxbus/PCI
  2376. * memory timeout
  2377. */
  2378. if ((uninorth_rev >= 0x11 && uninorth_rev <= 0x24) ||
  2379. uninorth_rev == 0xc0)
  2380. UN_OUT(0x2160, UN_IN(0x2160) & 0x00ffffff);
  2381. }
  2382. static void __init probe_one_macio(const char *name, const char *compat, int type)
  2383. {
  2384. struct device_node* node;
  2385. int i;
  2386. volatile u32 __iomem *base;
  2387. const u32 *addrp, *revp;
  2388. phys_addr_t addr;
  2389. u64 size;
  2390. for (node = NULL; (node = of_find_node_by_name(node, name)) != NULL;) {
  2391. if (!compat)
  2392. break;
  2393. if (of_device_is_compatible(node, compat))
  2394. break;
  2395. }
  2396. if (!node)
  2397. return;
  2398. for(i=0; i<MAX_MACIO_CHIPS; i++) {
  2399. if (!macio_chips[i].of_node)
  2400. break;
  2401. if (macio_chips[i].of_node == node)
  2402. return;
  2403. }
  2404. if (i >= MAX_MACIO_CHIPS) {
  2405. printk(KERN_ERR "pmac_feature: Please increase MAX_MACIO_CHIPS !\n");
  2406. printk(KERN_ERR "pmac_feature: %s skipped\n", node->full_name);
  2407. return;
  2408. }
  2409. addrp = of_get_pci_address(node, 0, &size, NULL);
  2410. if (addrp == NULL) {
  2411. printk(KERN_ERR "pmac_feature: %s: can't find base !\n",
  2412. node->full_name);
  2413. return;
  2414. }
  2415. addr = of_translate_address(node, addrp);
  2416. if (addr == 0) {
  2417. printk(KERN_ERR "pmac_feature: %s, can't translate base !\n",
  2418. node->full_name);
  2419. return;
  2420. }
  2421. base = ioremap(addr, (unsigned long)size);
  2422. if (!base) {
  2423. printk(KERN_ERR "pmac_feature: %s, can't map mac-io chip !\n",
  2424. node->full_name);
  2425. return;
  2426. }
  2427. if (type == macio_keylargo || type == macio_keylargo2) {
  2428. const u32 *did = of_get_property(node, "device-id", NULL);
  2429. if (*did == 0x00000025)
  2430. type = macio_pangea;
  2431. if (*did == 0x0000003e)
  2432. type = macio_intrepid;
  2433. if (*did == 0x0000004f)
  2434. type = macio_shasta;
  2435. }
  2436. macio_chips[i].of_node = node;
  2437. macio_chips[i].type = type;
  2438. macio_chips[i].base = base;
  2439. macio_chips[i].flags = MACIO_FLAG_SCCA_ON | MACIO_FLAG_SCCB_ON;
  2440. macio_chips[i].name = macio_names[type];
  2441. revp = of_get_property(node, "revision-id", NULL);
  2442. if (revp)
  2443. macio_chips[i].rev = *revp;
  2444. printk(KERN_INFO "Found a %s mac-io controller, rev: %d, mapped at 0x%p\n",
  2445. macio_names[type], macio_chips[i].rev, macio_chips[i].base);
  2446. }
  2447. static int __init
  2448. probe_macios(void)
  2449. {
  2450. /* Warning, ordering is important */
  2451. probe_one_macio("gc", NULL, macio_grand_central);
  2452. probe_one_macio("ohare", NULL, macio_ohare);
  2453. probe_one_macio("pci106b,7", NULL, macio_ohareII);
  2454. probe_one_macio("mac-io", "keylargo", macio_keylargo);
  2455. probe_one_macio("mac-io", "paddington", macio_paddington);
  2456. probe_one_macio("mac-io", "gatwick", macio_gatwick);
  2457. probe_one_macio("mac-io", "heathrow", macio_heathrow);
  2458. probe_one_macio("mac-io", "K2-Keylargo", macio_keylargo2);
  2459. /* Make sure the "main" macio chip appear first */
  2460. if (macio_chips[0].type == macio_gatwick
  2461. && macio_chips[1].type == macio_heathrow) {
  2462. struct macio_chip temp = macio_chips[0];
  2463. macio_chips[0] = macio_chips[1];
  2464. macio_chips[1] = temp;
  2465. }
  2466. if (macio_chips[0].type == macio_ohareII
  2467. && macio_chips[1].type == macio_ohare) {
  2468. struct macio_chip temp = macio_chips[0];
  2469. macio_chips[0] = macio_chips[1];
  2470. macio_chips[1] = temp;
  2471. }
  2472. macio_chips[0].lbus.index = 0;
  2473. macio_chips[1].lbus.index = 1;
  2474. return (macio_chips[0].of_node == NULL) ? -ENODEV : 0;
  2475. }
  2476. static void __init
  2477. initial_serial_shutdown(struct device_node *np)
  2478. {
  2479. int len;
  2480. const struct slot_names_prop {
  2481. int count;
  2482. char name[1];
  2483. } *slots;
  2484. const char *conn;
  2485. int port_type = PMAC_SCC_ASYNC;
  2486. int modem = 0;
  2487. slots = of_get_property(np, "slot-names", &len);
  2488. conn = of_get_property(np, "AAPL,connector", &len);
  2489. if (conn && (strcmp(conn, "infrared") == 0))
  2490. port_type = PMAC_SCC_IRDA;
  2491. else if (of_device_is_compatible(np, "cobalt"))
  2492. modem = 1;
  2493. else if (slots && slots->count > 0) {
  2494. if (strcmp(slots->name, "IrDA") == 0)
  2495. port_type = PMAC_SCC_IRDA;
  2496. else if (strcmp(slots->name, "Modem") == 0)
  2497. modem = 1;
  2498. }
  2499. if (modem)
  2500. pmac_call_feature(PMAC_FTR_MODEM_ENABLE, np, 0, 0);
  2501. pmac_call_feature(PMAC_FTR_SCC_ENABLE, np, port_type, 0);
  2502. }
  2503. static void __init
  2504. set_initial_features(void)
  2505. {
  2506. struct device_node *np;
  2507. /* That hack appears to be necessary for some StarMax motherboards
  2508. * but I'm not too sure it was audited for side-effects on other
  2509. * ohare based machines...
  2510. * Since I still have difficulties figuring the right way to
  2511. * differenciate them all and since that hack was there for a long
  2512. * time, I'll keep it around
  2513. */
  2514. if (macio_chips[0].type == macio_ohare) {
  2515. struct macio_chip *macio = &macio_chips[0];
  2516. np = of_find_node_by_name(NULL, "via-pmu");
  2517. if (np)
  2518. MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
  2519. else
  2520. MACIO_OUT32(OHARE_FCR, STARMAX_FEATURES);
  2521. of_node_put(np);
  2522. } else if (macio_chips[1].type == macio_ohare) {
  2523. struct macio_chip *macio = &macio_chips[1];
  2524. MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
  2525. }
  2526. #ifdef CONFIG_POWER4
  2527. if (macio_chips[0].type == macio_keylargo2 ||
  2528. macio_chips[0].type == macio_shasta) {
  2529. #ifndef CONFIG_SMP
  2530. /* On SMP machines running UP, we have the second CPU eating
  2531. * bus cycles. We need to take it off the bus. This is done
  2532. * from pmac_smp for SMP kernels running on one CPU
  2533. */
  2534. np = of_find_node_by_type(NULL, "cpu");
  2535. if (np != NULL)
  2536. np = of_find_node_by_type(np, "cpu");
  2537. if (np != NULL) {
  2538. g5_phy_disable_cpu1();
  2539. of_node_put(np);
  2540. }
  2541. #endif /* CONFIG_SMP */
  2542. /* Enable GMAC for now for PCI probing. It will be disabled
  2543. * later on after PCI probe
  2544. */
  2545. np = of_find_node_by_name(NULL, "ethernet");
  2546. while(np) {
  2547. if (of_device_is_compatible(np, "K2-GMAC"))
  2548. g5_gmac_enable(np, 0, 1);
  2549. np = of_find_node_by_name(np, "ethernet");
  2550. }
  2551. /* Enable FW before PCI probe. Will be disabled later on
  2552. * Note: We should have a batter way to check that we are
  2553. * dealing with uninorth internal cell and not a PCI cell
  2554. * on the external PCI. The code below works though.
  2555. */
  2556. np = of_find_node_by_name(NULL, "firewire");
  2557. while(np) {
  2558. if (of_device_is_compatible(np, "pci106b,5811")) {
  2559. macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;
  2560. g5_fw_enable(np, 0, 1);
  2561. }
  2562. np = of_find_node_by_name(np, "firewire");
  2563. }
  2564. }
  2565. #else /* CONFIG_POWER4 */
  2566. if (macio_chips[0].type == macio_keylargo ||
  2567. macio_chips[0].type == macio_pangea ||
  2568. macio_chips[0].type == macio_intrepid) {
  2569. /* Enable GMAC for now for PCI probing. It will be disabled
  2570. * later on after PCI probe
  2571. */
  2572. np = of_find_node_by_name(NULL, "ethernet");
  2573. while(np) {
  2574. if (np->parent
  2575. && of_device_is_compatible(np->parent, "uni-north")
  2576. && of_device_is_compatible(np, "gmac"))
  2577. core99_gmac_enable(np, 0, 1);
  2578. np = of_find_node_by_name(np, "ethernet");
  2579. }
  2580. /* Enable FW before PCI probe. Will be disabled later on
  2581. * Note: We should have a batter way to check that we are
  2582. * dealing with uninorth internal cell and not a PCI cell
  2583. * on the external PCI. The code below works though.
  2584. */
  2585. np = of_find_node_by_name(NULL, "firewire");
  2586. while(np) {
  2587. if (np->parent
  2588. && of_device_is_compatible(np->parent, "uni-north")
  2589. && (of_device_is_compatible(np, "pci106b,18") ||
  2590. of_device_is_compatible(np, "pci106b,30") ||
  2591. of_device_is_compatible(np, "pci11c1,5811"))) {
  2592. macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;
  2593. core99_firewire_enable(np, 0, 1);
  2594. }
  2595. np = of_find_node_by_name(np, "firewire");
  2596. }
  2597. /* Enable ATA-100 before PCI probe. */
  2598. np = of_find_node_by_name(NULL, "ata-6");
  2599. while(np) {
  2600. if (np->parent
  2601. && of_device_is_compatible(np->parent, "uni-north")
  2602. && of_device_is_compatible(np, "kauai-ata")) {
  2603. core99_ata100_enable(np, 1);
  2604. }
  2605. np = of_find_node_by_name(np, "ata-6");
  2606. }
  2607. /* Switch airport off */
  2608. for_each_node_by_name(np, "radio") {
  2609. if (np && np->parent == macio_chips[0].of_node) {
  2610. macio_chips[0].flags |= MACIO_FLAG_AIRPORT_ON;
  2611. core99_airport_enable(np, 0, 0);
  2612. }
  2613. }
  2614. of_node_put(np);
  2615. }
  2616. /* On all machines that support sound PM, switch sound off */
  2617. if (macio_chips[0].of_node)
  2618. pmac_do_feature_call(PMAC_FTR_SOUND_CHIP_ENABLE,
  2619. macio_chips[0].of_node, 0, 0);
  2620. /* While on some desktop G3s, we turn it back on */
  2621. if (macio_chips[0].of_node && macio_chips[0].type == macio_heathrow
  2622. && (pmac_mb.model_id == PMAC_TYPE_GOSSAMER ||
  2623. pmac_mb.model_id == PMAC_TYPE_SILK)) {
  2624. struct macio_chip *macio = &macio_chips[0];
  2625. MACIO_BIS(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
  2626. MACIO_BIC(HEATHROW_FCR, HRW_SOUND_POWER_N);
  2627. }
  2628. #endif /* CONFIG_POWER4 */
  2629. /* On all machines, switch modem & serial ports off */
  2630. for_each_node_by_name(np, "ch-a")
  2631. initial_serial_shutdown(np);
  2632. of_node_put(np);
  2633. for_each_node_by_name(np, "ch-b")
  2634. initial_serial_shutdown(np);
  2635. of_node_put(np);
  2636. }
  2637. void __init
  2638. pmac_feature_init(void)
  2639. {
  2640. /* Detect the UniNorth memory controller */
  2641. probe_uninorth();
  2642. /* Probe mac-io controllers */
  2643. if (probe_macios()) {
  2644. printk(KERN_WARNING "No mac-io chip found\n");
  2645. return;
  2646. }
  2647. /* Probe machine type */
  2648. if (probe_motherboard())
  2649. printk(KERN_WARNING "Unknown PowerMac !\n");
  2650. /* Set some initial features (turn off some chips that will
  2651. * be later turned on)
  2652. */
  2653. set_initial_features();
  2654. }
  2655. #if 0
  2656. static void dump_HT_speeds(char *name, u32 cfg, u32 frq)
  2657. {
  2658. int freqs[16] = { 200,300,400,500,600,800,1000,0,0,0,0,0,0,0,0,0 };
  2659. int bits[8] = { 8,16,0,32,2,4,0,0 };
  2660. int freq = (frq >> 8) & 0xf;
  2661. if (freqs[freq] == 0)
  2662. printk("%s: Unknown HT link frequency %x\n", name, freq);
  2663. else
  2664. printk("%s: %d MHz on main link, (%d in / %d out) bits width\n",
  2665. name, freqs[freq],
  2666. bits[(cfg >> 28) & 0x7], bits[(cfg >> 24) & 0x7]);
  2667. }
  2668. void __init pmac_check_ht_link(void)
  2669. {
  2670. u32 ufreq, freq, ucfg, cfg;
  2671. struct device_node *pcix_node;
  2672. u8 px_bus, px_devfn;
  2673. struct pci_controller *px_hose;
  2674. (void)in_be32(u3_ht_base + U3_HT_LINK_COMMAND);
  2675. ucfg = cfg = in_be32(u3_ht_base + U3_HT_LINK_CONFIG);
  2676. ufreq = freq = in_be32(u3_ht_base + U3_HT_LINK_FREQ);
  2677. dump_HT_speeds("U3 HyperTransport", cfg, freq);
  2678. pcix_node = of_find_compatible_node(NULL, "pci", "pci-x");
  2679. if (pcix_node == NULL) {
  2680. printk("No PCI-X bridge found\n");
  2681. return;
  2682. }
  2683. if (pci_device_from_OF_node(pcix_node, &px_bus, &px_devfn) != 0) {
  2684. printk("PCI-X bridge found but not matched to pci\n");
  2685. return;
  2686. }
  2687. px_hose = pci_find_hose_for_OF_device(pcix_node);
  2688. if (px_hose == NULL) {
  2689. printk("PCI-X bridge found but not matched to host\n");
  2690. return;
  2691. }
  2692. early_read_config_dword(px_hose, px_bus, px_devfn, 0xc4, &cfg);
  2693. early_read_config_dword(px_hose, px_bus, px_devfn, 0xcc, &freq);
  2694. dump_HT_speeds("PCI-X HT Uplink", cfg, freq);
  2695. early_read_config_dword(px_hose, px_bus, px_devfn, 0xc8, &cfg);
  2696. early_read_config_dword(px_hose, px_bus, px_devfn, 0xd0, &freq);
  2697. dump_HT_speeds("PCI-X HT Downlink", cfg, freq);
  2698. }
  2699. #endif /* 0 */
  2700. /*
  2701. * Early video resume hook
  2702. */
  2703. static void (*pmac_early_vresume_proc)(void *data);
  2704. static void *pmac_early_vresume_data;
  2705. void pmac_set_early_video_resume(void (*proc)(void *data), void *data)
  2706. {
  2707. if (!machine_is(powermac))
  2708. return;
  2709. preempt_disable();
  2710. pmac_early_vresume_proc = proc;
  2711. pmac_early_vresume_data = data;
  2712. preempt_enable();
  2713. }
  2714. EXPORT_SYMBOL(pmac_set_early_video_resume);
  2715. void pmac_call_early_video_resume(void)
  2716. {
  2717. if (pmac_early_vresume_proc)
  2718. pmac_early_vresume_proc(pmac_early_vresume_data);
  2719. }
  2720. /*
  2721. * AGP related suspend/resume code
  2722. */
  2723. static struct pci_dev *pmac_agp_bridge;
  2724. static int (*pmac_agp_suspend)(struct pci_dev *bridge);
  2725. static int (*pmac_agp_resume)(struct pci_dev *bridge);
  2726. void pmac_register_agp_pm(struct pci_dev *bridge,
  2727. int (*suspend)(struct pci_dev *bridge),
  2728. int (*resume)(struct pci_dev *bridge))
  2729. {
  2730. if (suspend || resume) {
  2731. pmac_agp_bridge = bridge;
  2732. pmac_agp_suspend = suspend;
  2733. pmac_agp_resume = resume;
  2734. return;
  2735. }
  2736. if (bridge != pmac_agp_bridge)
  2737. return;
  2738. pmac_agp_suspend = pmac_agp_resume = NULL;
  2739. return;
  2740. }
  2741. EXPORT_SYMBOL(pmac_register_agp_pm);
  2742. void pmac_suspend_agp_for_card(struct pci_dev *dev)
  2743. {
  2744. if (pmac_agp_bridge == NULL || pmac_agp_suspend == NULL)
  2745. return;
  2746. if (pmac_agp_bridge->bus != dev->bus)
  2747. return;
  2748. pmac_agp_suspend(pmac_agp_bridge);
  2749. }
  2750. EXPORT_SYMBOL(pmac_suspend_agp_for_card);
  2751. void pmac_resume_agp_for_card(struct pci_dev *dev)
  2752. {
  2753. if (pmac_agp_bridge == NULL || pmac_agp_resume == NULL)
  2754. return;
  2755. if (pmac_agp_bridge->bus != dev->bus)
  2756. return;
  2757. pmac_agp_resume(pmac_agp_bridge);
  2758. }
  2759. EXPORT_SYMBOL(pmac_resume_agp_for_card);
  2760. int pmac_get_uninorth_variant(void)
  2761. {
  2762. return uninorth_maj;
  2763. }