Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Stuff used by all variants of the driver |
| 3 | * |
Tilman Schmidt | 70440cf | 2006-04-10 22:55:14 -0700 | [diff] [blame] | 4 | * Copyright (c) 2001 by Stefan Eilers, |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 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" |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 17 | |
Greg Kroah-Hartman | 01107d3 | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 18 | static ssize_t show_cidmode(struct device *dev, |
| 19 | struct device_attribute *attr, char *buf) |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 20 | { |
Greg Kroah-Hartman | 01107d3 | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 21 | struct cardstate *cs = dev_get_drvdata(dev); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 22 | |
Tilman Schmidt | 4d1ff58 | 2007-10-16 01:27:50 -0700 | [diff] [blame] | 23 | return sprintf(buf, "%u\n", cs->cidmode); |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 24 | } |
| 25 | |
Greg Kroah-Hartman | 01107d3 | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 26 | static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr, |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 27 | const char *buf, size_t count) |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 28 | { |
Greg Kroah-Hartman | 01107d3 | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 29 | struct cardstate *cs = dev_get_drvdata(dev); |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 30 | long int value; |
| 31 | char *end; |
| 32 | |
| 33 | value = simple_strtol(buf, &end, 0); |
| 34 | while (*end) |
| 35 | if (!isspace(*end++)) |
| 36 | return -EINVAL; |
| 37 | if (value < 0 || value > 1) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 38 | return -EINVAL; |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 39 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 40 | if (mutex_lock_interruptible(&cs->mutex)) |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame] | 41 | return -ERESTARTSYS; |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 42 | |
| 43 | cs->waiting = 1; |
| 44 | if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 45 | NULL, value, NULL)) { |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 46 | cs->waiting = 0; |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 47 | mutex_unlock(&cs->mutex); |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 48 | return -ENOMEM; |
| 49 | } |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 50 | gigaset_schedule_event(cs); |
| 51 | |
| 52 | wait_event(cs->waitqueue, !cs->waiting); |
| 53 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 54 | mutex_unlock(&cs->mutex); |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 55 | |
| 56 | return count; |
| 57 | } |
| 58 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 59 | static DEVICE_ATTR(cidmode, S_IRUGO | S_IWUSR, show_cidmode, set_cidmode); |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 60 | |
| 61 | /* free sysfs for device */ |
Tilman Schmidt | b1d4746 | 2006-04-10 22:55:07 -0700 | [diff] [blame] | 62 | void gigaset_free_dev_sysfs(struct cardstate *cs) |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 63 | { |
Greg Kroah-Hartman | 01107d3 | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 64 | if (!cs->tty_dev) |
Hansjoerg Lipp | 3dda4e3 | 2006-04-22 18:43:00 +0200 | [diff] [blame] | 65 | return; |
| 66 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 67 | gig_dbg(DEBUG_INIT, "removing sysfs entries"); |
Greg Kroah-Hartman | 01107d3 | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 68 | device_remove_file(cs->tty_dev, &dev_attr_cidmode); |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 69 | } |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 70 | |
| 71 | /* initialize sysfs for device */ |
Tilman Schmidt | b1d4746 | 2006-04-10 22:55:07 -0700 | [diff] [blame] | 72 | void gigaset_init_dev_sysfs(struct cardstate *cs) |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 73 | { |
Greg Kroah-Hartman | 01107d3 | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 74 | if (!cs->tty_dev) |
Hansjoerg Lipp | 3dda4e3 | 2006-04-22 18:43:00 +0200 | [diff] [blame] | 75 | return; |
| 76 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 77 | gig_dbg(DEBUG_INIT, "setting up sysfs"); |
Greg Kroah-Hartman | 01107d3 | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 78 | if (device_create_file(cs->tty_dev, &dev_attr_cidmode)) |
Tilman Schmidt | 42e3d61 | 2009-05-13 12:44:17 +0000 | [diff] [blame] | 79 | pr_err("could not create sysfs attribute\n"); |
Hansjoerg Lipp | 982da5a | 2006-03-26 01:38:33 -0800 | [diff] [blame] | 80 | } |