feature.c 80 KB

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