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
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>
29 #include <asm/uaccess.h>
30 #include <asm/system.h>
31 #include <linux/delay.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 */
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
)
54 iface_num
>= MAX_INTERFACES
||
55 linkcheck_callbacks
[iface_num
] != NULL
)
57 linkcheck_callbacks
[iface_num
] = (linkcheck_func_t
) func
;
58 linkcheck_cookies
[iface_num
] = cookie
;
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
;
103 case LCD_Cursor_Left
:
109 case LCD_Cursor_Right
:
133 case LCD_Get_Cursor_Pos
:{
134 struct lcd_display display
;
138 display
.cursor_address
= (LCDReadInst
);
139 display
.cursor_address
=
140 (display
.cursor_address
& 0x07F);
142 ((struct lcd_display
*) arg
, &display
,
143 sizeof(struct lcd_display
)))
150 case LCD_Set_Cursor_Pos
:{
151 struct lcd_display display
;
154 (&display
, (struct lcd_display
*) arg
,
155 sizeof(struct lcd_display
)))
158 a
= (display
.cursor_address
| kLCD_Addr
);
167 case LCD_Get_Cursor
:{
168 struct lcd_display display
;
172 display
.character
= LCDReadData
;
175 ((struct lcd_display
*) arg
, &display
,
176 sizeof(struct lcd_display
)))
185 case LCD_Set_Cursor
:{
186 struct lcd_display display
;
189 (&display
, (struct lcd_display
*) arg
,
190 sizeof(struct lcd_display
)))
195 LCDWriteData(display
.character
);
223 struct lcd_display display
;
228 (&display
, (struct lcd_display
*) arg
,
229 sizeof(struct lcd_display
)))
238 for (index
= 0; index
< (display
.size1
); index
++) {
241 LCDWriteData(display
.line1
[index
]);
250 for (index
= 0; index
< (display
.size2
); index
++) {
253 LCDWriteData(display
.line2
[index
]);
260 struct lcd_display display
;
263 for (address
= kDD_R00
; address
<= kDD_R01
;
265 a
= (address
| kLCD_Addr
);
272 display
.line1
[address
] = LCDReadData
;
275 display
.line1
[0x27] = '\0';
277 for (address
= kDD_R10
; address
<= kDD_R11
;
279 a
= (address
| kLCD_Addr
);
287 display
.line2
[address
- 0x40] =
291 display
.line2
[0x27] = '\0';
294 ((struct lcd_display
*) arg
, &display
,
295 sizeof(struct lcd_display
)))
300 // set all GPIO leds to led_display.leds
303 struct lcd_display led_display
;
307 (&led_display
, (struct lcd_display
*) arg
,
308 sizeof(struct lcd_display
)))
311 led_state
= led_display
.leds
;
318 // set only bit led_display.leds
323 struct lcd_display led_display
;
327 (&led_display
, (struct lcd_display
*) arg
,
328 sizeof(struct lcd_display
)))
331 for (i
= 0; i
< (int) led_display
.leds
; i
++) {
335 led_state
= led_state
| bit
;
340 // clear only bit led_display.leds
345 struct lcd_display led_display
;
349 (&led_display
, (struct lcd_display
*) arg
,
350 sizeof(struct lcd_display
)))
353 for (i
= 0; i
< (int) led_display
.leds
; i
++) {
357 led_state
= led_state
& ~bit
;
364 button_display
.buttons
= GPIRead
;
366 ((struct lcd_display
*) arg
, &button_display
,
367 sizeof(struct lcd_display
)))
373 button_display
.buttons
=
374 *((volatile unsigned long *) (0xB0100060));
376 ((struct lcd_display
*) arg
, &button_display
,
377 sizeof(struct lcd_display
)))
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
390 (&button_display
, (struct lcd_display
*) arg
,
391 sizeof(button_display
)))
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
]);
403 button_display
.buttons
= 0;
406 ((struct lcd_display
*) arg
, &button_display
,
407 sizeof(struct lcd_display
)))
421 static int lcd_open(struct inode
*inode
, struct file
*file
)
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
))
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
)
454 while (((buttons_now
= (long) button_pressed()) == 0) &&
455 !(signal_pending(current
))) {
456 msleep_interruptible(2000);
460 if (signal_pending(current
))
466 * The various file operations we support.
469 static const struct file_operations lcd_fops
= {
475 static struct miscdevice lcd_dev
= {
481 static int lcd_init(void)
486 pr_info("%s\n", LCD_DRIVER
);
487 ret
= misc_register(&lcd_dev
);
489 printk(KERN_WARNING LCD
"Unable to register misc device.\n");
493 /* Check region? Naaah! Just snarf it up. */
494 /* request_region(RTC_PORT(0), RTC_IO_EXTENT, "lcd");*/
498 if ((data
& 0x000000FF) == (0x00)) {
500 pr_info(LCD
"LCD Not Present\n");
503 WRITE_GAL(kGal_DevBank2PReg
, kGal_DevBank2Cfg
);
504 WRITE_GAL(kGal_DevBank3PReg
, kGal_DevBank3Cfg
);
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");