power.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Interface for power-management for ppc64 compliant platform
  3. *
  4. * Manish Ahuja <mahuja@us.ibm.com>
  5. *
  6. * Feb 2007
  7. *
  8. * Copyright (C) 2007 IBM Corporation.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; version 2 of the License.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/kobject.h>
  24. #include <linux/string.h>
  25. #include <linux/errno.h>
  26. #include <linux/init.h>
  27. unsigned long rtas_poweron_auto; /* default and normal state is 0 */
  28. static ssize_t auto_poweron_show(struct kset *kset, char *buf)
  29. {
  30. return sprintf(buf, "%lu\n", rtas_poweron_auto);
  31. }
  32. static ssize_t
  33. auto_poweron_store(struct kset *kset, const char *buf, size_t n)
  34. {
  35. int ret;
  36. unsigned long ups_restart;
  37. ret = sscanf(buf, "%lu", &ups_restart);
  38. if ((ret == 1) && ((ups_restart == 1) || (ups_restart == 0))){
  39. rtas_poweron_auto = ups_restart;
  40. return n;
  41. }
  42. return -EINVAL;
  43. }
  44. static struct subsys_attribute auto_poweron_attr = {
  45. .attr = {
  46. .name = __stringify(auto_poweron),
  47. .mode = 0644,
  48. },
  49. .show = auto_poweron_show,
  50. .store = auto_poweron_store,
  51. };
  52. #ifndef CONFIG_PM
  53. decl_subsys(power,NULL,NULL);
  54. static struct attribute *g[] = {
  55. &auto_poweron_attr.attr,
  56. NULL,
  57. };
  58. static struct attribute_group attr_group = {
  59. .attrs = g,
  60. };
  61. static int __init pm_init(void)
  62. {
  63. int error = subsystem_register(&power_subsys);
  64. if (!error)
  65. error = sysfs_create_group(&power_subsys.kobj, &attr_group);
  66. return error;
  67. }
  68. core_initcall(pm_init);
  69. #else
  70. extern struct kset power_subsys;
  71. static int __init apo_pm_init(void)
  72. {
  73. return (subsys_create_file(&power_subsys, &auto_poweron_attr));
  74. }
  75. __initcall(apo_pm_init);
  76. #endif