The 0418__linux of LINUX device-driven development

Source: Internet
Author: User
At present, most Android manufacturers use kernel+ramdisk.img+dt.img to pack into boot.img.


The basic grammar of Device tree


DTS files are mainly composed of: Root-node, Child-node, property, include.
Root-node: Represented by '/', DT's entry point, all devices are in the form of child nodes under the root node.


Child-node:node in the form of node-name{};{} is the actual content of the node, under the root node is generally platform devices
Bus, peripheral as a child node in the form of the bus class node. As in the following example, CPUs this node is located under the root node and represents the
All cpu,cpu0~x are in the form of CPUs, representing all CPUs on the Soc.


Property: attribute, expressed as Key-value, located in a node.


Include file: Used to contain other source files into DTS, DTSi Common Files for multiple machine in general (I representative include)
, h files are generally defined with macro in DTS.




(i) Reg property


(ii) chosen node


(iii) Aliases node


(iv) Memory node
memory@0{
Device_type= "Memory";
reg=<0x00000000 0x20000000>;
};
(v) Compatible node
i2c6@50{
compatible = "SAMSUNG,XXXX-I2C";
reg=<0x50 0x4000>;
Interrupts=<1 0 4 28>;
};


(vi) Property


Selection of MSM Device tree


High-throughput platform DTS has two very important IDs, one is the Msm-id configuration chipset ID, the ID is after the boot
The XBL is read by the hardware register.


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)
Bits 7-0 = Platform Type ID [0x1]//0x1-> CDP 0x8->




SUBTYPE_ID:
Bits 31-13 = Reserved bits
Bits 12-11 = 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


Looking for a single board DT file:
1, LK in the first will be initialized in the XBL to get the current motherboard chipset ID, platform ID, pmic and so on to organize
2, in LK has the corresponding function to translate each DTB information, like 8996 platform:
PLATFORM_ID (chipset) =246 variant_id (platform) =1
Subtype=0 soc_rev=0x30001
pmic0=0x20009 pmic1=2000a


3, then compares with the above parameter in the DTB information, looks for the most suitable DTS configuration;


4, get to the most matching DTS, LK will output log:
[5880] Best match DTB Tags 246/00000001/00000000/30001/20009/2000a/0/0
Msm8996.dtsi. Basic DTS files, the underlying peripherals of the chip are defined in them
Msm8996-v3.dtsi. Extensions to Msm8996.dtsi, Version3 version
Msm8996-coresight-v3.dtsi. V3 version of the SOC information


5, finally need to pass the device tree in memory address to the kernel


How to configure CDP/MTP


Qualcomm recommends that the modification be done by modifying the XML file and then using the script to generate the boot_cdt_array.c and bin files.
The bin file can be burned directly into the CDT partition.


XML file path: Boot_images/qcompkg/tools/cdp_1.0_jedec_lpddr4.xml
Generate. c files and. bin files with a high-pass script: cdt_generator.py


Note If you modify the. c file to compile XBL burn and find that the modification is unsuccessful, the CDT partition may have been burned. bin file,
After the CDT partition needs to be wiped with FastBoot, reboot the confirmation again.


XBL the CDT parameter output log, based on the information here to determine the platform ID and subtype.


DT using
Using DT, add a single board drive:
1, add the device node information from the total DTSi file of the chip
sound-9335{
compatible = "Qcom,msm8996-asoc-snd-tasha";
Qcom,model = "Msm8996-tasha-snd-card";


}
2, add the driving information in the \DRIVE\XXX


3, after the kernel starts to debug registers the Xxx_probe function


4, the Xxx_probe function can call Linux of the API interface to get file node information.
Common interfaces:
If from=null, find the appropriate device_node based on 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");


Finds matching Device_node in global list of_allnodes based on 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");


Extraction of Gpio from the device tree, success: get GPIO number; failure: negative, absolute value is error code.
static inline int Of_get_named_gpio (struct device_node *np, const char *propname, int index);


Driver compile to Kernel
1, the location of the driver code. Drivers/char/xxx.c
2. Modify Kconfig File
3, modify makefile.
4, modify the previous level makefile and Kconfig.
5, use make menuconfig, or modify the Board config file, compile the new kernel.


Module Making and debugging
Module production
Put the xxx.c file into the Drivers/char subdirectory and modify
Drivers/char/makefile
Obj-m + + XXX.O
And then
Make modules, build modules are Drivers/char/xxx.ko
Debugging
To establish a device file in the root file system:
#mknod/dev/xxx C 232 0
Loading modules
# Insmod YYY
Uninstall module
#rmmod YYY


Driver Code Design


1, the definition and registration of equipment (device)
The device (device) structure that implements the hardware. There are two ways to inherit an existing device and create a new
Equipment. If you use an existing device, you generally need to define a private data structure.
Register the device, the new device, into the system's device list.


2. Define and register device driver
Implement the device (device) corresponding to the drive (driver) and join the system in the driver list.


3, the implementation of device-driven file_operations, such as probe, open and other functions.


Qualcomm 845
Pmic: How to provide the clock to clock?
And the clock tree difference.
Peripheral IO Port
Power management functions,


LDO Linear Buck
High efficiency of switching power supply








































Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.