sstrip, nas support, mppe support, mac os x patches, syslogd on bootup, inittab corre...
[openwrt.git] / obsolete-buildroot / sources / openwrt / kernel / diag.c
1 // replacement diag module
2 // (c) 2004 openwrt
3 // mbm at alt dot org
4 //
5 // initial release 2004/03/28
6
7 #include <linux/module.h>
8 #include <linux/init.h>
9 #include <linux/kernel.h>
10 #include <linux/timer.h>
11 #include <linux/sysctl.h>
12 #include <asm/io.h>
13 #include <typedefs.h>
14 #include <bcm4710.h>
15 #include <sbutils.h>
16
17 static void *sbh;
18
19 // v2.x - - - - -
20 #define DIAG_GPIO (1<<1)
21 #define DMZ_GPIO (1<<7)
22
23 static void set_gpio(uint32 mask, uint32 value) {
24 sb_gpiocontrol(sbh,mask,0);
25 sb_gpioouten(sbh,mask,mask);
26 sb_gpioout(sbh,mask,value);
27 }
28
29 static void v2_set_diag(u8 state) {
30 set_gpio(DIAG_GPIO,state);
31 }
32 static void v2_set_dmz(u8 state) {
33 set_gpio(DMZ_GPIO,state);
34 }
35
36 // v1.x - - - - -
37 #define LED_DIAG 0x13
38 #define LED_DMZ 0x12
39
40 static void v1_set_diag(u8 state) {
41 if (!state) {
42 *(volatile u8*)(KSEG1ADDR(BCM4710_EUART)+LED_DIAG)=0xFF;
43 } else {
44 *(volatile u8*)(KSEG1ADDR(BCM4710_EUART)+LED_DIAG);
45 }
46 }
47 static void v1_set_dmz(u8 state) {
48 if (!state) {
49 *(volatile u8*)(KSEG1ADDR(BCM4710_EUART)+LED_DMZ)=0xFF;
50 } else {
51 *(volatile u8*)(KSEG1ADDR(BCM4710_EUART)+LED_DMZ);
52 }
53 }
54
55 // - - - - -
56 static void ignore(u8 ignored) {};
57
58 // - - - - -
59 #define BIT_DMZ 0x01
60 #define BIT_DIAG 0x04
61
62 void (*set_diag)(u8 state);
63 void (*set_dmz)(u8 state);
64
65 static unsigned int diag = 0;
66 static struct timer_list timer;
67
68 static void diag_change()
69 {
70 printk(KERN_INFO "led -> %02x\n",diag);
71
72 set_diag(0xFF); // off
73 set_dmz(0xFF); // off
74
75 if(diag & BIT_DIAG)
76 set_diag(0x00); // on
77 if(diag & BIT_DMZ)
78 set_dmz(0x00); // on
79 }
80
81 static int proc_diag(ctl_table *table, int write, struct file *filp,
82 void *buffer, size_t *lenp)
83 {
84 int r;
85 r = proc_dointvec(table, write, filp, buffer, lenp);
86 if (write && !r) {
87 diag_change();
88 }
89 return r;
90 }
91
92 // - - - - -
93 static struct ctl_table_header *diag_sysctl_header;
94
95 static ctl_table sys_diag[] = {
96 {
97 ctl_name: 2000,
98 procname: "diag",
99 data: &diag,
100 maxlen: sizeof(diag),
101 mode: 0644,
102 proc_handler: proc_diag
103 },
104 { 0 }
105 };
106
107 static int __init diag_init()
108 {
109 u32 board_type;
110 sbh = sb_kattach();
111 sb_gpiosetcore(sbh);
112
113 board_type = sb_boardtype(sbh);
114 printk(KERN_INFO "diag board_type: %08x\n",board_type);
115
116 if (board_type & 0x400) {
117 set_diag=v1_set_diag;
118 set_dmz=v1_set_dmz;
119 if (board_type==0x41d) {
120 printk(KERN_INFO "buffalo hack.\n");
121 set_diag=ignore;
122 set_dmz=v2_set_dmz;
123 }
124 board_type=1;
125 } else {
126 board_type=2;
127 set_diag=v2_set_diag;
128 set_dmz=v2_set_dmz;
129 }
130 printk(KERN_INFO "using v%d hardware\n",board_type);
131
132 diag_sysctl_header = register_sysctl_table(sys_diag, 0);
133 diag_change();
134
135 return 0;
136 }
137
138 static void __exit diag_exit()
139 {
140 unregister_sysctl_table(diag_sysctl_header);
141 del_timer(&timer);
142 }
143
144 module_init(diag_init);
145 module_exit(diag_exit);
This page took 0.049373 seconds and 5 git commands to generate.