aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/rc/rc-main.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2012-10-11 18:11:54 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-10-27 09:49:51 -0400
commitc003ab1bedf028db15b0185b683d5c387204e8f5 (patch)
tree00f608e80e897589492eb2274c46ffb9fde769cf /drivers/media/rc/rc-main.c
parent304ce75dd501d84d33dbca3c544e903f1d3377f7 (diff)
[media] rc-core: add separate defines for protocol bitmaps and numbers
The RC_TYPE_* defines are currently used both where a single protocol is expected and where a bitmap of protocols is expected. Functions like rc_keydown() and functions which add/remove entries to the keytable want a single protocol. Future userspace APIs would also benefit from numeric protocols (rather than bitmap ones). Keytables are smaller if they can use a small(ish) integer rather than a bitmap. Other functions or struct members (e.g. allowed_protos, enabled_protocols, etc) accept multiple protocols and need a bitmap. Using different types reduces the risk of programmer error. Using a protocol enum whereever possible also makes for a more future-proof user-space API as we don't need to worry about a sufficient number of bits being available (e.g. in structs used for ioctl() calls). The use of both a number and a corresponding bit is dalso one in e.g. the input subsystem as well (see all the references to set/clear bit when changing keytables for example). This patch separate the different usages in preparation for upcoming patches. Where a single protocol is expected, enum rc_type is used; where one or more protocol(s) are expected, something like u64 is used. The patch has been rewritten so that the format of the sysfs "protocols" file is no longer altered (at the loss of some detail). The file itself should probably be deprecated in the future though. Signed-off-by: David Härdeman <david@hardeman.nu> Cc: Andy Walls <awalls@md.metrocast.net> Cc: Maxim Levitsky <maximlevitsky@gmail.com> Cc: Antti Palosaari <crope@iki.fi> Cc: Mike Isely <isely@pobox.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/rc/rc-main.c')
-rw-r--r--drivers/media/rc/rc-main.c73
1 files changed, 41 insertions, 32 deletions
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index cabc19c10515..601d1ac1c688 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -725,25 +725,36 @@ static struct class ir_input_class = {
725 .devnode = ir_devnode, 725 .devnode = ir_devnode,
726}; 726};
727 727
728/*
729 * These are the protocol textual descriptions that are
730 * used by the sysfs protocols file. Note that the order
731 * of the entries is relevant.
732 */
728static struct { 733static struct {
729 u64 type; 734 u64 type;
730 char *name; 735 char *name;
731} proto_names[] = { 736} proto_names[] = {
732 { RC_TYPE_UNKNOWN, "unknown" }, 737 { RC_BIT_NONE, "none" },
733 { RC_TYPE_RC5, "rc-5" }, 738 { RC_BIT_OTHER, "other" },
734 { RC_TYPE_NEC, "nec" }, 739 { RC_BIT_UNKNOWN, "unknown" },
735 { RC_TYPE_RC6, "rc-6" }, 740 { RC_BIT_RC5 |
736 { RC_TYPE_JVC, "jvc" }, 741 RC_BIT_RC5X, "rc-5" },
737 { RC_TYPE_SONY, "sony" }, 742 { RC_BIT_NEC, "nec" },
738 { RC_TYPE_RC5_SZ, "rc-5-sz" }, 743 { RC_BIT_RC6_0 |
739 { RC_TYPE_SANYO, "sanyo" }, 744 RC_BIT_RC6_6A_20 |
740 { RC_TYPE_MCE_KBD, "mce_kbd" }, 745 RC_BIT_RC6_6A_24 |
741 { RC_TYPE_LIRC, "lirc" }, 746 RC_BIT_RC6_6A_32 |
742 { RC_TYPE_OTHER, "other" }, 747 RC_BIT_RC6_MCE, "rc-6" },
748 { RC_BIT_JVC, "jvc" },
749 { RC_BIT_SONY12 |
750 RC_BIT_SONY15 |
751 RC_BIT_SONY20, "sony" },
752 { RC_BIT_RC5_SZ, "rc-5-sz" },
753 { RC_BIT_SANYO, "sanyo" },
754 { RC_BIT_MCE_KBD, "mce_kbd" },
755 { RC_BIT_LIRC, "lirc" },
743}; 756};
744 757
745#define PROTO_NONE "none"
746
747/** 758/**
748 * show_protocols() - shows the current IR protocol(s) 759 * show_protocols() - shows the current IR protocol(s)
749 * @device: the device descriptor 760 * @device: the device descriptor
@@ -790,6 +801,9 @@ static ssize_t show_protocols(struct device *device,
790 tmp += sprintf(tmp, "[%s] ", proto_names[i].name); 801 tmp += sprintf(tmp, "[%s] ", proto_names[i].name);
791 else if (allowed & proto_names[i].type) 802 else if (allowed & proto_names[i].type)
792 tmp += sprintf(tmp, "%s ", proto_names[i].name); 803 tmp += sprintf(tmp, "%s ", proto_names[i].name);
804
805 if (allowed & proto_names[i].type)
806 allowed &= ~proto_names[i].type;
793 } 807 }
794 808
795 if (tmp != buf) 809 if (tmp != buf)
@@ -867,26 +881,20 @@ static ssize_t store_protocols(struct device *device,
867 disable = false; 881 disable = false;
868 } 882 }
869 883
870 if (!enable && !disable && !strncasecmp(tmp, PROTO_NONE, sizeof(PROTO_NONE))) { 884 for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
871 tmp += sizeof(PROTO_NONE); 885 if (!strcasecmp(tmp, proto_names[i].name)) {
872 mask = 0; 886 mask = proto_names[i].type;
873 count++; 887 break;
874 } else {
875 for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
876 if (!strcasecmp(tmp, proto_names[i].name)) {
877 tmp += strlen(proto_names[i].name);
878 mask = proto_names[i].type;
879 break;
880 }
881 }
882 if (i == ARRAY_SIZE(proto_names)) {
883 IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
884 ret = -EINVAL;
885 goto out;
886 } 888 }
887 count++;
888 } 889 }
889 890
891 if (i == ARRAY_SIZE(proto_names)) {
892 IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
893 return -EINVAL;
894 }
895
896 count++;
897
890 if (enable) 898 if (enable)
891 type |= mask; 899 type |= mask;
892 else if (disable) 900 else if (disable)
@@ -902,7 +910,7 @@ static ssize_t store_protocols(struct device *device,
902 } 910 }
903 911
904 if (dev->change_protocol) { 912 if (dev->change_protocol) {
905 rc = dev->change_protocol(dev, type); 913 rc = dev->change_protocol(dev, &type);
906 if (rc < 0) { 914 if (rc < 0) {
907 IR_dprintk(1, "Error setting protocols to 0x%llx\n", 915 IR_dprintk(1, "Error setting protocols to 0x%llx\n",
908 (long long)type); 916 (long long)type);
@@ -1117,7 +1125,8 @@ int rc_register_device(struct rc_dev *dev)
1117 } 1125 }
1118 1126
1119 if (dev->change_protocol) { 1127 if (dev->change_protocol) {
1120 rc = dev->change_protocol(dev, rc_map->rc_type); 1128 u64 rc_type = (1 << rc_map->rc_type);
1129 rc = dev->change_protocol(dev, &rc_type);
1121 if (rc < 0) 1130 if (rc < 0)
1122 goto out_raw; 1131 goto out_raw;
1123 } 1132 }