blob: 97d123107ecb8bd7d5c8daa1e92e605853b97a5d [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>
Len Brownd472ba82013-02-09 23:27:26 -050020#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22/* Debug
23 *
24 * #define PMC_DEBUG_LED
25 * #define PMC_NO_IDLE
26 */
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#define PMC_OBPNAME "SUNW,pmc"
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080029#define PMC_DEVNAME "pmc"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#define PMC_IDLE_REG 0x00
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080032#define PMC_IDLE_ON 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
David S. Millerf1b6aa82008-08-27 02:48:26 -070034static u8 __iomem *regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
David S. Millerf1b6aa82008-08-27 02:48:26 -070036#define pmc_readb(offs) (sbus_readb(regs+offs))
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080037#define pmc_writeb(val, offs) (sbus_writeb(val, regs+offs))
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080039/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 * CPU idle callback function
41 * See .../arch/sparc/kernel/process.c
42 */
Sam Ravnborg39f66492008-12-08 01:02:23 -080043static void pmc_swift_idle(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
45#ifdef PMC_DEBUG_LED
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080046 set_auxio(0x00, AUXIO_LED);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#endif
48
49 pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG);
50
51#ifdef PMC_DEBUG_LED
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080052 set_auxio(AUXIO_LED, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#endif
Sam Ravnborg85bfbf42008-12-08 01:02:55 -080054}
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Greg Kroah-Hartman7c9503b2012-12-21 14:03:26 -080056static int pmc_probe(struct platform_device *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
David S. Millerf1b6aa82008-08-27 02:48:26 -070058 regs = of_ioremap(&op->resource[0], 0,
59 resource_size(&op->resource[0]), PMC_OBPNAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 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 Brownd472ba82013-02-09 23:27:26 -050067 sparc_idle = pmc_swift_idle;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#endif
69
70 printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
71 return 0;
72}
73
Sam Ravnborg505d9142011-04-21 15:37:20 -070074static struct of_device_id pmc_match[] = {
David S. Millerf1b6aa82008-08-27 02:48:26 -070075 {
76 .name = PMC_OBPNAME,
77 },
78 {},
79};
80MODULE_DEVICE_TABLE(of, pmc_match);
81
Grant Likely4ebb24f2011-02-22 20:01:33 -070082static struct platform_driver pmc_driver = {
Grant Likely40182942010-04-13 16:13:02 -070083 .driver = {
84 .name = "pmc",
Grant Likely40182942010-04-13 16:13:02 -070085 .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);