pmc.c 2.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11
/* pmc - Driver implementation for power management functions
 * of Power Management Controller (PMC) on SPARCstation-Voyager.
 *
 * Copyright (c) 2002 Eric Brower (ebrower@usa.net)
 */

#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/pm.h>
12 13
#include <linux/of.h>
#include <linux/of_device.h>
14
#include <linux/module.h>
L
Linus Torvalds 已提交
15 16 17

#include <asm/io.h>
#include <asm/oplib.h>
18
#include <linux/uaccess.h>
L
Linus Torvalds 已提交
19
#include <asm/auxio.h>
20
#include <asm/processor.h>
L
Linus Torvalds 已提交
21 22 23 24 25 26 27 28

/* Debug
 *
 * #define PMC_DEBUG_LED
 * #define PMC_NO_IDLE
 */

#define PMC_OBPNAME	"SUNW,pmc"
29
#define PMC_DEVNAME	"pmc"
L
Linus Torvalds 已提交
30 31

#define PMC_IDLE_REG	0x00
32
#define PMC_IDLE_ON	0x01
L
Linus Torvalds 已提交
33

34
static u8 __iomem *regs;
L
Linus Torvalds 已提交
35

36
#define pmc_readb(offs)		(sbus_readb(regs+offs))
37
#define pmc_writeb(val, offs)	(sbus_writeb(val, regs+offs))
L
Linus Torvalds 已提交
38

39
/*
L
Linus Torvalds 已提交
40 41 42
 * CPU idle callback function
 * See .../arch/sparc/kernel/process.c
 */
43
static void pmc_swift_idle(void)
L
Linus Torvalds 已提交
44 45
{
#ifdef PMC_DEBUG_LED
46
	set_auxio(0x00, AUXIO_LED);
L
Linus Torvalds 已提交
47 48 49 50 51
#endif

	pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG);

#ifdef PMC_DEBUG_LED
52
	set_auxio(AUXIO_LED, 0x00);
L
Linus Torvalds 已提交
53
#endif
54
}
L
Linus Torvalds 已提交
55

56
static int pmc_probe(struct platform_device *op)
L
Linus Torvalds 已提交
57
{
58 59
	regs = of_ioremap(&op->resource[0], 0,
			  resource_size(&op->resource[0]), PMC_OBPNAME);
L
Linus Torvalds 已提交
60 61 62 63 64 65 66
	if (!regs) {
		printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME);
		return -ENODEV;
	}

#ifndef PMC_NO_IDLE
	/* Assign power management IDLE handler */
67
	sparc_idle = pmc_swift_idle;
L
Linus Torvalds 已提交
68 69 70 71 72 73
#endif

	printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
	return 0;
}

74
static const struct of_device_id pmc_match[] = {
75 76 77 78 79 80 81
	{
		.name = PMC_OBPNAME,
	},
	{},
};
MODULE_DEVICE_TABLE(of, pmc_match);

82
static struct platform_driver pmc_driver = {
83 84 85 86
	.driver = {
		.name = "pmc",
		.of_match_table = pmc_match,
	},
87 88 89 90 91
	.probe		= pmc_probe,
};

static int __init pmc_init(void)
{
92
	return platform_driver_register(&pmc_driver);
93 94
}

L
Linus Torvalds 已提交
95 96 97 98
/* This driver is not critical to the boot process
 * and is easiest to ioremap when SBus is already
 * initialized, so we install ourselves thusly:
 */
99
__initcall(pmc_init);