feature.c 80 KB

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