usb: phy: phy-mv-usb: delete unnecessary 'out of memory' messages
[deliverable/linux.git] / drivers / power / reset / vexpress-poweroff.c
CommitLineData
790440bc
PM
1/*
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.
5 *
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.
10 *
11 * Copyright (C) 2012 ARM Limited
12 */
13
d08b8037 14#include <linux/delay.h>
790440bc
PM
15#include <linux/of.h>
16#include <linux/of_device.h>
17#include <linux/platform_device.h>
18#include <linux/stat.h>
19#include <linux/vexpress.h>
20
65deb782
CM
21#include <asm/system_misc.h>
22
790440bc
PM
23static void vexpress_reset_do(struct device *dev, const char *what)
24{
25 int err = -ENOENT;
3b9334ac 26 struct regmap *reg = dev_get_drvdata(dev);
790440bc 27
3b9334ac
PM
28 if (reg) {
29 err = regmap_write(reg, 0, 0);
d08b8037
PM
30 if (!err)
31 mdelay(1000);
790440bc
PM
32 }
33
34 dev_emerg(dev, "Unable to %s (%d)\n", what, err);
35}
36
37static struct device *vexpress_power_off_device;
38
65deb782 39static void vexpress_power_off(void)
790440bc
PM
40{
41 vexpress_reset_do(vexpress_power_off_device, "power off");
42}
43
44static struct device *vexpress_restart_device;
45
7b6d864b 46static void vexpress_restart(enum reboot_mode reboot_mode, const char *cmd)
790440bc
PM
47{
48 vexpress_reset_do(vexpress_restart_device, "restart");
49}
50
51static ssize_t vexpress_reset_active_show(struct device *dev,
52 struct device_attribute *attr, char *buf)
53{
54 return sprintf(buf, "%d\n", vexpress_restart_device == dev);
55}
56
57static ssize_t vexpress_reset_active_store(struct device *dev,
58 struct device_attribute *attr, const char *buf, size_t count)
59{
60 long value;
61 int err = kstrtol(buf, 0, &value);
62
63 if (!err && value)
64 vexpress_restart_device = dev;
65
66 return err ? err : count;
67}
68
69DEVICE_ATTR(active, S_IRUGO | S_IWUSR, vexpress_reset_active_show,
70 vexpress_reset_active_store);
71
72
73enum vexpress_reset_func { FUNC_RESET, FUNC_SHUTDOWN, FUNC_REBOOT };
74
75static struct of_device_id vexpress_reset_of_match[] = {
76 {
77 .compatible = "arm,vexpress-reset",
78 .data = (void *)FUNC_RESET,
79 }, {
80 .compatible = "arm,vexpress-shutdown",
81 .data = (void *)FUNC_SHUTDOWN
82 }, {
83 .compatible = "arm,vexpress-reboot",
84 .data = (void *)FUNC_REBOOT
85 },
86 {}
87};
88
89static int vexpress_reset_probe(struct platform_device *pdev)
90{
91 enum vexpress_reset_func func;
92 const struct of_device_id *match =
93 of_match_device(vexpress_reset_of_match, &pdev->dev);
3b9334ac 94 struct regmap *regmap;
790440bc
PM
95
96 if (match)
97 func = (enum vexpress_reset_func)match->data;
98 else
99 func = pdev->id_entry->driver_data;
100
3b9334ac
PM
101 regmap = devm_regmap_init_vexpress_config(&pdev->dev);
102 if (IS_ERR(regmap))
103 return PTR_ERR(regmap);
104 dev_set_drvdata(&pdev->dev, regmap);
d08b8037 105
790440bc
PM
106 switch (func) {
107 case FUNC_SHUTDOWN:
108 vexpress_power_off_device = &pdev->dev;
65deb782 109 pm_power_off = vexpress_power_off;
790440bc
PM
110 break;
111 case FUNC_RESET:
112 if (!vexpress_restart_device)
113 vexpress_restart_device = &pdev->dev;
65deb782 114 arm_pm_restart = vexpress_restart;
790440bc
PM
115 device_create_file(&pdev->dev, &dev_attr_active);
116 break;
117 case FUNC_REBOOT:
118 vexpress_restart_device = &pdev->dev;
65deb782 119 arm_pm_restart = vexpress_restart;
790440bc
PM
120 device_create_file(&pdev->dev, &dev_attr_active);
121 break;
122 };
123
124 return 0;
125}
126
127static 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, },
131 {}
132};
133
134static struct platform_driver vexpress_reset_driver = {
135 .probe = vexpress_reset_probe,
136 .driver = {
137 .name = "vexpress-reset",
138 .of_match_table = vexpress_reset_of_match,
139 },
140 .id_table = vexpress_reset_id_table,
141};
142
143static int __init vexpress_reset_init(void)
144{
145 return platform_driver_register(&vexpress_reset_driver);
146}
147device_initcall(vexpress_reset_init);
This page took 0.139812 seconds and 5 git commands to generate.