cx23885-ir.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Driver for the Conexant CX23885/7/8 PCIe bridge
  3. *
  4. * Infrared device support routines - non-input, non-vl42_subdev routines
  5. *
  6. * Copyright (C) 2009 Andy Walls <awalls@md.metrocast.net>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <media/v4l2-device.h>
  19. #include "cx23885.h"
  20. #include "cx23885-ir.h"
  21. #include "cx23885-input.h"
  22. #define CX23885_IR_RX_FIFO_SERVICE_REQ 0
  23. #define CX23885_IR_RX_END_OF_RX_DETECTED 1
  24. #define CX23885_IR_RX_HW_FIFO_OVERRUN 2
  25. #define CX23885_IR_RX_SW_FIFO_OVERRUN 3
  26. #define CX23885_IR_TX_FIFO_SERVICE_REQ 0
  27. void cx23885_ir_rx_work_handler(struct work_struct *work)
  28. {
  29. struct cx23885_dev *dev =
  30. container_of(work, struct cx23885_dev, ir_rx_work);
  31. u32 events = 0;
  32. unsigned long *notifications = &dev->ir_rx_notifications;
  33. if (test_and_clear_bit(CX23885_IR_RX_SW_FIFO_OVERRUN, notifications))
  34. events |= V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN;
  35. if (test_and_clear_bit(CX23885_IR_RX_HW_FIFO_OVERRUN, notifications))
  36. events |= V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN;
  37. if (test_and_clear_bit(CX23885_IR_RX_END_OF_RX_DETECTED, notifications))
  38. events |= V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED;
  39. if (test_and_clear_bit(CX23885_IR_RX_FIFO_SERVICE_REQ, notifications))
  40. events |= V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ;
  41. if (events == 0)
  42. return;
  43. if (dev->kernel_ir)
  44. cx23885_input_rx_work_handler(dev, events);
  45. }
  46. void cx23885_ir_tx_work_handler(struct work_struct *work)
  47. {
  48. struct cx23885_dev *dev =
  49. container_of(work, struct cx23885_dev, ir_tx_work);
  50. u32 events = 0;
  51. unsigned long *notifications = &dev->ir_tx_notifications;
  52. if (test_and_clear_bit(CX23885_IR_TX_FIFO_SERVICE_REQ, notifications))
  53. events |= V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ;
  54. if (events == 0)
  55. return;
  56. }
  57. /* Possibly called in an IRQ context */
  58. void cx23885_ir_rx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events)
  59. {
  60. struct cx23885_dev *dev = to_cx23885(sd->v4l2_dev);
  61. unsigned long *notifications = &dev->ir_rx_notifications;
  62. if (events & V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ)
  63. set_bit(CX23885_IR_RX_FIFO_SERVICE_REQ, notifications);
  64. if (events & V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED)
  65. set_bit(CX23885_IR_RX_END_OF_RX_DETECTED, notifications);
  66. if (events & V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN)
  67. set_bit(CX23885_IR_RX_HW_FIFO_OVERRUN, notifications);
  68. if (events & V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN)
  69. set_bit(CX23885_IR_RX_SW_FIFO_OVERRUN, notifications);
  70. /*
  71. * For the integrated AV core, we are already in a workqueue context.
  72. * For the CX23888 integrated IR, we are in an interrupt context.
  73. */
  74. if (sd == dev->sd_cx25840)
  75. cx23885_ir_rx_work_handler(&dev->ir_rx_work);
  76. else
  77. schedule_work(&dev->ir_rx_work);
  78. }
  79. /* Possibly called in an IRQ context */
  80. void cx23885_ir_tx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events)
  81. {
  82. struct cx23885_dev *dev = to_cx23885(sd->v4l2_dev);
  83. unsigned long *notifications = &dev->ir_tx_notifications;
  84. if (events & V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ)
  85. set_bit(CX23885_IR_TX_FIFO_SERVICE_REQ, notifications);
  86. /*
  87. * For the integrated AV core, we are already in a workqueue context.
  88. * For the CX23888 integrated IR, we are in an interrupt context.
  89. */
  90. if (sd == dev->sd_cx25840)
  91. cx23885_ir_tx_work_handler(&dev->ir_tx_work);
  92. else
  93. schedule_work(&dev->ir_tx_work);
  94. }