Commit 650ae67b authored by William Breathitt Gray's avatar William Breathitt Gray Committed by Greg Kroah-Hartman

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 <jpanis@baylibre.com>
Link: https://lore.kernel.org/r/8f47d6e1db71a11bb1e2666f8e2a6e9d256d4131.1664204990.git.william.gray@linaro.org/Signed-off-by: default avatarWilliam Breathitt Gray <william.gray@linaro.org>
Link: https://lore.kernel.org/r/b6e53438badcb6318997d13dd2fc052f97d808ac.1664318353.git.william.gray@linaro.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7bbf842c
...@@ -217,6 +217,7 @@ What: /sys/bus/counter/devices/counterX/signalY/cable_fault_component_id ...@@ -217,6 +217,7 @@ What: /sys/bus/counter/devices/counterX/signalY/cable_fault_component_id
What: /sys/bus/counter/devices/counterX/signalY/cable_fault_enable_component_id What: /sys/bus/counter/devices/counterX/signalY/cable_fault_enable_component_id
What: /sys/bus/counter/devices/counterX/signalY/filter_clock_prescaler_component_id What: /sys/bus/counter/devices/counterX/signalY/filter_clock_prescaler_component_id
What: /sys/bus/counter/devices/counterX/signalY/index_polarity_component_id What: /sys/bus/counter/devices/counterX/signalY/index_polarity_component_id
What: /sys/bus/counter/devices/counterX/signalY/polarity_component_id
What: /sys/bus/counter/devices/counterX/signalY/synchronous_mode_component_id What: /sys/bus/counter/devices/counterX/signalY/synchronous_mode_component_id
KernelVersion: 5.16 KernelVersion: 5.16
Contact: linux-iio@vger.kernel.org Contact: linux-iio@vger.kernel.org
...@@ -303,6 +304,19 @@ Description: ...@@ -303,6 +304,19 @@ Description:
Discrete set of available values for the respective Signal Y Discrete set of available values for the respective Signal Y
configuration are listed in this file. configuration are listed in this file.
What: /sys/bus/counter/devices/counterX/signalY/polarity
KernelVersion: 6.1
Contact: linux-iio@vger.kernel.org
Description:
Active level of Signal Y. The following polarity values are
available:
positive:
Signal high state considered active level (rising edge).
negative:
Signal low state considered active level (falling edge).
What: /sys/bus/counter/devices/counterX/signalY/name What: /sys/bus/counter/devices/counterX/signalY/name
KernelVersion: 5.2 KernelVersion: 5.2
Contact: linux-iio@vger.kernel.org Contact: linux-iio@vger.kernel.org
......
...@@ -487,6 +487,7 @@ static int counter_get_data(struct counter_device *const counter, ...@@ -487,6 +487,7 @@ static int counter_get_data(struct counter_device *const counter,
case COUNTER_COMP_ENUM: case COUNTER_COMP_ENUM:
case COUNTER_COMP_COUNT_DIRECTION: case COUNTER_COMP_COUNT_DIRECTION:
case COUNTER_COMP_COUNT_MODE: case COUNTER_COMP_COUNT_MODE:
case COUNTER_COMP_SIGNAL_POLARITY:
switch (comp_node->component.scope) { switch (comp_node->component.scope) {
case COUNTER_SCOPE_DEVICE: case COUNTER_SCOPE_DEVICE:
ret = comp->device_u32_read(counter, &value_u32); ret = comp->device_u32_read(counter, &value_u32);
......
...@@ -91,6 +91,11 @@ static const char *const counter_count_mode_str[] = { ...@@ -91,6 +91,11 @@ static const char *const counter_count_mode_str[] = {
[COUNTER_COUNT_MODE_MODULO_N] = "modulo-n" [COUNTER_COUNT_MODE_MODULO_N] = "modulo-n"
}; };
static const char *const counter_signal_polarity_str[] = {
[COUNTER_SIGNAL_POLARITY_POSITIVE] = "positive",
[COUNTER_SIGNAL_POLARITY_NEGATIVE] = "negative"
};
static ssize_t counter_comp_u8_show(struct device *dev, static ssize_t counter_comp_u8_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
...@@ -201,6 +206,8 @@ static ssize_t counter_comp_u32_show(struct device *dev, ...@@ -201,6 +206,8 @@ static ssize_t counter_comp_u32_show(struct device *dev,
return sysfs_emit(buf, "%s\n", counter_count_direction_str[data]); return sysfs_emit(buf, "%s\n", counter_count_direction_str[data]);
case COUNTER_COMP_COUNT_MODE: case COUNTER_COMP_COUNT_MODE:
return sysfs_emit(buf, "%s\n", counter_count_mode_str[data]); return sysfs_emit(buf, "%s\n", counter_count_mode_str[data]);
case COUNTER_COMP_SIGNAL_POLARITY:
return sysfs_emit(buf, "%s\n", counter_signal_polarity_str[data]);
default: default:
return sysfs_emit(buf, "%u\n", (unsigned int)data); return sysfs_emit(buf, "%u\n", (unsigned int)data);
} }
...@@ -252,6 +259,10 @@ static ssize_t counter_comp_u32_store(struct device *dev, ...@@ -252,6 +259,10 @@ static ssize_t counter_comp_u32_store(struct device *dev,
err = counter_find_enum(&data, avail->enums, avail->num_items, err = counter_find_enum(&data, avail->enums, avail->num_items,
buf, counter_count_mode_str); buf, counter_count_mode_str);
break; break;
case COUNTER_COMP_SIGNAL_POLARITY:
err = counter_find_enum(&data, avail->enums, avail->num_items,
buf, counter_signal_polarity_str);
break;
default: default:
err = kstrtou32(buf, 0, &data); err = kstrtou32(buf, 0, &data);
break; break;
...@@ -469,6 +480,7 @@ static int counter_attr_create(struct device *const dev, ...@@ -469,6 +480,7 @@ static int counter_attr_create(struct device *const dev,
case COUNTER_COMP_ENUM: case COUNTER_COMP_ENUM:
case COUNTER_COMP_COUNT_DIRECTION: case COUNTER_COMP_COUNT_DIRECTION:
case COUNTER_COMP_COUNT_MODE: case COUNTER_COMP_COUNT_MODE:
case COUNTER_COMP_SIGNAL_POLARITY:
if (comp->device_u32_read) { if (comp->device_u32_read) {
dev_attr->attr.mode |= 0444; dev_attr->attr.mode |= 0444;
dev_attr->show = counter_comp_u32_show; dev_attr->show = counter_comp_u32_show;
......
...@@ -31,6 +31,7 @@ enum counter_comp_type { ...@@ -31,6 +31,7 @@ enum counter_comp_type {
COUNTER_COMP_ENUM, COUNTER_COMP_ENUM,
COUNTER_COMP_COUNT_DIRECTION, COUNTER_COMP_COUNT_DIRECTION,
COUNTER_COMP_COUNT_MODE, COUNTER_COMP_COUNT_MODE,
COUNTER_COMP_SIGNAL_POLARITY,
}; };
/** /**
...@@ -477,6 +478,15 @@ struct counter_available { ...@@ -477,6 +478,15 @@ struct counter_available {
#define COUNTER_COMP_FLOOR(_read, _write) \ #define COUNTER_COMP_FLOOR(_read, _write) \
COUNTER_COMP_COUNT_U64("floor", _read, _write) COUNTER_COMP_COUNT_U64("floor", _read, _write)
#define COUNTER_COMP_POLARITY(_read, _write, _available) \
{ \
.type = COUNTER_COMP_SIGNAL_POLARITY, \
.name = "polarity", \
.signal_u32_read = (_read), \
.signal_u32_write = (_write), \
.priv = &(_available), \
}
#define COUNTER_COMP_PRESET(_read, _write) \ #define COUNTER_COMP_PRESET(_read, _write) \
COUNTER_COMP_COUNT_U64("preset", _read, _write) COUNTER_COMP_COUNT_U64("preset", _read, _write)
......
...@@ -153,4 +153,10 @@ enum counter_synapse_action { ...@@ -153,4 +153,10 @@ enum counter_synapse_action {
COUNTER_SYNAPSE_ACTION_BOTH_EDGES, COUNTER_SYNAPSE_ACTION_BOTH_EDGES,
}; };
/* Signal polarity values */
enum counter_signal_polarity {
COUNTER_SIGNAL_POLARITY_POSITIVE,
COUNTER_SIGNAL_POLARITY_NEGATIVE,
};
#endif /* _UAPI_COUNTER_H_ */ #endif /* _UAPI_COUNTER_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment