Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 354203
b: refs/heads/master
c: 1db18bb
h: refs/heads/master
i:
  354201: e483df8
  354199: 97b4da0
v: v3
  • Loading branch information
Lars-Peter Clausen authored and Jonathan Cameron committed Jan 26, 2013
1 parent 5c4ca00 commit 34ee4fa
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 5 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7ba8a04dcdfb5ebcb4985a92dfc4dc4f59510464
refs/heads/master: 1db18bb4c25823bfc11f370157f9d23a4d99ea1d
4 changes: 4 additions & 0 deletions trunk/drivers/iio/imu/adis16400.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@
#define ADIS16400_ALM_CTRL 0x48 /* Alarm control */
#define ADIS16400_AUX_DAC 0x4A /* Auxiliary DAC data */

#define ADIS16334_LOT_ID1 0x52 /* Lot identification code 1 */
#define ADIS16334_LOT_ID2 0x54 /* Lot identification code 2 */
#define ADIS16400_PRODUCT_ID 0x56 /* Product identifier */
#define ADIS16334_SERIAL_NUMBER 0x58 /* Serial number, lot specific */

#define ADIS16400_ERROR_ACTIVE (1<<14)
#define ADIS16400_NEW_DATA (1<<14)
Expand Down Expand Up @@ -132,6 +135,7 @@
#define ADIS16400_HAS_PROD_ID BIT(0)
#define ADIS16400_NO_BURST BIT(1)
#define ADIS16400_HAS_SLOW_MODE BIT(2)
#define ADIS16400_HAS_SERIAL_NUMBER BIT(3)

struct adis16400_state;

Expand Down
113 changes: 109 additions & 4 deletions trunk/drivers/iio/imu/adis16400_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,112 @@
#include <linux/sysfs.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/debugfs.h>

#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/buffer.h>

#include "adis16400.h"

#ifdef CONFIG_DEBUG_FS

static ssize_t adis16400_show_serial_number(struct file *file,
char __user *userbuf, size_t count, loff_t *ppos)
{
struct adis16400_state *st = file->private_data;
u16 lot1, lot2, serial_number;
char buf[16];
size_t len;
int ret;

ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID1, &lot1);
if (ret < 0)
return ret;

ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID2, &lot2);
if (ret < 0)
return ret;

ret = adis_read_reg_16(&st->adis, ADIS16334_SERIAL_NUMBER,
&serial_number);
if (ret < 0)
return ret;

len = snprintf(buf, sizeof(buf), "%.4x-%.4x-%.4x\n", lot1, lot2,
serial_number);

return simple_read_from_buffer(userbuf, count, ppos, buf, len);
}

static const struct file_operations adis16400_serial_number_fops = {
.open = simple_open,
.read = adis16400_show_serial_number,
.llseek = default_llseek,
.owner = THIS_MODULE,
};

static int adis16400_show_product_id(void *arg, u64 *val)
{
struct adis16400_state *st = arg;
uint16_t prod_id;
int ret;

ret = adis_read_reg_16(&st->adis, ADIS16400_PRODUCT_ID, &prod_id);
if (ret < 0)
return ret;

*val = prod_id;

return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(adis16400_product_id_fops,
adis16400_show_product_id, NULL, "%lld\n");

static int adis16400_show_flash_count(void *arg, u64 *val)
{
struct adis16400_state *st = arg;
uint16_t flash_count;
int ret;

ret = adis_read_reg_16(&st->adis, ADIS16400_FLASH_CNT, &flash_count);
if (ret < 0)
return ret;

*val = flash_count;

return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(adis16400_flash_count_fops,
adis16400_show_flash_count, NULL, "%lld\n");

static int adis16400_debugfs_init(struct iio_dev *indio_dev)
{
struct adis16400_state *st = iio_priv(indio_dev);

if (st->variant->flags & ADIS16400_HAS_SERIAL_NUMBER)
debugfs_create_file("serial_number", 0400,
indio_dev->debugfs_dentry, st,
&adis16400_serial_number_fops);
if (st->variant->flags & ADIS16400_HAS_PROD_ID)
debugfs_create_file("product_id", 0400,
indio_dev->debugfs_dentry, st,
&adis16400_product_id_fops);
debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry,
st, &adis16400_flash_count_fops);

return 0;
}

#else

static int adis16400_debugfs_init(struct iio_dev *indio_dev)
{
return 0;
}

#endif

enum adis16400_chip_variant {
ADIS16300,
ADIS16334,
Expand Down Expand Up @@ -600,7 +699,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
[ADIS16334] = {
.channels = adis16334_channels,
.num_channels = ARRAY_SIZE(adis16334_channels),
.flags = ADIS16400_HAS_PROD_ID,
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_NO_BURST |
ADIS16400_HAS_SERIAL_NUMBER,
.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
.accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
.temp_scale_nano = 67850000, /* 0.06785 C */
Expand All @@ -622,7 +722,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
[ADIS16360] = {
.channels = adis16350_channels,
.num_channels = ARRAY_SIZE(adis16350_channels),
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE |
ADIS16400_HAS_SERIAL_NUMBER,
.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
.accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */
.temp_scale_nano = 136000000, /* 0.136 C */
Expand All @@ -633,7 +734,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
[ADIS16362] = {
.channels = adis16350_channels,
.num_channels = ARRAY_SIZE(adis16350_channels),
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE |
ADIS16400_HAS_SERIAL_NUMBER,
.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
.accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */
.temp_scale_nano = 136000000, /* 0.136 C */
Expand All @@ -644,7 +746,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
[ADIS16364] = {
.channels = adis16350_channels,
.num_channels = ARRAY_SIZE(adis16350_channels),
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE |
ADIS16400_HAS_SERIAL_NUMBER,
.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
.accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
.temp_scale_nano = 136000000, /* 0.136 C */
Expand All @@ -671,6 +774,7 @@ static const struct iio_info adis16400_info = {
.write_raw = &adis16400_write_raw,
.attrs = &adis16400_attribute_group,
.update_scan_mode = adis16400_update_scan_mode,
.debugfs_reg_access = adis_debugfs_reg_access,
};

static const unsigned long adis16400_burst_scan_mask[] = {
Expand Down Expand Up @@ -768,6 +872,7 @@ static int adis16400_probe(struct spi_device *spi)
if (ret)
goto error_cleanup_buffer;

adis16400_debugfs_init(indio_dev);
return 0;

error_cleanup_buffer:
Expand Down

0 comments on commit 34ee4fa

Please sign in to comment.