no actual config changes
[openwrt.git] / obsolete-buildroot / sources / openwrt-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 #define BIT_DMZ 0x01
57 #define BIT_DIAG 0x04
58
59 void (*set_diag)(u8 state);
60 void (*set_dmz)(u8 state);
61
62 static unsigned int diag = 0;
63 static struct timer_list timer;
64
65 static void diag_change()
66 {
67 printk(KERN_INFO "led -> %02x\n",diag);
68
69 set_diag(0xFF); // off
70 set_dmz(0xFF); // off
71
72 if(diag & BIT_DIAG)
73 set_diag(0x00); // on
74 if(diag & BIT_DMZ)
75 set_dmz(0x00); // on
76 }
77
78 static int proc_diag(ctl_table *table, int write, struct file *filp,
79 void *buffer, size_t *lenp)
80 {
81 int r;
82 r = proc_dointvec(table, write, filp, buffer, lenp);
83 if (write && !r) {
84 diag_change();
85 }
86 return r;
87 }
88
89 // - - - - -
90 static struct ctl_table_header *diag_sysctl_header;
91
92 static ctl_table sys_diag[] = {
93 {
94 ctl_name: 2000,
95 procname: "diag",
96 data: &diag,
97 maxlen: sizeof(diag),
98 mode: 0644,
99 proc_handler: proc_diag
100 },
101 { 0 }
102 };
103
104 static int __init diag_init()
105 {
106 u32 board_type;
107 sbh = sb_kattach();
108 sb_gpiosetcore(sbh);
109
110 board_type = sb_boardtype(sbh);
111 printk(KERN_INFO "diag board_type: %08x\n",board_type);
112
113 if (board_type & 0x400) {
114 board_type=1;
115 set_diag=v1_set_diag;
116 set_dmz=v1_set_dmz;
117 } else {
118 board_type=2;
119 set_diag=v2_set_diag;
120 set_dmz=v2_set_dmz;
121 }
122 printk(KERN_INFO "using v%d hardware\n",board_type);
123
124 diag_sysctl_header = register_sysctl_table(sys_diag, 0);
125 diag_change();
126
127 return 0;
128 }
129
130 static void __exit diag_exit()
131 {
132 unregister_sysctl_table(diag_sysctl_header);
133 del_timer(&timer);
134 }
135
136 module_init(diag_init);
137 module_exit(diag_exit);
This page took 0.050896 seconds and 5 git commands to generate.