Skip to content

Commit

Permalink
counter: 104-quad-8: Support Filter Clock Prescaler
Browse files Browse the repository at this point in the history
The ACCES 104-QUAD-8 series does active filtering on the quadrature
input signals via the PC/104 bus clock (OSC 14.318 MHz). This patch
exposes the filter clock prescaler available on each channel.

Signed-off-by: William Breathitt Gray <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
vilhelmgray authored and jic23 committed Mar 8, 2020
1 parent 95c72b7 commit de65d05
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Documentation/ABI/testing/sysfs-bus-counter-104-quad-8
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
What: /sys/bus/counter/devices/counterX/signalY/filter_clock_prescaler
KernelVersion: 5.7
Contact: [email protected]
Description:
Filter clock factor for input Signal Y. This prescaler value
affects the inputs of both quadrature pair signals.

What: /sys/bus/counter/devices/counterX/signalY/index_polarity
KernelVersion: 5.2
Contact: [email protected]
Expand Down
61 changes: 58 additions & 3 deletions drivers/counter/104-quad-8.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ MODULE_PARM_DESC(base, "ACCES 104-QUAD-8 base addresses");
*/
struct quad8_iio {
struct counter_device counter;
unsigned int fck_prescaler[QUAD8_NUM_COUNTERS];
unsigned int preset[QUAD8_NUM_COUNTERS];
unsigned int count_mode[QUAD8_NUM_COUNTERS];
unsigned int quadrature_mode[QUAD8_NUM_COUNTERS];
Expand Down Expand Up @@ -84,6 +85,8 @@ struct quad8_iio {
#define QUAD8_RLD_PRESET_CNTR 0x08
/* Transfer Counter to Output Latch */
#define QUAD8_RLD_CNTR_OUT 0x10
/* Transfer Preset Register LSB to FCK Prescaler */
#define QUAD8_RLD_PRESET_PSC 0x18
#define QUAD8_CHAN_OP_ENABLE_COUNTERS 0x00
#define QUAD8_CHAN_OP_RESET_COUNTERS 0x01
#define QUAD8_CMR_QUADRATURE_X1 0x08
Expand Down Expand Up @@ -1140,16 +1143,62 @@ static ssize_t quad8_count_preset_enable_write(struct counter_device *counter,
return len;
}

static ssize_t quad8_signal_fck_prescaler_read(struct counter_device *counter,
struct counter_signal *signal, void *private, char *buf)
{
const struct quad8_iio *const priv = counter->priv;
const size_t channel_id = signal->id / 2;

return sprintf(buf, "%u\n", priv->fck_prescaler[channel_id]);
}

static ssize_t quad8_signal_fck_prescaler_write(struct counter_device *counter,
struct counter_signal *signal, void *private, const char *buf,
size_t len)
{
struct quad8_iio *const priv = counter->priv;
const size_t channel_id = signal->id / 2;
const int base_offset = priv->base + 2 * channel_id;
u8 prescaler;
int ret;

ret = kstrtou8(buf, 0, &prescaler);
if (ret)
return ret;

priv->fck_prescaler[channel_id] = prescaler;

/* Reset Byte Pointer */
outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP, base_offset + 1);

/* Set filter clock factor */
outb(prescaler, base_offset);
outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP | QUAD8_RLD_PRESET_PSC,
base_offset + 1);

return len;
}

static const struct counter_signal_ext quad8_signal_ext[] = {
{
.name = "filter_clock_prescaler",
.read = quad8_signal_fck_prescaler_read,
.write = quad8_signal_fck_prescaler_write
}
};

static const struct counter_signal_ext quad8_index_ext[] = {
COUNTER_SIGNAL_ENUM("index_polarity", &quad8_index_pol_enum),
COUNTER_SIGNAL_ENUM_AVAILABLE("index_polarity", &quad8_index_pol_enum),
COUNTER_SIGNAL_ENUM("synchronous_mode", &quad8_syn_mode_enum),
COUNTER_SIGNAL_ENUM_AVAILABLE("synchronous_mode", &quad8_syn_mode_enum)
};

#define QUAD8_QUAD_SIGNAL(_id, _name) { \
.id = (_id), \
.name = (_name) \
#define QUAD8_QUAD_SIGNAL(_id, _name) { \
.id = (_id), \
.name = (_name), \
.ext = quad8_signal_ext, \
.num_ext = ARRAY_SIZE(quad8_signal_ext) \
}

#define QUAD8_INDEX_SIGNAL(_id, _name) { \
Expand Down Expand Up @@ -1314,6 +1363,12 @@ static int quad8_probe(struct device *dev, unsigned int id)
base_offset = base[id] + 2 * i;
/* Reset Byte Pointer */
outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP, base_offset + 1);
/* Reset filter clock factor */
outb(0, base_offset);
outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP | QUAD8_RLD_PRESET_PSC,
base_offset + 1);
/* Reset Byte Pointer */
outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP, base_offset + 1);
/* Reset Preset Register */
for (j = 0; j < 3; j++)
outb(0x00, base_offset);
Expand Down
2 changes: 1 addition & 1 deletion drivers/iio/pressure/icp10100.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ static int icp10100_read_raw_measures(struct iio_dev *indio_dev,
default:
ret = -EINVAL;
break;
};
}

error_release:
iio_device_release_direct_mode(indio_dev);
Expand Down

0 comments on commit de65d05

Please sign in to comment.