c 源文件
#include <linux/proc_fs.h> /* zql add for creat profc */
#include <linux/seq_file.h>
#include <linux/module.h>
#include <linux/ioctl.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/hwinfo.h>
#define HWINFO_PROC_NAME "hwinfo1"
struct {
unsigned int pmic_info:2;
unsigned int panel_info:4;
unsigned int tp_maker_info:5;
unsigned int fp_info:1;
} hw_info;
//stuct hw_info hw_info;
void update_hardware_info(unsigned int type, unsigned int value)
{
switch(type)
{
case TYPE_PMIC:
hw_info.pmic_info = value;
break;
case TYPE_PANEL:
hw_info.panel_info = value;
break;
case TYPE_TP_MAKER:
hw_info.tp_maker_info = value;
break;
case TYPE_FP:
hw_info.fp_info = value;
break;
default:
break;
}
}
static int hwinfo_proc_show(struct seq_file *m, void *v)
{
switch (hw_info.fp_info) {
case 0:
seq_printf(m, "Fingerprint: Goodix\n");
break;
case 1:
seq_printf(m, "Fingerprint: FPC\n");
break;
default:
seq_printf(m, "Fingerprint: Unknown %x\n", hw_info.fp_info);
break;
}
return 0;
}
#if 1
static ssize_t hwinfo_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *f_pos)
{
char *tmp = kzalloc((count+1), GFP_KERNEL);
int tmpData;
if(!tmp)
return -ENOMEM;
if(copy_from_user(tmp, buffer, count))
{
kfree(tmp);
return EFAULT;
}
kstrtoint(tmp,10,&tmpData) ;
kfree(tmp);
hw_info.fp_info = tmpData;
return count;
}
#endif
static int hwinfo_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, hwinfo_proc_show, NULL);
}
static const struct file_operations hwinfo_proc_fops = {
.open = hwinfo_proc_open,
.read = seq_read,
.write = hwinfo_proc_write,
.llseek = seq_lseek,
.release = single_release,
};
static int __init hwinfo_init(void)
{
hw_info.fp_info = 0;
if (!proc_create(HWINFO_PROC_NAME, 0666, NULL, &hwinfo_proc_fops))
printk(KERN_ERR "hwinfo: unable to register /proc/hwinfo\n");
return 0;
}
static void __exit hwinfo_exit(void)
{
remove_proc_entry(HWINFO_PROC_NAME, NULL);
}
module_init(hwinfo_init);
module_exit(hwinfo_exit);
MODULE_LICENSE("GPL");
头文件
/* SPDX-License-Identifier: GPL-2.0 */
/*
* see fs/proc/hw_info.c
*/
#ifndef __LINUX_HWINFO_H
#define __LINUX_HWINFO_H
enum {
TYPE_PMIC,
TYPE_PANEL,
TYPE_TP_MAKER,
TYPE_FP,
};
void update_hardware_info(unsigned int type, unsigned int value);
#endif