cxd2880_integ.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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
  6. *
  7. * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
  8. */
  9. #include <linux/ktime.h>
  10. #include <linux/errno.h>
  11. #include "cxd2880_tnrdmd.h"
  12. #include "cxd2880_tnrdmd_mon.h"
  13. #include "cxd2880_integ.h"
  14. int cxd2880_integ_init(struct cxd2880_tnrdmd *tnr_dmd)
  15. {
  16. int ret;
  17. ktime_t start;
  18. u8 cpu_task_completed = 0;
  19. if (!tnr_dmd)
  20. return -EINVAL;
  21. ret = cxd2880_tnrdmd_init1(tnr_dmd);
  22. if (ret)
  23. return ret;
  24. start = ktime_get();
  25. while (1) {
  26. ret =
  27. cxd2880_tnrdmd_check_internal_cpu_status(tnr_dmd,
  28. &cpu_task_completed);
  29. if (ret)
  30. return ret;
  31. if (cpu_task_completed)
  32. break;
  33. if (ktime_to_ms(ktime_sub(ktime_get(), start)) >
  34. CXD2880_TNRDMD_WAIT_INIT_TIMEOUT)
  35. return -ETIMEDOUT;
  36. usleep_range(CXD2880_TNRDMD_WAIT_INIT_INTVL,
  37. CXD2880_TNRDMD_WAIT_INIT_INTVL + 1000);
  38. }
  39. return cxd2880_tnrdmd_init2(tnr_dmd);
  40. }
  41. int cxd2880_integ_cancel(struct cxd2880_tnrdmd *tnr_dmd)
  42. {
  43. if (!tnr_dmd)
  44. return -EINVAL;
  45. atomic_set(&tnr_dmd->cancel, 1);
  46. return 0;
  47. }
  48. int cxd2880_integ_check_cancellation(struct cxd2880_tnrdmd *tnr_dmd)
  49. {
  50. if (!tnr_dmd)
  51. return -EINVAL;
  52. if (atomic_read(&tnr_dmd->cancel) != 0)
  53. return -ECANCELED;
  54. return 0;
  55. }