2006-03-26 04:38:33 -05:00
|
|
|
/*
|
|
|
|
* Stuff used by all variants of the driver
|
|
|
|
*
|
2006-04-11 01:55:14 -04:00
|
|
|
* Copyright (c) 2001 by Stefan Eilers,
|
2006-03-26 04:38:33 -05:00
|
|
|
* 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>
|
|
|
|
|
2006-04-22 12:43:00 -04:00
|
|
|
static ssize_t show_cidmode(struct class_device *class, char *buf)
|
2006-03-26 04:38:33 -05:00
|
|
|
{
|
2006-04-11 01:55:16 -04:00
|
|
|
int ret;
|
|
|
|
unsigned long flags;
|
2006-04-22 12:43:00 -04:00
|
|
|
struct cardstate *cs = class_get_devdata(class);
|
2006-04-11 01:55:16 -04:00
|
|
|
|
|
|
|
spin_lock_irqsave(&cs->lock, flags);
|
|
|
|
ret = sprintf(buf, "%u\n", cs->cidmode);
|
|
|
|
spin_unlock_irqrestore(&cs->lock, flags);
|
|
|
|
|
|
|
|
return ret;
|
2006-03-26 04:38:33 -05:00
|
|
|
}
|
|
|
|
|
2006-04-22 12:43:00 -04:00
|
|
|
static ssize_t set_cidmode(struct class_device *class,
|
2006-04-11 01:55:00 -04:00
|
|
|
const char *buf, size_t count)
|
2006-03-26 04:38:33 -05:00
|
|
|
{
|
2006-04-22 12:43:00 -04:00
|
|
|
struct cardstate *cs = class_get_devdata(class);
|
2006-03-26 04:38:33 -05:00
|
|
|
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;
|
|
|
|
|
2006-04-11 01:55:12 -04:00
|
|
|
if (mutex_lock_interruptible(&cs->mutex))
|
2006-03-26 04:38:33 -05:00
|
|
|
return -ERESTARTSYS; // FIXME -EINTR?
|
|
|
|
|
|
|
|
cs->waiting = 1;
|
|
|
|
if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
|
2006-04-11 01:55:04 -04:00
|
|
|
NULL, value, NULL)) {
|
2006-03-26 04:38:33 -05:00
|
|
|
cs->waiting = 0;
|
2006-04-11 01:55:12 -04:00
|
|
|
mutex_unlock(&cs->mutex);
|
2006-03-26 04:38:33 -05:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2006-04-11 01:55:04 -04:00
|
|
|
gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
|
2006-03-26 04:38:33 -05:00
|
|
|
gigaset_schedule_event(cs);
|
|
|
|
|
|
|
|
wait_event(cs->waitqueue, !cs->waiting);
|
|
|
|
|
2006-04-11 01:55:12 -04:00
|
|
|
mutex_unlock(&cs->mutex);
|
2006-03-26 04:38:33 -05:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-04-22 12:43:00 -04:00
|
|
|
static CLASS_DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
|
2006-03-26 04:38:33 -05:00
|
|
|
|
|
|
|
/* free sysfs for device */
|
2006-04-11 01:55:07 -04:00
|
|
|
void gigaset_free_dev_sysfs(struct cardstate *cs)
|
2006-03-26 04:38:33 -05:00
|
|
|
{
|
2006-04-22 12:43:00 -04:00
|
|
|
if (!cs->class)
|
|
|
|
return;
|
|
|
|
|
2006-04-11 01:55:04 -04:00
|
|
|
gig_dbg(DEBUG_INIT, "removing sysfs entries");
|
2006-04-22 12:43:00 -04:00
|
|
|
class_device_remove_file(cs->class, &class_device_attr_cidmode);
|
2006-03-26 04:38:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize sysfs for device */
|
2006-04-11 01:55:07 -04:00
|
|
|
void gigaset_init_dev_sysfs(struct cardstate *cs)
|
2006-03-26 04:38:33 -05:00
|
|
|
{
|
2006-04-22 12:43:00 -04:00
|
|
|
if (!cs->class)
|
|
|
|
return;
|
|
|
|
|
2006-04-11 01:55:04 -04:00
|
|
|
gig_dbg(DEBUG_INIT, "setting up sysfs");
|
2006-10-02 05:17:37 -04:00
|
|
|
if (class_device_create_file(cs->class, &class_device_attr_cidmode))
|
|
|
|
dev_err(cs->dev, "could not create sysfs attribute\n");
|
2006-03-26 04:38:33 -05:00
|
|
|
}
|