2021-12-21 08:38:38 +01:00
|
|
|
/****************************************************************************
|
2022-08-01 11:31:49 +02:00
|
|
|
* drivers/power/pm/pm_autoupdate.c
|
2021-12-21 08:38:38 +01:00
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/irq.h>
|
|
|
|
#include <nuttx/power/pm.h>
|
|
|
|
#include "pm.h"
|
|
|
|
|
|
|
|
#if defined(CONFIG_PM)
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void pm_auto_updatestate_cb(FAR void *arg)
|
|
|
|
{
|
2023-11-20 04:20:31 +01:00
|
|
|
int domain = (intptr_t)arg;
|
2021-12-21 08:38:38 +01:00
|
|
|
enum pm_state_e newstate;
|
2023-01-16 14:29:36 +01:00
|
|
|
irqstate_t flags;
|
|
|
|
|
2022-12-30 06:42:31 +01:00
|
|
|
flags = pm_domain_lock(domain);
|
2021-12-21 08:38:38 +01:00
|
|
|
|
|
|
|
newstate = pm_checkstate(domain);
|
|
|
|
pm_changestate(domain, newstate);
|
2023-01-16 14:29:36 +01:00
|
|
|
|
2022-12-30 06:42:31 +01:00
|
|
|
pm_domain_unlock(domain, flags);
|
2021-12-21 08:38:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_auto_updatestate
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function update the domain state and notify the power system.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* domain - The PM domain to check
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void pm_auto_updatestate(int domain)
|
|
|
|
{
|
|
|
|
FAR struct pm_domain_s *pdom;
|
2024-05-31 11:18:53 +02:00
|
|
|
pdom = &g_pmdomains[domain];
|
2021-12-21 08:38:38 +01:00
|
|
|
|
|
|
|
if (pdom->auto_update)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_SCHED_WORKQUEUE)
|
|
|
|
if (up_interrupt_context())
|
|
|
|
{
|
|
|
|
work_queue(HPWORK, &pdom->update_work,
|
2023-11-20 04:20:31 +01:00
|
|
|
pm_auto_updatestate_cb,
|
|
|
|
(FAR void *)(intptr_t)domain, 0);
|
2021-12-21 08:38:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2023-11-20 04:20:31 +01:00
|
|
|
pm_auto_updatestate_cb((FAR void *)(intptr_t)domain);
|
2021-12-21 08:38:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_auto_update
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function set the domain with assign mode.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* domain - The PM domain to check
|
|
|
|
* auto_update - The PM domain auto update or not
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void pm_auto_update(int domain, bool auto_update)
|
|
|
|
{
|
|
|
|
FAR struct pm_domain_s *pdom;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
|
2024-05-31 11:18:53 +02:00
|
|
|
pdom = &g_pmdomains[domain];
|
2021-12-21 08:38:38 +01:00
|
|
|
|
2022-12-30 06:42:31 +01:00
|
|
|
flags = pm_domain_lock(domain);
|
2021-12-21 08:38:38 +01:00
|
|
|
pdom->auto_update = auto_update;
|
2022-12-30 06:42:31 +01:00
|
|
|
pm_domain_unlock(domain, flags);
|
2021-12-21 08:38:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_PM */
|