proc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. * ToDo: ...
  15. * =====================================================================
  16. * Version: $Id: proc.c,v 1.5.2.13 2006/02/04 18:28:16 hjlipp Exp $
  17. * =====================================================================
  18. */
  19. #include "gigaset.h"
  20. #include <linux/ctype.h>
  21. static ssize_t show_cidmode(struct device *dev, struct device_attribute *attr, char *buf)
  22. {
  23. struct usb_interface *intf = to_usb_interface(dev);
  24. struct cardstate *cs = usb_get_intfdata(intf);
  25. return sprintf(buf, "%d\n", atomic_read(&cs->cidmode)); // FIXME use scnprintf for 13607 bit architectures (if PAGE_SIZE==4096)
  26. }
  27. static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  28. {
  29. struct usb_interface *intf = to_usb_interface(dev);
  30. struct cardstate *cs = usb_get_intfdata(intf);
  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 (down_interruptible(&cs->sem))
  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. up(&cs->sem);
  46. return -ENOMEM;
  47. }
  48. dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
  49. gigaset_schedule_event(cs);
  50. wait_event(cs->waitqueue, !cs->waiting);
  51. up(&cs->sem);
  52. return count;
  53. }
  54. static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
  55. /* free sysfs for device */
  56. void gigaset_free_dev_sysfs(struct usb_interface *interface)
  57. {
  58. dbg(DEBUG_INIT, "removing sysfs entries");
  59. device_remove_file(&interface->dev, &dev_attr_cidmode);
  60. }
  61. EXPORT_SYMBOL_GPL(gigaset_free_dev_sysfs);
  62. /* initialize sysfs for device */
  63. void gigaset_init_dev_sysfs(struct usb_interface *interface)
  64. {
  65. dbg(DEBUG_INIT, "setting up sysfs");
  66. device_create_file(&interface->dev, &dev_attr_cidmode);
  67. }
  68. EXPORT_SYMBOL_GPL(gigaset_init_dev_sysfs);