proc.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. static ssize_t show_cidmode(struct device *dev,
  17. struct device_attribute *attr, char *buf)
  18. {
  19. struct cardstate *cs = dev_get_drvdata(dev);
  20. return sprintf(buf, "%u\n", cs->cidmode);
  21. }
  22. static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr,
  23. const char *buf, size_t count)
  24. {
  25. struct cardstate *cs = dev_get_drvdata(dev);
  26. long int value;
  27. char *end;
  28. value = simple_strtol(buf, &end, 0);
  29. while (*end)
  30. if (!isspace(*end++))
  31. return -EINVAL;
  32. if (value < 0 || value > 1)
  33. return -EINVAL;
  34. if (mutex_lock_interruptible(&cs->mutex))
  35. return -ERESTARTSYS;
  36. cs->waiting = 1;
  37. if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
  38. NULL, value, NULL)) {
  39. cs->waiting = 0;
  40. mutex_unlock(&cs->mutex);
  41. return -ENOMEM;
  42. }
  43. gigaset_schedule_event(cs);
  44. wait_event(cs->waitqueue, !cs->waiting);
  45. mutex_unlock(&cs->mutex);
  46. return count;
  47. }
  48. static DEVICE_ATTR(cidmode, S_IRUGO | S_IWUSR, show_cidmode, set_cidmode);
  49. /* free sysfs for device */
  50. void gigaset_free_dev_sysfs(struct cardstate *cs)
  51. {
  52. if (!cs->tty_dev)
  53. return;
  54. gig_dbg(DEBUG_INIT, "removing sysfs entries");
  55. device_remove_file(cs->tty_dev, &dev_attr_cidmode);
  56. }
  57. /* initialize sysfs for device */
  58. void gigaset_init_dev_sysfs(struct cardstate *cs)
  59. {
  60. if (!cs->tty_dev)
  61. return;
  62. gig_dbg(DEBUG_INIT, "setting up sysfs");
  63. if (device_create_file(cs->tty_dev, &dev_attr_cidmode))
  64. pr_err("could not create sysfs attribute\n");
  65. }