Merge tag 'module-implicit-v4.1-rc8' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / drivers / media / pci / cx23885 / cx23885-ir.c
CommitLineData
f59ad611
AW
1/*
2 * Driver for the Conexant CX23885/7/8 PCIe bridge
3 *
4 * Infrared device support routines - non-input, non-vl42_subdev routines
5 *
6afdeaf8 6 * Copyright (C) 2009 Andy Walls <awalls@md.metrocast.net>
f59ad611
AW
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.
f59ad611
AW
17 */
18
19#include <media/v4l2-device.h>
20
21#include "cx23885.h"
ada73eee 22#include "cx23885-ir.h"
dbda8f70 23#include "cx23885-input.h"
f59ad611
AW
24
25#define CX23885_IR_RX_FIFO_SERVICE_REQ 0
26#define CX23885_IR_RX_END_OF_RX_DETECTED 1
27#define CX23885_IR_RX_HW_FIFO_OVERRUN 2
28#define CX23885_IR_RX_SW_FIFO_OVERRUN 3
29
30#define CX23885_IR_TX_FIFO_SERVICE_REQ 0
31
32
33void cx23885_ir_rx_work_handler(struct work_struct *work)
34{
35 struct cx23885_dev *dev =
36 container_of(work, struct cx23885_dev, ir_rx_work);
37 u32 events = 0;
38 unsigned long *notifications = &dev->ir_rx_notifications;
39
40 if (test_and_clear_bit(CX23885_IR_RX_SW_FIFO_OVERRUN, notifications))
41 events |= V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN;
42 if (test_and_clear_bit(CX23885_IR_RX_HW_FIFO_OVERRUN, notifications))
43 events |= V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN;
44 if (test_and_clear_bit(CX23885_IR_RX_END_OF_RX_DETECTED, notifications))
45 events |= V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED;
46 if (test_and_clear_bit(CX23885_IR_RX_FIFO_SERVICE_REQ, notifications))
47 events |= V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ;
48
49 if (events == 0)
50 return;
dbda8f70 51
43c24078 52 if (dev->kernel_ir)
dbda8f70 53 cx23885_input_rx_work_handler(dev, events);
f59ad611
AW
54}
55
56void cx23885_ir_tx_work_handler(struct work_struct *work)
57{
58 struct cx23885_dev *dev =
59 container_of(work, struct cx23885_dev, ir_tx_work);
60 u32 events = 0;
61 unsigned long *notifications = &dev->ir_tx_notifications;
62
63 if (test_and_clear_bit(CX23885_IR_TX_FIFO_SERVICE_REQ, notifications))
64 events |= V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ;
65
66 if (events == 0)
67 return;
68
69}
70
e5514f10 71/* Possibly called in an IRQ context */
f59ad611
AW
72void cx23885_ir_rx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events)
73{
74 struct cx23885_dev *dev = to_cx23885(sd->v4l2_dev);
75 unsigned long *notifications = &dev->ir_rx_notifications;
76
77 if (events & V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ)
78 set_bit(CX23885_IR_RX_FIFO_SERVICE_REQ, notifications);
79 if (events & V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED)
80 set_bit(CX23885_IR_RX_END_OF_RX_DETECTED, notifications);
81 if (events & V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN)
82 set_bit(CX23885_IR_RX_HW_FIFO_OVERRUN, notifications);
83 if (events & V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN)
84 set_bit(CX23885_IR_RX_SW_FIFO_OVERRUN, notifications);
e5514f10
AW
85
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_rx_work_handler(&dev->ir_rx_work);
92 else
93 schedule_work(&dev->ir_rx_work);
f59ad611
AW
94}
95
e5514f10 96/* Possibly called in an IRQ context */
f59ad611
AW
97void cx23885_ir_tx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events)
98{
99 struct cx23885_dev *dev = to_cx23885(sd->v4l2_dev);
100 unsigned long *notifications = &dev->ir_tx_notifications;
101
102 if (events & V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ)
103 set_bit(CX23885_IR_TX_FIFO_SERVICE_REQ, notifications);
e5514f10
AW
104
105 /*
106 * For the integrated AV core, we are already in a workqueue context.
107 * For the CX23888 integrated IR, we are in an interrupt context.
108 */
109 if (sd == dev->sd_cx25840)
110 cx23885_ir_tx_work_handler(&dev->ir_tx_work);
111 else
112 schedule_work(&dev->ir_tx_work);
f59ad611 113}