1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2017 Intel Corporation
11 #include <linux/delay.h>
12 #include <linux/errno.h>
27 /* Bits in PMU_REGS_STS */
28 #define PMU_REGS_STS_BUSY (1 << 8)
31 struct pmu_regs *regs;
34 static int pmu_read_status(struct pmu_regs *regs)
40 val = readl(®s->sts);
41 if (!(val & PMU_REGS_STS_BUSY))
47 printf("WARNING: PMU still busy\n");
51 static int pmu_power_lss(struct pmu_regs *regs, unsigned int lss, bool on)
53 unsigned int offset = (lss * 2) / 32;
54 unsigned int shift = (lss * 2) % 32;
58 /* Check PMU status */
59 ret = pmu_read_status(regs);
64 ssc = readl(®s->sss[offset]);
66 /* Modify PMU values */
68 ssc &= ~(0x3 << shift); /* D0 */
70 ssc |= 0x3 << shift; /* D3hot */
72 /* Write modified PMU values */
73 writel(ssc, ®s->ssc[offset]);
75 /* Update modified PMU values */
76 writel(0x00002201, ®s->cmd);
78 /* Check PMU status */
79 return pmu_read_status(regs);
82 int pmu_turn_power(unsigned int lss, bool on)
88 ret = syscon_get_by_driver_data(X86_SYSCON_PMU, &dev);
92 pmu = dev_get_priv(dev);
94 return pmu_power_lss(pmu->regs, lss, on);
97 static int pmu_mid_probe(struct udevice *dev)
99 struct pmu_mid *pmu = dev_get_priv(dev);
101 pmu->regs = syscon_get_first_range(X86_SYSCON_PMU);
106 static const struct udevice_id pmu_mid_match[] = {
107 { .compatible = "intel,pmu-mid", .data = X86_SYSCON_PMU },
111 U_BOOT_DRIVER(intel_mid_pmu) = {
114 .of_match = pmu_mid_match,
115 .probe = pmu_mid_probe,
116 .priv_auto = sizeof(struct pmu_mid),