proc.c 2.2 KB

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