2 * /dev/lcd driver for Apple Network Servers.
5 #include <linux/types.h>
6 #include <linux/errno.h>
7 #include <linux/kernel.h>
8 #include <linux/miscdevice.h>
9 #include <linux/fcntl.h>
10 #include <linux/module.h>
11 #include <linux/delay.h>
14 #include <linux/uaccess.h>
15 #include <asm/sections.h>
21 #define ANSLCD_ADDR 0xf301c000
22 #define ANSLCD_CTRL_IX 0x00
23 #define ANSLCD_DATA_IX 0x10
25 static unsigned long anslcd_short_delay
= 80;
26 static unsigned long anslcd_long_delay
= 3280;
27 static volatile unsigned char __iomem
*anslcd_ptr
;
28 static DEFINE_MUTEX(anslcd_mutex
);
33 anslcd_write_byte_ctrl ( unsigned char c
)
36 printk(KERN_DEBUG
"LCD: CTRL byte: %02x\n",c
);
38 out_8(anslcd_ptr
+ ANSLCD_CTRL_IX
, c
);
43 udelay(anslcd_long_delay
); break;
44 default: udelay(anslcd_short_delay
);
49 anslcd_write_byte_data ( unsigned char c
)
51 out_8(anslcd_ptr
+ ANSLCD_DATA_IX
, c
);
52 udelay(anslcd_short_delay
);
56 anslcd_write( struct file
* file
, const char __user
* buf
,
57 size_t count
, loff_t
*ppos
)
59 const char __user
*p
= buf
;
63 printk(KERN_DEBUG
"LCD: write\n");
66 if (!access_ok(VERIFY_READ
, buf
, count
))
69 mutex_lock(&anslcd_mutex
);
70 for ( i
= *ppos
; count
> 0; ++i
, ++p
, --count
)
74 anslcd_write_byte_data( c
);
76 mutex_unlock(&anslcd_mutex
);
82 anslcd_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
84 char ch
, __user
*temp
;
88 printk(KERN_DEBUG
"LCD: ioctl(%d,%d)\n",cmd
,arg
);
91 mutex_lock(&anslcd_mutex
);
96 anslcd_write_byte_ctrl ( 0x38 );
97 anslcd_write_byte_ctrl ( 0x0f );
98 anslcd_write_byte_ctrl ( 0x06 );
99 anslcd_write_byte_ctrl ( 0x01 );
100 anslcd_write_byte_ctrl ( 0x02 );
102 case ANSLCD_SENDCTRL
:
103 temp
= (char __user
*) arg
;
104 __get_user(ch
, temp
);
105 for (; ch
; temp
++) { /* FIXME: This is ugly, but should work, as a \0 byte is not a valid command code */
106 anslcd_write_byte_ctrl ( ch
);
107 __get_user(ch
, temp
);
110 case ANSLCD_SETSHORTDELAY
:
111 if (!capable(CAP_SYS_ADMIN
))
114 anslcd_short_delay
=arg
;
116 case ANSLCD_SETLONGDELAY
:
117 if (!capable(CAP_SYS_ADMIN
))
120 anslcd_long_delay
=arg
;
126 mutex_unlock(&anslcd_mutex
);
131 anslcd_open( struct inode
* inode
, struct file
* file
)
136 const struct file_operations anslcd_fops
= {
137 .write
= anslcd_write
,
138 .unlocked_ioctl
= anslcd_ioctl
,
140 .llseek
= default_llseek
,
143 static struct miscdevice anslcd_dev
= {
149 const char anslcd_logo
[] = "********************" /* Line #1 */
150 "* LINUX! *" /* Line #3 */
151 "* Welcome to *" /* Line #2 */
152 "********************"; /* Line #4 */
159 struct device_node
* node
;
161 node
= of_find_node_by_name(NULL
, "lcd");
162 if (!node
|| !node
->parent
|| strcmp(node
->parent
->name
, "gc")) {
168 anslcd_ptr
= ioremap(ANSLCD_ADDR
, 0x20);
170 retval
= misc_register(&anslcd_dev
);
172 printk(KERN_INFO
"LCD: misc_register failed\n");
178 printk(KERN_DEBUG
"LCD: init\n");
181 mutex_lock(&anslcd_mutex
);
182 anslcd_write_byte_ctrl ( 0x38 );
183 anslcd_write_byte_ctrl ( 0x0c );
184 anslcd_write_byte_ctrl ( 0x06 );
185 anslcd_write_byte_ctrl ( 0x01 );
186 anslcd_write_byte_ctrl ( 0x02 );
188 anslcd_write_byte_data(anslcd_logo
[a
]);
190 mutex_unlock(&anslcd_mutex
);
197 misc_deregister(&anslcd_dev
);
201 module_init(anslcd_init
);
202 module_exit(anslcd_exit
);