xref: /linux/arch/sparc/kernel/pmc.c (revision 7c9503b8382cc41933d8a2f57f78b9dc3f975612)
11da177e4SLinus Torvalds /* pmc - Driver implementation for power management functions
21da177e4SLinus Torvalds  * of Power Management Controller (PMC) on SPARCstation-Voyager.
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Copyright (c) 2002 Eric Brower (ebrower@usa.net)
51da177e4SLinus Torvalds  */
61da177e4SLinus Torvalds 
71da177e4SLinus Torvalds #include <linux/kernel.h>
81da177e4SLinus Torvalds #include <linux/fs.h>
91da177e4SLinus Torvalds #include <linux/errno.h>
101da177e4SLinus Torvalds #include <linux/init.h>
111da177e4SLinus Torvalds #include <linux/pm.h>
12f1b6aa87SDavid S. Miller #include <linux/of.h>
13f1b6aa87SDavid S. Miller #include <linux/of_device.h>
14f060ac54SPaul Gortmaker #include <linux/module.h>
151da177e4SLinus Torvalds 
161da177e4SLinus Torvalds #include <asm/io.h>
171da177e4SLinus Torvalds #include <asm/oplib.h>
181da177e4SLinus Torvalds #include <asm/uaccess.h>
191da177e4SLinus Torvalds #include <asm/auxio.h>
201da177e4SLinus Torvalds 
211da177e4SLinus Torvalds /* Debug
221da177e4SLinus Torvalds  *
231da177e4SLinus Torvalds  * #define PMC_DEBUG_LED
241da177e4SLinus Torvalds  * #define PMC_NO_IDLE
251da177e4SLinus Torvalds  */
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds #define PMC_OBPNAME	"SUNW,pmc"
281da177e4SLinus Torvalds #define PMC_DEVNAME	"pmc"
291da177e4SLinus Torvalds 
301da177e4SLinus Torvalds #define PMC_IDLE_REG	0x00
311da177e4SLinus Torvalds #define PMC_IDLE_ON	0x01
321da177e4SLinus Torvalds 
33f1b6aa87SDavid S. Miller static u8 __iomem *regs;
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds #define pmc_readb(offs)		(sbus_readb(regs+offs))
361da177e4SLinus Torvalds #define pmc_writeb(val, offs)	(sbus_writeb(val, regs+offs))
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds /*
391da177e4SLinus Torvalds  * CPU idle callback function
401da177e4SLinus Torvalds  * See .../arch/sparc/kernel/process.c
411da177e4SLinus Torvalds  */
4239f6649bSSam Ravnborg static void pmc_swift_idle(void)
431da177e4SLinus Torvalds {
441da177e4SLinus Torvalds #ifdef PMC_DEBUG_LED
451da177e4SLinus Torvalds 	set_auxio(0x00, AUXIO_LED);
461da177e4SLinus Torvalds #endif
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds 	pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG);
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds #ifdef PMC_DEBUG_LED
511da177e4SLinus Torvalds 	set_auxio(AUXIO_LED, 0x00);
521da177e4SLinus Torvalds #endif
531da177e4SLinus Torvalds }
541da177e4SLinus Torvalds 
55*7c9503b8SGreg Kroah-Hartman static int pmc_probe(struct platform_device *op)
561da177e4SLinus Torvalds {
57f1b6aa87SDavid S. Miller 	regs = of_ioremap(&op->resource[0], 0,
58f1b6aa87SDavid S. Miller 			  resource_size(&op->resource[0]), PMC_OBPNAME);
591da177e4SLinus Torvalds 	if (!regs) {
601da177e4SLinus Torvalds 		printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME);
611da177e4SLinus Torvalds 		return -ENODEV;
621da177e4SLinus Torvalds 	}
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds #ifndef PMC_NO_IDLE
651da177e4SLinus Torvalds 	/* Assign power management IDLE handler */
661da177e4SLinus Torvalds 	pm_idle = pmc_swift_idle;
671da177e4SLinus Torvalds #endif
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds 	printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
701da177e4SLinus Torvalds 	return 0;
711da177e4SLinus Torvalds }
721da177e4SLinus Torvalds 
73505d9147SSam Ravnborg static struct of_device_id pmc_match[] = {
74f1b6aa87SDavid S. Miller 	{
75f1b6aa87SDavid S. Miller 		.name = PMC_OBPNAME,
76f1b6aa87SDavid S. Miller 	},
77f1b6aa87SDavid S. Miller 	{},
78f1b6aa87SDavid S. Miller };
79f1b6aa87SDavid S. Miller MODULE_DEVICE_TABLE(of, pmc_match);
80f1b6aa87SDavid S. Miller 
814ebb24f7SGrant Likely static struct platform_driver pmc_driver = {
824018294bSGrant Likely 	.driver = {
83f1b6aa87SDavid S. Miller 		.name = "pmc",
844018294bSGrant Likely 		.owner = THIS_MODULE,
854018294bSGrant Likely 		.of_match_table = pmc_match,
864018294bSGrant Likely 	},
87f1b6aa87SDavid S. Miller 	.probe		= pmc_probe,
88f1b6aa87SDavid S. Miller };
89f1b6aa87SDavid S. Miller 
90f1b6aa87SDavid S. Miller static int __init pmc_init(void)
91f1b6aa87SDavid S. Miller {
924ebb24f7SGrant Likely 	return platform_driver_register(&pmc_driver);
93f1b6aa87SDavid S. Miller }
94f1b6aa87SDavid S. Miller 
951da177e4SLinus Torvalds /* This driver is not critical to the boot process
961da177e4SLinus Torvalds  * and is easiest to ioremap when SBus is already
971da177e4SLinus Torvalds  * initialized, so we install ourselves thusly:
981da177e4SLinus Torvalds  */
99f1b6aa87SDavid S. Miller __initcall(pmc_init);
100