MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / drivers / char / lcd_16207.c
blobe65d12ef8eae69f4563e1da92fad3982f150c901
1 #include <linux/module.h>
2 #include <linux/errno.h>
3 #include <linux/cdev.h>
4 #include <linux/types.h>
5 #include <linux/errno.h>
6 #include <linux/miscdevice.h>
7 #include <linux/slab.h>
8 #include <linux/ioport.h>
9 #include <linux/fcntl.h>
10 #include <linux/mc146818rtc.h>
11 #include <linux/netdevice.h>
12 #include <linux/sched.h>
13 #include <linux/delay.h>
15 #include <asm/io.h>
16 #include <asm/uaccess.h>
17 #include <asm/system.h>
18 #include <linux/delay.h>
20 #define LCD_On 1
21 #define LCD_Off 2
22 #define LCD_Clear 3
23 #define LCD_Reset 4
24 #define LCD_Cursor_Left 5
25 #define LCD_Cursor_Right 6
26 #define LCD_Disp_Left 7
27 #define LCD_Disp_Right 8
28 #define LCD_Get_Cursor 9
29 #define LCD_Set_Cursor 10
30 #define LCD_Home 11
31 #define LCD_Read 12
32 #define LCD_Write 13
33 #define LCD_Cursor_Off 14
34 #define LCD_Cursor_On 15
35 #define LCD_Get_Cursor_Pos 16
36 #define LCD_Set_Cursor_Pos 17
37 #define LCD_Blink_Off 18
39 #define kLCD_IR na_lcd_16207_0
40 #define kLCD_DR (na_lcd_16207_0 + 8)
42 #define LCDWriteData(x) outl(x , kLCD_DR)
43 #define LCDWriteInst(x) outl(x , kLCD_IR)
45 #define LCDReadData inl(kLCD_DR)
46 #define LCDReadInst inl(kLCD_IR)
49 #define Major 250
51 static int Device_Open = 0;
53 static int lcd_16207_ioctl(struct inode *inode,struct file *filp,
54 unsigned int cmd,unsigned long arg);
56 static int lcd_16207_open(struct inode *inode,struct file *filp)
58 static int counter = 0;
59 if(Device_Open)return -EBUSY;
60 Device_Open++;
61 printk("You have open the device %d times\n",counter++);
62 return 0;
65 static int lcd_16207_release(struct inode *inode,struct file *filp)
67 Device_Open--;
68 printk("You have release the device\n");
69 return 0;
72 static int lcd_16207_ioctl(struct inode *inode,struct file *filp,
73 unsigned int cmd,unsigned long arg)
75 volatile unsigned long display;
77 switch (cmd) {
78 case LCD_On:
79 if (copy_from_user
80 (&display, (unsigned long *) arg,
81 sizeof(display)))
82 return -EFAULT;
84 LCDWriteInst(display);
85 break;
87 case LCD_Off:
88 if (copy_from_user
89 (&display, (unsigned long *) arg,
90 sizeof(display)))
91 return -EFAULT;
93 LCDWriteData(display);
94 break;
97 default:
98 return -EINVAL;
101 return 0;
104 static struct file_operations lcd_16207_fops={
105 .ioctl = lcd_16207_ioctl,
106 .open = lcd_16207_open,
107 .release = lcd_16207_release,
110 static int lcd_16207_init(void)
112 int ret = register_chrdev(Major,"LCD_PIO",&lcd_16207_fops);
113 if(ret<0)
115 printk("Registering the device failed with %d\n",Major);
116 return Major;
118 printk("You have init Device %d\n",Major);
119 return 0;
122 static void lcd_16207_exit(void)
124 if(unregister_chrdev(Major,"LCD_PIO"))
125 printk("exit failed");
128 module_init(lcd_16207_init);
129 module_exit(lcd_16207_exit);
131 MODULE_AUTHOR("Andrew Bose");
132 MODULE_LICENSE("GPL");