mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-11-01 00:48:50 +00:00
1310e6d638
This enables sharing of cs5535-mfd cells via the new mfd_shared_* API. Hooks for enable/disble of resources are added, with refcounting of resources being automatically handled so that cs5535_mfd_res_enable/disable are only called when necessary. Clients of cs5535-mfd (in this case, olpc-xo1.c) are also modified to use the mfd_shared API. The platform drivers are also renamed to olpc-xo1-{pms,acpi}, and resource enabling/disabling is replaced with mfd_shared API calls. Signed-off-by: Andres Salomon <dilinger@queued.net> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
147 lines
3.4 KiB
C
147 lines
3.4 KiB
C
/*
|
|
* Support for features of the OLPC XO-1 laptop
|
|
*
|
|
* Copyright (C) 2010 Andres Salomon <dilinger@queued.net>
|
|
* Copyright (C) 2010 One Laptop per Child
|
|
* Copyright (C) 2006 Red Hat, Inc.
|
|
* Copyright (C) 2006 Advanced Micro Devices, Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/pm.h>
|
|
#include <linux/mfd/core.h>
|
|
|
|
#include <asm/io.h>
|
|
#include <asm/olpc.h>
|
|
|
|
#define DRV_NAME "olpc-xo1"
|
|
|
|
/* PMC registers (PMS block) */
|
|
#define PM_SCLK 0x10
|
|
#define PM_IN_SLPCTL 0x20
|
|
#define PM_WKXD 0x34
|
|
#define PM_WKD 0x30
|
|
#define PM_SSC 0x54
|
|
|
|
/* PM registers (ACPI block) */
|
|
#define PM1_CNT 0x08
|
|
#define PM_GPE0_STS 0x18
|
|
|
|
static unsigned long acpi_base;
|
|
static unsigned long pms_base;
|
|
|
|
static void xo1_power_off(void)
|
|
{
|
|
printk(KERN_INFO "OLPC XO-1 power off sequence...\n");
|
|
|
|
/* Enable all of these controls with 0 delay */
|
|
outl(0x40000000, pms_base + PM_SCLK);
|
|
outl(0x40000000, pms_base + PM_IN_SLPCTL);
|
|
outl(0x40000000, pms_base + PM_WKXD);
|
|
outl(0x40000000, pms_base + PM_WKD);
|
|
|
|
/* Clear status bits (possibly unnecessary) */
|
|
outl(0x0002ffff, pms_base + PM_SSC);
|
|
outl(0xffffffff, acpi_base + PM_GPE0_STS);
|
|
|
|
/* Write SLP_EN bit to start the machinery */
|
|
outl(0x00002000, acpi_base + PM1_CNT);
|
|
}
|
|
|
|
static int __devinit olpc_xo1_probe(struct platform_device *pdev)
|
|
{
|
|
struct resource *res;
|
|
int err;
|
|
|
|
/* don't run on non-XOs */
|
|
if (!machine_is_olpc())
|
|
return -ENODEV;
|
|
|
|
err = mfd_shared_cell_enable(pdev);
|
|
if (err)
|
|
return err;
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_IO, 0);
|
|
if (!res) {
|
|
dev_err(&pdev->dev, "can't fetch device resource info\n");
|
|
return -EIO;
|
|
}
|
|
if (strcmp(pdev->name, "olpc-xo1-pms") == 0)
|
|
pms_base = res->start;
|
|
else if (strcmp(pdev->name, "olpc-xo1-ac-acpi") == 0)
|
|
acpi_base = res->start;
|
|
|
|
/* If we have both addresses, we can override the poweroff hook */
|
|
if (pms_base && acpi_base) {
|
|
pm_power_off = xo1_power_off;
|
|
printk(KERN_INFO "OLPC XO-1 support registered\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int __devexit olpc_xo1_remove(struct platform_device *pdev)
|
|
{
|
|
mfd_shared_cell_disable(pdev);
|
|
|
|
if (strcmp(pdev->name, "olpc-xo1-pms") == 0)
|
|
pms_base = 0;
|
|
else if (strcmp(pdev->name, "olpc-xo1-acpi") == 0)
|
|
acpi_base = 0;
|
|
|
|
pm_power_off = NULL;
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver cs5535_pms_drv = {
|
|
.driver = {
|
|
.name = "olpc-xo1-pms",
|
|
.owner = THIS_MODULE,
|
|
},
|
|
.probe = olpc_xo1_probe,
|
|
.remove = __devexit_p(olpc_xo1_remove),
|
|
};
|
|
|
|
static struct platform_driver cs5535_acpi_drv = {
|
|
.driver = {
|
|
.name = "olpc-xo1-acpi",
|
|
.owner = THIS_MODULE,
|
|
},
|
|
.probe = olpc_xo1_probe,
|
|
.remove = __devexit_p(olpc_xo1_remove),
|
|
};
|
|
|
|
static int __init olpc_xo1_init(void)
|
|
{
|
|
int r;
|
|
|
|
r = mfd_shared_platform_driver_register(&cs5535_pms_drv, "cs5535-pms");
|
|
if (r)
|
|
return r;
|
|
|
|
r = mfd_shared_platform_driver_register(&cs5535_acpi_drv,
|
|
"cs5535-acpi");
|
|
if (r)
|
|
mfd_shared_platform_driver_unregister(&cs5535_pms_drv);
|
|
|
|
return r;
|
|
}
|
|
|
|
static void __exit olpc_xo1_exit(void)
|
|
{
|
|
mfd_shared_platform_driver_unregister(&cs5535_acpi_drv);
|
|
mfd_shared_platform_driver_unregister(&cs5535_pms_drv);
|
|
}
|
|
|
|
MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_ALIAS("platform:cs5535-pms");
|
|
|
|
module_init(olpc_xo1_init);
|
|
module_exit(olpc_xo1_exit);
|