Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Suspend/resume support
0004  *
0005  * Copyright 2009  MontaVista Software, Inc.
0006  *
0007  * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
0008  */
0009 
0010 #include <linux/init.h>
0011 #include <linux/types.h>
0012 #include <linux/errno.h>
0013 #include <linux/export.h>
0014 #include <linux/suspend.h>
0015 #include <linux/delay.h>
0016 #include <linux/device.h>
0017 #include <linux/of_address.h>
0018 #include <linux/of_platform.h>
0019 
0020 struct pmc_regs {
0021     __be32 devdisr;
0022     __be32 devdisr2;
0023     __be32 :32;
0024     __be32 :32;
0025     __be32 pmcsr;
0026 #define PMCSR_SLP   (1 << 17)
0027 };
0028 
0029 static struct device *pmc_dev;
0030 static struct pmc_regs __iomem *pmc_regs;
0031 
0032 static int pmc_suspend_enter(suspend_state_t state)
0033 {
0034     int ret;
0035 
0036     setbits32(&pmc_regs->pmcsr, PMCSR_SLP);
0037     /* At this point, the CPU is asleep. */
0038 
0039     /* Upon resume, wait for SLP bit to be clear. */
0040     ret = spin_event_timeout((in_be32(&pmc_regs->pmcsr) & PMCSR_SLP) == 0,
0041                  10000, 10) ? 0 : -ETIMEDOUT;
0042     if (ret)
0043         dev_err(pmc_dev, "tired waiting for SLP bit to clear\n");
0044     return ret;
0045 }
0046 
0047 static int pmc_suspend_valid(suspend_state_t state)
0048 {
0049     if (state != PM_SUSPEND_STANDBY)
0050         return 0;
0051     return 1;
0052 }
0053 
0054 static const struct platform_suspend_ops pmc_suspend_ops = {
0055     .valid = pmc_suspend_valid,
0056     .enter = pmc_suspend_enter,
0057 };
0058 
0059 static int pmc_probe(struct platform_device *ofdev)
0060 {
0061     pmc_regs = of_iomap(ofdev->dev.of_node, 0);
0062     if (!pmc_regs)
0063         return -ENOMEM;
0064 
0065     pmc_dev = &ofdev->dev;
0066     suspend_set_ops(&pmc_suspend_ops);
0067     return 0;
0068 }
0069 
0070 static const struct of_device_id pmc_ids[] = {
0071     { .compatible = "fsl,mpc8548-pmc", },
0072     { .compatible = "fsl,mpc8641d-pmc", },
0073     { },
0074 };
0075 
0076 static struct platform_driver pmc_driver = {
0077     .driver = {
0078         .name = "fsl-pmc",
0079         .of_match_table = pmc_ids,
0080     },
0081     .probe = pmc_probe,
0082 };
0083 
0084 builtin_platform_driver(pmc_driver);