Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / media / dvb-frontends / cxd2880 / cxd2880_integ.c
blob5302ab0964c1afb900d41b90501044a265902c38
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * cxd2880_integ.c
4 * Sony CXD2880 DVB-T2/T tuner + demodulator driver
5 * integration layer common functions
7 * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
8 */
10 #include <linux/ktime.h>
11 #include <linux/errno.h>
13 #include "cxd2880_tnrdmd.h"
14 #include "cxd2880_tnrdmd_mon.h"
15 #include "cxd2880_integ.h"
17 int cxd2880_integ_init(struct cxd2880_tnrdmd *tnr_dmd)
19 int ret;
20 ktime_t start;
21 u8 cpu_task_completed = 0;
23 if (!tnr_dmd)
24 return -EINVAL;
26 ret = cxd2880_tnrdmd_init1(tnr_dmd);
27 if (ret)
28 return ret;
30 start = ktime_get();
32 while (1) {
33 ret =
34 cxd2880_tnrdmd_check_internal_cpu_status(tnr_dmd,
35 &cpu_task_completed);
36 if (ret)
37 return ret;
39 if (cpu_task_completed)
40 break;
42 if (ktime_to_ms(ktime_sub(ktime_get(), start)) >
43 CXD2880_TNRDMD_WAIT_INIT_TIMEOUT)
44 return -ETIMEDOUT;
46 usleep_range(CXD2880_TNRDMD_WAIT_INIT_INTVL,
47 CXD2880_TNRDMD_WAIT_INIT_INTVL + 1000);
50 return cxd2880_tnrdmd_init2(tnr_dmd);
53 int cxd2880_integ_cancel(struct cxd2880_tnrdmd *tnr_dmd)
55 if (!tnr_dmd)
56 return -EINVAL;
58 atomic_set(&tnr_dmd->cancel, 1);
60 return 0;
63 int cxd2880_integ_check_cancellation(struct cxd2880_tnrdmd *tnr_dmd)
65 if (!tnr_dmd)
66 return -EINVAL;
68 if (atomic_read(&tnr_dmd->cancel) != 0)
69 return -ECANCELED;
71 return 0;