Fresh fixes for rdc from sn9, thanks !
[openwrt.git] / target / linux / rdc-2.6 / patches / 000-rdc_fixes.patch
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
4 @@ -180,6 +180,14 @@
5 Only choose this option if you have such a system, otherwise you
6 should say N here.
7
8 +config X86_RDC
9 + bool "Support for RDC 3211 boards"
10 + help
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
14 + should say N here.
15 +
16 endchoice
17
18 config ACPI_SRAT
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
22 @@ -92,6 +92,10 @@
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/
30
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
36 @@ -361,7 +361,8 @@
37 static void __init hpet_time_init(void)
38 {
39 struct timespec ts;
40 - ts.tv_sec = get_cmos_time();
41 + /* RDC board does not have CMOS */
42 + ts.tv_sec = 0;
43 ts.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
44
45 do_settimeofday(&ts);
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
49 @@ -0,0 +1,5 @@
50 +#
51 +# Makefile for the linux kernel.
52 +#
53 +
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
58 @@ -0,0 +1,743 @@
59 +/*
60 + * LED interface for WP3200
61 + *
62 + * Copyright (C) 2002, by Allen Hung
63 + *
64 + */
65 +
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>
75 +#include <asm/io.h>
76 +#include <asm/uaccess.h>
77 +#include <asm/system.h>
78 +#include <linux/reboot.h>
79 +
80 +#include "led.h"
81 +
82 +#define BUF_LEN 30
83 +
84 +struct LED_DATA {
85 + char sts_buf[BUF_LEN+1];
86 + unsigned long sts;
87 +};
88 +
89 +struct LED_DATA led_data[LED_DEV_NUM];
90 +// sam
91 +unsigned long ul_ledstat = 0xffffffff;
92 +
93 +
94 +static struct timer_list blink_timer[LED_DEV_NUM];
95 +// sam 01-30-2004 for watchdog
96 +static struct timer_list watchdog;
97 +// end sam
98 +static char cmd_buf[BUF_LEN+1];
99 +
100 +//------------------------------------------------------------
101 +static long atoh(char *p)
102 +{
103 + long v = 0, c;
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;
108 + else break;
109 + }
110 + return v;
111 +}
112 +
113 +static int reset_flash_default(void *data)
114 +{
115 + char *argv[3], *envp[1] = {NULL};
116 + int i = 0;
117 +
118 + int reset_default=(int) data;
119 +
120 + argv[i++] = "/bin/flash";
121 + argv[i++] = "default";
122 + argv[i] = NULL;
123 + if(reset_default)
124 + if (call_usermodehelper(argv[0], argv, envp, 1))
125 + printk("failed to Reset to default\n");
126 + machine_restart(0);
127 + return 0;
128 +}
129 +
130 +// sam for ps 3205U -- using CSx1 (0xb0e00000)
131 +// bit map as following
132 +// BIT 1 2 3 4 5
133 +// POWER WLEN PORT1 PORT2 PORT3
134 +//
135 +// value 0 --> led on
136 +// value 1 --> led off
137 +
138 +#define _ROUTER_
139 +
140 +#ifdef _ROUTER_
141 + #define LED_VAL 0x8000384C // the data ofset of gpio 0~30
142 +#else
143 + #define LED_VAL 0x80003888 // the ofset of gpio 31~58
144 +#endif
145 +#define GPIO_VAL 0x8000384C // the offset of gpio 0-30
146 +
147 +
148 +
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
159 +// end sam
160 +
161 +
162 +//------------------------------------------------------------
163 +static void turn_led(int id, int on)
164 +{
165 + unsigned long led_bit = 1 << (id);
166 + unsigned long led_bit_val;
167 +
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
170 +
171 +#ifdef _ROUTER_
172 + led_bit_val = led_bit;
173 +#else
174 + led_bit_val = led_bit << 20;
175 +#endif
176 +
177 + switch ( on ) {
178 + case 0:
179 + ul_ledstat|= led_bit_val;
180 + outl(LED_VAL, 0xcf8);
181 + outl(ul_ledstat, 0xcfc);
182 + break; // LED OFF
183 + case 1:
184 + ul_ledstat &= ~led_bit_val;
185 + outl(LED_VAL, 0xcf8);
186 + outl(ul_ledstat, 0xcfc);
187 + break; // LED ON
188 + case 2:
189 + ul_ledstat ^= led_bit_val;
190 + outl(LED_VAL, 0xcf8);
191 + outl(ul_ledstat, 0xcfc);
192 + break; // LED inverse
193 + }
194 +}
195 +
196 +
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)
200 +{
201 + u_long sts = led_data[id].sts;
202 +
203 + if ( (sts & LED_BLINK_CMD) == LED_BLINK_CMD ) {
204 + unsigned long period = sts & LED_BLINK_PERIOD;
205 + if(period == 0xffff) // BLINK random
206 + {
207 + blink_timer[id].expires = jiffies + 3*led_flash[wlan_counter%30]*HZ/1000;
208 + wlan_counter++;
209 + }
210 + else
211 + blink_timer[id].expires = jiffies + (period * HZ / 1000);
212 + turn_led(id, 2);
213 + add_timer(&blink_timer[id]);
214 + }
215 + else if ( sts == LED_ON || sts == LED_OFF )
216 + turn_led(id, sts==LED_ON ? 1 : 0);
217 +}
218 +//------------------------------------------------------------
219 +static void get_token_str(char *str, char token[][21], int token_num)
220 +{
221 + int t, i;
222 +
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];
229 + }
230 + str += i;
231 + }
232 +}
233 +
234 +//------------------------------------------------------------
235 +static void set_led_status_by_str(int id)
236 +{
237 + char token[3][21], *p;
238 +
239 +
240 + get_token_str(led_data[id].sts_buf, token, 3);
241 +
242 + if ( strcmp(token[0], "LED") )
243 + {
244 + goto set_led_off;
245 + }
246 + if ( !strcmp(token[1], "ON") )
247 + {
248 +
249 + turn_led(id, 1);
250 + led_data[id].sts = LED_ON;
251 + }
252 + else if ( !strcmp(token[1], "OFF") )
253 + {
254 +
255 + goto set_led_off;
256 + }
257 + else if ( !strcmp(token[1], "BLINK") )
258 + {
259 + unsigned int period = 0;
260 + p = token[2];
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") )
270 + goto set_led_off;
271 + else if ( *p >= '0' && *p <= '9' )
272 + {
273 + while ( *p >= '0' && *p <= '9' )
274 + period = period * 10 + (*p++) - '0';
275 +// if ( period > 10000 )
276 +// period = 10000;
277 + }
278 + else
279 + period = LED_BLINK & LED_BLINK_PERIOD;
280 +
281 + if ( period == 0 )
282 + goto set_led_off;
283 +
284 + sprintf(led_data[id].sts_buf, "LED BLINK %d\n", period);
285 + led_data[id].sts = LED_BLINK_CMD + period;
286 + turn_led(id, 2);
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]);
292 +
293 + blink_timer[id].expires = jiffies + (1000 * HZ / 1000);
294 +
295 + add_timer(&blink_timer[id]);
296 + }
297 + else
298 + {
299 + goto set_led_off;
300 + }
301 + return;
302 + set_led_off:
303 + strcpy(led_data[id].sts_buf, "LED OFF\n");
304 + led_data[id].sts = LED_OFF;
305 + turn_led(id, 0);
306 +}
307 +
308 +//----------------------------------------------------------------------
309 +static int led_read_proc(char *buf, char **start, off_t fpos, int length, int *eof, void *data)
310 +{
311 + int len, dev;
312 +
313 + for ( len = dev = 0 ; dev < LED_DEV_NUM ; dev++ ) {
314 + len += sprintf(buf+len, "%d: %s", dev, led_data[dev].sts_buf);
315 + }
316 + len = strlen(buf) - fpos;
317 + if ( len <= 0 ) {
318 + *start = buf;
319 + *eof = 1;
320 + return 0;
321 + }
322 + *start = buf + fpos;
323 + if ( len <= length ) *eof = 1;
324 + return len < length ? len : length;
325 +}
326 +
327 +//----------------------------------------------------------------------
328 +static int led_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
329 +{
330 + int id = (int)file->private_data;
331 +
332 + switch ( cmd ) {
333 + case LED_ON:
334 + strcpy(led_data[id].sts_buf, "LED ON\n");
335 + set_led_status_by_str(id);
336 + break;
337 + case LED_OFF:
338 + strcpy(led_data[id].sts_buf, "LED OFF\n");
339 + set_led_status_by_str(id);
340 + break;
341 + default:
342 + if ( (cmd & LED_BLINK_CMD) != LED_BLINK_CMD )
343 + {
344 + break;
345 + }
346 + case LED_BLINK:
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);
353 + break;
354 + }
355 + return 0;
356 +}
357 +
358 +static int led_open(struct inode *inode, struct file *file)
359 +{
360 + int led_id = MINOR(inode->i_rdev);
361 +// unsigned long led_bit = 1 << (led_id);
362 +
363 + if ( led_id >= LED_DEV_NUM )
364 + return -ENODEV;
365 +/* sam 12/02/2003
366 + GPIO_SEL_I_O &= ~led_bit; // 0 to GPIO
367 + GPIO_O_EN |= (led_bit << 16); // 0 to Output
368 +*/
369 +
370 + file->private_data = (void*)led_id;
371 + return 0;
372 +}
373 +
374 +static long led_read(struct file *file, char *buf, size_t count, loff_t *fpos)
375 +{
376 + int rem, len;
377 + int id = (int)file->private_data;
378 + char *p = led_data[id].sts_buf;
379 +
380 + len = strlen(p);
381 + rem = len - *fpos;
382 + if ( rem <= 0 ) {
383 + *fpos = len;
384 + return 0;
385 + }
386 + if ( rem > count ) rem = count;
387 + memcpy(buf, p+(*fpos), rem);
388 + *fpos += rem;
389 + return rem;
390 +}
391 +
392 +static long led_write(struct file *file, char *buf, size_t count, loff_t *fpos)
393 +{
394 + int len;
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);
398 +
399 + p += *fpos;
400 + len = 0;
401 +
402 +
403 + while ( count > 0 )
404 + {
405 +
406 + if ( *fpos < BUF_LEN )
407 + {
408 + int c = *buf++;
409 + p[len] = c>='a' && c<='z' ? c-'a'+'A' : c;
410 + }
411 + (*fpos)++;
412 + len++;
413 + count--;
414 + }
415 + // sam
416 + set_led_status_by_str(id);
417 + (*fpos) = 0;
418 + //
419 +
420 + return len;
421 +}
422 +
423 +static int led_flush(struct file *file)
424 +{
425 + int id = (int)file->private_data;
426 +
427 + if ( file->f_mode & FMODE_WRITE )
428 + {
429 + set_led_status_by_str(id);
430 + }
431 + return 0;
432 +}
433 +
434 +static struct file_operations led_fops = {
435 + read: led_read,
436 + write: led_write,
437 + flush: led_flush,
438 + ioctl: led_ioctl,
439 + open: led_open,
440 +};
441 +
442 +//----------------------------------------------
443 +static unsigned long *reg_addr;
444 +static int dump_len;
445 +
446 +static int dump_content(char *buf)
447 +{
448 + return 0;
449 +}
450 +
451 +static long gpio_read(struct file *file, char *buf, size_t count, loff_t *fpos)
452 +{
453 + int rem, len;
454 + int id = (int)file->private_data;
455 + char temp[80*10];
456 + unsigned long gpio_regval =0;
457 +
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);
463 +
464 +
465 + // sam debug
466 + //printk(KERN_ERR "gpio_id:%d, gpio_regval:%08X\n", id, gpio_regval);
467 + //end sam
468 +
469 + if ( id < GPIO_DEV_NUM ) {
470 + int gpio_bit = 1 << id;
471 +
472 + len = sprintf(temp, "%d\n", (gpio_regval & gpio_bit) ? 1 : 0);
473 + }
474 + else // REG device
475 + len = dump_content(temp);
476 + rem = len - *fpos;
477 + if ( rem <= 0 ) {
478 + *fpos = len;
479 + return 0;
480 + }
481 + if ( rem > count ) rem = count;
482 + memcpy(buf, temp+(*fpos), rem);
483 + *fpos += rem;
484 + return rem;
485 +}
486 +
487 +static int gpio_flush(struct file *file)
488 +{
489 + return 0;
490 +}
491 +
492 +static int gpio_open(struct inode *inode, struct file *file)
493 +{
494 + int id = MINOR(inode->i_rdev);
495 + if ( id >= GPIO_DEV_NUM && id != REG_MINOR )
496 + return -ENODEV;
497 + file->private_data = (void*)id;
498 + return 0;
499 +}
500 +
501 +static struct file_operations gpio_fops = {
502 + read: gpio_read,
503 + open: gpio_open,
504 + flush: gpio_flush,
505 + write: led_write,
506 +};
507 +
508 +// ---------------------------------------------
509 +// sam 1-30-2004 LAN_STATUS Device
510 +
511 +//static unsigned long *reg_addr;
512 +//static int dump_len;
513 +
514 +//static int lanSt_content(char *buf)
515 +//{
516 +// int i, j, len;
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);
522 +
523 +// return len;
524 +//}
525 +
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)
531 +{
532 + int rem, len;
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;
537 + char temp[80*10];
538 +
539 + outw(0x2000 + MII_STATUS_ADDR + (PHY_ADDR << 8), MAC_IOBASE + 0x20);
540 + do{}while( (i++ < 2048) && (inw(MAC_IOBASE+0x20) & 0x2000) );
541 +
542 + status = inw(MAC_IOBASE + 0x24);
543 +
544 + // sam debug
545 + //printk(KERN_ERR "PHY REG1 Status:%04x\n", status );
546 + // end sam
547 +
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);
552 + }
553 + else // REG device
554 + {
555 + len = sprintf(temp, "-1\n");
556 + }
557 + rem = len - *fpos;
558 + if ( rem <= 0 ) {
559 + *fpos = len;
560 + return 0;
561 + }
562 + if ( rem > count ) rem = count;
563 + memcpy(buf, temp+(*fpos), rem);
564 + *fpos += rem;
565 + return rem;
566 +}
567 +
568 +static int lanSt_flush(struct file *file)
569 +{
570 + return 0;
571 +}
572 +
573 +static int lanSt_open(struct inode *inode, struct file *file)
574 +{
575 + int id = MINOR(inode->i_rdev);
576 + if ( id >= LAN_DEV_NUM && id != REG_MINOR )
577 + return -ENODEV;
578 + file->private_data = (void*)id;
579 + return 0;
580 +}
581 +
582 +static struct file_operations lanSt_fops = {
583 + read: lanSt_read,
584 + open: lanSt_open,
585 + flush: lanSt_flush,
586 + write: led_write,
587 +};
588 +
589 +//----------------------------------------------
590 +static int SwResetPress = 0;
591 +static int SwResetCounter = 0;
592 +static int RebootFlag = 0;
593 +static void watchdog_wrapper(unsigned int period)
594 +{
595 + // { RexHua add for restore default, by press SwReset 5 second, 2 sec to restart
596 +#if 0 //
597 + u_long reg;
598 +
599 + outl(GPIO_VAL, 0xcf8);
600 + reg = inl(0xcfc);
601 + reg |= 0x40;
602 + outl(reg, 0xcfc); // each in, need out 1 first
603 + reg = inl(0xcfc);
604 +
605 + if( (reg & 0x40) == 0)
606 + {
607 + if(SwResetPress == 0)
608 + {
609 + SwResetCounter=0;
610 + strcpy(led_data[15].sts_buf, "LED BLINK 500\n" );
611 + set_led_status_by_str(15);
612 + }
613 + SwResetPress=1;
614 + printk("SwReset press!\n");
615 +
616 + }
617 + else
618 + {
619 + if(SwResetPress=1)
620 + {
621 + strcpy(led_data[15].sts_buf, "LED ON\n" );
622 + set_led_status_by_str(15);
623 + }
624 +
625 + SwResetPress=0;
626 + if(RebootFlag == 1)
627 + machine_restart(0);
628 + }
629 +
630 + if(SwResetPress == 1)
631 + {
632 + if(SwResetCounter > 10)
633 + {
634 + turn_led(15, 0);
635 +// kernel_thread(reset_flash_default, 1, SIGCHLD);
636 + reset_flash_default(1);
637 + turn_led(15, 1);
638 + }
639 + else if(SwResetCounter == 3)
640 + {
641 + RebootFlag=1;
642 + strcpy(led_data[15].sts_buf, "LED BLINK 100\n" );
643 + set_led_status_by_str(15);
644 + }
645 + }
646 +
647 + SwResetCounter++;
648 +#endif
649 +
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);
656 +}
657 +
658 +//----------------------------------------------
659 +static int init_status;
660 +
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
668 +
669 +static void led_exit(void)
670 +{
671 + int id;
672 + for ( id = 0 ; id < LED_DEV_NUM ; id++ ) {
673 + del_timer(&blink_timer[id]);
674 + turn_led(id, 0);
675 + }
676 + if ( init_status & INIT_LED_PROC_READ )
677 + remove_proc_entry("driver/led", NULL);
678 +
679 + if ( init_status & INIT_LED_REGISTER )
680 + unregister_chrdev(LED_MAJOR, "led");
681 +
682 + if ( init_status & INIT_GPIO_REGISTER )
683 + unregister_chrdev(GPIO_MAJOR, "gpio");
684 + // sam 1-30-2004
685 +
686 + if( init_status & INIT_LAN_STATUS_REGISTER )
687 + unregister_chrdev(LAN_STATUS_MAJOR, "lanSt");
688 +
689 + if( init_status & INIT_WATCHDOG_REGISTER)
690 + del_timer(&watchdog);
691 +
692 +
693 + // end sam
694 +
695 +}
696 +
697 +static int __init led_init(void)
698 +{
699 + int result, id, i, j;
700 + unsigned long reg;
701 + init_status = 0;
702 +
703 + //----- register device (LED)-------------------------
704 +
705 +
706 + result = register_chrdev(LED_MAJOR, "led", &led_fops);
707 + if ( result < 0 ) {
708 + printk(KERN_ERR "led: can't register char device\n" );
709 + led_exit();
710 + return result;
711 + }
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" );
717 + led_exit();
718 + return result;
719 + }
720 + init_status |= INIT_GPIO_REGISTER;
721 +
722 + // sam 1-30-2004 LAN Status
723 + // ----- register device (LAN_STATUS)-------------------
724 +
725 + //--> sam 5-1802995
726 +
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" );
730 + led_exit();
731 + return result;
732 + }
733 + init_status |= INIT_LAN_STATUS_REGISTER;
734 +
735 + // <-- end sam
736 +
737 + // -----------init watchdog timer-------------------------
738 + //del_timer(&blink_timer[id]);
739 +
740 + outl(0x80003840, 0xcf8);
741 + reg = inl(0xcfc);
742 + reg |= 0x1600; // ensable SRC bit
743 + outl(reg, 0xcfc);
744 +#ifdef _ROUTER_
745 + outl(0x80003848, 0xcf8);
746 + reg = inl(0xcfc);
747 + reg |= 0x18040; // enable GPIO, PowerLED:15, WLAN_LED0:16, SwReset:6
748 + outl(reg, 0xcfc);
749 +
750 + outl(0x8000384c, 0xcf8);
751 + reg = inl(0xcfc);
752 + reg |= 0x40; // output SwReset:6 1, Set SwReset as Input
753 + outl(reg, 0xcfc);
754 +#endif
755 + // sam debug
756 + //reg = inl(0xcfc);
757 + //printk(KERN_ERR "REG40:%08X\n", reg);
758 + // end sam
759 + outl(0x80003844, 0xcf8);
760 + outl(0x00800080, 0xcfc); // enable watchdog and set the timeout = 1.34s
761 +
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;
768 +
769 + // end sam
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");
773 + led_exit();
774 + return -ENOMEM;
775 + }
776 + init_status |= INIT_LED_PROC_READ;
777 + //------------------------------
778 +// reg_addr = (unsigned long *)0xB4000000;
779 +// dump_len = 4;
780 +
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);
784 + }
785 +
786 +// for (i = 0; i < 0xffff; i++)
787 +// for (j = 0; j < 0x6000; j++);
788 +
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);
793 + }
794 +*/
795 + printk(KERN_INFO "LED & GPIO & LAN Status Driver LED_VERSION \n");
796 + return 0;
797 +}
798 +
799 +module_init(led_init);
800 +module_exit(led_exit);
801 +EXPORT_NO_SYMBOLS;
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
805 @@ -0,0 +1,32 @@
806 +#ifndef _LED_H_INCLUDED
807 +#define _LED_H_INCLUDED
808 +
809 +#include <linux/autoconf.h>
810 +
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
821 +// end sam
822 +
823 +//#define GPIO_IO_BASE 0xB4002480
824 +//#define GPIO_IO_BASE ((unsigned long)0xb20000b8)
825 +//#define GPIO_IO_EXTENT 0x40
826 +
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)
836 +
837 +#endif
This page took 0.076043 seconds and 5 git commands to generate.