Title: [8814] trunk/drivers/staging/iio/accel: staging:iio: merge the ADIS16220 driver as was added to mainline
Revision
8814
Author
vapier
Date
2010-05-23 00:27:18 -0400 (Sun, 23 May 2010)

Log Message

staging:iio: merge the ADIS16220 driver as was added to mainline

Modified Paths


Diff

Modified: trunk/drivers/staging/iio/accel/accel.h (8813 => 8814)


--- trunk/drivers/staging/iio/accel/accel.h	2010-05-23 04:25:16 UTC (rev 8813)
+++ trunk/drivers/staging/iio/accel/accel.h	2010-05-23 04:27:18 UTC (rev 8814)
@@ -24,7 +24,7 @@
 	IIO_DEVICE_ATTR(accel_z_gain, _mode, _show, _store, _addr)
 
 #define IIO_DEV_ATTR_ACCEL(_show, _addr)			\
-	IIO_DEVICE_ATTR(accel, S_IRUGO, _show, NULL, _addr)
+	IIO_DEVICE_ATTR(accel_raw, S_IRUGO, _show, NULL, _addr)
 
 #define IIO_DEV_ATTR_ACCEL_X(_show, _addr)			\
 	IIO_DEVICE_ATTR(accel_x_raw, S_IRUGO, _show, NULL, _addr)

Modified: trunk/drivers/staging/iio/accel/adis16220.h (8813 => 8814)


--- trunk/drivers/staging/iio/accel/adis16220.h	2010-05-23 04:25:16 UTC (rev 8813)
+++ trunk/drivers/staging/iio/accel/adis16220.h	2010-05-23 04:27:18 UTC (rev 8814)
@@ -6,37 +6,68 @@
 #define ADIS16220_READ_REG(a)    a
 #define ADIS16220_WRITE_REG(a) ((a) | 0x80)
 
-#define ADIS16220_FLASH_CNT     0x00 /* Flash memory write count */
-#define ADIS16220_ACCL_NULL     0x02 /* Control, acceleration offset adjustment control */
-#define ADIS16220_AIN1_NULL     0x04 /* Control, AIN1 offset adjustment control */
-#define ADIS16220_AIN2_NULL     0x06 /* Control, AIN2 offset adjustment control */
-#define ADIS16220_CAPT_SUPPLY   0x0A /* Output, power supply during capture */
-#define ADIS16220_CAPT_TEMP     0x0C /* Output, temperature during capture */
-#define ADIS16220_CAPT_PEAKA    0x0E /* Output, peak acceleration during capture */
-#define ADIS16220_CAPT_PEAK1    0x10 /* Output, peak AIN1 level during capture */
-#define ADIS16220_CAPT_PEAK2    0x12 /* Output, peak AIN2 level during capture */
-#define ADIS16220_CAPT_BUFA     0x14 /* Output, capture buffer for acceleration */
-#define ADIS16220_CAPT_BUF1     0x16 /* Output, capture buffer for AIN1 */
-#define ADIS16220_CAPT_BUF2     0x18 /* Output, capture buffer for AIN2 */
-#define ADIS16220_CAPT_PNTR     0x1A /* Control, capture buffer address pointer */
-#define ADIS16220_CAPT_CTRL     0x1C /* Control, capture control register */
-#define ADIS16220_CAPT_PRD      0x1E /* Control, capture period (automatic mode) */
-#define ADIS16220_ALM_MAGA      0x20 /* Control, Alarm A, acceleration peak threshold */
-#define ADIS16220_ALM_MAG1      0x22 /* Control, Alarm 1, AIN1 peak threshold */
-#define ADIS16220_ALM_MAG2      0x24 /* Control, Alarm 2, AIN2 peak threshold */
-#define ADIS16220_ALM_MAGS      0x26 /* Control, Alarm S, peak threshold */
-#define ADIS16220_ALM_CTRL      0x28 /* Control, alarm configuration register */
-#define ADIS16220_GPIO_CTRL     0x32 /* Control, general I/O configuration */
-#define ADIS16220_MSC_CTRL      0x34 /* Control, self-test control, AIN configuration */
-#define ADIS16220_DIO_CTRL      0x36 /* Control, digital I/O configuration */
-#define ADIS16220_AVG_CNT       0x38 /* Control, filter configuration */
-#define ADIS16220_DIAG_STAT     0x3C /* Status, system status */
-#define ADIS16220_GLOB_CMD      0x3E /* Control, system commands */
-#define ADIS16220_ST_DELTA      0x40 /* Status, self-test response */_
-#define ADIS16220_LOT_ID1       0x52 /* Lot Identification Code 1 */
-#define ADIS16220_LOT_ID2       0x54 /* Lot Identification Code 2 */
-#define ADIS16220_PROD_ID       0x56 /* Product identifier; convert to decimal = 16220 */
-#define ADIS16220_SERIAL_NUM    0x58 /* Serial number */
+/* Flash memory write count */
+#define ADIS16220_FLASH_CNT     0x00
+/* Control, acceleration offset adjustment control */
+#define ADIS16220_ACCL_NULL     0x02
+/* Control, AIN1 offset adjustment control */
+#define ADIS16220_AIN1_NULL     0x04
+/* Control, AIN2 offset adjustment control */
+#define ADIS16220_AIN2_NULL     0x06
+/* Output, power supply during capture */
+#define ADIS16220_CAPT_SUPPLY   0x0A
+/* Output, temperature during capture */
+#define ADIS16220_CAPT_TEMP     0x0C
+/* Output, peak acceleration during capture */
+#define ADIS16220_CAPT_PEAKA    0x0E
+/* Output, peak AIN1 level during capture */
+#define ADIS16220_CAPT_PEAK1    0x10
+/* Output, peak AIN2 level during capture */
+#define ADIS16220_CAPT_PEAK2    0x12
+/* Output, capture buffer for acceleration */
+#define ADIS16220_CAPT_BUFA     0x14
+/* Output, capture buffer for AIN1 */
+#define ADIS16220_CAPT_BUF1     0x16
+/* Output, capture buffer for AIN2 */
+#define ADIS16220_CAPT_BUF2     0x18
+/* Control, capture buffer address pointer */
+#define ADIS16220_CAPT_PNTR     0x1A
+/* Control, capture control register */
+#define ADIS16220_CAPT_CTRL     0x1C
+/* Control, capture period (automatic mode) */
+#define ADIS16220_CAPT_PRD      0x1E
+/* Control, Alarm A, acceleration peak threshold */
+#define ADIS16220_ALM_MAGA      0x20
+/* Control, Alarm 1, AIN1 peak threshold */
+#define ADIS16220_ALM_MAG1      0x22
+/* Control, Alarm 2, AIN2 peak threshold */
+#define ADIS16220_ALM_MAG2      0x24
+/* Control, Alarm S, peak threshold */
+#define ADIS16220_ALM_MAGS      0x26
+/* Control, alarm configuration register */
+#define ADIS16220_ALM_CTRL      0x28
+/* Control, general I/O configuration */
+#define ADIS16220_GPIO_CTRL     0x32
+/* Control, self-test control, AIN configuration */
+#define ADIS16220_MSC_CTRL      0x34
+/* Control, digital I/O configuration */
+#define ADIS16220_DIO_CTRL      0x36
+/* Control, filter configuration */
+#define ADIS16220_AVG_CNT       0x38
+/* Status, system status */
+#define ADIS16220_DIAG_STAT     0x3C
+/* Control, system commands */
+#define ADIS16220_GLOB_CMD      0x3E
+/* Status, self-test response */
+#define ADIS16220_ST_DELTA      0x40
+/* Lot Identification Code 1 */
+#define ADIS16220_LOT_ID1       0x52
+/* Lot Identification Code 2 */
+#define ADIS16220_LOT_ID2       0x54
+/* Product identifier; convert to decimal = 16220 */
+#define ADIS16220_PROD_ID       0x56
+/* Serial number */
+#define ADIS16220_SERIAL_NUM    0x58
 
 #define ADIS16220_CAPTURE_SIZE  2048
 
@@ -52,22 +83,34 @@
 #define ADIS16220_MSC_CTRL_DIO1_ACT_HIGH     (1<<0)
 
 /* DIAG_STAT */
-#define ADIS16220_DIAG_STAT_ALM_MAG2    (1<<14) /* AIN2 sample > ALM_MAG2 */
-#define ADIS16220_DIAG_STAT_ALM_MAG1    (1<<13) /* AIN1 sample > ALM_MAG1 */
-#define ADIS16220_DIAG_STAT_ALM_MAGA    (1<<12) /* Acceleration sample > ALM_MAGA */
-#define ADIS16220_DIAG_STAT_ALM_MAGS    (1<<11) /* Error condition programmed into ALM_MAGS[11:0] and
-						 ALM_CTRL[5:4] is true */
-#define ADIS16220_DIAG_STAT_PEAK_AIN2   (1<<10) /* |Peak value in AIN2 data capture| > ALM_MAG2 */
-#define ADIS16220_DIAG_STAT_PEAK_AIN1   (1<<9)  /* |Peak value in AIN1 data capture| > ALM_MAG1 */
-#define ADIS16220_DIAG_STAT_PEAK_ACCEL  (1<<8)  /* |Peak value in acceleration data capture| > ALM_MAGA */
-#define ADIS16220_DIAG_STAT_DATA_RDY    (1<<7)  /* Data ready, capture complete */
+/* AIN2 sample > ALM_MAG2 */
+#define ADIS16220_DIAG_STAT_ALM_MAG2    (1<<14)
+/* AIN1 sample > ALM_MAG1 */
+#define ADIS16220_DIAG_STAT_ALM_MAG1    (1<<13)
+/* Acceleration sample > ALM_MAGA */
+#define ADIS16220_DIAG_STAT_ALM_MAGA    (1<<12)
+/* Error condition programmed into ALM_MAGS[11:0] and ALM_CTRL[5:4] is true */
+#define ADIS16220_DIAG_STAT_ALM_MAGS    (1<<11)
+/* |Peak value in AIN2 data capture| > ALM_MAG2 */
+#define ADIS16220_DIAG_STAT_PEAK_AIN2   (1<<10)
+/* |Peak value in AIN1 data capture| > ALM_MAG1 */
+#define ADIS16220_DIAG_STAT_PEAK_AIN1   (1<<9)
+/* |Peak value in acceleration data capture| > ALM_MAGA */
+#define ADIS16220_DIAG_STAT_PEAK_ACCEL  (1<<8)
+/* Data ready, capture complete */
+#define ADIS16220_DIAG_STAT_DATA_RDY    (1<<7)
 #define ADIS16220_DIAG_STAT_FLASH_CHK	(1<<6)
 #define ADIS16220_DIAG_STAT_SELF_TEST	(1<<5)
-#define ADIS16220_DIAG_STAT_VIOLATION	(1<<4) /* Capture period violation/interruption */
-#define ADIS16220_DIAG_STAT_SPI_FAIL	(1<<3) /* SPI communications failure */
-#define ADIS16220_DIAG_STAT_FLASH_UPT	(1<<2) /* Flash update failure */
-#define ADIS16220_DIAG_STAT_POWER_HIGH	(1<<1) /* Power supply above 3.625 V */
-#define ADIS16220_DIAG_STAT_POWER_LOW	(1<<0) /* Power supply below 3.15 V */
+/* Capture period violation/interruption */
+#define ADIS16220_DIAG_STAT_VIOLATION	(1<<4)
+/* SPI communications failure */
+#define ADIS16220_DIAG_STAT_SPI_FAIL	(1<<3)
+/* Flash update failure */
+#define ADIS16220_DIAG_STAT_FLASH_UPT	(1<<2)
+/* Power supply above 3.625 V */
+#define ADIS16220_DIAG_STAT_POWER_HIGH	(1<<1)
+/* Power supply below 3.15 V */
+#define ADIS16220_DIAG_STAT_POWER_LOW	(1<<0)
 
 /* GLOB_CMD */
 #define ADIS16220_GLOB_CMD_SW_RESET	(1<<7)

Modified: trunk/drivers/staging/iio/accel/adis16220_core.c (8813 => 8814)


--- trunk/drivers/staging/iio/accel/adis16220_core.c	2010-05-23 04:25:16 UTC (rev 8813)
+++ trunk/drivers/staging/iio/accel/adis16220_core.c	2010-05-23 04:27:18 UTC (rev 8814)
@@ -21,7 +21,6 @@
 #include "../iio.h"
 #include "../sysfs.h"
 #include "accel.h"
-#include "../imu/volt.h"
 #include "../adc/adc.h"
 
 #include "adis16220.h"
@@ -36,7 +35,7 @@
  * @reg_address: the address of the register to be written
  * @val: the value to write
  **/
-int adis16220_spi_write_reg_8(struct device *dev,
+static int adis16220_spi_write_reg_8(struct device *dev,
 		u8 reg_address,
 		u8 val)
 {
@@ -142,8 +141,9 @@
 	spi_message_add_tail(&xfers[1], &msg);
 	ret = spi_sync(st->us, &msg);
 	if (ret) {
-		dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X",
-				lower_reg_address);
+		dev_err(&st->us->dev,
+			"problem when reading 16 bit register 0x%02X",
+			lower_reg_address);
 		goto error_ret;
 	}
 	*val = (st->rx[0] << 8) | st->rx[1];
@@ -352,9 +352,28 @@
 	return ret;
 }
 
-static ssize_t adis16220_capture_buffer_read(struct adis16220_state *st, char *buf,
-			loff_t off, size_t count, int addr)
+static ssize_t adis16220_capture_buffer_read(struct adis16220_state *st,
+					char *buf,
+					loff_t off,
+					size_t count,
+					int addr)
 {
+	struct spi_message msg;
+	struct spi_transfer xfers[] = {
+		{
+			.tx_buf = st->tx,
+			.bits_per_word = 8,
+			.len = 2,
+			.cs_change = 1,
+			.delay_usecs = 25,
+		}, {
+			.tx_buf = st->tx,
+			.rx_buf = st->rx,
+			.bits_per_word = 8,
+			.cs_change = 1,
+			.delay_usecs = 25,
+		},
+	};
 	int ret;
 	int i;
 
@@ -368,69 +387,99 @@
 		count = ADIS16220_CAPTURE_SIZE - off;
 
 	/* write the begin position of capture buffer */
-	ret = adis16220_spi_write_reg_16(&st->indio_dev->dev, ADIS16220_CAPT_PNTR, off > 1);
+	ret = adis16220_spi_write_reg_16(&st->indio_dev->dev,
+					ADIS16220_CAPT_PNTR,
+					off > 1);
 	if (ret)
 		return -EIO;
 
 	/* read count/2 values from capture buffer */
+	mutex_lock(&st->buf_lock);
+
 	for (i = 0; i < count; i += 2) {
-		ret = adis16220_spi_read_reg_16(&st->indio_dev->dev, addr, (u16 *)(buf + i));
-		if (ret)
-			return -EIO;
+		st->tx[i] = ADIS16220_READ_REG(addr);
+		st->tx[i + 1] = 0;
 	}
+	xfers[1].len = count;
 
+	spi_message_init(&msg);
+	spi_message_add_tail(&xfers[0], &msg);
+	spi_message_add_tail(&xfers[1], &msg);
+	ret = spi_sync(st->us, &msg);
+	if (ret) {
+
+		mutex_unlock(&st->buf_lock);
+		return -EIO;
+	}
+
+	memcpy(buf, st->rx, count);
+
+	mutex_unlock(&st->buf_lock);
 	return count;
 }
 
-static ssize_t adis16220_accel_bin_read(struct kobject *kobj, struct bin_attribute *attr,
-		char *buf, loff_t off, size_t count)
+static ssize_t adis16220_accel_bin_read(struct kobject *kobj,
+					struct bin_attribute *attr,
+					char *buf,
+					loff_t off,
+					size_t count)
 {
 	struct device *dev = container_of(kobj, struct device, kobj);
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct adis16220_state *st = iio_dev_get_devdata(indio_dev);
 
-	return adis16220_capture_buffer_read(st, buf, off, count, ADIS16220_CAPT_BUFA);
+	return adis16220_capture_buffer_read(st, buf,
+					off, count,
+					ADIS16220_CAPT_BUFA);
 }
 
-static ssize_t adis16220_adc1_bin_read(struct kobject *kobj, struct bin_attribute *attr,
-		char *buf, loff_t off, size_t count)
+static ssize_t adis16220_adc1_bin_read(struct kobject *kobj,
+				struct bin_attribute *attr,
+				char *buf, loff_t off,
+				size_t count)
 {
 	struct device *dev = container_of(kobj, struct device, kobj);
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct adis16220_state *st = iio_dev_get_devdata(indio_dev);
 
-	return adis16220_capture_buffer_read(st, buf, off, count, ADIS16220_CAPT_BUF1);
+	return adis16220_capture_buffer_read(st, buf,
+					off, count,
+					ADIS16220_CAPT_BUF1);
 }
 
-static ssize_t adis16220_adc2_bin_read(struct kobject *kobj, struct bin_attribute *attr,
-		char *buf, loff_t off, size_t count)
+static ssize_t adis16220_adc2_bin_read(struct kobject *kobj,
+				struct bin_attribute *attr,
+				char *buf, loff_t off,
+				size_t count)
 {
 	struct device *dev = container_of(kobj, struct device, kobj);
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct adis16220_state *st = iio_dev_get_devdata(indio_dev);
 
-	return adis16220_capture_buffer_read(st, buf, off, count, ADIS16220_CAPT_BUF2);
+	return adis16220_capture_buffer_read(st, buf,
+					off, count,
+					ADIS16220_CAPT_BUF2);
 }
 
-static IIO_DEV_ATTR_VOLT(supply, adis16220_read_12bit_unsigned,
+static IIO_DEV_ATTR_IN_NAMED_RAW(supply, adis16220_read_12bit_unsigned,
 		ADIS16220_CAPT_SUPPLY);
-static IIO_CONST_ATTR(volt_supply_scale, "0.0012207");
-static IIO_DEV_ATTR_ACCEL(adis16220_read_16bit,
-		ADIS16220_CAPT_BUFA);
-static IIO_DEV_ATTR_ACCEL_PEAK(adis16220_read_16bit,
-		ADIS16220_CAPT_PEAKA);
+static IIO_CONST_ATTR(in_supply_scale, "0.0012207");
+static IIO_DEV_ATTR_ACCEL(adis16220_read_16bit, ADIS16220_CAPT_BUFA);
+static IIO_DEVICE_ATTR(accel_peak_raw, S_IRUGO, adis16220_read_16bit,
+		NULL, ADIS16220_CAPT_PEAKA);
 static IIO_DEV_ATTR_ACCEL_OFFSET(S_IWUSR | S_IRUGO,
 		adis16220_read_16bit,
 		adis16220_write_16bit,
 		ADIS16220_ACCL_NULL);
-static IIO_DEV_ATTR_TEMP(adis16220_read_12bit_unsigned);
+static IIO_DEV_ATTR_TEMP_RAW(adis16220_read_12bit_unsigned);
 static IIO_CONST_ATTR(temp_offset, "25");
 static IIO_CONST_ATTR(temp_scale, "-0.47");
 
-static IIO_DEV_ATTR_ADC(1, adis16220_read_16bit, ADIS16220_CAPT_BUF1);
-static IIO_DEV_ATTR_ADC(2, adis16220_read_16bit, ADIS16220_CAPT_BUF2);
+static IIO_DEV_ATTR_IN_RAW(0, adis16220_read_16bit, ADIS16220_CAPT_BUF1);
+static IIO_DEV_ATTR_IN_RAW(1, adis16220_read_16bit, ADIS16220_CAPT_BUF2);
 
-static IIO_DEV_ATTR_RESET(adis16220_write_reset);
+static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL,
+		adis16220_write_reset, 0);
 
 #define IIO_DEV_ATTR_CAPTURE(_store)			\
 	IIO_DEVICE_ATTR(capture, S_IWUGO, NULL, _store, 0)
@@ -450,14 +499,14 @@
 static IIO_CONST_ATTR(name, "adis16220");
 
 static struct attribute *adis16220_attributes[] = {
-	&iio_dev_attr_volt_supply.dev_attr.attr,
-	&iio_const_attr_volt_supply_scale.dev_attr.attr,
-	&iio_dev_attr_accel.dev_attr.attr,
+	&iio_dev_attr_in_supply_raw.dev_attr.attr,
+	&iio_const_attr_in_supply_scale.dev_attr.attr,
+	&iio_dev_attr_accel_raw.dev_attr.attr,
 	&iio_dev_attr_accel_offset.dev_attr.attr,
-	&iio_dev_attr_accel_peak.dev_attr.attr,
-	&iio_dev_attr_temp.dev_attr.attr,
-	&iio_dev_attr_adc_1.dev_attr.attr,
-	&iio_dev_attr_adc_2.dev_attr.attr,
+	&iio_dev_attr_accel_peak_raw.dev_attr.attr,
+	&iio_dev_attr_temp_raw.dev_attr.attr,
+	&iio_dev_attr_in0_raw.dev_attr.attr,
+	&iio_dev_attr_in1_raw.dev_attr.attr,
 	&iio_const_attr_temp_offset.dev_attr.attr,
 	&iio_const_attr_temp_scale.dev_attr.attr,
 	&iio_const_attr_available_sampling_frequency.dev_attr.attr,
@@ -611,5 +660,5 @@
 module_exit(adis16220_exit);
 
 MODULE_AUTHOR("Barry Song <[email protected]>");
-MODULE_DESCRIPTION("Analog Devices ADIS16220 Programmable Digital Vibration Sensor driver");
+MODULE_DESCRIPTION("Analog Devices ADIS16220 Digital Vibration Sensor");
 MODULE_LICENSE("GPL v2");
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits

Reply via email to