iio: pll: New driver for ADF4350/ADF4351 Wideband Synthesizers (PLL)
Subsystems (4)
[email protected]
maintainerPATCH 1/1 iio: pll: New driver for ADF4350/ADF4351 Wideband Synthesizers (PLL)
From: Michael Hennerich <[email protected]>
This patch adds support for Analog Devices ADF4350/ADF4351 Wideband Synthesizers (35MHz to 4.4GHz).
--- .../staging/iio/Documentation/sysfs-bus-iio-pll | 46 ++ drivers/staging/iio/Kconfig | 1 + drivers/staging/iio/Makefile | 1 + drivers/staging/iio/pll/Kconfig | 16 + drivers/staging/iio/pll/Makefile | 5 + drivers/staging/iio/pll/adf4350.c | 485 ++++++++++++++++++++ drivers/staging/iio/pll/adf4350.h | 121 +++++ 7 files changed, 675 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/Documentation/sysfs-bus-iio-pll create mode 100644 drivers/staging/iio/pll/Kconfig create mode 100644 drivers/staging/iio/pll/Makefile create mode 100644 drivers/staging/iio/pll/adf4350.c create mode 100644 drivers/staging/iio/pll/adf4350.h
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +46 -0
@@ -0,0 +1,46 @@ + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_freq +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Stores PLL Y frequency in Hz. Reading returns the + actual frequency in Hz. When setting a new frequency, the PLL + requires some time to lock. If available, the user can read + out_pllY_locked in order to check whether the PLL has locked + or not. + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_freq_resolution +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Stores PLL Y frequency resolution/channel spacing in Hz. + The value given directly influences the MODULUS used by + the fractional-N PLL. It is assumed that the algorithm + that is used to compute the various dividers, is able to + generate proper values for multiples of channel spacing. + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_refin_freq +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Sets PLL Y REFin frequency in Hz. In some clock chained + applications, the reference frequency used by the PLL may + change during runtime. This attribute allows the user to + adjust the reference frequency accordingly. + The value written has no effect until out_pllY_freq is updated. + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_powerdown +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + If available, this attribute allows the user to power down + the PLL and it's RFOut buffers. This is in particular useful + during REFin changes. + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_locked +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + If available, this attribute allows the user to determine + whether the PLL has locked by reading '1' or not '0'. +
drivers/staging/iio/Kconfig +1 -0
@@ -68,6 +68,7 @@ source "drivers/staging/iio/imu/Kconfig" source "drivers/staging/iio/light/Kconfig" source "drivers/staging/iio/magnetometer/Kconfig" source "drivers/staging/iio/meter/Kconfig" +source "drivers/staging/iio/pll/Kconfig" source "drivers/staging/iio/resolver/Kconfig" source "drivers/staging/iio/trigger/Kconfig"
drivers/staging/iio/Makefile +1 -0
@@ -29,5 +29,6 @@ obj-y += imu/ obj-y += light/ obj-y += magnetometer/ obj-y += meter/ +obj-y += pll/ obj-y += resolver/ obj-y += trigger/
drivers/staging/iio/pll/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# +# Phase-Locked Loop (PLL) frequency synthesizers +# +menu "Phase-Locked Loop (PLL) frequency synthesizers" + +config ADF4350 + tristate "Analog Devices ADF4350/ADF4351 Wideband Synthesizers" + depends on SPI + help + Say yes here to build support for Analog Devices ADF4350/ADF4351 + Wideband Synthesizers. The driver provides direct access via sysfs. + + To compile this driver as a module, choose M here: the + module will be called adf4350. + +endmenu
drivers/staging/iio/pll/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Phase-Locked Loop (PLL) frequency synthesizers +# + +obj-$(CONFIG_ADF4350) += adf4350.o
drivers/staging/iio/pll/adf4350.c new file +485 -0
485 lines not on this page · raw message
drivers/staging/iio/pll/adf4350.h new file +121 -0
121 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Jonathan Cameron
maintainerQuoted 4 lines · On 12/09/2011 01:22 PM, [email protected] wrote:
From: Michael Hennerich <[email protected]>
This patch adds support for Analog Devices ADF4350/ADF4351 Wideband Synthesizers (35MHz to 4.4GHz).
Hi Michael,
Whilst I have no particular issue with having this device driver in IIO I can see that it has considerable overlap with the clock infrastructure. Perhaps you could give a quick summary of why it doesn't make more sense to fit this device in there?
Anyhow, on with the review!
There are a number of 'magic' register elements in the platform data. I'd much prefer to see them broken down into their constituent parts.
Various other bits and bobs inline...
Quoted 23 lines
Signed-off-by Michael Hennerich <[email protected]>--- .../staging/iio/Documentation/sysfs-bus-iio-pll | 46 ++ drivers/staging/iio/Kconfig | 1 + drivers/staging/iio/Makefile | 1 + drivers/staging/iio/pll/Kconfig | 16 + drivers/staging/iio/pll/Makefile | 5 + drivers/staging/iio/pll/adf4350.c | 485 ++++++++++++++++++++ drivers/staging/iio/pll/adf4350.h | 121 +++++ 7 files changed, 675 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/Documentation/sysfs-bus-iio-pll create mode 100644 drivers/staging/iio/pll/Kconfig create mode 100644 drivers/staging/iio/pll/Makefile create mode 100644 drivers/staging/iio/pll/adf4350.c create mode 100644 drivers/staging/iio/pll/adf4350.hdrivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +0
-0
drivers/staging/iio/Documentation/sysfs-bus-iio-pll line 10
Quoted 10 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +10
-0@@ -0,0 +1,46 @@ + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_freq +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Stores PLL Y frequency in Hz. Reading returns the + actual frequency in Hz. When setting a new frequency, the PLL + requires some time to lock. If available, the user can read + out_pllY_locked in order to check whether the PLL has locked + or not.
Is the fact that it is a pll vital? ultimately it's just a frequency output as far as we are concerned (up to the 'locked' stuff). I wonder if we should
be sharing more between this interface and the dds one. (I'm happy to be
convinced either way!) Having said that, the dds docs at least haven't
caught up with the out_ and in_ prefixes which isn't a great start...
How about semantics of having a write to this file wait to return until locking has occured? Just a thought.
drivers/staging/iio/Documentation/sysfs-bus-iio-pll line 21
Quoted 11 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +11
-0+ +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_freq_resolution +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Stores PLL Y frequency resolution/channel spacing in Hz. + The value given directly influences the MODULUS used by + the fractional-N PLL. It is assumed that the algorithm + that is used to compute the various dividers, is able to + generate proper values for multiples of channel spacing. +
Is this dependent on where we are wrt to current frequency?
drivers/staging/iio/Documentation/sysfs-bus-iio-pll line 29
Quoted 8 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +8
-0+What: /sys/bus/iio/devices/iio:deviceX/out_pllY_refin_freq +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Sets PLL Y REFin frequency in Hz. In some clock chained + applications, the reference frequency used by the PLL may + change during runtime. This attribute allows the user to + adjust the reference frequency accordingly.
If this is a clock, doesn't the kernel have some reasonable extensive infrastructure for handling it? linux/clk.h. This isn't an area I know well so freel free to tell me why I'm completely wrong :)
Quoted 108 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +17
-0+ The value written has no effect until out_pllY_freq is updated. + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_powerdown +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + If available, this attribute allows the user to power down + the PLL and it's RFOut buffers. This is in particular useful + during REFin changes. + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_locked +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + If available, this attribute allows the user to determine + whether the PLL has locked by reading '1' or not '0'. +drivers/staging/iio/Kconfig +1
-0@@ -68,6 +68,7 @@ source "drivers/staging/iio/imu/Kconfig" source "drivers/staging/iio/light/Kconfig" source "drivers/staging/iio/magnetometer/Kconfig" source "drivers/staging/iio/meter/Kconfig" +source "drivers/staging/iio/pll/Kconfig" source "drivers/staging/iio/resolver/Kconfig" source "drivers/staging/iio/trigger/Kconfig"drivers/staging/iio/Makefile +1
-0@@ -29,5 +29,6 @@ obj-y += imu/ obj-y += light/ obj-y += magnetometer/ obj-y += meter/ +obj-y += pll/ obj-y += resolver/ obj-y += trigger/drivers/staging/iio/pll/Kconfig new file +16
-0@@ -0,0 +1,16 @@ +# +# Phase-Locked Loop (PLL) frequency synthesizers +# +menu "Phase-Locked Loop (PLL) frequency synthesizers" + +config ADF4350 + tristate "Analog Devices ADF4350/ADF4351 Wideband Synthesizers" + depends on SPI + help + Say yes here to build support for Analog Devices ADF4350/ADF4351 + Wideband Synthesizers. The driver provides direct access via sysfs. + + To compile this driver as a module, choose M here: the + module will be called adf4350. + +endmenudrivers/staging/iio/pll/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# +# Phase-Locked Loop (PLL) frequency synthesizers +# + +obj-$(CONFIG_ADF4350) += adf4350.odrivers/staging/iio/pll/adf4350.c new file +29
-0@@ -0,0 +1,485 @@ +/* +* ADF4350/ADF4351 SPI Wideband Synthesizer driver +* +* Copyright 2011 Analog Devices Inc. +* +* Licensed under the GPL-2. +*/ + +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/spi/spi.h> +#include <linux/regulator/consumer.h> +#include <linux/err.h> +#include <linux/module.h> +#include <linux/gcd.h> +#include <linux/gpio.h> +#include <asm/div64.h> + +#include "../iio.h" +#include "../sysfs.h" + +#include "adf4350.h" + +enum { +ADF4350_SET_FREQ , +ADF4350_SET_FREQ_REFIN , +ADF4350_SET_FREQ_RESOLUTION ,
drivers/staging/iio/pll/adf4350.c line 39
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+ADF4350_PLL_LOCKED , + ADF4350_PLL_PWRDOWN, +}; + +struct adf4350_state { +struct spi_device *spi; +struct regulator *reg; +struct adf4350_platform_data *pdata; +unsigned long clkin; +unsigned long chspc;
Few cryptic names in here I'd like to see coments about..
Quoted 32 lines
drivers/staging/iio/pll/adf4350.c new file +32
-0+unsigned long fpfd; +unsigned long min_out_freq; +unsigned r0_fract; +unsigned r0_int; +unsigned r1_mod; +unsigned r4_rf_div_sel; +unsigned long regs[6 ]; +unsigned long regs_hw[6 ]; + +/* +* DMA (thus cache coherency maintenance) requires the +* transfer buffers to live in their own cache lines. +*/ +__be32 val____cacheline_aligned ; +}; + +static struct adf4350_platform_data default_pdata = { + .clkin =10000000 , + .channel_spacing =10000 , + .r2_user_settings =ADF4350_REG2_PD_POLARITY_POS , +ADF4350_REG2_CHARGE_PUMP_CURR_uA (2500 ), + .r3_user_settings =ADF4350_REG3_12BIT_CLKDIV_MODE (0 ), + .r4_user_settings =ADF4350_REG4_OUTPUT_PWR (0 ) | +ADF4350_REG4_MUTE_TILL_LOCK_EN , + .gpio_lock_detect =-1 , +}; + +static int adf4350_sync_config (struct adf4350_state *st) +{ +int ret, i, doublebuf =0 ; + +for (i =ADF4350_REG5 ; i >=ADF4350_REG0 ; i--) {
drivers/staging/iio/pll/adf4350.c line 81
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+if ((st->regs_hw[i] != st->regs[i]) || + ((i ==ADF4350_REG0 ) && doublebuf)) { + +switch (i) { +case ADF4350_REG1 : +case ADF4350_REG4 : + doublebuf =1 ; +break ; +case ADF4350_REG0 : + doublebuf =0 ;
I don't think this value can ever make any difference to anything.. You will only hit the cease statement when i == ...REG0 and that is last run of of the loop.
Quoted 44 lines
drivers/staging/iio/pll/adf4350.c new file +44
-0+break ; + } + + st->val =cpu_to_be32 (st->regs[i] | i); + ret =spi_write (st->spi, &st->val,4 ); +if (ret <0 ) +return ret; + st->regs_hw[i] = st->regs[i]; +dev_dbg (&st->spi->dev,"[%d] 0x%X\n" , + i, (u32 )st->regs[i] | i); + } + } +return 0 ; +} + +static int adf4350_tune_r_cnt (struct adf4350_state *st,unsigned short r_cnt) +{ +struct adf4350_platform_data *pdata = st->pdata; + +do { + r_cnt++; + st->fpfd = (st->clkin * (pdata->ref_doubler_en ?2 :1 )) / + (r_cnt * (pdata->ref_div2_en ?2 :1 )); + }while (st->fpfd >ADF4350_MAX_FREQ_PFD ); + +return r_cnt; +} + +static int adf4350_set_freq (struct adf4350_state *st,unsigned long long freq) +{ +struct adf4350_platform_data *pdata = st->pdata; +u64 tmp; +u32 div_gcd, prescaler; +u16 mdiv, r_cnt =0 ; +u8 band_sel_div; + +if (freq >ADF4350_MAX_OUT_FREQ || freq < st->min_out_freq) +return -EINVAL ; + +if (freq >ADF4350_MAX_FREQ_45_PRESC ) { + prescaler =ADF4350_REG1_PRESCALER ; + mdiv =75 ; + }else { + prescaler =0 ;
drivers/staging/iio/pll/adf4350.c line 135
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+ mdiv =23 ; + } + + st->r4_rf_div_sel =0 ; + +while (freq <ADF4350_MIN_VCO_FREQ ) { + freq <<=1 ; + st->r4_rf_div_sel++; + } +
/*
* Allow...
Quoted 44 lines
drivers/staging/iio/pll/adf4350.c new file +44
-0+/* Allow a predefined reference division factor +* if not set, compute our own +*/ +if (pdata->ref_div_factor) + r_cnt = pdata->ref_div_factor -1 ; + +do { + r_cnt =adf4350_tune_r_cnt (st, r_cnt); + + st->r1_mod = st->fpfd / st->chspc; +while (st->r1_mod >ADF4350_MAX_MODULUS ) { + r_cnt =adf4350_tune_r_cnt (st, r_cnt); + st->r1_mod = st->fpfd / st->chspc; + } + + tmp = freq * (u64 )st->r1_mod + (st->fpfd >1 ); +do_div (tmp, st->fpfd);/* Div round closest (n + d/2)/d */ + st->r0_fract =do_div (tmp, st->r1_mod); + st->r0_int = tmp; + }while (mdiv > st->r0_int); + + band_sel_div =DIV_ROUND_UP (st->fpfd,ADF4350_MAX_BANDSEL_CLK ); + +if (st->r0_fract && st->r1_mod) { + div_gcd =gcd (st->r1_mod, st->r0_fract); + st->r1_mod /= div_gcd; + st->r0_fract /= div_gcd; + }else { + st->r0_fract =0 ; + st->r1_mod =1 ; + } + +dev_dbg (&st->spi->dev,"VCO: %llu Hz, PFD %lu Hz\n" +"REF_DIV %d, R0_INT %d, R0_FRACT %d\n" +"R1_MOD %d, RF_DIV %d\nPRESCALER %s, BAND_SEL_DIV %d\n" , + freq, st->fpfd, r_cnt, st->r0_int, st->r0_fract, st->r1_mod, +1 << st->r4_rf_div_sel, prescaler ?"8/9" :"4/5" , + band_sel_div); + + st->regs[ADF4350_REG0 ] =ADF4350_REG0_INT (st->r0_int) | +ADF4350_REG0_FRACT (st->r0_fract); + + st->regs[ADF4350_REG1 ] =ADF4350_REG1_PHASE (0 ) | + ADF4350_REG1_MOD(st->r1_mod) |
drivers/staging/iio/pll/adf4350.c line 189
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+ prescaler; + + st->regs[ADF4350_REG3 ] = pdata->r3_user_settings & + (ADF4350_REG3_12BIT_CLKDIV (0xFFF ) | +ADF4350_REG3_12BIT_CLKDIV_MODE (0x3 ) | +ADF4350_REG3_12BIT_CSR_EN | +ADF4351_REG3_CHARGE_CANCELLATION_EN | + ADF4351_REG3_ANTI_BACKLASH_3ns_EN | +ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH ); +
Reorder these? 324 is unusual unless there is a reason...
Quoted 64 lines
drivers/staging/iio/pll/adf4350.c new file +64
-0+ st->regs[ADF4350_REG2 ] = +ADF4350_REG2_10BIT_R_CNT (r_cnt) | +ADF4350_REG2_DOUBLE_BUFF_EN | + (pdata->ref_doubler_en ?ADF4350_REG2_RMULT2_EN :0 ) | + (pdata->ref_div2_en ?ADF4350_REG2_RDIV2_EN :0 ) | + (pdata->r2_user_settings & (ADF4350_REG2_PD_POLARITY_POS | + ADF4350_REG2_LDP_6ns |ADF4350_REG2_LDF_INT_N | +ADF4350_REG2_CHARGE_PUMP_CURR_uA (5000 ) | +ADF4350_REG2_MUXOUT (0x7 ) |ADF4350_REG2_NOISE_MODE (0x9 ))); + + st->regs[ADF4350_REG4 ] = +ADF4350_REG4_FEEDBACK_FUND | +ADF4350_REG4_RF_DIV_SEL (st->r4_rf_div_sel) | +ADF4350_REG4_8BIT_BAND_SEL_CLKDIV (band_sel_div) | +ADF4350_REG4_RF_OUT_EN | + (pdata->r4_user_settings & + (ADF4350_REG4_OUTPUT_PWR (0x3 ) | +ADF4350_REG4_AUX_OUTPUT_PWR (0x3 ) | +ADF4350_REG4_AUX_OUTPUT_EN | +ADF4350_REG4_AUX_OUTPUT_FUND | +ADF4350_REG4_MUTE_TILL_LOCK_EN )); + + st->regs[ADF4350_REG5 ] =ADF4350_REG5_LD_PIN_MODE_DIGITAL ; + +return adf4350_sync_config (st); +} + +static ssize_t adf4350_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct adf4350_state *st =iio_priv (indio_dev); +struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); +unsigned long long readin; +int ret; + + ret =kstrtoull (buf,10 , &readin); +if (ret) +return ret; + +mutex_lock (&indio_dev->mlock); +switch ((u32 )this_attr->address) { +case ADF4350_SET_FREQ : + ret =adf4350_set_freq (st, readin); +break ; +case ADF4350_SET_FREQ_REFIN : +if (readin >ADF4350_MAX_FREQ_REFIN ) + ret = -EINVAL ; +else + st->clkin = readin; +break ; +case ADF4350_SET_FREQ_RESOLUTION : +if (readin ==0 ) + ret = -EINVAL ; +else + st->chspc = readin; +break ; +case ADF4350_PLL_PWRDOWN : +if (readin) + st->regs[ADF4350_REG2 ] |=ADF4350_REG2_POWER_DOWN_EN ; +else + st->regs[ADF4350_REG2 ] &= ~ADF4350_REG2_POWER_DOWN_EN ; +
drivers/staging/iio/pll/adf4350.c line 263
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+adf4350_sync_config (st); +break ; +default : + ret = -ENODEV ; + } +mutex_unlock (&indio_dev->mlock); + +return ret ? ret : len; +} +
One too many white lines here... (I'm in a fussy mood ;)
Quoted 59 lines
drivers/staging/iio/pll/adf4350.c new file +59
-0+ +static ssize_t adf4350_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct adf4350_state *st =iio_priv (indio_dev); +struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); +unsigned long long val; + +mutex_lock (&indio_dev->mlock); +switch ((u32 )this_attr->address) { +case ADF4350_SET_FREQ : + val = (u64)((st->r0_int * st->r1_mod) + st->r0_fract) * + (u64 )st->fpfd; +do_div (val, st->r1_mod * (1 << st->r4_rf_div_sel)); +break ; +case ADF4350_SET_FREQ_REFIN : + val = st->clkin; +break ; +case ADF4350_SET_FREQ_RESOLUTION : + val = st->chspc; +break ; +case ADF4350_PLL_LOCKED : + val =gpio_get_value (st->pdata->gpio_lock_detect); +break ; +case ADF4350_PLL_PWRDOWN : + val = !!(st->regs[ADF4350_REG2 ] &ADF4350_REG2_POWER_DOWN_EN ); +break ; + } +mutex_unlock (&indio_dev->mlock); + +return sprintf (buf,"%llu\n" , val); +} + +static IIO_DEVICE_ATTR(out_pll0_freq, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_SET_FREQ); + +static IIO_DEVICE_ATTR(out_pll0_refin_freq, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_SET_FREQ_REFIN); + +static IIO_DEVICE_ATTR(out_pll0_freq_resolution, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_SET_FREQ_RESOLUTION); + +static IIO_DEVICE_ATTR(out_pll0_locked, S_IRUGO, + adf4350_show, + NULL, + ADF4350_PLL_LOCKED); + +static IIO_DEVICE_ATTR(out_pll0_powerdown, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_PLL_PWRDOWN);
drivers/staging/iio/pll/adf4350.c line 332
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+ +static struct attribute *adf4350_attributes[] = { + &iio_dev_attr_out_pll0_freq.dev_attr.attr, + &iio_dev_attr_out_pll0_refin_freq.dev_attr.attr, + &iio_dev_attr_out_pll0_freq_resolution.dev_attr.attr, + &iio_dev_attr_out_pll0_locked.dev_attr.attr, + &iio_dev_attr_out_pll0_powerdown.dev_attr.attr, +NULL , +}; +
I'd be tempted for simplicity to have this visible and return -ENODEV or similar to indicate it isn't wired up... That will go much cleaner into the chan_spec stuff if we put these in there..
Quoted 36 lines
drivers/staging/iio/pll/adf4350.c new file +36
-0+static mode_t adf4350_attr_is_visible (struct kobject *kobj, +struct attribute *attr,int n) +{ + struct device *dev = container_of(kobj, struct device, kobj); +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct adf4350_state *st =iio_priv (indio_dev); + +mode_t mode = attr->mode; + +if ((attr == &iio_dev_attr_out_pll0_locked.dev_attr.attr) && + !gpio_is_valid (st->pdata->gpio_lock_detect)) + mode =0 ; + +return mode; +} + +static const struct attribute_group adf4350_attribute_group = { + .attrs = adf4350_attributes, + .is_visible = adf4350_attr_is_visible, +}; + +static const struct iio_info adf4350_info = { + .attrs = &adf4350_attribute_group, + .driver_module =THIS_MODULE , +}; + +static int __devinit adf4350_probe (struct spi_device *spi) +{ +struct adf4350_platform_data *pdata = spi->dev.platform_data; +struct iio_dev *indio_dev; +struct adf4350_state *st; +struct regulator *reg; +int ret; + +if (!pdata) { +dev_dbg (&spi->dev,"no platform data? using default\n" );
drivers/staging/iio/pll/adf4350.c line 378
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+ pdata = &default_pdata; + } + + reg =regulator_get (&spi->dev,"vcc" ); +if (!IS_ERR (reg)) { + ret =regulator_enable (reg); +if (ret) + goto error_put_reg; + } +
Why not reorder slightly then you can do the reg and spi bits directly into st->reg and st->spi? Avoids jumping through hoops on removal too.
Quoted 16 lines
drivers/staging/iio/pll/adf4350.c new file +16
-0+ indio_dev =iio_allocate_device (sizeof (*st)); +if (indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_disable_reg; + } + +spi_set_drvdata (spi, indio_dev); + st =iio_priv (indio_dev); + st->reg = reg; + st->spi = spi; + st->pdata = pdata; + + indio_dev->dev.parent = &spi->dev; + indio_dev->name =spi_get_device_id (spi)->name; + indio_dev->info = &adf4350_info; + indio_dev->modes =INDIO_DIRECT_MODE ;
drivers/staging/iio/pll/adf4350.c line 404
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+ + st->chspc = pdata->channel_spacing; + st->clkin = pdata->clkin; + + st->min_out_freq =spi_get_device_id (spi)->driver_data ==4351 ? +ADF4351_MIN_OUT_FREQ :ADF4350_MIN_OUT_FREQ ; + +memset (st->regs_hw,0xFF ,sizeof (st->regs_hw)); + +if (gpio_is_valid (pdata->gpio_lock_detect)) {
gpio_request_one would be slightly cleaner.
Quoted 37 lines
drivers/staging/iio/pll/adf4350.c new file +37
-0+ ret =gpio_request (pdata->gpio_lock_detect, indio_dev->name); +if (ret) { +dev_err (&spi->dev,"fail to request lock detect GPIO-%d" , + pdata->gpio_lock_detect); + goto error_free_device; + } +gpio_direction_input (pdata->gpio_lock_detect); + } + +if (pdata->power_up_frequency) { + ret =adf4350_set_freq (st, pdata->power_up_frequency); +if (ret) + goto error_free_device; + } + + ret =iio_device_register (indio_dev); +if (ret) + goto error_free_device; + +return 0 ; + +error_free_device: +iio_free_device (indio_dev); +error_disable_reg: +if (!IS_ERR (reg)) +regulator_disable (reg); +error_put_reg: +if (!IS_ERR (reg)) +regulator_put (reg); + +return ret; +} + +static int __devexit adf4350_remove(struct spi_device *spi) +{ +struct iio_dev *indio_dev =spi_get_drvdata (spi); +struct adf4350_state *st =iio_priv (indio_dev);
drivers/staging/iio/pll/adf4350.c line 451
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+struct regulator *reg = st->reg; + + st->regs[ADF4350_REG2 ] |=ADF4350_REG2_POWER_DOWN_EN ; +adf4350_sync_config (st); + +iio_device_unregister (indio_dev); +if (!IS_ERR (reg)) { +regulator_disable (reg); +regulator_put (reg); + }
iio_free_device is now explicitly required...
Quoted 42 lines
drivers/staging/iio/pll/adf4350.c new file +34
-0+return 0 ; +} + +static const struct spi_device_id adf4350_id[] = { + {"adf4350" ,4350 }, + {"adf4351" ,4351 }, + {} +}; + +static struct spi_driver adf4350_driver = { + .driver = { + .name ="adf4350" , + .owner =THIS_MODULE , + }, + .probe = adf4350_probe, + .remove =__devexit_p (adf4350_remove), + .id_table = adf4350_id, +}; + +static int __init adf4350_init (void ) +{ +return spi_register_driver (&adf4350_driver); +} +module_init (adf4350_init); + +static void __exit adf4350_exit(void) +{ +spi_unregister_driver (&adf4350_driver); +} +module_exit (adf4350_exit); + +MODULE_AUTHOR ("Michael Hennerich <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices ADF4350/ADF4351 PLL" ); +MODULE_LICENSE ("GPL v2" );drivers/staging/iio/pll/adf4350.h new file +2
-0@@ -0,0 +1,121 @@ +/* +* ADF4350/ADF4351 SPI PLL driver
drivers/staging/iio/pll/adf4350.h line 12
Quoted 10 lines
drivers/staging/iio/pll/adf4350.h new file +10
-0+* +* Copyright 2011 Analog Devices Inc. +* +* Licensed under the GPL-2. +*/ + +#ifndef IIO_PLL_ADF4350_H_ +#define IIO_PLL_ADF4350_H_ + +/* Registers */
Umm.. These doe feel a little bit pointless.. Perhaps just use the values in place of the defines for this one..
Quoted 92 lines
drivers/staging/iio/pll/adf4350.h new file +92
-0+#define ADF4350_REG0 0 +#define ADF4350_REG1 1 +#define ADF4350_REG2 2 +#define ADF4350_REG3 3 +#define ADF4350_REG4 4 +#define ADF4350_REG5 5 + +/* REG0 Bit Definitions */ +#define ADF4350_REG0_FRACT (x) (((x) & 0xFFF) << 3) +#define ADF4350_REG0_INT (x) (((x) & 0xFFFF) << 15) + +/* REG1 Bit Definitions */ +#define ADF4350_REG1_MOD (x) (((x) & 0xFFF) << 3) +#define ADF4350_REG1_PHASE (x) (((x) & 0xFFF) << 15) +#define ADF4350_REG1_PRESCALER (1 << 27) + +/* REG2 Bit Definitions */ +#define ADF4350_REG2_COUNTER_RESET_EN (1 << 3) +#define ADF4350_REG2_CP_THREESTATE_EN (1 << 4) +#define ADF4350_REG2_POWER_DOWN_EN (1 << 5) +#define ADF4350_REG2_PD_POLARITY_POS (1 << 6) +#define ADF4350_REG2_LDP_6ns (1 << 7) +#define ADF4350_REG2_LDP_10ns (0 << 7) +#define ADF4350_REG2_LDF_FRACT_N (0 << 8) +#define ADF4350_REG2_LDF_INT_N (1 << 8) +#define ADF4350_REG2_CHARGE_PUMP_CURR_uA (x) (((((x)-312) / 312) & 0xF) << 9) +#define ADF4350_REG2_DOUBLE_BUFF_EN (1 << 13) +#define ADF4350_REG2_10BIT_R_CNT (x) ((x) << 14) +#define ADF4350_REG2_RDIV2_EN (1 << 24) +#define ADF4350_REG2_RMULT2_EN (1 << 25) +#define ADF4350_REG2_MUXOUT (x) ((x) << 26) +#define ADF4350_REG2_NOISE_MODE (x) ((x) << 29) + +/* REG3 Bit Definitions */ +#define ADF4350_REG3_12BIT_CLKDIV (x) ((x) << 3) +#define ADF4350_REG3_12BIT_CLKDIV_MODE (x) ((x) << 16) +#define ADF4350_REG3_12BIT_CSR_EN (1 << 18) +#define ADF4351_REG3_CHARGE_CANCELLATION_EN (1 << 21) +#define ADF4351_REG3_ANTI_BACKLASH_3ns_EN (1 << 22) +#define ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH (1 << 23) + +/* REG4 Bit Definitions */ +#define ADF4350_REG4_OUTPUT_PWR (x) ((x) << 3) +#define ADF4350_REG4_RF_OUT_EN (1 << 5) +#define ADF4350_REG4_AUX_OUTPUT_PWR (x) ((x) << 6) +#define ADF4350_REG4_AUX_OUTPUT_EN (1 << 8) +#define ADF4350_REG4_AUX_OUTPUT_FUND (1 << 9) +#define ADF4350_REG4_AUX_OUTPUT_DIV (0 << 9) +#define ADF4350_REG4_MUTE_TILL_LOCK_EN (1 << 10) +#define ADF4350_REG4_VCO_PWRDOWN_EN (1 << 11) +#define ADF4350_REG4_8BIT_BAND_SEL_CLKDIV (x) ((x) << 12) +#define ADF4350_REG4_RF_DIV_SEL (x) ((x) << 20) +#define ADF4350_REG4_FEEDBACK_DIVIDED (0 << 23) +#define ADF4350_REG4_FEEDBACK_FUND (1 << 23) + +/* REG5 Bit Definitions */ +#define ADF4350_REG5_LD_PIN_MODE_LOW (0 << 22) +#define ADF4350_REG5_LD_PIN_MODE_DIGITAL (1 << 22) +#define ADF4350_REG5_LD_PIN_MODE_HIGH (3 << 22) + +/* Specifications */ +#define ADF4350_MAX_OUT_FREQ 4400000000ULL/* Hz */ +#define ADF4350_MIN_OUT_FREQ 137500000/* Hz */ +#define ADF4351_MIN_OUT_FREQ 34375000/* Hz */ +#define ADF4350_MIN_VCO_FREQ 2200000000ULL/* Hz */ +#define ADF4350_MAX_FREQ_45_PRESC 3000000000ULL/* Hz */ +#define ADF4350_MAX_FREQ_PFD 32000000/* Hz */ +#define ADF4350_MAX_BANDSEL_CLK 125000/* Hz */ +#define ADF4350_MAX_FREQ_REFIN 250000000/* Hz */ +#define ADF4350_MAX_MODULUS 4095 + +/* +* TODO: struct adf4350_platform_data needs to go into include/linux/iio +*/ + +/** +* struct adf4350_platform_data - platform specific information +* @clkin: REFin frequency in Hz. +* @channel_spacing: Channel spacing in Hz (influences MODULUS). +* @power_up_frequency: Optional, If set in Hz the PLL tunes to the desired +* frequency on probe. +* @ref_div_factor: Optional, if set the driver skips dynamic calculation +* and uses this default value instead. +* @ref_doubler_en: Enables reference doubler. +* @ref_div2_en: Enables reference divider. +* @r2_user_settings: User defined settings for ADF4350/1 REGISTER_2. +* @r3_user_settings: User defined settings for ADF4350/1 REGISTER_3. +* @r4_user_settings: User defined settings for ADF4350/1 REGISTER_4. +* @gpio_lock_detect: Optional, if set with a valid GPIO number, +* a PLL_LOCKED device attribute is created. +* If not used - set to -1. +*/
drivers/staging/iio/pll/adf4350.h line 114
Quoted 10 lines
drivers/staging/iio/pll/adf4350.h new file +10
-0+ +struct adf4350_platform_data { +unsigned long clkin; +unsigned long channel_spacing; +unsigned long long power_up_frequency; + +unsigned short ref_div_factor;/* 10-bit R counter */ +bool ref_doubler_en; +bool ref_div2_en; +
These next three are in the magic value category. I'd much rather see them broken down into their constituent elements.
Quoted 7 lines
drivers/staging/iio/pll/adf4350.h new file +7
-0+unsigned r2_user_settings; +unsigned r3_user_settings; +unsigned r4_user_settings; + int gpio_lock_detect; +}; + +#endif /* IIO_PLL_ADF4350_H_ */
Michael Hennerich
maintainerQuoted 11 lines · Jonathan Cameron
Quoted 4 lines · On 12/09/2011 01:22 PM, [email protected] wrote:
From: Michael Hennerich<[email protected]>
This patch adds support for Analog Devices ADF4350/ADF4351 Wideband Synthesizers (35MHz to 4.4GHz).
Hi Michael,
Whilst I have no particular issue with having this device driver in IIO I can see that it has considerable overlap with the clock infrastructure. Perhaps you could give a quick summary of why it doesn't make more sense to fit this device in there?
Hi Jonathan,
The in-kernel clock infrastructure is aimed for SoC like clock distribution. Typically one master clock,
and a number of scaled down clocks for the various clock salve peripherals. For example typical clock slaves here are:
SPI, I2C, UART, MMC, Video, etc.
This PLL device is more aimed for generating a standalone clock used in industrial and communications applications.
For example a Local Oscillator (LO) Frequency used with a Wide-band Mixer generating another Intermediate Frequency (IF) which is then samples by an ADC.
Also PLL input clocks are typically high stability, low phase noise clock sources, an not something derived from a SoC clock.
Quoted 34 lines
There are a number of 'magic' register elements in the platform data. I'd much prefer to see them broken down into their constituent parts.
Various other bits and bobs inline...
Quoted 29 lines
Signed-off-by Michael Hennerich<[email protected]>--- .../staging/iio/Documentation/sysfs-bus-iio-pll | 46 ++ drivers/staging/iio/Kconfig | 1 + drivers/staging/iio/Makefile | 1 + drivers/staging/iio/pll/Kconfig | 16 + drivers/staging/iio/pll/Makefile | 5 + drivers/staging/iio/pll/adf4350.c | 485 ++++++++++++++++++++ drivers/staging/iio/pll/adf4350.h | 121 +++++ 7 files changed, 675 insertions(+), 0 deletions(-)create mode 100644
drivers/staging/iio/Documentation/sysfs-bus-iio-pllcreate mode 100644drivers/staging/iio/pll/Kconfig
create mode 100644drivers/staging/iio/pll/Makefile
create mode 100644drivers/staging/iio/pll/adf4350.ccreate mode 100644drivers/staging/iio/pll/adf4350.hdrivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +7
-0@@ -0,0 +1,46 @@ + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_freq +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Stores PLL Y frequency in Hz. Reading returns the + actual frequency in Hz. When setting a new frequency, the PLL
Quoted 8 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll line 10
Quoted 3 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +3
-0+ requires some time to lock. If available, the user can read + out_pllY_locked in order to check whether the PLL has locked + or not.Is the fact that it is a pll vital? ultimately it's just a frequency output as far as we are concerned (up to the 'locked' stuff). I wonder if we should
be sharing more between this interface and the dds one. (I'm happy to be convinced either way!)
In fact - I was thinking about the same thing. The DDS parts are typically different from the PLL, however there is a common denominator.
How about we rename iio/dds to iio/frequency.
But I'm a bit unsure about the naming convention.
For dds we have out_ddsX_freqY or out_ddsX_outY_enable. shall we keep that scheme and likewise add:out_pllX_freqY, or move on to something like:
out_devX_freqY ?out_freqX_Y ?out_outX_Y_enable ?
Quoted 2 lines
Having said that, the dds docs at least haven't
caught up with theout_andin_prefixes which isn't a great start...
Thanks - I noticed that and a patch is already in my queue.
Quoted 2 lines
How about semantics of having a write to this file wait to return until locking has occured? Just a thought.
I could do that - but we need the pll_locked attribute anyways. The PLL could unlock under certain circumstances.
We therefore need an option to check the lock state.
Quoted 4 lines
Quoted 4 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +4
-0+ +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_freq_resolution +KernelVersion: 3.2.0 +Contact: [email protected]
Quoted 8 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll line 21
Quoted 7 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +7
-0+Description: + Stores PLL Y frequency resolution/channel spacing in Hz. + The value given directly influences the MODULUS used by + the fractional-N PLL. It is assumed that the algorithm + that is used to compute the various dividers, is able to + generate proper values for multiples of channel spacing. +Is this dependent on where we are wrt to current frequency?
No, it gives you the option so set a channel spacing,
used in your application. For example 200kHz for UMTS, GSM
and 15kHz for LTE.
The value written goes into account, only in subsequent writes to out_pllY_freq.
Quoted 11 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll line 29
Quoted 8 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +8
-0+What: /sys/bus/iio/devices/iio:deviceX/out_pllY_refin_freq +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Sets PLL Y REFin frequency in Hz. In some clock chained + applications, the reference frequency used by the PLL may + change during runtime. This attribute allows the user to + adjust the reference frequency accordingly.If this is a clock, doesn't the kernel have some reasonable extensive infrastructure for handling it?
linux/clk.h. This isn't an area I know well so freel free to tell me why I'm completely wrong :)
See comment above. The REFin frequency might be supplied by something not under control of the kernel.
Quoted 111 lines
Quoted 111 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +17
-0+ The value written has no effect until out_pllY_freq is updated. + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_powerdown +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + If available, this attribute allows the user to power down + the PLL and it's RFOut buffers. This is in particular useful + during REFin changes. + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_locked +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + If available, this attribute allows the user to determine + whether the PLL has locked by reading '1' or not '0'. +drivers/staging/iio/Kconfig +1
-0@@ -68,6 +68,7 @@ source "drivers/staging/iio/imu/Kconfig" source "drivers/staging/iio/light/Kconfig" source "drivers/staging/iio/magnetometer/Kconfig" source "drivers/staging/iio/meter/Kconfig" +source "drivers/staging/iio/pll/Kconfig" source "drivers/staging/iio/resolver/Kconfig" source "drivers/staging/iio/trigger/Kconfig"drivers/staging/iio/Makefile +1
-0@@ -29,5 +29,6 @@ obj-y += imu/ obj-y += light/ obj-y += magnetometer/ obj-y += meter/ +obj-y += pll/ obj-y += resolver/ obj-y += trigger/drivers/staging/iio/pll/Kconfig new file +16
-0@@ -0,0 +1,16 @@ +# +# Phase-Locked Loop (PLL) frequency synthesizers +# +menu "Phase-Locked Loop (PLL) frequency synthesizers" + +config ADF4350 + tristate "Analog Devices ADF4350/ADF4351 Wideband Synthesizers" + depends on SPI + help + Say yes here to build support for Analog Devices ADF4350/ADF4351 + Wideband Synthesizers. The driver provides direct access via sysfs. + + To compile this driver as a module, choose M here: the + module will be called adf4350. + +endmenudrivers/staging/iio/pll/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# +# Phase-Locked Loop (PLL) frequency synthesizers +# + +obj-$(CONFIG_ADF4350) += adf4350.odrivers/staging/iio/pll/adf4350.c new file +32
-0@@ -0,0 +1,485 @@ +/* +* ADF4350/ADF4351 SPI Wideband Synthesizer driver +* +* Copyright 2011 Analog Devices Inc. +* +* Licensed under the GPL-2. +*/ + +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/spi/spi.h> +#include <linux/regulator/consumer.h> +#include <linux/err.h> +#include <linux/module.h> +#include <linux/gcd.h> +#include <linux/gpio.h> +#include <asm/div64.h> + +#include "../iio.h" +#include "../sysfs.h" + +#include "adf4350.h" + +enum { +ADF4350_SET_FREQ , +ADF4350_SET_FREQ_REFIN , +ADF4350_SET_FREQ_RESOLUTION , +ADF4350_PLL_LOCKED , +ADF4350_PLL_PWRDOWN , +};
Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 39
Quoted 7 lines
drivers/staging/iio/pll/adf4350.c new file +7
-0+ +struct adf4350_state { +struct spi_device *spi; +struct regulator *reg; +struct adf4350_platform_data *pdata; +unsigned long clkin; +unsigned long chspc;Few cryptic names in here I'd like to see coments about..
PFD= Phase frequency detector
chspc = channel spacing
I'll add some comments.
Quoted 37 lines
Quoted 37 lines
drivers/staging/iio/pll/adf4350.c new file +37
-0+unsigned long fpfd; +unsigned long min_out_freq; +unsigned r0_fract; +unsigned r0_int; +unsigned r1_mod; +unsigned r4_rf_div_sel; +unsigned long regs[6 ]; +unsigned long regs_hw[6 ]; + +/* +* DMA (thus cache coherency maintenance) requires the +* transfer buffers to live in their own cache lines. +*/ +__be32 val____cacheline_aligned ; +}; + +static struct adf4350_platform_data default_pdata = { + .clkin =10000000 , + .channel_spacing =10000 , + .r2_user_settings =ADF4350_REG2_PD_POLARITY_POS , +ADF4350_REG2_CHARGE_PUMP_CURR_uA (2500 ), + .r3_user_settings =ADF4350_REG3_12BIT_CLKDIV_MODE (0 ), + .r4_user_settings =ADF4350_REG4_OUTPUT_PWR (0 ) | +ADF4350_REG4_MUTE_TILL_LOCK_EN , + .gpio_lock_detect =-1 , +}; + +static int adf4350_sync_config (struct adf4350_state *st) +{ +int ret, i, doublebuf =0 ; + +for (i =ADF4350_REG5 ; i>=ADF4350_REG0 ; i--) { +if ((st->regs_hw[i] != st->regs[i]) || + ((i ==ADF4350_REG0 )&& doublebuf)) { + +switch (i) { +case ADF4350_REG1 :
Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 81
Quoted 5 lines
drivers/staging/iio/pll/adf4350.c new file +5
-0+case ADF4350_REG4 : + doublebuf =1 ; +break ; +case ADF4350_REG0 : + doublebuf =0 ;I don't think this value can ever make any difference to anything.. You will only hit the cease statement when i == ...REG0 and that is last run of of the loop.
I know - I'll remove this case.
Quoted 103 lines
Quoted 44 lines
drivers/staging/iio/pll/adf4350.c new file +44
-0+break ; + } + + st->val =cpu_to_be32 (st->regs[i] | i); + ret =spi_write (st->spi,&st->val,4 ); +if (ret<0 ) +return ret; + st->regs_hw[i] = st->regs[i]; +dev_dbg (&st->spi->dev,"[%d] 0x%X\n" , + i, (u32 )st->regs[i] | i); + } + } +return 0 ; +} + +static int adf4350_tune_r_cnt (struct adf4350_state *st,unsigned short r_cnt) +{ +struct adf4350_platform_data *pdata = st->pdata; + +do { + r_cnt++; + st->fpfd = (st->clkin * (pdata->ref_doubler_en ?2 :1 )) / + (r_cnt * (pdata->ref_div2_en ?2 :1 )); + }while (st->fpfd>ADF4350_MAX_FREQ_PFD ); + +return r_cnt; +} + +static int adf4350_set_freq (struct adf4350_state *st,unsigned long long freq) +{ +struct adf4350_platform_data *pdata = st->pdata; +u64 tmp; +u32 div_gcd, prescaler; +u16 mdiv, r_cnt =0 ; +u8 band_sel_div; + +if (freq>ADF4350_MAX_OUT_FREQ || freq< st->min_out_freq) +return -EINVAL ; + +if (freq>ADF4350_MAX_FREQ_45_PRESC ) { + prescaler =ADF4350_REG1_PRESCALER ; + mdiv =75 ; + }else { + prescaler =0 ;drivers/staging/iio/pll/adf4350.c line 135
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+ mdiv =23 ; + } + + st->r4_rf_div_sel =0 ; + +while (freq<ADF4350_MIN_VCO_FREQ ) { + freq<<=1 ; + st->r4_rf_div_sel++; + } +/*
* Allow...Quoted 47 lines
drivers/staging/iio/pll/adf4350.c new file +47
-0+/* Allow a predefined reference division factor +* if not set, compute our own +*/ +if (pdata->ref_div_factor) + r_cnt = pdata->ref_div_factor -1 ; + +do { + r_cnt =adf4350_tune_r_cnt (st, r_cnt); + + st->r1_mod = st->fpfd / st->chspc; +while (st->r1_mod>ADF4350_MAX_MODULUS ) { + r_cnt =adf4350_tune_r_cnt (st, r_cnt); + st->r1_mod = st->fpfd / st->chspc; + } + + tmp = freq * (u64 )st->r1_mod + (st->fpfd>1 ); +do_div (tmp, st->fpfd);/* Div round closest (n + d/2)/d */ + st->r0_fract =do_div (tmp, st->r1_mod); + st->r0_int = tmp; + }while (mdiv> st->r0_int); + + band_sel_div =DIV_ROUND_UP (st->fpfd,ADF4350_MAX_BANDSEL_CLK ); + +if (st->r0_fract&& st->r1_mod) { + div_gcd =gcd (st->r1_mod, st->r0_fract); + st->r1_mod /= div_gcd; + st->r0_fract /= div_gcd; + }else { + st->r0_fract =0 ; + st->r1_mod =1 ; + } + +dev_dbg (&st->spi->dev,"VCO: %llu Hz, PFD %lu Hz\n" +"REF_DIV %d, R0_INT %d, R0_FRACT %d\n" +"R1_MOD %d, RF_DIV %d\nPRESCALER %s, BAND_SEL_DIV %d\n" , + freq, st->fpfd, r_cnt, st->r0_int, st->r0_fract, st->r1_mod, +1 << st->r4_rf_div_sel, prescaler ?"8/9" :"4/5" , + band_sel_div); + + st->regs[ADF4350_REG0 ] =ADF4350_REG0_INT (st->r0_int) | +ADF4350_REG0_FRACT (st->r0_fract); + + st->regs[ADF4350_REG1 ] =ADF4350_REG1_PHASE (0 ) | +ADF4350_REG1_MOD (st->r1_mod) | + prescaler; + + st->regs[ADF4350_REG3] = pdata->r3_user_settings&
Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 189
Quoted 7 lines
drivers/staging/iio/pll/adf4350.c new file +7
-0+ (ADF4350_REG3_12BIT_CLKDIV (0xFFF ) | +ADF4350_REG3_12BIT_CLKDIV_MODE (0x3 ) | +ADF4350_REG3_12BIT_CSR_EN | +ADF4351_REG3_CHARGE_CANCELLATION_EN | + ADF4351_REG3_ANTI_BACKLASH_3ns_EN | +ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH ); +Reorder these? 324 is unusual unless there is a reason...
The reason was, to group the indention style.
Quoted 139 lines
Quoted 64 lines
drivers/staging/iio/pll/adf4350.c new file +64
-0+ st->regs[ADF4350_REG2 ] = +ADF4350_REG2_10BIT_R_CNT (r_cnt) | +ADF4350_REG2_DOUBLE_BUFF_EN | + (pdata->ref_doubler_en ?ADF4350_REG2_RMULT2_EN :0 ) | + (pdata->ref_div2_en ?ADF4350_REG2_RDIV2_EN :0 ) | + (pdata->r2_user_settings& (ADF4350_REG2_PD_POLARITY_POS | + ADF4350_REG2_LDP_6ns |ADF4350_REG2_LDF_INT_N | +ADF4350_REG2_CHARGE_PUMP_CURR_uA (5000 ) | +ADF4350_REG2_MUXOUT (0x7 ) |ADF4350_REG2_NOISE_MODE (0x9 ))); + + st->regs[ADF4350_REG4 ] = +ADF4350_REG4_FEEDBACK_FUND | +ADF4350_REG4_RF_DIV_SEL (st->r4_rf_div_sel) | +ADF4350_REG4_8BIT_BAND_SEL_CLKDIV (band_sel_div) | +ADF4350_REG4_RF_OUT_EN | + (pdata->r4_user_settings& + (ADF4350_REG4_OUTPUT_PWR (0x3 ) | +ADF4350_REG4_AUX_OUTPUT_PWR (0x3 ) | +ADF4350_REG4_AUX_OUTPUT_EN | +ADF4350_REG4_AUX_OUTPUT_FUND | +ADF4350_REG4_MUTE_TILL_LOCK_EN )); + + st->regs[ADF4350_REG5 ] =ADF4350_REG5_LD_PIN_MODE_DIGITAL ; + +return adf4350_sync_config (st); +} + +static ssize_t adf4350_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct adf4350_state *st =iio_priv (indio_dev); +struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); +unsigned long long readin; +int ret; + + ret =kstrtoull (buf,10 ,&readin); +if (ret) +return ret; + +mutex_lock (&indio_dev->mlock); +switch ((u32 )this_attr->address) { +case ADF4350_SET_FREQ : + ret =adf4350_set_freq (st, readin); +break ; +case ADF4350_SET_FREQ_REFIN : +if (readin>ADF4350_MAX_FREQ_REFIN ) + ret = -EINVAL ; +else + st->clkin = readin; +break ; +case ADF4350_SET_FREQ_RESOLUTION : +if (readin ==0 ) + ret = -EINVAL ; +else + st->chspc = readin; +break ; +case ADF4350_PLL_PWRDOWN : +if (readin) + st->regs[ADF4350_REG2 ] |=ADF4350_REG2_POWER_DOWN_EN ; +else + st->regs[ADF4350_REG2 ]&= ~ADF4350_REG2_POWER_DOWN_EN ; +drivers/staging/iio/pll/adf4350.c line 263
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+adf4350_sync_config (st); +break ; +default : + ret = -ENODEV ; + } +mutex_unlock (&indio_dev->mlock); + +return ret ? ret : len; +} +One too many white lines here... (I'm in a fussy mood ;)
Quoted 64 lines
drivers/staging/iio/pll/adf4350.c new file +64
-0+ +static ssize_t adf4350_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct adf4350_state *st =iio_priv (indio_dev); +struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); +unsigned long long val; + +mutex_lock (&indio_dev->mlock); +switch ((u32 )this_attr->address) { +case ADF4350_SET_FREQ : + val = (u64)((st->r0_int * st->r1_mod) + st->r0_fract) * + (u64 )st->fpfd; +do_div (val, st->r1_mod * (1 << st->r4_rf_div_sel)); +break ; +case ADF4350_SET_FREQ_REFIN : + val = st->clkin; +break ; +case ADF4350_SET_FREQ_RESOLUTION : + val = st->chspc; +break ; +case ADF4350_PLL_LOCKED : + val =gpio_get_value (st->pdata->gpio_lock_detect); +break ; +case ADF4350_PLL_PWRDOWN : + val = !!(st->regs[ADF4350_REG2 ]&ADF4350_REG2_POWER_DOWN_EN ); +break ; + } +mutex_unlock (&indio_dev->mlock); + +return sprintf (buf,"%llu\n" , val); +} + +static IIO_DEVICE_ATTR(out_pll0_freq, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_SET_FREQ); + +static IIO_DEVICE_ATTR(out_pll0_refin_freq, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_SET_FREQ_REFIN); + +static IIO_DEVICE_ATTR(out_pll0_freq_resolution, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_SET_FREQ_RESOLUTION); + +static IIO_DEVICE_ATTR(out_pll0_locked, S_IRUGO, + adf4350_show, + NULL, + ADF4350_PLL_LOCKED); + +static IIO_DEVICE_ATTR(out_pll0_powerdown, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_PLL_PWRDOWN); + +static struct attribute *adf4350_attributes[] = { +&iio_dev_attr_out_pll0_freq.dev_attr.attr, +&iio_dev_attr_out_pll0_refin_freq.dev_attr.attr, +&iio_dev_attr_out_pll0_freq_resolution.dev_attr.attr,
Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 332
Quoted 5 lines
drivers/staging/iio/pll/adf4350.c new file +5
-0+&iio_dev_attr_out_pll0_locked.dev_attr.attr, +&iio_dev_attr_out_pll0_powerdown.dev_attr.attr, + NULL, +}; +I'd be tempted for simplicity to have this visible and return
-ENODEVor similar to indicate it isn't wired up... That will go much cleaner into thechan_specstuff if we put these in there..
ok.
BTW - the is_visible stuff is currently not working in IIO at all.
Since iio_device_register_sysfs() doesn't copy this attribute_group member into the new group. Lars will send a patch shortly.
Quoted 40 lines
Quoted 40 lines
drivers/staging/iio/pll/adf4350.c new file +40
-0+static mode_t adf4350_attr_is_visible (struct kobject *kobj, +struct attribute *attr,int n) +{ + struct device *dev = container_of(kobj, struct device, kobj); +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct adf4350_state *st =iio_priv (indio_dev); + +mode_t mode = attr->mode; + +if ((attr ==&iio_dev_attr_out_pll0_locked.dev_attr.attr)&& + !gpio_is_valid (st->pdata->gpio_lock_detect)) + mode =0 ; + +return mode; +} + +static const struct attribute_group adf4350_attribute_group = { + .attrs = adf4350_attributes, + .is_visible = adf4350_attr_is_visible, +}; + +static const struct iio_info adf4350_info = { + .attrs =&adf4350_attribute_group, + .driver_module =THIS_MODULE , +}; + +static int __devinit adf4350_probe (struct spi_device *spi) +{ +struct adf4350_platform_data *pdata = spi->dev.platform_data; +struct iio_dev *indio_dev; +struct adf4350_state *st; +struct regulator *reg; +int ret; + +if (!pdata) { +dev_dbg (&spi->dev,"no platform data? using default\n" ); + pdata =&default_pdata; + } + + reg =regulator_get (&spi->dev,"vcc" );
Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 378
Quoted 6 lines
drivers/staging/iio/pll/adf4350.c new file +6
-0+if (!IS_ERR (reg)) { + ret =regulator_enable (reg); +if (ret) + goto error_put_reg; + } +Why not reorder slightly then you can do the reg and spi bits directly into
st->regandst->spi? Avoids jumping through hoops on removal too.
ok
Quoted 19 lines
Quoted 19 lines
drivers/staging/iio/pll/adf4350.c new file +19
-0+ indio_dev =iio_allocate_device (sizeof (*st)); +if (indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_disable_reg; + } + +spi_set_drvdata (spi, indio_dev); + st =iio_priv (indio_dev); + st->reg = reg; + st->spi = spi; + st->pdata = pdata; + + indio_dev->dev.parent =&spi->dev; + indio_dev->name =spi_get_device_id (spi)->name; + indio_dev->info =&adf4350_info; + indio_dev->modes =INDIO_DIRECT_MODE ; + + st->chspc = pdata->channel_spacing; + st->clkin = pdata->clkin;
Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 404
Quoted 7 lines
drivers/staging/iio/pll/adf4350.c new file +7
-0+ + st->min_out_freq =spi_get_device_id (spi)->driver_data ==4351 ? +ADF4351_MIN_OUT_FREQ :ADF4350_MIN_OUT_FREQ ; + +memset (st->regs_hw,0xFF ,sizeof (st->regs_hw)); + +if (gpio_is_valid (pdata->gpio_lock_detect)) {
gpio_request_onewould be slightly cleaner.
Well - it adds another dependency to GPIOLIB.
Quoted 40 lines
Quoted 40 lines
drivers/staging/iio/pll/adf4350.c new file +40
-0+ ret =gpio_request (pdata->gpio_lock_detect, indio_dev->name); +if (ret) { +dev_err (&spi->dev,"fail to request lock detect GPIO-%d" , + pdata->gpio_lock_detect); + goto error_free_device; + } +gpio_direction_input (pdata->gpio_lock_detect); + } + +if (pdata->power_up_frequency) { + ret =adf4350_set_freq (st, pdata->power_up_frequency); +if (ret) + goto error_free_device; + } + + ret =iio_device_register (indio_dev); +if (ret) + goto error_free_device; + +return 0 ; + +error_free_device: +iio_free_device (indio_dev); +error_disable_reg: +if (!IS_ERR (reg)) +regulator_disable (reg); +error_put_reg: +if (!IS_ERR (reg)) +regulator_put (reg); + +return ret; +} + +static int __devexit adf4350_remove(struct spi_device *spi) +{ +struct iio_dev *indio_dev =spi_get_drvdata (spi); +struct adf4350_state *st =iio_priv (indio_dev); +struct regulator *reg = st->reg; + + st->regs[ADF4350_REG2 ] |=ADF4350_REG2_POWER_DOWN_EN ;
Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 451
Quoted 7 lines
drivers/staging/iio/pll/adf4350.c new file +7
-0+adf4350_sync_config (st); + +iio_device_unregister (indio_dev); +if (!IS_ERR (reg)) { +regulator_disable (reg); +regulator_put (reg); + }
iio_free_deviceis now explicitly required...
Ups. Good catch.
Quoted 46 lines
Quoted 46 lines
drivers/staging/iio/pll/adf4350.c new file +34
-0+return 0 ; +} + +static const struct spi_device_id adf4350_id[] = { + {"adf4350" ,4350 }, + {"adf4351" ,4351 }, + {} +}; + +static struct spi_driver adf4350_driver = { + .driver = { + .name ="adf4350" , + .owner =THIS_MODULE , + }, + .probe = adf4350_probe, + .remove =__devexit_p (adf4350_remove), + .id_table = adf4350_id, +}; + +static int __init adf4350_init (void ) +{ +return spi_register_driver (&adf4350_driver); +} +module_init (adf4350_init); + +static void __exit adf4350_exit(void) +{ +spi_unregister_driver (&adf4350_driver); +} +module_exit (adf4350_exit); + +MODULE_AUTHOR ("Michael Hennerich<[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices ADF4350/ADF4351 PLL" ); +MODULE_LICENSE ("GPL v2" );drivers/staging/iio/pll/adf4350.h new file +6
-0@@ -0,0 +1,121 @@ +/* +* ADF4350/ADF4351 SPI PLL driver +* +* Copyright 2011 Analog Devices Inc. +* +* Licensed under the GPL-2.
Quoted 8 lines
drivers/staging/iio/pll/adf4350.h line 12
Quoted 6 lines
drivers/staging/iio/pll/adf4350.h new file +6
-0+*/ + +#ifndef IIO_PLL_ADF4350_H_ +#define IIO_PLL_ADF4350_H_ + +/* Registers */ Umm.. These doe feel a little bit pointless.. Perhaps just use the values in place of the defines for this one..
Hmm - I prefer to keep them.
They make sure that the reader understands that we touching device registers. Ideally I would have named them a little bit more descriptive, however given the fact that so many different bits and fields are stuffed into single registers makes it difficult to find a proper name.
Quoted 96 lines
Quoted 96 lines
drivers/staging/iio/pll/adf4350.h new file +96
-0+#define ADF4350_REG0 0 +#define ADF4350_REG1 1 +#define ADF4350_REG2 2 +#define ADF4350_REG3 3 +#define ADF4350_REG4 4 +#define ADF4350_REG5 5 + +/* REG0 Bit Definitions */ +#define ADF4350_REG0_FRACT (x) (((x)& 0xFFF)<< 3) +#define ADF4350_REG0_INT (x) (((x)& 0xFFFF)<< 15) + +/* REG1 Bit Definitions */ +#define ADF4350_REG1_MOD (x) (((x)& 0xFFF)<< 3) +#define ADF4350_REG1_PHASE (x) (((x)& 0xFFF)<< 15) +#define ADF4350_REG1_PRESCALER (1<< 27) + +/* REG2 Bit Definitions */ +#define ADF4350_REG2_COUNTER_RESET_EN (1<< 3) +#define ADF4350_REG2_CP_THREESTATE_EN (1<< 4) +#define ADF4350_REG2_POWER_DOWN_EN (1<< 5) +#define ADF4350_REG2_PD_POLARITY_POS (1<< 6) +#define ADF4350_REG2_LDP_6ns (1<< 7) +#define ADF4350_REG2_LDP_10ns (0<< 7) +#define ADF4350_REG2_LDF_FRACT_N (0<< 8) +#define ADF4350_REG2_LDF_INT_N (1<< 8) +#define ADF4350_REG2_CHARGE_PUMP_CURR_uA (x) (((((x)-312) / 312)& 0xF)<< 9) +#define ADF4350_REG2_DOUBLE_BUFF_EN (1<< 13) +#define ADF4350_REG2_10BIT_R_CNT (x) ((x)<< 14) +#define ADF4350_REG2_RDIV2_EN (1<< 24) +#define ADF4350_REG2_RMULT2_EN (1<< 25) +#define ADF4350_REG2_MUXOUT (x) ((x)<< 26) +#define ADF4350_REG2_NOISE_MODE (x) ((x)<< 29) + +/* REG3 Bit Definitions */ +#define ADF4350_REG3_12BIT_CLKDIV (x) ((x)<< 3) +#define ADF4350_REG3_12BIT_CLKDIV_MODE (x) ((x)<< 16) +#define ADF4350_REG3_12BIT_CSR_EN (1<< 18) +#define ADF4351_REG3_CHARGE_CANCELLATION_EN (1<< 21) +#define ADF4351_REG3_ANTI_BACKLASH_3ns_EN (1<< 22) +#define ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH (1<< 23) + +/* REG4 Bit Definitions */ +#define ADF4350_REG4_OUTPUT_PWR (x) ((x)<< 3) +#define ADF4350_REG4_RF_OUT_EN (1<< 5) +#define ADF4350_REG4_AUX_OUTPUT_PWR (x) ((x)<< 6) +#define ADF4350_REG4_AUX_OUTPUT_EN (1<< 8) +#define ADF4350_REG4_AUX_OUTPUT_FUND (1<< 9) +#define ADF4350_REG4_AUX_OUTPUT_DIV (0<< 9) +#define ADF4350_REG4_MUTE_TILL_LOCK_EN (1<< 10) +#define ADF4350_REG4_VCO_PWRDOWN_EN (1<< 11) +#define ADF4350_REG4_8BIT_BAND_SEL_CLKDIV (x) ((x)<< 12) +#define ADF4350_REG4_RF_DIV_SEL (x) ((x)<< 20) +#define ADF4350_REG4_FEEDBACK_DIVIDED (0<< 23) +#define ADF4350_REG4_FEEDBACK_FUND (1<< 23) + +/* REG5 Bit Definitions */ +#define ADF4350_REG5_LD_PIN_MODE_LOW (0<< 22) +#define ADF4350_REG5_LD_PIN_MODE_DIGITAL (1<< 22) +#define ADF4350_REG5_LD_PIN_MODE_HIGH (3<< 22) + +/* Specifications */ +#define ADF4350_MAX_OUT_FREQ 4400000000ULL/* Hz */ +#define ADF4350_MIN_OUT_FREQ 137500000/* Hz */ +#define ADF4351_MIN_OUT_FREQ 34375000/* Hz */ +#define ADF4350_MIN_VCO_FREQ 2200000000ULL/* Hz */ +#define ADF4350_MAX_FREQ_45_PRESC 3000000000ULL/* Hz */ +#define ADF4350_MAX_FREQ_PFD 32000000/* Hz */ +#define ADF4350_MAX_BANDSEL_CLK 125000/* Hz */ +#define ADF4350_MAX_FREQ_REFIN 250000000/* Hz */ +#define ADF4350_MAX_MODULUS 4095 + +/* +* TODO: struct adf4350_platform_data needs to go into include/linux/iio +*/ + +/** +* struct adf4350_platform_data - platform specific information +* @clkin: REFin frequency in Hz. +* @channel_spacing: Channel spacing in Hz (influences MODULUS). +* @power_up_frequency: Optional, If set in Hz the PLL tunes to the desired +* frequency on probe. +* @ref_div_factor: Optional, if set the driver skips dynamic calculation +* and uses this default value instead. +* @ref_doubler_en: Enables reference doubler. +* @ref_div2_en: Enables reference divider. +* @r2_user_settings: User defined settings for ADF4350/1 REGISTER_2. +* @r3_user_settings: User defined settings for ADF4350/1 REGISTER_3. +* @r4_user_settings: User defined settings for ADF4350/1 REGISTER_4. +* @gpio_lock_detect: Optional, if set with a valid GPIO number, +* a PLL_LOCKED device attribute is created. +* If not used - set to -1. +*/ + +struct adf4350_platform_data { +unsigned long clkin; +unsigned long channel_spacing;
Quoted 8 lines
drivers/staging/iio/pll/adf4350.h line 114
Quoted 6 lines
drivers/staging/iio/pll/adf4350.h new file +6
-0+unsigned long long power_up_frequency; + +unsigned short ref_div_factor;/* 10-bit R counter */ +bool ref_doubler_en; +bool ref_div2_en; +These next three are in the magic value category. I'd much rather see them broken down into their constituent elements.
I can do that but it will blow this struct.
I tried to verbosely name the register bit definitions. And on the other side I made sure we mask out bits not intended to be set in here.
Quoted 8 lines
Quoted 7 lines
drivers/staging/iio/pll/adf4350.h new file +7
-0+unsigned r2_user_settings; +unsigned r3_user_settings; +unsigned r4_user_settings; + int gpio_lock_detect; +}; + +#endif /* IIO_PLL_ADF4350_H_ */
Signature · 8 lines
Greetings, Michael -- Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368; Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Margaret Seif
Jonathan Cameron
maintainerQuoted 12 lines · Michael Hennerich
Quoted 11 lines · Jonathan Cameron
Quoted 4 lines · On 12/09/2011 01:22 PM, [email protected] wrote:
From: Michael Hennerich<[email protected]>
This patch adds support for Analog Devices ADF4350/ADF4351 Wideband Synthesizers (35MHz to 4.4GHz).
Hi Michael,
Whilst I have no particular issue with having this device driver in IIO I can see that it has considerable overlap with the clock infrastructure. Perhaps you could give a quick summary of why it doesn't make more sense to fit this device in there?
Quoted 7 lines
Hi Jonathan,
The in-kernel clock infrastructure is aimed for SoC like clock distribution. Typically one master clock,
and a number of scaled down clocks for the various clock salve peripherals. For example typical clock slaves here are:
SPI, I2C, UART, MMC, Video, etc.
Agreed, but is it absolutely limited to that? Conceptually the problem being solved is similar. They have a source clock and an output clock that is some multiple of the frequency.
Quoted 6 lines
This PLL device is more aimed for generating a standalone clock used in industrial and communications applications.
For example a Local Oscillator (LO) Frequency used with a Wide-band Mixer generating another Intermediate Frequency (IF) which is then samples by an ADC.
Sure, different uses but still feels like they are roughly the same at heart.
Quoted 4 lines
Also PLL input clocks are typically high stability, low phase noise clock sources,
an not something derived from a SoC clock.
Agreed, but the quality of the sources doesn't have much to do with the way they are handled in kernel :) Maybe this is one to revist at a later point. Perhaps we will end up with a clk provider that is an IIO client using the inkernel interfaces.. Afterall, you could use a much more general dds for the same sort of thing (odd, but I bet someone will sooner or later ;)
Quoted 57 lines
Quoted 42 lines
There are a number of 'magic' register elements in the platform data. I'd much prefer to see them broken down into their constituent parts.
Various other bits and bobs inline...
Quoted 35 lines
Signed-off-by Michael Hennerich<[email protected]>--- .../staging/iio/Documentation/sysfs-bus-iio-pll | 46 ++ drivers/staging/iio/Kconfig | 1 + drivers/staging/iio/Makefile | 1 + drivers/staging/iio/pll/Kconfig | 16 + drivers/staging/iio/pll/Makefile | 5 + drivers/staging/iio/pll/adf4350.c | 485 ++++++++++++++++++++ drivers/staging/iio/pll/adf4350.h | 121 +++++ 7 files changed, 675 insertions(+), 0 deletions(-)create mode 100644
drivers/staging/iio/Documentation/sysfs-bus-iio-pllcreate mode 100644drivers/staging/iio/pll/Kconfig
create mode 100644drivers/staging/iio/pll/Makefile
create mode 100644drivers/staging/iio/pll/adf4350.ccreate mode 100644drivers/staging/iio/pll/adf4350.hdrivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +7
-0@@ -0,0 +1,46 @@ + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_freq +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Stores PLL Y frequency in Hz. Reading returns the + actual frequency in Hz. When setting a new frequency,the PLL
+ requires some time to lock. If available, the user can
read
+out_pllY_lockedin order to check whether the PLL hasQuoted 8 lines
Quoted 2 lines
locked
+ or not.Is the fact that it is a pll vital? ultimately it's just a frequency output
as far as we are concerned (up to the 'locked' stuff). I wonder if we should
be sharing more between this interface and the dds one. (I'm happy to be convinced either way!)In fact - I was thinking about the same thing. The DDS parts are typically different from the PLL, however there is a common denominator.
How about we rename iio/dds to iio/frequency.
But I'm a bit unsure about the naming convention.
Quoted 6 lines
For dds we have
out_ddsX_freqYorout_ddsX_outY_enable. shall we keep that scheme and likewise add:out_pllX_freqY, or move on to something like:
out_devX_freqY?out_freqX_Y?
This one looks reasonable to me. DDSs are currently the only case we have with two
Quoted 1 line
out_outX_Y_enable?
this one is rather uggly. Maybe we need a channel type
for ac voltage? altvolage perhaps? Or could just add sufficient
to allow us to treat it as a volage.
There is also the double indexes that we don't allow anywhere else. They are here because we have different waveforms with same underlying channel. We could had a bonus optional index to all channels I suppose and have this as the only current user? Or maybe just a flag to say its a 'subchannel' and use channel2. Afterall these channels are neither going to have modifiers or to be differential so I can't see a clash occuring on the use of that...
Quoted 5 lines
Quoted 4 lines
Having said that, the dds docs at least haven't
caught up with theout_andin_prefixes which isn't a great start...Thanks - I noticed that and a patch is already in my queue.
Cool.
Quoted 5 lines
Quoted 2 lines
How about semantics of having a write to this file wait to return until locking has occured? Just a thought.
I could do that - but we need the
pll_lockedattribute anyways. The PLL could unlock under certain circumstances.
We therefore need an option to check the lock state.
Agreed. This comes back to the age old question of unifying 'unexpected' events (similar loss of tracking for resolvers). We have the classic thresholds well covered, but it's not clear to me whether these even want to go through the same path.
Quoted 14 lines
Quoted 14 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll line 21
Quoted 13 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +2
-0+ +What:/sys/bus/iio/devices/iio:deviceX/out_pllY_freq_resolution
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +9
-0+KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Stores PLL Y frequency resolution/channel spacing in Hz. + The value given directly influences the MODULUS used by + the fractional-N PLL. It is assumed that the algorithm + that is used to compute the various dividers, is able to + generate proper values for multiples of channel spacing. +Is this dependent on where we are wrt to current frequency?
Quoted 5 lines
No, it gives you the option so set a channel spacing, used in your application. For example 200kHz for UMTS, GSM and 15kHz for LTE.
The value written goes into account, only in subsequent writes toout_pllY_freq.
Interesting. I read this initially as being a hardware restriction, not a software limiter. Perhaps put an explanantion of why into this description for those like me not so familiar with what one uses these for!
Quoted 13 lines
Quoted 13 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll line 29
Quoted 10 lines
+What:
/sys/bus/iio/devices/iio:deviceX/out_pllY_refin_freqdrivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +7
-0+KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Sets PLL Y REFin frequency in Hz. In some clock chained + applications, the reference frequency used by the PLL may + change during runtime. This attribute allows the user to + adjust the reference frequency accordingly.If this is a clock, doesn't the kernel have some reasonable extensive infrastructure for handling it?
linux/clk.h. This isn't an area I know well so freel free to tell me why I'm completely wrong :)
Quoted 2 lines
See comment above. The REFin frequency might be supplied by something not under control of the kernel.
That's fair enough, but also true of all clk sources. Ideally this would be handled by that infrastructure, not a knob in IIO.
Quoted 294 lines
Quoted 120 lines
Quoted 120 lines
+ The value written has no effect until
out_pllY_freqis
updated.drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +2
-0+ +What:/sys/bus/iio/devices/iio:deviceX/out_pllY_powerdown
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +5
-0+KernelVersion: 3.2.0 +Contact: [email protected] +Description: + If available, this attribute allows the user to power down + the PLL and it's RFOut buffers. This is in particularuseful
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +9
-0+ during REFin changes. + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_locked +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + If available, this attribute allows the user to determine + whether the PLL has locked by reading '1' or not '0'. +drivers/staging/iio/Kconfig +1
-0@@ -68,6 +68,7 @@ source "drivers/staging/iio/imu/Kconfig" source "drivers/staging/iio/light/Kconfig" source "drivers/staging/iio/magnetometer/Kconfig" source "drivers/staging/iio/meter/Kconfig" +source "drivers/staging/iio/pll/Kconfig" source "drivers/staging/iio/resolver/Kconfig" source "drivers/staging/iio/trigger/Kconfig"drivers/staging/iio/Makefile +1
-0@@ -29,5 +29,6 @@ obj-y += imu/ obj-y += light/ obj-y += magnetometer/ obj-y += meter/ +obj-y += pll/ obj-y += resolver/ obj-y += trigger/drivers/staging/iio/pll/Kconfig new file +10
-0@@ -0,0 +1,16 @@ +# +# Phase-Locked Loop (PLL) frequency synthesizers +# +menu "Phase-Locked Loop (PLL) frequency synthesizers" + +config ADF4350 + tristate "Analog Devices ADF4350/ADF4351 Wideband Synthesizers" + depends on SPI + help + Say yes here to build support for Analog DevicesADF4350/ADF4351
+ Wideband Synthesizers. The driver provides direct access via
sysfs.drivers/staging/iio/pll/Kconfig new file +5
-0+ + To compile this driver as a module, choose M here: the + module will be called adf4350. + +endmenudrivers/staging/iio/pll/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# +# Phase-Locked Loop (PLL) frequency synthesizers +# + +obj-$(CONFIG_ADF4350) += adf4350.odrivers/staging/iio/pll/adf4350.c new file +32
-0@@ -0,0 +1,485 @@ +/* +* ADF4350/ADF4351 SPI Wideband Synthesizer driver +* +* Copyright 2011 Analog Devices Inc. +* +* Licensed under the GPL-2. +*/ + +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/spi/spi.h> +#include <linux/regulator/consumer.h> +#include <linux/err.h> +#include <linux/module.h> +#include <linux/gcd.h> +#include <linux/gpio.h> +#include <asm/div64.h> + +#include "../iio.h" +#include "../sysfs.h" + +#include "adf4350.h" + +enum { +ADF4350_SET_FREQ , +ADF4350_SET_FREQ_REFIN , +ADF4350_SET_FREQ_RESOLUTION , +ADF4350_PLL_LOCKED , +ADF4350_PLL_PWRDOWN , +};Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 39
Quoted 7 lines
drivers/staging/iio/pll/adf4350.c new file +7
-0+ +struct adf4350_state { +struct spi_device *spi; +struct regulator *reg; +struct adf4350_platform_data *pdata; +unsigned long clkin; +unsigned long chspc;Few cryptic names in here I'd like to see coments about..
PFD= Phase frequency detector
chspc = channel spacingI'll add some comments.
Quoted 37 lines
Quoted 37 lines
drivers/staging/iio/pll/adf4350.c new file +37
-0+unsigned long fpfd; +unsigned long min_out_freq; +unsigned r0_fract; +unsigned r0_int; +unsigned r1_mod; +unsigned r4_rf_div_sel; +unsigned long regs[6 ]; +unsigned long regs_hw[6 ]; + +/* +* DMA (thus cache coherency maintenance) requires the +* transfer buffers to live in their own cache lines. +*/ +__be32 val____cacheline_aligned ; +}; + +static struct adf4350_platform_data default_pdata = { + .clkin =10000000 , + .channel_spacing =10000 , + .r2_user_settings =ADF4350_REG2_PD_POLARITY_POS , +ADF4350_REG2_CHARGE_PUMP_CURR_uA (2500 ), + .r3_user_settings =ADF4350_REG3_12BIT_CLKDIV_MODE (0 ), + .r4_user_settings =ADF4350_REG4_OUTPUT_PWR (0 ) | +ADF4350_REG4_MUTE_TILL_LOCK_EN , + .gpio_lock_detect =-1 , +}; + +static int adf4350_sync_config (struct adf4350_state *st) +{ +int ret, i, doublebuf =0 ; + +for (i =ADF4350_REG5 ; i>=ADF4350_REG0 ; i--) { +if ((st->regs_hw[i] != st->regs[i]) || + ((i ==ADF4350_REG0 )&& doublebuf)) { + +switch (i) { +case ADF4350_REG1 :Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 81
Quoted 5 lines
drivers/staging/iio/pll/adf4350.c new file +5
-0+case ADF4350_REG4 : + doublebuf =1 ; +break ; +case ADF4350_REG0 : + doublebuf =0 ;I don't think this value can ever make any difference to anything.. You will only hit the cease statement when i == ...REG0 and that is last run of of the loop.
I know - I'll remove this case.
Quoted 106 lines
Quoted 46 lines
drivers/staging/iio/pll/adf4350.c new file +16
-0+break ; + } + + st->val =cpu_to_be32 (st->regs[i] | i); + ret =spi_write (st->spi,&st->val,4 ); +if (ret<0 ) +return ret; + st->regs_hw[i] = st->regs[i]; +dev_dbg (&st->spi->dev,"[%d] 0x%X\n" , + i, (u32 )st->regs[i] | i); + } + } +return 0 ; +} + +static int adf4350_tune_r_cnt(struct adf4350_state *st, unsignedshort
r_cnt)drivers/staging/iio/pll/adf4350.c new file +13
-0+{ +struct adf4350_platform_data *pdata = st->pdata; + +do { + r_cnt++; + st->fpfd = (st->clkin * (pdata->ref_doubler_en ?2 :1 )) / + (r_cnt * (pdata->ref_div2_en ?2 :1 )); + }while (st->fpfd>ADF4350_MAX_FREQ_PFD ); + +return r_cnt; +} + +static int adf4350_set_freq(struct adf4350_state *st, unsigned longlong freq)
drivers/staging/iio/pll/adf4350.c new file +15
-0+{ +struct adf4350_platform_data *pdata = st->pdata; +u64 tmp; +u32 div_gcd, prescaler; +u16 mdiv, r_cnt =0 ; +u8 band_sel_div; + +if (freq>ADF4350_MAX_OUT_FREQ || freq< st->min_out_freq) +return -EINVAL ; + +if (freq>ADF4350_MAX_FREQ_45_PRESC ) { + prescaler =ADF4350_REG1_PRESCALER ; + mdiv =75 ; + }else { + prescaler =0 ;drivers/staging/iio/pll/adf4350.c line 135
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+ mdiv =23 ; + } + + st->r4_rf_div_sel =0 ; + +while (freq<ADF4350_MIN_VCO_FREQ ) { + freq<<=1 ; + st->r4_rf_div_sel++; + } +/*
* Allow...Quoted 48 lines
drivers/staging/iio/pll/adf4350.c new file +36
-0+/* Allow a predefined reference division factor +* if not set, compute our own +*/ +if (pdata->ref_div_factor) + r_cnt = pdata->ref_div_factor -1 ; + +do { + r_cnt =adf4350_tune_r_cnt (st, r_cnt); + + st->r1_mod = st->fpfd / st->chspc; +while (st->r1_mod>ADF4350_MAX_MODULUS ) { + r_cnt =adf4350_tune_r_cnt (st, r_cnt); + st->r1_mod = st->fpfd / st->chspc; + } + + tmp = freq * (u64 )st->r1_mod + (st->fpfd>1 ); +do_div (tmp, st->fpfd);/* Div round closest (n + d/2)/d */ + st->r0_fract =do_div (tmp, st->r1_mod); + st->r0_int = tmp; + }while (mdiv> st->r0_int); + + band_sel_div =DIV_ROUND_UP (st->fpfd,ADF4350_MAX_BANDSEL_CLK ); + +if (st->r0_fract&& st->r1_mod) { + div_gcd =gcd (st->r1_mod, st->r0_fract); + st->r1_mod /= div_gcd; + st->r0_fract /= div_gcd; + }else { + st->r0_fract =0 ; + st->r1_mod =1 ; + } + + dev_dbg(&st->spi->dev, "VCO: %llu Hz, PFD %lu Hz\n" + "REF_DIV %d, R0_INT %d, R0_FRACT %d\n" + "R1_MOD %d, RF_DIV %d\nPRESCALER %s, BAND_SEL_DIV %d\n", + freq, st->fpfd, r_cnt, st->r0_int, st->r0_fract,
st->r1_mod,drivers/staging/iio/pll/adf4350.c new file +11
-0+1 << st->r4_rf_div_sel, prescaler ?"8/9" :"4/5" , + band_sel_div); + + st->regs[ADF4350_REG0 ] =ADF4350_REG0_INT (st->r0_int) | +ADF4350_REG0_FRACT (st->r0_fract); + + st->regs[ADF4350_REG1 ] =ADF4350_REG1_PHASE (0 ) | +ADF4350_REG1_MOD (st->r1_mod) | + prescaler; + + st->regs[ADF4350_REG3] = pdata->r3_user_settings&Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 189
Quoted 7 lines
drivers/staging/iio/pll/adf4350.c new file +7
-0+ (ADF4350_REG3_12BIT_CLKDIV (0xFFF ) | +ADF4350_REG3_12BIT_CLKDIV_MODE (0x3 ) | +ADF4350_REG3_12BIT_CSR_EN | +ADF4351_REG3_CHARGE_CANCELLATION_EN | + ADF4351_REG3_ANTI_BACKLASH_3ns_EN | +ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH ); +Reorder these? 324 is unusual unless there is a reason...
Quoted 1 line
The reason was, to group the indention style.
Do them in order, makes for easier reviewing even if they are marginally less elegant!
Quoted 151 lines
Quoted 143 lines
Quoted 67 lines
drivers/staging/iio/pll/adf4350.c new file +61
-0+ st->regs[ADF4350_REG2 ] = +ADF4350_REG2_10BIT_R_CNT (r_cnt) | +ADF4350_REG2_DOUBLE_BUFF_EN | + (pdata->ref_doubler_en ?ADF4350_REG2_RMULT2_EN :0 ) | + (pdata->ref_div2_en ?ADF4350_REG2_RDIV2_EN :0 ) | + (pdata->r2_user_settings& (ADF4350_REG2_PD_POLARITY_POS | + ADF4350_REG2_LDP_6ns |ADF4350_REG2_LDF_INT_N | +ADF4350_REG2_CHARGE_PUMP_CURR_uA (5000 ) | +ADF4350_REG2_MUXOUT (0x7 ) |ADF4350_REG2_NOISE_MODE (0x9 ))); + + st->regs[ADF4350_REG4 ] = +ADF4350_REG4_FEEDBACK_FUND | +ADF4350_REG4_RF_DIV_SEL (st->r4_rf_div_sel) | +ADF4350_REG4_8BIT_BAND_SEL_CLKDIV (band_sel_div) | +ADF4350_REG4_RF_OUT_EN | + (pdata->r4_user_settings& + (ADF4350_REG4_OUTPUT_PWR (0x3 ) | +ADF4350_REG4_AUX_OUTPUT_PWR (0x3 ) | +ADF4350_REG4_AUX_OUTPUT_EN | +ADF4350_REG4_AUX_OUTPUT_FUND | +ADF4350_REG4_MUTE_TILL_LOCK_EN )); + + st->regs[ADF4350_REG5 ] =ADF4350_REG5_LD_PIN_MODE_DIGITAL ; + +return adf4350_sync_config (st); +} + +static ssize_t adf4350_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct adf4350_state *st =iio_priv (indio_dev); +struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); +unsigned long long readin; +int ret; + + ret =kstrtoull (buf,10 ,&readin); +if (ret) +return ret; + +mutex_lock (&indio_dev->mlock); +switch ((u32 )this_attr->address) { +case ADF4350_SET_FREQ : + ret =adf4350_set_freq (st, readin); +break ; +case ADF4350_SET_FREQ_REFIN : +if (readin>ADF4350_MAX_FREQ_REFIN ) + ret = -EINVAL ; +else + st->clkin = readin; +break ; +case ADF4350_SET_FREQ_RESOLUTION : +if (readin ==0 ) + ret = -EINVAL ; +else + st->chspc = readin; +break ; +case ADF4350_PLL_PWRDOWN : +if (readin) + st->regs[ADF4350_REG2] |=
ADF4350_REG2_POWER_DOWN_EN;drivers/staging/iio/pll/adf4350.c new file +2
-0+else + st->regs[ADF4350_REG2]&=~ADF4350_REG2_POWER_DOWN_EN;
drivers/staging/iio/pll/adf4350.c new file +1
-0+drivers/staging/iio/pll/adf4350.c line 263
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+adf4350_sync_config (st); +break ; +default : + ret = -ENODEV ; + } +mutex_unlock (&indio_dev->mlock); + +return ret ? ret : len; +} +One too many white lines here... (I'm in a fussy mood ;)
Quoted 65 lines
drivers/staging/iio/pll/adf4350.c new file +28
-0+ +static ssize_t adf4350_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct adf4350_state *st =iio_priv (indio_dev); +struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); +unsigned long long val; + +mutex_lock (&indio_dev->mlock); +switch ((u32 )this_attr->address) { +case ADF4350_SET_FREQ : + val = (u64)((st->r0_int * st->r1_mod) + st->r0_fract) * + (u64 )st->fpfd; +do_div (val, st->r1_mod * (1 << st->r4_rf_div_sel)); +break ; +case ADF4350_SET_FREQ_REFIN : + val = st->clkin; +break ; +case ADF4350_SET_FREQ_RESOLUTION : + val = st->chspc; +break ; +case ADF4350_PLL_LOCKED : + val =gpio_get_value (st->pdata->gpio_lock_detect); +break ; +case ADF4350_PLL_PWRDOWN : + val = !!(st->regs[ADF4350_REG2]&
ADF4350_REG2_POWER_DOWN_EN);drivers/staging/iio/pll/adf4350.c new file +36
-0+break ; + } +mutex_unlock (&indio_dev->mlock); + +return sprintf (buf,"%llu\n" , val); +} + +static IIO_DEVICE_ATTR(out_pll0_freq, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_SET_FREQ); + +static IIO_DEVICE_ATTR(out_pll0_refin_freq, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_SET_FREQ_REFIN); + +static IIO_DEVICE_ATTR(out_pll0_freq_resolution, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_SET_FREQ_RESOLUTION); + +static IIO_DEVICE_ATTR(out_pll0_locked, S_IRUGO, + adf4350_show, + NULL, + ADF4350_PLL_LOCKED); + +static IIO_DEVICE_ATTR(out_pll0_powerdown, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_PLL_PWRDOWN); + +static struct attribute *adf4350_attributes[] = { +&iio_dev_attr_out_pll0_freq.dev_attr.attr, +&iio_dev_attr_out_pll0_refin_freq.dev_attr.attr, +&iio_dev_attr_out_pll0_freq_resolution.dev_attr.attr,Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 332
Quoted 5 lines
+&iio_dev_attr_out_pll0_locked.dev_attr.attr,
+&iio_dev_attr_out_pll0_powerdown.dev_attr.attr,drivers/staging/iio/pll/adf4350.c new file +3
-0+ NULL, +}; +I'd be tempted for simplicity to have this visible and return
-ENODEVor similar to indicate it isn't wired up... That will go much cleaner into thechan_specstuff if we put these in there..
Quoted 3 lines
ok.
BTW - the
is_visiblestuff is currently not working in IIO at all.
True. I'd forgotton about it when I did that fast rework of
registration. Note I'm in general in favour of moving everything
possible into the chan_spec descriptions where this will typically not apply anyway. It's vital to do that if we want in kernel users to be able to get at the various knobs.
Quoted 3 lines
Since
iio_device_register_sysfs()doesn't copy thisattribute_groupmember into the new group. Lars will send a patch shortly.
Good.
Quoted 77 lines
Quoted 41 lines
Quoted 41 lines
drivers/staging/iio/pll/adf4350.c new file +40
-0+static mode_t adf4350_attr_is_visible (struct kobject *kobj, +struct attribute *attr,int n) +{ + struct device *dev = container_of(kobj, struct device, kobj); +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct adf4350_state *st =iio_priv (indio_dev); + +mode_t mode = attr->mode; + +if ((attr ==&iio_dev_attr_out_pll0_locked.dev_attr.attr)&& + !gpio_is_valid (st->pdata->gpio_lock_detect)) + mode =0 ; + +return mode; +} + +static const struct attribute_group adf4350_attribute_group = { + .attrs = adf4350_attributes, + .is_visible = adf4350_attr_is_visible, +}; + +static const struct iio_info adf4350_info = { + .attrs =&adf4350_attribute_group, + .driver_module =THIS_MODULE , +}; + +static int __devinit adf4350_probe (struct spi_device *spi) +{ +struct adf4350_platform_data *pdata = spi->dev.platform_data; +struct iio_dev *indio_dev; +struct adf4350_state *st; +struct regulator *reg; +int ret; + +if (!pdata) { +dev_dbg (&spi->dev,"no platform data? using default\n" ); + pdata =&default_pdata; + } + + reg =regulator_get (&spi->dev,"vcc" );Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 378
Quoted 6 lines
drivers/staging/iio/pll/adf4350.c new file +6
-0+if (!IS_ERR (reg)) { + ret =regulator_enable (reg); +if (ret) + goto error_put_reg; + } +Why not reorder slightly then you can do the reg and spi bits directly into
st->regandst->spi? Avoids jumping through hoops on removal too.ok
Quoted 19 lines
Quoted 19 lines
drivers/staging/iio/pll/adf4350.c new file +19
-0+ indio_dev =iio_allocate_device (sizeof (*st)); +if (indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_disable_reg; + } + +spi_set_drvdata (spi, indio_dev); + st =iio_priv (indio_dev); + st->reg = reg; + st->spi = spi; + st->pdata = pdata; + + indio_dev->dev.parent =&spi->dev; + indio_dev->name =spi_get_device_id (spi)->name; + indio_dev->info =&adf4350_info; + indio_dev->modes =INDIO_DIRECT_MODE ; + + st->chspc = pdata->channel_spacing; + st->clkin = pdata->clkin;Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 404
Quoted 7 lines
drivers/staging/iio/pll/adf4350.c new file +7
-0+ + st->min_out_freq =spi_get_device_id (spi)->driver_data ==4351 ? +ADF4351_MIN_OUT_FREQ :ADF4350_MIN_OUT_FREQ ; + +memset (st->regs_hw,0xFF ,sizeof (st->regs_hw)); + +if (gpio_is_valid (pdata->gpio_lock_detect)) {
gpio_request_onewould be slightly cleaner.
Quoted 1 line
Well - it adds another dependency to GPIOLIB.
Is this an issue any more? If so feel free to leave as is!
Quoted 109 lines
Quoted 43 lines
Quoted 43 lines
+ ret = gpio_request(pdata->gpio_lock_detect,
indio_dev->name);drivers/staging/iio/pll/adf4350.c new file +2
-0+if (ret) { + dev_err(&spi->dev, "fail to request lock detectGPIO-%d",
drivers/staging/iio/pll/adf4350.c new file +37
-0+ pdata->gpio_lock_detect); + goto error_free_device; + } +gpio_direction_input (pdata->gpio_lock_detect); + } + +if (pdata->power_up_frequency) { + ret =adf4350_set_freq (st, pdata->power_up_frequency); +if (ret) + goto error_free_device; + } + + ret =iio_device_register (indio_dev); +if (ret) + goto error_free_device; + +return 0 ; + +error_free_device: +iio_free_device (indio_dev); +error_disable_reg: +if (!IS_ERR (reg)) +regulator_disable (reg); +error_put_reg: +if (!IS_ERR (reg)) +regulator_put (reg); + +return ret; +} + +static int __devexit adf4350_remove(struct spi_device *spi) +{ +struct iio_dev *indio_dev =spi_get_drvdata (spi); +struct adf4350_state *st =iio_priv (indio_dev); +struct regulator *reg = st->reg; + + st->regs[ADF4350_REG2 ] |=ADF4350_REG2_POWER_DOWN_EN ;Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 451
Quoted 7 lines
drivers/staging/iio/pll/adf4350.c new file +7
-0+adf4350_sync_config (st); + +iio_device_unregister (indio_dev); +if (!IS_ERR (reg)) { +regulator_disable (reg); +regulator_put (reg); + }
iio_free_deviceis now explicitly required...Ups. Good catch.
Quoted 47 lines
Quoted 47 lines
drivers/staging/iio/pll/adf4350.c new file +34
-0+return 0 ; +} + +static const struct spi_device_id adf4350_id[] = { + {"adf4350" ,4350 }, + {"adf4351" ,4351 }, + {} +}; + +static struct spi_driver adf4350_driver = { + .driver = { + .name ="adf4350" , + .owner =THIS_MODULE , + }, + .probe = adf4350_probe, + .remove =__devexit_p (adf4350_remove), + .id_table = adf4350_id, +}; + +static int __init adf4350_init (void ) +{ +return spi_register_driver (&adf4350_driver); +} +module_init (adf4350_init); + +static void __exit adf4350_exit(void) +{ +spi_unregister_driver (&adf4350_driver); +} +module_exit (adf4350_exit); + +MODULE_AUTHOR ("Michael Hennerich<[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices ADF4350/ADF4351 PLL" ); +MODULE_LICENSE ("GPL v2" );drivers/staging/iio/pll/adf4350.h new file +6
-0@@ -0,0 +1,121 @@ +/* +* ADF4350/ADF4351 SPI PLL driver +* +* Copyright 2011 Analog Devices Inc. +* +* Licensed under the GPL-2. Quoted 8 lines
drivers/staging/iio/pll/adf4350.h line 12
Quoted 6 lines
drivers/staging/iio/pll/adf4350.h new file +6
-0+*/ + +#ifndef IIO_PLL_ADF4350_H_ +#define IIO_PLL_ADF4350_H_ + +/* Registers */ Umm.. These doe feel a little bit pointless.. Perhaps just use the values in place of the defines for this one..
Quoted 7 lines
Hmm - I prefer to keep them.
They make sure that the reader understands that we touching device registers.
Ideally I would have named them a little bit more descriptive, however given the fact that so many different bits and fields are stuffed into
single registers makes it difficult to find a proper name.
Fair enough. Agreed this device has a hideous register map!
Quoted 114 lines
Quoted 106 lines
Quoted 106 lines
drivers/staging/iio/pll/adf4350.h new file +9
-0+#define ADF4350_REG0 0 +#define ADF4350_REG1 1 +#define ADF4350_REG2 2 +#define ADF4350_REG3 3 +#define ADF4350_REG4 4 +#define ADF4350_REG5 5 + +/* REG0 Bit Definitions */ +#define ADF4350_REG0_FRACT (x) (((x)&0xFFF)<< 3)
drivers/staging/iio/pll/adf4350.h new file +5
-0+#define ADF4350_REG0_INT (x) (((x)& 0xFFFF)<< 15) + +/* REG1 Bit Definitions */ +#define ADF4350_REG1_MOD (x) (((x)& 0xFFF)<< 3) +#define ADF4350_REG1_PHASE (x) (((x)&0xFFF)<< 15)
drivers/staging/iio/pll/adf4350.h new file +12
-0+#define ADF4350_REG1_PRESCALER (1<< 27) + +/* REG2 Bit Definitions */ +#define ADF4350_REG2_COUNTER_RESET_EN (1<< 3) +#define ADF4350_REG2_CP_THREESTATE_EN (1<< 4) +#define ADF4350_REG2_POWER_DOWN_EN (1<< 5) +#define ADF4350_REG2_PD_POLARITY_POS (1<< 6) +#define ADF4350_REG2_LDP_6ns (1<< 7) +#define ADF4350_REG2_LDP_10ns (0<< 7) +#define ADF4350_REG2_LDF_FRACT_N (0<< 8) +#define ADF4350_REG2_LDF_INT_N (1<< 8) +#define ADF4350_REG2_CHARGE_PUMP_CURR_uA (x) (((((x)-312) / 312)&0xF)<< 9)
drivers/staging/iio/pll/adf4350.h new file +47
-0+#define ADF4350_REG2_DOUBLE_BUFF_EN (1<< 13) +#define ADF4350_REG2_10BIT_R_CNT (x) ((x)<< 14) +#define ADF4350_REG2_RDIV2_EN (1<< 24) +#define ADF4350_REG2_RMULT2_EN (1<< 25) +#define ADF4350_REG2_MUXOUT (x) ((x)<< 26) +#define ADF4350_REG2_NOISE_MODE (x) ((x)<< 29) + +/* REG3 Bit Definitions */ +#define ADF4350_REG3_12BIT_CLKDIV (x) ((x)<< 3) +#define ADF4350_REG3_12BIT_CLKDIV_MODE (x) ((x)<< 16) +#define ADF4350_REG3_12BIT_CSR_EN (1<< 18) +#define ADF4351_REG3_CHARGE_CANCELLATION_EN (1<< 21) +#define ADF4351_REG3_ANTI_BACKLASH_3ns_EN (1<< 22) +#define ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH (1<< 23) + +/* REG4 Bit Definitions */ +#define ADF4350_REG4_OUTPUT_PWR (x) ((x)<< 3) +#define ADF4350_REG4_RF_OUT_EN (1<< 5) +#define ADF4350_REG4_AUX_OUTPUT_PWR (x) ((x)<< 6) +#define ADF4350_REG4_AUX_OUTPUT_EN (1<< 8) +#define ADF4350_REG4_AUX_OUTPUT_FUND (1<< 9) +#define ADF4350_REG4_AUX_OUTPUT_DIV (0<< 9) +#define ADF4350_REG4_MUTE_TILL_LOCK_EN (1<< 10) +#define ADF4350_REG4_VCO_PWRDOWN_EN (1<< 11) +#define ADF4350_REG4_8BIT_BAND_SEL_CLKDIV (x) ((x)<< 12) +#define ADF4350_REG4_RF_DIV_SEL (x) ((x)<< 20) +#define ADF4350_REG4_FEEDBACK_DIVIDED (0<< 23) +#define ADF4350_REG4_FEEDBACK_FUND (1<< 23) + +/* REG5 Bit Definitions */ +#define ADF4350_REG5_LD_PIN_MODE_LOW (0<< 22) +#define ADF4350_REG5_LD_PIN_MODE_DIGITAL (1<< 22) +#define ADF4350_REG5_LD_PIN_MODE_HIGH (3<< 22) + +/* Specifications */ +#define ADF4350_MAX_OUT_FREQ 4400000000ULL/* Hz */ +#define ADF4350_MIN_OUT_FREQ 137500000/* Hz */ +#define ADF4351_MIN_OUT_FREQ 34375000/* Hz */ +#define ADF4350_MIN_VCO_FREQ 2200000000ULL/* Hz */ +#define ADF4350_MAX_FREQ_45_PRESC 3000000000ULL/* Hz */ +#define ADF4350_MAX_FREQ_PFD 32000000/* Hz */ +#define ADF4350_MAX_BANDSEL_CLK 125000/* Hz */ +#define ADF4350_MAX_FREQ_REFIN 250000000/* Hz */ +#define ADF4350_MAX_MODULUS 4095 + +/* +* TODO: struct adf4350_platform_data needs to go into
include/linux/iio
+ */drivers/staging/iio/pll/adf4350.h new file +6
-0+ +/** +* struct adf4350_platform_data - platform specific information +* @clkin: REFin frequency in Hz. +* @channel_spacing: Channel spacing in Hz (influences MODULUS). +* @power_up_frequency: Optional, If set in Hz the PLL tunes to the desired
+ * frequency on probe.
+ * @ref_div_factor: Optional, if set the driver skips dynamic calculation+ * and uses this default value instead. + * @ref_doubler_en: Enables reference doubler. + * @ref_div2_en: Enables reference divider.+ * @r2_user_settings: User defined settings for ADF4350/1
REGISTER_2.
+ * @r3_user_settings: User defined settings for ADF4350/1REGISTER_3.
+ * @r4_user_settings: User defined settings for ADF4350/1REGISTER_4.
+ * @gpio_lock_detect: Optional, if set with a valid GPIO number,
+ * aPLL_LOCKEDdevice attribute is created.
+ * If not used - set to -1.
+ */drivers/staging/iio/pll/adf4350.h new file +4
-0+ +struct adf4350_platform_data { +unsigned long clkin; +unsigned long channel_spacing;Quoted 8 lines
drivers/staging/iio/pll/adf4350.h line 114
Quoted 6 lines
drivers/staging/iio/pll/adf4350.h new file +6
-0+unsigned long long power_up_frequency; + +unsigned short ref_div_factor;/* 10-bit R counter */ +bool ref_doubler_en; +bool ref_div2_en; +These next three are in the magic value category. I'd much rather see them broken down into their constituent elements.
Quoted 1 line
I can do that but it will blow this struct.
if it's truely awful then lets leave it. I hate magic numbers but sometime hardware designers are against us!
Quoted 15 lines
I tried to verbosely name the register bit definitions. And on the other side I made sure we mask out bits not intended to be set in here.
Quoted 8 lines
Quoted 7 lines
drivers/staging/iio/pll/adf4350.h new file +7
-0+unsigned r2_user_settings; +unsigned r3_user_settings; +unsigned r4_user_settings; + int gpio_lock_detect; +}; + +#endif /* IIO_PLL_ADF4350_H_ */
Michael Hennerich
maintainerQuoted 33 lines · Jonathan Cameron
Quoted 12 lines · Michael Hennerich
Quoted 11 lines · Jonathan Cameron
Quoted 4 lines · On 12/09/2011 01:22 PM, [email protected] wrote:
From: Michael Hennerich<[email protected]>
This patch adds support for Analog Devices ADF4350/ADF4351 Wideband Synthesizers (35MHz to 4.4GHz).
Hi Michael,
Whilst I have no particular issue with having this device driver in IIO I can see that it has considerable overlap with the clock infrastructure. Perhaps you could give a quick summary of why it doesn't make more sense to fit this device in there?
Quoted 7 lines
Hi Jonathan,
The in-kernel clock infrastructure is aimed for SoC like clock distribution. Typically one master clock,
and a number of scaled down clocks for the various clock salve peripherals. For example typical clock slaves here are:
SPI, I2C, UART, MMC, Video, etc.Agreed, but is it absolutely limited to that? Conceptually the problem being solved is similar. They have a source clock and an output clock that is some multiple of the frequency.
Quoted 5 lines
This PLL device is more aimed for generating a standalone clock used in industrial and communications applications.
For example a Local Oscillator (LO) Frequency used with a Wide-band Mixer generating another Intermediate Frequency (IF) which is then samples by an ADC.Sure, different uses but still feels like they are roughly the same at heart.
Quoted 3 lines
Also PLL input clocks are typically high stability, low phase noise clock sources,
an not something derived from a SoC clock.
Quoted 6 lines
Agreed, but the quality of the sources doesn't have much to do with the way they are handled in kernel :) Maybe this is one to revist at a later point. Perhaps we will end up with a clk provider that is an IIO client using the inkernel interfaces.. Afterall, you could use a much more general dds for the same sort of thing (odd, but I bet someone will sooner or later ;)
Hi Jonathan,
I'll take a look and add the in-kernel interface as well.
To be consequent this device must be a clock slave and a clock provider. But foremost it's an iio client, with a defined user interface - since this is our target application.
Quoted 60 lines
Quoted 60 lines
Quoted 41 lines
There are a number of 'magic' register elements in the platform data. I'd much prefer to see them broken down into their constituent parts.
Various other bits and bobs inline...
Quoted 35 lines
Signed-off-by Michael Hennerich<[email protected]>--- .../staging/iio/Documentation/sysfs-bus-iio-pll | 46 ++ drivers/staging/iio/Kconfig | 1 + drivers/staging/iio/Makefile | 1 + drivers/staging/iio/pll/Kconfig | 16 + drivers/staging/iio/pll/Makefile | 5 + drivers/staging/iio/pll/adf4350.c | 485 ++++++++++++++++++++ drivers/staging/iio/pll/adf4350.h | 121 +++++ 7 files changed, 675 insertions(+), 0 deletions(-)create mode 100644
drivers/staging/iio/Documentation/sysfs-bus-iio-pllcreate mode 100644drivers/staging/iio/pll/Kconfig
create mode 100644drivers/staging/iio/pll/Makefile
create mode 100644drivers/staging/iio/pll/adf4350.ccreate mode 100644drivers/staging/iio/pll/adf4350.hdrivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +7
-0@@ -0,0 +1,46 @@ + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_freq +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Stores PLL Y frequency in Hz. Reading returns the + actual frequency in Hz. When setting a new frequency,the PLL
+ requires some time to lock. If available, the user can
read
+out_pllY_lockedin order to check whether the PLL hasQuoted 8 lines
Quoted 2 lines
locked
+ or not.Is the fact that it is a pll vital? ultimately it's just a frequency output
as far as we are concerned (up to the 'locked' stuff). I wonder if we should
be sharing more between this interface and the dds one. (I'm happy to be convinced either way!)In fact - I was thinking about the same thing. The DDS parts are typically different from the PLL, however there is a common denominator.
How about we rename iio/dds to iio/frequency.
But I'm a bit unsure about the naming convention.For dds we have
out_ddsX_freqYorout_ddsX_outY_enable. shall we keep that scheme and likewise add:out_pllX_freqY, or move on to something like:
Quoted 8 lines
Quoted 2 lines
out_devX_freqY?out_freqX_Y?This one looks reasonable to me. DDSs are currently the only case we have with two
Quoted 1 line
out_outX_Y_enable?this one is rather uggly. Maybe we need a channel type
for ac voltage? altvolage perhaps? Or could just add sufficient
to allow us to treat it as a volage.
I like this idea. Altvoltage sounds sensible. Acvoltage would sound more familiar, but given the fact that the 'C' stands for current ...
Quoted 7 lines
There is also the double indexes that we don't allow anywhere else. They are here because we have different waveforms with same underlying channel. We could had a bonus optional index to all channels I suppose and have this as the only current user? Or maybe just a flag to say its a 'subchannel' and use channel2. Afterall these channels are neither going to have modifiers or to be differential so I can't see a clash occuring on the use of that...
Well one of the indexes with the DDS parts is used to distinguish the tuning words options, in combination with the pincontrol feature. PLL devices typically doesn't feature this.
So bottom line - can we agree on:
out_altvoltageX_freqYout_altvoltageX_phaseYout_altvoltageX_scaleout_altvoltageX_enable
...
Where X stands for the output channel, and Y for some sort of option.
For the PLL and clock distribution parts that I have currently in the make. Y would be always 0.
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Having said that, the dds docs at least haven't
caught up with theout_andin_prefixes which isn't a great start...Thanks - I noticed that and a patch is already in my queue.
Cool.
Quoted 2 lines
Quoted 2 lines
How about semantics of having a write to this file wait to return until locking has occured? Just a thought.
Quoted 7 lines
Quoted 3 lines
I could do that - but we need the
pll_lockedattribute anyways. The PLL could unlock under certain circumstances.
We therefore need an option to check the lock state.Agreed. This comes back to the age old question of unifying 'unexpected' events (similar loss of tracking for resolvers). We have the classic thresholds well covered, but it's not clear to me whether these even want to go through the same path.
Well there is a need for such events, I don't mind if they take the same route.
Quoted 34 lines
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +2
-0+ +What:/sys/bus/iio/devices/iio:deviceX/out_pllY_freq_resolution
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +2
-0+KernelVersion: 3.2.0 +Contact: [email protected]Quoted 8 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll line 21
Quoted 7 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +7
-0+Description: + Stores PLL Y frequency resolution/channel spacing in Hz. + The value given directly influences the MODULUS used by + the fractional-N PLL. It is assumed that the algorithm + that is used to compute the various dividers, is able to + generate proper values for multiples of channel spacing. +Is this dependent on where we are wrt to current frequency?
Quoted 5 lines
No, it gives you the option so set a channel spacing, used in your application. For example 200kHz for UMTS, GSM and 15kHz for LTE.
The value written goes into account, only in subsequent writes toout_pllY_freq.Interesting. I read this initially as being a hardware restriction, not a software limiter. Perhaps put an explanantion of why into this description for those like me not so familiar with what one uses these for!
Quoted 12 lines
Quoted 12 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-pll line 29
Quoted 9 lines
+What:
/sys/bus/iio/devices/iio:deviceX/out_pllY_refin_freqdrivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +7
-0+KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Sets PLL Y REFin frequency in Hz. In some clock chained + applications, the reference frequency used by the PLL may + change during runtime. This attribute allows the user to + adjust the reference frequency accordingly.If this is a clock, doesn't the kernel have some reasonable extensive infrastructure for handling it?
linux/clk.h. This isn't an area I know well so freel free to tell me why I'm completely wrong :)
Quoted 4 lines
Quoted 2 lines
See comment above. The REFin frequency might be supplied by something not under control of the kernel.
That's fair enough, but also true of all clk sources. Ideally this would be handled by that infrastructure, not a knob in IIO.
I'll add the in-kernel interface too.
But we need the IIO knob as well.
Quoted 780 lines
Quoted 293 lines
Quoted 119 lines
Quoted 119 lines
+ The value written has no effect until
out_pllY_freqis
updated.drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +2
-0+ +What:/sys/bus/iio/devices/iio:deviceX/out_pllY_powerdown
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +5
-0+KernelVersion: 3.2.0 +Contact: [email protected] +Description: + If available, this attribute allows the user to power down + the PLL and it's RFOut buffers. This is in particularuseful
drivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +9
-0+ during REFin changes. + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_locked +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + If available, this attribute allows the user to determine + whether the PLL has locked by reading '1' or not '0'. +drivers/staging/iio/Kconfig +1
-0@@ -68,6 +68,7 @@ source "drivers/staging/iio/imu/Kconfig" source "drivers/staging/iio/light/Kconfig" source "drivers/staging/iio/magnetometer/Kconfig" source "drivers/staging/iio/meter/Kconfig" +source "drivers/staging/iio/pll/Kconfig" source "drivers/staging/iio/resolver/Kconfig" source "drivers/staging/iio/trigger/Kconfig"drivers/staging/iio/Makefile +1
-0@@ -29,5 +29,6 @@ obj-y += imu/ obj-y += light/ obj-y += magnetometer/ obj-y += meter/ +obj-y += pll/ obj-y += resolver/ obj-y += trigger/drivers/staging/iio/pll/Kconfig new file +10
-0@@ -0,0 +1,16 @@ +# +# Phase-Locked Loop (PLL) frequency synthesizers +# +menu "Phase-Locked Loop (PLL) frequency synthesizers" + +config ADF4350 + tristate "Analog Devices ADF4350/ADF4351 Wideband Synthesizers" + depends on SPI + help + Say yes here to build support for Analog DevicesADF4350/ADF4351
+ Wideband Synthesizers. The driver provides direct access via
sysfs.drivers/staging/iio/pll/Kconfig new file +5
-0+ + To compile this driver as a module, choose M here: the + module will be called adf4350. + +endmenudrivers/staging/iio/pll/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# +# Phase-Locked Loop (PLL) frequency synthesizers +# + +obj-$(CONFIG_ADF4350) += adf4350.odrivers/staging/iio/pll/adf4350.c new file +32
-0@@ -0,0 +1,485 @@ +/* +* ADF4350/ADF4351 SPI Wideband Synthesizer driver +* +* Copyright 2011 Analog Devices Inc. +* +* Licensed under the GPL-2. +*/ + +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/spi/spi.h> +#include <linux/regulator/consumer.h> +#include <linux/err.h> +#include <linux/module.h> +#include <linux/gcd.h> +#include <linux/gpio.h> +#include <asm/div64.h> + +#include "../iio.h" +#include "../sysfs.h" + +#include "adf4350.h" + +enum { +ADF4350_SET_FREQ , +ADF4350_SET_FREQ_REFIN , +ADF4350_SET_FREQ_RESOLUTION , +ADF4350_PLL_LOCKED , +ADF4350_PLL_PWRDOWN , +};Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 39
Quoted 7 lines
drivers/staging/iio/pll/adf4350.c new file +7
-0+ +struct adf4350_state { +struct spi_device *spi; +struct regulator *reg; +struct adf4350_platform_data *pdata; +unsigned long clkin; +unsigned long chspc;Few cryptic names in here I'd like to see coments about..
PFD= Phase frequency detector
chspc = channel spacingI'll add some comments.
Quoted 37 lines
Quoted 37 lines
drivers/staging/iio/pll/adf4350.c new file +37
-0+unsigned long fpfd; +unsigned long min_out_freq; +unsigned r0_fract; +unsigned r0_int; +unsigned r1_mod; +unsigned r4_rf_div_sel; +unsigned long regs[6 ]; +unsigned long regs_hw[6 ]; + +/* +* DMA (thus cache coherency maintenance) requires the +* transfer buffers to live in their own cache lines. +*/ +__be32 val____cacheline_aligned ; +}; + +static struct adf4350_platform_data default_pdata = { + .clkin =10000000 , + .channel_spacing =10000 , + .r2_user_settings =ADF4350_REG2_PD_POLARITY_POS , +ADF4350_REG2_CHARGE_PUMP_CURR_uA (2500 ), + .r3_user_settings =ADF4350_REG3_12BIT_CLKDIV_MODE (0 ), + .r4_user_settings =ADF4350_REG4_OUTPUT_PWR (0 ) | +ADF4350_REG4_MUTE_TILL_LOCK_EN , + .gpio_lock_detect =-1 , +}; + +static int adf4350_sync_config (struct adf4350_state *st) +{ +int ret, i, doublebuf =0 ; + +for (i =ADF4350_REG5 ; i>=ADF4350_REG0 ; i--) { +if ((st->regs_hw[i] != st->regs[i]) || + ((i ==ADF4350_REG0 )&& doublebuf)) { + +switch (i) { +case ADF4350_REG1 :Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 81
Quoted 5 lines
drivers/staging/iio/pll/adf4350.c new file +5
-0+case ADF4350_REG4 : + doublebuf =1 ; +break ; +case ADF4350_REG0 : + doublebuf =0 ;I don't think this value can ever make any difference to anything.. You will only hit the cease statement when i == ...REG0 and that is last run of of the loop.
I know - I'll remove this case.
Quoted 106 lines
Quoted 46 lines
drivers/staging/iio/pll/adf4350.c new file +16
-0+break ; + } + + st->val =cpu_to_be32 (st->regs[i] | i); + ret =spi_write (st->spi,&st->val,4 ); +if (ret<0 ) +return ret; + st->regs_hw[i] = st->regs[i]; +dev_dbg (&st->spi->dev,"[%d] 0x%X\n" , + i, (u32 )st->regs[i] | i); + } + } +return 0 ; +} + +static int adf4350_tune_r_cnt(struct adf4350_state *st, unsignedshort
r_cnt)drivers/staging/iio/pll/adf4350.c new file +13
-0+{ +struct adf4350_platform_data *pdata = st->pdata; + +do { + r_cnt++; + st->fpfd = (st->clkin * (pdata->ref_doubler_en ?2 :1 )) / + (r_cnt * (pdata->ref_div2_en ?2 :1 )); + }while (st->fpfd>ADF4350_MAX_FREQ_PFD ); + +return r_cnt; +} + +static int adf4350_set_freq(struct adf4350_state *st, unsigned longlong freq)
drivers/staging/iio/pll/adf4350.c new file +15
-0+{ +struct adf4350_platform_data *pdata = st->pdata; +u64 tmp; +u32 div_gcd, prescaler; +u16 mdiv, r_cnt =0 ; +u8 band_sel_div; + +if (freq>ADF4350_MAX_OUT_FREQ || freq< st->min_out_freq) +return -EINVAL ; + +if (freq>ADF4350_MAX_FREQ_45_PRESC ) { + prescaler =ADF4350_REG1_PRESCALER ; + mdiv =75 ; + }else { + prescaler =0 ;drivers/staging/iio/pll/adf4350.c line 135
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+ mdiv =23 ; + } + + st->r4_rf_div_sel =0 ; + +while (freq<ADF4350_MIN_VCO_FREQ ) { + freq<<=1 ; + st->r4_rf_div_sel++; + } +/*
* Allow...Quoted 48 lines
drivers/staging/iio/pll/adf4350.c new file +36
-0+/* Allow a predefined reference division factor +* if not set, compute our own +*/ +if (pdata->ref_div_factor) + r_cnt = pdata->ref_div_factor -1 ; + +do { + r_cnt =adf4350_tune_r_cnt (st, r_cnt); + + st->r1_mod = st->fpfd / st->chspc; +while (st->r1_mod>ADF4350_MAX_MODULUS ) { + r_cnt =adf4350_tune_r_cnt (st, r_cnt); + st->r1_mod = st->fpfd / st->chspc; + } + + tmp = freq * (u64 )st->r1_mod + (st->fpfd>1 ); +do_div (tmp, st->fpfd);/* Div round closest (n + d/2)/d */ + st->r0_fract =do_div (tmp, st->r1_mod); + st->r0_int = tmp; + }while (mdiv> st->r0_int); + + band_sel_div =DIV_ROUND_UP (st->fpfd,ADF4350_MAX_BANDSEL_CLK ); + +if (st->r0_fract&& st->r1_mod) { + div_gcd =gcd (st->r1_mod, st->r0_fract); + st->r1_mod /= div_gcd; + st->r0_fract /= div_gcd; + }else { + st->r0_fract =0 ; + st->r1_mod =1 ; + } + + dev_dbg(&st->spi->dev, "VCO: %llu Hz, PFD %lu Hz\n" + "REF_DIV %d, R0_INT %d, R0_FRACT %d\n" + "R1_MOD %d, RF_DIV %d\nPRESCALER %s, BAND_SEL_DIV %d\n", + freq, st->fpfd, r_cnt, st->r0_int, st->r0_fract,
st->r1_mod,drivers/staging/iio/pll/adf4350.c new file +11
-0+1 << st->r4_rf_div_sel, prescaler ?"8/9" :"4/5" , + band_sel_div); + + st->regs[ADF4350_REG0 ] =ADF4350_REG0_INT (st->r0_int) | +ADF4350_REG0_FRACT (st->r0_fract); + + st->regs[ADF4350_REG1 ] =ADF4350_REG1_PHASE (0 ) | +ADF4350_REG1_MOD (st->r1_mod) | + prescaler; + + st->regs[ADF4350_REG3] = pdata->r3_user_settings&Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 189
Quoted 7 lines
drivers/staging/iio/pll/adf4350.c new file +7
-0+ (ADF4350_REG3_12BIT_CLKDIV (0xFFF ) | +ADF4350_REG3_12BIT_CLKDIV_MODE (0x3 ) | +ADF4350_REG3_12BIT_CSR_EN | +ADF4351_REG3_CHARGE_CANCELLATION_EN | + ADF4351_REG3_ANTI_BACKLASH_3ns_EN | +ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH ); +Reorder these? 324 is unusual unless there is a reason...
Quoted 1 line
The reason was, to group the indention style.
Do them in order, makes for easier reviewing even if they are marginally less elegant!
Quoted 150 lines
Quoted 142 lines
Quoted 66 lines
drivers/staging/iio/pll/adf4350.c new file +61
-0+ st->regs[ADF4350_REG2 ] = +ADF4350_REG2_10BIT_R_CNT (r_cnt) | +ADF4350_REG2_DOUBLE_BUFF_EN | + (pdata->ref_doubler_en ?ADF4350_REG2_RMULT2_EN :0 ) | + (pdata->ref_div2_en ?ADF4350_REG2_RDIV2_EN :0 ) | + (pdata->r2_user_settings& (ADF4350_REG2_PD_POLARITY_POS | + ADF4350_REG2_LDP_6ns |ADF4350_REG2_LDF_INT_N | +ADF4350_REG2_CHARGE_PUMP_CURR_uA (5000 ) | +ADF4350_REG2_MUXOUT (0x7 ) |ADF4350_REG2_NOISE_MODE (0x9 ))); + + st->regs[ADF4350_REG4 ] = +ADF4350_REG4_FEEDBACK_FUND | +ADF4350_REG4_RF_DIV_SEL (st->r4_rf_div_sel) | +ADF4350_REG4_8BIT_BAND_SEL_CLKDIV (band_sel_div) | +ADF4350_REG4_RF_OUT_EN | + (pdata->r4_user_settings& + (ADF4350_REG4_OUTPUT_PWR (0x3 ) | +ADF4350_REG4_AUX_OUTPUT_PWR (0x3 ) | +ADF4350_REG4_AUX_OUTPUT_EN | +ADF4350_REG4_AUX_OUTPUT_FUND | +ADF4350_REG4_MUTE_TILL_LOCK_EN )); + + st->regs[ADF4350_REG5 ] =ADF4350_REG5_LD_PIN_MODE_DIGITAL ; + +return adf4350_sync_config (st); +} + +static ssize_t adf4350_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct adf4350_state *st =iio_priv (indio_dev); +struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); +unsigned long long readin; +int ret; + + ret =kstrtoull (buf,10 ,&readin); +if (ret) +return ret; + +mutex_lock (&indio_dev->mlock); +switch ((u32 )this_attr->address) { +case ADF4350_SET_FREQ : + ret =adf4350_set_freq (st, readin); +break ; +case ADF4350_SET_FREQ_REFIN : +if (readin>ADF4350_MAX_FREQ_REFIN ) + ret = -EINVAL ; +else + st->clkin = readin; +break ; +case ADF4350_SET_FREQ_RESOLUTION : +if (readin ==0 ) + ret = -EINVAL ; +else + st->chspc = readin; +break ; +case ADF4350_PLL_PWRDOWN : +if (readin) + st->regs[ADF4350_REG2] |=
ADF4350_REG2_POWER_DOWN_EN;drivers/staging/iio/pll/adf4350.c new file +2
-0+else + st->regs[ADF4350_REG2]&=~ADF4350_REG2_POWER_DOWN_EN;
drivers/staging/iio/pll/adf4350.c new file +1
-0+drivers/staging/iio/pll/adf4350.c line 263
Quoted 10 lines
drivers/staging/iio/pll/adf4350.c new file +10
-0+adf4350_sync_config (st); +break ; +default : + ret = -ENODEV ; + } +mutex_unlock (&indio_dev->mlock); + +return ret ? ret : len; +} +One too many white lines here... (I'm in a fussy mood ;)
Quoted 65 lines
drivers/staging/iio/pll/adf4350.c new file +28
-0+ +static ssize_t adf4350_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct adf4350_state *st =iio_priv (indio_dev); +struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); +unsigned long long val; + +mutex_lock (&indio_dev->mlock); +switch ((u32 )this_attr->address) { +case ADF4350_SET_FREQ : + val = (u64)((st->r0_int * st->r1_mod) + st->r0_fract) * + (u64 )st->fpfd; +do_div (val, st->r1_mod * (1 << st->r4_rf_div_sel)); +break ; +case ADF4350_SET_FREQ_REFIN : + val = st->clkin; +break ; +case ADF4350_SET_FREQ_RESOLUTION : + val = st->chspc; +break ; +case ADF4350_PLL_LOCKED : + val =gpio_get_value (st->pdata->gpio_lock_detect); +break ; +case ADF4350_PLL_PWRDOWN : + val = !!(st->regs[ADF4350_REG2]&
ADF4350_REG2_POWER_DOWN_EN);drivers/staging/iio/pll/adf4350.c new file +36
-0+break ; + } +mutex_unlock (&indio_dev->mlock); + +return sprintf (buf,"%llu\n" , val); +} + +static IIO_DEVICE_ATTR(out_pll0_freq, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_SET_FREQ); + +static IIO_DEVICE_ATTR(out_pll0_refin_freq, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_SET_FREQ_REFIN); + +static IIO_DEVICE_ATTR(out_pll0_freq_resolution, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_SET_FREQ_RESOLUTION); + +static IIO_DEVICE_ATTR(out_pll0_locked, S_IRUGO, + adf4350_show, + NULL, + ADF4350_PLL_LOCKED); + +static IIO_DEVICE_ATTR(out_pll0_powerdown, S_IRUGO | S_IWUSR, + adf4350_show, + adf4350_store, + ADF4350_PLL_PWRDOWN); + +static struct attribute *adf4350_attributes[] = { +&iio_dev_attr_out_pll0_freq.dev_attr.attr, +&iio_dev_attr_out_pll0_refin_freq.dev_attr.attr, +&iio_dev_attr_out_pll0_freq_resolution.dev_attr.attr,Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 332
Quoted 5 lines
+&iio_dev_attr_out_pll0_locked.dev_attr.attr,
+&iio_dev_attr_out_pll0_powerdown.dev_attr.attr,drivers/staging/iio/pll/adf4350.c new file +3
-0+ NULL, +}; +I'd be tempted for simplicity to have this visible and return
-ENODEVor similar to indicate it isn't wired up... That will go much cleaner into thechan_specstuff if we put these in there..Quoted 3 lines
ok.
BTW - the
is_visiblestuff is currently not working in IIO at all.True. I'd forgotton about it when I did that fast rework of
registration. Note I'm in general in favour of moving everything
possible into thechan_specdescriptions where this will typically not apply anyway. It's vital to do that if we want in kernel users to be able to get at the various knobs.Quoted 2 lines
Since
iio_device_register_sysfs()doesn't copy thisattribute_groupmember into the new group. Lars will send a patch shortly.Good.
Quoted 76 lines
Quoted 40 lines
Quoted 40 lines
drivers/staging/iio/pll/adf4350.c new file +40
-0+static mode_t adf4350_attr_is_visible (struct kobject *kobj, +struct attribute *attr,int n) +{ + struct device *dev = container_of(kobj, struct device, kobj); +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct adf4350_state *st =iio_priv (indio_dev); + +mode_t mode = attr->mode; + +if ((attr ==&iio_dev_attr_out_pll0_locked.dev_attr.attr)&& + !gpio_is_valid (st->pdata->gpio_lock_detect)) + mode =0 ; + +return mode; +} + +static const struct attribute_group adf4350_attribute_group = { + .attrs = adf4350_attributes, + .is_visible = adf4350_attr_is_visible, +}; + +static const struct iio_info adf4350_info = { + .attrs =&adf4350_attribute_group, + .driver_module =THIS_MODULE , +}; + +static int __devinit adf4350_probe (struct spi_device *spi) +{ +struct adf4350_platform_data *pdata = spi->dev.platform_data; +struct iio_dev *indio_dev; +struct adf4350_state *st; +struct regulator *reg; +int ret; + +if (!pdata) { +dev_dbg (&spi->dev,"no platform data? using default\n" ); + pdata =&default_pdata; + } + + reg =regulator_get (&spi->dev,"vcc" );Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 378
Quoted 6 lines
drivers/staging/iio/pll/adf4350.c new file +6
-0+if (!IS_ERR (reg)) { + ret =regulator_enable (reg); +if (ret) + goto error_put_reg; + } +Why not reorder slightly then you can do the reg and spi bits directly into
st->regandst->spi? Avoids jumping through hoops on removal too.ok
Quoted 19 lines
Quoted 19 lines
drivers/staging/iio/pll/adf4350.c new file +19
-0+ indio_dev =iio_allocate_device (sizeof (*st)); +if (indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_disable_reg; + } + +spi_set_drvdata (spi, indio_dev); + st =iio_priv (indio_dev); + st->reg = reg; + st->spi = spi; + st->pdata = pdata; + + indio_dev->dev.parent =&spi->dev; + indio_dev->name =spi_get_device_id (spi)->name; + indio_dev->info =&adf4350_info; + indio_dev->modes =INDIO_DIRECT_MODE ; + + st->chspc = pdata->channel_spacing; + st->clkin = pdata->clkin;Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 404
Quoted 7 lines
drivers/staging/iio/pll/adf4350.c new file +7
-0+ + st->min_out_freq =spi_get_device_id (spi)->driver_data ==4351 ? +ADF4351_MIN_OUT_FREQ :ADF4350_MIN_OUT_FREQ ; + +memset (st->regs_hw,0xFF ,sizeof (st->regs_hw)); + +if (gpio_is_valid (pdata->gpio_lock_detect)) {
gpio_request_onewould be slightly cleaner.Quoted 1 line
Well - it adds another dependency to GPIOLIB.
Is this an issue any more? If so feel free to leave as is!
Quoted 108 lines
Quoted 42 lines
Quoted 42 lines
+ ret = gpio_request(pdata->gpio_lock_detect,
indio_dev->name);drivers/staging/iio/pll/adf4350.c new file +2
-0+if (ret) { + dev_err(&spi->dev, "fail to request lock detectGPIO-%d",
drivers/staging/iio/pll/adf4350.c new file +37
-0+ pdata->gpio_lock_detect); + goto error_free_device; + } +gpio_direction_input (pdata->gpio_lock_detect); + } + +if (pdata->power_up_frequency) { + ret =adf4350_set_freq (st, pdata->power_up_frequency); +if (ret) + goto error_free_device; + } + + ret =iio_device_register (indio_dev); +if (ret) + goto error_free_device; + +return 0 ; + +error_free_device: +iio_free_device (indio_dev); +error_disable_reg: +if (!IS_ERR (reg)) +regulator_disable (reg); +error_put_reg: +if (!IS_ERR (reg)) +regulator_put (reg); + +return ret; +} + +static int __devexit adf4350_remove(struct spi_device *spi) +{ +struct iio_dev *indio_dev =spi_get_drvdata (spi); +struct adf4350_state *st =iio_priv (indio_dev); +struct regulator *reg = st->reg; + + st->regs[ADF4350_REG2 ] |=ADF4350_REG2_POWER_DOWN_EN ;Quoted 8 lines
drivers/staging/iio/pll/adf4350.c line 451
Quoted 7 lines
drivers/staging/iio/pll/adf4350.c new file +7
-0+adf4350_sync_config (st); + +iio_device_unregister (indio_dev); +if (!IS_ERR (reg)) { +regulator_disable (reg); +regulator_put (reg); + }
iio_free_deviceis now explicitly required...Ups. Good catch.
Quoted 47 lines
Quoted 47 lines
drivers/staging/iio/pll/adf4350.c new file +34
-0+return 0 ; +} + +static const struct spi_device_id adf4350_id[] = { + {"adf4350" ,4350 }, + {"adf4351" ,4351 }, + {} +}; + +static struct spi_driver adf4350_driver = { + .driver = { + .name ="adf4350" , + .owner =THIS_MODULE , + }, + .probe = adf4350_probe, + .remove =__devexit_p (adf4350_remove), + .id_table = adf4350_id, +}; + +static int __init adf4350_init (void ) +{ +return spi_register_driver (&adf4350_driver); +} +module_init (adf4350_init); + +static void __exit adf4350_exit(void) +{ +spi_unregister_driver (&adf4350_driver); +} +module_exit (adf4350_exit); + +MODULE_AUTHOR ("Michael Hennerich<[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices ADF4350/ADF4351 PLL" ); +MODULE_LICENSE ("GPL v2" );drivers/staging/iio/pll/adf4350.h new file +6
-0@@ -0,0 +1,121 @@ +/* +* ADF4350/ADF4351 SPI PLL driver +* +* Copyright 2011 Analog Devices Inc. +* +* Licensed under the GPL-2. Quoted 8 lines
drivers/staging/iio/pll/adf4350.h line 12
Quoted 6 lines
drivers/staging/iio/pll/adf4350.h new file +6
-0+*/ + +#ifndef IIO_PLL_ADF4350_H_ +#define IIO_PLL_ADF4350_H_ + +/* Registers */ Umm.. These doe feel a little bit pointless.. Perhaps just use the values in place of the defines for this one..
Quoted 7 lines
Hmm - I prefer to keep them.
They make sure that the reader understands that we touching device registers.
Ideally I would have named them a little bit more descriptive, however given the fact that so many different bits and fields are stuffed into
single registers makes it difficult to find a proper name.Fair enough. Agreed this device has a hideous register map!
Quoted 113 lines
Quoted 105 lines
Quoted 105 lines
drivers/staging/iio/pll/adf4350.h new file +9
-0+#define ADF4350_REG0 0 +#define ADF4350_REG1 1 +#define ADF4350_REG2 2 +#define ADF4350_REG3 3 +#define ADF4350_REG4 4 +#define ADF4350_REG5 5 + +/* REG0 Bit Definitions */ +#define ADF4350_REG0_FRACT (x) (((x)&0xFFF)<< 3)
drivers/staging/iio/pll/adf4350.h new file +5
-0+#define ADF4350_REG0_INT (x) (((x)& 0xFFFF)<< 15) + +/* REG1 Bit Definitions */ +#define ADF4350_REG1_MOD (x) (((x)& 0xFFF)<< 3) +#define ADF4350_REG1_PHASE (x) (((x)&0xFFF)<< 15)
drivers/staging/iio/pll/adf4350.h new file +12
-0+#define ADF4350_REG1_PRESCALER (1<< 27) + +/* REG2 Bit Definitions */ +#define ADF4350_REG2_COUNTER_RESET_EN (1<< 3) +#define ADF4350_REG2_CP_THREESTATE_EN (1<< 4) +#define ADF4350_REG2_POWER_DOWN_EN (1<< 5) +#define ADF4350_REG2_PD_POLARITY_POS (1<< 6) +#define ADF4350_REG2_LDP_6ns (1<< 7) +#define ADF4350_REG2_LDP_10ns (0<< 7) +#define ADF4350_REG2_LDF_FRACT_N (0<< 8) +#define ADF4350_REG2_LDF_INT_N (1<< 8) +#define ADF4350_REG2_CHARGE_PUMP_CURR_uA (x) (((((x)-312) / 312)&0xF)<< 9)
drivers/staging/iio/pll/adf4350.h new file +47
-0+#define ADF4350_REG2_DOUBLE_BUFF_EN (1<< 13) +#define ADF4350_REG2_10BIT_R_CNT (x) ((x)<< 14) +#define ADF4350_REG2_RDIV2_EN (1<< 24) +#define ADF4350_REG2_RMULT2_EN (1<< 25) +#define ADF4350_REG2_MUXOUT (x) ((x)<< 26) +#define ADF4350_REG2_NOISE_MODE (x) ((x)<< 29) + +/* REG3 Bit Definitions */ +#define ADF4350_REG3_12BIT_CLKDIV (x) ((x)<< 3) +#define ADF4350_REG3_12BIT_CLKDIV_MODE (x) ((x)<< 16) +#define ADF4350_REG3_12BIT_CSR_EN (1<< 18) +#define ADF4351_REG3_CHARGE_CANCELLATION_EN (1<< 21) +#define ADF4351_REG3_ANTI_BACKLASH_3ns_EN (1<< 22) +#define ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH (1<< 23) + +/* REG4 Bit Definitions */ +#define ADF4350_REG4_OUTPUT_PWR (x) ((x)<< 3) +#define ADF4350_REG4_RF_OUT_EN (1<< 5) +#define ADF4350_REG4_AUX_OUTPUT_PWR (x) ((x)<< 6) +#define ADF4350_REG4_AUX_OUTPUT_EN (1<< 8) +#define ADF4350_REG4_AUX_OUTPUT_FUND (1<< 9) +#define ADF4350_REG4_AUX_OUTPUT_DIV (0<< 9) +#define ADF4350_REG4_MUTE_TILL_LOCK_EN (1<< 10) +#define ADF4350_REG4_VCO_PWRDOWN_EN (1<< 11) +#define ADF4350_REG4_8BIT_BAND_SEL_CLKDIV (x) ((x)<< 12) +#define ADF4350_REG4_RF_DIV_SEL (x) ((x)<< 20) +#define ADF4350_REG4_FEEDBACK_DIVIDED (0<< 23) +#define ADF4350_REG4_FEEDBACK_FUND (1<< 23) + +/* REG5 Bit Definitions */ +#define ADF4350_REG5_LD_PIN_MODE_LOW (0<< 22) +#define ADF4350_REG5_LD_PIN_MODE_DIGITAL (1<< 22) +#define ADF4350_REG5_LD_PIN_MODE_HIGH (3<< 22) + +/* Specifications */ +#define ADF4350_MAX_OUT_FREQ 4400000000ULL/* Hz */ +#define ADF4350_MIN_OUT_FREQ 137500000/* Hz */ +#define ADF4351_MIN_OUT_FREQ 34375000/* Hz */ +#define ADF4350_MIN_VCO_FREQ 2200000000ULL/* Hz */ +#define ADF4350_MAX_FREQ_45_PRESC 3000000000ULL/* Hz */ +#define ADF4350_MAX_FREQ_PFD 32000000/* Hz */ +#define ADF4350_MAX_BANDSEL_CLK 125000/* Hz */ +#define ADF4350_MAX_FREQ_REFIN 250000000/* Hz */ +#define ADF4350_MAX_MODULUS 4095 + +/* +* TODO: struct adf4350_platform_data needs to go into
include/linux/iio
+ */drivers/staging/iio/pll/adf4350.h new file +6
-0+ +/** +* struct adf4350_platform_data - platform specific information +* @clkin: REFin frequency in Hz. +* @channel_spacing: Channel spacing in Hz (influences MODULUS). +* @power_up_frequency: Optional, If set in Hz the PLL tunes to the desired
+ * frequency on probe.
+ * @ref_div_factor: Optional, if set the driver skips dynamic calculation+ * and uses this default value instead. + * @ref_doubler_en: Enables reference doubler. + * @ref_div2_en: Enables reference divider.+ * @r2_user_settings: User defined settings for ADF4350/1
REGISTER_2.
+ * @r3_user_settings: User defined settings for ADF4350/1REGISTER_3.
+ * @r4_user_settings: User defined settings for ADF4350/1REGISTER_4.
+ * @gpio_lock_detect: Optional, if set with a valid GPIO number,
+ * aPLL_LOCKEDdevice attribute is created.
+ * If not used - set to -1.
+ */drivers/staging/iio/pll/adf4350.h new file +4
-0+ +struct adf4350_platform_data { +unsigned long clkin; +unsigned long channel_spacing;Quoted 8 lines
drivers/staging/iio/pll/adf4350.h line 114
Quoted 6 lines
drivers/staging/iio/pll/adf4350.h new file +6
-0+unsigned long long power_up_frequency; + +unsigned short ref_div_factor;/* 10-bit R counter */ +bool ref_doubler_en; +bool ref_div2_en; +These next three are in the magic value category. I'd much rather see them broken down into their constituent elements.
Quoted 1 line
I can do that but it will blow this struct.
if it's truely awful then lets leave it. I hate magic numbers but sometime hardware designers are against us!
Quoted 12 lines
I tried to verbosely name the register bit definitions. And on the other side I made sure we mask out bits not intended to be set in here.
Quoted 7 lines
Quoted 7 lines
drivers/staging/iio/pll/adf4350.h new file +7
-0+unsigned r2_user_settings; +unsigned r3_user_settings; +unsigned r4_user_settings; + int gpio_lock_detect; +}; + +#endif /* IIO_PLL_ADF4350_H_ */
Signature · 8 lines
Greetings, Michael -- Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368; Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Margaret Seif
Quoted 41 lines · Michael Hennerich
Quoted 33 lines · Jonathan Cameron
Quoted 12 lines · Michael Hennerich
Quoted 11 lines · Jonathan Cameron
Quoted 4 lines · On 12/09/2011 01:22 PM, [email protected] wrote:
From: Michael Hennerich<[email protected]>
This patch adds support for Analog Devices ADF4350/ADF4351 Wideband Synthesizers (35MHz to 4.4GHz).
Hi Michael,
Whilst I have no particular issue with having this device driver in IIO I can see that it has considerable overlap with the clock infrastructure. Perhaps you could give a quick summary of why it doesn't make more sense to fit this device in there?
Quoted 7 lines
Hi Jonathan,
The in-kernel clock infrastructure is aimed for SoC like clock distribution. Typically one master clock,
and a number of scaled down clocks for the various clock salve peripherals. For example typical clock slaves here are:
SPI, I2C, UART, MMC, Video, etc.Agreed, but is it absolutely limited to that? Conceptually the problem being solved is similar. They have a source clock and an output clock that is some multiple of the frequency.
Quoted 5 lines
This PLL device is more aimed for generating a standalone clock used in industrial and communications applications.
For example a Local Oscillator (LO) Frequency used with a Wide-band Mixer generating another Intermediate Frequency (IF) which is then samples by an ADC.Sure, different uses but still feels like they are roughly the same at heart.
Quoted 3 lines
Also PLL input clocks are typically high stability, low phase noise clock sources,
an not something derived from a SoC clock.Quoted 6 lines
Agreed, but the quality of the sources doesn't have much to do with the way they are handled in kernel :) Maybe this is one to revist at a later point. Perhaps we will end up with a clk provider that is an IIO client using the inkernel interfaces.. Afterall, you could use a much more general dds for the same sort of thing (odd, but I bet someone will sooner or later ;)
Quoted 6 lines
Hi Jonathan,
I'll take a look and add the in-kernel interface as well.
To be consequent this device must be a clock slave and a clock provider. But foremost it's an iio client, with a defined user interface - since this is our target application.
Cool.
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
Quoted 42 lines
There are a number of 'magic' register elements in the platform data. I'd much prefer to see them broken down into their constituent parts.
Various other bits and bobs inline...
Quoted 35 lines
Signed-off-by Michael Hennerich<[email protected]>--- .../staging/iio/Documentation/sysfs-bus-iio-pll | 46 ++ drivers/staging/iio/Kconfig | 1 + drivers/staging/iio/Makefile | 1 + drivers/staging/iio/pll/Kconfig | 16 + drivers/staging/iio/pll/Makefile | 5 + drivers/staging/iio/pll/adf4350.c | 485 ++++++++++++++++++++ drivers/staging/iio/pll/adf4350.h | 121 +++++ 7 files changed, 675 insertions(+), 0 deletions(-)create mode 100644
drivers/staging/iio/Documentation/sysfs-bus-iio-pllcreate mode 100644drivers/staging/iio/pll/Kconfig
create mode 100644drivers/staging/iio/pll/Makefile
create mode 100644drivers/staging/iio/pll/adf4350.ccreate mode 100644drivers/staging/iio/pll/adf4350.hdrivers/staging/iio/Documentation/sysfs-bus-iio-pll new file +7
-0@@ -0,0 +1,46 @@ + +What: /sys/bus/iio/devices/iio:deviceX/out_pllY_freq +KernelVersion: 3.2.0 +Contact: [email protected] +Description: + Stores PLL Y frequency in Hz. Reading returns the + actual frequency in Hz. When setting a new frequency,the PLL
+ requires some time to lock. If available, the user can
read
+out_pllY_lockedin order to check whether the PLL hasQuoted 8 lines
Quoted 2 lines
locked
+ or not.Is the fact that it is a pll vital? ultimately it's just a frequency output
as far as we are concerned (up to the 'locked' stuff). I wonder if we should
be sharing more between this interface and the dds one. (I'm happy to be convinced either way!)In fact - I was thinking about the same thing. The DDS parts are typically different from the PLL, however there is a common denominator.
How about we rename iio/dds to iio/frequency.
But I'm a bit unsure about the naming convention.For dds we have
out_ddsX_freqYorout_ddsX_outY_enable. shall we keep that scheme and likewise add:out_pllX_freqY, or move on to something like:
out_devX_freqY?out_freqX_Y?
Quoted 8 lines
Quoted 6 lines
This one looks reasonable to me. DDSs are currently the only case we have with two
Quoted 1 line
out_outX_Y_enable?this one is rather uggly. Maybe we need a channel type
for ac voltage? altvolage perhaps? Or could just add sufficient
to allow us to treat it as a volage.I like this idea. Altvoltage sounds sensible. Acvoltage would sound more familiar, but given the fact that the 'C' stands for current ...
Agreed, altvoltage is good as we can then have altcurrent etc which is nice.
Quoted 12 lines
Quoted 8 lines
There is also the double indexes that we don't allow anywhere else. They are here because we have different waveforms with same underlying channel. We could had a bonus optional index to all channels I suppose and have this as the only current user? Or maybe just a flag to say its a 'subchannel' and use channel2. Afterall these channels are neither going to have modifiers or to be differential so I can't see a clash occuring on the use of that...
Well one of the indexes with the DDS parts is used to distinguish the tuning words options, in combination with the pincontrol feature. PLL devices typically doesn't feature this.
Quoted 8 lines
So bottom line - can we agree on:
out_altvoltageX_freqYout_altvoltageX_phaseYout_altvoltageX_scaleout_altvoltageX_enable
...
Where X stands for the output channel, and Y for some sort of option.
Looks good as far as I am concerned. Might be worth a quick check through of dds and meter devices to see how we can extend this to cover them.
Quoted 13 lines
For the PLL and clock distribution parts that I have currently in the make. Y would be always 0.
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Having said that, the dds docs at least haven't
caught up with theout_andin_prefixes which isn't a great start...Thanks - I noticed that and a patch is already in my queue.
Cool.
Quoted 2 lines
Quoted 2 lines
How about semantics of having a write to this file wait to return until locking has occured? Just a thought.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
I could do that - but we need the
pll_lockedattribute anyways. The PLL could unlock under certain circumstances.
We therefore need an option to check the lock state.Agreed. This comes back to the age old question of unifying 'unexpected' events (similar loss of tracking for resolvers). We have the classic thresholds well covered, but it's not clear to me whether these even want to go through the same path.
Well there is a need for such events, I don't mind if they take the same route.
I think this is a more general kernel question ideally. How to handle something that corresponds to a 'all hell has broken loose, shut down the kit' event. Probably a few levels below that as well
This driver is going to need to be a lot more widely posted than IIO I think. Good luck figuring out who to send it to.
Jonathan
Michael Hennerich
maintainerQuoted 20 lines · J.I. Cameron
Quoted 18 lines · Michael Hennerich
Quoted 11 lines · Jonathan Cameron
Quoted 3 lines · Michael Hennerich
Quoted 2 lines · Jonathan Cameron
On 12/09/2011 01:22 PM, [email protected] wrote:
There is also the double indexes that we don't allow anywhere else. They are here because we have different waveforms with same underlying channel. We could had a bonus optional index to all channels I suppose and have this as the only current user? Or maybe just a flag to say its a 'subchannel' and use channel2. Afterall these channels are neither going to have modifiers or to be differential so I can't see a clash occuring on the use of that...
Well one of the indexes with the DDS parts is used to distinguish the tuning words options, in combination with the pincontrol feature. PLL devices typically doesn't feature this.
So bottom line - can we agree on:
Quoted 8 lines
Quoted 6 lines
out_altvoltageX_freqYout_altvoltageX_phaseYout_altvoltageX_scaleout_altvoltageX_enable
...
Where X stands for the output channel, and Y for some sort of option.Looks good as far as I am concerned. Might be worth a quick check through of dds and meter devices to see how we can extend this to cover them.
Hi Jonathan,
Looked at the various use cases. And the only user for the second subindex seems to be the DDS parts.
I now wondering if we should handle freqY and phaseY by using extended_name, rather than adding new postfixes for them. Which is going to be difficult anyways, since I may need the current postfixes such as _scale as well.
out_altvoltageX_freqY_scaleout_altvoltageX_phaseY_scale
An alternative could be to introduce an indexed extended_name, using the index passed in channel2? Not sure if it is worth adding it?
Signature · 8 lines
Greetings, Michael -- Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368; Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Margaret Seif
Quoted 30 lines · Michael Hennerich
Quoted 20 lines · J.I. Cameron
Quoted 18 lines · Michael Hennerich
Quoted 11 lines · Jonathan Cameron
Quoted 3 lines · Michael Hennerich
Quoted 2 lines · Jonathan Cameron
On 12/09/2011 01:22 PM, [email protected] wrote:
There is also the double indexes that we don't allow anywhere else. They are here because we have different waveforms with same underlying channel. We could had a bonus optional index to all channels I suppose and have this as the only current user? Or maybe just a flag to say its a 'subchannel' and use channel2. Afterall these channels are neither going to have modifiers or to be differential so I can't see a clash occuring on the use of that...
Well one of the indexes with the DDS parts is used to distinguish the tuning words options, in combination with the pincontrol feature. PLL devices typically doesn't feature this.
So bottom line - can we agree on:
Quoted 8 lines
Quoted 6 lines
out_altvoltageX_freqYout_altvoltageX_phaseYout_altvoltageX_scaleout_altvoltageX_enable
...
Where X stands for the output channel, and Y for some sort of option.Looks good as far as I am concerned. Might be worth a quick check through of dds and meter devices to see how we can extend this to cover them.
Quoted 7 lines
Hi Jonathan,
Looked at the various use cases. And the only user for the second subindex seems to be the DDS parts.
I now wondering if we should handle freqY and phaseY by using
extended_name, rather than adding new postfixes for them. Which is going to be difficult anyways,
Use extend name will make for some hideous logic in the read_raw, write_raw functions. If we need it (and it looks like we do), lets make whatever changes are necessary to do this cleanly in the chan spec structure. I'd been avoiding the DDS parts so far because I have little idea of how to make them play nicely with iio_chan_spec.
Ideally freq and phase would be chaninfo elements. Given that is a mask there is no obvious way of storing the associated index. This also effects the write_raw and read_raw functions as they have no way to get to that index either. That one could be avoided by changing them to take a u64 and embedding the index in a few bits of that
(fiddly carrying that through everywhere but not too bad).
We could simply define a set of freq0 freq1 freq2 as separate elements of the info mask, but that' really nasty and going to bite us at some point.
How about adding (with better naming);
int *infomask_nums;
//could drop next one if we define a magic termination value. int infomask_nums_number;
to iio_chan_spec.
where for example
static int inf_mask_nums[] = { [IIO_CHAN_INFO_FREQUENCY] = 7;
...
};
static struct iio_chan_spec bobschannels[] = { {
...usual stuff.
.info_mask = IIO_CHAN_INFO_FREQUENCY_SEPARATE_BIT, .infomask_nums = inf_mask_nums, .infomask_nums_number = ARRAY_SIZE(inf_mask_nums),
}
};
The parsing logic then create
in_accelX_freq0...in_accelX_freq6
This functionality may also be useful for filter taps...
Obviously the above creates large tables, so for space saving we may want to use a structure pairing IIO_CHAN_INFO_WWWWW with the number. Can terminate that with a 0,0 entry and loose the counter as well. (I like this version better come to think of it).
One other thought is that we may run into issues with the number of elements in the infomask. Only split I can think of is to put the shared elements in one mask and the separate ones in another.
Quoted 4 lines
since I may need the current postfixes such as
_scaleas well.
out_altvoltageX_freqY_scaleout_altvoltageX_phaseY_scale
My initial thought on this is that these are ulikely to be written in a particularly fast path, so we could avoid scale etc for them by dictating that they are written in the correct units? We already do this for things like sampling frequency.
If we take things to this many levels it is going to get very confusing. The raw and scale stuff only makes sense for stuff on fast paths. (Now I expect you will come up with an application where this is pushed from a buffer just to prove me wrong ;)
Quoted 3 lines
An alternative could be to introduce an indexed
extended_name, using the index passed in channel2? Not sure if it is worth adding it?
I would rather not as stated above. Handling logic will rely on reading that name which we have been desperately avoiding so far.
Quoted 4 lines
Michael Hennerich
maintainerQuoted 33 lines · J.I. Cameron
Quoted 31 lines · Michael Hennerich
Quoted 20 lines · J.I. Cameron
Quoted 18 lines · Michael Hennerich
Quoted 11 lines · Jonathan Cameron
Quoted 3 lines · Michael Hennerich
Quoted 2 lines · Jonathan Cameron
On 12/09/2011 01:22 PM, [email protected] wrote:
There is also the double indexes that we don't allow anywhere else. They are here because we have different waveforms with same underlying channel. We could had a bonus optional index to all channels I suppose and have this as the only current user? Or maybe just a flag to say its a 'subchannel' and use channel2. Afterall these channels are neither going to have modifiers or to be differential so I can't see a clash occuring on the use of that...
Well one of the indexes with the DDS parts is used to distinguish the tuning words options, in combination with the pincontrol feature. PLL devices typically doesn't feature this.
So bottom line - can we agree on:
Quoted 8 lines
Quoted 6 lines
out_altvoltageX_freqYout_altvoltageX_phaseYout_altvoltageX_scaleout_altvoltageX_enable
...
Where X stands for the output channel, and Y for some sort of option.Looks good as far as I am concerned. Might be worth a quick check through of dds and meter devices to see how we can extend this to cover them.
Hi Jonathan,
Quoted 8 lines
Quoted 6 lines
Looked at the various use cases. And the only user for the second subindex seems to be the DDS parts.
I now wondering if we should handle freqY and phaseY by using
extended_name, rather than adding new postfixes for them. Which is going to be difficult anyways,Use extend name will make for some hideous logic in the
read_raw,write_rawfunctions.
That really depends. I would need to add multiple channels to channel_spec. We can use .channel2 as well as .address to distinguish the 'extended_names', without the need to parse strings.
Quoted 12 lines
If we need it (and it looks like we do), lets make whatever
changes are necessary to do this cleanly in the chan spec structure. I'd been avoiding the DDS parts so far because I have little idea of how to make them play nicely withiio_chan_spec.Ideally freq and phase would be chaninfo elements. Given that is a mask there is no obvious way of storing the associated index. This also effects the
write_rawandread_rawfunctions as they have no way to get to that index either. That one could be avoided by changing them to take a u64 and embedding the index in a few bits of that
(fiddly carrying that through everywhere but not too bad).
Quoted 2 lines
We could simply define a set of freq0 freq1 freq2 as separate elements of the info mask, but that' really nasty and going to bite us at some point.
My fear is that we run out of bits in chaninfo pretty shortly, adding bits that aren't used frequently is not going to help.
Quoted 22 lines
How about adding (with better naming);
int
*infomask_nums;
//could drop next one if we define a magic termination value. intinfomask_nums_number;
toiio_chan_spec.where for example
static int inf_mask_nums[] = { [
IIO_CHAN_INFO_FREQUENCY] = 7;
...
};
static structiio_chan_specbobschannels[] = { {
...usual stuff.
.info_mask =IIO_CHAN_INFO_FREQUENCY_SEPARATE_BIT, .infomask_nums =inf_mask_nums, .infomask_nums_number =ARRAY_SIZE(inf_mask_nums),
}
};
Quoted 3 lines
The parsing logic then create
in_accelX_freq0...in_accelX_freq6
From a core pint of view, it will work an create X attributes, but without changing [read|write]_raw function parameter API, how will you determine which X is currently processed?
Quoted 6 lines
This functionality may also be useful for filter taps...
Obviously the above creates large tables, so for space saving we may want to use a structure pairing
IIO_CHAN_INFO_WWWWWwith the number. Can terminate that with a 0,0 entry and loose the counter as well. (I like this version better come to think of it).
Sorry can you explain in more detail?
Quoted 3 lines
One other thought is that we may run into issues with the number of elements in the infomask. Only split I can think of is to put the shared elements in one mask and the separate ones in another.
but then we are still limited to 32 versus 16 today... But we could increase to u64 at some day.
Quoted 9 lines
Quoted 4 lines
since I may need the current postfixes such as
_scaleas well.
out_altvoltageX_freqY_scaleout_altvoltageX_phaseY_scaleMy initial thought on this is that these are ulikely to be written in a particularly fast path, so we could avoid scale etc for them by dictating that they are written in the correct units? We already do this for things like sampling frequency.
Quoted 4 lines
If we take things to this many levels it is going to get very confusing. The raw and scale stuff only makes sense for stuff on fast paths. (Now I expect you will come up with an application where this is pushed from a buffer just to prove me wrong ;)
FSK, PSK modulation for example ;-)
Quoted 4 lines
Quoted 2 lines
An alternative could be to introduce an indexed
extended_name, using the index passed in channel2? Not sure if it is worth adding it?I would rather not as stated above. Handling logic will rely on reading that name which we have been desperately avoiding so far.
See comment above
Signature · 8 lines
Greetings, Michael -- Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368; Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Margaret Seif
Quoted 40 lines · Michael Hennerich
Quoted 39 lines · J.I. Cameron
Quoted 37 lines · Michael Hennerich
Quoted 20 lines · J.I. Cameron
Quoted 18 lines · Michael Hennerich
Quoted 11 lines · Jonathan Cameron
Quoted 3 lines · Michael Hennerich
Quoted 2 lines · Jonathan Cameron
On 12/09/2011 01:22 PM, [email protected] wrote:
There is also the double indexes that we don't allow anywhere else. They are here because we have different waveforms with same underlying channel. We could had a bonus optional index to all channels I suppose and have this as the only current user? Or maybe just a flag to say its a 'subchannel' and use channel2. Afterall these channels are neither going to have modifiers or to be differential so I can't see a clash occuring on the use of that...
Well one of the indexes with the DDS parts is used to distinguish the tuning words options, in combination with the pincontrol feature. PLL devices typically doesn't feature this.
So bottom line - can we agree on:
Quoted 8 lines
Quoted 6 lines
out_altvoltageX_freqYout_altvoltageX_phaseYout_altvoltageX_scaleout_altvoltageX_enable
...
Where X stands for the output channel, and Y for some sort of option.Looks good as far as I am concerned. Might be worth a quick check through of dds and meter devices to see how we can extend this to cover them.
Hi Jonathan,
Looked at the various use cases. And the only user for the second subindex seems to be the DDS parts.
I now wondering if we should handle freqY and phaseY by using
extended_name, rather than adding new postfixes for them. Which is going to be difficult anyways,
Quoted 6 lines
Quoted 2 lines
Use extend name will make for some hideous logic in the
read_raw,write_rawfunctions.That really depends. I would need to add multiple channels to
channel_spec. We can use .channel2 as well as .address to distinguish the 'extended_names', without the need to parse strings.
Still doesn't exactly look tidy!
Quoted 13 lines
Quoted 13 lines
If we need it (and it looks like we do), lets make whatever
changes are necessary to do this cleanly in the chan spec structure. I'd been avoiding the DDS parts so far because I have little idea of how to make them play nicely withiio_chan_spec.Ideally freq and phase would be chaninfo elements. Given that is a mask there is no obvious way of storing the associated index. This also effects the
write_rawandread_rawfunctions as they have no way to get to that index either. That one could be avoided by changing them to take a u64 and embedding the index in a few bits of that
(fiddly carrying that through everywhere but not too bad).
Quoted 4 lines
Quoted 2 lines
We could simply define a set of freq0 freq1 freq2 as separate elements of the info mask, but that' really nasty and going to bite us at some point.
My fear is that we run out of bits in chaninfo pretty shortly, adding bits that aren't used frequently is not going to help.
Agreed
Quoted 23 lines
Quoted 23 lines
How about adding (with better naming);
int
*infomask_nums;
//could drop next one if we define a magic termination value. intinfomask_nums_number;
toiio_chan_spec.where for example
static int inf_mask_nums[] = { [
IIO_CHAN_INFO_FREQUENCY] = 7;
...
};
static structiio_chan_specbobschannels[] = { {
...usual stuff.
.info_mask =IIO_CHAN_INFO_FREQUENCY_SEPARATE_BIT, .infomask_nums =inf_mask_nums, .infomask_nums_number =ARRAY_SIZE(inf_mask_nums),
}
};
Quoted 6 lines
Quoted 3 lines
The parsing logic then create
in_accelX_freq0...in_accelX_freq6
From a core pint of view, it will work an create X attributes, but without changing [read|write]_raw function parameter API, how will you determine which X is currently processed?
Take the mask up to a u64 and hide X in the high bits of that. thus, those who don't care don't see if and those who do can# pull it out. Not pretty though.
Quoted 7 lines
Quoted 7 lines
This functionality may also be useful for filter taps...
Obviously the above creates large tables, so for space saving we may want to use a structure pairing
IIO_CHAN_INFO_WWWWWwith the number. Can terminate that with a 0,0 entry and loose the counter as well. (I like this version better come to think of it).
Quoted 6 lines
Sorry can you explain in more detail?
Quoted 3 lines
One other thought is that we may run into issues with the number of elements in the infomask. Only split I can think of is to put the shared elements in one mask and the separate ones in another.
but then we are still limited to 32 versus 16 today... But we could increase to u64 at some day.
Indeed. I'd take them up to a general bitmap (or array of longs as statically assigned) but can't think of a clean way to then assign bits in them in the drivers. Alternative is a 0 terminated array of which elements are there. If we decide to do that then we probably want to make the switch sooner rather than later.
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
since I may need the current postfixes such as
_scaleas well.
out_altvoltageX_freqY_scaleout_altvoltageX_phaseY_scaleMy initial thought on this is that these are ulikely to be written in a particularly fast path, so we could avoid scale etc for them by dictating that they are written in the correct units? We already do this for things like sampling frequency.
Quoted 5 lines
Quoted 4 lines
If we take things to this many levels it is going to get very confusing. The raw and scale stuff only makes sense for stuff on fast paths. (Now I expect you will come up with an application where this is pushed from a buffer just to prove me wrong ;)
FSK, PSK modulation for example ;-)
But in those you typically write the symbol frequencies once and then
bang the controls that switch between them. If you are doing frequency
hopping then things are going to get pretty nasty. Could hit this
if trying to do fsk with a general purpose sine wave generator, but then I think the work 'Brave' comes to mind ;)
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
An alternative could be to introduce an indexed
extended_name, using the index passed in channel2? Not sure if it is worth adding it?I would rather not as stated above. Handling logic will rely on reading that name which we have been desperately avoiding so far.
See comment above