olpc-xo1-pm.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Support for power management features of the OLPC XO-1 laptop
  3. *
  4. * Copyright (C) 2010 Andres Salomon <dilinger@queued.net>
  5. * Copyright (C) 2010 One Laptop per Child
  6. * Copyright (C) 2006 Red Hat, Inc.
  7. * Copyright (C) 2006 Advanced Micro Devices, Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. */
  14. #include <linux/cs5535.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/pm.h>
  17. #include <linux/mfd/core.h>
  18. #include <asm/io.h>
  19. #include <asm/olpc.h>
  20. #define DRV_NAME "olpc-xo1-pm"
  21. static unsigned long acpi_base;
  22. static unsigned long pms_base;
  23. static void xo1_power_off(void)
  24. {
  25. printk(KERN_INFO "OLPC XO-1 power off sequence...\n");
  26. /* Enable all of these controls with 0 delay */
  27. outl(0x40000000, pms_base + CS5536_PM_SCLK);
  28. outl(0x40000000, pms_base + CS5536_PM_IN_SLPCTL);
  29. outl(0x40000000, pms_base + CS5536_PM_WKXD);
  30. outl(0x40000000, pms_base + CS5536_PM_WKD);
  31. /* Clear status bits (possibly unnecessary) */
  32. outl(0x0002ffff, pms_base + CS5536_PM_SSC);
  33. outl(0xffffffff, acpi_base + CS5536_PM_GPE0_STS);
  34. /* Write SLP_EN bit to start the machinery */
  35. outl(0x00002000, acpi_base + CS5536_PM1_CNT);
  36. }
  37. static int __devinit xo1_pm_probe(struct platform_device *pdev)
  38. {
  39. struct resource *res;
  40. int err;
  41. /* don't run on non-XOs */
  42. if (!machine_is_olpc())
  43. return -ENODEV;
  44. err = mfd_cell_enable(pdev);
  45. if (err)
  46. return err;
  47. res = platform_get_resource(pdev, IORESOURCE_IO, 0);
  48. if (!res) {
  49. dev_err(&pdev->dev, "can't fetch device resource info\n");
  50. return -EIO;
  51. }
  52. if (strcmp(pdev->name, "cs5535-pms") == 0)
  53. pms_base = res->start;
  54. else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
  55. acpi_base = res->start;
  56. /* If we have both addresses, we can override the poweroff hook */
  57. if (pms_base && acpi_base) {
  58. pm_power_off = xo1_power_off;
  59. printk(KERN_INFO "OLPC XO-1 support registered\n");
  60. }
  61. return 0;
  62. }
  63. static int __devexit xo1_pm_remove(struct platform_device *pdev)
  64. {
  65. mfd_cell_disable(pdev);
  66. if (strcmp(pdev->name, "cs5535-pms") == 0)
  67. pms_base = 0;
  68. else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
  69. acpi_base = 0;
  70. pm_power_off = NULL;
  71. return 0;
  72. }
  73. static struct platform_driver cs5535_pms_driver = {
  74. .driver = {
  75. .name = "cs5535-pms",
  76. .owner = THIS_MODULE,
  77. },
  78. .probe = xo1_pm_probe,
  79. .remove = __devexit_p(xo1_pm_remove),
  80. };
  81. static struct platform_driver cs5535_acpi_driver = {
  82. .driver = {
  83. .name = "olpc-xo1-pm-acpi",
  84. .owner = THIS_MODULE,
  85. },
  86. .probe = xo1_pm_probe,
  87. .remove = __devexit_p(xo1_pm_remove),
  88. };
  89. static int __init xo1_pm_init(void)
  90. {
  91. int r;
  92. r = platform_driver_register(&cs5535_pms_driver);
  93. if (r)
  94. return r;
  95. r = platform_driver_register(&cs5535_acpi_driver);
  96. if (r)
  97. platform_driver_unregister(&cs5535_pms_driver);
  98. return r;
  99. }
  100. arch_initcall(xo1_pm_init);