proc.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Stuff used by all variants of the driver
  3. *
  4. * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>,
  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 usb_interface *intf = to_usb_interface(dev);
  21. struct cardstate *cs = usb_get_intfdata(intf);
  22. return sprintf(buf, "%d\n", atomic_read(&cs->cidmode));
  23. }
  24. static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr,
  25. const char *buf, size_t count)
  26. {
  27. struct usb_interface *intf = to_usb_interface(dev);
  28. struct cardstate *cs = usb_get_intfdata(intf);
  29. long int value;
  30. char *end;
  31. value = simple_strtol(buf, &end, 0);
  32. while (*end)
  33. if (!isspace(*end++))
  34. return -EINVAL;
  35. if (value < 0 || value > 1)
  36. return -EINVAL;
  37. if (down_interruptible(&cs->sem))
  38. return -ERESTARTSYS; // FIXME -EINTR?
  39. cs->waiting = 1;
  40. if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
  41. NULL, value, NULL)) {
  42. cs->waiting = 0;
  43. up(&cs->sem);
  44. return -ENOMEM;
  45. }
  46. gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
  47. gigaset_schedule_event(cs);
  48. wait_event(cs->waitqueue, !cs->waiting);
  49. up(&cs->sem);
  50. return count;
  51. }
  52. static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
  53. /* free sysfs for device */
  54. void gigaset_free_dev_sysfs(struct usb_interface *interface)
  55. {
  56. gig_dbg(DEBUG_INIT, "removing sysfs entries");
  57. device_remove_file(&interface->dev, &dev_attr_cidmode);
  58. }
  59. EXPORT_SYMBOL_GPL(gigaset_free_dev_sysfs);
  60. /* initialize sysfs for device */
  61. void gigaset_init_dev_sysfs(struct usb_interface *interface)
  62. {
  63. gig_dbg(DEBUG_INIT, "setting up sysfs");
  64. device_create_file(&interface->dev, &dev_attr_cidmode);
  65. }
  66. EXPORT_SYMBOL_GPL(gigaset_init_dev_sysfs);