feature.c 80 KB

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