Merge tag 'for-linux-6.12-ofs1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.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>
263291fa
RH
12#include <linux/of.h>
13#include <linux/platform_device.h>
1da177e4 14
abbce6e2 15#include <asm/prom.h>
abbce6e2 16#include <asm/io.h>
1da177e4 17
1da177e4
LT
18static void __iomem *power_reg;
19
13077d80
DM
20static irqreturn_t power_handler(int irq, void *dev_id)
21{
a3761780 22 orderly_poweroff(true);
1da177e4
LT
23
24 /* FIXME: Check registers for status... */
25 return IRQ_HANDLED;
26}
1da177e4 27
7c9503b8 28static int has_button_interrupt(unsigned int irq, struct device_node *dp)
1da177e4 29{
13077d80 30 if (irq == 0xffffffff)
1da177e4 31 return 0;
928f4de0 32 if (!of_property_read_bool(dp, "button"))
1da177e4
LT
33 return 0;
34
35 return 1;
36}
37
7c9503b8 38static int power_probe(struct platform_device *op)
1da177e4 39{
abbce6e2 40 struct resource *res = &op->resource[0];
1636f8ac 41 unsigned int irq = op->archdata.irqs[0];
a2bd4fd1 42
abbce6e2
DM
43 power_reg = of_ioremap(res, 0, 0x4, "power");
44
ead1c2bd
RH
45 printk(KERN_INFO "%pOFn: Control reg at %llx\n",
46 op->dev.of_node, res->start);
a2bd4fd1 47
61c7a080 48 if (has_button_interrupt(irq, op->dev.of_node)) {
2256c13b 49 if (request_irq(irq,
00cde674 50 power_handler, 0, "power", NULL) < 0)
13077d80 51 printk(KERN_ERR "power: Cannot setup IRQ handler.\n");
1da177e4 52 }
abbce6e2
DM
53
54 return 0;
1da177e4 55}
a2bd4fd1 56
3628aa06 57static const struct of_device_id power_match[] = {
a2bd4fd1
DM
58 {
59 .name = "power",
60 },
61 {},
62};
63
4ebb24f7 64static struct platform_driver power_driver = {
abbce6e2 65 .probe = power_probe,
4018294b
GL
66 .driver = {
67 .name = "power",
4018294b 68 .of_match_table = power_match,
a2cd1558 69 },
a2bd4fd1
DM
70};
71
b1ebb975 72builtin_platform_driver(power_driver);