]> err.no Git - linux-2.6/blobdiff - drivers/macintosh/via-pmu.c
[PATCH] powerpc: Update OF address parsers
[linux-2.6] / drivers / macintosh / via-pmu.c
index 91920a1140fa1335ea76135580cc29e85f6518fe..d6dabee55f2feeafed35d3b96390dd65f8d5b715 100644 (file)
@@ -147,6 +147,7 @@ static struct device_node *vias;
 static int pmu_kind = PMU_UNKNOWN;
 static int pmu_fully_inited = 0;
 static int pmu_has_adb;
+static struct device_node *gpio_node;
 static unsigned char __iomem *gpio_reg = NULL;
 static int gpio_irq = -1;
 static int gpio_irq_enabled = -1;
@@ -155,10 +156,10 @@ static spinlock_t pmu_lock;
 static u8 pmu_intr_mask;
 static int pmu_version;
 static int drop_interrupts;
-#ifdef CONFIG_PM
+#if defined(CONFIG_PM) && defined(CONFIG_PPC32)
 static int option_lid_wakeup = 1;
 static int sleep_in_progress;
-#endif /* CONFIG_PM */
+#endif /* CONFIG_PM && CONFIG_PPC32 */
 static unsigned long async_req_locks;
 static unsigned int pmu_irq_stats[11];
 
@@ -295,22 +296,26 @@ static struct backlight_controller pmu_backlight_controller = {
 };
 #endif /* CONFIG_PMAC_BACKLIGHT */
 
-int
-find_via_pmu(void)
+int __init find_via_pmu(void)
 {
+       phys_addr_t taddr;
+       u32 *reg;
+
        if (via != 0)
                return 1;
-       vias = find_devices("via-pmu");
-       if (vias == 0)
+       vias = of_find_node_by_name(NULL, "via-pmu");
+       if (vias == NULL)
                return 0;
-       if (vias->next != 0)
-               printk(KERN_WARNING "Warning: only using 1st via-pmu\n");
 
-       if (vias->n_addrs < 1 || vias->n_intrs < 1) {
-               printk(KERN_ERR "via-pmu: %d addresses, %d interrupts!\n",
-                      vias->n_addrs, vias->n_intrs);
-               if (vias->n_addrs < 1 || vias->n_intrs < 1)
-                       return 0;
+       reg = (u32 *)get_property(vias, "reg", NULL);
+       if (reg == NULL) {
+               printk(KERN_ERR "via-pmu: No \"reg\" property !\n");
+               goto fail;
+       }
+       taddr = of_translate_address(vias, reg);
+       if (taddr == OF_BAD_ADDR) {
+               printk(KERN_ERR "via-pmu: Can't translate address !\n");
+               goto fail;
        }
 
        spin_lock_init(&pmu_lock);
@@ -331,7 +336,8 @@ find_via_pmu(void)
                pmu_kind = PMU_HEATHROW_BASED;
        else if (device_is_compatible(vias->parent, "Keylargo")
                 || device_is_compatible(vias->parent, "K2-Keylargo")) {
-               struct device_node *gpio, *gpiop;
+               struct device_node *gpiop;
+               phys_addr_t gaddr = 0;
 
                pmu_kind = PMU_KEYLARGO_BASED;
                pmu_has_adb = (find_type_devices("adb") != NULL);
@@ -341,19 +347,24 @@ find_via_pmu(void)
                                PMU_INT_TICK |
                                PMU_INT_ENVIRONMENT;
                
-               gpiop = find_devices("gpio");
-               if (gpiop && gpiop->n_addrs) {
-                       gpio_reg = ioremap(gpiop->addrs->address, 0x10);
-                       gpio = find_devices("extint-gpio1");
-                       if (gpio == NULL)
-                               gpio = find_devices("pmu-interrupt");
-                       if (gpio && gpio->parent == gpiop && gpio->n_intrs)
-                               gpio_irq = gpio->intrs[0].line;
+               gpiop = of_find_node_by_name(NULL, "gpio");
+               if (gpiop) {
+                       reg = (u32 *)get_property(gpiop, "reg", NULL);
+                       if (reg)
+                               gaddr = of_translate_address(gpiop, reg);
+                       if (gaddr != 0)
+                               gpio_reg = ioremap(gaddr, 0x10);
                }
+               if (gpio_reg == NULL)
+                       printk(KERN_ERR "via-pmu: Can't find GPIO reg !\n");
        } else
                pmu_kind = PMU_UNKNOWN;
 
-       via = ioremap(vias->addrs->address, 0x2000);
+       via = ioremap(taddr, 0x2000);
+       if (via == NULL) {
+               printk(KERN_ERR "via-pmu: Can't map address !\n");
+               goto fail;
+       }
        
        out_8(&via[IER], IER_CLR | 0x7f);       /* disable all intrs */
        out_8(&via[IFR], 0x7f);                 /* clear IFR */
@@ -365,23 +376,25 @@ find_via_pmu(void)
                return 0;
        }
 
-       printk(KERN_INFO "PMU driver %d initialized for %s, firmware: %02x\n",
+       printk(KERN_INFO "PMU driver v%d initialized for %s, firmware: %02x\n",
               PMU_DRIVER_VERSION, pbook_type[pmu_kind], pmu_version);
               
        sys_ctrler = SYS_CTRLER_PMU;
        
        return 1;
+ fail:
+       of_node_put(vias);
+       vias = NULL;
+       return 0;
 }
 
 #ifdef CONFIG_ADB
-static int
-pmu_probe(void)
+static int pmu_probe(void)
 {
        return vias == NULL? -ENODEV: 0;
 }
 
-static int __init
-pmu_init(void)
+static int __init pmu_init(void)
 {
        if (vias == NULL)
                return -ENODEV;
@@ -405,7 +418,7 @@ static int __init via_pmu_start(void)
        bright_req_2.complete = 1;
        batt_req.complete = 1;
 
-#if defined(CONFIG_PPC32) && !defined(CONFIG_PPC_MERGE)
+#ifndef CONFIG_PPC_MERGE
        if (pmu_kind == PMU_KEYLARGO_BASED)
                openpic_set_irq_priority(vias->intrs[0].line,
                                         OPENPIC_PRIORITY_DEFAULT + 1);
@@ -418,10 +431,22 @@ static int __init via_pmu_start(void)
                return -EAGAIN;
        }
 
-       if (pmu_kind == PMU_KEYLARGO_BASED && gpio_irq != -1) {
-               if (request_irq(gpio_irq, gpio1_interrupt, 0, "GPIO1 ADB", (void *)0))
-                       printk(KERN_ERR "pmu: can't get irq %d (GPIO1)\n", gpio_irq);
-               gpio_irq_enabled = 1;
+       if (pmu_kind == PMU_KEYLARGO_BASED) {
+               gpio_node = of_find_node_by_name(NULL, "extint-gpio1");
+               if (gpio_node == NULL)
+                       gpio_node = of_find_node_by_name(NULL,
+                                                        "pmu-interrupt");
+               if (gpio_node && gpio_node->n_intrs > 0)
+                       gpio_irq = gpio_node->intrs[0].line;
+
+               if (gpio_irq != -1) {
+                       if (request_irq(gpio_irq, gpio1_interrupt, 0,
+                                       "GPIO1 ADB", (void *)0))
+                               printk(KERN_ERR "pmu: can't get irq %d"
+                                      " (GPIO1)\n", gpio_irq);
+                       else
+                               gpio_irq_enabled = 1;
+               }
        }
 
        /* Enable interrupts */
@@ -865,7 +890,7 @@ proc_read_options(char *page, char **start, off_t off,
 {
        char *p = page;
 
-#ifdef CONFIG_PM
+#if defined(CONFIG_PM) && defined(CONFIG_PPC32)
        if (pmu_kind == PMU_KEYLARGO_BASED &&
            pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0)
                p += sprintf(p, "lid_wakeup=%d\n", option_lid_wakeup);
@@ -906,7 +931,7 @@ proc_write_options(struct file *file, const char __user *buffer,
        *(val++) = 0;
        while(*val == ' ')
                val++;
-#ifdef CONFIG_PM
+#if defined(CONFIG_PM) && defined(CONFIG_PPC32)
        if (pmu_kind == PMU_KEYLARGO_BASED &&
            pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0)
                if (!strcmp(label, "lid_wakeup"))
@@ -1371,7 +1396,6 @@ next:
                        }
                        pmu_done(req);
                } else {
-#if defined(CONFIG_XMON) && !defined(CONFIG_PPC64)
                        if (len == 4 && data[1] == 0x2c) {
                                extern int xmon_wants_key, xmon_adb_keycode;
                                if (xmon_wants_key) {
@@ -1379,7 +1403,6 @@ next:
                                        return;
                                }
                        }
-#endif /* defined(CONFIG_XMON) && !defined(CONFIG_PPC64) */
 #ifdef CONFIG_ADB
                        /*
                         * XXX On the [23]400 the PMU gives us an up
@@ -2053,6 +2076,7 @@ pmu_register_sleep_notifier(struct pmu_sleep_notifier *n)
        __list_add(&n->list, list->prev, list);
        return 0;
 }
+EXPORT_SYMBOL(pmu_register_sleep_notifier);
 
 int
 pmu_unregister_sleep_notifier(struct pmu_sleep_notifier* n)
@@ -2063,6 +2087,10 @@ pmu_unregister_sleep_notifier(struct pmu_sleep_notifier* n)
        n->list.next = NULL;
        return 0;
 }
+EXPORT_SYMBOL(pmu_unregister_sleep_notifier);
+#endif /* CONFIG_PM */
+
+#if defined(CONFIG_PM) && defined(CONFIG_PPC32)
 
 /* Sleep is broadcast last-to-first */
 static int
@@ -2664,10 +2692,10 @@ powerbook_sleep_3400(void)
        asleep = 1;
 
        /* Put the CPU into sleep mode */
-       asm volatile("mfspr %0,1008" : "=r" (hid0) :);
+       hid0 = mfspr(SPRN_HID0);
        hid0 = (hid0 & ~(HID0_NAP | HID0_DOZE)) | HID0_SLEEP;
-       asm volatile("mtspr 1008,%0" : : "r" (hid0));
-       _nmask_and_or_msr(0, MSR_POW | MSR_EE);
+       mtspr(SPRN_HID0, hid0);
+       mtmsr(mfmsr() | MSR_POW | MSR_EE);
        udelay(10);
 
        /* OK, we're awake again, start restoring things */
@@ -2687,7 +2715,7 @@ powerbook_sleep_3400(void)
        return 0;
 }
 
-#endif /* CONFIG_PM */
+#endif /* CONFIG_PM && CONFIG_PPC32 */
 
 /*
  * Support for /dev/pmu device
@@ -2871,7 +2899,7 @@ pmu_ioctl(struct inode * inode, struct file *filp,
        int error = -EINVAL;
 
        switch (cmd) {
-#ifdef CONFIG_PM
+#if defined(CONFIG_PM) && defined(CONFIG_PPC32)
        case PMU_IOC_SLEEP:
                if (!capable(CAP_SYS_ADMIN))
                        return -EACCES;
@@ -2899,7 +2927,7 @@ pmu_ioctl(struct inode * inode, struct file *filp,
                        return put_user(0, argp);
                else
                        return put_user(1, argp);
-#endif /* CONFIG_PM */
+#endif /* CONFIG_PM && CONFIG_PPC32 */
 
 #ifdef CONFIG_PMAC_BACKLIGHT
        /* Backlight should have its own device or go via
@@ -3047,7 +3075,7 @@ pmu_polled_request(struct adb_request *req)
  * to do suspend-to-disk.
  */
 
-#ifdef CONFIG_PM
+#if defined(CONFIG_PM) && defined(CONFIG_PPC32)
 
 static int pmu_sys_suspended = 0;
 
@@ -3082,7 +3110,7 @@ static int pmu_sys_resume(struct sys_device *sysdev)
        return 0;
 }
 
-#endif /* CONFIG_PM */
+#endif /* CONFIG_PM && CONFIG_PPC32 */
 
 static struct sysdev_class pmu_sysclass = {
        set_kset_name("pmu"),
@@ -3094,10 +3122,10 @@ static struct sys_device device_pmu = {
 };
 
 static struct sysdev_driver driver_pmu = {
-#ifdef CONFIG_PM
+#if defined(CONFIG_PM) && defined(CONFIG_PPC32)
        .suspend        = &pmu_sys_suspend,
        .resume         = &pmu_sys_resume,
-#endif /* CONFIG_PM */
+#endif /* CONFIG_PM && CONFIG_PPC32 */
 };
 
 static int __init init_pmu_sysfs(void)
@@ -3135,12 +3163,10 @@ EXPORT_SYMBOL(pmu_i2c_combined_read);
 EXPORT_SYMBOL(pmu_i2c_stdsub_write);
 EXPORT_SYMBOL(pmu_i2c_simple_read);
 EXPORT_SYMBOL(pmu_i2c_simple_write);
-#ifdef CONFIG_PM
-EXPORT_SYMBOL(pmu_register_sleep_notifier);
-EXPORT_SYMBOL(pmu_unregister_sleep_notifier);
+#if defined(CONFIG_PM) && defined(CONFIG_PPC32)
 EXPORT_SYMBOL(pmu_enable_irled);
 EXPORT_SYMBOL(pmu_battery_count);
 EXPORT_SYMBOL(pmu_batteries);
 EXPORT_SYMBOL(pmu_power_flags);
-#endif /* CONFIG_PM */
+#endif /* CONFIG_PM && CONFIG_PPC32 */