2020-03-06 04:28:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
|
2021-02-12 14:33:59 +00:00
|
|
|
* Copyright (C) 2018-2021 Linaro Ltd.
|
2020-03-06 04:28:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/interconnect.h>
|
2021-08-04 15:36:24 +00:00
|
|
|
#include <linux/pm.h>
|
2021-08-10 19:27:00 +00:00
|
|
|
#include <linux/pm_runtime.h>
|
2021-08-04 15:36:24 +00:00
|
|
|
#include <linux/bitops.h>
|
2020-03-06 04:28:19 +00:00
|
|
|
|
|
|
|
#include "ipa.h"
|
2021-08-20 16:01:29 +00:00
|
|
|
#include "ipa_power.h"
|
2021-08-04 15:36:24 +00:00
|
|
|
#include "ipa_endpoint.h"
|
2020-03-06 04:28:19 +00:00
|
|
|
#include "ipa_modem.h"
|
2020-11-19 22:40:39 +00:00
|
|
|
#include "ipa_data.h"
|
2020-03-06 04:28:19 +00:00
|
|
|
|
|
|
|
/**
|
2021-08-20 16:01:28 +00:00
|
|
|
* DOC: IPA Power Management
|
2020-03-06 04:28:19 +00:00
|
|
|
*
|
2021-08-20 16:01:28 +00:00
|
|
|
* The IPA hardware is enabled when the IPA core clock and all the
|
|
|
|
* interconnects (buses) it depends on are enabled. Runtime power
|
|
|
|
* management is used to determine whether the core clock and
|
|
|
|
* interconnects are enabled, and if not in use to be suspended
|
|
|
|
* automatically.
|
2020-03-06 04:28:19 +00:00
|
|
|
*
|
2021-08-20 16:01:28 +00:00
|
|
|
* The core clock currently runs at a fixed clock rate when enabled,
|
|
|
|
* an all interconnects use a fixed average and peak bandwidth.
|
2020-03-06 04:28:19 +00:00
|
|
|
*/
|
|
|
|
|
2021-08-20 16:01:27 +00:00
|
|
|
#define IPA_AUTOSUSPEND_DELAY 500 /* milliseconds */
|
|
|
|
|
2021-01-15 12:50:46 +00:00
|
|
|
/**
|
|
|
|
* struct ipa_interconnect - IPA interconnect information
|
|
|
|
* @path: Interconnect path
|
2021-01-15 12:50:47 +00:00
|
|
|
* @average_bandwidth: Average interconnect bandwidth (KB/second)
|
|
|
|
* @peak_bandwidth: Peak interconnect bandwidth (KB/second)
|
2021-01-15 12:50:46 +00:00
|
|
|
*/
|
|
|
|
struct ipa_interconnect {
|
|
|
|
struct icc_path *path;
|
2021-01-15 12:50:47 +00:00
|
|
|
u32 average_bandwidth;
|
|
|
|
u32 peak_bandwidth;
|
2021-01-15 12:50:46 +00:00
|
|
|
};
|
|
|
|
|
2021-08-04 15:36:26 +00:00
|
|
|
/**
|
|
|
|
* enum ipa_power_flag - IPA power flags
|
|
|
|
* @IPA_POWER_FLAG_RESUMED: Whether resume from suspend has been signaled
|
2021-08-12 19:50:31 +00:00
|
|
|
* @IPA_POWER_FLAG_SYSTEM: Hardware is system (not runtime) suspended
|
2021-08-19 21:12:28 +00:00
|
|
|
* @IPA_POWER_FLAG_STOPPED: Modem TX is disabled by ipa_start_xmit()
|
|
|
|
* @IPA_POWER_FLAG_STARTED: Modem TX was enabled by ipa_runtime_resume()
|
2021-08-04 15:36:26 +00:00
|
|
|
* @IPA_POWER_FLAG_COUNT: Number of defined power flags
|
|
|
|
*/
|
|
|
|
enum ipa_power_flag {
|
|
|
|
IPA_POWER_FLAG_RESUMED,
|
2021-08-12 19:50:31 +00:00
|
|
|
IPA_POWER_FLAG_SYSTEM,
|
2021-08-19 21:12:28 +00:00
|
|
|
IPA_POWER_FLAG_STOPPED,
|
|
|
|
IPA_POWER_FLAG_STARTED,
|
2021-08-04 15:36:26 +00:00
|
|
|
IPA_POWER_FLAG_COUNT, /* Last; not a flag */
|
|
|
|
};
|
|
|
|
|
2020-03-06 04:28:19 +00:00
|
|
|
/**
|
2021-08-20 16:01:28 +00:00
|
|
|
* struct ipa_power - IPA power management information
|
2021-08-10 19:27:01 +00:00
|
|
|
* @dev: IPA device pointer
|
2020-03-06 04:28:19 +00:00
|
|
|
* @core: IPA core clock
|
2021-08-19 21:12:28 +00:00
|
|
|
* @spinlock: Protects modem TX queue enable/disable
|
2021-08-04 15:36:26 +00:00
|
|
|
* @flags: Boolean state flags
|
2021-01-15 12:50:50 +00:00
|
|
|
* @interconnect_count: Number of elements in interconnect[]
|
2021-01-15 12:50:46 +00:00
|
|
|
* @interconnect: Interconnect array
|
2020-03-06 04:28:19 +00:00
|
|
|
*/
|
2021-08-20 16:01:28 +00:00
|
|
|
struct ipa_power {
|
2021-08-10 19:27:01 +00:00
|
|
|
struct device *dev;
|
2020-03-06 04:28:19 +00:00
|
|
|
struct clk *core;
|
2021-08-19 21:12:28 +00:00
|
|
|
spinlock_t spinlock; /* used with STOPPED/STARTED power flags */
|
2021-08-04 15:36:26 +00:00
|
|
|
DECLARE_BITMAP(flags, IPA_POWER_FLAG_COUNT);
|
2021-01-15 12:50:50 +00:00
|
|
|
u32 interconnect_count;
|
|
|
|
struct ipa_interconnect *interconnect;
|
2020-03-06 04:28:19 +00:00
|
|
|
};
|
|
|
|
|
2021-01-15 12:50:49 +00:00
|
|
|
static int ipa_interconnect_init_one(struct device *dev,
|
|
|
|
struct ipa_interconnect *interconnect,
|
|
|
|
const struct ipa_interconnect_data *data)
|
2020-03-06 04:28:19 +00:00
|
|
|
{
|
|
|
|
struct icc_path *path;
|
|
|
|
|
2021-01-15 12:50:49 +00:00
|
|
|
path = of_icc_get(dev, data->name);
|
|
|
|
if (IS_ERR(path)) {
|
|
|
|
int ret = PTR_ERR(path);
|
2020-03-06 04:28:19 +00:00
|
|
|
|
2021-02-12 14:33:59 +00:00
|
|
|
dev_err_probe(dev, ret, "error getting %s interconnect\n",
|
|
|
|
data->name);
|
2021-01-15 12:50:49 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
interconnect->path = path;
|
|
|
|
interconnect->average_bandwidth = data->average_bandwidth;
|
|
|
|
interconnect->peak_bandwidth = data->peak_bandwidth;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ipa_interconnect_exit_one(struct ipa_interconnect *interconnect)
|
|
|
|
{
|
|
|
|
icc_put(interconnect->path);
|
|
|
|
memset(interconnect, 0, sizeof(*interconnect));
|
2020-03-06 04:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize interconnects required for IPA operation */
|
2021-08-20 16:01:28 +00:00
|
|
|
static int ipa_interconnect_init(struct ipa_power *power, struct device *dev,
|
2021-01-15 12:50:47 +00:00
|
|
|
const struct ipa_interconnect_data *data)
|
2020-03-06 04:28:19 +00:00
|
|
|
{
|
2021-01-15 12:50:47 +00:00
|
|
|
struct ipa_interconnect *interconnect;
|
2021-01-15 12:50:50 +00:00
|
|
|
u32 count;
|
2021-01-15 12:50:49 +00:00
|
|
|
int ret;
|
2020-03-06 04:28:19 +00:00
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
count = power->interconnect_count;
|
2021-01-15 12:50:50 +00:00
|
|
|
interconnect = kcalloc(count, sizeof(*interconnect), GFP_KERNEL);
|
|
|
|
if (!interconnect)
|
|
|
|
return -ENOMEM;
|
2021-08-20 16:01:28 +00:00
|
|
|
power->interconnect = interconnect;
|
2021-01-15 12:50:50 +00:00
|
|
|
|
|
|
|
while (count--) {
|
|
|
|
ret = ipa_interconnect_init_one(dev, interconnect, data++);
|
|
|
|
if (ret)
|
|
|
|
goto out_unwind;
|
|
|
|
interconnect++;
|
|
|
|
}
|
2020-03-06 04:28:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2021-01-15 12:50:50 +00:00
|
|
|
out_unwind:
|
2021-08-20 16:01:28 +00:00
|
|
|
while (interconnect-- > power->interconnect)
|
2021-01-15 12:50:50 +00:00
|
|
|
ipa_interconnect_exit_one(interconnect);
|
2021-08-20 16:01:28 +00:00
|
|
|
kfree(power->interconnect);
|
|
|
|
power->interconnect = NULL;
|
2021-01-15 12:50:49 +00:00
|
|
|
|
|
|
|
return ret;
|
2020-03-06 04:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Inverse of ipa_interconnect_init() */
|
2021-08-20 16:01:28 +00:00
|
|
|
static void ipa_interconnect_exit(struct ipa_power *power)
|
2020-03-06 04:28:19 +00:00
|
|
|
{
|
2021-01-15 12:50:49 +00:00
|
|
|
struct ipa_interconnect *interconnect;
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
interconnect = power->interconnect + power->interconnect_count;
|
|
|
|
while (interconnect-- > power->interconnect)
|
2021-01-15 12:50:50 +00:00
|
|
|
ipa_interconnect_exit_one(interconnect);
|
2021-08-20 16:01:28 +00:00
|
|
|
kfree(power->interconnect);
|
|
|
|
power->interconnect = NULL;
|
2020-03-06 04:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Currently we only use one bandwidth level, so just "enable" interconnects */
|
|
|
|
static int ipa_interconnect_enable(struct ipa *ipa)
|
|
|
|
{
|
2021-01-15 12:50:47 +00:00
|
|
|
struct ipa_interconnect *interconnect;
|
2021-08-20 16:01:28 +00:00
|
|
|
struct ipa_power *power = ipa->power;
|
2020-03-06 04:28:19 +00:00
|
|
|
int ret;
|
2021-01-15 12:50:50 +00:00
|
|
|
u32 i;
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
interconnect = power->interconnect;
|
|
|
|
for (i = 0; i < power->interconnect_count; i++) {
|
2021-01-15 12:50:50 +00:00
|
|
|
ret = icc_set_bw(interconnect->path,
|
|
|
|
interconnect->average_bandwidth,
|
|
|
|
interconnect->peak_bandwidth);
|
2021-08-04 15:36:23 +00:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&ipa->pdev->dev,
|
|
|
|
"error %d enabling %s interconnect\n",
|
|
|
|
ret, icc_get_name(interconnect->path));
|
2021-01-15 12:50:50 +00:00
|
|
|
goto out_unwind;
|
2021-08-04 15:36:23 +00:00
|
|
|
}
|
2021-01-15 12:50:50 +00:00
|
|
|
interconnect++;
|
|
|
|
}
|
2020-03-06 04:28:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2021-01-15 12:50:50 +00:00
|
|
|
out_unwind:
|
2021-08-20 16:01:28 +00:00
|
|
|
while (interconnect-- > power->interconnect)
|
2021-01-15 12:50:50 +00:00
|
|
|
(void)icc_set_bw(interconnect->path, 0, 0);
|
2020-03-06 04:28:19 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* To disable an interconnect, we just its bandwidth to 0 */
|
2021-08-04 15:36:23 +00:00
|
|
|
static int ipa_interconnect_disable(struct ipa *ipa)
|
2020-03-06 04:28:19 +00:00
|
|
|
{
|
2021-01-15 12:50:47 +00:00
|
|
|
struct ipa_interconnect *interconnect;
|
2021-08-20 16:01:28 +00:00
|
|
|
struct ipa_power *power = ipa->power;
|
2021-08-04 15:36:23 +00:00
|
|
|
struct device *dev = &ipa->pdev->dev;
|
2021-01-15 12:50:45 +00:00
|
|
|
int result = 0;
|
2021-01-15 12:50:50 +00:00
|
|
|
u32 count;
|
2020-03-06 04:28:19 +00:00
|
|
|
int ret;
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
count = power->interconnect_count;
|
|
|
|
interconnect = power->interconnect + count;
|
2021-01-15 12:50:50 +00:00
|
|
|
while (count--) {
|
|
|
|
interconnect--;
|
|
|
|
ret = icc_set_bw(interconnect->path, 0, 0);
|
2021-08-04 15:36:23 +00:00
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "error %d disabling %s interconnect\n",
|
|
|
|
ret, icc_get_name(interconnect->path));
|
|
|
|
/* Try to disable all; record only the first error */
|
|
|
|
if (!result)
|
|
|
|
result = ret;
|
|
|
|
}
|
2021-01-15 12:50:50 +00:00
|
|
|
}
|
2020-03-06 04:28:19 +00:00
|
|
|
|
2021-08-04 15:36:23 +00:00
|
|
|
return result;
|
2020-03-06 04:28:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
/* Enable IPA power, enabling interconnects and the core clock */
|
|
|
|
static int ipa_power_enable(struct ipa *ipa)
|
2020-03-06 04:28:19 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ipa_interconnect_enable(ipa);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
ret = clk_prepare_enable(ipa->power->core);
|
2021-08-04 15:36:23 +00:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&ipa->pdev->dev, "error %d enabling core clock\n", ret);
|
|
|
|
(void)ipa_interconnect_disable(ipa);
|
|
|
|
}
|
2020-03-06 04:28:19 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
/* Inverse of ipa_power_enable() */
|
|
|
|
static int ipa_power_disable(struct ipa *ipa)
|
2020-03-06 04:28:19 +00:00
|
|
|
{
|
2021-08-20 16:01:28 +00:00
|
|
|
clk_disable_unprepare(ipa->power->core);
|
net: ipa: have ipa_clock_get() return a value
We currently assume no errors occur when enabling or disabling the
IPA core clock and interconnects. And although this commit exposes
errors that could occur, we generally assume this won't happen in
practice.
This commit changes ipa_clock_get() and ipa_clock_put() so each
returns a value. The values returned are meant to mimic what the
runtime power management functions return, so we can set up error
handling here before we make the switch. Have ipa_clock_get()
increment the reference count even if it returns an error, to match
the behavior of pm_runtime_get().
More details follow.
When taking a reference in ipa_clock_get(), return 0 for the first
reference, 1 for subsequent references, or a negative error code if
an error occurs. Note that if ipa_clock_get() returns an error, we
must not touch hardware; in some cases such errors now cause entire
blocks of code to be skipped.
When dropping a reference in ipa_clock_put(), we return 0 or an
error code. The error would come from ipa_clock_disable(), which
now returns what ipa_interconnect_disable() returns (either 0 or a
negative error code). For now, callers ignore the return value;
if an error occurs, a message will have already been logged, and
little more can actually be done to improve the situation.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-08-10 19:26:58 +00:00
|
|
|
|
|
|
|
return ipa_interconnect_disable(ipa);
|
2020-03-06 04:28:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 19:27:00 +00:00
|
|
|
static int ipa_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct ipa *ipa = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
/* Endpoints aren't usable until setup is complete */
|
|
|
|
if (ipa->setup_complete) {
|
2021-08-20 16:01:28 +00:00
|
|
|
__clear_bit(IPA_POWER_FLAG_RESUMED, ipa->power->flags);
|
2021-08-10 19:27:00 +00:00
|
|
|
ipa_endpoint_suspend(ipa);
|
|
|
|
gsi_suspend(&ipa->gsi);
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
return ipa_power_disable(ipa);
|
2021-08-10 19:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ipa_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct ipa *ipa = dev_get_drvdata(dev);
|
|
|
|
int ret;
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
ret = ipa_power_enable(ipa);
|
2021-08-10 19:27:00 +00:00
|
|
|
if (WARN_ON(ret < 0))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Endpoints aren't usable until setup is complete */
|
|
|
|
if (ipa->setup_complete) {
|
|
|
|
gsi_resume(&ipa->gsi);
|
|
|
|
ipa_endpoint_resume(ipa);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-12 19:50:31 +00:00
|
|
|
static int ipa_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct ipa *ipa = dev_get_drvdata(dev);
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
__set_bit(IPA_POWER_FLAG_SYSTEM, ipa->power->flags);
|
2021-08-12 19:50:31 +00:00
|
|
|
|
|
|
|
return pm_runtime_force_suspend(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipa_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct ipa *ipa = dev_get_drvdata(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pm_runtime_force_resume(dev);
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
__clear_bit(IPA_POWER_FLAG_SYSTEM, ipa->power->flags);
|
2021-08-12 19:50:31 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-07-03 21:23:34 +00:00
|
|
|
/* Return the current IPA core clock rate */
|
2021-08-20 16:01:28 +00:00
|
|
|
u32 ipa_core_clock_rate(struct ipa *ipa)
|
2020-07-03 21:23:34 +00:00
|
|
|
{
|
2021-08-20 16:01:28 +00:00
|
|
|
return ipa->power ? (u32)clk_get_rate(ipa->power->core) : 0;
|
2020-07-03 21:23:34 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 15:36:25 +00:00
|
|
|
/**
|
|
|
|
* ipa_suspend_handler() - Handle the suspend IPA interrupt
|
|
|
|
* @ipa: IPA pointer
|
|
|
|
* @irq_id: IPA interrupt type (unused)
|
|
|
|
*
|
|
|
|
* If an RX endpoint is suspended, and the IPA has a packet destined for
|
|
|
|
* that endpoint, the IPA generates a SUSPEND interrupt to inform the AP
|
|
|
|
* that it should resume the endpoint. If we get one of these interrupts
|
|
|
|
* we just wake up the system.
|
|
|
|
*/
|
|
|
|
static void ipa_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)
|
|
|
|
{
|
2021-08-12 19:50:31 +00:00
|
|
|
/* To handle an IPA interrupt we will have resumed the hardware
|
|
|
|
* just to handle the interrupt, so we're done. If we are in a
|
|
|
|
* system suspend, trigger a system resume.
|
2021-08-04 15:36:25 +00:00
|
|
|
*/
|
2021-08-20 16:01:28 +00:00
|
|
|
if (!__test_and_set_bit(IPA_POWER_FLAG_RESUMED, ipa->power->flags))
|
|
|
|
if (test_bit(IPA_POWER_FLAG_SYSTEM, ipa->power->flags))
|
2021-08-12 19:50:31 +00:00
|
|
|
pm_wakeup_dev_event(&ipa->pdev->dev, 0, true);
|
2021-08-04 15:36:25 +00:00
|
|
|
|
|
|
|
/* Acknowledge/clear the suspend interrupt on all endpoints */
|
|
|
|
ipa_interrupt_suspend_clear_all(ipa->interrupt);
|
|
|
|
}
|
|
|
|
|
2021-08-19 21:12:28 +00:00
|
|
|
/* The next few functions coordinate stopping and starting the modem
|
|
|
|
* network device transmit queue.
|
|
|
|
*
|
|
|
|
* Transmit can be running concurrent with power resume, and there's a
|
|
|
|
* chance the resume completes before the transmit path stops the queue,
|
|
|
|
* leaving the queue in a stopped state. The next two functions are used
|
|
|
|
* to avoid this: ipa_power_modem_queue_stop() is used by ipa_start_xmit()
|
|
|
|
* to conditionally stop the TX queue; and ipa_power_modem_queue_start()
|
|
|
|
* is used by ipa_runtime_resume() to conditionally restart it.
|
|
|
|
*
|
|
|
|
* Two flags and a spinlock are used. If the queue is stopped, the STOPPED
|
|
|
|
* power flag is set. And if the queue is started, the STARTED flag is set.
|
|
|
|
* The queue is only started on resume if the STOPPED flag is set. And the
|
|
|
|
* queue is only started in ipa_start_xmit() if the STARTED flag is *not*
|
|
|
|
* set. As a result, the queue remains operational if the two activites
|
|
|
|
* happen concurrently regardless of the order they complete. The spinlock
|
|
|
|
* ensures the flag and TX queue operations are done atomically.
|
|
|
|
*
|
|
|
|
* The first function stops the modem netdev transmit queue, but only if
|
|
|
|
* the STARTED flag is *not* set. That flag is cleared if it was set.
|
|
|
|
* If the queue is stopped, the STOPPED flag is set. This is called only
|
|
|
|
* from the power ->runtime_resume operation.
|
|
|
|
*/
|
|
|
|
void ipa_power_modem_queue_stop(struct ipa *ipa)
|
|
|
|
{
|
2021-08-20 16:01:28 +00:00
|
|
|
struct ipa_power *power = ipa->power;
|
2021-08-19 21:12:28 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
spin_lock_irqsave(&power->spinlock, flags);
|
2021-08-19 21:12:28 +00:00
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
if (!__test_and_clear_bit(IPA_POWER_FLAG_STARTED, power->flags)) {
|
2021-08-19 21:12:28 +00:00
|
|
|
netif_stop_queue(ipa->modem_netdev);
|
2021-08-20 16:01:28 +00:00
|
|
|
__set_bit(IPA_POWER_FLAG_STOPPED, power->flags);
|
2021-08-19 21:12:28 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
spin_unlock_irqrestore(&power->spinlock, flags);
|
2021-08-19 21:12:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function starts the modem netdev transmit queue, but only if the
|
|
|
|
* STOPPED flag is set. That flag is cleared if it was set. If the queue
|
|
|
|
* was restarted, the STARTED flag is set; this allows ipa_start_xmit()
|
|
|
|
* to skip stopping the queue in the event of a race.
|
|
|
|
*/
|
|
|
|
void ipa_power_modem_queue_wake(struct ipa *ipa)
|
|
|
|
{
|
2021-08-20 16:01:28 +00:00
|
|
|
struct ipa_power *power = ipa->power;
|
2021-08-19 21:12:28 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
spin_lock_irqsave(&power->spinlock, flags);
|
2021-08-19 21:12:28 +00:00
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
if (__test_and_clear_bit(IPA_POWER_FLAG_STOPPED, power->flags)) {
|
|
|
|
__set_bit(IPA_POWER_FLAG_STARTED, power->flags);
|
2021-08-19 21:12:28 +00:00
|
|
|
netif_wake_queue(ipa->modem_netdev);
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
spin_unlock_irqrestore(&power->spinlock, flags);
|
2021-08-19 21:12:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function clears the STARTED flag once the TX queue is operating */
|
|
|
|
void ipa_power_modem_queue_active(struct ipa *ipa)
|
|
|
|
{
|
2021-08-20 16:01:28 +00:00
|
|
|
clear_bit(IPA_POWER_FLAG_STARTED, ipa->power->flags);
|
2021-08-19 21:12:28 +00:00
|
|
|
}
|
|
|
|
|
2021-08-12 19:50:30 +00:00
|
|
|
int ipa_power_setup(struct ipa *ipa)
|
2021-08-04 15:36:25 +00:00
|
|
|
{
|
2021-08-12 19:50:30 +00:00
|
|
|
int ret;
|
|
|
|
|
2021-08-04 15:36:25 +00:00
|
|
|
ipa_interrupt_add(ipa->interrupt, IPA_IRQ_TX_SUSPEND,
|
|
|
|
ipa_suspend_handler);
|
2021-08-12 19:50:30 +00:00
|
|
|
|
|
|
|
ret = device_init_wakeup(&ipa->pdev->dev, true);
|
|
|
|
if (ret)
|
|
|
|
ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_TX_SUSPEND);
|
|
|
|
|
|
|
|
return ret;
|
2021-08-04 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ipa_power_teardown(struct ipa *ipa)
|
|
|
|
{
|
2021-08-12 19:50:30 +00:00
|
|
|
(void)device_init_wakeup(&ipa->pdev->dev, false);
|
2021-08-04 15:36:25 +00:00
|
|
|
ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_TX_SUSPEND);
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
/* Initialize IPA power management */
|
|
|
|
struct ipa_power *
|
|
|
|
ipa_power_init(struct device *dev, const struct ipa_power_data *data)
|
2020-03-06 04:28:19 +00:00
|
|
|
{
|
2021-08-20 16:01:28 +00:00
|
|
|
struct ipa_power *power;
|
2020-03-06 04:28:19 +00:00
|
|
|
struct clk *clk;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
clk = clk_get(dev, "core");
|
|
|
|
if (IS_ERR(clk)) {
|
2021-02-12 14:33:59 +00:00
|
|
|
dev_err_probe(dev, PTR_ERR(clk), "error getting core clock\n");
|
|
|
|
|
2020-03-06 04:28:19 +00:00
|
|
|
return ERR_CAST(clk);
|
|
|
|
}
|
|
|
|
|
2020-11-19 22:40:41 +00:00
|
|
|
ret = clk_set_rate(clk, data->core_clock_rate);
|
2020-03-06 04:28:19 +00:00
|
|
|
if (ret) {
|
2020-11-19 22:40:41 +00:00
|
|
|
dev_err(dev, "error %d setting core clock rate to %u\n",
|
|
|
|
ret, data->core_clock_rate);
|
2020-03-06 04:28:19 +00:00
|
|
|
goto err_clk_put;
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
power = kzalloc(sizeof(*power), GFP_KERNEL);
|
|
|
|
if (!power) {
|
2020-03-06 04:28:19 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_clk_put;
|
|
|
|
}
|
2021-08-20 16:01:28 +00:00
|
|
|
power->dev = dev;
|
|
|
|
power->core = clk;
|
|
|
|
spin_lock_init(&power->spinlock);
|
|
|
|
power->interconnect_count = data->interconnect_count;
|
2020-03-06 04:28:19 +00:00
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
ret = ipa_interconnect_init(power, dev, data->interconnect_data);
|
2020-03-06 04:28:19 +00:00
|
|
|
if (ret)
|
|
|
|
goto err_kfree;
|
|
|
|
|
2021-08-20 16:01:27 +00:00
|
|
|
pm_runtime_set_autosuspend_delay(dev, IPA_AUTOSUSPEND_DELAY);
|
|
|
|
pm_runtime_use_autosuspend(dev);
|
2021-08-10 19:27:01 +00:00
|
|
|
pm_runtime_enable(dev);
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
return power;
|
2020-03-06 04:28:19 +00:00
|
|
|
|
|
|
|
err_kfree:
|
2021-08-20 16:01:28 +00:00
|
|
|
kfree(power);
|
2020-03-06 04:28:19 +00:00
|
|
|
err_clk_put:
|
|
|
|
clk_put(clk);
|
|
|
|
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:01:28 +00:00
|
|
|
/* Inverse of ipa_power_init() */
|
|
|
|
void ipa_power_exit(struct ipa_power *power)
|
2020-03-06 04:28:19 +00:00
|
|
|
{
|
2021-08-20 16:01:28 +00:00
|
|
|
struct device *dev = power->dev;
|
|
|
|
struct clk *clk = power->core;
|
2020-03-06 04:28:19 +00:00
|
|
|
|
2021-08-20 16:01:27 +00:00
|
|
|
pm_runtime_disable(dev);
|
|
|
|
pm_runtime_dont_use_autosuspend(dev);
|
2021-08-20 16:01:28 +00:00
|
|
|
ipa_interconnect_exit(power);
|
|
|
|
kfree(power);
|
2020-03-06 04:28:19 +00:00
|
|
|
clk_put(clk);
|
|
|
|
}
|
2021-08-04 15:36:24 +00:00
|
|
|
|
|
|
|
const struct dev_pm_ops ipa_pm_ops = {
|
2021-08-12 19:50:31 +00:00
|
|
|
.suspend = ipa_suspend,
|
|
|
|
.resume = ipa_resume,
|
2021-08-10 19:27:01 +00:00
|
|
|
.runtime_suspend = ipa_runtime_suspend,
|
|
|
|
.runtime_resume = ipa_runtime_resume,
|
2021-08-04 15:36:24 +00:00
|
|
|
};
|