1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for the Conexant CX23885/7/8 PCIe bridge
5 * Infrared device support routines - non-input, non-vl42_subdev routines
7 * Copyright (C) 2009 Andy Walls <awalls@md.metrocast.net>
11 #include "cx23885-ir.h"
12 #include "cx23885-input.h"
14 #include <media/v4l2-device.h>
16 #define CX23885_IR_RX_FIFO_SERVICE_REQ 0
17 #define CX23885_IR_RX_END_OF_RX_DETECTED 1
18 #define CX23885_IR_RX_HW_FIFO_OVERRUN 2
19 #define CX23885_IR_RX_SW_FIFO_OVERRUN 3
21 #define CX23885_IR_TX_FIFO_SERVICE_REQ 0
24 void cx23885_ir_rx_work_handler(struct work_struct
*work
)
26 struct cx23885_dev
*dev
=
27 container_of(work
, struct cx23885_dev
, ir_rx_work
);
29 unsigned long *notifications
= &dev
->ir_rx_notifications
;
31 if (test_and_clear_bit(CX23885_IR_RX_SW_FIFO_OVERRUN
, notifications
))
32 events
|= V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN
;
33 if (test_and_clear_bit(CX23885_IR_RX_HW_FIFO_OVERRUN
, notifications
))
34 events
|= V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN
;
35 if (test_and_clear_bit(CX23885_IR_RX_END_OF_RX_DETECTED
, notifications
))
36 events
|= V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED
;
37 if (test_and_clear_bit(CX23885_IR_RX_FIFO_SERVICE_REQ
, notifications
))
38 events
|= V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ
;
44 cx23885_input_rx_work_handler(dev
, events
);
47 void cx23885_ir_tx_work_handler(struct work_struct
*work
)
49 struct cx23885_dev
*dev
=
50 container_of(work
, struct cx23885_dev
, ir_tx_work
);
52 unsigned long *notifications
= &dev
->ir_tx_notifications
;
54 if (test_and_clear_bit(CX23885_IR_TX_FIFO_SERVICE_REQ
, notifications
))
55 events
|= V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ
;
62 /* Possibly called in an IRQ context */
63 void cx23885_ir_rx_v4l2_dev_notify(struct v4l2_subdev
*sd
, u32 events
)
65 struct cx23885_dev
*dev
= to_cx23885(sd
->v4l2_dev
);
66 unsigned long *notifications
= &dev
->ir_rx_notifications
;
68 if (events
& V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ
)
69 set_bit(CX23885_IR_RX_FIFO_SERVICE_REQ
, notifications
);
70 if (events
& V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED
)
71 set_bit(CX23885_IR_RX_END_OF_RX_DETECTED
, notifications
);
72 if (events
& V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN
)
73 set_bit(CX23885_IR_RX_HW_FIFO_OVERRUN
, notifications
);
74 if (events
& V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN
)
75 set_bit(CX23885_IR_RX_SW_FIFO_OVERRUN
, notifications
);
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.
81 if (sd
== dev
->sd_cx25840
)
82 cx23885_ir_rx_work_handler(&dev
->ir_rx_work
);
84 schedule_work(&dev
->ir_rx_work
);
87 /* Possibly called in an IRQ context */
88 void cx23885_ir_tx_v4l2_dev_notify(struct v4l2_subdev
*sd
, u32 events
)
90 struct cx23885_dev
*dev
= to_cx23885(sd
->v4l2_dev
);
91 unsigned long *notifications
= &dev
->ir_tx_notifications
;
93 if (events
& V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ
)
94 set_bit(CX23885_IR_TX_FIFO_SERVICE_REQ
, notifications
);
97 * For the integrated AV core, we are already in a workqueue context.
98 * For the CX23888 integrated IR, we are in an interrupt context.
100 if (sd
== dev
->sd_cx25840
)
101 cx23885_ir_tx_work_handler(&dev
->ir_tx_work
);
103 schedule_work(&dev
->ir_tx_work
);