Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/connector: Add a fwnode pointer to drm_connector and register with ACPI (v2)

Add a fwnode pointer to struct drm_connector and register an acpi_bus_type
for the connectors with the ACPI subsystem (when CONFIG_ACPI is enabled).

The adding of the fwnode pointer allows drivers to associate a fwnode
that represents a connector with that connector.

When the new fwnode pointer points to an ACPI-companion, then the new
acpi_bus_type will cause the ACPI subsys to bind the device instantiated
for the connector with the fwnode by calling acpi_bind_one(). This will
result in a firmware_node symlink under /sys/class/card#-<connecter-name>/
which helps to verify that the fwnode-s and connectors are properly
matched.

Changes in v2:
- Make drm_connector_cleanup() call fwnode_handle_put() on
connector->fwnode and document this

Co-developed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Tested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Link: https://lore.kernel.org/r/20210817215201.795062-3-hdegoede@redhat.com

+47
+2
drivers/gpu/drm/drm_connector.c
··· 474 474 drm_mode_object_unregister(dev, &connector->base); 475 475 kfree(connector->name); 476 476 connector->name = NULL; 477 + fwnode_handle_put(connector->fwnode); 478 + connector->fwnode = NULL; 477 479 spin_lock_irq(&dev->mode_config.connector_list_lock); 478 480 list_del(&connector->head); 479 481 dev->mode_config.num_connector--;
+37
drivers/gpu/drm/drm_sysfs.c
··· 10 10 * Copyright (c) 2003-2004 IBM Corp. 11 11 */ 12 12 13 + #include <linux/acpi.h> 13 14 #include <linux/device.h> 14 15 #include <linux/err.h> 15 16 #include <linux/export.h> ··· 57 56 58 57 struct class *drm_class; 59 58 59 + #ifdef CONFIG_ACPI 60 + static bool drm_connector_acpi_bus_match(struct device *dev) 61 + { 62 + return dev->type == &drm_sysfs_device_connector; 63 + } 64 + 65 + static struct acpi_device *drm_connector_acpi_find_companion(struct device *dev) 66 + { 67 + struct drm_connector *connector = to_drm_connector(dev); 68 + 69 + return to_acpi_device_node(connector->fwnode); 70 + } 71 + 72 + static struct acpi_bus_type drm_connector_acpi_bus = { 73 + .name = "drm_connector", 74 + .match = drm_connector_acpi_bus_match, 75 + .find_companion = drm_connector_acpi_find_companion, 76 + }; 77 + 78 + static void drm_sysfs_acpi_register(void) 79 + { 80 + register_acpi_bus_type(&drm_connector_acpi_bus); 81 + } 82 + 83 + static void drm_sysfs_acpi_unregister(void) 84 + { 85 + unregister_acpi_bus_type(&drm_connector_acpi_bus); 86 + } 87 + #else 88 + static void drm_sysfs_acpi_register(void) { } 89 + static void drm_sysfs_acpi_unregister(void) { } 90 + #endif 91 + 60 92 static char *drm_devnode(struct device *dev, umode_t *mode) 61 93 { 62 94 return kasprintf(GFP_KERNEL, "dri/%s", dev_name(dev)); ··· 123 89 } 124 90 125 91 drm_class->devnode = drm_devnode; 92 + 93 + drm_sysfs_acpi_register(); 126 94 return 0; 127 95 } 128 96 ··· 137 101 { 138 102 if (IS_ERR_OR_NULL(drm_class)) 139 103 return; 104 + drm_sysfs_acpi_unregister(); 140 105 class_remove_file(drm_class, &class_attr_version.attr); 141 106 class_destroy(drm_class); 142 107 drm_class = NULL;
+8
include/drm/drm_connector.h
··· 1228 1228 struct device *kdev; 1229 1229 /** @attr: sysfs attributes */ 1230 1230 struct device_attribute *attr; 1231 + /** 1232 + * @fwnode: associated fwnode supplied by platform firmware 1233 + * 1234 + * Drivers can set this to associate a fwnode with a connector, drivers 1235 + * are expected to get a reference on the fwnode when setting this. 1236 + * drm_connector_cleanup() will call fwnode_handle_put() on this. 1237 + */ 1238 + struct fwnode_handle *fwnode; 1231 1239 1232 1240 /** 1233 1241 * @head: