1 diff -urN linux-2.6.17/arch/i386/Kconfig linux-2.6.17.new/arch/i386/Kconfig
2 --- linux-2.6.17/arch/i386/Kconfig 2006-06-18 03:49:35.000000000 +0200
3 +++ linux-2.6.17.new/arch/i386/Kconfig 2006-10-07 22:33:09.000000000 +0200
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 ther 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.17/arch/i386/kernel/time.c linux-2.6.17.new/arch/i386/kernel/time.c
20 --- linux-2.6.17/arch/i386/kernel/time.c 2006-06-18 03:49:35.000000000 +0200
21 +++ linux-2.6.17.new/arch/i386/kernel/time.c 2006-10-07 22:23:05.000000000 +0200
26 - xtime.tv_sec = get_cmos_time();
27 + /* RDC board does not have CMOS */
29 xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
30 set_normalized_timespec(&wall_to_monotonic,
31 -xtime.tv_sec, -xtime.tv_nsec);
32 diff -urN linux-2.6.17/arch/i386/mach-rdc/led.c linux-2.6.17.new/arch/i386/mach-rdc/led.c
33 --- linux-2.6.17/arch/i386/mach-rdc/led.c 1970-01-01 01:00:00.000000000 +0100
34 +++ linux-2.6.17.new/arch/i386/mach-rdc/led.c 2006-10-07 23:55:59.000000000 +0200
37 + * LED interface for WP3200
39 + * Copyright (C) 2002, by Allen Hung
43 +#include <linux/types.h>
44 +#include <linux/errno.h>
45 +#include <linux/ioport.h>
46 +#include <linux/fcntl.h>
47 +#include <linux/sched.h>
48 +#include <linux/module.h>
49 +#include <linux/proc_fs.h>
50 +#include <linux/init.h>
51 +#include <linux/timer.h>
53 +#include <asm/uaccess.h>
54 +#include <asm/system.h>
55 +#include <linux/reboot.h>
62 + char sts_buf[BUF_LEN+1];
66 +struct LED_DATA led_data[LED_DEV_NUM];
68 +unsigned long ul_ledstat = 0xffffffff;
71 +static struct timer_list blink_timer[LED_DEV_NUM];
72 +// sam 01-30-2004 for watchdog
73 +static struct timer_list watchdog;
75 +static char cmd_buf[BUF_LEN+1];
77 +//------------------------------------------------------------
78 +static long atoh(char *p)
81 + while ( (c = *p++) ) {
82 + if ( c >= '0' && c <= '9' ) v = (v << 4) + c - '0';
83 + else if ( c >= 'a' && c <= 'f' ) v = (v << 4) + c - 'a' + 0xA;
84 + else if ( c >= 'A' && c <= 'F' ) v = (v << 4) + c - 'A' + 0xA;
90 +static int reset_flash_default(void *data)
92 + char *argv[3], *envp[1] = {NULL};
95 + int reset_default=(int) data;
97 + argv[i++] = "/bin/flash";
98 + argv[i++] = "default";
101 + if (call_usermodehelper(argv[0], argv, envp, 1))
102 + printk("failed to Reset to default\n");
103 + machine_restart(0);
107 +// sam for ps 3205U -- using CSx1 (0xb0e00000)
108 +// bit map as following
110 +// POWER WLEN PORT1 PORT2 PORT3
112 +// value 0 --> led on
113 +// value 1 --> led off
118 + #define LED_VAL 0x8000384C // the data ofset of gpio 0~30
120 + #define LED_VAL 0x80003888 // the ofset of gpio 31~58
122 +#define GPIO_VAL 0x8000384C // the offset of gpio 0-30
126 +// sam 1-30-2004 LED status
127 +// bit map as following
128 +// BIT 4:0 Link status -->PHY Link ->1 = up, 0 = down
129 +#define LINK_STATUS (*(unsigned long *)0xb2000014)
130 +#define WATCHDOG_VAL (*(unsigned long *)0xb20000c0)
131 +#define WATCHDOG_PERIOD 500 // unit ms
132 +#define EXPIRE_TIME 300 // unit 10 ms
133 +#define CLEAR_TIMEER 0xffffa000l // bit 14:0 -> count up timer, write 0 to clear
134 +#define ENABLE_WATCHDOG 0x80000000l // bit 31 -> 1 enable , 0 disable watchdog
135 +#define WATCHDOG_SET_TMR_SHIFT 16 // bit 16:30 -> watchdog timer set
139 +//------------------------------------------------------------
140 +static void turn_led(int id, int on)
142 + unsigned long led_bit = 1 << (id);
143 + unsigned long led_bit_val;
145 + // since we define we have 8 led devices and use gpio 53, 55, 57, 58
146 + // which locate at bit21~26, so we rotate left 20bit
149 + led_bit_val = led_bit;
151 + led_bit_val = led_bit << 20;
156 + ul_ledstat|= led_bit_val;
157 + outl(LED_VAL, 0xcf8);
158 + outl(ul_ledstat, 0xcfc);
161 + ul_ledstat &= ~led_bit_val;
162 + outl(LED_VAL, 0xcf8);
163 + outl(ul_ledstat, 0xcfc);
166 + ul_ledstat ^= led_bit_val;
167 + outl(LED_VAL, 0xcf8);
168 + outl(ul_ledstat, 0xcfc);
169 + break; // LED inverse
174 +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
175 +static unsigned int wlan_counter; //Erwin
176 +static void blink_wrapper(u_long id)
178 + u_long sts = led_data[id].sts;
180 + if ( (sts & LED_BLINK_CMD) == LED_BLINK_CMD ) {
181 + unsigned long period = sts & LED_BLINK_PERIOD;
182 + if(period == 0xffff) // BLINK random
184 + blink_timer[id].expires = jiffies + 3*led_flash[wlan_counter%30]*HZ/1000;
188 + blink_timer[id].expires = jiffies + (period * HZ / 1000);
190 + add_timer(&blink_timer[id]);
192 + else if ( sts == LED_ON || sts == LED_OFF )
193 + turn_led(id, sts==LED_ON ? 1 : 0);
195 +//------------------------------------------------------------
196 +static void get_token_str(char *str, char token[][21], int token_num)
200 + for ( t = 0 ; t < token_num ; t++ ) {
201 + memset(token[t], 0, 21);
202 + while ( *str == ' ' ) str++;
203 + for ( i = 0 ; str[i] ; i++ ) {
204 + if ( str[i] == '\t' || str[i] == ' ' || str[i] == '\n' ) break;
205 + if ( i < 20 ) token[t][i] = str[i];
211 +//------------------------------------------------------------
212 +static void set_led_status_by_str(int id)
214 + char token[3][21], *p;
217 + get_token_str(led_data[id].sts_buf, token, 3);
219 + if ( strcmp(token[0], "LED") )
223 + if ( !strcmp(token[1], "ON") )
227 + led_data[id].sts = LED_ON;
229 + else if ( !strcmp(token[1], "OFF") )
234 + else if ( !strcmp(token[1], "BLINK") )
236 + unsigned int period = 0;
238 + if ( !strcmp(p, "FAST") )
239 + period = LED_BLINK_FAST & LED_BLINK_PERIOD;
240 + else if ( !strcmp(p, "SLOW") )
241 + period = LED_BLINK_SLOW & LED_BLINK_PERIOD;
242 + else if ( !strcmp(p, "EXTRA_SLOW") )
243 + period = LED_BLINK_EXTRA_SLOW & LED_BLINK_PERIOD;
244 + else if ( !strcmp(p, "RANDOM") )
245 + period = LED_BLINK_RANDOM & LED_BLINK_PERIOD;
246 + else if ( !strcmp(p, "OFF") )
248 + else if ( *p >= '0' && *p <= '9' )
250 + while ( *p >= '0' && *p <= '9' )
251 + period = period * 10 + (*p++) - '0';
252 +// if ( period > 10000 )
256 + period = LED_BLINK & LED_BLINK_PERIOD;
261 + sprintf(led_data[id].sts_buf, "LED BLINK %d\n", period);
262 + led_data[id].sts = LED_BLINK_CMD + period;
264 + // Set timer for next blink
265 + del_timer(&blink_timer[id]);
266 + blink_timer[id].function = blink_wrapper;
267 + blink_timer[id].data = id;
268 + init_timer(&blink_timer[id]);
270 + blink_timer[id].expires = jiffies + (1000 * HZ / 1000);
272 + add_timer(&blink_timer[id]);
280 + strcpy(led_data[id].sts_buf, "LED OFF\n");
281 + led_data[id].sts = LED_OFF;
285 +//----------------------------------------------------------------------
286 +static int led_read_proc(char *buf, char **start, off_t fpos, int length, int *eof, void *data)
290 + for ( len = dev = 0 ; dev < LED_DEV_NUM ; dev++ ) {
291 + len += sprintf(buf+len, "%d: %s", dev, led_data[dev].sts_buf);
293 + len = strlen(buf) - fpos;
299 + *start = buf + fpos;
300 + if ( len <= length ) *eof = 1;
301 + return len < length ? len : length;
304 +//----------------------------------------------------------------------
305 +static int led_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
307 + int id = (int)file->private_data;
311 + strcpy(led_data[id].sts_buf, "LED ON\n");
312 + set_led_status_by_str(id);
315 + strcpy(led_data[id].sts_buf, "LED OFF\n");
316 + set_led_status_by_str(id);
319 + if ( (cmd & LED_BLINK_CMD) != LED_BLINK_CMD )
324 + case LED_BLINK_FAST:
325 + case LED_BLINK_SLOW:
326 + case LED_BLINK_EXTRA_SLOW:
327 + case LED_BLINK_RANDOM:
328 + sprintf(led_data[id].sts_buf, "LED BLINK %d\n", (int)(cmd & LED_BLINK_PERIOD));
329 + set_led_status_by_str(id);
335 +static int led_open(struct inode *inode, struct file *file)
337 + int led_id = MINOR(inode->i_rdev);
338 +// unsigned long led_bit = 1 << (led_id);
340 + if ( led_id >= LED_DEV_NUM )
343 + GPIO_SEL_I_O &= ~led_bit; // 0 to GPIO
344 + GPIO_O_EN |= (led_bit << 16); // 0 to Output
347 + file->private_data = (void*)led_id;
351 +static long led_read(struct file *file, char *buf, size_t count, loff_t *fpos)
354 + int id = (int)file->private_data;
355 + char *p = led_data[id].sts_buf;
363 + if ( rem > count ) rem = count;
364 + memcpy(buf, p+(*fpos), rem);
369 +static long led_write(struct file *file, char *buf, size_t count, loff_t *fpos)
372 + int id = (int)file->private_data;
373 + char *p = id == REG_MINOR ? cmd_buf : led_data[id].sts_buf;
374 + memset(p, 0, BUF_LEN);
380 + while ( count > 0 )
383 + if ( *fpos < BUF_LEN )
386 + p[len] = c>='a' && c<='z' ? c-'a'+'A' : c;
393 + set_led_status_by_str(id);
400 +static int led_flush(struct file *file)
402 + int id = (int)file->private_data;
404 + if ( file->f_mode & FMODE_WRITE )
406 + set_led_status_by_str(id);
411 +static struct file_operations led_fops = {
419 +//----------------------------------------------
420 +static unsigned long *reg_addr;
421 +static int dump_len;
423 +static int dump_content(char *buf)
428 +static long gpio_read(struct file *file, char *buf, size_t count, loff_t *fpos)
431 + int id = (int)file->private_data;
433 + unsigned long gpio_regval =0;
435 + outl(GPIO_VAL, 0xcf8);
436 + gpio_regval = inl(0xcfc);
437 + gpio_regval |= 0x40;
438 + outl(gpio_regval, 0xcfc); // each in, need out 1 first
439 + gpio_regval = inl(0xcfc);
443 + //printk(KERN_ERR "gpio_id:%d, gpio_regval:%08X\n", id, gpio_regval);
446 + if ( id < GPIO_DEV_NUM ) {
447 + int gpio_bit = 1 << id;
449 + len = sprintf(temp, "%d\n", (gpio_regval & gpio_bit) ? 1 : 0);
452 + len = dump_content(temp);
458 + if ( rem > count ) rem = count;
459 + memcpy(buf, temp+(*fpos), rem);
464 +static int gpio_flush(struct file *file)
469 +static int gpio_open(struct inode *inode, struct file *file)
471 + int id = MINOR(inode->i_rdev);
472 + if ( id >= GPIO_DEV_NUM && id != REG_MINOR )
474 + file->private_data = (void*)id;
478 +static struct file_operations gpio_fops = {
485 +// ---------------------------------------------
486 +// sam 1-30-2004 LAN_STATUS Device
488 +//static unsigned long *reg_addr;
489 +//static int dump_len;
491 +//static int lanSt_content(char *buf)
494 +// unsigned long *p = (unsigned long *)0xb2000014; // PHY_ST
495 +// // j = dump_len/4 + ((dump_len&3) ? 1 : 0);
496 +// len = sprintf(buf, "Reg Addr = %08lX, Value = \n", (unsigned long)p);
497 +// // for ( i = 0 ; i < j ; i++, p++ )
498 +// len += sprintf(buf+len,"%08lX\n", *p);
503 +#define MAC_IOBASE 0xe800 // Eth0
504 +#define PHY_ADDR 1 // For Eth0
505 +#define MII_STATUS_ADDR 1
506 +// where "id" value means which bit of PHY reg 1 we want to check
507 +static long lanSt_read(struct file *file, char *buf, size_t count, loff_t *fpos)
510 +// unsigned long *p = (unsigned long *)0xb2000014; // PHY_ST
511 + unsigned short status;
512 + unsigned int i = 0;
513 + int id = (int)file->private_data;
516 + outw(0x2000 + MII_STATUS_ADDR + (PHY_ADDR << 8), MAC_IOBASE + 0x20);
517 + do{}while( (i++ < 2048) && (inw(MAC_IOBASE+0x20) & 0x2000) );
519 + status = inw(MAC_IOBASE + 0x24);
522 + //printk(KERN_ERR "PHY REG1 Status:%04x\n", status );
525 + if ( id < LAN_DEV_NUM ) {
526 + unsigned long lanSt_bit = 1 << id;
527 +// len = lanSt_content(temp);
528 + len = sprintf(temp, "%d\n",(status & lanSt_bit) ? 1 : 0);
532 + len = sprintf(temp, "-1\n");
539 + if ( rem > count ) rem = count;
540 + memcpy(buf, temp+(*fpos), rem);
545 +static int lanSt_flush(struct file *file)
550 +static int lanSt_open(struct inode *inode, struct file *file)
552 + int id = MINOR(inode->i_rdev);
553 + if ( id >= LAN_DEV_NUM && id != REG_MINOR )
555 + file->private_data = (void*)id;
559 +static struct file_operations lanSt_fops = {
562 + flush: lanSt_flush,
566 +//----------------------------------------------
567 +static int SwResetPress = 0;
568 +static int SwResetCounter = 0;
569 +static int RebootFlag = 0;
570 +static void watchdog_wrapper(unsigned int period)
572 + // { RexHua add for restore default, by press SwReset 5 second, 2 sec to restart
576 + outl(GPIO_VAL, 0xcf8);
579 + outl(reg, 0xcfc); // each in, need out 1 first
582 + if( (reg & 0x40) == 0)
584 + if(SwResetPress == 0)
587 + strcpy(led_data[15].sts_buf, "LED BLINK 500\n" );
588 + set_led_status_by_str(15);
591 + printk("SwReset press!\n");
598 + strcpy(led_data[15].sts_buf, "LED ON\n" );
599 + set_led_status_by_str(15);
603 + if(RebootFlag == 1)
604 + machine_restart(0);
607 + if(SwResetPress == 1)
609 + if(SwResetCounter > 10)
612 +// kernel_thread(reset_flash_default, 1, SIGCHLD);
613 + reset_flash_default(1);
616 + else if(SwResetCounter == 3)
619 + strcpy(led_data[15].sts_buf, "LED BLINK 100\n" );
620 + set_led_status_by_str(15);
627 + // clear timer count
628 + outl(0x80003844, 0xcf8);
629 + outl(0x00800080, 0xcfc); // enable watchdog and set the timeout = 1.34s
630 + //printk(KERN_ERR "wdt\n" );
631 + watchdog.expires = jiffies + (period * HZ / 1000);
632 + add_timer(&watchdog);
635 +//----------------------------------------------
636 +static int init_status;
638 +#define INIT_REGION 0x01
639 +#define INIT_LED_REGISTER 0x02
640 +#define INIT_LED_PROC_READ 0x04
641 +#define INIT_GPIO_REGISTER 0x08
642 +// sam 1-30-2004 LAN_STATUS
643 +#define INIT_LAN_STATUS_REGISTER 0x10
644 +#define INIT_WATCHDOG_REGISTER 0x20
646 +static void led_exit(void)
649 + for ( id = 0 ; id < LED_DEV_NUM ; id++ ) {
650 + del_timer(&blink_timer[id]);
653 + if ( init_status & INIT_LED_PROC_READ )
654 + remove_proc_entry("driver/led", NULL);
656 + if ( init_status & INIT_LED_REGISTER )
657 + unregister_chrdev(LED_MAJOR, "led");
659 + if ( init_status & INIT_GPIO_REGISTER )
660 + unregister_chrdev(GPIO_MAJOR, "gpio");
663 + if( init_status & INIT_LAN_STATUS_REGISTER )
664 + unregister_chrdev(LAN_STATUS_MAJOR, "lanSt");
666 + if( init_status & INIT_WATCHDOG_REGISTER)
667 + del_timer(&watchdog);
674 +static int __init led_init(void)
676 + int result, id, i, j;
680 + //----- register device (LED)-------------------------
683 + result = register_chrdev(LED_MAJOR, "led", &led_fops);
684 + if ( result < 0 ) {
685 + printk(KERN_ERR "led: can't register char device\n" );
689 + init_status |= INIT_LED_REGISTER;
690 + //----- register device (GPIO)-------------------------
691 + result = register_chrdev(GPIO_MAJOR, "gpio", &gpio_fops);
692 + if ( result < 0 ) {
693 + printk(KERN_ERR "gpio: can't register char device\n" );
697 + init_status |= INIT_GPIO_REGISTER;
699 + // sam 1-30-2004 LAN Status
700 + // ----- register device (LAN_STATUS)-------------------
702 + //--> sam 5-1802995
704 + result = register_chrdev(LAN_STATUS_MAJOR, "lanSt", &lanSt_fops);
705 + if ( result < 0 ) {
706 + printk(KERN_ERR "lanSt: can't register char device\n" );
710 + init_status |= INIT_LAN_STATUS_REGISTER;
714 + // -----------init watchdog timer-------------------------
715 + //del_timer(&blink_timer[id]);
717 + outl(0x80003840, 0xcf8);
719 + reg |= 0x1600; // ensable SRC bit
722 + outl(0x80003848, 0xcf8);
724 + reg |= 0x18040; // enable GPIO, PowerLED:15, WLAN_LED0:16, SwReset:6
727 + outl(0x8000384c, 0xcf8);
729 + reg |= 0x40; // output SwReset:6 1, Set SwReset as Input
733 + //reg = inl(0xcfc);
734 + //printk(KERN_ERR "REG40:%08X\n", reg);
736 + outl(0x80003844, 0xcf8);
737 + outl(0x00800080, 0xcfc); // enable watchdog and set the timeout = 1.34s
739 + watchdog.function = watchdog_wrapper;
740 + watchdog.data = WATCHDOG_PERIOD;
741 + init_timer(&watchdog);
742 + watchdog.expires = jiffies + (WATCHDOG_PERIOD * HZ / 1000);
743 + add_timer(&watchdog);
744 + init_status |= INIT_WATCHDOG_REGISTER;
747 + //------ read proc -------------------
748 + if ( !create_proc_read_entry("driver/led", 0, 0, led_read_proc, NULL) ) {
749 + printk(KERN_ERR "led: can't create /proc/driver/led\n");
753 + init_status |= INIT_LED_PROC_READ;
754 + //------------------------------
755 +// reg_addr = (unsigned long *)0xB4000000;
758 + for ( id = 0 ; id < LED_DEV_NUM ; id++ ) {
759 + strcpy(led_data[id].sts_buf, "LED ON\n" );
760 + set_led_status_by_str(id);
763 +// for (i = 0; i < 0xffff; i++)
764 +// for (j = 0; j < 0x6000; j++);
766 +/* sam 5-18-2005 remark
767 + for ( id = 0 ; id < LED_DEV_NUM ; id++ ) {
768 + strcpy(led_data[id].sts_buf, "LED ON\n" );
769 + set_led_status_by_str(id);
772 + printk(KERN_INFO "LED & GPIO & LAN Status Driver LED_VERSION \n");
776 +module_init(led_init);
777 +module_exit(led_exit);
779 diff -urN linux-2.6.17/arch/i386/mach-rdc/led.h linux-2.6.17.new/arch/i386/mach-rdc/led.h
780 --- linux-2.6.17/arch/i386/mach-rdc/led.h 1970-01-01 01:00:00.000000000 +0100
781 +++ linux-2.6.17.new/arch/i386/mach-rdc/led.h 2006-10-07 22:28:32.000000000 +0200
783 +#ifndef _LED_H_INCLUDED
784 +#define _LED_H_INCLUDED
786 +#include <linux/config.h>
788 +#define LED_VERSION "v1.0"
789 +#define LED_MAJOR 166
790 +#define LED_DEV_NUM 32
791 +#define LED_GPIO_START 1
792 +#define GPIO_MAJOR 167
793 +#define GPIO_DEV_NUM 32
794 +#define REG_MINOR 128
795 +// sam 1-30-2004 for LAN_STATUS
796 +#define LAN_STATUS_MAJOR 168
797 +#define LAN_DEV_NUM 5
800 +//#define GPIO_IO_BASE 0xB4002480
801 +//#define GPIO_IO_BASE ((unsigned long)0xb20000b8)
802 +//#define GPIO_IO_EXTENT 0x40
804 +#define LED_ON 0x010000
805 +#define LED_OFF 0x020000
806 +#define LED_BLINK_CMD 0x030000
807 +#define LED_BLINK_PERIOD 0x00FFFF
808 +#define LED_BLINK (LED_BLINK_CMD|1000)
809 +#define LED_BLINK_FAST (LED_BLINK_CMD|250)
810 +#define LED_BLINK_SLOW (LED_BLINK_CMD|500)
811 +#define LED_BLINK_EXTRA_SLOW (LED_BLINK_CMD|2000)
812 +#define LED_BLINK_RANDOM (LED_BLINK_CMD|0xffff)
815 diff -urN linux-2.6.17/arch/i386/mach-rdc/Makefile linux-2.6.17.new/arch/i386/mach-rdc/Makefile
816 --- linux-2.6.17/arch/i386/mach-rdc/Makefile 1970-01-01 01:00:00.000000000 +0100
817 +++ linux-2.6.17.new/arch/i386/mach-rdc/Makefile 2006-10-07 22:31:19.000000000 +0200
820 +# Makefile for the linux kernel.
823 +obj-$(CONFIG_X86_RDC) := led.o
824 diff -urN linux-2.6.17/arch/i386/Makefile linux-2.6.17.new/arch/i386/Makefile
825 --- linux-2.6.17/arch/i386/Makefile 2006-06-18 03:49:35.000000000 +0200
826 +++ linux-2.6.17.new/arch/i386/Makefile 2006-10-07 23:56:13.000000000 +0200
828 mflags-$(CONFIG_X86_ES7000) := -Iinclude/asm-i386/mach-es7000
829 mcore-$(CONFIG_X86_ES7000) := mach-default
830 core-$(CONFIG_X86_ES7000) := arch/i386/mach-es7000/
831 +# RDC subarch support
832 +mflags-$(CONFIG_X86_RDC) := -Iinclude/asm-i386/mach-generic
833 +mcore-$(CONFIG_X86_RDC) := mach-default
834 +core-$(CONFIG_X86_RDC) := arch/i386/mach-rdc/
836 # default subarch .h files
837 mflags-y += -Iinclude/asm-i386/mach-default