From d78d95efdfec5a39e470e8e866b864c8fc096c7a Mon Sep 17 00:00:00 2001 From: Jorge Zapata Date: Tue, 17 Feb 2009 17:48:14 +0100 Subject: Platform's DRM driver loading, unloading and sysfs interface support. --- drivers/gpu/drm/drm_drv.c | 29 +++++++++++++++++++++++ drivers/gpu/drm/drm_stub.c | 57 ++++++++++++++++++++++++++++++++++++++++++--- drivers/gpu/drm/drm_sysfs.c | 6 ++++- 3 files changed, 88 insertions(+), 4 deletions(-) (limited to 'drivers/gpu') diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 14c7a23dc15..30546a72d75 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -251,6 +251,7 @@ int drm_lastclose(struct drm_device * dev) */ int drm_init(struct drm_driver *driver) { +#ifdef CONFIG_PCI struct pci_dev *pdev = NULL; struct pci_device_id *pid; int i; @@ -280,11 +281,39 @@ int drm_init(struct drm_driver *driver) drm_get_dev(pdev, pid, driver); } } +#endif return 0; } EXPORT_SYMBOL(drm_init); +/** + * + * Call this to associate a drm_driver with a platform_device. + * + * \return zero on success or a negative number on failure. + * + * This is a replacement for drm_init(), but for platform drivers. + * In this case, the caller must provide the matching platform_device + * + * since there is no physical bus to scan through. + * + * \sa drm_init + * + */ + +int drm_platform_init(struct drm_driver *driver, struct platform_device *pdev) +{ + DRM_DEBUG("\n"); + + INIT_LIST_HEAD(&driver->device_list); + + return drm_get_platform_dev(pdev, driver); +} + +EXPORT_SYMBOL(drm_platform_init); + + /** * Called via cleanup_module() at module unload time. * diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c index 46bb923b097..e8aa423bd9b 100644 --- a/drivers/gpu/drm/drm_stub.c +++ b/drivers/gpu/drm/drm_stub.c @@ -213,12 +213,13 @@ static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev, idr_init(&dev->drw_idr); dev->pdev = pdev; - dev->pci_device = pdev->device; - dev->pci_vendor = pdev->vendor; - + if (pdev) { + dev->pci_device = pdev->device; + dev->pci_vendor = pdev->vendor; #ifdef __alpha__ dev->hose = pdev->sysdata; #endif + } if (drm_ht_create(&dev->map_hash, 12)) { return -ENOMEM; @@ -418,6 +419,56 @@ err_g1: return ret; } + /** + * + * Register a platform device as a DRM device + * + * \param pdev - platform device structure + * \param driver - the matching drm_driver structure + * \return zero on success or a negative number on failure. + * + * Attempt to gets inter module "drm" information. If we are first + * then register the character device and inter module information. + * Try and register, if we fail to register, backout previous work. + * + * \sa drm_get_dev + */ +int drm_get_platform_dev(struct platform_device *pdev, + struct drm_driver *driver) +{ + struct drm_device *dev; + int ret; +#if 0 + int len; +#endif + DRM_DEBUG("\n"); + + dev = drm_calloc(1, sizeof(*dev), DRM_MEM_STUB); + if (!dev) + return -ENOMEM; + + if ((ret = drm_fill_in_dev(dev, NULL, NULL, driver))) { + printk(KERN_ERR "DRM: Fill_in_dev failed.\n"); + goto err_g1; + } + + dev->platform_dev = pdev; + if ((ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY))) + goto err_g1; + + list_add_tail(&dev->driver_item, &driver->device_list); + + 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_g1: + drm_free(dev, sizeof(*dev), DRM_MEM_STUB); + return ret; +} + /** * Put a device minor number. * diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c index 5aa6780652a..44f7f16ebd6 100644 --- a/drivers/gpu/drm/drm_sysfs.c +++ b/drivers/gpu/drm/drm_sysfs.c @@ -477,7 +477,11 @@ int drm_sysfs_device_add(struct drm_minor *minor) int i, j; char *minor_str; - minor->kdev.parent = &minor->dev->pdev->dev; + if (minor->dev->pdev) { + minor->kdev.parent = &minor->dev->pdev->dev; + } else { + minor->kdev.parent = &minor->dev->platform_dev->dev; + } minor->kdev.class = drm_class; minor->kdev.release = drm_sysfs_device_release; minor->kdev.devt = minor->device; -- cgit v1.2.3