Devicetree output

The following section present the content of a C coded version of the devicetree

Devices instances definition

A hardware peripheral is visible from the SDK as a pi_device_t object. Such object has three pointers :

  • a configuration structure pointer

  • a data structure pointer

  • an api structure pointer

Based on the devicetree source file content, outputed C files must provide :

  • a definition of the configuration structure

  • a declaration of the data structure (it will be fullfilled by the device itself at run time)

  • a definition of the device itself with adequate pointers including the device api which is defined inside the device driver.

Note

All of this structures has a name convention.

Device name convention : DEVICENAME_dev
Data type and name convention : pi_DEVICENAME_data_t pi_DEVICENAME_data
Configuration type and name convention : pi_DEVICENAME_conf_t pi_DEVICENAME_conf
Api name convention : DEVICENAME_api
Naming convention

Type

Name convention

Device name

DEVICENAME_dev

Data type

pi_DEVICENAME_data_t

Data name

pi_DEVICENAME_data

Config type

pi_DEVICENAME_conf_t

Config name

pi_DEVICENAME_conf

Api name

DEVICENAME_api

Note

There is no convention about a device’s api type because it is cast into the generic api type pi_device_api_t

Here is an example of how a device is outputed.

sys
{
    device_name  = "mx25u51245g";
    device_type  = "flash";
    device_board = "gap9mod_v1_0_b";
    device_driver = "bsp/flash/mx25u51245g.h";
};
conf
{
    spi_itf      = <0>;
    spi_cs       = <0>;
    size         = <0x00800000>;
    sector_size  = <4096>;
    xip_en       = <0>;
    baudrate     = <0>;
};

Device API

For each outputed device, an enum is added to the pi_device_enum type. This enum type represent all devices a user can open and close in his application. If an application require only a flash device, the enum list will have only one member.

Here is an example about an application thta only use a mx25u51245g flash device

typedef enum {
    PI_FLASH_MX25U51245G,
    PI_FLASH_DEFAULT,
}pi_device_e;

Note

Here, a PI_FLASH_DEFAULT is also defined in the list thanks to the default driver mechanism. Please check Default driver section in Interaction with Kconfig page for more explanations. This is for applications that support multiple devices from a same type and use an abstracted API.

Devices outputed from the devicetree can be opened with the following function:

pi_err_t pi_open(pi_device_e device_enum, pi_device_t** device_ptr)
This function takes as an input a enum value representing a device from the devicetree and a pointer in which the matching device’s pointer will be returned.
If the enum is valid, the device’s open function is called and its pointer is returned.
Otherwise, the function returns an error as well as if the device’s open function fails.

Devices are closed with the following API using the same enum list:

pi_err_t pi_close(pi_device_e device_enum);

Automatic pad configuration

The devicetree aims to facilitate the pad configuration by automate the configuration of pads registers.

A pad is detected in device nodes if it has the following syntax :

GAP9_PADMUX(<pad_id>, <pad_af>, <pad_muxgroup>)

For each identified pad, a define will be outputed. The define’s value is obtained from the pi_pad_e enum list.

Here is an example with the mx25u51245g device, connected on the GAP9 Hyperbus0 interface :

pads
{
    ckn  = "GAP9_PADMUX(0, 0,-1)";
    ck   = "GAP9_PADMUX(1, 0,-1)";
    dq0  = "GAP9_PADMUX(2, 0,-1)";
    dq1  = "GAP9_PADMUX(3, 0,-1)";
    dq2  = "GAP9_PADMUX(4, 0,-1)";
    dq3  = "GAP9_PADMUX(5, 0,-1)";
    dq4  = "GAP9_PADMUX(6, 0,-1)";
    dq5  = "GAP9_PADMUX(7, 0,-1)";
    dq6  = "GAP9_PADMUX(8, 0,-1)";
    dq7  = "GAP9_PADMUX(9, 0,-1)";
    sn0  = "GAP9_PADMUX(10,0,-1)";
    csn1 = "GAP9_PADMUX(11,0,-1)";
    rwds = "GAP9_PADMUX(12,0,-1)";
};