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
)))
418 if ( !capable(CAP_SYS_ADMIN
) ) return -EPERM
;
420 pr_info(LCD
"Erasing Flash\n");
422 // Chip Erase Sequence
423 WRITE_FLASH(kFlash_Addr1
, kFlash_Data1
);
424 WRITE_FLASH(kFlash_Addr2
, kFlash_Data2
);
425 WRITE_FLASH(kFlash_Addr1
, kFlash_Erase3
);
426 WRITE_FLASH(kFlash_Addr1
, kFlash_Data1
);
427 WRITE_FLASH(kFlash_Addr2
, kFlash_Data2
);
428 WRITE_FLASH(kFlash_Addr1
, kFlash_Erase6
);
430 while ((!dqpoll(0x00000000, 0xFF))
431 && (!timeout(0x00000000))) {
435 if (READ_FLASH(0x07FFF0) == 0xFF) {
436 pr_info(LCD
"Erase Successful\n");
437 } else if (timeout
) {
438 pr_info(LCD
"Erase Timed Out\n");
448 volatile unsigned long burn_addr
;
450 unsigned int i
, index
;
454 struct lcd_display display
;
456 if ( !capable(CAP_SYS_ADMIN
) ) return -EPERM
;
459 (&display
, (struct lcd_display
*) arg
,
460 sizeof(struct lcd_display
)))
462 rom
= kmalloc((128), GFP_ATOMIC
);
464 printk(KERN_ERR LCD
"kmalloc() failed in %s\n",
469 pr_info(LCD
"Starting Flash burn\n");
470 for (i
= 0; i
< FLASH_SIZE
; i
= i
+ 128) {
473 (rom
, display
.RomImage
+ i
, 128)) {
477 burn_addr
= kFlashBase
+ i
;
478 spin_lock_irqsave(&lcd_lock
, flags
);
479 for (index
= 0; index
< (128); index
++) {
481 WRITE_FLASH(kFlash_Addr1
,
483 WRITE_FLASH(kFlash_Addr2
,
485 WRITE_FLASH(kFlash_Addr1
,
487 *((volatile unsigned char *)burn_addr
) =
488 (volatile unsigned char) rom
[index
];
490 while ((!dqpoll (burn_addr
,
491 (volatile unsigned char)
493 (!timeout(burn_addr
))) { }
496 spin_unlock_irqrestore(&lcd_lock
, flags
);
497 if (* ((volatile unsigned char *)
499 (volatile unsigned char)
501 } else if (timeout
) {
502 pr_info(LCD
"Flash burn timed out\n");
509 pr_info(LCD
"Flash successfully burned\n");
514 // read the flash all at once
518 unsigned char *user_bytes
;
519 volatile unsigned long read_addr
;
523 &(((struct lcd_display
*) arg
)->RomImage
[0]);
526 (VERIFY_WRITE
, user_bytes
, FLASH_SIZE
))
529 pr_info(LCD
"Reading Flash");
530 for (i
= 0; i
< FLASH_SIZE
; i
++) {
531 unsigned char tmp_byte
;
532 read_addr
= kFlashBase
+ i
;
534 *((volatile unsigned char *)
536 if (__put_user(tmp_byte
, &user_bytes
[i
]))
553 static int lcd_open(struct inode
*inode
, struct file
*file
)
561 /* Only RESET or NEXT counts as button pressed */
563 static inline int button_pressed(void)
565 unsigned long buttons
= GPIRead
;
567 if ((buttons
== BUTTON_Next
) || (buttons
== BUTTON_Next_B
)
568 || (buttons
== BUTTON_Reset_B
))
573 /* LED daemon sits on this and we wake him up once a key is pressed. */
575 static int lcd_waiters
= 0;
577 static ssize_t
lcd_read(struct file
*file
, char *buf
,
578 size_t count
, loff_t
*ofs
)
586 while (((buttons_now
= (long) button_pressed()) == 0) &&
587 !(signal_pending(current
))) {
588 msleep_interruptible(2000);
592 if (signal_pending(current
))
598 * The various file operations we support.
601 static const struct file_operations lcd_fops
= {
607 static struct miscdevice lcd_dev
= {
613 static int lcd_init(void)
618 pr_info("%s\n", LCD_DRIVER
);
619 ret
= misc_register(&lcd_dev
);
621 printk(KERN_WARNING LCD
"Unable to register misc device.\n");
625 /* Check region? Naaah! Just snarf it up. */
626 /* request_region(RTC_PORT(0), RTC_IO_EXTENT, "lcd");*/
630 if ((data
& 0x000000FF) == (0x00)) {
632 pr_info(LCD
"LCD Not Present\n");
635 WRITE_GAL(kGal_DevBank2PReg
, kGal_DevBank2Cfg
);
636 WRITE_GAL(kGal_DevBank3PReg
, kGal_DevBank3Cfg
);
642 static void __exit
lcd_exit(void)
644 misc_deregister(&lcd_dev
);
650 // Description: Polls the data lines to see if the flash is busy
652 // In: address, byte data
654 // Out: 0 = busy, 1 = write or erase complete
658 static int dqpoll(volatile unsigned long address
, volatile unsigned char data
)
660 volatile unsigned char dq7
;
664 return ((READ_FLASH(address
) & 0x80) == dq7
);
670 // Description: Checks to see if erase or write has timed out
676 // Out: 0 = not timed out, 1 = timed out
678 static int timeout(volatile unsigned long address
)
680 return (READ_FLASH(address
) & 0x20) == 0x20;
683 module_init(lcd_init
);
684 module_exit(lcd_exit
);
686 MODULE_AUTHOR("Andrew Bose");
687 MODULE_LICENSE("GPL");