Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of parsing linux or android to add the attribute interface of file system

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The first kind:

1. Add key header files:

# include # include

2. Search for the keyword "DEVICE_ATTR" in the existing driver file. If it exists, you can directly refer to the existing method and add one, as follows:

Unsigned int Gpio134_OtgID = 134; / / define the global variable static unsigned int otgid_status = 1; …

3. Define the read and write functions of the file system:

/ add zhaojr gpio134 control OTG ID for host or device mode static ssize_t setotgid_store (struct device * dev, struct device_attribute * attr,const char * buf, size_t count) {unsigned int ret=0; pr_err ("% s:\ n", _ _ func__); / / ret= kstrtoint (buf, 10, & otgid_status); ret= kstrtouint (buf, 10, & otgid_status); / / sscanf (buf, "% lu", & otgid_status); if (ret)

< 0){ pr_err("%s::kstrtouint() failed \n", __func__); } //sscanf(buf, "%d", &otgid_status); pr_err("%s: otgid_status=%d \n", __func__,otgid_status); if(otgid_status >

0) {gpio_set_value (Gpio134_OtgID, 1);} else {gpio_set_value (Gpio134_OtgID, 0);} return count;} static ssize_t setotgid_show (struct device * dev,struct device_attribute * attr, char * buf) {pr_err ("% s:\ n", _ _ func__); return sprintf (buf, "% d\ n", otgid_status);} / / static DEVICE_ATTR_RW (setotgid) / * struct device_attribute dev_attr_setotgid = {.attr = {. Name = "setotgid", .mode = 0664}, .show = setotgid_show, .store = setotgid_store,}; * / / setotgid consistency, the first parameter setotgid and setotgid_show, setotgid_store forward drilling must be consistent static DEVICE_ATTR (setotgid, 0664, setotgid_show, setotgid_store) / / end zhaojr addstatic struct device_attribute * android_usb_attributes [] = {& dev_attr_state, & dev_attr_setotgid, / / setotgid must be consistent with the name defined by DEVICE_ATTR NULL}

4. Define requests and initializations for specific GPIO pins in the probe () function

Static int mdss_mdp_probe (struct platform_device * pdev) {.... / / zhaojr add for gpio134 to usb host or device mode ret_status=gpio_request (Gpio134_OtgID, "Gpio134-OtgID") If (ret_status 0) {/ / add this judgment if there is a custom initialization state. Without it, there is no need to add if else operation pr_err ("% s-Gpio134_OtgID pin set 1\ n", _ _ func__); gpio_set_value (Gpio134_OtgID, 1); / / msleep (5);} else {pr_err ("% s-Gpio134_OtgID pin set 0\ n", _ _ func__) Gpio_set_value (Gpio134_OtgID, 0); / / msleep (5);} / / end zhaojr add....}

5. Add the release of resources to remove () function

Static int mdss_mdp_remove (struct platform_device * pdev) {struct mdss_data_type * mdata = platform_get_drvdata (pdev); if (! mdata) return-ENODEV; pr_err ("% s\ n", _ _ func__); gpio_free (Gpio134_OtgID) / / zhaojr add free gpio otgid pin...}

The second method:

In cases where the keyword "DEVICE_ATTR" is not searched in the driver file to be added, such as adding the control interface for turning the audio amplifier on and off:

1. Add key header files:

# include # include

2. Define global variables and interfaces that are up and down, and organize an array of attributes:

/ / add zhaojr gpio63 for close or speaker pa enablestruct kobject * spk_pa_kobj = NULL;unsigned int gpio63_spk_pa_gpio; / / for speaker pa ic enable//extern unsigned int gpio63_spk_pa_gpio;static unsigned int SpkPa_Gpio_Enable = 0 position static ssize_t spkpaon_store (struct device * dev, struct device_attribute * attr,const char * buf, size_t count) {unsigned int ret=0; / / ret= kstrtoint (buf, 10, & backlight_enable) Ret = kstrtouint (buf, 10, & SpkPa_Gpio_Enable); if (ret

< 0){ pr_err("%s::kstrtouint() failed \n", __func__); } pr_err("%s: SpkPa_Gpio_Enable=%d \n", __func__,SpkPa_Gpio_Enable); if(SpkPa_Gpio_Enable >

0) {/ / gpio_set_value (gpio63_spk_pa_gpio,1); pr_err ("% s: gpio_set_value gpio63 speaker pa enable\ n", _ _ func__); / / timing of power amplifier open gpio_set_value (gpio63_spk_pa_gpio,0); udelay (8); gpio_set_value (gpio63_spk_pa_gpio,1); udelay (8); gpio_set_value (gpio63_spk_pa_gpio,0); udelay (8) Gpio_set_value (gpio63_spk_pa_gpio,1); / / sdm660_cdc- > ext_spk_pa_set = true;} else {pr_err ("% s: gpio_set_value gpio63 speaker pa disable\ n", _ _ func__); / / timing of amplifier shutdown gpio_set_value (gpio63_spk_pa_gpio,0); udelay (600); / / sdm660_cdc- > ext_spk_pa_set = false;} return count } static ssize_t spkpaon_show (struct device * dev,struct device_attribute * attr, char * buf) {return sprintf (buf, "% d\ n", SpkPa_Gpio_Enable);} static DEVICE_ATTR (spkpaon, 0664, spkpaon_show, spkpaon_store); static struct attribute * spkpa_attributes [] = {& dev_attr_spkpaon.attr, NULL}; static const struct attribute_group apkpa_attr_group = {.attrs = spkpa_attributes, NULL}; / / end zhaojr add

3. Add the registration of the file system attribute interface to the probe () function:

There is no need to initialize the amplifier when registering, so there is no sdm660_cdc- > spk_pa_gpio (GPIO63) in the probe () function, just the request. For specific request operations, please refer to the audio section of the EAR and Speaker output sound configuration in the msm8953 audio section.

Vendor/qcom/opensource/audio-kernel/asoc/codecs/sdm660_cdc/msm-analog-cdc.c file operation

Static int msm_anlg_cdc_probe (struct platform_device * pdev) {int ret = 0; struct sdm660_cdc_priv * sdm660_cdc = NULL; struct sdm660_cdc_pdata * pdata; int adsp_state;. Dev_set_drvdata (& pdev- > dev, sdm660_cdc); / / kangting add sdm660_cdc- > spk_pa_gpio = of_get_named_gpio (pdev- > dev.of_node, "qcom,speaker-pa", 0); if (! gpio_is_valid (sdm660_cdc- > spk_pa_gpio) pr_err ("% s, sdm660_cdc- > spk_pa_gpio not specified\ n", _ _ func__) Else {pr_err ("% s, sdm660_cdc- > spk_pa_gpio is% d\ n", _ _ func__,sdm660_cdc- > spk_pa_gpio); ret= gpio_request (sdm660_cdc- > spk_pa_gpio, "spk_pa"); if (ret) {pr_err ("request spk_pa_gpio failed, ret=%d\ n", ret); gpio_free (sdm660_cdc- > spk_pa_gpio) }} / / kangting end ret = snd_soc_register_codec (& pdev- > dev, & soc_codec_dev_sdm660_cdc, msm_anlg_cdc_i2s_dai, ARRAY_SIZE (msm_anlg_cdc_i2s_dai)); if (ret) {dev_err (& pdev- > dev, "% s:snd_soc_register_codec failed with error% d\ n", _ _ func__, ret); goto err_supplies } BLOCKING_INIT_NOTIFIER_HEAD (& sdm660_cdc- > notifier); BLOCKING_INIT_NOTIFIER_HEAD (& sdm660_cdc- > notifier_mbhc); / / add by zhaojr gpio63_spk_pa_gpio = sdm660_cdc- > spk_pa_gpio; / / get the IO slogan defined by the device tree species spk_pa_kobj = kobject_create_and_add ("spk_pa", NULL) / / create / sys/spk_pa/ directory ret = sysfs_create_group (spk_pa_kobj, & apkpa_attr_group); / / create / sys/class/spk_pa/spkpaon node if (ret) dev_err (& pdev- > dev, "% s:sysfs_create_group failed with error\ n", _ _ func__) / / end zhaojr add..

4. Release resources in the remove function

Static int msm_anlg_cdc_remove (struct platform_device * pdev) {struct sdm660_cdc_priv * sdm660_cdc = dev_get_drvdata (& pdev- > dev); struct sdm660_cdc_pdata * pdata = sdm660_cdc- > dev- > platform_data; int count; / / add by zhaojr / / release resource gpio_free (sdm660_cdc- > spk_pa_gpio); kobject_put (spk_pa_kobj); / / key function sysfs_remove_group (spk_pa_kobj, & apkpa_attr_group) / / key function / / end zhaojr add for (count = 0; count

< sdm660_cdc->

Child_count & & count

< ANLG_CDC_CHILD_DEVICES_MAX; count++) platform_device_unregister( sdm660_cdc->

Pdev_child_ devices [count]; snd_soc_unregister_codec (& pdev- > dev); msm_anlg_cdc_disable_supplies (sdm660_cdc, pdata); wcd9xxx_spmi_irq_exit (); devm_kfree (& pdev- > dev, sdm660_cdc); return 0;}

Summary

This is the end of this article on parsing linux or android to add file system properties interface methods here, more related to linux file system properties interface content, please search the previous articles or continue to browse the following related articles hope that you will support more in the future!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report