Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Stuff used by all variants of the driver |
| 3 | * |
| 4 | * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>, |
| 5 | * Hansjoerg Lipp <hjlipp@web.de>, |
| 6 | * Tilman Schmidt <tilman@imap.cc>. |
| 7 | * |
| 8 | * ===================================================================== |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * ===================================================================== |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include "gigaset.h" |
| 17 | #include <linux/ctype.h> |
| 18 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 19 | static ssize_t show_cidmode(struct device *dev, struct device_attribute *attr, |
| 20 | char *buf) |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 21 | { |
| 22 | struct usb_interface *intf = to_usb_interface(dev); |
| 23 | struct cardstate *cs = usb_get_intfdata(intf); |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 24 | return sprintf(buf, "%d\n", atomic_read(&cs->cidmode)); |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 25 | } |
| 26 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 27 | static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr, |
| 28 | const char *buf, size_t count) |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 29 | { |
| 30 | struct usb_interface *intf = to_usb_interface(dev); |
| 31 | struct cardstate *cs = usb_get_intfdata(intf); |
| 32 | long int value; |
| 33 | char *end; |
| 34 | |
| 35 | value = simple_strtol(buf, &end, 0); |
| 36 | while (*end) |
| 37 | if (!isspace(*end++)) |
| 38 | return -EINVAL; |
| 39 | if (value < 0 || value > 1) |
| 40 | return -EINVAL; |
| 41 | |
| 42 | if (down_interruptible(&cs->sem)) |
| 43 | return -ERESTARTSYS; // FIXME -EINTR? |
| 44 | |
| 45 | cs->waiting = 1; |
| 46 | if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame^] | 47 | NULL, value, NULL)) { |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 48 | cs->waiting = 0; |
| 49 | up(&cs->sem); |
| 50 | return -ENOMEM; |
| 51 | } |
| 52 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame^] | 53 | gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE"); |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 54 | gigaset_schedule_event(cs); |
| 55 | |
| 56 | wait_event(cs->waitqueue, !cs->waiting); |
| 57 | |
| 58 | up(&cs->sem); |
| 59 | |
| 60 | return count; |
| 61 | } |
| 62 | |
| 63 | static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode); |
| 64 | |
| 65 | /* free sysfs for device */ |
| 66 | void gigaset_free_dev_sysfs(struct usb_interface *interface) |
| 67 | { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame^] | 68 | gig_dbg(DEBUG_INIT, "removing sysfs entries"); |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 69 | device_remove_file(&interface->dev, &dev_attr_cidmode); |
| 70 | } |
| 71 | EXPORT_SYMBOL_GPL(gigaset_free_dev_sysfs); |
| 72 | |
| 73 | /* initialize sysfs for device */ |
| 74 | void gigaset_init_dev_sysfs(struct usb_interface *interface) |
| 75 | { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame^] | 76 | gig_dbg(DEBUG_INIT, "setting up sysfs"); |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 77 | device_create_file(&interface->dev, &dev_attr_cidmode); |
| 78 | } |
| 79 | EXPORT_SYMBOL_GPL(gigaset_init_dev_sysfs); |