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, unsigned int cmd,
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, unsigned int cmd,
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 = ( display.cursor_address & 0x07F );
138 if(copy_to_user((struct lcd_display*)arg, &display, sizeof(struct lcd_display)))
145 case LCD_Set_Cursor_Pos: {
146 struct lcd_display display;
148 if(copy_from_user(&display, (struct lcd_display*)arg, sizeof(struct lcd_display)))
151 a = (display.cursor_address | kLCD_Addr );
160 case LCD_Get_Cursor: {
161 struct lcd_display display;
165 display.character = LCDReadData;
167 if(copy_to_user((struct lcd_display*)arg, &display, sizeof(struct lcd_display)))
176 case LCD_Set_Cursor:{
177 struct lcd_display display;
179 if(copy_from_user(&display, (struct lcd_display*)arg, sizeof(struct lcd_display)))
184 LCDWriteData( display.character );
212 struct lcd_display display;
215 if(copy_from_user(&display, (struct lcd_display*)arg, sizeof(struct lcd_display)))
224 for (index = 0; index < (display.size1); index++) {
227 LCDWriteData( display.line1[index]);
236 for (index = 0; index < (display.size2); index++) {
239 LCDWriteData( display.line2[index]);
246 struct lcd_display display;
249 for (address = kDD_R00; address <= kDD_R01; address++) {
250 a = (address | kLCD_Addr );
257 display.line1[address] = LCDReadData;
260 display.line1[ 0x27 ] = '\0';
262 for (address = kDD_R10; address <= kDD_R11; address++) {
263 a = (address | kLCD_Addr );
271 display.line2[address - 0x40 ] = LCDReadData;
274 display.line2[ 0x27 ] = '\0';
276 if(copy_to_user((struct lcd_display*)arg, &display,
277 sizeof(struct lcd_display)))
282 // set all GPIO leds to led_display.leds
285 struct lcd_display led_display;
288 if(copy_from_user(&led_display, (struct lcd_display*)arg,
289 sizeof(struct lcd_display)))
292 led_state = led_display.leds;
299 // set only bit led_display.leds
304 struct lcd_display led_display;
307 if(copy_from_user(&led_display, (struct lcd_display*)arg,
308 sizeof(struct lcd_display)))
311 for (i=0;i<(int)led_display.leds;i++)
316 led_state = led_state | bit;
321 // clear only bit led_display.leds
323 case LED_Bit_Clear: {
326 struct lcd_display led_display;
329 if(copy_from_user(&led_display, (struct lcd_display*)arg,
330 sizeof(struct lcd_display)))
333 for (i=0;i<(int)led_display.leds;i++)
338 led_state = led_state & ~bit;
345 button_display.buttons = GPIRead;
346 if(copy_to_user((struct lcd_display*)arg, &button_display, sizeof(struct lcd_display)))
352 button_display.buttons = *((volatile unsigned long *) (0xB0100060) );
353 if(copy_to_user((struct lcd_display*)arg, &button_display, sizeof(struct lcd_display)))
361 /* panel-utils should pass in the desired interface status is wanted for
362 * in "buttons" of the structure. We will set this to non-zero if the
363 * link is in fact up for the requested interface. --DaveM
365 if(copy_from_user(&button_display, (struct lcd_display *)arg, sizeof(button_display)))
367 iface_num = button_display.buttons;
368 #if defined(CONFIG_TULIP) && 0
369 if (iface_num >= 0 &&
370 iface_num < MAX_INTERFACES &&
371 linkcheck_callbacks[iface_num] != NULL) {
372 button_display.buttons =
373 linkcheck_callbacks[iface_num](linkcheck_cookies[iface_num]);
376 button_display.buttons = 0;
378 if(__copy_to_user((struct lcd_display*)arg, &button_display, sizeof(struct lcd_display)))
389 // Chip Erase Sequence
390 WRITE_FLASH( kFlash_Addr1, kFlash_Data1 );
391 WRITE_FLASH( kFlash_Addr2, kFlash_Data2 );
392 WRITE_FLASH( kFlash_Addr1, kFlash_Erase3 );
393 WRITE_FLASH( kFlash_Addr1, kFlash_Data1 );
394 WRITE_FLASH( kFlash_Addr2, kFlash_Data2 );
395 WRITE_FLASH( kFlash_Addr1, kFlash_Erase6 );
397 printk( "Erasing Flash.\n");
399 while ( (!dqpoll(0x00000000,0xFF)) && (!timeout(0x00000000)) ) {
407 if (READ_FLASH(0x07FFF0)==0xFF) { printk("Erase Successful\r\n"); }
408 else if (timeout) { printk("Erase Timed Out\r\n"); }
417 volatile unsigned long burn_addr;
423 struct lcd_display display;
425 if(copy_from_user(&display, (struct lcd_display*)arg, sizeof(struct lcd_display)))
427 rom = (unsigned char *) kmalloc((128),GFP_ATOMIC);
433 printk("Churning and Burning -");
435 for (i=0; i<FLASH_SIZE; i=i+128) {
437 if(copy_from_user(rom, display.RomImage + i, 128))
439 burn_addr = kFlashBase + i;
441 for ( index = 0; index < ( 128 ) ; index++ )
444 WRITE_FLASH( kFlash_Addr1, kFlash_Data1 );
445 WRITE_FLASH( kFlash_Addr2, kFlash_Data2 );
446 WRITE_FLASH( kFlash_Addr1, kFlash_Prog );
447 *((volatile unsigned char *)burn_addr) = (volatile unsigned char) rom[index];
449 while ( (!dqpoll(burn_addr,(volatile unsigned char) rom[index])) && (!timeout(burn_addr)) ) {
453 restore_flags(flags);
454 if ( *((volatile unsigned char *)(burn_addr-1)) == (volatile unsigned char) rom[index-1] ) {
455 } else if (timeout) {
456 printk("Program timed out\r\n");
466 // read the flash all at once
470 unsigned char *user_bytes;
471 volatile unsigned long read_addr;
474 user_bytes = &(((struct lcd_display *)arg)->RomImage[0]);
476 if(!access_ok(VERIFY_WRITE, user_bytes, FLASH_SIZE))
479 printk("Reading Flash");
480 for (i=0; i<FLASH_SIZE; i++) {
481 unsigned char tmp_byte;
482 read_addr = kFlashBase + i;
483 tmp_byte = *((volatile unsigned char *)read_addr);
484 if(__put_user (tmp_byte, &user_bytes[i]))
506 static int lcd_open(struct inode *inode, struct file *file)
514 /* Only RESET or NEXT counts as button pressed */
516 static inline int button_pressed(void)
518 unsigned long buttons = GPIRead;
520 if ( (buttons == BUTTON_Next) || (buttons == BUTTON_Next_B) || (buttons == BUTTON_Reset_B) )
525 /* LED daemon sits on this and we wake him up once a key is pressed. */
527 static int lcd_waiters = 0;
529 static long lcd_read(struct inode *inode, struct file *file, char *buf, unsigned long count)
537 while(((buttons_now = (long)button_pressed()) == 0) &&
538 !(signal_pending(current))) {
539 current->state = TASK_INTERRUPTIBLE;
540 schedule_timeout(2 * HZ);
544 if(signal_pending(current))
550 * The various file operations we support.
553 static struct file_operations lcd_fops = {
559 static struct miscdevice lcd_dev=
570 printk("%s\n", LCD_DRIVER);
571 misc_register(&lcd_dev);
573 /* Check region? Naaah! Just snarf it up. */
574 /* request_region(RTC_PORT(0), RTC_IO_EXTENT, "lcd");*/
578 if ( (data & 0x000000FF) == (0x00) ) {
580 printk("LCD Not Present\n");
584 WRITE_GAL( kGal_DevBank2PReg, kGal_DevBank2Cfg );
585 WRITE_GAL( kGal_DevBank3PReg, kGal_DevBank3Cfg );
595 // Description: Polls the data lines to see if the flash is busy
597 // In: address, byte data
599 // Out: 0 = busy, 1 = write or erase complete
603 int dqpoll( volatile unsigned long address, volatile unsigned char data ) {
605 volatile unsigned char dq7;
609 return ( (READ_FLASH(address) & 0x80) == dq7 );
617 // Description: Checks to see if erase or write has timed out
623 // Out: 0 = not timed out, 1 = timed out
625 int timeout( volatile unsigned long address ) {
628 return ( (READ_FLASH(address) & 0x20) == 0x20 );