Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging:iio: Remove ad5930/ad9850/ad9852/ad9910/ad9951 dummy drivers

All what these 'drivers' do is expose a single (non standard ABI) sysfs
attribute that when written to does a direct pass-through to spi_write(). This
is rather ugly and does not justify the existence of a driver as the same can
easily done by using the spidev interface.

The drivers will eventually be rewritten as proper IIO ABI compliant drivers
which do have the proper abstraction layers between userspace and the device.
But in the meantime these driver do not add any extra value and just clutter up
the staging area. So just remove them.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Lars-Peter Clausen and committed by
Jonathan Cameron
c83441e0 4ce72abc

-1117
-35
drivers/staging/iio/frequency/Kconfig
··· 3 3 # 4 4 menu "Direct Digital Synthesis" 5 5 6 - config AD5930 7 - tristate "Analog Devices ad5930/5932 driver" 8 - depends on SPI 9 - help 10 - Say yes here to build support for Analog Devices DDS chip 11 - ad5930/ad5932, provides direct access via sysfs. 12 - 13 6 config AD9832 14 7 tristate "Analog Devices ad9832/5 driver" 15 8 depends on SPI ··· 22 29 23 30 To compile this driver as a module, choose M here: the 24 31 module will be called ad9834. 25 - 26 - config AD9850 27 - tristate "Analog Devices ad9850/1 driver" 28 - depends on SPI 29 - help 30 - Say yes here to build support for Analog Devices DDS chip 31 - ad9850/1, provides direct access via sysfs. 32 - 33 - config AD9852 34 - tristate "Analog Devices ad9852/4 driver" 35 - depends on SPI 36 - help 37 - Say yes here to build support for Analog Devices DDS chip 38 - ad9852/4, provides direct access via sysfs. 39 - 40 - config AD9910 41 - tristate "Analog Devices ad9910 driver" 42 - depends on SPI 43 - help 44 - Say yes here to build support for Analog Devices DDS chip 45 - ad9910, provides direct access via sysfs. 46 - 47 - config AD9951 48 - tristate "Analog Devices ad9951 driver" 49 - depends on SPI 50 - help 51 - Say yes here to build support for Analog Devices DDS chip 52 - ad9951, provides direct access via sysfs. 53 32 54 33 endmenu
-5
drivers/staging/iio/frequency/Makefile
··· 2 2 # Makefile for Direct Digital Synthesis drivers 3 3 # 4 4 5 - obj-$(CONFIG_AD5930) += ad5930.o 6 5 obj-$(CONFIG_AD9832) += ad9832.o 7 6 obj-$(CONFIG_AD9834) += ad9834.o 8 - obj-$(CONFIG_AD9850) += ad9850.o 9 - obj-$(CONFIG_AD9852) += ad9852.o 10 - obj-$(CONFIG_AD9910) += ad9910.o 11 - obj-$(CONFIG_AD9951) += ad9951.o
-140
drivers/staging/iio/frequency/ad5930.c
··· 1 - /* 2 - * Driver for ADI Direct Digital Synthesis ad5930 3 - * 4 - * Copyright (c) 2010-2010 Analog Devices Inc. 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License version 2 as 8 - * published by the Free Software Foundation. 9 - * 10 - */ 11 - #include <linux/types.h> 12 - #include <linux/mutex.h> 13 - #include <linux/device.h> 14 - #include <linux/spi/spi.h> 15 - #include <linux/slab.h> 16 - #include <linux/sysfs.h> 17 - #include <linux/module.h> 18 - 19 - #include <linux/iio/iio.h> 20 - #include <linux/iio/sysfs.h> 21 - 22 - #define DRV_NAME "ad5930" 23 - 24 - #define value_mask (u16)0xf000 25 - #define addr_shift 12 26 - 27 - /* Register format: 4 bits addr + 12 bits value */ 28 - struct ad5903_config { 29 - u16 control; 30 - u16 incnum; 31 - u16 frqdelt[2]; 32 - u16 incitvl; 33 - u16 buritvl; 34 - u16 strtfrq[2]; 35 - }; 36 - 37 - struct ad5930_state { 38 - struct mutex lock; 39 - struct spi_device *sdev; 40 - }; 41 - 42 - static ssize_t ad5930_set_parameter(struct device *dev, 43 - struct device_attribute *attr, 44 - const char *buf, 45 - size_t len) 46 - { 47 - struct spi_transfer xfer; 48 - int ret; 49 - struct ad5903_config *config = (struct ad5903_config *)buf; 50 - struct iio_dev *idev = dev_to_iio_dev(dev); 51 - struct ad5930_state *st = iio_priv(idev); 52 - 53 - config->control = (config->control & ~value_mask); 54 - config->incnum = (config->control & ~value_mask) | (1 << addr_shift); 55 - config->frqdelt[0] = (config->control & ~value_mask) | (2 << addr_shift); 56 - config->frqdelt[1] = (config->control & ~value_mask) | 3 << addr_shift; 57 - config->incitvl = (config->control & ~value_mask) | 4 << addr_shift; 58 - config->buritvl = (config->control & ~value_mask) | 8 << addr_shift; 59 - config->strtfrq[0] = (config->control & ~value_mask) | 0xc << addr_shift; 60 - config->strtfrq[1] = (config->control & ~value_mask) | 0xd << addr_shift; 61 - 62 - xfer.len = len; 63 - xfer.tx_buf = config; 64 - mutex_lock(&st->lock); 65 - 66 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 67 - if (ret) 68 - goto error_ret; 69 - error_ret: 70 - mutex_unlock(&st->lock); 71 - 72 - return ret ? ret : len; 73 - } 74 - 75 - static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad5930_set_parameter, 0); 76 - 77 - static struct attribute *ad5930_attributes[] = { 78 - &iio_dev_attr_dds.dev_attr.attr, 79 - NULL, 80 - }; 81 - 82 - static const struct attribute_group ad5930_attribute_group = { 83 - .attrs = ad5930_attributes, 84 - }; 85 - 86 - static const struct iio_info ad5930_info = { 87 - .attrs = &ad5930_attribute_group, 88 - .driver_module = THIS_MODULE, 89 - }; 90 - 91 - static int ad5930_probe(struct spi_device *spi) 92 - { 93 - struct ad5930_state *st; 94 - struct iio_dev *idev; 95 - int ret = 0; 96 - 97 - idev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 98 - if (!idev) 99 - return -ENOMEM; 100 - spi_set_drvdata(spi, idev); 101 - st = iio_priv(idev); 102 - 103 - mutex_init(&st->lock); 104 - st->sdev = spi; 105 - idev->dev.parent = &spi->dev; 106 - idev->info = &ad5930_info; 107 - idev->modes = INDIO_DIRECT_MODE; 108 - 109 - ret = iio_device_register(idev); 110 - if (ret) 111 - return ret; 112 - spi->max_speed_hz = 2000000; 113 - spi->mode = SPI_MODE_3; 114 - spi->bits_per_word = 16; 115 - spi_setup(spi); 116 - 117 - return 0; 118 - } 119 - 120 - static int ad5930_remove(struct spi_device *spi) 121 - { 122 - iio_device_unregister(spi_get_drvdata(spi)); 123 - 124 - return 0; 125 - } 126 - 127 - static struct spi_driver ad5930_driver = { 128 - .driver = { 129 - .name = DRV_NAME, 130 - .owner = THIS_MODULE, 131 - }, 132 - .probe = ad5930_probe, 133 - .remove = ad5930_remove, 134 - }; 135 - module_spi_driver(ad5930_driver); 136 - 137 - MODULE_AUTHOR("Cliff Cai"); 138 - MODULE_DESCRIPTION("Analog Devices ad5930 driver"); 139 - MODULE_LICENSE("GPL v2"); 140 - MODULE_ALIAS("spi:" DRV_NAME);
-120
drivers/staging/iio/frequency/ad9850.c
··· 1 - /* 2 - * Driver for ADI Direct Digital Synthesis ad9850 3 - * 4 - * Copyright (c) 2010-2010 Analog Devices Inc. 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License version 2 as 8 - * published by the Free Software Foundation. 9 - * 10 - */ 11 - #include <linux/types.h> 12 - #include <linux/mutex.h> 13 - #include <linux/device.h> 14 - #include <linux/spi/spi.h> 15 - #include <linux/slab.h> 16 - #include <linux/sysfs.h> 17 - #include <linux/module.h> 18 - 19 - #include <linux/iio/iio.h> 20 - #include <linux/iio/sysfs.h> 21 - 22 - #define DRV_NAME "ad9850" 23 - 24 - /* Register format: 4 bits addr + 12 bits value */ 25 - struct ad9850_config { 26 - u8 control[5]; 27 - }; 28 - 29 - struct ad9850_state { 30 - struct mutex lock; 31 - struct spi_device *sdev; 32 - }; 33 - 34 - static ssize_t ad9850_set_parameter(struct device *dev, 35 - struct device_attribute *attr, 36 - const char *buf, 37 - size_t len) 38 - { 39 - struct spi_transfer xfer; 40 - int ret; 41 - struct ad9850_config *config = (struct ad9850_config *)buf; 42 - struct iio_dev *idev = dev_to_iio_dev(dev); 43 - struct ad9850_state *st = iio_priv(idev); 44 - 45 - xfer.len = len; 46 - xfer.tx_buf = config; 47 - mutex_lock(&st->lock); 48 - 49 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 50 - mutex_unlock(&st->lock); 51 - 52 - return ret ? ret : len; 53 - } 54 - 55 - static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad9850_set_parameter, 0); 56 - 57 - static struct attribute *ad9850_attributes[] = { 58 - &iio_dev_attr_dds.dev_attr.attr, 59 - NULL, 60 - }; 61 - 62 - static const struct attribute_group ad9850_attribute_group = { 63 - .attrs = ad9850_attributes, 64 - }; 65 - 66 - static const struct iio_info ad9850_info = { 67 - .attrs = &ad9850_attribute_group, 68 - .driver_module = THIS_MODULE, 69 - }; 70 - 71 - static int ad9850_probe(struct spi_device *spi) 72 - { 73 - struct ad9850_state *st; 74 - struct iio_dev *idev; 75 - int ret = 0; 76 - 77 - idev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 78 - if (!idev) 79 - return -ENOMEM; 80 - spi_set_drvdata(spi, idev); 81 - st = iio_priv(idev); 82 - mutex_init(&st->lock); 83 - st->sdev = spi; 84 - 85 - idev->dev.parent = &spi->dev; 86 - idev->info = &ad9850_info; 87 - idev->modes = INDIO_DIRECT_MODE; 88 - 89 - ret = iio_device_register(idev); 90 - if (ret) 91 - return ret; 92 - spi->max_speed_hz = 2000000; 93 - spi->mode = SPI_MODE_3; 94 - spi->bits_per_word = 16; 95 - spi_setup(spi); 96 - 97 - return 0; 98 - } 99 - 100 - static int ad9850_remove(struct spi_device *spi) 101 - { 102 - iio_device_unregister(spi_get_drvdata(spi)); 103 - 104 - return 0; 105 - } 106 - 107 - static struct spi_driver ad9850_driver = { 108 - .driver = { 109 - .name = DRV_NAME, 110 - .owner = THIS_MODULE, 111 - }, 112 - .probe = ad9850_probe, 113 - .remove = ad9850_remove, 114 - }; 115 - module_spi_driver(ad9850_driver); 116 - 117 - MODULE_AUTHOR("Cliff Cai"); 118 - MODULE_DESCRIPTION("Analog Devices ad9850 driver"); 119 - MODULE_LICENSE("GPL v2"); 120 - MODULE_ALIAS("spi:" DRV_NAME);
-245
drivers/staging/iio/frequency/ad9852.c
··· 1 - /* 2 - * Driver for ADI Direct Digital Synthesis ad9852 3 - * 4 - * Copyright (c) 2010 Analog Devices Inc. 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License version 2 as 8 - * published by the Free Software Foundation. 9 - * 10 - */ 11 - #include <linux/types.h> 12 - #include <linux/mutex.h> 13 - #include <linux/device.h> 14 - #include <linux/spi/spi.h> 15 - #include <linux/slab.h> 16 - #include <linux/sysfs.h> 17 - #include <linux/module.h> 18 - 19 - #include <linux/iio/iio.h> 20 - #include <linux/iio/sysfs.h> 21 - 22 - #define DRV_NAME "ad9852" 23 - 24 - #define addr_phaad1 0x0 25 - #define addr_phaad2 0x1 26 - #define addr_fretu1 0x2 27 - #define addr_fretu2 0x3 28 - #define addr_delfre 0x4 29 - #define addr_updclk 0x5 30 - #define addr_ramclk 0x6 31 - #define addr_contrl 0x7 32 - #define addr_optskm 0x8 33 - #define addr_optskr 0xa 34 - #define addr_dacctl 0xb 35 - 36 - #define COMPPD (1 << 4) 37 - #define REFMULT2 (1 << 2) 38 - #define BYPPLL (1 << 5) 39 - #define PLLRANG (1 << 6) 40 - #define IEUPCLK (1) 41 - #define OSKEN (1 << 5) 42 - 43 - #define read_bit (1 << 7) 44 - 45 - /* Register format: 1 byte addr + value */ 46 - struct ad9852_config { 47 - u8 phajst0[3]; 48 - u8 phajst1[3]; 49 - u8 fretun1[6]; 50 - u8 fretun2[6]; 51 - u8 dltafre[6]; 52 - u8 updtclk[5]; 53 - u8 ramprat[4]; 54 - u8 control[5]; 55 - u8 outpskm[3]; 56 - u8 outpskr[2]; 57 - u8 daccntl[3]; 58 - }; 59 - 60 - struct ad9852_state { 61 - struct mutex lock; 62 - struct spi_device *sdev; 63 - }; 64 - 65 - static ssize_t ad9852_set_parameter(struct device *dev, 66 - struct device_attribute *attr, 67 - const char *buf, 68 - size_t len) 69 - { 70 - struct spi_transfer xfer; 71 - int ret; 72 - struct ad9852_config *config = (struct ad9852_config *)buf; 73 - struct iio_dev *idev = dev_to_iio_dev(dev); 74 - struct ad9852_state *st = iio_priv(idev); 75 - 76 - xfer.len = 3; 77 - xfer.tx_buf = &config->phajst0[0]; 78 - mutex_lock(&st->lock); 79 - 80 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 81 - if (ret) 82 - goto error_ret; 83 - 84 - xfer.len = 3; 85 - xfer.tx_buf = &config->phajst1[0]; 86 - 87 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 88 - if (ret) 89 - goto error_ret; 90 - 91 - xfer.len = 6; 92 - xfer.tx_buf = &config->fretun1[0]; 93 - 94 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 95 - if (ret) 96 - goto error_ret; 97 - 98 - xfer.len = 6; 99 - xfer.tx_buf = &config->fretun2[0]; 100 - 101 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 102 - if (ret) 103 - goto error_ret; 104 - 105 - xfer.len = 6; 106 - xfer.tx_buf = &config->dltafre[0]; 107 - 108 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 109 - if (ret) 110 - goto error_ret; 111 - 112 - xfer.len = 5; 113 - xfer.tx_buf = &config->updtclk[0]; 114 - 115 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 116 - if (ret) 117 - goto error_ret; 118 - 119 - xfer.len = 4; 120 - xfer.tx_buf = &config->ramprat[0]; 121 - 122 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 123 - if (ret) 124 - goto error_ret; 125 - 126 - xfer.len = 5; 127 - xfer.tx_buf = &config->control[0]; 128 - 129 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 130 - if (ret) 131 - goto error_ret; 132 - 133 - xfer.len = 3; 134 - xfer.tx_buf = &config->outpskm[0]; 135 - 136 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 137 - if (ret) 138 - goto error_ret; 139 - 140 - xfer.len = 2; 141 - xfer.tx_buf = &config->outpskr[0]; 142 - 143 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 144 - if (ret) 145 - goto error_ret; 146 - 147 - xfer.len = 3; 148 - xfer.tx_buf = &config->daccntl[0]; 149 - 150 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 151 - if (ret) 152 - goto error_ret; 153 - error_ret: 154 - mutex_unlock(&st->lock); 155 - 156 - return ret ? ret : len; 157 - } 158 - 159 - static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad9852_set_parameter, 0); 160 - 161 - static void ad9852_init(struct ad9852_state *st) 162 - { 163 - struct spi_transfer xfer; 164 - int ret; 165 - u8 config[5]; 166 - 167 - config[0] = addr_contrl; 168 - config[1] = COMPPD; 169 - config[2] = REFMULT2 | BYPPLL | PLLRANG; 170 - config[3] = IEUPCLK; 171 - config[4] = OSKEN; 172 - 173 - mutex_lock(&st->lock); 174 - 175 - xfer.len = 5; 176 - xfer.tx_buf = &config; 177 - 178 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 179 - if (ret) 180 - goto error_ret; 181 - 182 - error_ret: 183 - mutex_unlock(&st->lock); 184 - 185 - 186 - 187 - } 188 - 189 - static struct attribute *ad9852_attributes[] = { 190 - &iio_dev_attr_dds.dev_attr.attr, 191 - NULL, 192 - }; 193 - 194 - static const struct attribute_group ad9852_attribute_group = { 195 - .attrs = ad9852_attributes, 196 - }; 197 - 198 - static const struct iio_info ad9852_info = { 199 - .attrs = &ad9852_attribute_group, 200 - .driver_module = THIS_MODULE, 201 - }; 202 - 203 - static int ad9852_probe(struct spi_device *spi) 204 - { 205 - struct ad9852_state *st; 206 - struct iio_dev *idev; 207 - int ret = 0; 208 - 209 - idev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 210 - if (!idev) 211 - return -ENOMEM; 212 - st = iio_priv(idev); 213 - spi_set_drvdata(spi, idev); 214 - mutex_init(&st->lock); 215 - st->sdev = spi; 216 - 217 - idev->dev.parent = &spi->dev; 218 - idev->info = &ad9852_info; 219 - idev->modes = INDIO_DIRECT_MODE; 220 - 221 - ret = devm_iio_device_register(&spi->dev, idev); 222 - if (ret) 223 - return ret; 224 - spi->max_speed_hz = 2000000; 225 - spi->mode = SPI_MODE_3; 226 - spi->bits_per_word = 8; 227 - spi_setup(spi); 228 - ad9852_init(st); 229 - 230 - return 0; 231 - } 232 - 233 - static struct spi_driver ad9852_driver = { 234 - .driver = { 235 - .name = DRV_NAME, 236 - .owner = THIS_MODULE, 237 - }, 238 - .probe = ad9852_probe, 239 - }; 240 - module_spi_driver(ad9852_driver); 241 - 242 - MODULE_AUTHOR("Cliff Cai"); 243 - MODULE_DESCRIPTION("Analog Devices ad9852 driver"); 244 - MODULE_LICENSE("GPL v2"); 245 - MODULE_ALIAS("spi:" DRV_NAME);
-371
drivers/staging/iio/frequency/ad9910.c
··· 1 - /* 2 - * Driver for ADI Direct Digital Synthesis ad9910 3 - * 4 - * Copyright (c) 2010 Analog Devices Inc. 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License version 2 as 8 - * published by the Free Software Foundation. 9 - * 10 - */ 11 - #include <linux/types.h> 12 - #include <linux/mutex.h> 13 - #include <linux/device.h> 14 - #include <linux/spi/spi.h> 15 - #include <linux/slab.h> 16 - #include <linux/sysfs.h> 17 - #include <linux/module.h> 18 - 19 - #include <linux/iio/iio.h> 20 - #include <linux/iio/sysfs.h> 21 - 22 - #define DRV_NAME "ad9910" 23 - 24 - #define CFR1 0x0 25 - #define CFR2 0x1 26 - #define CFR3 0x2 27 - 28 - #define AUXDAC 0x3 29 - #define IOUPD 0x4 30 - #define FTW 0x7 31 - #define POW 0x8 32 - #define ASF 0x9 33 - #define MULTC 0x0A 34 - #define DIG_RAMPL 0x0B 35 - #define DIG_RAMPS 0x0C 36 - #define DIG_RAMPR 0x0D 37 - #define SIN_TONEP0 0x0E 38 - #define SIN_TONEP1 0x0F 39 - #define SIN_TONEP2 0x10 40 - #define SIN_TONEP3 0x11 41 - #define SIN_TONEP4 0x12 42 - #define SIN_TONEP5 0x13 43 - #define SIN_TONEP6 0x14 44 - #define SIN_TONEP7 0x15 45 - 46 - #define RAM_ENABLE (1 << 7) 47 - 48 - #define MANUAL_OSK (1 << 7) 49 - #define INVSIC (1 << 6) 50 - #define DDS_SINEOP (1) 51 - 52 - #define AUTO_OSK (1) 53 - #define OSKEN (1 << 1) 54 - #define LOAD_ARR (1 << 2) 55 - #define CLR_PHA (1 << 3) 56 - #define CLR_DIG (1 << 4) 57 - #define ACLR_PHA (1 << 5) 58 - #define ACLR_DIG (1 << 6) 59 - #define LOAD_LRR (1 << 7) 60 - 61 - #define LSB_FST (1) 62 - #define SDIO_IPT (1 << 1) 63 - #define EXT_PWD (1 << 3) 64 - #define ADAC_PWD (1 << 4) 65 - #define REFCLK_PWD (1 << 5) 66 - #define DAC_PWD (1 << 6) 67 - #define DIG_PWD (1 << 7) 68 - 69 - #define ENA_AMP (1) 70 - #define READ_FTW (1) 71 - #define DIGR_LOW (1 << 1) 72 - #define DIGR_HIGH (1 << 2) 73 - #define DIGR_ENA (1 << 3) 74 - #define SYNCCLK_ENA (1 << 6) 75 - #define ITER_IOUPD (1 << 7) 76 - 77 - #define TX_ENA (1 << 1) 78 - #define PDCLK_INV (1 << 2) 79 - #define PDCLK_ENB (1 << 3) 80 - 81 - #define PARA_ENA (1 << 4) 82 - #define SYNC_DIS (1 << 5) 83 - #define DATA_ASS (1 << 6) 84 - #define MATCH_ENA (1 << 7) 85 - 86 - #define PLL_ENA (1) 87 - #define PFD_RST (1 << 2) 88 - #define REFCLK_RST (1 << 6) 89 - #define REFCLK_BYP (1 << 7) 90 - 91 - /* Register format: 1 byte addr + value */ 92 - struct ad9910_config { 93 - u8 auxdac[5]; 94 - u8 ioupd[5]; 95 - u8 ftw[5]; 96 - u8 pow[3]; 97 - u8 asf[5]; 98 - u8 multc[5]; 99 - u8 dig_rampl[9]; 100 - u8 dig_ramps[9]; 101 - u8 dig_rampr[5]; 102 - u8 sin_tonep0[9]; 103 - u8 sin_tonep1[9]; 104 - u8 sin_tonep2[9]; 105 - u8 sin_tonep3[9]; 106 - u8 sin_tonep4[9]; 107 - u8 sin_tonep5[9]; 108 - u8 sin_tonep6[9]; 109 - u8 sin_tonep7[9]; 110 - }; 111 - 112 - struct ad9910_state { 113 - struct mutex lock; 114 - struct spi_device *sdev; 115 - }; 116 - 117 - static ssize_t ad9910_set_parameter(struct device *dev, 118 - struct device_attribute *attr, 119 - const char *buf, 120 - size_t len) 121 - { 122 - struct spi_transfer xfer; 123 - int ret; 124 - struct ad9910_config *config = (struct ad9910_config *)buf; 125 - struct iio_dev *idev = dev_to_iio_dev(dev); 126 - struct ad9910_state *st = iio_priv(idev); 127 - 128 - xfer.len = 5; 129 - xfer.tx_buf = &config->auxdac[0]; 130 - mutex_lock(&st->lock); 131 - 132 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 133 - if (ret) 134 - goto error_ret; 135 - 136 - xfer.len = 5; 137 - xfer.tx_buf = &config->ioupd[0]; 138 - 139 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 140 - if (ret) 141 - goto error_ret; 142 - 143 - xfer.len = 5; 144 - xfer.tx_buf = &config->ftw[0]; 145 - 146 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 147 - if (ret) 148 - goto error_ret; 149 - 150 - xfer.len = 3; 151 - xfer.tx_buf = &config->pow[0]; 152 - 153 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 154 - if (ret) 155 - goto error_ret; 156 - 157 - xfer.len = 5; 158 - xfer.tx_buf = &config->asf[0]; 159 - 160 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 161 - if (ret) 162 - goto error_ret; 163 - 164 - xfer.len = 5; 165 - xfer.tx_buf = &config->multc[0]; 166 - 167 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 168 - if (ret) 169 - goto error_ret; 170 - 171 - xfer.len = 9; 172 - xfer.tx_buf = &config->dig_rampl[0]; 173 - 174 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 175 - if (ret) 176 - goto error_ret; 177 - 178 - xfer.len = 9; 179 - xfer.tx_buf = &config->dig_ramps[0]; 180 - 181 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 182 - if (ret) 183 - goto error_ret; 184 - 185 - xfer.len = 5; 186 - xfer.tx_buf = &config->dig_rampr[0]; 187 - 188 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 189 - if (ret) 190 - goto error_ret; 191 - 192 - xfer.len = 9; 193 - xfer.tx_buf = &config->sin_tonep0[0]; 194 - 195 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 196 - if (ret) 197 - goto error_ret; 198 - 199 - xfer.len = 9; 200 - xfer.tx_buf = &config->sin_tonep1[0]; 201 - 202 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 203 - if (ret) 204 - goto error_ret; 205 - 206 - xfer.len = 9; 207 - xfer.tx_buf = &config->sin_tonep2[0]; 208 - 209 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 210 - if (ret) 211 - goto error_ret; 212 - xfer.len = 9; 213 - xfer.tx_buf = &config->sin_tonep3[0]; 214 - 215 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 216 - if (ret) 217 - goto error_ret; 218 - 219 - xfer.len = 9; 220 - xfer.tx_buf = &config->sin_tonep4[0]; 221 - 222 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 223 - if (ret) 224 - goto error_ret; 225 - 226 - xfer.len = 9; 227 - xfer.tx_buf = &config->sin_tonep5[0]; 228 - 229 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 230 - if (ret) 231 - goto error_ret; 232 - 233 - xfer.len = 9; 234 - xfer.tx_buf = &config->sin_tonep6[0]; 235 - 236 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 237 - if (ret) 238 - goto error_ret; 239 - 240 - xfer.len = 9; 241 - xfer.tx_buf = &config->sin_tonep7[0]; 242 - 243 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 244 - if (ret) 245 - goto error_ret; 246 - error_ret: 247 - mutex_unlock(&st->lock); 248 - 249 - return ret ? ret : len; 250 - } 251 - 252 - static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad9910_set_parameter, 0); 253 - 254 - static void ad9910_init(struct ad9910_state *st) 255 - { 256 - struct spi_transfer xfer; 257 - int ret; 258 - u8 cfr[5]; 259 - 260 - cfr[0] = CFR1; 261 - cfr[1] = 0; 262 - cfr[2] = MANUAL_OSK | INVSIC | DDS_SINEOP; 263 - cfr[3] = AUTO_OSK | OSKEN | ACLR_PHA | ACLR_DIG | LOAD_LRR; 264 - cfr[4] = 0; 265 - 266 - mutex_lock(&st->lock); 267 - 268 - xfer.len = 5; 269 - xfer.tx_buf = &cfr; 270 - 271 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 272 - if (ret) 273 - goto error_ret; 274 - 275 - cfr[0] = CFR2; 276 - cfr[1] = ENA_AMP; 277 - cfr[2] = READ_FTW | DIGR_ENA | ITER_IOUPD; 278 - cfr[3] = TX_ENA | PDCLK_INV | PDCLK_ENB; 279 - cfr[4] = PARA_ENA; 280 - 281 - xfer.len = 5; 282 - xfer.tx_buf = &cfr; 283 - 284 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 285 - if (ret) 286 - goto error_ret; 287 - 288 - cfr[0] = CFR3; 289 - cfr[1] = PLL_ENA; 290 - cfr[2] = 0; 291 - cfr[3] = REFCLK_RST | REFCLK_BYP; 292 - cfr[4] = 0; 293 - 294 - xfer.len = 5; 295 - xfer.tx_buf = &cfr; 296 - 297 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 298 - if (ret) 299 - goto error_ret; 300 - 301 - error_ret: 302 - mutex_unlock(&st->lock); 303 - 304 - 305 - 306 - } 307 - 308 - static struct attribute *ad9910_attributes[] = { 309 - &iio_dev_attr_dds.dev_attr.attr, 310 - NULL, 311 - }; 312 - 313 - static const struct attribute_group ad9910_attribute_group = { 314 - .attrs = ad9910_attributes, 315 - }; 316 - 317 - static const struct iio_info ad9910_info = { 318 - .attrs = &ad9910_attribute_group, 319 - .driver_module = THIS_MODULE, 320 - }; 321 - 322 - static int ad9910_probe(struct spi_device *spi) 323 - { 324 - struct ad9910_state *st; 325 - struct iio_dev *idev; 326 - int ret = 0; 327 - 328 - idev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 329 - if (!idev) 330 - return -ENOMEM; 331 - spi_set_drvdata(spi, idev); 332 - st = iio_priv(idev); 333 - mutex_init(&st->lock); 334 - st->sdev = spi; 335 - 336 - idev->dev.parent = &spi->dev; 337 - idev->info = &ad9910_info; 338 - idev->modes = INDIO_DIRECT_MODE; 339 - 340 - ret = iio_device_register(idev); 341 - if (ret) 342 - return ret; 343 - spi->max_speed_hz = 2000000; 344 - spi->mode = SPI_MODE_3; 345 - spi->bits_per_word = 8; 346 - spi_setup(spi); 347 - ad9910_init(st); 348 - return 0; 349 - } 350 - 351 - static int ad9910_remove(struct spi_device *spi) 352 - { 353 - iio_device_unregister(spi_get_drvdata(spi)); 354 - 355 - return 0; 356 - } 357 - 358 - static struct spi_driver ad9910_driver = { 359 - .driver = { 360 - .name = DRV_NAME, 361 - .owner = THIS_MODULE, 362 - }, 363 - .probe = ad9910_probe, 364 - .remove = ad9910_remove, 365 - }; 366 - module_spi_driver(ad9910_driver); 367 - 368 - MODULE_AUTHOR("Cliff Cai"); 369 - MODULE_DESCRIPTION("Analog Devices ad9910 driver"); 370 - MODULE_LICENSE("GPL v2"); 371 - MODULE_ALIAS("spi:" DRV_NAME);
-201
drivers/staging/iio/frequency/ad9951.c
··· 1 - /* 2 - * Driver for ADI Direct Digital Synthesis ad9951 3 - * 4 - * Copyright (c) 2010 Analog Devices Inc. 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License version 2 as 8 - * published by the Free Software Foundation. 9 - * 10 - */ 11 - #include <linux/types.h> 12 - #include <linux/mutex.h> 13 - #include <linux/device.h> 14 - #include <linux/spi/spi.h> 15 - #include <linux/slab.h> 16 - #include <linux/sysfs.h> 17 - #include <linux/module.h> 18 - 19 - #include <linux/iio/iio.h> 20 - #include <linux/iio/sysfs.h> 21 - 22 - #define DRV_NAME "ad9951" 23 - 24 - #define CFR1 0x0 25 - #define CFR2 0x1 26 - 27 - #define AUTO_OSK (1) 28 - #define OSKEN (1 << 1) 29 - #define LOAD_ARR (1 << 2) 30 - 31 - #define AUTO_SYNC (1 << 7) 32 - 33 - #define LSB_FST (1) 34 - #define SDIO_IPT (1 << 1) 35 - #define CLR_PHA (1 << 2) 36 - #define SINE_OPT (1 << 4) 37 - #define ACLR_PHA (1 << 5) 38 - 39 - #define VCO_RANGE (1 << 2) 40 - 41 - #define CRS_OPT (1 << 1) 42 - #define HMANU_SYNC (1 << 2) 43 - #define HSPD_SYNC (1 << 3) 44 - 45 - /* Register format: 1 byte addr + value */ 46 - struct ad9951_config { 47 - u8 asf[3]; 48 - u8 arr[2]; 49 - u8 ftw0[5]; 50 - u8 ftw1[3]; 51 - }; 52 - 53 - struct ad9951_state { 54 - struct mutex lock; 55 - struct spi_device *sdev; 56 - }; 57 - 58 - static ssize_t ad9951_set_parameter(struct device *dev, 59 - struct device_attribute *attr, 60 - const char *buf, 61 - size_t len) 62 - { 63 - struct spi_transfer xfer; 64 - int ret; 65 - struct ad9951_config *config = (struct ad9951_config *)buf; 66 - struct iio_dev *idev = dev_to_iio_dev(dev); 67 - struct ad9951_state *st = iio_priv(idev); 68 - 69 - xfer.len = 3; 70 - xfer.tx_buf = &config->asf[0]; 71 - mutex_lock(&st->lock); 72 - 73 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 74 - if (ret) 75 - goto error_ret; 76 - 77 - xfer.len = 2; 78 - xfer.tx_buf = &config->arr[0]; 79 - 80 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 81 - if (ret) 82 - goto error_ret; 83 - 84 - xfer.len = 5; 85 - xfer.tx_buf = &config->ftw0[0]; 86 - 87 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 88 - if (ret) 89 - goto error_ret; 90 - 91 - xfer.len = 3; 92 - xfer.tx_buf = &config->ftw1[0]; 93 - 94 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 95 - if (ret) 96 - goto error_ret; 97 - error_ret: 98 - mutex_unlock(&st->lock); 99 - 100 - return ret ? ret : len; 101 - } 102 - 103 - static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad9951_set_parameter, 0); 104 - 105 - static void ad9951_init(struct ad9951_state *st) 106 - { 107 - struct spi_transfer xfer; 108 - int ret; 109 - u8 cfr[5]; 110 - 111 - cfr[0] = CFR1; 112 - cfr[1] = 0; 113 - cfr[2] = LSB_FST | CLR_PHA | SINE_OPT | ACLR_PHA; 114 - cfr[3] = AUTO_OSK | OSKEN | LOAD_ARR; 115 - cfr[4] = 0; 116 - 117 - mutex_lock(&st->lock); 118 - 119 - xfer.len = 5; 120 - xfer.tx_buf = &cfr; 121 - 122 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 123 - if (ret) 124 - goto error_ret; 125 - 126 - cfr[0] = CFR2; 127 - cfr[1] = VCO_RANGE; 128 - cfr[2] = HSPD_SYNC; 129 - cfr[3] = 0; 130 - 131 - xfer.len = 4; 132 - xfer.tx_buf = &cfr; 133 - 134 - ret = spi_sync_transfer(st->sdev, &xfer, 1); 135 - if (ret) 136 - goto error_ret; 137 - 138 - error_ret: 139 - mutex_unlock(&st->lock); 140 - 141 - 142 - 143 - } 144 - 145 - static struct attribute *ad9951_attributes[] = { 146 - &iio_dev_attr_dds.dev_attr.attr, 147 - NULL, 148 - }; 149 - 150 - static const struct attribute_group ad9951_attribute_group = { 151 - .attrs = ad9951_attributes, 152 - }; 153 - 154 - static const struct iio_info ad9951_info = { 155 - .attrs = &ad9951_attribute_group, 156 - .driver_module = THIS_MODULE, 157 - }; 158 - 159 - static int ad9951_probe(struct spi_device *spi) 160 - { 161 - struct ad9951_state *st; 162 - struct iio_dev *idev; 163 - int ret = 0; 164 - 165 - idev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 166 - if (!idev) 167 - return -ENOMEM; 168 - spi_set_drvdata(spi, idev); 169 - st = iio_priv(idev); 170 - mutex_init(&st->lock); 171 - st->sdev = spi; 172 - 173 - idev->dev.parent = &spi->dev; 174 - 175 - idev->info = &ad9951_info; 176 - idev->modes = INDIO_DIRECT_MODE; 177 - 178 - ret = devm_iio_device_register(&spi->dev, idev); 179 - if (ret) 180 - return ret; 181 - spi->max_speed_hz = 2000000; 182 - spi->mode = SPI_MODE_3; 183 - spi->bits_per_word = 8; 184 - spi_setup(spi); 185 - ad9951_init(st); 186 - return 0; 187 - } 188 - 189 - static struct spi_driver ad9951_driver = { 190 - .driver = { 191 - .name = DRV_NAME, 192 - .owner = THIS_MODULE, 193 - }, 194 - .probe = ad9951_probe, 195 - }; 196 - module_spi_driver(ad9951_driver); 197 - 198 - MODULE_AUTHOR("Cliff Cai"); 199 - MODULE_DESCRIPTION("Analog Devices ad9951 driver"); 200 - MODULE_LICENSE("GPL v2"); 201 - MODULE_ALIAS("spi:" DRV_NAME);