Lines Matching full:lr

514 static void linereq_put_event(struct linereq *lr,  in linereq_put_event()  argument
519 spin_lock(&lr->wait.lock); in linereq_put_event()
520 if (kfifo_is_full(&lr->events)) { in linereq_put_event()
522 kfifo_skip(&lr->events); in linereq_put_event()
524 kfifo_in(&lr->events, le, 1); in linereq_put_event()
525 spin_unlock(&lr->wait.lock); in linereq_put_event()
527 wake_up_poll(&lr->wait, EPOLLIN); in linereq_put_event()
535 struct linereq *lr = line->req; in edge_irq_thread() local
550 if (lr->num_lines != 1) in edge_irq_thread()
551 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_thread()
576 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; in edge_irq_thread()
579 linereq_put_event(lr, &le); in edge_irq_thread()
587 struct linereq *lr = line->req; in edge_irq_handler() local
595 if (lr->num_lines != 1) in edge_irq_handler()
596 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_handler()
635 struct linereq *lr; in debounce_work_func() local
665 lr = line->req; in debounce_work_func()
670 le.seqno = (lr->num_lines == 1) ? in debounce_work_func()
671 le.line_seqno : atomic_inc_return(&lr->seqno); in debounce_work_func()
680 linereq_put_event(lr, &le); in debounce_work_func()
972 static long linereq_get_values(struct linereq *lr, void __user *ip) in linereq_get_values() argument
985 for (num_get = 0, i = 0; i < lr->num_lines; i++) { in linereq_get_values()
988 descs = &lr->lines[i].desc; in linereq_get_values()
999 for (didx = 0, i = 0; i < lr->num_lines; i++) { in linereq_get_values()
1001 descs[didx] = lr->lines[i].desc; in linereq_get_values()
1015 for (didx = 0, i = 0; i < lr->num_lines; i++) { in linereq_get_values()
1017 if (lr->lines[i].sw_debounced) in linereq_get_values()
1018 val = debounced_value(&lr->lines[i]); in linereq_get_values()
1033 static long linereq_set_values_unlocked(struct linereq *lr, in linereq_set_values_unlocked() argument
1042 for (num_set = 0, i = 0; i < lr->num_lines; i++) { in linereq_set_values_unlocked()
1044 if (!test_bit(FLAG_IS_OUT, &lr->lines[i].desc->flags)) in linereq_set_values_unlocked()
1049 descs = &lr->lines[i].desc; in linereq_set_values_unlocked()
1060 for (didx = 0, i = 0; i < lr->num_lines; i++) { in linereq_set_values_unlocked()
1062 descs[didx] = lr->lines[i].desc; in linereq_set_values_unlocked()
1075 static long linereq_set_values(struct linereq *lr, void __user *ip) in linereq_set_values() argument
1083 mutex_lock(&lr->config_mutex); in linereq_set_values()
1085 ret = linereq_set_values_unlocked(lr, &lv); in linereq_set_values()
1087 mutex_unlock(&lr->config_mutex); in linereq_set_values()
1092 static long linereq_set_config_unlocked(struct linereq *lr, in linereq_set_config_unlocked() argument
1101 for (i = 0; i < lr->num_lines; i++) { in linereq_set_config_unlocked()
1102 desc = lr->lines[i].desc; in linereq_set_config_unlocked()
1116 edge_detector_stop(&lr->lines[i]); in linereq_set_config_unlocked()
1125 ret = edge_detector_update(&lr->lines[i], lc, i, in linereq_set_config_unlocked()
1139 static long linereq_set_config(struct linereq *lr, void __user *ip) in linereq_set_config() argument
1147 ret = gpio_v2_line_config_validate(&lc, lr->num_lines); in linereq_set_config()
1151 mutex_lock(&lr->config_mutex); in linereq_set_config()
1153 ret = linereq_set_config_unlocked(lr, &lc); in linereq_set_config()
1155 mutex_unlock(&lr->config_mutex); in linereq_set_config()
1163 struct linereq *lr = file->private_data; in linereq_ioctl() local
1167 return linereq_get_values(lr, ip); in linereq_ioctl()
1169 return linereq_set_values(lr, ip); in linereq_ioctl()
1171 return linereq_set_config(lr, ip); in linereq_ioctl()
1187 struct linereq *lr = file->private_data; in linereq_poll() local
1190 poll_wait(file, &lr->wait, wait); in linereq_poll()
1192 if (!kfifo_is_empty_spinlocked_noirqsave(&lr->events, in linereq_poll()
1193 &lr->wait.lock)) in linereq_poll()
1204 struct linereq *lr = file->private_data; in linereq_read() local
1213 spin_lock(&lr->wait.lock); in linereq_read()
1214 if (kfifo_is_empty(&lr->events)) { in linereq_read()
1216 spin_unlock(&lr->wait.lock); in linereq_read()
1221 spin_unlock(&lr->wait.lock); in linereq_read()
1225 ret = wait_event_interruptible_locked(lr->wait, in linereq_read()
1226 !kfifo_is_empty(&lr->events)); in linereq_read()
1228 spin_unlock(&lr->wait.lock); in linereq_read()
1233 ret = kfifo_out(&lr->events, &le, 1); in linereq_read()
1234 spin_unlock(&lr->wait.lock); in linereq_read()
1253 static void linereq_free(struct linereq *lr) in linereq_free() argument
1257 for (i = 0; i < lr->num_lines; i++) { in linereq_free()
1258 edge_detector_stop(&lr->lines[i]); in linereq_free()
1259 if (lr->lines[i].desc) in linereq_free()
1260 gpiod_free(lr->lines[i].desc); in linereq_free()
1262 kfifo_free(&lr->events); in linereq_free()
1263 kfree(lr->label); in linereq_free()
1264 put_device(&lr->gdev->dev); in linereq_free()
1265 kfree(lr); in linereq_free()
1270 struct linereq *lr = file->private_data; in linereq_release() local
1272 linereq_free(lr); in linereq_release()
1292 struct linereq *lr; in linereq_create() local
1312 lr = kzalloc(struct_size(lr, lines, ulr.num_lines), GFP_KERNEL); in linereq_create()
1313 if (!lr) in linereq_create()
1316 lr->gdev = gdev; in linereq_create()
1320 lr->lines[i].req = lr; in linereq_create()
1321 WRITE_ONCE(lr->lines[i].sw_debounced, 0); in linereq_create()
1322 INIT_DELAYED_WORK(&lr->lines[i].work, debounce_work_func); in linereq_create()
1327 lr->label = kstrndup(ulr.consumer, sizeof(ulr.consumer) - 1, in linereq_create()
1329 if (!lr->label) { in linereq_create()
1335 mutex_init(&lr->config_mutex); in linereq_create()
1336 init_waitqueue_head(&lr->wait); in linereq_create()
1337 lr->event_buffer_size = ulr.event_buffer_size; in linereq_create()
1338 if (lr->event_buffer_size == 0) in linereq_create()
1339 lr->event_buffer_size = ulr.num_lines * 16; in linereq_create()
1340 else if (lr->event_buffer_size > GPIO_V2_LINES_MAX * 16) in linereq_create()
1341 lr->event_buffer_size = GPIO_V2_LINES_MAX * 16; in linereq_create()
1343 atomic_set(&lr->seqno, 0); in linereq_create()
1344 lr->num_lines = ulr.num_lines; in linereq_create()
1356 ret = gpiod_request(desc, lr->label); in linereq_create()
1360 lr->lines[i].desc = desc; in linereq_create()
1383 ret = edge_detector_setup(&lr->lines[i], lc, i, in linereq_create()
1402 file = anon_inode_getfile("gpio-line", &line_fileops, lr, in linereq_create()
1423 lr->num_lines); in linereq_create()
1430 linereq_free(lr); in linereq_create()