// SPDX-License-Identifier: GPL-2.0+ /* * Surface Book (2 and later) hot-plug driver. * * Surface Book devices (can) have a hot-pluggable discrete GPU (dGPU). This * driver is responsible for out-of-band hot-plug event signaling on these * devices. It is specifically required when the hot-plug device is in D3cold * and can thus not generate PCIe hot-plug events itself. * * Event signaling is handled via ACPI, which will generate the appropriate * device-check notifications to be picked up by the PCIe hot-plug driver. * * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
*/
enum shps_irq_type { /* NOTE: Must be in order of enum shps_dsm_fn above. */
SHPS_IRQ_TYPE_BASE_PRESENCE = 0,
SHPS_IRQ_TYPE_DEVICE_POWER = 1,
SHPS_IRQ_TYPE_DEVICE_PRESENCE = 2,
SHPS_NUM_IRQS,
};
staticvoid shps_dsm_notify_irq(struct platform_device *pdev, enum shps_irq_type type)
{ struct shps_device *sdev = platform_get_drvdata(pdev);
acpi_handle handle = ACPI_HANDLE(&pdev->dev); union acpi_object *result; union acpi_object param; int value;
mutex_lock(&sdev->lock[type]);
value = gpiod_get_value_cansleep(sdev->gpio[type]); if (value < 0) {
mutex_unlock(&sdev->lock[type]);
dev_err(&pdev->dev, "failed to get gpio: %d (irq=%d)\n", type, value); return;
}
dev_dbg(&pdev->dev, "IRQ notification via DSM (irq=%d, value=%d)\n", type, value);
/* * Only set up interrupts that we actually need: The Surface Book 3 * does not have a DSM for base presence, so don't set up an interrupt * for that.
*/ if (!acpi_check_dsm(handle, &shps_dsm_guid, SHPS_DSM_REVISION, BIT(dsm))) {
dev_dbg(&pdev->dev, "IRQ notification via DSM not present (irq=%d)\n", type); return 0;
}
gpiod = devm_gpiod_get(&pdev->dev, shps_gpio_names[type], GPIOD_ASIS); if (IS_ERR(gpiod)) return PTR_ERR(gpiod);
irq = gpiod_to_irq(gpiod); if (irq < 0) return irq;
irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "shps-irq-%d", type); if (!irq_name) return -ENOMEM;
status = devm_request_threaded_irq(&pdev->dev, irq, NULL, shps_handle_irq,
flags, irq_name, pdev); if (status) return status;
dev_dbg(&pdev->dev, "set up irq %d as type %d\n", irq, type);
/* Ensure that IRQs have been fully handled and won't trigger any more. */ for (i = 0; i < SHPS_NUM_IRQS; i++) { if (sdev->irq[i] != SHPS_IRQ_NOT_PRESENT)
disable_irq(sdev->irq[i]);
/* * The MSHW0153 device is also present on the Surface Laptop 3, * however that doesn't have a hot-pluggable PCIe device. It also * doesn't have any GPIO interrupts/pins under the MSHW0153, so filter * it out here.
*/ if (gpiod_count(&pdev->dev, NULL) < 0) return -ENODEV;
status = devm_acpi_dev_add_driver_gpios(&pdev->dev, shps_acpi_gpios); if (status) return status;
sdev = devm_kzalloc(&pdev->dev, sizeof(*sdev), GFP_KERNEL); if (!sdev) return -ENOMEM;
platform_set_drvdata(pdev, sdev);
/* * Initialize IRQs so that we can safely call surface_hotplug_remove() * on errors.
*/ for (i = 0; i < SHPS_NUM_IRQS; i++)
sdev->irq[i] = SHPS_IRQ_NOT_PRESENT;
/* Set up IRQs. */ for (i = 0; i < SHPS_NUM_IRQS; i++) {
mutex_init(&sdev->lock[i]);
status = shps_setup_irq(pdev, i); if (status) {
dev_err(&pdev->dev, "failed to set up IRQ %d: %d\n", i, status); goto err;
}
}
/* Ensure everything is up-to-date. */ for (i = 0; i < SHPS_NUM_IRQS; i++) if (sdev->irq[i] != SHPS_IRQ_NOT_PRESENT)
shps_dsm_notify_irq(pdev, i);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.