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