feature.c 80 KB

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