pmac_feature.c 81 KB

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