rfkill: preserve state across suspend
[safe/jmp/linux-2.6] / net / rfkill / rfkill.c
index e348eab..5ad411d 100644 (file)
@@ -565,10 +565,15 @@ static void rfkill_release(struct device *dev)
 #ifdef CONFIG_PM
 static int rfkill_suspend(struct device *dev, pm_message_t state)
 {
+       struct rfkill *rfkill = to_rfkill(dev);
+
        /* mark class device as suspended */
        if (dev->power.power_state.event != state.event)
                dev->power.power_state = state;
 
+       /* store state for the resume handler */
+       rfkill->state_for_resume = rfkill->state;
+
        return 0;
 }
 
@@ -581,8 +586,17 @@ static int rfkill_resume(struct device *dev)
 
                dev->power.power_state.event = PM_EVENT_ON;
 
-               /* restore radio state AND notify everybody */
-               rfkill_toggle_radio(rfkill, rfkill->state, 1);
+               /*
+                * If we are under EPO, kick transmitter offline,
+                * otherwise restore to pre-suspend state.
+                *
+                * Issue a notification in any case
+                */
+               rfkill_toggle_radio(rfkill,
+                               rfkill_epo_lock_active ?
+                                       RFKILL_STATE_SOFT_BLOCKED :
+                                       rfkill->state_for_resume,
+                               1);
 
                mutex_unlock(&rfkill->mutex);
        }
@@ -657,7 +671,7 @@ static int rfkill_check_duplicity(const struct rfkill *rfkill)
        }
 
        /* 0: first switch of its kind */
-       return test_bit(rfkill->type, seen);
+       return (test_bit(rfkill->type, seen)) ? 1 : 0;
 }
 
 static int rfkill_add_switch(struct rfkill *rfkill)
@@ -765,7 +779,7 @@ static void rfkill_led_trigger_register(struct rfkill *rfkill)
        int error;
 
        if (!rfkill->led_trigger.name)
-               rfkill->led_trigger.name = rfkill->dev.bus_id;
+               rfkill->led_trigger.name = dev_name(&rfkill->dev);
        if (!rfkill->led_trigger.activate)
                rfkill->led_trigger.activate = rfkill_led_trigger_activate;
        error = led_trigger_register(&rfkill->led_trigger);
@@ -806,8 +820,7 @@ int __must_check rfkill_register(struct rfkill *rfkill)
                        "badly initialized rfkill struct\n"))
                return -EINVAL;
 
-       snprintf(dev->bus_id, sizeof(dev->bus_id),
-                "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1);
+       dev_set_name(dev, "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1);
 
        rfkill_led_trigger_register(rfkill);