2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * Copyright (C) 2012 ARM Limited
14 #include <linux/delay.h>
16 #include <linux/of_device.h>
17 #include <linux/platform_device.h>
18 #include <linux/stat.h>
19 #include <linux/vexpress.h>
21 #include <asm/system_misc.h>
23 static void vexpress_reset_do(struct device
*dev
, const char *what
)
26 struct regmap
*reg
= dev_get_drvdata(dev
);
29 err
= regmap_write(reg
, 0, 0);
34 dev_emerg(dev
, "Unable to %s (%d)\n", what
, err
);
37 static struct device
*vexpress_power_off_device
;
39 static void vexpress_power_off(void)
41 vexpress_reset_do(vexpress_power_off_device
, "power off");
44 static struct device
*vexpress_restart_device
;
46 static void vexpress_restart(enum reboot_mode reboot_mode
, const char *cmd
)
48 vexpress_reset_do(vexpress_restart_device
, "restart");
51 static ssize_t
vexpress_reset_active_show(struct device
*dev
,
52 struct device_attribute
*attr
, char *buf
)
54 return sprintf(buf
, "%d\n", vexpress_restart_device
== dev
);
57 static ssize_t
vexpress_reset_active_store(struct device
*dev
,
58 struct device_attribute
*attr
, const char *buf
, size_t count
)
61 int err
= kstrtol(buf
, 0, &value
);
64 vexpress_restart_device
= dev
;
66 return err
? err
: count
;
69 DEVICE_ATTR(active
, S_IRUGO
| S_IWUSR
, vexpress_reset_active_show
,
70 vexpress_reset_active_store
);
73 enum vexpress_reset_func
{ FUNC_RESET
, FUNC_SHUTDOWN
, FUNC_REBOOT
};
75 static struct of_device_id vexpress_reset_of_match
[] = {
77 .compatible
= "arm,vexpress-reset",
78 .data
= (void *)FUNC_RESET
,
80 .compatible
= "arm,vexpress-shutdown",
81 .data
= (void *)FUNC_SHUTDOWN
83 .compatible
= "arm,vexpress-reboot",
84 .data
= (void *)FUNC_REBOOT
89 static int vexpress_reset_probe(struct platform_device
*pdev
)
91 enum vexpress_reset_func func
;
92 const struct of_device_id
*match
=
93 of_match_device(vexpress_reset_of_match
, &pdev
->dev
);
94 struct regmap
*regmap
;
97 func
= (enum vexpress_reset_func
)match
->data
;
99 func
= pdev
->id_entry
->driver_data
;
101 regmap
= devm_regmap_init_vexpress_config(&pdev
->dev
);
103 return PTR_ERR(regmap
);
104 dev_set_drvdata(&pdev
->dev
, regmap
);
108 vexpress_power_off_device
= &pdev
->dev
;
109 pm_power_off
= vexpress_power_off
;
112 if (!vexpress_restart_device
)
113 vexpress_restart_device
= &pdev
->dev
;
114 arm_pm_restart
= vexpress_restart
;
115 device_create_file(&pdev
->dev
, &dev_attr_active
);
118 vexpress_restart_device
= &pdev
->dev
;
119 arm_pm_restart
= vexpress_restart
;
120 device_create_file(&pdev
->dev
, &dev_attr_active
);
127 static const struct platform_device_id vexpress_reset_id_table
[] = {
128 { .name
= "vexpress-reset", .driver_data
= FUNC_RESET
, },
129 { .name
= "vexpress-shutdown", .driver_data
= FUNC_SHUTDOWN
, },
130 { .name
= "vexpress-reboot", .driver_data
= FUNC_REBOOT
, },
134 static struct platform_driver vexpress_reset_driver
= {
135 .probe
= vexpress_reset_probe
,
137 .name
= "vexpress-reset",
138 .of_match_table
= vexpress_reset_of_match
,
140 .id_table
= vexpress_reset_id_table
,
143 static int __init
vexpress_reset_init(void)
145 return platform_driver_register(&vexpress_reset_driver
);
147 device_initcall(vexpress_reset_init
);