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>
29 #include <asm/uaccess.h>
30 #include <asm/system.h>
31 #include <linux/delay.h>
35 static int lcd_ioctl(struct inode *inode, struct file *file,
36 unsigned int cmd, unsigned long arg);
38 static int lcd_present = 1;
42 #if defined(CONFIG_TULIP) && 0
44 #define MAX_INTERFACES 8
45 static linkcheck_func_t linkcheck_callbacks[MAX_INTERFACES];
46 static void *linkcheck_cookies[MAX_INTERFACES];
48 int lcd_register_linkcheck_func(int iface_num, void *func, void *cookie)
51 iface_num >= MAX_INTERFACES ||
52 linkcheck_callbacks[iface_num] != NULL)
54 linkcheck_callbacks[iface_num] = (linkcheck_func_t) func;
55 linkcheck_cookies[iface_num] = cookie;
60 static int lcd_ioctl(struct inode *inode, struct file *file,
61 unsigned int cmd, unsigned long arg)
63 struct lcd_display button_display;
64 unsigned long address, a;
101 case LCD_Cursor_Left:
107 case LCD_Cursor_Right:
131 case LCD_Get_Cursor_Pos:{
132 struct lcd_display display;
136 display.cursor_address = (LCDReadInst);
137 display.cursor_address =
138 (display.cursor_address & 0x07F);
140 ((struct lcd_display *) arg, &display,
141 sizeof(struct lcd_display)))
148 case LCD_Set_Cursor_Pos:{
149 struct lcd_display display;
152 (&display, (struct lcd_display *) arg,
153 sizeof(struct lcd_display)))
156 a = (display.cursor_address | kLCD_Addr);
165 case LCD_Get_Cursor:{
166 struct lcd_display display;
170 display.character = LCDReadData;
173 ((struct lcd_display *) arg, &display,
174 sizeof(struct lcd_display)))
183 case LCD_Set_Cursor:{
184 struct lcd_display display;
187 (&display, (struct lcd_display *) arg,
188 sizeof(struct lcd_display)))
193 LCDWriteData(display.character);
221 struct lcd_display display;
225 (&display, (struct lcd_display *) arg,
226 sizeof(struct lcd_display)))
235 for (index = 0; index < (display.size1); index++) {
238 LCDWriteData(display.line1[index]);
247 for (index = 0; index < (display.size2); index++) {
250 LCDWriteData(display.line2[index]);
257 struct lcd_display display;
260 for (address = kDD_R00; address <= kDD_R01;
262 a = (address | kLCD_Addr);
269 display.line1[address] = LCDReadData;
272 display.line1[0x27] = '\0';
274 for (address = kDD_R10; address <= kDD_R11;
276 a = (address | kLCD_Addr);
284 display.line2[address - 0x40] =
288 display.line2[0x27] = '\0';
291 ((struct lcd_display *) arg, &display,
292 sizeof(struct lcd_display)))
297 // set all GPIO leds to led_display.leds
300 struct lcd_display led_display;
304 (&led_display, (struct lcd_display *) arg,
305 sizeof(struct lcd_display)))
308 led_state = led_display.leds;
315 // set only bit led_display.leds
320 struct lcd_display led_display;
324 (&led_display, (struct lcd_display *) arg,
325 sizeof(struct lcd_display)))
328 for (i = 0; i < (int) led_display.leds; i++) {
332 led_state = led_state | bit;
337 // clear only bit led_display.leds
342 struct lcd_display led_display;
346 (&led_display, (struct lcd_display *) arg,
347 sizeof(struct lcd_display)))
350 for (i = 0; i < (int) led_display.leds; i++) {
354 led_state = led_state & ~bit;
361 button_display.buttons = GPIRead;
363 ((struct lcd_display *) arg, &button_display,
364 sizeof(struct lcd_display)))
370 button_display.buttons =
371 *((volatile unsigned long *) (0xB0100060));
373 ((struct lcd_display *) arg, &button_display,
374 sizeof(struct lcd_display)))
382 /* panel-utils should pass in the desired interface status is wanted for
383 * in "buttons" of the structure. We will set this to non-zero if the
384 * link is in fact up for the requested interface. --DaveM
387 (&button_display, (struct lcd_display *) arg,
388 sizeof(button_display)))
390 iface_num = button_display.buttons;
391 #if defined(CONFIG_TULIP) && 0
392 if (iface_num >= 0 &&
393 iface_num < MAX_INTERFACES &&
394 linkcheck_callbacks[iface_num] != NULL) {
395 button_display.buttons =
396 linkcheck_callbacks[iface_num]
397 (linkcheck_cookies[iface_num]);
400 button_display.buttons = 0;
403 ((struct lcd_display *) arg, &button_display,
404 sizeof(struct lcd_display)))
415 // Chip Erase Sequence
416 WRITE_FLASH(kFlash_Addr1, kFlash_Data1);
417 WRITE_FLASH(kFlash_Addr2, kFlash_Data2);
418 WRITE_FLASH(kFlash_Addr1, kFlash_Erase3);
419 WRITE_FLASH(kFlash_Addr1, kFlash_Data1);
420 WRITE_FLASH(kFlash_Addr2, kFlash_Data2);
421 WRITE_FLASH(kFlash_Addr1, kFlash_Erase6);
423 printk("Erasing Flash.\n");
425 while ((!dqpoll(0x00000000, 0xFF))
426 && (!timeout(0x00000000))) {
434 if (READ_FLASH(0x07FFF0) == 0xFF) {
435 printk("Erase Successful\r\n");
436 } else if (timeout) {
437 printk("Erase Timed Out\r\n");
447 volatile unsigned long burn_addr;
453 struct lcd_display display;
456 (&display, (struct lcd_display *) arg,
457 sizeof(struct lcd_display)))
459 rom = (unsigned char *) kmalloc((128), GFP_ATOMIC);
465 printk("Churning and Burning -");
467 for (i = 0; i < FLASH_SIZE; i = i + 128) {
470 (rom, display.RomImage + i, 128))
472 burn_addr = kFlashBase + i;
474 for (index = 0; index < (128); index++) {
476 WRITE_FLASH(kFlash_Addr1,
478 WRITE_FLASH(kFlash_Addr2,
480 WRITE_FLASH(kFlash_Addr1,
482 *((volatile unsigned char *)
484 (volatile unsigned char) rom[index];
488 (volatile unsigned char)
490 && (!timeout(burn_addr))) {
494 restore_flags(flags);
496 ((volatile unsigned char *) (burn_addr
498 (volatile unsigned char) rom[index -
500 } else if (timeout) {
501 printk("Program timed out\r\n");
511 // read the flash all at once
515 unsigned char *user_bytes;
516 volatile unsigned long read_addr;
520 &(((struct lcd_display *) arg)->RomImage[0]);
523 (VERIFY_WRITE, user_bytes, FLASH_SIZE))
526 printk("Reading Flash");
527 for (i = 0; i < FLASH_SIZE; i++) {
528 unsigned char tmp_byte;
529 read_addr = kFlashBase + i;
531 *((volatile unsigned char *)
533 if (__put_user(tmp_byte, &user_bytes[i]))
551 static int lcd_open(struct inode *inode, struct file *file)
559 /* Only RESET or NEXT counts as button pressed */
561 static inline int button_pressed(void)
563 unsigned long buttons = GPIRead;
565 if ((buttons == BUTTON_Next) || (buttons == BUTTON_Next_B)
566 || (buttons == BUTTON_Reset_B))
571 /* LED daemon sits on this and we wake him up once a key is pressed. */
573 static int lcd_waiters = 0;
575 static long lcd_read(struct inode *inode, struct file *file, char *buf,
584 while (((buttons_now = (long) button_pressed()) == 0) &&
585 !(signal_pending(current))) {
586 current->state = TASK_INTERRUPTIBLE;
587 schedule_timeout(2 * HZ);
591 if (signal_pending(current))
597 * The various file operations we support.
600 static struct file_operations lcd_fops = {
606 static struct miscdevice lcd_dev = {
612 static int lcd_init(void)
616 printk("%s\n", LCD_DRIVER);
617 misc_register(&lcd_dev);
619 /* Check region? Naaah! Just snarf it up. */
620 /* request_region(RTC_PORT(0), RTC_IO_EXTENT, "lcd");*/
624 if ((data & 0x000000FF) == (0x00)) {
626 printk("LCD Not Present\n");
629 WRITE_GAL(kGal_DevBank2PReg, kGal_DevBank2Cfg);
630 WRITE_GAL(kGal_DevBank3PReg, kGal_DevBank3Cfg);
636 static void __exit lcd_exit(void)
638 misc_deregister(&lcd_dev);
644 // Description: Polls the data lines to see if the flash is busy
646 // In: address, byte data
648 // Out: 0 = busy, 1 = write or erase complete
652 static int dqpoll(volatile unsigned long address, volatile unsigned char data)
654 volatile unsigned char dq7;
658 return ((READ_FLASH(address) & 0x80) == dq7);
664 // Description: Checks to see if erase or write has timed out
670 // Out: 0 = not timed out, 1 = timed out
672 static int timeout(volatile unsigned long address)
674 return (READ_FLASH(address) & 0x20) == 0x20;
677 module_init(lcd_init);
678 module_exit(lcd_exit);
680 MODULE_AUTHOR("Andrew Bose");
681 MODULE_LICENSE("GPL");