{"id":2174168,"url":"http://patchwork.ozlabs.org/api/patches/2174168/?format=json","web_url":"http://patchwork.ozlabs.org/project/rtc-linux/patch/20251215-macsmc-subdevs-v6-4-0518cb5f28ae@gmail.com/","project":{"id":9,"url":"http://patchwork.ozlabs.org/api/projects/9/?format=json","name":"Linux RTC development","link_name":"rtc-linux","list_id":"linux-rtc.vger.kernel.org","list_email":"linux-rtc@vger.kernel.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20251215-macsmc-subdevs-v6-4-0518cb5f28ae@gmail.com>","list_archive_url":null,"date":"2025-12-15T09:37:48","name":"[v6,4/7] input: macsmc-input: New driver to handle the Apple Mac SMC buttons/lid","commit_ref":null,"pull_url":null,"state":"handled-elsewhere","archived":false,"hash":"3063578e7cbbf49b90a2da29c1a4ab001399087c","submitter":{"id":89516,"url":"http://patchwork.ozlabs.org/api/people/89516/?format=json","name":"James Calligeros","email":"jcalligeros99@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/rtc-linux/patch/20251215-macsmc-subdevs-v6-4-0518cb5f28ae@gmail.com/mbox/","series":[{"id":485366,"url":"http://patchwork.ozlabs.org/api/series/485366/?format=json","web_url":"http://patchwork.ozlabs.org/project/rtc-linux/list/?series=485366","date":"2025-12-15T09:37:44","name":"mfd: macsmc: add rtc, hwmon and hid subdevices","version":6,"mbox":"http://patchwork.ozlabs.org/series/485366/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2174168/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2174168/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-rtc+bounces-5543-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-rtc@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20230601 header.b=P9T4nBai;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-rtc+bounces-5543-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=\"P9T4nBai\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.214.177","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4dVFSj2lpFz1y15\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 15 Dec 2025 20:41:41 +1100 (AEDT)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 9A83E3012264\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 15 Dec 2025 09:38:51 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 26C60329E56;\n\tMon, 15 Dec 2025 09:38:51 +0000 (UTC)","from mail-pl1-f177.google.com (mail-pl1-f177.google.com\n [209.85.214.177])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 676DB314B8A\n\tfor <linux-rtc@vger.kernel.org>; Mon, 15 Dec 2025 09:38:49 +0000 (UTC)","by mail-pl1-f177.google.com with SMTP id\n d9443c01a7336-2a0a33d0585so12388465ad.1\n        for <linux-rtc@vger.kernel.org>; Mon, 15 Dec 2025 01:38:49 -0800 (PST)","from [192.168.2.3]\n (2403-580a-80ed-0-4835-5a07-49e7-f115.ip6.aussiebb.net.\n [2403:580a:80ed:0:4835:5a07:49e7:f115])\n        by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-29efd74f5e1sm113017705ad.16.2025.12.15.01.38.41\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Mon, 15 Dec 2025 01:38:48 -0800 (PST)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1765791531; cv=none;\n b=u8jzXNp/o7c/mRkWGiaDWpmK+L7HBwQd+EQDdUXU4Brpoeuzjm62/uUPVkfgrlOl8FglhWzG+thieWV4NLy21RYIU0r7KkdlmNheyOv4DU5xHLIJqPMau4IFmsThOuNx5YEh7Nmpcb/5oYKUDVD63SRvyZhhEOUn50ENk8r2Jx0=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1765791531; c=relaxed/simple;\n\tbh=juGdkiAL8Ef7FniFZDXGGIHcDDafInr/yvVMPwDegYM=;\n\th=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:\n\t In-Reply-To:To:Cc;\n b=c7ZL47mxVI4xZFFWBU56O4RjqL7pUTMt2N51MfahvG9hsUle0/FJpZYsIsyWpJfv+DA3uUhQOphmxr6l1b9GPNYPcYIda7OJmCkCnUb4GutLxW2LOMVquk2gUyHL5k/UkvrEZiZDh0tzthjlYidcE0z3xL+P0+Xc1ceeFPFoOjg=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com;\n spf=pass smtp.mailfrom=gmail.com;\n dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=P9T4nBai; arc=none smtp.client-ip=209.85.214.177","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20230601; t=1765791529; x=1766396329;\n darn=vger.kernel.org;\n        h=cc:to:in-reply-to:references:message-id:content-transfer-encoding\n         :mime-version:subject:date:from:from:to:cc:subject:date:message-id\n         :reply-to;\n        bh=MX4l83PZei/eA8H23B1WzGR4a5PAckpfpztaLgsdyrA=;\n        b=P9T4nBaiHE19GitMpjDMC6krcTlbcPuD2CYpd7V4GhUxgXJ5jAiSKutKdvXSYSbwDE\n         d9KqvMlcfYDnuwwQHkWo/+dLRSFPfneiAvIPZR/jyYqkpuQNPRdq7uuHTxqEf7TofDoJ\n         znXyUUEzMzQzqsUzLjROwVpZ6nr0hrfvQmx4fvC1+GVijkTxOcP5vAH1xYfLBKKUZEkK\n         HH9hNlPoO1Al080y7mXdK1IBhxvHowMgcRTPxNeiQOyx40+A9mRLMjV5qTLVNjsDRFjX\n         kAF/I7od5uE17zeM9BfqPhZp5B3aMY2DDNhdIyTj/e+rwKJNCuYl/lGmCxSJyE44joY8\n         jSaQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20230601; t=1765791529; x=1766396329;\n        h=cc:to:in-reply-to:references:message-id:content-transfer-encoding\n         :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to\n         :cc:subject:date:message-id:reply-to;\n        bh=MX4l83PZei/eA8H23B1WzGR4a5PAckpfpztaLgsdyrA=;\n        b=vDjkT0DLtzZC73Ea3snP9oQakYMjsxcS1Fv1CoJIl692BlK5L4dE03v7DCX4AeWveI\n         JTkgleSAgmQolR4K5hKSs8ZMMewg1ODK6zwNB03h+Vi7YdNRMwqJcpgntIKijfTkgA+0\n         9tLLUPN/hcrAHWplkUtbUrLrm+4qb23pWR0/GKNY2jabFa8TNaX9dxZ+Nicha7VKzdey\n         jUPJk0bLGfSPc46ml6Due3AMHz8BQunYTUpgkmquoAN/X77wJJctGfQD2Eqc/EDZx4eD\n         ht6ZLSm59HwxVAWn5Pypx2QnmRVcO1xvOpLjO1kW6Gdb6cGJ1s8eEDsPOqh3pbyOI4Zf\n         vvjA==","X-Forwarded-Encrypted":"i=1;\n AJvYcCXmMahk72DlB0hfhayfcm6525yYukybYzw8+tjiKOn9JdwGf9FaTguKb46qgc755zsxcghfwuVAUOE=@vger.kernel.org","X-Gm-Message-State":"AOJu0Yw705zEfLg22Pr1YlGVwaTuPjOLxmYU8u+VXdM6nmKm35WRPi8c\n\tjTS5vydNYl3zVIpvm+J8gm5uPlA/UoclWhAp5k2138dSs8Rj/zGnBrQ7","X-Gm-Gg":"AY/fxX486uBrcjXh7JLTfGj6Knh5zvFpRjD8daizc333aE0R01iVyTHsoUTUZnr4xTt\n\tuwhJQpMd3gvlhkkZdNp65YMnxIwMpuD/4a8JaKCyCTgNnIvxAVSkfrI3rLohKMgfQ4dqK1vnFAb\n\ts4FnVglzxD9toCAYjayYlxo7abqwRjndc3EACQ5rbq1VbGnQ0xzOoCkUZi/AT+u+6MXhfauA0Qq\n\tOCDi/jb9dfTJ1oOMJHi3WSLrXehnMmzlSoKp6ixPxiezLplkWXep+JgkcjoZYYfqgGWh5Cwljbm\n\t8Bw3BI+O6SQ07aeWKl9cQIE9lIDPSepawm3EYQVYx+WY1mz58oRAsn9dyQ0nVKxXJ7GhAh6ULxW\n\tLtvr7KPIV0bibswsbtsR/Cjn2IXDx4hmW72XewKNeV9/47tJ8BIe3O4cw4W8rvkOtoph3PuJcpY\n\twVtqZ0MpfmTXZIVZ03mOve5Tiv7Lgucmd6sexNUuv4fRrizHIhSsk5XnFjw1MFEJI4wzuGw97Cf\n\tS2tBpjVGMTuR9i37pqAZazMrq88woxt9zQnWSq+4u0CZSUhPxWY2a+KkoS7sWbqFDuoSRDTqPkV\n\tPX/LzGU+gXWxLNN5Ax2KAgLFIpk30FSkgn0rQpvgQphgE9xAizx3mgQfHlGfjA==","X-Google-Smtp-Source":"\n AGHT+IEGJ44+51Fi+YdUwyKv9dsSN+8JmzAkupuBnmxY9duLk9j4SAUpGagR8Wr9Xf65hMIh2opKeg==","X-Received":"by 2002:a17:902:e784:b0:295:6c26:933b with SMTP id\n d9443c01a7336-29f23dd1fd2mr76096885ad.1.1765791528782;\n        Mon, 15 Dec 2025 01:38:48 -0800 (PST)","From":"James Calligeros <jcalligeros99@gmail.com>","Date":"Mon, 15 Dec 2025 19:37:48 +1000","Subject":"[PATCH v6 4/7] input: macsmc-input: New driver to handle the Apple\n Mac SMC buttons/lid","Precedence":"bulk","X-Mailing-List":"linux-rtc@vger.kernel.org","List-Id":"<linux-rtc.vger.kernel.org>","List-Subscribe":"<mailto:linux-rtc+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-rtc+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","Message-Id":"<20251215-macsmc-subdevs-v6-4-0518cb5f28ae@gmail.com>","References":"<20251215-macsmc-subdevs-v6-0-0518cb5f28ae@gmail.com>","In-Reply-To":"<20251215-macsmc-subdevs-v6-0-0518cb5f28ae@gmail.com>","To":"Sven Peter <sven@kernel.org>, Janne Grunau <j@jannau.net>,\n Alyssa Rosenzweig <alyssa@rosenzweig.io>, Neal Gompa <neal@gompa.dev>,\n Lee Jones <lee@kernel.org>, Rob Herring <robh@kernel.org>,\n Krzysztof Kozlowski <krzk+dt@kernel.org>,\n Conor Dooley <conor+dt@kernel.org>,\n Alexandre Belloni <alexandre.belloni@bootlin.com>,\n Jean Delvare <jdelvare@suse.com>, Guenter Roeck <linux@roeck-us.net>,\n Dmitry Torokhov <dmitry.torokhov@gmail.com>,\n Jonathan Corbet <corbet@lwn.net>,\n James Calligeros <jcalligeros99@gmail.com>","Cc":"asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org,\n devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,\n linux-rtc@vger.kernel.org, linux-hwmon@vger.kernel.org,\n linux-input@vger.kernel.org, linux-doc@vger.kernel.org,\n Hector Martin <marcan@marcan.st>","X-Mailer":"b4 0.14.3","X-Developer-Signature":"v=1; a=openpgp-sha256; l=9128;\n i=jcalligeros99@gmail.com; h=from:subject:message-id;\n bh=lS/4q39E8TljfGLFH7Nskm9ro5EkQw4hj2XcyHKJZLk=;\n b=owGbwMvMwCV2xczoYuD3ygTG02pJDJn215mrpy8p3nlB5ZD90yrBuRZBLrWFR2a/lzUWjYmoi\n mnw3N/dMZGFQYyLwVJMkWVDk5DHbCO2m/0ilXth5rAygQyRFmlgAAIWBr7cxLxSIx0jPVNtQz1D\n Qx1jHSMGLk4BmGqjvQx/ZQP2h/89rBe/+7vGt6M9ATL70h0fdSodumMVxZJ/J57nGSPD+fMTtvU\n XTRS/uiFxg83h3Z9kX39pC41S+MVrcz54U68CFwA=","X-Developer-Key":"i=jcalligeros99@gmail.com; a=openpgp;\n fpr=B08212489B3206D98F1479BDD43632D151F77960"},"content":"From: Hector Martin <marcan@marcan.st>\n\nThis driver implements power button and lid switch support for Apple Mac\ndevices using SMC controllers driven by the macsmc driver.\n\nIn addition to basic input support, this also responds to the final\nshutdown warning (when the power button is held down long enough) by\ndoing an emergency kernel poweroff. This allows the NVMe controller to\nbe cleanly shut down, which prevents data loss for in-cache data.\n\nReviewed-by: Neal Gompa <neal@gompa.dev>\nSigned-off-by: Hector Martin <marcan@marcan.st>\nCo-developed-by: Sven Peter <sven@kernel.org>\nSigned-off-by: Sven Peter <sven@kernel.org>\nSigned-off-by: James Calligeros <jcalligeros99@gmail.com>\n---\n MAINTAINERS                       |   1 +\n drivers/input/misc/Kconfig        |  11 ++\n drivers/input/misc/Makefile       |   1 +\n drivers/input/misc/macsmc-input.c | 207 +++++++++++++++++++++++++\n 4 files changed, 220 insertions(+)","diff":"diff --git a/MAINTAINERS b/MAINTAINERS\nindex 5f160eb6762e..7f2160a18da2 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -2492,6 +2492,7 @@ F:\tdrivers/hwmon/macsmc-hwmon.c\n F:\tdrivers/pmdomain/apple/\n F:\tdrivers/i2c/busses/i2c-pasemi-core.c\n F:\tdrivers/i2c/busses/i2c-pasemi-platform.c\n+F:\tdrivers/input/misc/macsmc-input.c\n F:\tdrivers/input/touchscreen/apple_z2.c\n F:\tdrivers/iommu/apple-dart.c\n F:\tdrivers/iommu/io-pgtable-dart.c\ndiff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig\nindex 94a753fcb64f..0e805c870e29 100644\n--- a/drivers/input/misc/Kconfig\n+++ b/drivers/input/misc/Kconfig\n@@ -1003,4 +1003,15 @@ config INPUT_STPMIC1_ONKEY\n \t  To compile this driver as a module, choose M here: the\n \t  module will be called stpmic1_onkey.\n \n+config INPUT_MACSMC\n+\ttristate \"Apple Mac SMC lid/buttons\"\n+\tdepends on MFD_MACSMC\n+\thelp\n+\t  Say Y here if you want to use the input events delivered via the\n+\t  SMC controller on Apple Mac machines using the macsmc driver.\n+\t  This includes lid open/close and the power button.\n+\n+\t  To compile this driver as a module, choose M here: the\n+\t  module will be called macsmc-input.\n+\n endif\ndiff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile\nindex 415fc4e2918b..174031304975 100644\n--- a/drivers/input/misc/Makefile\n+++ b/drivers/input/misc/Makefile\n@@ -52,6 +52,7 @@ obj-$(CONFIG_INPUT_IQS7222)\t\t+= iqs7222.o\n obj-$(CONFIG_INPUT_KEYSPAN_REMOTE)\t+= keyspan_remote.o\n obj-$(CONFIG_INPUT_KXTJ9)\t\t+= kxtj9.o\n obj-$(CONFIG_INPUT_M68K_BEEP)\t\t+= m68kspkr.o\n+obj-$(CONFIG_INPUT_MACSMC_INPUT)\t+= macsmc-input.o\n obj-$(CONFIG_INPUT_MAX7360_ROTARY)\t+= max7360-rotary.o\n obj-$(CONFIG_INPUT_MAX77650_ONKEY)\t+= max77650-onkey.o\n obj-$(CONFIG_INPUT_MAX77693_HAPTIC)\t+= max77693-haptic.o\ndiff --git a/drivers/input/misc/macsmc-input.c b/drivers/input/misc/macsmc-input.c\nnew file mode 100644\nindex 000000000000..f4598e65fc80\n--- /dev/null\n+++ b/drivers/input/misc/macsmc-input.c\n@@ -0,0 +1,207 @@\n+// SPDX-License-Identifier: GPL-2.0-only OR MIT\n+/*\n+ * Apple SMC input event driver\n+ * Copyright The Asahi Linux Contributors\n+ *\n+ * This driver exposes certain events from the SMC as an input device.\n+ * This includes the lid open/close and power button notifications.\n+ */\n+\n+#include <linux/device.h>\n+#include <linux/input.h>\n+#include <linux/mfd/macsmc.h>\n+#include <linux/module.h>\n+#include <linux/reboot.h>\n+\n+/**\n+ * struct macsmc_input\n+ * @dev: Underlying struct device for the input sub-device\n+ * @smc: Pointer to apple_smc struct of the mfd parent\n+ * @input: Allocated input_dev; devres managed\n+ * @nb: Notifier block used for incoming events from SMC (e.g. button pressed down)\n+ * @wakeup_mode: Set to true when system is suspended and power button events should wake it\n+ */\n+struct macsmc_input {\n+\tstruct device *dev;\n+\tstruct apple_smc *smc;\n+\tstruct input_dev *input;\n+\tstruct notifier_block nb;\n+\tbool wakeup_mode;\n+};\n+\n+#define SMC_EV_BTN 0x7201\n+#define SMC_EV_LID 0x7203\n+\n+#define BTN_POWER\t\t0x01 /* power button on e.g. Mac Mini chasis pressed */\n+#define BTN_TOUCHID\t\t0x06 /* combined TouchID / power button on MacBooks pressed */\n+#define BTN_POWER_HELD_SHORT\t0xfe /* power button briefly held down */\n+#define BTN_POWER_HELD_LONG\t0x00 /* power button held down; sent just before forced poweroff */\n+\n+static void macsmc_input_event_button(struct macsmc_input *smcin, unsigned long event)\n+{\n+\tu8 button = (event >> 8) & 0xff;\n+\tu8 state = !!(event & 0xff);\n+\n+\tswitch (button) {\n+\tcase BTN_POWER:\n+\tcase BTN_TOUCHID:\n+\t\tpm_wakeup_dev_event(smcin->dev, 0, (smcin->wakeup_mode && state));\n+\n+\t\t/* Suppress KEY_POWER event to prevent immediate shutdown on wake */\n+\t\tif (smcin->wakeup_mode)\n+\t\t\treturn;\n+\n+\t\tinput_report_key(smcin->input, KEY_POWER, state);\n+\t\tinput_sync(smcin->input);\n+\t\tbreak;\n+\tcase BTN_POWER_HELD_SHORT: /* power button held down; ignore */\n+\t\tbreak;\n+\tcase BTN_POWER_HELD_LONG:\n+\t\t/*\n+\t\t * If we get here the power button has been held down for a while and\n+\t\t * we have about 4 seconds before forced power-off is triggered by SMC.\n+\t\t * Try to do an emergency shutdown to make sure the NVMe cache is\n+\t\t * flushed. macOS actually does this by panicing (!)...\n+\t\t */\n+\t\tif (state) {\n+\t\t\tdev_crit(smcin->dev, \"Triggering forced shutdown!\\n\");\n+\t\t\tif (kernel_can_power_off())\n+\t\t\t\tkernel_power_off();\n+\t\t\telse /* Missing macsmc-reboot driver? */\n+\t\t\t\tkernel_restart(\"SMC power button triggered restart\");\n+\t\t}\n+\t\tbreak;\n+\tdefault:\n+\t\tdev_warn(smcin->dev, \"Unknown SMC button event: %04lx\\n\", event & 0xffff);\n+\t}\n+}\n+\n+static void macsmc_input_event_lid(struct macsmc_input *smcin, unsigned long event)\n+{\n+\tu8 lid_state = !!((event >> 8) & 0xff);\n+\n+\tpm_wakeup_dev_event(smcin->dev, 0, (smcin->wakeup_mode && !lid_state));\n+\tinput_report_switch(smcin->input, SW_LID, lid_state);\n+\tinput_sync(smcin->input);\n+}\n+\n+static int macsmc_input_event(struct notifier_block *nb, unsigned long event, void *data)\n+{\n+\tstruct macsmc_input *smcin = container_of(nb, struct macsmc_input, nb);\n+\tu16 type = event >> 16;\n+\n+\tswitch (type) {\n+\tcase SMC_EV_BTN:\n+\t\tmacsmc_input_event_button(smcin, event);\n+\t\treturn NOTIFY_OK;\n+\tcase SMC_EV_LID:\n+\t\tmacsmc_input_event_lid(smcin, event);\n+\t\treturn NOTIFY_OK;\n+\tdefault:\n+\t\t/* SMC event meant for another driver */\n+\t\treturn NOTIFY_DONE;\n+\t}\n+}\n+\n+static int macsmc_input_probe(struct platform_device *pdev)\n+{\n+\tstruct apple_smc *smc = dev_get_drvdata(pdev->dev.parent);\n+\tstruct macsmc_input *smcin;\n+\tbool have_lid, have_power;\n+\tint error;\n+\n+\t/* Bail early if this SMC neither supports power button nor lid events */\n+\thave_lid = apple_smc_key_exists(smc, SMC_KEY(MSLD));\n+\thave_power = apple_smc_key_exists(smc, SMC_KEY(bHLD));\n+\tif (!have_lid && !have_power)\n+\t\treturn -ENODEV;\n+\n+\tsmcin = devm_kzalloc(&pdev->dev, sizeof(*smcin), GFP_KERNEL);\n+\tif (!smcin)\n+\t\treturn -ENOMEM;\n+\n+\tsmcin->dev = &pdev->dev;\n+\tsmcin->smc = smc;\n+\tplatform_set_drvdata(pdev, smcin);\n+\n+\tsmcin->input = devm_input_allocate_device(&pdev->dev);\n+\tif (!smcin->input)\n+\t\treturn -ENOMEM;\n+\n+\tsmcin->input->phys = \"macsmc-input (0)\";\n+\tsmcin->input->name = \"Apple SMC power/lid events\";\n+\n+\tif (have_lid)\n+\t\tinput_set_capability(smcin->input, EV_SW, SW_LID);\n+\tif (have_power)\n+\t\tinput_set_capability(smcin->input, EV_KEY, KEY_POWER);\n+\n+\tif (have_lid) {\n+\t\tu8 val;\n+\n+\t\terror = apple_smc_read_u8(smc, SMC_KEY(MSLD), &val);\n+\t\tif (error < 0)\n+\t\t\tdev_warn(&pdev->dev, \"Failed to read initial lid state\\n\");\n+\t\telse\n+\t\t\tinput_report_switch(smcin->input, SW_LID, val);\n+\t}\n+\n+\tif (have_power) {\n+\t\tu32 val;\n+\n+\t\terror = apple_smc_read_u32(smc, SMC_KEY(bHLD), &val);\n+\t\tif (error < 0)\n+\t\t\tdev_warn(&pdev->dev, \"Failed to read initial power button state\\n\");\n+\t\telse\n+\t\t\tinput_report_key(smcin->input, KEY_POWER, val & 1);\n+\t}\n+\n+\terror = input_register_device(smcin->input);\n+\tif (error) {\n+\t\tdev_err(&pdev->dev, \"Failed to register input device: %d\\n\", error);\n+\t\treturn error;\n+\t}\n+\n+\tinput_sync(smcin->input);\n+\n+\tsmcin->nb.notifier_call = macsmc_input_event;\n+\tblocking_notifier_chain_register(&smc->event_handlers, &smcin->nb);\n+\n+\tdevice_init_wakeup(&pdev->dev, true);\n+\n+\treturn 0;\n+}\n+\n+static int macsmc_input_pm_prepare(struct device *dev)\n+{\n+\tstruct macsmc_input *smcin = dev_get_drvdata(dev);\n+\n+\tsmcin->wakeup_mode = true;\n+\treturn 0;\n+}\n+\n+static void macsmc_input_pm_complete(struct device *dev)\n+{\n+\tstruct macsmc_input *smcin = dev_get_drvdata(dev);\n+\n+\tsmcin->wakeup_mode = false;\n+}\n+\n+static const struct dev_pm_ops macsmc_input_pm_ops = {\n+\t.prepare = macsmc_input_pm_prepare,\n+\t.complete = macsmc_input_pm_complete,\n+};\n+\n+static struct platform_driver macsmc_input_driver = {\n+\t.driver = {\n+\t\t.name = \"macsmc-input\",\n+\t\t.pm = &macsmc_input_pm_ops,\n+\t},\n+\t.probe = macsmc_input_probe,\n+};\n+module_platform_driver(macsmc_input_driver);\n+\n+MODULE_AUTHOR(\"Hector Martin <marcan@marcan.st>\");\n+MODULE_LICENSE(\"Dual MIT/GPL\");\n+MODULE_DESCRIPTION(\"Apple SMC input driver\");\n+MODULE_ALIAS(\"platform:macsmc-input\");\n","prefixes":["v6","4/7"]}