blob: 0e3202239ff5b7b1e13441ca1017fb672c9d33d8 [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>
Paul Gortmakerf060ac52011-07-31 01:50:31 -040014#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/oplib.h>
18#include <asm/uaccess.h>
19#include <asm/auxio.h>
20
21/* Debug
22 *
23 * #define PMC_DEBUG_LED
24 * #define PMC_NO_IDLE
25 */
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#define PMC_OBPNAME "SUNW,pmc"
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080028#define PMC_DEVNAME "pmc"
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#define PMC_IDLE_REG 0x00
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080031#define PMC_IDLE_ON 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
David S. Millerf1b6aa82008-08-27 02:48:26 -070033static u8 __iomem *regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
David S. Millerf1b6aa82008-08-27 02:48:26 -070035#define pmc_readb(offs) (sbus_readb(regs+offs))
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080036#define pmc_writeb(val, offs) (sbus_writeb(val, regs+offs))
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080038/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 * CPU idle callback function
40 * See .../arch/sparc/kernel/process.c
41 */
Sam Ravnborg39f66492008-12-08 01:02:23 -080042static void pmc_swift_idle(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
44#ifdef PMC_DEBUG_LED
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080045 set_auxio(0x00, AUXIO_LED);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#endif
47
48 pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG);
49
50#ifdef PMC_DEBUG_LED
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080051 set_auxio(AUXIO_LED, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#endif
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080053}
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Grant Likely4ebb24f2011-02-22 20:01:33 -070055static int __devinit pmc_probe(struct platform_device *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
David S. Millerf1b6aa82008-08-27 02:48:26 -070057 regs = of_ioremap(&op->resource[0], 0,
58 resource_size(&op->resource[0]), PMC_OBPNAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 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 Ravnborg85bfbf42008-12-08 01:02:55 -080066 pm_idle = pmc_swift_idle;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#endif
68
69 printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
70 return 0;
71}
72
Sam Ravnborg505d9142011-04-21 15:37:20 -070073static struct of_device_id pmc_match[] = {
David S. Millerf1b6aa82008-08-27 02:48:26 -070074 {
75 .name = PMC_OBPNAME,
76 },
77 {},
78};
79MODULE_DEVICE_TABLE(of, pmc_match);
80
Grant Likely4ebb24f2011-02-22 20:01:33 -070081static struct platform_driver pmc_driver = {
Grant Likely40182942010-04-13 16:13:02 -070082 .driver = {
83 .name = "pmc",
84 .owner = THIS_MODULE,
85 .of_match_table = pmc_match,
86 },
David S. Millerf1b6aa82008-08-27 02:48:26 -070087 .probe = pmc_probe,
88};
89
90static int __init pmc_init(void)
91{
Grant Likely4ebb24f2011-02-22 20:01:33 -070092 return platform_driver_register(&pmc_driver);
David S. Millerf1b6aa82008-08-27 02:48:26 -070093}
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095/* 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. Millerf1b6aa82008-08-27 02:48:26 -070099__initcall(pmc_init);