This version (05 Sep 2012 11:37) was approved by mhennerich.The Previously approved version (09 Nov 2011 11:29) is available.
This is a Linux industrial I/O (IIO) subsystem driver, targeting serial interface Accelerometer. The industrial I/O subsystem provides a unified framework for drivers for many different types of converters and sensors using a number of different physical interfaces (i2c, spi, etc). See IIO for more information.
| Function | File |
|---|---|
| driver | drivers/staging/iio/accel/adis16220_core.c |
| driver | drivers/staging/iio/accel/adis16220_ring.c |
| driver | drivers/staging/iio/accel/adis16220_trigger.c |
| include | drivers/staging/iio/accel/adis16220.h |
Unlike PCI or USB devices, SPI devices are not enumerated at the hardware level. Instead, the software must know which devices are connected on each SPI bus segment, and what slave selects these devices are using. For this reason, the kernel code must instantiate SPI devices explicitly. The most common method is to declare the SPI devices by bus number.
This method is appropriate when the SPI bus is a system bus, as in many embedded systems, wherein each SPI bus has a number which is known in advance. It is thus possible to pre-declare the SPI devices that inhabit this bus. This is done with an array of struct spi_board_info, which is registered by calling spi_register_board_info().
For more information see: Documentation/spi/spi-summary
Depending on the converter IC used, you may need to set the modalias accordingly, matching your part name. It may also required to adjust max_speed_hz. Please consult the datasheet, for maximum spi clock supported by the device in question.
static struct spi_board_info board_spi_board_info[] __initdata = { #if defined(CONFIG_ADIS16220) \ || defined(CONFIG_ADIS16220_MODULE) { .modalias = "adis16220", .max_speed_hz = 1000000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 5, /* CS, change it for your board */ .platform_data = NULL, /* No spi_driver specific config */ .mode = SPI_MODE_3, .irq = IRQ_PF5, }, #endif };
static int __init board_init(void) { [--snip--] spi_register_board_info(board_spi_board_info, ARRAY_SIZE(board_spi_board_info)); [--snip--] return 0; } arch_initcall(board_init);
Configure kernel with “make menuconfig” (alternatively use “make xconfig” or “make qconfig”)
The ADIS16220 Driver depends on CONFIG_SPI
Linux Kernel Configuration Device Drivers ---> [*] Staging drivers ---> <*> Industrial I/O support ---> --- Industrial I/O support -*- Enable ring buffer support within IIO -*- Industrial I/O lock free software ring -*- Enable triggered sampling support *** Accelerometers *** [--snip--] <*> ADIS16220 Programmable Digital Vibration Sensor [--snip--]
Each and every IIO device, typically a hardware chip, has a device folder under /sys/bus/iio/devices/iio:deviceX. Where X is the IIO index of the device. Under every of these directory folders reside a set of files, depending on the characteristics and features of the hardware device in question. These files are consistently generalized and documented in the IIO ABI documentation. In order to determine which IIO deviceX corresponds to which hardware device, the user can read the name file /sys/bus/iio/devices/iio:deviceX/name. In case the sequence in which the iio device drivers are loaded/registered is constant, the numbering is constant and may be known in advance.
This specifies any shell prompt running on the target
root:/> cd /sys/bus/iio/devices/ root:/sys/bus/iio/devices> ls iio:device0 trigger0 root:/sys/bus/iio/devices> cd iio:device0 root:/sys/devices/platform/bfin-spi.0/spi0.5/iio:device0> ls -l -r--r--r-- 1 root root 2048 Jan 4 03:39 accel_bin --w------- 1 root root 4096 Jan 4 03:39 capture -rw-r--r-- 1 root root 4096 Jan 4 03:39 capture_count -r--r--r-- 1 root root 4096 Jan 4 03:39 dev -r--r--r-- 1 root root 2048 Jan 4 03:39 in0_bin -r--r--r-- 1 root root 2048 Jan 4 03:39 in1_bin -rw-r--r-- 1 root root 4096 Jan 4 03:39 in_accel_offset -rw-r--r-- 1 root root 4096 Jan 4 03:39 in_accel_peak_raw -r--r--r-- 1 root root 4096 Jan 4 03:39 in_accel_raw -rw-r--r-- 1 root root 4096 Jan 4 03:39 in_accel_scale -rw-r--r-- 1 root root 4096 Jan 4 03:39 in_temp0_offset -r--r--r-- 1 root root 4096 Jan 4 03:39 in_temp0_raw -rw-r--r-- 1 root root 4096 Jan 4 03:39 in_temp0_scale -r--r--r-- 1 root root 4096 Jan 4 03:39 in_voltage0_supply_raw -rw-r--r-- 1 root root 4096 Jan 4 03:39 in_voltage0_supply_scale -rw-r--r-- 1 root root 4096 Jan 4 03:39 in_voltage1_offset -r--r--r-- 1 root root 4096 Jan 4 03:39 in_voltage1_raw -rw-r--r-- 1 root root 4096 Jan 4 03:39 in_voltage1_scale -r--r--r-- 1 root root 4096 Jan 4 03:39 in_voltage2_raw -r--r--r-- 1 root root 4096 Jan 4 03:39 name drwxr-xr-x 2 root root 0 Jan 4 03:39 power --w------- 1 root root 4096 Jan 4 03:39 reset lrwxrwxrwx 1 root root 0 Jan 4 03:39 subsystem -> ../../../../../bus/iio -rw-r--r-- 1 root root 4096 Jan 4 03:39 uevent
This specifies any shell prompt running on the target
root:/sys/devices/platform/bfin-spi.0/spi0.5/iio:device0> cat name adis16220
For a detailed description please see: drivers/staging/iio/Documentation/sysfs-bus-iio
| Device files |
|---|
| accel_bin |
| capture |
| capture_count |
| dev |
| in0_bin |
| in1_bin |
| in_accel_offset |
| in_accel_peak_raw |
| in_accel_raw |
| in_accel_scale |
| in_temp0_offset |
| in_temp0_raw |
| in_temp0_scale |
| in_voltage0_supply_raw |
| in_voltage0_supply_scale |
| in_voltage1_offset |
| in_voltage1_raw |
| in_voltage1_scale |
| in_voltage2_raw |
| name |
| reset |
This specifies any shell prompt running on the target
root:/> modprobe adis16220 adis16220: module is from the staging directory, the quality is unknown, you have been warned. adis16220: at CS5 (irq 54)
This specifies any shell prompt running on the target
root:/sys/devices/platform/bfin-spi.0/spi0.5/device0> echo 1 > capture
This specifies any shell prompt running on the target
root:/sys/devices/platform/bfin-spi.0/spi0.5/device0> cat capture_count 0
This specifies any shell prompt running on the target
root:/sys/devices/platform/bfin-spi.0/spi0.5/device0> cat in_accel_raw 1865 root:/sys/devices/platform/bfin-spi.0/spi0.5/device0> root:/sys/devices/platform/bfin-spi.0/spi0.5/device0> cat in_accel_raw 1895
You can also read the whole capture buffer by accessing the binary node in sysfs. For example, read accel_bin to get the capture buffer:
int main(int argc,char **argv) { int fd, ret; unsigned short *val; char buffer[2048]; if((fd=open("/sys/class/iio/device0/accel_bin",O_RDONLY))==-1) { printf("open /sys/class/iio/device0/accel_bin fail\n"); exit(1); } ret = read(fd, buffer, 1024); if (ret < 0) { printf("read /sys/class/iio/device0/accel_bin fail\n"); exit(1); } else { printf("read %d bytes from /sys/class/iio/device0/accel_bin\n", ret); int i; for (i = 0; i < ret; i += 2) { val = buffer + i; printf("%04x\n", *val); } } close(fd); }