22
22
#include <linux/iio/iio.h>
23
23
#include <linux/iio/sysfs.h>
24
24
25
+ #include <linux/jesd204/jesd204.h>
26
+
25
27
/* Registers address macro */
26
28
#define ADF4371_REG (x ) (x)
27
29
@@ -275,6 +277,7 @@ struct adf4371_state {
275
277
* writes.
276
278
*/
277
279
struct mutex lock ;
280
+ struct jesd204_dev * jdev ;
278
281
const struct adf4371_chip_info * chip_info ;
279
282
const char * adf4371_clk_names [4 ];
280
283
unsigned long clkin_freq ;
@@ -297,6 +300,10 @@ struct adf4371_state {
297
300
u8 buf [10 ] __aligned (IIO_DMA_MINALIGN );
298
301
};
299
302
303
+ struct adf4371_jesd204_priv {
304
+ struct adf4371_state * adf_st ;
305
+ };
306
+
300
307
static unsigned long long adf4371_pll_fract_n_get_rate (struct adf4371_state * st ,
301
308
u32 channel )
302
309
{
@@ -1234,10 +1241,34 @@ static int adf4371_clks_register(struct iio_dev *indio_dev)
1234
1241
adf4371_clk_del_provider , st );
1235
1242
}
1236
1243
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
+
1237
1266
static int adf4371_probe (struct spi_device * spi )
1238
1267
{
1239
1268
const struct spi_device_id * id = spi_get_device_id (spi );
1269
+ struct adf4371_jesd204_priv * priv ;
1240
1270
struct iio_dev * indio_dev ;
1271
+ struct jesd204_dev * jdev ;
1241
1272
struct adf4371_state * st ;
1242
1273
struct regmap * regmap ;
1243
1274
int ret ;
@@ -1294,6 +1325,11 @@ static int adf4371_probe(struct spi_device *spi)
1294
1325
if (ret < 0 )
1295
1326
return ret ;
1296
1327
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
+
1297
1333
ret = adf4371_setup (st );
1298
1334
if (ret < 0 ) {
1299
1335
dev_err (& spi -> dev , "ADF4371 setup failed\n" );
@@ -1304,7 +1340,17 @@ static int adf4371_probe(struct spi_device *spi)
1304
1340
if (ret < 0 )
1305
1341
return ret ;
1306
1342
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 );
1308
1354
}
1309
1355
1310
1356
static const struct spi_device_id adf4371_id_table [] = {
0 commit comments