This is a Linux industrial I/O (IIO) subsystem driver, targeting Impedance Converters and Network Analyzers. 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/impedance-analyzer/ad5933.c |
For compile time configuration, it’s common Linux practice to keep board- and application-specific configuration out of the main driver file, instead putting it into the board support file.
For devices on custom boards, as typical of embedded and SoC-(system-on-chip) based hardware, Linux uses platform_data to point to board-specific structures describing devices and how they are connected to the SoC. This can include available ports, chip variants, preferred modes, default initialization, additional pin roles, and so on. This shrinks the board-support packages (BSPs) and minimizes board and application specific #ifdefs in drivers.
The reference voltage or external reference clock may vary between boards and models. The platform_data for the device's “struct device” holds this information.
File: drivers/staging/iio/impedance-analyzer/ad5933.h:ad5933_platform_data
/** * struct ad5933_platform_data - platform specific data * @ext_clk_Hz: the external clock frequency in Hz, if not set * the driver uses the internal clock (16.776 MHz) * @vref_mv: the external reference voltage in millivolt */ struct ad5933_platform_data { unsigned long ext_clk_Hz; unsigned short vref_mv; };
static struct ad5933_platform_data ad5933_pdata = { .vref_mv = 3300, };
In case platform_data is not present or set to NULL, the driver will use the AD5933 internal 16.776MHz reference clock.
Unlike PCI or USB devices, I2C devices are not enumerated at the hardware level. Instead, the software must know which devices are connected on each I2C bus segment, and what address these devices are using. For this reason, the kernel code must instantiate I2C devices explicitly. There are different ways to achieve this, depending on the context and requirements. However the most common method is to declare the I2C devices by bus number.
This method is appropriate when the I2C bus is a system bus, as in many embedded systems, wherein each I2C bus has a number which is known in advance. It is thus possible to pre-declare the I2C devices that inhabit this bus. This is done with an array of struct i2c_board_info, which is registered by calling i2c_register_board_info().
So, to enable such a driver one need only edit the board support file by adding an appropriate entry to i2c_board_info.
For more information see: Documentation/i2c/instantiating-devices
Depending on the converter IC used, you may need to set the I2C_BOARD_INFO name accordingly, matching your part name.
ADI part number | I2C_BOARD_INFO Name |
---|---|
AD5933 | ad5933 |
AD5934 | ad5934 |
static struct i2c_board_info __initdata board_i2c_board_info[] = { #if defined(CONFIG_AD5933) || defi ned(CONFIG_AD5933_MODULE) { I2C_BOARD_INFO("ad5933", 0x0D), .platform_data = (void *)&ad5933_pdata, /* optional */ }, #endif };
static int __init board_init(void) { [--snip--] i2c_register_board_info(0, board_i2c_board_info, ARRAY_SIZE(board_i2c_board_info)); [--snip--] return 0; } arch_initcall(board_init);
Configure kernel with “make menuconfig” (alternatively use “make xconfig” or “make qconfig”)
The driver depends on CONFIG_I2C
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 [--snip--] *** Network Analyzer, Impedance Converters *** <*> Analog Devices AD5933, AD5934 driver [--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 root:/sys/bus/iio/devices> cd iio:device0 root:/sys/bus/iio/devices/iio:deviceX> ls -l drwxr-xr-x 4 root root 0 Jan 1 21:48 buffer -rw-r--r-- 1 root root 4096 Jan 1 21:48 in_voltage0_scale -r--r--r-- 1 root root 4096 Jan 1 21:48 in_voltage0_scale_available -r--r--r-- 1 root root 4096 Jan 1 21:48 name -rw-r--r-- 1 root root 4096 Jan 1 21:48 out_voltage0_freq_increment -rw-r--r-- 1 root root 4096 Jan 1 21:48 out_voltage0_freq_points -rw-r--r-- 1 root root 4096 Jan 1 21:48 out_voltage0_freq_start -rw-r--r-- 1 root root 4096 Jan 1 21:48 out_voltage0_scale -r--r--r-- 1 root root 4096 Jan 1 21:48 out_voltage0_scale_available -rw-r--r-- 1 root root 4096 Jan 1 21:48 out_voltage0_settling_cycles drwxr-xr-x 2 root root 0 Jan 1 21:48 power lrwxrwxrwx 1 root root 0 Jan 1 21:48 subsystem -> ../../../o -r--r--r-- 1 root root 4096 Jan 1 21:48 in_temp0_raw -rw-r--r-- 1 root root 4096 Jan 1 21:48 uevent
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:deviceX> cat name ad5933
Description: /sys/bus/iio/devices/iio:deviceX/out_voltageY_freq_start
Frequency sweep start frequency in Hz.
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:deviceX> echo 15000 > out_voltage0_freq_start root:/sys/bus/iio/devices/iio:deviceX> cat out_voltage0_freq_start 14999
Description: /sys/bus/iio/devices/iio:deviceX/out_voltageY_freq_increment
Frequency increment in Hz (step size) between consecutive frequency points along the sweep.
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:deviceX> echo 200 > out_voltageY_freq_increment
Description: /sys/bus/iio/devices/iio:deviceX/out_voltage0_freq_points
Number of frequency points (steps) in the frequency sweep.
This value, in conjunction with the out_voltageY_freq_start and the
out_voltageY_freq_increment, determines the frequency sweep range
for the sweep operation.
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:deviceX> echo 100 > out_voltage0_freq_points root:/sys/bus/iio/devices/iio:deviceX> cat out_voltage0_freq_points 100
Description: /sys/bus/iio/devices/iio:deviceX/out_voltage0_settling_cycles
Number of output excitation cycles (settling time cycles)
that are allowed to pass through the unknown impedance,
after each frequency increment, and before the ADC is triggered
to perform a conversion sequence of the response signal.
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:deviceX> echo 15 > out_voltage0_settling_cycles root:/sys/bus/iio/devices/iio:deviceX> cat out_voltage0_settling_cycles 15
Description: /sys/bus/iio/devices/iio:deviceX/out_voltage0_scale_available
List available output scales/ranges in millivolt.
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:deviceX> cat out_voltage0_scale_available 1980 970 383 198
Description: /sys/bus/iio/devices/iio:deviceX/out_voltage0_scale
Sets output scale/range in millivolt.
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:deviceX> echo 1980 > out_voltage0_scale root:/sys/bus/iio/devices/iio:deviceX> cat out_voltage0_scale 1980
Description: /sys/bus/iio/devices/iio:deviceX/in_voltage0_scale_available
List available input scales. Programmable gain amplifier (PGA) options.
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:deviceX> cat in_voltage0_scale_available 1 0.2
Description: /sys/bus/iio/devices/iio:deviceX/in_voltage0_scale
Sets input scale. Controls programmable gain amplifier (PGA).
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:deviceX> echo 0.2 > in_voltage0_scale root:/sys/bus/iio/devices/iio:deviceX> cat in_voltage0_scale 0.2Show internal temperature
Description: /sys/bus/iio/devices/iio:deviceX/in_temp0_input
Shows temperature in milli degrees Celsius.
The on-chip temperature sensor allows an accurate measurement of the ambient device temperature. The measurement range of the sensor is −40°C to +125°C.
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:deviceX> cat in_temp0_input 27987
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:deviceX/buffer> ls enable length root:/sys/bus/iio/devices/iio:deviceX/buffer>
The Industrial I/O subsystem provides support for various ring buffer based data acquisition methods. Apart from device specific hardware buffer support, the user can chose between two different software ring buffer implementations. One is the IIO lock free software ring, and the other is based on Linux kfifo. Devices with buffer support feature an additional sub-folder in the /sys/bus/iio/devices/deviceX/ folder hierarchy. Called deviceX:bufferY, where Y defaults to 0, for devices with a single buffer.
Every buffer implementation features a set of files:
length
Get/set the number of sample sets that may be held by the buffer.
enable
Enables/disables the buffer. This file should be written last, after length and selection of scan elements.
watermark
A single positive integer specifying the maximum number of scan
elements to wait for.
Poll will block until the watermark is reached.
Blocking read will wait until the minimum between the requested
read amount or the low water mark is available.
Non-blocking read will retrieve the available samples from the
buffer even if there are less samples then watermark level. This
allows the application to block on poll with a timeout and read
the available samples after the timeout expires and thus have a
maximum delay guarantee.
data_available
A read-only value indicating the bytes of data available in the
buffer. In the case of an output buffer, this indicates the
amount of empty space available to write data to. In the case of
an input buffer, this indicates the amount of data available for
reading.
length_align_bytes
Using the high-speed interface. DMA buffers may have an alignment requirement for the buffer length.
Newer versions of the kernel will report the alignment requirements
associated with a device through the `length_align_bytes` property.
scan_elements
The scan_elements directory contains interfaces for elements that will be captured for a single triggered sample set in the buffer.
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:deviceX/scan_elements> ls in_voltage0_imag_en in_voltage0_imag_type in_voltage0_real_index in_voltage0_imag_index in_voltage0_real_en in0_voltage_real_type
in_voltageX_en / in_voltageX-voltageY_en / timestamp_en:
Scan element control for triggered data capture.
Writing 1 will enable the scan element, writing 0 will disable it
in_voltageX_type / in_voltageX-voltageY_type / timestamp_type:
Description of the scan element data storage within the buffer
and therefore in the form in which it is read from user-space.
Form is [s|u]bits/storage-bits. s or u specifies if signed
(2's complement) or unsigned. bits is the number of bits of
data and storage-bits is the space (after padding) that it
occupies in the buffer. Note that some devices will have
additional information in the unused bits so to get a clean
value, the bits value must be used to mask the buffer output
value appropriately. The storage-bits value also specifies the
data alignment. So u12/16 will be a unsigned 12 bit integer
stored in a 16 bit location aligned to a 16 bit boundary.
For other storage combinations this attribute will be extended
appropriately.
in_voltageX_index / in_voltageX-voltageY_index / timestamp_index:
A single positive integer specifying the position of this
scan element in the buffer. Note these are not dependent on
what is enabled and may not be contiguous. Thus for user-space
to establish the full layout these must be used in conjunction
with all _en attributes to establish which channels are present,
and the relevant _type attributes to establish the data storage
format.
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:deviceX/scan_elements> grep “” * in_voltage0_imag_en: 1 in_voltage0_imag_index: 1 in_voltage0_imag_type: s16/16>>0 in_voltage0_real_en: 1 in_voltage0_real_index: 0 in_voltage0_real_type: s16/16>>0
This specifies any shell prompt running on the target - Example command sequence
> cd /sys/bus/iio/devices/iio:device0 > echo 10000 > out_voltage0_freq_start > echo 100 > out_voltage0_freq_increment > echo 100 > out_voltage0_freq_points > echo 512 > buffer/length > echo 1 > buffer/enable
index | datum | type |
---|---|---|
0 | Real Sample f0 | signed short 16-bit |
1 | Imag Sample f0 | signed short 16-bit |
[fn * 2] | Real Sample fn | signed short 16-bit |
[fn * 2] + 1 | Imag Sample fn | signed short 16-bit |
Z = in_voltage0_real + i * in_voltage0_imag
This specifies any shell prompt running on the target
root:> hexdump -d /dev/iio:device0* 0000000 09451 01627** 09541 01663 09622 01697 09708 01734 0000010 09799 01757 09889 01791 09985 01820 10079 01856 0000020 10172 01887 10264 01922 10357 01962 10451 02005 0000030 10543 02044 10628 02082 10714 02123 10798 02153 0000040 10889 02188 10983 02230 11069 02268 11157 02302 0000050 11246 02339 11335 02381 11429 02423 11514 02461 0000060 11603 02500 11688 02539 11782 02573 11871 02618 0000070 11955 02659 12045 02703 12135 02743 12221 02787 0000080 12307 02828 12393 02877 12481 02910 12567 02951 0000090 12659 02991 12750 03034 12840 03080 12927 03130 00000a0 13010 03173 13102 03220 13185 03268 13271 03313 00000b0 13356 03358 13443 03401 13525 03445 13612 03491 00000c0 13700 03536 13791 03584 13875 03630 13958 03684 00000d0 14047 03729 14135 03785 14216 03834 14302 03879 00000e0 14383 03930 14469 03982 14555 04028 14634 04084 00000f0 14722 04131 14805 04183 14890 04231 14972 04291 0000100 15052 04340 15136 04389 15216 04445 15301 04495 0000110 15377 04549 15455 04604 15526 04651 15595 04703 0000120 15661 04758 15731 04809 15782 04856 15836 04905 0000130 15885 04943 15939 04990 15993 05043 16035 05083 0000140 16077 05131 16118 05174 16165 05223 16198 05265 0000150 16241 05311 16275 05351 16300 05389 16336 05438 0000160 16373 05482 16405 05522 16441 05559 16470 05603 0000170 16498 05644 16534 05690 16554 05742 16577 05780 0000180 16601 05827 16621 05874 16640 05904 16668 05943 0000190 16686 05983 0000194
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
全部0条评论
快来发表一下你的评论吧 !