Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[linux-2.6-block.git] / arch / sparc / kernel / pmc.c
CommitLineData
1da177e4
LT
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>
1da177e4 11#include <linux/pm.h>
f1b6aa87
DM
12#include <linux/of.h>
13#include <linux/of_device.h>
f060ac54 14#include <linux/module.h>
1da177e4
LT
15
16#include <asm/io.h>
1da177e4
LT
17#include <asm/oplib.h>
18#include <asm/uaccess.h>
19#include <asm/auxio.h>
d472ba84 20#include <asm/processor.h>
1da177e4
LT
21
22/* Debug
23 *
24 * #define PMC_DEBUG_LED
25 * #define PMC_NO_IDLE
26 */
27
1da177e4 28#define PMC_OBPNAME "SUNW,pmc"
85bfbf44 29#define PMC_DEVNAME "pmc"
1da177e4
LT
30
31#define PMC_IDLE_REG 0x00
85bfbf44 32#define PMC_IDLE_ON 0x01
1da177e4 33
f1b6aa87 34static u8 __iomem *regs;
1da177e4 35
f1b6aa87 36#define pmc_readb(offs) (sbus_readb(regs+offs))
85bfbf44 37#define pmc_writeb(val, offs) (sbus_writeb(val, regs+offs))
1da177e4 38
85bfbf44 39/*
1da177e4
LT
40 * CPU idle callback function
41 * See .../arch/sparc/kernel/process.c
42 */
39f6649b 43static void pmc_swift_idle(void)
1da177e4
LT
44{
45#ifdef PMC_DEBUG_LED
85bfbf44 46 set_auxio(0x00, AUXIO_LED);
1da177e4
LT
47#endif
48
49 pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG);
50
51#ifdef PMC_DEBUG_LED
85bfbf44 52 set_auxio(AUXIO_LED, 0x00);
1da177e4 53#endif
85bfbf44 54}
1da177e4 55
7c9503b8 56static int pmc_probe(struct platform_device *op)
1da177e4 57{
f1b6aa87
DM
58 regs = of_ioremap(&op->resource[0], 0,
59 resource_size(&op->resource[0]), PMC_OBPNAME);
1da177e4
LT
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 */
d472ba84 67 sparc_idle = pmc_swift_idle;
1da177e4
LT
68#endif
69
70 printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
71 return 0;
72}
73
505d9147 74static struct of_device_id pmc_match[] = {
f1b6aa87
DM
75 {
76 .name = PMC_OBPNAME,
77 },
78 {},
79};
80MODULE_DEVICE_TABLE(of, pmc_match);
81
4ebb24f7 82static struct platform_driver pmc_driver = {
4018294b
GL
83 .driver = {
84 .name = "pmc",
85 .owner = THIS_MODULE,
86 .of_match_table = pmc_match,
87 },
f1b6aa87
DM
88 .probe = pmc_probe,
89};
90
91static int __init pmc_init(void)
92{
4ebb24f7 93 return platform_driver_register(&pmc_driver);
f1b6aa87
DM
94}
95
1da177e4
LT
96/* This driver is not critical to the boot process
97 * and is easiest to ioremap when SBus is already
98 * initialized, so we install ourselves thusly:
99 */
f1b6aa87 100__initcall(pmc_init);