Title: [8704] trunk/drivers/staging/iio/accel: adis16220: update according to test and add capture node
Revision
8704
Author
bhsong
Date
2010-05-11 05:41:20 -0400 (Tue, 11 May 2010)

Log Message

adis16220: update according to test and add capture node

Modified Paths


Diff

Modified: trunk/drivers/staging/iio/accel/adis16220.h (8703 => 8704)


--- trunk/drivers/staging/iio/accel/adis16220.h	2010-05-11 09:16:46 UTC (rev 8703)
+++ trunk/drivers/staging/iio/accel/adis16220.h	2010-05-11 09:41:20 UTC (rev 8704)
@@ -75,7 +75,6 @@
 #define ADIS16220_MAX_TX 24
 #define ADIS16220_MAX_RX 24
 
-#define ADIS16220_SPI_SLOW	(u32)(300 * 1000)
 #define ADIS16220_SPI_BURST	(u32)(1000 * 1000)
 #define ADIS16220_SPI_FAST	(u32)(2000 * 1000)
 
@@ -104,23 +103,9 @@
 	struct mutex			buf_lock;
 };
 
-int adis16220_spi_write_reg_8(struct device *dev,
-			      u8 reg_address,
-			      u8 val);
 
-int adis16220_spi_read_burst(struct device *dev, u8 *rx);
-
-int adis16220_spi_read_sequence(struct device *dev,
-				      u8 *tx, u8 *rx, int num);
-
 int adis16220_set_irq(struct device *dev, bool enable);
 
-int adis16220_reset(struct device *dev);
-
-int adis16220_stop_device(struct device *dev);
-
-int adis16220_check_status(struct device *dev);
-
 #ifdef CONFIG_IIO_RING_BUFFER
 /* At the moment triggers are only used for ring buffer
  * filling. This may change!

Modified: trunk/drivers/staging/iio/accel/adis16220_core.c (8703 => 8704)


--- trunk/drivers/staging/iio/accel/adis16220_core.c	2010-05-11 09:16:46 UTC (rev 8703)
+++ trunk/drivers/staging/iio/accel/adis16220_core.c	2010-05-11 09:41:20 UTC (rev 8704)
@@ -28,6 +28,8 @@
 
 #define DRIVER_NAME		"adis16220"
 
+static int adis16220_check_status(struct device *dev);
+
 /**
  * adis16220_spi_write_reg_8() - write single byte to a register
  * @dev: device associated with child of actual device (iio_dev or iio_trig)
@@ -73,11 +75,13 @@
 			.bits_per_word = 8,
 			.len = 2,
 			.cs_change = 1,
+			.delay_usecs = 25,
 		}, {
 			.tx_buf = st->tx + 2,
 			.bits_per_word = 8,
 			.len = 2,
 			.cs_change = 1,
+			.delay_usecs = 25,
 		},
 	};
 
@@ -117,11 +121,13 @@
 			.bits_per_word = 8,
 			.len = 2,
 			.cs_change = 1,
+			.delay_usecs = 25,
 		}, {
 			.rx_buf = st->rx,
 			.bits_per_word = 8,
 			.len = 2,
 			.cs_change = 1,
+			.delay_usecs = 25,
 		},
 	};
 
@@ -277,6 +283,30 @@
 	return ret ? ret : len;
 }
 
+static int adis16220_capture(struct device *dev)
+{
+	int ret;
+	ret = adis16220_spi_write_reg_16(dev,
+			ADIS16220_GLOB_CMD,
+			0xBF08); /* initiates a manual data capture */
+	if (ret)
+		dev_err(dev, "problem beginning capture");
+
+	return ret;
+}
+
+static int adis16220_reset(struct device *dev)
+{
+	int ret;
+	ret = adis16220_spi_write_reg_8(dev,
+			ADIS16220_GLOB_CMD,
+			ADIS16220_GLOB_CMD_SW_RESET);
+	if (ret)
+		dev_err(dev, "problem resetting device");
+
+	return ret;
+}
+
 static ssize_t adis16220_write_reset(struct device *dev,
 		struct device_attribute *attr,
 		const char *buf, size_t len)
@@ -287,11 +317,26 @@
 	case '1':
 	case 'y':
 	case 'Y':
-		return adis16220_reset(dev);
+		return adis16220_reset(dev) == 0 ? len : -EIO;
 	}
 	return -1;
 }
 
+static ssize_t adis16220_write_capture(struct device *dev,
+		struct device_attribute *attr,
+		const char *buf, size_t len)
+{
+	if (len < 1)
+		return -1;
+	switch (buf[0]) {
+	case '1':
+	case 'y':
+	case 'Y':
+		return adis16220_capture(dev) == 0 ? len : -EIO;
+	}
+	return -1;
+}
+
 int adis16220_set_irq(struct device *dev, bool enable)
 {
 	int ret;
@@ -314,21 +359,9 @@
 	return ret;
 }
 
-int adis16220_reset(struct device *dev)
+static int adis16220_self_test(struct device *dev)
 {
 	int ret;
-	ret = adis16220_spi_write_reg_8(dev,
-			ADIS16220_GLOB_CMD,
-			ADIS16220_GLOB_CMD_SW_RESET);
-	if (ret)
-		dev_err(dev, "problem resetting device");
-
-	return ret;
-}
-
-int adis16220_self_test(struct device *dev)
-{
-	int ret;
 	ret = adis16220_spi_write_reg_16(dev,
 			ADIS16220_MSC_CTRL,
 			ADIS16220_MSC_CTRL_SELF_TEST_EN);
@@ -343,7 +376,7 @@
 	return ret;
 }
 
-int adis16220_check_status(struct device *dev)
+static int adis16220_check_status(struct device *dev)
 {
 	u16 status;
 	int ret;
@@ -354,21 +387,8 @@
 		dev_err(dev, "Reading status failed\n");
 		goto error_ret;
 	}
-	ret = status;
-	if (status & ADIS16220_DIAG_STAT_ALM_MAG2)
-		dev_err(dev, "AIN2 sample > ALM_MAG2\n");
-	if (status & ADIS16220_DIAG_STAT_ALM_MAG1)
-		dev_err(dev, "AIN1 sample > ALM_MAG1\n");
-	if (status & ADIS16220_DIAG_STAT_ALM_MAGA)
-		dev_err(dev, "Acceleration sample > ALM_MAGA\n");
-	if (status & ADIS16220_DIAG_STAT_ALM_MAGS)
-		dev_err(dev, "Error condition programmed into ALM_MAGS[11:0]\n");
-	if (status & ADIS16220_DIAG_STAT_PEAK_AIN2)
-		dev_err(dev, "|Peak value in AIN2 data capture| > ALM_MAG2\n");
-	if (status & ADIS16220_DIAG_STAT_PEAK_AIN1)
-		dev_err(dev, "|Peak value in AIN1 data capture| > ALM_MAG1\n");
-	if (status & ADIS16220_DIAG_STAT_PEAK_ACCEL)
-		dev_err(dev, "|Peak value in acceleration data capture| > ALM_MAGA\n");
+	ret = status & 0x7F;
+
 	if (status & ADIS16220_DIAG_STAT_VIOLATION)
 		dev_err(dev, "Capture period violation/interruption\n");
 	if (status & ADIS16220_DIAG_STAT_SPI_FAIL)
@@ -397,6 +417,11 @@
 	}
 
 	/* Do self test */
+	ret = adis16220_self_test(dev);
+	if (ret) {
+		dev_err(dev, "self test failure");
+		goto err_ret;
+	}
 
 	/* Read status register to check the result */
 	ret = adis16220_check_status(dev);
@@ -438,6 +463,19 @@
 
 static IIO_DEV_ATTR_RESET(adis16220_write_reset);
 
+#define IIO_DEV_ATTR_CAPTURE(_store)			\
+	IIO_DEVICE_ATTR(capture, S_IWUGO, NULL, _store, 0)
+
+static IIO_DEV_ATTR_CAPTURE(adis16220_write_capture);
+
+#define IIO_DEV_ATTR_CAPTURE_COUNT(_mode, _show, _store, _addr)	\
+	IIO_DEVICE_ATTR(capture_count, _mode, _show, _store, _addr)
+
+static IIO_DEV_ATTR_CAPTURE_COUNT(S_IWUSR | S_IRUGO,
+		adis16220_read_16bit,
+		adis16220_write_16bit,
+		ADIS16220_CAPT_PNTR);
+
 static IIO_CONST_ATTR_AVAIL_SAMP_FREQ("100200");
 
 static IIO_CONST_ATTR(name, "adis16220");
@@ -463,6 +501,8 @@
 	&iio_const_attr_temp_scale.dev_attr.attr,
 	&iio_const_attr_available_sampling_frequency.dev_attr.attr,
 	&iio_dev_attr_reset.dev_attr.attr,
+	&iio_dev_attr_capture.dev_attr.attr,
+	&iio_dev_attr_capture_count.dev_attr.attr,
 	&iio_const_attr_name.dev_attr.attr,
 	NULL
 };
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits

Reply via email to