1 /* dvb-usb-remote.c is part of the DVB USB library.
3 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
6 * This file contains functions for initializing the input-device and for
7 * handling remote-control-queries.
9 #include "dvb_usb_common.h"
10 #include <linux/usb/input.h>
12 /* Remote-control poll function - called every dib->rc_query_interval ms to see
13 * whether the remote control has received anything.
15 * TODO: Fix the repeat rate of the input device.
17 static void dvb_usb_read_remote_control(struct work_struct
*work
)
19 struct dvb_usb_device
*d
=
20 container_of(work
, struct dvb_usb_device
, rc_query_work
.work
);
23 /* TODO: need a lock here. We can simply skip checking for the remote
24 control if we're busy. */
26 /* when the parameter has been set to 1 via sysfs while the
27 * driver was running, or when bulk mode is enabled after IR init
29 if (dvb_usb_disable_rc_polling
|| d
->props
.rc
.bulk_mode
)
32 err
= d
->props
.rc
.rc_query(d
);
34 err("error %d while querying for an remote control event.",
37 schedule_delayed_work(&d
->rc_query_work
,
38 msecs_to_jiffies(d
->props
.rc
.rc_interval
));
41 static int rc_core_dvb_usb_remote_init(struct dvb_usb_device
*d
)
46 dev
= rc_allocate_device();
50 dev
->driver_name
= d
->props
.rc
.module_name
;
51 dev
->map_name
= d
->rc_map
;
52 dev
->change_protocol
= d
->props
.rc
.change_protocol
;
53 dev
->allowed_protos
= d
->props
.rc
.allowed_protos
;
54 dev
->driver_type
= d
->props
.rc
.driver_type
;
55 usb_to_input_id(d
->udev
, &dev
->input_id
);
56 dev
->input_name
= "IR-receiver inside an USB DVB receiver";
57 dev
->input_phys
= d
->rc_phys
;
58 dev
->dev
.parent
= &d
->udev
->dev
;
61 /* leave remote controller enabled even there is no default map */
62 if (dev
->map_name
== NULL
)
63 dev
->map_name
= RC_MAP_EMPTY
;
65 err
= rc_register_device(dev
);
74 if (!d
->props
.rc
.rc_query
|| d
->props
.rc
.bulk_mode
)
77 /* Polling mode - initialize a work queue for handling it */
78 INIT_DELAYED_WORK(&d
->rc_query_work
, dvb_usb_read_remote_control
);
80 rc_interval
= d
->props
.rc
.rc_interval
;
82 info("schedule remote query interval to %d msecs.", rc_interval
);
83 schedule_delayed_work(&d
->rc_query_work
,
84 msecs_to_jiffies(rc_interval
));
89 int dvb_usb_remote_init(struct dvb_usb_device
*d
)
93 if (dvb_usb_disable_rc_polling
)
96 if (d
->props
.rc
.module_name
== NULL
)
99 usb_make_path(d
->udev
, d
->rc_phys
, sizeof(d
->rc_phys
));
100 strlcat(d
->rc_phys
, "/ir0", sizeof(d
->rc_phys
));
102 /* Start the remote-control polling. */
103 err
= rc_core_dvb_usb_remote_init(d
);
107 d
->state
|= DVB_USB_STATE_REMOTE
;
112 int dvb_usb_remote_exit(struct dvb_usb_device
*d
)
114 if (d
->state
& DVB_USB_STATE_REMOTE
) {
115 cancel_delayed_work_sync(&d
->rc_query_work
);
116 rc_unregister_device(d
->rc_dev
);
118 d
->state
&= ~DVB_USB_STATE_REMOTE
;