2019-10-21 16:14:33 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/modem/altair/altmdm_pm.c
|
|
|
|
*
|
2021-01-25 10:00:05 +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
|
2019-10-21 16:14:33 +02:00
|
|
|
*
|
2021-01-25 10:00:05 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2019-10-21 16:14:33 +02:00
|
|
|
*
|
2021-01-25 10:00:05 +01: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.
|
2019-10-21 16:14:33 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2019-10-21 16:14:33 +02:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/kmalloc.h>
|
2019-11-30 00:37:39 +01:00
|
|
|
#include <nuttx/signal.h>
|
2019-10-21 16:14:33 +02:00
|
|
|
#include <nuttx/modem/altmdm.h>
|
2019-11-30 00:37:39 +01:00
|
|
|
|
2019-10-21 16:14:33 +02:00
|
|
|
#include "altmdm_sys.h"
|
|
|
|
#include "altmdm_pm.h"
|
|
|
|
#include "altmdm_pm_state.h"
|
|
|
|
|
|
|
|
#if defined(CONFIG_MODEM_ALTMDM)
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Timeout is counted in units of millisecond. */
|
|
|
|
|
|
|
|
# define D2H_UP_EVENT_TIMEOUT (5*1000)
|
|
|
|
|
|
|
|
# define GPIO_LOW (false)
|
|
|
|
# define GPIO_HIGH (true)
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static struct altmdm_dev_s *g_privdata = NULL;
|
|
|
|
static bool g_is_initdone = false;
|
|
|
|
static altmdm_pm_cbfunc_t g_pm_callback = NULL;
|
|
|
|
static altmdm_pm_cbfunc_t g_pm_errcallback = NULL;
|
|
|
|
static sq_queue_t g_wakelock;
|
|
|
|
static uint32_t g_boot_stat = MODEM_PM_ERR_RESET_BOOTSTAT_NONE;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: set_mreq_gpio
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Control Master-request GPIO line.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int set_mreq_gpio(FAR struct altmdm_dev_s *priv, bool value)
|
|
|
|
{
|
2020-07-27 06:49:53 +02:00
|
|
|
DEBUGASSERT(priv && priv->lower);
|
|
|
|
priv->lower->master_request(value);
|
|
|
|
|
2019-10-21 16:14:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: set_h2d_gpio
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Control Host to Device GPIO line.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int set_h2d_gpio(FAR struct altmdm_dev_s *priv, bool value)
|
|
|
|
{
|
2020-07-27 06:49:53 +02:00
|
|
|
DEBUGASSERT(priv && priv->lower);
|
|
|
|
priv->lower->wakeup(value);
|
2019-10-21 16:14:33 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: set_mreq_down
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Deassert Master-request GPIO line.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int set_mreq_down(FAR struct altmdm_dev_s *priv)
|
|
|
|
{
|
|
|
|
return set_mreq_gpio(priv, GPIO_LOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-07-27 06:49:53 +02:00
|
|
|
* Name: set_mreq_up
|
2019-10-21 16:14:33 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2020-07-27 06:49:53 +02:00
|
|
|
* Assert Master-request GPIO line.
|
2019-10-21 16:14:33 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
static int set_mreq_up(FAR struct altmdm_dev_s *priv)
|
2019-10-21 16:14:33 +02:00
|
|
|
{
|
2020-07-27 06:49:53 +02:00
|
|
|
return set_mreq_gpio(priv, GPIO_HIGH);
|
2019-10-21 16:14:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-07-27 06:49:53 +02:00
|
|
|
* Name: set_h2d_down
|
2019-10-21 16:14:33 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2020-07-27 06:49:53 +02:00
|
|
|
* Deassert Host to Device GPIO line.
|
2019-10-21 16:14:33 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
static int set_h2d_down(FAR struct altmdm_dev_s *priv)
|
2019-10-21 16:14:33 +02:00
|
|
|
{
|
2020-07-27 06:49:53 +02:00
|
|
|
return set_h2d_gpio(priv, GPIO_LOW);
|
2019-10-21 16:14:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-07-27 06:49:53 +02:00
|
|
|
* Name: set_h2d_up
|
2019-10-21 16:14:33 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2020-07-27 06:49:53 +02:00
|
|
|
* Assert Host to Device GPIO line.
|
2019-10-21 16:14:33 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
static int set_h2d_up(FAR struct altmdm_dev_s *priv)
|
2019-10-21 16:14:33 +02:00
|
|
|
{
|
2020-07-27 06:49:53 +02:00
|
|
|
return set_h2d_gpio(priv, GPIO_HIGH);
|
2019-10-21 16:14:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: exe_callback
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Execute callback of modem power manager.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int exe_callback(uint32_t type, uint32_t cb_event)
|
|
|
|
{
|
|
|
|
altmdm_pm_cbfunc_t lcallback = NULL;
|
|
|
|
|
|
|
|
if (type == MODEM_PM_CB_TYPE_ERROR)
|
|
|
|
{
|
|
|
|
lcallback = g_pm_errcallback;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lcallback = g_pm_callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lcallback == NULL)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
2019-10-21 16:51:47 +02:00
|
|
|
|
2019-10-21 16:14:33 +02:00
|
|
|
lcallback(cb_event);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: sleep_modem_itself
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The modem slept on itself, it transitions to the sleep state.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int sleep_modem_itself(FAR struct altmdm_dev_s *priv)
|
|
|
|
{
|
|
|
|
set_h2d_down(priv);
|
|
|
|
|
|
|
|
/* Transitions to the sleep state. */
|
|
|
|
|
|
|
|
altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_SLEEP);
|
|
|
|
|
|
|
|
/* Perform processing at the time of state transition. */
|
|
|
|
|
|
|
|
exe_callback(MODEM_PM_CB_TYPE_NORMAL, MODEM_PM_CB_SLEEP);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: modem_sleep_procedure
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Make the modem transition to sleep.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int modem_sleep_procedure(FAR struct altmdm_dev_s *priv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = set_h2d_down(priv);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
/* Transitions to the sleep state. */
|
|
|
|
|
|
|
|
altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_SLEEP);
|
|
|
|
|
|
|
|
/* Perform processing at the time of state transition. */
|
|
|
|
|
|
|
|
exe_callback(MODEM_PM_CB_TYPE_NORMAL, MODEM_PM_CB_SLEEP);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: modem_wakeup_procedure
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Make the modem transition to wakeup.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
static int modem_wakeup_procedure(FAR struct altmdm_dev_s *priv,
|
|
|
|
CODE int (*wait_fn)(FAR struct altmdm_dev_s *priv, uint32_t timeout_ms))
|
2019-10-21 16:14:33 +02:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
if (MODEM_PM_INTERNAL_STATE_WAKE == altmdm_pm_getinternalstate())
|
|
|
|
{
|
|
|
|
return MODEM_PM_WAKEUP_ALREADY;
|
|
|
|
}
|
|
|
|
|
2019-10-21 16:14:33 +02:00
|
|
|
altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_GOING_TO_WAKE);
|
|
|
|
|
|
|
|
ret = set_h2d_up(priv);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
2020-07-27 06:49:53 +02:00
|
|
|
if (wait_fn)
|
2019-10-21 16:14:33 +02:00
|
|
|
{
|
2020-07-27 06:49:53 +02:00
|
|
|
set_mreq_up(priv);
|
2019-10-21 16:14:33 +02:00
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
ret = wait_fn(priv, D2H_UP_EVENT_TIMEOUT);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
m_err("ERR:%04d device is not up.\n", __LINE__);
|
2019-10-21 16:14:33 +02:00
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
/* Do rollback. */
|
|
|
|
|
|
|
|
set_mreq_down(priv);
|
|
|
|
|
|
|
|
set_h2d_down(priv);
|
|
|
|
|
|
|
|
altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_SLEEP);
|
|
|
|
|
|
|
|
ret = MODEM_PM_WAKEUP_FAIL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Transitions to the wake state. */
|
|
|
|
|
|
|
|
altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_WAKE);
|
|
|
|
|
|
|
|
/* Perform processing at the time of state transition. */
|
|
|
|
|
|
|
|
exe_callback(MODEM_PM_CB_TYPE_NORMAL, MODEM_PM_CB_WAKE);
|
2019-10-21 16:14:33 +02:00
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
ret = MODEM_PM_WAKEUP_DONE;
|
|
|
|
}
|
2019-10-21 16:14:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Transitions to the wake state. */
|
|
|
|
|
|
|
|
altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_WAKE);
|
|
|
|
|
|
|
|
/* Perform processing at the time of state transition. */
|
|
|
|
|
|
|
|
exe_callback(MODEM_PM_CB_TYPE_NORMAL, MODEM_PM_CB_WAKE);
|
2020-07-27 06:49:53 +02:00
|
|
|
|
|
|
|
ret = MODEM_PM_WAKEUP_DONE;
|
2019-10-21 16:14:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: sleep_is_possible
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if the modem can sleep.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int sleep_is_possible(FAR struct altmdm_dev_s *priv)
|
|
|
|
{
|
|
|
|
# ifdef CONFIG_MODEM_ALTMDM_KEEP_WAKE_STATE
|
|
|
|
return -EPERM;
|
|
|
|
# else
|
|
|
|
int num_of_lock;
|
|
|
|
uint32_t pm_state;
|
|
|
|
|
|
|
|
pm_state = altmdm_pm_getinternalstate();
|
|
|
|
if (pm_state != MODEM_PM_INTERNAL_STATE_WAKE)
|
|
|
|
{
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
num_of_lock = altmdm_pm_getwakelockstate();
|
|
|
|
if (num_of_lock)
|
|
|
|
{
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_boot_stat != MODEM_PM_ERR_RESET_BOOTSTAT_DONE)
|
|
|
|
{
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_init
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize the ALTMDM power manager driver.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_init(FAR struct altmdm_dev_s *priv)
|
|
|
|
{
|
|
|
|
if (g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_is_initdone = true;
|
|
|
|
|
|
|
|
g_privdata = priv;
|
|
|
|
|
|
|
|
altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_SLEEP);
|
|
|
|
|
|
|
|
sq_init(&g_wakelock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_uninit
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Uninitialize the ALTMDM power manager driver.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_uninit(FAR struct altmdm_dev_s *priv)
|
|
|
|
{
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_is_initdone = false;
|
|
|
|
|
|
|
|
altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_SLEEP);
|
|
|
|
|
|
|
|
sq_init(&g_wakelock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_wakeup
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Make modem wake up.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
int altmdm_pm_wakeup(FAR struct altmdm_dev_s *priv,
|
|
|
|
CODE int (*wait_fn)(FAR struct altmdm_dev_s *priv, uint32_t timeout_ms))
|
2019-10-21 16:14:33 +02:00
|
|
|
{
|
2020-07-27 06:49:53 +02:00
|
|
|
int ret = MODEM_PM_WAKEUP_FAIL;
|
2019-10-21 16:14:33 +02:00
|
|
|
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
ret = modem_wakeup_procedure(priv, wait_fn);
|
2019-10-21 16:14:33 +02:00
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
return ret;
|
2019-10-21 16:14:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_notify_reset
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Notify reset has done.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_notify_reset(FAR struct altmdm_dev_s *priv)
|
|
|
|
{
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
if (MODEM_PM_ERR_RESET_BOOTSTAT_NONE != g_boot_stat)
|
2019-10-21 16:14:33 +02:00
|
|
|
{
|
2020-07-27 06:49:53 +02:00
|
|
|
exe_callback(MODEM_PM_CB_TYPE_ERROR, g_boot_stat);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_err("ERR:%04d Unexpected boot stat:%d.\n",
|
|
|
|
__LINE__, g_boot_stat);
|
2019-10-21 16:14:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_registercb
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Register callback for ALTMDM power manager driver.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_registercb(uint32_t type, altmdm_pm_cbfunc_t cb)
|
|
|
|
{
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == MODEM_PM_CB_TYPE_ERROR)
|
|
|
|
{
|
|
|
|
if (g_pm_errcallback == NULL)
|
|
|
|
{
|
|
|
|
g_pm_errcallback = cb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (g_pm_callback == NULL)
|
|
|
|
{
|
|
|
|
g_pm_callback = cb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_deregistercb
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Deregister callback for ALTMDM power manager driver.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_deregistercb(uint32_t type)
|
|
|
|
{
|
|
|
|
altmdm_pm_cbfunc_t *lcallback = NULL;
|
|
|
|
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == MODEM_PM_CB_TYPE_ERROR)
|
|
|
|
{
|
|
|
|
lcallback = &g_pm_errcallback;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lcallback = &g_pm_callback;
|
|
|
|
}
|
2020-07-27 06:49:53 +02:00
|
|
|
|
2019-10-21 16:14:33 +02:00
|
|
|
if (*lcallback == NULL)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
*lcallback = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_sleepmodem
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Make modem sleep.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_sleepmodem(FAR struct altmdm_dev_s *priv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_GOING_TO_SLEEP);
|
|
|
|
ret = modem_sleep_procedure(priv);
|
2019-10-21 16:14:33 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_cansleep
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if modem can sleep.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_cansleep(FAR struct altmdm_dev_s *priv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = sleep_is_possible(priv);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
m_info("possible to sleep.\n");
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_info("impossible to sleep.\n");
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_initwakelock
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize the modem wakelock resource.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_initwakelock(FAR struct altmdm_pm_wakelock_s *lock)
|
|
|
|
{
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lock)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(lock, 0, sizeof(struct altmdm_pm_wakelock_s));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_acquirewakelock
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Acquire the modem wakelock.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_acquirewakelock(FAR struct altmdm_pm_wakelock_s *lock)
|
|
|
|
{
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lock)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
if (lock->count == 0)
|
|
|
|
{
|
|
|
|
sq_addlast((FAR sq_entry_t *) & lock->queue, &g_wakelock);
|
|
|
|
}
|
2020-07-27 06:49:53 +02:00
|
|
|
|
2019-10-21 16:14:33 +02:00
|
|
|
lock->count++;
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_releasewakelock
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Release the modem wakelock.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_releasewakelock(FAR struct altmdm_pm_wakelock_s *lock)
|
|
|
|
{
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lock && (lock->count < 1))
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
lock->count--;
|
|
|
|
|
|
|
|
if (lock->count == 0)
|
|
|
|
{
|
|
|
|
sq_rem((FAR sq_entry_t *) & lock->queue, &g_wakelock);
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_getnumofwakelock
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the lock count of the specified wakelock.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_getnumofwakelock(FAR struct altmdm_pm_wakelock_s *lock)
|
|
|
|
{
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lock)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lock->count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_getwakelockstate
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the wakelock status. If the return value is 0, it means that it is
|
|
|
|
* not locked. Otherwise it means that someone is locking.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_getwakelockstate(void)
|
|
|
|
{
|
|
|
|
int num;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
num = sq_count(&g_wakelock);
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_poweron
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Modem power on.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_poweron(FAR struct altmdm_dev_s *priv)
|
|
|
|
{
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
priv->lower->poweron();
|
2019-10-21 16:14:33 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_poweroff
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Modem power off.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_poweroff(FAR struct altmdm_dev_s *priv)
|
|
|
|
{
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
2020-07-27 06:49:53 +02:00
|
|
|
priv->lower->poweroff();
|
|
|
|
sleep_modem_itself(priv);
|
2019-10-21 16:14:33 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: altmdm_pm_set_bootstatus
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set boot status.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int altmdm_pm_set_bootstatus(FAR struct altmdm_dev_s *priv, uint32_t status)
|
|
|
|
{
|
|
|
|
if (!g_is_initdone)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_boot_stat = status;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|