blob: e3f9d0f089fa1195c97682c15784eb0b295d9feb [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"
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080017
Greg Kroah-Hartman01107d32006-08-07 22:19:37 -070018static ssize_t show_cidmode(struct device *dev,
19 struct device_attribute *attr, char *buf)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080020{
Greg Kroah-Hartman01107d32006-08-07 22:19:37 -070021 struct cardstate *cs = dev_get_drvdata(dev);
Tilman Schmidt69049cc2006-04-10 22:55:16 -070022
Tilman Schmidt4d1ff582007-10-16 01:27:50 -070023 return sprintf(buf, "%u\n", cs->cidmode);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080024}
25
Greg Kroah-Hartman01107d32006-08-07 22:19:37 -070026static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr,
Tilman Schmidt917f5082006-04-10 22:55:00 -070027 const char *buf, size_t count)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080028{
Greg Kroah-Hartman01107d32006-08-07 22:19:37 -070029 struct cardstate *cs = dev_get_drvdata(dev);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080030 long int value;
31 char *end;
32
33 value = simple_strtol(buf, &end, 0);
34 while (*end)
35 if (!isspace(*end++))
36 return -EINVAL;
37 if (value < 0 || value > 1)
Joe Perches475be4d2012-02-19 19:52:38 -080038 return -EINVAL;
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080039
Tilman Schmidtabfd1dc2006-04-10 22:55:12 -070040 if (mutex_lock_interruptible(&cs->mutex))
Tilman Schmidtd9ba9c92009-10-25 09:30:17 +000041 return -ERESTARTSYS;
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080042
43 cs->waiting = 1;
44 if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
Tilman Schmidt784d5852006-04-10 22:55:04 -070045 NULL, value, NULL)) {
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080046 cs->waiting = 0;
Tilman Schmidtabfd1dc2006-04-10 22:55:12 -070047 mutex_unlock(&cs->mutex);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080048 return -ENOMEM;
49 }
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080050 gigaset_schedule_event(cs);
51
52 wait_event(cs->waitqueue, !cs->waiting);
53
Tilman Schmidtabfd1dc2006-04-10 22:55:12 -070054 mutex_unlock(&cs->mutex);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080055
56 return count;
57}
58
Joe Perches475be4d2012-02-19 19:52:38 -080059static DEVICE_ATTR(cidmode, S_IRUGO | S_IWUSR, show_cidmode, set_cidmode);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080060
61/* free sysfs for device */
Tilman Schmidtb1d47462006-04-10 22:55:07 -070062void gigaset_free_dev_sysfs(struct cardstate *cs)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080063{
Greg Kroah-Hartman01107d32006-08-07 22:19:37 -070064 if (!cs->tty_dev)
Hansjoerg Lipp3dda4e32006-04-22 18:43:00 +020065 return;
66
Tilman Schmidt784d5852006-04-10 22:55:04 -070067 gig_dbg(DEBUG_INIT, "removing sysfs entries");
Greg Kroah-Hartman01107d32006-08-07 22:19:37 -070068 device_remove_file(cs->tty_dev, &dev_attr_cidmode);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080069}
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080070
71/* initialize sysfs for device */
Tilman Schmidtb1d47462006-04-10 22:55:07 -070072void gigaset_init_dev_sysfs(struct cardstate *cs)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080073{
Greg Kroah-Hartman01107d32006-08-07 22:19:37 -070074 if (!cs->tty_dev)
Hansjoerg Lipp3dda4e32006-04-22 18:43:00 +020075 return;
76
Tilman Schmidt784d5852006-04-10 22:55:04 -070077 gig_dbg(DEBUG_INIT, "setting up sysfs");
Greg Kroah-Hartman01107d32006-08-07 22:19:37 -070078 if (device_create_file(cs->tty_dev, &dev_attr_cidmode))
Tilman Schmidt42e3d612009-05-13 12:44:17 +000079 pr_err("could not create sysfs attribute\n");
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080080}