2011-09-05 03:24:27 +08:00
|
|
|
/****************************************************************************
|
2022-08-01 17:31:49 +08:00
|
|
|
* drivers/power/pm/pm.h
|
2011-09-05 03:24:27 +08:00
|
|
|
*
|
2021-03-31 17:15:31 +08: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
|
2011-09-05 03:24:27 +08:00
|
|
|
*
|
2021-03-31 17:15:31 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-09-05 03:24:27 +08:00
|
|
|
*
|
2021-03-31 17:15:31 +08:00
|
|
|
* 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.
|
2011-09-05 03:24:27 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-08-01 17:31:49 +08:00
|
|
|
#ifndef __DRIVERS_POWER_PM_PM_H
|
|
|
|
#define __DRIVERS_POWER_PM_PM_H
|
2011-09-05 03:24:27 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2022-09-25 23:08:38 +08:00
|
|
|
#include <nuttx/queue.h>
|
2022-05-29 23:59:14 +08:00
|
|
|
#include <nuttx/mutex.h>
|
2016-01-22 01:54:26 +08:00
|
|
|
#include <nuttx/clock.h>
|
|
|
|
#include <nuttx/power/pm.h>
|
2021-12-21 15:38:38 +08:00
|
|
|
#include <nuttx/wqueue.h>
|
2011-09-05 03:24:27 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-04-08 21:15:32 +08:00
|
|
|
* Pre-processor Definitions
|
2011-09-05 03:24:27 +08:00
|
|
|
****************************************************************************/
|
2019-10-29 08:28:41 +08:00
|
|
|
|
2011-09-05 03:24:27 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
2018-11-10 21:30:23 +08:00
|
|
|
|
2016-03-28 03:03:47 +08:00
|
|
|
/* This describes the activity and state for one domain */
|
2011-09-05 03:24:27 +08:00
|
|
|
|
2016-03-28 03:03:47 +08:00
|
|
|
struct pm_domain_s
|
2011-09-05 03:24:27 +08:00
|
|
|
{
|
2019-11-09 23:09:33 +08:00
|
|
|
/* The current state for this PM domain (as determined by an
|
|
|
|
* explicit call to pm_changestate())
|
2011-09-05 03:24:27 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
uint8_t state;
|
2018-11-10 21:30:23 +08:00
|
|
|
|
2018-08-28 03:16:34 +08:00
|
|
|
/* The power state lock count */
|
|
|
|
|
2022-06-16 18:21:36 +08:00
|
|
|
struct dq_queue_s wakelock[PM_COUNT];
|
2021-12-21 15:38:38 +08:00
|
|
|
|
2022-06-20 18:16:42 +08:00
|
|
|
#ifdef CONFIG_PM_PROCFS
|
|
|
|
struct dq_queue_s wakelockall;
|
|
|
|
struct timespec start;
|
|
|
|
struct timespec wake[PM_COUNT];
|
|
|
|
struct timespec sleep[PM_COUNT];
|
|
|
|
#endif
|
|
|
|
|
2021-12-21 15:38:38 +08:00
|
|
|
/* Auto update or not */
|
|
|
|
|
|
|
|
bool auto_update;
|
|
|
|
|
|
|
|
#if defined(CONFIG_SCHED_WORKQUEUE)
|
|
|
|
/* The worker of update callback */
|
|
|
|
|
|
|
|
struct work_s update_work;
|
|
|
|
#endif
|
2022-02-14 15:32:40 +08:00
|
|
|
|
|
|
|
/* A pointer to the PM governor instance */
|
|
|
|
|
|
|
|
FAR const struct pm_governor_s *governor;
|
2022-05-06 14:35:54 +08:00
|
|
|
|
2022-07-22 12:07:27 +08:00
|
|
|
/* Recursive lock for race condition */
|
2022-05-06 14:35:54 +08:00
|
|
|
|
2022-07-22 12:07:27 +08:00
|
|
|
rmutex_t lock;
|
2016-03-28 03:03:47 +08:00
|
|
|
};
|
|
|
|
|
2019-11-09 23:09:33 +08:00
|
|
|
/* This structure encapsulates all of the global data used by the PM system */
|
2016-03-28 03:03:47 +08:00
|
|
|
|
|
|
|
struct pm_global_s
|
|
|
|
{
|
2022-09-06 14:18:45 +08:00
|
|
|
/* This mutex manages mutually exclusive access to the power management
|
2011-09-05 03:24:27 +08:00
|
|
|
* registry. It must be initialized to the value 1.
|
|
|
|
*/
|
|
|
|
|
2022-09-06 14:18:45 +08:00
|
|
|
mutex_t reglock;
|
2011-09-05 03:24:27 +08:00
|
|
|
|
2018-08-28 03:22:11 +08:00
|
|
|
/* registry is a doubly-linked list of registered power management
|
2011-09-05 03:24:27 +08:00
|
|
|
* callback structures. To ensure mutually exclusive access, this list
|
|
|
|
* must be locked by calling pm_lock() before it is accessed.
|
|
|
|
*/
|
|
|
|
|
2018-08-28 03:22:11 +08:00
|
|
|
dq_queue_t registry;
|
2018-08-28 03:24:13 +08:00
|
|
|
|
2019-11-09 23:09:33 +08:00
|
|
|
/* The state information for each PM domain */
|
2018-08-28 03:24:13 +08:00
|
|
|
|
|
|
|
struct pm_domain_s domain[CONFIG_PM_NDOMAINS];
|
2011-09-05 03:24:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
# define EXTERN extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
# define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* All PM global data: */
|
|
|
|
|
|
|
|
EXTERN struct pm_global_s g_pmglobals;
|
|
|
|
|
2021-04-01 14:20:14 +08:00
|
|
|
/****************************************************************************
|
2011-09-05 03:24:27 +08:00
|
|
|
* Public Function Prototypes
|
2021-04-01 14:20:14 +08:00
|
|
|
****************************************************************************/
|
2011-09-05 03:24:27 +08:00
|
|
|
|
2022-03-15 20:42:34 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_lock
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Lock the power management operation.
|
|
|
|
*
|
2022-05-06 14:35:54 +08:00
|
|
|
* Input Parameters:
|
|
|
|
* domain - The PM domain to lock
|
|
|
|
*
|
2022-03-15 20:42:34 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2022-05-06 14:35:54 +08:00
|
|
|
irqstate_t pm_lock(int domain);
|
2022-03-15 20:42:34 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_unlock
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Unlock the power management operation.
|
|
|
|
*
|
2022-05-06 14:35:54 +08:00
|
|
|
* Input Parameters:
|
|
|
|
* domain - The PM domain to unlock
|
|
|
|
*
|
2022-03-15 20:42:34 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2022-05-06 14:35:54 +08:00
|
|
|
void pm_unlock(int domain, irqstate_t flags);
|
2022-03-15 20:42:34 +08:00
|
|
|
|
2022-06-16 18:21:36 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_wakelock_global_init
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called to setup global wakelock when system init
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void pm_wakelock_global_init(void);
|
|
|
|
|
2011-09-05 03:24:27 +08:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CONFIG_PM */
|
2022-08-01 17:31:49 +08:00
|
|
|
#endif /* #define __DRIVERS_POWER_PM_PM_H */
|