Commit e0014044 authored by Federico Vaga's avatar Federico Vaga

sysfs: replace nsamples with pre-samples and post-samples

It is difficult to support a board which has pre-samples and
post-samples registers and synchronize these value with the nsamples
zio_attribute and control field. But, it is really simple for board that
hasn't pre and post samples to use these two attributes because they can
use only one attribute for their purpose (only pre-sample or only
post-sample).
Signed-off-by: 's avatarFederico Vaga <federico.vaga@gmail.com>
Acked-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent bc7694fa
......@@ -3,9 +3,9 @@
The main idea behind the zio_attribute is that generally what is a
sysfs attribute is also a register in a I/O peripheral; ZIO attributes
can thus be used to export to the host system the device internal
registers. ZIO uses a pair of numbers: address and value. The address
represents the way to gain access to a device register; it is an union
can thus be used to export to the host system the device internal
registers. ZIO uses a pair of numbers: address and value. The address
represents the way to gain access to a device register; it is an union
of two elements: addr which is the register address, and ptr which is
a pointer to a private structure defined within the low-level driver;
the driver implementor can choose whether to use an address alone or
......@@ -25,7 +25,7 @@ allocate its own private structure.
ZIO sysfs Operations
====================
ZIO uses two sysfs operations: conf_set() and info_get(); the former
ZIO uses two sysfs operations: conf_set() and info_get(); the former
writes a configuration value to a register and the latter retrieves a
value from a register.
The ZIO core takes care of ASCII conversion between ZIO and sysfs
......@@ -42,7 +42,7 @@ at device scope.
ZIO calls the conf_set operation every time a user changes an attribute
value. Drivers can avoid defining info_get if the attributes are only
changed by the user. If values may change for other reasons (for
changed by the user. If values may change for other reasons (for
example to reflect internal device status), you must implement info_get
to re-syncronize the ZIO attribute value with the register value. When
the info_get method is not implemented, ZIO returns the current value
......@@ -51,13 +51,13 @@ of the attribute.
Attribute Classification
========================
ZIO classifies its own sysfs attributes in two categories: standard
and extended.
ZIO classifies its own sysfs attributes in two categories: standard
and extended.
Standard Attributes
-------------------
Standard attributes are the most common attributes among I/O
peripherals; for example gain, offset, sample-rate. The main feature
Standard attributes are the most common attributes among I/O
peripherals; for example gain, offset, sample-rate. The main feature
of a standard attribute is that its name in sysfs and its meaning are
clearly defined, irrespective of the peculiarities of the individual
device. Standard attributes are not mandatory, so each object
......@@ -74,7 +74,8 @@ Following the list of the current standard attributes:
ZATTR_MAXRATE /* hertz */
ZATTR_VREFTYPE /* source of Vref (0 = default) */
ZATTR_TRIG_REENABLE /* re-arm trigger */
ZATTR_TRIG_NSAMPLES /* samples for each transfer */
ZATTR_TRIG_PRE_SAMP, /* samples before trigger fire */
ZATTR_TRIG_POST_SAMP, /* samples after trigger fire */
ZATTR_ZBUF_MAXLEN /* max number of element in buffer */
Extended Attributes
......@@ -108,21 +109,21 @@ Each zio object (device, buffer and trigger) can define its own zio
attribute. In order to define a new zio attribute (standard or
extended), the zio framework provides some macros. The following
macro:
DEFINE_ZATTR_STD(_type, _name)
must be used to declare a new set of standard attributes; _type is
used to specify the kind of zio object, _name is the name of the
array of standard attributes. The following macros are used to
define each single attributes:
ZATTR_REG(zobj, _type, _mode, _add, _val)
ZATTR_PRV(zobj, _type, _mode, _priv, _val)
ZATTR_EXT_REG(_name, _mode, _add, _val)
ZATTR_EXT_PRV(_name, _mode, _priv, _val)
Where:
_val: is the default value of the zio attribute (the
_val: is the default value of the zio attribute (the
register on the peripheral)
_add: is the address to gain access to the physical
register
......
......@@ -79,7 +79,8 @@ enum zattr_standard_zdev {
};
enum zattr_standard_trig {
ZATTR_TRIG_REENABLE = 0,/* re-arm trigger */
ZATTR_TRIG_NSAMPLES, /* samples for each transfer */
ZATTR_TRIG_POST_SAMP, /* samples after trigger fire */
ZATTR_TRIG_PRE_SAMP, /* samples before trigger fire */
ZATTR_STD_NUM_TRIG, /* used to size arrays */
};
enum zattr_standard_zbuf {
......
......@@ -29,7 +29,7 @@ enum zti_attrs {
};
static DEFINE_ZATTR_STD(TRIG, zti_std_attr) = {
ZATTR_REG(trig, ZATTR_TRIG_NSAMPLES, S_IRUGO | S_IWUGO,
ZATTR_REG(trig, ZATTR_TRIG_POST_SAMP, S_IRUGO | S_IWUGO,
ZTI_ATTR_NSAMPLES, 16),
};
......
......@@ -33,7 +33,7 @@ enum ztt_attrs { /* names for the "addr" value of sw parameters */
};
static DEFINE_ZATTR_STD(TRIG, ztt_std_attr) = {
ZATTR_REG(trig, ZATTR_TRIG_NSAMPLES, S_IRUGO | S_IWUGO,
ZATTR_REG(trig, ZATTR_TRIG_POST_SAMP, S_IRUGO | S_IWUGO,
ZTT_ATTR_NSAMPLES, 16),
};
......
......@@ -20,7 +20,7 @@
#define ZTU_DEFAULT_BLOCK_SIZE 16
static DEFINE_ZATTR_STD(TRIG, ztu_std_attr) = {
ZATTR_REG(trig, ZATTR_TRIG_NSAMPLES, S_IRUGO | S_IWUGO,
ZATTR_REG(trig, ZATTR_TRIG_POST_SAMP, S_IRUGO | S_IWUGO,
0 /* no addr needed */, ZTU_DEFAULT_BLOCK_SIZE),
};
......
......@@ -33,7 +33,8 @@ const char zio_zdev_attr_names[ZATTR_STD_NUM_ZDEV][ZIO_NAME_LEN] = {
EXPORT_SYMBOL(zio_zdev_attr_names);
const char zio_trig_attr_names[ZATTR_STD_NUM_TRIG][ZIO_NAME_LEN] = {
[ZATTR_TRIG_REENABLE] = "re-enable",
[ZATTR_TRIG_NSAMPLES] = "nsamples",
[ZATTR_TRIG_PRE_SAMP] = "pre-samples",
[ZATTR_TRIG_POST_SAMP] = "post-samples",
};
EXPORT_SYMBOL(zio_trig_attr_names);
const char zio_zbuf_attr_names[ZATTR_STD_NUM_ZBUF][ZIO_NAME_LEN] = {
......@@ -606,6 +607,12 @@ static inline void __zattr_valcpy(struct zio_ctrl_attr *ctrl,
ctrl->std_val[zattr->index] = zattr->value;
}
}
static void __ctrl_update_nsamples(struct zio_ti *ti, struct zio_control *ctrl)
{
ctrl->nsamples = ti->zattr_set.std_zattr[ZATTR_TRIG_PRE_SAMP].value +
ti->zattr_set.std_zattr[ZATTR_TRIG_POST_SAMP].value;
}
static void __zattr_propagate_value(struct zio_obj_head *head,
struct zio_attribute *zattr)
{
......@@ -649,9 +656,13 @@ static void __zattr_propagate_value(struct zio_obj_head *head,
chan = &ti->cset->chan[i];
ctrl = chan->current_ctrl;
__zattr_valcpy(&ctrl->attr_trigger, zattr);
if (zattr->index == ZATTR_TRIG_NSAMPLES &&
(zattr->flags & ZATTR_TYPE) == ZATTR_TYPE_STD)
chan->current_ctrl->nsamples = zattr->value;
if ((zattr->flags & ZATTR_TYPE) == ZATTR_TYPE_EXT)
continue; /* continue to the next channel */
/* Only standard attributes */
if (zattr->index == ZATTR_TRIG_PRE_SAMP ||
zattr->index == ZATTR_TRIG_POST_SAMP)
__ctrl_update_nsamples(ti, ctrl);
}
break;
default:
......@@ -1688,8 +1699,7 @@ static int chan_register(struct zio_channel *chan, struct zio_channel *chan_t)
sizeof(ctrl->addr.devname));
ctrl->ssize = chan->cset->ssize;
/* Trigger instance is already assigned so */
ctrl->nsamples =
chan->cset->ti->zattr_set.std_zattr[ZATTR_TRIG_NSAMPLES].value;
__ctrl_update_nsamples(chan->cset->ti, ctrl);
chan->current_ctrl = ctrl;
/* Initialize and register channel device */
......@@ -2265,7 +2275,12 @@ int zio_register_trig(struct zio_trigger_type *trig, const char *name)
return -EINVAL;
if (!trig->zattr_set.std_zattr)
goto err_nsamp;
if (!trig->zattr_set.std_zattr[ZATTR_TRIG_NSAMPLES].attr.attr.mode)
/*
* The trigger must define how many samples acquire, so POST_SAMP or
* PRE_SAMP attribute must be available
*/
if (!(trig->zattr_set.std_zattr[ZATTR_TRIG_POST_SAMP].attr.attr.mode ||
trig->zattr_set.std_zattr[ZATTR_TRIG_PRE_SAMP].attr.attr.mode))
goto err_nsamp;
/* Verify if it is a valid name */
err = zobj_unique_name(&zstat->all_buffer_types, name);
......@@ -2284,8 +2299,8 @@ int zio_register_trig(struct zio_trigger_type *trig, const char *name)
return 0;
err_nsamp:
pr_err("%s: trigger \"%s\" lacks mandatory \"nsamples\" attribute",
__func__, name);
pr_err("%s: trigger \"%s\" lacks mandatory \"pre-sample\" or"
"\"post-sample\" attribute", __func__, name);
return -EINVAL;
}
EXPORT_SYMBOL(zio_register_trig);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment