Skip to content

Commit e958f8a

Browse files
committed
drivers: iio: frequency: adf4371.c: Add FSM ops
Add JESD FSM ops. Signed-off-by: George Mois <[email protected]>
1 parent 7d30c03 commit e958f8a

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

drivers/iio/frequency/adf4371.c

Lines changed: 53 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;
@@ -1284,6 +1315,12 @@ static int adf4371_probe(struct spi_device *spi)
12841315
indio_dev->channels = st->chip_info->channels;
12851316
indio_dev->num_channels = st->chip_info->num_channels + 1; /* Include IIO_TEMP */
12861317

1318+
st->clkin = devm_clk_get(&spi->dev, "clkin");
1319+
if (IS_ERR(st->clkin)) {
1320+
dev_err(&spi->dev, "failed to get clkin\n");
1321+
return PTR_ERR(st->clkin);
1322+
}
1323+
12871324
st->clkin = devm_clk_get_enabled(&spi->dev, "clkin");
12881325
if (IS_ERR(st->clkin))
12891326
return PTR_ERR(st->clkin);
@@ -1294,6 +1331,11 @@ static int adf4371_probe(struct spi_device *spi)
12941331
if (ret < 0)
12951332
return ret;
12961333

1334+
jdev = devm_jesd204_dev_register(&spi->dev, &adf4371_jesd204_data);
1335+
if (IS_ERR(jdev))
1336+
return dev_err_probe(&spi->dev, PTR_ERR(jdev),
1337+
"failed to register JESD204 device\n");
1338+
12971339
ret = adf4371_setup(st);
12981340
if (ret < 0) {
12991341
dev_err(&spi->dev, "ADF4371 setup failed\n");
@@ -1304,7 +1346,17 @@ static int adf4371_probe(struct spi_device *spi)
13041346
if (ret < 0)
13051347
return ret;
13061348

1307-
return devm_iio_device_register(&spi->dev, indio_dev);
1349+
if (jdev) {
1350+
st->jdev = jdev;
1351+
priv = jesd204_dev_priv(jdev);
1352+
priv->adf_st = st;
1353+
}
1354+
1355+
ret = devm_iio_device_register(&spi->dev, indio_dev);
1356+
if (ret < 0)
1357+
return ret;
1358+
1359+
return devm_jesd204_fsm_start(&spi->dev, st->jdev, JESD204_LINKS_ALL);
13081360
}
13091361

13101362
static const struct spi_device_id adf4371_id_table[] = {

0 commit comments

Comments
 (0)