Commit 419cdc54 authored by Andres Salomon's avatar Andres Salomon Committed by Samuel Ortiz

x86: OLPC: convert olpc-xo1 driver from pci device to platform device

The cs5535-mfd driver now takes care of the PCI BAR handling; this
means the olpc-xo1 driver shouldn't be touching the PCI device at all.

This patch uses both cs5535-acpi and cs5535-pms platform devices rather
than a single platform device because the cs5535-mfd driver may be used
by other CS5535 platform-specific drivers; OLPC doesn't get to dictate
that ACPI and PMS will always be used together.
Signed-off-by: default avatarAndres Salomon <dilinger@queued.net>
Acked-by: default avatarH. Peter Anvin <hpa@zytor.com>
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent cdd137c9
...@@ -2068,7 +2068,7 @@ config OLPC ...@@ -2068,7 +2068,7 @@ config OLPC
config OLPC_XO1 config OLPC_XO1
tristate "OLPC XO-1 support" tristate "OLPC XO-1 support"
depends on OLPC && PCI depends on OLPC && MFD_CS5535
---help--- ---help---
Add support for non-essential features of the OLPC XO-1 laptop. Add support for non-essential features of the OLPC XO-1 laptop.
......
/* /*
* Support for features of the OLPC XO-1 laptop * 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) 2010 One Laptop per Child
* Copyright (C) 2006 Red Hat, Inc. * Copyright (C) 2006 Red Hat, Inc.
* Copyright (C) 2006 Advanced Micro Devices, Inc. * Copyright (C) 2006 Advanced Micro Devices, Inc.
...@@ -12,8 +13,6 @@ ...@@ -12,8 +13,6 @@
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/pci.h>
#include <linux/pci_ids.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm.h> #include <linux/pm.h>
...@@ -22,9 +21,6 @@ ...@@ -22,9 +21,6 @@
#define DRV_NAME "olpc-xo1" #define DRV_NAME "olpc-xo1"
#define PMS_BAR 4
#define ACPI_BAR 5
/* PMC registers (PMS block) */ /* PMC registers (PMS block) */
#define PM_SCLK 0x10 #define PM_SCLK 0x10
#define PM_IN_SLPCTL 0x20 #define PM_IN_SLPCTL 0x20
...@@ -57,65 +53,67 @@ static void xo1_power_off(void) ...@@ -57,65 +53,67 @@ static void xo1_power_off(void)
outl(0x00002000, acpi_base + PM1_CNT); outl(0x00002000, acpi_base + PM1_CNT);
} }
/* Read the base addresses from the PCI BAR info */ static int __devinit olpc_xo1_probe(struct platform_device *pdev)
static int __devinit setup_bases(struct pci_dev *pdev)
{ {
int r; struct resource *res;
r = pci_enable_device_io(pdev); /* don't run on non-XOs */
if (r) { if (!machine_is_olpc())
dev_err(&pdev->dev, "can't enable device IO\n"); return -ENODEV;
return r;
}
r = pci_request_region(pdev, ACPI_BAR, DRV_NAME); res = platform_get_resource(pdev, IORESOURCE_IO, 0);
if (r) { if (!res) {
dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", ACPI_BAR); dev_err(&pdev->dev, "can't fetch device resource info\n");
return r; return -EIO;
} }
r = pci_request_region(pdev, PMS_BAR, DRV_NAME); if (!request_region(res->start, resource_size(res), DRV_NAME)) {
if (r) { dev_err(&pdev->dev, "can't request region\n");
dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", PMS_BAR); return -EIO;
pci_release_region(pdev, ACPI_BAR);
return r;
} }
acpi_base = pci_resource_start(pdev, ACPI_BAR); if (strcmp(pdev->name, "cs5535-pms") == 0)
pms_base = pci_resource_start(pdev, PMS_BAR); pms_base = res->start;
else if (strcmp(pdev->name, "cs5535-acpi") == 0)
return 0; acpi_base = res->start;
}
static int __devinit olpc_xo1_probe(struct platform_device *pdev)
{
struct pci_dev *pcidev;
int r;
pcidev = pci_get_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA,
NULL);
if (!pdev)
return -ENODEV;
r = setup_bases(pcidev);
if (r)
return r;
/* If we have both addresses, we can override the poweroff hook */
if (pms_base && acpi_base) {
pm_power_off = xo1_power_off; pm_power_off = xo1_power_off;
printk(KERN_INFO "OLPC XO-1 support registered\n"); printk(KERN_INFO "OLPC XO-1 support registered\n");
}
return 0; return 0;
} }
static int __devexit olpc_xo1_remove(struct platform_device *pdev) static int __devexit olpc_xo1_remove(struct platform_device *pdev)
{ {
struct resource *r;
r = platform_get_resource(pdev, IORESOURCE_IO, 0);
release_region(r->start, resource_size(r));
if (strcmp(pdev->name, "cs5535-pms") == 0)
pms_base = 0;
else if (strcmp(pdev->name, "cs5535-acpi") == 0)
acpi_base = 0;
pm_power_off = NULL; pm_power_off = NULL;
return 0; return 0;
} }
static struct platform_driver olpc_xo1_driver = { static struct platform_driver cs5535_pms_drv = {
.driver = {
.name = "cs5535-pms",
.owner = THIS_MODULE,
},
.probe = olpc_xo1_probe,
.remove = __devexit_p(olpc_xo1_remove),
};
static struct platform_driver cs5535_acpi_drv = {
.driver = { .driver = {
.name = DRV_NAME, .name = "cs5535-acpi",
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
.probe = olpc_xo1_probe, .probe = olpc_xo1_probe,
...@@ -124,12 +122,23 @@ static struct platform_driver olpc_xo1_driver = { ...@@ -124,12 +122,23 @@ static struct platform_driver olpc_xo1_driver = {
static int __init olpc_xo1_init(void) static int __init olpc_xo1_init(void)
{ {
return platform_driver_register(&olpc_xo1_driver); int r;
r = platform_driver_register(&cs5535_pms_drv);
if (r)
return r;
r = platform_driver_register(&cs5535_acpi_drv);
if (r)
platform_driver_unregister(&cs5535_pms_drv);
return r;
} }
static void __exit olpc_xo1_exit(void) static void __exit olpc_xo1_exit(void)
{ {
platform_driver_unregister(&olpc_xo1_driver); platform_driver_unregister(&cs5535_acpi_drv);
platform_driver_unregister(&cs5535_pms_drv);
} }
MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>"); MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment