interface.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * drivers/base/interface.c - common driverfs interface that's exported to
  3. * the world for all devices.
  4. *
  5. * Copyright (c) 2002-3 Patrick Mochel
  6. * Copyright (c) 2002-3 Open Source Development Labs
  7. *
  8. * This file is released under the GPLv2
  9. *
  10. */
  11. #include <linux/device.h>
  12. #include <linux/err.h>
  13. #include <linux/stat.h>
  14. #include <linux/string.h>
  15. /**
  16. * detach_state - control the default power state for the device.
  17. *
  18. * This is the state the device enters when it's driver module is
  19. * unloaded. The value is an unsigned integer, in the range of 0-4.
  20. * '0' indicates 'On', so no action will be taken when the driver is
  21. * unloaded. This is the default behavior.
  22. * '4' indicates 'Off', meaning the driver core will call the driver's
  23. * shutdown method to quiesce the device.
  24. * 1-3 indicate a low-power state for the device to enter via the
  25. * driver's suspend method.
  26. */
  27. static ssize_t detach_show(struct device * dev, char * buf)
  28. {
  29. return sprintf(buf, "%u\n", dev->detach_state);
  30. }
  31. static ssize_t detach_store(struct device * dev, const char * buf, size_t n)
  32. {
  33. u32 state;
  34. state = simple_strtoul(buf, NULL, 10);
  35. if (state > 4)
  36. return -EINVAL;
  37. dev->detach_state = state;
  38. return n;
  39. }
  40. static DEVICE_ATTR(detach_state, 0644, detach_show, detach_store);
  41. struct attribute * dev_default_attrs[] = {
  42. &dev_attr_detach_state.attr,
  43. NULL,
  44. };