@@ -304,56 +304,54 @@ static const struct dev_pm_ops rockchip_drm_pm_ops = {
304304 rockchip_drm_sys_resume )
305305};
306306
307- static int compare_of ( struct device * dev , void * data )
308- {
309- struct device_node * np = data ;
307+ #define MAX_ROCKCHIP_SUB_DRIVERS 16
308+ static struct platform_driver * rockchip_sub_drivers [ MAX_ROCKCHIP_SUB_DRIVERS ];
309+ static int num_rockchip_sub_drivers ;
310310
311- return dev -> of_node == np ;
311+ static int compare_dev (struct device * dev , void * data )
312+ {
313+ return dev == (struct device * )data ;
312314}
313315
314- static void rockchip_add_endpoints (struct device * dev ,
315- struct component_match * * match ,
316- struct device_node * port )
316+ static struct component_match * rockchip_drm_match_add (struct device * dev )
317317{
318- struct device_node * ep , * remote ;
318+ struct component_match * match = NULL ;
319+ int i ;
319320
320- for_each_child_of_node (port , ep ) {
321- remote = of_graph_get_remote_port_parent (ep );
322- if (!remote || !of_device_is_available (remote )) {
323- of_node_put (remote );
324- continue ;
325- } else if (!of_device_is_available (remote -> parent )) {
326- dev_warn (dev , "parent device of %s is not available\n" ,
327- remote -> full_name );
328- of_node_put (remote );
329- continue ;
330- }
321+ for (i = 0 ; i < num_rockchip_sub_drivers ; i ++ ) {
322+ struct platform_driver * drv = rockchip_sub_drivers [i ];
323+ struct device * p = NULL , * d ;
324+
325+ do {
326+ d = bus_find_device (& platform_bus_type , p , & drv -> driver ,
327+ (void * )platform_bus_type .match );
328+ put_device (p );
329+ p = d ;
331330
332- drm_of_component_match_add (dev , match , compare_of , remote );
333- of_node_put (remote );
331+ if (!d )
332+ break ;
333+ component_match_add (dev , & match , compare_dev , d );
334+ } while (true);
334335 }
336+
337+ return match ?: ERR_PTR (- ENODEV );
335338}
336339
337340static const struct component_master_ops rockchip_drm_ops = {
338341 .bind = rockchip_drm_bind ,
339342 .unbind = rockchip_drm_unbind ,
340343};
341344
342- static int rockchip_drm_platform_probe (struct platform_device * pdev )
345+ static int rockchip_drm_platform_of_probe (struct device * dev )
343346{
344- struct device * dev = & pdev -> dev ;
345- struct component_match * match = NULL ;
346347 struct device_node * np = dev -> of_node ;
347348 struct device_node * port ;
349+ bool found = false;
348350 int i ;
349351
350352 if (!np )
351353 return - ENODEV ;
352- /*
353- * Bind the crtc ports first, so that
354- * drm_of_find_possible_crtcs called from encoder .bind callbacks
355- * works as expected.
356- */
354+
357355 for (i = 0 ;; i ++ ) {
358356 struct device_node * iommu ;
359357
@@ -377,9 +375,9 @@ static int rockchip_drm_platform_probe(struct platform_device *pdev)
377375 is_support_iommu = false;
378376 }
379377
378+ found = true;
379+
380380 of_node_put (iommu );
381- drm_of_component_match_add (dev , & match , compare_of ,
382- port -> parent );
383381 of_node_put (port );
384382 }
385383
@@ -388,27 +386,27 @@ static int rockchip_drm_platform_probe(struct platform_device *pdev)
388386 return - ENODEV ;
389387 }
390388
391- if (!match ) {
389+ if (!found ) {
392390 dev_err (dev , "No available vop found for display-subsystem.\n" );
393391 return - ENODEV ;
394392 }
395- /*
396- * For each bound crtc, bind the encoders attached to its
397- * remote endpoint.
398- */
399- for (i = 0 ;; i ++ ) {
400- port = of_parse_phandle (np , "ports" , i );
401- if (!port )
402- break ;
403393
404- if (!of_device_is_available (port -> parent )) {
405- of_node_put (port );
406- continue ;
407- }
394+ return 0 ;
395+ }
408396
409- rockchip_add_endpoints (dev , & match , port );
410- of_node_put (port );
411- }
397+ static int rockchip_drm_platform_probe (struct platform_device * pdev )
398+ {
399+ struct device * dev = & pdev -> dev ;
400+ struct component_match * match = NULL ;
401+ int ret ;
402+
403+ ret = rockchip_drm_platform_of_probe (dev );
404+ if (ret )
405+ return ret ;
406+
407+ match = rockchip_drm_match_add (dev );
408+ if (IS_ERR (match ))
409+ return PTR_ERR (match );
412410
413411 return component_master_add_with_match (dev , & rockchip_drm_ops , match );
414412}
@@ -436,7 +434,54 @@ static struct platform_driver rockchip_drm_platform_driver = {
436434 },
437435};
438436
439- module_platform_driver (rockchip_drm_platform_driver );
437+ #define ADD_ROCKCHIP_SUB_DRIVER (drv , cond ) { \
438+ if (IS_ENABLED(cond) && \
439+ !WARN_ON(num_rockchip_sub_drivers >= MAX_ROCKCHIP_SUB_DRIVERS)) \
440+ rockchip_sub_drivers[num_rockchip_sub_drivers++] = &drv; \
441+ }
442+
443+ static int __init rockchip_drm_init (void )
444+ {
445+ int ret ;
446+
447+ num_rockchip_sub_drivers = 0 ;
448+ ADD_ROCKCHIP_SUB_DRIVER (vop_platform_driver , CONFIG_DRM_ROCKCHIP );
449+ ADD_ROCKCHIP_SUB_DRIVER (rockchip_dp_driver ,
450+ CONFIG_ROCKCHIP_ANALOGIX_DP );
451+ ADD_ROCKCHIP_SUB_DRIVER (cdn_dp_driver , CONFIG_ROCKCHIP_CDN_DP );
452+ ADD_ROCKCHIP_SUB_DRIVER (dw_hdmi_rockchip_pltfm_driver ,
453+ CONFIG_ROCKCHIP_DW_HDMI );
454+ ADD_ROCKCHIP_SUB_DRIVER (dw_mipi_dsi_driver ,
455+ CONFIG_ROCKCHIP_DW_MIPI_DSI );
456+ ADD_ROCKCHIP_SUB_DRIVER (inno_hdmi_driver , CONFIG_ROCKCHIP_INNO_HDMI );
457+
458+ ret = platform_register_drivers (rockchip_sub_drivers ,
459+ num_rockchip_sub_drivers );
460+ if (ret )
461+ return ret ;
462+
463+ ret = platform_driver_register (& rockchip_drm_platform_driver );
464+ if (ret )
465+ goto err_unreg_drivers ;
466+
467+ return 0 ;
468+
469+ err_unreg_drivers :
470+ platform_unregister_drivers (rockchip_sub_drivers ,
471+ num_rockchip_sub_drivers );
472+ return ret ;
473+ }
474+
475+ static void __exit rockchip_drm_fini (void )
476+ {
477+ platform_driver_unregister (& rockchip_drm_platform_driver );
478+
479+ platform_unregister_drivers (rockchip_sub_drivers ,
480+ num_rockchip_sub_drivers );
481+ }
482+
483+ module_init (rockchip_drm_init );
484+ module_exit (rockchip_drm_fini );
440485
441486MODULE_AUTHOR ("Mark Yao <mark.yao@rock-chips.com>" );
442487MODULE_DESCRIPTION ("ROCKCHIP DRM Driver" );
0 commit comments