[PATCH 09/12] drm: Add drm_register_device function

Sascha Hauer s.hauer at pengutronix.de
Thu Feb 2 03:58:01 PST 2012


pci, usb and platform support all duplicate the same code. Provide
a common function for this.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/gpu/drm/drm_stub.c |   56 ++++++++++++++++++++++++++++++++++++++++++++
 include/drm/drmP.h         |    2 +
 2 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
index 6d7b083..c36b19c 100644
--- a/drivers/gpu/drm/drm_stub.c
+++ b/drivers/gpu/drm/drm_stub.c
@@ -320,6 +320,62 @@ int drm_fill_in_dev(struct drm_device *dev,
 	return retcode;
 }
 
+int drm_register_device(struct drm_device *dev, struct drm_driver *driver,
+		unsigned long flags)
+{
+	int ret;
+
+	mutex_lock(&drm_global_mutex);
+
+	ret = drm_fill_in_dev(dev, NULL, driver);
+	if (ret) {
+		printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
+		goto err_g1;
+	}
+
+	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
+		ret = drm_get_minor(dev, &dev->control, DRM_MINOR_CONTROL);
+		if (ret)
+			goto err_g1;
+	}
+
+	ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY);
+	if (ret)
+		goto err_g2;
+
+	if (dev->driver->load) {
+		ret = dev->driver->load(dev, flags);
+		if (ret)
+			goto err_g3;
+	}
+
+	/* setup the grouping for the legacy output */
+	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
+		ret = drm_mode_group_init_legacy_group(dev,
+				&dev->primary->mode_group);
+		if (ret)
+			goto err_g3;
+	}
+
+	mutex_unlock(&drm_global_mutex);
+
+	DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
+		 driver->name, driver->major, driver->minor, driver->patchlevel,
+		 driver->date, dev->primary->index);
+
+	return 0;
+
+err_g3:
+	drm_put_minor(&dev->primary);
+err_g2:
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		drm_put_minor(&dev->control);
+err_g1:
+	mutex_unlock(&drm_global_mutex);
+
+	return ret;
+}
+EXPORT_SYMBOL(drm_register_device);
 
 /**
  * Get a secondary minor number.
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 3c14c05..467a9a5 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -1651,6 +1651,8 @@ extern int drm_fill_in_dev(struct drm_device *dev,
 			   const struct pci_device_id *ent,
 			   struct drm_driver *driver);
 int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type);
+int drm_register_device(struct drm_device *dev, struct drm_driver *driver,
+		unsigned long flags);
 /*@}*/
 
 /* PCI section */
-- 
1.7.8.3



More information about the dri-devel mailing list