olpc-xo1.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Support for features of the OLPC XO-1 laptop
  3. *
  4. * Copyright (C) 2010 One Laptop per Child
  5. * Copyright (C) 2006 Red Hat, Inc.
  6. * Copyright (C) 2006 Advanced Micro Devices, Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/pci.h>
  15. #include <linux/pci_ids.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/pm.h>
  18. #include <asm/io.h>
  19. #include <asm/olpc.h>
  20. #define DRV_NAME "olpc-xo1"
  21. #define PMS_BAR 4
  22. #define ACPI_BAR 5
  23. /* PMC registers (PMS block) */
  24. #define PM_SCLK 0x10
  25. #define PM_IN_SLPCTL 0x20
  26. #define PM_WKXD 0x34
  27. #define PM_WKD 0x30
  28. #define PM_SSC 0x54
  29. /* PM registers (ACPI block) */
  30. #define PM1_CNT 0x08
  31. #define PM_GPE0_STS 0x18
  32. static unsigned long acpi_base;
  33. static unsigned long pms_base;
  34. static void xo1_power_off(void)
  35. {
  36. printk(KERN_INFO "OLPC XO-1 power off sequence...\n");
  37. /* Enable all of these controls with 0 delay */
  38. outl(0x40000000, pms_base + PM_SCLK);
  39. outl(0x40000000, pms_base + PM_IN_SLPCTL);
  40. outl(0x40000000, pms_base + PM_WKXD);
  41. outl(0x40000000, pms_base + PM_WKD);
  42. /* Clear status bits (possibly unnecessary) */
  43. outl(0x0002ffff, pms_base + PM_SSC);
  44. outl(0xffffffff, acpi_base + PM_GPE0_STS);
  45. /* Write SLP_EN bit to start the machinery */
  46. outl(0x00002000, acpi_base + PM1_CNT);
  47. }
  48. /* Read the base addresses from the PCI BAR info */
  49. static int __devinit setup_bases(struct pci_dev *pdev)
  50. {
  51. int r;
  52. r = pci_enable_device_io(pdev);
  53. if (r) {
  54. dev_err(&pdev->dev, "can't enable device IO\n");
  55. return r;
  56. }
  57. r = pci_request_region(pdev, ACPI_BAR, DRV_NAME);
  58. if (r) {
  59. dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", ACPI_BAR);
  60. return r;
  61. }
  62. r = pci_request_region(pdev, PMS_BAR, DRV_NAME);
  63. if (r) {
  64. dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", PMS_BAR);
  65. pci_release_region(pdev, ACPI_BAR);
  66. return r;
  67. }
  68. acpi_base = pci_resource_start(pdev, ACPI_BAR);
  69. pms_base = pci_resource_start(pdev, PMS_BAR);
  70. return 0;
  71. }
  72. static int __devinit olpc_xo1_probe(struct platform_device *pdev)
  73. {
  74. struct pci_dev *pcidev;
  75. int r;
  76. pcidev = pci_get_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA,
  77. NULL);
  78. if (!pdev)
  79. return -ENODEV;
  80. r = setup_bases(pcidev);
  81. if (r)
  82. return r;
  83. pm_power_off = xo1_power_off;
  84. printk(KERN_INFO "OLPC XO-1 support registered\n");
  85. return 0;
  86. }
  87. static int __devexit olpc_xo1_remove(struct platform_device *pdev)
  88. {
  89. pm_power_off = NULL;
  90. return 0;
  91. }
  92. static struct platform_driver olpc_xo1_driver = {
  93. .driver = {
  94. .name = DRV_NAME,
  95. .owner = THIS_MODULE,
  96. },
  97. .probe = olpc_xo1_probe,
  98. .remove = __devexit_p(olpc_xo1_remove),
  99. };
  100. static int __init olpc_xo1_init(void)
  101. {
  102. return platform_driver_register(&olpc_xo1_driver);
  103. }
  104. static void __exit olpc_xo1_exit(void)
  105. {
  106. platform_driver_unregister(&olpc_xo1_driver);
  107. }
  108. MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>");
  109. MODULE_LICENSE("GPL");
  110. MODULE_ALIAS("platform:olpc-xo1");
  111. module_init(olpc_xo1_init);
  112. module_exit(olpc_xo1_exit);