feature.c 82 KB

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