2019-04-02 14:30:40 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Counter driver for the ACCES 104-QUAD-8
|
|
|
|
* Copyright (C) 2016 William Breathitt Gray
|
|
|
|
*
|
|
|
|
* This driver supports the ACCES 104-QUAD-8 and ACCES 104-QUAD-4.
|
|
|
|
*/
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/counter.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/ioport.h>
|
2021-09-29 11:16:06 +08:00
|
|
|
#include <linux/interrupt.h>
|
2019-04-02 14:30:40 +08:00
|
|
|
#include <linux/isa.h>
|
|
|
|
#include <linux/kernel.h>
|
2021-12-21 16:16:48 +08:00
|
|
|
#include <linux/list.h>
|
2019-04-02 14:30:40 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/types.h>
|
2021-09-29 11:16:05 +08:00
|
|
|
#include <linux/spinlock.h>
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
#define QUAD8_EXTENT 32
|
|
|
|
|
|
|
|
static unsigned int base[max_num_isa_dev(QUAD8_EXTENT)];
|
|
|
|
static unsigned int num_quad8;
|
2021-06-09 09:31:08 +08:00
|
|
|
module_param_hw_array(base, uint, ioport, &num_quad8, 0);
|
2019-04-02 14:30:40 +08:00
|
|
|
MODULE_PARM_DESC(base, "ACCES 104-QUAD-8 base addresses");
|
|
|
|
|
2021-09-29 11:16:06 +08:00
|
|
|
static unsigned int irq[max_num_isa_dev(QUAD8_EXTENT)];
|
|
|
|
module_param_hw_array(irq, uint, irq, NULL, 0);
|
|
|
|
MODULE_PARM_DESC(irq, "ACCES 104-QUAD-8 interrupt line numbers");
|
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
#define QUAD8_NUM_COUNTERS 8
|
|
|
|
|
2022-07-15 00:07:14 +08:00
|
|
|
/**
|
|
|
|
* struct channel_reg - channel register structure
|
|
|
|
* @data: Count data
|
|
|
|
* @control: Channel flags and control
|
|
|
|
*/
|
|
|
|
struct channel_reg {
|
|
|
|
u8 data;
|
|
|
|
u8 control;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct quad8_reg - device register structure
|
|
|
|
* @channel: quadrature counter data and control
|
|
|
|
* @interrupt_status: channel interrupt status
|
|
|
|
* @channel_oper: enable/reset counters and interrupt functions
|
|
|
|
* @index_interrupt: enable channel interrupts
|
|
|
|
* @reserved: reserved for Factory Use
|
|
|
|
* @index_input_levels: index signal logical input level
|
|
|
|
* @cable_status: differential encoder cable status
|
|
|
|
*/
|
|
|
|
struct quad8_reg {
|
|
|
|
struct channel_reg channel[QUAD8_NUM_COUNTERS];
|
|
|
|
u8 interrupt_status;
|
|
|
|
u8 channel_oper;
|
|
|
|
u8 index_interrupt;
|
|
|
|
u8 reserved[3];
|
|
|
|
u8 index_input_levels;
|
|
|
|
u8 cable_status;
|
|
|
|
};
|
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
/**
|
2021-01-30 10:37:03 +08:00
|
|
|
* struct quad8 - device private data structure
|
2021-08-09 20:37:26 +08:00
|
|
|
* @lock: lock to prevent clobbering device states during R/W ops
|
2019-04-02 14:30:40 +08:00
|
|
|
* @counter: instance of the counter_device
|
2020-03-02 06:07:19 +08:00
|
|
|
* @fck_prescaler: array of filter clock prescaler configurations
|
2019-04-02 14:30:40 +08:00
|
|
|
* @preset: array of preset values
|
|
|
|
* @count_mode: array of count mode configurations
|
|
|
|
* @quadrature_mode: array of quadrature mode configurations
|
|
|
|
* @quadrature_scale: array of quadrature mode scale configurations
|
|
|
|
* @ab_enable: array of A and B inputs enable configurations
|
|
|
|
* @preset_enable: array of set_to_preset_on_index attribute configurations
|
2021-09-29 11:16:06 +08:00
|
|
|
* @irq_trigger: array of current IRQ trigger function configurations
|
2019-04-02 14:30:40 +08:00
|
|
|
* @synchronous_mode: array of index function synchronous mode configurations
|
|
|
|
* @index_polarity: array of index function polarity configurations
|
2020-03-02 06:07:19 +08:00
|
|
|
* @cable_fault_enable: differential encoder cable status enable configurations
|
2022-07-15 00:07:14 +08:00
|
|
|
* @reg: I/O address offset for the device registers
|
2019-04-02 14:30:40 +08:00
|
|
|
*/
|
2021-01-30 10:37:03 +08:00
|
|
|
struct quad8 {
|
2021-09-29 11:16:05 +08:00
|
|
|
spinlock_t lock;
|
2020-02-23 00:49:58 +08:00
|
|
|
unsigned int fck_prescaler[QUAD8_NUM_COUNTERS];
|
2019-04-02 14:30:40 +08:00
|
|
|
unsigned int preset[QUAD8_NUM_COUNTERS];
|
|
|
|
unsigned int count_mode[QUAD8_NUM_COUNTERS];
|
|
|
|
unsigned int quadrature_mode[QUAD8_NUM_COUNTERS];
|
|
|
|
unsigned int quadrature_scale[QUAD8_NUM_COUNTERS];
|
|
|
|
unsigned int ab_enable[QUAD8_NUM_COUNTERS];
|
|
|
|
unsigned int preset_enable[QUAD8_NUM_COUNTERS];
|
2021-09-29 11:16:06 +08:00
|
|
|
unsigned int irq_trigger[QUAD8_NUM_COUNTERS];
|
2019-04-02 14:30:40 +08:00
|
|
|
unsigned int synchronous_mode[QUAD8_NUM_COUNTERS];
|
|
|
|
unsigned int index_polarity[QUAD8_NUM_COUNTERS];
|
2020-03-02 06:07:19 +08:00
|
|
|
unsigned int cable_fault_enable;
|
2022-07-15 00:07:14 +08:00
|
|
|
struct quad8_reg __iomem *reg;
|
2019-04-02 14:30:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Borrow Toggle flip-flop */
|
|
|
|
#define QUAD8_FLAG_BT BIT(0)
|
|
|
|
/* Carry Toggle flip-flop */
|
|
|
|
#define QUAD8_FLAG_CT BIT(1)
|
|
|
|
/* Error flag */
|
|
|
|
#define QUAD8_FLAG_E BIT(4)
|
|
|
|
/* Up/Down flag */
|
|
|
|
#define QUAD8_FLAG_UD BIT(5)
|
|
|
|
/* Reset and Load Signal Decoders */
|
|
|
|
#define QUAD8_CTR_RLD 0x00
|
|
|
|
/* Counter Mode Register */
|
|
|
|
#define QUAD8_CTR_CMR 0x20
|
|
|
|
/* Input / Output Control Register */
|
|
|
|
#define QUAD8_CTR_IOR 0x40
|
|
|
|
/* Index Control Register */
|
|
|
|
#define QUAD8_CTR_IDR 0x60
|
|
|
|
/* Reset Byte Pointer (three byte data pointer) */
|
|
|
|
#define QUAD8_RLD_RESET_BP 0x01
|
|
|
|
/* Reset Counter */
|
|
|
|
#define QUAD8_RLD_RESET_CNTR 0x02
|
|
|
|
/* Reset Borrow Toggle, Carry Toggle, Compare Toggle, and Sign flags */
|
|
|
|
#define QUAD8_RLD_RESET_FLAGS 0x04
|
|
|
|
/* Reset Error flag */
|
|
|
|
#define QUAD8_RLD_RESET_E 0x06
|
|
|
|
/* Preset Register to Counter */
|
|
|
|
#define QUAD8_RLD_PRESET_CNTR 0x08
|
|
|
|
/* Transfer Counter to Output Latch */
|
|
|
|
#define QUAD8_RLD_CNTR_OUT 0x10
|
2020-02-23 00:49:58 +08:00
|
|
|
/* Transfer Preset Register LSB to FCK Prescaler */
|
|
|
|
#define QUAD8_RLD_PRESET_PSC 0x18
|
2019-04-02 14:30:40 +08:00
|
|
|
#define QUAD8_CHAN_OP_RESET_COUNTERS 0x01
|
2021-09-29 11:16:06 +08:00
|
|
|
#define QUAD8_CHAN_OP_ENABLE_INTERRUPT_FUNC 0x04
|
2019-04-02 14:30:40 +08:00
|
|
|
#define QUAD8_CMR_QUADRATURE_X1 0x08
|
|
|
|
#define QUAD8_CMR_QUADRATURE_X2 0x10
|
|
|
|
#define QUAD8_CMR_QUADRATURE_X4 0x18
|
|
|
|
|
|
|
|
static int quad8_signal_read(struct counter_device *counter,
|
2021-08-03 20:06:14 +08:00
|
|
|
struct counter_signal *signal,
|
|
|
|
enum counter_signal_level *level)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
const struct quad8 *const priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
unsigned int state;
|
|
|
|
|
|
|
|
/* Only Index signal levels can be read */
|
|
|
|
if (signal->id < 16)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2022-07-15 00:07:14 +08:00
|
|
|
state = ioread8(&priv->reg->index_input_levels) & BIT(signal->id - 16);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-08-03 20:06:14 +08:00
|
|
|
*level = (state) ? COUNTER_SIGNAL_LEVEL_HIGH : COUNTER_SIGNAL_LEVEL_LOW;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int quad8_count_read(struct counter_device *counter,
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
struct counter_count *count, u64 *val)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2022-07-15 00:07:14 +08:00
|
|
|
struct channel_reg __iomem *const chan = priv->reg->channel + count->id;
|
2019-04-02 14:30:40 +08:00
|
|
|
unsigned int flags;
|
|
|
|
unsigned int borrow;
|
|
|
|
unsigned int carry;
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2019-04-02 14:30:40 +08:00
|
|
|
int i;
|
|
|
|
|
2022-07-15 00:07:14 +08:00
|
|
|
flags = ioread8(&chan->control);
|
2019-04-02 14:30:40 +08:00
|
|
|
borrow = flags & QUAD8_FLAG_BT;
|
|
|
|
carry = !!(flags & QUAD8_FLAG_CT);
|
|
|
|
|
|
|
|
/* Borrow XOR Carry effectively doubles count range */
|
2019-10-07 04:03:09 +08:00
|
|
|
*val = (unsigned long)(borrow ^ carry) << 24;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
/* Reset Byte Pointer; transfer Counter to Output Latch */
|
2022-07-15 00:07:13 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP | QUAD8_RLD_CNTR_OUT,
|
2022-07-15 00:07:14 +08:00
|
|
|
&chan->control);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
2022-07-15 00:07:14 +08:00
|
|
|
*val |= (unsigned long)ioread8(&chan->data) << (8 * i);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int quad8_count_write(struct counter_device *counter,
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
struct counter_count *count, u64 val)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2022-07-15 00:07:14 +08:00
|
|
|
struct channel_reg __iomem *const chan = priv->reg->channel + count->id;
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2019-04-02 14:30:40 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Only 24-bit values are supported */
|
2019-10-07 04:03:09 +08:00
|
|
|
if (val > 0xFFFFFF)
|
2021-08-03 20:06:13 +08:00
|
|
|
return -ERANGE;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
/* Reset Byte Pointer */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP, &chan->control);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Counter can only be set via Preset Register */
|
|
|
|
for (i = 0; i < 3; i++)
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(val >> (8 * i), &chan->data);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Transfer Preset Register to Counter */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_PRESET_CNTR, &chan->control);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Reset Byte Pointer */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP, &chan->control);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Set Preset Register back to original value */
|
2019-10-07 04:03:09 +08:00
|
|
|
val = priv->preset[count->id];
|
2019-04-02 14:30:40 +08:00
|
|
|
for (i = 0; i < 3; i++)
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(val >> (8 * i), &chan->data);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Reset Borrow, Carry, Compare, and Sign flags */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_RESET_FLAGS, &chan->control);
|
2019-04-02 14:30:40 +08:00
|
|
|
/* Reset Error flag */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_RESET_E, &chan->control);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-03 20:06:15 +08:00
|
|
|
static const enum counter_function quad8_count_functions_list[] = {
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
COUNTER_FUNCTION_PULSE_DIRECTION,
|
|
|
|
COUNTER_FUNCTION_QUADRATURE_X1_A,
|
|
|
|
COUNTER_FUNCTION_QUADRATURE_X2_A,
|
|
|
|
COUNTER_FUNCTION_QUADRATURE_X4,
|
2019-04-02 14:30:40 +08:00
|
|
|
};
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_function_read(struct counter_device *counter,
|
|
|
|
struct counter_count *count,
|
|
|
|
enum counter_function *function)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
const int id = count->id;
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
|
|
|
if (priv->quadrature_mode[id])
|
|
|
|
switch (priv->quadrature_scale[id]) {
|
2019-04-02 14:30:40 +08:00
|
|
|
case 0:
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*function = COUNTER_FUNCTION_QUADRATURE_X1_A;
|
2019-04-02 14:30:40 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*function = COUNTER_FUNCTION_QUADRATURE_X2_A;
|
2019-04-02 14:30:40 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*function = COUNTER_FUNCTION_QUADRATURE_X4;
|
2019-04-02 14:30:40 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*function = COUNTER_FUNCTION_PULSE_DIRECTION;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_function_write(struct counter_device *counter,
|
|
|
|
struct counter_count *count,
|
|
|
|
enum counter_function function)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
const int id = count->id;
|
|
|
|
unsigned int *const quadrature_mode = priv->quadrature_mode + id;
|
|
|
|
unsigned int *const scale = priv->quadrature_scale + id;
|
|
|
|
unsigned int *const synchronous_mode = priv->synchronous_mode + id;
|
2022-07-15 00:07:14 +08:00
|
|
|
u8 __iomem *const control = &priv->reg->channel[id].control;
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2020-03-16 20:49:30 +08:00
|
|
|
unsigned int mode_cfg;
|
|
|
|
unsigned int idr_cfg;
|
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
|
|
|
mode_cfg = priv->count_mode[id] << 1;
|
|
|
|
idr_cfg = priv->index_polarity[id] << 1;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
if (function == COUNTER_FUNCTION_PULSE_DIRECTION) {
|
2019-04-02 14:30:40 +08:00
|
|
|
*quadrature_mode = 0;
|
|
|
|
|
|
|
|
/* Quadrature scaling only available in quadrature mode */
|
|
|
|
*scale = 0;
|
|
|
|
|
|
|
|
/* Synchronous function not supported in non-quadrature mode */
|
|
|
|
if (*synchronous_mode) {
|
|
|
|
*synchronous_mode = 0;
|
|
|
|
/* Disable synchronous function mode */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_IDR | idr_cfg, control);
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*quadrature_mode = 1;
|
|
|
|
|
|
|
|
switch (function) {
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
case COUNTER_FUNCTION_QUADRATURE_X1_A:
|
2019-04-02 14:30:40 +08:00
|
|
|
*scale = 0;
|
|
|
|
mode_cfg |= QUAD8_CMR_QUADRATURE_X1;
|
|
|
|
break;
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
case COUNTER_FUNCTION_QUADRATURE_X2_A:
|
2019-04-02 14:30:40 +08:00
|
|
|
*scale = 1;
|
|
|
|
mode_cfg |= QUAD8_CMR_QUADRATURE_X2;
|
|
|
|
break;
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
case COUNTER_FUNCTION_QUADRATURE_X4:
|
2019-04-02 14:30:40 +08:00
|
|
|
*scale = 2;
|
|
|
|
mode_cfg |= QUAD8_CMR_QUADRATURE_X4;
|
|
|
|
break;
|
2021-08-03 20:06:12 +08:00
|
|
|
default:
|
|
|
|
/* should never reach this path */
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2021-08-03 20:06:12 +08:00
|
|
|
return -EINVAL;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load mode configuration to Counter Mode Register */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_CMR | mode_cfg, control);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_direction_read(struct counter_device *counter,
|
|
|
|
struct counter_count *count,
|
|
|
|
enum counter_count_direction *direction)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
const struct quad8 *const priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
unsigned int ud_flag;
|
2022-07-15 00:07:14 +08:00
|
|
|
u8 __iomem *const flag_addr = &priv->reg->channel[count->id].control;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* U/D flag: nonzero = up, zero = down */
|
2022-07-15 00:07:13 +08:00
|
|
|
ud_flag = ioread8(flag_addr) & QUAD8_FLAG_UD;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
*direction = (ud_flag) ? COUNTER_COUNT_DIRECTION_FORWARD :
|
|
|
|
COUNTER_COUNT_DIRECTION_BACKWARD;
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-06-09 09:31:15 +08:00
|
|
|
static const enum counter_synapse_action quad8_index_actions_list[] = {
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
COUNTER_SYNAPSE_ACTION_NONE,
|
|
|
|
COUNTER_SYNAPSE_ACTION_RISING_EDGE,
|
2019-04-02 14:30:40 +08:00
|
|
|
};
|
|
|
|
|
2021-06-09 09:31:15 +08:00
|
|
|
static const enum counter_synapse_action quad8_synapse_actions_list[] = {
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
COUNTER_SYNAPSE_ACTION_NONE,
|
|
|
|
COUNTER_SYNAPSE_ACTION_RISING_EDGE,
|
|
|
|
COUNTER_SYNAPSE_ACTION_FALLING_EDGE,
|
|
|
|
COUNTER_SYNAPSE_ACTION_BOTH_EDGES,
|
2019-04-02 14:30:40 +08:00
|
|
|
};
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_action_read(struct counter_device *counter,
|
|
|
|
struct counter_count *count,
|
|
|
|
struct counter_synapse *synapse,
|
|
|
|
enum counter_synapse_action *action)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
int err;
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
enum counter_function function;
|
2019-04-02 14:30:40 +08:00
|
|
|
const size_t signal_a_id = count->synapses[0].signal->id;
|
|
|
|
enum counter_count_direction direction;
|
|
|
|
|
|
|
|
/* Handle Index signals */
|
|
|
|
if (synapse->signal->id >= 16) {
|
|
|
|
if (priv->preset_enable[count->id])
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*action = COUNTER_SYNAPSE_ACTION_RISING_EDGE;
|
2019-04-02 14:30:40 +08:00
|
|
|
else
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*action = COUNTER_SYNAPSE_ACTION_NONE;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
err = quad8_function_read(counter, count, &function);
|
2019-04-02 14:30:40 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* Default action mode */
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*action = COUNTER_SYNAPSE_ACTION_NONE;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Determine action mode based on current count function mode */
|
|
|
|
switch (function) {
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
case COUNTER_FUNCTION_PULSE_DIRECTION:
|
2019-04-02 14:30:40 +08:00
|
|
|
if (synapse->signal->id == signal_a_id)
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*action = COUNTER_SYNAPSE_ACTION_RISING_EDGE;
|
2021-08-03 20:06:12 +08:00
|
|
|
return 0;
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
case COUNTER_FUNCTION_QUADRATURE_X1_A:
|
2019-04-02 14:30:40 +08:00
|
|
|
if (synapse->signal->id == signal_a_id) {
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
err = quad8_direction_read(counter, count, &direction);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
if (direction == COUNTER_COUNT_DIRECTION_FORWARD)
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*action = COUNTER_SYNAPSE_ACTION_RISING_EDGE;
|
2019-04-02 14:30:40 +08:00
|
|
|
else
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*action = COUNTER_SYNAPSE_ACTION_FALLING_EDGE;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
2021-08-03 20:06:12 +08:00
|
|
|
return 0;
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
case COUNTER_FUNCTION_QUADRATURE_X2_A:
|
2019-04-02 14:30:40 +08:00
|
|
|
if (synapse->signal->id == signal_a_id)
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES;
|
2021-08-03 20:06:12 +08:00
|
|
|
return 0;
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
case COUNTER_FUNCTION_QUADRATURE_X4:
|
|
|
|
*action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES;
|
2021-08-03 20:06:12 +08:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
/* should never reach this path */
|
|
|
|
return -EINVAL;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-29 11:16:06 +08:00
|
|
|
enum {
|
|
|
|
QUAD8_EVENT_CARRY = 0,
|
|
|
|
QUAD8_EVENT_COMPARE = 1,
|
|
|
|
QUAD8_EVENT_CARRY_BORROW = 2,
|
|
|
|
QUAD8_EVENT_INDEX = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int quad8_events_configure(struct counter_device *counter)
|
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2021-09-29 11:16:06 +08:00
|
|
|
unsigned long irq_enabled = 0;
|
|
|
|
unsigned long irqflags;
|
2021-12-21 16:16:48 +08:00
|
|
|
struct counter_event_node *event_node;
|
|
|
|
unsigned int next_irq_trigger;
|
2021-09-29 11:16:06 +08:00
|
|
|
unsigned long ior_cfg;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
|
|
|
|
2021-12-21 16:16:48 +08:00
|
|
|
list_for_each_entry(event_node, &counter->events_list, l) {
|
|
|
|
switch (event_node->event) {
|
|
|
|
case COUNTER_EVENT_OVERFLOW:
|
|
|
|
next_irq_trigger = QUAD8_EVENT_CARRY;
|
|
|
|
break;
|
|
|
|
case COUNTER_EVENT_THRESHOLD:
|
|
|
|
next_irq_trigger = QUAD8_EVENT_COMPARE;
|
|
|
|
break;
|
|
|
|
case COUNTER_EVENT_OVERFLOW_UNDERFLOW:
|
|
|
|
next_irq_trigger = QUAD8_EVENT_CARRY_BORROW;
|
|
|
|
break;
|
|
|
|
case COUNTER_EVENT_INDEX:
|
|
|
|
next_irq_trigger = QUAD8_EVENT_INDEX;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* should never reach this path */
|
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2021-09-29 11:16:06 +08:00
|
|
|
|
2021-12-21 16:16:48 +08:00
|
|
|
/* Skip configuration if it is the same as previously set */
|
|
|
|
if (priv->irq_trigger[event_node->channel] == next_irq_trigger)
|
|
|
|
continue;
|
2021-09-29 11:16:06 +08:00
|
|
|
|
2021-12-21 16:16:48 +08:00
|
|
|
/* Save new IRQ function configuration */
|
|
|
|
priv->irq_trigger[event_node->channel] = next_irq_trigger;
|
2021-09-29 11:16:06 +08:00
|
|
|
|
2021-12-21 16:16:48 +08:00
|
|
|
/* Load configuration to I/O Control Register */
|
|
|
|
ior_cfg = priv->ab_enable[event_node->channel] |
|
|
|
|
priv->preset_enable[event_node->channel] << 1 |
|
|
|
|
priv->irq_trigger[event_node->channel] << 3;
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_IOR | ior_cfg,
|
|
|
|
&priv->reg->channel[event_node->channel].control);
|
2021-09-29 11:16:06 +08:00
|
|
|
|
|
|
|
/* Enable IRQ line */
|
2021-12-21 16:16:48 +08:00
|
|
|
irq_enabled |= BIT(event_node->channel);
|
2021-09-29 11:16:06 +08:00
|
|
|
}
|
|
|
|
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(irq_enabled, &priv->reg->index_interrupt);
|
2021-09-29 11:16:06 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int quad8_watch_validate(struct counter_device *counter,
|
|
|
|
const struct counter_watch *watch)
|
|
|
|
{
|
2021-12-21 16:16:48 +08:00
|
|
|
struct counter_event_node *event_node;
|
2021-09-29 11:16:06 +08:00
|
|
|
|
|
|
|
if (watch->channel > QUAD8_NUM_COUNTERS - 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
switch (watch->event) {
|
|
|
|
case COUNTER_EVENT_OVERFLOW:
|
|
|
|
case COUNTER_EVENT_THRESHOLD:
|
|
|
|
case COUNTER_EVENT_OVERFLOW_UNDERFLOW:
|
|
|
|
case COUNTER_EVENT_INDEX:
|
2021-12-21 16:16:48 +08:00
|
|
|
list_for_each_entry(event_node, &counter->next_events_list, l)
|
|
|
|
if (watch->channel == event_node->channel &&
|
|
|
|
watch->event != event_node->event)
|
|
|
|
return -EINVAL;
|
2021-09-29 11:16:06 +08:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-27 00:48:16 +08:00
|
|
|
static const struct counter_ops quad8_ops = {
|
2019-04-02 14:30:40 +08:00
|
|
|
.signal_read = quad8_signal_read,
|
|
|
|
.count_read = quad8_count_read,
|
|
|
|
.count_write = quad8_count_write,
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
.function_read = quad8_function_read,
|
|
|
|
.function_write = quad8_function_write,
|
2021-09-29 11:16:06 +08:00
|
|
|
.action_read = quad8_action_read,
|
|
|
|
.events_configure = quad8_events_configure,
|
|
|
|
.watch_validate = quad8_watch_validate,
|
2019-04-02 14:30:40 +08:00
|
|
|
};
|
|
|
|
|
2021-01-30 10:37:03 +08:00
|
|
|
static const char *const quad8_index_polarity_modes[] = {
|
|
|
|
"negative",
|
|
|
|
"positive"
|
|
|
|
};
|
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
static int quad8_index_polarity_get(struct counter_device *counter,
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
struct counter_signal *signal,
|
|
|
|
u32 *index_polarity)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
const struct quad8 *const priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
const size_t channel_id = signal->id - 16;
|
|
|
|
|
|
|
|
*index_polarity = priv->index_polarity[channel_id];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int quad8_index_polarity_set(struct counter_device *counter,
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
struct counter_signal *signal,
|
|
|
|
u32 index_polarity)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
const size_t channel_id = signal->id - 16;
|
2022-07-15 00:07:14 +08:00
|
|
|
u8 __iomem *const control = &priv->reg->channel[channel_id].control;
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2020-03-16 20:49:30 +08:00
|
|
|
unsigned int idr_cfg = index_polarity << 1;
|
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
|
|
|
idr_cfg |= priv->synchronous_mode[channel_id];
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
priv->index_polarity[channel_id] = index_polarity;
|
|
|
|
|
|
|
|
/* Load Index Control configuration to Index Control Register */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_IDR | idr_cfg, control);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-30 10:37:03 +08:00
|
|
|
static const char *const quad8_synchronous_modes[] = {
|
|
|
|
"non-synchronous",
|
|
|
|
"synchronous"
|
|
|
|
};
|
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
static int quad8_synchronous_mode_get(struct counter_device *counter,
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
struct counter_signal *signal,
|
|
|
|
u32 *synchronous_mode)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
const struct quad8 *const priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
const size_t channel_id = signal->id - 16;
|
|
|
|
|
|
|
|
*synchronous_mode = priv->synchronous_mode[channel_id];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int quad8_synchronous_mode_set(struct counter_device *counter,
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
struct counter_signal *signal,
|
|
|
|
u32 synchronous_mode)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
const size_t channel_id = signal->id - 16;
|
2022-07-15 00:07:14 +08:00
|
|
|
u8 __iomem *const control = &priv->reg->channel[channel_id].control;
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2020-03-16 20:49:30 +08:00
|
|
|
unsigned int idr_cfg = synchronous_mode;
|
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
|
|
|
idr_cfg |= priv->index_polarity[channel_id] << 1;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Index function must be non-synchronous in non-quadrature mode */
|
2020-03-16 20:49:30 +08:00
|
|
|
if (synchronous_mode && !priv->quadrature_mode[channel_id]) {
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2019-04-02 14:30:40 +08:00
|
|
|
return -EINVAL;
|
2020-03-16 20:49:30 +08:00
|
|
|
}
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
priv->synchronous_mode[channel_id] = synchronous_mode;
|
|
|
|
|
|
|
|
/* Load Index Control configuration to Index Control Register */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_IDR | idr_cfg, control);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_count_floor_read(struct counter_device *counter,
|
|
|
|
struct counter_count *count, u64 *floor)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
|
|
|
/* Only a floor of 0 is supported */
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*floor = 0;
|
|
|
|
|
|
|
|
return 0;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_count_mode_read(struct counter_device *counter,
|
|
|
|
struct counter_count *count,
|
|
|
|
enum counter_count_mode *cnt_mode)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
const struct quad8 *const priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Map 104-QUAD-8 count mode to Generic Counter count mode */
|
|
|
|
switch (priv->count_mode[count->id]) {
|
|
|
|
case 0:
|
|
|
|
*cnt_mode = COUNTER_COUNT_MODE_NORMAL;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
*cnt_mode = COUNTER_COUNT_MODE_RANGE_LIMIT;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
*cnt_mode = COUNTER_COUNT_MODE_NON_RECYCLE;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
*cnt_mode = COUNTER_COUNT_MODE_MODULO_N;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_count_mode_write(struct counter_device *counter,
|
|
|
|
struct counter_count *count,
|
|
|
|
enum counter_count_mode cnt_mode)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
unsigned int count_mode;
|
2019-04-02 14:30:40 +08:00
|
|
|
unsigned int mode_cfg;
|
2022-07-15 00:07:14 +08:00
|
|
|
u8 __iomem *const control = &priv->reg->channel[count->id].control;
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Map Generic Counter count mode to 104-QUAD-8 count mode */
|
|
|
|
switch (cnt_mode) {
|
|
|
|
case COUNTER_COUNT_MODE_NORMAL:
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
count_mode = 0;
|
2019-04-02 14:30:40 +08:00
|
|
|
break;
|
|
|
|
case COUNTER_COUNT_MODE_RANGE_LIMIT:
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
count_mode = 1;
|
2019-04-02 14:30:40 +08:00
|
|
|
break;
|
|
|
|
case COUNTER_COUNT_MODE_NON_RECYCLE:
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
count_mode = 2;
|
2019-04-02 14:30:40 +08:00
|
|
|
break;
|
|
|
|
case COUNTER_COUNT_MODE_MODULO_N:
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
count_mode = 3;
|
2019-04-02 14:30:40 +08:00
|
|
|
break;
|
2021-08-03 20:06:12 +08:00
|
|
|
default:
|
|
|
|
/* should never reach this path */
|
|
|
|
return -EINVAL;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
priv->count_mode[count->id] = count_mode;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Set count mode configuration value */
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
mode_cfg = count_mode << 1;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Add quadrature mode configuration */
|
|
|
|
if (priv->quadrature_mode[count->id])
|
|
|
|
mode_cfg |= (priv->quadrature_scale[count->id] + 1) << 3;
|
|
|
|
|
|
|
|
/* Load mode configuration to Counter Mode Register */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_CMR | mode_cfg, control);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_count_enable_read(struct counter_device *counter,
|
|
|
|
struct counter_count *count, u8 *enable)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
const struct quad8 *const priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*enable = priv->ab_enable[count->id];
|
|
|
|
|
|
|
|
return 0;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_count_enable_write(struct counter_device *counter,
|
|
|
|
struct counter_count *count, u8 enable)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2022-07-15 00:07:14 +08:00
|
|
|
u8 __iomem *const control = &priv->reg->channel[count->id].control;
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2019-04-02 14:30:40 +08:00
|
|
|
unsigned int ior_cfg;
|
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
priv->ab_enable[count->id] = enable;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:06 +08:00
|
|
|
ior_cfg = enable | priv->preset_enable[count->id] << 1 |
|
|
|
|
priv->irq_trigger[count->id] << 3;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Load I/O control configuration */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_IOR | ior_cfg, control);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
return 0;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
2021-01-30 10:37:03 +08:00
|
|
|
static const char *const quad8_noise_error_states[] = {
|
|
|
|
"No excessive noise is present at the count inputs",
|
|
|
|
"Excessive noise is present at the count inputs"
|
|
|
|
};
|
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
static int quad8_error_noise_get(struct counter_device *counter,
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
struct counter_count *count, u32 *noise_error)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
const struct quad8 *const priv = counter_priv(counter);
|
2022-07-15 00:07:14 +08:00
|
|
|
u8 __iomem *const flag_addr = &priv->reg->channel[count->id].control;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2022-07-15 00:07:14 +08:00
|
|
|
*noise_error = !!(ioread8(flag_addr) & QUAD8_FLAG_E);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_count_preset_read(struct counter_device *counter,
|
|
|
|
struct counter_count *count, u64 *preset)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
const struct quad8 *const priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*preset = priv->preset[count->id];
|
|
|
|
|
|
|
|
return 0;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
2021-06-09 09:31:09 +08:00
|
|
|
static void quad8_preset_register_set(struct quad8 *const priv, const int id,
|
|
|
|
const unsigned int preset)
|
2020-03-16 20:49:30 +08:00
|
|
|
{
|
2022-07-15 00:07:14 +08:00
|
|
|
struct channel_reg __iomem *const chan = priv->reg->channel + id;
|
2020-03-16 20:49:30 +08:00
|
|
|
int i;
|
|
|
|
|
2021-01-30 10:37:03 +08:00
|
|
|
priv->preset[id] = preset;
|
2020-03-16 20:49:30 +08:00
|
|
|
|
|
|
|
/* Reset Byte Pointer */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP, &chan->control);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
|
|
|
/* Set Preset Register */
|
|
|
|
for (i = 0; i < 3; i++)
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(preset >> (8 * i), &chan->data);
|
2020-03-16 20:49:30 +08:00
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_count_preset_write(struct counter_device *counter,
|
|
|
|
struct counter_count *count, u64 preset)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Only 24-bit values are supported */
|
|
|
|
if (preset > 0xFFFFFF)
|
2021-08-03 20:06:13 +08:00
|
|
|
return -ERANGE;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2020-03-16 20:49:30 +08:00
|
|
|
quad8_preset_register_set(priv, count->id, preset);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
return 0;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_count_ceiling_read(struct counter_device *counter,
|
|
|
|
struct counter_count *count, u64 *ceiling)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Range Limit and Modulo-N count modes use preset value as ceiling */
|
|
|
|
switch (priv->count_mode[count->id]) {
|
|
|
|
case 1:
|
|
|
|
case 3:
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*ceiling = priv->preset[count->id];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* By default 0x1FFFFFF (25 bits unsigned) is maximum count */
|
|
|
|
*ceiling = 0x1FFFFFF;
|
|
|
|
break;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
return 0;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_count_ceiling_write(struct counter_device *counter,
|
|
|
|
struct counter_count *count, u64 ceiling)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2020-03-16 20:49:30 +08:00
|
|
|
|
|
|
|
/* Only 24-bit values are supported */
|
|
|
|
if (ceiling > 0xFFFFFF)
|
2021-08-03 20:06:13 +08:00
|
|
|
return -ERANGE;
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Range Limit and Modulo-N count modes use preset value as ceiling */
|
|
|
|
switch (priv->count_mode[count->id]) {
|
|
|
|
case 1:
|
|
|
|
case 3:
|
2020-03-16 20:49:30 +08:00
|
|
|
quad8_preset_register_set(priv, count->id, ceiling);
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
return 0;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2021-08-03 20:06:11 +08:00
|
|
|
return -EINVAL;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_count_preset_enable_read(struct counter_device *counter,
|
|
|
|
struct counter_count *count,
|
|
|
|
u8 *preset_enable)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
const struct quad8 *const priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*preset_enable = !priv->preset_enable[count->id];
|
|
|
|
|
|
|
|
return 0;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_count_preset_enable_write(struct counter_device *counter,
|
|
|
|
struct counter_count *count,
|
|
|
|
u8 preset_enable)
|
2019-04-02 14:30:40 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2022-07-15 00:07:14 +08:00
|
|
|
u8 __iomem *const control = &priv->reg->channel[count->id].control;
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2019-04-02 14:30:40 +08:00
|
|
|
unsigned int ior_cfg;
|
|
|
|
|
|
|
|
/* Preset enable is active low in Input/Output Control register */
|
|
|
|
preset_enable = !preset_enable;
|
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
priv->preset_enable[count->id] = preset_enable;
|
|
|
|
|
2021-09-29 11:16:06 +08:00
|
|
|
ior_cfg = priv->ab_enable[count->id] | preset_enable << 1 |
|
|
|
|
priv->irq_trigger[count->id] << 3;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
/* Load I/O control configuration to Input / Output Control Register */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_IOR | ior_cfg, control);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
return 0;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_signal_cable_fault_read(struct counter_device *counter,
|
|
|
|
struct counter_signal *signal,
|
|
|
|
u8 *cable_fault)
|
2020-03-02 06:07:19 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2020-03-02 06:07:19 +08:00
|
|
|
const size_t channel_id = signal->id / 2;
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2020-03-16 20:50:06 +08:00
|
|
|
bool disabled;
|
2020-03-02 06:07:19 +08:00
|
|
|
unsigned int status;
|
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2020-03-16 20:50:06 +08:00
|
|
|
|
|
|
|
disabled = !(priv->cable_fault_enable & BIT(channel_id));
|
|
|
|
|
|
|
|
if (disabled) {
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-02 06:07:19 +08:00
|
|
|
return -EINVAL;
|
2020-03-16 20:50:06 +08:00
|
|
|
}
|
2020-03-02 06:07:19 +08:00
|
|
|
|
|
|
|
/* Logic 0 = cable fault */
|
2022-07-15 00:07:14 +08:00
|
|
|
status = ioread8(&priv->reg->cable_status);
|
2020-03-02 06:07:19 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:50:06 +08:00
|
|
|
|
2020-03-02 06:07:19 +08:00
|
|
|
/* Mask respective channel and invert logic */
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*cable_fault = !(status & BIT(channel_id));
|
2020-03-02 06:07:19 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
return 0;
|
2020-03-02 06:07:19 +08:00
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_signal_cable_fault_enable_read(struct counter_device *counter,
|
|
|
|
struct counter_signal *signal,
|
|
|
|
u8 *enable)
|
2020-03-02 06:07:19 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
const struct quad8 *const priv = counter_priv(counter);
|
2020-03-02 06:07:19 +08:00
|
|
|
const size_t channel_id = signal->id / 2;
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*enable = !!(priv->cable_fault_enable & BIT(channel_id));
|
|
|
|
|
|
|
|
return 0;
|
2020-03-02 06:07:19 +08:00
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_signal_cable_fault_enable_write(struct counter_device *counter,
|
|
|
|
struct counter_signal *signal,
|
|
|
|
u8 enable)
|
2020-03-02 06:07:19 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2020-03-02 06:07:19 +08:00
|
|
|
const size_t channel_id = signal->id / 2;
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2020-03-02 06:07:19 +08:00
|
|
|
unsigned int cable_fault_enable;
|
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2020-03-16 20:50:06 +08:00
|
|
|
|
2020-03-02 06:07:19 +08:00
|
|
|
if (enable)
|
|
|
|
priv->cable_fault_enable |= BIT(channel_id);
|
|
|
|
else
|
|
|
|
priv->cable_fault_enable &= ~BIT(channel_id);
|
|
|
|
|
|
|
|
/* Enable is active low in Differential Encoder Cable Status register */
|
|
|
|
cable_fault_enable = ~priv->cable_fault_enable;
|
|
|
|
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(cable_fault_enable, &priv->reg->cable_status);
|
2020-03-02 06:07:19 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:50:06 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
return 0;
|
2020-03-02 06:07:19 +08:00
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_signal_fck_prescaler_read(struct counter_device *counter,
|
|
|
|
struct counter_signal *signal,
|
|
|
|
u8 *prescaler)
|
2020-02-23 00:49:58 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
const struct quad8 *const priv = counter_priv(counter);
|
2020-02-23 00:49:58 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
*prescaler = priv->fck_prescaler[signal->id / 2];
|
|
|
|
|
|
|
|
return 0;
|
2020-02-23 00:49:58 +08:00
|
|
|
}
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static int quad8_signal_fck_prescaler_write(struct counter_device *counter,
|
|
|
|
struct counter_signal *signal,
|
|
|
|
u8 prescaler)
|
2020-02-23 00:49:58 +08:00
|
|
|
{
|
2021-12-30 23:02:42 +08:00
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2020-02-23 00:49:58 +08:00
|
|
|
const size_t channel_id = signal->id / 2;
|
2022-07-15 00:07:14 +08:00
|
|
|
struct channel_reg __iomem *const chan = priv->reg->channel + channel_id;
|
2021-09-29 11:16:05 +08:00
|
|
|
unsigned long irqflags;
|
2020-02-23 00:49:58 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, irqflags);
|
2020-03-16 20:50:46 +08:00
|
|
|
|
2020-02-23 00:49:58 +08:00
|
|
|
priv->fck_prescaler[channel_id] = prescaler;
|
|
|
|
|
|
|
|
/* Reset Byte Pointer */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP, &chan->control);
|
2020-02-23 00:49:58 +08:00
|
|
|
|
|
|
|
/* Set filter clock factor */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(prescaler, &chan->data);
|
2022-07-15 00:07:13 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP | QUAD8_RLD_PRESET_PSC,
|
2022-07-15 00:07:14 +08:00
|
|
|
&chan->control);
|
2020-02-23 00:49:58 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, irqflags);
|
2020-03-16 20:50:46 +08:00
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct counter_comp quad8_signal_ext[] = {
|
|
|
|
COUNTER_COMP_SIGNAL_BOOL("cable_fault", quad8_signal_cable_fault_read,
|
|
|
|
NULL),
|
|
|
|
COUNTER_COMP_SIGNAL_BOOL("cable_fault_enable",
|
|
|
|
quad8_signal_cable_fault_enable_read,
|
|
|
|
quad8_signal_cable_fault_enable_write),
|
|
|
|
COUNTER_COMP_SIGNAL_U8("filter_clock_prescaler",
|
|
|
|
quad8_signal_fck_prescaler_read,
|
|
|
|
quad8_signal_fck_prescaler_write)
|
2020-02-23 00:49:58 +08:00
|
|
|
};
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static DEFINE_COUNTER_ENUM(quad8_index_pol_enum, quad8_index_polarity_modes);
|
|
|
|
static DEFINE_COUNTER_ENUM(quad8_synch_mode_enum, quad8_synchronous_modes);
|
|
|
|
|
|
|
|
static struct counter_comp quad8_index_ext[] = {
|
|
|
|
COUNTER_COMP_SIGNAL_ENUM("index_polarity", quad8_index_polarity_get,
|
|
|
|
quad8_index_polarity_set,
|
|
|
|
quad8_index_pol_enum),
|
|
|
|
COUNTER_COMP_SIGNAL_ENUM("synchronous_mode", quad8_synchronous_mode_get,
|
|
|
|
quad8_synchronous_mode_set,
|
|
|
|
quad8_synch_mode_enum),
|
2019-04-02 14:30:40 +08:00
|
|
|
};
|
|
|
|
|
2020-02-23 00:49:58 +08:00
|
|
|
#define QUAD8_QUAD_SIGNAL(_id, _name) { \
|
|
|
|
.id = (_id), \
|
|
|
|
.name = (_name), \
|
|
|
|
.ext = quad8_signal_ext, \
|
|
|
|
.num_ext = ARRAY_SIZE(quad8_signal_ext) \
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define QUAD8_INDEX_SIGNAL(_id, _name) { \
|
|
|
|
.id = (_id), \
|
|
|
|
.name = (_name), \
|
|
|
|
.ext = quad8_index_ext, \
|
|
|
|
.num_ext = ARRAY_SIZE(quad8_index_ext) \
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct counter_signal quad8_signals[] = {
|
|
|
|
QUAD8_QUAD_SIGNAL(0, "Channel 1 Quadrature A"),
|
|
|
|
QUAD8_QUAD_SIGNAL(1, "Channel 1 Quadrature B"),
|
|
|
|
QUAD8_QUAD_SIGNAL(2, "Channel 2 Quadrature A"),
|
|
|
|
QUAD8_QUAD_SIGNAL(3, "Channel 2 Quadrature B"),
|
|
|
|
QUAD8_QUAD_SIGNAL(4, "Channel 3 Quadrature A"),
|
|
|
|
QUAD8_QUAD_SIGNAL(5, "Channel 3 Quadrature B"),
|
|
|
|
QUAD8_QUAD_SIGNAL(6, "Channel 4 Quadrature A"),
|
|
|
|
QUAD8_QUAD_SIGNAL(7, "Channel 4 Quadrature B"),
|
|
|
|
QUAD8_QUAD_SIGNAL(8, "Channel 5 Quadrature A"),
|
|
|
|
QUAD8_QUAD_SIGNAL(9, "Channel 5 Quadrature B"),
|
|
|
|
QUAD8_QUAD_SIGNAL(10, "Channel 6 Quadrature A"),
|
|
|
|
QUAD8_QUAD_SIGNAL(11, "Channel 6 Quadrature B"),
|
|
|
|
QUAD8_QUAD_SIGNAL(12, "Channel 7 Quadrature A"),
|
|
|
|
QUAD8_QUAD_SIGNAL(13, "Channel 7 Quadrature B"),
|
|
|
|
QUAD8_QUAD_SIGNAL(14, "Channel 8 Quadrature A"),
|
|
|
|
QUAD8_QUAD_SIGNAL(15, "Channel 8 Quadrature B"),
|
|
|
|
QUAD8_INDEX_SIGNAL(16, "Channel 1 Index"),
|
|
|
|
QUAD8_INDEX_SIGNAL(17, "Channel 2 Index"),
|
|
|
|
QUAD8_INDEX_SIGNAL(18, "Channel 3 Index"),
|
|
|
|
QUAD8_INDEX_SIGNAL(19, "Channel 4 Index"),
|
|
|
|
QUAD8_INDEX_SIGNAL(20, "Channel 5 Index"),
|
|
|
|
QUAD8_INDEX_SIGNAL(21, "Channel 6 Index"),
|
|
|
|
QUAD8_INDEX_SIGNAL(22, "Channel 7 Index"),
|
|
|
|
QUAD8_INDEX_SIGNAL(23, "Channel 8 Index")
|
|
|
|
};
|
|
|
|
|
|
|
|
#define QUAD8_COUNT_SYNAPSES(_id) { \
|
|
|
|
{ \
|
|
|
|
.actions_list = quad8_synapse_actions_list, \
|
|
|
|
.num_actions = ARRAY_SIZE(quad8_synapse_actions_list), \
|
|
|
|
.signal = quad8_signals + 2 * (_id) \
|
|
|
|
}, \
|
|
|
|
{ \
|
|
|
|
.actions_list = quad8_synapse_actions_list, \
|
|
|
|
.num_actions = ARRAY_SIZE(quad8_synapse_actions_list), \
|
|
|
|
.signal = quad8_signals + 2 * (_id) + 1 \
|
|
|
|
}, \
|
|
|
|
{ \
|
|
|
|
.actions_list = quad8_index_actions_list, \
|
|
|
|
.num_actions = ARRAY_SIZE(quad8_index_actions_list), \
|
|
|
|
.signal = quad8_signals + 2 * (_id) + 16 \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct counter_synapse quad8_count_synapses[][3] = {
|
|
|
|
QUAD8_COUNT_SYNAPSES(0), QUAD8_COUNT_SYNAPSES(1),
|
|
|
|
QUAD8_COUNT_SYNAPSES(2), QUAD8_COUNT_SYNAPSES(3),
|
|
|
|
QUAD8_COUNT_SYNAPSES(4), QUAD8_COUNT_SYNAPSES(5),
|
|
|
|
QUAD8_COUNT_SYNAPSES(6), QUAD8_COUNT_SYNAPSES(7)
|
|
|
|
};
|
|
|
|
|
counter: Internalize sysfs interface code
This is a reimplementation of the Generic Counter driver interface.
There are no modifications to the Counter subsystem userspace interface,
so existing userspace applications should continue to run seamlessly.
The purpose of this patch is to internalize the sysfs interface code
among the various counter drivers into a shared module. Counter drivers
pass and take data natively (i.e. u8, u64, etc.) and the shared counter
module handles the translation between the sysfs interface and the
device drivers. This guarantees a standard userspace interface for all
counter drivers, and helps generalize the Generic Counter driver ABI in
order to support the Generic Counter chrdev interface (introduced in a
subsequent patch) without significant changes to the existing counter
drivers.
Note, Counter device registration is the same as before: drivers
populate a struct counter_device with components and callbacks, then
pass the structure to the devm_counter_register function. However,
what's different now is how the Counter subsystem code handles this
registration internally.
Whereas before callbacks would interact directly with sysfs data, this
interaction is now abstracted and instead callbacks interact with native
C data types. The counter_comp structure forms the basis for Counter
extensions.
The counter-sysfs.c file contains the code to parse through the
counter_device structure and register the requested components and
extensions. Attributes are created and populated based on type, with
respective translation functions to handle the mapping between sysfs and
the counter driver callbacks.
The translation performed for each attribute is straightforward: the
attribute type and data is parsed from the counter_attribute structure,
the respective counter driver read/write callback is called, and sysfs
I/O is handled before or after the driver read/write function is called.
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Kamel Bouhara <kamel.bouhara@bootlin.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Tested-by: David Lechner <david@lechnology.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> # for stm32
Link: https://lore.kernel.org/r/c68b4a1ffb195c1a2f65e8dd5ad7b7c14e79c6ef.1630031207.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2021-08-27 11:47:47 +08:00
|
|
|
static const enum counter_count_mode quad8_cnt_modes[] = {
|
|
|
|
COUNTER_COUNT_MODE_NORMAL,
|
|
|
|
COUNTER_COUNT_MODE_RANGE_LIMIT,
|
|
|
|
COUNTER_COUNT_MODE_NON_RECYCLE,
|
|
|
|
COUNTER_COUNT_MODE_MODULO_N,
|
|
|
|
};
|
|
|
|
|
|
|
|
static DEFINE_COUNTER_AVAILABLE(quad8_count_mode_available, quad8_cnt_modes);
|
|
|
|
|
|
|
|
static DEFINE_COUNTER_ENUM(quad8_error_noise_enum, quad8_noise_error_states);
|
|
|
|
|
|
|
|
static struct counter_comp quad8_count_ext[] = {
|
|
|
|
COUNTER_COMP_CEILING(quad8_count_ceiling_read,
|
|
|
|
quad8_count_ceiling_write),
|
|
|
|
COUNTER_COMP_FLOOR(quad8_count_floor_read, NULL),
|
|
|
|
COUNTER_COMP_COUNT_MODE(quad8_count_mode_read, quad8_count_mode_write,
|
|
|
|
quad8_count_mode_available),
|
|
|
|
COUNTER_COMP_DIRECTION(quad8_direction_read),
|
|
|
|
COUNTER_COMP_ENABLE(quad8_count_enable_read, quad8_count_enable_write),
|
|
|
|
COUNTER_COMP_COUNT_ENUM("error_noise", quad8_error_noise_get, NULL,
|
|
|
|
quad8_error_noise_enum),
|
|
|
|
COUNTER_COMP_PRESET(quad8_count_preset_read, quad8_count_preset_write),
|
|
|
|
COUNTER_COMP_PRESET_ENABLE(quad8_count_preset_enable_read,
|
|
|
|
quad8_count_preset_enable_write),
|
2019-04-02 14:30:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define QUAD8_COUNT(_id, _cntname) { \
|
|
|
|
.id = (_id), \
|
|
|
|
.name = (_cntname), \
|
|
|
|
.functions_list = quad8_count_functions_list, \
|
|
|
|
.num_functions = ARRAY_SIZE(quad8_count_functions_list), \
|
|
|
|
.synapses = quad8_count_synapses[(_id)], \
|
|
|
|
.num_synapses = 2, \
|
|
|
|
.ext = quad8_count_ext, \
|
|
|
|
.num_ext = ARRAY_SIZE(quad8_count_ext) \
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct counter_count quad8_counts[] = {
|
|
|
|
QUAD8_COUNT(0, "Channel 1 Count"),
|
|
|
|
QUAD8_COUNT(1, "Channel 2 Count"),
|
|
|
|
QUAD8_COUNT(2, "Channel 3 Count"),
|
|
|
|
QUAD8_COUNT(3, "Channel 4 Count"),
|
|
|
|
QUAD8_COUNT(4, "Channel 5 Count"),
|
|
|
|
QUAD8_COUNT(5, "Channel 6 Count"),
|
|
|
|
QUAD8_COUNT(6, "Channel 7 Count"),
|
|
|
|
QUAD8_COUNT(7, "Channel 8 Count")
|
|
|
|
};
|
|
|
|
|
2021-09-29 11:16:06 +08:00
|
|
|
static irqreturn_t quad8_irq_handler(int irq, void *private)
|
|
|
|
{
|
2021-12-30 23:02:52 +08:00
|
|
|
struct counter_device *counter = private;
|
|
|
|
struct quad8 *const priv = counter_priv(counter);
|
2021-09-29 11:16:06 +08:00
|
|
|
unsigned long irq_status;
|
|
|
|
unsigned long channel;
|
|
|
|
u8 event;
|
|
|
|
|
2022-07-15 00:07:14 +08:00
|
|
|
irq_status = ioread8(&priv->reg->interrupt_status);
|
2021-09-29 11:16:06 +08:00
|
|
|
if (!irq_status)
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
for_each_set_bit(channel, &irq_status, QUAD8_NUM_COUNTERS) {
|
|
|
|
switch (priv->irq_trigger[channel]) {
|
|
|
|
case QUAD8_EVENT_CARRY:
|
|
|
|
event = COUNTER_EVENT_OVERFLOW;
|
|
|
|
break;
|
|
|
|
case QUAD8_EVENT_COMPARE:
|
|
|
|
event = COUNTER_EVENT_THRESHOLD;
|
|
|
|
break;
|
|
|
|
case QUAD8_EVENT_CARRY_BORROW:
|
|
|
|
event = COUNTER_EVENT_OVERFLOW_UNDERFLOW;
|
|
|
|
break;
|
|
|
|
case QUAD8_EVENT_INDEX:
|
|
|
|
event = COUNTER_EVENT_INDEX;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* should never reach this path */
|
|
|
|
WARN_ONCE(true, "invalid interrupt trigger function %u configured for channel %lu\n",
|
|
|
|
priv->irq_trigger[channel], channel);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-12-30 23:02:52 +08:00
|
|
|
counter_push_event(counter, event, channel);
|
2021-09-29 11:16:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear pending interrupts on device */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CHAN_OP_ENABLE_INTERRUPT_FUNC, &priv->reg->channel_oper);
|
2021-09-29 11:16:06 +08:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2022-07-15 00:07:14 +08:00
|
|
|
static void quad8_init_counter(struct channel_reg __iomem *const chan)
|
2022-07-15 00:07:13 +08:00
|
|
|
{
|
|
|
|
unsigned long i;
|
|
|
|
|
|
|
|
/* Reset Byte Pointer */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP, &chan->control);
|
2022-07-15 00:07:13 +08:00
|
|
|
/* Reset filter clock factor */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(0, &chan->data);
|
2022-07-15 00:07:13 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP | QUAD8_RLD_PRESET_PSC,
|
2022-07-15 00:07:14 +08:00
|
|
|
&chan->control);
|
2022-07-15 00:07:13 +08:00
|
|
|
/* Reset Byte Pointer */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP, &chan->control);
|
2022-07-15 00:07:13 +08:00
|
|
|
/* Reset Preset Register */
|
|
|
|
for (i = 0; i < 3; i++)
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(0x00, &chan->data);
|
2022-07-15 00:07:13 +08:00
|
|
|
/* Reset Borrow, Carry, Compare, and Sign flags */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_RESET_FLAGS, &chan->control);
|
2022-07-15 00:07:13 +08:00
|
|
|
/* Reset Error flag */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_RLD | QUAD8_RLD_RESET_E, &chan->control);
|
2022-07-15 00:07:13 +08:00
|
|
|
/* Binary encoding; Normal count; non-quadrature mode */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_CMR, &chan->control);
|
2022-07-15 00:07:13 +08:00
|
|
|
/* Disable A and B inputs; preset on index; FLG1 as Carry */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_IOR, &chan->control);
|
2022-07-15 00:07:13 +08:00
|
|
|
/* Disable index function; negative index polarity */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CTR_IDR, &chan->control);
|
2022-07-15 00:07:13 +08:00
|
|
|
}
|
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
static int quad8_probe(struct device *dev, unsigned int id)
|
|
|
|
{
|
2021-12-30 23:02:52 +08:00
|
|
|
struct counter_device *counter;
|
2021-01-30 10:37:03 +08:00
|
|
|
struct quad8 *priv;
|
2022-07-15 00:07:13 +08:00
|
|
|
unsigned long i;
|
2021-09-29 11:16:06 +08:00
|
|
|
int err;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
|
|
|
if (!devm_request_region(dev, base[id], QUAD8_EXTENT, dev_name(dev))) {
|
|
|
|
dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n",
|
|
|
|
base[id], base[id] + QUAD8_EXTENT);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2021-12-30 23:02:52 +08:00
|
|
|
counter = devm_counter_alloc(dev, sizeof(*priv));
|
|
|
|
if (!counter)
|
2019-04-02 14:30:40 +08:00
|
|
|
return -ENOMEM;
|
2021-12-30 23:02:52 +08:00
|
|
|
priv = counter_priv(counter);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2022-07-15 00:07:14 +08:00
|
|
|
priv->reg = devm_ioport_map(dev, base[id], QUAD8_EXTENT);
|
|
|
|
if (!priv->reg)
|
2022-07-15 00:07:13 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-04-02 14:30:40 +08:00
|
|
|
/* Initialize Counter device and driver data */
|
2021-12-30 23:02:52 +08:00
|
|
|
counter->name = dev_name(dev);
|
|
|
|
counter->parent = dev;
|
|
|
|
counter->ops = &quad8_ops;
|
|
|
|
counter->counts = quad8_counts;
|
|
|
|
counter->num_counts = ARRAY_SIZE(quad8_counts);
|
|
|
|
counter->signals = quad8_signals;
|
|
|
|
counter->num_signals = ARRAY_SIZE(quad8_signals);
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-09-29 11:16:05 +08:00
|
|
|
spin_lock_init(&priv->lock);
|
2020-03-16 20:49:30 +08:00
|
|
|
|
2021-09-29 11:16:06 +08:00
|
|
|
/* Reset Index/Interrupt Register */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(0x00, &priv->reg->index_interrupt);
|
2019-04-02 14:30:40 +08:00
|
|
|
/* Reset all counters and disable interrupt function */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CHAN_OP_RESET_COUNTERS, &priv->reg->channel_oper);
|
2019-04-02 14:30:40 +08:00
|
|
|
/* Set initial configuration for all counters */
|
2022-07-15 00:07:13 +08:00
|
|
|
for (i = 0; i < QUAD8_NUM_COUNTERS; i++)
|
2022-07-15 00:07:14 +08:00
|
|
|
quad8_init_counter(priv->reg->channel + i);
|
2020-03-02 06:07:19 +08:00
|
|
|
/* Disable Differential Encoder Cable Status for all channels */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(0xFF, &priv->reg->cable_status);
|
2021-09-29 11:16:06 +08:00
|
|
|
/* Enable all counters and enable interrupt function */
|
2022-07-15 00:07:14 +08:00
|
|
|
iowrite8(QUAD8_CHAN_OP_ENABLE_INTERRUPT_FUNC, &priv->reg->channel_oper);
|
2021-09-29 11:16:06 +08:00
|
|
|
|
2022-01-05 17:30:52 +08:00
|
|
|
err = devm_request_irq(&counter->dev, irq[id], quad8_irq_handler,
|
|
|
|
IRQF_SHARED, counter->name, counter);
|
2021-09-29 11:16:06 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
2019-04-02 14:30:40 +08:00
|
|
|
|
2021-12-30 23:02:52 +08:00
|
|
|
err = devm_counter_add(dev, counter);
|
|
|
|
if (err < 0)
|
|
|
|
return dev_err_probe(dev, err, "Failed to add counter\n");
|
|
|
|
|
|
|
|
return 0;
|
2019-04-02 14:30:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct isa_driver quad8_driver = {
|
|
|
|
.probe = quad8_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "104-quad-8"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module_isa_driver(quad8_driver, num_quad8);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>");
|
2021-01-30 10:37:03 +08:00
|
|
|
MODULE_DESCRIPTION("ACCES 104-QUAD-8 driver");
|
2019-04-02 14:30:40 +08:00
|
|
|
MODULE_LICENSE("GPL v2");
|