All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <bjorn.helgaas@hp.com>
To: Clemens Ladisch <clemens@ladisch.de>
Cc: Venkatesh Pallipadi <venki@google.com>,
	Vojtech Pavlik <vojtech@suse.cz>,
	linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org
Subject: [PATCH v2 1/4] hpet: convert from ACPI to PNP driver
Date: Thu, 18 Mar 2010 11:59:30 -0600	[thread overview]
Message-ID: <20100318175930.15143.28660.stgit@bob.kio> (raw)
In-Reply-To: <20100318175852.15143.2124.stgit@bob.kio>


PNPACPI already parses _CRS, and does a more complete job than we did here,
so let's just take advantage of that.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
---

 drivers/char/hpet.c |  109 +++++++++++++++------------------------------------
 1 files changed, 33 insertions(+), 76 deletions(-)


diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index e481c59..5cb05ed 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -31,6 +31,7 @@
 #include <linux/seq_file.h>
 #include <linux/bitops.h>
 #include <linux/clocksource.h>
+#include <linux/pnp.h>
 
 #include <asm/current.h>
 #include <asm/uaccess.h>
@@ -40,7 +41,6 @@
 #include <asm/div64.h>
 
 #include <linux/acpi.h>
-#include <acpi/acpi_bus.h>
 #include <linux/hpet.h>
 
 /*
@@ -899,101 +899,56 @@ int hpet_alloc(struct hpet_data *hdp)
 	return 0;
 }
 
-static acpi_status hpet_resources(struct acpi_resource *res, void *data)
+#ifdef CONFIG_PNP
+static int hpet_pnp_add(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
 {
-	struct hpet_data *hdp;
-	acpi_status status;
-	struct acpi_resource_address64 addr;
-
-	hdp = data;
-
-	status = acpi_resource_to_address64(res, &addr);
-
-	if (ACPI_SUCCESS(status)) {
-		hdp->hd_phys_address = addr.minimum;
-		hdp->hd_address = ioremap(addr.minimum, addr.address_length);
-
-		if (hpet_is_known(hdp)) {
-			iounmap(hdp->hd_address);
-			return AE_ALREADY_EXISTS;
-		}
-	} else if (res->type == ACPI_RESOURCE_TYPE_FIXED_MEMORY32) {
-		struct acpi_resource_fixed_memory32 *fixmem32;
-
-		fixmem32 = &res->data.fixed_memory32;
-		if (!fixmem32)
-			return AE_NO_MEMORY;
-
-		hdp->hd_phys_address = fixmem32->address;
-		hdp->hd_address = ioremap(fixmem32->address,
-						HPET_RANGE_SIZE);
-
-		if (hpet_is_known(hdp)) {
-			iounmap(hdp->hd_address);
-			return AE_ALREADY_EXISTS;
-		}
-	} else if (res->type == ACPI_RESOURCE_TYPE_EXTENDED_IRQ) {
-		struct acpi_resource_extended_irq *irqp;
-		int i, irq;
-
-		irqp = &res->data.extended_irq;
-
-		for (i = 0; i < irqp->interrupt_count; i++) {
-			irq = acpi_register_gsi(NULL, irqp->interrupts[i],
-				      irqp->triggering, irqp->polarity);
-			if (irq < 0)
-				return AE_ERROR;
-
-			hdp->hd_irq[hdp->hd_nirqs] = irq;
-			hdp->hd_nirqs++;
-		}
-	}
-
-	return AE_OK;
-}
-
-static int hpet_acpi_add(struct acpi_device *device)
-{
-	acpi_status result;
 	struct hpet_data data;
+	struct resource *mem, *irq;
+	int i;
 
 	memset(&data, 0, sizeof(data));
 
-	result =
-	    acpi_walk_resources(device->handle, METHOD_NAME__CRS,
-				hpet_resources, &data);
-
-	if (ACPI_FAILURE(result))
+	mem = pnp_get_resource(dev, IORESOURCE_MEM, 0);
+	if (!mem)
 		return -ENODEV;
 
-	if (!data.hd_address || !data.hd_nirqs) {
-		printk("%s: no address or irqs in _CRS\n", __func__);
+	data.hd_phys_address = mem->start;
+
+	if (hpet_is_known(&data))
 		return -ENODEV;
+
+	i = 0;
+	while (data.hd_nirqs < ARRAY_SIZE(data.hd_irq)) {
+		irq = pnp_get_resource(dev, IORESOURCE_IRQ, i++);
+		if (pnp_resource_valid(irq) && pnp_resource_enabled(irq))
+			data.hd_irq[data.hd_nirqs++] = irq->start;
 	}
+	if (!data.hd_nirqs)
+		return -ENODEV;
+
+	data.hd_address = ioremap(mem->start, resource_size(mem));
 
 	return hpet_alloc(&data);
 }
 
-static int hpet_acpi_remove(struct acpi_device *device, int type)
+static void hpet_pnp_remove(struct pnp_dev *dev)
 {
 	/* XXX need to unregister clocksource, dealloc mem, etc */
-	return -EINVAL;
 }
 
-static const struct acpi_device_id hpet_device_ids[] = {
+static const struct pnp_device_id hpet_device_ids[] = {
 	{"PNP0103", 0},
 	{"", 0},
 };
 MODULE_DEVICE_TABLE(acpi, hpet_device_ids);
 
-static struct acpi_driver hpet_acpi_driver = {
+static struct pnp_driver hpet_pnp_driver = {
 	.name = "hpet",
-	.ids = hpet_device_ids,
-	.ops = {
-		.add = hpet_acpi_add,
-		.remove = hpet_acpi_remove,
-		},
+	.id_table = hpet_device_ids,
+	.probe = hpet_pnp_add,
+	.remove = hpet_pnp_remove,
 };
+#endif
 
 static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops };
 
@@ -1007,26 +962,28 @@ static int __init hpet_init(void)
 
 	sysctl_header = register_sysctl_table(dev_root);
 
-	result = acpi_bus_register_driver(&hpet_acpi_driver);
+#ifdef CONFIG_PNP
+	result = pnp_register_driver(&hpet_pnp_driver);
 	if (result < 0) {
 		if (sysctl_header)
 			unregister_sysctl_table(sysctl_header);
 		misc_deregister(&hpet_misc);
 		return result;
 	}
+#endif
 
 	return 0;
 }
 
 static void __exit hpet_exit(void)
 {
-	acpi_bus_unregister_driver(&hpet_acpi_driver);
+#ifdef CONFIG_PNP
+	pnp_unregister_driver(&hpet_pnp_driver);
+#endif
 
 	if (sysctl_header)
 		unregister_sysctl_table(sysctl_header);
 	misc_deregister(&hpet_misc);
-
-	return;
 }
 
 module_init(hpet_init);


  reply	other threads:[~2010-03-18 17:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-18 17:59 [PATCH v2 0/4] hpet: convert from ACPI to PNP driver Bjorn Helgaas
2010-03-18 17:59 ` Bjorn Helgaas [this message]
2010-03-18 19:26   ` [PATCH v2 1/4] " Venkatesh Pallipadi
2010-03-18 19:26     ` Venkatesh Pallipadi
2010-03-18 17:59 ` [PATCH v2 2/4] hpet: pass physical address, not entire hpet_data, to hpet_is_known() Bjorn Helgaas
2010-03-18 19:25   ` Venkatesh Pallipadi
2010-03-18 19:25     ` Venkatesh Pallipadi
2010-03-18 17:59 ` [PATCH v2 3/4] hpet: clean up io mapping when hpet_alloc() fails Bjorn Helgaas
2010-03-18 19:25   ` Venkatesh Pallipadi
2010-03-18 19:25     ` Venkatesh Pallipadi
2010-03-18 17:59 ` [PATCH v2 4/4] MAINTAINERS: remove obsolete HPET ACPI entry Bjorn Helgaas
2010-03-19  8:28 ` [PATCH v2 0/4] hpet: convert from ACPI to PNP driver Clemens Ladisch
2010-03-19 15:58   ` Bjorn Helgaas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100318175930.15143.28660.stgit@bob.kio \
    --to=bjorn.helgaas@hp.com \
    --cc=clemens@ladisch.de \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=venki@google.com \
    --cc=vojtech@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.