Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * cxd2880_integ.c
0004  * Sony CXD2880 DVB-T2/T tuner + demodulator driver
0005  * integration layer common functions
0006  *
0007  * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
0008  */
0009 
0010 #include <linux/ktime.h>
0011 #include <linux/errno.h>
0012 
0013 #include "cxd2880_tnrdmd.h"
0014 #include "cxd2880_tnrdmd_mon.h"
0015 #include "cxd2880_integ.h"
0016 
0017 int cxd2880_integ_init(struct cxd2880_tnrdmd *tnr_dmd)
0018 {
0019     int ret;
0020     ktime_t start;
0021     u8 cpu_task_completed = 0;
0022 
0023     if (!tnr_dmd)
0024         return -EINVAL;
0025 
0026     ret = cxd2880_tnrdmd_init1(tnr_dmd);
0027     if (ret)
0028         return ret;
0029 
0030     start = ktime_get();
0031 
0032     while (1) {
0033         ret =
0034             cxd2880_tnrdmd_check_internal_cpu_status(tnr_dmd,
0035                              &cpu_task_completed);
0036         if (ret)
0037             return ret;
0038 
0039         if (cpu_task_completed)
0040             break;
0041 
0042         if (ktime_to_ms(ktime_sub(ktime_get(), start)) >
0043                     CXD2880_TNRDMD_WAIT_INIT_TIMEOUT)
0044             return -ETIMEDOUT;
0045 
0046         usleep_range(CXD2880_TNRDMD_WAIT_INIT_INTVL,
0047                  CXD2880_TNRDMD_WAIT_INIT_INTVL + 1000);
0048     }
0049 
0050     return cxd2880_tnrdmd_init2(tnr_dmd);
0051 }
0052 
0053 int cxd2880_integ_cancel(struct cxd2880_tnrdmd *tnr_dmd)
0054 {
0055     if (!tnr_dmd)
0056         return -EINVAL;
0057 
0058     atomic_set(&tnr_dmd->cancel, 1);
0059 
0060     return 0;
0061 }
0062 
0063 int cxd2880_integ_check_cancellation(struct cxd2880_tnrdmd *tnr_dmd)
0064 {
0065     if (!tnr_dmd)
0066         return -EINVAL;
0067 
0068     if (atomic_read(&tnr_dmd->cancel) != 0)
0069         return -ECANCELED;
0070 
0071     return 0;
0072 }