综述
项目需求:传音客户
新增TP版本号节点:
/sys/devices/platform/miki-tpd/tp_firmware_version
自己编写一个简单的platform设备驱动
kernel-3.18/drivers/misc/mediatek/mikinode/
---mikinode.c
---Kconfig
---Makefile
1.mikinode.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/fs.h>
#define MIKI_TP_ATTR_NAME "tp_firmware_version"
u8 tp_fw_ver_factory = 0x01;
static ssize_t show_tp_version(struct device *dev,struct device_attribute *attr,char *buf)
{
printk("show_tp_version is call \n");
return snprintf(buf, PAGE_SIZE, "0x%02x\n", tp_fw_ver_factory);
}
static ssize_t store_tp_version(struct device *dev,struct device_attribute *attr,const char *buf,size_t size)
{
printk("store_tp_version is call \n");
return size;
}
static DEVICE_ATTR(tp_firmware_version,0664,show_tp_version,store_tp_version);
static int mikinode_probe(struct platform_device *dev)
{
int ret = 0;
printk("zcf mikinode_probe is call\n");
ret = device_create_file(&(dev->dev),&dev_attr_tp_firmware_version);
if(ret)
{
printk("zcf device_create_file failed\n");
}
return ret;
}
static struct platform_driver mikinode_driver = {
.driver = {
.name = "miki-tpd",
.owner = THIS_MODULE,
},
.probe = mikinode_probe,
};
#ifdef CONFIG_OF
static struct platform_device mikinode_device = {
.name = "miki-tpd",
.id = -1,
};
#endif
static int __init mikinode_init(void)
{
int err;
err = platform_device_register(&mikinode_device);
if(err)
{
printk("zcf failed to register device\n");
return -ENODEV;
}
err = platform_driver_register(&mikinode_driver);
if(err)
{
printk("zcf failed to register driver\n");
return -ENODEV;
}
return err;
}
static void __exit mikinode_exit(void)
{
platform_device_unregister(&mikinode_device);
}
module_init(mikinode_init);
module_exit(mikinode_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("miki tp node driver");
MODULE_AUTHOR("zengcf@mikimobile.com");
2.Kconfig
config MIKI_TP_SYS_NODE
bool "MIKI_TP_NODE for MediaTek package"
default n
help
It support to query TP version infomation.
If this option is set,it will support MIKI_TP_SYS_NODE.
3.Makefile
obj-y=mikinode.o
4.添加以下修改
kernel-3.18/drivers/misc/mediatek/Kconfig
kernel-3.18/drivers/misc/mediatek/Makefile
obj-y += mikinode/
device/mediatek/mt6580/init.mt6580.rc
#start-add by zcf in 2018.11.26 for tp_node
chmod 0666 /sys/devices/platform/miki-tpd/tp_firmware_version
chown root system /sys/devices/platform/miki-tpd/tp_firmware_version
#end-add by zcf in 2018.11.26 for tp_node
网友评论