Path: blob/master/arch/powerpc/platforms/powermac/feature.c
26481 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Copyright (C) 1996-2001 Paul Mackerras ([email protected])3* Ben. Herrenschmidt ([email protected])4*5* TODO:6*7* - Replace mdelay with some schedule loop if possible8* - Shorten some obfuscated delays on some routines (like modem9* power)10* - Refcount some clocks (see darwin)11* - Split split split...12*/13#include <linux/types.h>14#include <linux/init.h>15#include <linux/delay.h>16#include <linux/kernel.h>17#include <linux/sched.h>18#include <linux/of.h>19#include <linux/of_address.h>20#include <linux/spinlock.h>21#include <linux/adb.h>22#include <linux/pmu.h>23#include <linux/ioport.h>24#include <linux/export.h>25#include <linux/pci.h>26#include <asm/sections.h>27#include <asm/errno.h>28#include <asm/ohare.h>29#include <asm/heathrow.h>30#include <asm/keylargo.h>31#include <asm/uninorth.h>32#include <asm/io.h>33#include <asm/machdep.h>34#include <asm/pmac_feature.h>35#include <asm/dbdma.h>36#include <asm/pci-bridge.h>37#include <asm/pmac_low_i2c.h>3839#include "pmac.h"4041#undef DEBUG_FEATURE4243#ifdef DEBUG_FEATURE44#define DBG(fmt...) printk(KERN_DEBUG fmt)45#else46#define DBG(fmt...)47#endif4849#ifdef CONFIG_PPC_BOOK3S_3250extern int powersave_lowspeed;51#endif5253extern int powersave_nap;54extern struct device_node *k2_skiplist[2];5556/*57* We use a single global lock to protect accesses. Each driver has58* to take care of its own locking59*/60DEFINE_RAW_SPINLOCK(feature_lock);6162#define LOCK(flags) raw_spin_lock_irqsave(&feature_lock, flags);63#define UNLOCK(flags) raw_spin_unlock_irqrestore(&feature_lock, flags);646566/*67* Instance of some macio stuffs68*/69struct macio_chip macio_chips[MAX_MACIO_CHIPS];7071struct macio_chip *macio_find(struct device_node *child, int type)72{73while(child) {74int i;7576for (i=0; i < MAX_MACIO_CHIPS && macio_chips[i].of_node; i++)77if (child == macio_chips[i].of_node &&78(!type || macio_chips[i].type == type))79return &macio_chips[i];80child = child->parent;81}82return NULL;83}84EXPORT_SYMBOL_GPL(macio_find);8586static const char *macio_names[] =87{88"Unknown",89"Grand Central",90"OHare",91"OHareII",92"Heathrow",93"Gatwick",94"Paddington",95"Keylargo",96"Pangea",97"Intrepid",98"K2",99"Shasta",100};101102103struct device_node *uninorth_node;104u32 __iomem *uninorth_base;105106static u32 uninorth_rev;107static int uninorth_maj;108static void __iomem *u3_ht_base;109110/*111* For each motherboard family, we have a table of functions pointers112* that handle the various features.113*/114115typedef long (*feature_call)(struct device_node *node, long param, long value);116117struct feature_table_entry {118unsigned int selector;119feature_call function;120};121122struct pmac_mb_def123{124const char* model_string;125const char* model_name;126int model_id;127struct feature_table_entry* features;128unsigned long board_flags;129};130static struct pmac_mb_def pmac_mb;131132/*133* Here are the chip specific feature functions134*/135136#ifndef CONFIG_PPC64137138static int simple_feature_tweak(struct device_node *node, int type, int reg,139u32 mask, int value)140{141struct macio_chip* macio;142unsigned long flags;143144macio = macio_find(node, type);145if (!macio)146return -ENODEV;147LOCK(flags);148if (value)149MACIO_BIS(reg, mask);150else151MACIO_BIC(reg, mask);152(void)MACIO_IN32(reg);153UNLOCK(flags);154155return 0;156}157158static long ohare_htw_scc_enable(struct device_node *node, long param,159long value)160{161struct macio_chip* macio;162unsigned long chan_mask;163unsigned long fcr;164unsigned long flags;165int htw, trans;166unsigned long rmask;167168macio = macio_find(node, 0);169if (!macio)170return -ENODEV;171if (of_node_name_eq(node, "ch-a"))172chan_mask = MACIO_FLAG_SCCA_ON;173else if (of_node_name_eq(node, "ch-b"))174chan_mask = MACIO_FLAG_SCCB_ON;175else176return -ENODEV;177178htw = (macio->type == macio_heathrow || macio->type == macio_paddington179|| macio->type == macio_gatwick);180/* On these machines, the HRW_SCC_TRANS_EN_N bit mustn't be touched */181trans = (pmac_mb.model_id != PMAC_TYPE_YOSEMITE &&182pmac_mb.model_id != PMAC_TYPE_YIKES);183if (value) {184#ifdef CONFIG_ADB_PMU185if ((param & 0xfff) == PMAC_SCC_IRDA)186pmu_enable_irled(1);187#endif /* CONFIG_ADB_PMU */188LOCK(flags);189fcr = MACIO_IN32(OHARE_FCR);190/* Check if scc cell need enabling */191if (!(fcr & OH_SCC_ENABLE)) {192fcr |= OH_SCC_ENABLE;193if (htw) {194/* Side effect: this will also power up the195* modem, but it's too messy to figure out on which196* ports this controls the transceiver and on which197* it controls the modem198*/199if (trans)200fcr &= ~HRW_SCC_TRANS_EN_N;201MACIO_OUT32(OHARE_FCR, fcr);202fcr |= (rmask = HRW_RESET_SCC);203MACIO_OUT32(OHARE_FCR, fcr);204} else {205fcr |= (rmask = OH_SCC_RESET);206MACIO_OUT32(OHARE_FCR, fcr);207}208UNLOCK(flags);209(void)MACIO_IN32(OHARE_FCR);210mdelay(15);211LOCK(flags);212fcr &= ~rmask;213MACIO_OUT32(OHARE_FCR, fcr);214}215if (chan_mask & MACIO_FLAG_SCCA_ON)216fcr |= OH_SCCA_IO;217if (chan_mask & MACIO_FLAG_SCCB_ON)218fcr |= OH_SCCB_IO;219MACIO_OUT32(OHARE_FCR, fcr);220macio->flags |= chan_mask;221UNLOCK(flags);222if (param & PMAC_SCC_FLAG_XMON)223macio->flags |= MACIO_FLAG_SCC_LOCKED;224} else {225if (macio->flags & MACIO_FLAG_SCC_LOCKED)226return -EPERM;227LOCK(flags);228fcr = MACIO_IN32(OHARE_FCR);229if (chan_mask & MACIO_FLAG_SCCA_ON)230fcr &= ~OH_SCCA_IO;231if (chan_mask & MACIO_FLAG_SCCB_ON)232fcr &= ~OH_SCCB_IO;233MACIO_OUT32(OHARE_FCR, fcr);234if ((fcr & (OH_SCCA_IO | OH_SCCB_IO)) == 0) {235fcr &= ~OH_SCC_ENABLE;236if (htw && trans)237fcr |= HRW_SCC_TRANS_EN_N;238MACIO_OUT32(OHARE_FCR, fcr);239}240macio->flags &= ~(chan_mask);241UNLOCK(flags);242mdelay(10);243#ifdef CONFIG_ADB_PMU244if ((param & 0xfff) == PMAC_SCC_IRDA)245pmu_enable_irled(0);246#endif /* CONFIG_ADB_PMU */247}248return 0;249}250251static long ohare_floppy_enable(struct device_node *node, long param,252long value)253{254return simple_feature_tweak(node, macio_ohare,255OHARE_FCR, OH_FLOPPY_ENABLE, value);256}257258static long ohare_mesh_enable(struct device_node *node, long param, long value)259{260return simple_feature_tweak(node, macio_ohare,261OHARE_FCR, OH_MESH_ENABLE, value);262}263264static long ohare_ide_enable(struct device_node *node, long param, long value)265{266switch(param) {267case 0:268/* For some reason, setting the bit in set_initial_features()269* doesn't stick. I'm still investigating... --BenH.270*/271if (value)272simple_feature_tweak(node, macio_ohare,273OHARE_FCR, OH_IOBUS_ENABLE, 1);274return simple_feature_tweak(node, macio_ohare,275OHARE_FCR, OH_IDE0_ENABLE, value);276case 1:277return simple_feature_tweak(node, macio_ohare,278OHARE_FCR, OH_BAY_IDE_ENABLE, value);279default:280return -ENODEV;281}282}283284static long ohare_ide_reset(struct device_node *node, long param, long value)285{286switch(param) {287case 0:288return simple_feature_tweak(node, macio_ohare,289OHARE_FCR, OH_IDE0_RESET_N, !value);290case 1:291return simple_feature_tweak(node, macio_ohare,292OHARE_FCR, OH_IDE1_RESET_N, !value);293default:294return -ENODEV;295}296}297298static long ohare_sleep_state(struct device_node *node, long param, long value)299{300struct macio_chip* macio = &macio_chips[0];301302if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)303return -EPERM;304if (value == 1) {305MACIO_BIC(OHARE_FCR, OH_IOBUS_ENABLE);306} else if (value == 0) {307MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);308}309310return 0;311}312313static long heathrow_modem_enable(struct device_node *node, long param,314long value)315{316struct macio_chip* macio;317u8 gpio;318unsigned long flags;319320macio = macio_find(node, macio_unknown);321if (!macio)322return -ENODEV;323gpio = MACIO_IN8(HRW_GPIO_MODEM_RESET) & ~1;324if (!value) {325LOCK(flags);326MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio);327UNLOCK(flags);328(void)MACIO_IN8(HRW_GPIO_MODEM_RESET);329mdelay(250);330}331if (pmac_mb.model_id != PMAC_TYPE_YOSEMITE &&332pmac_mb.model_id != PMAC_TYPE_YIKES) {333LOCK(flags);334if (value)335MACIO_BIC(HEATHROW_FCR, HRW_SCC_TRANS_EN_N);336else337MACIO_BIS(HEATHROW_FCR, HRW_SCC_TRANS_EN_N);338UNLOCK(flags);339(void)MACIO_IN32(HEATHROW_FCR);340mdelay(250);341}342if (value) {343LOCK(flags);344MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio | 1);345(void)MACIO_IN8(HRW_GPIO_MODEM_RESET);346UNLOCK(flags); mdelay(250); LOCK(flags);347MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio);348(void)MACIO_IN8(HRW_GPIO_MODEM_RESET);349UNLOCK(flags); mdelay(250); LOCK(flags);350MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio | 1);351(void)MACIO_IN8(HRW_GPIO_MODEM_RESET);352UNLOCK(flags); mdelay(250);353}354return 0;355}356357static long heathrow_floppy_enable(struct device_node *node, long param,358long value)359{360return simple_feature_tweak(node, macio_unknown,361HEATHROW_FCR,362HRW_SWIM_ENABLE|HRW_BAY_FLOPPY_ENABLE,363value);364}365366static long heathrow_mesh_enable(struct device_node *node, long param,367long value)368{369struct macio_chip* macio;370unsigned long flags;371372macio = macio_find(node, macio_unknown);373if (!macio)374return -ENODEV;375LOCK(flags);376/* Set clear mesh cell enable */377if (value)378MACIO_BIS(HEATHROW_FCR, HRW_MESH_ENABLE);379else380MACIO_BIC(HEATHROW_FCR, HRW_MESH_ENABLE);381(void)MACIO_IN32(HEATHROW_FCR);382udelay(10);383/* Set/Clear termination power */384if (value)385MACIO_BIC(HEATHROW_MBCR, 0x04000000);386else387MACIO_BIS(HEATHROW_MBCR, 0x04000000);388(void)MACIO_IN32(HEATHROW_MBCR);389udelay(10);390UNLOCK(flags);391392return 0;393}394395static long heathrow_ide_enable(struct device_node *node, long param,396long value)397{398switch(param) {399case 0:400return simple_feature_tweak(node, macio_unknown,401HEATHROW_FCR, HRW_IDE0_ENABLE, value);402case 1:403return simple_feature_tweak(node, macio_unknown,404HEATHROW_FCR, HRW_BAY_IDE_ENABLE, value);405default:406return -ENODEV;407}408}409410static long heathrow_ide_reset(struct device_node *node, long param,411long value)412{413switch(param) {414case 0:415return simple_feature_tweak(node, macio_unknown,416HEATHROW_FCR, HRW_IDE0_RESET_N, !value);417case 1:418return simple_feature_tweak(node, macio_unknown,419HEATHROW_FCR, HRW_IDE1_RESET_N, !value);420default:421return -ENODEV;422}423}424425static long heathrow_bmac_enable(struct device_node *node, long param,426long value)427{428struct macio_chip* macio;429unsigned long flags;430431macio = macio_find(node, 0);432if (!macio)433return -ENODEV;434if (value) {435LOCK(flags);436MACIO_BIS(HEATHROW_FCR, HRW_BMAC_IO_ENABLE);437MACIO_BIS(HEATHROW_FCR, HRW_BMAC_RESET);438UNLOCK(flags);439(void)MACIO_IN32(HEATHROW_FCR);440mdelay(10);441LOCK(flags);442MACIO_BIC(HEATHROW_FCR, HRW_BMAC_RESET);443UNLOCK(flags);444(void)MACIO_IN32(HEATHROW_FCR);445mdelay(10);446} else {447LOCK(flags);448MACIO_BIC(HEATHROW_FCR, HRW_BMAC_IO_ENABLE);449UNLOCK(flags);450}451return 0;452}453454static long heathrow_sound_enable(struct device_node *node, long param,455long value)456{457struct macio_chip* macio;458unsigned long flags;459460/* B&W G3 and Yikes don't support that properly (the461* sound appear to never come back after being shut down).462*/463if (pmac_mb.model_id == PMAC_TYPE_YOSEMITE ||464pmac_mb.model_id == PMAC_TYPE_YIKES)465return 0;466467macio = macio_find(node, 0);468if (!macio)469return -ENODEV;470if (value) {471LOCK(flags);472MACIO_BIS(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);473MACIO_BIC(HEATHROW_FCR, HRW_SOUND_POWER_N);474UNLOCK(flags);475(void)MACIO_IN32(HEATHROW_FCR);476} else {477LOCK(flags);478MACIO_BIS(HEATHROW_FCR, HRW_SOUND_POWER_N);479MACIO_BIC(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);480UNLOCK(flags);481}482return 0;483}484485static u32 save_fcr[6];486static u32 save_mbcr;487static struct dbdma_regs save_dbdma[13];488static struct dbdma_regs save_alt_dbdma[13];489490static void dbdma_save(struct macio_chip *macio, struct dbdma_regs *save)491{492int i;493494/* Save state & config of DBDMA channels */495for (i = 0; i < 13; i++) {496volatile struct dbdma_regs __iomem * chan = (void __iomem *)497(macio->base + ((0x8000+i*0x100)>>2));498save[i].cmdptr_hi = in_le32(&chan->cmdptr_hi);499save[i].cmdptr = in_le32(&chan->cmdptr);500save[i].intr_sel = in_le32(&chan->intr_sel);501save[i].br_sel = in_le32(&chan->br_sel);502save[i].wait_sel = in_le32(&chan->wait_sel);503}504}505506static void dbdma_restore(struct macio_chip *macio, struct dbdma_regs *save)507{508int i;509510/* Save state & config of DBDMA channels */511for (i = 0; i < 13; i++) {512volatile struct dbdma_regs __iomem * chan = (void __iomem *)513(macio->base + ((0x8000+i*0x100)>>2));514out_le32(&chan->control, (ACTIVE|DEAD|WAKE|FLUSH|PAUSE|RUN)<<16);515while (in_le32(&chan->status) & ACTIVE)516mb();517out_le32(&chan->cmdptr_hi, save[i].cmdptr_hi);518out_le32(&chan->cmdptr, save[i].cmdptr);519out_le32(&chan->intr_sel, save[i].intr_sel);520out_le32(&chan->br_sel, save[i].br_sel);521out_le32(&chan->wait_sel, save[i].wait_sel);522}523}524525static void heathrow_sleep(struct macio_chip *macio, int secondary)526{527if (secondary) {528dbdma_save(macio, save_alt_dbdma);529save_fcr[2] = MACIO_IN32(0x38);530save_fcr[3] = MACIO_IN32(0x3c);531} else {532dbdma_save(macio, save_dbdma);533save_fcr[0] = MACIO_IN32(0x38);534save_fcr[1] = MACIO_IN32(0x3c);535save_mbcr = MACIO_IN32(0x34);536/* Make sure sound is shut down */537MACIO_BIS(HEATHROW_FCR, HRW_SOUND_POWER_N);538MACIO_BIC(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);539/* This seems to be necessary as well or the fan540* keeps coming up and battery drains fast */541MACIO_BIC(HEATHROW_FCR, HRW_IOBUS_ENABLE);542MACIO_BIC(HEATHROW_FCR, HRW_IDE0_RESET_N);543/* Make sure eth is down even if module or sleep544* won't work properly */545MACIO_BIC(HEATHROW_FCR, HRW_BMAC_IO_ENABLE | HRW_BMAC_RESET);546}547/* Make sure modem is shut down */548MACIO_OUT8(HRW_GPIO_MODEM_RESET,549MACIO_IN8(HRW_GPIO_MODEM_RESET) & ~1);550MACIO_BIS(HEATHROW_FCR, HRW_SCC_TRANS_EN_N);551MACIO_BIC(HEATHROW_FCR, OH_SCCA_IO|OH_SCCB_IO|HRW_SCC_ENABLE);552553/* Let things settle */554(void)MACIO_IN32(HEATHROW_FCR);555}556557static void heathrow_wakeup(struct macio_chip *macio, int secondary)558{559if (secondary) {560MACIO_OUT32(0x38, save_fcr[2]);561(void)MACIO_IN32(0x38);562mdelay(1);563MACIO_OUT32(0x3c, save_fcr[3]);564(void)MACIO_IN32(0x38);565mdelay(10);566dbdma_restore(macio, save_alt_dbdma);567} else {568MACIO_OUT32(0x38, save_fcr[0] | HRW_IOBUS_ENABLE);569(void)MACIO_IN32(0x38);570mdelay(1);571MACIO_OUT32(0x3c, save_fcr[1]);572(void)MACIO_IN32(0x38);573mdelay(1);574MACIO_OUT32(0x34, save_mbcr);575(void)MACIO_IN32(0x38);576mdelay(10);577dbdma_restore(macio, save_dbdma);578}579}580581static long heathrow_sleep_state(struct device_node *node, long param,582long value)583{584if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)585return -EPERM;586if (value == 1) {587if (macio_chips[1].type == macio_gatwick)588heathrow_sleep(&macio_chips[0], 1);589heathrow_sleep(&macio_chips[0], 0);590} else if (value == 0) {591heathrow_wakeup(&macio_chips[0], 0);592if (macio_chips[1].type == macio_gatwick)593heathrow_wakeup(&macio_chips[0], 1);594}595return 0;596}597598static long core99_scc_enable(struct device_node *node, long param, long value)599{600struct macio_chip* macio;601unsigned long flags;602unsigned long chan_mask;603u32 fcr;604605macio = macio_find(node, 0);606if (!macio)607return -ENODEV;608if (of_node_name_eq(node, "ch-a"))609chan_mask = MACIO_FLAG_SCCA_ON;610else if (of_node_name_eq(node, "ch-b"))611chan_mask = MACIO_FLAG_SCCB_ON;612else613return -ENODEV;614615if (value) {616int need_reset_scc = 0;617int need_reset_irda = 0;618619LOCK(flags);620fcr = MACIO_IN32(KEYLARGO_FCR0);621/* Check if scc cell need enabling */622if (!(fcr & KL0_SCC_CELL_ENABLE)) {623fcr |= KL0_SCC_CELL_ENABLE;624need_reset_scc = 1;625}626if (chan_mask & MACIO_FLAG_SCCA_ON) {627fcr |= KL0_SCCA_ENABLE;628/* Don't enable line drivers for I2S modem */629if ((param & 0xfff) == PMAC_SCC_I2S1)630fcr &= ~KL0_SCC_A_INTF_ENABLE;631else632fcr |= KL0_SCC_A_INTF_ENABLE;633}634if (chan_mask & MACIO_FLAG_SCCB_ON) {635fcr |= KL0_SCCB_ENABLE;636/* Perform irda specific inits */637if ((param & 0xfff) == PMAC_SCC_IRDA) {638fcr &= ~KL0_SCC_B_INTF_ENABLE;639fcr |= KL0_IRDA_ENABLE;640fcr |= KL0_IRDA_CLK32_ENABLE | KL0_IRDA_CLK19_ENABLE;641fcr |= KL0_IRDA_SOURCE1_SEL;642fcr &= ~(KL0_IRDA_FAST_CONNECT|KL0_IRDA_DEFAULT1|KL0_IRDA_DEFAULT0);643fcr &= ~(KL0_IRDA_SOURCE2_SEL|KL0_IRDA_HIGH_BAND);644need_reset_irda = 1;645} else646fcr |= KL0_SCC_B_INTF_ENABLE;647}648MACIO_OUT32(KEYLARGO_FCR0, fcr);649macio->flags |= chan_mask;650if (need_reset_scc) {651MACIO_BIS(KEYLARGO_FCR0, KL0_SCC_RESET);652(void)MACIO_IN32(KEYLARGO_FCR0);653UNLOCK(flags);654mdelay(15);655LOCK(flags);656MACIO_BIC(KEYLARGO_FCR0, KL0_SCC_RESET);657}658if (need_reset_irda) {659MACIO_BIS(KEYLARGO_FCR0, KL0_IRDA_RESET);660(void)MACIO_IN32(KEYLARGO_FCR0);661UNLOCK(flags);662mdelay(15);663LOCK(flags);664MACIO_BIC(KEYLARGO_FCR0, KL0_IRDA_RESET);665}666UNLOCK(flags);667if (param & PMAC_SCC_FLAG_XMON)668macio->flags |= MACIO_FLAG_SCC_LOCKED;669} else {670if (macio->flags & MACIO_FLAG_SCC_LOCKED)671return -EPERM;672LOCK(flags);673fcr = MACIO_IN32(KEYLARGO_FCR0);674if (chan_mask & MACIO_FLAG_SCCA_ON)675fcr &= ~KL0_SCCA_ENABLE;676if (chan_mask & MACIO_FLAG_SCCB_ON) {677fcr &= ~KL0_SCCB_ENABLE;678/* Perform irda specific clears */679if ((param & 0xfff) == PMAC_SCC_IRDA) {680fcr &= ~KL0_IRDA_ENABLE;681fcr &= ~(KL0_IRDA_CLK32_ENABLE | KL0_IRDA_CLK19_ENABLE);682fcr &= ~(KL0_IRDA_FAST_CONNECT|KL0_IRDA_DEFAULT1|KL0_IRDA_DEFAULT0);683fcr &= ~(KL0_IRDA_SOURCE1_SEL|KL0_IRDA_SOURCE2_SEL|KL0_IRDA_HIGH_BAND);684}685}686MACIO_OUT32(KEYLARGO_FCR0, fcr);687if ((fcr & (KL0_SCCA_ENABLE | KL0_SCCB_ENABLE)) == 0) {688fcr &= ~KL0_SCC_CELL_ENABLE;689MACIO_OUT32(KEYLARGO_FCR0, fcr);690}691macio->flags &= ~(chan_mask);692UNLOCK(flags);693mdelay(10);694}695return 0;696}697698static long699core99_modem_enable(struct device_node *node, long param, long value)700{701struct macio_chip* macio;702u8 gpio;703unsigned long flags;704705/* Hack for internal USB modem */706if (node == NULL) {707if (macio_chips[0].type != macio_keylargo)708return -ENODEV;709node = macio_chips[0].of_node;710}711macio = macio_find(node, 0);712if (!macio)713return -ENODEV;714gpio = MACIO_IN8(KL_GPIO_MODEM_RESET);715gpio |= KEYLARGO_GPIO_OUTPUT_ENABLE;716gpio &= ~KEYLARGO_GPIO_OUTOUT_DATA;717718if (!value) {719LOCK(flags);720MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);721UNLOCK(flags);722(void)MACIO_IN8(KL_GPIO_MODEM_RESET);723mdelay(250);724}725LOCK(flags);726if (value) {727MACIO_BIC(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);728UNLOCK(flags);729(void)MACIO_IN32(KEYLARGO_FCR2);730mdelay(250);731} else {732MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);733UNLOCK(flags);734}735if (value) {736LOCK(flags);737MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);738(void)MACIO_IN8(KL_GPIO_MODEM_RESET);739UNLOCK(flags); mdelay(250); LOCK(flags);740MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);741(void)MACIO_IN8(KL_GPIO_MODEM_RESET);742UNLOCK(flags); mdelay(250); LOCK(flags);743MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);744(void)MACIO_IN8(KL_GPIO_MODEM_RESET);745UNLOCK(flags); mdelay(250);746}747return 0;748}749750static long751pangea_modem_enable(struct device_node *node, long param, long value)752{753struct macio_chip* macio;754u8 gpio;755unsigned long flags;756757/* Hack for internal USB modem */758if (node == NULL) {759if (macio_chips[0].type != macio_pangea &&760macio_chips[0].type != macio_intrepid)761return -ENODEV;762node = macio_chips[0].of_node;763}764macio = macio_find(node, 0);765if (!macio)766return -ENODEV;767gpio = MACIO_IN8(KL_GPIO_MODEM_RESET);768gpio |= KEYLARGO_GPIO_OUTPUT_ENABLE;769gpio &= ~KEYLARGO_GPIO_OUTOUT_DATA;770771if (!value) {772LOCK(flags);773MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);774UNLOCK(flags);775(void)MACIO_IN8(KL_GPIO_MODEM_RESET);776mdelay(250);777}778LOCK(flags);779if (value) {780MACIO_OUT8(KL_GPIO_MODEM_POWER,781KEYLARGO_GPIO_OUTPUT_ENABLE);782UNLOCK(flags);783(void)MACIO_IN32(KEYLARGO_FCR2);784mdelay(250);785} else {786MACIO_OUT8(KL_GPIO_MODEM_POWER,787KEYLARGO_GPIO_OUTPUT_ENABLE | KEYLARGO_GPIO_OUTOUT_DATA);788UNLOCK(flags);789}790if (value) {791LOCK(flags);792MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);793(void)MACIO_IN8(KL_GPIO_MODEM_RESET);794UNLOCK(flags); mdelay(250); LOCK(flags);795MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);796(void)MACIO_IN8(KL_GPIO_MODEM_RESET);797UNLOCK(flags); mdelay(250); LOCK(flags);798MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);799(void)MACIO_IN8(KL_GPIO_MODEM_RESET);800UNLOCK(flags); mdelay(250);801}802return 0;803}804805static long806core99_ata100_enable(struct device_node *node, long value)807{808unsigned long flags;809struct pci_dev *pdev = NULL;810u8 pbus, pid;811int rc;812813if (uninorth_rev < 0x24)814return -ENODEV;815816LOCK(flags);817if (value)818UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_ATA100);819else820UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_ATA100);821(void)UN_IN(UNI_N_CLOCK_CNTL);822UNLOCK(flags);823udelay(20);824825if (value) {826if (pci_device_from_OF_node(node, &pbus, &pid) == 0)827pdev = pci_get_domain_bus_and_slot(0, pbus, pid);828if (pdev == NULL)829return 0;830rc = pci_enable_device(pdev);831if (rc == 0)832pci_set_master(pdev);833pci_dev_put(pdev);834if (rc)835return rc;836}837return 0;838}839840static long841core99_ide_enable(struct device_node *node, long param, long value)842{843/* Bus ID 0 to 2 are KeyLargo based IDE, busID 3 is U2844* based ata-100845*/846switch(param) {847case 0:848return simple_feature_tweak(node, macio_unknown,849KEYLARGO_FCR1, KL1_EIDE0_ENABLE, value);850case 1:851return simple_feature_tweak(node, macio_unknown,852KEYLARGO_FCR1, KL1_EIDE1_ENABLE, value);853case 2:854return simple_feature_tweak(node, macio_unknown,855KEYLARGO_FCR1, KL1_UIDE_ENABLE, value);856case 3:857return core99_ata100_enable(node, value);858default:859return -ENODEV;860}861}862863static long864core99_ide_reset(struct device_node *node, long param, long value)865{866switch(param) {867case 0:868return simple_feature_tweak(node, macio_unknown,869KEYLARGO_FCR1, KL1_EIDE0_RESET_N, !value);870case 1:871return simple_feature_tweak(node, macio_unknown,872KEYLARGO_FCR1, KL1_EIDE1_RESET_N, !value);873case 2:874return simple_feature_tweak(node, macio_unknown,875KEYLARGO_FCR1, KL1_UIDE_RESET_N, !value);876default:877return -ENODEV;878}879}880881static long882core99_gmac_enable(struct device_node *node, long param, long value)883{884unsigned long flags;885886LOCK(flags);887if (value)888UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_GMAC);889else890UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_GMAC);891(void)UN_IN(UNI_N_CLOCK_CNTL);892UNLOCK(flags);893udelay(20);894895return 0;896}897898static long899core99_gmac_phy_reset(struct device_node *node, long param, long value)900{901unsigned long flags;902struct macio_chip *macio;903904macio = &macio_chips[0];905if (macio->type != macio_keylargo && macio->type != macio_pangea &&906macio->type != macio_intrepid)907return -ENODEV;908909LOCK(flags);910MACIO_OUT8(KL_GPIO_ETH_PHY_RESET, KEYLARGO_GPIO_OUTPUT_ENABLE);911(void)MACIO_IN8(KL_GPIO_ETH_PHY_RESET);912UNLOCK(flags);913mdelay(10);914LOCK(flags);915MACIO_OUT8(KL_GPIO_ETH_PHY_RESET, /*KEYLARGO_GPIO_OUTPUT_ENABLE | */916KEYLARGO_GPIO_OUTOUT_DATA);917UNLOCK(flags);918mdelay(10);919920return 0;921}922923static long924core99_sound_chip_enable(struct device_node *node, long param, long value)925{926struct macio_chip* macio;927unsigned long flags;928929macio = macio_find(node, 0);930if (!macio)931return -ENODEV;932933/* Do a better probe code, screamer G4 desktops &934* iMacs can do that too, add a recalibrate in935* the driver as well936*/937if (pmac_mb.model_id == PMAC_TYPE_PISMO ||938pmac_mb.model_id == PMAC_TYPE_TITANIUM) {939LOCK(flags);940if (value)941MACIO_OUT8(KL_GPIO_SOUND_POWER,942KEYLARGO_GPIO_OUTPUT_ENABLE |943KEYLARGO_GPIO_OUTOUT_DATA);944else945MACIO_OUT8(KL_GPIO_SOUND_POWER,946KEYLARGO_GPIO_OUTPUT_ENABLE);947(void)MACIO_IN8(KL_GPIO_SOUND_POWER);948UNLOCK(flags);949}950return 0;951}952953static long954core99_airport_enable(struct device_node *node, long param, long value)955{956struct macio_chip* macio;957unsigned long flags;958int state;959960macio = macio_find(node, 0);961if (!macio)962return -ENODEV;963964/* Hint: we allow passing of macio itself for the sake of the965* sleep code966*/967if (node != macio->of_node &&968(!node->parent || node->parent != macio->of_node))969return -ENODEV;970state = (macio->flags & MACIO_FLAG_AIRPORT_ON) != 0;971if (value == state)972return 0;973if (value) {974/* This code is a reproduction of OF enable-cardslot975* and init-wireless methods, slightly hacked until976* I got it working.977*/978LOCK(flags);979MACIO_OUT8(KEYLARGO_GPIO_0+0xf, 5);980(void)MACIO_IN8(KEYLARGO_GPIO_0+0xf);981UNLOCK(flags);982mdelay(10);983LOCK(flags);984MACIO_OUT8(KEYLARGO_GPIO_0+0xf, 4);985(void)MACIO_IN8(KEYLARGO_GPIO_0+0xf);986UNLOCK(flags);987988mdelay(10);989990LOCK(flags);991MACIO_BIC(KEYLARGO_FCR2, KL2_CARDSEL_16);992(void)MACIO_IN32(KEYLARGO_FCR2);993udelay(10);994MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xb, 0);995(void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xb);996udelay(10);997MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xa, 0x28);998(void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xa);999udelay(10);1000MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xd, 0x28);1001(void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xd);1002udelay(10);1003MACIO_OUT8(KEYLARGO_GPIO_0+0xd, 0x28);1004(void)MACIO_IN8(KEYLARGO_GPIO_0+0xd);1005udelay(10);1006MACIO_OUT8(KEYLARGO_GPIO_0+0xe, 0x28);1007(void)MACIO_IN8(KEYLARGO_GPIO_0+0xe);1008UNLOCK(flags);1009udelay(10);1010MACIO_OUT32(0x1c000, 0);1011mdelay(1);1012MACIO_OUT8(0x1a3e0, 0x41);1013(void)MACIO_IN8(0x1a3e0);1014udelay(10);1015LOCK(flags);1016MACIO_BIS(KEYLARGO_FCR2, KL2_CARDSEL_16);1017(void)MACIO_IN32(KEYLARGO_FCR2);1018UNLOCK(flags);1019mdelay(100);10201021macio->flags |= MACIO_FLAG_AIRPORT_ON;1022} else {1023LOCK(flags);1024MACIO_BIC(KEYLARGO_FCR2, KL2_CARDSEL_16);1025(void)MACIO_IN32(KEYLARGO_FCR2);1026MACIO_OUT8(KL_GPIO_AIRPORT_0, 0);1027MACIO_OUT8(KL_GPIO_AIRPORT_1, 0);1028MACIO_OUT8(KL_GPIO_AIRPORT_2, 0);1029MACIO_OUT8(KL_GPIO_AIRPORT_3, 0);1030MACIO_OUT8(KL_GPIO_AIRPORT_4, 0);1031(void)MACIO_IN8(KL_GPIO_AIRPORT_4);1032UNLOCK(flags);10331034macio->flags &= ~MACIO_FLAG_AIRPORT_ON;1035}1036return 0;1037}10381039#ifdef CONFIG_SMP1040static long1041core99_reset_cpu(struct device_node *node, long param, long value)1042{1043unsigned int reset_io = 0;1044unsigned long flags;1045struct macio_chip *macio;1046struct device_node *np;1047const int dflt_reset_lines[] = { KL_GPIO_RESET_CPU0,1048KL_GPIO_RESET_CPU1,1049KL_GPIO_RESET_CPU2,1050KL_GPIO_RESET_CPU3 };10511052macio = &macio_chips[0];1053if (macio->type != macio_keylargo)1054return -ENODEV;10551056for_each_of_cpu_node(np) {1057const u32 *rst = of_get_property(np, "soft-reset", NULL);1058if (!rst)1059continue;1060if (param == of_get_cpu_hwid(np, 0)) {1061of_node_put(np);1062reset_io = *rst;1063break;1064}1065}1066if (np == NULL || reset_io == 0)1067reset_io = dflt_reset_lines[param];10681069LOCK(flags);1070MACIO_OUT8(reset_io, KEYLARGO_GPIO_OUTPUT_ENABLE);1071(void)MACIO_IN8(reset_io);1072udelay(1);1073MACIO_OUT8(reset_io, 0);1074(void)MACIO_IN8(reset_io);1075UNLOCK(flags);10761077return 0;1078}1079#endif /* CONFIG_SMP */10801081static long1082core99_usb_enable(struct device_node *node, long param, long value)1083{1084struct macio_chip *macio;1085unsigned long flags;1086const char *prop;1087int number;1088u32 reg;10891090macio = &macio_chips[0];1091if (macio->type != macio_keylargo && macio->type != macio_pangea &&1092macio->type != macio_intrepid)1093return -ENODEV;10941095prop = of_get_property(node, "AAPL,clock-id", NULL);1096if (!prop)1097return -ENODEV;1098if (strncmp(prop, "usb0u048", 8) == 0)1099number = 0;1100else if (strncmp(prop, "usb1u148", 8) == 0)1101number = 2;1102else if (strncmp(prop, "usb2u248", 8) == 0)1103number = 4;1104else1105return -ENODEV;11061107/* Sorry for the brute-force locking, but this is only used during1108* sleep and the timing seem to be critical1109*/1110LOCK(flags);1111if (value) {1112/* Turn ON */1113if (number == 0) {1114MACIO_BIC(KEYLARGO_FCR0, (KL0_USB0_PAD_SUSPEND0 | KL0_USB0_PAD_SUSPEND1));1115(void)MACIO_IN32(KEYLARGO_FCR0);1116UNLOCK(flags);1117mdelay(1);1118LOCK(flags);1119MACIO_BIS(KEYLARGO_FCR0, KL0_USB0_CELL_ENABLE);1120} else if (number == 2) {1121MACIO_BIC(KEYLARGO_FCR0, (KL0_USB1_PAD_SUSPEND0 | KL0_USB1_PAD_SUSPEND1));1122UNLOCK(flags);1123(void)MACIO_IN32(KEYLARGO_FCR0);1124mdelay(1);1125LOCK(flags);1126MACIO_BIS(KEYLARGO_FCR0, KL0_USB1_CELL_ENABLE);1127} else if (number == 4) {1128MACIO_BIC(KEYLARGO_FCR1, (KL1_USB2_PAD_SUSPEND0 | KL1_USB2_PAD_SUSPEND1));1129UNLOCK(flags);1130(void)MACIO_IN32(KEYLARGO_FCR1);1131mdelay(1);1132LOCK(flags);1133MACIO_BIS(KEYLARGO_FCR1, KL1_USB2_CELL_ENABLE);1134}1135if (number < 4) {1136reg = MACIO_IN32(KEYLARGO_FCR4);1137reg &= ~(KL4_PORT_WAKEUP_ENABLE(number) | KL4_PORT_RESUME_WAKE_EN(number) |1138KL4_PORT_CONNECT_WAKE_EN(number) | KL4_PORT_DISCONNECT_WAKE_EN(number));1139reg &= ~(KL4_PORT_WAKEUP_ENABLE(number+1) | KL4_PORT_RESUME_WAKE_EN(number+1) |1140KL4_PORT_CONNECT_WAKE_EN(number+1) | KL4_PORT_DISCONNECT_WAKE_EN(number+1));1141MACIO_OUT32(KEYLARGO_FCR4, reg);1142(void)MACIO_IN32(KEYLARGO_FCR4);1143udelay(10);1144} else {1145reg = MACIO_IN32(KEYLARGO_FCR3);1146reg &= ~(KL3_IT_PORT_WAKEUP_ENABLE(0) | KL3_IT_PORT_RESUME_WAKE_EN(0) |1147KL3_IT_PORT_CONNECT_WAKE_EN(0) | KL3_IT_PORT_DISCONNECT_WAKE_EN(0));1148reg &= ~(KL3_IT_PORT_WAKEUP_ENABLE(1) | KL3_IT_PORT_RESUME_WAKE_EN(1) |1149KL3_IT_PORT_CONNECT_WAKE_EN(1) | KL3_IT_PORT_DISCONNECT_WAKE_EN(1));1150MACIO_OUT32(KEYLARGO_FCR3, reg);1151(void)MACIO_IN32(KEYLARGO_FCR3);1152udelay(10);1153}1154if (macio->type == macio_intrepid) {1155/* wait for clock stopped bits to clear */1156u32 test0 = 0, test1 = 0;1157u32 status0, status1;1158int timeout = 1000;11591160UNLOCK(flags);1161switch (number) {1162case 0:1163test0 = UNI_N_CLOCK_STOPPED_USB0;1164test1 = UNI_N_CLOCK_STOPPED_USB0PCI;1165break;1166case 2:1167test0 = UNI_N_CLOCK_STOPPED_USB1;1168test1 = UNI_N_CLOCK_STOPPED_USB1PCI;1169break;1170case 4:1171test0 = UNI_N_CLOCK_STOPPED_USB2;1172test1 = UNI_N_CLOCK_STOPPED_USB2PCI;1173break;1174}1175do {1176if (--timeout <= 0) {1177printk(KERN_ERR "core99_usb_enable: "1178"Timeout waiting for clocks\n");1179break;1180}1181mdelay(1);1182status0 = UN_IN(UNI_N_CLOCK_STOP_STATUS0);1183status1 = UN_IN(UNI_N_CLOCK_STOP_STATUS1);1184} while ((status0 & test0) | (status1 & test1));1185LOCK(flags);1186}1187} else {1188/* Turn OFF */1189if (number < 4) {1190reg = MACIO_IN32(KEYLARGO_FCR4);1191reg |= KL4_PORT_WAKEUP_ENABLE(number) | KL4_PORT_RESUME_WAKE_EN(number) |1192KL4_PORT_CONNECT_WAKE_EN(number) | KL4_PORT_DISCONNECT_WAKE_EN(number);1193reg |= KL4_PORT_WAKEUP_ENABLE(number+1) | KL4_PORT_RESUME_WAKE_EN(number+1) |1194KL4_PORT_CONNECT_WAKE_EN(number+1) | KL4_PORT_DISCONNECT_WAKE_EN(number+1);1195MACIO_OUT32(KEYLARGO_FCR4, reg);1196(void)MACIO_IN32(KEYLARGO_FCR4);1197udelay(1);1198} else {1199reg = MACIO_IN32(KEYLARGO_FCR3);1200reg |= KL3_IT_PORT_WAKEUP_ENABLE(0) | KL3_IT_PORT_RESUME_WAKE_EN(0) |1201KL3_IT_PORT_CONNECT_WAKE_EN(0) | KL3_IT_PORT_DISCONNECT_WAKE_EN(0);1202reg |= KL3_IT_PORT_WAKEUP_ENABLE(1) | KL3_IT_PORT_RESUME_WAKE_EN(1) |1203KL3_IT_PORT_CONNECT_WAKE_EN(1) | KL3_IT_PORT_DISCONNECT_WAKE_EN(1);1204MACIO_OUT32(KEYLARGO_FCR3, reg);1205(void)MACIO_IN32(KEYLARGO_FCR3);1206udelay(1);1207}1208if (number == 0) {1209if (macio->type != macio_intrepid)1210MACIO_BIC(KEYLARGO_FCR0, KL0_USB0_CELL_ENABLE);1211(void)MACIO_IN32(KEYLARGO_FCR0);1212udelay(1);1213MACIO_BIS(KEYLARGO_FCR0, (KL0_USB0_PAD_SUSPEND0 | KL0_USB0_PAD_SUSPEND1));1214(void)MACIO_IN32(KEYLARGO_FCR0);1215} else if (number == 2) {1216if (macio->type != macio_intrepid)1217MACIO_BIC(KEYLARGO_FCR0, KL0_USB1_CELL_ENABLE);1218(void)MACIO_IN32(KEYLARGO_FCR0);1219udelay(1);1220MACIO_BIS(KEYLARGO_FCR0, (KL0_USB1_PAD_SUSPEND0 | KL0_USB1_PAD_SUSPEND1));1221(void)MACIO_IN32(KEYLARGO_FCR0);1222} else if (number == 4) {1223udelay(1);1224MACIO_BIS(KEYLARGO_FCR1, (KL1_USB2_PAD_SUSPEND0 | KL1_USB2_PAD_SUSPEND1));1225(void)MACIO_IN32(KEYLARGO_FCR1);1226}1227udelay(1);1228}1229UNLOCK(flags);12301231return 0;1232}12331234static long1235core99_firewire_enable(struct device_node *node, long param, long value)1236{1237unsigned long flags;1238struct macio_chip *macio;12391240macio = &macio_chips[0];1241if (macio->type != macio_keylargo && macio->type != macio_pangea &&1242macio->type != macio_intrepid)1243return -ENODEV;1244if (!(macio->flags & MACIO_FLAG_FW_SUPPORTED))1245return -ENODEV;12461247LOCK(flags);1248if (value) {1249UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_FW);1250(void)UN_IN(UNI_N_CLOCK_CNTL);1251} else {1252UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_FW);1253(void)UN_IN(UNI_N_CLOCK_CNTL);1254}1255UNLOCK(flags);1256mdelay(1);12571258return 0;1259}12601261static long1262core99_firewire_cable_power(struct device_node *node, long param, long value)1263{1264unsigned long flags;1265struct macio_chip *macio;12661267/* Trick: we allow NULL node */1268if ((pmac_mb.board_flags & PMAC_MB_HAS_FW_POWER) == 0)1269return -ENODEV;1270macio = &macio_chips[0];1271if (macio->type != macio_keylargo && macio->type != macio_pangea &&1272macio->type != macio_intrepid)1273return -ENODEV;1274if (!(macio->flags & MACIO_FLAG_FW_SUPPORTED))1275return -ENODEV;12761277LOCK(flags);1278if (value) {1279MACIO_OUT8(KL_GPIO_FW_CABLE_POWER , 0);1280MACIO_IN8(KL_GPIO_FW_CABLE_POWER);1281udelay(10);1282} else {1283MACIO_OUT8(KL_GPIO_FW_CABLE_POWER , 4);1284MACIO_IN8(KL_GPIO_FW_CABLE_POWER); udelay(10);1285}1286UNLOCK(flags);1287mdelay(1);12881289return 0;1290}12911292static long1293intrepid_aack_delay_enable(struct device_node *node, long param, long value)1294{1295unsigned long flags;12961297if (uninorth_rev < 0xd2)1298return -ENODEV;12991300LOCK(flags);1301if (param)1302UN_BIS(UNI_N_AACK_DELAY, UNI_N_AACK_DELAY_ENABLE);1303else1304UN_BIC(UNI_N_AACK_DELAY, UNI_N_AACK_DELAY_ENABLE);1305UNLOCK(flags);13061307return 0;1308}130913101311#endif /* CONFIG_PPC64 */13121313static long1314core99_read_gpio(struct device_node *node, long param, long value)1315{1316struct macio_chip *macio = &macio_chips[0];13171318return MACIO_IN8(param);1319}132013211322static long1323core99_write_gpio(struct device_node *node, long param, long value)1324{1325struct macio_chip *macio = &macio_chips[0];13261327MACIO_OUT8(param, (u8)(value & 0xff));1328return 0;1329}13301331#ifdef CONFIG_PPC641332static long g5_gmac_enable(struct device_node *node, long param, long value)1333{1334struct macio_chip *macio = &macio_chips[0];1335unsigned long flags;13361337if (node == NULL)1338return -ENODEV;13391340LOCK(flags);1341if (value) {1342MACIO_BIS(KEYLARGO_FCR1, K2_FCR1_GMAC_CLK_ENABLE);1343mb();1344k2_skiplist[0] = NULL;1345} else {1346k2_skiplist[0] = node;1347mb();1348MACIO_BIC(KEYLARGO_FCR1, K2_FCR1_GMAC_CLK_ENABLE);1349}13501351UNLOCK(flags);1352mdelay(1);13531354return 0;1355}13561357static long g5_fw_enable(struct device_node *node, long param, long value)1358{1359struct macio_chip *macio = &macio_chips[0];1360unsigned long flags;13611362if (node == NULL)1363return -ENODEV;13641365LOCK(flags);1366if (value) {1367MACIO_BIS(KEYLARGO_FCR1, K2_FCR1_FW_CLK_ENABLE);1368mb();1369k2_skiplist[1] = NULL;1370} else {1371k2_skiplist[1] = node;1372mb();1373MACIO_BIC(KEYLARGO_FCR1, K2_FCR1_FW_CLK_ENABLE);1374}13751376UNLOCK(flags);1377mdelay(1);13781379return 0;1380}13811382static long g5_mpic_enable(struct device_node *node, long param, long value)1383{1384unsigned long flags;1385struct device_node *parent = of_get_parent(node);1386int is_u3;13871388if (parent == NULL)1389return 0;1390is_u3 = of_node_name_eq(parent, "u3") || of_node_name_eq(parent, "u4");1391of_node_put(parent);1392if (!is_u3)1393return 0;13941395LOCK(flags);1396UN_BIS(U3_TOGGLE_REG, U3_MPIC_RESET | U3_MPIC_OUTPUT_ENABLE);1397UNLOCK(flags);13981399return 0;1400}14011402static long g5_eth_phy_reset(struct device_node *node, long param, long value)1403{1404struct macio_chip *macio = &macio_chips[0];1405struct device_node *phy;1406int need_reset;14071408/*1409* We must not reset the combo PHYs, only the BCM5221 found in1410* the iMac G5.1411*/1412phy = of_get_next_child(node, NULL);1413if (!phy)1414return -ENODEV;1415need_reset = of_device_is_compatible(phy, "B5221");1416of_node_put(phy);1417if (!need_reset)1418return 0;14191420/* PHY reset is GPIO 29, not in device-tree unfortunately */1421MACIO_OUT8(K2_GPIO_EXTINT_0 + 29,1422KEYLARGO_GPIO_OUTPUT_ENABLE | KEYLARGO_GPIO_OUTOUT_DATA);1423/* Thankfully, this is now always called at a time when we can1424* schedule by sungem.1425*/1426msleep(10);1427MACIO_OUT8(K2_GPIO_EXTINT_0 + 29, 0);14281429return 0;1430}14311432static long g5_i2s_enable(struct device_node *node, long param, long value)1433{1434/* Very crude implementation for now */1435struct macio_chip *macio = &macio_chips[0];1436unsigned long flags;1437int cell;1438u32 fcrs[3][3] = {1439{ 0,1440K2_FCR1_I2S0_CELL_ENABLE |1441K2_FCR1_I2S0_CLK_ENABLE_BIT | K2_FCR1_I2S0_ENABLE,1442KL3_I2S0_CLK18_ENABLE1443},1444{ KL0_SCC_A_INTF_ENABLE,1445K2_FCR1_I2S1_CELL_ENABLE |1446K2_FCR1_I2S1_CLK_ENABLE_BIT | K2_FCR1_I2S1_ENABLE,1447KL3_I2S1_CLK18_ENABLE1448},1449{ KL0_SCC_B_INTF_ENABLE,1450SH_FCR1_I2S2_CELL_ENABLE |1451SH_FCR1_I2S2_CLK_ENABLE_BIT | SH_FCR1_I2S2_ENABLE,1452SH_FCR3_I2S2_CLK18_ENABLE1453},1454};14551456if (macio->type != macio_keylargo2 && macio->type != macio_shasta)1457return -ENODEV;1458if (strncmp(node->name, "i2s-", 4))1459return -ENODEV;1460cell = node->name[4] - 'a';1461switch(cell) {1462case 0:1463case 1:1464break;1465case 2:1466if (macio->type == macio_shasta)1467break;1468fallthrough;1469default:1470return -ENODEV;1471}14721473LOCK(flags);1474if (value) {1475MACIO_BIC(KEYLARGO_FCR0, fcrs[cell][0]);1476MACIO_BIS(KEYLARGO_FCR1, fcrs[cell][1]);1477MACIO_BIS(KEYLARGO_FCR3, fcrs[cell][2]);1478} else {1479MACIO_BIC(KEYLARGO_FCR3, fcrs[cell][2]);1480MACIO_BIC(KEYLARGO_FCR1, fcrs[cell][1]);1481MACIO_BIS(KEYLARGO_FCR0, fcrs[cell][0]);1482}1483udelay(10);1484UNLOCK(flags);14851486return 0;1487}148814891490#ifdef CONFIG_SMP1491static long g5_reset_cpu(struct device_node *node, long param, long value)1492{1493unsigned int reset_io = 0;1494unsigned long flags;1495struct macio_chip *macio;1496struct device_node *np;14971498macio = &macio_chips[0];1499if (macio->type != macio_keylargo2 && macio->type != macio_shasta)1500return -ENODEV;15011502for_each_of_cpu_node(np) {1503const u32 *rst = of_get_property(np, "soft-reset", NULL);1504if (!rst)1505continue;1506if (param == of_get_cpu_hwid(np, 0)) {1507of_node_put(np);1508reset_io = *rst;1509break;1510}1511}1512if (np == NULL || reset_io == 0)1513return -ENODEV;15141515LOCK(flags);1516MACIO_OUT8(reset_io, KEYLARGO_GPIO_OUTPUT_ENABLE);1517(void)MACIO_IN8(reset_io);1518udelay(1);1519MACIO_OUT8(reset_io, 0);1520(void)MACIO_IN8(reset_io);1521UNLOCK(flags);15221523return 0;1524}1525#endif /* CONFIG_SMP */15261527/*1528* This can be called from pmac_smp so isn't static1529*1530* This takes the second CPU off the bus on dual CPU machines1531* running UP1532*/1533void __init g5_phy_disable_cpu1(void)1534{1535if (uninorth_maj == 3)1536UN_OUT(U3_API_PHY_CONFIG_1, 0);1537}1538#endif /* CONFIG_PPC64 */15391540#ifndef CONFIG_PPC64154115421543#ifdef CONFIG_PM1544static u32 save_gpio_levels[2];1545static u8 save_gpio_extint[KEYLARGO_GPIO_EXTINT_CNT];1546static u8 save_gpio_normal[KEYLARGO_GPIO_CNT];1547static u32 save_unin_clock_ctl;15481549static void keylargo_shutdown(struct macio_chip *macio, int sleep_mode)1550{1551u32 temp;15521553if (sleep_mode) {1554mdelay(1);1555MACIO_BIS(KEYLARGO_FCR0, KL0_USB_REF_SUSPEND);1556(void)MACIO_IN32(KEYLARGO_FCR0);1557mdelay(1);1558}15591560MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |1561KL0_SCC_CELL_ENABLE |1562KL0_IRDA_ENABLE | KL0_IRDA_CLK32_ENABLE |1563KL0_IRDA_CLK19_ENABLE);15641565MACIO_BIC(KEYLARGO_MBCR, KL_MBCR_MB0_DEV_MASK);1566MACIO_BIS(KEYLARGO_MBCR, KL_MBCR_MB0_IDE_ENABLE);15671568MACIO_BIC(KEYLARGO_FCR1,1569KL1_AUDIO_SEL_22MCLK | KL1_AUDIO_CLK_ENABLE_BIT |1570KL1_AUDIO_CLK_OUT_ENABLE | KL1_AUDIO_CELL_ENABLE |1571KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |1572KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |1573KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |1574KL1_EIDE0_ENABLE | KL1_EIDE0_RESET_N |1575KL1_EIDE1_ENABLE | KL1_EIDE1_RESET_N |1576KL1_UIDE_ENABLE);15771578MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);1579MACIO_BIC(KEYLARGO_FCR2, KL2_IOBUS_ENABLE);15801581temp = MACIO_IN32(KEYLARGO_FCR3);1582if (macio->rev >= 2) {1583temp |= KL3_SHUTDOWN_PLL2X;1584if (sleep_mode)1585temp |= KL3_SHUTDOWN_PLL_TOTAL;1586}15871588temp |= KL3_SHUTDOWN_PLLKW6 | KL3_SHUTDOWN_PLLKW4 |1589KL3_SHUTDOWN_PLLKW35;1590if (sleep_mode)1591temp |= KL3_SHUTDOWN_PLLKW12;1592temp &= ~(KL3_CLK66_ENABLE | KL3_CLK49_ENABLE | KL3_CLK45_ENABLE1593| KL3_CLK31_ENABLE | KL3_I2S1_CLK18_ENABLE | KL3_I2S0_CLK18_ENABLE);1594if (sleep_mode)1595temp &= ~(KL3_TIMER_CLK18_ENABLE | KL3_VIA_CLK16_ENABLE);1596MACIO_OUT32(KEYLARGO_FCR3, temp);15971598/* Flush posted writes & wait a bit */1599(void)MACIO_IN32(KEYLARGO_FCR0); mdelay(1);1600}16011602static void pangea_shutdown(struct macio_chip *macio, int sleep_mode)1603{1604u32 temp;16051606MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |1607KL0_SCC_CELL_ENABLE |1608KL0_USB0_CELL_ENABLE | KL0_USB1_CELL_ENABLE);16091610MACIO_BIC(KEYLARGO_FCR1,1611KL1_AUDIO_SEL_22MCLK | KL1_AUDIO_CLK_ENABLE_BIT |1612KL1_AUDIO_CLK_OUT_ENABLE | KL1_AUDIO_CELL_ENABLE |1613KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |1614KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |1615KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |1616KL1_UIDE_ENABLE);1617if (pmac_mb.board_flags & PMAC_MB_MOBILE)1618MACIO_BIC(KEYLARGO_FCR1, KL1_UIDE_RESET_N);16191620MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);16211622temp = MACIO_IN32(KEYLARGO_FCR3);1623temp |= KL3_SHUTDOWN_PLLKW6 | KL3_SHUTDOWN_PLLKW4 |1624KL3_SHUTDOWN_PLLKW35;1625temp &= ~(KL3_CLK49_ENABLE | KL3_CLK45_ENABLE | KL3_CLK31_ENABLE1626| KL3_I2S0_CLK18_ENABLE | KL3_I2S1_CLK18_ENABLE);1627if (sleep_mode)1628temp &= ~(KL3_VIA_CLK16_ENABLE | KL3_TIMER_CLK18_ENABLE);1629MACIO_OUT32(KEYLARGO_FCR3, temp);16301631/* Flush posted writes & wait a bit */1632(void)MACIO_IN32(KEYLARGO_FCR0); mdelay(1);1633}16341635static void intrepid_shutdown(struct macio_chip *macio, int sleep_mode)1636{1637u32 temp;16381639MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |1640KL0_SCC_CELL_ENABLE);16411642MACIO_BIC(KEYLARGO_FCR1,1643KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |1644KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |1645KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |1646KL1_EIDE0_ENABLE);1647if (pmac_mb.board_flags & PMAC_MB_MOBILE)1648MACIO_BIC(KEYLARGO_FCR1, KL1_UIDE_RESET_N);16491650temp = MACIO_IN32(KEYLARGO_FCR3);1651temp &= ~(KL3_CLK49_ENABLE | KL3_CLK45_ENABLE |1652KL3_I2S1_CLK18_ENABLE | KL3_I2S0_CLK18_ENABLE);1653if (sleep_mode)1654temp &= ~(KL3_TIMER_CLK18_ENABLE | KL3_IT_VIA_CLK32_ENABLE);1655MACIO_OUT32(KEYLARGO_FCR3, temp);16561657/* Flush posted writes & wait a bit */1658(void)MACIO_IN32(KEYLARGO_FCR0);1659mdelay(10);1660}166116621663static int1664core99_sleep(void)1665{1666struct macio_chip *macio;1667int i;16681669macio = &macio_chips[0];1670if (macio->type != macio_keylargo && macio->type != macio_pangea &&1671macio->type != macio_intrepid)1672return -ENODEV;16731674/* We power off the wireless slot in case it was not done1675* by the driver. We don't power it on automatically however1676*/1677if (macio->flags & MACIO_FLAG_AIRPORT_ON)1678core99_airport_enable(macio->of_node, 0, 0);16791680/* We power off the FW cable. Should be done by the driver... */1681if (macio->flags & MACIO_FLAG_FW_SUPPORTED) {1682core99_firewire_enable(NULL, 0, 0);1683core99_firewire_cable_power(NULL, 0, 0);1684}16851686/* We make sure int. modem is off (in case driver lost it) */1687if (macio->type == macio_keylargo)1688core99_modem_enable(macio->of_node, 0, 0);1689else1690pangea_modem_enable(macio->of_node, 0, 0);16911692/* We make sure the sound is off as well */1693core99_sound_chip_enable(macio->of_node, 0, 0);16941695/*1696* Save various bits of KeyLargo1697*/16981699/* Save the state of the various GPIOs */1700save_gpio_levels[0] = MACIO_IN32(KEYLARGO_GPIO_LEVELS0);1701save_gpio_levels[1] = MACIO_IN32(KEYLARGO_GPIO_LEVELS1);1702for (i=0; i<KEYLARGO_GPIO_EXTINT_CNT; i++)1703save_gpio_extint[i] = MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+i);1704for (i=0; i<KEYLARGO_GPIO_CNT; i++)1705save_gpio_normal[i] = MACIO_IN8(KEYLARGO_GPIO_0+i);17061707/* Save the FCRs */1708if (macio->type == macio_keylargo)1709save_mbcr = MACIO_IN32(KEYLARGO_MBCR);1710save_fcr[0] = MACIO_IN32(KEYLARGO_FCR0);1711save_fcr[1] = MACIO_IN32(KEYLARGO_FCR1);1712save_fcr[2] = MACIO_IN32(KEYLARGO_FCR2);1713save_fcr[3] = MACIO_IN32(KEYLARGO_FCR3);1714save_fcr[4] = MACIO_IN32(KEYLARGO_FCR4);1715if (macio->type == macio_pangea || macio->type == macio_intrepid)1716save_fcr[5] = MACIO_IN32(KEYLARGO_FCR5);17171718/* Save state & config of DBDMA channels */1719dbdma_save(macio, save_dbdma);17201721/*1722* Turn off as much as we can1723*/1724if (macio->type == macio_pangea)1725pangea_shutdown(macio, 1);1726else if (macio->type == macio_intrepid)1727intrepid_shutdown(macio, 1);1728else if (macio->type == macio_keylargo)1729keylargo_shutdown(macio, 1);17301731/*1732* Put the host bridge to sleep1733*/17341735save_unin_clock_ctl = UN_IN(UNI_N_CLOCK_CNTL);1736/* Note: do not switch GMAC off, driver does it when necessary, WOL must keep it1737* enabled !1738*/1739UN_OUT(UNI_N_CLOCK_CNTL, save_unin_clock_ctl &1740~(/*UNI_N_CLOCK_CNTL_GMAC|*/UNI_N_CLOCK_CNTL_FW/*|UNI_N_CLOCK_CNTL_PCI*/));1741udelay(100);1742UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_SLEEPING);1743UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_SLEEP);1744mdelay(10);17451746/*1747* FIXME: A bit of black magic with OpenPIC (don't ask me why)1748*/1749if (pmac_mb.model_id == PMAC_TYPE_SAWTOOTH) {1750MACIO_BIS(0x506e0, 0x00400000);1751MACIO_BIS(0x506e0, 0x80000000);1752}1753return 0;1754}17551756static int1757core99_wake_up(void)1758{1759struct macio_chip *macio;1760int i;17611762macio = &macio_chips[0];1763if (macio->type != macio_keylargo && macio->type != macio_pangea &&1764macio->type != macio_intrepid)1765return -ENODEV;17661767/*1768* Wakeup the host bridge1769*/1770UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_NORMAL);1771udelay(10);1772UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_RUNNING);1773udelay(10);17741775/*1776* Restore KeyLargo1777*/17781779if (macio->type == macio_keylargo) {1780MACIO_OUT32(KEYLARGO_MBCR, save_mbcr);1781(void)MACIO_IN32(KEYLARGO_MBCR); udelay(10);1782}1783MACIO_OUT32(KEYLARGO_FCR0, save_fcr[0]);1784(void)MACIO_IN32(KEYLARGO_FCR0); udelay(10);1785MACIO_OUT32(KEYLARGO_FCR1, save_fcr[1]);1786(void)MACIO_IN32(KEYLARGO_FCR1); udelay(10);1787MACIO_OUT32(KEYLARGO_FCR2, save_fcr[2]);1788(void)MACIO_IN32(KEYLARGO_FCR2); udelay(10);1789MACIO_OUT32(KEYLARGO_FCR3, save_fcr[3]);1790(void)MACIO_IN32(KEYLARGO_FCR3); udelay(10);1791MACIO_OUT32(KEYLARGO_FCR4, save_fcr[4]);1792(void)MACIO_IN32(KEYLARGO_FCR4); udelay(10);1793if (macio->type == macio_pangea || macio->type == macio_intrepid) {1794MACIO_OUT32(KEYLARGO_FCR5, save_fcr[5]);1795(void)MACIO_IN32(KEYLARGO_FCR5); udelay(10);1796}17971798dbdma_restore(macio, save_dbdma);17991800MACIO_OUT32(KEYLARGO_GPIO_LEVELS0, save_gpio_levels[0]);1801MACIO_OUT32(KEYLARGO_GPIO_LEVELS1, save_gpio_levels[1]);1802for (i=0; i<KEYLARGO_GPIO_EXTINT_CNT; i++)1803MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+i, save_gpio_extint[i]);1804for (i=0; i<KEYLARGO_GPIO_CNT; i++)1805MACIO_OUT8(KEYLARGO_GPIO_0+i, save_gpio_normal[i]);18061807/* FIXME more black magic with OpenPIC ... */1808if (pmac_mb.model_id == PMAC_TYPE_SAWTOOTH) {1809MACIO_BIC(0x506e0, 0x00400000);1810MACIO_BIC(0x506e0, 0x80000000);1811}18121813UN_OUT(UNI_N_CLOCK_CNTL, save_unin_clock_ctl);1814udelay(100);18151816return 0;1817}18181819#endif /* CONFIG_PM */18201821static long1822core99_sleep_state(struct device_node *node, long param, long value)1823{1824/* Param == 1 means to enter the "fake sleep" mode that is1825* used for CPU speed switch1826*/1827if (param == 1) {1828if (value == 1) {1829UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_SLEEPING);1830UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_IDLE2);1831} else {1832UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_NORMAL);1833udelay(10);1834UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_RUNNING);1835udelay(10);1836}1837return 0;1838}1839if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)1840return -EPERM;18411842#ifdef CONFIG_PM1843if (value == 1)1844return core99_sleep();1845else if (value == 0)1846return core99_wake_up();18471848#endif /* CONFIG_PM */1849return 0;1850}18511852#endif /* CONFIG_PPC64 */18531854static long1855generic_dev_can_wake(struct device_node *node, long param, long value)1856{1857/* Todo: eventually check we are really dealing with on-board1858* video device ...1859*/18601861if (pmac_mb.board_flags & PMAC_MB_MAY_SLEEP)1862pmac_mb.board_flags |= PMAC_MB_CAN_SLEEP;1863return 0;1864}18651866static long generic_get_mb_info(struct device_node *node, long param, long value)1867{1868switch(param) {1869case PMAC_MB_INFO_MODEL:1870return pmac_mb.model_id;1871case PMAC_MB_INFO_FLAGS:1872return pmac_mb.board_flags;1873case PMAC_MB_INFO_NAME:1874/* hack hack hack... but should work */1875*((const char **)value) = pmac_mb.model_name;1876return 0;1877}1878return -EINVAL;1879}188018811882/*1883* Table definitions1884*/18851886/* Used on any machine1887*/1888static struct feature_table_entry any_features[] = {1889{ PMAC_FTR_GET_MB_INFO, generic_get_mb_info },1890{ PMAC_FTR_DEVICE_CAN_WAKE, generic_dev_can_wake },1891{ 0, NULL }1892};18931894#ifndef CONFIG_PPC6418951896/* OHare based motherboards. Currently, we only use these on the1897* 2400,3400 and 3500 series powerbooks. Some older desktops seem1898* to have issues with turning on/off those asic cells1899*/1900static struct feature_table_entry ohare_features[] = {1901{ PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },1902{ PMAC_FTR_SWIM3_ENABLE, ohare_floppy_enable },1903{ PMAC_FTR_MESH_ENABLE, ohare_mesh_enable },1904{ PMAC_FTR_IDE_ENABLE, ohare_ide_enable},1905{ PMAC_FTR_IDE_RESET, ohare_ide_reset},1906{ PMAC_FTR_SLEEP_STATE, ohare_sleep_state },1907{ 0, NULL }1908};19091910/* Heathrow desktop machines (Beige G3).1911* Separated as some features couldn't be properly tested1912* and the serial port control bits appear to confuse it.1913*/1914static struct feature_table_entry heathrow_desktop_features[] = {1915{ PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },1916{ PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },1917{ PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },1918{ PMAC_FTR_IDE_RESET, heathrow_ide_reset },1919{ PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },1920{ 0, NULL }1921};19221923/* Heathrow based laptop, that is the Wallstreet and mainstreet1924* powerbooks.1925*/1926static struct feature_table_entry heathrow_laptop_features[] = {1927{ PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },1928{ PMAC_FTR_MODEM_ENABLE, heathrow_modem_enable },1929{ PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },1930{ PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },1931{ PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },1932{ PMAC_FTR_IDE_RESET, heathrow_ide_reset },1933{ PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },1934{ PMAC_FTR_SOUND_CHIP_ENABLE, heathrow_sound_enable },1935{ PMAC_FTR_SLEEP_STATE, heathrow_sleep_state },1936{ 0, NULL }1937};19381939/* Paddington based machines1940* The lombard (101) powerbook, first iMac models, B&W G3 and Yikes G4.1941*/1942static struct feature_table_entry paddington_features[] = {1943{ PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },1944{ PMAC_FTR_MODEM_ENABLE, heathrow_modem_enable },1945{ PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },1946{ PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },1947{ PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },1948{ PMAC_FTR_IDE_RESET, heathrow_ide_reset },1949{ PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },1950{ PMAC_FTR_SOUND_CHIP_ENABLE, heathrow_sound_enable },1951{ PMAC_FTR_SLEEP_STATE, heathrow_sleep_state },1952{ 0, NULL }1953};19541955/* Core99 & MacRISC 2 machines (all machines released since the1956* iBook (included), that is all AGP machines, except pangea1957* chipset. The pangea chipset is the "combo" UniNorth/KeyLargo1958* used on iBook2 & iMac "flow power".1959*/1960static struct feature_table_entry core99_features[] = {1961{ PMAC_FTR_SCC_ENABLE, core99_scc_enable },1962{ PMAC_FTR_MODEM_ENABLE, core99_modem_enable },1963{ PMAC_FTR_IDE_ENABLE, core99_ide_enable },1964{ PMAC_FTR_IDE_RESET, core99_ide_reset },1965{ PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },1966{ PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },1967{ PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },1968{ PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },1969{ PMAC_FTR_USB_ENABLE, core99_usb_enable },1970{ PMAC_FTR_1394_ENABLE, core99_firewire_enable },1971{ PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },1972#ifdef CONFIG_PM1973{ PMAC_FTR_SLEEP_STATE, core99_sleep_state },1974#endif1975#ifdef CONFIG_SMP1976{ PMAC_FTR_RESET_CPU, core99_reset_cpu },1977#endif /* CONFIG_SMP */1978{ PMAC_FTR_READ_GPIO, core99_read_gpio },1979{ PMAC_FTR_WRITE_GPIO, core99_write_gpio },1980{ 0, NULL }1981};19821983/* RackMac1984*/1985static struct feature_table_entry rackmac_features[] = {1986{ PMAC_FTR_SCC_ENABLE, core99_scc_enable },1987{ PMAC_FTR_IDE_ENABLE, core99_ide_enable },1988{ PMAC_FTR_IDE_RESET, core99_ide_reset },1989{ PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },1990{ PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },1991{ PMAC_FTR_USB_ENABLE, core99_usb_enable },1992{ PMAC_FTR_1394_ENABLE, core99_firewire_enable },1993{ PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },1994{ PMAC_FTR_SLEEP_STATE, core99_sleep_state },1995#ifdef CONFIG_SMP1996{ PMAC_FTR_RESET_CPU, core99_reset_cpu },1997#endif /* CONFIG_SMP */1998{ PMAC_FTR_READ_GPIO, core99_read_gpio },1999{ PMAC_FTR_WRITE_GPIO, core99_write_gpio },2000{ 0, NULL }2001};20022003/* Pangea features2004*/2005static struct feature_table_entry pangea_features[] = {2006{ PMAC_FTR_SCC_ENABLE, core99_scc_enable },2007{ PMAC_FTR_MODEM_ENABLE, pangea_modem_enable },2008{ PMAC_FTR_IDE_ENABLE, core99_ide_enable },2009{ PMAC_FTR_IDE_RESET, core99_ide_reset },2010{ PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },2011{ PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },2012{ PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },2013{ PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },2014{ PMAC_FTR_USB_ENABLE, core99_usb_enable },2015{ PMAC_FTR_1394_ENABLE, core99_firewire_enable },2016{ PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },2017{ PMAC_FTR_SLEEP_STATE, core99_sleep_state },2018{ PMAC_FTR_READ_GPIO, core99_read_gpio },2019{ PMAC_FTR_WRITE_GPIO, core99_write_gpio },2020{ 0, NULL }2021};20222023/* Intrepid features2024*/2025static struct feature_table_entry intrepid_features[] = {2026{ PMAC_FTR_SCC_ENABLE, core99_scc_enable },2027{ PMAC_FTR_MODEM_ENABLE, pangea_modem_enable },2028{ PMAC_FTR_IDE_ENABLE, core99_ide_enable },2029{ PMAC_FTR_IDE_RESET, core99_ide_reset },2030{ PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },2031{ PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },2032{ PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },2033{ PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },2034{ PMAC_FTR_USB_ENABLE, core99_usb_enable },2035{ PMAC_FTR_1394_ENABLE, core99_firewire_enable },2036{ PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },2037{ PMAC_FTR_SLEEP_STATE, core99_sleep_state },2038{ PMAC_FTR_READ_GPIO, core99_read_gpio },2039{ PMAC_FTR_WRITE_GPIO, core99_write_gpio },2040{ PMAC_FTR_AACK_DELAY_ENABLE, intrepid_aack_delay_enable },2041{ 0, NULL }2042};20432044#else /* CONFIG_PPC64 */20452046/* G5 features2047*/2048static struct feature_table_entry g5_features[] = {2049{ PMAC_FTR_GMAC_ENABLE, g5_gmac_enable },2050{ PMAC_FTR_1394_ENABLE, g5_fw_enable },2051{ PMAC_FTR_ENABLE_MPIC, g5_mpic_enable },2052{ PMAC_FTR_GMAC_PHY_RESET, g5_eth_phy_reset },2053{ PMAC_FTR_SOUND_CHIP_ENABLE, g5_i2s_enable },2054#ifdef CONFIG_SMP2055{ PMAC_FTR_RESET_CPU, g5_reset_cpu },2056#endif /* CONFIG_SMP */2057{ PMAC_FTR_READ_GPIO, core99_read_gpio },2058{ PMAC_FTR_WRITE_GPIO, core99_write_gpio },2059{ 0, NULL }2060};20612062#endif /* CONFIG_PPC64 */20632064static struct pmac_mb_def pmac_mb_defs[] = {2065#ifndef CONFIG_PPC642066/*2067* Desktops2068*/20692070{ "AAPL,8500", "PowerMac 8500/8600",2071PMAC_TYPE_PSURGE, NULL,207202073},2074{ "AAPL,9500", "PowerMac 9500/9600",2075PMAC_TYPE_PSURGE, NULL,207602077},2078{ "AAPL,7200", "PowerMac 7200",2079PMAC_TYPE_PSURGE, NULL,208002081},2082{ "AAPL,7300", "PowerMac 7200/7300",2083PMAC_TYPE_PSURGE, NULL,208402085},2086{ "AAPL,7500", "PowerMac 7500",2087PMAC_TYPE_PSURGE, NULL,208802089},2090{ "AAPL,ShinerESB", "Apple Network Server",2091PMAC_TYPE_ANS, NULL,209202093},2094{ "AAPL,e407", "Alchemy",2095PMAC_TYPE_ALCHEMY, NULL,209602097},2098{ "AAPL,e411", "Gazelle",2099PMAC_TYPE_GAZELLE, NULL,210002101},2102{ "AAPL,Gossamer", "PowerMac G3 (Gossamer)",2103PMAC_TYPE_GOSSAMER, heathrow_desktop_features,210402105},2106{ "AAPL,PowerMac G3", "PowerMac G3 (Silk)",2107PMAC_TYPE_SILK, heathrow_desktop_features,210802109},2110{ "PowerMac1,1", "Blue&White G3",2111PMAC_TYPE_YOSEMITE, paddington_features,211202113},2114{ "PowerMac1,2", "PowerMac G4 PCI Graphics",2115PMAC_TYPE_YIKES, paddington_features,211602117},2118{ "PowerMac2,1", "iMac FireWire",2119PMAC_TYPE_FW_IMAC, core99_features,2120PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE992121},2122{ "PowerMac2,2", "iMac FireWire",2123PMAC_TYPE_FW_IMAC, core99_features,2124PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE992125},2126{ "PowerMac3,1", "PowerMac G4 AGP Graphics",2127PMAC_TYPE_SAWTOOTH, core99_features,2128PMAC_MB_OLD_CORE992129},2130{ "PowerMac3,2", "PowerMac G4 AGP Graphics",2131PMAC_TYPE_SAWTOOTH, core99_features,2132PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE992133},2134{ "PowerMac3,3", "PowerMac G4 AGP Graphics",2135PMAC_TYPE_SAWTOOTH, core99_features,2136PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE992137},2138{ "PowerMac3,4", "PowerMac G4 Silver",2139PMAC_TYPE_QUICKSILVER, core99_features,2140PMAC_MB_MAY_SLEEP2141},2142{ "PowerMac3,5", "PowerMac G4 Silver",2143PMAC_TYPE_QUICKSILVER, core99_features,2144PMAC_MB_MAY_SLEEP2145},2146{ "PowerMac3,6", "PowerMac G4 Windtunnel",2147PMAC_TYPE_WINDTUNNEL, core99_features,2148PMAC_MB_MAY_SLEEP,2149},2150{ "PowerMac4,1", "iMac \"Flower Power\"",2151PMAC_TYPE_PANGEA_IMAC, pangea_features,2152PMAC_MB_MAY_SLEEP2153},2154{ "PowerMac4,2", "Flat panel iMac",2155PMAC_TYPE_FLAT_PANEL_IMAC, pangea_features,2156PMAC_MB_CAN_SLEEP2157},2158{ "PowerMac4,4", "eMac",2159PMAC_TYPE_EMAC, core99_features,2160PMAC_MB_MAY_SLEEP2161},2162{ "PowerMac5,1", "PowerMac G4 Cube",2163PMAC_TYPE_CUBE, core99_features,2164PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE992165},2166{ "PowerMac6,1", "Flat panel iMac",2167PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2168PMAC_MB_MAY_SLEEP,2169},2170{ "PowerMac6,3", "Flat panel iMac",2171PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2172PMAC_MB_MAY_SLEEP,2173},2174{ "PowerMac6,4", "eMac",2175PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2176PMAC_MB_MAY_SLEEP,2177},2178{ "PowerMac10,1", "Mac mini",2179PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2180PMAC_MB_MAY_SLEEP,2181},2182{ "PowerMac10,2", "Mac mini (Late 2005)",2183PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2184PMAC_MB_MAY_SLEEP,2185},2186{ "iMac,1", "iMac (first generation)",2187PMAC_TYPE_ORIG_IMAC, paddington_features,218802189},21902191/*2192* Xserve's2193*/21942195{ "RackMac1,1", "XServe",2196PMAC_TYPE_RACKMAC, rackmac_features,21970,2198},2199{ "RackMac1,2", "XServe rev. 2",2200PMAC_TYPE_RACKMAC, rackmac_features,22010,2202},22032204/*2205* Laptops2206*/22072208{ "AAPL,3400/2400", "PowerBook 3400",2209PMAC_TYPE_HOOPER, ohare_features,2210PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE2211},2212{ "AAPL,3500", "PowerBook 3500",2213PMAC_TYPE_KANGA, ohare_features,2214PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE2215},2216{ "AAPL,PowerBook1998", "PowerBook Wallstreet",2217PMAC_TYPE_WALLSTREET, heathrow_laptop_features,2218PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE2219},2220{ "PowerBook1,1", "PowerBook 101 (Lombard)",2221PMAC_TYPE_101_PBOOK, paddington_features,2222PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE2223},2224{ "PowerBook2,1", "iBook (first generation)",2225PMAC_TYPE_ORIG_IBOOK, core99_features,2226PMAC_MB_CAN_SLEEP | PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE2227},2228{ "PowerBook2,2", "iBook FireWire",2229PMAC_TYPE_FW_IBOOK, core99_features,2230PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER |2231PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE2232},2233{ "PowerBook3,1", "PowerBook Pismo",2234PMAC_TYPE_PISMO, core99_features,2235PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER |2236PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE2237},2238{ "PowerBook3,2", "PowerBook Titanium",2239PMAC_TYPE_TITANIUM, core99_features,2240PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE2241},2242{ "PowerBook3,3", "PowerBook Titanium II",2243PMAC_TYPE_TITANIUM2, core99_features,2244PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE2245},2246{ "PowerBook3,4", "PowerBook Titanium III",2247PMAC_TYPE_TITANIUM3, core99_features,2248PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE2249},2250{ "PowerBook3,5", "PowerBook Titanium IV",2251PMAC_TYPE_TITANIUM4, core99_features,2252PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE2253},2254{ "PowerBook4,1", "iBook 2",2255PMAC_TYPE_IBOOK2, pangea_features,2256PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE2257},2258{ "PowerBook4,2", "iBook 2",2259PMAC_TYPE_IBOOK2, pangea_features,2260PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE2261},2262{ "PowerBook4,3", "iBook 2 rev. 2",2263PMAC_TYPE_IBOOK2, pangea_features,2264PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE2265},2266{ "PowerBook5,1", "PowerBook G4 17\"",2267PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2268PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2269},2270{ "PowerBook5,2", "PowerBook G4 15\"",2271PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2272PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2273},2274{ "PowerBook5,3", "PowerBook G4 17\"",2275PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2276PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2277},2278{ "PowerBook5,4", "PowerBook G4 15\"",2279PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2280PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2281},2282{ "PowerBook5,5", "PowerBook G4 17\"",2283PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2284PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2285},2286{ "PowerBook5,6", "PowerBook G4 15\"",2287PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2288PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2289},2290{ "PowerBook5,7", "PowerBook G4 17\"",2291PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2292PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2293},2294{ "PowerBook5,8", "PowerBook G4 15\"",2295PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2296PMAC_MB_MAY_SLEEP | PMAC_MB_MOBILE,2297},2298{ "PowerBook5,9", "PowerBook G4 17\"",2299PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2300PMAC_MB_MAY_SLEEP | PMAC_MB_MOBILE,2301},2302{ "PowerBook6,1", "PowerBook G4 12\"",2303PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2304PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2305},2306{ "PowerBook6,2", "PowerBook G4",2307PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2308PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2309},2310{ "PowerBook6,3", "iBook G4",2311PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2312PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2313},2314{ "PowerBook6,4", "PowerBook G4 12\"",2315PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2316PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2317},2318{ "PowerBook6,5", "iBook G4",2319PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2320PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2321},2322{ "PowerBook6,7", "iBook G4",2323PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2324PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2325},2326{ "PowerBook6,8", "PowerBook G4 12\"",2327PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,2328PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,2329},2330#else /* CONFIG_PPC64 */2331{ "PowerMac7,2", "PowerMac G5",2332PMAC_TYPE_POWERMAC_G5, g5_features,23330,2334},2335{ "PowerMac7,3", "PowerMac G5",2336PMAC_TYPE_POWERMAC_G5, g5_features,23370,2338},2339{ "PowerMac8,1", "iMac G5",2340PMAC_TYPE_IMAC_G5, g5_features,23410,2342},2343{ "PowerMac9,1", "PowerMac G5",2344PMAC_TYPE_POWERMAC_G5_U3L, g5_features,23450,2346},2347{ "PowerMac11,2", "PowerMac G5 Dual Core",2348PMAC_TYPE_POWERMAC_G5_U3L, g5_features,23490,2350},2351{ "PowerMac12,1", "iMac G5 (iSight)",2352PMAC_TYPE_POWERMAC_G5_U3L, g5_features,23530,2354},2355{ "RackMac3,1", "XServe G5",2356PMAC_TYPE_XSERVE_G5, g5_features,23570,2358},2359#endif /* CONFIG_PPC64 */2360};23612362/*2363* The toplevel feature_call callback2364*/2365long pmac_do_feature_call(unsigned int selector, ...)2366{2367struct device_node *node;2368long param, value;2369int i;2370feature_call func = NULL;2371va_list args;23722373if (pmac_mb.features)2374for (i=0; pmac_mb.features[i].function; i++)2375if (pmac_mb.features[i].selector == selector) {2376func = pmac_mb.features[i].function;2377break;2378}2379if (!func)2380for (i=0; any_features[i].function; i++)2381if (any_features[i].selector == selector) {2382func = any_features[i].function;2383break;2384}2385if (!func)2386return -ENODEV;23872388va_start(args, selector);2389node = (struct device_node*)va_arg(args, void*);2390param = va_arg(args, long);2391value = va_arg(args, long);2392va_end(args);23932394return func(node, param, value);2395}23962397static int __init probe_motherboard(void)2398{2399int i;2400struct macio_chip *macio = &macio_chips[0];2401const char *model = NULL;2402struct device_node *dt;2403int ret = 0;24042405/* Lookup known motherboard type in device-tree. First try an2406* exact match on the "model" property, then try a "compatible"2407* match is none is found.2408*/2409dt = of_find_node_by_name(NULL, "device-tree");2410if (dt != NULL)2411model = of_get_property(dt, "model", NULL);2412for(i=0; model && i<ARRAY_SIZE(pmac_mb_defs); i++) {2413if (strcmp(model, pmac_mb_defs[i].model_string) == 0) {2414pmac_mb = pmac_mb_defs[i];2415goto found;2416}2417}2418for(i=0; i<ARRAY_SIZE(pmac_mb_defs); i++) {2419if (of_machine_is_compatible(pmac_mb_defs[i].model_string)) {2420pmac_mb = pmac_mb_defs[i];2421goto found;2422}2423}24242425/* Fallback to selection depending on mac-io chip type */2426switch(macio->type) {2427#ifndef CONFIG_PPC642428case macio_grand_central:2429pmac_mb.model_id = PMAC_TYPE_PSURGE;2430pmac_mb.model_name = "Unknown PowerSurge";2431break;2432case macio_ohare:2433pmac_mb.model_id = PMAC_TYPE_UNKNOWN_OHARE;2434pmac_mb.model_name = "Unknown OHare-based";2435break;2436case macio_heathrow:2437pmac_mb.model_id = PMAC_TYPE_UNKNOWN_HEATHROW;2438pmac_mb.model_name = "Unknown Heathrow-based";2439pmac_mb.features = heathrow_desktop_features;2440break;2441case macio_paddington:2442pmac_mb.model_id = PMAC_TYPE_UNKNOWN_PADDINGTON;2443pmac_mb.model_name = "Unknown Paddington-based";2444pmac_mb.features = paddington_features;2445break;2446case macio_keylargo:2447pmac_mb.model_id = PMAC_TYPE_UNKNOWN_CORE99;2448pmac_mb.model_name = "Unknown Keylargo-based";2449pmac_mb.features = core99_features;2450break;2451case macio_pangea:2452pmac_mb.model_id = PMAC_TYPE_UNKNOWN_PANGEA;2453pmac_mb.model_name = "Unknown Pangea-based";2454pmac_mb.features = pangea_features;2455break;2456case macio_intrepid:2457pmac_mb.model_id = PMAC_TYPE_UNKNOWN_INTREPID;2458pmac_mb.model_name = "Unknown Intrepid-based";2459pmac_mb.features = intrepid_features;2460break;2461#else /* CONFIG_PPC64 */2462case macio_keylargo2:2463pmac_mb.model_id = PMAC_TYPE_UNKNOWN_K2;2464pmac_mb.model_name = "Unknown K2-based";2465pmac_mb.features = g5_features;2466break;2467case macio_shasta:2468pmac_mb.model_id = PMAC_TYPE_UNKNOWN_SHASTA;2469pmac_mb.model_name = "Unknown Shasta-based";2470pmac_mb.features = g5_features;2471break;2472#endif /* CONFIG_PPC64 */2473default:2474ret = -ENODEV;2475goto done;2476}2477found:2478#ifndef CONFIG_PPC642479/* Fixup Hooper vs. Comet */2480if (pmac_mb.model_id == PMAC_TYPE_HOOPER) {2481u32 __iomem * mach_id_ptr = ioremap(0xf3000034, 4);2482if (!mach_id_ptr) {2483ret = -ENODEV;2484goto done;2485}2486/* Here, I used to disable the media-bay on comet. It2487* appears this is wrong, the floppy connector is actually2488* a kind of media-bay and works with the current driver.2489*/2490if (__raw_readl(mach_id_ptr) & 0x20000000UL)2491pmac_mb.model_id = PMAC_TYPE_COMET;2492iounmap(mach_id_ptr);2493}24942495/* Set default value of powersave_nap on machines that support it.2496* It appears that uninorth rev 3 has a problem with it, we don't2497* enable it on those. In theory, the flush-on-lock property is2498* supposed to be set when not supported, but I'm not very confident2499* that all Apple OF revs did it properly, I do it the paranoid way.2500*/2501if (uninorth_base && uninorth_rev > 3) {2502struct device_node *np;25032504for_each_of_cpu_node(np) {2505int cpu_count = 1;25062507/* Nap mode not supported on SMP */2508if (of_property_read_bool(np, "flush-on-lock") ||2509(cpu_count > 1)) {2510powersave_nap = 0;2511of_node_put(np);2512break;2513}25142515cpu_count++;2516powersave_nap = 1;2517}2518}2519if (powersave_nap)2520printk(KERN_DEBUG "Processor NAP mode on idle enabled.\n");25212522/* On CPUs that support it (750FX), lowspeed by default during2523* NAP mode2524*/2525powersave_lowspeed = 1;25262527#else /* CONFIG_PPC64 */2528powersave_nap = 1;2529#endif /* CONFIG_PPC64 */25302531/* Check for "mobile" machine */2532if (model && (strncmp(model, "PowerBook", 9) == 02533|| strncmp(model, "iBook", 5) == 0))2534pmac_mb.board_flags |= PMAC_MB_MOBILE;253525362537printk(KERN_INFO "PowerMac motherboard: %s\n", pmac_mb.model_name);2538done:2539of_node_put(dt);2540return ret;2541}25422543/* Initialize the Core99 UniNorth host bridge and memory controller2544*/2545static void __init probe_uninorth(void)2546{2547struct resource res;2548unsigned long actrl;25492550/* Locate core99 Uni-N */2551uninorth_node = of_find_node_by_name(NULL, "uni-n");2552uninorth_maj = 1;25532554/* Locate G5 u3 */2555if (uninorth_node == NULL) {2556uninorth_node = of_find_node_by_name(NULL, "u3");2557uninorth_maj = 3;2558}2559/* Locate G5 u4 */2560if (uninorth_node == NULL) {2561uninorth_node = of_find_node_by_name(NULL, "u4");2562uninorth_maj = 4;2563}2564if (uninorth_node == NULL) {2565uninorth_maj = 0;2566return;2567}25682569if (of_address_to_resource(uninorth_node, 0, &res))2570return;25712572uninorth_base = ioremap(res.start, 0x40000);2573if (uninorth_base == NULL)2574return;2575uninorth_rev = in_be32(UN_REG(UNI_N_VERSION));2576if (uninorth_maj == 3 || uninorth_maj == 4) {2577u3_ht_base = ioremap(res.start + U3_HT_CONFIG_BASE, 0x1000);2578if (u3_ht_base == NULL) {2579iounmap(uninorth_base);2580return;2581}2582}25832584printk(KERN_INFO "Found %s memory controller & host bridge"2585" @ 0x%08x revision: 0x%02x\n", uninorth_maj == 3 ? "U3" :2586uninorth_maj == 4 ? "U4" : "UniNorth",2587(unsigned int)res.start, uninorth_rev);2588printk(KERN_INFO "Mapped at 0x%08lx\n", (unsigned long)uninorth_base);25892590/* Set the arbitrer QAck delay according to what Apple does2591*/2592if (uninorth_rev < 0x11) {2593actrl = UN_IN(UNI_N_ARB_CTRL) & ~UNI_N_ARB_CTRL_QACK_DELAY_MASK;2594actrl |= ((uninorth_rev < 3) ? UNI_N_ARB_CTRL_QACK_DELAY105 :2595UNI_N_ARB_CTRL_QACK_DELAY) <<2596UNI_N_ARB_CTRL_QACK_DELAY_SHIFT;2597UN_OUT(UNI_N_ARB_CTRL, actrl);2598}25992600/* Some more magic as done by them in recent MacOS X on UniNorth2601* revs 1.5 to 2.O and Pangea. Seem to toggle the UniN Maxbus/PCI2602* memory timeout2603*/2604if ((uninorth_rev >= 0x11 && uninorth_rev <= 0x24) ||2605uninorth_rev == 0xc0)2606UN_OUT(0x2160, UN_IN(0x2160) & 0x00ffffff);2607}26082609static void __init probe_one_macio(const char *name, const char *compat, int type)2610{2611struct device_node* node;2612int i;2613volatile u32 __iomem *base;2614const __be32 *addrp;2615const u32 *revp;2616phys_addr_t addr;2617u64 size;26182619for_each_node_by_name(node, name) {2620if (!compat)2621break;2622if (of_device_is_compatible(node, compat))2623break;2624}2625if (!node)2626return;2627for(i=0; i<MAX_MACIO_CHIPS; i++) {2628if (!macio_chips[i].of_node)2629break;2630if (macio_chips[i].of_node == node)2631goto out_put;2632}26332634if (i >= MAX_MACIO_CHIPS) {2635printk(KERN_ERR "pmac_feature: Please increase MAX_MACIO_CHIPS !\n");2636printk(KERN_ERR "pmac_feature: %pOF skipped\n", node);2637goto out_put;2638}2639addrp = of_get_pci_address(node, 0, &size, NULL);2640if (addrp == NULL) {2641printk(KERN_ERR "pmac_feature: %pOF: can't find base !\n",2642node);2643goto out_put;2644}2645addr = of_translate_address(node, addrp);2646if (addr == 0) {2647printk(KERN_ERR "pmac_feature: %pOF, can't translate base !\n",2648node);2649goto out_put;2650}2651base = ioremap(addr, (unsigned long)size);2652if (!base) {2653printk(KERN_ERR "pmac_feature: %pOF, can't map mac-io chip !\n",2654node);2655goto out_put;2656}2657if (type == macio_keylargo || type == macio_keylargo2) {2658const u32 *did = of_get_property(node, "device-id", NULL);2659if (*did == 0x00000025)2660type = macio_pangea;2661if (*did == 0x0000003e)2662type = macio_intrepid;2663if (*did == 0x0000004f)2664type = macio_shasta;2665}2666macio_chips[i].of_node = node;2667macio_chips[i].type = type;2668macio_chips[i].base = base;2669macio_chips[i].flags = MACIO_FLAG_SCCA_ON | MACIO_FLAG_SCCB_ON;2670macio_chips[i].name = macio_names[type];2671revp = of_get_property(node, "revision-id", NULL);2672if (revp)2673macio_chips[i].rev = *revp;2674printk(KERN_INFO "Found a %s mac-io controller, rev: %d, mapped at 0x%p\n",2675macio_names[type], macio_chips[i].rev, macio_chips[i].base);26762677return;26782679out_put:2680of_node_put(node);2681}26822683static int __init2684probe_macios(void)2685{2686/* Warning, ordering is important */2687probe_one_macio("gc", NULL, macio_grand_central);2688probe_one_macio("ohare", NULL, macio_ohare);2689probe_one_macio("pci106b,7", NULL, macio_ohareII);2690probe_one_macio("mac-io", "keylargo", macio_keylargo);2691probe_one_macio("mac-io", "paddington", macio_paddington);2692probe_one_macio("mac-io", "gatwick", macio_gatwick);2693probe_one_macio("mac-io", "heathrow", macio_heathrow);2694probe_one_macio("mac-io", "K2-Keylargo", macio_keylargo2);26952696/* Make sure the "main" macio chip appear first */2697if (macio_chips[0].type == macio_gatwick2698&& macio_chips[1].type == macio_heathrow) {2699struct macio_chip temp = macio_chips[0];2700macio_chips[0] = macio_chips[1];2701macio_chips[1] = temp;2702}2703if (macio_chips[0].type == macio_ohareII2704&& macio_chips[1].type == macio_ohare) {2705struct macio_chip temp = macio_chips[0];2706macio_chips[0] = macio_chips[1];2707macio_chips[1] = temp;2708}2709macio_chips[0].lbus.index = 0;2710macio_chips[1].lbus.index = 1;27112712return (macio_chips[0].of_node == NULL) ? -ENODEV : 0;2713}27142715static void __init2716initial_serial_shutdown(struct device_node *np)2717{2718int len;2719const struct slot_names_prop {2720int count;2721char name[1];2722} *slots;2723const char *conn;2724int port_type = PMAC_SCC_ASYNC;2725int modem = 0;27262727slots = of_get_property(np, "slot-names", &len);2728conn = of_get_property(np, "AAPL,connector", &len);2729if (conn && (strcmp(conn, "infrared") == 0))2730port_type = PMAC_SCC_IRDA;2731else if (of_device_is_compatible(np, "cobalt"))2732modem = 1;2733else if (slots && slots->count > 0) {2734if (strcmp(slots->name, "IrDA") == 0)2735port_type = PMAC_SCC_IRDA;2736else if (strcmp(slots->name, "Modem") == 0)2737modem = 1;2738}2739if (modem)2740pmac_call_feature(PMAC_FTR_MODEM_ENABLE, np, 0, 0);2741pmac_call_feature(PMAC_FTR_SCC_ENABLE, np, port_type, 0);2742}27432744static void __init2745set_initial_features(void)2746{2747struct device_node *np;27482749/* That hack appears to be necessary for some StarMax motherboards2750* but I'm not too sure it was audited for side-effects on other2751* ohare based machines...2752* Since I still have difficulties figuring the right way to2753* differentiate them all and since that hack was there for a long2754* time, I'll keep it around2755*/2756if (macio_chips[0].type == macio_ohare) {2757struct macio_chip *macio = &macio_chips[0];2758np = of_find_node_by_name(NULL, "via-pmu");2759if (np)2760MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);2761else2762MACIO_OUT32(OHARE_FCR, STARMAX_FEATURES);2763of_node_put(np);2764} else if (macio_chips[1].type == macio_ohare) {2765struct macio_chip *macio = &macio_chips[1];2766MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);2767}27682769#ifdef CONFIG_PPC642770if (macio_chips[0].type == macio_keylargo2 ||2771macio_chips[0].type == macio_shasta) {2772#ifndef CONFIG_SMP2773/* On SMP machines running UP, we have the second CPU eating2774* bus cycles. We need to take it off the bus. This is done2775* from pmac_smp for SMP kernels running on one CPU2776*/2777np = of_find_node_by_type(NULL, "cpu");2778if (np != NULL)2779np = of_find_node_by_type(np, "cpu");2780if (np != NULL) {2781g5_phy_disable_cpu1();2782of_node_put(np);2783}2784#endif /* CONFIG_SMP */2785/* Enable GMAC for now for PCI probing. It will be disabled2786* later on after PCI probe2787*/2788for_each_node_by_name(np, "ethernet")2789if (of_device_is_compatible(np, "K2-GMAC"))2790g5_gmac_enable(np, 0, 1);27912792/* Enable FW before PCI probe. Will be disabled later on2793* Note: We should have a batter way to check that we are2794* dealing with uninorth internal cell and not a PCI cell2795* on the external PCI. The code below works though.2796*/2797for_each_node_by_name(np, "firewire") {2798if (of_device_is_compatible(np, "pci106b,5811")) {2799macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;2800g5_fw_enable(np, 0, 1);2801}2802}2803}2804#else /* CONFIG_PPC64 */28052806if (macio_chips[0].type == macio_keylargo ||2807macio_chips[0].type == macio_pangea ||2808macio_chips[0].type == macio_intrepid) {2809/* Enable GMAC for now for PCI probing. It will be disabled2810* later on after PCI probe2811*/2812for_each_node_by_name(np, "ethernet") {2813if (np->parent2814&& of_device_is_compatible(np->parent, "uni-north")2815&& of_device_is_compatible(np, "gmac"))2816core99_gmac_enable(np, 0, 1);2817}28182819/* Enable FW before PCI probe. Will be disabled later on2820* Note: We should have a batter way to check that we are2821* dealing with uninorth internal cell and not a PCI cell2822* on the external PCI. The code below works though.2823*/2824for_each_node_by_name(np, "firewire") {2825if (np->parent2826&& of_device_is_compatible(np->parent, "uni-north")2827&& (of_device_is_compatible(np, "pci106b,18") ||2828of_device_is_compatible(np, "pci106b,30") ||2829of_device_is_compatible(np, "pci11c1,5811"))) {2830macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;2831core99_firewire_enable(np, 0, 1);2832}2833}28342835/* Enable ATA-100 before PCI probe. */2836for_each_node_by_name(np, "ata-6") {2837if (np->parent2838&& of_device_is_compatible(np->parent, "uni-north")2839&& of_device_is_compatible(np, "kauai-ata")) {2840core99_ata100_enable(np, 1);2841}2842}28432844/* Switch airport off */2845for_each_node_by_name(np, "radio") {2846if (np->parent == macio_chips[0].of_node) {2847macio_chips[0].flags |= MACIO_FLAG_AIRPORT_ON;2848core99_airport_enable(np, 0, 0);2849}2850}2851}28522853/* On all machines that support sound PM, switch sound off */2854if (macio_chips[0].of_node)2855pmac_do_feature_call(PMAC_FTR_SOUND_CHIP_ENABLE,2856macio_chips[0].of_node, 0, 0);28572858/* While on some desktop G3s, we turn it back on */2859if (macio_chips[0].of_node && macio_chips[0].type == macio_heathrow2860&& (pmac_mb.model_id == PMAC_TYPE_GOSSAMER ||2861pmac_mb.model_id == PMAC_TYPE_SILK)) {2862struct macio_chip *macio = &macio_chips[0];2863MACIO_BIS(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);2864MACIO_BIC(HEATHROW_FCR, HRW_SOUND_POWER_N);2865}28662867#endif /* CONFIG_PPC64 */28682869/* On all machines, switch modem & serial ports off */2870for_each_node_by_name(np, "ch-a")2871initial_serial_shutdown(np);2872for_each_node_by_name(np, "ch-b")2873initial_serial_shutdown(np);2874}28752876void __init2877pmac_feature_init(void)2878{2879/* Detect the UniNorth memory controller */2880probe_uninorth();28812882/* Probe mac-io controllers */2883if (probe_macios()) {2884printk(KERN_WARNING "No mac-io chip found\n");2885return;2886}28872888/* Probe machine type */2889if (probe_motherboard())2890printk(KERN_WARNING "Unknown PowerMac !\n");28912892/* Set some initial features (turn off some chips that will2893* be later turned on)2894*/2895set_initial_features();2896}28972898#if 02899static void dump_HT_speeds(char *name, u32 cfg, u32 frq)2900{2901int freqs[16] = { 200,300,400,500,600,800,1000,0,0,0,0,0,0,0,0,0 };2902int bits[8] = { 8,16,0,32,2,4,0,0 };2903int freq = (frq >> 8) & 0xf;29042905if (freqs[freq] == 0)2906printk("%s: Unknown HT link frequency %x\n", name, freq);2907else2908printk("%s: %d MHz on main link, (%d in / %d out) bits width\n",2909name, freqs[freq],2910bits[(cfg >> 28) & 0x7], bits[(cfg >> 24) & 0x7]);2911}29122913void __init pmac_check_ht_link(void)2914{2915u32 ufreq, freq, ucfg, cfg;2916struct device_node *pcix_node;2917u8 px_bus, px_devfn;2918struct pci_controller *px_hose;29192920(void)in_be32(u3_ht_base + U3_HT_LINK_COMMAND);2921ucfg = cfg = in_be32(u3_ht_base + U3_HT_LINK_CONFIG);2922ufreq = freq = in_be32(u3_ht_base + U3_HT_LINK_FREQ);2923dump_HT_speeds("U3 HyperTransport", cfg, freq);29242925pcix_node = of_find_compatible_node(NULL, "pci", "pci-x");2926if (pcix_node == NULL) {2927printk("No PCI-X bridge found\n");2928return;2929}2930if (pci_device_from_OF_node(pcix_node, &px_bus, &px_devfn) != 0) {2931printk("PCI-X bridge found but not matched to pci\n");2932return;2933}2934px_hose = pci_find_hose_for_OF_device(pcix_node);2935if (px_hose == NULL) {2936printk("PCI-X bridge found but not matched to host\n");2937return;2938}2939early_read_config_dword(px_hose, px_bus, px_devfn, 0xc4, &cfg);2940early_read_config_dword(px_hose, px_bus, px_devfn, 0xcc, &freq);2941dump_HT_speeds("PCI-X HT Uplink", cfg, freq);2942early_read_config_dword(px_hose, px_bus, px_devfn, 0xc8, &cfg);2943early_read_config_dword(px_hose, px_bus, px_devfn, 0xd0, &freq);2944dump_HT_speeds("PCI-X HT Downlink", cfg, freq);2945}2946#endif /* 0 */29472948/*2949* Early video resume hook2950*/29512952static void (*pmac_early_vresume_proc)(void *data);2953static void *pmac_early_vresume_data;29542955void pmac_set_early_video_resume(void (*proc)(void *data), void *data)2956{2957if (!machine_is(powermac))2958return;2959preempt_disable();2960pmac_early_vresume_proc = proc;2961pmac_early_vresume_data = data;2962preempt_enable();2963}2964EXPORT_SYMBOL(pmac_set_early_video_resume);29652966void pmac_call_early_video_resume(void)2967{2968if (pmac_early_vresume_proc)2969pmac_early_vresume_proc(pmac_early_vresume_data);2970}29712972/*2973* AGP related suspend/resume code2974*/29752976static struct pci_dev *pmac_agp_bridge;2977static int (*pmac_agp_suspend)(struct pci_dev *bridge);2978static int (*pmac_agp_resume)(struct pci_dev *bridge);29792980void pmac_register_agp_pm(struct pci_dev *bridge,2981int (*suspend)(struct pci_dev *bridge),2982int (*resume)(struct pci_dev *bridge))2983{2984if (suspend || resume) {2985pmac_agp_bridge = bridge;2986pmac_agp_suspend = suspend;2987pmac_agp_resume = resume;2988return;2989}2990if (bridge != pmac_agp_bridge)2991return;2992pmac_agp_suspend = pmac_agp_resume = NULL;2993return;2994}2995EXPORT_SYMBOL(pmac_register_agp_pm);29962997void pmac_suspend_agp_for_card(struct pci_dev *dev)2998{2999if (pmac_agp_bridge == NULL || pmac_agp_suspend == NULL)3000return;3001if (pmac_agp_bridge->bus != dev->bus)3002return;3003pmac_agp_suspend(pmac_agp_bridge);3004}3005EXPORT_SYMBOL(pmac_suspend_agp_for_card);30063007void pmac_resume_agp_for_card(struct pci_dev *dev)3008{3009if (pmac_agp_bridge == NULL || pmac_agp_resume == NULL)3010return;3011if (pmac_agp_bridge->bus != dev->bus)3012return;3013pmac_agp_resume(pmac_agp_bridge);3014}3015EXPORT_SYMBOL(pmac_resume_agp_for_card);30163017int pmac_get_uninorth_variant(void)3018{3019return uninorth_maj;3020}302130223023