laitimes

Linux DRM those things - master device bind

author:Oda BSP

This article describes the RockPI 4A single-board DRM module master device bind function rockchip_drm_bind().

File: drivers/gpu/drm/rockchip/rockchip_drm_drv.c.

Function: Completes the initialization of the DRM master device and calls all slave device bind functions to initialize the entire display system.

The execution process is shown in the following figure:

Linux DRM those things - master device bind

1、drm_dev_alloc(&rockchip_drm_driver, dev)

Function: Assign and initialize a DRM device, followed by a call drm_dev_register() to complete device registration.

Focus on device driver implementation (rockchip_drm_driver), followed by libdrm introduction.

static struct drm_driver rockchip_drm_driver = {
    .driver_features    = DRIVER_MODESET | DRIVER_GEM |
                  DRIVER_PRIME | DRIVER_ATOMIC |
                  DRIVER_RENDER,
    .preclose       = rockchip_drm_preclose,
    .lastclose      = rockchip_drm_lastclose,
    .get_vblank_counter = drm_vblank_no_hw_counter,
    .open           = rockchip_drm_open,
    .postclose      = rockchip_drm_postclose,
    .enable_vblank      = rockchip_drm_crtc_enable_vblank,   
    .disable_vblank     = rockchip_drm_crtc_disable_vblank,  
    .gem_vm_ops     = &rockchip_drm_vm_ops,
    .gem_free_object    = rockchip_gem_free_object,
    .dumb_create        = rockchip_gem_dumb_create,          
    .dumb_map_offset    = rockchip_gem_dumb_map_offset,      
    .dumb_destroy       = drm_gem_dumb_destroy,
    .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
    .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
    .gem_prime_import   = drm_gem_prime_import,
    .gem_prime_export   = drm_gem_prime_export,
    .gem_prime_get_sg_table = rockchip_gem_prime_get_sg_table,
    .gem_prime_import_sg_table  = rockchip_gem_prime_import_sg_table,
    .gem_prime_vmap     = rockchip_gem_prime_vmap,
    .gem_prime_vunmap   = rockchip_gem_prime_vunmap,
    .gem_prime_mmap     = rockchip_gem_mmap_buf,
    .gem_prime_begin_cpu_access = rockchip_gem_prime_begin_cpu_access,
    .gem_prime_end_cpu_access = rockchip_gem_prime_end_cpu_access,
#ifdef CONFIG_DEBUG_FS
    .debugfs_init       = rockchip_drm_debugfs_init,
    .debugfs_cleanup    = rockchip_drm_debugfs_cleanup,
#endif
    .ioctls         = rockchip_ioctls,
    .num_ioctls     = ARRAY_SIZE(rockchip_ioctls),
    .fops           = &rockchip_drm_driver_fops,
    .name   = DRIVER_NAME,
    .desc   = DRIVER_DESC,
    .date   = DRIVER_DATE,
    .major  = DRIVER_MAJOR,
    .minor  = DRIVER_MINOR,
}           

The function at the beginning of the drm_ is a function implemented by the DRM framework, which can be used directly by various manufacturers without adaptation.

2、drm_dev_set_unique(drm_dev, "%s", dev_name(dev))

Function: Sets the unique name of the DRM device (dev->unique), i.e. display-subsystem.

3、devfreq_get_devfreq_by_phandle(dev, 0)

Function: Get devfreq.

4、devm_clk_get(dev, "hdmi-tmds-pll")

Function: Get the hdmi-tmds-pll clock.

5、devm_clk_get(dev, "default-vop-pll")

Function: Get the default-vop-pll clock.

6、fence_context_alloc(1)

Function: Assign 1 set of fence contexts.

7、rockchip_drm_init_iommu(drm_dev)

Function: InitializeSioMMU.

IOMMU (Input/Output Memory Management Unit): Translates a virtual address accessed by a device into a physical address.

MMU: Converts a virtual address accessed by the CPU into a physical address.

8、drm_mode_config_init(drm_dev)

Function: Initialize mode_config, create DRM framework standard properties.

9、rockchip_drm_mode_config_init(drm_dev)

Features: Set the width and height limits of the rockchip mode_config, register drm_mode_config_funcs.

static const struct drm_mode_config_funcs rockchip_drm_mode_config_funcs = {
    .fb_create = rockchip_user_fb_create, 
    .output_poll_changed = rockchip_drm_output_poll_changed,
    .atomic_check = drm_atomic_helper_check,
    .atomic_commit = rockchip_drm_atomic_commit,
};           

10、rockchip_drm_create_properties(drm_dev)

Function: Set the rockchip drm property.

11、component_bind_all(dev, drm_dev)

Function: Calls all slave device bind drivers.

12、rockchip_attach_connector_property(drm_dev)

Function: Assigns properties of the connector (brightness, contrast, saturation, and hue).

Brightness: Brightness

contrast: Contrast

Saturation: Saturation

hue: hue

13、drm_vblank_init(drm_dev, drm_dev->mode_config.num_crtc)

Function: Initialize vblank.

14、drm_mode_config_reset(drm_dev)

Features: Reset Plan, CRTC, Encoder, and Connector.

15、rockchip_drm_set_property_default(drm_dev)

Function: Sets the default properties of the Connector.

16、drm_kms_helper_poll_init(drm_dev)

Function: Enables KMS polling mechanism.

17、rockchip_gem_pool_init(drm_dev)

Function: Initialize the memory pool.

18、of_reserved_mem_device_init(drm_dev->dev)

Function: Assign memory reserved in dts configuration to devices.

19、rockchip_drm_fbdev_init(drm_dev)

Function: Initialize framebuffer.

20、drm_dev_register(drm_dev, 0)

Function: Register DRM devices.

Read on