1 // SPDX-License-Identifier: GPL-2.0
3 * /dev/lcd driver for Apple Network Servers.
6 #include <linux/types.h>
7 #include <linux/errno.h>
8 #include <linux/kernel.h>
9 #include <linux/miscdevice.h>
10 #include <linux/fcntl.h>
11 #include <linux/module.h>
12 #include <linux/delay.h>
15 #include <linux/uaccess.h>
16 #include <asm/sections.h>
22 #define ANSLCD_ADDR 0xf301c000
23 #define ANSLCD_CTRL_IX 0x00
24 #define ANSLCD_DATA_IX 0x10
26 static unsigned long anslcd_short_delay
= 80;
27 static unsigned long anslcd_long_delay
= 3280;
28 static volatile unsigned char __iomem
*anslcd_ptr
;
29 static DEFINE_MUTEX(anslcd_mutex
);
34 anslcd_write_byte_ctrl ( unsigned char c
)
37 printk(KERN_DEBUG
"LCD: CTRL byte: %02x\n",c
);
39 out_8(anslcd_ptr
+ ANSLCD_CTRL_IX
, c
);
44 udelay(anslcd_long_delay
); break;
45 default: udelay(anslcd_short_delay
);
50 anslcd_write_byte_data ( unsigned char c
)
52 out_8(anslcd_ptr
+ ANSLCD_DATA_IX
, c
);
53 udelay(anslcd_short_delay
);
57 anslcd_write( struct file
* file
, const char __user
* buf
,
58 size_t count
, loff_t
*ppos
)
60 const char __user
*p
= buf
;
64 printk(KERN_DEBUG
"LCD: write\n");
67 if (!access_ok(VERIFY_READ
, buf
, count
))
70 mutex_lock(&anslcd_mutex
);
71 for ( i
= *ppos
; count
> 0; ++i
, ++p
, --count
)
75 anslcd_write_byte_data( c
);
77 mutex_unlock(&anslcd_mutex
);
83 anslcd_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
85 char ch
, __user
*temp
;
89 printk(KERN_DEBUG
"LCD: ioctl(%d,%d)\n",cmd
,arg
);
92 mutex_lock(&anslcd_mutex
);
97 anslcd_write_byte_ctrl ( 0x38 );
98 anslcd_write_byte_ctrl ( 0x0f );
99 anslcd_write_byte_ctrl ( 0x06 );
100 anslcd_write_byte_ctrl ( 0x01 );
101 anslcd_write_byte_ctrl ( 0x02 );
103 case ANSLCD_SENDCTRL
:
104 temp
= (char __user
*) arg
;
105 __get_user(ch
, temp
);
106 for (; ch
; temp
++) { /* FIXME: This is ugly, but should work, as a \0 byte is not a valid command code */
107 anslcd_write_byte_ctrl ( ch
);
108 __get_user(ch
, temp
);
111 case ANSLCD_SETSHORTDELAY
:
112 if (!capable(CAP_SYS_ADMIN
))
115 anslcd_short_delay
=arg
;
117 case ANSLCD_SETLONGDELAY
:
118 if (!capable(CAP_SYS_ADMIN
))
121 anslcd_long_delay
=arg
;
127 mutex_unlock(&anslcd_mutex
);
132 anslcd_open( struct inode
* inode
, struct file
* file
)
137 const struct file_operations anslcd_fops
= {
138 .write
= anslcd_write
,
139 .unlocked_ioctl
= anslcd_ioctl
,
141 .llseek
= default_llseek
,
144 static struct miscdevice anslcd_dev
= {
150 const char anslcd_logo
[] = "********************" /* Line #1 */
151 "* LINUX! *" /* Line #3 */
152 "* Welcome to *" /* Line #2 */
153 "********************"; /* Line #4 */
160 struct device_node
* node
;
162 node
= of_find_node_by_name(NULL
, "lcd");
163 if (!node
|| !node
->parent
|| strcmp(node
->parent
->name
, "gc")) {
169 anslcd_ptr
= ioremap(ANSLCD_ADDR
, 0x20);
171 retval
= misc_register(&anslcd_dev
);
173 printk(KERN_INFO
"LCD: misc_register failed\n");
179 printk(KERN_DEBUG
"LCD: init\n");
182 mutex_lock(&anslcd_mutex
);
183 anslcd_write_byte_ctrl ( 0x38 );
184 anslcd_write_byte_ctrl ( 0x0c );
185 anslcd_write_byte_ctrl ( 0x06 );
186 anslcd_write_byte_ctrl ( 0x01 );
187 anslcd_write_byte_ctrl ( 0x02 );
189 anslcd_write_byte_data(anslcd_logo
[a
]);
191 mutex_unlock(&anslcd_mutex
);
198 misc_deregister(&anslcd_dev
);
202 module_init(anslcd_init
);
203 module_exit(anslcd_exit
);
204 MODULE_LICENSE("GPL v2");