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/config.h>
18 #include <linux/types.h>
19 #include <linux/errno.h>
20 #include <linux/miscdevice.h>
21 #include <linux/slab.h>
22 #include <linux/ioport.h>
23 #include <linux/fcntl.h>
24 #include <linux/mc146818rtc.h>
25 #include <linux/netdevice.h>
26 #include <linux/sched.h>
27 #include <linux/delay.h>
30 #include <asm/uaccess.h>
31 #include <asm/system.h>
32 #include <linux/delay.h>
36 static DEFINE_SPINLOCK(lcd_lock);
38 static int lcd_ioctl(struct inode *inode, struct file *file,
39 unsigned int cmd, unsigned long arg);
41 static unsigned int lcd_present = 1;
43 /* used in arch/mips/cobalt/reset.c */
46 #if defined(CONFIG_TULIP) && 0
48 #define MAX_INTERFACES 8
49 static linkcheck_func_t linkcheck_callbacks[MAX_INTERFACES];
50 static void *linkcheck_cookies[MAX_INTERFACES];
52 int lcd_register_linkcheck_func(int iface_num, void *func, void *cookie)
55 iface_num >= MAX_INTERFACES ||
56 linkcheck_callbacks[iface_num] != NULL)
58 linkcheck_callbacks[iface_num] = (linkcheck_func_t) func;
59 linkcheck_cookies[iface_num] = cookie;
64 static int lcd_ioctl(struct inode *inode, struct file *file,
65 unsigned int cmd, unsigned long arg)
67 struct lcd_display button_display;
68 unsigned long address, a;
104 case LCD_Cursor_Left:
110 case LCD_Cursor_Right:
134 case LCD_Get_Cursor_Pos:{
135 struct lcd_display display;
139 display.cursor_address = (LCDReadInst);
140 display.cursor_address =
141 (display.cursor_address & 0x07F);
143 ((struct lcd_display *) arg, &display,
144 sizeof(struct lcd_display)))
151 case LCD_Set_Cursor_Pos:{
152 struct lcd_display display;
155 (&display, (struct lcd_display *) arg,
156 sizeof(struct lcd_display)))
159 a = (display.cursor_address | kLCD_Addr);
168 case LCD_Get_Cursor:{
169 struct lcd_display display;
173 display.character = LCDReadData;
176 ((struct lcd_display *) arg, &display,
177 sizeof(struct lcd_display)))
186 case LCD_Set_Cursor:{
187 struct lcd_display display;
190 (&display, (struct lcd_display *) arg,
191 sizeof(struct lcd_display)))
196 LCDWriteData(display.character);
224 struct lcd_display display;
229 (&display, (struct lcd_display *) arg,
230 sizeof(struct lcd_display)))
239 for (index = 0; index < (display.size1); index++) {
242 LCDWriteData(display.line1[index]);
251 for (index = 0; index < (display.size2); index++) {
254 LCDWriteData(display.line2[index]);
261 struct lcd_display display;
264 for (address = kDD_R00; address <= kDD_R01;
266 a = (address | kLCD_Addr);
273 display.line1[address] = LCDReadData;
276 display.line1[0x27] = '\0';
278 for (address = kDD_R10; address <= kDD_R11;
280 a = (address | kLCD_Addr);
288 display.line2[address - 0x40] =
292 display.line2[0x27] = '\0';
295 ((struct lcd_display *) arg, &display,
296 sizeof(struct lcd_display)))
301 // set all GPIO leds to led_display.leds
304 struct lcd_display led_display;
308 (&led_display, (struct lcd_display *) arg,
309 sizeof(struct lcd_display)))
312 led_state = led_display.leds;
319 // set only bit led_display.leds
324 struct lcd_display led_display;
328 (&led_display, (struct lcd_display *) arg,
329 sizeof(struct lcd_display)))
332 for (i = 0; i < (int) led_display.leds; i++) {
336 led_state = led_state | bit;
341 // clear only bit led_display.leds
346 struct lcd_display led_display;
350 (&led_display, (struct lcd_display *) arg,
351 sizeof(struct lcd_display)))
354 for (i = 0; i < (int) led_display.leds; i++) {
358 led_state = led_state & ~bit;
365 button_display.buttons = GPIRead;
367 ((struct lcd_display *) arg, &button_display,
368 sizeof(struct lcd_display)))
374 button_display.buttons =
375 *((volatile unsigned long *) (0xB0100060));
377 ((struct lcd_display *) arg, &button_display,
378 sizeof(struct lcd_display)))
386 /* panel-utils should pass in the desired interface status is wanted for
387 * in "buttons" of the structure. We will set this to non-zero if the
388 * link is in fact up for the requested interface. --DaveM
391 (&button_display, (struct lcd_display *) arg,
392 sizeof(button_display)))
394 iface_num = button_display.buttons;
395 #if defined(CONFIG_TULIP) && 0
396 if (iface_num >= 0 &&
397 iface_num < MAX_INTERFACES &&
398 linkcheck_callbacks[iface_num] != NULL) {
399 button_display.buttons =
400 linkcheck_callbacks[iface_num]
401 (linkcheck_cookies[iface_num]);
404 button_display.buttons = 0;
407 ((struct lcd_display *) arg, &button_display,
408 sizeof(struct lcd_display)))
419 if ( !capable(CAP_SYS_ADMIN) ) return -EPERM;
421 pr_info(LCD "Erasing Flash\n");
423 // Chip Erase Sequence
424 WRITE_FLASH(kFlash_Addr1, kFlash_Data1);
425 WRITE_FLASH(kFlash_Addr2, kFlash_Data2);
426 WRITE_FLASH(kFlash_Addr1, kFlash_Erase3);
427 WRITE_FLASH(kFlash_Addr1, kFlash_Data1);
428 WRITE_FLASH(kFlash_Addr2, kFlash_Data2);
429 WRITE_FLASH(kFlash_Addr1, kFlash_Erase6);
431 while ((!dqpoll(0x00000000, 0xFF))
432 && (!timeout(0x00000000))) {
436 if (READ_FLASH(0x07FFF0) == 0xFF) {
437 pr_info(LCD "Erase Successful\n");
438 } else if (timeout) {
439 pr_info(LCD "Erase Timed Out\n");
449 volatile unsigned long burn_addr;
451 unsigned int i, index;
455 struct lcd_display display;
457 if ( !capable(CAP_SYS_ADMIN) ) return -EPERM;
460 (&display, (struct lcd_display *) arg,
461 sizeof(struct lcd_display)))
463 rom = (unsigned char *) kmalloc((128), GFP_ATOMIC);
465 printk(KERN_ERR LCD "kmalloc() failed in %s\n",
470 pr_info(LCD "Starting Flash burn\n");
471 for (i = 0; i < FLASH_SIZE; i = i + 128) {
474 (rom, display.RomImage + i, 128)) {
478 burn_addr = kFlashBase + i;
479 spin_lock_irqsave(&lcd_lock, flags);
480 for (index = 0; index < (128); index++) {
482 WRITE_FLASH(kFlash_Addr1,
484 WRITE_FLASH(kFlash_Addr2,
486 WRITE_FLASH(kFlash_Addr1,
488 *((volatile unsigned char *)burn_addr) =
489 (volatile unsigned char) rom[index];
491 while ((!dqpoll (burn_addr,
492 (volatile unsigned char)
494 (!timeout(burn_addr))) { }
497 spin_unlock_irqrestore(&lcd_lock, flags);
498 if (* ((volatile unsigned char *)
500 (volatile unsigned char)
502 } else if (timeout) {
503 pr_info(LCD "Flash burn timed out\n");
510 pr_info(LCD "Flash successfully burned\n");
515 // read the flash all at once
519 unsigned char *user_bytes;
520 volatile unsigned long read_addr;
524 &(((struct lcd_display *) arg)->RomImage[0]);
527 (VERIFY_WRITE, user_bytes, FLASH_SIZE))
530 pr_info(LCD "Reading Flash");
531 for (i = 0; i < FLASH_SIZE; i++) {
532 unsigned char tmp_byte;
533 read_addr = kFlashBase + i;
535 *((volatile unsigned char *)
537 if (__put_user(tmp_byte, &user_bytes[i]))
554 static int lcd_open(struct inode *inode, struct file *file)
562 /* Only RESET or NEXT counts as button pressed */
564 static inline int button_pressed(void)
566 unsigned long buttons = GPIRead;
568 if ((buttons == BUTTON_Next) || (buttons == BUTTON_Next_B)
569 || (buttons == BUTTON_Reset_B))
574 /* LED daemon sits on this and we wake him up once a key is pressed. */
576 static int lcd_waiters = 0;
578 static long lcd_read(struct inode *inode, struct file *file, char *buf,
587 while (((buttons_now = (long) button_pressed()) == 0) &&
588 !(signal_pending(current))) {
589 msleep_interruptible(2000);
593 if (signal_pending(current))
599 * The various file operations we support.
602 static struct file_operations lcd_fops = {
608 static struct miscdevice lcd_dev = {
614 static int lcd_init(void)
619 pr_info("%s\n", LCD_DRIVER);
620 ret = misc_register(&lcd_dev);
622 printk(KERN_WARNING LCD "Unable to register misc device.\n");
626 /* Check region? Naaah! Just snarf it up. */
627 /* request_region(RTC_PORT(0), RTC_IO_EXTENT, "lcd");*/
631 if ((data & 0x000000FF) == (0x00)) {
633 pr_info(LCD "LCD Not Present\n");
636 WRITE_GAL(kGal_DevBank2PReg, kGal_DevBank2Cfg);
637 WRITE_GAL(kGal_DevBank3PReg, kGal_DevBank3Cfg);
643 static void __exit lcd_exit(void)
645 misc_deregister(&lcd_dev);
651 // Description: Polls the data lines to see if the flash is busy
653 // In: address, byte data
655 // Out: 0 = busy, 1 = write or erase complete
659 static int dqpoll(volatile unsigned long address, volatile unsigned char data)
661 volatile unsigned char dq7;
665 return ((READ_FLASH(address) & 0x80) == dq7);
671 // Description: Checks to see if erase or write has timed out
677 // Out: 0 = not timed out, 1 = timed out
679 static int timeout(volatile unsigned long address)
681 return (READ_FLASH(address) & 0x20) == 0x20;
684 module_init(lcd_init);
685 module_exit(lcd_exit);
687 MODULE_AUTHOR("Andrew Bose");
688 MODULE_LICENSE("GPL");