1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Suspend/resume support 4 * 5 * Copyright 2009 MontaVista Software, Inc. 6 * 7 * Author: Anton Vorontsov <avorontsov@ru.mvista.com> 8 */ 9 10 #include <linux/init.h> 11 #include <linux/types.h> 12 #include <linux/errno.h> 13 #include <linux/export.h> 14 #include <linux/suspend.h> 15 #include <linux/delay.h> 16 #include <linux/of_address.h> 17 #include <linux/platform_device.h> 18 19 struct pmc_regs { 20 __be32 devdisr; 21 __be32 devdisr2; 22 __be32 :32; 23 __be32 :32; 24 __be32 pmcsr; 25 #define PMCSR_SLP (1 << 17) 26 }; 27 28 static struct device *pmc_dev; 29 static struct pmc_regs __iomem *pmc_regs; 30 31 static int pmc_suspend_enter(suspend_state_t state) 32 { 33 int ret; 34 35 setbits32(&pmc_regs->pmcsr, PMCSR_SLP); 36 /* At this point, the CPU is asleep. */ 37 38 /* Upon resume, wait for SLP bit to be clear. */ 39 ret = spin_event_timeout((in_be32(&pmc_regs->pmcsr) & PMCSR_SLP) == 0, 40 10000, 10) ? 0 : -ETIMEDOUT; 41 if (ret) 42 dev_err(pmc_dev, "tired waiting for SLP bit to clear\n"); 43 return ret; 44 } 45 46 static int pmc_suspend_valid(suspend_state_t state) 47 { 48 if (state != PM_SUSPEND_STANDBY) 49 return 0; 50 return 1; 51 } 52 53 static const struct platform_suspend_ops pmc_suspend_ops = { 54 .valid = pmc_suspend_valid, 55 .enter = pmc_suspend_enter, 56 }; 57 58 static int pmc_probe(struct platform_device *ofdev) 59 { 60 pmc_regs = of_iomap(ofdev->dev.of_node, 0); 61 if (!pmc_regs) 62 return -ENOMEM; 63 64 pmc_dev = &ofdev->dev; 65 suspend_set_ops(&pmc_suspend_ops); 66 return 0; 67 } 68 69 static const struct of_device_id pmc_ids[] = { 70 { .compatible = "fsl,mpc8548-pmc", }, 71 { .compatible = "fsl,mpc8641d-pmc", }, 72 { }, 73 }; 74 75 static struct platform_driver pmc_driver = { 76 .driver = { 77 .name = "fsl-pmc", 78 .of_match_table = pmc_ids, 79 }, 80 .probe = pmc_probe, 81 }; 82 83 builtin_platform_driver(pmc_driver); 84