| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* pmc - Driver implementation for power management functions | 
 | 2 |  * of Power Management Controller (PMC) on SPARCstation-Voyager. | 
 | 3 |  * | 
 | 4 |  * Copyright (c) 2002 Eric Brower (ebrower@usa.net) | 
 | 5 |  */ | 
 | 6 |  | 
 | 7 | #include <linux/kernel.h> | 
 | 8 | #include <linux/fs.h> | 
 | 9 | #include <linux/errno.h> | 
 | 10 | #include <linux/init.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/pm.h> | 
| David S. Miller | f1b6aa8 | 2008-08-27 02:48:26 -0700 | [diff] [blame] | 12 | #include <linux/of.h> | 
 | 13 | #include <linux/of_device.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 |  | 
 | 15 | #include <asm/io.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/oplib.h> | 
 | 17 | #include <asm/uaccess.h> | 
 | 18 | #include <asm/auxio.h> | 
 | 19 |  | 
 | 20 | /* Debug | 
 | 21 |  * | 
 | 22 |  * #define PMC_DEBUG_LED | 
 | 23 |  * #define PMC_NO_IDLE | 
 | 24 |  */ | 
 | 25 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #define PMC_OBPNAME	"SUNW,pmc" | 
| Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 27 | #define PMC_DEVNAME	"pmc" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 |  | 
 | 29 | #define PMC_IDLE_REG	0x00 | 
| Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 30 | #define PMC_IDLE_ON	0x01 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 |  | 
| David S. Miller | f1b6aa8 | 2008-08-27 02:48:26 -0700 | [diff] [blame] | 32 | static u8 __iomem *regs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 |  | 
| David S. Miller | f1b6aa8 | 2008-08-27 02:48:26 -0700 | [diff] [blame] | 34 | #define pmc_readb(offs)		(sbus_readb(regs+offs)) | 
| Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 35 | #define pmc_writeb(val, offs)	(sbus_writeb(val, regs+offs)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 |  | 
| Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 37 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 |  * CPU idle callback function | 
 | 39 |  * See .../arch/sparc/kernel/process.c | 
 | 40 |  */ | 
| Sam Ravnborg | 39f6649 | 2008-12-08 01:02:23 -0800 | [diff] [blame] | 41 | static void pmc_swift_idle(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | { | 
 | 43 | #ifdef PMC_DEBUG_LED | 
| Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 44 | 	set_auxio(0x00, AUXIO_LED); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #endif | 
 | 46 |  | 
 | 47 | 	pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG); | 
 | 48 |  | 
 | 49 | #ifdef PMC_DEBUG_LED | 
| Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 50 | 	set_auxio(AUXIO_LED, 0x00); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #endif | 
| Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 52 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 |  | 
| David S. Miller | f1b6aa8 | 2008-08-27 02:48:26 -0700 | [diff] [blame] | 54 | static int __devinit pmc_probe(struct of_device *op, | 
 | 55 | 			       const struct of_device_id *match) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { | 
| David S. Miller | f1b6aa8 | 2008-08-27 02:48:26 -0700 | [diff] [blame] | 57 | 	regs = of_ioremap(&op->resource[0], 0, | 
 | 58 | 			  resource_size(&op->resource[0]), PMC_OBPNAME); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | 	if (!regs) { | 
 | 60 | 		printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME); | 
 | 61 | 		return -ENODEV; | 
 | 62 | 	} | 
 | 63 |  | 
 | 64 | #ifndef PMC_NO_IDLE | 
 | 65 | 	/* Assign power management IDLE handler */ | 
| Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 66 | 	pm_idle = pmc_swift_idle; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #endif | 
 | 68 |  | 
 | 69 | 	printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME); | 
 | 70 | 	return 0; | 
 | 71 | } | 
 | 72 |  | 
| David S. Miller | fd09831 | 2008-08-31 01:23:17 -0700 | [diff] [blame] | 73 | static struct of_device_id __initdata pmc_match[] = { | 
| David S. Miller | f1b6aa8 | 2008-08-27 02:48:26 -0700 | [diff] [blame] | 74 | 	{ | 
 | 75 | 		.name = PMC_OBPNAME, | 
 | 76 | 	}, | 
 | 77 | 	{}, | 
 | 78 | }; | 
 | 79 | MODULE_DEVICE_TABLE(of, pmc_match); | 
 | 80 |  | 
 | 81 | static struct of_platform_driver pmc_driver = { | 
 | 82 | 	.name		= "pmc", | 
 | 83 | 	.match_table	= pmc_match, | 
 | 84 | 	.probe		= pmc_probe, | 
 | 85 | }; | 
 | 86 |  | 
 | 87 | static int __init pmc_init(void) | 
 | 88 | { | 
 | 89 | 	return of_register_driver(&pmc_driver, &of_bus_type); | 
 | 90 | } | 
 | 91 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | /* This driver is not critical to the boot process | 
 | 93 |  * and is easiest to ioremap when SBus is already | 
 | 94 |  * initialized, so we install ourselves thusly: | 
 | 95 |  */ | 
| David S. Miller | f1b6aa8 | 2008-08-27 02:48:26 -0700 | [diff] [blame] | 96 | __initcall(pmc_init); |