• William Breathitt Gray's avatar
    counter: Introduce the COUNTER_COMP_ARRAY component type · d2011be1
    William Breathitt Gray authored
    The COUNTER_COMP_ARRAY Counter component type is introduced to enable
    support for Counter array components. With Counter array components,
    exposure for buffers on counter devices can be defined via new Counter
    array component macros. This should simplify code for driver authors who
    would otherwise need to define individual Counter components for each
    array element.
    
    Eight Counter array component macros are introduced::
    
            DEFINE_COUNTER_ARRAY_U64(_name, _length)
            DEFINE_COUNTER_ARRAY_CAPTURE(_name, _length)
            DEFINE_COUNTER_ARRAY_POLARITY(_name, _enums, _length)
            COUNTER_COMP_DEVICE_ARRAY_U64(_name, _read, _write, _array)
            COUNTER_COMP_COUNT_ARRAY_U64(_name, _read, _write, _array)
            COUNTER_COMP_SIGNAL_ARRAY_U64(_name, _read, _write, _array)
            COUNTER_COMP_ARRAY_CAPTURE(_read, _write, _array)
            COUNTER_COMP_ARRAY_POLARITY(_read, _write, _array)
    
    Eight Counter array callbacks are introduced as well::
    
            int (*signal_array_u32_read)(struct counter_device *counter,
                                         struct counter_signal *signal,
                                         size_t idx, u32 *val);
            int (*signal_array_u32_write)(struct counter_device *counter,
                                          struct counter_signal *signal,
                                          size_t idx, u32 val);
            int (*device_array_u64_read)(struct counter_device *counter,
                                         size_t idx, u64 *val);
            int (*count_array_u64_read)(struct counter_device *counter,
                                        struct counter_count *count,
                                        size_t idx, u64 *val);
            int (*signal_array_u64_read)(struct counter_device *counter,
                                         struct counter_signal *signal,
                                         size_t idx, u64 *val);
            int (*device_array_u64_write)(struct counter_device *counter,
                                          size_t idx, u64 val);
            int (*count_array_u64_write)(struct counter_device *counter,
                                         struct counter_count *count,
                                         size_t idx, u64 val);
            int (*signal_array_u64_write)(struct counter_device *counter,
                                          struct counter_signal *signal,
                                          size_t idx, u64 val);
    
    Driver authors can handle reads/writes for an array component by
    receiving an element index via the `idx` parameter and processing the
    respective value via the `val` parameter.
    
    For example, suppose a driver wants to expose a Count's read-only
    capture buffer of four elements using a callback
    `foobar_capture_read()`::
    
            DEFINE_COUNTER_ARRAY_CAPTURE(foobar_capture_array, 4);
            COUNTER_COMP_ARRAY_CAPTURE(foobar_capture_read, NULL,
                                       foobar_capture_array)
    
    Respective sysfs attributes for each array element would appear for the
    respective Count:
    
    * /sys/bus/counter/devices/counterX/countY/capture0
    * /sys/bus/counter/devices/counterX/countY/capture1
    * /sys/bus/counter/devices/counterX/countY/capture2
    * /sys/bus/counter/devices/counterX/countY/capture3
    
    If a user tries to read _capture2_ for example, `idx` will be `2` when
    passed to the `foobar_capture_read()` callback, and thus the driver
    knows which array element to handle.
    
    Counter arrays for polarity elements can be defined in a similar
    manner as u64 elements::
    
            const enum counter_signal_polarity foobar_polarity_states[] = {
                    COUNTER_SIGNAL_POLARITY_POSITIVE,
                    COUNTER_SIGNAL_POLARITY_NEGATIVE,
            };
            DEFINE_COUNTER_ARRAY_POLARITY(foobar_polarity_array,
                                          foobar_polarity_states, 4);
            COUNTER_COMP_ARRAY_POLARITY(foobar_polarity_read,
                                        foobar_polarity_write,
                                        foobar_polarity_array)
    Tested-by: default avatarJulien Panis <jpanis@baylibre.com>
    Link: https://lore.kernel.org/r/5310c22520aeae65b1b74952419f49ac4c8e1ec1.1664204990.git.william.gray@linaro.org/Signed-off-by: default avatarWilliam Breathitt Gray <william.gray@linaro.org>
    Link: https://lore.kernel.org/r/a51fd608704bdfc5a0efa503fc5481df34241e0a.1664318353.git.william.gray@linaro.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    d2011be1
counter-sysfs.c 31.4 KB