feature.c 79 KB

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