0418 of LINUX device driver development

At present, most Android manufacturers use the method of kernel+ramdisk.img+dt.img to package it into boot.img.


The basic syntax DTS file of Device Tree is


mainly composed of: root-node, child-node, property, and include.
root-node: Represented by '/', Entry Point of DT, all devices are under the root node in the form of child nodes.


child-node: The form of node is node-name{}; {} is the actual content of the node, the root node is generally the Platform device
bus , and the peripherals exist in the form of child nodes in the nodes of the bus class. In the following example, the cpus node is located under the root node, representing
all CPUs, and cpu0~x are under cpus in the form of child nodes, representing all the CPUs on the SoC.


property: The property, in the form of key-value, located in the node.


include file: It is used to include other source files into dts. Generally, there are multiple Machine common files in dtsi (i stands for include)
, and h files are generally used for macro definitions in dts.




(1) reg property


(2) chosen node


(3) aliases node


(4) memory node
memory@0{
device_type="memory";
reg=<0x00000000 0x20000000>;
};
(5) compatible node
i2c6@50{
compatible = "samsung,xxxx-i2c";
reg=<0x50 0x4000>;
interrupts=<1 0 4 28>;
};


(6) Selection of Property


MSM Device


Tree There are two very important Qualcomm platform DTS id, one is the msm-id configuration chipset id, the id is
read from the hardware register by the XBL after booting.


The other is board-id, which is used to represent platform and subtype.
platform_id:
◆ bits 31-24 = Platform Subtype ID    
◆ bits 23-16 = Platform Version (Major)    
◆ bits 15-8 = Platform Version (Minor)    
◆ 7-0 = Platform Type ID [0x1] //0x1 -> CDP 0x8 -> MTP




subtype_id:
◆ bits 31-13 = Reserved Bits
◆ bits 12-11 = bits Panel Detection. 
00 - limit to HD, 01 - limit to 720p
10 - limit to qHD
11 - limit to FWVGA 
◆ bits 10-8 = DDR Size. default value as 0x0 
◆ bits 7-0 = Platform Subtype


finds the DT file of the board:
1. LK will first initialize the chipset of the current motherboard obtained from XBL id, platform id, pmic, etc.
2. There are corresponding functions in LK to translate each DTB information, such as 8996 platform:
platform_id(chipset)=246 variant_id(platform)=1
subtype=0 soc_rev=0x30001
pmic0=0x20009 pmic1=2000a


3. Then compare with the above parameters in the DTB information to find the most suitable DTS configuration;


4. After obtaining the most matching DTS, LK will output the log:
[5880]Best match DTB tags 246/00000001/ 00000000/30001/20009/2000a/0/0
msm8996.dtsi. The basic DTS file, in which the basic peripherals of the chip are defined
msm8996-v3.dtsi. The extension to msm8996.dtsi, Version3 version
msm8996-coresight-v3. dtsi. SOC information of V3 version


5. Finally, the address of the device tree in memory needs to be passed to the kernel


How to configure CDP/MTP


Qualcomm recommends that the modification method is to modify the XML file and then use the script to generate boot_cdt_array.c and the bin file. The
bin file can be directly burned into the cdt partition.


XML file path: boot_images/QcomPkg/Tools/cdp_1.0_jedec_lpddr4.xml
Use Qualcomm script to generate .c files and .bin files: cdt_generator.py


Note that if you modify the .c file to compile XBL and find that the modification is unsuccessful, it may be cdt The partition has been burned with .bin file, you
need to use fastboot to erase the cdt partition, and then turn it on again to confirm.


The CDT parameter in XBL outputs log, and the platform id and subtype are determined according to the information here.


DT use
Use DT to add a single board driver:
1. Add device node information from the general DTSI file of the chip
sound-9335{
    compatible = "qcom,msm8996-asoc-snd-tasha";
    qcom,model = "msm8996-tasha- snd-card";


}
2. Add driver information to \drive\XXX


3. XXX_probe function that debugs and registers after the kernel is started


4. The XXX_probe function can call the OF API interface in linux to obtain file node information.
Commonly used interface:
If from=NULL, find the appropriate device_node according to the name in the global linked list of_allnodes.
struct device_node *of_find_node_by_name(struct device_node *from, const char *name)
For example:
struct device_node *np;
np = of_find_node_by_name(NULL,"firmware");


Find the matching device_node in the global linked list of_allnodes according to the device type.
struct device_node *of_find_node_by_type (struct device_node *from, const char *type)
For example:
struct device_node *tsi_pci;
tsi_pci=of_find_node_by_type(NULL,"pci");


Extract the gpio port from the device tree, success: get the GPIO port number; failure: negative number, absolute value is the error code.
static inline int of_get_named_gpio(struct device_node *np, const char *propname, int index); The


driver is compiled to the location of kernel
1 and the driver code. drivers/char/xxx.c
2. Modify the Kconfig file
3. Modify the Makefile.
4. Modify the previous Makefile and Kconfig.
5. Use make menuconfig, or modify the board config file to compile the new kernel.


Module production and debugging
Module production
Put the xxx.c file into the drivers/char subdirectory, modify
drivers/char/Makefile
obj-m += xxx.o
Then, make modules, the generated modules are all debugged
in drivers/char/xxx.ko Create a device file in the root file system: #mknod/dev/XXX c 232 0 load module # insmod YYY unload module #rmmod YYY driver code design 1. Define and register the device (device) that implements the device structure corresponding to the hardware body. There are two ways, inherit the existing equipment and create a new equipment . If an existing device is used, it is generally necessary to define a private data structure. Registered devices, that is, new devices, are added to the device list of the system. 2. Define and register the device driver Implement the driver corresponding to the device and add it to the system driver list. 3. Implement device-driven file_operations, such as probe, open and other functions. Qualcomm 845 PMIC: How to provide clock to provide clock?



























The difference with the clock tree?
Peripheral IO port
Power management function,


LDO linear step-down
switching power supply High efficiency








































Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326050769&siteId=291194637