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 ;
@@ -1284,6 +1315,12 @@ static int adf4371_probe(struct spi_device *spi)
1284
1315
indio_dev -> channels = st -> chip_info -> channels ;
1285
1316
indio_dev -> num_channels = st -> chip_info -> num_channels + 1 ; /* Include IIO_TEMP */
1286
1317
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
+
1287
1324
st -> clkin = devm_clk_get_enabled (& spi -> dev , "clkin" );
1288
1325
if (IS_ERR (st -> clkin ))
1289
1326
return PTR_ERR (st -> clkin );
@@ -1294,6 +1331,11 @@ static int adf4371_probe(struct spi_device *spi)
1294
1331
if (ret < 0 )
1295
1332
return ret ;
1296
1333
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
+
1297
1339
ret = adf4371_setup (st );
1298
1340
if (ret < 0 ) {
1299
1341
dev_err (& spi -> dev , "ADF4371 setup failed\n" );
@@ -1304,7 +1346,17 @@ static int adf4371_probe(struct spi_device *spi)
1304
1346
if (ret < 0 )
1305
1347
return ret ;
1306
1348
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 );
1308
1360
}
1309
1361
1310
1362
static const struct spi_device_id adf4371_id_table [] = {
0 commit comments