olpc-xo1.c 3.4 KB

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