第一种:
1、添加关键头文件:
#include <linux/of_gpio.h> #include <linux/gpio.h> #include <linux/delay.h> #include <linux/module.h> #include <linux/types.h> #include <linux/kobject.h>
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, "%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的一致性,第一个参数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 failed\n",__func__); } pr_err("android_device_create()::Gpio134_OtgID gpio_request OK\n"); gpio_direction_output(Gpio134_OtgID,1); if(otgid_status > 0){ //有自定义初始化状态就添加上这个判断,没有就不需要添加if else操作 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、在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("%s\n", __func__); gpio_free(Gpio134_OtgID); //zhaojr add free gpio otgid pin ........................................................ }
第二种方法:
在要添加驱动文件中没有搜索"DEVICE_ATTR"关键字的情况,如添加音频功放打开和关闭的控制接口:
1、添加关键头文件:
#include <linux/of_gpio.h> #include <linux/gpio.h> #include <linux/delay.h> #include <linux/module.h> #include <linux/types.h> #include <linux/kobject.h>
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, "%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、在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 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; //将设备树种定义的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 error\n",__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; }
总结
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“解析linux或android添加文件系统的属性接口的方法”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新动态
2024年11月23日
2024年11月23日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]