Skip to content

Commit ee18185

Browse files
fransklaversre
authored andcommitted
power: reset: ltc2952: make trigger input optional
Currently the ltc2952 supports only one button sequence to initiate powerdown. This is not always desirable, as even prolonged button presses can happen in use. Allow ltc2952 users to pick their own power down sequence, by making the trigger input optional. Since this still means that the ltc2952 may power down the platform if the power button is pressed for about 5 seconds, we still need to make sure to start the watchdog toggle to prolong the system power for as long as we need it. This will still allow the system to control power using the kill signal. Signed-off-by: Frans Klaver <frans.klaver@xsens.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
1 parent c1ada2f commit ee18185

1 file changed

Lines changed: 55 additions & 32 deletions

File tree

‎drivers/power/reset/ltc2952-poweroff.c‎

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
* - trigger (input)
3333
* A level change indicates the shut-down trigger. If it's state reverts
3434
* within the time-out defined by trigger_delay, the shut down is not
35-
* executed.
35+
* executed. If no pin is assigned to this input, the driver will start the
36+
* watchdog toggle immediately. The chip will only power off the system if
37+
* it is requested to do so through the kill line.
3638
*
3739
* - watchdog (output)
3840
* Once a shut down is triggered, the driver will toggle this signal,
@@ -116,15 +118,10 @@ static enum hrtimer_restart ltc2952_poweroff_timer_wde(struct hrtimer *timer)
116118
return HRTIMER_RESTART;
117119
}
118120

119-
static enum hrtimer_restart
120-
ltc2952_poweroff_timer_trigger(struct hrtimer *timer)
121+
static void ltc2952_poweroff_start_wde(struct ltc2952_poweroff *data)
121122
{
122-
struct ltc2952_poweroff *data = to_ltc2952(timer, timer_trigger);
123-
int ret = hrtimer_start(&data->timer_wde,
124-
data->wde_interval, HRTIMER_MODE_REL);
125-
126-
if (ret) {
127-
dev_err(data->dev, "unable to start the timer\n");
123+
if (hrtimer_start(&data->timer_wde, data->wde_interval,
124+
HRTIMER_MODE_REL)) {
128125
/*
129126
* The device will not toggle the watchdog reset,
130127
* thus shut down is only safe if the PowerPath controller
@@ -133,10 +130,17 @@ ltc2952_poweroff_timer_trigger(struct hrtimer *timer)
133130
*
134131
* Only sending a warning as the system will power-off anyway
135132
*/
133+
dev_err(data->dev, "unable to start the timer\n");
136134
}
135+
}
137136

138-
dev_info(data->dev, "executing shutdown\n");
137+
static enum hrtimer_restart
138+
ltc2952_poweroff_timer_trigger(struct hrtimer *timer)
139+
{
140+
struct ltc2952_poweroff *data = to_ltc2952(timer, timer_trigger);
139141

142+
ltc2952_poweroff_start_wde(data);
143+
dev_info(data->dev, "executing shutdown\n");
140144
orderly_poweroff(true);
141145

142146
return HRTIMER_NORESTART;
@@ -190,7 +194,7 @@ static void ltc2952_poweroff_default(struct ltc2952_poweroff *data)
190194

191195
static int ltc2952_poweroff_init(struct platform_device *pdev)
192196
{
193-
int ret, virq;
197+
int ret;
194198
struct ltc2952_poweroff *data = platform_get_drvdata(pdev);
195199

196200
ltc2952_poweroff_default(data);
@@ -210,29 +214,48 @@ static int ltc2952_poweroff_init(struct platform_device *pdev)
210214
return ret;
211215
}
212216

213-
data->gpio_trigger = devm_gpiod_get(&pdev->dev, "trigger",
214-
GPIOD_IN);
215-
if (IS_ERR(ltc2952_data->gpio_trigger)) {
216-
ret = PTR_ERR(ltc2952_data->gpio_trigger);
217-
dev_err(&pdev->dev, "unable to claim gpio \"trigger\"\n");
218-
return ret;
219-
}
220-
221-
virq = gpiod_to_irq(data->gpio_trigger);
222-
if (virq < 0) {
223-
dev_err(&pdev->dev, "cannot map GPIO as interrupt");
224-
return ret;
217+
data->gpio_trigger = devm_gpiod_get(&pdev->dev, "trigger", GPIOD_IN);
218+
if (IS_ERR(data->gpio_trigger)) {
219+
/*
220+
* It's not a problem if the trigger gpio isn't available, but
221+
* it is worth a warning if its use was defined in the device
222+
* tree.
223+
*/
224+
if (PTR_ERR(data->gpio_trigger) != -ENOENT)
225+
dev_err(&pdev->dev,
226+
"unable to claim gpio \"trigger\"\n");
227+
data->gpio_trigger = NULL;
225228
}
226229

227-
ret = devm_request_irq(&pdev->dev, virq,
228-
ltc2952_poweroff_handler,
229-
(IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING),
230-
"ltc2952-poweroff",
231-
data);
232-
233-
if (ret) {
234-
dev_err(&pdev->dev, "cannot configure an interrupt handler\n");
235-
return ret;
230+
if (devm_request_irq(&pdev->dev, gpiod_to_irq(data->gpio_trigger),
231+
ltc2952_poweroff_handler,
232+
(IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING),
233+
"ltc2952-poweroff",
234+
data)) {
235+
/*
236+
* Some things may have happened:
237+
* - No trigger input was defined
238+
* - Claiming the GPIO failed
239+
* - We could not map to an IRQ
240+
* - We couldn't register an interrupt handler
241+
*
242+
* None of these really are problems, but all of them
243+
* disqualify the push button from controlling the power.
244+
*
245+
* It is therefore important to note that if the ltc2952
246+
* detects a button press for long enough, it will still start
247+
* its own powerdown window and cut the power on us if we don't
248+
* start the watchdog trigger.
249+
*/
250+
if (data->gpio_trigger) {
251+
dev_warn(&pdev->dev,
252+
"unable to configure the trigger interrupt\n");
253+
devm_gpiod_put(&pdev->dev, data->gpio_trigger);
254+
data->gpio_trigger = NULL;
255+
}
256+
dev_info(&pdev->dev,
257+
"power down trigger input will not be used\n");
258+
ltc2952_poweroff_start_wde(data);
236259
}
237260

238261
return 0;

0 commit comments

Comments
 (0)