feature.c 80 KB

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