Lines Matching full:rfkill
15 #include <linux/rfkill.h>
25 #include "rfkill.h"
37 struct rfkill { struct
69 #define to_rfkill(d) container_of(d, struct rfkill, dev) argument
95 * the rfkill struct under their own lock, and take this lock during
96 * rfkill method calls -- which will cause an AB-BA deadlock situation.
105 static LIST_HEAD(rfkill_fds); /* list of open fds of /dev/rfkill */
120 static void rfkill_led_trigger_event(struct rfkill *rfkill) in rfkill_led_trigger_event() argument
124 if (!rfkill->registered) in rfkill_led_trigger_event()
127 trigger = &rfkill->led_trigger; in rfkill_led_trigger_event()
129 if (rfkill->state & RFKILL_BLOCK_ANY) in rfkill_led_trigger_event()
137 struct rfkill *rfkill; in rfkill_led_trigger_activate() local
139 rfkill = container_of(led->trigger, struct rfkill, led_trigger); in rfkill_led_trigger_activate()
141 rfkill_led_trigger_event(rfkill); in rfkill_led_trigger_activate()
146 const char *rfkill_get_led_trigger_name(struct rfkill *rfkill) in rfkill_get_led_trigger_name() argument
148 return rfkill->led_trigger.name; in rfkill_get_led_trigger_name()
152 void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name) in rfkill_set_led_trigger_name() argument
154 BUG_ON(!rfkill); in rfkill_set_led_trigger_name()
156 rfkill->ledtrigname = name; in rfkill_set_led_trigger_name()
160 static int rfkill_led_trigger_register(struct rfkill *rfkill) in rfkill_led_trigger_register() argument
162 rfkill->led_trigger.name = rfkill->ledtrigname in rfkill_led_trigger_register()
163 ? : dev_name(&rfkill->dev); in rfkill_led_trigger_register()
164 rfkill->led_trigger.activate = rfkill_led_trigger_activate; in rfkill_led_trigger_register()
165 return led_trigger_register(&rfkill->led_trigger); in rfkill_led_trigger_register()
168 static void rfkill_led_trigger_unregister(struct rfkill *rfkill) in rfkill_led_trigger_unregister() argument
170 led_trigger_unregister(&rfkill->led_trigger); in rfkill_led_trigger_unregister()
180 struct rfkill *rfkill; in rfkill_global_led_trigger_worker() local
183 list_for_each_entry(rfkill, &rfkill_list, node) { in rfkill_global_led_trigger_worker()
184 if (!(rfkill->state & RFKILL_BLOCK_ANY)) { in rfkill_global_led_trigger_worker()
208 rfkill_any_led_trigger.name = "rfkill-any"; in rfkill_global_led_trigger_register()
213 rfkill_none_led_trigger.name = "rfkill-none"; in rfkill_global_led_trigger_register()
231 static void rfkill_led_trigger_event(struct rfkill *rfkill) in rfkill_led_trigger_event() argument
235 static inline int rfkill_led_trigger_register(struct rfkill *rfkill) in rfkill_led_trigger_register() argument
240 static inline void rfkill_led_trigger_unregister(struct rfkill *rfkill) in rfkill_led_trigger_unregister() argument
259 struct rfkill *rfkill, in rfkill_fill_event() argument
264 ev->idx = rfkill->idx; in rfkill_fill_event()
265 ev->type = rfkill->type; in rfkill_fill_event()
268 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_fill_event()
269 ev->hard = !!(rfkill->state & RFKILL_BLOCK_HW); in rfkill_fill_event()
270 ev->soft = !!(rfkill->state & (RFKILL_BLOCK_SW | in rfkill_fill_event()
272 ev->hard_block_reasons = rfkill->hard_block_reasons; in rfkill_fill_event()
273 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_fill_event()
276 static void rfkill_send_events(struct rfkill *rfkill, enum rfkill_operation op) in rfkill_send_events() argument
285 rfkill_fill_event(&ev->ev, rfkill, op); in rfkill_send_events()
293 static void rfkill_event(struct rfkill *rfkill) in rfkill_event() argument
295 if (!rfkill->registered) in rfkill_event()
298 kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE); in rfkill_event()
300 /* also send event to /dev/rfkill */ in rfkill_event()
301 rfkill_send_events(rfkill, RFKILL_OP_CHANGE); in rfkill_event()
307 * @rfkill: the rfkill struct to use
313 static void rfkill_set_block(struct rfkill *rfkill, bool blocked) in rfkill_set_block() argument
319 if (unlikely(rfkill->dev.power.power_state.event & PM_EVENT_SLEEP)) in rfkill_set_block()
327 if (rfkill->ops->query) in rfkill_set_block()
328 rfkill->ops->query(rfkill, rfkill->data); in rfkill_set_block()
330 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_set_block()
331 prev = rfkill->state & RFKILL_BLOCK_SW; in rfkill_set_block()
334 rfkill->state |= RFKILL_BLOCK_SW_PREV; in rfkill_set_block()
336 rfkill->state &= ~RFKILL_BLOCK_SW_PREV; in rfkill_set_block()
339 rfkill->state |= RFKILL_BLOCK_SW; in rfkill_set_block()
341 rfkill->state &= ~RFKILL_BLOCK_SW; in rfkill_set_block()
343 rfkill->state |= RFKILL_BLOCK_SW_SETCALL; in rfkill_set_block()
344 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_set_block()
346 err = rfkill->ops->set_block(rfkill->data, blocked); in rfkill_set_block()
348 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_set_block()
355 if (rfkill->state & RFKILL_BLOCK_SW_PREV) in rfkill_set_block()
356 rfkill->state |= RFKILL_BLOCK_SW; in rfkill_set_block()
358 rfkill->state &= ~RFKILL_BLOCK_SW; in rfkill_set_block()
360 rfkill->state &= ~RFKILL_BLOCK_SW_SETCALL; in rfkill_set_block()
361 rfkill->state &= ~RFKILL_BLOCK_SW_PREV; in rfkill_set_block()
362 curr = rfkill->state & RFKILL_BLOCK_SW; in rfkill_set_block()
363 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_set_block()
365 rfkill_led_trigger_event(rfkill); in rfkill_set_block()
369 rfkill_event(rfkill); in rfkill_set_block()
372 static void rfkill_sync(struct rfkill *rfkill) in rfkill_sync() argument
376 if (!rfkill->need_sync) in rfkill_sync()
379 rfkill_set_block(rfkill, rfkill_global_states[rfkill->type].cur); in rfkill_sync()
380 rfkill->need_sync = false; in rfkill_sync()
411 struct rfkill *rfkill; in __rfkill_switch_all() local
414 list_for_each_entry(rfkill, &rfkill_list, node) { in __rfkill_switch_all()
415 if (rfkill->type != type && type != RFKILL_TYPE_ALL) in __rfkill_switch_all()
418 rfkill_set_block(rfkill, blocked); in __rfkill_switch_all()
448 * This kicks all non-suspended rfkill devices to RFKILL_STATE_SOFT_BLOCKED,
449 * ignoring everything in its path but rfkill_global_mutex and rfkill->mutex.
456 struct rfkill *rfkill; in rfkill_epo() local
465 list_for_each_entry(rfkill, &rfkill_list, node) in rfkill_epo()
466 rfkill_set_block(rfkill, true); in rfkill_epo()
501 * Used by rfkill-input manually unlock state changes, when
541 bool rfkill_set_hw_state_reason(struct rfkill *rfkill, in rfkill_set_hw_state_reason() argument
548 BUG_ON(!rfkill); in rfkill_set_hw_state_reason()
550 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_set_hw_state_reason()
551 prev = !!(rfkill->hard_block_reasons & reason); in rfkill_set_hw_state_reason()
553 rfkill->state |= RFKILL_BLOCK_HW; in rfkill_set_hw_state_reason()
554 rfkill->hard_block_reasons |= reason; in rfkill_set_hw_state_reason()
556 rfkill->hard_block_reasons &= ~reason; in rfkill_set_hw_state_reason()
557 if (!rfkill->hard_block_reasons) in rfkill_set_hw_state_reason()
558 rfkill->state &= ~RFKILL_BLOCK_HW; in rfkill_set_hw_state_reason()
560 ret = !!(rfkill->state & RFKILL_BLOCK_ANY); in rfkill_set_hw_state_reason()
561 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_set_hw_state_reason()
563 rfkill_led_trigger_event(rfkill); in rfkill_set_hw_state_reason()
566 if (rfkill->registered && prev != blocked) in rfkill_set_hw_state_reason()
567 schedule_work(&rfkill->uevent_work); in rfkill_set_hw_state_reason()
573 static void __rfkill_set_sw_state(struct rfkill *rfkill, bool blocked) in __rfkill_set_sw_state() argument
578 if (rfkill->state & RFKILL_BLOCK_SW_SETCALL) in __rfkill_set_sw_state()
582 rfkill->state |= bit; in __rfkill_set_sw_state()
584 rfkill->state &= ~bit; in __rfkill_set_sw_state()
587 bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked) in rfkill_set_sw_state() argument
592 BUG_ON(!rfkill); in rfkill_set_sw_state()
594 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_set_sw_state()
595 prev = !!(rfkill->state & RFKILL_BLOCK_SW); in rfkill_set_sw_state()
596 __rfkill_set_sw_state(rfkill, blocked); in rfkill_set_sw_state()
597 hwblock = !!(rfkill->state & RFKILL_BLOCK_HW); in rfkill_set_sw_state()
599 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_set_sw_state()
601 if (!rfkill->registered) in rfkill_set_sw_state()
605 schedule_work(&rfkill->uevent_work); in rfkill_set_sw_state()
607 rfkill_led_trigger_event(rfkill); in rfkill_set_sw_state()
614 void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked) in rfkill_init_sw_state() argument
618 BUG_ON(!rfkill); in rfkill_init_sw_state()
619 BUG_ON(rfkill->registered); in rfkill_init_sw_state()
621 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_init_sw_state()
622 __rfkill_set_sw_state(rfkill, blocked); in rfkill_init_sw_state()
623 rfkill->persistent = true; in rfkill_init_sw_state()
624 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_init_sw_state()
628 void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw) in rfkill_set_states() argument
633 BUG_ON(!rfkill); in rfkill_set_states()
635 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_set_states()
641 swprev = !!(rfkill->state & RFKILL_BLOCK_SW); in rfkill_set_states()
642 hwprev = !!(rfkill->state & RFKILL_BLOCK_HW); in rfkill_set_states()
643 __rfkill_set_sw_state(rfkill, sw); in rfkill_set_states()
645 rfkill->state |= RFKILL_BLOCK_HW; in rfkill_set_states()
647 rfkill->state &= ~RFKILL_BLOCK_HW; in rfkill_set_states()
649 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_set_states()
651 if (!rfkill->registered) { in rfkill_set_states()
652 rfkill->persistent = true; in rfkill_set_states()
655 schedule_work(&rfkill->uevent_work); in rfkill_set_states()
657 rfkill_led_trigger_event(rfkill); in rfkill_set_states()
694 struct rfkill *rfkill = to_rfkill(dev); in name_show() local
696 return sysfs_emit(buf, "%s\n", rfkill->name); in name_show()
703 struct rfkill *rfkill = to_rfkill(dev); in type_show() local
705 return sysfs_emit(buf, "%s\n", rfkill_types[rfkill->type]); in type_show()
712 struct rfkill *rfkill = to_rfkill(dev); in index_show() local
714 return sysfs_emit(buf, "%d\n", rfkill->idx); in index_show()
721 struct rfkill *rfkill = to_rfkill(dev); in persistent_show() local
723 return sysfs_emit(buf, "%d\n", rfkill->persistent); in persistent_show()
730 struct rfkill *rfkill = to_rfkill(dev); in hard_show() local
732 return sysfs_emit(buf, "%d\n", (rfkill->state & RFKILL_BLOCK_HW) ? 1 : 0); in hard_show()
739 struct rfkill *rfkill = to_rfkill(dev); in soft_show() local
742 rfkill_sync(rfkill); in soft_show()
745 return sysfs_emit(buf, "%d\n", (rfkill->state & RFKILL_BLOCK_SW) ? 1 : 0); in soft_show()
751 struct rfkill *rfkill = to_rfkill(dev); in soft_store() local
766 rfkill_sync(rfkill); in soft_store()
767 rfkill_set_block(rfkill, state); in soft_store()
778 struct rfkill *rfkill = to_rfkill(dev); in hard_block_reasons_show() local
780 return sysfs_emit(buf, "0x%lx\n", rfkill->hard_block_reasons); in hard_block_reasons_show()
797 struct rfkill *rfkill = to_rfkill(dev); in state_show() local
800 rfkill_sync(rfkill); in state_show()
803 return sysfs_emit(buf, "%d\n", user_state_from_blocked(rfkill->state)); in state_show()
809 struct rfkill *rfkill = to_rfkill(dev); in state_store() local
825 rfkill_sync(rfkill); in state_store()
826 rfkill_set_block(rfkill, state == RFKILL_USER_STATE_SOFT_BLOCKED); in state_store()
848 struct rfkill *rfkill = to_rfkill(dev); in rfkill_release() local
850 kfree(rfkill); in rfkill_release()
855 struct rfkill *rfkill = to_rfkill(dev); in rfkill_dev_uevent() local
861 error = add_uevent_var(env, "RFKILL_NAME=%s", rfkill->name); in rfkill_dev_uevent()
865 rfkill_types[rfkill->type]); in rfkill_dev_uevent()
868 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_dev_uevent()
869 state = rfkill->state; in rfkill_dev_uevent()
870 reasons = rfkill->hard_block_reasons; in rfkill_dev_uevent()
871 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_dev_uevent()
879 void rfkill_pause_polling(struct rfkill *rfkill) in rfkill_pause_polling() argument
881 BUG_ON(!rfkill); in rfkill_pause_polling()
883 if (!rfkill->ops->poll) in rfkill_pause_polling()
886 rfkill->polling_paused = true; in rfkill_pause_polling()
887 cancel_delayed_work_sync(&rfkill->poll_work); in rfkill_pause_polling()
891 void rfkill_resume_polling(struct rfkill *rfkill) in rfkill_resume_polling() argument
893 BUG_ON(!rfkill); in rfkill_resume_polling()
895 if (!rfkill->ops->poll) in rfkill_resume_polling()
898 rfkill->polling_paused = false; in rfkill_resume_polling()
900 if (rfkill->suspended) in rfkill_resume_polling()
904 &rfkill->poll_work, 0); in rfkill_resume_polling()
911 struct rfkill *rfkill = to_rfkill(dev); in rfkill_suspend() local
913 rfkill->suspended = true; in rfkill_suspend()
914 cancel_delayed_work_sync(&rfkill->poll_work); in rfkill_suspend()
921 struct rfkill *rfkill = to_rfkill(dev); in rfkill_resume() local
924 rfkill->suspended = false; in rfkill_resume()
926 if (!rfkill->registered) in rfkill_resume()
929 if (!rfkill->persistent) { in rfkill_resume()
930 cur = !!(rfkill->state & RFKILL_BLOCK_SW); in rfkill_resume()
931 rfkill_set_block(rfkill, cur); in rfkill_resume()
934 if (rfkill->ops->poll && !rfkill->polling_paused) in rfkill_resume()
936 &rfkill->poll_work, 0); in rfkill_resume()
948 .name = "rfkill",
955 bool rfkill_blocked(struct rfkill *rfkill) in rfkill_blocked() argument
960 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_blocked()
961 state = rfkill->state; in rfkill_blocked()
962 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_blocked()
968 bool rfkill_soft_blocked(struct rfkill *rfkill) in rfkill_soft_blocked() argument
973 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_soft_blocked()
974 state = rfkill->state; in rfkill_soft_blocked()
975 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_soft_blocked()
981 struct rfkill * __must_check rfkill_alloc(const char *name, in rfkill_alloc()
987 struct rfkill *rfkill; in rfkill_alloc() local
1002 rfkill = kzalloc(sizeof(*rfkill) + strlen(name) + 1, GFP_KERNEL); in rfkill_alloc()
1003 if (!rfkill) in rfkill_alloc()
1006 spin_lock_init(&rfkill->lock); in rfkill_alloc()
1007 INIT_LIST_HEAD(&rfkill->node); in rfkill_alloc()
1008 rfkill->type = type; in rfkill_alloc()
1009 strcpy(rfkill->name, name); in rfkill_alloc()
1010 rfkill->ops = ops; in rfkill_alloc()
1011 rfkill->data = ops_data; in rfkill_alloc()
1013 dev = &rfkill->dev; in rfkill_alloc()
1018 return rfkill; in rfkill_alloc()
1024 struct rfkill *rfkill; in rfkill_poll() local
1026 rfkill = container_of(work, struct rfkill, poll_work.work); in rfkill_poll()
1033 rfkill->ops->poll(rfkill, rfkill->data); in rfkill_poll()
1036 &rfkill->poll_work, in rfkill_poll()
1042 struct rfkill *rfkill; in rfkill_uevent_work() local
1044 rfkill = container_of(work, struct rfkill, uevent_work); in rfkill_uevent_work()
1047 rfkill_event(rfkill); in rfkill_uevent_work()
1053 struct rfkill *rfkill = container_of(work, struct rfkill, sync_work); in rfkill_sync_work() local
1056 rfkill_sync(rfkill); in rfkill_sync_work()
1060 int __must_check rfkill_register(struct rfkill *rfkill) in rfkill_register() argument
1066 if (!rfkill) in rfkill_register()
1069 dev = &rfkill->dev; in rfkill_register()
1073 if (rfkill->registered) { in rfkill_register()
1078 rfkill->idx = rfkill_no; in rfkill_register()
1079 dev_set_name(dev, "rfkill%lu", rfkill_no); in rfkill_register()
1082 list_add_tail(&rfkill->node, &rfkill_list); in rfkill_register()
1088 error = rfkill_led_trigger_register(rfkill); in rfkill_register()
1092 rfkill->registered = true; in rfkill_register()
1094 INIT_DELAYED_WORK(&rfkill->poll_work, rfkill_poll); in rfkill_register()
1095 INIT_WORK(&rfkill->uevent_work, rfkill_uevent_work); in rfkill_register()
1096 INIT_WORK(&rfkill->sync_work, rfkill_sync_work); in rfkill_register()
1098 if (rfkill->ops->poll) in rfkill_register()
1100 &rfkill->poll_work, in rfkill_register()
1103 if (!rfkill->persistent || rfkill_epo_lock_active) { in rfkill_register()
1104 rfkill->need_sync = true; in rfkill_register()
1105 schedule_work(&rfkill->sync_work); in rfkill_register()
1108 bool soft_blocked = !!(rfkill->state & RFKILL_BLOCK_SW); in rfkill_register()
1111 __rfkill_switch_all(rfkill->type, soft_blocked); in rfkill_register()
1116 rfkill_send_events(rfkill, RFKILL_OP_ADD); in rfkill_register()
1122 device_del(&rfkill->dev); in rfkill_register()
1124 list_del_init(&rfkill->node); in rfkill_register()
1131 void rfkill_unregister(struct rfkill *rfkill) in rfkill_unregister() argument
1133 BUG_ON(!rfkill); in rfkill_unregister()
1135 if (rfkill->ops->poll) in rfkill_unregister()
1136 cancel_delayed_work_sync(&rfkill->poll_work); in rfkill_unregister()
1138 cancel_work_sync(&rfkill->uevent_work); in rfkill_unregister()
1139 cancel_work_sync(&rfkill->sync_work); in rfkill_unregister()
1141 rfkill->registered = false; in rfkill_unregister()
1143 device_del(&rfkill->dev); in rfkill_unregister()
1146 rfkill_send_events(rfkill, RFKILL_OP_DEL); in rfkill_unregister()
1147 list_del_init(&rfkill->node); in rfkill_unregister()
1151 rfkill_led_trigger_unregister(rfkill); in rfkill_unregister()
1155 void rfkill_destroy(struct rfkill *rfkill) in rfkill_destroy() argument
1157 if (rfkill) in rfkill_destroy()
1158 put_device(&rfkill->dev); in rfkill_destroy()
1165 struct rfkill *rfkill; in rfkill_fop_open() local
1184 list_for_each_entry(rfkill, &rfkill_list, node) { in rfkill_fop_open()
1188 rfkill_sync(rfkill); in rfkill_fop_open()
1189 rfkill_fill_event(&ev->ev, rfkill, RFKILL_OP_ADD); in rfkill_fop_open()
1272 struct rfkill *rfkill; in rfkill_fop_write() local
1298 list_for_each_entry(rfkill, &rfkill_list, node) in rfkill_fop_write()
1299 if (rfkill->type == ev.type || in rfkill_fop_write()
1301 rfkill_set_block(rfkill, ev.soft); in rfkill_fop_write()
1305 list_for_each_entry(rfkill, &rfkill_list, node) in rfkill_fop_write()
1306 if (rfkill->idx == ev.idx && in rfkill_fop_write()
1307 (rfkill->type == ev.type || in rfkill_fop_write()
1309 rfkill_set_block(rfkill, ev.soft); in rfkill_fop_write()
1338 printk(KERN_DEBUG "rfkill: input handler enabled\n"); in rfkill_fop_release()
1362 printk(KERN_DEBUG "rfkill: input handler disabled\n"); in rfkill_fop_ioctl()
1399 #define RFKILL_NAME "rfkill"