Skip to content

Commit

Permalink
iio:ad9361 print out the SPI CLK during probe
Browse files Browse the repository at this point in the history
This will only work for those SPI controllers which populate their
effective_speed_hz during the clock setting, but for those that do,
this will print out the SPI clock (in MHz) so it is easier to understand
what's going on in the system.

will see things like:
ad9361 : AD936x Rev 2 successfully initialized (SPI @ 5.20 MHz)
or
ad9361 : AD936x Rev 2 successfully initialized (SPI @ 41.66 MHz)
or (with older SPI controller drivers)
ad9361 : AD936x Rev 2 successfully initialized

tested on PlutoSDR

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz authored and mhennerich committed Dec 16, 2021
1 parent 0b18c37 commit c0c1250
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions drivers/iio/adc/ad9361.c
Original file line number Diff line number Diff line change
Expand Up @@ -9399,13 +9399,44 @@ ad9361_gt_bin_read(struct file *filp, struct kobject *kobj,
return ret;
}

static int ad9361_spi_check(struct spi_device *spi)
{
u8 buf[3] = {0};
int ret;
u16 cmd;
struct spi_transfer t = {
.tx_buf = buf,
.rx_buf = buf,
.len = sizeof(buf),
};

/*
* We need do a low level spi transfer to get the effective speed
* otherwise we would just do a ad9361_spi_read()
*/
cmd = AD_READ | AD_CNT(1) | AD_ADDR(REG_PRODUCT_ID);
buf[0] = cmd >> 8;
buf[1] = cmd & 0xFF;

ret = spi_sync_transfer(spi, &t, 1);
if (ret)
return ret;

if ((buf[2] & PRODUCT_ID_MASK) != PRODUCT_ID_9361) {
dev_err(&spi->dev, "%s : Unsupported PRODUCT_ID 0x%X", __func__, buf[2]);
return -ENODEV;
}

return t.effective_speed_hz;
}

static int ad9361_probe(struct spi_device *spi)
{
struct iio_dev *indio_dev;
struct ad9361_rf_phy_state *st;
struct ad9361_rf_phy *phy;
struct clk *clk = NULL;
int ret, rev;
int ret, rev, hz;

dev_info(&spi->dev, "%s : enter (%s)", __func__,
spi_get_device_id(spi)->name);
Expand Down Expand Up @@ -9468,12 +9499,9 @@ static int ad9361_probe(struct spi_device *spi)

ad9361_reset(phy);

ret = ad9361_spi_read(spi, REG_PRODUCT_ID);
if ((ret & PRODUCT_ID_MASK) != PRODUCT_ID_9361) {
dev_err(&spi->dev, "%s : Unsupported PRODUCT_ID 0x%X",
__func__, ret);
return -ENODEV;
}
hz = ad9361_spi_check(spi);
if (hz < 0)
return hz;

rev = ret & REV_MASK;

Expand Down Expand Up @@ -9544,8 +9572,12 @@ static int ad9361_probe(struct spi_device *spi)
if (ret < 0)
dev_warn(&spi->dev, "%s: failed to register debugfs", __func__);

dev_info(&spi->dev, "%s : AD936x Rev %d successfully initialized",
__func__, rev);
if (hz > 0)
dev_info(&spi->dev, "%s : AD936x Rev %d successfully initialized (SPI @ %u.%02u MHz)",
__func__, rev, hz / 1000000, hz % 1000000 / 1000 / 10);
else
dev_info(&spi->dev, "%s : AD936x Rev %d successfully initialized",
__func__, rev);

return 0;

Expand Down

0 comments on commit c0c1250

Please sign in to comment.