diff --git a/doc/sphinx/source/drivers/lt3074.rst b/doc/sphinx/source/drivers/lt3074.rst new file mode 100644 index 00000000000..690b8eedf75 --- /dev/null +++ b/doc/sphinx/source/drivers/lt3074.rst @@ -0,0 +1 @@ +.. include:: ../../../../drivers/power/lt3074/README.rst \ No newline at end of file diff --git a/doc/sphinx/source/drivers_doc.rst b/doc/sphinx/source/drivers_doc.rst index 745c89c32c9..ad796dda933 100644 --- a/doc/sphinx/source/drivers_doc.rst +++ b/doc/sphinx/source/drivers_doc.rst @@ -101,6 +101,7 @@ POWER MANAGEMENT drivers/ltc4162l drivers/ltc4296 drivers/ltm4686 + drivers/lt3074 drivers/lt7170 drivers/lt7182s drivers/lt8491 diff --git a/doc/sphinx/source/projects/lt3074.rst b/doc/sphinx/source/projects/lt3074.rst new file mode 100644 index 00000000000..f5b7d6373eb --- /dev/null +++ b/doc/sphinx/source/projects/lt3074.rst @@ -0,0 +1 @@ +.. include:: ../../../../projects/lt3074/README.rst \ No newline at end of file diff --git a/doc/sphinx/source/projects_doc.rst b/doc/sphinx/source/projects_doc.rst index 22eb063b6f0..30ccca40533 100644 --- a/doc/sphinx/source/projects_doc.rst +++ b/doc/sphinx/source/projects_doc.rst @@ -75,6 +75,7 @@ POWER MANAGEMENT projects/ltc4162l projects/ltc4296 projects/ltm4686 + projects/lt3074 projects/lt7170 projects/lt7182s projects/lt8722 diff --git a/drivers/power/lt3074/README.rst b/drivers/power/lt3074/README.rst new file mode 100644 index 00000000000..64de5c9a970 --- /dev/null +++ b/drivers/power/lt3074/README.rst @@ -0,0 +1,206 @@ +LT3074 no-OS driver +==================== + +Supported Devices +----------------- + +`LT3074 `_ + +Overview +-------- + +The LT3074 is a low voltage, ultralow noise, and ultrafast transient response +linear regulator with a PMBus serial interface. The device supplies up to 3A +with a typical dropout voltage of 45mV. + +Applications +------------ + +LT3074 +------- + +* RF Power Supplies: PLLs, VCOs, Mixers, LNAs, PAs +* High Speed/High Precision Data Converters +* Low Noise Instrumentation +* Post-Regulator for Switching Supplies +* FPGA and DSP Power Supplies +* Medical Applications + +LT3074 Device Configuration +---------------------------- + +Driver Initialization +--------------------- + +In order to be able to use the device, you will have to provide the support +for the communication protocol (I2C) alongside other GPIO pins if needed in the +specific application (depends on the way the device is used). + +The first API to be called is **lt3074_init**. Make sure that it return 0, +which means that the driver was initialized correctly. + +The initialization API uses the device descriptor and an initialization +parameter. The initialization parameter contains the optional GPIO pin +parameters for interfacing with ALERT and EN pins, and configurations for packet +error checking. + +Status Bytes +------------ + +Assertion in the status bytes/words indicates fault/warning in device input/ +output, temperature, and communication, memory and logic. These statuses can be +accessed via the **lt3074_read_status** API. + +Telemetry +--------- + +Measurements for each output channel can be read using the +**lt3074_read_value** API. Some telemetry values includes input/output voltage, +input/output current, die temperature, and output power. + +Overvalue and Undervalue Limits Configuration +--------------------------------------------- + +Overvalue and undervalue limits sets the threshold at which the device voltage, +current, and temperature must meet. When these measurements cross the limits, a +status bit may be asserted. These limits can be configured using the +**lt3074_set_limit** API. + +VOUT Margin Configuration +------------------------- + +The LT3074 output voltage margin is programmable from 0% to 30%. These can be +configured using the **lt3074_vout_margin** API. + +LT3074 Driver Initialization Example +------------------------------------- + +.. code-block:: bash + + struct lt3074_dev *lt3074_dev; + struct no_os_i2c_init_param lt3074_i2c_ip = { + .device_id = I2C_DEVICE_ID, + .max_speed_hz = 100000, + .platform_ops = I2C_OPS, + .slave_address = LT3074_PMBUS_ADDRESS, + .extra = I2C_EXTRA, + }; + + struct no_os_gpio_init_param lt3074_enable_ip = { + .port = GPIO_EN_PORT, + .number = GPIO_EN_NUMBER, + .pull = NO_OS_PULL_UP, + .platform_ops = GPIO_OPS, + .extra = GPIO_EXTRA, + }; + + struct lt3074_init_param lt3074_ip = { + .i2c_init = <3074_i2c_ip, + .alert_param = NULL, + .pg_param = NULL, + .en_param = lt3074_enable_ip, + .crc_en = false, + }; + + ret = lt3074_init(<3074_dev, <3074_ip); + if (ret) + goto error; + +LT3074 no-OS IIO support +------------------------- + +The LT3074 IIO driver comes on top of the LT3074 driver and offers support +for interfacing IIO clients through libiio. + +LT3074 IIO Device Configuration +-------------------------------- + +Channels +-------- + +The device has a total of 3 input channels and 2 output channels. The input +consists of the input voltage, bias voltage, and the die temperature. The +output consists of the output voltage and current. + +* ``vout - output voltage`` +* ``iout - output current`` +* ``vin - input voltage`` +* ``vbias - bias voltage`` +* ``temperature - die temperature`` + +Channel Attributes +------------------ + +EAch channels have 2 channel attributes: + +* ``raw - the raw value of the channel`` +* ``scale - the scale value of the channel calculated accordingly to each specific channel using a priv`` + +Global Attributes +----------------- + +The device has a total of 12 global attributes: + +* ``vout_margin_low - VOUT margin low limit`` +* ``vout_margin_high - VOUT margin high limit`` +* ``vout_margin_available - Available state of the vout_margin_low and vout_margin_high`` +* ``vout_ov_warn_limit - Output overvoltage warning limit`` +* ``vout_uv_warn_limit - Output undervoltage warning limit`` +* ``iout_oc_fault_limit - Output overcurrent fault limit`` +* ``ot_warn_limit - Overtemperature warning limit`` +* ``vin_ov_warn_limit - Input overvoltage warning limit`` +* ``vin_uv_warn_limit - Input undervoltage warning limit`` +* ``vbias_ov_warn_limit - Bias overvoltage warning limit`` +* ``vbias_uv_warn_limit - Bias undervoltage warning limit`` +* ``iout_min_warn_limit - Output minimum current warning limit`` + +Debug Attributes +---------------- + +The device has a total of 8 debug attributes: + +* ``status_byte - Status byte value`` +* ``status_vout - VOUT status byte value`` +* ``status_iout - IOUT status byte value`` +* ``status_input - INPUT status byte value`` +* ``status_mfr_specific - MFR_SPECIFIC status byte value`` +* ``status_word - Status word value`` +* ``status_temperature - TEMPERATURE status byte value of the device`` +* ``status_cml - CML status byte value of the device`` + +LT3074 IIO Driver Initialization Example +----------------------------------------- + +.. code-block:: bash + + int ret; + + struct lt3074_iio_desc *lt3074_iio_desc; + struct lt3074_iio_desc_init_param lt3074_iio_ip = { + .lt3074_init_param = <3074_ip, + }; + + struct iio_app_desc *app; + struct iio_app_init_param app_init_param = { 0 }; + + ret = lt3074_iio_init(<3074_iio_desc, <3074_iio_ip); + if (ret) + return ret; + + struct iio_app_device iio_devices[] = { + { + .name = "lt3074", + .dev = lt3074_iio_desc, + .dev_descriptor = lt3074_iio_desc->iio_dev, + } + }; + + app_init_param.devices = iio_devices; + app_init_param.nb_devices = NO_OS_ARRAY_SIZE(iio_devices); + app_init_param.uart_init_params = lt3074_uart_ip; + + ret = iio_app_init(&app, app_init_param); + if (ret) + return ret; + + return iio_app_run(app); diff --git a/drivers/power/lt3074/iio_lt3074.c b/drivers/power/lt3074/iio_lt3074.c new file mode 100644 index 00000000000..fb90012b6f2 --- /dev/null +++ b/drivers/power/lt3074/iio_lt3074.c @@ -0,0 +1,706 @@ +/***************************************************************************//** +* @file iio_lt3074.c +* @brief Source file for the LT3074 IIO Driver +* @author Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#include +#include +#include +#include "no_os_alloc.h" +#include "no_os_error.h" +#include "no_os_units.h" +#include "no_os_util.h" + +#include "lt3074.h" +#include "iio_lt3074.h" + +static const uint8_t lt3074_margin_avail[] = { + 0, + 1, + 3, + 5, + 10, + 15, + 20, + 25, + 30, +}; + +enum lt3074_iio_chan_type { + LT3074_IIO_VIN_CHAN, + LT3074_IIO_VOUT_CHAN, + LT3074_IIO_IOUT_CHAN, + LT3074_IIO_TEMP_CHAN, + LT3074_IIO_VBIAS_CHAN, +}; + +static struct iio_device lt3074_iio_dev; + +/** + * @brief Read register value. + * @param dev - The iio device structure. + * @param reg - Register to read. + * @param readval - Read value. + * @return ret - Result of the reading procedure. + * In case of success, the size of the read data is returned. +*/ +static int32_t lt3074_iio_reg_read(void *dev, uint32_t reg, uint32_t *readval) +{ + struct lt3074_iio_desc *iio_lt3074 = dev; + struct lt3074_dev *lt3074 = iio_lt3074->lt3074_dev; + int ret; + uint8_t block[6] = {0}; + + switch (reg) { + case LT3074_PAGE: + case LT3074_OPERATION: + case LT3074_ON_OFF_CONFIG: + case LT3074_WRITE_PROTECT: + case LT3074_STATUS_BYTE: + case LT3074_STATUS_VOUT: + case LT3074_STATUS_IOUT: + case LT3074_STATUS_INPUT: + case LT3074_STATUS_TEMPERATURE: + case LT3074_STATUS_CML: + case LT3074_STATUS_MFR_SPECIFIC: + case LT3074_MFR_MARGIN: + case LT3074_MFR_RAIL_ADDRESS: + case LT3074_CAPABILITY: + case LT3074_VOUT_MODE: + case LT3074_IOUT_OC_FAULT_RESPONSE: + case LT3074_REVISION: + case LT3074_MFR_DEFAULT_CONFIG: + return lt3074_read_byte(lt3074, (uint8_t)reg, + (uint8_t *)readval); + case LT3074_VOUT_OV_WARN_LIMIT: + case LT3074_VOUT_UV_WARN_LIMIT: + case LT3074_IOUT_OC_FAULT_LIMIT: + case LT3074_OT_WARN_LIMIT: + case LT3074_VIN_OV_WARN_LIMIT: + case LT3074_VIN_UV_WARN_LIMIT: + case LT3074_STATUS_WORD: + case LT3074_MFR_READ_VBIAS: + case LT3074_MFR_BIAS_OV_WARN_LIMIT: + case LT3074_MFR_BIAS_UV_WARN_LIMIT: + case LT3074_MFR_IOUT_MIN_WARN_LIMIT: + case LT3074_READ_VIN: + case LT3074_READ_VOUT: + case LT3074_READ_IOUT: + case LT3074_READ_TEMPERATURE_1: + case LT3074_IC_DEVICE_REV: + case LT3074_MFR_SPECIAL_ID: + return lt3074_read_word(lt3074, (uint8_t)reg, + (uint16_t *)readval); + case LT3074_IC_DEVICE_ID: + ret = lt3074_read_block_data(lt3074, (uint8_t)reg, + &block[0], 6); + if (ret) + return ret; + + *readval = no_os_get_unaligned_be32(block); + + return 0; + default: + return -EINVAL; + } +} + +/** + * @brief Write register value. + * @param dev - The iio device structure. + * @param reg - Register to write. + * @param writeval - Value to write. + * @return ret - Result of the writing procedure. +*/ +static int32_t lt3074_iio_reg_write(void *dev, uint32_t reg, uint32_t writeval) +{ + struct lt3074_iio_desc *iio_lt3074 = dev; + struct lt3074_dev *lt3074 = iio_lt3074->lt3074_dev; + + switch (reg) { + case LT3074_PAGE: + case LT3074_OPERATION: + case LT3074_ON_OFF_CONFIG: + case LT3074_WRITE_PROTECT: + case LT3074_STATUS_BYTE: + case LT3074_STATUS_VOUT: + case LT3074_STATUS_IOUT: + case LT3074_STATUS_INPUT: + case LT3074_STATUS_TEMPERATURE: + case LT3074_STATUS_CML: + case LT3074_STATUS_MFR_SPECIFIC: + case LT3074_MFR_MARGIN: + case LT3074_MFR_RAIL_ADDRESS: + return lt3074_write_byte(lt3074, (uint8_t)reg, + (uint8_t)writeval); + case LT3074_CLEAR_FAULTS: + case LT3074_MFR_RESET: + return lt3074_send_byte(dev, (uint8_t) reg); + case LT3074_VOUT_OV_WARN_LIMIT: + case LT3074_VOUT_UV_WARN_LIMIT: + case LT3074_IOUT_OC_FAULT_LIMIT: + case LT3074_OT_WARN_LIMIT: + case LT3074_VIN_OV_WARN_LIMIT: + case LT3074_VIN_UV_WARN_LIMIT: + case LT3074_STATUS_WORD: + case LT3074_MFR_READ_VBIAS: + case LT3074_MFR_BIAS_OV_WARN_LIMIT: + case LT3074_MFR_BIAS_UV_WARN_LIMIT: + case LT3074_MFR_IOUT_MIN_WARN_LIMIT: + return lt3074_write_word(lt3074, (uint8_t)reg, + (uint16_t)writeval); + default: + return -EINVAL; + } +} + +/** + * @brief Handles the read request for raw attribute. + * @param dev - The iio device structure. + * @param buf - Command buffer to be filled with requested data. + * @param len - Length of the received command buffer in bytes. + * @param channel - Command channel info. + * @param priv - Command attribute id. + * @return ret - Result of the reading procedure. + * In case of success, the size of the read data is returned. +*/ +static int lt3074_iio_read_raw(void *dev, char *buf, uint32_t len, + const struct iio_ch_info *channel, + intptr_t priv) +{ + struct lt3074_iio_desc *iio_lt3074 = dev; + struct lt3074_dev *lt3074 = iio_lt3074->lt3074_dev; + int ret; + uint16_t value; + + switch (channel->address) { + case LT3074_IIO_VIN_CHAN: + ret = lt3074_read_word(lt3074, LT3074_READ_VIN, &value); + break; + case LT3074_IIO_IOUT_CHAN: + ret = lt3074_read_word(lt3074, LT3074_READ_IOUT, &value); + break; + case LT3074_IIO_VOUT_CHAN: + ret = lt3074_read_word(lt3074, LT3074_READ_VOUT, &value); + break; + case LT3074_IIO_TEMP_CHAN: + ret = lt3074_read_word(lt3074, LT3074_READ_TEMPERATURE_1, + &value); + break; + case LT3074_IIO_VBIAS_CHAN: + ret = lt3074_read_word(lt3074, LT3074_MFR_READ_VBIAS, &value); + break; + default: + return -EINVAL; + } + + if (ret) + return ret; + + return iio_format_value(buf, len, IIO_VAL_INT, 1, (int32_t *)&value); +} + +/** + * @brief Handles the read request for scale attribute. + * @param dev - The iio device structure. + * @param buf - Command buffer to be filled with requested data. + * @param len - Length of the received command buffer in bytes. + * @param channel - Command channel info. + * @param priv - Command attribute id. + * @return ret - Result of the reading procedure. + * In case of success, the size of the read data is returned. +*/ +static int lt3074_iio_read_scale(void *dev, char *buf, uint32_t len, + const struct iio_ch_info *channel, + intptr_t priv) +{ + int vals[2], ret; + struct lt3074_iio_desc *iio_lt3074 = dev; + struct lt3074_dev *lt3074 = iio_lt3074->lt3074_dev; + + switch (channel->address) { + case LT3074_IIO_VIN_CHAN: + ret = lt3074_read_value(lt3074, LT3074_VIN, &vals[0]); + break; + case LT3074_IIO_IOUT_CHAN: + ret = lt3074_read_value(lt3074, LT3074_IOUT, &vals[0]); + break; + case LT3074_IIO_VOUT_CHAN: + ret = lt3074_read_value(lt3074, LT3074_VOUT, &vals[0]); + break; + case LT3074_IIO_TEMP_CHAN: + ret = lt3074_read_value(lt3074, LT3074_TEMP, &vals[0]); + break; + case LT3074_IIO_VBIAS_CHAN: + ret = lt3074_read_value(lt3074, LT3074_VBIAS, &vals[0]); + break; + default: + return -EINVAL; + } + if (ret) + return ret; + + vals[1] = MILLI; + + return iio_format_value(buf, len, IIO_VAL_FRACTIONAL, 2, (int32_t *)vals); +} + +/** + * @brief Handles the read request for status debug attribute. + * @param dev - The iio device structure. + * @param buf - Command buffer to be filled with requested data. + * @param len - Length of the received command buffer in bytes. + * @param channel - Command channel info. + * @param priv - Command attribute id. + * @return ret - Result of the reading procedure. + * In case of success, the size of the read data is returned. +*/ +static int lt3074_iio_read_status(void *dev, char *buf, uint32_t len, + const struct iio_ch_info *channel, + intptr_t priv) +{ + struct lt3074_iio_desc *iio_lt3074 = dev; + struct lt3074_dev *lt3074 = iio_lt3074->lt3074_dev; + int ret; + uint16_t status_word; + uint8_t status_byte; + + if (priv == LT3074_STATUS_WORD) { + ret = lt3074_read_word(lt3074, LT3074_STATUS_WORD, &status_word); + if (ret) + return ret; + return iio_format_value(buf, len, IIO_VAL_INT, 1, + (int32_t *)&status_word); + } else { + ret = lt3074_read_byte(lt3074, (uint8_t)priv, &status_byte); + if (ret) + return ret; + return iio_format_value(buf, len, IIO_VAL_INT, 1, + (int32_t *)&status_byte); + } +} + +/** + * @brief Handles the read request for vout margin global attributes. + * @param dev - The iio device structure. + * @param buf - Command buffer to be filled with requested data. + * @param len - Length of the received command buffer in bytes. + * @param channel - Command channel info. + * @param priv - Command attribute id. + * @return ret - Result of the reading procedure. + * In case of success, the size of the read data is returned. +*/ +static int lt3074_iio_read_vout_margin(void *dev, char *buf, uint32_t len, + const struct iio_ch_info *channel, + intptr_t priv) +{ + struct lt3074_iio_desc *iio_lt3074 = dev; + struct lt3074_dev *lt3074 = iio_lt3074->lt3074_dev; + int ret; + uint8_t data; + + if (!dev) + return -EINVAL; + + if (!iio_lt3074->lt3074_dev) + return -EINVAL; + + ret = lt3074_read_byte(lt3074, LT3074_MFR_MARGIN, &data); + if (ret) + return ret; + + data = no_os_field_get(priv, data); + data = no_os_clamp(data, 0, 8); + + return sprintf(buf, "%d ", lt3074_margin_avail[data]); +} + +/** + * @brief Handles the read request for vout_margin_available attribute. + * @param dev - The iio device structure. + * @param buf - Command buffer to be filled with requested data. + * @param len - Length of the received command buffer in bytes. + * @param channel - Command channel info. + * @param priv - Command attribute id. + * @return ret - Result of the reading procedure. + * In case of success, the size of the read data is returned. +*/ +static int lt3074_iio_read_margin_available(void *dev, char *buf, uint32_t len, + const struct iio_ch_info *channel, + intptr_t priv) +{ + int length = 0; + uint32_t i; + + for (i = 0; i < NO_OS_ARRAY_SIZE(lt3074_margin_avail); i++) + length += sprintf(buf + length, "%d ", + lt3074_margin_avail[i]); + + return length; +} + +/** + * @brief Handles the write request for vout margin global attributes. + * @param dev - The iio device structure. + * @param buf - Command buffer to be filled with requested data. + * @param len - Length of the received command buffer in bytes. + * @param channel - Command channel info. + * @param priv - Command attribute id. + * @return ret - Result of the reading procedure. + * In case of success, the size of the read data is returned. +*/ +static int lt3074_iio_write_vout_margin(void *dev, char *buf, uint32_t len, + const struct iio_ch_info *channel, + intptr_t priv) +{ + struct lt3074_iio_desc *iio_lt3074 = dev; + struct lt3074_dev *lt3074 = iio_lt3074->lt3074_dev; + int ret, val; + uint8_t data, i; + + iio_parse_value(buf, IIO_VAL_INT, (int32_t *)&val, NULL); + + for (i = 0; i < NO_OS_ARRAY_SIZE(lt3074_margin_avail); i++) + if (val == lt3074_margin_avail[i]) + break; + + if (i == NO_OS_ARRAY_SIZE(lt3074_margin_avail)) + return -EINVAL; + + ret = lt3074_read_byte(lt3074, LT3074_MFR_MARGIN, &data); + if (ret) + return ret; + + data &= ~priv; + data |= no_os_field_prep(priv, i); + + return lt3074_write_byte(lt3074, LT3074_MFR_MARGIN, data); +} + +/** + * @brief Handles the read request for limits global attributes. + * @param dev - The iio device structure. + * @param buf - Command buffer to be filled with requested data. + * @param len - Length of the received command buffer in bytes. + * @param channel - Command channel info. + * @param priv - Command attribute id. + * @return ret - Result of the reading procedure. + * In case of success, the size of the read data is returned. +*/ +static int lt3074_iio_read_limits(void *dev, char *buf, uint32_t len, + const struct iio_ch_info *channel, + intptr_t priv) +{ + struct lt3074_iio_desc *iio_lt3074 = dev; + struct lt3074_dev *lt3074 = iio_lt3074->lt3074_dev; + int ret, vals[2]; + + if (!dev) + return -EINVAL; + + if (!iio_lt3074->lt3074_dev) + return -EINVAL; + + ret = lt3074_read_word_data(lt3074, priv, &vals[1]); + if (ret) + return ret; + + vals[0] = (int32_t)(vals[1] / MILLI); + vals[1] = (int32_t)((vals[1] * MILLI) % MICRO); + + return iio_format_value(buf, len, IIO_VAL_INT_PLUS_MICRO, 2, + (int32_t *)vals); +} + +/** + * @brief Handles the write request for limits global attributes. + * @param dev - The iio device structure. + * @param buf - Command buffer to be filled with requested data. + * @param len - Length of the received command buffer in bytes. + * @param channel - Command channel info. + * @param priv - Command attribute id. + * @return ret - Result of the reading procedure. + * In case of success, the size of the read data is returned. +*/ +static int lt3074_iio_write_limits(void *dev, char *buf, uint32_t len, + const struct iio_ch_info *channel, + intptr_t priv) +{ + struct lt3074_iio_desc *iio_lt3074 = dev; + struct lt3074_dev *lt3074 = iio_lt3074->lt3074_dev; + int val1, val2; + + iio_parse_value(buf, IIO_VAL_INT_PLUS_MICRO, (int32_t *)&val1, + (int32_t *)&val2); + + val1 = val1 * MILLI + val2 / MILLI; + + return lt3074_set_limit(lt3074, (enum lt3074_limit_type)priv, val1); +} + +/** + * @brief Initializes the LT3074 IIO descriptor. + * @param iio_desc - The iio device descriptor. + * @param init_param - The structure that contains the device initial parameters. + * @return 0 in case of success, an error code otherwise. + */ +int lt3074_iio_init(struct lt3074_iio_desc **iio_desc, + struct lt3074_iio_desc_init_param *init_param) +{ + struct lt3074_iio_desc *descriptor; + int ret; + + if (!init_param || !init_param->lt3074_init_param) + return -EINVAL; + + descriptor = no_os_calloc(1, sizeof(*descriptor)); + if (!descriptor) + return -ENOMEM; + + ret = lt3074_init(&descriptor->lt3074_dev, + init_param->lt3074_init_param); + if (ret) + goto dev_err; + + descriptor->iio_dev = <3074_iio_dev; + + *iio_desc = descriptor; + + return 0; + +dev_err: + lt3074_iio_remove(descriptor); + + return ret; +} + +/** + * @brief Free resources allocated by the init function. + * @param iio_desc - The iio device descriptor. + * @return 0 in case of success, an error code otherwise. + */ +int lt3074_iio_remove(struct lt3074_iio_desc *iio_desc) +{ + if (!iio_desc) + return -ENODEV; + + no_os_free(iio_desc->iio_dev->channels); + lt3074_remove(iio_desc->lt3074_dev); + no_os_free(iio_desc); + + return 0; +} + +static struct iio_attribute lt3074_chan_attrs[] = { + { + .name = "raw", + .show = lt3074_iio_read_raw, + }, + { + .name = "scale", + .show = lt3074_iio_read_scale, + }, + END_ATTRIBUTES_ARRAY +}; + +static struct iio_attribute lt3074_global_attrs[] = { + { + .name = "vout_margin_low", + .show = lt3074_iio_read_vout_margin, + .store = lt3074_iio_write_vout_margin, + .priv = LT3074_MARGIN_LOW_MSK + }, + { + .name = "vout_margin_high", + .show = lt3074_iio_read_vout_margin, + .store = lt3074_iio_write_vout_margin, + .priv = LT3074_MARGIN_HIGH_MSK + }, + { + .name = "vout_margin_available", + .show = lt3074_iio_read_margin_available + }, + { + .name = "vout_ov_warn_limit", + .show = lt3074_iio_read_limits, + .store = lt3074_iio_write_limits, + .priv = LT3074_VOUT_OV_WARN_LIMIT_TYPE + }, + { + .name = "vout_uv_warn_limit", + .show = lt3074_iio_read_limits, + .store = lt3074_iio_write_limits, + .priv = LT3074_VOUT_UV_WARN_LIMIT_TYPE + }, + { + .name = "iout_oc_fault_limit", + .show = lt3074_iio_read_limits, + .store = lt3074_iio_write_limits, + .priv = LT3074_IOUT_OC_FAULT_LIMIT_TYPE + }, + { + .name = "ot_warn_limit", + .show = lt3074_iio_read_limits, + .store = lt3074_iio_write_limits, + .priv = LT3074_OT_WARN_LIMIT_TYPE + }, + { + .name = "vin_ov_warn_limit", + .show = lt3074_iio_read_limits, + .store = lt3074_iio_write_limits, + .priv = LT3074_VIN_OV_WARN_LIMIT_TYPE + }, + { + .name = "vin_uv_warn_limit", + .show = lt3074_iio_read_limits, + .store = lt3074_iio_write_limits, + .priv = LT3074_VIN_UV_WARN_LIMIT_TYPE + }, + { + .name = "vbias_ov_warn_limit", + .show = lt3074_iio_read_limits, + .store = lt3074_iio_write_limits, + .priv = LT3074_VBIAS_OV_WARN_LIMIT_TYPE + }, + { + .name = "vbias_uv_warn_limit", + .show = lt3074_iio_read_limits, + .store = lt3074_iio_write_limits, + .priv = LT3074_VBIAS_UV_WARN_LIMIT_TYPE + }, + { + .name = "iout_min_warn_limit", + .show = lt3074_iio_read_limits, + .store = lt3074_iio_write_limits, + .priv = LT3074_IOUT_MIN_WARN_LIMIT_TYPE + }, + END_ATTRIBUTES_ARRAY +}; + +static struct iio_attribute lt3074_debug_attrs[] = { + { + .name = "status_byte", + .show = lt3074_iio_read_status, + .priv = LT3074_STATUS_BYTE + }, + { + .name = "status_vout", + .show = lt3074_iio_read_status, + .priv = LT3074_STATUS_VOUT + }, + { + .name = "status_iout", + .show = lt3074_iio_read_status, + .priv = LT3074_STATUS_IOUT + }, + { + .name = "status_input", + .show = lt3074_iio_read_status, + .priv = LT3074_STATUS_INPUT + }, + { + .name = "status_temperature", + .show = lt3074_iio_read_status, + .priv = LT3074_STATUS_TEMPERATURE + }, + { + .name = "status_cml", + .show = lt3074_iio_read_status, + .priv = LT3074_STATUS_CML + }, + { + .name = "status_mfr_specific", + .show = lt3074_iio_read_status, + .priv = LT3074_STATUS_MFR_SPECIFIC + }, + { + .name = "status_word", + .show = lt3074_iio_read_status, + .priv = LT3074_STATUS_WORD + }, + END_ATTRIBUTES_ARRAY +}; + +static struct iio_channel lt3074_channels[] = { + { + .name = "vin", + .ch_type = IIO_VOLTAGE, + .indexed = 1, + .channel = LT3074_IIO_VIN_CHAN, + .address = LT3074_IIO_VIN_CHAN, + .attributes = lt3074_chan_attrs, + .ch_out = false + }, + { + .name = "vout", + .ch_type = IIO_VOLTAGE, + .indexed = 1, + .channel = LT3074_IIO_VOUT_CHAN, + .address = LT3074_IIO_VOUT_CHAN, + .attributes = lt3074_chan_attrs, + .ch_out = true, + }, + { + .name = "iout", + .ch_type = IIO_CURRENT, + .indexed = 1, + .channel = LT3074_IIO_IOUT_CHAN, + .address = LT3074_IIO_IOUT_CHAN, + .attributes = lt3074_chan_attrs, + .ch_out = true, + }, + { + .name = "temperature", + .ch_type = IIO_TEMP, + .indexed = 1, + .channel = LT3074_IIO_TEMP_CHAN, + .address = LT3074_IIO_TEMP_CHAN, + .attributes = lt3074_chan_attrs, + .ch_out = false, + }, + { + .name = "vbias", + .ch_type = IIO_VOLTAGE, + .indexed = 1, + .channel = LT3074_IIO_VBIAS_CHAN, + .address = LT3074_IIO_VBIAS_CHAN, + .attributes = lt3074_chan_attrs, + .ch_out = false, + }, +}; + +static struct iio_device lt3074_iio_dev = { + .num_ch = NO_OS_ARRAY_SIZE(lt3074_channels), + .channels = lt3074_channels, + .attributes = lt3074_global_attrs, + .debug_attributes = lt3074_debug_attrs, + .debug_reg_read = lt3074_iio_reg_read, + .debug_reg_write = lt3074_iio_reg_write, +}; diff --git a/drivers/power/lt3074/iio_lt3074.h b/drivers/power/lt3074/iio_lt3074.h new file mode 100644 index 00000000000..c218f8d8b55 --- /dev/null +++ b/drivers/power/lt3074/iio_lt3074.h @@ -0,0 +1,62 @@ +/***************************************************************************//** +* @file iio_lt3074.h +* @brief Header file for the LT3074 IIO Driver +* @author Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#ifndef IIO_LT3074_H +#define IIO_LT3074_H + +#include +#include "iio.h" +#include "lt3074.h" + +/** + * @brief Structure holding the LT3074 IIO device descriptor +*/ +struct lt3074_iio_desc { + struct lt3074_dev *lt3074_dev; + struct iio_device *iio_dev; +}; + +/** + * @brief Structure holding the LT3074 IIO initialization parameter. +*/ +struct lt3074_iio_desc_init_param { + struct lt3074_init_param *lt3074_init_param; +}; + +/** Initializes the LT3074 IIO descriptor. */ +int lt3074_iio_init(struct lt3074_iio_desc **, + struct lt3074_iio_desc_init_param *); + +/** Free resources allocated by the initialization function. */ +int lt3074_iio_remove(struct lt3074_iio_desc *); + +#endif /* IIO_LT3074_H */ diff --git a/drivers/power/lt3074/lt3074.c b/drivers/power/lt3074/lt3074.c new file mode 100644 index 00000000000..c2e176994a0 --- /dev/null +++ b/drivers/power/lt3074/lt3074.c @@ -0,0 +1,778 @@ +/******************************************************************************* +* @file lt3074.c +* @brief Source code of the LT3074 Driver +* @authors Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#include +#include +#include +#include + +#include "no_os_units.h" +#include "no_os_util.h" +#include "no_os_delay.h" +#include "no_os_alloc.h" +#include "no_os_i2c.h" +#include "no_os_gpio.h" +#include "no_os_crc8.h" + +#include "lt3074.h" + +NO_OS_DECLARE_CRC8_TABLE(lt3074_crc_table); + +/** + * @brief Converts data to LINEAR16 register value. + * + * @param dev The LT3074 device structure. + * @param data The data value to be converted. + * @param reg Pointer to store the converted register value. + * @return Returns 0 on success, or a negative error code on failure. + */ +static int lt3074_data2reg_linear16(struct lt3074_dev *dev, int data, + uint16_t *reg) +{ + if (data <= 0) + return -EINVAL; + data <<= -(dev->lin16_exp); + + data = NO_OS_DIV_ROUND_CLOSEST_ULL(data, MILLI); + *reg = (uint16_t)no_os_clamp(data, 0, 0xFFFF); + + return 0; +} + +/** + * @brief Converts data to LINEAR11 register value + * + * @param dev The LT3074 device structure. + * @param data The data value to be converted. + * @param reg Pointer to store the resulting register value. + * @return Returns 0 on success, or a negative error code on failure. + */ +static int lt3074_data2reg_linear11(struct lt3074_dev *dev, int data, + uint16_t *reg) +{ + int exp = 0, mant = 0; + uint8_t negative = 0; + + if (data < 0) { + negative = 1; + data = -data; + } + + /* If value too high, continuously do m/2 until m < 1023. */ + while (data >= LT3074_LIN11_MANTISSA_MAX && + exp < LT3074_LIN11_EXPONENT_MAX) { + exp++; + data >>= 1; + } + + /* If value too low, increase mantissa. */ + while (data < LT3074_LIN11_MANTISSA_MIN && + exp > LT3074_LIN11_EXPONENT_MIN) { + exp--; + data <<= 1; + } + + mant = no_os_clamp(NO_OS_DIV_ROUND_CLOSEST_ULL(data, MILLI), + 0, 0x3FF); + if (negative) + mant = -mant; + + *reg = no_os_field_prep(LT3074_LIN11_MANTISSA_MSK, mant) | + no_os_field_prep(LT3074_LIN11_EXPONENT_MSK, exp); + + return 0; +} + +/** + * @brief Converts raw LINEAR16 register value to its actual data + * + * @param dev Pointer to the lt3074_dev structure. + * @param reg 16-bit register value to be converted. + * @param data Pointer to an integer to store the converted linear data. + * @return 0 on success, negative error code on failure. + */ +static int lt3074_reg2data_linear16(struct lt3074_dev *dev, uint16_t reg, + int *data) +{ + int exp = dev->lin16_exp; + if (exp < 0) + exp = -exp; + + *data = ((int)(reg) * MILLI) >> exp; + + return 0; +} + +/** + * @brief Converts raw LINEAR11 register value to its actual data + * + * @param dev Pointer to the LT3074 device structure. + * @param reg The register value to be converted. + * @param data Pointer to the variable where the converted data will be stored. + * @return Returns 0 on success, or a negative error code on failure. + */ +static int lt3074_reg2data_linear11(struct lt3074_dev *dev, uint16_t reg, + int *data) +{ + int val, exp, mant; + + exp = LT3074_LIN11_EXPONENT(reg); + mant = LT3074_LIN11_MANTISSA(reg); + + val = mant * MILLI; + if (exp >= 0) + *data = val << exp; + else + *data = val >> -exp; + + return 0; +} + +/** + * @brief Converts the given data value to a register value. + * + * @param dev The LT3074 device structure. + * @param cmd The command value. + * @param data The data value to be converted. + * @param reg Pointer to store the converted register value. + * @return Returns 0 on success, or a negative error code on failure. + */ +static int lt3074_data2reg(struct lt3074_dev *dev, uint8_t cmd, + int data, uint16_t *reg) +{ + switch (cmd) { + case LT3074_VOUT_OV_WARN_LIMIT: + case LT3074_VOUT_UV_WARN_LIMIT: + case LT3074_READ_VOUT: + return lt3074_data2reg_linear16(dev, data, reg); + case LT3074_IOUT_OC_FAULT_LIMIT: + case LT3074_OT_WARN_LIMIT: + case LT3074_VIN_OV_WARN_LIMIT: + case LT3074_VIN_UV_WARN_LIMIT: + case LT3074_READ_VIN: + case LT3074_READ_IOUT: + case LT3074_READ_TEMPERATURE_1: + case LT3074_MFR_READ_VBIAS: + case LT3074_MFR_BIAS_OV_WARN_LIMIT: + case LT3074_MFR_BIAS_UV_WARN_LIMIT: + case LT3074_MFR_IOUT_MIN_WARN_LIMIT: + return lt3074_data2reg_linear11(dev, data, reg); + default: + return -EINVAL; + } +} + +/** + * @brief Converts the given register value to its actual data value. + * + * @param dev The LT3074 device structure. + * @param cmd The command value. + * @param reg The register value to be converted. + * @param data Pointer to store the converted data value. + * @return Returns 0 on success, or a negative error code on failure. + */ +static int lt3074_reg2data(struct lt3074_dev *dev, uint8_t cmd, + uint16_t reg, int *data) +{ + switch (cmd) { + case LT3074_VOUT_OV_WARN_LIMIT: + case LT3074_VOUT_UV_WARN_LIMIT: + case LT3074_READ_VOUT: + return lt3074_reg2data_linear16(dev, reg, data); + case LT3074_IOUT_OC_FAULT_LIMIT: + case LT3074_OT_WARN_LIMIT: + case LT3074_VIN_OV_WARN_LIMIT: + case LT3074_VIN_UV_WARN_LIMIT: + case LT3074_READ_VIN: + case LT3074_READ_IOUT: + case LT3074_READ_TEMPERATURE_1: + case LT3074_MFR_READ_VBIAS: + case LT3074_MFR_BIAS_OV_WARN_LIMIT: + case LT3074_MFR_BIAS_UV_WARN_LIMIT: + case LT3074_MFR_IOUT_MIN_WARN_LIMIT: + return lt3074_reg2data_linear11(dev, reg, data); + default: + return -EINVAL; + } +} + +/** + * @brief Perform packet-error checking via CRC + * + * @param dev The LT3074 device structure. + * @param cmd The command byte. + * @param buf Pointer to the data buffer. + * @param nbytes Number of bytes in the data buffer. + * @param op Operation performed. 0 for write, 1 for read + * @return The calculated PEC value. + */ +static uint8_t lt3074_pec(struct lt3074_dev *dev, uint8_t cmd, uint8_t *buf, + size_t nbytes, uint8_t op) +{ + uint8_t crc_buf[nbytes + op + 2]; + + crc_buf[0] = (dev->i2c_desc->slave_address << 1); + crc_buf[1] = cmd; + if (op) + crc_buf[2] = (dev->i2c_desc->slave_address << 1) | 1; + + memcpy(&crc_buf[2 + op], buf, nbytes); + + return no_os_crc8(lt3074_crc_table, crc_buf, nbytes + op + 2, 0); +} + +/** + * @brief Initialize the device structure + * + * @param device - Device structure + * @param init_param - Initialization parameters + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_init(struct lt3074_dev **device, + struct lt3074_init_param *init_param) +{ + struct lt3074_dev *dev; + int ret; + uint16_t word; + uint8_t block[7]; + + dev = (struct lt3074_dev *)no_os_calloc(1, sizeof(struct lt3074_dev)); + if (!dev) + return -ENOMEM; + + /* Initialize I2C */ + ret = no_os_i2c_init(&dev->i2c_desc, init_param->i2c_init); + if (ret) + goto i2c_err; + + /* Identify device */ + ret = lt3074_read_word(dev, LT3074_MFR_SPECIAL_ID, &word); + if (ret) + goto dev_err; + if (word != LT3074_SPECIAL_ID_VALUE) { + ret = -EIO; + goto dev_err; + } + + ret = lt3074_read_block_data(dev, LT3074_IC_DEVICE_ID, block, 6); + if (ret || (strncmp((char *)block, "LT3074", 6))) { + ret = -EIO; + goto dev_err; + } + + /* Set PEC */ + dev->crc_en = init_param->crc_en; + if (dev->crc_en) + no_os_crc8_populate_msb(lt3074_crc_table, + LT3074_CRC_POLYNOMIAL); + + dev->lin16_exp = LT3074_LIN16_EXPONENT; + + /* Initialize GPIO for PGOOD */ + ret = no_os_gpio_get_optional(&dev->pg_desc, + init_param->pg_param); + if (ret) + goto dev_err; + + ret = no_os_gpio_direction_input(dev->pg_desc); + if (ret) + goto dev_err; + + /* Initialize GPIO for EN */ + ret = no_os_gpio_get_optional(&dev->en_desc, + init_param->en_param); + if (ret) + goto dev_err; + + ret = no_os_gpio_direction_output(dev->en_desc, NO_OS_GPIO_HIGH); + if (ret) + goto dev_err; + + /* Initialize GPIO for ALERT */ + ret = no_os_gpio_get_optional(&dev->alert_desc, + init_param->alert_param); + if (ret) + goto dev_err; + + ret = no_os_gpio_direction_input(dev->alert_desc); + if (ret) + goto dev_err; + + /* Set operation */ + ret = lt3074_set_operation(dev, LT3074_OPERATION_ON); + if (ret) + goto dev_err; + + /* Clear faults */ + ret = lt3074_clear_faults(dev); + if (ret) + goto dev_err; + + *device = dev; + + return 0; + +dev_err: + no_os_i2c_remove(dev->i2c_desc); +i2c_err: + no_os_free(dev); + return ret; +} + +/** + * @brief Free or remove device instance + * + * @param dev - The device structure + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_remove(struct lt3074_dev *dev) +{ + int ret; + + ret = no_os_i2c_remove(dev->i2c_desc); + if (ret) + return ret; + + ret = no_os_gpio_remove(dev->pg_desc); + if (ret) + return ret; + + ret = no_os_gpio_remove(dev->en_desc); + if (ret) + return ret; + + ret = no_os_gpio_remove(dev->alert_desc); + if (ret) + return ret; + + no_os_free(dev); + + return ret; +} + +/** + * @brief Send a PMBus command to the device + * + * @param dev - Device structure + * @param cmd - PMBus command + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_send_byte(struct lt3074_dev *dev, uint8_t cmd) +{ + return no_os_i2c_write(dev->i2c_desc, &cmd, 1, 1); +} + +/** + * @brief Perform a raw PMBus read byte operation + * + * @param dev - Device structure + * @param cmd - PMBus command + * @param data - Address of the byte read + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_read_byte(struct lt3074_dev *dev, uint8_t cmd, uint8_t *data) +{ + int ret; + uint8_t rx_buf[2]; + + ret = no_os_i2c_write(dev->i2c_desc, &cmd, 1, 0); + if (ret) + return ret; + + if (dev->crc_en) { + ret = no_os_i2c_read(dev->i2c_desc, rx_buf, 2, 1); + if (ret) + return ret; + + if (lt3074_pec(dev, cmd, rx_buf, 1, 1) != rx_buf[1]) + return -EBADMSG; + + *data = rx_buf[0]; + return ret; + } else + return no_os_i2c_read(dev->i2c_desc, data, 1, 1); +} + +/** + * @brief Perform a raw PMBus write byte operation + * + * @param dev - Device structure + * @param cmd - PMBus command + * @param value - Byte to be written + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_write_byte(struct lt3074_dev *dev, uint8_t cmd, uint8_t value) +{ + uint8_t tx_buf[3] = {0}; + + tx_buf[0] = cmd; + tx_buf[1] = value; + + if (dev->crc_en) + tx_buf[2] = lt3074_pec(dev, cmd, &value, 1, 0); + + return no_os_i2c_write(dev->i2c_desc, tx_buf, dev->crc_en + 2, 1); +} + +/** + * @brief Perform a raw PMBus read word operation + * + * @param dev - Device structure + * @param cmd - PMBus command + * @param word - Address of the read word + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_read_word(struct lt3074_dev *dev, uint8_t cmd, uint16_t *word) +{ + int ret; + uint8_t rx_buf[3] = {0}; + + ret = no_os_i2c_write(dev->i2c_desc, &cmd, 1, 0); + if (ret) + return ret; + + if (dev->crc_en) { + ret = no_os_i2c_read(dev->i2c_desc, rx_buf, 3, 1); + if (ret) + return ret; + + if (lt3074_pec(dev, cmd, rx_buf, 2, 1) != rx_buf[2]) + return -EBADMSG; + } else { + ret = no_os_i2c_read(dev->i2c_desc, rx_buf, 2, 1); + if (ret) + return ret; + } + + *word = no_os_get_unaligned_le16(rx_buf); + return 0; +} + +/** + * @brief Perform a raw PMBus write word operation + * + * @param dev - Device structure + * @param cmd - PMBus command + * @param word - Word to write + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_write_word(struct lt3074_dev *dev, uint8_t cmd, uint16_t word) +{ + uint8_t tx_buf[4] = {0}; + + tx_buf[0] = cmd; + no_os_put_unaligned_le16(word, &tx_buf[1]); + + if (dev->crc_en) + tx_buf[3] = lt3074_pec(dev, cmd, &tx_buf[1], 2, 0); + + return no_os_i2c_write(dev->i2c_desc, tx_buf, dev->crc_en + 3, 1); +} + +/** + * @brief Perform a PMBus read word operation and converts to actual value + * + * @param dev - Device structure + * @param cmd - PMBus command + * @param data - Address of data read + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_read_word_data(struct lt3074_dev *dev, uint8_t cmd, int *data) +{ + int ret; + uint16_t reg; + + ret = lt3074_read_word(dev, cmd, ®); + if (ret) + return ret; + + return lt3074_reg2data(dev, cmd, reg, data); +} + +/** + * @brief Converts value to register data and do PMBus write word operation + * + * @param dev - Device structure + * @param cmd - PMBus command + * @param data - Value to write + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_write_word_data(struct lt3074_dev *dev, uint8_t cmd, int data) +{ + int ret; + uint16_t reg; + + ret = lt3074_data2reg(dev, cmd, data, ®); + if (ret) + return ret; + + return lt3074_write_word(dev, cmd, reg); +} + +/** + * @brief Perform a PMBus read block operation + * + * @param dev - Device structure + * @param cmd - PMBus command + * @param data - Address of the read block + * @param nbytes - Size of the block in bytes + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_read_block_data(struct lt3074_dev *dev, uint8_t cmd, + uint8_t *data, size_t nbytes) +{ + int ret; + uint8_t rxbuf[nbytes + 2]; + + ret = no_os_i2c_write(dev->i2c_desc, &cmd, 1, 0); + if (ret) + return ret; + + if (dev->crc_en) { + ret = no_os_i2c_read(dev->i2c_desc, rxbuf, nbytes + 2, 1); + if (ret) + return ret; + + if ((size_t)rxbuf[0] > nbytes) + return -EMSGSIZE; + + if (lt3074_pec(dev, cmd, rxbuf, nbytes + 1, 1) != + rxbuf[nbytes + 1]) + return -EBADMSG; + + memcpy(data, &rxbuf[1], nbytes); + } else { + ret = no_os_i2c_read(dev->i2c_desc, rxbuf, nbytes + 1, 1); + if (ret) + return ret; + + if ((size_t)rxbuf[0] > nbytes) + return -EMSGSIZE; + + memcpy(data, &rxbuf[1], nbytes); + } + + return 0; +} + +/** + * @brief Read a value + * + * @param dev - Device structure + * @param value_type - Value type. + * Example values: LT3074_VIN + * LT3074_VOUT + * LT3074_IOUT + * LT3074_TEMP + * LT3074_VBIAS + * @param value - Address of the read value + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_read_value(struct lt3074_dev *dev, + enum lt3074_value_type value_type, + int *value) +{ + return lt3074_read_word_data(dev, (uint8_t)value_type, value); +} + +/** + * @brief Read statuses + * + * @param dev - Device structure + * @param status_type - Status type. + * Example values: LT3074_STATUS_BYTE_TYPE + * LT3074_STATUS_VOUT_TYPE + * LT3074_STATUS_IOUT_TYPE + * LT3074_STATUS_INPUT_TYPE + * LT3074_STATUS_CML_TYPE + * @param status - Address of the status structure + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_read_status(struct lt3074_dev *dev, + enum lt3074_status_type status_type, + struct lt3074_status *status) +{ + int ret; + + if (status_type & LT3074_STATUS_WORD_TYPE) { + ret = lt3074_read_word(dev, LT3074_STATUS_WORD, + &status->word); + if (ret) + return ret; + } + + if (status_type & LT3074_STATUS_BYTE_TYPE) { + ret = lt3074_read_byte(dev, LT3074_STATUS_BYTE, + &status->byte); + if (ret) + return ret; + } + + if (status_type & LT3074_STATUS_VOUT_TYPE) { + ret = lt3074_read_byte(dev, LT3074_STATUS_VOUT, + &status->vout); + if (ret) + return ret; + } + + if (status_type & LT3074_STATUS_IOUT_TYPE) { + ret = lt3074_read_byte(dev, LT3074_STATUS_IOUT, + &status->iout); + if (ret) + return ret; + } + + if (status_type & LT3074_STATUS_INPUT_TYPE) { + ret = lt3074_read_byte(dev, LT3074_STATUS_INPUT, + &status->input); + if (ret) + return ret; + } + + if (status_type & LT3074_STATUS_TEMP_TYPE) { + ret = lt3074_read_byte(dev, LT3074_STATUS_TEMPERATURE, + &status->temp); + if (ret) + return ret; + } + + if (status_type & LT3074_STATUS_CML_TYPE) { + ret = lt3074_read_byte(dev, LT3074_STATUS_CML, + &status->cml); + if (ret) + return ret; + } + + if (status_type & LT3074_STATUS_MFR_SPECIFIC_TYPE) { + ret = lt3074_read_byte(dev, LT3074_STATUS_MFR_SPECIFIC, + &status->mfr_specific); + if (ret) + return ret; + } + + return 0; +} + +/** + * @brief Set output voltage margin + * + * @param dev - Device structure + * @param margin_high - Upper margin + * @param margin_low - Lower margin + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_vout_margin(struct lt3074_dev *dev, enum lt3074_margin margin_high, + enum lt3074_margin margin_low) +{ + uint8_t raw_data; + + raw_data = no_os_field_prep(LT3074_MARGIN_LOW_MSK, margin_high) | + no_os_field_prep(LT3074_MARGIN_HIGH_MSK, margin_low); + + return lt3074_write_byte(dev, LT3074_MFR_MARGIN, raw_data); +} + +/** + * @brief Sets the limit value for a specific fault/warning limits. + * + * @param dev - Device structure + * @param limit - The type of limit to set. + * @param limit_val - The value to set for the specified limit type. + * @return Returns 0 on success, or a negative error code on failure. + */ +int lt3074_set_limit(struct lt3074_dev *dev, enum lt3074_limit_type limit, + int limit_val) +{ + return lt3074_write_word_data(dev, (uint8_t)limit, limit_val); +} + +/** + * @brief Set operation. + * + * @param dev - Device structure + * @param operation - Operation. + * Accepted values are: LT3074_OPERATION_OFF + * LT3074_OPERATION_ON + * LT3074_OPERATION_MARGIN_HIGH + * LT3074_OPERATION_MARGIN_LOW + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_set_operation(struct lt3074_dev *dev, + enum lt3074_operation_type operation) +{ + int ret; + uint8_t temp; + + ret = lt3074_read_byte(dev, LT3074_OPERATION, &temp); + if (ret) + return ret; + + temp &= ~LT3074_OPERATION_ACCESS_MSK; + temp |= operation; + + return lt3074_write_byte(dev, LT3074_OPERATION, temp); +} + +/** + * @brief Clear status registers. + * + * @param dev - Device structure + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_clear_faults(struct lt3074_dev *dev) +{ + return lt3074_send_byte(dev, LT3074_CLEAR_FAULTS); +} + +/** + * @brief Enable/Disable the device using the EN pin. + * + * @param dev - Device structure + * @param state - Enable/Disable state. 0 for disable, 1 for enable. + * + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_set_enable_pin(struct lt3074_dev *dev, bool state) +{ + return no_os_gpio_direction_output(dev->en_desc, state); +} + +/** + * @brief Perform a device software reset + * + * @param dev - Device structure + * @return 0 in case of success, negative error code otherwise + */ +int lt3074_software_reset(struct lt3074_dev *dev) +{ + return lt3074_send_byte(dev, LT3074_MFR_RESET); +} diff --git a/drivers/power/lt3074/lt3074.h b/drivers/power/lt3074/lt3074.h new file mode 100644 index 00000000000..9c7cc4ed820 --- /dev/null +++ b/drivers/power/lt3074/lt3074.h @@ -0,0 +1,256 @@ +/******************************************************************************* +* @file lt3074.h +* @brief Header file of the LT3074 Driver +* @authors Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#ifndef __LT3074_H__ +#define __LT3074_H__ + +#include +#include +#include "no_os_util.h" +#include "no_os_i2c.h" + +/* PMBus commands */ +#define LT3074_PAGE 0x00 +#define LT3074_OPERATION 0x01 +#define LT3074_ON_OFF_CONFIG 0x02 +#define LT3074_CLEAR_FAULTS 0x03 +#define LT3074_WRITE_PROTECT 0x10 +#define LT3074_CAPABILITY 0x19 +#define LT3074_VOUT_MODE 0x20 +#define LT3074_VOUT_OV_WARN_LIMIT 0x42 +#define LT3074_VOUT_UV_WARN_LIMIT 0x43 +#define LT3074_IOUT_OC_FAULT_LIMIT 0x46 +#define LT3074_IOUT_OC_FAULT_RESPONSE 0x47 +#define LT3074_OT_WARN_LIMIT 0x51 +#define LT3074_VIN_OV_WARN_LIMIT 0x57 +#define LT3074_VIN_UV_WARN_LIMIT 0x58 +#define LT3074_STATUS_BYTE 0x78 +#define LT3074_STATUS_WORD 0x79 +#define LT3074_STATUS_VOUT 0x7A +#define LT3074_STATUS_IOUT 0x7B +#define LT3074_STATUS_INPUT 0x7C +#define LT3074_STATUS_TEMPERATURE 0x7D +#define LT3074_STATUS_CML 0x7E +#define LT3074_STATUS_MFR_SPECIFIC 0x80 +#define LT3074_READ_VIN 0x88 +#define LT3074_READ_VOUT 0x8B +#define LT3074_READ_IOUT 0x8C +#define LT3074_READ_TEMPERATURE_1 0x8D +#define LT3074_REVISION 0x98 +#define LT3074_IC_DEVICE_ID 0xAD +#define LT3074_IC_DEVICE_REV 0xAE + +/* Manufacturer registers */ +#define LT3074_MFR_MARGIN 0xC4 +#define LT3074_MFR_READ_VBIAS 0xC6 +#define LT3074_MFR_BIAS_OV_WARN_LIMIT 0xC7 +#define LT3074_MFR_BIAS_UV_WARN_LIMIT 0xC8 +#define LT3074_MFR_IOUT_MIN_WARN_LIMIT 0xC9 +#define LT3074_MFR_SPECIAL_ID 0xE7 +#define LT3074_MFR_DEFAULT_CONFIG 0xF5 +#define LT3074_MFR_RAIL_ADDRESS 0xFA +#define LT3074_MFR_RESET 0xFD + +/* PMBus-specific parameters */ +#define LT3074_CRC_POLYNOMIAL 0x7 +#define LT3074_MARGIN_HIGH_MSK 0xF0 +#define LT3074_MARGIN_LOW_MSK 0x0F +#define LT3074_OPERATION_ACCESS_MSK (NO_OS_GENMASK(5,4) | NO_OS_BIT(7)) +#define LT3074_SPECIAL_ID_VALUE 0x1C1D + +/* Status types masks */ +#define LT3074_STATUS_BYTE_TYPE_MSK 0x01 +#define LT3074_STATUS_VOUT_TYPE_MSK 0x02 +#define LT3074_STATUS_IOUT_TYPE_MSK 0x04 +#define LT3074_STATUS_INPUT_TYPE_MSK 0x08 +#define LT3074_STATUS_TEMP_TYPE_MSK 0x10 +#define LT3074_STATUS_CML_TYPE_MSK 0x20 +#define LT3074_STATUS_MFR_SPECIFIC_TYPE_MSK 0x40 +#define LT3074_STATUS_WORD_TYPE_MSK 0x80 +#define LT3074_STATUS_ALL_TYPE_MSK 0xFF + +/* LINEAR data format params */ +#define LT3074_LIN11_MANTISSA_MAX 1023000L +#define LT3074_LIN11_MANTISSA_MIN 511000L +#define LT3074_LIN11_EXPONENT_MAX 15 +#define LT3074_LIN11_EXPONENT_MIN -15 +#define LT3074_LIN11_MANTISSA_MSK NO_OS_GENMASK(10,0) +#define LT3074_LIN11_EXPONENT_MSK NO_OS_GENMASK(15,11) +#define LT3074_LIN11_EXPONENT(x) ((int16_t)(x) >> 11) +#define LT3074_LIN11_MANTISSA(x) (((int16_t)((x & 0x7FF) << 5)) >> 5) +#define LT3074_LIN16_EXPONENT -13 + +enum lt3074_operation_type { + LT3074_OPERATION_OFF, + LT3074_OPERATION_ON = 0x80, + LT3074_OPERATION_MARGIN_HIGH = 0xA0, + LT3074_OPERATION_MARGIN_LOW = 0x90, +}; + +enum lt3074_value_type { + LT3074_VIN = LT3074_READ_VIN, + LT3074_VOUT = LT3074_READ_VOUT, + LT3074_IOUT = LT3074_READ_IOUT, + LT3074_TEMP = LT3074_READ_TEMPERATURE_1, + LT3074_VBIAS = LT3074_MFR_READ_VBIAS, +}; + +enum lt3074_limit_type { + LT3074_VOUT_OV_WARN_LIMIT_TYPE = LT3074_VOUT_OV_WARN_LIMIT, + LT3074_VOUT_UV_WARN_LIMIT_TYPE = LT3074_VOUT_UV_WARN_LIMIT, + LT3074_IOUT_OC_FAULT_LIMIT_TYPE = LT3074_IOUT_OC_FAULT_LIMIT, + LT3074_OT_WARN_LIMIT_TYPE = LT3074_OT_WARN_LIMIT, + LT3074_VIN_OV_WARN_LIMIT_TYPE = LT3074_VIN_OV_WARN_LIMIT, + LT3074_VIN_UV_WARN_LIMIT_TYPE = LT3074_VIN_UV_WARN_LIMIT, + LT3074_VBIAS_OV_WARN_LIMIT_TYPE = LT3074_MFR_BIAS_OV_WARN_LIMIT, + LT3074_VBIAS_UV_WARN_LIMIT_TYPE = LT3074_MFR_BIAS_UV_WARN_LIMIT, + LT3074_IOUT_MIN_WARN_LIMIT_TYPE = LT3074_MFR_IOUT_MIN_WARN_LIMIT, +}; + +enum lt3074_status_type { + LT3074_STATUS_BYTE_TYPE = LT3074_STATUS_BYTE_TYPE_MSK, + LT3074_STATUS_VOUT_TYPE = LT3074_STATUS_VOUT_TYPE_MSK, + LT3074_STATUS_IOUT_TYPE = LT3074_STATUS_IOUT_TYPE_MSK, + LT3074_STATUS_INPUT_TYPE = LT3074_STATUS_INPUT_TYPE_MSK, + LT3074_STATUS_TEMP_TYPE = LT3074_STATUS_TEMP_TYPE_MSK, + LT3074_STATUS_CML_TYPE = LT3074_STATUS_CML_TYPE_MSK, + LT3074_STATUS_MFR_SPECIFIC_TYPE = LT3074_STATUS_MFR_SPECIFIC_TYPE_MSK, + LT3074_STATUS_WORD_TYPE = LT3074_STATUS_WORD_TYPE_MSK, + LT3074_STATUS_ALL_TYPE = LT3074_STATUS_ALL_TYPE_MSK, +}; + +enum lt3074_margin { + LT3074_MARGIN_PERCENTAGE_0, + LT3074_MARGIN_PERCENTAGE_1, + LT3074_MARGIN_PERCENTAGE_3, + LT3074_MARGIN_PERCENTAGE_5, + LT3074_MARGIN_PERCENTAGE_10, + LT3074_MARGIN_PERCENTAGE_15, + LT3074_MARGIN_PERCENTAGE_20, + LT3074_MARGIN_PERCENTAGE_25, + LT3074_MARGIN_PERCENTAGE_30, +}; + +struct lt3074_dev { + struct no_os_i2c_desc *i2c_desc; + struct no_os_gpio_desc *pg_desc; + struct no_os_gpio_desc *en_desc; + struct no_os_gpio_desc *alert_desc; + + int lin16_exp; + bool crc_en; +}; + +struct lt3074_init_param { + struct no_os_i2c_init_param *i2c_init; + struct no_os_gpio_init_param *pg_param; + struct no_os_gpio_init_param *en_param; + struct no_os_gpio_init_param *alert_param; + + bool crc_en; +}; + +struct lt3074_status { + uint16_t word; + uint8_t byte; + uint8_t vout; + uint8_t iout; + uint8_t input; + uint8_t temp; + uint8_t cml; + uint8_t mfr_specific; +}; + +/* Initialize the device structure */ +int lt3074_init(struct lt3074_dev **dev, + struct lt3074_init_param *init_param); + +/* Free or remove device instance */ +int lt3074_remove(struct lt3074_dev *dev); + +/* Send a PMBus command to the device */ +int lt3074_send_byte(struct lt3074_dev *dev, uint8_t cmd); + +/* Perform a PMBus read_byte operation */ +int lt3074_read_byte(struct lt3074_dev *dev, uint8_t cmd, uint8_t *data); + +/* Perform a PMBus write_byte operation */ +int lt3074_write_byte(struct lt3074_dev *dev, uint8_t cmd, uint8_t value); + +/* Perform a PMBus read_word operation */ +int lt3074_read_word(struct lt3074_dev *dev, uint8_t cmd, uint16_t *word); + +/* Perform a PMBus write_word operation */ +int lt3074_write_word(struct lt3074_dev *dev, uint8_t cmd, uint16_t word); + +/* Perform a PMBus read_word operation then perform conversion*/ +int lt3074_read_word_data(struct lt3074_dev *dev, uint8_t cmd, int *data); + +/* Perform conversion then perform a PMBus write_word operation */ +int lt3074_write_word_data(struct lt3074_dev *dev, uint8_t cmd, int data); + +/* Read a block of bytes */ +int lt3074_read_block_data(struct lt3074_dev *dev, uint8_t cmd, + uint8_t *data, size_t nbytes); + +/* Read specific value type */ +int lt3074_read_value(struct lt3074_dev *dev, + enum lt3074_value_type value_type, + int *value); + +/* Read status */ +int lt3074_read_status(struct lt3074_dev *dev, + enum lt3074_status_type status_type, + struct lt3074_status *status); + +/* Set VOUT margins */ +int lt3074_vout_margin(struct lt3074_dev *dev, enum lt3074_margin margin_high, + enum lt3074_margin margin_low); + +/* Set fault/warning limit values */ +int lt3074_set_limit(struct lt3074_dev *dev, enum lt3074_limit_type limit, + int limit_val); + +/* Set operation */ +int lt3074_set_operation(struct lt3074_dev *dev, + enum lt3074_operation_type operation); + +/* Clear status registers */ +int lt3074_clear_faults(struct lt3074_dev *dev); + +/* Turn output ON/OFF */ +int lt3074_set_enable_pin(struct lt3074_dev *dev, bool state); + +/* Software reset */ +int lt3074_software_reset(struct lt3074_dev *dev); + +#endif /* __LT3074_H__ */ diff --git a/projects/lt3074/Makefile b/projects/lt3074/Makefile new file mode 100644 index 00000000000..ea22697a376 --- /dev/null +++ b/projects/lt3074/Makefile @@ -0,0 +1,9 @@ +# Select the example you want to enable by choosing y for enabling and n for disabling +BASIC_EXAMPLE = n +IIO_EXAMPLE = y + +include ../../tools/scripts/generic_variables.mk + +include src.mk + +include ../../tools/scripts/generic.mk diff --git a/projects/lt3074/README.rst b/projects/lt3074/README.rst new file mode 100644 index 00000000000..f40701c2f10 --- /dev/null +++ b/projects/lt3074/README.rst @@ -0,0 +1,176 @@ +Evaluating the LT3074 +====================== + + +Contents +-------- + +.. contents:: Table of Contents + :depth: 3 + +Supported Evaluation Boards +--------------------------- + +* `EVAL-LT3074 `_ + +Overview +-------- + +The EVAL-LT3074-AZ evaluation board features the LT3074, a 3A, ultralow noise, +high power-supply rejection ratio (PSRR), 45mV dropout ultrafast linear +regulator with PMBus capability. The evaluation board allows the LT3074 to be +configured without the use of external components. + +Full performance details are provided in the LT3074 data sheet, which should +be consulted in conjunction with user guide. + +Hardware Specifications +----------------------- + +Power Supply Requirements +^^^^^^^^^^^^^^^^^^^^^^^^^ + +An external power supply between 2.4V to 5.5V can be used for this project. + +**Pin Description** + + J11: + + +-----+----------+-------------------------------------------+ + | Pin | Name | Description | + +-----+----------+-------------------------------------------+ + | 1 | VDD3P3 | Do Not Connect | + +-----+----------+-------------------------------------------+ + | 2 | GND | Connect to Ground | + +-----+----------+-------------------------------------------+ + | 3 | SDA | I2C Serial Data | + +-----+----------+-------------------------------------------+ + | 4 | SCL | I2C Serial Clock | + +-----+----------+-------------------------------------------+ + | 5 | EN | Do Not Connect | + +-----+----------+-------------------------------------------+ + | 6 | ALERT | Do Not Connect | + +-----+----------+-------------------------------------------+ + + Other connections: + + +-----+----------+-------------------------------------------+ + | Pin | Name | Description | + +-----+----------+-------------------------------------------+ + | 1 | VI+ | Power Supply, +2.4V - +5.5V | + +-----+----------+-------------------------------------------+ + | 2 | GND | Ground | + +-----+----------+-------------------------------------------+ + | 3 | EXTVBIAS | Power Supply, +2.4V - +5.5V | + +-----+----------+-------------------------------------------+ + | 4 | VOUT | Connect to Load | + +-----+----------+-------------------------------------------+ + | 5 | POWERGOOD| Do Not Connect | + +-----+----------+-------------------------------------------+ + + +No-OS Build Setup +----------------- + +Please see: https://wiki.analog.com/resources/no-os/build + +No-OS Supported Examples +------------------------ + +The initialization data used in the examples is taken out from: +`Project Common Data Path `_ + +The macros used in Common Data are defined in platform specific files found in: +`Project Platform Configuration Path `_ + +Basic example +^^^^^^^^^^^^^ + +This is a simple example that initializes the LT3074, sets the output margin and +a warning limit, and performs telemetry. + +In order to build the basic example make sure you have the following configuration in the Makefile +`Makefile `_ + +.. code-block:: bash + + # Select the example you want to enable by choosing y for enabling and n for disabling + BASIC_EXAMPLE = y + IIO_EXAMPLE = n + +IIO example +^^^^^^^^^^^ + +This project is actually a IIOD demo for EVAL-LT3074 evaluation board. +The project launches a IIOD server on the board so that the user may connect +to it via an IIO client. +Using IIO-Oscilloscope, the user can configure the IMU and view the measured data on a plot. + +If you are not familiar with ADI IIO Application, please take a look at: +`IIO No-OS `_ + +If you are not familiar with ADI IIO-Oscilloscope Client, please take a look at: +`IIO Oscilloscope `_ + +The No-OS IIO Application together with the No-OS IIO LT3074 driver take care of +all the back-end logic needed to setup the IIO server. + +This example initializes the IIO device and calls the IIO app as shown in: +`IIO Example `_ + +In order to build the IIO project make sure you have the following configuration in the +`Makefile `_ + +.. code-block:: bash + + # Select the example you want to enable by choosing y for enabling and n for disabling + BASIC_EXAMPLE = n + IIO__EXAMPLE = y + +No-OS Supported Platforms +------------------------- + +Maxim Platform +^^^^^^^^^^^^^^ + +**Used hardware** + +* `EVAL-LT3074 evaluation board `_ +* `MAX32666EVKIT `_ + +**Connections**: + +J11: + ++-----------------------------+------------+----------------------------------------------+-----------------------------+ +| EVAL-LT3074 Pin Number | Mnemonic | Function | MAX32666EVKIT Pin Number | ++-----------------------------+------------+----------------------------------------------+-----------------------------+ +| 2 | GND | Ground | GND | ++-----------------------------+------------+----------------------------------------------+-----------------------------+ +| 3 | SDA | External Power Supply, 12VDC (5mA current) | P0.15 | ++-----------------------------+------------+----------------------------------------------+-----------------------------+ +| 4 | SCL | External Power Supply, 20.1VDC (5mA current) | P0.14 | ++-----------------------------+------------+----------------------------------------------+-----------------------------+ +| 5 | EN | Enable pin | Do Not Connect | ++-----------------------------+------------+----------------------------------------------+-----------------------------+ +| 6 | ALERT | Fault alert pin | Do Not Connect | ++-----------------------------+------------+----------------------------------------------+-----------------------------+ + +Other connection: + ++-----------------------------+------------+----------------------------------------------+-----------------------------+ +| EVAL-LT3074 Pin Number | Mnemonic | Function | MAX32666EVKIT Pin Number | ++-----------------------------+------------+----------------------------------------------+-----------------------------+ +| 5 | POWERGOOD | Power Good | Do Not Connect | ++-----------------------------+------------+----------------------------------------------+-----------------------------+ + +**Build Command** + +.. code-block:: bash + + # to delete current build + make reset + # to build the project + make PLATFORM=maxim TARGET=max32665 + # to flash the code + make run diff --git a/projects/lt3074/builds.json b/projects/lt3074/builds.json new file mode 100644 index 00000000000..71195bc2bb8 --- /dev/null +++ b/projects/lt3074/builds.json @@ -0,0 +1,10 @@ +{ + "maxim": { + "basic_example_max32666": { + "flags" : "BASIC_EXAMPLE=y IIO_EXAMPLE=n TARGET=max32665" + }, + "iio_example_max32666": { + "flags" : "BASIC_EXAMPLE=n IIO_EXAMPLE=y TARGET=max32665" + } + } +} diff --git a/projects/lt3074/src.mk b/projects/lt3074/src.mk new file mode 100644 index 00000000000..ae9a978e2af --- /dev/null +++ b/projects/lt3074/src.mk @@ -0,0 +1,25 @@ +include $(PROJECT)/src/platform/$(PLATFORM)/platform_src.mk +include $(PROJECT)/src/examples/examples_src.mk + +NO_OS_INC_DIRS += \ + $(INCLUDE) \ + $(PROJECT)/src/ \ + $(DRIVERS)/api/ \ + $(DRIVERS)/power/lt3074/ + +SRCS += $(PROJECT)/src/platform/$(PLATFORM)/main.c \ + $(PROJECT)/src/common/common_data.c \ + $(PROJECT)/src/platform/$(PLATFORM)/parameters.c \ + $(NO-OS)/util/no_os_lf256fifo.c \ + $(DRIVERS)/api/no_os_i2c.c \ + $(DRIVERS)/api/no_os_dma.c \ + $(DRIVERS)/api/no_os_uart.c \ + $(DRIVERS)/api/no_os_irq.c \ + $(DRIVERS)/api/no_os_gpio.c \ + $(DRIVERS)/api/no_os_pwm.c \ + $(DRIVERS)/power/lt3074/lt3074.c \ + $(NO-OS)/util/no_os_util.c \ + $(NO-OS)/util/no_os_list.c \ + $(NO-OS)/util/no_os_alloc.c \ + $(NO-OS)/util/no_os_mutex.c \ + $(NO-OS)/util/no_os_crc8.c diff --git a/projects/lt3074/src/common/common_data.c b/projects/lt3074/src/common/common_data.c new file mode 100644 index 00000000000..48595a7d526 --- /dev/null +++ b/projects/lt3074/src/common/common_data.c @@ -0,0 +1,61 @@ +/***************************************************************************//** +* @file common_data.c +* @brief Defines common data to be used by lt3074 examples. +* @author Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#include "common_data.h" + +struct no_os_uart_init_param lt3074_uart_ip = { + .device_id = UART_DEVICE_ID, + .irq_id = UART_IRQ_ID, + .asynchronous_rx = true, + .baud_rate = UART_BAUDRATE, + .size = NO_OS_UART_CS_8, + .parity = NO_OS_UART_PAR_NO, + .stop = NO_OS_UART_STOP_1_BIT, + .platform_ops = UART_OPS, + .extra = UART_EXTRA, +}; + +struct no_os_i2c_init_param lt3074_i2c_ip = { + .device_id = I2C_DEVICE_ID, + .max_speed_hz = 100000, + .platform_ops = I2C_OPS, + .slave_address = LT3074_PMBUS_59K_261K_ADDRESS, + .extra = I2C_EXTRA, +}; + +struct lt3074_init_param lt3074_ip = { + .i2c_init = <3074_i2c_ip, + .pg_param = NULL, + .en_param = NULL, + .alert_param = NULL, + .crc_en = true +}; diff --git a/projects/lt3074/src/common/common_data.h b/projects/lt3074/src/common/common_data.h new file mode 100644 index 00000000000..a9435fb983a --- /dev/null +++ b/projects/lt3074/src/common/common_data.h @@ -0,0 +1,46 @@ +/***************************************************************************//** +* @file common_data.h +* @brief Defines common data to be used by lt3074 examples. +* @author Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#ifndef __COMMON_DATA_H__ +#define __COMMON_DATA_H__ + +#include "platform_includes.h" +#include "no_os_i2c.h" +#include "lt3074.h" + +#define LT3074_PMBUS_59K_261K_ADDRESS 0x6E + +extern struct no_os_uart_init_param lt3074_uart_ip; +extern struct no_os_i2c_init_param lt3074_i2c_ip; +extern struct lt3074_init_param lt3074_ip; + +#endif /* __COMMON_DATA_H__ */ diff --git a/projects/lt3074/src/examples/basic/basic_example.c b/projects/lt3074/src/examples/basic/basic_example.c new file mode 100644 index 00000000000..58f300573ce --- /dev/null +++ b/projects/lt3074/src/examples/basic/basic_example.c @@ -0,0 +1,107 @@ +/***************************************************************************//** +* @file basic_example.c +* @brief Basic example source file for lt3074 project. +* @author Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#include "common_data.h" +#include "basic_example.h" +#include "no_os_delay.h" +#include "no_os_print_log.h" +#include "lt3074.h" + +int basic_example_main() +{ + int ret; + + struct lt3074_dev *dev; + struct lt3074_status status; + int vals[5]; + + pr_info("Running basic example.\n"); + + ret = lt3074_init(&dev, <3074_ip); + if (ret) + goto exit; + + ret = lt3074_vout_margin(dev, LT3074_MARGIN_PERCENTAGE_10, + LT3074_MARGIN_PERCENTAGE_10); + if (ret) + goto exit; + + ret = lt3074_set_limit(dev, LT3074_VIN_OV_WARN_LIMIT_TYPE, 4500); + if (ret) + goto exit; + + while (1) { + ret = lt3074_read_value(dev, LT3074_VIN, &vals[0]); + if (ret) + goto exit; + + ret = lt3074_read_value(dev, LT3074_VOUT, &vals[1]); + if (ret) + goto exit; + + ret = lt3074_read_value(dev, LT3074_VBIAS, &vals[2]); + if (ret) + goto exit; + + ret = lt3074_read_value(dev, LT3074_IOUT, &vals[3]); + if (ret) + goto exit; + + ret = lt3074_read_value(dev, LT3074_TEMP, &vals[4]); + if (ret) + goto exit; + + ret = lt3074_read_status(dev, LT3074_STATUS_ALL_TYPE, &status); + if (status.vout) + pr_info("Status vout asserted.\n"); + if (status.iout) + pr_info("Status iout asserted.\n"); + if (status.input) + pr_info("Status input asserted.\n"); + if (status.temp) + pr_info("Status temp asserted.\n"); + if (status.cml) + pr_info("Status cml asserted.\n"); + if (status.mfr_specific) + pr_info("Status mfr_specific asserted.\n"); + + pr_info("vin = %d mV | vout = %d mV | vbias = %d mV | iout = %d mA | temp = %d C\n", + vals[0], vals[1], vals[2], vals[3], vals[4] / 1000); + + no_os_mdelay(500); + } + +exit: + pr_err("Error code: %d.\n", ret); + lt3074_remove(dev); + return ret; +} diff --git a/projects/lt3074/src/examples/basic/basic_example.h b/projects/lt3074/src/examples/basic/basic_example.h new file mode 100644 index 00000000000..097418318f6 --- /dev/null +++ b/projects/lt3074/src/examples/basic/basic_example.h @@ -0,0 +1,38 @@ +/***************************************************************************//** +* @file basic_example.h +* @brief Basic example header file for lt3074 project. +* @author Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#ifndef __BASIC_EXAMPLE_H__ +#define __BASIC_EXAMPLE_H__ + +int basic_example_main(); + +#endif /* __BASIC_EXAMPLE_H__ */ diff --git a/projects/lt3074/src/examples/examples_src.mk b/projects/lt3074/src/examples/examples_src.mk new file mode 100644 index 00000000000..77fe66d737d --- /dev/null +++ b/projects/lt3074/src/examples/examples_src.mk @@ -0,0 +1,22 @@ +ifeq (y,$(strip $(IIO_EXAMPLE))) +IIOD=y +CFLAGS += -DIIO_EXAMPLE=1 +SRCS += $(PROJECT)/src/examples/iio_example/iio_example.c +endif + +ifeq (y,$(strip $(BASIC_EXAMPLE))) +CFLAGS += -DBASIC_EXAMPLE=1 +SRCS += $(PROJECT)/src/examples/basic/basic_example.c +endif + +ifeq (y, $(strip $(IIOD))) +LIBRARIES += iio +NO_OS_INC_DIRS += \ + $(NO-OS)/iio/ + +SRCS += $(NO-OS)/iio/iio_app/iio_app.c \ + $(DRIVERS)/power/lt3074/iio_lt3074.c \ + $(NO-OS)/iio/iio.c \ + $(NO-OS)/iio/iiod.c \ + $(NO-OS)/util/no_os_fifo.c +endif diff --git a/projects/lt3074/src/examples/iio_example/iio_example.c b/projects/lt3074/src/examples/iio_example/iio_example.c new file mode 100644 index 00000000000..ad7637ff668 --- /dev/null +++ b/projects/lt3074/src/examples/iio_example/iio_example.c @@ -0,0 +1,81 @@ +/***************************************************************************//** +* @file iio_example.c +* @brief IIO example source file for lt3074 project. +* @author Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#include "iio_example.h" +#include "iio_lt3074.h" +#include "common_data.h" +#include "no_os_print_log.h" +#include "iio_app.h" + +int iio_example_main() +{ + int ret; + + struct lt3074_iio_desc *lt3074_iio_desc; + struct lt3074_iio_desc_init_param lt3074_iio_ip = { + .lt3074_init_param = <3074_ip, + }; + + struct iio_app_desc *app; + struct iio_app_init_param app_init_param = { 0 }; + + ret = lt3074_iio_init(<3074_iio_desc, <3074_iio_ip); + if (ret) + goto exit; + + struct iio_app_device iio_devices[] = { + { + .name = "lt3074", + .dev = lt3074_iio_desc, + .dev_descriptor = lt3074_iio_desc->iio_dev, + } + }; + + app_init_param.devices = iio_devices; + app_init_param.nb_devices = NO_OS_ARRAY_SIZE(iio_devices); + app_init_param.uart_init_params = lt3074_uart_ip; + + ret = iio_app_init(&app, app_init_param); + if (ret) + goto remove_iio_lt3074; + + ret = iio_app_run(app); + + iio_app_remove(app); + +remove_iio_lt3074: + lt3074_iio_remove(lt3074_iio_desc); +exit: + if (ret) + pr_info("Error!\n"); + return ret; +} diff --git a/projects/lt3074/src/examples/iio_example/iio_example.h b/projects/lt3074/src/examples/iio_example/iio_example.h new file mode 100644 index 00000000000..7546269e5a2 --- /dev/null +++ b/projects/lt3074/src/examples/iio_example/iio_example.h @@ -0,0 +1,38 @@ +/***************************************************************************//** +* @file iio_example.h +* @brief IIO example header file for lt3074 project. +* @author Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#ifndef __IIO_EXAMPLE_H__ +#define __IIO_EXAMPLE_H__ + +int iio_example_main(); + +#endif /* __IIO_EXAMPLE_H__ */ diff --git a/projects/lt3074/src/platform/maxim/main.c b/projects/lt3074/src/platform/maxim/main.c new file mode 100644 index 00000000000..b22d7f0d4af --- /dev/null +++ b/projects/lt3074/src/platform/maxim/main.c @@ -0,0 +1,72 @@ +/***************************************************************************//** +* @file main.c +* @brief Main file for Maxim platform of lt3074 project. +* @author Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#include "platform_includes.h" +#include "common_data.h" +#include "no_os_error.h" + +#ifdef BASIC_EXAMPLE +#include "basic_example.h" +#endif + +#ifdef IIO_EXAMPLE +#include "iio_example.h" +#endif + +int main() +{ + int ret = -EINVAL; + +#ifdef BASIC_EXAMPLE + struct no_os_uart_desc *uart_desc; + + ret = no_os_uart_init(&uart_desc, <3074_uart_ip); + if (ret) + return ret; + + no_os_uart_stdio(uart_desc); + ret = basic_example_main(); +#endif + +#ifdef IIO_EXAMPLE + ret = iio_example_main(); +#endif + +#if (BASIC_EXAMPLE + IIO_EXAMPLE == 0) +#error At least one example has to be selected using y value in Makefile. +#elif (BASIC_EXAMPLE + IIO_EXAMPLE > 1) +#error Selected example projects cannot be enabled at the same time. \ +Please enable only one example and re - build the project. +#endif + + return ret; +} diff --git a/projects/lt3074/src/platform/maxim/parameters.c b/projects/lt3074/src/platform/maxim/parameters.c new file mode 100644 index 00000000000..aeb81471104 --- /dev/null +++ b/projects/lt3074/src/platform/maxim/parameters.c @@ -0,0 +1,42 @@ +/***************************************************************************//** +* @file parameters.c +* @brief Definition of Maxim platform data used by lt3074 project. +* @author Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#include "parameters.h" + +struct max_uart_init_param lt3074_uart_extra = { + .flow = UART_FLOW_DIS, + .map = UART_MAP_A +}; + +struct max_i2c_init_param lt3074_i2c_extra = { + .vssel = MXC_GPIO_VSSEL_VDDIOH +}; diff --git a/projects/lt3074/src/platform/maxim/parameters.h b/projects/lt3074/src/platform/maxim/parameters.h new file mode 100644 index 00000000000..5c1a41b4427 --- /dev/null +++ b/projects/lt3074/src/platform/maxim/parameters.h @@ -0,0 +1,59 @@ +/***************************************************************************//** +* @file parameters.h +* @brief Definition of Maxim platform data used by lt3074 project. +* @author Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#ifndef __PARAMETERS_H__ +#define __PARAMETERS_H__ + +#include "maxim_irq.h" +#include "maxim_i2c.h" +#include "maxim_gpio.h" +#include "maxim_uart.h" +#include "maxim_uart_stdio.h" + +#ifdef IIO_SUPPORT +#define INTC_DEVICE_ID 0 +#endif + +#define UART_DEVICE_ID 1 +#define UART_IRQ_ID UART1_IRQn +#define UART_BAUDRATE 115200 +#define UART_OPS &max_uart_ops +#define UART_EXTRA <3074_uart_extra + +#define I2C_DEVICE_ID 1 +#define I2C_OPS &max_i2c_ops +#define I2C_EXTRA <3074_i2c_extra + +extern struct max_uart_init_param lt3074_uart_extra; +extern struct max_i2c_init_param lt3074_i2c_extra; + +#endif /* __PARAMETERS_H__ */ diff --git a/projects/lt3074/src/platform/maxim/platform_src.mk b/projects/lt3074/src/platform/maxim/platform_src.mk new file mode 100644 index 00000000000..34959e02075 --- /dev/null +++ b/projects/lt3074/src/platform/maxim/platform_src.mk @@ -0,0 +1,12 @@ +NO_OS_INC_DIRS += \ + $(PLATFORM_DRIVERS) \ + $(PLATFORM_DRIVERS)/../common/ + +SRCS += $(PLATFORM_DRIVERS)/maxim_delay.c \ + $(PLATFORM_DRIVERS)/maxim_gpio.c \ + $(PLATFORM_DRIVERS)/maxim_gpio_irq.c \ + $(PLATFORM_DRIVERS)/maxim_irq.c \ + $(PLATFORM_DRIVERS)/../common/maxim_dma.c \ + $(PLATFORM_DRIVERS)/maxim_i2c.c \ + $(PLATFORM_DRIVERS)/maxim_uart.c \ + $(PLATFORM_DRIVERS)/maxim_uart_stdio.c diff --git a/projects/lt3074/src/platform/platform_includes.h b/projects/lt3074/src/platform/platform_includes.h new file mode 100644 index 00000000000..e1828f39350 --- /dev/null +++ b/projects/lt3074/src/platform/platform_includes.h @@ -0,0 +1,40 @@ +/***************************************************************************//** +* @file platform_includes.h +* @brief Includes for used platforms used by lt3074 project. +* @author Cedric Justine Encarnacion (cedricjustine.encarnacion@analog.com) +******************************************************************************** +* Copyright 2025(c) Analog Devices, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of Analog Devices, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ +#ifndef __PLATFORM_INCLUDES_H__ +#define __PLATFORM_INCLUDES_H__ + +#ifdef MAXIM_PLATFORM +#include "maxim/parameters.h" +#endif + +#endif /* __PLATFORM_INCLUDES_H__ */