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

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2006 - 2007 Ivo van Doorn
96 * rfkill method calls -- which will cause an AB-BA deadlock situation.
98 * To fix that, we need to rework this code here to be mostly lock-free
113 bool cur, sav; member
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()
135 static int rfkill_led_trigger_activate(struct led_classdev *led) in rfkill_led_trigger_activate() argument
139 rfkill = container_of(led->trigger, struct rfkill, led_trigger); in rfkill_led_trigger_activate()
148 return rfkill->led_trigger.name; in rfkill_get_led_trigger_name()
156 rfkill->ledtrigname = name; in rfkill_set_led_trigger_name()
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()
170 led_trigger_unregister(&rfkill->led_trigger); in rfkill_led_trigger_unregister()
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()
264 ev->idx = rfkill->idx; in rfkill_fill_event()
265 ev->type = rfkill->type; in rfkill_fill_event()
266 ev->op = op; 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()
285 rfkill_fill_event(&ev->ev, rfkill, op); in rfkill_send_events()
286 mutex_lock(&data->mtx); in rfkill_send_events()
287 list_add_tail(&ev->list, &data->events); in rfkill_send_events()
288 mutex_unlock(&data->mtx); in rfkill_send_events()
289 wake_up_interruptible(&data->read_wait); in rfkill_send_events()
295 if (!rfkill->registered) in rfkill_event()
298 kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE); in rfkill_event()
305 * rfkill_set_block - wrapper for set_block method
319 if (unlikely(rfkill->dev.power.power_state.event & PM_EVENT_SLEEP)) in rfkill_set_block()
324 * _hard_ kill state -- whenever something tries to change the 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()
351 * Failed -- reset status to _PREV, which may be different 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()
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()
388 rfkill_global_states[type].cur = blocked; in rfkill_update_global_state()
393 rfkill_global_states[i].cur = blocked; in rfkill_update_global_state()
400 * __rfkill_switch_all - Toggle state of all switches of given type
415 if (rfkill->type != type && type != RFKILL_TYPE_ALL) in __rfkill_switch_all()
423 * rfkill_switch_all - Toggle state of all switches of given type
446 * rfkill_epo - emergency power off all transmitters
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.
469 rfkill_global_states[i].sav = rfkill_global_states[i].cur; in rfkill_epo()
470 rfkill_global_states[i].cur = true; in rfkill_epo()
477 * rfkill_restore_states - restore global states
499 * rfkill_remove_epo_lock - unlock state changes
501 * Used by rfkill-input manually unlock state changes, when
515 * rfkill_is_epo_lock_active - returns true EPO is active
529 * rfkill_get_global_sw_state - returns global state for a type
537 return rfkill_global_states[type].cur; in rfkill_get_global_sw_state()
554 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_set_hw_state_reason()
555 prev = !!(rfkill->hard_block_reasons & reason); in rfkill_set_hw_state_reason()
557 rfkill->state |= RFKILL_BLOCK_HW; in rfkill_set_hw_state_reason()
558 rfkill->hard_block_reasons |= reason; in rfkill_set_hw_state_reason()
560 rfkill->hard_block_reasons &= ~reason; in rfkill_set_hw_state_reason()
561 if (!rfkill->hard_block_reasons) in rfkill_set_hw_state_reason()
562 rfkill->state &= ~RFKILL_BLOCK_HW; in rfkill_set_hw_state_reason()
564 ret = !!(rfkill->state & RFKILL_BLOCK_ANY); in rfkill_set_hw_state_reason()
565 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_set_hw_state_reason()
570 if (rfkill->registered && prev != blocked) in rfkill_set_hw_state_reason()
571 schedule_work(&rfkill->uevent_work); in rfkill_set_hw_state_reason()
581 /* if in a ops->set_block right now, use other bit */ in __rfkill_set_sw_state()
582 if (rfkill->state & RFKILL_BLOCK_SW_SETCALL) in __rfkill_set_sw_state()
586 rfkill->state |= bit; in __rfkill_set_sw_state()
588 rfkill->state &= ~bit; in __rfkill_set_sw_state()
598 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_set_sw_state()
599 prev = !!(rfkill->state & RFKILL_BLOCK_SW); in rfkill_set_sw_state()
601 hwblock = !!(rfkill->state & RFKILL_BLOCK_HW); in rfkill_set_sw_state()
603 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_set_sw_state()
605 if (!rfkill->registered) in rfkill_set_sw_state()
609 schedule_work(&rfkill->uevent_work); in rfkill_set_sw_state()
623 BUG_ON(rfkill->registered); in rfkill_init_sw_state()
625 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_init_sw_state()
627 rfkill->persistent = true; in rfkill_init_sw_state()
628 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_init_sw_state()
639 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_set_states()
645 swprev = !!(rfkill->state & RFKILL_BLOCK_SW); in rfkill_set_states()
646 hwprev = !!(rfkill->state & RFKILL_BLOCK_HW); in rfkill_set_states()
649 rfkill->state |= RFKILL_BLOCK_HW; in rfkill_set_states()
651 rfkill->state &= ~RFKILL_BLOCK_HW; in rfkill_set_states()
653 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_set_states()
655 if (!rfkill->registered) { in rfkill_set_states()
656 rfkill->persistent = true; in rfkill_set_states()
659 schedule_work(&rfkill->uevent_work); in rfkill_set_states()
700 return sysfs_emit(buf, "%s\n", rfkill->name); in name_show()
709 return sysfs_emit(buf, "%s\n", rfkill_types[rfkill->type]); in type_show()
718 return sysfs_emit(buf, "%d\n", rfkill->idx); in index_show()
727 return sysfs_emit(buf, "%d\n", rfkill->persistent); in persistent_show()
736 return sysfs_emit(buf, "%d\n", (rfkill->state & RFKILL_BLOCK_HW) ? 1 : 0); in hard_show()
749 return sysfs_emit(buf, "%d\n", (rfkill->state & RFKILL_BLOCK_SW) ? 1 : 0); in soft_show()
760 return -EPERM; in soft_store()
767 return -EINVAL; in soft_store()
784 return sysfs_emit(buf, "0x%lx\n", rfkill->hard_block_reasons); in hard_block_reasons_show()
807 return sysfs_emit(buf, "%d\n", user_state_from_blocked(rfkill->state)); in state_show()
818 return -EPERM; in state_store()
826 return -EINVAL; in state_store()
865 error = add_uevent_var(env, "RFKILL_NAME=%s", rfkill->name); in rfkill_dev_uevent()
869 rfkill_types[rfkill->type]); in rfkill_dev_uevent()
872 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_dev_uevent()
873 state = rfkill->state; in rfkill_dev_uevent()
874 reasons = rfkill->hard_block_reasons; in rfkill_dev_uevent()
875 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_dev_uevent()
887 if (!rfkill->ops->poll) in rfkill_pause_polling()
890 rfkill->polling_paused = true; in rfkill_pause_polling()
891 cancel_delayed_work_sync(&rfkill->poll_work); in rfkill_pause_polling()
899 if (!rfkill->ops->poll) in rfkill_resume_polling()
902 rfkill->polling_paused = false; in rfkill_resume_polling()
904 if (rfkill->suspended) in rfkill_resume_polling()
908 &rfkill->poll_work, 0); in rfkill_resume_polling()
917 rfkill->suspended = true; in rfkill_suspend()
918 cancel_delayed_work_sync(&rfkill->poll_work); in rfkill_suspend()
926 bool cur; in rfkill_resume() local
928 rfkill->suspended = false; in rfkill_resume()
930 if (!rfkill->registered) in rfkill_resume()
933 if (!rfkill->persistent) { in rfkill_resume()
934 cur = !!(rfkill->state & RFKILL_BLOCK_SW); in rfkill_resume()
935 rfkill_set_block(rfkill, cur); in rfkill_resume()
938 if (rfkill->ops->poll && !rfkill->polling_paused) in rfkill_resume()
940 &rfkill->poll_work, 0); in rfkill_resume()
964 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_blocked()
965 state = rfkill->state; in rfkill_blocked()
966 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_blocked()
977 spin_lock_irqsave(&rfkill->lock, flags); in rfkill_soft_blocked()
978 state = rfkill->state; in rfkill_soft_blocked()
979 spin_unlock_irqrestore(&rfkill->lock, flags); in rfkill_soft_blocked()
997 if (WARN_ON(!ops->set_block)) in rfkill_alloc()
1010 spin_lock_init(&rfkill->lock); in rfkill_alloc()
1011 INIT_LIST_HEAD(&rfkill->node); in rfkill_alloc()
1012 rfkill->type = type; in rfkill_alloc()
1013 strcpy(rfkill->name, name); in rfkill_alloc()
1014 rfkill->ops = ops; in rfkill_alloc()
1015 rfkill->data = ops_data; in rfkill_alloc()
1017 dev = &rfkill->dev; in rfkill_alloc()
1018 dev->class = &rfkill_class; in rfkill_alloc()
1019 dev->parent = parent; in rfkill_alloc()
1033 * Poll hardware state -- driver will use one of the in rfkill_poll()
1037 rfkill->ops->poll(rfkill, rfkill->data); in rfkill_poll()
1040 &rfkill->poll_work, in rfkill_poll()
1071 return -EINVAL; in rfkill_register()
1073 dev = &rfkill->dev; in rfkill_register()
1077 if (rfkill->registered) { in rfkill_register()
1078 error = -EALREADY; in rfkill_register()
1082 rfkill->idx = rfkill_no; in rfkill_register()
1086 list_add_tail(&rfkill->node, &rfkill_list); in rfkill_register()
1096 rfkill->registered = true; in rfkill_register()
1098 INIT_DELAYED_WORK(&rfkill->poll_work, rfkill_poll); in rfkill_register()
1099 INIT_WORK(&rfkill->uevent_work, rfkill_uevent_work); in rfkill_register()
1100 INIT_WORK(&rfkill->sync_work, rfkill_sync_work); in rfkill_register()
1102 if (rfkill->ops->poll) in rfkill_register()
1104 &rfkill->poll_work, in rfkill_register()
1107 if (!rfkill->persistent || rfkill_epo_lock_active) { in rfkill_register()
1108 rfkill->need_sync = true; in rfkill_register()
1109 schedule_work(&rfkill->sync_work); in rfkill_register()
1112 bool soft_blocked = !!(rfkill->state & RFKILL_BLOCK_SW); in rfkill_register()
1115 __rfkill_switch_all(rfkill->type, soft_blocked); in rfkill_register()
1126 device_del(&rfkill->dev); in rfkill_register()
1128 list_del_init(&rfkill->node); in rfkill_register()
1139 if (rfkill->ops->poll) in rfkill_unregister()
1140 cancel_delayed_work_sync(&rfkill->poll_work); in rfkill_unregister()
1142 cancel_work_sync(&rfkill->uevent_work); in rfkill_unregister()
1143 cancel_work_sync(&rfkill->sync_work); in rfkill_unregister()
1145 rfkill->registered = false; in rfkill_unregister()
1147 device_del(&rfkill->dev); in rfkill_unregister()
1151 list_del_init(&rfkill->node); in rfkill_unregister()
1162 put_device(&rfkill->dev); in rfkill_destroy()
1174 return -ENOMEM; in rfkill_fop_open()
1176 data->max_size = RFKILL_EVENT_SIZE_V1; in rfkill_fop_open()
1178 INIT_LIST_HEAD(&data->events); in rfkill_fop_open()
1179 mutex_init(&data->mtx); in rfkill_fop_open()
1180 init_waitqueue_head(&data->read_wait); in rfkill_fop_open()
1193 rfkill_fill_event(&ev->ev, rfkill, RFKILL_OP_ADD); in rfkill_fop_open()
1194 mutex_lock(&data->mtx); in rfkill_fop_open()
1195 list_add_tail(&ev->list, &data->events); in rfkill_fop_open()
1196 mutex_unlock(&data->mtx); in rfkill_fop_open()
1198 list_add(&data->list, &rfkill_fds); in rfkill_fop_open()
1201 file->private_data = data; in rfkill_fop_open()
1207 mutex_destroy(&data->mtx); in rfkill_fop_open()
1208 list_for_each_entry_safe(ev, tmp, &data->events, list) in rfkill_fop_open()
1211 return -ENOMEM; in rfkill_fop_open()
1216 struct rfkill_data *data = file->private_data; in rfkill_fop_poll()
1219 poll_wait(file, &data->read_wait, wait); in rfkill_fop_poll()
1221 mutex_lock(&data->mtx); in rfkill_fop_poll()
1222 if (!list_empty(&data->events)) in rfkill_fop_poll()
1224 mutex_unlock(&data->mtx); in rfkill_fop_poll()
1232 struct rfkill_data *data = file->private_data; in rfkill_fop_read()
1237 mutex_lock(&data->mtx); in rfkill_fop_read()
1239 while (list_empty(&data->events)) { in rfkill_fop_read()
1240 if (file->f_flags & O_NONBLOCK) { in rfkill_fop_read()
1241 ret = -EAGAIN; in rfkill_fop_read()
1244 mutex_unlock(&data->mtx); in rfkill_fop_read()
1245 /* since we re-check and it just compares pointers, in rfkill_fop_read()
1248 ret = wait_event_interruptible(data->read_wait, in rfkill_fop_read()
1249 !list_empty(&data->events)); in rfkill_fop_read()
1250 mutex_lock(&data->mtx); in rfkill_fop_read()
1256 ev = list_first_entry(&data->events, struct rfkill_int_event, in rfkill_fop_read()
1259 sz = min_t(unsigned long, sizeof(ev->ev), count); in rfkill_fop_read()
1260 sz = min_t(unsigned long, sz, data->max_size); in rfkill_fop_read()
1262 if (copy_to_user(buf, &ev->ev, sz)) in rfkill_fop_read()
1263 ret = -EFAULT; in rfkill_fop_read()
1265 list_del(&ev->list); in rfkill_fop_read()
1268 mutex_unlock(&data->mtx); in rfkill_fop_read()
1275 struct rfkill_data *data = file->private_data; in rfkill_fop_write()
1281 if (count < RFKILL_EVENT_SIZE_V1 - 1) in rfkill_fop_write()
1282 return -EINVAL; in rfkill_fop_write()
1290 count = min_t(size_t, count, data->max_size); in rfkill_fop_write()
1292 return -EFAULT; in rfkill_fop_write()
1295 return -EINVAL; in rfkill_fop_write()
1303 if (rfkill->type == ev.type || in rfkill_fop_write()
1310 if (rfkill->idx == ev.idx && in rfkill_fop_write()
1311 (rfkill->type == ev.type || in rfkill_fop_write()
1317 ret = -EINVAL; in rfkill_fop_write()
1328 struct rfkill_data *data = file->private_data; in rfkill_fop_release()
1332 list_del(&data->list); in rfkill_fop_release()
1335 mutex_destroy(&data->mtx); in rfkill_fop_release()
1336 list_for_each_entry_safe(ev, tmp, &data->events, list) in rfkill_fop_release()
1340 if (data->input_handler) in rfkill_fop_release()
1353 struct rfkill_data *data = file->private_data; in rfkill_fop_ioctl()
1354 int ret = -ENOSYS; in rfkill_fop_ioctl()
1358 return -ENOSYS; in rfkill_fop_ioctl()
1360 mutex_lock(&data->mtx); in rfkill_fop_ioctl()
1364 if (!data->input_handler) { in rfkill_fop_ioctl()
1367 data->input_handler = true; in rfkill_fop_ioctl()
1374 ret = -EFAULT; in rfkill_fop_ioctl()
1378 ret = -EINVAL; in rfkill_fop_ioctl()
1381 data->max_size = size; in rfkill_fop_ioctl()
1387 mutex_unlock(&data->mtx); in rfkill_fop_ioctl()