]> Pileus Git - ~andy/linux/blob - drivers/staging/ft1000/ft1000-usb/ft1000_proc.c
Merge remote-tracking branch 'regulator/fix/dbx500' into regulator-linus
[~andy/linux] / drivers / staging / ft1000 / ft1000-usb / ft1000_proc.c
1 /*
2  * ft1000_proc.c - ft1000 proc interface
3  *
4  * Copyright    (C) 2009-2010 Quintec
5  *              (C) 2010 Open-nandra
6  *      <marek.belisko@open-nandra.com>
7  *
8  * This file is subject to the terms and conditions of the GNU General
9  * Public License. See the file "COPYING" in the main directory of this
10  * archive for more details.
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
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/proc_fs.h>
25 #include <linux/seq_file.h>
26 #include <linux/netdevice.h>
27
28
29 #include "ft1000_usb.h"
30
31 #define FT1000_PROC_DIR "ft1000"
32
33
34 #define seq_putx(m, message, size, var) \
35         seq_printf(m, message); \
36         for(i = 0; i < (size - 1); i++) \
37                 seq_printf(m, "%02x:", var[i]); \
38         seq_printf(m, "%02x\n", var[i])
39
40 #define seq_putd(m, message, size, var) \
41         seq_printf(m, message); \
42         for(i = 0; i < (size - 1); i++) \
43                 seq_printf(m, "%d.", var[i]); \
44         seq_printf(m, "%d\n", var[i])
45
46
47 #define FTNET_PROC init_net.proc_net
48
49
50 int ft1000_read_dpram16 (struct ft1000_usb *ft1000dev, u16 indx,
51                          u8 *buffer, u8 highlow);
52
53
54 static int ft1000ReadProc(struct seq_file *m, void *v)
55 {
56         static const char *status[] = { 
57                 "Idle (Disconnect)", 
58                 "Searching",
59                 "Active (Connected)",
60                 "Waiting for L2",
61                 "Sleep",
62                 "No Coverage",
63                 "",
64                 "",
65         };
66         static const char *signal[] = { "", "*", "**", "***", "****" };
67
68         struct net_device *dev = m->private;
69         struct ft1000_info *info = netdev_priv(dev);
70         int i;
71         unsigned short ledStat;
72         unsigned short conStat;
73         int strength;
74         int quality;
75         struct timeval tv;
76         time_t delta;
77
78         if (info->ProgConStat != 0xFF) {
79                 ft1000_read_dpram16(info->priv, FT1000_MAG_DSP_LED,
80                            (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX);
81                 info->LedStat = ntohs(ledStat);
82
83                 ft1000_read_dpram16(info->priv, FT1000_MAG_DSP_CON_STATE,
84                         (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
85                 info->ConStat = ntohs(conStat);
86                 do_gettimeofday(&tv);
87                 delta = (tv.tv_sec - info->ConTm);
88         } else {
89                 info->ConStat = 0xf;
90                 delta = 0;
91         }
92
93         i = (info->LedStat) & 0xf;
94         switch (i) {
95         case 0x1:
96                 strength = 1;
97                 break;
98         case 0x3:
99                 strength = 2;
100                 break;
101         case 0x7:
102                 strength = 3;
103                 break;
104         case 0xf:
105                 strength = 4;
106                 break;
107         default:
108                 strength = 0;
109         }
110
111         i = (info->LedStat >> 8) & 0xf;
112         switch (i) {
113         case 0x1:
114                 quality = 1;
115                 break;
116         case 0x3:
117                 quality = 2;
118                 break;
119         case 0x7:
120                 quality = 3;
121                 break;
122         case 0xf:
123                 quality = 4;
124                 break;
125         default:
126                 quality = 0;
127         }
128
129         seq_printf(m, "Connection Time: %02ld:%02ld:%02ld\n",
130                 ((delta / 3600) % 24), ((delta / 60) % 60), (delta % 60));
131         seq_printf(m, "Connection Time[s]: %ld\n", delta);
132         seq_printf(m, "Asic ID: %s\n",
133         (info->AsicID) == ELECTRABUZZ_ID ? "ELECTRABUZZ ASIC" : "MAGNEMITE ASIC");
134         seq_putx(m, "SKU: ", SKUSZ, info->Sku);
135         seq_putx(m, "EUI64: ", EUISZ, info->eui64);
136         seq_putd(m, "DSP version number: ", DSPVERSZ, info->DspVer);
137         seq_putx(m, "Hardware Serial Number: ", HWSERNUMSZ, info->HwSerNum);
138         seq_putx(m, "Caliberation Version: ", CALVERSZ, info->RfCalVer);
139         seq_putd(m, "Caliberation Date: ", CALDATESZ, info->RfCalDate);
140         seq_printf(m, "Media State: %s\n", (info->mediastate) ? "link" : "no link");
141         seq_printf(m, "Connection Status: %s\n", status[info->ConStat & 0x7]);
142         seq_printf(m, "RX packets: %ld\n", info->stats.rx_packets);
143         seq_printf(m, "TX packets: %ld\n", info->stats.tx_packets);
144         seq_printf(m, "RX bytes: %ld\n", info->stats.rx_bytes);
145         seq_printf(m, "TX bytes: %ld\n", info->stats.tx_bytes);
146         seq_printf(m, "Signal Strength: %s\n", signal[strength]);
147         seq_printf(m, "Signal Quality: %s\n", signal[quality]);
148         return 0;
149 }
150
151 /*
152  * seq_file wrappers for procfile show routines.
153  */
154 static int ft1000_proc_open(struct inode *inode, struct file *file)
155 {
156         return single_open(file, ft1000ReadProc, PDE_DATA(inode));
157 }
158
159 static const struct file_operations ft1000_proc_fops = {
160         .open           = ft1000_proc_open,
161         .read           = seq_read,
162         .llseek         = seq_lseek,
163         .release        = single_release,
164 };
165
166 static int
167 ft1000NotifyProc(struct notifier_block *this, unsigned long event, void *ptr)
168 {
169         struct net_device *dev = ptr;
170         struct ft1000_info *info;
171         struct proc_dir_entry *ft1000_proc_file;
172
173         info = netdev_priv(dev);
174
175         switch (event) {
176         case NETDEV_CHANGENAME:
177                 remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
178                 ft1000_proc_file =
179                         proc_create_data(dev->name, 0644, info->ft1000_proc_dir,
180                                          &ft1000_proc_fops, dev);
181                 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
182                 break;
183         }
184
185         return NOTIFY_DONE;
186 }
187
188 static struct notifier_block ft1000_netdev_notifier = {
189         .notifier_call = ft1000NotifyProc,
190 };
191
192
193 int ft1000_init_proc(struct net_device *dev)
194 {
195         struct ft1000_info *info;
196         struct proc_dir_entry *ft1000_proc_file;
197         int ret = -EINVAL;
198
199         info = netdev_priv(dev);
200
201         info->ft1000_proc_dir = proc_mkdir(FT1000_PROC_DIR, FTNET_PROC);
202         if (info->ft1000_proc_dir == NULL) {
203                 printk(KERN_WARNING "Unable to create %s dir.\n",
204                         FT1000_PROC_DIR);
205                 goto fail;
206         }
207
208         ft1000_proc_file =
209                 proc_create_data(dev->name, 0644, info->ft1000_proc_dir,
210                                  &ft1000_proc_fops, dev);
211
212         if (!ft1000_proc_file) {
213                 printk(KERN_WARNING "Unable to create /proc entry.\n");
214                 goto fail_entry;
215         }
216
217         snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
218
219         ret = register_netdevice_notifier(&ft1000_netdev_notifier);
220         if (ret)
221                 goto fail_notif;
222
223         return 0;
224
225 fail_notif:
226         remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
227 fail_entry:
228         remove_proc_entry(FT1000_PROC_DIR, FTNET_PROC);
229 fail:
230         return ret;
231 }
232
233 void ft1000_cleanup_proc(struct ft1000_info *info)
234 {
235         remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
236         remove_proc_entry(FT1000_PROC_DIR, FTNET_PROC);
237         unregister_netdevice_notifier(&ft1000_netdev_notifier);
238 }