feature.c 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029
  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_find_slot(pbus, pid);
  761. if (pdev == NULL)
  762. return 0;
  763. rc = pci_enable_device(pdev);
  764. if (rc)
  765. return rc;
  766. pci_set_master(pdev);
  767. }
  768. return 0;
  769. }
  770. static long
  771. core99_ide_enable(struct device_node *node, long param, long value)
  772. {
  773. /* Bus ID 0 to 2 are KeyLargo based IDE, busID 3 is U2
  774. * based ata-100
  775. */
  776. switch(param) {
  777. case 0:
  778. return simple_feature_tweak(node, macio_unknown,
  779. KEYLARGO_FCR1, KL1_EIDE0_ENABLE, value);
  780. case 1:
  781. return simple_feature_tweak(node, macio_unknown,
  782. KEYLARGO_FCR1, KL1_EIDE1_ENABLE, value);
  783. case 2:
  784. return simple_feature_tweak(node, macio_unknown,
  785. KEYLARGO_FCR1, KL1_UIDE_ENABLE, value);
  786. case 3:
  787. return core99_ata100_enable(node, value);
  788. default:
  789. return -ENODEV;
  790. }
  791. }
  792. static long
  793. core99_ide_reset(struct device_node *node, long param, long value)
  794. {
  795. switch(param) {
  796. case 0:
  797. return simple_feature_tweak(node, macio_unknown,
  798. KEYLARGO_FCR1, KL1_EIDE0_RESET_N, !value);
  799. case 1:
  800. return simple_feature_tweak(node, macio_unknown,
  801. KEYLARGO_FCR1, KL1_EIDE1_RESET_N, !value);
  802. case 2:
  803. return simple_feature_tweak(node, macio_unknown,
  804. KEYLARGO_FCR1, KL1_UIDE_RESET_N, !value);
  805. default:
  806. return -ENODEV;
  807. }
  808. }
  809. static long
  810. core99_gmac_enable(struct device_node *node, long param, long value)
  811. {
  812. unsigned long flags;
  813. LOCK(flags);
  814. if (value)
  815. UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_GMAC);
  816. else
  817. UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_GMAC);
  818. (void)UN_IN(UNI_N_CLOCK_CNTL);
  819. UNLOCK(flags);
  820. udelay(20);
  821. return 0;
  822. }
  823. static long
  824. core99_gmac_phy_reset(struct device_node *node, long param, long value)
  825. {
  826. unsigned long flags;
  827. struct macio_chip *macio;
  828. macio = &macio_chips[0];
  829. if (macio->type != macio_keylargo && macio->type != macio_pangea &&
  830. macio->type != macio_intrepid)
  831. return -ENODEV;
  832. LOCK(flags);
  833. MACIO_OUT8(KL_GPIO_ETH_PHY_RESET, KEYLARGO_GPIO_OUTPUT_ENABLE);
  834. (void)MACIO_IN8(KL_GPIO_ETH_PHY_RESET);
  835. UNLOCK(flags);
  836. mdelay(10);
  837. LOCK(flags);
  838. MACIO_OUT8(KL_GPIO_ETH_PHY_RESET, /*KEYLARGO_GPIO_OUTPUT_ENABLE | */
  839. KEYLARGO_GPIO_OUTOUT_DATA);
  840. UNLOCK(flags);
  841. mdelay(10);
  842. return 0;
  843. }
  844. static long
  845. core99_sound_chip_enable(struct device_node *node, long param, long value)
  846. {
  847. struct macio_chip* macio;
  848. unsigned long flags;
  849. macio = macio_find(node, 0);
  850. if (!macio)
  851. return -ENODEV;
  852. /* Do a better probe code, screamer G4 desktops &
  853. * iMacs can do that too, add a recalibrate in
  854. * the driver as well
  855. */
  856. if (pmac_mb.model_id == PMAC_TYPE_PISMO ||
  857. pmac_mb.model_id == PMAC_TYPE_TITANIUM) {
  858. LOCK(flags);
  859. if (value)
  860. MACIO_OUT8(KL_GPIO_SOUND_POWER,
  861. KEYLARGO_GPIO_OUTPUT_ENABLE |
  862. KEYLARGO_GPIO_OUTOUT_DATA);
  863. else
  864. MACIO_OUT8(KL_GPIO_SOUND_POWER,
  865. KEYLARGO_GPIO_OUTPUT_ENABLE);
  866. (void)MACIO_IN8(KL_GPIO_SOUND_POWER);
  867. UNLOCK(flags);
  868. }
  869. return 0;
  870. }
  871. static long
  872. core99_airport_enable(struct device_node *node, long param, long value)
  873. {
  874. struct macio_chip* macio;
  875. unsigned long flags;
  876. int state;
  877. macio = macio_find(node, 0);
  878. if (!macio)
  879. return -ENODEV;
  880. /* Hint: we allow passing of macio itself for the sake of the
  881. * sleep code
  882. */
  883. if (node != macio->of_node &&
  884. (!node->parent || node->parent != macio->of_node))
  885. return -ENODEV;
  886. state = (macio->flags & MACIO_FLAG_AIRPORT_ON) != 0;
  887. if (value == state)
  888. return 0;
  889. if (value) {
  890. /* This code is a reproduction of OF enable-cardslot
  891. * and init-wireless methods, slightly hacked until
  892. * I got it working.
  893. */
  894. LOCK(flags);
  895. MACIO_OUT8(KEYLARGO_GPIO_0+0xf, 5);
  896. (void)MACIO_IN8(KEYLARGO_GPIO_0+0xf);
  897. UNLOCK(flags);
  898. mdelay(10);
  899. LOCK(flags);
  900. MACIO_OUT8(KEYLARGO_GPIO_0+0xf, 4);
  901. (void)MACIO_IN8(KEYLARGO_GPIO_0+0xf);
  902. UNLOCK(flags);
  903. mdelay(10);
  904. LOCK(flags);
  905. MACIO_BIC(KEYLARGO_FCR2, KL2_CARDSEL_16);
  906. (void)MACIO_IN32(KEYLARGO_FCR2);
  907. udelay(10);
  908. MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xb, 0);
  909. (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xb);
  910. udelay(10);
  911. MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xa, 0x28);
  912. (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xa);
  913. udelay(10);
  914. MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xd, 0x28);
  915. (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xd);
  916. udelay(10);
  917. MACIO_OUT8(KEYLARGO_GPIO_0+0xd, 0x28);
  918. (void)MACIO_IN8(KEYLARGO_GPIO_0+0xd);
  919. udelay(10);
  920. MACIO_OUT8(KEYLARGO_GPIO_0+0xe, 0x28);
  921. (void)MACIO_IN8(KEYLARGO_GPIO_0+0xe);
  922. UNLOCK(flags);
  923. udelay(10);
  924. MACIO_OUT32(0x1c000, 0);
  925. mdelay(1);
  926. MACIO_OUT8(0x1a3e0, 0x41);
  927. (void)MACIO_IN8(0x1a3e0);
  928. udelay(10);
  929. LOCK(flags);
  930. MACIO_BIS(KEYLARGO_FCR2, KL2_CARDSEL_16);
  931. (void)MACIO_IN32(KEYLARGO_FCR2);
  932. UNLOCK(flags);
  933. mdelay(100);
  934. macio->flags |= MACIO_FLAG_AIRPORT_ON;
  935. } else {
  936. LOCK(flags);
  937. MACIO_BIC(KEYLARGO_FCR2, KL2_CARDSEL_16);
  938. (void)MACIO_IN32(KEYLARGO_FCR2);
  939. MACIO_OUT8(KL_GPIO_AIRPORT_0, 0);
  940. MACIO_OUT8(KL_GPIO_AIRPORT_1, 0);
  941. MACIO_OUT8(KL_GPIO_AIRPORT_2, 0);
  942. MACIO_OUT8(KL_GPIO_AIRPORT_3, 0);
  943. MACIO_OUT8(KL_GPIO_AIRPORT_4, 0);
  944. (void)MACIO_IN8(KL_GPIO_AIRPORT_4);
  945. UNLOCK(flags);
  946. macio->flags &= ~MACIO_FLAG_AIRPORT_ON;
  947. }
  948. return 0;
  949. }
  950. #ifdef CONFIG_SMP
  951. static long
  952. core99_reset_cpu(struct device_node *node, long param, long value)
  953. {
  954. unsigned int reset_io = 0;
  955. unsigned long flags;
  956. struct macio_chip *macio;
  957. struct device_node *np;
  958. struct device_node *cpus;
  959. const int dflt_reset_lines[] = { KL_GPIO_RESET_CPU0,
  960. KL_GPIO_RESET_CPU1,
  961. KL_GPIO_RESET_CPU2,
  962. KL_GPIO_RESET_CPU3 };
  963. macio = &macio_chips[0];
  964. if (macio->type != macio_keylargo)
  965. return -ENODEV;
  966. cpus = of_find_node_by_path("/cpus");
  967. if (cpus == NULL)
  968. return -ENODEV;
  969. for (np = cpus->child; np != NULL; np = np->sibling) {
  970. const u32 *num = of_get_property(np, "reg", NULL);
  971. const u32 *rst = of_get_property(np, "soft-reset", NULL);
  972. if (num == NULL || rst == NULL)
  973. continue;
  974. if (param == *num) {
  975. reset_io = *rst;
  976. break;
  977. }
  978. }
  979. of_node_put(cpus);
  980. if (np == NULL || reset_io == 0)
  981. reset_io = dflt_reset_lines[param];
  982. LOCK(flags);
  983. MACIO_OUT8(reset_io, KEYLARGO_GPIO_OUTPUT_ENABLE);
  984. (void)MACIO_IN8(reset_io);
  985. udelay(1);
  986. MACIO_OUT8(reset_io, 0);
  987. (void)MACIO_IN8(reset_io);
  988. UNLOCK(flags);
  989. return 0;
  990. }
  991. #endif /* CONFIG_SMP */
  992. static long
  993. core99_usb_enable(struct device_node *node, long param, long value)
  994. {
  995. struct macio_chip *macio;
  996. unsigned long flags;
  997. const char *prop;
  998. int number;
  999. u32 reg;
  1000. macio = &macio_chips[0];
  1001. if (macio->type != macio_keylargo && macio->type != macio_pangea &&
  1002. macio->type != macio_intrepid)
  1003. return -ENODEV;
  1004. prop = of_get_property(node, "AAPL,clock-id", NULL);
  1005. if (!prop)
  1006. return -ENODEV;
  1007. if (strncmp(prop, "usb0u048", 8) == 0)
  1008. number = 0;
  1009. else if (strncmp(prop, "usb1u148", 8) == 0)
  1010. number = 2;
  1011. else if (strncmp(prop, "usb2u248", 8) == 0)
  1012. number = 4;
  1013. else
  1014. return -ENODEV;
  1015. /* Sorry for the brute-force locking, but this is only used during
  1016. * sleep and the timing seem to be critical
  1017. */
  1018. LOCK(flags);
  1019. if (value) {
  1020. /* Turn ON */
  1021. if (number == 0) {
  1022. MACIO_BIC(KEYLARGO_FCR0, (KL0_USB0_PAD_SUSPEND0 | KL0_USB0_PAD_SUSPEND1));
  1023. (void)MACIO_IN32(KEYLARGO_FCR0);
  1024. UNLOCK(flags);
  1025. mdelay(1);
  1026. LOCK(flags);
  1027. MACIO_BIS(KEYLARGO_FCR0, KL0_USB0_CELL_ENABLE);
  1028. } else if (number == 2) {
  1029. MACIO_BIC(KEYLARGO_FCR0, (KL0_USB1_PAD_SUSPEND0 | KL0_USB1_PAD_SUSPEND1));
  1030. UNLOCK(flags);
  1031. (void)MACIO_IN32(KEYLARGO_FCR0);
  1032. mdelay(1);
  1033. LOCK(flags);
  1034. MACIO_BIS(KEYLARGO_FCR0, KL0_USB1_CELL_ENABLE);
  1035. } else if (number == 4) {
  1036. MACIO_BIC(KEYLARGO_FCR1, (KL1_USB2_PAD_SUSPEND0 | KL1_USB2_PAD_SUSPEND1));
  1037. UNLOCK(flags);
  1038. (void)MACIO_IN32(KEYLARGO_FCR1);
  1039. mdelay(1);
  1040. LOCK(flags);
  1041. MACIO_BIS(KEYLARGO_FCR1, KL1_USB2_CELL_ENABLE);
  1042. }
  1043. if (number < 4) {
  1044. reg = MACIO_IN32(KEYLARGO_FCR4);
  1045. reg &= ~(KL4_PORT_WAKEUP_ENABLE(number) | KL4_PORT_RESUME_WAKE_EN(number) |
  1046. KL4_PORT_CONNECT_WAKE_EN(number) | KL4_PORT_DISCONNECT_WAKE_EN(number));
  1047. reg &= ~(KL4_PORT_WAKEUP_ENABLE(number+1) | KL4_PORT_RESUME_WAKE_EN(number+1) |
  1048. KL4_PORT_CONNECT_WAKE_EN(number+1) | KL4_PORT_DISCONNECT_WAKE_EN(number+1));
  1049. MACIO_OUT32(KEYLARGO_FCR4, reg);
  1050. (void)MACIO_IN32(KEYLARGO_FCR4);
  1051. udelay(10);
  1052. } else {
  1053. reg = MACIO_IN32(KEYLARGO_FCR3);
  1054. reg &= ~(KL3_IT_PORT_WAKEUP_ENABLE(0) | KL3_IT_PORT_RESUME_WAKE_EN(0) |
  1055. KL3_IT_PORT_CONNECT_WAKE_EN(0) | KL3_IT_PORT_DISCONNECT_WAKE_EN(0));
  1056. reg &= ~(KL3_IT_PORT_WAKEUP_ENABLE(1) | KL3_IT_PORT_RESUME_WAKE_EN(1) |
  1057. KL3_IT_PORT_CONNECT_WAKE_EN(1) | KL3_IT_PORT_DISCONNECT_WAKE_EN(1));
  1058. MACIO_OUT32(KEYLARGO_FCR3, reg);
  1059. (void)MACIO_IN32(KEYLARGO_FCR3);
  1060. udelay(10);
  1061. }
  1062. if (macio->type == macio_intrepid) {
  1063. /* wait for clock stopped bits to clear */
  1064. u32 test0 = 0, test1 = 0;
  1065. u32 status0, status1;
  1066. int timeout = 1000;
  1067. UNLOCK(flags);
  1068. switch (number) {
  1069. case 0:
  1070. test0 = UNI_N_CLOCK_STOPPED_USB0;
  1071. test1 = UNI_N_CLOCK_STOPPED_USB0PCI;
  1072. break;
  1073. case 2:
  1074. test0 = UNI_N_CLOCK_STOPPED_USB1;
  1075. test1 = UNI_N_CLOCK_STOPPED_USB1PCI;
  1076. break;
  1077. case 4:
  1078. test0 = UNI_N_CLOCK_STOPPED_USB2;
  1079. test1 = UNI_N_CLOCK_STOPPED_USB2PCI;
  1080. break;
  1081. }
  1082. do {
  1083. if (--timeout <= 0) {
  1084. printk(KERN_ERR "core99_usb_enable: "
  1085. "Timeout waiting for clocks\n");
  1086. break;
  1087. }
  1088. mdelay(1);
  1089. status0 = UN_IN(UNI_N_CLOCK_STOP_STATUS0);
  1090. status1 = UN_IN(UNI_N_CLOCK_STOP_STATUS1);
  1091. } while ((status0 & test0) | (status1 & test1));
  1092. LOCK(flags);
  1093. }
  1094. } else {
  1095. /* Turn OFF */
  1096. if (number < 4) {
  1097. reg = MACIO_IN32(KEYLARGO_FCR4);
  1098. reg |= KL4_PORT_WAKEUP_ENABLE(number) | KL4_PORT_RESUME_WAKE_EN(number) |
  1099. KL4_PORT_CONNECT_WAKE_EN(number) | KL4_PORT_DISCONNECT_WAKE_EN(number);
  1100. reg |= KL4_PORT_WAKEUP_ENABLE(number+1) | KL4_PORT_RESUME_WAKE_EN(number+1) |
  1101. KL4_PORT_CONNECT_WAKE_EN(number+1) | KL4_PORT_DISCONNECT_WAKE_EN(number+1);
  1102. MACIO_OUT32(KEYLARGO_FCR4, reg);
  1103. (void)MACIO_IN32(KEYLARGO_FCR4);
  1104. udelay(1);
  1105. } else {
  1106. reg = MACIO_IN32(KEYLARGO_FCR3);
  1107. reg |= KL3_IT_PORT_WAKEUP_ENABLE(0) | KL3_IT_PORT_RESUME_WAKE_EN(0) |
  1108. KL3_IT_PORT_CONNECT_WAKE_EN(0) | KL3_IT_PORT_DISCONNECT_WAKE_EN(0);
  1109. reg |= KL3_IT_PORT_WAKEUP_ENABLE(1) | KL3_IT_PORT_RESUME_WAKE_EN(1) |
  1110. KL3_IT_PORT_CONNECT_WAKE_EN(1) | KL3_IT_PORT_DISCONNECT_WAKE_EN(1);
  1111. MACIO_OUT32(KEYLARGO_FCR3, reg);
  1112. (void)MACIO_IN32(KEYLARGO_FCR3);
  1113. udelay(1);
  1114. }
  1115. if (number == 0) {
  1116. if (macio->type != macio_intrepid)
  1117. MACIO_BIC(KEYLARGO_FCR0, KL0_USB0_CELL_ENABLE);
  1118. (void)MACIO_IN32(KEYLARGO_FCR0);
  1119. udelay(1);
  1120. MACIO_BIS(KEYLARGO_FCR0, (KL0_USB0_PAD_SUSPEND0 | KL0_USB0_PAD_SUSPEND1));
  1121. (void)MACIO_IN32(KEYLARGO_FCR0);
  1122. } else if (number == 2) {
  1123. if (macio->type != macio_intrepid)
  1124. MACIO_BIC(KEYLARGO_FCR0, KL0_USB1_CELL_ENABLE);
  1125. (void)MACIO_IN32(KEYLARGO_FCR0);
  1126. udelay(1);
  1127. MACIO_BIS(KEYLARGO_FCR0, (KL0_USB1_PAD_SUSPEND0 | KL0_USB1_PAD_SUSPEND1));
  1128. (void)MACIO_IN32(KEYLARGO_FCR0);
  1129. } else if (number == 4) {
  1130. udelay(1);
  1131. MACIO_BIS(KEYLARGO_FCR1, (KL1_USB2_PAD_SUSPEND0 | KL1_USB2_PAD_SUSPEND1));
  1132. (void)MACIO_IN32(KEYLARGO_FCR1);
  1133. }
  1134. udelay(1);
  1135. }
  1136. UNLOCK(flags);
  1137. return 0;
  1138. }
  1139. static long
  1140. core99_firewire_enable(struct device_node *node, long param, long value)
  1141. {
  1142. unsigned long flags;
  1143. struct macio_chip *macio;
  1144. macio = &macio_chips[0];
  1145. if (macio->type != macio_keylargo && macio->type != macio_pangea &&
  1146. macio->type != macio_intrepid)
  1147. return -ENODEV;
  1148. if (!(macio->flags & MACIO_FLAG_FW_SUPPORTED))
  1149. return -ENODEV;
  1150. LOCK(flags);
  1151. if (value) {
  1152. UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_FW);
  1153. (void)UN_IN(UNI_N_CLOCK_CNTL);
  1154. } else {
  1155. UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_FW);
  1156. (void)UN_IN(UNI_N_CLOCK_CNTL);
  1157. }
  1158. UNLOCK(flags);
  1159. mdelay(1);
  1160. return 0;
  1161. }
  1162. static long
  1163. core99_firewire_cable_power(struct device_node *node, long param, long value)
  1164. {
  1165. unsigned long flags;
  1166. struct macio_chip *macio;
  1167. /* Trick: we allow NULL node */
  1168. if ((pmac_mb.board_flags & PMAC_MB_HAS_FW_POWER) == 0)
  1169. return -ENODEV;
  1170. macio = &macio_chips[0];
  1171. if (macio->type != macio_keylargo && macio->type != macio_pangea &&
  1172. macio->type != macio_intrepid)
  1173. return -ENODEV;
  1174. if (!(macio->flags & MACIO_FLAG_FW_SUPPORTED))
  1175. return -ENODEV;
  1176. LOCK(flags);
  1177. if (value) {
  1178. MACIO_OUT8(KL_GPIO_FW_CABLE_POWER , 0);
  1179. MACIO_IN8(KL_GPIO_FW_CABLE_POWER);
  1180. udelay(10);
  1181. } else {
  1182. MACIO_OUT8(KL_GPIO_FW_CABLE_POWER , 4);
  1183. MACIO_IN8(KL_GPIO_FW_CABLE_POWER); udelay(10);
  1184. }
  1185. UNLOCK(flags);
  1186. mdelay(1);
  1187. return 0;
  1188. }
  1189. static long
  1190. intrepid_aack_delay_enable(struct device_node *node, long param, long value)
  1191. {
  1192. unsigned long flags;
  1193. if (uninorth_rev < 0xd2)
  1194. return -ENODEV;
  1195. LOCK(flags);
  1196. if (param)
  1197. UN_BIS(UNI_N_AACK_DELAY, UNI_N_AACK_DELAY_ENABLE);
  1198. else
  1199. UN_BIC(UNI_N_AACK_DELAY, UNI_N_AACK_DELAY_ENABLE);
  1200. UNLOCK(flags);
  1201. return 0;
  1202. }
  1203. #endif /* CONFIG_POWER4 */
  1204. static long
  1205. core99_read_gpio(struct device_node *node, long param, long value)
  1206. {
  1207. struct macio_chip *macio = &macio_chips[0];
  1208. return MACIO_IN8(param);
  1209. }
  1210. static long
  1211. core99_write_gpio(struct device_node *node, long param, long value)
  1212. {
  1213. struct macio_chip *macio = &macio_chips[0];
  1214. MACIO_OUT8(param, (u8)(value & 0xff));
  1215. return 0;
  1216. }
  1217. #ifdef CONFIG_POWER4
  1218. static long g5_gmac_enable(struct device_node *node, long param, long value)
  1219. {
  1220. struct macio_chip *macio = &macio_chips[0];
  1221. unsigned long flags;
  1222. if (node == NULL)
  1223. return -ENODEV;
  1224. LOCK(flags);
  1225. if (value) {
  1226. MACIO_BIS(KEYLARGO_FCR1, K2_FCR1_GMAC_CLK_ENABLE);
  1227. mb();
  1228. k2_skiplist[0] = NULL;
  1229. } else {
  1230. k2_skiplist[0] = node;
  1231. mb();
  1232. MACIO_BIC(KEYLARGO_FCR1, K2_FCR1_GMAC_CLK_ENABLE);
  1233. }
  1234. UNLOCK(flags);
  1235. mdelay(1);
  1236. return 0;
  1237. }
  1238. static long g5_fw_enable(struct device_node *node, long param, long value)
  1239. {
  1240. struct macio_chip *macio = &macio_chips[0];
  1241. unsigned long flags;
  1242. if (node == NULL)
  1243. return -ENODEV;
  1244. LOCK(flags);
  1245. if (value) {
  1246. MACIO_BIS(KEYLARGO_FCR1, K2_FCR1_FW_CLK_ENABLE);
  1247. mb();
  1248. k2_skiplist[1] = NULL;
  1249. } else {
  1250. k2_skiplist[1] = node;
  1251. mb();
  1252. MACIO_BIC(KEYLARGO_FCR1, K2_FCR1_FW_CLK_ENABLE);
  1253. }
  1254. UNLOCK(flags);
  1255. mdelay(1);
  1256. return 0;
  1257. }
  1258. static long g5_mpic_enable(struct device_node *node, long param, long value)
  1259. {
  1260. unsigned long flags;
  1261. struct device_node *parent = of_get_parent(node);
  1262. int is_u3;
  1263. if (parent == NULL)
  1264. return 0;
  1265. is_u3 = strcmp(parent->name, "u3") == 0 ||
  1266. strcmp(parent->name, "u4") == 0;
  1267. of_node_put(parent);
  1268. if (!is_u3)
  1269. return 0;
  1270. LOCK(flags);
  1271. UN_BIS(U3_TOGGLE_REG, U3_MPIC_RESET | U3_MPIC_OUTPUT_ENABLE);
  1272. UNLOCK(flags);
  1273. return 0;
  1274. }
  1275. static long g5_eth_phy_reset(struct device_node *node, long param, long value)
  1276. {
  1277. struct macio_chip *macio = &macio_chips[0];
  1278. struct device_node *phy;
  1279. int need_reset;
  1280. /*
  1281. * We must not reset the combo PHYs, only the BCM5221 found in
  1282. * the iMac G5.
  1283. */
  1284. phy = of_get_next_child(node, NULL);
  1285. if (!phy)
  1286. return -ENODEV;
  1287. need_reset = of_device_is_compatible(phy, "B5221");
  1288. of_node_put(phy);
  1289. if (!need_reset)
  1290. return 0;
  1291. /* PHY reset is GPIO 29, not in device-tree unfortunately */
  1292. MACIO_OUT8(K2_GPIO_EXTINT_0 + 29,
  1293. KEYLARGO_GPIO_OUTPUT_ENABLE | KEYLARGO_GPIO_OUTOUT_DATA);
  1294. /* Thankfully, this is now always called at a time when we can
  1295. * schedule by sungem.
  1296. */
  1297. msleep(10);
  1298. MACIO_OUT8(K2_GPIO_EXTINT_0 + 29, 0);
  1299. return 0;
  1300. }
  1301. static long g5_i2s_enable(struct device_node *node, long param, long value)
  1302. {
  1303. /* Very crude implementation for now */
  1304. struct macio_chip *macio = &macio_chips[0];
  1305. unsigned long flags;
  1306. int cell;
  1307. u32 fcrs[3][3] = {
  1308. { 0,
  1309. K2_FCR1_I2S0_CELL_ENABLE |
  1310. K2_FCR1_I2S0_CLK_ENABLE_BIT | K2_FCR1_I2S0_ENABLE,
  1311. KL3_I2S0_CLK18_ENABLE
  1312. },
  1313. { KL0_SCC_A_INTF_ENABLE,
  1314. K2_FCR1_I2S1_CELL_ENABLE |
  1315. K2_FCR1_I2S1_CLK_ENABLE_BIT | K2_FCR1_I2S1_ENABLE,
  1316. KL3_I2S1_CLK18_ENABLE
  1317. },
  1318. { KL0_SCC_B_INTF_ENABLE,
  1319. SH_FCR1_I2S2_CELL_ENABLE |
  1320. SH_FCR1_I2S2_CLK_ENABLE_BIT | SH_FCR1_I2S2_ENABLE,
  1321. SH_FCR3_I2S2_CLK18_ENABLE
  1322. },
  1323. };
  1324. if (macio->type != macio_keylargo2 && macio->type != macio_shasta)
  1325. return -ENODEV;
  1326. if (strncmp(node->name, "i2s-", 4))
  1327. return -ENODEV;
  1328. cell = node->name[4] - 'a';
  1329. switch(cell) {
  1330. case 0:
  1331. case 1:
  1332. break;
  1333. case 2:
  1334. if (macio->type == macio_shasta)
  1335. break;
  1336. default:
  1337. return -ENODEV;
  1338. }
  1339. LOCK(flags);
  1340. if (value) {
  1341. MACIO_BIC(KEYLARGO_FCR0, fcrs[cell][0]);
  1342. MACIO_BIS(KEYLARGO_FCR1, fcrs[cell][1]);
  1343. MACIO_BIS(KEYLARGO_FCR3, fcrs[cell][2]);
  1344. } else {
  1345. MACIO_BIC(KEYLARGO_FCR3, fcrs[cell][2]);
  1346. MACIO_BIC(KEYLARGO_FCR1, fcrs[cell][1]);
  1347. MACIO_BIS(KEYLARGO_FCR0, fcrs[cell][0]);
  1348. }
  1349. udelay(10);
  1350. UNLOCK(flags);
  1351. return 0;
  1352. }
  1353. #ifdef CONFIG_SMP
  1354. static long g5_reset_cpu(struct device_node *node, long param, long value)
  1355. {
  1356. unsigned int reset_io = 0;
  1357. unsigned long flags;
  1358. struct macio_chip *macio;
  1359. struct device_node *np;
  1360. struct device_node *cpus;
  1361. macio = &macio_chips[0];
  1362. if (macio->type != macio_keylargo2 && macio->type != macio_shasta)
  1363. return -ENODEV;
  1364. cpus = of_find_node_by_path("/cpus");
  1365. if (cpus == NULL)
  1366. return -ENODEV;
  1367. for (np = cpus->child; np != NULL; np = np->sibling) {
  1368. const u32 *num = of_get_property(np, "reg", NULL);
  1369. const u32 *rst = of_get_property(np, "soft-reset", NULL);
  1370. if (num == NULL || rst == NULL)
  1371. continue;
  1372. if (param == *num) {
  1373. reset_io = *rst;
  1374. break;
  1375. }
  1376. }
  1377. of_node_put(cpus);
  1378. if (np == NULL || reset_io == 0)
  1379. return -ENODEV;
  1380. LOCK(flags);
  1381. MACIO_OUT8(reset_io, KEYLARGO_GPIO_OUTPUT_ENABLE);
  1382. (void)MACIO_IN8(reset_io);
  1383. udelay(1);
  1384. MACIO_OUT8(reset_io, 0);
  1385. (void)MACIO_IN8(reset_io);
  1386. UNLOCK(flags);
  1387. return 0;
  1388. }
  1389. #endif /* CONFIG_SMP */
  1390. /*
  1391. * This can be called from pmac_smp so isn't static
  1392. *
  1393. * This takes the second CPU off the bus on dual CPU machines
  1394. * running UP
  1395. */
  1396. void g5_phy_disable_cpu1(void)
  1397. {
  1398. if (uninorth_maj == 3)
  1399. UN_OUT(U3_API_PHY_CONFIG_1, 0);
  1400. }
  1401. #endif /* CONFIG_POWER4 */
  1402. #ifndef CONFIG_POWER4
  1403. #ifdef CONFIG_PM
  1404. static u32 save_gpio_levels[2];
  1405. static u8 save_gpio_extint[KEYLARGO_GPIO_EXTINT_CNT];
  1406. static u8 save_gpio_normal[KEYLARGO_GPIO_CNT];
  1407. static u32 save_unin_clock_ctl;
  1408. static void keylargo_shutdown(struct macio_chip *macio, int sleep_mode)
  1409. {
  1410. u32 temp;
  1411. if (sleep_mode) {
  1412. mdelay(1);
  1413. MACIO_BIS(KEYLARGO_FCR0, KL0_USB_REF_SUSPEND);
  1414. (void)MACIO_IN32(KEYLARGO_FCR0);
  1415. mdelay(1);
  1416. }
  1417. MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
  1418. KL0_SCC_CELL_ENABLE |
  1419. KL0_IRDA_ENABLE | KL0_IRDA_CLK32_ENABLE |
  1420. KL0_IRDA_CLK19_ENABLE);
  1421. MACIO_BIC(KEYLARGO_MBCR, KL_MBCR_MB0_DEV_MASK);
  1422. MACIO_BIS(KEYLARGO_MBCR, KL_MBCR_MB0_IDE_ENABLE);
  1423. MACIO_BIC(KEYLARGO_FCR1,
  1424. KL1_AUDIO_SEL_22MCLK | KL1_AUDIO_CLK_ENABLE_BIT |
  1425. KL1_AUDIO_CLK_OUT_ENABLE | KL1_AUDIO_CELL_ENABLE |
  1426. KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
  1427. KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
  1428. KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
  1429. KL1_EIDE0_ENABLE | KL1_EIDE0_RESET_N |
  1430. KL1_EIDE1_ENABLE | KL1_EIDE1_RESET_N |
  1431. KL1_UIDE_ENABLE);
  1432. MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
  1433. MACIO_BIC(KEYLARGO_FCR2, KL2_IOBUS_ENABLE);
  1434. temp = MACIO_IN32(KEYLARGO_FCR3);
  1435. if (macio->rev >= 2) {
  1436. temp |= KL3_SHUTDOWN_PLL2X;
  1437. if (sleep_mode)
  1438. temp |= KL3_SHUTDOWN_PLL_TOTAL;
  1439. }
  1440. temp |= KL3_SHUTDOWN_PLLKW6 | KL3_SHUTDOWN_PLLKW4 |
  1441. KL3_SHUTDOWN_PLLKW35;
  1442. if (sleep_mode)
  1443. temp |= KL3_SHUTDOWN_PLLKW12;
  1444. temp &= ~(KL3_CLK66_ENABLE | KL3_CLK49_ENABLE | KL3_CLK45_ENABLE
  1445. | KL3_CLK31_ENABLE | KL3_I2S1_CLK18_ENABLE | KL3_I2S0_CLK18_ENABLE);
  1446. if (sleep_mode)
  1447. temp &= ~(KL3_TIMER_CLK18_ENABLE | KL3_VIA_CLK16_ENABLE);
  1448. MACIO_OUT32(KEYLARGO_FCR3, temp);
  1449. /* Flush posted writes & wait a bit */
  1450. (void)MACIO_IN32(KEYLARGO_FCR0); mdelay(1);
  1451. }
  1452. static void pangea_shutdown(struct macio_chip *macio, int sleep_mode)
  1453. {
  1454. u32 temp;
  1455. MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
  1456. KL0_SCC_CELL_ENABLE |
  1457. KL0_USB0_CELL_ENABLE | KL0_USB1_CELL_ENABLE);
  1458. MACIO_BIC(KEYLARGO_FCR1,
  1459. KL1_AUDIO_SEL_22MCLK | KL1_AUDIO_CLK_ENABLE_BIT |
  1460. KL1_AUDIO_CLK_OUT_ENABLE | KL1_AUDIO_CELL_ENABLE |
  1461. KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
  1462. KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
  1463. KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
  1464. KL1_UIDE_ENABLE);
  1465. if (pmac_mb.board_flags & PMAC_MB_MOBILE)
  1466. MACIO_BIC(KEYLARGO_FCR1, KL1_UIDE_RESET_N);
  1467. MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
  1468. temp = MACIO_IN32(KEYLARGO_FCR3);
  1469. temp |= KL3_SHUTDOWN_PLLKW6 | KL3_SHUTDOWN_PLLKW4 |
  1470. KL3_SHUTDOWN_PLLKW35;
  1471. temp &= ~(KL3_CLK49_ENABLE | KL3_CLK45_ENABLE | KL3_CLK31_ENABLE
  1472. | KL3_I2S0_CLK18_ENABLE | KL3_I2S1_CLK18_ENABLE);
  1473. if (sleep_mode)
  1474. temp &= ~(KL3_VIA_CLK16_ENABLE | KL3_TIMER_CLK18_ENABLE);
  1475. MACIO_OUT32(KEYLARGO_FCR3, temp);
  1476. /* Flush posted writes & wait a bit */
  1477. (void)MACIO_IN32(KEYLARGO_FCR0); mdelay(1);
  1478. }
  1479. static void intrepid_shutdown(struct macio_chip *macio, int sleep_mode)
  1480. {
  1481. u32 temp;
  1482. MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
  1483. KL0_SCC_CELL_ENABLE);
  1484. MACIO_BIC(KEYLARGO_FCR1,
  1485. KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
  1486. KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
  1487. KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
  1488. KL1_EIDE0_ENABLE);
  1489. if (pmac_mb.board_flags & PMAC_MB_MOBILE)
  1490. MACIO_BIC(KEYLARGO_FCR1, KL1_UIDE_RESET_N);
  1491. temp = MACIO_IN32(KEYLARGO_FCR3);
  1492. temp &= ~(KL3_CLK49_ENABLE | KL3_CLK45_ENABLE |
  1493. KL3_I2S1_CLK18_ENABLE | KL3_I2S0_CLK18_ENABLE);
  1494. if (sleep_mode)
  1495. temp &= ~(KL3_TIMER_CLK18_ENABLE | KL3_IT_VIA_CLK32_ENABLE);
  1496. MACIO_OUT32(KEYLARGO_FCR3, temp);
  1497. /* Flush posted writes & wait a bit */
  1498. (void)MACIO_IN32(KEYLARGO_FCR0);
  1499. mdelay(10);
  1500. }
  1501. static int
  1502. core99_sleep(void)
  1503. {
  1504. struct macio_chip *macio;
  1505. int i;
  1506. macio = &macio_chips[0];
  1507. if (macio->type != macio_keylargo && macio->type != macio_pangea &&
  1508. macio->type != macio_intrepid)
  1509. return -ENODEV;
  1510. /* We power off the wireless slot in case it was not done
  1511. * by the driver. We don't power it on automatically however
  1512. */
  1513. if (macio->flags & MACIO_FLAG_AIRPORT_ON)
  1514. core99_airport_enable(macio->of_node, 0, 0);
  1515. /* We power off the FW cable. Should be done by the driver... */
  1516. if (macio->flags & MACIO_FLAG_FW_SUPPORTED) {
  1517. core99_firewire_enable(NULL, 0, 0);
  1518. core99_firewire_cable_power(NULL, 0, 0);
  1519. }
  1520. /* We make sure int. modem is off (in case driver lost it) */
  1521. if (macio->type == macio_keylargo)
  1522. core99_modem_enable(macio->of_node, 0, 0);
  1523. else
  1524. pangea_modem_enable(macio->of_node, 0, 0);
  1525. /* We make sure the sound is off as well */
  1526. core99_sound_chip_enable(macio->of_node, 0, 0);
  1527. /*
  1528. * Save various bits of KeyLargo
  1529. */
  1530. /* Save the state of the various GPIOs */
  1531. save_gpio_levels[0] = MACIO_IN32(KEYLARGO_GPIO_LEVELS0);
  1532. save_gpio_levels[1] = MACIO_IN32(KEYLARGO_GPIO_LEVELS1);
  1533. for (i=0; i<KEYLARGO_GPIO_EXTINT_CNT; i++)
  1534. save_gpio_extint[i] = MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+i);
  1535. for (i=0; i<KEYLARGO_GPIO_CNT; i++)
  1536. save_gpio_normal[i] = MACIO_IN8(KEYLARGO_GPIO_0+i);
  1537. /* Save the FCRs */
  1538. if (macio->type == macio_keylargo)
  1539. save_mbcr = MACIO_IN32(KEYLARGO_MBCR);
  1540. save_fcr[0] = MACIO_IN32(KEYLARGO_FCR0);
  1541. save_fcr[1] = MACIO_IN32(KEYLARGO_FCR1);
  1542. save_fcr[2] = MACIO_IN32(KEYLARGO_FCR2);
  1543. save_fcr[3] = MACIO_IN32(KEYLARGO_FCR3);
  1544. save_fcr[4] = MACIO_IN32(KEYLARGO_FCR4);
  1545. if (macio->type == macio_pangea || macio->type == macio_intrepid)
  1546. save_fcr[5] = MACIO_IN32(KEYLARGO_FCR5);
  1547. /* Save state & config of DBDMA channels */
  1548. dbdma_save(macio, save_dbdma);
  1549. /*
  1550. * Turn off as much as we can
  1551. */
  1552. if (macio->type == macio_pangea)
  1553. pangea_shutdown(macio, 1);
  1554. else if (macio->type == macio_intrepid)
  1555. intrepid_shutdown(macio, 1);
  1556. else if (macio->type == macio_keylargo)
  1557. keylargo_shutdown(macio, 1);
  1558. /*
  1559. * Put the host bridge to sleep
  1560. */
  1561. save_unin_clock_ctl = UN_IN(UNI_N_CLOCK_CNTL);
  1562. /* Note: do not switch GMAC off, driver does it when necessary, WOL must keep it
  1563. * enabled !
  1564. */
  1565. UN_OUT(UNI_N_CLOCK_CNTL, save_unin_clock_ctl &
  1566. ~(/*UNI_N_CLOCK_CNTL_GMAC|*/UNI_N_CLOCK_CNTL_FW/*|UNI_N_CLOCK_CNTL_PCI*/));
  1567. udelay(100);
  1568. UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_SLEEPING);
  1569. UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_SLEEP);
  1570. mdelay(10);
  1571. /*
  1572. * FIXME: A bit of black magic with OpenPIC (don't ask me why)
  1573. */
  1574. if (pmac_mb.model_id == PMAC_TYPE_SAWTOOTH) {
  1575. MACIO_BIS(0x506e0, 0x00400000);
  1576. MACIO_BIS(0x506e0, 0x80000000);
  1577. }
  1578. return 0;
  1579. }
  1580. static int
  1581. core99_wake_up(void)
  1582. {
  1583. struct macio_chip *macio;
  1584. int i;
  1585. macio = &macio_chips[0];
  1586. if (macio->type != macio_keylargo && macio->type != macio_pangea &&
  1587. macio->type != macio_intrepid)
  1588. return -ENODEV;
  1589. /*
  1590. * Wakeup the host bridge
  1591. */
  1592. UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_NORMAL);
  1593. udelay(10);
  1594. UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_RUNNING);
  1595. udelay(10);
  1596. /*
  1597. * Restore KeyLargo
  1598. */
  1599. if (macio->type == macio_keylargo) {
  1600. MACIO_OUT32(KEYLARGO_MBCR, save_mbcr);
  1601. (void)MACIO_IN32(KEYLARGO_MBCR); udelay(10);
  1602. }
  1603. MACIO_OUT32(KEYLARGO_FCR0, save_fcr[0]);
  1604. (void)MACIO_IN32(KEYLARGO_FCR0); udelay(10);
  1605. MACIO_OUT32(KEYLARGO_FCR1, save_fcr[1]);
  1606. (void)MACIO_IN32(KEYLARGO_FCR1); udelay(10);
  1607. MACIO_OUT32(KEYLARGO_FCR2, save_fcr[2]);
  1608. (void)MACIO_IN32(KEYLARGO_FCR2); udelay(10);
  1609. MACIO_OUT32(KEYLARGO_FCR3, save_fcr[3]);
  1610. (void)MACIO_IN32(KEYLARGO_FCR3); udelay(10);
  1611. MACIO_OUT32(KEYLARGO_FCR4, save_fcr[4]);
  1612. (void)MACIO_IN32(KEYLARGO_FCR4); udelay(10);
  1613. if (macio->type == macio_pangea || macio->type == macio_intrepid) {
  1614. MACIO_OUT32(KEYLARGO_FCR5, save_fcr[5]);
  1615. (void)MACIO_IN32(KEYLARGO_FCR5); udelay(10);
  1616. }
  1617. dbdma_restore(macio, save_dbdma);
  1618. MACIO_OUT32(KEYLARGO_GPIO_LEVELS0, save_gpio_levels[0]);
  1619. MACIO_OUT32(KEYLARGO_GPIO_LEVELS1, save_gpio_levels[1]);
  1620. for (i=0; i<KEYLARGO_GPIO_EXTINT_CNT; i++)
  1621. MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+i, save_gpio_extint[i]);
  1622. for (i=0; i<KEYLARGO_GPIO_CNT; i++)
  1623. MACIO_OUT8(KEYLARGO_GPIO_0+i, save_gpio_normal[i]);
  1624. /* FIXME more black magic with OpenPIC ... */
  1625. if (pmac_mb.model_id == PMAC_TYPE_SAWTOOTH) {
  1626. MACIO_BIC(0x506e0, 0x00400000);
  1627. MACIO_BIC(0x506e0, 0x80000000);
  1628. }
  1629. UN_OUT(UNI_N_CLOCK_CNTL, save_unin_clock_ctl);
  1630. udelay(100);
  1631. return 0;
  1632. }
  1633. #endif /* CONFIG_PM */
  1634. static long
  1635. core99_sleep_state(struct device_node *node, long param, long value)
  1636. {
  1637. /* Param == 1 means to enter the "fake sleep" mode that is
  1638. * used for CPU speed switch
  1639. */
  1640. if (param == 1) {
  1641. if (value == 1) {
  1642. UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_SLEEPING);
  1643. UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_IDLE2);
  1644. } else {
  1645. UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_NORMAL);
  1646. udelay(10);
  1647. UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_RUNNING);
  1648. udelay(10);
  1649. }
  1650. return 0;
  1651. }
  1652. if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
  1653. return -EPERM;
  1654. #ifdef CONFIG_PM
  1655. if (value == 1)
  1656. return core99_sleep();
  1657. else if (value == 0)
  1658. return core99_wake_up();
  1659. #endif /* CONFIG_PM */
  1660. return 0;
  1661. }
  1662. #endif /* CONFIG_POWER4 */
  1663. static long
  1664. generic_dev_can_wake(struct device_node *node, long param, long value)
  1665. {
  1666. /* Todo: eventually check we are really dealing with on-board
  1667. * video device ...
  1668. */
  1669. if (pmac_mb.board_flags & PMAC_MB_MAY_SLEEP)
  1670. pmac_mb.board_flags |= PMAC_MB_CAN_SLEEP;
  1671. return 0;
  1672. }
  1673. static long generic_get_mb_info(struct device_node *node, long param, long value)
  1674. {
  1675. switch(param) {
  1676. case PMAC_MB_INFO_MODEL:
  1677. return pmac_mb.model_id;
  1678. case PMAC_MB_INFO_FLAGS:
  1679. return pmac_mb.board_flags;
  1680. case PMAC_MB_INFO_NAME:
  1681. /* hack hack hack... but should work */
  1682. *((const char **)value) = pmac_mb.model_name;
  1683. return 0;
  1684. }
  1685. return -EINVAL;
  1686. }
  1687. /*
  1688. * Table definitions
  1689. */
  1690. /* Used on any machine
  1691. */
  1692. static struct feature_table_entry any_features[] = {
  1693. { PMAC_FTR_GET_MB_INFO, generic_get_mb_info },
  1694. { PMAC_FTR_DEVICE_CAN_WAKE, generic_dev_can_wake },
  1695. { 0, NULL }
  1696. };
  1697. #ifndef CONFIG_POWER4
  1698. /* OHare based motherboards. Currently, we only use these on the
  1699. * 2400,3400 and 3500 series powerbooks. Some older desktops seem
  1700. * to have issues with turning on/off those asic cells
  1701. */
  1702. static struct feature_table_entry ohare_features[] = {
  1703. { PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },
  1704. { PMAC_FTR_SWIM3_ENABLE, ohare_floppy_enable },
  1705. { PMAC_FTR_MESH_ENABLE, ohare_mesh_enable },
  1706. { PMAC_FTR_IDE_ENABLE, ohare_ide_enable},
  1707. { PMAC_FTR_IDE_RESET, ohare_ide_reset},
  1708. { PMAC_FTR_SLEEP_STATE, ohare_sleep_state },
  1709. { 0, NULL }
  1710. };
  1711. /* Heathrow desktop machines (Beige G3).
  1712. * Separated as some features couldn't be properly tested
  1713. * and the serial port control bits appear to confuse it.
  1714. */
  1715. static struct feature_table_entry heathrow_desktop_features[] = {
  1716. { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
  1717. { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
  1718. { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
  1719. { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
  1720. { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
  1721. { 0, NULL }
  1722. };
  1723. /* Heathrow based laptop, that is the Wallstreet and mainstreet
  1724. * powerbooks.
  1725. */
  1726. static struct feature_table_entry heathrow_laptop_features[] = {
  1727. { PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },
  1728. { PMAC_FTR_MODEM_ENABLE, heathrow_modem_enable },
  1729. { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
  1730. { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
  1731. { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
  1732. { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
  1733. { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
  1734. { PMAC_FTR_SOUND_CHIP_ENABLE, heathrow_sound_enable },
  1735. { PMAC_FTR_SLEEP_STATE, heathrow_sleep_state },
  1736. { 0, NULL }
  1737. };
  1738. /* Paddington based machines
  1739. * The lombard (101) powerbook, first iMac models, B&W G3 and Yikes G4.
  1740. */
  1741. static struct feature_table_entry paddington_features[] = {
  1742. { PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },
  1743. { PMAC_FTR_MODEM_ENABLE, heathrow_modem_enable },
  1744. { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
  1745. { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
  1746. { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
  1747. { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
  1748. { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
  1749. { PMAC_FTR_SOUND_CHIP_ENABLE, heathrow_sound_enable },
  1750. { PMAC_FTR_SLEEP_STATE, heathrow_sleep_state },
  1751. { 0, NULL }
  1752. };
  1753. /* Core99 & MacRISC 2 machines (all machines released since the
  1754. * iBook (included), that is all AGP machines, except pangea
  1755. * chipset. The pangea chipset is the "combo" UniNorth/KeyLargo
  1756. * used on iBook2 & iMac "flow power".
  1757. */
  1758. static struct feature_table_entry core99_features[] = {
  1759. { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
  1760. { PMAC_FTR_MODEM_ENABLE, core99_modem_enable },
  1761. { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
  1762. { PMAC_FTR_IDE_RESET, core99_ide_reset },
  1763. { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
  1764. { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
  1765. { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
  1766. { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
  1767. { PMAC_FTR_USB_ENABLE, core99_usb_enable },
  1768. { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
  1769. { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
  1770. #ifdef CONFIG_PM
  1771. { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
  1772. #endif
  1773. #ifdef CONFIG_SMP
  1774. { PMAC_FTR_RESET_CPU, core99_reset_cpu },
  1775. #endif /* CONFIG_SMP */
  1776. { PMAC_FTR_READ_GPIO, core99_read_gpio },
  1777. { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
  1778. { 0, NULL }
  1779. };
  1780. /* RackMac
  1781. */
  1782. static struct feature_table_entry rackmac_features[] = {
  1783. { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
  1784. { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
  1785. { PMAC_FTR_IDE_RESET, core99_ide_reset },
  1786. { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
  1787. { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
  1788. { PMAC_FTR_USB_ENABLE, core99_usb_enable },
  1789. { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
  1790. { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
  1791. { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
  1792. #ifdef CONFIG_SMP
  1793. { PMAC_FTR_RESET_CPU, core99_reset_cpu },
  1794. #endif /* CONFIG_SMP */
  1795. { PMAC_FTR_READ_GPIO, core99_read_gpio },
  1796. { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
  1797. { 0, NULL }
  1798. };
  1799. /* Pangea features
  1800. */
  1801. static struct feature_table_entry pangea_features[] = {
  1802. { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
  1803. { PMAC_FTR_MODEM_ENABLE, pangea_modem_enable },
  1804. { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
  1805. { PMAC_FTR_IDE_RESET, core99_ide_reset },
  1806. { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
  1807. { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
  1808. { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
  1809. { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
  1810. { PMAC_FTR_USB_ENABLE, core99_usb_enable },
  1811. { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
  1812. { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
  1813. { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
  1814. { PMAC_FTR_READ_GPIO, core99_read_gpio },
  1815. { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
  1816. { 0, NULL }
  1817. };
  1818. /* Intrepid features
  1819. */
  1820. static struct feature_table_entry intrepid_features[] = {
  1821. { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
  1822. { PMAC_FTR_MODEM_ENABLE, pangea_modem_enable },
  1823. { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
  1824. { PMAC_FTR_IDE_RESET, core99_ide_reset },
  1825. { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
  1826. { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
  1827. { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
  1828. { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
  1829. { PMAC_FTR_USB_ENABLE, core99_usb_enable },
  1830. { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
  1831. { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
  1832. { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
  1833. { PMAC_FTR_READ_GPIO, core99_read_gpio },
  1834. { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
  1835. { PMAC_FTR_AACK_DELAY_ENABLE, intrepid_aack_delay_enable },
  1836. { 0, NULL }
  1837. };
  1838. #else /* CONFIG_POWER4 */
  1839. /* G5 features
  1840. */
  1841. static struct feature_table_entry g5_features[] = {
  1842. { PMAC_FTR_GMAC_ENABLE, g5_gmac_enable },
  1843. { PMAC_FTR_1394_ENABLE, g5_fw_enable },
  1844. { PMAC_FTR_ENABLE_MPIC, g5_mpic_enable },
  1845. { PMAC_FTR_GMAC_PHY_RESET, g5_eth_phy_reset },
  1846. { PMAC_FTR_SOUND_CHIP_ENABLE, g5_i2s_enable },
  1847. #ifdef CONFIG_SMP
  1848. { PMAC_FTR_RESET_CPU, g5_reset_cpu },
  1849. #endif /* CONFIG_SMP */
  1850. { PMAC_FTR_READ_GPIO, core99_read_gpio },
  1851. { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
  1852. { 0, NULL }
  1853. };
  1854. #endif /* CONFIG_POWER4 */
  1855. static struct pmac_mb_def pmac_mb_defs[] = {
  1856. #ifndef CONFIG_POWER4
  1857. /*
  1858. * Desktops
  1859. */
  1860. { "AAPL,8500", "PowerMac 8500/8600",
  1861. PMAC_TYPE_PSURGE, NULL,
  1862. 0
  1863. },
  1864. { "AAPL,9500", "PowerMac 9500/9600",
  1865. PMAC_TYPE_PSURGE, NULL,
  1866. 0
  1867. },
  1868. { "AAPL,7200", "PowerMac 7200",
  1869. PMAC_TYPE_PSURGE, NULL,
  1870. 0
  1871. },
  1872. { "AAPL,7300", "PowerMac 7200/7300",
  1873. PMAC_TYPE_PSURGE, NULL,
  1874. 0
  1875. },
  1876. { "AAPL,7500", "PowerMac 7500",
  1877. PMAC_TYPE_PSURGE, NULL,
  1878. 0
  1879. },
  1880. { "AAPL,ShinerESB", "Apple Network Server",
  1881. PMAC_TYPE_ANS, NULL,
  1882. 0
  1883. },
  1884. { "AAPL,e407", "Alchemy",
  1885. PMAC_TYPE_ALCHEMY, NULL,
  1886. 0
  1887. },
  1888. { "AAPL,e411", "Gazelle",
  1889. PMAC_TYPE_GAZELLE, NULL,
  1890. 0
  1891. },
  1892. { "AAPL,Gossamer", "PowerMac G3 (Gossamer)",
  1893. PMAC_TYPE_GOSSAMER, heathrow_desktop_features,
  1894. 0
  1895. },
  1896. { "AAPL,PowerMac G3", "PowerMac G3 (Silk)",
  1897. PMAC_TYPE_SILK, heathrow_desktop_features,
  1898. 0
  1899. },
  1900. { "PowerMac1,1", "Blue&White G3",
  1901. PMAC_TYPE_YOSEMITE, paddington_features,
  1902. 0
  1903. },
  1904. { "PowerMac1,2", "PowerMac G4 PCI Graphics",
  1905. PMAC_TYPE_YIKES, paddington_features,
  1906. 0
  1907. },
  1908. { "PowerMac2,1", "iMac FireWire",
  1909. PMAC_TYPE_FW_IMAC, core99_features,
  1910. PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
  1911. },
  1912. { "PowerMac2,2", "iMac FireWire",
  1913. PMAC_TYPE_FW_IMAC, core99_features,
  1914. PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
  1915. },
  1916. { "PowerMac3,1", "PowerMac G4 AGP Graphics",
  1917. PMAC_TYPE_SAWTOOTH, core99_features,
  1918. PMAC_MB_OLD_CORE99
  1919. },
  1920. { "PowerMac3,2", "PowerMac G4 AGP Graphics",
  1921. PMAC_TYPE_SAWTOOTH, core99_features,
  1922. PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
  1923. },
  1924. { "PowerMac3,3", "PowerMac G4 AGP Graphics",
  1925. PMAC_TYPE_SAWTOOTH, core99_features,
  1926. PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
  1927. },
  1928. { "PowerMac3,4", "PowerMac G4 Silver",
  1929. PMAC_TYPE_QUICKSILVER, core99_features,
  1930. PMAC_MB_MAY_SLEEP
  1931. },
  1932. { "PowerMac3,5", "PowerMac G4 Silver",
  1933. PMAC_TYPE_QUICKSILVER, core99_features,
  1934. PMAC_MB_MAY_SLEEP
  1935. },
  1936. { "PowerMac3,6", "PowerMac G4 Windtunnel",
  1937. PMAC_TYPE_WINDTUNNEL, core99_features,
  1938. PMAC_MB_MAY_SLEEP,
  1939. },
  1940. { "PowerMac4,1", "iMac \"Flower Power\"",
  1941. PMAC_TYPE_PANGEA_IMAC, pangea_features,
  1942. PMAC_MB_MAY_SLEEP
  1943. },
  1944. { "PowerMac4,2", "Flat panel iMac",
  1945. PMAC_TYPE_FLAT_PANEL_IMAC, pangea_features,
  1946. PMAC_MB_CAN_SLEEP
  1947. },
  1948. { "PowerMac4,4", "eMac",
  1949. PMAC_TYPE_EMAC, core99_features,
  1950. PMAC_MB_MAY_SLEEP
  1951. },
  1952. { "PowerMac5,1", "PowerMac G4 Cube",
  1953. PMAC_TYPE_CUBE, core99_features,
  1954. PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
  1955. },
  1956. { "PowerMac6,1", "Flat panel iMac",
  1957. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  1958. PMAC_MB_MAY_SLEEP,
  1959. },
  1960. { "PowerMac6,3", "Flat panel iMac",
  1961. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  1962. PMAC_MB_MAY_SLEEP,
  1963. },
  1964. { "PowerMac6,4", "eMac",
  1965. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  1966. PMAC_MB_MAY_SLEEP,
  1967. },
  1968. { "PowerMac10,1", "Mac mini",
  1969. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  1970. PMAC_MB_MAY_SLEEP,
  1971. },
  1972. { "iMac,1", "iMac (first generation)",
  1973. PMAC_TYPE_ORIG_IMAC, paddington_features,
  1974. 0
  1975. },
  1976. /*
  1977. * Xserve's
  1978. */
  1979. { "RackMac1,1", "XServe",
  1980. PMAC_TYPE_RACKMAC, rackmac_features,
  1981. 0,
  1982. },
  1983. { "RackMac1,2", "XServe rev. 2",
  1984. PMAC_TYPE_RACKMAC, rackmac_features,
  1985. 0,
  1986. },
  1987. /*
  1988. * Laptops
  1989. */
  1990. { "AAPL,3400/2400", "PowerBook 3400",
  1991. PMAC_TYPE_HOOPER, ohare_features,
  1992. PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
  1993. },
  1994. { "AAPL,3500", "PowerBook 3500",
  1995. PMAC_TYPE_KANGA, ohare_features,
  1996. PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
  1997. },
  1998. { "AAPL,PowerBook1998", "PowerBook Wallstreet",
  1999. PMAC_TYPE_WALLSTREET, heathrow_laptop_features,
  2000. PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
  2001. },
  2002. { "PowerBook1,1", "PowerBook 101 (Lombard)",
  2003. PMAC_TYPE_101_PBOOK, paddington_features,
  2004. PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
  2005. },
  2006. { "PowerBook2,1", "iBook (first generation)",
  2007. PMAC_TYPE_ORIG_IBOOK, core99_features,
  2008. PMAC_MB_CAN_SLEEP | PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE
  2009. },
  2010. { "PowerBook2,2", "iBook FireWire",
  2011. PMAC_TYPE_FW_IBOOK, core99_features,
  2012. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER |
  2013. PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE
  2014. },
  2015. { "PowerBook3,1", "PowerBook Pismo",
  2016. PMAC_TYPE_PISMO, core99_features,
  2017. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER |
  2018. PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE
  2019. },
  2020. { "PowerBook3,2", "PowerBook Titanium",
  2021. PMAC_TYPE_TITANIUM, core99_features,
  2022. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2023. },
  2024. { "PowerBook3,3", "PowerBook Titanium II",
  2025. PMAC_TYPE_TITANIUM2, core99_features,
  2026. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2027. },
  2028. { "PowerBook3,4", "PowerBook Titanium III",
  2029. PMAC_TYPE_TITANIUM3, core99_features,
  2030. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2031. },
  2032. { "PowerBook3,5", "PowerBook Titanium IV",
  2033. PMAC_TYPE_TITANIUM4, core99_features,
  2034. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2035. },
  2036. { "PowerBook4,1", "iBook 2",
  2037. PMAC_TYPE_IBOOK2, pangea_features,
  2038. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2039. },
  2040. { "PowerBook4,2", "iBook 2",
  2041. PMAC_TYPE_IBOOK2, pangea_features,
  2042. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2043. },
  2044. { "PowerBook4,3", "iBook 2 rev. 2",
  2045. PMAC_TYPE_IBOOK2, pangea_features,
  2046. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
  2047. },
  2048. { "PowerBook5,1", "PowerBook G4 17\"",
  2049. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2050. PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2051. },
  2052. { "PowerBook5,2", "PowerBook G4 15\"",
  2053. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2054. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2055. },
  2056. { "PowerBook5,3", "PowerBook G4 17\"",
  2057. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2058. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2059. },
  2060. { "PowerBook5,4", "PowerBook G4 15\"",
  2061. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2062. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2063. },
  2064. { "PowerBook5,5", "PowerBook G4 17\"",
  2065. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2066. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2067. },
  2068. { "PowerBook5,6", "PowerBook G4 15\"",
  2069. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2070. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2071. },
  2072. { "PowerBook5,7", "PowerBook G4 17\"",
  2073. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2074. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2075. },
  2076. { "PowerBook5,8", "PowerBook G4 15\"",
  2077. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2078. PMAC_MB_MAY_SLEEP | PMAC_MB_MOBILE,
  2079. },
  2080. { "PowerBook5,9", "PowerBook G4 17\"",
  2081. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2082. PMAC_MB_MAY_SLEEP | PMAC_MB_MOBILE,
  2083. },
  2084. { "PowerBook6,1", "PowerBook G4 12\"",
  2085. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2086. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2087. },
  2088. { "PowerBook6,2", "PowerBook G4",
  2089. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2090. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2091. },
  2092. { "PowerBook6,3", "iBook G4",
  2093. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2094. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2095. },
  2096. { "PowerBook6,4", "PowerBook G4 12\"",
  2097. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2098. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2099. },
  2100. { "PowerBook6,5", "iBook G4",
  2101. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2102. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2103. },
  2104. { "PowerBook6,7", "iBook G4",
  2105. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2106. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2107. },
  2108. { "PowerBook6,8", "PowerBook G4 12\"",
  2109. PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
  2110. PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
  2111. },
  2112. #else /* CONFIG_POWER4 */
  2113. { "PowerMac7,2", "PowerMac G5",
  2114. PMAC_TYPE_POWERMAC_G5, g5_features,
  2115. 0,
  2116. },
  2117. #ifdef CONFIG_PPC64
  2118. { "PowerMac7,3", "PowerMac G5",
  2119. PMAC_TYPE_POWERMAC_G5, g5_features,
  2120. 0,
  2121. },
  2122. { "PowerMac8,1", "iMac G5",
  2123. PMAC_TYPE_IMAC_G5, g5_features,
  2124. 0,
  2125. },
  2126. { "PowerMac9,1", "PowerMac G5",
  2127. PMAC_TYPE_POWERMAC_G5_U3L, g5_features,
  2128. 0,
  2129. },
  2130. { "PowerMac11,2", "PowerMac G5 Dual Core",
  2131. PMAC_TYPE_POWERMAC_G5_U3L, g5_features,
  2132. 0,
  2133. },
  2134. { "PowerMac12,1", "iMac G5 (iSight)",
  2135. PMAC_TYPE_POWERMAC_G5_U3L, g5_features,
  2136. 0,
  2137. },
  2138. { "RackMac3,1", "XServe G5",
  2139. PMAC_TYPE_XSERVE_G5, g5_features,
  2140. 0,
  2141. },
  2142. #endif /* CONFIG_PPC64 */
  2143. #endif /* CONFIG_POWER4 */
  2144. };
  2145. /*
  2146. * The toplevel feature_call callback
  2147. */
  2148. long pmac_do_feature_call(unsigned int selector, ...)
  2149. {
  2150. struct device_node *node;
  2151. long param, value;
  2152. int i;
  2153. feature_call func = NULL;
  2154. va_list args;
  2155. if (pmac_mb.features)
  2156. for (i=0; pmac_mb.features[i].function; i++)
  2157. if (pmac_mb.features[i].selector == selector) {
  2158. func = pmac_mb.features[i].function;
  2159. break;
  2160. }
  2161. if (!func)
  2162. for (i=0; any_features[i].function; i++)
  2163. if (any_features[i].selector == selector) {
  2164. func = any_features[i].function;
  2165. break;
  2166. }
  2167. if (!func)
  2168. return -ENODEV;
  2169. va_start(args, selector);
  2170. node = (struct device_node*)va_arg(args, void*);
  2171. param = va_arg(args, long);
  2172. value = va_arg(args, long);
  2173. va_end(args);
  2174. return func(node, param, value);
  2175. }
  2176. static int __init probe_motherboard(void)
  2177. {
  2178. int i;
  2179. struct macio_chip *macio = &macio_chips[0];
  2180. const char *model = NULL;
  2181. struct device_node *dt;
  2182. int ret = 0;
  2183. /* Lookup known motherboard type in device-tree. First try an
  2184. * exact match on the "model" property, then try a "compatible"
  2185. * match is none is found.
  2186. */
  2187. dt = of_find_node_by_name(NULL, "device-tree");
  2188. if (dt != NULL)
  2189. model = of_get_property(dt, "model", NULL);
  2190. for(i=0; model && i<(sizeof(pmac_mb_defs)/sizeof(struct pmac_mb_def)); i++) {
  2191. if (strcmp(model, pmac_mb_defs[i].model_string) == 0) {
  2192. pmac_mb = pmac_mb_defs[i];
  2193. goto found;
  2194. }
  2195. }
  2196. for(i=0; i<(sizeof(pmac_mb_defs)/sizeof(struct pmac_mb_def)); i++) {
  2197. if (machine_is_compatible(pmac_mb_defs[i].model_string)) {
  2198. pmac_mb = pmac_mb_defs[i];
  2199. goto found;
  2200. }
  2201. }
  2202. /* Fallback to selection depending on mac-io chip type */
  2203. switch(macio->type) {
  2204. #ifndef CONFIG_POWER4
  2205. case macio_grand_central:
  2206. pmac_mb.model_id = PMAC_TYPE_PSURGE;
  2207. pmac_mb.model_name = "Unknown PowerSurge";
  2208. break;
  2209. case macio_ohare:
  2210. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_OHARE;
  2211. pmac_mb.model_name = "Unknown OHare-based";
  2212. break;
  2213. case macio_heathrow:
  2214. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_HEATHROW;
  2215. pmac_mb.model_name = "Unknown Heathrow-based";
  2216. pmac_mb.features = heathrow_desktop_features;
  2217. break;
  2218. case macio_paddington:
  2219. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_PADDINGTON;
  2220. pmac_mb.model_name = "Unknown Paddington-based";
  2221. pmac_mb.features = paddington_features;
  2222. break;
  2223. case macio_keylargo:
  2224. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_CORE99;
  2225. pmac_mb.model_name = "Unknown Keylargo-based";
  2226. pmac_mb.features = core99_features;
  2227. break;
  2228. case macio_pangea:
  2229. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_PANGEA;
  2230. pmac_mb.model_name = "Unknown Pangea-based";
  2231. pmac_mb.features = pangea_features;
  2232. break;
  2233. case macio_intrepid:
  2234. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_INTREPID;
  2235. pmac_mb.model_name = "Unknown Intrepid-based";
  2236. pmac_mb.features = intrepid_features;
  2237. break;
  2238. #else /* CONFIG_POWER4 */
  2239. case macio_keylargo2:
  2240. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_K2;
  2241. pmac_mb.model_name = "Unknown K2-based";
  2242. pmac_mb.features = g5_features;
  2243. break;
  2244. case macio_shasta:
  2245. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_SHASTA;
  2246. pmac_mb.model_name = "Unknown Shasta-based";
  2247. pmac_mb.features = g5_features;
  2248. break;
  2249. #endif /* CONFIG_POWER4 */
  2250. default:
  2251. ret = -ENODEV;
  2252. goto done;
  2253. }
  2254. found:
  2255. #ifndef CONFIG_POWER4
  2256. /* Fixup Hooper vs. Comet */
  2257. if (pmac_mb.model_id == PMAC_TYPE_HOOPER) {
  2258. u32 __iomem * mach_id_ptr = ioremap(0xf3000034, 4);
  2259. if (!mach_id_ptr) {
  2260. ret = -ENODEV;
  2261. goto done;
  2262. }
  2263. /* Here, I used to disable the media-bay on comet. It
  2264. * appears this is wrong, the floppy connector is actually
  2265. * a kind of media-bay and works with the current driver.
  2266. */
  2267. if (__raw_readl(mach_id_ptr) & 0x20000000UL)
  2268. pmac_mb.model_id = PMAC_TYPE_COMET;
  2269. iounmap(mach_id_ptr);
  2270. }
  2271. /* Set default value of powersave_nap on machines that support it.
  2272. * It appears that uninorth rev 3 has a problem with it, we don't
  2273. * enable it on those. In theory, the flush-on-lock property is
  2274. * supposed to be set when not supported, but I'm not very confident
  2275. * that all Apple OF revs did it properly, I do it the paranoid way.
  2276. */
  2277. while (uninorth_base && uninorth_rev > 3) {
  2278. struct device_node *cpus = of_find_node_by_path("/cpus");
  2279. struct device_node *np;
  2280. if (!cpus || !cpus->child) {
  2281. printk(KERN_WARNING "Can't find CPU(s) in device tree !\n");
  2282. of_node_put(cpus);
  2283. break;
  2284. }
  2285. np = cpus->child;
  2286. /* Nap mode not supported on SMP */
  2287. if (np->sibling) {
  2288. of_node_put(cpus);
  2289. break;
  2290. }
  2291. /* Nap mode not supported if flush-on-lock property is present */
  2292. if (of_get_property(np, "flush-on-lock", NULL)) {
  2293. of_node_put(cpus);
  2294. break;
  2295. }
  2296. of_node_put(cpus);
  2297. powersave_nap = 1;
  2298. printk(KERN_DEBUG "Processor NAP mode on idle enabled.\n");
  2299. break;
  2300. }
  2301. /* On CPUs that support it (750FX), lowspeed by default during
  2302. * NAP mode
  2303. */
  2304. powersave_lowspeed = 1;
  2305. #else /* CONFIG_POWER4 */
  2306. powersave_nap = 1;
  2307. #endif /* CONFIG_POWER4 */
  2308. /* Check for "mobile" machine */
  2309. if (model && (strncmp(model, "PowerBook", 9) == 0
  2310. || strncmp(model, "iBook", 5) == 0))
  2311. pmac_mb.board_flags |= PMAC_MB_MOBILE;
  2312. printk(KERN_INFO "PowerMac motherboard: %s\n", pmac_mb.model_name);
  2313. done:
  2314. of_node_put(dt);
  2315. return ret;
  2316. }
  2317. /* Initialize the Core99 UniNorth host bridge and memory controller
  2318. */
  2319. static void __init probe_uninorth(void)
  2320. {
  2321. const u32 *addrp;
  2322. phys_addr_t address;
  2323. unsigned long actrl;
  2324. /* Locate core99 Uni-N */
  2325. uninorth_node = of_find_node_by_name(NULL, "uni-n");
  2326. /* Locate G5 u3 */
  2327. if (uninorth_node == NULL) {
  2328. uninorth_node = of_find_node_by_name(NULL, "u3");
  2329. uninorth_maj = 3;
  2330. }
  2331. /* Locate G5 u4 */
  2332. if (uninorth_node == NULL) {
  2333. uninorth_node = of_find_node_by_name(NULL, "u4");
  2334. uninorth_maj = 4;
  2335. }
  2336. if (uninorth_node == NULL)
  2337. return;
  2338. addrp = of_get_property(uninorth_node, "reg", NULL);
  2339. if (addrp == NULL)
  2340. return;
  2341. address = of_translate_address(uninorth_node, addrp);
  2342. if (address == 0)
  2343. return;
  2344. uninorth_base = ioremap(address, 0x40000);
  2345. uninorth_rev = in_be32(UN_REG(UNI_N_VERSION));
  2346. if (uninorth_maj == 3 || uninorth_maj == 4)
  2347. u3_ht_base = ioremap(address + U3_HT_CONFIG_BASE, 0x1000);
  2348. printk(KERN_INFO "Found %s memory controller & host bridge"
  2349. " @ 0x%08x revision: 0x%02x\n", uninorth_maj == 3 ? "U3" :
  2350. uninorth_maj == 4 ? "U4" : "UniNorth",
  2351. (unsigned int)address, uninorth_rev);
  2352. printk(KERN_INFO "Mapped at 0x%08lx\n", (unsigned long)uninorth_base);
  2353. /* Set the arbitrer QAck delay according to what Apple does
  2354. */
  2355. if (uninorth_rev < 0x11) {
  2356. actrl = UN_IN(UNI_N_ARB_CTRL) & ~UNI_N_ARB_CTRL_QACK_DELAY_MASK;
  2357. actrl |= ((uninorth_rev < 3) ? UNI_N_ARB_CTRL_QACK_DELAY105 :
  2358. UNI_N_ARB_CTRL_QACK_DELAY) <<
  2359. UNI_N_ARB_CTRL_QACK_DELAY_SHIFT;
  2360. UN_OUT(UNI_N_ARB_CTRL, actrl);
  2361. }
  2362. /* Some more magic as done by them in recent MacOS X on UniNorth
  2363. * revs 1.5 to 2.O and Pangea. Seem to toggle the UniN Maxbus/PCI
  2364. * memory timeout
  2365. */
  2366. if ((uninorth_rev >= 0x11 && uninorth_rev <= 0x24) ||
  2367. uninorth_rev == 0xc0)
  2368. UN_OUT(0x2160, UN_IN(0x2160) & 0x00ffffff);
  2369. }
  2370. static void __init probe_one_macio(const char *name, const char *compat, int type)
  2371. {
  2372. struct device_node* node;
  2373. int i;
  2374. volatile u32 __iomem *base;
  2375. const u32 *addrp, *revp;
  2376. phys_addr_t addr;
  2377. u64 size;
  2378. for (node = NULL; (node = of_find_node_by_name(node, name)) != NULL;) {
  2379. if (!compat)
  2380. break;
  2381. if (of_device_is_compatible(node, compat))
  2382. break;
  2383. }
  2384. if (!node)
  2385. return;
  2386. for(i=0; i<MAX_MACIO_CHIPS; i++) {
  2387. if (!macio_chips[i].of_node)
  2388. break;
  2389. if (macio_chips[i].of_node == node)
  2390. return;
  2391. }
  2392. if (i >= MAX_MACIO_CHIPS) {
  2393. printk(KERN_ERR "pmac_feature: Please increase MAX_MACIO_CHIPS !\n");
  2394. printk(KERN_ERR "pmac_feature: %s skipped\n", node->full_name);
  2395. return;
  2396. }
  2397. addrp = of_get_pci_address(node, 0, &size, NULL);
  2398. if (addrp == NULL) {
  2399. printk(KERN_ERR "pmac_feature: %s: can't find base !\n",
  2400. node->full_name);
  2401. return;
  2402. }
  2403. addr = of_translate_address(node, addrp);
  2404. if (addr == 0) {
  2405. printk(KERN_ERR "pmac_feature: %s, can't translate base !\n",
  2406. node->full_name);
  2407. return;
  2408. }
  2409. base = ioremap(addr, (unsigned long)size);
  2410. if (!base) {
  2411. printk(KERN_ERR "pmac_feature: %s, can't map mac-io chip !\n",
  2412. node->full_name);
  2413. return;
  2414. }
  2415. if (type == macio_keylargo || type == macio_keylargo2) {
  2416. const u32 *did = of_get_property(node, "device-id", NULL);
  2417. if (*did == 0x00000025)
  2418. type = macio_pangea;
  2419. if (*did == 0x0000003e)
  2420. type = macio_intrepid;
  2421. if (*did == 0x0000004f)
  2422. type = macio_shasta;
  2423. }
  2424. macio_chips[i].of_node = node;
  2425. macio_chips[i].type = type;
  2426. macio_chips[i].base = base;
  2427. macio_chips[i].flags = MACIO_FLAG_SCCB_ON | MACIO_FLAG_SCCB_ON;
  2428. macio_chips[i].name = macio_names[type];
  2429. revp = of_get_property(node, "revision-id", NULL);
  2430. if (revp)
  2431. macio_chips[i].rev = *revp;
  2432. printk(KERN_INFO "Found a %s mac-io controller, rev: %d, mapped at 0x%p\n",
  2433. macio_names[type], macio_chips[i].rev, macio_chips[i].base);
  2434. }
  2435. static int __init
  2436. probe_macios(void)
  2437. {
  2438. /* Warning, ordering is important */
  2439. probe_one_macio("gc", NULL, macio_grand_central);
  2440. probe_one_macio("ohare", NULL, macio_ohare);
  2441. probe_one_macio("pci106b,7", NULL, macio_ohareII);
  2442. probe_one_macio("mac-io", "keylargo", macio_keylargo);
  2443. probe_one_macio("mac-io", "paddington", macio_paddington);
  2444. probe_one_macio("mac-io", "gatwick", macio_gatwick);
  2445. probe_one_macio("mac-io", "heathrow", macio_heathrow);
  2446. probe_one_macio("mac-io", "K2-Keylargo", macio_keylargo2);
  2447. /* Make sure the "main" macio chip appear first */
  2448. if (macio_chips[0].type == macio_gatwick
  2449. && macio_chips[1].type == macio_heathrow) {
  2450. struct macio_chip temp = macio_chips[0];
  2451. macio_chips[0] = macio_chips[1];
  2452. macio_chips[1] = temp;
  2453. }
  2454. if (macio_chips[0].type == macio_ohareII
  2455. && macio_chips[1].type == macio_ohare) {
  2456. struct macio_chip temp = macio_chips[0];
  2457. macio_chips[0] = macio_chips[1];
  2458. macio_chips[1] = temp;
  2459. }
  2460. macio_chips[0].lbus.index = 0;
  2461. macio_chips[1].lbus.index = 1;
  2462. return (macio_chips[0].of_node == NULL) ? -ENODEV : 0;
  2463. }
  2464. static void __init
  2465. initial_serial_shutdown(struct device_node *np)
  2466. {
  2467. int len;
  2468. const struct slot_names_prop {
  2469. int count;
  2470. char name[1];
  2471. } *slots;
  2472. const char *conn;
  2473. int port_type = PMAC_SCC_ASYNC;
  2474. int modem = 0;
  2475. slots = of_get_property(np, "slot-names", &len);
  2476. conn = of_get_property(np, "AAPL,connector", &len);
  2477. if (conn && (strcmp(conn, "infrared") == 0))
  2478. port_type = PMAC_SCC_IRDA;
  2479. else if (of_device_is_compatible(np, "cobalt"))
  2480. modem = 1;
  2481. else if (slots && slots->count > 0) {
  2482. if (strcmp(slots->name, "IrDA") == 0)
  2483. port_type = PMAC_SCC_IRDA;
  2484. else if (strcmp(slots->name, "Modem") == 0)
  2485. modem = 1;
  2486. }
  2487. if (modem)
  2488. pmac_call_feature(PMAC_FTR_MODEM_ENABLE, np, 0, 0);
  2489. pmac_call_feature(PMAC_FTR_SCC_ENABLE, np, port_type, 0);
  2490. }
  2491. static void __init
  2492. set_initial_features(void)
  2493. {
  2494. struct device_node *np;
  2495. /* That hack appears to be necessary for some StarMax motherboards
  2496. * but I'm not too sure it was audited for side-effects on other
  2497. * ohare based machines...
  2498. * Since I still have difficulties figuring the right way to
  2499. * differenciate them all and since that hack was there for a long
  2500. * time, I'll keep it around
  2501. */
  2502. if (macio_chips[0].type == macio_ohare) {
  2503. struct macio_chip *macio = &macio_chips[0];
  2504. np = of_find_node_by_name(NULL, "via-pmu");
  2505. if (np)
  2506. MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
  2507. else
  2508. MACIO_OUT32(OHARE_FCR, STARMAX_FEATURES);
  2509. of_node_put(np);
  2510. } else if (macio_chips[1].type == macio_ohare) {
  2511. struct macio_chip *macio = &macio_chips[1];
  2512. MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
  2513. }
  2514. #ifdef CONFIG_POWER4
  2515. if (macio_chips[0].type == macio_keylargo2 ||
  2516. macio_chips[0].type == macio_shasta) {
  2517. #ifndef CONFIG_SMP
  2518. /* On SMP machines running UP, we have the second CPU eating
  2519. * bus cycles. We need to take it off the bus. This is done
  2520. * from pmac_smp for SMP kernels running on one CPU
  2521. */
  2522. np = of_find_node_by_type(NULL, "cpu");
  2523. if (np != NULL)
  2524. np = of_find_node_by_type(np, "cpu");
  2525. if (np != NULL) {
  2526. g5_phy_disable_cpu1();
  2527. of_node_put(np);
  2528. }
  2529. #endif /* CONFIG_SMP */
  2530. /* Enable GMAC for now for PCI probing. It will be disabled
  2531. * later on after PCI probe
  2532. */
  2533. np = of_find_node_by_name(NULL, "ethernet");
  2534. while(np) {
  2535. if (of_device_is_compatible(np, "K2-GMAC"))
  2536. g5_gmac_enable(np, 0, 1);
  2537. np = of_find_node_by_name(np, "ethernet");
  2538. }
  2539. /* Enable FW before PCI probe. Will be disabled later on
  2540. * Note: We should have a batter way to check that we are
  2541. * dealing with uninorth internal cell and not a PCI cell
  2542. * on the external PCI. The code below works though.
  2543. */
  2544. np = of_find_node_by_name(NULL, "firewire");
  2545. while(np) {
  2546. if (of_device_is_compatible(np, "pci106b,5811")) {
  2547. macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;
  2548. g5_fw_enable(np, 0, 1);
  2549. }
  2550. np = of_find_node_by_name(np, "firewire");
  2551. }
  2552. }
  2553. #else /* CONFIG_POWER4 */
  2554. if (macio_chips[0].type == macio_keylargo ||
  2555. macio_chips[0].type == macio_pangea ||
  2556. macio_chips[0].type == macio_intrepid) {
  2557. /* Enable GMAC for now for PCI probing. It will be disabled
  2558. * later on after PCI probe
  2559. */
  2560. np = of_find_node_by_name(NULL, "ethernet");
  2561. while(np) {
  2562. if (np->parent
  2563. && of_device_is_compatible(np->parent, "uni-north")
  2564. && of_device_is_compatible(np, "gmac"))
  2565. core99_gmac_enable(np, 0, 1);
  2566. np = of_find_node_by_name(np, "ethernet");
  2567. }
  2568. /* Enable FW before PCI probe. Will be disabled later on
  2569. * Note: We should have a batter way to check that we are
  2570. * dealing with uninorth internal cell and not a PCI cell
  2571. * on the external PCI. The code below works though.
  2572. */
  2573. np = of_find_node_by_name(NULL, "firewire");
  2574. while(np) {
  2575. if (np->parent
  2576. && of_device_is_compatible(np->parent, "uni-north")
  2577. && (of_device_is_compatible(np, "pci106b,18") ||
  2578. of_device_is_compatible(np, "pci106b,30") ||
  2579. of_device_is_compatible(np, "pci11c1,5811"))) {
  2580. macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;
  2581. core99_firewire_enable(np, 0, 1);
  2582. }
  2583. np = of_find_node_by_name(np, "firewire");
  2584. }
  2585. /* Enable ATA-100 before PCI probe. */
  2586. np = of_find_node_by_name(NULL, "ata-6");
  2587. while(np) {
  2588. if (np->parent
  2589. && of_device_is_compatible(np->parent, "uni-north")
  2590. && of_device_is_compatible(np, "kauai-ata")) {
  2591. core99_ata100_enable(np, 1);
  2592. }
  2593. np = of_find_node_by_name(np, "ata-6");
  2594. }
  2595. /* Switch airport off */
  2596. for_each_node_by_name(np, "radio") {
  2597. if (np && np->parent == macio_chips[0].of_node) {
  2598. macio_chips[0].flags |= MACIO_FLAG_AIRPORT_ON;
  2599. core99_airport_enable(np, 0, 0);
  2600. }
  2601. }
  2602. of_node_put(np);
  2603. }
  2604. /* On all machines that support sound PM, switch sound off */
  2605. if (macio_chips[0].of_node)
  2606. pmac_do_feature_call(PMAC_FTR_SOUND_CHIP_ENABLE,
  2607. macio_chips[0].of_node, 0, 0);
  2608. /* While on some desktop G3s, we turn it back on */
  2609. if (macio_chips[0].of_node && macio_chips[0].type == macio_heathrow
  2610. && (pmac_mb.model_id == PMAC_TYPE_GOSSAMER ||
  2611. pmac_mb.model_id == PMAC_TYPE_SILK)) {
  2612. struct macio_chip *macio = &macio_chips[0];
  2613. MACIO_BIS(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
  2614. MACIO_BIC(HEATHROW_FCR, HRW_SOUND_POWER_N);
  2615. }
  2616. #endif /* CONFIG_POWER4 */
  2617. /* On all machines, switch modem & serial ports off */
  2618. for_each_node_by_name(np, "ch-a")
  2619. initial_serial_shutdown(np);
  2620. of_node_put(np);
  2621. for_each_node_by_name(np, "ch-b")
  2622. initial_serial_shutdown(np);
  2623. of_node_put(np);
  2624. }
  2625. void __init
  2626. pmac_feature_init(void)
  2627. {
  2628. /* Detect the UniNorth memory controller */
  2629. probe_uninorth();
  2630. /* Probe mac-io controllers */
  2631. if (probe_macios()) {
  2632. printk(KERN_WARNING "No mac-io chip found\n");
  2633. return;
  2634. }
  2635. /* Probe machine type */
  2636. if (probe_motherboard())
  2637. printk(KERN_WARNING "Unknown PowerMac !\n");
  2638. /* Set some initial features (turn off some chips that will
  2639. * be later turned on)
  2640. */
  2641. set_initial_features();
  2642. }
  2643. #if 0
  2644. static void dump_HT_speeds(char *name, u32 cfg, u32 frq)
  2645. {
  2646. int freqs[16] = { 200,300,400,500,600,800,1000,0,0,0,0,0,0,0,0,0 };
  2647. int bits[8] = { 8,16,0,32,2,4,0,0 };
  2648. int freq = (frq >> 8) & 0xf;
  2649. if (freqs[freq] == 0)
  2650. printk("%s: Unknown HT link frequency %x\n", name, freq);
  2651. else
  2652. printk("%s: %d MHz on main link, (%d in / %d out) bits width\n",
  2653. name, freqs[freq],
  2654. bits[(cfg >> 28) & 0x7], bits[(cfg >> 24) & 0x7]);
  2655. }
  2656. void __init pmac_check_ht_link(void)
  2657. {
  2658. u32 ufreq, freq, ucfg, cfg;
  2659. struct device_node *pcix_node;
  2660. u8 px_bus, px_devfn;
  2661. struct pci_controller *px_hose;
  2662. (void)in_be32(u3_ht_base + U3_HT_LINK_COMMAND);
  2663. ucfg = cfg = in_be32(u3_ht_base + U3_HT_LINK_CONFIG);
  2664. ufreq = freq = in_be32(u3_ht_base + U3_HT_LINK_FREQ);
  2665. dump_HT_speeds("U3 HyperTransport", cfg, freq);
  2666. pcix_node = of_find_compatible_node(NULL, "pci", "pci-x");
  2667. if (pcix_node == NULL) {
  2668. printk("No PCI-X bridge found\n");
  2669. return;
  2670. }
  2671. if (pci_device_from_OF_node(pcix_node, &px_bus, &px_devfn) != 0) {
  2672. printk("PCI-X bridge found but not matched to pci\n");
  2673. return;
  2674. }
  2675. px_hose = pci_find_hose_for_OF_device(pcix_node);
  2676. if (px_hose == NULL) {
  2677. printk("PCI-X bridge found but not matched to host\n");
  2678. return;
  2679. }
  2680. early_read_config_dword(px_hose, px_bus, px_devfn, 0xc4, &cfg);
  2681. early_read_config_dword(px_hose, px_bus, px_devfn, 0xcc, &freq);
  2682. dump_HT_speeds("PCI-X HT Uplink", cfg, freq);
  2683. early_read_config_dword(px_hose, px_bus, px_devfn, 0xc8, &cfg);
  2684. early_read_config_dword(px_hose, px_bus, px_devfn, 0xd0, &freq);
  2685. dump_HT_speeds("PCI-X HT Downlink", cfg, freq);
  2686. }
  2687. #endif /* 0 */
  2688. /*
  2689. * Early video resume hook
  2690. */
  2691. static void (*pmac_early_vresume_proc)(void *data);
  2692. static void *pmac_early_vresume_data;
  2693. void pmac_set_early_video_resume(void (*proc)(void *data), void *data)
  2694. {
  2695. if (!machine_is(powermac))
  2696. return;
  2697. preempt_disable();
  2698. pmac_early_vresume_proc = proc;
  2699. pmac_early_vresume_data = data;
  2700. preempt_enable();
  2701. }
  2702. EXPORT_SYMBOL(pmac_set_early_video_resume);
  2703. void pmac_call_early_video_resume(void)
  2704. {
  2705. if (pmac_early_vresume_proc)
  2706. pmac_early_vresume_proc(pmac_early_vresume_data);
  2707. }
  2708. /*
  2709. * AGP related suspend/resume code
  2710. */
  2711. static struct pci_dev *pmac_agp_bridge;
  2712. static int (*pmac_agp_suspend)(struct pci_dev *bridge);
  2713. static int (*pmac_agp_resume)(struct pci_dev *bridge);
  2714. void pmac_register_agp_pm(struct pci_dev *bridge,
  2715. int (*suspend)(struct pci_dev *bridge),
  2716. int (*resume)(struct pci_dev *bridge))
  2717. {
  2718. if (suspend || resume) {
  2719. pmac_agp_bridge = bridge;
  2720. pmac_agp_suspend = suspend;
  2721. pmac_agp_resume = resume;
  2722. return;
  2723. }
  2724. if (bridge != pmac_agp_bridge)
  2725. return;
  2726. pmac_agp_suspend = pmac_agp_resume = NULL;
  2727. return;
  2728. }
  2729. EXPORT_SYMBOL(pmac_register_agp_pm);
  2730. void pmac_suspend_agp_for_card(struct pci_dev *dev)
  2731. {
  2732. if (pmac_agp_bridge == NULL || pmac_agp_suspend == NULL)
  2733. return;
  2734. if (pmac_agp_bridge->bus != dev->bus)
  2735. return;
  2736. pmac_agp_suspend(pmac_agp_bridge);
  2737. }
  2738. EXPORT_SYMBOL(pmac_suspend_agp_for_card);
  2739. void pmac_resume_agp_for_card(struct pci_dev *dev)
  2740. {
  2741. if (pmac_agp_bridge == NULL || pmac_agp_resume == NULL)
  2742. return;
  2743. if (pmac_agp_bridge->bus != dev->bus)
  2744. return;
  2745. pmac_agp_resume(pmac_agp_bridge);
  2746. }
  2747. EXPORT_SYMBOL(pmac_resume_agp_for_card);