proc.c 2.24 KB
Newer Older
1
2
3
/*
 * Stuff used by all variants of the driver
 *
4
 * Copyright (c) 2001 by Stefan Eilers,
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 *                       Hansjoerg Lipp <hjlipp@web.de>,
 *                       Tilman Schmidt <tilman@imap.cc>.
 *
 * =====================================================================
 *	This program is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License as
 *	published by the Free Software Foundation; either version 2 of
 *	the License, or (at your option) any later version.
 * =====================================================================
 */

#include "gigaset.h"
#include <linux/ctype.h>

19
static ssize_t show_cidmode(struct class_device *class, char *buf)
20
{
21
22
	int ret;
	unsigned long flags;
23
	struct cardstate *cs = class_get_devdata(class);
24
25
26
27
28
29

	spin_lock_irqsave(&cs->lock, flags);
	ret = sprintf(buf, "%u\n", cs->cidmode);
	spin_unlock_irqrestore(&cs->lock, flags);

	return ret;
30
31
}

32
static ssize_t set_cidmode(struct class_device *class,
33
			   const char *buf, size_t count)
34
{
35
	struct cardstate *cs = class_get_devdata(class);
36
37
38
39
40
41
42
43
44
45
	long int value;
	char *end;

	value = simple_strtol(buf, &end, 0);
	while (*end)
		if (!isspace(*end++))
			return -EINVAL;
	if (value < 0 || value > 1)
			return -EINVAL;

46
	if (mutex_lock_interruptible(&cs->mutex))
47
48
49
50
		return -ERESTARTSYS; // FIXME -EINTR?

	cs->waiting = 1;
	if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
51
			       NULL, value, NULL)) {
52
		cs->waiting = 0;
53
		mutex_unlock(&cs->mutex);
54
55
56
		return -ENOMEM;
	}

57
	gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
58
59
60
61
	gigaset_schedule_event(cs);

	wait_event(cs->waitqueue, !cs->waiting);

62
	mutex_unlock(&cs->mutex);
63
64
65
66

	return count;
}

67
static CLASS_DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
68
69

/* free sysfs for device */
70
void gigaset_free_dev_sysfs(struct cardstate *cs)
71
{
72
73
74
	if (!cs->class)
		return;

75
	gig_dbg(DEBUG_INIT, "removing sysfs entries");
76
	class_device_remove_file(cs->class, &class_device_attr_cidmode);
77
78
79
}

/* initialize sysfs for device */
80
void gigaset_init_dev_sysfs(struct cardstate *cs)
81
{
82
83
84
	if (!cs->class)
		return;

85
	gig_dbg(DEBUG_INIT, "setting up sysfs");
86
87
	if (class_device_create_file(cs->class, &class_device_attr_cidmode))
		dev_err(cs->dev, "could not create sysfs attribute\n");
88
}