linux/drivers/isdn/gigaset/proc.c
<<
>>
Prefs
   1/*
   2 * Stuff used by all variants of the driver
   3 *
   4 * Copyright (c) 2001 by Stefan Eilers,
   5 *                       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 * =====================================================================
  14 */
  15
  16#include "gigaset.h"
  17#include <linux/ctype.h>
  18
  19static ssize_t show_cidmode(struct device *dev,
  20                            struct device_attribute *attr, char *buf)
  21{
  22        struct cardstate *cs = dev_get_drvdata(dev);
  23
  24        return sprintf(buf, "%u\n", cs->cidmode);
  25}
  26
  27static 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        long int value;
  32        char *end;
  33
  34        value = simple_strtol(buf, &end, 0);
  35        while (*end)
  36                if (!isspace(*end++))
  37                        return -EINVAL;
  38        if (value < 0 || value > 1)
  39                        return -EINVAL;
  40
  41        if (mutex_lock_interruptible(&cs->mutex))
  42                return -ERESTARTSYS; // FIXME -EINTR?
  43
  44        cs->waiting = 1;
  45        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                return -ENOMEM;
  50        }
  51
  52        gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
  53        gigaset_schedule_event(cs);
  54
  55        wait_event(cs->waitqueue, !cs->waiting);
  56
  57        mutex_unlock(&cs->mutex);
  58
  59        return count;
  60}
  61
  62static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
  63
  64/* free sysfs for device */
  65void gigaset_free_dev_sysfs(struct cardstate *cs)
  66{
  67        if (!cs->tty_dev)
  68                return;
  69
  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 */
  75void gigaset_init_dev_sysfs(struct cardstate *cs)
  76{
  77        if (!cs->tty_dev)
  78                return;
  79
  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}
  84