Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Support for features of the OLPC XO-1 laptop |
| 3 | * |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 4 | * Copyright (C) 2010 Andres Salomon <dilinger@queued.net> |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 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 | |
| 15 | #include <linux/module.h> |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/pm.h> |
Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame] | 18 | #include <linux/mfd/core.h> |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 19 | |
| 20 | #include <asm/io.h> |
| 21 | #include <asm/olpc.h> |
| 22 | |
| 23 | #define DRV_NAME "olpc-xo1" |
| 24 | |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 25 | /* PMC registers (PMS block) */ |
| 26 | #define PM_SCLK 0x10 |
| 27 | #define PM_IN_SLPCTL 0x20 |
| 28 | #define PM_WKXD 0x34 |
| 29 | #define PM_WKD 0x30 |
| 30 | #define PM_SSC 0x54 |
| 31 | |
| 32 | /* PM registers (ACPI block) */ |
| 33 | #define PM1_CNT 0x08 |
| 34 | #define PM_GPE0_STS 0x18 |
| 35 | |
| 36 | static unsigned long acpi_base; |
| 37 | static unsigned long pms_base; |
| 38 | |
| 39 | static void xo1_power_off(void) |
| 40 | { |
| 41 | printk(KERN_INFO "OLPC XO-1 power off sequence...\n"); |
| 42 | |
| 43 | /* Enable all of these controls with 0 delay */ |
| 44 | outl(0x40000000, pms_base + PM_SCLK); |
| 45 | outl(0x40000000, pms_base + PM_IN_SLPCTL); |
| 46 | outl(0x40000000, pms_base + PM_WKXD); |
| 47 | outl(0x40000000, pms_base + PM_WKD); |
| 48 | |
| 49 | /* Clear status bits (possibly unnecessary) */ |
| 50 | outl(0x0002ffff, pms_base + PM_SSC); |
| 51 | outl(0xffffffff, acpi_base + PM_GPE0_STS); |
| 52 | |
| 53 | /* Write SLP_EN bit to start the machinery */ |
| 54 | outl(0x00002000, acpi_base + PM1_CNT); |
| 55 | } |
| 56 | |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 57 | static int __devinit olpc_xo1_probe(struct platform_device *pdev) |
| 58 | { |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 59 | struct resource *res; |
Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame] | 60 | int err; |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 61 | |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 62 | /* don't run on non-XOs */ |
| 63 | if (!machine_is_olpc()) |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 64 | return -ENODEV; |
| 65 | |
Andres Salomon | f77289a | 2011-03-03 09:51:58 -0800 | [diff] [blame] | 66 | err = mfd_cell_enable(pdev); |
Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame] | 67 | if (err) |
| 68 | return err; |
| 69 | |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 70 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 71 | if (!res) { |
| 72 | dev_err(&pdev->dev, "can't fetch device resource info\n"); |
| 73 | return -EIO; |
| 74 | } |
Daniel Drake | adfa4bd | 2011-03-22 13:50:39 -0700 | [diff] [blame^] | 75 | if (strcmp(pdev->name, "cs5535-pms") == 0) |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 76 | pms_base = res->start; |
Daniel Drake | adfa4bd | 2011-03-22 13:50:39 -0700 | [diff] [blame^] | 77 | else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0) |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 78 | acpi_base = res->start; |
| 79 | |
| 80 | /* If we have both addresses, we can override the poweroff hook */ |
| 81 | if (pms_base && acpi_base) { |
| 82 | pm_power_off = xo1_power_off; |
| 83 | printk(KERN_INFO "OLPC XO-1 support registered\n"); |
| 84 | } |
| 85 | |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | static int __devexit olpc_xo1_remove(struct platform_device *pdev) |
| 90 | { |
Andres Salomon | f77289a | 2011-03-03 09:51:58 -0800 | [diff] [blame] | 91 | mfd_cell_disable(pdev); |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 92 | |
Daniel Drake | adfa4bd | 2011-03-22 13:50:39 -0700 | [diff] [blame^] | 93 | if (strcmp(pdev->name, "cs5535-pms") == 0) |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 94 | pms_base = 0; |
Daniel Drake | adfa4bd | 2011-03-22 13:50:39 -0700 | [diff] [blame^] | 95 | else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0) |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 96 | acpi_base = 0; |
| 97 | |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 98 | pm_power_off = NULL; |
| 99 | return 0; |
| 100 | } |
| 101 | |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 102 | static struct platform_driver cs5535_pms_drv = { |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 103 | .driver = { |
Daniel Drake | adfa4bd | 2011-03-22 13:50:39 -0700 | [diff] [blame^] | 104 | .name = "cs5535-pms", |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 105 | .owner = THIS_MODULE, |
| 106 | }, |
| 107 | .probe = olpc_xo1_probe, |
| 108 | .remove = __devexit_p(olpc_xo1_remove), |
| 109 | }; |
| 110 | |
| 111 | static struct platform_driver cs5535_acpi_drv = { |
| 112 | .driver = { |
Daniel Drake | adfa4bd | 2011-03-22 13:50:39 -0700 | [diff] [blame^] | 113 | .name = "olpc-xo1-pm-acpi", |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 114 | .owner = THIS_MODULE, |
| 115 | }, |
| 116 | .probe = olpc_xo1_probe, |
| 117 | .remove = __devexit_p(olpc_xo1_remove), |
| 118 | }; |
| 119 | |
| 120 | static int __init olpc_xo1_init(void) |
| 121 | { |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 122 | int r; |
| 123 | |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 124 | r = platform_driver_register(&cs5535_pms_drv); |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 125 | if (r) |
| 126 | return r; |
| 127 | |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 128 | r = platform_driver_register(&cs5535_acpi_drv); |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 129 | if (r) |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 130 | platform_driver_unregister(&cs5535_pms_drv); |
Andres Salomon | 419cdc5 | 2010-11-29 15:45:06 -0800 | [diff] [blame] | 131 | |
| 132 | return r; |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | static void __exit olpc_xo1_exit(void) |
| 136 | { |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 137 | platform_driver_unregister(&cs5535_acpi_drv); |
| 138 | platform_driver_unregister(&cs5535_pms_drv); |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>"); |
| 142 | MODULE_LICENSE("GPL"); |
Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame] | 143 | MODULE_ALIAS("platform:cs5535-pms"); |
Daniel Drake | bf1ebf0 | 2010-10-10 10:40:32 +0100 | [diff] [blame] | 144 | |
| 145 | module_init(olpc_xo1_init); |
| 146 | module_exit(olpc_xo1_exit); |