1 diff -urN linux-2.6.19/arch/i386/Kconfig linux-2.6.19.new/arch/i386/Kconfig
2 --- linux-2.6.19/arch/i386/Kconfig 2006-11-29 22:57:37.000000000 +0100
3 +++ linux-2.6.19.new/arch/i386/Kconfig 2006-12-17 17:13:33.000000000 +0100
5 Only choose this option if you have such a system, otherwise you
9 + bool "Support for RDC 3211 boards"
11 + Support for RDC 3211 sustems. Say 'Y' here if the kernel is
12 + supposed to run on an IA-32 RDC R3211 system.
13 + Only choose this option if you have such as system, otherwise you
19 diff -urN linux-2.6.19/arch/i386/Makefile linux-2.6.19.new/arch/i386/Makefile
20 --- linux-2.6.19/arch/i386/Makefile 2006-11-29 22:57:37.000000000 +0100
21 +++ linux-2.6.19.new/arch/i386/Makefile 2006-12-17 17:13:33.000000000 +0100
23 mflags-$(CONFIG_X86_ES7000) := -Iinclude/asm-i386/mach-es7000
24 mcore-$(CONFIG_X86_ES7000) := mach-default
25 core-$(CONFIG_X86_ES7000) := arch/i386/mach-es7000/
26 +# RDC subarch support
27 +mflags-$(CONFIG_X86_RDC) := -Iinclude/asm-i386/mach-generic
28 +mcore-$(CONFIG_X86_RDC) := mach-default
29 +core-$(CONFIG_X86_RDC) := arch/i386/mach-rdc/
31 # default subarch .h files
32 mflags-y += -Iinclude/asm-i386/mach-default
33 diff -urN linux-2.6.19/arch/i386/kernel/time.c linux-2.6.19.new/arch/i386/kernel/time.c
34 --- linux-2.6.19/arch/i386/kernel/time.c 2006-11-29 22:57:37.000000000 +0100
35 +++ linux-2.6.19.new/arch/i386/kernel/time.c 2006-12-17 17:13:10.000000000 +0100
37 static void __init hpet_time_init(void)
40 - ts.tv_sec = get_cmos_time();
41 + /* RDC board does not have CMOS */
43 ts.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
46 diff -urN linux-2.6.19/arch/i386/mach-rdc/Makefile linux-2.6.19.new/arch/i386/mach-rdc/Makefile
47 --- linux-2.6.19/arch/i386/mach-rdc/Makefile 1970-01-01 01:00:00.000000000 +0100
48 +++ linux-2.6.19.new/arch/i386/mach-rdc/Makefile 2006-12-17 17:13:33.000000000 +0100
51 +# Makefile for the linux kernel.
54 +obj-$(CONFIG_X86_RDC) := led.o
55 diff -urN linux-2.6.19/arch/i386/mach-rdc/led.c linux-2.6.19.new/arch/i386/mach-rdc/led.c
56 --- linux-2.6.19/arch/i386/mach-rdc/led.c 1970-01-01 01:00:00.000000000 +0100
57 +++ linux-2.6.19.new/arch/i386/mach-rdc/led.c 2006-12-17 17:13:33.000000000 +0100
60 + * LED interface for WP3200
62 + * Copyright (C) 2002, by Allen Hung
66 +#include <linux/types.h>
67 +#include <linux/errno.h>
68 +#include <linux/ioport.h>
69 +#include <linux/fcntl.h>
70 +#include <linux/sched.h>
71 +#include <linux/module.h>
72 +#include <linux/proc_fs.h>
73 +#include <linux/init.h>
74 +#include <linux/timer.h>
76 +#include <asm/uaccess.h>
77 +#include <asm/system.h>
78 +#include <linux/reboot.h>
85 + char sts_buf[BUF_LEN+1];
89 +struct LED_DATA led_data[LED_DEV_NUM];
91 +unsigned long ul_ledstat = 0xffffffff;
94 +static struct timer_list blink_timer[LED_DEV_NUM];
95 +// sam 01-30-2004 for watchdog
96 +static struct timer_list watchdog;
98 +static char cmd_buf[BUF_LEN+1];
100 +//------------------------------------------------------------
101 +static long atoh(char *p)
104 + while ( (c = *p++) ) {
105 + if ( c >= '0' && c <= '9' ) v = (v << 4) + c - '0';
106 + else if ( c >= 'a' && c <= 'f' ) v = (v << 4) + c - 'a' + 0xA;
107 + else if ( c >= 'A' && c <= 'F' ) v = (v << 4) + c - 'A' + 0xA;
113 +static int reset_flash_default(void *data)
115 + char *argv[3], *envp[1] = {NULL};
118 + int reset_default=(int) data;
120 + argv[i++] = "/bin/flash";
121 + argv[i++] = "default";
124 + if (call_usermodehelper(argv[0], argv, envp, 1))
125 + printk("failed to Reset to default\n");
126 + machine_restart(0);
130 +// sam for ps 3205U -- using CSx1 (0xb0e00000)
131 +// bit map as following
133 +// POWER WLEN PORT1 PORT2 PORT3
135 +// value 0 --> led on
136 +// value 1 --> led off
141 + #define LED_VAL 0x8000384C // the data ofset of gpio 0~30
143 + #define LED_VAL 0x80003888 // the ofset of gpio 31~58
145 +#define GPIO_VAL 0x8000384C // the offset of gpio 0-30
149 +// sam 1-30-2004 LED status
150 +// bit map as following
151 +// BIT 4:0 Link status -->PHY Link ->1 = up, 0 = down
152 +#define LINK_STATUS (*(unsigned long *)0xb2000014)
153 +#define WATCHDOG_VAL (*(unsigned long *)0xb20000c0)
154 +#define WATCHDOG_PERIOD 500 // unit ms
155 +#define EXPIRE_TIME 300 // unit 10 ms
156 +#define CLEAR_TIMEER 0xffffa000l // bit 14:0 -> count up timer, write 0 to clear
157 +#define ENABLE_WATCHDOG 0x80000000l // bit 31 -> 1 enable , 0 disable watchdog
158 +#define WATCHDOG_SET_TMR_SHIFT 16 // bit 16:30 -> watchdog timer set
162 +//------------------------------------------------------------
163 +static void turn_led(int id, int on)
165 + unsigned long led_bit = 1 << (id);
166 + unsigned long led_bit_val;
168 + // since we define we have 8 led devices and use gpio 53, 55, 57, 58
169 + // which locate at bit21~26, so we rotate left 20bit
172 + led_bit_val = led_bit;
174 + led_bit_val = led_bit << 20;
179 + ul_ledstat|= led_bit_val;
180 + outl(LED_VAL, 0xcf8);
181 + outl(ul_ledstat, 0xcfc);
184 + ul_ledstat &= ~led_bit_val;
185 + outl(LED_VAL, 0xcf8);
186 + outl(ul_ledstat, 0xcfc);
189 + ul_ledstat ^= led_bit_val;
190 + outl(LED_VAL, 0xcf8);
191 + outl(ul_ledstat, 0xcfc);
192 + break; // LED inverse
197 +static int led_flash[30]={20,10,100,5,5,150,100,5,5,50,20,50,50,20,60,5,20,10,30,10,5,10,50,2,5,5,5,70,10,50};//Erwin
198 +static unsigned int wlan_counter; //Erwin
199 +static void blink_wrapper(u_long id)
201 + u_long sts = led_data[id].sts;
203 + if ( (sts & LED_BLINK_CMD) == LED_BLINK_CMD ) {
204 + unsigned long period = sts & LED_BLINK_PERIOD;
205 + if(period == 0xffff) // BLINK random
207 + blink_timer[id].expires = jiffies + 3*led_flash[wlan_counter%30]*HZ/1000;
211 + blink_timer[id].expires = jiffies + (period * HZ / 1000);
213 + add_timer(&blink_timer[id]);
215 + else if ( sts == LED_ON || sts == LED_OFF )
216 + turn_led(id, sts==LED_ON ? 1 : 0);
218 +//------------------------------------------------------------
219 +static void get_token_str(char *str, char token[][21], int token_num)
223 + for ( t = 0 ; t < token_num ; t++ ) {
224 + memset(token[t], 0, 21);
225 + while ( *str == ' ' ) str++;
226 + for ( i = 0 ; str[i] ; i++ ) {
227 + if ( str[i] == '\t' || str[i] == ' ' || str[i] == '\n' ) break;
228 + if ( i < 20 ) token[t][i] = str[i];
234 +//------------------------------------------------------------
235 +static void set_led_status_by_str(int id)
237 + char token[3][21], *p;
240 + get_token_str(led_data[id].sts_buf, token, 3);
242 + if ( strcmp(token[0], "LED") )
246 + if ( !strcmp(token[1], "ON") )
250 + led_data[id].sts = LED_ON;
252 + else if ( !strcmp(token[1], "OFF") )
257 + else if ( !strcmp(token[1], "BLINK") )
259 + unsigned int period = 0;
261 + if ( !strcmp(p, "FAST") )
262 + period = LED_BLINK_FAST & LED_BLINK_PERIOD;
263 + else if ( !strcmp(p, "SLOW") )
264 + period = LED_BLINK_SLOW & LED_BLINK_PERIOD;
265 + else if ( !strcmp(p, "EXTRA_SLOW") )
266 + period = LED_BLINK_EXTRA_SLOW & LED_BLINK_PERIOD;
267 + else if ( !strcmp(p, "RANDOM") )
268 + period = LED_BLINK_RANDOM & LED_BLINK_PERIOD;
269 + else if ( !strcmp(p, "OFF") )
271 + else if ( *p >= '0' && *p <= '9' )
273 + while ( *p >= '0' && *p <= '9' )
274 + period = period * 10 + (*p++) - '0';
275 +// if ( period > 10000 )
279 + period = LED_BLINK & LED_BLINK_PERIOD;
284 + sprintf(led_data[id].sts_buf, "LED BLINK %d\n", period);
285 + led_data[id].sts = LED_BLINK_CMD + period;
287 + // Set timer for next blink
288 + del_timer(&blink_timer[id]);
289 + blink_timer[id].function = blink_wrapper;
290 + blink_timer[id].data = id;
291 + init_timer(&blink_timer[id]);
293 + blink_timer[id].expires = jiffies + (1000 * HZ / 1000);
295 + add_timer(&blink_timer[id]);
303 + strcpy(led_data[id].sts_buf, "LED OFF\n");
304 + led_data[id].sts = LED_OFF;
308 +//----------------------------------------------------------------------
309 +static int led_read_proc(char *buf, char **start, off_t fpos, int length, int *eof, void *data)
313 + for ( len = dev = 0 ; dev < LED_DEV_NUM ; dev++ ) {
314 + len += sprintf(buf+len, "%d: %s", dev, led_data[dev].sts_buf);
316 + len = strlen(buf) - fpos;
322 + *start = buf + fpos;
323 + if ( len <= length ) *eof = 1;
324 + return len < length ? len : length;
327 +//----------------------------------------------------------------------
328 +static int led_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
330 + int id = (int)file->private_data;
334 + strcpy(led_data[id].sts_buf, "LED ON\n");
335 + set_led_status_by_str(id);
338 + strcpy(led_data[id].sts_buf, "LED OFF\n");
339 + set_led_status_by_str(id);
342 + if ( (cmd & LED_BLINK_CMD) != LED_BLINK_CMD )
347 + case LED_BLINK_FAST:
348 + case LED_BLINK_SLOW:
349 + case LED_BLINK_EXTRA_SLOW:
350 + case LED_BLINK_RANDOM:
351 + sprintf(led_data[id].sts_buf, "LED BLINK %d\n", (int)(cmd & LED_BLINK_PERIOD));
352 + set_led_status_by_str(id);
358 +static int led_open(struct inode *inode, struct file *file)
360 + int led_id = MINOR(inode->i_rdev);
361 +// unsigned long led_bit = 1 << (led_id);
363 + if ( led_id >= LED_DEV_NUM )
366 + GPIO_SEL_I_O &= ~led_bit; // 0 to GPIO
367 + GPIO_O_EN |= (led_bit << 16); // 0 to Output
370 + file->private_data = (void*)led_id;
374 +static long led_read(struct file *file, char *buf, size_t count, loff_t *fpos)
377 + int id = (int)file->private_data;
378 + char *p = led_data[id].sts_buf;
386 + if ( rem > count ) rem = count;
387 + memcpy(buf, p+(*fpos), rem);
392 +static long led_write(struct file *file, char *buf, size_t count, loff_t *fpos)
395 + int id = (int)file->private_data;
396 + char *p = id == REG_MINOR ? cmd_buf : led_data[id].sts_buf;
397 + memset(p, 0, BUF_LEN);
403 + while ( count > 0 )
406 + if ( *fpos < BUF_LEN )
409 + p[len] = c>='a' && c<='z' ? c-'a'+'A' : c;
416 + set_led_status_by_str(id);
423 +static int led_flush(struct file *file)
425 + int id = (int)file->private_data;
427 + if ( file->f_mode & FMODE_WRITE )
429 + set_led_status_by_str(id);
434 +static struct file_operations led_fops = {
442 +//----------------------------------------------
443 +static unsigned long *reg_addr;
444 +static int dump_len;
446 +static int dump_content(char *buf)
451 +static long gpio_read(struct file *file, char *buf, size_t count, loff_t *fpos)
454 + int id = (int)file->private_data;
456 + unsigned long gpio_regval =0;
458 + outl(GPIO_VAL, 0xcf8);
459 + gpio_regval = inl(0xcfc);
460 + gpio_regval |= 0x40;
461 + outl(gpio_regval, 0xcfc); // each in, need out 1 first
462 + gpio_regval = inl(0xcfc);
466 + //printk(KERN_ERR "gpio_id:%d, gpio_regval:%08X\n", id, gpio_regval);
469 + if ( id < GPIO_DEV_NUM ) {
470 + int gpio_bit = 1 << id;
472 + len = sprintf(temp, "%d\n", (gpio_regval & gpio_bit) ? 1 : 0);
475 + len = dump_content(temp);
481 + if ( rem > count ) rem = count;
482 + memcpy(buf, temp+(*fpos), rem);
487 +static int gpio_flush(struct file *file)
492 +static int gpio_open(struct inode *inode, struct file *file)
494 + int id = MINOR(inode->i_rdev);
495 + if ( id >= GPIO_DEV_NUM && id != REG_MINOR )
497 + file->private_data = (void*)id;
501 +static struct file_operations gpio_fops = {
508 +// ---------------------------------------------
509 +// sam 1-30-2004 LAN_STATUS Device
511 +//static unsigned long *reg_addr;
512 +//static int dump_len;
514 +//static int lanSt_content(char *buf)
517 +// unsigned long *p = (unsigned long *)0xb2000014; // PHY_ST
518 +// // j = dump_len/4 + ((dump_len&3) ? 1 : 0);
519 +// len = sprintf(buf, "Reg Addr = %08lX, Value = \n", (unsigned long)p);
520 +// // for ( i = 0 ; i < j ; i++, p++ )
521 +// len += sprintf(buf+len,"%08lX\n", *p);
526 +#define MAC_IOBASE 0xe800 // Eth0
527 +#define PHY_ADDR 1 // For Eth0
528 +#define MII_STATUS_ADDR 1
529 +// where "id" value means which bit of PHY reg 1 we want to check
530 +static long lanSt_read(struct file *file, char *buf, size_t count, loff_t *fpos)
533 +// unsigned long *p = (unsigned long *)0xb2000014; // PHY_ST
534 + unsigned short status;
535 + unsigned int i = 0;
536 + int id = (int)file->private_data;
539 + outw(0x2000 + MII_STATUS_ADDR + (PHY_ADDR << 8), MAC_IOBASE + 0x20);
540 + do{}while( (i++ < 2048) && (inw(MAC_IOBASE+0x20) & 0x2000) );
542 + status = inw(MAC_IOBASE + 0x24);
545 + //printk(KERN_ERR "PHY REG1 Status:%04x\n", status );
548 + if ( id < LAN_DEV_NUM ) {
549 + unsigned long lanSt_bit = 1 << id;
550 +// len = lanSt_content(temp);
551 + len = sprintf(temp, "%d\n",(status & lanSt_bit) ? 1 : 0);
555 + len = sprintf(temp, "-1\n");
562 + if ( rem > count ) rem = count;
563 + memcpy(buf, temp+(*fpos), rem);
568 +static int lanSt_flush(struct file *file)
573 +static int lanSt_open(struct inode *inode, struct file *file)
575 + int id = MINOR(inode->i_rdev);
576 + if ( id >= LAN_DEV_NUM && id != REG_MINOR )
578 + file->private_data = (void*)id;
582 +static struct file_operations lanSt_fops = {
585 + flush: lanSt_flush,
589 +//----------------------------------------------
590 +static int SwResetPress = 0;
591 +static int SwResetCounter = 0;
592 +static int RebootFlag = 0;
593 +static void watchdog_wrapper(unsigned int period)
595 + // { RexHua add for restore default, by press SwReset 5 second, 2 sec to restart
599 + outl(GPIO_VAL, 0xcf8);
602 + outl(reg, 0xcfc); // each in, need out 1 first
605 + if( (reg & 0x40) == 0)
607 + if(SwResetPress == 0)
610 + strcpy(led_data[15].sts_buf, "LED BLINK 500\n" );
611 + set_led_status_by_str(15);
614 + printk("SwReset press!\n");
621 + strcpy(led_data[15].sts_buf, "LED ON\n" );
622 + set_led_status_by_str(15);
626 + if(RebootFlag == 1)
627 + machine_restart(0);
630 + if(SwResetPress == 1)
632 + if(SwResetCounter > 10)
635 +// kernel_thread(reset_flash_default, 1, SIGCHLD);
636 + reset_flash_default(1);
639 + else if(SwResetCounter == 3)
642 + strcpy(led_data[15].sts_buf, "LED BLINK 100\n" );
643 + set_led_status_by_str(15);
650 + // clear timer count
651 + outl(0x80003844, 0xcf8);
652 + outl(0x00800080, 0xcfc); // enable watchdog and set the timeout = 1.34s
653 + //printk(KERN_ERR "wdt\n" );
654 + watchdog.expires = jiffies + (period * HZ / 1000);
655 + add_timer(&watchdog);
658 +//----------------------------------------------
659 +static int init_status;
661 +#define INIT_REGION 0x01
662 +#define INIT_LED_REGISTER 0x02
663 +#define INIT_LED_PROC_READ 0x04
664 +#define INIT_GPIO_REGISTER 0x08
665 +// sam 1-30-2004 LAN_STATUS
666 +#define INIT_LAN_STATUS_REGISTER 0x10
667 +#define INIT_WATCHDOG_REGISTER 0x20
669 +static void led_exit(void)
672 + for ( id = 0 ; id < LED_DEV_NUM ; id++ ) {
673 + del_timer(&blink_timer[id]);
676 + if ( init_status & INIT_LED_PROC_READ )
677 + remove_proc_entry("driver/led", NULL);
679 + if ( init_status & INIT_LED_REGISTER )
680 + unregister_chrdev(LED_MAJOR, "led");
682 + if ( init_status & INIT_GPIO_REGISTER )
683 + unregister_chrdev(GPIO_MAJOR, "gpio");
686 + if( init_status & INIT_LAN_STATUS_REGISTER )
687 + unregister_chrdev(LAN_STATUS_MAJOR, "lanSt");
689 + if( init_status & INIT_WATCHDOG_REGISTER)
690 + del_timer(&watchdog);
697 +static int __init led_init(void)
699 + int result, id, i, j;
703 + //----- register device (LED)-------------------------
706 + result = register_chrdev(LED_MAJOR, "led", &led_fops);
707 + if ( result < 0 ) {
708 + printk(KERN_ERR "led: can't register char device\n" );
712 + init_status |= INIT_LED_REGISTER;
713 + //----- register device (GPIO)-------------------------
714 + result = register_chrdev(GPIO_MAJOR, "gpio", &gpio_fops);
715 + if ( result < 0 ) {
716 + printk(KERN_ERR "gpio: can't register char device\n" );
720 + init_status |= INIT_GPIO_REGISTER;
722 + // sam 1-30-2004 LAN Status
723 + // ----- register device (LAN_STATUS)-------------------
725 + //--> sam 5-1802995
727 + result = register_chrdev(LAN_STATUS_MAJOR, "lanSt", &lanSt_fops);
728 + if ( result < 0 ) {
729 + printk(KERN_ERR "lanSt: can't register char device\n" );
733 + init_status |= INIT_LAN_STATUS_REGISTER;
737 + // -----------init watchdog timer-------------------------
738 + //del_timer(&blink_timer[id]);
740 + outl(0x80003840, 0xcf8);
742 + reg |= 0x1600; // ensable SRC bit
745 + outl(0x80003848, 0xcf8);
747 + reg |= 0x18040; // enable GPIO, PowerLED:15, WLAN_LED0:16, SwReset:6
750 + outl(0x8000384c, 0xcf8);
752 + reg |= 0x40; // output SwReset:6 1, Set SwReset as Input
756 + //reg = inl(0xcfc);
757 + //printk(KERN_ERR "REG40:%08X\n", reg);
759 + outl(0x80003844, 0xcf8);
760 + outl(0x00800080, 0xcfc); // enable watchdog and set the timeout = 1.34s
762 + watchdog.function = watchdog_wrapper;
763 + watchdog.data = WATCHDOG_PERIOD;
764 + init_timer(&watchdog);
765 + watchdog.expires = jiffies + (WATCHDOG_PERIOD * HZ / 1000);
766 + add_timer(&watchdog);
767 + init_status |= INIT_WATCHDOG_REGISTER;
770 + //------ read proc -------------------
771 + if ( !create_proc_read_entry("driver/led", 0, 0, led_read_proc, NULL) ) {
772 + printk(KERN_ERR "led: can't create /proc/driver/led\n");
776 + init_status |= INIT_LED_PROC_READ;
777 + //------------------------------
778 +// reg_addr = (unsigned long *)0xB4000000;
781 + for ( id = 0 ; id < LED_DEV_NUM ; id++ ) {
782 + strcpy(led_data[id].sts_buf, "LED ON\n" );
783 + set_led_status_by_str(id);
786 +// for (i = 0; i < 0xffff; i++)
787 +// for (j = 0; j < 0x6000; j++);
789 +/* sam 5-18-2005 remark
790 + for ( id = 0 ; id < LED_DEV_NUM ; id++ ) {
791 + strcpy(led_data[id].sts_buf, "LED ON\n" );
792 + set_led_status_by_str(id);
795 + printk(KERN_INFO "LED & GPIO & LAN Status Driver LED_VERSION \n");
799 +module_init(led_init);
800 +module_exit(led_exit);
802 diff -urN linux-2.6.19/arch/i386/mach-rdc/led.h linux-2.6.19.new/arch/i386/mach-rdc/led.h
803 --- linux-2.6.19/arch/i386/mach-rdc/led.h 1970-01-01 01:00:00.000000000 +0100
804 +++ linux-2.6.19.new/arch/i386/mach-rdc/led.h 2006-12-17 17:13:33.000000000 +0100
806 +#ifndef _LED_H_INCLUDED
807 +#define _LED_H_INCLUDED
809 +#include <linux/autoconf.h>
811 +#define LED_VERSION "v1.0"
812 +#define LED_MAJOR 166
813 +#define LED_DEV_NUM 32
814 +#define LED_GPIO_START 1
815 +#define GPIO_MAJOR 167
816 +#define GPIO_DEV_NUM 32
817 +#define REG_MINOR 128
818 +// sam 1-30-2004 for LAN_STATUS
819 +#define LAN_STATUS_MAJOR 168
820 +#define LAN_DEV_NUM 5
823 +//#define GPIO_IO_BASE 0xB4002480
824 +//#define GPIO_IO_BASE ((unsigned long)0xb20000b8)
825 +//#define GPIO_IO_EXTENT 0x40
827 +#define LED_ON 0x010000
828 +#define LED_OFF 0x020000
829 +#define LED_BLINK_CMD 0x030000
830 +#define LED_BLINK_PERIOD 0x00FFFF
831 +#define LED_BLINK (LED_BLINK_CMD|1000)
832 +#define LED_BLINK_FAST (LED_BLINK_CMD|250)
833 +#define LED_BLINK_SLOW (LED_BLINK_CMD|500)
834 +#define LED_BLINK_EXTRA_SLOW (LED_BLINK_CMD|2000)
835 +#define LED_BLINK_RANDOM (LED_BLINK_CMD|0xffff)