baylibre-acme: Dynamically check per probe config options.
PROBE_FACTOR and POWER_OFF options are advertised for all ACME probes (channel groups) regardless of whether they actually have given capability. Check these options in config_list() at runtime and only advertise them for probes which support them. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
This commit is contained in:
parent
1190c65397
commit
1fe04eb8d6
|
@ -28,10 +28,19 @@ static const uint32_t devopts[] = {
|
|||
SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
|
||||
};
|
||||
|
||||
static const uint32_t devopts_cg[] = {
|
||||
SR_CONF_PROBE_FACTOR | SR_CONF_GET | SR_CONF_SET,
|
||||
SR_CONF_POWER_OFF | SR_CONF_GET | SR_CONF_SET,
|
||||
};
|
||||
/*
|
||||
* Currently there are two channel-group/probe options for ACME:
|
||||
* - SR_CONF_PROBE_FACTOR - allows to modify current shunt resistance
|
||||
* calibration
|
||||
* - SR_CONF_POWER_OFF - allows to remotely cut-off/restore power to
|
||||
* measured devices
|
||||
*
|
||||
* They are not static - we have to check each probe's capabilities in
|
||||
* config_list().
|
||||
*/
|
||||
#define MAX_DEVOPTS_CG 2
|
||||
#define HAS_PROBE_FACTOR (SR_CONF_PROBE_FACTOR | SR_CONF_GET | SR_CONF_SET)
|
||||
#define HAS_POWER_OFF (SR_CONF_POWER_OFF | SR_CONF_GET | SR_CONF_SET)
|
||||
|
||||
#define MAX_SAMPLE_RATE 500 /* In Hz */
|
||||
|
||||
|
@ -263,9 +272,10 @@ static int config_list(uint32_t key, GVariant **data,
|
|||
const struct sr_dev_inst *sdi,
|
||||
const struct sr_channel_group *cg)
|
||||
{
|
||||
uint32_t devopts_cg[MAX_DEVOPTS_CG];
|
||||
GVariant *gvar;
|
||||
GVariantBuilder gvb;
|
||||
int ret;
|
||||
int ret, num_devopts_cg = 0;
|
||||
|
||||
(void)sdi;
|
||||
(void)cg;
|
||||
|
@ -291,8 +301,13 @@ static int config_list(uint32_t key, GVariant **data,
|
|||
} else {
|
||||
switch (key) {
|
||||
case SR_CONF_DEVICE_OPTIONS:
|
||||
if (bl_acme_get_probe_type(cg) == PROBE_ENRG)
|
||||
devopts_cg[num_devopts_cg++] = HAS_PROBE_FACTOR;
|
||||
if (bl_acme_probe_has_pws(cg))
|
||||
devopts_cg[num_devopts_cg++] = HAS_POWER_OFF;
|
||||
|
||||
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
|
||||
devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t));
|
||||
devopts_cg, num_devopts_cg, sizeof(uint32_t));
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -245,6 +245,20 @@ SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
SR_PRIV int bl_acme_get_probe_type(const struct sr_channel_group *cg)
|
||||
{
|
||||
struct channel_group_priv *cgp = cg->priv;
|
||||
|
||||
return cgp->probe_type;
|
||||
}
|
||||
|
||||
SR_PRIV int bl_acme_probe_has_pws(const struct sr_channel_group *cg)
|
||||
{
|
||||
struct channel_group_priv *cgp = cg->priv;
|
||||
|
||||
return sr_gpio_getval_export(pws_info_gpios[cgp->index]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets path to the hwmon attribute if this channel group
|
||||
* supports shunt resistance setting. The caller has to supply
|
||||
|
@ -348,8 +362,7 @@ SR_PRIV int bl_acme_read_power_state(const struct sr_channel_group *cg,
|
|||
|
||||
cgp = cg->priv;
|
||||
|
||||
val = sr_gpio_getval_export(pws_info_gpios[cgp->index]);
|
||||
if (val != 1) {
|
||||
if (!bl_acme_probe_has_pws(cg)) {
|
||||
sr_err("Probe has no power-switch");
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
@ -368,8 +381,7 @@ SR_PRIV int bl_acme_set_power_off(const struct sr_channel_group *cg,
|
|||
|
||||
cgp = cg->priv;
|
||||
|
||||
val = sr_gpio_getval_export(pws_info_gpios[cgp->index]);
|
||||
if (val != 1) {
|
||||
if (!bl_acme_probe_has_pws(cg)) {
|
||||
sr_err("Probe has no power-switch");
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,9 @@ SR_PRIV gboolean bl_acme_detect_probe(unsigned int addr,
|
|||
SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type,
|
||||
unsigned int addr, int prb_num);
|
||||
|
||||
SR_PRIV int bl_acme_get_probe_type(const struct sr_channel_group *cg);
|
||||
SR_PRIV int bl_acme_probe_has_pws(const struct sr_channel_group *cg);
|
||||
|
||||
SR_PRIV int bl_acme_get_shunt(const struct sr_channel_group *cg,
|
||||
uint64_t *shunt);
|
||||
SR_PRIV int bl_acme_set_shunt(const struct sr_channel_group *cg,
|
||||
|
|
Loading…
Reference in New Issue