OpenCores
URL https://opencores.org/ocsvn/wiegand_ctl/wiegand_ctl/trunk

Subversion Repositories wiegand_ctl

[/] [wiegand_ctl/] [trunk/] [sw/] [driver/] [linux/] [wiegand_drv.c] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 jeaander
/* Necessary includes for drivers */
2
#include <linux/init.h>
3
#include <linux/config.h>
4
#include <linux/module.h>
5
#include <linux/kernel.h> /* printk() */
6
#include <linux/slab.h> /* kmalloc() */
7
#include <linux/fs.h> /* everything... */
8
#include <linux/errno.h> /* error codes */
9
#include <linux/types.h> /* size_t */
10
#include <linux/proc_fs.h>
11
#include <linux/fcntl.h> /* O_ACCMODE */
12
#include <linux/ioport.h>
13
#include <asm/system.h> /* cli(), *_flags */
14
#include <asm/uaccess.h> /* copy_from/to_user */
15
#include <asm/io.h> /* inb, outb */
16
 
17
MODULE_LICENSE("Dual BSD/GPL");
18
 
19
/* Function declaration of parlelport.c */
20
int parlelport_open(struct inode *inode, struct file *filp);
21
int parlelport_release(struct inode *inode, struct file *filp);
22
ssize_t parlelport_read(struct file *filp, char *buf,
23
                       size_t count, loff_t *f_pos);
24
ssize_t parlelport_write(struct file *filp, char *buf,
25
                       size_t count, loff_t *f_pos);
26
void parlelport_exit(void);
27
int parlelport_init(void);
28
 
29
/* Structure that declares the common */
30
/* file access fcuntions */
31
struct file_operations parlelport_fops = {
32
  read: parlelport_read,
33
  write: parlelport_write,
34
  open: parlelport_open,
35
  release: parlelport_release
36
};
37
 
38
/* Driver global variables */
39
/* Major number */
40
int parlelport_major = 61;
41
 
42
/* Control variable for memory */
43
/* reservation of the parallel port*/
44
int port;
45
 
46
module_init(parlelport_init);
47
module_exit(parlelport_exit);
48
 
49
int parlelport_init(void) {
50
  int result;
51
 
52
  /* Registering device */
53
  result = register_chrdev(parlelport_major, "parlelport",
54
      &parlelport_fops);
55
  if (result < 0) {
56
    printk(
57
      "<1>parlelport: cannot obtain major number %d\n",
58
      parlelport_major);
59
    return result;
60
  }
61
 
62
  <parlelport modified init module>
63
 
64
  printk("<1>Inserting parlelport module\n");
65
  return 0;
66
 
67
  fail:
68
    parlelport_exit();
69
    return result;
70
}
71
 
72
void parlelport_exit(void) {
73
 
74
  /* Make major number free! */
75
  unregister_chrdev(parlelport_major, "parlelport");
76
 
77
  <parlelport modified exit module>
78
 
79
  printk("<1>Removing parlelport module\n");
80
}
81
 
82
int parlelport_open(struct inode *inode, struct file *filp) {
83
 
84
  /* Success */
85
  return 0;
86
 
87
}
88
 
89
int parlelport_release(struct inode *inode, struct file *filp) {
90
 
91
  /* Success */
92
  return 0;
93
}
94
 
95
ssize_t parlelport_read(struct file *filp, char *buf,
96
  size_t count, loff_t *f_pos) {
97
 
98
  /* Buffer to read the device */
99
  char parlelport_buffer;
100
 
101
  <parlelport inport>
102
 
103
  /* We transfer data to user space */
104
  copy_to_user(buf,&parlelport_buffer,1);
105
 
106
  /* We change the reading position as best suits */
107
  if (*f_pos == 0) {
108
    *f_pos+=1;
109
    return 1;
110
  } else {
111
    return 0;
112
  }
113
}
114
 
115
ssize_t parlelport_write( struct file *filp, char *buf,
116
  size_t count, loff_t *f_pos) {
117
 
118
  char *tmp;
119
 
120
  /* Buffer writing to the device */
121
  char parlelport_buffer;
122
 
123
  tmp=buf+count-1;
124
  copy_from_user(&parlelport_buffer,tmp,1);
125
 
126
  <parlelport outport>
127
 
128
  return 1;
129
}
130
 
131
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.