2222#include <drm/drm_core.h>
2323#include <drm/drmP.h>
2424
25- #define to_drm_minor (d ) container_of(d, struct drm_minor, kdev )
26- #define to_drm_connector (d ) container_of(d, struct drm_connector, kdev )
25+ #define to_drm_minor (d ) dev_get_drvdata(d )
26+ #define to_drm_connector (d ) dev_get_drvdata(d )
2727
2828static struct device_type drm_sysfs_device_minor = {
2929 .name = "drm_minor"
@@ -162,20 +162,6 @@ void drm_sysfs_destroy(void)
162162 drm_class = NULL ;
163163}
164164
165- /**
166- * drm_sysfs_device_release - do nothing
167- * @dev: Linux device
168- *
169- * Normally, this would free the DRM device associated with @dev, along
170- * with cleaning up any other stuff. But we do that in the DRM core, so
171- * this function can just return and hope that the core does its job.
172- */
173- static void drm_sysfs_device_release (struct device * dev )
174- {
175- memset (dev , 0 , sizeof (struct device ));
176- return ;
177- }
178-
179165/*
180166 * Connector properties
181167 */
@@ -394,29 +380,26 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
394380 int i ;
395381 int ret ;
396382
397- /* We shouldn't get called more than once for the same connector */
398- BUG_ON (device_is_registered (& connector -> kdev ));
399-
400- connector -> kdev .parent = & dev -> primary -> kdev ;
401- connector -> kdev .class = drm_class ;
402- connector -> kdev .release = drm_sysfs_device_release ;
383+ if (connector -> kdev )
384+ return 0 ;
403385
386+ /* We shouldn't get called more than once for the same connector */
387+ connector -> kdev = device_create (drm_class , dev -> primary -> kdev ,
388+ 0 , connector , "card%d-%s" ,
389+ dev -> primary -> index , drm_get_connector_name (connector ));
404390 DRM_DEBUG ("adding \"%s\" to sysfs\n" ,
405391 drm_get_connector_name (connector ));
406392
407- dev_set_name (& connector -> kdev , "card%d-%s" ,
408- dev -> primary -> index , drm_get_connector_name (connector ));
409- ret = device_register (& connector -> kdev );
410-
411- if (ret ) {
412- DRM_ERROR ("failed to register connector device: %d\n" , ret );
393+ if (IS_ERR (connector -> kdev )) {
394+ DRM_ERROR ("failed to register connector device: %ld\n" , PTR_ERR (connector -> kdev ));
395+ ret = PTR_ERR (connector -> kdev );
413396 goto out ;
414397 }
415398
416399 /* Standard attributes */
417400
418401 for (attr_cnt = 0 ; attr_cnt < ARRAY_SIZE (connector_attrs ); attr_cnt ++ ) {
419- ret = device_create_file (& connector -> kdev , & connector_attrs [attr_cnt ]);
402+ ret = device_create_file (connector -> kdev , & connector_attrs [attr_cnt ]);
420403 if (ret )
421404 goto err_out_files ;
422405 }
@@ -433,7 +416,7 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
433416 case DRM_MODE_CONNECTOR_Component :
434417 case DRM_MODE_CONNECTOR_TV :
435418 for (opt_cnt = 0 ; opt_cnt < ARRAY_SIZE (connector_attrs_opt1 ); opt_cnt ++ ) {
436- ret = device_create_file (& connector -> kdev , & connector_attrs_opt1 [opt_cnt ]);
419+ ret = device_create_file (connector -> kdev , & connector_attrs_opt1 [opt_cnt ]);
437420 if (ret )
438421 goto err_out_files ;
439422 }
@@ -442,7 +425,7 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
442425 break ;
443426 }
444427
445- ret = sysfs_create_bin_file (& connector -> kdev . kobj , & edid_attr );
428+ ret = sysfs_create_bin_file (& connector -> kdev -> kobj , & edid_attr );
446429 if (ret )
447430 goto err_out_files ;
448431
@@ -453,10 +436,11 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
453436
454437err_out_files :
455438 for (i = 0 ; i < opt_cnt ; i ++ )
456- device_remove_file (& connector -> kdev , & connector_attrs_opt1 [i ]);
439+ device_remove_file (connector -> kdev , & connector_attrs_opt1 [i ]);
457440 for (i = 0 ; i < attr_cnt ; i ++ )
458- device_remove_file (& connector -> kdev , & connector_attrs [i ]);
459- device_unregister (& connector -> kdev );
441+ device_remove_file (connector -> kdev , & connector_attrs [i ]);
442+ put_device (connector -> kdev );
443+ device_unregister (connector -> kdev );
460444
461445out :
462446 return ret ;
@@ -480,16 +464,17 @@ void drm_sysfs_connector_remove(struct drm_connector *connector)
480464{
481465 int i ;
482466
483- if (!connector -> kdev . parent )
467+ if (!connector -> kdev )
484468 return ;
485469 DRM_DEBUG ("removing \"%s\" from sysfs\n" ,
486470 drm_get_connector_name (connector ));
487471
488472 for (i = 0 ; i < ARRAY_SIZE (connector_attrs ); i ++ )
489- device_remove_file (& connector -> kdev , & connector_attrs [i ]);
490- sysfs_remove_bin_file (& connector -> kdev .kobj , & edid_attr );
491- device_unregister (& connector -> kdev );
492- connector -> kdev .parent = NULL ;
473+ device_remove_file (connector -> kdev , & connector_attrs [i ]);
474+ sysfs_remove_bin_file (& connector -> kdev -> kobj , & edid_attr );
475+ put_device (connector -> kdev );
476+ device_unregister (connector -> kdev );
477+ connector -> kdev = NULL ;
493478}
494479EXPORT_SYMBOL (drm_sysfs_connector_remove );
495480
@@ -508,7 +493,7 @@ void drm_sysfs_hotplug_event(struct drm_device *dev)
508493
509494 DRM_DEBUG ("generating hotplug event\n" );
510495
511- kobject_uevent_env (& dev -> primary -> kdev . kobj , KOBJ_CHANGE , envp );
496+ kobject_uevent_env (& dev -> primary -> kdev -> kobj , KOBJ_CHANGE , envp );
512497}
513498EXPORT_SYMBOL (drm_sysfs_hotplug_event );
514499
@@ -523,34 +508,23 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
523508 */
524509int drm_sysfs_device_add (struct drm_minor * minor )
525510{
526- int err ;
527511 char * minor_str ;
528512
529- minor -> kdev .parent = minor -> dev -> dev ;
530-
531- minor -> kdev .class = drm_class ;
532- minor -> kdev .release = drm_sysfs_device_release ;
533- minor -> kdev .devt = minor -> device ;
534- minor -> kdev .type = & drm_sysfs_device_minor ;
535513 if (minor -> type == DRM_MINOR_CONTROL )
536514 minor_str = "controlD%d" ;
537515 else if (minor -> type == DRM_MINOR_RENDER )
538516 minor_str = "renderD%d" ;
539517 else
540518 minor_str = "card%d" ;
541519
542- dev_set_name ( & minor -> kdev , minor_str , minor -> index );
543-
544- err = device_register ( & minor -> kdev );
545- if (err ) {
546- DRM_ERROR ("device add failed: %d \n" , err );
547- goto err_out ;
520+ minor -> kdev = device_create ( drm_class , minor -> dev -> dev ,
521+ MKDEV ( DRM_MAJOR , minor -> index ),
522+ minor , minor_str , minor -> index );
523+ if (IS_ERR ( minor -> kdev ) ) {
524+ DRM_ERROR ("device create failed %ld \n" , PTR_ERR ( minor -> kdev ) );
525+ return PTR_ERR ( minor -> kdev ) ;
548526 }
549-
550527 return 0 ;
551-
552- err_out :
553- return err ;
554528}
555529
556530/**
@@ -562,9 +536,9 @@ int drm_sysfs_device_add(struct drm_minor *minor)
562536 */
563537void drm_sysfs_device_remove (struct drm_minor * minor )
564538{
565- if (minor -> kdev . parent )
566- device_unregister ( & minor -> kdev );
567- minor -> kdev . parent = NULL ;
539+ if (minor -> kdev )
540+ device_destroy ( drm_class , MKDEV ( DRM_MAJOR , minor -> index ) );
541+ minor -> kdev = NULL ;
568542}
569543
570544
0 commit comments