feature.c 84 KB

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