diff options
Diffstat (limited to 'drivers/staging/iio/frequency')
-rw-r--r-- | drivers/staging/iio/frequency/ad9832.c | 10 | ||||
-rw-r--r-- | drivers/staging/iio/frequency/ad9832.h | 12 | ||||
-rw-r--r-- | drivers/staging/iio/frequency/ad9834.c | 45 | ||||
-rw-r--r-- | drivers/staging/iio/frequency/ad9834.h | 37 | ||||
-rw-r--r-- | drivers/staging/iio/frequency/dds.h | 4 |
5 files changed, 56 insertions, 52 deletions
diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c index cf68159a5848..a861fe0149b1 100644 --- a/drivers/staging/iio/frequency/ad9832.c +++ b/drivers/staging/iio/frequency/ad9832.c @@ -24,8 +24,8 @@ static unsigned long ad9832_calc_freqreg(unsigned long mclk, unsigned long fout) { - unsigned long long freqreg = (u64) fout * - (u64) ((u64) 1L << AD9832_FREQ_BITS); + unsigned long long freqreg = (u64)fout * + (u64)((u64)1L << AD9832_FREQ_BITS); do_div(freqreg, mclk); return freqreg; } @@ -59,7 +59,7 @@ static int ad9832_write_frequency(struct ad9832_state *st, static int ad9832_write_phase(struct ad9832_state *st, unsigned long addr, unsigned long phase) { - if (phase > (1 << AD9832_PHASE_BITS)) + if (phase > BIT(AD9832_PHASE_BITS)) return -EINVAL; st->phase_data[0] = cpu_to_be16((AD9832_CMD_PHA8BITSW << CMD_SHIFT) | @@ -86,7 +86,7 @@ static ssize_t ad9832_write(struct device *dev, struct device_attribute *attr, goto error_ret; mutex_lock(&indio_dev->mlock); - switch ((u32) this_attr->address) { + switch ((u32)this_attr->address) { case AD9832_FREQ0HM: case AD9832_FREQ1HM: ret = ad9832_write_frequency(st, this_attr->address, val); @@ -220,7 +220,7 @@ static int ad9832_probe(struct spi_device *spi) } indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); - if (indio_dev == NULL) { + if (!indio_dev) { ret = -ENOMEM; goto error_disable_reg; } diff --git a/drivers/staging/iio/frequency/ad9832.h b/drivers/staging/iio/frequency/ad9832.h index 386f4dc8c9a1..d32323b46be6 100644 --- a/drivers/staging/iio/frequency/ad9832.h +++ b/drivers/staging/iio/frequency/ad9832.h @@ -42,13 +42,13 @@ #define AD9832_CMD_SYNCSELSRC 0x8 #define AD9832_CMD_SLEEPRESCLR 0xC -#define AD9832_FREQ (1 << 11) +#define AD9832_FREQ BIT(11) #define AD9832_PHASE(x) (((x) & 3) << 9) -#define AD9832_SYNC (1 << 13) -#define AD9832_SELSRC (1 << 12) -#define AD9832_SLEEP (1 << 13) -#define AD9832_RESET (1 << 12) -#define AD9832_CLR (1 << 11) +#define AD9832_SYNC BIT(13) +#define AD9832_SELSRC BIT(12) +#define AD9832_SLEEP BIT(13) +#define AD9832_RESET BIT(12) +#define AD9832_CLR BIT(11) #define CMD_SHIFT 12 #define ADD_SHIFT 8 #define AD9832_FREQ_BITS 32 diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c index 5c803191c2ce..d02bb44fb8fc 100644 --- a/drivers/staging/iio/frequency/ad9834.c +++ b/drivers/staging/iio/frequency/ad9834.c @@ -27,7 +27,7 @@ static unsigned int ad9834_calc_freqreg(unsigned long mclk, unsigned long fout) { - unsigned long long freqreg = (u64) fout * (u64) (1 << AD9834_FREQ_BITS); + unsigned long long freqreg = (u64)fout * (u64)BIT(AD9834_FREQ_BITS); do_div(freqreg, mclk); return freqreg; @@ -53,9 +53,9 @@ static int ad9834_write_frequency(struct ad9834_state *st, } static int ad9834_write_phase(struct ad9834_state *st, - unsigned long addr, unsigned long phase) + unsigned long addr, unsigned long phase) { - if (phase > (1 << AD9834_PHASE_BITS)) + if (phase > BIT(AD9834_PHASE_BITS)) return -EINVAL; st->data = cpu_to_be16(addr | phase); @@ -63,9 +63,9 @@ static int ad9834_write_phase(struct ad9834_state *st, } static ssize_t ad9834_write(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ad9834_state *st = iio_priv(indio_dev); @@ -78,7 +78,7 @@ static ssize_t ad9834_write(struct device *dev, goto error_ret; mutex_lock(&indio_dev->mlock); - switch ((u32) this_attr->address) { + switch ((u32)this_attr->address) { case AD9834_REG_FREQ0: case AD9834_REG_FREQ1: ret = ad9834_write_frequency(st, this_attr->address, val); @@ -111,9 +111,9 @@ static ssize_t ad9834_write(struct device *dev, break; case AD9834_FSEL: case AD9834_PSEL: - if (val == 0) + if (val == 0) { st->control &= ~(this_attr->address | AD9834_PIN_SW); - else if (val == 1) { + } else if (val == 1) { st->control |= this_attr->address; st->control &= ~AD9834_PIN_SW; } else { @@ -142,9 +142,9 @@ error_ret: } static ssize_t ad9834_store_wavetype(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ad9834_state *st = iio_priv(indio_dev); @@ -154,7 +154,7 @@ static ssize_t ad9834_store_wavetype(struct device *dev, mutex_lock(&indio_dev->mlock); - switch ((u32) this_attr->address) { + switch ((u32)this_attr->address) { case 0: if (sysfs_streq(buf, "sine")) { st->control &= ~AD9834_MODE; @@ -179,7 +179,7 @@ static ssize_t ad9834_store_wavetype(struct device *dev, break; case 1: if (sysfs_streq(buf, "square") && - !(st->control & AD9834_MODE)) { + !(st->control & AD9834_MODE)) { st->control &= ~AD9834_MODE; st->control |= AD9834_OPBITEN; } else { @@ -200,9 +200,10 @@ static ssize_t ad9834_store_wavetype(struct device *dev, return ret ? ret : len; } -static ssize_t ad9834_show_out0_wavetype_available(struct device *dev, - struct device_attribute *attr, - char *buf) +static +ssize_t ad9834_show_out0_wavetype_available(struct device *dev, + struct device_attribute *attr, + char *buf) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ad9834_state *st = iio_priv(indio_dev); @@ -218,13 +219,13 @@ static ssize_t ad9834_show_out0_wavetype_available(struct device *dev, return sprintf(buf, "%s\n", str); } - static IIO_DEVICE_ATTR(out_altvoltage0_out0_wavetype_available, S_IRUGO, ad9834_show_out0_wavetype_available, NULL, 0); -static ssize_t ad9834_show_out1_wavetype_available(struct device *dev, - struct device_attribute *attr, - char *buf) +static +ssize_t ad9834_show_out1_wavetype_available(struct device *dev, + struct device_attribute *attr, + char *buf) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ad9834_state *st = iio_priv(indio_dev); @@ -336,7 +337,7 @@ static int ad9834_probe(struct spi_device *spi) } indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); - if (indio_dev == NULL) { + if (!indio_dev) { ret = -ENOMEM; goto error_disable_reg; } diff --git a/drivers/staging/iio/frequency/ad9834.h b/drivers/staging/iio/frequency/ad9834.h index 8ca6e52bae6b..40fdd5da7bd0 100644 --- a/drivers/staging/iio/frequency/ad9834.h +++ b/drivers/staging/iio/frequency/ad9834.h @@ -10,31 +10,31 @@ /* Registers */ -#define AD9834_REG_CMD (0 << 14) -#define AD9834_REG_FREQ0 (1 << 14) -#define AD9834_REG_FREQ1 (2 << 14) -#define AD9834_REG_PHASE0 (6 << 13) -#define AD9834_REG_PHASE1 (7 << 13) +#define AD9834_REG_CMD 0 +#define AD9834_REG_FREQ0 BIT(14) +#define AD9834_REG_FREQ1 BIT(15) +#define AD9834_REG_PHASE0 (BIT(15) | BIT(14)) +#define AD9834_REG_PHASE1 (BIT(15) | BIT(14) | BIT(13)) /* Command Control Bits */ -#define AD9834_B28 (1 << 13) -#define AD9834_HLB (1 << 12) -#define AD9834_FSEL (1 << 11) -#define AD9834_PSEL (1 << 10) -#define AD9834_PIN_SW (1 << 9) -#define AD9834_RESET (1 << 8) -#define AD9834_SLEEP1 (1 << 7) -#define AD9834_SLEEP12 (1 << 6) -#define AD9834_OPBITEN (1 << 5) -#define AD9834_SIGN_PIB (1 << 4) -#define AD9834_DIV2 (1 << 3) -#define AD9834_MODE (1 << 1) +#define AD9834_B28 BIT(13) +#define AD9834_HLB BIT(12) +#define AD9834_FSEL BIT(11) +#define AD9834_PSEL BIT(10) +#define AD9834_PIN_SW BIT(9) +#define AD9834_RESET BIT(8) +#define AD9834_SLEEP1 BIT(7) +#define AD9834_SLEEP12 BIT(6) +#define AD9834_OPBITEN BIT(5) +#define AD9834_SIGN_PIB BIT(4) +#define AD9834_DIV2 BIT(3) +#define AD9834_MODE BIT(1) #define AD9834_FREQ_BITS 28 #define AD9834_PHASE_BITS 12 -#define RES_MASK(bits) ((1 << (bits)) - 1) +#define RES_MASK(bits) (BIT(bits) - 1) /** * struct ad9834_state - driver instance specific data @@ -69,7 +69,6 @@ struct ad9834_state { __be16 freq_data[2]; }; - /* * TODO: struct ad7887_platform_data needs to go into include/linux/iio */ diff --git a/drivers/staging/iio/frequency/dds.h b/drivers/staging/iio/frequency/dds.h index 611e2b0cfc4c..fe53e7324c94 100644 --- a/drivers/staging/iio/frequency/dds.h +++ b/drivers/staging/iio/frequency/dds.h @@ -5,6 +5,8 @@ * * Licensed under the GPL-2 or later. */ +#ifndef IIO_DDS_H_ +#define IIO_DDS_H_ /** * /sys/bus/iio/devices/.../out_altvoltageX_frequencyY @@ -108,3 +110,5 @@ #define IIO_CONST_ATTR_OUT_WAVETYPES_AVAILABLE(_channel, _output, _modes)\ IIO_CONST_ATTR( \ out_altvoltage##_channel##_out##_output##_wavetype_available, _modes) + +#endif /* IIO_DDS_H_ */ |