]> err.no Git - linux-2.6/blobdiff - drivers/macintosh/via-pmu.c
[NETFILTER]: nf_conntrack: EXPORT_SYMBOL cleanup
[linux-2.6] / drivers / macintosh / via-pmu.c
index 06ca80bfd6b98442dfce7c532d33a6d8a9e4ced0..e63ea1c1f3c1de9833ac155d8e3e7587d5ff8693 100644 (file)
@@ -16,7 +16,6 @@
  *    a sleep or a freq. switch
  *  - Move sleep code out of here to pmac_pm, merge into new
  *    common PM infrastructure
- *  - Move backlight code out as well
  *  - Save/Restore PCI space properly
  *
  */
@@ -60,9 +59,7 @@
 #include <asm/mmu_context.h>
 #include <asm/cputable.h>
 #include <asm/time.h>
-#ifdef CONFIG_PMAC_BACKLIGHT
 #include <asm/backlight.h>
-#endif
 
 #include "via-pmu-event.h"
 
@@ -177,10 +174,6 @@ static int query_batt_timer = BATTERY_POLLING_COUNT;
 static struct adb_request batt_req;
 static struct proc_dir_entry *proc_pmu_batt[PMU_MAX_BATTERIES];
 
-#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
-extern int disable_kernel_backlight;
-#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */
-
 int __fake_sleep;
 int asleep;
 BLOCKING_NOTIFIER_HEAD(sleep_notifier_list);
@@ -198,8 +191,8 @@ static int pmu_adb_reset_bus(void);
 
 static int init_pmu(void);
 static void pmu_start(void);
-static irqreturn_t via_pmu_interrupt(int irq, void *arg, struct pt_regs *regs);
-static irqreturn_t gpio1_interrupt(int irq, void *arg, struct pt_regs *regs);
+static irqreturn_t via_pmu_interrupt(int irq, void *arg);
+static irqreturn_t gpio1_interrupt(int irq, void *arg);
 static int proc_get_info(char *page, char **start, off_t off,
                          int count, int *eof, void *data);
 static int proc_get_irqstats(char *page, char **start, off_t off,
@@ -287,7 +280,7 @@ static char *pbook_type[] = {
 int __init find_via_pmu(void)
 {
        u64 taddr;
-       u32 *reg;
+       const u32 *reg;
 
        if (via != 0)
                return 1;
@@ -295,7 +288,7 @@ int __init find_via_pmu(void)
        if (vias == NULL)
                return 0;
 
-       reg = (u32 *)get_property(vias, "reg", NULL);
+       reg = get_property(vias, "reg", NULL);
        if (reg == NULL) {
                printk(KERN_ERR "via-pmu: No \"reg\" property !\n");
                goto fail;
@@ -337,14 +330,16 @@ int __init find_via_pmu(void)
                
                gpiop = of_find_node_by_name(NULL, "gpio");
                if (gpiop) {
-                       reg = (u32 *)get_property(gpiop, "reg", NULL);
+                       reg = get_property(gpiop, "reg", NULL);
                        if (reg)
                                gaddr = of_translate_address(gpiop, reg);
                        if (gaddr != OF_BAD_ADDR)
                                gpio_reg = ioremap(gaddr, 0x10);
                }
-               if (gpio_reg == NULL)
+               if (gpio_reg == NULL) {
                        printk(KERN_ERR "via-pmu: Can't find GPIO reg !\n");
+                       goto fail_gpio;
+               }
        } else
                pmu_kind = PMU_UNKNOWN;
 
@@ -372,6 +367,9 @@ int __init find_via_pmu(void)
        return 1;
  fail:
        of_node_put(vias);
+       iounmap(gpio_reg);
+       gpio_reg = NULL;
+ fail_gpio:
        vias = NULL;
        return 0;
 }
@@ -466,7 +464,7 @@ static int __init via_pmu_dev_init(void)
 
 #ifdef CONFIG_PMAC_BACKLIGHT
        /* Initialize backlight */
-       pmu_backlight_init(vias);
+       pmu_backlight_init();
 #endif
 
 #ifdef CONFIG_PPC32
@@ -486,9 +484,9 @@ static int __init via_pmu_dev_init(void)
                pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART;
        } else {
                struct device_node* prim = find_devices("power-mgt");
-               u32 *prim_info = NULL;
+               const u32 *prim_info = NULL;
                if (prim)
-                       prim_info = (u32 *)get_property(prim, "prim-info", NULL);
+                       prim_info = get_property(prim, "prim-info", NULL);
                if (prim_info) {
                        /* Other stuffs here yet unknown */
                        pmu_battery_count = (prim_info[6] >> 16) & 0xff;
@@ -557,7 +555,7 @@ init_pmu(void)
                }
                if (pmu_state == idle)
                        adb_int_pending = 1;
-               via_pmu_interrupt(0, NULL, NULL);
+               via_pmu_interrupt(0, NULL);
                udelay(10);
        }
 
@@ -1217,7 +1215,7 @@ pmu_poll(void)
                return;
        if (disable_poll)
                return;
-       via_pmu_interrupt(0, NULL, NULL);
+       via_pmu_interrupt(0, NULL);
 }
 
 void
@@ -1230,7 +1228,7 @@ pmu_poll_adb(void)
        /* Kicks ADB read when PMU is suspended */
        adb_int_pending = 1;
        do {
-               via_pmu_interrupt(0, NULL, NULL);
+               via_pmu_interrupt(0, NULL);
        } while (pmu_suspended && (adb_int_pending || pmu_state != idle
                || req_awaiting_reply));
 }
@@ -1241,7 +1239,7 @@ pmu_wait_complete(struct adb_request *req)
        if (!via)
                return;
        while((pmu_state != idle && pmu_state != locked) || !req->complete)
-               via_pmu_interrupt(0, NULL, NULL);
+               via_pmu_interrupt(0, NULL);
 }
 
 /* This function loops until the PMU is idle and prevents it from
@@ -1270,7 +1268,7 @@ pmu_suspend(void)
                spin_unlock_irqrestore(&pmu_lock, flags);
                if (req_awaiting_reply)
                        adb_int_pending = 1;
-               via_pmu_interrupt(0, NULL, NULL);
+               via_pmu_interrupt(0, NULL);
                spin_lock_irqsave(&pmu_lock, flags);
                if (!adb_int_pending && pmu_state == idle && !req_awaiting_reply) {
 #ifdef SUSPEND_USES_PMU
@@ -1320,7 +1318,7 @@ pmu_resume(void)
 
 /* Interrupt data could be the result data from an ADB cmd */
 static void
-pmu_handle_data(unsigned char *data, int len, struct pt_regs *regs)
+pmu_handle_data(unsigned char *data, int len)
 {
        unsigned char ints, pirq;
        int i = 0;
@@ -1395,7 +1393,7 @@ next:
                        if (!(pmu_kind == PMU_OHARE_BASED && len == 4
                              && data[1] == 0x2c && data[3] == 0xff
                              && (data[2] & ~1) == 0xf4))
-                               adb_input(data+1, len-1, regs, 1);
+                               adb_input(data+1, len-1, 1);
 #endif /* CONFIG_ADB */                
                }
        }
@@ -1403,11 +1401,8 @@ next:
        else if ((1 << pirq) & PMU_INT_SNDBRT) {
 #ifdef CONFIG_PMAC_BACKLIGHT
                if (len == 3)
-#ifdef CONFIG_INPUT_ADBHID
-                       if (!disable_kernel_backlight)
-#endif /* CONFIG_INPUT_ADBHID */
-                               pmac_backlight_set_legacy_brightness(data[1] >> 4);
-#endif /* CONFIG_PMAC_BACKLIGHT */
+                       pmac_backlight_set_legacy_brightness_pmu(data[1] >> 4);
+#endif
        }
        /* Tick interrupt */
        else if ((1 << pirq) & PMU_INT_TICK) {
@@ -1436,7 +1431,7 @@ next:
 }
 
 static struct adb_request*
-pmu_sr_intr(struct pt_regs *regs)
+pmu_sr_intr(void)
 {
        struct adb_request *req;
        int bite = 0;
@@ -1542,7 +1537,7 @@ pmu_sr_intr(struct pt_regs *regs)
 }
 
 static irqreturn_t
-via_pmu_interrupt(int irq, void *arg, struct pt_regs *regs)
+via_pmu_interrupt(int irq, void *arg)
 {
        unsigned long flags;
        int intr;
@@ -1572,7 +1567,7 @@ via_pmu_interrupt(int irq, void *arg, struct pt_regs *regs)
                        pmu_irq_stats[0]++;
                }
                if (intr & SR_INT) {
-                       req = pmu_sr_intr(regs);
+                       req = pmu_sr_intr();
                        if (req)
                                break;
                }
@@ -1618,7 +1613,7 @@ no_free_slot:
                
        /* Deal with interrupt datas outside of the lock */
        if (int_data >= 0) {
-               pmu_handle_data(interrupt_data[int_data], interrupt_data_len[int_data], regs);
+               pmu_handle_data(interrupt_data[int_data], interrupt_data_len[int_data]);
                spin_lock_irqsave(&pmu_lock, flags);
                ++disable_poll;
                int_data_state[int_data] = int_data_empty;
@@ -1643,7 +1638,7 @@ pmu_unlock(void)
 
 
 static irqreturn_t
-gpio1_interrupt(int irq, void *arg, struct pt_regs *regs)
+gpio1_interrupt(int irq, void *arg)
 {
        unsigned long flags;
 
@@ -1656,7 +1651,7 @@ gpio1_interrupt(int irq, void *arg, struct pt_regs *regs)
                pmu_irq_stats[1]++;
                adb_int_pending = 1;
                spin_unlock_irqrestore(&pmu_lock, flags);
-               via_pmu_interrupt(0, NULL, NULL);
+               via_pmu_interrupt(0, NULL);
                return IRQ_HANDLED;
        }
        return IRQ_NONE;
@@ -1837,7 +1832,7 @@ pbook_alloc_pci_save(void)
        struct pci_dev *pd = NULL;
 
        npci = 0;
-       while ((pd = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) {
+       while ((pd = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) {
                ++npci;
        }
        if (npci == 0)
@@ -1867,9 +1862,11 @@ pbook_pci_save(void)
        if (ps == NULL)
                return;
 
-       while ((pd = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) {
-               if (npci-- == 0)
+       while ((pd = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) {
+               if (npci-- == 0) {
+                       pci_dev_put(pd);
                        return;
+               }
 #ifndef HACKED_PCI_SAVE
                pci_read_config_word(pd, PCI_COMMAND, &ps->command);
                pci_read_config_word(pd, PCI_CACHE_LINE_SIZE, &ps->cache_lat);
@@ -1897,11 +1894,13 @@ pbook_pci_restore(void)
        int npci = pbook_npci_saves;
        int j;
 
-       while ((pd = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) {
+       while ((pd = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) {
 #ifdef HACKED_PCI_SAVE
                int i;
-               if (npci-- == 0)
+               if (npci-- == 0) {
+                       pci_dev_put(pd);
                        return;
+               }
                ps++;
                for (i=2;i<16;i++)
                        pci_write_config_dword(pd, i<<4, ps->config[i]);
@@ -2005,6 +2004,8 @@ restore_via_state(void)
        out_8(&via[IER], IER_SET | SR_INT | CB1_INT);
 }
 
+extern void pmu_backlight_set_sleep(int sleep);
+
 static int
 pmac_suspend_devices(void)
 {
@@ -2042,6 +2043,11 @@ pmac_suspend_devices(void)
                return -EBUSY;
        }
 
+#ifdef CONFIG_PMAC_BACKLIGHT
+       /* Tell backlight code not to muck around with the chip anymore */
+       pmu_backlight_set_sleep(1);
+#endif
+
        /* Call platform functions marked "on sleep" */
        pmac_pfunc_i2c_suspend();
        pmac_pfunc_base_suspend();
@@ -2100,12 +2106,17 @@ pmac_wakeup_devices(void)
 {
        mdelay(100);
 
+#ifdef CONFIG_PMAC_BACKLIGHT
+       /* Tell backlight code it can use the chip again */
+       pmu_backlight_set_sleep(0);
+#endif
+
        /* Power back up system devices (including the PIC) */
        device_power_up();
 
        /* Force a poll of ADB interrupts */
        adb_int_pending = 1;
-       via_pmu_interrupt(0, NULL, NULL);
+       via_pmu_interrupt(0, NULL);
 
        /* Restart jiffies & scheduling */
        wakeup_decrementer();
@@ -2414,7 +2425,7 @@ struct pmu_private {
        spinlock_t lock;
 #if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
        int     backlight_locker;
-#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */    
+#endif
 };
 
 static LIST_HEAD(all_pmu_pvt);
@@ -2464,7 +2475,7 @@ pmu_open(struct inode *inode, struct file *file)
        spin_lock_irqsave(&all_pvt_lock, flags);
 #if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
        pp->backlight_locker = 0;
-#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */    
+#endif
        list_add(&pp->list, &all_pmu_pvt);
        spin_unlock_irqrestore(&all_pvt_lock, flags);
        file->private_data = pp;
@@ -2559,13 +2570,12 @@ pmu_release(struct inode *inode, struct file *file)
                spin_lock_irqsave(&all_pvt_lock, flags);
                list_del(&pp->list);
                spin_unlock_irqrestore(&all_pvt_lock, flags);
+
 #if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
-               if (pp->backlight_locker) {
-                       spin_lock_irqsave(&pmu_lock, flags);
-                       disable_kernel_backlight--;
-                       spin_unlock_irqrestore(&pmu_lock, flags);
-               }
-#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */
+               if (pp->backlight_locker)
+                       pmac_backlight_enable();
+#endif
+
                kfree(pp);
        }
        unlock_kernel();
@@ -2642,18 +2652,18 @@ pmu_ioctl(struct inode * inode, struct file *filp,
 #ifdef CONFIG_INPUT_ADBHID
        case PMU_IOC_GRAB_BACKLIGHT: {
                struct pmu_private *pp = filp->private_data;
-               unsigned long flags;
 
                if (pp->backlight_locker)
                        return 0;
+
                pp->backlight_locker = 1;
-               spin_lock_irqsave(&pmu_lock, flags);
-               disable_kernel_backlight++;
-               spin_unlock_irqrestore(&pmu_lock, flags);
+               pmac_backlight_disable();
+
                return 0;
        }
 #endif /* CONFIG_INPUT_ADBHID */
 #endif /* CONFIG_PMAC_BACKLIGHT_LEGACY */
+
        case PMU_IOC_GET_MODEL:
                return put_user(pmu_kind, argp);
        case PMU_IOC_HAS_ADB: