feature.c 82 KB

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