proc.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. int ret;
  21. unsigned long flags;
  22. struct cardstate *cs = dev_get_drvdata(dev);
  23. spin_lock_irqsave(&cs->lock, flags);
  24. ret = sprintf(buf, "%u\n", cs->cidmode);
  25. spin_unlock_irqrestore(&cs->lock, flags);
  26. return ret;
  27. }
  28. static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr,
  29. const char *buf, size_t count)
  30. {
  31. struct cardstate *cs = dev_get_drvdata(dev);
  32. long int value;
  33. char *end;
  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. if (mutex_lock_interruptible(&cs->mutex))
  41. return -ERESTARTSYS; // FIXME -EINTR?
  42. cs->waiting = 1;
  43. if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
  44. NULL, value, NULL)) {
  45. cs->waiting = 0;
  46. mutex_unlock(&cs->mutex);
  47. return -ENOMEM;
  48. }
  49. gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
  50. gigaset_schedule_event(cs);
  51. wait_event(cs->waitqueue, !cs->waiting);
  52. mutex_unlock(&cs->mutex);
  53. return count;
  54. }
  55. static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
  56. /* free sysfs for device */
  57. void gigaset_free_dev_sysfs(struct cardstate *cs)
  58. {
  59. if (!cs->tty_dev)
  60. return;
  61. gig_dbg(DEBUG_INIT, "removing sysfs entries");
  62. device_remove_file(cs->tty_dev, &dev_attr_cidmode);
  63. }
  64. /* initialize sysfs for device */
  65. void gigaset_init_dev_sysfs(struct cardstate *cs)
  66. {
  67. if (!cs->tty_dev)
  68. return;
  69. gig_dbg(DEBUG_INIT, "setting up sysfs");
  70. if (device_create_file(cs->tty_dev, &dev_attr_cidmode))
  71. dev_err(cs->dev, "could not create sysfs attribute\n");
  72. }