From 8498c1ed8adf14530732cb9f47a06191b4e439d7 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 27 Nov 2024 17:15:33 +0200 Subject: [PATCH] Replace iio_device_attr_* with the libiio v1.x iio_attr_* API Signed-off-by: Dan --- ad9361_baseband_auto_rate.c | 27 ++++++++++++++++++++------- ad9361_design_taps.c | 8 ++++++-- ad9361_fmcomms5_phase_sync.c | 5 +++-- ad9361_multichip_sync.c | 31 +++++++++++++++++++++---------- 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/ad9361_baseband_auto_rate.c b/ad9361_baseband_auto_rate.c index 9df97db..2cc68ba 100644 --- a/ad9361_baseband_auto_rate.c +++ b/ad9361_baseband_auto_rate.c @@ -53,9 +53,14 @@ static int16_t fir_64_2[] = { int ad9361_set_trx_fir_enable(struct iio_device *dev, int enable) { - const struct iio_attr *attr; - int ret = iio_device_attr_write_bool(dev, - "in_out_voltage_filter_fir_en", !!enable); + const struct iio_attr *attr = iio_device_find_attr(dev, + "in_out_voltage_filter_fir_en"); + int ret; + + if (attr) + ret = iio_attr_write_bool(attr, !!enable); + else + ret = -ENODEV; if (ret < 0) { attr = iio_channel_find_attr( iio_device_find_channel(dev, "out", false), @@ -70,8 +75,13 @@ int ad9361_get_trx_fir_enable(struct iio_device *dev, int *enable) { const struct iio_attr *chAttr; bool value; + struct iio_attr *attr = iio_device_find_attr(dev, "in_out_voltage_filter_fir_en"); + int ret; - int ret = iio_device_attr_read_bool(dev, "in_out_voltage_filter_fir_en", &value); + if (attr) + ret = iio_attr_read_bool(attr, &value); + else + ret = -ENODEV; if (ret < 0) chAttr = iio_channel_find_attr( @@ -89,7 +99,7 @@ int ad9361_get_trx_fir_enable(struct iio_device *dev, int *enable) int ad9361_set_bb_rate(struct iio_device *dev, unsigned long rate) { struct iio_channel *chan; - const struct iio_attr *v0_samplfreq_attr; + const struct iio_attr *v0_samplfreq_attr, *attr; long long current_rate; int dec, taps, ret, i, enable, len = 0; int16_t *fir; @@ -150,7 +160,9 @@ int ad9361_set_bb_rate(struct iio_device *dev, unsigned long rate) len += snprintf(buf + len, FIR_BUF_SIZE - len, "\n"); - ret = iio_device_attr_write_raw(dev, "filter_fir_config", buf, len); + attr = iio_device_find_attr(dev, "filter_fir_config"); + if (attr) + ret = iio_attr_write_raw(attr, buf, len); free (buf); if (ret < 0) @@ -160,7 +172,8 @@ int ad9361_set_bb_rate(struct iio_device *dev, unsigned long rate) int dacrate, txrate, max; char readbuf[100]; - ret = iio_device_attr_read_raw(dev, "tx_path_rates", readbuf, sizeof(readbuf)); + attr = iio_device_find_attr(dev, "tx_path_rates"); + ret = iio_attr_read_raw(attr, readbuf, sizeof(readbuf)); if (ret < 0) return ret; ret = sscanf(readbuf, "BBPLL:%*d DAC:%d T2:%*d T1:%*d TF:%*d TXSAMP:%d", &dacrate, &txrate); diff --git a/ad9361_design_taps.c b/ad9361_design_taps.c index 7787066..499acd8 100644 --- a/ad9361_design_taps.c +++ b/ad9361_design_taps.c @@ -255,7 +255,9 @@ int apply_custom_filter(struct iio_device *dev, unsigned dec_tx, len += snprintf(buf + len, FIR_BUF_SIZE - len, "\n"); - ret = iio_device_attr_write_raw(dev, "filter_fir_config", buf, len); + attr = iio_device_find_attr(dev, "filter_fir_config"); + if (attr) + ret = iio_attr_write_raw(attr, buf, len); free (buf); if (ret < 0) @@ -265,7 +267,9 @@ int apply_custom_filter(struct iio_device *dev, unsigned dec_tx, int dacrate, txrate, max; char readbuf[100]; - ret = iio_device_attr_read_raw(dev, "tx_path_rates", readbuf, sizeof(readbuf)); + attr = iio_device_find_attr(dev, "tx_path_rates"); + if (attr) + ret = iio_attr_read_raw(attr, readbuf, sizeof(readbuf)); if (ret < 0) return ret; ret = sscanf(readbuf, "BBPLL:%*d DAC:%d T2:%*d T1:%*d TF:%*d TXSAMP:%d", diff --git a/ad9361_fmcomms5_phase_sync.c b/ad9361_fmcomms5_phase_sync.c index 0d024b4..f6fe47d 100644 --- a/ad9361_fmcomms5_phase_sync.c +++ b/ad9361_fmcomms5_phase_sync.c @@ -226,8 +226,9 @@ void configure_ports(unsigned val) // Configure ADG918 switches #if !EXTERNAL_REFERENCE_TONE - iio_device_debug_attr_write_longlong(dev_phy, "calibration_switch_control", - sw); + attr = iio_device_find_debug_attr(dev_phy, "calibration_switch_control"); + if (attr) + iio_attr_write_longlong(attr, sw); #endif // Map ports to switch orientation attr = iio_channel_find_attr(iio_device_find_channel(dev_phy, "voltage0", diff --git a/ad9361_multichip_sync.c b/ad9361_multichip_sync.c index 95b5640..cacec06 100644 --- a/ad9361_multichip_sync.c +++ b/ad9361_multichip_sync.c @@ -46,6 +46,7 @@ int ad9361_multichip_sync(struct iio_device *master, struct iio_device **slaves, unsigned int i, step; bool mcs_is_debug_attr = !iio_device_find_attr(master, "multichip_sync"); const struct iio_attr *attr; + const struct iio_attr *master_ensm_attr; if (num_slaves >= MAX_AD9361_SYNC_DEVS || num_slaves < 1) return -EINVAL; @@ -88,35 +89,45 @@ int ad9361_multichip_sync(struct iio_device *master, struct iio_device **slaves, } /* Move the parts int ALERT for MCS */ - iio_device_attr_read_raw(master, "ensm_mode", ensm_mode[0], sizeof(ensm_mode)); - iio_device_attr_write(master, "ensm_mode", "alert"); + master_ensm_attr = iio_device_find_attr(master, "ensm_mode"); + iio_attr_read_raw(attr, ensm_mode[0], sizeof(ensm_mode)); + iio_attr_write_string(attr, "alert"); for (i = 0; i < num_slaves; i++) { - iio_device_attr_read_raw(slaves[i], "ensm_mode", ensm_mode[i + 1], sizeof(ensm_mode)); - iio_device_attr_write(slaves[i], "ensm_mode", "alert"); + attr = iio_device_find_attr(slaves[i], "ensm_mode"); + if (attr) { + iio_attr_read_raw(attr, ensm_mode[i + 1], sizeof(ensm_mode)); + iio_attr_write_string(attr, "alert"); + } } for (step = 0; step <= 5; step++) { for (i = 0; i < num_slaves; i++) { if (mcs_is_debug_attr) - iio_device_debug_attr_write_longlong(slaves[i], "multichip_sync", step); + attr = iio_device_find_debug_attr(slaves[i], "multichip_sync"); else - iio_device_attr_write_longlong(slaves[i], "multichip_sync", step); + attr = iio_device_find_attr(slaves[i], "multichip_sync"); + if (attr) + iio_attr_write_longlong(attr, step); } /* The master controls the SYNC GPIO */ if (mcs_is_debug_attr) - iio_device_debug_attr_write_longlong(master, "multichip_sync", step); + attr = iio_device_find_debug_attr(master, "multichip_sync" ); else - iio_device_attr_write_longlong(master, "multichip_sync", step); + attr = iio_device_find_attr(master, "multichip_sync"); + if (attr) + iio_attr_write_longlong(attr, step); ad9361_sleep_ms(); } - iio_device_attr_write(master, "ensm_mode", ensm_mode[0]); + iio_attr_write(master_ensm_attr, ensm_mode[0]); for (i = 0; i < num_slaves; i++) - iio_device_attr_write(slaves[i], "ensm_mode", ensm_mode[i + 1]); + attr = iio_device_find_attr(slaves[i], "ensm_mode"); + if (attr) + iio_attr_write(attr, ensm_mode[i + 1]); return 0; }