Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.5 kB
0
Indexable
Never
#include<linux/module.h>
#include<linux/fs.h>
#include<linux/cdev.h>
#include<linux/device.h>
#include<linux/kdev_t.h>

#define DEV_MEM_SIZE 512

char device_buffer[DEV_MEM_SIZE];

dev_t device_number;

struct cdev pcd_cdev;

loff_t pcd_lseek(struct file *filp, loff_t off, int whence){
	return 0;
}

ssize_t pcd_read(struct file *filp, char __user *buff, size_t count, loff_t *f_pos){
	return 0;
}

ssize_t pcd_write(struct file *filp, const char __user *buff, size_t count, loff_t *f_pos){
	return 0;
}

int pcd_open(struct inode *inode, struct file *filp){
	return 0;
}

int pcd_release(struct inode *inode, struct file *filp){
	return 0;
}

struct file_operations pcd_fops = 
{
	.open = pcd_open,
	.write = pcd_write,
	.release = pcd_release,
	.read = pcd_read,
	.llseek = pcd_lseek,
};

struct class *pcd_class;
struct device *pcd_device;
static int __init pcd_driver_init(void){
	int ret;
	ret = alloc_chrdev_region(&device_number,0,1,"pcd_devices");
	
	pr_info("%s Device number <MAJOR>:<MINOR> = %d:%d\n",__func__,MAJOR(device_number), MINOR(device_number));
	cdev_init(&pcd_cdev, &pcd_fops);
	pcd_cdev.owner = THIS_MODULE;
	cdev_add(&pcd_cdev, device_number, 1);
	pcd_class= class_create(THIS_MODULE,"pcd_class");
	pcd_device = device_create(pcd_class, NULL, device_number,NULL,"pcd");
	pr_info("Module init was sucessfull !");
	return 0;
}

static void __exit pcd_driver_cleanup(void){
	
}

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Tra");
MODULE_DESCRIPTION("First driver");
MODULE_VERSION("2:1.0");
Leave a Comment