proc.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #include "gigaset.h"
  16. #include <linux/ctype.h>
  17. static ssize_t show_cidmode(struct device *dev, struct device_attribute *attr,
  18. char *buf)
  19. {
  20. struct cardstate *cs = dev_get_drvdata(dev);
  21. return sprintf(buf, "%d\n", atomic_read(&cs->cidmode));
  22. }
  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. value = simple_strtol(buf, &end, 0);
  30. while (*end)
  31. if (!isspace(*end++))
  32. return -EINVAL;
  33. if (value < 0 || value > 1)
  34. return -EINVAL;
  35. if (mutex_lock_interruptible(&cs->mutex))
  36. return -ERESTARTSYS; // FIXME -EINTR?
  37. cs->waiting = 1;
  38. if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
  39. NULL, value, NULL)) {
  40. cs->waiting = 0;
  41. mutex_unlock(&cs->mutex);
  42. return -ENOMEM;
  43. }
  44. gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
  45. gigaset_schedule_event(cs);
  46. wait_event(cs->waitqueue, !cs->waiting);
  47. mutex_unlock(&cs->mutex);
  48. return count;
  49. }
  50. static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
  51. /* free sysfs for device */
  52. void gigaset_free_dev_sysfs(struct cardstate *cs)
  53. {
  54. gig_dbg(DEBUG_INIT, "removing sysfs entries");
  55. device_remove_file(cs->dev, &dev_attr_cidmode);
  56. }
  57. /* initialize sysfs for device */
  58. void gigaset_init_dev_sysfs(struct cardstate *cs)
  59. {
  60. gig_dbg(DEBUG_INIT, "setting up sysfs");
  61. device_create_file(cs->dev, &dev_attr_cidmode);
  62. }