Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/adp5055 #2395

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
709 changes: 709 additions & 0 deletions drivers/power/adp5055/adp5055.c

Large diffs are not rendered by default.

241 changes: 241 additions & 0 deletions drivers/power/adp5055/adp5055.h
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#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__ */
8 changes: 8 additions & 0 deletions projects/adp5055/Makefile
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions projects/adp5055/builds.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
44 changes: 44 additions & 0 deletions projects/adp5055/src.mk
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions projects/adp5055/src/common/common_data.c
Original file line number Diff line number Diff line change
@@ -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
};
Loading
Loading