blob: 93d7b4465f8d2493dc542d0e836ac255182e25f2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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 Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/pm.h>
David S. Millerf1b6aa82008-08-27 02:48:26 -070012#include <linux/of.h>
13#include <linux/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#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 Torvalds1da177e2005-04-16 15:20:36 -070026#define PMC_OBPNAME "SUNW,pmc"
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080027#define PMC_DEVNAME "pmc"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#define PMC_IDLE_REG 0x00
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080030#define PMC_IDLE_ON 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
David S. Millerf1b6aa82008-08-27 02:48:26 -070032static u8 __iomem *regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
David S. Millerf1b6aa82008-08-27 02:48:26 -070034#define pmc_readb(offs) (sbus_readb(regs+offs))
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080035#define pmc_writeb(val, offs) (sbus_writeb(val, regs+offs))
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080037/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 * CPU idle callback function
39 * See .../arch/sparc/kernel/process.c
40 */
Sam Ravnborg39f66492008-12-08 01:02:23 -080041static void pmc_swift_idle(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
43#ifdef PMC_DEBUG_LED
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080044 set_auxio(0x00, AUXIO_LED);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#endif
46
47 pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG);
48
49#ifdef PMC_DEBUG_LED
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080050 set_auxio(AUXIO_LED, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#endif
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080052}
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Grant Likely4ebb24f2011-02-22 20:01:33 -070054static int __devinit pmc_probe(struct platform_device *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
David S. Millerf1b6aa82008-08-27 02:48:26 -070056 regs = of_ioremap(&op->resource[0], 0,
57 resource_size(&op->resource[0]), PMC_OBPNAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 if (!regs) {
59 printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME);
60 return -ENODEV;
61 }
62
63#ifndef PMC_NO_IDLE
64 /* Assign power management IDLE handler */
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080065 pm_idle = pmc_swift_idle;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#endif
67
68 printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
69 return 0;
70}
71
David S. Millerfd098312008-08-31 01:23:17 -070072static struct of_device_id __initdata pmc_match[] = {
David S. Millerf1b6aa82008-08-27 02:48:26 -070073 {
74 .name = PMC_OBPNAME,
75 },
76 {},
77};
78MODULE_DEVICE_TABLE(of, pmc_match);
79
Grant Likely4ebb24f2011-02-22 20:01:33 -070080static struct platform_driver pmc_driver = {
Grant Likely40182942010-04-13 16:13:02 -070081 .driver = {
82 .name = "pmc",
83 .owner = THIS_MODULE,
84 .of_match_table = pmc_match,
85 },
David S. Millerf1b6aa82008-08-27 02:48:26 -070086 .probe = pmc_probe,
87};
88
89static int __init pmc_init(void)
90{
Grant Likely4ebb24f2011-02-22 20:01:33 -070091 return platform_driver_register(&pmc_driver);
David S. Millerf1b6aa82008-08-27 02:48:26 -070092}
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094/* This driver is not critical to the boot process
95 * and is easiest to ioremap when SBus is already
96 * initialized, so we install ourselves thusly:
97 */
David S. Millerf1b6aa82008-08-27 02:48:26 -070098__initcall(pmc_init);