Commit 34ff7999 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman
Browse files

Merge tag 'counter-updates-for-6.15' of...

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
parents 046cc01b ba27a024
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -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>
+160 −0
Original line number Diff line number Diff line
@@ -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");
+32 −0
Original line number Diff line number Diff line
@@ -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;
+3 −0
Original line number Diff line number Diff line
@@ -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, \
Loading