fix typos in CONFIG_SITE files
[openwrt/svn-archive/openwrt.git] / openwrt / target / linux / package / diag / src / diag.h
1 /*
2 * diag.h - GPIO interface driver for Broadcom boards
3 *
4 * Copyright (C) 2006 Mike Baker <mbm@openwrt.org>,
5 * Felix Fietkau <nbd@openwrt.org>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 * $Id:$
22 */
23
24 #define MODULE_NAME "diag"
25
26 #define MAX_GPIO 8
27 #define FLASH_TIME HZ/6
28
29 enum polarity_t {
30 REVERSE = 0,
31 NORMAL = 1,
32 };
33
34 enum {
35 PROC_BUTTON,
36 PROC_LED,
37 PROC_MODEL,
38 PROC_GPIOMASK
39 };
40
41 struct prochandler_t {
42 int type;
43 void *ptr;
44 };
45
46 struct button_t {
47 struct prochandler_t proc;
48 char *name;
49 u32 gpio;
50 unsigned long seen;
51 u8 pressed;
52 };
53
54 struct led_t {
55 struct prochandler_t proc;
56 char *name;
57 u32 gpio;
58 u8 polarity;
59 u8 flash;
60 u8 state;
61 };
62
63 struct platform_t {
64 char *name;
65
66 struct button_t buttons[MAX_GPIO];
67 u32 button_mask;
68 u32 button_polarity;
69
70 struct led_t leds[MAX_GPIO];
71 };
72
73 struct event_t {
74 struct tq_struct tq;
75 char buf[256];
76 char *argv[3];
77 char *envp[6];
78 };
79
80 #define sbh bcm947xx_sbh
81 #define sbh_lock bcm947xx_sbh_lock
82
83 extern void *bcm947xx_sbh;
84 extern spinlock_t bcm947xx_sbh_lock;
85 extern char *nvram_get(char *str);
86
87 static struct platform_t platform;
88
89 /* buttons */
90
91 static void set_irqenable(int enabled);
92
93 static void register_buttons(struct button_t *b);
94 static void unregister_buttons(struct button_t *b);
95
96 static void hotplug_button(struct event_t *event);
97 static void button_handler(int irq, void *dev_id, struct pt_regs *regs);
98
99 /* leds */
100
101 static void register_leds(struct led_t *l);
102 static void unregister_leds(struct led_t *l);
103
104 #define EXTIF_ADDR 0x1f000000
105 #define EXTIF_UART (EXTIF_ADDR + 0x00800000)
106
107 #define GPIO_TYPE_NORMAL (0x0 << 24)
108 #define GPIO_TYPE_EXTIF (0x1 << 24)
109 #define GPIO_TYPE_MASK (0xf << 24)
110
111 static void set_led_extif(struct led_t *led);
112 static void led_flash(unsigned long dummy);
113
114 static struct timer_list led_timer = {
115 function: &led_flash
116 };
117
118 /* proc */
119
120 static struct proc_dir_entry *diag, *leds;
121
122 static ssize_t diag_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos);
123 static ssize_t diag_proc_write(struct file *file, const char *buf, size_t count, void *data);
124
125 static struct file_operations diag_proc_fops = {
126 read: diag_proc_read,
127 write: diag_proc_write
128 };
129
130 static struct prochandler_t proc_model = { .type = PROC_MODEL };
131 static struct prochandler_t proc_gpiomask = { .type = PROC_GPIOMASK };
132
133 /* TODO: export existing sb_irq instead */
134 static int sb_irq(void *sbh)
135 {
136 uint idx;
137 void *regs;
138 sbconfig_t *sb;
139 uint32 flag, sbipsflag;
140 uint irq = 0;
141
142 regs = sb_coreregs(sbh);
143 sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
144 flag = (R_REG(&sb->sbtpsflag) & SBTPS_NUM0_MASK);
145
146 idx = sb_coreidx(sbh);
147
148 if ((regs = sb_setcore(sbh, SB_MIPS, 0)) ||
149 (regs = sb_setcore(sbh, SB_MIPS33, 0))) {
150 sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
151
152 /* sbipsflag specifies which core is routed to interrupts 1 to 4 */
153 sbipsflag = R_REG(&sb->sbipsflag);
154 for (irq = 1; irq <= 4; irq++, sbipsflag >>= 8) {
155 if ((sbipsflag & 0x3f) == flag)
156 break;
157 }
158 if (irq == 5)
159 irq = 0;
160 }
161
162 sb_setcoreidx(sbh, idx);
163
164 return irq;
165 }