diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-04-08 00:02:49 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-05-19 11:57:02 -0400 |
commit | b320f80a6a02bbf31f7ed6ab3332f7c4ebaaac2c (patch) | |
tree | 56dc5821a102227fc0d7b676dd53425ee9c1d2a9 /drivers | |
parent | 626cf6979e99bf2c642456308bed7bb25a37569b (diff) |
V4L/DVB: ir-core: properly present the supported and current protocols
Hardware decoders have a more limited set of decoders than software ones.
In general, they support just one protocol at a given time, but allow
changing between a few options.
Rename the previous badly named "current_protocol" as just "protocol",
meaning the current protocol(s) accepted by the driver, and
add a "support_protocols" to represent the entire universe of supported
protocols by that specific hardware.
As commented on http://lwn.net/Articles/378884/, the "one file, one value"
rule doesn't fit nor does make much sense for bitmap or enum values. So, the
supported_protocols will enum all supported protocols, and the protocol
will present all active protocols.
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/IR/ir-sysfs.c | 63 |
1 files changed, 44 insertions, 19 deletions
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c index 81eebd8eae5a..e47a4f102637 100644 --- a/drivers/media/IR/ir-sysfs.c +++ b/drivers/media/IR/ir-sysfs.c | |||
@@ -56,13 +56,13 @@ static ssize_t show_protocol(struct device *d, | |||
56 | if (ir_type == IR_TYPE_UNKNOWN) | 56 | if (ir_type == IR_TYPE_UNKNOWN) |
57 | s = "Unknown"; | 57 | s = "Unknown"; |
58 | else if (ir_type == IR_TYPE_RC5) | 58 | else if (ir_type == IR_TYPE_RC5) |
59 | s = "RC-5"; | 59 | s = "rc-5"; |
60 | else if (ir_type == IR_TYPE_PD) | 60 | else if (ir_type == IR_TYPE_PD) |
61 | s = "Pulse/distance"; | 61 | s = "pulse-distance"; |
62 | else if (ir_type == IR_TYPE_NEC) | 62 | else if (ir_type == IR_TYPE_NEC) |
63 | s = "NEC"; | 63 | s = "nec"; |
64 | else | 64 | else |
65 | s = "Other"; | 65 | s = "other"; |
66 | 66 | ||
67 | return sprintf(buf, "%s\n", s); | 67 | return sprintf(buf, "%s\n", s); |
68 | } | 68 | } |
@@ -86,23 +86,22 @@ static ssize_t store_protocol(struct device *d, | |||
86 | size_t len) | 86 | size_t len) |
87 | { | 87 | { |
88 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | 88 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); |
89 | u64 ir_type = IR_TYPE_UNKNOWN; | 89 | u64 ir_type = 0; |
90 | int rc = -EINVAL; | 90 | int rc = -EINVAL; |
91 | unsigned long flags; | 91 | unsigned long flags; |
92 | char *buf; | 92 | char *buf; |
93 | 93 | ||
94 | buf = strsep((char **) &data, "\n"); | 94 | while (buf = strsep((char **) &data, " \n")) { |
95 | 95 | if (!strcasecmp(buf, "rc-5") || !strcasecmp(buf, "rc5")) | |
96 | if (!strcasecmp(buf, "rc-5") || !strcasecmp(buf, "rc5")) | 96 | ir_type |= IR_TYPE_RC5; |
97 | ir_type = IR_TYPE_RC5; | 97 | if (!strcasecmp(buf, "pd") || !strcasecmp(buf, "pulse-distance")) |
98 | else if (!strcasecmp(buf, "pd")) | 98 | ir_type |= IR_TYPE_PD; |
99 | ir_type = IR_TYPE_PD; | 99 | if (!strcasecmp(buf, "nec")) |
100 | else if (!strcasecmp(buf, "nec")) | 100 | ir_type |= IR_TYPE_NEC; |
101 | ir_type = IR_TYPE_NEC; | 101 | } |
102 | 102 | ||
103 | if (ir_type == IR_TYPE_UNKNOWN) { | 103 | if (!ir_type) { |
104 | IR_dprintk(1, "Error setting protocol to %lld\n", | 104 | IR_dprintk(1, "Unknown protocol\n"); |
105 | (long long)ir_type); | ||
106 | return -EINVAL; | 105 | return -EINVAL; |
107 | } | 106 | } |
108 | 107 | ||
@@ -120,12 +119,34 @@ static ssize_t store_protocol(struct device *d, | |||
120 | ir_dev->rc_tab.ir_type = ir_type; | 119 | ir_dev->rc_tab.ir_type = ir_type; |
121 | spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags); | 120 | spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags); |
122 | 121 | ||
123 | IR_dprintk(1, "Current protocol is %lld\n", | 122 | IR_dprintk(1, "Current protocol(s) is(are) %lld\n", |
124 | (long long)ir_type); | 123 | (long long)ir_type); |
125 | 124 | ||
126 | return len; | 125 | return len; |
127 | } | 126 | } |
128 | 127 | ||
128 | static ssize_t show_supported_protocols(struct device *d, | ||
129 | struct device_attribute *mattr, char *buf) | ||
130 | { | ||
131 | char *orgbuf = buf; | ||
132 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | ||
133 | |||
134 | /* FIXME: doesn't support multiple protocols at the same time */ | ||
135 | if (ir_dev->props->allowed_protos == IR_TYPE_UNKNOWN) | ||
136 | buf += sprintf(buf, "unknown "); | ||
137 | if (ir_dev->props->allowed_protos & IR_TYPE_RC5) | ||
138 | buf += sprintf(buf, "rc-5 "); | ||
139 | if (ir_dev->props->allowed_protos & IR_TYPE_PD) | ||
140 | buf += sprintf(buf, "pulse-distance "); | ||
141 | if (ir_dev->props->allowed_protos & IR_TYPE_NEC) | ||
142 | buf += sprintf(buf, "nec "); | ||
143 | if (buf == orgbuf) | ||
144 | buf += sprintf(buf, "other "); | ||
145 | |||
146 | buf += sprintf(buf - 1, "\n"); | ||
147 | |||
148 | return buf - orgbuf; | ||
149 | } | ||
129 | 150 | ||
130 | #define ADD_HOTPLUG_VAR(fmt, val...) \ | 151 | #define ADD_HOTPLUG_VAR(fmt, val...) \ |
131 | do { \ | 152 | do { \ |
@@ -149,11 +170,15 @@ static int ir_dev_uevent(struct device *device, struct kobj_uevent_env *env) | |||
149 | /* | 170 | /* |
150 | * Static device attribute struct with the sysfs attributes for IR's | 171 | * Static device attribute struct with the sysfs attributes for IR's |
151 | */ | 172 | */ |
152 | static DEVICE_ATTR(current_protocol, S_IRUGO | S_IWUSR, | 173 | static DEVICE_ATTR(protocol, S_IRUGO | S_IWUSR, |
153 | show_protocol, store_protocol); | 174 | show_protocol, store_protocol); |
154 | 175 | ||
176 | static DEVICE_ATTR(supported_protocols, S_IRUGO | S_IWUSR, | ||
177 | show_supported_protocols, NULL); | ||
178 | |||
155 | static struct attribute *ir_hw_dev_attrs[] = { | 179 | static struct attribute *ir_hw_dev_attrs[] = { |
156 | &dev_attr_current_protocol.attr, | 180 | &dev_attr_protocol.attr, |
181 | &dev_attr_supported_protocols.attr, | ||
157 | NULL, | 182 | NULL, |
158 | }; | 183 | }; |
159 | 184 | ||