power.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Interface for power-management for ppc64 compliant platform
  4. *
  5. * Manish Ahuja <[email protected]>
  6. *
  7. * Feb 2007
  8. *
  9. * Copyright (C) 2007 IBM Corporation.
  10. */
  11. #include <linux/kobject.h>
  12. #include <linux/string.h>
  13. #include <linux/errno.h>
  14. #include <linux/init.h>
  15. #include <asm/machdep.h>
  16. #include "pseries.h"
  17. unsigned long rtas_poweron_auto; /* default and normal state is 0 */
  18. static ssize_t auto_poweron_show(struct kobject *kobj,
  19. struct kobj_attribute *attr, char *buf)
  20. {
  21. return sprintf(buf, "%lu\n", rtas_poweron_auto);
  22. }
  23. static ssize_t auto_poweron_store(struct kobject *kobj,
  24. struct kobj_attribute *attr,
  25. const char *buf, size_t n)
  26. {
  27. int ret;
  28. unsigned long ups_restart;
  29. ret = sscanf(buf, "%lu", &ups_restart);
  30. if ((ret == 1) && ((ups_restart == 1) || (ups_restart == 0))){
  31. rtas_poweron_auto = ups_restart;
  32. return n;
  33. }
  34. return -EINVAL;
  35. }
  36. static struct kobj_attribute auto_poweron_attr =
  37. __ATTR(auto_poweron, 0644, auto_poweron_show, auto_poweron_store);
  38. #ifndef CONFIG_PM
  39. struct kobject *power_kobj;
  40. static struct attribute *g[] = {
  41. &auto_poweron_attr.attr,
  42. NULL,
  43. };
  44. static const struct attribute_group attr_group = {
  45. .attrs = g,
  46. };
  47. static int __init pm_init(void)
  48. {
  49. power_kobj = kobject_create_and_add("power", NULL);
  50. if (!power_kobj)
  51. return -ENOMEM;
  52. return sysfs_create_group(power_kobj, &attr_group);
  53. }
  54. machine_core_initcall(pseries, pm_init);
  55. #else
  56. static int __init apo_pm_init(void)
  57. {
  58. return (sysfs_create_file(power_kobj, &auto_poweron_attr.attr));
  59. }
  60. machine_device_initcall(pseries, apo_pm_init);
  61. #endif