-
Notifications
You must be signed in to change notification settings - Fork 916
Max22007 dev #3015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: rpi-6.12.y
Are you sure you want to change the base?
Max22007 dev #3015
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) | ||
| %YAML 1.2 | ||
| --- | ||
| $id: http://devicetree.org/schemas/iio/dac/adi,max22007.yaml# | ||
| $schema: http://devicetree.org/meta-schemas/core.yaml# | ||
|
|
||
| title: Analog Devices MAX22007 DAC device driver | ||
|
|
||
| maintainers: | ||
| - Janani Sunil <janani.sunil@analog.com> | ||
|
|
||
| description: | ||
| The MAX22007 is a quad-channel, 12-bit digital-to-analog converter (DAC) | ||
| with integrated precision output amplifiers and current output capability. | ||
| Each channel can be independently configured for voltage or current output. | ||
| Datasheet available at https://www.analog.com/en/products/max22007.html | ||
|
|
||
| $ref: /schemas/spi/spi-peripheral-props.yaml# | ||
|
|
||
| properties: | ||
| compatible: | ||
| const: adi,max22007 | ||
|
|
||
| reg: | ||
| maxItems: 1 | ||
|
|
||
| spi-max-frequency: | ||
| maximum: 500000 | ||
|
|
||
| '#address-cells': | ||
| const: 1 | ||
|
|
||
| '#size-cells': | ||
| const: 0 | ||
|
|
||
| vdd-supply: | ||
| description: Low-Voltage Power Supply from +2.7V to +5.5V. | ||
|
|
||
| hvdd-supply: | ||
| description: | ||
| Positive High-Voltage Power Supply from +8V to (HVSS +24V) for | ||
| the Output Channels. | ||
|
|
||
| hvss-supply: | ||
| description: | ||
| Negative High-Voltage Power Supply from -2V to 0V for the Output Channels. | ||
|
|
||
|
|
||
| reset-gpios: | ||
| maxItems: 1 | ||
| description: | ||
| GPIO used for hardware reset of the device. | ||
|
|
||
| patternProperties: | ||
| "^channel@[0-3]$": | ||
| allOf: | ||
| - $ref: /schemas/iio/dac/dac.yaml# | ||
| - type: object | ||
| description: | ||
| Represents the external channels which are connected to the DAC. | ||
| Channels not specified in the device tree will be powered off. | ||
|
|
||
| properties: | ||
| reg: | ||
| description: Channel number | ||
| maxItems: 1 | ||
|
|
||
| output-range-microamp: | ||
| type: array | ||
| items: | ||
| type: integer | ||
| minItems: 2 | ||
| maxItems: 2 | ||
| description: Min and max output range in microamps. | ||
|
|
||
| unevaluatedProperties: false | ||
|
|
||
| required: | ||
| - compatible | ||
| - reg | ||
jansunil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| anyOf: | ||
| - required: [channel@0] | ||
| - required: [channel@1] | ||
| - required: [channel@2] | ||
| - required: [channel@3] | ||
jansunil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| unevaluatedProperties: false | ||
|
|
||
| examples: | ||
| - | | ||
| #include <dt-bindings/gpio/gpio.h> | ||
| spi { | ||
| #address-cells = <1>; | ||
| #size-cells = <0>; | ||
|
|
||
| dac@0 { | ||
| compatible = "adi,max22007"; | ||
| reg = <0>; | ||
| spi-max-frequency = <500000>; | ||
| reset-gpios = <&gpio 19 GPIO_ACTIVE_LOW>; | ||
| #address-cells = <1>; | ||
| #size-cells = <0>; | ||
|
|
||
| channel@0 { | ||
| reg = <0>; | ||
| }; | ||
|
|
||
| channel@1 { | ||
| reg = <1>; | ||
| output-range-microamp = <0 25000>; | ||
| }; | ||
| }; | ||
| }; | ||
| ... | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,3 +31,4 @@ Industrial I/O Kernel Drivers | |
| adxl380 | ||
| bno055 | ||
| ep93xx_adc | ||
| max22007 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| .. SPDX-License-Identifier: GPL-2.0-only | ||
|
|
||
| =============== | ||
| MAX22007 driver | ||
| =============== | ||
|
|
||
| Device driver for Analog Devices Inc. MAX22007 quad-channel industrial DAC. | ||
| The module name is ``max22007``. | ||
|
|
||
| Supported devices | ||
| ================= | ||
|
|
||
| * `MAX22007 <https://www.analog.com/en/products/max22007.html>`_ | ||
|
|
||
| Wiring connections | ||
| ================== | ||
|
|
||
| The MAX22007 uses a standard SPI interface. | ||
|
|
||
| Device Tree Configuration | ||
| ========================= | ||
|
|
||
| The device supports both global and per-channel configuration through device tree. | ||
|
|
||
| Global Properties: | ||
| * ``reset-gpios``: GPIO pin for hardware reset (optional, falls back to software reset if not specified) | ||
| * ``vdd-supply``: Low-Voltage Power Supply from +2.7V to +5.5V (optional) | ||
| * ``hvdd-supply``: Positive High-Voltage Power Supply from +8V to (HVSS +24V) for the Output Channels (optional) | ||
| * ``hvss-supply``: Negative High-Voltage Power Supply from -2V to 0V for the Output Channels (optional) | ||
|
|
||
| Per-channel properties: | ||
| * ``output-range-microvolt``: Specify the channel output range in microvolts for voltage mode channels | ||
| * ``output-range-microamp``: Specify the channel output range in microamperes for current mode channels | ||
|
|
||
| Note: The driver operates in transparent mode (immediate register-to-output updates). | ||
| Channel mode is determined by the presence of output-range properties: | ||
| - If ``output-range-microamp`` is present, the channel operates in current mode | ||
| - Otherwise, the channel defaults to voltage mode | ||
|
|
||
| Device attributes | ||
| ================= | ||
|
|
||
| The MAX22007 driver provides IIO DAC interfaces that vary based on the | ||
| configured channel mode. Each channel appears as a separate IIO device | ||
| attribute: | ||
|
|
||
| * ``out_voltage_raw`` (voltage mode channels) | ||
| * ``out_current_raw`` (current mode channels) | ||
| * ``out_voltage_scale`` / ``out_current_scale`` (channel scaling factors) | ||
| * ``out_voltage_powerdown`` / ``out_current_powerdown`` (channel power control) | ||
| * ``crc_enable`` (device-wide CRC8 error checking control) | ||
|
|
||
| The driver automatically configures the IIO channel type based on the configured | ||
| channel mode from device tree. | ||
|
|
||
| Power Mode Control | ||
| ================== | ||
|
|
||
| Each channel provides standard IIO ``powerdown`` attributes for runtime power control: | ||
|
|
||
| * Write ``1`` to power down (disable) the channel output | ||
| * Write ``0`` to power up (enable) the channel output | ||
| * Read the attribute to get the current power state (1=powered down, 0=powered up) | ||
|
|
||
| This allows individual channels to be powered on/off independently for power | ||
| management and safety purposes. | ||
|
|
||
| CRC Control | ||
| =========== | ||
|
|
||
| The driver provides runtime control over SPI CRC8 error checking through the | ||
| ``crc_enable`` attribute: | ||
|
|
||
| * Write ``1`` to enable CRC8 error checking for data integrity (default) | ||
| * Write ``0`` to disable CRC8 checking for improved performance | ||
| * Read the attribute to get the current CRC state (1=enabled, 0=disabled) | ||
|
|
||
| CRC is enabled by default at driver initialization to ensure data integrity, | ||
| but can be disabled at runtime if needed for performance optimization. | ||
|
|
||
| Usage Examples | ||
| ============== | ||
|
|
||
| Setting DAC output values: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| # Set channel 0 (voltage mode) to raw value 655 (≈2V) | ||
| # Output is updated immediately in transparent mode | ||
| echo 655 > /sys/bus/iio/devices/iio:deviceX/out_voltage0_raw | ||
|
|
||
| # Set channel 1 (current mode) | ||
| # Output is updated immediately in transparent mode | ||
| echo 1024 > /sys/bus/iio/devices/iio:deviceX/out_current1_raw | ||
|
|
||
| Controlling channel power modes: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| # Enable channel 0 (power up) | ||
| echo 0 > /sys/bus/iio/devices/iio:deviceX/out_voltage0_powerdown | ||
|
|
||
| # Disable channel 1 (power down) | ||
| echo 1 > /sys/bus/iio/devices/iio:deviceX/out_current1_powerdown | ||
|
|
||
| # Check current power state (0=powered up, 1=powered down) | ||
| cat /sys/bus/iio/devices/iio:deviceX/out_voltage0_powerdown | ||
|
|
||
| Controlling CRC error checking: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| # Enable CRC8 checking (default) | ||
| echo 1 > /sys/bus/iio/devices/iio:deviceX/crc_enable | ||
|
|
||
| # Disable CRC8 checking for performance | ||
| echo 0 > /sys/bus/iio/devices/iio:deviceX/crc_enable | ||
|
|
||
| # Check current CRC state (1=enabled, 0=disabled) | ||
| cat /sys/bus/iio/devices/iio:deviceX/crc_enable | ||
|
|
||
| Reading channel values and scale factors: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| # Read raw DAC value | ||
| cat /sys/bus/iio/devices/iio:deviceX/out_voltage0_raw | ||
|
|
||
| # Read scale factor (volts per LSB) | ||
| cat /sys/bus/iio/devices/iio:deviceX/out_voltage0_scale | ||
|
|
||
| Check available channels: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| ls /sys/bus/iio/devices/iio:deviceX/out_*_raw | ||
|
|
||
| Scale Calculations | ||
| ================== | ||
|
|
||
| The driver provides accurate scale factors based on the hardware configuration: | ||
|
|
||
| **Voltage Mode:** | ||
| - Scale = (5 × 2.5V) / 4096 = 0.003051757 V per LSB | ||
| - Range: 0V to 12.5V over 12-bit (0-4095) | ||
| - Formula: Output = Raw_Value × Scale | ||
|
|
||
| **Current Mode:** | ||
| - Scale = (2.5V / (2 × 50Ω)) / 4096 = 0.000006103515625 A per LSB | ||
| - Range: 0A to 0.025A over 12-bit (0-4095) | ||
| - Formula: Output = Raw_Value × Scale | ||
|
|
||
| Register Map | ||
| ------------ | ||
|
|
||
| The MAX22007 uses the following register mapping: | ||
|
|
||
| .. list-table:: | ||
| :header-rows: 1 | ||
|
|
||
| * - Address | ||
| - Register Name | ||
| - Description | ||
| * - 0x03 | ||
| - CONFIG_REG | ||
| - Configuration register (CRC enable, DAC latch modes) | ||
| * - 0x04 | ||
| - CONTROL_REG | ||
| - LDAC control register for runtime updates | ||
| * - 0x05 | ||
| - CHANNEL_MODE_REG | ||
| - Channel mode and power control | ||
| * - 0x06 | ||
| - SOFT_RESET_REG | ||
| - Software reset control | ||
| * - 0x07-0x0A | ||
| - DAC_CHANNEL_REG(0-3) | ||
| - DAC data registers for channels 0-3 | ||
|
|
||
|
|
||
| Driver Architecture | ||
| =================== | ||
|
|
||
| The driver implements the following key features: | ||
|
|
||
| * **CRC8 Error Checking**: Runtime configurable CRC8 for SPI data integrity (enabled by default) | ||
| * **Channel Configuration**: Supports per-channel mode and power configuration | ||
| * **Register Map**: Uses regmap for efficient register access and caching | ||
| * **IIO Integration**: Full integration with the Linux IIO subsystem | ||
|
|
||
| Not Implemented | ||
| =============== | ||
|
|
||
| * Channel configuration (voltage/current mode) is set at device tree parsing | ||
| and cannot be changed dynamically | ||
| * The driver requires proper device tree configuration for optimal operation | ||
| * Simultaneous multi-channel LDAC updates (only single-channel updates supported) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // SPDX-License-Identifier: GPL-2.0 | ||
| /* | ||
| * Analog Devices MAX22007 | ||
| * | ||
| * Copyright (C) 2025 Analog Devices Inc. | ||
| */ | ||
|
|
||
| /dts-v1/; | ||
| /plugin/; | ||
|
|
||
| #include <dt-bindings/gpio/gpio.h> | ||
|
|
||
| &spi0 { | ||
| status = "okay"; | ||
|
|
||
| max22007: max22007@0 { | ||
| compatible = "adi,max22007"; | ||
| reg = <0>; | ||
| spi-max-frequency = <500000>; | ||
| spi-cpha; | ||
| spi-cpol; | ||
| status = "okay"; | ||
| reset-gpios = <&gpio 19 GPIO_ACTIVE_LOW>; | ||
| #address-cells = <1>; | ||
| #size-cells = <0>; | ||
|
|
||
| channel@0 { | ||
| reg = <0>; | ||
| }; | ||
|
|
||
| channel@1 { | ||
| reg = <1>; | ||
| output-range-microamp = <0 25000>; | ||
| }; | ||
|
|
||
| channel@2 { | ||
| reg = <2>; | ||
| }; | ||
|
|
||
| channel@3 { | ||
| reg = <3>; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| &spidev0 { | ||
| status = "disabled"; | ||
| }; | ||
|
|
||
| &spidev1 { | ||
| status = "disabled"; | ||
| }; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The overlay is a different patch.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we keep it here until review and then move it later on? (please correct me if my understanding is wrong) |
||
Uh oh!
There was an error while loading. Please reload this page.