Skip to content

Commit 8ddcfab

Browse files
committed
drivers: iio: frequency: adf4371: Add FSM ops
Add JESD FSM ops. These modifications are required if the device is added to a JESD topology. Required by the AD9213 driver, so that the initialization sequence is synchronized with the AD9213 operation. Signed-off-by: George Mois <george.mois@analog.com>
1 parent b0d67b6 commit 8ddcfab

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

drivers/iio/frequency/adf4371.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <linux/iio/iio.h>
2323
#include <linux/iio/sysfs.h>
2424

25+
#include <linux/jesd204/jesd204.h>
26+
2527
/* Registers address macro */
2628
#define ADF4371_REG(x) (x)
2729

@@ -275,6 +277,7 @@ struct adf4371_state {
275277
* writes.
276278
*/
277279
struct mutex lock;
280+
struct jesd204_dev *jdev;
278281
const struct adf4371_chip_info *chip_info;
279282
const char *adf4371_clk_names[4];
280283
unsigned long clkin_freq;
@@ -297,6 +300,10 @@ struct adf4371_state {
297300
u8 buf[10] __aligned(IIO_DMA_MINALIGN);
298301
};
299302

303+
struct adf4371_jesd204_priv {
304+
struct adf4371_state *adf_st;
305+
};
306+
300307
static unsigned long long adf4371_pll_fract_n_get_rate(struct adf4371_state *st,
301308
u32 channel)
302309
{
@@ -1234,10 +1241,34 @@ static int adf4371_clks_register(struct iio_dev *indio_dev)
12341241
adf4371_clk_del_provider, st);
12351242
}
12361243

1244+
static int adf4371_jesd204_link_init(struct jesd204_dev *jdev,
1245+
enum jesd204_state_op_reason reason,
1246+
struct jesd204_link *lnk)
1247+
{
1248+
struct device *dev = jesd204_dev_to_device(jdev);
1249+
1250+
dev_dbg(dev, "%s:%d link_num %u reason %s\n", __func__,
1251+
__LINE__, lnk->link_id, jesd204_state_op_reason_str(reason));
1252+
1253+
return JESD204_STATE_CHANGE_DONE;
1254+
}
1255+
1256+
static const struct jesd204_dev_data adf4371_jesd204_data = {
1257+
.state_ops = {
1258+
[JESD204_OP_LINK_INIT] = {
1259+
.per_link = adf4371_jesd204_link_init,
1260+
},
1261+
},
1262+
1263+
.sizeof_priv = sizeof(struct adf4371_jesd204_priv),
1264+
};
1265+
12371266
static int adf4371_probe(struct spi_device *spi)
12381267
{
12391268
const struct spi_device_id *id = spi_get_device_id(spi);
1269+
struct adf4371_jesd204_priv *priv;
12401270
struct iio_dev *indio_dev;
1271+
struct jesd204_dev *jdev;
12411272
struct adf4371_state *st;
12421273
struct regmap *regmap;
12431274
int ret;
@@ -1294,6 +1325,11 @@ static int adf4371_probe(struct spi_device *spi)
12941325
if (ret < 0)
12951326
return ret;
12961327

1328+
jdev = devm_jesd204_dev_register(&spi->dev, &adf4371_jesd204_data);
1329+
if (IS_ERR(jdev))
1330+
return dev_err_probe(&spi->dev, PTR_ERR(jdev),
1331+
"failed to register JESD204 device\n");
1332+
12971333
ret = adf4371_setup(st);
12981334
if (ret < 0) {
12991335
dev_err(&spi->dev, "ADF4371 setup failed\n");
@@ -1304,7 +1340,17 @@ static int adf4371_probe(struct spi_device *spi)
13041340
if (ret < 0)
13051341
return ret;
13061342

1307-
return devm_iio_device_register(&spi->dev, indio_dev);
1343+
if (jdev) {
1344+
st->jdev = jdev;
1345+
priv = jesd204_dev_priv(jdev);
1346+
priv->adf_st = st;
1347+
}
1348+
1349+
ret = devm_iio_device_register(&spi->dev, indio_dev);
1350+
if (ret < 0)
1351+
return ret;
1352+
1353+
return devm_jesd204_fsm_start(&spi->dev, st->jdev, JESD204_LINKS_ALL);
13081354
}
13091355

13101356
static const struct spi_device_id adf4371_id_table[] = {

0 commit comments

Comments
 (0)