diff options
author | Olof Johansson <olof@lixom.net> | 2012-11-26 04:09:30 -0500 |
---|---|---|
committer | Olof Johansson <olof@lixom.net> | 2012-11-26 04:09:53 -0500 |
commit | 0dfeada90989833d0144b4df25d2b9ce3746624f (patch) | |
tree | 0773c2f81a94ca99b8b07b0d984754c81fdd16cc /drivers/power/reset/gpio-poweroff.c | |
parent | d408c5dcc524dfc8e687c443719a3d6be86e2ea0 (diff) | |
parent | 2a18588c0ce336933be3c99c91e74e21db56a0fe (diff) |
Merge tag 'orion_dt_for_3.8' of git://git.infradead.org/users/jcooper/linux into next/dt
From Jason Cooper:
orion dt for v3.8
- ehci-orion dt binding
- gpio-poweroff
- use dt regulators
- move mpp to DT/pinctrl
Depends on:
- orion/boards
- merge conflicts
- keep all 'select's in Kconfig
- remove all #includes in board-*.c
- pinctrl/devel up to:
- 06763c7 pinctrl: mvebu: move to its own directory
* tag 'orion_dt_for_3.8' of git://git.infradead.org/users/jcooper/linux: (211 commits)
ARM: Kirkwood: remove kirkwood_ehci_init() from new boards
ARM: Kirkwood: Add support LED of OpenBlocks A6
ARM: Kirkwood: Convert to EHCI via DT for OpenBlocks A6
ARM: kirkwood: Add NAND partiton map for OpenBlocks A6
ARM: kirkwood: Add support second I2C bus and RTC on OpenBlocks A6
ARM: kirkwood: Add support DT of second I2C bus
ARM: kirkwood: Convert mplcec4 board to pinctrl
ARM: Kirkwood: Convert km_kirkwood to pinctrl
ARM: Kirkwood: support 98DX412x kirkwoods with pinctrl
ARM: Kirkwood: Convert IX2-200 to pinctrl.
ARM: Kirkwood: Convert lsxl boards to pinctrl.
ARM: Kirkwood: Convert ib62x0 to pinctrl.
ARM: Kirkwood: Convert GoFlex Net to pinctrl.
ARM: Kirkwood: Convert dreamplug to pinctrl.
ARM: Kirkwood: Convert dockstar to pinctrl.
ARM: Kirkwood: Convert dnskw to pinctrl
ARM: Kirkwood: Convert iConnect to pinctrl.
ARM: Kirkwood: Convert TS219 to pinctrl.
ARM: Kirkwood: Add DTSI files for pinctrl
ARM: Kirkwood: Make use of mvebu pincltl and gpio drivers
...
Signed-off-by: Olof Johansson <olof@lixom.net>
Diffstat (limited to 'drivers/power/reset/gpio-poweroff.c')
-rw-r--r-- | drivers/power/reset/gpio-poweroff.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/drivers/power/reset/gpio-poweroff.c b/drivers/power/reset/gpio-poweroff.c new file mode 100644 index 000000000000..0491e5335d02 --- /dev/null +++ b/drivers/power/reset/gpio-poweroff.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | * Toggles a GPIO pin to power down a device | ||
3 | * | ||
4 | * Jamie Lentin <jm@lentin.co.uk> | ||
5 | * Andrew Lunn <andrew@lunn.ch> | ||
6 | * | ||
7 | * Copyright (C) 2012 Jamie Lentin | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | * | ||
13 | */ | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/delay.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/gpio.h> | ||
19 | #include <linux/of_platform.h> | ||
20 | #include <linux/of_gpio.h> | ||
21 | #include <linux/module.h> | ||
22 | |||
23 | /* | ||
24 | * Hold configuration here, cannot be more than one instance of the driver | ||
25 | * since pm_power_off itself is global. | ||
26 | */ | ||
27 | static int gpio_num = -1; | ||
28 | static int gpio_active_low; | ||
29 | |||
30 | static void gpio_poweroff_do_poweroff(void) | ||
31 | { | ||
32 | BUG_ON(gpio_num == -1); | ||
33 | |||
34 | /* drive it active */ | ||
35 | gpio_direction_output(gpio_num, !gpio_active_low); | ||
36 | mdelay(100); | ||
37 | /* rising edge or drive inactive */ | ||
38 | gpio_set_value(gpio_num, gpio_active_low); | ||
39 | mdelay(100); | ||
40 | /* falling edge */ | ||
41 | gpio_set_value(gpio_num, !gpio_active_low); | ||
42 | |||
43 | /* give it some time */ | ||
44 | mdelay(3000); | ||
45 | |||
46 | WARN_ON(1); | ||
47 | } | ||
48 | |||
49 | static int __devinit gpio_poweroff_probe(struct platform_device *pdev) | ||
50 | { | ||
51 | enum of_gpio_flags flags; | ||
52 | bool input = false; | ||
53 | int ret; | ||
54 | |||
55 | /* If a pm_power_off function has already been added, leave it alone */ | ||
56 | if (pm_power_off != NULL) { | ||
57 | pr_err("%s: pm_power_off function already registered", | ||
58 | __func__); | ||
59 | return -EBUSY; | ||
60 | } | ||
61 | |||
62 | gpio_num = of_get_gpio_flags(pdev->dev.of_node, 0, &flags); | ||
63 | if (gpio_num < 0) { | ||
64 | pr_err("%s: Could not get GPIO configuration: %d", | ||
65 | __func__, gpio_num); | ||
66 | return -ENODEV; | ||
67 | } | ||
68 | gpio_active_low = flags & OF_GPIO_ACTIVE_LOW; | ||
69 | |||
70 | if (of_get_property(pdev->dev.of_node, "input", NULL)) | ||
71 | input = true; | ||
72 | |||
73 | ret = gpio_request(gpio_num, "poweroff-gpio"); | ||
74 | if (ret) { | ||
75 | pr_err("%s: Could not get GPIO %d", __func__, gpio_num); | ||
76 | return ret; | ||
77 | } | ||
78 | if (input) { | ||
79 | if (gpio_direction_input(gpio_num)) { | ||
80 | pr_err("Could not set direction of GPIO %d to input", | ||
81 | gpio_num); | ||
82 | goto err; | ||
83 | } | ||
84 | } else { | ||
85 | if (gpio_direction_output(gpio_num, gpio_active_low)) { | ||
86 | pr_err("Could not set direction of GPIO %d", gpio_num); | ||
87 | goto err; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | pm_power_off = &gpio_poweroff_do_poweroff; | ||
92 | return 0; | ||
93 | |||
94 | err: | ||
95 | gpio_free(gpio_num); | ||
96 | return -ENODEV; | ||
97 | } | ||
98 | |||
99 | static int __devexit gpio_poweroff_remove(struct platform_device *pdev) | ||
100 | { | ||
101 | if (gpio_num != -1) | ||
102 | gpio_free(gpio_num); | ||
103 | if (pm_power_off == &gpio_poweroff_do_poweroff) | ||
104 | pm_power_off = NULL; | ||
105 | |||
106 | return 0; | ||
107 | } | ||
108 | |||
109 | static const struct of_device_id of_gpio_poweroff_match[] = { | ||
110 | { .compatible = "gpio-poweroff", }, | ||
111 | {}, | ||
112 | }; | ||
113 | |||
114 | static struct platform_driver gpio_poweroff_driver = { | ||
115 | .probe = gpio_poweroff_probe, | ||
116 | .remove = __devexit_p(gpio_poweroff_remove), | ||
117 | .driver = { | ||
118 | .name = "poweroff-gpio", | ||
119 | .owner = THIS_MODULE, | ||
120 | .of_match_table = of_gpio_poweroff_match, | ||
121 | }, | ||
122 | }; | ||
123 | |||
124 | module_platform_driver(gpio_poweroff_driver); | ||
125 | |||
126 | MODULE_AUTHOR("Jamie Lentin <jm@lentin.co.uk>"); | ||
127 | MODULE_DESCRIPTION("GPIO poweroff driver"); | ||
128 | MODULE_LICENSE("GPL"); | ||
129 | MODULE_ALIAS("platform:poweroff-gpio"); | ||