blob: 80d8ef1874f3f23db3ab3458e849b84a220b67f8 [file] [log] [blame]
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -08001/*
2 * Stuff used by all variants of the driver
3 *
Tilman Schmidt70440cf2006-04-10 22:55:14 -07004 * Copyright (c) 2001 by Stefan Eilers,
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -08005 * 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 Lipp982da5a2006-03-26 01:38:33 -080014 */
15
16#include "gigaset.h"
17#include <linux/ctype.h>
18
Tilman Schmidt917f5082006-04-10 22:55:00 -070019static ssize_t show_cidmode(struct device *dev, struct device_attribute *attr,
20 char *buf)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080021{
Tilman Schmidtb1d47462006-04-10 22:55:07 -070022 struct cardstate *cs = dev_get_drvdata(dev);
Tilman Schmidt917f5082006-04-10 22:55:00 -070023 return sprintf(buf, "%d\n", atomic_read(&cs->cidmode));
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080024}
25
Tilman Schmidt917f5082006-04-10 22:55:00 -070026static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr,
27 const char *buf, size_t count)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080028{
Tilman Schmidtb1d47462006-04-10 22:55:07 -070029 struct cardstate *cs = dev_get_drvdata(dev);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080030 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)
38 return -EINVAL;
39
Tilman Schmidtabfd1dc2006-04-10 22:55:12 -070040 if (mutex_lock_interruptible(&cs->mutex))
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080041 return -ERESTARTSYS; // FIXME -EINTR?
42
43 cs->waiting = 1;
44 if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
Tilman Schmidt784d5852006-04-10 22:55:04 -070045 NULL, value, NULL)) {
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080046 cs->waiting = 0;
Tilman Schmidtabfd1dc2006-04-10 22:55:12 -070047 mutex_unlock(&cs->mutex);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080048 return -ENOMEM;
49 }
50
Tilman Schmidt784d5852006-04-10 22:55:04 -070051 gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080052 gigaset_schedule_event(cs);
53
54 wait_event(cs->waitqueue, !cs->waiting);
55
Tilman Schmidtabfd1dc2006-04-10 22:55:12 -070056 mutex_unlock(&cs->mutex);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080057
58 return count;
59}
60
61static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
62
63/* free sysfs for device */
Tilman Schmidtb1d47462006-04-10 22:55:07 -070064void gigaset_free_dev_sysfs(struct cardstate *cs)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080065{
Tilman Schmidt784d5852006-04-10 22:55:04 -070066 gig_dbg(DEBUG_INIT, "removing sysfs entries");
Tilman Schmidtb1d47462006-04-10 22:55:07 -070067 device_remove_file(cs->dev, &dev_attr_cidmode);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080068}
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080069
70/* initialize sysfs for device */
Tilman Schmidtb1d47462006-04-10 22:55:07 -070071void gigaset_init_dev_sysfs(struct cardstate *cs)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080072{
Tilman Schmidt784d5852006-04-10 22:55:04 -070073 gig_dbg(DEBUG_INIT, "setting up sysfs");
Tilman Schmidtb1d47462006-04-10 22:55:07 -070074 device_create_file(cs->dev, &dev_attr_cidmode);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080075}