日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 默认站点!

默认站点

當前位置: 首頁 >

linux接口 头文件,第一种:1、添加关键头文件:#include linux/of_gpio.h#include linux/gpio.h...

發布時間:2023/12/2 29 豆豆
默认站点 收集整理的這篇文章主要介紹了 linux接口 头文件,第一种:1、添加关键头文件:#include linux/of_gpio.h#include linux/gpio.h... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第一種:

1、添加關鍵頭文件:

#include

#include

#include

#include

#include

#include

2、在已經存在驅動文件中搜索"DEVICE_ATTR"關鍵字,如果存在,直接參考已經存在的方法添加一個即可,如下:

unsigned int Gpio134_OtgID = 134; //定義全局變量

static unsigned int otgid_status = 1;

3、定義文件系統的讀寫函數:

//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, "%dn",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的一致性,第一個參數setotgid和setotgid_show、setotgid_store前鉆必須保持一致

static DEVICE_ATTR(setotgid, 0664, setotgid_show, setotgid_store);

//end zhaojr add

static struct device_attribute *android_usb_attributes[] = {

&dev_attr_state,

&dev_attr_setotgid, //setotgid跟DEVICE_ATTR定義的name必須保持一致

NULL

};

4、在probe()函數中定義針對具體GPIO管腳的請求和初始化

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){

pr_err("usb gadget configfs %s::Gpio134_OtgID gpio_request failedn",__func__);

}

pr_err("android_device_create()::Gpio134_OtgID gpio_request OKn");

gpio_direction_output(Gpio134_OtgID,1);

if(otgid_status > 0){ //有自定義初始化狀態就添加上這個判斷,沒有就不需要添加if else操作

pr_err("%s-Gpio134_OtgID pin set 1n", __func__);

gpio_set_value(Gpio134_OtgID, 1);

//msleep(5);

}else{

pr_err("%s-Gpio134_OtgID pin set 0n", __func__);

gpio_set_value(Gpio134_OtgID, 0);

//msleep(5);

}

//end zhaojr add

................................................................

}

5、在remove()函數中添加資源的釋放

static int mdss_mdp_remove(struct platform_device *pdev)

{

struct mdss_data_type *mdata = platform_get_drvdata(pdev);

if (!mdata)

return -ENODEV;

pr_err("%sn", __func__);

gpio_free(Gpio134_OtgID); //zhaojr add free gpio otgid pin

........................................................

}

第二種方法:

在要添加驅動文件中沒有搜索"DEVICE_ATTR"關鍵字的情況,如添加音頻功放打開和關閉的控制接口:

1、添加關鍵頭文件:

#include

#include

#include

#include

#include

#include

2、定義全局變量和定義打開和關閉的接口并組織屬性數組:

// add zhaojr gpio63 for close or speaker pa enable

struct 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;

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__);

//功放打開的時序

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__);

//功放關閉的時序

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, "%dn",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、在probe()函數中添加文件系統屬性接口的注冊:

在注冊的時候并不需要對功放進行初始化,所以probe()函數中并沒有對sdm660_cdc->spk_pa_gpio(GPIO63),只操作了請求。具體的請求操作請參考:msm8953 audio部分的EAR和Speaker輸出的聲音配置中的音頻部分的

vendor/qcom/opensource/audio-kernel/asoc/codecs/sdm660_cdc/msm-analog-cdc.c文件操作

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 specifiedn",__func__);

else{

pr_err("%s, sdm660_cdc->spk_pa_gpio is %dn",__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=%dn",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 %dn",

__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; //將設備樹種定義的IO口號獲取進來

spk_pa_kobj = kobject_create_and_add("spk_pa", NULL); //創建/sys/spk_pa/目錄

ret = sysfs_create_group(spk_pa_kobj, &apkpa_attr_group); //創建/sys/class/spk_pa/spkpaon節點

if (ret)

dev_err(&pdev->dev,"%s:sysfs_create_group failed with errorn",__func__);

//end zhaojr add

....................................

4、在remove函數中釋放資源

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 //釋放資源

gpio_free(sdm660_cdc->spk_pa_gpio);

kobject_put(spk_pa_kobj); //關鍵函數

sysfs_remove_group(spk_pa_kobj, &apkpa_attr_group); //關鍵函數

//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;

}

總結

到此這篇關于解析linux或android添加文件系統的屬性接口的方法的文章就介紹到這了,更多相關linux 文件系統的屬性接口內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

總結

以上是默认站点為你收集整理的linux接口 头文件,第一种:1、添加关键头文件:#include linux/of_gpio.h#include linux/gpio.h...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得默认站点網站內容還不錯,歡迎將默认站点推薦給好友。