]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/pnp/support.c
Merge branch 'drm-intel-next' of git://git.kernel.org/pub/scm/linux/kernel/git/anholt...
[mirror_ubuntu-artful-kernel.git] / drivers / pnp / support.c
CommitLineData
1da177e4 1/*
07d4e9af 2 * support.c - standard functions for the use of pnp protocol drivers
1da177e4
LT
3 *
4 * Copyright 2003 Adam Belay <ambx1@neo.rr.com>
1f32ca31
BH
5 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
6 * Bjorn Helgaas <bjorn.helgaas@hp.com>
1da177e4
LT
7 */
8
1da177e4
LT
9#include <linux/module.h>
10#include <linux/ctype.h>
1da177e4
LT
11#include <linux/pnp.h>
12#include "base.h"
13
14/**
07d4e9af
BH
15 * pnp_is_active - Determines if a device is active based on its current
16 * resources
1da177e4 17 * @dev: pointer to the desired PnP device
1da177e4 18 */
9dd78466 19int pnp_is_active(struct pnp_dev *dev)
1da177e4 20{
aee3ad81
BH
21 /*
22 * I don't think this is very reliable because pnp_disable_dev()
23 * only clears out auto-assigned resources.
24 */
1da177e4
LT
25 if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 &&
26 !pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 &&
9dd78466
BH
27 pnp_irq(dev, 0) == -1 && pnp_dma(dev, 0) == -1)
28 return 0;
1da177e4
LT
29 else
30 return 1;
31}
32
1da177e4 33EXPORT_SYMBOL(pnp_is_active);
25eb8461
BH
34
35/*
36 * Functionally similar to acpi_ex_eisa_id_to_string(), but that's
37 * buried in the ACPI CA, and we can't depend on it being present.
38 */
39void pnp_eisa_id_to_string(u32 id, char *str)
40{
41 id = be32_to_cpu(id);
42
43 /*
44 * According to the specs, the first three characters are five-bit
45 * compressed ASCII, and the left-over high order bit should be zero.
46 * However, the Linux ISAPNP code historically used six bits for the
47 * first character, and there seem to be IDs that depend on that,
48 * e.g., "nEC8241" in the Linux 8250_pnp serial driver and the
49 * FreeBSD sys/pc98/cbus/sio_cbus.c driver.
50 */
51 str[0] = 'A' + ((id >> 26) & 0x3f) - 1;
52 str[1] = 'A' + ((id >> 21) & 0x1f) - 1;
53 str[2] = 'A' + ((id >> 16) & 0x1f) - 1;
3fc95772
HH
54 str[3] = hex_asc_hi(id >> 8);
55 str[4] = hex_asc_lo(id >> 8);
56 str[5] = hex_asc_hi(id);
57 str[6] = hex_asc_lo(id);
25eb8461
BH
58 str[7] = '\0';
59}
81b5c75f 60
9fdee4e0
BH
61char *pnp_resource_type_name(struct resource *res)
62{
63 switch (pnp_resource_type(res)) {
64 case IORESOURCE_IO:
65 return "io";
66 case IORESOURCE_MEM:
67 return "mem";
68 case IORESOURCE_IRQ:
69 return "irq";
70 case IORESOURCE_DMA:
71 return "dma";
72 }
73 return NULL;
74}
75
81b5c75f
BH
76void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc)
77{
aee3ad81 78 char buf[128];
ea44c1d6 79 int len;
aee3ad81 80 struct pnp_resource *pnp_res;
81b5c75f 81 struct resource *res;
81b5c75f 82
819beac3 83 if (list_empty(&dev->resources)) {
2f53432c 84 pnp_dbg(&dev->dev, "%s: no current resources\n", desc);
819beac3
BH
85 return;
86 }
87
2f53432c 88 pnp_dbg(&dev->dev, "%s: current resources:\n", desc);
aee3ad81
BH
89 list_for_each_entry(pnp_res, &dev->resources, list) {
90 res = &pnp_res->res;
ea44c1d6 91 len = 0;
81b5c75f 92
ea44c1d6
BH
93 len += scnprintf(buf + len, sizeof(buf) - len, " %-3s ",
94 pnp_resource_type_name(res));
aee3ad81
BH
95
96 if (res->flags & IORESOURCE_DISABLED) {
2f53432c 97 pnp_dbg(&dev->dev, "%sdisabled\n", buf);
aee3ad81
BH
98 continue;
99 }
100
101 switch (pnp_resource_type(res)) {
102 case IORESOURCE_IO:
103 case IORESOURCE_MEM:
ea44c1d6
BH
104 len += scnprintf(buf + len, sizeof(buf) - len,
105 "%#llx-%#llx flags %#lx",
106 (unsigned long long) res->start,
107 (unsigned long long) res->end,
108 res->flags);
aee3ad81
BH
109 break;
110 case IORESOURCE_IRQ:
111 case IORESOURCE_DMA:
ea44c1d6
BH
112 len += scnprintf(buf + len, sizeof(buf) - len,
113 "%lld flags %#lx",
114 (unsigned long long) res->start,
115 res->flags);
aee3ad81
BH
116 break;
117 }
2f53432c 118 pnp_dbg(&dev->dev, "%s\n", buf);
81b5c75f 119 }
81b5c75f 120}
1f32ca31
BH
121
122char *pnp_option_priority_name(struct pnp_option *option)
123{
124 switch (pnp_option_priority(option)) {
125 case PNP_RES_PRIORITY_PREFERRED:
126 return "preferred";
127 case PNP_RES_PRIORITY_ACCEPTABLE:
128 return "acceptable";
129 case PNP_RES_PRIORITY_FUNCTIONAL:
130 return "functional";
131 }
132 return "invalid";
133}
134
135void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option)
136{
1f32ca31
BH
137 char buf[128];
138 int len = 0, i;
139 struct pnp_port *port;
140 struct pnp_mem *mem;
141 struct pnp_irq *irq;
142 struct pnp_dma *dma;
143
144 if (pnp_option_is_dependent(option))
ea44c1d6
BH
145 len += scnprintf(buf + len, sizeof(buf) - len,
146 " dependent set %d (%s) ",
147 pnp_option_set(option),
148 pnp_option_priority_name(option));
1f32ca31 149 else
ea44c1d6
BH
150 len += scnprintf(buf + len, sizeof(buf) - len,
151 " independent ");
1f32ca31
BH
152
153 switch (option->type) {
154 case IORESOURCE_IO:
155 port = &option->u.port;
ea44c1d6
BH
156 len += scnprintf(buf + len, sizeof(buf) - len, "io min %#llx "
157 "max %#llx align %lld size %lld flags %#x",
158 (unsigned long long) port->min,
159 (unsigned long long) port->max,
160 (unsigned long long) port->align,
161 (unsigned long long) port->size, port->flags);
1f32ca31
BH
162 break;
163 case IORESOURCE_MEM:
164 mem = &option->u.mem;
ea44c1d6
BH
165 len += scnprintf(buf + len, sizeof(buf) - len, "mem min %#llx "
166 "max %#llx align %lld size %lld flags %#x",
167 (unsigned long long) mem->min,
168 (unsigned long long) mem->max,
169 (unsigned long long) mem->align,
170 (unsigned long long) mem->size, mem->flags);
1f32ca31
BH
171 break;
172 case IORESOURCE_IRQ:
173 irq = &option->u.irq;
ea44c1d6 174 len += scnprintf(buf + len, sizeof(buf) - len, "irq");
1f32ca31 175 if (bitmap_empty(irq->map.bits, PNP_IRQ_NR))
ea44c1d6
BH
176 len += scnprintf(buf + len, sizeof(buf) - len,
177 " <none>");
1f32ca31
BH
178 else {
179 for (i = 0; i < PNP_IRQ_NR; i++)
180 if (test_bit(i, irq->map.bits))
ea44c1d6
BH
181 len += scnprintf(buf + len,
182 sizeof(buf) - len,
183 " %d", i);
1f32ca31 184 }
ea44c1d6
BH
185 len += scnprintf(buf + len, sizeof(buf) - len, " flags %#x",
186 irq->flags);
1f32ca31 187 if (irq->flags & IORESOURCE_IRQ_OPTIONAL)
ea44c1d6
BH
188 len += scnprintf(buf + len, sizeof(buf) - len,
189 " (optional)");
1f32ca31
BH
190 break;
191 case IORESOURCE_DMA:
192 dma = &option->u.dma;
ea44c1d6 193 len += scnprintf(buf + len, sizeof(buf) - len, "dma");
1f32ca31 194 if (!dma->map)
ea44c1d6
BH
195 len += scnprintf(buf + len, sizeof(buf) - len,
196 " <none>");
1f32ca31
BH
197 else {
198 for (i = 0; i < 8; i++)
199 if (dma->map & (1 << i))
ea44c1d6
BH
200 len += scnprintf(buf + len,
201 sizeof(buf) - len,
202 " %d", i);
1f32ca31 203 }
ea44c1d6
BH
204 len += scnprintf(buf + len, sizeof(buf) - len, " (bitmask %#x) "
205 "flags %#x", dma->map, dma->flags);
1f32ca31
BH
206 break;
207 }
2f53432c 208 pnp_dbg(&dev->dev, "%s\n", buf);
1f32ca31 209}