xref: /linux/arch/sparc/kernel/pmc.c (revision d472ba840d622e48f5c94369263ef3af18ab64f8)
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>
20*d472ba84SLen Brown #include <asm/processor.h>
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds /* Debug
231da177e4SLinus Torvalds  *
241da177e4SLinus Torvalds  * #define PMC_DEBUG_LED
251da177e4SLinus Torvalds  * #define PMC_NO_IDLE
261da177e4SLinus Torvalds  */
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds #define PMC_OBPNAME	"SUNW,pmc"
291da177e4SLinus Torvalds #define PMC_DEVNAME	"pmc"
301da177e4SLinus Torvalds 
311da177e4SLinus Torvalds #define PMC_IDLE_REG	0x00
321da177e4SLinus Torvalds #define PMC_IDLE_ON	0x01
331da177e4SLinus Torvalds 
34f1b6aa87SDavid S. Miller static u8 __iomem *regs;
351da177e4SLinus Torvalds 
361da177e4SLinus Torvalds #define pmc_readb(offs)		(sbus_readb(regs+offs))
371da177e4SLinus Torvalds #define pmc_writeb(val, offs)	(sbus_writeb(val, regs+offs))
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds /*
401da177e4SLinus Torvalds  * CPU idle callback function
411da177e4SLinus Torvalds  * See .../arch/sparc/kernel/process.c
421da177e4SLinus Torvalds  */
4339f6649bSSam Ravnborg static void pmc_swift_idle(void)
441da177e4SLinus Torvalds {
451da177e4SLinus Torvalds #ifdef PMC_DEBUG_LED
461da177e4SLinus Torvalds 	set_auxio(0x00, AUXIO_LED);
471da177e4SLinus Torvalds #endif
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds 	pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG);
501da177e4SLinus Torvalds 
511da177e4SLinus Torvalds #ifdef PMC_DEBUG_LED
521da177e4SLinus Torvalds 	set_auxio(AUXIO_LED, 0x00);
531da177e4SLinus Torvalds #endif
541da177e4SLinus Torvalds }
551da177e4SLinus Torvalds 
567c9503b8SGreg Kroah-Hartman static int pmc_probe(struct platform_device *op)
571da177e4SLinus Torvalds {
58f1b6aa87SDavid S. Miller 	regs = of_ioremap(&op->resource[0], 0,
59f1b6aa87SDavid S. Miller 			  resource_size(&op->resource[0]), PMC_OBPNAME);
601da177e4SLinus Torvalds 	if (!regs) {
611da177e4SLinus Torvalds 		printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME);
621da177e4SLinus Torvalds 		return -ENODEV;
631da177e4SLinus Torvalds 	}
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds #ifndef PMC_NO_IDLE
661da177e4SLinus Torvalds 	/* Assign power management IDLE handler */
67*d472ba84SLen Brown 	sparc_idle = pmc_swift_idle;
681da177e4SLinus Torvalds #endif
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds 	printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
711da177e4SLinus Torvalds 	return 0;
721da177e4SLinus Torvalds }
731da177e4SLinus Torvalds 
74505d9147SSam Ravnborg static struct of_device_id pmc_match[] = {
75f1b6aa87SDavid S. Miller 	{
76f1b6aa87SDavid S. Miller 		.name = PMC_OBPNAME,
77f1b6aa87SDavid S. Miller 	},
78f1b6aa87SDavid S. Miller 	{},
79f1b6aa87SDavid S. Miller };
80f1b6aa87SDavid S. Miller MODULE_DEVICE_TABLE(of, pmc_match);
81f1b6aa87SDavid S. Miller 
824ebb24f7SGrant Likely static struct platform_driver pmc_driver = {
834018294bSGrant Likely 	.driver = {
84f1b6aa87SDavid S. Miller 		.name = "pmc",
854018294bSGrant Likely 		.owner = THIS_MODULE,
864018294bSGrant Likely 		.of_match_table = pmc_match,
874018294bSGrant Likely 	},
88f1b6aa87SDavid S. Miller 	.probe		= pmc_probe,
89f1b6aa87SDavid S. Miller };
90f1b6aa87SDavid S. Miller 
91f1b6aa87SDavid S. Miller static int __init pmc_init(void)
92f1b6aa87SDavid S. Miller {
934ebb24f7SGrant Likely 	return platform_driver_register(&pmc_driver);
94f1b6aa87SDavid S. Miller }
95f1b6aa87SDavid S. Miller 
961da177e4SLinus Torvalds /* This driver is not critical to the boot process
971da177e4SLinus Torvalds  * and is easiest to ioremap when SBus is already
981da177e4SLinus Torvalds  * initialized, so we install ourselves thusly:
991da177e4SLinus Torvalds  */
100f1b6aa87SDavid S. Miller __initcall(pmc_init);
101