Lines Matching +full:led +full:- +full:cur

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2006 - 2007 Ivo van Doorn
95 * rfkill method calls -- which will cause an AB-BA deadlock situation.
97 * To fix that, we need to rework this code here to be mostly lock-free
112 bool cur, sav; member
123 if (!rfkill->registered) in rfkill_led_trigger_event()
126 trigger = &rfkill->led_trigger; in rfkill_led_trigger_event()
128 if (rfkill->state & RFKILL_BLOCK_ANY) in rfkill_led_trigger_event()
134 static int rfkill_led_trigger_activate(struct led_classdev *led) in rfkill_led_trigger_activate() argument
138 rfkill = container_of(led->trigger, struct rfkill, led_trigger); in rfkill_led_trigger_activate()
147 return rfkill->led_trigger.name; in rfkill_get_led_trigger_name()
155 rfkill->ledtrigname = name; in rfkill_set_led_trigger_name()
161 rfkill->led_trigger.name = rfkill->ledtrigname in rfkill_led_trigger_register()
162 ? : dev_name(&rfkill->dev); in rfkill_led_trigger_register()
163 rfkill->led_trigger.activate = rfkill_led_trigger_activate; in rfkill_led_trigger_register()
164 return led_trigger_register(&rfkill->led_trigger); in rfkill_led_trigger_register()
169 led_trigger_unregister(&rfkill->led_trigger); in rfkill_led_trigger_unregister()
183 if (!(rfkill->state & RFKILL_BLOCK_ANY)) { in rfkill_global_led_trigger_worker()
207 rfkill_any_led_trigger.name = "rfkill-any"; in rfkill_global_led_trigger_register()
212 rfkill_none_led_trigger.name = "rfkill-none"; in rfkill_global_led_trigger_register()
263 ev->idx = rfkill->idx; in rfkill_fill_event()
264 ev->type = rfkill->type; in rfkill_fill_event()
265 ev->op = op; in rfkill_fill_event()
267 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_fill_event()
268 ev->hard = !!(rfkill->state & RFKILL_BLOCK_HW); in rfkill_fill_event()
269 ev->soft = !!(rfkill->state & (RFKILL_BLOCK_SW | in rfkill_fill_event()
271 ev->hard_block_reasons = rfkill->hard_block_reasons; in rfkill_fill_event()
272 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_fill_event()
284 rfkill_fill_event(&ev->ev, rfkill, op); in rfkill_send_events()
285 mutex_lock(&data->mtx); in rfkill_send_events()
286 list_add_tail(&ev->list, &data->events); in rfkill_send_events()
287 mutex_unlock(&data->mtx); in rfkill_send_events()
288 wake_up_interruptible(&data->read_wait); in rfkill_send_events()
294 if (!rfkill->registered) in rfkill_event()
297 kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE); in rfkill_event()
304 * rfkill_set_block - wrapper for set_block method
318 if (unlikely(rfkill->dev.power.power_state.event & PM_EVENT_SLEEP)) in rfkill_set_block()
323 * _hard_ kill state -- whenever something tries to change the in rfkill_set_block()
326 if (rfkill->ops->query) in rfkill_set_block()
327 rfkill->ops->query(rfkill, rfkill->data); in rfkill_set_block()
329 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_set_block()
330 prev = rfkill->state & RFKILL_BLOCK_SW; in rfkill_set_block()
333 rfkill->state |= RFKILL_BLOCK_SW_PREV; in rfkill_set_block()
335 rfkill->state &= ~RFKILL_BLOCK_SW_PREV; in rfkill_set_block()
338 rfkill->state |= RFKILL_BLOCK_SW; in rfkill_set_block()
340 rfkill->state &= ~RFKILL_BLOCK_SW; in rfkill_set_block()
342 rfkill->state |= RFKILL_BLOCK_SW_SETCALL; in rfkill_set_block()
343 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_set_block()
345 err = rfkill->ops->set_block(rfkill->data, blocked); in rfkill_set_block()
347 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_set_block()
350 * Failed -- reset status to _PREV, which may be different in rfkill_set_block()
354 if (rfkill->state & RFKILL_BLOCK_SW_PREV) in rfkill_set_block()
355 rfkill->state |= RFKILL_BLOCK_SW; in rfkill_set_block()
357 rfkill->state &= ~RFKILL_BLOCK_SW; in rfkill_set_block()
359 rfkill->state &= ~RFKILL_BLOCK_SW_SETCALL; in rfkill_set_block()
360 rfkill->state &= ~RFKILL_BLOCK_SW_PREV; in rfkill_set_block()
361 curr = rfkill->state & RFKILL_BLOCK_SW; in rfkill_set_block()
362 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_set_block()
376 rfkill_global_states[type].cur = blocked; in rfkill_update_global_state()
381 rfkill_global_states[i].cur = blocked; in rfkill_update_global_state()
388 * __rfkill_switch_all - Toggle state of all switches of given type
403 if (rfkill->type != type && type != RFKILL_TYPE_ALL) in __rfkill_switch_all()
411 * rfkill_switch_all - Toggle state of all switches of given type
434 * rfkill_epo - emergency power off all transmitters
436 * This kicks all non-suspended rfkill devices to RFKILL_STATE_SOFT_BLOCKED,
437 * ignoring everything in its path but rfkill_global_mutex and rfkill->mutex.
457 rfkill_global_states[i].sav = rfkill_global_states[i].cur; in rfkill_epo()
458 rfkill_global_states[i].cur = true; in rfkill_epo()
465 * rfkill_restore_states - restore global states
487 * rfkill_remove_epo_lock - unlock state changes
489 * Used by rfkill-input manually unlock state changes, when
503 * rfkill_is_epo_lock_active - returns true EPO is active
517 * rfkill_get_global_sw_state - returns global state for a type
525 return rfkill_global_states[type].cur; in rfkill_get_global_sw_state()
542 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_set_hw_state_reason()
543 prev = !!(rfkill->hard_block_reasons & reason); in rfkill_set_hw_state_reason()
545 rfkill->state |= RFKILL_BLOCK_HW; in rfkill_set_hw_state_reason()
546 rfkill->hard_block_reasons |= reason; in rfkill_set_hw_state_reason()
548 rfkill->hard_block_reasons &= ~reason; in rfkill_set_hw_state_reason()
549 if (!rfkill->hard_block_reasons) in rfkill_set_hw_state_reason()
550 rfkill->state &= ~RFKILL_BLOCK_HW; in rfkill_set_hw_state_reason()
552 ret = !!(rfkill->state & RFKILL_BLOCK_ANY); in rfkill_set_hw_state_reason()
553 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_set_hw_state_reason()
558 if (rfkill->registered && prev != blocked) in rfkill_set_hw_state_reason()
559 schedule_work(&rfkill->uevent_work); in rfkill_set_hw_state_reason()
569 /* if in a ops->set_block right now, use other bit */ in __rfkill_set_sw_state()
570 if (rfkill->state & RFKILL_BLOCK_SW_SETCALL) in __rfkill_set_sw_state()
574 rfkill->state |= bit; in __rfkill_set_sw_state()
576 rfkill->state &= ~bit; in __rfkill_set_sw_state()
586 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_set_sw_state()
587 prev = !!(rfkill->state & RFKILL_BLOCK_SW); in rfkill_set_sw_state()
589 hwblock = !!(rfkill->state & RFKILL_BLOCK_HW); in rfkill_set_sw_state()
591 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_set_sw_state()
593 if (!rfkill->registered) in rfkill_set_sw_state()
597 schedule_work(&rfkill->uevent_work); in rfkill_set_sw_state()
611 BUG_ON(rfkill->registered); in rfkill_init_sw_state()
613 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_init_sw_state()
615 rfkill->persistent = true; in rfkill_init_sw_state()
616 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_init_sw_state()
627 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_set_states()
633 swprev = !!(rfkill->state & RFKILL_BLOCK_SW); in rfkill_set_states()
634 hwprev = !!(rfkill->state & RFKILL_BLOCK_HW); in rfkill_set_states()
637 rfkill->state |= RFKILL_BLOCK_HW; in rfkill_set_states()
639 rfkill->state &= ~RFKILL_BLOCK_HW; in rfkill_set_states()
641 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_set_states()
643 if (!rfkill->registered) { in rfkill_set_states()
644 rfkill->persistent = true; in rfkill_set_states()
647 schedule_work(&rfkill->uevent_work); in rfkill_set_states()
688 return sprintf(buf, "%s\n", rfkill->name); in name_show()
697 return sprintf(buf, "%s\n", rfkill_types[rfkill->type]); in type_show()
706 return sprintf(buf, "%d\n", rfkill->idx); in index_show()
715 return sprintf(buf, "%d\n", rfkill->persistent); in persistent_show()
724 return sprintf(buf, "%d\n", (rfkill->state & RFKILL_BLOCK_HW) ? 1 : 0 ); in hard_show()
733 return sprintf(buf, "%d\n", (rfkill->state & RFKILL_BLOCK_SW) ? 1 : 0 ); in soft_show()
744 return -EPERM; in soft_store()
751 return -EINVAL; in soft_store()
767 return sprintf(buf, "0x%lx\n", rfkill->hard_block_reasons); in hard_block_reasons_show()
786 return sprintf(buf, "%d\n", user_state_from_blocked(rfkill->state)); in state_show()
797 return -EPERM; in state_store()
805 return -EINVAL; in state_store()
843 error = add_uevent_var(env, "RFKILL_NAME=%s", rfkill->name); in rfkill_dev_uevent()
847 rfkill_types[rfkill->type]); in rfkill_dev_uevent()
850 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_dev_uevent()
851 state = rfkill->state; in rfkill_dev_uevent()
852 reasons = rfkill->hard_block_reasons; in rfkill_dev_uevent()
853 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_dev_uevent()
865 if (!rfkill->ops->poll) in rfkill_pause_polling()
868 rfkill->polling_paused = true; in rfkill_pause_polling()
869 cancel_delayed_work_sync(&rfkill->poll_work); in rfkill_pause_polling()
877 if (!rfkill->ops->poll) in rfkill_resume_polling()
880 rfkill->polling_paused = false; in rfkill_resume_polling()
882 if (rfkill->suspended) in rfkill_resume_polling()
886 &rfkill->poll_work, 0); in rfkill_resume_polling()
895 rfkill->suspended = true; in rfkill_suspend()
896 cancel_delayed_work_sync(&rfkill->poll_work); in rfkill_suspend()
904 bool cur; in rfkill_resume() local
906 rfkill->suspended = false; in rfkill_resume()
908 if (!rfkill->registered) in rfkill_resume()
911 if (!rfkill->persistent) { in rfkill_resume()
912 cur = !!(rfkill->state & RFKILL_BLOCK_SW); in rfkill_resume()
913 rfkill_set_block(rfkill, cur); in rfkill_resume()
916 if (rfkill->ops->poll && !rfkill->polling_paused) in rfkill_resume()
918 &rfkill->poll_work, 0); in rfkill_resume()
942 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_blocked()
943 state = rfkill->state; in rfkill_blocked()
944 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_blocked()
955 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_soft_blocked()
956 state = rfkill->state; in rfkill_soft_blocked()
957 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_soft_blocked()
975 if (WARN_ON(!ops->set_block)) in rfkill_alloc()
988 spin_lock_init(&rfkill->lock); in rfkill_alloc()
989 INIT_LIST_HEAD(&rfkill->node); in rfkill_alloc()
990 rfkill->type = type; in rfkill_alloc()
991 strcpy(rfkill->name, name); in rfkill_alloc()
992 rfkill->ops = ops; in rfkill_alloc()
993 rfkill->data = ops_data; in rfkill_alloc()
995 dev = &rfkill->dev; in rfkill_alloc()
996 dev->class = &rfkill_class; in rfkill_alloc()
997 dev->parent = parent; in rfkill_alloc()
1011 * Poll hardware state -- driver will use one of the in rfkill_poll()
1015 rfkill->ops->poll(rfkill, rfkill->data); in rfkill_poll()
1018 &rfkill->poll_work, in rfkill_poll()
1036 bool cur; in rfkill_sync_work() local
1041 cur = rfkill_global_states[rfkill->type].cur; in rfkill_sync_work()
1042 rfkill_set_block(rfkill, cur); in rfkill_sync_work()
1053 return -EINVAL; in rfkill_register()
1055 dev = &rfkill->dev; in rfkill_register()
1059 if (rfkill->registered) { in rfkill_register()
1060 error = -EALREADY; in rfkill_register()
1064 rfkill->idx = rfkill_no; in rfkill_register()
1068 list_add_tail(&rfkill->node, &rfkill_list); in rfkill_register()
1078 rfkill->registered = true; in rfkill_register()
1080 INIT_DELAYED_WORK(&rfkill->poll_work, rfkill_poll); in rfkill_register()
1081 INIT_WORK(&rfkill->uevent_work, rfkill_uevent_work); in rfkill_register()
1082 INIT_WORK(&rfkill->sync_work, rfkill_sync_work); in rfkill_register()
1084 if (rfkill->ops->poll) in rfkill_register()
1086 &rfkill->poll_work, in rfkill_register()
1089 if (!rfkill->persistent || rfkill_epo_lock_active) { in rfkill_register()
1090 schedule_work(&rfkill->sync_work); in rfkill_register()
1093 bool soft_blocked = !!(rfkill->state & RFKILL_BLOCK_SW); in rfkill_register()
1096 __rfkill_switch_all(rfkill->type, soft_blocked); in rfkill_register()
1107 device_del(&rfkill->dev); in rfkill_register()
1109 list_del_init(&rfkill->node); in rfkill_register()
1120 if (rfkill->ops->poll) in rfkill_unregister()
1121 cancel_delayed_work_sync(&rfkill->poll_work); in rfkill_unregister()
1123 cancel_work_sync(&rfkill->uevent_work); in rfkill_unregister()
1124 cancel_work_sync(&rfkill->sync_work); in rfkill_unregister()
1126 rfkill->registered = false; in rfkill_unregister()
1128 device_del(&rfkill->dev); in rfkill_unregister()
1132 list_del_init(&rfkill->node); in rfkill_unregister()
1143 put_device(&rfkill->dev); in rfkill_destroy()
1155 return -ENOMEM; in rfkill_fop_open()
1157 data->max_size = RFKILL_EVENT_SIZE_V1; in rfkill_fop_open()
1159 INIT_LIST_HEAD(&data->events); in rfkill_fop_open()
1160 mutex_init(&data->mtx); in rfkill_fop_open()
1161 init_waitqueue_head(&data->read_wait); in rfkill_fop_open()
1164 mutex_lock(&data->mtx); in rfkill_fop_open()
1174 rfkill_fill_event(&ev->ev, rfkill, RFKILL_OP_ADD); in rfkill_fop_open()
1175 list_add_tail(&ev->list, &data->events); in rfkill_fop_open()
1177 list_add(&data->list, &rfkill_fds); in rfkill_fop_open()
1178 mutex_unlock(&data->mtx); in rfkill_fop_open()
1181 file->private_data = data; in rfkill_fop_open()
1186 mutex_unlock(&data->mtx); in rfkill_fop_open()
1188 mutex_destroy(&data->mtx); in rfkill_fop_open()
1189 list_for_each_entry_safe(ev, tmp, &data->events, list) in rfkill_fop_open()
1192 return -ENOMEM; in rfkill_fop_open()
1197 struct rfkill_data *data = file->private_data; in rfkill_fop_poll()
1200 poll_wait(file, &data->read_wait, wait); in rfkill_fop_poll()
1202 mutex_lock(&data->mtx); in rfkill_fop_poll()
1203 if (!list_empty(&data->events)) in rfkill_fop_poll()
1205 mutex_unlock(&data->mtx); in rfkill_fop_poll()
1213 struct rfkill_data *data = file->private_data; in rfkill_fop_read()
1218 mutex_lock(&data->mtx); in rfkill_fop_read()
1220 while (list_empty(&data->events)) { in rfkill_fop_read()
1221 if (file->f_flags & O_NONBLOCK) { in rfkill_fop_read()
1222 ret = -EAGAIN; in rfkill_fop_read()
1225 mutex_unlock(&data->mtx); in rfkill_fop_read()
1226 /* since we re-check and it just compares pointers, in rfkill_fop_read()
1229 ret = wait_event_interruptible(data->read_wait, in rfkill_fop_read()
1230 !list_empty(&data->events)); in rfkill_fop_read()
1231 mutex_lock(&data->mtx); in rfkill_fop_read()
1237 ev = list_first_entry(&data->events, struct rfkill_int_event, in rfkill_fop_read()
1240 sz = min_t(unsigned long, sizeof(ev->ev), count); in rfkill_fop_read()
1241 sz = min_t(unsigned long, sz, data->max_size); in rfkill_fop_read()
1243 if (copy_to_user(buf, &ev->ev, sz)) in rfkill_fop_read()
1244 ret = -EFAULT; in rfkill_fop_read()
1246 list_del(&ev->list); in rfkill_fop_read()
1249 mutex_unlock(&data->mtx); in rfkill_fop_read()
1256 struct rfkill_data *data = file->private_data; in rfkill_fop_write()
1262 if (count < RFKILL_EVENT_SIZE_V1 - 1) in rfkill_fop_write()
1263 return -EINVAL; in rfkill_fop_write()
1271 count = min_t(size_t, count, data->max_size); in rfkill_fop_write()
1273 return -EFAULT; in rfkill_fop_write()
1276 return -EINVAL; in rfkill_fop_write()
1284 if (rfkill->type == ev.type || in rfkill_fop_write()
1291 if (rfkill->idx == ev.idx && in rfkill_fop_write()
1292 (rfkill->type == ev.type || in rfkill_fop_write()
1298 ret = -EINVAL; in rfkill_fop_write()
1309 struct rfkill_data *data = file->private_data; in rfkill_fop_release()
1313 list_del(&data->list); in rfkill_fop_release()
1316 mutex_destroy(&data->mtx); in rfkill_fop_release()
1317 list_for_each_entry_safe(ev, tmp, &data->events, list) in rfkill_fop_release()
1321 if (data->input_handler) in rfkill_fop_release()
1334 struct rfkill_data *data = file->private_data; in rfkill_fop_ioctl()
1335 int ret = -ENOSYS; in rfkill_fop_ioctl()
1339 return -ENOSYS; in rfkill_fop_ioctl()
1341 mutex_lock(&data->mtx); in rfkill_fop_ioctl()
1345 if (!data->input_handler) { in rfkill_fop_ioctl()
1348 data->input_handler = true; in rfkill_fop_ioctl()
1355 ret = -EFAULT; in rfkill_fop_ioctl()
1359 ret = -EINVAL; in rfkill_fop_ioctl()
1362 data->max_size = size; in rfkill_fop_ioctl()
1368 mutex_unlock(&data->mtx); in rfkill_fop_ioctl()