cx23885-ir.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Driver for the Conexant CX23885/7/8 PCIe bridge
  4. *
  5. * Infrared device support routines - non-input, non-vl42_subdev routines
  6. *
  7. * Copyright (C) 2009 Andy Walls <[email protected]>
  8. */
  9. #include "cx23885.h"
  10. #include "cx23885-ir.h"
  11. #include "cx23885-input.h"
  12. #include <media/v4l2-device.h>
  13. #define CX23885_IR_RX_FIFO_SERVICE_REQ 0
  14. #define CX23885_IR_RX_END_OF_RX_DETECTED 1
  15. #define CX23885_IR_RX_HW_FIFO_OVERRUN 2
  16. #define CX23885_IR_RX_SW_FIFO_OVERRUN 3
  17. #define CX23885_IR_TX_FIFO_SERVICE_REQ 0
  18. void cx23885_ir_rx_work_handler(struct work_struct *work)
  19. {
  20. struct cx23885_dev *dev =
  21. container_of(work, struct cx23885_dev, ir_rx_work);
  22. u32 events = 0;
  23. unsigned long *notifications = &dev->ir_rx_notifications;
  24. if (test_and_clear_bit(CX23885_IR_RX_SW_FIFO_OVERRUN, notifications))
  25. events |= V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN;
  26. if (test_and_clear_bit(CX23885_IR_RX_HW_FIFO_OVERRUN, notifications))
  27. events |= V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN;
  28. if (test_and_clear_bit(CX23885_IR_RX_END_OF_RX_DETECTED, notifications))
  29. events |= V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED;
  30. if (test_and_clear_bit(CX23885_IR_RX_FIFO_SERVICE_REQ, notifications))
  31. events |= V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ;
  32. if (events == 0)
  33. return;
  34. if (dev->kernel_ir)
  35. cx23885_input_rx_work_handler(dev, events);
  36. }
  37. void cx23885_ir_tx_work_handler(struct work_struct *work)
  38. {
  39. struct cx23885_dev *dev =
  40. container_of(work, struct cx23885_dev, ir_tx_work);
  41. u32 events = 0;
  42. unsigned long *notifications = &dev->ir_tx_notifications;
  43. if (test_and_clear_bit(CX23885_IR_TX_FIFO_SERVICE_REQ, notifications))
  44. events |= V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ;
  45. if (events == 0)
  46. return;
  47. }
  48. /* Possibly called in an IRQ context */
  49. void cx23885_ir_rx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events)
  50. {
  51. struct cx23885_dev *dev = to_cx23885(sd->v4l2_dev);
  52. unsigned long *notifications = &dev->ir_rx_notifications;
  53. if (events & V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ)
  54. set_bit(CX23885_IR_RX_FIFO_SERVICE_REQ, notifications);
  55. if (events & V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED)
  56. set_bit(CX23885_IR_RX_END_OF_RX_DETECTED, notifications);
  57. if (events & V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN)
  58. set_bit(CX23885_IR_RX_HW_FIFO_OVERRUN, notifications);
  59. if (events & V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN)
  60. set_bit(CX23885_IR_RX_SW_FIFO_OVERRUN, notifications);
  61. /*
  62. * For the integrated AV core, we are already in a workqueue context.
  63. * For the CX23888 integrated IR, we are in an interrupt context.
  64. */
  65. if (sd == dev->sd_cx25840)
  66. cx23885_ir_rx_work_handler(&dev->ir_rx_work);
  67. else
  68. schedule_work(&dev->ir_rx_work);
  69. }
  70. /* Possibly called in an IRQ context */
  71. void cx23885_ir_tx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events)
  72. {
  73. struct cx23885_dev *dev = to_cx23885(sd->v4l2_dev);
  74. unsigned long *notifications = &dev->ir_tx_notifications;
  75. if (events & V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ)
  76. set_bit(CX23885_IR_TX_FIFO_SERVICE_REQ, notifications);
  77. /*
  78. * For the integrated AV core, we are already in a workqueue context.
  79. * For the CX23888 integrated IR, we are in an interrupt context.
  80. */
  81. if (sd == dev->sd_cx25840)
  82. cx23885_ir_tx_work_handler(&dev->ir_tx_work);
  83. else
  84. schedule_work(&dev->ir_tx_work);
  85. }