blob: 814eb3ce039bd8cc69fbcd6a69ea6b01e52e2900 [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>
11#include <linux/miscdevice.h>
12#include <linux/pm.h>
David S. Millerf1b6aa82008-08-27 02:48:26 -070013#include <linux/of.h>
14#include <linux/of_device.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
27#define PMC_MINOR MISC_DYNAMIC_MINOR
28#define PMC_OBPNAME "SUNW,pmc"
29#define PMC_DEVNAME "pmc"
30
31#define PMC_IDLE_REG 0x00
32#define PMC_IDLE_ON 0x01
33
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))
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#define pmc_writeb(val, offs) (sbus_writeb(val, regs+offs))
38
39/*
40 * CPU idle callback function
41 * See .../arch/sparc/kernel/process.c
42 */
43void pmc_swift_idle(void)
44{
45#ifdef PMC_DEBUG_LED
46 set_auxio(0x00, AUXIO_LED);
47#endif
48
49 pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG);
50
51#ifdef PMC_DEBUG_LED
52 set_auxio(AUXIO_LED, 0x00);
53#endif
54}
55
David S. Millerf1b6aa82008-08-27 02:48:26 -070056static int __devinit pmc_probe(struct of_device *op,
57 const struct of_device_id *match)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
David S. Millerf1b6aa82008-08-27 02:48:26 -070059 regs = of_ioremap(&op->resource[0], 0,
60 resource_size(&op->resource[0]), PMC_OBPNAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 if (!regs) {
62 printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME);
63 return -ENODEV;
64 }
65
66#ifndef PMC_NO_IDLE
67 /* Assign power management IDLE handler */
68 pm_idle = pmc_swift_idle;
69#endif
70
71 printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
72 return 0;
73}
74
David S. Millerfd098312008-08-31 01:23:17 -070075static struct of_device_id __initdata pmc_match[] = {
David S. Millerf1b6aa82008-08-27 02:48:26 -070076 {
77 .name = PMC_OBPNAME,
78 },
79 {},
80};
81MODULE_DEVICE_TABLE(of, pmc_match);
82
83static struct of_platform_driver pmc_driver = {
84 .name = "pmc",
85 .match_table = pmc_match,
86 .probe = pmc_probe,
87};
88
89static int __init pmc_init(void)
90{
91 return of_register_driver(&pmc_driver, &of_bus_type);
92}
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);