blob: d267a636b53c63cbd9558b73e57474248d5f9a16 [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 Schmidt69049cc2006-04-10 22:55:16 -070022 int ret;
23 unsigned long flags;
Tilman Schmidtb1d47462006-04-10 22:55:07 -070024 struct cardstate *cs = dev_get_drvdata(dev);
Tilman Schmidt69049cc2006-04-10 22:55:16 -070025
26 spin_lock_irqsave(&cs->lock, flags);
27 ret = sprintf(buf, "%u\n", cs->cidmode);
28 spin_unlock_irqrestore(&cs->lock, flags);
29
30 return ret;
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080031}
32
Tilman Schmidt917f5082006-04-10 22:55:00 -070033static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr,
34 const char *buf, size_t count)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080035{
Tilman Schmidtb1d47462006-04-10 22:55:07 -070036 struct cardstate *cs = dev_get_drvdata(dev);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080037 long int value;
38 char *end;
39
40 value = simple_strtol(buf, &end, 0);
41 while (*end)
42 if (!isspace(*end++))
43 return -EINVAL;
44 if (value < 0 || value > 1)
45 return -EINVAL;
46
Tilman Schmidtabfd1dc2006-04-10 22:55:12 -070047 if (mutex_lock_interruptible(&cs->mutex))
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080048 return -ERESTARTSYS; // FIXME -EINTR?
49
50 cs->waiting = 1;
51 if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
Tilman Schmidt784d5852006-04-10 22:55:04 -070052 NULL, value, NULL)) {
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080053 cs->waiting = 0;
Tilman Schmidtabfd1dc2006-04-10 22:55:12 -070054 mutex_unlock(&cs->mutex);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080055 return -ENOMEM;
56 }
57
Tilman Schmidt784d5852006-04-10 22:55:04 -070058 gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080059 gigaset_schedule_event(cs);
60
61 wait_event(cs->waitqueue, !cs->waiting);
62
Tilman Schmidtabfd1dc2006-04-10 22:55:12 -070063 mutex_unlock(&cs->mutex);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080064
65 return count;
66}
67
68static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
69
70/* free sysfs for device */
Tilman Schmidtb1d47462006-04-10 22:55:07 -070071void gigaset_free_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, "removing sysfs entries");
Tilman Schmidtb1d47462006-04-10 22:55:07 -070074 device_remove_file(cs->dev, &dev_attr_cidmode);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080075}
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080076
77/* initialize sysfs for device */
Tilman Schmidtb1d47462006-04-10 22:55:07 -070078void gigaset_init_dev_sysfs(struct cardstate *cs)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080079{
Tilman Schmidt784d5852006-04-10 22:55:04 -070080 gig_dbg(DEBUG_INIT, "setting up sysfs");
Tilman Schmidtb1d47462006-04-10 22:55:07 -070081 device_create_file(cs->dev, &dev_attr_cidmode);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080082}