Device Driver Porting in OpenHarmony

LCD Driver Porting

The primary task for porting an LCD driver involves creating a driver that instantiates a panel model and completes the registration process.

LCD drivers reside in the source directory //drivers/hdf_core/framework/model/display/driver/panel.

Creating a Panel Driver

Implement an HDF driver and invoke the RegisterPanel interface during driver initialization to register the model instance. The following example demonstrates the structure:

int32_t PanelDriverInit(struct HdfDeviceObject *device)
{
    struct PanelConfig *panelCfg = AllocatePanelResources();
    
    if (RegisterPanelInstance(panelCfg) != HDF_SUCCESS) {
        HDF_LOGE("%s: Panel registration failed", __func__);
        DeallocatePanelResources(panelCfg);
        return HDF_FAILURE;
    }
    
    return HDF_SUCCESS;
}

struct HdfDriverEntry g_lcdDriverRegistration = {
    .moduleVersion = 1,
    .moduleName = "LCD_SAMPLE_CONTROLLER",
    .Init = PanelDriverInit,
};

HDF_INIT(g_lcdDriverRegistration);

Configuring Panel Driver Loading

All device information to a product is defined in //vendor/vendor_name/product_name/config/device_info/device_info.hcs. Modify this file to add configuration under the display host, within the device_lcd device section:

root {
    display :: host {
        lcd_device :: device {
            displayNode :: deviceNode {
                policy = 0;
                priority = 100;
                preload = 2;
                moduleName = "LCD_SAMPLE_CONTROLLER";
            }
        }
    }
}

Note: The moduleName value must match the moduleName defined in the panel driver implementation.

Touch Panel Driver Porting

This section covers touchscreen driver porting. Touch device drivers are located in //drivers/hdf_core/framework/model/input/driver/touchscreen. The main task involves registering a ChipDevice model instance with the system.

Creating a Touch Device Driver

Create a new source file named touch_controller_name.c within the touchscreen directory. Implement the following registration pattern:

#include "hdf_touch.h"

static int32_t TouchControllerInitialize(struct HdfDeviceObject *device)
{
    TouchDevice *touchDevice = ConstructTouchDevice();
    
    if (RegisterTouchChip(touchDevice) != HDF_SUCCESS) {
        DestroyTouchDevice(touchDevice);
        return HDF_FAILURE;
    }
    
    return HDF_SUCCESS;
}

struct HdfDriverEntry g_touchChipDriverEntry = {
    .moduleVersion = 1,
    .moduleName = "HDF_TOUCH_SAMPLE_CONTROLLER",
    .Init = TouchControllerInitialize,
};

HDF_INIT(g_touchChipDriverEntry);

The ChipDevice structure must implement the required callback methods for touch event handling, power management, and device configuration.

Configuring Product for Touch Driver Loading

Modify the device information file at //vendor/vendor_name/product_name/config/device_info/device_info.hcs. Add configuration under the input host, within the device_touch_chip device section:

sampleNode :: deviceNode {
    policy = 0;
    priority = 130;
    preload = 0;
    permission = 0660;
    moduleName = "HDF_TOUCH_SAMPLE_CONTROLLER";
    deviceMatchAttr = "touch_sample_configs";
}

Important: The moduleName must exactly match the value defined in the touchscreen driver implementation.

WLAN Driver Porting

WLAN driver architecture comprises two distinct components: one responsible for WLAN device management and another handling WLAN data traffic.

WLAN Architecture Overview

The architecture separates WLAN management functions from data path operations. The HDF WLAN framework provides abstractions for both components, enabling modular driver implementation through distinct interface contracts.

Implementing HDF WLAN Chip Driver

Create a chip-specific driver file at /device/vendor_name/peripheral/wifi/chip_name/hdf_wlan_chip_name.c using the following template:

static int32_t WifiChipDriverInit(struct HdfDeviceObject *device)
{
    static struct HdfChipDriverFactory factory = CreateDriverFactoryInstance();
    struct HdfChipDriverManager *manager = RetrieveChipDriverManager();
    
    if (manager->RegisterDriver(&factory) != HDF_SUCCESS) {
        HDF_LOGE("%s: Factory registration failed", __func__);
        return HDF_FAILURE;
    }
    
    return HDF_SUCCESS;
}

static void WifiChipDriverRelease(struct HdfDeviceObject *device)
{
    // Cleanup resources
}

struct HdfDriverEntry g_wifiChipDriverEntry = {
    .moduleVersion = 1,
    .Init = WifiChipDriverInit,
    .Release = WifiChipDriverRelease,
    .moduleName = "HDF_WIFI_CHIP_SAMPLE"
};

HDF_INIT(g_wifiChipDriverEntry);

The CreateDriverFactoryInstance function constructs an HdfChipDriverFactory object that provides methods for chip-specific operations. The Build method creates an HdfChipDriver instance responsible for managign the network interface, which must implement lifecycle and data path management callbacks.

Creating Chip Configuration File

Define driver-supported chip configurations in a dedicated file under //vendor/vendor_name/product_name/config/wifi/wlan_chip_chip_name.hcs:

root {
    wlan_config {
        sample_chip :& chipList {
            sample_chip :: chipInstance {
                match_attr = "hdf_wlan_chips_sample_chip";
                driverName = "wlan_sample_driver";
                sdio {
                    vendorId = 0xABCD;
                    deviceId = [0x1234, 0x5678];
                }
            }
        }
    }
}

Note: Replace vendor_name, product_name, and chip_name with actual values. The vendorId and deviceId must correspond to the specific chip identification codes.

Configuring Driver Loading

Modify //vendor/vendor_name/product_name/config/device_info/device_info.hcs to add driver loading configuration under the network host, within the device_wlan_chips device section:

wlanNode :: deviceNode {
    policy = 0;
    preload = 2;
    moduleName = "HDF_WLAN_CHIPS";
    deviceMatchAttr = "hdf_wlan_chips_sample_chip";
    serviceName = "wlan_sample_driver";
}

Important: The moduleName must match the value defined in the HDF WLAN chip driver implementation.

Updating Kconfig to Driver Visibility

Add configuration menu entries in device/vendor_name/drivers/Kconfig to expose the WLAN module in kernel configuration:

config DRIVERS_HDF_WIFI_sample_chip
    bool "Enable Sample Chip Host driver"
    default n
    depends on DRIVERS_HDF_WLAN
    help
        Enable this to include Sample Chip Host driver support.

Replace sample_chip with the actual chip identifier.

Modifying Build Scripts

Append configuration to //device/vendor_name/drivers/lite.mk to integrate the driver into the build process:

ifeq ($(LOSCFG_DRIVERS_HDF_WIFI_sample_chip), y)
    LITEOS_BASELIB += -lhdf_wlan_chipdriver_sample_chip
    LIB_SUBDIRS    += ../peripheral/wifi/sample_chip
endif

Note: Replace sample_chip with the appropriate chip identifier in all configuration entries and build scripts.

Tags: OpenHarmony LCD Driver Touch Panel WLAN Driver HDF

Posted on Thu, 07 May 2026 08:35:56 +0000 by slapdashgrim