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 systems. 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/mach-rdc/Makefile linux-2.6.19.new/arch/i386/mach-rdc/Makefile
34 --- linux-2.6.19/arch/i386/mach-rdc/Makefile 1970-01-01 01:00:00.000000000 +0100
35 +++ linux-2.6.19.new/arch/i386/mach-rdc/Makefile 2006-12-17 17:13:33.000000000 +0100
38 +# Makefile for the linux kernel.
41 +obj-$(CONFIG_X86_RDC) := led.o
42 diff -urN linux-2.6.19/arch/i386/mach-rdc/led.c linux-2.6.19.new/arch/i386/mach-rdc/led.c
43 --- linux-2.6.19/arch/i386/mach-rdc/led.c 1970-01-01 01:00:00.000000000 +0100
44 +++ linux-2.6.19.new/arch/i386/mach-rdc/led.c 2006-12-17 17:13:33.000000000 +0100
47 + * LED interface for WP3200
49 + * Copyright (C) 2002, by Allen Hung
53 +#include <linux/types.h>
54 +#include <linux/errno.h>
55 +#include <linux/ioport.h>
56 +#include <linux/fcntl.h>
57 +#include <linux/sched.h>
58 +#include <linux/module.h>
59 +#include <linux/proc_fs.h>
60 +#include <linux/init.h>
61 +#include <linux/timer.h>
63 +#include <asm/uaccess.h>
64 +#include <asm/system.h>
65 +#include <linux/reboot.h>
72 + char sts_buf[BUF_LEN+1];
76 +struct LED_DATA led_data[LED_DEV_NUM];
78 +unsigned long ul_ledstat = 0xffffffff;
81 +static struct timer_list blink_timer[LED_DEV_NUM];
82 +// sam 01-30-2004 for watchdog
83 +static struct timer_list watchdog;
85 +static char cmd_buf[BUF_LEN+1];
87 +//------------------------------------------------------------
88 +static long atoh(char *p)
91 + while ( (c = *p++) ) {
92 + if ( c >= '0' && c <= '9' ) v = (v << 4) + c - '0';
93 + else if ( c >= 'a' && c <= 'f' ) v = (v << 4) + c - 'a' + 0xA;
94 + else if ( c >= 'A' && c <= 'F' ) v = (v << 4) + c - 'A' + 0xA;
100 +static int reset_flash_default(void *data)
102 + char *argv[3], *envp[1] = {NULL};
105 + int reset_default=(int) data;
107 + argv[i++] = "/bin/flash";
108 + argv[i++] = "default";
111 + if (call_usermodehelper(argv[0], argv, envp, 1))
112 + printk("failed to Reset to default\n");
113 + machine_restart(0);
117 +// sam for ps 3205U -- using CSx1 (0xb0e00000)
118 +// bit map as following
120 +// POWER WLEN PORT1 PORT2 PORT3
122 +// value 0 --> led on
123 +// value 1 --> led off
128 + #define LED_VAL 0x8000384C // the data ofset of gpio 0~30
130 + #define LED_VAL 0x80003888 // the ofset of gpio 31~58
132 +#define GPIO_VAL 0x8000384C // the offset of gpio 0-30
136 +// sam 1-30-2004 LED status
137 +// bit map as following
138 +// BIT 4:0 Link status -->PHY Link ->1 = up, 0 = down
139 +#define LINK_STATUS (*(unsigned long *)0xb2000014)
140 +#define WATCHDOG_VAL (*(unsigned long *)0xb20000c0)
141 +#define WATCHDOG_PERIOD 500 // unit ms
142 +#define EXPIRE_TIME 300 // unit 10 ms
143 +#define CLEAR_TIMEER 0xffffa000l // bit 14:0 -> count up timer, write 0 to clear
144 +#define ENABLE_WATCHDOG 0x80000000l // bit 31 -> 1 enable , 0 disable watchdog
145 +#define WATCHDOG_SET_TMR_SHIFT 16 // bit 16:30 -> watchdog timer set
149 +//------------------------------------------------------------
150 +static void turn_led(int id, int on)
152 + unsigned long led_bit = 1 << (id);
153 + unsigned long led_bit_val;
155 + // since we define we have 8 led devices and use gpio 53, 55, 57, 58
156 + // which locate at bit21~26, so we rotate left 20bit
159 + led_bit_val = led_bit;
161 + led_bit_val = led_bit << 20;
166 + ul_ledstat|= led_bit_val;
167 + outl(LED_VAL, 0xcf8);
168 + outl(ul_ledstat, 0xcfc);
171 + ul_ledstat &= ~led_bit_val;
172 + outl(LED_VAL, 0xcf8);
173 + outl(ul_ledstat, 0xcfc);
176 + ul_ledstat ^= led_bit_val;
177 + outl(LED_VAL, 0xcf8);
178 + outl(ul_ledstat, 0xcfc);
179 + break; // LED inverse
184 +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
185 +static unsigned int wlan_counter; //Erwin
186 +static void blink_wrapper(u_long id)
188 + u_long sts = led_data[id].sts;
190 + if ( (sts & LED_BLINK_CMD) == LED_BLINK_CMD ) {
191 + unsigned long period = sts & LED_BLINK_PERIOD;
192 + if(period == 0xffff) // BLINK random
194 + blink_timer[id].expires = jiffies + 3*led_flash[wlan_counter%30]*HZ/1000;
198 + blink_timer[id].expires = jiffies + (period * HZ / 1000);
200 + add_timer(&blink_timer[id]);
202 + else if ( sts == LED_ON || sts == LED_OFF )
203 + turn_led(id, sts==LED_ON ? 1 : 0);
205 +//------------------------------------------------------------
206 +static void get_token_str(char *str, char token[][21], int token_num)
210 + for ( t = 0 ; t < token_num ; t++ ) {
211 + memset(token[t], 0, 21);
212 + while ( *str == ' ' ) str++;
213 + for ( i = 0 ; str[i] ; i++ ) {
214 + if ( str[i] == '\t' || str[i] == ' ' || str[i] == '\n' ) break;
215 + if ( i < 20 ) token[t][i] = str[i];
221 +//------------------------------------------------------------
222 +static void set_led_status_by_str(int id)
224 + char token[3][21], *p;
227 + get_token_str(led_data[id].sts_buf, token, 3);
229 + if ( strcmp(token[0], "LED") )
233 + if ( !strcmp(token[1], "ON") )
237 + led_data[id].sts = LED_ON;
239 + else if ( !strcmp(token[1], "OFF") )
244 + else if ( !strcmp(token[1], "BLINK") )
246 + unsigned int period = 0;
248 + if ( !strcmp(p, "FAST") )
249 + period = LED_BLINK_FAST & LED_BLINK_PERIOD;
250 + else if ( !strcmp(p, "SLOW") )
251 + period = LED_BLINK_SLOW & LED_BLINK_PERIOD;
252 + else if ( !strcmp(p, "EXTRA_SLOW") )
253 + period = LED_BLINK_EXTRA_SLOW & LED_BLINK_PERIOD;
254 + else if ( !strcmp(p, "RANDOM") )
255 + period = LED_BLINK_RANDOM & LED_BLINK_PERIOD;
256 + else if ( !strcmp(p, "OFF") )
258 + else if ( *p >= '0' && *p <= '9' )
260 + while ( *p >= '0' && *p <= '9' )
261 + period = period * 10 + (*p++) - '0';
262 +// if ( period > 10000 )
266 + period = LED_BLINK & LED_BLINK_PERIOD;
271 + sprintf(led_data[id].sts_buf, "LED BLINK %d\n", period);
272 + led_data[id].sts = LED_BLINK_CMD + period;
274 + // Set timer for next blink
275 + del_timer(&blink_timer[id]);
276 + blink_timer[id].function = blink_wrapper;
277 + blink_timer[id].data = id;
278 + init_timer(&blink_timer[id]);
280 + blink_timer[id].expires = jiffies + (1000 * HZ / 1000);
282 + add_timer(&blink_timer[id]);
290 + strcpy(led_data[id].sts_buf, "LED OFF\n");
291 + led_data[id].sts = LED_OFF;
295 +//----------------------------------------------------------------------
296 +static int led_read_proc(char *buf, char **start, off_t fpos, int length, int *eof, void *data)
300 + for ( len = dev = 0 ; dev < LED_DEV_NUM ; dev++ ) {
301 + len += sprintf(buf+len, "%d: %s", dev, led_data[dev].sts_buf);
303 + len = strlen(buf) - fpos;
309 + *start = buf + fpos;
310 + if ( len <= length ) *eof = 1;
311 + return len < length ? len : length;
314 +//----------------------------------------------------------------------
315 +static int led_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
317 + int id = (int)file->private_data;
321 + strcpy(led_data[id].sts_buf, "LED ON\n");
322 + set_led_status_by_str(id);
325 + strcpy(led_data[id].sts_buf, "LED OFF\n");
326 + set_led_status_by_str(id);
329 + if ( (cmd & LED_BLINK_CMD) != LED_BLINK_CMD )
334 + case LED_BLINK_FAST:
335 + case LED_BLINK_SLOW:
336 + case LED_BLINK_EXTRA_SLOW:
337 + case LED_BLINK_RANDOM:
338 + sprintf(led_data[id].sts_buf, "LED BLINK %d\n", (int)(cmd & LED_BLINK_PERIOD));
339 + set_led_status_by_str(id);
345 +static int led_open(struct inode *inode, struct file *file)
347 + int led_id = MINOR(inode->i_rdev);
348 +// unsigned long led_bit = 1 << (led_id);
350 + if ( led_id >= LED_DEV_NUM )
353 + GPIO_SEL_I_O &= ~led_bit; // 0 to GPIO
354 + GPIO_O_EN |= (led_bit << 16); // 0 to Output
357 + file->private_data = (void*)led_id;
361 +static long led_read(struct file *file, char *buf, size_t count, loff_t *fpos)
364 + int id = (int)file->private_data;
365 + char *p = led_data[id].sts_buf;
373 + if ( rem > count ) rem = count;
374 + memcpy(buf, p+(*fpos), rem);
379 +static long led_write(struct file *file, char *buf, size_t count, loff_t *fpos)
382 + int id = (int)file->private_data;
383 + char *p = id == REG_MINOR ? cmd_buf : led_data[id].sts_buf;
384 + memset(p, 0, BUF_LEN);
390 + while ( count > 0 )
393 + if ( *fpos < BUF_LEN )
396 + p[len] = c>='a' && c<='z' ? c-'a'+'A' : c;
403 + set_led_status_by_str(id);
410 +static int led_flush(struct file *file)
412 + int id = (int)file->private_data;
414 + if ( file->f_mode & FMODE_WRITE )
416 + set_led_status_by_str(id);
421 +static struct file_operations led_fops = {
429 +//----------------------------------------------
430 +static unsigned long *reg_addr;
431 +static int dump_len;
433 +static int dump_content(char *buf)
438 +static long gpio_read(struct file *file, char *buf, size_t count, loff_t *fpos)
441 + int id = (int)file->private_data;
443 + unsigned long gpio_regval =0;
445 + outl(GPIO_VAL, 0xcf8);
446 + gpio_regval = inl(0xcfc);
447 + gpio_regval |= 0x40;
448 + outl(gpio_regval, 0xcfc); // each in, need out 1 first
449 + gpio_regval = inl(0xcfc);
453 + //printk(KERN_ERR "gpio_id:%d, gpio_regval:%08X\n", id, gpio_regval);
456 + if ( id < GPIO_DEV_NUM ) {
457 + int gpio_bit = 1 << id;
459 + len = sprintf(temp, "%d\n", (gpio_regval & gpio_bit) ? 1 : 0);
462 + len = dump_content(temp);
468 + if ( rem > count ) rem = count;
469 + memcpy(buf, temp+(*fpos), rem);
474 +static int gpio_flush(struct file *file)
479 +static int gpio_open(struct inode *inode, struct file *file)
481 + int id = MINOR(inode->i_rdev);
482 + if ( id >= GPIO_DEV_NUM && id != REG_MINOR )
484 + file->private_data = (void*)id;
488 +static struct file_operations gpio_fops = {
495 +// ---------------------------------------------
496 +// sam 1-30-2004 LAN_STATUS Device
498 +//static unsigned long *reg_addr;
499 +//static int dump_len;
501 +//static int lanSt_content(char *buf)
504 +// unsigned long *p = (unsigned long *)0xb2000014; // PHY_ST
505 +// // j = dump_len/4 + ((dump_len&3) ? 1 : 0);
506 +// len = sprintf(buf, "Reg Addr = %08lX, Value = \n", (unsigned long)p);
507 +// // for ( i = 0 ; i < j ; i++, p++ )
508 +// len += sprintf(buf+len,"%08lX\n", *p);
513 +#define MAC_IOBASE 0xe800 // Eth0
514 +#define PHY_ADDR 1 // For Eth0
515 +#define MII_STATUS_ADDR 1
516 +// where "id" value means which bit of PHY reg 1 we want to check
517 +static long lanSt_read(struct file *file, char *buf, size_t count, loff_t *fpos)
520 +// unsigned long *p = (unsigned long *)0xb2000014; // PHY_ST
521 + unsigned short status;
522 + unsigned int i = 0;
523 + int id = (int)file->private_data;
526 + outw(0x2000 + MII_STATUS_ADDR + (PHY_ADDR << 8), MAC_IOBASE + 0x20);
527 + do{}while( (i++ < 2048) && (inw(MAC_IOBASE+0x20) & 0x2000) );
529 + status = inw(MAC_IOBASE + 0x24);
532 + //printk(KERN_ERR "PHY REG1 Status:%04x\n", status );
535 + if ( id < LAN_DEV_NUM ) {
536 + unsigned long lanSt_bit = 1 << id;
537 +// len = lanSt_content(temp);
538 + len = sprintf(temp, "%d\n",(status & lanSt_bit) ? 1 : 0);
542 + len = sprintf(temp, "-1\n");
549 + if ( rem > count ) rem = count;
550 + memcpy(buf, temp+(*fpos), rem);
555 +static int lanSt_flush(struct file *file)
560 +static int lanSt_open(struct inode *inode, struct file *file)
562 + int id = MINOR(inode->i_rdev);
563 + if ( id >= LAN_DEV_NUM && id != REG_MINOR )
565 + file->private_data = (void*)id;
569 +static struct file_operations lanSt_fops = {
572 + flush: lanSt_flush,
576 +//----------------------------------------------
577 +static int SwResetPress = 0;
578 +static int SwResetCounter = 0;
579 +static int RebootFlag = 0;
580 +static void watchdog_wrapper(unsigned int period)
582 + // { RexHua add for restore default, by press SwReset 5 second, 2 sec to restart
586 + outl(GPIO_VAL, 0xcf8);
589 + outl(reg, 0xcfc); // each in, need out 1 first
592 + if( (reg & 0x40) == 0)
594 + if(SwResetPress == 0)
597 + strcpy(led_data[15].sts_buf, "LED BLINK 500\n" );
598 + set_led_status_by_str(15);
601 + printk("SwReset press!\n");
608 + strcpy(led_data[15].sts_buf, "LED ON\n" );
609 + set_led_status_by_str(15);
613 + if(RebootFlag == 1)
614 + machine_restart(0);
617 + if(SwResetPress == 1)
619 + if(SwResetCounter > 10)
622 +// kernel_thread(reset_flash_default, 1, SIGCHLD);
623 + reset_flash_default(1);
626 + else if(SwResetCounter == 3)
629 + strcpy(led_data[15].sts_buf, "LED BLINK 100\n" );
630 + set_led_status_by_str(15);
637 + // clear timer count
638 + outl(0x80003844, 0xcf8);
639 + outl(0x00800080, 0xcfc); // enable watchdog and set the timeout = 1.34s
640 + //printk(KERN_ERR "wdt\n" );
641 + watchdog.expires = jiffies + (period * HZ / 1000);
642 + add_timer(&watchdog);
645 +//----------------------------------------------
646 +static int init_status;
648 +#define INIT_REGION 0x01
649 +#define INIT_LED_REGISTER 0x02
650 +#define INIT_LED_PROC_READ 0x04
651 +#define INIT_GPIO_REGISTER 0x08
652 +// sam 1-30-2004 LAN_STATUS
653 +#define INIT_LAN_STATUS_REGISTER 0x10
654 +#define INIT_WATCHDOG_REGISTER 0x20
656 +static void led_exit(void)
659 + for ( id = 0 ; id < LED_DEV_NUM ; id++ ) {
660 + del_timer(&blink_timer[id]);
663 + if ( init_status & INIT_LED_PROC_READ )
664 + remove_proc_entry("driver/led", NULL);
666 + if ( init_status & INIT_LED_REGISTER )
667 + unregister_chrdev(LED_MAJOR, "led");
669 + if ( init_status & INIT_GPIO_REGISTER )
670 + unregister_chrdev(GPIO_MAJOR, "gpio");
673 + if( init_status & INIT_LAN_STATUS_REGISTER )
674 + unregister_chrdev(LAN_STATUS_MAJOR, "lanSt");
676 + if( init_status & INIT_WATCHDOG_REGISTER)
677 + del_timer(&watchdog);
684 +static int __init led_init(void)
686 + int result, id, i, j;
690 + //----- register device (LED)-------------------------
693 + result = register_chrdev(LED_MAJOR, "led", &led_fops);
694 + if ( result < 0 ) {
695 + printk(KERN_ERR "led: can't register char device\n" );
699 + init_status |= INIT_LED_REGISTER;
700 + //----- register device (GPIO)-------------------------
701 + result = register_chrdev(GPIO_MAJOR, "gpio", &gpio_fops);
702 + if ( result < 0 ) {
703 + printk(KERN_ERR "gpio: can't register char device\n" );
707 + init_status |= INIT_GPIO_REGISTER;
709 + // sam 1-30-2004 LAN Status
710 + // ----- register device (LAN_STATUS)-------------------
712 + //--> sam 5-1802995
714 + result = register_chrdev(LAN_STATUS_MAJOR, "lanSt", &lanSt_fops);
715 + if ( result < 0 ) {
716 + printk(KERN_ERR "lanSt: can't register char device\n" );
720 + init_status |= INIT_LAN_STATUS_REGISTER;
724 + // -----------init watchdog timer-------------------------
725 + //del_timer(&blink_timer[id]);
727 + outl(0x80003840, 0xcf8);
729 + reg |= 0x1600; // ensable SRC bit
732 + outl(0x80003848, 0xcf8);
734 + reg |= 0x18040; // enable GPIO, PowerLED:15, WLAN_LED0:16, SwReset:6
737 + outl(0x8000384c, 0xcf8);
739 + reg |= 0x40; // output SwReset:6 1, Set SwReset as Input
743 + //reg = inl(0xcfc);
744 + //printk(KERN_ERR "REG40:%08X\n", reg);
746 + outl(0x80003844, 0xcf8);
747 + outl(0x00800080, 0xcfc); // enable watchdog and set the timeout = 1.34s
749 + watchdog.function = watchdog_wrapper;
750 + watchdog.data = WATCHDOG_PERIOD;
751 + init_timer(&watchdog);
752 + watchdog.expires = jiffies + (WATCHDOG_PERIOD * HZ / 1000);
753 + add_timer(&watchdog);
754 + init_status |= INIT_WATCHDOG_REGISTER;
757 + //------ read proc -------------------
758 + if ( !create_proc_read_entry("driver/led", 0, 0, led_read_proc, NULL) ) {
759 + printk(KERN_ERR "led: can't create /proc/driver/led\n");
763 + init_status |= INIT_LED_PROC_READ;
764 + //------------------------------
765 +// reg_addr = (unsigned long *)0xB4000000;
768 + for ( id = 0 ; id < LED_DEV_NUM ; id++ ) {
769 + strcpy(led_data[id].sts_buf, "LED ON\n" );
770 + set_led_status_by_str(id);
773 +// for (i = 0; i < 0xffff; i++)
774 +// for (j = 0; j < 0x6000; j++);
776 +/* sam 5-18-2005 remark
777 + for ( id = 0 ; id < LED_DEV_NUM ; id++ ) {
778 + strcpy(led_data[id].sts_buf, "LED ON\n" );
779 + set_led_status_by_str(id);
782 + printk(KERN_INFO "LED & GPIO & LAN Status Driver LED_VERSION \n");
786 +module_init(led_init);
787 +module_exit(led_exit);
789 diff -urN linux-2.6.19/arch/i386/mach-rdc/led.h linux-2.6.19.new/arch/i386/mach-rdc/led.h
790 --- linux-2.6.19/arch/i386/mach-rdc/led.h 1970-01-01 01:00:00.000000000 +0100
791 +++ linux-2.6.19.new/arch/i386/mach-rdc/led.h 2006-12-17 17:13:33.000000000 +0100
793 +#ifndef _LED_H_INCLUDED
794 +#define _LED_H_INCLUDED
796 +#include <linux/autoconf.h>
798 +#define LED_VERSION "v1.0"
799 +#define LED_MAJOR 166
800 +#define LED_DEV_NUM 32
801 +#define LED_GPIO_START 1
802 +#define GPIO_MAJOR 167
803 +#define GPIO_DEV_NUM 32
804 +#define REG_MINOR 128
805 +// sam 1-30-2004 for LAN_STATUS
806 +#define LAN_STATUS_MAJOR 168
807 +#define LAN_DEV_NUM 5
810 +//#define GPIO_IO_BASE 0xB4002480
811 +//#define GPIO_IO_BASE ((unsigned long)0xb20000b8)
812 +//#define GPIO_IO_EXTENT 0x40
814 +#define LED_ON 0x010000
815 +#define LED_OFF 0x020000
816 +#define LED_BLINK_CMD 0x030000
817 +#define LED_BLINK_PERIOD 0x00FFFF
818 +#define LED_BLINK (LED_BLINK_CMD|1000)
819 +#define LED_BLINK_FAST (LED_BLINK_CMD|250)
820 +#define LED_BLINK_SLOW (LED_BLINK_CMD|500)
821 +#define LED_BLINK_EXTRA_SLOW (LED_BLINK_CMD|2000)
822 +#define LED_BLINK_RANDOM (LED_BLINK_CMD|0xffff)