feature.c 80 KB

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