aboutsummaryrefslogtreecommitdiff
path: root/drivers/media/rc/rc-main.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-09-05 18:21:14 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2015-09-05 18:21:14 -0700
commit9cfcc658da9693f65e7224e8329e40ada2f3c699 (patch)
tree44fb518eee069733f3f895177899815e7c89e5b0 /drivers/media/rc/rc-main.c
parente3a98ac47698bf1c1e4e6fae72afc9866953fce5 (diff)
parent50ef28a6ac216fd8b796257a3768fef8f57b917d (diff)
Merge tag 'media/v4.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media updates from Mauro Carvalho Chehab: - new DVB frontend drivers: ascot2e, cxd2841er, horus3a, lnbh25 - new HDMI capture driver: tc358743 - new driver for NetUP DVB new boards (netup_unidvb) - IR support for DVBSky cards (smipcie-ir) - Coda driver has gain macroblock tiling support - Renesas R-Car gains JPEG codec driver - new DVB platform driver for STi boards: c8sectpfe - added documentation for the media core kABI to device-drivers DocBook - lots of driver fixups, cleanups and improvements * tag 'media/v4.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (297 commits) [media] c8sectpfe: Remove select on undefined LIBELF_32 [media] i2c: fix platform_no_drv_owner.cocci warnings [media] cx231xx: Use wake_up_interruptible() instead of wake_up_interruptible_nr() [media] tc358743: only queue subdev notifications if devnode is set [media] tc358743: add missing Kconfig dependency/select [media] c8sectpfe: Use %pad to print 'dma_addr_t' [media] DocBook media: Fix typo "the the" in xml files [media] tc358743: make reset gpio optional [media] tc358743: set direction of reset gpio using devm_gpiod_get [media] dvbdev: document most of the functions/data structs [media] dvb_frontend.h: document the struct dvb_frontend [media] dvb-frontend.h: document struct dtv_frontend_properties [media] dvb-frontend.h: document struct dvb_frontend_ops [media] dvb: Use DVBFE_ALGO_HW where applicable [media] dvb_frontend.h: document struct analog_demod_ops [media] dvb_frontend.h: Document struct dvb_tuner_ops [media] Docbook: Document struct analog_parameters [media] dvb_frontend.h: get rid of dvbfe_modcod [media] add documentation for struct dvb_tuner_info [media] dvb_frontend: document dvb_frontend_tune_settings ...
Diffstat (limited to 'drivers/media/rc/rc-main.c')
-rw-r--r--drivers/media/rc/rc-main.c74
1 files changed, 46 insertions, 28 deletions
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 0ff388a16168..3f0f71adabb4 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -18,17 +18,15 @@
#include <linux/input.h>
#include <linux/leds.h>
#include <linux/slab.h>
+#include <linux/idr.h>
#include <linux/device.h>
#include <linux/module.h>
#include "rc-core-priv.h"
-/* Bitmap to store allocated device numbers from 0 to IRRCV_NUM_DEVICES - 1 */
-#define IRRCV_NUM_DEVICES 256
-static DECLARE_BITMAP(ir_core_dev_number, IRRCV_NUM_DEVICES);
-
/* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */
#define IR_TAB_MIN_SIZE 256
#define IR_TAB_MAX_SIZE 8192
+#define RC_DEV_MAX 256
/* FIXME: IR_KEYPRESS_TIMEOUT should be protocol specific */
#define IR_KEYPRESS_TIMEOUT 250
@@ -38,6 +36,9 @@ static LIST_HEAD(rc_map_list);
static DEFINE_SPINLOCK(rc_map_lock);
static struct led_trigger *led_feedback;
+/* Used to keep track of rc devices */
+static DEFINE_IDA(rc_ida);
+
static struct rc_map_list *seek_rc_map(const char *name)
{
struct rc_map_list *map = NULL;
@@ -799,7 +800,6 @@ static struct {
{ RC_BIT_SANYO, "sanyo" },
{ RC_BIT_SHARP, "sharp" },
{ RC_BIT_MCE_KBD, "mce_kbd" },
- { RC_BIT_LIRC, "lirc" },
{ RC_BIT_XMP, "xmp" },
};
@@ -828,6 +828,23 @@ struct rc_filter_attribute {
.mask = (_mask), \
}
+static bool lirc_is_present(void)
+{
+#if defined(CONFIG_LIRC_MODULE)
+ struct module *lirc;
+
+ mutex_lock(&module_mutex);
+ lirc = find_module("lirc_dev");
+ mutex_unlock(&module_mutex);
+
+ return lirc ? true : false;
+#elif defined(CONFIG_LIRC)
+ return true;
+#else
+ return false;
+#endif
+}
+
/**
* show_protocols() - shows the current/wakeup IR protocol(s)
* @device: the device descriptor
@@ -882,6 +899,9 @@ static ssize_t show_protocols(struct device *device,
allowed &= ~proto_names[i].type;
}
+ if (dev->driver_type == RC_DRIVER_IR_RAW && lirc_is_present())
+ tmp += sprintf(tmp, "[lirc] ");
+
if (tmp != buf)
tmp--;
*tmp = '\n';
@@ -933,8 +953,12 @@ static int parse_protocol_change(u64 *protocols, const char *buf)
}
if (i == ARRAY_SIZE(proto_names)) {
- IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
- return -EINVAL;
+ if (!strcasecmp(tmp, "lirc"))
+ mask = 0;
+ else {
+ IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
+ return -EINVAL;
+ }
}
count++;
@@ -1191,9 +1215,6 @@ static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env)
{
struct rc_dev *dev = to_rc_dev(device);
- if (!dev || !dev->input_dev)
- return -ENODEV;
-
if (dev->rc_map.name)
ADD_HOTPLUG_VAR("NAME=%s", dev->rc_map.name);
if (dev->driver_name)
@@ -1312,7 +1333,9 @@ int rc_register_device(struct rc_dev *dev)
static bool raw_init = false; /* raw decoders loaded? */
struct rc_map *rc_map;
const char *path;
- int rc, devno, attr = 0;
+ int attr = 0;
+ int minor;
+ int rc;
if (!dev || !dev->map_name)
return -EINVAL;
@@ -1332,13 +1355,13 @@ int rc_register_device(struct rc_dev *dev)
if (dev->close)
dev->input_dev->close = ir_close;
- do {
- devno = find_first_zero_bit(ir_core_dev_number,
- IRRCV_NUM_DEVICES);
- /* No free device slots */
- if (devno >= IRRCV_NUM_DEVICES)
- return -ENOMEM;
- } while (test_and_set_bit(devno, ir_core_dev_number));
+ minor = ida_simple_get(&rc_ida, 0, RC_DEV_MAX, GFP_KERNEL);
+ if (minor < 0)
+ return minor;
+
+ dev->minor = minor;
+ dev_set_name(&dev->dev, "rc%u", dev->minor);
+ dev_set_drvdata(&dev->dev, dev);
dev->dev.groups = dev->sysfs_groups;
dev->sysfs_groups[attr++] = &rc_dev_protocol_attr_grp;
@@ -1358,9 +1381,6 @@ int rc_register_device(struct rc_dev *dev)
*/
mutex_lock(&dev->lock);
- dev->devno = devno;
- dev_set_name(&dev->dev, "rc%ld", dev->devno);
- dev_set_drvdata(&dev->dev, dev);
rc = device_add(&dev->dev);
if (rc)
goto out_unlock;
@@ -1423,8 +1443,6 @@ int rc_register_device(struct rc_dev *dev)
if (dev->change_protocol) {
u64 rc_type = (1ll << rc_map->rc_type);
- if (dev->driver_type == RC_DRIVER_IR_RAW)
- rc_type |= RC_BIT_LIRC;
rc = dev->change_protocol(dev, &rc_type);
if (rc < 0)
goto out_raw;
@@ -1433,8 +1451,8 @@ int rc_register_device(struct rc_dev *dev)
mutex_unlock(&dev->lock);
- IR_dprintk(1, "Registered rc%ld (driver: %s, remote: %s, mode %s)\n",
- dev->devno,
+ IR_dprintk(1, "Registered rc%u (driver: %s, remote: %s, mode %s)\n",
+ dev->minor,
dev->driver_name ? dev->driver_name : "unknown",
rc_map->name ? rc_map->name : "unknown",
dev->driver_type == RC_DRIVER_IR_RAW ? "raw" : "cooked");
@@ -1453,7 +1471,7 @@ out_dev:
device_del(&dev->dev);
out_unlock:
mutex_unlock(&dev->lock);
- clear_bit(dev->devno, ir_core_dev_number);
+ ida_simple_remove(&rc_ida, minor);
return rc;
}
EXPORT_SYMBOL_GPL(rc_register_device);
@@ -1465,8 +1483,6 @@ void rc_unregister_device(struct rc_dev *dev)
del_timer_sync(&dev->timer_keyup);
- clear_bit(dev->devno, ir_core_dev_number);
-
if (dev->driver_type == RC_DRIVER_IR_RAW)
ir_raw_event_unregister(dev);
@@ -1479,6 +1495,8 @@ void rc_unregister_device(struct rc_dev *dev)
device_del(&dev->dev);
+ ida_simple_remove(&rc_ida, dev->minor);
+
rc_free_device(dev);
}