proc.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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,
  18. struct device_attribute *attr, char *buf)
  19. {
  20. struct cardstate *cs = dev_get_drvdata(dev);
  21. return sprintf(buf, "%u\n", 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. if (!cs->tty_dev)
  55. return;
  56. gig_dbg(DEBUG_INIT, "removing sysfs entries");
  57. device_remove_file(cs->tty_dev, &dev_attr_cidmode);
  58. }
  59. /* initialize sysfs for device */
  60. void gigaset_init_dev_sysfs(struct cardstate *cs)
  61. {
  62. if (!cs->tty_dev)
  63. return;
  64. gig_dbg(DEBUG_INIT, "setting up sysfs");
  65. if (device_create_file(cs->tty_dev, &dev_attr_cidmode))
  66. dev_err(cs->dev, "could not create sysfs attribute\n");
  67. }