|
| 1 | +.. SPDX-License-Identifier: GPL-2.0-only |
| 2 | +
|
| 3 | +=============== |
| 4 | +MAX22007 driver |
| 5 | +=============== |
| 6 | + |
| 7 | +Device driver for Analog Devices Inc. MAX22007 quad-channel industrial DAC. |
| 8 | +The module name is ``max22007``. |
| 9 | + |
| 10 | +The MAX22007 is a quad-channel, 12-bit digital-to-analog converter (DAC) with |
| 11 | +integrated precision output amplifiers and current output capability. Each |
| 12 | +channel can be independently configured for voltage or current output mode. |
| 13 | + |
| 14 | +Supported devices |
| 15 | +================= |
| 16 | + |
| 17 | +* `MAX22007 <https://www.analog.com/en/products/max22007.html>`_ |
| 18 | + |
| 19 | +Device Features |
| 20 | +=============== |
| 21 | + |
| 22 | +* 4 independent DAC channels |
| 23 | +* 12-bit resolution |
| 24 | +* Configurable voltage or current output per channel |
| 25 | +* Configurable latch modes (LDAC control or transparent) |
| 26 | +* Individual channel power control |
| 27 | +* SPI interface with CRC8 error checking |
| 28 | +* Industrial temperature range operation |
| 29 | + |
| 30 | +Wiring connections |
| 31 | +================== |
| 32 | + |
| 33 | +The MAX22007 uses a standard SPI interface: |
| 34 | + |
| 35 | +:: |
| 36 | + |
| 37 | + .----------------. .----------. |
| 38 | + | |--- SPI_CLK ----| | |
| 39 | + | SPI Master |--- SPI_CS -----| MAX22007 | |
| 40 | + | |--- SPI_MOSI ---| | |
| 41 | + | |--- SPI_MISO ---| | |
| 42 | + |________________| |__________| |
| 43 | + |
| 44 | +Device Tree Configuration |
| 45 | +========================= |
| 46 | + |
| 47 | +The device supports per-channel configuration through device tree. Each channel |
| 48 | +can be configured with the following optional properties: |
| 49 | + |
| 50 | +* ``adi,dac-latch-mode``: Controls when DAC updates occur |
| 51 | + - 0: LDAC pin controls the latch (default) |
| 52 | + - 1: Transparent latch mode (immediate update) |
| 53 | + |
| 54 | +* ``adi,channel-mode``: Sets the output mode |
| 55 | + - 0: Voltage output mode (default) |
| 56 | + - 1: Current output mode |
| 57 | + |
| 58 | +* ``adi,channel-power``: Controls channel power state |
| 59 | + - 0: Channel powered off |
| 60 | + - 1: Channel powered on (default) |
| 61 | + |
| 62 | +Example device tree configuration: |
| 63 | + |
| 64 | +.. code-block:: devicetree |
| 65 | +
|
| 66 | + dac@0 { |
| 67 | + compatible = "adi,max22007"; |
| 68 | + reg = <0>; |
| 69 | + spi-max-frequency = <25000000>; |
| 70 | + #address-cells = <1>; |
| 71 | + #size-cells = <0>; |
| 72 | +
|
| 73 | + channel@0 { |
| 74 | + reg = <0>; |
| 75 | + adi,channel-mode = <0>; /* Voltage output */ |
| 76 | + adi,dac-latch-mode = <0>; /* LDAC control */ |
| 77 | + adi,channel-power = <1>; /* Powered on */ |
| 78 | + }; |
| 79 | +
|
| 80 | + channel@1 { |
| 81 | + reg = <1>; |
| 82 | + adi,channel-mode = <1>; /* Current output */ |
| 83 | + }; |
| 84 | + }; |
| 85 | +
|
| 86 | +Sysfs Interface |
| 87 | +=============== |
| 88 | + |
| 89 | +The MAX22007 driver provides standard IIO DAC interfaces. Each channel appears |
| 90 | +as a separate IIO device attribute: |
| 91 | + |
| 92 | +* ``out_voltage_raw`` (voltage mode channels) |
| 93 | +* ``out_current_raw`` (current mode channels) |
| 94 | + |
| 95 | +The driver automatically configures the IIO channel type based on the configured |
| 96 | +channel mode from device tree. |
| 97 | + |
| 98 | +Usage Examples |
| 99 | +============== |
| 100 | + |
| 101 | +Setting DAC output value: |
| 102 | + |
| 103 | +.. code-block:: bash |
| 104 | +
|
| 105 | + # Set channel 0 (voltage mode) to mid-scale |
| 106 | + echo 2048 > /sys/bus/iio/devices/iio:deviceX/out_voltage0_raw |
| 107 | +
|
| 108 | + # Set channel 1 (current mode) to quarter scale |
| 109 | + echo 1024 > /sys/bus/iio/devices/iio:deviceX/out_current1_raw |
| 110 | +
|
| 111 | +Reading current DAC value: |
| 112 | + |
| 113 | +.. code-block:: bash |
| 114 | +
|
| 115 | + # Read channel 0 value |
| 116 | + cat /sys/bus/iio/devices/iio:deviceX/out_voltage0_raw |
| 117 | +
|
| 118 | +Channel Information: |
| 119 | + |
| 120 | +.. code-block:: bash |
| 121 | +
|
| 122 | + # Check available channels |
| 123 | + ls /sys/bus/iio/devices/iio:deviceX/out_*_raw |
| 124 | +
|
| 125 | +Register Access |
| 126 | +=============== |
| 127 | + |
| 128 | +The MAX22007 device provides register access through debugfs when the driver |
| 129 | +is compiled with debug support. This allows direct hardware register access |
| 130 | +for debugging and advanced configuration. |
| 131 | + |
| 132 | +Register Map |
| 133 | +------------ |
| 134 | + |
| 135 | +The MAX22007 uses the following register mapping: |
| 136 | + |
| 137 | +.. list-table:: |
| 138 | + :header-rows: 1 |
| 139 | + |
| 140 | + * - Address |
| 141 | + - Register Name |
| 142 | + - Description |
| 143 | + * - 0x03 |
| 144 | + - CONFIG_REG |
| 145 | + - Configuration register (CRC enable, DAC latch modes) |
| 146 | + * - 0x05 |
| 147 | + - CHANNEL_MODE_REG |
| 148 | + - Channel mode and power control |
| 149 | + * - 0x06 |
| 150 | + - SOFT_RESET_REG |
| 151 | + - Software reset control |
| 152 | + * - 0x07-0x0A |
| 153 | + - DAC_CHANNEL_REG(0-3) |
| 154 | + - DAC data registers for channels 0-3 |
| 155 | + |
| 156 | +Register Access via Debugfs |
| 157 | +---------------------------- |
| 158 | + |
| 159 | +When debugfs is enabled, the driver exposes register access through: |
| 160 | + |
| 161 | +.. code-block:: bash |
| 162 | +
|
| 163 | + # Navigate to the device debugfs directory |
| 164 | + cd /sys/kernel/debug/iio/iio:deviceX/ |
| 165 | +
|
| 166 | + # Read a register (example: read CONFIG_REG at address 0x03) |
| 167 | + echo 0x03 > direct_reg_access |
| 168 | + cat direct_reg_access |
| 169 | +
|
| 170 | + # Write to a register (example: write 0x1234 to CONFIG_REG) |
| 171 | + echo 0x03 0x1234 > direct_reg_access |
| 172 | +
|
| 173 | +Programming Examples |
| 174 | +-------------------- |
| 175 | + |
| 176 | +**Direct Register Programming**: |
| 177 | + |
| 178 | +.. code-block:: bash |
| 179 | +
|
| 180 | + # Enable CRC (set bit 0 in CONFIG_REG) |
| 181 | + echo 0x03 0x0001 > /sys/kernel/debug/iio/iio:deviceX/direct_reg_access |
| 182 | +
|
| 183 | + # Set channel 0 to voltage mode and power on (clear bit 12, set bit 8 in CHANNEL_MODE_REG) |
| 184 | + echo 0x05 0x0100 > /sys/kernel/debug/iio/iio:deviceX/direct_reg_access |
| 185 | +
|
| 186 | + # Set DAC channel 0 to mid-scale (0x800 shifted to bits [15:4]) |
| 187 | + echo 0x07 0x8000 > /sys/kernel/debug/iio/iio:deviceX/direct_reg_access |
| 188 | +
|
| 189 | +**Reading Register Values**: |
| 190 | + |
| 191 | +.. code-block:: bash |
| 192 | +
|
| 193 | + # Read current channel mode configuration |
| 194 | + echo 0x05 > /sys/kernel/debug/iio/iio:deviceX/direct_reg_access |
| 195 | + cat /sys/kernel/debug/iio/iio:deviceX/direct_reg_access |
| 196 | +
|
| 197 | + # Read DAC channel 0 current value |
| 198 | + echo 0x07 > /sys/kernel/debug/iio/iio:deviceX/direct_reg_access |
| 199 | + cat /sys/kernel/debug/iio/iio:deviceX/direct_reg_access |
| 200 | +
|
| 201 | +Driver Architecture |
| 202 | +=================== |
| 203 | + |
| 204 | +The driver implements the following key features: |
| 205 | + |
| 206 | +* **CRC8 Error Checking**: All SPI communications use CRC8 for data integrity |
| 207 | +* **Channel Configuration**: Supports per-channel mode and power configuration |
| 208 | +* **Register Map**: Uses regmap for efficient register access and caching |
| 209 | +* **IIO Integration**: Full integration with the Linux IIO subsystem |
| 210 | +* **Debugfs Access**: Direct register access for debugging and development |
| 211 | + |
| 212 | +Notes and Limitations |
| 213 | +===================== |
| 214 | + |
| 215 | +* Channel configuration (voltage/current mode) is set at device tree parsing |
| 216 | + and cannot be changed dynamically |
| 217 | +* The driver requires proper device tree configuration for optimal operation |
| 218 | +* CRC error detection helps ensure data integrity in noisy industrial environments |
0 commit comments