2007-09-19 22:01:29 -06:00
|
|
|
|
2004-09-22 23:40:05 -06:00
|
|
|
/*
|
2004-09-30 15:12:10 -06:00
|
|
|
* drm_sysfs.c - Modifications to drm_sysfs_class.c to support
|
2004-09-22 23:40:05 -06:00
|
|
|
* extra sysfs attribute from DRM. Normal drm_sysfs_class
|
|
|
|
* does not allow adding attributes.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Jon Smirl <jonsmirl@gmail.com>
|
|
|
|
* Copyright (c) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
|
|
|
|
* Copyright (c) 2003-2004 IBM Corp.
|
|
|
|
*
|
|
|
|
* This file is released under the GPLv2
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/kdev_t.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
#include "drm_core.h"
|
2007-09-19 22:01:29 -06:00
|
|
|
#include "drmP.h"
|
2004-09-22 23:40:05 -06:00
|
|
|
|
2008-01-03 23:49:40 -07:00
|
|
|
#define to_drm_minor(d) container_of(d, struct drm_minor, kdev)
|
2007-10-26 17:08:54 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_sysfs_suspend - DRM class suspend hook
|
|
|
|
* @dev: Linux device to suspend
|
|
|
|
* @state: power state to enter
|
|
|
|
*
|
|
|
|
* Just figures out what the actual struct drm_device associated with
|
|
|
|
* @dev is and calls its suspend hook, if present.
|
|
|
|
*/
|
|
|
|
static int drm_sysfs_suspend(struct device *dev, pm_message_t state)
|
|
|
|
{
|
2008-01-03 23:49:40 -07:00
|
|
|
struct drm_minor *drm_minor = to_drm_minor(dev);
|
|
|
|
struct drm_device *drm_dev = drm_minor->dev;
|
2007-10-26 17:08:54 -06:00
|
|
|
|
|
|
|
printk(KERN_ERR "%s\n", __FUNCTION__);
|
|
|
|
|
2008-01-08 22:21:56 -07:00
|
|
|
if (drm_minor->type == DRM_MINOR_CONTROL)
|
|
|
|
if (drm_dev->driver->suspend)
|
2008-02-21 04:37:07 -07:00
|
|
|
return drm_dev->driver->suspend(drm_dev, state);
|
2007-10-26 17:08:54 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_sysfs_resume - DRM class resume hook
|
|
|
|
* @dev: Linux device to resume
|
|
|
|
*
|
|
|
|
* Just figures out what the actual struct drm_device associated with
|
|
|
|
* @dev is and calls its resume hook, if present.
|
|
|
|
*/
|
|
|
|
static int drm_sysfs_resume(struct device *dev)
|
|
|
|
{
|
2008-01-03 23:49:40 -07:00
|
|
|
struct drm_minor *drm_minor = to_drm_minor(dev);
|
|
|
|
struct drm_device *drm_dev = drm_minor->dev;
|
2007-10-26 17:08:54 -06:00
|
|
|
|
2008-01-08 22:21:56 -07:00
|
|
|
if (drm_minor->type == DRM_MINOR_CONTROL)
|
|
|
|
if (drm_dev->driver->resume)
|
|
|
|
return drm_dev->driver->resume(drm_dev);
|
2007-10-26 17:08:54 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-22 23:40:05 -06:00
|
|
|
/* Display the version of drm_core. This doesn't work right in current design */
|
|
|
|
static ssize_t version_show(struct class *dev, char *buf)
|
|
|
|
{
|
2005-02-07 04:20:43 -07:00
|
|
|
return sprintf(buf, "%s %d.%d.%d %s\n", CORE_NAME, CORE_MAJOR,
|
|
|
|
CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
|
2004-09-22 23:40:05 -06:00
|
|
|
}
|
2004-09-30 15:12:10 -06:00
|
|
|
|
2004-09-22 23:40:05 -06:00
|
|
|
static CLASS_ATTR(version, S_IRUGO, version_show, NULL);
|
|
|
|
|
|
|
|
/**
|
2004-09-27 13:51:38 -06:00
|
|
|
* drm_sysfs_create - create a struct drm_sysfs_class structure
|
2004-09-22 23:40:05 -06:00
|
|
|
* @owner: pointer to the module that is to "own" this struct drm_sysfs_class
|
|
|
|
* @name: pointer to a string for the name of this class.
|
|
|
|
*
|
2007-10-26 17:08:54 -06:00
|
|
|
* This is used to create DRM class pointer that can then be used
|
2004-09-27 13:51:38 -06:00
|
|
|
* in calls to drm_sysfs_device_add().
|
2004-09-22 23:40:05 -06:00
|
|
|
*
|
|
|
|
* Note, the pointer created here is to be destroyed when finished by making a
|
2004-09-27 13:51:38 -06:00
|
|
|
* call to drm_sysfs_destroy().
|
2004-09-22 23:40:05 -06:00
|
|
|
*/
|
2007-09-19 22:01:29 -06:00
|
|
|
struct class *drm_sysfs_create(struct module *owner, char *name)
|
2004-09-22 23:40:05 -06:00
|
|
|
{
|
2007-09-19 22:01:29 -06:00
|
|
|
struct class *class;
|
|
|
|
int err;
|
2004-09-22 23:40:05 -06:00
|
|
|
|
2007-09-19 22:01:29 -06:00
|
|
|
class = class_create(owner, name);
|
|
|
|
if (IS_ERR(class)) {
|
|
|
|
err = PTR_ERR(class);
|
|
|
|
goto err_out;
|
2004-09-22 23:40:05 -06:00
|
|
|
}
|
2007-09-19 22:01:29 -06:00
|
|
|
|
2007-11-09 10:08:08 -07:00
|
|
|
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22))
|
2007-10-26 17:08:54 -06:00
|
|
|
class->suspend = drm_sysfs_suspend;
|
|
|
|
class->resume = drm_sysfs_resume;
|
2007-11-09 10:08:08 -07:00
|
|
|
#endif
|
2007-10-26 17:08:54 -06:00
|
|
|
|
2007-09-19 22:01:29 -06:00
|
|
|
err = class_create_file(class, &class_attr_version);
|
|
|
|
if (err)
|
|
|
|
goto err_out_class;
|
|
|
|
|
|
|
|
return class;
|
|
|
|
|
|
|
|
err_out_class:
|
|
|
|
class_destroy(class);
|
|
|
|
err_out:
|
|
|
|
return ERR_PTR(err);
|
2004-09-22 23:40:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-10-26 17:08:54 -06:00
|
|
|
* drm_sysfs_destroy - destroys DRM class
|
2004-09-22 23:40:05 -06:00
|
|
|
*
|
2007-10-26 17:08:54 -06:00
|
|
|
* Destroy the DRM device class.
|
2004-09-22 23:40:05 -06:00
|
|
|
*/
|
2007-10-26 17:08:54 -06:00
|
|
|
void drm_sysfs_destroy(void)
|
2004-09-22 23:40:05 -06:00
|
|
|
{
|
2007-10-26 17:08:54 -06:00
|
|
|
if ((drm_class == NULL) || (IS_ERR(drm_class)))
|
2004-09-22 23:40:05 -06:00
|
|
|
return;
|
2007-10-26 17:08:54 -06:00
|
|
|
class_remove_file(drm_class, &class_attr_version);
|
|
|
|
class_destroy(drm_class);
|
2004-09-22 23:40:05 -06:00
|
|
|
}
|
|
|
|
|
2007-10-26 17:08:54 -06:00
|
|
|
static ssize_t show_dri(struct device *device, struct device_attribute *attr,
|
|
|
|
char *buf)
|
2005-07-03 11:16:12 -06:00
|
|
|
{
|
2008-01-03 23:49:40 -07:00
|
|
|
struct drm_minor *drm_minor = to_drm_minor(device);
|
|
|
|
struct drm_device *drm_dev = drm_minor->dev;
|
|
|
|
if (drm_dev->driver->dri_library_name)
|
|
|
|
return drm_dev->driver->dri_library_name(drm_dev, buf);
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%s\n", drm_dev->driver->pci_driver.name);
|
2005-07-03 11:16:12 -06:00
|
|
|
}
|
|
|
|
|
2007-10-26 17:08:54 -06:00
|
|
|
/**
|
|
|
|
* drm_sysfs_device_release - do nothing
|
|
|
|
* @dev: Linux device
|
|
|
|
*
|
|
|
|
* Normally, this would free the DRM device associated with @dev, along
|
|
|
|
* with cleaning up any other stuff. But we do that in the DRM core, so
|
|
|
|
* this function can just return and hope that the core does its job.
|
|
|
|
*/
|
|
|
|
static void drm_sysfs_device_release(struct device *dev)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-08 13:42:23 -06:00
|
|
|
/*
|
2008-05-29 23:03:12 -06:00
|
|
|
* Connector properties
|
2008-04-08 13:42:23 -06:00
|
|
|
*/
|
|
|
|
static ssize_t status_show(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
2008-05-29 23:03:12 -06:00
|
|
|
struct drm_connector *connector = container_of(device, struct drm_connector, kdev);
|
2008-04-08 13:42:23 -06:00
|
|
|
return snprintf(buf, PAGE_SIZE, "%s",
|
2008-05-29 23:03:12 -06:00
|
|
|
drm_get_connector_status_name(connector->funcs->detect(connector)));
|
2008-04-08 13:42:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dpms_show(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
2008-05-29 23:03:12 -06:00
|
|
|
struct drm_connector *connector = container_of(device, struct drm_connector, kdev);
|
|
|
|
struct drm_device *dev = connector->dev;
|
2008-04-08 13:42:23 -06:00
|
|
|
uint64_t dpms_status;
|
|
|
|
int ret;
|
|
|
|
|
2008-05-29 23:03:12 -06:00
|
|
|
ret = drm_connector_property_get_value(connector,
|
2008-04-08 13:42:23 -06:00
|
|
|
dev->mode_config.dpms_property,
|
|
|
|
&dpms_status);
|
|
|
|
if (ret)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%s", drm_get_dpms_name((int)dpms_status));
|
|
|
|
}
|
|
|
|
|
2008-07-03 00:07:35 -06:00
|
|
|
static ssize_t enabled_show(struct device *device,
|
2008-07-02 17:05:07 -06:00
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct drm_connector *connector = container_of(device, struct drm_connector, kdev);
|
|
|
|
|
|
|
|
if (connector->encoder)
|
2008-07-03 00:07:35 -06:00
|
|
|
return snprintf(buf, PAGE_SIZE, "enabled");
|
2008-07-02 17:05:07 -06:00
|
|
|
else
|
2008-07-03 00:07:35 -06:00
|
|
|
return snprintf(buf, PAGE_SIZE, "disabled");
|
2008-07-02 17:05:07 -06:00
|
|
|
}
|
|
|
|
|
2008-04-08 13:42:23 -06:00
|
|
|
static ssize_t edid_show(struct kobject *kobj, struct bin_attribute *attr,
|
|
|
|
char *buf, loff_t off, size_t count)
|
|
|
|
{
|
2008-05-29 23:03:12 -06:00
|
|
|
struct device *connector_dev = container_of(kobj, struct device, kobj);
|
|
|
|
struct drm_connector *connector = container_of(connector_dev, struct drm_connector,
|
2008-04-08 13:42:23 -06:00
|
|
|
kdev);
|
|
|
|
unsigned char *edid;
|
|
|
|
size_t size;
|
|
|
|
|
2008-05-29 23:03:12 -06:00
|
|
|
if (!connector->edid_blob_ptr)
|
2008-04-08 13:42:23 -06:00
|
|
|
return 0;
|
|
|
|
|
2008-05-29 23:03:12 -06:00
|
|
|
edid = connector->edid_blob_ptr->data;
|
|
|
|
size = connector->edid_blob_ptr->length;
|
2008-04-08 13:42:23 -06:00
|
|
|
if (!edid)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (off >= size)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (off + count > size)
|
|
|
|
count = size - off;
|
|
|
|
memcpy(buf, edid + off, count);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t modes_show(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
2008-05-29 23:03:12 -06:00
|
|
|
struct drm_connector *connector = container_of(device, struct drm_connector, kdev);
|
2008-04-08 13:42:23 -06:00
|
|
|
struct drm_display_mode *mode;
|
|
|
|
int written = 0;
|
|
|
|
|
2008-05-29 23:03:12 -06:00
|
|
|
list_for_each_entry(mode, &connector->modes, head) {
|
2008-04-08 13:42:23 -06:00
|
|
|
written += snprintf(buf + written, PAGE_SIZE - written, "%s\n",
|
|
|
|
mode->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
2008-07-04 09:17:11 -06:00
|
|
|
static ssize_t subconnector_show(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct drm_connector *connector = container_of(device, struct drm_connector, kdev);
|
|
|
|
struct drm_device *dev = connector->dev;
|
|
|
|
struct drm_property *prop = NULL;
|
|
|
|
uint64_t subconnector;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (connector->connector_type) {
|
|
|
|
case DRM_MODE_CONNECTOR_DVII:
|
|
|
|
prop = dev->mode_config.dvi_i_subconnector_property;
|
|
|
|
break;
|
|
|
|
case DRM_MODE_CONNECTOR_Composite:
|
|
|
|
case DRM_MODE_CONNECTOR_SVIDEO:
|
|
|
|
case DRM_MODE_CONNECTOR_Component:
|
|
|
|
prop = dev->mode_config.tv_subconnector_property;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DRM_ERROR("Wrong connector type for this property\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!prop) {
|
|
|
|
DRM_ERROR("Unable to find subconnector property\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = drm_connector_property_get_value(connector, prop, &subconnector);
|
|
|
|
if (ret)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%s", drm_get_subconnector_name((int)subconnector));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t select_subconnector_show(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct drm_connector *connector = container_of(device, struct drm_connector, kdev);
|
|
|
|
struct drm_device *dev = connector->dev;
|
|
|
|
struct drm_property *prop = NULL;
|
|
|
|
uint64_t subconnector;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (connector->connector_type) {
|
|
|
|
case DRM_MODE_CONNECTOR_DVII:
|
|
|
|
prop = dev->mode_config.dvi_i_select_subconnector_property;
|
|
|
|
break;
|
|
|
|
case DRM_MODE_CONNECTOR_Composite:
|
|
|
|
case DRM_MODE_CONNECTOR_SVIDEO:
|
|
|
|
case DRM_MODE_CONNECTOR_Component:
|
|
|
|
prop = dev->mode_config.tv_select_subconnector_property;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DRM_ERROR("Wrong connector type for this property\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!prop) {
|
|
|
|
DRM_ERROR("Unable to find select subconnector property\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = drm_connector_property_get_value(connector, prop, &subconnector);
|
|
|
|
if (ret)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%s", drm_get_select_subconnector_name((int)subconnector));
|
|
|
|
}
|
|
|
|
|
2008-05-29 23:03:12 -06:00
|
|
|
static struct device_attribute connector_attrs[] = {
|
2008-04-08 13:42:23 -06:00
|
|
|
__ATTR_RO(status),
|
2008-07-03 00:07:35 -06:00
|
|
|
__ATTR_RO(enabled),
|
2008-04-08 13:42:23 -06:00
|
|
|
__ATTR_RO(dpms),
|
|
|
|
__ATTR_RO(modes),
|
|
|
|
};
|
|
|
|
|
2008-07-04 09:17:11 -06:00
|
|
|
/* These attributes are for both DVI-I connectors and all types of tv-out. */
|
|
|
|
static struct device_attribute connector_attrs_opt1[] = {
|
|
|
|
__ATTR_RO(subconnector),
|
|
|
|
__ATTR_RO(select_subconnector),
|
|
|
|
};
|
|
|
|
|
2008-04-08 13:42:23 -06:00
|
|
|
static struct bin_attribute edid_attr = {
|
|
|
|
.attr.name = "edid",
|
|
|
|
.size = 128,
|
|
|
|
.read = edid_show,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2008-05-29 23:03:12 -06:00
|
|
|
* drm_sysfs_connector_add - add an connector to sysfs
|
|
|
|
* @connector: connector to add
|
2008-04-08 13:42:23 -06:00
|
|
|
*
|
2008-05-29 23:03:12 -06:00
|
|
|
* Create an connector device in sysfs, along with its associated connector
|
2008-04-08 13:42:23 -06:00
|
|
|
* properties (so far, connection status, dpms, mode list & edid) and
|
2008-05-29 23:03:12 -06:00
|
|
|
* generate a hotplug event so userspace knows there's a new connector
|
2008-04-08 13:42:23 -06:00
|
|
|
* available.
|
2008-06-05 16:58:43 -06:00
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* This routine should only be called *once* for each DRM minor registered.
|
|
|
|
* A second call for an already registered device will trigger the BUG_ON
|
|
|
|
* below.
|
2008-04-08 13:42:23 -06:00
|
|
|
*/
|
2008-05-29 23:03:12 -06:00
|
|
|
int drm_sysfs_connector_add(struct drm_connector *connector)
|
2008-04-08 13:42:23 -06:00
|
|
|
{
|
2008-05-29 23:03:12 -06:00
|
|
|
struct drm_device *dev = connector->dev;
|
2008-04-08 13:42:23 -06:00
|
|
|
int ret = 0, i, j;
|
|
|
|
|
2008-06-05 16:58:43 -06:00
|
|
|
/* We shouldn't get called more than once for the same connector */
|
|
|
|
BUG_ON(device_is_registered(&connector->kdev));
|
2008-04-08 13:42:23 -06:00
|
|
|
|
2008-05-29 23:03:12 -06:00
|
|
|
connector->kdev.parent = &dev->primary->kdev;
|
|
|
|
connector->kdev.class = drm_class;
|
|
|
|
connector->kdev.release = drm_sysfs_device_release;
|
2008-04-08 13:42:23 -06:00
|
|
|
|
2008-06-05 16:58:43 -06:00
|
|
|
DRM_DEBUG("adding \"%s\" to sysfs\n",
|
|
|
|
drm_get_connector_name(connector));
|
2008-04-08 13:42:23 -06:00
|
|
|
|
2008-05-29 23:03:12 -06:00
|
|
|
snprintf(connector->kdev.bus_id, BUS_ID_SIZE, "card%d-%s",
|
|
|
|
dev->primary->index, drm_get_connector_name(connector));
|
|
|
|
ret = device_register(&connector->kdev);
|
2008-04-08 13:42:23 -06:00
|
|
|
|
|
|
|
if (ret) {
|
2008-05-29 23:03:12 -06:00
|
|
|
DRM_ERROR("failed to register connector device: %d\n", ret);
|
2008-04-08 13:42:23 -06:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-07-04 09:17:11 -06:00
|
|
|
/* Standard attributes */
|
|
|
|
|
2008-05-29 23:03:12 -06:00
|
|
|
for (i = 0; i < ARRAY_SIZE(connector_attrs); i++) {
|
|
|
|
ret = device_create_file(&connector->kdev, &connector_attrs[i]);
|
2008-04-08 13:42:23 -06:00
|
|
|
if (ret)
|
|
|
|
goto err_out_files;
|
|
|
|
}
|
|
|
|
|
2008-07-04 09:17:11 -06:00
|
|
|
/* Optional attributes */
|
|
|
|
/* On the long run it maybe a good idea to make one set of optionals per connector type. */
|
|
|
|
|
|
|
|
switch (connector->connector_type) {
|
|
|
|
case DRM_MODE_CONNECTOR_DVII:
|
|
|
|
case DRM_MODE_CONNECTOR_Composite:
|
|
|
|
case DRM_MODE_CONNECTOR_SVIDEO:
|
|
|
|
case DRM_MODE_CONNECTOR_Component:
|
|
|
|
for (i = 0; i < ARRAY_SIZE(connector_attrs_opt1); i++) {
|
|
|
|
ret = device_create_file(&connector->kdev, &connector_attrs_opt1[i]);
|
|
|
|
if (ret)
|
|
|
|
goto err_out_files;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-29 23:03:12 -06:00
|
|
|
ret = sysfs_create_bin_file(&connector->kdev.kobj, &edid_attr);
|
2008-04-08 13:42:23 -06:00
|
|
|
if (ret)
|
|
|
|
goto err_out_files;
|
|
|
|
|
2008-05-29 23:03:12 -06:00
|
|
|
/* Let userspace know we have a new connector */
|
2008-04-08 13:42:23 -06:00
|
|
|
drm_sysfs_hotplug_event(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_out_files:
|
|
|
|
if (i > 0)
|
|
|
|
for (j = 0; j < i; j++)
|
2008-05-29 23:03:12 -06:00
|
|
|
device_remove_file(&connector->kdev, &connector_attrs[i]);
|
|
|
|
device_unregister(&connector->kdev);
|
2008-04-08 13:42:23 -06:00
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
2008-05-29 23:03:12 -06:00
|
|
|
EXPORT_SYMBOL(drm_sysfs_connector_add);
|
2008-04-08 13:42:23 -06:00
|
|
|
|
|
|
|
/**
|
2008-05-29 23:03:12 -06:00
|
|
|
* drm_sysfs_connector_remove - remove an connector device from sysfs
|
|
|
|
* @connector: connector to remove
|
2008-04-08 13:42:23 -06:00
|
|
|
*
|
2008-05-29 23:03:12 -06:00
|
|
|
* Remove @connector and its associated attributes from sysfs. Note that
|
2008-04-08 13:42:23 -06:00
|
|
|
* the device model core will take care of sending the "remove" uevent
|
|
|
|
* at this time, so we don't need to do it.
|
2008-06-05 16:58:43 -06:00
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* This routine should only be called if the connector was previously
|
|
|
|
* successfully registered. If @connector hasn't been registered yet,
|
|
|
|
* you'll likely see a panic somewhere deep in sysfs code when called.
|
2008-04-08 13:42:23 -06:00
|
|
|
*/
|
2008-05-29 23:03:12 -06:00
|
|
|
void drm_sysfs_connector_remove(struct drm_connector *connector)
|
2008-04-08 13:42:23 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-06-05 16:58:43 -06:00
|
|
|
DRM_DEBUG("removing \"%s\" from sysfs\n",
|
|
|
|
drm_get_connector_name(connector));
|
2008-06-03 21:16:49 -06:00
|
|
|
|
2008-05-29 23:03:12 -06:00
|
|
|
for (i = 0; i < ARRAY_SIZE(connector_attrs); i++)
|
|
|
|
device_remove_file(&connector->kdev, &connector_attrs[i]);
|
|
|
|
sysfs_remove_bin_file(&connector->kdev.kobj, &edid_attr);
|
|
|
|
device_unregister(&connector->kdev);
|
2008-04-08 13:42:23 -06:00
|
|
|
}
|
2008-05-29 23:03:12 -06:00
|
|
|
EXPORT_SYMBOL(drm_sysfs_connector_remove);
|
2008-04-08 13:42:23 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_sysfs_hotplug_event - generate a DRM uevent
|
|
|
|
* @dev: DRM device
|
|
|
|
*
|
|
|
|
* Send a uevent for the DRM device specified by @dev. Currently we only
|
|
|
|
* set HOTPLUG=1 in the uevent environment, but this could be expanded to
|
|
|
|
* deal with other types of events.
|
|
|
|
*/
|
|
|
|
void drm_sysfs_hotplug_event(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
char *event_string = "HOTPLUG=1";
|
|
|
|
char *envp[] = { event_string, NULL };
|
|
|
|
|
|
|
|
DRM_DEBUG("generating hotplug event\n");
|
|
|
|
|
|
|
|
kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, envp);
|
|
|
|
}
|
2008-08-09 11:33:32 -06:00
|
|
|
EXPORT_SYMBOL(drm_sysfs_hotplug_event);
|
2008-04-08 13:42:23 -06:00
|
|
|
|
|
|
|
static struct device_attribute dri_attrs[] = {
|
|
|
|
__ATTR(dri_library_name, S_IRUGO, show_dri, NULL),
|
|
|
|
};
|
|
|
|
|
2004-09-22 23:40:05 -06:00
|
|
|
/**
|
2004-09-27 13:51:38 -06:00
|
|
|
* drm_sysfs_device_add - adds a class device to sysfs for a character driver
|
2007-10-26 17:08:54 -06:00
|
|
|
* @dev: DRM device to be added
|
|
|
|
* @head: DRM head in question
|
2004-09-22 23:40:05 -06:00
|
|
|
*
|
2007-10-26 17:08:54 -06:00
|
|
|
* Add a DRM device to the DRM's device model class. We use @dev's PCI device
|
|
|
|
* as the parent for the Linux device, and make sure it has a file containing
|
|
|
|
* the driver we're using (for userspace compatibility).
|
2008-06-05 16:58:43 -06:00
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* This routine should only be called *once* for each DRM minor registered.
|
|
|
|
* A second call for an already registered device will trigger the BUG_ON
|
|
|
|
* below.
|
2004-09-22 23:40:05 -06:00
|
|
|
*/
|
2008-01-03 23:49:40 -07:00
|
|
|
int drm_sysfs_device_add(struct drm_minor *minor)
|
2004-09-22 23:40:05 -06:00
|
|
|
{
|
2007-10-26 17:08:54 -06:00
|
|
|
int err;
|
|
|
|
int i, j;
|
2008-01-03 23:49:40 -07:00
|
|
|
char *minor_str;
|
|
|
|
|
|
|
|
minor->kdev.parent = &minor->dev->pdev->dev;
|
|
|
|
minor->kdev.class = drm_class;
|
|
|
|
minor->kdev.release = drm_sysfs_device_release;
|
|
|
|
minor->kdev.devt = minor->device;
|
|
|
|
if (minor->type == DRM_MINOR_CONTROL)
|
2008-02-12 19:12:52 -07:00
|
|
|
minor_str = "controlD%d";
|
2008-02-14 17:04:28 -07:00
|
|
|
else if (minor->type == DRM_MINOR_RENDER)
|
|
|
|
minor_str = "renderD%d";
|
2008-01-03 23:49:40 -07:00
|
|
|
else
|
|
|
|
minor_str = "card%d";
|
|
|
|
|
2008-02-12 19:12:52 -07:00
|
|
|
snprintf(minor->kdev.bus_id, BUS_ID_SIZE, minor_str, minor->index);
|
2008-01-03 23:49:40 -07:00
|
|
|
|
2008-06-05 16:58:43 -06:00
|
|
|
/* Shouldn't register more than once */
|
|
|
|
BUG_ON(device_is_registered(&minor->kdev));
|
|
|
|
|
|
|
|
DRM_DEBUG("registering DRM device \"%s\"\n", minor->kdev.bus_id);
|
|
|
|
|
2008-01-03 23:49:40 -07:00
|
|
|
err = device_register(&minor->kdev);
|
2007-10-26 17:08:54 -06:00
|
|
|
if (err) {
|
|
|
|
DRM_ERROR("device add failed: %d\n", err);
|
2007-09-19 22:01:29 -06:00
|
|
|
goto err_out;
|
2004-09-22 23:40:05 -06:00
|
|
|
}
|
|
|
|
|
2008-04-08 13:42:23 -06:00
|
|
|
for (i = 0; i < ARRAY_SIZE(dri_attrs); i++) {
|
|
|
|
err = device_create_file(&minor->kdev, &dri_attrs[i]);
|
2007-09-19 22:01:29 -06:00
|
|
|
if (err)
|
|
|
|
goto err_out_files;
|
2007-07-02 15:52:07 -06:00
|
|
|
}
|
2005-07-03 11:16:12 -06:00
|
|
|
|
2007-10-26 17:08:54 -06:00
|
|
|
return 0;
|
2007-07-02 15:52:07 -06:00
|
|
|
|
2007-09-19 22:01:29 -06:00
|
|
|
err_out_files:
|
|
|
|
if (i > 0)
|
|
|
|
for (j = 0; j < i; j++)
|
2008-09-25 23:37:21 -06:00
|
|
|
device_remove_file(&minor->kdev, &dri_attrs[j]);
|
2008-01-03 23:49:40 -07:00
|
|
|
device_unregister(&minor->kdev);
|
2007-09-19 22:01:29 -06:00
|
|
|
err_out:
|
2007-10-26 17:08:54 -06:00
|
|
|
|
|
|
|
return err;
|
2004-09-22 23:40:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-10-26 17:08:54 -06:00
|
|
|
* drm_sysfs_device_remove - remove DRM device
|
|
|
|
* @dev: DRM device to remove
|
2004-09-22 23:40:05 -06:00
|
|
|
*
|
|
|
|
* This call unregisters and cleans up a class device that was created with a
|
2004-09-27 13:51:38 -06:00
|
|
|
* call to drm_sysfs_device_add()
|
2004-09-22 23:40:05 -06:00
|
|
|
*/
|
2008-01-03 23:49:40 -07:00
|
|
|
void drm_sysfs_device_remove(struct drm_minor *minor)
|
2004-09-22 23:40:05 -06:00
|
|
|
{
|
2005-07-03 12:07:03 -06:00
|
|
|
int i;
|
2005-07-03 11:16:12 -06:00
|
|
|
|
2008-04-08 13:42:23 -06:00
|
|
|
for (i = 0; i < ARRAY_SIZE(dri_attrs); i++)
|
|
|
|
device_remove_file(&minor->kdev, &dri_attrs[i]);
|
2008-01-03 23:49:40 -07:00
|
|
|
device_unregister(&minor->kdev);
|
2004-09-22 23:40:05 -06:00
|
|
|
}
|