From 65387152c7a7f8983b058450f76977e570d31f91 Mon Sep 17 00:00:00 2001 From: Angelo Catapang Date: Wed, 11 Dec 2024 09:48:42 +0800 Subject: [PATCH 1/2] Adding support for ADP5055 Signed-off-by: Angelo Catapang --- drivers/power/adp5055/adp5055.c | 709 ++++++++++++++++++++++++++++++++ drivers/power/adp5055/adp5055.h | 241 +++++++++++ 2 files changed, 950 insertions(+) create mode 100644 drivers/power/adp5055/adp5055.c create mode 100644 drivers/power/adp5055/adp5055.h diff --git a/drivers/power/adp5055/adp5055.c b/drivers/power/adp5055/adp5055.c new file mode 100644 index 00000000000..85e0c0964ce --- /dev/null +++ b/drivers/power/adp5055/adp5055.c @@ -0,0 +1,709 @@ +/***************************************************************************//** + * @file adp5055.c + * @brief Source file for the ADP5055 Driver + * @author Angelo Catapang (angelo.catapang@analog.com) +******************************************************************************** + * Copyright 2024(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 "adp5055.h" +#include "no_os_alloc.h" +#include "no_os_delay.h" +#include "no_os_error.h" + +/** + * @brief Read data from ADP5055 + * @param desc - ADP5055 device descriptor + * @param address - 8-bit ADP5055 register address. + * @param data - Buffer with received data. + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_read(struct adp5055_desc *desc, uint8_t address, uint8_t *data) +{ + int ret; + + if (!desc) + return -EINVAL; + + ret = no_os_i2c_write(desc->i2c_desc, &address, 1, 0); + if (ret) + return ret; + + return no_os_i2c_read(desc->i2c_desc, data, 1, 1); +} + +/** + * @brief Write data to ADP5055 + * @param desc - ADP5055 device descriptor + * @param address - 8-bit ADP5055 register address + * @param data - Data byte value to write to the ADP5055 + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_write(struct adp5055_desc *desc, uint8_t address, uint8_t data) +{ + uint8_t val[2] = {0, 0}; + + if (!desc) + return -EINVAL; + + val[0] = address; + val[1] = data; + + return no_os_i2c_write(desc->i2c_desc, val, 2, 1); +} + +/** + * @brief Read statuses + * @param desc - ADP5055 device descriptor + * @param status_val - Status value to be returned. + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_read_status(struct adp5055_desc *desc, uint8_t *status_val) +{ + return adp5055_read(desc, ADP5055_STATUS_CML, status_val); +} + +/** + * @brief Configures enabling of individual channels by hardware and/or software + * @param desc - ADP5055 device descriptor + * @param mode - Enable mode + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_set_enable_mode(struct adp5055_desc *desc, enum adp5055_en_mode mode) +{ + int ret; + uint8_t data; + + ret = adp5055_read(desc, ADP5055_CTRL_MODE1, &data); + if (ret) + return ret; + + data &= ~ADP5055_EN_MODE_MASK; + data |= no_os_field_prep(ADP5055_EN_MODE_MASK, mode); + + return adp5055_write(desc, ADP5055_CTRL_MODE1, data); +} + +/** + * @brief Enables or disables dynamic voltage scaling across all channels + * @param desc - ADP5055 device descriptor + * @param en - If true, output voltage transitions only with a write to the VIDx_GO + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_set_dvs_auto(struct adp5055_desc *desc, bool en) +{ + int ret; + uint8_t data; + + ret = adp5055_read(desc, ADP5055_CTRL_MODE1, &data); + if (ret) + return ret; + + data &= ~ADP5055_DVS_AUTO; + data |= no_os_field_prep(ADP5055_DVS_AUTO, en ? 1 : 0); + + return adp5055_write(desc, ADP5055_CTRL_MODE1, data); +} + +/** + * @brief Enables or disables overcurrent protection (OCP) blanking for all channels + * @param desc - ADP5055 device descriptor + * @param en - If true, enables OCP blanking + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_set_ocp_blanking(struct adp5055_desc *desc, bool en) +{ + int ret; + uint8_t data; + + ret = adp5055_read(desc, ADP5055_CTRL_MODE2, &data); + if (ret) + return ret; + + data &= ~ADP5055_OCP_BLANKING; + data |= no_os_field_prep(ADP5055_OCP_BLANKING, en ? 1 : 0); + + return adp5055_write(desc, ADP5055_CTRL_MODE2, data); +} + +/** + * @brief Enables or disables automatic PWM/PSM per channel + * @param desc - ADP5055 device descriptor + * @param ch - ADP5055 output channel + * @param en - If true, enables automatic PWM/PSM on specified channel + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_set_auto_pwm_psm(struct adp5055_desc *desc, enum adp5055_channel ch, bool en) +{ + int ret; + uint8_t data; + uint32_t mask; + + switch(ch) + { + case ADP5055_VOUT1: + mask = ADP5055_PSM1_ON; + break; + case ADP5055_VOUT2: + mask = ADP5055_PSM2_ON; + break; + case ADP5055_VOUT3: + mask = ADP5055_PSM3_ON; + break; + default: + return -EINVAL; + } + + ret = adp5055_read(desc, ADP5055_CTRL_MODE2, &data); + if (ret) + return ret; + + data &= ~mask; + data |= no_os_field_prep(mask, en ? 1 : 0); + + return adp5055_write(desc, ADP5055_CTRL_MODE2, data); +} + +/** + * @brief Enables or disables output discharge per channel + * @param desc - ADP5055 device descriptor + * @param ch - ADP5055 output channel + * @param en - If true, enables output discharge on the specified channel + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_set_output_discharge(struct adp5055_desc *desc, enum adp5055_channel ch, bool en) +{ + int ret; + uint8_t data; + uint32_t mask; + + switch(ch) + { + case ADP5055_VOUT1: + mask = ADP5055_DSCG1_ON; + break; + case ADP5055_VOUT2: + mask = ADP5055_DSCG2_ON; + break; + case ADP5055_VOUT3: + mask = ADP5055_DSCG3_ON; + break; + default: + return -EINVAL; + } + + ret = adp5055_read(desc, ADP5055_CTRL_MODE2, &data); + if (ret) + return ret; + + data &= ~mask; + data |= no_os_field_prep(mask, en ? 1 : 0); + + return adp5055_write(desc, ADP5055_CTRL_MODE2, data); +} + +/** + * @brief Sets both enable and disable delay per channel + * @param desc - ADP5055 device descriptor + * @param ch - ADP5055 output channel + * @param en_dly - Enable delay on the specified channel + * @param dis_dly - Disable delay on the specified channel + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_set_enable_disable_delay(struct adp5055_desc *desc, enum adp5055_channel ch, enum adp5055_en_dly en_dly, enum adp5055_dis_dly dis_dly) +{ + int ret; + uint8_t address, data; + uint32_t mask; + + switch(ch) + { + case ADP5055_VOUT1: + address = ADP5055_DLY1; + break; + case ADP5055_VOUT2: + address = ADP5055_DLY2; + break; + case ADP5055_VOUT3: + address = ADP5055_DLY3; + break; + default: + return -EINVAL; + } + mask = ADP5055_EN_DLY_MASK | ADP5055_DIS_DLY_MASK; + + ret = adp5055_read(desc, address, &data); + if (ret) + return ret; + + data &= ~mask; + data |= no_os_field_prep(ADP5055_EN_DLY_MASK, en_dly); + data |= no_os_field_prep(ADP5055_DIS_DLY_MASK, dis_dly); + + return adp5055_write(desc, address, data); +} + +/** + * @brief Sets 8-bit code of output voltage reference of a channel + * @param desc - ADP5055 device descriptor + * @param ch - ADP5055 output channel + * @param val - 8-bit code of output voltage reference (Vref = 408mV + (1.5mV * val)) + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_set_vid_code(struct adp5055_desc *desc, enum adp5055_channel ch, uint8_t val) +{ + uint8_t address; + + switch(ch) + { + case ADP5055_VOUT1: + address = ADP5055_VID1; + break; + case ADP5055_VOUT2: + address = ADP5055_VID2; + break; + case ADP5055_VOUT3: + address = ADP5055_VID3; + break; + default: + return -EINVAL; + } + + return adp5055_write(desc, address, val); +} + +/** + * @brief Initiates output voltage transition on specified channel when dynamic voltage scaling is enabled + * @param desc - ADP5055 device descriptor + * @param ch - ADP5055 output channel + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_start_vout(struct adp5055_desc *desc, enum adp5055_channel ch) +{ + int ret; + uint8_t data; + uint32_t mask; + + switch (ch) { + case ADP5055_VOUT1: + mask = ADP5055_VID1_GO; + break; + case ADP5055_VOUT2: + mask = ADP5055_VID2_GO; + break; + case ADP5055_VOUT3: + mask = ADP5055_VID3_GO; + break; + default: + return -EINVAL; + } + + ret = adp5055_read(desc, ADP5055_VID_GO, &data); + if (ret) + return ret; + + data &= ~mask; + data |= no_os_field_prep(mask, 1); + + return adp5055_write(desc, ADP5055_VID_GO, data); +} + +/** + * @brief Enables output voltage channel in software + * @param desc - ADP5055 device descriptor + * @param ch - ADP5055 output channel + * @param en - Channel enable or disable + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_enable_channel(struct adp5055_desc *desc, enum adp5055_channel ch, bool en) +{ + int ret; + uint8_t data; + uint32_t mask; + + switch(ch) + { + case ADP5055_VOUT1: + mask = ADP5055_CH1_ON; + break; + case ADP5055_VOUT2: + mask = ADP5055_CH2_ON; + break; + case ADP5055_VOUT3: + mask = ADP5055_CH3_ON; + break; + default: + return -EINVAL; + } + + ret = adp5055_read(desc, ADP5055_CTRL123, &data); + if (ret) + return ret; + + data &= ~mask; + data |= no_os_field_prep(mask, en ? 1 : 0); + + return adp5055_write(desc, ADP5055_CTRL123, data); +} + +/** + * @brief Sets dynamic voltage scaling interval for each channel + * @param desc - ADP5055 device descriptor + * @param ch - ADP5055 output channel + * @param intval - Dynamic voltage scaling interval setting + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_set_dvs_interval(struct adp5055_desc *desc, enum adp5055_channel ch, enum adp5055_dvs_intval intval) +{ + int ret; + uint8_t data; + uint32_t mask; + + switch(ch) + { + case ADP5055_VOUT1: + mask = ADP5055_DVS_INTVAL1; + break; + case ADP5055_VOUT2: + mask = ADP5055_DVS_INTVAL2; + break; + case ADP5055_VOUT3: + mask = ADP5055_DVS_INTVAL3; + break; + default: + return -EINVAL; + } + + ret = adp5055_read(desc, ADP5055_DVS_CFG, &data); + if (ret) + return ret; + + data &= ~mask; + data |= no_os_field_prep(mask, intval); + + return adp5055_write(desc, ADP5055_DVS_CFG, data); +} + +/** + * @brief Sets high or low limit for output voltage reference + * @param desc - ADP5055 device descriptor + * @param ch - ADP5055 output channel + * @param lim_type - Selects whether high or low limit is set + * @param lim_val - 4-bit code of high / low output voltage reference limit + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_set_vidx_lim(struct adp5055_desc *desc, enum adp5055_channel ch, enum adp5055_vidx_limit lim_type, uint8_t lim_val) +{ + int ret; + uint8_t data; + uint8_t address; + uint32_t mask; + + switch (ch) { + case ADP5055_VOUT1: + address = ADP5055_DVS_LIM1; + break; + case ADP5055_VOUT2: + address = ADP5055_DVS_LIM2; + break; + case ADP5055_VOUT3: + address = ADP5055_DVS_LIM3; + break; + default: + return -EINVAL; + } + + switch (lim_type) { + case ADP5055_VIDX_LOW: + mask = ADP5055_VIDX_LOW_MASK; + break; + case ADP5055_VIDX_HIGH: + mask = ADP5055_VIDX_HIGH_MASK; + break; + default: + return -EINVAL; + } + + ret = adp5055_read(desc, address, &data); + if (ret) + return ret; + + data &= ~mask; + data |= no_os_field_prep(mask, lim_val); + + return adp5055_write(desc, address, data); +} + +/** + * @brief Configures fast transient sensitivity per channel + * @param desc - ADP5055 device descriptor + * @param ch - ADP5055 output channel + * @param ft - Fast transient setting + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_set_fast_transient(struct adp5055_desc *desc, enum adp5055_channel ch, enum adp5055_ft_th ft) +{ + int ret; + uint8_t data; + uint32_t mask; + + switch (ch) { + case ADP5055_VOUT1: + mask = ADP5055_FT1_TH; + break; + case ADP5055_VOUT2: + mask = ADP5055_FT2_TH; + break; + case ADP5055_VOUT3: + mask = ADP5055_FT3_TH; + break; + default: + return -EINVAL; + } + + ret = adp5055_read(desc, ADP5055_FT_CFG, &data); + if (ret) + return ret; + + data &= ~mask; + data |= no_os_field_prep(mask, ft); + + return adp5055_write(desc, ADP5055_FT_CFG, data); +} + +/** + * @brief Enables power good signal to external PWRGD hardware pin + * @param desc - ADP5055 device descriptor + * @param ch - ADP5055 output channel + * @param en - If true, power good signal of specified channel is outputted at external PWRGD hardware pin + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_set_pg_channel_output(struct adp5055_desc *desc, enum adp5055_channel ch, bool en) +{ + int ret; + uint8_t data; + uint32_t mask; + + switch (ch) { + case ADP5055_VOUT1: + mask = ADP5055_PG1_MASK; + break; + case ADP5055_VOUT2: + mask = ADP5055_PG2_MASK; + break; + case ADP5055_VOUT3: + mask = ADP5055_PG3_MASK; + break; + default: + return -EINVAL; + } + + ret = adp5055_read(desc, ADP5055_PG_CFG, &data); + if (ret) + return ret; + + data &= ~mask; + data |= no_os_field_prep(mask, en ? 0 : 1); + + return adp5055_write(desc, ADP5055_PG_CFG, data); +} + +/** + * @brief Enables a delay in the PWRGD hardware pin + * @param desc - ADP5055 device descriptor + * @param en - If false, PWRGD pin responds immediately + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_set_pg_hw_delay(struct adp5055_desc *desc, bool en) +{ + int ret; + uint8_t data; + + ret = adp5055_read(desc, ADP5055_PG_CFG, &data); + if (ret) + return ret; + + data &= ~ADP5055_PWRGD_DLY; + data |= no_os_field_prep(ADP5055_PWRGD_DLY, en ? 1 : 0); + + return adp5055_write(desc, ADP5055_PG_CFG, data); +} + +/** + * @brief Reads real-time power good status of specified channel + * @param desc - ADP5055 device descriptor + * @param ch - ADP5055 output channel + * @param pg_val - Stores the value of the real-time power good status + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_read_pg(struct adp5055_desc *desc, enum adp5055_channel ch, uint8_t *pg_val) +{ + int ret; + uint8_t data; + uint32_t mask; + + switch (ch) { + case ADP5055_VOUT1: + mask = ADP5055_PWRGD1; + break; + case ADP5055_VOUT2: + mask = ADP5055_PWRGD2; + break; + case ADP5055_VOUT3: + mask = ADP5055_PWRGD3; + break; + default: + return -EINVAL; + } + + ret = adp5055_read(desc, ADP5055_PG_READ, &data); + if (ret) + return ret; + + *pg_val = no_os_field_get(mask, data); + + return 0; +} + +/** + * @brief Reads the latched status of a specified channel + * @param desc - ADP5055 device descriptor + * @param ch - ADP5055 output channel + * @param lch_status_type - Selects which latch status to read + * @param lch_status_val - Stores the latch status value of the specified channel + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_read_latched_status(struct adp5055_desc *desc, enum adp5055_channel ch, enum adp5055_latch_status lch_status_type, uint8_t *lch_status_val) +{ + int ret; + uint8_t data; + uint32_t mask; + uint8_t ch_offset; + + switch (ch) { + case ADP5055_VOUT1: + ch_offset = 0; + break; + case ADP5055_VOUT2: + ch_offset = 1; + break; + case ADP5055_VOUT3: + ch_offset = 2; + break; + default: + return -EINVAL; + } + + switch (lch_status_type) { + case ADP5055_LCH_INIT_FAIL: + mask = ADP5055_INT_LCH; + break; + case ADP5055_LCH_OVERCURRENT_HICCUP: + mask = ADP5055_OCP1_LCH << ch_offset; + break; + case ADP5055_LCH_THERMAL_SHUTDOWN: + mask = ADP5055_TSD_LCH; + break; + case ADP5055_LCH_PG_FAIL: + mask = ADP5055_PG1_LCH << ch_offset; + break; + default: + return -EINVAL; + } + + ret = adp5055_read(desc, ADP5055_STATUS_LCH, &data); + if (ret) + return ret; + + *lch_status_val = no_os_field_get(mask, data); + + return 0; +} + +/** + * @brief Initialize the ADP5055 device. + * @param desc - ADP5055 device descriptor + * @param init_param - Initialization parameter containing information about the + * ADP5055 device to be initialized. + * @return 0 in case of succes, negative error code otherwise +*/ +int adp5055_init(struct adp5055_desc **desc, + struct adp5055_init_param *init_param) +{ + struct adp5055_desc *descriptor; + int ret; + + descriptor = (struct adp5055_desc *)no_os_calloc(sizeof(*descriptor), 1); + if (!descriptor) + return -ENOMEM; + + ret = no_os_i2c_init(&descriptor->i2c_desc, init_param->i2c_param); + if (ret) + goto free_desc; + + /* Time needed for the ADP5055 to power-up. */ + no_os_mdelay(52); + + *desc = descriptor; + + return 0; + +free_desc: + adp5055_remove(descriptor); + + return ret; +} + +/** + * @brief Free the resources allocated by the adp5055_init() + * @param desc - ADP5055 device descriptor + * @return- 0 in case of succes, negative error code otherwise +*/ +int adp5055_remove(struct adp5055_desc *desc) +{ + int ret; + + if (!desc) + return -ENODEV; + + if (desc->i2c_desc) { + ret = adp5055_set_enable_mode(desc, ADP5055_EN_MODE_HW_AND_SW); + if (ret) + return ret; + + ret = adp5055_write(desc, ADP5055_CTRL123, 0); + if (ret) + return ret; + } + + no_os_i2c_remove(desc->i2c_desc); + no_os_free(desc); + + return 0; +} diff --git a/drivers/power/adp5055/adp5055.h b/drivers/power/adp5055/adp5055.h new file mode 100644 index 00000000000..7dcc49311ea --- /dev/null +++ b/drivers/power/adp5055/adp5055.h @@ -0,0 +1,241 @@ +/***************************************************************************//** + * @file adp5055.h + * @brief Header file for the ADP5055 Driver + * @author Angelo Catapang (angelo.catapang@analog.com) +******************************************************************************** + * Copyright 2024(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 __ADP_5055_H__ +#define __ADP_5055_H__ + +#include +#include +#include +#include "no_os_gpio.h" +#include "no_os_i2c.h" +#include "no_os_pwm.h" +#include "no_os_util.h" +#include "no_os_units.h" + +#define ADP5055_CAPABILITY 0x19 +#define ADP5055_STATUS_CML 0x7E +#define ADP5055_MODEL_ID 0xD0 +#define ADP5055_CTRL123 0xD1 +#define ADP5055_VID_GO 0xD2 +#define ADP5055_CTRL_MODE1 0xD3 +#define ADP5055_CTRL_MODE2 0xD4 +#define ADP5055_DLY1 0xD5 +#define ADP5055_DLY2 0xD6 +#define ADP5055_DLY3 0xD7 +#define ADP5055_VID1 0xD8 +#define ADP5055_VID2 0xD9 +#define ADP5055_VID3 0xDA +#define ADP5055_DVS_CFG 0xDB +#define ADP5055_DVS_LIM1 0xDC +#define ADP5055_DVS_LIM2 0xDD +#define ADP5055_DVS_LIM3 0xDE +#define ADP5055_FT_CFG 0xDF +#define ADP5055_PG_CFG 0xE0 +#define ADP5055_PG_READ 0xE1 +#define ADP5055_STATUS_LCH 0xE2 + +#define ADP5055_CH1_ON NO_OS_BIT(0) +#define ADP5055_CH2_ON NO_OS_BIT(1) +#define ADP5055_CH3_ON NO_OS_BIT(2) + +#define ADP5055_VID1_GO NO_OS_BIT(0) +#define ADP5055_VID2_GO NO_OS_BIT(1) +#define ADP5055_VID3_GO NO_OS_BIT(2) + +#define ADP5055_EN_MODE_MASK NO_OS_GENMASK(1, 0) +#define ADP5055_DVS_AUTO NO_OS_BIT(4) + +#define ADP5055_DSCG1_ON NO_OS_BIT(0) +#define ADP5055_DSCG2_ON NO_OS_BIT(1) +#define ADP5055_DSCG3_ON NO_OS_BIT(2) +#define ADP5055_PSM1_ON NO_OS_BIT(4) +#define ADP5055_PSM2_ON NO_OS_BIT(5) +#define ADP5055_PSM3_ON NO_OS_BIT(6) +#define ADP5055_OCP_BLANKING NO_OS_BIT(7) + +#define ADP5055_EN_DLY_MASK NO_OS_GENMASK(2, 0) +#define ADP5055_DIS_DLY_MASK NO_OS_GENMASK(6, 4) + +#define ADP5055_DVS_INTVAL1 NO_OS_GENMASK(1, 0) +#define ADP5055_DVS_INTVAL2 NO_OS_GENMASK(3, 2) +#define ADP5055_DVS_INTVAL3 NO_OS_GENMASK(5, 4) + +#define ADP5055_VIDX_LOW_MASK NO_OS_GENMASK(3, 0) +#define ADP5055_VIDX_HIGH_MASK NO_OS_GENMASK(7, 4) + +#define ADP5055_FT1_TH NO_OS_GENMASK(1, 0) +#define ADP5055_FT2_TH NO_OS_GENMASK(3, 2) +#define ADP5055_FT3_TH NO_OS_GENMASK(5, 4) + +#define ADP5055_PG1_MASK NO_OS_BIT(0) +#define ADP5055_PG2_MASK NO_OS_BIT(1) +#define ADP5055_PG3_MASK NO_OS_BIT(2) +#define ADP5055_PWRGD_DLY NO_OS_BIT(4) + +#define ADP5055_PWRGD1 NO_OS_BIT(0) +#define ADP5055_PWRGD2 NO_OS_BIT(1) +#define ADP5055_PWRGD3 NO_OS_BIT(2) + +#define ADP5055_PG1_LCH NO_OS_BIT(0) +#define ADP5055_PG2_LCH NO_OS_BIT(1) +#define ADP5055_PG3_LCH NO_OS_BIT(2) +#define ADP5055_TSD_LCH NO_OS_BIT(3) +#define ADP5055_OCP1_LCH NO_OS_BIT(4) +#define ADP5055_OCP2_LCH NO_OS_BIT(5) +#define ADP5055_OCP3_LCH NO_OS_BIT(6) +#define ADP5055_INT_LCH NO_OS_BIT(7) + +/* PMBus Addresses */ +#define ADP5055_PMBUS_OPEN_ADDRESS 0x70 +#define ADP5055_PMBUS_0OHM_ADDRESS 0x70 +#define ADP5055_PMBUS_14KOHM_ADDRESS 0x71 +#define ADP5055_PMBUS_16KOHM_ADDRESS 0x72 +#define ADP5055_PMBUS_20KOHM_ADDRESS 0x73 +#define ADP5055_PMBUS_23KOHM_ADDRESS 0x70 +#define ADP5055_PMBUS_32KOHM_ADDRESS 0x71 +#define ADP5055_PMBUS_39KOHM_ADDRESS 0x73 +#define ADP5055_PMBUS_47KOHM_ADDRESS 0x71 +#define ADP5055_PMBUS_57KOHM_ADDRESS 0x72 +#define ADP5055_PMBUS_71KOHM_ADDRESS 0x73 +#define ADP5055_PMBUS_90KOHM_ADDRESS 0x70 +#define ADP5055_PMBUS_127KOHM_ADDRESS 0x71 +#define ADP5055_PMBUS_200KOHM_ADDRESS 0x72 +#define ADP5055_PMBUS_511KOHM_ADDRESS 0x73 + +enum adp5055_latch_status { + ADP5055_LCH_INIT_FAIL, + ADP5055_LCH_OVERCURRENT_HICCUP, + ADP5055_LCH_THERMAL_SHUTDOWN, + ADP5055_LCH_PG_FAIL +}; + +enum adp5055_en_mode { + ADP5055_EN_MODE_HW_ONLY, + ADP5055_EN_MODE_SW_ONLY, + ADP5055_EN_MODE_HW_AND_SW, + ADP5055_EN_MODE_HW_OR_SW +}; + +enum adp5055_vidx_limit { + ADP5055_VIDX_LOW, + ADP5055_VIDX_HIGH +}; + +enum adp5055_ft_th { + ADP5055_FT_NONE, + ADP5055_FT_1_5WINDOW_3G, // 1.5% window with 3xGm, Gm=350uA/V + ADP5055_FT_1_5WINDOW_5G, // 1.5% window with 5xGm, Gm=350uA/V + ADP5055_FT_2_5WINDOW_5G // 2.5% window with 5xGm, Gm=350uA/V +}; + +enum adp5055_dvs_intval { + ADP5055_DVS_INTVAL_125US, // 125uS at 12mV/ms slew rate + ADP5055_DVS_INTVAL_62US, // 62.5uS at 24mV/ms slew rate + ADP5055_DVS_INTVAL_31US, // 31.2uS at 48mV/ms slew rate + ADP5055_DVS_INTVAL_15US, // 15.6uS at 96mV/ms slew rate +}; + +enum adp5055_en_dly { + ADP5055_EN_NO_DELAY, + ADP5055_EN_1TSET, + ADP5055_EN_2TSET, + ADP5055_EN_3TSET, + ADP5055_EN_4TSET, + ADP5055_EN_5TSET, + ADP5055_EN_6TSET, + ADP5055_EN_7TSET, +}; + +enum adp5055_dis_dly { + ADP5055_DIS_NO_DELAY, + ADP5055_DIS_2TSET, + ADP5055_DIS_4TSET, + ADP5055_DIS_6TSET, + ADP5055_DIS_8TSET, + ADP5055_DIS_10TSET, + ADP5055_DIS_12TSET, + ADP5055_DIS_14TSET, +}; + +enum adp5055_channel { + ADP5055_VOUT1, + ADP5055_VOUT2, + ADP5055_VOUT3 +}; + +/** + * @brief Initialization parameter for the ADP5055 device. +*/ +struct adp5055_init_param { + struct no_os_i2c_init_param *i2c_param; +}; + +/** + * @brief Device descriptor for ADP5055. +*/ +struct adp5055_desc { + struct no_os_i2c_desc *i2c_desc; +}; + +/** Read command from ADP5055 device. */ +int adp5055_read(struct adp5055_desc *desc, uint8_t address, uint8_t *data); + +/** Write command to ADP5055 device. */ +int adp5055_write(struct adp5055_desc *desc, uint8_t address, uint8_t data); + +int adp5055_read_status(struct adp5055_desc *desc, uint8_t *status_val); +int adp5055_set_enable_mode(struct adp5055_desc *desc, enum adp5055_en_mode mode); +int adp5055_set_dvs_auto(struct adp5055_desc *desc, bool en); +int adp5055_set_ocp_blanking(struct adp5055_desc *desc, bool en); +int adp5055_set_auto_pwm_psm(struct adp5055_desc *desc, enum adp5055_channel ch, bool en); +int adp5055_set_output_discharge(struct adp5055_desc *desc, enum adp5055_channel ch, bool en); +int adp5055_set_enable_disable_delay(struct adp5055_desc *desc, enum adp5055_channel ch, enum adp5055_en_dly en_dly, enum adp5055_dis_dly dis_dly); +int adp5055_set_vid_code(struct adp5055_desc *desc, enum adp5055_channel ch, uint8_t val); +int adp5055_start_vout(struct adp5055_desc *desc, enum adp5055_channel ch); +int adp5055_enable_channel(struct adp5055_desc *desc, enum adp5055_channel ch, bool en); +int adp5055_set_dvs_interval(struct adp5055_desc *desc, enum adp5055_channel ch, enum adp5055_dvs_intval intval); +int adp5055_set_vidx_lim(struct adp5055_desc *desc, enum adp5055_channel ch, enum adp5055_vidx_limit lim_type, uint8_t lim_val); +int adp5055_set_fast_transient(struct adp5055_desc *desc, enum adp5055_channel ch, enum adp5055_ft_th ft); +int adp5055_set_pg_channel_output(struct adp5055_desc *desc, enum adp5055_channel ch, bool en); +int adp5055_set_pg_hw_delay(struct adp5055_desc *desc, bool en); +int adp5055_read_pg(struct adp5055_desc *desc, enum adp5055_channel ch, uint8_t *pg_val); +int adp5055_read_latched_status(struct adp5055_desc *desc, enum adp5055_channel ch, enum adp5055_latch_status lch_status_type, uint8_t *lch_status_val); + +/** Initialize the ADP5055 device descriptor. */ +int adp5055_init(struct adp5055_desc **desc, + struct adp5055_init_param *init_param); + +/** Remove resources allocated by the init function. */ +int adp5055_remove(struct adp5055_desc *desc); + +#endif /** __ADP_5055_H__ */ From e66427988bf2da8adba7cccbefd4b628dc860c77 Mon Sep 17 00:00:00 2001 From: Angelo Catapang Date: Wed, 11 Dec 2024 09:50:25 +0800 Subject: [PATCH 2/2] Adding project support for ADP5055 Signed-off-by: Angelo Catapang --- projects/adp5055/Makefile | 8 + projects/adp5055/builds.json | 10 ++ projects/adp5055/src.mk | 44 ++++++ projects/adp5055/src/common/common_data.c | 55 +++++++ projects/adp5055/src/common/common_data.h | 52 +++++++ .../src/examples/basic/basic_example.c | 138 ++++++++++++++++++ .../src/examples/basic/basic_example.h | 38 +++++ projects/adp5055/src/examples/examples_src.mk | 5 + projects/adp5055/src/platform/maxim/main.c | 53 +++++++ .../adp5055/src/platform/maxim/parameters.c | 41 ++++++ .../adp5055/src/platform/maxim/parameters.h | 57 ++++++++ .../src/platform/maxim/platform_src.mk | 12 ++ .../adp5055/src/platform/platform_includes.h | 40 +++++ 13 files changed, 553 insertions(+) create mode 100644 projects/adp5055/Makefile create mode 100644 projects/adp5055/builds.json create mode 100644 projects/adp5055/src.mk create mode 100644 projects/adp5055/src/common/common_data.c create mode 100644 projects/adp5055/src/common/common_data.h create mode 100644 projects/adp5055/src/examples/basic/basic_example.c create mode 100644 projects/adp5055/src/examples/basic/basic_example.h create mode 100644 projects/adp5055/src/examples/examples_src.mk create mode 100644 projects/adp5055/src/platform/maxim/main.c create mode 100644 projects/adp5055/src/platform/maxim/parameters.c create mode 100644 projects/adp5055/src/platform/maxim/parameters.h create mode 100644 projects/adp5055/src/platform/maxim/platform_src.mk create mode 100644 projects/adp5055/src/platform/platform_includes.h diff --git a/projects/adp5055/Makefile b/projects/adp5055/Makefile new file mode 100644 index 00000000000..064e45b3547 --- /dev/null +++ b/projects/adp5055/Makefile @@ -0,0 +1,8 @@ +# Select the example you want to enable by choosing y for enabling and n for disabling +BASIC_EXAMPLE = y + +include ../../tools/scripts/generic_variables.mk + +include src.mk + +include ../../tools/scripts/generic.mk diff --git a/projects/adp5055/builds.json b/projects/adp5055/builds.json new file mode 100644 index 00000000000..09b5bc3f856 --- /dev/null +++ b/projects/adp5055/builds.json @@ -0,0 +1,10 @@ +{ + "maxim": { + "basic_example_max32690": { + "flags" : "BASIC_EXAMPLE=y IIO_EXAMPLE=n TARGET=max32690" + }, + "iio_example_max32690": { + "flags" : "BASIC_EXAMPLE=n IIO_EXAMPLE=y TARGET=max32690" + } + } +} diff --git a/projects/adp5055/src.mk b/projects/adp5055/src.mk new file mode 100644 index 00000000000..da3924614e7 --- /dev/null +++ b/projects/adp5055/src.mk @@ -0,0 +1,44 @@ +include $(PROJECT)/src/platform/$(PLATFORM)/platform_src.mk +include $(PROJECT)/src/examples/examples_src.mk + +SRCS += $(PROJECT)/src/platform/$(PLATFORM)/main.c + +INCS += $(PROJECT)/src/common/common_data.h +SRCS += $(PROJECT)/src/common/common_data.c + +INCS += $(PROJECT)/src/platform/platform_includes.h + +INCS += $(PROJECT)/src/platform/$(PLATFORM)/parameters.h +SRCS += $(PROJECT)/src/platform/$(PLATFORM)/parameters.c + +INCS += $(INCLUDE)/no_os_delay.h \ + $(INCLUDE)/no_os_error.h \ + $(INCLUDE)/no_os_list.h \ + $(INCLUDE)/no_os_gpio.h \ + $(INCLUDE)/no_os_dma.h \ + $(INCLUDE)/no_os_print_log.h \ + $(INCLUDE)/no_os_i2c.h \ + $(INCLUDE)/no_os_irq.h \ + $(INCLUDE)/no_os_pwm.h \ + $(INCLUDE)/no_os_rtc.h \ + $(INCLUDE)/no_os_uart.h \ + $(INCLUDE)/no_os_lf256fifo.h \ + $(INCLUDE)/no_os_util.h \ + $(INCLUDE)/no_os_units.h \ + $(INCLUDE)/no_os_alloc.h \ + $(INCLUDE)/no_os_mutex.h + +SRCS += $(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 \ + $(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 + +INCS += $(DRIVERS)/power/adp5055/adp5055.h +SRCS += $(DRIVERS)/power/adp5055/adp5055.c diff --git a/projects/adp5055/src/common/common_data.c b/projects/adp5055/src/common/common_data.c new file mode 100644 index 00000000000..30828f68beb --- /dev/null +++ b/projects/adp5055/src/common/common_data.c @@ -0,0 +1,55 @@ +/***************************************************************************//** + * @file common_data.c + * @brief Defines common data to be used by adp5055 examples. + * @author Angelo Catapang (angelo.catapang@analog.com) +******************************************************************************** + * Copyright 2024(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 adp5055_uart_ip = { + .device_id = UART_DEVICE_ID, + .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 adp5055_i2c_ip = { + .device_id = I2C_DEVICE_ID, + .max_speed_hz = 100000, + .platform_ops = I2C_OPS, + .slave_address = ADP5055_PMBUS_23KOHM_ADDRESS, + .extra = I2C_EXTRA, +}; + +struct adp5055_init_param adp5055_ip = { + .i2c_param = &adp5055_i2c_ip +}; diff --git a/projects/adp5055/src/common/common_data.h b/projects/adp5055/src/common/common_data.h new file mode 100644 index 00000000000..f92cca5fbaf --- /dev/null +++ b/projects/adp5055/src/common/common_data.h @@ -0,0 +1,52 @@ +/***************************************************************************//** + * @file common_data.h + * @brief Defines common data to be used by adp5055 examples. + * @author Angelo Catapang (angelo.catapang@analog.com) +******************************************************************************** + * Copyright 2024(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 "adp5055.h" + +extern struct no_os_uart_init_param adp5055_uart_ip; +extern struct no_os_i2c_init_param adp5055_i2c_ip; +extern struct adp5055_init_param adp5055_ip; + +// EVAL-ADP5055 External Parameters +#define RTOP1 20000.0 +#define RBOT1 30100.0 +#define RTOP2 20000.0 +#define RBOT2 16900.0 +#define RTOP3 20000.0 +#define RBOT3 10000.0 + +#endif /* __COMMON_DATA_H__ */ diff --git a/projects/adp5055/src/examples/basic/basic_example.c b/projects/adp5055/src/examples/basic/basic_example.c new file mode 100644 index 00000000000..d8560a71aac --- /dev/null +++ b/projects/adp5055/src/examples/basic/basic_example.c @@ -0,0 +1,138 @@ +/***************************************************************************//** + * @file basic_example.c + * @brief Basic example source file for adp5055 project. + * @author Angelo Catapang (angelo.catapang@analog.com) +******************************************************************************** + * Copyright 2024(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_i2c.h" +#include "no_os_print_log.h" +#include "no_os_util.h" +#include "adp5055.h" + +int basic_example_main() +{ + int ret; + + struct adp5055_desc *adp5055_desc; + uint8_t model_id; + + float vout1_voltage = 1.2; + float vout1_ref; + uint8_t vid1_code; + + uint8_t pg1_val; + uint8_t status_lch; + + ret = adp5055_init(&adp5055_desc, &adp5055_ip); + if (ret) + goto exit; + + ret = adp5055_read(adp5055_desc, ADP5055_MODEL_ID, &model_id); + if (ret) + goto exit; + + if (model_id != 0x40) + goto exit; + + ret = adp5055_set_dvs_auto(adp5055_desc, true); + if (ret) + goto exit; + + ret = adp5055_set_dvs_auto(adp5055_desc, true); + if (ret) + goto exit; + + ret = adp5055_set_auto_pwm_psm(adp5055_desc, ADP5055_VOUT1, false); + if (ret) + goto exit; + + ret = adp5055_set_output_discharge(adp5055_desc, ADP5055_VOUT1, false); + if (ret) + goto exit; + + ret = adp5055_set_enable_disable_delay(adp5055_desc, ADP5055_VOUT1, ADP5055_EN_NO_DELAY, ADP5055_DIS_NO_DELAY); + if (ret) + goto exit; + + ret = adp5055_set_dvs_interval(adp5055_desc, ADP5055_VOUT1, ADP5055_DVS_INTVAL_125US); + if (ret) + goto exit; + + ret = adp5055_set_vidx_lim(adp5055_desc, ADP5055_VOUT1, ADP5055_VIDX_HIGH, 0); + if (ret) + goto exit; + + ret = adp5055_set_vidx_lim(adp5055_desc, ADP5055_VOUT1, ADP5055_VIDX_LOW, 0); + if (ret) + goto exit; + + + ret = adp5055_set_fast_transient(adp5055_desc, ADP5055_VOUT1, ADP5055_FT_NONE); + if (ret) + goto exit; + + ret = adp5055_set_pg_hw_delay(adp5055_desc, false); + if (ret) + goto exit; + + ret = adp5055_set_pg_channel_output(adp5055_desc, ADP5055_VOUT1, true); + if (ret) + goto exit; + + vout1_ref = vout1_voltage / (1 + (RTOP1 / RBOT1)); + vid1_code = (uint8_t) ((vout1_ref - 0.408) / 0.0015); + + ret = adp5055_set_vid_code(adp5055_desc, ADP5055_VOUT1, vid1_code); + if (ret) + goto exit; + + ret = adp5055_enable_channel(adp5055_desc, ADP5055_VOUT1, true); + if (ret) + goto exit; + + /* Checking statuses. */ + ret = adp5055_read_pg(adp5055_desc, ADP5055_VOUT1, &pg1_val); + if (ret) + goto exit; + + ret = adp5055_read(adp5055_desc, ADP5055_STATUS_LCH, &status_lch); + if (ret) + goto exit; + +exit: + if (ret) + pr_info("Error!\n"); + + adp5055_remove(adp5055_desc); + + return ret; +} diff --git a/projects/adp5055/src/examples/basic/basic_example.h b/projects/adp5055/src/examples/basic/basic_example.h new file mode 100644 index 00000000000..06c71bf4327 --- /dev/null +++ b/projects/adp5055/src/examples/basic/basic_example.h @@ -0,0 +1,38 @@ +/***************************************************************************//** + * @file basic_example.h + * @brief Basic example header file for adp5055 project. + * @author Angelo Catapang (angelo.catapang@analog.com) +******************************************************************************** + * Copyright 2024(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/adp5055/src/examples/examples_src.mk b/projects/adp5055/src/examples/examples_src.mk new file mode 100644 index 00000000000..3bfdda6fd2d --- /dev/null +++ b/projects/adp5055/src/examples/examples_src.mk @@ -0,0 +1,5 @@ +ifeq (y,$(strip $(BASIC_EXAMPLE))) +CFLAGS += -DBASIC_EXAMPLE +SRCS += $(PROJECT)/src/examples/basic/basic_example.c +INCS += $(PROJECT)/src/examples/basic/basic_example.h +endif diff --git a/projects/adp5055/src/platform/maxim/main.c b/projects/adp5055/src/platform/maxim/main.c new file mode 100644 index 00000000000..c4ca65a9b54 --- /dev/null +++ b/projects/adp5055/src/platform/maxim/main.c @@ -0,0 +1,53 @@ +/***************************************************************************//** + * @file main.c + * @brief Main file for Maxim platform of adp5055 project. + * @author Angelo Catapang (angelo.catapang@analog.com) +******************************************************************************** + * Copyright 2024(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" + +#include "basic_example.h" + +int main() +{ + int ret = -EINVAL; + + struct no_os_uart_desc *uart_desc; + + ret = no_os_uart_init(&uart_desc, &adp5055_uart_ip); + if (ret) + return ret; + + no_os_uart_stdio(uart_desc); + ret = basic_example_main(); + + return ret; +} diff --git a/projects/adp5055/src/platform/maxim/parameters.c b/projects/adp5055/src/platform/maxim/parameters.c new file mode 100644 index 00000000000..f46b8a6fd99 --- /dev/null +++ b/projects/adp5055/src/platform/maxim/parameters.c @@ -0,0 +1,41 @@ +/***************************************************************************//** + * @file parameters.c + * @brief Definition of Maxim platform data used by adp5055 project. + * @author Angelo Catapang (angelo.catapang@analog.com) +******************************************************************************** + * Copyright 2024(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 adp5055_uart_extra = { + .flow = UART_FLOW_DIS, +}; + +struct max_i2c_init_param adp5055_i2c_extra = { + .vssel = MXC_GPIO_VSSEL_VDDIOH +}; diff --git a/projects/adp5055/src/platform/maxim/parameters.h b/projects/adp5055/src/platform/maxim/parameters.h new file mode 100644 index 00000000000..80a691977d4 --- /dev/null +++ b/projects/adp5055/src/platform/maxim/parameters.h @@ -0,0 +1,57 @@ +/***************************************************************************//** + * @file parameters.h + * @brief Definition of Maxim platform data used by adp5055 project. + * @author Angelo Catapang (angelo.catapang@analog.com) +******************************************************************************** + * Copyright 2024(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_uart.h" +#include "maxim_uart_stdio.h" + +#ifdef IIO_SUPPORT +#define INTC_DEVICE_ID 0 +#endif + +#define UART_DEVICE_ID 0 +#define UART_BAUDRATE 57600 +#define UART_OPS &max_uart_ops +#define UART_EXTRA &adp5055_uart_extra + +#define I2C_DEVICE_ID 0 +#define I2C_OPS &max_i2c_ops +#define I2C_EXTRA &adp5055_i2c_extra + +extern struct max_uart_init_param adp5055_uart_extra; +extern struct max_i2c_init_param adp5055_i2c_extra; + +#endif /* __PARAMETERS_H__ */ diff --git a/projects/adp5055/src/platform/maxim/platform_src.mk b/projects/adp5055/src/platform/maxim/platform_src.mk new file mode 100644 index 00000000000..e1f79685d9c --- /dev/null +++ b/projects/adp5055/src/platform/maxim/platform_src.mk @@ -0,0 +1,12 @@ +INCS += $(PLATFORM_DRIVERS)/maxim_irq.h \ + $(PLATFORM_DRIVERS)/../common/maxim_dma.h \ + $(PLATFORM_DRIVERS)/maxim_i2c.h \ + $(PLATFORM_DRIVERS)/maxim_uart.h \ + $(PLATFORM_DRIVERS)/maxim_uart_stdio.h + +SRCS += $(PLATFORM_DRIVERS)/maxim_delay.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/adp5055/src/platform/platform_includes.h b/projects/adp5055/src/platform/platform_includes.h new file mode 100644 index 00000000000..2981b8afe07 --- /dev/null +++ b/projects/adp5055/src/platform/platform_includes.h @@ -0,0 +1,40 @@ +/***************************************************************************//** + * @file platform_includes.h + * @brief Includes for used platforms used by adp5055 project. + * @author Angelo Catapang (angelo.catapang@analog.com) +******************************************************************************** + * Copyright 2024(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__ */