15b6c26a9SCarlo Caione /* 25b6c26a9SCarlo Caione * axp20x power button driver. 35b6c26a9SCarlo Caione * 45b6c26a9SCarlo Caione * Copyright (C) 2013 Carlo Caione <carlo@caione.org> 55b6c26a9SCarlo Caione * 65b6c26a9SCarlo Caione * This file is subject to the terms and conditions of the GNU General 75b6c26a9SCarlo Caione * Public License. See the file "COPYING" in the main directory of this 85b6c26a9SCarlo Caione * archive for more details. 95b6c26a9SCarlo Caione * 105b6c26a9SCarlo Caione * This program is distributed in the hope that it will be useful, 115b6c26a9SCarlo Caione * but WITHOUT ANY WARRANTY; without even the implied warranty of 125b6c26a9SCarlo Caione * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 135b6c26a9SCarlo Caione * GNU General Public License for more details. 145b6c26a9SCarlo Caione */ 155b6c26a9SCarlo Caione 169b13a4caSHans de Goede #include <linux/acpi.h> 175b6c26a9SCarlo Caione #include <linux/errno.h> 185b6c26a9SCarlo Caione #include <linux/irq.h> 195b6c26a9SCarlo Caione #include <linux/init.h> 205b6c26a9SCarlo Caione #include <linux/input.h> 215b6c26a9SCarlo Caione #include <linux/interrupt.h> 225b6c26a9SCarlo Caione #include <linux/kernel.h> 235b6c26a9SCarlo Caione #include <linux/mfd/axp20x.h> 245b6c26a9SCarlo Caione #include <linux/module.h> 25*5ecc1e94SHans de Goede #include <linux/platform_data/x86/soc.h> 265b6c26a9SCarlo Caione #include <linux/platform_device.h> 275b6c26a9SCarlo Caione #include <linux/regmap.h> 285b6c26a9SCarlo Caione #include <linux/slab.h> 295b6c26a9SCarlo Caione 305b6c26a9SCarlo Caione #define AXP20X_PEK_STARTUP_MASK (0xc0) 315b6c26a9SCarlo Caione #define AXP20X_PEK_SHUTDOWN_MASK (0x03) 325b6c26a9SCarlo Caione 33fbc1b323SQuentin Schulz struct axp20x_info { 34fbc1b323SQuentin Schulz const struct axp20x_time *startup_time; 35fbc1b323SQuentin Schulz unsigned int startup_mask; 36fbc1b323SQuentin Schulz const struct axp20x_time *shutdown_time; 37fbc1b323SQuentin Schulz unsigned int shutdown_mask; 38fbc1b323SQuentin Schulz }; 39fbc1b323SQuentin Schulz 405b6c26a9SCarlo Caione struct axp20x_pek { 415b6c26a9SCarlo Caione struct axp20x_dev *axp20x; 425b6c26a9SCarlo Caione struct input_dev *input; 43fbc1b323SQuentin Schulz struct axp20x_info *info; 445b6c26a9SCarlo Caione int irq_dbr; 455b6c26a9SCarlo Caione int irq_dbf; 465b6c26a9SCarlo Caione }; 475b6c26a9SCarlo Caione 485b6c26a9SCarlo Caione struct axp20x_time { 495b6c26a9SCarlo Caione unsigned int time; 505b6c26a9SCarlo Caione unsigned int idx; 515b6c26a9SCarlo Caione }; 525b6c26a9SCarlo Caione 535b6c26a9SCarlo Caione static const struct axp20x_time startup_time[] = { 545b6c26a9SCarlo Caione { .time = 128, .idx = 0 }, 555b6c26a9SCarlo Caione { .time = 1000, .idx = 2 }, 565b6c26a9SCarlo Caione { .time = 3000, .idx = 1 }, 575b6c26a9SCarlo Caione { .time = 2000, .idx = 3 }, 585b6c26a9SCarlo Caione }; 595b6c26a9SCarlo Caione 60c3cc9447SQuentin Schulz static const struct axp20x_time axp221_startup_time[] = { 61c3cc9447SQuentin Schulz { .time = 128, .idx = 0 }, 62c3cc9447SQuentin Schulz { .time = 1000, .idx = 1 }, 63c3cc9447SQuentin Schulz { .time = 2000, .idx = 2 }, 64c3cc9447SQuentin Schulz { .time = 3000, .idx = 3 }, 65c3cc9447SQuentin Schulz }; 66c3cc9447SQuentin Schulz 675b6c26a9SCarlo Caione static const struct axp20x_time shutdown_time[] = { 685b6c26a9SCarlo Caione { .time = 4000, .idx = 0 }, 695b6c26a9SCarlo Caione { .time = 6000, .idx = 1 }, 705b6c26a9SCarlo Caione { .time = 8000, .idx = 2 }, 715b6c26a9SCarlo Caione { .time = 10000, .idx = 3 }, 725b6c26a9SCarlo Caione }; 735b6c26a9SCarlo Caione 74fbc1b323SQuentin Schulz static const struct axp20x_info axp20x_info = { 75fbc1b323SQuentin Schulz .startup_time = startup_time, 76fbc1b323SQuentin Schulz .startup_mask = AXP20X_PEK_STARTUP_MASK, 77fbc1b323SQuentin Schulz .shutdown_time = shutdown_time, 78fbc1b323SQuentin Schulz .shutdown_mask = AXP20X_PEK_SHUTDOWN_MASK, 795b6c26a9SCarlo Caione }; 805b6c26a9SCarlo Caione 81c3cc9447SQuentin Schulz static const struct axp20x_info axp221_info = { 82c3cc9447SQuentin Schulz .startup_time = axp221_startup_time, 83c3cc9447SQuentin Schulz .startup_mask = AXP20X_PEK_STARTUP_MASK, 84c3cc9447SQuentin Schulz .shutdown_time = shutdown_time, 85c3cc9447SQuentin Schulz .shutdown_mask = AXP20X_PEK_SHUTDOWN_MASK, 86c3cc9447SQuentin Schulz }; 87c3cc9447SQuentin Schulz 88fbc1b323SQuentin Schulz static ssize_t axp20x_show_attr(struct device *dev, 89fbc1b323SQuentin Schulz const struct axp20x_time *time, 90fbc1b323SQuentin Schulz unsigned int mask, char *buf) 915b6c26a9SCarlo Caione { 925b6c26a9SCarlo Caione struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev); 935b6c26a9SCarlo Caione unsigned int val; 945b6c26a9SCarlo Caione int ret, i; 955b6c26a9SCarlo Caione 965b6c26a9SCarlo Caione ret = regmap_read(axp20x_pek->axp20x->regmap, AXP20X_PEK_KEY, &val); 975b6c26a9SCarlo Caione if (ret != 0) 985b6c26a9SCarlo Caione return ret; 995b6c26a9SCarlo Caione 100fbc1b323SQuentin Schulz val &= mask; 101fbc1b323SQuentin Schulz val >>= ffs(mask) - 1; 1025b6c26a9SCarlo Caione 1035b6c26a9SCarlo Caione for (i = 0; i < 4; i++) 104fbc1b323SQuentin Schulz if (val == time[i].idx) 105fbc1b323SQuentin Schulz val = time[i].time; 1065b6c26a9SCarlo Caione 1075b6c26a9SCarlo Caione return sprintf(buf, "%u\n", val); 1085b6c26a9SCarlo Caione } 1095b6c26a9SCarlo Caione 110fbc1b323SQuentin Schulz static ssize_t axp20x_show_attr_startup(struct device *dev, 1115b6c26a9SCarlo Caione struct device_attribute *attr, 112fbc1b323SQuentin Schulz char *buf) 1135b6c26a9SCarlo Caione { 1145b6c26a9SCarlo Caione struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev); 115fbc1b323SQuentin Schulz 116fbc1b323SQuentin Schulz return axp20x_show_attr(dev, axp20x_pek->info->startup_time, 117fbc1b323SQuentin Schulz axp20x_pek->info->startup_mask, buf); 118fbc1b323SQuentin Schulz } 119fbc1b323SQuentin Schulz 120fbc1b323SQuentin Schulz static ssize_t axp20x_show_attr_shutdown(struct device *dev, 121fbc1b323SQuentin Schulz struct device_attribute *attr, 122fbc1b323SQuentin Schulz char *buf) 123fbc1b323SQuentin Schulz { 124fbc1b323SQuentin Schulz struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev); 125fbc1b323SQuentin Schulz 126fbc1b323SQuentin Schulz return axp20x_show_attr(dev, axp20x_pek->info->shutdown_time, 127fbc1b323SQuentin Schulz axp20x_pek->info->shutdown_mask, buf); 128fbc1b323SQuentin Schulz } 129fbc1b323SQuentin Schulz 130fbc1b323SQuentin Schulz static ssize_t axp20x_store_attr(struct device *dev, 131fbc1b323SQuentin Schulz const struct axp20x_time *time, 132fbc1b323SQuentin Schulz unsigned int mask, const char *buf, 133fbc1b323SQuentin Schulz size_t count) 134fbc1b323SQuentin Schulz { 135fbc1b323SQuentin Schulz struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev); 1365b6c26a9SCarlo Caione char val_str[20]; 1375b6c26a9SCarlo Caione size_t len; 1385b6c26a9SCarlo Caione int ret, i; 1395b6c26a9SCarlo Caione unsigned int val, idx = 0; 1405b6c26a9SCarlo Caione unsigned int best_err = UINT_MAX; 1415b6c26a9SCarlo Caione 1425b6c26a9SCarlo Caione val_str[sizeof(val_str) - 1] = '\0'; 1435b6c26a9SCarlo Caione strncpy(val_str, buf, sizeof(val_str) - 1); 1445b6c26a9SCarlo Caione len = strlen(val_str); 1455b6c26a9SCarlo Caione 1465b6c26a9SCarlo Caione if (len && val_str[len - 1] == '\n') 1475b6c26a9SCarlo Caione val_str[len - 1] = '\0'; 1485b6c26a9SCarlo Caione 1495b6c26a9SCarlo Caione ret = kstrtouint(val_str, 10, &val); 1505b6c26a9SCarlo Caione if (ret) 1515b6c26a9SCarlo Caione return ret; 1525b6c26a9SCarlo Caione 1535b6c26a9SCarlo Caione for (i = 3; i >= 0; i--) { 1545b6c26a9SCarlo Caione unsigned int err; 1555b6c26a9SCarlo Caione 156fbc1b323SQuentin Schulz err = abs(time[i].time - val); 1575b6c26a9SCarlo Caione if (err < best_err) { 1585b6c26a9SCarlo Caione best_err = err; 159fbc1b323SQuentin Schulz idx = time[i].idx; 1605b6c26a9SCarlo Caione } 1615b6c26a9SCarlo Caione 1625b6c26a9SCarlo Caione if (!err) 1635b6c26a9SCarlo Caione break; 1645b6c26a9SCarlo Caione } 1655b6c26a9SCarlo Caione 166fbc1b323SQuentin Schulz idx <<= ffs(mask) - 1; 167fbc1b323SQuentin Schulz ret = regmap_update_bits(axp20x_pek->axp20x->regmap, AXP20X_PEK_KEY, 168fbc1b323SQuentin Schulz mask, idx); 1695b6c26a9SCarlo Caione if (ret != 0) 1705b6c26a9SCarlo Caione return -EINVAL; 171b388de88SDmitry Torokhov 1725b6c26a9SCarlo Caione return count; 1735b6c26a9SCarlo Caione } 1745b6c26a9SCarlo Caione 175fbc1b323SQuentin Schulz static ssize_t axp20x_store_attr_startup(struct device *dev, 176fbc1b323SQuentin Schulz struct device_attribute *attr, 177fbc1b323SQuentin Schulz const char *buf, size_t count) 178fbc1b323SQuentin Schulz { 179fbc1b323SQuentin Schulz struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev); 1805b6c26a9SCarlo Caione 181fbc1b323SQuentin Schulz return axp20x_store_attr(dev, axp20x_pek->info->startup_time, 182fbc1b323SQuentin Schulz axp20x_pek->info->startup_mask, buf, count); 183fbc1b323SQuentin Schulz } 184fbc1b323SQuentin Schulz 185fbc1b323SQuentin Schulz static ssize_t axp20x_store_attr_shutdown(struct device *dev, 186fbc1b323SQuentin Schulz struct device_attribute *attr, 187fbc1b323SQuentin Schulz const char *buf, size_t count) 188fbc1b323SQuentin Schulz { 189fbc1b323SQuentin Schulz struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev); 190fbc1b323SQuentin Schulz 191fbc1b323SQuentin Schulz return axp20x_store_attr(dev, axp20x_pek->info->shutdown_time, 192fbc1b323SQuentin Schulz axp20x_pek->info->shutdown_mask, buf, count); 193fbc1b323SQuentin Schulz } 194fbc1b323SQuentin Schulz 195cbe821a2SBen Dooks (Codethink) static DEVICE_ATTR(startup, 0644, axp20x_show_attr_startup, 196cbe821a2SBen Dooks (Codethink) axp20x_store_attr_startup); 197cbe821a2SBen Dooks (Codethink) static DEVICE_ATTR(shutdown, 0644, axp20x_show_attr_shutdown, 198fbc1b323SQuentin Schulz axp20x_store_attr_shutdown); 199b388de88SDmitry Torokhov 200d99995a4SGreg Kroah-Hartman static struct attribute *axp20x_attrs[] = { 201fbc1b323SQuentin Schulz &dev_attr_startup.attr, 202fbc1b323SQuentin Schulz &dev_attr_shutdown.attr, 203b388de88SDmitry Torokhov NULL, 204b388de88SDmitry Torokhov }; 205d99995a4SGreg Kroah-Hartman ATTRIBUTE_GROUPS(axp20x); 2065b6c26a9SCarlo Caione 2075b6c26a9SCarlo Caione static irqreturn_t axp20x_pek_irq(int irq, void *pwr) 2085b6c26a9SCarlo Caione { 2099747070cSHans de Goede struct axp20x_pek *axp20x_pek = pwr; 2109747070cSHans de Goede struct input_dev *idev = axp20x_pek->input; 2119747070cSHans de Goede 2129747070cSHans de Goede if (!idev) 2139747070cSHans de Goede return IRQ_HANDLED; 2145b6c26a9SCarlo Caione 215eeeee40fSHans de Goede /* 216eeeee40fSHans de Goede * The power-button is connected to ground so a falling edge (dbf) 217eeeee40fSHans de Goede * means it is pressed. 218eeeee40fSHans de Goede */ 219eeeee40fSHans de Goede if (irq == axp20x_pek->irq_dbf) 2205b6c26a9SCarlo Caione input_report_key(idev, KEY_POWER, true); 221eeeee40fSHans de Goede else if (irq == axp20x_pek->irq_dbr) 2225b6c26a9SCarlo Caione input_report_key(idev, KEY_POWER, false); 2235b6c26a9SCarlo Caione 2245b6c26a9SCarlo Caione input_sync(idev); 2255b6c26a9SCarlo Caione 2265b6c26a9SCarlo Caione return IRQ_HANDLED; 2275b6c26a9SCarlo Caione } 2285b6c26a9SCarlo Caione 229f2bd5a9eSHans de Goede static int axp20x_pek_probe_input_device(struct axp20x_pek *axp20x_pek, 230f2bd5a9eSHans de Goede struct platform_device *pdev) 2315b6c26a9SCarlo Caione { 2325b6c26a9SCarlo Caione struct input_dev *idev; 2335b6c26a9SCarlo Caione int error; 2345b6c26a9SCarlo Caione 2355b6c26a9SCarlo Caione axp20x_pek->input = devm_input_allocate_device(&pdev->dev); 2365b6c26a9SCarlo Caione if (!axp20x_pek->input) 2375b6c26a9SCarlo Caione return -ENOMEM; 2385b6c26a9SCarlo Caione 2395b6c26a9SCarlo Caione idev = axp20x_pek->input; 2405b6c26a9SCarlo Caione 2415b6c26a9SCarlo Caione idev->name = "axp20x-pek"; 2425b6c26a9SCarlo Caione idev->phys = "m1kbd/input2"; 2435b6c26a9SCarlo Caione idev->dev.parent = &pdev->dev; 2445b6c26a9SCarlo Caione 2455b6c26a9SCarlo Caione input_set_capability(idev, EV_KEY, KEY_POWER); 2465b6c26a9SCarlo Caione 2475b6c26a9SCarlo Caione input_set_drvdata(idev, axp20x_pek); 2485b6c26a9SCarlo Caione 249f2bd5a9eSHans de Goede error = input_register_device(idev); 250f2bd5a9eSHans de Goede if (error) { 251f2bd5a9eSHans de Goede dev_err(&pdev->dev, "Can't register input device: %d\n", 252f2bd5a9eSHans de Goede error); 253f2bd5a9eSHans de Goede return error; 254f2bd5a9eSHans de Goede } 255f2bd5a9eSHans de Goede 256f2bd5a9eSHans de Goede return 0; 257f2bd5a9eSHans de Goede } 258f2bd5a9eSHans de Goede 259*5ecc1e94SHans de Goede static bool axp20x_pek_should_register_input(struct axp20x_pek *axp20x_pek) 2608d4b3137SHans de Goede { 2618d4b3137SHans de Goede if (IS_ENABLED(CONFIG_INPUT_SOC_BUTTON_ARRAY) && 2628d4b3137SHans de Goede axp20x_pek->axp20x->variant == AXP288_ID) { 2638d4b3137SHans de Goede /* 2648d4b3137SHans de Goede * On Cherry Trail platforms (hrv == 3), do not register the 2650fd5f221SHans de Goede * input device if there is an "INTCFD9" or "ACPI0011" gpio 2668d4b3137SHans de Goede * button ACPI device, as that handles the power button too, 2678d4b3137SHans de Goede * and otherwise we end up reporting all presses twice. 2688d4b3137SHans de Goede */ 269*5ecc1e94SHans de Goede if (soc_intel_is_cht() && 270*5ecc1e94SHans de Goede (acpi_dev_present("INTCFD9", NULL, -1) || 2710fd5f221SHans de Goede acpi_dev_present("ACPI0011", NULL, -1))) 2728d4b3137SHans de Goede return false; 2738d4b3137SHans de Goede } 2748d4b3137SHans de Goede 2758d4b3137SHans de Goede return true; 2768d4b3137SHans de Goede } 2778d4b3137SHans de Goede 278f2bd5a9eSHans de Goede static int axp20x_pek_probe(struct platform_device *pdev) 279f2bd5a9eSHans de Goede { 280f2bd5a9eSHans de Goede struct axp20x_pek *axp20x_pek; 281fbc1b323SQuentin Schulz const struct platform_device_id *match = platform_get_device_id(pdev); 282f2bd5a9eSHans de Goede int error; 283f2bd5a9eSHans de Goede 284fbc1b323SQuentin Schulz if (!match) { 285fbc1b323SQuentin Schulz dev_err(&pdev->dev, "Failed to get platform_device_id\n"); 286fbc1b323SQuentin Schulz return -EINVAL; 287fbc1b323SQuentin Schulz } 288fbc1b323SQuentin Schulz 289f2bd5a9eSHans de Goede axp20x_pek = devm_kzalloc(&pdev->dev, sizeof(struct axp20x_pek), 290f2bd5a9eSHans de Goede GFP_KERNEL); 291f2bd5a9eSHans de Goede if (!axp20x_pek) 292f2bd5a9eSHans de Goede return -ENOMEM; 293f2bd5a9eSHans de Goede 294f2bd5a9eSHans de Goede axp20x_pek->axp20x = dev_get_drvdata(pdev->dev.parent); 295f2bd5a9eSHans de Goede 2969747070cSHans de Goede axp20x_pek->irq_dbr = platform_get_irq_byname(pdev, "PEK_DBR"); 2979747070cSHans de Goede if (axp20x_pek->irq_dbr < 0) 2989747070cSHans de Goede return axp20x_pek->irq_dbr; 2999747070cSHans de Goede axp20x_pek->irq_dbr = regmap_irq_get_virq( 3009747070cSHans de Goede axp20x_pek->axp20x->regmap_irqc, axp20x_pek->irq_dbr); 3019747070cSHans de Goede 3029747070cSHans de Goede axp20x_pek->irq_dbf = platform_get_irq_byname(pdev, "PEK_DBF"); 3039747070cSHans de Goede if (axp20x_pek->irq_dbf < 0) 3049747070cSHans de Goede return axp20x_pek->irq_dbf; 3059747070cSHans de Goede axp20x_pek->irq_dbf = regmap_irq_get_virq( 3069747070cSHans de Goede axp20x_pek->axp20x->regmap_irqc, axp20x_pek->irq_dbf); 3079747070cSHans de Goede 308*5ecc1e94SHans de Goede if (axp20x_pek_should_register_input(axp20x_pek)) { 309f2bd5a9eSHans de Goede error = axp20x_pek_probe_input_device(axp20x_pek, pdev); 310f2bd5a9eSHans de Goede if (error) 311f2bd5a9eSHans de Goede return error; 3129b13a4caSHans de Goede } 313f2bd5a9eSHans de Goede 314fbc1b323SQuentin Schulz axp20x_pek->info = (struct axp20x_info *)match->driver_data; 315fbc1b323SQuentin Schulz 3169747070cSHans de Goede error = devm_request_any_context_irq(&pdev->dev, axp20x_pek->irq_dbr, 3179747070cSHans de Goede axp20x_pek_irq, 0, 3189747070cSHans de Goede "axp20x-pek-dbr", axp20x_pek); 3199747070cSHans de Goede if (error < 0) { 3209747070cSHans de Goede dev_err(&pdev->dev, "Failed to request dbr IRQ#%d: %d\n", 3219747070cSHans de Goede axp20x_pek->irq_dbr, error); 3229747070cSHans de Goede return error; 3239747070cSHans de Goede } 3249747070cSHans de Goede 3259747070cSHans de Goede error = devm_request_any_context_irq(&pdev->dev, axp20x_pek->irq_dbf, 3269747070cSHans de Goede axp20x_pek_irq, 0, 3279747070cSHans de Goede "axp20x-pek-dbf", axp20x_pek); 3289747070cSHans de Goede if (error < 0) { 3299747070cSHans de Goede dev_err(&pdev->dev, "Failed to request dbf IRQ#%d: %d\n", 3309747070cSHans de Goede axp20x_pek->irq_dbf, error); 3319747070cSHans de Goede return error; 3329747070cSHans de Goede } 3339747070cSHans de Goede 3349747070cSHans de Goede device_init_wakeup(&pdev->dev, true); 3359747070cSHans de Goede 336b388de88SDmitry Torokhov platform_set_drvdata(pdev, axp20x_pek); 3375b6c26a9SCarlo Caione 3385b6c26a9SCarlo Caione return 0; 3395b6c26a9SCarlo Caione } 3405b6c26a9SCarlo Caione 341fe77f9bbSSamuel Holland static int __maybe_unused axp20x_pek_suspend(struct device *dev) 342fe77f9bbSSamuel Holland { 343fe77f9bbSSamuel Holland struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev); 344fe77f9bbSSamuel Holland 345fe77f9bbSSamuel Holland /* 346fe77f9bbSSamuel Holland * As nested threaded IRQs are not automatically disabled during 347fe77f9bbSSamuel Holland * suspend, we must explicitly disable non-wakeup IRQs. 348fe77f9bbSSamuel Holland */ 349fe77f9bbSSamuel Holland if (device_may_wakeup(dev)) { 350fe77f9bbSSamuel Holland enable_irq_wake(axp20x_pek->irq_dbf); 351fe77f9bbSSamuel Holland enable_irq_wake(axp20x_pek->irq_dbr); 352fe77f9bbSSamuel Holland } else { 353fe77f9bbSSamuel Holland disable_irq(axp20x_pek->irq_dbf); 354fe77f9bbSSamuel Holland disable_irq(axp20x_pek->irq_dbr); 355fe77f9bbSSamuel Holland } 356fe77f9bbSSamuel Holland 357fe77f9bbSSamuel Holland return 0; 358fe77f9bbSSamuel Holland } 359fe77f9bbSSamuel Holland 360fe77f9bbSSamuel Holland static int __maybe_unused axp20x_pek_resume(struct device *dev) 361fe77f9bbSSamuel Holland { 362fe77f9bbSSamuel Holland struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev); 363fe77f9bbSSamuel Holland 364fe77f9bbSSamuel Holland if (device_may_wakeup(dev)) { 365fe77f9bbSSamuel Holland disable_irq_wake(axp20x_pek->irq_dbf); 366fe77f9bbSSamuel Holland disable_irq_wake(axp20x_pek->irq_dbr); 367fe77f9bbSSamuel Holland } else { 368fe77f9bbSSamuel Holland enable_irq(axp20x_pek->irq_dbf); 369fe77f9bbSSamuel Holland enable_irq(axp20x_pek->irq_dbr); 370fe77f9bbSSamuel Holland } 371fe77f9bbSSamuel Holland 372fe77f9bbSSamuel Holland return 0; 373fe77f9bbSSamuel Holland } 374fe77f9bbSSamuel Holland 37558be7689SHans de Goede static int __maybe_unused axp20x_pek_resume_noirq(struct device *dev) 37658be7689SHans de Goede { 37758be7689SHans de Goede struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev); 37858be7689SHans de Goede 37958be7689SHans de Goede if (axp20x_pek->axp20x->variant != AXP288_ID) 38058be7689SHans de Goede return 0; 38158be7689SHans de Goede 38258be7689SHans de Goede /* 38358be7689SHans de Goede * Clear interrupts from button presses during suspend, to avoid 38458be7689SHans de Goede * a wakeup power-button press getting reported to userspace. 38558be7689SHans de Goede */ 38658be7689SHans de Goede regmap_write(axp20x_pek->axp20x->regmap, 38758be7689SHans de Goede AXP20X_IRQ1_STATE + AXP288_IRQ_POKN / 8, 38858be7689SHans de Goede BIT(AXP288_IRQ_POKN % 8)); 38958be7689SHans de Goede 39058be7689SHans de Goede return 0; 39158be7689SHans de Goede } 39258be7689SHans de Goede 39358be7689SHans de Goede static const struct dev_pm_ops axp20x_pek_pm_ops = { 394fe77f9bbSSamuel Holland SET_SYSTEM_SLEEP_PM_OPS(axp20x_pek_suspend, axp20x_pek_resume) 39558be7689SHans de Goede #ifdef CONFIG_PM_SLEEP 39658be7689SHans de Goede .resume_noirq = axp20x_pek_resume_noirq, 39758be7689SHans de Goede #endif 39858be7689SHans de Goede }; 39958be7689SHans de Goede 400fbc1b323SQuentin Schulz static const struct platform_device_id axp_pek_id_match[] = { 401fbc1b323SQuentin Schulz { 402fbc1b323SQuentin Schulz .name = "axp20x-pek", 403fbc1b323SQuentin Schulz .driver_data = (kernel_ulong_t)&axp20x_info, 404fbc1b323SQuentin Schulz }, 405c3cc9447SQuentin Schulz { 406c3cc9447SQuentin Schulz .name = "axp221-pek", 407c3cc9447SQuentin Schulz .driver_data = (kernel_ulong_t)&axp221_info, 408c3cc9447SQuentin Schulz }, 409fbc1b323SQuentin Schulz { /* sentinel */ } 410fbc1b323SQuentin Schulz }; 411481c209fSHans de Goede MODULE_DEVICE_TABLE(platform, axp_pek_id_match); 412fbc1b323SQuentin Schulz 4135b6c26a9SCarlo Caione static struct platform_driver axp20x_pek_driver = { 4145b6c26a9SCarlo Caione .probe = axp20x_pek_probe, 415fbc1b323SQuentin Schulz .id_table = axp_pek_id_match, 4165b6c26a9SCarlo Caione .driver = { 4175b6c26a9SCarlo Caione .name = "axp20x-pek", 41858be7689SHans de Goede .pm = &axp20x_pek_pm_ops, 419d99995a4SGreg Kroah-Hartman .dev_groups = axp20x_groups, 4205b6c26a9SCarlo Caione }, 4215b6c26a9SCarlo Caione }; 4225b6c26a9SCarlo Caione module_platform_driver(axp20x_pek_driver); 4235b6c26a9SCarlo Caione 4245b6c26a9SCarlo Caione MODULE_DESCRIPTION("axp20x Power Button"); 4255b6c26a9SCarlo Caione MODULE_AUTHOR("Carlo Caione <carlo@caione.org>"); 4265b6c26a9SCarlo Caione MODULE_LICENSE("GPL"); 427