mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-14 00:47:26 +00:00
83d290c56f
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
116 lines
2.1 KiB
C
116 lines
2.1 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright (c) 2017 Intel Corporation
|
|
*/
|
|
#include <common.h>
|
|
#include <dm.h>
|
|
#include <regmap.h>
|
|
#include <syscon.h>
|
|
#include <asm/cpu.h>
|
|
#include <asm/pmu.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/io.h>
|
|
|
|
/* Registers */
|
|
struct pmu_regs {
|
|
u32 sts;
|
|
u32 cmd;
|
|
u32 ics;
|
|
u32 reserved;
|
|
u32 wkc[4];
|
|
u32 wks[4];
|
|
u32 ssc[4];
|
|
u32 sss[4];
|
|
};
|
|
|
|
/* Bits in PMU_REGS_STS */
|
|
#define PMU_REGS_STS_BUSY (1 << 8)
|
|
|
|
struct pmu_mid {
|
|
struct pmu_regs *regs;
|
|
};
|
|
|
|
static int pmu_read_status(struct pmu_regs *regs)
|
|
{
|
|
int retry = 500000;
|
|
u32 val;
|
|
|
|
do {
|
|
val = readl(®s->sts);
|
|
if (!(val & PMU_REGS_STS_BUSY))
|
|
return 0;
|
|
|
|
udelay(1);
|
|
} while (--retry);
|
|
|
|
printf("WARNING: PMU still busy\n");
|
|
return -EBUSY;
|
|
}
|
|
|
|
static int pmu_power_lss(struct pmu_regs *regs, unsigned int lss, bool on)
|
|
{
|
|
unsigned int offset = (lss * 2) / 32;
|
|
unsigned int shift = (lss * 2) % 32;
|
|
u32 ssc;
|
|
int ret;
|
|
|
|
/* Check PMU status */
|
|
ret = pmu_read_status(regs);
|
|
if (ret)
|
|
return ret;
|
|
|
|
/* Read PMU values */
|
|
ssc = readl(®s->sss[offset]);
|
|
|
|
/* Modify PMU values */
|
|
if (on)
|
|
ssc &= ~(0x3 << shift); /* D0 */
|
|
else
|
|
ssc |= 0x3 << shift; /* D3hot */
|
|
|
|
/* Write modified PMU values */
|
|
writel(ssc, ®s->ssc[offset]);
|
|
|
|
/* Update modified PMU values */
|
|
writel(0x00002201, ®s->cmd);
|
|
|
|
/* Check PMU status */
|
|
return pmu_read_status(regs);
|
|
}
|
|
|
|
int pmu_turn_power(unsigned int lss, bool on)
|
|
{
|
|
struct pmu_mid *pmu;
|
|
struct udevice *dev;
|
|
int ret;
|
|
|
|
ret = syscon_get_by_driver_data(X86_SYSCON_PMU, &dev);
|
|
if (ret)
|
|
return ret;
|
|
|
|
pmu = dev_get_priv(dev);
|
|
|
|
return pmu_power_lss(pmu->regs, lss, on);
|
|
}
|
|
|
|
static int pmu_mid_probe(struct udevice *dev)
|
|
{
|
|
struct pmu_mid *pmu = dev_get_priv(dev);
|
|
|
|
pmu->regs = syscon_get_first_range(X86_SYSCON_PMU);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct udevice_id pmu_mid_match[] = {
|
|
{ .compatible = "intel,pmu-mid", .data = X86_SYSCON_PMU },
|
|
{ /* sentinel */ }
|
|
};
|
|
|
|
U_BOOT_DRIVER(intel_mid_pmu) = {
|
|
.name = "pmu_mid",
|
|
.id = UCLASS_SYSCON,
|
|
.of_match = pmu_mid_match,
|
|
.probe = pmu_mid_probe,
|
|
.priv_auto_alloc_size = sizeof(struct pmu_mid),
|
|
};
|