cx23885-ir.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301, USA.
  22. */
  23. #include <media/v4l2-device.h>
  24. #include "cx23885.h"
  25. #include "cx23885-ir.h"
  26. #include "cx23885-input.h"
  27. #define CX23885_IR_RX_FIFO_SERVICE_REQ 0
  28. #define CX23885_IR_RX_END_OF_RX_DETECTED 1
  29. #define CX23885_IR_RX_HW_FIFO_OVERRUN 2
  30. #define CX23885_IR_RX_SW_FIFO_OVERRUN 3
  31. #define CX23885_IR_TX_FIFO_SERVICE_REQ 0
  32. void cx23885_ir_rx_work_handler(struct work_struct *work)
  33. {
  34. struct cx23885_dev *dev =
  35. container_of(work, struct cx23885_dev, ir_rx_work);
  36. u32 events = 0;
  37. unsigned long *notifications = &dev->ir_rx_notifications;
  38. if (test_and_clear_bit(CX23885_IR_RX_SW_FIFO_OVERRUN, notifications))
  39. events |= V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN;
  40. if (test_and_clear_bit(CX23885_IR_RX_HW_FIFO_OVERRUN, notifications))
  41. events |= V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN;
  42. if (test_and_clear_bit(CX23885_IR_RX_END_OF_RX_DETECTED, notifications))
  43. events |= V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED;
  44. if (test_and_clear_bit(CX23885_IR_RX_FIFO_SERVICE_REQ, notifications))
  45. events |= V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ;
  46. if (events == 0)
  47. return;
  48. if (dev->kernel_ir)
  49. cx23885_input_rx_work_handler(dev, events);
  50. }
  51. void cx23885_ir_tx_work_handler(struct work_struct *work)
  52. {
  53. struct cx23885_dev *dev =
  54. container_of(work, struct cx23885_dev, ir_tx_work);
  55. u32 events = 0;
  56. unsigned long *notifications = &dev->ir_tx_notifications;
  57. if (test_and_clear_bit(CX23885_IR_TX_FIFO_SERVICE_REQ, notifications))
  58. events |= V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ;
  59. if (events == 0)
  60. return;
  61. }
  62. /* Possibly called in an IRQ context */
  63. void cx23885_ir_rx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events)
  64. {
  65. struct cx23885_dev *dev = to_cx23885(sd->v4l2_dev);
  66. unsigned long *notifications = &dev->ir_rx_notifications;
  67. if (events & V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ)
  68. set_bit(CX23885_IR_RX_FIFO_SERVICE_REQ, notifications);
  69. if (events & V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED)
  70. set_bit(CX23885_IR_RX_END_OF_RX_DETECTED, notifications);
  71. if (events & V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN)
  72. set_bit(CX23885_IR_RX_HW_FIFO_OVERRUN, notifications);
  73. if (events & V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN)
  74. set_bit(CX23885_IR_RX_SW_FIFO_OVERRUN, notifications);
  75. /*
  76. * For the integrated AV core, we are already in a workqueue context.
  77. * For the CX23888 integrated IR, we are in an interrupt context.
  78. */
  79. if (sd == dev->sd_cx25840)
  80. cx23885_ir_rx_work_handler(&dev->ir_rx_work);
  81. else
  82. schedule_work(&dev->ir_rx_work);
  83. }
  84. /* Possibly called in an IRQ context */
  85. void cx23885_ir_tx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events)
  86. {
  87. struct cx23885_dev *dev = to_cx23885(sd->v4l2_dev);
  88. unsigned long *notifications = &dev->ir_tx_notifications;
  89. if (events & V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ)
  90. set_bit(CX23885_IR_TX_FIFO_SERVICE_REQ, notifications);
  91. /*
  92. * For the integrated AV core, we are already in a workqueue context.
  93. * For the CX23888 integrated IR, we are in an interrupt context.
  94. */
  95. if (sd == dev->sd_cx25840)
  96. cx23885_ir_tx_work_handler(&dev->ir_tx_work);
  97. else
  98. schedule_work(&dev->ir_tx_work);
  99. }