diff options
author | Marek Belisko <marek.belisko@open-nandra.com> | 2010-12-09 05:26:46 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-12-09 19:34:31 -0500 |
commit | 9119dee1ce32453dfe24656091d69f8d57397fe0 (patch) | |
tree | 62ba9580073d9f6f736c0f97c23f6afb698e2853 | |
parent | 372058f1b4b3603a7e0c26f38d6eb20a3dd8c453 (diff) |
staging: ft1000: Convert char device to debugfs.
Character device was used only for debugging purposes.
Convert it to debugfs functionality. For every plugged device
create new directory with one file.
Signed-off-by: Marek Belisko <marek.belisko@open-nandra.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c | 68 | ||||
-rw-r--r-- | drivers/staging/ft1000/ft1000-usb/ft1000_hw.c | 1 | ||||
-rw-r--r-- | drivers/staging/ft1000/ft1000-usb/ft1000_usb.h | 8 |
3 files changed, 57 insertions, 20 deletions
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c b/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c index 1aec926c993c..1238b7759e5b 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c | |||
@@ -37,7 +37,7 @@ | |||
37 | #include <linux/kmod.h> | 37 | #include <linux/kmod.h> |
38 | #include <linux/ioctl.h> | 38 | #include <linux/ioctl.h> |
39 | #include <linux/unistd.h> | 39 | #include <linux/unistd.h> |
40 | 40 | #include <linux/debugfs.h> | |
41 | #include "ft1000_usb.h" | 41 | #include "ft1000_usb.h" |
42 | //#include "ft1000_ioctl.h" | 42 | //#include "ft1000_ioctl.h" |
43 | 43 | ||
@@ -156,9 +156,11 @@ int ft1000_CreateDevice(struct ft1000_device *dev) | |||
156 | struct ft1000_info *info = netdev_priv(dev->net); | 156 | struct ft1000_info *info = netdev_priv(dev->net); |
157 | int result; | 157 | int result; |
158 | int i; | 158 | int i; |
159 | struct dentry *dir, *file; | ||
160 | struct ft1000_debug_dirs *tmp; | ||
159 | 161 | ||
160 | // make a new device name | 162 | // make a new device name |
161 | sprintf(info->DeviceName, "%s%d", "FT100", info->CardNumber); | 163 | sprintf(info->DeviceName, "%s%d", "FT1000_", info->CardNumber); |
162 | 164 | ||
163 | DEBUG("ft1000_CreateDevice: number of instance = %d\n", ft1000_flarion_cnt); | 165 | DEBUG("ft1000_CreateDevice: number of instance = %d\n", ft1000_flarion_cnt); |
164 | DEBUG("DeviceCreated = %x\n", info->DeviceCreated); | 166 | DEBUG("DeviceCreated = %x\n", info->DeviceCreated); |
@@ -179,21 +181,31 @@ int ft1000_CreateDevice(struct ft1000_device *dev) | |||
179 | DEBUG("ft1000_CreateDevice: \"%s\" device registration\n", info->DeviceName); | 181 | DEBUG("ft1000_CreateDevice: \"%s\" device registration\n", info->DeviceName); |
180 | info->DeviceMajor = 0; | 182 | info->DeviceMajor = 0; |
181 | 183 | ||
182 | result = register_chrdev(info->DeviceMajor, info->DeviceName, &ft1000fops); | 184 | tmp = kmalloc(sizeof(struct ft1000_debug_dirs), GFP_KERNEL); |
183 | if (result < 0) | 185 | if (tmp == NULL) { |
184 | { | 186 | result = -1; |
185 | DEBUG("ft1000_CreateDevice: unable to get major %d\n", info->DeviceMajor); | 187 | goto fail; |
186 | return result; | 188 | } |
187 | } | ||
188 | 189 | ||
189 | DEBUG("ft1000_CreateDevice: registered char device \"%s\"\n", info->DeviceName); | 190 | dir = debugfs_create_dir(info->DeviceName, 0); |
191 | if (IS_ERR(dir)) { | ||
192 | result = PTR_ERR(dir); | ||
193 | goto debug_dir_fail; | ||
194 | } | ||
190 | 195 | ||
191 | // save a dynamic device major number | 196 | file = debugfs_create_file("device", S_IRUGO | S_IWUGO, dir, |
192 | if (info->DeviceMajor == 0) | 197 | NULL, &ft1000fops); |
193 | { | 198 | if (IS_ERR(file)) { |
194 | info->DeviceMajor = result; | 199 | result = PTR_ERR(file); |
195 | DEBUG("ft1000_PcdCreateDevice: device major = %d\n", info->DeviceMajor); | 200 | goto debug_file_fail; |
196 | } | 201 | } |
202 | |||
203 | tmp->dent = dir; | ||
204 | tmp->file = file; | ||
205 | tmp->int_number = info->CardNumber; | ||
206 | list_add(&(tmp->list), &(info->nodes.list)); | ||
207 | |||
208 | DEBUG("ft1000_CreateDevice: registered char device \"%s\"\n", info->DeviceName); | ||
197 | 209 | ||
198 | // initialize application information | 210 | // initialize application information |
199 | 211 | ||
@@ -243,7 +255,14 @@ int ft1000_CreateDevice(struct ft1000_device *dev) | |||
243 | info->DeviceCreated = TRUE; | 255 | info->DeviceCreated = TRUE; |
244 | ft1000_flarion_cnt++; | 256 | ft1000_flarion_cnt++; |
245 | 257 | ||
246 | return result; | 258 | return 0; |
259 | |||
260 | debug_file_fail: | ||
261 | debugfs_remove(dir); | ||
262 | debug_dir_fail: | ||
263 | kfree(tmp); | ||
264 | fail: | ||
265 | return result; | ||
247 | } | 266 | } |
248 | 267 | ||
249 | //--------------------------------------------------------------------------- | 268 | //--------------------------------------------------------------------------- |
@@ -259,10 +278,11 @@ int ft1000_CreateDevice(struct ft1000_device *dev) | |||
259 | void ft1000_DestroyDevice(struct net_device *dev) | 278 | void ft1000_DestroyDevice(struct net_device *dev) |
260 | { | 279 | { |
261 | struct ft1000_info *info = netdev_priv(dev); | 280 | struct ft1000_info *info = netdev_priv(dev); |
262 | int result = 0; | ||
263 | int i; | 281 | int i; |
264 | struct dpram_blk *pdpram_blk; | 282 | struct dpram_blk *pdpram_blk; |
265 | struct dpram_blk *ptr; | 283 | struct dpram_blk *ptr; |
284 | struct list_head *pos, *q; | ||
285 | struct ft1000_debug_dirs *dir; | ||
266 | 286 | ||
267 | DEBUG("ft1000_chdev:ft1000_DestroyDevice called\n"); | 287 | DEBUG("ft1000_chdev:ft1000_DestroyDevice called\n"); |
268 | 288 | ||
@@ -271,9 +291,17 @@ void ft1000_DestroyDevice(struct net_device *dev) | |||
271 | if (info->DeviceCreated) | 291 | if (info->DeviceCreated) |
272 | { | 292 | { |
273 | ft1000_flarion_cnt--; | 293 | ft1000_flarion_cnt--; |
274 | unregister_chrdev(info->DeviceMajor, info->DeviceName); | 294 | list_for_each_safe(pos, q, &info->nodes.list) { |
275 | DEBUG("ft1000_DestroyDevice: unregistered device \"%s\", result = %d\n", | 295 | dir = list_entry(pos, struct ft1000_debug_dirs, list); |
276 | info->DeviceName, result); | 296 | if (dir->int_number == info->CardNumber) { |
297 | debugfs_remove(dir->file); | ||
298 | debugfs_remove(dir->dent); | ||
299 | list_del(pos); | ||
300 | kfree(dir); | ||
301 | } | ||
302 | } | ||
303 | DEBUG("ft1000_DestroyDevice: unregistered device \"%s\"\n", | ||
304 | info->DeviceName); | ||
277 | 305 | ||
278 | // Make sure we free any memory reserve for slow Queue | 306 | // Make sure we free any memory reserve for slow Queue |
279 | for (i=0; i<MAX_NUM_APP; i++) { | 307 | for (i=0; i<MAX_NUM_APP; i++) { |
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c index 1ca01e2ea361..22536da75011 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c | |||
@@ -851,6 +851,7 @@ u16 init_ft1000_netdev(struct ft1000_device *ft1000dev) | |||
851 | 851 | ||
852 | INIT_LIST_HEAD(&pInfo->prov_list); | 852 | INIT_LIST_HEAD(&pInfo->prov_list); |
853 | 853 | ||
854 | INIT_LIST_HEAD(&pInfo->nodes.list); | ||
854 | //mbelian | 855 | //mbelian |
855 | #ifdef HAVE_NET_DEVICE_OPS | 856 | #ifdef HAVE_NET_DEVICE_OPS |
856 | netdev->netdev_ops = &ftnet_ops; | 857 | netdev->netdev_ops = &ftnet_ops; |
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h index a07db26441f1..5bead6314985 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h | |||
@@ -473,6 +473,13 @@ struct ft1000_device | |||
473 | // struct net_device_stats stats; //mbelian | 473 | // struct net_device_stats stats; //mbelian |
474 | } __attribute__ ((packed)); | 474 | } __attribute__ ((packed)); |
475 | 475 | ||
476 | struct ft1000_debug_dirs { | ||
477 | struct list_head list; | ||
478 | struct dentry *dent; | ||
479 | struct dentry *file; | ||
480 | int int_number; | ||
481 | }; | ||
482 | |||
476 | struct ft1000_info { | 483 | struct ft1000_info { |
477 | struct ft1000_device *pFt1000Dev; | 484 | struct ft1000_device *pFt1000Dev; |
478 | struct net_device_stats stats; | 485 | struct net_device_stats stats; |
@@ -508,6 +515,7 @@ struct ft1000_info { | |||
508 | u8 CardNumber; | 515 | u8 CardNumber; |
509 | u8 DeviceName[15]; | 516 | u8 DeviceName[15]; |
510 | int DeviceMajor; | 517 | int DeviceMajor; |
518 | struct ft1000_debug_dirs nodes; | ||
511 | int registered; | 519 | int registered; |
512 | int mediastate; | 520 | int mediastate; |
513 | int dhcpflg; | 521 | int dhcpflg; |