Skip to content

Commit 856b10d

Browse files
PopPaul2021nunojsa
authored andcommitted
iio: frequency: ad9508: Support write only mode
There are some evaluation boards (e.g., EVAL-AD916X) where the direction for the level translator of the SDIO pin is hardwired to VDD, forcing the device to operate in write-mode only. Signed-off-by: PopPaul2021 <[email protected]>
1 parent 3019403 commit 856b10d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

drivers/iio/frequency/ad9508.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ struct ad9508_state {
8787

8888
struct gpio_desc *reset_gpio;
8989
struct gpio_desc *sync_gpio;
90-
90+
bool write_mode_only;
91+
unsigned long regs_hw[44];
9192
struct mutex lock;
9293

9394
/*
@@ -106,6 +107,9 @@ static int ad9508_read(struct iio_dev *indio_dev, unsigned addr)
106107
int ret;
107108
u32 mask = ~0U >> (32 - 8 * AD9508_TRANSF_LEN(addr));
108109

110+
if (st->write_mode_only)
111+
return st->regs_hw[AD9508_ADDR(addr)];
112+
109113
/* We encode the register size 1..3 bytes into the register address.
110114
* On transfer we get the size from the register datum, and make sure
111115
* the result is properly aligned.
@@ -161,6 +165,8 @@ static int ad9508_write(struct iio_dev *indio_dev, unsigned addr, unsigned val)
161165
if (ret < 0)
162166
dev_err(&indio_dev->dev, "write failed (%d)", ret);
163167

168+
st->regs_hw[AD9508_ADDR(addr)] = val;
169+
164170
return ret;
165171
}
166172

@@ -661,6 +667,20 @@ static int ad9508_probe(struct spi_device *spi)
661667
indio_dev->channels = st->ad9508_channels;
662668
indio_dev->num_channels = pdata->num_channels;
663669

670+
if (device_property_present(&st->spi->dev, "adi,write-mode-only"))
671+
st->write_mode_only = true;
672+
673+
memset(st->regs_hw, 0xFF, sizeof(st->regs_hw));
674+
675+
/* Initialize the regs_hw array with the reset values */
676+
677+
st->regs_hw[AD9508_ADDR(AD9508_PART_ID)] = 0x0500;
678+
st->regs_hw[AD9508_ADDR(AD9508_SYNC_BAR)] = 0x1;
679+
st->regs_hw[AD9508_ADDR(AD9508_CHANNEL_OUT_DRIVER(0))] = 0x14;
680+
st->regs_hw[AD9508_ADDR(AD9508_CHANNEL_OUT_DRIVER(1))] = 0x14;
681+
st->regs_hw[AD9508_ADDR(AD9508_CHANNEL_OUT_DRIVER(2))] = 0x14;
682+
st->regs_hw[AD9508_ADDR(AD9508_CHANNEL_OUT_DRIVER(3))] = 0x14;
683+
664684
ret = ad9508_setup(indio_dev);
665685
if (ret < 0)
666686
goto error_disable_reg;

0 commit comments

Comments
 (0)