Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] rc: add wakeup_protocols sysfs file

Add a wakeup_protocols sysfs file which controls the new
rc_dev::enabled_protocols[RC_FILTER_WAKEUP], which is the mask of
protocols that are used for the wakeup filter.

A new RC driver callback change_wakeup_protocol() is called to change
the wakeup protocol mask.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Reviewed-by: Antti Seppälä <a.seppala@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>

authored by

James Hogan and committed by
Mauro Carvalho Chehab
ab88c66d acff5f24

+90 -38
+21 -2
Documentation/ABI/testing/sysfs-class-rc
··· 61 61 an error. 62 62 This value may be reset to 0 if the current protocol is altered. 63 63 64 + What: /sys/class/rc/rcN/wakeup_protocols 65 + Date: Feb 2014 66 + KernelVersion: 3.15 67 + Contact: Mauro Carvalho Chehab <m.chehab@samsung.com> 68 + Description: 69 + Reading this file returns a list of available protocols to use 70 + for the wakeup filter, something like: 71 + "rc5 rc6 nec jvc [sony]" 72 + The enabled wakeup protocol is shown in [] brackets. 73 + Writing "+proto" will add a protocol to the list of enabled 74 + wakeup protocols. 75 + Writing "-proto" will remove a protocol from the list of enabled 76 + wakeup protocols. 77 + Writing "proto" will use "proto" for wakeup events. 78 + Writing "none" will disable wakeup. 79 + Write fails with EINVAL if an invalid protocol combination or 80 + unknown protocol name is used, or if wakeup is not supported by 81 + the hardware. 82 + 64 83 What: /sys/class/rc/rcN/wakeup_filter 65 84 Date: Jan 2014 66 85 KernelVersion: 3.15 ··· 93 74 scancodes which match the filter will wake the system from e.g. 94 75 suspend to RAM or power off. 95 76 Otherwise the write will fail with an error. 96 - This value may be reset to 0 if the current protocol is altered. 77 + This value may be reset to 0 if the wakeup protocol is altered. 97 78 98 79 What: /sys/class/rc/rcN/wakeup_filter_mask 99 80 Date: Jan 2014 ··· 108 89 scancodes which match the filter will wake the system from e.g. 109 90 suspend to RAM or power off. 110 91 Otherwise the write will fail with an error. 111 - This value may be reset to 0 if the current protocol is altered. 92 + This value may be reset to 0 if the wakeup protocol is altered.
+18 -2
Documentation/DocBook/media/v4l/remote_controllers.xml
··· 102 102 <para>This value may be reset to 0 if the current protocol is altered.</para> 103 103 104 104 </section> 105 + <section id="sys_class_rc_rcN_wakeup_protocols"> 106 + <title>/sys/class/rc/rcN/wakeup_protocols</title> 107 + <para>Reading this file returns a list of available protocols to use for the 108 + wakeup filter, something like:</para> 109 + <para><constant>rc5 rc6 nec jvc [sony]</constant></para> 110 + <para>The enabled wakeup protocol is shown in [] brackets.</para> 111 + <para>Writing "+proto" will add a protocol to the list of enabled wakeup 112 + protocols.</para> 113 + <para>Writing "-proto" will remove a protocol from the list of enabled wakeup 114 + protocols.</para> 115 + <para>Writing "proto" will use "proto" for wakeup events.</para> 116 + <para>Writing "none" will disable wakeup.</para> 117 + <para>Write fails with EINVAL if an invalid protocol combination or unknown 118 + protocol name is used, or if wakeup is not supported by the hardware.</para> 119 + 120 + </section> 105 121 <section id="sys_class_rc_rcN_wakeup_filter"> 106 122 <title>/sys/class/rc/rcN/wakeup_filter</title> 107 123 <para>Sets the scancode wakeup filter expected value. ··· 128 112 scancodes which match the filter will wake the system from e.g. 129 113 suspend to RAM or power off. 130 114 Otherwise the write will fail with an error.</para> 131 - <para>This value may be reset to 0 if the current protocol is altered.</para> 115 + <para>This value may be reset to 0 if the wakeup protocol is altered.</para> 132 116 133 117 </section> 134 118 <section id="sys_class_rc_rcN_wakeup_filter_mask"> ··· 141 125 scancodes which match the filter will wake the system from e.g. 142 126 suspend to RAM or power off. 143 127 Otherwise the write will fail with an error.</para> 144 - <para>This value may be reset to 0 if the current protocol is altered.</para> 128 + <para>This value may be reset to 0 if the wakeup protocol is altered.</para> 145 129 </section> 146 130 </section> 147 131
+48 -34
drivers/media/rc/rc-main.c
··· 803 803 }; 804 804 805 805 /** 806 - * show_protocols() - shows the current IR protocol(s) 806 + * struct rc_filter_attribute - Device attribute relating to a filter type. 807 + * @attr: Device attribute. 808 + * @type: Filter type. 809 + * @mask: false for filter value, true for filter mask. 810 + */ 811 + struct rc_filter_attribute { 812 + struct device_attribute attr; 813 + enum rc_filter_type type; 814 + bool mask; 815 + }; 816 + #define to_rc_filter_attr(a) container_of(a, struct rc_filter_attribute, attr) 817 + 818 + #define RC_PROTO_ATTR(_name, _mode, _show, _store, _type) \ 819 + struct rc_filter_attribute dev_attr_##_name = { \ 820 + .attr = __ATTR(_name, _mode, _show, _store), \ 821 + .type = (_type), \ 822 + } 823 + #define RC_FILTER_ATTR(_name, _mode, _show, _store, _type, _mask) \ 824 + struct rc_filter_attribute dev_attr_##_name = { \ 825 + .attr = __ATTR(_name, _mode, _show, _store), \ 826 + .type = (_type), \ 827 + .mask = (_mask), \ 828 + } 829 + 830 + /** 831 + * show_protocols() - shows the current/wakeup IR protocol(s) 807 832 * @device: the device descriptor 808 833 * @mattr: the device attribute struct (unused) 809 834 * @buf: a pointer to the output buffer 810 835 * 811 836 * This routine is a callback routine for input read the IR protocol type(s). 812 - * it is trigged by reading /sys/class/rc/rc?/protocols. 837 + * it is trigged by reading /sys/class/rc/rc?/[wakeup_]protocols. 813 838 * It returns the protocol names of supported protocols. 814 839 * Enabled protocols are printed in brackets. 815 840 * ··· 845 820 struct device_attribute *mattr, char *buf) 846 821 { 847 822 struct rc_dev *dev = to_rc_dev(device); 823 + struct rc_filter_attribute *fattr = to_rc_filter_attr(mattr); 848 824 u64 allowed, enabled; 849 825 char *tmp = buf; 850 826 int i; ··· 856 830 857 831 mutex_lock(&dev->lock); 858 832 859 - enabled = dev->enabled_protocols[RC_FILTER_NORMAL]; 860 - if (dev->driver_type == RC_DRIVER_SCANCODE) 861 - allowed = dev->allowed_protocols[RC_FILTER_NORMAL]; 833 + enabled = dev->enabled_protocols[fattr->type]; 834 + if (dev->driver_type == RC_DRIVER_SCANCODE || 835 + fattr->type == RC_FILTER_WAKEUP) 836 + allowed = dev->allowed_protocols[fattr->type]; 862 837 else if (dev->raw) 863 838 allowed = ir_raw_get_allowed_protocols(); 864 839 else { ··· 891 864 } 892 865 893 866 /** 894 - * store_protocols() - changes the current IR protocol(s) 867 + * store_protocols() - changes the current/wakeup IR protocol(s) 895 868 * @device: the device descriptor 896 869 * @mattr: the device attribute struct (unused) 897 870 * @buf: a pointer to the input buffer 898 871 * @len: length of the input buffer 899 872 * 900 873 * This routine is for changing the IR protocol type. 901 - * It is trigged by writing to /sys/class/rc/rc?/protocols. 874 + * It is trigged by writing to /sys/class/rc/rc?/[wakeup_]protocols. 902 875 * Writing "+proto" will add a protocol to the list of enabled protocols. 903 876 * Writing "-proto" will remove a protocol from the list of enabled protocols. 904 877 * Writing "proto" will enable only "proto". ··· 915 888 size_t len) 916 889 { 917 890 struct rc_dev *dev = to_rc_dev(device); 891 + struct rc_filter_attribute *fattr = to_rc_filter_attr(mattr); 918 892 bool enable, disable; 919 893 const char *tmp; 920 894 u64 type; 921 895 u64 mask; 922 896 int rc, i, count = 0; 923 897 ssize_t ret; 898 + int (*change_protocol)(struct rc_dev *dev, u64 *rc_type); 924 899 925 900 /* Device is being removed */ 926 901 if (!dev) ··· 935 906 ret = -EINVAL; 936 907 goto out; 937 908 } 938 - type = dev->enabled_protocols[RC_FILTER_NORMAL]; 909 + type = dev->enabled_protocols[fattr->type]; 939 910 940 911 while ((tmp = strsep((char **) &data, " \n")) != NULL) { 941 912 if (!*tmp) ··· 983 954 goto out; 984 955 } 985 956 986 - if (dev->change_protocol) { 987 - rc = dev->change_protocol(dev, &type); 957 + change_protocol = (fattr->type == RC_FILTER_NORMAL) 958 + ? dev->change_protocol : dev->change_wakeup_protocol; 959 + if (change_protocol) { 960 + rc = change_protocol(dev, &type); 988 961 if (rc < 0) { 989 962 IR_dprintk(1, "Error setting protocols to 0x%llx\n", 990 963 (long long)type); ··· 995 964 } 996 965 } 997 966 998 - dev->enabled_protocols[RC_FILTER_NORMAL] = type; 967 + dev->enabled_protocols[fattr->type] = type; 999 968 IR_dprintk(1, "Current protocol(s): 0x%llx\n", 1000 969 (long long)type); 1001 970 ··· 1005 974 mutex_unlock(&dev->lock); 1006 975 return ret; 1007 976 } 1008 - 1009 - /** 1010 - * struct rc_filter_attribute - Device attribute relating to a filter type. 1011 - * @attr: Device attribute. 1012 - * @type: Filter type. 1013 - * @mask: false for filter value, true for filter mask. 1014 - */ 1015 - struct rc_filter_attribute { 1016 - struct device_attribute attr; 1017 - enum rc_filter_type type; 1018 - bool mask; 1019 - }; 1020 - #define to_rc_filter_attr(a) container_of(a, struct rc_filter_attribute, attr) 1021 - 1022 - #define RC_FILTER_ATTR(_name, _mode, _show, _store, _type, _mask) \ 1023 - struct rc_filter_attribute dev_attr_##_name = { \ 1024 - .attr = __ATTR(_name, _mode, _show, _store), \ 1025 - .type = (_type), \ 1026 - .mask = (_mask), \ 1027 - } 1028 977 1029 978 /** 1030 979 * show_filter() - shows the current scancode filter value or mask ··· 1139 1128 /* 1140 1129 * Static device attribute struct with the sysfs attributes for IR's 1141 1130 */ 1142 - static DEVICE_ATTR(protocols, S_IRUGO | S_IWUSR, 1143 - show_protocols, store_protocols); 1131 + static RC_PROTO_ATTR(protocols, S_IRUGO | S_IWUSR, 1132 + show_protocols, store_protocols, RC_FILTER_NORMAL); 1133 + static RC_PROTO_ATTR(wakeup_protocols, S_IRUGO | S_IWUSR, 1134 + show_protocols, store_protocols, RC_FILTER_WAKEUP); 1144 1135 static RC_FILTER_ATTR(filter, S_IRUGO|S_IWUSR, 1145 1136 show_filter, store_filter, RC_FILTER_NORMAL, false); 1146 1137 static RC_FILTER_ATTR(filter_mask, S_IRUGO|S_IWUSR, ··· 1153 1140 show_filter, store_filter, RC_FILTER_WAKEUP, true); 1154 1141 1155 1142 static struct attribute *rc_dev_attrs[] = { 1156 - &dev_attr_protocols.attr, 1143 + &dev_attr_protocols.attr.attr, 1144 + &dev_attr_wakeup_protocols.attr.attr, 1157 1145 &dev_attr_filter.attr.attr, 1158 1146 &dev_attr_filter_mask.attr.attr, 1159 1147 &dev_attr_wakeup_filter.attr.attr,
+3
include/media/rc-core.h
··· 97 97 * @tx_resolution: resolution (in ns) of output sampler 98 98 * @scancode_filters: scancode filters (indexed by enum rc_filter_type) 99 99 * @change_protocol: allow changing the protocol used on hardware decoders 100 + * @change_wakeup_protocol: allow changing the protocol used for wakeup 101 + * filtering 100 102 * @open: callback to allow drivers to enable polling/irq when IR input device 101 103 * is opened. 102 104 * @close: callback to allow drivers to disable polling/irq when IR input device ··· 147 145 u32 tx_resolution; 148 146 struct rc_scancode_filter scancode_filters[RC_FILTER_MAX]; 149 147 int (*change_protocol)(struct rc_dev *dev, u64 *rc_type); 148 + int (*change_wakeup_protocol)(struct rc_dev *dev, u64 *rc_type); 150 149 int (*open)(struct rc_dev *dev); 151 150 void (*close)(struct rc_dev *dev); 152 151 int (*s_tx_mask)(struct rc_dev *dev, u32 mask);