Skip to content

Dac pm3 support #90240

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
81 changes: 71 additions & 10 deletions drivers/dac/dac_mcux_gau.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
/*
* Copyright 2023 NXP
* Copyright 2023, 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

#define DT_DRV_COMPAT nxp_gau_dac

#include <zephyr/drivers/dac.h>

#include <fsl_dac.h>

#define LOG_LEVEL CONFIG_DAC_LOG_LEVEL
#include "fsl_clock.h"
#include <zephyr/logging/log.h>
#include <zephyr/irq.h>
#include <zephyr/pm/policy.h>
#include <zephyr/pm/device.h>

LOG_MODULE_REGISTER(nxp_gau_dac);
#define LOG_LEVEL CONFIG_DAC_LOG_LEVEL
#define ZEPHYR_USER_NODE_RESTORE DT_PATH(zephyr_user)
#if (DT_NODE_HAS_PROP(ZEPHYR_USER_NODE_RESTORE, dac) && \
DT_NODE_HAS_PROP(ZEPHYR_USER_NODE_RESTORE, dac_channel_id) && \
DT_NODE_HAS_PROP(ZEPHYR_USER_NODE_RESTORE, dac_resolution))
#define DAC_NODE DT_PHANDLE(ZEPHYR_USER_NODE_RESTORE, dac)
#define DAC_CHANNEL_ID_RESTORE DT_PROP(ZEPHYR_USER_NODE_RESTORE, dac_channel_id)
#define DAC_RESOLUTION_RESTORE DT_PROP(ZEPHYR_USER_NODE_RESTORE, dac_resolution)
#endif

struct nxp_gau_dac_config {
DAC_Type *base;
Expand All @@ -40,6 +50,8 @@
dac_channel_config_t dac_channel_config = {0};
bool use_internal = true;

pm_policy_device_power_lock_get(dev);/*Lock the PM states*/

if (channel_cfg->resolution != 10) {
LOG_ERR("DAC only support 10 bit resolution");
return -EINVAL;
Expand Down Expand Up @@ -101,21 +113,70 @@
return 0;
};

static int nxp_gau_dac_init_common(const struct device *dev)
{
const struct nxp_gau_dac_config *config = dev->config;
dac_config_t dac_cfg;

DAC_GetDefaultConfig(&dac_cfg);

dac_cfg.conversionRate = config->conversion_rate;
dac_cfg.refSource = config->voltage_ref;
dac_cfg.rangeSelect = config->output_range;

DAC_Init(config->base, &dac_cfg);

/* Attack clock for GAU and reset */
CLOCK_AttachClk(kMAIN_CLK_to_GAU_CLK);
CLOCK_SetClkDiv(kCLOCK_DivGauClk, 1U);
CLOCK_EnableClock(kCLOCK_Gau);
RESET_PeripheralReset(kGAU_RST_SHIFT_RSTn);

POWER_PowerOnGau();

return 0;
};

int nxp_gau_deinit(const struct device *dev)
{
const struct nxp_gau_dac_config *config = dev->config;

DAC_Deinit(config->base);

pm_policy_device_power_lock_put(dev); /*Free the PM states*/

return 0;
}

static int dac_mcux_pm_action(const struct device *dev, enum pm_device_action action)
{
switch (action) {
case PM_DEVICE_ACTION_RESUME:
case PM_DEVICE_ACTION_SUSPEND:
case PM_DEVICE_ACTION_TURN_OFF:
break;
case PM_DEVICE_ACTION_TURN_ON:
nxp_gau_dac_init_common(dev);
break;
default:
return -ENOTSUP;
}
return 0;
}

#define NXP_GAU_DAC_INIT(inst) \
\
const struct nxp_gau_dac_config nxp_gau_dac_##inst##_config = { \
.base = (DAC_Type *) DT_INST_REG_ADDR(inst), \
.voltage_ref = DT_INST_ENUM_IDX(inst, nxp_dac_reference), \
.conversion_rate = DT_INST_ENUM_IDX(inst, nxp_conversion_rate), \
.output_range = DT_INST_ENUM_IDX(inst, \
nxp_output_voltage_range), \
}; \
\
\
DEVICE_DT_INST_DEFINE(inst, &nxp_gau_dac_init, NULL, \
NULL, \
PM_DEVICE_DT_INST_DEFINE(inst, dac_mcux_pm_action); \

Check warning on line 175 in drivers/dac/dac_mcux_gau.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

drivers/dac/dac_mcux_gau.c:175 line length of 129 exceeds 100 columns
DEVICE_DT_INST_DEFINE(inst, &nxp_gau_dac_init, PM_DEVICE_DT_INST_GET(inst), \

Check warning on line 176 in drivers/dac/dac_mcux_gau.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

drivers/dac/dac_mcux_gau.c:176 line length of 105 exceeds 100 columns
NULL, \
&nxp_gau_dac_##inst##_config, \
POST_KERNEL, CONFIG_DAC_INIT_PRIORITY, \
&nxp_gau_dac_driver_api);

DT_INST_FOREACH_STATUS_OKAY(NXP_GAU_DAC_INIT)
DT_INST_FOREACH_STATUS_OKAY(NXP_GAU_DAC_INIT)

Check warning on line 182 in drivers/dac/dac_mcux_gau.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

MISSING_EOF_NEWLINE

drivers/dac/dac_mcux_gau.c:182 adding a line without newline at end of file
1 change: 1 addition & 0 deletions dts/arm/nxp/nxp_rw6xx_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@
interrupts = <108 0>;
status = "disabled";
#io-channel-cells = <0>;
zephyr,disabling-power-states = <&suspend &standby>;
power-domains = <&power_mode3_domain>;
};
};
Expand Down
Loading