]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
staging: adis16255 - TODO issues resolved and typos removed
authorMatthias Brugger <mensch0815@googlemail.com>
Fri, 7 May 2010 19:39:56 +0000 (21:39 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 11 May 2010 21:46:03 +0000 (14:46 -0700)
This patch adds the adis16255 driver to the build system under the staging directory.
It solves also most issues mentioned in TODO list:
- sample rate exported to sysfs
- spi_adis16255_bringup and spi_adis16255_shutdown encapsulated
- chip selftest in spi_adis16255_bringup
- kernel messages reduced to a reasonable number
I removed the TODO file, because ther was only the reset of the gyroscope left.
This is IMOH not necessary for the actual driver.

There are also some typos in adis.c file. This patch should get rid of them as well.

Signed-off-by: Matthias Brugger <mensch0815@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/Kconfig
drivers/staging/Makefile
drivers/staging/adis16255/Kconfig
drivers/staging/adis16255/Makefile
drivers/staging/adis16255/TODO [deleted file]
drivers/staging/adis16255/adis16255.c

index e062b092073e01ae3cef3af244a1cc2da5b4cbaa..06d3b10d2a143523cc5d5745183a4910f0879d0b 100644 (file)
@@ -137,5 +137,7 @@ source "drivers/staging/cxt1e1/Kconfig"
 
 source "drivers/staging/ti-st/Kconfig"
 
+source "drivers/staging/adis16255/Kconfig"
+
 endif # !STAGING_EXCLUDE_BUILD
 endif # STAGING
index 097c158d91f7000f08fd2e73d66aa05958d7d194..5526870777c6e407089173aea805a27fae6ffe31 100644 (file)
@@ -49,3 +49,4 @@ obj-$(CONFIG_VIDEO_DT3155)    += dt3155v4l/
 obj-$(CONFIG_CRYSTALHD)                += crystalhd/
 obj-$(CONFIG_CXT1E1)           += cxt1e1/
 obj-$(CONFIG_TI_ST)            += ti-st/
+obj-$(CONFIG_ADIS16255))               += adis16255/
index 3952cf95b783eeb8c3b682a5fb4664afb9c1f105..a642be66adeac6f85089470bb8d7697c115de16b 100644 (file)
@@ -2,8 +2,10 @@ config ADIS16255
        tristate "Ananlog Devices ADIS16250/16255"
        depends on SPI && SYSFS
        ---help---
-      If you say yes here you get support for the Analog Devices
-      ADIS16250/16255 Low Power Gyroscope.
+       If you say yes here you get support for the Analog Devices
+       ADIS16250/16255 Low Power Gyroscope. The driver exposes
+       orientation and gyroscope value, as well as sample rate
+       to the sysfs.
 
-      This driver can also be built as a module. If so, the module
-      will be called adis16255.
+       This driver can also be built as a module. If so, the module
+       will be called adis16255.
index 8057372d37819efee66ffaf8a485ac874d5c5aa2..8c3908106bfad684c717ab81408e86553765b520 100644 (file)
@@ -1 +1 @@
-obj-$(CONFIG_ADIS16255) += adis1625.o
+obj-$(CONFIG_ADIS16255)                += adis16255.o
diff --git a/drivers/staging/adis16255/TODO b/drivers/staging/adis16255/TODO
deleted file mode 100644 (file)
index 31e4ac3..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-* sample rate changeable or at least readable from sysfs
-* reset gyroscope
-* encapsulate adis_init and adis_turn_off
-* AD_CHK deletion
-* chip selftest in adis_init
-* reduce kernel messages to reasonable amount
-
-Contact: Matthias Brugger <mensch0815@gmail.com>
index 8d110692a030c6c02335cd2f9f95243116ec694e..1ba11f00b2e726fa8d4d070eb9a1e0fdc535b88f 100644 (file)
  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
+/*
+ * The driver just has a bare interface to the sysfs (sample rate in Hz,
+ * orientation (x, y, z) and gyroscope data in °/sec.
+ *
+ * It should be added to iio subsystem when this has left staging.
+ *
+ */
+
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/device.h>
  * @data:      Last read data from device.
  * @irq_adis:  GPIO Number of IRQ signal
  * @irq:       irq line manage by kernel
- * @negative:  indicates if sensor is upside down (negative 1)
+ * @negative:  indicates if sensor is upside down (negative == 1)
  * @direction: indicates axis (x, y, z) the sensor is meassuring
  */
 struct spi_adis16255_data {
        struct device dev;
        struct spi_device *spi;
        s16 data;
-       int irq_adis;
        int irq;
        u8 negative;
        char direction;
@@ -81,47 +88,44 @@ static int spi_adis16255_read_data(struct spi_adis16255_data *spiadis,
                                        u8 adr,
                                        u8 *rbuf)
 {
-       struct spi_device *spi piadis->spi;
+       struct spi_device *spi = spiadis->spi;
        struct spi_message msg;
        struct spi_transfer xfer1, xfer2;
        u8 *buf, *rx;
        int ret;
 
-       buf �malloc(4, GFP_KERNEL);
-       if (buf NULL)
+       buf = kzalloc(4, GFP_KERNEL);
+       if (buf == NULL)
                return -ENOMEM;
 
-       rx zalloc(4, GFP_KERNEL);
-       if (rx NULL) {
-               ret ENOMEM;
+       rx = kzalloc(4, GFP_KERNEL);
+       if (rx == NULL) {
+               ret = -ENOMEM;
                goto err_buf;
        }
 
-       buf[0] �dr;
-       buf[1] 羵00;
-       buf[2] 羵00;
-       buf[3] 羵00;
+       buf[0] = adr;
 
        spi_message_init(&msg);
        memset(&xfer1, 0, sizeof(xfer1));
        memset(&xfer2, 0, sizeof(xfer2));
 
-       xfer1.tx_buf uf;
-       xfer1.rx_buf uf + 2;
-       xfer1.len ;
-       xfer1.delay_usecs ;
+       xfer1.tx_buf = buf;
+       xfer1.rx_buf = buf + 2;
+       xfer1.len = 2;
+       xfer1.delay_usecs = 9;
 
-       xfer2.tx_buf x + 2;
-       xfer2.rx_buf x;
-       xfer2.len ;
+       xfer2.tx_buf = rx + 2;
+       xfer2.rx_buf = rx;
+       xfer2.len = 2;
 
        spi_message_add_tail(&xfer1, &msg);
        spi_message_add_tail(&xfer2, &msg);
 
-       ret pi_sync(spi, &msg);
-       if (ret 0) {
-               rbuf[0] x[0];
-               rbuf[1] x[1];
+       ret = spi_sync(spi, &msg);
+       if (ret == 0) {
+               rbuf[0] = rx[0];
+               rbuf[1] = rx[1];
        }
 
        kfree(rx);
@@ -136,19 +140,19 @@ static int spi_adis16255_write_data(struct spi_adis16255_data *spiadis,
                                        u8 adr2,
                                        u8 *wbuf)
 {
-       struct spi_device *spi piadis->spi;
+       struct spi_device *spi = spiadis->spi;
        struct spi_message   msg;
        struct spi_transfer  xfer1, xfer2;
        u8       *buf, *rx;
        int         ret;
 
-       buf malloc(4, GFP_KERNEL);
-       if (buf NULL)
+       buf = kmalloc(4, GFP_KERNEL);
+       if (buf == NULL)
                return -ENOMEM;
 
-       rx zalloc(4, GFP_KERNEL);
-       if (rx NULL) {
-               ret ENOMEM;
+       rx = kzalloc(4, GFP_KERNEL);
+       if (rx == NULL) {
+               ret = -ENOMEM;
                goto err_buf;
        }
 
@@ -156,27 +160,27 @@ static int spi_adis16255_write_data(struct spi_adis16255_data *spiadis,
        memset(&xfer1, 0, sizeof(xfer1));
        memset(&xfer2, 0, sizeof(xfer2));
 
-       buf[0] dr1 | 0x80;
-       buf[1] wbuf;
+       buf[0] = adr1 | 0x80;
+       buf[1] = *wbuf;
 
-       buf[2] dr2 | 0x80;
-       buf[3] (wbuf + 1);
+       buf[2] = adr2 | 0x80;
+       buf[3] = *(wbuf + 1);
 
-       xfer1.tx_buf uf;
-       xfer1.rx_buf x;
-       xfer1.len ;
-       xfer1.delay_usecs ;
+       xfer1.tx_buf = buf;
+       xfer1.rx_buf = rx;
+       xfer1.len = 2;
+       xfer1.delay_usecs = 9;
 
-       xfer2.tx_buf uf+2;
-       xfer2.rx_buf x+2;
-       xfer2.len ;
+       xfer2.tx_buf = buf+2;
+       xfer2.rx_buf = rx+2;
+       xfer2.len = 2;
 
        spi_message_add_tail(&xfer1, &msg);
        spi_message_add_tail(&xfer2, &msg);
 
-       ret pi_sync(spi, &msg);
-       if (ret !)
-               dev_warn(&spi->dev, "wirte data to %#x %#x failed\n",
+       ret = spi_sync(spi, &msg);
+       if (ret != 0)
+               dev_warn(&spi->dev, "write data to %#x %#x failed\n",
                                buf[0], buf[2]);
 
        kfree(rx);
@@ -189,29 +193,31 @@ err_buf:
 
 static irqreturn_t adis_irq_thread(int irq, void *dev_id)
 {
-       struct spi_adis16255_data *spiadis ev_id;
+       struct spi_adis16255_data *spiadis = dev_id;
        int status;
-       u16 value;
-
-       status �spi_adis16255_read_data(spiadis, ADIS_GYRO_OUT, (u8 *)&value);
-       if (status �0) {
-               /* perform on new data only... */
-               if (value & 0x8000) {
-                       /* delete error and new data bit */
-                       value �alue & 0x3fff;
-                       /* set negative value */
-                       if (value & 0x2000)
-                               value �alue | 0xe000;
-
-                       if (likely(spiadis->negative))
-                               value �value;
-
-                       spiadis->data �s16) value;
-               }
-       } else {
+       u16 value = 0;
+
+       status =  spi_adis16255_read_data(spiadis, ADIS_GYRO_OUT, (u8 *)&value);
+       if (status != 0) {
                dev_warn(&spiadis->spi->dev, "SPI FAILED\n");
+               goto exit;
        }
 
+       /* perform on new data only... */
+       if (value & 0x8000) {
+               /* delete error and new data bit */
+               value = value & 0x3fff;
+               /* set negative value */
+               if (value & 0x2000)
+                       value = value | 0xe000;
+
+               if (likely(spiadis->negative))
+                       value = -value;
+
+               spiadis->data = (s16) value;
+       }
+
+exit:
        return IRQ_HANDLED;
 }
 
@@ -221,7 +227,7 @@ ssize_t adis16255_show_data(struct device *device,
                struct device_attribute *da,
                char *buf)
 {
-       struct spi_adis16255_data *spiadis ev_get_drvdata(device);
+       struct spi_adis16255_data *spiadis = dev_get_drvdata(device);
        return snprintf(buf, PAGE_SIZE, "%d\n", spiadis->data);
 }
 DEVICE_ATTR(data, S_IRUGO , adis16255_show_data, NULL);
@@ -230,112 +236,186 @@ ssize_t adis16255_show_direction(struct device *device,
                struct device_attribute *da,
                char *buf)
 {
-       struct spi_adis16255_data *spiadis ev_get_drvdata(device);
+       struct spi_adis16255_data *spiadis = dev_get_drvdata(device);
        return snprintf(buf, PAGE_SIZE, "%c\n", spiadis->direction);
 }
 DEVICE_ATTR(direction, S_IRUGO , adis16255_show_direction, NULL);
 
-static struct attribute *adis16255_attributes[] �
+ssize_t adis16255_show_sample_rate(struct device *device,
+               struct device_attribute *da,
+               char *buf)
+{
+       struct spi_adis16255_data *spiadis = dev_get_drvdata(device);
+       int status = 0;
+       u16 value = 0;
+       int ts = 0;
+
+       status = spi_adis16255_read_data(spiadis, ADIS_SMPL_PRD_MSB,
+                               (u8 *)&value);
+       if (status != 0)
+               return -EINVAL;
+
+       if (value & 0x80) {
+               /* timebase = 60.54 ms */
+               ts = 60540 * ((0x7f & value) + 1);
+       } else {
+               /* timebase = 1.953 ms */
+               ts = 1953 * ((0x7f & value) + 1);
+       }
+
+       return snprintf(buf, PAGE_SIZE, "%d\n", (1000*1000)/ts);
+}
+DEVICE_ATTR(sample_rate, S_IRUGO , adis16255_show_sample_rate, NULL);
+
+static struct attribute *adis16255_attributes[] = {
        &dev_attr_data.attr,
        &dev_attr_direction.attr,
+       &dev_attr_sample_rate.attr,
        NULL
 };
 
-static const struct attribute_group adis16255_attr_group 
-       .attrs dis16255_attributes,
+static const struct attribute_group adis16255_attr_group = {
+       .attrs = adis16255_attributes,
 };
 
 /*-------------------------------------------------------------------------*/
 
-static int spi_adis16255_probe(struct spi_device *spi)
+static int spi_adis16255_shutdown(struct spi_adis16255_data *spiadis)
+{
+       u16 value = 0;
+       /* turn sensor off */
+       spi_adis16255_write_data(spiadis,
+                       ADIS_SMPL_PRD_MSB, ADIS_SMPL_PRD_LSB,
+                       (u8 *)&value);
+       spi_adis16255_write_data(spiadis,
+                       ADIS_MSC_CTRL_MSB, ADIS_MSC_CTRL_LSB,
+                       (u8 *)&value);
+       return 0;
+}
+
+static int spi_adis16255_bringup(struct spi_adis16255_data *spiadis)
 {
+       int status = 0;
+       u16 value = 0;
+
+       status = spi_adis16255_read_data(spiadis, ADIS_GYRO_SCALE,
+                               (u8 *)&value);
+       if (status != 0)
+               goto err;
+       if (value != 0x0800) {
+               dev_warn(&spiadis->spi->dev, "Scale factor is none default"
+                               "value (%.4x)\n", value);
+       }
+
+       /* timebase = 1.953 ms, Ns = 0 -> 512 Hz sample rate */
+       value =  0x0001;
+       status = spi_adis16255_write_data(spiadis,
+                               ADIS_SMPL_PRD_MSB, ADIS_SMPL_PRD_LSB,
+                               (u8 *)&value);
+       if (status != 0)
+               goto err;
+
+       /* start internal self-test */
+       value = 0x0400;
+       status = spi_adis16255_write_data(spiadis,
+                               ADIS_MSC_CTRL_MSB, ADIS_MSC_CTRL_LSB,
+                               (u8 *)&value);
+       if (status != 0)
+               goto err;
+
+       /* wait 35 ms to finish self-test */
+       msleep(35);
+
+       value = 0x0000;
+       status = spi_adis16255_read_data(spiadis, ADIS_STATUS,
+                               (u8 *)&value);
+       if (status != 0)
+               goto err;
+
+       if (value & 0x23) {
+               if (value & 0x20) {
+                       dev_warn(&spiadis->spi->dev, "self-test error\n");
+                       status = -ENODEV;
+                       goto err;
+               } else if (value & 0x3) {
+                       dev_warn(&spiadis->spi->dev, "Sensor voltage"
+                                               "out of range.\n");
+                       status = -ENODEV;
+                       goto err;
+               }
+       }
 
-#define AD_CHK(_ss)\
-       do {\
-               status �ss;\
-               if (status !�)\
-                       goto irq_err;\
-       } while (0);
+       /* set interrupt to active high on DIO0 when data ready */
+       value = 0x0006;
+       status = spi_adis16255_write_data(spiadis,
+                               ADIS_MSC_CTRL_MSB, ADIS_MSC_CTRL_LSB,
+                               (u8 *)&value);
+       if (status != 0)
+               goto err;
+       return status;
+
+err:
+       spi_adis16255_shutdown(spiadis);
+       return status;
+}
+
+/*-------------------------------------------------------------------------*/
 
-       struct adis16255_init_data *init_data �pi->dev.platform_data;
+static int spi_adis16255_probe(struct spi_device *spi)
+{
+
+       struct adis16255_init_data *init_data = spi->dev.platform_data;
        struct spi_adis16255_data  *spiadis;
-       int status �;
-       u16 value;
+       int status = 0;
 
-       spiadis zalloc(sizeof(*spiadis), GFP_KERNEL);
+       spiadis = kzalloc(sizeof(*spiadis), GFP_KERNEL);
        if (!spiadis)
                return -ENOMEM;
 
-       spiadis->spi �pi;
-       spiadis->irq_adis �nit_data->irq;
-       spiadis->direction �nit_data->direction;
+       spiadis->spi = spi;
+       spiadis->direction = init_data->direction;
 
        if (init_data->negative)
-               spiadis->negative ;
+               spiadis->negative = 1;
 
-       status �pio_request(spiadis->irq_adis, "adis16255");
-       if (status !)
+       status = gpio_request(init_data->irq, "adis16255");
+       if (status != 0)
                goto err;
 
-       status �pio_direction_input(spiadis->irq_adis);
-       if (status !)
+       status = gpio_direction_input(init_data->irq);
+       if (status != 0)
                goto gpio_err;
 
-       spiadis->irq �pio_to_irq(spiadis->irq_adis);
+       spiadis->irq = gpio_to_irq(init_data->irq);
 
-       status equest_threaded_irq(spiadis->irq,
+       status = request_threaded_irq(spiadis->irq,
                        NULL, adis_irq_thread,
                        IRQF_DISABLED, "adis-driver", spiadis);
 
-       if (status !) {
+       if (status != 0) {
                dev_err(&spi->dev, "IRQ request failed\n");
                goto gpio_err;
        }
 
-       dev_dbg(&spi->dev, "GPIO %d IRQ %d\n", spiadis->irq_adis, spiadis->irq);
+       dev_dbg(&spi->dev, "GPIO %d IRQ %d\n", init_data->irq, spiadis->irq);
 
        dev_set_drvdata(&spi->dev, spiadis);
-       AD_CHK(sysfs_create_group(&spi->dev.kobj, &adis16255_attr_group));
-
-       dev_info(&spi->dev, "spi_adis16255 driver added!\n");
+       status = sysfs_create_group(&spi->dev.kobj, &adis16255_attr_group);
+       if (status != 0)
+               goto irq_err;
 
-       AD_CHK(spi_adis16255_read_data(spiadis, ADIS_SUPPLY_OUT, (u8 *)&value));
-       dev_info(&spi->dev, "sensor works with %d mV (%.4x)!\n",
-                       ((value & 0x0fff)*18315)/10000,
-                       (value & 0x0fff));
+       status = spi_adis16255_bringup(spiadis);
+       if (status != 0)
+               goto irq_err;
 
-       AD_CHK(spi_adis16255_read_data(spiadis, ADIS_GYRO_SCALE, (u8 *)&value));
-       dev_info(&spi->dev, "adis GYRO_SCALE is %.4x\n", value);
-
-       AD_CHK(spi_adis16255_read_data(spiadis, ADIS_STATUS, (u8 *)&value));
-       dev_info(&spi->dev, "adis STATUS is %.4x\n", value);
-
-       /* timebase �.953 ms, Ns � -> 512 Hz sample rate */
-       value �0x0001;
-       AD_CHK(spi_adis16255_write_data(spiadis,
-                               ADIS_SMPL_PRD_MSB, ADIS_SMPL_PRD_LSB,
-                               (u8 *)&value));
-       value 羵0000;
-       AD_CHK(spi_adis16255_read_data(spiadis, ADIS_SMPL_PRD_MSB,
-                               (u8 *)&value));
-       dev_info(&spi->dev, "adis SMP_PRD is %.4x\n", value);
-
-       /* set interrupt on new data... */
-       value 羵0006;
-       AD_CHK(spi_adis16255_write_data(spiadis,
-                               ADIS_MSC_CTRL_MSB, ADIS_MSC_CTRL_LSB,
-                               (u8 *)&value));
-       value 羵0000;
-       AD_CHK(spi_adis16255_read_data(spiadis, ADIS_MSC_CTRL_MSB,
-                               (u8 *)&value));
-       dev_info(&spi->dev, "adis MSC_CONTROL is %.4x\n", value);
+       dev_info(&spi->dev, "spi_adis16255 driver added!\n");
 
        return status;
 
 irq_err:
        free_irq(spiadis->irq, spiadis);
 gpio_err:
-       gpio_free(spiadis->irq_adis);
+       gpio_free(init_data->irq);
 err:
        kfree(spiadis);
        return status;
@@ -343,22 +423,12 @@ err:
 
 static int spi_adis16255_remove(struct spi_device *spi)
 {
-       u16 value �;
-       struct spi_adis16255_data  *spiadis    �ev_get_drvdata(&spi->dev);
-
-       /* turn sensor off */
-       spi_adis16255_write_data(spiadis,
-                       ADIS_SMPL_PRD_MSB, ADIS_SMPL_PRD_LSB,
-                       (u8 *)&value);
-       spi_adis16255_write_data(spiadis,
-                       ADIS_MSC_CTRL_MSB, ADIS_MSC_CTRL_LSB,
-                       (u8 *)&value);
+       struct spi_adis16255_data  *spiadis    = dev_get_drvdata(&spi->dev);
 
-       dev_info(&spi->dev, "unregister: GPIO %d IRQ %d\n",
-               spiadis->irq_adis, spiadis->irq);
+       spi_adis16255_shutdown(spiadis);
 
        free_irq(spiadis->irq, spiadis);
-       gpio_free(spiadis->irq_adis);
+       gpio_free(irq_to_gpio(spiadis->irq));
 
        sysfs_remove_group(&spiadis->spi->dev.kobj, &adis16255_attr_group);
 
@@ -368,13 +438,13 @@ static int spi_adis16255_remove(struct spi_device *spi)
        return 0;
 }
 
-static struct spi_driver spi_adis16255_drv 
-       .driver 
-               .name "spi_adis16255",
-               .owner HIS_MODULE,
+static struct spi_driver spi_adis16255_drv = {
+       .driver = {
+               .name =  "spi_adis16255",
+               .owner = THIS_MODULE,
        },
-       .probe pi_adis16255_probe,
-       .remove  __devexit_p(spi_adis16255_remove),
+       .probe = spi_adis16255_probe,
+       .remove =   __devexit_p(spi_adis16255_remove),
 };
 
 /*-------------------------------------------------------------------------*/