0001
0002
0003
0004
0005
0006
0007 #include <linux/acpi.h>
0008 #include <linux/device.h>
0009 #include <linux/devm-helpers.h>
0010 #include <linux/interrupt.h>
0011 #include <linux/kernel.h>
0012 #include <linux/mod_devicetable.h>
0013 #include <linux/module.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/pm.h>
0016 #include <linux/reboot.h>
0017 #include <linux/types.h>
0018
0019 struct pwr_mlxbf {
0020 struct work_struct send_work;
0021 const char *hid;
0022 };
0023
0024 static void pwr_mlxbf_send_work(struct work_struct *work)
0025 {
0026 acpi_bus_generate_netlink_event("button/power.*", "Power Button", 0x80, 1);
0027 }
0028
0029 static irqreturn_t pwr_mlxbf_irq(int irq, void *ptr)
0030 {
0031 const char *rst_pwr_hid = "MLNXBF24";
0032 const char *low_pwr_hid = "MLNXBF29";
0033 struct pwr_mlxbf *priv = ptr;
0034
0035 if (!strncmp(priv->hid, rst_pwr_hid, 8))
0036 emergency_restart();
0037
0038 if (!strncmp(priv->hid, low_pwr_hid, 8))
0039 schedule_work(&priv->send_work);
0040
0041 return IRQ_HANDLED;
0042 }
0043
0044 static int pwr_mlxbf_probe(struct platform_device *pdev)
0045 {
0046 struct device *dev = &pdev->dev;
0047 struct acpi_device *adev;
0048 struct pwr_mlxbf *priv;
0049 const char *hid;
0050 int irq, err;
0051
0052 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
0053 if (!priv)
0054 return -ENOMEM;
0055
0056 adev = ACPI_COMPANION(dev);
0057 if (!adev)
0058 return -ENXIO;
0059
0060 hid = acpi_device_hid(adev);
0061 priv->hid = hid;
0062
0063 irq = acpi_dev_gpio_irq_get(ACPI_COMPANION(dev), 0);
0064 if (irq < 0)
0065 return dev_err_probe(dev, irq, "Error getting %s irq.\n", priv->hid);
0066
0067 err = devm_work_autocancel(dev, &priv->send_work, pwr_mlxbf_send_work);
0068 if (err)
0069 return err;
0070
0071 err = devm_request_irq(dev, irq, pwr_mlxbf_irq, 0, hid, priv);
0072 if (err)
0073 dev_err(dev, "Failed request of %s irq\n", priv->hid);
0074
0075 return err;
0076 }
0077
0078 static const struct acpi_device_id __maybe_unused pwr_mlxbf_acpi_match[] = {
0079 { "MLNXBF24", 0 },
0080 { "MLNXBF29", 0 },
0081 {},
0082 };
0083 MODULE_DEVICE_TABLE(acpi, pwr_mlxbf_acpi_match);
0084
0085 static struct platform_driver pwr_mlxbf_driver = {
0086 .driver = {
0087 .name = "pwr_mlxbf",
0088 .acpi_match_table = pwr_mlxbf_acpi_match,
0089 },
0090 .probe = pwr_mlxbf_probe,
0091 };
0092
0093 module_platform_driver(pwr_mlxbf_driver);
0094
0095 MODULE_DESCRIPTION("Mellanox BlueField power driver");
0096 MODULE_AUTHOR("Asmaa Mnebhi <asmaa@nvidia.com>");
0097 MODULE_LICENSE("Dual BSD/GPL");