[SCSI] eata_pio: Remove FALSE/TRUE defines
[linux-2.6/mini2440.git] / drivers / char / lcd.c
blob5f4fdcf7c96e50124404e3e1fa16963bf9da9480
1 /*
2 * LCD, LED and Button interface for Cobalt
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
8 * Copyright (C) 1996, 1997 by Andrew Bose
10 * Linux kernel version history:
11 * March 2001: Ported from 2.0.34 by Liam Davies
15 #define RTC_IO_EXTENT 0x10 /*Only really two ports, but... */
17 #include <linux/types.h>
18 #include <linux/errno.h>
19 #include <linux/miscdevice.h>
20 #include <linux/slab.h>
21 #include <linux/ioport.h>
22 #include <linux/fcntl.h>
23 #include <linux/mc146818rtc.h>
24 #include <linux/netdevice.h>
25 #include <linux/sched.h>
26 #include <linux/delay.h>
28 #include <asm/io.h>
29 #include <asm/uaccess.h>
30 #include <asm/system.h>
31 #include <linux/delay.h>
33 #include "lcd.h"
35 static DEFINE_SPINLOCK(lcd_lock);
37 static int lcd_ioctl(struct inode *inode, struct file *file,
38 unsigned int cmd, unsigned long arg);
40 static unsigned int lcd_present = 1;
42 /* used in arch/mips/cobalt/reset.c */
43 int led_state = 0;
45 #if defined(CONFIG_TULIP) && 0
47 #define MAX_INTERFACES 8
48 static linkcheck_func_t linkcheck_callbacks[MAX_INTERFACES];
49 static void *linkcheck_cookies[MAX_INTERFACES];
51 int lcd_register_linkcheck_func(int iface_num, void *func, void *cookie)
53 if (iface_num < 0 ||
54 iface_num >= MAX_INTERFACES ||
55 linkcheck_callbacks[iface_num] != NULL)
56 return -1;
57 linkcheck_callbacks[iface_num] = (linkcheck_func_t) func;
58 linkcheck_cookies[iface_num] = cookie;
59 return 0;
61 #endif
63 static int lcd_ioctl(struct inode *inode, struct file *file,
64 unsigned int cmd, unsigned long arg)
66 struct lcd_display button_display;
67 unsigned long address, a;
69 switch (cmd) {
70 case LCD_On:
71 udelay(150);
72 BusyCheck();
73 LCDWriteInst(0x0F);
74 break;
76 case LCD_Off:
77 udelay(150);
78 BusyCheck();
79 LCDWriteInst(0x08);
80 break;
82 case LCD_Reset:
83 udelay(150);
84 LCDWriteInst(0x3F);
85 udelay(150);
86 LCDWriteInst(0x3F);
87 udelay(150);
88 LCDWriteInst(0x3F);
89 udelay(150);
90 LCDWriteInst(0x3F);
91 udelay(150);
92 LCDWriteInst(0x01);
93 udelay(150);
94 LCDWriteInst(0x06);
95 break;
97 case LCD_Clear:
98 udelay(150);
99 BusyCheck();
100 LCDWriteInst(0x01);
101 break;
103 case LCD_Cursor_Left:
104 udelay(150);
105 BusyCheck();
106 LCDWriteInst(0x10);
107 break;
109 case LCD_Cursor_Right:
110 udelay(150);
111 BusyCheck();
112 LCDWriteInst(0x14);
113 break;
115 case LCD_Cursor_Off:
116 udelay(150);
117 BusyCheck();
118 LCDWriteInst(0x0C);
119 break;
121 case LCD_Cursor_On:
122 udelay(150);
123 BusyCheck();
124 LCDWriteInst(0x0F);
125 break;
127 case LCD_Blink_Off:
128 udelay(150);
129 BusyCheck();
130 LCDWriteInst(0x0E);
131 break;
133 case LCD_Get_Cursor_Pos:{
134 struct lcd_display display;
136 udelay(150);
137 BusyCheck();
138 display.cursor_address = (LCDReadInst);
139 display.cursor_address =
140 (display.cursor_address & 0x07F);
141 if (copy_to_user
142 ((struct lcd_display *) arg, &display,
143 sizeof(struct lcd_display)))
144 return -EFAULT;
146 break;
150 case LCD_Set_Cursor_Pos:{
151 struct lcd_display display;
153 if (copy_from_user
154 (&display, (struct lcd_display *) arg,
155 sizeof(struct lcd_display)))
156 return -EFAULT;
158 a = (display.cursor_address | kLCD_Addr);
160 udelay(150);
161 BusyCheck();
162 LCDWriteInst(a);
164 break;
167 case LCD_Get_Cursor:{
168 struct lcd_display display;
170 udelay(150);
171 BusyCheck();
172 display.character = LCDReadData;
174 if (copy_to_user
175 ((struct lcd_display *) arg, &display,
176 sizeof(struct lcd_display)))
177 return -EFAULT;
178 udelay(150);
179 BusyCheck();
180 LCDWriteInst(0x10);
182 break;
185 case LCD_Set_Cursor:{
186 struct lcd_display display;
188 if (copy_from_user
189 (&display, (struct lcd_display *) arg,
190 sizeof(struct lcd_display)))
191 return -EFAULT;
193 udelay(150);
194 BusyCheck();
195 LCDWriteData(display.character);
196 udelay(150);
197 BusyCheck();
198 LCDWriteInst(0x10);
200 break;
204 case LCD_Disp_Left:
205 udelay(150);
206 BusyCheck();
207 LCDWriteInst(0x18);
208 break;
210 case LCD_Disp_Right:
211 udelay(150);
212 BusyCheck();
213 LCDWriteInst(0x1C);
214 break;
216 case LCD_Home:
217 udelay(150);
218 BusyCheck();
219 LCDWriteInst(0x02);
220 break;
222 case LCD_Write:{
223 struct lcd_display display;
224 unsigned int index;
227 if (copy_from_user
228 (&display, (struct lcd_display *) arg,
229 sizeof(struct lcd_display)))
230 return -EFAULT;
232 udelay(150);
233 BusyCheck();
234 LCDWriteInst(0x80);
235 udelay(150);
236 BusyCheck();
238 for (index = 0; index < (display.size1); index++) {
239 udelay(150);
240 BusyCheck();
241 LCDWriteData(display.line1[index]);
242 BusyCheck();
245 udelay(150);
246 BusyCheck();
247 LCDWriteInst(0xC0);
248 udelay(150);
249 BusyCheck();
250 for (index = 0; index < (display.size2); index++) {
251 udelay(150);
252 BusyCheck();
253 LCDWriteData(display.line2[index]);
256 break;
259 case LCD_Read:{
260 struct lcd_display display;
262 BusyCheck();
263 for (address = kDD_R00; address <= kDD_R01;
264 address++) {
265 a = (address | kLCD_Addr);
267 udelay(150);
268 BusyCheck();
269 LCDWriteInst(a);
270 udelay(150);
271 BusyCheck();
272 display.line1[address] = LCDReadData;
275 display.line1[0x27] = '\0';
277 for (address = kDD_R10; address <= kDD_R11;
278 address++) {
279 a = (address | kLCD_Addr);
281 udelay(150);
282 BusyCheck();
283 LCDWriteInst(a);
285 udelay(150);
286 BusyCheck();
287 display.line2[address - 0x40] =
288 LCDReadData;
291 display.line2[0x27] = '\0';
293 if (copy_to_user
294 ((struct lcd_display *) arg, &display,
295 sizeof(struct lcd_display)))
296 return -EFAULT;
297 break;
300 // set all GPIO leds to led_display.leds
302 case LED_Set:{
303 struct lcd_display led_display;
306 if (copy_from_user
307 (&led_display, (struct lcd_display *) arg,
308 sizeof(struct lcd_display)))
309 return -EFAULT;
311 led_state = led_display.leds;
312 LEDSet(led_state);
314 break;
318 // set only bit led_display.leds
320 case LED_Bit_Set:{
321 unsigned int i;
322 int bit = 1;
323 struct lcd_display led_display;
326 if (copy_from_user
327 (&led_display, (struct lcd_display *) arg,
328 sizeof(struct lcd_display)))
329 return -EFAULT;
331 for (i = 0; i < (int) led_display.leds; i++) {
332 bit = 2 * bit;
335 led_state = led_state | bit;
336 LEDSet(led_state);
337 break;
340 // clear only bit led_display.leds
342 case LED_Bit_Clear:{
343 unsigned int i;
344 int bit = 1;
345 struct lcd_display led_display;
348 if (copy_from_user
349 (&led_display, (struct lcd_display *) arg,
350 sizeof(struct lcd_display)))
351 return -EFAULT;
353 for (i = 0; i < (int) led_display.leds; i++) {
354 bit = 2 * bit;
357 led_state = led_state & ~bit;
358 LEDSet(led_state);
359 break;
363 case BUTTON_Read:{
364 button_display.buttons = GPIRead;
365 if (copy_to_user
366 ((struct lcd_display *) arg, &button_display,
367 sizeof(struct lcd_display)))
368 return -EFAULT;
369 break;
372 case LINK_Check:{
373 button_display.buttons =
374 *((volatile unsigned long *) (0xB0100060));
375 if (copy_to_user
376 ((struct lcd_display *) arg, &button_display,
377 sizeof(struct lcd_display)))
378 return -EFAULT;
379 break;
382 case LINK_Check_2:{
383 int iface_num;
385 /* panel-utils should pass in the desired interface status is wanted for
386 * in "buttons" of the structure. We will set this to non-zero if the
387 * link is in fact up for the requested interface. --DaveM
389 if (copy_from_user
390 (&button_display, (struct lcd_display *) arg,
391 sizeof(button_display)))
392 return -EFAULT;
393 iface_num = button_display.buttons;
394 #if defined(CONFIG_TULIP) && 0
395 if (iface_num >= 0 &&
396 iface_num < MAX_INTERFACES &&
397 linkcheck_callbacks[iface_num] != NULL) {
398 button_display.buttons =
399 linkcheck_callbacks[iface_num]
400 (linkcheck_cookies[iface_num]);
401 } else
402 #endif
403 button_display.buttons = 0;
405 if (__copy_to_user
406 ((struct lcd_display *) arg, &button_display,
407 sizeof(struct lcd_display)))
408 return -EFAULT;
409 break;
412 default:
413 return -EINVAL;
417 return 0;
421 static int lcd_open(struct inode *inode, struct file *file)
423 if (!lcd_present)
424 return -ENXIO;
425 else
426 return 0;
429 /* Only RESET or NEXT counts as button pressed */
431 static inline int button_pressed(void)
433 unsigned long buttons = GPIRead;
435 if ((buttons == BUTTON_Next) || (buttons == BUTTON_Next_B)
436 || (buttons == BUTTON_Reset_B))
437 return buttons;
438 return 0;
441 /* LED daemon sits on this and we wake him up once a key is pressed. */
443 static int lcd_waiters = 0;
445 static ssize_t lcd_read(struct file *file, char *buf,
446 size_t count, loff_t *ofs)
448 long buttons_now;
450 if (lcd_waiters > 0)
451 return -EINVAL;
453 lcd_waiters++;
454 while (((buttons_now = (long) button_pressed()) == 0) &&
455 !(signal_pending(current))) {
456 msleep_interruptible(2000);
458 lcd_waiters--;
460 if (signal_pending(current))
461 return -ERESTARTSYS;
462 return buttons_now;
466 * The various file operations we support.
469 static const struct file_operations lcd_fops = {
470 .read = lcd_read,
471 .ioctl = lcd_ioctl,
472 .open = lcd_open,
475 static struct miscdevice lcd_dev = {
476 MISC_DYNAMIC_MINOR,
477 "lcd",
478 &lcd_fops
481 static int lcd_init(void)
483 int ret;
484 unsigned long data;
486 pr_info("%s\n", LCD_DRIVER);
487 ret = misc_register(&lcd_dev);
488 if (ret) {
489 printk(KERN_WARNING LCD "Unable to register misc device.\n");
490 return ret;
493 /* Check region? Naaah! Just snarf it up. */
494 /* request_region(RTC_PORT(0), RTC_IO_EXTENT, "lcd");*/
496 udelay(150);
497 data = LCDReadData;
498 if ((data & 0x000000FF) == (0x00)) {
499 lcd_present = 0;
500 pr_info(LCD "LCD Not Present\n");
501 } else {
502 lcd_present = 1;
503 WRITE_GAL(kGal_DevBank2PReg, kGal_DevBank2Cfg);
504 WRITE_GAL(kGal_DevBank3PReg, kGal_DevBank3Cfg);
507 return 0;
510 static void __exit lcd_exit(void)
512 misc_deregister(&lcd_dev);
515 module_init(lcd_init);
516 module_exit(lcd_exit);
518 MODULE_AUTHOR("Andrew Bose");
519 MODULE_LICENSE("GPL");