|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#define DT_DRV_COMPAT nordic_nrf_gpio_pad_group |
| 8 | + |
| 9 | +#include <zephyr/kernel.h> |
| 10 | +#include <zephyr/device.h> |
| 11 | +#include <zephyr/pm/device.h> |
| 12 | +#include <zephyr/logging/log.h> |
| 13 | + |
| 14 | +#include <hal/nrf_gpio.h> |
| 15 | + |
| 16 | +LOG_MODULE_REGISTER(nrf_gpio_pad_group, CONFIG_POWER_DOMAIN_LOG_LEVEL); |
| 17 | + |
| 18 | +struct nrf_port_retain_config { |
| 19 | + NRF_GPIO_Type *regs; |
| 20 | + uint32_t retain_mask; |
| 21 | +}; |
| 22 | + |
| 23 | +static void nrf_port_retain_driver_turn_off(const struct device *dev) |
| 24 | +{ |
| 25 | + const struct nrf_port_retain_config *dev_config = dev->config; |
| 26 | + |
| 27 | + LOG_DBG("%s pads 0x%08x retain %s", dev->name, dev_config->retain_mask, "enable"); |
| 28 | + nrf_gpio_port_retain_enable(dev_config->regs, dev_config->retain_mask); |
| 29 | +} |
| 30 | + |
| 31 | +static void nrf_port_retain_driver_turn_on(const struct device *dev) |
| 32 | +{ |
| 33 | + const struct nrf_port_retain_config *dev_config = dev->config; |
| 34 | + |
| 35 | + LOG_DBG("%s pads 0x%08x retain %s", dev->name, dev_config->retain_mask, "disable"); |
| 36 | + nrf_gpio_port_retain_disable(dev_config->regs, dev_config->retain_mask); |
| 37 | +} |
| 38 | + |
| 39 | +static int nrf_port_retain_driver_pm_action(const struct device *dev, |
| 40 | + enum pm_device_action action) |
| 41 | +{ |
| 42 | + switch (action) { |
| 43 | + case PM_DEVICE_ACTION_TURN_OFF: |
| 44 | + nrf_port_retain_driver_turn_off(dev); |
| 45 | + break; |
| 46 | + |
| 47 | + case PM_DEVICE_ACTION_TURN_ON: |
| 48 | + nrf_port_retain_driver_turn_on(dev); |
| 49 | + break; |
| 50 | + |
| 51 | + default: |
| 52 | + break; |
| 53 | + }; |
| 54 | + |
| 55 | + return 0; |
| 56 | +} |
| 57 | + |
| 58 | +static int nrf_port_retain_driver_init(const struct device *dev) |
| 59 | +{ |
| 60 | + return pm_device_driver_init(dev, nrf_port_retain_driver_pm_action); |
| 61 | +} |
| 62 | + |
| 63 | +#define NRF_GPIO_PAD_GROUP_DEFINE(inst) \ |
| 64 | + static const struct nrf_port_retain_config _CONCAT(config, inst) = { \ |
| 65 | + .regs = (NRF_GPIO_Type *)DT_REG_ADDR(DT_INST_PARENT(inst)), \ |
| 66 | + .retain_mask = DT_PROP_OR(inst, retain_mask, UINT32_MAX), \ |
| 67 | + }; \ |
| 68 | + \ |
| 69 | + PM_DEVICE_DT_INST_DEFINE(inst, nrf_port_retain_driver_pm_action); \ |
| 70 | + \ |
| 71 | + DEVICE_DT_INST_DEFINE( \ |
| 72 | + inst, \ |
| 73 | + nrf_port_retain_driver_init, \ |
| 74 | + PM_DEVICE_DT_INST_GET(inst), \ |
| 75 | + NULL, \ |
| 76 | + &_CONCAT(config, inst), \ |
| 77 | + PRE_KERNEL_1, \ |
| 78 | + UTIL_INC(CONFIG_GPIO_INIT_PRIORITY), \ |
| 79 | + NULL \ |
| 80 | + ); |
| 81 | + |
| 82 | +DT_INST_FOREACH_STATUS_OKAY(NRF_GPIO_PAD_GROUP_DEFINE) |
0 commit comments