blob: a2a59d36824dc815a391bfcea7d73fd427807594 [file] [log] [blame]
Daniel Drakebf1ebf02010-10-10 10:40:32 +01001/*
Daniel Drakea3128582011-06-25 17:34:10 +01002 * Support for power management features of the OLPC XO-1 laptop
Daniel Drakebf1ebf02010-10-10 10:40:32 +01003 *
Andres Salomon419cdc52010-11-29 15:45:06 -08004 * Copyright (C) 2010 Andres Salomon <dilinger@queued.net>
Daniel Drakebf1ebf02010-10-10 10:40:32 +01005 * 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 Drake7a0d4fc2011-06-25 17:34:09 +010015#include <linux/cs5535.h>
Daniel Drakebf1ebf02010-10-10 10:40:32 +010016#include <linux/platform_device.h>
17#include <linux/pm.h>
Andres Salomon1310e6d2011-02-17 19:07:36 -080018#include <linux/mfd/core.h>
Daniel Drakebf1ebf02010-10-10 10:40:32 +010019
20#include <asm/io.h>
21#include <asm/olpc.h>
22
Daniel Drakea3128582011-06-25 17:34:10 +010023#define DRV_NAME "olpc-xo1-pm"
Daniel Drakebf1ebf02010-10-10 10:40:32 +010024
Daniel Drakebf1ebf02010-10-10 10:40:32 +010025static unsigned long acpi_base;
26static unsigned long pms_base;
27
28static void xo1_power_off(void)
29{
30 printk(KERN_INFO "OLPC XO-1 power off sequence...\n");
31
32 /* Enable all of these controls with 0 delay */
Daniel Drake7a0d4fc2011-06-25 17:34:09 +010033 outl(0x40000000, pms_base + CS5536_PM_SCLK);
34 outl(0x40000000, pms_base + CS5536_PM_IN_SLPCTL);
35 outl(0x40000000, pms_base + CS5536_PM_WKXD);
36 outl(0x40000000, pms_base + CS5536_PM_WKD);
Daniel Drakebf1ebf02010-10-10 10:40:32 +010037
38 /* Clear status bits (possibly unnecessary) */
Daniel Drake7a0d4fc2011-06-25 17:34:09 +010039 outl(0x0002ffff, pms_base + CS5536_PM_SSC);
40 outl(0xffffffff, acpi_base + CS5536_PM_GPE0_STS);
Daniel Drakebf1ebf02010-10-10 10:40:32 +010041
42 /* Write SLP_EN bit to start the machinery */
Daniel Drake7a0d4fc2011-06-25 17:34:09 +010043 outl(0x00002000, acpi_base + CS5536_PM1_CNT);
Daniel Drakebf1ebf02010-10-10 10:40:32 +010044}
45
Daniel Drakea3128582011-06-25 17:34:10 +010046static int __devinit xo1_pm_probe(struct platform_device *pdev)
Daniel Drakebf1ebf02010-10-10 10:40:32 +010047{
Andres Salomon419cdc52010-11-29 15:45:06 -080048 struct resource *res;
Andres Salomon1310e6d2011-02-17 19:07:36 -080049 int err;
Daniel Drakebf1ebf02010-10-10 10:40:32 +010050
Andres Salomon419cdc52010-11-29 15:45:06 -080051 /* don't run on non-XOs */
52 if (!machine_is_olpc())
Daniel Drakebf1ebf02010-10-10 10:40:32 +010053 return -ENODEV;
54
Andres Salomonf77289a2011-03-03 09:51:58 -080055 err = mfd_cell_enable(pdev);
Andres Salomon1310e6d2011-02-17 19:07:36 -080056 if (err)
57 return err;
58
Andres Salomon419cdc52010-11-29 15:45:06 -080059 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
60 if (!res) {
61 dev_err(&pdev->dev, "can't fetch device resource info\n");
62 return -EIO;
63 }
Daniel Drakeadfa4bd2011-03-22 13:50:39 -070064 if (strcmp(pdev->name, "cs5535-pms") == 0)
Andres Salomon419cdc52010-11-29 15:45:06 -080065 pms_base = res->start;
Daniel Drakeadfa4bd2011-03-22 13:50:39 -070066 else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
Andres Salomon419cdc52010-11-29 15:45:06 -080067 acpi_base = res->start;
68
69 /* If we have both addresses, we can override the poweroff hook */
70 if (pms_base && acpi_base) {
71 pm_power_off = xo1_power_off;
72 printk(KERN_INFO "OLPC XO-1 support registered\n");
73 }
74
Daniel Drakebf1ebf02010-10-10 10:40:32 +010075 return 0;
76}
77
Daniel Drakea3128582011-06-25 17:34:10 +010078static int __devexit xo1_pm_remove(struct platform_device *pdev)
Daniel Drakebf1ebf02010-10-10 10:40:32 +010079{
Andres Salomonf77289a2011-03-03 09:51:58 -080080 mfd_cell_disable(pdev);
Andres Salomon419cdc52010-11-29 15:45:06 -080081
Daniel Drakeadfa4bd2011-03-22 13:50:39 -070082 if (strcmp(pdev->name, "cs5535-pms") == 0)
Andres Salomon419cdc52010-11-29 15:45:06 -080083 pms_base = 0;
Daniel Drakeadfa4bd2011-03-22 13:50:39 -070084 else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
Andres Salomon419cdc52010-11-29 15:45:06 -080085 acpi_base = 0;
86
Daniel Drakebf1ebf02010-10-10 10:40:32 +010087 pm_power_off = NULL;
88 return 0;
89}
90
Daniel Drakea3128582011-06-25 17:34:10 +010091static struct platform_driver cs5535_pms_driver = {
Daniel Drakebf1ebf02010-10-10 10:40:32 +010092 .driver = {
Daniel Drakeadfa4bd2011-03-22 13:50:39 -070093 .name = "cs5535-pms",
Andres Salomon419cdc52010-11-29 15:45:06 -080094 .owner = THIS_MODULE,
95 },
Daniel Drakea3128582011-06-25 17:34:10 +010096 .probe = xo1_pm_probe,
97 .remove = __devexit_p(xo1_pm_remove),
Andres Salomon419cdc52010-11-29 15:45:06 -080098};
99
Daniel Drakea3128582011-06-25 17:34:10 +0100100static struct platform_driver cs5535_acpi_driver = {
Andres Salomon419cdc52010-11-29 15:45:06 -0800101 .driver = {
Daniel Drakeadfa4bd2011-03-22 13:50:39 -0700102 .name = "olpc-xo1-pm-acpi",
Daniel Drakebf1ebf02010-10-10 10:40:32 +0100103 .owner = THIS_MODULE,
104 },
Daniel Drakea3128582011-06-25 17:34:10 +0100105 .probe = xo1_pm_probe,
106 .remove = __devexit_p(xo1_pm_remove),
Daniel Drakebf1ebf02010-10-10 10:40:32 +0100107};
108
Daniel Drakea3128582011-06-25 17:34:10 +0100109static int __init xo1_pm_init(void)
Daniel Drakebf1ebf02010-10-10 10:40:32 +0100110{
Andres Salomon419cdc52010-11-29 15:45:06 -0800111 int r;
112
Daniel Drakea3128582011-06-25 17:34:10 +0100113 r = platform_driver_register(&cs5535_pms_driver);
Andres Salomon419cdc52010-11-29 15:45:06 -0800114 if (r)
115 return r;
116
Daniel Drakea3128582011-06-25 17:34:10 +0100117 r = platform_driver_register(&cs5535_acpi_driver);
Andres Salomon419cdc52010-11-29 15:45:06 -0800118 if (r)
Daniel Drakea3128582011-06-25 17:34:10 +0100119 platform_driver_unregister(&cs5535_pms_driver);
Andres Salomon419cdc52010-11-29 15:45:06 -0800120
121 return r;
Daniel Drakebf1ebf02010-10-10 10:40:32 +0100122}
Daniel Drakea3128582011-06-25 17:34:10 +0100123arch_initcall(xo1_pm_init);