xref: /dragonfly/sys/dev/drm/drm_sysfs.c (revision 3f2dd94a)
1c2ee31feSFrançois Tigeot /*
23a2096e8SFrançois Tigeot  * Copyright 2015-2018 François Tigeot <ftigeot@wolfpond.org>
3c2ee31feSFrançois Tigeot  * All Rights Reserved.
4c2ee31feSFrançois Tigeot  *
5c2ee31feSFrançois Tigeot  * Permission is hereby granted, free of charge, to any person obtaining a
6c2ee31feSFrançois Tigeot  * copy of this software and associated documentation files (the "Software"),
7c2ee31feSFrançois Tigeot  * to deal in the Software without restriction, including without limitation
8c2ee31feSFrançois Tigeot  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9c2ee31feSFrançois Tigeot  * and/or sell copies of the Software, and to permit persons to whom the
10c2ee31feSFrançois Tigeot  * Software is furnished to do so, subject to the following conditions:
11c2ee31feSFrançois Tigeot  *
12c2ee31feSFrançois Tigeot  * The above copyright notice and this permission notice (including the next
13c2ee31feSFrançois Tigeot  * paragraph) shall be included in all copies or substantial portions of the
14c2ee31feSFrançois Tigeot  * Software.
15c2ee31feSFrançois Tigeot  *
16c2ee31feSFrançois Tigeot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17c2ee31feSFrançois Tigeot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18c2ee31feSFrançois Tigeot  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19c2ee31feSFrançois Tigeot  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20c2ee31feSFrançois Tigeot  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21c2ee31feSFrançois Tigeot  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22c2ee31feSFrançois Tigeot  * IN THE SOFTWARE.
23c2ee31feSFrançois Tigeot  */
24c2ee31feSFrançois Tigeot 
253a2096e8SFrançois Tigeot #include <linux/device.h>
263a2096e8SFrançois Tigeot 
273a2096e8SFrançois Tigeot #include <drm/drm_sysfs.h>
28c2ee31feSFrançois Tigeot #include <drm/drmP.h>
292c9916cdSFrançois Tigeot #include "drm_internal.h"
30c2ee31feSFrançois Tigeot 
drm_sysfs_connector_add(struct drm_connector * connector)31c2ee31feSFrançois Tigeot int drm_sysfs_connector_add(struct drm_connector *connector)
32c2ee31feSFrançois Tigeot {
33d31c517dSFrançois Tigeot 	struct drm_device *dev = connector->dev;
34d31c517dSFrançois Tigeot 
35d31c517dSFrançois Tigeot 	if (connector->kdev)
36d31c517dSFrançois Tigeot 		return 0;
37d31c517dSFrançois Tigeot 
38d31c517dSFrançois Tigeot 	/* Linux uses device_create_with_groups() here */
39d31c517dSFrançois Tigeot 	connector->kdev = kzalloc(sizeof(struct device), M_WAITOK);
40d31c517dSFrançois Tigeot 	connector->kdev->kobj.name = kasprintf(GFP_KERNEL, "card%d-%s",
41d31c517dSFrançois Tigeot 					       dev->primary->index,
42d31c517dSFrançois Tigeot 					       connector->name);
43d31c517dSFrançois Tigeot 	DRM_DEBUG("adding \"%s\" to sysfs\n", connector->name);
44d31c517dSFrançois Tigeot 
45c2ee31feSFrançois Tigeot 	return 0;
46c2ee31feSFrançois Tigeot }
47c2ee31feSFrançois Tigeot 
drm_sysfs_connector_remove(struct drm_connector * connector)48c2ee31feSFrançois Tigeot void drm_sysfs_connector_remove(struct drm_connector *connector)
49c2ee31feSFrançois Tigeot {
50d31c517dSFrançois Tigeot 	DRM_DEBUG("removing \"%s\" from sysfs\n", connector->name);
51d31c517dSFrançois Tigeot 
52d31c517dSFrançois Tigeot 	if (connector->kdev)
53d31c517dSFrançois Tigeot 		kfree(connector->kdev);
54c2ee31feSFrançois Tigeot }
55ba55f2f5SFrançois Tigeot 
drm_sysfs_hotplug_event(struct drm_device * dev)56ba55f2f5SFrançois Tigeot void drm_sysfs_hotplug_event(struct drm_device *dev)
57ba55f2f5SFrançois Tigeot {
58ba55f2f5SFrançois Tigeot }
593a2096e8SFrançois Tigeot 
drm_class_device_register(struct device * dev)603a2096e8SFrançois Tigeot int drm_class_device_register(struct device *dev)
613a2096e8SFrançois Tigeot {
623a2096e8SFrançois Tigeot 	return 0;
633a2096e8SFrançois Tigeot }
643a2096e8SFrançois Tigeot 
65a85cb24fSFrançois Tigeot /**
66a85cb24fSFrançois Tigeot  * drm_class_device_unregister - unregister device with the DRM sysfs class
67a85cb24fSFrançois Tigeot  * @dev: device to unregister
68a85cb24fSFrançois Tigeot  *
69a85cb24fSFrançois Tigeot  * Unregisters a &struct device from the DRM sysfs class. Essentially only used
70a85cb24fSFrançois Tigeot  * by ttm to have a place for its global settings. Drivers should never use
71a85cb24fSFrançois Tigeot  * this.
72a85cb24fSFrançois Tigeot  */
drm_class_device_unregister(struct device * dev)733a2096e8SFrançois Tigeot void drm_class_device_unregister(struct device *dev)
743a2096e8SFrançois Tigeot {
753a2096e8SFrançois Tigeot }
76*3f2dd94aSFrançois Tigeot 
77*3f2dd94aSFrançois Tigeot extern struct dev_ops drm_cdevsw;
78*3f2dd94aSFrançois Tigeot 
drm_sysfs_minor_alloc(struct drm_minor * minor)79*3f2dd94aSFrançois Tigeot struct device *drm_sysfs_minor_alloc(struct drm_minor *minor)
80*3f2dd94aSFrançois Tigeot {
81*3f2dd94aSFrançois Tigeot 	const char dev_str[12];
82*3f2dd94aSFrançois Tigeot 	struct device *kdev;
83*3f2dd94aSFrançois Tigeot 	int r;
84*3f2dd94aSFrançois Tigeot 	struct cdev *devnode;
85*3f2dd94aSFrançois Tigeot 
86*3f2dd94aSFrançois Tigeot 	if (minor->type == DRM_MINOR_PRIMARY)
87*3f2dd94aSFrançois Tigeot 		ksnprintf(dev_str, sizeof(dev_str), "card%d", minor->index);
88*3f2dd94aSFrançois Tigeot 	else if (minor->type == DRM_MINOR_RENDER)
89*3f2dd94aSFrançois Tigeot 		ksnprintf(dev_str, sizeof(dev_str), "renderD%d", minor->index);
90*3f2dd94aSFrançois Tigeot 	else
91*3f2dd94aSFrançois Tigeot 		return NULL;
92*3f2dd94aSFrançois Tigeot 
93*3f2dd94aSFrançois Tigeot 	kdev = kzalloc(sizeof(*kdev), GFP_KERNEL);
94*3f2dd94aSFrançois Tigeot 	if (!kdev)
95*3f2dd94aSFrançois Tigeot 		return ERR_PTR(-ENOMEM);
96*3f2dd94aSFrançois Tigeot 
97*3f2dd94aSFrançois Tigeot 	devnode = make_dev(&drm_cdevsw, minor->index,
98*3f2dd94aSFrançois Tigeot 		DRM_DEV_UID, DRM_DEV_GID, DRM_DEV_MODE, "dri/%s", dev_str);
99*3f2dd94aSFrançois Tigeot 
100*3f2dd94aSFrançois Tigeot 	kdev->parent = minor->dev->dev;
101*3f2dd94aSFrançois Tigeot 	dev_set_drvdata(kdev, minor);
102*3f2dd94aSFrançois Tigeot 
103*3f2dd94aSFrançois Tigeot 	r = dev_set_name(kdev, dev_str);
104*3f2dd94aSFrançois Tigeot 	if (r < 0)
105*3f2dd94aSFrançois Tigeot 		goto err_free;
106*3f2dd94aSFrançois Tigeot 
107*3f2dd94aSFrançois Tigeot 	return kdev;
108*3f2dd94aSFrançois Tigeot 
109*3f2dd94aSFrançois Tigeot err_free:
110*3f2dd94aSFrançois Tigeot 	return ERR_PTR(r);
111*3f2dd94aSFrançois Tigeot }
112*3f2dd94aSFrançois Tigeot 
113