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 int lcd_ioctl(struct inode *inode, struct file *file,
37 unsigned int cmd, unsigned long arg);
39 static int lcd_present = 1;
43 #if defined(CONFIG_TULIP) && 0
45 #define MAX_INTERFACES 8
46 static linkcheck_func_t linkcheck_callbacks[MAX_INTERFACES];
47 static void *linkcheck_cookies[MAX_INTERFACES];
49 int lcd_register_linkcheck_func(int iface_num, void *func, void *cookie)
52 iface_num >= MAX_INTERFACES ||
53 linkcheck_callbacks[iface_num] != NULL)
55 linkcheck_callbacks[iface_num] = (linkcheck_func_t) func;
56 linkcheck_cookies[iface_num] = cookie;
61 static int lcd_ioctl(struct inode *inode, struct file *file,
62 unsigned int cmd, unsigned long arg)
64 struct lcd_display button_display;
65 unsigned long address, a;
102 case LCD_Cursor_Left:
108 case LCD_Cursor_Right:
132 case LCD_Get_Cursor_Pos:{
133 struct lcd_display display;
137 display.cursor_address = (LCDReadInst);
138 display.cursor_address =
139 (display.cursor_address & 0x07F);
141 ((struct lcd_display *) arg, &display,
142 sizeof(struct lcd_display)))
149 case LCD_Set_Cursor_Pos:{
150 struct lcd_display display;
153 (&display, (struct lcd_display *) arg,
154 sizeof(struct lcd_display)))
157 a = (display.cursor_address | kLCD_Addr);
166 case LCD_Get_Cursor:{
167 struct lcd_display display;
171 display.character = LCDReadData;
174 ((struct lcd_display *) arg, &display,
175 sizeof(struct lcd_display)))
184 case LCD_Set_Cursor:{
185 struct lcd_display display;
188 (&display, (struct lcd_display *) arg,
189 sizeof(struct lcd_display)))
194 LCDWriteData(display.character);
222 struct lcd_display display;
226 (&display, (struct lcd_display *) arg,
227 sizeof(struct lcd_display)))
236 for (index = 0; index < (display.size1); index++) {
239 LCDWriteData(display.line1[index]);
248 for (index = 0; index < (display.size2); index++) {
251 LCDWriteData(display.line2[index]);
258 struct lcd_display display;
261 for (address = kDD_R00; address <= kDD_R01;
263 a = (address | kLCD_Addr);
270 display.line1[address] = LCDReadData;
273 display.line1[0x27] = '\0';
275 for (address = kDD_R10; address <= kDD_R11;
277 a = (address | kLCD_Addr);
285 display.line2[address - 0x40] =
289 display.line2[0x27] = '\0';
292 ((struct lcd_display *) arg, &display,
293 sizeof(struct lcd_display)))
298 // set all GPIO leds to led_display.leds
301 struct lcd_display led_display;
305 (&led_display, (struct lcd_display *) arg,
306 sizeof(struct lcd_display)))
309 led_state = led_display.leds;
316 // set only bit led_display.leds
321 struct lcd_display led_display;
325 (&led_display, (struct lcd_display *) arg,
326 sizeof(struct lcd_display)))
329 for (i = 0; i < (int) led_display.leds; i++) {
333 led_state = led_state | bit;
338 // clear only bit led_display.leds
343 struct lcd_display led_display;
347 (&led_display, (struct lcd_display *) arg,
348 sizeof(struct lcd_display)))
351 for (i = 0; i < (int) led_display.leds; i++) {
355 led_state = led_state & ~bit;
362 button_display.buttons = GPIRead;
364 ((struct lcd_display *) arg, &button_display,
365 sizeof(struct lcd_display)))
371 button_display.buttons =
372 *((volatile unsigned long *) (0xB0100060));
374 ((struct lcd_display *) arg, &button_display,
375 sizeof(struct lcd_display)))
383 /* panel-utils should pass in the desired interface status is wanted for
384 * in "buttons" of the structure. We will set this to non-zero if the
385 * link is in fact up for the requested interface. --DaveM
388 (&button_display, (struct lcd_display *) arg,
389 sizeof(button_display)))
391 iface_num = button_display.buttons;
392 #if defined(CONFIG_TULIP) && 0
393 if (iface_num >= 0 &&
394 iface_num < MAX_INTERFACES &&
395 linkcheck_callbacks[iface_num] != NULL) {
396 button_display.buttons =
397 linkcheck_callbacks[iface_num]
398 (linkcheck_cookies[iface_num]);
401 button_display.buttons = 0;
404 ((struct lcd_display *) arg, &button_display,
405 sizeof(struct lcd_display)))
416 // Chip Erase Sequence
417 WRITE_FLASH(kFlash_Addr1, kFlash_Data1);
418 WRITE_FLASH(kFlash_Addr2, kFlash_Data2);
419 WRITE_FLASH(kFlash_Addr1, kFlash_Erase3);
420 WRITE_FLASH(kFlash_Addr1, kFlash_Data1);
421 WRITE_FLASH(kFlash_Addr2, kFlash_Data2);
422 WRITE_FLASH(kFlash_Addr1, kFlash_Erase6);
424 printk("Erasing Flash.\n");
426 while ((!dqpoll(0x00000000, 0xFF))
427 && (!timeout(0x00000000))) {
435 if (READ_FLASH(0x07FFF0) == 0xFF) {
436 printk("Erase Successful\r\n");
437 } else if (timeout) {
438 printk("Erase Timed Out\r\n");
448 volatile unsigned long burn_addr;
454 struct lcd_display display;
457 (&display, (struct lcd_display *) arg,
458 sizeof(struct lcd_display)))
460 rom = (unsigned char *) kmalloc((128), GFP_ATOMIC);
466 printk("Churning and Burning -");
468 for (i = 0; i < FLASH_SIZE; i = i + 128) {
471 (rom, display.RomImage + i, 128))
473 burn_addr = kFlashBase + i;
475 for (index = 0; index < (128); index++) {
477 WRITE_FLASH(kFlash_Addr1,
479 WRITE_FLASH(kFlash_Addr2,
481 WRITE_FLASH(kFlash_Addr1,
483 *((volatile unsigned char *)
485 (volatile unsigned char) rom[index];
489 (volatile unsigned char)
491 && (!timeout(burn_addr))) {
495 restore_flags(flags);
497 ((volatile unsigned char *) (burn_addr
499 (volatile unsigned char) rom[index -
501 } else if (timeout) {
502 printk("Program timed out\r\n");
512 // read the flash all at once
516 unsigned char *user_bytes;
517 volatile unsigned long read_addr;
521 &(((struct lcd_display *) arg)->RomImage[0]);
524 (VERIFY_WRITE, user_bytes, FLASH_SIZE))
527 printk("Reading Flash");
528 for (i = 0; i < FLASH_SIZE; i++) {
529 unsigned char tmp_byte;
530 read_addr = kFlashBase + i;
532 *((volatile unsigned char *)
534 if (__put_user(tmp_byte, &user_bytes[i]))
552 static int lcd_open(struct inode *inode, struct file *file)
560 /* Only RESET or NEXT counts as button pressed */
562 static inline int button_pressed(void)
564 unsigned long buttons = GPIRead;
566 if ((buttons == BUTTON_Next) || (buttons == BUTTON_Next_B)
567 || (buttons == BUTTON_Reset_B))
572 /* LED daemon sits on this and we wake him up once a key is pressed. */
574 static int lcd_waiters = 0;
576 static long lcd_read(struct inode *inode, struct file *file, char *buf,
585 while (((buttons_now = (long) button_pressed()) == 0) &&
586 !(signal_pending(current))) {
587 msleep_interruptible(2000);
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");