iio: expose shared parameter in IIO_ENUM_AVAILABLE
The shared parameter should be configurable based on its usage, and not constrained to IIO_SHARED_BY_TYPE. This patch aims to improve the flexibility in using the IIO_ENUM_AVAILABLE define and avoid redefining custom iio enums that expose the shared parameter. An example is the ad5766.c driver where IIO_ENUM_AVAILABLE_SHARED was defined in order to achieve `shared` parameter customization. The current state of the IIO_ENUM_AVAILABLE implementation will imply similar redefinitions each time a driver will require access to the `shared` parameter. An example would be admv1013 driver which will require custom device attribute for the frequency translation modes: Quadrature I/Q mode and Intermediate Frequency mode. Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com> Link: https://lore.kernel.org/r/20211119085627.6348-1-antoniu.miclaus@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
ab1fb45579
commit
ffc7c5172a
@ -658,7 +658,7 @@ static const struct iio_chan_spec_ext_info bma023_ext_info[] = {
|
||||
|
||||
static const struct iio_chan_spec_ext_info bma180_ext_info[] = {
|
||||
IIO_ENUM("power_mode", IIO_SHARED_BY_TYPE, &bma180_power_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("power_mode", &bma180_power_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("power_mode", IIO_SHARED_BY_TYPE, &bma180_power_mode_enum),
|
||||
IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, bma180_accel_get_mount_matrix),
|
||||
{ }
|
||||
};
|
||||
|
@ -917,7 +917,7 @@ static const struct iio_enum mma9553_calibgender_enum = {
|
||||
|
||||
static const struct iio_chan_spec_ext_info mma9553_ext_info[] = {
|
||||
IIO_ENUM("calibgender", IIO_SHARED_BY_TYPE, &mma9553_calibgender_enum),
|
||||
IIO_ENUM_AVAILABLE("calibgender", &mma9553_calibgender_enum),
|
||||
IIO_ENUM_AVAILABLE("calibgender", IIO_SHARED_BY_TYPE, &mma9553_calibgender_enum),
|
||||
{},
|
||||
};
|
||||
|
||||
|
@ -257,7 +257,8 @@ static const struct iio_chan_spec_ext_info ad7192_calibsys_ext_info[] = {
|
||||
},
|
||||
IIO_ENUM("sys_calibration_mode", IIO_SEPARATE,
|
||||
&ad7192_syscalib_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("sys_calibration_mode", &ad7192_syscalib_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("sys_calibration_mode", IIO_SHARED_BY_TYPE,
|
||||
&ad7192_syscalib_mode_enum),
|
||||
{}
|
||||
};
|
||||
|
||||
|
@ -350,7 +350,7 @@ static const struct iio_enum hi8435_sensing_mode = {
|
||||
|
||||
static const struct iio_chan_spec_ext_info hi8435_ext_info[] = {
|
||||
IIO_ENUM("sensing_mode", IIO_SEPARATE, &hi8435_sensing_mode),
|
||||
IIO_ENUM_AVAILABLE("sensing_mode", &hi8435_sensing_mode),
|
||||
IIO_ENUM_AVAILABLE("sensing_mode", IIO_SHARED_BY_TYPE, &hi8435_sensing_mode),
|
||||
{},
|
||||
};
|
||||
|
||||
|
@ -377,7 +377,7 @@ static const struct iio_chan_spec_ext_info ad5064_ext_info[] = {
|
||||
.shared = IIO_SEPARATE,
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SEPARATE, &ad5064_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", &ad5064_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, &ad5064_powerdown_mode_enum),
|
||||
{ },
|
||||
};
|
||||
|
||||
@ -389,7 +389,7 @@ static const struct iio_chan_spec_ext_info ltc2617_ext_info[] = {
|
||||
.shared = IIO_SEPARATE,
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SEPARATE, <c2617_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", <c2617_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, <c2617_powerdown_mode_enum),
|
||||
{ },
|
||||
};
|
||||
|
||||
|
@ -249,7 +249,7 @@ static const struct iio_chan_spec_ext_info ad5380_ext_info[] = {
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SHARED_BY_TYPE,
|
||||
&ad5380_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", &ad5380_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, &ad5380_powerdown_mode_enum),
|
||||
{ },
|
||||
};
|
||||
|
||||
|
@ -142,7 +142,7 @@ static const struct iio_chan_spec_ext_info ad5446_ext_info_powerdown[] = {
|
||||
.shared = IIO_SEPARATE,
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SEPARATE, &ad5446_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", &ad5446_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, &ad5446_powerdown_mode_enum),
|
||||
{ },
|
||||
};
|
||||
|
||||
|
@ -241,7 +241,7 @@ static const struct iio_chan_spec_ext_info ad5504_ext_info[] = {
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SHARED_BY_TYPE,
|
||||
&ad5504_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", &ad5504_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, &ad5504_powerdown_mode_enum),
|
||||
{ },
|
||||
};
|
||||
|
||||
|
@ -159,7 +159,7 @@ static const struct iio_chan_spec_ext_info ad5624r_ext_info[] = {
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SHARED_BY_TYPE,
|
||||
&ad5624r_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", &ad5624r_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, &ad5624r_powerdown_mode_enum),
|
||||
{ },
|
||||
};
|
||||
|
||||
|
@ -184,7 +184,7 @@ static const struct iio_chan_spec_ext_info ad5686_ext_info[] = {
|
||||
.shared = IIO_SEPARATE,
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SEPARATE, &ad5686_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", &ad5686_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, &ad5686_powerdown_mode_enum),
|
||||
{ },
|
||||
};
|
||||
|
||||
|
@ -426,14 +426,6 @@ static ssize_t ad5766_write_ext(struct iio_dev *indio_dev,
|
||||
.shared = _shared, \
|
||||
}
|
||||
|
||||
#define IIO_ENUM_AVAILABLE_SHARED(_name, _shared, _e) \
|
||||
{ \
|
||||
.name = (_name "_available"), \
|
||||
.shared = _shared, \
|
||||
.read = iio_enum_available_read, \
|
||||
.private = (uintptr_t)(_e), \
|
||||
}
|
||||
|
||||
static const struct iio_chan_spec_ext_info ad5766_ext_info[] = {
|
||||
|
||||
_AD5766_CHAN_EXT_INFO("dither_enable", AD5766_DITHER_ENABLE,
|
||||
@ -443,9 +435,8 @@ static const struct iio_chan_spec_ext_info ad5766_ext_info[] = {
|
||||
_AD5766_CHAN_EXT_INFO("dither_source", AD5766_DITHER_SOURCE,
|
||||
IIO_SEPARATE),
|
||||
IIO_ENUM("dither_scale", IIO_SEPARATE, &ad5766_dither_scale_enum),
|
||||
IIO_ENUM_AVAILABLE_SHARED("dither_scale",
|
||||
IIO_SEPARATE,
|
||||
&ad5766_dither_scale_enum),
|
||||
IIO_ENUM_AVAILABLE("dither_scale", IIO_SEPARATE,
|
||||
&ad5766_dither_scale_enum),
|
||||
{}
|
||||
};
|
||||
|
||||
|
@ -285,7 +285,7 @@ static const struct iio_chan_spec_ext_info ad5791_ext_info[] = {
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SHARED_BY_TYPE,
|
||||
&ad5791_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", &ad5791_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, &ad5791_powerdown_mode_enum),
|
||||
{ },
|
||||
};
|
||||
|
||||
|
@ -137,7 +137,7 @@ static const struct iio_chan_spec_ext_info max5821_ext_info[] = {
|
||||
.shared = IIO_SEPARATE,
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SEPARATE, &max5821_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", &max5821_powerdown_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, &max5821_powerdown_mode_enum),
|
||||
{ },
|
||||
};
|
||||
|
||||
|
@ -221,8 +221,8 @@ static const struct iio_chan_spec_ext_info mcp4725_ext_info[] = {
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SEPARATE,
|
||||
&mcp472x_powerdown_mode_enum[MCP4725]),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode",
|
||||
&mcp472x_powerdown_mode_enum[MCP4725]),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE,
|
||||
&mcp472x_powerdown_mode_enum[MCP4725]),
|
||||
{ },
|
||||
};
|
||||
|
||||
@ -235,8 +235,8 @@ static const struct iio_chan_spec_ext_info mcp4726_ext_info[] = {
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SEPARATE,
|
||||
&mcp472x_powerdown_mode_enum[MCP4726]),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode",
|
||||
&mcp472x_powerdown_mode_enum[MCP4726]),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE,
|
||||
&mcp472x_powerdown_mode_enum[MCP4726]),
|
||||
{ },
|
||||
};
|
||||
|
||||
|
@ -246,7 +246,7 @@ static const struct iio_chan_spec_ext_info stm32_dac_ext_info[] = {
|
||||
.shared = IIO_SEPARATE,
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SEPARATE, &stm32_dac_powerdown_mode_en),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", &stm32_dac_powerdown_mode_en),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, &stm32_dac_powerdown_mode_en),
|
||||
{},
|
||||
};
|
||||
|
||||
|
@ -160,7 +160,7 @@ static const struct iio_chan_spec_ext_info ti_dac_ext_info[] = {
|
||||
.shared = IIO_SHARED_BY_TYPE,
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SHARED_BY_TYPE, &ti_dac_powerdown_mode),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", &ti_dac_powerdown_mode),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, &ti_dac_powerdown_mode),
|
||||
{ },
|
||||
};
|
||||
|
||||
|
@ -212,7 +212,7 @@ static const struct iio_chan_spec_ext_info dac5571_ext_info[] = {
|
||||
.shared = IIO_SEPARATE,
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SEPARATE, &dac5571_powerdown_mode),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", &dac5571_powerdown_mode),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, &dac5571_powerdown_mode),
|
||||
{},
|
||||
};
|
||||
|
||||
|
@ -146,7 +146,7 @@ static const struct iio_chan_spec_ext_info ti_dac_ext_info[] = {
|
||||
.shared = IIO_SHARED_BY_TYPE,
|
||||
},
|
||||
IIO_ENUM("powerdown_mode", IIO_SHARED_BY_TYPE, &ti_dac_powerdown_mode),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", &ti_dac_powerdown_mode),
|
||||
IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, &ti_dac_powerdown_mode),
|
||||
{ },
|
||||
};
|
||||
|
||||
|
@ -246,7 +246,7 @@ static const struct iio_enum hmc5843_meas_conf_enum = {
|
||||
|
||||
static const struct iio_chan_spec_ext_info hmc5843_ext_info[] = {
|
||||
IIO_ENUM("meas_conf", IIO_SHARED_BY_TYPE, &hmc5843_meas_conf_enum),
|
||||
IIO_ENUM_AVAILABLE("meas_conf", &hmc5843_meas_conf_enum),
|
||||
IIO_ENUM_AVAILABLE("meas_conf", IIO_SHARED_BY_TYPE, &hmc5843_meas_conf_enum),
|
||||
IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, hmc5843_get_mount_matrix),
|
||||
{ }
|
||||
};
|
||||
@ -260,7 +260,7 @@ static const struct iio_enum hmc5983_meas_conf_enum = {
|
||||
|
||||
static const struct iio_chan_spec_ext_info hmc5983_ext_info[] = {
|
||||
IIO_ENUM("meas_conf", IIO_SHARED_BY_TYPE, &hmc5983_meas_conf_enum),
|
||||
IIO_ENUM_AVAILABLE("meas_conf", &hmc5983_meas_conf_enum),
|
||||
IIO_ENUM_AVAILABLE("meas_conf", IIO_SHARED_BY_TYPE, &hmc5983_meas_conf_enum),
|
||||
IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, hmc5843_get_mount_matrix),
|
||||
{ }
|
||||
};
|
||||
|
@ -696,9 +696,9 @@ static const struct iio_chan_spec_ext_info stm32_trigger_count_info[] = {
|
||||
.write = stm32_count_set_preset
|
||||
},
|
||||
IIO_ENUM("enable_mode", IIO_SEPARATE, &stm32_enable_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("enable_mode", &stm32_enable_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("enable_mode", IIO_SHARED_BY_TYPE, &stm32_enable_mode_enum),
|
||||
IIO_ENUM("trigger_mode", IIO_SEPARATE, &stm32_trigger_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("trigger_mode", &stm32_trigger_mode_enum),
|
||||
IIO_ENUM_AVAILABLE("trigger_mode", IIO_SHARED_BY_TYPE, &stm32_trigger_mode_enum),
|
||||
{}
|
||||
};
|
||||
|
||||
|
@ -103,15 +103,16 @@ ssize_t iio_enum_write(struct iio_dev *indio_dev,
|
||||
/**
|
||||
* IIO_ENUM_AVAILABLE() - Initialize enum available extended channel attribute
|
||||
* @_name: Attribute name ("_available" will be appended to the name)
|
||||
* @_shared: Whether the attribute is shared between all channels
|
||||
* @_e: Pointer to an iio_enum struct
|
||||
*
|
||||
* Creates a read only attribute which lists all the available enum items in a
|
||||
* space separated list. This should usually be used together with IIO_ENUM()
|
||||
*/
|
||||
#define IIO_ENUM_AVAILABLE(_name, _e) \
|
||||
#define IIO_ENUM_AVAILABLE(_name, _shared, _e) \
|
||||
{ \
|
||||
.name = (_name "_available"), \
|
||||
.shared = IIO_SHARED_BY_TYPE, \
|
||||
.shared = _shared, \
|
||||
.read = iio_enum_available_read, \
|
||||
.private = (uintptr_t)(_e), \
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user