olpc-xo1.c 3.2 KB

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