Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/ioport.h>
- #include <linux/fs.h>
- #include <linux/cdev.h>
- #include <linux/device.h>
- #include <asm/io.h>
- #include "gpio_defs.h"
- #include "hwaccess.h"
- MODULE_LICENSE("Dual BSD/GPL");
- static int sample_cdev_open(struct inode *inode, struct file *file) {
- printk(KERN_INFO "open sample char device\n");
- return 0;
- }
- static int sample_cdev_release(struct inode *inode, struct file *file) {
- printk(KERN_INFO "release sample char device\n");
- return 0;
- }
- static ssize_t sample_cdev_read(struct file *file, char __user *data, size_t size, loff_t *offset) {
- return size;
- }
- static ssize_t sample_cdev_write(struct file *file, const char __user *data, size_t size, loff_t *offset) {
- return size;
- }
- static struct file_operations sample_cdev_fops = {
- .owner = THIS_MODULE,
- .open = sample_cdev_open,
- .release = sample_cdev_release,
- .read = sample_cdev_read,
- .write = sample_cdev_write,
- };
- static int my_init(void) {
- dev_t dev = 0;
- int PageSize = 4096;
- static struct cdev* sample_cdev;
- GpioRegs gpioRegs;
- printk("<1> Hello world!\n");
- if(request_mem_region(GPIO_BASE, sizeof(GpioRegs), "Name") == 0)
- {
- // goto fail_request_mem_region;
- }
- ioremap_nocache(GPIO_BASE, PageSize);
- if (alloc_chrdev_region(&dev,GPIO_FIRST_MINOR,1,"Name") < 0)
- {
- // goto fail_ioremap_nocache;
- }
- sample_cdev = cdev_alloc();
- if(!sample_cdev)
- {
- printk(KERN_ERR "failed to alloc cdev\n");
- return 1;
- }
- cdev_init(sample_cdev, &sample_cdev_fops);
- if(cdev_add(sample_cdev, dev, 1) < 0)
- {
- printk(KERN_ERR "failed to add cdev\n");
- goto fail_add_cdev;
- }
- initLeds(&gpioRegs);
- initSwitches(&gpioRegs);
- return 0;
- /*
- fail_ioremap_cache:
- //TODO requestregion freigeben
- fail_request_region:
- return 1;*/
- }
- static void my_exit(void) {
- printk("<1> Bye, cruel world\n");
- }
- module_init(my_init);
- module_exit(my_exit);
Advertisement
Add Comment
Please, Sign In to add comment