/* First, define some important variables related to the device (touch screen) in DTSi.
The purpose of defining these variables is to read the DTSi file corresponding to the project in different projects, to improve the compatibility of the code for Touch screen, and to make the kernel code clearer. */* First Look at what is written in the DTSi file.
*/* Ty-focaltech-ft6206.dtsi */&SOC {i2c@78b9000 {/* BLSP1 QUP5 */focaltech@38 {};
};
Gen-vkeys {compatible = "Qcom,gen-vkeys";
label = "Ft5x06_ts";
Qcom,disp-maxx = <480>;
Qcom,disp-maxy = <854>;
Qcom,panel-maxx = <480>;
Qcom,panel-maxy = <946>;
Qcom,key-codes = <158 172 139>;
Qcom,y-offset = <0>;
Qcom,key-menu-coords = <120 30>;
Qcom,key-home-coords = <240 30>;
Qcom,key-back-coords = <360 30>;
Qcom,key-search-coords = <0 0 0 0>;
};
};
For convenience purposes, get the contents of the DTSi file by using the Of_find_property () function.
In the DTSi file, the left side of the equals sign is for easy searching and the right is the true value.
Understanding the framework, here is a concrete look at the Of_find_property () function execution process.
Before reading the data in DTSi, we first set up an array: struct Vkeys_platform_data {const char *name;
int Disp_maxx;
int disp_maxy;
int Panel_maxx;
int panel_maxy;
int *keycodes;
int Num_keys;
int y_offset;int y_center;
int *x_center;
int v_width;
int v_height;
};
1. Read the string for example: Label = "Ft5x06_ts";
Char *name;
rc = of_property_read_string (NP, "label", &pdata->name);
if (RC) {dev_err (dev, "Failed to read label\n");
Return-einval;
} snprintf (Name, Max_buf_size, "virtualkeys.%s", pdata->name);
The name pointer points to Virtualkeys.ft5x06_ts.
The main use of this API is of_property_read_string ().
2. Read a single value for example: Qcom,y-offset = <0>;
rc = OF_PROPERTY_READ_U32 (NP, "Qcom,y-offset", &val);
if (!RC) Pdata->y_offset = val;
else if (rc! =-einval) {dev_err (dev, "Failed to read y position offset\n");
return RC; }//This is also very simple 3.
Read array: Prop = Of_find_property (NP, "Qcom,key-codes", NULL);
if (prop) {Pdata->num_keys = prop->length/sizeof (U32);
Pdata->keycodes = Devm_kzalloc (dev, sizeof (u32) * Pdata->num_keys, Gfp_kernel);
if (!pdata->keycodes) Return-enomem;
rc = Of_property_read_u32_array (NP, "Qcom,key-codes", Pdata->keycodes, Pdata->num_keys); IF (RC) {dev_err (dev, "Failed to read key codes\n");
Return-einval;
}} This step is mainly focused on rc = Of_property_read_u32_array (NP, "Qcom,key-codes", Pdata->keycodes, Pdata->num_keys);
At the end, the data is stored in the pointer pdata->keycodes, pdata->num_keys the number of data in the array.
---------------------------------------------------------------------------OK.