In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to initialize the linux driver according to the device tree file. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.
I. premise
The new version of ARM-based Linux will be based on Device Tree to replace the previous device driver. Learn more about the device tree (Device Tree) where Device Tree can access Bao's Bolg:ARM Linux 3.x
Here is just an example of adding a dtsi file in arch/arm/boot/dts and reading node information in dtsi in the driver, and writing node information to the sys file system. As for how to create, read and write sys files, please refer to: create files under linux sysfs
2. Example 1. Add dtsi file
The added dtsi file can be based on your phone or development board to determine where to put it. Dts total directory: arch/arm/boot/dts
In the example, the location of the dtsi is located at:
Xm-test.dtsi:
/ {xm-test {compatible = "xiaomi,xm-test"; xm_test_tip;};}
Where xm-test and "xiaomi,xm-test" must be unique.
Note: you need to add # include "xm-test.dtsi" to the audio.dtsi file, depending on which file you add include under.
2. Drive # include # define HW_TEST "xm_test_tip" # define i2c_info "xm_test, i2c_show" static ssize_t show (struct device_driver * driver, char * buf) {if (NULL! = buf) {/ * Newline is not appended on purpose, for convenience of reader programs * / snprintf (buf, PAGE_SIZE, "% s\ n", i2c_info) Return strlen (buf);} return 0;} DRIVER_ATTR (i2c_test, 0444, show, NULL); static struct attribute * audio_attrs [] = {& driver_attr_i2c_test.attr, NULL,}; static struct attribute_group audio_group = {.name = "xm_test", .attrs = audio_attrs,}; static const struct attribute_group * groups [] = {& audio_group, NULL,} Static int xm_test_probe (struct platform_device * pdev) {if (NULL = = pdev) {printk ("xiaomi_test: xm_test_probe failed, pdev is NULL\ n"); return 0;} if (NULL = = pdev- > dev.of_node) {printk ("xiaomi_test: xm_test_probe failed, of_node is NULL\ n"); return 0 } / * the presence of xm_test_tip will print out when the phone / development board starts * / if (of_property_read_bool (pdev- > dev.of_node, HW_TEST)) {printk ("xm_test:% s is existing\ n", HW_TEST);} printk ("= hanshubo =\ n"); return 0 The information of} / * .clients should be the same as that of compatible in dtsi * / static struct of_device_id audio_info_match_table [] = {{.clients = "xiaomi,xm-test",}, {},} Static struct platform_driver xm_test = {/ / device_driver .driver = {/ * the name here does not need to be consistent with the dtsi node xm-test * / .name = "xm-test", .of _ match_table = audio_info_match_table, .owner = THIS_MODULE, .groups = groups,}, .probe = xm_test_probe, .remove = NULL,} Static int _ init audio_info_init (void) {return platform_driver_register (& xm_test);} static void _ exit audio_info_exit (void) {platform_driver_unregister (& xm_test);} module_init (audio_info_init); module_exit (audio_info_exit); MODULE_LICENSE ("GPL"); 3. Verify whether the write in the sys file system is successful.
You will find the file i2c_test file in sys/bus/platform/drivers/xm_test:
# cat i2c_test# xm_test, i2c_show
Note: when registering a device using the device tree, the device node name "xm-test" does not have to be consistent with platform_driver.driver.name.
In other words, the bus will not match the device and the driver through these two items.
On how to initialize the linux driver according to the device tree file to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.