4 * Description: ks0108 LCD Controller driver
8 * Author: Copyright (C) Miguel Ojeda Sandonis
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/init.h>
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/delay.h>
32 #include <linux/parport.h>
33 #include <linux/uaccess.h>
34 #include <linux/ks0108.h>
36 #define KS0108_NAME "ks0108"
42 static unsigned int ks0108_port
= CONFIG_KS0108_PORT
;
43 module_param(ks0108_port
, uint
, S_IRUGO
);
44 MODULE_PARM_DESC(ks0108_port
, "Parallel port where the LCD is connected");
46 static unsigned int ks0108_delay
= CONFIG_KS0108_DELAY
;
47 module_param(ks0108_delay
, uint
, S_IRUGO
);
48 MODULE_PARM_DESC(ks0108_delay
, "Delay between each control writing (microseconds)");
54 static struct parport
*ks0108_parport
;
55 static struct pardevice
*ks0108_pardevice
;
58 * ks0108 Exported Commands (don't lock)
60 * You _should_ lock in the top driver: This functions _should not_
61 * get race conditions in any way. Locking for each byte here would be
62 * so slow and useless.
64 * There are not bit definitions because they are not flags,
65 * just arbitrary combinations defined by the documentation for each
66 * function in the ks0108 LCD controller. If you want to know what means
67 * a specific combination, look at the function's name.
69 * The ks0108_writecontrol bits need to be reverted ^(0,1,3) because
70 * the parallel port also revert them using a "not" logic gate.
73 #define bit(n) (((unsigned char)1)<<(n))
75 void ks0108_writedata(unsigned char byte
)
77 parport_write_data(ks0108_parport
, byte
);
80 void ks0108_writecontrol(unsigned char byte
)
83 parport_write_control(ks0108_parport
, byte
^ (bit(0) | bit(1) | bit(3)));
86 void ks0108_displaystate(unsigned char state
)
88 ks0108_writedata((state
? bit(0) : 0) | bit(1) | bit(2) | bit(3) | bit(4) | bit(5));
91 void ks0108_startline(unsigned char startline
)
93 ks0108_writedata(min(startline
,(unsigned char)63) | bit(6) | bit(7));
96 void ks0108_address(unsigned char address
)
98 ks0108_writedata(min(address
,(unsigned char)63) | bit(6));
101 void ks0108_page(unsigned char page
)
103 ks0108_writedata(min(page
,(unsigned char)7) | bit(3) | bit(4) | bit(5) | bit(7));
106 EXPORT_SYMBOL_GPL(ks0108_writedata
);
107 EXPORT_SYMBOL_GPL(ks0108_writecontrol
);
108 EXPORT_SYMBOL_GPL(ks0108_displaystate
);
109 EXPORT_SYMBOL_GPL(ks0108_startline
);
110 EXPORT_SYMBOL_GPL(ks0108_address
);
111 EXPORT_SYMBOL_GPL(ks0108_page
);
114 * Is the module inited?
117 static unsigned char ks0108_inited
;
118 unsigned char ks0108_isinited(void)
120 return ks0108_inited
;
122 EXPORT_SYMBOL_GPL(ks0108_isinited
);
128 static int __init
ks0108_init(void)
133 ks0108_parport
= parport_find_base(ks0108_port
);
134 if (ks0108_parport
== NULL
) {
135 printk(KERN_ERR KS0108_NAME
": ERROR: "
136 "parport didn't find %i port\n", ks0108_port
);
140 ks0108_pardevice
= parport_register_device(ks0108_parport
, KS0108_NAME
,
141 NULL
, NULL
, NULL
, PARPORT_DEV_EXCL
, NULL
);
142 parport_put_port(ks0108_parport
);
143 if (ks0108_pardevice
== NULL
) {
144 printk(KERN_ERR KS0108_NAME
": ERROR: "
145 "parport didn't register new device\n");
149 result
= parport_claim(ks0108_pardevice
);
151 printk(KERN_ERR KS0108_NAME
": ERROR: "
152 "can't claim %i parport, maybe in use\n", ks0108_port
);
161 parport_unregister_device(ks0108_pardevice
);
167 static void __exit
ks0108_exit(void)
169 parport_release(ks0108_pardevice
);
170 parport_unregister_device(ks0108_pardevice
);
173 module_init(ks0108_init
);
174 module_exit(ks0108_exit
);
176 MODULE_LICENSE("GPL v2");
177 MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>");
178 MODULE_DESCRIPTION("ks0108 LCD Controller driver");