9 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/slab.h>
16 #include <linux/module.h>
19 #include <asm/div64.h>
56 .channel_spacing = 10000,
62 .gpio_lock_detect = -1,
67 int ret,
i, doublebuf = 0;
81 ret = spi_write(st->
spi, &st->val, 4);
92 static int adf4350_reg_access(
struct iio_dev *indio_dev,
93 unsigned reg,
unsigned writeval,
103 if (readval ==
NULL) {
105 ret = adf4350_sync_config(st);
115 static int adf4350_tune_r_cnt(
struct adf4350_state *st,
unsigned short r_cnt)
132 u32 div_gcd, prescaler, chspc;
166 r_cnt = adf4350_tune_r_cnt(st, r_cnt);
174 }
while (r_cnt == 0);
180 }
while (mdiv > st->
r0_int);
193 dev_dbg(&st->
spi->dev,
"VCO: %llu Hz, PFD %lu Hz\n"
194 "REF_DIV %d, R0_INT %d, R0_FRACT %d\n"
195 "R1_MOD %d, RF_DIV %d\nPRESCALER %s, BAND_SEL_DIV %d\n",
239 return adf4350_sync_config(st);
245 const char *
buf,
size_t len)
248 unsigned long long readin;
256 switch ((
u32)
private) {
258 ret = adf4350_set_freq(st, readin);
278 adf4350_sync_config(st);
285 return ret ? ret : len;
294 unsigned long long val;
298 switch ((
u32)
private) {
304 if (gpio_is_valid(st->
pdata->gpio_lock_detect))
324 return ret < 0 ? ret :
sprintf(buf,
"%llu\n", val);
327 #define _ADF4350_EXT_INFO(_name, _ident) { \
329 .read = adf4350_read, \
330 .write = adf4350_write, \
350 .ext_info = adf4350_ext_info,
353 static const struct iio_info adf4350_info = {
354 .debugfs_reg_access = &adf4350_reg_access,
366 dev_warn(&spi->
dev,
"no platform data? using default\n");
372 if (indio_dev ==
NULL)
375 st = iio_priv(indio_dev);
378 if (!IS_ERR(st->
reg)) {
384 spi_set_drvdata(spi, indio_dev);
388 indio_dev->
dev.parent = &spi->
dev;
392 indio_dev->
info = &adf4350_info;
394 indio_dev->
channels = &adf4350_chan;
408 dev_err(&spi->
dev,
"fail to request lock detect GPIO-%d",
410 goto error_disable_reg;
418 goto error_free_gpio;
423 goto error_free_gpio;
432 if (!IS_ERR(st->
reg))
435 if (!IS_ERR(st->
reg))
445 struct iio_dev *indio_dev = spi_get_drvdata(spi);
450 adf4350_sync_config(st);
459 if (gpio_is_valid(st->
pdata->gpio_lock_detect))
478 .probe = adf4350_probe,
480 .id_table = adf4350_id,