mirror of
https://github.com/torvalds/linux.git
synced 2026-05-25 23:52:08 +02:00
Counter updates for 6.15
counter: - Introduce the COUNTER_EVENT_DIRECTION_CHANGE event - Introduce the COUNTER_COMP_COMPARE helper macro microchip-tcb-cpature: - Add IRQ handling - Add support for capture extensions - Add support for compare extension ti-eqep: - Add support for reading and detecting changes in direction tools/counter: - Add counter_watch_events executable to .gitignore - Support COUNTER_EVENT_DIRECTION_CHANGE in counter_watch_events tool -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQSNN83d4NIlKPjon7a1SFbKvhIjKwUCZ8+ECgAKCRC1SFbKvhIj K/i+AQDS3TVUcot2C+NsvNKud2hA2Q7IIIsAsorQgSdjnx9wDAD8CfQvuvEr6JhZ WuWxw8L59xJAYlInQjpP89pZQA4g+Ao= =b0Dk -----END PGP SIGNATURE----- Merge tag 'counter-updates-for-6.15' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/wbg/counter into char-misc-next William writes: Counter updates for 6.15 counter: - Introduce the COUNTER_EVENT_DIRECTION_CHANGE event - Introduce the COUNTER_COMP_COMPARE helper macro microchip-tcb-cpature: - Add IRQ handling - Add support for capture extensions - Add support for compare extension ti-eqep: - Add support for reading and detecting changes in direction tools/counter: - Add counter_watch_events executable to .gitignore - Support COUNTER_EVENT_DIRECTION_CHANGE in counter_watch_events tool * tag 'counter-updates-for-6.15' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/wbg/counter: counter: microchip-tcb-capture: Add support for RC Compare counter: Introduce the compare component counter: microchip-tcb-capture: Add capture extensions for registers RA/RB counter: microchip-tcb-capture: Add IRQ handling counter: ti-eqep: add direction support tools/counter: add direction change event to watcher counter: add direction change event tools/counter: gitignore counter_watch_events
This commit is contained in:
commit
34ff7999dc
|
|
@ -34,6 +34,14 @@ Contact: linux-iio@vger.kernel.org
|
|||
Description:
|
||||
Count data of Count Y represented as a string.
|
||||
|
||||
What: /sys/bus/counter/devices/counterX/countY/compare
|
||||
KernelVersion: 6.15
|
||||
Contact: linux-iio@vger.kernel.org
|
||||
Description:
|
||||
If the counter device supports compare registers -- registers
|
||||
used to compare counter channels against a particular count --
|
||||
the compare count for channel Y is provided by this attribute.
|
||||
|
||||
What: /sys/bus/counter/devices/counterX/countY/capture
|
||||
KernelVersion: 6.1
|
||||
Contact: linux-iio@vger.kernel.org
|
||||
|
|
@ -301,6 +309,7 @@ Description:
|
|||
|
||||
What: /sys/bus/counter/devices/counterX/cascade_counts_enable_component_id
|
||||
What: /sys/bus/counter/devices/counterX/external_input_phase_clock_select_component_id
|
||||
What: /sys/bus/counter/devices/counterX/countY/compare_component_id
|
||||
What: /sys/bus/counter/devices/counterX/countY/capture_component_id
|
||||
What: /sys/bus/counter/devices/counterX/countY/ceiling_component_id
|
||||
What: /sys/bus/counter/devices/counterX/countY/floor_component_id
|
||||
|
|
|
|||
|
|
@ -15644,6 +15644,7 @@ L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
|
|||
L: linux-iio@vger.kernel.org
|
||||
S: Maintained
|
||||
F: drivers/counter/microchip-tcb-capture.c
|
||||
F: include/uapi/linux/counter/microchip-tcb-capture.h
|
||||
|
||||
MICROCHIP USB251XB DRIVER
|
||||
M: Richard Leitner <richard.leitner@skidata.com>
|
||||
|
|
|
|||
|
|
@ -6,18 +6,24 @@
|
|||
*/
|
||||
#include <linux/clk.h>
|
||||
#include <linux/counter.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/mfd/syscon.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <uapi/linux/counter/microchip-tcb-capture.h>
|
||||
#include <soc/at91/atmel_tcb.h>
|
||||
|
||||
#define ATMEL_TC_CMR_MASK (ATMEL_TC_LDRA_RISING | ATMEL_TC_LDRB_FALLING | \
|
||||
ATMEL_TC_ETRGEDG_RISING | ATMEL_TC_LDBDIS | \
|
||||
ATMEL_TC_LDBSTOP)
|
||||
|
||||
#define ATMEL_TC_DEF_IRQS (ATMEL_TC_ETRGS | ATMEL_TC_COVFS | \
|
||||
ATMEL_TC_LDRAS | ATMEL_TC_LDRBS | ATMEL_TC_CPCS)
|
||||
|
||||
#define ATMEL_TC_QDEN BIT(8)
|
||||
#define ATMEL_TC_POSEN BIT(9)
|
||||
|
||||
|
|
@ -247,6 +253,90 @@ static int mchp_tc_count_read(struct counter_device *counter,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int mchp_tc_count_cap_read(struct counter_device *counter,
|
||||
struct counter_count *count, size_t idx, u64 *val)
|
||||
{
|
||||
struct mchp_tc_data *const priv = counter_priv(counter);
|
||||
u32 cnt;
|
||||
int ret;
|
||||
|
||||
switch (idx) {
|
||||
case COUNTER_MCHP_EXCAP_RA:
|
||||
ret = regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], RA), &cnt);
|
||||
break;
|
||||
case COUNTER_MCHP_EXCAP_RB:
|
||||
ret = regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], RB), &cnt);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
*val = cnt;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mchp_tc_count_cap_write(struct counter_device *counter,
|
||||
struct counter_count *count, size_t idx, u64 val)
|
||||
{
|
||||
struct mchp_tc_data *const priv = counter_priv(counter);
|
||||
int ret;
|
||||
|
||||
if (val > U32_MAX)
|
||||
return -ERANGE;
|
||||
|
||||
switch (idx) {
|
||||
case COUNTER_MCHP_EXCAP_RA:
|
||||
ret = regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], RA), val);
|
||||
break;
|
||||
case COUNTER_MCHP_EXCAP_RB:
|
||||
ret = regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], RB), val);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mchp_tc_count_compare_read(struct counter_device *counter, struct counter_count *count,
|
||||
u64 *val)
|
||||
{
|
||||
struct mchp_tc_data *const priv = counter_priv(counter);
|
||||
u32 cnt;
|
||||
int ret;
|
||||
|
||||
ret = regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], RC), &cnt);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
*val = cnt;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mchp_tc_count_compare_write(struct counter_device *counter, struct counter_count *count,
|
||||
u64 val)
|
||||
{
|
||||
struct mchp_tc_data *const priv = counter_priv(counter);
|
||||
|
||||
if (val > U32_MAX)
|
||||
return -ERANGE;
|
||||
|
||||
return regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], RC), val);
|
||||
}
|
||||
|
||||
static DEFINE_COUNTER_ARRAY_CAPTURE(mchp_tc_cnt_cap_array, 2);
|
||||
|
||||
static struct counter_comp mchp_tc_count_ext[] = {
|
||||
COUNTER_COMP_ARRAY_CAPTURE(mchp_tc_count_cap_read, mchp_tc_count_cap_write,
|
||||
mchp_tc_cnt_cap_array),
|
||||
COUNTER_COMP_COMPARE(mchp_tc_count_compare_read, mchp_tc_count_compare_write),
|
||||
};
|
||||
|
||||
static struct counter_count mchp_tc_counts[] = {
|
||||
{
|
||||
.id = 0,
|
||||
|
|
@ -255,6 +345,8 @@ static struct counter_count mchp_tc_counts[] = {
|
|||
.num_functions = ARRAY_SIZE(mchp_tc_count_functions),
|
||||
.synapses = mchp_tc_count_synapses,
|
||||
.num_synapses = ARRAY_SIZE(mchp_tc_count_synapses),
|
||||
.ext = mchp_tc_count_ext,
|
||||
.num_ext = ARRAY_SIZE(mchp_tc_count_ext),
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -294,6 +386,65 @@ static const struct of_device_id atmel_tc_of_match[] = {
|
|||
{ /* sentinel */ }
|
||||
};
|
||||
|
||||
static irqreturn_t mchp_tc_isr(int irq, void *dev_id)
|
||||
{
|
||||
struct counter_device *const counter = dev_id;
|
||||
struct mchp_tc_data *const priv = counter_priv(counter);
|
||||
u32 sr, mask;
|
||||
|
||||
regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], SR), &sr);
|
||||
regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], IMR), &mask);
|
||||
|
||||
sr &= mask;
|
||||
if (!(sr & ATMEL_TC_ALL_IRQ))
|
||||
return IRQ_NONE;
|
||||
|
||||
if (sr & ATMEL_TC_ETRGS)
|
||||
counter_push_event(counter, COUNTER_EVENT_CHANGE_OF_STATE,
|
||||
COUNTER_MCHP_EVCHN_CV);
|
||||
if (sr & ATMEL_TC_LDRAS)
|
||||
counter_push_event(counter, COUNTER_EVENT_CAPTURE,
|
||||
COUNTER_MCHP_EVCHN_RA);
|
||||
if (sr & ATMEL_TC_LDRBS)
|
||||
counter_push_event(counter, COUNTER_EVENT_CAPTURE,
|
||||
COUNTER_MCHP_EVCHN_RB);
|
||||
if (sr & ATMEL_TC_CPCS)
|
||||
counter_push_event(counter, COUNTER_EVENT_THRESHOLD,
|
||||
COUNTER_MCHP_EVCHN_RC);
|
||||
if (sr & ATMEL_TC_COVFS)
|
||||
counter_push_event(counter, COUNTER_EVENT_OVERFLOW,
|
||||
COUNTER_MCHP_EVCHN_CV);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static void mchp_tc_irq_remove(void *ptr)
|
||||
{
|
||||
struct mchp_tc_data *priv = ptr;
|
||||
|
||||
regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], IDR), ATMEL_TC_DEF_IRQS);
|
||||
}
|
||||
|
||||
static int mchp_tc_irq_enable(struct counter_device *const counter, int irq)
|
||||
{
|
||||
struct mchp_tc_data *const priv = counter_priv(counter);
|
||||
int ret = devm_request_irq(counter->parent, irq, mchp_tc_isr, 0,
|
||||
dev_name(counter->parent), counter);
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], IER), ATMEL_TC_DEF_IRQS);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = devm_add_action_or_reset(counter->parent, mchp_tc_irq_remove, priv);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mchp_tc_clk_remove(void *ptr)
|
||||
{
|
||||
clk_disable_unprepare((struct clk *)ptr);
|
||||
|
|
@ -378,6 +529,15 @@ static int mchp_tc_probe(struct platform_device *pdev)
|
|||
counter->num_signals = ARRAY_SIZE(mchp_tc_count_signals);
|
||||
counter->signals = mchp_tc_count_signals;
|
||||
|
||||
i = of_irq_get(np->parent, 0);
|
||||
if (i == -EPROBE_DEFER)
|
||||
return -EPROBE_DEFER;
|
||||
if (i > 0) {
|
||||
ret = mchp_tc_irq_enable(counter, i);
|
||||
if (ret < 0)
|
||||
return dev_err_probe(&pdev->dev, ret, "Failed to set up IRQ");
|
||||
}
|
||||
|
||||
ret = devm_counter_add(&pdev->dev, counter);
|
||||
if (ret < 0)
|
||||
return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
|
||||
|
|
|
|||
|
|
@ -107,6 +107,15 @@
|
|||
#define QCLR_PCE BIT(1)
|
||||
#define QCLR_INT BIT(0)
|
||||
|
||||
#define QEPSTS_UPEVNT BIT(7)
|
||||
#define QEPSTS_FDF BIT(6)
|
||||
#define QEPSTS_QDF BIT(5)
|
||||
#define QEPSTS_QDLF BIT(4)
|
||||
#define QEPSTS_COEF BIT(3)
|
||||
#define QEPSTS_CDEF BIT(2)
|
||||
#define QEPSTS_FIMF BIT(1)
|
||||
#define QEPSTS_PCEF BIT(0)
|
||||
|
||||
/* EQEP Inputs */
|
||||
enum {
|
||||
TI_EQEP_SIGNAL_QEPA, /* QEPA/XCLK */
|
||||
|
|
@ -286,6 +295,9 @@ static int ti_eqep_events_configure(struct counter_device *counter)
|
|||
case COUNTER_EVENT_UNDERFLOW:
|
||||
qeint |= QEINT_PCU;
|
||||
break;
|
||||
case COUNTER_EVENT_DIRECTION_CHANGE:
|
||||
qeint |= QEINT_QDC;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -298,6 +310,7 @@ static int ti_eqep_watch_validate(struct counter_device *counter,
|
|||
switch (watch->event) {
|
||||
case COUNTER_EVENT_OVERFLOW:
|
||||
case COUNTER_EVENT_UNDERFLOW:
|
||||
case COUNTER_EVENT_DIRECTION_CHANGE:
|
||||
if (watch->channel != 0)
|
||||
return -EINVAL;
|
||||
|
||||
|
|
@ -368,11 +381,27 @@ static int ti_eqep_position_enable_write(struct counter_device *counter,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int ti_eqep_direction_read(struct counter_device *counter,
|
||||
struct counter_count *count,
|
||||
enum counter_count_direction *direction)
|
||||
{
|
||||
struct ti_eqep_cnt *priv = counter_priv(counter);
|
||||
u32 qepsts;
|
||||
|
||||
regmap_read(priv->regmap16, QEPSTS, &qepsts);
|
||||
|
||||
*direction = (qepsts & QEPSTS_QDF) ? COUNTER_COUNT_DIRECTION_FORWARD
|
||||
: COUNTER_COUNT_DIRECTION_BACKWARD;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct counter_comp ti_eqep_position_ext[] = {
|
||||
COUNTER_COMP_CEILING(ti_eqep_position_ceiling_read,
|
||||
ti_eqep_position_ceiling_write),
|
||||
COUNTER_COMP_ENABLE(ti_eqep_position_enable_read,
|
||||
ti_eqep_position_enable_write),
|
||||
COUNTER_COMP_DIRECTION(ti_eqep_direction_read),
|
||||
};
|
||||
|
||||
static struct counter_signal ti_eqep_signals[] = {
|
||||
|
|
@ -439,6 +468,9 @@ static irqreturn_t ti_eqep_irq_handler(int irq, void *dev_id)
|
|||
if (qflg & QFLG_PCU)
|
||||
counter_push_event(counter, COUNTER_EVENT_UNDERFLOW, 0);
|
||||
|
||||
if (qflg & QFLG_QDC)
|
||||
counter_push_event(counter, COUNTER_EVENT_DIRECTION_CHANGE, 0);
|
||||
|
||||
regmap_write(priv->regmap16, QCLR, qflg);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
|
|
|
|||
|
|
@ -580,6 +580,9 @@ struct counter_array {
|
|||
#define COUNTER_COMP_CEILING(_read, _write) \
|
||||
COUNTER_COMP_COUNT_U64("ceiling", _read, _write)
|
||||
|
||||
#define COUNTER_COMP_COMPARE(_read, _write) \
|
||||
COUNTER_COMP_COUNT_U64("compare", _read, _write)
|
||||
|
||||
#define COUNTER_COMP_COUNT_MODE(_read, _write, _available) \
|
||||
{ \
|
||||
.type = COUNTER_COMP_COUNT_MODE, \
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ enum counter_event_type {
|
|||
COUNTER_EVENT_CHANGE_OF_STATE,
|
||||
/* Count value captured */
|
||||
COUNTER_EVENT_CAPTURE,
|
||||
/* Direction change detected */
|
||||
COUNTER_EVENT_DIRECTION_CHANGE,
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
40
include/uapi/linux/counter/microchip-tcb-capture.h
Normal file
40
include/uapi/linux/counter/microchip-tcb-capture.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
||||
/*
|
||||
* Channel numbers used by the microchip-tcb-capture driver
|
||||
* Copyright (C) 2025 Bence Csókás
|
||||
*/
|
||||
#ifndef _UAPI_COUNTER_MCHP_TCB_H_
|
||||
#define _UAPI_COUNTER_MCHP_TCB_H_
|
||||
|
||||
/*
|
||||
* The driver defines the following components:
|
||||
*
|
||||
* Count 0
|
||||
* \__ Synapse 0 -- Signal 0 (Channel A, i.e. TIOA)
|
||||
* \__ Synapse 1 -- Signal 1 (Channel B, i.e. TIOB)
|
||||
* \__ Extension capture0 (RA register)
|
||||
* \__ Extension capture1 (RB register)
|
||||
*
|
||||
* It also supports the following events:
|
||||
*
|
||||
* Channel 0:
|
||||
* - CV register changed
|
||||
* - CV overflowed
|
||||
* - RA captured
|
||||
* Channel 1:
|
||||
* - RB captured
|
||||
* Channel 2:
|
||||
* - RC compare triggered
|
||||
*/
|
||||
|
||||
/* Capture extensions */
|
||||
#define COUNTER_MCHP_EXCAP_RA 0
|
||||
#define COUNTER_MCHP_EXCAP_RB 1
|
||||
|
||||
/* Event channels */
|
||||
#define COUNTER_MCHP_EVCHN_CV 0
|
||||
#define COUNTER_MCHP_EVCHN_RA 0
|
||||
#define COUNTER_MCHP_EVCHN_RB 1
|
||||
#define COUNTER_MCHP_EVCHN_RC 2
|
||||
|
||||
#endif /* _UAPI_COUNTER_MCHP_TCB_H_ */
|
||||
1
tools/counter/.gitignore
vendored
1
tools/counter/.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
/counter_example
|
||||
/counter_watch_events
|
||||
/include/linux/counter.h
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ static const char * const counter_event_type_name[] = {
|
|||
"COUNTER_EVENT_INDEX",
|
||||
"COUNTER_EVENT_CHANGE_OF_STATE",
|
||||
"COUNTER_EVENT_CAPTURE",
|
||||
"COUNTER_EVENT_DIRECTION_CHANGE",
|
||||
};
|
||||
|
||||
static const char * const counter_component_type_name[] = {
|
||||
|
|
@ -118,6 +119,7 @@ static void print_usage(void)
|
|||
" evt_index (COUNTER_EVENT_INDEX)\n"
|
||||
" evt_change_of_state (COUNTER_EVENT_CHANGE_OF_STATE)\n"
|
||||
" evt_capture (COUNTER_EVENT_CAPTURE)\n"
|
||||
" evt_direction_change (COUNTER_EVENT_DIRECTION_CHANGE)\n"
|
||||
"\n"
|
||||
" chan=<n> channel <n> for this watch [default: 0]\n"
|
||||
" id=<n> component id <n> for this watch [default: 0]\n"
|
||||
|
|
@ -157,6 +159,7 @@ enum {
|
|||
WATCH_EVENT_INDEX,
|
||||
WATCH_EVENT_CHANGE_OF_STATE,
|
||||
WATCH_EVENT_CAPTURE,
|
||||
WATCH_EVENT_DIRECTION_CHANGE,
|
||||
WATCH_CHANNEL,
|
||||
WATCH_ID,
|
||||
WATCH_PARENT,
|
||||
|
|
@ -183,6 +186,7 @@ static char * const counter_watch_subopts[WATCH_SUBOPTS_MAX + 1] = {
|
|||
[WATCH_EVENT_INDEX] = "evt_index",
|
||||
[WATCH_EVENT_CHANGE_OF_STATE] = "evt_change_of_state",
|
||||
[WATCH_EVENT_CAPTURE] = "evt_capture",
|
||||
[WATCH_EVENT_DIRECTION_CHANGE] = "evt_direction_change",
|
||||
/* channel, id, parent */
|
||||
[WATCH_CHANNEL] = "chan",
|
||||
[WATCH_ID] = "id",
|
||||
|
|
@ -278,6 +282,7 @@ int main(int argc, char **argv)
|
|||
case WATCH_EVENT_INDEX:
|
||||
case WATCH_EVENT_CHANGE_OF_STATE:
|
||||
case WATCH_EVENT_CAPTURE:
|
||||
case WATCH_EVENT_DIRECTION_CHANGE:
|
||||
/* match counter_event_type: subtract enum value */
|
||||
ret -= WATCH_EVENT_OVERFLOW;
|
||||
watches[i].event = ret;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user