Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Documentation/devicetree/bindings/power/apple,pmc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ properties:
$ref: /schemas/types.yaml#/definitions/phandle
description: PMP firmware owner that initializes the voter interface.

apple,pmp-voter:
$ref: /schemas/types.yaml#/definitions/uint32
maximum: 31
description:
Voter agent of the PMP named by apple,pmp, for a PMP whose board values
(apple,board-id and apple,dram-vendor-id) the boot loader fills in.
When it has not filled them in, the PMP never starts, so the PMC does
not wait for it and leaves this agent out of apple,static-voters.

apple,static-voters:
$ref: /schemas/types.yaml#/definitions/uint32-array
description: Voter agents to enable on every rail.
Expand Down Expand Up @@ -344,6 +353,10 @@ patternProperties:
- compatible
- reg

dependentRequired:
apple,pmp-voter:
- apple,pmp

required:
- compatible
- reg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ properties:
$ref: /schemas/types.yaml#/definitions/phandle
description:
The PMP that publishes this report, on SoCs where the host starts the
PMP after a display handoff.
PMP after a display handoff, or where the boot loader fills in the
PMP's board values (apple,board-id and apple,dram-vendor-id). The
report does not wait for an enabled PMP without those values.

apple,pmp-tables:
$ref: /schemas/types.yaml#/definitions/phandle
Expand Down
23 changes: 23 additions & 0 deletions drivers/pmdomain/apple/pmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#include <linux/thermal.h>
#include <linux/workqueue.h>

#include "pmp-handoff.h"

#if IS_ENABLED(CONFIG_APPLE_PMC_KUNIT_TEST)
#include <kunit/static_stub.h>
#endif
Expand Down Expand Up @@ -1330,8 +1332,23 @@ static int apple_pmc_probe(struct platform_device *pdev)
struct device_node *pmp_node;
struct platform_device *pmp;
struct device_link *link;
bool pmp_voter_off = false;
u32 pmp_voter;

pmp_node = of_parse_phandle(np, "apple,pmp", 0);
if (pmp_node && !of_property_read_u32(np, "apple,pmp-voter", &pmp_voter) &&
!(of_device_is_available(pmp_node) && apple_pmp_has_board_values(pmp_node))) {
/*
* The boot loader did not hand this PMP over, so it never
* starts. Run without its votes rather than wait for it, so
* that the CLPC below still comes up.
*/
dev_info(dev, "%pOF was not handed over; running without its votes\n",
pmp_node);
of_node_put(pmp_node);
pmp_node = NULL;
pmp_voter_off = true;
}
if (pmp_node) {
pmp = of_find_device_by_node(pmp_node);
of_node_put(pmp_node);
Expand Down Expand Up @@ -1402,6 +1419,12 @@ static int apple_pmc_probe(struct platform_device *pdev)
pmc->static_agents |= BIT(agents[i]);
}
}
if (pmp_voter_off) {
if (pmp_voter >= pmc->hw->agents)
return dev_err_probe(dev, -EINVAL, "invalid PMP voter %u\n",
pmp_voter);
pmc->static_agents &= ~BIT(pmp_voter);
}

platform_set_drvdata(pdev, pmc);
ret = devm_add_action_or_reset(dev, apple_pmc_release, pmc);
Expand Down
22 changes: 22 additions & 0 deletions drivers/pmdomain/apple/pmp-handoff.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef _APPLE_PMP_HANDOFF_H
#define _APPLE_PMP_HANDOFF_H

#include <linux/of.h>
#include <linux/types.h>

/*
* Whether @pmp has the running machine's apple,board-id and
* apple,dram-vendor-id. The PMP driver refuses to start the PMP without
* them, and a DT that leaves them to the boot loader only has them when the
* loader filled them in.
*/
static inline bool apple_pmp_has_board_values(const struct device_node *pmp)
{
u32 val;

return !of_property_read_u32(pmp, "apple,board-id", &val) &&
!of_property_read_u32(pmp, "apple,dram-vendor-id", &val);
}

#endif /* _APPLE_PMP_HANDOFF_H */
20 changes: 19 additions & 1 deletion drivers/pmdomain/apple/pmp-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "pmp-dram.h"
#include "pmp-ane.h"
#include "pmp-floor-gov.h"
#include "pmp-handoff.h"

#define PMP_REPORT_READY 0x1

Expand Down Expand Up @@ -2474,6 +2475,23 @@ static int apple_pmp_report_resume(struct device *dev)
static DEFINE_SIMPLE_DEV_PM_OPS(apple_pmp_report_pm_ops, apple_pmp_report_suspend,
apple_pmp_report_resume);

/*
* Whether to wait for the PMP to run. A report that names an enabled PMP in
* apple,pmp whose board values the boot loader did not fill in keeps its
* requests to itself: that PMP never starts. Any other report waits for it.
*/
static bool apple_pmp_report_pmp_handed_over(struct apple_pmp_report *rep)
{
struct device_node *pmp = of_parse_phandle(rep->dev->of_node, "apple,pmp", 0);
bool wait = !pmp || !of_device_is_available(pmp) ||
apple_pmp_has_board_values(pmp);

if (!wait)
dev_info(rep->dev, "%pOF was not handed over; not waiting for it\n", pmp);
of_node_put(pmp);
return wait;
}

static int apple_pmp_report_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
Expand Down Expand Up @@ -2565,7 +2583,7 @@ static int apple_pmp_report_probe(struct platform_device *pdev)
if (ret)
return dev_err_probe(dev, ret, "failed to create child devices\n");

if (rep->defer)
if (rep->defer && apple_pmp_report_pmp_handed_over(rep))
queue_delayed_work(system_freezable_power_efficient_wq,
&rep->ready_work, 0);

Expand Down
Loading