feature.c 80 KB

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