aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial/8250_acpi.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/serial/8250_acpi.c
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/serial/8250_acpi.c')
-rw-r--r--drivers/serial/8250_acpi.c171
1 files changed, 171 insertions, 0 deletions
diff --git a/drivers/serial/8250_acpi.c b/drivers/serial/8250_acpi.c
new file mode 100644
index 00000000000..6b9ead28851
--- /dev/null
+++ b/drivers/serial/8250_acpi.c
@@ -0,0 +1,171 @@
1/*
2 * Copyright (c) 2002-2003 Matthew Wilcox for Hewlett-Packard
3 * Copyright (C) 2004 Hewlett-Packard Co
4 * Bjorn Helgaas <bjorn.helgaas@hp.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/acpi.h>
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/serial_core.h>
16
17#include <acpi/acpi_bus.h>
18
19#include <asm/io.h>
20
21#include "8250.h"
22
23struct serial_private {
24 int line;
25};
26
27static acpi_status acpi_serial_mmio(struct uart_port *port,
28 struct acpi_resource_address64 *addr)
29{
30 port->mapbase = addr->min_address_range;
31 port->iotype = UPIO_MEM;
32 port->flags |= UPF_IOREMAP;
33 return AE_OK;
34}
35
36static acpi_status acpi_serial_port(struct uart_port *port,
37 struct acpi_resource_io *io)
38{
39 if (io->range_length) {
40 port->iobase = io->min_base_address;
41 port->iotype = UPIO_PORT;
42 } else
43 printk(KERN_ERR "%s: zero-length IO port range?\n", __FUNCTION__);
44 return AE_OK;
45}
46
47static acpi_status acpi_serial_ext_irq(struct uart_port *port,
48 struct acpi_resource_ext_irq *ext_irq)
49{
50 if (ext_irq->number_of_interrupts > 0)
51 port->irq = acpi_register_gsi(ext_irq->interrupts[0],
52 ext_irq->edge_level, ext_irq->active_high_low);
53 return AE_OK;
54}
55
56static acpi_status acpi_serial_irq(struct uart_port *port,
57 struct acpi_resource_irq *irq)
58{
59 if (irq->number_of_interrupts > 0)
60 port->irq = acpi_register_gsi(irq->interrupts[0],
61 irq->edge_level, irq->active_high_low);
62 return AE_OK;
63}
64
65static acpi_status acpi_serial_resource(struct acpi_resource *res, void *data)
66{
67 struct uart_port *port = (struct uart_port *) data;
68 struct acpi_resource_address64 addr;
69 acpi_status status;
70
71 status = acpi_resource_to_address64(res, &addr);
72 if (ACPI_SUCCESS(status))
73 return acpi_serial_mmio(port, &addr);
74 else if (res->id == ACPI_RSTYPE_IO)
75 return acpi_serial_port(port, &res->data.io);
76 else if (res->id == ACPI_RSTYPE_EXT_IRQ)
77 return acpi_serial_ext_irq(port, &res->data.extended_irq);
78 else if (res->id == ACPI_RSTYPE_IRQ)
79 return acpi_serial_irq(port, &res->data.irq);
80 return AE_OK;
81}
82
83static int acpi_serial_add(struct acpi_device *device)
84{
85 struct serial_private *priv;
86 acpi_status status;
87 struct uart_port port;
88 int result;
89
90 memset(&port, 0, sizeof(struct uart_port));
91
92 port.uartclk = 1843200;
93 port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
94
95 priv = kmalloc(sizeof(struct serial_private), GFP_KERNEL);
96 if (!priv) {
97 result = -ENOMEM;
98 goto fail;
99 }
100 memset(priv, 0, sizeof(*priv));
101
102 status = acpi_walk_resources(device->handle, METHOD_NAME__CRS,
103 acpi_serial_resource, &port);
104 if (ACPI_FAILURE(status)) {
105 result = -ENODEV;
106 goto fail;
107 }
108
109 if (!port.mapbase && !port.iobase) {
110 printk(KERN_ERR "%s: no iomem or port address in %s _CRS\n",
111 __FUNCTION__, device->pnp.bus_id);
112 result = -ENODEV;
113 goto fail;
114 }
115
116 priv->line = serial8250_register_port(&port);
117 if (priv->line < 0) {
118 printk(KERN_WARNING "Couldn't register serial port %s: %d\n",
119 device->pnp.bus_id, priv->line);
120 result = -ENODEV;
121 goto fail;
122 }
123
124 acpi_driver_data(device) = priv;
125 return 0;
126
127fail:
128 kfree(priv);
129
130 return result;
131}
132
133static int acpi_serial_remove(struct acpi_device *device, int type)
134{
135 struct serial_private *priv;
136
137 if (!device || !acpi_driver_data(device))
138 return -EINVAL;
139
140 priv = acpi_driver_data(device);
141 serial8250_unregister_port(priv->line);
142 kfree(priv);
143
144 return 0;
145}
146
147static struct acpi_driver acpi_serial_driver = {
148 .name = "serial",
149 .class = "",
150 .ids = "PNP0501",
151 .ops = {
152 .add = acpi_serial_add,
153 .remove = acpi_serial_remove,
154 },
155};
156
157static int __init acpi_serial_init(void)
158{
159 return acpi_bus_register_driver(&acpi_serial_driver);
160}
161
162static void __exit acpi_serial_exit(void)
163{
164 acpi_bus_unregister_driver(&acpi_serial_driver);
165}
166
167module_init(acpi_serial_init);
168module_exit(acpi_serial_exit);
169
170MODULE_LICENSE("GPL");
171MODULE_DESCRIPTION("Generic 8250/16x50 ACPI serial driver");