power.c 2.5 KB
Newer Older
1
/* power.c: Power management driver.
L
Linus Torvalds 已提交
2
 *
3
 * Copyright (C) 1999, 2007 David S. Miller (davem@davemloft.net)
L
Linus Torvalds 已提交
4 5 6 7 8 9 10 11 12
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/signal.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
13
#include <linux/pm.h>
A
Arnd Bergmann 已提交
14
#include <linux/syscalls.h>
15
#include <linux/reboot.h>
L
Linus Torvalds 已提交
16 17 18

#include <asm/system.h>
#include <asm/auxio.h>
19 20 21
#include <asm/prom.h>
#include <asm/of_device.h>
#include <asm/io.h>
22
#include <asm/sstate.h>
L
Linus Torvalds 已提交
23 24 25 26 27 28 29 30 31 32 33

#include <linux/unistd.h>

/*
 * sysctl - toggle power-off restriction for serial console 
 * systems in machine_power_off()
 */
int scons_pwroff = 1; 

static void __iomem *power_reg;

34 35
static irqreturn_t power_handler(int irq, void *dev_id)
{
36
	orderly_poweroff(true);
L
Linus Torvalds 已提交
37 38 39 40 41 42 43 44 45 46 47

	/* FIXME: Check registers for status... */
	return IRQ_HANDLED;
}

extern void machine_halt(void);
extern void machine_alt_power_off(void);
static void (*poweroff_method)(void) = machine_alt_power_off;

void machine_power_off(void)
{
48
	sstate_poweroff();
49
	if (strcmp(of_console_device->type, "serial") || scons_pwroff) {
L
Linus Torvalds 已提交
50 51 52 53 54 55
		if (power_reg) {
			/* Both register bits seem to have the
			 * same effect, so until I figure out
			 * what the difference is...
			 */
			writel(AUXIO_PCIO_CPWR_OFF | AUXIO_PCIO_SPWR_OFF, power_reg);
56
		} else {
L
Linus Torvalds 已提交
57 58 59 60
			if (poweroff_method != NULL) {
				poweroff_method();
				/* not reached */
			}
61
		}
L
Linus Torvalds 已提交
62 63 64 65
	}
	machine_halt();
}

66 67 68
void (*pm_power_off)(void) = machine_power_off;
EXPORT_SYMBOL(pm_power_off);

69
static int __init has_button_interrupt(unsigned int irq, struct device_node *dp)
L
Linus Torvalds 已提交
70
{
71
	if (irq == 0xffffffff)
L
Linus Torvalds 已提交
72
		return 0;
73
	if (!of_find_property(dp, "button", NULL))
L
Linus Torvalds 已提交
74 75 76 77 78
		return 0;

	return 1;
}

79
static int __devinit power_probe(struct of_device *op, const struct of_device_id *match)
L
Linus Torvalds 已提交
80
{
81 82
	struct resource *res = &op->resource[0];
	unsigned int irq= op->irqs[0];
83

84 85
	power_reg = of_ioremap(res, 0, 0x4, "power");

86
	printk(KERN_INFO "%s: Control reg at %lx\n",
87
	       op->node->name, res->start);
88

L
Linus Torvalds 已提交
89
	poweroff_method = machine_halt;  /* able to use the standard halt */
90

91
	if (has_button_interrupt(irq, op->node)) {
92
		if (request_irq(irq,
93
				power_handler, 0, "power", NULL) < 0)
94
			printk(KERN_ERR "power: Cannot setup IRQ handler.\n");
L
Linus Torvalds 已提交
95
	}
96 97

	return 0;
L
Linus Torvalds 已提交
98
}
99 100 101 102 103 104 105 106

static struct of_device_id power_match[] = {
	{
		.name = "power",
	},
	{},
};

107
static struct of_platform_driver power_driver = {
108
	.match_table	= power_match,
109
	.probe		= power_probe,
110 111 112
	.driver		= {
		.name	= "power",
	},
113 114 115 116
};

void __init power_init(void)
{
117
	of_register_driver(&power_driver, &of_platform_bus_type);
118 119
	return;
}