Merge ../powerpc-merge
[linux-2.6.git] / arch / powerpc / platforms / powermac / feature.c
index b1f8969..c8b4a2b 100644 (file)
@@ -1,6 +1,4 @@
 /*
- *  arch/ppc/platforms/pmac_feature.c
- *
  *  Copyright (C) 1996-2001 Paul Mackerras (paulus@cs.anu.edu.au)
  *                          Ben. Herrenschmidt (benh@kernel.crashing.org)
  *
@@ -58,12 +56,11 @@ extern int powersave_lowspeed;
 extern int powersave_nap;
 extern struct device_node *k2_skiplist[2];
 
-
 /*
  * We use a single global lock to protect accesses. Each driver has
  * to take care of its own locking
  */
-static DEFINE_SPINLOCK(feature_lock);
+DEFINE_SPINLOCK(feature_lock);
 
 #define LOCK(flags)    spin_lock_irqsave(&feature_lock, flags);
 #define UNLOCK(flags)  spin_unlock_irqrestore(&feature_lock, flags);
@@ -101,26 +98,17 @@ static const char *macio_names[] =
        "Keylargo",
        "Pangea",
        "Intrepid",
-       "K2"
+       "K2",
+       "Shasta",
 };
 
 
+struct device_node *uninorth_node;
+u32 __iomem *uninorth_base;
 
-/*
- * Uninorth reg. access. Note that Uni-N regs are big endian
- */
-
-#define UN_REG(r)      (uninorth_base + ((r) >> 2))
-#define UN_IN(r)       (in_be32(UN_REG(r)))
-#define UN_OUT(r,v)    (out_be32(UN_REG(r), (v)))
-#define UN_BIS(r,v)    (UN_OUT((r), UN_IN(r) | (v)))
-#define UN_BIC(r,v)    (UN_OUT((r), UN_IN(r) & ~(v)))
-
-static struct device_node *uninorth_node;
-static u32 __iomem *uninorth_base;
 static u32 uninorth_rev;
-static int uninorth_u3;
-static void __iomem *u3_ht;
+static int uninorth_maj;
+static void __iomem *u3_ht_base;
 
 /*
  * For each motherboard family, we have a table of functions pointers
@@ -1399,8 +1387,15 @@ static long g5_fw_enable(struct device_node *node, long param, long value)
 static long g5_mpic_enable(struct device_node *node, long param, long value)
 {
        unsigned long flags;
+       struct device_node *parent = of_get_parent(node);
+       int is_u3;
 
-       if (node->parent == NULL || strcmp(node->parent->name, "u3"))
+       if (parent == NULL)
+               return 0;
+       is_u3 = strcmp(parent->name, "u3") == 0 ||
+               strcmp(parent->name, "u4") == 0;
+       of_node_put(parent);
+       if (!is_u3)
                return 0;
 
        LOCK(flags);
@@ -1464,7 +1459,7 @@ static long g5_i2s_enable(struct device_node *node, long param, long value)
                },
        };
 
-       if (macio->type != macio_keylargo2 /* && macio->type != macio_shasta*/)
+       if (macio->type != macio_keylargo2 && macio->type != macio_shasta)
                return -ENODEV;
        if (strncmp(node->name, "i2s-", 4))
                return -ENODEV;
@@ -1473,11 +1468,9 @@ static long g5_i2s_enable(struct device_node *node, long param, long value)
        case 0:
        case 1:
                break;
-#if 0
        case 2:
                if (macio->type == macio_shasta)
                        break;
-#endif
        default:
                return -ENODEV;
        }
@@ -1508,7 +1501,7 @@ static long g5_reset_cpu(struct device_node *node, long param, long value)
        struct device_node *np;
 
        macio = &macio_chips[0];
-       if (macio->type != macio_keylargo2)
+       if (macio->type != macio_keylargo2 && macio->type != macio_shasta)
                return -ENODEV;
 
        np = find_path_device("/cpus");
@@ -1547,14 +1540,17 @@ static long g5_reset_cpu(struct device_node *node, long param, long value)
  */
 void g5_phy_disable_cpu1(void)
 {
-       UN_OUT(U3_API_PHY_CONFIG_1, 0);
+       if (uninorth_maj == 3)
+               UN_OUT(U3_API_PHY_CONFIG_1, 0);
 }
 #endif /* CONFIG_POWER4 */
 
 #ifndef CONFIG_POWER4
 
-static void
-keylargo_shutdown(struct macio_chip *macio, int sleep_mode)
+
+#ifdef CONFIG_PM
+
+static void keylargo_shutdown(struct macio_chip *macio, int sleep_mode)
 {
        u32 temp;
 
@@ -1607,8 +1603,7 @@ keylargo_shutdown(struct macio_chip *macio, int sleep_mode)
        (void)MACIO_IN32(KEYLARGO_FCR0); mdelay(1);
 }
 
-static void
-pangea_shutdown(struct macio_chip *macio, int sleep_mode)
+static void pangea_shutdown(struct macio_chip *macio, int sleep_mode)
 {
        u32 temp;
 
@@ -1641,8 +1636,7 @@ pangea_shutdown(struct macio_chip *macio, int sleep_mode)
        (void)MACIO_IN32(KEYLARGO_FCR0); mdelay(1);
 }
 
-static void
-intrepid_shutdown(struct macio_chip *macio, int sleep_mode)
+static void intrepid_shutdown(struct macio_chip *macio, int sleep_mode)
 {
        u32 temp;
 
@@ -1650,10 +1644,10 @@ intrepid_shutdown(struct macio_chip *macio, int sleep_mode)
                  KL0_SCC_CELL_ENABLE);
 
        MACIO_BIC(KEYLARGO_FCR1,
-                 /*KL1_USB2_CELL_ENABLE |*/
                KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
                KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
-               KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE);
+               KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
+               KL1_EIDE0_ENABLE);
        if (pmac_mb.board_flags & PMAC_MB_MOBILE)
                MACIO_BIC(KEYLARGO_FCR1, KL1_UIDE_RESET_N);
 
@@ -1670,124 +1664,6 @@ intrepid_shutdown(struct macio_chip *macio, int sleep_mode)
 }
 
 
-void pmac_tweak_clock_spreading(int enable)
-{
-       struct macio_chip *macio = &macio_chips[0];
-
-       /* Hack for doing clock spreading on some machines PowerBooks and
-        * iBooks. This implements the "platform-do-clockspreading" OF
-        * property as decoded manually on various models. For safety, we also
-        * check the product ID in the device-tree in cases we'll whack the i2c
-        * chip to make reasonably sure we won't set wrong values in there
-        *
-        * Of course, ultimately, we have to implement a real parser for
-        * the platform-do-* stuff...
-        */
-
-       if (macio->type == macio_intrepid) {
-               struct device_node *clock =
-                       of_find_node_by_path("/uni-n@f8000000/hw-clock");
-               if (clock && get_property(clock, "platform-do-clockspreading",
-                                         NULL)) {
-                       printk(KERN_INFO "%sabling clock spreading on Intrepid"
-                              " ASIC\n", enable ? "En" : "Dis");
-                       if (enable)
-                               UN_OUT(UNI_N_CLOCK_SPREADING, 2);
-                       else
-                               UN_OUT(UNI_N_CLOCK_SPREADING, 0);
-                       mdelay(40);
-               }
-               of_node_put(clock);
-       }
-
-       while (machine_is_compatible("PowerBook5,2") ||
-              machine_is_compatible("PowerBook5,3") ||
-              machine_is_compatible("PowerBook6,2") ||
-              machine_is_compatible("PowerBook6,3")) {
-               struct device_node *ui2c = of_find_node_by_type(NULL, "i2c");
-               struct device_node *dt = of_find_node_by_name(NULL, "device-tree");
-               u8 buffer[9];
-               u32 *productID;
-               int i, rc, changed = 0;
-
-               if (dt == NULL)
-                       break;
-               productID = (u32 *)get_property(dt, "pid#", NULL);
-               if (productID == NULL)
-                       break;
-               while(ui2c) {
-                       struct device_node *p = of_get_parent(ui2c);
-                       if (p && !strcmp(p->name, "uni-n"))
-                               break;
-                       ui2c = of_find_node_by_type(ui2c, "i2c");
-               }
-               if (ui2c == NULL)
-                       break;
-               DBG("Trying to bump clock speed for PID: %08x...\n", *productID);
-               rc = pmac_low_i2c_open(ui2c, 1);
-               if (rc != 0)
-                       break;
-               pmac_low_i2c_setmode(ui2c, pmac_low_i2c_mode_combined);
-               rc = pmac_low_i2c_xfer(ui2c, 0xd2 | pmac_low_i2c_read, 0x80, buffer, 9);
-               DBG("read result: %d,", rc);
-               if (rc != 0) {
-                       pmac_low_i2c_close(ui2c);
-                       break;
-               }
-               for (i=0; i<9; i++)
-                       DBG(" %02x", buffer[i]);
-               DBG("\n");
-
-               switch(*productID) {
-               case 0x1182:    /* AlBook 12" rev 2 */
-               case 0x1183:    /* iBook G4 12" */
-                       buffer[0] = (buffer[0] & 0x8f) | 0x70;
-                       buffer[2] = (buffer[2] & 0x7f) | 0x00;
-                       buffer[5] = (buffer[5] & 0x80) | 0x31;
-                       buffer[6] = (buffer[6] & 0x40) | 0xb0;
-                       buffer[7] = (buffer[7] & 0x00) | (enable ? 0xc0 : 0xba);
-                       buffer[8] = (buffer[8] & 0x00) | 0x30;
-                       changed = 1;
-                       break;
-               case 0x3142:    /* AlBook 15" (ATI M10) */
-               case 0x3143:    /* AlBook 17" (ATI M10) */
-                       buffer[0] = (buffer[0] & 0xaf) | 0x50;
-                       buffer[2] = (buffer[2] & 0x7f) | 0x00;
-                       buffer[5] = (buffer[5] & 0x80) | 0x31;
-                       buffer[6] = (buffer[6] & 0x40) | 0xb0;
-                       buffer[7] = (buffer[7] & 0x00) | (enable ? 0xd0 : 0xc0);
-                       buffer[8] = (buffer[8] & 0x00) | 0x30;
-                       changed = 1;
-                       break;
-               default:
-                       DBG("i2c-hwclock: Machine model not handled\n");
-                       break;
-               }
-               if (!changed) {
-                       pmac_low_i2c_close(ui2c);
-                       break;
-               }
-               printk(KERN_INFO "%sabling clock spreading on i2c clock chip\n",
-                      enable ? "En" : "Dis");
-
-               pmac_low_i2c_setmode(ui2c, pmac_low_i2c_mode_stdsub);
-               rc = pmac_low_i2c_xfer(ui2c, 0xd2 | pmac_low_i2c_write, 0x80, buffer, 9);
-               DBG("write result: %d,", rc);
-               pmac_low_i2c_setmode(ui2c, pmac_low_i2c_mode_combined);
-               rc = pmac_low_i2c_xfer(ui2c, 0xd2 | pmac_low_i2c_read, 0x80, buffer, 9);
-               DBG("read result: %d,", rc);
-               if (rc != 0) {
-                       pmac_low_i2c_close(ui2c);
-                       break;
-               }
-               for (i=0; i<9; i++)
-                       DBG(" %02x", buffer[i]);
-               pmac_low_i2c_close(ui2c);
-               break;
-       }
-}
-
-
 static int
 core99_sleep(void)
 {
@@ -1944,6 +1820,8 @@ core99_wake_up(void)
        return 0;
 }
 
+#endif /* CONFIG_PM */
+
 static long
 core99_sleep_state(struct device_node *node, long param, long value)
 {
@@ -1965,10 +1843,13 @@ core99_sleep_state(struct device_node *node, long param, long value)
        if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
                return -EPERM;
 
+#ifdef CONFIG_PM
        if (value == 1)
                return core99_sleep();
        else if (value == 0)
                return core99_wake_up();
+
+#endif /* CONFIG_PM */
        return 0;
 }
 
@@ -2092,7 +1973,9 @@ static struct feature_table_entry core99_features[] = {
        { PMAC_FTR_USB_ENABLE,          core99_usb_enable },
        { PMAC_FTR_1394_ENABLE,         core99_firewire_enable },
        { PMAC_FTR_1394_CABLE_POWER,    core99_firewire_cable_power },
+#ifdef CONFIG_PM
        { PMAC_FTR_SLEEP_STATE,         core99_sleep_state },
+#endif
 #ifdef CONFIG_SMP
        { PMAC_FTR_RESET_CPU,           core99_reset_cpu },
 #endif /* CONFIG_SMP */
@@ -2298,7 +2181,7 @@ static struct pmac_mb_def pmac_mb_defs[] = {
        },
        {       "PowerMac10,1",                 "Mac mini",
                PMAC_TYPE_UNKNOWN_INTREPID,     intrepid_features,
-               PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER,
+               PMAC_MB_MAY_SLEEP,
        },
        {       "iMac,1",                       "iMac (first generation)",
                PMAC_TYPE_ORIG_IMAC,            paddington_features,
@@ -2410,11 +2293,11 @@ static struct pmac_mb_def pmac_mb_defs[] = {
        },
        {       "PowerBook5,8",                 "PowerBook G4 15\"",
                PMAC_TYPE_UNKNOWN_INTREPID,     intrepid_features,
-               PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
+               PMAC_MB_MAY_SLEEP  | PMAC_MB_MOBILE,
        },
        {       "PowerBook5,9",                 "PowerBook G4 17\"",
                PMAC_TYPE_UNKNOWN_INTREPID,     intrepid_features,
-               PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
+               PMAC_MB_MAY_SLEEP | PMAC_MB_MOBILE,
        },
        {       "PowerBook6,1",                 "PowerBook G4 12\"",
                PMAC_TYPE_UNKNOWN_INTREPID,     intrepid_features,
@@ -2462,6 +2345,14 @@ static struct pmac_mb_def pmac_mb_defs[] = {
                PMAC_TYPE_POWERMAC_G5_U3L,      g5_features,
                0,
        },
+       {       "PowerMac11,2",                 "PowerMac G5 Dual Core",
+               PMAC_TYPE_POWERMAC_G5_U3L,      g5_features,
+               0,
+       },
+       {       "PowerMac12,1",                 "iMac G5 (iSight)",
+               PMAC_TYPE_POWERMAC_G5_U3L,      g5_features,
+               0,
+       },
        {       "RackMac3,1",                   "XServe G5",
                PMAC_TYPE_XSERVE_G5,            g5_features,
                0,
@@ -2574,6 +2465,11 @@ static int __init probe_motherboard(void)
                pmac_mb.model_name = "Unknown K2-based";
                pmac_mb.features = g5_features;
                break;
+       case macio_shasta:
+               pmac_mb.model_id = PMAC_TYPE_UNKNOWN_SHASTA;
+               pmac_mb.model_name = "Unknown Shasta-based";
+               pmac_mb.features = g5_features;
+               break;
 #endif /* CONFIG_POWER4 */
        default:
                return -ENODEV;
@@ -2651,7 +2547,12 @@ static void __init probe_uninorth(void)
        /* Locate G5 u3 */
        if (uninorth_node == NULL) {
                uninorth_node = of_find_node_by_name(NULL, "u3");
-               uninorth_u3 = 1;
+               uninorth_maj = 3;
+       }
+       /* Locate G5 u4 */
+       if (uninorth_node == NULL) {
+               uninorth_node = of_find_node_by_name(NULL, "u4");
+               uninorth_maj = 4;
        }
        if (uninorth_node == NULL)
                return;
@@ -2664,12 +2565,13 @@ static void __init probe_uninorth(void)
                return;
        uninorth_base = ioremap(address, 0x40000);
        uninorth_rev = in_be32(UN_REG(UNI_N_VERSION));
-       if (uninorth_u3)
-               u3_ht = ioremap(address + U3_HT_CONFIG_BASE, 0x1000);
+       if (uninorth_maj == 3 || uninorth_maj == 4)
+               u3_ht_base = ioremap(address + U3_HT_CONFIG_BASE, 0x1000);
 
-       printk(KERN_INFO "Found %s memory controller & host bridge,"
-              " revision: %d\n", uninorth_u3 ? "U3" : "UniNorth",
-              uninorth_rev);
+       printk(KERN_INFO "Found %s memory controller & host bridge"
+              " @ 0x%08x revision: 0x%02x\n", uninorth_maj == 3 ? "U3" :
+              uninorth_maj == 4 ? "U4" : "UniNorth",
+              (unsigned int)address, uninorth_rev);
        printk(KERN_INFO "Mapped at 0x%08lx\n", (unsigned long)uninorth_base);
 
        /* Set the arbitrer QAck delay according to what Apple does
@@ -2677,7 +2579,8 @@ static void __init probe_uninorth(void)
        if (uninorth_rev < 0x11) {
                actrl = UN_IN(UNI_N_ARB_CTRL) & ~UNI_N_ARB_CTRL_QACK_DELAY_MASK;
                actrl |= ((uninorth_rev < 3) ? UNI_N_ARB_CTRL_QACK_DELAY105 :
-                       UNI_N_ARB_CTRL_QACK_DELAY) << UNI_N_ARB_CTRL_QACK_DELAY_SHIFT;
+                       UNI_N_ARB_CTRL_QACK_DELAY) <<
+                       UNI_N_ARB_CTRL_QACK_DELAY_SHIFT;
                UN_OUT(UNI_N_ARB_CTRL, actrl);
        }
 
@@ -2685,7 +2588,8 @@ static void __init probe_uninorth(void)
         * revs 1.5 to 2.O and Pangea. Seem to toggle the UniN Maxbus/PCI
         * memory timeout
         */
-       if ((uninorth_rev >= 0x11 && uninorth_rev <= 0x24) || uninorth_rev == 0xc0)
+       if ((uninorth_rev >= 0x11 && uninorth_rev <= 0x24) ||
+           uninorth_rev == 0xc0)
                UN_OUT(0x2160, UN_IN(0x2160) & 0x00ffffff);
 }
 
@@ -2736,12 +2640,14 @@ static void __init probe_one_macio(const char *name, const char *compat, int typ
                       node->full_name);
                return;
        }
-       if (type == macio_keylargo) {
+       if (type == macio_keylargo || type == macio_keylargo2) {
                u32 *did = (u32 *)get_property(node, "device-id", NULL);
                if (*did == 0x00000025)
                        type = macio_pangea;
                if (*did == 0x0000003e)
                        type = macio_intrepid;
+               if (*did == 0x0000004f)
+                       type = macio_shasta;
        }
        macio_chips[i].of_node  = node;
        macio_chips[i].type     = type;
@@ -2840,7 +2746,8 @@ set_initial_features(void)
        }
 
 #ifdef CONFIG_POWER4
-       if (macio_chips[0].type == macio_keylargo2) {
+       if (macio_chips[0].type == macio_keylargo2 ||
+           macio_chips[0].type == macio_shasta) {
 #ifndef CONFIG_SMP
                /* On SMP machines running UP, we have the second CPU eating
                 * bus cycles. We need to take it off the bus. This is done
@@ -2949,12 +2856,6 @@ set_initial_features(void)
                MACIO_BIC(HEATHROW_FCR, HRW_SOUND_POWER_N);
        }
 
-       /* Some machine models need the clock chip to be properly setup for
-        * clock spreading now. This should be a platform function but we
-        * don't do these at the moment
-        */
-       pmac_tweak_clock_spreading(1);
-
 #endif /* CONFIG_POWER4 */
 
        /* On all machines, switch modem & serial ports off */
@@ -2982,9 +2883,6 @@ pmac_feature_init(void)
                return;
        }
 
-       /* Setup low-level i2c stuffs */
-       pmac_init_low_i2c();
-
        /* Probe machine type */
        if (probe_motherboard())
                printk(KERN_WARNING "Unknown PowerMac !\n");
@@ -3017,9 +2915,9 @@ void __init pmac_check_ht_link(void)
        u8      px_bus, px_devfn;
        struct pci_controller *px_hose;
 
-       (void)in_be32(u3_ht + U3_HT_LINK_COMMAND);
-       ucfg = cfg = in_be32(u3_ht + U3_HT_LINK_CONFIG);
-       ufreq = freq = in_be32(u3_ht + U3_HT_LINK_FREQ);
+       (void)in_be32(u3_ht_base + U3_HT_LINK_COMMAND);
+       ucfg = cfg = in_be32(u3_ht_base + U3_HT_LINK_CONFIG);
+       ufreq = freq = in_be32(u3_ht_base + U3_HT_LINK_FREQ);
        dump_HT_speeds("U3 HyperTransport", cfg, freq);
 
        pcix_node = of_find_compatible_node(NULL, "pci", "pci-x");