Skip to content

Commit

Permalink
Replace iio_device_attr_* with the libiio v1.x iio_attr_* API
Browse files Browse the repository at this point in the history
Signed-off-by: Dan <[email protected]>
  • Loading branch information
dNechita committed Nov 27, 2024
1 parent b61dbca commit 8498c1e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
27 changes: 20 additions & 7 deletions ad9361_baseband_auto_rate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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(
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions ad9361_design_taps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions ad9361_fmcomms5_phase_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 21 additions & 10 deletions ad9361_multichip_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 8498c1e

Please sign in to comment.