proc.c 2.0 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
 *                       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"

18 19
static ssize_t show_cidmode(struct device *dev,
			    struct device_attribute *attr, char *buf)
20
{
21
	struct cardstate *cs = dev_get_drvdata(dev);
22

T
Tilman Schmidt 已提交
23
	return sprintf(buf, "%u\n", cs->cidmode);
24 25
}

26
static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr,
27
			   const char *buf, size_t count)
28
{
29
	struct cardstate *cs = dev_get_drvdata(dev);
30 31 32 33 34 35 36 37 38 39
	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;

40
	if (mutex_lock_interruptible(&cs->mutex))
T
Tilman Schmidt 已提交
41
		return -ERESTARTSYS;
42 43 44

	cs->waiting = 1;
	if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
45
			       NULL, value, NULL)) {
46
		cs->waiting = 0;
47
		mutex_unlock(&cs->mutex);
48 49 50 51 52 53
		return -ENOMEM;
	}
	gigaset_schedule_event(cs);

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

54
	mutex_unlock(&cs->mutex);
55 56 57 58

	return count;
}

59
static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
60 61

/* free sysfs for device */
62
void gigaset_free_dev_sysfs(struct cardstate *cs)
63
{
64
	if (!cs->tty_dev)
65 66
		return;

67
	gig_dbg(DEBUG_INIT, "removing sysfs entries");
68
	device_remove_file(cs->tty_dev, &dev_attr_cidmode);
69 70 71
}

/* initialize sysfs for device */
72
void gigaset_init_dev_sysfs(struct cardstate *cs)
73
{
74
	if (!cs->tty_dev)
75 76
		return;

77
	gig_dbg(DEBUG_INIT, "setting up sysfs");
78
	if (device_create_file(cs->tty_dev, &dev_attr_cidmode))
79
		pr_err("could not create sysfs attribute\n");
80
}