pmac_feature.c 81 KB

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