olpc-xo1.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Support for 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/module.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"
  21. /* PMC registers (PMS block) */
  22. #define PM_SCLK 0x10
  23. #define PM_IN_SLPCTL 0x20
  24. #define PM_WKXD 0x34
  25. #define PM_WKD 0x30
  26. #define PM_SSC 0x54
  27. /* PM registers (ACPI block) */
  28. #define PM1_CNT 0x08
  29. #define PM_GPE0_STS 0x18
  30. static unsigned long acpi_base;
  31. static unsigned long pms_base;
  32. static void xo1_power_off(void)
  33. {
  34. printk(KERN_INFO "OLPC XO-1 power off sequence...\n");
  35. /* Enable all of these controls with 0 delay */
  36. outl(0x40000000, pms_base + PM_SCLK);
  37. outl(0x40000000, pms_base + PM_IN_SLPCTL);
  38. outl(0x40000000, pms_base + PM_WKXD);
  39. outl(0x40000000, pms_base + PM_WKD);
  40. /* Clear status bits (possibly unnecessary) */
  41. outl(0x0002ffff, pms_base + PM_SSC);
  42. outl(0xffffffff, acpi_base + PM_GPE0_STS);
  43. /* Write SLP_EN bit to start the machinery */
  44. outl(0x00002000, acpi_base + PM1_CNT);
  45. }
  46. static int __devinit olpc_xo1_probe(struct platform_device *pdev)
  47. {
  48. struct resource *res;
  49. int err;
  50. /* don't run on non-XOs */
  51. if (!machine_is_olpc())
  52. return -ENODEV;
  53. err = mfd_cell_enable(pdev);
  54. if (err)
  55. return err;
  56. res = platform_get_resource(pdev, IORESOURCE_IO, 0);
  57. if (!res) {
  58. dev_err(&pdev->dev, "can't fetch device resource info\n");
  59. return -EIO;
  60. }
  61. if (strcmp(pdev->name, "cs5535-pms") == 0)
  62. pms_base = res->start;
  63. else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
  64. acpi_base = res->start;
  65. /* If we have both addresses, we can override the poweroff hook */
  66. if (pms_base && acpi_base) {
  67. pm_power_off = xo1_power_off;
  68. printk(KERN_INFO "OLPC XO-1 support registered\n");
  69. }
  70. return 0;
  71. }
  72. static int __devexit olpc_xo1_remove(struct platform_device *pdev)
  73. {
  74. mfd_cell_disable(pdev);
  75. if (strcmp(pdev->name, "cs5535-pms") == 0)
  76. pms_base = 0;
  77. else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
  78. acpi_base = 0;
  79. pm_power_off = NULL;
  80. return 0;
  81. }
  82. static struct platform_driver cs5535_pms_drv = {
  83. .driver = {
  84. .name = "cs5535-pms",
  85. .owner = THIS_MODULE,
  86. },
  87. .probe = olpc_xo1_probe,
  88. .remove = __devexit_p(olpc_xo1_remove),
  89. };
  90. static struct platform_driver cs5535_acpi_drv = {
  91. .driver = {
  92. .name = "olpc-xo1-pm-acpi",
  93. .owner = THIS_MODULE,
  94. },
  95. .probe = olpc_xo1_probe,
  96. .remove = __devexit_p(olpc_xo1_remove),
  97. };
  98. static int __init olpc_xo1_init(void)
  99. {
  100. int r;
  101. r = platform_driver_register(&cs5535_pms_drv);
  102. if (r)
  103. return r;
  104. r = platform_driver_register(&cs5535_acpi_drv);
  105. if (r)
  106. platform_driver_unregister(&cs5535_pms_drv);
  107. return r;
  108. }
  109. static void __exit olpc_xo1_exit(void)
  110. {
  111. platform_driver_unregister(&cs5535_acpi_drv);
  112. platform_driver_unregister(&cs5535_pms_drv);
  113. }
  114. MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>");
  115. MODULE_LICENSE("GPL");
  116. MODULE_ALIAS("platform:cs5535-pms");
  117. module_init(olpc_xo1_init);
  118. module_exit(olpc_xo1_exit);