1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2017 Intel Corporation
10 #include <linux/delay.h>
11 #include <linux/errno.h>
26 /* Bits in PMU_REGS_STS */
27 #define PMU_REGS_STS_BUSY (1 << 8)
30 struct pmu_regs *regs;
33 static int pmu_read_status(struct pmu_regs *regs)
39 val = readl(®s->sts);
40 if (!(val & PMU_REGS_STS_BUSY))
46 printf("WARNING: PMU still busy\n");
50 static int pmu_power_lss(struct pmu_regs *regs, unsigned int lss, bool on)
52 unsigned int offset = (lss * 2) / 32;
53 unsigned int shift = (lss * 2) % 32;
57 /* Check PMU status */
58 ret = pmu_read_status(regs);
63 ssc = readl(®s->sss[offset]);
65 /* Modify PMU values */
67 ssc &= ~(0x3 << shift); /* D0 */
69 ssc |= 0x3 << shift; /* D3hot */
71 /* Write modified PMU values */
72 writel(ssc, ®s->ssc[offset]);
74 /* Update modified PMU values */
75 writel(0x00002201, ®s->cmd);
77 /* Check PMU status */
78 return pmu_read_status(regs);
81 int pmu_turn_power(unsigned int lss, bool on)
87 ret = syscon_get_by_driver_data(X86_SYSCON_PMU, &dev);
91 pmu = dev_get_priv(dev);
93 return pmu_power_lss(pmu->regs, lss, on);
96 static int pmu_mid_probe(struct udevice *dev)
98 struct pmu_mid *pmu = dev_get_priv(dev);
100 pmu->regs = syscon_get_first_range(X86_SYSCON_PMU);
105 static const struct udevice_id pmu_mid_match[] = {
106 { .compatible = "intel,pmu-mid", .data = X86_SYSCON_PMU },
110 U_BOOT_DRIVER(intel_mid_pmu) = {
113 .of_match = pmu_mid_match,
114 .probe = pmu_mid_probe,
115 .priv_auto = sizeof(struct pmu_mid),