• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Stuff used by all variants of the driver
4  *
5  * Copyright (c) 2001 by Stefan Eilers,
6  *                       Hansjoerg Lipp <hjlipp@web.de>,
7  *                       Tilman Schmidt <tilman@imap.cc>.
8  *
9  * =====================================================================
10  * =====================================================================
11  */
12 
13 #include "gigaset.h"
14 
show_cidmode(struct device * dev,struct device_attribute * attr,char * buf)15 static ssize_t show_cidmode(struct device *dev,
16 			    struct device_attribute *attr, char *buf)
17 {
18 	struct cardstate *cs = dev_get_drvdata(dev);
19 
20 	return sprintf(buf, "%u\n", cs->cidmode);
21 }
22 
set_cidmode(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)23 static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr,
24 			   const char *buf, size_t count)
25 {
26 	struct cardstate *cs = dev_get_drvdata(dev);
27 	long int value;
28 	char *end;
29 
30 	value = simple_strtol(buf, &end, 0);
31 	while (*end)
32 		if (!isspace(*end++))
33 			return -EINVAL;
34 	if (value < 0 || value > 1)
35 		return -EINVAL;
36 
37 	if (mutex_lock_interruptible(&cs->mutex))
38 		return -ERESTARTSYS;
39 
40 	cs->waiting = 1;
41 	if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
42 			       NULL, value, NULL)) {
43 		cs->waiting = 0;
44 		mutex_unlock(&cs->mutex);
45 		return -ENOMEM;
46 	}
47 	gigaset_schedule_event(cs);
48 
49 	wait_event(cs->waitqueue, !cs->waiting);
50 
51 	mutex_unlock(&cs->mutex);
52 
53 	return count;
54 }
55 
56 static DEVICE_ATTR(cidmode, S_IRUGO | S_IWUSR, show_cidmode, set_cidmode);
57 
58 /* free sysfs for device */
gigaset_free_dev_sysfs(struct cardstate * cs)59 void gigaset_free_dev_sysfs(struct cardstate *cs)
60 {
61 	if (!cs->tty_dev)
62 		return;
63 
64 	gig_dbg(DEBUG_INIT, "removing sysfs entries");
65 	device_remove_file(cs->tty_dev, &dev_attr_cidmode);
66 }
67 
68 /* initialize sysfs for device */
gigaset_init_dev_sysfs(struct cardstate * cs)69 void gigaset_init_dev_sysfs(struct cardstate *cs)
70 {
71 	if (!cs->tty_dev)
72 		return;
73 
74 	gig_dbg(DEBUG_INIT, "setting up sysfs");
75 	if (device_create_file(cs->tty_dev, &dev_attr_cidmode))
76 		pr_err("could not create sysfs attribute\n");
77 }
78