Lines Matching refs:lr

523 static void linereq_put_event(struct linereq *lr,  in linereq_put_event()  argument
528 spin_lock(&lr->wait.lock); in linereq_put_event()
529 if (kfifo_is_full(&lr->events)) { in linereq_put_event()
531 kfifo_skip(&lr->events); in linereq_put_event()
533 kfifo_in(&lr->events, le, 1); in linereq_put_event()
534 spin_unlock(&lr->wait.lock); in linereq_put_event()
536 wake_up_poll(&lr->wait, EPOLLIN); in linereq_put_event()
552 struct linereq *lr = line->req; in edge_irq_thread() local
568 if (lr->num_lines != 1) in edge_irq_thread()
569 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_thread()
594 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; in edge_irq_thread()
597 linereq_put_event(lr, &le); in edge_irq_thread()
605 struct linereq *lr = line->req; in edge_irq_handler() local
613 if (lr->num_lines != 1) in edge_irq_handler()
614 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_handler()
653 struct linereq *lr; in debounce_work_func() local
685 lr = line->req; in debounce_work_func()
690 le.seqno = (lr->num_lines == 1) ? in debounce_work_func()
691 le.line_seqno : atomic_inc_return(&lr->seqno); in debounce_work_func()
700 linereq_put_event(lr, &le); in debounce_work_func()
997 static long linereq_get_values(struct linereq *lr, void __user *ip) in linereq_get_values() argument
1010 for (num_get = 0, i = 0; i < lr->num_lines; i++) { in linereq_get_values()
1013 descs = &lr->lines[i].desc; in linereq_get_values()
1024 for (didx = 0, i = 0; i < lr->num_lines; i++) { in linereq_get_values()
1026 descs[didx] = lr->lines[i].desc; in linereq_get_values()
1040 for (didx = 0, i = 0; i < lr->num_lines; i++) { in linereq_get_values()
1042 if (lr->lines[i].sw_debounced) in linereq_get_values()
1043 val = debounced_value(&lr->lines[i]); in linereq_get_values()
1058 static long linereq_set_values_unlocked(struct linereq *lr, in linereq_set_values_unlocked() argument
1067 for (num_set = 0, i = 0; i < lr->num_lines; i++) { in linereq_set_values_unlocked()
1069 if (!test_bit(FLAG_IS_OUT, &lr->lines[i].desc->flags)) in linereq_set_values_unlocked()
1074 descs = &lr->lines[i].desc; in linereq_set_values_unlocked()
1085 for (didx = 0, i = 0; i < lr->num_lines; i++) { in linereq_set_values_unlocked()
1087 descs[didx] = lr->lines[i].desc; in linereq_set_values_unlocked()
1100 static long linereq_set_values(struct linereq *lr, void __user *ip) in linereq_set_values() argument
1108 mutex_lock(&lr->config_mutex); in linereq_set_values()
1110 ret = linereq_set_values_unlocked(lr, &lv); in linereq_set_values()
1112 mutex_unlock(&lr->config_mutex); in linereq_set_values()
1117 static long linereq_set_config_unlocked(struct linereq *lr, in linereq_set_config_unlocked() argument
1126 for (i = 0; i < lr->num_lines; i++) { in linereq_set_config_unlocked()
1127 desc = lr->lines[i].desc; in linereq_set_config_unlocked()
1141 edge_detector_stop(&lr->lines[i]); in linereq_set_config_unlocked()
1150 ret = edge_detector_update(&lr->lines[i], lc, i, in linereq_set_config_unlocked()
1164 static long linereq_set_config(struct linereq *lr, void __user *ip) in linereq_set_config() argument
1172 ret = gpio_v2_line_config_validate(&lc, lr->num_lines); in linereq_set_config()
1176 mutex_lock(&lr->config_mutex); in linereq_set_config()
1178 ret = linereq_set_config_unlocked(lr, &lc); in linereq_set_config()
1180 mutex_unlock(&lr->config_mutex); in linereq_set_config()
1188 struct linereq *lr = file->private_data; in linereq_ioctl() local
1192 return linereq_get_values(lr, ip); in linereq_ioctl()
1194 return linereq_set_values(lr, ip); in linereq_ioctl()
1196 return linereq_set_config(lr, ip); in linereq_ioctl()
1212 struct linereq *lr = file->private_data; in linereq_poll() local
1215 poll_wait(file, &lr->wait, wait); in linereq_poll()
1217 if (!kfifo_is_empty_spinlocked_noirqsave(&lr->events, in linereq_poll()
1218 &lr->wait.lock)) in linereq_poll()
1229 struct linereq *lr = file->private_data; in linereq_read() local
1238 spin_lock(&lr->wait.lock); in linereq_read()
1239 if (kfifo_is_empty(&lr->events)) { in linereq_read()
1241 spin_unlock(&lr->wait.lock); in linereq_read()
1246 spin_unlock(&lr->wait.lock); in linereq_read()
1250 ret = wait_event_interruptible_locked(lr->wait, in linereq_read()
1251 !kfifo_is_empty(&lr->events)); in linereq_read()
1253 spin_unlock(&lr->wait.lock); in linereq_read()
1258 ret = kfifo_out(&lr->events, &le, 1); in linereq_read()
1259 spin_unlock(&lr->wait.lock); in linereq_read()
1278 static void linereq_free(struct linereq *lr) in linereq_free() argument
1282 for (i = 0; i < lr->num_lines; i++) { in linereq_free()
1283 edge_detector_stop(&lr->lines[i]); in linereq_free()
1284 if (lr->lines[i].desc) in linereq_free()
1285 gpiod_free(lr->lines[i].desc); in linereq_free()
1287 kfifo_free(&lr->events); in linereq_free()
1288 kfree(lr->label); in linereq_free()
1289 put_device(&lr->gdev->dev); in linereq_free()
1290 kfree(lr); in linereq_free()
1295 struct linereq *lr = file->private_data; in linereq_release() local
1297 linereq_free(lr); in linereq_release()
1317 struct linereq *lr; in linereq_create() local
1337 lr = kzalloc(struct_size(lr, lines, ulr.num_lines), GFP_KERNEL); in linereq_create()
1338 if (!lr) in linereq_create()
1341 lr->gdev = gdev; in linereq_create()
1345 lr->lines[i].req = lr; in linereq_create()
1346 WRITE_ONCE(lr->lines[i].sw_debounced, 0); in linereq_create()
1347 INIT_DELAYED_WORK(&lr->lines[i].work, debounce_work_func); in linereq_create()
1352 lr->label = kstrndup(ulr.consumer, sizeof(ulr.consumer) - 1, in linereq_create()
1354 if (!lr->label) { in linereq_create()
1360 mutex_init(&lr->config_mutex); in linereq_create()
1361 init_waitqueue_head(&lr->wait); in linereq_create()
1362 lr->event_buffer_size = ulr.event_buffer_size; in linereq_create()
1363 if (lr->event_buffer_size == 0) in linereq_create()
1364 lr->event_buffer_size = ulr.num_lines * 16; in linereq_create()
1365 else if (lr->event_buffer_size > GPIO_V2_LINES_MAX * 16) in linereq_create()
1366 lr->event_buffer_size = GPIO_V2_LINES_MAX * 16; in linereq_create()
1368 atomic_set(&lr->seqno, 0); in linereq_create()
1369 lr->num_lines = ulr.num_lines; in linereq_create()
1381 ret = gpiod_request(desc, lr->label); in linereq_create()
1385 lr->lines[i].desc = desc; in linereq_create()
1408 ret = edge_detector_setup(&lr->lines[i], lc, i, in linereq_create()
1427 file = anon_inode_getfile("gpio-line", &line_fileops, lr, in linereq_create()
1448 lr->num_lines); in linereq_create()
1455 linereq_free(lr); in linereq_create()