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> |
Paul Gortmaker | f060ac5 | 2011-07-31 01:50:31 -0400 | [diff] [blame] | 14 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <asm/oplib.h> |
| 18 | #include <asm/uaccess.h> |
| 19 | #include <asm/auxio.h> |
Len Brown | d472ba8 | 2013-02-09 23:27:26 -0500 | [diff] [blame] | 20 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | /* Debug |
| 23 | * |
| 24 | * #define PMC_DEBUG_LED |
| 25 | * #define PMC_NO_IDLE |
| 26 | */ |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #define PMC_OBPNAME "SUNW,pmc" |
Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 29 | #define PMC_DEVNAME "pmc" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | #define PMC_IDLE_REG 0x00 |
Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 32 | #define PMC_IDLE_ON 0x01 |
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 | static u8 __iomem *regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
David S. Miller | f1b6aa8 | 2008-08-27 02:48:26 -0700 | [diff] [blame] | 36 | #define pmc_readb(offs) (sbus_readb(regs+offs)) |
Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 37 | #define pmc_writeb(val, offs) (sbus_writeb(val, regs+offs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 39 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | * CPU idle callback function |
| 41 | * See .../arch/sparc/kernel/process.c |
| 42 | */ |
Sam Ravnborg | 39f6649 | 2008-12-08 01:02:23 -0800 | [diff] [blame] | 43 | static void pmc_swift_idle(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
| 45 | #ifdef PMC_DEBUG_LED |
Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 46 | set_auxio(0x00, AUXIO_LED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #endif |
| 48 | |
| 49 | pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG); |
| 50 | |
| 51 | #ifdef PMC_DEBUG_LED |
Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 52 | set_auxio(AUXIO_LED, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #endif |
Sam Ravnborg | 85bfbf4 | 2008-12-08 01:02:55 -0800 | [diff] [blame] | 54 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Greg Kroah-Hartman | 7c9503b | 2012-12-21 14:03:26 -0800 | [diff] [blame] | 56 | static int pmc_probe(struct platform_device *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
David S. Miller | f1b6aa8 | 2008-08-27 02:48:26 -0700 | [diff] [blame] | 58 | regs = of_ioremap(&op->resource[0], 0, |
| 59 | resource_size(&op->resource[0]), PMC_OBPNAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | if (!regs) { |
| 61 | printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME); |
| 62 | return -ENODEV; |
| 63 | } |
| 64 | |
| 65 | #ifndef PMC_NO_IDLE |
| 66 | /* Assign power management IDLE handler */ |
Len Brown | d472ba8 | 2013-02-09 23:27:26 -0500 | [diff] [blame] | 67 | sparc_idle = pmc_swift_idle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #endif |
| 69 | |
| 70 | printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME); |
| 71 | return 0; |
| 72 | } |
| 73 | |
Sam Ravnborg | 505d914 | 2011-04-21 15:37:20 -0700 | [diff] [blame] | 74 | static struct of_device_id pmc_match[] = { |
David S. Miller | f1b6aa8 | 2008-08-27 02:48:26 -0700 | [diff] [blame] | 75 | { |
| 76 | .name = PMC_OBPNAME, |
| 77 | }, |
| 78 | {}, |
| 79 | }; |
| 80 | MODULE_DEVICE_TABLE(of, pmc_match); |
| 81 | |
Grant Likely | 4ebb24f | 2011-02-22 20:01:33 -0700 | [diff] [blame] | 82 | static struct platform_driver pmc_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 83 | .driver = { |
| 84 | .name = "pmc", |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 85 | .of_match_table = pmc_match, |
| 86 | }, |
David S. Miller | f1b6aa8 | 2008-08-27 02:48:26 -0700 | [diff] [blame] | 87 | .probe = pmc_probe, |
| 88 | }; |
| 89 | |
| 90 | static int __init pmc_init(void) |
| 91 | { |
Grant Likely | 4ebb24f | 2011-02-22 20:01:33 -0700 | [diff] [blame] | 92 | return platform_driver_register(&pmc_driver); |
David S. Miller | f1b6aa8 | 2008-08-27 02:48:26 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | /* This driver is not critical to the boot process |
| 96 | * and is easiest to ioremap when SBus is already |
| 97 | * initialized, so we install ourselves thusly: |
| 98 | */ |
David S. Miller | f1b6aa8 | 2008-08-27 02:48:26 -0700 | [diff] [blame] | 99 | __initcall(pmc_init); |