| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Linux Plug and Play Support | 
|  | 3 | * Copyright by Adam Belay <ambx1@neo.rr.com> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ | 
|  | 5 |  | 
|  | 6 | #ifndef _LINUX_PNP_H | 
|  | 7 | #define _LINUX_PNP_H | 
|  | 8 |  | 
|  | 9 | #ifdef __KERNEL__ | 
|  | 10 |  | 
|  | 11 | #include <linux/device.h> | 
|  | 12 | #include <linux/list.h> | 
|  | 13 | #include <linux/errno.h> | 
|  | 14 | #include <linux/mod_devicetable.h> | 
|  | 15 |  | 
|  | 16 | #define PNP_MAX_PORT		8 | 
|  | 17 | #define PNP_MAX_MEM		4 | 
|  | 18 | #define PNP_MAX_IRQ		2 | 
|  | 19 | #define PNP_MAX_DMA		2 | 
|  | 20 | #define PNP_NAME_LEN		50 | 
|  | 21 |  | 
|  | 22 | struct pnp_protocol; | 
|  | 23 | struct pnp_dev; | 
|  | 24 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | /* | 
|  | 26 | * Resource Management | 
|  | 27 | */ | 
|  | 28 |  | 
|  | 29 | /* Use these instead of directly reading pnp_dev to get resource information */ | 
|  | 30 | #define pnp_port_start(dev,bar)   ((dev)->res.port_resource[(bar)].start) | 
|  | 31 | #define pnp_port_end(dev,bar)     ((dev)->res.port_resource[(bar)].end) | 
|  | 32 | #define pnp_port_flags(dev,bar)   ((dev)->res.port_resource[(bar)].flags) | 
|  | 33 | #define pnp_port_valid(dev,bar) \ | 
|  | 34 | ((pnp_port_flags((dev),(bar)) & (IORESOURCE_IO | IORESOURCE_UNSET)) \ | 
|  | 35 | == IORESOURCE_IO) | 
|  | 36 | #define pnp_port_len(dev,bar) \ | 
|  | 37 | ((pnp_port_start((dev),(bar)) == 0 &&	\ | 
|  | 38 | pnp_port_end((dev),(bar)) ==		\ | 
|  | 39 | pnp_port_start((dev),(bar))) ? 0 :	\ | 
|  | 40 | \ | 
|  | 41 | (pnp_port_end((dev),(bar)) -		\ | 
|  | 42 | pnp_port_start((dev),(bar)) + 1)) | 
|  | 43 |  | 
|  | 44 | #define pnp_mem_start(dev,bar)   ((dev)->res.mem_resource[(bar)].start) | 
|  | 45 | #define pnp_mem_end(dev,bar)     ((dev)->res.mem_resource[(bar)].end) | 
|  | 46 | #define pnp_mem_flags(dev,bar)   ((dev)->res.mem_resource[(bar)].flags) | 
|  | 47 | #define pnp_mem_valid(dev,bar) \ | 
|  | 48 | ((pnp_mem_flags((dev),(bar)) & (IORESOURCE_MEM | IORESOURCE_UNSET)) \ | 
|  | 49 | == IORESOURCE_MEM) | 
|  | 50 | #define pnp_mem_len(dev,bar) \ | 
|  | 51 | ((pnp_mem_start((dev),(bar)) == 0 &&	\ | 
|  | 52 | pnp_mem_end((dev),(bar)) ==		\ | 
|  | 53 | pnp_mem_start((dev),(bar))) ? 0 :	\ | 
|  | 54 | \ | 
|  | 55 | (pnp_mem_end((dev),(bar)) -		\ | 
|  | 56 | pnp_mem_start((dev),(bar)) + 1)) | 
|  | 57 |  | 
|  | 58 | #define pnp_irq(dev,bar)	 ((dev)->res.irq_resource[(bar)].start) | 
|  | 59 | #define pnp_irq_flags(dev,bar)	 ((dev)->res.irq_resource[(bar)].flags) | 
|  | 60 | #define pnp_irq_valid(dev,bar) \ | 
|  | 61 | ((pnp_irq_flags((dev),(bar)) & (IORESOURCE_IRQ | IORESOURCE_UNSET)) \ | 
|  | 62 | == IORESOURCE_IRQ) | 
|  | 63 |  | 
|  | 64 | #define pnp_dma(dev,bar)	 ((dev)->res.dma_resource[(bar)].start) | 
|  | 65 | #define pnp_dma_flags(dev,bar)	 ((dev)->res.dma_resource[(bar)].flags) | 
|  | 66 | #define pnp_dma_valid(dev,bar) \ | 
|  | 67 | ((pnp_dma_flags((dev),(bar)) & (IORESOURCE_DMA | IORESOURCE_UNSET)) \ | 
|  | 68 | == IORESOURCE_DMA) | 
|  | 69 |  | 
|  | 70 | #define PNP_PORT_FLAG_16BITADDR	(1<<0) | 
|  | 71 | #define PNP_PORT_FLAG_FIXED	(1<<1) | 
|  | 72 |  | 
|  | 73 | struct pnp_port { | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 74 | unsigned short min;	/* min base number */ | 
|  | 75 | unsigned short max;	/* max base number */ | 
|  | 76 | unsigned char align;	/* align boundary */ | 
|  | 77 | unsigned char size;	/* size of range */ | 
|  | 78 | unsigned char flags;	/* port flags */ | 
|  | 79 | unsigned char pad;	/* pad */ | 
|  | 80 | struct pnp_port *next;	/* next port */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | }; | 
|  | 82 |  | 
|  | 83 | #define PNP_IRQ_NR 256 | 
|  | 84 | struct pnp_irq { | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 85 | DECLARE_BITMAP(map, PNP_IRQ_NR);	/* bitmask for IRQ lines */ | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 86 | unsigned char flags;	/* IRQ flags */ | 
|  | 87 | unsigned char pad;	/* pad */ | 
|  | 88 | struct pnp_irq *next;	/* next IRQ */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | }; | 
|  | 90 |  | 
|  | 91 | struct pnp_dma { | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 92 | unsigned char map;	/* bitmask for DMA channels */ | 
|  | 93 | unsigned char flags;	/* DMA flags */ | 
|  | 94 | struct pnp_dma *next;	/* next port */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | }; | 
|  | 96 |  | 
|  | 97 | struct pnp_mem { | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 98 | unsigned int min;	/* min base number */ | 
|  | 99 | unsigned int max;	/* max base number */ | 
|  | 100 | unsigned int align;	/* align boundary */ | 
|  | 101 | unsigned int size;	/* size of range */ | 
|  | 102 | unsigned char flags;	/* memory flags */ | 
|  | 103 | unsigned char pad;	/* pad */ | 
|  | 104 | struct pnp_mem *next;	/* next memory resource */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | }; | 
|  | 106 |  | 
|  | 107 | #define PNP_RES_PRIORITY_PREFERRED	0 | 
|  | 108 | #define PNP_RES_PRIORITY_ACCEPTABLE	1 | 
|  | 109 | #define PNP_RES_PRIORITY_FUNCTIONAL	2 | 
|  | 110 | #define PNP_RES_PRIORITY_INVALID	65535 | 
|  | 111 |  | 
|  | 112 | struct pnp_option { | 
|  | 113 | unsigned short priority;	/* priority */ | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 114 | struct pnp_port *port;		/* first port */ | 
|  | 115 | struct pnp_irq *irq;		/* first IRQ */ | 
|  | 116 | struct pnp_dma *dma;		/* first DMA */ | 
|  | 117 | struct pnp_mem *mem;		/* first memory resource */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | struct pnp_option *next;	/* used to chain dependent resources */ | 
|  | 119 | }; | 
|  | 120 |  | 
|  | 121 | struct pnp_resource_table { | 
|  | 122 | struct resource port_resource[PNP_MAX_PORT]; | 
|  | 123 | struct resource mem_resource[PNP_MAX_MEM]; | 
|  | 124 | struct resource dma_resource[PNP_MAX_DMA]; | 
|  | 125 | struct resource irq_resource[PNP_MAX_IRQ]; | 
|  | 126 | }; | 
|  | 127 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /* | 
|  | 129 | * Device Managemnt | 
|  | 130 | */ | 
|  | 131 |  | 
|  | 132 | struct pnp_card { | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 133 | struct device dev;		/* Driver Model device interface */ | 
|  | 134 | unsigned char number;		/* used as an index, must be unique */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | struct list_head global_list;	/* node in global list of cards */ | 
|  | 136 | struct list_head protocol_list;	/* node in protocol's list of cards */ | 
|  | 137 | struct list_head devices;	/* devices attached to the card */ | 
|  | 138 |  | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 139 | struct pnp_protocol *protocol; | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 140 | struct pnp_id *id;		/* contains supported EISA IDs */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 |  | 
|  | 142 | char name[PNP_NAME_LEN];	/* contains a human-readable name */ | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 143 | unsigned char pnpver;		/* Plug & Play version */ | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 144 | unsigned char productver;	/* product version */ | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 145 | unsigned int serial;		/* serial number */ | 
|  | 146 | unsigned char checksum;		/* if zero - checksum passed */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | struct proc_dir_entry *procdir;	/* directory entry in /proc/bus/isapnp */ | 
|  | 148 | }; | 
|  | 149 |  | 
|  | 150 | #define global_to_pnp_card(n) list_entry(n, struct pnp_card, global_list) | 
|  | 151 | #define protocol_to_pnp_card(n) list_entry(n, struct pnp_card, protocol_list) | 
|  | 152 | #define to_pnp_card(n) container_of(n, struct pnp_card, dev) | 
|  | 153 | #define pnp_for_each_card(card) \ | 
|  | 154 | for((card) = global_to_pnp_card(pnp_cards.next); \ | 
|  | 155 | (card) != global_to_pnp_card(&pnp_cards); \ | 
|  | 156 | (card) = global_to_pnp_card((card)->global_list.next)) | 
|  | 157 |  | 
|  | 158 | struct pnp_card_link { | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 159 | struct pnp_card *card; | 
|  | 160 | struct pnp_card_driver *driver; | 
|  | 161 | void *driver_data; | 
| Takashi Iwai | 4c98cfe | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 162 | pm_message_t pm_state; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | }; | 
|  | 164 |  | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 165 | static inline void *pnp_get_card_drvdata(struct pnp_card_link *pcard) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { | 
|  | 167 | return pcard->driver_data; | 
|  | 168 | } | 
|  | 169 |  | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 170 | static inline void pnp_set_card_drvdata(struct pnp_card_link *pcard, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { | 
|  | 172 | pcard->driver_data = data; | 
|  | 173 | } | 
|  | 174 |  | 
|  | 175 | struct pnp_dev { | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 176 | struct device dev;		/* Driver Model device interface */ | 
| David Brownell | 2e17c55 | 2007-05-08 00:25:29 -0700 | [diff] [blame] | 177 | u64 dma_mask; | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 178 | unsigned char number;		/* used as an index, must be unique */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | int status; | 
|  | 180 |  | 
|  | 181 | struct list_head global_list;	/* node in global list of devices */ | 
|  | 182 | struct list_head protocol_list;	/* node in list of device's protocol */ | 
|  | 183 | struct list_head card_list;	/* node in card's list of devices */ | 
|  | 184 | struct list_head rdev_list;	/* node in cards list of requested devices */ | 
|  | 185 |  | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 186 | struct pnp_protocol *protocol; | 
|  | 187 | struct pnp_card *card;	/* card the device is attached to, none if NULL */ | 
|  | 188 | struct pnp_driver *driver; | 
|  | 189 | struct pnp_card_link *card_link; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 |  | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 191 | struct pnp_id *id;		/* supported EISA IDs */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 |  | 
|  | 193 | int active; | 
|  | 194 | int capabilities; | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 195 | struct pnp_option *independent; | 
|  | 196 | struct pnp_option *dependent; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | struct pnp_resource_table res; | 
|  | 198 |  | 
|  | 199 | char name[PNP_NAME_LEN];	/* contains a human-readable name */ | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 200 | unsigned short regs;		/* ISAPnP: supported registers */ | 
|  | 201 | int flags;			/* used by protocols */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | struct proc_dir_entry *procent;	/* device entry in /proc/bus/isapnp */ | 
|  | 203 | void *data; | 
|  | 204 | }; | 
|  | 205 |  | 
|  | 206 | #define global_to_pnp_dev(n) list_entry(n, struct pnp_dev, global_list) | 
|  | 207 | #define card_to_pnp_dev(n) list_entry(n, struct pnp_dev, card_list) | 
|  | 208 | #define protocol_to_pnp_dev(n) list_entry(n, struct pnp_dev, protocol_list) | 
|  | 209 | #define	to_pnp_dev(n) container_of(n, struct pnp_dev, dev) | 
|  | 210 | #define pnp_for_each_dev(dev) \ | 
|  | 211 | for((dev) = global_to_pnp_dev(pnp_global.next); \ | 
|  | 212 | (dev) != global_to_pnp_dev(&pnp_global); \ | 
|  | 213 | (dev) = global_to_pnp_dev((dev)->global_list.next)) | 
|  | 214 | #define card_for_each_dev(card,dev) \ | 
|  | 215 | for((dev) = card_to_pnp_dev((card)->devices.next); \ | 
|  | 216 | (dev) != card_to_pnp_dev(&(card)->devices); \ | 
|  | 217 | (dev) = card_to_pnp_dev((dev)->card_list.next)) | 
|  | 218 | #define pnp_dev_name(dev) (dev)->name | 
|  | 219 |  | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 220 | static inline void *pnp_get_drvdata(struct pnp_dev *pdev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | { | 
|  | 222 | return dev_get_drvdata(&pdev->dev); | 
|  | 223 | } | 
|  | 224 |  | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 225 | static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { | 
|  | 227 | dev_set_drvdata(&pdev->dev, data); | 
|  | 228 | } | 
|  | 229 |  | 
|  | 230 | struct pnp_fixup { | 
|  | 231 | char id[7]; | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 232 | void (*quirk_function) (struct pnp_dev * dev);	/* fixup function */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | }; | 
|  | 234 |  | 
|  | 235 | /* config parameters */ | 
|  | 236 | #define PNP_CONFIG_NORMAL	0x0001 | 
|  | 237 | #define PNP_CONFIG_FORCE	0x0002	/* disables validity checking */ | 
|  | 238 |  | 
|  | 239 | /* capabilities */ | 
|  | 240 | #define PNP_READ		0x0001 | 
|  | 241 | #define PNP_WRITE		0x0002 | 
|  | 242 | #define PNP_DISABLE		0x0004 | 
|  | 243 | #define PNP_CONFIGURABLE	0x0008 | 
|  | 244 | #define PNP_REMOVABLE		0x0010 | 
|  | 245 |  | 
| Bjorn Helgaas | 402b310 | 2007-10-16 23:31:09 -0700 | [diff] [blame] | 246 | #define pnp_can_read(dev)	(((dev)->protocol->get) && \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | ((dev)->capabilities & PNP_READ)) | 
| Bjorn Helgaas | 402b310 | 2007-10-16 23:31:09 -0700 | [diff] [blame] | 248 | #define pnp_can_write(dev)	(((dev)->protocol->set) && \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | ((dev)->capabilities & PNP_WRITE)) | 
| Bjorn Helgaas | 402b310 | 2007-10-16 23:31:09 -0700 | [diff] [blame] | 250 | #define pnp_can_disable(dev)	(((dev)->protocol->disable) && \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | ((dev)->capabilities & PNP_DISABLE)) | 
|  | 252 | #define pnp_can_configure(dev)	((!(dev)->active) && \ | 
|  | 253 | ((dev)->capabilities & PNP_CONFIGURABLE)) | 
|  | 254 |  | 
|  | 255 | #ifdef CONFIG_ISAPNP | 
|  | 256 | extern struct pnp_protocol isapnp_protocol; | 
|  | 257 | #define pnp_device_is_isapnp(dev) ((dev)->protocol == (&isapnp_protocol)) | 
|  | 258 | #else | 
|  | 259 | #define pnp_device_is_isapnp(dev) 0 | 
|  | 260 | #endif | 
|  | 261 |  | 
|  | 262 | #ifdef CONFIG_PNPBIOS | 
|  | 263 | extern struct pnp_protocol pnpbios_protocol; | 
|  | 264 | #define pnp_device_is_pnpbios(dev) ((dev)->protocol == (&pnpbios_protocol)) | 
|  | 265 | #else | 
|  | 266 | #define pnp_device_is_pnpbios(dev) 0 | 
|  | 267 | #endif | 
|  | 268 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | /* status */ | 
|  | 270 | #define PNP_READY		0x0000 | 
|  | 271 | #define PNP_ATTACHED		0x0001 | 
|  | 272 | #define PNP_BUSY		0x0002 | 
|  | 273 | #define PNP_FAULTY		0x0004 | 
|  | 274 |  | 
|  | 275 | /* isapnp specific macros */ | 
|  | 276 |  | 
|  | 277 | #define isapnp_card_number(dev)	((dev)->card ? (dev)->card->number : -1) | 
|  | 278 | #define isapnp_csn_number(dev)  ((dev)->number) | 
|  | 279 |  | 
|  | 280 | /* | 
|  | 281 | * Driver Management | 
|  | 282 | */ | 
|  | 283 |  | 
|  | 284 | struct pnp_id { | 
|  | 285 | char id[PNP_ID_LEN]; | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 286 | struct pnp_id *next; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | }; | 
|  | 288 |  | 
|  | 289 | struct pnp_driver { | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 290 | char *name; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | const struct pnp_device_id *id_table; | 
|  | 292 | unsigned int flags; | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 293 | int (*probe) (struct pnp_dev *dev, const struct pnp_device_id *dev_id); | 
|  | 294 | void (*remove) (struct pnp_dev *dev); | 
|  | 295 | int (*suspend) (struct pnp_dev *dev, pm_message_t state); | 
|  | 296 | int (*resume) (struct pnp_dev *dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | struct device_driver driver; | 
|  | 298 | }; | 
|  | 299 |  | 
|  | 300 | #define	to_pnp_driver(drv) container_of(drv, struct pnp_driver, driver) | 
|  | 301 |  | 
|  | 302 | struct pnp_card_driver { | 
|  | 303 | struct list_head global_list; | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 304 | char *name; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | const struct pnp_card_device_id *id_table; | 
|  | 306 | unsigned int flags; | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 307 | int (*probe) (struct pnp_card_link *card, | 
|  | 308 | const struct pnp_card_device_id *card_id); | 
|  | 309 | void (*remove) (struct pnp_card_link *card); | 
|  | 310 | int (*suspend) (struct pnp_card_link *card, pm_message_t state); | 
|  | 311 | int (*resume) (struct pnp_card_link *card); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | struct pnp_driver link; | 
|  | 313 | }; | 
|  | 314 |  | 
|  | 315 | #define	to_pnp_card_driver(drv) container_of(drv, struct pnp_card_driver, link) | 
|  | 316 |  | 
|  | 317 | /* pnp driver flags */ | 
|  | 318 | #define PNP_DRIVER_RES_DO_NOT_CHANGE	0x0001	/* do not change the state of the device */ | 
|  | 319 | #define PNP_DRIVER_RES_DISABLE		0x0003	/* ensure the device is disabled */ | 
|  | 320 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | /* | 
|  | 322 | * Protocol Management | 
|  | 323 | */ | 
|  | 324 |  | 
|  | 325 | struct pnp_protocol { | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 326 | struct list_head protocol_list; | 
|  | 327 | char *name; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 |  | 
|  | 329 | /* resource control functions */ | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 330 | int (*get) (struct pnp_dev *dev, struct pnp_resource_table *res); | 
|  | 331 | int (*set) (struct pnp_dev *dev, struct pnp_resource_table *res); | 
|  | 332 | int (*disable) (struct pnp_dev *dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 |  | 
| Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 334 | /* protocol specific suspend/resume */ | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 335 | int (*suspend) (struct pnp_dev * dev, pm_message_t state); | 
|  | 336 | int (*resume) (struct pnp_dev * dev); | 
| Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 337 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | /* used by pnp layer only (look but don't touch) */ | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 339 | unsigned char number;	/* protocol number */ | 
|  | 340 | struct device dev;	/* link to driver model */ | 
|  | 341 | struct list_head cards; | 
|  | 342 | struct list_head devices; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | }; | 
|  | 344 |  | 
|  | 345 | #define to_pnp_protocol(n) list_entry(n, struct pnp_protocol, protocol_list) | 
|  | 346 | #define protocol_for_each_card(protocol,card) \ | 
|  | 347 | for((card) = protocol_to_pnp_card((protocol)->cards.next); \ | 
|  | 348 | (card) != protocol_to_pnp_card(&(protocol)->cards); \ | 
|  | 349 | (card) = protocol_to_pnp_card((card)->protocol_list.next)) | 
|  | 350 | #define protocol_for_each_dev(protocol,dev) \ | 
|  | 351 | for((dev) = protocol_to_pnp_dev((protocol)->devices.next); \ | 
|  | 352 | (dev) != protocol_to_pnp_dev(&(protocol)->devices); \ | 
|  | 353 | (dev) = protocol_to_pnp_dev((dev)->protocol_list.next)) | 
|  | 354 |  | 
| David Brownell | cbcdc1d | 2007-02-10 01:45:13 -0800 | [diff] [blame] | 355 | extern struct bus_type pnp_bus_type; | 
|  | 356 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | #if defined(CONFIG_PNP) | 
|  | 358 |  | 
|  | 359 | /* device management */ | 
|  | 360 | int pnp_register_protocol(struct pnp_protocol *protocol); | 
|  | 361 | void pnp_unregister_protocol(struct pnp_protocol *protocol); | 
|  | 362 | int pnp_add_device(struct pnp_dev *dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | int pnp_device_attach(struct pnp_dev *pnp_dev); | 
|  | 364 | void pnp_device_detach(struct pnp_dev *pnp_dev); | 
|  | 365 | extern struct list_head pnp_global; | 
| Bjorn Helgaas | 8f81dd1 | 2007-05-08 00:35:54 -0700 | [diff] [blame] | 366 | extern int pnp_platform_devices; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 |  | 
|  | 368 | /* multidevice card support */ | 
|  | 369 | int pnp_add_card(struct pnp_card *card); | 
|  | 370 | void pnp_remove_card(struct pnp_card *card); | 
|  | 371 | int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev); | 
|  | 372 | void pnp_remove_card_device(struct pnp_dev *dev); | 
|  | 373 | int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card); | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 374 | struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, | 
|  | 375 | const char *id, struct pnp_dev *from); | 
|  | 376 | void pnp_release_card_device(struct pnp_dev *dev); | 
|  | 377 | int pnp_register_card_driver(struct pnp_card_driver *drv); | 
|  | 378 | void pnp_unregister_card_driver(struct pnp_card_driver *drv); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | extern struct list_head pnp_cards; | 
|  | 380 |  | 
|  | 381 | /* resource management */ | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 382 | struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev); | 
|  | 383 | struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev, | 
|  | 384 | int priority); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data); | 
|  | 386 | int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data); | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 387 | int pnp_register_port_resource(struct pnp_option *option, | 
|  | 388 | struct pnp_port *data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data); | 
|  | 390 | void pnp_init_resource_table(struct pnp_resource_table *table); | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 391 | int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, | 
|  | 392 | int mode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | int pnp_auto_config_dev(struct pnp_dev *dev); | 
|  | 394 | int pnp_validate_config(struct pnp_dev *dev); | 
| Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 395 | int pnp_start_dev(struct pnp_dev *dev); | 
|  | 396 | int pnp_stop_dev(struct pnp_dev *dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | int pnp_activate_dev(struct pnp_dev *dev); | 
|  | 398 | int pnp_disable_dev(struct pnp_dev *dev); | 
| Greg Kroah-Hartman | b60ba83 | 2006-06-12 17:07:07 -0700 | [diff] [blame] | 399 | void pnp_resource_change(struct resource *resource, resource_size_t start, | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 400 | resource_size_t size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 |  | 
|  | 402 | /* protocol helpers */ | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 403 | int pnp_is_active(struct pnp_dev *dev); | 
|  | 404 | int compare_pnp_id(struct pnp_id *pos, const char *id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev); | 
|  | 406 | int pnp_register_driver(struct pnp_driver *drv); | 
|  | 407 | void pnp_unregister_driver(struct pnp_driver *drv); | 
|  | 408 |  | 
|  | 409 | #else | 
|  | 410 |  | 
|  | 411 | /* device management */ | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 412 | static inline int pnp_register_protocol(struct pnp_protocol *protocol) { return -ENODEV; } | 
|  | 413 | static inline void pnp_unregister_protocol(struct pnp_protocol *protocol) { } | 
|  | 414 | static inline int pnp_init_device(struct pnp_dev *dev) { return -ENODEV; } | 
|  | 415 | static inline int pnp_add_device(struct pnp_dev *dev) { return -ENODEV; } | 
|  | 416 | static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; } | 
|  | 417 | static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { } | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 418 |  | 
| Bjorn Helgaas | 8f81dd1 | 2007-05-08 00:35:54 -0700 | [diff] [blame] | 419 | #define pnp_platform_devices 0 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 |  | 
|  | 421 | /* multidevice card support */ | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 422 | static inline int pnp_add_card(struct pnp_card *card) { return -ENODEV; } | 
|  | 423 | static inline void pnp_remove_card(struct pnp_card *card) { } | 
|  | 424 | static inline int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev) { return -ENODEV; } | 
|  | 425 | static inline void pnp_remove_card_device(struct pnp_dev *dev) { } | 
|  | 426 | static inline int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card) { return -ENODEV; } | 
|  | 427 | static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, const char *id, struct pnp_dev *from) { return NULL; } | 
|  | 428 | static inline void pnp_release_card_device(struct pnp_dev *dev) { } | 
|  | 429 | static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return -ENODEV; } | 
|  | 430 | static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 |  | 
|  | 432 | /* resource management */ | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 433 | static inline struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev) { return NULL; } | 
|  | 434 | static inline struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev, int priority) { return NULL; } | 
|  | 435 | static inline int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data) { return -ENODEV; } | 
|  | 436 | static inline int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data) { return -ENODEV; } | 
|  | 437 | static inline int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data) { return -ENODEV; } | 
|  | 438 | static inline int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data) { return -ENODEV; } | 
|  | 439 | static inline void pnp_init_resource_table(struct pnp_resource_table *table) { } | 
|  | 440 | static inline int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, int mode) { return -ENODEV; } | 
|  | 441 | static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; } | 
|  | 442 | static inline int pnp_validate_config(struct pnp_dev *dev) { return -ENODEV; } | 
|  | 443 | static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; } | 
|  | 444 | static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; } | 
|  | 445 | static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; } | 
|  | 446 | static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; } | 
|  | 447 | static inline void pnp_resource_change(struct resource *resource, resource_size_t start, resource_size_t size) { } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 |  | 
|  | 449 | /* protocol helpers */ | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 450 | static inline int pnp_is_active(struct pnp_dev *dev) { return 0; } | 
|  | 451 | static inline int compare_pnp_id(struct pnp_id *pos, const char *id) { return -ENODEV; } | 
|  | 452 | static inline int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev) { return -ENODEV; } | 
|  | 453 | static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; } | 
|  | 454 | static inline void pnp_unregister_driver(struct pnp_driver *drv) { } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 |  | 
|  | 456 | #endif /* CONFIG_PNP */ | 
|  | 457 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | #define pnp_err(format, arg...) printk(KERN_ERR "pnp: " format "\n" , ## arg) | 
|  | 459 | #define pnp_info(format, arg...) printk(KERN_INFO "pnp: " format "\n" , ## arg) | 
|  | 460 | #define pnp_warn(format, arg...) printk(KERN_WARNING "pnp: " format "\n" , ## arg) | 
|  | 461 |  | 
| Bjorn Helgaas | e139aa5 | 2005-09-06 15:17:05 -0700 | [diff] [blame] | 462 | #ifdef CONFIG_PNP_DEBUG | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | #define pnp_dbg(format, arg...) printk(KERN_DEBUG "pnp: " format "\n" , ## arg) | 
|  | 464 | #else | 
|  | 465 | #define pnp_dbg(format, arg...) do {} while (0) | 
|  | 466 | #endif | 
|  | 467 |  | 
|  | 468 | #endif /* __KERNEL__ */ | 
|  | 469 |  | 
|  | 470 | #endif /* _LINUX_PNP_H */ |