]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/sparc/kernel/power.c
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-bionic-kernel.git] / arch / sparc / kernel / power.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
13077d80 2/* power.c: Power management driver.
1da177e4 3 *
c510b9bf 4 * Copyright (C) 1999, 2007, 2008 David S. Miller (davem@davemloft.net)
1da177e4
LT
5 */
6
1da177e4 7#include <linux/kernel.h>
066bcaca 8#include <linux/export.h>
1da177e4 9#include <linux/init.h>
1da177e4 10#include <linux/interrupt.h>
a3761780 11#include <linux/reboot.h>
764f2579 12#include <linux/of_device.h>
1da177e4 13
abbce6e2 14#include <asm/prom.h>
abbce6e2 15#include <asm/io.h>
1da177e4 16
1da177e4
LT
17static void __iomem *power_reg;
18
13077d80
DM
19static irqreturn_t power_handler(int irq, void *dev_id)
20{
a3761780 21 orderly_poweroff(true);
1da177e4
LT
22
23 /* FIXME: Check registers for status... */
24 return IRQ_HANDLED;
25}
1da177e4 26
7c9503b8 27static int has_button_interrupt(unsigned int irq, struct device_node *dp)
1da177e4 28{
13077d80 29 if (irq == 0xffffffff)
1da177e4 30 return 0;
690c8fd3 31 if (!of_find_property(dp, "button", NULL))
1da177e4
LT
32 return 0;
33
34 return 1;
35}
36
7c9503b8 37static int power_probe(struct platform_device *op)
1da177e4 38{
abbce6e2 39 struct resource *res = &op->resource[0];
1636f8ac 40 unsigned int irq = op->archdata.irqs[0];
a2bd4fd1 41
abbce6e2
DM
42 power_reg = of_ioremap(res, 0, 0x4, "power");
43
90181136 44 printk(KERN_INFO "%s: Control reg at %llx\n",
61c7a080 45 op->dev.of_node->name, res->start);
a2bd4fd1 46
61c7a080 47 if (has_button_interrupt(irq, op->dev.of_node)) {
2256c13b 48 if (request_irq(irq,
00cde674 49 power_handler, 0, "power", NULL) < 0)
13077d80 50 printk(KERN_ERR "power: Cannot setup IRQ handler.\n");
1da177e4 51 }
abbce6e2
DM
52
53 return 0;
1da177e4 54}
a2bd4fd1 55
3628aa06 56static const struct of_device_id power_match[] = {
a2bd4fd1
DM
57 {
58 .name = "power",
59 },
60 {},
61};
62
4ebb24f7 63static struct platform_driver power_driver = {
abbce6e2 64 .probe = power_probe,
4018294b
GL
65 .driver = {
66 .name = "power",
4018294b 67 .of_match_table = power_match,
a2cd1558 68 },
a2bd4fd1
DM
69};
70
b1ebb975 71builtin_platform_driver(power_driver);