Skip to content

Commit 650ae67

Browse files
William Breathitt Graygregkh
authored andcommitted
counter: Introduce the Signal polarity component
The Signal polarity component represents the active level of a respective Signal. There are two possible states: positive (rising edge) and negative (falling edge); enum counter_signal_polarity represents these states. A convenience macro COUNTER_COMP_POLARITY() is provided for driver authors to declare a Signal polarity component. Cc: Julien Panis <[email protected]> Link: https://lore.kernel.org/r/8f47d6e1db71a11bb1e2666f8e2a6e9d256d4131.1664204990.git.william.gray@linaro.org/ Signed-off-by: William Breathitt Gray <[email protected]> Link: https://lore.kernel.org/r/b6e53438badcb6318997d13dd2fc052f97d808ac.1664318353.git.william.gray@linaro.org Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7bbf842 commit 650ae67

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed

Documentation/ABI/testing/sysfs-bus-counter

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ What: /sys/bus/counter/devices/counterX/signalY/cable_fault_component_id
217217
What: /sys/bus/counter/devices/counterX/signalY/cable_fault_enable_component_id
218218
What: /sys/bus/counter/devices/counterX/signalY/filter_clock_prescaler_component_id
219219
What: /sys/bus/counter/devices/counterX/signalY/index_polarity_component_id
220+
What: /sys/bus/counter/devices/counterX/signalY/polarity_component_id
220221
What: /sys/bus/counter/devices/counterX/signalY/synchronous_mode_component_id
221222
KernelVersion: 5.16
222223
@@ -303,6 +304,19 @@ Description:
303304
Discrete set of available values for the respective Signal Y
304305
configuration are listed in this file.
305306

307+
What: /sys/bus/counter/devices/counterX/signalY/polarity
308+
KernelVersion: 6.1
309+
310+
Description:
311+
Active level of Signal Y. The following polarity values are
312+
available:
313+
314+
positive:
315+
Signal high state considered active level (rising edge).
316+
317+
negative:
318+
Signal low state considered active level (falling edge).
319+
306320
What: /sys/bus/counter/devices/counterX/signalY/name
307321
KernelVersion: 5.2
308322

drivers/counter/counter-chrdev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ static int counter_get_data(struct counter_device *const counter,
487487
case COUNTER_COMP_ENUM:
488488
case COUNTER_COMP_COUNT_DIRECTION:
489489
case COUNTER_COMP_COUNT_MODE:
490+
case COUNTER_COMP_SIGNAL_POLARITY:
490491
switch (comp_node->component.scope) {
491492
case COUNTER_SCOPE_DEVICE:
492493
ret = comp->device_u32_read(counter, &value_u32);

drivers/counter/counter-sysfs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ static const char *const counter_count_mode_str[] = {
9191
[COUNTER_COUNT_MODE_MODULO_N] = "modulo-n"
9292
};
9393

94+
static const char *const counter_signal_polarity_str[] = {
95+
[COUNTER_SIGNAL_POLARITY_POSITIVE] = "positive",
96+
[COUNTER_SIGNAL_POLARITY_NEGATIVE] = "negative"
97+
};
98+
9499
static ssize_t counter_comp_u8_show(struct device *dev,
95100
struct device_attribute *attr, char *buf)
96101
{
@@ -201,6 +206,8 @@ static ssize_t counter_comp_u32_show(struct device *dev,
201206
return sysfs_emit(buf, "%s\n", counter_count_direction_str[data]);
202207
case COUNTER_COMP_COUNT_MODE:
203208
return sysfs_emit(buf, "%s\n", counter_count_mode_str[data]);
209+
case COUNTER_COMP_SIGNAL_POLARITY:
210+
return sysfs_emit(buf, "%s\n", counter_signal_polarity_str[data]);
204211
default:
205212
return sysfs_emit(buf, "%u\n", (unsigned int)data);
206213
}
@@ -252,6 +259,10 @@ static ssize_t counter_comp_u32_store(struct device *dev,
252259
err = counter_find_enum(&data, avail->enums, avail->num_items,
253260
buf, counter_count_mode_str);
254261
break;
262+
case COUNTER_COMP_SIGNAL_POLARITY:
263+
err = counter_find_enum(&data, avail->enums, avail->num_items,
264+
buf, counter_signal_polarity_str);
265+
break;
255266
default:
256267
err = kstrtou32(buf, 0, &data);
257268
break;
@@ -469,6 +480,7 @@ static int counter_attr_create(struct device *const dev,
469480
case COUNTER_COMP_ENUM:
470481
case COUNTER_COMP_COUNT_DIRECTION:
471482
case COUNTER_COMP_COUNT_MODE:
483+
case COUNTER_COMP_SIGNAL_POLARITY:
472484
if (comp->device_u32_read) {
473485
dev_attr->attr.mode |= 0444;
474486
dev_attr->show = counter_comp_u32_show;

include/linux/counter.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ enum counter_comp_type {
3131
COUNTER_COMP_ENUM,
3232
COUNTER_COMP_COUNT_DIRECTION,
3333
COUNTER_COMP_COUNT_MODE,
34+
COUNTER_COMP_SIGNAL_POLARITY,
3435
};
3536

3637
/**
@@ -477,6 +478,15 @@ struct counter_available {
477478
#define COUNTER_COMP_FLOOR(_read, _write) \
478479
COUNTER_COMP_COUNT_U64("floor", _read, _write)
479480

481+
#define COUNTER_COMP_POLARITY(_read, _write, _available) \
482+
{ \
483+
.type = COUNTER_COMP_SIGNAL_POLARITY, \
484+
.name = "polarity", \
485+
.signal_u32_read = (_read), \
486+
.signal_u32_write = (_write), \
487+
.priv = &(_available), \
488+
}
489+
480490
#define COUNTER_COMP_PRESET(_read, _write) \
481491
COUNTER_COMP_COUNT_U64("preset", _read, _write)
482492

include/uapi/linux/counter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,10 @@ enum counter_synapse_action {
153153
COUNTER_SYNAPSE_ACTION_BOTH_EDGES,
154154
};
155155

156+
/* Signal polarity values */
157+
enum counter_signal_polarity {
158+
COUNTER_SIGNAL_POLARITY_POSITIVE,
159+
COUNTER_SIGNAL_POLARITY_NEGATIVE,
160+
};
161+
156162
#endif /* _UAPI_COUNTER_H_ */

0 commit comments

Comments
 (0)