proc.c 2.1 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 20
static ssize_t show_cidmode(struct device *dev,
			    struct device_attribute *attr, char *buf)
21
{
22
	struct cardstate *cs = dev_get_drvdata(dev);
23

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

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

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

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

52
	gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
53 54 55 56
	gigaset_schedule_event(cs);

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

57
	mutex_unlock(&cs->mutex);
58 59 60 61

	return count;
}

62
static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
63 64

/* free sysfs for device */
65
void gigaset_free_dev_sysfs(struct cardstate *cs)
66
{
67
	if (!cs->tty_dev)
68 69
		return;

70
	gig_dbg(DEBUG_INIT, "removing sysfs entries");
71
	device_remove_file(cs->tty_dev, &dev_attr_cidmode);
72 73 74
}

/* initialize sysfs for device */
75
void gigaset_init_dev_sysfs(struct cardstate *cs)
76
{
77
	if (!cs->tty_dev)
78 79
		return;

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