Path: blob/master/arch/x86/platform/olpc/olpc-xo1.c
10821 views
/*1* Support for features of the OLPC XO-1 laptop2*3* Copyright (C) 2010 Andres Salomon <[email protected]>4* Copyright (C) 2010 One Laptop per Child5* 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 modify9* it under the terms of the GNU General Public License as published by10* the Free Software Foundation; either version 2 of the License, or11* (at your option) any later version.12*/1314#include <linux/module.h>15#include <linux/platform_device.h>16#include <linux/pm.h>17#include <linux/mfd/core.h>1819#include <asm/io.h>20#include <asm/olpc.h>2122#define DRV_NAME "olpc-xo1"2324/* PMC registers (PMS block) */25#define PM_SCLK 0x1026#define PM_IN_SLPCTL 0x2027#define PM_WKXD 0x3428#define PM_WKD 0x3029#define PM_SSC 0x543031/* PM registers (ACPI block) */32#define PM1_CNT 0x0833#define PM_GPE0_STS 0x183435static unsigned long acpi_base;36static unsigned long pms_base;3738static void xo1_power_off(void)39{40printk(KERN_INFO "OLPC XO-1 power off sequence...\n");4142/* Enable all of these controls with 0 delay */43outl(0x40000000, pms_base + PM_SCLK);44outl(0x40000000, pms_base + PM_IN_SLPCTL);45outl(0x40000000, pms_base + PM_WKXD);46outl(0x40000000, pms_base + PM_WKD);4748/* Clear status bits (possibly unnecessary) */49outl(0x0002ffff, pms_base + PM_SSC);50outl(0xffffffff, acpi_base + PM_GPE0_STS);5152/* Write SLP_EN bit to start the machinery */53outl(0x00002000, acpi_base + PM1_CNT);54}5556static int __devinit olpc_xo1_probe(struct platform_device *pdev)57{58struct resource *res;59int err;6061/* don't run on non-XOs */62if (!machine_is_olpc())63return -ENODEV;6465err = mfd_cell_enable(pdev);66if (err)67return err;6869res = platform_get_resource(pdev, IORESOURCE_IO, 0);70if (!res) {71dev_err(&pdev->dev, "can't fetch device resource info\n");72return -EIO;73}74if (strcmp(pdev->name, "cs5535-pms") == 0)75pms_base = res->start;76else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)77acpi_base = res->start;7879/* If we have both addresses, we can override the poweroff hook */80if (pms_base && acpi_base) {81pm_power_off = xo1_power_off;82printk(KERN_INFO "OLPC XO-1 support registered\n");83}8485return 0;86}8788static int __devexit olpc_xo1_remove(struct platform_device *pdev)89{90mfd_cell_disable(pdev);9192if (strcmp(pdev->name, "cs5535-pms") == 0)93pms_base = 0;94else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)95acpi_base = 0;9697pm_power_off = NULL;98return 0;99}100101static struct platform_driver cs5535_pms_drv = {102.driver = {103.name = "cs5535-pms",104.owner = THIS_MODULE,105},106.probe = olpc_xo1_probe,107.remove = __devexit_p(olpc_xo1_remove),108};109110static struct platform_driver cs5535_acpi_drv = {111.driver = {112.name = "olpc-xo1-pm-acpi",113.owner = THIS_MODULE,114},115.probe = olpc_xo1_probe,116.remove = __devexit_p(olpc_xo1_remove),117};118119static int __init olpc_xo1_init(void)120{121int r;122123r = platform_driver_register(&cs5535_pms_drv);124if (r)125return r;126127r = platform_driver_register(&cs5535_acpi_drv);128if (r)129platform_driver_unregister(&cs5535_pms_drv);130131return r;132}133134static void __exit olpc_xo1_exit(void)135{136platform_driver_unregister(&cs5535_acpi_drv);137platform_driver_unregister(&cs5535_pms_drv);138}139140MODULE_AUTHOR("Daniel Drake <[email protected]>");141MODULE_LICENSE("GPL");142MODULE_ALIAS("platform:cs5535-pms");143144module_init(olpc_xo1_init);145module_exit(olpc_xo1_exit);146147148