blob: 9ae3a7f3e7b3724982ce68bc75a37ae215766a6a [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"
17#include <linux/ctype.h>
18
Hansjoerg Lipp3dda4e32006-04-22 18:43:00 +020019static ssize_t show_cidmode(struct class_device *class, char *buf)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080020{
Tilman Schmidt69049cc2006-04-10 22:55:16 -070021 int ret;
22 unsigned long flags;
Hansjoerg Lipp3dda4e32006-04-22 18:43:00 +020023 struct cardstate *cs = class_get_devdata(class);
Tilman Schmidt69049cc2006-04-10 22:55:16 -070024
25 spin_lock_irqsave(&cs->lock, flags);
26 ret = sprintf(buf, "%u\n", cs->cidmode);
27 spin_unlock_irqrestore(&cs->lock, flags);
28
29 return ret;
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080030}
31
Hansjoerg Lipp3dda4e32006-04-22 18:43:00 +020032static ssize_t set_cidmode(struct class_device *class,
Tilman Schmidt917f5082006-04-10 22:55:00 -070033 const char *buf, size_t count)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080034{
Hansjoerg Lipp3dda4e32006-04-22 18:43:00 +020035 struct cardstate *cs = class_get_devdata(class);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080036 long int value;
37 char *end;
38
39 value = simple_strtol(buf, &end, 0);
40 while (*end)
41 if (!isspace(*end++))
42 return -EINVAL;
43 if (value < 0 || value > 1)
44 return -EINVAL;
45
Tilman Schmidtabfd1dc2006-04-10 22:55:12 -070046 if (mutex_lock_interruptible(&cs->mutex))
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080047 return -ERESTARTSYS; // FIXME -EINTR?
48
49 cs->waiting = 1;
50 if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
Tilman Schmidt784d5852006-04-10 22:55:04 -070051 NULL, value, NULL)) {
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080052 cs->waiting = 0;
Tilman Schmidtabfd1dc2006-04-10 22:55:12 -070053 mutex_unlock(&cs->mutex);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080054 return -ENOMEM;
55 }
56
Tilman Schmidt784d5852006-04-10 22:55:04 -070057 gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080058 gigaset_schedule_event(cs);
59
60 wait_event(cs->waitqueue, !cs->waiting);
61
Tilman Schmidtabfd1dc2006-04-10 22:55:12 -070062 mutex_unlock(&cs->mutex);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080063
64 return count;
65}
66
Hansjoerg Lipp3dda4e32006-04-22 18:43:00 +020067static CLASS_DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080068
69/* free sysfs for device */
Tilman Schmidtb1d47462006-04-10 22:55:07 -070070void gigaset_free_dev_sysfs(struct cardstate *cs)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080071{
Hansjoerg Lipp3dda4e32006-04-22 18:43:00 +020072 if (!cs->class)
73 return;
74
Tilman Schmidt784d5852006-04-10 22:55:04 -070075 gig_dbg(DEBUG_INIT, "removing sysfs entries");
Hansjoerg Lipp3dda4e32006-04-22 18:43:00 +020076 class_device_remove_file(cs->class, &class_device_attr_cidmode);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080077}
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080078
79/* initialize sysfs for device */
Tilman Schmidtb1d47462006-04-10 22:55:07 -070080void gigaset_init_dev_sysfs(struct cardstate *cs)
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080081{
Hansjoerg Lipp3dda4e32006-04-22 18:43:00 +020082 if (!cs->class)
83 return;
84
Tilman Schmidt784d5852006-04-10 22:55:04 -070085 gig_dbg(DEBUG_INIT, "setting up sysfs");
Hansjoerg Lipp3dda4e32006-04-22 18:43:00 +020086 class_device_create_file(cs->class, &class_device_attr_cidmode);
Hansjoerg Lipp982da5a2006-03-26 01:38:33 -080087}