blob: 2588ca6a9028d40efccccd8f6250271d860966f4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Linux Plug and Play Support
3 * Copyright by Adam Belay <ambx1@neo.rr.com>
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -06004 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
5 * Bjorn Helgaas <bjorn.helgaas@hp.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
8#ifndef _LINUX_PNP_H
9#define _LINUX_PNP_H
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/device.h>
12#include <linux/list.h>
13#include <linux/errno.h>
14#include <linux/mod_devicetable.h>
Peter Hurley01395d72015-01-22 11:50:24 -050015#include <linux/console.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#define PNP_NAME_LEN 50
18
19struct pnp_protocol;
20struct pnp_dev;
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/*
23 * Resource Management
24 */
David Milleref3d7712008-09-16 15:00:11 -070025#ifdef CONFIG_PNP
Rene Hermanb563cf52008-10-15 22:03:58 -070026struct resource *pnp_get_resource(struct pnp_dev *dev, unsigned long type,
27 unsigned int num);
David Milleref3d7712008-09-16 15:00:11 -070028#else
Rene Hermanb563cf52008-10-15 22:03:58 -070029static inline struct resource *pnp_get_resource(struct pnp_dev *dev,
30 unsigned long type, unsigned int num)
David Milleref3d7712008-09-16 15:00:11 -070031{
32 return NULL;
33}
34#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Bjorn Helgaas13575e812008-04-28 16:34:16 -060036static inline int pnp_resource_valid(struct resource *res)
37{
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -060038 if (res)
39 return 1;
40 return 0;
41}
42
43static inline int pnp_resource_enabled(struct resource *res)
44{
45 if (res && !(res->flags & IORESOURCE_DISABLED))
Bjorn Helgaas13575e812008-04-28 16:34:16 -060046 return 1;
47 return 0;
48}
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Bjorn Helgaas13575e812008-04-28 16:34:16 -060050static inline resource_size_t pnp_resource_len(struct resource *res)
51{
52 if (res->start == 0 && res->end == 0)
53 return 0;
Joe Perches28f65c112011-06-09 09:13:32 -070054 return resource_size(res);
Bjorn Helgaas13575e812008-04-28 16:34:16 -060055}
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Bjorn Helgaas13575e812008-04-28 16:34:16 -060058static inline resource_size_t pnp_port_start(struct pnp_dev *dev,
59 unsigned int bar)
60{
Bjorn Helgaas20bfdbb2008-06-27 16:56:56 -060061 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
62
63 if (pnp_resource_valid(res))
64 return res->start;
65 return 0;
Bjorn Helgaas13575e812008-04-28 16:34:16 -060066}
67
68static inline resource_size_t pnp_port_end(struct pnp_dev *dev,
69 unsigned int bar)
70{
Bjorn Helgaas20bfdbb2008-06-27 16:56:56 -060071 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
72
73 if (pnp_resource_valid(res))
74 return res->end;
75 return 0;
Bjorn Helgaas13575e812008-04-28 16:34:16 -060076}
77
78static inline unsigned long pnp_port_flags(struct pnp_dev *dev,
79 unsigned int bar)
80{
Bjorn Helgaas20bfdbb2008-06-27 16:56:56 -060081 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
82
83 if (pnp_resource_valid(res))
84 return res->flags;
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -060085 return IORESOURCE_IO | IORESOURCE_AUTO;
Bjorn Helgaas13575e812008-04-28 16:34:16 -060086}
87
88static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar)
89{
90 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IO, bar));
91}
92
93static inline resource_size_t pnp_port_len(struct pnp_dev *dev,
94 unsigned int bar)
95{
Bjorn Helgaas20bfdbb2008-06-27 16:56:56 -060096 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
97
98 if (pnp_resource_valid(res))
99 return pnp_resource_len(res);
100 return 0;
Bjorn Helgaas13575e812008-04-28 16:34:16 -0600101}
102
103
104static inline resource_size_t pnp_mem_start(struct pnp_dev *dev,
105 unsigned int bar)
106{
Bjorn Helgaas20bfdbb2008-06-27 16:56:56 -0600107 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
108
109 if (pnp_resource_valid(res))
110 return res->start;
111 return 0;
Bjorn Helgaas13575e812008-04-28 16:34:16 -0600112}
113
114static inline resource_size_t pnp_mem_end(struct pnp_dev *dev,
115 unsigned int bar)
116{
Bjorn Helgaas20bfdbb2008-06-27 16:56:56 -0600117 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
118
119 if (pnp_resource_valid(res))
120 return res->end;
121 return 0;
Bjorn Helgaas13575e812008-04-28 16:34:16 -0600122}
123
124static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar)
125{
Bjorn Helgaas20bfdbb2008-06-27 16:56:56 -0600126 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
127
128 if (pnp_resource_valid(res))
129 return res->flags;
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600130 return IORESOURCE_MEM | IORESOURCE_AUTO;
Bjorn Helgaas13575e812008-04-28 16:34:16 -0600131}
132
133static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar)
134{
135 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_MEM, bar));
136}
137
138static inline resource_size_t pnp_mem_len(struct pnp_dev *dev,
139 unsigned int bar)
140{
Bjorn Helgaas20bfdbb2008-06-27 16:56:56 -0600141 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
142
143 if (pnp_resource_valid(res))
144 return pnp_resource_len(res);
145 return 0;
Bjorn Helgaas13575e812008-04-28 16:34:16 -0600146}
147
148
149static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar)
150{
Bjorn Helgaas20bfdbb2008-06-27 16:56:56 -0600151 struct resource *res = pnp_get_resource(dev, IORESOURCE_IRQ, bar);
152
153 if (pnp_resource_valid(res))
154 return res->start;
155 return -1;
Bjorn Helgaas13575e812008-04-28 16:34:16 -0600156}
157
158static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar)
159{
Bjorn Helgaas20bfdbb2008-06-27 16:56:56 -0600160 struct resource *res = pnp_get_resource(dev, IORESOURCE_IRQ, bar);
161
162 if (pnp_resource_valid(res))
163 return res->flags;
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600164 return IORESOURCE_IRQ | IORESOURCE_AUTO;
Bjorn Helgaas13575e812008-04-28 16:34:16 -0600165}
166
167static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar)
168{
169 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IRQ, bar));
170}
171
172
173static inline resource_size_t pnp_dma(struct pnp_dev *dev, unsigned int bar)
174{
Bjorn Helgaas20bfdbb2008-06-27 16:56:56 -0600175 struct resource *res = pnp_get_resource(dev, IORESOURCE_DMA, bar);
176
177 if (pnp_resource_valid(res))
178 return res->start;
179 return -1;
Bjorn Helgaas13575e812008-04-28 16:34:16 -0600180}
181
182static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar)
183{
Bjorn Helgaas20bfdbb2008-06-27 16:56:56 -0600184 struct resource *res = pnp_get_resource(dev, IORESOURCE_DMA, bar);
185
186 if (pnp_resource_valid(res))
187 return res->flags;
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600188 return IORESOURCE_DMA | IORESOURCE_AUTO;
Bjorn Helgaas13575e812008-04-28 16:34:16 -0600189}
190
191static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar)
192{
193 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_DMA, bar));
194}
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197/*
Joe Perchesfd3f8982008-02-03 17:45:46 +0200198 * Device Management
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 */
200
201struct pnp_card {
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700202 struct device dev; /* Driver Model device interface */
203 unsigned char number; /* used as an index, must be unique */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 struct list_head global_list; /* node in global list of cards */
205 struct list_head protocol_list; /* node in protocol's list of cards */
206 struct list_head devices; /* devices attached to the card */
207
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700208 struct pnp_protocol *protocol;
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700209 struct pnp_id *id; /* contains supported EISA IDs */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 char name[PNP_NAME_LEN]; /* contains a human-readable name */
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700212 unsigned char pnpver; /* Plug & Play version */
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700213 unsigned char productver; /* product version */
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700214 unsigned int serial; /* serial number */
215 unsigned char checksum; /* if zero - checksum passed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 struct proc_dir_entry *procdir; /* directory entry in /proc/bus/isapnp */
217};
218
219#define global_to_pnp_card(n) list_entry(n, struct pnp_card, global_list)
220#define protocol_to_pnp_card(n) list_entry(n, struct pnp_card, protocol_list)
221#define to_pnp_card(n) container_of(n, struct pnp_card, dev)
222#define pnp_for_each_card(card) \
223 for((card) = global_to_pnp_card(pnp_cards.next); \
224 (card) != global_to_pnp_card(&pnp_cards); \
225 (card) = global_to_pnp_card((card)->global_list.next))
226
227struct pnp_card_link {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700228 struct pnp_card *card;
229 struct pnp_card_driver *driver;
230 void *driver_data;
Takashi Iwai4c98cfe2005-11-29 09:09:32 +0100231 pm_message_t pm_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232};
233
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700234static inline void *pnp_get_card_drvdata(struct pnp_card_link *pcard)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
236 return pcard->driver_data;
237}
238
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700239static inline void pnp_set_card_drvdata(struct pnp_card_link *pcard, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 pcard->driver_data = data;
242}
243
244struct pnp_dev {
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700245 struct device dev; /* Driver Model device interface */
David Brownell2e17c552007-05-08 00:25:29 -0700246 u64 dma_mask;
Bjorn Helgaas544451a2008-04-10 21:29:28 -0700247 unsigned int number; /* used as an index, must be unique */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 int status;
249
250 struct list_head global_list; /* node in global list of devices */
251 struct list_head protocol_list; /* node in list of device's protocol */
252 struct list_head card_list; /* node in card's list of devices */
253 struct list_head rdev_list; /* node in cards list of requested devices */
254
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700255 struct pnp_protocol *protocol;
256 struct pnp_card *card; /* card the device is attached to, none if NULL */
257 struct pnp_driver *driver;
258 struct pnp_card_link *card_link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700260 struct pnp_id *id; /* supported EISA IDs */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 int active;
263 int capabilities;
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600264 unsigned int num_dependent_sets;
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600265 struct list_head resources;
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600266 struct list_head options;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 char name[PNP_NAME_LEN]; /* contains a human-readable name */
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700269 int flags; /* used by protocols */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 struct proc_dir_entry *procent; /* device entry in /proc/bus/isapnp */
271 void *data;
272};
273
274#define global_to_pnp_dev(n) list_entry(n, struct pnp_dev, global_list)
275#define card_to_pnp_dev(n) list_entry(n, struct pnp_dev, card_list)
276#define protocol_to_pnp_dev(n) list_entry(n, struct pnp_dev, protocol_list)
277#define to_pnp_dev(n) container_of(n, struct pnp_dev, dev)
278#define pnp_for_each_dev(dev) \
279 for((dev) = global_to_pnp_dev(pnp_global.next); \
280 (dev) != global_to_pnp_dev(&pnp_global); \
281 (dev) = global_to_pnp_dev((dev)->global_list.next))
282#define card_for_each_dev(card,dev) \
283 for((dev) = card_to_pnp_dev((card)->devices.next); \
284 (dev) != card_to_pnp_dev(&(card)->devices); \
285 (dev) = card_to_pnp_dev((dev)->card_list.next))
286#define pnp_dev_name(dev) (dev)->name
287
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700288static inline void *pnp_get_drvdata(struct pnp_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
290 return dev_get_drvdata(&pdev->dev);
291}
292
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700293static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
295 dev_set_drvdata(&pdev->dev, data);
296}
297
298struct pnp_fixup {
299 char id[7];
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700300 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301};
302
303/* config parameters */
304#define PNP_CONFIG_NORMAL 0x0001
305#define PNP_CONFIG_FORCE 0x0002 /* disables validity checking */
306
307/* capabilities */
308#define PNP_READ 0x0001
309#define PNP_WRITE 0x0002
310#define PNP_DISABLE 0x0004
311#define PNP_CONFIGURABLE 0x0008
312#define PNP_REMOVABLE 0x0010
Peter Hurley01395d72015-01-22 11:50:24 -0500313#define PNP_CONSOLE 0x0020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Bjorn Helgaas402b3102007-10-16 23:31:09 -0700315#define pnp_can_read(dev) (((dev)->protocol->get) && \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 ((dev)->capabilities & PNP_READ))
Bjorn Helgaas402b3102007-10-16 23:31:09 -0700317#define pnp_can_write(dev) (((dev)->protocol->set) && \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 ((dev)->capabilities & PNP_WRITE))
Peter Hurley01395d72015-01-22 11:50:24 -0500319#define pnp_can_disable(dev) (((dev)->protocol->disable) && \
320 ((dev)->capabilities & PNP_DISABLE) && \
321 (!((dev)->capabilities & PNP_CONSOLE) || \
322 console_suspend_enabled))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#define pnp_can_configure(dev) ((!(dev)->active) && \
324 ((dev)->capabilities & PNP_CONFIGURABLE))
Peter Hurley01395d72015-01-22 11:50:24 -0500325#define pnp_can_suspend(dev) (((dev)->protocol->suspend) && \
326 (!((dev)->capabilities & PNP_CONSOLE) || \
327 console_suspend_enabled))
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330#ifdef CONFIG_ISAPNP
331extern struct pnp_protocol isapnp_protocol;
332#define pnp_device_is_isapnp(dev) ((dev)->protocol == (&isapnp_protocol))
333#else
334#define pnp_device_is_isapnp(dev) 0
335#endif
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800336extern struct mutex pnp_res_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338#ifdef CONFIG_PNPBIOS
339extern struct pnp_protocol pnpbios_protocol;
Luis R. Rodriguez80dfd832016-04-13 17:04:41 -0700340extern bool arch_pnpbios_disabled(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341#define pnp_device_is_pnpbios(dev) ((dev)->protocol == (&pnpbios_protocol))
342#else
343#define pnp_device_is_pnpbios(dev) 0
Luis R. Rodriguez80dfd832016-04-13 17:04:41 -0700344#define arch_pnpbios_disabled() false
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345#endif
346
Bjorn Helgaas9065ce42009-11-17 17:05:19 -0700347#ifdef CONFIG_PNPACPI
348extern struct pnp_protocol pnpacpi_protocol;
349
350static inline struct acpi_device *pnp_acpi_device(struct pnp_dev *dev)
351{
352 if (dev->protocol == &pnpacpi_protocol)
353 return dev->data;
354 return NULL;
355}
356#else
357#define pnp_acpi_device(dev) 0
358#endif
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360/* status */
361#define PNP_READY 0x0000
362#define PNP_ATTACHED 0x0001
363#define PNP_BUSY 0x0002
364#define PNP_FAULTY 0x0004
365
366/* isapnp specific macros */
367
368#define isapnp_card_number(dev) ((dev)->card ? (dev)->card->number : -1)
369#define isapnp_csn_number(dev) ((dev)->number)
370
371/*
372 * Driver Management
373 */
374
375struct pnp_id {
376 char id[PNP_ID_LEN];
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700377 struct pnp_id *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378};
379
380struct pnp_driver {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700381 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 const struct pnp_device_id *id_table;
383 unsigned int flags;
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700384 int (*probe) (struct pnp_dev *dev, const struct pnp_device_id *dev_id);
385 void (*remove) (struct pnp_dev *dev);
David Härdemanabd66332009-09-21 17:04:52 -0700386 void (*shutdown) (struct pnp_dev *dev);
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700387 int (*suspend) (struct pnp_dev *dev, pm_message_t state);
388 int (*resume) (struct pnp_dev *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 struct device_driver driver;
390};
391
392#define to_pnp_driver(drv) container_of(drv, struct pnp_driver, driver)
393
394struct pnp_card_driver {
395 struct list_head global_list;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700396 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 const struct pnp_card_device_id *id_table;
398 unsigned int flags;
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700399 int (*probe) (struct pnp_card_link *card,
400 const struct pnp_card_device_id *card_id);
401 void (*remove) (struct pnp_card_link *card);
402 int (*suspend) (struct pnp_card_link *card, pm_message_t state);
403 int (*resume) (struct pnp_card_link *card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 struct pnp_driver link;
405};
406
407#define to_pnp_card_driver(drv) container_of(drv, struct pnp_card_driver, link)
408
409/* pnp driver flags */
410#define PNP_DRIVER_RES_DO_NOT_CHANGE 0x0001 /* do not change the state of the device */
411#define PNP_DRIVER_RES_DISABLE 0x0003 /* ensure the device is disabled */
412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413/*
414 * Protocol Management
415 */
416
417struct pnp_protocol {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700418 struct list_head protocol_list;
419 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421 /* resource control functions */
Bjorn Helgaas59284cb2008-04-28 16:34:05 -0600422 int (*get) (struct pnp_dev *dev);
423 int (*set) (struct pnp_dev *dev);
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700424 int (*disable) (struct pnp_dev *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Shaohua Lifc30e682007-07-20 10:03:20 +0800426 /* protocol specific suspend/resume */
Alan Sternb14e0332010-06-29 22:49:24 +0200427 bool (*can_wakeup) (struct pnp_dev *dev);
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700428 int (*suspend) (struct pnp_dev * dev, pm_message_t state);
429 int (*resume) (struct pnp_dev * dev);
Shaohua Lifc30e682007-07-20 10:03:20 +0800430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 /* used by pnp layer only (look but don't touch) */
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700432 unsigned char number; /* protocol number */
433 struct device dev; /* link to driver model */
434 struct list_head cards;
435 struct list_head devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436};
437
438#define to_pnp_protocol(n) list_entry(n, struct pnp_protocol, protocol_list)
439#define protocol_for_each_card(protocol,card) \
440 for((card) = protocol_to_pnp_card((protocol)->cards.next); \
441 (card) != protocol_to_pnp_card(&(protocol)->cards); \
442 (card) = protocol_to_pnp_card((card)->protocol_list.next))
443#define protocol_for_each_dev(protocol,dev) \
444 for((dev) = protocol_to_pnp_dev((protocol)->devices.next); \
445 (dev) != protocol_to_pnp_dev(&(protocol)->devices); \
446 (dev) = protocol_to_pnp_dev((dev)->protocol_list.next))
447
David Brownellcbcdc1d2007-02-10 01:45:13 -0800448extern struct bus_type pnp_bus_type;
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450#if defined(CONFIG_PNP)
451
452/* device management */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453int pnp_device_attach(struct pnp_dev *pnp_dev);
454void pnp_device_detach(struct pnp_dev *pnp_dev);
455extern struct list_head pnp_global;
Bjorn Helgaas8f81dd12007-05-08 00:35:54 -0700456extern int pnp_platform_devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458/* multidevice card support */
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700459struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,
460 const char *id, struct pnp_dev *from);
461void pnp_release_card_device(struct pnp_dev *dev);
462int pnp_register_card_driver(struct pnp_card_driver *drv);
463void pnp_unregister_card_driver(struct pnp_card_driver *drv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464extern struct list_head pnp_cards;
465
466/* resource management */
Bjorn Helgaas57fd51a2008-06-27 16:57:01 -0600467int pnp_possible_config(struct pnp_dev *dev, int type, resource_size_t base,
468 resource_size_t size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469int pnp_auto_config_dev(struct pnp_dev *dev);
Pierre Ossman68094e32005-11-29 09:09:32 +0100470int pnp_start_dev(struct pnp_dev *dev);
471int pnp_stop_dev(struct pnp_dev *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472int pnp_activate_dev(struct pnp_dev *dev);
473int pnp_disable_dev(struct pnp_dev *dev);
Bjorn Helgaas1b8e6962009-06-05 14:37:23 +0000474int pnp_range_reserved(resource_size_t start, resource_size_t end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476/* protocol helpers */
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700477int pnp_is_active(struct pnp_dev *dev);
478int compare_pnp_id(struct pnp_id *pos, const char *id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479int pnp_register_driver(struct pnp_driver *drv);
480void pnp_unregister_driver(struct pnp_driver *drv);
481
482#else
483
484/* device management */
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700485static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; }
486static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700487
Bjorn Helgaas8f81dd12007-05-08 00:35:54 -0700488#define pnp_platform_devices 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490/* multidevice card support */
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700491static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, const char *id, struct pnp_dev *from) { return NULL; }
492static inline void pnp_release_card_device(struct pnp_dev *dev) { }
493static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return -ENODEV; }
494static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496/* resource management */
Bjorn Helgaas57fd51a2008-06-27 16:57:01 -0600497static inline int pnp_possible_config(struct pnp_dev *dev, int type,
498 resource_size_t base,
499 resource_size_t size) { return 0; }
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700500static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; }
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700501static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; }
502static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; }
503static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; }
504static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; }
Bjorn Helgaas1b8e6962009-06-05 14:37:23 +0000505static inline int pnp_range_reserved(resource_size_t start, resource_size_t end) { return 0;}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507/* protocol helpers */
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700508static inline int pnp_is_active(struct pnp_dev *dev) { return 0; }
509static inline int compare_pnp_id(struct pnp_id *pos, const char *id) { return -ENODEV; }
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700510static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; }
511static inline void pnp_unregister_driver(struct pnp_driver *drv) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513#endif /* CONFIG_PNP */
514
Peter Huewe95c0fd42015-03-16 21:46:30 +0100515/**
516 * module_pnp_driver() - Helper macro for registering a PnP driver
517 * @__pnp_driver: pnp_driver struct
518 *
519 * Helper macro for PnP drivers which do not do anything special in module
520 * init/exit. This eliminates a lot of boilerplate. Each module may only
521 * use this macro once, and calling it replaces module_init() and module_exit()
522 */
523#define module_pnp_driver(__pnp_driver) \
524 module_driver(__pnp_driver, pnp_register_driver, \
525 pnp_unregister_driver)
526
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#endif /* _LINUX_PNP_H */