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
14 #include <linux/types.h>
15 #include <linux/errno.h>
16 #include <linux/miscdevice.h>
17 #include <linux/slab.h>
18 #include <linux/ioport.h>
19 #include <linux/fcntl.h>
20 #include <linux/mc146818rtc.h>
21 #include <linux/netdevice.h>
22 #include <linux/sched.h>
23 #include <linux/delay.h>
26 #include <asm/uaccess.h>
27 #include <asm/system.h>
31 static int lcd_ioctl(struct inode *inode, struct file *file,
32 unsigned int cmd, unsigned long arg);
34 static unsigned int lcd_present = 1;
36 /* used in arch/mips/cobalt/reset.c */
39 #if defined(CONFIG_TULIP) && 0
41 #define MAX_INTERFACES 8
42 static linkcheck_func_t linkcheck_callbacks[MAX_INTERFACES];
43 static void *linkcheck_cookies[MAX_INTERFACES];
45 int lcd_register_linkcheck_func(int iface_num, void *func, void *cookie)
48 iface_num >= MAX_INTERFACES ||
49 linkcheck_callbacks[iface_num] != NULL)
51 linkcheck_callbacks[iface_num] = (linkcheck_func_t) func;
52 linkcheck_cookies[iface_num] = cookie;
57 static int lcd_ioctl(struct inode *inode, struct file *file,
58 unsigned int cmd, unsigned long arg)
60 struct lcd_display button_display;
61 unsigned long address, a;
103 case LCD_Cursor_Right:
127 case LCD_Get_Cursor_Pos:{
128 struct lcd_display display;
132 display.cursor_address = (LCDReadInst);
133 display.cursor_address =
134 (display.cursor_address & 0x07F);
136 ((struct lcd_display *) arg, &display,
137 sizeof(struct lcd_display)))
144 case LCD_Set_Cursor_Pos:{
145 struct lcd_display display;
148 (&display, (struct lcd_display *) arg,
149 sizeof(struct lcd_display)))
152 a = (display.cursor_address | kLCD_Addr);
161 case LCD_Get_Cursor:{
162 struct lcd_display display;
166 display.character = LCDReadData;
169 ((struct lcd_display *) arg, &display,
170 sizeof(struct lcd_display)))
179 case LCD_Set_Cursor:{
180 struct lcd_display display;
183 (&display, (struct lcd_display *) arg,
184 sizeof(struct lcd_display)))
189 LCDWriteData(display.character);
217 struct lcd_display display;
222 (&display, (struct lcd_display *) arg,
223 sizeof(struct lcd_display)))
232 for (index = 0; index < (display.size1); index++) {
235 LCDWriteData(display.line1[index]);
244 for (index = 0; index < (display.size2); index++) {
247 LCDWriteData(display.line2[index]);
254 struct lcd_display display;
257 for (address = kDD_R00; address <= kDD_R01;
259 a = (address | kLCD_Addr);
266 display.line1[address] = LCDReadData;
269 display.line1[0x27] = '\0';
271 for (address = kDD_R10; address <= kDD_R11;
273 a = (address | kLCD_Addr);
281 display.line2[address - 0x40] =
285 display.line2[0x27] = '\0';
288 ((struct lcd_display *) arg, &display,
289 sizeof(struct lcd_display)))
294 // set all GPIO leds to led_display.leds
297 struct lcd_display led_display;
301 (&led_display, (struct lcd_display *) arg,
302 sizeof(struct lcd_display)))
305 led_state = led_display.leds;
312 // set only bit led_display.leds
317 struct lcd_display led_display;
321 (&led_display, (struct lcd_display *) arg,
322 sizeof(struct lcd_display)))
325 for (i = 0; i < (int) led_display.leds; i++) {
329 led_state = led_state | bit;
334 // clear only bit led_display.leds
339 struct lcd_display led_display;
343 (&led_display, (struct lcd_display *) arg,
344 sizeof(struct lcd_display)))
347 for (i = 0; i < (int) led_display.leds; i++) {
351 led_state = led_state & ~bit;
358 button_display.buttons = GPIRead;
360 ((struct lcd_display *) arg, &button_display,
361 sizeof(struct lcd_display)))
367 button_display.buttons =
368 *((volatile unsigned long *) (0xB0100060));
370 ((struct lcd_display *) arg, &button_display,
371 sizeof(struct lcd_display)))
379 /* panel-utils should pass in the desired interface status is wanted for
380 * in "buttons" of the structure. We will set this to non-zero if the
381 * link is in fact up for the requested interface. --DaveM
384 (&button_display, (struct lcd_display *) arg,
385 sizeof(button_display)))
387 iface_num = button_display.buttons;
388 #if defined(CONFIG_TULIP) && 0
389 if (iface_num >= 0 &&
390 iface_num < MAX_INTERFACES &&
391 linkcheck_callbacks[iface_num] != NULL) {
392 button_display.buttons =
393 linkcheck_callbacks[iface_num]
394 (linkcheck_cookies[iface_num]);
397 button_display.buttons = 0;
400 ((struct lcd_display *) arg, &button_display,
401 sizeof(struct lcd_display)))
415 static int lcd_open(struct inode *inode, struct file *file)
423 /* Only RESET or NEXT counts as button pressed */
425 static inline int button_pressed(void)
427 unsigned long buttons = GPIRead;
429 if ((buttons == BUTTON_Next) || (buttons == BUTTON_Next_B)
430 || (buttons == BUTTON_Reset_B))
435 /* LED daemon sits on this and we wake him up once a key is pressed. */
437 static int lcd_waiters = 0;
439 static ssize_t lcd_read(struct file *file, char *buf,
440 size_t count, loff_t *ofs)
448 while (((buttons_now = (long) button_pressed()) == 0) &&
449 !(signal_pending(current))) {
450 msleep_interruptible(2000);
454 if (signal_pending(current))
460 * The various file operations we support.
463 static const struct file_operations lcd_fops = {
469 static struct miscdevice lcd_dev = {
475 static int lcd_init(void)
480 pr_info("%s\n", LCD_DRIVER);
481 ret = misc_register(&lcd_dev);
483 printk(KERN_WARNING LCD "Unable to register misc device.\n");
487 /* Check region? Naaah! Just snarf it up. */
488 /* request_region(RTC_PORT(0), RTC_IO_EXTENT, "lcd");*/
492 if ((data & 0x000000FF) == (0x00)) {
494 pr_info(LCD "LCD Not Present\n");
497 WRITE_GAL(kGal_DevBank2PReg, kGal_DevBank2Cfg);
498 WRITE_GAL(kGal_DevBank3PReg, kGal_DevBank3Cfg);
504 static void __exit lcd_exit(void)
506 misc_deregister(&lcd_dev);
509 module_init(lcd_init);
510 module_exit(lcd_exit);
512 MODULE_AUTHOR("Andrew Bose");
513 MODULE_LICENSE("GPL");