Skip to content

Commit b9a8545

Browse files
marcanjannau
authored andcommitted
Input: macsmc-hid: Support button/lid wakeups
Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent f444ed1 commit b9a8545

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

drivers/input/misc/macsmc-hid.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct macsmc_hid {
1818
struct apple_smc *smc;
1919
struct input_dev *input;
2020
struct notifier_block nb;
21+
bool wakeup_mode;
2122
};
2223

2324
#define SMC_EV_BTN 0x7201
@@ -38,8 +39,15 @@ static int macsmc_hid_event(struct notifier_block *nb, unsigned long event, void
3839
case SMC_EV_BTN:
3940
switch (d1) {
4041
case BTN_POWER:
41-
input_report_key(smchid->input, KEY_POWER, d2);
42-
input_sync(smchid->input);
42+
if (smchid->wakeup_mode) {
43+
if (d2) {
44+
dev_info(smchid->dev, "Button wakeup\n");
45+
pm_wakeup_hard_event(smchid->dev);
46+
}
47+
} else {
48+
input_report_key(smchid->input, KEY_POWER, d2);
49+
input_sync(smchid->input);
50+
}
4351
break;
4452
case BTN_POWER_HELD1:
4553
/*
@@ -68,6 +76,10 @@ static int macsmc_hid_event(struct notifier_block *nb, unsigned long event, void
6876
}
6977
return NOTIFY_OK;
7078
case SMC_EV_LID:
79+
if (smchid->wakeup_mode && !d1) {
80+
dev_info(smchid->dev, "Lid wakeup\n");
81+
pm_wakeup_hard_event(smchid->dev);
82+
}
7183
input_report_switch(smchid->input, SW_LID, d1);
7284
input_sync(smchid->input);
7385
return NOTIFY_OK;
@@ -95,6 +107,7 @@ static int macsmc_hid_probe(struct platform_device *pdev)
95107

96108
smchid->dev = &pdev->dev;
97109
smchid->smc = smc;
110+
platform_set_drvdata(pdev, smchid);
98111

99112
smchid->input = devm_input_allocate_device(&pdev->dev);
100113
if (!smchid->input)
@@ -140,12 +153,36 @@ static int macsmc_hid_probe(struct platform_device *pdev)
140153
smchid->nb.notifier_call = macsmc_hid_event;
141154
apple_smc_register_notifier(smc, &smchid->nb);
142155

156+
device_init_wakeup(&pdev->dev, 1);
157+
158+
return 0;
159+
}
160+
161+
static int macsmc_hid_pm_prepare(struct device *dev)
162+
{
163+
struct macsmc_hid *smchid = dev_get_drvdata(dev);
164+
165+
smchid->wakeup_mode = true;
143166
return 0;
144167
}
145168

169+
static void macsmc_hid_pm_complete(struct device *dev)
170+
{
171+
struct macsmc_hid *smchid = dev_get_drvdata(dev);
172+
173+
smchid->wakeup_mode = false;
174+
}
175+
176+
static const struct dev_pm_ops macsmc_hid_pm_ops = {
177+
.prepare = macsmc_hid_pm_prepare,
178+
.complete = macsmc_hid_pm_complete,
179+
};
180+
146181
static struct platform_driver macsmc_hid_driver = {
147182
.driver = {
148183
.name = "macsmc-hid",
184+
.owner = THIS_MODULE,
185+
.pm = &macsmc_hid_pm_ops,
149186
},
150187
.probe = macsmc_hid_probe,
151188
};

0 commit comments

Comments
 (0)