1 // SPDX-License-Identifier: GPL-2.0
3 * ACPI PCI Hot Plug Extension for Ampere Altra. Allows control of
4 * attention LEDs via requests to system firmware.
6 * Copyright (C) 2023 Ampere Computing LLC
9 #define pr_fmt(fmt) "acpiphp_ampere_altra: " fmt
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/pci.h>
14 #include <linux/pci_hotplug.h>
15 #include <linux/platform_device.h>
19 #define HANDLE_OPEN 0xb0200000
20 #define HANDLE_CLOSE 0xb0300000
21 #define REQUEST 0xf0700000
22 #define LED_CMD 0x00000004
23 #define LED_ATTENTION 0x00000002
24 #define LED_SET_ON 0x00000001
25 #define LED_SET_OFF 0x00000002
26 #define LED_SET_BLINK 0x00000003
28 static u32 led_service_id[4];
30 static int led_status(u8 status)
33 case 1: return LED_SET_ON;
34 case 2: return LED_SET_BLINK;
35 default: return LED_SET_OFF;
39 static int set_attention_status(struct hotplug_slot *slot, u8 status)
41 struct arm_smccc_res res;
43 struct pci_dev *root_port;
48 bus = slot->pci_slot->bus;
49 root_port = pcie_find_root_port(bus->self);
53 local_irq_save(flags);
54 arm_smccc_smc(HANDLE_OPEN, led_service_id[0], led_service_id[1],
55 led_service_id[2], led_service_id[3], 0, 0, 0, &res);
60 handle = res.a1 & 0xffff0000;
62 arm_smccc_smc(REQUEST, LED_CMD, led_status(status), LED_ATTENTION,
63 (PCI_SLOT(root_port->devfn) << 4) | (pci_domain_nr(bus) & 0xf),
68 arm_smccc_smc(HANDLE_CLOSE, handle, 0, 0, 0, 0, 0, 0, &res);
71 local_irq_restore(flags);
75 static int get_attention_status(struct hotplug_slot *slot, u8 *status)
80 static struct acpiphp_attention_info ampere_altra_attn = {
81 .set_attn = set_attention_status,
82 .get_attn = get_attention_status,
86 static int altra_led_probe(struct platform_device *pdev)
88 struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev);
91 ret = fwnode_property_read_u32_array(fwnode, "uuid", led_service_id, 4);
93 dev_err(&pdev->dev, "can't find uuid\n");
97 ret = acpiphp_register_attention(&ere_altra_attn);
99 dev_err(&pdev->dev, "can't register driver\n");
105 static void altra_led_remove(struct platform_device *pdev)
107 acpiphp_unregister_attention(&ere_altra_attn);
110 static const struct acpi_device_id altra_led_ids[] = {
114 MODULE_DEVICE_TABLE(acpi, altra_led_ids);
116 static struct platform_driver altra_led_driver = {
118 .name = "ampere-altra-leds",
119 .acpi_match_table = altra_led_ids,
121 .probe = altra_led_probe,
122 .remove_new = altra_led_remove,
124 module_platform_driver(altra_led_driver);
126 MODULE_AUTHOR("D Scott Phillips <scott@os.amperecomputing.com>");
127 MODULE_LICENSE("GPL");