diff --git a/Documentation/zio/sysfs.txt b/Documentation/zio/sysfs.txt index 0aae10743c4edfdfaf2147ee46de4b20b527cccb..15e4fad6b5dc565b446738a118b3c898e5c11bb5 100644 --- a/Documentation/zio/sysfs.txt +++ b/Documentation/zio/sysfs.txt @@ -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 diff --git a/include/linux/zio-sysfs.h b/include/linux/zio-sysfs.h index 53b3bad83683dbf9050714bbc959d45b17d1c8a6..85fe5e220d62c0af1ffa75fdcd0e4badf39db7b2 100644 --- a/include/linux/zio-sysfs.h +++ b/include/linux/zio-sysfs.h @@ -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 { diff --git a/triggers/zio-trig-irq.c b/triggers/zio-trig-irq.c index 6f3d69bb7fe11f980b0ddacb50a0a02893402720..8c632a0334230c089ce8a9bfa18a906737bb9c1d 100644 --- a/triggers/zio-trig-irq.c +++ b/triggers/zio-trig-irq.c @@ -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), }; diff --git a/triggers/zio-trig-timer.c b/triggers/zio-trig-timer.c index abfb67ef2704344dd743f2d6cff81ebcda1f8cdd..5b5ba4acfeb9448c57c9c39af4385ac87fd6a216 100644 --- a/triggers/zio-trig-timer.c +++ b/triggers/zio-trig-timer.c @@ -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), }; diff --git a/triggers/zio-trig-user.c b/triggers/zio-trig-user.c index e91a9558812856aeea3c72ce216ad2445e66af5f..fd0b109e592e5c56256830411dcdd64c3377c2e9 100644 --- a/triggers/zio-trig-user.c +++ b/triggers/zio-trig-user.c @@ -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), }; diff --git a/zio-sys.c b/zio-sys.c index 26ec48212ebec1c774bf8140f17af7837d9b4748..b441b4e655741470f4d5cb78500c782f93966695 100644 --- a/zio-sys.c +++ b/zio-sys.c @@ -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);